* hl-line.el (hl-line): New face.
[bpt/emacs.git] / lisp / progmodes / idlwave.el
CommitLineData
52a244eb 1;; idlwave.el --- IDL editing mode for GNU Emacs
d91362c9 2;; Copyright (c) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
f66f03de 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>
f66f03de 9;; Version: 6.0_em22
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
f66f03de
S
31;; IDLWAVE enables feature-rich development and interaction with IDL,
32;; the Interactive Data Language. It provides a compelling,
33;; full-featured alternative to the IDLDE development environment
34;; bundled with IDL.
3938cb82 35
52a244eb
S
36;; In the remotely distant past, based on pascal.el, though bears
37;; little resemblance to it now.
f32b3b91
CD
38;;
39;; Incorporates many ideas, such as abbrevs, action routines, and
40;; continuation line indenting, from wave.el.
41;; wave.el original written by Lubos Pochman, Precision Visuals, Boulder.
42;;
43;; See the mode description ("C-h m" in idlwave-mode or "C-h f idlwave-mode")
44;; for features, key bindings, and info.
45;; Also, Info format documentation is available with `M-x idlwave-info'
46;;
5e72c6b2
S
47;; New versions of IDLWAVE, documentation, and more information
48;; available from:
49;; http://idlwave.org
f32b3b91
CD
50;;
51;; INSTALLATION
52;; ============
53;;
54;; Follow the instructions in the INSTALL file of the distribution.
55;; In short, put this file on your load path and add the following
56;; lines to your .emacs file:
57;;
58;; (autoload 'idlwave-mode "idlwave" "IDLWAVE Mode" t)
8c7b4ec8 59;; (autoload 'idlwave-shell "idlw-shell" "IDLWAVE Shell" t)
f32b3b91
CD
60;; (setq auto-mode-alist (cons '("\\.pro\\'" . idlwave-mode) auto-mode-alist))
61;;
62;;
63;; SOURCE
64;; ======
65;;
76959b77 66;; The newest version of this file is available from the maintainer's
52a244eb 67;; Webpage:
f32b3b91 68;;
5e72c6b2 69;; http://idlwave.org
f32b3b91
CD
70;;
71;; DOCUMENTATION
72;; =============
73;;
52a244eb
S
74;; IDLWAVE is documented online in info format. A printable version
75;; of the documentation is available from the maintainers webpage (see
76;; SOURCE).
775591f7 77;;
f66f03de 78;;
f32b3b91
CD
79;; ACKNOWLEDGMENTS
80;; ===============
81;;
82;; Thanks to the following people for their contributions and comments:
83;;
52a244eb
S
84;; Ulrik Dickow <dickow_at_nbi.dk>
85;; Eric E. Dors <edors_at_lanl.gov>
86;; Stein Vidar H. Haugan <s.v.h.haugan_at_astro.uio.no>
87;; David Huenemoerder <dph_at_space.mit.edu>
88;; Kevin Ivory <Kevin.Ivory_at_linmpi.mpg.de>
89;; Dick Jackson <dick_at_d-jackson.com>
90;; Xuyong Liu <liu_at_stsci.edu>
91;; Simon Marshall <Simon.Marshall_at_esrin.esa.it>
92;; Laurent Mugnier <mugnier_at_onera.fr>
93;; Lubos Pochman <lubos_at_rsinc.com>
94;; Bob Portmann <portmann_at_al.noaa.gov>
95;; Patrick M. Ryan <pat_at_jaameri.gsfc.nasa.gov>
96;; Marty Ryba <ryba_at_ll.mit.edu>
97;; Paul Sorenson <aardvark62_at_msn.com>
98;; Phil Sterne <sterne_at_dublin.llnl.gov>
99;; Phil Williams <williams_at_irc.chmcc.org>
f32b3b91
CD
100;;
101;; CUSTOMIZATION:
102;; =============
103;;
52a244eb
S
104;; IDLWAVE has extensive customize support; to learn about the
105;; variables which control the mode's behavior, use `M-x
106;; idlwave-customize'.
f32b3b91
CD
107;;
108;; You can set your own preferred values with Customize, or with Lisp
109;; code in .emacs. For an example of what to put into .emacs, check
52a244eb
S
110;; the TexInfo documentation or see a complete .emacs available at the
111;; website.
f32b3b91
CD
112;;
113;; KNOWN PROBLEMS:
114;; ==============
115;;
76959b77
S
116;; IDLWAVE support for the IDL-derived PV-WAVE CL language of Visual
117;; Numerics, Inc. is growing less and less complete as the two
118;; languages grow increasingly apart. The mode probably shouldn't
3938cb82 119;; even have "WAVE" in its title, but it's catchy, and was required
52a244eb 120;; to avoid conflict with the CORBA idl.el mode. Caveat WAVEor.
76959b77 121;;
f32b3b91
CD
122;; Moving the point backwards in conjunction with abbrev expansion
123;; does not work as I would like it, but this is a problem with
124;; emacs abbrev expansion done by the self-insert-command. It ends
125;; up inserting the character that expanded the abbrev after moving
126;; point backward, e.g., "\cl" expanded with a space becomes
127;; "LONG( )" with point before the close paren. This is solved by
f66f03de 128;; using a temporary function in `post-command-hook' - not pretty,
595ab50b 129;; but it works.
f32b3b91
CD
130;;
131;; Tabs and spaces are treated equally as whitespace when filling a
132;; comment paragraph. To accomplish this, tabs are permanently
133;; replaced by spaces in the text surrounding the paragraph, which
134;; may be an undesirable side-effect. Replacing tabs with spaces is
135;; limited to comments only and occurs only when a comment
136;; paragraph is filled via `idlwave-fill-paragraph'.
137;;
52a244eb
S
138;; Muti-statement lines (using "&") on block begin and end lines can
139;; ruin the formatting. For example, multiple end statements on a
140;; line: endif & endif. Using "&" outside of block begin/end lines
141;; should be okay.
f32b3b91 142;;
76959b77
S
143;; Determining the expression at point for printing and other
144;; examination commands is somewhat rough: currently only fairly
145;; simple entities are found. You can always drag-select or examine
52a244eb 146;; a pre-selected region.
f32b3b91 147;;
f32b3b91
CD
148;; When forcing completion of method keywords, the initial
149;; query for a method has multiple entries for some methods. Would
595ab50b 150;; be too difficult to fix this hardly used case.
f32b3b91
CD
151;;
152\f
153;;; Code:
154
52a244eb 155
f32b3b91 156(eval-when-compile (require 'cl))
52a244eb
S
157(require 'idlw-help)
158
159;; For XEmacs
160(unless (fboundp 'line-beginning-position)
161 (defalias 'line-beginning-position 'point-at-bol))
162(unless (fboundp 'line-end-position)
163 (defalias 'line-end-position 'point-at-eol))
164(unless (fboundp 'char-valid-p)
165 (defalias 'char-valid-p 'characterp))
f66f03de
S
166(unless (fboundp 'match-string-no-properties)
167 (defalias 'match-string-no-properties 'match-string))
f32b3b91 168
3938cb82
S
169(if (not (fboundp 'cancel-timer))
170 (condition-case nil
171 (require 'timer)
172 (error nil)))
173
f32b3b91 174(eval-and-compile
5e72c6b2
S
175 ;; Kludge to allow `defcustom' for Emacs 19.
176 (condition-case () (require 'custom) (error nil))
177 (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
178 nil ;; We've got what we needed
179 ;; We have the old or no custom-library, hack around it!
180 (defmacro defgroup (&rest args) nil)
f66f03de 181 (defmacro defcustom (var value doc &rest args)
5e72c6b2 182 `(defvar ,var ,value ,doc))))
f32b3b91
CD
183
184(defgroup idlwave nil
31b58798 185 "Major mode for editing IDL .pro files."
f32b3b91 186 :tag "IDLWAVE"
f66f03de 187 :link '(url-link :tag "Home Page"
5e72c6b2 188 "http://idlwave.org")
595ab50b
CD
189 :link '(emacs-commentary-link :tag "Commentary in idlw-shell.el"
190 "idlw-shell.el")
f32b3b91
CD
191 :link '(emacs-commentary-link :tag "Commentary in idlwave.el" "idlwave.el")
192 :link '(custom-manual "(idlwave)Top")
193 :prefix "idlwave"
194 :group 'languages)
195
52a244eb 196
f32b3b91
CD
197;;; Variables for indentation behavior ---------------------------------------
198
199(defgroup idlwave-code-formatting nil
200 "Indentation and formatting options for IDLWAVE mode."
201 :group 'idlwave)
202
f66f03de 203(defcustom idlwave-main-block-indent 2
f32b3b91
CD
204 "*Extra indentation for the main block of code.
205That is the block between the FUNCTION/PRO statement and the END
206statement for that program unit."
207 :group 'idlwave-code-formatting
208 :type 'integer)
209
f66f03de 210(defcustom idlwave-block-indent 3
f32b3b91
CD
211 "*Extra indentation applied to block lines.
212If you change this, you probably also want to change `idlwave-end-offset'."
213 :group 'idlwave-code-formatting
214 :type 'integer)
215
f66f03de 216(defcustom idlwave-end-offset -3
f32b3b91
CD
217 "*Extra indentation applied to block END lines.
218A value equal to negative `idlwave-block-indent' will make END lines
219line up with the block BEGIN lines."
220 :group 'idlwave-code-formatting
221 :type 'integer)
222
f66f03de 223(defcustom idlwave-continuation-indent 3
f32b3b91
CD
224 "*Extra indentation applied to continuation lines.
225This extra offset applies to the first of a set of continuation lines.
5e72c6b2
S
226The following lines receive the same indentation as the first."
227 :group 'idlwave-code-formatting
228 :type 'integer)
229
f66f03de 230(defcustom idlwave-max-extra-continuation-indent 40
5e72c6b2
S
231 "*Maximum additional indentation for special continuation indent.
232Several special indentations are tried to help line up continuation
233lines in routine calls or definitions, other statements with
134b6671 234parentheses, or assignment statements. This variable specifies a
5e72c6b2
S
235maximum amount by which this special indentation can exceed the
236standard continuation indentation, otherwise defaulting to a fixed
237offset. Set to 0 to effectively disable all special continuation
238indentation, or to a large number (like 100) to enable it in all
52a244eb 239cases. See also `idlwave-indent-to-open-paren', which can override
5e72c6b2 240this variable."
f32b3b91
CD
241 :group 'idlwave-code-formatting
242 :type 'integer)
243
5e72c6b2
S
244(defcustom idlwave-indent-to-open-paren t
245 "*Non-nil means, indent continuation lines to innermost open
246parenthesis. This indentation occurs even if otherwise disallowed by
247`idlwave-max-extra-continuation-indent'. Matching parens and the
248interleaving args are lined up. Example:
249
250 x = function_a(function_b(function_c( a, b, [1,2,3, $
251 4,5,6 $
252 ], $
253 c, d $
254 )))
255
256When this variable is nil, paren alignment may still occur, based on
257the value of `max-extra-continuation-indent', which, if zero, would
258yield:
259
260 x = function_a(function_b(function_c( a, b, [1,2,3, $
261 4,5,6 $
262 ], $
263 c, d $
264 )))"
265 :group 'idlwave-code-formatting
266 :type 'boolean)
267
52a244eb
S
268(defcustom idlwave-indent-parens-nested nil
269 "*Non-nil means, indent continuation lines with parens by nesting
270lines at consecutively deeper levels."
271 :group 'idlwave-code-formatting
272 :type 'boolean)
273
274
f32b3b91
CD
275(defcustom idlwave-hanging-indent t
276 "*If set non-nil then comment paragraphs are indented under the
277hanging indent given by `idlwave-hang-indent-regexp' match in the first line
278of the paragraph."
279 :group 'idlwave-code-formatting
280 :type 'boolean)
281
282(defcustom idlwave-hang-indent-regexp "- "
283 "*Regular expression matching the position of the hanging indent
284in the first line of a comment paragraph. The size of the indent
285extends to the end of the match for the regular expression."
286 :group 'idlwave-code-formatting
287 :type 'regexp)
288
289(defcustom idlwave-use-last-hang-indent nil
290 "*If non-nil then use last match on line for `idlwave-indent-regexp'."
291 :group 'idlwave-code-formatting
292 :type 'boolean)
293
294(defcustom idlwave-fill-comment-line-only t
295 "*If non-nil then auto fill will only operate on comment lines."
296 :group 'idlwave-code-formatting
297 :type 'boolean)
298
299(defcustom idlwave-auto-fill-split-string t
300 "*If non-nil then auto fill will split strings with the IDL `+' operator.
f66f03de
S
301When the line end falls within a string, string concatenation with the
302'+' operator will be used to distribute a long string over lines.
f32b3b91
CD
303If nil and a string is split then a terminal beep and warning are issued.
304
305This variable is ignored when `idlwave-fill-comment-line-only' is
306non-nil, since in this case code is not auto-filled."
307 :group 'idlwave-code-formatting
308 :type 'boolean)
309
310(defcustom idlwave-split-line-string t
311 "*If non-nil then `idlwave-split-line' will split strings with `+'.
312When the splitting point of a line falls inside a string, split the string
313using the `+' string concatenation operator. If nil and a string is
314split then a terminal beep and warning are issued."
315 :group 'idlwave-code-formatting
316 :type 'boolean)
317
318(defcustom idlwave-no-change-comment ";;;"
319 "*The indentation of a comment that starts with this regular
320expression will not be changed. Note that the indentation of a comment
321at the beginning of a line is never changed."
322 :group 'idlwave-code-formatting
323 :type 'string)
324
325(defcustom idlwave-begin-line-comment nil
326 "*A comment anchored at the beginning of line.
327A comment matching this regular expression will not have its
328indentation changed. If nil the default is \"^;\", i.e., any line
329beginning with a \";\". Expressions for comments at the beginning of
330the line should begin with \"^\"."
331 :group 'idlwave-code-formatting
332 :type '(choice (const :tag "Any line beginning with `;'" nil)
333 'regexp))
334
335(defcustom idlwave-code-comment ";;[^;]"
336 "*A comment that starts with this regular expression on a line by
337itself is indented as if it is a part of IDL code. As a result if
338the comment is not preceded by whitespace it is unchanged."
339 :group 'idlwave-code-formatting
340 :type 'regexp)
341
342;; Comments not matching any of the above will be indented as a
343;; right-margin comment, i.e., to a minimum of `comment-column'.
344
f32b3b91
CD
345;;; Routine Info and Completion ---------------------------------------
346
15e42531
CD
347(defgroup idlwave-routine-info nil
348 "Routine Info options for IDLWAVE mode."
f32b3b91
CD
349 :group 'idlwave)
350
52a244eb
S
351(defcustom idlwave-use-library-catalogs t
352 "*Non-nil means search the IDL path for library catalog files.
353
354These files, named .idlwave_catalog, document routine information for
355individual directories and libraries of IDL .pro files. Many popular
356libraries come with catalog files by default, so leaving this on is a
357usually a good idea.."
358 :group 'idlwave-routine-info
359 :type 'boolean)
5e72c6b2
S
360
361(defcustom idlwave-init-rinfo-when-idle-after 10
f66f03de
S
362 "*Seconds of idle time before routine info is automatically
363initialized. Initializing the routine info can take a long time, in
364particular if a large number of library catalogs are involved. When
365Emacs is idle for more than the number of seconds specified by this
366variable, it starts the initialization. The process is split into
367five steps, in order to keep work interruption as short as possible.
368If one of the steps finishes, and no user input has arrived in the
369mean time, initialization proceeds immediately to the next step. A
370good value for this variable is about 1/3 of the time initialization
371take in your setup. So if you have a fast machine and no problems
372with a slow network connection, don't hesitate to set this to 2
373seconds. A Value of 0 means, don't initialize automatically, but
374instead wait until routine information is needed, and initialize
375then."
5e72c6b2
S
376 :group 'idlwave-routine-info
377 :type 'number)
378
f32b3b91 379(defcustom idlwave-scan-all-buffers-for-routine-info t
15e42531
CD
380 "*Non-nil means, scan buffers for IDL programs when updating info.
381The scanning is done by the command `idlwave-update-routine-info'.
382The following values are allowed:
383
384nil Don't scan any buffers.
385t Scan all idlwave-mode buffers in the current editing session.
386current Scan only the current buffer, but no other buffers."
387 :group 'idlwave-routine-info
388 :type '(choice
389 (const :tag "No buffer" nil)
390 (const :tag "All buffers" t)
391 (const :tag "Current buffer only" 'current)))
f32b3b91
CD
392
393(defcustom idlwave-query-shell-for-routine-info t
394 "*Non-nil means query the shell for info about compiled routines.
395Querying the shell is useful to get information about compiled modules,
396and it is turned on by default. However, when you have a complete library
397scan, this is not necessary."
15e42531 398 :group 'idlwave-routine-info
f32b3b91
CD
399 :type 'boolean)
400
15e42531
CD
401(defcustom idlwave-auto-routine-info-updates
402 '(find-file save-buffer kill-buffer compile-buffer)
403 "*Controls under what circumstances routine info is updated automatically.
404Possible values:
405nil Never
406t All available
facebc7b 407\(...) A list of circumstances. Allowed members are:
15e42531
CD
408 find-file Add info for new IDLWAVE buffers.
409 save-buffer Update buffer info when buffer is saved
410 kill-buffer Remove buffer info when buffer gets killed
411 compile-buffer Update shell info after `idlwave-shell-save-and...'"
412 :group 'idlwave-routine-info
413 :type '(choice
414 (const :tag "Never" nil)
415 (const :tag "As often as possible" t)
416 (set :tag "Checklist" :greedy t
417 (const :tag "When visiting a file" find-file)
418 (const :tag "When saving a buffer" save-buffer)
419 (const :tag "After a buffer was killed" kill-buffer)
420 (const :tag "After a buffer was compiled successfully, update shell info" compile-buffer))))
f66f03de 421
15e42531
CD
422(defcustom idlwave-rinfo-max-source-lines 5
423 "*Maximum number of source files displayed in the Routine Info window.
424When an integer, it is the maximum number of source files displayed.
425t means to show all source files."
426 :group 'idlwave-routine-info
427 :type 'integer)
428
f32b3b91 429(defcustom idlwave-library-path nil
f66f03de
S
430 "Library path for Windows and MacOS (OS9). Not needed under Unix.
431When selecting the directories to scan for IDL user catalog routine
432info, IDLWAVE can, under UNIX, query the shell for the exact search
433path \(the value of !PATH). However, under Windows and MacOS
434(pre-OSX), the IDLWAVE shell does not work. In this case, this
435variable can be set to specify the paths where IDLWAVE can find PRO
436files. The shell will only be asked for a list of paths when this
437variable is nil. The value is a list of directories. A directory
438preceeded by a `+' will be searched recursively. If you set this
439variable on a UNIX system, the shell will not be queried. See also
440`idlwave-system-directory'."
15e42531 441 :group 'idlwave-routine-info
f32b3b91
CD
442 :type '(repeat (directory)))
443
15e42531 444(defcustom idlwave-system-directory ""
52a244eb
S
445 "The IDL system directory for Windows and MacOS. Not needed under
446UNIX. Set this to the value of the `!DIR' system variable in IDL.
447IDLWAVE uses this to find out which of the library routines belong to
448the official system library. All files inside the `lib' subdirectory
449are considered system library files - so don't install private stuff
450in this directory. On UNIX systems, IDLWAVE queries the shell for the
451value of `!DIR'. See also `idlwave-library-path'."
15e42531
CD
452 :group 'idlwave-routine-info
453 :type 'directory)
454
f66f03de
S
455;; Configuration files
456(defcustom idlwave-config-directory
52a244eb
S
457 (convert-standard-filename "~/.idlwave")
458 "*Directory for configuration files and user-library catalog."
15e42531 459 :group 'idlwave-routine-info
f32b3b91
CD
460 :type 'file)
461
52a244eb 462(defvar idlwave-user-catalog-file "idlusercat.el")
f66f03de 463(defvar idlwave-xml-system-rinfo-converted-file "idl_xml_rinfo.el")
52a244eb
S
464(defvar idlwave-path-file "idlpath.el")
465
466(defvar idlwave-libinfo-file nil
467 "*Obsolete variable, no longer used.")
468
15e42531
CD
469(defcustom idlwave-special-lib-alist nil
470 "Alist of regular expressions matching special library directories.
471When listing routine source locations, IDLWAVE gives a short hint where
f66f03de 472the file defining the routine is located. By default it lists `SystemLib'
15e42531
CD
473for routines in the system library `!DIR/lib' and `Library' for anything
474else. This variable can define additional types. The car of each entry
475is a regular expression matching the file name (they normally will match
476on the path). The cdr is the string to be used as identifier. Max 10
477chars are allowed."
478 :group 'idlwave-routine-info
479 :type '(repeat
480 (cons regexp string)))
481
52a244eb 482(defcustom idlwave-auto-write-paths t
f66f03de 483 "Write out path (!PATH) and system directory (!DIR) info automatically.
52a244eb
S
484Path info is needed to locate library catalog files. If non-nil,
485whenever the path-list changes as a result of shell-query, etc., it is
486written to file. Otherwise, the menu option \"Write Paths\" can be
487used to force a write."
488 :group 'idlwave-routine-info
05a1abfc 489 :type 'boolean)
775591f7 490
15e42531
CD
491(defgroup idlwave-completion nil
492 "Completion options for IDLWAVE mode."
493 :prefix "idlwave"
494 :group 'idlwave)
495
f32b3b91
CD
496(eval-and-compile
497 (defconst idlwave-tmp
498 '(choice :tag "by applying the function"
499 (const upcase)
500 (const downcase)
501 (const capitalize)
502 (const preserve)
503 (symbol :tag "Other"))))
504
f32b3b91
CD
505(defcustom idlwave-completion-case '((routine . upcase)
506 (keyword . upcase)
507 (class . preserve)
508 (method . preserve))
509 "Association list setting the case of completed words.
510
511This variable determines the case (UPPER/lower/Capitalized...) of
512words inserted into the buffer by completion. The preferred case can
513be specified separately for routine names, keywords, classes and
f66f03de 514methods.
f32b3b91
CD
515This alist should therefore have entries for `routine' (normal
516functions and procedures, i.e. non-methods), `keyword', `class', and
517`method'. Plausible values are
518
519upcase upcase whole word, like `BOX_CURSOR'
520downcase downcase whole word, like `read_ppm'
521capitalize capitalize each part, like `Widget_Control'
522preserve preserve case as is, like `IDLgrView'
523
524The value can also be any Emacs Lisp function which transforms the
525case of characters in a string.
526
527A value of `preserve' means that the case of the completed word is
528identical to the way it was written in the definition statement of the
529routine. This was implemented to allow for mixed-case completion, in
530particular of object classes and methods.
531If a completable word is defined in multiple locations, the meaning of
532`preserve' is not unique since the different definitions might be
533cased differently. Therefore IDLWAVE always takes the case of the
534*first* definition it encounters during routine info collection and
535uses the case derived from it consistently.
536
537Note that a lowercase-only string in the buffer will always be completed in
538lower case (but see the variable `idlwave-completion-force-default-case').
539
540After changing this variable, you need to either restart Emacs or press
541`C-u C-c C-i' to update the internal lists."
15e42531 542 :group 'idlwave-completion
f32b3b91
CD
543 :type `(repeat
544 (cons (symbol :tag "Derive completion case for")
545 ,idlwave-tmp)))
546
547(defcustom idlwave-completion-force-default-case nil
548 "*Non-nil means, completion will always honor `idlwave-completion-case'.
549When nil, only the completion of a mixed case or upper case string
550will honor the default settings in `idlwave-completion-case', while
551the completion of lower case strings will be completed entirely in
552lower case."
15e42531 553 :group 'idlwave-completion
f32b3b91
CD
554 :type 'boolean)
555
556(defcustom idlwave-complete-empty-string-as-lower-case nil
557 "*Non-nil means, the empty string is considered downcase for completion.
558The case of what is already in the buffer determines the case of completions.
559When this variable is non-nil, the empty string is considered to be downcase.
560Completing on the empty string then offers downcase versions of the possible
561completions."
15e42531 562 :group 'idlwave-completion
f32b3b91
CD
563 :type 'boolean)
564
565(defvar idlwave-default-completion-case-is-down nil
566 "Obsolete variable. See `idlwave-complete-empty-string-as-lower-case' and
567`idlwave-completion-case'.")
568
569(defcustom idlwave-buffer-case-takes-precedence nil
570 "*Non-nil means, the case of tokens in buffers dominates over system stuff.
571To make this possible, we need to re-case everything each time we update
572the routine info from the buffers. This is slow.
573The default is to consider the case given in the system and library files
574first which makes updating much faster."
15e42531
CD
575 :group 'idlwave-completion
576 :type 'boolean)
577
578(defcustom idlwave-highlight-help-links-in-completion t
579 "*Non-nil means, highlight completions for which system help is available.
580Help can then be accessed with mouse-3.
581This option is only effective when the online help system is installed."
582 :group 'idlwave-completion
f32b3b91
CD
583 :type 'boolean)
584
05a1abfc
CD
585(defcustom idlwave-support-inheritance t
586 "Non-nil means, treat inheritance with completion, online help etc.
cef6cafe 587When nil, IDLWAVE only knows about the native methods and tags of a class,
05a1abfc
CD
588not about inherited ones."
589 :group 'idlwave-routine-info
590 :type 'boolean)
591
5e72c6b2
S
592(defcustom idlwave-keyword-class-inheritance '("^[gs]etproperty$" "^init$")
593 "List of regular expressions for class-driven keyword inheritance.
594Keyword inheritance is often tied to class inheritance by \"chaining\"
595up the class tree. While it cannot be assumed that the presence of an
596_EXTRA or _REF_EXTRA symbol guarantees such chaining will occur, for
597certain methods this assumption is almost always true. The methods
598for which to assume this can be set here."
599 :group 'idlwave-routine-info
600 :type '(repeat (regexp :tag "Match method:")))
f66f03de 601
5e72c6b2 602
f32b3b91
CD
603(defcustom idlwave-completion-show-classes 1
604 "*Number of classes to show when completing object methods and keywords.
605When completing methods or keywords for an object with unknown class,
2e8b9c7d 606the *Completions* buffer will show the valid classes for each completion
f32b3b91
CD
607like this:
608
609MyMethod <Class1,Class2,Class3>
610
611The value of this variable may be nil to inhibit display, or an integer to
612indicate the maximum number of classes to display.
613
614On XEmacs, a full list of classes will also be placed into a `help-echo'
615property on the competion items, so that the list of classes for the current
616item is displayed in the echo area. If the value of this variable is a
617negative integer, the `help-echo' property will be suppressed."
15e42531 618 :group 'idlwave-completion
f32b3b91
CD
619 :type '(choice (const :tag "Don't show" nil)
620 (integer :tag "Number of classes shown" 1)))
621
622(defcustom idlwave-completion-fontify-classes t
623 "*Non-nil means, fontify the classes in completions buffer.
624This makes it easier to distinguish the completion items from the extra
625class info listed. See `idlwave-completion-show-classes'."
15e42531 626 :group 'idlwave-completion
f32b3b91
CD
627 :type 'boolean)
628
629(defcustom idlwave-query-class '((method-default . nil)
630 (keyword-default . nil))
631 "Association list governing specification of object classes for completion.
632
5e72c6b2
S
633When IDLWAVE tries to complete object-oriented methods, it usually
634cannot determine the class of a given object from context. In order
635to provide the user with a correct list of methods or keywords, it
76959b77
S
636needs to determine the appropriate class. IDLWAVE has two ways of
637doing this (well, three ways if you count the shell... see
638`idlwave-shell-query-for-class'):
639
6401. Combine the items of all available classes which contain this
641 method for the purpose of completion. So when completing a method,
642 all methods of all known classes are available, and when completing
643 a keyword, all keywords allowed for this method in any class are
644 shown. This behavior is very much like normal completion and is
645 therefore the default. It works much better than one might think -
646 only for the INIT, GETPROPERTY and SETPROPERTY the keyword lists
647 become uncomfortably long. See also
5e72c6b2 648 `idlwave-completion-show-classes'.
f32b3b91
CD
649
6502. The second possibility is to ask the user on each occasion. To
651 make this less interruptive, IDLWAVE can store the class as a text
652 property on the object operator `->'. For a given object in the
653 source code, class selection will then be needed only once
654 - for example to complete the method. Keywords to the method can
655 then be completed directly, because the class is already known.
656 You will have to turn on the storage of the selected class
657 explicitly with the variable `idlwave-store-inquired-class'.
658
5e72c6b2
S
659This variable allows you to configure IDLWAVE's method and
660method-keyword completion behavior. Its value is an alist, which
661should contain at least two elements: (method-default . VALUE) and
facebc7b 662\(keyword-default . VALUE), where VALUE is either t or nil. These
5e72c6b2
S
663specify if the class should be found during method and keyword
664completion, respectively.
f32b3b91 665
f66f03de 666The alist may have additional entries specifying exceptions from the
f32b3b91
CD
667keyword completion rule for specific methods, like INIT or
668GETPROPERTY. In order to turn on class specification for the INIT
669method, add an entry (\"INIT\" . t). The method name must be ALL-CAPS."
15e42531 670 :group 'idlwave-completion
f32b3b91
CD
671 :type '(list
672 (cons (const method-default)
673 (boolean :tag "Determine class when completing METHODS "))
674 (cons (const keyword-default)
675 (boolean :tag "Determine class when completing KEYWORDS "))
676 (repeat
677 :tag "Exceptions to defaults"
678 :inline t
679 (cons (string :tag "MODULE" :value "")
680 (boolean :tag "Determine class for this method")))))
681
f66f03de 682(defcustom idlwave-store-inquired-class t
f32b3b91
CD
683 "*Non-nil means, store class of a method call as text property on `->'.
684IDLWAVE sometimes has to ask the user for the class associated with a
685particular object method call. This happens during the commands
686`idlwave-routine-info' and `idlwave-complete', depending upon the
687value of the variable `idlwave-query-class'.
688
689When you specify a class, this information can be stored as a text
f66f03de 690property on the `->' arrow in the source code, so that during the same
f32b3b91
CD
691editing session, IDLWAVE will not have to ask again. When this
692variable is non-nil, IDLWAVE will store and reuse the class information.
693The class stored can be checked and removed with `\\[idlwave-routine-info]'
694on the arrow.
695
696The default of this variable is nil, since the result of commands then
697is more predictable. However, if you know what you are doing, it can
698be nice to turn this on.
699
700An arrow which knows the class will be highlighted with
701`idlwave-class-arrow-face'. The command \\[idlwave-routine-info]
702displays (with prefix arg: deletes) the class stored on the arrow
703at point."
15e42531 704 :group 'idlwave-completion
f32b3b91
CD
705 :type 'boolean)
706
707(defcustom idlwave-class-arrow-face 'bold
708 "*Face to highlight object operator arrows `->' which carry a class property.
709When IDLWAVE stores a class name as text property on an object arrow
facebc7b 710\(see variable `idlwave-store-inquired-class', it highlights the arrow
f32b3b91 711with this font in order to remind the user that this arrow is special."
15e42531 712 :group 'idlwave-completion
f32b3b91
CD
713 :type 'symbol)
714
715(defcustom idlwave-resize-routine-help-window t
716 "*Non-nil means, resize the Routine-info *Help* window to fit the content."
15e42531 717 :group 'idlwave-completion
f32b3b91
CD
718 :type 'boolean)
719
720(defcustom idlwave-keyword-completion-adds-equal t
721 "*Non-nil means, completion automatically adds `=' after completed keywords."
15e42531 722 :group 'idlwave-completion
f32b3b91
CD
723 :type 'boolean)
724
725(defcustom idlwave-function-completion-adds-paren t
726 "*Non-nil means, completion automatically adds `(' after completed function.
0ff9b955 727nil means, don't add anything.
f32b3b91
CD
728A value of `2' means, also add the closing parenthesis and position cursor
729between the two."
15e42531 730 :group 'idlwave-completion
f32b3b91
CD
731 :type '(choice (const :tag "Nothing" nil)
732 (const :tag "(" t)
733 (const :tag "()" 2)))
734
735(defcustom idlwave-completion-restore-window-configuration t
736 "*Non-nil means, try to restore the window configuration after completion.
737When completion is not unique, Emacs displays a list of completions.
738This messes up your window configuration. With this variable set, IDLWAVE
739restores the old configuration after successful completion."
15e42531 740 :group 'idlwave-completion
f32b3b91
CD
741 :type 'boolean)
742
743;;; Variables for abbrev and action behavior -----------------------------
744
745(defgroup idlwave-abbrev-and-indent-action nil
746 "IDLWAVE performs actions when expanding abbreviations or indenting lines.
747The variables in this group govern this."
748 :group 'idlwave)
749
750(defcustom idlwave-do-actions nil
751 "*Non-nil means performs actions when indenting.
752The actions that can be performed are listed in `idlwave-indent-action-table'."
753 :group 'idlwave-abbrev-and-indent-action
754 :type 'boolean)
755
756(defcustom idlwave-abbrev-start-char "\\"
757 "*A single character string used to start abbreviations in abbrev mode.
758Possible characters to chose from: ~`\%
759or even '?'. '.' is not a good choice because it can make structure
760field names act like abbrevs in certain circumstances.
761
762Changes to this in `idlwave-mode-hook' will have no effect. Instead a user
763must set it directly using `setq' in the .emacs file before idlwave.el
764is loaded."
765 :group 'idlwave-abbrev-and-indent-action
766 :type 'string)
767
768(defcustom idlwave-surround-by-blank nil
769 "*Non-nil means, enable `idlwave-surround'.
595ab50b 770If non-nil, `=',`<',`>',`&',`,', `->' are surrounded with spaces by
f32b3b91
CD
771`idlwave-surround'.
772See help for `idlwave-indent-action-table' for symbols using `idlwave-surround'.
773
774Also see the default key bindings for keys using `idlwave-surround'.
775Keys are bound and made into actions calling `idlwave-surround' with
776`idlwave-action-and-binding'.
777See help for `idlwave-action-and-binding' for examples.
778
779Also see help for `idlwave-surround'."
780 :group 'idlwave-abbrev-and-indent-action
781 :type 'boolean)
782
783(defcustom idlwave-pad-keyword t
52a244eb
S
784 "*Non-nil means pad '=' in keywords (routine calls or defs) like assignment.
785Whenever `idlwave-surround' is non-nil then this affects how '=' is
786padded for keywords and for variables. If t, pad the same as for
787assignments. If nil then spaces are removed. With any other value,
788spaces are left unchanged."
f32b3b91 789 :group 'idlwave-abbrev-and-indent-action
15e42531
CD
790 :type '(choice
791 (const :tag "Pad like assignments" t)
792 (const :tag "Remove space near `='" nil)
793 (const :tag "Keep space near `='" 'keep)))
f32b3b91
CD
794
795(defcustom idlwave-show-block t
796 "*Non-nil means point blinks to block beginning for `idlwave-show-begin'."
797 :group 'idlwave-abbrev-and-indent-action
798 :type 'boolean)
799
800(defcustom idlwave-expand-generic-end nil
801 "*Non-nil means expand generic END to ENDIF/ENDELSE/ENDWHILE etc."
802 :group 'idlwave-abbrev-and-indent-action
803 :type 'boolean)
804
15e42531
CD
805(defcustom idlwave-reindent-end t
806 "*Non-nil means re-indent line after END was typed."
807 :group 'idlwave-abbrev-and-indent-action
808 :type 'boolean)
809
f32b3b91
CD
810(defcustom idlwave-abbrev-move t
811 "*Non-nil means the abbrev hook can move point.
812Set to nil by `idlwave-expand-region-abbrevs'. To see the abbrev
813definitions, use the command `list-abbrevs', for abbrevs that move
814point. Moving point is useful, for example, to place point between
815parentheses of expanded functions.
816
817See `idlwave-check-abbrev'."
818 :group 'idlwave-abbrev-and-indent-action
819 :type 'boolean)
820
821(defcustom idlwave-abbrev-change-case nil
822 "*Non-nil means all abbrevs will be forced to either upper or lower case.
823If the value t, all expanded abbrevs will be upper case.
824If the value is 'down then abbrevs will be forced to lower case.
825If nil, the case will not change.
826If `idlwave-reserved-word-upcase' is non-nil, reserved words will always be
827upper case, regardless of this variable."
828 :group 'idlwave-abbrev-and-indent-action
829 :type 'boolean)
830
831(defcustom idlwave-reserved-word-upcase nil
832 "*Non-nil means, reserved words will be made upper case via abbrev expansion.
833If nil case of reserved words is controlled by `idlwave-abbrev-change-case'.
834Has effect only if in abbrev-mode."
835 :group 'idlwave-abbrev-and-indent-action
836 :type 'boolean)
837
838;;; Action/Expand Tables.
839;;
840;; The average user may have difficulty modifying this directly. It
841;; can be modified/set in idlwave-mode-hook, but it is easier to use
842;; idlwave-action-and-binding. See help for idlwave-action-and-binding for
843;; examples of how to add an action.
844;;
845;; The action table is used by `idlwave-indent-line' whereas both the
846;; action and expand tables are used by `idlwave-indent-and-action'. In
847;; general, the expand table is only used when a line is explicitly
848;; indented. Whereas, in addition to being used when the expand table
849;; is used, the action table is used when a line is indirectly
850;; indented via line splitting, auto-filling or a new line creation.
851;;
852;; Example actions:
853;;
854;; Capitalize system vars
855;; (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)
856;;
857;; Capitalize procedure name
858;; (idlwave-action-and-binding "\\<\\(pro\\|function\\)\\>[ \t]*\\<"
859;; '(capitalize-word 1) t)
860;;
861;; Capitalize common block name
862;; (idlwave-action-and-binding "\\<common\\>[ \t]+\\<"
863;; '(capitalize-word 1) t)
864;; Capitalize label
865;; (idlwave-action-and-binding (concat "^[ \t]*" idlwave-label)
866;; '(capitalize-word -1) t)
867
868(defvar idlwave-indent-action-table nil
869 "*Associated array containing action lists of search string (car),
870and function as a cdr. This table is used by `idlwave-indent-line'.
871See documentation for `idlwave-do-action' for a complete description of
872the action lists.
873
874Additions to the table are made with `idlwave-action-and-binding' when a
875binding is not requested.
876See help on `idlwave-action-and-binding' for examples.")
877
878(defvar idlwave-indent-expand-table nil
879 "*Associated array containing action lists of search string (car),
880and function as a cdr. The table is used by the
881`idlwave-indent-and-action' function. See documentation for
882`idlwave-do-action' for a complete description of the action lists.
883
884Additions to the table are made with `idlwave-action-and-binding' when a
885binding is requested.
886See help on `idlwave-action-and-binding' for examples.")
887
888;;; Documentation header and history keyword ---------------------------------
889
890(defgroup idlwave-documentation nil
891 "Options for documenting IDLWAVE files."
892 :group 'idlwave)
893
894;; FIXME: make defcustom?
895(defvar idlwave-file-header
896 (list nil
897 ";+
898; NAME:
899;
900;
901;
902; PURPOSE:
903;
904;
905;
906; CATEGORY:
907;
908;
909;
910; CALLING SEQUENCE:
911;
912;
913;
914; INPUTS:
915;
916;
917;
918; OPTIONAL INPUTS:
919;
920;
921;
922; KEYWORD PARAMETERS:
923;
924;
925;
926; OUTPUTS:
927;
928;
929;
930; OPTIONAL OUTPUTS:
931;
932;
933;
934; COMMON BLOCKS:
935;
936;
937;
938; SIDE EFFECTS:
939;
940;
941;
942; RESTRICTIONS:
943;
944;
945;
946; PROCEDURE:
947;
948;
949;
950; EXAMPLE:
951;
952;
953;
954; MODIFICATION HISTORY:
955;
956;-
957")
958 "*A list (PATHNAME STRING) specifying the doc-header template to use for
959summarizing a file. If PATHNAME is non-nil then this file will be included.
0ff9b955 960Otherwise STRING is used. If nil, the file summary will be omitted.
f32b3b91
CD
961For example you might set PATHNAME to the path for the
962lib_template.pro file included in the IDL distribution.")
963
f66f03de 964(defcustom idlwave-header-to-beginning-of-file t
5e72c6b2
S
965 "*Non-nil means, the documentation header will always be at start of file.
966When nil, the header is positioned between the PRO/FUNCTION line of
967the current routine and the code, allowing several routine headers in
968a file."
969 :group 'idlwave-documentation
970 :type 'boolean)
971
f32b3b91
CD
972(defcustom idlwave-timestamp-hook 'idlwave-default-insert-timestamp
973 "*The hook function used to update the timestamp of a function."
974 :group 'idlwave-documentation
975 :type 'function)
976
977(defcustom idlwave-doc-modifications-keyword "HISTORY"
978 "*The modifications keyword to use with the log documentation commands.
979A ':' is added to the keyword end.
980Inserted by doc-header and used to position logs by doc-modification.
981If nil it will not be inserted."
982 :group 'idlwave-documentation
983 :type 'string)
984
985(defcustom idlwave-doclib-start "^;+\\+"
986 "*Regexp matching the start of a document library header."
987 :group 'idlwave-documentation
988 :type 'regexp)
989
990(defcustom idlwave-doclib-end "^;+-"
991 "*Regexp matching the end of a document library header."
992 :group 'idlwave-documentation
993 :type 'regexp)
994
995;;; External Programs -------------------------------------------------------
996
997(defgroup idlwave-external-programs nil
05a1abfc 998 "Path locations of external commands used by IDLWAVE."
f32b3b91
CD
999 :group 'idlwave)
1000
f32b3b91 1001(defcustom idlwave-shell-explicit-file-name "idl"
5e72c6b2 1002 "*If non-nil, this is the command to run IDL.
f32b3b91 1003Should be an absolute file path or path relative to the current environment
5e72c6b2
S
1004execution search path. If you want to specify command line switches
1005for the idl program, use `idlwave-shell-command-line-options'.
1006
1007I know the name of this variable is badly chosen, but I cannot change
1008it without compromizing backwards-compatibility."
f32b3b91
CD
1009 :group 'idlwave-external-programs
1010 :type 'string)
1011
f32b3b91 1012(defcustom idlwave-shell-command-line-options nil
5e72c6b2
S
1013 "*A list of command line options for calling the IDL program.
1014Since IDL is executed directly without going through a shell like /bin/sh,
1015this should be a list of strings like '(\"-rt=file\" \"-nw\") with a separate
1016string for each argument. But you may also give a single string which
1017contains the options whitespace-separated. Emacs will be kind enough to
1018split it for you."
1019 :type '(choice
1020 string
1021 (repeat (string :value "")))
f32b3b91
CD
1022 :group 'idlwave-external-programs)
1023
1024(defcustom idlwave-help-application "idlhelp"
f66f03de
S
1025 "*The external application providing reference help for programming.
1026Obsolete, if the IDL Assistant is being used for help."
f32b3b91
CD
1027 :group 'idlwave-external-programs
1028 :type 'string)
1029
05a1abfc
CD
1030;;; Some Shell variables which must be defined here.-----------------------
1031
1032(defcustom idlwave-shell-debug-modifiers '()
1033 "List of modifiers to be used for the debugging commands.
1034Will be used to bind debugging commands in the shell buffer and in all
1035source buffers. These are additional convenience bindings, the debugging
1036commands are always available with the `C-c C-d' prefix.
1037If you set this to '(control shift), this means setting a breakpoint will
1038be on `C-S-b', compiling a source file on `C-S-c' etc. Possible modifiers
1039are `control', `meta', `super', `hyper', `alt', and `shift'."
1040 :group 'idlwave-shell-general-setup
1041 :type '(set :tag "Specify modifiers"
1042 (const control)
1043 (const meta)
1044 (const super)
1045 (const hyper)
1046 (const alt)
1047 (const shift)))
1048
1049(defcustom idlwave-shell-automatic-start nil
1050 "*If non-nil attempt invoke idlwave-shell if not already running.
1051This is checked when an attempt to send a command to an
1052IDL process is made."
1053 :group 'idlwave-shell-general-setup
1054 :type 'boolean)
1055
f32b3b91
CD
1056;;; Miscellaneous variables -------------------------------------------------
1057
1058(defgroup idlwave-misc nil
1059 "Miscellaneous options for IDLWAVE mode."
8ec3bce0 1060 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
f32b3b91
CD
1061 :group 'idlwave)
1062
1063(defcustom idlwave-startup-message t
1064 "*Non-nil displays a startup message when `idlwave-mode' is first called."
1065 :group 'idlwave-misc
1066 :type 'boolean)
1067
f66f03de 1068(defcustom idlwave-default-font-lock-items
facebc7b 1069 '(pros-and-functions batch-files idlwave-idl-keywords label goto
f32b3b91
CD
1070 common-blocks class-arrows)
1071 "Items which should be fontified on the default fontification level 2.
1072IDLWAVE defines 3 levels of fontification. Level 1 is very little, level 3
1073is everything and level 2 is specified by this list.
1074This variable must be set before IDLWAVE gets loaded. It is
1075a list of symbols, the following symbols are allowed.
1076
1077pros-and-functions Procedure and Function definitions
1078batch-files Batch Files
facebc7b 1079idlwave-idl-keywords IDL Keywords
f32b3b91
CD
1080label Statement Labels
1081goto Goto Statements
1082common-blocks Common Blocks
1083keyword-parameters Keyword Parameters in routine definitions and calls
1084system-variables System Variables
1085fixme FIXME: Warning in comments (on XEmacs only v. 21.0 and up)
1086class-arrows Object Arrows with class property"
1087 :group 'idlwave-misc
1088 :type '(set
1089 :inline t :greedy t
1090 (const :tag "Procedure and Function definitions" pros-and-functions)
facebc7b
S
1091 (const :tag "Batch Files" batch-files)
1092 (const :tag "IDL Keywords (reserved words)" idlwave-idl-keywords)
1093 (const :tag "Statement Labels" label)
1094 (const :tag "Goto Statements" goto)
1095 (const :tag "Tags in Structure Definition" structtag)
1096 (const :tag "Structure Name" structname)
1097 (const :tag "Common Blocks" common-blocks)
1098 (const :tag "Keyword Parameters" keyword-parameters)
1099 (const :tag "System Variables" system-variables)
1100 (const :tag "FIXME: Warning" fixme)
f32b3b91
CD
1101 (const :tag "Object Arrows with class property " class-arrows)))
1102
1103(defcustom idlwave-mode-hook nil
1104 "Normal hook. Executed when a buffer is put into `idlwave-mode'."
1105 :group 'idlwave-misc
1106 :type 'hook)
1107
1108(defcustom idlwave-load-hook nil
1109 "Normal hook. Executed when idlwave.el is loaded."
1110 :group 'idlwave-misc
1111 :type 'hook)
1112
15e42531
CD
1113(defvar idlwave-experimental nil
1114 "Non-nil means turn on a few experimental features.
1115This variable is only for the maintainer, to test difficult stuff,
1116while still distributing stable releases.
1117As a user, you should not set this to t.")
1118
f32b3b91
CD
1119;;;
1120;;; End customization variables section
1121;;;
1122
1123;;; Non customization variables
1124
1125;;; font-lock mode - Additions by Phil Williams, Ulrik Dickow and
52a244eb 1126;;; Simon Marshall <simon_at_gnu.ai.mit.edu>
f32b3b91
CD
1127;;; and Carsten Dominik...
1128
76959b77 1129;; The following are the reserved words in IDL. Maybe we should
f66f03de 1130;; highlight some more stuff as well?
76959b77
S
1131;; Procedure declarations. Fontify keyword plus procedure name.
1132(defvar idlwave-idl-keywords
f66f03de 1133 ;; To update this regexp, update the list of keywords and
76959b77 1134 ;; evaluate the form.
f66f03de 1135 ;; (insert
76959b77 1136 ;; (prin1-to-string
f66f03de 1137 ;; (concat
76959b77 1138 ;; "\\<\\("
f66f03de 1139 ;; (regexp-opt
52a244eb 1140 ;; '("||" "&&" "and" "or" "xor" "not"
f66f03de 1141 ;; "eq" "ge" "gt" "le" "lt" "ne"
76959b77 1142 ;; "for" "do" "endfor"
f66f03de 1143 ;; "if" "then" "endif" "else" "endelse"
76959b77
S
1144 ;; "case" "of" "endcase"
1145 ;; "switch" "break" "continue" "endswitch"
1146 ;; "begin" "end"
1147 ;; "repeat" "until" "endrep"
f66f03de 1148 ;; "while" "endwhile"
76959b77
S
1149 ;; "goto" "return"
1150 ;; "inherits" "mod"
1151 ;; "compile_opt" "forward_function"
1152 ;; "on_error" "on_ioerror")) ; on_error is not officially reserved
1153 ;; "\\)\\>")))
52a244eb
S
1154 "\\<\\(&&\\|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\\|||\\)\\>")
1155
76959b77 1156
facebc7b 1157(let* (;; Procedure declarations. Fontify keyword plus procedure name.
f32b3b91
CD
1158 ;; Function declarations. Fontify keyword plus function name.
1159 (pros-and-functions
1160 '("\\<\\(function\\|pro\\)\\>[ \t]+\\(\\sw+\\(::\\sw+\\)?\\)"
1161 (1 font-lock-keyword-face)
1162 (2 font-lock-function-name-face nil t)))
1163
1164 ;; Common blocks
1165 (common-blocks
1166 '("\\<\\(common\\)\\>[ \t]*\\(\\sw+\\)?[ \t]*,?"
1167 (1 font-lock-keyword-face) ; "common"
1168 (2 font-lock-reference-face nil t) ; block name
f66f03de 1169 ("[ \t]*\\(\\sw+\\)[ ,]*"
f32b3b91 1170 ;; Start with point after block name and comma
f66f03de 1171 (goto-char (match-end 0)) ; needed for XEmacs, could be nil
f32b3b91
CD
1172 nil
1173 (1 font-lock-variable-name-face) ; variable names
1174 )))
1175
1176 ;; Batch files
1177 (batch-files
1178 '("^[ \t]*\\(@[^ \t\n]+\\)" (1 font-lock-string-face)))
1179
1180 ;; FIXME warning.
1181 (fixme
1182 '("\\<FIXME:" (0 font-lock-warning-face t)))
1183
1184 ;; Labels
1185 (label
1186 '("^[ \t]*\\([a-zA-Z]\\sw*:\\)" (1 font-lock-reference-face)))
1187
1188 ;; The goto statement and its label
1189 (goto
1190 '("\\(goto\\)[ \t]*,[ \t]*\\([a-zA-Z]\\sw*\\)"
1191 (1 font-lock-keyword-face)
1192 (2 font-lock-reference-face)))
1193
52a244eb
S
1194 ;; Tags in structure definitions. Note that this definition
1195 ;; actually collides with labels, so we have to use the same
1196 ;; face. It also matches named subscript ranges,
1197 ;; e.g. vec{bottom:top]. No good way around this.
05a1abfc
CD
1198 (structtag
1199 '("\\<\\([a-zA-Z][a-zA-Z0-9_]*:\\)[^:]" (1 font-lock-reference-face)))
1200
1201 ;; Structure names
1202 (structname
1203 '("\\({\\|\\<inherits\\s-\\)\\s-*\\([a-zA-Z][a-zA-Z0-9_]*\\)[},\t \n]"
1204 (2 font-lock-function-name-face)))
1205
52a244eb 1206 ;; Keyword parameters, like /xlog or ,xrange=[]
f32b3b91 1207 ;; This is anchored to the comma preceeding the keyword.
595ab50b
CD
1208 ;; Treats continuation lines, works only during whole buffer
1209 ;; fontification. Slow, use it only in fancy fontification.
f32b3b91 1210 (keyword-parameters
0dc2be2f
S
1211 '("\\(,\\|[a-zA-Z0-9_](\\)[ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\([ \t]*\\(;.*\\)?\n\\)*[ \t]*\\)?\\(/[a-zA-Z_]\\sw*\\|[a-zA-Z_]\\sw*[ \t]*=\\)"
1212 (6 font-lock-reference-face)))
f32b3b91 1213
595ab50b 1214 ;; System variables start with a bang.
f32b3b91 1215 (system-variables
15e42531 1216 '("\\(![a-zA-Z_0-9]+\\(\\.\\sw+\\)?\\)"
f32b3b91
CD
1217 (1 font-lock-variable-name-face)))
1218
1219 ;; Special and unusual operators (not used because too noisy)
1220 (special-operators
1221 '("[<>#]" (0 font-lock-keyword-face)))
1222
1223 ;; All operators (not used because too noisy)
1224 (all-operators
1225 '("[-*^#+<>/]" (0 font-lock-keyword-face)))
f66f03de 1226
f32b3b91
CD
1227 ;; Arrows with text property `idlwave-class'
1228 (class-arrows
facebc7b
S
1229 '(idlwave-match-class-arrows (0 idlwave-class-arrow-face))))
1230
1231 (defconst idlwave-font-lock-keywords-1
1232 (list pros-and-functions batch-files)
1233 "Subdued level highlighting for IDLWAVE mode.")
f32b3b91 1234
facebc7b
S
1235 (defconst idlwave-font-lock-keywords-2
1236 (mapcar 'symbol-value idlwave-default-font-lock-items)
1237 "Medium level highlighting for IDLWAVE mode.")
f32b3b91 1238
facebc7b 1239 (defconst idlwave-font-lock-keywords-3
f32b3b91
CD
1240 (list pros-and-functions
1241 batch-files
76959b77 1242 idlwave-idl-keywords
f32b3b91 1243 label goto
05a1abfc
CD
1244 structtag
1245 structname
f32b3b91
CD
1246 common-blocks
1247 keyword-parameters
1248 system-variables
facebc7b
S
1249 class-arrows)
1250 "Gaudy level highlighting for IDLWAVE mode."))
f32b3b91
CD
1251
1252(defun idlwave-match-class-arrows (limit)
1253 ;; Match an object arrow with class property
1254 (and idlwave-store-inquired-class
1255 (re-search-forward "->" limit 'limit)
1256 (get-text-property (match-beginning 0) 'idlwave-class)))
1257
1258(defvar idlwave-font-lock-keywords idlwave-font-lock-keywords-2
1259 "Default expressions to highlight in IDLWAVE mode.")
1260
1261(defvar idlwave-font-lock-defaults
1262 '((idlwave-font-lock-keywords
f66f03de 1263 idlwave-font-lock-keywords-1
f32b3b91
CD
1264 idlwave-font-lock-keywords-2
1265 idlwave-font-lock-keywords-3)
f66f03de
S
1266 nil t
1267 ((?$ . "w") (?_ . "w") (?. . "w") (?| . "w") (?& . "w"))
f32b3b91
CD
1268 beginning-of-line))
1269
f66f03de 1270(put 'idlwave-mode 'font-lock-defaults
f32b3b91
CD
1271 idlwave-font-lock-defaults) ; XEmacs
1272
1273(defconst idlwave-comment-line-start-skip "^[ \t]*;"
1274 "Regexp to match the start of a full-line comment.
1275That is the _beginning_ of a line containing a comment delimiter `;' preceded
1276only by whitespace.")
1277
f66f03de 1278(defconst idlwave-begin-block-reg
05a1abfc 1279 "\\<\\(pro\\|function\\|begin\\|case\\|switch\\)\\>"
f32b3b91
CD
1280 "Regular expression to find the beginning of a block. The case does
1281not matter. The search skips matches in comments.")
1282
52a244eb 1283(defconst idlwave-begin-unit-reg "^\\s-*\\(pro\\|function\\)\\>\\|\\`"
f32b3b91
CD
1284 "Regular expression to find the beginning of a unit. The case does
1285not matter.")
1286
52a244eb 1287(defconst idlwave-end-unit-reg "^\\s-*\\(pro\\|function\\)\\>\\|\\'"
f32b3b91
CD
1288 "Regular expression to find the line that indicates the end of unit.
1289This line is the end of buffer or the start of another unit. The case does
1290not matter. The search skips matches in comments.")
1291
1292(defconst idlwave-continue-line-reg "\\<\\$"
1293 "Regular expression to match a continued line.")
1294
1295(defconst idlwave-end-block-reg
05a1abfc 1296 "\\<end\\(\\|case\\|switch\\|else\\|for\\|if\\|rep\\|while\\)\\>"
f32b3b91
CD
1297 "Regular expression to find the end of a block. The case does
1298not matter. The search skips matches found in comments.")
1299
1300(defconst idlwave-block-matches
1301 '(("pro" . "end")
1302 ("function" . "end")
1303 ("case" . "endcase")
1304 ("else" . "endelse")
1305 ("for" . "endfor")
1306 ("then" . "endif")
1307 ("repeat" . "endrep")
05a1abfc 1308 ("switch" . "endswitch")
f32b3b91
CD
1309 ("while" . "endwhile"))
1310 "Matches between statements and the corresponding END variant.
1311The cars are the reserved words starting a block. If the block really
1312begins with BEGIN, the cars are the reserved words before the begin
1313which can be used to identify the block type.
1314This is used to check for the correct END type, to close blocks and
1315to expand generic end statements to their detailed form.")
1316
1317(defconst idlwave-block-match-regexp
1318 "\\<\\(else\\|for\\|then\\|repeat\\|while\\)\\>"
1319"Regular expression matching reserved words which can stand before
1320blocks starting with a BEGIN statement. The matches must have associations
1321`idlwave-block-matches'")
1322
52a244eb 1323(defconst idlwave-identifier "[a-zA-Z_][a-zA-Z0-9$_]*"
f32b3b91
CD
1324 "Regular expression matching an IDL identifier.")
1325
1326(defconst idlwave-sysvar (concat "!" idlwave-identifier)
1327 "Regular expression matching IDL system variables.")
1328
1329(defconst idlwave-variable (concat idlwave-identifier "\\|" idlwave-sysvar)
1330 "Regular expression matching IDL variable names.")
1331
1332(defconst idlwave-label (concat idlwave-identifier ":")
1333 "Regular expression matching IDL labels.")
1334
52a244eb
S
1335(defconst idlwave-method-call (concat idlwave-identifier "\\s *->"
1336 "\\(\\s *" idlwave-identifier "::\\)?"
1337))
1338
f32b3b91
CD
1339(defconst idlwave-statement-match
1340 (list
aa87aafc 1341 ;; "endif else" is the only possible "end" that can be
f32b3b91
CD
1342 ;; followed by a statement on the same line.
1343 '(endelse . ("end\\(\\|if\\)\\s +else" "end\\(\\|if\\)\\s +else"))
1344 ;; all other "end"s can not be followed by a statement.
1345 (cons 'end (list idlwave-end-block-reg nil))
1346 '(if . ("if\\>" "then"))
1347 '(for . ("for\\>" "do"))
1348 '(begin . ("begin\\>" nil))
1349 '(pdef . ("pro\\>\\|function\\>" nil))
1350 '(while . ("while\\>" "do"))
1351 '(repeat . ("repeat\\>" "repeat"))
1352 '(goto . ("goto\\>" nil))
1353 '(case . ("case\\>" nil))
05a1abfc 1354 '(switch . ("switch\\>" nil))
f66f03de 1355 (cons 'call (list (concat "\\(" idlwave-variable "\\) *= *"
52a244eb
S
1356 "\\(" idlwave-method-call "\\s *\\)?"
1357 idlwave-identifier
1358 "\\s *(") nil))
f66f03de 1359 (cons 'call (list (concat
52a244eb 1360 "\\(" idlwave-method-call "\\s *\\)?"
f66f03de 1361 idlwave-identifier
52a244eb 1362 "\\( *\\($\\|\\$\\)\\|\\s *,\\)") nil))
f66f03de 1363 (cons 'assign (list (concat
52a244eb 1364 "\\(" idlwave-variable "\\) *=") nil)))
f66f03de 1365
f32b3b91
CD
1366 "Associated list of statement matching regular expressions.
1367Each regular expression matches the start of an IDL statement. The
1368first element of each association is a symbol giving the statement
1369type. The associated value is a list. The first element of this list
1370is a regular expression matching the start of an IDL statement for
1371identifying the statement type. The second element of this list is a
1372regular expression for finding a substatement for the type. The
1373substatement starts after the end of the found match modulo
1374whitespace. If it is nil then the statement has no substatement. The
1375list order matters since matching an assignment statement exactly is
1376not possible without parsing. Thus assignment statement become just
15e42531 1377the leftover unidentified statements containing an equal sign." )
f32b3b91
CD
1378
1379(defvar idlwave-fill-function 'auto-fill-function
1380 "IDL mode auto fill function.")
1381
1382(defvar idlwave-comment-indent-function 'comment-indent-function
1383 "IDL mode comment indent function.")
1384
1385;; Note that this is documented in the v18 manuals as being a string
1386;; of length one rather than a single character.
1387;; The code in this file accepts either format for compatibility.
f66f03de 1388(defvar idlwave-comment-indent-char ?\
f32b3b91
CD
1389 "Character to be inserted for IDL comment indentation.
1390Normally a space.")
1391
1392(defconst idlwave-continuation-char ?$
1393 "Character which is inserted as a last character on previous line by
1394 \\[idlwave-split-line] to begin a continuation line. Normally $.")
1395
f66f03de 1396(defconst idlwave-mode-version "6.0_em22")
f32b3b91
CD
1397
1398(defmacro idlwave-keyword-abbrev (&rest args)
1399 "Creates a function for abbrev hooks to call `idlwave-check-abbrev' with args."
8a946354 1400 `(quote (lambda ()
5e72c6b2 1401 ,(append '(idlwave-check-abbrev) args))))
f32b3b91
CD
1402
1403;; If I take the time I can replace idlwave-keyword-abbrev with
1404;; idlwave-code-abbrev and remove the quoted abbrev check from
1405;; idlwave-check-abbrev. Then, e.g, (idlwave-keyword-abbrev 0 t) becomes
1406;; (idlwave-code-abbrev idlwave-check-abbrev 0 t). In fact I should change
1407;; the name of idlwave-check-abbrev to something like idlwave-modify-abbrev.
1408
1409(defmacro idlwave-code-abbrev (&rest args)
1410 "Creates a function for abbrev hooks that ensures abbrevs are not quoted.
1411Specifically, if the abbrev is in a comment or string it is unexpanded.
1412Otherwise ARGS forms a list that is evaluated."
8a946354 1413 `(quote (lambda ()
5e72c6b2
S
1414 ,(prin1-to-string args) ;; Puts the code in the doc string
1415 (if (idlwave-quoted)
1416 (progn (unexpand-abbrev) nil)
1417 ,(append args)))))
f32b3b91
CD
1418
1419(defvar idlwave-mode-map (make-sparse-keymap)
1420 "Keymap used in IDL mode.")
1421
1422(defvar idlwave-mode-syntax-table (make-syntax-table)
1423 "Syntax table in use in `idlwave-mode' buffers.")
1424
1425(modify-syntax-entry ?+ "." idlwave-mode-syntax-table)
1426(modify-syntax-entry ?- "." idlwave-mode-syntax-table)
1427(modify-syntax-entry ?* "." idlwave-mode-syntax-table)
1428(modify-syntax-entry ?/ "." idlwave-mode-syntax-table)
1429(modify-syntax-entry ?^ "." idlwave-mode-syntax-table)
1430(modify-syntax-entry ?# "." idlwave-mode-syntax-table)
1431(modify-syntax-entry ?= "." idlwave-mode-syntax-table)
1432(modify-syntax-entry ?% "." idlwave-mode-syntax-table)
1433(modify-syntax-entry ?< "." idlwave-mode-syntax-table)
1434(modify-syntax-entry ?> "." idlwave-mode-syntax-table)
1435(modify-syntax-entry ?\' "\"" idlwave-mode-syntax-table)
1436(modify-syntax-entry ?\" "\"" idlwave-mode-syntax-table)
1437(modify-syntax-entry ?\\ "." idlwave-mode-syntax-table)
1438(modify-syntax-entry ?_ "_" idlwave-mode-syntax-table)
1439(modify-syntax-entry ?{ "(}" idlwave-mode-syntax-table)
1440(modify-syntax-entry ?} "){" idlwave-mode-syntax-table)
1441(modify-syntax-entry ?$ "_" idlwave-mode-syntax-table)
1442(modify-syntax-entry ?. "." idlwave-mode-syntax-table)
1443(modify-syntax-entry ?\; "<" idlwave-mode-syntax-table)
1444(modify-syntax-entry ?\n ">" idlwave-mode-syntax-table)
1445(modify-syntax-entry ?\f ">" idlwave-mode-syntax-table)
1446
1447(defvar idlwave-find-symbol-syntax-table
1448 (copy-syntax-table idlwave-mode-syntax-table)
1449 "Syntax table that treats symbol characters as word characters.")
1450
05a1abfc
CD
1451(modify-syntax-entry ?$ "w" idlwave-find-symbol-syntax-table)
1452(modify-syntax-entry ?_ "w" idlwave-find-symbol-syntax-table)
1453(modify-syntax-entry ?! "w" idlwave-find-symbol-syntax-table)
1454(modify-syntax-entry ?. "w" idlwave-find-symbol-syntax-table)
1455
76959b77
S
1456(defmacro idlwave-with-special-syntax (&rest body)
1457 "Execute BODY with a different syntax table."
05a1abfc
CD
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
76959b77
S
1465;(defmacro idlwave-with-special-syntax1 (&rest body)
1466; "Execute BODY with a different syntax table."
1467; `(let ((saved-syntax (syntax-table)))
1468; (unwind-protect
1469; (progn
1470; (set-syntax-table idlwave-find-symbol-syntax-table)
1471; ,@body)
1472; (set-syntax-table saved-syntax))))
1473
f32b3b91
CD
1474(defun idlwave-action-and-binding (key cmd &optional select)
1475 "KEY and CMD are made into a key binding and an indent action.
1476KEY is a string - same as for the `define-key' function. CMD is a
1477function of no arguments or a list to be evaluated. CMD is bound to
1478KEY in `idlwave-mode-map' by defining an anonymous function calling
1479`self-insert-command' followed by CMD. If KEY contains more than one
1480character a binding will only be set if SELECT is 'both.
1481
5e72c6b2 1482\(KEY . CMD\) is also placed in the `idlwave-indent-expand-table',
f32b3b91
CD
1483replacing any previous value for KEY. If a binding is not set then it
1484will instead be placed in `idlwave-indent-action-table'.
1485
1486If the optional argument SELECT is nil then an action and binding are
1487created. If SELECT is 'noaction, then a binding is always set and no
1488action is created. If SELECT is 'both then an action and binding
1489will both be created even if KEY contains more than one character.
1490Otherwise, if SELECT is non-nil then only an action is created.
1491
1492Some examples:
1493No spaces before and 1 after a comma
1494 (idlwave-action-and-binding \",\" '(idlwave-surround 0 1))
1495A minimum of 1 space before and after `=' (see `idlwave-expand-equal').
1496 (idlwave-action-and-binding \"=\" '(idlwave-expand-equal -1 -1))
1497Capitalize system variables - action only
1498 (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)"
1499 (if (not (equal select 'noaction))
1500 ;; Add action
1501 (let* ((table (if select 'idlwave-indent-action-table
1502 'idlwave-indent-expand-table))
3938cb82
S
1503 (table-key (regexp-quote key))
1504 (cell (assoc table-key (eval table))))
f32b3b91
CD
1505 (if cell
1506 ;; Replace action command
1507 (setcdr cell cmd)
1508 ;; New action
3938cb82 1509 (set table (append (eval table) (list (cons table-key cmd)))))))
f32b3b91
CD
1510 ;; Make key binding for action
1511 (if (or (and (null select) (= (length key) 1))
1512 (equal select 'noaction)
1513 (equal select 'both))
1514 (define-key idlwave-mode-map key
1515 (append '(lambda ()
1516 (interactive)
1517 (self-insert-command 1))
1518 (list (if (listp cmd)
1519 cmd
1520 (list cmd)))))))
1521
1522(fset 'idlwave-debug-map (make-sparse-keymap))
1523
595ab50b 1524(define-key idlwave-mode-map "\C-c " 'idlwave-hard-tab)
15e42531 1525(define-key idlwave-mode-map [(control tab)] 'idlwave-hard-tab)
595ab50b 1526;(define-key idlwave-mode-map "\C-c\C- " 'idlwave-hard-tab)
f32b3b91
CD
1527(define-key idlwave-mode-map "'" 'idlwave-show-matching-quote)
1528(define-key idlwave-mode-map "\"" 'idlwave-show-matching-quote)
76959b77 1529(define-key idlwave-mode-map "\C-g" 'idlwave-keyboard-quit)
f32b3b91
CD
1530(define-key idlwave-mode-map "\C-c;" 'idlwave-toggle-comment-region)
1531(define-key idlwave-mode-map "\C-\M-a" 'idlwave-beginning-of-subprogram)
1532(define-key idlwave-mode-map "\C-\M-e" 'idlwave-end-of-subprogram)
1533(define-key idlwave-mode-map "\C-c{" 'idlwave-beginning-of-block)
1534(define-key idlwave-mode-map "\C-c}" 'idlwave-end-of-block)
1535(define-key idlwave-mode-map "\C-c]" 'idlwave-close-block)
3938cb82 1536(define-key idlwave-mode-map [(meta control h)] 'idlwave-mark-subprogram)
f32b3b91
CD
1537(define-key idlwave-mode-map "\M-\C-n" 'idlwave-forward-block)
1538(define-key idlwave-mode-map "\M-\C-p" 'idlwave-backward-block)
1539(define-key idlwave-mode-map "\M-\C-d" 'idlwave-down-block)
1540(define-key idlwave-mode-map "\M-\C-u" 'idlwave-backward-up-block)
1541(define-key idlwave-mode-map "\M-\r" 'idlwave-split-line)
1542(define-key idlwave-mode-map "\M-\C-q" 'idlwave-indent-subprogram)
1543(define-key idlwave-mode-map "\C-c\C-p" 'idlwave-previous-statement)
1544(define-key idlwave-mode-map "\C-c\C-n" 'idlwave-next-statement)
1545;; (define-key idlwave-mode-map "\r" 'idlwave-newline)
1546;; (define-key idlwave-mode-map "\t" 'idlwave-indent-line)
f66f03de 1547(define-key idlwave-mode-map [(shift iso-lefttab)] 'idlwave-indent-statement)
f32b3b91
CD
1548(define-key idlwave-mode-map "\C-c\C-a" 'idlwave-auto-fill-mode)
1549(define-key idlwave-mode-map "\M-q" 'idlwave-fill-paragraph)
1550(define-key idlwave-mode-map "\M-s" 'idlwave-edit-in-idlde)
1551(define-key idlwave-mode-map "\C-c\C-h" 'idlwave-doc-header)
1552(define-key idlwave-mode-map "\C-c\C-m" 'idlwave-doc-modification)
1553(define-key idlwave-mode-map "\C-c\C-c" 'idlwave-case)
1554(define-key idlwave-mode-map "\C-c\C-d" 'idlwave-debug-map)
05a1abfc
CD
1555(when (and (boundp 'idlwave-shell-debug-modifiers)
1556 (listp idlwave-shell-debug-modifiers)
1557 (not (equal idlwave-shell-debug-modifiers '())))
1558 ;; Bind the debug commands also with the special modifiers.
1559 (let ((shift (memq 'shift idlwave-shell-debug-modifiers))
f66f03de 1560 (mods-noshift (delq 'shift
05a1abfc 1561 (copy-sequence idlwave-shell-debug-modifiers))))
f66f03de 1562 (define-key idlwave-mode-map
05a1abfc
CD
1563 (vector (append mods-noshift (list (if shift ?C ?c))))
1564 'idlwave-shell-save-and-run)
f66f03de 1565 (define-key idlwave-mode-map
05a1abfc 1566 (vector (append mods-noshift (list (if shift ?B ?b))))
52a244eb 1567 'idlwave-shell-break-here)
f66f03de 1568 (define-key idlwave-mode-map
52a244eb
S
1569 (vector (append mods-noshift (list (if shift ?E ?e))))
1570 'idlwave-shell-run-region)))
1571(define-key idlwave-mode-map "\C-c\C-d\C-c" 'idlwave-shell-save-and-run)
1572(define-key idlwave-mode-map "\C-c\C-d\C-b" 'idlwave-shell-break-here)
1573(define-key idlwave-mode-map "\C-c\C-d\C-e" 'idlwave-shell-run-region)
f32b3b91
CD
1574(define-key idlwave-mode-map "\C-c\C-f" 'idlwave-for)
1575;; (define-key idlwave-mode-map "\C-c\C-f" 'idlwave-function)
1576;; (define-key idlwave-mode-map "\C-c\C-p" 'idlwave-procedure)
1577(define-key idlwave-mode-map "\C-c\C-r" 'idlwave-repeat)
1578(define-key idlwave-mode-map "\C-c\C-w" 'idlwave-while)
15e42531 1579(define-key idlwave-mode-map "\C-c\C-k" 'idlwave-kill-autoloaded-buffers)
f32b3b91
CD
1580(define-key idlwave-mode-map "\C-c\C-s" 'idlwave-shell)
1581(define-key idlwave-mode-map "\C-c\C-l" 'idlwave-shell-recenter-shell-window)
15e42531 1582(define-key idlwave-mode-map "\C-c\C-b" 'idlwave-list-buffer-load-path-shadows)
22d5821d
CD
1583(autoload 'idlwave-shell "idlw-shell"
1584 "Run an inferior IDL, with I/O through buffer `(idlwave-shell-buffer)'." t)
8c7b4ec8
EZ
1585(autoload 'idlwave-shell-send-command "idlw-shell")
1586(autoload 'idlwave-shell-recenter-shell-window "idlw-shell"
f32b3b91 1587 "Run `idlwave-shell' and switch back to current window" t)
8c7b4ec8 1588(autoload 'idlwave-shell-save-and-run "idlw-shell"
f32b3b91 1589 "Save and run buffer under the shell." t)
15e42531
CD
1590(autoload 'idlwave-shell-break-here "idlw-shell"
1591 "Set breakpoint in current line." t)
52a244eb
S
1592(autoload 'idlwave-shell-run-region "idlw-shell"
1593 "Compile and run the region." t)
f32b3b91 1594(define-key idlwave-mode-map "\C-c\C-v" 'idlwave-find-module)
3938cb82 1595(define-key idlwave-mode-map "\C-c\C-t" 'idlwave-find-module-this-file)
f32b3b91 1596(define-key idlwave-mode-map "\C-c?" 'idlwave-routine-info)
15e42531 1597(define-key idlwave-mode-map "\M-?" 'idlwave-context-help)
76959b77 1598(define-key idlwave-mode-map [(control meta ?\?)] 'idlwave-online-help)
52a244eb 1599;; Pickup both forms of Esc/Meta binding
f32b3b91 1600(define-key idlwave-mode-map [(meta tab)] 'idlwave-complete)
52a244eb
S
1601(define-key idlwave-mode-map [?\e?\t] 'idlwave-complete)
1602(define-key idlwave-mode-map "\M-\C-i" 'idlwave-complete)
1603(define-key idlwave-mode-map "\C-c\C-i" 'idlwave-update-routine-info)
1604(define-key idlwave-mode-map "\C-c=" 'idlwave-resolve)
f66f03de 1605(define-key idlwave-mode-map
15e42531
CD
1606 (if (featurep 'xemacs) [(shift button3)] [(shift mouse-3)])
1607 'idlwave-mouse-context-help)
f32b3b91
CD
1608
1609;; Set action and key bindings.
1610;; See description of the function `idlwave-action-and-binding'.
1611;; Automatically add spaces for the following characters
f66f03de
S
1612
1613;; Actions for & are complicated by &&
1614(idlwave-action-and-binding "&" 'idlwave-custom-ampersand-surround)
1615
1616;; Automatically add spaces to equal sign if not keyword. This needs
1617;; to go ahead of > and <, so >= and <= will be treated correctly
f32b3b91
CD
1618(idlwave-action-and-binding "=" '(idlwave-expand-equal -1 -1))
1619
f66f03de
S
1620;; Actions for > and < are complicated by >=, <=, and ->...
1621(idlwave-action-and-binding "<" '(idlwave-custom-ltgtr-surround nil))
1622(idlwave-action-and-binding ">" '(idlwave-custom-ltgtr-surround 'gtr))
1623
1624(idlwave-action-and-binding "," '(idlwave-surround 0 -1 1))
1625
1626
f32b3b91
CD
1627;;;
1628;;; Abbrev Section
1629;;;
1630;;; When expanding abbrevs and the abbrev hook moves backward, an extra
1631;;; space is inserted (this is the space typed by the user to expanded
1632;;; the abbrev).
1633;;;
5e72c6b2
S
1634(defvar idlwave-mode-abbrev-table nil
1635 "Abbreviation table used for IDLWAVE mode")
1636(define-abbrev-table 'idlwave-mode-abbrev-table ())
1637
1638(defun idlwave-define-abbrev (name expansion hook &optional noprefix table)
1639 "Define-abbrev with backward compatibility.
1640
1641If NOPREFIX is non-nil, don't prepend prefix character. Installs into
1642idlwave-mode-abbrev-table unless TABLE is non-nil."
1643 (let ((abbrevs-changed nil) ;; mask the current value to avoid save
1644 (args (list (or table idlwave-mode-abbrev-table)
1645 (if noprefix name (concat idlwave-abbrev-start-char name))
1646 expansion
1647 hook)))
1648 (condition-case nil
1649 (apply 'define-abbrev (append args '(0 t)))
1650 (error (apply 'define-abbrev args)))))
f32b3b91
CD
1651
1652(condition-case nil
f66f03de 1653 (modify-syntax-entry (string-to-char idlwave-abbrev-start-char)
f32b3b91
CD
1654 "w" idlwave-mode-syntax-table)
1655 (error nil))
1656
5e72c6b2
S
1657;;
1658;; Templates
1659;;
1660(idlwave-define-abbrev "c" "" (idlwave-code-abbrev idlwave-case))
1661(idlwave-define-abbrev "sw" "" (idlwave-code-abbrev idlwave-switch))
1662(idlwave-define-abbrev "f" "" (idlwave-code-abbrev idlwave-for))
1663(idlwave-define-abbrev "fu" "" (idlwave-code-abbrev idlwave-function))
1664(idlwave-define-abbrev "pr" "" (idlwave-code-abbrev idlwave-procedure))
1665(idlwave-define-abbrev "r" "" (idlwave-code-abbrev idlwave-repeat))
1666(idlwave-define-abbrev "w" "" (idlwave-code-abbrev idlwave-while))
1667(idlwave-define-abbrev "i" "" (idlwave-code-abbrev idlwave-if))
1668(idlwave-define-abbrev "elif" "" (idlwave-code-abbrev idlwave-elif))
1669;;
1670;; Keywords, system functions, conversion routines
1671;;
1672(idlwave-define-abbrev "ap" "arg_present()" (idlwave-keyword-abbrev 1))
1673(idlwave-define-abbrev "b" "begin" (idlwave-keyword-abbrev 0 t))
1674(idlwave-define-abbrev "co" "common" (idlwave-keyword-abbrev 0 t))
1675(idlwave-define-abbrev "cb" "byte()" (idlwave-keyword-abbrev 1))
1676(idlwave-define-abbrev "cx" "fix()" (idlwave-keyword-abbrev 1))
1677(idlwave-define-abbrev "cl" "long()" (idlwave-keyword-abbrev 1))
1678(idlwave-define-abbrev "cf" "float()" (idlwave-keyword-abbrev 1))
1679(idlwave-define-abbrev "cs" "string()" (idlwave-keyword-abbrev 1))
1680(idlwave-define-abbrev "cc" "complex()" (idlwave-keyword-abbrev 1))
1681(idlwave-define-abbrev "cd" "double()" (idlwave-keyword-abbrev 1))
1682(idlwave-define-abbrev "e" "else" (idlwave-keyword-abbrev 0 t))
1683(idlwave-define-abbrev "ec" "endcase" 'idlwave-show-begin)
1684(idlwave-define-abbrev "es" "endswitch" 'idlwave-show-begin)
1685(idlwave-define-abbrev "ee" "endelse" 'idlwave-show-begin)
1686(idlwave-define-abbrev "ef" "endfor" 'idlwave-show-begin)
1687(idlwave-define-abbrev "ei" "endif else if" 'idlwave-show-begin)
1688(idlwave-define-abbrev "el" "endif else" 'idlwave-show-begin)
1689(idlwave-define-abbrev "en" "endif" 'idlwave-show-begin)
1690(idlwave-define-abbrev "er" "endrep" 'idlwave-show-begin)
1691(idlwave-define-abbrev "ew" "endwhile" 'idlwave-show-begin)
1692(idlwave-define-abbrev "g" "goto," (idlwave-keyword-abbrev 0 t))
1693(idlwave-define-abbrev "h" "help," (idlwave-keyword-abbrev 0))
1694(idlwave-define-abbrev "k" "keyword_set()" (idlwave-keyword-abbrev 1))
1695(idlwave-define-abbrev "n" "n_elements()" (idlwave-keyword-abbrev 1))
1696(idlwave-define-abbrev "on" "on_error," (idlwave-keyword-abbrev 0))
1697(idlwave-define-abbrev "oi" "on_ioerror," (idlwave-keyword-abbrev 0 1))
1698(idlwave-define-abbrev "ow" "openw," (idlwave-keyword-abbrev 0))
1699(idlwave-define-abbrev "or" "openr," (idlwave-keyword-abbrev 0))
1700(idlwave-define-abbrev "ou" "openu," (idlwave-keyword-abbrev 0))
1701(idlwave-define-abbrev "p" "print," (idlwave-keyword-abbrev 0))
1702(idlwave-define-abbrev "pt" "plot," (idlwave-keyword-abbrev 0))
1703(idlwave-define-abbrev "re" "read," (idlwave-keyword-abbrev 0))
1704(idlwave-define-abbrev "rf" "readf," (idlwave-keyword-abbrev 0))
1705(idlwave-define-abbrev "ru" "readu," (idlwave-keyword-abbrev 0))
1706(idlwave-define-abbrev "rt" "return" (idlwave-keyword-abbrev 0))
1707(idlwave-define-abbrev "sc" "strcompress()" (idlwave-keyword-abbrev 1))
1708(idlwave-define-abbrev "sn" "strlen()" (idlwave-keyword-abbrev 1))
1709(idlwave-define-abbrev "sl" "strlowcase()" (idlwave-keyword-abbrev 1))
1710(idlwave-define-abbrev "su" "strupcase()" (idlwave-keyword-abbrev 1))
1711(idlwave-define-abbrev "sm" "strmid()" (idlwave-keyword-abbrev 1))
1712(idlwave-define-abbrev "sp" "strpos()" (idlwave-keyword-abbrev 1))
1713(idlwave-define-abbrev "st" "strput()" (idlwave-keyword-abbrev 1))
1714(idlwave-define-abbrev "sr" "strtrim()" (idlwave-keyword-abbrev 1))
1715(idlwave-define-abbrev "t" "then" (idlwave-keyword-abbrev 0 t))
1716(idlwave-define-abbrev "u" "until" (idlwave-keyword-abbrev 0 t))
1717(idlwave-define-abbrev "wu" "writeu," (idlwave-keyword-abbrev 0))
1718(idlwave-define-abbrev "iap" "if arg_present() then" (idlwave-keyword-abbrev 6))
1719(idlwave-define-abbrev "ik" "if keyword_set() then" (idlwave-keyword-abbrev 6))
1720(idlwave-define-abbrev "ine" "if n_elements() eq 0 then" (idlwave-keyword-abbrev 11))
1721(idlwave-define-abbrev "inn" "if n_elements() ne 0 then" (idlwave-keyword-abbrev 11))
1722(idlwave-define-abbrev "np" "n_params()" (idlwave-keyword-abbrev 0))
1723(idlwave-define-abbrev "s" "size()" (idlwave-keyword-abbrev 1))
1724(idlwave-define-abbrev "wi" "widget_info()" (idlwave-keyword-abbrev 1))
1725(idlwave-define-abbrev "wc" "widget_control," (idlwave-keyword-abbrev 0))
3938cb82
S
1726(idlwave-define-abbrev "pv" "ptr_valid()" (idlwave-keyword-abbrev 1))
1727(idlwave-define-abbrev "ipv" "if ptr_valid() then" (idlwave-keyword-abbrev 6))
ff689efd 1728
5e72c6b2
S
1729;; This section is reserved words only. (From IDL user manual)
1730;;
1731(idlwave-define-abbrev "and" "and" (idlwave-keyword-abbrev 0 t) t)
1732(idlwave-define-abbrev "begin" "begin" (idlwave-keyword-abbrev 0 t) t)
1733(idlwave-define-abbrev "break" "break" (idlwave-keyword-abbrev 0 t) t)
1734(idlwave-define-abbrev "case" "case" (idlwave-keyword-abbrev 0 t) t)
1735(idlwave-define-abbrev "common" "common" (idlwave-keyword-abbrev 0 t) t)
1736(idlwave-define-abbrev "continue" "continue" (idlwave-keyword-abbrev 0 t) t)
1737(idlwave-define-abbrev "do" "do" (idlwave-keyword-abbrev 0 t) t)
1738(idlwave-define-abbrev "else" "else" (idlwave-keyword-abbrev 0 t) t)
1739(idlwave-define-abbrev "end" "end" 'idlwave-show-begin-check t)
1740(idlwave-define-abbrev "endcase" "endcase" 'idlwave-show-begin-check t)
1741(idlwave-define-abbrev "endelse" "endelse" 'idlwave-show-begin-check t)
1742(idlwave-define-abbrev "endfor" "endfor" 'idlwave-show-begin-check t)
1743(idlwave-define-abbrev "endif" "endif" 'idlwave-show-begin-check t)
1744(idlwave-define-abbrev "endrep" "endrep" 'idlwave-show-begin-check t)
1745(idlwave-define-abbrev "endswitch" "endswitch" 'idlwave-show-begin-check t)
1746(idlwave-define-abbrev "endwhi" "endwhi" 'idlwave-show-begin-check t)
1747(idlwave-define-abbrev "endwhile" "endwhile" 'idlwave-show-begin-check t)
1748(idlwave-define-abbrev "eq" "eq" (idlwave-keyword-abbrev 0 t) t)
1749(idlwave-define-abbrev "for" "for" (idlwave-keyword-abbrev 0 t) t)
1750(idlwave-define-abbrev "function" "function" (idlwave-keyword-abbrev 0 t) t)
1751(idlwave-define-abbrev "ge" "ge" (idlwave-keyword-abbrev 0 t) t)
1752(idlwave-define-abbrev "goto" "goto" (idlwave-keyword-abbrev 0 t) t)
1753(idlwave-define-abbrev "gt" "gt" (idlwave-keyword-abbrev 0 t) t)
1754(idlwave-define-abbrev "if" "if" (idlwave-keyword-abbrev 0 t) t)
1755(idlwave-define-abbrev "le" "le" (idlwave-keyword-abbrev 0 t) t)
1756(idlwave-define-abbrev "lt" "lt" (idlwave-keyword-abbrev 0 t) t)
1757(idlwave-define-abbrev "mod" "mod" (idlwave-keyword-abbrev 0 t) t)
1758(idlwave-define-abbrev "ne" "ne" (idlwave-keyword-abbrev 0 t) t)
1759(idlwave-define-abbrev "not" "not" (idlwave-keyword-abbrev 0 t) t)
1760(idlwave-define-abbrev "of" "of" (idlwave-keyword-abbrev 0 t) t)
1761(idlwave-define-abbrev "on_ioerror" "on_ioerror" (idlwave-keyword-abbrev 0 t) t)
1762(idlwave-define-abbrev "or" "or" (idlwave-keyword-abbrev 0 t) t)
1763(idlwave-define-abbrev "pro" "pro" (idlwave-keyword-abbrev 0 t) t)
1764(idlwave-define-abbrev "repeat" "repeat" (idlwave-keyword-abbrev 0 t) t)
1765(idlwave-define-abbrev "switch" "switch" (idlwave-keyword-abbrev 0 t) t)
1766(idlwave-define-abbrev "then" "then" (idlwave-keyword-abbrev 0 t) t)
1767(idlwave-define-abbrev "until" "until" (idlwave-keyword-abbrev 0 t) t)
1768(idlwave-define-abbrev "while" "while" (idlwave-keyword-abbrev 0 t) t)
1769(idlwave-define-abbrev "xor" "xor" (idlwave-keyword-abbrev 0 t) t)
f32b3b91
CD
1770
1771(defvar imenu-create-index-function)
1772(defvar extract-index-name-function)
1773(defvar prev-index-position-function)
1774(defvar imenu-extract-index-name-function)
1775(defvar imenu-prev-index-position-function)
5e72c6b2 1776;; defined later - so just make the compiler hush
f66f03de 1777(defvar idlwave-mode-menu)
f32b3b91
CD
1778(defvar idlwave-mode-debug-menu)
1779
1780;;;###autoload
1781(defun idlwave-mode ()
f66f03de 1782 "Major mode for editing IDL source files (version 6.0_em22).
f32b3b91
CD
1783
1784The main features of this mode are
1785
17861. Indentation and Formatting
1787 --------------------------
1788 Like other Emacs programming modes, C-j inserts a newline and indents.
1789 TAB is used for explicit indentation of the current line.
1790
5e72c6b2
S
1791 To start a continuation line, use \\[idlwave-split-line]. This
1792 function can also be used in the middle of a line to split the line
1793 at that point. When used inside a long constant string, the string
1794 is split at that point with the `+' concatenation operator.
f32b3b91
CD
1795
1796 Comments are indented as follows:
1797
1798 `;;;' Indentation remains unchanged.
1799 `;;' Indent like the surrounding code
1800 `;' Indent to a minimum column.
1801
1802 The indentation of comments starting in column 0 is never changed.
1803
5e72c6b2
S
1804 Use \\[idlwave-fill-paragraph] to refill a paragraph inside a
1805 comment. The indentation of the second line of the paragraph
1806 relative to the first will be retained. Use
1807 \\[idlwave-auto-fill-mode] to toggle auto-fill mode for these
1808 comments. When the variable `idlwave-fill-comment-line-only' is
52a244eb 1809 nil, code can also be auto-filled and auto-indented.
f32b3b91
CD
1810
1811 To convert pre-existing IDL code to your formatting style, mark the
5e72c6b2
S
1812 entire buffer with \\[mark-whole-buffer] and execute
1813 \\[idlwave-expand-region-abbrevs]. Then mark the entire buffer
1814 again followed by \\[indent-region] (`indent-region').
f32b3b91
CD
1815
18162. Routine Info
1817 ------------
5e72c6b2
S
1818 IDLWAVE displays information about the calling sequence and the
1819 accepted keyword parameters of a procedure or function with
1820 \\[idlwave-routine-info]. \\[idlwave-find-module] jumps to the
1821 source file of a module. These commands know about system
1822 routines, all routines in idlwave-mode buffers and (when the
1823 idlwave-shell is active) about all modules currently compiled under
52a244eb
S
1824 this shell. It also makes use of pre-compiled or custom-scanned
1825 user and library catalogs many popular libraries ship with by
1826 default. Use \\[idlwave-update-routine-info] to update this
15e42531
CD
1827 information, which is also used for completion (see item 4).
1828
18293. Online IDL Help
1830 ---------------
f66f03de 1831
15e42531 1832 \\[idlwave-context-help] displays the IDL documentation relevant
f66f03de
S
1833 for the system variable, keyword, or routines at point. A single
1834 key stroke gets you directly to the right place in the docs. See
52a244eb 1835 the manual to configure where and how the HTML help is displayed.
f32b3b91 1836
15e42531 18374. Completion
f32b3b91 1838 ----------
15e42531 1839 \\[idlwave-complete] completes the names of procedures, functions
52a244eb
S
1840 class names, keyword parameters, system variables and tags, class
1841 tags, structure tags, filenames and much more. It is context
1842 sensitive and figures out what is expected at point. Lower case
1843 strings are completed in lower case, other strings in mixed or
1844 upper case.
f32b3b91 1845
15e42531 18465. Code Templates and Abbreviations
f32b3b91
CD
1847 --------------------------------
1848 Many Abbreviations are predefined to expand to code fragments and templates.
1849 The abbreviations start generally with a `\\`. Some examples
1850
1851 \\pr PROCEDURE template
1852 \\fu FUNCTION template
1853 \\c CASE statement template
05a1abfc 1854 \\sw SWITCH statement template
f32b3b91
CD
1855 \\f FOR loop template
1856 \\r REPEAT Loop template
1857 \\w WHILE loop template
1858 \\i IF statement template
1859 \\elif IF-ELSE statement template
1860 \\b BEGIN
f66f03de 1861
52a244eb
S
1862 For a full list, use \\[idlwave-list-abbrevs]. Some templates also
1863 have direct keybindings - see the list of keybindings below.
775591f7 1864
52a244eb
S
1865 \\[idlwave-doc-header] inserts a documentation header at the
1866 beginning of the current program unit (pro, function or main).
1867 Change log entries can be added to the current program unit with
1868 \\[idlwave-doc-modification].
f32b3b91 1869
15e42531 18706. Automatic Case Conversion
f32b3b91
CD
1871 -------------------------
1872 The case of reserved words and some abbrevs is controlled by
1873 `idlwave-reserved-word-upcase' and `idlwave-abbrev-change-case'.
1874
15e42531 18757. Automatic END completion
f32b3b91
CD
1876 ------------------------
1877 If the variable `idlwave-expand-generic-end' is non-nil, each END typed
1878 will be converted to the specific version, like ENDIF, ENDFOR, etc.
1879
15e42531 18808. Hooks
f32b3b91
CD
1881 -----
1882 Loading idlwave.el runs `idlwave-load-hook'.
1883 Turning on `idlwave-mode' runs `idlwave-mode-hook'.
1884
15e42531 18859. Documentation and Customization
f32b3b91 1886 -------------------------------
5e72c6b2
S
1887 Info documentation for this package is available. Use
1888 \\[idlwave-info] to display (complain to your sysadmin if that does
1889 not work). For Postscript, PDF, and HTML versions of the
1890 documentation, check IDLWAVE's homepage at `http://idlwave.org'.
f32b3b91
CD
1891 IDLWAVE has customize support - see the group `idlwave'.
1892
15e42531 189310.Keybindings
f32b3b91
CD
1894 -----------
1895 Here is a list of all keybindings of this mode.
1896 If some of the key bindings below show with ??, use \\[describe-key]
1897 followed by the key sequence to see what the key sequence does.
1898
1899\\{idlwave-mode-map}"
1900
1901 (interactive)
1902 (kill-all-local-variables)
f66f03de 1903
f32b3b91
CD
1904 (if idlwave-startup-message
1905 (message "Emacs IDLWAVE mode version %s." idlwave-mode-version))
1906 (setq idlwave-startup-message nil)
f66f03de 1907
f32b3b91
CD
1908 (setq local-abbrev-table idlwave-mode-abbrev-table)
1909 (set-syntax-table idlwave-mode-syntax-table)
f66f03de 1910
f32b3b91 1911 (set (make-local-variable 'indent-line-function) 'idlwave-indent-and-action)
f66f03de 1912
f32b3b91
CD
1913 (make-local-variable idlwave-comment-indent-function)
1914 (set idlwave-comment-indent-function 'idlwave-comment-hook)
f66f03de 1915
f32b3b91
CD
1916 (set (make-local-variable 'comment-start-skip) ";+[ \t]*")
1917 (set (make-local-variable 'comment-start) ";")
0dc2be2f 1918 (set (make-local-variable 'comment-add) 1) ; ";;" for new and regions
f66f03de 1919 (set (make-local-variable 'require-final-newline) t)
f32b3b91
CD
1920 (set (make-local-variable 'abbrev-all-caps) t)
1921 (set (make-local-variable 'indent-tabs-mode) nil)
1922 (set (make-local-variable 'completion-ignore-case) t)
f66f03de 1923
f32b3b91
CD
1924 (use-local-map idlwave-mode-map)
1925
1926 (when (featurep 'easymenu)
1927 (easy-menu-add idlwave-mode-menu idlwave-mode-map)
1928 (easy-menu-add idlwave-mode-debug-menu idlwave-mode-map))
1929
1930 (setq mode-name "IDLWAVE")
1931 (setq major-mode 'idlwave-mode)
1932 (setq abbrev-mode t)
f66f03de 1933
f32b3b91
CD
1934 (set (make-local-variable idlwave-fill-function) 'idlwave-auto-fill)
1935 (setq comment-end "")
1936 (set (make-local-variable 'comment-multi-line) nil)
f66f03de 1937 (set (make-local-variable 'paragraph-separate)
5e72c6b2 1938 "[ \t\f]*$\\|[ \t]*;+[ \t]*$\\|;+[+=-_*]+$")
f32b3b91
CD
1939 (set (make-local-variable 'paragraph-start) "[ \t\f]\\|[ \t]*;+[ \t]")
1940 (set (make-local-variable 'paragraph-ignore-fill-prefix) nil)
76959b77 1941 (set (make-local-variable 'parse-sexp-ignore-comments) t)
775591f7 1942
f32b3b91
CD
1943 ;; Set tag table list to use IDLTAGS as file name.
1944 (if (boundp 'tag-table-alist)
1945 (add-to-list 'tag-table-alist '("\\.pro$" . "IDLTAGS")))
f66f03de 1946
f32b3b91 1947 ;; Font-lock additions - originally Phil Williams, then Ulrik Dickow
52a244eb 1948 ;; Following line is for Emacs - XEmacs uses the corresponding property
f32b3b91
CD
1949 ;; on the `idlwave-mode' symbol.
1950 (set (make-local-variable 'font-lock-defaults) idlwave-font-lock-defaults)
0dc2be2f
S
1951 (set (make-local-variable 'font-lock-mark-block-function)
1952 'idlwave-mark-subprogram)
1953 (set (make-local-variable 'font-lock-fontify-region-function)
1954 'idlwave-font-lock-fontify-region)
f32b3b91
CD
1955
1956 ;; Imenu setup
1957 (set (make-local-variable 'imenu-create-index-function)
1958 'imenu-default-create-index-function)
1959 (set (make-local-variable 'imenu-extract-index-name-function)
1960 'idlwave-unit-name)
1961 (set (make-local-variable 'imenu-prev-index-position-function)
1962 'idlwave-prev-index-position)
1963
0dc2be2f
S
1964 ;; HideShow setup
1965 (add-to-list 'hs-special-modes-alist
1966 (list 'idlwave-mode
1967 idlwave-begin-block-reg
1968 idlwave-end-block-reg
1969 ";"
1970 'idlwave-forward-block nil))
1971
1972
f32b3b91 1973 ;; Make a local post-command-hook and add our hook to it
f66f03de
S
1974 ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
1975 ;; (make-local-hook 'post-command-hook)
15e42531
CD
1976 (add-hook 'post-command-hook 'idlwave-command-hook nil 'local)
1977
1978 ;; Make local hooks for buffer updates
f66f03de
S
1979 ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
1980 ;; (make-local-hook 'kill-buffer-hook)
15e42531 1981 (add-hook 'kill-buffer-hook 'idlwave-kill-buffer-update nil 'local)
f66f03de
S
1982 ;; (make-local-hook 'after-save-hook)
1983 ;; (add-hook 'after-save-hook 'idlwave-save-buffer-update nil 'local)
15e42531
CD
1984 (add-hook 'after-save-hook 'idlwave-revoke-license-to-kill nil 'local)
1985
52a244eb
S
1986 ;; Setup directories and file, if necessary
1987 (idlwave-setup)
1988
15e42531
CD
1989 ;; Update the routine info with info about current buffer?
1990 (idlwave-new-buffer-update)
f32b3b91 1991
f66f03de
S
1992 ;; Check help location
1993 (idlwave-help-check-locations)
1994
f32b3b91 1995 ;; Run the mode hook
9a969196 1996 (run-mode-hooks 'idlwave-mode-hook))
f32b3b91 1997
52a244eb
S
1998(defvar idlwave-setup-done nil)
1999(defun idlwave-setup ()
2000 (unless idlwave-setup-done
2001 (if (not (file-directory-p idlwave-config-directory))
2002 (make-directory idlwave-config-directory))
f66f03de
S
2003 (setq
2004 idlwave-user-catalog-file (expand-file-name
2005 idlwave-user-catalog-file
2006 idlwave-config-directory)
2007 idlwave-xml-system-rinfo-converted-file
2008 (expand-file-name
2009 idlwave-xml-system-rinfo-converted-file
2010 idlwave-config-directory)
2011 idlwave-path-file (expand-file-name
2012 idlwave-path-file
2013 idlwave-config-directory))
52a244eb
S
2014 (idlwave-read-paths) ; we may need these early
2015 (setq idlwave-setup-done t)))
2016
0dc2be2f
S
2017(defun idlwave-font-lock-fontify-region (beg end &optional verbose)
2018 "Fontify continuation lines correctly."
2019 (let (pos)
2020 (save-excursion
2021 (goto-char beg)
2022 (forward-line -1)
2023 (when (setq pos (idlwave-is-continuation-line))
2024 (goto-char pos)
2025 (idlwave-beginning-of-statement)
2026 (setq beg (point)))))
2027 (font-lock-default-fontify-region beg end verbose))
2028
f32b3b91 2029;;
52a244eb 2030;; Code Formatting ----------------------------------------------------
f66f03de 2031;;
f32b3b91 2032
f32b3b91
CD
2033(defun idlwave-hard-tab ()
2034 "Inserts TAB in buffer in current position."
2035 (interactive)
2036 (insert "\t"))
2037
2038;;; This stuff is experimental
2039
2040(defvar idlwave-command-hook nil
2041 "If non-nil, a list that can be evaluated using `eval'.
2042It is evaluated in the lisp function `idlwave-command-hook' which is
2043placed in `post-command-hook'.")
2044
2045(defun idlwave-command-hook ()
2046 "Command run after every command.
2047Evaluates a non-nil value of the *variable* `idlwave-command-hook' and
2048sets the variable to zero afterwards."
2049 (and idlwave-command-hook
2050 (listp idlwave-command-hook)
2051 (condition-case nil
2052 (eval idlwave-command-hook)
2053 (error nil)))
2054 (setq idlwave-command-hook nil))
2055
2056;;; End experiment
2057
2058;; It would be better to use expand.el for better abbrev handling and
2059;; versatility.
2060
2061(defun idlwave-check-abbrev (arg &optional reserved)
2062 "Reverses abbrev expansion if in comment or string.
2063Argument ARG is the number of characters to move point
2064backward if `idlwave-abbrev-move' is non-nil.
2065If optional argument RESERVED is non-nil then the expansion
2066consists of reserved words, which will be capitalized if
2067`idlwave-reserved-word-upcase' is non-nil.
2068Otherwise, the abbrev will be capitalized if `idlwave-abbrev-change-case'
2069is non-nil, unless its value is \`down in which case the abbrev will be
2070made into all lowercase.
2071Returns non-nil if abbrev is left expanded."
2072 (if (idlwave-quoted)
2073 (progn (unexpand-abbrev)
2074 nil)
2075 (if (and reserved idlwave-reserved-word-upcase)
2076 (upcase-region last-abbrev-location (point))
2077 (cond
2078 ((equal idlwave-abbrev-change-case 'down)
2079 (downcase-region last-abbrev-location (point)))
2080 (idlwave-abbrev-change-case
2081 (upcase-region last-abbrev-location (point)))))
2082 (if (and idlwave-abbrev-move (> arg 0))
2083 (if (boundp 'post-command-hook)
2084 (setq idlwave-command-hook (list 'backward-char (1+ arg)))
2085 (backward-char arg)))
2086 t))
2087
2088(defun idlwave-in-comment ()
2089 "Returns t if point is inside a comment, nil otherwise."
2090 (save-excursion
2091 (let ((here (point)))
2092 (and (idlwave-goto-comment) (> here (point))))))
2093
2094(defun idlwave-goto-comment ()
2095 "Move to start of comment delimiter on current line.
2096Moves to end of line if there is no comment delimiter.
2097Ignores comment delimiters in strings.
2098Returns point if comment found and nil otherwise."
2099 (let ((eos (progn (end-of-line) (point)))
2100 (data (match-data))
2101 found)
2102 ;; Look for first comment delimiter not in a string
2103 (beginning-of-line)
2104 (setq found (search-forward comment-start eos 'lim))
2105 (while (and found (idlwave-in-quote))
2106 (setq found (search-forward comment-start eos 'lim)))
2107 (store-match-data data)
2108 (and found (not (idlwave-in-quote))
2109 (progn
2110 (backward-char 1)
2111 (point)))))
2112
5e72c6b2
S
2113(defvar transient-mark-mode)
2114(defvar zmacs-regions)
2115(defvar mark-active)
2116(defun idlwave-region-active-p ()
52a244eb 2117 "Is transient-mark-mode on and the region active?
5e72c6b2
S
2118Works on both Emacs and XEmacs."
2119 (if (featurep 'xemacs)
2120 (and zmacs-regions (region-active-p))
2121 (and transient-mark-mode mark-active)))
2122
f32b3b91
CD
2123(defun idlwave-show-matching-quote ()
2124 "Insert quote and show matching quote if this is end of a string."
2125 (interactive)
2126 (let ((bq (idlwave-in-quote))
2127 (inq last-command-char))
2128 (if (and bq (not (idlwave-in-comment)))
2129 (let ((delim (char-after bq)))
2130 (insert inq)
2131 (if (eq inq delim)
2132 (save-excursion
2133 (goto-char bq)
2134 (sit-for 1))))
2135 ;; Not the end of a string
2136 (insert inq))))
2137
2138(defun idlwave-show-begin-check ()
2139 "Ensure that the previous word was a token before `idlwave-show-begin'.
2140An END token must be preceded by whitespace."
5e72c6b2
S
2141 (if (not (idlwave-quoted))
2142 (if
2143 (save-excursion
2144 (backward-word 1)
2145 (backward-char 1)
2146 (looking-at "[ \t\n\f]"))
2147 (idlwave-show-begin))))
f32b3b91
CD
2148
2149(defun idlwave-show-begin ()
2150 "Finds the start of current block and blinks to it for a second.
2151Also checks if the correct end statement has been used."
2152 ;; All end statements are reserved words
76959b77 2153 ;; Re-indent end line
52a244eb
S
2154 ;;(insert-char ?\ 1) ;; So indent, etc. work well
2155 ;;(backward-char 1)
76959b77
S
2156 (let* ((pos (point-marker))
2157 (last-abbrev-marker (copy-marker last-abbrev-location))
2158 (eol-pos (save-excursion (end-of-line) (point)))
2159 begin-pos end-pos end end1 )
2160 (if idlwave-reindent-end (idlwave-indent-line))
52a244eb 2161 (setq last-abbrev-location (marker-position last-abbrev-marker))
f32b3b91
CD
2162 (when (and (idlwave-check-abbrev 0 t)
2163 idlwave-show-block)
2164 (save-excursion
2165 ;; Move inside current block
76959b77 2166 (goto-char last-abbrev-marker)
f32b3b91 2167 (idlwave-block-jump-out -1 'nomark)
76959b77
S
2168 (setq begin-pos (point))
2169 (idlwave-block-jump-out 1 'nomark)
2170 (setq end-pos (point))
2171 (if (> end-pos eol-pos)
2172 (setq end-pos pos))
2173 (goto-char end-pos)
f66f03de 2174 (setq end (buffer-substring
76959b77
S
2175 (progn
2176 (skip-chars-backward "a-zA-Z")
2177 (point))
2178 end-pos))
2179 (goto-char begin-pos)
f32b3b91
CD
2180 (when (setq end1 (cdr (idlwave-block-master)))
2181 (cond
5e72c6b2 2182 ((null end1)) ; no-operation
f32b3b91
CD
2183 ((string= (downcase end) (downcase end1))
2184 (sit-for 1))
2185 ((string= (downcase end) "end")
2186 ;; A generic end
2187 (if idlwave-expand-generic-end
2188 (save-excursion
2189 (goto-char pos)
2190 (backward-char 3)
2191 (insert (if (string= end "END") (upcase end1) end1))
2192 (delete-char 3)))
2193 (sit-for 1))
2194 (t
2195 (beep)
f66f03de 2196 (message "Warning: Shouldn't this be \"%s\" instead of \"%s\"?"
f32b3b91 2197 end1 end)
52a244eb
S
2198 (sit-for 1))))))))
2199 ;;(delete-char 1))
f32b3b91
CD
2200
2201(defun idlwave-block-master ()
2202 (let ((case-fold-search t))
2203 (save-excursion
2204 (cond
05a1abfc 2205 ((looking-at "pro\\|case\\|switch\\|function\\>")
f32b3b91
CD
2206 (assoc (downcase (match-string 0)) idlwave-block-matches))
2207 ((looking-at "begin\\>")
f66f03de
S
2208 (let ((limit (save-excursion
2209 (idlwave-beginning-of-statement)
f32b3b91
CD
2210 (point))))
2211 (cond
52a244eb
S
2212 ((re-search-backward ":[ \t]*\\=" limit t)
2213 ;; seems to be a case thing
2214 '("begin" . "end"))
f32b3b91
CD
2215 ((re-search-backward idlwave-block-match-regexp limit t)
2216 (assoc (downcase (match-string 1))
2217 idlwave-block-matches))
f32b3b91 2218 (t
52a244eb 2219 ;; Just a normal block
f32b3b91
CD
2220 '("begin" . "end")))))
2221 (t nil)))))
2222
2223(defun idlwave-close-block ()
2224 "Terminate the current block with the correct END statement."
2225 (interactive)
f32b3b91
CD
2226 ;; Start new line if we are not in a new line
2227 (unless (save-excursion
2228 (skip-chars-backward " \t")
2229 (bolp))
2230 (let ((idlwave-show-block nil))
2231 (newline-and-indent)))
5e72c6b2
S
2232 (let ((last-abbrev-location (point))) ; for upcasing
2233 (insert "end")
2234 (idlwave-show-begin)))
2235
f66f03de
S
2236(defun idlwave-custom-ampersand-surround (&optional is-action)
2237 "Surround &, leaving room for && (which surrround as well)."
2238 (let* ((prev-char (char-after (- (point) 2)))
2239 (next-char (char-after (point)))
2240 (amp-left (eq prev-char ?&))
2241 (amp-right (eq next-char ?&))
2242 (len (if amp-left 2 1)))
2243 (unless amp-right ;no need to do it twice, amp-left will catch it.
2244 (idlwave-surround -1 (if (or is-action amp-left) -1) len))))
2245
2246(defun idlwave-custom-ltgtr-surround (gtr &optional is-action)
2247 "Surround > and < by blanks, leaving room for >= and <=, and considering ->."
2248 (let* ((prev-char (char-after (- (point) 2)))
2249 (next-char (char-after (point)))
2250 (method-invoke (and gtr (eq prev-char ?-)))
2251 (len (if method-invoke 2 1)))
2252 (unless (eq next-char ?=)
2253 ;; Key binding: pad only on left, to save for possible >=/<=
2254 (idlwave-surround -1 (if (or is-action method-invoke) -1) len))))
2255
2256(defun idlwave-surround (&optional before after length is-action)
595ab50b
CD
2257 "Surround the LENGTH characters before point with blanks.
2258LENGTH defaults to 1.
f32b3b91 2259Optional arguments BEFORE and AFTER affect the behavior before and
595ab50b
CD
2260after the characters (see also description of `idlwave-make-space'):
2261
2262nil do nothing
22630 force no spaces
2264integer > 0 force exactly n spaces
2265integer < 0 at least |n| spaces
f32b3b91
CD
2266
2267The function does nothing if any of the following conditions is true:
2268- `idlwave-surround-by-blank' is nil
f66f03de 2269- the character before point is inside a string or comment"
5e72c6b2 2270 (when (and idlwave-surround-by-blank (not (idlwave-quoted)))
f66f03de
S
2271 (let ((length (or length 1))) ; establish a default for LENGTH
2272 (backward-char length)
2273 (save-restriction
2274 (let ((here (point)))
2275 (skip-chars-backward " \t")
2276 (if (bolp)
2277 ;; avoid clobbering indent
2278 (progn
2279 (move-to-column (idlwave-calculate-indent))
2280 (if (<= (point) here)
2281 (narrow-to-region (point) here))
2282 (goto-char here)))
2283 (idlwave-make-space before))
2284 (skip-chars-forward " \t"))
2285 (forward-char length)
2286 (idlwave-make-space after)
2287 ;; Check to see if the line should auto wrap
2288 (if (and (equal (char-after (1- (point))) ?\ )
2289 (> (current-column) fill-column))
2290 (funcall auto-fill-function)))))
f32b3b91
CD
2291
2292(defun idlwave-make-space (n)
2293 "Make space at point.
2294The space affected is all the spaces and tabs around point.
2295If n is non-nil then point is left abs(n) spaces from the beginning of
2296the contiguous space.
2297The amount of space at point is determined by N.
2298If the value of N is:
2299nil - do nothing.
595ab50b
CD
2300> 0 - exactly N spaces.
2301< 0 - a minimum of -N spaces, i.e., do not change if there are
2302 already -N spaces.
23030 - no spaces (i.e. remove any existing space)."
f32b3b91
CD
2304 (if (integerp n)
2305 (let
2306 ((start-col (progn (skip-chars-backward " \t") (current-column)))
2307 (left (point))
2308 (end-col (progn (skip-chars-forward " \t") (current-column))))
2309 (delete-horizontal-space)
2310 (cond
2311 ((> n 0)
2312 (idlwave-indent-to (+ start-col n))
2313 (goto-char (+ left n)))
2314 ((< n 0)
2315 (idlwave-indent-to end-col (- n))
2316 (goto-char (- left n)))
2317 ;; n = 0, done
2318 ))))
2319
2320(defun idlwave-newline ()
2321 "Inserts a newline and indents the current and previous line."
2322 (interactive)
2323 ;;
2324 ;; Handle unterminated single and double quotes
2325 ;; If not in a comment and in a string then insertion of a newline
2326 ;; will mean unbalanced quotes.
2327 ;;
2328 (if (and (not (idlwave-in-comment)) (idlwave-in-quote))
2329 (progn (beep)
2330 (message "Warning: unbalanced quotes?")))
2331 (newline)
2332 ;;
2333 ;; The current line is being split, the cursor should be at the
2334 ;; beginning of the new line skipping the leading indentation.
2335 ;;
2336 ;; The reason we insert the new line before indenting is that the
2337 ;; indenting could be confused by keywords (e.g. END) on the line
2338 ;; after the split point. This prevents us from just using
2339 ;; `indent-for-tab-command' followed by `newline-and-indent'.
2340 ;;
2341 (beginning-of-line 0)
2342 (idlwave-indent-line)
2343 (forward-line)
2344 (idlwave-indent-line))
2345
2346;;
2347;; Use global variable 'comment-column' to set parallel comment
2348;;
2349;; Modeled on lisp.el
2350;; Emacs Lisp and IDL (Wave CL) have identical comment syntax
2351(defun idlwave-comment-hook ()
2352 "Compute indent for the beginning of the IDL comment delimiter."
2353 (if (or (looking-at idlwave-no-change-comment)
2354 (if idlwave-begin-line-comment
2355 (looking-at idlwave-begin-line-comment)
2356 (looking-at "^;")))
2357 (current-column)
2358 (if (looking-at idlwave-code-comment)
2359 (if (save-excursion (skip-chars-backward " \t") (bolp))
2360 ;; On line by itself, indent as code
2361 (let ((tem (idlwave-calculate-indent)))
2362 (if (listp tem) (car tem) tem))
2363 ;; after code - do not change
2364 (current-column))
2365 (skip-chars-backward " \t")
2366 (max (if (bolp) 0 (1+ (current-column)))
2367 comment-column))))
2368
2369(defun idlwave-split-line ()
2370 "Continue line by breaking line at point and indent the lines.
2371For a code line insert continuation marker. If the line is a line comment
2372then the new line will contain a comment with the same indentation.
2373Splits strings with the IDL operator `+' if `idlwave-split-line-string' is
2374non-nil."
2375 (interactive)
15e42531
CD
2376 ;; Expand abbreviation, just like normal RET would.
2377 (and abbrev-mode (expand-abbrev))
f32b3b91
CD
2378 (let (beg)
2379 (if (not (idlwave-in-comment))
2380 ;; For code line add continuation.
2381 ;; Check if splitting a string.
2382 (progn
2383 (if (setq beg (idlwave-in-quote))
2384 (if idlwave-split-line-string
2385 ;; Split the string.
2386 (progn (insert (setq beg (char-after beg)) " + "
2387 idlwave-continuation-char beg)
5e72c6b2
S
2388 (backward-char 1)
2389 (newline-and-indent)
2390 (forward-char 1))
f32b3b91
CD
2391 ;; Do not split the string.
2392 (beep)
2393 (message "Warning: continuation inside string!!")
2394 (insert " " idlwave-continuation-char))
2395 ;; Not splitting a string.
15e42531
CD
2396 (if (not (member (char-before) '(?\ ?\t)))
2397 (insert " "))
5e72c6b2
S
2398 (insert idlwave-continuation-char)
2399 (newline-and-indent)))
f32b3b91
CD
2400 (indent-new-comment-line))
2401 ;; Indent previous line
2402 (setq beg (- (point-max) (point)))
2403 (forward-line -1)
2404 (idlwave-indent-line)
2405 (goto-char (- (point-max) beg))
2406 ;; Reindent new line
2407 (idlwave-indent-line)))
2408
2409(defun idlwave-beginning-of-subprogram ()
2410 "Moves point to the beginning of the current program unit."
2411 (interactive)
2412 (idlwave-find-key idlwave-begin-unit-reg -1))
2413
2414(defun idlwave-end-of-subprogram ()
2415 "Moves point to the start of the next program unit."
2416 (interactive)
2417 (idlwave-end-of-statement)
2418 (idlwave-find-key idlwave-end-unit-reg 1))
2419
2420(defun idlwave-mark-statement ()
2421 "Mark current IDL statement."
2422 (interactive)
2423 (idlwave-end-of-statement)
2424 (let ((end (point)))
2425 (idlwave-beginning-of-statement)
0dc2be2f 2426 (push-mark end nil t)))
f32b3b91
CD
2427
2428(defun idlwave-mark-block ()
2429 "Mark containing block."
2430 (interactive)
2431 (idlwave-end-of-statement)
2432 (idlwave-backward-up-block -1)
2433 (idlwave-end-of-statement)
2434 (let ((end (point)))
2435 (idlwave-backward-block)
2436 (idlwave-beginning-of-statement)
0dc2be2f 2437 (push-mark end nil t)))
f32b3b91
CD
2438
2439
2440(defun idlwave-mark-subprogram ()
2441 "Put mark at beginning of program, point at end.
2442The marks are pushed."
2443 (interactive)
2444 (idlwave-end-of-statement)
2445 (idlwave-beginning-of-subprogram)
2446 (let ((beg (point)))
2447 (idlwave-forward-block)
0dc2be2f 2448 (push-mark beg nil t))
f32b3b91
CD
2449 (exchange-point-and-mark))
2450
2451(defun idlwave-backward-up-block (&optional arg)
2452 "Move to beginning of enclosing block if prefix ARG >= 0.
2453If prefix ARG < 0 then move forward to enclosing block end."
2454 (interactive "p")
2455 (idlwave-block-jump-out (- arg) 'nomark))
2456
2457(defun idlwave-beginning-of-block ()
2458 "Go to the beginning of the current block."
2459 (interactive)
2460 (idlwave-block-jump-out -1 'nomark)
2461 (forward-word 1))
2462
2463(defun idlwave-end-of-block ()
2464 "Go to the beginning of the current block."
2465 (interactive)
2466 (idlwave-block-jump-out 1 'nomark)
2467 (backward-word 1))
2468
0dc2be2f 2469(defun idlwave-forward-block (&optional arg)
f32b3b91
CD
2470 "Move across next nested block."
2471 (interactive)
0dc2be2f
S
2472 (let ((arg (or arg 1)))
2473 (if (idlwave-down-block arg)
2474 (idlwave-block-jump-out arg 'nomark))))
f32b3b91
CD
2475
2476(defun idlwave-backward-block ()
2477 "Move backward across previous nested block."
2478 (interactive)
2479 (if (idlwave-down-block -1)
2480 (idlwave-block-jump-out -1 'nomark)))
2481
2482(defun idlwave-down-block (&optional arg)
2483 "Go down a block.
2484With ARG: ARG >= 0 go forwards, ARG < 0 go backwards.
2485Returns non-nil if successfull."
2486 (interactive "p")
2487 (let (status)
2488 (if (< arg 0)
2489 ;; Backward
2490 (let ((eos (save-excursion
2491 (idlwave-block-jump-out -1 'nomark)
2492 (point))))
f66f03de 2493 (if (setq status (idlwave-find-key
f32b3b91
CD
2494 idlwave-end-block-reg -1 'nomark eos))
2495 (idlwave-beginning-of-statement)
2496 (message "No nested block before beginning of containing block.")))
2497 ;; Forward
2498 (let ((eos (save-excursion
2499 (idlwave-block-jump-out 1 'nomark)
2500 (point))))
f66f03de 2501 (if (setq status (idlwave-find-key
f32b3b91
CD
2502 idlwave-begin-block-reg 1 'nomark eos))
2503 (idlwave-end-of-statement)
2504 (message "No nested block before end of containing block."))))
2505 status))
2506
2507(defun idlwave-mark-doclib ()
2508 "Put point at beginning of doc library header, mark at end.
2509The marks are pushed."
2510 (interactive)
2511 (let (beg
2512 (here (point)))
2513 (goto-char (point-max))
2514 (if (re-search-backward idlwave-doclib-start nil t)
f66f03de 2515 (progn
f32b3b91
CD
2516 (setq beg (progn (beginning-of-line) (point)))
2517 (if (re-search-forward idlwave-doclib-end nil t)
2518 (progn
2519 (forward-line 1)
0dc2be2f 2520 (push-mark beg nil t)
f32b3b91
CD
2521 (message "Could not find end of doc library header.")))
2522 (message "Could not find doc library header start.")
2523 (goto-char here)))))
2524
15e42531
CD
2525(defun idlwave-current-routine ()
2526 "Return (NAME TYPE CLASS) of current routine."
2527 (idlwave-routines)
2528 (save-excursion
2529 (idlwave-beginning-of-subprogram)
2530 (if (looking-at "[ \t]*\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)")
2531 (let* ((type (if (string= (downcase (match-string 1)) "pro")
2532 'pro 'function))
2533 (class (idlwave-sintern-class (match-string 3)))
2534 (name (idlwave-sintern-routine-or-method (match-string 4) class)))
2535 (list name type class)))))
2536
f32b3b91
CD
2537(defvar idlwave-shell-prompt-pattern)
2538(defun idlwave-beginning-of-statement ()
2539 "Move to beginning of the current statement.
2540Skips back past statement continuations.
2541Point is placed at the beginning of the line whether or not this is an
2542actual statement."
2543 (interactive)
2544 (cond
2545 ((eq major-mode 'idlwave-shell-mode)
2546 (if (re-search-backward idlwave-shell-prompt-pattern nil t)
2547 (goto-char (match-end 0))))
f66f03de 2548 (t
f32b3b91
CD
2549 (if (save-excursion (forward-line -1) (idlwave-is-continuation-line))
2550 (idlwave-previous-statement)
2551 (beginning-of-line)))))
2552
2553(defun idlwave-previous-statement ()
2554 "Moves point to beginning of the previous statement.
2555Returns t if the current line before moving is the beginning of
2556the first non-comment statement in the file, and nil otherwise."
2557 (interactive)
2558 (let (first-statement)
2559 (if (not (= (forward-line -1) 0))
2560 ;; first line in file
2561 t
2562 ;; skip blank lines, label lines, include lines and line comments
2563 (while (and
2564 ;; The current statement is the first statement until we
2565 ;; reach another statement.
2566 (setq first-statement
2567 (or
2568 (looking-at idlwave-comment-line-start-skip)
2569 (looking-at "[ \t]*$")
2570 (looking-at (concat "[ \t]*" idlwave-label "[ \t]*$"))
2571 (looking-at "^@")))
2572 (= (forward-line -1) 0)))
2573 ;; skip continuation lines
2574 (while (and
2575 (save-excursion
2576 (forward-line -1)
2577 (idlwave-is-continuation-line))
2578 (= (forward-line -1) 0)))
2579 first-statement)))
2580
f32b3b91
CD
2581(defun idlwave-end-of-statement ()
2582 "Moves point to the end of the current IDL statement.
05a1abfc
CD
2583If not in a statement just moves to end of line. Returns position."
2584 (interactive)
2585 (while (and (idlwave-is-continuation-line)
2586 (= (forward-line 1) 0))
2587 (while (and (idlwave-is-comment-or-empty-line)
2588 (= (forward-line 1) 0))))
2589 (end-of-line)
2590 (point))
2591
2592(defun idlwave-end-of-statement0 ()
2593 "Moves point to the end of the current IDL statement.
f32b3b91
CD
2594If not in a statement just moves to end of line. Returns position."
2595 (interactive)
2596 (while (and (idlwave-is-continuation-line)
2597 (= (forward-line 1) 0)))
2598 (end-of-line)
2599 (point))
2600
2601(defun idlwave-next-statement ()
2602 "Moves point to beginning of the next IDL statement.
2603 Returns t if that statement is the last
2604 non-comment IDL statement in the file, and nil otherwise."
2605 (interactive)
2606 (let (last-statement)
2607 (idlwave-end-of-statement)
2608 ;; skip blank lines, label lines, include lines and line comments
2609 (while (and (= (forward-line 1) 0)
2610 ;; The current statement is the last statement until
2611 ;; we reach a new statement.
2612 (setq last-statement
2613 (or
2614 (looking-at idlwave-comment-line-start-skip)
2615 (looking-at "[ \t]*$")
2616 (looking-at (concat "[ \t]*" idlwave-label "[ \t]*$"))
2617 (looking-at "^@")))))
2618 last-statement))
2619
76959b77
S
2620(defun idlwave-skip-multi-commands (&optional lim)
2621 "Skip past multiple commands on a line (with `&')."
2622 (let ((save-point (point)))
2623 (when (re-search-forward ".*&" lim t)
2624 (goto-char (match-end 0))
f66f03de 2625 (if (idlwave-quoted)
6b75c9af
S
2626 (goto-char save-point)
2627 (if (eq (char-after (- (point) 2)) ?&) (goto-char save-point))))
76959b77
S
2628 (point)))
2629
15e42531 2630(defun idlwave-skip-label-or-case ()
f32b3b91
CD
2631 "Skip label or case statement element.
2632Returns position after label.
2633If there is no label point is not moved and nil is returned."
15e42531
CD
2634 ;; Case expressions and labels are terminated by a colon.
2635 ;; So we find the first colon in the line and make sure
2636 ;; - no `?' is before it (might be a ? b : c)
2637 ;; - it is not in a comment
2638 ;; - not in a string constant
2639 ;; - not in parenthesis (like a[0:3])
5e72c6b2 2640 ;; - not followed by another ":" in explicit class, ala a->b::c
15e42531 2641 ;; As many in this mode, this function is heuristic and not an exact
f66f03de 2642 ;; parser.
5e72c6b2
S
2643 (let* ((start (point))
2644 (eos (save-excursion (idlwave-end-of-statement) (point)))
2645 (end (idlwave-find-key ":" 1 'nomark eos)))
f32b3b91 2646 (if (and end
15e42531 2647 (= (nth 0 (parse-partial-sexp start end)) 0)
5e72c6b2
S
2648 (not (string-match "\\?" (buffer-substring start end)))
2649 (not (string-match "^::" (buffer-substring end eos))))
f32b3b91
CD
2650 (progn
2651 (forward-char)
2652 (point))
2653 (goto-char start)
2654 nil)))
2655
2656(defun idlwave-start-of-substatement (&optional pre)
2657 "Move to start of next IDL substatement after point.
2658Uses the type of the current IDL statement to determine if the next
2659statement is on a new line or is a subpart of the current statement.
2660Returns point at start of substatement modulo whitespace.
2661If optional argument is non-nil move to beginning of current
15e42531 2662substatement."
f32b3b91
CD
2663 (let ((orig (point))
2664 (eos (idlwave-end-of-statement))
2665 (ifnest 0)
2666 st nst last)
2667 (idlwave-beginning-of-statement)
15e42531 2668 (idlwave-skip-label-or-case)
52a244eb
S
2669 (if (< (point) orig)
2670 (idlwave-skip-multi-commands orig))
f32b3b91
CD
2671 (setq last (point))
2672 ;; Continue looking for substatements until we are past orig
2673 (while (and (<= (point) orig) (not (eobp)))
2674 (setq last (point))
2675 (setq nst (nth 1 (cdr (setq st (car (idlwave-statement-type))))))
2676 (if (equal (car st) 'if) (setq ifnest (1+ ifnest)))
2677 (cond ((and nst
2678 (idlwave-find-key nst 1 'nomark eos))
2679 (goto-char (match-end 0)))
2680 ((and (> ifnest 0) (idlwave-find-key "\\<else\\>" 1 'nomark eos))
2681 (setq ifnest (1- ifnest))
2682 (goto-char (match-end 0)))
2683 (t (setq ifnest 0)
2684 (idlwave-next-statement))))
2685 (if pre (goto-char last))
15e42531
CD
2686 ;; If a continuation line starts here, move to next line
2687 (if (looking-at "[ \t]*\\$\\([ \t]*\\(;\\|$\\)\\)")
2688 (beginning-of-line 2))
f32b3b91
CD
2689 (point)))
2690
2691(defun idlwave-statement-type ()
2692 "Return the type of the current IDL statement.
2693Uses `idlwave-statement-match' to return a cons of (type . point) with
2694point the ending position where the type was determined. Type is the
2695association from `idlwave-statement-match', i.e. the cons cell from the
2696list not just the type symbol. Returns nil if not an identifiable
2697statement."
2698 (save-excursion
2699 ;; Skip whitespace within a statement which is spaces, tabs, continuations
76959b77
S
2700 ;; and possibly comments
2701 (while (looking-at "[ \t]*\\$")
f32b3b91
CD
2702 (forward-line 1))
2703 (skip-chars-forward " \t")
2704 (let ((st idlwave-statement-match)
2705 (case-fold-search t))
2706 (while (and (not (looking-at (nth 0 (cdr (car st)))))
2707 (setq st (cdr st))))
2708 (if st
2709 (append st (match-end 0))))))
2710
f66f03de 2711(defun idlwave-expand-equal (&optional before after is-action)
52a244eb
S
2712 "Pad '=' with spaces. Two cases: Assignment statement, and keyword
2713assignment. Which case is determined using
2714`idlwave-start-of-substatement' and `idlwave-statement-type'. The
2715equal sign will be surrounded by BEFORE and AFTER blanks. If
2716`idlwave-pad-keyword' is t then keyword assignment is treated just
15e42531
CD
2717like assignment statements. When nil, spaces are removed for keyword
2718assignment. Any other value keeps the current space around the `='.
f66f03de 2719Limits in for loops are treated as keyword assignment.
52a244eb
S
2720
2721Starting with IDL 6.0, a number of op= assignments are available.
2722Since ambiguities of the form:
2723
2724r and= b
2725rand= b
2726
2727can occur, alphanumeric operator assignment will never be pre-padded,
2728only post-padded. You must use a space before these to disambiguate
2729\(not just for padding, but for proper parsing by IDL too!). Other
2730operators, such as ##=, ^=, etc., will be pre-padded.
2731
f66f03de
S
2732IS-ACTION is ignored.
2733
52a244eb 2734See `idlwave-surround'."
f32b3b91 2735 (if idlwave-surround-by-blank
f66f03de 2736 (let
52a244eb 2737 ((non-an-ops "\\(##\\|\\*\\|\\+\\|-\\|/\\|<\\|>\\|\\^\\)\\=")
f66f03de 2738 (an-ops
52a244eb
S
2739 "\\s-\\(AND\\|EQ\\|GE\\|GT\\|LE\\|LT\\|MOD\\|NE\\|OR\\|XOR\\)\\=")
2740 (len 1))
f66f03de
S
2741
2742 (save-excursion
52a244eb
S
2743 (let ((case-fold-search t))
2744 (backward-char)
f66f03de 2745 (if (or
52a244eb
S
2746 (re-search-backward non-an-ops nil t)
2747 ;; Why doesn't ##? work for both?
f66f03de 2748 (re-search-backward "\\(#\\)\\=" nil t))
52a244eb
S
2749 (setq len (1+ (length (match-string 1))))
2750 (when (re-search-backward an-ops nil t)
3938cb82 2751 ;(setq begin nil) ; won't modify begin
52a244eb 2752 (setq len (1+ (length (match-string 1))))))))
f66f03de
S
2753
2754 (if (eq t idlwave-pad-keyword)
52a244eb 2755 ;; Everything gets padded equally
f66f03de 2756 (idlwave-surround before after len)
52a244eb
S
2757 ;; Treating keywords/for variables specially...
2758 (let ((st (save-excursion ; To catch "for" variables
2759 (idlwave-start-of-substatement t)
2760 (idlwave-statement-type)))
2761 (what (save-excursion ; To catch keywords
2762 (skip-chars-backward "= \t")
2763 (nth 2 (idlwave-where)))))
2764 (cond ((or (memq what '(function-keyword procedure-keyword))
f66f03de
S
2765 (memq (caar st) '(for pdef)))
2766 (cond
52a244eb
S
2767 ((null idlwave-pad-keyword)
2768 (idlwave-surround 0 0)
2769 ) ; remove space
2770 (t))) ; leave any spaces alone
f66f03de
S
2771 (t (idlwave-surround before after len))))))))
2772
f32b3b91 2773
5e72c6b2
S
2774(defun idlwave-indent-and-action (&optional arg)
2775 "Call `idlwave-indent-line' and do expand actions.
2776With prefix ARG non-nil, indent the entire sub-statement."
2777 (interactive "p")
05a1abfc 2778 (save-excursion
f66f03de
S
2779 (if (and idlwave-expand-generic-end
2780 (re-search-backward "\\<\\(end\\)\\s-*\\="
05a1abfc
CD
2781 (max 0 (- (point) 10)) t)
2782 (looking-at "\\(end\\)\\([ \n\t]\\|\\'\\)"))
2783 (progn (goto-char (match-end 1))
5e72c6b2
S
2784 ;;Expand the END abbreviation, just as RET or Space would have.
2785 (if abbrev-mode (expand-abbrev)
2786 (idlwave-show-begin)))))
52a244eb
S
2787 (when (and (not arg) current-prefix-arg)
2788 (setq arg current-prefix-arg)
2789 (setq current-prefix-arg nil))
f66f03de 2790 (if arg
5e72c6b2
S
2791 (idlwave-indent-statement)
2792 (idlwave-indent-line t)))
f32b3b91
CD
2793
2794(defun idlwave-indent-line (&optional expand)
2795 "Indents current IDL line as code or as a comment.
2796The actions in `idlwave-indent-action-table' are performed.
2797If the optional argument EXPAND is non-nil then the actions in
2798`idlwave-indent-expand-table' are performed."
2799 (interactive)
2800 ;; Move point out of left margin.
2801 (if (save-excursion
2802 (skip-chars-backward " \t")
2803 (bolp))
2804 (skip-chars-forward " \t"))
2805 (let ((mloc (point-marker)))
2806 (save-excursion
2807 (beginning-of-line)
2808 (if (looking-at idlwave-comment-line-start-skip)
2809 ;; Indentation for a line comment
2810 (progn
2811 (skip-chars-forward " \t")
2812 (idlwave-indent-left-margin (idlwave-comment-hook)))
2813 ;;
2814 ;; Code Line
2815 ;;
2816 ;; Before indenting, run action routines.
2817 ;;
2818 (if (and expand idlwave-do-actions)
2819 (mapcar 'idlwave-do-action idlwave-indent-expand-table))
2820 ;;
2821 (if idlwave-do-actions
2822 (mapcar 'idlwave-do-action idlwave-indent-action-table))
2823 ;;
2824 ;; No longer expand abbrevs on the line. The user can do this
2825 ;; manually using expand-region-abbrevs.
2826 ;;
2827 ;; Indent for code line
2828 ;;
2829 (beginning-of-line)
2830 (if (or
2831 ;; a label line
2832 (looking-at (concat "^" idlwave-label "[ \t]*$"))
2833 ;; a batch command
2834 (looking-at "^[ \t]*@"))
2835 ;; leave flush left
2836 nil
2837 ;; indent the line
2838 (idlwave-indent-left-margin (idlwave-calculate-indent)))
2839 ;; Adjust parallel comment
76959b77
S
2840 (end-of-line)
2841 (if (idlwave-in-comment)
2842 ;; Emacs 21 is too smart with fill-column on comment indent
2843 (let ((fill-column (if (fboundp 'comment-indent-new-line)
2844 (1- (frame-width))
2845 fill-column)))
2846 (indent-for-comment)))))
f32b3b91
CD
2847 (goto-char mloc)
2848 ;; Get rid of marker
76959b77 2849 (set-marker mloc nil)))
f32b3b91
CD
2850
2851(defun idlwave-do-action (action)
f66f03de
S
2852 "Perform an action repeatedly on a line. ACTION is a list (REG
2853. FUNC). REG is a regular expression. FUNC is either a function name
2854to be called with `funcall' or a list to be evaluated with `eval'.
2855The action performed by FUNC should leave point after the match for
2856REG - otherwise an infinite loop may be entered. FUNC is always
2857passed a final argument of 'is-action, so it can discriminate between
2858being run as an action, or a key binding"
f32b3b91
CD
2859 (let ((action-key (car action))
2860 (action-routine (cdr action)))
2861 (beginning-of-line)
2862 (while (idlwave-look-at action-key)
2863 (if (listp action-routine)
f66f03de
S
2864 (eval (append action-routine '('is-action)))
2865 (funcall action-routine 'is-action)))))
f32b3b91
CD
2866
2867(defun idlwave-indent-to (col &optional min)
2868 "Indent from point with spaces until column COL.
2869Inserts space before markers at point."
2870 (if (not min) (setq min 0))
2871 (insert-before-markers
15e42531 2872 (make-string (max min (- col (current-column))) ?\ )))
f32b3b91
CD
2873
2874(defun idlwave-indent-left-margin (col)
2875 "Indent the current line to column COL.
2876Indents such that first non-whitespace character is at column COL
2877Inserts spaces before markers at point."
2878 (save-excursion
2879 (beginning-of-line)
2880 (delete-horizontal-space)
2881 (idlwave-indent-to col)))
2882
2883(defun idlwave-indent-subprogram ()
2884 "Indents program unit which contains point."
2885 (interactive)
2886 (save-excursion
2887 (idlwave-end-of-statement)
2888 (idlwave-beginning-of-subprogram)
2889 (let ((beg (point)))
2890 (idlwave-forward-block)
2891 (message "Indenting subprogram...")
2892 (indent-region beg (point) nil))
2893 (message "Indenting subprogram...done.")))
2894
5e72c6b2
S
2895(defun idlwave-indent-statement ()
2896 "Indent current statement, including all continuation lines."
2897 (interactive)
2898 (save-excursion
2899 (idlwave-beginning-of-statement)
2900 (let ((beg (point)))
2901 (idlwave-end-of-statement)
2902 (indent-region beg (point) nil))))
2903
f32b3b91
CD
2904(defun idlwave-calculate-indent ()
2905 "Return appropriate indentation for current line as IDL code."
2906 (save-excursion
2907 (beginning-of-line)
2908 (cond
2909 ;; Check for beginning of unit - main (beginning of buffer), pro, or
2910 ;; function
2911 ((idlwave-look-at idlwave-begin-unit-reg)
2912 0)
2913 ;; Check for continuation line
2914 ((save-excursion
2915 (and (= (forward-line -1) 0)
2916 (idlwave-is-continuation-line)))
2917 (idlwave-calculate-cont-indent))
2918 ;; calculate indent based on previous and current statements
52a244eb
S
2919 (t (let* (beg-prev-pos
2920 (the-indent
2921 ;; calculate indent based on previous statement
2922 (save-excursion
2923 (cond
2924 ;; Beginning of file
f66f03de 2925 ((prog1
52a244eb
S
2926 (idlwave-previous-statement)
2927 (setq beg-prev-pos (point)))
2928 0)
2929 ;; Main block
2930 ((idlwave-look-at idlwave-begin-unit-reg t)
2931 (+ (idlwave-current-statement-indent)
2932 idlwave-main-block-indent))
2933 ;; Begin block
2934 ((idlwave-look-at idlwave-begin-block-reg t)
f66f03de 2935 (+ (idlwave-min-current-statement-indent)
52a244eb
S
2936 idlwave-block-indent))
2937 ;; End Block
2938 ((idlwave-look-at idlwave-end-block-reg t)
2939 (progn
2940 ;; Match to the *beginning* of the block opener
2941 (goto-char beg-prev-pos)
2942 (idlwave-block-jump-out -1 'nomark) ; go to begin block
2943 (idlwave-min-current-statement-indent)))
2944 ;; idlwave-end-offset
2945 ;; idlwave-block-indent))
f66f03de 2946
52a244eb
S
2947 ;; Default to current indent
2948 ((idlwave-current-statement-indent))))))
f32b3b91
CD
2949 ;; adjust the indentation based on the current statement
2950 (cond
2951 ;; End block
5e72c6b2
S
2952 ((idlwave-look-at idlwave-end-block-reg)
2953 (+ the-indent idlwave-end-offset))
f32b3b91
CD
2954 (the-indent)))))))
2955
2956;;
52a244eb 2957;; Parentheses indent
f32b3b91
CD
2958;;
2959
5e72c6b2
S
2960(defun idlwave-calculate-paren-indent (beg-reg end-reg close-exp)
2961 "Calculate the continuation indent inside a paren group.
f66f03de 2962Returns a cons-cell with (open . indent), where open is the
5e72c6b2
S
2963location of the open paren"
2964 (let ((open (nth 1 (parse-partial-sexp beg-reg end-reg))))
2965 ;; Found an innermost open paren.
2966 (when open
2967 (goto-char open)
2968 ;; Line up with next word unless this is a closing paren.
2969 (cons open
2970 (cond
52a244eb
S
2971 ;; Plain Kernighan-style nested indent
2972 (idlwave-indent-parens-nested
2973 (+ idlwave-continuation-indent (idlwave-current-indent)))
2974
5e72c6b2
S
2975 ;; This is a closed paren - line up under open paren.
2976 (close-exp
2977 (current-column))
52a244eb
S
2978
2979 ;; Empty (or just comment) follows -- revert to basic indent
5e72c6b2
S
2980 ((progn
2981 ;; Skip paren
2982 (forward-char 1)
2983 (looking-at "[ \t$]*\\(;.*\\)?$"))
52a244eb
S
2984 nil)
2985
2986 ;; Line up with first word after any blank space
5e72c6b2
S
2987 ((progn
2988 (skip-chars-forward " \t")
2989 (current-column))))))))
2990
f32b3b91 2991(defun idlwave-calculate-cont-indent ()
52a244eb
S
2992 "Calculates the IDL continuation indent column from the previous
2993statement. Note that here previous statement usually means the
2994beginning of the current statement if this statement is a continuation
2995of the previous line. Various special types of continuations,
2996including assignments, routine definitions, and parenthetical
2997groupings, are treated separately."
f32b3b91 2998 (save-excursion
52a244eb 2999 (let* ((case-fold-search t)
f32b3b91 3000 (end-reg (progn (beginning-of-line) (point)))
52a244eb
S
3001 (beg-last-statement (save-excursion (idlwave-previous-statement)
3002 (point)))
f66f03de 3003 (beg-reg (progn (idlwave-start-of-substatement 'pre)
52a244eb
S
3004 (if (eq (line-beginning-position) end-reg)
3005 (goto-char beg-last-statement)
3006 (point))))
3007 (basic-indent (+ (idlwave-min-current-statement-indent end-reg)
3008 idlwave-continuation-indent))
3009 fancy-nonparen-indent fancy-paren-indent)
f66f03de 3010 (cond
52a244eb
S
3011 ;; Align then with its matching if, etc.
3012 ((let ((matchers '(("\\<if\\>" . "[ \t]*then")
3013 ("\\<\\(if\\|end\\(if\\)?\\)\\>" . "[ \t]*else")
3014 ("\\<\\(for\\|while\\)\\>" . "[ \t]*do")
f66f03de 3015 ("\\<\\(repeat\\|end\\(rep\\)?\\)\\>" .
52a244eb
S
3016 "[ \t]*until")
3017 ("\\<case\\>" . "[ \t]*of")))
3018 match cont-re)
3019 (goto-char end-reg)
f66f03de 3020 (and
52a244eb
S
3021 (setq cont-re
3022 (catch 'exit
3023 (while (setq match (car matchers))
3024 (if (looking-at (cdr match))
3025 (throw 'exit (car match)))
3026 (setq matchers (cdr matchers)))))
3027 (idlwave-find-key cont-re -1 'nomark beg-last-statement)))
3028 (if (looking-at "end") ;; that one's special
f66f03de 3029 (- (idlwave-current-indent)
52a244eb
S
3030 (+ idlwave-block-indent idlwave-end-offset))
3031 (idlwave-current-indent)))
3032
3033 ;; Indent in from the previous line for continuing statements
3034 ((let ((matchers '("\\<then\\>"
3035 "\\<do\\>"
3036 "\\<repeat\\>"
3037 "\\<else\\>"))
3038 match)
3039 (catch 'exit
3040 (goto-char end-reg)
3041 (if (/= (forward-line -1) 0)
3042 (throw 'exit nil))
3043 (while (setq match (car matchers))
3044 (if (looking-at (concat ".*" match "[ \t]*\\$[ \t]*"
3045 "\\(;.*\\)?$"))
3046 (throw 'exit t))
3047 (setq matchers (cdr matchers)))))
3048 (+ idlwave-continuation-indent (idlwave-current-indent)))
3049
3050 ;; Parenthetical indent, either traditional or Kernighan style
3051 ((setq fancy-paren-indent
3052 (let* ((end-reg end-reg)
3053 (close-exp (progn
3054 (goto-char end-reg)
f66f03de 3055 (skip-chars-forward " \t")
52a244eb
S
3056 (looking-at "\\s)")))
3057 indent-cons)
3058 (catch 'loop
3059 (while (setq indent-cons (idlwave-calculate-paren-indent
3060 beg-reg end-reg close-exp))
3061 ;; First permitted containing paren
3062 (if (or
3063 idlwave-indent-to-open-paren
3064 idlwave-indent-parens-nested
3065 (null (cdr indent-cons))
3066 (< (- (cdr indent-cons) basic-indent)
3067 idlwave-max-extra-continuation-indent))
3068 (throw 'loop (cdr indent-cons)))
3069 (setq end-reg (car indent-cons))))))
5e72c6b2
S
3070 fancy-paren-indent)
3071
52a244eb
S
3072 ;; A continued assignment, or procedure call/definition
3073 ((and
3074 (> idlwave-max-extra-continuation-indent 0)
3075 (setq fancy-nonparen-indent
3076 (progn
3077 (goto-char beg-reg)
3078 (while (idlwave-look-at "&")) ; skip continued statements
3079 (cond
3080 ;; A continued Procedure call or definition
3081 ((progn
3082 (idlwave-look-at "^[ \t]*\\(pro\\|function\\)") ;skip over
3083 (looking-at "[ \t]*\\([a-zA-Z0-9.$_]+[ \t]*->[ \t]*\\)?[a-zA-Z][:a-zA-Z0-9$_]*[ \t]*\\(,\\)[ \t]*"))
3084 (goto-char (match-end 0))
3085 ;; Comment only, or blank line with "$"? Basic indent.
3086 (if (save-match-data (looking-at "[ \t$]*\\(;.*\\)?$"))
3087 nil
3088 (current-column)))
f66f03de 3089
52a244eb
S
3090 ;; Continued assignment (with =):
3091 ((catch 'assign ;
3092 (while (looking-at "[^=\n\r]*\\(=\\)[ \t]*")
3093 (goto-char (match-end 0))
f66f03de 3094 (if (null (idlwave-what-function beg-reg))
52a244eb
S
3095 (throw 'assign t))))
3096 (unless (or
3097 (idlwave-in-quote)
3098 (looking-at "[ \t$]*\\(;.*\\)?$") ; use basic
3099 (save-excursion
3100 (goto-char beg-last-statement)
3101 (eq (caar (idlwave-statement-type)) 'for)))
3102 (current-column))))))
3103 (< (- fancy-nonparen-indent basic-indent)
3104 idlwave-max-extra-continuation-indent))
3105 (if fancy-paren-indent ;calculated but disallowed paren indent
3106 (+ fancy-nonparen-indent idlwave-continuation-indent)
3107 fancy-nonparen-indent))
3108
3109 ;; Basic indent, by default
3110 (t basic-indent)))))
3111
3112
f32b3b91 3113
15e42531
CD
3114(defun idlwave-find-key (key-re &optional dir nomark limit)
3115 "Move to next match of the regular expression KEY-RE.
3116Matches inside comments or string constants will be ignored.
3117If DIR is negative, the search will be backwards.
3118At a successful match, the mark is pushed unless NOMARK is non-nil.
3119Searches are limited to LIMIT.
3120Searches are case-insensitive and use a special syntax table which
3121treats `$' and `_' as word characters.
3122Return value is the beginning of the match or (in case of failure) nil."
3123 (setq dir (or dir 0))
3124 (let ((case-fold-search t)
3125 (search-func (if (> dir 0) 're-search-forward 're-search-backward))
3126 found)
3127 (idlwave-with-special-syntax
3128 (save-excursion
3129 (catch 'exit
3130 (while (funcall search-func key-re limit t)
3131 (if (not (idlwave-quoted))
52a244eb
S
3132 (throw 'exit (setq found (match-beginning 0)))
3133 (if (or (and (> dir 0) (eobp))
3134 (and (< dir 0) (bobp)))
3135 (throw 'exit nil)))))))
15e42531
CD
3136 (if found
3137 (progn
3138 (if (not nomark) (push-mark))
3139 (goto-char found)
3140 found)
3141 nil)))
3142
f32b3b91
CD
3143(defun idlwave-block-jump-out (&optional dir nomark)
3144 "When optional argument DIR is non-negative, move forward to end of
3145current block using the `idlwave-begin-block-reg' and `idlwave-end-block-reg'
3146regular expressions. When DIR is negative, move backwards to block beginning.
3147Recursively calls itself to skip over nested blocks. DIR defaults to
3148forward. Calls `push-mark' unless the optional argument NOMARK is
3149non-nil. Movement is limited by the start of program units because of
3150possibility of unbalanced blocks."
3151 (interactive "P")
3152 (or dir (setq dir 0))
3153 (let* ((here (point))
3154 (case-fold-search t)
3155 (limit (if (>= dir 0) (point-max) (point-min)))
f66f03de 3156 (block-limit (if (>= dir 0)
f32b3b91
CD
3157 idlwave-begin-block-reg
3158 idlwave-end-block-reg))
3159 found
3160 (block-reg (concat idlwave-begin-block-reg "\\|"
3161 idlwave-end-block-reg))
3162 (unit-limit (or (save-excursion
3163 (if (< dir 0)
3164 (idlwave-find-key
3165 idlwave-begin-unit-reg dir t limit)
3166 (end-of-line)
f66f03de 3167 (idlwave-find-key
f32b3b91
CD
3168 idlwave-end-unit-reg dir t limit)))
3169 limit)))
3170 (if (>= dir 0) (end-of-line)) ;Make sure we are in current block
3171 (if (setq found (idlwave-find-key block-reg dir t unit-limit))
3172 (while (and found (looking-at block-limit))
3173 (if (>= dir 0) (forward-word 1))
3174 (idlwave-block-jump-out dir t)
3175 (setq found (idlwave-find-key block-reg dir t unit-limit))))
3176 (if (not nomark) (push-mark here))
3177 (if (not found) (goto-char unit-limit)
3178 (if (>= dir 0) (forward-word 1)))))
3179
52a244eb
S
3180(defun idlwave-min-current-statement-indent (&optional end-reg)
3181 "The minimum indent in the current statement."
3182 (idlwave-beginning-of-statement)
3183 (if (not (idlwave-is-continuation-line))
3184 (idlwave-current-indent)
3185 (let ((min (idlwave-current-indent)) comm-or-empty)
3186 (while (and (= (forward-line 1) 0)
3187 (or (setq comm-or-empty (idlwave-is-comment-or-empty-line))
3188 (idlwave-is-continuation-line))
3189 (or (null end-reg) (< (point) end-reg)))
3190 (unless comm-or-empty (setq min (min min (idlwave-current-indent)))))
3191 (if (or comm-or-empty (and end-reg (>= (point) end-reg)))
f66f03de 3192 min
52a244eb
S
3193 (min min (idlwave-current-indent))))))
3194
3195(defun idlwave-current-statement-indent (&optional last-line)
f32b3b91
CD
3196 "Return indentation of the current statement.
3197If in a statement, moves to beginning of statement before finding indent."
52a244eb
S
3198 (if last-line
3199 (idlwave-end-of-statement)
3200 (idlwave-beginning-of-statement))
f32b3b91
CD
3201 (idlwave-current-indent))
3202
3203(defun idlwave-current-indent ()
3204 "Return the column of the indentation of the current line.
3205Skips any whitespace. Returns 0 if the end-of-line follows the whitespace."
3206 (save-excursion
3207 (beginning-of-line)
3208 (skip-chars-forward " \t")
3209 ;; if we are at the end of blank line return 0
3210 (cond ((eolp) 0)
3211 ((current-column)))))
3212
3213(defun idlwave-is-continuation-line ()
5e72c6b2
S
3214 "Tests if current line is continuation line.
3215Blank or comment-only lines following regular continuation lines (with
3216`$') count as continuations too."
0dc2be2f
S
3217 (let (p)
3218 (save-excursion
3219 (or
3220 (idlwave-look-at "\\<\\$")
3221 (catch 'loop
3222 (while (and (looking-at "^[ \t]*\\(;.*\\)?$")
3223 (eq (forward-line -1) 0))
3224 (if (setq p (idlwave-look-at "\\<\\$")) (throw 'loop p))))))))
f32b3b91
CD
3225
3226(defun idlwave-is-comment-line ()
05a1abfc 3227 "Tests if the current line is a comment line."
f32b3b91
CD
3228 (save-excursion
3229 (beginning-of-line 1)
3230 (looking-at "[ \t]*;")))
3231
05a1abfc
CD
3232(defun idlwave-is-comment-or-empty-line ()
3233 "Tests if the current line is a comment line."
3234 (save-excursion
3235 (beginning-of-line 1)
3236 (looking-at "[ \t]*[;\n]")))
3237
f32b3b91 3238(defun idlwave-look-at (regexp &optional cont beg)
15e42531
CD
3239 "Searches current line from current point for REGEXP.
3240If optional argument CONT is non-nil, searches to the end of
3241the current statement.
3242If optional arg BEG is non-nil, search starts from the beginning of the
3243current statement.
3244Ignores matches that end in a comment or inside a string expression.
3245Returns point if successful, nil otherwise.
3246This function produces unexpected results if REGEXP contains quotes or
3247a comment delimiter. The search is case insensitive.
3248If successful leaves point after the match, otherwise, does not move point."
f32b3b91 3249 (let ((here (point))
f32b3b91 3250 (case-fold-search t)
15e42531
CD
3251 (eos (save-excursion
3252 (if cont (idlwave-end-of-statement) (end-of-line))
3253 (point)))
f32b3b91 3254 found)
15e42531
CD
3255 (idlwave-with-special-syntax
3256 (if beg (idlwave-beginning-of-statement))
3257 (while (and (setq found (re-search-forward regexp eos t))
3258 (idlwave-quoted))))
f32b3b91
CD
3259 (if (not found) (goto-char here))
3260 found))
3261
3262(defun idlwave-fill-paragraph (&optional nohang)
3263 "Fills paragraphs in comments.
3264A paragraph is made up of all contiguous lines having the same comment
3265leader (the leading whitespace before the comment delimiter and the
3266comment delimiter). In addition, paragraphs are separated by blank
3267line comments. The indentation is given by the hanging indent of the
3268first line, otherwise by the minimum indentation of the lines after
3269the first line. The indentation of the first line does not change.
3270Does not effect code lines. Does not fill comments on the same line
3271with code. The hanging indent is given by the end of the first match
3272matching `idlwave-hang-indent-regexp' on the paragraph's first line . If the
3273optional argument NOHANG is non-nil then the hanging indent is
3274ignored."
3275 (interactive "P")
3276 ;; check if this is a line comment
3277 (if (save-excursion
3278 (beginning-of-line)
3279 (skip-chars-forward " \t")
3280 (looking-at comment-start))
3281 (let
3282 ((indent 999)
3283 pre here diff fill-prefix-reg bcl first-indent
3284 hang start end)
3285 ;; Change tabs to spaces in the surrounding paragraph.
3286 ;; The surrounding paragraph will be the largest containing block of
3287 ;; contiguous line comments. Thus, we may be changing tabs in
3288 ;; a much larger area than is needed, but this is the easiest
3289 ;; brute force way to do it.
3290 ;;
3291 ;; This has the undesirable side effect of replacing the tabs
3292 ;; permanently without the user's request or knowledge.
3293 (save-excursion
3294 (backward-paragraph)
3295 (setq start (point)))
3296 (save-excursion
3297 (forward-paragraph)
3298 (setq end (point)))
3299 (untabify start end)
3300 ;;
3301 (setq here (point))
3302 (beginning-of-line)
3303 (setq bcl (point))
3304 (re-search-forward
3305 (concat "^[ \t]*" comment-start "+")
3306 (save-excursion (end-of-line) (point))
3307 t)
3308 ;; Get the comment leader on the line and its length
3309 (setq pre (current-column))
3310 ;; the comment leader is the indentation plus exactly the
3311 ;; number of consecutive ";".
3312 (setq fill-prefix-reg
3313 (concat
3314 (setq fill-prefix
3315 (regexp-quote
3316 (buffer-substring (save-excursion
3317 (beginning-of-line) (point))
3318 (point))))
3319 "[^;]"))
f66f03de 3320
f32b3b91
CD
3321 ;; Mark the beginning and end of the paragraph
3322 (goto-char bcl)
3323 (while (and (looking-at fill-prefix-reg)
3324 (not (looking-at paragraph-separate))
3325 (not (bobp)))
3326 (forward-line -1))
3327 ;; Move to first line of paragraph
3328 (if (/= (point) bcl)
3329 (forward-line 1))
3330 (setq start (point))
3331 (goto-char bcl)
3332 (while (and (looking-at fill-prefix-reg)
3333 (not (looking-at paragraph-separate))
3334 (not (eobp)))
3335 (forward-line 1))
3336 (beginning-of-line)
3337 (if (or (not (looking-at fill-prefix-reg))
3338 (looking-at paragraph-separate))
3339 (forward-line -1))
3340 (end-of-line)
3341 ;; if at end of buffer add a newline (need this because
3342 ;; fill-region needs END to be at the beginning of line after
3343 ;; the paragraph or it will add a line).
3344 (if (eobp)
3345 (progn (insert ?\n) (backward-char 1)))
3346 ;; Set END to the beginning of line after the paragraph
3347 ;; END is calculated as distance from end of buffer
3348 (setq end (- (point-max) (point) 1))
3349 ;;
3350 ;; Calculate the indentation for the paragraph.
3351 ;;
3352 ;; In the following while statements, after one iteration
3353 ;; point will be at the beginning of a line in which case
3354 ;; the while will not be executed for the
3355 ;; the first paragraph line and thus will not affect the
3356 ;; indentation.
3357 ;;
3358 ;; First check to see if indentation is based on hanging indent.
3359 (if (and (not nohang) idlwave-hanging-indent
3360 (setq hang
3361 (save-excursion
3362 (goto-char start)
3363 (idlwave-calc-hanging-indent))))
3364 ;; Adjust lines of paragraph by inserting spaces so that
3365 ;; each line's indent is at least as great as the hanging
3366 ;; indent. This is needed for fill-paragraph to work with
3367 ;; a fill-prefix.
3368 (progn
3369 (setq indent hang)
3370 (beginning-of-line)
3371 (while (> (point) start)
3372 (re-search-forward comment-start-skip
3373 (save-excursion (end-of-line) (point))
3374 t)
3375 (if (> (setq diff (- indent (current-column))) 0)
3376 (progn
3377 (if (>= here (point))
3378 ;; adjust the original location for the
3379 ;; inserted text.
3380 (setq here (+ here diff)))
15e42531 3381 (insert (make-string diff ?\ ))))
f32b3b91
CD
3382 (forward-line -1))
3383 )
f66f03de 3384
f32b3b91
CD
3385 ;; No hang. Instead find minimum indentation of paragraph
3386 ;; after first line.
3387 ;; For the following while statement, since START is at the
aa87aafc 3388 ;; beginning of line and END is at the end of line
f32b3b91
CD
3389 ;; point is greater than START at least once (which would
3390 ;; be the case for a single line paragraph).
3391 (while (> (point) start)
3392 (beginning-of-line)
3393 (setq indent
3394 (min indent
3395 (progn
3396 (re-search-forward
3397 comment-start-skip
3398 (save-excursion (end-of-line) (point))
3399 t)
3400 (current-column))))
3401 (forward-line -1))
3402 )
3403 (setq fill-prefix (concat fill-prefix
3404 (make-string (- indent pre)
15e42531 3405 ?\ )))
f32b3b91
CD
3406 ;; first-line indent
3407 (setq first-indent
3408 (max
3409 (progn
3410 (re-search-forward
3411 comment-start-skip
3412 (save-excursion (end-of-line) (point))
3413 t)
3414 (current-column))
3415 indent))
f66f03de 3416
f32b3b91
CD
3417 ;; try to keep point at its original place
3418 (goto-char here)
3419
3420 ;; In place of the more modern fill-region-as-paragraph, a hack
3421 ;; to keep whitespace untouched on the first line within the
3422 ;; indent length and to preserve any indent on the first line
3423 ;; (first indent).
3424 (save-excursion
3425 (setq diff
3426 (buffer-substring start (+ start first-indent -1)))
15e42531 3427 (subst-char-in-region start (+ start first-indent -1) ?\ ?~ nil)
f32b3b91
CD
3428 (fill-region-as-paragraph
3429 start
3430 (- (point-max) end)
3431 (current-justification)
3432 nil)
3433 (delete-region start (+ start first-indent -1))
3434 (goto-char start)
3435 (insert diff))
3436 ;; When we want the point at the beginning of the comment
3437 ;; body fill-region will put it at the beginning of the line.
3438 (if (bolp) (skip-chars-forward (concat " \t" comment-start)))
3439 (setq fill-prefix nil))))
3440
3441(defun idlwave-calc-hanging-indent ()
3442 "Calculate the position of the hanging indent for the comment
3443paragraph. The hanging indent position is given by the first match
3444with the `idlwave-hang-indent-regexp'. If `idlwave-use-last-hang-indent' is
3445non-nil then use last occurrence matching `idlwave-hang-indent-regexp' on
3446the line.
3447If not found returns nil."
3448 (if idlwave-use-last-hang-indent
3449 (save-excursion
3450 (end-of-line)
3451 (if (re-search-backward
3452 idlwave-hang-indent-regexp
3453 (save-excursion (beginning-of-line) (point))
3454 t)
3455 (+ (current-column) (length idlwave-hang-indent-regexp))))
3456 (save-excursion
3457 (beginning-of-line)
3458 (if (re-search-forward
3459 idlwave-hang-indent-regexp
3460 (save-excursion (end-of-line) (point))
3461 t)
3462 (current-column)))))
3463
3464(defun idlwave-auto-fill ()
f66f03de 3465 "Called to break lines in auto fill mode.
52a244eb
S
3466Only fills non-comment lines if `idlwave-fill-comment-line-only' is
3467non-nil. Places a continuation character at the end of the line if
3468not in a comment. Splits strings with IDL concatenation operator `+'
3469if `idlwave-auto-fill-split-string' is non-nil."
f32b3b91
CD
3470 (if (<= (current-column) fill-column)
3471 nil ; do not to fill
3472 (if (or (not idlwave-fill-comment-line-only)
3473 (save-excursion
3474 ;; Check for comment line
3475 (beginning-of-line)
3476 (looking-at idlwave-comment-line-start-skip)))
3477 (let (beg)
3478 (idlwave-indent-line)
3479 ;; Prevent actions do-auto-fill which calls indent-line-function.
3480 (let (idlwave-do-actions
3481 (paragraph-start ".")
52a244eb
S
3482 (paragraph-separate ".")
3483 (fill-nobreak-predicate
3484 (if (and (idlwave-in-quote)
3485 idlwave-auto-fill-split-string)
3486 (lambda () ;; We'll need 5 spaces for " ' + $"
3487 (<= (- fill-column (current-column)) 5)
3488 ))))
f32b3b91
CD
3489 (do-auto-fill))
3490 (save-excursion
3491 (end-of-line 0)
3492 ;; Indent the split line
3493 (idlwave-indent-line)
3494 )
3495 (if (save-excursion
3496 (beginning-of-line)
3497 (looking-at idlwave-comment-line-start-skip))
3498 ;; A continued line comment
3499 ;; We treat continued line comments as part of a comment
3500 ;; paragraph. So we check for a hanging indent.
3501 (if idlwave-hanging-indent
3502 (let ((here (- (point-max) (point)))
3503 (indent
3504 (save-excursion
3505 (forward-line -1)
3506 (idlwave-calc-hanging-indent))))
3507 (if indent
3508 (progn
3509 ;; Remove whitespace between comment delimiter and
3510 ;; text, insert spaces for appropriate indentation.
3511 (beginning-of-line)
3512 (re-search-forward
3513 comment-start-skip
3514 (save-excursion (end-of-line) (point)) t)
3515 (delete-horizontal-space)
3516 (idlwave-indent-to indent)
3517 (goto-char (- (point-max) here)))
3518 )))
3519 ;; Split code or comment?
3520 (if (save-excursion
3521 (end-of-line 0)
3522 (idlwave-in-comment))
52a244eb 3523 ;; Splitting a non-full-line comment.
f32b3b91
CD
3524 ;; Insert the comment delimiter from split line
3525 (progn
3526 (save-excursion
3527 (beginning-of-line)
3528 (skip-chars-forward " \t")
3529 ;; Insert blank to keep off beginning of line
3530 (insert " "
3531 (save-excursion
3532 (forward-line -1)
3533 (buffer-substring (idlwave-goto-comment)
3534 (progn
3535 (skip-chars-forward "; ")
3536 (point))))))
3537 (idlwave-indent-line))
3538 ;; Split code line - add continuation character
3539 (save-excursion
3540 (end-of-line 0)
3541 ;; Check to see if we split a string
3542 (if (and (setq beg (idlwave-in-quote))
3543 idlwave-auto-fill-split-string)
3544 ;; Split the string and concatenate.
3545 ;; The first extra space is for the space
3546 ;; the line was split. That space was removed.
3547 (insert " " (char-after beg) " +"))
3548 (insert " $"))
3549 (if beg
3550 (if idlwave-auto-fill-split-string
3551 ;; Make the second part of continued string
3552 (save-excursion
3553 (beginning-of-line)
3554 (skip-chars-forward " \t")
3555 (insert (char-after beg)))
3556 ;; Warning
3557 (beep)
3558 (message "Warning: continuation inside a string.")))
3559 ;; Although do-auto-fill (via indent-new-comment-line) calls
3560 ;; idlwave-indent-line for the new line, re-indent again
3561 ;; because of the addition of the continuation character.
3562 (idlwave-indent-line))
3563 )))))
3564
3565(defun idlwave-auto-fill-mode (arg)
3566 "Toggle auto-fill mode for IDL mode.
3567With arg, turn auto-fill mode on if arg is positive.
3568In auto-fill mode, inserting a space at a column beyond `fill-column'
3569automatically breaks the line at a previous space."
3570 (interactive "P")
3571 (prog1 (set idlwave-fill-function
3572 (if (if (null arg)
3573 (not (symbol-value idlwave-fill-function))
3574 (> (prefix-numeric-value arg) 0))
3575 'idlwave-auto-fill
3576 nil))
3577 ;; update mode-line
3578 (set-buffer-modified-p (buffer-modified-p))))
3579
52a244eb
S
3580;(defun idlwave-fill-routine-call ()
3581; "Fill a routine definition or statement, indenting appropriately."
3582; (let ((where (idlwave-where)))))
3583
3584
f32b3b91
CD
3585(defun idlwave-doc-header (&optional nomark )
3586 "Insert a documentation header at the beginning of the unit.
3587Inserts the value of the variable idlwave-file-header. Sets mark before
3588moving to do insertion unless the optional prefix argument NOMARK
3589is non-nil."
3590 (interactive "P")
3591 (or nomark (push-mark))
3592 ;; make sure we catch the current line if it begins the unit
5e72c6b2
S
3593 (if idlwave-header-to-beginning-of-file
3594 (goto-char (point-min))
3595 (end-of-line)
3596 (idlwave-beginning-of-subprogram)
3597 (beginning-of-line)
3598 ;; skip function or procedure line
3599 (if (idlwave-look-at "\\<\\(pro\\|function\\)\\>")
3600 (progn
3601 (idlwave-end-of-statement)
3602 (if (> (forward-line 1) 0) (insert "\n")))))
3603 (let ((pos (point)))
3604 (if idlwave-file-header
3605 (cond ((car idlwave-file-header)
a527b753 3606 (insert-file-contents (car idlwave-file-header)))
5e72c6b2
S
3607 ((stringp (car (cdr idlwave-file-header)))
3608 (insert (car (cdr idlwave-file-header))))))
3609 (goto-char pos)))
f32b3b91
CD
3610
3611(defun idlwave-default-insert-timestamp ()
3612 "Default timestamp insertion function"
3613 (insert (current-time-string))
3614 (insert ", " (user-full-name))
5e72c6b2 3615 (if (boundp 'user-mail-address)
f66f03de 3616 (insert " <" user-mail-address ">")
5e72c6b2 3617 (insert " <" (user-login-name) "@" (system-name) ">"))
f32b3b91
CD
3618 ;; Remove extra spaces from line
3619 (idlwave-fill-paragraph)
3620 ;; Insert a blank line comment to separate from the date entry -
3621 ;; will keep the entry from flowing onto date line if re-filled.
5e72c6b2 3622 (insert "\n;\n;\t\t"))
f32b3b91
CD
3623
3624(defun idlwave-doc-modification ()
3625 "Insert a brief modification log at the beginning of the current program.
3626Looks for an occurrence of the value of user variable
3627`idlwave-doc-modifications-keyword' if non-nil. Inserts time and user name
3628and places the point for the user to add a log. Before moving, saves
3629location on mark ring so that the user can return to previous point."
3630 (interactive)
3631 (push-mark)
05a1abfc
CD
3632 (let* (beg end)
3633 (if (and (or (re-search-backward idlwave-doclib-start nil t)
3634 (progn
3635 (goto-char (point-min))
3636 (re-search-forward idlwave-doclib-start nil t)))
3637 (setq beg (match-beginning 0))
3638 (re-search-forward idlwave-doclib-end nil t)
3639 (setq end (match-end 0)))
3640 (progn
3641 (goto-char beg)
f66f03de 3642 (if (re-search-forward
05a1abfc
CD
3643 (concat idlwave-doc-modifications-keyword ":")
3644 end t)
3645 (end-of-line)
3646 (goto-char end)
3647 (end-of-line -1)
3648 (insert "\n" comment-start "\n")
3649 (insert comment-start " " idlwave-doc-modifications-keyword ":"))
3650 (insert "\n;\n;\t")
3651 (run-hooks 'idlwave-timestamp-hook))
3652 (error "No valid DOCLIB header"))))
f32b3b91
CD
3653
3654;;; CJC 3/16/93
3655;;; Interface to expand-region-abbrevs which did not work when the
3656;;; abbrev hook associated with an abbrev moves point backwards
3657;;; after abbrev expansion, e.g., as with the abbrev '.n'.
3658;;; The original would enter an infinite loop in attempting to expand
3659;;; .n (it would continually expand and unexpand the abbrev without expanding
3660;;; because the point would keep going back to the beginning of the
3661;;; abbrev instead of to the end of the abbrev). We now keep the
3662;;; abbrev hook from moving backwards.
3663;;;
3664(defun idlwave-expand-region-abbrevs (start end)
3665 "Expand each abbrev occurrence in the region.
3666Calling from a program, arguments are START END."
3667 (interactive "r")
3668 (save-excursion
3669 (goto-char (min start end))
3670 (let ((idlwave-show-block nil) ;Do not blink
3671 (idlwave-abbrev-move nil)) ;Do not move
3672 (expand-region-abbrevs start end 'noquery))))
3673
3674(defun idlwave-quoted ()
3675 "Returns t if point is in a comment or quoted string.
3676nil otherwise."
3677 (or (idlwave-in-comment) (idlwave-in-quote)))
3678
3679(defun idlwave-in-quote ()
3680 "Returns location of the opening quote
3681if point is in a IDL string constant, nil otherwise.
3682Ignores comment delimiters on the current line.
3683Properly handles nested quotation marks and octal
3684constants - a double quote followed by an octal digit."
3685;;; Treat an octal inside an apostrophe to be a normal string. Treat a
3686;;; double quote followed by an octal digit to be an octal constant
3687;;; rather than a string. Therefore, there is no terminating double
3688;;; quote.
3689 (save-excursion
3690 ;; Because single and double quotes can quote each other we must
3691 ;; search for the string start from the beginning of line.
3692 (let* ((start (point))
3693 (eol (progn (end-of-line) (point)))
3694 (bq (progn (beginning-of-line) (point)))
3695 (endq (point))
3696 (data (match-data))
3697 delim
3698 found)
3699 (while (< endq start)
3700 ;; Find string start
3701 ;; Don't find an octal constant beginning with a double quote
52a244eb 3702 (if (re-search-forward "[\"']" eol 'lim)
f32b3b91
CD
3703 ;; Find the string end.
3704 ;; In IDL, two consecutive delimiters after the start of a
3705 ;; string act as an
3706 ;; escape for the delimiter in the string.
3707 ;; Two consecutive delimiters alone (i.e., not after the
aa87aafc 3708 ;; start of a string) is the null string.
f32b3b91
CD
3709 (progn
3710 ;; Move to position after quote
3711 (goto-char (1+ (match-beginning 0)))
3712 (setq bq (1- (point)))
3713 ;; Get the string delimiter
3714 (setq delim (char-to-string (preceding-char)))
3715 ;; Check for null string
3716 (if (looking-at delim)
3717 (progn (setq endq (point)) (forward-char 1))
3718 ;; Look for next unpaired delimiter
3719 (setq found (search-forward delim eol 'lim))
3720 (while (looking-at delim)
3721 (forward-char 1)
3722 (setq found (search-forward delim eol 'lim)))
3723 (if found
3724 (setq endq (- (point) 1))
3725 (setq endq (point)))
3726 ))
3727 (progn (setq bq (point)) (setq endq (point)))))
3728 (store-match-data data)
3729 ;; return string beginning position or nil
3730 (if (> start bq) bq))))
3731
76959b77
S
3732(defun idlwave-is-pointer-dereference (&optional limit)
3733 "Determines if the character after point is a pointer dereference *."
3734 (let ((pos (point)))
3735 (and
3736 (eq (char-after) ?\*)
3737 (not (idlwave-in-quote))
3738 (save-excursion
3739 (forward-char)
f66f03de 3740 (re-search-backward (concat "\\(" idlwave-idl-keywords
76959b77
S
3741 "\\|[[(*+-/=,^><]\\)\\s-*\\*") limit t)))))
3742
3743
f32b3b91
CD
3744;; Statement templates
3745
3746;; Replace these with a general template function, something like
3747;; expand.el (I think there was also something with a name similar to
3748;; dmacro.el)
3749
3750(defun idlwave-template (s1 s2 &optional prompt noindent)
3751 "Build a template with optional prompt expression.
3752
3753Opens a line if point is not followed by a newline modulo intervening
3754whitespace. S1 and S2 are strings. S1 is inserted at point followed
595ab50b
CD
3755by S2. Point is inserted between S1 and S2. The case of S1 and S2 is
3756adjusted according to `idlwave-abbrev-change-case'. If optional argument
f32b3b91
CD
3757PROMPT is a string then it is displayed as a message in the
3758minibuffer. The PROMPT serves as a reminder to the user of an
3759expression to enter.
3760
3761The lines containing S1 and S2 are reindented using `indent-region'
3762unless the optional second argument NOINDENT is non-nil."
15e42531 3763 (if (eq major-mode 'idlwave-shell-mode)
05a1abfc 3764 ;; This is a gross hack to avoit template abbrev expansion
15e42531
CD
3765 ;; in the shell. FIXME: This is a dirty hack.
3766 (if (and (eq this-command 'self-insert-command)
3767 (equal last-abbrev-location (point)))
3768 (insert last-abbrev-text)
3769 (error "No templates in idlwave-shell"))
3770 (cond ((eq idlwave-abbrev-change-case 'down)
3771 (setq s1 (downcase s1) s2 (downcase s2)))
3772 (idlwave-abbrev-change-case
3773 (setq s1 (upcase s1) s2 (upcase s2))))
3774 (let ((beg (save-excursion (beginning-of-line) (point)))
3775 end)
3776 (if (not (looking-at "\\s-*\n"))
3777 (open-line 1))
3778 (insert s1)
3779 (save-excursion
3780 (insert s2)
3781 (setq end (point)))
3782 (if (not noindent)
3783 (indent-region beg end nil))
3784 (if (stringp prompt)
3785 (message prompt)))))
f66f03de 3786
595ab50b
CD
3787(defun idlwave-rw-case (string)
3788 "Make STRING have the case required by `idlwave-reserved-word-upcase'."
3789 (if idlwave-reserved-word-upcase
3790 (upcase string)
3791 string))
3792
f32b3b91
CD
3793(defun idlwave-elif ()
3794 "Build skeleton IDL if-else block."
3795 (interactive)
595ab50b
CD
3796 (idlwave-template
3797 (idlwave-rw-case "if")
3798 (idlwave-rw-case " then begin\n\nendif else begin\n\nendelse")
3799 "Condition expression"))
f32b3b91
CD
3800
3801(defun idlwave-case ()
3802 "Build skeleton IDL case statement."
3803 (interactive)
f66f03de 3804 (idlwave-template
595ab50b
CD
3805 (idlwave-rw-case "case")
3806 (idlwave-rw-case " of\n\nendcase")
3807 "Selector expression"))
f32b3b91 3808
05a1abfc
CD
3809(defun idlwave-switch ()
3810 "Build skeleton IDL switch statement."
3811 (interactive)
f66f03de 3812 (idlwave-template
05a1abfc
CD
3813 (idlwave-rw-case "switch")
3814 (idlwave-rw-case " of\n\nendswitch")
3815 "Selector expression"))
3816
f32b3b91
CD
3817(defun idlwave-for ()
3818 "Build skeleton for loop statment."
3819 (interactive)
f66f03de 3820 (idlwave-template
595ab50b
CD
3821 (idlwave-rw-case "for")
3822 (idlwave-rw-case " do begin\n\nendfor")
3823 "Loop expression"))
f32b3b91
CD
3824
3825(defun idlwave-if ()
3826 "Build skeleton for loop statment."
3827 (interactive)
595ab50b
CD
3828 (idlwave-template
3829 (idlwave-rw-case "if")
3830 (idlwave-rw-case " then begin\n\nendif")
3831 "Scalar logical expression"))
f32b3b91
CD
3832
3833(defun idlwave-procedure ()
3834 (interactive)
f66f03de 3835 (idlwave-template
595ab50b
CD
3836 (idlwave-rw-case "pro")
3837 (idlwave-rw-case "\n\nreturn\nend")
3838 "Procedure name"))
f32b3b91
CD
3839
3840(defun idlwave-function ()
3841 (interactive)
f66f03de 3842 (idlwave-template
595ab50b
CD
3843 (idlwave-rw-case "function")
3844 (idlwave-rw-case "\n\nreturn\nend")
3845 "Function name"))
f32b3b91
CD
3846
3847(defun idlwave-repeat ()
3848 (interactive)
595ab50b
CD
3849 (idlwave-template
3850 (idlwave-rw-case "repeat begin\n\nendrep until")
3851 (idlwave-rw-case "")
3852 "Exit condition"))
f32b3b91
CD
3853
3854(defun idlwave-while ()
3855 (interactive)
f66f03de 3856 (idlwave-template
595ab50b
CD
3857 (idlwave-rw-case "while")
3858 (idlwave-rw-case " do begin\n\nendwhile")
3859 "Entry condition"))
f32b3b91
CD
3860
3861(defun idlwave-split-string (string &optional pattern)
3862 "Return a list of substrings of STRING which are separated by PATTERN.
3863If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
3864 (or pattern
3865 (setq pattern "[ \f\t\n\r\v]+"))
3866 (let (parts (start 0))
3867 (while (string-match pattern string start)
3868 (setq parts (cons (substring string start (match-beginning 0)) parts)
3869 start (match-end 0)))
3870 (nreverse (cons (substring string start) parts))))
3871
3872(defun idlwave-replace-string (string replace_string replace_with)
3873 (let* ((start 0)
3874 (last (length string))
3875 (ret_string "")
3876 end)
3877 (while (setq end (string-match replace_string string start))
3878 (setq ret_string
3879 (concat ret_string (substring string start end) replace_with))
3880 (setq start (match-end 0)))
3881 (setq ret_string (concat ret_string (substring string start last)))))
3882
3883(defun idlwave-get-buffer-visiting (file)
3884 ;; Return the buffer currently visiting FILE
3885 (cond
3886 ((boundp 'find-file-compare-truenames) ; XEmacs
3887 (let ((find-file-compare-truenames t))
3888 (get-file-buffer file)))
3889 ((fboundp 'find-buffer-visiting) ; Emacs
3890 (find-buffer-visiting file))
3891 (t (error "This should not happen (idlwave-get-buffer-visiting)"))))
3892
15e42531
CD
3893(defvar idlwave-outlawed-buffers nil
3894 "List of buffer pulled up by idlwave for special reasons.
3895Buffers in this list may be killed by `idlwave-kill-autoloaded-buffers'.")
3896
3897(defun idlwave-find-file-noselect (file &optional why)
f32b3b91
CD
3898 ;; Return a buffer visiting file.
3899 (or (idlwave-get-buffer-visiting file)
15e42531
CD
3900 (let ((buf (find-file-noselect file)))
3901 (if why (add-to-list 'idlwave-outlawed-buffers (cons buf why)))
3902 buf)))
3903
3904(defun idlwave-kill-autoloaded-buffers ()
52a244eb 3905 "Kill buffers created automatically by IDLWAVE.
15e42531
CD
3906Function prompts for a letter to identify the buffers to kill.
3907Possible letters are:
3908
3909f Buffers created by the command \\[idlwave-find-module] or mouse
3910 clicks in the routine info window.
3911s Buffers created by the IDLWAVE Shell to display where execution
3912 stopped or an error was found.
3913a Both of the above.
3914
3915Buffer containing unsaved changes require confirmation before they are killed."
3916 (interactive)
3917 (if (null idlwave-outlawed-buffers)
3918 (error "No IDLWAVE-created buffers available")
3919 (princ (format "Kill IDLWAVE-created buffers: [f]ind source(%d), [s]hell display(%d), [a]ll ? "
3920 (idlwave-count-outlawed-buffers 'find)
3921 (idlwave-count-outlawed-buffers 'shell)))
3922 (let ((c (read-char)))
3923 (cond
3924 ((member c '(?f ?\C-f))
3925 (idlwave-do-kill-autoloaded-buffers 'find))
3926 ((member c '(?s ?\C-s))
3927 (idlwave-do-kill-autoloaded-buffers 'shell))
3928 ((member c '(?a ?\C-a))
3929 (idlwave-do-kill-autoloaded-buffers t))
3930 (t (error "Abort"))))))
3931
3932(defun idlwave-count-outlawed-buffers (tag)
3933 "How many outlawed buffers have tag TAG?"
3934 (length (delq nil
f66f03de
S
3935 (mapcar
3936 (lambda (x) (eq (cdr x) tag))
15e42531
CD
3937 idlwave-outlawed-buffers))))
3938
3939(defun idlwave-do-kill-autoloaded-buffers (&rest reasons)
3940 "Kill all buffers pulled up by IDLWAVE matching REASONS."
3941 (let* ((list (copy-sequence idlwave-outlawed-buffers))
3942 (cnt 0)
3943 entry)
3944 (while (setq entry (pop list))
3945 (if (buffer-live-p (car entry))
3946 (and (or (memq t reasons)
3947 (memq (cdr entry) reasons))
3948 (kill-buffer (car entry))
3949 (incf cnt)
f66f03de 3950 (setq idlwave-outlawed-buffers
15e42531 3951 (delq entry idlwave-outlawed-buffers)))
f66f03de 3952 (setq idlwave-outlawed-buffers
15e42531
CD
3953 (delq entry idlwave-outlawed-buffers))))
3954 (message "%d buffer%s killed" cnt (if (= cnt 1) "" "s"))))
3955
3956(defun idlwave-revoke-license-to-kill ()
3957 "Remove BUFFER from the buffers which may be killed.
3958Killing would be done by `idlwave-do-kill-autoloaded-buffers'.
3959Intended for `after-save-hook'."
3960 (let* ((buf (current-buffer))
3961 (entry (assq buf idlwave-outlawed-buffers)))
3962 ;; Revoke license
3963 (if entry
f66f03de 3964 (setq idlwave-outlawed-buffers
15e42531
CD
3965 (delq entry idlwave-outlawed-buffers)))
3966 ;; Remove this function from the hook.
3967 (remove-hook 'after-save-hook 'idlwave-revoke-license-to-kill 'local)))
3968
3969(defvar idlwave-path-alist)
3970(defun idlwave-locate-lib-file (file)
f32b3b91 3971 ;; Find FILE on the scanned lib path and return a buffer visiting it
15e42531 3972 (let* ((dirs idlwave-path-alist)
f32b3b91
CD
3973 dir efile)
3974 (catch 'exit
15e42531 3975 (while (setq dir (car (pop dirs)))
f32b3b91
CD
3976 (if (file-regular-p
3977 (setq efile (expand-file-name file dir)))
15e42531 3978 (throw 'exit efile))))))
52a244eb 3979
15e42531
CD
3980(defun idlwave-expand-lib-file-name (file)
3981 ;; Find FILE on the scanned lib path and return a buffer visiting it
52a244eb 3982 ;; This is for, e.g., finding source with no user catalog
f66f03de 3983 (cond
15e42531 3984 ((null file) nil)
15e42531
CD
3985 ((file-name-absolute-p file) file)
3986 (t (idlwave-locate-lib-file file))))
f32b3b91
CD
3987
3988(defun idlwave-make-tags ()
3989 "Creates the IDL tags file IDLTAGS in the current directory from
3990the list of directories specified in the minibuffer. Directories may be
3991for example: . /usr/local/rsi/idl/lib. All the subdirectories of the
3992specified top directories are searched if the directory name is prefixed
3993by @. Specify @ directories with care, it may take a long, long time if
3994you specify /."
3995 (interactive)
3996 (let (directory directories cmd append status numdirs dir getsubdirs
3997 buffer save_buffer files numfiles item errbuf)
f66f03de 3998
f32b3b91
CD
3999 ;;
4000 ;; Read list of directories
4001 (setq directory (read-string "Tag Directories: " "."))
4002 (setq directories (idlwave-split-string directory "[ \t]+"))
4003 ;;
4004 ;; Set etags command, vars
4005 (setq cmd "etags --output=IDLTAGS --language=none --regex='/[
4006\\t]*[pP][Rr][Oo][ \\t]+\\([^ \\t,]+\\)/' --regex='/[
4007\\t]*[Ff][Uu][Nn][Cc][Tt][Ii][Oo][Nn][ \\t]+\\([^ \\t,]+\\)/' ")
4008 (setq append " ")
4009 (setq status 0)
4010 ;;
4011 ;; For each directory
4012 (setq numdirs 0)
4013 (setq dir (nth numdirs directories))
4014 (while (and dir)
4015 ;;
4016 ;; Find the subdirectories
4017 (if (string-match "^[@]\\(.+\\)$" dir)
4018 (setq getsubdirs t) (setq getsubdirs nil))
4019 (if (and getsubdirs) (setq dir (substring dir 1 (length dir))))
4020 (setq dir (expand-file-name dir))
4021 (if (file-directory-p dir)
4022 (progn
4023 (if (and getsubdirs)
4024 (progn
4025 (setq buffer (get-buffer-create "*idltags*"))
4026 (call-process "sh" nil buffer nil "-c"
4027 (concat "find " dir " -type d -print"))
4028 (setq save_buffer (current-buffer))
4029 (set-buffer buffer)
4030 (setq files (idlwave-split-string
4031 (idlwave-replace-string
4032 (buffer-substring 1 (point-max))
4033 "\n" "/*.pro ")
4034 "[ \t]+"))
4035 (set-buffer save_buffer)
4036 (kill-buffer buffer))
4037 (setq files (list (concat dir "/*.pro"))))
4038 ;;
4039 ;; For each subdirectory
4040 (setq numfiles 0)
4041 (setq item (nth numfiles files))
4042 (while (and item)
4043 ;;
4044 ;; Call etags
4045 (if (not (string-match "^[ \\t]*$" item))
4046 (progn
29a4e67d 4047 (message "%s" (concat "Tagging " item "..."))
f32b3b91 4048 (setq errbuf (get-buffer-create "*idltags-error*"))
52a244eb 4049 (setq status (+ status
f66f03de 4050 (if (eq 0 (call-process
52a244eb
S
4051 "sh" nil errbuf nil "-c"
4052 (concat cmd append item)))
4053 0
4054 1)))
f32b3b91
CD
4055 ;;
4056 ;; Append additional tags
4057 (setq append " --append ")
4058 (setq numfiles (1+ numfiles))
4059 (setq item (nth numfiles files)))
4060 (progn
4061 (setq numfiles (1+ numfiles))
4062 (setq item (nth numfiles files))
4063 )))
f66f03de 4064
f32b3b91
CD
4065 (setq numdirs (1+ numdirs))
4066 (setq dir (nth numdirs directories)))
4067 (progn
4068 (setq numdirs (1+ numdirs))
4069 (setq dir (nth numdirs directories)))))
f66f03de 4070
f32b3b91
CD
4071 (setq errbuf (get-buffer-create "*idltags-error*"))
4072 (if (= status 0)
4073 (kill-buffer errbuf))
4074 (message "")
4075 ))
4076
4077(defun idlwave-toggle-comment-region (beg end &optional n)
4078 "Comment the lines in the region if the first non-blank line is
4079commented, and conversely, uncomment region. If optional prefix arg
4080N is non-nil, then for N positive, add N comment delimiters or for N
4081negative, remove N comment delimiters.
4082Uses `comment-region' which does not place comment delimiters on
4083blank lines."
4084 (interactive "r\nP")
4085 (if n
4086 (comment-region beg end (prefix-numeric-value n))
4087 (save-excursion
4088 (goto-char beg)
4089 (beginning-of-line)
4090 ;; skip blank lines
4091 (skip-chars-forward " \t\n")
4092 (if (looking-at (concat "[ \t]*\\(" comment-start "+\\)"))
52a244eb
S
4093 (if (fboundp 'uncomment-region)
4094 (uncomment-region beg end)
4095 (comment-region beg end
4096 (- (length (buffer-substring
4097 (match-beginning 1)
4098 (match-end 1))))))
4099 (comment-region beg end)))))
f32b3b91
CD
4100
4101
4102;; ----------------------------------------------------------------------------
4103;; ----------------------------------------------------------------------------
4104;; ----------------------------------------------------------------------------
4105;; ----------------------------------------------------------------------------
4106;;
4107;; Completion and Routine Info
4108;;
4109
4110;; String "intern" functions
4111
4112;; For the completion and routine info function, we want to normalize
4113;; the case of procedure names etc. We do this by "interning" these
4114;; string is a hand-crafted way. Hashes are used to map the downcase
52a244eb
S
4115;; version of the strings to the cased versions. Most *-sint-*
4116;; variables consist of *two* hashes, a buffer+shell, followed by a
4117;; system hash. The former is re-scanned, and the latter takes case
4118;; precedence.
4119;;
4120;; Since these cased versions are really lisp objects, we can use `eq'
4121;; to search, which is a large performance boost. All new strings
4122;; need to be "sinterned". We do this as early as possible after
4123;; getting these strings from completion or buffer substrings. So
4124;; most of the code can simply assume to deal with "sinterned"
4125;; strings. The only exception is that the functions which scan whole
4126;; buffers for routine information do not intern the grabbed strings.
4127;; This is only done afterwards. Therefore in these functions it is
4128;; *not* safe to assume the strings can be compared with `eq' and be
4129;; fed into the routine assq functions.
f32b3b91
CD
4130
4131;; Here we define the hashing functions.
4132
4133;; The variables which hold the hashes.
4134(defvar idlwave-sint-routines '(nil))
4135(defvar idlwave-sint-keywords '(nil))
4136(defvar idlwave-sint-methods '(nil))
4137(defvar idlwave-sint-classes '(nil))
52a244eb
S
4138(defvar idlwave-sint-dirs '(nil))
4139(defvar idlwave-sint-libnames '(nil))
f32b3b91
CD
4140
4141(defun idlwave-reset-sintern (&optional what)
4142 "Reset all sintern hashes."
4143 ;; Make sure the hash functions are accessible.
4144 (if (or (not (fboundp 'gethash))
4145 (not (fboundp 'puthash)))
f66f03de 4146 (progn
f32b3b91
CD
4147 (require 'cl)
4148 (or (fboundp 'puthash)
4149 (defalias 'puthash 'cl-puthash))))
4150 (let ((entries '((idlwave-sint-routines 1000 10)
4151 (idlwave-sint-keywords 1000 10)
4152 (idlwave-sint-methods 100 10)
4153 (idlwave-sint-classes 10 10))))
4154
4155 ;; Make sure these are lists
4156 (loop for entry in entries
4157 for var = (car entry)
4158 do (if (not (consp (symbol-value var))) (set var (list nil))))
4159
f66f03de 4160 ;; Reset the system & library hash
f32b3b91
CD
4161 (when (or (eq what t) (eq what 'syslib)
4162 (null (cdr idlwave-sint-routines)))
f32b3b91
CD
4163 (loop for entry in entries
4164 for var = (car entry) for size = (nth 1 entry)
f66f03de 4165 do (setcdr (symbol-value var)
f32b3b91 4166 (make-hash-table ':size size ':test 'equal)))
52a244eb
S
4167 (setq idlwave-sint-dirs nil
4168 idlwave-sint-libnames nil))
f32b3b91 4169
f66f03de 4170 ;; Reset the buffer & shell hash
f32b3b91
CD
4171 (when (or (eq what t) (eq what 'bufsh)
4172 (null (car idlwave-sint-routines)))
f32b3b91
CD
4173 (loop for entry in entries
4174 for var = (car entry) for size = (nth 1 entry)
f66f03de 4175 do (setcar (symbol-value var)
f32b3b91
CD
4176 (make-hash-table ':size size ':test 'equal))))))
4177
4178(defun idlwave-sintern-routine-or-method (name &optional class set)
4179 (if class
4180 (idlwave-sintern-method name set)
4181 (idlwave-sintern-routine name set)))
4182
4183(defun idlwave-sintern (stype &rest args)
4184 (apply (intern (concat "idlwave-sintern-" (symbol-name stype))) args))
4185
4186;;(defmacro idlwave-sintern (type var)
4187;; `(cond ((not (stringp name)) name)
4188;; ((gethash (downcase name) (cdr ,var)))
4189;; ((gethash (downcase name) (car ,var)))
4190;; (set (idlwave-sintern-set name ,type ,var set))
4191;; (name)))
4192
4193(defun idlwave-sintern-routine (name &optional set)
4194 (cond ((not (stringp name)) name)
4195 ((gethash (downcase name) (cdr idlwave-sint-routines)))
4196 ((gethash (downcase name) (car idlwave-sint-routines)))
4197 (set (idlwave-sintern-set name 'routine idlwave-sint-routines set))
4198 (name)))
4199(defun idlwave-sintern-keyword (name &optional set)
4200 (cond ((not (stringp name)) name)
4201 ((gethash (downcase name) (cdr idlwave-sint-keywords)))
4202 ((gethash (downcase name) (car idlwave-sint-keywords)))
4203 (set (idlwave-sintern-set name 'keyword idlwave-sint-keywords set))
4204 (name)))
4205(defun idlwave-sintern-method (name &optional set)
4206 (cond ((not (stringp name)) name)
4207 ((gethash (downcase name) (cdr idlwave-sint-methods)))
4208 ((gethash (downcase name) (car idlwave-sint-methods)))
4209 (set (idlwave-sintern-set name 'method idlwave-sint-methods set))
4210 (name)))
4211(defun idlwave-sintern-class (name &optional set)
4212 (cond ((not (stringp name)) name)
4213 ((gethash (downcase name) (cdr idlwave-sint-classes)))
4214 ((gethash (downcase name) (car idlwave-sint-classes)))
4215 (set (idlwave-sintern-set name 'class idlwave-sint-classes set))
4216 (name)))
4217
52a244eb
S
4218(defun idlwave-sintern-dir (dir &optional set)
4219 (car (or (member dir idlwave-sint-dirs)
4220 (setq idlwave-sint-dirs (cons dir idlwave-sint-dirs)))))
4221(defun idlwave-sintern-libname (name &optional set)
4222 (car (or (member name idlwave-sint-libnames)
4223 (setq idlwave-sint-libnames (cons name idlwave-sint-libnames)))))
f32b3b91
CD
4224
4225(defun idlwave-sintern-set (name type tables set)
4226 (let* ((func (or (cdr (assq type idlwave-completion-case))
4227 'identity))
4228 (iname (funcall (if (eq func 'preserve) 'identity func) name))
4229 (table (if (eq set 'sys) (cdr tables) (car tables))))
4230 (puthash (downcase name) iname table)
4231 iname))
4232
52a244eb
S
4233(defun idlwave-sintern-keyword-list (kwd-list &optional set)
4234 "Sintern a set of keywords (file (key . link) (key2 . link2) ...)"
4235 (mapcar (lambda(x)
4236 (setcar x (idlwave-sintern-keyword (car x) set)))
4237 (cdr kwd-list))
4238 kwd-list)
4239
4240(defun idlwave-sintern-rinfo-list (list &optional set default-dir)
4241 "Sintern all strings in the rinfo LIST. With optional parameter
4242SET: also set new patterns. Probably this will always have to be t.
4243If DEFAULT-DIR is passed, it is used as the base of the directory"
4244 (let (entry name type class kwds res source call new)
f32b3b91
CD
4245 (while list
4246 (setq entry (car list)
4247 list (cdr list)
4248 name (car entry)
4249 type (nth 1 entry)
4250 class (nth 2 entry)
4251 source (nth 3 entry)
4252 call (nth 4 entry)
52a244eb
S
4253 kwds (nthcdr 5 entry))
4254
4255 ;; The class and name
f32b3b91
CD
4256 (if class
4257 (progn
4258 (if (symbolp class) (setq class (symbol-name class)))
4259 (setq class (idlwave-sintern-class class set))
4260 (setq name (idlwave-sintern-method name set)))
4261 (setq name (idlwave-sintern-routine name set)))
f66f03de 4262
52a244eb
S
4263 ;; The source
4264 (let ((source-type (car source))
4265 (source-file (nth 1 source))
f66f03de 4266 (source-dir (if default-dir
52a244eb
S
4267 (file-name-as-directory default-dir)
4268 (nth 2 source)))
4269 (source-lib (nth 3 source)))
4270 (if (stringp source-dir)
4271 (setq source-dir (idlwave-sintern-dir source-dir set)))
4272 (if (stringp source-lib)
4273 (setq source-lib (idlwave-sintern-libname source-lib set)))
4274 (setq source (list source-type source-file source-dir source-lib)))
f66f03de 4275
52a244eb
S
4276 ;; The keywords
4277 (setq kwds (mapcar (lambda (x)
4278 (idlwave-sintern-keyword-list x set))
4279 kwds))
4280
4281 ;; Build a canonicalized list
4282 (setq new (nconc (list name type class source call) kwds)
4283 res (cons new res)))
f32b3b91
CD
4284 (nreverse res)))
4285
05a1abfc
CD
4286;; Creating new sintern tables
4287
4288(defun idlwave-new-sintern-type (tag)
4289 "Define a variable and a function to sintern the new type TAG.
4290This defines the function `idlwave-sintern-TAG' and the variable
4291`idlwave-sint-TAGs'."
4292 (let* ((name (symbol-name tag))
4293 (names (concat name "s"))
4294 (var (intern (concat "idlwave-sint-" names)))
4295 (func (intern (concat "idlwave-sintern-" name))))
4296 (set var nil) ; initial value of the association list
4297 (fset func ; set the function
4298 `(lambda (name &optional set)
4299 (cond ((not (stringp name)) name)
4300 ((cdr (assoc (downcase name) ,var)))
4301 (set
4302 (setq ,var (cons (cons (downcase name) name) ,var))
4303 name)
4304 (name))))))
4305
4306(defun idlwave-reset-sintern-type (tag)
4307 "Reset the sintern variable associated with TAG."
4308 (set (intern (concat "idlwave-sint-" (symbol-name tag) "s")) nil))
4309
f32b3b91
CD
4310;;---------------------------------------------------------------------------
4311
4312
4313;; The variables which hold the information
15e42531 4314(defvar idlwave-system-routines nil
f32b3b91
CD
4315 "Holds the routine-info obtained by scanning buffers.")
4316(defvar idlwave-buffer-routines nil
4317 "Holds the routine-info obtained by scanning buffers.")
4318(defvar idlwave-compiled-routines nil
15e42531
CD
4319 "Holds the routine-info obtained by asking the shell.")
4320(defvar idlwave-unresolved-routines nil
4321 "Holds the unresolved routine-info obtained by asking the shell.")
52a244eb
S
4322(defvar idlwave-user-catalog-routines nil
4323 "Holds the procedure routine-info from the user scan.")
4324(defvar idlwave-library-catalog-routines nil
3938cb82
S
4325 "Holds the procedure routine-info from the .idlwave_catalog library files.")
4326(defvar idlwave-library-catalog-libname nil
4327 "Name of library catalog loaded from .idlwave_catalog files.")
15e42531 4328(defvar idlwave-path-alist nil
52a244eb
S
4329 "Alist with !PATH directories and zero or more flags if the dir has
4330been scanned in a user catalog ('user) or discovered in a library
4331catalog \('lib).")
15e42531
CD
4332(defvar idlwave-true-path-alist nil
4333 "Like `idlwave-path-alist', but with true filenames.")
f32b3b91 4334(defvar idlwave-routines nil
52a244eb 4335 "Holds the combinded procedure/function/method routine-info.")
f32b3b91
CD
4336(defvar idlwave-class-alist nil
4337 "Holds the class names known to IDLWAVE.")
4338(defvar idlwave-class-history nil
4339 "The history of classes selected with the minibuffer.")
4340(defvar idlwave-force-class-query nil)
4341(defvar idlwave-before-completion-wconf nil
4342 "The window configuration just before the completion buffer was displayed.")
15e42531
CD
4343(defvar idlwave-last-system-routine-info-cons-cell nil
4344 "The last cons cell in the system routine info.")
f32b3b91
CD
4345
4346;;
4347;; The code to get routine info from different sources.
4348
15e42531 4349(defvar idlwave-system-routines)
5e72c6b2
S
4350(defvar idlwave-catalog-process nil
4351 "The background process currently updating the catalog.")
4352
f32b3b91
CD
4353(defun idlwave-routines ()
4354 "Provide a list of IDL routines.
4355This routine loads the builtin routines on the first call. Later it
4356only returns the value of the variable."
5e72c6b2
S
4357 (if (and idlwave-catalog-process
4358 (processp idlwave-catalog-process))
4359 (progn
4360 (cond
4361 ((equal (process-status idlwave-catalog-process) 'exit)
4362 (message "updating........")
4363 (setq idlwave-catalog-process nil)
4364 (idlwave-update-routine-info '(4)))
4365 ((equal (process-status idlwave-catalog-process) 'run)
4366 ;; Keep it running...
4367 )
4368 (t
4369 ;; Something is wrong, get rid of the process
4370 (message "Problem with catalog process") (beep)
4371 (condition-case nil
4372 (kill-process idlwave-catalog-process)
4373 (error nil))
4374 (setq idlwave-catalog-process nil)))))
f32b3b91
CD
4375 (or idlwave-routines
4376 (progn
4377 (idlwave-update-routine-info)
4378 ;; return the current value
4379 idlwave-routines)))
4380
05a1abfc
CD
4381(defvar idlwave-update-rinfo-hook nil
4382 "List of functions which should run after a global rinfo update.
4383Does not run after automatic updates of buffer or the shell.")
4384
5e72c6b2
S
4385(defun idlwave-rescan-catalog-directories ()
4386 "Rescan the previously selected directories. For batch processing."
4387 (idlwave-update-routine-info '(16)))
4388
4389(defun idlwave-rescan-asynchronously ()
4390 "Dispatch another emacs instance to update the idlwave catalog.
4391After the process finishes normally, the first access to routine info
4392will re-read the catalog."
4393 (interactive)
4394 (if (processp idlwave-catalog-process)
4395 (if (eq (process-status idlwave-catalog-process) 'run)
4396 (if (yes-or-no-p "A catalog-updating process is running. Kill it? ")
4397 (progn
4398 (condition-case nil
4399 (kill-process idlwave-catalog-process)
4400 (error nil))
4401 (error "Process killed, no new process started"))
4402 (error "Quit"))
4403 (condition-case nil
4404 (kill-process idlwave-catalog-process)
4405 (error nil))))
52a244eb
S
4406 (if (or (not idlwave-user-catalog-file)
4407 (not (stringp idlwave-user-catalog-file))
4408 (not (file-regular-p idlwave-user-catalog-file)))
5e72c6b2
S
4409 (error "No catalog has been produced yet"))
4410 (let* ((emacs (expand-file-name (invocation-name) (invocation-directory)))
4411 (args (list "-batch"
4412 "-l" (expand-file-name "~/.emacs")
4413 "-l" "idlwave"
4414 "-f" "idlwave-rescan-catalog-directories"))
f66f03de 4415 (process (apply 'start-process "idlcat"
5e72c6b2
S
4416 nil emacs args)))
4417 (setq idlwave-catalog-process process)
f66f03de 4418 (set-process-sentinel
5e72c6b2
S
4419 process
4420 (lambda (pro why)
4421 (when (string-match "finished" why)
4422 (setq idlwave-routines nil
4423 idlwave-system-routines nil
4424 idlwave-catalog-process nil)
4425 (or (idlwave-start-load-rinfo-timer)
4426 (idlwave-update-routine-info '(4))))))
4427 (message "Background job started to update catalog file")))
4428
4429
52a244eb
S
4430;; Format for all routine info user catalog, library catalogs, etc.:
4431;;
4432;; ("ROUTINE" type class
4433;; (system) | (lib pro_file dir "LIBNAME") | (user pro_file dir "USERLIB") |
4434;; (buffer pro_file dir) | (compiled pro_file dir)
f66f03de
S
4435;; "calling_string" ("HELPFILE" (("KWD1" . link1) ...))
4436;; ("HELPFILE2" (("KWD2" . link) ...)) ...)
52a244eb
S
4437;;
4438;; DIR will be supplied dynamically while loading library catalogs,
4439;; and is sinterned to save space, as is LIBNAME. PRO_FILE can be a
4440;; complete filepath, in which case DIR is unnecessary. HELPFILE can
4441;; be nil, as can LINK1, etc., if no HTML help is available.
4442
4443
5e72c6b2 4444(defvar idlwave-load-rinfo-idle-timer)
3938cb82
S
4445(defvar idlwave-shell-path-query)
4446
52a244eb 4447(defun idlwave-update-routine-info (&optional arg no-concatenate)
f32b3b91
CD
4448 "Update the internal routine-info lists.
4449These lists are used by `idlwave-routine-info' (\\[idlwave-routine-info])
4450and by `idlwave-complete' (\\[idlwave-complete]) to provide information
4451about individual routines.
4452
4453The information can come from 4 sources:
44541. IDL programs in the current editing session
44552. Compiled modules in an IDL shell running as Emacs subprocess
44563. A list which covers the IDL system routines.
44574. A list which covers the prescanned library files.
4458
4459Scans all IDLWAVE-mode buffers of the current editing session (see
4460`idlwave-scan-all-buffers-for-routine-info').
4461When an IDL shell is running, this command also queries the IDL program
4462for currently compiled routines.
4463
4464With prefix ARG, also reload the system and library lists.
52a244eb
S
4465With two prefix ARG's, also rescans the chosen user catalog tree.
4466With three prefix args, dispatch asynchronous process to do the update.
4467
4468If NO-CONCATENATE is non-nil, don't pre-concatenate the routine info
4469lists, but instead wait for the shell query to complete and
4470asynchronously finish updating routine info. This is set
4471automatically when called interactively. When you need routine
4472information updated immediately, leave NO-CONCATENATE nil."
751adbde 4473 (interactive "P\np")
5e72c6b2
S
4474 ;; Stop any idle processing
4475 (if (or (and (fboundp 'itimerp)
4476 (itimerp idlwave-load-rinfo-idle-timer))
4477 (and (fboundp 'timerp)
4478 (timerp idlwave-load-rinfo-idle-timer)))
4479 (cancel-timer idlwave-load-rinfo-idle-timer))
4480 (cond
4481 ((equal arg '(64))
4482 ;; Start a background process which updates the catalog.
4483 (idlwave-rescan-asynchronously))
4484 ((equal arg '(16))
52a244eb
S
4485 ;; Update the user catalog now, and wait for them.
4486 (idlwave-create-user-catalog-file t))
5e72c6b2
S
4487 (t
4488 (let* ((load (or arg
4489 idlwave-buffer-case-takes-precedence
4490 (null idlwave-routines)))
4491 ;; The override-idle means, even if the idle timer has done some
4492 ;; preparing work, load and renormalize everything anyway.
4493 (override-idle (or arg idlwave-buffer-case-takes-precedence)))
f66f03de 4494
f32b3b91 4495 (setq idlwave-buffer-routines nil
15e42531
CD
4496 idlwave-compiled-routines nil
4497 idlwave-unresolved-routines nil)
f32b3b91 4498 ;; Reset the appropriate hashes
5e72c6b2
S
4499 (if (get 'idlwave-reset-sintern 'done-by-idle)
4500 ;; reset was already done in idle time, so skip this step now once
4501 (put 'idlwave-reset-sintern 'done-by-idle nil)
4502 (idlwave-reset-sintern (cond (load t)
4503 ((null idlwave-system-routines) t)
4504 (t 'bufsh))))
f66f03de 4505
f32b3b91
CD
4506 (if idlwave-buffer-case-takes-precedence
4507 ;; We can safely scan the buffer stuff first
4508 (progn
4509 (idlwave-update-buffer-routine-info)
f66f03de 4510 (and load (idlwave-load-all-rinfo override-idle)))
f32b3b91 4511 ;; We first do the system info, and then the buffers
f66f03de 4512 (and load (idlwave-load-all-rinfo override-idle))
f32b3b91
CD
4513 (idlwave-update-buffer-routine-info))
4514
4515 ;; Let's see if there is a shell
4516 (let* ((shell-is-running (and (fboundp 'idlwave-shell-is-running)
4517 (idlwave-shell-is-running)))
4518 (ask-shell (and shell-is-running
4519 idlwave-query-shell-for-routine-info)))
f66f03de 4520
52a244eb 4521 ;; Load the library catalogs again, first re-scanning the path
f66f03de 4522 (when arg
52a244eb
S
4523 (if shell-is-running
4524 (idlwave-shell-send-command idlwave-shell-path-query
4525 '(progn
4526 (idlwave-shell-get-path-info)
4527 (idlwave-scan-library-catalogs))
4528 'hide)
4529 (idlwave-scan-library-catalogs)))
775591f7 4530
f32b3b91 4531 (if (or (not ask-shell)
52a244eb 4532 (not no-concatenate))
f32b3b91
CD
4533 ;; 1. If we are not going to ask the shell, we need to do the
4534 ;; concatenation now.
52a244eb
S
4535 ;; 2. When this function is called non-interactively, it
4536 ;; means that someone needs routine info *now*. The
4537 ;; shell update causes the concatenation to be
4538 ;; *delayed*, so not in time for the current command.
4539 ;; Therefore, we do a concatenation now, even though
4540 ;; the shell might do it again.
4541 (idlwave-concatenate-rinfo-lists nil 'run-hooks))
f66f03de 4542
f32b3b91 4543 (when ask-shell
52a244eb 4544 ;; Ask the shell about the routines it knows of.
f32b3b91 4545 (message "Querying the shell")
5e72c6b2
S
4546 (idlwave-shell-update-routine-info nil t)))))))
4547
52a244eb
S
4548
4549(defvar idlwave-load-rinfo-steps-done (make-vector 6 nil))
5e72c6b2
S
4550(defvar idlwave-load-rinfo-idle-timer nil)
4551(defun idlwave-start-load-rinfo-timer ()
4552 (if (or (and (fboundp 'itimerp)
4553 (itimerp idlwave-load-rinfo-idle-timer))
4554 (and (fboundp 'timerp)
4555 (timerp idlwave-load-rinfo-idle-timer)))
4556 (cancel-timer idlwave-load-rinfo-idle-timer))
52a244eb 4557 (setq idlwave-load-rinfo-steps-done (make-vector 6 nil))
5e72c6b2
S
4558 (setq idlwave-load-rinfo-idle-timer nil)
4559 (if (and idlwave-init-rinfo-when-idle-after
4560 (numberp idlwave-init-rinfo-when-idle-after)
4561 (not (equal 0 idlwave-init-rinfo-when-idle-after))
4562 (not idlwave-routines))
4563 (condition-case nil
4564 (progn
4565 (setq idlwave-load-rinfo-idle-timer
4566 (run-with-idle-timer
4567 idlwave-init-rinfo-when-idle-after
4568 nil 'idlwave-load-rinfo-next-step)))
4569 (error nil))))
4570
3938cb82
S
4571(defvar idlwave-library-routines nil "Obsolete variable.")
4572
f66f03de
S
4573;;------ XML Help routine info system
4574(defun idlwave-load-system-routine-info ()
4575 ;; Load the system routine info from the cached routine info file,
4576 ;; which, if necessary, will be re-created from the XML file on
4577 ;; disk. As a last fallback, load the (likely outdated) idlw-rinfo
4578 ;; file distributed with older IDLWAVE versions (<6.0)
4579 (unless (and (load idlwave-xml-system-rinfo-converted-file
4580 'noerror 'nomessage)
4581 (idlwave-xml-system-routine-info-up-to-date))
4582 ;; See if we can create it from XML source
4583 (condition-case nil
4584 (idlwave-convert-xml-system-routine-info)
4585 (error
4586 (unless (load idlwave-xml-system-rinfo-converted-file
4587 'noerror 'nomessage)
4588 (if idlwave-system-routines
4589 (message
4590 "Failed to load converted routine info, using old conversion.")
4591 (message
4592 "Failed to convert XML routine info, falling back on idlw-rinfo.")
4593 (if (not (load "idlw-rinfo" 'noerror 'nomessage))
4594 (message
4595 "Could not locate any system routine information."))))))))
4596
4597(defun idlwave-xml-system-routine-info-up-to-date()
4598 (let* ((dir (file-name-as-directory
4599 (expand-file-name "help/online_help" (idlwave-sys-dir))))
4600 (catalog-file (expand-file-name "idl_catalog.xml" dir)))
4601 (file-newer-than-file-p ;converted file is newer than catalog
4602 idlwave-xml-system-rinfo-converted-file
4603 catalog-file)))
4604
4605(defvar idlwave-system-class-info nil) ; Gathered from idlw-rinfo
4606(defvar idlwave-system-variables-alist nil
4607 "Alist of system variables and the associated structure tags.
4608Gets set in cached XML rinfo, or `idlw-rinfo.el'.")
4609(defvar idlwave-executive-commands-alist nil
4610 "Alist of system variables and their help files.")
4611(defvar idlwave-help-special-topic-words nil)
4612
4613
4614(defun idlwave-shorten-syntax (syntax name &optional class)
4615 ;; From a list of syntax statments, shorten with %s and group with "or"
4616 (let ((case-fold-search t))
4617 (mapconcat
4618 (lambda (x)
4619 (while (string-match name x)
4620 (setq x (replace-match "%s" t t x)))
4621 (if class
4622 (while (string-match class x)
4623 (setq x (replace-match "%s" t t x))))
4624 x)
4625 (nreverse syntax)
4626 " or ")))
4627
4628(defun idlwave-xml-create-class-method-lists (xml-entry)
4629 ;; Create a class list entry from the xml parsed list., returning a
4630 ;; cons of form (class-entry method-entries).
4631 (let* ((nameblock (nth 1 xml-entry))
4632 (class (cdr (assq 'name nameblock)))
4633 (link (cdr (assq 'link nameblock)))
4634 (params (cddr xml-entry))
4635 (case-fold-search t)
4636 class-entry
4637 method methods-entry extra-kwds
4638 props get-props set-props init-props inherits
4639 pelem ptype)
4640 (while params
4641 (setq pelem (car params))
4642 (when (listp pelem)
4643 (setq ptype (car pelem)
4644 props (car (cdr pelem)))
4645 (cond
4646 ((eq ptype 'SUPERCLASS)
4647 (push (cdr (assq 'name props)) inherits))
4648
4649 ((eq ptype 'PROPERTY)
4650 (let ((pname (cdr (assq 'name props)))
4651 (plink (cdr (assq 'link props)))
4652 (get (string= (cdr (assq 'get props)) "Yes"))
4653 (set (string= (cdr (assq 'set props)) "Yes"))
4654 (init (string= (cdr (assq 'init props)) "Yes")))
4655 (if get (push (list pname plink) get-props))
4656 (if set (push (list pname plink) set-props))
4657 (if init (push (list pname plink) init-props))))
4658
4659 ((eq ptype 'METHOD)
4660 (setq method (cdr (assq 'name props)))
4661 (setq extra-kwds ;;Assume all property keywords are gathered already
4662 (cond
4663 ((string-match (concat class "::Init") method)
4664 (put 'init-props 'matched t)
4665 init-props)
4666 ((string-match (concat class "::GetProperty") method)
4667 (put 'get-props 'matched t)
4668 get-props)
4669 ((string-match (concat class "::SetProperty") method)
4670 (put 'set-props 'matched t)
4671 set-props)
4672 (t nil)))
4673 (setq methods-entry
4674 (nconc (idlwave-xml-create-rinfo-list pelem class extra-kwds)
4675 methods-entry)))
4676 (t)))
4677 (setq params (cdr params)))
4678 ;(unless (get 'init-props 'matched)
4679 ; (message "Failed to match Init in class %s" class))
4680 ;(unless (get 'get-props 'matched)
4681 ; (message "Failed to match GetProperty in class %s" class))
4682 ;(unless (get 'set-props 'matched)
4683 ; (message "Failed to match SetProperty in class %s" class))
4684 (setq class-entry
4685 (if inherits
4686 (list class (append '(inherits) inherits) (list 'link link))
4687 (list class (list 'link link))))
4688 (cons class-entry methods-entry)))
4689
4690(defun idlwave-xml-create-rinfo-list (xml-entry &optional class extra-kws)
4691 ;; Create correctly structured list elements from ROUTINE or METHOD
4692 ;; XML list structures. Return a list of list elements, with more
4693 ;; than one sub-list possible if a routine can serve as both
4694 ;; procedure and function (e.g. call_method).
4695 (let* ((nameblock (nth 1 xml-entry))
4696 (name (cdr (assq 'name nameblock)))
4697 (link (cdr (assq 'link nameblock)))
4698 (params (cddr xml-entry))
4699 (syntax-vec (make-vector 3 nil)) ; procedure, function, exec command
4700 (case-fold-search t)
4701 syntax kwd klink pref-list kwds pelem ptype entry props result type)
4702 (if class ;; strip out class name from class method name string
4703 (if (string-match (concat class "::") name)
4704 (setq name (substring name (match-end 0)))))
4705 (while params
4706 (setq pelem (car params))
4707 (when (listp pelem)
4708 (setq ptype (car pelem)
4709 props (car (cdr pelem)))
4710 (cond
4711 ((eq ptype 'SYNTAX)
4712 (setq syntax (cdr (assq 'name props)))
4713 (if (string-match "-&gt;" syntax)
4714 (setq syntax (replace-match "->" t nil syntax)))
4715 (setq type (cdr (assq 'type props)))
4716 (push syntax
4717 (aref syntax-vec (cond
4718 ((string-match "^pro" type) 0)
4719 ((string-match "^fun" type) 1)
4720 ((string-match "^exec" type) 2)))))
4721 ((eq ptype 'KEYWORD)
4722 (setq kwd (cdr (assq 'name props))
4723 klink (cdr (assq 'link props)))
4724 (if (string-match "^\\[XY\\(Z?\\)\\]" kwd)
4725 (progn
4726 (setq pref-list
4727 (if (match-string 1 kwd) '("X" "Y" "Z") '("X" "Y"))
4728 kwd (substring kwd (match-end 0)))
4729 (loop for x in pref-list do
4730 (push (list (concat x kwd) klink) kwds)))
4731 (push (list kwd klink) kwds)))
4732
4733 (t))); Do nothing for the others
4734 (setq params (cdr params)))
4735
4736 ;; Debug
4737; (if (and (null (aref syntax-vec 0))
4738; (null (aref syntax-vec 1))
4739; (null (aref syntax-vec 2)))
4740; (with-current-buffer (get-buffer-create "IDL_XML_catalog_complaints")
4741; (if class
4742; (insert (format "Missing SYNTAX entry for %s::%s\n" class name))
4743; (insert (message "Missing SYNTAX entry for %s\n" name)))))
4744
4745 ;; Executive commands are treated specially
4746 (if (aref syntax-vec 2)
4747 (cons (substring name 1) link)
4748 (if extra-kws (setq kwds (nconc kwds extra-kws)))
4749 (setq kwds (idlwave-rinfo-group-keywords kwds link))
4750 (loop for idx from 0 to 1 do
4751 (if (aref syntax-vec idx)
4752 (push (append (list name (if (eq idx 0) 'pro 'fun)
4753 class '(system)
4754 (idlwave-shorten-syntax
4755 (aref syntax-vec idx) name class))
4756 kwds) result)))
4757 result)))
4758
4759
4760(defun idlwave-rinfo-group-keywords (kwds master-link)
4761 ;; Group keywords by link file, as a list with elements
4762 ;; (linkfile ( ("KWD1" . link1) ("KWD2" . link2))
4763 (let (kwd link anchor linkfiles block master-elt)
4764 (while kwds
4765 (setq kwd (car kwds)
4766 link (idlwave-split-link-target (nth 1 kwd))
4767 anchor (cdr link)
4768 link (car link)
4769 kwd (car kwd))
4770 (if (setq block (assoc link linkfiles))
4771 (push (cons kwd anchor) (cdr block))
4772 (push (list link (cons kwd anchor)) linkfiles))
4773 (setq kwds (cdr kwds)))
4774 ;; Ensure the master link is there
4775 (if (setq master-elt (assoc master-link linkfiles))
4776 (if (eq (car linkfiles) master-elt)
4777 linkfiles
4778 (cons master-elt (delq master-elt linkfiles)))
4779 (push (list master-link) linkfiles))))
4780
4781(defun idlwave-convert-xml-clean-statement-aliases (aliases)
4782 ;; Clean up the syntax of routines which are actually aliases by
4783 ;; removing the "OR" from the statements
4784 (let (syntax entry)
4785 (loop for x in aliases do
4786 (setq entry (assoc x idlwave-system-routines))
4787 (when entry
4788 (while (string-match " +or +" (setq syntax (nth 4 entry)))
4789 (setf (nth 4 entry) (replace-match ", " t t syntax)))))))
4790
4791(defun idlwave-convert-xml-clean-routine-aliases (aliases)
4792 ;; Duplicate and trim original routine aliases from rinfo list
4793 ;; This if for, e.g. OPENR/OPENW/OPENU
4794 (let (alias remove-list new parts all-parts)
4795 (loop for x in aliases do
4796 (when (setq parts (split-string (cdr x) "/"))
4797 (setq new (assoc (cdr x) all-parts))
4798 (unless new
4799 (setq new (cons (cdr x) parts))
4800 (push new all-parts))
4801 (setcdr new (delete (car x) (cdr new)))))
4802
4803 ;; Add any missing aliases (separate by slashes)
4804 (loop for x in all-parts do
4805 (if (cdr x)
4806 (push (cons (nth 1 x) (car x)) aliases)))
4807
4808 (loop for x in aliases do
4809 (when (setq alias (assoc (cdr x) idlwave-system-routines))
4810 (unless (memq alias remove-list) (push alias remove-list))
4811 (setq alias (copy-sequence alias))
4812 (setcar alias (car x))
4813 (push alias idlwave-system-routines)))
4814 (loop for x in remove-list do
4815 (delq x idlwave-system-routines))))
4816
4817(defun idlwave-convert-xml-clean-sysvar-aliases (aliases)
4818 ;; Duplicate and trim original routine aliases from rinfo list
4819 ;; This if for, e.g. !X, !Y, !Z.
4820 (let (alias remove-list new parts all-parts)
4821 (loop for x in aliases do
4822 (when (setq alias (assoc (cdr x) idlwave-system-variables-alist))
4823 (unless (memq alias remove-list) (push alias remove-list))
4824 (setq alias (copy-sequence alias))
4825 (setcar alias (car x))
4826 (push alias idlwave-system-variables-alist)))
4827 (loop for x in remove-list do
4828 (delq x idlwave-system-variables-alist))))
4829
4830
4831(defun idlwave-xml-create-sysvar-alist (xml-entry)
4832 ;; Create a sysvar list entry from the xml parsed list.
4833 (let* ((nameblock (nth 1 xml-entry))
4834 (sysvar (substring (cdr (assq 'name nameblock)) 1))
4835 (link (cdr (assq 'link nameblock)))
4836 (params (cddr xml-entry))
4837 (case-fold-search t)
4838 pelem ptype props fields tags)
4839 (while params
4840 (setq pelem (car params))
4841 (when (listp pelem)
4842 (setq ptype (car pelem)
4843 props (car (cdr pelem)))
4844 (cond
4845 ((eq ptype 'FIELD)
4846 (push (cons (cdr (assq 'name props))
4847 (cdr
4848 (idlwave-split-link-target (cdr (assq 'link props)))))
4849 tags))))
4850 (setq params (cdr params)))
4851 (delq nil
4852 (list sysvar (if tags (cons 'tags tags)) (list 'link link)))))
4853
4854
4855(defvar idlwave-xml-routine-info-file nil)
4856
4857(defun idlwave-save-routine-info ()
4858 (if idlwave-xml-routine-info-file
4859 (with-temp-file idlwave-xml-system-rinfo-converted-file
4860 (insert
4861 (concat ";; *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
4862;; IDLWAVE Routine Information File (IDLWAVE version " idlwave-mode-version ")
4863;; Automatically generated from source file:
4864;; " idlwave-xml-routine-info-file "
4865;; on " (current-time-string) "
4866;; Do not edit."))
4867 (insert (format "\n(setq idlwave-xml-routine-info-file \n \"%s\")"
4868 idlwave-xml-routine-info-file))
4869 (insert "\n(setq idlwave-system-routines\n '")
4870 (prin1 idlwave-system-routines (current-buffer))
4871 (insert ")")
4872 (insert "\n(setq idlwave-system-variables-alist\n '")
4873 (prin1 idlwave-system-variables-alist (current-buffer))
4874 (insert ")")
4875 (insert "\n(setq idlwave-system-class-info\n '")
4876 (prin1 idlwave-system-class-info (current-buffer))
4877 (insert ")")
4878 (insert "\n(setq idlwave-executive-commands-alist\n '")
4879 (prin1 idlwave-executive-commands-alist (current-buffer))
4880 (insert ")")
4881 (insert "\n(setq idlwave-help-special-topic-words\n '")
4882 (prin1 idlwave-help-special-topic-words (current-buffer))
4883 (insert ")"))))
4884
4885(defun idlwave-convert-xml-system-routine-info ()
4886 "Convert XML supplied IDL routine info into internal form.
4887Cache to disk for quick recovery."
4888 (interactive)
4889 (let* ((dir (file-name-as-directory
4890 (expand-file-name "help/online_help" (idlwave-sys-dir))))
4891 (catalog-file (expand-file-name "idl_catalog.xml" dir))
4892 (elem-cnt 0)
4893 props rinfo msg-cnt elem type nelem class-result alias
4894 routines routine-aliases statement-aliases sysvar-aliases
4895 buf version-string)
4896 (if (not (file-exists-p catalog-file))
4897 (error "No such XML routine info file: %s" catalog-file)
4898 (if (not (file-readable-p catalog-file))
4899 (error "Cannot read XML routine info file: %s" catalog-file)))
4900 (require 'xml)
4901 (message "Reading XML routine info...")
4902 (unwind-protect
4903 (progn
4904 ;; avoid warnings about read-only files
4905 (setq buf (find-file-noselect catalog-file 'nowarn))
4906 (setq rinfo (xml-parse-file catalog-file)))
4907 (if (bufferp buf) (kill-buffer buf)))
4908 (message "Reading XML routine info...done")
4909 (setq rinfo (assq 'CATALOG rinfo))
4910 (unless rinfo (error "Failed to parse XML routine info"))
4911 ;;(setq rinfo (car rinfo)) ; Skip the catalog stuff.
4912
4913 (setq version-string (cdr (assq 'version (nth 1 rinfo)))
4914 rinfo (cddr rinfo))
4915
4916 (setq nelem (length rinfo)
4917 msg-cnt (/ nelem 20))
4918
4919 (setq idlwave-xml-routine-info-file nil)
4920 (message "Converting XML routine info...")
4921 (setq idlwave-system-routines nil
4922 idlwave-system-variables-alist nil
4923 idlwave-system-class-info nil
4924 idlwave-executive-commands-alist nil
4925 idlwave-help-special-topic-words nil)
4926
4927 (while rinfo
4928 (setq elem (car rinfo)
4929 rinfo (cdr rinfo))
4930 (incf elem-cnt)
4931 (when (listp elem)
4932 (setq type (car elem)
4933 props (car (cdr elem)))
4934 (if (= (mod elem-cnt msg-cnt) 0)
4935 (message "Converting XML routine info...%2d%%"
4936 (/ (* elem-cnt 100) nelem)))
4937 (cond
4938 ((eq type 'ROUTINE)
4939 (if (setq alias (assq 'alias_to props))
4940 (push (cons (cdr (assq 'name props)) (cdr alias))
4941 routine-aliases)
4942 (setq routines (idlwave-xml-create-rinfo-list elem))
4943 (if (listp (cdr routines))
4944 (setq idlwave-system-routines
4945 (nconc idlwave-system-routines routines))
4946 ;; a cons cell is an executive commands
4947 (push routines idlwave-executive-commands-alist))))
4948
4949 ((eq type 'CLASS)
4950 (setq class-result (idlwave-xml-create-class-method-lists elem))
4951 (push (car class-result) idlwave-system-class-info)
4952 (setq idlwave-system-routines
4953 (nconc idlwave-system-routines (cdr class-result))))
4954
4955 ((eq type 'STATEMENT)
4956 (push (cons (cdr (assq 'name props))
4957 (cdr (assq 'link props)))
4958 idlwave-help-special-topic-words)
4959 ;; Save the links to those which are statement aliases (not routines)
4960 (if (setq alias (assq 'alias_to props))
4961 (unless (member (cdr alias) statement-aliases)
4962 (push (cdr alias) statement-aliases))))
4963
4964 ((eq type 'SYSVAR)
4965 (if (setq alias (cdr (assq 'alias_to props)))
4966 (push (cons (substring (cdr (assq 'name props)) 1)
4967 (substring alias 1))
4968 sysvar-aliases)
4969 (push (idlwave-xml-create-sysvar-alist elem)
4970 idlwave-system-variables-alist)))
4971 (t))))
4972 (idlwave-convert-xml-clean-routine-aliases routine-aliases)
4973 (idlwave-convert-xml-clean-statement-aliases statement-aliases)
4974 (idlwave-convert-xml-clean-sysvar-aliases sysvar-aliases)
4975
4976 (setq idlwave-xml-routine-info-file catalog-file)
4977 (idlwave-save-routine-info)
4978 (message "Converting XML routine info...done")))
4979
4980
4981;; ("ROUTINE" type class
4982;; (system) | (lib pro_file dir "LIBNAME") | (user pro_file dir "USERLIB") |
4983;; (buffer pro_file dir) | (compiled pro_file dir)
4984;; "calling_string" ("HELPFILE" (("KWD1" . link1) ...))
4985;; ("HELPFILE2" (("KWD2" . link) ...)) ...)
4986
4987
5e72c6b2
S
4988(defun idlwave-load-rinfo-next-step ()
4989 (let ((inhibit-quit t)
4990 (arr idlwave-load-rinfo-steps-done))
f66f03de 4991 (if (catch 'exit
5e72c6b2 4992 (when (not (aref arr 0))
f66f03de
S
4993 (message "Loading system routine info in idle time...")
4994 (idlwave-load-system-routine-info)
4995 ;;(load "idlw-rinfo" 'noerror 'nomessage)
4996 (message "Loading system routine info in idle time...done")
5e72c6b2
S
4997 (aset arr 0 t)
4998 (throw 'exit t))
f66f03de 4999
5e72c6b2
S
5000 (when (not (aref arr 1))
5001 (message "Normalizing idlwave-system-routines in idle time...")
5002 (idlwave-reset-sintern t)
5003 (put 'idlwave-reset-sintern 'done-by-idle t)
5004 (setq idlwave-system-routines
5005 (idlwave-sintern-rinfo-list idlwave-system-routines 'sys))
5006 (message "Normalizing idlwave-system-routines in idle time...done")
5007 (aset arr 1 t)
5008 (throw 'exit t))
f66f03de 5009
5e72c6b2 5010 (when (not (aref arr 2))
52a244eb
S
5011 (when (and (stringp idlwave-user-catalog-file)
5012 (file-regular-p idlwave-user-catalog-file))
5013 (message "Loading user catalog in idle time...")
5e72c6b2 5014 (condition-case nil
52a244eb
S
5015 (load-file idlwave-user-catalog-file)
5016 (error (throw 'exit nil)))
5017 ;; Check for the old style catalog and warn
5018 (if (and
5019 (boundp 'idlwave-library-routines)
5020 idlwave-library-routines)
775591f7 5021 (progn
52a244eb
S
5022 (setq idlwave-library-routines nil)
5023 (ding)
f66f03de 5024 (message "Outdated user catalog: %s... recreate"
52a244eb 5025 idlwave-user-catalog-file))
f66f03de
S
5026 (message "Loading user catalog in idle time...done")))
5027 (aset arr 2 t)
5028 (throw 'exit t))
5029
5e72c6b2 5030 (when (not (aref arr 3))
52a244eb
S
5031 (when idlwave-user-catalog-routines
5032 (message "Normalizing user catalog routines in idle time...")
f66f03de 5033 (setq idlwave-user-catalog-routines
52a244eb
S
5034 (idlwave-sintern-rinfo-list
5035 idlwave-user-catalog-routines 'sys))
f66f03de 5036 (message
52a244eb 5037 "Normalizing user catalog routines in idle time...done"))
5e72c6b2
S
5038 (aset arr 3 t)
5039 (throw 'exit t))
f66f03de 5040
5e72c6b2 5041 (when (not (aref arr 4))
f66f03de 5042 (idlwave-scan-library-catalogs
52a244eb
S
5043 "Loading and normalizing library catalogs in idle time...")
5044 (aset arr 4 t)
5045 (throw 'exit t))
5046 (when (not (aref arr 5))
5e72c6b2
S
5047 (message "Finishing initialization in idle time...")
5048 (idlwave-routines)
5049 (message "Finishing initialization in idle time...done")
f66f03de 5050 (aset arr 5 t)
5e72c6b2 5051 (throw 'exit nil)))
52a244eb
S
5052 ;; restart the timer
5053 (if (sit-for 1)
5054 (idlwave-load-rinfo-next-step)
5055 (setq idlwave-load-rinfo-idle-timer
5056 (run-with-idle-timer
5057 idlwave-init-rinfo-when-idle-after
5058 nil 'idlwave-load-rinfo-next-step))))))
5e72c6b2 5059
f66f03de
S
5060(defun idlwave-load-all-rinfo (&optional force)
5061 ;; Load and case-treat the system, user catalog, and library routine
5062 ;; info files.
5063
5064 ;; System
5e72c6b2 5065 (when (or force (not (aref idlwave-load-rinfo-steps-done 0)))
f66f03de
S
5066 ;;(load "idlw-rinfo" 'noerror 'nomessage))
5067 (idlwave-load-system-routine-info))
5e72c6b2
S
5068 (when (or force (not (aref idlwave-load-rinfo-steps-done 1)))
5069 (message "Normalizing idlwave-system-routines...")
5070 (setq idlwave-system-routines
5071 (idlwave-sintern-rinfo-list idlwave-system-routines 'sys))
5072 (message "Normalizing idlwave-system-routines...done"))
f66f03de
S
5073 (when idlwave-system-routines
5074 (setq idlwave-routines (copy-sequence idlwave-system-routines))
5075 (setq idlwave-last-system-routine-info-cons-cell
5076 (nthcdr (1- (length idlwave-routines)) idlwave-routines)))
5077
5078 ;; User catalog
52a244eb
S
5079 (when (and (stringp idlwave-user-catalog-file)
5080 (file-regular-p idlwave-user-catalog-file))
f32b3b91 5081 (condition-case nil
52a244eb
S
5082 (when (or force (not (aref idlwave-load-rinfo-steps-done 2)))
5083 (load-file idlwave-user-catalog-file))
5084 (error nil))
f66f03de
S
5085 (when (and
5086 (boundp 'idlwave-library-routines)
5087 idlwave-library-routines)
52a244eb 5088 (setq idlwave-library-routines nil)
f66f03de
S
5089 (error "Outdated user catalog: %s... recreate"
5090 idlwave-user-catalog-file))
52a244eb
S
5091 (setq idlwave-true-path-alist nil)
5092 (when (or force (not (aref idlwave-load-rinfo-steps-done 3)))
5093 (message "Normalizing user catalog routines...")
f66f03de
S
5094 (setq idlwave-user-catalog-routines
5095 (idlwave-sintern-rinfo-list
52a244eb
S
5096 idlwave-user-catalog-routines 'sys))
5097 (message "Normalizing user catalog routines...done")))
f66f03de
S
5098
5099 ;; Library catalog
52a244eb
S
5100 (when (or force (not (aref idlwave-load-rinfo-steps-done 4)))
5101 (idlwave-scan-library-catalogs
5102 "Loading and normalizing library catalogs..."))
05a1abfc
CD
5103 (run-hooks 'idlwave-after-load-rinfo-hook))
5104
f32b3b91
CD
5105
5106(defun idlwave-update-buffer-routine-info ()
5107 (let (res)
f66f03de 5108 (cond
15e42531
CD
5109 ((eq idlwave-scan-all-buffers-for-routine-info t)
5110 ;; Scan all buffers, current buffer last
5111 (message "Scanning all buffers...")
f66f03de 5112 (setq res (idlwave-get-routine-info-from-buffers
15e42531
CD
5113 (reverse (buffer-list)))))
5114 ((null idlwave-scan-all-buffers-for-routine-info)
5115 ;; Don't scan any buffers
5116 (setq res nil))
5117 (t
f32b3b91
CD
5118 ;; Just scan this buffer
5119 (if (eq major-mode 'idlwave-mode)
5120 (progn
5121 (message "Scanning current buffer...")
5122 (setq res (idlwave-get-routine-info-from-buffers
15e42531 5123 (list (current-buffer))))))))
f32b3b91 5124 ;; Put the result into the correct variable
f66f03de 5125 (setq idlwave-buffer-routines
52a244eb 5126 (idlwave-sintern-rinfo-list res 'set))))
f32b3b91 5127
05a1abfc 5128(defun idlwave-concatenate-rinfo-lists (&optional quiet run-hook)
f32b3b91 5129 "Put the different sources for routine information together."
f66f03de 5130 ;; The sequence here is important because earlier definitions shadow
f32b3b91 5131 ;; later ones. We assume that if things in the buffers are newer
52a244eb 5132 ;; then in the shell of the system, they are meant to be different.
15e42531
CD
5133 (setcdr idlwave-last-system-routine-info-cons-cell
5134 (append idlwave-buffer-routines
5135 idlwave-compiled-routines
52a244eb
S
5136 idlwave-library-catalog-routines
5137 idlwave-user-catalog-routines))
f32b3b91 5138 (setq idlwave-class-alist nil)
15e42531 5139
f32b3b91 5140 ;; Give a message with information about the number of routines we have.
15e42531 5141 (unless quiet
f66f03de 5142 (message
52a244eb 5143 "Routines Found: buffer(%d) compiled(%d) library(%d) user(%d) system(%d)"
15e42531
CD
5144 (length idlwave-buffer-routines)
5145 (length idlwave-compiled-routines)
52a244eb
S
5146 (length idlwave-library-catalog-routines)
5147 (length idlwave-user-catalog-routines)
05a1abfc
CD
5148 (length idlwave-system-routines)))
5149 (if run-hook
5150 (run-hooks 'idlwave-update-rinfo-hook)))
15e42531
CD
5151
5152(defun idlwave-class-alist ()
5153 "Return the class alist - make it if necessary."
5154 (or idlwave-class-alist
5155 (let (class)
5156 (loop for x in idlwave-routines do
5157 (when (and (setq class (nth 2 x))
5158 (not (assq class idlwave-class-alist)))
5159 (push (list class) idlwave-class-alist)))
f66f03de 5160 idlwave-class-alist)))
15e42531
CD
5161
5162;; Three functions for the hooks
5163(defun idlwave-save-buffer-update ()
5164 (idlwave-update-current-buffer-info 'save-buffer))
5165(defun idlwave-kill-buffer-update ()
5166 (idlwave-update-current-buffer-info 'kill-buffer))
5167(defun idlwave-new-buffer-update ()
5168 (idlwave-update-current-buffer-info 'find-file))
5169
5170(defun idlwave-update-current-buffer-info (why)
52a244eb 5171 "Update idlwave-routines for current buffer. Can run from after-save-hook."
15e42531
CD
5172 (when (and (eq major-mode 'idlwave-mode)
5173 (or (eq t idlwave-auto-routine-info-updates)
5174 (memq why idlwave-auto-routine-info-updates))
5175 idlwave-scan-all-buffers-for-routine-info
5176 idlwave-routines)
5177 (condition-case nil
5178 (let (routines)
5179 (idlwave-replace-buffer-routine-info
5180 (buffer-file-name)
5181 (if (eq why 'kill-buffer)
5182 nil
5183 (setq routines
5184 (idlwave-sintern-rinfo-list
5185 (idlwave-get-routine-info-from-buffers
5186 (list (current-buffer))) 'set))))
5187 (idlwave-concatenate-rinfo-lists 'quiet)
5188 routines)
5189 (error nil))))
5190
5191(defun idlwave-replace-buffer-routine-info (file new)
5192 "Cut the part from FILE out of `idlwave-buffer-routines' and add NEW."
f66f03de 5193 (let ((list idlwave-buffer-routines)
15e42531
CD
5194 found)
5195 (while list
5196 ;; The following test uses eq to make sure it works correctly
5197 ;; when two buffers visit the same file. Then the file names
5198 ;; will be equal, but not eq.
52a244eb 5199 (if (eq (idlwave-routine-source-file (nth 3 (car list))) file)
15e42531
CD
5200 (progn
5201 (setcar list nil)
5202 (setq found t))
5203 (if found
f66f03de 5204 ;; End of that section reached. Jump.
15e42531
CD
5205 (setq list nil)))
5206 (setq list (cdr list)))
5207 (setq idlwave-buffer-routines
5208 (append new (delq nil idlwave-buffer-routines)))))
f32b3b91
CD
5209
5210;;----- Scanning buffers -------------------
5211
5212(defun idlwave-get-routine-info-from-buffers (buffers)
5213 "Call `idlwave-get-buffer-routine-info' on idlwave-mode buffers in BUFFERS."
5214 (let (buf routine-lists res)
5215 (save-excursion
5216 (while (setq buf (pop buffers))
5217 (set-buffer buf)
05a1abfc
CD
5218 (if (and (eq major-mode 'idlwave-mode)
5219 buffer-file-name)
f32b3b91
CD
5220 ;; yes, this buffer has the right mode.
5221 (progn (setq res (condition-case nil
5222 (idlwave-get-buffer-routine-info)
5223 (error nil)))
5224 (push res routine-lists)))))
5225 ;; Concatenate the individual lists and return the result
5226 (apply 'nconc routine-lists)))
5227
5228(defun idlwave-get-buffer-routine-info ()
5229 "Scan the current buffer for routine info. Return (PRO-LIST FUNC-LIST)."
5230 (let* ((case-fold-search t)
5231 routine-list string entry)
5232 (save-excursion
5233 (save-restriction
5234 (widen)
5235 (goto-char (point-min))
f66f03de 5236 (while (re-search-forward
15e42531 5237 "^[ \t]*\\(pro\\|function\\)[ \t]" nil t)
76959b77 5238 (setq string (buffer-substring-no-properties
f32b3b91 5239 (match-beginning 0)
f66f03de 5240 (progn
f32b3b91
CD
5241 (idlwave-end-of-statement)
5242 (point))))
5243 (setq entry (idlwave-parse-definition string))
5244 (push entry routine-list))))
5245 routine-list))
5246
15e42531 5247(defvar idlwave-scanning-lib-dir)
f32b3b91
CD
5248(defun idlwave-parse-definition (string)
5249 "Parse a module definition."
5250 (let ((case-fold-search t)
5251 start name args type keywords class)
5252 ;; Remove comments
5253 (while (string-match ";.*" string)
5254 (setq string (replace-match "" t t string)))
5255 ;; Remove the continuation line stuff
5256 (while (string-match "\\([^a-zA-Z0-9$_]\\)\\$[ \t]*\n" string)
5257 (setq string (replace-match "\\1 " t nil string)))
05a1abfc
CD
5258 (while (string-match "\n" string)
5259 (setq string (replace-match " " t nil string)))
f32b3b91
CD
5260 ;; Match the name and type.
5261 (when (string-match
5262 "\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)" string)
5263 (setq start (match-end 0))
5264 (setq type (downcase (match-string 1 string)))
5265 (if (match-beginning 3)
5266 (setq class (match-string 3 string)))
5267 (setq name (match-string 4 string)))
5268 ;; Match normal args and keyword args
5269 (while (string-match
15e42531 5270 ",\\s-*\\([a-zA-Z][a-zA-Z0-9$_]*\\|\\(_ref\\)?_extra\\)\\s-*\\(=\\)?"
f32b3b91
CD
5271 string start)
5272 (setq start (match-end 0))
15e42531 5273 (if (match-beginning 3)
f32b3b91
CD
5274 (push (match-string 1 string) keywords)
5275 (push (match-string 1 string) args)))
5276 ;; Normalize and sort.
5277 (setq args (nreverse args))
f66f03de 5278 (setq keywords (sort keywords (lambda (a b)
f32b3b91
CD
5279 (string< (downcase a) (downcase b)))))
5280 ;; Make and return the entry
5281 ;; We don't know which argument are optional, so this information
5282 ;; will not be contained in the calling sequence.
5283 (list name
5284 (if (equal type "pro") 'pro 'fun)
5285 class
5286 (cond ((not (boundp 'idlwave-scanning-lib))
52a244eb 5287 (list 'buffer (buffer-file-name)))
f66f03de 5288; ((string= (downcase
15e42531
CD
5289; (file-name-sans-extension
5290; (file-name-nondirectory (buffer-file-name))))
5291; (downcase name))
5292; (list 'lib))
5293; (t (cons 'lib (file-name-nondirectory (buffer-file-name))))
52a244eb
S
5294 (t (list 'user (file-name-nondirectory (buffer-file-name))
5295 idlwave-scanning-lib-dir "UserLib")))
f66f03de 5296 (concat
f32b3b91
CD
5297 (if (string= type "function") "Result = " "")
5298 (if class "Obj ->[%s::]" "")
5299 "%s"
5300 (if args
5301 (concat
5302 (if (string= type "function") "(" ", ")
5303 (mapconcat 'identity args ", ")
5304 (if (string= type "function") ")" ""))))
5305 (if keywords
52a244eb 5306 (cons nil (mapcar 'list keywords)) ;No help file
f32b3b91
CD
5307 nil))))
5308
f32b3b91 5309
52a244eb 5310;;----- Scanning the user catalog -------------------
15e42531
CD
5311
5312(defun idlwave-sys-dir ()
5313 "Return the syslib directory, or a dummy that never matches."
3938cb82
S
5314 (cond
5315 ((and idlwave-system-directory
5316 (not (string= idlwave-system-directory "")))
5317 idlwave-system-directory)
5318 ((getenv "IDL_DIR"))
5319 (t "@@@@@@@@")))
5320
52a244eb 5321
52a244eb 5322(defun idlwave-create-user-catalog-file (&optional arg)
f32b3b91 5323 "Scan all files on selected dirs of IDL search path for routine information.
52a244eb
S
5324
5325A widget checklist will allow you to choose the directories. Write
5326the result as a file `idlwave-user-catalog-file'. When this file
5327exists, will be automatically loaded to give routine information about
5328library routines. With ARG, just rescan the same directories as last
5329time - so no widget will pop up."
f32b3b91
CD
5330 (interactive "P")
5331 ;; Make sure the file is loaded if it exists.
52a244eb
S
5332 (if (and (stringp idlwave-user-catalog-file)
5333 (file-regular-p idlwave-user-catalog-file))
f32b3b91 5334 (condition-case nil
52a244eb 5335 (load-file idlwave-user-catalog-file)
f32b3b91
CD
5336 (error nil)))
5337 ;; Make sure the file name makes sense
52a244eb
S
5338 (unless (and (stringp idlwave-user-catalog-file)
5339 (> (length idlwave-user-catalog-file) 0)
f32b3b91 5340 (file-accessible-directory-p
52a244eb 5341 (file-name-directory idlwave-user-catalog-file))
f66f03de 5342 (not (string= "" (file-name-nondirectory
52a244eb
S
5343 idlwave-user-catalog-file))))
5344 (error "`idlwave-user-catalog-file' does not point to a file in an accessible directory"))
f66f03de 5345
f32b3b91 5346 (cond
f32b3b91 5347 ;; Rescan the known directories
52a244eb
S
5348 ((and arg idlwave-path-alist
5349 (consp (car idlwave-path-alist)))
5350 (idlwave-scan-user-lib-files idlwave-path-alist))
5351
5352 ;; Expand the directories from library-path and run the widget
f32b3b91 5353 (idlwave-library-path
52a244eb 5354 (idlwave-display-user-catalog-widget
f66f03de 5355 (if idlwave-true-path-alist
52a244eb
S
5356 ;; Propagate any flags on the existing path-alist
5357 (mapcar (lambda (x)
5358 (let ((path-entry (assoc (file-truename x)
5359 idlwave-true-path-alist)))
5360 (if path-entry
f66f03de 5361 (cons x (cdr path-entry))
52a244eb
S
5362 (list x))))
5363 (idlwave-expand-path idlwave-library-path))
5364 (mapcar 'list (idlwave-expand-path idlwave-library-path)))))
5365
5366 ;; Ask the shell for the path and then run the widget
f32b3b91 5367 (t
f32b3b91 5368 (message "Asking the shell for IDL path...")
15e42531
CD
5369 (require 'idlw-shell)
5370 (idlwave-shell-send-command idlwave-shell-path-query
52a244eb 5371 '(idlwave-user-catalog-command-hook nil)
15e42531 5372 'hide))))
f32b3b91 5373
52a244eb
S
5374
5375;; Parse shell path information and select among it.
5376(defun idlwave-user-catalog-command-hook (&optional arg)
5377 ;; Command hook used by `idlwave-create-user-catalog-file'.
f32b3b91
CD
5378 (if arg
5379 ;; Scan immediately
52a244eb
S
5380 (idlwave-scan-user-lib-files idlwave-path-alist)
5381 ;; Set the path and display the widget
5382 (idlwave-shell-get-path-info 'no-write) ; set to something path-alist
5383 (idlwave-scan-library-catalogs "Locating library catalogs..." 'no-load)
5384 (idlwave-display-user-catalog-widget idlwave-path-alist)))
5385
f66f03de 5386(defconst idlwave-user-catalog-widget-help-string
52a244eb
S
5387 "This is the front-end to the creation of the IDLWAVE user catalog.
5388Please select the directories on IDL's search path from which you
5389would like to extract routine information, to be stored in the file:
f32b3b91
CD
5390
5391 %s
5392
52a244eb
S
5393If this is not the correct file, first set variable
5394`idlwave-user-catalog-file', and call this command again.
15e42531 5395
52a244eb
S
5396N.B. Many libraries include pre-scanned catalog files
5397\(\".idlwave_catalog\"). These are marked with \"[LIB]\", and need
5398not be scanned. You can scan your own libraries off-line using the
5399perl script `idlwave_catalog'.
15e42531 5400
f32b3b91
CD
5401After selecting the directories, choose [Scan & Save] to scan the library
5402directories and save the routine info.
5403\n")
5404
5405(defvar idlwave-widget)
5406(defvar widget-keymap)
52a244eb 5407(defun idlwave-display-user-catalog-widget (dirs-list)
f32b3b91
CD
5408 "Create the widget to select IDL search path directories for scanning."
5409 (interactive)
5410 (require 'widget)
5411 (require 'wid-edit)
52a244eb 5412 (unless dirs-list
f32b3b91
CD
5413 (error "Don't know IDL's search path"))
5414
f32b3b91
CD
5415 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
5416 (switch-to-buffer (get-buffer-create "*IDLWAVE Widget*"))
5417 (kill-all-local-variables)
5418 (make-local-variable 'idlwave-widget)
52a244eb
S
5419 (widget-insert (format idlwave-user-catalog-widget-help-string
5420 idlwave-user-catalog-file))
f66f03de 5421
f32b3b91 5422 (widget-create 'push-button
52a244eb 5423 :notify 'idlwave-widget-scan-user-lib-files
f32b3b91
CD
5424 "Scan & Save")
5425 (widget-insert " ")
5426 (widget-create 'push-button
52a244eb 5427 :notify 'idlwave-delete-user-catalog-file
f32b3b91
CD
5428 "Delete File")
5429 (widget-insert " ")
5430 (widget-create 'push-button
f66f03de 5431 :notify
52a244eb
S
5432 '(lambda (&rest ignore)
5433 (let ((path-list (widget-get idlwave-widget :path-dirs)))
5434 (mapcar (lambda (x)
5435 (unless (memq 'lib (cdr x))
5436 (idlwave-path-alist-add-flag x 'user)))
5437 path-list)
5438 (idlwave-display-user-catalog-widget path-list)))
5439 "Select All Non-Lib")
f32b3b91
CD
5440 (widget-insert " ")
5441 (widget-create 'push-button
f66f03de 5442 :notify
52a244eb
S
5443 '(lambda (&rest ignore)
5444 (let ((path-list (widget-get idlwave-widget :path-dirs)))
5445 (mapcar (lambda (x)
5446 (idlwave-path-alist-remove-flag x 'user))
5447 path-list)
5448 (idlwave-display-user-catalog-widget path-list)))
f32b3b91 5449 "Deselect All")
52a244eb
S
5450 (widget-insert " ")
5451 (widget-create 'push-button
5452 :notify (lambda (&rest ignore)
5453 (kill-buffer (current-buffer)))
5454 "Quit")
f32b3b91
CD
5455 (widget-insert "\n\n")
5456
52a244eb 5457 (widget-insert "Select Directories: \n")
f66f03de 5458
f32b3b91
CD
5459 (setq idlwave-widget
5460 (apply 'widget-create
5461 'checklist
f66f03de
S
5462 :value (delq nil (mapcar (lambda (x)
5463 (if (memq 'user (cdr x))
52a244eb
S
5464 (car x)))
5465 dirs-list))
f32b3b91
CD
5466 :greedy t
5467 :tag "List of directories"
f66f03de
S
5468 (mapcar (lambda (x)
5469 (list 'item
52a244eb
S
5470 (if (memq 'lib (cdr x))
5471 (concat "[LIB] " (car x) )
5472 (car x)))) dirs-list)))
5473 (widget-put idlwave-widget :path-dirs dirs-list)
f32b3b91
CD
5474 (widget-insert "\n")
5475 (use-local-map widget-keymap)
5476 (widget-setup)
5477 (goto-char (point-min))
5478 (delete-other-windows))
f66f03de 5479
52a244eb 5480(defun idlwave-delete-user-catalog-file (&rest ignore)
f32b3b91 5481 (if (yes-or-no-p
52a244eb 5482 (format "Delete file %s " idlwave-user-catalog-file))
f32b3b91 5483 (progn
52a244eb
S
5484 (delete-file idlwave-user-catalog-file)
5485 (message "%s has been deleted" idlwave-user-catalog-file))))
f32b3b91 5486
52a244eb
S
5487(defun idlwave-widget-scan-user-lib-files (&rest ignore)
5488 ;; Call `idlwave-scan-user-lib-files' with data taken from the widget.
f32b3b91 5489 (let* ((widget idlwave-widget)
15e42531 5490 (selected-dirs (widget-value widget))
52a244eb
S
5491 (path-alist (widget-get widget :path-dirs))
5492 (this-path-alist path-alist)
5493 dir-entry)
5494 (while (setq dir-entry (pop this-path-alist))
f66f03de 5495 (if (member
52a244eb
S
5496 (if (memq 'lib (cdr dir-entry))
5497 (concat "[LIB] " (car dir-entry))
5498 (car dir-entry))
5499 selected-dirs)
5500 (idlwave-path-alist-add-flag dir-entry 'user)
5501 (idlwave-path-alist-remove-flag dir-entry 'user)))
5502 (idlwave-scan-user-lib-files path-alist)))
f32b3b91
CD
5503
5504(defvar font-lock-mode)
52a244eb
S
5505(defun idlwave-scan-user-lib-files (path-alist)
5506 ;; Scan the PRO files in PATH-ALIST and store the info in the user catalog
f32b3b91 5507 (let* ((idlwave-scanning-lib t)
15e42531 5508 (idlwave-scanning-lib-dir "")
f32b3b91 5509 (idlwave-completion-case nil)
15e42531 5510 dirs-alist dir files file)
52a244eb
S
5511 (setq idlwave-user-catalog-routines nil
5512 idlwave-path-alist path-alist ; for library-path instead
5513 idlwave-true-path-alist nil)
5514 (if idlwave-auto-write-paths (idlwave-write-paths))
f32b3b91
CD
5515 (save-excursion
5516 (set-buffer (get-buffer-create "*idlwave-scan.pro*"))
5517 (idlwave-mode)
15e42531
CD
5518 (setq dirs-alist (reverse path-alist))
5519 (while (setq dir (pop dirs-alist))
52a244eb 5520 (when (memq 'user (cdr dir)) ; Has it marked for scan?
15e42531 5521 (setq dir (car dir))
52a244eb 5522 (setq idlwave-scanning-lib-dir dir)
15e42531
CD
5523 (when (file-directory-p dir)
5524 (setq files (directory-files dir 'full "\\.[pP][rR][oO]\\'"))
5525 (while (setq file (pop files))
5526 (when (file-regular-p file)
5527 (if (not (file-readable-p file))
5528 (message "Skipping %s (no read permission)" file)
5529 (message "Scanning %s..." file)
5530 (erase-buffer)
5531 (insert-file-contents file 'visit)
52a244eb 5532 (setq idlwave-user-catalog-routines
15e42531
CD
5533 (append (idlwave-get-routine-info-from-buffers
5534 (list (current-buffer)))
52a244eb
S
5535 idlwave-user-catalog-routines)))))))))
5536 (message "Creating user catalog file...")
f32b3b91
CD
5537 (kill-buffer "*idlwave-scan.pro*")
5538 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
15e42531
CD
5539 (let ((font-lock-maximum-size 0)
5540 (auto-mode-alist nil))
52a244eb 5541 (find-file idlwave-user-catalog-file))
f32b3b91
CD
5542 (if (and (boundp 'font-lock-mode)
5543 font-lock-mode)
5544 (font-lock-mode 0))
5545 (erase-buffer)
52a244eb 5546 (insert ";; IDLWAVE user catalog file\n")
f32b3b91
CD
5547 (insert (format ";; Created %s\n\n" (current-time-string)))
5548
f32b3b91 5549 ;; Define the routine info list
52a244eb 5550 (insert "\n(setq idlwave-user-catalog-routines\n '(")
5e72c6b2
S
5551 (let ((standard-output (current-buffer)))
5552 (mapcar (lambda (x)
5553 (insert "\n ")
5554 (prin1 x)
5555 (goto-char (point-max)))
52a244eb 5556 idlwave-user-catalog-routines))
f32b3b91 5557 (insert (format "))\n\n;;; %s ends here\n"
52a244eb 5558 (file-name-nondirectory idlwave-user-catalog-file)))
f32b3b91
CD
5559 (goto-char (point-min))
5560 ;; Save the buffer
5561 (save-buffer 0)
5562 (kill-buffer (current-buffer)))
52a244eb 5563 (message "Creating user catalog file...done")
f32b3b91 5564 (message "Info for %d routines saved in %s"
52a244eb
S
5565 (length idlwave-user-catalog-routines)
5566 idlwave-user-catalog-file)
f32b3b91
CD
5567 (sit-for 2)
5568 (idlwave-update-routine-info t))
5569
52a244eb
S
5570(defun idlwave-read-paths ()
5571 (if (and (stringp idlwave-path-file)
5572 (file-regular-p idlwave-path-file))
5573 (condition-case nil
5574 (load idlwave-path-file t t t)
5575 (error nil))))
5576
5577(defun idlwave-write-paths ()
5578 (interactive)
5579 (when (and idlwave-path-alist idlwave-system-directory)
5580 (let ((font-lock-maximum-size 0)
5581 (auto-mode-alist nil))
5582 (find-file idlwave-path-file))
5583 (if (and (boundp 'font-lock-mode)
5584 font-lock-mode)
5585 (font-lock-mode 0))
5586 (erase-buffer)
5587 (insert ";; IDLWAVE paths\n")
5588 (insert (format ";; Created %s\n\n" (current-time-string)))
5589 ;; Define the variable which knows the value of "!DIR"
5590 (insert (format "\n(setq idlwave-system-directory \"%s\")\n"
5591 idlwave-system-directory))
f66f03de 5592
52a244eb
S
5593 ;; Define the variable which contains a list of all scanned directories
5594 (insert "\n(setq idlwave-path-alist\n '(")
5595 (let ((standard-output (current-buffer)))
5596 (mapcar (lambda (x)
5597 (insert "\n ")
5598 (prin1 x)
5599 (goto-char (point-max)))
5600 idlwave-path-alist))
5601 (insert "))\n")
5602 (save-buffer 0)
5603 (kill-buffer (current-buffer))))
5604
5605
f32b3b91
CD
5606(defun idlwave-expand-path (path &optional default-dir)
5607 ;; Expand parts of path starting with '+' recursively into directory list.
5608 ;; Relative recursive path elements are expanded relative to DEFAULT-DIR.
5609 (message "Expanding path...")
5610 (let (path1 dir recursive)
5611 (while (setq dir (pop path))
5612 (if (setq recursive (string= (substring dir 0 1) "+"))
5613 (setq dir (substring dir 1)))
5614 (if (and recursive
5615 (not (file-name-absolute-p dir)))
5616 (setq dir (expand-file-name dir default-dir)))
5617 (if recursive
5618 ;; Expand recursively
5619 (setq path1 (append (idlwave-recursive-directory-list dir) path1))
5620 ;; Keep unchanged
5621 (push dir path1)))
5622 (message "Expanding path...done")
5623 (nreverse path1)))
5624
5625(defun idlwave-recursive-directory-list (dir)
5626 ;; Return a list of all directories below DIR, including DIR itself
5627 (let ((path (list dir)) path1 file files)
5628 (while (setq dir (pop path))
5629 (when (file-directory-p dir)
5630 (setq files (nreverse (directory-files dir t "[^.]")))
5631 (while (setq file (pop files))
f66f03de 5632 (if (file-directory-p file)
f32b3b91
CD
5633 (push (file-name-as-directory file) path)))
5634 (push dir path1)))
5635 path1))
5636
52a244eb
S
5637
5638;;----- Scanning the library catalogs ------------------
5639
3938cb82
S
5640
5641
5642
52a244eb 5643(defun idlwave-scan-library-catalogs (&optional message-base no-load)
f66f03de 5644 "Scan for library catalog files (.idlwave_catalog) and ingest.
52a244eb
S
5645
5646All directories on `idlwave-path-alist' (or `idlwave-library-path'
5647instead, if present) are searched. Print MESSAGE-BASE along with the
5648libraries being loaded, if passed, and skip loading/normalizing if
5649NO-LOAD is non-nil. The variable `idlwave-use-library-catalogs' can
5650be set to nil to disable library catalog scanning."
5651 (when idlwave-use-library-catalogs
f66f03de 5652 (let ((dirs
52a244eb
S
5653 (if idlwave-library-path
5654 (idlwave-expand-path idlwave-library-path)
5655 (mapcar 'car idlwave-path-alist)))
5656 (old-libname "")
5657 dir-entry dir flags catalog all-routines)
5658 (if message-base (message message-base))
5659 (while (setq dir (pop dirs))
5660 (catch 'continue
f66f03de 5661 (when (file-readable-p
52a244eb
S
5662 (setq catalog (expand-file-name ".idlwave_catalog" dir)))
5663 (unless no-load
5664 (setq idlwave-library-catalog-routines nil)
5665 ;; Load the catalog file
5666 (condition-case nil
5667 (load catalog t t t)
5668 (error (throw 'continue t)))
f66f03de
S
5669 (when (and
5670 message-base
5671 (not (string= idlwave-library-catalog-libname
52a244eb 5672 old-libname)))
f66f03de
S
5673 (message "%s" (concat message-base
5674 idlwave-library-catalog-libname))
52a244eb
S
5675 (setq old-libname idlwave-library-catalog-libname))
5676 (when idlwave-library-catalog-routines
5677 (setq all-routines
f66f03de 5678 (append
52a244eb
S
5679 (idlwave-sintern-rinfo-list
5680 idlwave-library-catalog-routines 'sys dir)
5681 all-routines))))
f66f03de 5682
52a244eb
S
5683 ;; Add a 'lib flag if on path-alist
5684 (when (and idlwave-path-alist
5685 (setq dir-entry (assoc dir idlwave-path-alist)))
5686 (idlwave-path-alist-add-flag dir-entry 'lib)))))
5687 (unless no-load (setq idlwave-library-catalog-routines all-routines))
5688 (if message-base (message (concat message-base "done"))))))
5689
5690;;----- Communicating with the Shell -------------------
f32b3b91
CD
5691
5692;; First, here is the idl program which can be used to query IDL for
f66f03de 5693;; defined routines.
f32b3b91
CD
5694(defconst idlwave-routine-info.pro
5695 "
05a1abfc 5696;; START OF IDLWAVE SUPPORT ROUTINES
f66f03de
S
5697pro idlwave_print_safe,item,limit
5698 catch,err
5699 if err ne 0 then begin
5700 print,'Could not print item.'
5701 return
5702 endif
5703 if n_elements(item) gt limit then $
5704 print,item[0:limit-1],'<... truncated at ',strtrim(limit,2),' elements>' $
5705 else print,item
5706end
5707
15e42531 5708pro idlwave_print_info_entry,name,func=func,separator=sep
f32b3b91 5709 ;; See if it's an object method
15e42531 5710 if name eq '' then return
f66f03de 5711 func = keyword_set(func)
f32b3b91
CD
5712 methsep = strpos(name,'::')
5713 meth = methsep ne -1
f66f03de 5714
f32b3b91
CD
5715 ;; Get routine info
5716 pars = routine_info(name,/parameters,functions=func)
5717 source = routine_info(name,/source,functions=func)
5718 nargs = pars.num_args
5719 nkw = pars.num_kw_args
5720 if nargs gt 0 then args = pars.args
5721 if nkw gt 0 then kwargs = pars.kw_args
f66f03de 5722
f32b3b91 5723 ;; Trim the class, and make the name
f66f03de 5724 if meth then begin
f32b3b91
CD
5725 class = strmid(name,0,methsep)
5726 name = strmid(name,methsep+2,strlen(name)-1)
f66f03de 5727 if nargs gt 0 then begin
f32b3b91
CD
5728 ;; remove the self argument
5729 wh = where(args ne 'SELF',nargs)
52a244eb 5730 if nargs gt 0 then args = args[wh]
f32b3b91
CD
5731 endif
5732 endif else begin
5733 ;; No class, just a normal routine.
5734 class = \"\"
5735 endelse
f66f03de 5736
f32b3b91
CD
5737 ;; Calling sequence
5738 cs = \"\"
5739 if func then cs = 'Result = '
5740 if meth then cs = cs + 'Obj -> [' + '%s' + '::]'
5741 cs = cs + '%s'
5742 if func then cs = cs + '(' else if nargs gt 0 then cs = cs + ', '
5743 if nargs gt 0 then begin
5744 for j=0,nargs-1 do begin
52a244eb 5745 cs = cs + args[j]
f32b3b91
CD
5746 if j lt nargs-1 then cs = cs + ', '
5747 endfor
5748 end
5749 if func then cs = cs + ')'
5750 ;; Keyword arguments
5751 kwstring = ''
5752 if nkw gt 0 then begin
5753 for j=0,nkw-1 do begin
52a244eb 5754 kwstring = kwstring + ' ' + kwargs[j]
f32b3b91
CD
5755 endfor
5756 endif
f66f03de 5757
52a244eb 5758 ret=(['IDLWAVE-PRO','IDLWAVE-FUN'])[func]
f66f03de 5759
52a244eb 5760 print,ret + ': ' + name + sep + class + sep + source[0].path $
f32b3b91
CD
5761 + sep + cs + sep + kwstring
5762end
5763
f66f03de 5764pro idlwave_routine_info,file
52a244eb 5765 on_error,1
f32b3b91
CD
5766 sep = '<@>'
5767 print,'>>>BEGIN OF IDLWAVE ROUTINE INFO (\"' + sep + '\" IS THE SEPARATOR)'
5768 all = routine_info()
f66f03de
S
5769 fileQ=n_elements(file) ne 0
5770 if fileQ then file=strtrim(file,2)
5771 for i=0L,n_elements(all)-1L do begin
5772 if fileQ then begin
5773 if (routine_info(all[i],/SOURCE)).path eq file then $
5774 idlwave_print_info_entry,all[i],separator=sep
5775 endif else idlwave_print_info_entry,all[i],separator=sep
5776 endfor
f32b3b91 5777 all = routine_info(/functions)
f66f03de
S
5778 for i=0L,n_elements(all)-1L do begin
5779 if fileQ then begin
5780 if (routine_info(all[i],/FUNCTIONS,/SOURCE)).path eq file then $
5781 idlwave_print_info_entry,all[i],separator=sep,/FUNC
5782 endif else idlwave_print_info_entry,all[i],separator=sep,/FUNC
5783 endfor
f32b3b91
CD
5784 print,'>>>END OF IDLWAVE ROUTINE INFO'
5785end
05a1abfc
CD
5786
5787pro idlwave_get_sysvars
52a244eb 5788 on_error,1
05a1abfc
CD
5789 catch,error_status
5790 if error_status ne 0 then begin
5791 print, 'Cannot get info about system variables'
5792 endif else begin
5793 help,/brief,output=s,/system_variables ; ? unsafe use of OUTPUT=
5794 s = strtrim(strjoin(s,' ',/single),2) ; make one line
5795 v = strsplit(s,' +',/regex,/extract) ; get variables
f66f03de 5796 for i=0L,n_elements(v)-1 do begin
05a1abfc
CD
5797 t = [''] ; get tag list
5798 a=execute('if n_tags('+v[i]+') gt 0 then t=tag_names('+v[i]+')')
5799 print, 'IDLWAVE-SYSVAR: '+v[i]+' '+strjoin(t,' ',/single)
5800 endfor
5801 endelse
5802end
5803
5804pro idlwave_get_class_tags, class
5805 res = execute('tags=tag_names({'+class+'})')
5e72c6b2 5806 if res then print,'IDLWAVE-CLASS-TAGS: '+class+' '+strjoin(tags,' ',/single)
05a1abfc
CD
5807end
5808;; END OF IDLWAVE SUPPORT ROUTINES
f66f03de 5809"
05a1abfc 5810 "The idl programs to get info from the shell.")
f32b3b91 5811
15e42531
CD
5812(defvar idlwave-idlwave_routine_info-compiled nil
5813 "Remembers if the routine info procedure is already compiled.")
f32b3b91
CD
5814
5815(defvar idlwave-shell-temp-pro-file)
15e42531 5816(defvar idlwave-shell-temp-rinfo-save-file)
f66f03de
S
5817
5818(defun idlwave-shell-compile-helper-routines (&optional wait)
15e42531 5819 (unless (and idlwave-idlwave_routine_info-compiled
5e72c6b2 5820 (file-readable-p (idlwave-shell-temp-file 'rinfo)))
15e42531
CD
5821 (save-excursion
5822 (set-buffer (idlwave-find-file-noselect
5e72c6b2 5823 (idlwave-shell-temp-file 'pro)))
15e42531
CD
5824 (erase-buffer)
5825 (insert idlwave-routine-info.pro)
5826 (save-buffer 0))
f66f03de
S
5827 (idlwave-shell-send-command
5828 (concat ".run \"" idlwave-shell-temp-pro-file "\"")
52a244eb 5829 nil 'hide wait)
15e42531 5830 (idlwave-shell-send-command
f66f03de 5831 (format "save,'idlwave_print_safe','idlwave_routine_info','idlwave_print_info_entry','idlwave_get_class_tags','idlwave_get_sysvars',FILE='%s',/ROUTINES"
5e72c6b2 5832 (idlwave-shell-temp-file 'rinfo))
f66f03de
S
5833 nil 'hide)
5834 (setq idlwave-idlwave_routine_info-compiled t))
15e42531 5835
f66f03de
S
5836 ;; Restore if necessary. Must use execute to hide lame routine_info
5837 ;; errors on undefinded routine
15e42531 5838 (idlwave-shell-send-command
f66f03de
S
5839 (format "if execute(\"_v=routine_info('idlwave_routine_info',/SOURCE)\") eq 0 then restore,'%s' else if _v.path eq '' then restore,'%s'"
5840 idlwave-shell-temp-rinfo-save-file
15e42531 5841 idlwave-shell-temp-rinfo-save-file)
f66f03de
S
5842 nil 'hide))
5843
5844
5845(defun idlwave-shell-update-routine-info (&optional quiet run-hooks wait file)
5846 "Query the shell for routine_info of compiled modules and update the lists."
5847 ;; Save and compile the procedure. The compiled procedure is then
5848 ;; saved into an IDL SAVE file, to allow for fast RESTORE. We may
5849 ;; need to test for and possibly RESTORE the procedure each time we
5850 ;; use it, since the user may have killed or redefined it. In
5851 ;; particular, .RESET_SESSION will kill all user procedures. If
5852 ;; FILE is set, only update routine info for routines in that file.
5853
5854 (idlwave-shell-compile-helper-routines wait)
5855 ; execute the routine_info procedure, and analyze the output
5856 (idlwave-shell-send-command
5857 (format "idlwave_routine_info%s" (if file (concat ",'" file "'") ""))
15e42531
CD
5858 `(progn
5859 (idlwave-shell-routine-info-filter)
05a1abfc 5860 (idlwave-concatenate-rinfo-lists ,quiet ,run-hooks))
52a244eb 5861 'hide wait))
f32b3b91
CD
5862
5863;; ---------------------------------------------------------------------------
5864;;
5865;; Completion and displaying routine calling sequences
5866
15e42531 5867(defvar idlwave-completion-help-info nil)
52a244eb 5868(defvar idlwave-completion-help-links nil)
15e42531 5869(defvar idlwave-current-obj_new-class nil)
05a1abfc 5870(defvar idlwave-complete-special nil)
15e42531 5871
f32b3b91
CD
5872(defun idlwave-complete (&optional arg module class)
5873 "Complete a function, procedure or keyword name at point.
2e8b9c7d 5874This function is smart and figures out what can be completed
f32b3b91
CD
5875at this point.
5876- At the beginning of a statement it completes procedure names.
5877- In the middle of a statement it completes function names.
5878- after a `(' or `,' in the argument list of a function or procedure,
5879 it completes a keyword of the relevant function or procedure.
5880- In the first arg of `OBJ_NEW', it completes a class name.
5881
5e72c6b2 5882When several completions are possible, a list will be displayed in the
f32b3b91 5883*Completions* buffer. If this list is too long to fit into the
5e72c6b2
S
5884window, scrolling can be achieved by repeatedly pressing
5885\\[idlwave-complete].
f32b3b91
CD
5886
5887The function also knows about object methods. When it needs a class
5888name, the action depends upon `idlwave-query-class', which see. You
5e72c6b2
S
5889can force IDLWAVE to ask you for a class name with a
5890\\[universal-argument] prefix argument to this command.
f32b3b91
CD
5891
5892See also the variables `idlwave-keyword-completion-adds-equal' and
5893`idlwave-function-completion-adds-paren'.
5894
5895The optional ARG can be used to specify the completion type in order
5896to override IDLWAVE's idea of what should be completed at point.
5897Possible values are:
5898
58990 <=> query for the completion type
59001 <=> 'procedure
59012 <=> 'procedure-keyword
59023 <=> 'function
59034 <=> 'function-keyword
59045 <=> 'procedure-method
59056 <=> 'procedure-method-keyword
59067 <=> 'function-method
59078 <=> 'function-method-keyword
59089 <=> 'class
5909
5e72c6b2
S
5910As a special case, the universal argument C-u forces completion of
5911function names in places where the default would be a keyword.
5912
52a244eb
S
5913Two prefix argument, C-u C-u, prompts for a regexp by which to limit
5914completion.
5915
f32b3b91
CD
5916For Lisp programmers only:
5917When we force a keyword, optional argument MODULE can contain the module name.
5918When we force a method or a method keyword, CLASS can specify the class."
5919 (interactive "P")
5920 (idlwave-routines)
5921 (let* ((where-list
5922 (if (and arg
52a244eb 5923 (or (and (integerp arg) (not (equal arg '(16))))
f32b3b91
CD
5924 (symbolp arg)))
5925 (idlwave-make-force-complete-where-list arg module class)
5926 (idlwave-where)))
5927 (what (nth 2 where-list))
52a244eb
S
5928 (idlwave-force-class-query (equal arg '(4)))
5929 (completion-regexp-list
5930 (if (equal arg '(16))
5931 (list (read-string (concat "Completion Regexp: "))))))
f66f03de 5932
f32b3b91
CD
5933 (if (and module (string-match "::" module))
5934 (setq class (substring module 0 (match-beginning 0))
5935 module (substring module (match-end 0))))
5936
5937 (cond
5938
5939 ((and (null arg)
5940 (eq (car-safe last-command) 'idlwave-display-completion-list)
595ab50b 5941 (get-buffer-window "*Completions*"))
f32b3b91
CD
5942 (setq this-command last-command)
5943 (idlwave-scroll-completions))
5944
52a244eb 5945 ;; Complete a filename in quotes
05a1abfc
CD
5946 ((and (idlwave-in-quote)
5947 (not (eq what 'class)))
5948 (idlwave-complete-filename))
5949
52a244eb
S
5950 ;; Check for any special completion functions
5951 ((and idlwave-complete-special
5952 (idlwave-call-special idlwave-complete-special)))
f66f03de 5953
f32b3b91
CD
5954 ((null what)
5955 (error "Nothing to complete here"))
5956
52a244eb 5957 ;; Complete a class
f32b3b91 5958 ((eq what 'class)
15e42531 5959 (setq idlwave-completion-help-info '(class))
f32b3b91
CD
5960 (idlwave-complete-class))
5961
5962 ((eq what 'procedure)
5963 ;; Complete a procedure name
5e72c6b2
S
5964 (let* ((cw-list (nth 3 where-list))
5965 (class-selector (idlwave-determine-class cw-list 'pro))
5966 (super-classes (unless (idlwave-explicit-class-listed cw-list)
5967 (idlwave-all-class-inherits class-selector)))
f32b3b91
CD
5968 (isa (concat "procedure" (if class-selector "-method" "")))
5969 (type-selector 'pro))
f66f03de 5970 (setq idlwave-completion-help-info
05a1abfc 5971 (list 'routine nil type-selector class-selector nil super-classes))
f32b3b91
CD
5972 (idlwave-complete-in-buffer
5973 'procedure (if class-selector 'method 'routine)
5974 (idlwave-routines) 'idlwave-selector
5975 (format "Select a %s name%s"
5976 isa
5977 (if class-selector
f66f03de
S
5978 (format " (class is %s)"
5979 (if (eq class-selector t)
76959b77 5980 "unknown" class-selector))
f32b3b91
CD
5981 ""))
5982 isa
52a244eb 5983 'idlwave-attach-method-classes 'idlwave-add-file-link-selector)))
f32b3b91
CD
5984
5985 ((eq what 'function)
5986 ;; Complete a function name
5e72c6b2
S
5987 (let* ((cw-list (nth 3 where-list))
5988 (class-selector (idlwave-determine-class cw-list 'fun))
5989 (super-classes (unless (idlwave-explicit-class-listed cw-list)
5990 (idlwave-all-class-inherits class-selector)))
f32b3b91
CD
5991 (isa (concat "function" (if class-selector "-method" "")))
5992 (type-selector 'fun))
f66f03de 5993 (setq idlwave-completion-help-info
05a1abfc 5994 (list 'routine nil type-selector class-selector nil super-classes))
f32b3b91
CD
5995 (idlwave-complete-in-buffer
5996 'function (if class-selector 'method 'routine)
5997 (idlwave-routines) 'idlwave-selector
5998 (format "Select a %s name%s"
5999 isa
6000 (if class-selector
f66f03de 6001 (format " (class is %s)"
76959b77
S
6002 (if (eq class-selector t)
6003 "unknown" class-selector))
f32b3b91
CD
6004 ""))
6005 isa
52a244eb 6006 'idlwave-attach-method-classes 'idlwave-add-file-link-selector)))
f32b3b91 6007
52a244eb 6008 ((and (memq what '(procedure-keyword function-keyword)) ; Special Case
5e72c6b2
S
6009 (equal arg '(4)))
6010 (idlwave-complete 3))
6011
f32b3b91
CD
6012 ((eq what 'procedure-keyword)
6013 ;; Complete a procedure keyword
6014 (let* ((where (nth 3 where-list))
6015 (name (car where))
6016 (method-selector name)
6017 (type-selector 'pro)
6018 (class (idlwave-determine-class where 'pro))
6019 (class-selector class)
05a1abfc 6020 (super-classes (idlwave-all-class-inherits class-selector))
f32b3b91 6021 (isa (format "procedure%s-keyword" (if class "-method" "")))
15e42531 6022 (entry (idlwave-best-rinfo-assq
f32b3b91 6023 name 'pro class (idlwave-routines)))
3938cb82 6024 (system (if entry (eq (car (nth 3 entry)) 'system)))
52a244eb 6025 (list (idlwave-entry-keywords entry 'do-link)))
f32b3b91
CD
6026 (unless (or entry (eq class t))
6027 (error "Nothing known about procedure %s"
6028 (idlwave-make-full-name class name)))
f66f03de 6029 (setq list (idlwave-fix-keywords name 'pro class list
3938cb82 6030 super-classes system))
b6a97790 6031 (unless list (error "No keywords available for procedure %s"
3938cb82 6032 (idlwave-make-full-name class name)))
f66f03de 6033 (setq idlwave-completion-help-info
52a244eb 6034 (list 'keyword name type-selector class-selector entry super-classes))
f32b3b91
CD
6035 (idlwave-complete-in-buffer
6036 'keyword 'keyword list nil
6037 (format "Select keyword for procedure %s%s"
6038 (idlwave-make-full-name class name)
15e42531 6039 (if (or (member '("_EXTRA") list)
f66f03de 6040 (member '("_REF_EXTRA") list))
15e42531 6041 " (note _EXTRA)" ""))
f32b3b91
CD
6042 isa
6043 'idlwave-attach-keyword-classes)))
6044
6045 ((eq what 'function-keyword)
6046 ;; Complete a function keyword
6047 (let* ((where (nth 3 where-list))
6048 (name (car where))
6049 (method-selector name)
6050 (type-selector 'fun)
6051 (class (idlwave-determine-class where 'fun))
6052 (class-selector class)
05a1abfc 6053 (super-classes (idlwave-all-class-inherits class-selector))
f32b3b91 6054 (isa (format "function%s-keyword" (if class "-method" "")))
15e42531 6055 (entry (idlwave-best-rinfo-assq
f32b3b91 6056 name 'fun class (idlwave-routines)))
3938cb82 6057 (system (if entry (eq (car (nth 3 entry)) 'system)))
52a244eb 6058 (list (idlwave-entry-keywords entry 'do-link))
15e42531 6059 msg-name)
f32b3b91
CD
6060 (unless (or entry (eq class t))
6061 (error "Nothing known about function %s"
6062 (idlwave-make-full-name class name)))
f66f03de 6063 (setq list (idlwave-fix-keywords name 'fun class list
3938cb82 6064 super-classes system))
15e42531
CD
6065 ;; OBJ_NEW: Messages mention the proper Init method
6066 (setq msg-name (if (and (null class)
6067 (string= (upcase name) "OBJ_NEW"))
6068 (concat idlwave-current-obj_new-class
6069 "::Init (via OBJ_NEW)")
6070 (idlwave-make-full-name class name)))
b6a97790 6071 (unless list (error "No keywords available for function %s"
3938cb82 6072 msg-name))
f66f03de 6073 (setq idlwave-completion-help-info
05a1abfc 6074 (list 'keyword name type-selector class-selector nil super-classes))
f32b3b91
CD
6075 (idlwave-complete-in-buffer
6076 'keyword 'keyword list nil
15e42531
CD
6077 (format "Select keyword for function %s%s" msg-name
6078 (if (or (member '("_EXTRA") list)
f66f03de 6079 (member '("_REF_EXTRA") list))
15e42531 6080 " (note _EXTRA)" ""))
f32b3b91
CD
6081 isa
6082 'idlwave-attach-keyword-classes)))
15e42531 6083
f32b3b91
CD
6084 (t (error "This should not happen (idlwave-complete)")))))
6085
05a1abfc
CD
6086(defvar idlwave-complete-special nil
6087 "List of special completion functions.
52a244eb
S
6088These functions are called for each completion. Each function must
6089check if its own special completion context is present. If yes, it
6090should use `idlwave-complete-in-buffer' to do some completion and
6091return t. If such a function returns t, *no further* attempts to
6092complete other contexts will be done. If the function returns nil,
6093other completions will be tried.")
76959b77
S
6094
6095(defun idlwave-call-special (functions &rest args)
6096 (let ((funcs functions)
6097 fun ret)
05a1abfc 6098 (catch 'exit
76959b77
S
6099 (while (setq fun (pop funcs))
6100 (if (setq ret (apply fun args))
6101 (throw 'exit ret)))
05a1abfc
CD
6102 nil)))
6103
f32b3b91
CD
6104(defun idlwave-make-force-complete-where-list (what &optional module class)
6105 ;; Return an artificial WHERE specification to force the completion
6106 ;; routine to complete a specific item independent of context.
6107 ;; WHAT is the prefix arg of `idlwave-complete', see there for details.
6108 ;; MODULE and CLASS can be used to specify the routine name and class.
6109 ;; The class name will also be found in MODULE if that is like "class::mod".
6110 (let* ((what-list '(("procedure") ("procedure-keyword")
6111 ("function") ("function-keyword")
6112 ("procedure-method") ("procedure-method-keyword")
6113 ("function-method") ("function-method-keyword")
6114 ("class")))
6115 (module (idlwave-sintern-routine-or-method module class))
6116 (class (idlwave-sintern-class class))
f66f03de 6117 (what (cond
f32b3b91
CD
6118 ((equal what 0)
6119 (setq what
f66f03de 6120 (intern (completing-read
f32b3b91
CD
6121 "Complete what? " what-list nil t))))
6122 ((integerp what)
6123 (setq what (intern (car (nth (1- what) what-list)))))
6124 ((and what
6125 (symbolp what)
6126 (assoc (symbol-name what) what-list))
6127 what)
eac9c0ef 6128 (t (error "Invalid WHAT"))))
f32b3b91
CD
6129 (nil-list '(nil nil nil nil))
6130 (class-list (list nil nil (or class t) nil)))
6131
6132 (cond
6133
6134 ((eq what 'procedure)
6135 (list nil-list nil-list 'procedure nil-list nil))
6136
6137 ((eq what 'procedure-keyword)
6138 (let* ((class-selector nil)
05a1abfc 6139 (super-classes nil)
f32b3b91
CD
6140 (type-selector 'pro)
6141 (pro (or module
f66f03de 6142 (idlwave-completing-read
f32b3b91
CD
6143 "Procedure: " (idlwave-routines) 'idlwave-selector))))
6144 (setq pro (idlwave-sintern-routine pro))
6145 (list nil-list nil-list 'procedure-keyword
6146 (list pro nil nil nil) nil)))
6147
6148 ((eq what 'function)
6149 (list nil-list nil-list 'function nil-list nil))
6150
6151 ((eq what 'function-keyword)
6152 (let* ((class-selector nil)
05a1abfc 6153 (super-classes nil)
f32b3b91
CD
6154 (type-selector 'fun)
6155 (func (or module
f66f03de 6156 (idlwave-completing-read
f32b3b91
CD
6157 "Function: " (idlwave-routines) 'idlwave-selector))))
6158 (setq func (idlwave-sintern-routine func))
6159 (list nil-list nil-list 'function-keyword
6160 (list func nil nil nil) nil)))
6161
6162 ((eq what 'procedure-method)
6163 (list nil-list nil-list 'procedure class-list nil))
6164
6165 ((eq what 'procedure-method-keyword)
6166 (let* ((class (idlwave-determine-class class-list 'pro))
6167 (class-selector class)
05a1abfc 6168 (super-classes (idlwave-all-class-inherits class-selector))
f32b3b91
CD
6169 (type-selector 'pro)
6170 (pro (or module
6171 (idlwave-completing-read
6172 (format "Procedure in %s class: " class-selector)
6173 (idlwave-routines) 'idlwave-selector))))
6174 (setq pro (idlwave-sintern-method pro))
6175 (list nil-list nil-list 'procedure-keyword
6176 (list pro nil class nil) nil)))
6177
6178 ((eq what 'function-method)
6179 (list nil-list nil-list 'function class-list nil))
6180
6181 ((eq what 'function-method-keyword)
6182 (let* ((class (idlwave-determine-class class-list 'fun))
6183 (class-selector class)
05a1abfc 6184 (super-classes (idlwave-all-class-inherits class-selector))
f32b3b91
CD
6185 (type-selector 'fun)
6186 (func (or module
6187 (idlwave-completing-read
6188 (format "Function in %s class: " class-selector)
6189 (idlwave-routines) 'idlwave-selector))))
6190 (setq func (idlwave-sintern-method func))
6191 (list nil-list nil-list 'function-keyword
6192 (list func nil class nil) nil)))
6193
6194 ((eq what 'class)
6195 (list nil-list nil-list 'class nil-list nil))
f66f03de 6196
eac9c0ef 6197 (t (error "Invalid value for WHAT")))))
f32b3b91
CD
6198
6199(defun idlwave-completing-read (&rest args)
6200 ;; Completing read, case insensitive
6201 (let ((old-value (default-value 'completion-ignore-case)))
6202 (unwind-protect
6203 (progn
6204 (setq-default completion-ignore-case t)
6205 (apply 'completing-read args))
6206 (setq-default completion-ignore-case old-value))))
6207
05a1abfc
CD
6208(defvar idlwave-shell-default-directory)
6209(defun idlwave-complete-filename ()
6210 "Use the comint stuff to complete a file name."
6211 (require 'comint)
6212 (let* ((comint-file-name-chars "~/A-Za-z0-9+@:_.$#%={}\\-")
6213 (comint-completion-addsuffix nil)
6214 (default-directory
6215 (if (and (boundp 'idlwave-shell-default-directory)
6216 (stringp idlwave-shell-default-directory)
6217 (file-directory-p idlwave-shell-default-directory))
6218 idlwave-shell-default-directory
f66f03de 6219 default-directory)))
05a1abfc
CD
6220 (comint-dynamic-complete-filename)))
6221
f32b3b91
CD
6222(defun idlwave-make-full-name (class name)
6223 ;; Make a fully qualified module name including the class name
6224 (concat (if class (format "%s::" class) "") name))
6225
15e42531
CD
6226(defun idlwave-rinfo-assoc (name type class list)
6227 "Like `idlwave-rinfo-assq', but sintern strings first."
f66f03de 6228 (idlwave-rinfo-assq
15e42531
CD
6229 (idlwave-sintern-routine-or-method name class)
6230 type (idlwave-sintern-class class) list))
6231
f32b3b91
CD
6232(defun idlwave-rinfo-assq (name type class list)
6233 ;; Works like assq, but also checks type and class
6234 (catch 'exit
6235 (let (match)
6236 (while (setq match (assq name list))
6237 (and (or (eq type t)
6238 (eq (nth 1 match) type))
6239 (eq (nth 2 match) class)
6240 (throw 'exit match))
6241 (setq list (cdr (memq match list)))))))
6242
05a1abfc 6243(defun idlwave-rinfo-assq-any-class (name type class list)
52a244eb 6244 ;; Return the first matching method on the inheritance list
05a1abfc
CD
6245 (let* ((classes (cons class (idlwave-all-class-inherits class)))
6246 class rtn)
6247 (while classes
6248 (if (setq rtn (idlwave-rinfo-assq name type (pop classes) list))
6249 (setq classes nil)))
6250 rtn))
6251
f66f03de 6252(defun idlwave-best-rinfo-assq (name type class list &optional with-file
52a244eb
S
6253 keep-system)
6254 "Like `idlwave-rinfo-assq', but get all twins and sort, then return first.
6255If WITH-FILE is passed, find the best rinfo entry with a file
6256included. If KEEP-SYSTEM is set, don't prune system for compiled
6257syslib files."
15e42531 6258 (let ((twins (idlwave-routine-twins
05a1abfc 6259 (idlwave-rinfo-assq-any-class name type class list)
15e42531
CD
6260 list))
6261 syslibp)
6262 (when (> (length twins) 1)
6263 (setq twins (sort twins 'idlwave-routine-entry-compare-twins))
52a244eb
S
6264 (if (and (null keep-system)
6265 (eq 'system (car (nth 3 (car twins))))
15e42531
CD
6266 (setq syslibp (idlwave-any-syslib (cdr twins)))
6267 (not (equal 1 syslibp)))
52a244eb
S
6268 ;; Its a compiled syslib, so we need to remove the system entry
6269 (setq twins (cdr twins)))
6270 (if with-file
6271 (setq twins (delq nil
6272 (mapcar (lambda (x)
6273 (if (nth 1 (nth 3 x)) x))
6274 twins)))))
15e42531
CD
6275 (car twins)))
6276
f66f03de 6277(defun idlwave-best-rinfo-assoc (name type class list &optional with-file
52a244eb 6278 keep-system)
15e42531
CD
6279 "Like `idlwave-best-rinfo-assq', but sintern strings first."
6280 (idlwave-best-rinfo-assq
6281 (idlwave-sintern-routine-or-method name class)
52a244eb 6282 type (idlwave-sintern-class class) list with-file keep-system))
15e42531
CD
6283
6284(defun idlwave-any-syslib (entries)
6285 "Does the entry list ENTRIES contain a syslib entry?
6286If yes, return the index (>=1)."
6287 (let (file (cnt 0))
6288 (catch 'exit
6289 (while entries
6290 (incf cnt)
52a244eb
S
6291 (setq file (idlwave-routine-source-file (nth 3 (car entries))))
6292 (if (and file (idlwave-syslib-p file))
15e42531
CD
6293 (throw 'exit cnt)
6294 (setq entries (cdr entries))))
6295 nil)))
6296
f32b3b91
CD
6297(defun idlwave-all-assq (key list)
6298 "Return a list of all associations of Key in LIST."
6299 (let (rtn elt)
6300 (while (setq elt (assq key list))
6301 (push elt rtn)
6302 (setq list (cdr (memq elt list))))
6303 (nreverse rtn)))
6304
6305(defun idlwave-all-method-classes (method &optional type)
6306 "Return all classes which have a method METHOD. TYPE is 'fun or 'pro.
6307When TYPE is not specified, both procedures and functions will be considered."
6308 (if (null method)
15e42531 6309 (mapcar 'car (idlwave-class-alist))
f32b3b91
CD
6310 (let (rtn)
6311 (mapcar (lambda (x)
6312 (and (nth 2 x)
6313 (or (not type)
6314 (eq type (nth 1 x)))
6315 (push (nth 2 x) rtn)))
6316 (idlwave-all-assq method (idlwave-routines)))
6317 (idlwave-uniquify rtn))))
6318
6319(defun idlwave-all-method-keyword-classes (method keyword &optional type)
6320 "Return all classes which have a method METHOD with keyword KEYWORD.
6321TYPE is 'fun or 'pro.
6322When TYPE is not specified, both procedures and functions will be considered."
6323 (if (or (null method)
6324 (null keyword))
6325 nil
6326 (let (rtn)
6327 (mapcar (lambda (x)
52a244eb
S
6328 (and (nth 2 x) ; non-nil class
6329 (or (not type) ; correct or unspecified type
f32b3b91 6330 (eq type (nth 1 x)))
52a244eb 6331 (assoc keyword (idlwave-entry-keywords x))
f32b3b91
CD
6332 (push (nth 2 x) rtn)))
6333 (idlwave-all-assq method (idlwave-routines)))
6334 (idlwave-uniquify rtn))))
6335
05a1abfc
CD
6336(defun idlwave-members-only (list club)
6337 "Return list of all elements in LIST which are also in CLUB."
6338 (let (rtn)
6339 (while list
6340 (if (member (car list) club)
6341 (setq rtn (cons (car list) rtn)))
6342 (setq list (cdr list)))
6343 (nreverse rtn)))
6344
6345(defun idlwave-nonmembers-only (list club)
6346 "Return list of all elements in LIST which are not in CLUB."
6347 (let (rtn)
6348 (while list
6349 (if (member (car list) club)
6350 nil
6351 (setq rtn (cons (car list) rtn)))
6352 (setq list (cdr list)))
6353 (nreverse rtn)))
6354
5e72c6b2
S
6355(defun idlwave-explicit-class-listed (info)
6356 "Return whether or not the class is listed explicitly, ala a->b::c.
6357INFO is as returned by idlwave-what-function or -procedure."
6358 (let ((apos (nth 3 info)))
6359 (if apos
6360 (save-excursion (goto-char apos)
6361 (looking-at "->[a-zA-Z][a-zA-Z0-9$_]*::")))))
6362
76959b77
S
6363(defvar idlwave-determine-class-special nil
6364 "List of special functions for determining class.
6365Must accept two arguments: `apos' and `info'")
6366
f32b3b91 6367(defun idlwave-determine-class (info type)
f66f03de 6368 ;; Determine the class of a routine call.
76959b77
S
6369 ;; INFO is the `cw-list' structure as returned by idlwave-where.
6370 ;; The second element in this structure is the class. When nil, we
6371 ;; return nil. When t, try to get the class from text properties at
6372 ;; the arrow. When the object is "self", we use the class of the
6373 ;; current routine. otherwise prompt the user for a class name.
6374 ;; Also stores the selected class as a text property at the arrow.
f32b3b91
CD
6375 ;; TYPE is 'fun or 'pro.
6376 (let* ((class (nth 2 info))
6377 (apos (nth 3 info))
6378 (nassoc (assoc (if (stringp (car info))
6379 (upcase (car info))
6380 (car info))
6381 idlwave-query-class))
6382 (dassoc (assq (if (car info) 'keyword-default 'method-default)
6383 idlwave-query-class))
6384 (query (cond (nassoc (cdr nassoc))
6385 (dassoc (cdr dassoc))
6386 (t t)))
6387 (arrow (and apos (string= (buffer-substring apos (+ 2 apos)) "->")))
f66f03de 6388 (is-self
15e42531
CD
6389 (and arrow
6390 (save-excursion (goto-char apos)
6391 (forward-word -1)
6392 (let ((case-fold-search t))
6393 (looking-at "self\\>")))))
f32b3b91 6394 (force-query idlwave-force-class-query)
76959b77 6395 store special-class class-alist)
f32b3b91
CD
6396 (cond
6397 ((null class) nil)
6398 ((eq t class)
6399 ;; There is an object which would like to know its class
6400 (if (and arrow (get-text-property apos 'idlwave-class)
6401 idlwave-store-inquired-class
6402 (not force-query))
6403 (setq class (get-text-property apos 'idlwave-class)
6404 class (idlwave-sintern-class class)))
76959b77
S
6405 (if (and (eq t class) is-self)
6406 (setq class (or (nth 2 (idlwave-current-routine)) class)))
6407
6408 ;; Before prompting, try any special class determination routines
f66f03de 6409 (when (and (eq t class)
76959b77
S
6410 idlwave-determine-class-special
6411 (not force-query))
f66f03de 6412 (setq special-class
76959b77 6413 (idlwave-call-special idlwave-determine-class-special apos))
f66f03de 6414 (if special-class
76959b77
S
6415 (setq class (idlwave-sintern-class special-class)
6416 store idlwave-store-inquired-class)))
f66f03de 6417
76959b77 6418 ;; Prompt for a class, if we need to
f32b3b91
CD
6419 (when (and (eq class t)
6420 (or force-query query))
f66f03de 6421 (setq class-alist
f32b3b91
CD
6422 (mapcar 'list (idlwave-all-method-classes (car info) type)))
6423 (setq class
6424 (idlwave-sintern-class
6425 (cond
6426 ((and (= (length class-alist) 0) (not force-query))
6427 (error "No classes available with method %s" (car info)))
6428 ((and (= (length class-alist) 1) (not force-query))
6429 (car (car class-alist)))
f66f03de 6430 (t
f32b3b91 6431 (setq store idlwave-store-inquired-class)
f66f03de 6432 (idlwave-completing-read
f32b3b91
CD
6433 (format "Class%s: " (if (stringp (car info))
6434 (format " for %s method %s"
6435 type (car info))
6436 ""))
6437 class-alist nil nil nil 'idlwave-class-history))))))
76959b77
S
6438
6439 ;; Store it, if requested
f32b3b91
CD
6440 (when (and class (not (eq t class)))
6441 ;; We have a real class here
6442 (when (and store arrow)
76959b77 6443 (condition-case ()
f66f03de
S
6444 (add-text-properties
6445 apos (+ apos 2)
6446 `(idlwave-class ,class face ,idlwave-class-arrow-face
76959b77
S
6447 rear-nonsticky t))
6448 (error nil)))
f32b3b91
CD
6449 (setf (nth 2 info) class))
6450 ;; Return the class
6451 class)
6452 ;; Default as fallback
6453 (t class))))
6454
6455(defvar type-selector)
6456(defvar class-selector)
6457(defvar method-selector)
05a1abfc 6458(defvar super-classes)
f32b3b91
CD
6459(defun idlwave-selector (a)
6460 (and (eq (nth 1 a) type-selector)
6461 (or (and (nth 2 a) (eq class-selector t))
05a1abfc 6462 (eq (nth 2 a) class-selector)
52a244eb
S
6463 (memq (nth 2 a) super-classes))))
6464
6465(defun idlwave-add-file-link-selector (a)
6466 ;; Record a file link, if any, for the tested names during selection.
6467 (let ((sel (idlwave-selector a)) file)
6468 (if (and sel (setq file (idlwave-entry-has-help a)))
6469 (push (cons (car a) file) idlwave-completion-help-links))
6470 sel))
6471
f32b3b91
CD
6472
6473(defun idlwave-where ()
f66f03de 6474 "Find out where we are.
f32b3b91 6475The return value is a list with the following stuff:
5e72c6b2 6476\(PRO-LIST FUNC-LIST COMPLETE-WHAT CW-LIST LAST-CHAR)
f32b3b91
CD
6477
6478PRO-LIST (PRO POINT CLASS ARROW)
6479FUNC-LIST (FUNC POINT CLASS ARROW)
6480COMPLETE-WHAT a symbol indicating what kind of completion makes sense here
f66f03de 6481CW-LIST (PRO-OR-FUNC POINT CLASS ARROW) Like PRO-LIST, for what can
5e72c6b2 6482 be completed here.
f32b3b91
CD
6483LAST-CHAR last relevant character before point (non-white non-comment,
6484 not part of current identifier or leading slash).
6485
6486In the lists, we have these meanings:
6487PRO: Procedure name
6488FUNC: Function name
6489POINT: Where is this
6490CLASS: What class has the routine (nil=no, t=is method, but class unknown)
5e72c6b2 6491ARROW: Location of the arrow"
f32b3b91 6492 (idlwave-routines)
f66f03de 6493 (let* (;(bos (save-excursion (idlwave-beginning-of-statement) (point)))
15e42531 6494 (bos (save-excursion (idlwave-start-of-substatement 'pre) (point)))
f32b3b91
CD
6495 (func-entry (idlwave-what-function bos))
6496 (func (car func-entry))
6497 (func-class (nth 1 func-entry))
6498 (func-arrow (nth 2 func-entry))
6499 (func-point (or (nth 3 func-entry) 0))
6500 (func-level (or (nth 4 func-entry) 0))
6501 (pro-entry (idlwave-what-procedure bos))
6502 (pro (car pro-entry))
6503 (pro-class (nth 1 pro-entry))
6504 (pro-arrow (nth 2 pro-entry))
6505 (pro-point (or (nth 3 pro-entry) 0))
6506 (last-char (idlwave-last-valid-char))
6507 (case-fold-search t)
52a244eb 6508 (match-string (buffer-substring bos (point)))
f32b3b91
CD
6509 cw cw-mod cw-arrow cw-class cw-point)
6510 (if (< func-point pro-point) (setq func nil))
6511 (cond
15e42531 6512 ((string-match "\\`[ \t]*\\(pro\\|function\\)[ \t]+[a-zA-Z0-9_]*\\'"
52a244eb 6513 match-string)
15e42531 6514 (setq cw 'class))
f66f03de
S
6515 ((string-match
6516 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)?\\'"
52a244eb
S
6517 (if (> pro-point 0)
6518 (buffer-substring pro-point (point))
6519 match-string))
f32b3b91
CD
6520 (setq cw 'procedure cw-class pro-class cw-point pro-point
6521 cw-arrow pro-arrow))
6522 ((string-match "\\`[ \t]*\\(pro\\|function\\)\\>"
52a244eb 6523 match-string)
f32b3b91 6524 nil)
05a1abfc 6525 ((string-match "OBJ_NEW([ \t]*['\"]\\([a-zA-Z0-9$_]*\\)?\\'"
52a244eb 6526 match-string)
f66f03de 6527 (setq cw 'class))
05a1abfc 6528 ((string-match "\\<inherits\\s-+\\([a-zA-Z0-9$_]*\\)?\\'"
52a244eb 6529 match-string)
f66f03de
S
6530 (setq cw 'class))
6531 ((and func
f32b3b91
CD
6532 (> func-point pro-point)
6533 (= func-level 1)
6534 (memq last-char '(?\( ?,)))
6535 (setq cw 'function-keyword cw-mod func cw-point func-point
6536 cw-class func-class cw-arrow func-arrow))
6537 ((and pro (eq last-char ?,))
6538 (setq cw 'procedure-keyword cw-mod pro cw-point pro-point
6539 cw-class pro-class cw-arrow pro-arrow))
6540; ((member last-char '(?\' ?\) ?\] ?!))
6541; ;; after these chars, a function makes no sense
6542; ;; FIXME: I am sure there can be more in this list
6543; ;; FIXME: Do we want to do this at all?
6544; nil)
6545 ;; Everywhere else we try a function.
6546 (t
6547 (setq cw 'function)
6548 (save-excursion
52a244eb 6549 (if (re-search-backward "->[ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\s-*\\)?\\(\\([$a-zA-Z0-9_]+\\)::\\)?[$a-zA-Z0-9_]*\\=" bos t)
76959b77 6550 (setq cw-arrow (copy-marker (match-beginning 0))
52a244eb
S
6551 cw-class (if (match-end 4)
6552 (idlwave-sintern-class (match-string 4))
5e72c6b2 6553 t))))))
f32b3b91
CD
6554 (list (list pro pro-point pro-class pro-arrow)
6555 (list func func-point func-class func-arrow)
6556 cw
6557 (list cw-mod cw-point cw-class cw-arrow)
6558 last-char)))
6559
6560(defun idlwave-this-word (&optional class)
6561 ;; Grab the word around point. CLASS is for the `skip-chars=...' functions
52a244eb 6562 (setq class (or class "a-zA-Z0-9$_."))
f32b3b91 6563 (save-excursion
52a244eb 6564 (buffer-substring
f32b3b91
CD
6565 (progn (skip-chars-backward class) (point))
6566 (progn (skip-chars-forward class) (point)))))
6567
f32b3b91
CD
6568(defun idlwave-what-function (&optional bound)
6569 ;; Find out if point is within the argument list of a function.
76959b77
S
6570 ;; The return value is ("function-name" class arrow-start (point) level).
6571 ;; Level is 1 on the top level parentheses, higher further down.
f32b3b91
CD
6572
6573 ;; If the optional BOUND is an integer, bound backwards directed
6574 ;; searches to this point.
6575
6576 (catch 'exit
f66f03de 6577 (let (pos
f32b3b91 6578 func-point
f32b3b91
CD
6579 (cnt 0)
6580 func arrow-start class)
15e42531
CD
6581 (idlwave-with-special-syntax
6582 (save-restriction
6583 (save-excursion
6584 (narrow-to-region (max 1 (or bound 0)) (point-max))
6585 ;; move back out of the current parenthesis
6586 (while (condition-case nil
6587 (progn (up-list -1) t)
6588 (error nil))
6589 (setq pos (point))
6590 (incf cnt)
6591 (when (and (= (following-char) ?\()
f66f03de 6592 (re-search-backward
15e42531
CD
6593 "\\(::\\|\\<\\)\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\="
6594 bound t))
6595 (setq func (match-string 2)
6596 func-point (goto-char (match-beginning 2))
6597 pos func-point)
f66f03de 6598 (if (re-search-backward
15e42531 6599 "->[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\=" bound t)
76959b77 6600 (setq arrow-start (copy-marker (match-beginning 0))
15e42531 6601 class (or (match-string 2) t)))
f66f03de
S
6602 (throw
6603 'exit
15e42531
CD
6604 (list
6605 (idlwave-sintern-routine-or-method func class)
6606 (idlwave-sintern-class class)
6607 arrow-start func-point cnt)))
6608 (goto-char pos))
6609 (throw 'exit nil)))))))
f32b3b91
CD
6610
6611(defun idlwave-what-procedure (&optional bound)
6612 ;; Find out if point is within the argument list of a procedure.
6613 ;; The return value is ("procedure-name" class arrow-pos (point)).
6614
6615 ;; If the optional BOUND is an integer, bound backwards directed
6616 ;; searches to this point.
6617 (let ((pos (point)) pro-point
6618 pro class arrow-start string)
f66f03de 6619 (save-excursion
05a1abfc 6620 ;;(idlwave-beginning-of-statement)
15e42531 6621 (idlwave-start-of-substatement 'pre)
f32b3b91 6622 (setq string (buffer-substring (point) pos))
f66f03de 6623 (if (string-match
76959b77
S
6624 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\(,\\|\\'\\)" string)
6625 (setq pro (match-string 1 string)
6626 pro-point (+ (point) (match-beginning 1)))
f32b3b91
CD
6627 (if (and (idlwave-skip-object)
6628 (setq string (buffer-substring (point) pos))
f66f03de
S
6629 (string-match
6630 "\\`[ \t]*\\(->\\)[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\([a-zA-Z][a-zA-Z0-9$_]*\\)?[ \t]*\\(,\\|\\(\\$\\s *\\(;.*\\)?\\)?$\\)"
52a244eb 6631 string))
f32b3b91
CD
6632 (setq pro (if (match-beginning 4)
6633 (match-string 4 string))
6634 pro-point (if (match-beginning 4)
6635 (+ (point) (match-beginning 4))
6636 pos)
76959b77 6637 arrow-start (copy-marker (+ (point) (match-beginning 1)))
f32b3b91
CD
6638 class (or (match-string 3 string) t)))))
6639 (list (idlwave-sintern-routine-or-method pro class)
6640 (idlwave-sintern-class class)
6641 arrow-start
6642 pro-point)))
6643
6644(defun idlwave-skip-object ()
6645 ;; If there is an object at point, move over it and return t.
6646 (let ((pos (point)))
6647 (if (catch 'exit
6648 (save-excursion
6649 (skip-chars-forward " ") ; white space
6650 (skip-chars-forward "*") ; de-reference
6651 (cond
6652 ((looking-at idlwave-identifier)
6653 (goto-char (match-end 0)))
6654 ((eq (following-char) ?\()
6655 nil)
6656 (t (throw 'exit nil)))
6657 (catch 'endwhile
6658 (while t
6659 (cond ((eq (following-char) ?.)
6660 (forward-char 1)
6661 (if (not (looking-at idlwave-identifier))
6662 (throw 'exit nil))
6663 (goto-char (match-end 0)))
6664 ((memq (following-char) '(?\( ?\[))
6665 (condition-case nil
6666 (forward-list 1)
6667 (error (throw 'exit nil))))
6668 (t (throw 'endwhile t)))))
6669 (if (looking-at "[ \t]*->")
6670 (throw 'exit (setq pos (match-beginning 0)))
6671 (throw 'exit nil))))
6672 (goto-char pos)
6673 nil)))
f66f03de 6674
f32b3b91
CD
6675(defun idlwave-last-valid-char ()
6676 "Return the last character before point which is not white or a comment
6677and also not part of the current identifier. Since we do this in
6678order to identify places where keywords are, we consider the initial
6679`/' of a keyword as part of the identifier.
6680This function is not general, can only be used for completion stuff."
6681 (catch 'exit
6682 (save-excursion
6683 ;; skip the current identifier
6684 (skip-chars-backward "a-zA-Z0-9_$")
6685 ;; also skip a leading slash which might be belong to the keyword
6686 (if (eq (preceding-char) ?/)
6687 (backward-char 1))
6688 ;; FIXME: does not check if this is a valid identifier
6689 (while t
6690 (skip-chars-backward " \t")
6691 (cond
6692 ((memq (preceding-char) '(?\; ?\$)) (throw 'exit nil))
6693 ((eq (preceding-char) ?\n)
6694 (beginning-of-line 0)
3938cb82 6695 (if (looking-at "\\([^\n]*\\)\\$[ \t]*\\(;[^\n]*\\)?\n")
f32b3b91
CD
6696 ;; continuation line
6697 (goto-char (match-end 1))
6698 (throw 'exit nil)))
6699 (t (throw 'exit (preceding-char))))))))
6700
6701(defvar idlwave-complete-after-success-form nil
6702 "A form to evaluate after successful completion.")
6703(defvar idlwave-complete-after-success-form-force nil
6704 "A form to evaluate after completion selection in *Completions* buffer.")
6705(defconst idlwave-completion-mark (make-marker)
6706 "A mark pointing to the beginning of the completion string.")
6707
6708(defun idlwave-complete-in-buffer (type stype list selector prompt isa
52a244eb
S
6709 &optional prepare-display-function
6710 special-selector)
f32b3b91 6711 "Perform TYPE completion of word before point against LIST.
76959b77 6712SELECTOR is the PREDICATE argument for the completion function. Show
52a244eb
S
6713PROMPT in echo area. TYPE is one of the intern types, e.g. 'function,
6714'procedure, 'class-tag, 'keyword, 'sysvar, etc.. SPECIAL-SELECTOR is
6715used only once, for `all-completions', and can be used to, e.g.,
6716accumulate information on matching completions."
f32b3b91
CD
6717 (let* ((completion-ignore-case t)
6718 beg (end (point)) slash part spart completion all-completions
6719 dpart dcompletion)
6720
6721 (unless list
6722 (error (concat prompt ": No completions available")))
6723
6724 ;; What is already in the buffer?
6725 (save-excursion
6726 (skip-chars-backward "a-zA-Z0-9_$")
6727 (setq slash (eq (preceding-char) ?/)
6728 beg (point)
6729 idlwave-complete-after-success-form
6730 (list 'idlwave-after-successful-completion
6731 (list 'quote type) slash beg)
6732 idlwave-complete-after-success-form-force
6733 (list 'idlwave-after-successful-completion
6734 (list 'quote type) slash (list 'quote 'force))))
6735
6736 ;; Try a completion
6737 (setq part (buffer-substring beg end)
6738 dpart (downcase part)
6739 spart (idlwave-sintern stype part)
6740 completion (try-completion part list selector)
52a244eb
S
6741 dcompletion (if (stringp completion) (downcase completion))
6742 idlwave-completion-help-links nil)
f32b3b91
CD
6743 (cond
6744 ((null completion)
6745 ;; nothing available.
76959b77 6746 (error (concat prompt ": no completion for \"%s\"") part))
f32b3b91
CD
6747 ((and (not (equal dpart dcompletion))
6748 (not (eq t completion)))
6749 ;; We can add something
6750 (delete-region beg end)
6751 (if (and (string= part dpart)
6752 (or (not (string= part ""))
6753 idlwave-complete-empty-string-as-lower-case)
6754 (not idlwave-completion-force-default-case))
6755 (insert dcompletion)
6756 (insert completion))
6757 (if (eq t (try-completion completion list selector))
6758 ;; Now this is a unique match
6759 (idlwave-after-successful-completion type slash beg))
6760 t)
6761 ((or (eq completion t)
52a244eb 6762 (and (= 1 (length (setq all-completions
f32b3b91 6763 (idlwave-uniquify
f66f03de
S
6764 (all-completions part list
6765 (or special-selector
52a244eb
S
6766 selector))))))
6767 (equal dpart dcompletion)))
f32b3b91
CD
6768 ;; This is already complete
6769 (idlwave-after-successful-completion type slash beg)
6770 (message "%s is already the complete %s" part isa)
6771 nil)
f66f03de 6772 (t
f32b3b91
CD
6773 ;; We cannot add something - offer a list.
6774 (message "Making completion list...")
f66f03de 6775
52a244eb
S
6776 (unless idlwave-completion-help-links ; already set somewhere?
6777 (mapcar (lambda (x) ; Pass link prop through to highlight-linked
6778 (let ((link (get-text-property 0 'link (car x))))
6779 (if link
f66f03de 6780 (push (cons (car x) link)
52a244eb
S
6781 idlwave-completion-help-links))))
6782 list))
f32b3b91 6783 (let* ((list all-completions)
05a1abfc 6784 ;; "complete" means, this is already a valid completion
f32b3b91 6785 (complete (memq spart all-completions))
52a244eb
S
6786 (completion-highlight-first-word-only t)) ; XEmacs
6787; (completion-fixup-function ; Emacs
6788; (lambda () (and (eq (preceding-char) ?>)
6789; (re-search-backward " <" beg t)))))
f66f03de 6790
f32b3b91
CD
6791 (setq list (sort list (lambda (a b)
6792 (string< (downcase a) (downcase b)))))
6793 (if prepare-display-function
6794 (setq list (funcall prepare-display-function list)))
6795 (if (and (string= part dpart)
6796 (or (not (string= part ""))
6797 idlwave-complete-empty-string-as-lower-case)
6798 (not idlwave-completion-force-default-case))
6799 (setq list (mapcar (lambda (x)
f66f03de 6800 (if (listp x)
f32b3b91
CD
6801 (setcar x (downcase (car x)))
6802 (setq x (downcase x)))
6803 x)
6804 list)))
6805 (idlwave-display-completion-list list prompt beg complete))
6806 t))))
6807
6808(defun idlwave-complete-class ()
6809 "Complete a class at point."
6810 (interactive)
6811 ;; Call `idlwave-routines' to make sure the class list will be available
6812 (idlwave-routines)
15e42531
CD
6813 ;; Check for the special case of completing empty string after pro/function
6814 (if (let ((case-fold-search t))
6815 (save-excursion
6816 (and
6817 (re-search-backward "\\<\\(pro\\|function\\)[ \t]+\\="
6818 (- (point) 15) t)
6819 (goto-char (point-min))
f66f03de 6820 (re-search-forward
15e42531
CD
6821 "^[ \t]*\\(pro\\|function\\)[ \t]+\\([a-zA-Z0-9_]+::\\)" nil t))))
6822 ;; Yank the full class specification
6823 (insert (match-string 2))
52a244eb 6824 ;; Do the completion, using list gathered from `idlwave-routines'
f66f03de
S
6825 (idlwave-complete-in-buffer
6826 'class 'class (idlwave-class-alist) nil
52a244eb
S
6827 "Select a class" "class"
6828 '(lambda (list) ;; Push it to help-links if system help available
6829 (mapcar (lambda (x)
6830 (let* ((entry (idlwave-class-info x))
6831 (link (nth 1 (assq 'link entry))))
f66f03de 6832 (if link (push (cons x link)
52a244eb
S
6833 idlwave-completion-help-links))
6834 x))
6835 list)))))
f32b3b91 6836
76959b77 6837(defun idlwave-attach-classes (list type show-classes)
05a1abfc 6838 ;; Attach the proper class list to a LIST of completion items.
76959b77
S
6839 ;; TYPE, when 'kwd, shows classes for method keywords, when
6840 ;; 'class-tag, for class tags, and otherwise for methods.
f32b3b91 6841 ;; SHOW-CLASSES is the value of `idlwave-completion-show-classes'.
76959b77
S
6842 (if (or (null show-classes) ; don't want to see classes
6843 (null class-selector) ; not a method call
f66f03de 6844 (and
76959b77
S
6845 (stringp class-selector) ; the class is already known
6846 (not super-classes))) ; no possibilities for inheritance
6847 ;; In these cases, we do not have to do anything
6848 list
05a1abfc
CD
6849 (let* ((do-prop (and (>= show-classes 0)
6850 (>= emacs-major-version 21)))
f32b3b91 6851 (do-buf (not (= show-classes 0)))
76959b77 6852 ;; (do-dots (featurep 'xemacs))
05a1abfc 6853 (do-dots t)
76959b77 6854 (inherit (if (and (not (eq type 'class-tag)) super-classes)
05a1abfc 6855 (cons class-selector super-classes)))
f32b3b91
CD
6856 (max (abs show-classes))
6857 (lmax (if do-dots (apply 'max (mapcar 'length list))))
6858 classes nclasses class-info space)
f66f03de 6859 (mapcar
f32b3b91
CD
6860 (lambda (x)
6861 ;; get the classes
76959b77
S
6862 (if (eq type 'class-tag)
6863 ;; Just one class for tags
6864 (setq classes
f66f03de 6865 (list
76959b77 6866 (idlwave-class-or-superclass-with-tag class-selector x)))
52a244eb 6867 ;; Multiple classes for method or method-keyword
76959b77
S
6868 (setq classes
6869 (if (eq type 'kwd)
6870 (idlwave-all-method-keyword-classes
6871 method-selector x type-selector)
6872 (idlwave-all-method-classes x type-selector)))
6873 (if inherit
f66f03de 6874 (setq classes
76959b77
S
6875 (delq nil
6876 (mapcar (lambda (x) (if (memq x inherit) x nil))
6877 classes)))))
f32b3b91
CD
6878 (setq nclasses (length classes))
6879 ;; Make the separator between item and class-info
6880 (if do-dots
6881 (setq space (concat " " (make-string (- lmax (length x)) ?.)))
6882 (setq space " "))
6883 (if do-buf
6884 ;; We do want info in the buffer
6885 (if (<= nclasses max)
6886 (setq class-info (concat
6887 space
6888 "<" (mapconcat 'identity classes ",") ">"))
6889 (setq class-info (format "%s<%d classes>" space nclasses)))
6890 (setq class-info nil))
6891 (when do-prop
6892 ;; We do want properties
6893 (setq x (copy-sequence x))
6894 (put-text-property 0 (length x)
52a244eb
S
6895 'help-echo (mapconcat 'identity classes " ")
6896 x))
f32b3b91
CD
6897 (if class-info
6898 (list x class-info)
6899 x))
6900 list))))
6901
6902(defun idlwave-attach-method-classes (list)
6903 ;; Call idlwave-attach-classes with method parameters
76959b77 6904 (idlwave-attach-classes list 'method idlwave-completion-show-classes))
f32b3b91
CD
6905(defun idlwave-attach-keyword-classes (list)
6906 ;; Call idlwave-attach-classes with keyword parameters
76959b77
S
6907 (idlwave-attach-classes list 'kwd idlwave-completion-show-classes))
6908(defun idlwave-attach-class-tag-classes (list)
6909 ;; Call idlwave-attach-classes with class structure tags
6910 (idlwave-attach-classes list 'class-tag idlwave-completion-show-classes))
f66f03de 6911
f32b3b91
CD
6912
6913;;----------------------------------------------------------------------
6914;;----------------------------------------------------------------------
6915;;----------------------------------------------------------------------
6916;;----------------------------------------------------------------------
6917;;----------------------------------------------------------------------
5e72c6b2
S
6918(defvar rtn)
6919(defun idlwave-pset (item)
6920 (set 'rtn item))
6921
6922(defun idlwave-popup-select (ev list title &optional sort)
6923 "Select an item in LIST with a popup menu.
6924TITLE is the title to put atop the popup. If SORT is non-nil,
6925sort the list before displaying"
6926 (let ((maxpopup idlwave-max-popup-menu-items)
6927 rtn menu resp)
6928 (cond ((null list))
6929 ((= 1 (length list))
6930 (setq rtn (car list)))
6931 ((featurep 'xemacs)
f66f03de 6932 (if sort (setq list (sort list (lambda (a b)
5e72c6b2
S
6933 (string< (upcase a) (upcase b))))))
6934 (setq menu
6935 (append (list title)
6936 (mapcar (lambda (x) (vector x (list 'idlwave-pset
6937 x)))
6938 list)))
6939 (setq menu (idlwave-split-menu-xemacs menu maxpopup))
6940 (setq resp (get-popup-menu-response menu))
6941 (funcall (event-function resp) (event-object resp)))
6942 (t
f66f03de 6943 (if sort (setq list (sort list (lambda (a b)
5e72c6b2
S
6944 (string< (upcase a) (upcase b))))))
6945 (setq menu (cons title
6946 (list
6947 (append (list "")
6948 (mapcar (lambda(x) (cons x x)) list)))))
6949 (setq menu (idlwave-split-menu-emacs menu maxpopup))
6950 (setq rtn (x-popup-menu ev menu))))
6951 rtn))
6952
6953(defun idlwave-split-menu-xemacs (menu N)
6954 "Split the MENU into submenus of maximum length N."
6955 (if (<= (length menu) (1+ N))
6956 ;; No splitting needed
6957 menu
6958 (let* ((title (car menu))
6959 (entries (cdr menu))
6960 (menu (list title))
6961 (cnt 0)
6962 (nextmenu nil))
6963 (while entries
6964 (while (and entries (< cnt N))
6965 (setq cnt (1+ cnt)
6966 nextmenu (cons (car entries) nextmenu)
6967 entries (cdr entries)))
6968 (setq nextmenu (nreverse nextmenu))
6969 (setq nextmenu (cons (format "%s...%s"
6970 (aref (car nextmenu) 0)
6971 (aref (nth (1- cnt) nextmenu) 0))
6972 nextmenu))
6973 (setq menu (cons nextmenu menu)
6974 nextmenu nil
6975 cnt 0))
6976 (nreverse menu))))
6977
6978(defun idlwave-split-menu-emacs (menu N)
6979 "Split the MENU into submenus of maximum length N."
6980 (if (<= (length (nth 1 menu)) (1+ N))
6981 ;; No splitting needed
6982 menu
6983 (let* ((title (car menu))
6984 (entries (cdr (nth 1 menu)))
6985 (menu nil)
6986 (cnt 0)
6987 (nextmenu nil))
6988 (while entries
6989 (while (and entries (< cnt N))
6990 (setq cnt (1+ cnt)
6991 nextmenu (cons (car entries) nextmenu)
6992 entries (cdr entries)))
6993 (setq nextmenu (nreverse nextmenu))
6994 (prin1 nextmenu)
6995 (setq nextmenu (cons (format "%s...%s"
6996 (car (car nextmenu))
6997 (car (nth (1- cnt) nextmenu)))
6998 nextmenu))
6999 (setq menu (cons nextmenu menu)
7000 nextmenu nil
7001 cnt 0))
7002 (setq menu (nreverse menu))
7003 (setq menu (cons title menu))
7004 menu)))
f32b3b91 7005
15e42531
CD
7006(defvar idlwave-completion-setup-hook nil)
7007
f32b3b91
CD
7008(defun idlwave-scroll-completions (&optional message)
7009 "Scroll the completion window on this frame."
7010 (let ((cwin (get-buffer-window "*Completions*" 'visible))
7011 (win (selected-window)))
7012 (unwind-protect
7013 (progn
7014 (select-window cwin)
7015 (condition-case nil
7016 (scroll-up)
7017 (error (if (and (listp last-command)
7018 (nth 2 last-command))
7019 (progn
7020 (select-window win)
7021 (eval idlwave-complete-after-success-form))
7022 (set-window-start cwin (point-min)))))
7023 (and message (message message)))
7024 (select-window win))))
7025
7026(defun idlwave-display-completion-list (list &optional message beg complete)
7027 "Display the completions in LIST in the completions buffer and echo MESSAGE."
7028 (unless (and (get-buffer-window "*Completions*")
7029 (idlwave-local-value 'idlwave-completion-p "*Completions*"))
7030 (move-marker idlwave-completion-mark beg)
7031 (setq idlwave-before-completion-wconf (current-window-configuration)))
7032
7033 (if (featurep 'xemacs)
f66f03de 7034 (idlwave-display-completion-list-xemacs
15e42531 7035 list)
f32b3b91
CD
7036 (idlwave-display-completion-list-emacs list))
7037
7038 ;; Store a special value in `this-command'. When `idlwave-complete'
7039 ;; finds this in `last-command', it will scroll the *Completions* buffer.
7040 (setq this-command (list 'idlwave-display-completion-list message complete))
7041
7042 ;; Mark the completions buffer as created by cib
7043 (idlwave-set-local 'idlwave-completion-p t "*Completions*")
7044
7045 ;; Fontify the classes
7046 (if (and idlwave-completion-fontify-classes
7047 (consp (car list)))
7048 (idlwave-completion-fontify-classes))
7049
15e42531
CD
7050 ;; Run the hook
7051 (run-hooks 'idlwave-completion-setup-hook)
7052
f32b3b91
CD
7053 ;; Display the message
7054 (message (or message "Making completion list...done")))
7055
7056(defun idlwave-choose (function &rest args)
7057 "Call FUNCTION as a completion chooser and pass ARGS to it."
7058 (let ((completion-ignore-case t)) ; install correct value
7059 (apply function args))
15e42531
CD
7060 (if (and (eq major-mode 'idlwave-shell-mode)
7061 (boundp 'font-lock-mode)
7062 (not font-lock-mode))
52a244eb 7063 ;; For the shell, remove the fontification of the word before point
15e42531
CD
7064 (let ((beg (save-excursion
7065 (skip-chars-backward "a-zA-Z0-9_")
7066 (point))))
7067 (remove-text-properties beg (point) '(face nil))))
f32b3b91
CD
7068 (eval idlwave-complete-after-success-form-force))
7069
76959b77
S
7070(defun idlwave-keyboard-quit ()
7071 (interactive)
7072 (unwind-protect
7073 (if (eq (car-safe last-command) 'idlwave-display-completion-list)
7074 (idlwave-restore-wconf-after-completion))
7075 (keyboard-quit)))
7076
f32b3b91
CD
7077(defun idlwave-restore-wconf-after-completion ()
7078 "Restore the old (before completion) window configuration."
7079 (and idlwave-completion-restore-window-configuration
7080 idlwave-before-completion-wconf
7081 (set-window-configuration idlwave-before-completion-wconf)))
7082
52a244eb
S
7083(defun idlwave-one-key-select (sym prompt delay)
7084 "Make the user select an element from the alist in the variable SYM.
7085The keys of the alist are expected to be strings. The function returns the
7086car of the selected association.
7087To do this, PROMPT is displayed and and the user must hit a letter key to
7088select an entry. If the user does not reply within DELAY seconds, a help
7089window with the options is displayed automatically.
7090The key which is associated with each option is generated automatically.
7091First, the strings are checked for preselected keys, like in \"[P]rint\".
7092If these don't exist, a letter in the string is automatically selected."
7093 (let* ((alist (symbol-value sym))
7094 (temp-buffer-show-hook (if (fboundp 'fit-window-to-buffer)
7095 '(fit-window-to-buffer)))
7096 keys-alist char)
7097 ;; First check the cache
7098 (if (and (eq (symbol-value sym) (get sym :one-key-alist-last)))
7099 (setq keys-alist (get sym :one-key-alist-cache))
7100 ;; Need to make new list
7101 (setq keys-alist (idlwave-make-one-key-alist alist))
7102 (put sym :one-key-alist-cache keys-alist)
7103 (put sym :one-key-alist-last alist))
7104 ;; Display prompt and wait for quick reply
7105 (message "%s[%s]" prompt
7106 (mapconcat (lambda(x) (char-to-string (car x)))
7107 keys-alist ""))
7108 (if (sit-for delay)
7109 ;; No quick reply: Show help
7110 (save-window-excursion
7111 (with-output-to-temp-buffer "*Completions*"
7112 (mapcar (lambda(x)
7113 (princ (nth 1 x))
7114 (princ "\n"))
f66f03de 7115 keys-alist))
52a244eb
S
7116 (setq char (read-char)))
7117 (setq char (read-char)))
7118 (message nil)
7119 ;; Return the selected result
7120 (nth 2 (assoc char keys-alist))))
7121
7122;; Used for, e.g., electric debug super-examine.
7123(defun idlwave-make-one-key-alist (alist)
7124 "Make an alist for single key selection."
7125 (let ((l alist) keys-alist name start char help
7126 (cnt 0)
7127 (case-fold-search nil))
7128 (while l
7129 (setq name (car (car l))
7130 l (cdr l))
7131 (catch 'exit
7132 ;; First check if the configuration predetermined a key
7133 (if (string-match "\\[\\(.\\)\\]" name)
7134 (progn
7135 (setq char (string-to-char (downcase (match-string 1 name)))
7136 help (format "%c: %s" char name)
7137 keys-alist (cons (list char help name) keys-alist))
7138 (throw 'exit t)))
7139 ;; Then check for capital letters
7140 (setq start 0)
7141 (while (string-match "[A-Z]" name start)
7142 (setq start (match-end 0)
7143 char (string-to-char (downcase (match-string 0 name))))
7144 (if (not (assoc char keys-alist))
7145 (progn
7146 (setq help (format "%c: %s" char
7147 (replace-match
7148 (concat "[" (match-string 0 name) "]")
7149 t t name))
7150 keys-alist (cons (list char help name) keys-alist))
7151 (throw 'exit t))))
7152 ;; Now check for lowercase letters
7153 (setq start 0)
7154 (while (string-match "[a-z]" name start)
7155 (setq start (match-end 0)
7156 char (string-to-char (match-string 0 name)))
7157 (if (not (assoc char keys-alist))
7158 (progn
7159 (setq help (format "%c: %s" char
7160 (replace-match
7161 (concat "[" (match-string 0 name) "]")
7162 t t name))
7163 keys-alist (cons (list char help name) keys-alist))
7164 (throw 'exit t))))
7165 ;; Bummer, nothing found! Use a stupid number
7166 (setq char (string-to-char (int-to-string (setq cnt (1+ cnt))))
7167 help (format "%c: %s" char name)
7168 keys-alist (cons (list char help name) keys-alist))))
7169 (nreverse keys-alist)))
7170
f32b3b91
CD
7171(defun idlwave-set-local (var value &optional buffer)
7172 "Set the buffer-local value of VAR in BUFFER to VALUE."
7173 (save-excursion
7174 (set-buffer (or buffer (current-buffer)))
7175 (set (make-local-variable var) value)))
7176
7177(defun idlwave-local-value (var &optional buffer)
7178 "Return the value of VAR in BUFFER, but only if VAR is local to BUFFER."
7179 (save-excursion
7180 (set-buffer (or buffer (current-buffer)))
7181 (and (local-variable-p var (current-buffer))
7182 (symbol-value var))))
7183
15e42531
CD
7184;; In XEmacs, we can use :activate-callback directly to advice the
7185;; choose functions. We use the private keymap only for the online
7186;; help feature.
f32b3b91 7187
15e42531
CD
7188(defvar idlwave-completion-map nil
7189 "Keymap for completion-list-mode with idlwave-complete.")
7190
7191(defun idlwave-display-completion-list-xemacs (list &rest cl-args)
f32b3b91 7192 (with-output-to-temp-buffer "*Completions*"
15e42531
CD
7193 (apply 'display-completion-list list
7194 ':activate-callback 'idlwave-default-choose-completion
7195 cl-args))
7196 (save-excursion
7197 (set-buffer "*Completions*")
7198 (use-local-map
7199 (or idlwave-completion-map
7200 (setq idlwave-completion-map
7201 (idlwave-make-modified-completion-map-xemacs
7202 (current-local-map)))))))
f32b3b91
CD
7203
7204(defun idlwave-default-choose-completion (&rest args)
7205 "Execute `default-choose-completion' and then restore the win-conf."
7206 (apply 'idlwave-choose 'default-choose-completion args))
7207
15e42531
CD
7208(defun idlwave-make-modified-completion-map-xemacs (old-map)
7209 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
7210 (let ((new-map (copy-keymap old-map)))
7211 (define-key new-map [button3up] 'idlwave-mouse-completion-help)
7212 (define-key new-map [button3] (lambda ()
7213 (interactive)
7214 (setq this-command last-command)))
7215 new-map))
f32b3b91 7216
76959b77 7217;; In Emacs we also replace keybindings in the completion
15e42531 7218;; map in order to install our wrappers.
f32b3b91
CD
7219
7220(defun idlwave-display-completion-list-emacs (list)
7221 "Display completion list and install the choose wrappers."
7222 (with-output-to-temp-buffer "*Completions*"
7223 (display-completion-list list))
7224 (save-excursion
7225 (set-buffer "*Completions*")
7226 (use-local-map
7227 (or idlwave-completion-map
7228 (setq idlwave-completion-map
15e42531
CD
7229 (idlwave-make-modified-completion-map-emacs
7230 (current-local-map)))))))
7231
7232(defun idlwave-make-modified-completion-map-emacs (old-map)
f32b3b91
CD
7233 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
7234 (let ((new-map (copy-keymap old-map)))
f66f03de 7235 (substitute-key-definition
f32b3b91
CD
7236 'choose-completion 'idlwave-choose-completion new-map)
7237 (substitute-key-definition
7238 'mouse-choose-completion 'idlwave-mouse-choose-completion new-map)
15e42531 7239 (define-key new-map [mouse-3] 'idlwave-mouse-completion-help)
f32b3b91
CD
7240 new-map))
7241
7242(defun idlwave-choose-completion (&rest args)
7243 "Choose the completion that point is in or next to."
7244 (interactive)
7245 (apply 'idlwave-choose 'choose-completion args))
7246
7247(defun idlwave-mouse-choose-completion (&rest args)
7248 "Click on an alternative in the `*Completions*' buffer to choose it."
7249 (interactive "e")
7250 (apply 'idlwave-choose 'mouse-choose-completion args))
7251
7252;;----------------------------------------------------------------------
7253;;----------------------------------------------------------------------
7254
05a1abfc 7255;;; ------------------------------------------------------------------------
52a244eb 7256;;; Stucture parsing code, and code to manage class info
05a1abfc
CD
7257
7258;;
7259;; - Go again over the documentation how to write a completion
7260;; plugin. It is in self.el, but currently still very bad.
f66f03de
S
7261;; This could be in a separate file in the distribution, or
7262;; in an appendix for the manual.
52a244eb
S
7263
7264(defvar idlwave-struct-skip
7265 "[ \t]*\\(\\$.*\n\\(^[ \t]*\\(\\$[ \t]*\\)?\\(;.*\\)?\n\\)*\\)?[ \t]*"
7266 "Regexp for skipping continued blank or comment-only lines in
7267structures")
7268
7269(defvar idlwave-struct-tag-regexp
7270 (concat "[{,]" ;leading comma/brace
7271 idlwave-struct-skip ; 4 groups
7272 "\\([a-zA-Z][a-zA-Z0-9_]*\\)" ;the tag itself, group 5
7273 "[ \t]*:") ; the final colon
7274 "Regexp for structure tags.")
05a1abfc
CD
7275
7276(defun idlwave-struct-tags ()
7277 "Return a list of all tags in the structure defined at point.
7278Point is expected just before the opening `{' of the struct definition."
7279 (save-excursion
7280 (let* ((borders (idlwave-struct-borders))
7281 (beg (car borders))
7282 (end (cdr borders))
7283 tags)
7284 (goto-char beg)
52a244eb
S
7285 (save-restriction
7286 (narrow-to-region beg end)
7287 (while (re-search-forward idlwave-struct-tag-regexp end t)
7288 ;; Check if we are still on the top level of the structure.
7289 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
7290 (= (point) beg))
7291 (push (match-string-no-properties 5) tags))
7292 (goto-char (match-end 0))))
7293 (nreverse tags))))
05a1abfc 7294
76959b77
S
7295(defun idlwave-find-struct-tag (tag)
7296 "Find a given TAG in the structure defined at point."
7297 (let* ((borders (idlwave-struct-borders))
7298 (beg (car borders))
7299 (end (cdr borders))
7300 (case-fold-search t))
f66f03de 7301 (re-search-forward (concat "\\(^[ \t]*\\|[,{][ \t]*\\)" tag "[ \t]*:")
76959b77
S
7302 end t)))
7303
05a1abfc
CD
7304(defun idlwave-struct-inherits ()
7305 "Return a list of all `inherits' names in the struct at point.
7306Point is expected just before the opening `{' of the struct definition."
7307 (save-excursion
7308 (let* ((borders (idlwave-struct-borders))
7309 (beg (car borders))
7310 (end (cdr borders))
7311 (case-fold-search t)
7312 names)
7313 (goto-char beg)
52a244eb
S
7314 (save-restriction
7315 (narrow-to-region beg end)
f66f03de 7316 (while (re-search-forward
52a244eb
S
7317 (concat "[{,]" ;leading comma/brace
7318 idlwave-struct-skip ; 4 groups
7319 "inherits" ; The INHERITS tag
7320 idlwave-struct-skip ; 4 more
7321 "\\([a-zA-Z][a-zA-Z0-9_]*\\)") ; The super-group, #9
7322 end t)
7323 ;; Check if we are still on the top level of the structure.
7324 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
7325 (= (point) beg))
7326 (push (match-string-no-properties 9) names))
7327 (goto-char (match-end 0))))
05a1abfc
CD
7328 (nreverse names))))
7329
5e72c6b2 7330(defun idlwave-in-structure ()
52a244eb 7331 "Return t if point is inside an IDL structure definition."
5e72c6b2
S
7332 (let ((beg (point)))
7333 (save-excursion
7334 (if (not (or (idlwave-in-comment) (idlwave-in-quote)))
7335 (if (idlwave-find-structure-definition nil nil 'back)
7336 (let ((borders (idlwave-struct-borders)))
7337 (or (= (car borders) (cdr borders)) ;; struct not yet closed...
7338 (and (> beg (car borders)) (< beg (cdr borders))))))))))
05a1abfc
CD
7339
7340(defun idlwave-struct-borders ()
7341 "Return the borders of the {...} after point as a cons cell."
7342 (let (beg)
7343 (save-excursion
7344 (skip-chars-forward "^{")
7345 (setq beg (point))
7346 (condition-case nil (forward-list 1)
7347 (error (goto-char beg)))
7348 (cons beg (point)))))
7349
7350(defun idlwave-find-structure-definition (&optional var name bound)
52a244eb
S
7351 "Search forward for a structure definition. If VAR is non-nil,
7352search for a structure assigned to variable VAR. If NAME is non-nil,
7353search for a named structure NAME, if a string, or a generic named
7354structure otherwise. If BOUND is an integer, limit the search. If
7355BOUND is the symbol `all', we search first back and then forward
7356through the entire file. If BOUND is the symbol `back' we search only
7357backward."
76959b77 7358 (let* ((ws "[ \t]*\\(\\$.*\n[ \t]*\\)*")
05a1abfc
CD
7359 (case-fold-search t)
7360 (lim (if (integerp bound) bound nil))
7361 (re (concat
7362 (if var
7363 (concat "\\<" (regexp-quote (downcase var)) "\\>" ws)
7364 "\\(\\)")
7365 "=" ws "\\({\\)"
f66f03de 7366 (if name
52a244eb 7367 (if (stringp name)
f66f03de 7368 (concat ws "\\(\\<" (downcase name) "\\)[^a-zA-Z0-9_$]")
52a244eb
S
7369 ;; Just a generic name
7370 (concat ws "\\<\\([a-zA-Z_0-9$]+\\)" ws ","))
7371 ""))))
5e72c6b2 7372 (if (or (and (or (eq bound 'all) (eq bound 'back))
05a1abfc 7373 (re-search-backward re nil t))
5e72c6b2 7374 (and (not (eq bound 'back)) (re-search-forward re lim t)))
52a244eb
S
7375 (progn
7376 (goto-char (match-beginning 3))
7377 (match-string-no-properties 5)))))
7378
f66f03de 7379(defvar idlwave-class-info nil)
52a244eb 7380(defvar idlwave-class-reset nil) ; to reset buffer-local classes
05a1abfc 7381
05a1abfc 7382(add-hook 'idlwave-update-rinfo-hook
52a244eb 7383 (lambda () (setq idlwave-class-reset t)))
05a1abfc
CD
7384(add-hook 'idlwave-after-load-rinfo-hook
7385 (lambda () (setq idlwave-class-info nil)))
7386
7387(defun idlwave-class-info (class)
7388 (let (list entry)
52a244eb
S
7389 (if idlwave-class-info
7390 (if idlwave-class-reset
f66f03de 7391 (setq
52a244eb
S
7392 idlwave-class-reset nil
7393 idlwave-class-info ; Remove any visited in a buffer
f66f03de
S
7394 (delq nil (mapcar
7395 (lambda (x)
7396 (let ((filebuf
7397 (idlwave-class-file-or-buffer
52a244eb
S
7398 (or (cdr (assq 'found-in x)) (car x)))))
7399 (if (cdr filebuf)
7400 nil
7401 x)))
7402 idlwave-class-info))))
7403 ;; Info is nil, put in the system stuff to start.
05a1abfc
CD
7404 (setq idlwave-class-info idlwave-system-class-info)
7405 (setq list idlwave-class-info)
7406 (while (setq entry (pop list))
7407 (idlwave-sintern-class-info entry)))
7408 (setq class (idlwave-sintern-class class))
52a244eb
S
7409 (or (assq class idlwave-class-info)
7410 (progn (idlwave-scan-class-info class)
7411 (assq class idlwave-class-info)))))
05a1abfc
CD
7412
7413(defun idlwave-sintern-class-info (entry)
7414 "Sintern the class names in a class-info entry."
7415 (let ((taglist (assq 'tags entry))
7416 (inherits (assq 'inherits entry)))
7417 (setcar entry (idlwave-sintern-class (car entry) 'set))
7418 (if inherits
7419 (setcdr inherits (mapcar (lambda (x) (idlwave-sintern-class x 'set))
7420 (cdr inherits))))))
7421
52a244eb
S
7422(defun idlwave-find-class-definition (class &optional all-hook alt-class)
7423 "Find class structure definition(s)
7424If ALL-HOOK is set, find all named structure definitions in a given
7425class__define routine, on which ALL-HOOK will be run. If ALT-CLASS is
7426set, look for the name__define pro, and inside of it, for the ALT-CLASS
7427class/struct definition"
7428 (let ((case-fold-search t) end-lim list name)
7429 (when (re-search-forward
7430 (concat "^[ \t]*pro[ \t]+" (downcase class) "__define" "\\>") nil t)
7431 (if all-hook
7432 (progn
7433 ;; For everything there
7434 (setq end-lim (save-excursion (idlwave-end-of-subprogram) (point)))
f66f03de 7435 (while (setq name
52a244eb
S
7436 (idlwave-find-structure-definition nil t end-lim))
7437 (funcall all-hook name)))
7438 (idlwave-find-structure-definition nil (or alt-class class))))))
76959b77 7439
52a244eb
S
7440
7441(defun idlwave-class-file-or-buffer (class)
7442 "Find buffer visiting CLASS definition"
05a1abfc 7443 (let* ((pro (concat (downcase class) "__define"))
52a244eb
S
7444 (file (idlwave-routine-source-file
7445 (nth 3 (idlwave-rinfo-assoc pro 'pro nil
7446 (idlwave-routines))))))
7447 (cons file (if file (idlwave-get-buffer-visiting file)))))
7448
7449
7450(defun idlwave-scan-class-info (class)
7451 "Scan all class and named structure info in the class__define pro"
7452 (let* ((idlwave-auto-routine-info-updates nil)
7453 (filebuf (idlwave-class-file-or-buffer class))
7454 (file (car filebuf))
7455 (buf (cdr filebuf))
7456 (class (idlwave-sintern-class class)))
7457 (if (or
7458 (not file)
7459 (and ;; neither a regular file nor a visited buffer
7460 (not buf)
7461 (not (file-regular-p file))))
7462 nil ; Cannot find the file/buffer to get any info
05a1abfc 7463 (save-excursion
52a244eb
S
7464 (if buf (set-buffer buf)
7465 ;; Read the file in temporarily
05a1abfc
CD
7466 (set-buffer (get-buffer-create " *IDLWAVE-tmp*"))
7467 (erase-buffer)
7468 (unless (eq major-mode 'idlwave-mode)
7469 (idlwave-mode))
7470 (insert-file-contents file))
7471 (save-excursion
7472 (goto-char 1)
f66f03de 7473 (idlwave-find-class-definition class
52a244eb
S
7474 ;; Scan all of the structures found there
7475 (lambda (name)
7476 (let* ((this-class (idlwave-sintern-class name))
f66f03de 7477 (entry
52a244eb
S
7478 (list this-class
7479 (cons 'tags (idlwave-struct-tags))
7480 (cons 'inherits (idlwave-struct-inherits)))))
7481 (if (not (eq this-class class))
7482 (setq entry (nconc entry (list (cons 'found-in class)))))
7483 (idlwave-sintern-class-info entry)
7484 (push entry idlwave-class-info)))))))))
7485
7486(defun idlwave-class-found-in (class)
7487 "Return the FOUND-IN property of the class."
7488 (cdr (assq 'found-in (idlwave-class-info class))))
05a1abfc
CD
7489(defun idlwave-class-tags (class)
7490 "Return the native tags in CLASS."
7491 (cdr (assq 'tags (idlwave-class-info class))))
7492(defun idlwave-class-inherits (class)
7493 "Return the direct superclasses of CLASS."
7494 (cdr (assq 'inherits (idlwave-class-info class))))
7495
52a244eb 7496
05a1abfc
CD
7497(defun idlwave-all-class-tags (class)
7498 "Return a list of native and inherited tags in CLASS."
76959b77
S
7499 (condition-case err
7500 (apply 'append (mapcar 'idlwave-class-tags
7501 (cons class (idlwave-all-class-inherits class))))
f66f03de 7502 (error
76959b77
S
7503 (idlwave-class-tag-reset)
7504 (error "%s" (error-message-string err)))))
7505
05a1abfc
CD
7506
7507(defun idlwave-all-class-inherits (class)
7508 "Return a list of all superclasses of CLASS (recursively expanded).
5e72c6b2 7509The list is cached in `idlwave-class-info' for faster access."
05a1abfc
CD
7510 (cond
7511 ((not idlwave-support-inheritance) nil)
7512 ((eq class nil) nil)
7513 ((eq class t) nil)
7514 (t
7515 (let ((info (idlwave-class-info class))
7516 entry)
7517 (if (setq entry (assq 'all-inherits info))
7518 (cdr entry)
76959b77
S
7519 ;; Save the depth of inheritance scan to check for circular references
7520 (let ((inherits (mapcar (lambda (x) (cons x 0))
7521 (idlwave-class-inherits class)))
05a1abfc
CD
7522 rtn all-inherits cl)
7523 (while inherits
7524 (setq cl (pop inherits)
76959b77
S
7525 rtn (cons (car cl) rtn)
7526 inherits (append (mapcar (lambda (x)
7527 (cons x (1+ (cdr cl))))
7528 (idlwave-class-inherits (car cl)))
7529 inherits))
7530 (if (> (cdr cl) 999)
7531 (error
7532 "Class scan: inheritance depth exceeded. Circular inheritance?")
7533 ))
05a1abfc
CD
7534 (setq all-inherits (nreverse rtn))
7535 (nconc info (list (cons 'all-inherits all-inherits)))
7536 all-inherits))))))
7537
52a244eb 7538(defun idlwave-entry-keywords (entry &optional record-link)
f66f03de 7539 "Return the flat entry keywords alist from routine-info entry.
52a244eb
S
7540If RECORD-LINK is non-nil, the keyword text is copied and a text
7541property indicating the link is added."
7542 (let (kwds)
7543 (mapcar
f66f03de 7544 (lambda (key-list)
52a244eb
S
7545 (let ((file (car key-list)))
7546 (mapcar (lambda (key-cons)
7547 (let ((key (car key-cons))
7548 (link (cdr key-cons)))
7549 (when (and record-link file)
7550 (setq key (copy-sequence key))
f66f03de 7551 (put-text-property
52a244eb 7552 0 (length key)
f66f03de
S
7553 'link
7554 (concat
7555 file
7556 (if link
52a244eb
S
7557 (concat idlwave-html-link-sep
7558 (number-to-string link))))
7559 key))
7560 (push (list key) kwds)))
7561 (cdr key-list))))
7562 (nthcdr 5 entry))
7563 (nreverse kwds)))
7564
7565(defun idlwave-entry-find-keyword (entry keyword)
7566 "Find keyword KEYWORD in entry ENTRY, and return (with link) if set"
7567 (catch 'exit
7568 (mapc
f66f03de 7569 (lambda (key-list)
52a244eb
S
7570 (let ((file (car key-list))
7571 (kwd (assoc keyword (cdr key-list))))
7572 (when kwd
f66f03de 7573 (setq kwd (cons (car kwd)
52a244eb 7574 (if (and file (cdr kwd))
f66f03de 7575 (concat file
52a244eb
S
7576 idlwave-html-link-sep
7577 (number-to-string (cdr kwd)))
7578 (cdr kwd))))
7579 (throw 'exit kwd))))
7580 (nthcdr 5 entry))))
05a1abfc
CD
7581
7582;;==========================================================================
7583;;
7584;; Completing class structure tags. This is a completion plugin.
7585;; The necessary taglist is constructed dynamically
7586
7587(defvar idlwave-current-tags-class nil)
7588(defvar idlwave-current-class-tags nil)
7589(defvar idlwave-current-native-class-tags nil)
76959b77
S
7590(defvar idlwave-sint-class-tags nil)
7591(idlwave-new-sintern-type 'class-tag)
05a1abfc 7592(add-to-list 'idlwave-complete-special 'idlwave-complete-class-structure-tag)
76959b77 7593(add-hook 'idlwave-update-rinfo-hook 'idlwave-class-tag-reset)
05a1abfc
CD
7594
7595(defun idlwave-complete-class-structure-tag ()
7596 "Complete a structure tag on a `self' argument in an object method."
7597 (interactive)
7598 (let ((pos (point))
7599 (case-fold-search t))
7600 (if (save-excursion
7601 ;; Check if the context is right
52a244eb 7602 (skip-chars-backward "a-zA-Z0-9._$")
05a1abfc
CD
7603 (and (< (point) (- pos 4))
7604 (looking-at "self\\.")))
76959b77
S
7605 (let* ((class-selector (nth 2 (idlwave-current-routine)))
7606 (super-classes (idlwave-all-class-inherits class-selector)))
05a1abfc 7607 ;; Check if we are in a class routine
76959b77 7608 (unless class-selector
e8af40ee 7609 (error "Not in a method procedure or function"))
05a1abfc 7610 ;; Check if we need to update the "current" class
76959b77
S
7611 (if (not (equal class-selector idlwave-current-tags-class))
7612 (idlwave-prepare-class-tag-completion class-selector))
f66f03de 7613 (setq idlwave-completion-help-info
76959b77 7614 (list 'idlwave-complete-class-structure-tag-help
f66f03de 7615 (idlwave-sintern-routine
76959b77
S
7616 (concat class-selector "__define"))
7617 nil))
05a1abfc
CD
7618 (let ((idlwave-cpl-bold idlwave-current-native-class-tags))
7619 (idlwave-complete-in-buffer
f66f03de 7620 'class-tag 'class-tag
05a1abfc 7621 idlwave-current-class-tags nil
76959b77
S
7622 (format "Select a tag of class %s" class-selector)
7623 "class tag"
7624 'idlwave-attach-class-tag-classes))
05a1abfc
CD
7625 t) ; return t to skip other completions
7626 nil)))
7627
76959b77 7628(defun idlwave-class-tag-reset ()
05a1abfc
CD
7629 (setq idlwave-current-tags-class nil))
7630
7631(defun idlwave-prepare-class-tag-completion (class)
7632 "Find and parse the necessary class definitions for class structure tags."
76959b77 7633 (setq idlwave-sint-class-tags nil)
05a1abfc
CD
7634 (setq idlwave-current-tags-class class)
7635 (setq idlwave-current-class-tags
7636 (mapcar (lambda (x)
76959b77 7637 (list (idlwave-sintern-class-tag x 'set)))
05a1abfc
CD
7638 (idlwave-all-class-tags class)))
7639 (setq idlwave-current-native-class-tags
7640 (mapcar 'downcase (idlwave-class-tags class))))
7641
7642;===========================================================================
7643;;
7644;; Completing system variables and their structure fields
52a244eb 7645;; This is also a plugin.
05a1abfc
CD
7646
7647(defvar idlwave-sint-sysvars nil)
7648(defvar idlwave-sint-sysvartags nil)
7649(idlwave-new-sintern-type 'sysvar)
7650(idlwave-new-sintern-type 'sysvartag)
7651(add-to-list 'idlwave-complete-special 'idlwave-complete-sysvar-or-tag)
7652(add-hook 'idlwave-update-rinfo-hook 'idlwave-sysvars-reset)
05a1abfc
CD
7653(add-hook 'idlwave-after-load-rinfo-hook 'idlwave-sintern-sysvar-alist)
7654
05a1abfc
CD
7655
7656(defun idlwave-complete-sysvar-or-tag ()
7657 "Complete a system variable."
7658 (interactive)
7659 (let ((pos (point))
7660 (case-fold-search t))
7661 (cond ((save-excursion
7662 ;; Check if the context is right for system variable
7663 (skip-chars-backward "[a-zA-Z0-9_$]")
7664 (equal (char-before) ?!))
7665 (setq idlwave-completion-help-info '(idlwave-complete-sysvar-help))
f66f03de 7666 (idlwave-complete-in-buffer 'sysvar 'sysvar
05a1abfc
CD
7667 idlwave-system-variables-alist nil
7668 "Select a system variable"
7669 "system variable")
7670 t) ; return t to skip other completions
7671 ((save-excursion
7672 ;; Check if the context is right for sysvar tag
52a244eb 7673 (skip-chars-backward "a-zA-Z0-9_$.")
05a1abfc
CD
7674 (and (equal (char-before) ?!)
7675 (looking-at "\\([a-zA-Z][a-zA-Z0-9_$]*\\)\\.")
7676 (<= (match-end 0) pos)))
7677 ;; Complete a system variable tag
7678 (let* ((var (idlwave-sintern-sysvar (match-string 1)))
7679 (entry (assq var idlwave-system-variables-alist))
52a244eb
S
7680 (tags (cdr (assq 'tags entry))))
7681 (or entry (error "!%s is not a known system variable" var))
05a1abfc
CD
7682 (or tags (error "System variable !%s is not a structure" var))
7683 (setq idlwave-completion-help-info
52a244eb 7684 (list 'idlwave-complete-sysvar-tag-help var))
f66f03de 7685 (idlwave-complete-in-buffer 'sysvartag 'sysvartag
05a1abfc
CD
7686 tags nil
7687 "Select a system variable tag"
7688 "system variable tag")
7689 t)) ; return t to skip other completions
7690 (t nil))))
7691
f66f03de
S
7692(defvar link) ;dynamic variables set by help callback
7693(defvar props)
05a1abfc 7694(defun idlwave-complete-sysvar-help (mode word)
52a244eb
S
7695 (let ((word (or (nth 1 idlwave-completion-help-info) word))
7696 (entry (assoc word idlwave-system-variables-alist)))
7697 (cond
7698 ((eq mode 'test)
7699 (and (stringp word) entry (nth 1 (assq 'link entry))))
7700 ((eq mode 'set)
7701 (if entry (setq link (nth 1 (assq 'link entry))))) ;; setting dynamic!!!
7702 (t (error "This should not happen")))))
7703
7704(defun idlwave-complete-sysvar-tag-help (mode word)
7705 (let* ((var (nth 1 idlwave-completion-help-info))
7706 (entry (assoc var idlwave-system-variables-alist))
7707 (tags (cdr (assq 'tags entry)))
7708 (main (nth 1 (assq 'link entry)))
7709 target main-base)
7710 (cond
7711 ((eq mode 'test) ; we can at least link the main
7712 (and (stringp word) entry main))
7713 ((eq mode 'set)
f66f03de
S
7714 (if entry
7715 (setq link
52a244eb
S
7716 (if (setq target (cdr (assoc word tags)))
7717 (idlwave-substitute-link-target main target)
7718 main)))) ;; setting dynamic!!!
7719 (t (error "This should not happen")))))
7720
f66f03de
S
7721(defun idlwave-split-link-target (link)
7722 "Split a given link into link file and anchor."
7723 (if (string-match idlwave-html-link-sep link)
7724 (cons (substring link 0 (match-beginning 0))
7725 (string-to-number (substring link (match-end 0))))))
7726
52a244eb
S
7727(defun idlwave-substitute-link-target (link target)
7728 "Substitute the target anchor for the given link."
7729 (let (main-base)
7730 (setq main-base (if (string-match "#" link)
7731 (substring link 0 (match-beginning 0))
7732 link))
7733 (if target
7734 (concat main-base idlwave-html-link-sep (number-to-string target))
7735 link)))
76959b77
S
7736
7737;; Fake help in the source buffer for class structure tags.
52a244eb 7738;; KWD AND NAME ARE GLOBAL-VARIABLES HERE.
f66f03de 7739(defvar name)
52a244eb 7740(defvar kwd)
76959b77
S
7741(defvar idlwave-help-do-class-struct-tag nil)
7742(defun idlwave-complete-class-structure-tag-help (mode word)
7743 (cond
7744 ((eq mode 'test) ; nothing gets fontified for class tags
7745 nil)
7746 ((eq mode 'set)
52a244eb 7747 (let (class-with found-in)
f66f03de
S
7748 (when (setq class-with
7749 (idlwave-class-or-superclass-with-tag
76959b77
S
7750 idlwave-current-tags-class
7751 word))
f66f03de 7752 (if (assq (idlwave-sintern-class class-with)
76959b77 7753 idlwave-system-class-info)
ff689efd 7754 (error "No help available for system class tags"))
52a244eb
S
7755 (if (setq found-in (idlwave-class-found-in class-with))
7756 (setq name (cons (concat found-in "__define") class-with))
7757 (setq name (concat class-with "__define")))))
76959b77
S
7758 (setq kwd word
7759 idlwave-help-do-class-struct-tag t))
7760 (t (error "This should not happen"))))
7761
7762(defun idlwave-class-or-superclass-with-tag (class tag)
7763 "Find and return the CLASS or one of its superclass with the
7764associated TAG, if any."
f66f03de 7765 (let ((sclasses (cons class (cdr (assq 'all-inherits
76959b77
S
7766 (idlwave-class-info class)))))
7767 cl)
7768 (catch 'exit
7769 (while sclasses
7770 (setq cl (pop sclasses))
7771 (let ((tags (idlwave-class-tags cl)))
7772 (while tags
7773 (if (eq t (compare-strings tag 0 nil (car tags) 0 nil t))
f66f03de 7774 (throw 'exit cl))
76959b77
S
7775 (setq tags (cdr tags))))))))
7776
05a1abfc
CD
7777
7778(defun idlwave-sysvars-reset ()
7779 (if (and (fboundp 'idlwave-shell-is-running)
52a244eb
S
7780 (idlwave-shell-is-running)
7781 idlwave-idlwave_routine_info-compiled)
05a1abfc
CD
7782 (idlwave-shell-send-command "idlwave_get_sysvars"
7783 'idlwave-process-sysvars 'hide)))
7784
7785(defun idlwave-process-sysvars ()
7786 (idlwave-shell-filter-sysvars)
7787 (setq idlwave-sint-sysvars nil
7788 idlwave-sint-sysvartags nil)
7789 (idlwave-sintern-sysvar-alist))
7790
05a1abfc 7791(defun idlwave-sintern-sysvar-alist ()
52a244eb 7792 (let ((list idlwave-system-variables-alist) entry tags)
05a1abfc
CD
7793 (while (setq entry (pop list))
7794 (setcar entry (idlwave-sintern-sysvar (car entry) 'set))
52a244eb
S
7795 (setq tags (assq 'tags entry))
7796 (if tags
f66f03de
S
7797 (setcdr tags
7798 (mapcar (lambda (x)
52a244eb
S
7799 (cons (idlwave-sintern-sysvartag (car x) 'set)
7800 (cdr x)))
7801 (cdr tags)))))))
05a1abfc
CD
7802
7803(defvar idlwave-shell-command-output)
7804(defun idlwave-shell-filter-sysvars ()
52a244eb 7805 "Get any new system variables and tags."
05a1abfc
CD
7806 (let ((text idlwave-shell-command-output)
7807 (start 0)
7808 (old idlwave-system-variables-alist)
52a244eb 7809 var tags type name class link old-entry)
05a1abfc
CD
7810 (setq idlwave-system-variables-alist nil)
7811 (while (string-match "^IDLWAVE-SYSVAR: !\\([a-zA-Z0-9_$]+\\)\\( \\(.*\\)\\)?"
7812 text start)
7813 (setq start (match-end 0)
7814 var (match-string 1 text)
f66f03de 7815 tags (if (match-end 3)
52a244eb
S
7816 (idlwave-split-string (match-string 3 text))))
7817 ;; Maintain old links, if present
7818 (setq old-entry (assq (idlwave-sintern-sysvar var) old))
7819 (setq link (assq 'link old-entry))
05a1abfc 7820 (setq idlwave-system-variables-alist
f66f03de
S
7821 (cons (list var
7822 (cons
7823 'tags
7824 (mapcar (lambda (x)
7825 (cons x
7826 (cdr (assq
7827 (idlwave-sintern-sysvartag x)
52a244eb
S
7828 (cdr (assq 'tags old-entry))))))
7829 tags)) link)
05a1abfc
CD
7830 idlwave-system-variables-alist)))
7831 ;; Keep the old value if query was not successful
7832 (setq idlwave-system-variables-alist
7833 (or idlwave-system-variables-alist old))))
7834
f32b3b91
CD
7835(defun idlwave-completion-fontify-classes ()
7836 "Goto the *Completions* buffer and fontify the class info."
7837 (when (featurep 'font-lock)
7838 (save-excursion
7839 (set-buffer "*Completions*")
7840 (save-excursion
7841 (goto-char (point-min))
76959b77
S
7842 (let ((buffer-read-only nil))
7843 (while (re-search-forward "\\.*<[^>]+>" nil t)
7844 (put-text-property (match-beginning 0) (match-end 0)
7845 'face 'font-lock-string-face)))))))
f32b3b91
CD
7846
7847(defun idlwave-uniquify (list)
52a244eb 7848 (let ((ht (make-hash-table :size (length list) :test 'equal)))
f66f03de 7849 (delq nil
52a244eb 7850 (mapcar (lambda (x)
f66f03de 7851 (unless (gethash x ht)
52a244eb
S
7852 (puthash x t ht)
7853 x))
7854 list))))
f32b3b91
CD
7855
7856(defun idlwave-after-successful-completion (type slash &optional verify)
7857 "Add `=' or `(' after successful completion of keyword and function.
7858Restore the pre-completion window configuration if possible."
7859 (cond
7860 ((eq type 'procedure)
7861 nil)
7862 ((eq type 'function)
7863 (cond
7864 ((equal idlwave-function-completion-adds-paren nil) nil)
7865 ((or (equal idlwave-function-completion-adds-paren t)
7866 (equal idlwave-function-completion-adds-paren 1))
7867 (insert "("))
7868 ((equal idlwave-function-completion-adds-paren 2)
7869 (insert "()")
7870 (backward-char 1))
7871 (t nil)))
7872 ((eq type 'keyword)
7873 (if (and idlwave-keyword-completion-adds-equal
7874 (not slash))
7875 (progn (insert "=") t)
7876 nil)))
7877
7878 ;; Restore the pre-completion window configuration if this is safe.
f66f03de
S
7879
7880 (if (or (eq verify 'force) ; force
7881 (and
f32b3b91 7882 (get-buffer-window "*Completions*") ; visible
f66f03de 7883 (idlwave-local-value 'idlwave-completion-p
f32b3b91
CD
7884 "*Completions*") ; cib-buffer
7885 (eq (marker-buffer idlwave-completion-mark)
7886 (current-buffer)) ; buffer OK
7887 (equal (marker-position idlwave-completion-mark)
7888 verify))) ; pos OK
7889 (idlwave-restore-wconf-after-completion))
7890 (move-marker idlwave-completion-mark nil)
7891 (setq idlwave-before-completion-wconf nil))
7892
15e42531
CD
7893(defun idlwave-mouse-context-help (ev &optional arg)
7894 "Call `idlwave-context-help' on the clicked location."
7895 (interactive "eP")
7896 (mouse-set-point ev)
7897 (idlwave-context-help arg))
7898
7899(defvar idlwave-last-context-help-pos nil)
7900(defun idlwave-context-help (&optional arg)
7901 "Display IDL Online Help on context.
76959b77
S
7902If point is on a keyword, help for that keyword will be shown. If
7903point is on a routine name or in the argument list of a routine, help
7904for that routine will be displayed. Works for system routines and
7905keywords, it pulls up text help. For other routies and keywords,
7906visits the source file, finding help in the header (if
7907`idlwave-help-source-try-header' is non-nil) or the routine definition
7908itself."
f32b3b91 7909 (interactive "P")
15e42531
CD
7910 (idlwave-do-context-help arg))
7911
7912(defun idlwave-mouse-completion-help (ev)
7913 "Display online help about the completion at point."
7914 (interactive "eP")
52a244eb
S
7915 ;; Restore last-command for next command, to make
7916 ;; scrolling/cancelling of completions work.
15e42531
CD
7917 (setq this-command last-command)
7918 (idlwave-do-mouse-completion-help ev))
15e42531 7919
f32b3b91 7920(defun idlwave-routine-info (&optional arg external)
52a244eb
S
7921 "Display a routines calling sequence and list of keywords. When
7922point is on the name a function or procedure, or in the argument list
7923of a function or procedure, this command displays a help buffer with
7924the information. When called with prefix arg, enforce class query.
f32b3b91
CD
7925
7926When point is on an object operator `->', display the class stored in
7927this arrow, if any (see `idlwave-store-inquired-class'). With a
7928prefix arg, the class property is cleared out."
7929
7930 (interactive "P")
7931 (idlwave-routines)
7932 (if (string-match "->" (buffer-substring
7933 (max (point-min) (1- (point)))
7934 (min (+ 2 (point)) (point-max))))
7935 ;; Cursor is on an arrow
7936 (if (get-text-property (point) 'idlwave-class)
7937 ;; arrow has class property
7938 (if arg
7939 ;; Remove property
7940 (save-excursion
7941 (backward-char 1)
7942 (when (looking-at ".?\\(->\\)")
7943 (remove-text-properties (match-beginning 1) (match-end 1)
7944 '(idlwave-class nil face nil))
7945 (message "Class property removed from arrow")))
7946 ;; Echo class property
7947 (message "Arrow has text property identifying object to be class %s"
7948 (get-text-property (point) 'idlwave-class)))
7949 ;; No property found
7950 (message "Arrow has no class text property"))
7951
7952 ;; Not on an arrow...
7953 (let* ((idlwave-query-class nil)
7954 (idlwave-force-class-query (equal arg '(4)))
7955 (module (idlwave-what-module)))
15e42531 7956 (if (car module)
05a1abfc
CD
7957 (apply 'idlwave-display-calling-sequence
7958 (idlwave-fix-module-if-obj_new module))
e8af40ee 7959 (error "Don't know which calling sequence to show")))))
f32b3b91
CD
7960
7961(defun idlwave-resolve (&optional arg)
52a244eb 7962 "Call RESOLVE_ROUTINE on the module name at point.
f32b3b91
CD
7963Like `idlwave-routine-info', this looks for a routine call at point.
7964After confirmation in the minibuffer, it will use the shell to issue
7965a RESOLVE call for this routine, to attempt to make it defined and its
7966routine info available for IDLWAVE. If the routine is a method call,
7967both `class__method' and `class__define' will be tried.
7968With ARG, enforce query for the class of object methods."
7969 (interactive "P")
7970 (let* ((idlwave-query-class nil)
7971 (idlwave-force-class-query (equal arg '(4)))
7972 (module (idlwave-what-module))
7973 (name (idlwave-make-full-name (nth 2 module) (car module)))
7974 (type (if (eq (nth 1 module) 'pro) "pro" "function"))
7975 (resolve (read-string "Resolve: " (format "%s %s" type name)))
7976 (kwd "")
7977 class)
7978 (if (string-match "\\(pro\\|function\\)[ \t]+\\(\\(.*\\)::\\)?\\(.*\\)"
7979 resolve)
7980 (setq type (match-string 1 resolve)
f66f03de 7981 class (if (match-beginning 2)
f32b3b91
CD
7982 (match-string 3 resolve)
7983 nil)
7984 name (match-string 4 resolve)))
7985 (if (string= (downcase type) "function")
7986 (setq kwd ",/is_function"))
7987
7988 (cond
7989 ((null class)
f66f03de 7990 (idlwave-shell-send-command
f32b3b91
CD
7991 (format "resolve_routine,'%s'%s" (downcase name) kwd)
7992 'idlwave-update-routine-info
7993 nil t))
7994 (t
f66f03de 7995 (idlwave-shell-send-command
f32b3b91 7996 (format "resolve_routine,'%s__define'%s" (downcase class) kwd)
f66f03de
S
7997 (list 'idlwave-shell-send-command
7998 (format "resolve_routine,'%s__%s'%s"
f32b3b91
CD
7999 (downcase class) (downcase name) kwd)
8000 '(idlwave-update-routine-info)
8001 nil t))))))
8002
3938cb82
S
8003(defun idlwave-find-module-this-file ()
8004 (interactive)
8005 (idlwave-find-module '(4)))
8006
f32b3b91
CD
8007(defun idlwave-find-module (&optional arg)
8008 "Find the source code of an IDL module.
52a244eb
S
8009Works for modules for which IDLWAVE has routine info available. The
8010function offers as default the module name `idlwave-routine-info'
8011would use. With ARG limit to this buffer. With two prefix ARG's
8012force class query for object methods."
f32b3b91
CD
8013 (interactive "P")
8014 (let* ((idlwave-query-class nil)
52a244eb
S
8015 (idlwave-force-class-query (equal arg '(16)))
8016 (this-buffer (equal arg '(4)))
05a1abfc 8017 (module (idlwave-fix-module-if-obj_new (idlwave-what-module)))
52a244eb 8018 (default (if module
f66f03de 8019 (concat (idlwave-make-full-name
52a244eb
S
8020 (nth 2 module) (car module))
8021 (if (eq (nth 1 module) 'pro) "<p>" "<f>"))
8022 "none"))
f66f03de 8023 (list
52a244eb
S
8024 (idlwave-uniquify
8025 (delq nil
f66f03de 8026 (mapcar (lambda (x)
52a244eb
S
8027 (if (eq 'system (car-safe (nth 3 x)))
8028 ;; Take out system routines with no source.
8029 nil
8030 (list
f66f03de 8031 (concat (idlwave-make-full-name
52a244eb
S
8032 (nth 2 x) (car x))
8033 (if (eq (nth 1 x) 'pro) "<p>" "<f>")))))
8034 (if this-buffer
8035 (idlwave-save-buffer-update)
8036 (idlwave-routines))))))
f32b3b91 8037 (name (idlwave-completing-read
52a244eb
S
8038 (if (or (not this-buffer)
8039 (assoc default list))
8040 (format "Module (Default %s): " default)
8041 (format "Module in this file: "))
f32b3b91
CD
8042 list))
8043 type class)
8044 (if (string-match "\\`\\s-*\\'" name)
8045 ;; Nothing, use the default.
8046 (setq name default))
8047 (if (string-match "<[fp]>" name)
8048 (setq type (substring name -2 -1)
8049 name (substring name 0 -3)))
8050 (if (string-match "\\(.*\\)::\\(.*\\)" name)
8051 (setq class (match-string 1 name)
8052 name (match-string 2 name)))
8053 (setq name (idlwave-sintern-routine-or-method name class)
8054 class (idlwave-sintern-class class)
8055 type (cond ((equal type "f") 'fun)
8056 ((equal type "p") 'pro)
8057 (t t)))
52a244eb 8058 (idlwave-do-find-module name type class nil this-buffer)))
f32b3b91 8059
f66f03de 8060(defun idlwave-do-find-module (name type class
52a244eb 8061 &optional force-source this-buffer)
f32b3b91 8062 (let ((name1 (idlwave-make-full-name class name))
f66f03de 8063 source buf1 entry
f32b3b91 8064 (buf (current-buffer))
05a1abfc 8065 (pos (point))
52a244eb
S
8066 file name2)
8067 (setq entry (idlwave-best-rinfo-assq name type class (idlwave-routines)
8068 'WITH-FILE)
05a1abfc
CD
8069 source (or force-source (nth 3 entry))
8070 name2 (if (nth 2 entry)
8071 (idlwave-make-full-name (nth 2 entry) name)
775591f7 8072 name1))
f66f03de 8073 (if source
52a244eb
S
8074 (setq file (idlwave-routine-source-file source)))
8075 (unless file ; Try to find it on the path.
f66f03de
S
8076 (setq file
8077 (idlwave-expand-lib-file-name
52a244eb
S
8078 (if class
8079 (format "%s__define.pro" (downcase class))
8080 (format "%s.pro" (downcase name))))))
f32b3b91
CD
8081 (cond
8082 ((or (null name) (equal name ""))
8083 (error "Abort"))
f32b3b91 8084 ((eq (car source) 'system)
f66f03de 8085 (error "Source code for system routine %s is not available"
05a1abfc 8086 name2))
52a244eb 8087 ((or (not file) (not (file-regular-p file)))
e8af40ee 8088 (error "Source code for routine %s is not available"
05a1abfc 8089 name2))
52a244eb
S
8090 (t
8091 (when (not this-buffer)
f66f03de 8092 (setq buf1
52a244eb
S
8093 (idlwave-find-file-noselect file 'find))
8094 (pop-to-buffer buf1 t))
15e42531 8095 (goto-char (point-max))
f32b3b91 8096 (let ((case-fold-search t))
15e42531 8097 (if (re-search-backward
f32b3b91 8098 (concat "^[ \t]*\\<"
52a244eb
S
8099 (cond ((eq type 'fun) "function")
8100 ((eq type 'pro) "pro")
f32b3b91 8101 (t "\\(pro\\|function\\)"))
f66f03de 8102 "\\>[ \t]+"
05a1abfc 8103 (regexp-quote (downcase name2))
f32b3b91
CD
8104 "[^a-zA-Z0-9_$]")
8105 nil t)
8106 (goto-char (match-beginning 0))
8107 (pop-to-buffer buf)
8108 (goto-char pos)
05a1abfc 8109 (error "Could not find routine %s" name2)))))))
f32b3b91
CD
8110
8111(defun idlwave-what-module ()
8112 "Return a default module for stuff near point.
8113Used by `idlwave-routine-info' and `idlwave-find-module'."
8114 (idlwave-routines)
15e42531
CD
8115 (if (let ((case-fold-search t))
8116 (save-excursion
8117 (idlwave-beginning-of-statement)
8118 (looking-at "[ \t]*\\(pro\\|function\\)[ \t]+\\(\\([a-zA-Z0-9_$]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)\\([, \t\n]\\|$\\)")))
8119 ;; This is a function or procedure definition statement
8120 ;; We return the defined routine as module.
8121 (list
52a244eb
S
8122 (idlwave-sintern-routine-or-method (match-string-no-properties 4)
8123 (match-string-no-properties 2))
15e42531
CD
8124 (if (equal (downcase (match-string 1)) "pro") 'pro 'fun)
8125 (idlwave-sintern-class (match-string 3)))
8126
52a244eb 8127 ;; Not a definition statement - analyze precise position.
15e42531
CD
8128 (let* ((where (idlwave-where))
8129 (cw (nth 2 where))
8130 (pro (car (nth 0 where)))
8131 (func (car (nth 1 where)))
8132 (this-word (idlwave-this-word "a-zA-Z0-9$_"))
8133 (next-char (save-excursion (skip-chars-forward "a-zA-Z0-9$_")
8134 (following-char)))
8135 )
8136 (cond
8137 ((and (eq cw 'procedure)
8138 (not (equal this-word "")))
f66f03de 8139 (setq this-word (idlwave-sintern-routine-or-method
15e42531
CD
8140 this-word (nth 2 (nth 3 where))))
8141 (list this-word 'pro
f66f03de 8142 (idlwave-determine-class
15e42531
CD
8143 (cons this-word (cdr (nth 3 where)))
8144 'pro)))
f66f03de 8145 ((and (eq cw 'function)
15e42531
CD
8146 (not (equal this-word ""))
8147 (or (eq next-char ?\() ; exclude arrays, vars.
8148 (looking-at "[a-zA-Z0-9_]*[ \t]*(")))
f66f03de 8149 (setq this-word (idlwave-sintern-routine-or-method
15e42531
CD
8150 this-word (nth 2 (nth 3 where))))
8151 (list this-word 'fun
8152 (idlwave-determine-class
8153 (cons this-word (cdr (nth 3 where)))
8154 'fun)))
8155 ((and (memq cw '(function-keyword procedure-keyword))
8156 (not (equal this-word ""))
8157 (eq next-char ?\()) ; A function!
8158 (setq this-word (idlwave-sintern-routine this-word))
8159 (list this-word 'fun nil))
8160 (func
8161 (list func 'fun (idlwave-determine-class (nth 1 where) 'fun)))
8162 (pro
8163 (list pro 'pro (idlwave-determine-class (nth 0 where) 'pro)))
8164 (t nil)))))
f32b3b91 8165
05a1abfc
CD
8166(defun idlwave-what-module-find-class ()
8167 "Call idlwave-what-module and find the inherited class if necessary."
8168 (let* ((module (idlwave-what-module))
8169 (class (nth 2 module))
8170 classes)
8171 (if (and (= (length module) 3)
8172 (stringp class))
8173 (list (car module)
8174 (nth 1 module)
8175 (apply 'idlwave-find-inherited-class module))
8176 module)))
8177
8178(defun idlwave-find-inherited-class (name type class)
8179 "Find the class which defines TYPE NAME and is CLASS or inherited by CLASS."
8180 (let ((entry (idlwave-best-rinfo-assoc name type class (idlwave-routines))))
8181 (if entry
8182 (nth 2 entry)
8183 class)))
8184
8185(defun idlwave-fix-module-if-obj_new (module)
f66f03de 8186 "Check if MODULE points to obj_new.
52a244eb
S
8187If yes, and if the cursor is in the keyword region, change to the
8188appropriate Init method."
05a1abfc
CD
8189 (let* ((name (car module))
8190 (pos (point))
8191 (case-fold-search t)
8192 string)
8193 (if (and (stringp name)
8194 (equal (downcase name) "obj_new")
8195 (save-excursion
8196 (idlwave-beginning-of-statement)
8197 (setq string (buffer-substring (point) pos))
8198 (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
8199 string)))
8200 (let ((name "Init")
8201 (class (match-string 1 string)))
8202 (setq module (list (idlwave-sintern-method "Init")
8203 'fun
8204 (idlwave-sintern-class class)))))
8205 module))
8206
f66f03de 8207(defun idlwave-fix-keywords (name type class keywords
3938cb82 8208 &optional super-classes system)
52a244eb
S
8209 "Update a list of keywords.
8210Translate OBJ_NEW, adding all super-class keywords, or all keywords
3938cb82
S
8211from all classes if class equals t. If SYSTEM is non-nil, don't
8212demand _EXTRA in the keyword list."
5e72c6b2 8213 (let ((case-fold-search t))
f32b3b91
CD
8214
8215 ;; If this is the OBJ_NEW function, try to figure out the class and use
8216 ;; the keywords from the corresponding INIT method.
5e72c6b2 8217 (if (and (equal (upcase name) "OBJ_NEW")
05a1abfc
CD
8218 (or (eq major-mode 'idlwave-mode)
8219 (eq major-mode 'idlwave-shell-mode)))
f32b3b91
CD
8220 (let* ((bos (save-excursion (idlwave-beginning-of-statement) (point)))
8221 (string (buffer-substring bos (point)))
8222 (case-fold-search t)
8223 class)
8224 (and (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
8225 string)
8226 (setq class (idlwave-sintern-class (match-string 1 string)))
15e42531 8227 (setq idlwave-current-obj_new-class class)
f66f03de
S
8228 (setq keywords
8229 (append keywords
52a244eb
S
8230 (idlwave-entry-keywords
8231 (idlwave-rinfo-assq
8232 (idlwave-sintern-method "INIT")
8233 'fun
8234 class
8235 (idlwave-routines)) 'do-link))))))
f66f03de 8236
f32b3b91
CD
8237 ;; If the class is `t', combine all keywords of all methods NAME
8238 (when (eq class t)
52a244eb
S
8239 (mapc (lambda (entry)
8240 (and
8241 (nth 2 entry) ; non-nil class
8242 (eq (nth 1 entry) type) ; correct type
f66f03de
S
8243 (setq keywords
8244 (append keywords
52a244eb
S
8245 (idlwave-entry-keywords entry 'do-link)))))
8246 (idlwave-all-assq name (idlwave-routines)))
5e72c6b2 8247 (setq keywords (idlwave-uniquify keywords)))
f66f03de 8248
5e72c6b2 8249 ;; If we have inheritance, add all keywords from superclasses, if
52a244eb 8250 ;; the user indicated that method in `idlwave-keyword-class-inheritance'
f66f03de 8251 (when (and
52a244eb 8252 super-classes
5e72c6b2
S
8253 idlwave-keyword-class-inheritance
8254 (stringp class)
f66f03de 8255 (or
3938cb82
S
8256 system
8257 (assq (idlwave-sintern-keyword "_extra") keywords)
8258 (assq (idlwave-sintern-keyword "_ref_extra") keywords))
5e72c6b2
S
8259 ;; Check if one of the keyword-class regexps matches the name
8260 (let ((regexps idlwave-keyword-class-inheritance) re)
8261 (catch 'exit
8262 (while (setq re (pop regexps))
8263 (if (string-match re name) (throw 'exit t))))))
52a244eb
S
8264
8265 (loop for entry in (idlwave-routines) do
8266 (and (nth 2 entry) ; non-nil class
8267 (memq (nth 2 entry) super-classes) ; an inherited class
8268 (eq (nth 1 entry) type) ; correct type
8269 (eq (car entry) name) ; correct name
5e72c6b2 8270 (mapcar (lambda (k) (add-to-list 'keywords k))
52a244eb 8271 (idlwave-entry-keywords entry 'do-link))))
f32b3b91 8272 (setq keywords (idlwave-uniquify keywords)))
f66f03de 8273
f32b3b91
CD
8274 ;; Return the final list
8275 keywords))
8276
15e42531 8277(defun idlwave-expand-keyword (keyword module)
2e8b9c7d 8278 "Expand KEYWORD to one of the valid keyword parameters of MODULE.
15e42531
CD
8279KEYWORD may be an exact match or an abbreviation of a keyword.
8280If the match is exact, KEYWORD itself is returned, even if there may be other
8281keywords of which KEYWORD is an abbreviation. This is necessary because some
8282system routines have keywords which are prefixes of other keywords.
8283If KEYWORD is an abbreviation of several keywords, a list of all possible
8284completions is returned.
8285If the abbreviation was unique, the correct keyword is returned.
8286If it cannot be a keyword, the function return nil.
8287If we do not know about MODULE, just return KEYWORD literally."
8288 (let* ((name (car module))
8289 (type (nth 1 module))
8290 (class (nth 2 module))
8291 (kwd (idlwave-sintern-keyword keyword))
8292 (entry (idlwave-best-rinfo-assoc name type class (idlwave-routines)))
52a244eb 8293 (kwd-alist (idlwave-entry-keywords entry))
15e42531
CD
8294 (extra (or (assq (idlwave-sintern-keyword "_EXTRA") kwd-alist)
8295 (assq (idlwave-sintern-keyword "_REF_EXTRA") kwd-alist)))
8296 (completion-ignore-case t)
8297 candidates)
f66f03de 8298 (cond ((assq kwd kwd-alist)
15e42531
CD
8299 kwd)
8300 ((setq candidates (all-completions kwd kwd-alist))
8301 (if (= (length candidates) 1)
8302 (car candidates)
8303 candidates))
8304 ((and entry extra)
f66f03de 8305 ;; Inheritance may cause this keyword to be correct
15e42531
CD
8306 keyword)
8307 (entry
8308 ;; We do know the function, which does not have the keyword.
8309 nil)
8310 (t
8311 ;; We do not know the function, so this just might be a correct
8312 ;; keyword - return it as it is.
8313 keyword))))
8314
8315(defvar idlwave-rinfo-mouse-map (make-sparse-keymap))
f32b3b91 8316(defvar idlwave-rinfo-map (make-sparse-keymap))
f66f03de 8317(define-key idlwave-rinfo-mouse-map
f32b3b91
CD
8318 (if (featurep 'xemacs) [button2] [mouse-2])
8319 'idlwave-mouse-active-rinfo)
f66f03de 8320(define-key idlwave-rinfo-mouse-map
15e42531
CD
8321 (if (featurep 'xemacs) [(shift button2)] [(shift mouse-2)])
8322 'idlwave-mouse-active-rinfo-shift)
f66f03de 8323(define-key idlwave-rinfo-mouse-map
f32b3b91
CD
8324 (if (featurep 'xemacs) [button3] [mouse-3])
8325 'idlwave-mouse-active-rinfo-right)
15e42531
CD
8326(define-key idlwave-rinfo-mouse-map " " 'idlwave-active-rinfo-space)
8327(define-key idlwave-rinfo-map "q" 'idlwave-quit-help)
8328(define-key idlwave-rinfo-mouse-map "q" 'idlwave-quit-help)
8329(defvar idlwave-popup-source nil)
8330(defvar idlwave-rinfo-marker (make-marker))
8331
8332(defun idlwave-quit-help ()
8333 (interactive)
8334 (let ((ri-window (get-buffer-window "*Help*"))
8335 (olh-window (get-buffer-window "*IDLWAVE Help*")))
8336 (when (and olh-window
8337 (fboundp 'idlwave-help-quit))
8338 (select-window olh-window)
8339 (idlwave-help-quit))
8340 (when (window-live-p ri-window)
8341 (delete-window ri-window))))
f32b3b91 8342
05a1abfc
CD
8343(defun idlwave-display-calling-sequence (name type class
8344 &optional initial-class)
f32b3b91 8345 ;; Display the calling sequence of module NAME, type TYPE in class CLASS.
05a1abfc
CD
8346 (let* ((initial-class (or initial-class class))
8347 (entry (or (idlwave-best-rinfo-assq name type class
15e42531 8348 (idlwave-routines))
f66f03de 8349 (idlwave-rinfo-assq name type class
15e42531 8350 idlwave-unresolved-routines)))
f32b3b91
CD
8351 (name (or (car entry) name))
8352 (class (or (nth 2 entry) class))
05a1abfc 8353 (superclasses (idlwave-all-class-inherits initial-class))
15e42531
CD
8354 (twins (idlwave-routine-twins entry))
8355 (dtwins (idlwave-study-twins twins))
8356 (all dtwins)
52a244eb 8357 (system (eq (car (nth 3 entry)) 'system))
f32b3b91 8358 (calling-seq (nth 4 entry))
52a244eb
S
8359 (keywords (idlwave-entry-keywords entry 'do-link))
8360 (html-file (car (nth 5 entry)))
15e42531 8361 (help-echo-kwd
52a244eb 8362 "Button2: Insert KEYWORD (SHIFT=`/KEYWORD') | Button3: Online Help ")
15e42531 8363 (help-echo-use
52a244eb 8364 "Button2/3: Online Help")
15e42531 8365 (help-echo-src
52a244eb 8366 "Button2: Jump to source and back | Button3: Source in Help window.")
05a1abfc
CD
8367 (help-echo-class
8368 "Button2: Display info about same method in superclass")
f32b3b91 8369 (col 0)
52a244eb 8370 (data (list name type class (current-buffer) nil initial-class))
f32b3b91 8371 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
f66f03de 8372 (face 'idlwave-help-link)
15e42531 8373 beg props win cnt total)
f66f03de 8374 ;; Fix keywords, but don't add chained super-classes, since these
52a244eb 8375 ;; are shown separately for that super-class
f32b3b91
CD
8376 (setq keywords (idlwave-fix-keywords name type class keywords))
8377 (cond
8378 ((null entry)
05a1abfc
CD
8379 (error "No %s %s known %s" type name
8380 (if initial-class (concat "in class " initial-class) "")))
f32b3b91 8381 ((or (null name) (equal name ""))
e8af40ee 8382 (error "No function or procedure call at point"))
f32b3b91 8383 ((null calling-seq)
52a244eb 8384 (error "Calling sequence of %s %s not available" type name))
f32b3b91
CD
8385 (t
8386 (save-excursion
15e42531 8387 (move-marker idlwave-rinfo-marker (point))
f32b3b91 8388 (set-buffer (get-buffer-create "*Help*"))
15e42531 8389 (use-local-map idlwave-rinfo-map)
f32b3b91
CD
8390 (setq buffer-read-only nil)
8391 (erase-buffer)
8392 (set (make-local-variable 'idlwave-popup-source) nil)
15e42531
CD
8393 (set (make-local-variable 'idlwave-current-obj_new-class)
8394 idlwave-current-obj_new-class)
05a1abfc
CD
8395 (when superclasses
8396 (setq props (list 'mouse-face 'highlight
8397 km-prop idlwave-rinfo-mouse-map
8398 'help-echo help-echo-class
8399 'data (cons 'class data)))
8400 (let ((classes (cons initial-class superclasses)) c)
8401 (insert "Classes: ")
8402 (while (setq c (pop classes))
8403 (insert " ")
8404 (setq beg (point))
8405 (insert c)
8406 (if (equal (downcase c) (downcase class))
8407 (add-text-properties beg (point) (list 'face 'bold))
52a244eb 8408 ;; If Method exists in a different class link it
05a1abfc
CD
8409 (if (idlwave-rinfo-assq name type c (idlwave-routines))
8410 (add-text-properties beg (point) props))))
8411 (insert "\n")))
52a244eb
S
8412 (setq props (list 'mouse-face 'highlight
8413 km-prop idlwave-rinfo-mouse-map
8414 'help-echo help-echo-use
8415 'data (cons 'usage data)))
f66f03de 8416 (if html-file (setq props (append (list 'face face 'link html-file)
52a244eb 8417 props)))
f32b3b91
CD
8418 (insert "Usage: ")
8419 (setq beg (point))
8420 (insert (if class
52a244eb
S
8421 (format calling-seq class name class name class name)
8422 (format calling-seq name name name name))
f32b3b91
CD
8423 "\n")
8424 (add-text-properties beg (point) props)
f66f03de 8425
f32b3b91
CD
8426 (insert "Keywords:")
8427 (if (null keywords)
8428 (insert " No keywords accepted.")
8429 (setq col 9)
8430 (mapcar
8431 (lambda (x)
f66f03de 8432 (if (>= (+ col 1 (length (car x)))
f32b3b91
CD
8433 (window-width))
8434 (progn
8435 (insert "\n ")
8436 (setq col 9)))
8437 (insert " ")
8438 (setq beg (point)
52a244eb 8439 ;; Relevant keywords already have link property attached
f32b3b91 8440 props (list 'mouse-face 'highlight
15e42531 8441 km-prop idlwave-rinfo-mouse-map
f32b3b91 8442 'data (cons 'keyword data)
15e42531 8443 'help-echo help-echo-kwd
f32b3b91 8444 'keyword (car x)))
52a244eb 8445 (if system (setq props (append (list 'face face) props)))
f32b3b91
CD
8446 (insert (car x))
8447 (add-text-properties beg (point) props)
8448 (setq col (+ col 1 (length (car x)))))
8449 keywords))
f66f03de 8450
15e42531 8451 (setq cnt 1 total (length all))
52a244eb 8452 ;; Here entry is (key file (list of type-conses))
15e42531
CD
8453 (while (setq entry (pop all))
8454 (setq props (list 'mouse-face 'highlight
8455 km-prop idlwave-rinfo-mouse-map
8456 'help-echo help-echo-src
52a244eb
S
8457 'source (list (car (car (nth 2 entry))) ;type
8458 (nth 1 entry)
8459 nil
8460 (cdr (car (nth 2 entry))))
15e42531
CD
8461 'data (cons 'source data)))
8462 (idlwave-insert-source-location
f66f03de 8463 (format "\n%-8s %s"
15e42531
CD
8464 (if (equal cnt 1)
8465 (if (> total 1) "Sources:" "Source:")
8466 "")
8467 (if (> total 1) "- " ""))
8468 entry props)
8469 (incf cnt)
8470 (when (and all (> cnt idlwave-rinfo-max-source-lines))
8471 ;; No more source lines, please
f66f03de 8472 (insert (format
15e42531
CD
8473 "\n Source information truncated to %d entries."
8474 idlwave-rinfo-max-source-lines))
8475 (setq all nil)))
10c8e594 8476 (goto-char (point-min))
f32b3b91
CD
8477 (setq buffer-read-only t))
8478 (display-buffer "*Help*")
8479 (if (and (setq win (get-buffer-window "*Help*"))
8480 idlwave-resize-routine-help-window)
8481 (progn
8482 (let ((ww (selected-window)))
8483 (unwind-protect
8484 (progn
8485 (select-window win)
f66f03de 8486 (enlarge-window (- (/ (frame-height) 2)
f32b3b91
CD
8487 (window-height)))
8488 (shrink-window-if-larger-than-buffer))
8489 (select-window ww)))))))))
8490
15e42531
CD
8491(defun idlwave-insert-source-location (prefix entry &optional file-props)
8492 "Insert a source location into the routine info buffer.
52a244eb
S
8493Start line with PREFIX. If a file name is inserted, add FILE-PROPS to
8494it."
15e42531
CD
8495 (let* ((key (car entry))
8496 (file (nth 1 entry))
8497 (types (nth 2 entry))
52a244eb
S
8498 (shell-flag (assq 'compiled types))
8499 (buffer-flag (assq 'buffer types))
8500 (user-flag (assq 'user types))
8501 (lib-flag (assq 'lib types))
8502 (ndupl (or (and buffer-flag (idlwave-count-memq 'buffer types))
8503 (and user-flag (idlwave-count-memq 'user types))
8504 (and lib-flag (idlwave-count-memq 'lib types))
15e42531
CD
8505 1))
8506 (doflags t)
8507 beg special)
8508
8509 (insert prefix)
8510
8511 (cond
8512 ((eq key 'system)
8513 (setq doflags nil)
52a244eb
S
8514 (insert "System "))
8515
15e42531
CD
8516 ((eq key 'builtin)
8517 (setq doflags nil)
52a244eb
S
8518 (insert "Builtin "))
8519
15e42531 8520 ((and (not file) shell-flag)
52a244eb
S
8521 (insert "Unresolved"))
8522
f66f03de 8523 ((null file)
52a244eb 8524 (insert "ERROR"))
f66f03de 8525
15e42531
CD
8526 ((idlwave-syslib-p file)
8527 (if (string-match "obsolete" (file-name-directory file))
52a244eb
S
8528 (insert "Obsolete ")
8529 (insert "SystemLib ")))
8530
8531 ;; New special syntax: taken directly from routine-info for
8532 ;; library catalog routines
8533 ((setq special (or (cdr lib-flag) (cdr user-flag)))
8534 (insert (format "%-10s" special)))
8535
8536 ;; Old special syntax: a matching regexp
8537 ((setq special (idlwave-special-lib-test file))
8538 (insert (format "%-10s" special)))
f66f03de 8539
52a244eb 8540 ;; Catch-all with file
15e42531 8541 ((idlwave-lib-p file) (insert "Library "))
52a244eb
S
8542
8543 ;; Sanity catch all
15e42531
CD
8544 (t (insert "Other ")))
8545
8546 (when doflags
8547 (insert (concat
8548 " ["
52a244eb
S
8549 (if lib-flag "L" "-")
8550 (if user-flag "C" "-")
15e42531
CD
8551 (if shell-flag "S" "-")
8552 (if buffer-flag "B" "-")
8553 "] ")))
f66f03de 8554 (when (> ndupl 1)
15e42531
CD
8555 (setq beg (point))
8556 (insert (format "(%dx) " ndupl))
8557 (add-text-properties beg (point) (list 'face 'bold)))
8558 (when (and file (not (equal file "")))
8559 (setq beg (point))
8560 (insert (apply 'abbreviate-file-name
8561 (if (featurep 'xemacs) (list file t) (list file))))
8562 (if file-props
8563 (add-text-properties beg (point) file-props)))))
8564
8565(defun idlwave-special-lib-test (file)
8566 "Check the path of FILE against the regexps which define special libs.
8567Return the name of the special lib if there is a match."
8568 (let ((alist idlwave-special-lib-alist)
8569 entry rtn)
8570 (cond
8571 ((stringp file)
8572 (while (setq entry (pop alist))
8573 (if (string-match (car entry) file)
8574 (setq rtn (cdr entry)
8575 alist nil)))
8576 rtn)
8577 (t nil))))
f66f03de 8578
f32b3b91
CD
8579(defun idlwave-mouse-active-rinfo-right (ev)
8580 (interactive "e")
8581 (idlwave-mouse-active-rinfo ev 'right))
8582
15e42531 8583(defun idlwave-mouse-active-rinfo-shift (ev)
f32b3b91 8584 (interactive "e")
15e42531
CD
8585 (idlwave-mouse-active-rinfo ev nil 'shift))
8586
8587(defun idlwave-active-rinfo-space ()
8588 (interactive)
8589 (idlwave-mouse-active-rinfo nil 'right))
8590
8591(defun idlwave-mouse-active-rinfo (ev &optional right shift)
8592 "Does the mouse actions in the routine info buffer.
8593Optional args RIGHT and SHIFT indicate, if mouse-3 was used, and if SHIFT
8594was pressed."
8595 (interactive "e")
8596 (if ev (mouse-set-point ev))
f66f03de 8597 (let (data id name type class buf bufwin source link keyword
3938cb82 8598 word initial-class)
f32b3b91 8599 (setq data (get-text-property (point) 'data)
15e42531 8600 source (get-text-property (point) 'source)
f32b3b91 8601 keyword (get-text-property (point) 'keyword)
52a244eb 8602 link (get-text-property (point) 'link)
f32b3b91 8603 id (car data)
15e42531 8604 name (nth 1 data) type (nth 2 data) class (nth 3 data)
f32b3b91 8605 buf (nth 4 data)
05a1abfc
CD
8606 initial-class (nth 6 data)
8607 word (idlwave-this-word)
f32b3b91 8608 bufwin (get-buffer-window buf t))
52a244eb
S
8609
8610 (cond ((eq id 'class) ; Switch class being displayed
05a1abfc 8611 (if (window-live-p bufwin) (select-window bufwin))
f66f03de 8612 (idlwave-display-calling-sequence
05a1abfc 8613 (idlwave-sintern-method name)
f66f03de 8614 type (idlwave-sintern-class word)
05a1abfc 8615 initial-class))
52a244eb
S
8616 ((eq id 'usage) ; Online help on this routine
8617 (idlwave-online-help link name type class))
8618 ((eq id 'source) ; Source in help or buffer
8619 (if right ; In help
15e42531
CD
8620 (let ((idlwave-extra-help-function 'idlwave-help-with-source)
8621 (idlwave-help-source-try-header nil)
52a244eb 8622 ;; Fake idlwave-routines so help will find the right entry
15e42531 8623 (idlwave-routines
52a244eb 8624 (list (list name type class source ""))))
15e42531 8625 (idlwave-help-get-special-help name type class nil))
52a244eb 8626 ;; Otherwise just pop to the source
f32b3b91
CD
8627 (setq idlwave-popup-source (not idlwave-popup-source))
8628 (if idlwave-popup-source
8629 (condition-case err
15e42531 8630 (idlwave-do-find-module name type class source)
f32b3b91
CD
8631 (error
8632 (setq idlwave-popup-source nil)
8633 (if (window-live-p bufwin) (select-window bufwin))
8634 (error (nth 1 err))))
8635 (if bufwin
8636 (select-window bufwin)
15e42531
CD
8637 (pop-to-buffer buf))
8638 (goto-char (marker-position idlwave-rinfo-marker)))))
f32b3b91
CD
8639 ((eq id 'keyword)
8640 (if right
52a244eb 8641 (idlwave-online-help link name type class keyword)
15e42531
CD
8642 (idlwave-rinfo-insert-keyword keyword buf shift))))))
8643
8644(defun idlwave-rinfo-insert-keyword (keyword buffer &optional shift)
8645 "Insert KEYWORD in BUFFER. Make sure buffer is displayed in a window."
8646 (let ((bwin (get-buffer-window buffer)))
8647 (if idlwave-complete-empty-string-as-lower-case
8648 (setq keyword (downcase keyword)))
8649 (if bwin
8650 (select-window bwin)
8651 (pop-to-buffer buffer)
8652 (setq bwin (get-buffer-window buffer)))
8653 (if (eq (preceding-char) ?/)
8654 (insert keyword)
f66f03de 8655 (unless (save-excursion
15e42531 8656 (re-search-backward
f66f03de 8657 "[(,][ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\)?[ \t]*\\="
15e42531
CD
8658 (min (- (point) 100) (point-min)) t))
8659 (insert ", "))
8660 (if shift (insert "/"))
8661 (insert keyword)
8662 (if (and (not shift)
8663 idlwave-keyword-completion-adds-equal)
8664 (insert "=")))))
8665
8666(defun idlwave-list-buffer-load-path-shadows (&optional arg)
8667 "List the load path shadows of all routines defined in current buffer."
8668 (interactive "P")
8669 (idlwave-routines)
8670 (if (eq major-mode 'idlwave-mode)
8671 (idlwave-list-load-path-shadows
8672 nil (idlwave-update-current-buffer-info 'save-buffer)
8673 "in current buffer")
8674 (error "Current buffer is not in idlwave-mode")))
8675
8676(defun idlwave-list-shell-load-path-shadows (&optional arg)
8677 "List the load path shadows of all routines compiled under the shell.
8678This is very useful for checking an IDL application. Just compile the
8679application, do RESOLVE_ALL, and `C-c C-i' to compile all referenced
8680routines and update IDLWAVE internal info. Then check for shadowing
8681with this command."
8682 (interactive "P")
8683 (cond
8684 ((or (not (fboundp 'idlwave-shell-is-running))
8685 (not (idlwave-shell-is-running)))
8686 (error "Shell is not running"))
8687 ((null idlwave-compiled-routines)
e8af40ee 8688 (error "No compiled routines. Maybe you need to update with `C-c C-i'"))
15e42531
CD
8689 (t
8690 (idlwave-list-load-path-shadows nil idlwave-compiled-routines
8691 "in the shell"))))
8692
8693(defun idlwave-list-all-load-path-shadows (&optional arg)
8694 "List the load path shadows of all routines known to IDLWAVE."
8695 (interactive "P")
8696 (idlwave-list-load-path-shadows nil nil "globally"))
8697
8698(defun idlwave-list-load-path-shadows (arg &optional special-routines loc)
8699 "List the routines which are defined multiple times.
8700Search the information IDLWAVE has about IDL routines for multiple
8701definitions.
8702When SPECIAL-ROUTINES in non-nil, only look for shadows of these routines.
8703
8704When IDL hits a routine call which is not defined, it will search on
8705the load path in order to find a definition. The output of this
8706command can be used to detect possible name clashes during this process."
8707 (idlwave-routines) ; Make sure everything is loaded.
52a244eb 8708 (unless (or idlwave-user-catalog-routines idlwave-library-catalog-routines)
f66f03de 8709 (or (y-or-n-p
52a244eb 8710 "You don't have any user or library catalogs. Continue anyway? ")
15e42531
CD
8711 (error "Abort")))
8712 (let* ((routines (append idlwave-system-routines
8713 idlwave-compiled-routines
52a244eb
S
8714 idlwave-library-catalog-routines
8715 idlwave-user-catalog-routines
15e42531
CD
8716 idlwave-buffer-routines
8717 nil))
8718 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
8719 (keymap (make-sparse-keymap))
8720 (props (list 'mouse-face 'highlight
8721 km-prop keymap
f66f03de 8722 'help-echo "Mouse2: Find source"))
15e42531 8723 (nroutines (length (or special-routines routines)))
f66f03de 8724 (step (/ nroutines 100))
15e42531 8725 (n 0)
15e42531
CD
8726 (cnt 0)
8727 (idlwave-sort-prefer-buffer-info nil)
8728 routine twins dtwins twin done props1 lroutines)
8729
8730 (if special-routines
8731 ;; Just looking for shadows of a few special routines
8732 (setq lroutines routines
8733 routines special-routines))
8734
8735 (message "Sorting routines...")
8736 (setq routines (sort routines
8737 (lambda (a b)
8738 (string< (downcase (idlwave-make-full-name
8739 (nth 2 a) (car a)))
8740 (downcase (idlwave-make-full-name
8741 (nth 2 b) (car b)))))))
8742 (message "Sorting routines...done")
8743
8744 (define-key keymap (if (featurep 'xemacs) [(button2)] [(mouse-2)])
f66f03de 8745 (lambda (ev)
15e42531
CD
8746 (interactive "e")
8747 (mouse-set-point ev)
8748 (apply 'idlwave-do-find-module
8749 (get-text-property (point) 'find-args))))
8750 (define-key keymap [(return)]
f66f03de 8751 (lambda ()
15e42531
CD
8752 (interactive)
8753 (apply 'idlwave-do-find-module
8754 (get-text-property (point) 'find-args))))
8755 (message "Compiling list...( 0%%)")
8756 (save-excursion
8757 (set-buffer (get-buffer-create "*Shadows*"))
8758 (setq buffer-read-only nil)
8759 (erase-buffer)
8760 (while (setq routine (pop routines))
f66f03de
S
8761 (if (= (mod (setq n (1+ n)) step) 0)
8762 (message "Compiling list...(%2d%%)" (/ (* n 100) nroutines)))
8763
15e42531
CD
8764 ;; Get a list of all twins
8765 (setq twins (idlwave-routine-twins routine (or lroutines routines)))
8766 (if (memq routine done)
8767 (setq dtwins nil)
8768 (setq dtwins (idlwave-study-twins twins)))
5e72c6b2 8769 ;; Mark all twins as dealt with
15e42531
CD
8770 (setq done (append twins done))
8771 (when (or (> (length dtwins) 1)
52a244eb
S
8772 (> (idlwave-count-memq 'lib (nth 2 (car dtwins))) 1)
8773 (> (idlwave-count-memq 'user (nth 2 (car dtwins))) 1)
8774 (> (idlwave-count-memq 'buffer (nth 2 (car dtwins))) 1))
15e42531
CD
8775 (incf cnt)
8776 (insert (format "\n%s%s"
f66f03de 8777 (idlwave-make-full-name (nth 2 routine)
52a244eb 8778 (car routine))
15e42531
CD
8779 (if (eq (nth 1 routine) 'fun) "()" "")))
8780 (while (setq twin (pop dtwins))
8781 (setq props1 (append (list 'find-args
f66f03de
S
8782 (list (nth 0 routine)
8783 (nth 1 routine)
52a244eb 8784 (nth 2 routine)))
15e42531
CD
8785 props))
8786 (idlwave-insert-source-location "\n - " twin props1))))
8787 (goto-char (point-min))
8788 (setq buffer-read-only t))
8789 (setq loc (or loc ""))
8790 (if (> cnt 0)
8791 (progn
8792 (display-buffer (get-buffer "*Shadows*"))
8793 (message "%d case%s of shadowing found %s"
8794 cnt (if (= cnt 1) "" "s") loc))
8795 (message "No shadowing conflicts found %s" loc))))
8796
8797(defun idlwave-print-source (routine)
8798 (let* ((source (nth 3 routine))
8799 (stype (car source))
52a244eb
S
8800 (sfile (idlwave-routine-source-file source)))
8801 (if (idlwave-syslib-p sfile) (setq stype 'syslib))
15e42531
CD
8802 (if (and (eq stype 'compiled)
8803 (or (not (stringp sfile))
8804 (not (string-match "\\S-" sfile))))
8805 (setq stype 'unresolved))
f66f03de 8806 (princ (format " %-10s %s\n"
15e42531
CD
8807 stype
8808 (if sfile sfile "No source code available")))))
8809
8810(defun idlwave-routine-twins (entry &optional list)
8811 "Return all twin entries of ENTRY in LIST.
8812LIST defaults to `idlwave-routines'.
8813Twin entries are those which have the same name, type, and class.
8814ENTRY will also be returned, as the first item of this list."
8815 (let* ((name (car entry))
8816 (type (nth 1 entry))
8817 (class (nth 2 entry))
8818 (candidates (idlwave-all-assq name (or list (idlwave-routines))))
8819 twins candidate)
8820 (while (setq candidate (pop candidates))
8821 (if (and (not (eq candidate entry))
8822 (eq type (nth 1 candidate))
8823 (eq class (nth 2 candidate)))
8824 (push candidate twins)))
f66f03de 8825 (if (setq candidate (idlwave-rinfo-assq name type class
15e42531
CD
8826 idlwave-unresolved-routines))
8827 (push candidate twins))
8828 (cons entry (nreverse twins))))
8829
8830(defun idlwave-study-twins (entries)
f66f03de 8831 "Return dangerous twins of first entry in ENTRIES.
52a244eb
S
8832Dangerous twins are routines with same name, but in different files on
8833the load path. If a file is in the system library and has an entry in
8834the `idlwave-system-routines' list, we omit the latter as
8835non-dangerous because many IDL routines are implemented as library
8836routines, and may have been scanned."
15e42531 8837 (let* ((entry (car entries))
f66f03de 8838 (name (car entry)) ;
15e42531
CD
8839 (type (nth 1 entry)) ; Must be bound for
8840 (class (nth 2 entry)) ; idlwave-routine-twin-compare
8841 (cnt 0)
52a244eb 8842 source type type-cons file alist syslibp key)
15e42531
CD
8843 (while (setq entry (pop entries))
8844 (incf cnt)
8845 (setq source (nth 3 entry)
8846 type (car source)
52a244eb
S
8847 type-cons (cons type (nth 3 source))
8848 file (idlwave-routine-source-file source))
8849
15e42531
CD
8850 ;; Make KEY to index entry properly
8851 (setq key (cond ((eq type 'system) type)
8852 (file (file-truename file))
8853 (t 'unresolved)))
52a244eb
S
8854
8855 ;; Check for an entry in the system library
f66f03de 8856 (if (and file
15e42531
CD
8857 (not syslibp)
8858 (idlwave-syslib-p file))
15e42531 8859 (setq syslibp t))
f66f03de 8860
52a244eb
S
8861 ;; If there's more than one matching entry for the same file, just
8862 ;; append the type-cons to the type list.
15e42531 8863 (if (setq entry (assoc key alist))
52a244eb
S
8864 (push type-cons (nth 2 entry))
8865 (push (list key file (list type-cons)) alist)))
f66f03de 8866
15e42531 8867 (setq alist (nreverse alist))
f66f03de 8868
15e42531 8869 (when syslibp
52a244eb
S
8870 ;; File is in system *library* - remove any 'system entry
8871 (setq alist (delq (assq 'system alist) alist)))
f66f03de 8872
52a244eb
S
8873 ;; If 'system remains and we've scanned the syslib, it's a builtin
8874 ;; (rather than a !DIR/lib/.pro file bundled as source).
15e42531
CD
8875 (when (and (idlwave-syslib-scanned-p)
8876 (setq entry (assoc 'system alist)))
8877 (setcar entry 'builtin))
8878 (sort alist 'idlwave-routine-twin-compare)))
8879
15e42531
CD
8880(defvar type)
8881(defvar class)
8882(defvar idlwave-sort-prefer-buffer-info t
8883 "Internal variable used to influence `idlwave-routine-twin-compare'.")
8884
8885(defmacro idlwave-xor (a b)
8886 `(and (or ,a ,b)
8887 (not (and ,a ,b))))
8888
8889(defun idlwave-routine-entry-compare (a b)
8890 "Compare two routine info entries for sortiung. This is the general case.
8891It first compates class, names, and type. If it turns out that A and B
cef6cafe 8892are twins (same name, class, and type), calls another routine which
15e42531
CD
8893compares twins on the basis of their file names and path locations."
8894 (let ((name (car a)) (type (nth 1 a)) (class (nth 2 a)))
8895 (cond
8896 ((not (equal (idlwave-downcase-safe class)
8897 (idlwave-downcase-safe (nth 2 b))))
8898 ;; Class decides
8899 (cond ((null (nth 2 b)) nil)
8900 ((null class) t)
8901 (t (string< (downcase class) (downcase (nth 2 b))))))
8902 ((not (equal (downcase name) (downcase (car b))))
8903 ;; Name decides
8904 (string< (downcase name) (downcase (car b))))
8905 ((not (eq type (nth 1 b)))
8906 ;; Type decides
8907 (< (if (eq type 'fun) 1 0) (if (eq (nth 1 b) 'fun) 1 0)))
f66f03de 8908 (t
15e42531
CD
8909 ;; A and B are twins - so the decision is more complicated.
8910 ;; Call twin-compare with the proper arguments.
8911 (idlwave-routine-entry-compare-twins a b)))))
8912
8913(defun idlwave-routine-entry-compare-twins (a b)
52a244eb
S
8914 "Compare two routine entries, under the assumption that they are
8915twins. This basically calls `idlwave-routine-twin-compare' with the
8916correct args."
8917 (let* ((name (car a)) (type (nth 1 a)) (class (nth 2 a)) ; needed outside
8918 (asrc (nth 3 a))
8919 (atype (car asrc))
8920 (bsrc (nth 3 b))
8921 (btype (car bsrc))
8922 (afile (idlwave-routine-source-file asrc))
8923 (bfile (idlwave-routine-source-file bsrc)))
15e42531
CD
8924 (idlwave-routine-twin-compare
8925 (if (stringp afile)
8926 (list (file-truename afile) afile (list atype))
8927 (list atype afile (list atype)))
8928 (if (stringp bfile)
8929 (list (file-truename bfile) bfile (list btype))
8930 (list btype bfile (list btype))))
8931 ))
8932
8933(defun idlwave-routine-twin-compare (a b)
8934 "Compare two routine twin entries for sorting.
8935In here, A and B are not normal routine info entries, but special
8936lists (KEY FILENAME (TYPES...)).
8937This expects NAME TYPE CLASS to be bound to the right values."
8938 (let* (;; Dis-assemble entries
8939 (akey (car a)) (bkey (car b))
8940 (afile (nth 1 a)) (bfile (nth 1 b))
8941 (atypes (nth 2 a)) (btypes (nth 2 b))
8942 ;; System routines?
8943 (asysp (memq akey '(builtin system)))
8944 (bsysp (memq bkey '(builtin system)))
8945 ;; Compiled routines?
8946 (acompp (memq 'compiled atypes))
8947 (bcompp (memq 'compiled btypes))
8948 ;; Unresolved?
8949 (aunresp (or (eq akey 'unresolved)
8950 (and acompp (not afile))))
8951 (bunresp (or (eq bkey 'unresolved)
8952 (and bcompp (not bfile))))
8953 ;; Buffer info available?
8954 (abufp (memq 'buffer atypes))
8955 (bbufp (memq 'buffer btypes))
8956 ;; On search path?
8957 (tpath-alist (idlwave-true-path-alist))
52a244eb
S
8958 (apathp (and (stringp akey)
8959 (assoc (file-name-directory akey) tpath-alist)))
f66f03de 8960 (bpathp (and (stringp bkey)
52a244eb 8961 (assoc (file-name-directory bkey) tpath-alist)))
15e42531
CD
8962 ;; How early on search path? High number means early since we
8963 ;; measure the tail of the path list
8964 (anpath (length (memq apathp tpath-alist)))
8965 (bnpath (length (memq bpathp tpath-alist)))
8966 ;; Look at file names
8967 (aname (if (stringp afile) (downcase (file-name-nondirectory afile)) ""))
8968 (bname (if (stringp bfile) (downcase (file-name-nondirectory bfile)) ""))
8969 (fname-re (if class (format "\\`%s__\\(%s\\|define\\)\\.pro\\'"
8970 (regexp-quote (downcase class))
8971 (regexp-quote (downcase name)))
8972 (format "\\`%s\\.pro" (regexp-quote (downcase name)))))
8973 ;; Is file name derived from the routine name?
8974 ;; Method file or class definition file?
8975 (anamep (string-match fname-re aname))
8976 (adefp (and class anamep (string= "define" (match-string 1 aname))))
8977 (bnamep (string-match fname-re bname))
8978 (bdefp (and class bnamep (string= "define" (match-string 1 bname)))))
8979
8980 ;; Now: follow JD's ideas about sorting. Looks really simple now,
8981 ;; doesn't it? The difficult stuff is hidden above...
8982 (cond
8983 ((idlwave-xor asysp bsysp) asysp) ; System entries first
8984 ((idlwave-xor aunresp bunresp) bunresp) ; Unresolved last
8985 ((and idlwave-sort-prefer-buffer-info
8986 (idlwave-xor abufp bbufp)) abufp) ; Buffers before non-buffers
8987 ((idlwave-xor acompp bcompp) acompp) ; Compiled entries
8988 ((idlwave-xor apathp bpathp) apathp) ; Library before non-library
8989 ((idlwave-xor anamep bnamep) anamep) ; Correct file names first
8990 ((and class anamep bnamep ; both file names match ->
8991 (idlwave-xor adefp bdefp)) bdefp) ; __define after __method
8992 ((> anpath bnpath) t) ; Who is first on path?
8993 (t nil)))) ; Default
8994
52a244eb 8995(defun idlwave-routine-source-file (source)
f66f03de 8996 (if (nth 2 source)
52a244eb
S
8997 (expand-file-name (nth 1 source) (nth 2 source))
8998 (nth 1 source)))
8999
15e42531
CD
9000(defun idlwave-downcase-safe (string)
9001 "Donwcase if string, else return unchanged."
9002 (if (stringp string)
9003 (downcase string)
9004 string))
9005
9006(defun idlwave-count-eq (elt list)
9007 "How often is ELT in LIST?"
9008 (length (delq nil (mapcar (lambda (x) (eq x elt)) list))))
9009
52a244eb
S
9010(defun idlwave-count-memq (elt alist)
9011 "How often is ELT a key in ALIST?"
9012 (length (delq nil (mapcar (lambda (x) (eq (car x) elt)) alist))))
9013
15e42531 9014(defun idlwave-syslib-p (file)
52a244eb 9015 "Non-nil if FILE is in the system library."
15e42531
CD
9016 (let* ((true-syslib (file-name-as-directory
9017 (file-truename
9018 (expand-file-name "lib" (idlwave-sys-dir)))))
9019 (true-file (file-truename file)))
9020 (string-match (concat "^" (regexp-quote true-syslib)) true-file)))
9021
9022(defun idlwave-lib-p (file)
9023 "Non-nil if file is in the library"
9024 (let ((true-dir (file-name-directory (file-truename file))))
9025 (assoc true-dir (idlwave-true-path-alist))))
9026
52a244eb
S
9027(defun idlwave-path-alist-add-flag (list-entry flag)
9028 "Add a flag to the path list entry, if not set."
9029 (let ((flags (cdr list-entry)))
9030 (add-to-list 'flags flag)
9031 (setcdr list-entry flags)))
9032
9033(defun idlwave-path-alist-remove-flag (list-entry flag)
9034 "Remove a flag to the path list entry, if set."
9035 (let ((flags (delq flag (cdr list-entry))))
9036 (setcdr list-entry flags)))
9037
15e42531
CD
9038(defun idlwave-true-path-alist ()
9039 "Return `idlwave-path-alist' alist with true-names.
52a244eb 9040Info is cached, but relies on the functions setting `idlwave-path-alist'
15e42531
CD
9041to reset the variable `idlwave-true-path-alist' to nil."
9042 (or idlwave-true-path-alist
9043 (setq idlwave-true-path-alist
9044 (mapcar (lambda(x) (cons
9045 (file-name-as-directory
9046 (file-truename
9047 (directory-file-name
9048 (car x))))
9049 (cdr x)))
9050 idlwave-path-alist))))
9051
9052(defun idlwave-syslib-scanned-p ()
9053 "Non-nil if the system lib file !DIR/lib has been scanned."
9054 (let* ((true-syslib (file-name-as-directory
9055 (file-truename
9056 (expand-file-name "lib" (idlwave-sys-dir))))))
9057 (cdr (assoc true-syslib (idlwave-true-path-alist)))))
9058
9059;; ----------------------------------------------------------------------------
9060;;
9061;; Online Help display
9062
f32b3b91
CD
9063
9064;; ----------------------------------------------------------------------------
9065;;
9066;; Additions for use with imenu.el and func-menu.el
9067;; (pop-up a list of IDL units in the current file).
9068;;
9069
9070(defun idlwave-prev-index-position ()
9071 "Search for the previous procedure or function.
9072Return nil if not found. For use with imenu.el."
9073 (save-match-data
9074 (cond
9075 ((idlwave-find-key "\\<\\(pro\\|function\\)\\>" -1 'nomark))
9076 ;; ((idlwave-find-key idlwave-begin-unit-reg 1 'nomark)
9077 (t nil))))
9078
9079(defun idlwave-unit-name ()
9080 "Return the unit name.
9081Assumes that point is at the beginning of the unit as found by
9082`idlwave-prev-index-position'."
9083 (forward-sexp 2)
9084 (forward-sexp -1)
9085 (let ((begin (point)))
f66f03de 9086 (re-search-forward
52a244eb 9087 "[a-zA-Z_][a-zA-Z0-9$_]+\\(::[a-zA-Z_][a-zA-Z0-9$_]+\\)?")
f32b3b91
CD
9088 (if (fboundp 'buffer-substring-no-properties)
9089 (buffer-substring-no-properties begin (point))
9090 (buffer-substring begin (point)))))
9091
facebc7b
S
9092(defalias 'idlwave-function-menu
9093 (condition-case nil
f32b3b91
CD
9094 (progn
9095 (require 'func-menu)
facebc7b
S
9096 'function-menu)
9097 (error (condition-case nil
9098 (progn
9099 (require 'imenu)
9100 'imenu)
9101 (error nil)))))
f32b3b91 9102
52a244eb 9103;; Here we hack func-menu.el in order to support this new mode.
f32b3b91
CD
9104;; The latest versions of func-menu.el already have this stuff in, so
9105;; we hack only if it is not already there.
9106(when (fboundp 'eval-after-load)
9107 (eval-after-load "func-menu"
9108 '(progn
9109 (or (assq 'idlwave-mode fume-function-name-regexp-alist)
9110 (not (boundp 'fume-function-name-regexp-idl)) ; avoid problems
9111 (setq fume-function-name-regexp-alist
9112 (cons '(idlwave-mode . fume-function-name-regexp-idl)
9113 fume-function-name-regexp-alist)))
9114 (or (assq 'idlwave-mode fume-find-function-name-method-alist)
9115 (not (fboundp 'fume-find-next-idl-function-name)) ; avoid problems
9116 (setq fume-find-function-name-method-alist
9117 (cons '(idlwave-mode . fume-find-next-idl-function-name)
9118 fume-find-function-name-method-alist))))))
9119
9120(defun idlwave-edit-in-idlde ()
9121 "Edit the current file in IDL Development environment."
9122 (interactive)
9123 (start-process "idldeclient" nil
9124 idlwave-shell-explicit-file-name "-c" "-e"
f66f03de
S
9125 (buffer-file-name)))
9126
9127(defvar idlwave-help-use-assistant)
f32b3b91
CD
9128(defun idlwave-launch-idlhelp ()
9129 "Start the IDLhelp application."
9130 (interactive)
f66f03de
S
9131 (if idlwave-help-use-assistant
9132 (idlwave-help-assistant-raise)
9133 (start-process "idlhelp" nil idlwave-help-application)))
9134
f32b3b91
CD
9135;; Menus - using easymenu.el
9136(defvar idlwave-mode-menu-def
9137 `("IDLWAVE"
9138 ["PRO/FUNC menu" idlwave-function-menu t]
9139 ("Motion"
9140 ["Subprogram Start" idlwave-beginning-of-subprogram t]
9141 ["Subprogram End" idlwave-end-of-subprogram t]
9142 ["Block Start" idlwave-beginning-of-block t]
9143 ["Block End" idlwave-end-of-block t]
9144 ["Up Block" idlwave-backward-up-block t]
9145 ["Down Block" idlwave-down-block t]
9146 ["Skip Block Backward" idlwave-backward-block t]
9147 ["Skip Block Forward" idlwave-forward-block t])
9148 ("Mark"
9149 ["Subprogram" idlwave-mark-subprogram t]
9150 ["Block" idlwave-mark-block t]
9151 ["Header" idlwave-mark-doclib t])
9152 ("Format"
f66f03de
S
9153 ["Indent Entire Statement" idlwave-indent-statement
9154 :active t :keys "C-u \\[indent-for-tab-command]" ]
f32b3b91 9155 ["Indent Subprogram" idlwave-indent-subprogram t]
f66f03de 9156 ["(Un)Comment Region" idlwave-toggle-comment-region t]
f32b3b91
CD
9157 ["Continue/Split line" idlwave-split-line t]
9158 "--"
9159 ["Toggle Auto Fill" idlwave-auto-fill-mode :style toggle
9160 :selected (symbol-value idlwave-fill-function)])
9161 ("Templates"
9162 ["Procedure" idlwave-procedure t]
9163 ["Function" idlwave-function t]
9164 ["Doc Header" idlwave-doc-header t]
9165 ["Log" idlwave-doc-modification t]
9166 "--"
9167 ["Case" idlwave-case t]
9168 ["For" idlwave-for t]
9169 ["Repeat" idlwave-repeat t]
9170 ["While" idlwave-while t]
9171 "--"
9172 ["Close Block" idlwave-close-block t])
15e42531 9173 ("Completion"
f32b3b91 9174 ["Complete" idlwave-complete t]
f66f03de 9175 ("Complete Specific"
f32b3b91
CD
9176 ["1 Procedure Name" (idlwave-complete 'procedure) t]
9177 ["2 Procedure Keyword" (idlwave-complete 'procedure-keyword) t]
9178 "--"
9179 ["3 Function Name" (idlwave-complete 'function) t]
9180 ["4 Function Keyword" (idlwave-complete 'function-keyword) t]
9181 "--"
9182 ["5 Procedure Method Name" (idlwave-complete 'procedure-method) t]
9183 ["6 Procedure Method Keyword" (idlwave-complete 'procedure-method-keyword) t]
9184 "--"
9185 ["7 Function Method Name" (idlwave-complete 'function-method) t]
9186 ["8 Function Method Keyword" (idlwave-complete 'function-method-keyword) t]
9187 "--"
15e42531
CD
9188 ["9 Class Name" idlwave-complete-class t]))
9189 ("Routine Info"
f32b3b91 9190 ["Show Routine Info" idlwave-routine-info t]
52a244eb 9191 ["Online Context Help" idlwave-context-help t]
f32b3b91
CD
9192 "--"
9193 ["Find Routine Source" idlwave-find-module t]
15e42531 9194 ["Resolve Routine" idlwave-resolve (featurep 'idlw-shell)]
f32b3b91
CD
9195 "--"
9196 ["Update Routine Info" idlwave-update-routine-info t]
f66f03de 9197 ["Rescan XML Help Catalog" idlwave-convert-xml-system-routine-info t]
f32b3b91 9198 "--"
52a244eb
S
9199 "IDL User Catalog"
9200 ["Select Catalog Directories" (idlwave-create-user-catalog-file nil) t]
15e42531 9201 ["Scan Directories" (idlwave-update-routine-info '(16))
5e72c6b2
S
9202 (and idlwave-path-alist (not idlwave-catalog-process))]
9203 ["Scan Directories &" (idlwave-update-routine-info '(64))
9204 (and idlwave-path-alist (not idlwave-catalog-process))]
15e42531
CD
9205 "--"
9206 "Routine Shadows"
9207 ["Check Current Buffer" idlwave-list-buffer-load-path-shadows t]
9208 ["Check Compiled Routines" idlwave-list-shell-load-path-shadows t]
9209 ["Check Everything" idlwave-list-all-load-path-shadows t])
9210 ("Misc"
9211 ["Kill auto-created buffers" idlwave-kill-autoloaded-buffers t]
9212 "--"
9213 ["Insert TAB character" idlwave-hard-tab t])
f32b3b91
CD
9214 "--"
9215 ("External"
f32b3b91
CD
9216 ["Start IDL shell" idlwave-shell t]
9217 ["Edit file in IDLDE" idlwave-edit-in-idlde t]
9218 ["Launch IDL Help" idlwave-launch-idlhelp t])
9219 "--"
9220 ("Customize"
9221 ["Browse IDLWAVE Group" idlwave-customize t]
9222 "--"
f66f03de 9223 ["Build Full Customize Menu" idlwave-create-customize-menu
f32b3b91
CD
9224 (fboundp 'customize-menu-create)])
9225 ("Documentation"
9226 ["Describe Mode" describe-mode t]
9227 ["Abbreviation List" idlwave-list-abbrevs t]
9228 "--"
9229 ["Commentary in idlwave.el" idlwave-show-commentary t]
595ab50b 9230 ["Commentary in idlw-shell.el" idlwave-shell-show-commentary t]
f32b3b91
CD
9231 "--"
9232 ["Info" idlwave-info t]
9233 "--"
9234 ["Launch IDL Help" idlwave-launch-idlhelp t])))
9235
9236(defvar idlwave-mode-debug-menu-def
9237 '("Debug"
9238 ["Start IDL shell" idlwave-shell t]
9239 ["Save and .RUN buffer" idlwave-shell-save-and-run
f66f03de 9240 (and (boundp 'idlwave-shell-automatic-start)
f32b3b91
CD
9241 idlwave-shell-automatic-start)]))
9242
9243(if (or (featurep 'easymenu) (load "easymenu" t))
9244 (progn
f66f03de
S
9245 (easy-menu-define idlwave-mode-menu idlwave-mode-map
9246 "IDL and WAVE CL editing menu"
f32b3b91 9247 idlwave-mode-menu-def)
f66f03de
S
9248 (easy-menu-define idlwave-mode-debug-menu idlwave-mode-map
9249 "IDL and WAVE CL editing menu"
f32b3b91
CD
9250 idlwave-mode-debug-menu-def)))
9251
9252(defun idlwave-customize ()
9253 "Call the customize function with idlwave as argument."
9254 (interactive)
f66f03de 9255 ;; Try to load the code for the shell, so that we can customize it
f32b3b91 9256 ;; as well.
22d5821d
CD
9257 (or (featurep 'idlw-shell)
9258 (load "idlw-shell" t))
f32b3b91
CD
9259 (customize-browse 'idlwave))
9260
9261(defun idlwave-create-customize-menu ()
9262 "Create a full customization menu for IDLWAVE, insert it into the menu."
9263 (interactive)
9264 (if (fboundp 'customize-menu-create)
9265 (progn
f66f03de 9266 ;; Try to load the code for the shell, so that we can customize it
f32b3b91 9267 ;; as well.
22d5821d
CD
9268 (or (featurep 'idlw-shell)
9269 (load "idlw-shell" t))
f66f03de 9270 (easy-menu-change
f32b3b91
CD
9271 '("IDLWAVE") "Customize"
9272 `(["Browse IDLWAVE group" idlwave-customize t]
9273 "--"
9274 ,(customize-menu-create 'idlwave)
9275 ["Set" Custom-set t]
9276 ["Save" Custom-save t]
9277 ["Reset to Current" Custom-reset-current t]
9278 ["Reset to Saved" Custom-reset-saved t]
9279 ["Reset to Standard Settings" Custom-reset-standard t]))
9280 (message "\"IDLWAVE\"-menu now contains full customization menu"))
9281 (error "Cannot expand menu (outdated version of cus-edit.el)")))
9282
9283(defun idlwave-show-commentary ()
9284 "Use the finder to view the file documentation from `idlwave.el'."
9285 (interactive)
9286 (require 'finder)
9287 (finder-commentary "idlwave.el"))
9288
9289(defun idlwave-shell-show-commentary ()
595ab50b 9290 "Use the finder to view the file documentation from `idlw-shell.el'."
f32b3b91
CD
9291 (interactive)
9292 (require 'finder)
595ab50b 9293 (finder-commentary "idlw-shell.el"))
f32b3b91
CD
9294
9295(defun idlwave-info ()
9296 "Read documentation for IDLWAVE in the info system."
9297 (interactive)
9298 (require 'info)
9299 (Info-goto-node "(idlwave)"))
9300
9301(defun idlwave-list-abbrevs (arg)
9302 "Show the code abbreviations define in IDLWAVE mode.
9303This lists all abbrevs where the replacement text differs from the input text.
9304These are the ones the users want to learn to speed up their writing.
9305
9306The function does *not* list abbrevs which replace a word with itself
9307to call a hook. These hooks are used to change the case of words or
9308to blink the matching `begin', and the user does not need to know them.
9309
9310With arg, list all abbrevs with the corresponding hook.
9311
9312This function was written since `list-abbrevs' looks terrible for IDLWAVE mode."
9313
9314 (interactive "P")
9315 (let ((table (symbol-value 'idlwave-mode-abbrev-table))
9316 abbrevs
9317 str rpl func fmt (len-str 0) (len-rpl 0))
f66f03de 9318 (mapatoms
f32b3b91
CD
9319 (lambda (sym)
9320 (if (symbol-value sym)
9321 (progn
9322 (setq str (symbol-name sym)
9323 rpl (symbol-value sym)
9324 func (symbol-function sym))
9325 (if arg
9326 (setq func (prin1-to-string func))
9327 (if (and (listp func) (stringp (nth 2 func)))
9328 (setq rpl (concat "EVAL: " (nth 2 func))
9329 func "")
9330 (setq func "")))
9331 (if (or arg (not (string= rpl str)))
9332 (progn
9333 (setq len-str (max len-str (length str)))
9334 (setq len-rpl (max len-rpl (length rpl)))
9335 (setq abbrevs (cons (list str rpl func) abbrevs)))))))
9336 table)
9337 ;; sort the list
9338 (setq abbrevs (sort abbrevs (lambda (a b) (string< (car a) (car b)))))
9339 ;; Make the format
9340 (setq fmt (format "%%-%ds %%-%ds %%s\n" len-str len-rpl))
9341 (with-output-to-temp-buffer "*Help*"
9342 (if arg
9343 (progn
f66f03de 9344 (princ "Abbreviations and Actions in IDLWAVE-Mode\n")
f32b3b91
CD
9345 (princ "=========================================\n\n")
9346 (princ (format fmt "KEY" "REPLACE" "HOOK"))
9347 (princ (format fmt "---" "-------" "----")))
9348 (princ "Code Abbreviations and Templates in IDLWAVE-Mode\n")
9349 (princ "================================================\n\n")
9350 (princ (format fmt "KEY" "ACTION" ""))
9351 (princ (format fmt "---" "------" "")))
9352 (mapcar
9353 (lambda (list)
9354 (setq str (car list)
9355 rpl (nth 1 list)
9356 func (nth 2 list))
9357 (princ (format fmt str rpl func)))
9358 abbrevs)))
9359 ;; Make sure each abbreviation uses only one display line
9360 (save-excursion
9361 (set-buffer "*Help*")
9362 (setq truncate-lines t)))
9363
5e72c6b2
S
9364;; Add .pro files to speedbar for support, if it's loaded
9365(eval-after-load "speedbar" '(speedbar-add-supported-extension ".pro"))
9366
5e72c6b2
S
9367;; Set an idle timer to load the routine info.
9368;; Will only work on systems which support this.
9369(or idlwave-routines (idlwave-start-load-rinfo-timer))
9370
f66f03de 9371;;;###autoload (add-to-list 'auto-mode-alist '("\\.[Pp][Rr][Oo]\\'" . idlwave-mode))
52a244eb 9372
15e42531 9373;; Run the hook
f32b3b91
CD
9374(run-hooks 'idlwave-load-hook)
9375
9376(provide 'idlwave)
9377
8df608c1 9378;; arch-tag: f77f3b0c-c37c-424f-a328-0886fd42b6fb
f32b3b91 9379;;; idlwave.el ends here