]> code.delx.au - gnu-emacs/blob - lisp/progmodes/idlwave.el
(idlwave-max-extra-continuation-indent): Fix typo.
[gnu-emacs] / lisp / progmodes / idlwave.el
1 ;;; idlwave.el --- IDL and WAVE CL editing mode for GNU Emacs
2 ;; Copyright (c) 1999, 2000, 2001,2002 Free Software Foundation
3
4 ;; Author: Carsten Dominik <dominik@astro.uva.nl>
5 ;; Chris Chase <chase@att.com>
6 ;; Maintainer: J.D. Smith <jdsmith@as.arizona.edu>
7 ;; Version: 4.14
8 ;; Date: $Date: 2002/07/18 18:58:07 $
9 ;; Keywords: languages
10
11 ;; This file is part of GNU Emacs.
12
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; any later version.
17
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
27
28 ;;; Commentary:
29
30 ;; In distant past, based on pascal.el. Though bears little
31 ;; resemblance to that now.
32 ;;
33 ;; Incorporates many ideas, such as abbrevs, action routines, and
34 ;; continuation line indenting, from wave.el.
35 ;; wave.el original written by Lubos Pochman, Precision Visuals, Boulder.
36 ;;
37 ;; See the mode description ("C-h m" in idlwave-mode or "C-h f idlwave-mode")
38 ;; for features, key bindings, and info.
39 ;; Also, Info format documentation is available with `M-x idlwave-info'
40 ;;
41 ;; New versions of IDLWAVE, documentation, and more information
42 ;; available from:
43 ;; http://idlwave.org
44 ;;
45 ;; INSTALLATION
46 ;; ============
47 ;;
48 ;; Follow the instructions in the INSTALL file of the distribution.
49 ;; In short, put this file on your load path and add the following
50 ;; lines to your .emacs file:
51 ;;
52 ;; (autoload 'idlwave-mode "idlwave" "IDLWAVE Mode" t)
53 ;; (autoload 'idlwave-shell "idlw-shell" "IDLWAVE Shell" t)
54 ;; (setq auto-mode-alist (cons '("\\.pro\\'" . idlwave-mode) auto-mode-alist))
55 ;;
56 ;;
57 ;; SOURCE
58 ;; ======
59 ;;
60 ;; The newest version of this file is available from the maintainers
61 ;; Webpage.
62 ;;
63 ;; http://idlwave.org
64 ;;
65 ;; DOCUMENTATION
66 ;; =============
67 ;;
68 ;; IDLWAVE is documented online in info format.
69 ;; A printable version of the documentation is available from the
70 ;; maintainers webpage (see under SOURCE)
71 ;;
72 ;;
73 ;; ACKNOWLEDGMENTS
74 ;; ===============
75 ;;
76 ;; Thanks to the following people for their contributions and comments:
77 ;;
78 ;; Ulrik Dickow <dickow@nbi.dk>
79 ;; Eric E. Dors <edors@lanl.gov>
80 ;; Stein Vidar H. Haugan <s.v.h.haugan@astro.uio.no>
81 ;; David Huenemoerder <dph@space.mit.edu>
82 ;; Kevin Ivory <Kevin.Ivory@linmpi.mpg.de>
83 ;; Xuyong Liu <liu@stsci.edu>
84 ;; Simon Marshall <Simon.Marshall@esrin.esa.it>
85 ;; Laurent Mugnier <mugnier@onera.fr>
86 ;; Lubos Pochman <lubos@rsinc.com>
87 ;; Patrick M. Ryan <pat@jaameri.gsfc.nasa.gov>
88 ;; Marty Ryba <ryba@ll.mit.edu>
89 ;; Phil Williams <williams@irc.chmcc.org>
90 ;; J.D. Smith <jdsmith@astrosun.tn.cornell.edu>
91 ;; Phil Sterne <sterne@dublin.llnl.gov>
92 ;;
93 ;; CUSTOMIZATION:
94 ;; =============
95 ;;
96 ;; IDLWAVE has customize support - so if you want to learn about the
97 ;; variables which control the behavior of the mode, use
98 ;; `M-x idlwave-customize'.
99 ;;
100 ;; You can set your own preferred values with Customize, or with Lisp
101 ;; code in .emacs. For an example of what to put into .emacs, check
102 ;; the TexInfo documentation.
103 ;;
104 ;; KNOWN PROBLEMS:
105 ;; ==============
106 ;;
107 ;; Moving the point backwards in conjunction with abbrev expansion
108 ;; does not work as I would like it, but this is a problem with
109 ;; emacs abbrev expansion done by the self-insert-command. It ends
110 ;; up inserting the character that expanded the abbrev after moving
111 ;; point backward, e.g., "\cl" expanded with a space becomes
112 ;; "LONG( )" with point before the close paren. This is solved by
113 ;; using a temporary function in `post-command-hook' - not pretty,
114 ;; but it works.
115 ;;
116 ;; Tabs and spaces are treated equally as whitespace when filling a
117 ;; comment paragraph. To accomplish this, tabs are permanently
118 ;; replaced by spaces in the text surrounding the paragraph, which
119 ;; may be an undesirable side-effect. Replacing tabs with spaces is
120 ;; limited to comments only and occurs only when a comment
121 ;; paragraph is filled via `idlwave-fill-paragraph'.
122 ;;
123 ;; "&" is ignored when parsing statements.
124 ;; Avoid muti-statement lines (using "&") on block begin and end
125 ;; lines. Multi-statement lines can mess up the formatting, for
126 ;; example, multiple end statements on a line: endif & endif.
127 ;; Using "&" outside of block begin/end lines should be okay.
128 ;;
129 ;; It is possible that the parser which decides what to complete has
130 ;; problems with pointer dereferencing statements. I don't use
131 ;; pointers often enough to find out - please report any problems.
132 ;;
133 ;; When forcing completion of method keywords, the initial
134 ;; query for a method has multiple entries for some methods. Would
135 ;; be too difficult to fix this hardly used case.
136 ;;
137 \f
138 ;;; Code:
139
140 (eval-when-compile (require 'cl))
141
142 (eval-and-compile
143 ;; Kludge to allow `defcustom' for Emacs 19.
144 (condition-case () (require 'custom) (error nil))
145 (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
146 nil ;; We've got what we needed
147 ;; We have the old or no custom-library, hack around it!
148 (defmacro defgroup (&rest args) nil)
149 (defmacro defcustom (var value doc &rest args)
150 `(defvar ,var ,value ,doc))))
151
152 (defgroup idlwave nil
153 "Major mode for editing IDL .pro files"
154 :tag "IDLWAVE"
155 :link '(url-link :tag "Home Page"
156 "http://idlwave.org")
157 :link '(emacs-commentary-link :tag "Commentary in idlw-shell.el"
158 "idlw-shell.el")
159 :link '(emacs-commentary-link :tag "Commentary in idlwave.el" "idlwave.el")
160 :link '(custom-manual "(idlwave)Top")
161 :prefix "idlwave"
162 :group 'languages)
163
164 ;;; Variables for indentation behavior ---------------------------------------
165
166 (defgroup idlwave-code-formatting nil
167 "Indentation and formatting options for IDLWAVE mode."
168 :group 'idlwave)
169
170 (defcustom idlwave-main-block-indent 0
171 "*Extra indentation for the main block of code.
172 That is the block between the FUNCTION/PRO statement and the END
173 statement for that program unit."
174 :group 'idlwave-code-formatting
175 :type 'integer)
176
177 (defcustom idlwave-block-indent 4
178 "*Extra indentation applied to block lines.
179 If you change this, you probably also want to change `idlwave-end-offset'."
180 :group 'idlwave-code-formatting
181 :type 'integer)
182
183 (defcustom idlwave-end-offset -4
184 "*Extra indentation applied to block END lines.
185 A value equal to negative `idlwave-block-indent' will make END lines
186 line up with the block BEGIN lines."
187 :group 'idlwave-code-formatting
188 :type 'integer)
189
190 (defcustom idlwave-continuation-indent 2
191 "*Extra indentation applied to continuation lines.
192 This extra offset applies to the first of a set of continuation lines.
193 The following lines receive the same indentation as the first."
194 :group 'idlwave-code-formatting
195 :type 'integer)
196
197 (defcustom idlwave-max-extra-continuation-indent 20
198 "*Maximum additional indentation for special continuation indent.
199 Several special indentations are tried to help line up continuation
200 lines in routine calls or definitions, other statements with
201 parentheses, or assignment statements. This variable specifies a
202 maximum amount by which this special indentation can exceed the
203 standard continuation indentation, otherwise defaulting to a fixed
204 offset. Set to 0 to effectively disable all special continuation
205 indentation, or to a large number (like 100) to enable it in all
206 cases. See also `idlwave-indent-top-open-paren', which can override
207 this variable."
208 :group 'idlwave-code-formatting
209 :type 'integer)
210
211 (defcustom idlwave-indent-to-open-paren t
212 "*Non-nil means, indent continuation lines to innermost open
213 parenthesis. This indentation occurs even if otherwise disallowed by
214 `idlwave-max-extra-continuation-indent'. Matching parens and the
215 interleaving args are lined up. Example:
216
217 x = function_a(function_b(function_c( a, b, [1,2,3, $
218 4,5,6 $
219 ], $
220 c, d $
221 )))
222
223 When this variable is nil, paren alignment may still occur, based on
224 the value of `max-extra-continuation-indent', which, if zero, would
225 yield:
226
227 x = function_a(function_b(function_c( a, b, [1,2,3, $
228 4,5,6 $
229 ], $
230 c, d $
231 )))"
232 :group 'idlwave-code-formatting
233 :type 'boolean)
234
235 (defcustom idlwave-hanging-indent t
236 "*If set non-nil then comment paragraphs are indented under the
237 hanging indent given by `idlwave-hang-indent-regexp' match in the first line
238 of the paragraph."
239 :group 'idlwave-code-formatting
240 :type 'boolean)
241
242 (defcustom idlwave-hang-indent-regexp "- "
243 "*Regular expression matching the position of the hanging indent
244 in the first line of a comment paragraph. The size of the indent
245 extends to the end of the match for the regular expression."
246 :group 'idlwave-code-formatting
247 :type 'regexp)
248
249 (defcustom idlwave-use-last-hang-indent nil
250 "*If non-nil then use last match on line for `idlwave-indent-regexp'."
251 :group 'idlwave-code-formatting
252 :type 'boolean)
253
254 (defcustom idlwave-fill-comment-line-only t
255 "*If non-nil then auto fill will only operate on comment lines."
256 :group 'idlwave-code-formatting
257 :type 'boolean)
258
259 (defcustom idlwave-auto-fill-split-string t
260 "*If non-nil then auto fill will split strings with the IDL `+' operator.
261 When the line end falls within a string, string concatenation with the
262 '+' operator will be used to distribute a long string over lines.
263 If nil and a string is split then a terminal beep and warning are issued.
264
265 This variable is ignored when `idlwave-fill-comment-line-only' is
266 non-nil, since in this case code is not auto-filled."
267 :group 'idlwave-code-formatting
268 :type 'boolean)
269
270 (defcustom idlwave-split-line-string t
271 "*If non-nil then `idlwave-split-line' will split strings with `+'.
272 When the splitting point of a line falls inside a string, split the string
273 using the `+' string concatenation operator. If nil and a string is
274 split then a terminal beep and warning are issued."
275 :group 'idlwave-code-formatting
276 :type 'boolean)
277
278 (defcustom idlwave-no-change-comment ";;;"
279 "*The indentation of a comment that starts with this regular
280 expression will not be changed. Note that the indentation of a comment
281 at the beginning of a line is never changed."
282 :group 'idlwave-code-formatting
283 :type 'string)
284
285 (defcustom idlwave-begin-line-comment nil
286 "*A comment anchored at the beginning of line.
287 A comment matching this regular expression will not have its
288 indentation changed. If nil the default is \"^;\", i.e., any line
289 beginning with a \";\". Expressions for comments at the beginning of
290 the line should begin with \"^\"."
291 :group 'idlwave-code-formatting
292 :type '(choice (const :tag "Any line beginning with `;'" nil)
293 'regexp))
294
295 (defcustom idlwave-code-comment ";;[^;]"
296 "*A comment that starts with this regular expression on a line by
297 itself is indented as if it is a part of IDL code. As a result if
298 the comment is not preceded by whitespace it is unchanged."
299 :group 'idlwave-code-formatting
300 :type 'regexp)
301
302 ;; Comments not matching any of the above will be indented as a
303 ;; right-margin comment, i.e., to a minimum of `comment-column'.
304
305
306 ;;; Routine Info and Completion ---------------------------------------
307
308 (defgroup idlwave-routine-info nil
309 "Routine Info options for IDLWAVE mode."
310 :group 'idlwave)
311
312
313 (defcustom idlwave-init-rinfo-when-idle-after 10
314 "*Seconds of idle time before routine info is automatically initialized.
315 Initializing the routine info can take long, in particular if a large
316 library catalog is involved. When Emacs is idle for more than the number
317 of seconds specified by this variable, it starts the initialization.
318 The process is split into five steps, in order to keep possible work
319 interruption as short as possible. If one of the steps finishes, and no
320 user input has arrived in the mean time, initialization proceeds immediately
321 to the next step.
322 A good value for this variable is about 1/3 of the time initialization
323 take in you setup. So if you have a fast machine and no problems with a slow network connection, don't hesitate to set this to 2 seconds.
324 A Value of 0 means, don't initialize automatically."
325 :group 'idlwave-routine-info
326 :type 'number)
327
328 (defcustom idlwave-scan-all-buffers-for-routine-info t
329 "*Non-nil means, scan buffers for IDL programs when updating info.
330 The scanning is done by the command `idlwave-update-routine-info'.
331 The following values are allowed:
332
333 nil Don't scan any buffers.
334 t Scan all idlwave-mode buffers in the current editing session.
335 current Scan only the current buffer, but no other buffers."
336 :group 'idlwave-routine-info
337 :type '(choice
338 (const :tag "No buffer" nil)
339 (const :tag "All buffers" t)
340 (const :tag "Current buffer only" 'current)))
341
342 (defcustom idlwave-query-shell-for-routine-info t
343 "*Non-nil means query the shell for info about compiled routines.
344 Querying the shell is useful to get information about compiled modules,
345 and it is turned on by default. However, when you have a complete library
346 scan, this is not necessary."
347 :group 'idlwave-routine-info
348 :type 'boolean)
349
350 (defcustom idlwave-auto-routine-info-updates
351 '(find-file save-buffer kill-buffer compile-buffer)
352 "*Controls under what circumstances routine info is updated automatically.
353 Possible values:
354 nil Never
355 t All available
356 (...) A list of circumstances. Allowed members are:
357 find-file Add info for new IDLWAVE buffers.
358 save-buffer Update buffer info when buffer is saved
359 kill-buffer Remove buffer info when buffer gets killed
360 compile-buffer Update shell info after `idlwave-shell-save-and...'"
361 :group 'idlwave-routine-info
362 :type '(choice
363 (const :tag "Never" nil)
364 (const :tag "As often as possible" t)
365 (set :tag "Checklist" :greedy t
366 (const :tag "When visiting a file" find-file)
367 (const :tag "When saving a buffer" save-buffer)
368 (const :tag "After a buffer was killed" kill-buffer)
369 (const :tag "After a buffer was compiled successfully, update shell info" compile-buffer))))
370
371 (defcustom idlwave-rinfo-max-source-lines 5
372 "*Maximum number of source files displayed in the Routine Info window.
373 When an integer, it is the maximum number of source files displayed.
374 t means to show all source files."
375 :group 'idlwave-routine-info
376 :type 'integer)
377
378 (defcustom idlwave-library-path nil
379 "Library path for Windows and MacOS. Not needed under Unix.
380 When selecting the directories to scan for IDL library routine info,
381 IDLWAVE can under UNIX query the shell for the exact search path.
382 However, under Windows and MacOS, the IDLWAVE shell does not work. In this
383 case, this variable specifies the path where IDLWAVE can find library files.
384 The shell will only be asked when this variable is nil.
385 The value is a list of directories. A directory preceeded by a `+' will
386 be searched recursively. If you set this variable on a UNIX system, the shell
387 will not be asked.
388 See also `idlwave-system-directory'."
389 :group 'idlwave-routine-info
390 :type '(repeat (directory)))
391
392 (defcustom idlwave-system-directory ""
393 "The IDL system directory for Windows and MacOS. Not needed under UNIX.
394 Set this to the value of the `!DIR' system variable in IDL. IDLWAVE uses
395 this to find out which of the library routines belong to the official system
396 library. All files inside the `lib' subdirectory are considered system
397 library files - so don't install private stuff in this directory.
398 On UNIX systems, IDLWAVE queries the shell for the value of `!DIR'.
399 See also `idlwave-library-path'."
400 :group 'idlwave-routine-info
401 :type 'directory)
402
403 (defcustom idlwave-libinfo-file "~/.idlcat.el"
404 "*File for routine information of the IDL library.
405 When this points to a file, the file will be loaded when IDLWAVE first
406 accesses routine info (or does completion).
407 When you scan the library with `idlwave-create-libinfo-file', this file
408 will be used to store the result."
409 :group 'idlwave-routine-info
410 :type 'file)
411
412 (defcustom idlwave-special-lib-alist nil
413 "Alist of regular expressions matching special library directories.
414 When listing routine source locations, IDLWAVE gives a short hint where
415 the file defining the routine is located. By default it lists `SystemLib'
416 for routines in the system library `!DIR/lib' and `Library' for anything
417 else. This variable can define additional types. The car of each entry
418 is a regular expression matching the file name (they normally will match
419 on the path). The cdr is the string to be used as identifier. Max 10
420 chars are allowed."
421 :group 'idlwave-routine-info
422 :type '(repeat
423 (cons regexp string)))
424
425 (defgroup idlwave-online-help nil
426 "Online Help options for IDLWAVE mode."
427 :group 'idlwave)
428
429 (defcustom idlwave-help-directory ""
430 "The directory where idlw-help.txt and idlw-help.el are stored."
431 :group 'idlwave-online-help
432 :type 'file)
433
434 (defcustom idlwave-help-use-dedicated-frame t
435 "*Non-nil means, use a separate frame for Online Help if possible."
436 :group 'idlwave-online-help
437 :type 'boolean)
438
439 (defcustom idlwave-help-frame-parameters
440 '((height . 20) (unsplittable . t))
441 "The frame parameters for the special Online Help frame.
442 See also `idlwave-help-use-dedicated-frame'.
443 If you do not set the frame width here, the value specified in
444 `idlw-help.el' will be used."
445 :group 'idlwave-online-help
446 :type '(repeat
447 (cons symbol sexp)))
448
449 (defcustom idlwave-max-popup-menu-items 20
450 "Maximum number of items per pane in popup menus.
451 Currently only used for class selection during completion help."
452 :group 'idlwave-online-help
453 :type 'integer)
454
455 (defcustom idlwave-extra-help-function 'idlwave-help-with-source
456 "The function to call for online help if the normal help fails.
457 Online help works only for system routines which are described in the
458 IDL manuals. A function may be specified to access help from other sources.
459
460 The function must accept four arguments: NAME, TYPE, CLASS, KEYWORD.
461 The Help buffer is current when this function is called, and the help
462 text should be loaded into this buffer. If help is found, the function
463 should return the buffer position which should be used as `window-start'
464 in the help window. Also, the variable `idlwave-help-mode-line-indicator'
465 should be set to a useful string, which will be displayed in the mode line
466 of the help window. If should also set the variable `idlwave-min-frame-width'
467 to a positive integer. IDLWAVE will ensure that the help frame is at
468 least that many columns wide.
469 Failure to find help should be indicated by throwing an error.
470
471 When this variable is non-nil, IDLWAVE will allow the mouse-3 help click
472 for every routine and keyword, even though the item may not be highlighted
473 in blue (indicating the availability of system documentation).
474
475 The default value for this function is `idlwave-help-with-source' which
476 loads the routine source file into the help buffer. If you try to write
477 a different function which accesses a special help file or so, it is
478 probably a good idea to still call this function as a fallback."
479 :group 'idlwave-online-help
480 :type 'symbol)
481
482 (defcustom idlwave-help-fontify-source-code nil
483 "*Non-nil means, fontify source code displayed as help like normal code."
484 :group 'idlwave-online-help
485 :type 'boolean)
486
487 (defcustom idlwave-help-source-try-header t
488 "*Non-nil means, try to find help in routine header when displaying source.
489 Routines which are not documented in the system manual use their source as
490 help text. When this variable is non-nil, we try to find a description of
491 the help item in the first routine doclib header above the routine definition.
492 If the variable is nil, or if we cannot find/parse the header, the routine
493 definition is displayed instead."
494 :group 'idlwave-online-help
495 :type 'boolean)
496
497 (defface idlwave-help-link-face
498 '((((class color)) (:foreground "Blue"))
499 (t (:weight bold)))
500 "Face for highlighting links into IDLWAVE online help."
501 :group 'idlwave-online-help)
502
503 (defcustom idlwave-help-activate-links-aggressively t
504 "*Non-nil means, make all possible links in help active.
505 This just activates all words which are also a help topic - some links may
506 be misleading."
507 :group 'idlwave-online-help
508 :type 'boolean)
509
510
511 (defgroup idlwave-completion nil
512 "Completion options for IDLWAVE mode."
513 :prefix "idlwave"
514 :group 'idlwave)
515
516 (eval-and-compile
517 (defconst idlwave-tmp
518 '(choice :tag "by applying the function"
519 (const upcase)
520 (const downcase)
521 (const capitalize)
522 (const preserve)
523 (symbol :tag "Other"))))
524
525 (defcustom idlwave-completion-case '((routine . upcase)
526 (keyword . upcase)
527 (class . preserve)
528 (method . preserve))
529 "Association list setting the case of completed words.
530
531 This variable determines the case (UPPER/lower/Capitalized...) of
532 words inserted into the buffer by completion. The preferred case can
533 be specified separately for routine names, keywords, classes and
534 methods.
535 This alist should therefore have entries for `routine' (normal
536 functions and procedures, i.e. non-methods), `keyword', `class', and
537 `method'. Plausible values are
538
539 upcase upcase whole word, like `BOX_CURSOR'
540 downcase downcase whole word, like `read_ppm'
541 capitalize capitalize each part, like `Widget_Control'
542 preserve preserve case as is, like `IDLgrView'
543
544 The value can also be any Emacs Lisp function which transforms the
545 case of characters in a string.
546
547 A value of `preserve' means that the case of the completed word is
548 identical to the way it was written in the definition statement of the
549 routine. This was implemented to allow for mixed-case completion, in
550 particular of object classes and methods.
551 If a completable word is defined in multiple locations, the meaning of
552 `preserve' is not unique since the different definitions might be
553 cased differently. Therefore IDLWAVE always takes the case of the
554 *first* definition it encounters during routine info collection and
555 uses the case derived from it consistently.
556
557 Note that a lowercase-only string in the buffer will always be completed in
558 lower case (but see the variable `idlwave-completion-force-default-case').
559
560 After changing this variable, you need to either restart Emacs or press
561 `C-u C-c C-i' to update the internal lists."
562 :group 'idlwave-completion
563 :type `(repeat
564 (cons (symbol :tag "Derive completion case for")
565 ,idlwave-tmp)))
566
567 (defcustom idlwave-completion-force-default-case nil
568 "*Non-nil means, completion will always honor `idlwave-completion-case'.
569 When nil, only the completion of a mixed case or upper case string
570 will honor the default settings in `idlwave-completion-case', while
571 the completion of lower case strings will be completed entirely in
572 lower case."
573 :group 'idlwave-completion
574 :type 'boolean)
575
576 (defcustom idlwave-complete-empty-string-as-lower-case nil
577 "*Non-nil means, the empty string is considered downcase for completion.
578 The case of what is already in the buffer determines the case of completions.
579 When this variable is non-nil, the empty string is considered to be downcase.
580 Completing on the empty string then offers downcase versions of the possible
581 completions."
582 :group 'idlwave-completion
583 :type 'boolean)
584
585 (defvar idlwave-default-completion-case-is-down nil
586 "Obsolete variable. See `idlwave-complete-empty-string-as-lower-case' and
587 `idlwave-completion-case'.")
588
589 (defcustom idlwave-buffer-case-takes-precedence nil
590 "*Non-nil means, the case of tokens in buffers dominates over system stuff.
591 To make this possible, we need to re-case everything each time we update
592 the routine info from the buffers. This is slow.
593 The default is to consider the case given in the system and library files
594 first which makes updating much faster."
595 :group 'idlwave-completion
596 :type 'boolean)
597
598 (defcustom idlwave-highlight-help-links-in-completion t
599 "*Non-nil means, highlight completions for which system help is available.
600 Help can then be accessed with mouse-3.
601 This option is only effective when the online help system is installed."
602 :group 'idlwave-completion
603 :type 'boolean)
604
605 (defcustom idlwave-support-inheritance t
606 "Non-nil means, treat inheritance with completion, online help etc.
607 When nil, IDLWAVE only knows about the native methods and tags of a class,
608 not about inherited ones."
609 :group 'idlwave-routine-info
610 :type 'boolean)
611
612 (defcustom idlwave-keyword-class-inheritance '("^[gs]etproperty$" "^init$")
613 "List of regular expressions for class-driven keyword inheritance.
614 Keyword inheritance is often tied to class inheritance by \"chaining\"
615 up the class tree. While it cannot be assumed that the presence of an
616 _EXTRA or _REF_EXTRA symbol guarantees such chaining will occur, for
617 certain methods this assumption is almost always true. The methods
618 for which to assume this can be set here."
619 :group 'idlwave-routine-info
620 :type '(repeat (regexp :tag "Match method:")))
621
622
623 (defcustom idlwave-completion-show-classes 1
624 "*Number of classes to show when completing object methods and keywords.
625 When completing methods or keywords for an object with unknown class,
626 the *Completions* buffer will show the legal classes for each completion
627 like this:
628
629 MyMethod <Class1,Class2,Class3>
630
631 The value of this variable may be nil to inhibit display, or an integer to
632 indicate the maximum number of classes to display.
633
634 On XEmacs, a full list of classes will also be placed into a `help-echo'
635 property on the competion items, so that the list of classes for the current
636 item is displayed in the echo area. If the value of this variable is a
637 negative integer, the `help-echo' property will be suppressed."
638 :group 'idlwave-completion
639 :type '(choice (const :tag "Don't show" nil)
640 (integer :tag "Number of classes shown" 1)))
641
642 (defcustom idlwave-completion-fontify-classes t
643 "*Non-nil means, fontify the classes in completions buffer.
644 This makes it easier to distinguish the completion items from the extra
645 class info listed. See `idlwave-completion-show-classes'."
646 :group 'idlwave-completion
647 :type 'boolean)
648
649 (defcustom idlwave-query-class '((method-default . nil)
650 (keyword-default . nil))
651 "Association list governing specification of object classes for completion.
652
653 When IDLWAVE tries to complete object-oriented methods, it usually
654 cannot determine the class of a given object from context. In order
655 to provide the user with a correct list of methods or keywords, it
656 needs have to determine the appropriate class. IDLWAVE has two ways
657 to deal with this problem.
658
659 1. One possibility is to combine the items of all available classes
660 which contain this method for the purpose of completion. So when
661 completing a method, all methods of all known classes are
662 available, and when completing a keyword, all keywords allowed for
663 this method in any class are shown. This behavior is very much
664 like normal completion and is therefore the default. It works much
665 better than one might think - only for the INIT, GETPROPERTY and
666 SETPROPERTY the keyword lists become uncomfortably long. See also
667 `idlwave-completion-show-classes'.
668
669 2. The second possibility is to ask the user on each occasion. To
670 make this less interruptive, IDLWAVE can store the class as a text
671 property on the object operator `->'. For a given object in the
672 source code, class selection will then be needed only once
673 - for example to complete the method. Keywords to the method can
674 then be completed directly, because the class is already known.
675 You will have to turn on the storage of the selected class
676 explicitly with the variable `idlwave-store-inquired-class'.
677
678 This variable allows you to configure IDLWAVE's method and
679 method-keyword completion behavior. Its value is an alist, which
680 should contain at least two elements: (method-default . VALUE) and
681 (keyword-default . VALUE), where VALUE is either t or nil. These
682 specify if the class should be found during method and keyword
683 completion, respectively.
684
685 The alist may have additional entries specifying exceptions from the
686 keyword completion rule for specific methods, like INIT or
687 GETPROPERTY. In order to turn on class specification for the INIT
688 method, add an entry (\"INIT\" . t). The method name must be ALL-CAPS."
689 :group 'idlwave-completion
690 :type '(list
691 (cons (const method-default)
692 (boolean :tag "Determine class when completing METHODS "))
693 (cons (const keyword-default)
694 (boolean :tag "Determine class when completing KEYWORDS "))
695 (repeat
696 :tag "Exceptions to defaults"
697 :inline t
698 (cons (string :tag "MODULE" :value "")
699 (boolean :tag "Determine class for this method")))))
700
701 (defcustom idlwave-store-inquired-class nil
702 "*Non-nil means, store class of a method call as text property on `->'.
703 IDLWAVE sometimes has to ask the user for the class associated with a
704 particular object method call. This happens during the commands
705 `idlwave-routine-info' and `idlwave-complete', depending upon the
706 value of the variable `idlwave-query-class'.
707
708 When you specify a class, this information can be stored as a text
709 property on the `->' arrow in the source code, so that during the same
710 editing session, IDLWAVE will not have to ask again. When this
711 variable is non-nil, IDLWAVE will store and reuse the class information.
712 The class stored can be checked and removed with `\\[idlwave-routine-info]'
713 on the arrow.
714
715 The default of this variable is nil, since the result of commands then
716 is more predictable. However, if you know what you are doing, it can
717 be nice to turn this on.
718
719 An arrow which knows the class will be highlighted with
720 `idlwave-class-arrow-face'. The command \\[idlwave-routine-info]
721 displays (with prefix arg: deletes) the class stored on the arrow
722 at point."
723 :group 'idlwave-completion
724 :type 'boolean)
725
726 (defcustom idlwave-class-arrow-face 'bold
727 "*Face to highlight object operator arrows `->' which carry a class property.
728 When IDLWAVE stores a class name as text property on an object arrow
729 (see variable `idlwave-store-inquired-class', it highlights the arrow
730 with this font in order to remind the user that this arrow is special."
731 :group 'idlwave-completion
732 :type 'symbol)
733
734 (defcustom idlwave-resize-routine-help-window t
735 "*Non-nil means, resize the Routine-info *Help* window to fit the content."
736 :group 'idlwave-completion
737 :type 'boolean)
738
739 (defcustom idlwave-keyword-completion-adds-equal t
740 "*Non-nil means, completion automatically adds `=' after completed keywords."
741 :group 'idlwave-completion
742 :type 'boolean)
743
744 (defcustom idlwave-function-completion-adds-paren t
745 "*Non-nil means, completion automatically adds `(' after completed function.
746 nil means, don't add anything.
747 A value of `2' means, also add the closing parenthesis and position cursor
748 between the two."
749 :group 'idlwave-completion
750 :type '(choice (const :tag "Nothing" nil)
751 (const :tag "(" t)
752 (const :tag "()" 2)))
753
754 (defcustom idlwave-completion-restore-window-configuration t
755 "*Non-nil means, try to restore the window configuration after completion.
756 When completion is not unique, Emacs displays a list of completions.
757 This messes up your window configuration. With this variable set, IDLWAVE
758 restores the old configuration after successful completion."
759 :group 'idlwave-completion
760 :type 'boolean)
761
762 ;;; Variables for abbrev and action behavior -----------------------------
763
764 (defgroup idlwave-abbrev-and-indent-action nil
765 "IDLWAVE performs actions when expanding abbreviations or indenting lines.
766 The variables in this group govern this."
767 :group 'idlwave)
768
769 (defcustom idlwave-do-actions nil
770 "*Non-nil means performs actions when indenting.
771 The actions that can be performed are listed in `idlwave-indent-action-table'."
772 :group 'idlwave-abbrev-and-indent-action
773 :type 'boolean)
774
775 (defcustom idlwave-abbrev-start-char "\\"
776 "*A single character string used to start abbreviations in abbrev mode.
777 Possible characters to chose from: ~`\%
778 or even '?'. '.' is not a good choice because it can make structure
779 field names act like abbrevs in certain circumstances.
780
781 Changes to this in `idlwave-mode-hook' will have no effect. Instead a user
782 must set it directly using `setq' in the .emacs file before idlwave.el
783 is loaded."
784 :group 'idlwave-abbrev-and-indent-action
785 :type 'string)
786
787 (defcustom idlwave-surround-by-blank nil
788 "*Non-nil means, enable `idlwave-surround'.
789 If non-nil, `=',`<',`>',`&',`,', `->' are surrounded with spaces by
790 `idlwave-surround'.
791 See help for `idlwave-indent-action-table' for symbols using `idlwave-surround'.
792
793 Also see the default key bindings for keys using `idlwave-surround'.
794 Keys are bound and made into actions calling `idlwave-surround' with
795 `idlwave-action-and-binding'.
796 See help for `idlwave-action-and-binding' for examples.
797
798 Also see help for `idlwave-surround'."
799 :group 'idlwave-abbrev-and-indent-action
800 :type 'boolean)
801
802 (defcustom idlwave-pad-keyword t
803 "*Non-nil means pad '=' for keywords like assignments.
804 Whenever `idlwave-surround' is non-nil then this affects how '=' is padded
805 for keywords. If t, it is padded the same as for assignments.
806 If nil then spaces are removed. With any other value, spaces are left
807 unchanged."
808 :group 'idlwave-abbrev-and-indent-action
809 :type '(choice
810 (const :tag "Pad like assignments" t)
811 (const :tag "Remove space near `='" nil)
812 (const :tag "Keep space near `='" 'keep)))
813
814 (defcustom idlwave-show-block t
815 "*Non-nil means point blinks to block beginning for `idlwave-show-begin'."
816 :group 'idlwave-abbrev-and-indent-action
817 :type 'boolean)
818
819 (defcustom idlwave-expand-generic-end nil
820 "*Non-nil means expand generic END to ENDIF/ENDELSE/ENDWHILE etc."
821 :group 'idlwave-abbrev-and-indent-action
822 :type 'boolean)
823
824 (defcustom idlwave-reindent-end t
825 "*Non-nil means re-indent line after END was typed."
826 :group 'idlwave-abbrev-and-indent-action
827 :type 'boolean)
828
829 (defcustom idlwave-abbrev-move t
830 "*Non-nil means the abbrev hook can move point.
831 Set to nil by `idlwave-expand-region-abbrevs'. To see the abbrev
832 definitions, use the command `list-abbrevs', for abbrevs that move
833 point. Moving point is useful, for example, to place point between
834 parentheses of expanded functions.
835
836 See `idlwave-check-abbrev'."
837 :group 'idlwave-abbrev-and-indent-action
838 :type 'boolean)
839
840 (defcustom idlwave-abbrev-change-case nil
841 "*Non-nil means all abbrevs will be forced to either upper or lower case.
842 If the value t, all expanded abbrevs will be upper case.
843 If the value is 'down then abbrevs will be forced to lower case.
844 If nil, the case will not change.
845 If `idlwave-reserved-word-upcase' is non-nil, reserved words will always be
846 upper case, regardless of this variable."
847 :group 'idlwave-abbrev-and-indent-action
848 :type 'boolean)
849
850 (defcustom idlwave-reserved-word-upcase nil
851 "*Non-nil means, reserved words will be made upper case via abbrev expansion.
852 If nil case of reserved words is controlled by `idlwave-abbrev-change-case'.
853 Has effect only if in abbrev-mode."
854 :group 'idlwave-abbrev-and-indent-action
855 :type 'boolean)
856
857 ;;; Action/Expand Tables.
858 ;;
859 ;; The average user may have difficulty modifying this directly. It
860 ;; can be modified/set in idlwave-mode-hook, but it is easier to use
861 ;; idlwave-action-and-binding. See help for idlwave-action-and-binding for
862 ;; examples of how to add an action.
863 ;;
864 ;; The action table is used by `idlwave-indent-line' whereas both the
865 ;; action and expand tables are used by `idlwave-indent-and-action'. In
866 ;; general, the expand table is only used when a line is explicitly
867 ;; indented. Whereas, in addition to being used when the expand table
868 ;; is used, the action table is used when a line is indirectly
869 ;; indented via line splitting, auto-filling or a new line creation.
870 ;;
871 ;; Example actions:
872 ;;
873 ;; Capitalize system vars
874 ;; (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)
875 ;;
876 ;; Capitalize procedure name
877 ;; (idlwave-action-and-binding "\\<\\(pro\\|function\\)\\>[ \t]*\\<"
878 ;; '(capitalize-word 1) t)
879 ;;
880 ;; Capitalize common block name
881 ;; (idlwave-action-and-binding "\\<common\\>[ \t]+\\<"
882 ;; '(capitalize-word 1) t)
883 ;; Capitalize label
884 ;; (idlwave-action-and-binding (concat "^[ \t]*" idlwave-label)
885 ;; '(capitalize-word -1) t)
886
887 (defvar idlwave-indent-action-table nil
888 "*Associated array containing action lists of search string (car),
889 and function as a cdr. This table is used by `idlwave-indent-line'.
890 See documentation for `idlwave-do-action' for a complete description of
891 the action lists.
892
893 Additions to the table are made with `idlwave-action-and-binding' when a
894 binding is not requested.
895 See help on `idlwave-action-and-binding' for examples.")
896
897 (defvar idlwave-indent-expand-table nil
898 "*Associated array containing action lists of search string (car),
899 and function as a cdr. The table is used by the
900 `idlwave-indent-and-action' function. See documentation for
901 `idlwave-do-action' for a complete description of the action lists.
902
903 Additions to the table are made with `idlwave-action-and-binding' when a
904 binding is requested.
905 See help on `idlwave-action-and-binding' for examples.")
906
907 ;;; Documentation header and history keyword ---------------------------------
908
909 (defgroup idlwave-documentation nil
910 "Options for documenting IDLWAVE files."
911 :group 'idlwave)
912
913 ;; FIXME: make defcustom?
914 (defvar idlwave-file-header
915 (list nil
916 ";+
917 ; NAME:
918 ;
919 ;
920 ;
921 ; PURPOSE:
922 ;
923 ;
924 ;
925 ; CATEGORY:
926 ;
927 ;
928 ;
929 ; CALLING SEQUENCE:
930 ;
931 ;
932 ;
933 ; INPUTS:
934 ;
935 ;
936 ;
937 ; OPTIONAL INPUTS:
938 ;
939 ;
940 ;
941 ; KEYWORD PARAMETERS:
942 ;
943 ;
944 ;
945 ; OUTPUTS:
946 ;
947 ;
948 ;
949 ; OPTIONAL OUTPUTS:
950 ;
951 ;
952 ;
953 ; COMMON BLOCKS:
954 ;
955 ;
956 ;
957 ; SIDE EFFECTS:
958 ;
959 ;
960 ;
961 ; RESTRICTIONS:
962 ;
963 ;
964 ;
965 ; PROCEDURE:
966 ;
967 ;
968 ;
969 ; EXAMPLE:
970 ;
971 ;
972 ;
973 ; MODIFICATION HISTORY:
974 ;
975 ;-
976 ")
977 "*A list (PATHNAME STRING) specifying the doc-header template to use for
978 summarizing a file. If PATHNAME is non-nil then this file will be included.
979 Otherwise STRING is used. If nil, the file summary will be omitted.
980 For example you might set PATHNAME to the path for the
981 lib_template.pro file included in the IDL distribution.")
982
983 (defcustom idlwave-header-to-beginning-of-file nil
984 "*Non-nil means, the documentation header will always be at start of file.
985 When nil, the header is positioned between the PRO/FUNCTION line of
986 the current routine and the code, allowing several routine headers in
987 a file."
988 :group 'idlwave-documentation
989 :type 'boolean)
990
991 (defcustom idlwave-timestamp-hook 'idlwave-default-insert-timestamp
992 "*The hook function used to update the timestamp of a function."
993 :group 'idlwave-documentation
994 :type 'function)
995
996 (defcustom idlwave-doc-modifications-keyword "HISTORY"
997 "*The modifications keyword to use with the log documentation commands.
998 A ':' is added to the keyword end.
999 Inserted by doc-header and used to position logs by doc-modification.
1000 If nil it will not be inserted."
1001 :group 'idlwave-documentation
1002 :type 'string)
1003
1004 (defcustom idlwave-doclib-start "^;+\\+"
1005 "*Regexp matching the start of a document library header."
1006 :group 'idlwave-documentation
1007 :type 'regexp)
1008
1009 (defcustom idlwave-doclib-end "^;+-"
1010 "*Regexp matching the end of a document library header."
1011 :group 'idlwave-documentation
1012 :type 'regexp)
1013
1014 ;;; External Programs -------------------------------------------------------
1015
1016 (defgroup idlwave-external-programs nil
1017 "Path locations of external commands used by IDLWAVE."
1018 :group 'idlwave)
1019
1020 ;; WARNING: The following variable has recently been moved from
1021 ;; idlw-shell.el to this file. I hope this does not break
1022 ;; anything.
1023
1024 (defcustom idlwave-shell-explicit-file-name "idl"
1025 "*If non-nil, this is the command to run IDL.
1026 Should be an absolute file path or path relative to the current environment
1027 execution search path. If you want to specify command line switches
1028 for the idl program, use `idlwave-shell-command-line-options'.
1029
1030 I know the name of this variable is badly chosen, but I cannot change
1031 it without compromizing backwards-compatibility."
1032 :group 'idlwave-external-programs
1033 :type 'string)
1034
1035 (defcustom idlwave-shell-command-line-options nil
1036 "*A list of command line options for calling the IDL program.
1037 Since IDL is executed directly without going through a shell like /bin/sh,
1038 this should be a list of strings like '(\"-rt=file\" \"-nw\") with a separate
1039 string for each argument. But you may also give a single string which
1040 contains the options whitespace-separated. Emacs will be kind enough to
1041 split it for you."
1042 :type '(choice
1043 string
1044 (repeat (string :value "")))
1045 :group 'idlwave-external-programs)
1046
1047 (defcustom idlwave-help-application "idlhelp"
1048 "*The external application providing reference help for programming."
1049 :group 'idlwave-external-programs
1050 :type 'string)
1051
1052 ;;; Some Shell variables which must be defined here.-----------------------
1053
1054 (defcustom idlwave-shell-debug-modifiers '()
1055 "List of modifiers to be used for the debugging commands.
1056 Will be used to bind debugging commands in the shell buffer and in all
1057 source buffers. These are additional convenience bindings, the debugging
1058 commands are always available with the `C-c C-d' prefix.
1059 If you set this to '(control shift), this means setting a breakpoint will
1060 be on `C-S-b', compiling a source file on `C-S-c' etc. Possible modifiers
1061 are `control', `meta', `super', `hyper', `alt', and `shift'."
1062 :group 'idlwave-shell-general-setup
1063 :type '(set :tag "Specify modifiers"
1064 (const control)
1065 (const meta)
1066 (const super)
1067 (const hyper)
1068 (const alt)
1069 (const shift)))
1070
1071 (defcustom idlwave-shell-automatic-start nil
1072 "*If non-nil attempt invoke idlwave-shell if not already running.
1073 This is checked when an attempt to send a command to an
1074 IDL process is made."
1075 :group 'idlwave-shell-general-setup
1076 :type 'boolean)
1077
1078 ;;; Miscellaneous variables -------------------------------------------------
1079
1080 (defgroup idlwave-misc nil
1081 "Miscellaneous options for IDLWAVE mode."
1082 :group 'idlwave)
1083
1084 (defcustom idlwave-startup-message t
1085 "*Non-nil displays a startup message when `idlwave-mode' is first called."
1086 :group 'idlwave-misc
1087 :type 'boolean)
1088
1089 (defcustom idlwave-default-font-lock-items
1090 '(pros-and-functions batch-files idl-keywords label goto
1091 common-blocks class-arrows)
1092 "Items which should be fontified on the default fontification level 2.
1093 IDLWAVE defines 3 levels of fontification. Level 1 is very little, level 3
1094 is everything and level 2 is specified by this list.
1095 This variable must be set before IDLWAVE gets loaded. It is
1096 a list of symbols, the following symbols are allowed.
1097
1098 pros-and-functions Procedure and Function definitions
1099 batch-files Batch Files
1100 idl-keywords IDL Keywords
1101 label Statement Labels
1102 goto Goto Statements
1103 common-blocks Common Blocks
1104 keyword-parameters Keyword Parameters in routine definitions and calls
1105 system-variables System Variables
1106 fixme FIXME: Warning in comments (on XEmacs only v. 21.0 and up)
1107 class-arrows Object Arrows with class property"
1108 :group 'idlwave-misc
1109 :type '(set
1110 :inline t :greedy t
1111 (const :tag "Procedure and Function definitions" pros-and-functions)
1112 (const :tag "Batch Files" batch-files)
1113 (const :tag "IDL Keywords (reserved words)" idl-keywords)
1114 (const :tag "Statement Labels" label)
1115 (const :tag "Goto Statements" goto)
1116 (const :tag "Tags in Structure Definition" structtag)
1117 (const :tag "Structure Name" structname)
1118 (const :tag "Common Blocks" common-blocks)
1119 (const :tag "Keyword Parameters" keyword-parameters)
1120 (const :tag "System Variables" system-variables)
1121 (const :tag "FIXME: Warning" fixme)
1122 (const :tag "Object Arrows with class property " class-arrows)))
1123
1124 (defcustom idlwave-mode-hook nil
1125 "Normal hook. Executed when a buffer is put into `idlwave-mode'."
1126 :group 'idlwave-misc
1127 :type 'hook)
1128
1129 (defcustom idlwave-load-hook nil
1130 "Normal hook. Executed when idlwave.el is loaded."
1131 :group 'idlwave-misc
1132 :type 'hook)
1133
1134 (defvar idlwave-experimental nil
1135 "Non-nil means turn on a few experimental features.
1136 This variable is only for the maintainer, to test difficult stuff,
1137 while still distributing stable releases.
1138 As a user, you should not set this to t.")
1139
1140 ;;;
1141 ;;; End customization variables section
1142 ;;;
1143
1144 ;;; Non customization variables
1145
1146 ;;; font-lock mode - Additions by Phil Williams, Ulrik Dickow and
1147 ;;; Simon Marshall <simon@gnu.ai.mit.edu>
1148 ;;; and Carsten Dominik...
1149
1150 (defconst idlwave-font-lock-keywords-1 nil
1151 "Subdued level highlighting for IDLWAVE mode.")
1152
1153 (defconst idlwave-font-lock-keywords-2 nil
1154 "Medium level highlighting for IDLWAVE mode.")
1155
1156 (defconst idlwave-font-lock-keywords-3 nil
1157 "Gaudy level highlighting for IDLWAVE mode.")
1158
1159 (let* ((oldp (or (string-match "Lucid" emacs-version)
1160 (not (boundp 'emacs-minor-version))
1161 (and (<= emacs-major-version 19)
1162 (<= emacs-minor-version 29))))
1163
1164 ;; The following are the reserved words in IDL. Maybe we should
1165 ;; highlight some more stuff as well?
1166 (idl-keywords
1167 ;; To update this regexp, update the list of keywords and
1168 ;; evaluate the form.
1169 ; (insert
1170 ; (prin1-to-string
1171 ; (concat
1172 ; "\\<\\("
1173 ; (regexp-opt
1174 ; '("and" "or" "xor" "not"
1175 ; "eq" "ge" "gt" "le" "lt" "ne"
1176 ; "for" "do" "endfor"
1177 ; "if" "then" "endif" "else" "endelse"
1178 ; "case" "of" "endcase"
1179 ; "switch" "break" "continue" "endswitch"
1180 ; "begin" "end"
1181 ; "repeat" "until" "endrep"
1182 ; "while" "endwhile"
1183 ; "goto" "return"
1184 ; "inherits" "mod"
1185 ; "compile_opt" "forward_function"
1186 ; "on_error" "on_ioerror")) ; on_error is not officially reserved
1187 ; "\\)\\>")))
1188
1189 "\\<\\(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\\)\\>")
1190
1191 ;; Procedure declarations. Fontify keyword plus procedure name.
1192 ;; Function declarations. Fontify keyword plus function name.
1193 (pros-and-functions
1194 '("\\<\\(function\\|pro\\)\\>[ \t]+\\(\\sw+\\(::\\sw+\\)?\\)"
1195 (1 font-lock-keyword-face)
1196 (2 font-lock-function-name-face nil t)))
1197
1198 ;; Common blocks
1199 (common-blocks
1200 '("\\<\\(common\\)\\>[ \t]*\\(\\sw+\\)?[ \t]*,?"
1201 (1 font-lock-keyword-face) ; "common"
1202 (2 font-lock-reference-face nil t) ; block name
1203 (font-lock-match-c++-style-declaration-item-and-skip-to-next
1204 ;; Start with point after block name and comma
1205 (goto-char (match-end 0)) ; needed for XEmacs, could be nil
1206 nil
1207 (1 font-lock-variable-name-face) ; variable names
1208 )))
1209
1210 ;; Batch files
1211 (batch-files
1212 '("^[ \t]*\\(@[^ \t\n]+\\)" (1 font-lock-string-face)))
1213
1214 ;; FIXME warning.
1215 (fixme
1216 '("\\<FIXME:" (0 font-lock-warning-face t)))
1217
1218 ;; Labels
1219 (label
1220 '("^[ \t]*\\([a-zA-Z]\\sw*:\\)" (1 font-lock-reference-face)))
1221
1222 ;; The goto statement and its label
1223 (goto
1224 '("\\(goto\\)[ \t]*,[ \t]*\\([a-zA-Z]\\sw*\\)"
1225 (1 font-lock-keyword-face)
1226 (2 font-lock-reference-face)))
1227
1228 ;; Tags in structure definitions. Note that this definition actually
1229 ;; collides with labels, so we have to use the same face.
1230 (structtag
1231 '("\\<\\([a-zA-Z][a-zA-Z0-9_]*:\\)[^:]" (1 font-lock-reference-face)))
1232
1233 ;; Structure names
1234 (structname
1235 '("\\({\\|\\<inherits\\s-\\)\\s-*\\([a-zA-Z][a-zA-Z0-9_]*\\)[},\t \n]"
1236 (2 font-lock-function-name-face)))
1237
1238 ;; Named parameters, like /xlog or ,xrange=[]
1239 ;; This is anchored to the comma preceeding the keyword.
1240 ;; Treats continuation lines, works only during whole buffer
1241 ;; fontification. Slow, use it only in fancy fontification.
1242 (keyword-parameters
1243 '("\\(,\\|[a-zA-Z0-9_](\\)[ \t]*\\(\\$[ \t]*\\(;.*\\)?\\(\n[ \t]*;.*\\)*\n[ \t]*\\)?\\(/[a-zA-Z_]\\sw*\\|[a-zA-Z_]\\sw*[ \t]*=\\)"
1244 (5 font-lock-reference-face)))
1245
1246 ;; System variables start with a bang.
1247 (system-variables
1248 '("\\(![a-zA-Z_0-9]+\\(\\.\\sw+\\)?\\)"
1249 (1 font-lock-variable-name-face)))
1250
1251 ;; Special and unusual operators (not used because too noisy)
1252 (special-operators
1253 '("[<>#]" (0 font-lock-keyword-face)))
1254
1255 ;; All operators (not used because too noisy)
1256 (all-operators
1257 '("[-*^#+<>/]" (0 font-lock-keyword-face)))
1258
1259 ;; Arrows with text property `idlwave-class'
1260 (class-arrows
1261 (list 'idlwave-match-class-arrows
1262 (list 0 (if (featurep 'xemacs)
1263 idlwave-class-arrow-face
1264 'idlwave-class-arrow-face))))
1265
1266 )
1267
1268 ;; The following lines are just a dummy to make the compiler shut up
1269 ;; about variables bound but not used.
1270 (setq oldp oldp
1271 idl-keywords idl-keywords
1272 pros-and-functions pros-and-functions
1273 common-blocks common-blocks
1274 batch-files batch-files
1275 fixme fixme
1276 label label
1277 goto goto
1278 structtag structtag
1279 structname structname
1280 keyword-parameters keyword-parameters
1281 system-variables system-variables
1282 special-operators special-operators
1283 all-operators all-operators
1284 class-arrows class-arrows)
1285
1286 (setq idlwave-font-lock-keywords-1
1287 (list pros-and-functions
1288 batch-files
1289 ))
1290
1291 (setq idlwave-font-lock-keywords-2
1292 (mapcar 'symbol-value idlwave-default-font-lock-items))
1293
1294 (setq idlwave-font-lock-keywords-3
1295 (list pros-and-functions
1296 batch-files
1297 idl-keywords
1298 label goto
1299 structtag
1300 structname
1301 common-blocks
1302 keyword-parameters
1303 system-variables
1304 class-arrows
1305 ))
1306 )
1307
1308 (defun idlwave-match-class-arrows (limit)
1309 ;; Match an object arrow with class property
1310 (and idlwave-store-inquired-class
1311 (re-search-forward "->" limit 'limit)
1312 (get-text-property (match-beginning 0) 'idlwave-class)))
1313
1314 (defvar idlwave-font-lock-keywords idlwave-font-lock-keywords-2
1315 "Default expressions to highlight in IDLWAVE mode.")
1316
1317 (defvar idlwave-font-lock-defaults
1318 '((idlwave-font-lock-keywords
1319 idlwave-font-lock-keywords-1
1320 idlwave-font-lock-keywords-2
1321 idlwave-font-lock-keywords-3)
1322 nil t
1323 ((?$ . "w") (?_ . "w") (?. . "w"))
1324 beginning-of-line))
1325
1326 (put 'idlwave-mode 'font-lock-defaults
1327 idlwave-font-lock-defaults) ; XEmacs
1328
1329 (defconst idlwave-comment-line-start-skip "^[ \t]*;"
1330 "Regexp to match the start of a full-line comment.
1331 That is the _beginning_ of a line containing a comment delimiter `;' preceded
1332 only by whitespace.")
1333
1334 (defconst idlwave-begin-block-reg
1335 "\\<\\(pro\\|function\\|begin\\|case\\|switch\\)\\>"
1336 "Regular expression to find the beginning of a block. The case does
1337 not matter. The search skips matches in comments.")
1338
1339 (defconst idlwave-begin-unit-reg "\\<\\(pro\\|function\\)\\>\\|\\`"
1340 "Regular expression to find the beginning of a unit. The case does
1341 not matter.")
1342
1343 (defconst idlwave-end-unit-reg "\\<\\(pro\\|function\\)\\>\\|\\'"
1344 "Regular expression to find the line that indicates the end of unit.
1345 This line is the end of buffer or the start of another unit. The case does
1346 not matter. The search skips matches in comments.")
1347
1348 (defconst idlwave-continue-line-reg "\\<\\$"
1349 "Regular expression to match a continued line.")
1350
1351 (defconst idlwave-end-block-reg
1352 "\\<end\\(\\|case\\|switch\\|else\\|for\\|if\\|rep\\|while\\)\\>"
1353 "Regular expression to find the end of a block. The case does
1354 not matter. The search skips matches found in comments.")
1355
1356 (defconst idlwave-block-matches
1357 '(("pro" . "end")
1358 ("function" . "end")
1359 ("case" . "endcase")
1360 ("else" . "endelse")
1361 ("for" . "endfor")
1362 ("then" . "endif")
1363 ("repeat" . "endrep")
1364 ("switch" . "endswitch")
1365 ("while" . "endwhile"))
1366 "Matches between statements and the corresponding END variant.
1367 The cars are the reserved words starting a block. If the block really
1368 begins with BEGIN, the cars are the reserved words before the begin
1369 which can be used to identify the block type.
1370 This is used to check for the correct END type, to close blocks and
1371 to expand generic end statements to their detailed form.")
1372
1373 (defconst idlwave-block-match-regexp
1374 "\\<\\(else\\|for\\|then\\|repeat\\|while\\)\\>"
1375 "Regular expression matching reserved words which can stand before
1376 blocks starting with a BEGIN statement. The matches must have associations
1377 `idlwave-block-matches'")
1378
1379 (defconst idlwave-identifier "[a-zA-Z][a-zA-Z0-9$_]*"
1380 "Regular expression matching an IDL identifier.")
1381
1382 (defconst idlwave-sysvar (concat "!" idlwave-identifier)
1383 "Regular expression matching IDL system variables.")
1384
1385 (defconst idlwave-variable (concat idlwave-identifier "\\|" idlwave-sysvar)
1386 "Regular expression matching IDL variable names.")
1387
1388 (defconst idlwave-label (concat idlwave-identifier ":")
1389 "Regular expression matching IDL labels.")
1390
1391 (defconst idlwave-statement-match
1392 (list
1393 ;; "endif else" is the only possible "end" that can be
1394 ;; followed by a statement on the same line.
1395 '(endelse . ("end\\(\\|if\\)\\s +else" "end\\(\\|if\\)\\s +else"))
1396 ;; all other "end"s can not be followed by a statement.
1397 (cons 'end (list idlwave-end-block-reg nil))
1398 '(if . ("if\\>" "then"))
1399 '(for . ("for\\>" "do"))
1400 '(begin . ("begin\\>" nil))
1401 '(pdef . ("pro\\>\\|function\\>" nil))
1402 '(while . ("while\\>" "do"))
1403 '(repeat . ("repeat\\>" "repeat"))
1404 '(goto . ("goto\\>" nil))
1405 '(case . ("case\\>" nil))
1406 '(switch . ("switch\\>" nil))
1407 (cons 'call (list (concat idlwave-identifier "\\(\\s *$\\|\\s *,\\)") nil))
1408 '(assign . ("[^=>\n]*=" nil)))
1409
1410 "Associated list of statement matching regular expressions.
1411 Each regular expression matches the start of an IDL statement. The
1412 first element of each association is a symbol giving the statement
1413 type. The associated value is a list. The first element of this list
1414 is a regular expression matching the start of an IDL statement for
1415 identifying the statement type. The second element of this list is a
1416 regular expression for finding a substatement for the type. The
1417 substatement starts after the end of the found match modulo
1418 whitespace. If it is nil then the statement has no substatement. The
1419 list order matters since matching an assignment statement exactly is
1420 not possible without parsing. Thus assignment statement become just
1421 the leftover unidentified statements containing an equal sign." )
1422
1423 (defvar idlwave-fill-function 'auto-fill-function
1424 "IDL mode auto fill function.")
1425
1426 (defvar idlwave-comment-indent-function 'comment-indent-function
1427 "IDL mode comment indent function.")
1428
1429 ;; Note that this is documented in the v18 manuals as being a string
1430 ;; of length one rather than a single character.
1431 ;; The code in this file accepts either format for compatibility.
1432 (defvar idlwave-comment-indent-char ?\
1433 "Character to be inserted for IDL comment indentation.
1434 Normally a space.")
1435
1436 (defconst idlwave-continuation-char ?$
1437 "Character which is inserted as a last character on previous line by
1438 \\[idlwave-split-line] to begin a continuation line. Normally $.")
1439
1440 (defconst idlwave-mode-version " 4.14")
1441
1442 (defmacro idlwave-keyword-abbrev (&rest args)
1443 "Creates a function for abbrev hooks to call `idlwave-check-abbrev' with args."
1444 `(quote (lambda ()
1445 ,(append '(idlwave-check-abbrev) args))))
1446
1447 ;; If I take the time I can replace idlwave-keyword-abbrev with
1448 ;; idlwave-code-abbrev and remove the quoted abbrev check from
1449 ;; idlwave-check-abbrev. Then, e.g, (idlwave-keyword-abbrev 0 t) becomes
1450 ;; (idlwave-code-abbrev idlwave-check-abbrev 0 t). In fact I should change
1451 ;; the name of idlwave-check-abbrev to something like idlwave-modify-abbrev.
1452
1453 (defmacro idlwave-code-abbrev (&rest args)
1454 "Creates a function for abbrev hooks that ensures abbrevs are not quoted.
1455 Specifically, if the abbrev is in a comment or string it is unexpanded.
1456 Otherwise ARGS forms a list that is evaluated."
1457 `(quote (lambda ()
1458 ,(prin1-to-string args) ;; Puts the code in the doc string
1459 (if (idlwave-quoted)
1460 (progn (unexpand-abbrev) nil)
1461 ,(append args)))))
1462
1463 (defvar idlwave-mode-map (make-sparse-keymap)
1464 "Keymap used in IDL mode.")
1465
1466 (defvar idlwave-mode-syntax-table (make-syntax-table)
1467 "Syntax table in use in `idlwave-mode' buffers.")
1468
1469 (modify-syntax-entry ?+ "." idlwave-mode-syntax-table)
1470 (modify-syntax-entry ?- "." idlwave-mode-syntax-table)
1471 (modify-syntax-entry ?* "." idlwave-mode-syntax-table)
1472 (modify-syntax-entry ?/ "." idlwave-mode-syntax-table)
1473 (modify-syntax-entry ?^ "." idlwave-mode-syntax-table)
1474 (modify-syntax-entry ?# "." idlwave-mode-syntax-table)
1475 (modify-syntax-entry ?= "." idlwave-mode-syntax-table)
1476 (modify-syntax-entry ?% "." idlwave-mode-syntax-table)
1477 (modify-syntax-entry ?< "." idlwave-mode-syntax-table)
1478 (modify-syntax-entry ?> "." idlwave-mode-syntax-table)
1479 (modify-syntax-entry ?\' "\"" idlwave-mode-syntax-table)
1480 (modify-syntax-entry ?\" "\"" idlwave-mode-syntax-table)
1481 (modify-syntax-entry ?\\ "." idlwave-mode-syntax-table)
1482 (modify-syntax-entry ?_ "_" idlwave-mode-syntax-table)
1483 (modify-syntax-entry ?{ "(}" idlwave-mode-syntax-table)
1484 (modify-syntax-entry ?} "){" idlwave-mode-syntax-table)
1485 (modify-syntax-entry ?$ "_" idlwave-mode-syntax-table)
1486 (modify-syntax-entry ?. "." idlwave-mode-syntax-table)
1487 (modify-syntax-entry ?\; "<" idlwave-mode-syntax-table)
1488 (modify-syntax-entry ?\n ">" idlwave-mode-syntax-table)
1489 (modify-syntax-entry ?\f ">" idlwave-mode-syntax-table)
1490
1491 (defvar idlwave-find-symbol-syntax-table
1492 (copy-syntax-table idlwave-mode-syntax-table)
1493 "Syntax table that treats symbol characters as word characters.")
1494
1495 (modify-syntax-entry ?$ "w" idlwave-find-symbol-syntax-table)
1496 (modify-syntax-entry ?_ "w" idlwave-find-symbol-syntax-table)
1497
1498 (defmacro idlwave-with-special-syntax (&rest body)
1499 "Execute BODY with a different systax table."
1500 `(let ((saved-syntax (syntax-table)))
1501 (unwind-protect
1502 (progn
1503 (set-syntax-table idlwave-find-symbol-syntax-table)
1504 ,@body)
1505 (set-syntax-table saved-syntax))))
1506
1507 (defvar idlwave-print-symbol-syntax-table
1508 (copy-syntax-table idlwave-mode-syntax-table)
1509 "Syntax table that treats symbol characters as word characters.")
1510
1511 (modify-syntax-entry ?$ "w" idlwave-find-symbol-syntax-table)
1512 (modify-syntax-entry ?_ "w" idlwave-find-symbol-syntax-table)
1513 (modify-syntax-entry ?! "w" idlwave-find-symbol-syntax-table)
1514 (modify-syntax-entry ?. "w" idlwave-find-symbol-syntax-table)
1515
1516 (defmacro idlwave-with-special-syntax1 (&rest body)
1517 "Execute BODY with a different systax table."
1518 `(let ((saved-syntax (syntax-table)))
1519 (unwind-protect
1520 (progn
1521 (set-syntax-table idlwave-find-symbol-syntax-table)
1522 ,@body)
1523 (set-syntax-table saved-syntax))))
1524
1525 (defun idlwave-action-and-binding (key cmd &optional select)
1526 "KEY and CMD are made into a key binding and an indent action.
1527 KEY is a string - same as for the `define-key' function. CMD is a
1528 function of no arguments or a list to be evaluated. CMD is bound to
1529 KEY in `idlwave-mode-map' by defining an anonymous function calling
1530 `self-insert-command' followed by CMD. If KEY contains more than one
1531 character a binding will only be set if SELECT is 'both.
1532
1533 \(KEY . CMD\) is also placed in the `idlwave-indent-expand-table',
1534 replacing any previous value for KEY. If a binding is not set then it
1535 will instead be placed in `idlwave-indent-action-table'.
1536
1537 If the optional argument SELECT is nil then an action and binding are
1538 created. If SELECT is 'noaction, then a binding is always set and no
1539 action is created. If SELECT is 'both then an action and binding
1540 will both be created even if KEY contains more than one character.
1541 Otherwise, if SELECT is non-nil then only an action is created.
1542
1543 Some examples:
1544 No spaces before and 1 after a comma
1545 (idlwave-action-and-binding \",\" '(idlwave-surround 0 1))
1546 A minimum of 1 space before and after `=' (see `idlwave-expand-equal').
1547 (idlwave-action-and-binding \"=\" '(idlwave-expand-equal -1 -1))
1548 Capitalize system variables - action only
1549 (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)"
1550 (if (not (equal select 'noaction))
1551 ;; Add action
1552 (let* ((table (if select 'idlwave-indent-action-table
1553 'idlwave-indent-expand-table))
1554 (cell (assoc key (eval table))))
1555 (if cell
1556 ;; Replace action command
1557 (setcdr cell cmd)
1558 ;; New action
1559 (set table (append (eval table) (list (cons key cmd)))))))
1560 ;; Make key binding for action
1561 (if (or (and (null select) (= (length key) 1))
1562 (equal select 'noaction)
1563 (equal select 'both))
1564 (define-key idlwave-mode-map key
1565 (append '(lambda ()
1566 (interactive)
1567 (self-insert-command 1))
1568 (list (if (listp cmd)
1569 cmd
1570 (list cmd)))))))
1571
1572 (fset 'idlwave-debug-map (make-sparse-keymap))
1573
1574 (define-key idlwave-mode-map "\C-c " 'idlwave-hard-tab)
1575 (define-key idlwave-mode-map [(control tab)] 'idlwave-hard-tab)
1576 ;(define-key idlwave-mode-map "\C-c\C- " 'idlwave-hard-tab)
1577 (define-key idlwave-mode-map "'" 'idlwave-show-matching-quote)
1578 (define-key idlwave-mode-map "\"" 'idlwave-show-matching-quote)
1579 (define-key idlwave-mode-map "\C-c;" 'idlwave-toggle-comment-region)
1580 (define-key idlwave-mode-map "\C-\M-a" 'idlwave-beginning-of-subprogram)
1581 (define-key idlwave-mode-map "\C-\M-e" 'idlwave-end-of-subprogram)
1582 (define-key idlwave-mode-map "\C-c{" 'idlwave-beginning-of-block)
1583 (define-key idlwave-mode-map "\C-c}" 'idlwave-end-of-block)
1584 (define-key idlwave-mode-map "\C-c]" 'idlwave-close-block)
1585 (define-key idlwave-mode-map "\M-\C-h" 'idlwave-mark-subprogram)
1586 (define-key idlwave-mode-map "\M-\C-n" 'idlwave-forward-block)
1587 (define-key idlwave-mode-map "\M-\C-p" 'idlwave-backward-block)
1588 (define-key idlwave-mode-map "\M-\C-d" 'idlwave-down-block)
1589 (define-key idlwave-mode-map "\M-\C-u" 'idlwave-backward-up-block)
1590 (define-key idlwave-mode-map "\M-\r" 'idlwave-split-line)
1591 (define-key idlwave-mode-map "\M-\C-q" 'idlwave-indent-subprogram)
1592 (define-key idlwave-mode-map "\C-c\C-p" 'idlwave-previous-statement)
1593 (define-key idlwave-mode-map "\C-c\C-n" 'idlwave-next-statement)
1594 ;; (define-key idlwave-mode-map "\r" 'idlwave-newline)
1595 ;; (define-key idlwave-mode-map "\t" 'idlwave-indent-line)
1596 (define-key idlwave-mode-map (kbd "S-<iso-lefttab>") 'idlwave-indent-statement)
1597 (define-key idlwave-mode-map "\C-c\C-a" 'idlwave-auto-fill-mode)
1598 (define-key idlwave-mode-map "\M-q" 'idlwave-fill-paragraph)
1599 (define-key idlwave-mode-map "\M-s" 'idlwave-edit-in-idlde)
1600 (define-key idlwave-mode-map "\C-c\C-h" 'idlwave-doc-header)
1601 (define-key idlwave-mode-map "\C-c\C-m" 'idlwave-doc-modification)
1602 (define-key idlwave-mode-map "\C-c\C-c" 'idlwave-case)
1603 (define-key idlwave-mode-map "\C-c\C-d" 'idlwave-debug-map)
1604 (define-key idlwave-mode-map "\C-c\C-d\C-c" 'idlwave-shell-save-and-run)
1605 (define-key idlwave-mode-map "\C-c\C-d\C-b" 'idlwave-shell-break-here)
1606 (when (and (boundp 'idlwave-shell-debug-modifiers)
1607 (listp idlwave-shell-debug-modifiers)
1608 (not (equal idlwave-shell-debug-modifiers '())))
1609 ;; Bind the debug commands also with the special modifiers.
1610 (let ((shift (memq 'shift idlwave-shell-debug-modifiers))
1611 (mods-noshift (delq 'shift
1612 (copy-sequence idlwave-shell-debug-modifiers))))
1613 (define-key idlwave-mode-map
1614 (vector (append mods-noshift (list (if shift ?C ?c))))
1615 'idlwave-shell-save-and-run)
1616 (define-key idlwave-mode-map
1617 (vector (append mods-noshift (list (if shift ?B ?b))))
1618 'idlwave-shell-break-here)))
1619 (define-key idlwave-mode-map "\C-c\C-f" 'idlwave-for)
1620 ;; (define-key idlwave-mode-map "\C-c\C-f" 'idlwave-function)
1621 ;; (define-key idlwave-mode-map "\C-c\C-p" 'idlwave-procedure)
1622 (define-key idlwave-mode-map "\C-c\C-r" 'idlwave-repeat)
1623 (define-key idlwave-mode-map "\C-c\C-w" 'idlwave-while)
1624 (define-key idlwave-mode-map "\C-c\C-k" 'idlwave-kill-autoloaded-buffers)
1625 (define-key idlwave-mode-map "\C-c\C-s" 'idlwave-shell)
1626 (define-key idlwave-mode-map "\C-c\C-l" 'idlwave-shell-recenter-shell-window)
1627 (define-key idlwave-mode-map "\C-c\C-b" 'idlwave-list-buffer-load-path-shadows)
1628 (autoload 'idlwave-shell "idlw-shell"
1629 "Run an inferior IDL, with I/O through buffer `(idlwave-shell-buffer)'." t)
1630 (autoload 'idlwave-shell-send-command "idlw-shell")
1631 (autoload 'idlwave-shell-recenter-shell-window "idlw-shell"
1632 "Run `idlwave-shell' and switch back to current window" t)
1633 (autoload 'idlwave-shell-save-and-run "idlw-shell"
1634 "Save and run buffer under the shell." t)
1635 (autoload 'idlwave-shell-break-here "idlw-shell"
1636 "Set breakpoint in current line." t)
1637 (define-key idlwave-mode-map "\C-c\C-v" 'idlwave-find-module)
1638 (define-key idlwave-mode-map "\C-c?" 'idlwave-routine-info)
1639 (define-key idlwave-mode-map "\M-?" 'idlwave-context-help)
1640 (define-key idlwave-mode-map [(meta tab)] 'idlwave-complete)
1641 (define-key idlwave-mode-map "\C-c\C-i" 'idlwave-update-routine-info)
1642 (define-key idlwave-mode-map "\C-c=" 'idlwave-resolve)
1643 (define-key idlwave-mode-map
1644 (if (featurep 'xemacs) [(shift button3)] [(shift mouse-3)])
1645 'idlwave-mouse-context-help)
1646
1647 ;; Set action and key bindings.
1648 ;; See description of the function `idlwave-action-and-binding'.
1649 ;; Automatically add spaces for the following characters
1650 (idlwave-action-and-binding "&" '(idlwave-surround -1 -1))
1651 (idlwave-action-and-binding "<" '(idlwave-surround -1 -1))
1652 ;; Binding works for both > and ->, by changing the length of the token.
1653 (idlwave-action-and-binding ">" '(idlwave-surround -1 -1 '(?-) 1
1654 'idlwave-gtr-pad-hook))
1655 (idlwave-action-and-binding "->" '(idlwave-surround -1 -1 nil 2) t)
1656 (idlwave-action-and-binding "," '(idlwave-surround 0 -1))
1657 ;; Automatically add spaces to equal sign if not keyword
1658 (idlwave-action-and-binding "=" '(idlwave-expand-equal -1 -1))
1659
1660 ;;;
1661 ;;; Abbrev Section
1662 ;;;
1663 ;;; When expanding abbrevs and the abbrev hook moves backward, an extra
1664 ;;; space is inserted (this is the space typed by the user to expanded
1665 ;;; the abbrev).
1666 ;;;
1667 (defvar idlwave-mode-abbrev-table nil
1668 "Abbreviation table used for IDLWAVE mode")
1669 (define-abbrev-table 'idlwave-mode-abbrev-table ())
1670
1671 (defun idlwave-define-abbrev (name expansion hook &optional noprefix table)
1672 "Define-abbrev with backward compatibility.
1673
1674 If NOPREFIX is non-nil, don't prepend prefix character. Installs into
1675 idlwave-mode-abbrev-table unless TABLE is non-nil."
1676 (let ((abbrevs-changed nil) ;; mask the current value to avoid save
1677 (args (list (or table idlwave-mode-abbrev-table)
1678 (if noprefix name (concat idlwave-abbrev-start-char name))
1679 expansion
1680 hook)))
1681 (condition-case nil
1682 (apply 'define-abbrev (append args '(0 t)))
1683 (error (apply 'define-abbrev args)))))
1684
1685 (condition-case nil
1686 (modify-syntax-entry (string-to-char idlwave-abbrev-start-char)
1687 "w" idlwave-mode-syntax-table)
1688 (error nil))
1689
1690 ;;
1691 ;; Templates
1692 ;;
1693 (idlwave-define-abbrev "c" "" (idlwave-code-abbrev idlwave-case))
1694 (idlwave-define-abbrev "sw" "" (idlwave-code-abbrev idlwave-switch))
1695 (idlwave-define-abbrev "f" "" (idlwave-code-abbrev idlwave-for))
1696 (idlwave-define-abbrev "fu" "" (idlwave-code-abbrev idlwave-function))
1697 (idlwave-define-abbrev "pr" "" (idlwave-code-abbrev idlwave-procedure))
1698 (idlwave-define-abbrev "r" "" (idlwave-code-abbrev idlwave-repeat))
1699 (idlwave-define-abbrev "w" "" (idlwave-code-abbrev idlwave-while))
1700 (idlwave-define-abbrev "i" "" (idlwave-code-abbrev idlwave-if))
1701 (idlwave-define-abbrev "elif" "" (idlwave-code-abbrev idlwave-elif))
1702 ;;
1703 ;; Keywords, system functions, conversion routines
1704 ;;
1705 (idlwave-define-abbrev "ap" "arg_present()" (idlwave-keyword-abbrev 1))
1706 (idlwave-define-abbrev "b" "begin" (idlwave-keyword-abbrev 0 t))
1707 (idlwave-define-abbrev "co" "common" (idlwave-keyword-abbrev 0 t))
1708 (idlwave-define-abbrev "cb" "byte()" (idlwave-keyword-abbrev 1))
1709 (idlwave-define-abbrev "cx" "fix()" (idlwave-keyword-abbrev 1))
1710 (idlwave-define-abbrev "cl" "long()" (idlwave-keyword-abbrev 1))
1711 (idlwave-define-abbrev "cf" "float()" (idlwave-keyword-abbrev 1))
1712 (idlwave-define-abbrev "cs" "string()" (idlwave-keyword-abbrev 1))
1713 (idlwave-define-abbrev "cc" "complex()" (idlwave-keyword-abbrev 1))
1714 (idlwave-define-abbrev "cd" "double()" (idlwave-keyword-abbrev 1))
1715 (idlwave-define-abbrev "e" "else" (idlwave-keyword-abbrev 0 t))
1716 (idlwave-define-abbrev "ec" "endcase" 'idlwave-show-begin)
1717 (idlwave-define-abbrev "es" "endswitch" 'idlwave-show-begin)
1718 (idlwave-define-abbrev "ee" "endelse" 'idlwave-show-begin)
1719 (idlwave-define-abbrev "ef" "endfor" 'idlwave-show-begin)
1720 (idlwave-define-abbrev "ei" "endif else if" 'idlwave-show-begin)
1721 (idlwave-define-abbrev "el" "endif else" 'idlwave-show-begin)
1722 (idlwave-define-abbrev "en" "endif" 'idlwave-show-begin)
1723 (idlwave-define-abbrev "er" "endrep" 'idlwave-show-begin)
1724 (idlwave-define-abbrev "ew" "endwhile" 'idlwave-show-begin)
1725 (idlwave-define-abbrev "g" "goto," (idlwave-keyword-abbrev 0 t))
1726 (idlwave-define-abbrev "h" "help," (idlwave-keyword-abbrev 0))
1727 (idlwave-define-abbrev "k" "keyword_set()" (idlwave-keyword-abbrev 1))
1728 (idlwave-define-abbrev "n" "n_elements()" (idlwave-keyword-abbrev 1))
1729 (idlwave-define-abbrev "on" "on_error," (idlwave-keyword-abbrev 0))
1730 (idlwave-define-abbrev "oi" "on_ioerror," (idlwave-keyword-abbrev 0 1))
1731 (idlwave-define-abbrev "ow" "openw," (idlwave-keyword-abbrev 0))
1732 (idlwave-define-abbrev "or" "openr," (idlwave-keyword-abbrev 0))
1733 (idlwave-define-abbrev "ou" "openu," (idlwave-keyword-abbrev 0))
1734 (idlwave-define-abbrev "p" "print," (idlwave-keyword-abbrev 0))
1735 (idlwave-define-abbrev "pt" "plot," (idlwave-keyword-abbrev 0))
1736 (idlwave-define-abbrev "re" "read," (idlwave-keyword-abbrev 0))
1737 (idlwave-define-abbrev "rf" "readf," (idlwave-keyword-abbrev 0))
1738 (idlwave-define-abbrev "ru" "readu," (idlwave-keyword-abbrev 0))
1739 (idlwave-define-abbrev "rt" "return" (idlwave-keyword-abbrev 0))
1740 (idlwave-define-abbrev "sc" "strcompress()" (idlwave-keyword-abbrev 1))
1741 (idlwave-define-abbrev "sn" "strlen()" (idlwave-keyword-abbrev 1))
1742 (idlwave-define-abbrev "sl" "strlowcase()" (idlwave-keyword-abbrev 1))
1743 (idlwave-define-abbrev "su" "strupcase()" (idlwave-keyword-abbrev 1))
1744 (idlwave-define-abbrev "sm" "strmid()" (idlwave-keyword-abbrev 1))
1745 (idlwave-define-abbrev "sp" "strpos()" (idlwave-keyword-abbrev 1))
1746 (idlwave-define-abbrev "st" "strput()" (idlwave-keyword-abbrev 1))
1747 (idlwave-define-abbrev "sr" "strtrim()" (idlwave-keyword-abbrev 1))
1748 (idlwave-define-abbrev "t" "then" (idlwave-keyword-abbrev 0 t))
1749 (idlwave-define-abbrev "u" "until" (idlwave-keyword-abbrev 0 t))
1750 (idlwave-define-abbrev "wu" "writeu," (idlwave-keyword-abbrev 0))
1751 (idlwave-define-abbrev "iap" "if arg_present() then" (idlwave-keyword-abbrev 6))
1752 (idlwave-define-abbrev "ik" "if keyword_set() then" (idlwave-keyword-abbrev 6))
1753 (idlwave-define-abbrev "ine" "if n_elements() eq 0 then" (idlwave-keyword-abbrev 11))
1754 (idlwave-define-abbrev "inn" "if n_elements() ne 0 then" (idlwave-keyword-abbrev 11))
1755 (idlwave-define-abbrev "np" "n_params()" (idlwave-keyword-abbrev 0))
1756 (idlwave-define-abbrev "s" "size()" (idlwave-keyword-abbrev 1))
1757 (idlwave-define-abbrev "wi" "widget_info()" (idlwave-keyword-abbrev 1))
1758 (idlwave-define-abbrev "wc" "widget_control," (idlwave-keyword-abbrev 0))
1759
1760 ;; This section is reserved words only. (From IDL user manual)
1761 ;;
1762 (idlwave-define-abbrev "and" "and" (idlwave-keyword-abbrev 0 t) t)
1763 (idlwave-define-abbrev "begin" "begin" (idlwave-keyword-abbrev 0 t) t)
1764 (idlwave-define-abbrev "break" "break" (idlwave-keyword-abbrev 0 t) t)
1765 (idlwave-define-abbrev "case" "case" (idlwave-keyword-abbrev 0 t) t)
1766 (idlwave-define-abbrev "common" "common" (idlwave-keyword-abbrev 0 t) t)
1767 (idlwave-define-abbrev "continue" "continue" (idlwave-keyword-abbrev 0 t) t)
1768 (idlwave-define-abbrev "do" "do" (idlwave-keyword-abbrev 0 t) t)
1769 (idlwave-define-abbrev "else" "else" (idlwave-keyword-abbrev 0 t) t)
1770 (idlwave-define-abbrev "end" "end" 'idlwave-show-begin-check t)
1771 (idlwave-define-abbrev "endcase" "endcase" 'idlwave-show-begin-check t)
1772 (idlwave-define-abbrev "endelse" "endelse" 'idlwave-show-begin-check t)
1773 (idlwave-define-abbrev "endfor" "endfor" 'idlwave-show-begin-check t)
1774 (idlwave-define-abbrev "endif" "endif" 'idlwave-show-begin-check t)
1775 (idlwave-define-abbrev "endrep" "endrep" 'idlwave-show-begin-check t)
1776 (idlwave-define-abbrev "endswitch" "endswitch" 'idlwave-show-begin-check t)
1777 (idlwave-define-abbrev "endwhi" "endwhi" 'idlwave-show-begin-check t)
1778 (idlwave-define-abbrev "endwhile" "endwhile" 'idlwave-show-begin-check t)
1779 (idlwave-define-abbrev "eq" "eq" (idlwave-keyword-abbrev 0 t) t)
1780 (idlwave-define-abbrev "for" "for" (idlwave-keyword-abbrev 0 t) t)
1781 (idlwave-define-abbrev "function" "function" (idlwave-keyword-abbrev 0 t) t)
1782 (idlwave-define-abbrev "ge" "ge" (idlwave-keyword-abbrev 0 t) t)
1783 (idlwave-define-abbrev "goto" "goto" (idlwave-keyword-abbrev 0 t) t)
1784 (idlwave-define-abbrev "gt" "gt" (idlwave-keyword-abbrev 0 t) t)
1785 (idlwave-define-abbrev "if" "if" (idlwave-keyword-abbrev 0 t) t)
1786 (idlwave-define-abbrev "le" "le" (idlwave-keyword-abbrev 0 t) t)
1787 (idlwave-define-abbrev "lt" "lt" (idlwave-keyword-abbrev 0 t) t)
1788 (idlwave-define-abbrev "mod" "mod" (idlwave-keyword-abbrev 0 t) t)
1789 (idlwave-define-abbrev "ne" "ne" (idlwave-keyword-abbrev 0 t) t)
1790 (idlwave-define-abbrev "not" "not" (idlwave-keyword-abbrev 0 t) t)
1791 (idlwave-define-abbrev "of" "of" (idlwave-keyword-abbrev 0 t) t)
1792 (idlwave-define-abbrev "on_ioerror" "on_ioerror" (idlwave-keyword-abbrev 0 t) t)
1793 (idlwave-define-abbrev "or" "or" (idlwave-keyword-abbrev 0 t) t)
1794 (idlwave-define-abbrev "pro" "pro" (idlwave-keyword-abbrev 0 t) t)
1795 (idlwave-define-abbrev "repeat" "repeat" (idlwave-keyword-abbrev 0 t) t)
1796 (idlwave-define-abbrev "switch" "switch" (idlwave-keyword-abbrev 0 t) t)
1797 (idlwave-define-abbrev "then" "then" (idlwave-keyword-abbrev 0 t) t)
1798 (idlwave-define-abbrev "until" "until" (idlwave-keyword-abbrev 0 t) t)
1799 (idlwave-define-abbrev "while" "while" (idlwave-keyword-abbrev 0 t) t)
1800 (idlwave-define-abbrev "xor" "xor" (idlwave-keyword-abbrev 0 t) t)
1801
1802 (defvar imenu-create-index-function)
1803 (defvar extract-index-name-function)
1804 (defvar prev-index-position-function)
1805 (defvar imenu-extract-index-name-function)
1806 (defvar imenu-prev-index-position-function)
1807 ;; defined later - so just make the compiler hush
1808 (defvar idlwave-mode-menu)
1809 (defvar idlwave-mode-debug-menu)
1810
1811 ;;;###autoload
1812 (defun idlwave-mode ()
1813 "Major mode for editing IDL and WAVE CL .pro files.
1814
1815 The main features of this mode are
1816
1817 1. Indentation and Formatting
1818 --------------------------
1819 Like other Emacs programming modes, C-j inserts a newline and indents.
1820 TAB is used for explicit indentation of the current line.
1821
1822 To start a continuation line, use \\[idlwave-split-line]. This
1823 function can also be used in the middle of a line to split the line
1824 at that point. When used inside a long constant string, the string
1825 is split at that point with the `+' concatenation operator.
1826
1827 Comments are indented as follows:
1828
1829 `;;;' Indentation remains unchanged.
1830 `;;' Indent like the surrounding code
1831 `;' Indent to a minimum column.
1832
1833 The indentation of comments starting in column 0 is never changed.
1834
1835 Use \\[idlwave-fill-paragraph] to refill a paragraph inside a
1836 comment. The indentation of the second line of the paragraph
1837 relative to the first will be retained. Use
1838 \\[idlwave-auto-fill-mode] to toggle auto-fill mode for these
1839 comments. When the variable `idlwave-fill-comment-line-only' is
1840 nil, code can also be auto-filled and auto-indented (not
1841 recommended).
1842
1843 To convert pre-existing IDL code to your formatting style, mark the
1844 entire buffer with \\[mark-whole-buffer] and execute
1845 \\[idlwave-expand-region-abbrevs]. Then mark the entire buffer
1846 again followed by \\[indent-region] (`indent-region').
1847
1848 2. Routine Info
1849 ------------
1850 IDLWAVE displays information about the calling sequence and the
1851 accepted keyword parameters of a procedure or function with
1852 \\[idlwave-routine-info]. \\[idlwave-find-module] jumps to the
1853 source file of a module. These commands know about system
1854 routines, all routines in idlwave-mode buffers and (when the
1855 idlwave-shell is active) about all modules currently compiled under
1856 this shell. Use \\[idlwave-update-routine-info] to update this
1857 information, which is also used for completion (see item 4).
1858
1859 3. Online IDL Help
1860 ---------------
1861 \\[idlwave-context-help] displays the IDL documentation relevant
1862 for the system variable, keyword, or routine at point. A single key
1863 stroke gets you directly to the right place in the docs. Two additional
1864 files (an ASCII version of the IDL documentation and a topics file) must
1865 be installed for this - check the IDLWAVE webpage for these files.
1866
1867 4. Completion
1868 ----------
1869 \\[idlwave-complete] completes the names of procedures, functions
1870 class names and keyword parameters. It is context sensitive and
1871 figures out what is expected at point (procedure/function/keyword).
1872 Lower case strings are completed in lower case, other strings in
1873 mixed or upper case.
1874
1875 5. Code Templates and Abbreviations
1876 --------------------------------
1877 Many Abbreviations are predefined to expand to code fragments and templates.
1878 The abbreviations start generally with a `\\`. Some examples
1879
1880 \\pr PROCEDURE template
1881 \\fu FUNCTION template
1882 \\c CASE statement template
1883 \\sw SWITCH statement template
1884 \\f FOR loop template
1885 \\r REPEAT Loop template
1886 \\w WHILE loop template
1887 \\i IF statement template
1888 \\elif IF-ELSE statement template
1889 \\b BEGIN
1890
1891 For a full list, use \\[idlwave-list-abbrevs]. Some templates also have
1892 direct keybindings - see the list of keybindings below.
1893
1894 \\[idlwave-doc-header] inserts a documentation header at the beginning of the
1895 current program unit (pro, function or main). Change log entries
1896 can be added to the current program unit with \\[idlwave-doc-modification].
1897
1898 6. Automatic Case Conversion
1899 -------------------------
1900 The case of reserved words and some abbrevs is controlled by
1901 `idlwave-reserved-word-upcase' and `idlwave-abbrev-change-case'.
1902
1903 7. Automatic END completion
1904 ------------------------
1905 If the variable `idlwave-expand-generic-end' is non-nil, each END typed
1906 will be converted to the specific version, like ENDIF, ENDFOR, etc.
1907
1908 8. Hooks
1909 -----
1910 Loading idlwave.el runs `idlwave-load-hook'.
1911 Turning on `idlwave-mode' runs `idlwave-mode-hook'.
1912
1913 9. Documentation and Customization
1914 -------------------------------
1915 Info documentation for this package is available. Use
1916 \\[idlwave-info] to display (complain to your sysadmin if that does
1917 not work). For Postscript, PDF, and HTML versions of the
1918 documentation, check IDLWAVE's homepage at `http://idlwave.org'.
1919 IDLWAVE has customize support - see the group `idlwave'.
1920
1921 10.Keybindings
1922 -----------
1923 Here is a list of all keybindings of this mode.
1924 If some of the key bindings below show with ??, use \\[describe-key]
1925 followed by the key sequence to see what the key sequence does.
1926
1927 \\{idlwave-mode-map}"
1928
1929 (interactive)
1930 (kill-all-local-variables)
1931
1932 (if idlwave-startup-message
1933 (message "Emacs IDLWAVE mode version %s." idlwave-mode-version))
1934 (setq idlwave-startup-message nil)
1935
1936 (setq local-abbrev-table idlwave-mode-abbrev-table)
1937 (set-syntax-table idlwave-mode-syntax-table)
1938
1939 (set (make-local-variable 'indent-line-function) 'idlwave-indent-and-action)
1940
1941 (make-local-variable idlwave-comment-indent-function)
1942 (set idlwave-comment-indent-function 'idlwave-comment-hook)
1943
1944 (set (make-local-variable 'comment-start-skip) ";+[ \t]*")
1945 (set (make-local-variable 'comment-start) ";")
1946 (set (make-local-variable 'require-final-newline) t)
1947 (set (make-local-variable 'abbrev-all-caps) t)
1948 (set (make-local-variable 'indent-tabs-mode) nil)
1949 (set (make-local-variable 'completion-ignore-case) t)
1950
1951 (use-local-map idlwave-mode-map)
1952
1953 (when (featurep 'easymenu)
1954 (easy-menu-add idlwave-mode-menu idlwave-mode-map)
1955 (easy-menu-add idlwave-mode-debug-menu idlwave-mode-map))
1956
1957 (setq mode-name "IDLWAVE")
1958 (setq major-mode 'idlwave-mode)
1959 (setq abbrev-mode t)
1960
1961 (set (make-local-variable idlwave-fill-function) 'idlwave-auto-fill)
1962 (setq comment-end "")
1963 (set (make-local-variable 'comment-multi-line) nil)
1964 (set (make-local-variable 'paragraph-separate)
1965 "[ \t\f]*$\\|[ \t]*;+[ \t]*$\\|;+[+=-_*]+$")
1966 (set (make-local-variable 'paragraph-start) "[ \t\f]\\|[ \t]*;+[ \t]")
1967 (set (make-local-variable 'paragraph-ignore-fill-prefix) nil)
1968 (set (make-local-variable 'parse-sexp-ignore-comments) nil)
1969
1970 ;; Set tag table list to use IDLTAGS as file name.
1971 (if (boundp 'tag-table-alist)
1972 (add-to-list 'tag-table-alist '("\\.pro$" . "IDLTAGS")))
1973
1974 ;; Font-lock additions - originally Phil Williams, then Ulrik Dickow
1975 ;; Following line is for Emacs - XEmacs uses the corresponding porperty
1976 ;; on the `idlwave-mode' symbol.
1977 (set (make-local-variable 'font-lock-defaults) idlwave-font-lock-defaults)
1978
1979 ;; Imenu setup
1980 (set (make-local-variable 'imenu-create-index-function)
1981 'imenu-default-create-index-function)
1982 (set (make-local-variable 'imenu-extract-index-name-function)
1983 'idlwave-unit-name)
1984 (set (make-local-variable 'imenu-prev-index-position-function)
1985 'idlwave-prev-index-position)
1986
1987 ;; Make a local post-command-hook and add our hook to it
1988 ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
1989 (make-local-hook 'post-command-hook)
1990 (add-hook 'post-command-hook 'idlwave-command-hook nil 'local)
1991
1992 ;; Make local hooks for buffer updates
1993 ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
1994 (make-local-hook 'kill-buffer-hook)
1995 (add-hook 'kill-buffer-hook 'idlwave-kill-buffer-update nil 'local)
1996 (make-local-hook 'after-save-hook)
1997 (add-hook 'after-save-hook 'idlwave-save-buffer-update nil 'local)
1998 (add-hook 'after-save-hook 'idlwave-revoke-license-to-kill nil 'local)
1999
2000 ;; Update the routine info with info about current buffer?
2001 (idlwave-new-buffer-update)
2002
2003 ;; Run the mode hook
2004 (run-hooks 'idlwave-mode-hook))
2005
2006 ;;
2007 ;; Done with start up and initialization code.
2008 ;; The remaining routines are the code formatting functions.
2009 ;;
2010
2011 (defun idlwave-push-mark (&rest rest)
2012 "Push mark for compatibility with Emacs 18/19."
2013 (if (fboundp 'iconify-frame)
2014 (apply 'push-mark rest)
2015 (push-mark)))
2016
2017 (defun idlwave-hard-tab ()
2018 "Inserts TAB in buffer in current position."
2019 (interactive)
2020 (insert "\t"))
2021
2022 ;;; This stuff is experimental
2023
2024 (defvar idlwave-command-hook nil
2025 "If non-nil, a list that can be evaluated using `eval'.
2026 It is evaluated in the lisp function `idlwave-command-hook' which is
2027 placed in `post-command-hook'.")
2028
2029 (defun idlwave-command-hook ()
2030 "Command run after every command.
2031 Evaluates a non-nil value of the *variable* `idlwave-command-hook' and
2032 sets the variable to zero afterwards."
2033 (and idlwave-command-hook
2034 (listp idlwave-command-hook)
2035 (condition-case nil
2036 (eval idlwave-command-hook)
2037 (error nil)))
2038 (setq idlwave-command-hook nil))
2039
2040 ;;; End experiment
2041
2042 ;; It would be better to use expand.el for better abbrev handling and
2043 ;; versatility.
2044
2045 (defun idlwave-check-abbrev (arg &optional reserved)
2046 "Reverses abbrev expansion if in comment or string.
2047 Argument ARG is the number of characters to move point
2048 backward if `idlwave-abbrev-move' is non-nil.
2049 If optional argument RESERVED is non-nil then the expansion
2050 consists of reserved words, which will be capitalized if
2051 `idlwave-reserved-word-upcase' is non-nil.
2052 Otherwise, the abbrev will be capitalized if `idlwave-abbrev-change-case'
2053 is non-nil, unless its value is \`down in which case the abbrev will be
2054 made into all lowercase.
2055 Returns non-nil if abbrev is left expanded."
2056 (if (idlwave-quoted)
2057 (progn (unexpand-abbrev)
2058 nil)
2059 (if (and reserved idlwave-reserved-word-upcase)
2060 (upcase-region last-abbrev-location (point))
2061 (cond
2062 ((equal idlwave-abbrev-change-case 'down)
2063 (downcase-region last-abbrev-location (point)))
2064 (idlwave-abbrev-change-case
2065 (upcase-region last-abbrev-location (point)))))
2066 (if (and idlwave-abbrev-move (> arg 0))
2067 (if (boundp 'post-command-hook)
2068 (setq idlwave-command-hook (list 'backward-char (1+ arg)))
2069 (backward-char arg)))
2070 t))
2071
2072 (defun idlwave-in-comment ()
2073 "Returns t if point is inside a comment, nil otherwise."
2074 (save-excursion
2075 (let ((here (point)))
2076 (and (idlwave-goto-comment) (> here (point))))))
2077
2078 (defun idlwave-goto-comment ()
2079 "Move to start of comment delimiter on current line.
2080 Moves to end of line if there is no comment delimiter.
2081 Ignores comment delimiters in strings.
2082 Returns point if comment found and nil otherwise."
2083 (let ((eos (progn (end-of-line) (point)))
2084 (data (match-data))
2085 found)
2086 ;; Look for first comment delimiter not in a string
2087 (beginning-of-line)
2088 (setq found (search-forward comment-start eos 'lim))
2089 (while (and found (idlwave-in-quote))
2090 (setq found (search-forward comment-start eos 'lim)))
2091 (store-match-data data)
2092 (and found (not (idlwave-in-quote))
2093 (progn
2094 (backward-char 1)
2095 (point)))))
2096
2097 (defvar transient-mark-mode)
2098 (defvar zmacs-regions)
2099 (defvar mark-active)
2100 (defun idlwave-region-active-p ()
2101 "Is transien-mark-mode on an the region active?
2102 Works on both Emacs and XEmacs."
2103 (if (featurep 'xemacs)
2104 (and zmacs-regions (region-active-p))
2105 (and transient-mark-mode mark-active)))
2106
2107 (defun idlwave-show-matching-quote ()
2108 "Insert quote and show matching quote if this is end of a string."
2109 (interactive)
2110 (let ((bq (idlwave-in-quote))
2111 (inq last-command-char))
2112 (if (and bq (not (idlwave-in-comment)))
2113 (let ((delim (char-after bq)))
2114 (insert inq)
2115 (if (eq inq delim)
2116 (save-excursion
2117 (goto-char bq)
2118 (sit-for 1))))
2119 ;; Not the end of a string
2120 (insert inq))))
2121
2122 (defun idlwave-show-begin-check ()
2123 "Ensure that the previous word was a token before `idlwave-show-begin'.
2124 An END token must be preceded by whitespace."
2125 (if (not (idlwave-quoted))
2126 (if
2127 (save-excursion
2128 (backward-word 1)
2129 (backward-char 1)
2130 (looking-at "[ \t\n\f]"))
2131 (idlwave-show-begin))))
2132
2133 (defun idlwave-show-begin ()
2134 "Finds the start of current block and blinks to it for a second.
2135 Also checks if the correct end statement has been used."
2136 ;; All end statements are reserved words
2137 (let* ((pos (point))
2138 end end1)
2139 (when (and (idlwave-check-abbrev 0 t)
2140 idlwave-show-block)
2141 (save-excursion
2142 ;; Move inside current block
2143 (setq end (buffer-substring
2144 (save-excursion (skip-chars-backward "a-zA-Z")
2145 (point))
2146 (point)))
2147 (idlwave-beginning-of-statement)
2148 (idlwave-block-jump-out -1 'nomark)
2149 (when (setq end1 (cdr (idlwave-block-master)))
2150 (cond
2151 ((null end1)) ; no-operation
2152 ((string= (downcase end) (downcase end1))
2153 (sit-for 1))
2154 ((string= (downcase end) "end")
2155 ;; A generic end
2156 (if idlwave-expand-generic-end
2157 (save-excursion
2158 (goto-char pos)
2159 (backward-char 3)
2160 (insert (if (string= end "END") (upcase end1) end1))
2161 (delete-char 3)))
2162 (sit-for 1))
2163 (t
2164 (beep)
2165 (message "Warning: Shouldn't this be \"%s\" instead of \"%s\"?"
2166 end1 end)
2167 (sit-for 1)))))))
2168 ;; Re-indent end line
2169 (if idlwave-reindent-end
2170 (idlwave-indent-line)))
2171
2172 (defun idlwave-block-master ()
2173 (let ((case-fold-search t))
2174 (save-excursion
2175 (cond
2176 ((looking-at "pro\\|case\\|switch\\|function\\>")
2177 (assoc (downcase (match-string 0)) idlwave-block-matches))
2178 ((looking-at "begin\\>")
2179 (let ((limit (save-excursion
2180 (idlwave-beginning-of-statement)
2181 (point))))
2182 (cond
2183 ((re-search-backward idlwave-block-match-regexp limit t)
2184 (assoc (downcase (match-string 1))
2185 idlwave-block-matches))
2186 ;;((re-search-backward ":[ \t]*\\=" limit t)
2187 ;; ;; seems to be a case thing
2188 ;; '("begin" . "end"))
2189 (t
2190 ;; Just a nromal block
2191 '("begin" . "end")))))
2192 (t nil)))))
2193
2194 (defun idlwave-close-block ()
2195 "Terminate the current block with the correct END statement."
2196 (interactive)
2197
2198 ;; Start new line if we are not in a new line
2199 (unless (save-excursion
2200 (skip-chars-backward " \t")
2201 (bolp))
2202 (let ((idlwave-show-block nil))
2203 (newline-and-indent)))
2204 (let ((last-abbrev-location (point))) ; for upcasing
2205 (insert "end")
2206 (idlwave-show-begin)))
2207
2208 (defun idlwave-gtr-pad-hook (char)
2209 "Let the > symbol expand around -> if present. The new token length
2210 is returned."
2211 2)
2212
2213 (defun idlwave-surround (&optional before after escape-chars length ec-hook)
2214 "Surround the LENGTH characters before point with blanks.
2215 LENGTH defaults to 1.
2216 Optional arguments BEFORE and AFTER affect the behavior before and
2217 after the characters (see also description of `idlwave-make-space'):
2218
2219 nil do nothing
2220 0 force no spaces
2221 integer > 0 force exactly n spaces
2222 integer < 0 at least |n| spaces
2223
2224 The function does nothing if any of the following conditions is true:
2225 - `idlwave-surround-by-blank' is nil
2226 - the character before point is inside a string or comment
2227 - the char preceeding the string to be surrounded is a member of ESCAPE-CHARS.
2228 This hack is used to avoid padding of `>' when it is part of
2229 the '->' operator. In this case, ESCAPE-CHARS would be '(?-).
2230
2231 If a function is passed in EC-HOOK, and an ESCAPE-CHARS match occurs,
2232 the named function will be called with a single argument of the
2233 preceeding character. Then idlwave-surround will run as usual if
2234 EC-HOOK returns non-nil, and a new length will be taken from the
2235 return value."
2236 (when (and idlwave-surround-by-blank (not (idlwave-quoted)))
2237 (let* ((length (or length 1)) ; establish a default for LENGTH
2238 (prev-char (char-after (- (point) (1+ length)))))
2239 (when (or (not (memq prev-char escape-chars))
2240 (and (fboundp ec-hook)
2241 (setq length
2242 (save-excursion (funcall ec-hook prev-char)))))
2243 (backward-char length)
2244 (save-restriction
2245 (let ((here (point)))
2246 (skip-chars-backward " \t")
2247 (if (bolp)
2248 ;; avoid clobbering indent
2249 (progn
2250 (move-to-column (idlwave-calculate-indent))
2251 (if (<= (point) here)
2252 (narrow-to-region (point) here))
2253 (goto-char here)))
2254 (idlwave-make-space before))
2255 (skip-chars-forward " \t"))
2256 (forward-char length)
2257 (idlwave-make-space after)
2258 ;; Check to see if the line should auto wrap
2259 (if (and (equal (char-after (1- (point))) ?\ )
2260 (> (current-column) fill-column))
2261 (funcall auto-fill-function))))))
2262
2263 (defun idlwave-make-space (n)
2264 "Make space at point.
2265 The space affected is all the spaces and tabs around point.
2266 If n is non-nil then point is left abs(n) spaces from the beginning of
2267 the contiguous space.
2268 The amount of space at point is determined by N.
2269 If the value of N is:
2270 nil - do nothing.
2271 > 0 - exactly N spaces.
2272 < 0 - a minimum of -N spaces, i.e., do not change if there are
2273 already -N spaces.
2274 0 - no spaces (i.e. remove any existing space)."
2275 (if (integerp n)
2276 (let
2277 ((start-col (progn (skip-chars-backward " \t") (current-column)))
2278 (left (point))
2279 (end-col (progn (skip-chars-forward " \t") (current-column))))
2280 (delete-horizontal-space)
2281 (cond
2282 ((> n 0)
2283 (idlwave-indent-to (+ start-col n))
2284 (goto-char (+ left n)))
2285 ((< n 0)
2286 (idlwave-indent-to end-col (- n))
2287 (goto-char (- left n)))
2288 ;; n = 0, done
2289 ))))
2290
2291 (defun idlwave-newline ()
2292 "Inserts a newline and indents the current and previous line."
2293 (interactive)
2294 ;;
2295 ;; Handle unterminated single and double quotes
2296 ;; If not in a comment and in a string then insertion of a newline
2297 ;; will mean unbalanced quotes.
2298 ;;
2299 (if (and (not (idlwave-in-comment)) (idlwave-in-quote))
2300 (progn (beep)
2301 (message "Warning: unbalanced quotes?")))
2302 (newline)
2303 ;;
2304 ;; The current line is being split, the cursor should be at the
2305 ;; beginning of the new line skipping the leading indentation.
2306 ;;
2307 ;; The reason we insert the new line before indenting is that the
2308 ;; indenting could be confused by keywords (e.g. END) on the line
2309 ;; after the split point. This prevents us from just using
2310 ;; `indent-for-tab-command' followed by `newline-and-indent'.
2311 ;;
2312 (beginning-of-line 0)
2313 (idlwave-indent-line)
2314 (forward-line)
2315 (idlwave-indent-line))
2316
2317 ;;
2318 ;; Use global variable 'comment-column' to set parallel comment
2319 ;;
2320 ;; Modeled on lisp.el
2321 ;; Emacs Lisp and IDL (Wave CL) have identical comment syntax
2322 (defun idlwave-comment-hook ()
2323 "Compute indent for the beginning of the IDL comment delimiter."
2324 (if (or (looking-at idlwave-no-change-comment)
2325 (if idlwave-begin-line-comment
2326 (looking-at idlwave-begin-line-comment)
2327 (looking-at "^;")))
2328 (current-column)
2329 (if (looking-at idlwave-code-comment)
2330 (if (save-excursion (skip-chars-backward " \t") (bolp))
2331 ;; On line by itself, indent as code
2332 (let ((tem (idlwave-calculate-indent)))
2333 (if (listp tem) (car tem) tem))
2334 ;; after code - do not change
2335 (current-column))
2336 (skip-chars-backward " \t")
2337 (max (if (bolp) 0 (1+ (current-column)))
2338 comment-column))))
2339
2340 (defun idlwave-split-line ()
2341 "Continue line by breaking line at point and indent the lines.
2342 For a code line insert continuation marker. If the line is a line comment
2343 then the new line will contain a comment with the same indentation.
2344 Splits strings with the IDL operator `+' if `idlwave-split-line-string' is
2345 non-nil."
2346 (interactive)
2347 ;; Expand abbreviation, just like normal RET would.
2348 (and abbrev-mode (expand-abbrev))
2349 (let (beg)
2350 (if (not (idlwave-in-comment))
2351 ;; For code line add continuation.
2352 ;; Check if splitting a string.
2353 (progn
2354 (if (setq beg (idlwave-in-quote))
2355 (if idlwave-split-line-string
2356 ;; Split the string.
2357 (progn (insert (setq beg (char-after beg)) " + "
2358 idlwave-continuation-char beg)
2359 (backward-char 1)
2360 (newline-and-indent)
2361 (forward-char 1))
2362 ;; Do not split the string.
2363 (beep)
2364 (message "Warning: continuation inside string!!")
2365 (insert " " idlwave-continuation-char))
2366 ;; Not splitting a string.
2367 (if (not (member (char-before) '(?\ ?\t)))
2368 (insert " "))
2369 (insert idlwave-continuation-char)
2370 (newline-and-indent)))
2371 (indent-new-comment-line))
2372 ;; Indent previous line
2373 (setq beg (- (point-max) (point)))
2374 (forward-line -1)
2375 (idlwave-indent-line)
2376 (goto-char (- (point-max) beg))
2377 ;; Reindent new line
2378 (idlwave-indent-line)))
2379
2380 (defun idlwave-beginning-of-subprogram ()
2381 "Moves point to the beginning of the current program unit."
2382 (interactive)
2383 (idlwave-find-key idlwave-begin-unit-reg -1))
2384
2385 (defun idlwave-end-of-subprogram ()
2386 "Moves point to the start of the next program unit."
2387 (interactive)
2388 (idlwave-end-of-statement)
2389 (idlwave-find-key idlwave-end-unit-reg 1))
2390
2391 (defun idlwave-mark-statement ()
2392 "Mark current IDL statement."
2393 (interactive)
2394 (idlwave-end-of-statement)
2395 (let ((end (point)))
2396 (idlwave-beginning-of-statement)
2397 (idlwave-push-mark end nil t)))
2398
2399 (defun idlwave-mark-block ()
2400 "Mark containing block."
2401 (interactive)
2402 (idlwave-end-of-statement)
2403 (idlwave-backward-up-block -1)
2404 (idlwave-end-of-statement)
2405 (let ((end (point)))
2406 (idlwave-backward-block)
2407 (idlwave-beginning-of-statement)
2408 (idlwave-push-mark end nil t)))
2409
2410
2411 (defun idlwave-mark-subprogram ()
2412 "Put mark at beginning of program, point at end.
2413 The marks are pushed."
2414 (interactive)
2415 (idlwave-end-of-statement)
2416 (idlwave-beginning-of-subprogram)
2417 (let ((beg (point)))
2418 (idlwave-forward-block)
2419 (idlwave-push-mark beg nil t))
2420 (exchange-point-and-mark))
2421
2422 (defun idlwave-backward-up-block (&optional arg)
2423 "Move to beginning of enclosing block if prefix ARG >= 0.
2424 If prefix ARG < 0 then move forward to enclosing block end."
2425 (interactive "p")
2426 (idlwave-block-jump-out (- arg) 'nomark))
2427
2428 (defun idlwave-beginning-of-block ()
2429 "Go to the beginning of the current block."
2430 (interactive)
2431 (idlwave-block-jump-out -1 'nomark)
2432 (forward-word 1))
2433
2434 (defun idlwave-end-of-block ()
2435 "Go to the beginning of the current block."
2436 (interactive)
2437 (idlwave-block-jump-out 1 'nomark)
2438 (backward-word 1))
2439
2440 (defun idlwave-forward-block ()
2441 "Move across next nested block."
2442 (interactive)
2443 (if (idlwave-down-block 1)
2444 (idlwave-block-jump-out 1 'nomark)))
2445
2446 (defun idlwave-backward-block ()
2447 "Move backward across previous nested block."
2448 (interactive)
2449 (if (idlwave-down-block -1)
2450 (idlwave-block-jump-out -1 'nomark)))
2451
2452 (defun idlwave-down-block (&optional arg)
2453 "Go down a block.
2454 With ARG: ARG >= 0 go forwards, ARG < 0 go backwards.
2455 Returns non-nil if successfull."
2456 (interactive "p")
2457 (let (status)
2458 (if (< arg 0)
2459 ;; Backward
2460 (let ((eos (save-excursion
2461 (idlwave-block-jump-out -1 'nomark)
2462 (point))))
2463 (if (setq status (idlwave-find-key
2464 idlwave-end-block-reg -1 'nomark eos))
2465 (idlwave-beginning-of-statement)
2466 (message "No nested block before beginning of containing block.")))
2467 ;; Forward
2468 (let ((eos (save-excursion
2469 (idlwave-block-jump-out 1 'nomark)
2470 (point))))
2471 (if (setq status (idlwave-find-key
2472 idlwave-begin-block-reg 1 'nomark eos))
2473 (idlwave-end-of-statement)
2474 (message "No nested block before end of containing block."))))
2475 status))
2476
2477 (defun idlwave-mark-doclib ()
2478 "Put point at beginning of doc library header, mark at end.
2479 The marks are pushed."
2480 (interactive)
2481 (let (beg
2482 (here (point)))
2483 (goto-char (point-max))
2484 (if (re-search-backward idlwave-doclib-start nil t)
2485 (progn
2486 (setq beg (progn (beginning-of-line) (point)))
2487 (if (re-search-forward idlwave-doclib-end nil t)
2488 (progn
2489 (forward-line 1)
2490 (idlwave-push-mark beg nil t)
2491 (message "Could not find end of doc library header.")))
2492 (message "Could not find doc library header start.")
2493 (goto-char here)))))
2494
2495
2496 (defun idlwave-current-routine ()
2497 "Return (NAME TYPE CLASS) of current routine."
2498 (idlwave-routines)
2499 (save-excursion
2500 (idlwave-beginning-of-subprogram)
2501 (if (looking-at "[ \t]*\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)")
2502 (let* ((type (if (string= (downcase (match-string 1)) "pro")
2503 'pro 'function))
2504 (class (idlwave-sintern-class (match-string 3)))
2505 (name (idlwave-sintern-routine-or-method (match-string 4) class)))
2506 (list name type class)))))
2507
2508 (defvar idlwave-shell-prompt-pattern)
2509 (defun idlwave-beginning-of-statement ()
2510 "Move to beginning of the current statement.
2511 Skips back past statement continuations.
2512 Point is placed at the beginning of the line whether or not this is an
2513 actual statement."
2514 (interactive)
2515 (cond
2516 ((eq major-mode 'idlwave-shell-mode)
2517 (if (re-search-backward idlwave-shell-prompt-pattern nil t)
2518 (goto-char (match-end 0))))
2519 (t
2520 (if (save-excursion (forward-line -1) (idlwave-is-continuation-line))
2521 (idlwave-previous-statement)
2522 (beginning-of-line)))))
2523
2524 (defun idlwave-previous-statement ()
2525 "Moves point to beginning of the previous statement.
2526 Returns t if the current line before moving is the beginning of
2527 the first non-comment statement in the file, and nil otherwise."
2528 (interactive)
2529 (let (first-statement)
2530 (if (not (= (forward-line -1) 0))
2531 ;; first line in file
2532 t
2533 ;; skip blank lines, label lines, include lines and line comments
2534 (while (and
2535 ;; The current statement is the first statement until we
2536 ;; reach another statement.
2537 (setq first-statement
2538 (or
2539 (looking-at idlwave-comment-line-start-skip)
2540 (looking-at "[ \t]*$")
2541 (looking-at (concat "[ \t]*" idlwave-label "[ \t]*$"))
2542 (looking-at "^@")))
2543 (= (forward-line -1) 0)))
2544 ;; skip continuation lines
2545 (while (and
2546 (save-excursion
2547 (forward-line -1)
2548 (idlwave-is-continuation-line))
2549 (= (forward-line -1) 0)))
2550 first-statement)))
2551
2552 (defun idlwave-end-of-statement ()
2553 "Moves point to the end of the current IDL statement.
2554 If not in a statement just moves to end of line. Returns position."
2555 (interactive)
2556 (while (and (idlwave-is-continuation-line)
2557 (= (forward-line 1) 0))
2558 (while (and (idlwave-is-comment-or-empty-line)
2559 (= (forward-line 1) 0))))
2560 (end-of-line)
2561 (point))
2562
2563 (defun idlwave-end-of-statement0 ()
2564 "Moves point to the end of the current IDL statement.
2565 If not in a statement just moves to end of line. Returns position."
2566 (interactive)
2567 (while (and (idlwave-is-continuation-line)
2568 (= (forward-line 1) 0)))
2569 (end-of-line)
2570 (point))
2571
2572 (defun idlwave-next-statement ()
2573 "Moves point to beginning of the next IDL statement.
2574 Returns t if that statement is the last
2575 non-comment IDL statement in the file, and nil otherwise."
2576 (interactive)
2577 (let (last-statement)
2578 (idlwave-end-of-statement)
2579 ;; skip blank lines, label lines, include lines and line comments
2580 (while (and (= (forward-line 1) 0)
2581 ;; The current statement is the last statement until
2582 ;; we reach a new statement.
2583 (setq last-statement
2584 (or
2585 (looking-at idlwave-comment-line-start-skip)
2586 (looking-at "[ \t]*$")
2587 (looking-at (concat "[ \t]*" idlwave-label "[ \t]*$"))
2588 (looking-at "^@")))))
2589 last-statement))
2590
2591 (defun idlwave-skip-label-or-case ()
2592 "Skip label or case statement element.
2593 Returns position after label.
2594 If there is no label point is not moved and nil is returned."
2595 ;; Case expressions and labels are terminated by a colon.
2596 ;; So we find the first colon in the line and make sure
2597 ;; - no `?' is before it (might be a ? b : c)
2598 ;; - it is not in a comment
2599 ;; - not in a string constant
2600 ;; - not in parenthesis (like a[0:3])
2601 ;; - not followed by another ":" in explicit class, ala a->b::c
2602 ;; As many in this mode, this function is heuristic and not an exact
2603 ;; parser.
2604 (let* ((start (point))
2605 (eos (save-excursion (idlwave-end-of-statement) (point)))
2606 (end (idlwave-find-key ":" 1 'nomark eos)))
2607 (if (and end
2608 (= (nth 0 (parse-partial-sexp start end)) 0)
2609 (not (string-match "\\?" (buffer-substring start end)))
2610 (not (string-match "^::" (buffer-substring end eos))))
2611 (progn
2612 (forward-char)
2613 (point))
2614 (goto-char start)
2615 nil)))
2616
2617 (defun idlwave-start-of-substatement (&optional pre)
2618 "Move to start of next IDL substatement after point.
2619 Uses the type of the current IDL statement to determine if the next
2620 statement is on a new line or is a subpart of the current statement.
2621 Returns point at start of substatement modulo whitespace.
2622 If optional argument is non-nil move to beginning of current
2623 substatement."
2624 (let ((orig (point))
2625 (eos (idlwave-end-of-statement))
2626 (ifnest 0)
2627 st nst last)
2628 (idlwave-beginning-of-statement)
2629 (idlwave-skip-label-or-case)
2630 (setq last (point))
2631 ;; Continue looking for substatements until we are past orig
2632 (while (and (<= (point) orig) (not (eobp)))
2633 (setq last (point))
2634 (setq nst (nth 1 (cdr (setq st (car (idlwave-statement-type))))))
2635 (if (equal (car st) 'if) (setq ifnest (1+ ifnest)))
2636 (cond ((and nst
2637 (idlwave-find-key nst 1 'nomark eos))
2638 (goto-char (match-end 0)))
2639 ((and (> ifnest 0) (idlwave-find-key "\\<else\\>" 1 'nomark eos))
2640 (setq ifnest (1- ifnest))
2641 (goto-char (match-end 0)))
2642 (t (setq ifnest 0)
2643 (idlwave-next-statement))))
2644 (if pre (goto-char last))
2645 ;; If a continuation line starts here, move to next line
2646 (if (looking-at "[ \t]*\\$\\([ \t]*\\(;\\|$\\)\\)")
2647 (beginning-of-line 2))
2648 (point)))
2649
2650 (defun idlwave-statement-type ()
2651 "Return the type of the current IDL statement.
2652 Uses `idlwave-statement-match' to return a cons of (type . point) with
2653 point the ending position where the type was determined. Type is the
2654 association from `idlwave-statement-match', i.e. the cons cell from the
2655 list not just the type symbol. Returns nil if not an identifiable
2656 statement."
2657 (save-excursion
2658 ;; Skip whitespace within a statement which is spaces, tabs, continuations
2659 (while (looking-at "[ \t]*\\<\\$")
2660 (forward-line 1))
2661 (skip-chars-forward " \t")
2662 (let ((st idlwave-statement-match)
2663 (case-fold-search t))
2664 (while (and (not (looking-at (nth 0 (cdr (car st)))))
2665 (setq st (cdr st))))
2666 (if st
2667 (append st (match-end 0))))))
2668
2669 (defun idlwave-expand-equal (&optional before after)
2670 "Pad '=' with spaces.
2671 Two cases: Assignment statement, and keyword assignment.
2672 The case is determined using `idlwave-start-of-substatement' and
2673 `idlwave-statement-type'.
2674 The equal sign will be surrounded by BEFORE and AFTER blanks.
2675 If `idlwave-pad-keyword' is t then keyword assignment is treated just
2676 like assignment statements. When nil, spaces are removed for keyword
2677 assignment. Any other value keeps the current space around the `='.
2678 Limits in for loops are treated as keyword assignment.
2679 See `idlwave-surround'. "
2680 ;; Even though idlwave-surround checks `idlwave-surround-by-blank' this
2681 ;; check saves the time of finding the statement type.
2682 (if idlwave-surround-by-blank
2683 (let ((st (save-excursion
2684 (idlwave-start-of-substatement t)
2685 (idlwave-statement-type))))
2686
2687 (cond ((or (and (equal (car (car st)) 'assign)
2688 (equal (cdr st) (point)))
2689 (eq t idlwave-pad-keyword))
2690 ;; An assignment statement or keywor and we need padding
2691 (idlwave-surround before after))
2692 ((null idlwave-pad-keyword)
2693 ;; Spaces should be removed at a keyword
2694 (idlwave-surround 0 0))
2695 (t)))))
2696
2697 (defun idlwave-indent-and-action (&optional arg)
2698 "Call `idlwave-indent-line' and do expand actions.
2699 With prefix ARG non-nil, indent the entire sub-statement."
2700 (interactive "p")
2701 (save-excursion
2702 (if (and idlwave-expand-generic-end
2703 (re-search-backward "\\<\\(end\\)\\s-*\\="
2704 (max 0 (- (point) 10)) t)
2705 (looking-at "\\(end\\)\\([ \n\t]\\|\\'\\)"))
2706 (progn (goto-char (match-end 1))
2707 ;;Expand the END abbreviation, just as RET or Space would have.
2708 (if abbrev-mode (expand-abbrev)
2709 (idlwave-show-begin)))))
2710 (if arg
2711 (idlwave-indent-statement)
2712 (idlwave-indent-line t)))
2713
2714 (defun idlwave-indent-line (&optional expand)
2715 "Indents current IDL line as code or as a comment.
2716 The actions in `idlwave-indent-action-table' are performed.
2717 If the optional argument EXPAND is non-nil then the actions in
2718 `idlwave-indent-expand-table' are performed."
2719 (interactive)
2720 ;; Move point out of left margin.
2721 (if (save-excursion
2722 (skip-chars-backward " \t")
2723 (bolp))
2724 (skip-chars-forward " \t"))
2725 (let ((mloc (point-marker)))
2726 (save-excursion
2727 (beginning-of-line)
2728 (if (looking-at idlwave-comment-line-start-skip)
2729 ;; Indentation for a line comment
2730 (progn
2731 (skip-chars-forward " \t")
2732 (idlwave-indent-left-margin (idlwave-comment-hook)))
2733 ;;
2734 ;; Code Line
2735 ;;
2736 ;; Before indenting, run action routines.
2737 ;;
2738 (if (and expand idlwave-do-actions)
2739 (mapcar 'idlwave-do-action idlwave-indent-expand-table))
2740 ;;
2741 (if idlwave-do-actions
2742 (mapcar 'idlwave-do-action idlwave-indent-action-table))
2743 ;;
2744 ;; No longer expand abbrevs on the line. The user can do this
2745 ;; manually using expand-region-abbrevs.
2746 ;;
2747 ;; Indent for code line
2748 ;;
2749 (beginning-of-line)
2750 (if (or
2751 ;; a label line
2752 (looking-at (concat "^" idlwave-label "[ \t]*$"))
2753 ;; a batch command
2754 (looking-at "^[ \t]*@"))
2755 ;; leave flush left
2756 nil
2757 ;; indent the line
2758 (idlwave-indent-left-margin (idlwave-calculate-indent)))
2759 ;; Adjust parallel comment
2760 (end-of-line)
2761 (if (idlwave-in-comment)
2762 (indent-for-comment))))
2763 (goto-char mloc)
2764 ;; Get rid of marker
2765 (set-marker mloc nil)
2766 ))
2767
2768 (defun idlwave-do-action (action)
2769 "Perform an action repeatedly on a line.
2770 ACTION is a list (REG . FUNC). REG is a regular expression. FUNC is
2771 either a function name to be called with `funcall' or a list to be
2772 evaluated with `eval'. The action performed by FUNC should leave point
2773 after the match for REG - otherwise an infinite loop may be entered."
2774 (let ((action-key (car action))
2775 (action-routine (cdr action)))
2776 (beginning-of-line)
2777 (while (idlwave-look-at action-key)
2778 (if (listp action-routine)
2779 (eval action-routine)
2780 (funcall action-routine)))))
2781
2782 (defun idlwave-indent-to (col &optional min)
2783 "Indent from point with spaces until column COL.
2784 Inserts space before markers at point."
2785 (if (not min) (setq min 0))
2786 (insert-before-markers
2787 (make-string (max min (- col (current-column))) ?\ )))
2788
2789 (defun idlwave-indent-left-margin (col)
2790 "Indent the current line to column COL.
2791 Indents such that first non-whitespace character is at column COL
2792 Inserts spaces before markers at point."
2793 (save-excursion
2794 (beginning-of-line)
2795 (delete-horizontal-space)
2796 (idlwave-indent-to col)))
2797
2798 (defun idlwave-indent-subprogram ()
2799 "Indents program unit which contains point."
2800 (interactive)
2801 (save-excursion
2802 (idlwave-end-of-statement)
2803 (idlwave-beginning-of-subprogram)
2804 (let ((beg (point)))
2805 (idlwave-forward-block)
2806 (message "Indenting subprogram...")
2807 (indent-region beg (point) nil))
2808 (message "Indenting subprogram...done.")))
2809
2810 (defun idlwave-indent-statement ()
2811 "Indent current statement, including all continuation lines."
2812 (interactive)
2813 (save-excursion
2814 (idlwave-beginning-of-statement)
2815 (let ((beg (point)))
2816 (idlwave-end-of-statement)
2817 (indent-region beg (point) nil))))
2818
2819 (defun idlwave-calculate-indent ()
2820 "Return appropriate indentation for current line as IDL code."
2821 (save-excursion
2822 (beginning-of-line)
2823 (cond
2824 ;; Check for beginning of unit - main (beginning of buffer), pro, or
2825 ;; function
2826 ((idlwave-look-at idlwave-begin-unit-reg)
2827 0)
2828 ;; Check for continuation line
2829 ((save-excursion
2830 (and (= (forward-line -1) 0)
2831 (idlwave-is-continuation-line)))
2832 (idlwave-calculate-cont-indent))
2833 ;; calculate indent based on previous and current statements
2834 (t (let ((the-indent
2835 ;; calculate indent based on previous statement
2836 (save-excursion
2837 (cond
2838 ((idlwave-previous-statement)
2839 0)
2840 ;; Main block
2841 ((idlwave-look-at idlwave-begin-unit-reg t)
2842 (+ (idlwave-current-statement-indent)
2843 idlwave-main-block-indent))
2844 ;; Begin block
2845 ((idlwave-look-at idlwave-begin-block-reg t)
2846 (+ (idlwave-current-statement-indent)
2847 idlwave-block-indent))
2848 ((idlwave-look-at idlwave-end-block-reg t)
2849 (- (idlwave-current-statement-indent)
2850 idlwave-end-offset
2851 idlwave-block-indent))
2852 ((idlwave-current-statement-indent))))))
2853 ;; adjust the indentation based on the current statement
2854 (cond
2855 ;; End block
2856 ((idlwave-look-at idlwave-end-block-reg)
2857 (+ the-indent idlwave-end-offset))
2858 (the-indent)))))))
2859
2860 ;;
2861 ;; Parentheses balacing/indent
2862 ;;
2863
2864 (defun idlwave-calculate-paren-indent (beg-reg end-reg close-exp)
2865 "Calculate the continuation indent inside a paren group.
2866 Returns a cons-cell with (open . indent), where open is the
2867 location of the open paren"
2868 (let ((open (nth 1 (parse-partial-sexp beg-reg end-reg))))
2869 ;; Found an innermost open paren.
2870 (when open
2871 (goto-char open)
2872 ;; Line up with next word unless this is a closing paren.
2873 (cons open
2874 (cond
2875 ;; This is a closed paren - line up under open paren.
2876 (close-exp
2877 (current-column))
2878 ;; Empty (or just comment) - just line up next to paren
2879 ((progn
2880 ;; Skip paren
2881 (forward-char 1)
2882 (looking-at "[ \t$]*\\(;.*\\)?$"))
2883 (current-column))
2884 ;; Line up with first word after blank space
2885 ((progn
2886 (skip-chars-forward " \t")
2887 (current-column))))))))
2888
2889 (defun idlwave-calculate-cont-indent ()
2890 "Calculates the IDL continuation indent column from the previous statement.
2891 Note that here previous statement means the beginning of the current
2892 statement if this statement is a continuation of the previous line."
2893 (save-excursion
2894 (let* (open
2895 (case-fold-search t)
2896 (end-reg (progn (beginning-of-line) (point)))
2897 (close-exp (progn (skip-chars-forward " \t") (looking-at "\\s)")))
2898 (beg-reg (progn (idlwave-previous-statement) (point)))
2899 (cur-indent (idlwave-current-indent))
2900 (else-cont (and (goto-char end-reg) (looking-at "[ \t]*else")))
2901 (basic-indent ;; The basic, non-fancy indent
2902 (+ cur-indent idlwave-continuation-indent))
2903 (fancy-nonparen-indent ;; A smarter indent for routine/assignments
2904 ;; Try without parens first:
2905 (progn
2906 (goto-char beg-reg)
2907 (while (idlwave-look-at "&")) ; skip over continued statements
2908 (cond
2909 ;; A continued Procedure call or definition
2910 ((progn
2911 (idlwave-look-at "\\(pro\\|function\\)")
2912 (looking-at "[ \t]*\\([a-zA-Z0-9$_]+[ \t]*->[ \t]*\\)?[a-zA-Z][:a-zA-Z0-9$_]*[ \t]*\\(,\\)[ \t]*"))
2913 (goto-char (match-end 0))
2914 ;; Comment only, or blank line with "$"? Align with ,
2915 (if (save-match-data (looking-at "[ \t$]*\\(;.*\\)?$"))
2916 (goto-char (match-end 2)))
2917 (current-column))
2918
2919 ;; Continued assignment (with =),
2920 ((looking-at "[ \t]*[a-zA-Z0-9$_]+[ \t]*\\(=\\)[ \t]*")
2921 (goto-char (match-end 0))
2922 ;; Comment only? Align with =
2923 (if (save-match-data (looking-at "[ \t$]*\\(;.*\\)?$"))
2924 (progn
2925 (goto-char (match-end 1))
2926 (if idlwave-surround-by-blank
2927 (1+ (current-column))
2928 (current-column)))
2929 (current-column))))))
2930 (fancy-nonparen-indent-allowed
2931 (and fancy-nonparen-indent
2932 (< (- fancy-nonparen-indent basic-indent)
2933 idlwave-max-extra-continuation-indent)))
2934 (fancy-paren-indent-cons ;; A smarter indent for paren groups
2935 ;; Look for any enclosing parens
2936 (idlwave-calculate-paren-indent beg-reg end-reg close-exp))
2937 (fancy-paren-open (car fancy-paren-indent-cons))
2938 (fancy-paren-indent (cdr fancy-paren-indent-cons))
2939 (fancy-paren-indent-allowed
2940 (and fancy-paren-indent
2941 (or idlwave-indent-to-open-paren ;; override
2942 (< (- fancy-paren-indent basic-indent)
2943 idlwave-max-extra-continuation-indent))))
2944 fancy-enclosing-parent-indent)
2945 (cond
2946 ;; else continuations are always standard
2947 (else-cont
2948 cur-indent)
2949
2950 ;; an allowed parenthesis-indent
2951 (fancy-paren-indent-allowed
2952 fancy-paren-indent)
2953
2954 ;; a disallowed paren indent nested inside one or more other
2955 ;; parens: indent relative to the first allowed enclosing paren
2956 ;; set, if any... if it's actually a greater indent, just use
2957 ;; the fancy-paren-indent anyway.
2958 ((and fancy-paren-indent
2959 (not fancy-paren-indent-allowed)
2960 (setq fancy-enclosing-paren-indent
2961 (let ((enclose-open fancy-paren-open)
2962 enclose-indent-cons
2963 enclose-indent)
2964 (catch 'loop
2965 (while (setq enclose-indent-cons
2966 (idlwave-calculate-paren-indent
2967 beg-reg (max (1- enclose-open) beg-reg)
2968 nil)
2969 enclose-open (car enclose-indent-cons)
2970 enclose-indent (cdr enclose-indent-cons))
2971 (if (< (- enclose-indent basic-indent)
2972 idlwave-max-extra-continuation-indent)
2973 (throw 'loop enclose-indent)))))))
2974 (min fancy-paren-indent
2975 (+ fancy-enclosing-paren-indent idlwave-continuation-indent)))
2976
2977 ;; a disallowed paren indent inside another type: indent relative
2978 ((and fancy-paren-indent
2979 (not fancy-paren-indent-allowed)
2980 fancy-nonparen-indent-allowed )
2981 (+ fancy-nonparen-indent idlwave-continuation-indent))
2982
2983 ;; an allowed nonparen-only indent
2984 (fancy-nonparen-indent-allowed
2985 fancy-nonparen-indent)
2986
2987 ;; everything else
2988 (t
2989 basic-indent)))))
2990
2991 (defun idlwave-find-key (key-re &optional dir nomark limit)
2992 "Move to next match of the regular expression KEY-RE.
2993 Matches inside comments or string constants will be ignored.
2994 If DIR is negative, the search will be backwards.
2995 At a successful match, the mark is pushed unless NOMARK is non-nil.
2996 Searches are limited to LIMIT.
2997 Searches are case-insensitive and use a special syntax table which
2998 treats `$' and `_' as word characters.
2999 Return value is the beginning of the match or (in case of failure) nil."
3000 (setq dir (or dir 0))
3001 (let ((case-fold-search t)
3002 (search-func (if (> dir 0) 're-search-forward 're-search-backward))
3003 found)
3004 (idlwave-with-special-syntax
3005 (save-excursion
3006 (catch 'exit
3007 (while (funcall search-func key-re limit t)
3008 (if (not (idlwave-quoted))
3009 (throw 'exit (setq found (match-beginning 0))))))))
3010 (if found
3011 (progn
3012 (if (not nomark) (push-mark))
3013 (goto-char found)
3014 found)
3015 nil)))
3016
3017 (defun idlwave-block-jump-out (&optional dir nomark)
3018 "When optional argument DIR is non-negative, move forward to end of
3019 current block using the `idlwave-begin-block-reg' and `idlwave-end-block-reg'
3020 regular expressions. When DIR is negative, move backwards to block beginning.
3021 Recursively calls itself to skip over nested blocks. DIR defaults to
3022 forward. Calls `push-mark' unless the optional argument NOMARK is
3023 non-nil. Movement is limited by the start of program units because of
3024 possibility of unbalanced blocks."
3025 (interactive "P")
3026 (or dir (setq dir 0))
3027 (let* ((here (point))
3028 (case-fold-search t)
3029 (limit (if (>= dir 0) (point-max) (point-min)))
3030 (block-limit (if (>= dir 0)
3031 idlwave-begin-block-reg
3032 idlwave-end-block-reg))
3033 found
3034 (block-reg (concat idlwave-begin-block-reg "\\|"
3035 idlwave-end-block-reg))
3036 (unit-limit (or (save-excursion
3037 (if (< dir 0)
3038 (idlwave-find-key
3039 idlwave-begin-unit-reg dir t limit)
3040 (end-of-line)
3041 (idlwave-find-key
3042 idlwave-end-unit-reg dir t limit)))
3043 limit)))
3044 (if (>= dir 0) (end-of-line)) ;Make sure we are in current block
3045 (if (setq found (idlwave-find-key block-reg dir t unit-limit))
3046 (while (and found (looking-at block-limit))
3047 (if (>= dir 0) (forward-word 1))
3048 (idlwave-block-jump-out dir t)
3049 (setq found (idlwave-find-key block-reg dir t unit-limit))))
3050 (if (not nomark) (push-mark here))
3051 (if (not found) (goto-char unit-limit)
3052 (if (>= dir 0) (forward-word 1)))))
3053
3054 (defun idlwave-current-statement-indent ()
3055 "Return indentation of the current statement.
3056 If in a statement, moves to beginning of statement before finding indent."
3057 (idlwave-beginning-of-statement)
3058 (idlwave-current-indent))
3059
3060 (defun idlwave-current-indent ()
3061 "Return the column of the indentation of the current line.
3062 Skips any whitespace. Returns 0 if the end-of-line follows the whitespace."
3063 (save-excursion
3064 (beginning-of-line)
3065 (skip-chars-forward " \t")
3066 ;; if we are at the end of blank line return 0
3067 (cond ((eolp) 0)
3068 ((current-column)))))
3069
3070 (defun idlwave-is-continuation-line ()
3071 "Tests if current line is continuation line.
3072 Blank or comment-only lines following regular continuation lines (with
3073 `$') count as continuations too."
3074 (save-excursion
3075 (or
3076 (idlwave-look-at "\\<\\$")
3077 (catch 'loop
3078 (while (and (looking-at "^[ \t]*\\(;.*\\)?$")
3079 (eq (forward-line -1) 0))
3080 (if (idlwave-look-at "\\<\\$") (throw 'loop t)))))))
3081
3082 (defun idlwave-is-comment-line ()
3083 "Tests if the current line is a comment line."
3084 (save-excursion
3085 (beginning-of-line 1)
3086 (looking-at "[ \t]*;")))
3087
3088 (defun idlwave-is-comment-or-empty-line ()
3089 "Tests if the current line is a comment line."
3090 (save-excursion
3091 (beginning-of-line 1)
3092 (looking-at "[ \t]*[;\n]")))
3093
3094 (defun idlwave-look-at (regexp &optional cont beg)
3095 "Searches current line from current point for REGEXP.
3096 If optional argument CONT is non-nil, searches to the end of
3097 the current statement.
3098 If optional arg BEG is non-nil, search starts from the beginning of the
3099 current statement.
3100 Ignores matches that end in a comment or inside a string expression.
3101 Returns point if successful, nil otherwise.
3102 This function produces unexpected results if REGEXP contains quotes or
3103 a comment delimiter. The search is case insensitive.
3104 If successful leaves point after the match, otherwise, does not move point."
3105 (let ((here (point))
3106 (case-fold-search t)
3107 (eos (save-excursion
3108 (if cont (idlwave-end-of-statement) (end-of-line))
3109 (point)))
3110 found)
3111 (idlwave-with-special-syntax
3112 (if beg (idlwave-beginning-of-statement))
3113 (while (and (setq found (re-search-forward regexp eos t))
3114 (idlwave-quoted))))
3115 (if (not found) (goto-char here))
3116 found))
3117
3118 (defun idlwave-fill-paragraph (&optional nohang)
3119 "Fills paragraphs in comments.
3120 A paragraph is made up of all contiguous lines having the same comment
3121 leader (the leading whitespace before the comment delimiter and the
3122 comment delimiter). In addition, paragraphs are separated by blank
3123 line comments. The indentation is given by the hanging indent of the
3124 first line, otherwise by the minimum indentation of the lines after
3125 the first line. The indentation of the first line does not change.
3126 Does not effect code lines. Does not fill comments on the same line
3127 with code. The hanging indent is given by the end of the first match
3128 matching `idlwave-hang-indent-regexp' on the paragraph's first line . If the
3129 optional argument NOHANG is non-nil then the hanging indent is
3130 ignored."
3131 (interactive "P")
3132 ;; check if this is a line comment
3133 (if (save-excursion
3134 (beginning-of-line)
3135 (skip-chars-forward " \t")
3136 (looking-at comment-start))
3137 (let
3138 ((indent 999)
3139 pre here diff fill-prefix-reg bcl first-indent
3140 hang start end)
3141 ;; Change tabs to spaces in the surrounding paragraph.
3142 ;; The surrounding paragraph will be the largest containing block of
3143 ;; contiguous line comments. Thus, we may be changing tabs in
3144 ;; a much larger area than is needed, but this is the easiest
3145 ;; brute force way to do it.
3146 ;;
3147 ;; This has the undesirable side effect of replacing the tabs
3148 ;; permanently without the user's request or knowledge.
3149 (save-excursion
3150 (backward-paragraph)
3151 (setq start (point)))
3152 (save-excursion
3153 (forward-paragraph)
3154 (setq end (point)))
3155 (untabify start end)
3156 ;;
3157 (setq here (point))
3158 (beginning-of-line)
3159 (setq bcl (point))
3160 (re-search-forward
3161 (concat "^[ \t]*" comment-start "+")
3162 (save-excursion (end-of-line) (point))
3163 t)
3164 ;; Get the comment leader on the line and its length
3165 (setq pre (current-column))
3166 ;; the comment leader is the indentation plus exactly the
3167 ;; number of consecutive ";".
3168 (setq fill-prefix-reg
3169 (concat
3170 (setq fill-prefix
3171 (regexp-quote
3172 (buffer-substring (save-excursion
3173 (beginning-of-line) (point))
3174 (point))))
3175 "[^;]"))
3176
3177 ;; Mark the beginning and end of the paragraph
3178 (goto-char bcl)
3179 (while (and (looking-at fill-prefix-reg)
3180 (not (looking-at paragraph-separate))
3181 (not (bobp)))
3182 (forward-line -1))
3183 ;; Move to first line of paragraph
3184 (if (/= (point) bcl)
3185 (forward-line 1))
3186 (setq start (point))
3187 (goto-char bcl)
3188 (while (and (looking-at fill-prefix-reg)
3189 (not (looking-at paragraph-separate))
3190 (not (eobp)))
3191 (forward-line 1))
3192 (beginning-of-line)
3193 (if (or (not (looking-at fill-prefix-reg))
3194 (looking-at paragraph-separate))
3195 (forward-line -1))
3196 (end-of-line)
3197 ;; if at end of buffer add a newline (need this because
3198 ;; fill-region needs END to be at the beginning of line after
3199 ;; the paragraph or it will add a line).
3200 (if (eobp)
3201 (progn (insert ?\n) (backward-char 1)))
3202 ;; Set END to the beginning of line after the paragraph
3203 ;; END is calculated as distance from end of buffer
3204 (setq end (- (point-max) (point) 1))
3205 ;;
3206 ;; Calculate the indentation for the paragraph.
3207 ;;
3208 ;; In the following while statements, after one iteration
3209 ;; point will be at the beginning of a line in which case
3210 ;; the while will not be executed for the
3211 ;; the first paragraph line and thus will not affect the
3212 ;; indentation.
3213 ;;
3214 ;; First check to see if indentation is based on hanging indent.
3215 (if (and (not nohang) idlwave-hanging-indent
3216 (setq hang
3217 (save-excursion
3218 (goto-char start)
3219 (idlwave-calc-hanging-indent))))
3220 ;; Adjust lines of paragraph by inserting spaces so that
3221 ;; each line's indent is at least as great as the hanging
3222 ;; indent. This is needed for fill-paragraph to work with
3223 ;; a fill-prefix.
3224 (progn
3225 (setq indent hang)
3226 (beginning-of-line)
3227 (while (> (point) start)
3228 (re-search-forward comment-start-skip
3229 (save-excursion (end-of-line) (point))
3230 t)
3231 (if (> (setq diff (- indent (current-column))) 0)
3232 (progn
3233 (if (>= here (point))
3234 ;; adjust the original location for the
3235 ;; inserted text.
3236 (setq here (+ here diff)))
3237 (insert (make-string diff ?\ ))))
3238 (forward-line -1))
3239 )
3240
3241 ;; No hang. Instead find minimum indentation of paragraph
3242 ;; after first line.
3243 ;; For the following while statement, since START is at the
3244 ;; beginning of line and END is at the end of line
3245 ;; point is greater than START at least once (which would
3246 ;; be the case for a single line paragraph).
3247 (while (> (point) start)
3248 (beginning-of-line)
3249 (setq indent
3250 (min indent
3251 (progn
3252 (re-search-forward
3253 comment-start-skip
3254 (save-excursion (end-of-line) (point))
3255 t)
3256 (current-column))))
3257 (forward-line -1))
3258 )
3259 (setq fill-prefix (concat fill-prefix
3260 (make-string (- indent pre)
3261 ?\ )))
3262 ;; first-line indent
3263 (setq first-indent
3264 (max
3265 (progn
3266 (re-search-forward
3267 comment-start-skip
3268 (save-excursion (end-of-line) (point))
3269 t)
3270 (current-column))
3271 indent))
3272
3273 ;; try to keep point at its original place
3274 (goto-char here)
3275
3276 ;; In place of the more modern fill-region-as-paragraph, a hack
3277 ;; to keep whitespace untouched on the first line within the
3278 ;; indent length and to preserve any indent on the first line
3279 ;; (first indent).
3280 (save-excursion
3281 (setq diff
3282 (buffer-substring start (+ start first-indent -1)))
3283 (subst-char-in-region start (+ start first-indent -1) ?\ ?~ nil)
3284 (fill-region-as-paragraph
3285 start
3286 (- (point-max) end)
3287 (current-justification)
3288 nil)
3289 (delete-region start (+ start first-indent -1))
3290 (goto-char start)
3291 (insert diff))
3292 ;; When we want the point at the beginning of the comment
3293 ;; body fill-region will put it at the beginning of the line.
3294 (if (bolp) (skip-chars-forward (concat " \t" comment-start)))
3295 (setq fill-prefix nil))))
3296
3297 (defun idlwave-calc-hanging-indent ()
3298 "Calculate the position of the hanging indent for the comment
3299 paragraph. The hanging indent position is given by the first match
3300 with the `idlwave-hang-indent-regexp'. If `idlwave-use-last-hang-indent' is
3301 non-nil then use last occurrence matching `idlwave-hang-indent-regexp' on
3302 the line.
3303 If not found returns nil."
3304 (if idlwave-use-last-hang-indent
3305 (save-excursion
3306 (end-of-line)
3307 (if (re-search-backward
3308 idlwave-hang-indent-regexp
3309 (save-excursion (beginning-of-line) (point))
3310 t)
3311 (+ (current-column) (length idlwave-hang-indent-regexp))))
3312 (save-excursion
3313 (beginning-of-line)
3314 (if (re-search-forward
3315 idlwave-hang-indent-regexp
3316 (save-excursion (end-of-line) (point))
3317 t)
3318 (current-column)))))
3319
3320 (defun idlwave-auto-fill ()
3321 "Called to break lines in auto fill mode.
3322 Only fills comment lines if `idlwave-fill-comment-line-only' is non-nil.
3323 Places a continuation character at the end of the line
3324 if not in a comment. Splits strings with IDL concatenation operator
3325 `+' if `idlwave-auto-fill-split-string is non-nil."
3326 (if (<= (current-column) fill-column)
3327 nil ; do not to fill
3328 (if (or (not idlwave-fill-comment-line-only)
3329 (save-excursion
3330 ;; Check for comment line
3331 (beginning-of-line)
3332 (looking-at idlwave-comment-line-start-skip)))
3333 (let (beg)
3334 (idlwave-indent-line)
3335 ;; Prevent actions do-auto-fill which calls indent-line-function.
3336 (let (idlwave-do-actions
3337 (paragraph-start ".")
3338 (paragraph-separate "."))
3339 (do-auto-fill))
3340 (save-excursion
3341 (end-of-line 0)
3342 ;; Indent the split line
3343 (idlwave-indent-line)
3344 )
3345 (if (save-excursion
3346 (beginning-of-line)
3347 (looking-at idlwave-comment-line-start-skip))
3348 ;; A continued line comment
3349 ;; We treat continued line comments as part of a comment
3350 ;; paragraph. So we check for a hanging indent.
3351 (if idlwave-hanging-indent
3352 (let ((here (- (point-max) (point)))
3353 (indent
3354 (save-excursion
3355 (forward-line -1)
3356 (idlwave-calc-hanging-indent))))
3357 (if indent
3358 (progn
3359 ;; Remove whitespace between comment delimiter and
3360 ;; text, insert spaces for appropriate indentation.
3361 (beginning-of-line)
3362 (re-search-forward
3363 comment-start-skip
3364 (save-excursion (end-of-line) (point)) t)
3365 (delete-horizontal-space)
3366 (idlwave-indent-to indent)
3367 (goto-char (- (point-max) here)))
3368 )))
3369 ;; Split code or comment?
3370 (if (save-excursion
3371 (end-of-line 0)
3372 (idlwave-in-comment))
3373 ;; Splitting a non-line comment.
3374 ;; Insert the comment delimiter from split line
3375 (progn
3376 (save-excursion
3377 (beginning-of-line)
3378 (skip-chars-forward " \t")
3379 ;; Insert blank to keep off beginning of line
3380 (insert " "
3381 (save-excursion
3382 (forward-line -1)
3383 (buffer-substring (idlwave-goto-comment)
3384 (progn
3385 (skip-chars-forward "; ")
3386 (point))))))
3387 (idlwave-indent-line))
3388 ;; Split code line - add continuation character
3389 (save-excursion
3390 (end-of-line 0)
3391 ;; Check to see if we split a string
3392 (if (and (setq beg (idlwave-in-quote))
3393 idlwave-auto-fill-split-string)
3394 ;; Split the string and concatenate.
3395 ;; The first extra space is for the space
3396 ;; the line was split. That space was removed.
3397 (insert " " (char-after beg) " +"))
3398 (insert " $"))
3399 (if beg
3400 (if idlwave-auto-fill-split-string
3401 ;; Make the second part of continued string
3402 (save-excursion
3403 (beginning-of-line)
3404 (skip-chars-forward " \t")
3405 (insert (char-after beg)))
3406 ;; Warning
3407 (beep)
3408 (message "Warning: continuation inside a string.")))
3409 ;; Although do-auto-fill (via indent-new-comment-line) calls
3410 ;; idlwave-indent-line for the new line, re-indent again
3411 ;; because of the addition of the continuation character.
3412 (idlwave-indent-line))
3413 )))))
3414
3415 (defun idlwave-auto-fill-mode (arg)
3416 "Toggle auto-fill mode for IDL mode.
3417 With arg, turn auto-fill mode on if arg is positive.
3418 In auto-fill mode, inserting a space at a column beyond `fill-column'
3419 automatically breaks the line at a previous space."
3420 (interactive "P")
3421 (prog1 (set idlwave-fill-function
3422 (if (if (null arg)
3423 (not (symbol-value idlwave-fill-function))
3424 (> (prefix-numeric-value arg) 0))
3425 'idlwave-auto-fill
3426 nil))
3427 ;; update mode-line
3428 (set-buffer-modified-p (buffer-modified-p))))
3429
3430 (defun idlwave-doc-header (&optional nomark )
3431 "Insert a documentation header at the beginning of the unit.
3432 Inserts the value of the variable idlwave-file-header. Sets mark before
3433 moving to do insertion unless the optional prefix argument NOMARK
3434 is non-nil."
3435 (interactive "P")
3436 (or nomark (push-mark))
3437 ;; make sure we catch the current line if it begins the unit
3438 (if idlwave-header-to-beginning-of-file
3439 (goto-char (point-min))
3440 (end-of-line)
3441 (idlwave-beginning-of-subprogram)
3442 (beginning-of-line)
3443 ;; skip function or procedure line
3444 (if (idlwave-look-at "\\<\\(pro\\|function\\)\\>")
3445 (progn
3446 (idlwave-end-of-statement)
3447 (if (> (forward-line 1) 0) (insert "\n")))))
3448 (let ((pos (point)))
3449 (if idlwave-file-header
3450 (cond ((car idlwave-file-header)
3451 (insert-file (car idlwave-file-header)))
3452 ((stringp (car (cdr idlwave-file-header)))
3453 (insert (car (cdr idlwave-file-header))))))
3454 (goto-char pos)))
3455
3456 (defun idlwave-default-insert-timestamp ()
3457 "Default timestamp insertion function"
3458 (insert (current-time-string))
3459 (insert ", " (user-full-name))
3460 (if (boundp 'user-mail-address)
3461 (insert " <" user-mail-address ">")
3462 (insert " <" (user-login-name) "@" (system-name) ">"))
3463 ;; Remove extra spaces from line
3464 (idlwave-fill-paragraph)
3465 ;; Insert a blank line comment to separate from the date entry -
3466 ;; will keep the entry from flowing onto date line if re-filled.
3467 (insert "\n;\n;\t\t"))
3468
3469 (defun idlwave-doc-modification ()
3470 "Insert a brief modification log at the beginning of the current program.
3471 Looks for an occurrence of the value of user variable
3472 `idlwave-doc-modifications-keyword' if non-nil. Inserts time and user name
3473 and places the point for the user to add a log. Before moving, saves
3474 location on mark ring so that the user can return to previous point."
3475 (interactive)
3476 (push-mark)
3477 (let* (beg end)
3478 (if (and (or (re-search-backward idlwave-doclib-start nil t)
3479 (progn
3480 (goto-char (point-min))
3481 (re-search-forward idlwave-doclib-start nil t)))
3482 (setq beg (match-beginning 0))
3483 (re-search-forward idlwave-doclib-end nil t)
3484 (setq end (match-end 0)))
3485 (progn
3486 (goto-char beg)
3487 (if (re-search-forward
3488 (concat idlwave-doc-modifications-keyword ":")
3489 end t)
3490 (end-of-line)
3491 (goto-char end)
3492 (end-of-line -1)
3493 (insert "\n" comment-start "\n")
3494 (insert comment-start " " idlwave-doc-modifications-keyword ":"))
3495 (insert "\n;\n;\t")
3496 (run-hooks 'idlwave-timestamp-hook))
3497 (error "No valid DOCLIB header"))))
3498
3499 ;;; CJC 3/16/93
3500 ;;; Interface to expand-region-abbrevs which did not work when the
3501 ;;; abbrev hook associated with an abbrev moves point backwards
3502 ;;; after abbrev expansion, e.g., as with the abbrev '.n'.
3503 ;;; The original would enter an infinite loop in attempting to expand
3504 ;;; .n (it would continually expand and unexpand the abbrev without expanding
3505 ;;; because the point would keep going back to the beginning of the
3506 ;;; abbrev instead of to the end of the abbrev). We now keep the
3507 ;;; abbrev hook from moving backwards.
3508 ;;;
3509 (defun idlwave-expand-region-abbrevs (start end)
3510 "Expand each abbrev occurrence in the region.
3511 Calling from a program, arguments are START END."
3512 (interactive "r")
3513 (save-excursion
3514 (goto-char (min start end))
3515 (let ((idlwave-show-block nil) ;Do not blink
3516 (idlwave-abbrev-move nil)) ;Do not move
3517 (expand-region-abbrevs start end 'noquery))))
3518
3519 (defun idlwave-quoted ()
3520 "Returns t if point is in a comment or quoted string.
3521 nil otherwise."
3522 (or (idlwave-in-comment) (idlwave-in-quote)))
3523
3524 (defun idlwave-in-quote ()
3525 "Returns location of the opening quote
3526 if point is in a IDL string constant, nil otherwise.
3527 Ignores comment delimiters on the current line.
3528 Properly handles nested quotation marks and octal
3529 constants - a double quote followed by an octal digit."
3530 ;;; Treat an octal inside an apostrophe to be a normal string. Treat a
3531 ;;; double quote followed by an octal digit to be an octal constant
3532 ;;; rather than a string. Therefore, there is no terminating double
3533 ;;; quote.
3534 (save-excursion
3535 ;; Because single and double quotes can quote each other we must
3536 ;; search for the string start from the beginning of line.
3537 (let* ((start (point))
3538 (eol (progn (end-of-line) (point)))
3539 (bq (progn (beginning-of-line) (point)))
3540 (endq (point))
3541 (data (match-data))
3542 delim
3543 found)
3544 (while (< endq start)
3545 ;; Find string start
3546 ;; Don't find an octal constant beginning with a double quote
3547 (if (re-search-forward "\"[^0-7]\\|'\\|\"$" eol 'lim)
3548 ;; Find the string end.
3549 ;; In IDL, two consecutive delimiters after the start of a
3550 ;; string act as an
3551 ;; escape for the delimiter in the string.
3552 ;; Two consecutive delimiters alone (i.e., not after the
3553 ;; start of a string) is the null string.
3554 (progn
3555 ;; Move to position after quote
3556 (goto-char (1+ (match-beginning 0)))
3557 (setq bq (1- (point)))
3558 ;; Get the string delimiter
3559 (setq delim (char-to-string (preceding-char)))
3560 ;; Check for null string
3561 (if (looking-at delim)
3562 (progn (setq endq (point)) (forward-char 1))
3563 ;; Look for next unpaired delimiter
3564 (setq found (search-forward delim eol 'lim))
3565 (while (looking-at delim)
3566 (forward-char 1)
3567 (setq found (search-forward delim eol 'lim)))
3568 (if found
3569 (setq endq (- (point) 1))
3570 (setq endq (point)))
3571 ))
3572 (progn (setq bq (point)) (setq endq (point)))))
3573 (store-match-data data)
3574 ;; return string beginning position or nil
3575 (if (> start bq) bq))))
3576
3577 ;; Statement templates
3578
3579 ;; Replace these with a general template function, something like
3580 ;; expand.el (I think there was also something with a name similar to
3581 ;; dmacro.el)
3582
3583 (defun idlwave-template (s1 s2 &optional prompt noindent)
3584 "Build a template with optional prompt expression.
3585
3586 Opens a line if point is not followed by a newline modulo intervening
3587 whitespace. S1 and S2 are strings. S1 is inserted at point followed
3588 by S2. Point is inserted between S1 and S2. The case of S1 and S2 is
3589 adjusted according to `idlwave-abbrev-change-case'. If optional argument
3590 PROMPT is a string then it is displayed as a message in the
3591 minibuffer. The PROMPT serves as a reminder to the user of an
3592 expression to enter.
3593
3594 The lines containing S1 and S2 are reindented using `indent-region'
3595 unless the optional second argument NOINDENT is non-nil."
3596 (if (eq major-mode 'idlwave-shell-mode)
3597 ;; This is a gross hack to avoit template abbrev expansion
3598 ;; in the shell. FIXME: This is a dirty hack.
3599 (if (and (eq this-command 'self-insert-command)
3600 (equal last-abbrev-location (point)))
3601 (insert last-abbrev-text)
3602 (error "No templates in idlwave-shell"))
3603 (cond ((eq idlwave-abbrev-change-case 'down)
3604 (setq s1 (downcase s1) s2 (downcase s2)))
3605 (idlwave-abbrev-change-case
3606 (setq s1 (upcase s1) s2 (upcase s2))))
3607 (let ((beg (save-excursion (beginning-of-line) (point)))
3608 end)
3609 (if (not (looking-at "\\s-*\n"))
3610 (open-line 1))
3611 (insert s1)
3612 (save-excursion
3613 (insert s2)
3614 (setq end (point)))
3615 (if (not noindent)
3616 (indent-region beg end nil))
3617 (if (stringp prompt)
3618 (message prompt)))))
3619
3620 (defun idlwave-rw-case (string)
3621 "Make STRING have the case required by `idlwave-reserved-word-upcase'."
3622 (if idlwave-reserved-word-upcase
3623 (upcase string)
3624 string))
3625
3626 (defun idlwave-elif ()
3627 "Build skeleton IDL if-else block."
3628 (interactive)
3629 (idlwave-template
3630 (idlwave-rw-case "if")
3631 (idlwave-rw-case " then begin\n\nendif else begin\n\nendelse")
3632 "Condition expression"))
3633
3634 (defun idlwave-case ()
3635 "Build skeleton IDL case statement."
3636 (interactive)
3637 (idlwave-template
3638 (idlwave-rw-case "case")
3639 (idlwave-rw-case " of\n\nendcase")
3640 "Selector expression"))
3641
3642 (defun idlwave-switch ()
3643 "Build skeleton IDL switch statement."
3644 (interactive)
3645 (idlwave-template
3646 (idlwave-rw-case "switch")
3647 (idlwave-rw-case " of\n\nendswitch")
3648 "Selector expression"))
3649
3650 (defun idlwave-for ()
3651 "Build skeleton for loop statment."
3652 (interactive)
3653 (idlwave-template
3654 (idlwave-rw-case "for")
3655 (idlwave-rw-case " do begin\n\nendfor")
3656 "Loop expression"))
3657
3658 (defun idlwave-if ()
3659 "Build skeleton for loop statment."
3660 (interactive)
3661 (idlwave-template
3662 (idlwave-rw-case "if")
3663 (idlwave-rw-case " then begin\n\nendif")
3664 "Scalar logical expression"))
3665
3666 (defun idlwave-procedure ()
3667 (interactive)
3668 (idlwave-template
3669 (idlwave-rw-case "pro")
3670 (idlwave-rw-case "\n\nreturn\nend")
3671 "Procedure name"))
3672
3673 (defun idlwave-function ()
3674 (interactive)
3675 (idlwave-template
3676 (idlwave-rw-case "function")
3677 (idlwave-rw-case "\n\nreturn\nend")
3678 "Function name"))
3679
3680 (defun idlwave-repeat ()
3681 (interactive)
3682 (idlwave-template
3683 (idlwave-rw-case "repeat begin\n\nendrep until")
3684 (idlwave-rw-case "")
3685 "Exit condition"))
3686
3687 (defun idlwave-while ()
3688 (interactive)
3689 (idlwave-template
3690 (idlwave-rw-case "while")
3691 (idlwave-rw-case " do begin\n\nendwhile")
3692 "Entry condition"))
3693
3694 (defun idlwave-split-string (string &optional pattern)
3695 "Return a list of substrings of STRING which are separated by PATTERN.
3696 If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
3697 (or pattern
3698 (setq pattern "[ \f\t\n\r\v]+"))
3699 (let (parts (start 0))
3700 (while (string-match pattern string start)
3701 (setq parts (cons (substring string start (match-beginning 0)) parts)
3702 start (match-end 0)))
3703 (nreverse (cons (substring string start) parts))))
3704
3705 (defun idlwave-replace-string (string replace_string replace_with)
3706 (let* ((start 0)
3707 (last (length string))
3708 (ret_string "")
3709 end)
3710 (while (setq end (string-match replace_string string start))
3711 (setq ret_string
3712 (concat ret_string (substring string start end) replace_with))
3713 (setq start (match-end 0)))
3714 (setq ret_string (concat ret_string (substring string start last)))))
3715
3716 (defun idlwave-get-buffer-visiting (file)
3717 ;; Return the buffer currently visiting FILE
3718 (cond
3719 ((boundp 'find-file-compare-truenames) ; XEmacs
3720 (let ((find-file-compare-truenames t))
3721 (get-file-buffer file)))
3722 ((fboundp 'find-buffer-visiting) ; Emacs
3723 (find-buffer-visiting file))
3724 (t (error "This should not happen (idlwave-get-buffer-visiting)"))))
3725
3726 (defvar idlwave-outlawed-buffers nil
3727 "List of buffer pulled up by idlwave for special reasons.
3728 Buffers in this list may be killed by `idlwave-kill-autoloaded-buffers'.")
3729
3730 (defun idlwave-find-file-noselect (file &optional why)
3731 ;; Return a buffer visiting file.
3732 (or (idlwave-get-buffer-visiting file)
3733 (let ((buf (find-file-noselect file)))
3734 (if why (add-to-list 'idlwave-outlawed-buffers (cons buf why)))
3735 buf)))
3736
3737 (defun idlwave-kill-autoloaded-buffers ()
3738 "Cleanup by killing buffers created automatically by IDLWAVE.
3739 Function prompts for a letter to identify the buffers to kill.
3740 Possible letters are:
3741
3742 f Buffers created by the command \\[idlwave-find-module] or mouse
3743 clicks in the routine info window.
3744 s Buffers created by the IDLWAVE Shell to display where execution
3745 stopped or an error was found.
3746 a Both of the above.
3747
3748 Buffer containing unsaved changes require confirmation before they are killed."
3749 (interactive)
3750 (if (null idlwave-outlawed-buffers)
3751 (error "No IDLWAVE-created buffers available")
3752 (princ (format "Kill IDLWAVE-created buffers: [f]ind source(%d), [s]hell display(%d), [a]ll ? "
3753 (idlwave-count-outlawed-buffers 'find)
3754 (idlwave-count-outlawed-buffers 'shell)))
3755 (let ((c (read-char)))
3756 (cond
3757 ((member c '(?f ?\C-f))
3758 (idlwave-do-kill-autoloaded-buffers 'find))
3759 ((member c '(?s ?\C-s))
3760 (idlwave-do-kill-autoloaded-buffers 'shell))
3761 ((member c '(?a ?\C-a))
3762 (idlwave-do-kill-autoloaded-buffers t))
3763 (t (error "Abort"))))))
3764
3765 (defun idlwave-count-outlawed-buffers (tag)
3766 "How many outlawed buffers have tag TAG?"
3767 (length (delq nil
3768 (mapcar
3769 (lambda (x) (eq (cdr x) tag))
3770 idlwave-outlawed-buffers))))
3771
3772 (defun idlwave-do-kill-autoloaded-buffers (&rest reasons)
3773 "Kill all buffers pulled up by IDLWAVE matching REASONS."
3774 (let* ((list (copy-sequence idlwave-outlawed-buffers))
3775 (cnt 0)
3776 entry)
3777 (while (setq entry (pop list))
3778 (if (buffer-live-p (car entry))
3779 (and (or (memq t reasons)
3780 (memq (cdr entry) reasons))
3781 (kill-buffer (car entry))
3782 (incf cnt)
3783 (setq idlwave-outlawed-buffers
3784 (delq entry idlwave-outlawed-buffers)))
3785 (setq idlwave-outlawed-buffers
3786 (delq entry idlwave-outlawed-buffers))))
3787 (message "%d buffer%s killed" cnt (if (= cnt 1) "" "s"))))
3788
3789 (defun idlwave-revoke-license-to-kill ()
3790 "Remove BUFFER from the buffers which may be killed.
3791 Killing would be done by `idlwave-do-kill-autoloaded-buffers'.
3792 Intended for `after-save-hook'."
3793 (let* ((buf (current-buffer))
3794 (entry (assq buf idlwave-outlawed-buffers)))
3795 ;; Revoke license
3796 (if entry
3797 (setq idlwave-outlawed-buffers
3798 (delq entry idlwave-outlawed-buffers)))
3799 ;; Remove this function from the hook.
3800 (remove-hook 'after-save-hook 'idlwave-revoke-license-to-kill 'local)))
3801
3802 (defvar idlwave-path-alist)
3803 (defun idlwave-locate-lib-file (file)
3804 ;; Find FILE on the scanned lib path and return a buffer visiting it
3805 (let* ((dirs idlwave-path-alist)
3806 dir efile)
3807 (catch 'exit
3808 (while (setq dir (car (pop dirs)))
3809 (if (file-regular-p
3810 (setq efile (expand-file-name file dir)))
3811 (throw 'exit efile))))))
3812 (defun idlwave-expand-lib-file-name (file)
3813 ;; Find FILE on the scanned lib path and return a buffer visiting it
3814 (cond
3815 ((null file) nil)
3816 ((string-match "\\`\\({\\([0-9]+\\)}/\\)\\(.*\\)" file)
3817 (expand-file-name (match-string 3 file)
3818 (car (nth (1- (string-to-int (match-string 2 file)))
3819 idlwave-path-alist))))
3820 ((file-name-absolute-p file) file)
3821 (t (idlwave-locate-lib-file file))))
3822
3823 (defun idlwave-make-tags ()
3824 "Creates the IDL tags file IDLTAGS in the current directory from
3825 the list of directories specified in the minibuffer. Directories may be
3826 for example: . /usr/local/rsi/idl/lib. All the subdirectories of the
3827 specified top directories are searched if the directory name is prefixed
3828 by @. Specify @ directories with care, it may take a long, long time if
3829 you specify /."
3830 (interactive)
3831 (let (directory directories cmd append status numdirs dir getsubdirs
3832 buffer save_buffer files numfiles item errbuf)
3833
3834 ;;
3835 ;; Read list of directories
3836 (setq directory (read-string "Tag Directories: " "."))
3837 (setq directories (idlwave-split-string directory "[ \t]+"))
3838 ;;
3839 ;; Set etags command, vars
3840 (setq cmd "etags --output=IDLTAGS --language=none --regex='/[
3841 \\t]*[pP][Rr][Oo][ \\t]+\\([^ \\t,]+\\)/' --regex='/[
3842 \\t]*[Ff][Uu][Nn][Cc][Tt][Ii][Oo][Nn][ \\t]+\\([^ \\t,]+\\)/' ")
3843 (setq append " ")
3844 (setq status 0)
3845 ;;
3846 ;; For each directory
3847 (setq numdirs 0)
3848 (setq dir (nth numdirs directories))
3849 (while (and dir)
3850 ;;
3851 ;; Find the subdirectories
3852 (if (string-match "^[@]\\(.+\\)$" dir)
3853 (setq getsubdirs t) (setq getsubdirs nil))
3854 (if (and getsubdirs) (setq dir (substring dir 1 (length dir))))
3855 (setq dir (expand-file-name dir))
3856 (if (file-directory-p dir)
3857 (progn
3858 (if (and getsubdirs)
3859 (progn
3860 (setq buffer (get-buffer-create "*idltags*"))
3861 (call-process "sh" nil buffer nil "-c"
3862 (concat "find " dir " -type d -print"))
3863 (setq save_buffer (current-buffer))
3864 (set-buffer buffer)
3865 (setq files (idlwave-split-string
3866 (idlwave-replace-string
3867 (buffer-substring 1 (point-max))
3868 "\n" "/*.pro ")
3869 "[ \t]+"))
3870 (set-buffer save_buffer)
3871 (kill-buffer buffer))
3872 (setq files (list (concat dir "/*.pro"))))
3873 ;;
3874 ;; For each subdirectory
3875 (setq numfiles 0)
3876 (setq item (nth numfiles files))
3877 (while (and item)
3878 ;;
3879 ;; Call etags
3880 (if (not (string-match "^[ \\t]*$" item))
3881 (progn
3882 (message (concat "Tagging " item "..."))
3883 (setq errbuf (get-buffer-create "*idltags-error*"))
3884 (setq status (+ status
3885 (call-process "sh" nil errbuf nil "-c"
3886 (concat cmd append item))))
3887 ;;
3888 ;; Append additional tags
3889 (setq append " --append ")
3890 (setq numfiles (1+ numfiles))
3891 (setq item (nth numfiles files)))
3892 (progn
3893 (setq numfiles (1+ numfiles))
3894 (setq item (nth numfiles files))
3895 )))
3896
3897 (setq numdirs (1+ numdirs))
3898 (setq dir (nth numdirs directories)))
3899 (progn
3900 (setq numdirs (1+ numdirs))
3901 (setq dir (nth numdirs directories)))))
3902
3903 (setq errbuf (get-buffer-create "*idltags-error*"))
3904 (if (= status 0)
3905 (kill-buffer errbuf))
3906 (message "")
3907 ))
3908
3909 (defun idlwave-toggle-comment-region (beg end &optional n)
3910 "Comment the lines in the region if the first non-blank line is
3911 commented, and conversely, uncomment region. If optional prefix arg
3912 N is non-nil, then for N positive, add N comment delimiters or for N
3913 negative, remove N comment delimiters.
3914 Uses `comment-region' which does not place comment delimiters on
3915 blank lines."
3916 (interactive "r\nP")
3917 (if n
3918 (comment-region beg end (prefix-numeric-value n))
3919 (save-excursion
3920 (goto-char beg)
3921 (beginning-of-line)
3922 ;; skip blank lines
3923 (skip-chars-forward " \t\n")
3924 (if (looking-at (concat "[ \t]*\\(" comment-start "+\\)"))
3925 (comment-region beg end
3926 (- (length (buffer-substring
3927 (match-beginning 1)
3928 (match-end 1)))))
3929 (comment-region beg end)))))
3930
3931
3932 ;; ----------------------------------------------------------------------------
3933 ;; ----------------------------------------------------------------------------
3934 ;; ----------------------------------------------------------------------------
3935 ;; ----------------------------------------------------------------------------
3936 ;;
3937 ;; Completion and Routine Info
3938 ;;
3939
3940 ;; String "intern" functions
3941
3942 ;; For the completion and routine info function, we want to normalize
3943 ;; the case of procedure names etc. We do this by "interning" these
3944 ;; string is a hand-crafted way. Hashes are used to map the downcase
3945 ;; version of the strings to the cased versions. Since these cased
3946 ;; versions are really lisp objects, we can use `eq' to search, which
3947 ;; is a large performance boost.
3948 ;; All new strings need to be "sinterned". We do this as early as
3949 ;; possible after getting these strings from completion or buffer
3950 ;; substrings. So most of the code can simply assume to deal with
3951 ;; "sinterned" strings. The only exception is that the functions
3952 ;; which scan whole buffers for routine information do not intern the
3953 ;; grabbed strings. This is only done afterwards. Therefore in these
3954 ;; functions it is *not* save to assume the strings can be compared
3955 ;; with `eq' and be fed into the routine assq functions.
3956
3957 ;; Here we define the hashing functions.
3958
3959 ;; The variables which hold the hashes.
3960 (defvar idlwave-sint-routines '(nil))
3961 (defvar idlwave-sint-keywords '(nil))
3962 (defvar idlwave-sint-methods '(nil))
3963 (defvar idlwave-sint-classes '(nil))
3964 (defvar idlwave-sint-files '(nil))
3965
3966 (defun idlwave-reset-sintern (&optional what)
3967 "Reset all sintern hashes."
3968 ;; Make sure the hash functions are accessible.
3969 (if (or (not (fboundp 'gethash))
3970 (not (fboundp 'puthash)))
3971 (progn
3972 (require 'cl)
3973 (or (fboundp 'puthash)
3974 (defalias 'puthash 'cl-puthash))))
3975 (let ((entries '((idlwave-sint-routines 1000 10)
3976 (idlwave-sint-keywords 1000 10)
3977 (idlwave-sint-methods 100 10)
3978 (idlwave-sint-classes 10 10))))
3979
3980 ;; Make sure these are lists
3981 (loop for entry in entries
3982 for var = (car entry)
3983 do (if (not (consp (symbol-value var))) (set var (list nil))))
3984
3985 (when (or (eq what t) (eq what 'syslib)
3986 (null (cdr idlwave-sint-routines)))
3987 ;; Reset the system & library hash
3988 (loop for entry in entries
3989 for var = (car entry) for size = (nth 1 entry)
3990 do (setcdr (symbol-value var)
3991 (make-hash-table ':size size ':test 'equal)))
3992 (setq idlwave-sint-files nil))
3993
3994 (when (or (eq what t) (eq what 'bufsh)
3995 (null (car idlwave-sint-routines)))
3996 ;; Reset the buffer & shell hash
3997 (loop for entry in entries
3998 for var = (car entry) for size = (nth 1 entry)
3999 do (setcar (symbol-value var)
4000 (make-hash-table ':size size ':test 'equal))))))
4001
4002 (defun idlwave-sintern-routine-or-method (name &optional class set)
4003 (if class
4004 (idlwave-sintern-method name set)
4005 (idlwave-sintern-routine name set)))
4006
4007 (defun idlwave-sintern (stype &rest args)
4008 (apply (intern (concat "idlwave-sintern-" (symbol-name stype))) args))
4009
4010 ;;(defmacro idlwave-sintern (type var)
4011 ;; `(cond ((not (stringp name)) name)
4012 ;; ((gethash (downcase name) (cdr ,var)))
4013 ;; ((gethash (downcase name) (car ,var)))
4014 ;; (set (idlwave-sintern-set name ,type ,var set))
4015 ;; (name)))
4016
4017 (defun idlwave-sintern-routine (name &optional set)
4018 (cond ((not (stringp name)) name)
4019 ((gethash (downcase name) (cdr idlwave-sint-routines)))
4020 ((gethash (downcase name) (car idlwave-sint-routines)))
4021 (set (idlwave-sintern-set name 'routine idlwave-sint-routines set))
4022 (name)))
4023 (defun idlwave-sintern-keyword (name &optional set)
4024 (cond ((not (stringp name)) name)
4025 ((gethash (downcase name) (cdr idlwave-sint-keywords)))
4026 ((gethash (downcase name) (car idlwave-sint-keywords)))
4027 (set (idlwave-sintern-set name 'keyword idlwave-sint-keywords set))
4028 (name)))
4029 (defun idlwave-sintern-method (name &optional set)
4030 (cond ((not (stringp name)) name)
4031 ((gethash (downcase name) (cdr idlwave-sint-methods)))
4032 ((gethash (downcase name) (car idlwave-sint-methods)))
4033 (set (idlwave-sintern-set name 'method idlwave-sint-methods set))
4034 (name)))
4035 (defun idlwave-sintern-class (name &optional set)
4036 (cond ((not (stringp name)) name)
4037 ((gethash (downcase name) (cdr idlwave-sint-classes)))
4038 ((gethash (downcase name) (car idlwave-sint-classes)))
4039 (set (idlwave-sintern-set name 'class idlwave-sint-classes set))
4040 (name)))
4041
4042 (defun idlwave-sintern-file (name &optional set)
4043 (car (or (member name idlwave-sint-files)
4044 (setq idlwave-sint-files (cons name idlwave-sint-files)))))
4045
4046 (defun idlwave-sintern-set (name type tables set)
4047 (let* ((func (or (cdr (assq type idlwave-completion-case))
4048 'identity))
4049 (iname (funcall (if (eq func 'preserve) 'identity func) name))
4050 (table (if (eq set 'sys) (cdr tables) (car tables))))
4051 (puthash (downcase name) iname table)
4052 iname))
4053
4054 (defun idlwave-sintern-rinfo-list (list &optional set)
4055 "Sintern all strings in the rinfo LIST. With optional parameter SET:
4056 also set new patterns. Probably this will always have to be t."
4057 (let (entry name type class kwds res source call olh new)
4058 (while list
4059 (setq entry (car list)
4060 list (cdr list)
4061 name (car entry)
4062 type (nth 1 entry)
4063 class (nth 2 entry)
4064 source (nth 3 entry)
4065 call (nth 4 entry)
4066 kwds (nth 5 entry)
4067 olh (nth 6 entry))
4068 (setq kwds (mapcar (lambda (x)
4069 (list (idlwave-sintern-keyword (car x) set)))
4070 kwds))
4071 (if class
4072 (progn
4073 (if (symbolp class) (setq class (symbol-name class)))
4074 (setq class (idlwave-sintern-class class set))
4075 (setq name (idlwave-sintern-method name set)))
4076 (setq name (idlwave-sintern-routine name set)))
4077 (if (stringp (cdr source))
4078 (setcdr source (idlwave-sintern-file (cdr source) t)))
4079 (setq new (if olh
4080 (list name type class source call kwds olh)
4081 (list name type class source call kwds)))
4082 (setq res (cons new res)))
4083 (nreverse res)))
4084
4085 ;; Creating new sintern tables
4086
4087 (defun idlwave-new-sintern-type (tag)
4088 "Define a variable and a function to sintern the new type TAG.
4089 This defines the function `idlwave-sintern-TAG' and the variable
4090 `idlwave-sint-TAGs'."
4091 (let* ((name (symbol-name tag))
4092 (names (concat name "s"))
4093 (var (intern (concat "idlwave-sint-" names)))
4094 (func (intern (concat "idlwave-sintern-" name))))
4095 (set var nil) ; initial value of the association list
4096 (fset func ; set the function
4097 `(lambda (name &optional set)
4098 (cond ((not (stringp name)) name)
4099 ((cdr (assoc (downcase name) ,var)))
4100 (set
4101 (setq ,var (cons (cons (downcase name) name) ,var))
4102 name)
4103 (name))))))
4104
4105 (defun idlwave-reset-sintern-type (tag)
4106 "Reset the sintern variable associated with TAG."
4107 (set (intern (concat "idlwave-sint-" (symbol-name tag) "s")) nil))
4108
4109 ;;---------------------------------------------------------------------------
4110
4111
4112 ;; The variables which hold the information
4113 (defvar idlwave-system-routines nil
4114 "Holds the routine-info obtained by scanning buffers.")
4115 (defvar idlwave-buffer-routines nil
4116 "Holds the routine-info obtained by scanning buffers.")
4117 (defvar idlwave-compiled-routines nil
4118 "Holds the routine-info obtained by asking the shell.")
4119 (defvar idlwave-unresolved-routines nil
4120 "Holds the unresolved routine-info obtained by asking the shell.")
4121 (defvar idlwave-library-routines nil
4122 "Holds the procedure routine-info from the library scan.")
4123 (defvar idlwave-path-alist nil
4124 "Alist with !PATH directories and a flag if the dir has been scanned.")
4125 (defvar idlwave-true-path-alist nil
4126 "Like `idlwave-path-alist', but with true filenames.")
4127 (defvar idlwave-routines nil
4128 "Holds the combinded procedure routine-info.")
4129 (defvar idlwave-class-alist nil
4130 "Holds the class names known to IDLWAVE.")
4131 (defvar idlwave-class-history nil
4132 "The history of classes selected with the minibuffer.")
4133 (defvar idlwave-force-class-query nil)
4134 (defvar idlwave-before-completion-wconf nil
4135 "The window configuration just before the completion buffer was displayed.")
4136 (defvar idlwave-last-system-routine-info-cons-cell nil
4137 "The last cons cell in the system routine info.")
4138
4139 ;;
4140 ;; The code to get routine info from different sources.
4141
4142 (defvar idlwave-system-routines)
4143 (defvar idlwave-catalog-process nil
4144 "The background process currently updating the catalog.")
4145
4146 (defun idlwave-routines ()
4147 "Provide a list of IDL routines.
4148 This routine loads the builtin routines on the first call. Later it
4149 only returns the value of the variable."
4150 (if (and idlwave-catalog-process
4151 (processp idlwave-catalog-process))
4152 (progn
4153 (cond
4154 ((equal (process-status idlwave-catalog-process) 'exit)
4155 (message "updating........")
4156 (setq idlwave-catalog-process nil)
4157 (idlwave-update-routine-info '(4)))
4158 ((equal (process-status idlwave-catalog-process) 'run)
4159 ;; Keep it running...
4160 )
4161 (t
4162 ;; Something is wrong, get rid of the process
4163 (message "Problem with catalog process") (beep)
4164 (condition-case nil
4165 (kill-process idlwave-catalog-process)
4166 (error nil))
4167 (setq idlwave-catalog-process nil)))))
4168 (or idlwave-routines
4169 (progn
4170 (idlwave-update-routine-info)
4171 ;; return the current value
4172 idlwave-routines)))
4173
4174 (defvar idlwave-update-rinfo-hook nil
4175 "List of functions which should run after a global rinfo update.
4176 Does not run after automatic updates of buffer or the shell.")
4177
4178 (defun idlwave-rescan-catalog-directories ()
4179 "Rescan the previously selected directories. For batch processing."
4180 (idlwave-update-routine-info '(16)))
4181
4182 (defun idlwave-rescan-asynchronously ()
4183 "Dispatch another emacs instance to update the idlwave catalog.
4184 After the process finishes normally, the first access to routine info
4185 will re-read the catalog."
4186 (interactive)
4187 (if (processp idlwave-catalog-process)
4188 (if (eq (process-status idlwave-catalog-process) 'run)
4189 (if (yes-or-no-p "A catalog-updating process is running. Kill it? ")
4190 (progn
4191 (condition-case nil
4192 (kill-process idlwave-catalog-process)
4193 (error nil))
4194 (error "Process killed, no new process started"))
4195 (error "Quit"))
4196 (condition-case nil
4197 (kill-process idlwave-catalog-process)
4198 (error nil))))
4199 (if (or (not idlwave-libinfo-file)
4200 (not (stringp idlwave-libinfo-file))
4201 (not (file-regular-p idlwave-libinfo-file)))
4202 (error "No catalog has been produced yet"))
4203 (let* ((emacs (expand-file-name (invocation-name) (invocation-directory)))
4204 (args (list "-batch"
4205 "-l" (expand-file-name "~/.emacs")
4206 "-l" "idlwave"
4207 "-f" "idlwave-rescan-catalog-directories"))
4208 (process (apply 'start-process "idlcat"
4209 nil emacs args)))
4210 (setq idlwave-catalog-process process)
4211 (set-process-sentinel
4212 process
4213 (lambda (pro why)
4214 (when (string-match "finished" why)
4215 (setq idlwave-routines nil
4216 idlwave-system-routines nil
4217 idlwave-catalog-process nil)
4218 (or (idlwave-start-load-rinfo-timer)
4219 (idlwave-update-routine-info '(4))))))
4220 (message "Background job started to update catalog file")))
4221
4222
4223 (defvar idlwave-load-rinfo-idle-timer)
4224 (defun idlwave-update-routine-info (&optional arg)
4225 "Update the internal routine-info lists.
4226 These lists are used by `idlwave-routine-info' (\\[idlwave-routine-info])
4227 and by `idlwave-complete' (\\[idlwave-complete]) to provide information
4228 about individual routines.
4229
4230 The information can come from 4 sources:
4231 1. IDL programs in the current editing session
4232 2. Compiled modules in an IDL shell running as Emacs subprocess
4233 3. A list which covers the IDL system routines.
4234 4. A list which covers the prescanned library files.
4235
4236 Scans all IDLWAVE-mode buffers of the current editing session (see
4237 `idlwave-scan-all-buffers-for-routine-info').
4238 When an IDL shell is running, this command also queries the IDL program
4239 for currently compiled routines.
4240
4241 With prefix ARG, also reload the system and library lists.
4242 With two prefix ARG's, also rescans the library tree.
4243 With three prefix args, dispatch asynchronous process to do the update."
4244 (interactive "P")
4245 ;; Stop any idle processing
4246 (if (or (and (fboundp 'itimerp)
4247 (itimerp idlwave-load-rinfo-idle-timer))
4248 (and (fboundp 'timerp)
4249 (timerp idlwave-load-rinfo-idle-timer)))
4250 (cancel-timer idlwave-load-rinfo-idle-timer))
4251 (cond
4252 ((equal arg '(64))
4253 ;; Start a background process which updates the catalog.
4254 (idlwave-rescan-asynchronously))
4255 ((equal arg '(16))
4256 ;; Update the catalog now, and wait for it.
4257 (idlwave-create-libinfo-file t))
4258 (t
4259 (let* ((load (or arg
4260 idlwave-buffer-case-takes-precedence
4261 (null idlwave-routines)))
4262 ;; The override-idle means, even if the idle timer has done some
4263 ;; preparing work, load and renormalize everything anyway.
4264 (override-idle (or arg idlwave-buffer-case-takes-precedence)))
4265
4266 (setq idlwave-buffer-routines nil
4267 idlwave-compiled-routines nil
4268 idlwave-unresolved-routines nil)
4269 ;; Reset the appropriate hashes
4270 (if (get 'idlwave-reset-sintern 'done-by-idle)
4271 ;; reset was already done in idle time, so skip this step now once
4272 (put 'idlwave-reset-sintern 'done-by-idle nil)
4273 (idlwave-reset-sintern (cond (load t)
4274 ((null idlwave-system-routines) t)
4275 (t 'bufsh))))
4276
4277 (if idlwave-buffer-case-takes-precedence
4278 ;; We can safely scan the buffer stuff first
4279 (progn
4280 (idlwave-update-buffer-routine-info)
4281 (and load (idlwave-load-system-rinfo override-idle)))
4282 ;; We first do the system info, and then the buffers
4283 (and load (idlwave-load-system-rinfo override-idle))
4284 (idlwave-update-buffer-routine-info))
4285
4286 ;; Let's see if there is a shell
4287 (let* ((shell-is-running (and (fboundp 'idlwave-shell-is-running)
4288 (idlwave-shell-is-running)))
4289 (ask-shell (and shell-is-running
4290 idlwave-query-shell-for-routine-info)))
4291
4292 (if (or (not ask-shell)
4293 (not (interactive-p)))
4294 ;; 1. If we are not going to ask the shell, we need to do the
4295 ;; concatenation now.
4296 ;; 2. When this function is called non-interactively, it means
4297 ;; that someone needs routine info *now*. The shell update
4298 ;; causes the concatenation *delayed*, so not in time for
4299 ;; the current command. Therefore, we do a concatenation
4300 ;; now, even though the shell might do it again.
4301 (idlwave-concatenate-rinfo-lists nil t))
4302
4303 (when ask-shell
4304 ;; Ask the shell about the routines it knows.
4305 (message "Querying the shell")
4306 (idlwave-shell-update-routine-info nil t)))))))
4307
4308 (defvar idlwave-load-rinfo-steps-done (make-vector 5 nil))
4309 (defvar idlwave-load-rinfo-idle-timer nil)
4310 (defun idlwave-start-load-rinfo-timer ()
4311 (if (or (and (fboundp 'itimerp)
4312 (itimerp idlwave-load-rinfo-idle-timer))
4313 (and (fboundp 'timerp)
4314 (timerp idlwave-load-rinfo-idle-timer)))
4315 (cancel-timer idlwave-load-rinfo-idle-timer))
4316 (setq idlwave-load-rinfo-steps-done (make-vector 5 nil))
4317 (setq idlwave-load-rinfo-idle-timer nil)
4318 (if (and idlwave-init-rinfo-when-idle-after
4319 (numberp idlwave-init-rinfo-when-idle-after)
4320 (not (equal 0 idlwave-init-rinfo-when-idle-after))
4321 (not idlwave-routines))
4322 (condition-case nil
4323 (progn
4324 (setq idlwave-load-rinfo-idle-timer
4325 (run-with-idle-timer
4326 idlwave-init-rinfo-when-idle-after
4327 nil 'idlwave-load-rinfo-next-step)))
4328 (error nil))))
4329
4330
4331
4332 (defun idlwave-load-rinfo-next-step ()
4333 (let ((inhibit-quit t)
4334 (arr idlwave-load-rinfo-steps-done))
4335 (if (catch 'exit
4336 (when (not (aref arr 0))
4337 (message "Loading idlw-rinfo.el in idle time...")
4338 (load "idlw-rinfo" 'noerror 'nomessage)
4339 (message "Loading idlw-rinfo.el in idle time...done")
4340 (aset arr 0 t)
4341 (throw 'exit t))
4342 (when (not (aref arr 1))
4343 (message "Normalizing idlwave-system-routines in idle time...")
4344 (idlwave-reset-sintern t)
4345 (put 'idlwave-reset-sintern 'done-by-idle t)
4346 (setq idlwave-system-routines
4347 (idlwave-sintern-rinfo-list idlwave-system-routines 'sys))
4348 (message "Normalizing idlwave-system-routines in idle time...done")
4349 (aset arr 1 t)
4350 (throw 'exit t))
4351 (when (not (aref arr 2))
4352 (when (and (stringp idlwave-libinfo-file)
4353 (file-regular-p idlwave-libinfo-file))
4354 (condition-case nil
4355 (progn
4356 (message "Loading library catalog in idle time...")
4357 (load-file idlwave-libinfo-file)
4358 (message "Loading library catalog in idle time...done")
4359 (aset arr 2 t)
4360 (throw 'exit t))
4361 (error (throw 'exit nil)))))
4362 (when (not (aref arr 3))
4363 (when idlwave-library-routines
4364 (message "Normalizing idlwave-library-routines in idle time...")
4365 (setq idlwave-library-routines (idlwave-sintern-rinfo-list
4366 idlwave-library-routines 'sys))
4367 (message "Normalizing idlwave-library-routines in idle time...done"))
4368 (aset arr 3 t)
4369 (throw 'exit t))
4370 (when (not (aref arr 4))
4371 (message "Finishing initialization in idle time...")
4372 (idlwave-routines)
4373 (message "Finishing initialization in idle time...done")
4374 (throw 'exit nil)))
4375 (progn
4376 ;; restart the timer
4377 (if (sit-for 1)
4378 (idlwave-load-rinfo-next-step)
4379 (setq idlwave-load-rinfo-idle-timer
4380 (run-with-idle-timer
4381 idlwave-init-rinfo-when-idle-after
4382 nil 'idlwave-load-rinfo-next-step)))
4383 ))))
4384
4385 (defun idlwave-load-system-rinfo (&optional force)
4386 ;; Load and case-treat the system and lib info files.
4387 (when (or force (not (aref idlwave-load-rinfo-steps-done 0)))
4388 (load "idlw-rinfo" 'noerror 'nomessage))
4389 (when (or force (not (aref idlwave-load-rinfo-steps-done 1)))
4390 (message "Normalizing idlwave-system-routines...")
4391 (setq idlwave-system-routines
4392 (idlwave-sintern-rinfo-list idlwave-system-routines 'sys))
4393 (message "Normalizing idlwave-system-routines...done"))
4394 (setq idlwave-routines (copy-sequence idlwave-system-routines))
4395 (setq idlwave-last-system-routine-info-cons-cell
4396 (nthcdr (1- (length idlwave-routines)) idlwave-routines))
4397 (when (and (stringp idlwave-libinfo-file)
4398 (file-regular-p idlwave-libinfo-file))
4399 (condition-case nil
4400 (progn
4401 (when (or force (not (aref idlwave-load-rinfo-steps-done 2)))
4402 (load-file idlwave-libinfo-file))
4403 (setq idlwave-true-path-alist nil)
4404 (when (or force (not (aref idlwave-load-rinfo-steps-done 3)))
4405 (message "Normalizing idlwave-library-routines...")
4406 (setq idlwave-library-routines (idlwave-sintern-rinfo-list
4407 idlwave-library-routines 'sys))
4408 (message "Normalizing idlwave-library-routines...done")))
4409 (error nil)))
4410
4411 (run-hooks 'idlwave-after-load-rinfo-hook))
4412
4413
4414 (defun idlwave-update-buffer-routine-info ()
4415 (let (res)
4416 (cond
4417 ((eq idlwave-scan-all-buffers-for-routine-info t)
4418 ;; Scan all buffers, current buffer last
4419 (message "Scanning all buffers...")
4420 (setq res (idlwave-get-routine-info-from-buffers
4421 (reverse (buffer-list)))))
4422 ((null idlwave-scan-all-buffers-for-routine-info)
4423 ;; Don't scan any buffers
4424 (setq res nil))
4425 (t
4426 ;; Just scan this buffer
4427 (if (eq major-mode 'idlwave-mode)
4428 (progn
4429 (message "Scanning current buffer...")
4430 (setq res (idlwave-get-routine-info-from-buffers
4431 (list (current-buffer))))))))
4432 ;; Put the result into the correct variable
4433 (setq idlwave-buffer-routines
4434 (idlwave-sintern-rinfo-list res t))))
4435
4436 (defun idlwave-concatenate-rinfo-lists (&optional quiet run-hook)
4437 "Put the different sources for routine information together."
4438 ;; The sequence here is important because earlier definitions shadow
4439 ;; later ones. We assume that if things in the buffers are newer
4440 ;; then in the shell of the system, it is meant to be different.
4441
4442 (setcdr idlwave-last-system-routine-info-cons-cell
4443 (append idlwave-buffer-routines
4444 idlwave-compiled-routines
4445 idlwave-library-routines))
4446 (setq idlwave-class-alist nil)
4447
4448 ;; Give a message with information about the number of routines we have.
4449 (unless quiet
4450 (message
4451 "Routine info updated: buffer(%d) compiled(%d) catalog(%d) system(%d)"
4452 (length idlwave-buffer-routines)
4453 (length idlwave-compiled-routines)
4454 (length idlwave-library-routines)
4455 (length idlwave-system-routines)))
4456 (if run-hook
4457 (run-hooks 'idlwave-update-rinfo-hook)))
4458
4459 (defun idlwave-class-alist ()
4460 "Return the class alist - make it if necessary."
4461 (or idlwave-class-alist
4462 (let (class)
4463 (loop for x in idlwave-routines do
4464 (when (and (setq class (nth 2 x))
4465 (not (assq class idlwave-class-alist)))
4466 (push (list class) idlwave-class-alist)))
4467 idlwave-class-alist)))
4468
4469 ;; Three functions for the hooks
4470 (defun idlwave-save-buffer-update ()
4471 (idlwave-update-current-buffer-info 'save-buffer))
4472 (defun idlwave-kill-buffer-update ()
4473 (idlwave-update-current-buffer-info 'kill-buffer))
4474 (defun idlwave-new-buffer-update ()
4475 (idlwave-update-current-buffer-info 'find-file))
4476
4477 (defun idlwave-update-current-buffer-info (why)
4478 "Undate idlwave-routines for current buffer. Can run from after-save-hook."
4479 (when (and (eq major-mode 'idlwave-mode)
4480 (or (eq t idlwave-auto-routine-info-updates)
4481 (memq why idlwave-auto-routine-info-updates))
4482 idlwave-scan-all-buffers-for-routine-info
4483 idlwave-routines)
4484 (condition-case nil
4485 (let (routines)
4486 (idlwave-replace-buffer-routine-info
4487 (buffer-file-name)
4488 (if (eq why 'kill-buffer)
4489 nil
4490 (setq routines
4491 (idlwave-sintern-rinfo-list
4492 (idlwave-get-routine-info-from-buffers
4493 (list (current-buffer))) 'set))))
4494 (idlwave-concatenate-rinfo-lists 'quiet)
4495 routines)
4496 (error nil))))
4497
4498 (defun idlwave-replace-buffer-routine-info (file new)
4499 "Cut the part from FILE out of `idlwave-buffer-routines' and add NEW."
4500 (let ((list idlwave-buffer-routines)
4501 found)
4502 (while list
4503 ;; The following test uses eq to make sure it works correctly
4504 ;; when two buffers visit the same file. Then the file names
4505 ;; will be equal, but not eq.
4506 (if (eq (cdr (nth 3 (car list))) file)
4507 (progn
4508 (setcar list nil)
4509 (setq found t))
4510 (if found
4511 ;; End of that section reached. Jump.
4512 (setq list nil)))
4513 (setq list (cdr list)))
4514 (setq idlwave-buffer-routines
4515 (append new (delq nil idlwave-buffer-routines)))))
4516
4517 ;;----- Scanning buffers -------------------
4518
4519 (defun idlwave-get-routine-info-from-buffers (buffers)
4520 "Call `idlwave-get-buffer-routine-info' on idlwave-mode buffers in BUFFERS."
4521 (let (buf routine-lists res)
4522 (save-excursion
4523 (while (setq buf (pop buffers))
4524 (set-buffer buf)
4525 (if (and (eq major-mode 'idlwave-mode)
4526 buffer-file-name)
4527 ;; yes, this buffer has the right mode.
4528 (progn (setq res (condition-case nil
4529 (idlwave-get-buffer-routine-info)
4530 (error nil)))
4531 (push res routine-lists)))))
4532 ;; Concatenate the individual lists and return the result
4533 (apply 'nconc routine-lists)))
4534
4535 (defun idlwave-get-buffer-routine-info ()
4536 "Scan the current buffer for routine info. Return (PRO-LIST FUNC-LIST)."
4537 (let* ((case-fold-search t)
4538 routine-list string entry)
4539 (save-excursion
4540 (save-restriction
4541 (widen)
4542 (goto-char (point-min))
4543 (while (re-search-forward
4544 "^[ \t]*\\(pro\\|function\\)[ \t]" nil t)
4545 (setq string (buffer-substring
4546 (match-beginning 0)
4547 (progn
4548 (idlwave-end-of-statement)
4549 (point))))
4550 (setq entry (idlwave-parse-definition string))
4551 (push entry routine-list))))
4552 routine-list))
4553
4554 (defvar idlwave-scanning-lib-dir)
4555 (defun idlwave-parse-definition (string)
4556 "Parse a module definition."
4557 (let ((case-fold-search t)
4558 start name args type keywords class)
4559 ;; Remove comments
4560 (while (string-match ";.*" string)
4561 (setq string (replace-match "" t t string)))
4562 ;; Remove the continuation line stuff
4563 (while (string-match "\\([^a-zA-Z0-9$_]\\)\\$[ \t]*\n" string)
4564 (setq string (replace-match "\\1 " t nil string)))
4565 (while (string-match "\n" string)
4566 (setq string (replace-match " " t nil string)))
4567 ;; Match the name and type.
4568 (when (string-match
4569 "\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)" string)
4570 (setq start (match-end 0))
4571 (setq type (downcase (match-string 1 string)))
4572 (if (match-beginning 3)
4573 (setq class (match-string 3 string)))
4574 (setq name (match-string 4 string)))
4575 ;; Match normal args and keyword args
4576 (while (string-match
4577 ",\\s-*\\([a-zA-Z][a-zA-Z0-9$_]*\\|\\(_ref\\)?_extra\\)\\s-*\\(=\\)?"
4578 string start)
4579 (setq start (match-end 0))
4580 (if (match-beginning 3)
4581 (push (match-string 1 string) keywords)
4582 (push (match-string 1 string) args)))
4583 ;; Normalize and sort.
4584 (setq args (nreverse args))
4585 (setq keywords (sort keywords (lambda (a b)
4586 (string< (downcase a) (downcase b)))))
4587 ;; Make and return the entry
4588 ;; We don't know which argument are optional, so this information
4589 ;; will not be contained in the calling sequence.
4590 (list name
4591 (if (equal type "pro") 'pro 'fun)
4592 class
4593 (cond ((not (boundp 'idlwave-scanning-lib))
4594 (cons 'buffer (buffer-file-name)))
4595 ; ((string= (downcase
4596 ; (file-name-sans-extension
4597 ; (file-name-nondirectory (buffer-file-name))))
4598 ; (downcase name))
4599 ; (list 'lib))
4600 ; (t (cons 'lib (file-name-nondirectory (buffer-file-name))))
4601 (t (cons 'lib (concat idlwave-scanning-lib-dir
4602 (file-name-nondirectory (buffer-file-name))))))
4603 (concat
4604 (if (string= type "function") "Result = " "")
4605 (if class "Obj ->[%s::]" "")
4606 "%s"
4607 (if args
4608 (concat
4609 (if (string= type "function") "(" ", ")
4610 (mapconcat 'identity args ", ")
4611 (if (string= type "function") ")" ""))))
4612 (if keywords
4613 (mapcar 'list keywords)
4614 nil))))
4615
4616 ;;----- Scanning the library -------------------
4617
4618 (defvar idlwave-sys-dir nil
4619 "Internal variable.")
4620
4621 (defun idlwave-sys-dir ()
4622 "Return the syslib directory, or a dummy that never matches."
4623 (or idlwave-sys-dir
4624 "@@@@@@@@"))
4625
4626 (defvar idlwave-shell-path-query)
4627 (defun idlwave-create-libinfo-file (&optional arg)
4628 "Scan all files on selected dirs of IDL search path for routine information.
4629 A widget checklist will allow you to choose the directories.
4630 Write the result as a file `idlwave-libinfo-file'. When this file exists,
4631 will be automatically loaded to give routine information about library
4632 routines.
4633 With ARG, just rescan the same directories as last time - so no widget
4634 will pop up."
4635 (interactive "P")
4636 ;; Make sure the file is loaded if it exists.
4637 (if (and (stringp idlwave-libinfo-file)
4638 (file-regular-p idlwave-libinfo-file))
4639 (condition-case nil
4640 (load-file idlwave-libinfo-file)
4641 (error nil)))
4642 ;; Make sure the file name makes sense
4643 (unless (and (stringp idlwave-libinfo-file)
4644 (> (length idlwave-libinfo-file) 0)
4645 (file-accessible-directory-p
4646 (file-name-directory idlwave-libinfo-file))
4647 (not (string= "" (file-name-nondirectory
4648 idlwave-libinfo-file))))
4649 (error "`idlwave-libinfo-file' does not point to file in accessible directory"))
4650
4651 (cond
4652 ((and arg idlwave-path-alist
4653 (consp (car idlwave-path-alist))
4654 idlwave-sys-dir)
4655 ;; Rescan the known directories
4656 (idlwave-scan-lib-files
4657 idlwave-sys-dir
4658 idlwave-path-alist))
4659 (idlwave-library-path
4660 ;; Get the directories from that variable
4661 (idlwave-display-libinfo-widget
4662 idlwave-system-directory
4663 (idlwave-expand-path idlwave-library-path)
4664 (delq nil (mapcar (lambda (x) (if (consp x) (if (cdr x) (car x) nil) x))
4665 idlwave-path-alist))))
4666 (t
4667 ;; Ask the shell for the path and run the widget
4668 (message "Asking the shell for IDL path...")
4669 (require 'idlw-shell)
4670 (idlwave-shell-send-command idlwave-shell-path-query
4671 '(idlwave-libinfo-command-hook nil)
4672 'hide))))
4673
4674 (defun idlwave-libinfo-command-hook (&optional arg)
4675 ;; Command hook used by `idlwave-create-libinfo-file'.
4676 (if arg
4677 ;; Scan immediately
4678 (idlwave-scan-lib-files
4679 idlwave-sys-dir
4680 idlwave-path-alist)
4681 ;; Display the widget
4682 (let* ((rpl (idlwave-shell-path-filter))
4683 (sysdir (car rpl))
4684 (dirs (cdr rpl)))
4685 (idlwave-display-libinfo-widget
4686 sysdir dirs
4687 (delq nil (mapcar (lambda (x) (if (cdr x) (car x) nil))
4688 idlwave-path-alist))))))
4689
4690 (defconst idlwave-libinfo-widget-help-string
4691 "This is the front-end to the creation of IDLWAVE library catalog.
4692 Please select below the directories on IDL's search path from which you
4693 would like to extract routine information, which will be stored in the file
4694
4695 %s
4696
4697 If this is not the correct file, first set variable `idlwave-libinfo-file'.
4698 Then call this command again.
4699
4700 For writing code, you need to include the directories which contain the
4701 routines you use. If IDLWAVE should be able to analyse routine shadowing
4702 it is best to scan all directories.
4703
4704 After selecting the directories, choose [Scan & Save] to scan the library
4705 directories and save the routine info.
4706 \n")
4707
4708 (defvar idlwave-widget)
4709 (defvar widget-keymap)
4710 (defun idlwave-display-libinfo-widget (sysdir dirs selected-dirs)
4711 "Create the widget to select IDL search path directories for scanning."
4712 (interactive)
4713 (require 'widget)
4714 (require 'wid-edit)
4715 (unless dirs
4716 (error "Don't know IDL's search path"))
4717
4718 ;; Allow only those directories to be selected which are in the path.
4719 (setq selected-dirs (delq nil (mapcar (lambda (x)
4720 (if (member x dirs) x nil))
4721 selected-dirs)))
4722 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
4723 (switch-to-buffer (get-buffer-create "*IDLWAVE Widget*"))
4724 (kill-all-local-variables)
4725 (make-local-variable 'idlwave-widget)
4726 (widget-insert (format idlwave-libinfo-widget-help-string
4727 idlwave-libinfo-file))
4728
4729 (widget-create 'push-button
4730 :notify 'idlwave-widget-scan-lib-files
4731 "Scan & Save")
4732 (widget-insert " ")
4733 (widget-create 'push-button
4734 :notify (lambda (&rest ignore)
4735 (kill-buffer (current-buffer)))
4736 "Quit")
4737 (widget-insert " ")
4738 (widget-create 'push-button
4739 :notify 'idlwave-delete-libinfo-file
4740 "Delete File")
4741 (widget-insert " ")
4742 (widget-create 'push-button
4743 :notify '(lambda (&rest ignore)
4744 (idlwave-display-libinfo-widget
4745 (widget-get idlwave-widget :sysdir)
4746 (widget-get idlwave-widget :path-dirs)
4747 (widget-get idlwave-widget :path-dirs)))
4748 "Select All")
4749 (widget-insert " ")
4750 (widget-create 'push-button
4751 :notify '(lambda (&rest ignore)
4752 (idlwave-display-libinfo-widget
4753 (widget-get idlwave-widget :sysdir)
4754 (widget-get idlwave-widget :path-dirs)
4755 nil))
4756 "Deselect All")
4757 (widget-insert "\n\n")
4758
4759 (widget-insert "Select Directories\n")
4760
4761 (setq idlwave-widget
4762 (apply 'widget-create
4763 'checklist
4764 :value selected-dirs
4765 :greedy t
4766 :tag "List of directories"
4767 (mapcar (lambda (x) (list 'item x)) dirs)))
4768 (widget-put idlwave-widget :path-dirs dirs)
4769 (widget-put idlwave-widget :sysdir sysdir)
4770 (widget-insert "\n")
4771 (use-local-map widget-keymap)
4772 (widget-setup)
4773 (goto-char (point-min))
4774 (delete-other-windows))
4775
4776 (defun idlwave-delete-libinfo-file (&rest ignore)
4777 (if (yes-or-no-p
4778 (format "Delete file %s " idlwave-libinfo-file))
4779 (progn
4780 (delete-file idlwave-libinfo-file)
4781 (message "%s has been deleted" idlwave-libinfo-file))))
4782
4783 (defun idlwave-widget-scan-lib-files (&rest ignore)
4784 ;; Call `idlwave-scan-lib-files' with data taken from the widget.
4785 (let* ((widget idlwave-widget)
4786 (selected-dirs (widget-value widget))
4787 (sysdir (widget-get widget :sysdir))
4788 (path-dirs (widget-get widget :path-dirs))
4789 (path-dir-alist
4790 (mapcar (lambda (x) (cons x (if (member x selected-dirs) t nil)))
4791 path-dirs)))
4792 (idlwave-scan-lib-files sysdir path-dir-alist)))
4793
4794 (defvar font-lock-mode)
4795 (defun idlwave-scan-lib-files (sysdir path-alist)
4796 ;; Scan the files in PATH-ALIST and store the info in a file
4797 (let* ((idlwave-scanning-lib t)
4798 (idlwave-scanning-lib-dir "")
4799 (dircnt (1+ (length path-alist)))
4800 (idlwave-completion-case nil)
4801 dirs-alist dir files file)
4802 (setq idlwave-library-routines nil)
4803 (setq idlwave-path-alist path-alist)
4804 (setq idlwave-true-path-alist nil)
4805 (setq idlwave-sys-dir sysdir)
4806 (save-excursion
4807 (set-buffer (get-buffer-create "*idlwave-scan.pro*"))
4808 (idlwave-mode)
4809 (setq dirs-alist (reverse path-alist))
4810 (while (setq dir (pop dirs-alist))
4811 (decf dircnt)
4812 (when (cdr dir)
4813 ;; Has the flag of scanned directories
4814 (setq dir (car dir))
4815 (setq idlwave-scanning-lib-dir (format "{%d}/" dircnt))
4816 (when (file-directory-p dir)
4817 (setq files (directory-files dir 'full "\\.[pP][rR][oO]\\'"))
4818 (while (setq file (pop files))
4819 (when (file-regular-p file)
4820 (if (not (file-readable-p file))
4821 (message "Skipping %s (no read permission)" file)
4822 (message "Scanning %s..." file)
4823 (erase-buffer)
4824 (insert-file-contents file 'visit)
4825 (setq idlwave-library-routines
4826 (append (idlwave-get-routine-info-from-buffers
4827 (list (current-buffer)))
4828 idlwave-library-routines)))
4829 ))))))
4830 ;; Sorting is not necessary since we sort each time before a routine
4831 ;; is used. So we don't do it here - the catalog file looks nicer
4832 ;; when it is unsorted.
4833 ;;(message "Sorting...")
4834 ;;(setq idlwave-library-routines
4835 ;;(sort idlwave-library-routines 'idlwave-routine-entry-compare))
4836 ;;(message "Sorting...done")
4837 (message "Creating libinfo file...")
4838 (kill-buffer "*idlwave-scan.pro*")
4839 (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
4840 (let ((font-lock-maximum-size 0)
4841 (auto-mode-alist nil))
4842 (find-file idlwave-libinfo-file))
4843 (if (and (boundp 'font-lock-mode)
4844 font-lock-mode)
4845 (font-lock-mode 0))
4846 (erase-buffer)
4847 (insert ";; IDLWAVE libinfo file\n")
4848 (insert (format ";; Created %s\n\n" (current-time-string)))
4849
4850 ;; Define the variable which knows the value of "!DIR"
4851 (insert (format "\n(setq idlwave-sys-dir \"%s\")\n"
4852 idlwave-sys-dir))
4853
4854 ;; Define the variable which contains a list of all scanned directories
4855 (insert "\n(setq idlwave-path-alist\n '(")
4856 (mapcar (lambda (x)
4857 (insert (format "\n (\"%s\" . %s)" (car x) (cdr x))))
4858 path-alist)
4859 (insert "))\n")
4860
4861 ;; Define the routine info list
4862 (insert "\n(setq idlwave-library-routines\n '(")
4863 (let ((standard-output (current-buffer)))
4864 (mapcar (lambda (x)
4865 (insert "\n ")
4866 (prin1 x)
4867 (goto-char (point-max)))
4868 ; (insert (with-output-to-string (prin1 x))))
4869 idlwave-library-routines))
4870 (insert (format "))\n\n;;; %s ends here\n"
4871 (file-name-nondirectory idlwave-libinfo-file)))
4872 (goto-char (point-min))
4873 ;; Save the buffer
4874 (save-buffer 0)
4875 (kill-buffer (current-buffer)))
4876 (message "Creating libinfo file...done")
4877 (message "Info for %d routines saved in %s"
4878 (length idlwave-library-routines)
4879 idlwave-libinfo-file)
4880 (sit-for 2)
4881 (idlwave-update-routine-info t))
4882
4883 (defun idlwave-expand-path (path &optional default-dir)
4884 ;; Expand parts of path starting with '+' recursively into directory list.
4885 ;; Relative recursive path elements are expanded relative to DEFAULT-DIR.
4886 (message "Expanding path...")
4887 (let (path1 dir recursive)
4888 (while (setq dir (pop path))
4889 (if (setq recursive (string= (substring dir 0 1) "+"))
4890 (setq dir (substring dir 1)))
4891 (if (and recursive
4892 (not (file-name-absolute-p dir)))
4893 (setq dir (expand-file-name dir default-dir)))
4894 (if recursive
4895 ;; Expand recursively
4896 (setq path1 (append (idlwave-recursive-directory-list dir) path1))
4897 ;; Keep unchanged
4898 (push dir path1)))
4899 (message "Expanding path...done")
4900 (nreverse path1)))
4901
4902 (defun idlwave-recursive-directory-list (dir)
4903 ;; Return a list of all directories below DIR, including DIR itself
4904 (let ((path (list dir)) path1 file files)
4905 (while (setq dir (pop path))
4906 (when (file-directory-p dir)
4907 (setq files (nreverse (directory-files dir t "[^.]")))
4908 (while (setq file (pop files))
4909 (if (file-directory-p file)
4910 (push (file-name-as-directory file) path)))
4911 (push dir path1)))
4912 path1))
4913
4914 ;;----- Asking the shell -------------------
4915
4916 ;; First, here is the idl program which can be used to query IDL for
4917 ;; defined routines.
4918 (defconst idlwave-routine-info.pro
4919 "
4920 ;; START OF IDLWAVE SUPPORT ROUTINES
4921 pro idlwave_print_info_entry,name,func=func,separator=sep
4922 ;; See if it's an object method
4923 if name eq '' then return
4924 func = keyword_set(func)
4925 methsep = strpos(name,'::')
4926 meth = methsep ne -1
4927
4928 ;; Get routine info
4929 pars = routine_info(name,/parameters,functions=func)
4930 source = routine_info(name,/source,functions=func)
4931 nargs = pars.num_args
4932 nkw = pars.num_kw_args
4933 if nargs gt 0 then args = pars.args
4934 if nkw gt 0 then kwargs = pars.kw_args
4935
4936 ;; Trim the class, and make the name
4937 if meth then begin
4938 class = strmid(name,0,methsep)
4939 name = strmid(name,methsep+2,strlen(name)-1)
4940 if nargs gt 0 then begin
4941 ;; remove the self argument
4942 wh = where(args ne 'SELF',nargs)
4943 if nargs gt 0 then args = args(wh)
4944 endif
4945 endif else begin
4946 ;; No class, just a normal routine.
4947 class = \"\"
4948 endelse
4949
4950 ;; Calling sequence
4951 cs = \"\"
4952 if func then cs = 'Result = '
4953 if meth then cs = cs + 'Obj -> [' + '%s' + '::]'
4954 cs = cs + '%s'
4955 if func then cs = cs + '(' else if nargs gt 0 then cs = cs + ', '
4956 if nargs gt 0 then begin
4957 for j=0,nargs-1 do begin
4958 cs = cs + args(j)
4959 if j lt nargs-1 then cs = cs + ', '
4960 endfor
4961 end
4962 if func then cs = cs + ')'
4963 ;; Keyword arguments
4964 kwstring = ''
4965 if nkw gt 0 then begin
4966 for j=0,nkw-1 do begin
4967 kwstring = kwstring + ' ' + kwargs(j)
4968 endfor
4969 endif
4970
4971 ret=(['IDLWAVE-PRO','IDLWAVE-FUN'])(func)
4972
4973 print,ret + ': ' + name + sep + class + sep + source(0).path $
4974 + sep + cs + sep + kwstring
4975 end
4976
4977 pro idlwave_routine_info
4978 sep = '<@>'
4979 print,'>>>BEGIN OF IDLWAVE ROUTINE INFO (\"' + sep + '\" IS THE SEPARATOR)'
4980 all = routine_info()
4981 for i=0,n_elements(all)-1 do $
4982 idlwave_print_info_entry,all(i),separator=sep
4983 all = routine_info(/functions)
4984 for i=0,n_elements(all)-1 do $
4985 idlwave_print_info_entry,all(i),/func,separator=sep
4986 print,'>>>END OF IDLWAVE ROUTINE INFO'
4987 end
4988
4989 pro idlwave_get_sysvars
4990 forward_function strjoin,strtrim,strsplit
4991 catch,error_status
4992 if error_status ne 0 then begin
4993 print, 'Cannot get info about system variables'
4994 endif else begin
4995 help,/brief,output=s,/system_variables ; ? unsafe use of OUTPUT=
4996 s = strtrim(strjoin(s,' ',/single),2) ; make one line
4997 v = strsplit(s,' +',/regex,/extract) ; get variables
4998 for i=0,n_elements(v)-1 do begin
4999 t = [''] ; get tag list
5000 a=execute('if n_tags('+v[i]+') gt 0 then t=tag_names('+v[i]+')')
5001 print, 'IDLWAVE-SYSVAR: '+v[i]+' '+strjoin(t,' ',/single)
5002 endfor
5003 endelse
5004 end
5005
5006 pro idlwave_get_class_tags, class
5007 res = execute('tags=tag_names({'+class+'})')
5008 if res then print,'IDLWAVE-CLASS-TAGS: '+class+' '+strjoin(tags,' ',/single)
5009 end
5010 ;; END OF IDLWAVE SUPPORT ROUTINES
5011 "
5012 "The idl programs to get info from the shell.")
5013
5014 (defvar idlwave-idlwave_routine_info-compiled nil
5015 "Remembers if the routine info procedure is already compiled.")
5016
5017 (defvar idlwave-shell-temp-pro-file)
5018 (defvar idlwave-shell-temp-rinfo-save-file)
5019 (defun idlwave-shell-update-routine-info (&optional quiet run-hooks)
5020 "Query the shell for routine_info of compiled modules and update the lists."
5021 ;; Save and compile the procedure. The compiled procedure is then
5022 ;; saved into an IDL SAVE file, to allow for fast RESTORE.
5023 ;; We need to RESTORE the procedure each time we use it, since
5024 ;; the user may have killed or redefined it. In particular,
5025 ;; .RESET_SESSION will kill all user procedures.
5026 (unless (and idlwave-idlwave_routine_info-compiled
5027 (file-readable-p (idlwave-shell-temp-file 'rinfo)))
5028 (save-excursion
5029 (set-buffer (idlwave-find-file-noselect
5030 (idlwave-shell-temp-file 'pro)))
5031 (erase-buffer)
5032 (insert idlwave-routine-info.pro)
5033 (save-buffer 0))
5034 (idlwave-shell-send-command
5035 (concat ".run " idlwave-shell-temp-pro-file)
5036 nil 'hide)
5037 ; (message "SENDING SAVE") ; ????????????????????????
5038 (idlwave-shell-send-command
5039 (format "save,'idlwave_routine_info','idlwave_print_info_entry',FILE='%s',/ROUTINES"
5040 (idlwave-shell-temp-file 'rinfo))
5041 nil 'hide))
5042
5043 ;; Restore and execute the procedure, analyze the output
5044 ; (message "SENDING RESTORE & EXECUTE") ; ????????????????????????
5045 (idlwave-shell-send-command
5046 (format "RESTORE, '%s' & idlwave_routine_info"
5047 idlwave-shell-temp-rinfo-save-file)
5048 `(progn
5049 (idlwave-shell-routine-info-filter)
5050 (idlwave-concatenate-rinfo-lists ,quiet ,run-hooks))
5051 'hide))
5052
5053 ;; ---------------------------------------------------------------------------
5054 ;;
5055 ;; Completion and displaying routine calling sequences
5056
5057 (defvar idlwave-completion-help-info nil)
5058 (defvar idlwave-current-obj_new-class nil)
5059 (defvar idlwave-complete-special nil)
5060
5061 (defun idlwave-complete (&optional arg module class)
5062 "Complete a function, procedure or keyword name at point.
5063 This function is smart and figures out what can be legally completed
5064 at this point.
5065 - At the beginning of a statement it completes procedure names.
5066 - In the middle of a statement it completes function names.
5067 - after a `(' or `,' in the argument list of a function or procedure,
5068 it completes a keyword of the relevant function or procedure.
5069 - In the first arg of `OBJ_NEW', it completes a class name.
5070
5071 When several completions are possible, a list will be displayed in the
5072 *Completions* buffer. If this list is too long to fit into the
5073 window, scrolling can be achieved by repeatedly pressing
5074 \\[idlwave-complete].
5075
5076 The function also knows about object methods. When it needs a class
5077 name, the action depends upon `idlwave-query-class', which see. You
5078 can force IDLWAVE to ask you for a class name with a
5079 \\[universal-argument] prefix argument to this command.
5080
5081 See also the variables `idlwave-keyword-completion-adds-equal' and
5082 `idlwave-function-completion-adds-paren'.
5083
5084 The optional ARG can be used to specify the completion type in order
5085 to override IDLWAVE's idea of what should be completed at point.
5086 Possible values are:
5087
5088 0 <=> query for the completion type
5089 1 <=> 'procedure
5090 2 <=> 'procedure-keyword
5091 3 <=> 'function
5092 4 <=> 'function-keyword
5093 5 <=> 'procedure-method
5094 6 <=> 'procedure-method-keyword
5095 7 <=> 'function-method
5096 8 <=> 'function-method-keyword
5097 9 <=> 'class
5098
5099 As a special case, the universal argument C-u forces completion of
5100 function names in places where the default would be a keyword.
5101
5102 For Lisp programmers only:
5103 When we force a keyword, optional argument MODULE can contain the module name.
5104 When we force a method or a method keyword, CLASS can specify the class."
5105 (interactive "P")
5106 (idlwave-routines)
5107 (let* ((where-list
5108 (if (and arg
5109 (or (integerp arg)
5110 (symbolp arg)))
5111 (idlwave-make-force-complete-where-list arg module class)
5112 (idlwave-where)))
5113 (what (nth 2 where-list))
5114 (idlwave-force-class-query (equal arg '(4))))
5115
5116 (if (and module (string-match "::" module))
5117 (setq class (substring module 0 (match-beginning 0))
5118 module (substring module (match-end 0))))
5119
5120 (cond
5121
5122 ((and (null arg)
5123 (eq (car-safe last-command) 'idlwave-display-completion-list)
5124 (get-buffer-window "*Completions*"))
5125 (setq this-command last-command)
5126 (idlwave-scroll-completions))
5127
5128 ;; Check for any special completion functions
5129 ((and idlwave-complete-special
5130 (idlwave-complete-special)))
5131
5132 ((and (idlwave-in-quote)
5133 (not (eq what 'class)))
5134 (idlwave-complete-filename))
5135
5136 ((null what)
5137 (error "Nothing to complete here"))
5138
5139 ((eq what 'class)
5140 (setq idlwave-completion-help-info '(class))
5141 (idlwave-complete-class))
5142
5143 ((eq what 'procedure)
5144 ;; Complete a procedure name
5145 (let* ((cw-list (nth 3 where-list))
5146 (class-selector (idlwave-determine-class cw-list 'pro))
5147 (super-classes (unless (idlwave-explicit-class-listed cw-list)
5148 (idlwave-all-class-inherits class-selector)))
5149 (isa (concat "procedure" (if class-selector "-method" "")))
5150 (type-selector 'pro))
5151 (setq idlwave-completion-help-info
5152 (list 'routine nil type-selector class-selector nil super-classes))
5153 (idlwave-complete-in-buffer
5154 'procedure (if class-selector 'method 'routine)
5155 (idlwave-routines) 'idlwave-selector
5156 (format "Select a %s name%s"
5157 isa
5158 (if class-selector
5159 (format " (class is %s)" class-selector)
5160 ""))
5161 isa
5162 'idlwave-attach-method-classes)))
5163
5164 ((eq what 'function)
5165 ;; Complete a function name
5166 (let* ((cw-list (nth 3 where-list))
5167 (class-selector (idlwave-determine-class cw-list 'fun))
5168 (super-classes (unless (idlwave-explicit-class-listed cw-list)
5169 (idlwave-all-class-inherits class-selector)))
5170 (isa (concat "function" (if class-selector "-method" "")))
5171 (type-selector 'fun))
5172 (setq idlwave-completion-help-info
5173 (list 'routine nil type-selector class-selector nil super-classes))
5174 (idlwave-complete-in-buffer
5175 'function (if class-selector 'method 'routine)
5176 (idlwave-routines) 'idlwave-selector
5177 (format "Select a %s name%s"
5178 isa
5179 (if class-selector
5180 (format " (class is %s)" class-selector)
5181 ""))
5182 isa
5183 'idlwave-attach-method-classes)))
5184
5185 ((and (memq what '(procedure-keyword function-keyword))
5186 (equal arg '(4)))
5187 (idlwave-complete 3))
5188
5189 ((eq what 'procedure-keyword)
5190 ;; Complete a procedure keyword
5191 (let* ((where (nth 3 where-list))
5192 (name (car where))
5193 (method-selector name)
5194 (type-selector 'pro)
5195 (class (idlwave-determine-class where 'pro))
5196 (class-selector class)
5197 (super-classes (idlwave-all-class-inherits class-selector))
5198 (isa (format "procedure%s-keyword" (if class "-method" "")))
5199 (entry (idlwave-best-rinfo-assq
5200 name 'pro class (idlwave-routines)))
5201 (list (nth 5 entry)))
5202 (unless (or entry (eq class t))
5203 (error "Nothing known about procedure %s"
5204 (idlwave-make-full-name class name)))
5205 (setq list (idlwave-fix-keywords name 'pro class list))
5206 (unless list (error (format "No keywords available for procedure %s"
5207 (idlwave-make-full-name class name))))
5208 (setq idlwave-completion-help-info
5209 (list 'keyword name type-selector class-selector nil super-classes))
5210 (idlwave-complete-in-buffer
5211 'keyword 'keyword list nil
5212 (format "Select keyword for procedure %s%s"
5213 (idlwave-make-full-name class name)
5214 (if (or (member '("_EXTRA") list)
5215 (member '("_REF_EXTRA") list))
5216 " (note _EXTRA)" ""))
5217 isa
5218 'idlwave-attach-keyword-classes)))
5219
5220 ((eq what 'function-keyword)
5221 ;; Complete a function keyword
5222 (let* ((where (nth 3 where-list))
5223 (name (car where))
5224 (method-selector name)
5225 (type-selector 'fun)
5226 (class (idlwave-determine-class where 'fun))
5227 (class-selector class)
5228 (super-classes (idlwave-all-class-inherits class-selector))
5229 (isa (format "function%s-keyword" (if class "-method" "")))
5230 (entry (idlwave-best-rinfo-assq
5231 name 'fun class (idlwave-routines)))
5232 (list (nth 5 entry))
5233 msg-name)
5234 (unless (or entry (eq class t))
5235 (error "Nothing known about function %s"
5236 (idlwave-make-full-name class name)))
5237 (setq list (idlwave-fix-keywords name 'fun class list))
5238 ;; OBJ_NEW: Messages mention the proper Init method
5239 (setq msg-name (if (and (null class)
5240 (string= (upcase name) "OBJ_NEW"))
5241 (concat idlwave-current-obj_new-class
5242 "::Init (via OBJ_NEW)")
5243 (idlwave-make-full-name class name)))
5244 (unless list (error (format "No keywords available for function %s"
5245 msg-name)))
5246 (setq idlwave-completion-help-info
5247 (list 'keyword name type-selector class-selector nil super-classes))
5248 (idlwave-complete-in-buffer
5249 'keyword 'keyword list nil
5250 (format "Select keyword for function %s%s" msg-name
5251 (if (or (member '("_EXTRA") list)
5252 (member '("_REF_EXTRA") list))
5253 " (note _EXTRA)" ""))
5254 isa
5255 'idlwave-attach-keyword-classes)))
5256
5257 (t (error "This should not happen (idlwave-complete)")))))
5258
5259 (defvar idlwave-complete-special nil
5260 "List of special completion functions.
5261 These functions are called for each completion. Each function must check
5262 if its own special completion context is present. If yes, it should
5263 use `idlwave-complete-in-buffer' to do some completion and return `t'.
5264 If such a function returns `t', *no further* attempts to complete
5265 other contexts will be done. If the function returns `nil', other completions
5266 will be tried.")
5267 (defun idlwave-complete-special ()
5268 (let ((functions idlwave-complete-special)
5269 fun)
5270 (catch 'exit
5271 (while (setq fun (pop functions))
5272 (if (funcall fun)
5273 (throw 'exit t)))
5274 nil)))
5275
5276 (defun idlwave-make-force-complete-where-list (what &optional module class)
5277 ;; Return an artificial WHERE specification to force the completion
5278 ;; routine to complete a specific item independent of context.
5279 ;; WHAT is the prefix arg of `idlwave-complete', see there for details.
5280 ;; MODULE and CLASS can be used to specify the routine name and class.
5281 ;; The class name will also be found in MODULE if that is like "class::mod".
5282 (let* ((what-list '(("procedure") ("procedure-keyword")
5283 ("function") ("function-keyword")
5284 ("procedure-method") ("procedure-method-keyword")
5285 ("function-method") ("function-method-keyword")
5286 ("class")))
5287 (module (idlwave-sintern-routine-or-method module class))
5288 (class (idlwave-sintern-class class))
5289 (what (cond
5290 ((equal what 0)
5291 (setq what
5292 (intern (completing-read
5293 "Complete what? " what-list nil t))))
5294 ((integerp what)
5295 (setq what (intern (car (nth (1- what) what-list)))))
5296 ((and what
5297 (symbolp what)
5298 (assoc (symbol-name what) what-list))
5299 what)
5300 (t (error "Illegal WHAT"))))
5301 (nil-list '(nil nil nil nil))
5302 (class-list (list nil nil (or class t) nil)))
5303
5304 (cond
5305
5306 ((eq what 'procedure)
5307 (list nil-list nil-list 'procedure nil-list nil))
5308
5309 ((eq what 'procedure-keyword)
5310 (let* ((class-selector nil)
5311 (super-classes nil)
5312 (type-selector 'pro)
5313 (pro (or module
5314 (idlwave-completing-read
5315 "Procedure: " (idlwave-routines) 'idlwave-selector))))
5316 (setq pro (idlwave-sintern-routine pro))
5317 (list nil-list nil-list 'procedure-keyword
5318 (list pro nil nil nil) nil)))
5319
5320 ((eq what 'function)
5321 (list nil-list nil-list 'function nil-list nil))
5322
5323 ((eq what 'function-keyword)
5324 (let* ((class-selector nil)
5325 (super-classes nil)
5326 (type-selector 'fun)
5327 (func (or module
5328 (idlwave-completing-read
5329 "Function: " (idlwave-routines) 'idlwave-selector))))
5330 (setq func (idlwave-sintern-routine func))
5331 (list nil-list nil-list 'function-keyword
5332 (list func nil nil nil) nil)))
5333
5334 ((eq what 'procedure-method)
5335 (list nil-list nil-list 'procedure class-list nil))
5336
5337 ((eq what 'procedure-method-keyword)
5338 (let* ((class (idlwave-determine-class class-list 'pro))
5339 (class-selector class)
5340 (super-classes (idlwave-all-class-inherits class-selector))
5341 (type-selector 'pro)
5342 (pro (or module
5343 (idlwave-completing-read
5344 (format "Procedure in %s class: " class-selector)
5345 (idlwave-routines) 'idlwave-selector))))
5346 (setq pro (idlwave-sintern-method pro))
5347 (list nil-list nil-list 'procedure-keyword
5348 (list pro nil class nil) nil)))
5349
5350 ((eq what 'function-method)
5351 (list nil-list nil-list 'function class-list nil))
5352
5353 ((eq what 'function-method-keyword)
5354 (let* ((class (idlwave-determine-class class-list 'fun))
5355 (class-selector class)
5356 (super-classes (idlwave-all-class-inherits class-selector))
5357 (type-selector 'fun)
5358 (func (or module
5359 (idlwave-completing-read
5360 (format "Function in %s class: " class-selector)
5361 (idlwave-routines) 'idlwave-selector))))
5362 (setq func (idlwave-sintern-method func))
5363 (list nil-list nil-list 'function-keyword
5364 (list func nil class nil) nil)))
5365
5366 ((eq what 'class)
5367 (list nil-list nil-list 'class nil-list nil))
5368
5369 (t (error "Illegal value for WHAT")))))
5370
5371 (defun idlwave-completing-read (&rest args)
5372 ;; Completing read, case insensitive
5373 (let ((old-value (default-value 'completion-ignore-case)))
5374 (unwind-protect
5375 (progn
5376 (setq-default completion-ignore-case t)
5377 (apply 'completing-read args))
5378 (setq-default completion-ignore-case old-value))))
5379
5380 (defvar idlwave-shell-default-directory)
5381 (defun idlwave-complete-filename ()
5382 "Use the comint stuff to complete a file name."
5383 (require 'comint)
5384 (let* ((comint-file-name-chars "~/A-Za-z0-9+@:_.$#%={}\\-")
5385 (comint-completion-addsuffix nil)
5386 (default-directory
5387 (if (and (boundp 'idlwave-shell-default-directory)
5388 (stringp idlwave-shell-default-directory)
5389 (file-directory-p idlwave-shell-default-directory))
5390 idlwave-shell-default-directory
5391 default-directory)))
5392 (comint-dynamic-complete-filename)))
5393
5394 (defun idlwave-make-full-name (class name)
5395 ;; Make a fully qualified module name including the class name
5396 (concat (if class (format "%s::" class) "") name))
5397
5398 (defun idlwave-rinfo-assoc (name type class list)
5399 "Like `idlwave-rinfo-assq', but sintern strings first."
5400 (idlwave-rinfo-assq
5401 (idlwave-sintern-routine-or-method name class)
5402 type (idlwave-sintern-class class) list))
5403
5404 (defun idlwave-rinfo-assq (name type class list)
5405 ;; Works like assq, but also checks type and class
5406 (catch 'exit
5407 (let (match)
5408 (while (setq match (assq name list))
5409 (and (or (eq type t)
5410 (eq (nth 1 match) type))
5411 (eq (nth 2 match) class)
5412 (throw 'exit match))
5413 (setq list (cdr (memq match list)))))))
5414
5415 (defun idlwave-rinfo-assq-any-class (name type class list)
5416 (let* ((classes (cons class (idlwave-all-class-inherits class)))
5417 class rtn)
5418 (while classes
5419 (if (setq rtn (idlwave-rinfo-assq name type (pop classes) list))
5420 (setq classes nil)))
5421 rtn))
5422
5423 (defun idlwave-best-rinfo-assq (name type class list)
5424 "Like `idlwave-rinfo-assq', but get all twins and sort, then return first."
5425 (let ((twins (idlwave-routine-twins
5426 (idlwave-rinfo-assq-any-class name type class list)
5427 list))
5428 syslibp)
5429 (when (> (length twins) 1)
5430 (setq twins (sort twins 'idlwave-routine-entry-compare-twins))
5431 (if (and (eq 'system (car (nth 3 (car twins))))
5432 (setq syslibp (idlwave-any-syslib (cdr twins)))
5433 (not (equal 1 syslibp)))
5434 ;; Its a syslib, so we need to remove the system entry
5435 (setq twins (cdr twins))))
5436 (car twins)))
5437
5438 (defun idlwave-best-rinfo-assoc (name type class list)
5439 "Like `idlwave-best-rinfo-assq', but sintern strings first."
5440 (idlwave-best-rinfo-assq
5441 (idlwave-sintern-routine-or-method name class)
5442 type (idlwave-sintern-class class) list))
5443
5444 (defun idlwave-any-syslib (entries)
5445 "Does the entry list ENTRIES contain a syslib entry?
5446 If yes, return the index (>=1)."
5447 (let (file (cnt 0))
5448 (catch 'exit
5449 (while entries
5450 (incf cnt)
5451 (setq file (cdr (nth 3 (car entries))))
5452 (if (and file
5453 (idlwave-syslib-p
5454 (idlwave-expand-lib-file-name file)))
5455 (throw 'exit cnt)
5456 (setq entries (cdr entries))))
5457 nil)))
5458
5459 (defun idlwave-all-assq (key list)
5460 "Return a list of all associations of Key in LIST."
5461 (let (rtn elt)
5462 (while (setq elt (assq key list))
5463 (push elt rtn)
5464 (setq list (cdr (memq elt list))))
5465 (nreverse rtn)))
5466
5467 (defun idlwave-all-method-classes (method &optional type)
5468 "Return all classes which have a method METHOD. TYPE is 'fun or 'pro.
5469 When TYPE is not specified, both procedures and functions will be considered."
5470 (if (null method)
5471 (mapcar 'car (idlwave-class-alist))
5472 (let (rtn)
5473 (mapcar (lambda (x)
5474 (and (nth 2 x)
5475 (or (not type)
5476 (eq type (nth 1 x)))
5477 (push (nth 2 x) rtn)))
5478 (idlwave-all-assq method (idlwave-routines)))
5479 (idlwave-uniquify rtn))))
5480
5481 (defun idlwave-all-method-keyword-classes (method keyword &optional type)
5482 "Return all classes which have a method METHOD with keyword KEYWORD.
5483 TYPE is 'fun or 'pro.
5484 When TYPE is not specified, both procedures and functions will be considered."
5485 (if (or (null method)
5486 (null keyword))
5487 nil
5488 (let (rtn)
5489 (mapcar (lambda (x)
5490 (and (nth 2 x)
5491 (or (not type)
5492 (eq type (nth 1 x)))
5493 (assoc keyword (nth 5 x))
5494 (push (nth 2 x) rtn)))
5495 (idlwave-all-assq method (idlwave-routines)))
5496 (idlwave-uniquify rtn))))
5497
5498 (defun idlwave-members-only (list club)
5499 "Return list of all elements in LIST which are also in CLUB."
5500 (let (rtn)
5501 (while list
5502 (if (member (car list) club)
5503 (setq rtn (cons (car list) rtn)))
5504 (setq list (cdr list)))
5505 (nreverse rtn)))
5506
5507 (defun idlwave-nonmembers-only (list club)
5508 "Return list of all elements in LIST which are not in CLUB."
5509 (let (rtn)
5510 (while list
5511 (if (member (car list) club)
5512 nil
5513 (setq rtn (cons (car list) rtn)))
5514 (setq list (cdr list)))
5515 (nreverse rtn)))
5516
5517 (defun idlwave-explicit-class-listed (info)
5518 "Return whether or not the class is listed explicitly, ala a->b::c.
5519 INFO is as returned by idlwave-what-function or -procedure."
5520 (let ((apos (nth 3 info)))
5521 (if apos
5522 (save-excursion (goto-char apos)
5523 (looking-at "->[a-zA-Z][a-zA-Z0-9$_]*::")))))
5524
5525 (defun idlwave-determine-class (info type)
5526 ;; Determine the class of a routine call. INFO is the structure returned
5527 ;; `idlwave-what-function' or `idlwave-what-procedure'.
5528 ;; The third element in this structure is the class. When nil, we return nil.
5529 ;; When t, try to get the class from text properties at the arrow. When
5530 ;; the object is "self", we use the class of the current routine.
5531 ;; otherwise prompt the user for a class name. Also stores the selected
5532 ;; class as a text property at the arrow.
5533 ;; TYPE is 'fun or 'pro.
5534 (let* ((class (nth 2 info))
5535 (apos (nth 3 info))
5536 (nassoc (assoc (if (stringp (car info))
5537 (upcase (car info))
5538 (car info))
5539 idlwave-query-class))
5540 (dassoc (assq (if (car info) 'keyword-default 'method-default)
5541 idlwave-query-class))
5542 (query (cond (nassoc (cdr nassoc))
5543 (dassoc (cdr dassoc))
5544 (t t)))
5545 (arrow (and apos (string= (buffer-substring apos (+ 2 apos)) "->")))
5546 (is-self
5547 (and arrow
5548 (save-excursion (goto-char apos)
5549 (forward-word -1)
5550 (let ((case-fold-search t))
5551 (looking-at "self\\>")))))
5552 (force-query idlwave-force-class-query)
5553 store class-alist)
5554 (cond
5555 ((null class) nil)
5556 ((eq t class)
5557 ;; There is an object which would like to know its class
5558 (if (and arrow (get-text-property apos 'idlwave-class)
5559 idlwave-store-inquired-class
5560 (not force-query))
5561 (setq class (get-text-property apos 'idlwave-class)
5562 class (idlwave-sintern-class class)))
5563 (when (and (eq t class)
5564 is-self)
5565 (setq class (or (nth 2 (idlwave-current-routine)) class)))
5566 (when (and (eq class t)
5567 (or force-query query))
5568 (setq class-alist
5569 (mapcar 'list (idlwave-all-method-classes (car info) type)))
5570 (setq class
5571 (idlwave-sintern-class
5572 (cond
5573 ((and (= (length class-alist) 0) (not force-query))
5574 (error "No classes available with method %s" (car info)))
5575 ((and (= (length class-alist) 1) (not force-query))
5576 (car (car class-alist)))
5577 (t
5578 (setq store idlwave-store-inquired-class)
5579 (idlwave-completing-read
5580 (format "Class%s: " (if (stringp (car info))
5581 (format " for %s method %s"
5582 type (car info))
5583 ""))
5584 class-alist nil nil nil 'idlwave-class-history))))))
5585 (when (and class (not (eq t class)))
5586 ;; We have a real class here
5587 (when (and store arrow)
5588 (put-text-property apos (+ apos 2) 'idlwave-class class)
5589 (put-text-property apos (+ apos 2) 'face idlwave-class-arrow-face))
5590 (setf (nth 2 info) class))
5591 ;; Return the class
5592 class)
5593 ;; Default as fallback
5594 (t class))))
5595
5596 (defvar type-selector)
5597 (defvar class-selector)
5598 (defvar method-selector)
5599 (defvar super-classes)
5600 (defun idlwave-selector (a)
5601 (and (eq (nth 1 a) type-selector)
5602 (or (and (nth 2 a) (eq class-selector t))
5603 (eq (nth 2 a) class-selector)
5604 (memq (nth 2 a) super-classes)
5605 )))
5606
5607 (defun idlwave-where ()
5608 "Find out where we are.
5609 The return value is a list with the following stuff:
5610 \(PRO-LIST FUNC-LIST COMPLETE-WHAT CW-LIST LAST-CHAR)
5611
5612 PRO-LIST (PRO POINT CLASS ARROW)
5613 FUNC-LIST (FUNC POINT CLASS ARROW)
5614 COMPLETE-WHAT a symbol indicating what kind of completion makes sense here
5615 CW-LIST (PRO-OR-FUNC POINT CLASS ARROW) Like PRO-LIST, for what can
5616 be completed here.
5617 LAST-CHAR last relevant character before point (non-white non-comment,
5618 not part of current identifier or leading slash).
5619
5620 In the lists, we have these meanings:
5621 PRO: Procedure name
5622 FUNC: Function name
5623 POINT: Where is this
5624 CLASS: What class has the routine (nil=no, t=is method, but class unknown)
5625 ARROW: Location of the arrow"
5626 (idlwave-routines)
5627 (let* (;(bos (save-excursion (idlwave-beginning-of-statement) (point)))
5628 (bos (save-excursion (idlwave-start-of-substatement 'pre) (point)))
5629 (func-entry (idlwave-what-function bos))
5630 (func (car func-entry))
5631 (func-class (nth 1 func-entry))
5632 (func-arrow (nth 2 func-entry))
5633 (func-point (or (nth 3 func-entry) 0))
5634 (func-level (or (nth 4 func-entry) 0))
5635 (pro-entry (idlwave-what-procedure bos))
5636 (pro (car pro-entry))
5637 (pro-class (nth 1 pro-entry))
5638 (pro-arrow (nth 2 pro-entry))
5639 (pro-point (or (nth 3 pro-entry) 0))
5640 (last-char (idlwave-last-valid-char))
5641 (case-fold-search t)
5642 cw cw-mod cw-arrow cw-class cw-point)
5643 (if (< func-point pro-point) (setq func nil))
5644 (cond
5645 ((string-match "\\`[ \t]*\\(pro\\|function\\)[ \t]+[a-zA-Z0-9_]*\\'"
5646 (buffer-substring bos (point)))
5647 (setq cw 'class))
5648 ((string-match
5649 "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)?\\'"
5650 (buffer-substring (if (> pro-point 0) pro-point bos) (point)))
5651 (setq cw 'procedure cw-class pro-class cw-point pro-point
5652 cw-arrow pro-arrow))
5653 ((string-match "\\`[ \t]*\\(pro\\|function\\)\\>"
5654 (buffer-substring bos (point)))
5655 nil)
5656 ((string-match "OBJ_NEW([ \t]*['\"]\\([a-zA-Z0-9$_]*\\)?\\'"
5657 (buffer-substring bos (point)))
5658 (setq cw 'class))
5659 ((string-match "\\<inherits\\s-+\\([a-zA-Z0-9$_]*\\)?\\'"
5660 (buffer-substring bos (point)))
5661 (setq cw 'class))
5662 ((and func
5663 (> func-point pro-point)
5664 (= func-level 1)
5665 (memq last-char '(?\( ?,)))
5666 (setq cw 'function-keyword cw-mod func cw-point func-point
5667 cw-class func-class cw-arrow func-arrow))
5668 ((and pro (eq last-char ?,))
5669 (setq cw 'procedure-keyword cw-mod pro cw-point pro-point
5670 cw-class pro-class cw-arrow pro-arrow))
5671 ; ((member last-char '(?\' ?\) ?\] ?!))
5672 ; ;; after these chars, a function makes no sense
5673 ; ;; FIXME: I am sure there can be more in this list
5674 ; ;; FIXME: Do we want to do this at all?
5675 ; nil)
5676 ;; Everywhere else we try a function.
5677 (t
5678 (setq cw 'function)
5679 (save-excursion
5680 (if (re-search-backward "->[ \t]*\\(\\([$a-zA-Z0-9_]+\\)::\\)?[$a-zA-Z0-9_]*\\=" bos t)
5681 (setq cw-arrow (match-beginning 0)
5682 cw-class (if (match-end 2)
5683 (idlwave-sintern-class (match-string 2))
5684 t))))))
5685 (list (list pro pro-point pro-class pro-arrow)
5686 (list func func-point func-class func-arrow)
5687 cw
5688 (list cw-mod cw-point cw-class cw-arrow)
5689 last-char)))
5690
5691 (defun idlwave-this-word (&optional class)
5692 ;; Grab the word around point. CLASS is for the `skip-chars=...' functions
5693 (setq class (or class "a-zA-Z0-9$_"))
5694 (save-excursion
5695 (buffer-substring-no-properties
5696 (progn (skip-chars-backward class) (point))
5697 (progn (skip-chars-forward class) (point)))))
5698
5699 (defun idlwave-what-function (&optional bound)
5700 ;; Find out if point is within the argument list of a function.
5701 ;; The return value is ("function-name" (point) level).
5702 ;; Level is 1 on the to level parenthesis, higher further down.
5703
5704 ;; If the optional BOUND is an integer, bound backwards directed
5705 ;; searches to this point.
5706
5707 (catch 'exit
5708 (let (pos
5709 func-point
5710 (cnt 0)
5711 func arrow-start class)
5712 (idlwave-with-special-syntax
5713 (save-restriction
5714 (save-excursion
5715 (narrow-to-region (max 1 (or bound 0)) (point-max))
5716 ;; move back out of the current parenthesis
5717 (while (condition-case nil
5718 (progn (up-list -1) t)
5719 (error nil))
5720 (setq pos (point))
5721 (incf cnt)
5722 (when (and (= (following-char) ?\()
5723 (re-search-backward
5724 "\\(::\\|\\<\\)\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\="
5725 bound t))
5726 (setq func (match-string 2)
5727 func-point (goto-char (match-beginning 2))
5728 pos func-point)
5729 (if (re-search-backward
5730 "->[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\=" bound t)
5731 (setq arrow-start (match-beginning 0)
5732 class (or (match-string 2) t)))
5733 (throw
5734 'exit
5735 (list
5736 (idlwave-sintern-routine-or-method func class)
5737 (idlwave-sintern-class class)
5738 arrow-start func-point cnt)))
5739 (goto-char pos))
5740 (throw 'exit nil)))))))
5741
5742 (defun idlwave-what-procedure (&optional bound)
5743 ;; Find out if point is within the argument list of a procedure.
5744 ;; The return value is ("procedure-name" class arrow-pos (point)).
5745
5746 ;; If the optional BOUND is an integer, bound backwards directed
5747 ;; searches to this point.
5748 (let ((pos (point)) pro-point
5749 pro class arrow-start string)
5750 (save-excursion
5751 ;;(idlwave-beginning-of-statement)
5752 (idlwave-start-of-substatement 'pre)
5753 (setq string (buffer-substring (point) pos))
5754 (if (string-match
5755 "\\`\\(.*&\\)?[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\(,\\|\\'\\)" string)
5756 (setq pro (match-string 2 string)
5757 pro-point (+ (point) (match-beginning 2)))
5758 (if (and (idlwave-skip-object)
5759 (setq string (buffer-substring (point) pos))
5760 (string-match
5761 "\\`[ \t]*\\(->\\)[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\([a-zA-Z][a-zA-Z0-9$_]*\\)?[ \t]*\\(,\\|\\'\\)" string))
5762 (setq pro (if (match-beginning 4)
5763 (match-string 4 string))
5764 pro-point (if (match-beginning 4)
5765 (+ (point) (match-beginning 4))
5766 pos)
5767 arrow-start (+ (point) (match-beginning 1))
5768 class (or (match-string 3 string) t)))))
5769 (list (idlwave-sintern-routine-or-method pro class)
5770 (idlwave-sintern-class class)
5771 arrow-start
5772 pro-point)))
5773
5774 (defun idlwave-skip-object ()
5775 ;; If there is an object at point, move over it and return t.
5776 (let ((pos (point)))
5777 (if (catch 'exit
5778 (save-excursion
5779 (skip-chars-forward " ") ; white space
5780 (skip-chars-forward "*") ; de-reference
5781 (cond
5782 ((looking-at idlwave-identifier)
5783 (goto-char (match-end 0)))
5784 ((eq (following-char) ?\()
5785 nil)
5786 (t (throw 'exit nil)))
5787 (catch 'endwhile
5788 (while t
5789 (cond ((eq (following-char) ?.)
5790 (forward-char 1)
5791 (if (not (looking-at idlwave-identifier))
5792 (throw 'exit nil))
5793 (goto-char (match-end 0)))
5794 ((memq (following-char) '(?\( ?\[))
5795 (condition-case nil
5796 (forward-list 1)
5797 (error (throw 'exit nil))))
5798 (t (throw 'endwhile t)))))
5799 (if (looking-at "[ \t]*->")
5800 (throw 'exit (setq pos (match-beginning 0)))
5801 (throw 'exit nil))))
5802 (goto-char pos)
5803 nil)))
5804
5805
5806 (defun idlwave-last-valid-char ()
5807 "Return the last character before point which is not white or a comment
5808 and also not part of the current identifier. Since we do this in
5809 order to identify places where keywords are, we consider the initial
5810 `/' of a keyword as part of the identifier.
5811 This function is not general, can only be used for completion stuff."
5812 (catch 'exit
5813 (save-excursion
5814 ;; skip the current identifier
5815 (skip-chars-backward "a-zA-Z0-9_$")
5816 ;; also skip a leading slash which might be belong to the keyword
5817 (if (eq (preceding-char) ?/)
5818 (backward-char 1))
5819 ;; FIXME: does not check if this is a valid identifier
5820 (while t
5821 (skip-chars-backward " \t")
5822 (cond
5823 ((memq (preceding-char) '(?\; ?\$)) (throw 'exit nil))
5824 ((eq (preceding-char) ?\n)
5825 (beginning-of-line 0)
5826 (if (looking-at "\\([^;\n]*\\)\\$[ \t]*\\(;[^\n]*\\)?\n")
5827 ;; continuation line
5828 (goto-char (match-end 1))
5829 (throw 'exit nil)))
5830 (t (throw 'exit (preceding-char))))))))
5831
5832 (defvar idlwave-complete-after-success-form nil
5833 "A form to evaluate after successful completion.")
5834 (defvar idlwave-complete-after-success-form-force nil
5835 "A form to evaluate after completion selection in *Completions* buffer.")
5836 (defconst idlwave-completion-mark (make-marker)
5837 "A mark pointing to the beginning of the completion string.")
5838
5839 (defun idlwave-complete-in-buffer (type stype list selector prompt isa
5840 &optional prepare-display-function)
5841 "Perform TYPE completion of word before point against LIST.
5842 SELECTOR is the PREDICATE argument for the completion function.
5843 Show PROMPT in echo area. TYPE is one of 'function, 'procedure or 'keyword."
5844 (let* ((completion-ignore-case t)
5845 beg (end (point)) slash part spart completion all-completions
5846 dpart dcompletion)
5847
5848 (unless list
5849 (error (concat prompt ": No completions available")))
5850
5851 ;; What is already in the buffer?
5852 (save-excursion
5853 (skip-chars-backward "a-zA-Z0-9_$")
5854 (setq slash (eq (preceding-char) ?/)
5855 beg (point)
5856 idlwave-complete-after-success-form
5857 (list 'idlwave-after-successful-completion
5858 (list 'quote type) slash beg)
5859 idlwave-complete-after-success-form-force
5860 (list 'idlwave-after-successful-completion
5861 (list 'quote type) slash (list 'quote 'force))))
5862
5863 ;; Try a completion
5864 (setq part (buffer-substring beg end)
5865 dpart (downcase part)
5866 spart (idlwave-sintern stype part)
5867 completion (try-completion part list selector)
5868 dcompletion (if (stringp completion) (downcase completion)))
5869 (cond
5870 ((null completion)
5871 ;; nothing available.
5872 (error "Can't find %s completion for \"%s\"" isa part))
5873 ((and (not (equal dpart dcompletion))
5874 (not (eq t completion)))
5875 ;; We can add something
5876 (delete-region beg end)
5877 (if (and (string= part dpart)
5878 (or (not (string= part ""))
5879 idlwave-complete-empty-string-as-lower-case)
5880 (not idlwave-completion-force-default-case))
5881 (insert dcompletion)
5882 (insert completion))
5883 (if (eq t (try-completion completion list selector))
5884 ;; Now this is a unique match
5885 (idlwave-after-successful-completion type slash beg))
5886 t)
5887 ((or (eq completion t)
5888 (and (equal dpart dcompletion)
5889 (= 1 (length (setq all-completions
5890 (idlwave-uniquify
5891 (all-completions part list selector)))))))
5892 ;; This is already complete
5893 (idlwave-after-successful-completion type slash beg)
5894 (message "%s is already the complete %s" part isa)
5895 nil)
5896 (t
5897 ;; We cannot add something - offer a list.
5898 (message "Making completion list...")
5899 (let* ((list all-completions)
5900 ;; "complete" means, this is already a valid completion
5901 (complete (memq spart all-completions))
5902 (completion-highlight-first-word-only t) ; XEmacs
5903 (completion-fixup-function ; Emacs
5904 (lambda () (and (eq (preceding-char) ?>)
5905 (re-search-backward " <" beg t)))))
5906 (setq list (sort list (lambda (a b)
5907 (string< (downcase a) (downcase b)))))
5908 (if prepare-display-function
5909 (setq list (funcall prepare-display-function list)))
5910 (if (and (string= part dpart)
5911 (or (not (string= part ""))
5912 idlwave-complete-empty-string-as-lower-case)
5913 (not idlwave-completion-force-default-case))
5914 (setq list (mapcar (lambda (x)
5915 (if (listp x)
5916 (setcar x (downcase (car x)))
5917 (setq x (downcase x)))
5918 x)
5919 list)))
5920 (idlwave-display-completion-list list prompt beg complete))
5921 t))))
5922
5923 (defun idlwave-complete-class ()
5924 "Complete a class at point."
5925 (interactive)
5926 ;; Call `idlwave-routines' to make sure the class list will be available
5927 (idlwave-routines)
5928 ;; Check for the special case of completing empty string after pro/function
5929 (if (let ((case-fold-search t))
5930 (save-excursion
5931 (and
5932 (re-search-backward "\\<\\(pro\\|function\\)[ \t]+\\="
5933 (- (point) 15) t)
5934 (goto-char (point-min))
5935 (re-search-forward
5936 "^[ \t]*\\(pro\\|function\\)[ \t]+\\([a-zA-Z0-9_]+::\\)" nil t))))
5937 ;; Yank the full class specification
5938 (insert (match-string 2))
5939 ;; Do the completion
5940 (idlwave-complete-in-buffer 'class 'class (idlwave-class-alist) nil
5941 "Select a class" "class")))
5942
5943 (defun idlwave-attach-classes (list is-kwd show-classes)
5944 ;; Attach the proper class list to a LIST of completion items.
5945 ;; IS-KWD, when non-nil, shows its keywords - otherwise its methods
5946 ;; SHOW-CLASSES is the value of `idlwave-completion-show-classes'.
5947 (catch 'exit
5948 (if (or (null show-classes) ; don't want to see classes
5949 (null class-selector) ; not a method call
5950 (and (stringp class-selector) ; the class is already known
5951 (not super-classes))) ; no possibilities for inheritance
5952 ;; In these cases, we do not have to do anything
5953 (throw 'exit list))
5954
5955 (let* ((do-prop (and (>= show-classes 0)
5956 (>= emacs-major-version 21)))
5957 (do-buf (not (= show-classes 0)))
5958 ; (do-dots (featurep 'xemacs))
5959 (do-dots t)
5960 (inherit (if super-classes
5961 (cons class-selector super-classes)))
5962 (max (abs show-classes))
5963 (lmax (if do-dots (apply 'max (mapcar 'length list))))
5964 classes nclasses class-info space)
5965 (mapcar
5966 (lambda (x)
5967 ;; get the classes
5968 (setq classes
5969 (if is-kwd
5970 (idlwave-all-method-keyword-classes
5971 method-selector x type-selector)
5972 (idlwave-all-method-classes x type-selector)))
5973 (if inherit
5974 (setq classes
5975 (delq nil
5976 (mapcar (lambda (x) (if (memq x inherit) x nil))
5977 classes))))
5978 (setq nclasses (length classes))
5979 ;; Make the separator between item and class-info
5980 (if do-dots
5981 (setq space (concat " " (make-string (- lmax (length x)) ?.)))
5982 (setq space " "))
5983 (if do-buf
5984 ;; We do want info in the buffer
5985 (if (<= nclasses max)
5986 (setq class-info (concat
5987 space
5988 "<" (mapconcat 'identity classes ",") ">"))
5989 (setq class-info (format "%s<%d classes>" space nclasses)))
5990 (setq class-info nil))
5991 (when do-prop
5992 ;; We do want properties
5993 (setq x (copy-sequence x))
5994 (put-text-property 0 (length x)
5995 'help-echo (mapconcat 'identity classes " ")
5996 x))
5997 (if class-info
5998 (list x class-info)
5999 x))
6000 list))))
6001
6002 (defun idlwave-attach-method-classes (list)
6003 ;; Call idlwave-attach-classes with method parameters
6004 (idlwave-attach-classes list nil idlwave-completion-show-classes))
6005 (defun idlwave-attach-keyword-classes (list)
6006 ;; Call idlwave-attach-classes with keyword parameters
6007 (idlwave-attach-classes list t idlwave-completion-show-classes))
6008
6009 ;;----------------------------------------------------------------------
6010 ;;----------------------------------------------------------------------
6011 ;;----------------------------------------------------------------------
6012 ;;----------------------------------------------------------------------
6013 ;;----------------------------------------------------------------------
6014 (defvar rtn)
6015 (defun idlwave-pset (item)
6016 (set 'rtn item))
6017
6018 (defun idlwave-popup-select (ev list title &optional sort)
6019 "Select an item in LIST with a popup menu.
6020 TITLE is the title to put atop the popup. If SORT is non-nil,
6021 sort the list before displaying"
6022 (let ((maxpopup idlwave-max-popup-menu-items)
6023 rtn menu resp)
6024 (cond ((null list))
6025 ((= 1 (length list))
6026 (setq rtn (car list)))
6027 ((featurep 'xemacs)
6028 (if sort (setq list (sort list (lambda (a b)
6029 (string< (upcase a) (upcase b))))))
6030 (setq menu
6031 (append (list title)
6032 (mapcar (lambda (x) (vector x (list 'idlwave-pset
6033 x)))
6034 list)))
6035 (setq menu (idlwave-split-menu-xemacs menu maxpopup))
6036 (setq resp (get-popup-menu-response menu))
6037 (funcall (event-function resp) (event-object resp)))
6038 (t
6039 (if sort (setq list (sort list (lambda (a b)
6040 (string< (upcase a) (upcase b))))))
6041 (setq menu (cons title
6042 (list
6043 (append (list "")
6044 (mapcar (lambda(x) (cons x x)) list)))))
6045 (setq menu (idlwave-split-menu-emacs menu maxpopup))
6046 (setq rtn (x-popup-menu ev menu))))
6047 rtn))
6048
6049 (defun idlwave-split-menu-xemacs (menu N)
6050 "Split the MENU into submenus of maximum length N."
6051 (if (<= (length menu) (1+ N))
6052 ;; No splitting needed
6053 menu
6054 (let* ((title (car menu))
6055 (entries (cdr menu))
6056 (menu (list title))
6057 (cnt 0)
6058 (nextmenu nil))
6059 (while entries
6060 (while (and entries (< cnt N))
6061 (setq cnt (1+ cnt)
6062 nextmenu (cons (car entries) nextmenu)
6063 entries (cdr entries)))
6064 (setq nextmenu (nreverse nextmenu))
6065 (setq nextmenu (cons (format "%s...%s"
6066 (aref (car nextmenu) 0)
6067 (aref (nth (1- cnt) nextmenu) 0))
6068 nextmenu))
6069 (setq menu (cons nextmenu menu)
6070 nextmenu nil
6071 cnt 0))
6072 (nreverse menu))))
6073
6074 (defun idlwave-split-menu-emacs (menu N)
6075 "Split the MENU into submenus of maximum length N."
6076 (if (<= (length (nth 1 menu)) (1+ N))
6077 ;; No splitting needed
6078 menu
6079 (let* ((title (car menu))
6080 (entries (cdr (nth 1 menu)))
6081 (menu nil)
6082 (cnt 0)
6083 (nextmenu nil))
6084 (while entries
6085 (while (and entries (< cnt N))
6086 (setq cnt (1+ cnt)
6087 nextmenu (cons (car entries) nextmenu)
6088 entries (cdr entries)))
6089 (setq nextmenu (nreverse nextmenu))
6090 (prin1 nextmenu)
6091 (setq nextmenu (cons (format "%s...%s"
6092 (car (car nextmenu))
6093 (car (nth (1- cnt) nextmenu)))
6094 nextmenu))
6095 (setq menu (cons nextmenu menu)
6096 nextmenu nil
6097 cnt 0))
6098 (setq menu (nreverse menu))
6099 (setq menu (cons title menu))
6100 menu)))
6101
6102 (defvar idlwave-completion-setup-hook nil)
6103
6104 (defun idlwave-scroll-completions (&optional message)
6105 "Scroll the completion window on this frame."
6106 (let ((cwin (get-buffer-window "*Completions*" 'visible))
6107 (win (selected-window)))
6108 (unwind-protect
6109 (progn
6110 (select-window cwin)
6111 (condition-case nil
6112 (scroll-up)
6113 (error (if (and (listp last-command)
6114 (nth 2 last-command))
6115 (progn
6116 (select-window win)
6117 (eval idlwave-complete-after-success-form))
6118 (set-window-start cwin (point-min)))))
6119 (and message (message message)))
6120 (select-window win))))
6121
6122 (defun idlwave-display-completion-list (list &optional message beg complete)
6123 "Display the completions in LIST in the completions buffer and echo MESSAGE."
6124 (unless (and (get-buffer-window "*Completions*")
6125 (idlwave-local-value 'idlwave-completion-p "*Completions*"))
6126 (move-marker idlwave-completion-mark beg)
6127 (setq idlwave-before-completion-wconf (current-window-configuration)))
6128
6129 (if (featurep 'xemacs)
6130 (idlwave-display-completion-list-xemacs
6131 list)
6132 (idlwave-display-completion-list-emacs list))
6133
6134 ;; Store a special value in `this-command'. When `idlwave-complete'
6135 ;; finds this in `last-command', it will scroll the *Completions* buffer.
6136 (setq this-command (list 'idlwave-display-completion-list message complete))
6137
6138 ;; Mark the completions buffer as created by cib
6139 (idlwave-set-local 'idlwave-completion-p t "*Completions*")
6140
6141 ;; Fontify the classes
6142 (if (and idlwave-completion-fontify-classes
6143 (consp (car list)))
6144 (idlwave-completion-fontify-classes))
6145
6146 ;; Run the hook
6147 (run-hooks 'idlwave-completion-setup-hook)
6148
6149 ;; Display the message
6150 (message (or message "Making completion list...done")))
6151
6152 (defun idlwave-choose (function &rest args)
6153 "Call FUNCTION as a completion chooser and pass ARGS to it."
6154 (let ((completion-ignore-case t)) ; install correct value
6155 (apply function args))
6156 (if (and (eq major-mode 'idlwave-shell-mode)
6157 (boundp 'font-lock-mode)
6158 (not font-lock-mode))
6159 ;; Remove the fontification of the word before point
6160 (let ((beg (save-excursion
6161 (skip-chars-backward "a-zA-Z0-9_")
6162 (point))))
6163 (remove-text-properties beg (point) '(face nil))))
6164 (eval idlwave-complete-after-success-form-force))
6165
6166 (defun idlwave-restore-wconf-after-completion ()
6167 "Restore the old (before completion) window configuration."
6168 (and idlwave-completion-restore-window-configuration
6169 idlwave-before-completion-wconf
6170 (set-window-configuration idlwave-before-completion-wconf)))
6171
6172 (defun idlwave-set-local (var value &optional buffer)
6173 "Set the buffer-local value of VAR in BUFFER to VALUE."
6174 (save-excursion
6175 (set-buffer (or buffer (current-buffer)))
6176 (set (make-local-variable var) value)))
6177
6178 (defun idlwave-local-value (var &optional buffer)
6179 "Return the value of VAR in BUFFER, but only if VAR is local to BUFFER."
6180 (save-excursion
6181 (set-buffer (or buffer (current-buffer)))
6182 (and (local-variable-p var (current-buffer))
6183 (symbol-value var))))
6184
6185 ;; In XEmacs, we can use :activate-callback directly to advice the
6186 ;; choose functions. We use the private keymap only for the online
6187 ;; help feature.
6188
6189 (defvar idlwave-completion-map nil
6190 "Keymap for completion-list-mode with idlwave-complete.")
6191
6192 (defun idlwave-display-completion-list-xemacs (list &rest cl-args)
6193 (with-output-to-temp-buffer "*Completions*"
6194 (apply 'display-completion-list list
6195 ':activate-callback 'idlwave-default-choose-completion
6196 cl-args))
6197 (save-excursion
6198 (set-buffer "*Completions*")
6199 (use-local-map
6200 (or idlwave-completion-map
6201 (setq idlwave-completion-map
6202 (idlwave-make-modified-completion-map-xemacs
6203 (current-local-map)))))))
6204
6205 (defun idlwave-default-choose-completion (&rest args)
6206 "Execute `default-choose-completion' and then restore the win-conf."
6207 (apply 'idlwave-choose 'default-choose-completion args))
6208
6209 (defun idlwave-make-modified-completion-map-xemacs (old-map)
6210 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
6211 (let ((new-map (copy-keymap old-map)))
6212 (define-key new-map [button3up] 'idlwave-mouse-completion-help)
6213 (define-key new-map [button3] (lambda ()
6214 (interactive)
6215 (setq this-command last-command)))
6216 new-map))
6217
6218 ;; In Emacs we also to replace choose keybindings in the completion
6219 ;; map in order to install our wrappers.
6220
6221 (defun idlwave-display-completion-list-emacs (list)
6222 "Display completion list and install the choose wrappers."
6223 (with-output-to-temp-buffer "*Completions*"
6224 (display-completion-list list))
6225 (save-excursion
6226 (set-buffer "*Completions*")
6227 (use-local-map
6228 (or idlwave-completion-map
6229 (setq idlwave-completion-map
6230 (idlwave-make-modified-completion-map-emacs
6231 (current-local-map)))))))
6232
6233 (defun idlwave-make-modified-completion-map-emacs (old-map)
6234 "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
6235 (let ((new-map (copy-keymap old-map)))
6236 (substitute-key-definition
6237 'choose-completion 'idlwave-choose-completion new-map)
6238 (substitute-key-definition
6239 'mouse-choose-completion 'idlwave-mouse-choose-completion new-map)
6240 (define-key new-map [mouse-3] 'idlwave-mouse-completion-help)
6241 new-map))
6242
6243 (defun idlwave-choose-completion (&rest args)
6244 "Choose the completion that point is in or next to."
6245 (interactive)
6246 (apply 'idlwave-choose 'choose-completion args))
6247
6248 (defun idlwave-mouse-choose-completion (&rest args)
6249 "Click on an alternative in the `*Completions*' buffer to choose it."
6250 (interactive "e")
6251 (apply 'idlwave-choose 'mouse-choose-completion args))
6252
6253 ;;----------------------------------------------------------------------
6254 ;;----------------------------------------------------------------------
6255
6256 ;;; ------------------------------------------------------------------------
6257 ;;; Sturucture parsing code, and code to manage class info
6258
6259 ;;
6260 ;; - Go again over the documentation how to write a completion
6261 ;; plugin. It is in self.el, but currently still very bad.
6262 ;; This could be in a separate file in the distribution, or
6263 ;; in an appendix for the manual.
6264
6265 (defun idlwave-struct-tags ()
6266 "Return a list of all tags in the structure defined at point.
6267 Point is expected just before the opening `{' of the struct definition."
6268 (save-excursion
6269 (let* ((borders (idlwave-struct-borders))
6270 (beg (car borders))
6271 (end (cdr borders))
6272 tags)
6273 (goto-char beg)
6274 (while (re-search-forward "[{,][ \t]*\\(\\$.*\n[ \t]*\\)?\\([a-zA-Z][a-zA-Z0-9_]*\\)[ \t]*:" end t)
6275 ;; Check if we are still on the top level of the structure.
6276 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
6277 (= (point) beg))
6278 (push (match-string 2) tags))
6279 (goto-char (match-end 0)))
6280 (nreverse tags))))
6281
6282 (defun idlwave-struct-inherits ()
6283 "Return a list of all `inherits' names in the struct at point.
6284 Point is expected just before the opening `{' of the struct definition."
6285 (save-excursion
6286 (let* ((borders (idlwave-struct-borders))
6287 (beg (car borders))
6288 (end (cdr borders))
6289 (case-fold-search t)
6290 names)
6291 (goto-char beg)
6292 (while (re-search-forward "[{,][ \t]*\\(\\$.*\n[ \t]*\\)?inherits[ \t]*\\(\\$.*\n[ \t]*\\)?\\([a-zA-Z][a-zA-Z0-9_]*\\)" end t)
6293 ;; Check if we are still on the top level of the structure.
6294 (if (and (condition-case nil (progn (up-list -1) t) (error nil))
6295 (= (point) beg))
6296 (push (match-string 3) names))
6297 (goto-char (match-end 0)))
6298 (nreverse names))))
6299
6300 (defun idlwave-in-structure ()
6301 "Return t if point is inside an IDL structure."
6302 (let ((beg (point)))
6303 (save-excursion
6304 (if (not (or (idlwave-in-comment) (idlwave-in-quote)))
6305 (if (idlwave-find-structure-definition nil nil 'back)
6306 (let ((borders (idlwave-struct-borders)))
6307 (or (= (car borders) (cdr borders)) ;; struct not yet closed...
6308 (and (> beg (car borders)) (< beg (cdr borders))))))))))
6309
6310 (defun idlwave-struct-borders ()
6311 "Return the borders of the {...} after point as a cons cell."
6312 (let (beg)
6313 (save-excursion
6314 (skip-chars-forward "^{")
6315 (setq beg (point))
6316 (condition-case nil (forward-list 1)
6317 (error (goto-char beg)))
6318 (cons beg (point)))))
6319
6320 (defun idlwave-find-structure-definition (&optional var name bound)
6321 "Search forward for a structure definition.
6322 If VAR is non-nil, search for a structure assigned to variable VAR.
6323 If NAME is non-nil, search for a named structure NAME. If BOUND is an
6324 integer, limit the search. If BOUND is the symbol `all', we search
6325 first back and then forward through the entire file. If BOUND is the
6326 symbol `back' we search only backward."
6327 (let* ((ws "[ \t]*\\(\\$.*\n[ \t]*\\)?")
6328 (case-fold-search t)
6329 (lim (if (integerp bound) bound nil))
6330 (re (concat
6331 (if var
6332 (concat "\\<" (regexp-quote (downcase var)) "\\>" ws)
6333 "\\(\\)")
6334 "=" ws "\\({\\)"
6335 (if name (concat ws "\\<" (downcase name) "[^a-zA-Z0-9_$]") ""))))
6336 (if (or (and (or (eq bound 'all) (eq bound 'back))
6337 (re-search-backward re nil t))
6338 (and (not (eq bound 'back)) (re-search-forward re lim t)))
6339 (goto-char (match-beginning 3)))))
6340
6341 (defvar idlwave-class-info nil)
6342 (defvar idlwave-system-class-info nil)
6343 (add-hook 'idlwave-update-rinfo-hook
6344 (lambda () (setq idlwave-class-info nil)))
6345 (add-hook 'idlwave-after-load-rinfo-hook
6346 (lambda () (setq idlwave-class-info nil)))
6347
6348 (defun idlwave-class-info (class)
6349 (let (list entry)
6350 (unless idlwave-class-info
6351 ;; Info is nil, put in the system stuff.
6352 (setq idlwave-class-info idlwave-system-class-info)
6353 (setq list idlwave-class-info)
6354 (while (setq entry (pop list))
6355 (idlwave-sintern-class-info entry)))
6356 (setq class (idlwave-sintern-class class))
6357 (setq entry (assq class idlwave-class-info))
6358 (unless entry
6359 (setq entry (idlwave-find-class-info class))
6360 (when entry
6361 ;; Sintern and cache the info
6362 (idlwave-sintern-class-info entry)
6363 (push entry idlwave-class-info)))
6364 entry))
6365
6366 (defun idlwave-sintern-class-info (entry)
6367 "Sintern the class names in a class-info entry."
6368 (let ((taglist (assq 'tags entry))
6369 (inherits (assq 'inherits entry)))
6370 (setcar entry (idlwave-sintern-class (car entry) 'set))
6371 (if inherits
6372 (setcdr inherits (mapcar (lambda (x) (idlwave-sintern-class x 'set))
6373 (cdr inherits))))))
6374
6375 (defun idlwave-find-class-info (class)
6376 "Find the __define procedure for a class structure and return info entry."
6377 (let* ((pro (concat (downcase class) "__define"))
6378 (class (idlwave-sintern-class class))
6379 (idlwave-auto-routine-info-updates nil)
6380 (file (cdr (nth 3 (idlwave-rinfo-assoc pro 'pro nil
6381 (idlwave-routines)))))
6382 buf)
6383 (if (or (not file)
6384 (not (file-regular-p
6385 (setq file (idlwave-expand-lib-file-name file)))))
6386 nil ; Cannot get info
6387 (save-excursion
6388 (if (setq buf (idlwave-get-buffer-visiting file))
6389 (set-buffer buf)
6390 (set-buffer (get-buffer-create " *IDLWAVE-tmp*"))
6391 (erase-buffer)
6392 (unless (eq major-mode 'idlwave-mode)
6393 (idlwave-mode))
6394 (insert-file-contents file))
6395 (save-excursion
6396 (goto-char 1)
6397 (setq case-fold-search t)
6398 (when (and (re-search-forward
6399 (concat "^[ \t]*pro[ \t]+" pro "\\>") nil t)
6400 ;; FIXME: should we limit to end of pro here?
6401 (idlwave-find-structure-definition nil class))
6402 (list class
6403 (cons 'tags (idlwave-struct-tags))
6404 (cons 'inherits (idlwave-struct-inherits)))))))))
6405
6406 (defun idlwave-class-tags (class)
6407 "Return the native tags in CLASS."
6408 (cdr (assq 'tags (idlwave-class-info class))))
6409 (defun idlwave-class-inherits (class)
6410 "Return the direct superclasses of CLASS."
6411 (cdr (assq 'inherits (idlwave-class-info class))))
6412
6413 (defun idlwave-all-class-tags (class)
6414 "Return a list of native and inherited tags in CLASS."
6415 (apply 'append (mapcar 'idlwave-class-tags
6416 (cons class (idlwave-all-class-inherits class)))))
6417
6418 (defun idlwave-all-class-inherits (class)
6419 "Return a list of all superclasses of CLASS (recursively expanded).
6420 The list is cached in `idlwave-class-info' for faster access."
6421 (cond
6422 ((not idlwave-support-inheritance) nil)
6423 ((eq class nil) nil)
6424 ((eq class t) nil)
6425 (t
6426 (let ((info (idlwave-class-info class))
6427 entry)
6428 (if (setq entry (assq 'all-inherits info))
6429 (cdr entry)
6430 (let ((inherits (idlwave-class-inherits class))
6431 rtn all-inherits cl)
6432 (while inherits
6433 (setq cl (pop inherits)
6434 rtn (cons cl rtn)
6435 inherits (append inherits (idlwave-class-inherits cl))))
6436 (setq all-inherits (nreverse rtn))
6437 (nconc info (list (cons 'all-inherits all-inherits)))
6438 all-inherits))))))
6439
6440
6441 ;;==========================================================================
6442 ;;
6443 ;; Completing class structure tags. This is a completion plugin.
6444 ;; The necessary taglist is constructed dynamically
6445
6446 (defvar idlwave-current-tags-class nil)
6447 (defvar idlwave-current-class-tags nil)
6448 (defvar idlwave-current-native-class-tags nil)
6449 (defvar idlwave-sint-classtags nil)
6450 (idlwave-new-sintern-type 'classtag)
6451 (add-to-list 'idlwave-complete-special 'idlwave-complete-class-structure-tag)
6452 (add-hook 'idlwave-update-rinfo-hook 'idlwave-classtag-reset)
6453
6454 (defun idlwave-complete-class-structure-tag ()
6455 "Complete a structure tag on a `self' argument in an object method."
6456 (interactive)
6457 (let ((pos (point))
6458 (case-fold-search t))
6459 (if (save-excursion
6460 ;; Check if the context is right
6461 (skip-chars-backward "[a-zA-Z0-9._$]")
6462 (and (< (point) (- pos 4))
6463 (looking-at "self\\.")))
6464 (let* ((class (nth 2 (idlwave-current-routine))))
6465 ;; Check if we are in a class routine
6466 (unless class
6467 (error "Not in a method procedure or function"))
6468 ;; Check if we need to update the "current" class
6469 (if (not (equal class idlwave-current-tags-class))
6470 (idlwave-prepare-class-tag-completion class))
6471 (setq idlwave-completion-help-info nil)
6472 (let ((idlwave-cpl-bold idlwave-current-native-class-tags))
6473 (idlwave-complete-in-buffer
6474 'classtag 'classtag
6475 idlwave-current-class-tags nil
6476 (format "Select a tag of class %s" class)
6477 "class tag"))
6478 t) ; return t to skip other completions
6479 nil)))
6480
6481 (defun idlwave-classtag-reset ()
6482 (setq idlwave-current-tags-class nil))
6483
6484 (defun idlwave-prepare-class-tag-completion (class)
6485 "Find and parse the necessary class definitions for class structure tags."
6486 (setq idlwave-sint-classtags nil)
6487 (setq idlwave-current-tags-class class)
6488 (setq idlwave-current-class-tags
6489 (mapcar (lambda (x)
6490 (list (idlwave-sintern-classtag x 'set)))
6491 (idlwave-all-class-tags class)))
6492 (setq idlwave-current-native-class-tags
6493 (mapcar 'downcase (idlwave-class-tags class))))
6494
6495 ;===========================================================================
6496 ;;
6497 ;; Completing system variables and their structure fields
6498 ;; This is also a plugin. It is a bit bigger since we support loading
6499 ;; current system variables from the shell and highlighting in the
6500 ;; completions buffer.
6501
6502 (defvar idlwave-sint-sysvars nil)
6503 (defvar idlwave-sint-sysvartags nil)
6504 (idlwave-new-sintern-type 'sysvar)
6505 (idlwave-new-sintern-type 'sysvartag)
6506 (add-to-list 'idlwave-complete-special 'idlwave-complete-sysvar-or-tag)
6507 (add-hook 'idlwave-update-rinfo-hook 'idlwave-sysvars-reset)
6508 (add-hook 'idlwave-after-load-rinfo-hook 'idlwave-remember-builtin-sysvars)
6509 (add-hook 'idlwave-after-load-rinfo-hook 'idlwave-sintern-sysvar-alist)
6510
6511 (defvar idlwave-system-variables-alist nil
6512 "Alist of system variables and the associated structure tags.
6513 Gets set in `idlw-rinfo.el'.")
6514 (defvar idlwave-builtin-system-variables nil)
6515
6516 (defun idlwave-complete-sysvar-or-tag ()
6517 "Complete a system variable."
6518 (interactive)
6519 (let ((pos (point))
6520 (case-fold-search t))
6521 (cond ((save-excursion
6522 ;; Check if the context is right for system variable
6523 (skip-chars-backward "[a-zA-Z0-9_$]")
6524 (equal (char-before) ?!))
6525 (setq idlwave-completion-help-info '(idlwave-complete-sysvar-help))
6526 (idlwave-complete-in-buffer 'sysvar 'sysvar
6527 idlwave-system-variables-alist nil
6528 "Select a system variable"
6529 "system variable")
6530 t) ; return t to skip other completions
6531 ((save-excursion
6532 ;; Check if the context is right for sysvar tag
6533 (skip-chars-backward "[a-zA-Z0-9_$.]")
6534 (and (equal (char-before) ?!)
6535 (looking-at "\\([a-zA-Z][a-zA-Z0-9_$]*\\)\\.")
6536 (<= (match-end 0) pos)))
6537 ;; Complete a system variable tag
6538 (let* ((var (idlwave-sintern-sysvar (match-string 1)))
6539 (entry (assq var idlwave-system-variables-alist))
6540 (tags (cdr entry)))
6541 (or entry (error "!%s is not know to be a system variable" var))
6542 (or tags (error "System variable !%s is not a structure" var))
6543 (setq idlwave-completion-help-info
6544 (list 'idlwave-complete-sysvar-help var))
6545 (idlwave-complete-in-buffer 'sysvartag 'sysvartag
6546 tags nil
6547 "Select a system variable tag"
6548 "system variable tag")
6549 t)) ; return t to skip other completions
6550 (t nil))))
6551
6552 (defvar name)
6553 (defvar kwd)
6554 (defun idlwave-complete-sysvar-help (mode word)
6555 (cond
6556 ((eq mode 'test)
6557 (or (and (eq nil (nth 1 idlwave-completion-help-info))
6558 (member (downcase word) idlwave-builtin-system-variables))
6559 (and (stringp (nth 1 idlwave-completion-help-info))
6560 (member (downcase (nth 1 idlwave-completion-help-info))
6561 idlwave-builtin-system-variables))))
6562 ((eq mode 'set)
6563 (setq name "system variables"
6564 kwd (concat "!"
6565 (if (stringp (nth 1 idlwave-completion-help-info))
6566 (nth 1 idlwave-completion-help-info)
6567 word))))
6568 (t (error "This should not happen"))))
6569
6570
6571 (defun idlwave-sysvars-reset ()
6572 (if (and (fboundp 'idlwave-shell-is-running)
6573 (idlwave-shell-is-running))
6574 (idlwave-shell-send-command "idlwave_get_sysvars"
6575 'idlwave-process-sysvars 'hide)))
6576
6577 (defun idlwave-process-sysvars ()
6578 (idlwave-shell-filter-sysvars)
6579 (setq idlwave-sint-sysvars nil
6580 idlwave-sint-sysvartags nil)
6581 (idlwave-sintern-sysvar-alist))
6582
6583 (defun idlwave-remember-builtin-sysvars ()
6584 (setq idlwave-builtin-system-variables
6585 (mapcar 'downcase
6586 (mapcar 'car idlwave-system-variables-alist))))
6587
6588 (defun idlwave-sintern-sysvar-alist ()
6589 (let ((list idlwave-system-variables-alist) entry)
6590 (while (setq entry (pop list))
6591 (setcar entry (idlwave-sintern-sysvar (car entry) 'set))
6592 (setcdr entry (mapcar (lambda (x)
6593 (list (idlwave-sintern-sysvartag (car x) 'set)))
6594 (cdr entry))))))
6595
6596 (defvar idlwave-shell-command-output)
6597 (defun idlwave-shell-filter-sysvars ()
6598 "Get the system variables and structure tags."
6599 (let ((text idlwave-shell-command-output)
6600 (start 0)
6601 (old idlwave-system-variables-alist)
6602 var tags type name class)
6603 (setq idlwave-system-variables-alist nil)
6604 (while (string-match "^IDLWAVE-SYSVAR: !\\([a-zA-Z0-9_$]+\\)\\( \\(.*\\)\\)?"
6605 text start)
6606 (setq start (match-end 0)
6607 var (match-string 1 text)
6608 tags (if (match-end 3) (idlwave-split-string (match-string 3 text))))
6609 (setq idlwave-system-variables-alist
6610 (cons (cons var (mapcar 'list tags))
6611 idlwave-system-variables-alist)))
6612 ;; Keep the old value if query was not successful
6613 (setq idlwave-system-variables-alist
6614 (or idlwave-system-variables-alist old))))
6615
6616 (defun idlwave-completion-fontify-classes ()
6617 "Goto the *Completions* buffer and fontify the class info."
6618 (when (featurep 'font-lock)
6619 (save-excursion
6620 (set-buffer "*Completions*")
6621 (save-excursion
6622 (goto-char (point-min))
6623 (while (re-search-forward "\\.*<[^>]+>" nil t)
6624 (put-text-property (match-beginning 0) (match-end 0)
6625 'face 'font-lock-string-face))))))
6626
6627 (defun idlwave-uniquify (list)
6628 (let (nlist)
6629 (loop for x in list do
6630 (add-to-list 'nlist x))
6631 nlist))
6632
6633 (defun idlwave-after-successful-completion (type slash &optional verify)
6634 "Add `=' or `(' after successful completion of keyword and function.
6635 Restore the pre-completion window configuration if possible."
6636 (cond
6637 ((eq type 'procedure)
6638 nil)
6639 ((eq type 'function)
6640 (cond
6641 ((equal idlwave-function-completion-adds-paren nil) nil)
6642 ((or (equal idlwave-function-completion-adds-paren t)
6643 (equal idlwave-function-completion-adds-paren 1))
6644 (insert "("))
6645 ((equal idlwave-function-completion-adds-paren 2)
6646 (insert "()")
6647 (backward-char 1))
6648 (t nil)))
6649 ((eq type 'keyword)
6650 (if (and idlwave-keyword-completion-adds-equal
6651 (not slash))
6652 (progn (insert "=") t)
6653 nil)))
6654
6655 ;; Restore the pre-completion window configuration if this is safe.
6656
6657 (if (or (eq verify 'force) ; force
6658 (and
6659 (get-buffer-window "*Completions*") ; visible
6660 (idlwave-local-value 'idlwave-completion-p
6661 "*Completions*") ; cib-buffer
6662 (eq (marker-buffer idlwave-completion-mark)
6663 (current-buffer)) ; buffer OK
6664 (equal (marker-position idlwave-completion-mark)
6665 verify))) ; pos OK
6666 (idlwave-restore-wconf-after-completion))
6667 (move-marker idlwave-completion-mark nil)
6668 (setq idlwave-before-completion-wconf nil))
6669
6670 (defun idlwave-mouse-context-help (ev &optional arg)
6671 "Call `idlwave-context-help' on the clicked location."
6672 (interactive "eP")
6673 (mouse-set-point ev)
6674 (idlwave-context-help arg))
6675
6676 (defvar idlwave-last-context-help-pos nil)
6677 (defun idlwave-context-help (&optional arg)
6678 "Display IDL Online Help on context.
6679 If point is on a keyword, help for that keyword will be shown.
6680 If point is on a routine name or in the argument list of a routine,
6681 help for that routine will be displayed.
6682 Works for system routines and keywords only."
6683 (interactive "P")
6684 (idlwave-require-online-help)
6685 (idlwave-do-context-help arg))
6686
6687 (defun idlwave-mouse-completion-help (ev)
6688 "Display online help about the completion at point."
6689 (interactive "eP")
6690 (idlwave-require-online-help)
6691 ;; Restore last-command for next command, to make scrolling of completions
6692 ;; work.
6693 (setq this-command last-command)
6694 (idlwave-do-mouse-completion-help ev))
6695
6696 (defvar idlwave-help-is-loaded nil
6697 "Is online help avaiable?")
6698 ;; The following variables will be defined by `idlw-help.el'.
6699 (defvar idlwave-help-frame-width nil)
6700 (defvar idlwave-help-file nil)
6701 (defvar idlwave-help-topics nil)
6702
6703 (defun idlwave-help-directory ()
6704 "Return the help directory, or nil if that is not known."
6705 (or (and (stringp idlwave-help-directory)
6706 (> (length idlwave-help-directory) 0)
6707 idlwave-help-directory)
6708 (getenv "IDLWAVE_HELP_DIRECTORY")))
6709
6710 (defun idlwave-require-online-help ()
6711 (if idlwave-help-is-loaded
6712 t ;; everything is OK.
6713 (let* ((dir (or (idlwave-help-directory)
6714 (error "Online Help is not installed (idlwave-help-directory is unknown)")))
6715 (lfile1 (expand-file-name "idlw-help.elc" dir))
6716 (lfile2 (expand-file-name "idlw-help.el" dir))
6717 (hfile (expand-file-name "idlw-help.txt" dir)))
6718 (if (or (and (file-regular-p lfile1) (load-file lfile1))
6719 (and (file-regular-p lfile2) (load-file lfile2)))
6720 (progn
6721 (if (and idlwave-help-frame-parameters
6722 (not (assoc 'width idlwave-help-frame-parameters)))
6723 (push (cons 'width idlwave-help-frame-width)
6724 idlwave-help-frame-parameters))
6725 (or idlwave-help-topics
6726 (error "File `%s' in help dir `%s' does not define `idlwave-help-topics'"
6727 "idlw-help.el" dir)))
6728 (error "No such file `%s' in help dir `%s'" "idlw-help.el" dir))
6729 (if (file-regular-p hfile)
6730 (setq idlwave-help-is-loaded t
6731 idlwave-help-file hfile)
6732 (error "No such file `%s' in dir `%s'" "idlw-help.txt" dir)))))
6733
6734 (defun idlwave-routine-info (&optional arg external)
6735 "Display a routines calling sequence and list of keywords.
6736 When point is on the name a function or procedure, or in the argument
6737 list of a function or procedure, this command displays a help buffer
6738 with the information. When called with prefix arg, enforce class
6739 query.
6740
6741 When point is on an object operator `->', display the class stored in
6742 this arrow, if any (see `idlwave-store-inquired-class'). With a
6743 prefix arg, the class property is cleared out."
6744
6745 (interactive "P")
6746 (idlwave-routines)
6747 (if (string-match "->" (buffer-substring
6748 (max (point-min) (1- (point)))
6749 (min (+ 2 (point)) (point-max))))
6750 ;; Cursor is on an arrow
6751 (if (get-text-property (point) 'idlwave-class)
6752 ;; arrow has class property
6753 (if arg
6754 ;; Remove property
6755 (save-excursion
6756 (backward-char 1)
6757 (when (looking-at ".?\\(->\\)")
6758 (remove-text-properties (match-beginning 1) (match-end 1)
6759 '(idlwave-class nil face nil))
6760 (message "Class property removed from arrow")))
6761 ;; Echo class property
6762 (message "Arrow has text property identifying object to be class %s"
6763 (get-text-property (point) 'idlwave-class)))
6764 ;; No property found
6765 (message "Arrow has no class text property"))
6766
6767 ;; Not on an arrow...
6768 (let* ((idlwave-query-class nil)
6769 (idlwave-force-class-query (equal arg '(4)))
6770 (module (idlwave-what-module)))
6771 (if (car module)
6772 (apply 'idlwave-display-calling-sequence
6773 (idlwave-fix-module-if-obj_new module))
6774 (error "Don't know which calling sequence to show")))))
6775
6776 (defun idlwave-resolve (&optional arg)
6777 "Call RESOLVE on the module name at point.
6778 Like `idlwave-routine-info', this looks for a routine call at point.
6779 After confirmation in the minibuffer, it will use the shell to issue
6780 a RESOLVE call for this routine, to attempt to make it defined and its
6781 routine info available for IDLWAVE. If the routine is a method call,
6782 both `class__method' and `class__define' will be tried.
6783 With ARG, enforce query for the class of object methods."
6784 (interactive "P")
6785 (let* ((idlwave-query-class nil)
6786 (idlwave-force-class-query (equal arg '(4)))
6787 (module (idlwave-what-module))
6788 (name (idlwave-make-full-name (nth 2 module) (car module)))
6789 (type (if (eq (nth 1 module) 'pro) "pro" "function"))
6790 (resolve (read-string "Resolve: " (format "%s %s" type name)))
6791 (kwd "")
6792 class)
6793 (if (string-match "\\(pro\\|function\\)[ \t]+\\(\\(.*\\)::\\)?\\(.*\\)"
6794 resolve)
6795 (setq type (match-string 1 resolve)
6796 class (if (match-beginning 2)
6797 (match-string 3 resolve)
6798 nil)
6799 name (match-string 4 resolve)))
6800 (if (string= (downcase type) "function")
6801 (setq kwd ",/is_function"))
6802
6803 (cond
6804 ((null class)
6805 (idlwave-shell-send-command
6806 (format "resolve_routine,'%s'%s" (downcase name) kwd)
6807 'idlwave-update-routine-info
6808 nil t))
6809 (t
6810 (idlwave-shell-send-command
6811 (format "resolve_routine,'%s__define'%s" (downcase class) kwd)
6812 (list 'idlwave-shell-send-command
6813 (format "resolve_routine,'%s__%s'%s"
6814 (downcase class) (downcase name) kwd)
6815 '(idlwave-update-routine-info)
6816 nil t))))))
6817
6818 (defun idlwave-find-module (&optional arg)
6819 "Find the source code of an IDL module.
6820 Works for modules for which IDLWAVE has routine info available.
6821 The function offers as default the module name `idlwave-routine-info' would
6822 use. With ARG force class query for object methods."
6823 (interactive "P")
6824 (let* ((idlwave-query-class nil)
6825 (idlwave-force-class-query (equal arg '(4)))
6826 (module (idlwave-fix-module-if-obj_new (idlwave-what-module)))
6827 (default (concat (idlwave-make-full-name (nth 2 module) (car module))
6828 (if (eq (nth 1 module) 'pro) "<p>" "<f>")))
6829 (list
6830 (delq nil
6831 (mapcar (lambda (x)
6832 (if (eq 'system (car-safe (nth 3 x)))
6833 ;; Take out system routines with no source.
6834 nil
6835 (cons
6836 (concat (idlwave-make-full-name (nth 2 x) (car x))
6837 (if (eq (nth 1 x) 'pro) "<p>" "<f>"))
6838 (cdr x))))
6839 (idlwave-routines))))
6840 (name (idlwave-completing-read
6841 (format "Module (Default %s): "
6842 (if default default "none"))
6843 list))
6844 type class)
6845 (if (string-match "\\`\\s-*\\'" name)
6846 ;; Nothing, use the default.
6847 (setq name default))
6848 (if (string-match "<[fp]>" name)
6849 (setq type (substring name -2 -1)
6850 name (substring name 0 -3)))
6851 (if (string-match "\\(.*\\)::\\(.*\\)" name)
6852 (setq class (match-string 1 name)
6853 name (match-string 2 name)))
6854 (setq name (idlwave-sintern-routine-or-method name class)
6855 class (idlwave-sintern-class class)
6856 type (cond ((equal type "f") 'fun)
6857 ((equal type "p") 'pro)
6858 (t t)))
6859 (idlwave-do-find-module name type class)))
6860
6861 (defun idlwave-do-find-module (name type class &optional force-source)
6862 (let ((name1 (idlwave-make-full-name class name))
6863 source buf1 entry
6864 (buf (current-buffer))
6865 (pos (point))
6866 name2)
6867 (setq entry (idlwave-best-rinfo-assq name type class (idlwave-routines))
6868 source (or force-source (nth 3 entry))
6869 name2 (if (nth 2 entry)
6870 (idlwave-make-full-name (nth 2 entry) name)
6871 name1))
6872 (cond
6873 ((or (null name) (equal name ""))
6874 (error "Abort"))
6875 ((null entry)
6876 (error "Nothing known about a module %s" name2))
6877 ((eq (car source) 'system)
6878 (error "Source code for system routine %s is not available"
6879 name2))
6880 ((equal (cdr source) "")
6881 (error "Source code for routine %s is not available"
6882 name2))
6883 ((memq (car source) '(buffer lib compiled))
6884 (setq buf1
6885 (if (eq (car source) 'lib)
6886 (idlwave-find-file-noselect
6887 (idlwave-expand-lib-file-name
6888 (or (cdr source)
6889 (format "%s.pro" (downcase name)))) 'find)
6890 (idlwave-find-file-noselect (cdr source) 'find)))
6891 (pop-to-buffer buf1 t)
6892 (goto-char (point-max))
6893 (let ((case-fold-search t))
6894 (if (re-search-backward
6895 (concat "^[ \t]*\\<"
6896 (cond ((equal type "f") "function")
6897 ((equal type "p") "pro")
6898 (t "\\(pro\\|function\\)"))
6899 "\\>[ \t]+"
6900 (regexp-quote (downcase name2))
6901 "[^a-zA-Z0-9_$]")
6902 nil t)
6903 (goto-char (match-beginning 0))
6904 (pop-to-buffer buf)
6905 (goto-char pos)
6906 (error "Could not find routine %s" name2)))))))
6907
6908 (defun idlwave-what-module ()
6909 "Return a default module for stuff near point.
6910 Used by `idlwave-routine-info' and `idlwave-find-module'."
6911 (idlwave-routines)
6912 (if (let ((case-fold-search t))
6913 (save-excursion
6914 (idlwave-beginning-of-statement)
6915 (looking-at "[ \t]*\\(pro\\|function\\)[ \t]+\\(\\([a-zA-Z0-9_$]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)\\([, \t\n]\\|$\\)")))
6916 ;; This is a function or procedure definition statement
6917 ;; We return the defined routine as module.
6918 (list
6919 (idlwave-sintern-routine-or-method (match-string 4)
6920 (match-string 2))
6921 (if (equal (downcase (match-string 1)) "pro") 'pro 'fun)
6922 (idlwave-sintern-class (match-string 3)))
6923
6924 ;; Not a definition statement - analyze precise positon.
6925 (let* ((where (idlwave-where))
6926 (cw (nth 2 where))
6927 (pro (car (nth 0 where)))
6928 (func (car (nth 1 where)))
6929 (this-word (idlwave-this-word "a-zA-Z0-9$_"))
6930 (next-char (save-excursion (skip-chars-forward "a-zA-Z0-9$_")
6931 (following-char)))
6932 )
6933 (cond
6934 ((and (eq cw 'procedure)
6935 (not (equal this-word "")))
6936 (setq this-word (idlwave-sintern-routine-or-method
6937 this-word (nth 2 (nth 3 where))))
6938 (list this-word 'pro
6939 (idlwave-determine-class
6940 (cons this-word (cdr (nth 3 where)))
6941 'pro)))
6942 ((and (eq cw 'function)
6943 (not (equal this-word ""))
6944 (or (eq next-char ?\() ; exclude arrays, vars.
6945 (looking-at "[a-zA-Z0-9_]*[ \t]*(")))
6946 (setq this-word (idlwave-sintern-routine-or-method
6947 this-word (nth 2 (nth 3 where))))
6948 (list this-word 'fun
6949 (idlwave-determine-class
6950 (cons this-word (cdr (nth 3 where)))
6951 'fun)))
6952 ((and (memq cw '(function-keyword procedure-keyword))
6953 (not (equal this-word ""))
6954 (eq next-char ?\()) ; A function!
6955 (setq this-word (idlwave-sintern-routine this-word))
6956 (list this-word 'fun nil))
6957 (func
6958 (list func 'fun (idlwave-determine-class (nth 1 where) 'fun)))
6959 (pro
6960 (list pro 'pro (idlwave-determine-class (nth 0 where) 'pro)))
6961 (t nil)))))
6962
6963 (defun idlwave-what-module-find-class ()
6964 "Call idlwave-what-module and find the inherited class if necessary."
6965 (let* ((module (idlwave-what-module))
6966 (class (nth 2 module))
6967 classes)
6968 (if (and (= (length module) 3)
6969 (stringp class))
6970 (list (car module)
6971 (nth 1 module)
6972 (apply 'idlwave-find-inherited-class module))
6973 module)))
6974
6975 (defun idlwave-find-inherited-class (name type class)
6976 "Find the class which defines TYPE NAME and is CLASS or inherited by CLASS."
6977 (let ((entry (idlwave-best-rinfo-assoc name type class (idlwave-routines))))
6978 (if entry
6979 (nth 2 entry)
6980 class)))
6981
6982 (defun idlwave-fix-module-if-obj_new (module)
6983 "Check if MODULE points to obj_new. If yes, and if the cursor is in the
6984 keyword region, change to the appropriate Init method."
6985 (let* ((name (car module))
6986 (pos (point))
6987 (case-fold-search t)
6988 string)
6989 (if (and (stringp name)
6990 (equal (downcase name) "obj_new")
6991 (save-excursion
6992 (idlwave-beginning-of-statement)
6993 (setq string (buffer-substring (point) pos))
6994 (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
6995 string)))
6996 (let ((name "Init")
6997 (class (match-string 1 string)))
6998 (setq module (list (idlwave-sintern-method "Init")
6999 'fun
7000 (idlwave-sintern-class class)))))
7001 module))
7002
7003
7004 (defun idlwave-fix-keywords (name type class keywords)
7005 ;; This fixes the list of keywords.
7006 (let ((case-fold-search t))
7007
7008 ;; If this is the OBJ_NEW function, try to figure out the class and use
7009 ;; the keywords from the corresponding INIT method.
7010 (if (and (equal (upcase name) "OBJ_NEW")
7011 (or (eq major-mode 'idlwave-mode)
7012 (eq major-mode 'idlwave-shell-mode)))
7013 (let* ((bos (save-excursion (idlwave-beginning-of-statement) (point)))
7014 (string (buffer-substring bos (point)))
7015 (case-fold-search t)
7016 class)
7017 (and (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
7018 string)
7019 (setq class (idlwave-sintern-class (match-string 1 string)))
7020 (setq idlwave-current-obj_new-class class)
7021 (setq keywords
7022 (append keywords
7023 (nth 5 (idlwave-rinfo-assq
7024 (idlwave-sintern-method "INIT")
7025 'fun
7026 class
7027 (idlwave-routines))))))))
7028
7029 ;; If the class is `t', combine all keywords of all methods NAME
7030 (when (eq class t)
7031 (loop for x in (idlwave-routines) do
7032 (and (nth 2 x) ; non-nil class
7033 (eq (nth 1 x) type) ; correct type
7034 (eq (car x) name) ; correct name
7035 (mapcar (lambda (k) (add-to-list 'keywords k))
7036 (nth 5 x))))
7037 (setq keywords (idlwave-uniquify keywords)))
7038
7039 ;; If we have inheritance, add all keywords from superclasses, if
7040 ;; the user indicated that method in
7041 ;; `idlwave-keyword-class-inheritance'
7042 (when (and
7043 idlwave-keyword-class-inheritance
7044 (stringp class)
7045 (or (assq (idlwave-sintern-keyword "_extra") keywords)
7046 (assq (idlwave-sintern-keyword "_ref_extra") keywords))
7047 (boundp 'super-classes)
7048 ;; Check if one of the keyword-class regexps matches the name
7049 (let ((regexps idlwave-keyword-class-inheritance) re)
7050 (catch 'exit
7051 (while (setq re (pop regexps))
7052 (if (string-match re name) (throw 'exit t))))))
7053 (loop for x in (idlwave-routines) do
7054 (and (nth 2 x) ; non-nil class
7055 (or (eq (nth 2 x) class) ; the right class
7056 (memq (nth 2 x) super-classes)) ; an inherited class
7057 (eq (nth 1 x) type) ; correct type
7058 (eq (car x) name) ; correct name
7059 (mapcar (lambda (k) (add-to-list 'keywords k))
7060 (nth 5 x))))
7061 (setq keywords (idlwave-uniquify keywords)))
7062
7063 ;; Return the final list
7064 keywords))
7065
7066 (defun idlwave-expand-keyword (keyword module)
7067 "Expand KEYWORD to one of the legal keyword parameters of MODULE.
7068 KEYWORD may be an exact match or an abbreviation of a keyword.
7069 If the match is exact, KEYWORD itself is returned, even if there may be other
7070 keywords of which KEYWORD is an abbreviation. This is necessary because some
7071 system routines have keywords which are prefixes of other keywords.
7072 If KEYWORD is an abbreviation of several keywords, a list of all possible
7073 completions is returned.
7074 If the abbreviation was unique, the correct keyword is returned.
7075 If it cannot be a keyword, the function return nil.
7076 If we do not know about MODULE, just return KEYWORD literally."
7077 (let* ((name (car module))
7078 (type (nth 1 module))
7079 (class (nth 2 module))
7080 (kwd (idlwave-sintern-keyword keyword))
7081 (entry (idlwave-best-rinfo-assoc name type class (idlwave-routines)))
7082 (kwd-alist (nth 5 entry))
7083 (extra (or (assq (idlwave-sintern-keyword "_EXTRA") kwd-alist)
7084 (assq (idlwave-sintern-keyword "_REF_EXTRA") kwd-alist)))
7085 (completion-ignore-case t)
7086 candidates)
7087 (cond ((assq kwd kwd-alist)
7088 kwd)
7089 ((setq candidates (all-completions kwd kwd-alist))
7090 (if (= (length candidates) 1)
7091 (car candidates)
7092 candidates))
7093 ((and entry extra)
7094 ;; Inheritance may cause this keyword to be correct
7095 keyword)
7096 (entry
7097 ;; We do know the function, which does not have the keyword.
7098 nil)
7099 (t
7100 ;; We do not know the function, so this just might be a correct
7101 ;; keyword - return it as it is.
7102 keyword))))
7103
7104 (defvar idlwave-rinfo-mouse-map (make-sparse-keymap))
7105 (defvar idlwave-rinfo-map (make-sparse-keymap))
7106 (define-key idlwave-rinfo-mouse-map
7107 (if (featurep 'xemacs) [button2] [mouse-2])
7108 'idlwave-mouse-active-rinfo)
7109 (define-key idlwave-rinfo-mouse-map
7110 (if (featurep 'xemacs) [(shift button2)] [(shift mouse-2)])
7111 'idlwave-mouse-active-rinfo-shift)
7112 (define-key idlwave-rinfo-mouse-map
7113 (if (featurep 'xemacs) [button3] [mouse-3])
7114 'idlwave-mouse-active-rinfo-right)
7115 (define-key idlwave-rinfo-mouse-map " " 'idlwave-active-rinfo-space)
7116 (define-key idlwave-rinfo-map "q" 'idlwave-quit-help)
7117 (define-key idlwave-rinfo-mouse-map "q" 'idlwave-quit-help)
7118 (defvar idlwave-popup-source nil)
7119 (defvar idlwave-rinfo-marker (make-marker))
7120
7121 (defun idlwave-quit-help ()
7122 (interactive)
7123 (let ((ri-window (get-buffer-window "*Help*"))
7124 (olh-window (get-buffer-window "*IDLWAVE Help*")))
7125 (when (and olh-window
7126 (fboundp 'idlwave-help-quit))
7127 (select-window olh-window)
7128 (idlwave-help-quit))
7129 (when (window-live-p ri-window)
7130 (delete-window ri-window))))
7131
7132 (defun idlwave-display-calling-sequence (name type class
7133 &optional initial-class)
7134 ;; Display the calling sequence of module NAME, type TYPE in class CLASS.
7135 (let* ((initial-class (or initial-class class))
7136 (entry (or (idlwave-best-rinfo-assq name type class
7137 (idlwave-routines))
7138 (idlwave-rinfo-assq name type class
7139 idlwave-unresolved-routines)))
7140 (name (or (car entry) name))
7141 (class (or (nth 2 entry) class))
7142 (superclasses (idlwave-all-class-inherits initial-class))
7143 (twins (idlwave-routine-twins entry))
7144 (dtwins (idlwave-study-twins twins))
7145 (all dtwins)
7146 (system (idlwave-rinfo-assq
7147 name type class idlwave-system-routines))
7148 (have-sysdoc (and system (idlwave-help-directory)))
7149 ;; (source (nth 3 entry))
7150 (have-olh (and (or system idlwave-extra-help-function)
7151 (idlwave-help-directory)))
7152 (calling-seq (nth 4 entry))
7153 (keywords (nth 5 entry))
7154 (olh (nth 6 entry))
7155 (help-echo-kwd
7156 (if have-olh
7157 "Button2: Insert KEYWORD (SHIFT=`/KEYWORD') Button3: Online Help "
7158 "Button2: Insert KEYWORD (SHIFT=`/KEYWORD')."))
7159 (help-echo-use
7160 (if have-olh
7161 "Button2/3: Online Help"
7162 nil))
7163 (help-echo-src
7164 (if (idlwave-help-directory)
7165 "Button2: Pop to source and back. Button3: Source in Help window."
7166 "Button2: Pop to source and back."))
7167 (help-echo-class
7168 "Button2: Display info about same method in superclass")
7169 (col 0)
7170 (data (list name type class (current-buffer) olh initial-class))
7171 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
7172 (face 'idlwave-help-link-face)
7173 beg props win cnt total)
7174 (setq keywords (idlwave-fix-keywords name type class keywords))
7175 (cond
7176 ((null entry)
7177 (error "No %s %s known %s" type name
7178 (if initial-class (concat "in class " initial-class) "")))
7179 ((or (null name) (equal name ""))
7180 (error "No function or procedure call at point"))
7181 ((null calling-seq)
7182 (error "Calling sequence of %s %s is not available" type name))
7183 (t
7184 (save-excursion
7185 (move-marker idlwave-rinfo-marker (point))
7186 (set-buffer (get-buffer-create "*Help*"))
7187 (use-local-map idlwave-rinfo-map)
7188 (setq buffer-read-only nil)
7189 (erase-buffer)
7190 (set (make-local-variable 'idlwave-popup-source) nil)
7191 (set (make-local-variable 'idlwave-current-obj_new-class)
7192 idlwave-current-obj_new-class)
7193 (when superclasses
7194 (setq props (list 'mouse-face 'highlight
7195 km-prop idlwave-rinfo-mouse-map
7196 'help-echo help-echo-class
7197 'data (cons 'class data)))
7198 (let ((classes (cons initial-class superclasses)) c)
7199 (insert "Classes: ")
7200 (while (setq c (pop classes))
7201 (insert " ")
7202 (setq beg (point))
7203 (insert c)
7204 (if (equal (downcase c) (downcase class))
7205 (add-text-properties beg (point) (list 'face 'bold))
7206 (if (idlwave-rinfo-assq name type c (idlwave-routines))
7207 (add-text-properties beg (point) props))))
7208 (insert "\n")))
7209 (setq props (if have-olh
7210 (list 'mouse-face 'highlight
7211 km-prop idlwave-rinfo-mouse-map
7212 'help-echo help-echo-use
7213 'data (cons 'usage data))))
7214 (if have-sysdoc (setq props (append (list 'face face) props)))
7215 (insert "Usage: ")
7216 (setq beg (point))
7217 (insert (if class
7218 (format calling-seq class name)
7219 (format calling-seq name))
7220 "\n")
7221 (add-text-properties beg (point) props)
7222
7223 (insert "Keywords:")
7224 (if (null keywords)
7225 (insert " No keywords accepted.")
7226 (setq col 9)
7227 (mapcar
7228 (lambda (x)
7229 (if (>= (+ col 1 (length (car x)))
7230 (window-width))
7231 (progn
7232 (insert "\n ")
7233 (setq col 9)))
7234 (insert " ")
7235 (setq beg (point)
7236 props (list 'mouse-face 'highlight
7237 km-prop idlwave-rinfo-mouse-map
7238 'data (cons 'keyword data)
7239 'help-echo help-echo-kwd
7240 'keyword (car x)))
7241 (if have-sysdoc (setq props (append (list 'face face) props)))
7242 (insert (car x))
7243 (add-text-properties beg (point) props)
7244 (setq col (+ col 1 (length (car x)))))
7245 keywords))
7246
7247 (setq cnt 1 total (length all))
7248 (while (setq entry (pop all))
7249 (setq props (list 'mouse-face 'highlight
7250 km-prop idlwave-rinfo-mouse-map
7251 'help-echo help-echo-src
7252 'source (cons (car (nth 2 entry)) (nth 1 entry))
7253 'data (cons 'source data)))
7254 (idlwave-insert-source-location
7255 (format "\n%-8s %s"
7256 (if (equal cnt 1)
7257 (if (> total 1) "Sources:" "Source:")
7258 "")
7259 (if (> total 1) "- " ""))
7260 entry props)
7261 (incf cnt)
7262 (when (and all (> cnt idlwave-rinfo-max-source-lines))
7263 ;; No more source lines, please
7264 (insert (format
7265 "\n Source information truncated to %d entries."
7266 idlwave-rinfo-max-source-lines))
7267 (setq all nil)))
7268
7269 (setq buffer-read-only t))
7270 (display-buffer "*Help*")
7271 (if (and (setq win (get-buffer-window "*Help*"))
7272 idlwave-resize-routine-help-window)
7273 (progn
7274 (let ((ww (selected-window)))
7275 (unwind-protect
7276 (progn
7277 (select-window win)
7278 (enlarge-window (- (/ (frame-height) 2)
7279 (window-height)))
7280 (shrink-window-if-larger-than-buffer))
7281 (select-window ww)))))))))
7282
7283 (defun idlwave-insert-source-location (prefix entry &optional file-props)
7284 "Insert a source location into the routine info buffer.
7285 Start line with PREFIX.
7286 If a file name is inserted, add FILE-PROPS to it."
7287
7288 (let* ((key (car entry))
7289 (file (nth 1 entry))
7290 (types (nth 2 entry))
7291 (shell-flag (member 'compiled types))
7292 (buffer-flag (member 'buffer types))
7293 (lib-flag (member 'lib types))
7294 (ndupl (or (and buffer-flag (idlwave-count-eq 'buffer types))
7295 (and lib-flag (idlwave-count-eq 'lib types))
7296 1))
7297 (doflags t)
7298 beg special)
7299
7300 (insert prefix)
7301
7302 (cond
7303 ((eq key 'system)
7304 (setq doflags nil)
7305 (insert "System "))
7306 ((eq key 'builtin)
7307 (setq doflags nil)
7308 (insert "Builtin "))
7309 ((and (not file) shell-flag)
7310 (insert "Unresolved"))
7311 ((null file) (insert "ERROR"))
7312 ((setq special (idlwave-special-lib-test file))
7313 (insert (format "%-10s" special)))
7314 ((idlwave-syslib-p file)
7315 (if (string-match "obsolete" (file-name-directory file))
7316 (insert "Obsolete ")
7317 (insert "SystemLib ")))
7318 ((idlwave-lib-p file) (insert "Library "))
7319 (t (insert "Other ")))
7320
7321 (when doflags
7322 (insert (concat
7323 " ["
7324 (if lib-flag "C" "-")
7325 (if shell-flag "S" "-")
7326 (if buffer-flag "B" "-")
7327 "] ")))
7328 (when (> ndupl 1)
7329 (setq beg (point))
7330 (insert (format "(%dx) " ndupl))
7331 (add-text-properties beg (point) (list 'face 'bold)))
7332 (when (and file (not (equal file "")))
7333 (setq beg (point))
7334 (insert (apply 'abbreviate-file-name
7335 (if (featurep 'xemacs) (list file t) (list file))))
7336 (if file-props
7337 (add-text-properties beg (point) file-props)))))
7338
7339 (defun idlwave-special-lib-test (file)
7340 "Check the path of FILE against the regexps which define special libs.
7341 Return the name of the special lib if there is a match."
7342 (let ((alist idlwave-special-lib-alist)
7343 entry rtn)
7344 (cond
7345 ((stringp file)
7346 (while (setq entry (pop alist))
7347 (if (string-match (car entry) file)
7348 (setq rtn (cdr entry)
7349 alist nil)))
7350 rtn)
7351 (t nil))))
7352
7353 (defun idlwave-mouse-active-rinfo-right (ev)
7354 (interactive "e")
7355 (idlwave-mouse-active-rinfo ev 'right))
7356
7357 (defun idlwave-mouse-active-rinfo-shift (ev)
7358 (interactive "e")
7359 (idlwave-mouse-active-rinfo ev nil 'shift))
7360
7361 (defun idlwave-active-rinfo-space ()
7362 (interactive)
7363 (idlwave-mouse-active-rinfo nil 'right))
7364
7365 (defun idlwave-mouse-active-rinfo (ev &optional right shift)
7366 "Does the mouse actions in the routine info buffer.
7367 Optional args RIGHT and SHIFT indicate, if mouse-3 was used, and if SHIFT
7368 was pressed."
7369 (interactive "e")
7370 (if ev (mouse-set-point ev))
7371 (let (data id name type class buf keyword bufwin source word initial-class)
7372 (setq data (get-text-property (point) 'data)
7373 source (get-text-property (point) 'source)
7374 keyword (get-text-property (point) 'keyword)
7375 id (car data)
7376 name (nth 1 data) type (nth 2 data) class (nth 3 data)
7377 buf (nth 4 data)
7378 initial-class (nth 6 data)
7379 word (idlwave-this-word)
7380 bufwin (get-buffer-window buf t))
7381 (cond ((eq id 'class)
7382 (if (window-live-p bufwin) (select-window bufwin))
7383 (idlwave-display-calling-sequence
7384 (idlwave-sintern-method name)
7385 type (idlwave-sintern-class word)
7386 initial-class))
7387 ((eq id 'usage)
7388 (idlwave-require-online-help)
7389 (idlwave-online-help nil name type class))
7390 ((eq id 'source)
7391 (if (and right (idlwave-help-directory))
7392 (let ((idlwave-extra-help-function 'idlwave-help-with-source)
7393 (idlwave-help-source-try-header nil)
7394 ;; Fake idlwave-routines, to make help find the right entry
7395 (idlwave-routines
7396 (list (list (nth 1 data) (nth 2 data) (nth 3 data) source ""))))
7397 (idlwave-require-online-help)
7398 (idlwave-help-get-special-help name type class nil))
7399 (setq idlwave-popup-source (not idlwave-popup-source))
7400 (if idlwave-popup-source
7401 (condition-case err
7402 (idlwave-do-find-module name type class source)
7403 (error
7404 (setq idlwave-popup-source nil)
7405 (if (window-live-p bufwin) (select-window bufwin))
7406 (error (nth 1 err))))
7407 (if bufwin
7408 (select-window bufwin)
7409 (pop-to-buffer buf))
7410 (goto-char (marker-position idlwave-rinfo-marker)))))
7411 ((eq id 'keyword)
7412 (if right
7413 (progn
7414 (idlwave-require-online-help)
7415 (idlwave-online-help nil name type class keyword))
7416 (idlwave-rinfo-insert-keyword keyword buf shift))))))
7417
7418 (defun idlwave-rinfo-insert-keyword (keyword buffer &optional shift)
7419 "Insert KEYWORD in BUFFER. Make sure buffer is displayed in a window."
7420 (let ((bwin (get-buffer-window buffer)))
7421 (if idlwave-complete-empty-string-as-lower-case
7422 (setq keyword (downcase keyword)))
7423 (if bwin
7424 (select-window bwin)
7425 (pop-to-buffer buffer)
7426 (setq bwin (get-buffer-window buffer)))
7427 (if (eq (preceding-char) ?/)
7428 (insert keyword)
7429 (unless (save-excursion
7430 (re-search-backward
7431 "[(,][ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\)?[ \t]*\\="
7432 (min (- (point) 100) (point-min)) t))
7433 (insert ", "))
7434 (if shift (insert "/"))
7435 (insert keyword)
7436 (if (and (not shift)
7437 idlwave-keyword-completion-adds-equal)
7438 (insert "=")))))
7439
7440 (defun idlwave-list-buffer-load-path-shadows (&optional arg)
7441 "List the load path shadows of all routines defined in current buffer."
7442 (interactive "P")
7443 (idlwave-routines)
7444 (if (eq major-mode 'idlwave-mode)
7445 (idlwave-list-load-path-shadows
7446 nil (idlwave-update-current-buffer-info 'save-buffer)
7447 "in current buffer")
7448 (error "Current buffer is not in idlwave-mode")))
7449
7450 (defun idlwave-list-shell-load-path-shadows (&optional arg)
7451 "List the load path shadows of all routines compiled under the shell.
7452 This is very useful for checking an IDL application. Just compile the
7453 application, do RESOLVE_ALL, and `C-c C-i' to compile all referenced
7454 routines and update IDLWAVE internal info. Then check for shadowing
7455 with this command."
7456 (interactive "P")
7457 (cond
7458 ((or (not (fboundp 'idlwave-shell-is-running))
7459 (not (idlwave-shell-is-running)))
7460 (error "Shell is not running"))
7461 ((null idlwave-compiled-routines)
7462 (error "No compiled routines. Maybe you need to update with `C-c C-i'"))
7463 (t
7464 (idlwave-list-load-path-shadows nil idlwave-compiled-routines
7465 "in the shell"))))
7466
7467 (defun idlwave-list-all-load-path-shadows (&optional arg)
7468 "List the load path shadows of all routines known to IDLWAVE."
7469 (interactive "P")
7470 (idlwave-list-load-path-shadows nil nil "globally"))
7471
7472 (defun idlwave-list-load-path-shadows (arg &optional special-routines loc)
7473 "List the routines which are defined multiple times.
7474 Search the information IDLWAVE has about IDL routines for multiple
7475 definitions.
7476 When SPECIAL-ROUTINES in non-nil, only look for shadows of these routines.
7477
7478 When IDL hits a routine call which is not defined, it will search on
7479 the load path in order to find a definition. The output of this
7480 command can be used to detect possible name clashes during this process."
7481 (idlwave-routines) ; Make sure everything is loaded.
7482 (unless idlwave-library-routines
7483 (or (y-or-n-p
7484 "You don't have a library catalog. Continue anyway? ")
7485 (error "Abort")))
7486 (let* ((routines (append idlwave-system-routines
7487 idlwave-compiled-routines
7488 idlwave-library-routines
7489 idlwave-buffer-routines
7490 nil))
7491 (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
7492 (keymap (make-sparse-keymap))
7493 (props (list 'mouse-face 'highlight
7494 km-prop keymap
7495 'help-echo "Mouse2: Find source"))
7496 (nroutines (length (or special-routines routines)))
7497 (step (/ nroutines 99))
7498 (n 0)
7499 (next-perc 1)
7500 (cnt 0)
7501 (idlwave-sort-prefer-buffer-info nil)
7502 routine twins dtwins twin done props1 lroutines)
7503
7504 (if special-routines
7505 ;; Just looking for shadows of a few special routines
7506 (setq lroutines routines
7507 routines special-routines))
7508
7509 (message "Sorting routines...")
7510 (setq routines (sort routines
7511 (lambda (a b)
7512 (string< (downcase (idlwave-make-full-name
7513 (nth 2 a) (car a)))
7514 (downcase (idlwave-make-full-name
7515 (nth 2 b) (car b)))))))
7516 (message "Sorting routines...done")
7517
7518 (define-key keymap (if (featurep 'xemacs) [(button2)] [(mouse-2)])
7519 (lambda (ev)
7520 (interactive "e")
7521 (mouse-set-point ev)
7522 (apply 'idlwave-do-find-module
7523 (get-text-property (point) 'find-args))))
7524 (define-key keymap [(return)]
7525 (lambda ()
7526 (interactive)
7527 (apply 'idlwave-do-find-module
7528 (get-text-property (point) 'find-args))))
7529 (message "Compiling list...( 0%%)")
7530 (save-excursion
7531 (set-buffer (get-buffer-create "*Shadows*"))
7532 (setq buffer-read-only nil)
7533 (erase-buffer)
7534 (while (setq routine (pop routines))
7535 (setq n (1+ n))
7536 (if (= (* next-perc step) n)
7537 (progn
7538 (message "Compiling list...(%2d%%)" next-perc)
7539 (setq next-perc (1+ next-perc))))
7540 ;; Get a list of all twins
7541 (setq twins (idlwave-routine-twins routine (or lroutines routines)))
7542 (if (memq routine done)
7543 (setq dtwins nil)
7544 (setq dtwins (idlwave-study-twins twins)))
7545 ;; Mark all twins as dealt with
7546 (setq done (append twins done))
7547 (when (or (> (length dtwins) 1)
7548 (> (idlwave-count-eq 'lib (nth 2 (car dtwins))) 1)
7549 (> (idlwave-count-eq 'buffer (nth 2 (car dtwins))) 1))
7550 (incf cnt)
7551 (insert (format "\n%s%s"
7552 (idlwave-make-full-name (nth 2 routine) (car routine))
7553 (if (eq (nth 1 routine) 'fun) "()" "")))
7554 (while (setq twin (pop dtwins))
7555 (setq props1 (append (list 'find-args
7556 (list (nth 0 routine)
7557 (nth 1 routine)
7558 (nth 2 routine)
7559 (cons 'lib (nth 1 twin))))
7560 props))
7561 (idlwave-insert-source-location "\n - " twin props1))))
7562 (goto-char (point-min))
7563 (setq buffer-read-only t))
7564 (setq loc (or loc ""))
7565 (if (> cnt 0)
7566 (progn
7567 (display-buffer (get-buffer "*Shadows*"))
7568 (message "%d case%s of shadowing found %s"
7569 cnt (if (= cnt 1) "" "s") loc))
7570 (message "No shadowing conflicts found %s" loc))))
7571
7572 (defun idlwave-print-source (routine)
7573 (let* ((source (nth 3 routine))
7574 (stype (car source))
7575 (sfile (cdr source)))
7576 (if (and (eq stype 'lib) sfile)
7577 (progn
7578 (setq sfile (idlwave-expand-lib-file-name sfile))
7579 (if (idlwave-syslib-p sfile) (setq stype 'syslib))))
7580 (if (and (eq stype 'compiled)
7581 (or (not (stringp sfile))
7582 (not (string-match "\\S-" sfile))))
7583 (setq stype 'unresolved))
7584 (princ (format " %-10s %s\n"
7585 stype
7586 (if sfile sfile "No source code available")))))
7587
7588 (defun idlwave-routine-twins (entry &optional list)
7589 "Return all twin entries of ENTRY in LIST.
7590 LIST defaults to `idlwave-routines'.
7591 Twin entries are those which have the same name, type, and class.
7592 ENTRY will also be returned, as the first item of this list."
7593 (let* ((name (car entry))
7594 (type (nth 1 entry))
7595 (class (nth 2 entry))
7596 (candidates (idlwave-all-assq name (or list (idlwave-routines))))
7597 twins candidate)
7598 (while (setq candidate (pop candidates))
7599 (if (and (not (eq candidate entry))
7600 (eq type (nth 1 candidate))
7601 (eq class (nth 2 candidate)))
7602 (push candidate twins)))
7603 (if (setq candidate (idlwave-rinfo-assq name type class
7604 idlwave-unresolved-routines))
7605 (push candidate twins))
7606 (cons entry (nreverse twins))))
7607
7608 (defun idlwave-study-twins (entries)
7609 "Return dangerous twins of first entry in TWINS.
7610 Dangerous twins are routines with same name, but in different files
7611 on the load path.
7612 If a file is in the system library and has an entry in the
7613 `idlwave-system-routines' list, we omit the latter because many IDL
7614 routines are implemented as library routines."
7615 (let* ((entry (car entries))
7616 (name (car entry)) ;
7617 (type (nth 1 entry)) ; Must be bound for
7618 (class (nth 2 entry)) ; idlwave-routine-twin-compare
7619 (cnt 0)
7620 source type file thefile alist syslibp key)
7621 (while (setq entry (pop entries))
7622 (incf cnt)
7623 (setq source (nth 3 entry)
7624 type (car source)
7625 file (cdr source))
7626 (if (eq type 'lib)
7627 (setq file (idlwave-expand-lib-file-name file)))
7628 ;; Make KEY to index entry properly
7629 (setq key (cond ((eq type 'system) type)
7630 (file (file-truename file))
7631 (t 'unresolved)))
7632 (if (and file
7633 (not syslibp)
7634 (idlwave-syslib-p file))
7635 ;; We do have an entry in the system library
7636 (setq syslibp t))
7637
7638 (setq thefile (or thefile file))
7639 (if (setq entry (assoc key alist))
7640 (push type (nth 2 entry))
7641 (push (list key file (list type)) alist)))
7642
7643 (setq alist (nreverse alist))
7644
7645 (when syslibp
7646 ;; File is system *library* - remove any system entry
7647 (setq alist (delq (assoc 'system alist) alist)))
7648
7649 (when (and (idlwave-syslib-scanned-p)
7650 (setq entry (assoc 'system alist)))
7651 (setcar entry 'builtin))
7652 (sort alist 'idlwave-routine-twin-compare)))
7653
7654 (defvar name)
7655 (defvar type)
7656 (defvar class)
7657 (defvar idlwave-sort-prefer-buffer-info t
7658 "Internal variable used to influence `idlwave-routine-twin-compare'.")
7659
7660 (defmacro idlwave-xor (a b)
7661 `(and (or ,a ,b)
7662 (not (and ,a ,b))))
7663
7664 (defun idlwave-routine-entry-compare (a b)
7665 "Compare two routine info entries for sortiung. This is the general case.
7666 It first compates class, names, and type. If it turns out that A and B
7667 are twins (same name, class, and type), calls another routine which
7668 compares twins on the basis of their file names and path locations."
7669 (let ((name (car a)) (type (nth 1 a)) (class (nth 2 a)))
7670 (cond
7671 ((not (equal (idlwave-downcase-safe class)
7672 (idlwave-downcase-safe (nth 2 b))))
7673 ;; Class decides
7674 (cond ((null (nth 2 b)) nil)
7675 ((null class) t)
7676 (t (string< (downcase class) (downcase (nth 2 b))))))
7677 ((not (equal (downcase name) (downcase (car b))))
7678 ;; Name decides
7679 (string< (downcase name) (downcase (car b))))
7680 ((not (eq type (nth 1 b)))
7681 ;; Type decides
7682 (< (if (eq type 'fun) 1 0) (if (eq (nth 1 b) 'fun) 1 0)))
7683 (t
7684 ;; A and B are twins - so the decision is more complicated.
7685 ;; Call twin-compare with the proper arguments.
7686 (idlwave-routine-entry-compare-twins a b)))))
7687
7688 (defun idlwave-routine-entry-compare-twins (a b)
7689 "Compare two routine entries, under the assumption that they are twins.
7690 This basically calles `idlwave-routine-twin-compare' with the correct args."
7691 (let ((name (car a)) (type (nth 1 a)) (class (nth 2 a)) ; needed outside
7692 (atype (car (nth 3 a)))
7693 (btype (car (nth 3 b)))
7694 (afile (cdr (nth 3 a)))
7695 (bfile (cdr (nth 3 b))))
7696 (if (eq atype 'lib)
7697 (setq afile (idlwave-expand-lib-file-name afile)))
7698 (if (eq btype 'lib)
7699 (setq bfile (idlwave-expand-lib-file-name bfile)))
7700 (idlwave-routine-twin-compare
7701 (if (stringp afile)
7702 (list (file-truename afile) afile (list atype))
7703 (list atype afile (list atype)))
7704 (if (stringp bfile)
7705 (list (file-truename bfile) bfile (list btype))
7706 (list btype bfile (list btype))))
7707 ))
7708
7709 (defun idlwave-routine-twin-compare (a b)
7710 "Compare two routine twin entries for sorting.
7711 In here, A and B are not normal routine info entries, but special
7712 lists (KEY FILENAME (TYPES...)).
7713 This expects NAME TYPE CLASS to be bound to the right values."
7714 (let* (;; Dis-assemble entries
7715 (akey (car a)) (bkey (car b))
7716 (afile (nth 1 a)) (bfile (nth 1 b))
7717 (atypes (nth 2 a)) (btypes (nth 2 b))
7718 ;; System routines?
7719 (asysp (memq akey '(builtin system)))
7720 (bsysp (memq bkey '(builtin system)))
7721 ;; Compiled routines?
7722 (acompp (memq 'compiled atypes))
7723 (bcompp (memq 'compiled btypes))
7724 ;; Unresolved?
7725 (aunresp (or (eq akey 'unresolved)
7726 (and acompp (not afile))))
7727 (bunresp (or (eq bkey 'unresolved)
7728 (and bcompp (not bfile))))
7729 ;; Buffer info available?
7730 (abufp (memq 'buffer atypes))
7731 (bbufp (memq 'buffer btypes))
7732 ;; On search path?
7733 (tpath-alist (idlwave-true-path-alist))
7734 (apathp (assoc akey tpath-alist))
7735 (bpathp (assoc bkey tpath-alist))
7736 ;; How early on search path? High number means early since we
7737 ;; measure the tail of the path list
7738 (anpath (length (memq apathp tpath-alist)))
7739 (bnpath (length (memq bpathp tpath-alist)))
7740 ;; Look at file names
7741 (aname (if (stringp afile) (downcase (file-name-nondirectory afile)) ""))
7742 (bname (if (stringp bfile) (downcase (file-name-nondirectory bfile)) ""))
7743 (fname-re (if class (format "\\`%s__\\(%s\\|define\\)\\.pro\\'"
7744 (regexp-quote (downcase class))
7745 (regexp-quote (downcase name)))
7746 (format "\\`%s\\.pro" (regexp-quote (downcase name)))))
7747 ;; Is file name derived from the routine name?
7748 ;; Method file or class definition file?
7749 (anamep (string-match fname-re aname))
7750 (adefp (and class anamep (string= "define" (match-string 1 aname))))
7751 (bnamep (string-match fname-re bname))
7752 (bdefp (and class bnamep (string= "define" (match-string 1 bname)))))
7753
7754 ;; Now: follow JD's ideas about sorting. Looks really simple now,
7755 ;; doesn't it? The difficult stuff is hidden above...
7756 (cond
7757 ((idlwave-xor asysp bsysp) asysp) ; System entries first
7758 ((idlwave-xor aunresp bunresp) bunresp) ; Unresolved last
7759 ((and idlwave-sort-prefer-buffer-info
7760 (idlwave-xor abufp bbufp)) abufp) ; Buffers before non-buffers
7761 ((idlwave-xor acompp bcompp) acompp) ; Compiled entries
7762 ((idlwave-xor apathp bpathp) apathp) ; Library before non-library
7763 ((idlwave-xor anamep bnamep) anamep) ; Correct file names first
7764 ((and class anamep bnamep ; both file names match ->
7765 (idlwave-xor adefp bdefp)) bdefp) ; __define after __method
7766 ((> anpath bnpath) t) ; Who is first on path?
7767 (t nil)))) ; Default
7768
7769 (defun idlwave-downcase-safe (string)
7770 "Donwcase if string, else return unchanged."
7771 (if (stringp string)
7772 (downcase string)
7773 string))
7774
7775 (defun idlwave-count-eq (elt list)
7776 "How often is ELT in LIST?"
7777 (length (delq nil (mapcar (lambda (x) (eq x elt)) list))))
7778
7779 (defun idlwave-syslib-p (file)
7780 "Non-nil of FILE is in the system library."
7781 (let* ((true-syslib (file-name-as-directory
7782 (file-truename
7783 (expand-file-name "lib" (idlwave-sys-dir)))))
7784 (true-file (file-truename file)))
7785 (string-match (concat "^" (regexp-quote true-syslib)) true-file)))
7786
7787 (defun idlwave-lib-p (file)
7788 "Non-nil if file is in the library"
7789 (let ((true-dir (file-name-directory (file-truename file))))
7790 (assoc true-dir (idlwave-true-path-alist))))
7791
7792 (defun idlwave-true-path-alist ()
7793 "Return `idlwave-path-alist' alist with true-names.
7794 Info is cached, but relies on the functons setting `idlwave-path-alist'
7795 to reset the variable `idlwave-true-path-alist' to nil."
7796 (or idlwave-true-path-alist
7797 (setq idlwave-true-path-alist
7798 (mapcar (lambda(x) (cons
7799 (file-name-as-directory
7800 (file-truename
7801 (directory-file-name
7802 (car x))))
7803 (cdr x)))
7804 idlwave-path-alist))))
7805
7806 (defun idlwave-syslib-scanned-p ()
7807 "Non-nil if the system lib file !DIR/lib has been scanned."
7808 (let* ((true-syslib (file-name-as-directory
7809 (file-truename
7810 (expand-file-name "lib" (idlwave-sys-dir))))))
7811 (cdr (assoc true-syslib (idlwave-true-path-alist)))))
7812
7813 ;; ----------------------------------------------------------------------------
7814 ;;
7815 ;; Online Help display
7816
7817
7818 ;; ----------------------------------------------------------------------------
7819 ;;
7820 ;; Additions for use with imenu.el and func-menu.el
7821 ;; (pop-up a list of IDL units in the current file).
7822 ;;
7823
7824 (defun idlwave-prev-index-position ()
7825 "Search for the previous procedure or function.
7826 Return nil if not found. For use with imenu.el."
7827 (save-match-data
7828 (cond
7829 ((idlwave-find-key "\\<\\(pro\\|function\\)\\>" -1 'nomark))
7830 ;; ((idlwave-find-key idlwave-begin-unit-reg 1 'nomark)
7831 (t nil))))
7832
7833 (defun idlwave-unit-name ()
7834 "Return the unit name.
7835 Assumes that point is at the beginning of the unit as found by
7836 `idlwave-prev-index-position'."
7837 (forward-sexp 2)
7838 (forward-sexp -1)
7839 (let ((begin (point)))
7840 (re-search-forward "[a-zA-Z][a-zA-Z0-9$_]+\\(::[a-zA-Z][a-zA-Z0-9$_]+\\)?")
7841 (if (fboundp 'buffer-substring-no-properties)
7842 (buffer-substring-no-properties begin (point))
7843 (buffer-substring begin (point)))))
7844
7845 (defun idlwave-function-menu ()
7846 "Use `imenu' or `function-menu' to jump to a procedure or function."
7847 (interactive)
7848 (if (string-match "XEmacs" emacs-version)
7849 (progn
7850 (require 'func-menu)
7851 (function-menu))
7852 (require 'imenu)
7853 (imenu (imenu-choose-buffer-index))))
7854
7855 ;; Here we kack func-menu.el in order to support this new mode.
7856 ;; The latest versions of func-menu.el already have this stuff in, so
7857 ;; we hack only if it is not already there.
7858 (when (fboundp 'eval-after-load)
7859 (eval-after-load "func-menu"
7860 '(progn
7861 (or (assq 'idlwave-mode fume-function-name-regexp-alist)
7862 (not (boundp 'fume-function-name-regexp-idl)) ; avoid problems
7863 (setq fume-function-name-regexp-alist
7864 (cons '(idlwave-mode . fume-function-name-regexp-idl)
7865 fume-function-name-regexp-alist)))
7866 (or (assq 'idlwave-mode fume-find-function-name-method-alist)
7867 (not (fboundp 'fume-find-next-idl-function-name)) ; avoid problems
7868 (setq fume-find-function-name-method-alist
7869 (cons '(idlwave-mode . fume-find-next-idl-function-name)
7870 fume-find-function-name-method-alist))))))
7871
7872 (defun idlwave-edit-in-idlde ()
7873 "Edit the current file in IDL Development environment."
7874 (interactive)
7875 (start-process "idldeclient" nil
7876 idlwave-shell-explicit-file-name "-c" "-e"
7877 (buffer-file-name) "&"))
7878
7879 (defun idlwave-launch-idlhelp ()
7880 "Start the IDLhelp application."
7881 (interactive)
7882 (start-process "idlhelp" nil idlwave-help-application))
7883
7884 ;; Menus - using easymenu.el
7885 (defvar idlwave-mode-menu-def
7886 `("IDLWAVE"
7887 ["PRO/FUNC menu" idlwave-function-menu t]
7888 ("Motion"
7889 ["Subprogram Start" idlwave-beginning-of-subprogram t]
7890 ["Subprogram End" idlwave-end-of-subprogram t]
7891 ["Block Start" idlwave-beginning-of-block t]
7892 ["Block End" idlwave-end-of-block t]
7893 ["Up Block" idlwave-backward-up-block t]
7894 ["Down Block" idlwave-down-block t]
7895 ["Skip Block Backward" idlwave-backward-block t]
7896 ["Skip Block Forward" idlwave-forward-block t])
7897 ("Mark"
7898 ["Subprogram" idlwave-mark-subprogram t]
7899 ["Block" idlwave-mark-block t]
7900 ["Header" idlwave-mark-doclib t])
7901 ("Format"
7902 ["Indent Subprogram" idlwave-indent-subprogram t]
7903 ["(Un)Comment Region" idlwave-toggle-comment-region "C-c ;"]
7904 ["Continue/Split line" idlwave-split-line t]
7905 "--"
7906 ["Toggle Auto Fill" idlwave-auto-fill-mode :style toggle
7907 :selected (symbol-value idlwave-fill-function)])
7908 ("Templates"
7909 ["Procedure" idlwave-procedure t]
7910 ["Function" idlwave-function t]
7911 ["Doc Header" idlwave-doc-header t]
7912 ["Log" idlwave-doc-modification t]
7913 "--"
7914 ["Case" idlwave-case t]
7915 ["For" idlwave-for t]
7916 ["Repeat" idlwave-repeat t]
7917 ["While" idlwave-while t]
7918 "--"
7919 ["Close Block" idlwave-close-block t])
7920 ("Completion"
7921 ["Complete" idlwave-complete t]
7922 ("Complete Special"
7923 ["1 Procedure Name" (idlwave-complete 'procedure) t]
7924 ["2 Procedure Keyword" (idlwave-complete 'procedure-keyword) t]
7925 "--"
7926 ["3 Function Name" (idlwave-complete 'function) t]
7927 ["4 Function Keyword" (idlwave-complete 'function-keyword) t]
7928 "--"
7929 ["5 Procedure Method Name" (idlwave-complete 'procedure-method) t]
7930 ["6 Procedure Method Keyword" (idlwave-complete 'procedure-method-keyword) t]
7931 "--"
7932 ["7 Function Method Name" (idlwave-complete 'function-method) t]
7933 ["8 Function Method Keyword" (idlwave-complete 'function-method-keyword) t]
7934 "--"
7935 ["9 Class Name" idlwave-complete-class t]))
7936 ("Routine Info"
7937 ["Show Routine Info" idlwave-routine-info t]
7938 ["Online Context Help" idlwave-context-help (idlwave-help-directory)]
7939 "--"
7940 ["Find Routine Source" idlwave-find-module t]
7941 ["Resolve Routine" idlwave-resolve (featurep 'idlw-shell)]
7942 "--"
7943 ["Update Routine Info" idlwave-update-routine-info t]
7944 "--"
7945 "IDL Library Catalog"
7946 ["Select Catalog Directories" (idlwave-create-libinfo-file nil) t]
7947 ["Scan Directories" (idlwave-update-routine-info '(16))
7948 (and idlwave-path-alist (not idlwave-catalog-process))]
7949 ["Scan Directories &" (idlwave-update-routine-info '(64))
7950 (and idlwave-path-alist (not idlwave-catalog-process))]
7951 "--"
7952 "Routine Shadows"
7953 ["Check Current Buffer" idlwave-list-buffer-load-path-shadows t]
7954 ["Check Compiled Routines" idlwave-list-shell-load-path-shadows t]
7955 ["Check Everything" idlwave-list-all-load-path-shadows t])
7956 ("Misc"
7957 ["Kill auto-created buffers" idlwave-kill-autoloaded-buffers t]
7958 "--"
7959 ["Insert TAB character" idlwave-hard-tab t])
7960 "--"
7961 ("External"
7962 ["Generate IDL tags" idlwave-make-tags t]
7963 ["Start IDL shell" idlwave-shell t]
7964 ["Edit file in IDLDE" idlwave-edit-in-idlde t]
7965 ["Launch IDL Help" idlwave-launch-idlhelp t])
7966 "--"
7967 ("Customize"
7968 ["Browse IDLWAVE Group" idlwave-customize t]
7969 "--"
7970 ["Build Full Customize Menu" idlwave-create-customize-menu
7971 (fboundp 'customize-menu-create)])
7972 ("Documentation"
7973 ["Describe Mode" describe-mode t]
7974 ["Abbreviation List" idlwave-list-abbrevs t]
7975 "--"
7976 ["Commentary in idlwave.el" idlwave-show-commentary t]
7977 ["Commentary in idlw-shell.el" idlwave-shell-show-commentary t]
7978 "--"
7979 ["Info" idlwave-info t]
7980 "--"
7981 ["Launch IDL Help" idlwave-launch-idlhelp t])))
7982
7983 (defvar idlwave-mode-debug-menu-def
7984 '("Debug"
7985 ["Start IDL shell" idlwave-shell t]
7986 ["Save and .RUN buffer" idlwave-shell-save-and-run
7987 (and (boundp 'idlwave-shell-automatic-start)
7988 idlwave-shell-automatic-start)]))
7989
7990 (if (or (featurep 'easymenu) (load "easymenu" t))
7991 (progn
7992 (easy-menu-define idlwave-mode-menu idlwave-mode-map
7993 "IDL and WAVE CL editing menu"
7994 idlwave-mode-menu-def)
7995 (easy-menu-define idlwave-mode-debug-menu idlwave-mode-map
7996 "IDL and WAVE CL editing menu"
7997 idlwave-mode-debug-menu-def)))
7998
7999 (defun idlwave-customize ()
8000 "Call the customize function with idlwave as argument."
8001 (interactive)
8002 ;; Try to load the code for the shell, so that we can customize it
8003 ;; as well.
8004 (or (featurep 'idlw-shell)
8005 (load "idlw-shell" t))
8006 (customize-browse 'idlwave))
8007
8008 (defun idlwave-create-customize-menu ()
8009 "Create a full customization menu for IDLWAVE, insert it into the menu."
8010 (interactive)
8011 (if (fboundp 'customize-menu-create)
8012 (progn
8013 ;; Try to load the code for the shell, so that we can customize it
8014 ;; as well.
8015 (or (featurep 'idlw-shell)
8016 (load "idlw-shell" t))
8017 (easy-menu-change
8018 '("IDLWAVE") "Customize"
8019 `(["Browse IDLWAVE group" idlwave-customize t]
8020 "--"
8021 ,(customize-menu-create 'idlwave)
8022 ["Set" Custom-set t]
8023 ["Save" Custom-save t]
8024 ["Reset to Current" Custom-reset-current t]
8025 ["Reset to Saved" Custom-reset-saved t]
8026 ["Reset to Standard Settings" Custom-reset-standard t]))
8027 (message "\"IDLWAVE\"-menu now contains full customization menu"))
8028 (error "Cannot expand menu (outdated version of cus-edit.el)")))
8029
8030 (defun idlwave-show-commentary ()
8031 "Use the finder to view the file documentation from `idlwave.el'."
8032 (interactive)
8033 (require 'finder)
8034 (finder-commentary "idlwave.el"))
8035
8036 (defun idlwave-shell-show-commentary ()
8037 "Use the finder to view the file documentation from `idlw-shell.el'."
8038 (interactive)
8039 (require 'finder)
8040 (finder-commentary "idlw-shell.el"))
8041
8042 (defun idlwave-info ()
8043 "Read documentation for IDLWAVE in the info system."
8044 (interactive)
8045 (require 'info)
8046 (Info-goto-node "(idlwave)"))
8047
8048 (defun idlwave-list-abbrevs (arg)
8049 "Show the code abbreviations define in IDLWAVE mode.
8050 This lists all abbrevs where the replacement text differs from the input text.
8051 These are the ones the users want to learn to speed up their writing.
8052
8053 The function does *not* list abbrevs which replace a word with itself
8054 to call a hook. These hooks are used to change the case of words or
8055 to blink the matching `begin', and the user does not need to know them.
8056
8057 With arg, list all abbrevs with the corresponding hook.
8058
8059 This function was written since `list-abbrevs' looks terrible for IDLWAVE mode."
8060
8061 (interactive "P")
8062 (let ((table (symbol-value 'idlwave-mode-abbrev-table))
8063 abbrevs
8064 str rpl func fmt (len-str 0) (len-rpl 0))
8065 (mapatoms
8066 (lambda (sym)
8067 (if (symbol-value sym)
8068 (progn
8069 (setq str (symbol-name sym)
8070 rpl (symbol-value sym)
8071 func (symbol-function sym))
8072 (if arg
8073 (setq func (prin1-to-string func))
8074 (if (and (listp func) (stringp (nth 2 func)))
8075 (setq rpl (concat "EVAL: " (nth 2 func))
8076 func "")
8077 (setq func "")))
8078 (if (or arg (not (string= rpl str)))
8079 (progn
8080 (setq len-str (max len-str (length str)))
8081 (setq len-rpl (max len-rpl (length rpl)))
8082 (setq abbrevs (cons (list str rpl func) abbrevs)))))))
8083 table)
8084 ;; sort the list
8085 (setq abbrevs (sort abbrevs (lambda (a b) (string< (car a) (car b)))))
8086 ;; Make the format
8087 (setq fmt (format "%%-%ds %%-%ds %%s\n" len-str len-rpl))
8088 (with-output-to-temp-buffer "*Help*"
8089 (if arg
8090 (progn
8091 (princ "Abbreviations and Actions in IDLWAVE-Mode\n")
8092 (princ "=========================================\n\n")
8093 (princ (format fmt "KEY" "REPLACE" "HOOK"))
8094 (princ (format fmt "---" "-------" "----")))
8095 (princ "Code Abbreviations and Templates in IDLWAVE-Mode\n")
8096 (princ "================================================\n\n")
8097 (princ (format fmt "KEY" "ACTION" ""))
8098 (princ (format fmt "---" "------" "")))
8099 (mapcar
8100 (lambda (list)
8101 (setq str (car list)
8102 rpl (nth 1 list)
8103 func (nth 2 list))
8104 (princ (format fmt str rpl func)))
8105 abbrevs)))
8106 ;; Make sure each abbreviation uses only one display line
8107 (save-excursion
8108 (set-buffer "*Help*")
8109 (setq truncate-lines t)))
8110
8111 ;; Add .pro files to speedbar for support, if it's loaded
8112 (eval-after-load "speedbar" '(speedbar-add-supported-extension ".pro"))
8113
8114 ;; Try to load online help, but catch any errors.
8115 (condition-case nil
8116 (idlwave-require-online-help)
8117 (error nil))
8118
8119 ;; Set an idle timer to load the routine info.
8120 ;; Will only work on systems which support this.
8121 (or idlwave-routines (idlwave-start-load-rinfo-timer))
8122
8123 ;; Run the hook
8124 (run-hooks 'idlwave-load-hook)
8125
8126 (provide 'idlwave)
8127
8128 ;;; idlwave.el ends here