Commit | Line | Data |
---|---|---|
52a244eb | 1 | ;; idlwave.el --- IDL editing mode for GNU Emacs |
d7a0267c | 2 | |
1ba983e8 GM |
3 | ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
4 | ;; 2008, 2009 Free Software Foundation, Inc. | |
f32b3b91 | 5 | |
52a244eb | 6 | ;; Authors: J.D. Smith <jdsmith@as.arizona.edu> |
65363a4e | 7 | ;; Carsten Dominik <dominik@science.uva.nl> |
52a244eb | 8 | ;; Chris Chase <chase@att.com> |
5e72c6b2 | 9 | ;; Maintainer: J.D. Smith <jdsmith@as.arizona.edu> |
e08734e2 | 10 | ;; Version: 6.1_em22 |
f32b3b91 CD |
11 | ;; Keywords: languages |
12 | ||
e8af40ee | 13 | ;; This file is part of GNU Emacs. |
f32b3b91 | 14 | |
b1fc2b50 | 15 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
f32b3b91 | 16 | ;; it under the terms of the GNU General Public License as published by |
b1fc2b50 GM |
17 | ;; the Free Software Foundation, either version 3 of the License, or |
18 | ;; (at your option) any later version. | |
f32b3b91 CD |
19 | |
20 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
21 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 | ;; GNU General Public License for more details. | |
24 | ||
25 | ;; You should have received a copy of the GNU General Public License | |
b1fc2b50 | 26 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
f32b3b91 CD |
27 | |
28 | ;;; Commentary: | |
29 | ||
f66f03de S |
30 | ;; IDLWAVE enables feature-rich development and interaction with IDL, |
31 | ;; the Interactive Data Language. It provides a compelling, | |
32 | ;; full-featured alternative to the IDLDE development environment | |
33 | ;; bundled with IDL. | |
3938cb82 | 34 | |
52a244eb S |
35 | ;; In the remotely distant past, based on pascal.el, though bears |
36 | ;; little resemblance to it now. | |
f32b3b91 CD |
37 | ;; |
38 | ;; Incorporates many ideas, such as abbrevs, action routines, and | |
39 | ;; continuation line indenting, from wave.el. | |
40 | ;; wave.el original written by Lubos Pochman, Precision Visuals, Boulder. | |
41 | ;; | |
42 | ;; See the mode description ("C-h m" in idlwave-mode or "C-h f idlwave-mode") | |
43 | ;; for features, key bindings, and info. | |
44 | ;; Also, Info format documentation is available with `M-x idlwave-info' | |
45 | ;; | |
5e72c6b2 S |
46 | ;; New versions of IDLWAVE, documentation, and more information |
47 | ;; available from: | |
48 | ;; http://idlwave.org | |
f32b3b91 CD |
49 | ;; |
50 | ;; INSTALLATION | |
51 | ;; ============ | |
52 | ;; | |
53 | ;; Follow the instructions in the INSTALL file of the distribution. | |
54 | ;; In short, put this file on your load path and add the following | |
55 | ;; lines to your .emacs file: | |
56 | ;; | |
57 | ;; (autoload 'idlwave-mode "idlwave" "IDLWAVE Mode" t) | |
8c7b4ec8 | 58 | ;; (autoload 'idlwave-shell "idlw-shell" "IDLWAVE Shell" t) |
f32b3b91 CD |
59 | ;; (setq auto-mode-alist (cons '("\\.pro\\'" . idlwave-mode) auto-mode-alist)) |
60 | ;; | |
61 | ;; | |
62 | ;; SOURCE | |
63 | ;; ====== | |
64 | ;; | |
76959b77 | 65 | ;; The newest version of this file is available from the maintainer's |
52a244eb | 66 | ;; Webpage: |
f32b3b91 | 67 | ;; |
5e72c6b2 | 68 | ;; http://idlwave.org |
f32b3b91 CD |
69 | ;; |
70 | ;; DOCUMENTATION | |
71 | ;; ============= | |
72 | ;; | |
52a244eb S |
73 | ;; IDLWAVE is documented online in info format. A printable version |
74 | ;; of the documentation is available from the maintainers webpage (see | |
75 | ;; SOURCE). | |
775591f7 | 76 | ;; |
4b1aaa8b | 77 | ;; |
f32b3b91 CD |
78 | ;; ACKNOWLEDGMENTS |
79 | ;; =============== | |
80 | ;; | |
81 | ;; Thanks to the following people for their contributions and comments: | |
82 | ;; | |
52a244eb S |
83 | ;; Ulrik Dickow <dickow_at_nbi.dk> |
84 | ;; Eric E. Dors <edors_at_lanl.gov> | |
85 | ;; Stein Vidar H. Haugan <s.v.h.haugan_at_astro.uio.no> | |
86 | ;; David Huenemoerder <dph_at_space.mit.edu> | |
87 | ;; Kevin Ivory <Kevin.Ivory_at_linmpi.mpg.de> | |
88 | ;; Dick Jackson <dick_at_d-jackson.com> | |
89 | ;; Xuyong Liu <liu_at_stsci.edu> | |
90 | ;; Simon Marshall <Simon.Marshall_at_esrin.esa.it> | |
91 | ;; Laurent Mugnier <mugnier_at_onera.fr> | |
92 | ;; Lubos Pochman <lubos_at_rsinc.com> | |
93 | ;; Bob Portmann <portmann_at_al.noaa.gov> | |
94 | ;; Patrick M. Ryan <pat_at_jaameri.gsfc.nasa.gov> | |
95 | ;; Marty Ryba <ryba_at_ll.mit.edu> | |
96 | ;; Paul Sorenson <aardvark62_at_msn.com> | |
97 | ;; Phil Sterne <sterne_at_dublin.llnl.gov> | |
98 | ;; Phil Williams <williams_at_irc.chmcc.org> | |
f32b3b91 CD |
99 | ;; |
100 | ;; CUSTOMIZATION: | |
101 | ;; ============= | |
102 | ;; | |
52a244eb S |
103 | ;; IDLWAVE has extensive customize support; to learn about the |
104 | ;; variables which control the mode's behavior, use `M-x | |
105 | ;; idlwave-customize'. | |
f32b3b91 CD |
106 | ;; |
107 | ;; You can set your own preferred values with Customize, or with Lisp | |
108 | ;; code in .emacs. For an example of what to put into .emacs, check | |
52a244eb S |
109 | ;; the TexInfo documentation or see a complete .emacs available at the |
110 | ;; website. | |
f32b3b91 CD |
111 | ;; |
112 | ;; KNOWN PROBLEMS: | |
113 | ;; ============== | |
114 | ;; | |
76959b77 S |
115 | ;; IDLWAVE support for the IDL-derived PV-WAVE CL language of Visual |
116 | ;; Numerics, Inc. is growing less and less complete as the two | |
117 | ;; languages grow increasingly apart. The mode probably shouldn't | |
3938cb82 | 118 | ;; even have "WAVE" in its title, but it's catchy, and was required |
52a244eb | 119 | ;; to avoid conflict with the CORBA idl.el mode. Caveat WAVEor. |
76959b77 | 120 | ;; |
f32b3b91 CD |
121 | ;; Moving the point backwards in conjunction with abbrev expansion |
122 | ;; does not work as I would like it, but this is a problem with | |
123 | ;; emacs abbrev expansion done by the self-insert-command. It ends | |
124 | ;; up inserting the character that expanded the abbrev after moving | |
125 | ;; point backward, e.g., "\cl" expanded with a space becomes | |
126 | ;; "LONG( )" with point before the close paren. This is solved by | |
4b1aaa8b | 127 | ;; using a temporary function in `post-command-hook' - not pretty, |
595ab50b | 128 | ;; but it works. |
f32b3b91 CD |
129 | ;; |
130 | ;; Tabs and spaces are treated equally as whitespace when filling a | |
131 | ;; comment paragraph. To accomplish this, tabs are permanently | |
132 | ;; replaced by spaces in the text surrounding the paragraph, which | |
133 | ;; may be an undesirable side-effect. Replacing tabs with spaces is | |
134 | ;; limited to comments only and occurs only when a comment | |
135 | ;; paragraph is filled via `idlwave-fill-paragraph'. | |
136 | ;; | |
52a244eb S |
137 | ;; Muti-statement lines (using "&") on block begin and end lines can |
138 | ;; ruin the formatting. For example, multiple end statements on a | |
139 | ;; line: endif & endif. Using "&" outside of block begin/end lines | |
140 | ;; should be okay. | |
f32b3b91 | 141 | ;; |
76959b77 S |
142 | ;; Determining the expression at point for printing and other |
143 | ;; examination commands is somewhat rough: currently only fairly | |
144 | ;; simple entities are found. You can always drag-select or examine | |
52a244eb | 145 | ;; a pre-selected region. |
f32b3b91 | 146 | ;; |
f32b3b91 CD |
147 | ;; When forcing completion of method keywords, the initial |
148 | ;; query for a method has multiple entries for some methods. Would | |
595ab50b | 149 | ;; be too difficult to fix this hardly used case. |
f32b3b91 CD |
150 | ;; |
151 | \f | |
152 | ;;; Code: | |
153 | ||
52a244eb | 154 | |
f32b3b91 | 155 | (eval-when-compile (require 'cl)) |
52a244eb S |
156 | (require 'idlw-help) |
157 | ||
158 | ;; For XEmacs | |
159 | (unless (fboundp 'line-beginning-position) | |
160 | (defalias 'line-beginning-position 'point-at-bol)) | |
161 | (unless (fboundp 'line-end-position) | |
162 | (defalias 'line-end-position 'point-at-eol)) | |
163 | (unless (fboundp 'char-valid-p) | |
164 | (defalias 'char-valid-p 'characterp)) | |
f66f03de S |
165 | (unless (fboundp 'match-string-no-properties) |
166 | (defalias 'match-string-no-properties 'match-string)) | |
f32b3b91 | 167 | |
3938cb82 S |
168 | (if (not (fboundp 'cancel-timer)) |
169 | (condition-case nil | |
170 | (require 'timer) | |
171 | (error nil))) | |
172 | ||
73e72da4 DN |
173 | (declare-function idlwave-shell-get-path-info "idlw-shell") |
174 | (declare-function idlwave-shell-temp-file "idlw-shell") | |
175 | (declare-function idlwave-shell-is-running "idlw-shell") | |
176 | (declare-function widget-value "wid-edit" (widget)) | |
177 | (declare-function comint-dynamic-complete-filename "comint" ()) | |
73e72da4 | 178 | |
f32b3b91 | 179 | (defgroup idlwave nil |
31b58798 | 180 | "Major mode for editing IDL .pro files." |
f32b3b91 | 181 | :tag "IDLWAVE" |
4b1aaa8b | 182 | :link '(url-link :tag "Home Page" |
5e72c6b2 | 183 | "http://idlwave.org") |
595ab50b CD |
184 | :link '(emacs-commentary-link :tag "Commentary in idlw-shell.el" |
185 | "idlw-shell.el") | |
f32b3b91 CD |
186 | :link '(emacs-commentary-link :tag "Commentary in idlwave.el" "idlwave.el") |
187 | :link '(custom-manual "(idlwave)Top") | |
188 | :prefix "idlwave" | |
189 | :group 'languages) | |
190 | ||
52a244eb | 191 | |
f32b3b91 CD |
192 | ;;; Variables for indentation behavior --------------------------------------- |
193 | ||
194 | (defgroup idlwave-code-formatting nil | |
195 | "Indentation and formatting options for IDLWAVE mode." | |
196 | :group 'idlwave) | |
197 | ||
f66f03de | 198 | (defcustom idlwave-main-block-indent 2 |
f32b3b91 CD |
199 | "*Extra indentation for the main block of code. |
200 | That is the block between the FUNCTION/PRO statement and the END | |
201 | statement for that program unit." | |
202 | :group 'idlwave-code-formatting | |
203 | :type 'integer) | |
204 | ||
f66f03de | 205 | (defcustom idlwave-block-indent 3 |
f32b3b91 CD |
206 | "*Extra indentation applied to block lines. |
207 | If you change this, you probably also want to change `idlwave-end-offset'." | |
208 | :group 'idlwave-code-formatting | |
209 | :type 'integer) | |
210 | ||
f66f03de | 211 | (defcustom idlwave-end-offset -3 |
f32b3b91 CD |
212 | "*Extra indentation applied to block END lines. |
213 | A value equal to negative `idlwave-block-indent' will make END lines | |
214 | line up with the block BEGIN lines." | |
215 | :group 'idlwave-code-formatting | |
216 | :type 'integer) | |
217 | ||
f66f03de | 218 | (defcustom idlwave-continuation-indent 3 |
f32b3b91 CD |
219 | "*Extra indentation applied to continuation lines. |
220 | This extra offset applies to the first of a set of continuation lines. | |
5e72c6b2 S |
221 | The following lines receive the same indentation as the first." |
222 | :group 'idlwave-code-formatting | |
223 | :type 'integer) | |
224 | ||
f66f03de | 225 | (defcustom idlwave-max-extra-continuation-indent 40 |
5e72c6b2 S |
226 | "*Maximum additional indentation for special continuation indent. |
227 | Several special indentations are tried to help line up continuation | |
228 | lines in routine calls or definitions, other statements with | |
134b6671 | 229 | parentheses, or assignment statements. This variable specifies a |
5e72c6b2 S |
230 | maximum amount by which this special indentation can exceed the |
231 | standard continuation indentation, otherwise defaulting to a fixed | |
232 | offset. Set to 0 to effectively disable all special continuation | |
233 | indentation, or to a large number (like 100) to enable it in all | |
52a244eb | 234 | cases. See also `idlwave-indent-to-open-paren', which can override |
5e72c6b2 | 235 | this variable." |
f32b3b91 CD |
236 | :group 'idlwave-code-formatting |
237 | :type 'integer) | |
238 | ||
5e72c6b2 S |
239 | (defcustom idlwave-indent-to-open-paren t |
240 | "*Non-nil means, indent continuation lines to innermost open | |
241 | parenthesis. This indentation occurs even if otherwise disallowed by | |
242 | `idlwave-max-extra-continuation-indent'. Matching parens and the | |
243 | interleaving args are lined up. Example: | |
244 | ||
245 | x = function_a(function_b(function_c( a, b, [1,2,3, $ | |
246 | 4,5,6 $ | |
247 | ], $ | |
248 | c, d $ | |
249 | ))) | |
250 | ||
251 | When this variable is nil, paren alignment may still occur, based on | |
252 | the value of `max-extra-continuation-indent', which, if zero, would | |
253 | yield: | |
254 | ||
255 | x = function_a(function_b(function_c( a, b, [1,2,3, $ | |
256 | 4,5,6 $ | |
257 | ], $ | |
258 | c, d $ | |
259 | )))" | |
260 | :group 'idlwave-code-formatting | |
261 | :type 'boolean) | |
262 | ||
52a244eb S |
263 | (defcustom idlwave-indent-parens-nested nil |
264 | "*Non-nil means, indent continuation lines with parens by nesting | |
265 | lines at consecutively deeper levels." | |
266 | :group 'idlwave-code-formatting | |
267 | :type 'boolean) | |
268 | ||
269 | ||
f32b3b91 CD |
270 | (defcustom idlwave-hanging-indent t |
271 | "*If set non-nil then comment paragraphs are indented under the | |
272 | hanging indent given by `idlwave-hang-indent-regexp' match in the first line | |
273 | of the paragraph." | |
274 | :group 'idlwave-code-formatting | |
275 | :type 'boolean) | |
276 | ||
277 | (defcustom idlwave-hang-indent-regexp "- " | |
278 | "*Regular expression matching the position of the hanging indent | |
279 | in the first line of a comment paragraph. The size of the indent | |
280 | extends to the end of the match for the regular expression." | |
281 | :group 'idlwave-code-formatting | |
282 | :type 'regexp) | |
283 | ||
284 | (defcustom idlwave-use-last-hang-indent nil | |
285 | "*If non-nil then use last match on line for `idlwave-indent-regexp'." | |
286 | :group 'idlwave-code-formatting | |
287 | :type 'boolean) | |
288 | ||
289 | (defcustom idlwave-fill-comment-line-only t | |
290 | "*If non-nil then auto fill will only operate on comment lines." | |
291 | :group 'idlwave-code-formatting | |
292 | :type 'boolean) | |
293 | ||
294 | (defcustom idlwave-auto-fill-split-string t | |
295 | "*If non-nil then auto fill will split strings with the IDL `+' operator. | |
4b1aaa8b PE |
296 | When the line end falls within a string, string concatenation with the |
297 | '+' operator will be used to distribute a long string over lines. | |
f32b3b91 CD |
298 | If nil and a string is split then a terminal beep and warning are issued. |
299 | ||
300 | This variable is ignored when `idlwave-fill-comment-line-only' is | |
301 | non-nil, since in this case code is not auto-filled." | |
302 | :group 'idlwave-code-formatting | |
303 | :type 'boolean) | |
304 | ||
305 | (defcustom idlwave-split-line-string t | |
306 | "*If non-nil then `idlwave-split-line' will split strings with `+'. | |
307 | When the splitting point of a line falls inside a string, split the string | |
308 | using the `+' string concatenation operator. If nil and a string is | |
309 | split then a terminal beep and warning are issued." | |
310 | :group 'idlwave-code-formatting | |
311 | :type 'boolean) | |
312 | ||
313 | (defcustom idlwave-no-change-comment ";;;" | |
314 | "*The indentation of a comment that starts with this regular | |
315 | expression will not be changed. Note that the indentation of a comment | |
316 | at the beginning of a line is never changed." | |
317 | :group 'idlwave-code-formatting | |
318 | :type 'string) | |
319 | ||
320 | (defcustom idlwave-begin-line-comment nil | |
321 | "*A comment anchored at the beginning of line. | |
322 | A comment matching this regular expression will not have its | |
323 | indentation changed. If nil the default is \"^;\", i.e., any line | |
324 | beginning with a \";\". Expressions for comments at the beginning of | |
325 | the line should begin with \"^\"." | |
326 | :group 'idlwave-code-formatting | |
327 | :type '(choice (const :tag "Any line beginning with `;'" nil) | |
328 | 'regexp)) | |
329 | ||
330 | (defcustom idlwave-code-comment ";;[^;]" | |
331 | "*A comment that starts with this regular expression on a line by | |
332 | itself is indented as if it is a part of IDL code. As a result if | |
333 | the comment is not preceded by whitespace it is unchanged." | |
334 | :group 'idlwave-code-formatting | |
335 | :type 'regexp) | |
336 | ||
337 | ;; Comments not matching any of the above will be indented as a | |
338 | ;; right-margin comment, i.e., to a minimum of `comment-column'. | |
339 | ||
f32b3b91 CD |
340 | ;;; Routine Info and Completion --------------------------------------- |
341 | ||
15e42531 CD |
342 | (defgroup idlwave-routine-info nil |
343 | "Routine Info options for IDLWAVE mode." | |
f32b3b91 CD |
344 | :group 'idlwave) |
345 | ||
52a244eb S |
346 | (defcustom idlwave-use-library-catalogs t |
347 | "*Non-nil means search the IDL path for library catalog files. | |
348 | ||
349 | These files, named .idlwave_catalog, document routine information for | |
350 | individual directories and libraries of IDL .pro files. Many popular | |
351 | libraries come with catalog files by default, so leaving this on is a | |
352 | usually a good idea.." | |
353 | :group 'idlwave-routine-info | |
354 | :type 'boolean) | |
5e72c6b2 S |
355 | |
356 | (defcustom idlwave-init-rinfo-when-idle-after 10 | |
f66f03de S |
357 | "*Seconds of idle time before routine info is automatically |
358 | initialized. Initializing the routine info can take a long time, in | |
359 | particular if a large number of library catalogs are involved. When | |
360 | Emacs is idle for more than the number of seconds specified by this | |
361 | variable, it starts the initialization. The process is split into | |
362 | five steps, in order to keep work interruption as short as possible. | |
363 | If one of the steps finishes, and no user input has arrived in the | |
364 | mean time, initialization proceeds immediately to the next step. A | |
365 | good value for this variable is about 1/3 of the time initialization | |
366 | take in your setup. So if you have a fast machine and no problems | |
367 | with a slow network connection, don't hesitate to set this to 2 | |
368 | seconds. A Value of 0 means, don't initialize automatically, but | |
369 | instead wait until routine information is needed, and initialize | |
370 | then." | |
5e72c6b2 S |
371 | :group 'idlwave-routine-info |
372 | :type 'number) | |
373 | ||
f32b3b91 | 374 | (defcustom idlwave-scan-all-buffers-for-routine-info t |
15e42531 CD |
375 | "*Non-nil means, scan buffers for IDL programs when updating info. |
376 | The scanning is done by the command `idlwave-update-routine-info'. | |
377 | The following values are allowed: | |
378 | ||
379 | nil Don't scan any buffers. | |
380 | t Scan all idlwave-mode buffers in the current editing session. | |
381 | current Scan only the current buffer, but no other buffers." | |
382 | :group 'idlwave-routine-info | |
383 | :type '(choice | |
384 | (const :tag "No buffer" nil) | |
385 | (const :tag "All buffers" t) | |
386 | (const :tag "Current buffer only" 'current))) | |
f32b3b91 CD |
387 | |
388 | (defcustom idlwave-query-shell-for-routine-info t | |
389 | "*Non-nil means query the shell for info about compiled routines. | |
390 | Querying the shell is useful to get information about compiled modules, | |
391 | and it is turned on by default. However, when you have a complete library | |
392 | scan, this is not necessary." | |
15e42531 | 393 | :group 'idlwave-routine-info |
f32b3b91 CD |
394 | :type 'boolean) |
395 | ||
15e42531 CD |
396 | (defcustom idlwave-auto-routine-info-updates |
397 | '(find-file save-buffer kill-buffer compile-buffer) | |
398 | "*Controls under what circumstances routine info is updated automatically. | |
399 | Possible values: | |
400 | nil Never | |
401 | t All available | |
facebc7b | 402 | \(...) A list of circumstances. Allowed members are: |
15e42531 CD |
403 | find-file Add info for new IDLWAVE buffers. |
404 | save-buffer Update buffer info when buffer is saved | |
405 | kill-buffer Remove buffer info when buffer gets killed | |
406 | compile-buffer Update shell info after `idlwave-shell-save-and...'" | |
407 | :group 'idlwave-routine-info | |
408 | :type '(choice | |
409 | (const :tag "Never" nil) | |
410 | (const :tag "As often as possible" t) | |
411 | (set :tag "Checklist" :greedy t | |
412 | (const :tag "When visiting a file" find-file) | |
413 | (const :tag "When saving a buffer" save-buffer) | |
414 | (const :tag "After a buffer was killed" kill-buffer) | |
415 | (const :tag "After a buffer was compiled successfully, update shell info" compile-buffer)))) | |
4b1aaa8b | 416 | |
15e42531 CD |
417 | (defcustom idlwave-rinfo-max-source-lines 5 |
418 | "*Maximum number of source files displayed in the Routine Info window. | |
419 | When an integer, it is the maximum number of source files displayed. | |
420 | t means to show all source files." | |
421 | :group 'idlwave-routine-info | |
422 | :type 'integer) | |
423 | ||
f32b3b91 | 424 | (defcustom idlwave-library-path nil |
8c43762b | 425 | "Library path for Windows and MacOS (OS9). Not needed under UNIX. |
f66f03de S |
426 | When selecting the directories to scan for IDL user catalog routine |
427 | info, IDLWAVE can, under UNIX, query the shell for the exact search | |
428 | path \(the value of !PATH). However, under Windows and MacOS | |
8c43762b | 429 | \(pre-OSX), the IDLWAVE shell does not work. In this case, this |
f66f03de S |
430 | variable can be set to specify the paths where IDLWAVE can find PRO |
431 | files. The shell will only be asked for a list of paths when this | |
432 | variable is nil. The value is a list of directories. A directory | |
433 | preceeded by a `+' will be searched recursively. If you set this | |
434 | variable on a UNIX system, the shell will not be queried. See also | |
435 | `idlwave-system-directory'." | |
15e42531 | 436 | :group 'idlwave-routine-info |
f32b3b91 CD |
437 | :type '(repeat (directory))) |
438 | ||
15e42531 | 439 | (defcustom idlwave-system-directory "" |
52a244eb S |
440 | "The IDL system directory for Windows and MacOS. Not needed under |
441 | UNIX. Set this to the value of the `!DIR' system variable in IDL. | |
442 | IDLWAVE uses this to find out which of the library routines belong to | |
443 | the official system library. All files inside the `lib' subdirectory | |
444 | are considered system library files - so don't install private stuff | |
445 | in this directory. On UNIX systems, IDLWAVE queries the shell for the | |
446 | value of `!DIR'. See also `idlwave-library-path'." | |
15e42531 CD |
447 | :group 'idlwave-routine-info |
448 | :type 'directory) | |
449 | ||
f66f03de | 450 | ;; Configuration files |
4b1aaa8b | 451 | (defcustom idlwave-config-directory |
52a244eb S |
452 | (convert-standard-filename "~/.idlwave") |
453 | "*Directory for configuration files and user-library catalog." | |
15e42531 | 454 | :group 'idlwave-routine-info |
f32b3b91 CD |
455 | :type 'file) |
456 | ||
52a244eb | 457 | (defvar idlwave-user-catalog-file "idlusercat.el") |
f66f03de | 458 | (defvar idlwave-xml-system-rinfo-converted-file "idl_xml_rinfo.el") |
52a244eb S |
459 | (defvar idlwave-path-file "idlpath.el") |
460 | ||
461 | (defvar idlwave-libinfo-file nil | |
462 | "*Obsolete variable, no longer used.") | |
463 | ||
15e42531 CD |
464 | (defcustom idlwave-special-lib-alist nil |
465 | "Alist of regular expressions matching special library directories. | |
466 | When listing routine source locations, IDLWAVE gives a short hint where | |
4b1aaa8b | 467 | the file defining the routine is located. By default it lists `SystemLib' |
15e42531 CD |
468 | for routines in the system library `!DIR/lib' and `Library' for anything |
469 | else. This variable can define additional types. The car of each entry | |
470 | is a regular expression matching the file name (they normally will match | |
471 | on the path). The cdr is the string to be used as identifier. Max 10 | |
472 | chars are allowed." | |
473 | :group 'idlwave-routine-info | |
474 | :type '(repeat | |
475 | (cons regexp string))) | |
476 | ||
52a244eb | 477 | (defcustom idlwave-auto-write-paths t |
4b1aaa8b | 478 | "Write out path (!PATH) and system directory (!DIR) info automatically. |
52a244eb S |
479 | Path info is needed to locate library catalog files. If non-nil, |
480 | whenever the path-list changes as a result of shell-query, etc., it is | |
481 | written to file. Otherwise, the menu option \"Write Paths\" can be | |
482 | used to force a write." | |
483 | :group 'idlwave-routine-info | |
05a1abfc | 484 | :type 'boolean) |
775591f7 | 485 | |
15e42531 CD |
486 | (defgroup idlwave-completion nil |
487 | "Completion options for IDLWAVE mode." | |
488 | :prefix "idlwave" | |
489 | :group 'idlwave) | |
490 | ||
f32b3b91 CD |
491 | (eval-and-compile |
492 | (defconst idlwave-tmp | |
493 | '(choice :tag "by applying the function" | |
494 | (const upcase) | |
495 | (const downcase) | |
496 | (const capitalize) | |
497 | (const preserve) | |
498 | (symbol :tag "Other")))) | |
499 | ||
f32b3b91 CD |
500 | (defcustom idlwave-completion-case '((routine . upcase) |
501 | (keyword . upcase) | |
502 | (class . preserve) | |
503 | (method . preserve)) | |
504 | "Association list setting the case of completed words. | |
505 | ||
506 | This variable determines the case (UPPER/lower/Capitalized...) of | |
507 | words inserted into the buffer by completion. The preferred case can | |
508 | be specified separately for routine names, keywords, classes and | |
4b1aaa8b | 509 | methods. |
f32b3b91 CD |
510 | This alist should therefore have entries for `routine' (normal |
511 | functions and procedures, i.e. non-methods), `keyword', `class', and | |
512 | `method'. Plausible values are | |
513 | ||
514 | upcase upcase whole word, like `BOX_CURSOR' | |
515 | downcase downcase whole word, like `read_ppm' | |
516 | capitalize capitalize each part, like `Widget_Control' | |
517 | preserve preserve case as is, like `IDLgrView' | |
518 | ||
519 | The value can also be any Emacs Lisp function which transforms the | |
520 | case of characters in a string. | |
521 | ||
522 | A value of `preserve' means that the case of the completed word is | |
523 | identical to the way it was written in the definition statement of the | |
524 | routine. This was implemented to allow for mixed-case completion, in | |
525 | particular of object classes and methods. | |
526 | If a completable word is defined in multiple locations, the meaning of | |
527 | `preserve' is not unique since the different definitions might be | |
528 | cased differently. Therefore IDLWAVE always takes the case of the | |
529 | *first* definition it encounters during routine info collection and | |
530 | uses the case derived from it consistently. | |
531 | ||
532 | Note that a lowercase-only string in the buffer will always be completed in | |
533 | lower case (but see the variable `idlwave-completion-force-default-case'). | |
534 | ||
535 | After changing this variable, you need to either restart Emacs or press | |
536 | `C-u C-c C-i' to update the internal lists." | |
15e42531 | 537 | :group 'idlwave-completion |
f32b3b91 CD |
538 | :type `(repeat |
539 | (cons (symbol :tag "Derive completion case for") | |
540 | ,idlwave-tmp))) | |
541 | ||
542 | (defcustom idlwave-completion-force-default-case nil | |
543 | "*Non-nil means, completion will always honor `idlwave-completion-case'. | |
544 | When nil, only the completion of a mixed case or upper case string | |
545 | will honor the default settings in `idlwave-completion-case', while | |
546 | the completion of lower case strings will be completed entirely in | |
547 | lower case." | |
15e42531 | 548 | :group 'idlwave-completion |
f32b3b91 CD |
549 | :type 'boolean) |
550 | ||
551 | (defcustom idlwave-complete-empty-string-as-lower-case nil | |
552 | "*Non-nil means, the empty string is considered downcase for completion. | |
553 | The case of what is already in the buffer determines the case of completions. | |
554 | When this variable is non-nil, the empty string is considered to be downcase. | |
555 | Completing on the empty string then offers downcase versions of the possible | |
556 | completions." | |
15e42531 | 557 | :group 'idlwave-completion |
f32b3b91 CD |
558 | :type 'boolean) |
559 | ||
560 | (defvar idlwave-default-completion-case-is-down nil | |
561 | "Obsolete variable. See `idlwave-complete-empty-string-as-lower-case' and | |
562 | `idlwave-completion-case'.") | |
563 | ||
564 | (defcustom idlwave-buffer-case-takes-precedence nil | |
565 | "*Non-nil means, the case of tokens in buffers dominates over system stuff. | |
566 | To make this possible, we need to re-case everything each time we update | |
567 | the routine info from the buffers. This is slow. | |
568 | The default is to consider the case given in the system and library files | |
569 | first which makes updating much faster." | |
15e42531 CD |
570 | :group 'idlwave-completion |
571 | :type 'boolean) | |
572 | ||
573 | (defcustom idlwave-highlight-help-links-in-completion t | |
574 | "*Non-nil means, highlight completions for which system help is available. | |
575 | Help can then be accessed with mouse-3. | |
576 | This option is only effective when the online help system is installed." | |
577 | :group 'idlwave-completion | |
f32b3b91 CD |
578 | :type 'boolean) |
579 | ||
05a1abfc CD |
580 | (defcustom idlwave-support-inheritance t |
581 | "Non-nil means, treat inheritance with completion, online help etc. | |
cef6cafe | 582 | When nil, IDLWAVE only knows about the native methods and tags of a class, |
05a1abfc CD |
583 | not about inherited ones." |
584 | :group 'idlwave-routine-info | |
585 | :type 'boolean) | |
586 | ||
5e72c6b2 S |
587 | (defcustom idlwave-keyword-class-inheritance '("^[gs]etproperty$" "^init$") |
588 | "List of regular expressions for class-driven keyword inheritance. | |
589 | Keyword inheritance is often tied to class inheritance by \"chaining\" | |
590 | up the class tree. While it cannot be assumed that the presence of an | |
591 | _EXTRA or _REF_EXTRA symbol guarantees such chaining will occur, for | |
592 | certain methods this assumption is almost always true. The methods | |
593 | for which to assume this can be set here." | |
594 | :group 'idlwave-routine-info | |
595 | :type '(repeat (regexp :tag "Match method:"))) | |
4b1aaa8b | 596 | |
5e72c6b2 | 597 | |
f32b3b91 CD |
598 | (defcustom idlwave-completion-show-classes 1 |
599 | "*Number of classes to show when completing object methods and keywords. | |
600 | When completing methods or keywords for an object with unknown class, | |
2e8b9c7d | 601 | the *Completions* buffer will show the valid classes for each completion |
f32b3b91 CD |
602 | like this: |
603 | ||
604 | MyMethod <Class1,Class2,Class3> | |
605 | ||
606 | The value of this variable may be nil to inhibit display, or an integer to | |
607 | indicate the maximum number of classes to display. | |
608 | ||
609 | On XEmacs, a full list of classes will also be placed into a `help-echo' | |
610 | property on the competion items, so that the list of classes for the current | |
611 | item is displayed in the echo area. If the value of this variable is a | |
612 | negative integer, the `help-echo' property will be suppressed." | |
15e42531 | 613 | :group 'idlwave-completion |
f32b3b91 CD |
614 | :type '(choice (const :tag "Don't show" nil) |
615 | (integer :tag "Number of classes shown" 1))) | |
616 | ||
617 | (defcustom idlwave-completion-fontify-classes t | |
618 | "*Non-nil means, fontify the classes in completions buffer. | |
619 | This makes it easier to distinguish the completion items from the extra | |
620 | class info listed. See `idlwave-completion-show-classes'." | |
15e42531 | 621 | :group 'idlwave-completion |
f32b3b91 CD |
622 | :type 'boolean) |
623 | ||
624 | (defcustom idlwave-query-class '((method-default . nil) | |
625 | (keyword-default . nil)) | |
626 | "Association list governing specification of object classes for completion. | |
627 | ||
5e72c6b2 S |
628 | When IDLWAVE tries to complete object-oriented methods, it usually |
629 | cannot determine the class of a given object from context. In order | |
630 | to provide the user with a correct list of methods or keywords, it | |
76959b77 S |
631 | needs to determine the appropriate class. IDLWAVE has two ways of |
632 | doing this (well, three ways if you count the shell... see | |
633 | `idlwave-shell-query-for-class'): | |
634 | ||
635 | 1. Combine the items of all available classes which contain this | |
636 | method for the purpose of completion. So when completing a method, | |
637 | all methods of all known classes are available, and when completing | |
638 | a keyword, all keywords allowed for this method in any class are | |
639 | shown. This behavior is very much like normal completion and is | |
640 | therefore the default. It works much better than one might think - | |
641 | only for the INIT, GETPROPERTY and SETPROPERTY the keyword lists | |
642 | become uncomfortably long. See also | |
5e72c6b2 | 643 | `idlwave-completion-show-classes'. |
f32b3b91 CD |
644 | |
645 | 2. The second possibility is to ask the user on each occasion. To | |
646 | make this less interruptive, IDLWAVE can store the class as a text | |
647 | property on the object operator `->'. For a given object in the | |
648 | source code, class selection will then be needed only once | |
649 | - for example to complete the method. Keywords to the method can | |
650 | then be completed directly, because the class is already known. | |
651 | You will have to turn on the storage of the selected class | |
652 | explicitly with the variable `idlwave-store-inquired-class'. | |
653 | ||
5e72c6b2 S |
654 | This variable allows you to configure IDLWAVE's method and |
655 | method-keyword completion behavior. Its value is an alist, which | |
656 | should contain at least two elements: (method-default . VALUE) and | |
facebc7b | 657 | \(keyword-default . VALUE), where VALUE is either t or nil. These |
5e72c6b2 S |
658 | specify if the class should be found during method and keyword |
659 | completion, respectively. | |
f32b3b91 | 660 | |
4b1aaa8b | 661 | The alist may have additional entries specifying exceptions from the |
f32b3b91 CD |
662 | keyword completion rule for specific methods, like INIT or |
663 | GETPROPERTY. In order to turn on class specification for the INIT | |
664 | method, add an entry (\"INIT\" . t). The method name must be ALL-CAPS." | |
15e42531 | 665 | :group 'idlwave-completion |
f32b3b91 CD |
666 | :type '(list |
667 | (cons (const method-default) | |
668 | (boolean :tag "Determine class when completing METHODS ")) | |
669 | (cons (const keyword-default) | |
670 | (boolean :tag "Determine class when completing KEYWORDS ")) | |
671 | (repeat | |
672 | :tag "Exceptions to defaults" | |
673 | :inline t | |
674 | (cons (string :tag "MODULE" :value "") | |
675 | (boolean :tag "Determine class for this method"))))) | |
676 | ||
f66f03de | 677 | (defcustom idlwave-store-inquired-class t |
f32b3b91 CD |
678 | "*Non-nil means, store class of a method call as text property on `->'. |
679 | IDLWAVE sometimes has to ask the user for the class associated with a | |
680 | particular object method call. This happens during the commands | |
681 | `idlwave-routine-info' and `idlwave-complete', depending upon the | |
682 | value of the variable `idlwave-query-class'. | |
683 | ||
684 | When you specify a class, this information can be stored as a text | |
4b1aaa8b | 685 | property on the `->' arrow in the source code, so that during the same |
f32b3b91 CD |
686 | editing session, IDLWAVE will not have to ask again. When this |
687 | variable is non-nil, IDLWAVE will store and reuse the class information. | |
688 | The class stored can be checked and removed with `\\[idlwave-routine-info]' | |
689 | on the arrow. | |
690 | ||
691 | The default of this variable is nil, since the result of commands then | |
692 | is more predictable. However, if you know what you are doing, it can | |
693 | be nice to turn this on. | |
694 | ||
695 | An arrow which knows the class will be highlighted with | |
696 | `idlwave-class-arrow-face'. The command \\[idlwave-routine-info] | |
697 | displays (with prefix arg: deletes) the class stored on the arrow | |
698 | at point." | |
15e42531 | 699 | :group 'idlwave-completion |
f32b3b91 CD |
700 | :type 'boolean) |
701 | ||
702 | (defcustom idlwave-class-arrow-face 'bold | |
703 | "*Face to highlight object operator arrows `->' which carry a class property. | |
704 | When IDLWAVE stores a class name as text property on an object arrow | |
facebc7b | 705 | \(see variable `idlwave-store-inquired-class', it highlights the arrow |
f32b3b91 | 706 | with this font in order to remind the user that this arrow is special." |
15e42531 | 707 | :group 'idlwave-completion |
f32b3b91 CD |
708 | :type 'symbol) |
709 | ||
710 | (defcustom idlwave-resize-routine-help-window t | |
711 | "*Non-nil means, resize the Routine-info *Help* window to fit the content." | |
15e42531 | 712 | :group 'idlwave-completion |
f32b3b91 CD |
713 | :type 'boolean) |
714 | ||
715 | (defcustom idlwave-keyword-completion-adds-equal t | |
716 | "*Non-nil means, completion automatically adds `=' after completed keywords." | |
15e42531 | 717 | :group 'idlwave-completion |
f32b3b91 CD |
718 | :type 'boolean) |
719 | ||
720 | (defcustom idlwave-function-completion-adds-paren t | |
721 | "*Non-nil means, completion automatically adds `(' after completed function. | |
0ff9b955 | 722 | nil means, don't add anything. |
f32b3b91 CD |
723 | A value of `2' means, also add the closing parenthesis and position cursor |
724 | between the two." | |
15e42531 | 725 | :group 'idlwave-completion |
f32b3b91 CD |
726 | :type '(choice (const :tag "Nothing" nil) |
727 | (const :tag "(" t) | |
728 | (const :tag "()" 2))) | |
729 | ||
730 | (defcustom idlwave-completion-restore-window-configuration t | |
731 | "*Non-nil means, try to restore the window configuration after completion. | |
732 | When completion is not unique, Emacs displays a list of completions. | |
733 | This messes up your window configuration. With this variable set, IDLWAVE | |
734 | restores the old configuration after successful completion." | |
15e42531 | 735 | :group 'idlwave-completion |
f32b3b91 CD |
736 | :type 'boolean) |
737 | ||
738 | ;;; Variables for abbrev and action behavior ----------------------------- | |
739 | ||
740 | (defgroup idlwave-abbrev-and-indent-action nil | |
741 | "IDLWAVE performs actions when expanding abbreviations or indenting lines. | |
742 | The variables in this group govern this." | |
743 | :group 'idlwave) | |
744 | ||
745 | (defcustom idlwave-do-actions nil | |
746 | "*Non-nil means performs actions when indenting. | |
747 | The actions that can be performed are listed in `idlwave-indent-action-table'." | |
748 | :group 'idlwave-abbrev-and-indent-action | |
749 | :type 'boolean) | |
750 | ||
751 | (defcustom idlwave-abbrev-start-char "\\" | |
752 | "*A single character string used to start abbreviations in abbrev mode. | |
753 | Possible characters to chose from: ~`\% | |
754 | or even '?'. '.' is not a good choice because it can make structure | |
755 | field names act like abbrevs in certain circumstances. | |
756 | ||
757 | Changes to this in `idlwave-mode-hook' will have no effect. Instead a user | |
758 | must set it directly using `setq' in the .emacs file before idlwave.el | |
759 | is loaded." | |
760 | :group 'idlwave-abbrev-and-indent-action | |
761 | :type 'string) | |
762 | ||
763 | (defcustom idlwave-surround-by-blank nil | |
764 | "*Non-nil means, enable `idlwave-surround'. | |
595ab50b | 765 | If non-nil, `=',`<',`>',`&',`,', `->' are surrounded with spaces by |
f32b3b91 CD |
766 | `idlwave-surround'. |
767 | See help for `idlwave-indent-action-table' for symbols using `idlwave-surround'. | |
768 | ||
769 | Also see the default key bindings for keys using `idlwave-surround'. | |
770 | Keys are bound and made into actions calling `idlwave-surround' with | |
771 | `idlwave-action-and-binding'. | |
772 | See help for `idlwave-action-and-binding' for examples. | |
773 | ||
774 | Also see help for `idlwave-surround'." | |
775 | :group 'idlwave-abbrev-and-indent-action | |
776 | :type 'boolean) | |
777 | ||
778 | (defcustom idlwave-pad-keyword t | |
52a244eb S |
779 | "*Non-nil means pad '=' in keywords (routine calls or defs) like assignment. |
780 | Whenever `idlwave-surround' is non-nil then this affects how '=' is | |
781 | padded for keywords and for variables. If t, pad the same as for | |
782 | assignments. If nil then spaces are removed. With any other value, | |
783 | spaces are left unchanged." | |
f32b3b91 | 784 | :group 'idlwave-abbrev-and-indent-action |
15e42531 CD |
785 | :type '(choice |
786 | (const :tag "Pad like assignments" t) | |
787 | (const :tag "Remove space near `='" nil) | |
788 | (const :tag "Keep space near `='" 'keep))) | |
f32b3b91 CD |
789 | |
790 | (defcustom idlwave-show-block t | |
791 | "*Non-nil means point blinks to block beginning for `idlwave-show-begin'." | |
792 | :group 'idlwave-abbrev-and-indent-action | |
793 | :type 'boolean) | |
794 | ||
795 | (defcustom idlwave-expand-generic-end nil | |
796 | "*Non-nil means expand generic END to ENDIF/ENDELSE/ENDWHILE etc." | |
797 | :group 'idlwave-abbrev-and-indent-action | |
798 | :type 'boolean) | |
799 | ||
15e42531 CD |
800 | (defcustom idlwave-reindent-end t |
801 | "*Non-nil means re-indent line after END was typed." | |
802 | :group 'idlwave-abbrev-and-indent-action | |
803 | :type 'boolean) | |
804 | ||
f32b3b91 CD |
805 | (defcustom idlwave-abbrev-move t |
806 | "*Non-nil means the abbrev hook can move point. | |
807 | Set to nil by `idlwave-expand-region-abbrevs'. To see the abbrev | |
808 | definitions, use the command `list-abbrevs', for abbrevs that move | |
809 | point. Moving point is useful, for example, to place point between | |
810 | parentheses of expanded functions. | |
811 | ||
812 | See `idlwave-check-abbrev'." | |
813 | :group 'idlwave-abbrev-and-indent-action | |
814 | :type 'boolean) | |
815 | ||
816 | (defcustom idlwave-abbrev-change-case nil | |
817 | "*Non-nil means all abbrevs will be forced to either upper or lower case. | |
818 | If the value t, all expanded abbrevs will be upper case. | |
819 | If the value is 'down then abbrevs will be forced to lower case. | |
820 | If nil, the case will not change. | |
821 | If `idlwave-reserved-word-upcase' is non-nil, reserved words will always be | |
822 | upper case, regardless of this variable." | |
823 | :group 'idlwave-abbrev-and-indent-action | |
824 | :type 'boolean) | |
825 | ||
826 | (defcustom idlwave-reserved-word-upcase nil | |
827 | "*Non-nil means, reserved words will be made upper case via abbrev expansion. | |
828 | If nil case of reserved words is controlled by `idlwave-abbrev-change-case'. | |
829 | Has effect only if in abbrev-mode." | |
830 | :group 'idlwave-abbrev-and-indent-action | |
831 | :type 'boolean) | |
832 | ||
833 | ;;; Action/Expand Tables. | |
834 | ;; | |
835 | ;; The average user may have difficulty modifying this directly. It | |
836 | ;; can be modified/set in idlwave-mode-hook, but it is easier to use | |
837 | ;; idlwave-action-and-binding. See help for idlwave-action-and-binding for | |
838 | ;; examples of how to add an action. | |
839 | ;; | |
840 | ;; The action table is used by `idlwave-indent-line' whereas both the | |
841 | ;; action and expand tables are used by `idlwave-indent-and-action'. In | |
842 | ;; general, the expand table is only used when a line is explicitly | |
843 | ;; indented. Whereas, in addition to being used when the expand table | |
844 | ;; is used, the action table is used when a line is indirectly | |
845 | ;; indented via line splitting, auto-filling or a new line creation. | |
846 | ;; | |
847 | ;; Example actions: | |
848 | ;; | |
849 | ;; Capitalize system vars | |
850 | ;; (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t) | |
851 | ;; | |
852 | ;; Capitalize procedure name | |
853 | ;; (idlwave-action-and-binding "\\<\\(pro\\|function\\)\\>[ \t]*\\<" | |
854 | ;; '(capitalize-word 1) t) | |
855 | ;; | |
856 | ;; Capitalize common block name | |
857 | ;; (idlwave-action-and-binding "\\<common\\>[ \t]+\\<" | |
858 | ;; '(capitalize-word 1) t) | |
859 | ;; Capitalize label | |
860 | ;; (idlwave-action-and-binding (concat "^[ \t]*" idlwave-label) | |
861 | ;; '(capitalize-word -1) t) | |
862 | ||
863 | (defvar idlwave-indent-action-table nil | |
864 | "*Associated array containing action lists of search string (car), | |
865 | and function as a cdr. This table is used by `idlwave-indent-line'. | |
866 | See documentation for `idlwave-do-action' for a complete description of | |
867 | the action lists. | |
868 | ||
869 | Additions to the table are made with `idlwave-action-and-binding' when a | |
870 | binding is not requested. | |
871 | See help on `idlwave-action-and-binding' for examples.") | |
872 | ||
873 | (defvar idlwave-indent-expand-table nil | |
874 | "*Associated array containing action lists of search string (car), | |
875 | and function as a cdr. The table is used by the | |
876 | `idlwave-indent-and-action' function. See documentation for | |
877 | `idlwave-do-action' for a complete description of the action lists. | |
878 | ||
879 | Additions to the table are made with `idlwave-action-and-binding' when a | |
880 | binding is requested. | |
881 | See help on `idlwave-action-and-binding' for examples.") | |
882 | ||
883 | ;;; Documentation header and history keyword --------------------------------- | |
884 | ||
885 | (defgroup idlwave-documentation nil | |
886 | "Options for documenting IDLWAVE files." | |
887 | :group 'idlwave) | |
888 | ||
889 | ;; FIXME: make defcustom? | |
890 | (defvar idlwave-file-header | |
891 | (list nil | |
892 | ";+ | |
893 | ; NAME: | |
894 | ; | |
895 | ; | |
896 | ; | |
897 | ; PURPOSE: | |
898 | ; | |
899 | ; | |
900 | ; | |
901 | ; CATEGORY: | |
902 | ; | |
903 | ; | |
904 | ; | |
905 | ; CALLING SEQUENCE: | |
906 | ; | |
907 | ; | |
908 | ; | |
909 | ; INPUTS: | |
910 | ; | |
911 | ; | |
912 | ; | |
913 | ; OPTIONAL INPUTS: | |
914 | ; | |
915 | ; | |
916 | ; | |
917 | ; KEYWORD PARAMETERS: | |
918 | ; | |
919 | ; | |
920 | ; | |
921 | ; OUTPUTS: | |
922 | ; | |
923 | ; | |
924 | ; | |
925 | ; OPTIONAL OUTPUTS: | |
926 | ; | |
927 | ; | |
928 | ; | |
929 | ; COMMON BLOCKS: | |
930 | ; | |
931 | ; | |
932 | ; | |
933 | ; SIDE EFFECTS: | |
934 | ; | |
935 | ; | |
936 | ; | |
937 | ; RESTRICTIONS: | |
938 | ; | |
939 | ; | |
940 | ; | |
941 | ; PROCEDURE: | |
942 | ; | |
943 | ; | |
944 | ; | |
945 | ; EXAMPLE: | |
946 | ; | |
947 | ; | |
948 | ; | |
949 | ; MODIFICATION HISTORY: | |
950 | ; | |
951 | ;- | |
952 | ") | |
953 | "*A list (PATHNAME STRING) specifying the doc-header template to use for | |
954 | summarizing a file. If PATHNAME is non-nil then this file will be included. | |
0ff9b955 | 955 | Otherwise STRING is used. If nil, the file summary will be omitted. |
f32b3b91 CD |
956 | For example you might set PATHNAME to the path for the |
957 | lib_template.pro file included in the IDL distribution.") | |
958 | ||
f66f03de | 959 | (defcustom idlwave-header-to-beginning-of-file t |
5e72c6b2 S |
960 | "*Non-nil means, the documentation header will always be at start of file. |
961 | When nil, the header is positioned between the PRO/FUNCTION line of | |
962 | the current routine and the code, allowing several routine headers in | |
963 | a file." | |
964 | :group 'idlwave-documentation | |
965 | :type 'boolean) | |
966 | ||
f32b3b91 CD |
967 | (defcustom idlwave-timestamp-hook 'idlwave-default-insert-timestamp |
968 | "*The hook function used to update the timestamp of a function." | |
969 | :group 'idlwave-documentation | |
970 | :type 'function) | |
971 | ||
972 | (defcustom idlwave-doc-modifications-keyword "HISTORY" | |
973 | "*The modifications keyword to use with the log documentation commands. | |
974 | A ':' is added to the keyword end. | |
975 | Inserted by doc-header and used to position logs by doc-modification. | |
976 | If nil it will not be inserted." | |
977 | :group 'idlwave-documentation | |
978 | :type 'string) | |
979 | ||
980 | (defcustom idlwave-doclib-start "^;+\\+" | |
981 | "*Regexp matching the start of a document library header." | |
982 | :group 'idlwave-documentation | |
983 | :type 'regexp) | |
984 | ||
985 | (defcustom idlwave-doclib-end "^;+-" | |
986 | "*Regexp matching the end of a document library header." | |
987 | :group 'idlwave-documentation | |
988 | :type 'regexp) | |
989 | ||
990 | ;;; External Programs ------------------------------------------------------- | |
991 | ||
992 | (defgroup idlwave-external-programs nil | |
05a1abfc | 993 | "Path locations of external commands used by IDLWAVE." |
f32b3b91 CD |
994 | :group 'idlwave) |
995 | ||
f32b3b91 | 996 | (defcustom idlwave-shell-explicit-file-name "idl" |
5e72c6b2 | 997 | "*If non-nil, this is the command to run IDL. |
f32b3b91 | 998 | Should be an absolute file path or path relative to the current environment |
5e72c6b2 S |
999 | execution search path. If you want to specify command line switches |
1000 | for the idl program, use `idlwave-shell-command-line-options'. | |
1001 | ||
1002 | I know the name of this variable is badly chosen, but I cannot change | |
1003 | it without compromizing backwards-compatibility." | |
f32b3b91 CD |
1004 | :group 'idlwave-external-programs |
1005 | :type 'string) | |
1006 | ||
f32b3b91 | 1007 | (defcustom idlwave-shell-command-line-options nil |
5e72c6b2 S |
1008 | "*A list of command line options for calling the IDL program. |
1009 | Since IDL is executed directly without going through a shell like /bin/sh, | |
1010 | this should be a list of strings like '(\"-rt=file\" \"-nw\") with a separate | |
1011 | string for each argument. But you may also give a single string which | |
1012 | contains the options whitespace-separated. Emacs will be kind enough to | |
1013 | split it for you." | |
1014 | :type '(choice | |
1015 | string | |
1016 | (repeat (string :value ""))) | |
f32b3b91 CD |
1017 | :group 'idlwave-external-programs) |
1018 | ||
1019 | (defcustom idlwave-help-application "idlhelp" | |
f66f03de S |
1020 | "*The external application providing reference help for programming. |
1021 | Obsolete, if the IDL Assistant is being used for help." | |
f32b3b91 CD |
1022 | :group 'idlwave-external-programs |
1023 | :type 'string) | |
1024 | ||
05a1abfc CD |
1025 | ;;; Some Shell variables which must be defined here.----------------------- |
1026 | ||
1027 | (defcustom idlwave-shell-debug-modifiers '() | |
1028 | "List of modifiers to be used for the debugging commands. | |
1029 | Will be used to bind debugging commands in the shell buffer and in all | |
1030 | source buffers. These are additional convenience bindings, the debugging | |
1031 | commands are always available with the `C-c C-d' prefix. | |
1032 | If you set this to '(control shift), this means setting a breakpoint will | |
1033 | be on `C-S-b', compiling a source file on `C-S-c' etc. Possible modifiers | |
1034 | are `control', `meta', `super', `hyper', `alt', and `shift'." | |
1035 | :group 'idlwave-shell-general-setup | |
1036 | :type '(set :tag "Specify modifiers" | |
1037 | (const control) | |
1038 | (const meta) | |
1039 | (const super) | |
1040 | (const hyper) | |
1041 | (const alt) | |
1042 | (const shift))) | |
1043 | ||
1044 | (defcustom idlwave-shell-automatic-start nil | |
1045 | "*If non-nil attempt invoke idlwave-shell if not already running. | |
1046 | This is checked when an attempt to send a command to an | |
1047 | IDL process is made." | |
1048 | :group 'idlwave-shell-general-setup | |
1049 | :type 'boolean) | |
1050 | ||
f32b3b91 CD |
1051 | ;;; Miscellaneous variables ------------------------------------------------- |
1052 | ||
1053 | (defgroup idlwave-misc nil | |
1054 | "Miscellaneous options for IDLWAVE mode." | |
8ec3bce0 | 1055 | :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces) |
f32b3b91 CD |
1056 | :group 'idlwave) |
1057 | ||
1058 | (defcustom idlwave-startup-message t | |
1059 | "*Non-nil displays a startup message when `idlwave-mode' is first called." | |
1060 | :group 'idlwave-misc | |
1061 | :type 'boolean) | |
1062 | ||
4b1aaa8b | 1063 | (defcustom idlwave-default-font-lock-items |
facebc7b | 1064 | '(pros-and-functions batch-files idlwave-idl-keywords label goto |
f32b3b91 CD |
1065 | common-blocks class-arrows) |
1066 | "Items which should be fontified on the default fontification level 2. | |
1067 | IDLWAVE defines 3 levels of fontification. Level 1 is very little, level 3 | |
1068 | is everything and level 2 is specified by this list. | |
1069 | This variable must be set before IDLWAVE gets loaded. It is | |
1070 | a list of symbols, the following symbols are allowed. | |
1071 | ||
1072 | pros-and-functions Procedure and Function definitions | |
1073 | batch-files Batch Files | |
facebc7b | 1074 | idlwave-idl-keywords IDL Keywords |
f32b3b91 CD |
1075 | label Statement Labels |
1076 | goto Goto Statements | |
1077 | common-blocks Common Blocks | |
1078 | keyword-parameters Keyword Parameters in routine definitions and calls | |
1079 | system-variables System Variables | |
1080 | fixme FIXME: Warning in comments (on XEmacs only v. 21.0 and up) | |
1081 | class-arrows Object Arrows with class property" | |
1082 | :group 'idlwave-misc | |
1083 | :type '(set | |
1084 | :inline t :greedy t | |
1085 | (const :tag "Procedure and Function definitions" pros-and-functions) | |
facebc7b S |
1086 | (const :tag "Batch Files" batch-files) |
1087 | (const :tag "IDL Keywords (reserved words)" idlwave-idl-keywords) | |
1088 | (const :tag "Statement Labels" label) | |
1089 | (const :tag "Goto Statements" goto) | |
1090 | (const :tag "Tags in Structure Definition" structtag) | |
1091 | (const :tag "Structure Name" structname) | |
1092 | (const :tag "Common Blocks" common-blocks) | |
1093 | (const :tag "Keyword Parameters" keyword-parameters) | |
1094 | (const :tag "System Variables" system-variables) | |
1095 | (const :tag "FIXME: Warning" fixme) | |
f32b3b91 CD |
1096 | (const :tag "Object Arrows with class property " class-arrows))) |
1097 | ||
1098 | (defcustom idlwave-mode-hook nil | |
1099 | "Normal hook. Executed when a buffer is put into `idlwave-mode'." | |
1100 | :group 'idlwave-misc | |
1101 | :type 'hook) | |
1102 | ||
1103 | (defcustom idlwave-load-hook nil | |
1104 | "Normal hook. Executed when idlwave.el is loaded." | |
1105 | :group 'idlwave-misc | |
1106 | :type 'hook) | |
1107 | ||
15e42531 CD |
1108 | (defvar idlwave-experimental nil |
1109 | "Non-nil means turn on a few experimental features. | |
1110 | This variable is only for the maintainer, to test difficult stuff, | |
1111 | while still distributing stable releases. | |
1112 | As a user, you should not set this to t.") | |
1113 | ||
f32b3b91 CD |
1114 | ;;; |
1115 | ;;; End customization variables section | |
1116 | ;;; | |
1117 | ||
1118 | ;;; Non customization variables | |
1119 | ||
1120 | ;;; font-lock mode - Additions by Phil Williams, Ulrik Dickow and | |
52a244eb | 1121 | ;;; Simon Marshall <simon_at_gnu.ai.mit.edu> |
f32b3b91 CD |
1122 | ;;; and Carsten Dominik... |
1123 | ||
76959b77 | 1124 | ;; The following are the reserved words in IDL. Maybe we should |
4b1aaa8b | 1125 | ;; highlight some more stuff as well? |
76959b77 S |
1126 | ;; Procedure declarations. Fontify keyword plus procedure name. |
1127 | (defvar idlwave-idl-keywords | |
4b1aaa8b | 1128 | ;; To update this regexp, update the list of keywords and |
76959b77 | 1129 | ;; evaluate the form. |
4b1aaa8b | 1130 | ;; (insert |
76959b77 | 1131 | ;; (prin1-to-string |
4b1aaa8b | 1132 | ;; (concat |
76959b77 | 1133 | ;; "\\<\\(" |
4b1aaa8b | 1134 | ;; (regexp-opt |
52a244eb | 1135 | ;; '("||" "&&" "and" "or" "xor" "not" |
4b1aaa8b | 1136 | ;; "eq" "ge" "gt" "le" "lt" "ne" |
76959b77 | 1137 | ;; "for" "do" "endfor" |
4b1aaa8b | 1138 | ;; "if" "then" "endif" "else" "endelse" |
76959b77 S |
1139 | ;; "case" "of" "endcase" |
1140 | ;; "switch" "break" "continue" "endswitch" | |
1141 | ;; "begin" "end" | |
1142 | ;; "repeat" "until" "endrep" | |
4b1aaa8b | 1143 | ;; "while" "endwhile" |
76959b77 S |
1144 | ;; "goto" "return" |
1145 | ;; "inherits" "mod" | |
1146 | ;; "compile_opt" "forward_function" | |
1147 | ;; "on_error" "on_ioerror")) ; on_error is not officially reserved | |
1148 | ;; "\\)\\>"))) | |
52a244eb S |
1149 | "\\<\\(&&\\|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\\|||\\)\\>") |
1150 | ||
76959b77 | 1151 | |
facebc7b | 1152 | (let* (;; Procedure declarations. Fontify keyword plus procedure name. |
f32b3b91 CD |
1153 | ;; Function declarations. Fontify keyword plus function name. |
1154 | (pros-and-functions | |
1155 | '("\\<\\(function\\|pro\\)\\>[ \t]+\\(\\sw+\\(::\\sw+\\)?\\)" | |
1156 | (1 font-lock-keyword-face) | |
1157 | (2 font-lock-function-name-face nil t))) | |
1158 | ||
1159 | ;; Common blocks | |
1160 | (common-blocks | |
1161 | '("\\<\\(common\\)\\>[ \t]*\\(\\sw+\\)?[ \t]*,?" | |
1162 | (1 font-lock-keyword-face) ; "common" | |
1163 | (2 font-lock-reference-face nil t) ; block name | |
f66f03de | 1164 | ("[ \t]*\\(\\sw+\\)[ ,]*" |
f32b3b91 | 1165 | ;; Start with point after block name and comma |
4b1aaa8b | 1166 | (goto-char (match-end 0)) ; needed for XEmacs, could be nil |
f32b3b91 CD |
1167 | nil |
1168 | (1 font-lock-variable-name-face) ; variable names | |
1169 | ))) | |
1170 | ||
1171 | ;; Batch files | |
1172 | (batch-files | |
1173 | '("^[ \t]*\\(@[^ \t\n]+\\)" (1 font-lock-string-face))) | |
1174 | ||
1175 | ;; FIXME warning. | |
1176 | (fixme | |
1177 | '("\\<FIXME:" (0 font-lock-warning-face t))) | |
1178 | ||
1179 | ;; Labels | |
1180 | (label | |
1181 | '("^[ \t]*\\([a-zA-Z]\\sw*:\\)" (1 font-lock-reference-face))) | |
1182 | ||
1183 | ;; The goto statement and its label | |
1184 | (goto | |
1185 | '("\\(goto\\)[ \t]*,[ \t]*\\([a-zA-Z]\\sw*\\)" | |
1186 | (1 font-lock-keyword-face) | |
1187 | (2 font-lock-reference-face))) | |
1188 | ||
52a244eb S |
1189 | ;; Tags in structure definitions. Note that this definition |
1190 | ;; actually collides with labels, so we have to use the same | |
1191 | ;; face. It also matches named subscript ranges, | |
1192 | ;; e.g. vec{bottom:top]. No good way around this. | |
05a1abfc CD |
1193 | (structtag |
1194 | '("\\<\\([a-zA-Z][a-zA-Z0-9_]*:\\)[^:]" (1 font-lock-reference-face))) | |
1195 | ||
1196 | ;; Structure names | |
1197 | (structname | |
1198 | '("\\({\\|\\<inherits\\s-\\)\\s-*\\([a-zA-Z][a-zA-Z0-9_]*\\)[},\t \n]" | |
1199 | (2 font-lock-function-name-face))) | |
1200 | ||
52a244eb | 1201 | ;; Keyword parameters, like /xlog or ,xrange=[] |
f32b3b91 | 1202 | ;; This is anchored to the comma preceeding the keyword. |
595ab50b CD |
1203 | ;; Treats continuation lines, works only during whole buffer |
1204 | ;; fontification. Slow, use it only in fancy fontification. | |
f32b3b91 | 1205 | (keyword-parameters |
0dc2be2f S |
1206 | '("\\(,\\|[a-zA-Z0-9_](\\)[ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\([ \t]*\\(;.*\\)?\n\\)*[ \t]*\\)?\\(/[a-zA-Z_]\\sw*\\|[a-zA-Z_]\\sw*[ \t]*=\\)" |
1207 | (6 font-lock-reference-face))) | |
f32b3b91 | 1208 | |
595ab50b | 1209 | ;; System variables start with a bang. |
f32b3b91 | 1210 | (system-variables |
15e42531 | 1211 | '("\\(![a-zA-Z_0-9]+\\(\\.\\sw+\\)?\\)" |
f32b3b91 CD |
1212 | (1 font-lock-variable-name-face))) |
1213 | ||
1214 | ;; Special and unusual operators (not used because too noisy) | |
1215 | (special-operators | |
1216 | '("[<>#]" (0 font-lock-keyword-face))) | |
1217 | ||
1218 | ;; All operators (not used because too noisy) | |
1219 | (all-operators | |
1220 | '("[-*^#+<>/]" (0 font-lock-keyword-face))) | |
4b1aaa8b | 1221 | |
f32b3b91 CD |
1222 | ;; Arrows with text property `idlwave-class' |
1223 | (class-arrows | |
facebc7b S |
1224 | '(idlwave-match-class-arrows (0 idlwave-class-arrow-face)))) |
1225 | ||
1226 | (defconst idlwave-font-lock-keywords-1 | |
1227 | (list pros-and-functions batch-files) | |
1228 | "Subdued level highlighting for IDLWAVE mode.") | |
f32b3b91 | 1229 | |
facebc7b S |
1230 | (defconst idlwave-font-lock-keywords-2 |
1231 | (mapcar 'symbol-value idlwave-default-font-lock-items) | |
1232 | "Medium level highlighting for IDLWAVE mode.") | |
f32b3b91 | 1233 | |
facebc7b | 1234 | (defconst idlwave-font-lock-keywords-3 |
f32b3b91 CD |
1235 | (list pros-and-functions |
1236 | batch-files | |
76959b77 | 1237 | idlwave-idl-keywords |
f32b3b91 | 1238 | label goto |
05a1abfc CD |
1239 | structtag |
1240 | structname | |
f32b3b91 CD |
1241 | common-blocks |
1242 | keyword-parameters | |
1243 | system-variables | |
facebc7b S |
1244 | class-arrows) |
1245 | "Gaudy level highlighting for IDLWAVE mode.")) | |
f32b3b91 CD |
1246 | |
1247 | (defun idlwave-match-class-arrows (limit) | |
1248 | ;; Match an object arrow with class property | |
1249 | (and idlwave-store-inquired-class | |
1250 | (re-search-forward "->" limit 'limit) | |
1251 | (get-text-property (match-beginning 0) 'idlwave-class))) | |
1252 | ||
1253 | (defvar idlwave-font-lock-keywords idlwave-font-lock-keywords-2 | |
1254 | "Default expressions to highlight in IDLWAVE mode.") | |
1255 | ||
1256 | (defvar idlwave-font-lock-defaults | |
1257 | '((idlwave-font-lock-keywords | |
4b1aaa8b | 1258 | idlwave-font-lock-keywords-1 |
f32b3b91 CD |
1259 | idlwave-font-lock-keywords-2 |
1260 | idlwave-font-lock-keywords-3) | |
4b1aaa8b PE |
1261 | nil t |
1262 | ((?$ . "w") (?_ . "w") (?. . "w") (?| . "w") (?& . "w")) | |
f32b3b91 CD |
1263 | beginning-of-line)) |
1264 | ||
4b1aaa8b | 1265 | (put 'idlwave-mode 'font-lock-defaults |
f32b3b91 CD |
1266 | idlwave-font-lock-defaults) ; XEmacs |
1267 | ||
1268 | (defconst idlwave-comment-line-start-skip "^[ \t]*;" | |
1269 | "Regexp to match the start of a full-line comment. | |
1270 | That is the _beginning_ of a line containing a comment delimiter `;' preceded | |
1271 | only by whitespace.") | |
1272 | ||
4b1aaa8b | 1273 | (defconst idlwave-begin-block-reg |
05a1abfc | 1274 | "\\<\\(pro\\|function\\|begin\\|case\\|switch\\)\\>" |
f32b3b91 CD |
1275 | "Regular expression to find the beginning of a block. The case does |
1276 | not matter. The search skips matches in comments.") | |
1277 | ||
52a244eb | 1278 | (defconst idlwave-begin-unit-reg "^\\s-*\\(pro\\|function\\)\\>\\|\\`" |
f32b3b91 CD |
1279 | "Regular expression to find the beginning of a unit. The case does |
1280 | not matter.") | |
1281 | ||
52a244eb | 1282 | (defconst idlwave-end-unit-reg "^\\s-*\\(pro\\|function\\)\\>\\|\\'" |
f32b3b91 CD |
1283 | "Regular expression to find the line that indicates the end of unit. |
1284 | This line is the end of buffer or the start of another unit. The case does | |
1285 | not matter. The search skips matches in comments.") | |
1286 | ||
1287 | (defconst idlwave-continue-line-reg "\\<\\$" | |
1288 | "Regular expression to match a continued line.") | |
1289 | ||
1290 | (defconst idlwave-end-block-reg | |
05a1abfc | 1291 | "\\<end\\(\\|case\\|switch\\|else\\|for\\|if\\|rep\\|while\\)\\>" |
f32b3b91 CD |
1292 | "Regular expression to find the end of a block. The case does |
1293 | not matter. The search skips matches found in comments.") | |
1294 | ||
1295 | (defconst idlwave-block-matches | |
1296 | '(("pro" . "end") | |
1297 | ("function" . "end") | |
1298 | ("case" . "endcase") | |
1299 | ("else" . "endelse") | |
1300 | ("for" . "endfor") | |
1301 | ("then" . "endif") | |
1302 | ("repeat" . "endrep") | |
05a1abfc | 1303 | ("switch" . "endswitch") |
f32b3b91 CD |
1304 | ("while" . "endwhile")) |
1305 | "Matches between statements and the corresponding END variant. | |
1306 | The cars are the reserved words starting a block. If the block really | |
1307 | begins with BEGIN, the cars are the reserved words before the begin | |
1308 | which can be used to identify the block type. | |
1309 | This is used to check for the correct END type, to close blocks and | |
1310 | to expand generic end statements to their detailed form.") | |
1311 | ||
1312 | (defconst idlwave-block-match-regexp | |
1313 | "\\<\\(else\\|for\\|then\\|repeat\\|while\\)\\>" | |
1314 | "Regular expression matching reserved words which can stand before | |
1315 | blocks starting with a BEGIN statement. The matches must have associations | |
1316 | `idlwave-block-matches'") | |
1317 | ||
52a244eb | 1318 | (defconst idlwave-identifier "[a-zA-Z_][a-zA-Z0-9$_]*" |
f32b3b91 CD |
1319 | "Regular expression matching an IDL identifier.") |
1320 | ||
1321 | (defconst idlwave-sysvar (concat "!" idlwave-identifier) | |
1322 | "Regular expression matching IDL system variables.") | |
1323 | ||
1324 | (defconst idlwave-variable (concat idlwave-identifier "\\|" idlwave-sysvar) | |
1325 | "Regular expression matching IDL variable names.") | |
1326 | ||
1327 | (defconst idlwave-label (concat idlwave-identifier ":") | |
1328 | "Regular expression matching IDL labels.") | |
1329 | ||
52a244eb S |
1330 | (defconst idlwave-method-call (concat idlwave-identifier "\\s *->" |
1331 | "\\(\\s *" idlwave-identifier "::\\)?" | |
1332 | )) | |
1333 | ||
f32b3b91 CD |
1334 | (defconst idlwave-statement-match |
1335 | (list | |
aa87aafc | 1336 | ;; "endif else" is the only possible "end" that can be |
f32b3b91 CD |
1337 | ;; followed by a statement on the same line. |
1338 | '(endelse . ("end\\(\\|if\\)\\s +else" "end\\(\\|if\\)\\s +else")) | |
1339 | ;; all other "end"s can not be followed by a statement. | |
1340 | (cons 'end (list idlwave-end-block-reg nil)) | |
1341 | '(if . ("if\\>" "then")) | |
1342 | '(for . ("for\\>" "do")) | |
1343 | '(begin . ("begin\\>" nil)) | |
1344 | '(pdef . ("pro\\>\\|function\\>" nil)) | |
1345 | '(while . ("while\\>" "do")) | |
1346 | '(repeat . ("repeat\\>" "repeat")) | |
1347 | '(goto . ("goto\\>" nil)) | |
1348 | '(case . ("case\\>" nil)) | |
05a1abfc | 1349 | '(switch . ("switch\\>" nil)) |
4b1aaa8b | 1350 | (cons 'call (list (concat "\\(" idlwave-variable "\\) *= *" |
52a244eb S |
1351 | "\\(" idlwave-method-call "\\s *\\)?" |
1352 | idlwave-identifier | |
1353 | "\\s *(") nil)) | |
4b1aaa8b | 1354 | (cons 'call (list (concat |
52a244eb | 1355 | "\\(" idlwave-method-call "\\s *\\)?" |
4b1aaa8b | 1356 | idlwave-identifier |
52a244eb | 1357 | "\\( *\\($\\|\\$\\)\\|\\s *,\\)") nil)) |
4b1aaa8b | 1358 | (cons 'assign (list (concat |
52a244eb | 1359 | "\\(" idlwave-variable "\\) *=") nil))) |
4b1aaa8b | 1360 | |
f32b3b91 CD |
1361 | "Associated list of statement matching regular expressions. |
1362 | Each regular expression matches the start of an IDL statement. The | |
1363 | first element of each association is a symbol giving the statement | |
1364 | type. The associated value is a list. The first element of this list | |
1365 | is a regular expression matching the start of an IDL statement for | |
1366 | identifying the statement type. The second element of this list is a | |
1367 | regular expression for finding a substatement for the type. The | |
1368 | substatement starts after the end of the found match modulo | |
1369 | whitespace. If it is nil then the statement has no substatement. The | |
1370 | list order matters since matching an assignment statement exactly is | |
1371 | not possible without parsing. Thus assignment statement become just | |
15e42531 | 1372 | the leftover unidentified statements containing an equal sign." ) |
f32b3b91 CD |
1373 | |
1374 | (defvar idlwave-fill-function 'auto-fill-function | |
1375 | "IDL mode auto fill function.") | |
1376 | ||
1377 | (defvar idlwave-comment-indent-function 'comment-indent-function | |
1378 | "IDL mode comment indent function.") | |
1379 | ||
1380 | ;; Note that this is documented in the v18 manuals as being a string | |
1381 | ;; of length one rather than a single character. | |
1382 | ;; The code in this file accepts either format for compatibility. | |
4b1aaa8b | 1383 | (defvar idlwave-comment-indent-char ?\ |
f32b3b91 CD |
1384 | "Character to be inserted for IDL comment indentation. |
1385 | Normally a space.") | |
1386 | ||
1387 | (defconst idlwave-continuation-char ?$ | |
1388 | "Character which is inserted as a last character on previous line by | |
1389 | \\[idlwave-split-line] to begin a continuation line. Normally $.") | |
1390 | ||
e08734e2 | 1391 | (defconst idlwave-mode-version "6.1_em22") |
f32b3b91 CD |
1392 | |
1393 | (defmacro idlwave-keyword-abbrev (&rest args) | |
1394 | "Creates a function for abbrev hooks to call `idlwave-check-abbrev' with args." | |
8a946354 | 1395 | `(quote (lambda () |
5e72c6b2 | 1396 | ,(append '(idlwave-check-abbrev) args)))) |
f32b3b91 CD |
1397 | |
1398 | ;; If I take the time I can replace idlwave-keyword-abbrev with | |
1399 | ;; idlwave-code-abbrev and remove the quoted abbrev check from | |
1400 | ;; idlwave-check-abbrev. Then, e.g, (idlwave-keyword-abbrev 0 t) becomes | |
1401 | ;; (idlwave-code-abbrev idlwave-check-abbrev 0 t). In fact I should change | |
1402 | ;; the name of idlwave-check-abbrev to something like idlwave-modify-abbrev. | |
1403 | ||
1404 | (defmacro idlwave-code-abbrev (&rest args) | |
1405 | "Creates a function for abbrev hooks that ensures abbrevs are not quoted. | |
1406 | Specifically, if the abbrev is in a comment or string it is unexpanded. | |
1407 | Otherwise ARGS forms a list that is evaluated." | |
8a946354 | 1408 | `(quote (lambda () |
5e72c6b2 S |
1409 | ,(prin1-to-string args) ;; Puts the code in the doc string |
1410 | (if (idlwave-quoted) | |
1411 | (progn (unexpand-abbrev) nil) | |
1412 | ,(append args))))) | |
f32b3b91 CD |
1413 | |
1414 | (defvar idlwave-mode-map (make-sparse-keymap) | |
1415 | "Keymap used in IDL mode.") | |
1416 | ||
1417 | (defvar idlwave-mode-syntax-table (make-syntax-table) | |
1418 | "Syntax table in use in `idlwave-mode' buffers.") | |
1419 | ||
1420 | (modify-syntax-entry ?+ "." idlwave-mode-syntax-table) | |
1421 | (modify-syntax-entry ?- "." idlwave-mode-syntax-table) | |
1422 | (modify-syntax-entry ?* "." idlwave-mode-syntax-table) | |
1423 | (modify-syntax-entry ?/ "." idlwave-mode-syntax-table) | |
1424 | (modify-syntax-entry ?^ "." idlwave-mode-syntax-table) | |
1425 | (modify-syntax-entry ?# "." idlwave-mode-syntax-table) | |
1426 | (modify-syntax-entry ?= "." idlwave-mode-syntax-table) | |
1427 | (modify-syntax-entry ?% "." idlwave-mode-syntax-table) | |
1428 | (modify-syntax-entry ?< "." idlwave-mode-syntax-table) | |
1429 | (modify-syntax-entry ?> "." idlwave-mode-syntax-table) | |
1430 | (modify-syntax-entry ?\' "\"" idlwave-mode-syntax-table) | |
1431 | (modify-syntax-entry ?\" "\"" idlwave-mode-syntax-table) | |
1432 | (modify-syntax-entry ?\\ "." idlwave-mode-syntax-table) | |
1433 | (modify-syntax-entry ?_ "_" idlwave-mode-syntax-table) | |
1434 | (modify-syntax-entry ?{ "(}" idlwave-mode-syntax-table) | |
1435 | (modify-syntax-entry ?} "){" idlwave-mode-syntax-table) | |
1436 | (modify-syntax-entry ?$ "_" idlwave-mode-syntax-table) | |
1437 | (modify-syntax-entry ?. "." idlwave-mode-syntax-table) | |
1438 | (modify-syntax-entry ?\; "<" idlwave-mode-syntax-table) | |
1439 | (modify-syntax-entry ?\n ">" idlwave-mode-syntax-table) | |
1440 | (modify-syntax-entry ?\f ">" idlwave-mode-syntax-table) | |
1441 | ||
1442 | (defvar idlwave-find-symbol-syntax-table | |
1443 | (copy-syntax-table idlwave-mode-syntax-table) | |
1444 | "Syntax table that treats symbol characters as word characters.") | |
1445 | ||
05a1abfc CD |
1446 | (modify-syntax-entry ?$ "w" idlwave-find-symbol-syntax-table) |
1447 | (modify-syntax-entry ?_ "w" idlwave-find-symbol-syntax-table) | |
1448 | (modify-syntax-entry ?! "w" idlwave-find-symbol-syntax-table) | |
1449 | (modify-syntax-entry ?. "w" idlwave-find-symbol-syntax-table) | |
1450 | ||
76959b77 S |
1451 | (defmacro idlwave-with-special-syntax (&rest body) |
1452 | "Execute BODY with a different syntax table." | |
05a1abfc CD |
1453 | `(let ((saved-syntax (syntax-table))) |
1454 | (unwind-protect | |
1455 | (progn | |
1456 | (set-syntax-table idlwave-find-symbol-syntax-table) | |
1457 | ,@body) | |
1458 | (set-syntax-table saved-syntax)))) | |
1459 | ||
76959b77 S |
1460 | ;(defmacro idlwave-with-special-syntax1 (&rest body) |
1461 | ; "Execute BODY with a different syntax table." | |
1462 | ; `(let ((saved-syntax (syntax-table))) | |
1463 | ; (unwind-protect | |
1464 | ; (progn | |
1465 | ; (set-syntax-table idlwave-find-symbol-syntax-table) | |
1466 | ; ,@body) | |
1467 | ; (set-syntax-table saved-syntax)))) | |
1468 | ||
f32b3b91 CD |
1469 | (defun idlwave-action-and-binding (key cmd &optional select) |
1470 | "KEY and CMD are made into a key binding and an indent action. | |
1471 | KEY is a string - same as for the `define-key' function. CMD is a | |
1472 | function of no arguments or a list to be evaluated. CMD is bound to | |
1473 | KEY in `idlwave-mode-map' by defining an anonymous function calling | |
1474 | `self-insert-command' followed by CMD. If KEY contains more than one | |
1475 | character a binding will only be set if SELECT is 'both. | |
1476 | ||
5e72c6b2 | 1477 | \(KEY . CMD\) is also placed in the `idlwave-indent-expand-table', |
f32b3b91 CD |
1478 | replacing any previous value for KEY. If a binding is not set then it |
1479 | will instead be placed in `idlwave-indent-action-table'. | |
1480 | ||
1481 | If the optional argument SELECT is nil then an action and binding are | |
1482 | created. If SELECT is 'noaction, then a binding is always set and no | |
1483 | action is created. If SELECT is 'both then an action and binding | |
1484 | will both be created even if KEY contains more than one character. | |
1485 | Otherwise, if SELECT is non-nil then only an action is created. | |
1486 | ||
1487 | Some examples: | |
1488 | No spaces before and 1 after a comma | |
1489 | (idlwave-action-and-binding \",\" '(idlwave-surround 0 1)) | |
1490 | A minimum of 1 space before and after `=' (see `idlwave-expand-equal'). | |
1491 | (idlwave-action-and-binding \"=\" '(idlwave-expand-equal -1 -1)) | |
1492 | Capitalize system variables - action only | |
1493 | (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)" | |
1494 | (if (not (equal select 'noaction)) | |
1495 | ;; Add action | |
1496 | (let* ((table (if select 'idlwave-indent-action-table | |
1497 | 'idlwave-indent-expand-table)) | |
3938cb82 S |
1498 | (table-key (regexp-quote key)) |
1499 | (cell (assoc table-key (eval table)))) | |
f32b3b91 CD |
1500 | (if cell |
1501 | ;; Replace action command | |
1502 | (setcdr cell cmd) | |
1503 | ;; New action | |
3938cb82 | 1504 | (set table (append (eval table) (list (cons table-key cmd))))))) |
f32b3b91 CD |
1505 | ;; Make key binding for action |
1506 | (if (or (and (null select) (= (length key) 1)) | |
1507 | (equal select 'noaction) | |
1508 | (equal select 'both)) | |
1509 | (define-key idlwave-mode-map key | |
1510 | (append '(lambda () | |
1511 | (interactive) | |
1512 | (self-insert-command 1)) | |
1513 | (list (if (listp cmd) | |
1514 | cmd | |
1515 | (list cmd))))))) | |
1516 | ||
1517 | (fset 'idlwave-debug-map (make-sparse-keymap)) | |
1518 | ||
595ab50b | 1519 | (define-key idlwave-mode-map "\C-c " 'idlwave-hard-tab) |
15e42531 | 1520 | (define-key idlwave-mode-map [(control tab)] 'idlwave-hard-tab) |
595ab50b | 1521 | ;(define-key idlwave-mode-map "\C-c\C- " 'idlwave-hard-tab) |
f32b3b91 CD |
1522 | (define-key idlwave-mode-map "'" 'idlwave-show-matching-quote) |
1523 | (define-key idlwave-mode-map "\"" 'idlwave-show-matching-quote) | |
76959b77 | 1524 | (define-key idlwave-mode-map "\C-g" 'idlwave-keyboard-quit) |
f32b3b91 CD |
1525 | (define-key idlwave-mode-map "\C-c;" 'idlwave-toggle-comment-region) |
1526 | (define-key idlwave-mode-map "\C-\M-a" 'idlwave-beginning-of-subprogram) | |
1527 | (define-key idlwave-mode-map "\C-\M-e" 'idlwave-end-of-subprogram) | |
1528 | (define-key idlwave-mode-map "\C-c{" 'idlwave-beginning-of-block) | |
1529 | (define-key idlwave-mode-map "\C-c}" 'idlwave-end-of-block) | |
1530 | (define-key idlwave-mode-map "\C-c]" 'idlwave-close-block) | |
3938cb82 | 1531 | (define-key idlwave-mode-map [(meta control h)] 'idlwave-mark-subprogram) |
f32b3b91 CD |
1532 | (define-key idlwave-mode-map "\M-\C-n" 'idlwave-forward-block) |
1533 | (define-key idlwave-mode-map "\M-\C-p" 'idlwave-backward-block) | |
1534 | (define-key idlwave-mode-map "\M-\C-d" 'idlwave-down-block) | |
1535 | (define-key idlwave-mode-map "\M-\C-u" 'idlwave-backward-up-block) | |
1536 | (define-key idlwave-mode-map "\M-\r" 'idlwave-split-line) | |
1537 | (define-key idlwave-mode-map "\M-\C-q" 'idlwave-indent-subprogram) | |
1538 | (define-key idlwave-mode-map "\C-c\C-p" 'idlwave-previous-statement) | |
1539 | (define-key idlwave-mode-map "\C-c\C-n" 'idlwave-next-statement) | |
1540 | ;; (define-key idlwave-mode-map "\r" 'idlwave-newline) | |
1541 | ;; (define-key idlwave-mode-map "\t" 'idlwave-indent-line) | |
f66f03de | 1542 | (define-key idlwave-mode-map [(shift iso-lefttab)] 'idlwave-indent-statement) |
f32b3b91 CD |
1543 | (define-key idlwave-mode-map "\C-c\C-a" 'idlwave-auto-fill-mode) |
1544 | (define-key idlwave-mode-map "\M-q" 'idlwave-fill-paragraph) | |
1545 | (define-key idlwave-mode-map "\M-s" 'idlwave-edit-in-idlde) | |
1546 | (define-key idlwave-mode-map "\C-c\C-h" 'idlwave-doc-header) | |
1547 | (define-key idlwave-mode-map "\C-c\C-m" 'idlwave-doc-modification) | |
1548 | (define-key idlwave-mode-map "\C-c\C-c" 'idlwave-case) | |
1549 | (define-key idlwave-mode-map "\C-c\C-d" 'idlwave-debug-map) | |
05a1abfc CD |
1550 | (when (and (boundp 'idlwave-shell-debug-modifiers) |
1551 | (listp idlwave-shell-debug-modifiers) | |
1552 | (not (equal idlwave-shell-debug-modifiers '()))) | |
1553 | ;; Bind the debug commands also with the special modifiers. | |
1554 | (let ((shift (memq 'shift idlwave-shell-debug-modifiers)) | |
4b1aaa8b | 1555 | (mods-noshift (delq 'shift |
05a1abfc | 1556 | (copy-sequence idlwave-shell-debug-modifiers)))) |
4b1aaa8b | 1557 | (define-key idlwave-mode-map |
05a1abfc CD |
1558 | (vector (append mods-noshift (list (if shift ?C ?c)))) |
1559 | 'idlwave-shell-save-and-run) | |
4b1aaa8b | 1560 | (define-key idlwave-mode-map |
05a1abfc | 1561 | (vector (append mods-noshift (list (if shift ?B ?b)))) |
52a244eb | 1562 | 'idlwave-shell-break-here) |
4b1aaa8b | 1563 | (define-key idlwave-mode-map |
52a244eb S |
1564 | (vector (append mods-noshift (list (if shift ?E ?e)))) |
1565 | 'idlwave-shell-run-region))) | |
1566 | (define-key idlwave-mode-map "\C-c\C-d\C-c" 'idlwave-shell-save-and-run) | |
1567 | (define-key idlwave-mode-map "\C-c\C-d\C-b" 'idlwave-shell-break-here) | |
1568 | (define-key idlwave-mode-map "\C-c\C-d\C-e" 'idlwave-shell-run-region) | |
f32b3b91 CD |
1569 | (define-key idlwave-mode-map "\C-c\C-f" 'idlwave-for) |
1570 | ;; (define-key idlwave-mode-map "\C-c\C-f" 'idlwave-function) | |
1571 | ;; (define-key idlwave-mode-map "\C-c\C-p" 'idlwave-procedure) | |
1572 | (define-key idlwave-mode-map "\C-c\C-r" 'idlwave-repeat) | |
1573 | (define-key idlwave-mode-map "\C-c\C-w" 'idlwave-while) | |
15e42531 | 1574 | (define-key idlwave-mode-map "\C-c\C-k" 'idlwave-kill-autoloaded-buffers) |
f32b3b91 CD |
1575 | (define-key idlwave-mode-map "\C-c\C-s" 'idlwave-shell) |
1576 | (define-key idlwave-mode-map "\C-c\C-l" 'idlwave-shell-recenter-shell-window) | |
15e42531 | 1577 | (define-key idlwave-mode-map "\C-c\C-b" 'idlwave-list-buffer-load-path-shadows) |
22d5821d CD |
1578 | (autoload 'idlwave-shell "idlw-shell" |
1579 | "Run an inferior IDL, with I/O through buffer `(idlwave-shell-buffer)'." t) | |
8c7b4ec8 EZ |
1580 | (autoload 'idlwave-shell-send-command "idlw-shell") |
1581 | (autoload 'idlwave-shell-recenter-shell-window "idlw-shell" | |
f32b3b91 | 1582 | "Run `idlwave-shell' and switch back to current window" t) |
8c7b4ec8 | 1583 | (autoload 'idlwave-shell-save-and-run "idlw-shell" |
f32b3b91 | 1584 | "Save and run buffer under the shell." t) |
15e42531 CD |
1585 | (autoload 'idlwave-shell-break-here "idlw-shell" |
1586 | "Set breakpoint in current line." t) | |
52a244eb S |
1587 | (autoload 'idlwave-shell-run-region "idlw-shell" |
1588 | "Compile and run the region." t) | |
f32b3b91 | 1589 | (define-key idlwave-mode-map "\C-c\C-v" 'idlwave-find-module) |
3938cb82 | 1590 | (define-key idlwave-mode-map "\C-c\C-t" 'idlwave-find-module-this-file) |
f32b3b91 | 1591 | (define-key idlwave-mode-map "\C-c?" 'idlwave-routine-info) |
15e42531 | 1592 | (define-key idlwave-mode-map "\M-?" 'idlwave-context-help) |
8c43762b | 1593 | (define-key idlwave-mode-map [(control meta ?\?)] |
e08734e2 | 1594 | 'idlwave-help-assistant-help-with-topic) |
52a244eb | 1595 | ;; Pickup both forms of Esc/Meta binding |
f32b3b91 | 1596 | (define-key idlwave-mode-map [(meta tab)] 'idlwave-complete) |
52a244eb S |
1597 | (define-key idlwave-mode-map [?\e?\t] 'idlwave-complete) |
1598 | (define-key idlwave-mode-map "\M-\C-i" 'idlwave-complete) | |
1599 | (define-key idlwave-mode-map "\C-c\C-i" 'idlwave-update-routine-info) | |
1600 | (define-key idlwave-mode-map "\C-c=" 'idlwave-resolve) | |
4b1aaa8b | 1601 | (define-key idlwave-mode-map |
15e42531 CD |
1602 | (if (featurep 'xemacs) [(shift button3)] [(shift mouse-3)]) |
1603 | 'idlwave-mouse-context-help) | |
f32b3b91 CD |
1604 | |
1605 | ;; Set action and key bindings. | |
1606 | ;; See description of the function `idlwave-action-and-binding'. | |
1607 | ;; Automatically add spaces for the following characters | |
f66f03de S |
1608 | |
1609 | ;; Actions for & are complicated by && | |
1610 | (idlwave-action-and-binding "&" 'idlwave-custom-ampersand-surround) | |
1611 | ||
1612 | ;; Automatically add spaces to equal sign if not keyword. This needs | |
1613 | ;; to go ahead of > and <, so >= and <= will be treated correctly | |
f32b3b91 CD |
1614 | (idlwave-action-and-binding "=" '(idlwave-expand-equal -1 -1)) |
1615 | ||
4b1aaa8b | 1616 | ;; Actions for > and < are complicated by >=, <=, and ->... |
f66f03de S |
1617 | (idlwave-action-and-binding "<" '(idlwave-custom-ltgtr-surround nil)) |
1618 | (idlwave-action-and-binding ">" '(idlwave-custom-ltgtr-surround 'gtr)) | |
1619 | ||
1620 | (idlwave-action-and-binding "," '(idlwave-surround 0 -1 1)) | |
1621 | ||
1622 | ||
f32b3b91 CD |
1623 | ;;; |
1624 | ;;; Abbrev Section | |
1625 | ;;; | |
1626 | ;;; When expanding abbrevs and the abbrev hook moves backward, an extra | |
1627 | ;;; space is inserted (this is the space typed by the user to expanded | |
1628 | ;;; the abbrev). | |
1629 | ;;; | |
5e72c6b2 S |
1630 | (defvar idlwave-mode-abbrev-table nil |
1631 | "Abbreviation table used for IDLWAVE mode") | |
1632 | (define-abbrev-table 'idlwave-mode-abbrev-table ()) | |
1633 | ||
1634 | (defun idlwave-define-abbrev (name expansion hook &optional noprefix table) | |
1635 | "Define-abbrev with backward compatibility. | |
1636 | ||
1637 | If NOPREFIX is non-nil, don't prepend prefix character. Installs into | |
1638 | idlwave-mode-abbrev-table unless TABLE is non-nil." | |
1639 | (let ((abbrevs-changed nil) ;; mask the current value to avoid save | |
1640 | (args (list (or table idlwave-mode-abbrev-table) | |
1641 | (if noprefix name (concat idlwave-abbrev-start-char name)) | |
1642 | expansion | |
1643 | hook))) | |
1644 | (condition-case nil | |
1645 | (apply 'define-abbrev (append args '(0 t))) | |
1646 | (error (apply 'define-abbrev args))))) | |
f32b3b91 CD |
1647 | |
1648 | (condition-case nil | |
4b1aaa8b | 1649 | (modify-syntax-entry (string-to-char idlwave-abbrev-start-char) |
f32b3b91 CD |
1650 | "w" idlwave-mode-syntax-table) |
1651 | (error nil)) | |
1652 | ||
5e72c6b2 S |
1653 | ;; |
1654 | ;; Templates | |
1655 | ;; | |
1656 | (idlwave-define-abbrev "c" "" (idlwave-code-abbrev idlwave-case)) | |
1657 | (idlwave-define-abbrev "sw" "" (idlwave-code-abbrev idlwave-switch)) | |
1658 | (idlwave-define-abbrev "f" "" (idlwave-code-abbrev idlwave-for)) | |
1659 | (idlwave-define-abbrev "fu" "" (idlwave-code-abbrev idlwave-function)) | |
1660 | (idlwave-define-abbrev "pr" "" (idlwave-code-abbrev idlwave-procedure)) | |
1661 | (idlwave-define-abbrev "r" "" (idlwave-code-abbrev idlwave-repeat)) | |
1662 | (idlwave-define-abbrev "w" "" (idlwave-code-abbrev idlwave-while)) | |
1663 | (idlwave-define-abbrev "i" "" (idlwave-code-abbrev idlwave-if)) | |
1664 | (idlwave-define-abbrev "elif" "" (idlwave-code-abbrev idlwave-elif)) | |
1665 | ;; | |
1666 | ;; Keywords, system functions, conversion routines | |
1667 | ;; | |
1668 | (idlwave-define-abbrev "ap" "arg_present()" (idlwave-keyword-abbrev 1)) | |
1669 | (idlwave-define-abbrev "b" "begin" (idlwave-keyword-abbrev 0 t)) | |
1670 | (idlwave-define-abbrev "co" "common" (idlwave-keyword-abbrev 0 t)) | |
1671 | (idlwave-define-abbrev "cb" "byte()" (idlwave-keyword-abbrev 1)) | |
1672 | (idlwave-define-abbrev "cx" "fix()" (idlwave-keyword-abbrev 1)) | |
1673 | (idlwave-define-abbrev "cl" "long()" (idlwave-keyword-abbrev 1)) | |
1674 | (idlwave-define-abbrev "cf" "float()" (idlwave-keyword-abbrev 1)) | |
1675 | (idlwave-define-abbrev "cs" "string()" (idlwave-keyword-abbrev 1)) | |
1676 | (idlwave-define-abbrev "cc" "complex()" (idlwave-keyword-abbrev 1)) | |
1677 | (idlwave-define-abbrev "cd" "double()" (idlwave-keyword-abbrev 1)) | |
1678 | (idlwave-define-abbrev "e" "else" (idlwave-keyword-abbrev 0 t)) | |
1679 | (idlwave-define-abbrev "ec" "endcase" 'idlwave-show-begin) | |
1680 | (idlwave-define-abbrev "es" "endswitch" 'idlwave-show-begin) | |
1681 | (idlwave-define-abbrev "ee" "endelse" 'idlwave-show-begin) | |
1682 | (idlwave-define-abbrev "ef" "endfor" 'idlwave-show-begin) | |
1683 | (idlwave-define-abbrev "ei" "endif else if" 'idlwave-show-begin) | |
1684 | (idlwave-define-abbrev "el" "endif else" 'idlwave-show-begin) | |
1685 | (idlwave-define-abbrev "en" "endif" 'idlwave-show-begin) | |
1686 | (idlwave-define-abbrev "er" "endrep" 'idlwave-show-begin) | |
1687 | (idlwave-define-abbrev "ew" "endwhile" 'idlwave-show-begin) | |
1688 | (idlwave-define-abbrev "g" "goto," (idlwave-keyword-abbrev 0 t)) | |
1689 | (idlwave-define-abbrev "h" "help," (idlwave-keyword-abbrev 0)) | |
1690 | (idlwave-define-abbrev "k" "keyword_set()" (idlwave-keyword-abbrev 1)) | |
1691 | (idlwave-define-abbrev "n" "n_elements()" (idlwave-keyword-abbrev 1)) | |
1692 | (idlwave-define-abbrev "on" "on_error," (idlwave-keyword-abbrev 0)) | |
1693 | (idlwave-define-abbrev "oi" "on_ioerror," (idlwave-keyword-abbrev 0 1)) | |
1694 | (idlwave-define-abbrev "ow" "openw," (idlwave-keyword-abbrev 0)) | |
1695 | (idlwave-define-abbrev "or" "openr," (idlwave-keyword-abbrev 0)) | |
1696 | (idlwave-define-abbrev "ou" "openu," (idlwave-keyword-abbrev 0)) | |
1697 | (idlwave-define-abbrev "p" "print," (idlwave-keyword-abbrev 0)) | |
1698 | (idlwave-define-abbrev "pt" "plot," (idlwave-keyword-abbrev 0)) | |
1699 | (idlwave-define-abbrev "re" "read," (idlwave-keyword-abbrev 0)) | |
1700 | (idlwave-define-abbrev "rf" "readf," (idlwave-keyword-abbrev 0)) | |
1701 | (idlwave-define-abbrev "ru" "readu," (idlwave-keyword-abbrev 0)) | |
1702 | (idlwave-define-abbrev "rt" "return" (idlwave-keyword-abbrev 0)) | |
1703 | (idlwave-define-abbrev "sc" "strcompress()" (idlwave-keyword-abbrev 1)) | |
1704 | (idlwave-define-abbrev "sn" "strlen()" (idlwave-keyword-abbrev 1)) | |
1705 | (idlwave-define-abbrev "sl" "strlowcase()" (idlwave-keyword-abbrev 1)) | |
1706 | (idlwave-define-abbrev "su" "strupcase()" (idlwave-keyword-abbrev 1)) | |
1707 | (idlwave-define-abbrev "sm" "strmid()" (idlwave-keyword-abbrev 1)) | |
1708 | (idlwave-define-abbrev "sp" "strpos()" (idlwave-keyword-abbrev 1)) | |
1709 | (idlwave-define-abbrev "st" "strput()" (idlwave-keyword-abbrev 1)) | |
1710 | (idlwave-define-abbrev "sr" "strtrim()" (idlwave-keyword-abbrev 1)) | |
1711 | (idlwave-define-abbrev "t" "then" (idlwave-keyword-abbrev 0 t)) | |
1712 | (idlwave-define-abbrev "u" "until" (idlwave-keyword-abbrev 0 t)) | |
1713 | (idlwave-define-abbrev "wu" "writeu," (idlwave-keyword-abbrev 0)) | |
1714 | (idlwave-define-abbrev "iap" "if arg_present() then" (idlwave-keyword-abbrev 6)) | |
1715 | (idlwave-define-abbrev "ik" "if keyword_set() then" (idlwave-keyword-abbrev 6)) | |
1716 | (idlwave-define-abbrev "ine" "if n_elements() eq 0 then" (idlwave-keyword-abbrev 11)) | |
1717 | (idlwave-define-abbrev "inn" "if n_elements() ne 0 then" (idlwave-keyword-abbrev 11)) | |
1718 | (idlwave-define-abbrev "np" "n_params()" (idlwave-keyword-abbrev 0)) | |
1719 | (idlwave-define-abbrev "s" "size()" (idlwave-keyword-abbrev 1)) | |
1720 | (idlwave-define-abbrev "wi" "widget_info()" (idlwave-keyword-abbrev 1)) | |
1721 | (idlwave-define-abbrev "wc" "widget_control," (idlwave-keyword-abbrev 0)) | |
3938cb82 S |
1722 | (idlwave-define-abbrev "pv" "ptr_valid()" (idlwave-keyword-abbrev 1)) |
1723 | (idlwave-define-abbrev "ipv" "if ptr_valid() then" (idlwave-keyword-abbrev 6)) | |
ff689efd | 1724 | |
5e72c6b2 S |
1725 | ;; This section is reserved words only. (From IDL user manual) |
1726 | ;; | |
1727 | (idlwave-define-abbrev "and" "and" (idlwave-keyword-abbrev 0 t) t) | |
1728 | (idlwave-define-abbrev "begin" "begin" (idlwave-keyword-abbrev 0 t) t) | |
1729 | (idlwave-define-abbrev "break" "break" (idlwave-keyword-abbrev 0 t) t) | |
1730 | (idlwave-define-abbrev "case" "case" (idlwave-keyword-abbrev 0 t) t) | |
1731 | (idlwave-define-abbrev "common" "common" (idlwave-keyword-abbrev 0 t) t) | |
1732 | (idlwave-define-abbrev "continue" "continue" (idlwave-keyword-abbrev 0 t) t) | |
1733 | (idlwave-define-abbrev "do" "do" (idlwave-keyword-abbrev 0 t) t) | |
1734 | (idlwave-define-abbrev "else" "else" (idlwave-keyword-abbrev 0 t) t) | |
1735 | (idlwave-define-abbrev "end" "end" 'idlwave-show-begin-check t) | |
1736 | (idlwave-define-abbrev "endcase" "endcase" 'idlwave-show-begin-check t) | |
1737 | (idlwave-define-abbrev "endelse" "endelse" 'idlwave-show-begin-check t) | |
1738 | (idlwave-define-abbrev "endfor" "endfor" 'idlwave-show-begin-check t) | |
1739 | (idlwave-define-abbrev "endif" "endif" 'idlwave-show-begin-check t) | |
1740 | (idlwave-define-abbrev "endrep" "endrep" 'idlwave-show-begin-check t) | |
1741 | (idlwave-define-abbrev "endswitch" "endswitch" 'idlwave-show-begin-check t) | |
1742 | (idlwave-define-abbrev "endwhi" "endwhi" 'idlwave-show-begin-check t) | |
1743 | (idlwave-define-abbrev "endwhile" "endwhile" 'idlwave-show-begin-check t) | |
1744 | (idlwave-define-abbrev "eq" "eq" (idlwave-keyword-abbrev 0 t) t) | |
1745 | (idlwave-define-abbrev "for" "for" (idlwave-keyword-abbrev 0 t) t) | |
1746 | (idlwave-define-abbrev "function" "function" (idlwave-keyword-abbrev 0 t) t) | |
1747 | (idlwave-define-abbrev "ge" "ge" (idlwave-keyword-abbrev 0 t) t) | |
1748 | (idlwave-define-abbrev "goto" "goto" (idlwave-keyword-abbrev 0 t) t) | |
1749 | (idlwave-define-abbrev "gt" "gt" (idlwave-keyword-abbrev 0 t) t) | |
1750 | (idlwave-define-abbrev "if" "if" (idlwave-keyword-abbrev 0 t) t) | |
1751 | (idlwave-define-abbrev "le" "le" (idlwave-keyword-abbrev 0 t) t) | |
1752 | (idlwave-define-abbrev "lt" "lt" (idlwave-keyword-abbrev 0 t) t) | |
1753 | (idlwave-define-abbrev "mod" "mod" (idlwave-keyword-abbrev 0 t) t) | |
1754 | (idlwave-define-abbrev "ne" "ne" (idlwave-keyword-abbrev 0 t) t) | |
1755 | (idlwave-define-abbrev "not" "not" (idlwave-keyword-abbrev 0 t) t) | |
1756 | (idlwave-define-abbrev "of" "of" (idlwave-keyword-abbrev 0 t) t) | |
1757 | (idlwave-define-abbrev "on_ioerror" "on_ioerror" (idlwave-keyword-abbrev 0 t) t) | |
1758 | (idlwave-define-abbrev "or" "or" (idlwave-keyword-abbrev 0 t) t) | |
1759 | (idlwave-define-abbrev "pro" "pro" (idlwave-keyword-abbrev 0 t) t) | |
1760 | (idlwave-define-abbrev "repeat" "repeat" (idlwave-keyword-abbrev 0 t) t) | |
1761 | (idlwave-define-abbrev "switch" "switch" (idlwave-keyword-abbrev 0 t) t) | |
1762 | (idlwave-define-abbrev "then" "then" (idlwave-keyword-abbrev 0 t) t) | |
1763 | (idlwave-define-abbrev "until" "until" (idlwave-keyword-abbrev 0 t) t) | |
1764 | (idlwave-define-abbrev "while" "while" (idlwave-keyword-abbrev 0 t) t) | |
1765 | (idlwave-define-abbrev "xor" "xor" (idlwave-keyword-abbrev 0 t) t) | |
f32b3b91 CD |
1766 | |
1767 | (defvar imenu-create-index-function) | |
1768 | (defvar extract-index-name-function) | |
1769 | (defvar prev-index-position-function) | |
1770 | (defvar imenu-extract-index-name-function) | |
1771 | (defvar imenu-prev-index-position-function) | |
5e72c6b2 | 1772 | ;; defined later - so just make the compiler hush |
4b1aaa8b | 1773 | (defvar idlwave-mode-menu) |
f32b3b91 CD |
1774 | (defvar idlwave-mode-debug-menu) |
1775 | ||
1776 | ;;;###autoload | |
1777 | (defun idlwave-mode () | |
e08734e2 | 1778 | "Major mode for editing IDL source files (version 6.1_em22). |
f32b3b91 CD |
1779 | |
1780 | The main features of this mode are | |
1781 | ||
1782 | 1. Indentation and Formatting | |
1783 | -------------------------- | |
1784 | Like other Emacs programming modes, C-j inserts a newline and indents. | |
1785 | TAB is used for explicit indentation of the current line. | |
1786 | ||
5e72c6b2 S |
1787 | To start a continuation line, use \\[idlwave-split-line]. This |
1788 | function can also be used in the middle of a line to split the line | |
1789 | at that point. When used inside a long constant string, the string | |
1790 | is split at that point with the `+' concatenation operator. | |
f32b3b91 CD |
1791 | |
1792 | Comments are indented as follows: | |
1793 | ||
1794 | `;;;' Indentation remains unchanged. | |
1795 | `;;' Indent like the surrounding code | |
1796 | `;' Indent to a minimum column. | |
1797 | ||
1798 | The indentation of comments starting in column 0 is never changed. | |
1799 | ||
5e72c6b2 S |
1800 | Use \\[idlwave-fill-paragraph] to refill a paragraph inside a |
1801 | comment. The indentation of the second line of the paragraph | |
1802 | relative to the first will be retained. Use | |
1803 | \\[idlwave-auto-fill-mode] to toggle auto-fill mode for these | |
1804 | comments. When the variable `idlwave-fill-comment-line-only' is | |
52a244eb | 1805 | nil, code can also be auto-filled and auto-indented. |
f32b3b91 CD |
1806 | |
1807 | To convert pre-existing IDL code to your formatting style, mark the | |
5e72c6b2 S |
1808 | entire buffer with \\[mark-whole-buffer] and execute |
1809 | \\[idlwave-expand-region-abbrevs]. Then mark the entire buffer | |
1810 | again followed by \\[indent-region] (`indent-region'). | |
f32b3b91 CD |
1811 | |
1812 | 2. Routine Info | |
1813 | ------------ | |
5e72c6b2 S |
1814 | IDLWAVE displays information about the calling sequence and the |
1815 | accepted keyword parameters of a procedure or function with | |
1816 | \\[idlwave-routine-info]. \\[idlwave-find-module] jumps to the | |
1817 | source file of a module. These commands know about system | |
1818 | routines, all routines in idlwave-mode buffers and (when the | |
1819 | idlwave-shell is active) about all modules currently compiled under | |
52a244eb S |
1820 | this shell. It also makes use of pre-compiled or custom-scanned |
1821 | user and library catalogs many popular libraries ship with by | |
1822 | default. Use \\[idlwave-update-routine-info] to update this | |
15e42531 CD |
1823 | information, which is also used for completion (see item 4). |
1824 | ||
1825 | 3. Online IDL Help | |
1826 | --------------- | |
f66f03de | 1827 | |
15e42531 | 1828 | \\[idlwave-context-help] displays the IDL documentation relevant |
f66f03de S |
1829 | for the system variable, keyword, or routines at point. A single |
1830 | key stroke gets you directly to the right place in the docs. See | |
52a244eb | 1831 | the manual to configure where and how the HTML help is displayed. |
f32b3b91 | 1832 | |
15e42531 | 1833 | 4. Completion |
f32b3b91 | 1834 | ---------- |
15e42531 | 1835 | \\[idlwave-complete] completes the names of procedures, functions |
52a244eb S |
1836 | class names, keyword parameters, system variables and tags, class |
1837 | tags, structure tags, filenames and much more. It is context | |
1838 | sensitive and figures out what is expected at point. Lower case | |
1839 | strings are completed in lower case, other strings in mixed or | |
1840 | upper case. | |
f32b3b91 | 1841 | |
15e42531 | 1842 | 5. Code Templates and Abbreviations |
f32b3b91 CD |
1843 | -------------------------------- |
1844 | Many Abbreviations are predefined to expand to code fragments and templates. | |
1845 | The abbreviations start generally with a `\\`. Some examples | |
1846 | ||
1847 | \\pr PROCEDURE template | |
1848 | \\fu FUNCTION template | |
1849 | \\c CASE statement template | |
05a1abfc | 1850 | \\sw SWITCH statement template |
f32b3b91 CD |
1851 | \\f FOR loop template |
1852 | \\r REPEAT Loop template | |
1853 | \\w WHILE loop template | |
1854 | \\i IF statement template | |
1855 | \\elif IF-ELSE statement template | |
1856 | \\b BEGIN | |
4b1aaa8b | 1857 | |
52a244eb S |
1858 | For a full list, use \\[idlwave-list-abbrevs]. Some templates also |
1859 | have direct keybindings - see the list of keybindings below. | |
775591f7 | 1860 | |
52a244eb S |
1861 | \\[idlwave-doc-header] inserts a documentation header at the |
1862 | beginning of the current program unit (pro, function or main). | |
1863 | Change log entries can be added to the current program unit with | |
1864 | \\[idlwave-doc-modification]. | |
f32b3b91 | 1865 | |
15e42531 | 1866 | 6. Automatic Case Conversion |
f32b3b91 CD |
1867 | ------------------------- |
1868 | The case of reserved words and some abbrevs is controlled by | |
1869 | `idlwave-reserved-word-upcase' and `idlwave-abbrev-change-case'. | |
1870 | ||
15e42531 | 1871 | 7. Automatic END completion |
f32b3b91 CD |
1872 | ------------------------ |
1873 | If the variable `idlwave-expand-generic-end' is non-nil, each END typed | |
1874 | will be converted to the specific version, like ENDIF, ENDFOR, etc. | |
1875 | ||
15e42531 | 1876 | 8. Hooks |
f32b3b91 CD |
1877 | ----- |
1878 | Loading idlwave.el runs `idlwave-load-hook'. | |
1879 | Turning on `idlwave-mode' runs `idlwave-mode-hook'. | |
1880 | ||
15e42531 | 1881 | 9. Documentation and Customization |
f32b3b91 | 1882 | ------------------------------- |
5e72c6b2 S |
1883 | Info documentation for this package is available. Use |
1884 | \\[idlwave-info] to display (complain to your sysadmin if that does | |
1885 | not work). For Postscript, PDF, and HTML versions of the | |
1886 | documentation, check IDLWAVE's homepage at `http://idlwave.org'. | |
f32b3b91 CD |
1887 | IDLWAVE has customize support - see the group `idlwave'. |
1888 | ||
15e42531 | 1889 | 10.Keybindings |
f32b3b91 CD |
1890 | ----------- |
1891 | Here is a list of all keybindings of this mode. | |
1892 | If some of the key bindings below show with ??, use \\[describe-key] | |
1893 | followed by the key sequence to see what the key sequence does. | |
1894 | ||
1895 | \\{idlwave-mode-map}" | |
1896 | ||
1897 | (interactive) | |
1898 | (kill-all-local-variables) | |
4b1aaa8b | 1899 | |
f32b3b91 CD |
1900 | (if idlwave-startup-message |
1901 | (message "Emacs IDLWAVE mode version %s." idlwave-mode-version)) | |
1902 | (setq idlwave-startup-message nil) | |
4b1aaa8b | 1903 | |
f32b3b91 CD |
1904 | (setq local-abbrev-table idlwave-mode-abbrev-table) |
1905 | (set-syntax-table idlwave-mode-syntax-table) | |
4b1aaa8b | 1906 | |
f32b3b91 | 1907 | (set (make-local-variable 'indent-line-function) 'idlwave-indent-and-action) |
4b1aaa8b | 1908 | |
f32b3b91 CD |
1909 | (make-local-variable idlwave-comment-indent-function) |
1910 | (set idlwave-comment-indent-function 'idlwave-comment-hook) | |
4b1aaa8b | 1911 | |
f32b3b91 CD |
1912 | (set (make-local-variable 'comment-start-skip) ";+[ \t]*") |
1913 | (set (make-local-variable 'comment-start) ";") | |
0dc2be2f | 1914 | (set (make-local-variable 'comment-add) 1) ; ";;" for new and regions |
f66f03de | 1915 | (set (make-local-variable 'require-final-newline) t) |
f32b3b91 CD |
1916 | (set (make-local-variable 'abbrev-all-caps) t) |
1917 | (set (make-local-variable 'indent-tabs-mode) nil) | |
1918 | (set (make-local-variable 'completion-ignore-case) t) | |
4b1aaa8b | 1919 | |
f32b3b91 CD |
1920 | (use-local-map idlwave-mode-map) |
1921 | ||
1922 | (when (featurep 'easymenu) | |
1923 | (easy-menu-add idlwave-mode-menu idlwave-mode-map) | |
1924 | (easy-menu-add idlwave-mode-debug-menu idlwave-mode-map)) | |
1925 | ||
1926 | (setq mode-name "IDLWAVE") | |
1927 | (setq major-mode 'idlwave-mode) | |
1928 | (setq abbrev-mode t) | |
4b1aaa8b | 1929 | |
f32b3b91 CD |
1930 | (set (make-local-variable idlwave-fill-function) 'idlwave-auto-fill) |
1931 | (setq comment-end "") | |
1932 | (set (make-local-variable 'comment-multi-line) nil) | |
4b1aaa8b | 1933 | (set (make-local-variable 'paragraph-separate) |
5e72c6b2 | 1934 | "[ \t\f]*$\\|[ \t]*;+[ \t]*$\\|;+[+=-_*]+$") |
f32b3b91 CD |
1935 | (set (make-local-variable 'paragraph-start) "[ \t\f]\\|[ \t]*;+[ \t]") |
1936 | (set (make-local-variable 'paragraph-ignore-fill-prefix) nil) | |
76959b77 | 1937 | (set (make-local-variable 'parse-sexp-ignore-comments) t) |
775591f7 | 1938 | |
e08734e2 | 1939 | ;; ChangeLog |
8c43762b | 1940 | (set (make-local-variable 'add-log-current-defun-function) |
e08734e2 S |
1941 | 'idlwave-current-routine-fullname) |
1942 | ||
f32b3b91 CD |
1943 | ;; Set tag table list to use IDLTAGS as file name. |
1944 | (if (boundp 'tag-table-alist) | |
1945 | (add-to-list 'tag-table-alist '("\\.pro$" . "IDLTAGS"))) | |
4b1aaa8b | 1946 | |
e08734e2 | 1947 | ;; Font-lock additions |
52a244eb | 1948 | ;; Following line is for Emacs - XEmacs uses the corresponding property |
f32b3b91 CD |
1949 | ;; on the `idlwave-mode' symbol. |
1950 | (set (make-local-variable 'font-lock-defaults) idlwave-font-lock-defaults) | |
0dc2be2f S |
1951 | (set (make-local-variable 'font-lock-mark-block-function) |
1952 | 'idlwave-mark-subprogram) | |
1953 | (set (make-local-variable 'font-lock-fontify-region-function) | |
1954 | 'idlwave-font-lock-fontify-region) | |
f32b3b91 CD |
1955 | |
1956 | ;; Imenu setup | |
1957 | (set (make-local-variable 'imenu-create-index-function) | |
1958 | 'imenu-default-create-index-function) | |
1959 | (set (make-local-variable 'imenu-extract-index-name-function) | |
1960 | 'idlwave-unit-name) | |
1961 | (set (make-local-variable 'imenu-prev-index-position-function) | |
1962 | 'idlwave-prev-index-position) | |
1963 | ||
0dc2be2f S |
1964 | ;; HideShow setup |
1965 | (add-to-list 'hs-special-modes-alist | |
1966 | (list 'idlwave-mode | |
1967 | idlwave-begin-block-reg | |
1968 | idlwave-end-block-reg | |
1969 | ";" | |
1970 | 'idlwave-forward-block nil)) | |
4b1aaa8b | 1971 | |
f32b3b91 | 1972 | ;; Make a local post-command-hook and add our hook to it |
f66f03de S |
1973 | ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility |
1974 | ;; (make-local-hook 'post-command-hook) | |
15e42531 CD |
1975 | (add-hook 'post-command-hook 'idlwave-command-hook nil 'local) |
1976 | ||
1977 | ;; Make local hooks for buffer updates | |
f66f03de S |
1978 | ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility |
1979 | ;; (make-local-hook 'kill-buffer-hook) | |
15e42531 | 1980 | (add-hook 'kill-buffer-hook 'idlwave-kill-buffer-update nil 'local) |
f66f03de | 1981 | ;; (make-local-hook 'after-save-hook) |
e08734e2 | 1982 | (add-hook 'after-save-hook 'idlwave-save-buffer-update nil 'local) |
15e42531 CD |
1983 | (add-hook 'after-save-hook 'idlwave-revoke-license-to-kill nil 'local) |
1984 | ||
52a244eb S |
1985 | ;; Setup directories and file, if necessary |
1986 | (idlwave-setup) | |
1987 | ||
15e42531 CD |
1988 | ;; Update the routine info with info about current buffer? |
1989 | (idlwave-new-buffer-update) | |
f32b3b91 | 1990 | |
f66f03de S |
1991 | ;; Check help location |
1992 | (idlwave-help-check-locations) | |
1993 | ||
f32b3b91 | 1994 | ;; Run the mode hook |
9a969196 | 1995 | (run-mode-hooks 'idlwave-mode-hook)) |
f32b3b91 | 1996 | |
52a244eb S |
1997 | (defvar idlwave-setup-done nil) |
1998 | (defun idlwave-setup () | |
1999 | (unless idlwave-setup-done | |
2000 | (if (not (file-directory-p idlwave-config-directory)) | |
2001 | (make-directory idlwave-config-directory)) | |
4b1aaa8b PE |
2002 | (setq |
2003 | idlwave-user-catalog-file (expand-file-name | |
2004 | idlwave-user-catalog-file | |
f66f03de | 2005 | idlwave-config-directory) |
4b1aaa8b PE |
2006 | idlwave-xml-system-rinfo-converted-file |
2007 | (expand-file-name | |
f66f03de S |
2008 | idlwave-xml-system-rinfo-converted-file |
2009 | idlwave-config-directory) | |
4b1aaa8b PE |
2010 | idlwave-path-file (expand-file-name |
2011 | idlwave-path-file | |
f66f03de | 2012 | idlwave-config-directory)) |
52a244eb S |
2013 | (idlwave-read-paths) ; we may need these early |
2014 | (setq idlwave-setup-done t))) | |
2015 | ||
0dc2be2f S |
2016 | (defun idlwave-font-lock-fontify-region (beg end &optional verbose) |
2017 | "Fontify continuation lines correctly." | |
2018 | (let (pos) | |
2019 | (save-excursion | |
2020 | (goto-char beg) | |
2021 | (forward-line -1) | |
2022 | (when (setq pos (idlwave-is-continuation-line)) | |
2023 | (goto-char pos) | |
2024 | (idlwave-beginning-of-statement) | |
2025 | (setq beg (point))))) | |
2026 | (font-lock-default-fontify-region beg end verbose)) | |
2027 | ||
f32b3b91 | 2028 | ;; |
52a244eb | 2029 | ;; Code Formatting ---------------------------------------------------- |
4b1aaa8b | 2030 | ;; |
f32b3b91 | 2031 | |
f32b3b91 CD |
2032 | (defun idlwave-hard-tab () |
2033 | "Inserts TAB in buffer in current position." | |
2034 | (interactive) | |
2035 | (insert "\t")) | |
2036 | ||
2037 | ;;; This stuff is experimental | |
2038 | ||
2039 | (defvar idlwave-command-hook nil | |
2040 | "If non-nil, a list that can be evaluated using `eval'. | |
2041 | It is evaluated in the lisp function `idlwave-command-hook' which is | |
2042 | placed in `post-command-hook'.") | |
2043 | ||
2044 | (defun idlwave-command-hook () | |
2045 | "Command run after every command. | |
2046 | Evaluates a non-nil value of the *variable* `idlwave-command-hook' and | |
2047 | sets the variable to zero afterwards." | |
2048 | (and idlwave-command-hook | |
2049 | (listp idlwave-command-hook) | |
2050 | (condition-case nil | |
2051 | (eval idlwave-command-hook) | |
2052 | (error nil))) | |
2053 | (setq idlwave-command-hook nil)) | |
2054 | ||
2055 | ;;; End experiment | |
2056 | ||
2057 | ;; It would be better to use expand.el for better abbrev handling and | |
2058 | ;; versatility. | |
2059 | ||
2060 | (defun idlwave-check-abbrev (arg &optional reserved) | |
2061 | "Reverses abbrev expansion if in comment or string. | |
2062 | Argument ARG is the number of characters to move point | |
2063 | backward if `idlwave-abbrev-move' is non-nil. | |
2064 | If optional argument RESERVED is non-nil then the expansion | |
2065 | consists of reserved words, which will be capitalized if | |
2066 | `idlwave-reserved-word-upcase' is non-nil. | |
2067 | Otherwise, the abbrev will be capitalized if `idlwave-abbrev-change-case' | |
2068 | is non-nil, unless its value is \`down in which case the abbrev will be | |
2069 | made into all lowercase. | |
2070 | Returns non-nil if abbrev is left expanded." | |
2071 | (if (idlwave-quoted) | |
2072 | (progn (unexpand-abbrev) | |
2073 | nil) | |
2074 | (if (and reserved idlwave-reserved-word-upcase) | |
2075 | (upcase-region last-abbrev-location (point)) | |
2076 | (cond | |
2077 | ((equal idlwave-abbrev-change-case 'down) | |
2078 | (downcase-region last-abbrev-location (point))) | |
2079 | (idlwave-abbrev-change-case | |
2080 | (upcase-region last-abbrev-location (point))))) | |
2081 | (if (and idlwave-abbrev-move (> arg 0)) | |
2082 | (if (boundp 'post-command-hook) | |
2083 | (setq idlwave-command-hook (list 'backward-char (1+ arg))) | |
2084 | (backward-char arg))) | |
2085 | t)) | |
2086 | ||
2087 | (defun idlwave-in-comment () | |
2088 | "Returns t if point is inside a comment, nil otherwise." | |
2089 | (save-excursion | |
2090 | (let ((here (point))) | |
2091 | (and (idlwave-goto-comment) (> here (point)))))) | |
2092 | ||
2093 | (defun idlwave-goto-comment () | |
2094 | "Move to start of comment delimiter on current line. | |
2095 | Moves to end of line if there is no comment delimiter. | |
2096 | Ignores comment delimiters in strings. | |
2097 | Returns point if comment found and nil otherwise." | |
2098 | (let ((eos (progn (end-of-line) (point))) | |
2099 | (data (match-data)) | |
2100 | found) | |
2101 | ;; Look for first comment delimiter not in a string | |
2102 | (beginning-of-line) | |
2103 | (setq found (search-forward comment-start eos 'lim)) | |
2104 | (while (and found (idlwave-in-quote)) | |
2105 | (setq found (search-forward comment-start eos 'lim))) | |
2106 | (store-match-data data) | |
2107 | (and found (not (idlwave-in-quote)) | |
2108 | (progn | |
2109 | (backward-char 1) | |
2110 | (point))))) | |
2111 | ||
5e72c6b2 | 2112 | (defun idlwave-region-active-p () |
a00e54f7 RS |
2113 | "Should we operate on an active region?" |
2114 | (if (fboundp 'use-region-p) | |
2115 | (use-region-p) | |
2116 | (region-active-p))) | |
5e72c6b2 | 2117 | |
f32b3b91 CD |
2118 | (defun idlwave-show-matching-quote () |
2119 | "Insert quote and show matching quote if this is end of a string." | |
2120 | (interactive) | |
2121 | (let ((bq (idlwave-in-quote)) | |
1ba983e8 | 2122 | (inq last-command-event)) |
f32b3b91 CD |
2123 | (if (and bq (not (idlwave-in-comment))) |
2124 | (let ((delim (char-after bq))) | |
2125 | (insert inq) | |
2126 | (if (eq inq delim) | |
2127 | (save-excursion | |
2128 | (goto-char bq) | |
2129 | (sit-for 1)))) | |
2130 | ;; Not the end of a string | |
2131 | (insert inq)))) | |
2132 | ||
2133 | (defun idlwave-show-begin-check () | |
2134 | "Ensure that the previous word was a token before `idlwave-show-begin'. | |
2135 | An END token must be preceded by whitespace." | |
5e72c6b2 S |
2136 | (if (not (idlwave-quoted)) |
2137 | (if | |
2138 | (save-excursion | |
2139 | (backward-word 1) | |
2140 | (backward-char 1) | |
2141 | (looking-at "[ \t\n\f]")) | |
2142 | (idlwave-show-begin)))) | |
f32b3b91 CD |
2143 | |
2144 | (defun idlwave-show-begin () | |
2145 | "Finds the start of current block and blinks to it for a second. | |
2146 | Also checks if the correct end statement has been used." | |
2147 | ;; All end statements are reserved words | |
76959b77 | 2148 | ;; Re-indent end line |
52a244eb S |
2149 | ;;(insert-char ?\ 1) ;; So indent, etc. work well |
2150 | ;;(backward-char 1) | |
76959b77 S |
2151 | (let* ((pos (point-marker)) |
2152 | (last-abbrev-marker (copy-marker last-abbrev-location)) | |
2153 | (eol-pos (save-excursion (end-of-line) (point))) | |
2154 | begin-pos end-pos end end1 ) | |
2155 | (if idlwave-reindent-end (idlwave-indent-line)) | |
52a244eb | 2156 | (setq last-abbrev-location (marker-position last-abbrev-marker)) |
f32b3b91 CD |
2157 | (when (and (idlwave-check-abbrev 0 t) |
2158 | idlwave-show-block) | |
2159 | (save-excursion | |
2160 | ;; Move inside current block | |
76959b77 | 2161 | (goto-char last-abbrev-marker) |
f32b3b91 | 2162 | (idlwave-block-jump-out -1 'nomark) |
76959b77 S |
2163 | (setq begin-pos (point)) |
2164 | (idlwave-block-jump-out 1 'nomark) | |
2165 | (setq end-pos (point)) | |
2166 | (if (> end-pos eol-pos) | |
2167 | (setq end-pos pos)) | |
2168 | (goto-char end-pos) | |
4b1aaa8b | 2169 | (setq end (buffer-substring |
76959b77 S |
2170 | (progn |
2171 | (skip-chars-backward "a-zA-Z") | |
2172 | (point)) | |
2173 | end-pos)) | |
2174 | (goto-char begin-pos) | |
f32b3b91 CD |
2175 | (when (setq end1 (cdr (idlwave-block-master))) |
2176 | (cond | |
5e72c6b2 | 2177 | ((null end1)) ; no-operation |
f32b3b91 CD |
2178 | ((string= (downcase end) (downcase end1)) |
2179 | (sit-for 1)) | |
2180 | ((string= (downcase end) "end") | |
2181 | ;; A generic end | |
2182 | (if idlwave-expand-generic-end | |
2183 | (save-excursion | |
2184 | (goto-char pos) | |
2185 | (backward-char 3) | |
2186 | (insert (if (string= end "END") (upcase end1) end1)) | |
2187 | (delete-char 3))) | |
2188 | (sit-for 1)) | |
2189 | (t | |
2190 | (beep) | |
4b1aaa8b | 2191 | (message "Warning: Shouldn't this be \"%s\" instead of \"%s\"?" |
f32b3b91 | 2192 | end1 end) |
52a244eb S |
2193 | (sit-for 1)))))))) |
2194 | ;;(delete-char 1)) | |
f32b3b91 CD |
2195 | |
2196 | (defun idlwave-block-master () | |
2197 | (let ((case-fold-search t)) | |
2198 | (save-excursion | |
2199 | (cond | |
05a1abfc | 2200 | ((looking-at "pro\\|case\\|switch\\|function\\>") |
f32b3b91 CD |
2201 | (assoc (downcase (match-string 0)) idlwave-block-matches)) |
2202 | ((looking-at "begin\\>") | |
4b1aaa8b PE |
2203 | (let ((limit (save-excursion |
2204 | (idlwave-beginning-of-statement) | |
f32b3b91 CD |
2205 | (point)))) |
2206 | (cond | |
52a244eb S |
2207 | ((re-search-backward ":[ \t]*\\=" limit t) |
2208 | ;; seems to be a case thing | |
2209 | '("begin" . "end")) | |
f32b3b91 CD |
2210 | ((re-search-backward idlwave-block-match-regexp limit t) |
2211 | (assoc (downcase (match-string 1)) | |
2212 | idlwave-block-matches)) | |
f32b3b91 | 2213 | (t |
52a244eb | 2214 | ;; Just a normal block |
f32b3b91 CD |
2215 | '("begin" . "end"))))) |
2216 | (t nil))))) | |
2217 | ||
2218 | (defun idlwave-close-block () | |
2219 | "Terminate the current block with the correct END statement." | |
2220 | (interactive) | |
f32b3b91 CD |
2221 | ;; Start new line if we are not in a new line |
2222 | (unless (save-excursion | |
2223 | (skip-chars-backward " \t") | |
2224 | (bolp)) | |
2225 | (let ((idlwave-show-block nil)) | |
2226 | (newline-and-indent))) | |
5e72c6b2 S |
2227 | (let ((last-abbrev-location (point))) ; for upcasing |
2228 | (insert "end") | |
2229 | (idlwave-show-begin))) | |
2230 | ||
f66f03de S |
2231 | (defun idlwave-custom-ampersand-surround (&optional is-action) |
2232 | "Surround &, leaving room for && (which surrround as well)." | |
2233 | (let* ((prev-char (char-after (- (point) 2))) | |
2234 | (next-char (char-after (point))) | |
2235 | (amp-left (eq prev-char ?&)) | |
2236 | (amp-right (eq next-char ?&)) | |
2237 | (len (if amp-left 2 1))) | |
2238 | (unless amp-right ;no need to do it twice, amp-left will catch it. | |
2239 | (idlwave-surround -1 (if (or is-action amp-left) -1) len)))) | |
2240 | ||
2241 | (defun idlwave-custom-ltgtr-surround (gtr &optional is-action) | |
2242 | "Surround > and < by blanks, leaving room for >= and <=, and considering ->." | |
2243 | (let* ((prev-char (char-after (- (point) 2))) | |
2244 | (next-char (char-after (point))) | |
2245 | (method-invoke (and gtr (eq prev-char ?-))) | |
2246 | (len (if method-invoke 2 1))) | |
2247 | (unless (eq next-char ?=) | |
2248 | ;; Key binding: pad only on left, to save for possible >=/<= | |
2249 | (idlwave-surround -1 (if (or is-action method-invoke) -1) len)))) | |
2250 | ||
2251 | (defun idlwave-surround (&optional before after length is-action) | |
595ab50b CD |
2252 | "Surround the LENGTH characters before point with blanks. |
2253 | LENGTH defaults to 1. | |
f32b3b91 | 2254 | Optional arguments BEFORE and AFTER affect the behavior before and |
595ab50b CD |
2255 | after the characters (see also description of `idlwave-make-space'): |
2256 | ||
2257 | nil do nothing | |
2258 | 0 force no spaces | |
2259 | integer > 0 force exactly n spaces | |
2260 | integer < 0 at least |n| spaces | |
f32b3b91 CD |
2261 | |
2262 | The function does nothing if any of the following conditions is true: | |
2263 | - `idlwave-surround-by-blank' is nil | |
f66f03de | 2264 | - the character before point is inside a string or comment" |
5e72c6b2 | 2265 | (when (and idlwave-surround-by-blank (not (idlwave-quoted))) |
f66f03de S |
2266 | (let ((length (or length 1))) ; establish a default for LENGTH |
2267 | (backward-char length) | |
2268 | (save-restriction | |
2269 | (let ((here (point))) | |
2270 | (skip-chars-backward " \t") | |
2271 | (if (bolp) | |
2272 | ;; avoid clobbering indent | |
2273 | (progn | |
2274 | (move-to-column (idlwave-calculate-indent)) | |
2275 | (if (<= (point) here) | |
2276 | (narrow-to-region (point) here)) | |
2277 | (goto-char here))) | |
2278 | (idlwave-make-space before)) | |
2279 | (skip-chars-forward " \t")) | |
2280 | (forward-char length) | |
2281 | (idlwave-make-space after) | |
2282 | ;; Check to see if the line should auto wrap | |
2283 | (if (and (equal (char-after (1- (point))) ?\ ) | |
2284 | (> (current-column) fill-column)) | |
2285 | (funcall auto-fill-function))))) | |
f32b3b91 CD |
2286 | |
2287 | (defun idlwave-make-space (n) | |
2288 | "Make space at point. | |
2289 | The space affected is all the spaces and tabs around point. | |
2290 | If n is non-nil then point is left abs(n) spaces from the beginning of | |
2291 | the contiguous space. | |
2292 | The amount of space at point is determined by N. | |
2293 | If the value of N is: | |
2294 | nil - do nothing. | |
595ab50b CD |
2295 | > 0 - exactly N spaces. |
2296 | < 0 - a minimum of -N spaces, i.e., do not change if there are | |
2297 | already -N spaces. | |
2298 | 0 - no spaces (i.e. remove any existing space)." | |
f32b3b91 CD |
2299 | (if (integerp n) |
2300 | (let | |
2301 | ((start-col (progn (skip-chars-backward " \t") (current-column))) | |
2302 | (left (point)) | |
2303 | (end-col (progn (skip-chars-forward " \t") (current-column)))) | |
2304 | (delete-horizontal-space) | |
2305 | (cond | |
2306 | ((> n 0) | |
2307 | (idlwave-indent-to (+ start-col n)) | |
2308 | (goto-char (+ left n))) | |
2309 | ((< n 0) | |
2310 | (idlwave-indent-to end-col (- n)) | |
2311 | (goto-char (- left n))) | |
2312 | ;; n = 0, done | |
2313 | )))) | |
2314 | ||
2315 | (defun idlwave-newline () | |
2316 | "Inserts a newline and indents the current and previous line." | |
2317 | (interactive) | |
2318 | ;; | |
2319 | ;; Handle unterminated single and double quotes | |
2320 | ;; If not in a comment and in a string then insertion of a newline | |
2321 | ;; will mean unbalanced quotes. | |
2322 | ;; | |
2323 | (if (and (not (idlwave-in-comment)) (idlwave-in-quote)) | |
2324 | (progn (beep) | |
2325 | (message "Warning: unbalanced quotes?"))) | |
2326 | (newline) | |
2327 | ;; | |
2328 | ;; The current line is being split, the cursor should be at the | |
2329 | ;; beginning of the new line skipping the leading indentation. | |
2330 | ;; | |
2331 | ;; The reason we insert the new line before indenting is that the | |
2332 | ;; indenting could be confused by keywords (e.g. END) on the line | |
2333 | ;; after the split point. This prevents us from just using | |
2334 | ;; `indent-for-tab-command' followed by `newline-and-indent'. | |
2335 | ;; | |
2336 | (beginning-of-line 0) | |
2337 | (idlwave-indent-line) | |
2338 | (forward-line) | |
2339 | (idlwave-indent-line)) | |
2340 | ||
2341 | ;; | |
2342 | ;; Use global variable 'comment-column' to set parallel comment | |
2343 | ;; | |
2344 | ;; Modeled on lisp.el | |
2345 | ;; Emacs Lisp and IDL (Wave CL) have identical comment syntax | |
2346 | (defun idlwave-comment-hook () | |
2347 | "Compute indent for the beginning of the IDL comment delimiter." | |
2348 | (if (or (looking-at idlwave-no-change-comment) | |
2349 | (if idlwave-begin-line-comment | |
2350 | (looking-at idlwave-begin-line-comment) | |
2351 | (looking-at "^;"))) | |
2352 | (current-column) | |
2353 | (if (looking-at idlwave-code-comment) | |
2354 | (if (save-excursion (skip-chars-backward " \t") (bolp)) | |
2355 | ;; On line by itself, indent as code | |
2356 | (let ((tem (idlwave-calculate-indent))) | |
2357 | (if (listp tem) (car tem) tem)) | |
2358 | ;; after code - do not change | |
2359 | (current-column)) | |
2360 | (skip-chars-backward " \t") | |
2361 | (max (if (bolp) 0 (1+ (current-column))) | |
2362 | comment-column)))) | |
2363 | ||
2364 | (defun idlwave-split-line () | |
2365 | "Continue line by breaking line at point and indent the lines. | |
2366 | For a code line insert continuation marker. If the line is a line comment | |
2367 | then the new line will contain a comment with the same indentation. | |
2368 | Splits strings with the IDL operator `+' if `idlwave-split-line-string' is | |
2369 | non-nil." | |
2370 | (interactive) | |
15e42531 CD |
2371 | ;; Expand abbreviation, just like normal RET would. |
2372 | (and abbrev-mode (expand-abbrev)) | |
f32b3b91 CD |
2373 | (let (beg) |
2374 | (if (not (idlwave-in-comment)) | |
2375 | ;; For code line add continuation. | |
2376 | ;; Check if splitting a string. | |
2377 | (progn | |
2378 | (if (setq beg (idlwave-in-quote)) | |
2379 | (if idlwave-split-line-string | |
2380 | ;; Split the string. | |
2381 | (progn (insert (setq beg (char-after beg)) " + " | |
2382 | idlwave-continuation-char beg) | |
5e72c6b2 S |
2383 | (backward-char 1) |
2384 | (newline-and-indent) | |
2385 | (forward-char 1)) | |
f32b3b91 CD |
2386 | ;; Do not split the string. |
2387 | (beep) | |
2388 | (message "Warning: continuation inside string!!") | |
2389 | (insert " " idlwave-continuation-char)) | |
2390 | ;; Not splitting a string. | |
15e42531 CD |
2391 | (if (not (member (char-before) '(?\ ?\t))) |
2392 | (insert " ")) | |
5e72c6b2 S |
2393 | (insert idlwave-continuation-char) |
2394 | (newline-and-indent))) | |
f32b3b91 CD |
2395 | (indent-new-comment-line)) |
2396 | ;; Indent previous line | |
2397 | (setq beg (- (point-max) (point))) | |
2398 | (forward-line -1) | |
2399 | (idlwave-indent-line) | |
2400 | (goto-char (- (point-max) beg)) | |
2401 | ;; Reindent new line | |
2402 | (idlwave-indent-line))) | |
2403 | ||
cca13260 S |
2404 | (defun idlwave-beginning-of-subprogram (&optional nomark) |
2405 | "Moves point to the beginning of the current program unit. | |
2406 | If NOMARK is non-nil, do not push mark." | |
f32b3b91 | 2407 | (interactive) |
cca13260 | 2408 | (idlwave-find-key idlwave-begin-unit-reg -1 nomark)) |
f32b3b91 | 2409 | |
cca13260 S |
2410 | (defun idlwave-end-of-subprogram (&optional nomark) |
2411 | "Moves point to the start of the next program unit. | |
2412 | If NOMARK is non-nil, do not push mark." | |
f32b3b91 CD |
2413 | (interactive) |
2414 | (idlwave-end-of-statement) | |
cca13260 | 2415 | (idlwave-find-key idlwave-end-unit-reg 1 nomark)) |
f32b3b91 CD |
2416 | |
2417 | (defun idlwave-mark-statement () | |
2418 | "Mark current IDL statement." | |
2419 | (interactive) | |
2420 | (idlwave-end-of-statement) | |
2421 | (let ((end (point))) | |
2422 | (idlwave-beginning-of-statement) | |
0dc2be2f | 2423 | (push-mark end nil t))) |
f32b3b91 CD |
2424 | |
2425 | (defun idlwave-mark-block () | |
2426 | "Mark containing block." | |
2427 | (interactive) | |
2428 | (idlwave-end-of-statement) | |
2429 | (idlwave-backward-up-block -1) | |
2430 | (idlwave-end-of-statement) | |
2431 | (let ((end (point))) | |
2432 | (idlwave-backward-block) | |
2433 | (idlwave-beginning-of-statement) | |
0dc2be2f | 2434 | (push-mark end nil t))) |
f32b3b91 CD |
2435 | |
2436 | ||
2437 | (defun idlwave-mark-subprogram () | |
2438 | "Put mark at beginning of program, point at end. | |
2439 | The marks are pushed." | |
2440 | (interactive) | |
2441 | (idlwave-end-of-statement) | |
2442 | (idlwave-beginning-of-subprogram) | |
2443 | (let ((beg (point))) | |
2444 | (idlwave-forward-block) | |
0dc2be2f | 2445 | (push-mark beg nil t)) |
f32b3b91 CD |
2446 | (exchange-point-and-mark)) |
2447 | ||
2448 | (defun idlwave-backward-up-block (&optional arg) | |
2449 | "Move to beginning of enclosing block if prefix ARG >= 0. | |
2450 | If prefix ARG < 0 then move forward to enclosing block end." | |
2451 | (interactive "p") | |
2452 | (idlwave-block-jump-out (- arg) 'nomark)) | |
2453 | ||
2454 | (defun idlwave-beginning-of-block () | |
2455 | "Go to the beginning of the current block." | |
2456 | (interactive) | |
2457 | (idlwave-block-jump-out -1 'nomark) | |
2458 | (forward-word 1)) | |
2459 | ||
2460 | (defun idlwave-end-of-block () | |
2461 | "Go to the beginning of the current block." | |
2462 | (interactive) | |
2463 | (idlwave-block-jump-out 1 'nomark) | |
2464 | (backward-word 1)) | |
2465 | ||
0dc2be2f | 2466 | (defun idlwave-forward-block (&optional arg) |
f32b3b91 CD |
2467 | "Move across next nested block." |
2468 | (interactive) | |
0dc2be2f S |
2469 | (let ((arg (or arg 1))) |
2470 | (if (idlwave-down-block arg) | |
2471 | (idlwave-block-jump-out arg 'nomark)))) | |
f32b3b91 CD |
2472 | |
2473 | (defun idlwave-backward-block () | |
2474 | "Move backward across previous nested block." | |
2475 | (interactive) | |
2476 | (if (idlwave-down-block -1) | |
2477 | (idlwave-block-jump-out -1 'nomark))) | |
2478 | ||
2479 | (defun idlwave-down-block (&optional arg) | |
2480 | "Go down a block. | |
2481 | With ARG: ARG >= 0 go forwards, ARG < 0 go backwards. | |
2482 | Returns non-nil if successfull." | |
2483 | (interactive "p") | |
2484 | (let (status) | |
2485 | (if (< arg 0) | |
2486 | ;; Backward | |
2487 | (let ((eos (save-excursion | |
2488 | (idlwave-block-jump-out -1 'nomark) | |
2489 | (point)))) | |
4b1aaa8b | 2490 | (if (setq status (idlwave-find-key |
f32b3b91 CD |
2491 | idlwave-end-block-reg -1 'nomark eos)) |
2492 | (idlwave-beginning-of-statement) | |
2493 | (message "No nested block before beginning of containing block."))) | |
2494 | ;; Forward | |
2495 | (let ((eos (save-excursion | |
2496 | (idlwave-block-jump-out 1 'nomark) | |
2497 | (point)))) | |
4b1aaa8b | 2498 | (if (setq status (idlwave-find-key |
f32b3b91 CD |
2499 | idlwave-begin-block-reg 1 'nomark eos)) |
2500 | (idlwave-end-of-statement) | |
2501 | (message "No nested block before end of containing block.")))) | |
2502 | status)) | |
2503 | ||
2504 | (defun idlwave-mark-doclib () | |
2505 | "Put point at beginning of doc library header, mark at end. | |
2506 | The marks are pushed." | |
2507 | (interactive) | |
2508 | (let (beg | |
2509 | (here (point))) | |
2510 | (goto-char (point-max)) | |
2511 | (if (re-search-backward idlwave-doclib-start nil t) | |
4b1aaa8b | 2512 | (progn |
f32b3b91 CD |
2513 | (setq beg (progn (beginning-of-line) (point))) |
2514 | (if (re-search-forward idlwave-doclib-end nil t) | |
2515 | (progn | |
2516 | (forward-line 1) | |
0dc2be2f | 2517 | (push-mark beg nil t) |
f32b3b91 CD |
2518 | (message "Could not find end of doc library header."))) |
2519 | (message "Could not find doc library header start.") | |
2520 | (goto-char here))))) | |
2521 | ||
e08734e2 S |
2522 | (defun idlwave-current-routine-fullname () |
2523 | (let ((name (idlwave-current-routine))) | |
2524 | (idlwave-make-full-name (nth 2 name) (car name)))) | |
2525 | ||
15e42531 CD |
2526 | (defun idlwave-current-routine () |
2527 | "Return (NAME TYPE CLASS) of current routine." | |
2528 | (idlwave-routines) | |
2529 | (save-excursion | |
cca13260 | 2530 | (idlwave-beginning-of-subprogram 'nomark) |
15e42531 CD |
2531 | (if (looking-at "[ \t]*\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)") |
2532 | (let* ((type (if (string= (downcase (match-string 1)) "pro") | |
2533 | 'pro 'function)) | |
2534 | (class (idlwave-sintern-class (match-string 3))) | |
2535 | (name (idlwave-sintern-routine-or-method (match-string 4) class))) | |
2536 | (list name type class))))) | |
2537 | ||
f32b3b91 CD |
2538 | (defvar idlwave-shell-prompt-pattern) |
2539 | (defun idlwave-beginning-of-statement () | |
2540 | "Move to beginning of the current statement. | |
2541 | Skips back past statement continuations. | |
2542 | Point is placed at the beginning of the line whether or not this is an | |
2543 | actual statement." | |
2544 | (interactive) | |
2545 | (cond | |
2546 | ((eq major-mode 'idlwave-shell-mode) | |
2547 | (if (re-search-backward idlwave-shell-prompt-pattern nil t) | |
2548 | (goto-char (match-end 0)))) | |
4b1aaa8b | 2549 | (t |
f32b3b91 CD |
2550 | (if (save-excursion (forward-line -1) (idlwave-is-continuation-line)) |
2551 | (idlwave-previous-statement) | |
2552 | (beginning-of-line))))) | |
2553 | ||
2554 | (defun idlwave-previous-statement () | |
2555 | "Moves point to beginning of the previous statement. | |
2556 | Returns t if the current line before moving is the beginning of | |
2557 | the first non-comment statement in the file, and nil otherwise." | |
2558 | (interactive) | |
2559 | (let (first-statement) | |
2560 | (if (not (= (forward-line -1) 0)) | |
2561 | ;; first line in file | |
2562 | t | |
2563 | ;; skip blank lines, label lines, include lines and line comments | |
2564 | (while (and | |
2565 | ;; The current statement is the first statement until we | |
2566 | ;; reach another statement. | |
2567 | (setq first-statement | |
2568 | (or | |
2569 | (looking-at idlwave-comment-line-start-skip) | |
2570 | (looking-at "[ \t]*$") | |
2571 | (looking-at (concat "[ \t]*" idlwave-label "[ \t]*$")) | |
2572 | (looking-at "^@"))) | |
2573 | (= (forward-line -1) 0))) | |
2574 | ;; skip continuation lines | |
2575 | (while (and | |
2576 | (save-excursion | |
2577 | (forward-line -1) | |
2578 | (idlwave-is-continuation-line)) | |
2579 | (= (forward-line -1) 0))) | |
2580 | first-statement))) | |
2581 | ||
f32b3b91 CD |
2582 | (defun idlwave-end-of-statement () |
2583 | "Moves point to the end of the current IDL statement. | |
05a1abfc CD |
2584 | If not in a statement just moves to end of line. Returns position." |
2585 | (interactive) | |
2586 | (while (and (idlwave-is-continuation-line) | |
2587 | (= (forward-line 1) 0)) | |
2588 | (while (and (idlwave-is-comment-or-empty-line) | |
2589 | (= (forward-line 1) 0)))) | |
2590 | (end-of-line) | |
2591 | (point)) | |
2592 | ||
2593 | (defun idlwave-end-of-statement0 () | |
2594 | "Moves point to the end of the current IDL statement. | |
f32b3b91 CD |
2595 | If not in a statement just moves to end of line. Returns position." |
2596 | (interactive) | |
2597 | (while (and (idlwave-is-continuation-line) | |
2598 | (= (forward-line 1) 0))) | |
2599 | (end-of-line) | |
2600 | (point)) | |
2601 | ||
2602 | (defun idlwave-next-statement () | |
2603 | "Moves point to beginning of the next IDL statement. | |
2604 | Returns t if that statement is the last | |
2605 | non-comment IDL statement in the file, and nil otherwise." | |
2606 | (interactive) | |
2607 | (let (last-statement) | |
2608 | (idlwave-end-of-statement) | |
2609 | ;; skip blank lines, label lines, include lines and line comments | |
2610 | (while (and (= (forward-line 1) 0) | |
2611 | ;; The current statement is the last statement until | |
2612 | ;; we reach a new statement. | |
2613 | (setq last-statement | |
2614 | (or | |
2615 | (looking-at idlwave-comment-line-start-skip) | |
2616 | (looking-at "[ \t]*$") | |
2617 | (looking-at (concat "[ \t]*" idlwave-label "[ \t]*$")) | |
2618 | (looking-at "^@"))))) | |
2619 | last-statement)) | |
2620 | ||
76959b77 S |
2621 | (defun idlwave-skip-multi-commands (&optional lim) |
2622 | "Skip past multiple commands on a line (with `&')." | |
2623 | (let ((save-point (point))) | |
2624 | (when (re-search-forward ".*&" lim t) | |
2625 | (goto-char (match-end 0)) | |
4b1aaa8b | 2626 | (if (idlwave-quoted) |
6b75c9af S |
2627 | (goto-char save-point) |
2628 | (if (eq (char-after (- (point) 2)) ?&) (goto-char save-point)))) | |
76959b77 S |
2629 | (point))) |
2630 | ||
15e42531 | 2631 | (defun idlwave-skip-label-or-case () |
f32b3b91 CD |
2632 | "Skip label or case statement element. |
2633 | Returns position after label. | |
2634 | If there is no label point is not moved and nil is returned." | |
15e42531 CD |
2635 | ;; Case expressions and labels are terminated by a colon. |
2636 | ;; So we find the first colon in the line and make sure | |
2637 | ;; - no `?' is before it (might be a ? b : c) | |
2638 | ;; - it is not in a comment | |
2639 | ;; - not in a string constant | |
2640 | ;; - not in parenthesis (like a[0:3]) | |
5e72c6b2 | 2641 | ;; - not followed by another ":" in explicit class, ala a->b::c |
15e42531 | 2642 | ;; As many in this mode, this function is heuristic and not an exact |
4b1aaa8b | 2643 | ;; parser. |
5e72c6b2 S |
2644 | (let* ((start (point)) |
2645 | (eos (save-excursion (idlwave-end-of-statement) (point))) | |
2646 | (end (idlwave-find-key ":" 1 'nomark eos))) | |
f32b3b91 | 2647 | (if (and end |
15e42531 | 2648 | (= (nth 0 (parse-partial-sexp start end)) 0) |
5e72c6b2 S |
2649 | (not (string-match "\\?" (buffer-substring start end))) |
2650 | (not (string-match "^::" (buffer-substring end eos)))) | |
f32b3b91 CD |
2651 | (progn |
2652 | (forward-char) | |
2653 | (point)) | |
2654 | (goto-char start) | |
2655 | nil))) | |
2656 | ||
2657 | (defun idlwave-start-of-substatement (&optional pre) | |
2658 | "Move to start of next IDL substatement after point. | |
2659 | Uses the type of the current IDL statement to determine if the next | |
2660 | statement is on a new line or is a subpart of the current statement. | |
2661 | Returns point at start of substatement modulo whitespace. | |
2662 | If optional argument is non-nil move to beginning of current | |
15e42531 | 2663 | substatement." |
f32b3b91 CD |
2664 | (let ((orig (point)) |
2665 | (eos (idlwave-end-of-statement)) | |
2666 | (ifnest 0) | |
2667 | st nst last) | |
2668 | (idlwave-beginning-of-statement) | |
15e42531 | 2669 | (idlwave-skip-label-or-case) |
52a244eb S |
2670 | (if (< (point) orig) |
2671 | (idlwave-skip-multi-commands orig)) | |
f32b3b91 CD |
2672 | (setq last (point)) |
2673 | ;; Continue looking for substatements until we are past orig | |
2674 | (while (and (<= (point) orig) (not (eobp))) | |
2675 | (setq last (point)) | |
2676 | (setq nst (nth 1 (cdr (setq st (car (idlwave-statement-type)))))) | |
2677 | (if (equal (car st) 'if) (setq ifnest (1+ ifnest))) | |
2678 | (cond ((and nst | |
2679 | (idlwave-find-key nst 1 'nomark eos)) | |
2680 | (goto-char (match-end 0))) | |
2681 | ((and (> ifnest 0) (idlwave-find-key "\\<else\\>" 1 'nomark eos)) | |
2682 | (setq ifnest (1- ifnest)) | |
2683 | (goto-char (match-end 0))) | |
2684 | (t (setq ifnest 0) | |
2685 | (idlwave-next-statement)))) | |
2686 | (if pre (goto-char last)) | |
15e42531 CD |
2687 | ;; If a continuation line starts here, move to next line |
2688 | (if (looking-at "[ \t]*\\$\\([ \t]*\\(;\\|$\\)\\)") | |
2689 | (beginning-of-line 2)) | |
f32b3b91 CD |
2690 | (point))) |
2691 | ||
2692 | (defun idlwave-statement-type () | |
2693 | "Return the type of the current IDL statement. | |
2694 | Uses `idlwave-statement-match' to return a cons of (type . point) with | |
2695 | point the ending position where the type was determined. Type is the | |
2696 | association from `idlwave-statement-match', i.e. the cons cell from the | |
2697 | list not just the type symbol. Returns nil if not an identifiable | |
2698 | statement." | |
2699 | (save-excursion | |
2700 | ;; Skip whitespace within a statement which is spaces, tabs, continuations | |
76959b77 S |
2701 | ;; and possibly comments |
2702 | (while (looking-at "[ \t]*\\$") | |
f32b3b91 CD |
2703 | (forward-line 1)) |
2704 | (skip-chars-forward " \t") | |
2705 | (let ((st idlwave-statement-match) | |
2706 | (case-fold-search t)) | |
2707 | (while (and (not (looking-at (nth 0 (cdr (car st))))) | |
2708 | (setq st (cdr st)))) | |
2709 | (if st | |
2710 | (append st (match-end 0)))))) | |
2711 | ||
f66f03de | 2712 | (defun idlwave-expand-equal (&optional before after is-action) |
52a244eb S |
2713 | "Pad '=' with spaces. Two cases: Assignment statement, and keyword |
2714 | assignment. Which case is determined using | |
2715 | `idlwave-start-of-substatement' and `idlwave-statement-type'. The | |
2716 | equal sign will be surrounded by BEFORE and AFTER blanks. If | |
2717 | `idlwave-pad-keyword' is t then keyword assignment is treated just | |
15e42531 CD |
2718 | like assignment statements. When nil, spaces are removed for keyword |
2719 | assignment. Any other value keeps the current space around the `='. | |
4b1aaa8b | 2720 | Limits in for loops are treated as keyword assignment. |
52a244eb S |
2721 | |
2722 | Starting with IDL 6.0, a number of op= assignments are available. | |
2723 | Since ambiguities of the form: | |
2724 | ||
2725 | r and= b | |
2726 | rand= b | |
2727 | ||
2728 | can occur, alphanumeric operator assignment will never be pre-padded, | |
2729 | only post-padded. You must use a space before these to disambiguate | |
2730 | \(not just for padding, but for proper parsing by IDL too!). Other | |
2731 | operators, such as ##=, ^=, etc., will be pre-padded. | |
2732 | ||
f66f03de S |
2733 | IS-ACTION is ignored. |
2734 | ||
52a244eb | 2735 | See `idlwave-surround'." |
f32b3b91 | 2736 | (if idlwave-surround-by-blank |
4b1aaa8b | 2737 | (let |
52a244eb | 2738 | ((non-an-ops "\\(##\\|\\*\\|\\+\\|-\\|/\\|<\\|>\\|\\^\\)\\=") |
4b1aaa8b | 2739 | (an-ops |
52a244eb S |
2740 | "\\s-\\(AND\\|EQ\\|GE\\|GT\\|LE\\|LT\\|MOD\\|NE\\|OR\\|XOR\\)\\=") |
2741 | (len 1)) | |
4b1aaa8b PE |
2742 | |
2743 | (save-excursion | |
52a244eb S |
2744 | (let ((case-fold-search t)) |
2745 | (backward-char) | |
4b1aaa8b | 2746 | (if (or |
52a244eb S |
2747 | (re-search-backward non-an-ops nil t) |
2748 | ;; Why doesn't ##? work for both? | |
4b1aaa8b | 2749 | (re-search-backward "\\(#\\)\\=" nil t)) |
52a244eb S |
2750 | (setq len (1+ (length (match-string 1)))) |
2751 | (when (re-search-backward an-ops nil t) | |
3938cb82 | 2752 | ;(setq begin nil) ; won't modify begin |
52a244eb | 2753 | (setq len (1+ (length (match-string 1)))))))) |
4b1aaa8b PE |
2754 | |
2755 | (if (eq t idlwave-pad-keyword) | |
52a244eb | 2756 | ;; Everything gets padded equally |
f66f03de | 2757 | (idlwave-surround before after len) |
52a244eb S |
2758 | ;; Treating keywords/for variables specially... |
2759 | (let ((st (save-excursion ; To catch "for" variables | |
2760 | (idlwave-start-of-substatement t) | |
2761 | (idlwave-statement-type))) | |
2762 | (what (save-excursion ; To catch keywords | |
2763 | (skip-chars-backward "= \t") | |
2764 | (nth 2 (idlwave-where))))) | |
2765 | (cond ((or (memq what '(function-keyword procedure-keyword)) | |
4b1aaa8b PE |
2766 | (memq (caar st) '(for pdef))) |
2767 | (cond | |
52a244eb S |
2768 | ((null idlwave-pad-keyword) |
2769 | (idlwave-surround 0 0) | |
2770 | ) ; remove space | |
2771 | (t))) ; leave any spaces alone | |
f66f03de | 2772 | (t (idlwave-surround before after len)))))))) |
4b1aaa8b | 2773 | |
f32b3b91 | 2774 | |
5e72c6b2 S |
2775 | (defun idlwave-indent-and-action (&optional arg) |
2776 | "Call `idlwave-indent-line' and do expand actions. | |
2777 | With prefix ARG non-nil, indent the entire sub-statement." | |
2778 | (interactive "p") | |
05a1abfc | 2779 | (save-excursion |
4b1aaa8b PE |
2780 | (if (and idlwave-expand-generic-end |
2781 | (re-search-backward "\\<\\(end\\)\\s-*\\=" | |
05a1abfc CD |
2782 | (max 0 (- (point) 10)) t) |
2783 | (looking-at "\\(end\\)\\([ \n\t]\\|\\'\\)")) | |
2784 | (progn (goto-char (match-end 1)) | |
5e72c6b2 S |
2785 | ;;Expand the END abbreviation, just as RET or Space would have. |
2786 | (if abbrev-mode (expand-abbrev) | |
2787 | (idlwave-show-begin))))) | |
52a244eb S |
2788 | (when (and (not arg) current-prefix-arg) |
2789 | (setq arg current-prefix-arg) | |
2790 | (setq current-prefix-arg nil)) | |
4b1aaa8b | 2791 | (if arg |
5e72c6b2 S |
2792 | (idlwave-indent-statement) |
2793 | (idlwave-indent-line t))) | |
f32b3b91 CD |
2794 | |
2795 | (defun idlwave-indent-line (&optional expand) | |
2796 | "Indents current IDL line as code or as a comment. | |
2797 | The actions in `idlwave-indent-action-table' are performed. | |
2798 | If the optional argument EXPAND is non-nil then the actions in | |
2799 | `idlwave-indent-expand-table' are performed." | |
2800 | (interactive) | |
2801 | ;; Move point out of left margin. | |
2802 | (if (save-excursion | |
2803 | (skip-chars-backward " \t") | |
2804 | (bolp)) | |
2805 | (skip-chars-forward " \t")) | |
2806 | (let ((mloc (point-marker))) | |
2807 | (save-excursion | |
2808 | (beginning-of-line) | |
2809 | (if (looking-at idlwave-comment-line-start-skip) | |
2810 | ;; Indentation for a line comment | |
2811 | (progn | |
2812 | (skip-chars-forward " \t") | |
2813 | (idlwave-indent-left-margin (idlwave-comment-hook))) | |
2814 | ;; | |
2815 | ;; Code Line | |
2816 | ;; | |
2817 | ;; Before indenting, run action routines. | |
2818 | ;; | |
2819 | (if (and expand idlwave-do-actions) | |
8ffcfb27 | 2820 | (mapc 'idlwave-do-action idlwave-indent-expand-table)) |
f32b3b91 CD |
2821 | ;; |
2822 | (if idlwave-do-actions | |
8ffcfb27 | 2823 | (mapc 'idlwave-do-action idlwave-indent-action-table)) |
f32b3b91 CD |
2824 | ;; |
2825 | ;; No longer expand abbrevs on the line. The user can do this | |
2826 | ;; manually using expand-region-abbrevs. | |
2827 | ;; | |
2828 | ;; Indent for code line | |
2829 | ;; | |
2830 | (beginning-of-line) | |
2831 | (if (or | |
2832 | ;; a label line | |
2833 | (looking-at (concat "^" idlwave-label "[ \t]*$")) | |
2834 | ;; a batch command | |
2835 | (looking-at "^[ \t]*@")) | |
2836 | ;; leave flush left | |
2837 | nil | |
2838 | ;; indent the line | |
2839 | (idlwave-indent-left-margin (idlwave-calculate-indent))) | |
2840 | ;; Adjust parallel comment | |
76959b77 S |
2841 | (end-of-line) |
2842 | (if (idlwave-in-comment) | |
2843 | ;; Emacs 21 is too smart with fill-column on comment indent | |
2844 | (let ((fill-column (if (fboundp 'comment-indent-new-line) | |
2845 | (1- (frame-width)) | |
2846 | fill-column))) | |
2847 | (indent-for-comment))))) | |
f32b3b91 CD |
2848 | (goto-char mloc) |
2849 | ;; Get rid of marker | |
76959b77 | 2850 | (set-marker mloc nil))) |
f32b3b91 CD |
2851 | |
2852 | (defun idlwave-do-action (action) | |
f66f03de S |
2853 | "Perform an action repeatedly on a line. ACTION is a list (REG |
2854 | . FUNC). REG is a regular expression. FUNC is either a function name | |
2855 | to be called with `funcall' or a list to be evaluated with `eval'. | |
2856 | The action performed by FUNC should leave point after the match for | |
2857 | REG - otherwise an infinite loop may be entered. FUNC is always | |
2858 | passed a final argument of 'is-action, so it can discriminate between | |
2859 | being run as an action, or a key binding" | |
f32b3b91 CD |
2860 | (let ((action-key (car action)) |
2861 | (action-routine (cdr action))) | |
2862 | (beginning-of-line) | |
2863 | (while (idlwave-look-at action-key) | |
2864 | (if (listp action-routine) | |
f66f03de S |
2865 | (eval (append action-routine '('is-action))) |
2866 | (funcall action-routine 'is-action))))) | |
f32b3b91 CD |
2867 | |
2868 | (defun idlwave-indent-to (col &optional min) | |
2869 | "Indent from point with spaces until column COL. | |
2870 | Inserts space before markers at point." | |
2871 | (if (not min) (setq min 0)) | |
2872 | (insert-before-markers | |
15e42531 | 2873 | (make-string (max min (- col (current-column))) ?\ ))) |
f32b3b91 CD |
2874 | |
2875 | (defun idlwave-indent-left-margin (col) | |
2876 | "Indent the current line to column COL. | |
2877 | Indents such that first non-whitespace character is at column COL | |
2878 | Inserts spaces before markers at point." | |
2879 | (save-excursion | |
2880 | (beginning-of-line) | |
2881 | (delete-horizontal-space) | |
2882 | (idlwave-indent-to col))) | |
2883 | ||
2884 | (defun idlwave-indent-subprogram () | |
2885 | "Indents program unit which contains point." | |
2886 | (interactive) | |
2887 | (save-excursion | |
2888 | (idlwave-end-of-statement) | |
2889 | (idlwave-beginning-of-subprogram) | |
2890 | (let ((beg (point))) | |
2891 | (idlwave-forward-block) | |
2892 | (message "Indenting subprogram...") | |
2893 | (indent-region beg (point) nil)) | |
2894 | (message "Indenting subprogram...done."))) | |
2895 | ||
5e72c6b2 S |
2896 | (defun idlwave-indent-statement () |
2897 | "Indent current statement, including all continuation lines." | |
2898 | (interactive) | |
2899 | (save-excursion | |
2900 | (idlwave-beginning-of-statement) | |
2901 | (let ((beg (point))) | |
2902 | (idlwave-end-of-statement) | |
2903 | (indent-region beg (point) nil)))) | |
2904 | ||
f32b3b91 CD |
2905 | (defun idlwave-calculate-indent () |
2906 | "Return appropriate indentation for current line as IDL code." | |
2907 | (save-excursion | |
2908 | (beginning-of-line) | |
2909 | (cond | |
2910 | ;; Check for beginning of unit - main (beginning of buffer), pro, or | |
2911 | ;; function | |
2912 | ((idlwave-look-at idlwave-begin-unit-reg) | |
2913 | 0) | |
2914 | ;; Check for continuation line | |
2915 | ((save-excursion | |
2916 | (and (= (forward-line -1) 0) | |
2917 | (idlwave-is-continuation-line))) | |
2918 | (idlwave-calculate-cont-indent)) | |
2919 | ;; calculate indent based on previous and current statements | |
52a244eb S |
2920 | (t (let* (beg-prev-pos |
2921 | (the-indent | |
2922 | ;; calculate indent based on previous statement | |
2923 | (save-excursion | |
2924 | (cond | |
2925 | ;; Beginning of file | |
4b1aaa8b | 2926 | ((prog1 |
52a244eb S |
2927 | (idlwave-previous-statement) |
2928 | (setq beg-prev-pos (point))) | |
2929 | 0) | |
2930 | ;; Main block | |
2931 | ((idlwave-look-at idlwave-begin-unit-reg t) | |
2932 | (+ (idlwave-current-statement-indent) | |
2933 | idlwave-main-block-indent)) | |
2934 | ;; Begin block | |
2935 | ((idlwave-look-at idlwave-begin-block-reg t) | |
4b1aaa8b | 2936 | (+ (idlwave-min-current-statement-indent) |
52a244eb S |
2937 | idlwave-block-indent)) |
2938 | ;; End Block | |
2939 | ((idlwave-look-at idlwave-end-block-reg t) | |
2940 | (progn | |
2941 | ;; Match to the *beginning* of the block opener | |
2942 | (goto-char beg-prev-pos) | |
2943 | (idlwave-block-jump-out -1 'nomark) ; go to begin block | |
2944 | (idlwave-min-current-statement-indent))) | |
2945 | ;; idlwave-end-offset | |
2946 | ;; idlwave-block-indent)) | |
4b1aaa8b | 2947 | |
52a244eb S |
2948 | ;; Default to current indent |
2949 | ((idlwave-current-statement-indent)))))) | |
f32b3b91 CD |
2950 | ;; adjust the indentation based on the current statement |
2951 | (cond | |
2952 | ;; End block | |
5e72c6b2 S |
2953 | ((idlwave-look-at idlwave-end-block-reg) |
2954 | (+ the-indent idlwave-end-offset)) | |
f32b3b91 CD |
2955 | (the-indent))))))) |
2956 | ||
2957 | ;; | |
52a244eb | 2958 | ;; Parentheses indent |
f32b3b91 CD |
2959 | ;; |
2960 | ||
5e72c6b2 S |
2961 | (defun idlwave-calculate-paren-indent (beg-reg end-reg close-exp) |
2962 | "Calculate the continuation indent inside a paren group. | |
4b1aaa8b | 2963 | Returns a cons-cell with (open . indent), where open is the |
5e72c6b2 S |
2964 | location of the open paren" |
2965 | (let ((open (nth 1 (parse-partial-sexp beg-reg end-reg)))) | |
2966 | ;; Found an innermost open paren. | |
2967 | (when open | |
2968 | (goto-char open) | |
2969 | ;; Line up with next word unless this is a closing paren. | |
2970 | (cons open | |
2971 | (cond | |
52a244eb S |
2972 | ;; Plain Kernighan-style nested indent |
2973 | (idlwave-indent-parens-nested | |
2974 | (+ idlwave-continuation-indent (idlwave-current-indent))) | |
2975 | ||
5e72c6b2 S |
2976 | ;; This is a closed paren - line up under open paren. |
2977 | (close-exp | |
2978 | (current-column)) | |
52a244eb S |
2979 | |
2980 | ;; Empty (or just comment) follows -- revert to basic indent | |
5e72c6b2 S |
2981 | ((progn |
2982 | ;; Skip paren | |
2983 | (forward-char 1) | |
2984 | (looking-at "[ \t$]*\\(;.*\\)?$")) | |
52a244eb S |
2985 | nil) |
2986 | ||
2987 | ;; Line up with first word after any blank space | |
5e72c6b2 S |
2988 | ((progn |
2989 | (skip-chars-forward " \t") | |
2990 | (current-column)))))))) | |
2991 | ||
f32b3b91 | 2992 | (defun idlwave-calculate-cont-indent () |
52a244eb S |
2993 | "Calculates the IDL continuation indent column from the previous |
2994 | statement. Note that here previous statement usually means the | |
2995 | beginning of the current statement if this statement is a continuation | |
2996 | of the previous line. Various special types of continuations, | |
2997 | including assignments, routine definitions, and parenthetical | |
2998 | groupings, are treated separately." | |
f32b3b91 | 2999 | (save-excursion |
52a244eb | 3000 | (let* ((case-fold-search t) |
f32b3b91 | 3001 | (end-reg (progn (beginning-of-line) (point))) |
52a244eb S |
3002 | (beg-last-statement (save-excursion (idlwave-previous-statement) |
3003 | (point))) | |
4b1aaa8b | 3004 | (beg-reg (progn (idlwave-start-of-substatement 'pre) |
52a244eb S |
3005 | (if (eq (line-beginning-position) end-reg) |
3006 | (goto-char beg-last-statement) | |
3007 | (point)))) | |
3008 | (basic-indent (+ (idlwave-min-current-statement-indent end-reg) | |
3009 | idlwave-continuation-indent)) | |
3010 | fancy-nonparen-indent fancy-paren-indent) | |
4b1aaa8b | 3011 | (cond |
52a244eb S |
3012 | ;; Align then with its matching if, etc. |
3013 | ((let ((matchers '(("\\<if\\>" . "[ \t]*then") | |
3014 | ("\\<\\(if\\|end\\(if\\)?\\)\\>" . "[ \t]*else") | |
3015 | ("\\<\\(for\\|while\\)\\>" . "[ \t]*do") | |
4b1aaa8b | 3016 | ("\\<\\(repeat\\|end\\(rep\\)?\\)\\>" . |
52a244eb S |
3017 | "[ \t]*until") |
3018 | ("\\<case\\>" . "[ \t]*of"))) | |
3019 | match cont-re) | |
3020 | (goto-char end-reg) | |
4b1aaa8b | 3021 | (and |
52a244eb S |
3022 | (setq cont-re |
3023 | (catch 'exit | |
3024 | (while (setq match (car matchers)) | |
3025 | (if (looking-at (cdr match)) | |
3026 | (throw 'exit (car match))) | |
3027 | (setq matchers (cdr matchers))))) | |
3028 | (idlwave-find-key cont-re -1 'nomark beg-last-statement))) | |
3029 | (if (looking-at "end") ;; that one's special | |
4b1aaa8b | 3030 | (- (idlwave-current-indent) |
52a244eb S |
3031 | (+ idlwave-block-indent idlwave-end-offset)) |
3032 | (idlwave-current-indent))) | |
3033 | ||
3034 | ;; Indent in from the previous line for continuing statements | |
3035 | ((let ((matchers '("\\<then\\>" | |
3036 | "\\<do\\>" | |
3037 | "\\<repeat\\>" | |
3038 | "\\<else\\>")) | |
3039 | match) | |
3040 | (catch 'exit | |
3041 | (goto-char end-reg) | |
3042 | (if (/= (forward-line -1) 0) | |
3043 | (throw 'exit nil)) | |
3044 | (while (setq match (car matchers)) | |
3045 | (if (looking-at (concat ".*" match "[ \t]*\\$[ \t]*" | |
3046 | "\\(;.*\\)?$")) | |
3047 | (throw 'exit t)) | |
3048 | (setq matchers (cdr matchers))))) | |
3049 | (+ idlwave-continuation-indent (idlwave-current-indent))) | |
3050 | ||
3051 | ;; Parenthetical indent, either traditional or Kernighan style | |
3052 | ((setq fancy-paren-indent | |
3053 | (let* ((end-reg end-reg) | |
3054 | (close-exp (progn | |
3055 | (goto-char end-reg) | |
4b1aaa8b | 3056 | (skip-chars-forward " \t") |
52a244eb S |
3057 | (looking-at "\\s)"))) |
3058 | indent-cons) | |
3059 | (catch 'loop | |
3060 | (while (setq indent-cons (idlwave-calculate-paren-indent | |
3061 | beg-reg end-reg close-exp)) | |
3062 | ;; First permitted containing paren | |
3063 | (if (or | |
3064 | idlwave-indent-to-open-paren | |
3065 | idlwave-indent-parens-nested | |
3066 | (null (cdr indent-cons)) | |
3067 | (< (- (cdr indent-cons) basic-indent) | |
3068 | idlwave-max-extra-continuation-indent)) | |
3069 | (throw 'loop (cdr indent-cons))) | |
3070 | (setq end-reg (car indent-cons)))))) | |
5e72c6b2 S |
3071 | fancy-paren-indent) |
3072 | ||
52a244eb S |
3073 | ;; A continued assignment, or procedure call/definition |
3074 | ((and | |
3075 | (> idlwave-max-extra-continuation-indent 0) | |
3076 | (setq fancy-nonparen-indent | |
3077 | (progn | |
3078 | (goto-char beg-reg) | |
3079 | (while (idlwave-look-at "&")) ; skip continued statements | |
3080 | (cond | |
3081 | ;; A continued Procedure call or definition | |
3082 | ((progn | |
3083 | (idlwave-look-at "^[ \t]*\\(pro\\|function\\)") ;skip over | |
3084 | (looking-at "[ \t]*\\([a-zA-Z0-9.$_]+[ \t]*->[ \t]*\\)?[a-zA-Z][:a-zA-Z0-9$_]*[ \t]*\\(,\\)[ \t]*")) | |
3085 | (goto-char (match-end 0)) | |
3086 | ;; Comment only, or blank line with "$"? Basic indent. | |
3087 | (if (save-match-data (looking-at "[ \t$]*\\(;.*\\)?$")) | |
3088 | nil | |
3089 | (current-column))) | |
4b1aaa8b | 3090 | |
52a244eb S |
3091 | ;; Continued assignment (with =): |
3092 | ((catch 'assign ; | |
3093 | (while (looking-at "[^=\n\r]*\\(=\\)[ \t]*") | |
3094 | (goto-char (match-end 0)) | |
4b1aaa8b | 3095 | (if (null (idlwave-what-function beg-reg)) |
52a244eb S |
3096 | (throw 'assign t)))) |
3097 | (unless (or | |
3098 | (idlwave-in-quote) | |
3099 | (looking-at "[ \t$]*\\(;.*\\)?$") ; use basic | |
3100 | (save-excursion | |
3101 | (goto-char beg-last-statement) | |
3102 | (eq (caar (idlwave-statement-type)) 'for))) | |
3103 | (current-column)))))) | |
3104 | (< (- fancy-nonparen-indent basic-indent) | |
3105 | idlwave-max-extra-continuation-indent)) | |
3106 | (if fancy-paren-indent ;calculated but disallowed paren indent | |
3107 | (+ fancy-nonparen-indent idlwave-continuation-indent) | |
3108 | fancy-nonparen-indent)) | |
3109 | ||
3110 | ;; Basic indent, by default | |
3111 | (t basic-indent))))) | |
3112 | ||
3113 | ||
f32b3b91 | 3114 | |
15e42531 CD |
3115 | (defun idlwave-find-key (key-re &optional dir nomark limit) |
3116 | "Move to next match of the regular expression KEY-RE. | |
3117 | Matches inside comments or string constants will be ignored. | |
3118 | If DIR is negative, the search will be backwards. | |
3119 | At a successful match, the mark is pushed unless NOMARK is non-nil. | |
3120 | Searches are limited to LIMIT. | |
3121 | Searches are case-insensitive and use a special syntax table which | |
3122 | treats `$' and `_' as word characters. | |
3123 | Return value is the beginning of the match or (in case of failure) nil." | |
3124 | (setq dir (or dir 0)) | |
3125 | (let ((case-fold-search t) | |
3126 | (search-func (if (> dir 0) 're-search-forward 're-search-backward)) | |
3127 | found) | |
3128 | (idlwave-with-special-syntax | |
3129 | (save-excursion | |
3130 | (catch 'exit | |
3131 | (while (funcall search-func key-re limit t) | |
3132 | (if (not (idlwave-quoted)) | |
52a244eb S |
3133 | (throw 'exit (setq found (match-beginning 0))) |
3134 | (if (or (and (> dir 0) (eobp)) | |
3135 | (and (< dir 0) (bobp))) | |
3136 | (throw 'exit nil))))))) | |
15e42531 CD |
3137 | (if found |
3138 | (progn | |
3139 | (if (not nomark) (push-mark)) | |
3140 | (goto-char found) | |
3141 | found) | |
3142 | nil))) | |
3143 | ||
f32b3b91 CD |
3144 | (defun idlwave-block-jump-out (&optional dir nomark) |
3145 | "When optional argument DIR is non-negative, move forward to end of | |
3146 | current block using the `idlwave-begin-block-reg' and `idlwave-end-block-reg' | |
3147 | regular expressions. When DIR is negative, move backwards to block beginning. | |
3148 | Recursively calls itself to skip over nested blocks. DIR defaults to | |
3149 | forward. Calls `push-mark' unless the optional argument NOMARK is | |
3150 | non-nil. Movement is limited by the start of program units because of | |
3151 | possibility of unbalanced blocks." | |
3152 | (interactive "P") | |
3153 | (or dir (setq dir 0)) | |
3154 | (let* ((here (point)) | |
3155 | (case-fold-search t) | |
3156 | (limit (if (>= dir 0) (point-max) (point-min))) | |
4b1aaa8b | 3157 | (block-limit (if (>= dir 0) |
f32b3b91 CD |
3158 | idlwave-begin-block-reg |
3159 | idlwave-end-block-reg)) | |
3160 | found | |
3161 | (block-reg (concat idlwave-begin-block-reg "\\|" | |
3162 | idlwave-end-block-reg)) | |
3163 | (unit-limit (or (save-excursion | |
3164 | (if (< dir 0) | |
3165 | (idlwave-find-key | |
3166 | idlwave-begin-unit-reg dir t limit) | |
3167 | (end-of-line) | |
4b1aaa8b | 3168 | (idlwave-find-key |
f32b3b91 CD |
3169 | idlwave-end-unit-reg dir t limit))) |
3170 | limit))) | |
3171 | (if (>= dir 0) (end-of-line)) ;Make sure we are in current block | |
3172 | (if (setq found (idlwave-find-key block-reg dir t unit-limit)) | |
3173 | (while (and found (looking-at block-limit)) | |
3174 | (if (>= dir 0) (forward-word 1)) | |
3175 | (idlwave-block-jump-out dir t) | |
3176 | (setq found (idlwave-find-key block-reg dir t unit-limit)))) | |
3177 | (if (not nomark) (push-mark here)) | |
3178 | (if (not found) (goto-char unit-limit) | |
3179 | (if (>= dir 0) (forward-word 1))))) | |
3180 | ||
52a244eb S |
3181 | (defun idlwave-min-current-statement-indent (&optional end-reg) |
3182 | "The minimum indent in the current statement." | |
3183 | (idlwave-beginning-of-statement) | |
3184 | (if (not (idlwave-is-continuation-line)) | |
3185 | (idlwave-current-indent) | |
3186 | (let ((min (idlwave-current-indent)) comm-or-empty) | |
3187 | (while (and (= (forward-line 1) 0) | |
3188 | (or (setq comm-or-empty (idlwave-is-comment-or-empty-line)) | |
3189 | (idlwave-is-continuation-line)) | |
3190 | (or (null end-reg) (< (point) end-reg))) | |
3191 | (unless comm-or-empty (setq min (min min (idlwave-current-indent))))) | |
3192 | (if (or comm-or-empty (and end-reg (>= (point) end-reg))) | |
4b1aaa8b | 3193 | min |
52a244eb S |
3194 | (min min (idlwave-current-indent)))))) |
3195 | ||
3196 | (defun idlwave-current-statement-indent (&optional last-line) | |
f32b3b91 CD |
3197 | "Return indentation of the current statement. |
3198 | If in a statement, moves to beginning of statement before finding indent." | |
52a244eb S |
3199 | (if last-line |
3200 | (idlwave-end-of-statement) | |
3201 | (idlwave-beginning-of-statement)) | |
f32b3b91 CD |
3202 | (idlwave-current-indent)) |
3203 | ||
3204 | (defun idlwave-current-indent () | |
3205 | "Return the column of the indentation of the current line. | |
3206 | Skips any whitespace. Returns 0 if the end-of-line follows the whitespace." | |
3207 | (save-excursion | |
3208 | (beginning-of-line) | |
3209 | (skip-chars-forward " \t") | |
3210 | ;; if we are at the end of blank line return 0 | |
3211 | (cond ((eolp) 0) | |
3212 | ((current-column))))) | |
3213 | ||
3214 | (defun idlwave-is-continuation-line () | |
5e72c6b2 S |
3215 | "Tests if current line is continuation line. |
3216 | Blank or comment-only lines following regular continuation lines (with | |
3217 | `$') count as continuations too." | |
0dc2be2f S |
3218 | (let (p) |
3219 | (save-excursion | |
4b1aaa8b | 3220 | (or |
0dc2be2f S |
3221 | (idlwave-look-at "\\<\\$") |
3222 | (catch 'loop | |
4b1aaa8b | 3223 | (while (and (looking-at "^[ \t]*\\(;.*\\)?$") |
0dc2be2f S |
3224 | (eq (forward-line -1) 0)) |
3225 | (if (setq p (idlwave-look-at "\\<\\$")) (throw 'loop p)))))))) | |
f32b3b91 CD |
3226 | |
3227 | (defun idlwave-is-comment-line () | |
05a1abfc | 3228 | "Tests if the current line is a comment line." |
f32b3b91 CD |
3229 | (save-excursion |
3230 | (beginning-of-line 1) | |
3231 | (looking-at "[ \t]*;"))) | |
3232 | ||
05a1abfc CD |
3233 | (defun idlwave-is-comment-or-empty-line () |
3234 | "Tests if the current line is a comment line." | |
3235 | (save-excursion | |
3236 | (beginning-of-line 1) | |
3237 | (looking-at "[ \t]*[;\n]"))) | |
3238 | ||
f32b3b91 | 3239 | (defun idlwave-look-at (regexp &optional cont beg) |
15e42531 CD |
3240 | "Searches current line from current point for REGEXP. |
3241 | If optional argument CONT is non-nil, searches to the end of | |
3242 | the current statement. | |
3243 | If optional arg BEG is non-nil, search starts from the beginning of the | |
3244 | current statement. | |
3245 | Ignores matches that end in a comment or inside a string expression. | |
3246 | Returns point if successful, nil otherwise. | |
3247 | This function produces unexpected results if REGEXP contains quotes or | |
3248 | a comment delimiter. The search is case insensitive. | |
3249 | If successful leaves point after the match, otherwise, does not move point." | |
f32b3b91 | 3250 | (let ((here (point)) |
f32b3b91 | 3251 | (case-fold-search t) |
15e42531 CD |
3252 | (eos (save-excursion |
3253 | (if cont (idlwave-end-of-statement) (end-of-line)) | |
3254 | (point))) | |
f32b3b91 | 3255 | found) |
15e42531 CD |
3256 | (idlwave-with-special-syntax |
3257 | (if beg (idlwave-beginning-of-statement)) | |
3258 | (while (and (setq found (re-search-forward regexp eos t)) | |
3259 | (idlwave-quoted)))) | |
f32b3b91 CD |
3260 | (if (not found) (goto-char here)) |
3261 | found)) | |
3262 | ||
3263 | (defun idlwave-fill-paragraph (&optional nohang) | |
3264 | "Fills paragraphs in comments. | |
3265 | A paragraph is made up of all contiguous lines having the same comment | |
3266 | leader (the leading whitespace before the comment delimiter and the | |
3267 | comment delimiter). In addition, paragraphs are separated by blank | |
3268 | line comments. The indentation is given by the hanging indent of the | |
3269 | first line, otherwise by the minimum indentation of the lines after | |
3270 | the first line. The indentation of the first line does not change. | |
3271 | Does not effect code lines. Does not fill comments on the same line | |
3272 | with code. The hanging indent is given by the end of the first match | |
3273 | matching `idlwave-hang-indent-regexp' on the paragraph's first line . If the | |
3274 | optional argument NOHANG is non-nil then the hanging indent is | |
3275 | ignored." | |
3276 | (interactive "P") | |
3277 | ;; check if this is a line comment | |
3278 | (if (save-excursion | |
3279 | (beginning-of-line) | |
3280 | (skip-chars-forward " \t") | |
3281 | (looking-at comment-start)) | |
3282 | (let | |
3283 | ((indent 999) | |
3284 | pre here diff fill-prefix-reg bcl first-indent | |
3285 | hang start end) | |
3286 | ;; Change tabs to spaces in the surrounding paragraph. | |
3287 | ;; The surrounding paragraph will be the largest containing block of | |
3288 | ;; contiguous line comments. Thus, we may be changing tabs in | |
3289 | ;; a much larger area than is needed, but this is the easiest | |
3290 | ;; brute force way to do it. | |
3291 | ;; | |
3292 | ;; This has the undesirable side effect of replacing the tabs | |
3293 | ;; permanently without the user's request or knowledge. | |
3294 | (save-excursion | |
3295 | (backward-paragraph) | |
3296 | (setq start (point))) | |
3297 | (save-excursion | |
3298 | (forward-paragraph) | |
3299 | (setq end (point))) | |
3300 | (untabify start end) | |
3301 | ;; | |
3302 | (setq here (point)) | |
3303 | (beginning-of-line) | |
3304 | (setq bcl (point)) | |
3305 | (re-search-forward | |
3306 | (concat "^[ \t]*" comment-start "+") | |
3307 | (save-excursion (end-of-line) (point)) | |
3308 | t) | |
3309 | ;; Get the comment leader on the line and its length | |
3310 | (setq pre (current-column)) | |
3311 | ;; the comment leader is the indentation plus exactly the | |
3312 | ;; number of consecutive ";". | |
3313 | (setq fill-prefix-reg | |
3314 | (concat | |
3315 | (setq fill-prefix | |
3316 | (regexp-quote | |
3317 | (buffer-substring (save-excursion | |
3318 | (beginning-of-line) (point)) | |
3319 | (point)))) | |
3320 | "[^;]")) | |
4b1aaa8b | 3321 | |
f32b3b91 CD |
3322 | ;; Mark the beginning and end of the paragraph |
3323 | (goto-char bcl) | |
3324 | (while (and (looking-at fill-prefix-reg) | |
3325 | (not (looking-at paragraph-separate)) | |
3326 | (not (bobp))) | |
3327 | (forward-line -1)) | |
3328 | ;; Move to first line of paragraph | |
3329 | (if (/= (point) bcl) | |
3330 | (forward-line 1)) | |
3331 | (setq start (point)) | |
3332 | (goto-char bcl) | |
3333 | (while (and (looking-at fill-prefix-reg) | |
3334 | (not (looking-at paragraph-separate)) | |
3335 | (not (eobp))) | |
3336 | (forward-line 1)) | |
3337 | (beginning-of-line) | |
3338 | (if (or (not (looking-at fill-prefix-reg)) | |
3339 | (looking-at paragraph-separate)) | |
3340 | (forward-line -1)) | |
3341 | (end-of-line) | |
3342 | ;; if at end of buffer add a newline (need this because | |
3343 | ;; fill-region needs END to be at the beginning of line after | |
3344 | ;; the paragraph or it will add a line). | |
3345 | (if (eobp) | |
3346 | (progn (insert ?\n) (backward-char 1))) | |
3347 | ;; Set END to the beginning of line after the paragraph | |
3348 | ;; END is calculated as distance from end of buffer | |
3349 | (setq end (- (point-max) (point) 1)) | |
3350 | ;; | |
3351 | ;; Calculate the indentation for the paragraph. | |
3352 | ;; | |
3353 | ;; In the following while statements, after one iteration | |
3354 | ;; point will be at the beginning of a line in which case | |
3355 | ;; the while will not be executed for the | |
3356 | ;; the first paragraph line and thus will not affect the | |
3357 | ;; indentation. | |
3358 | ;; | |
3359 | ;; First check to see if indentation is based on hanging indent. | |
3360 | (if (and (not nohang) idlwave-hanging-indent | |
3361 | (setq hang | |
3362 | (save-excursion | |
3363 | (goto-char start) | |
3364 | (idlwave-calc-hanging-indent)))) | |
3365 | ;; Adjust lines of paragraph by inserting spaces so that | |
3366 | ;; each line's indent is at least as great as the hanging | |
3367 | ;; indent. This is needed for fill-paragraph to work with | |
3368 | ;; a fill-prefix. | |
3369 | (progn | |
3370 | (setq indent hang) | |
3371 | (beginning-of-line) | |
3372 | (while (> (point) start) | |
3373 | (re-search-forward comment-start-skip | |
3374 | (save-excursion (end-of-line) (point)) | |
3375 | t) | |
3376 | (if (> (setq diff (- indent (current-column))) 0) | |
3377 | (progn | |
3378 | (if (>= here (point)) | |
3379 | ;; adjust the original location for the | |
3380 | ;; inserted text. | |
3381 | (setq here (+ here diff))) | |
15e42531 | 3382 | (insert (make-string diff ?\ )))) |
f32b3b91 CD |
3383 | (forward-line -1)) |
3384 | ) | |
4b1aaa8b | 3385 | |
f32b3b91 CD |
3386 | ;; No hang. Instead find minimum indentation of paragraph |
3387 | ;; after first line. | |
3388 | ;; For the following while statement, since START is at the | |
aa87aafc | 3389 | ;; beginning of line and END is at the end of line |
f32b3b91 CD |
3390 | ;; point is greater than START at least once (which would |
3391 | ;; be the case for a single line paragraph). | |
3392 | (while (> (point) start) | |
3393 | (beginning-of-line) | |
3394 | (setq indent | |
3395 | (min indent | |
3396 | (progn | |
3397 | (re-search-forward | |
3398 | comment-start-skip | |
3399 | (save-excursion (end-of-line) (point)) | |
3400 | t) | |
3401 | (current-column)))) | |
3402 | (forward-line -1)) | |
3403 | ) | |
3404 | (setq fill-prefix (concat fill-prefix | |
3405 | (make-string (- indent pre) | |
15e42531 | 3406 | ?\ ))) |
f32b3b91 CD |
3407 | ;; first-line indent |
3408 | (setq first-indent | |
3409 | (max | |
3410 | (progn | |
3411 | (re-search-forward | |
3412 | comment-start-skip | |
3413 | (save-excursion (end-of-line) (point)) | |
3414 | t) | |
3415 | (current-column)) | |
3416 | indent)) | |
4b1aaa8b | 3417 | |
f32b3b91 CD |
3418 | ;; try to keep point at its original place |
3419 | (goto-char here) | |
3420 | ||
3421 | ;; In place of the more modern fill-region-as-paragraph, a hack | |
3422 | ;; to keep whitespace untouched on the first line within the | |
3423 | ;; indent length and to preserve any indent on the first line | |
3424 | ;; (first indent). | |
3425 | (save-excursion | |
3426 | (setq diff | |
3427 | (buffer-substring start (+ start first-indent -1))) | |
15e42531 | 3428 | (subst-char-in-region start (+ start first-indent -1) ?\ ?~ nil) |
f32b3b91 CD |
3429 | (fill-region-as-paragraph |
3430 | start | |
3431 | (- (point-max) end) | |
3432 | (current-justification) | |
3433 | nil) | |
3434 | (delete-region start (+ start first-indent -1)) | |
3435 | (goto-char start) | |
3436 | (insert diff)) | |
3437 | ;; When we want the point at the beginning of the comment | |
3438 | ;; body fill-region will put it at the beginning of the line. | |
3439 | (if (bolp) (skip-chars-forward (concat " \t" comment-start))) | |
3440 | (setq fill-prefix nil)))) | |
3441 | ||
3442 | (defun idlwave-calc-hanging-indent () | |
3443 | "Calculate the position of the hanging indent for the comment | |
3444 | paragraph. The hanging indent position is given by the first match | |
3445 | with the `idlwave-hang-indent-regexp'. If `idlwave-use-last-hang-indent' is | |
3446 | non-nil then use last occurrence matching `idlwave-hang-indent-regexp' on | |
3447 | the line. | |
3448 | If not found returns nil." | |
3449 | (if idlwave-use-last-hang-indent | |
3450 | (save-excursion | |
3451 | (end-of-line) | |
3452 | (if (re-search-backward | |
3453 | idlwave-hang-indent-regexp | |
3454 | (save-excursion (beginning-of-line) (point)) | |
3455 | t) | |
3456 | (+ (current-column) (length idlwave-hang-indent-regexp)))) | |
3457 | (save-excursion | |
3458 | (beginning-of-line) | |
3459 | (if (re-search-forward | |
3460 | idlwave-hang-indent-regexp | |
3461 | (save-excursion (end-of-line) (point)) | |
3462 | t) | |
3463 | (current-column))))) | |
3464 | ||
3465 | (defun idlwave-auto-fill () | |
4b1aaa8b | 3466 | "Called to break lines in auto fill mode. |
52a244eb S |
3467 | Only fills non-comment lines if `idlwave-fill-comment-line-only' is |
3468 | non-nil. Places a continuation character at the end of the line if | |
3469 | not in a comment. Splits strings with IDL concatenation operator `+' | |
3470 | if `idlwave-auto-fill-split-string' is non-nil." | |
f32b3b91 CD |
3471 | (if (<= (current-column) fill-column) |
3472 | nil ; do not to fill | |
3473 | (if (or (not idlwave-fill-comment-line-only) | |
3474 | (save-excursion | |
3475 | ;; Check for comment line | |
3476 | (beginning-of-line) | |
3477 | (looking-at idlwave-comment-line-start-skip))) | |
3478 | (let (beg) | |
3479 | (idlwave-indent-line) | |
3480 | ;; Prevent actions do-auto-fill which calls indent-line-function. | |
3481 | (let (idlwave-do-actions | |
d6aac72d | 3482 | (paragraph-separate ".") |
52a244eb S |
3483 | (fill-nobreak-predicate |
3484 | (if (and (idlwave-in-quote) | |
3485 | idlwave-auto-fill-split-string) | |
3486 | (lambda () ;; We'll need 5 spaces for " ' + $" | |
3487 | (<= (- fill-column (current-column)) 5) | |
3488 | )))) | |
f32b3b91 CD |
3489 | (do-auto-fill)) |
3490 | (save-excursion | |
3491 | (end-of-line 0) | |
3492 | ;; Indent the split line | |
a86bd650 | 3493 | (idlwave-indent-line)) |
f32b3b91 CD |
3494 | (if (save-excursion |
3495 | (beginning-of-line) | |
3496 | (looking-at idlwave-comment-line-start-skip)) | |
3497 | ;; A continued line comment | |
3498 | ;; We treat continued line comments as part of a comment | |
3499 | ;; paragraph. So we check for a hanging indent. | |
3500 | (if idlwave-hanging-indent | |
3501 | (let ((here (- (point-max) (point))) | |
3502 | (indent | |
3503 | (save-excursion | |
3504 | (forward-line -1) | |
3505 | (idlwave-calc-hanging-indent)))) | |
3506 | (if indent | |
3507 | (progn | |
3508 | ;; Remove whitespace between comment delimiter and | |
3509 | ;; text, insert spaces for appropriate indentation. | |
3510 | (beginning-of-line) | |
3511 | (re-search-forward | |
3512 | comment-start-skip | |
3513 | (save-excursion (end-of-line) (point)) t) | |
3514 | (delete-horizontal-space) | |
3515 | (idlwave-indent-to indent) | |
3516 | (goto-char (- (point-max) here))) | |
3517 | ))) | |
3518 | ;; Split code or comment? | |
3519 | (if (save-excursion | |
3520 | (end-of-line 0) | |
3521 | (idlwave-in-comment)) | |
52a244eb | 3522 | ;; Splitting a non-full-line comment. |
f32b3b91 CD |
3523 | ;; Insert the comment delimiter from split line |
3524 | (progn | |
3525 | (save-excursion | |
3526 | (beginning-of-line) | |
3527 | (skip-chars-forward " \t") | |
3528 | ;; Insert blank to keep off beginning of line | |
3529 | (insert " " | |
3530 | (save-excursion | |
3531 | (forward-line -1) | |
3532 | (buffer-substring (idlwave-goto-comment) | |
3533 | (progn | |
3534 | (skip-chars-forward "; ") | |
3535 | (point)))))) | |
3536 | (idlwave-indent-line)) | |
3537 | ;; Split code line - add continuation character | |
3538 | (save-excursion | |
3539 | (end-of-line 0) | |
3540 | ;; Check to see if we split a string | |
3541 | (if (and (setq beg (idlwave-in-quote)) | |
3542 | idlwave-auto-fill-split-string) | |
3543 | ;; Split the string and concatenate. | |
3544 | ;; The first extra space is for the space | |
3545 | ;; the line was split. That space was removed. | |
3546 | (insert " " (char-after beg) " +")) | |
3547 | (insert " $")) | |
3548 | (if beg | |
3549 | (if idlwave-auto-fill-split-string | |
3550 | ;; Make the second part of continued string | |
3551 | (save-excursion | |
3552 | (beginning-of-line) | |
3553 | (skip-chars-forward " \t") | |
3554 | (insert (char-after beg))) | |
3555 | ;; Warning | |
3556 | (beep) | |
3557 | (message "Warning: continuation inside a string."))) | |
3558 | ;; Although do-auto-fill (via indent-new-comment-line) calls | |
3559 | ;; idlwave-indent-line for the new line, re-indent again | |
3560 | ;; because of the addition of the continuation character. | |
3561 | (idlwave-indent-line)) | |
3562 | ))))) | |
3563 | ||
3564 | (defun idlwave-auto-fill-mode (arg) | |
3565 | "Toggle auto-fill mode for IDL mode. | |
3566 | With arg, turn auto-fill mode on if arg is positive. | |
3567 | In auto-fill mode, inserting a space at a column beyond `fill-column' | |
3568 | automatically breaks the line at a previous space." | |
3569 | (interactive "P") | |
3570 | (prog1 (set idlwave-fill-function | |
3571 | (if (if (null arg) | |
3572 | (not (symbol-value idlwave-fill-function)) | |
3573 | (> (prefix-numeric-value arg) 0)) | |
3574 | 'idlwave-auto-fill | |
3575 | nil)) | |
3576 | ;; update mode-line | |
3577 | (set-buffer-modified-p (buffer-modified-p)))) | |
3578 | ||
52a244eb S |
3579 | ;(defun idlwave-fill-routine-call () |
3580 | ; "Fill a routine definition or statement, indenting appropriately." | |
3581 | ; (let ((where (idlwave-where))))) | |
3582 | ||
3583 | ||
f32b3b91 CD |
3584 | (defun idlwave-doc-header (&optional nomark ) |
3585 | "Insert a documentation header at the beginning of the unit. | |
3586 | Inserts the value of the variable idlwave-file-header. Sets mark before | |
3587 | moving to do insertion unless the optional prefix argument NOMARK | |
3588 | is non-nil." | |
3589 | (interactive "P") | |
3590 | (or nomark (push-mark)) | |
3591 | ;; make sure we catch the current line if it begins the unit | |
5e72c6b2 S |
3592 | (if idlwave-header-to-beginning-of-file |
3593 | (goto-char (point-min)) | |
3594 | (end-of-line) | |
3595 | (idlwave-beginning-of-subprogram) | |
3596 | (beginning-of-line) | |
3597 | ;; skip function or procedure line | |
3598 | (if (idlwave-look-at "\\<\\(pro\\|function\\)\\>") | |
3599 | (progn | |
3600 | (idlwave-end-of-statement) | |
3601 | (if (> (forward-line 1) 0) (insert "\n"))))) | |
3602 | (let ((pos (point))) | |
3603 | (if idlwave-file-header | |
3604 | (cond ((car idlwave-file-header) | |
a527b753 | 3605 | (insert-file-contents (car idlwave-file-header))) |
5e72c6b2 S |
3606 | ((stringp (car (cdr idlwave-file-header))) |
3607 | (insert (car (cdr idlwave-file-header)))))) | |
3608 | (goto-char pos))) | |
f32b3b91 CD |
3609 | |
3610 | (defun idlwave-default-insert-timestamp () | |
3611 | "Default timestamp insertion function" | |
3612 | (insert (current-time-string)) | |
3613 | (insert ", " (user-full-name)) | |
5e72c6b2 | 3614 | (if (boundp 'user-mail-address) |
4b1aaa8b | 3615 | (insert " <" user-mail-address ">") |
5e72c6b2 | 3616 | (insert " <" (user-login-name) "@" (system-name) ">")) |
f32b3b91 CD |
3617 | ;; Remove extra spaces from line |
3618 | (idlwave-fill-paragraph) | |
3619 | ;; Insert a blank line comment to separate from the date entry - | |
3620 | ;; will keep the entry from flowing onto date line if re-filled. | |
5e72c6b2 | 3621 | (insert "\n;\n;\t\t")) |
f32b3b91 CD |
3622 | |
3623 | (defun idlwave-doc-modification () | |
3624 | "Insert a brief modification log at the beginning of the current program. | |
3625 | Looks for an occurrence of the value of user variable | |
3626 | `idlwave-doc-modifications-keyword' if non-nil. Inserts time and user name | |
3627 | and places the point for the user to add a log. Before moving, saves | |
3628 | location on mark ring so that the user can return to previous point." | |
3629 | (interactive) | |
3630 | (push-mark) | |
05a1abfc CD |
3631 | (let* (beg end) |
3632 | (if (and (or (re-search-backward idlwave-doclib-start nil t) | |
3633 | (progn | |
3634 | (goto-char (point-min)) | |
3635 | (re-search-forward idlwave-doclib-start nil t))) | |
3636 | (setq beg (match-beginning 0)) | |
3637 | (re-search-forward idlwave-doclib-end nil t) | |
3638 | (setq end (match-end 0))) | |
3639 | (progn | |
3640 | (goto-char beg) | |
4b1aaa8b | 3641 | (if (re-search-forward |
05a1abfc CD |
3642 | (concat idlwave-doc-modifications-keyword ":") |
3643 | end t) | |
3644 | (end-of-line) | |
3645 | (goto-char end) | |
3646 | (end-of-line -1) | |
3647 | (insert "\n" comment-start "\n") | |
3648 | (insert comment-start " " idlwave-doc-modifications-keyword ":")) | |
3649 | (insert "\n;\n;\t") | |
3650 | (run-hooks 'idlwave-timestamp-hook)) | |
3651 | (error "No valid DOCLIB header")))) | |
f32b3b91 | 3652 | |
e08734e2 | 3653 | |
f32b3b91 CD |
3654 | ;;; CJC 3/16/93 |
3655 | ;;; Interface to expand-region-abbrevs which did not work when the | |
3656 | ;;; abbrev hook associated with an abbrev moves point backwards | |
3657 | ;;; after abbrev expansion, e.g., as with the abbrev '.n'. | |
3658 | ;;; The original would enter an infinite loop in attempting to expand | |
3659 | ;;; .n (it would continually expand and unexpand the abbrev without expanding | |
3660 | ;;; because the point would keep going back to the beginning of the | |
3661 | ;;; abbrev instead of to the end of the abbrev). We now keep the | |
3662 | ;;; abbrev hook from moving backwards. | |
3663 | ;;; | |
3664 | (defun idlwave-expand-region-abbrevs (start end) | |
3665 | "Expand each abbrev occurrence in the region. | |
3666 | Calling from a program, arguments are START END." | |
3667 | (interactive "r") | |
3668 | (save-excursion | |
3669 | (goto-char (min start end)) | |
3670 | (let ((idlwave-show-block nil) ;Do not blink | |
3671 | (idlwave-abbrev-move nil)) ;Do not move | |
3672 | (expand-region-abbrevs start end 'noquery)))) | |
3673 | ||
3674 | (defun idlwave-quoted () | |
3675 | "Returns t if point is in a comment or quoted string. | |
3676 | nil otherwise." | |
3677 | (or (idlwave-in-comment) (idlwave-in-quote))) | |
3678 | ||
3679 | (defun idlwave-in-quote () | |
3680 | "Returns location of the opening quote | |
3681 | if point is in a IDL string constant, nil otherwise. | |
3682 | Ignores comment delimiters on the current line. | |
3683 | Properly handles nested quotation marks and octal | |
3684 | constants - a double quote followed by an octal digit." | |
3685 | ;;; Treat an octal inside an apostrophe to be a normal string. Treat a | |
3686 | ;;; double quote followed by an octal digit to be an octal constant | |
3687 | ;;; rather than a string. Therefore, there is no terminating double | |
3688 | ;;; quote. | |
3689 | (save-excursion | |
3690 | ;; Because single and double quotes can quote each other we must | |
3691 | ;; search for the string start from the beginning of line. | |
3692 | (let* ((start (point)) | |
3693 | (eol (progn (end-of-line) (point))) | |
3694 | (bq (progn (beginning-of-line) (point))) | |
3695 | (endq (point)) | |
3696 | (data (match-data)) | |
3697 | delim | |
3698 | found) | |
3699 | (while (< endq start) | |
3700 | ;; Find string start | |
3701 | ;; Don't find an octal constant beginning with a double quote | |
52a244eb | 3702 | (if (re-search-forward "[\"']" eol 'lim) |
f32b3b91 CD |
3703 | ;; Find the string end. |
3704 | ;; In IDL, two consecutive delimiters after the start of a | |
3705 | ;; string act as an | |
3706 | ;; escape for the delimiter in the string. | |
3707 | ;; Two consecutive delimiters alone (i.e., not after the | |
aa87aafc | 3708 | ;; start of a string) is the null string. |
f32b3b91 CD |
3709 | (progn |
3710 | ;; Move to position after quote | |
3711 | (goto-char (1+ (match-beginning 0))) | |
3712 | (setq bq (1- (point))) | |
3713 | ;; Get the string delimiter | |
3714 | (setq delim (char-to-string (preceding-char))) | |
3715 | ;; Check for null string | |
3716 | (if (looking-at delim) | |
3717 | (progn (setq endq (point)) (forward-char 1)) | |
3718 | ;; Look for next unpaired delimiter | |
3719 | (setq found (search-forward delim eol 'lim)) | |
3720 | (while (looking-at delim) | |
3721 | (forward-char 1) | |
3722 | (setq found (search-forward delim eol 'lim))) | |
3723 | (if found | |
3724 | (setq endq (- (point) 1)) | |
3725 | (setq endq (point))) | |
3726 | )) | |
3727 | (progn (setq bq (point)) (setq endq (point))))) | |
3728 | (store-match-data data) | |
3729 | ;; return string beginning position or nil | |
3730 | (if (> start bq) bq)))) | |
3731 | ||
76959b77 S |
3732 | (defun idlwave-is-pointer-dereference (&optional limit) |
3733 | "Determines if the character after point is a pointer dereference *." | |
3734 | (let ((pos (point))) | |
3735 | (and | |
3736 | (eq (char-after) ?\*) | |
3737 | (not (idlwave-in-quote)) | |
3738 | (save-excursion | |
3739 | (forward-char) | |
4b1aaa8b | 3740 | (re-search-backward (concat "\\(" idlwave-idl-keywords |
76959b77 S |
3741 | "\\|[[(*+-/=,^><]\\)\\s-*\\*") limit t))))) |
3742 | ||
3743 | ||
f32b3b91 CD |
3744 | ;; Statement templates |
3745 | ||
3746 | ;; Replace these with a general template function, something like | |
3747 | ;; expand.el (I think there was also something with a name similar to | |
3748 | ;; dmacro.el) | |
3749 | ||
3750 | (defun idlwave-template (s1 s2 &optional prompt noindent) | |
3751 | "Build a template with optional prompt expression. | |
3752 | ||
3753 | Opens a line if point is not followed by a newline modulo intervening | |
3754 | whitespace. S1 and S2 are strings. S1 is inserted at point followed | |
595ab50b CD |
3755 | by S2. Point is inserted between S1 and S2. The case of S1 and S2 is |
3756 | adjusted according to `idlwave-abbrev-change-case'. If optional argument | |
f32b3b91 CD |
3757 | PROMPT is a string then it is displayed as a message in the |
3758 | minibuffer. The PROMPT serves as a reminder to the user of an | |
3759 | expression to enter. | |
3760 | ||
3761 | The lines containing S1 and S2 are reindented using `indent-region' | |
3762 | unless the optional second argument NOINDENT is non-nil." | |
15e42531 | 3763 | (if (eq major-mode 'idlwave-shell-mode) |
05a1abfc | 3764 | ;; This is a gross hack to avoit template abbrev expansion |
15e42531 CD |
3765 | ;; in the shell. FIXME: This is a dirty hack. |
3766 | (if (and (eq this-command 'self-insert-command) | |
3767 | (equal last-abbrev-location (point))) | |
3768 | (insert last-abbrev-text) | |
3769 | (error "No templates in idlwave-shell")) | |
3770 | (cond ((eq idlwave-abbrev-change-case 'down) | |
3771 | (setq s1 (downcase s1) s2 (downcase s2))) | |
3772 | (idlwave-abbrev-change-case | |
3773 | (setq s1 (upcase s1) s2 (upcase s2)))) | |
3774 | (let ((beg (save-excursion (beginning-of-line) (point))) | |
3775 | end) | |
3776 | (if (not (looking-at "\\s-*\n")) | |
3777 | (open-line 1)) | |
3778 | (insert s1) | |
3779 | (save-excursion | |
3780 | (insert s2) | |
3781 | (setq end (point))) | |
3782 | (if (not noindent) | |
3783 | (indent-region beg end nil)) | |
3784 | (if (stringp prompt) | |
274f1353 | 3785 | (message "%s" prompt))))) |
4b1aaa8b | 3786 | |
595ab50b CD |
3787 | (defun idlwave-rw-case (string) |
3788 | "Make STRING have the case required by `idlwave-reserved-word-upcase'." | |
3789 | (if idlwave-reserved-word-upcase | |
3790 | (upcase string) | |
3791 | string)) | |
3792 | ||
f32b3b91 CD |
3793 | (defun idlwave-elif () |
3794 | "Build skeleton IDL if-else block." | |
3795 | (interactive) | |
595ab50b CD |
3796 | (idlwave-template |
3797 | (idlwave-rw-case "if") | |
3798 | (idlwave-rw-case " then begin\n\nendif else begin\n\nendelse") | |
3799 | "Condition expression")) | |
f32b3b91 CD |
3800 | |
3801 | (defun idlwave-case () | |
3802 | "Build skeleton IDL case statement." | |
3803 | (interactive) | |
4b1aaa8b | 3804 | (idlwave-template |
595ab50b CD |
3805 | (idlwave-rw-case "case") |
3806 | (idlwave-rw-case " of\n\nendcase") | |
3807 | "Selector expression")) | |
f32b3b91 | 3808 | |
05a1abfc CD |
3809 | (defun idlwave-switch () |
3810 | "Build skeleton IDL switch statement." | |
3811 | (interactive) | |
4b1aaa8b | 3812 | (idlwave-template |
05a1abfc CD |
3813 | (idlwave-rw-case "switch") |
3814 | (idlwave-rw-case " of\n\nendswitch") | |
3815 | "Selector expression")) | |
3816 | ||
f32b3b91 CD |
3817 | (defun idlwave-for () |
3818 | "Build skeleton for loop statment." | |
3819 | (interactive) | |
4b1aaa8b | 3820 | (idlwave-template |
595ab50b CD |
3821 | (idlwave-rw-case "for") |
3822 | (idlwave-rw-case " do begin\n\nendfor") | |
3823 | "Loop expression")) | |
f32b3b91 CD |
3824 | |
3825 | (defun idlwave-if () | |
3826 | "Build skeleton for loop statment." | |
3827 | (interactive) | |
595ab50b CD |
3828 | (idlwave-template |
3829 | (idlwave-rw-case "if") | |
3830 | (idlwave-rw-case " then begin\n\nendif") | |
3831 | "Scalar logical expression")) | |
f32b3b91 CD |
3832 | |
3833 | (defun idlwave-procedure () | |
3834 | (interactive) | |
4b1aaa8b | 3835 | (idlwave-template |
595ab50b CD |
3836 | (idlwave-rw-case "pro") |
3837 | (idlwave-rw-case "\n\nreturn\nend") | |
3838 | "Procedure name")) | |
f32b3b91 CD |
3839 | |
3840 | (defun idlwave-function () | |
3841 | (interactive) | |
4b1aaa8b | 3842 | (idlwave-template |
595ab50b CD |
3843 | (idlwave-rw-case "function") |
3844 | (idlwave-rw-case "\n\nreturn\nend") | |
3845 | "Function name")) | |
f32b3b91 CD |
3846 | |
3847 | (defun idlwave-repeat () | |
3848 | (interactive) | |
595ab50b CD |
3849 | (idlwave-template |
3850 | (idlwave-rw-case "repeat begin\n\nendrep until") | |
3851 | (idlwave-rw-case "") | |
3852 | "Exit condition")) | |
f32b3b91 CD |
3853 | |
3854 | (defun idlwave-while () | |
3855 | (interactive) | |
4b1aaa8b | 3856 | (idlwave-template |
595ab50b CD |
3857 | (idlwave-rw-case "while") |
3858 | (idlwave-rw-case " do begin\n\nendwhile") | |
3859 | "Entry condition")) | |
f32b3b91 CD |
3860 | |
3861 | (defun idlwave-split-string (string &optional pattern) | |
3862 | "Return a list of substrings of STRING which are separated by PATTERN. | |
3863 | If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"." | |
3864 | (or pattern | |
3865 | (setq pattern "[ \f\t\n\r\v]+")) | |
3866 | (let (parts (start 0)) | |
3867 | (while (string-match pattern string start) | |
3868 | (setq parts (cons (substring string start (match-beginning 0)) parts) | |
3869 | start (match-end 0))) | |
3870 | (nreverse (cons (substring string start) parts)))) | |
3871 | ||
3872 | (defun idlwave-replace-string (string replace_string replace_with) | |
3873 | (let* ((start 0) | |
3874 | (last (length string)) | |
3875 | (ret_string "") | |
3876 | end) | |
3877 | (while (setq end (string-match replace_string string start)) | |
3878 | (setq ret_string | |
3879 | (concat ret_string (substring string start end) replace_with)) | |
3880 | (setq start (match-end 0))) | |
3881 | (setq ret_string (concat ret_string (substring string start last))))) | |
3882 | ||
3883 | (defun idlwave-get-buffer-visiting (file) | |
3884 | ;; Return the buffer currently visiting FILE | |
3885 | (cond | |
3886 | ((boundp 'find-file-compare-truenames) ; XEmacs | |
3887 | (let ((find-file-compare-truenames t)) | |
3888 | (get-file-buffer file))) | |
3889 | ((fboundp 'find-buffer-visiting) ; Emacs | |
3890 | (find-buffer-visiting file)) | |
3891 | (t (error "This should not happen (idlwave-get-buffer-visiting)")))) | |
3892 | ||
15e42531 CD |
3893 | (defvar idlwave-outlawed-buffers nil |
3894 | "List of buffer pulled up by idlwave for special reasons. | |
3895 | Buffers in this list may be killed by `idlwave-kill-autoloaded-buffers'.") | |
3896 | ||
3897 | (defun idlwave-find-file-noselect (file &optional why) | |
f32b3b91 CD |
3898 | ;; Return a buffer visiting file. |
3899 | (or (idlwave-get-buffer-visiting file) | |
15e42531 CD |
3900 | (let ((buf (find-file-noselect file))) |
3901 | (if why (add-to-list 'idlwave-outlawed-buffers (cons buf why))) | |
3902 | buf))) | |
3903 | ||
3904 | (defun idlwave-kill-autoloaded-buffers () | |
52a244eb | 3905 | "Kill buffers created automatically by IDLWAVE. |
15e42531 CD |
3906 | Function prompts for a letter to identify the buffers to kill. |
3907 | Possible letters are: | |
3908 | ||
3909 | f Buffers created by the command \\[idlwave-find-module] or mouse | |
3910 | clicks in the routine info window. | |
3911 | s Buffers created by the IDLWAVE Shell to display where execution | |
3912 | stopped or an error was found. | |
3913 | a Both of the above. | |
3914 | ||
3915 | Buffer containing unsaved changes require confirmation before they are killed." | |
3916 | (interactive) | |
3917 | (if (null idlwave-outlawed-buffers) | |
3918 | (error "No IDLWAVE-created buffers available") | |
3919 | (princ (format "Kill IDLWAVE-created buffers: [f]ind source(%d), [s]hell display(%d), [a]ll ? " | |
3920 | (idlwave-count-outlawed-buffers 'find) | |
3921 | (idlwave-count-outlawed-buffers 'shell))) | |
3922 | (let ((c (read-char))) | |
3923 | (cond | |
3924 | ((member c '(?f ?\C-f)) | |
3925 | (idlwave-do-kill-autoloaded-buffers 'find)) | |
3926 | ((member c '(?s ?\C-s)) | |
3927 | (idlwave-do-kill-autoloaded-buffers 'shell)) | |
3928 | ((member c '(?a ?\C-a)) | |
3929 | (idlwave-do-kill-autoloaded-buffers t)) | |
3930 | (t (error "Abort")))))) | |
3931 | ||
3932 | (defun idlwave-count-outlawed-buffers (tag) | |
3933 | "How many outlawed buffers have tag TAG?" | |
3934 | (length (delq nil | |
4b1aaa8b PE |
3935 | (mapcar |
3936 | (lambda (x) (eq (cdr x) tag)) | |
15e42531 CD |
3937 | idlwave-outlawed-buffers)))) |
3938 | ||
3939 | (defun idlwave-do-kill-autoloaded-buffers (&rest reasons) | |
3940 | "Kill all buffers pulled up by IDLWAVE matching REASONS." | |
3941 | (let* ((list (copy-sequence idlwave-outlawed-buffers)) | |
3942 | (cnt 0) | |
3943 | entry) | |
3944 | (while (setq entry (pop list)) | |
3945 | (if (buffer-live-p (car entry)) | |
3946 | (and (or (memq t reasons) | |
3947 | (memq (cdr entry) reasons)) | |
3948 | (kill-buffer (car entry)) | |
3949 | (incf cnt) | |
4b1aaa8b | 3950 | (setq idlwave-outlawed-buffers |
15e42531 | 3951 | (delq entry idlwave-outlawed-buffers))) |
4b1aaa8b | 3952 | (setq idlwave-outlawed-buffers |
15e42531 CD |
3953 | (delq entry idlwave-outlawed-buffers)))) |
3954 | (message "%d buffer%s killed" cnt (if (= cnt 1) "" "s")))) | |
3955 | ||
3956 | (defun idlwave-revoke-license-to-kill () | |
3957 | "Remove BUFFER from the buffers which may be killed. | |
3958 | Killing would be done by `idlwave-do-kill-autoloaded-buffers'. | |
3959 | Intended for `after-save-hook'." | |
3960 | (let* ((buf (current-buffer)) | |
3961 | (entry (assq buf idlwave-outlawed-buffers))) | |
3962 | ;; Revoke license | |
3963 | (if entry | |
4b1aaa8b | 3964 | (setq idlwave-outlawed-buffers |
15e42531 CD |
3965 | (delq entry idlwave-outlawed-buffers))) |
3966 | ;; Remove this function from the hook. | |
3967 | (remove-hook 'after-save-hook 'idlwave-revoke-license-to-kill 'local))) | |
3968 | ||
3969 | (defvar idlwave-path-alist) | |
3970 | (defun idlwave-locate-lib-file (file) | |
f32b3b91 | 3971 | ;; Find FILE on the scanned lib path and return a buffer visiting it |
15e42531 | 3972 | (let* ((dirs idlwave-path-alist) |
f32b3b91 CD |
3973 | dir efile) |
3974 | (catch 'exit | |
15e42531 | 3975 | (while (setq dir (car (pop dirs))) |
f32b3b91 CD |
3976 | (if (file-regular-p |
3977 | (setq efile (expand-file-name file dir))) | |
15e42531 | 3978 | (throw 'exit efile)))))) |
52a244eb | 3979 | |
15e42531 CD |
3980 | (defun idlwave-expand-lib-file-name (file) |
3981 | ;; Find FILE on the scanned lib path and return a buffer visiting it | |
52a244eb | 3982 | ;; This is for, e.g., finding source with no user catalog |
4b1aaa8b | 3983 | (cond |
15e42531 | 3984 | ((null file) nil) |
15e42531 CD |
3985 | ((file-name-absolute-p file) file) |
3986 | (t (idlwave-locate-lib-file file)))) | |
f32b3b91 CD |
3987 | |
3988 | (defun idlwave-make-tags () | |
3989 | "Creates the IDL tags file IDLTAGS in the current directory from | |
3990 | the list of directories specified in the minibuffer. Directories may be | |
3991 | for example: . /usr/local/rsi/idl/lib. All the subdirectories of the | |
3992 | specified top directories are searched if the directory name is prefixed | |
3993 | by @. Specify @ directories with care, it may take a long, long time if | |
3994 | you specify /." | |
3995 | (interactive) | |
3996 | (let (directory directories cmd append status numdirs dir getsubdirs | |
3997 | buffer save_buffer files numfiles item errbuf) | |
4b1aaa8b | 3998 | |
f32b3b91 CD |
3999 | ;; |
4000 | ;; Read list of directories | |
4001 | (setq directory (read-string "Tag Directories: " ".")) | |
4002 | (setq directories (idlwave-split-string directory "[ \t]+")) | |
4003 | ;; | |
4004 | ;; Set etags command, vars | |
4005 | (setq cmd "etags --output=IDLTAGS --language=none --regex='/[ | |
4006 | \\t]*[pP][Rr][Oo][ \\t]+\\([^ \\t,]+\\)/' --regex='/[ | |
4007 | \\t]*[Ff][Uu][Nn][Cc][Tt][Ii][Oo][Nn][ \\t]+\\([^ \\t,]+\\)/' ") | |
4008 | (setq append " ") | |
4009 | (setq status 0) | |
4010 | ;; | |
4011 | ;; For each directory | |
4012 | (setq numdirs 0) | |
4013 | (setq dir (nth numdirs directories)) | |
4014 | (while (and dir) | |
4015 | ;; | |
4016 | ;; Find the subdirectories | |
4017 | (if (string-match "^[@]\\(.+\\)$" dir) | |
4018 | (setq getsubdirs t) (setq getsubdirs nil)) | |
4019 | (if (and getsubdirs) (setq dir (substring dir 1 (length dir)))) | |
4020 | (setq dir (expand-file-name dir)) | |
4021 | (if (file-directory-p dir) | |
4022 | (progn | |
4023 | (if (and getsubdirs) | |
4024 | (progn | |
4025 | (setq buffer (get-buffer-create "*idltags*")) | |
4026 | (call-process "sh" nil buffer nil "-c" | |
4027 | (concat "find " dir " -type d -print")) | |
4028 | (setq save_buffer (current-buffer)) | |
4029 | (set-buffer buffer) | |
4030 | (setq files (idlwave-split-string | |
4031 | (idlwave-replace-string | |
4032 | (buffer-substring 1 (point-max)) | |
4033 | "\n" "/*.pro ") | |
4034 | "[ \t]+")) | |
4035 | (set-buffer save_buffer) | |
4036 | (kill-buffer buffer)) | |
4037 | (setq files (list (concat dir "/*.pro")))) | |
4038 | ;; | |
4039 | ;; For each subdirectory | |
4040 | (setq numfiles 0) | |
4041 | (setq item (nth numfiles files)) | |
4042 | (while (and item) | |
4043 | ;; | |
4044 | ;; Call etags | |
4045 | (if (not (string-match "^[ \\t]*$" item)) | |
4046 | (progn | |
29a4e67d | 4047 | (message "%s" (concat "Tagging " item "...")) |
f32b3b91 | 4048 | (setq errbuf (get-buffer-create "*idltags-error*")) |
52a244eb | 4049 | (setq status (+ status |
4b1aaa8b | 4050 | (if (eq 0 (call-process |
52a244eb S |
4051 | "sh" nil errbuf nil "-c" |
4052 | (concat cmd append item))) | |
4053 | 0 | |
4054 | 1))) | |
f32b3b91 CD |
4055 | ;; |
4056 | ;; Append additional tags | |
4057 | (setq append " --append ") | |
4058 | (setq numfiles (1+ numfiles)) | |
4059 | (setq item (nth numfiles files))) | |
4060 | (progn | |
4061 | (setq numfiles (1+ numfiles)) | |
4062 | (setq item (nth numfiles files)) | |
4063 | ))) | |
4b1aaa8b | 4064 | |
f32b3b91 CD |
4065 | (setq numdirs (1+ numdirs)) |
4066 | (setq dir (nth numdirs directories))) | |
4067 | (progn | |
4068 | (setq numdirs (1+ numdirs)) | |
4069 | (setq dir (nth numdirs directories))))) | |
4b1aaa8b | 4070 | |
f32b3b91 CD |
4071 | (setq errbuf (get-buffer-create "*idltags-error*")) |
4072 | (if (= status 0) | |
4073 | (kill-buffer errbuf)) | |
4074 | (message "") | |
4075 | )) | |
4076 | ||
4077 | (defun idlwave-toggle-comment-region (beg end &optional n) | |
4078 | "Comment the lines in the region if the first non-blank line is | |
4079 | commented, and conversely, uncomment region. If optional prefix arg | |
4080 | N is non-nil, then for N positive, add N comment delimiters or for N | |
4081 | negative, remove N comment delimiters. | |
4082 | Uses `comment-region' which does not place comment delimiters on | |
4083 | blank lines." | |
4084 | (interactive "r\nP") | |
4085 | (if n | |
4086 | (comment-region beg end (prefix-numeric-value n)) | |
4087 | (save-excursion | |
4088 | (goto-char beg) | |
4089 | (beginning-of-line) | |
4090 | ;; skip blank lines | |
4091 | (skip-chars-forward " \t\n") | |
4092 | (if (looking-at (concat "[ \t]*\\(" comment-start "+\\)")) | |
52a244eb S |
4093 | (if (fboundp 'uncomment-region) |
4094 | (uncomment-region beg end) | |
4095 | (comment-region beg end | |
4096 | (- (length (buffer-substring | |
4097 | (match-beginning 1) | |
4098 | (match-end 1)))))) | |
4099 | (comment-region beg end))))) | |
f32b3b91 CD |
4100 | |
4101 | ||
4102 | ;; ---------------------------------------------------------------------------- | |
4103 | ;; ---------------------------------------------------------------------------- | |
4104 | ;; ---------------------------------------------------------------------------- | |
4105 | ;; ---------------------------------------------------------------------------- | |
4106 | ;; | |
4107 | ;; Completion and Routine Info | |
4108 | ;; | |
4109 | ||
4110 | ;; String "intern" functions | |
4111 | ||
4112 | ;; For the completion and routine info function, we want to normalize | |
4113 | ;; the case of procedure names etc. We do this by "interning" these | |
4114 | ;; string is a hand-crafted way. Hashes are used to map the downcase | |
52a244eb S |
4115 | ;; version of the strings to the cased versions. Most *-sint-* |
4116 | ;; variables consist of *two* hashes, a buffer+shell, followed by a | |
4117 | ;; system hash. The former is re-scanned, and the latter takes case | |
4118 | ;; precedence. | |
4119 | ;; | |
4120 | ;; Since these cased versions are really lisp objects, we can use `eq' | |
4121 | ;; to search, which is a large performance boost. All new strings | |
4122 | ;; need to be "sinterned". We do this as early as possible after | |
4123 | ;; getting these strings from completion or buffer substrings. So | |
4124 | ;; most of the code can simply assume to deal with "sinterned" | |
4125 | ;; strings. The only exception is that the functions which scan whole | |
4126 | ;; buffers for routine information do not intern the grabbed strings. | |
4127 | ;; This is only done afterwards. Therefore in these functions it is | |
4128 | ;; *not* safe to assume the strings can be compared with `eq' and be | |
4129 | ;; fed into the routine assq functions. | |
f32b3b91 CD |
4130 | |
4131 | ;; Here we define the hashing functions. | |
4132 | ||
4133 | ;; The variables which hold the hashes. | |
4134 | (defvar idlwave-sint-routines '(nil)) | |
4135 | (defvar idlwave-sint-keywords '(nil)) | |
4136 | (defvar idlwave-sint-methods '(nil)) | |
4137 | (defvar idlwave-sint-classes '(nil)) | |
52a244eb S |
4138 | (defvar idlwave-sint-dirs '(nil)) |
4139 | (defvar idlwave-sint-libnames '(nil)) | |
f32b3b91 CD |
4140 | |
4141 | (defun idlwave-reset-sintern (&optional what) | |
4142 | "Reset all sintern hashes." | |
4143 | ;; Make sure the hash functions are accessible. | |
4144 | (if (or (not (fboundp 'gethash)) | |
4145 | (not (fboundp 'puthash))) | |
4b1aaa8b | 4146 | (progn |
f32b3b91 CD |
4147 | (require 'cl) |
4148 | (or (fboundp 'puthash) | |
4149 | (defalias 'puthash 'cl-puthash)))) | |
4150 | (let ((entries '((idlwave-sint-routines 1000 10) | |
4151 | (idlwave-sint-keywords 1000 10) | |
4152 | (idlwave-sint-methods 100 10) | |
4153 | (idlwave-sint-classes 10 10)))) | |
4154 | ||
4155 | ;; Make sure these are lists | |
4156 | (loop for entry in entries | |
4157 | for var = (car entry) | |
4158 | do (if (not (consp (symbol-value var))) (set var (list nil)))) | |
4159 | ||
f66f03de | 4160 | ;; Reset the system & library hash |
f32b3b91 CD |
4161 | (when (or (eq what t) (eq what 'syslib) |
4162 | (null (cdr idlwave-sint-routines))) | |
f32b3b91 CD |
4163 | (loop for entry in entries |
4164 | for var = (car entry) for size = (nth 1 entry) | |
4b1aaa8b | 4165 | do (setcdr (symbol-value var) |
f32b3b91 | 4166 | (make-hash-table ':size size ':test 'equal))) |
52a244eb S |
4167 | (setq idlwave-sint-dirs nil |
4168 | idlwave-sint-libnames nil)) | |
f32b3b91 | 4169 | |
f66f03de | 4170 | ;; Reset the buffer & shell hash |
f32b3b91 CD |
4171 | (when (or (eq what t) (eq what 'bufsh) |
4172 | (null (car idlwave-sint-routines))) | |
f32b3b91 CD |
4173 | (loop for entry in entries |
4174 | for var = (car entry) for size = (nth 1 entry) | |
4b1aaa8b | 4175 | do (setcar (symbol-value var) |
f32b3b91 CD |
4176 | (make-hash-table ':size size ':test 'equal)))))) |
4177 | ||
4178 | (defun idlwave-sintern-routine-or-method (name &optional class set) | |
4179 | (if class | |
4180 | (idlwave-sintern-method name set) | |
4181 | (idlwave-sintern-routine name set))) | |
4182 | ||
4183 | (defun idlwave-sintern (stype &rest args) | |
4184 | (apply (intern (concat "idlwave-sintern-" (symbol-name stype))) args)) | |
4185 | ||
4186 | ;;(defmacro idlwave-sintern (type var) | |
4187 | ;; `(cond ((not (stringp name)) name) | |
4188 | ;; ((gethash (downcase name) (cdr ,var))) | |
4189 | ;; ((gethash (downcase name) (car ,var))) | |
4190 | ;; (set (idlwave-sintern-set name ,type ,var set)) | |
4191 | ;; (name))) | |
4192 | ||
4193 | (defun idlwave-sintern-routine (name &optional set) | |
4194 | (cond ((not (stringp name)) name) | |
4195 | ((gethash (downcase name) (cdr idlwave-sint-routines))) | |
4196 | ((gethash (downcase name) (car idlwave-sint-routines))) | |
4197 | (set (idlwave-sintern-set name 'routine idlwave-sint-routines set)) | |
4198 | (name))) | |
4199 | (defun idlwave-sintern-keyword (name &optional set) | |
4200 | (cond ((not (stringp name)) name) | |
4201 | ((gethash (downcase name) (cdr idlwave-sint-keywords))) | |
4202 | ((gethash (downcase name) (car idlwave-sint-keywords))) | |
4203 | (set (idlwave-sintern-set name 'keyword idlwave-sint-keywords set)) | |
4204 | (name))) | |
4205 | (defun idlwave-sintern-method (name &optional set) | |
4206 | (cond ((not (stringp name)) name) | |
4207 | ((gethash (downcase name) (cdr idlwave-sint-methods))) | |
4208 | ((gethash (downcase name) (car idlwave-sint-methods))) | |
4209 | (set (idlwave-sintern-set name 'method idlwave-sint-methods set)) | |
4210 | (name))) | |
4211 | (defun idlwave-sintern-class (name &optional set) | |
4212 | (cond ((not (stringp name)) name) | |
4213 | ((gethash (downcase name) (cdr idlwave-sint-classes))) | |
4214 | ((gethash (downcase name) (car idlwave-sint-classes))) | |
4215 | (set (idlwave-sintern-set name 'class idlwave-sint-classes set)) | |
4216 | (name))) | |
4217 | ||
52a244eb S |
4218 | (defun idlwave-sintern-dir (dir &optional set) |
4219 | (car (or (member dir idlwave-sint-dirs) | |
4220 | (setq idlwave-sint-dirs (cons dir idlwave-sint-dirs))))) | |
4221 | (defun idlwave-sintern-libname (name &optional set) | |
4222 | (car (or (member name idlwave-sint-libnames) | |
4223 | (setq idlwave-sint-libnames (cons name idlwave-sint-libnames))))) | |
f32b3b91 CD |
4224 | |
4225 | (defun idlwave-sintern-set (name type tables set) | |
4226 | (let* ((func (or (cdr (assq type idlwave-completion-case)) | |
4227 | 'identity)) | |
4228 | (iname (funcall (if (eq func 'preserve) 'identity func) name)) | |
4229 | (table (if (eq set 'sys) (cdr tables) (car tables)))) | |
4230 | (puthash (downcase name) iname table) | |
4231 | iname)) | |
4232 | ||
52a244eb S |
4233 | (defun idlwave-sintern-keyword-list (kwd-list &optional set) |
4234 | "Sintern a set of keywords (file (key . link) (key2 . link2) ...)" | |
8ffcfb27 GM |
4235 | (mapc (lambda(x) |
4236 | (setcar x (idlwave-sintern-keyword (car x) set))) | |
4237 | (cdr kwd-list)) | |
52a244eb S |
4238 | kwd-list) |
4239 | ||
4240 | (defun idlwave-sintern-rinfo-list (list &optional set default-dir) | |
4241 | "Sintern all strings in the rinfo LIST. With optional parameter | |
4242 | SET: also set new patterns. Probably this will always have to be t. | |
4243 | If DEFAULT-DIR is passed, it is used as the base of the directory" | |
4244 | (let (entry name type class kwds res source call new) | |
f32b3b91 CD |
4245 | (while list |
4246 | (setq entry (car list) | |
4247 | list (cdr list) | |
4248 | name (car entry) | |
4249 | type (nth 1 entry) | |
4250 | class (nth 2 entry) | |
4251 | source (nth 3 entry) | |
4252 | call (nth 4 entry) | |
52a244eb S |
4253 | kwds (nthcdr 5 entry)) |
4254 | ||
4255 | ;; The class and name | |
f32b3b91 CD |
4256 | (if class |
4257 | (progn | |
4258 | (if (symbolp class) (setq class (symbol-name class))) | |
4259 | (setq class (idlwave-sintern-class class set)) | |
4260 | (setq name (idlwave-sintern-method name set))) | |
4261 | (setq name (idlwave-sintern-routine name set))) | |
4b1aaa8b | 4262 | |
52a244eb S |
4263 | ;; The source |
4264 | (let ((source-type (car source)) | |
4265 | (source-file (nth 1 source)) | |
4b1aaa8b | 4266 | (source-dir (if default-dir |
52a244eb S |
4267 | (file-name-as-directory default-dir) |
4268 | (nth 2 source))) | |
4269 | (source-lib (nth 3 source))) | |
4270 | (if (stringp source-dir) | |
4271 | (setq source-dir (idlwave-sintern-dir source-dir set))) | |
4272 | (if (stringp source-lib) | |
4273 | (setq source-lib (idlwave-sintern-libname source-lib set))) | |
4274 | (setq source (list source-type source-file source-dir source-lib))) | |
4b1aaa8b | 4275 | |
52a244eb S |
4276 | ;; The keywords |
4277 | (setq kwds (mapcar (lambda (x) | |
4278 | (idlwave-sintern-keyword-list x set)) | |
4279 | kwds)) | |
4280 | ||
4281 | ;; Build a canonicalized list | |
4282 | (setq new (nconc (list name type class source call) kwds) | |
4283 | res (cons new res))) | |
f32b3b91 CD |
4284 | (nreverse res))) |
4285 | ||
05a1abfc CD |
4286 | ;; Creating new sintern tables |
4287 | ||
4288 | (defun idlwave-new-sintern-type (tag) | |
4289 | "Define a variable and a function to sintern the new type TAG. | |
4290 | This defines the function `idlwave-sintern-TAG' and the variable | |
4291 | `idlwave-sint-TAGs'." | |
4292 | (let* ((name (symbol-name tag)) | |
4293 | (names (concat name "s")) | |
4294 | (var (intern (concat "idlwave-sint-" names))) | |
4295 | (func (intern (concat "idlwave-sintern-" name)))) | |
4296 | (set var nil) ; initial value of the association list | |
4297 | (fset func ; set the function | |
4298 | `(lambda (name &optional set) | |
4299 | (cond ((not (stringp name)) name) | |
4300 | ((cdr (assoc (downcase name) ,var))) | |
4301 | (set | |
4302 | (setq ,var (cons (cons (downcase name) name) ,var)) | |
4303 | name) | |
4304 | (name)))))) | |
4305 | ||
4306 | (defun idlwave-reset-sintern-type (tag) | |
4307 | "Reset the sintern variable associated with TAG." | |
4308 | (set (intern (concat "idlwave-sint-" (symbol-name tag) "s")) nil)) | |
4309 | ||
f32b3b91 CD |
4310 | ;;--------------------------------------------------------------------------- |
4311 | ||
4312 | ||
4313 | ;; The variables which hold the information | |
15e42531 | 4314 | (defvar idlwave-system-routines nil |
f32b3b91 CD |
4315 | "Holds the routine-info obtained by scanning buffers.") |
4316 | (defvar idlwave-buffer-routines nil | |
4317 | "Holds the routine-info obtained by scanning buffers.") | |
4318 | (defvar idlwave-compiled-routines nil | |
15e42531 CD |
4319 | "Holds the routine-info obtained by asking the shell.") |
4320 | (defvar idlwave-unresolved-routines nil | |
4321 | "Holds the unresolved routine-info obtained by asking the shell.") | |
52a244eb S |
4322 | (defvar idlwave-user-catalog-routines nil |
4323 | "Holds the procedure routine-info from the user scan.") | |
4324 | (defvar idlwave-library-catalog-routines nil | |
3938cb82 S |
4325 | "Holds the procedure routine-info from the .idlwave_catalog library files.") |
4326 | (defvar idlwave-library-catalog-libname nil | |
4327 | "Name of library catalog loaded from .idlwave_catalog files.") | |
15e42531 | 4328 | (defvar idlwave-path-alist nil |
52a244eb S |
4329 | "Alist with !PATH directories and zero or more flags if the dir has |
4330 | been scanned in a user catalog ('user) or discovered in a library | |
4331 | catalog \('lib).") | |
15e42531 CD |
4332 | (defvar idlwave-true-path-alist nil |
4333 | "Like `idlwave-path-alist', but with true filenames.") | |
f32b3b91 | 4334 | (defvar idlwave-routines nil |
b9e4fbd3 | 4335 | "Holds the combined procedure/function/method routine-info.") |
f32b3b91 CD |
4336 | (defvar idlwave-class-alist nil |
4337 | "Holds the class names known to IDLWAVE.") | |
4338 | (defvar idlwave-class-history nil | |
4339 | "The history of classes selected with the minibuffer.") | |
4340 | (defvar idlwave-force-class-query nil) | |
4341 | (defvar idlwave-before-completion-wconf nil | |
4342 | "The window configuration just before the completion buffer was displayed.") | |
15e42531 CD |
4343 | (defvar idlwave-last-system-routine-info-cons-cell nil |
4344 | "The last cons cell in the system routine info.") | |
f32b3b91 CD |
4345 | |
4346 | ;; | |
4347 | ;; The code to get routine info from different sources. | |
4348 | ||
15e42531 | 4349 | (defvar idlwave-system-routines) |
5e72c6b2 S |
4350 | (defvar idlwave-catalog-process nil |
4351 | "The background process currently updating the catalog.") | |
4352 | ||
f32b3b91 CD |
4353 | (defun idlwave-routines () |
4354 | "Provide a list of IDL routines. | |
4355 | This routine loads the builtin routines on the first call. Later it | |
4356 | only returns the value of the variable." | |
5e72c6b2 S |
4357 | (if (and idlwave-catalog-process |
4358 | (processp idlwave-catalog-process)) | |
4359 | (progn | |
4360 | (cond | |
4361 | ((equal (process-status idlwave-catalog-process) 'exit) | |
4362 | (message "updating........") | |
4363 | (setq idlwave-catalog-process nil) | |
4364 | (idlwave-update-routine-info '(4))) | |
4365 | ((equal (process-status idlwave-catalog-process) 'run) | |
4366 | ;; Keep it running... | |
4367 | ) | |
4368 | (t | |
4369 | ;; Something is wrong, get rid of the process | |
4370 | (message "Problem with catalog process") (beep) | |
4371 | (condition-case nil | |
4372 | (kill-process idlwave-catalog-process) | |
4373 | (error nil)) | |
4374 | (setq idlwave-catalog-process nil))))) | |
f32b3b91 CD |
4375 | (or idlwave-routines |
4376 | (progn | |
4377 | (idlwave-update-routine-info) | |
4378 | ;; return the current value | |
4379 | idlwave-routines))) | |
4380 | ||
05a1abfc CD |
4381 | (defvar idlwave-update-rinfo-hook nil |
4382 | "List of functions which should run after a global rinfo update. | |
4383 | Does not run after automatic updates of buffer or the shell.") | |
4384 | ||
5e72c6b2 S |
4385 | (defun idlwave-rescan-catalog-directories () |
4386 | "Rescan the previously selected directories. For batch processing." | |
4387 | (idlwave-update-routine-info '(16))) | |
4388 | ||
4389 | (defun idlwave-rescan-asynchronously () | |
8a6a28ac | 4390 | "Dispatch another Emacs instance to update the idlwave catalog. |
5e72c6b2 S |
4391 | After the process finishes normally, the first access to routine info |
4392 | will re-read the catalog." | |
4393 | (interactive) | |
4394 | (if (processp idlwave-catalog-process) | |
4395 | (if (eq (process-status idlwave-catalog-process) 'run) | |
4396 | (if (yes-or-no-p "A catalog-updating process is running. Kill it? ") | |
4397 | (progn | |
4398 | (condition-case nil | |
4399 | (kill-process idlwave-catalog-process) | |
4400 | (error nil)) | |
4401 | (error "Process killed, no new process started")) | |
4402 | (error "Quit")) | |
4403 | (condition-case nil | |
4404 | (kill-process idlwave-catalog-process) | |
4405 | (error nil)))) | |
52a244eb S |
4406 | (if (or (not idlwave-user-catalog-file) |
4407 | (not (stringp idlwave-user-catalog-file)) | |
4408 | (not (file-regular-p idlwave-user-catalog-file))) | |
5e72c6b2 | 4409 | (error "No catalog has been produced yet")) |
4b1aaa8b | 4410 | (let* ((emacs (concat invocation-directory invocation-name)) |
5e72c6b2 S |
4411 | (args (list "-batch" |
4412 | "-l" (expand-file-name "~/.emacs") | |
4413 | "-l" "idlwave" | |
4414 | "-f" "idlwave-rescan-catalog-directories")) | |
4b1aaa8b | 4415 | (process (apply 'start-process "idlcat" |
5e72c6b2 S |
4416 | nil emacs args))) |
4417 | (setq idlwave-catalog-process process) | |
4b1aaa8b | 4418 | (set-process-sentinel |
5e72c6b2 S |
4419 | process |
4420 | (lambda (pro why) | |
4421 | (when (string-match "finished" why) | |
4422 | (setq idlwave-routines nil | |
4423 | idlwave-system-routines nil | |
4424 | idlwave-catalog-process nil) | |
4425 | (or (idlwave-start-load-rinfo-timer) | |
4426 | (idlwave-update-routine-info '(4)))))) | |
4427 | (message "Background job started to update catalog file"))) | |
4428 | ||
4429 | ||
52a244eb S |
4430 | ;; Format for all routine info user catalog, library catalogs, etc.: |
4431 | ;; | |
4432 | ;; ("ROUTINE" type class | |
4433 | ;; (system) | (lib pro_file dir "LIBNAME") | (user pro_file dir "USERLIB") | | |
4434 | ;; (buffer pro_file dir) | (compiled pro_file dir) | |
4b1aaa8b | 4435 | ;; "calling_string" ("HELPFILE" (("KWD1" . link1) ...)) |
f66f03de | 4436 | ;; ("HELPFILE2" (("KWD2" . link) ...)) ...) |
52a244eb S |
4437 | ;; |
4438 | ;; DIR will be supplied dynamically while loading library catalogs, | |
4439 | ;; and is sinterned to save space, as is LIBNAME. PRO_FILE can be a | |
4440 | ;; complete filepath, in which case DIR is unnecessary. HELPFILE can | |
4441 | ;; be nil, as can LINK1, etc., if no HTML help is available. | |
4442 | ||
4443 | ||
5e72c6b2 | 4444 | (defvar idlwave-load-rinfo-idle-timer) |
3938cb82 S |
4445 | (defvar idlwave-shell-path-query) |
4446 | ||
52a244eb | 4447 | (defun idlwave-update-routine-info (&optional arg no-concatenate) |
f32b3b91 CD |
4448 | "Update the internal routine-info lists. |
4449 | These lists are used by `idlwave-routine-info' (\\[idlwave-routine-info]) | |
4450 | and by `idlwave-complete' (\\[idlwave-complete]) to provide information | |
4451 | about individual routines. | |
4452 | ||
4453 | The information can come from 4 sources: | |
4454 | 1. IDL programs in the current editing session | |
4455 | 2. Compiled modules in an IDL shell running as Emacs subprocess | |
4456 | 3. A list which covers the IDL system routines. | |
4457 | 4. A list which covers the prescanned library files. | |
4458 | ||
4459 | Scans all IDLWAVE-mode buffers of the current editing session (see | |
4460 | `idlwave-scan-all-buffers-for-routine-info'). | |
4461 | When an IDL shell is running, this command also queries the IDL program | |
4462 | for currently compiled routines. | |
4463 | ||
4464 | With prefix ARG, also reload the system and library lists. | |
52a244eb S |
4465 | With two prefix ARG's, also rescans the chosen user catalog tree. |
4466 | With three prefix args, dispatch asynchronous process to do the update. | |
4467 | ||
4468 | If NO-CONCATENATE is non-nil, don't pre-concatenate the routine info | |
4469 | lists, but instead wait for the shell query to complete and | |
4470 | asynchronously finish updating routine info. This is set | |
4471 | automatically when called interactively. When you need routine | |
4472 | information updated immediately, leave NO-CONCATENATE nil." | |
751adbde | 4473 | (interactive "P\np") |
5e72c6b2 S |
4474 | ;; Stop any idle processing |
4475 | (if (or (and (fboundp 'itimerp) | |
4476 | (itimerp idlwave-load-rinfo-idle-timer)) | |
4477 | (and (fboundp 'timerp) | |
4478 | (timerp idlwave-load-rinfo-idle-timer))) | |
4479 | (cancel-timer idlwave-load-rinfo-idle-timer)) | |
4480 | (cond | |
4481 | ((equal arg '(64)) | |
4482 | ;; Start a background process which updates the catalog. | |
4483 | (idlwave-rescan-asynchronously)) | |
4484 | ((equal arg '(16)) | |
52a244eb S |
4485 | ;; Update the user catalog now, and wait for them. |
4486 | (idlwave-create-user-catalog-file t)) | |
5e72c6b2 S |
4487 | (t |
4488 | (let* ((load (or arg | |
4489 | idlwave-buffer-case-takes-precedence | |
4490 | (null idlwave-routines))) | |
4491 | ;; The override-idle means, even if the idle timer has done some | |
4492 | ;; preparing work, load and renormalize everything anyway. | |
4493 | (override-idle (or arg idlwave-buffer-case-takes-precedence))) | |
4b1aaa8b | 4494 | |
f32b3b91 | 4495 | (setq idlwave-buffer-routines nil |
15e42531 CD |
4496 | idlwave-compiled-routines nil |
4497 | idlwave-unresolved-routines nil) | |
f32b3b91 | 4498 | ;; Reset the appropriate hashes |
5e72c6b2 S |
4499 | (if (get 'idlwave-reset-sintern 'done-by-idle) |
4500 | ;; reset was already done in idle time, so skip this step now once | |
4501 | (put 'idlwave-reset-sintern 'done-by-idle nil) | |
4502 | (idlwave-reset-sintern (cond (load t) | |
4503 | ((null idlwave-system-routines) t) | |
4504 | (t 'bufsh)))) | |
4b1aaa8b | 4505 | |
f32b3b91 CD |
4506 | (if idlwave-buffer-case-takes-precedence |
4507 | ;; We can safely scan the buffer stuff first | |
4508 | (progn | |
4509 | (idlwave-update-buffer-routine-info) | |
f66f03de | 4510 | (and load (idlwave-load-all-rinfo override-idle))) |
f32b3b91 | 4511 | ;; We first do the system info, and then the buffers |
f66f03de | 4512 | (and load (idlwave-load-all-rinfo override-idle)) |
f32b3b91 CD |
4513 | (idlwave-update-buffer-routine-info)) |
4514 | ||
4515 | ;; Let's see if there is a shell | |
4516 | (let* ((shell-is-running (and (fboundp 'idlwave-shell-is-running) | |
4517 | (idlwave-shell-is-running))) | |
4518 | (ask-shell (and shell-is-running | |
4519 | idlwave-query-shell-for-routine-info))) | |
4b1aaa8b | 4520 | |
52a244eb | 4521 | ;; Load the library catalogs again, first re-scanning the path |
4b1aaa8b | 4522 | (when arg |
52a244eb S |
4523 | (if shell-is-running |
4524 | (idlwave-shell-send-command idlwave-shell-path-query | |
4525 | '(progn | |
4526 | (idlwave-shell-get-path-info) | |
4527 | (idlwave-scan-library-catalogs)) | |
4528 | 'hide) | |
4529 | (idlwave-scan-library-catalogs))) | |
775591f7 | 4530 | |
f32b3b91 | 4531 | (if (or (not ask-shell) |
52a244eb | 4532 | (not no-concatenate)) |
f32b3b91 CD |
4533 | ;; 1. If we are not going to ask the shell, we need to do the |
4534 | ;; concatenation now. | |
52a244eb S |
4535 | ;; 2. When this function is called non-interactively, it |
4536 | ;; means that someone needs routine info *now*. The | |
4537 | ;; shell update causes the concatenation to be | |
4538 | ;; *delayed*, so not in time for the current command. | |
4539 | ;; Therefore, we do a concatenation now, even though | |
4540 | ;; the shell might do it again. | |
4541 | (idlwave-concatenate-rinfo-lists nil 'run-hooks)) | |
4b1aaa8b | 4542 | |
f32b3b91 | 4543 | (when ask-shell |
52a244eb | 4544 | ;; Ask the shell about the routines it knows of. |
f32b3b91 | 4545 | (message "Querying the shell") |
5e72c6b2 S |
4546 | (idlwave-shell-update-routine-info nil t))))))) |
4547 | ||
52a244eb S |
4548 | |
4549 | (defvar idlwave-load-rinfo-steps-done (make-vector 6 nil)) | |
5e72c6b2 S |
4550 | (defvar idlwave-load-rinfo-idle-timer nil) |
4551 | (defun idlwave-start-load-rinfo-timer () | |
4552 | (if (or (and (fboundp 'itimerp) | |
4553 | (itimerp idlwave-load-rinfo-idle-timer)) | |
4554 | (and (fboundp 'timerp) | |
4555 | (timerp idlwave-load-rinfo-idle-timer))) | |
4556 | (cancel-timer idlwave-load-rinfo-idle-timer)) | |
52a244eb | 4557 | (setq idlwave-load-rinfo-steps-done (make-vector 6 nil)) |
5e72c6b2 S |
4558 | (setq idlwave-load-rinfo-idle-timer nil) |
4559 | (if (and idlwave-init-rinfo-when-idle-after | |
4560 | (numberp idlwave-init-rinfo-when-idle-after) | |
4561 | (not (equal 0 idlwave-init-rinfo-when-idle-after)) | |
4562 | (not idlwave-routines)) | |
4563 | (condition-case nil | |
4564 | (progn | |
4565 | (setq idlwave-load-rinfo-idle-timer | |
4566 | (run-with-idle-timer | |
4567 | idlwave-init-rinfo-when-idle-after | |
4568 | nil 'idlwave-load-rinfo-next-step))) | |
4569 | (error nil)))) | |
4570 | ||
3938cb82 S |
4571 | (defvar idlwave-library-routines nil "Obsolete variable.") |
4572 | ||
f66f03de S |
4573 | ;;------ XML Help routine info system |
4574 | (defun idlwave-load-system-routine-info () | |
4575 | ;; Load the system routine info from the cached routine info file, | |
4576 | ;; which, if necessary, will be re-created from the XML file on | |
4577 | ;; disk. As a last fallback, load the (likely outdated) idlw-rinfo | |
4578 | ;; file distributed with older IDLWAVE versions (<6.0) | |
4b1aaa8b | 4579 | (unless (and (load idlwave-xml-system-rinfo-converted-file |
f66f03de S |
4580 | 'noerror 'nomessage) |
4581 | (idlwave-xml-system-routine-info-up-to-date)) | |
4582 | ;; See if we can create it from XML source | |
4583 | (condition-case nil | |
4584 | (idlwave-convert-xml-system-routine-info) | |
4b1aaa8b PE |
4585 | (error |
4586 | (unless (load idlwave-xml-system-rinfo-converted-file | |
f66f03de S |
4587 | 'noerror 'nomessage) |
4588 | (if idlwave-system-routines | |
4b1aaa8b | 4589 | (message |
f66f03de | 4590 | "Failed to load converted routine info, using old conversion.") |
4b1aaa8b | 4591 | (message |
f66f03de S |
4592 | "Failed to convert XML routine info, falling back on idlw-rinfo.") |
4593 | (if (not (load "idlw-rinfo" 'noerror 'nomessage)) | |
4b1aaa8b | 4594 | (message |
f66f03de S |
4595 | "Could not locate any system routine information.")))))))) |
4596 | ||
4597 | (defun idlwave-xml-system-routine-info-up-to-date() | |
4b1aaa8b | 4598 | (let* ((dir (file-name-as-directory |
f66f03de S |
4599 | (expand-file-name "help/online_help" (idlwave-sys-dir)))) |
4600 | (catalog-file (expand-file-name "idl_catalog.xml" dir))) | |
4601 | (file-newer-than-file-p ;converted file is newer than catalog | |
4602 | idlwave-xml-system-rinfo-converted-file | |
4603 | catalog-file))) | |
4604 | ||
4605 | (defvar idlwave-system-class-info nil) ; Gathered from idlw-rinfo | |
4606 | (defvar idlwave-system-variables-alist nil | |
4607 | "Alist of system variables and the associated structure tags. | |
4608 | Gets set in cached XML rinfo, or `idlw-rinfo.el'.") | |
4609 | (defvar idlwave-executive-commands-alist nil | |
4610 | "Alist of system variables and their help files.") | |
4611 | (defvar idlwave-help-special-topic-words nil) | |
4612 | ||
4b1aaa8b | 4613 | |
f66f03de S |
4614 | (defun idlwave-shorten-syntax (syntax name &optional class) |
4615 | ;; From a list of syntax statments, shorten with %s and group with "or" | |
4616 | (let ((case-fold-search t)) | |
4b1aaa8b | 4617 | (mapconcat |
f66f03de S |
4618 | (lambda (x) |
4619 | (while (string-match name x) | |
4620 | (setq x (replace-match "%s" t t x))) | |
4b1aaa8b | 4621 | (if class |
f66f03de S |
4622 | (while (string-match class x) |
4623 | (setq x (replace-match "%s" t t x)))) | |
4624 | x) | |
4625 | (nreverse syntax) | |
4626 | " or "))) | |
4627 | ||
4628 | (defun idlwave-xml-create-class-method-lists (xml-entry) | |
4629 | ;; Create a class list entry from the xml parsed list., returning a | |
4630 | ;; cons of form (class-entry method-entries). | |
4631 | (let* ((nameblock (nth 1 xml-entry)) | |
4632 | (class (cdr (assq 'name nameblock))) | |
4633 | (link (cdr (assq 'link nameblock))) | |
4634 | (params (cddr xml-entry)) | |
4635 | (case-fold-search t) | |
4636 | class-entry | |
4637 | method methods-entry extra-kwds | |
4638 | props get-props set-props init-props inherits | |
4639 | pelem ptype) | |
4640 | (while params | |
4641 | (setq pelem (car params)) | |
4642 | (when (listp pelem) | |
4643 | (setq ptype (car pelem) | |
4644 | props (car (cdr pelem))) | |
4645 | (cond | |
4646 | ((eq ptype 'SUPERCLASS) | |
58c8f915 S |
4647 | (let ((pname (cdr (assq 'name props))) |
4648 | (plink (cdr (assq 'link props)))) | |
4649 | (unless (and (string= pname "None") | |
4650 | (string= plink "None")) | |
4651 | (push pname inherits)))) | |
f66f03de S |
4652 | |
4653 | ((eq ptype 'PROPERTY) | |
4654 | (let ((pname (cdr (assq 'name props))) | |
4655 | (plink (cdr (assq 'link props))) | |
4656 | (get (string= (cdr (assq 'get props)) "Yes")) | |
4657 | (set (string= (cdr (assq 'set props)) "Yes")) | |
4658 | (init (string= (cdr (assq 'init props)) "Yes"))) | |
4659 | (if get (push (list pname plink) get-props)) | |
4660 | (if set (push (list pname plink) set-props)) | |
4661 | (if init (push (list pname plink) init-props)))) | |
4662 | ||
4663 | ((eq ptype 'METHOD) | |
4664 | (setq method (cdr (assq 'name props))) | |
4665 | (setq extra-kwds ;;Assume all property keywords are gathered already | |
4666 | (cond | |
4667 | ((string-match (concat class "::Init") method) | |
4668 | (put 'init-props 'matched t) | |
4669 | init-props) | |
4670 | ((string-match (concat class "::GetProperty") method) | |
4671 | (put 'get-props 'matched t) | |
4672 | get-props) | |
4673 | ((string-match (concat class "::SetProperty") method) | |
4674 | (put 'set-props 'matched t) | |
4675 | set-props) | |
4676 | (t nil))) | |
4b1aaa8b PE |
4677 | (setq methods-entry |
4678 | (nconc (idlwave-xml-create-rinfo-list pelem class extra-kwds) | |
f66f03de S |
4679 | methods-entry))) |
4680 | (t))) | |
4681 | (setq params (cdr params))) | |
4682 | ;(unless (get 'init-props 'matched) | |
4683 | ; (message "Failed to match Init in class %s" class)) | |
4684 | ;(unless (get 'get-props 'matched) | |
4685 | ; (message "Failed to match GetProperty in class %s" class)) | |
4686 | ;(unless (get 'set-props 'matched) | |
4687 | ; (message "Failed to match SetProperty in class %s" class)) | |
4b1aaa8b PE |
4688 | (setq class-entry |
4689 | (if inherits | |
f66f03de S |
4690 | (list class (append '(inherits) inherits) (list 'link link)) |
4691 | (list class (list 'link link)))) | |
4692 | (cons class-entry methods-entry))) | |
4b1aaa8b | 4693 | |
f66f03de S |
4694 | (defun idlwave-xml-create-rinfo-list (xml-entry &optional class extra-kws) |
4695 | ;; Create correctly structured list elements from ROUTINE or METHOD | |
4696 | ;; XML list structures. Return a list of list elements, with more | |
4697 | ;; than one sub-list possible if a routine can serve as both | |
4698 | ;; procedure and function (e.g. call_method). | |
4699 | (let* ((nameblock (nth 1 xml-entry)) | |
4700 | (name (cdr (assq 'name nameblock))) | |
4701 | (link (cdr (assq 'link nameblock))) | |
4702 | (params (cddr xml-entry)) | |
4703 | (syntax-vec (make-vector 3 nil)) ; procedure, function, exec command | |
4704 | (case-fold-search t) | |
4705 | syntax kwd klink pref-list kwds pelem ptype entry props result type) | |
4706 | (if class ;; strip out class name from class method name string | |
4707 | (if (string-match (concat class "::") name) | |
4708 | (setq name (substring name (match-end 0))))) | |
4709 | (while params | |
4710 | (setq pelem (car params)) | |
4711 | (when (listp pelem) | |
4712 | (setq ptype (car pelem) | |
4713 | props (car (cdr pelem))) | |
4714 | (cond | |
4715 | ((eq ptype 'SYNTAX) | |
4716 | (setq syntax (cdr (assq 'name props))) | |
4717 | (if (string-match "->" syntax) | |
4718 | (setq syntax (replace-match "->" t nil syntax))) | |
4719 | (setq type (cdr (assq 'type props))) | |
4720 | (push syntax | |
4721 | (aref syntax-vec (cond | |
4722 | ((string-match "^pro" type) 0) | |
4723 | ((string-match "^fun" type) 1) | |
4724 | ((string-match "^exec" type) 2))))) | |
4725 | ((eq ptype 'KEYWORD) | |
4726 | (setq kwd (cdr (assq 'name props)) | |
4727 | klink (cdr (assq 'link props))) | |
4728 | (if (string-match "^\\[XY\\(Z?\\)\\]" kwd) | |
4b1aaa8b PE |
4729 | (progn |
4730 | (setq pref-list | |
f66f03de S |
4731 | (if (match-string 1 kwd) '("X" "Y" "Z") '("X" "Y")) |
4732 | kwd (substring kwd (match-end 0))) | |
4733 | (loop for x in pref-list do | |
4734 | (push (list (concat x kwd) klink) kwds))) | |
4735 | (push (list kwd klink) kwds))) | |
4736 | ||
4737 | (t))); Do nothing for the others | |
4738 | (setq params (cdr params))) | |
4b1aaa8b | 4739 | |
f66f03de S |
4740 | ;; Debug |
4741 | ; (if (and (null (aref syntax-vec 0)) | |
4742 | ; (null (aref syntax-vec 1)) | |
4743 | ; (null (aref syntax-vec 2))) | |
4744 | ; (with-current-buffer (get-buffer-create "IDL_XML_catalog_complaints") | |
4745 | ; (if class | |
4746 | ; (insert (format "Missing SYNTAX entry for %s::%s\n" class name)) | |
4747 | ; (insert (message "Missing SYNTAX entry for %s\n" name))))) | |
4748 | ||
4749 | ;; Executive commands are treated specially | |
4750 | (if (aref syntax-vec 2) | |
4751 | (cons (substring name 1) link) | |
4752 | (if extra-kws (setq kwds (nconc kwds extra-kws))) | |
4753 | (setq kwds (idlwave-rinfo-group-keywords kwds link)) | |
4754 | (loop for idx from 0 to 1 do | |
4755 | (if (aref syntax-vec idx) | |
4b1aaa8b | 4756 | (push (append (list name (if (eq idx 0) 'pro 'fun) |
f66f03de | 4757 | class '(system) |
4b1aaa8b | 4758 | (idlwave-shorten-syntax |
f66f03de S |
4759 | (aref syntax-vec idx) name class)) |
4760 | kwds) result))) | |
4761 | result))) | |
4762 | ||
4763 | ||
4764 | (defun idlwave-rinfo-group-keywords (kwds master-link) | |
4b1aaa8b | 4765 | ;; Group keywords by link file, as a list with elements |
f66f03de S |
4766 | ;; (linkfile ( ("KWD1" . link1) ("KWD2" . link2)) |
4767 | (let (kwd link anchor linkfiles block master-elt) | |
4768 | (while kwds | |
4769 | (setq kwd (car kwds) | |
4770 | link (idlwave-split-link-target (nth 1 kwd)) | |
4771 | anchor (cdr link) | |
4772 | link (car link) | |
4773 | kwd (car kwd)) | |
4774 | (if (setq block (assoc link linkfiles)) | |
4775 | (push (cons kwd anchor) (cdr block)) | |
4776 | (push (list link (cons kwd anchor)) linkfiles)) | |
4777 | (setq kwds (cdr kwds))) | |
4778 | ;; Ensure the master link is there | |
4779 | (if (setq master-elt (assoc master-link linkfiles)) | |
4780 | (if (eq (car linkfiles) master-elt) | |
4781 | linkfiles | |
4782 | (cons master-elt (delq master-elt linkfiles))) | |
4783 | (push (list master-link) linkfiles)))) | |
4b1aaa8b | 4784 | |
f66f03de S |
4785 | (defun idlwave-convert-xml-clean-statement-aliases (aliases) |
4786 | ;; Clean up the syntax of routines which are actually aliases by | |
4787 | ;; removing the "OR" from the statements | |
4788 | (let (syntax entry) | |
4789 | (loop for x in aliases do | |
4790 | (setq entry (assoc x idlwave-system-routines)) | |
4791 | (when entry | |
4792 | (while (string-match " +or +" (setq syntax (nth 4 entry))) | |
4793 | (setf (nth 4 entry) (replace-match ", " t t syntax))))))) | |
4794 | ||
4795 | (defun idlwave-convert-xml-clean-routine-aliases (aliases) | |
4796 | ;; Duplicate and trim original routine aliases from rinfo list | |
4b1aaa8b | 4797 | ;; This if for, e.g. OPENR/OPENW/OPENU |
f66f03de S |
4798 | (let (alias remove-list new parts all-parts) |
4799 | (loop for x in aliases do | |
4800 | (when (setq parts (split-string (cdr x) "/")) | |
4801 | (setq new (assoc (cdr x) all-parts)) | |
4802 | (unless new | |
4803 | (setq new (cons (cdr x) parts)) | |
4804 | (push new all-parts)) | |
4805 | (setcdr new (delete (car x) (cdr new))))) | |
4b1aaa8b | 4806 | |
f66f03de S |
4807 | ;; Add any missing aliases (separate by slashes) |
4808 | (loop for x in all-parts do | |
4809 | (if (cdr x) | |
4810 | (push (cons (nth 1 x) (car x)) aliases))) | |
4811 | ||
4812 | (loop for x in aliases do | |
4813 | (when (setq alias (assoc (cdr x) idlwave-system-routines)) | |
4814 | (unless (memq alias remove-list) (push alias remove-list)) | |
4815 | (setq alias (copy-sequence alias)) | |
4816 | (setcar alias (car x)) | |
4817 | (push alias idlwave-system-routines))) | |
4818 | (loop for x in remove-list do | |
4819 | (delq x idlwave-system-routines)))) | |
4820 | ||
4821 | (defun idlwave-convert-xml-clean-sysvar-aliases (aliases) | |
4822 | ;; Duplicate and trim original routine aliases from rinfo list | |
4823 | ;; This if for, e.g. !X, !Y, !Z. | |
4824 | (let (alias remove-list new parts all-parts) | |
4825 | (loop for x in aliases do | |
4826 | (when (setq alias (assoc (cdr x) idlwave-system-variables-alist)) | |
4827 | (unless (memq alias remove-list) (push alias remove-list)) | |
4828 | (setq alias (copy-sequence alias)) | |
4829 | (setcar alias (car x)) | |
4830 | (push alias idlwave-system-variables-alist))) | |
4831 | (loop for x in remove-list do | |
4832 | (delq x idlwave-system-variables-alist)))) | |
4833 | ||
4834 | ||
4835 | (defun idlwave-xml-create-sysvar-alist (xml-entry) | |
4836 | ;; Create a sysvar list entry from the xml parsed list. | |
4837 | (let* ((nameblock (nth 1 xml-entry)) | |
a86bd650 | 4838 | (name (cdr (assq 'name nameblock))) |
b9e4fbd3 | 4839 | (sysvar (substring name (progn (string-match "^ *!" name) |
a86bd650 | 4840 | (match-end 0)))) |
f66f03de S |
4841 | (link (cdr (assq 'link nameblock))) |
4842 | (params (cddr xml-entry)) | |
4843 | (case-fold-search t) | |
4844 | pelem ptype props fields tags) | |
4845 | (while params | |
4846 | (setq pelem (car params)) | |
4847 | (when (listp pelem) | |
4848 | (setq ptype (car pelem) | |
4849 | props (car (cdr pelem))) | |
4850 | (cond | |
4851 | ((eq ptype 'FIELD) | |
4b1aaa8b | 4852 | (push (cons (cdr (assq 'name props)) |
f66f03de S |
4853 | (cdr |
4854 | (idlwave-split-link-target (cdr (assq 'link props))))) | |
4855 | tags)))) | |
4856 | (setq params (cdr params))) | |
4857 | (delq nil | |
4858 | (list sysvar (if tags (cons 'tags tags)) (list 'link link))))) | |
4859 | ||
4860 | ||
4861 | (defvar idlwave-xml-routine-info-file nil) | |
4862 | ||
4863 | (defun idlwave-save-routine-info () | |
4864 | (if idlwave-xml-routine-info-file | |
4865 | (with-temp-file idlwave-xml-system-rinfo-converted-file | |
4b1aaa8b | 4866 | (insert |
f66f03de | 4867 | (concat ";; *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* |
4b1aaa8b PE |
4868 | ;; IDLWAVE Routine Information File (IDLWAVE version " idlwave-mode-version ") |
4869 | ;; Automatically generated from source file: | |
f66f03de S |
4870 | ;; " idlwave-xml-routine-info-file " |
4871 | ;; on " (current-time-string) " | |
4872 | ;; Do not edit.")) | |
4873 | (insert (format "\n(setq idlwave-xml-routine-info-file \n \"%s\")" | |
4874 | idlwave-xml-routine-info-file)) | |
4875 | (insert "\n(setq idlwave-system-routines\n '") | |
4876 | (prin1 idlwave-system-routines (current-buffer)) | |
4877 | (insert ")") | |
4878 | (insert "\n(setq idlwave-system-variables-alist\n '") | |
4879 | (prin1 idlwave-system-variables-alist (current-buffer)) | |
4880 | (insert ")") | |
4881 | (insert "\n(setq idlwave-system-class-info\n '") | |
4882 | (prin1 idlwave-system-class-info (current-buffer)) | |
4883 | (insert ")") | |
4884 | (insert "\n(setq idlwave-executive-commands-alist\n '") | |
4885 | (prin1 idlwave-executive-commands-alist (current-buffer)) | |
4886 | (insert ")") | |
4887 | (insert "\n(setq idlwave-help-special-topic-words\n '") | |
4888 | (prin1 idlwave-help-special-topic-words (current-buffer)) | |
4889 | (insert ")")))) | |
4890 | ||
4891 | (defun idlwave-convert-xml-system-routine-info () | |
4892 | "Convert XML supplied IDL routine info into internal form. | |
4893 | Cache to disk for quick recovery." | |
4894 | (interactive) | |
4b1aaa8b | 4895 | (let* ((dir (file-name-as-directory |
f66f03de S |
4896 | (expand-file-name "help/online_help" (idlwave-sys-dir)))) |
4897 | (catalog-file (expand-file-name "idl_catalog.xml" dir)) | |
4898 | (elem-cnt 0) | |
4b1aaa8b | 4899 | props rinfo msg-cnt elem type nelem class-result alias |
f66f03de | 4900 | routines routine-aliases statement-aliases sysvar-aliases |
e08734e2 | 4901 | version-string) |
f66f03de S |
4902 | (if (not (file-exists-p catalog-file)) |
4903 | (error "No such XML routine info file: %s" catalog-file) | |
4904 | (if (not (file-readable-p catalog-file)) | |
4905 | (error "Cannot read XML routine info file: %s" catalog-file))) | |
4b1aaa8b | 4906 | (message "Reading XML routine info...") |
e08734e2 | 4907 | (setq rinfo (xml-parse-file catalog-file)) |
f66f03de S |
4908 | (message "Reading XML routine info...done") |
4909 | (setq rinfo (assq 'CATALOG rinfo)) | |
4910 | (unless rinfo (error "Failed to parse XML routine info")) | |
4911 | ;;(setq rinfo (car rinfo)) ; Skip the catalog stuff. | |
4b1aaa8b | 4912 | |
f66f03de S |
4913 | (setq version-string (cdr (assq 'version (nth 1 rinfo))) |
4914 | rinfo (cddr rinfo)) | |
4915 | ||
4916 | (setq nelem (length rinfo) | |
4917 | msg-cnt (/ nelem 20)) | |
4b1aaa8b | 4918 | |
f66f03de S |
4919 | (setq idlwave-xml-routine-info-file nil) |
4920 | (message "Converting XML routine info...") | |
4921 | (setq idlwave-system-routines nil | |
4922 | idlwave-system-variables-alist nil | |
4923 | idlwave-system-class-info nil | |
4924 | idlwave-executive-commands-alist nil | |
4925 | idlwave-help-special-topic-words nil) | |
4926 | ||
4927 | (while rinfo | |
4928 | (setq elem (car rinfo) | |
4929 | rinfo (cdr rinfo)) | |
4930 | (incf elem-cnt) | |
4931 | (when (listp elem) | |
4932 | (setq type (car elem) | |
4933 | props (car (cdr elem))) | |
4934 | (if (= (mod elem-cnt msg-cnt) 0) | |
4b1aaa8b | 4935 | (message "Converting XML routine info...%2d%%" |
f66f03de | 4936 | (/ (* elem-cnt 100) nelem))) |
4b1aaa8b | 4937 | (cond |
f66f03de S |
4938 | ((eq type 'ROUTINE) |
4939 | (if (setq alias (assq 'alias_to props)) | |
4b1aaa8b | 4940 | (push (cons (cdr (assq 'name props)) (cdr alias)) |
f66f03de S |
4941 | routine-aliases) |
4942 | (setq routines (idlwave-xml-create-rinfo-list elem)) | |
4943 | (if (listp (cdr routines)) | |
4944 | (setq idlwave-system-routines | |
4945 | (nconc idlwave-system-routines routines)) | |
4946 | ;; a cons cell is an executive commands | |
4947 | (push routines idlwave-executive-commands-alist)))) | |
4b1aaa8b | 4948 | |
f66f03de S |
4949 | ((eq type 'CLASS) |
4950 | (setq class-result (idlwave-xml-create-class-method-lists elem)) | |
4951 | (push (car class-result) idlwave-system-class-info) | |
4952 | (setq idlwave-system-routines | |
4953 | (nconc idlwave-system-routines (cdr class-result)))) | |
4954 | ||
4955 | ((eq type 'STATEMENT) | |
4956 | (push (cons (cdr (assq 'name props)) | |
4957 | (cdr (assq 'link props))) | |
4958 | idlwave-help-special-topic-words) | |
4959 | ;; Save the links to those which are statement aliases (not routines) | |
4960 | (if (setq alias (assq 'alias_to props)) | |
4961 | (unless (member (cdr alias) statement-aliases) | |
4962 | (push (cdr alias) statement-aliases)))) | |
4963 | ||
4964 | ((eq type 'SYSVAR) | |
4965 | (if (setq alias (cdr (assq 'alias_to props))) | |
4b1aaa8b | 4966 | (push (cons (substring (cdr (assq 'name props)) 1) |
f66f03de S |
4967 | (substring alias 1)) |
4968 | sysvar-aliases) | |
4b1aaa8b | 4969 | (push (idlwave-xml-create-sysvar-alist elem) |
f66f03de S |
4970 | idlwave-system-variables-alist))) |
4971 | (t)))) | |
4972 | (idlwave-convert-xml-clean-routine-aliases routine-aliases) | |
4973 | (idlwave-convert-xml-clean-statement-aliases statement-aliases) | |
4974 | (idlwave-convert-xml-clean-sysvar-aliases sysvar-aliases) | |
4975 | ||
4976 | (setq idlwave-xml-routine-info-file catalog-file) | |
4977 | (idlwave-save-routine-info) | |
4978 | (message "Converting XML routine info...done"))) | |
4b1aaa8b PE |
4979 | |
4980 | ||
f66f03de S |
4981 | ;; ("ROUTINE" type class |
4982 | ;; (system) | (lib pro_file dir "LIBNAME") | (user pro_file dir "USERLIB") | | |
4983 | ;; (buffer pro_file dir) | (compiled pro_file dir) | |
4b1aaa8b | 4984 | ;; "calling_string" ("HELPFILE" (("KWD1" . link1) ...)) |
f66f03de S |
4985 | ;; ("HELPFILE2" (("KWD2" . link) ...)) ...) |
4986 | ||
4987 | ||
5e72c6b2 S |
4988 | (defun idlwave-load-rinfo-next-step () |
4989 | (let ((inhibit-quit t) | |
4990 | (arr idlwave-load-rinfo-steps-done)) | |
f66f03de | 4991 | (if (catch 'exit |
5e72c6b2 | 4992 | (when (not (aref arr 0)) |
f66f03de S |
4993 | (message "Loading system routine info in idle time...") |
4994 | (idlwave-load-system-routine-info) | |
4995 | ;;(load "idlw-rinfo" 'noerror 'nomessage) | |
4996 | (message "Loading system routine info in idle time...done") | |
5e72c6b2 S |
4997 | (aset arr 0 t) |
4998 | (throw 'exit t)) | |
4b1aaa8b | 4999 | |
5e72c6b2 S |
5000 | (when (not (aref arr 1)) |
5001 | (message "Normalizing idlwave-system-routines in idle time...") | |
5002 | (idlwave-reset-sintern t) | |
5003 | (put 'idlwave-reset-sintern 'done-by-idle t) | |
5004 | (setq idlwave-system-routines | |
5005 | (idlwave-sintern-rinfo-list idlwave-system-routines 'sys)) | |
5006 | (message "Normalizing idlwave-system-routines in idle time...done") | |
5007 | (aset arr 1 t) | |
5008 | (throw 'exit t)) | |
f66f03de | 5009 | |
5e72c6b2 | 5010 | (when (not (aref arr 2)) |
52a244eb S |
5011 | (when (and (stringp idlwave-user-catalog-file) |
5012 | (file-regular-p idlwave-user-catalog-file)) | |
5013 | (message "Loading user catalog in idle time...") | |
5e72c6b2 | 5014 | (condition-case nil |
52a244eb S |
5015 | (load-file idlwave-user-catalog-file) |
5016 | (error (throw 'exit nil))) | |
5017 | ;; Check for the old style catalog and warn | |
5018 | (if (and | |
5019 | (boundp 'idlwave-library-routines) | |
5020 | idlwave-library-routines) | |
775591f7 | 5021 | (progn |
52a244eb S |
5022 | (setq idlwave-library-routines nil) |
5023 | (ding) | |
4b1aaa8b | 5024 | (message "Outdated user catalog: %s... recreate" |
52a244eb | 5025 | idlwave-user-catalog-file)) |
f66f03de S |
5026 | (message "Loading user catalog in idle time...done"))) |
5027 | (aset arr 2 t) | |
5028 | (throw 'exit t)) | |
5029 | ||
5e72c6b2 | 5030 | (when (not (aref arr 3)) |
52a244eb S |
5031 | (when idlwave-user-catalog-routines |
5032 | (message "Normalizing user catalog routines in idle time...") | |
4b1aaa8b | 5033 | (setq idlwave-user-catalog-routines |
52a244eb S |
5034 | (idlwave-sintern-rinfo-list |
5035 | idlwave-user-catalog-routines 'sys)) | |
4b1aaa8b | 5036 | (message |
52a244eb | 5037 | "Normalizing user catalog routines in idle time...done")) |
5e72c6b2 S |
5038 | (aset arr 3 t) |
5039 | (throw 'exit t)) | |
f66f03de | 5040 | |
5e72c6b2 | 5041 | (when (not (aref arr 4)) |
4b1aaa8b | 5042 | (idlwave-scan-library-catalogs |
52a244eb S |
5043 | "Loading and normalizing library catalogs in idle time...") |
5044 | (aset arr 4 t) | |
5045 | (throw 'exit t)) | |
5046 | (when (not (aref arr 5)) | |
5e72c6b2 S |
5047 | (message "Finishing initialization in idle time...") |
5048 | (idlwave-routines) | |
5049 | (message "Finishing initialization in idle time...done") | |
4b1aaa8b | 5050 | (aset arr 5 t) |
5e72c6b2 | 5051 | (throw 'exit nil))) |
52a244eb S |
5052 | ;; restart the timer |
5053 | (if (sit-for 1) | |
5054 | (idlwave-load-rinfo-next-step) | |
5055 | (setq idlwave-load-rinfo-idle-timer | |
5056 | (run-with-idle-timer | |
5057 | idlwave-init-rinfo-when-idle-after | |
5058 | nil 'idlwave-load-rinfo-next-step)))))) | |
5e72c6b2 | 5059 | |
f66f03de S |
5060 | (defun idlwave-load-all-rinfo (&optional force) |
5061 | ;; Load and case-treat the system, user catalog, and library routine | |
5062 | ;; info files. | |
5063 | ||
5064 | ;; System | |
5e72c6b2 | 5065 | (when (or force (not (aref idlwave-load-rinfo-steps-done 0))) |
f66f03de S |
5066 | ;;(load "idlw-rinfo" 'noerror 'nomessage)) |
5067 | (idlwave-load-system-routine-info)) | |
5e72c6b2 S |
5068 | (when (or force (not (aref idlwave-load-rinfo-steps-done 1))) |
5069 | (message "Normalizing idlwave-system-routines...") | |
5070 | (setq idlwave-system-routines | |
5071 | (idlwave-sintern-rinfo-list idlwave-system-routines 'sys)) | |
5072 | (message "Normalizing idlwave-system-routines...done")) | |
f66f03de S |
5073 | (when idlwave-system-routines |
5074 | (setq idlwave-routines (copy-sequence idlwave-system-routines)) | |
5075 | (setq idlwave-last-system-routine-info-cons-cell | |
5076 | (nthcdr (1- (length idlwave-routines)) idlwave-routines))) | |
5077 | ||
5078 | ;; User catalog | |
52a244eb S |
5079 | (when (and (stringp idlwave-user-catalog-file) |
5080 | (file-regular-p idlwave-user-catalog-file)) | |
f32b3b91 | 5081 | (condition-case nil |
52a244eb S |
5082 | (when (or force (not (aref idlwave-load-rinfo-steps-done 2))) |
5083 | (load-file idlwave-user-catalog-file)) | |
5084 | (error nil)) | |
4b1aaa8b | 5085 | (when (and |
f66f03de S |
5086 | (boundp 'idlwave-library-routines) |
5087 | idlwave-library-routines) | |
52a244eb | 5088 | (setq idlwave-library-routines nil) |
4b1aaa8b | 5089 | (error "Outdated user catalog: %s... recreate" |
f66f03de | 5090 | idlwave-user-catalog-file)) |
52a244eb S |
5091 | (setq idlwave-true-path-alist nil) |
5092 | (when (or force (not (aref idlwave-load-rinfo-steps-done 3))) | |
5093 | (message "Normalizing user catalog routines...") | |
4b1aaa8b PE |
5094 | (setq idlwave-user-catalog-routines |
5095 | (idlwave-sintern-rinfo-list | |
52a244eb S |
5096 | idlwave-user-catalog-routines 'sys)) |
5097 | (message "Normalizing user catalog routines...done"))) | |
f66f03de S |
5098 | |
5099 | ;; Library catalog | |
52a244eb S |
5100 | (when (or force (not (aref idlwave-load-rinfo-steps-done 4))) |
5101 | (idlwave-scan-library-catalogs | |
5102 | "Loading and normalizing library catalogs...")) | |
05a1abfc CD |
5103 | (run-hooks 'idlwave-after-load-rinfo-hook)) |
5104 | ||
f32b3b91 CD |
5105 | |
5106 | (defun idlwave-update-buffer-routine-info () | |
5107 | (let (res) | |
4b1aaa8b | 5108 | (cond |
15e42531 CD |
5109 | ((eq idlwave-scan-all-buffers-for-routine-info t) |
5110 | ;; Scan all buffers, current buffer last | |
5111 | (message "Scanning all buffers...") | |
4b1aaa8b | 5112 | (setq res (idlwave-get-routine-info-from-buffers |
15e42531 CD |
5113 | (reverse (buffer-list))))) |
5114 | ((null idlwave-scan-all-buffers-for-routine-info) | |
5115 | ;; Don't scan any buffers | |
5116 | (setq res nil)) | |
5117 | (t | |
f32b3b91 CD |
5118 | ;; Just scan this buffer |
5119 | (if (eq major-mode 'idlwave-mode) | |
5120 | (progn | |
5121 | (message "Scanning current buffer...") | |
5122 | (setq res (idlwave-get-routine-info-from-buffers | |
15e42531 | 5123 | (list (current-buffer)))))))) |
f32b3b91 | 5124 | ;; Put the result into the correct variable |
4b1aaa8b | 5125 | (setq idlwave-buffer-routines |
52a244eb | 5126 | (idlwave-sintern-rinfo-list res 'set)))) |
f32b3b91 | 5127 | |
05a1abfc | 5128 | (defun idlwave-concatenate-rinfo-lists (&optional quiet run-hook) |
f32b3b91 | 5129 | "Put the different sources for routine information together." |
4b1aaa8b | 5130 | ;; The sequence here is important because earlier definitions shadow |
f32b3b91 | 5131 | ;; later ones. We assume that if things in the buffers are newer |
52a244eb | 5132 | ;; then in the shell of the system, they are meant to be different. |
15e42531 CD |
5133 | (setcdr idlwave-last-system-routine-info-cons-cell |
5134 | (append idlwave-buffer-routines | |
5135 | idlwave-compiled-routines | |
52a244eb S |
5136 | idlwave-library-catalog-routines |
5137 | idlwave-user-catalog-routines)) | |
f32b3b91 | 5138 | (setq idlwave-class-alist nil) |
15e42531 | 5139 | |
f32b3b91 | 5140 | ;; Give a message with information about the number of routines we have. |
15e42531 | 5141 | (unless quiet |
4b1aaa8b | 5142 | (message |
52a244eb | 5143 | "Routines Found: buffer(%d) compiled(%d) library(%d) user(%d) system(%d)" |
15e42531 CD |
5144 | (length idlwave-buffer-routines) |
5145 | (length idlwave-compiled-routines) | |
52a244eb S |
5146 | (length idlwave-library-catalog-routines) |
5147 | (length idlwave-user-catalog-routines) | |
05a1abfc CD |
5148 | (length idlwave-system-routines))) |
5149 | (if run-hook | |
5150 | (run-hooks 'idlwave-update-rinfo-hook))) | |
15e42531 CD |
5151 | |
5152 | (defun idlwave-class-alist () | |
5153 | "Return the class alist - make it if necessary." | |
5154 | (or idlwave-class-alist | |
5155 | (let (class) | |
5156 | (loop for x in idlwave-routines do | |
5157 | (when (and (setq class (nth 2 x)) | |
5158 | (not (assq class idlwave-class-alist))) | |
5159 | (push (list class) idlwave-class-alist))) | |
4b1aaa8b | 5160 | idlwave-class-alist))) |
15e42531 CD |
5161 | |
5162 | ;; Three functions for the hooks | |
5163 | (defun idlwave-save-buffer-update () | |
5164 | (idlwave-update-current-buffer-info 'save-buffer)) | |
5165 | (defun idlwave-kill-buffer-update () | |
5166 | (idlwave-update-current-buffer-info 'kill-buffer)) | |
5167 | (defun idlwave-new-buffer-update () | |
5168 | (idlwave-update-current-buffer-info 'find-file)) | |
5169 | ||
5170 | (defun idlwave-update-current-buffer-info (why) | |
52a244eb | 5171 | "Update idlwave-routines for current buffer. Can run from after-save-hook." |
15e42531 CD |
5172 | (when (and (eq major-mode 'idlwave-mode) |
5173 | (or (eq t idlwave-auto-routine-info-updates) | |
5174 | (memq why idlwave-auto-routine-info-updates)) | |
5175 | idlwave-scan-all-buffers-for-routine-info | |
5176 | idlwave-routines) | |
5177 | (condition-case nil | |
5178 | (let (routines) | |
5179 | (idlwave-replace-buffer-routine-info | |
5180 | (buffer-file-name) | |
5181 | (if (eq why 'kill-buffer) | |
5182 | nil | |
5183 | (setq routines | |
5184 | (idlwave-sintern-rinfo-list | |
5185 | (idlwave-get-routine-info-from-buffers | |
5186 | (list (current-buffer))) 'set)))) | |
5187 | (idlwave-concatenate-rinfo-lists 'quiet) | |
5188 | routines) | |
5189 | (error nil)))) | |
5190 | ||
5191 | (defun idlwave-replace-buffer-routine-info (file new) | |
5192 | "Cut the part from FILE out of `idlwave-buffer-routines' and add NEW." | |
4b1aaa8b | 5193 | (let ((list idlwave-buffer-routines) |
15e42531 CD |
5194 | found) |
5195 | (while list | |
5196 | ;; The following test uses eq to make sure it works correctly | |
5197 | ;; when two buffers visit the same file. Then the file names | |
5198 | ;; will be equal, but not eq. | |
52a244eb | 5199 | (if (eq (idlwave-routine-source-file (nth 3 (car list))) file) |
15e42531 CD |
5200 | (progn |
5201 | (setcar list nil) | |
5202 | (setq found t)) | |
5203 | (if found | |
4b1aaa8b | 5204 | ;; End of that section reached. Jump. |
15e42531 CD |
5205 | (setq list nil))) |
5206 | (setq list (cdr list))) | |
5207 | (setq idlwave-buffer-routines | |
5208 | (append new (delq nil idlwave-buffer-routines))))) | |
f32b3b91 CD |
5209 | |
5210 | ;;----- Scanning buffers ------------------- | |
5211 | ||
5212 | (defun idlwave-get-routine-info-from-buffers (buffers) | |
5213 | "Call `idlwave-get-buffer-routine-info' on idlwave-mode buffers in BUFFERS." | |
5214 | (let (buf routine-lists res) | |
5215 | (save-excursion | |
5216 | (while (setq buf (pop buffers)) | |
5217 | (set-buffer buf) | |
05a1abfc CD |
5218 | (if (and (eq major-mode 'idlwave-mode) |
5219 | buffer-file-name) | |
f32b3b91 CD |
5220 | ;; yes, this buffer has the right mode. |
5221 | (progn (setq res (condition-case nil | |
5222 | (idlwave-get-buffer-routine-info) | |
5223 | (error nil))) | |
5224 | (push res routine-lists))))) | |
5225 | ;; Concatenate the individual lists and return the result | |
5226 | (apply 'nconc routine-lists))) | |
5227 | ||
5228 | (defun idlwave-get-buffer-routine-info () | |
5229 | "Scan the current buffer for routine info. Return (PRO-LIST FUNC-LIST)." | |
5230 | (let* ((case-fold-search t) | |
5231 | routine-list string entry) | |
5232 | (save-excursion | |
5233 | (save-restriction | |
5234 | (widen) | |
5235 | (goto-char (point-min)) | |
4b1aaa8b | 5236 | (while (re-search-forward |
15e42531 | 5237 | "^[ \t]*\\(pro\\|function\\)[ \t]" nil t) |
76959b77 | 5238 | (setq string (buffer-substring-no-properties |
f32b3b91 | 5239 | (match-beginning 0) |
4b1aaa8b | 5240 | (progn |
f32b3b91 CD |
5241 | (idlwave-end-of-statement) |
5242 | (point)))) | |
5243 | (setq entry (idlwave-parse-definition string)) | |
5244 | (push entry routine-list)))) | |
5245 | routine-list)) | |
5246 | ||
15e42531 | 5247 | (defvar idlwave-scanning-lib-dir) |
f32b3b91 CD |
5248 | (defun idlwave-parse-definition (string) |
5249 | "Parse a module definition." | |
5250 | (let ((case-fold-search t) | |
5251 | start name args type keywords class) | |
5252 | ;; Remove comments | |
5253 | (while (string-match ";.*" string) | |
5254 | (setq string (replace-match "" t t string))) | |
5255 | ;; Remove the continuation line stuff | |
5256 | (while (string-match "\\([^a-zA-Z0-9$_]\\)\\$[ \t]*\n" string) | |
5257 | (setq string (replace-match "\\1 " t nil string))) | |
05a1abfc CD |
5258 | (while (string-match "\n" string) |
5259 | (setq string (replace-match " " t nil string))) | |
f32b3b91 CD |
5260 | ;; Match the name and type. |
5261 | (when (string-match | |
5262 | "\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)" string) | |
5263 | (setq start (match-end 0)) | |
5264 | (setq type (downcase (match-string 1 string))) | |
5265 | (if (match-beginning 3) | |
5266 | (setq class (match-string 3 string))) | |
5267 | (setq name (match-string 4 string))) | |
5268 | ;; Match normal args and keyword args | |
5269 | (while (string-match | |
15e42531 | 5270 | ",\\s-*\\([a-zA-Z][a-zA-Z0-9$_]*\\|\\(_ref\\)?_extra\\)\\s-*\\(=\\)?" |
f32b3b91 CD |
5271 | string start) |
5272 | (setq start (match-end 0)) | |
15e42531 | 5273 | (if (match-beginning 3) |
f32b3b91 CD |
5274 | (push (match-string 1 string) keywords) |
5275 | (push (match-string 1 string) args))) | |
5276 | ;; Normalize and sort. | |
5277 | (setq args (nreverse args)) | |
4b1aaa8b | 5278 | (setq keywords (sort keywords (lambda (a b) |
f32b3b91 CD |
5279 | (string< (downcase a) (downcase b))))) |
5280 | ;; Make and return the entry | |
5281 | ;; We don't know which argument are optional, so this information | |
5282 | ;; will not be contained in the calling sequence. | |
5283 | (list name | |
5284 | (if (equal type "pro") 'pro 'fun) | |
5285 | class | |
5286 | (cond ((not (boundp 'idlwave-scanning-lib)) | |
52a244eb | 5287 | (list 'buffer (buffer-file-name))) |
4b1aaa8b | 5288 | ; ((string= (downcase |
15e42531 CD |
5289 | ; (file-name-sans-extension |
5290 | ; (file-name-nondirectory (buffer-file-name)))) | |
5291 | ; (downcase name)) | |
5292 | ; (list 'lib)) | |
5293 | ; (t (cons 'lib (file-name-nondirectory (buffer-file-name)))) | |
52a244eb S |
5294 | (t (list 'user (file-name-nondirectory (buffer-file-name)) |
5295 | idlwave-scanning-lib-dir "UserLib"))) | |
4b1aaa8b | 5296 | (concat |
f32b3b91 CD |
5297 | (if (string= type "function") "Result = " "") |
5298 | (if class "Obj ->[%s::]" "") | |
5299 | "%s" | |
5300 | (if args | |
5301 | (concat | |
5302 | (if (string= type "function") "(" ", ") | |
5303 | (mapconcat 'identity args ", ") | |
5304 | (if (string= type "function") ")" "")))) | |
5305 | (if keywords | |
52a244eb | 5306 | (cons nil (mapcar 'list keywords)) ;No help file |
f32b3b91 CD |
5307 | nil)))) |
5308 | ||
f32b3b91 | 5309 | |
52a244eb | 5310 | ;;----- Scanning the user catalog ------------------- |
15e42531 CD |
5311 | |
5312 | (defun idlwave-sys-dir () | |
5313 | "Return the syslib directory, or a dummy that never matches." | |
3938cb82 S |
5314 | (cond |
5315 | ((and idlwave-system-directory | |
5316 | (not (string= idlwave-system-directory ""))) | |
5317 | idlwave-system-directory) | |
5318 | ((getenv "IDL_DIR")) | |
5319 | (t "@@@@@@@@"))) | |
5320 | ||
52a244eb | 5321 | |
52a244eb | 5322 | (defun idlwave-create-user-catalog-file (&optional arg) |
f32b3b91 | 5323 | "Scan all files on selected dirs of IDL search path for routine information. |
52a244eb S |
5324 | |
5325 | A widget checklist will allow you to choose the directories. Write | |
5326 | the result as a file `idlwave-user-catalog-file'. When this file | |
5327 | exists, will be automatically loaded to give routine information about | |
5328 | library routines. With ARG, just rescan the same directories as last | |
5329 | time - so no widget will pop up." | |
f32b3b91 CD |
5330 | (interactive "P") |
5331 | ;; Make sure the file is loaded if it exists. | |
52a244eb S |
5332 | (if (and (stringp idlwave-user-catalog-file) |
5333 | (file-regular-p idlwave-user-catalog-file)) | |
f32b3b91 | 5334 | (condition-case nil |
52a244eb | 5335 | (load-file idlwave-user-catalog-file) |
f32b3b91 CD |
5336 | (error nil))) |
5337 | ;; Make sure the file name makes sense | |
52a244eb S |
5338 | (unless (and (stringp idlwave-user-catalog-file) |
5339 | (> (length idlwave-user-catalog-file) 0) | |
f32b3b91 | 5340 | (file-accessible-directory-p |
52a244eb | 5341 | (file-name-directory idlwave-user-catalog-file)) |
4b1aaa8b | 5342 | (not (string= "" (file-name-nondirectory |
52a244eb S |
5343 | idlwave-user-catalog-file)))) |
5344 | (error "`idlwave-user-catalog-file' does not point to a file in an accessible directory")) | |
4b1aaa8b | 5345 | |
f32b3b91 | 5346 | (cond |
f32b3b91 | 5347 | ;; Rescan the known directories |
52a244eb S |
5348 | ((and arg idlwave-path-alist |
5349 | (consp (car idlwave-path-alist))) | |
5350 | (idlwave-scan-user-lib-files idlwave-path-alist)) | |
5351 | ||
5352 | ;; Expand the directories from library-path and run the widget | |
f32b3b91 | 5353 | (idlwave-library-path |
52a244eb | 5354 | (idlwave-display-user-catalog-widget |
4b1aaa8b | 5355 | (if idlwave-true-path-alist |
52a244eb S |
5356 | ;; Propagate any flags on the existing path-alist |
5357 | (mapcar (lambda (x) | |
5358 | (let ((path-entry (assoc (file-truename x) | |
5359 | idlwave-true-path-alist))) | |
5360 | (if path-entry | |
4b1aaa8b | 5361 | (cons x (cdr path-entry)) |
52a244eb S |
5362 | (list x)))) |
5363 | (idlwave-expand-path idlwave-library-path)) | |
5364 | (mapcar 'list (idlwave-expand-path idlwave-library-path))))) | |
5365 | ||
5366 | ;; Ask the shell for the path and then run the widget | |
f32b3b91 | 5367 | (t |
f32b3b91 | 5368 | (message "Asking the shell for IDL path...") |
15e42531 CD |
5369 | (require 'idlw-shell) |
5370 | (idlwave-shell-send-command idlwave-shell-path-query | |
52a244eb | 5371 | '(idlwave-user-catalog-command-hook nil) |
15e42531 | 5372 | 'hide)))) |
f32b3b91 | 5373 | |
52a244eb S |
5374 | |
5375 | ;; Parse shell path information and select among it. | |
5376 | (defun idlwave-user-catalog-command-hook (&optional arg) | |
5377 | ;; Command hook used by `idlwave-create-user-catalog-file'. | |
f32b3b91 CD |
5378 | (if arg |
5379 | ;; Scan immediately | |
52a244eb S |
5380 | (idlwave-scan-user-lib-files idlwave-path-alist) |
5381 | ;; Set the path and display the widget | |
5382 | (idlwave-shell-get-path-info 'no-write) ; set to something path-alist | |
5383 | (idlwave-scan-library-catalogs "Locating library catalogs..." 'no-load) | |
5384 | (idlwave-display-user-catalog-widget idlwave-path-alist))) | |
5385 | ||
4b1aaa8b | 5386 | (defconst idlwave-user-catalog-widget-help-string |
52a244eb S |
5387 | "This is the front-end to the creation of the IDLWAVE user catalog. |
5388 | Please select the directories on IDL's search path from which you | |
5389 | would like to extract routine information, to be stored in the file: | |
f32b3b91 CD |
5390 | |
5391 | %s | |
5392 | ||
52a244eb S |
5393 | If this is not the correct file, first set variable |
5394 | `idlwave-user-catalog-file', and call this command again. | |
15e42531 | 5395 | |
52a244eb S |
5396 | N.B. Many libraries include pre-scanned catalog files |
5397 | \(\".idlwave_catalog\"). These are marked with \"[LIB]\", and need | |
5398 | not be scanned. You can scan your own libraries off-line using the | |
5399 | perl script `idlwave_catalog'. | |
15e42531 | 5400 | |
f32b3b91 CD |
5401 | After selecting the directories, choose [Scan & Save] to scan the library |
5402 | directories and save the routine info. | |
5403 | \n") | |
5404 | ||
5405 | (defvar idlwave-widget) | |
5406 | (defvar widget-keymap) | |
52a244eb | 5407 | (defun idlwave-display-user-catalog-widget (dirs-list) |
f32b3b91 CD |
5408 | "Create the widget to select IDL search path directories for scanning." |
5409 | (interactive) | |
5410 | (require 'widget) | |
5411 | (require 'wid-edit) | |
52a244eb | 5412 | (unless dirs-list |
f32b3b91 CD |
5413 | (error "Don't know IDL's search path")) |
5414 | ||
f32b3b91 CD |
5415 | (kill-buffer (get-buffer-create "*IDLWAVE Widget*")) |
5416 | (switch-to-buffer (get-buffer-create "*IDLWAVE Widget*")) | |
5417 | (kill-all-local-variables) | |
5418 | (make-local-variable 'idlwave-widget) | |
52a244eb S |
5419 | (widget-insert (format idlwave-user-catalog-widget-help-string |
5420 | idlwave-user-catalog-file)) | |
4b1aaa8b | 5421 | |
f32b3b91 | 5422 | (widget-create 'push-button |
52a244eb | 5423 | :notify 'idlwave-widget-scan-user-lib-files |
f32b3b91 CD |
5424 | "Scan & Save") |
5425 | (widget-insert " ") | |
5426 | (widget-create 'push-button | |
52a244eb | 5427 | :notify 'idlwave-delete-user-catalog-file |
f32b3b91 CD |
5428 | "Delete File") |
5429 | (widget-insert " ") | |
5430 | (widget-create 'push-button | |
4b1aaa8b | 5431 | :notify |
52a244eb S |
5432 | '(lambda (&rest ignore) |
5433 | (let ((path-list (widget-get idlwave-widget :path-dirs))) | |
5434 | (mapcar (lambda (x) | |
5435 | (unless (memq 'lib (cdr x)) | |
5436 | (idlwave-path-alist-add-flag x 'user))) | |
5437 | path-list) | |
5438 | (idlwave-display-user-catalog-widget path-list))) | |
5439 | "Select All Non-Lib") | |
f32b3b91 CD |
5440 | (widget-insert " ") |
5441 | (widget-create 'push-button | |
4b1aaa8b | 5442 | :notify |
52a244eb S |
5443 | '(lambda (&rest ignore) |
5444 | (let ((path-list (widget-get idlwave-widget :path-dirs))) | |
5445 | (mapcar (lambda (x) | |
5446 | (idlwave-path-alist-remove-flag x 'user)) | |
5447 | path-list) | |
5448 | (idlwave-display-user-catalog-widget path-list))) | |
f32b3b91 | 5449 | "Deselect All") |
52a244eb S |
5450 | (widget-insert " ") |
5451 | (widget-create 'push-button | |
5452 | :notify (lambda (&rest ignore) | |
5453 | (kill-buffer (current-buffer))) | |
5454 | "Quit") | |
f32b3b91 CD |
5455 | (widget-insert "\n\n") |
5456 | ||
52a244eb | 5457 | (widget-insert "Select Directories: \n") |
4b1aaa8b | 5458 | |
f32b3b91 CD |
5459 | (setq idlwave-widget |
5460 | (apply 'widget-create | |
5461 | 'checklist | |
4b1aaa8b PE |
5462 | :value (delq nil (mapcar (lambda (x) |
5463 | (if (memq 'user (cdr x)) | |
52a244eb S |
5464 | (car x))) |
5465 | dirs-list)) | |
f32b3b91 CD |
5466 | :greedy t |
5467 | :tag "List of directories" | |
4b1aaa8b PE |
5468 | (mapcar (lambda (x) |
5469 | (list 'item | |
52a244eb S |
5470 | (if (memq 'lib (cdr x)) |
5471 | (concat "[LIB] " (car x) ) | |
5472 | (car x)))) dirs-list))) | |
5473 | (widget-put idlwave-widget :path-dirs dirs-list) | |
f32b3b91 CD |
5474 | (widget-insert "\n") |
5475 | (use-local-map widget-keymap) | |
5476 | (widget-setup) | |
5477 | (goto-char (point-min)) | |
5478 | (delete-other-windows)) | |
4b1aaa8b | 5479 | |
52a244eb | 5480 | (defun idlwave-delete-user-catalog-file (&rest ignore) |
f32b3b91 | 5481 | (if (yes-or-no-p |
52a244eb | 5482 | (format "Delete file %s " idlwave-user-catalog-file)) |
f32b3b91 | 5483 | (progn |
52a244eb S |
5484 | (delete-file idlwave-user-catalog-file) |
5485 | (message "%s has been deleted" idlwave-user-catalog-file)))) | |
f32b3b91 | 5486 | |
52a244eb S |
5487 | (defun idlwave-widget-scan-user-lib-files (&rest ignore) |
5488 | ;; Call `idlwave-scan-user-lib-files' with data taken from the widget. | |
f32b3b91 | 5489 | (let* ((widget idlwave-widget) |
15e42531 | 5490 | (selected-dirs (widget-value widget)) |
52a244eb S |
5491 | (path-alist (widget-get widget :path-dirs)) |
5492 | (this-path-alist path-alist) | |
5493 | dir-entry) | |
5494 | (while (setq dir-entry (pop this-path-alist)) | |
4b1aaa8b | 5495 | (if (member |
52a244eb S |
5496 | (if (memq 'lib (cdr dir-entry)) |
5497 | (concat "[LIB] " (car dir-entry)) | |
5498 | (car dir-entry)) | |
5499 | selected-dirs) | |
5500 | (idlwave-path-alist-add-flag dir-entry 'user) | |
5501 | (idlwave-path-alist-remove-flag dir-entry 'user))) | |
5502 | (idlwave-scan-user-lib-files path-alist))) | |
f32b3b91 CD |
5503 | |
5504 | (defvar font-lock-mode) | |
52a244eb S |
5505 | (defun idlwave-scan-user-lib-files (path-alist) |
5506 | ;; Scan the PRO files in PATH-ALIST and store the info in the user catalog | |
f32b3b91 | 5507 | (let* ((idlwave-scanning-lib t) |
15e42531 | 5508 | (idlwave-scanning-lib-dir "") |
f32b3b91 | 5509 | (idlwave-completion-case nil) |
15e42531 | 5510 | dirs-alist dir files file) |
52a244eb S |
5511 | (setq idlwave-user-catalog-routines nil |
5512 | idlwave-path-alist path-alist ; for library-path instead | |
5513 | idlwave-true-path-alist nil) | |
5514 | (if idlwave-auto-write-paths (idlwave-write-paths)) | |
f32b3b91 CD |
5515 | (save-excursion |
5516 | (set-buffer (get-buffer-create "*idlwave-scan.pro*")) | |
5517 | (idlwave-mode) | |
15e42531 CD |
5518 | (setq dirs-alist (reverse path-alist)) |
5519 | (while (setq dir (pop dirs-alist)) | |
52a244eb | 5520 | (when (memq 'user (cdr dir)) ; Has it marked for scan? |
15e42531 | 5521 | (setq dir (car dir)) |
52a244eb | 5522 | (setq idlwave-scanning-lib-dir dir) |
15e42531 CD |
5523 | (when (file-directory-p dir) |
5524 | (setq files (directory-files dir 'full "\\.[pP][rR][oO]\\'")) | |
5525 | (while (setq file (pop files)) | |
5526 | (when (file-regular-p file) | |
5527 | (if (not (file-readable-p file)) | |
5528 | (message "Skipping %s (no read permission)" file) | |
5529 | (message "Scanning %s..." file) | |
5530 | (erase-buffer) | |
5531 | (insert-file-contents file 'visit) | |
52a244eb | 5532 | (setq idlwave-user-catalog-routines |
15e42531 CD |
5533 | (append (idlwave-get-routine-info-from-buffers |
5534 | (list (current-buffer))) | |
52a244eb S |
5535 | idlwave-user-catalog-routines))))))))) |
5536 | (message "Creating user catalog file...") | |
f32b3b91 CD |
5537 | (kill-buffer "*idlwave-scan.pro*") |
5538 | (kill-buffer (get-buffer-create "*IDLWAVE Widget*")) | |
15e42531 CD |
5539 | (let ((font-lock-maximum-size 0) |
5540 | (auto-mode-alist nil)) | |
52a244eb | 5541 | (find-file idlwave-user-catalog-file)) |
f32b3b91 CD |
5542 | (if (and (boundp 'font-lock-mode) |
5543 | font-lock-mode) | |
5544 | (font-lock-mode 0)) | |
5545 | (erase-buffer) | |
52a244eb | 5546 | (insert ";; IDLWAVE user catalog file\n") |
f32b3b91 CD |
5547 | (insert (format ";; Created %s\n\n" (current-time-string))) |
5548 | ||
f32b3b91 | 5549 | ;; Define the routine info list |
52a244eb | 5550 | (insert "\n(setq idlwave-user-catalog-routines\n '(") |
5e72c6b2 | 5551 | (let ((standard-output (current-buffer))) |
8ffcfb27 GM |
5552 | (mapc (lambda (x) |
5553 | (insert "\n ") | |
5554 | (prin1 x) | |
5555 | (goto-char (point-max))) | |
5556 | idlwave-user-catalog-routines)) | |
f32b3b91 | 5557 | (insert (format "))\n\n;;; %s ends here\n" |
52a244eb | 5558 | (file-name-nondirectory idlwave-user-catalog-file))) |
f32b3b91 CD |
5559 | (goto-char (point-min)) |
5560 | ;; Save the buffer | |
5561 | (save-buffer 0) | |
5562 | (kill-buffer (current-buffer))) | |
52a244eb | 5563 | (message "Creating user catalog file...done") |
f32b3b91 | 5564 | (message "Info for %d routines saved in %s" |
52a244eb S |
5565 | (length idlwave-user-catalog-routines) |
5566 | idlwave-user-catalog-file) | |
f32b3b91 CD |
5567 | (sit-for 2) |
5568 | (idlwave-update-routine-info t)) | |
5569 | ||
52a244eb S |
5570 | (defun idlwave-read-paths () |
5571 | (if (and (stringp idlwave-path-file) | |
5572 | (file-regular-p idlwave-path-file)) | |
5573 | (condition-case nil | |
5574 | (load idlwave-path-file t t t) | |
5575 | (error nil)))) | |
5576 | ||
5577 | (defun idlwave-write-paths () | |
5578 | (interactive) | |
5579 | (when (and idlwave-path-alist idlwave-system-directory) | |
5580 | (let ((font-lock-maximum-size 0) | |
5581 | (auto-mode-alist nil)) | |
5582 | (find-file idlwave-path-file)) | |
5583 | (if (and (boundp 'font-lock-mode) | |
5584 | font-lock-mode) | |
5585 | (font-lock-mode 0)) | |
5586 | (erase-buffer) | |
5587 | (insert ";; IDLWAVE paths\n") | |
5588 | (insert (format ";; Created %s\n\n" (current-time-string))) | |
5589 | ;; Define the variable which knows the value of "!DIR" | |
5590 | (insert (format "\n(setq idlwave-system-directory \"%s\")\n" | |
5591 | idlwave-system-directory)) | |
4b1aaa8b | 5592 | |
52a244eb S |
5593 | ;; Define the variable which contains a list of all scanned directories |
5594 | (insert "\n(setq idlwave-path-alist\n '(") | |
5595 | (let ((standard-output (current-buffer))) | |
8ffcfb27 GM |
5596 | (mapc (lambda (x) |
5597 | (insert "\n ") | |
5598 | (prin1 x) | |
5599 | (goto-char (point-max))) | |
5600 | idlwave-path-alist)) | |
52a244eb S |
5601 | (insert "))\n") |
5602 | (save-buffer 0) | |
5603 | (kill-buffer (current-buffer)))) | |
5604 | ||
5605 | ||
f32b3b91 CD |
5606 | (defun idlwave-expand-path (path &optional default-dir) |
5607 | ;; Expand parts of path starting with '+' recursively into directory list. | |
5608 | ;; Relative recursive path elements are expanded relative to DEFAULT-DIR. | |
5609 | (message "Expanding path...") | |
5610 | (let (path1 dir recursive) | |
5611 | (while (setq dir (pop path)) | |
5612 | (if (setq recursive (string= (substring dir 0 1) "+")) | |
5613 | (setq dir (substring dir 1))) | |
5614 | (if (and recursive | |
5615 | (not (file-name-absolute-p dir))) | |
5616 | (setq dir (expand-file-name dir default-dir))) | |
5617 | (if recursive | |
5618 | ;; Expand recursively | |
5619 | (setq path1 (append (idlwave-recursive-directory-list dir) path1)) | |
5620 | ;; Keep unchanged | |
5621 | (push dir path1))) | |
5622 | (message "Expanding path...done") | |
5623 | (nreverse path1))) | |
5624 | ||
5625 | (defun idlwave-recursive-directory-list (dir) | |
5626 | ;; Return a list of all directories below DIR, including DIR itself | |
5627 | (let ((path (list dir)) path1 file files) | |
5628 | (while (setq dir (pop path)) | |
5629 | (when (file-directory-p dir) | |
5630 | (setq files (nreverse (directory-files dir t "[^.]"))) | |
5631 | (while (setq file (pop files)) | |
4b1aaa8b | 5632 | (if (file-directory-p file) |
f32b3b91 CD |
5633 | (push (file-name-as-directory file) path))) |
5634 | (push dir path1))) | |
5635 | path1)) | |
5636 | ||
52a244eb S |
5637 | |
5638 | ;;----- Scanning the library catalogs ------------------ | |
5639 | ||
3938cb82 S |
5640 | |
5641 | ||
5642 | ||
52a244eb | 5643 | (defun idlwave-scan-library-catalogs (&optional message-base no-load) |
4b1aaa8b | 5644 | "Scan for library catalog files (.idlwave_catalog) and ingest. |
52a244eb S |
5645 | |
5646 | All directories on `idlwave-path-alist' (or `idlwave-library-path' | |
5647 | instead, if present) are searched. Print MESSAGE-BASE along with the | |
5648 | libraries being loaded, if passed, and skip loading/normalizing if | |
5649 | NO-LOAD is non-nil. The variable `idlwave-use-library-catalogs' can | |
5650 | be set to nil to disable library catalog scanning." | |
5651 | (when idlwave-use-library-catalogs | |
4b1aaa8b | 5652 | (let ((dirs |
52a244eb S |
5653 | (if idlwave-library-path |
5654 | (idlwave-expand-path idlwave-library-path) | |
5655 | (mapcar 'car idlwave-path-alist))) | |
5656 | (old-libname "") | |
5657 | dir-entry dir flags catalog all-routines) | |
5658 | (if message-base (message message-base)) | |
5659 | (while (setq dir (pop dirs)) | |
5660 | (catch 'continue | |
4b1aaa8b | 5661 | (when (file-readable-p |
52a244eb S |
5662 | (setq catalog (expand-file-name ".idlwave_catalog" dir))) |
5663 | (unless no-load | |
5664 | (setq idlwave-library-catalog-routines nil) | |
5665 | ;; Load the catalog file | |
5666 | (condition-case nil | |
5667 | (load catalog t t t) | |
5668 | (error (throw 'continue t))) | |
4b1aaa8b PE |
5669 | (when (and |
5670 | message-base | |
5671 | (not (string= idlwave-library-catalog-libname | |
52a244eb | 5672 | old-libname))) |
4b1aaa8b | 5673 | (message "%s" (concat message-base |
f66f03de | 5674 | idlwave-library-catalog-libname)) |
52a244eb S |
5675 | (setq old-libname idlwave-library-catalog-libname)) |
5676 | (when idlwave-library-catalog-routines | |
5677 | (setq all-routines | |
4b1aaa8b | 5678 | (append |
52a244eb S |
5679 | (idlwave-sintern-rinfo-list |
5680 | idlwave-library-catalog-routines 'sys dir) | |
5681 | all-routines)))) | |
4b1aaa8b | 5682 | |
52a244eb S |
5683 | ;; Add a 'lib flag if on path-alist |
5684 | (when (and idlwave-path-alist | |
5685 | (setq dir-entry (assoc dir idlwave-path-alist))) | |
5686 | (idlwave-path-alist-add-flag dir-entry 'lib))))) | |
5687 | (unless no-load (setq idlwave-library-catalog-routines all-routines)) | |
5688 | (if message-base (message (concat message-base "done")))))) | |
5689 | ||
5690 | ;;----- Communicating with the Shell ------------------- | |
f32b3b91 CD |
5691 | |
5692 | ;; First, here is the idl program which can be used to query IDL for | |
4b1aaa8b | 5693 | ;; defined routines. |
f32b3b91 CD |
5694 | (defconst idlwave-routine-info.pro |
5695 | " | |
05a1abfc | 5696 | ;; START OF IDLWAVE SUPPORT ROUTINES |
f66f03de S |
5697 | pro idlwave_print_safe,item,limit |
5698 | catch,err | |
5699 | if err ne 0 then begin | |
5700 | print,'Could not print item.' | |
5701 | return | |
5702 | endif | |
5703 | if n_elements(item) gt limit then $ | |
5704 | print,item[0:limit-1],'<... truncated at ',strtrim(limit,2),' elements>' $ | |
5705 | else print,item | |
5706 | end | |
5707 | ||
15e42531 | 5708 | pro idlwave_print_info_entry,name,func=func,separator=sep |
f32b3b91 | 5709 | ;; See if it's an object method |
15e42531 | 5710 | if name eq '' then return |
4b1aaa8b | 5711 | func = keyword_set(func) |
f32b3b91 CD |
5712 | methsep = strpos(name,'::') |
5713 | meth = methsep ne -1 | |
4b1aaa8b | 5714 | |
f32b3b91 CD |
5715 | ;; Get routine info |
5716 | pars = routine_info(name,/parameters,functions=func) | |
5717 | source = routine_info(name,/source,functions=func) | |
5718 | nargs = pars.num_args | |
5719 | nkw = pars.num_kw_args | |
5720 | if nargs gt 0 then args = pars.args | |
5721 | if nkw gt 0 then kwargs = pars.kw_args | |
4b1aaa8b | 5722 | |
f32b3b91 | 5723 | ;; Trim the class, and make the name |
4b1aaa8b | 5724 | if meth then begin |
f32b3b91 CD |
5725 | class = strmid(name,0,methsep) |
5726 | name = strmid(name,methsep+2,strlen(name)-1) | |
4b1aaa8b | 5727 | if nargs gt 0 then begin |
f32b3b91 CD |
5728 | ;; remove the self argument |
5729 | wh = where(args ne 'SELF',nargs) | |
52a244eb | 5730 | if nargs gt 0 then args = args[wh] |
f32b3b91 CD |
5731 | endif |
5732 | endif else begin | |
5733 | ;; No class, just a normal routine. | |
5734 | class = \"\" | |
5735 | endelse | |
4b1aaa8b | 5736 | |
f32b3b91 CD |
5737 | ;; Calling sequence |
5738 | cs = \"\" | |
5739 | if func then cs = 'Result = ' | |
5740 | if meth then cs = cs + 'Obj -> [' + '%s' + '::]' | |
5741 | cs = cs + '%s' | |
5742 | if func then cs = cs + '(' else if nargs gt 0 then cs = cs + ', ' | |
5743 | if nargs gt 0 then begin | |
5744 | for j=0,nargs-1 do begin | |
52a244eb | 5745 | cs = cs + args[j] |
f32b3b91 CD |
5746 | if j lt nargs-1 then cs = cs + ', ' |
5747 | endfor | |
5748 | end | |
5749 | if func then cs = cs + ')' | |
5750 | ;; Keyword arguments | |
5751 | kwstring = '' | |
5752 | if nkw gt 0 then begin | |
5753 | for j=0,nkw-1 do begin | |
52a244eb | 5754 | kwstring = kwstring + ' ' + kwargs[j] |
f32b3b91 CD |
5755 | endfor |
5756 | endif | |
4b1aaa8b | 5757 | |
52a244eb | 5758 | ret=(['IDLWAVE-PRO','IDLWAVE-FUN'])[func] |
4b1aaa8b | 5759 | |
52a244eb | 5760 | print,ret + ': ' + name + sep + class + sep + source[0].path $ |
f32b3b91 CD |
5761 | + sep + cs + sep + kwstring |
5762 | end | |
5763 | ||
f66f03de | 5764 | pro idlwave_routine_info,file |
52a244eb | 5765 | on_error,1 |
f32b3b91 CD |
5766 | sep = '<@>' |
5767 | print,'>>>BEGIN OF IDLWAVE ROUTINE INFO (\"' + sep + '\" IS THE SEPARATOR)' | |
5768 | all = routine_info() | |
f66f03de S |
5769 | fileQ=n_elements(file) ne 0 |
5770 | if fileQ then file=strtrim(file,2) | |
4b1aaa8b PE |
5771 | for i=0L,n_elements(all)-1L do begin |
5772 | if fileQ then begin | |
f66f03de S |
5773 | if (routine_info(all[i],/SOURCE)).path eq file then $ |
5774 | idlwave_print_info_entry,all[i],separator=sep | |
5775 | endif else idlwave_print_info_entry,all[i],separator=sep | |
4b1aaa8b | 5776 | endfor |
f32b3b91 | 5777 | all = routine_info(/functions) |
4b1aaa8b PE |
5778 | for i=0L,n_elements(all)-1L do begin |
5779 | if fileQ then begin | |
f66f03de S |
5780 | if (routine_info(all[i],/FUNCTIONS,/SOURCE)).path eq file then $ |
5781 | idlwave_print_info_entry,all[i],separator=sep,/FUNC | |
5782 | endif else idlwave_print_info_entry,all[i],separator=sep,/FUNC | |
4b1aaa8b | 5783 | endfor |
f32b3b91 CD |
5784 | print,'>>>END OF IDLWAVE ROUTINE INFO' |
5785 | end | |
05a1abfc CD |
5786 | |
5787 | pro idlwave_get_sysvars | |
52a244eb | 5788 | on_error,1 |
05a1abfc CD |
5789 | catch,error_status |
5790 | if error_status ne 0 then begin | |
5791 | print, 'Cannot get info about system variables' | |
5792 | endif else begin | |
5793 | help,/brief,output=s,/system_variables ; ? unsafe use of OUTPUT= | |
5794 | s = strtrim(strjoin(s,' ',/single),2) ; make one line | |
5795 | v = strsplit(s,' +',/regex,/extract) ; get variables | |
f66f03de | 5796 | for i=0L,n_elements(v)-1 do begin |
05a1abfc CD |
5797 | t = [''] ; get tag list |
5798 | a=execute('if n_tags('+v[i]+') gt 0 then t=tag_names('+v[i]+')') | |
5799 | print, 'IDLWAVE-SYSVAR: '+v[i]+' '+strjoin(t,' ',/single) | |
5800 | endfor | |
5801 | endelse | |
5802 | end | |
5803 | ||
5804 | pro idlwave_get_class_tags, class | |
5805 | res = execute('tags=tag_names({'+class+'})') | |
5e72c6b2 | 5806 | if res then print,'IDLWAVE-CLASS-TAGS: '+class+' '+strjoin(tags,' ',/single) |
05a1abfc CD |
5807 | end |
5808 | ;; END OF IDLWAVE SUPPORT ROUTINES | |
4b1aaa8b | 5809 | " |
05a1abfc | 5810 | "The idl programs to get info from the shell.") |
f32b3b91 | 5811 | |
15e42531 CD |
5812 | (defvar idlwave-idlwave_routine_info-compiled nil |
5813 | "Remembers if the routine info procedure is already compiled.") | |
f32b3b91 CD |
5814 | |
5815 | (defvar idlwave-shell-temp-pro-file) | |
15e42531 | 5816 | (defvar idlwave-shell-temp-rinfo-save-file) |
f66f03de S |
5817 | |
5818 | (defun idlwave-shell-compile-helper-routines (&optional wait) | |
15e42531 | 5819 | (unless (and idlwave-idlwave_routine_info-compiled |
5e72c6b2 | 5820 | (file-readable-p (idlwave-shell-temp-file 'rinfo))) |
15e42531 CD |
5821 | (save-excursion |
5822 | (set-buffer (idlwave-find-file-noselect | |
5e72c6b2 | 5823 | (idlwave-shell-temp-file 'pro))) |
15e42531 CD |
5824 | (erase-buffer) |
5825 | (insert idlwave-routine-info.pro) | |
5826 | (save-buffer 0)) | |
4b1aaa8b | 5827 | (idlwave-shell-send-command |
f66f03de | 5828 | (concat ".run \"" idlwave-shell-temp-pro-file "\"") |
52a244eb | 5829 | nil 'hide wait) |
15e42531 | 5830 | (idlwave-shell-send-command |
4b1aaa8b | 5831 | (format "save,'idlwave_print_safe','idlwave_routine_info','idlwave_print_info_entry','idlwave_get_class_tags','idlwave_get_sysvars',FILE='%s',/ROUTINES" |
5e72c6b2 | 5832 | (idlwave-shell-temp-file 'rinfo)) |
f66f03de S |
5833 | nil 'hide) |
5834 | (setq idlwave-idlwave_routine_info-compiled t)) | |
15e42531 | 5835 | |
f66f03de S |
5836 | ;; Restore if necessary. Must use execute to hide lame routine_info |
5837 | ;; errors on undefinded routine | |
15e42531 | 5838 | (idlwave-shell-send-command |
f66f03de S |
5839 | (format "if execute(\"_v=routine_info('idlwave_routine_info',/SOURCE)\") eq 0 then restore,'%s' else if _v.path eq '' then restore,'%s'" |
5840 | idlwave-shell-temp-rinfo-save-file | |
15e42531 | 5841 | idlwave-shell-temp-rinfo-save-file) |
f66f03de S |
5842 | nil 'hide)) |
5843 | ||
5844 | ||
5845 | (defun idlwave-shell-update-routine-info (&optional quiet run-hooks wait file) | |
5846 | "Query the shell for routine_info of compiled modules and update the lists." | |
5847 | ;; Save and compile the procedure. The compiled procedure is then | |
5848 | ;; saved into an IDL SAVE file, to allow for fast RESTORE. We may | |
5849 | ;; need to test for and possibly RESTORE the procedure each time we | |
5850 | ;; use it, since the user may have killed or redefined it. In | |
5851 | ;; particular, .RESET_SESSION will kill all user procedures. If | |
5852 | ;; FILE is set, only update routine info for routines in that file. | |
5853 | ||
5854 | (idlwave-shell-compile-helper-routines wait) | |
5855 | ; execute the routine_info procedure, and analyze the output | |
5856 | (idlwave-shell-send-command | |
5857 | (format "idlwave_routine_info%s" (if file (concat ",'" file "'") "")) | |
15e42531 CD |
5858 | `(progn |
5859 | (idlwave-shell-routine-info-filter) | |
05a1abfc | 5860 | (idlwave-concatenate-rinfo-lists ,quiet ,run-hooks)) |
52a244eb | 5861 | 'hide wait)) |
f32b3b91 CD |
5862 | |
5863 | ;; --------------------------------------------------------------------------- | |
5864 | ;; | |
5865 | ;; Completion and displaying routine calling sequences | |
5866 | ||
15e42531 | 5867 | (defvar idlwave-completion-help-info nil) |
52a244eb | 5868 | (defvar idlwave-completion-help-links nil) |
15e42531 | 5869 | (defvar idlwave-current-obj_new-class nil) |
05a1abfc | 5870 | (defvar idlwave-complete-special nil) |
15e42531 | 5871 | |
f32b3b91 CD |
5872 | (defun idlwave-complete (&optional arg module class) |
5873 | "Complete a function, procedure or keyword name at point. | |
2e8b9c7d | 5874 | This function is smart and figures out what can be completed |
f32b3b91 CD |
5875 | at this point. |
5876 | - At the beginning of a statement it completes procedure names. | |
5877 | - In the middle of a statement it completes function names. | |
5878 | - after a `(' or `,' in the argument list of a function or procedure, | |
5879 | it completes a keyword of the relevant function or procedure. | |
5880 | - In the first arg of `OBJ_NEW', it completes a class name. | |
5881 | ||
5e72c6b2 | 5882 | When several completions are possible, a list will be displayed in the |
f32b3b91 | 5883 | *Completions* buffer. If this list is too long to fit into the |
5e72c6b2 S |
5884 | window, scrolling can be achieved by repeatedly pressing |
5885 | \\[idlwave-complete]. | |
f32b3b91 CD |
5886 | |
5887 | The function also knows about object methods. When it needs a class | |
5888 | name, the action depends upon `idlwave-query-class', which see. You | |
5e72c6b2 S |
5889 | can force IDLWAVE to ask you for a class name with a |
5890 | \\[universal-argument] prefix argument to this command. | |
f32b3b91 CD |
5891 | |
5892 | See also the variables `idlwave-keyword-completion-adds-equal' and | |
5893 | `idlwave-function-completion-adds-paren'. | |
5894 | ||
5895 | The optional ARG can be used to specify the completion type in order | |
5896 | to override IDLWAVE's idea of what should be completed at point. | |
5897 | Possible values are: | |
5898 | ||
5899 | 0 <=> query for the completion type | |
5900 | 1 <=> 'procedure | |
5901 | 2 <=> 'procedure-keyword | |
5902 | 3 <=> 'function | |
5903 | 4 <=> 'function-keyword | |
5904 | 5 <=> 'procedure-method | |
5905 | 6 <=> 'procedure-method-keyword | |
5906 | 7 <=> 'function-method | |
5907 | 8 <=> 'function-method-keyword | |
5908 | 9 <=> 'class | |
5909 | ||
5e72c6b2 S |
5910 | As a special case, the universal argument C-u forces completion of |
5911 | function names in places where the default would be a keyword. | |
5912 | ||
52a244eb S |
5913 | Two prefix argument, C-u C-u, prompts for a regexp by which to limit |
5914 | completion. | |
5915 | ||
f32b3b91 CD |
5916 | For Lisp programmers only: |
5917 | When we force a keyword, optional argument MODULE can contain the module name. | |
5918 | When we force a method or a method keyword, CLASS can specify the class." | |
5919 | (interactive "P") | |
5920 | (idlwave-routines) | |
5921 | (let* ((where-list | |
5922 | (if (and arg | |
52a244eb | 5923 | (or (and (integerp arg) (not (equal arg '(16)))) |
f32b3b91 CD |
5924 | (symbolp arg))) |
5925 | (idlwave-make-force-complete-where-list arg module class) | |
5926 | (idlwave-where))) | |
5927 | (what (nth 2 where-list)) | |
52a244eb S |
5928 | (idlwave-force-class-query (equal arg '(4))) |
5929 | (completion-regexp-list | |
5930 | (if (equal arg '(16)) | |
5931 | (list (read-string (concat "Completion Regexp: ")))))) | |
4b1aaa8b | 5932 | |
f32b3b91 CD |
5933 | (if (and module (string-match "::" module)) |
5934 | (setq class (substring module 0 (match-beginning 0)) | |
5935 | module (substring module (match-end 0)))) | |
5936 | ||
5937 | (cond | |
5938 | ||
5939 | ((and (null arg) | |
5940 | (eq (car-safe last-command) 'idlwave-display-completion-list) | |
595ab50b | 5941 | (get-buffer-window "*Completions*")) |
f32b3b91 CD |
5942 | (setq this-command last-command) |
5943 | (idlwave-scroll-completions)) | |
5944 | ||
52a244eb | 5945 | ;; Complete a filename in quotes |
05a1abfc CD |
5946 | ((and (idlwave-in-quote) |
5947 | (not (eq what 'class))) | |
5948 | (idlwave-complete-filename)) | |
5949 | ||
52a244eb S |
5950 | ;; Check for any special completion functions |
5951 | ((and idlwave-complete-special | |
5952 | (idlwave-call-special idlwave-complete-special))) | |
4b1aaa8b | 5953 | |
f32b3b91 CD |
5954 | ((null what) |
5955 | (error "Nothing to complete here")) | |
5956 | ||
52a244eb | 5957 | ;; Complete a class |
f32b3b91 | 5958 | ((eq what 'class) |
15e42531 | 5959 | (setq idlwave-completion-help-info '(class)) |
f32b3b91 CD |
5960 | (idlwave-complete-class)) |
5961 | ||
5962 | ((eq what 'procedure) | |
5963 | ;; Complete a procedure name | |
5e72c6b2 S |
5964 | (let* ((cw-list (nth 3 where-list)) |
5965 | (class-selector (idlwave-determine-class cw-list 'pro)) | |
5966 | (super-classes (unless (idlwave-explicit-class-listed cw-list) | |
5967 | (idlwave-all-class-inherits class-selector))) | |
f32b3b91 CD |
5968 | (isa (concat "procedure" (if class-selector "-method" ""))) |
5969 | (type-selector 'pro)) | |
4b1aaa8b | 5970 | (setq idlwave-completion-help-info |
05a1abfc | 5971 | (list 'routine nil type-selector class-selector nil super-classes)) |
f32b3b91 CD |
5972 | (idlwave-complete-in-buffer |
5973 | 'procedure (if class-selector 'method 'routine) | |
5974 | (idlwave-routines) 'idlwave-selector | |
5975 | (format "Select a %s name%s" | |
5976 | isa | |
5977 | (if class-selector | |
4b1aaa8b PE |
5978 | (format " (class is %s)" |
5979 | (if (eq class-selector t) | |
76959b77 | 5980 | "unknown" class-selector)) |
f32b3b91 CD |
5981 | "")) |
5982 | isa | |
52a244eb | 5983 | 'idlwave-attach-method-classes 'idlwave-add-file-link-selector))) |
f32b3b91 CD |
5984 | |
5985 | ((eq what 'function) | |
5986 | ;; Complete a function name | |
5e72c6b2 S |
5987 | (let* ((cw-list (nth 3 where-list)) |
5988 | (class-selector (idlwave-determine-class cw-list 'fun)) | |
5989 | (super-classes (unless (idlwave-explicit-class-listed cw-list) | |
5990 | (idlwave-all-class-inherits class-selector))) | |
f32b3b91 CD |
5991 | (isa (concat "function" (if class-selector "-method" ""))) |
5992 | (type-selector 'fun)) | |
4b1aaa8b | 5993 | (setq idlwave-completion-help-info |
05a1abfc | 5994 | (list 'routine nil type-selector class-selector nil super-classes)) |
f32b3b91 CD |
5995 | (idlwave-complete-in-buffer |
5996 | 'function (if class-selector 'method 'routine) | |
5997 | (idlwave-routines) 'idlwave-selector | |
5998 | (format "Select a %s name%s" | |
5999 | isa | |
6000 | (if class-selector | |
4b1aaa8b | 6001 | (format " (class is %s)" |
76959b77 S |
6002 | (if (eq class-selector t) |
6003 | "unknown" class-selector)) | |
f32b3b91 CD |
6004 | "")) |
6005 | isa | |
52a244eb | 6006 | 'idlwave-attach-method-classes 'idlwave-add-file-link-selector))) |
f32b3b91 | 6007 | |
52a244eb | 6008 | ((and (memq what '(procedure-keyword function-keyword)) ; Special Case |
5e72c6b2 S |
6009 | (equal arg '(4))) |
6010 | (idlwave-complete 3)) | |
6011 | ||
f32b3b91 CD |
6012 | ((eq what 'procedure-keyword) |
6013 | ;; Complete a procedure keyword | |
6014 | (let* ((where (nth 3 where-list)) | |
6015 | (name (car where)) | |
6016 | (method-selector name) | |
6017 | (type-selector 'pro) | |
6018 | (class (idlwave-determine-class where 'pro)) | |
6019 | (class-selector class) | |
05a1abfc | 6020 | (super-classes (idlwave-all-class-inherits class-selector)) |
f32b3b91 | 6021 | (isa (format "procedure%s-keyword" (if class "-method" ""))) |
15e42531 | 6022 | (entry (idlwave-best-rinfo-assq |
f32b3b91 | 6023 | name 'pro class (idlwave-routines))) |
3938cb82 | 6024 | (system (if entry (eq (car (nth 3 entry)) 'system))) |
52a244eb | 6025 | (list (idlwave-entry-keywords entry 'do-link))) |
f32b3b91 CD |
6026 | (unless (or entry (eq class t)) |
6027 | (error "Nothing known about procedure %s" | |
6028 | (idlwave-make-full-name class name))) | |
4b1aaa8b | 6029 | (setq list (idlwave-fix-keywords name 'pro class list |
3938cb82 | 6030 | super-classes system)) |
b6a97790 | 6031 | (unless list (error "No keywords available for procedure %s" |
3938cb82 | 6032 | (idlwave-make-full-name class name))) |
4b1aaa8b | 6033 | (setq idlwave-completion-help-info |
52a244eb | 6034 | (list 'keyword name type-selector class-selector entry super-classes)) |
f32b3b91 CD |
6035 | (idlwave-complete-in-buffer |
6036 | 'keyword 'keyword list nil | |
6037 | (format "Select keyword for procedure %s%s" | |
6038 | (idlwave-make-full-name class name) | |
15e42531 | 6039 | (if (or (member '("_EXTRA") list) |
4b1aaa8b | 6040 | (member '("_REF_EXTRA") list)) |
15e42531 | 6041 | " (note _EXTRA)" "")) |
f32b3b91 CD |
6042 | isa |
6043 | 'idlwave-attach-keyword-classes))) | |
6044 | ||
6045 | ((eq what 'function-keyword) | |
6046 | ;; Complete a function keyword | |
6047 | (let* ((where (nth 3 where-list)) | |
6048 | (name (car where)) | |
6049 | (method-selector name) | |
6050 | (type-selector 'fun) | |
6051 | (class (idlwave-determine-class where 'fun)) | |
6052 | (class-selector class) | |
05a1abfc | 6053 | (super-classes (idlwave-all-class-inherits class-selector)) |
f32b3b91 | 6054 | (isa (format "function%s-keyword" (if class "-method" ""))) |
15e42531 | 6055 | (entry (idlwave-best-rinfo-assq |
f32b3b91 | 6056 | name 'fun class (idlwave-routines))) |
3938cb82 | 6057 | (system (if entry (eq (car (nth 3 entry)) 'system))) |
52a244eb | 6058 | (list (idlwave-entry-keywords entry 'do-link)) |
15e42531 | 6059 | msg-name) |
f32b3b91 CD |
6060 | (unless (or entry (eq class t)) |
6061 | (error "Nothing known about function %s" | |
6062 | (idlwave-make-full-name class name))) | |
4b1aaa8b | 6063 | (setq list (idlwave-fix-keywords name 'fun class list |
3938cb82 | 6064 | super-classes system)) |
15e42531 CD |
6065 | ;; OBJ_NEW: Messages mention the proper Init method |
6066 | (setq msg-name (if (and (null class) | |
6067 | (string= (upcase name) "OBJ_NEW")) | |
6068 | (concat idlwave-current-obj_new-class | |
6069 | "::Init (via OBJ_NEW)") | |
6070 | (idlwave-make-full-name class name))) | |
b6a97790 | 6071 | (unless list (error "No keywords available for function %s" |
3938cb82 | 6072 | msg-name)) |
4b1aaa8b | 6073 | (setq idlwave-completion-help-info |
05a1abfc | 6074 | (list 'keyword name type-selector class-selector nil super-classes)) |
f32b3b91 CD |
6075 | (idlwave-complete-in-buffer |
6076 | 'keyword 'keyword list nil | |
15e42531 CD |
6077 | (format "Select keyword for function %s%s" msg-name |
6078 | (if (or (member '("_EXTRA") list) | |
4b1aaa8b | 6079 | (member '("_REF_EXTRA") list)) |
15e42531 | 6080 | " (note _EXTRA)" "")) |
f32b3b91 CD |
6081 | isa |
6082 | 'idlwave-attach-keyword-classes))) | |
15e42531 | 6083 | |
f32b3b91 CD |
6084 | (t (error "This should not happen (idlwave-complete)"))))) |
6085 | ||
05a1abfc CD |
6086 | (defvar idlwave-complete-special nil |
6087 | "List of special completion functions. | |
52a244eb S |
6088 | These functions are called for each completion. Each function must |
6089 | check if its own special completion context is present. If yes, it | |
6090 | should use `idlwave-complete-in-buffer' to do some completion and | |
6091 | return t. If such a function returns t, *no further* attempts to | |
6092 | complete other contexts will be done. If the function returns nil, | |
6093 | other completions will be tried.") | |
76959b77 S |
6094 | |
6095 | (defun idlwave-call-special (functions &rest args) | |
6096 | (let ((funcs functions) | |
6097 | fun ret) | |
05a1abfc | 6098 | (catch 'exit |
76959b77 S |
6099 | (while (setq fun (pop funcs)) |
6100 | (if (setq ret (apply fun args)) | |
6101 | (throw 'exit ret))) | |
05a1abfc CD |
6102 | nil))) |
6103 | ||
f32b3b91 CD |
6104 | (defun idlwave-make-force-complete-where-list (what &optional module class) |
6105 | ;; Return an artificial WHERE specification to force the completion | |
6106 | ;; routine to complete a specific item independent of context. | |
6107 | ;; WHAT is the prefix arg of `idlwave-complete', see there for details. | |
6108 | ;; MODULE and CLASS can be used to specify the routine name and class. | |
6109 | ;; The class name will also be found in MODULE if that is like "class::mod". | |
6110 | (let* ((what-list '(("procedure") ("procedure-keyword") | |
6111 | ("function") ("function-keyword") | |
6112 | ("procedure-method") ("procedure-method-keyword") | |
6113 | ("function-method") ("function-method-keyword") | |
6114 | ("class"))) | |
6115 | (module (idlwave-sintern-routine-or-method module class)) | |
6116 | (class (idlwave-sintern-class class)) | |
4b1aaa8b | 6117 | (what (cond |
f32b3b91 CD |
6118 | ((equal what 0) |
6119 | (setq what | |
4b1aaa8b | 6120 | (intern (completing-read |
f32b3b91 CD |
6121 | "Complete what? " what-list nil t)))) |
6122 | ((integerp what) | |
6123 | (setq what (intern (car (nth (1- what) what-list))))) | |
6124 | ((and what | |
6125 | (symbolp what) | |
6126 | (assoc (symbol-name what) what-list)) | |
6127 | what) | |
eac9c0ef | 6128 | (t (error "Invalid WHAT")))) |
f32b3b91 CD |
6129 | (nil-list '(nil nil nil nil)) |
6130 | (class-list (list nil nil (or class t) nil))) | |
6131 | ||
6132 | (cond | |
6133 | ||
6134 | ((eq what 'procedure) | |
6135 | (list nil-list nil-list 'procedure nil-list nil)) | |
6136 | ||
6137 | ((eq what 'procedure-keyword) | |
6138 | (let* ((class-selector nil) | |
05a1abfc | 6139 | (super-classes nil) |
f32b3b91 CD |
6140 | (type-selector 'pro) |
6141 | (pro (or module | |
4b1aaa8b | 6142 | (idlwave-completing-read |
f32b3b91 CD |
6143 | "Procedure: " (idlwave-routines) 'idlwave-selector)))) |
6144 | (setq pro (idlwave-sintern-routine pro)) | |
6145 | (list nil-list nil-list 'procedure-keyword | |
6146 | (list pro nil nil nil) nil))) | |
6147 | ||
6148 | ((eq what 'function) | |
6149 | (list nil-list nil-list 'function nil-list nil)) | |
6150 | ||
6151 | ((eq what 'function-keyword) | |
6152 | (let* ((class-selector nil) | |
05a1abfc | 6153 | (super-classes nil) |
f32b3b91 CD |
6154 | (type-selector 'fun) |
6155 | (func (or module | |
4b1aaa8b | 6156 | (idlwave-completing-read |
f32b3b91 CD |
6157 | "Function: " (idlwave-routines) 'idlwave-selector)))) |
6158 | (setq func (idlwave-sintern-routine func)) | |
6159 | (list nil-list nil-list 'function-keyword | |
6160 | (list func nil nil nil) nil))) | |
6161 | ||
6162 | ((eq what 'procedure-method) | |
6163 | (list nil-list nil-list 'procedure class-list nil)) | |
6164 | ||
6165 | ((eq what 'procedure-method-keyword) | |
6166 | (let* ((class (idlwave-determine-class class-list 'pro)) | |
6167 | (class-selector class) | |
05a1abfc | 6168 | (super-classes (idlwave-all-class-inherits class-selector)) |
f32b3b91 CD |
6169 | (type-selector 'pro) |
6170 | (pro (or module | |
6171 | (idlwave-completing-read | |
6172 | (format "Procedure in %s class: " class-selector) | |
6173 | (idlwave-routines) 'idlwave-selector)))) | |
6174 | (setq pro (idlwave-sintern-method pro)) | |
6175 | (list nil-list nil-list 'procedure-keyword | |
6176 | (list pro nil class nil) nil))) | |
6177 | ||
6178 | ((eq what 'function-method) | |
6179 | (list nil-list nil-list 'function class-list nil)) | |
6180 | ||
6181 | ((eq what 'function-method-keyword) | |
6182 | (let* ((class (idlwave-determine-class class-list 'fun)) | |
6183 | (class-selector class) | |
05a1abfc | 6184 | (super-classes (idlwave-all-class-inherits class-selector)) |
f32b3b91 CD |
6185 | (type-selector 'fun) |
6186 | (func (or module | |
6187 | (idlwave-completing-read | |
6188 | (format "Function in %s class: " class-selector) | |
6189 | (idlwave-routines) 'idlwave-selector)))) | |
6190 | (setq func (idlwave-sintern-method func)) | |
6191 | (list nil-list nil-list 'function-keyword | |
6192 | (list func nil class nil) nil))) | |
6193 | ||
6194 | ((eq what 'class) | |
6195 | (list nil-list nil-list 'class nil-list nil)) | |
4b1aaa8b | 6196 | |
eac9c0ef | 6197 | (t (error "Invalid value for WHAT"))))) |
f32b3b91 CD |
6198 | |
6199 | (defun idlwave-completing-read (&rest args) | |
6200 | ;; Completing read, case insensitive | |
6201 | (let ((old-value (default-value 'completion-ignore-case))) | |
6202 | (unwind-protect | |
6203 | (progn | |
6204 | (setq-default completion-ignore-case t) | |
6205 | (apply 'completing-read args)) | |
6206 | (setq-default completion-ignore-case old-value)))) | |
6207 | ||
05a1abfc CD |
6208 | (defvar idlwave-shell-default-directory) |
6209 | (defun idlwave-complete-filename () | |
6210 | "Use the comint stuff to complete a file name." | |
6211 | (require 'comint) | |
6212 | (let* ((comint-file-name-chars "~/A-Za-z0-9+@:_.$#%={}\\-") | |
6213 | (comint-completion-addsuffix nil) | |
6214 | (default-directory | |
6215 | (if (and (boundp 'idlwave-shell-default-directory) | |
6216 | (stringp idlwave-shell-default-directory) | |
6217 | (file-directory-p idlwave-shell-default-directory)) | |
6218 | idlwave-shell-default-directory | |
4b1aaa8b | 6219 | default-directory))) |
05a1abfc CD |
6220 | (comint-dynamic-complete-filename))) |
6221 | ||
f32b3b91 CD |
6222 | (defun idlwave-make-full-name (class name) |
6223 | ;; Make a fully qualified module name including the class name | |
6224 | (concat (if class (format "%s::" class) "") name)) | |
6225 | ||
15e42531 CD |
6226 | (defun idlwave-rinfo-assoc (name type class list) |
6227 | "Like `idlwave-rinfo-assq', but sintern strings first." | |
4b1aaa8b | 6228 | (idlwave-rinfo-assq |
15e42531 CD |
6229 | (idlwave-sintern-routine-or-method name class) |
6230 | type (idlwave-sintern-class class) list)) | |
6231 | ||
f32b3b91 CD |
6232 | (defun idlwave-rinfo-assq (name type class list) |
6233 | ;; Works like assq, but also checks type and class | |
6234 | (catch 'exit | |
6235 | (let (match) | |
6236 | (while (setq match (assq name list)) | |
6237 | (and (or (eq type t) | |
6238 | (eq (nth 1 match) type)) | |
6239 | (eq (nth 2 match) class) | |
6240 | (throw 'exit match)) | |
6241 | (setq list (cdr (memq match list))))))) | |
6242 | ||
05a1abfc | 6243 | (defun idlwave-rinfo-assq-any-class (name type class list) |
52a244eb | 6244 | ;; Return the first matching method on the inheritance list |
05a1abfc CD |
6245 | (let* ((classes (cons class (idlwave-all-class-inherits class))) |
6246 | class rtn) | |
6247 | (while classes | |
6248 | (if (setq rtn (idlwave-rinfo-assq name type (pop classes) list)) | |
6249 | (setq classes nil))) | |
6250 | rtn)) | |
6251 | ||
4b1aaa8b | 6252 | (defun idlwave-best-rinfo-assq (name type class list &optional with-file |
52a244eb S |
6253 | keep-system) |
6254 | "Like `idlwave-rinfo-assq', but get all twins and sort, then return first. | |
6255 | If WITH-FILE is passed, find the best rinfo entry with a file | |
6256 | included. If KEEP-SYSTEM is set, don't prune system for compiled | |
6257 | syslib files." | |
15e42531 | 6258 | (let ((twins (idlwave-routine-twins |
05a1abfc | 6259 | (idlwave-rinfo-assq-any-class name type class list) |
15e42531 CD |
6260 | list)) |
6261 | syslibp) | |
6262 | (when (> (length twins) 1) | |
6263 | (setq twins (sort twins 'idlwave-routine-entry-compare-twins)) | |
52a244eb S |
6264 | (if (and (null keep-system) |
6265 | (eq 'system (car (nth 3 (car twins)))) | |
15e42531 CD |
6266 | (setq syslibp (idlwave-any-syslib (cdr twins))) |
6267 | (not (equal 1 syslibp))) | |
52a244eb S |
6268 | ;; Its a compiled syslib, so we need to remove the system entry |
6269 | (setq twins (cdr twins))) | |
6270 | (if with-file | |
6271 | (setq twins (delq nil | |
6272 | (mapcar (lambda (x) | |
6273 | (if (nth 1 (nth 3 x)) x)) | |
6274 | twins))))) | |
15e42531 CD |
6275 | (car twins))) |
6276 | ||
4b1aaa8b | 6277 | (defun idlwave-best-rinfo-assoc (name type class list &optional with-file |
52a244eb | 6278 | keep-system) |
15e42531 CD |
6279 | "Like `idlwave-best-rinfo-assq', but sintern strings first." |
6280 | (idlwave-best-rinfo-assq | |
6281 | (idlwave-sintern-routine-or-method name class) | |
52a244eb | 6282 | type (idlwave-sintern-class class) list with-file keep-system)) |
15e42531 CD |
6283 | |
6284 | (defun idlwave-any-syslib (entries) | |
6285 | "Does the entry list ENTRIES contain a syslib entry? | |
6286 | If yes, return the index (>=1)." | |
6287 | (let (file (cnt 0)) | |
6288 | (catch 'exit | |
6289 | (while entries | |
6290 | (incf cnt) | |
52a244eb S |
6291 | (setq file (idlwave-routine-source-file (nth 3 (car entries)))) |
6292 | (if (and file (idlwave-syslib-p file)) | |
15e42531 CD |
6293 | (throw 'exit cnt) |
6294 | (setq entries (cdr entries)))) | |
6295 | nil))) | |
6296 | ||
f32b3b91 CD |
6297 | (defun idlwave-all-assq (key list) |
6298 | "Return a list of all associations of Key in LIST." | |
6299 | (let (rtn elt) | |
6300 | (while (setq elt (assq key list)) | |
6301 | (push elt rtn) | |
6302 | (setq list (cdr (memq elt list)))) | |
6303 | (nreverse rtn))) | |
6304 | ||
6305 | (defun idlwave-all-method-classes (method &optional type) | |
6306 | "Return all classes which have a method METHOD. TYPE is 'fun or 'pro. | |
6307 | When TYPE is not specified, both procedures and functions will be considered." | |
6308 | (if (null method) | |
15e42531 | 6309 | (mapcar 'car (idlwave-class-alist)) |
f32b3b91 | 6310 | (let (rtn) |
8ffcfb27 GM |
6311 | (mapc (lambda (x) |
6312 | (and (nth 2 x) | |
6313 | (or (not type) | |
6314 | (eq type (nth 1 x))) | |
6315 | (push (nth 2 x) rtn))) | |
6316 | (idlwave-all-assq method (idlwave-routines))) | |
f32b3b91 CD |
6317 | (idlwave-uniquify rtn)))) |
6318 | ||
6319 | (defun idlwave-all-method-keyword-classes (method keyword &optional type) | |
6320 | "Return all classes which have a method METHOD with keyword KEYWORD. | |
6321 | TYPE is 'fun or 'pro. | |
6322 | When TYPE is not specified, both procedures and functions will be considered." | |
6323 | (if (or (null method) | |
6324 | (null keyword)) | |
6325 | nil | |
6326 | (let (rtn) | |
8ffcfb27 GM |
6327 | (mapc (lambda (x) |
6328 | (and (nth 2 x) ; non-nil class | |
6329 | (or (not type) ; correct or unspecified type | |
6330 | (eq type (nth 1 x))) | |
6331 | (assoc keyword (idlwave-entry-keywords x)) | |
6332 | (push (nth 2 x) rtn))) | |
6333 | (idlwave-all-assq method (idlwave-routines))) | |
f32b3b91 CD |
6334 | (idlwave-uniquify rtn)))) |
6335 | ||
05a1abfc CD |
6336 | (defun idlwave-members-only (list club) |
6337 | "Return list of all elements in LIST which are also in CLUB." | |
6338 | (let (rtn) | |
6339 | (while list | |
6340 | (if (member (car list) club) | |
6341 | (setq rtn (cons (car list) rtn))) | |
6342 | (setq list (cdr list))) | |
6343 | (nreverse rtn))) | |
6344 | ||
6345 | (defun idlwave-nonmembers-only (list club) | |
6346 | "Return list of all elements in LIST which are not in CLUB." | |
6347 | (let (rtn) | |
6348 | (while list | |
6349 | (if (member (car list) club) | |
6350 | nil | |
6351 | (setq rtn (cons (car list) rtn))) | |
6352 | (setq list (cdr list))) | |
6353 | (nreverse rtn))) | |
6354 | ||
5e72c6b2 S |
6355 | (defun idlwave-explicit-class-listed (info) |
6356 | "Return whether or not the class is listed explicitly, ala a->b::c. | |
6357 | INFO is as returned by idlwave-what-function or -procedure." | |
6358 | (let ((apos (nth 3 info))) | |
6359 | (if apos | |
6360 | (save-excursion (goto-char apos) | |
6361 | (looking-at "->[a-zA-Z][a-zA-Z0-9$_]*::"))))) | |
6362 | ||
76959b77 S |
6363 | (defvar idlwave-determine-class-special nil |
6364 | "List of special functions for determining class. | |
6365 | Must accept two arguments: `apos' and `info'") | |
6366 | ||
f32b3b91 | 6367 | (defun idlwave-determine-class (info type) |
4b1aaa8b | 6368 | ;; Determine the class of a routine call. |
76959b77 S |
6369 | ;; INFO is the `cw-list' structure as returned by idlwave-where. |
6370 | ;; The second element in this structure is the class. When nil, we | |
6371 | ;; return nil. When t, try to get the class from text properties at | |
6372 | ;; the arrow. When the object is "self", we use the class of the | |
6373 | ;; current routine. otherwise prompt the user for a class name. | |
6374 | ;; Also stores the selected class as a text property at the arrow. | |
f32b3b91 CD |
6375 | ;; TYPE is 'fun or 'pro. |
6376 | (let* ((class (nth 2 info)) | |
6377 | (apos (nth 3 info)) | |
6378 | (nassoc (assoc (if (stringp (car info)) | |
6379 | (upcase (car info)) | |
6380 | (car info)) | |
6381 | idlwave-query-class)) | |
6382 | (dassoc (assq (if (car info) 'keyword-default 'method-default) | |
6383 | idlwave-query-class)) | |
6384 | (query (cond (nassoc (cdr nassoc)) | |
6385 | (dassoc (cdr dassoc)) | |
6386 | (t t))) | |
6387 | (arrow (and apos (string= (buffer-substring apos (+ 2 apos)) "->"))) | |
4b1aaa8b | 6388 | (is-self |
15e42531 CD |
6389 | (and arrow |
6390 | (save-excursion (goto-char apos) | |
6391 | (forward-word -1) | |
6392 | (let ((case-fold-search t)) | |
6393 | (looking-at "self\\>"))))) | |
f32b3b91 | 6394 | (force-query idlwave-force-class-query) |
76959b77 | 6395 | store special-class class-alist) |
f32b3b91 CD |
6396 | (cond |
6397 | ((null class) nil) | |
6398 | ((eq t class) | |
6399 | ;; There is an object which would like to know its class | |
6400 | (if (and arrow (get-text-property apos 'idlwave-class) | |
6401 | idlwave-store-inquired-class | |
6402 | (not force-query)) | |
6403 | (setq class (get-text-property apos 'idlwave-class) | |
6404 | class (idlwave-sintern-class class))) | |
76959b77 S |
6405 | (if (and (eq t class) is-self) |
6406 | (setq class (or (nth 2 (idlwave-current-routine)) class))) | |
6407 | ||
6408 | ;; Before prompting, try any special class determination routines | |
4b1aaa8b | 6409 | (when (and (eq t class) |
76959b77 S |
6410 | idlwave-determine-class-special |
6411 | (not force-query)) | |
4b1aaa8b | 6412 | (setq special-class |
76959b77 | 6413 | (idlwave-call-special idlwave-determine-class-special apos)) |
4b1aaa8b | 6414 | (if special-class |
76959b77 S |
6415 | (setq class (idlwave-sintern-class special-class) |
6416 | store idlwave-store-inquired-class))) | |
4b1aaa8b | 6417 | |
76959b77 | 6418 | ;; Prompt for a class, if we need to |
f32b3b91 CD |
6419 | (when (and (eq class t) |
6420 | (or force-query query)) | |
4b1aaa8b | 6421 | (setq class-alist |
f32b3b91 CD |
6422 | (mapcar 'list (idlwave-all-method-classes (car info) type))) |
6423 | (setq class | |
6424 | (idlwave-sintern-class | |
6425 | (cond | |
6426 | ((and (= (length class-alist) 0) (not force-query)) | |
6427 | (error "No classes available with method %s" (car info))) | |
6428 | ((and (= (length class-alist) 1) (not force-query)) | |
6429 | (car (car class-alist))) | |
4b1aaa8b | 6430 | (t |
f32b3b91 | 6431 | (setq store idlwave-store-inquired-class) |
4b1aaa8b | 6432 | (idlwave-completing-read |
f32b3b91 CD |
6433 | (format "Class%s: " (if (stringp (car info)) |
6434 | (format " for %s method %s" | |
6435 | type (car info)) | |
6436 | "")) | |
6437 | class-alist nil nil nil 'idlwave-class-history)))))) | |
76959b77 S |
6438 | |
6439 | ;; Store it, if requested | |
f32b3b91 CD |
6440 | (when (and class (not (eq t class))) |
6441 | ;; We have a real class here | |
6442 | (when (and store arrow) | |
76959b77 | 6443 | (condition-case () |
4b1aaa8b PE |
6444 | (add-text-properties |
6445 | apos (+ apos 2) | |
6446 | `(idlwave-class ,class face ,idlwave-class-arrow-face | |
76959b77 S |
6447 | rear-nonsticky t)) |
6448 | (error nil))) | |
f32b3b91 CD |
6449 | (setf (nth 2 info) class)) |
6450 | ;; Return the class | |
6451 | class) | |
6452 | ;; Default as fallback | |
6453 | (t class)))) | |
6454 | ||
6455 | (defvar type-selector) | |
6456 | (defvar class-selector) | |
6457 | (defvar method-selector) | |
05a1abfc | 6458 | (defvar super-classes) |
f32b3b91 CD |
6459 | (defun idlwave-selector (a) |
6460 | (and (eq (nth 1 a) type-selector) | |
6461 | (or (and (nth 2 a) (eq class-selector t)) | |
05a1abfc | 6462 | (eq (nth 2 a) class-selector) |
52a244eb S |
6463 | (memq (nth 2 a) super-classes)))) |
6464 | ||
6465 | (defun idlwave-add-file-link-selector (a) | |
6466 | ;; Record a file link, if any, for the tested names during selection. | |
6467 | (let ((sel (idlwave-selector a)) file) | |
6468 | (if (and sel (setq file (idlwave-entry-has-help a))) | |
6469 | (push (cons (car a) file) idlwave-completion-help-links)) | |
6470 | sel)) | |
6471 | ||
f32b3b91 CD |
6472 | |
6473 | (defun idlwave-where () | |
4b1aaa8b | 6474 | "Find out where we are. |
f32b3b91 | 6475 | The return value is a list with the following stuff: |
5e72c6b2 | 6476 | \(PRO-LIST FUNC-LIST COMPLETE-WHAT CW-LIST LAST-CHAR) |
f32b3b91 CD |
6477 | |
6478 | PRO-LIST (PRO POINT CLASS ARROW) | |
6479 | FUNC-LIST (FUNC POINT CLASS ARROW) | |
6480 | COMPLETE-WHAT a symbol indicating what kind of completion makes sense here | |
4b1aaa8b | 6481 | CW-LIST (PRO-OR-FUNC POINT CLASS ARROW) Like PRO-LIST, for what can |
5e72c6b2 | 6482 | be completed here. |
f32b3b91 CD |
6483 | LAST-CHAR last relevant character before point (non-white non-comment, |
6484 | not part of current identifier or leading slash). | |
6485 | ||
6486 | In the lists, we have these meanings: | |
6487 | PRO: Procedure name | |
6488 | FUNC: Function name | |
6489 | POINT: Where is this | |
6490 | CLASS: What class has the routine (nil=no, t=is method, but class unknown) | |
5e72c6b2 | 6491 | ARROW: Location of the arrow" |
f32b3b91 | 6492 | (idlwave-routines) |
4b1aaa8b | 6493 | (let* (;(bos (save-excursion (idlwave-beginning-of-statement) (point))) |
15e42531 | 6494 | (bos (save-excursion (idlwave-start-of-substatement 'pre) (point))) |
f32b3b91 CD |
6495 | (func-entry (idlwave-what-function bos)) |
6496 | (func (car func-entry)) | |
6497 | (func-class (nth 1 func-entry)) | |
6498 | (func-arrow (nth 2 func-entry)) | |
6499 | (func-point (or (nth 3 func-entry) 0)) | |
6500 | (func-level (or (nth 4 func-entry) 0)) | |
6501 | (pro-entry (idlwave-what-procedure bos)) | |
6502 | (pro (car pro-entry)) | |
6503 | (pro-class (nth 1 pro-entry)) | |
6504 | (pro-arrow (nth 2 pro-entry)) | |
6505 | (pro-point (or (nth 3 pro-entry) 0)) | |
6506 | (last-char (idlwave-last-valid-char)) | |
6507 | (case-fold-search t) | |
52a244eb | 6508 | (match-string (buffer-substring bos (point))) |
f32b3b91 CD |
6509 | cw cw-mod cw-arrow cw-class cw-point) |
6510 | (if (< func-point pro-point) (setq func nil)) | |
6511 | (cond | |
15e42531 | 6512 | ((string-match "\\`[ \t]*\\(pro\\|function\\)[ \t]+[a-zA-Z0-9_]*\\'" |
52a244eb | 6513 | match-string) |
15e42531 | 6514 | (setq cw 'class)) |
4b1aaa8b PE |
6515 | ((string-match |
6516 | "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)?\\'" | |
52a244eb S |
6517 | (if (> pro-point 0) |
6518 | (buffer-substring pro-point (point)) | |
6519 | match-string)) | |
f32b3b91 CD |
6520 | (setq cw 'procedure cw-class pro-class cw-point pro-point |
6521 | cw-arrow pro-arrow)) | |
6522 | ((string-match "\\`[ \t]*\\(pro\\|function\\)\\>" | |
52a244eb | 6523 | match-string) |
f32b3b91 | 6524 | nil) |
05a1abfc | 6525 | ((string-match "OBJ_NEW([ \t]*['\"]\\([a-zA-Z0-9$_]*\\)?\\'" |
52a244eb | 6526 | match-string) |
4b1aaa8b | 6527 | (setq cw 'class)) |
05a1abfc | 6528 | ((string-match "\\<inherits\\s-+\\([a-zA-Z0-9$_]*\\)?\\'" |
52a244eb | 6529 | match-string) |
4b1aaa8b PE |
6530 | (setq cw 'class)) |
6531 | ((and func | |
f32b3b91 CD |
6532 | (> func-point pro-point) |
6533 | (= func-level 1) | |
6534 | (memq last-char '(?\( ?,))) | |
6535 | (setq cw 'function-keyword cw-mod func cw-point func-point | |
6536 | cw-class func-class cw-arrow func-arrow)) | |
6537 | ((and pro (eq last-char ?,)) | |
6538 | (setq cw 'procedure-keyword cw-mod pro cw-point pro-point | |
6539 | cw-class pro-class cw-arrow pro-arrow)) | |
6540 | ; ((member last-char '(?\' ?\) ?\] ?!)) | |
6541 | ; ;; after these chars, a function makes no sense | |
6542 | ; ;; FIXME: I am sure there can be more in this list | |
6543 | ; ;; FIXME: Do we want to do this at all? | |
6544 | ; nil) | |
6545 | ;; Everywhere else we try a function. | |
6546 | (t | |
6547 | (setq cw 'function) | |
6548 | (save-excursion | |
52a244eb | 6549 | (if (re-search-backward "->[ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\s-*\\)?\\(\\([$a-zA-Z0-9_]+\\)::\\)?[$a-zA-Z0-9_]*\\=" bos t) |
76959b77 | 6550 | (setq cw-arrow (copy-marker (match-beginning 0)) |
52a244eb S |
6551 | cw-class (if (match-end 4) |
6552 | (idlwave-sintern-class (match-string 4)) | |
5e72c6b2 | 6553 | t)))))) |
f32b3b91 CD |
6554 | (list (list pro pro-point pro-class pro-arrow) |
6555 | (list func func-point func-class func-arrow) | |
6556 | cw | |
6557 | (list cw-mod cw-point cw-class cw-arrow) | |
6558 | last-char))) | |
6559 | ||
6560 | (defun idlwave-this-word (&optional class) | |
6561 | ;; Grab the word around point. CLASS is for the `skip-chars=...' functions | |
52a244eb | 6562 | (setq class (or class "a-zA-Z0-9$_.")) |
f32b3b91 | 6563 | (save-excursion |
52a244eb | 6564 | (buffer-substring |
f32b3b91 CD |
6565 | (progn (skip-chars-backward class) (point)) |
6566 | (progn (skip-chars-forward class) (point))))) | |
6567 | ||
f32b3b91 CD |
6568 | (defun idlwave-what-function (&optional bound) |
6569 | ;; Find out if point is within the argument list of a function. | |
76959b77 S |
6570 | ;; The return value is ("function-name" class arrow-start (point) level). |
6571 | ;; Level is 1 on the top level parentheses, higher further down. | |
f32b3b91 CD |
6572 | |
6573 | ;; If the optional BOUND is an integer, bound backwards directed | |
6574 | ;; searches to this point. | |
6575 | ||
6576 | (catch 'exit | |
4b1aaa8b | 6577 | (let (pos |
f32b3b91 | 6578 | func-point |
f32b3b91 CD |
6579 | (cnt 0) |
6580 | func arrow-start class) | |
15e42531 CD |
6581 | (idlwave-with-special-syntax |
6582 | (save-restriction | |
6583 | (save-excursion | |
6584 | (narrow-to-region (max 1 (or bound 0)) (point-max)) | |
6585 | ;; move back out of the current parenthesis | |
6586 | (while (condition-case nil | |
6587 | (progn (up-list -1) t) | |
6588 | (error nil)) | |
6589 | (setq pos (point)) | |
6590 | (incf cnt) | |
6591 | (when (and (= (following-char) ?\() | |
4b1aaa8b | 6592 | (re-search-backward |
15e42531 CD |
6593 | "\\(::\\|\\<\\)\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\=" |
6594 | bound t)) | |
6595 | (setq func (match-string 2) | |
6596 | func-point (goto-char (match-beginning 2)) | |
6597 | pos func-point) | |
4b1aaa8b | 6598 | (if (re-search-backward |
15e42531 | 6599 | "->[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\=" bound t) |
76959b77 | 6600 | (setq arrow-start (copy-marker (match-beginning 0)) |
15e42531 | 6601 | class (or (match-string 2) t))) |
4b1aaa8b PE |
6602 | (throw |
6603 | 'exit | |
15e42531 CD |
6604 | (list |
6605 | (idlwave-sintern-routine-or-method func class) | |
6606 | (idlwave-sintern-class class) | |
6607 | arrow-start func-point cnt))) | |
6608 | (goto-char pos)) | |
6609 | (throw 'exit nil))))))) | |
f32b3b91 CD |
6610 | |
6611 | (defun idlwave-what-procedure (&optional bound) | |
6612 | ;; Find out if point is within the argument list of a procedure. | |
6613 | ;; The return value is ("procedure-name" class arrow-pos (point)). | |
6614 | ||
6615 | ;; If the optional BOUND is an integer, bound backwards directed | |
6616 | ;; searches to this point. | |
6617 | (let ((pos (point)) pro-point | |
6618 | pro class arrow-start string) | |
4b1aaa8b | 6619 | (save-excursion |
05a1abfc | 6620 | ;;(idlwave-beginning-of-statement) |
15e42531 | 6621 | (idlwave-start-of-substatement 'pre) |
f32b3b91 | 6622 | (setq string (buffer-substring (point) pos)) |
4b1aaa8b | 6623 | (if (string-match |
76959b77 S |
6624 | "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\(,\\|\\'\\)" string) |
6625 | (setq pro (match-string 1 string) | |
6626 | pro-point (+ (point) (match-beginning 1))) | |
f32b3b91 CD |
6627 | (if (and (idlwave-skip-object) |
6628 | (setq string (buffer-substring (point) pos)) | |
4b1aaa8b PE |
6629 | (string-match |
6630 | "\\`[ \t]*\\(->\\)[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\([a-zA-Z][a-zA-Z0-9$_]*\\)?[ \t]*\\(,\\|\\(\\$\\s *\\(;.*\\)?\\)?$\\)" | |
52a244eb | 6631 | string)) |
f32b3b91 CD |
6632 | (setq pro (if (match-beginning 4) |
6633 | (match-string 4 string)) | |
6634 | pro-point (if (match-beginning 4) | |
6635 | (+ (point) (match-beginning 4)) | |
6636 | pos) | |
76959b77 | 6637 | arrow-start (copy-marker (+ (point) (match-beginning 1))) |
f32b3b91 CD |
6638 | class (or (match-string 3 string) t))))) |
6639 | (list (idlwave-sintern-routine-or-method pro class) | |
6640 | (idlwave-sintern-class class) | |
6641 | arrow-start | |
6642 | pro-point))) | |
6643 | ||
6644 | (defun idlwave-skip-object () | |
6645 | ;; If there is an object at point, move over it and return t. | |
6646 | (let ((pos (point))) | |
6647 | (if (catch 'exit | |
6648 | (save-excursion | |
6649 | (skip-chars-forward " ") ; white space | |
6650 | (skip-chars-forward "*") ; de-reference | |
6651 | (cond | |
6652 | ((looking-at idlwave-identifier) | |
6653 | (goto-char (match-end 0))) | |
6654 | ((eq (following-char) ?\() | |
6655 | nil) | |
6656 | (t (throw 'exit nil))) | |
6657 | (catch 'endwhile | |
6658 | (while t | |
6659 | (cond ((eq (following-char) ?.) | |
6660 | (forward-char 1) | |
6661 | (if (not (looking-at idlwave-identifier)) | |
6662 | (throw 'exit nil)) | |
6663 | (goto-char (match-end 0))) | |
6664 | ((memq (following-char) '(?\( ?\[)) | |
6665 | (condition-case nil | |
6666 | (forward-list 1) | |
6667 | (error (throw 'exit nil)))) | |
6668 | (t (throw 'endwhile t))))) | |
6669 | (if (looking-at "[ \t]*->") | |
6670 | (throw 'exit (setq pos (match-beginning 0))) | |
6671 | (throw 'exit nil)))) | |
6672 | (goto-char pos) | |
6673 | nil))) | |
4b1aaa8b | 6674 | |
f32b3b91 CD |
6675 | (defun idlwave-last-valid-char () |
6676 | "Return the last character before point which is not white or a comment | |
6677 | and also not part of the current identifier. Since we do this in | |
6678 | order to identify places where keywords are, we consider the initial | |
6679 | `/' of a keyword as part of the identifier. | |
6680 | This function is not general, can only be used for completion stuff." | |
6681 | (catch 'exit | |
6682 | (save-excursion | |
6683 | ;; skip the current identifier | |
6684 | (skip-chars-backward "a-zA-Z0-9_$") | |
6685 | ;; also skip a leading slash which might be belong to the keyword | |
6686 | (if (eq (preceding-char) ?/) | |
6687 | (backward-char 1)) | |
6688 | ;; FIXME: does not check if this is a valid identifier | |
6689 | (while t | |
6690 | (skip-chars-backward " \t") | |
6691 | (cond | |
6692 | ((memq (preceding-char) '(?\; ?\$)) (throw 'exit nil)) | |
6693 | ((eq (preceding-char) ?\n) | |
6694 | (beginning-of-line 0) | |
3938cb82 | 6695 | (if (looking-at "\\([^\n]*\\)\\$[ \t]*\\(;[^\n]*\\)?\n") |
f32b3b91 CD |
6696 | ;; continuation line |
6697 | (goto-char (match-end 1)) | |
6698 | (throw 'exit nil))) | |
6699 | (t (throw 'exit (preceding-char)))))))) | |
6700 | ||
6701 | (defvar idlwave-complete-after-success-form nil | |
6702 | "A form to evaluate after successful completion.") | |
6703 | (defvar idlwave-complete-after-success-form-force nil | |
6704 | "A form to evaluate after completion selection in *Completions* buffer.") | |
6705 | (defconst idlwave-completion-mark (make-marker) | |
6706 | "A mark pointing to the beginning of the completion string.") | |
6707 | ||
6708 | (defun idlwave-complete-in-buffer (type stype list selector prompt isa | |
52a244eb S |
6709 | &optional prepare-display-function |
6710 | special-selector) | |
f32b3b91 | 6711 | "Perform TYPE completion of word before point against LIST. |
76959b77 | 6712 | SELECTOR is the PREDICATE argument for the completion function. Show |
52a244eb S |
6713 | PROMPT in echo area. TYPE is one of the intern types, e.g. 'function, |
6714 | 'procedure, 'class-tag, 'keyword, 'sysvar, etc.. SPECIAL-SELECTOR is | |
6715 | used only once, for `all-completions', and can be used to, e.g., | |
6716 | accumulate information on matching completions." | |
f32b3b91 CD |
6717 | (let* ((completion-ignore-case t) |
6718 | beg (end (point)) slash part spart completion all-completions | |
6719 | dpart dcompletion) | |
6720 | ||
6721 | (unless list | |
6722 | (error (concat prompt ": No completions available"))) | |
6723 | ||
6724 | ;; What is already in the buffer? | |
6725 | (save-excursion | |
6726 | (skip-chars-backward "a-zA-Z0-9_$") | |
6727 | (setq slash (eq (preceding-char) ?/) | |
6728 | beg (point) | |
6729 | idlwave-complete-after-success-form | |
6730 | (list 'idlwave-after-successful-completion | |
6731 | (list 'quote type) slash beg) | |
6732 | idlwave-complete-after-success-form-force | |
6733 | (list 'idlwave-after-successful-completion | |
6734 | (list 'quote type) slash (list 'quote 'force)))) | |
6735 | ||
6736 | ;; Try a completion | |
6737 | (setq part (buffer-substring beg end) | |
6738 | dpart (downcase part) | |
6739 | spart (idlwave-sintern stype part) | |
6740 | completion (try-completion part list selector) | |
52a244eb S |
6741 | dcompletion (if (stringp completion) (downcase completion)) |
6742 | idlwave-completion-help-links nil) | |
f32b3b91 CD |
6743 | (cond |
6744 | ((null completion) | |
6745 | ;; nothing available. | |
76959b77 | 6746 | (error (concat prompt ": no completion for \"%s\"") part)) |
f32b3b91 CD |
6747 | ((and (not (equal dpart dcompletion)) |
6748 | (not (eq t completion))) | |
6749 | ;; We can add something | |
6750 | (delete-region beg end) | |
6751 | (if (and (string= part dpart) | |
6752 | (or (not (string= part "")) | |
6753 | idlwave-complete-empty-string-as-lower-case) | |
6754 | (not idlwave-completion-force-default-case)) | |
6755 | (insert dcompletion) | |
6756 | (insert completion)) | |
6757 | (if (eq t (try-completion completion list selector)) | |
6758 | ;; Now this is a unique match | |
6759 | (idlwave-after-successful-completion type slash beg)) | |
6760 | t) | |
6761 | ((or (eq completion t) | |
52a244eb | 6762 | (and (= 1 (length (setq all-completions |
f32b3b91 | 6763 | (idlwave-uniquify |
4b1aaa8b PE |
6764 | (all-completions part list |
6765 | (or special-selector | |
52a244eb S |
6766 | selector)))))) |
6767 | (equal dpart dcompletion))) | |
f32b3b91 CD |
6768 | ;; This is already complete |
6769 | (idlwave-after-successful-completion type slash beg) | |
6770 | (message "%s is already the complete %s" part isa) | |
6771 | nil) | |
4b1aaa8b | 6772 | (t |
f32b3b91 CD |
6773 | ;; We cannot add something - offer a list. |
6774 | (message "Making completion list...") | |
4b1aaa8b | 6775 | |
52a244eb | 6776 | (unless idlwave-completion-help-links ; already set somewhere? |
9001c33f GM |
6777 | (mapc (lambda (x) ; Pass link prop through to highlight-linked |
6778 | (let ((link (get-text-property 0 'link (car x)))) | |
6779 | (if link | |
6780 | (push (cons (car x) link) | |
6781 | idlwave-completion-help-links)))) | |
6782 | list)) | |
f32b3b91 | 6783 | (let* ((list all-completions) |
05a1abfc | 6784 | ;; "complete" means, this is already a valid completion |
f32b3b91 | 6785 | (complete (memq spart all-completions)) |
52a244eb S |
6786 | (completion-highlight-first-word-only t)) ; XEmacs |
6787 | ; (completion-fixup-function ; Emacs | |
6788 | ; (lambda () (and (eq (preceding-char) ?>) | |
6789 | ; (re-search-backward " <" beg t))))) | |
4b1aaa8b | 6790 | |
f32b3b91 CD |
6791 | (setq list (sort list (lambda (a b) |
6792 | (string< (downcase a) (downcase b))))) | |
6793 | (if prepare-display-function | |
6794 | (setq list (funcall prepare-display-function list))) | |
6795 | (if (and (string= part dpart) | |
6796 | (or (not (string= part "")) | |
6797 | idlwave-complete-empty-string-as-lower-case) | |
6798 | (not idlwave-completion-force-default-case)) | |
6799 | (setq list (mapcar (lambda (x) | |
4b1aaa8b | 6800 | (if (listp x) |
f32b3b91 CD |
6801 | (setcar x (downcase (car x))) |
6802 | (setq x (downcase x))) | |
6803 | x) | |
6804 | list))) | |
6805 | (idlwave-display-completion-list list prompt beg complete)) | |
6806 | t)))) | |
6807 | ||
6808 | (defun idlwave-complete-class () | |
6809 | "Complete a class at point." | |
6810 | (interactive) | |
6811 | ;; Call `idlwave-routines' to make sure the class list will be available | |
6812 | (idlwave-routines) | |
15e42531 CD |
6813 | ;; Check for the special case of completing empty string after pro/function |
6814 | (if (let ((case-fold-search t)) | |
6815 | (save-excursion | |
6816 | (and | |
6817 | (re-search-backward "\\<\\(pro\\|function\\)[ \t]+\\=" | |
6818 | (- (point) 15) t) | |
6819 | (goto-char (point-min)) | |
4b1aaa8b | 6820 | (re-search-forward |
15e42531 CD |
6821 | "^[ \t]*\\(pro\\|function\\)[ \t]+\\([a-zA-Z0-9_]+::\\)" nil t)))) |
6822 | ;; Yank the full class specification | |
6823 | (insert (match-string 2)) | |
52a244eb | 6824 | ;; Do the completion, using list gathered from `idlwave-routines' |
4b1aaa8b PE |
6825 | (idlwave-complete-in-buffer |
6826 | 'class 'class (idlwave-class-alist) nil | |
52a244eb S |
6827 | "Select a class" "class" |
6828 | '(lambda (list) ;; Push it to help-links if system help available | |
6829 | (mapcar (lambda (x) | |
6830 | (let* ((entry (idlwave-class-info x)) | |
6831 | (link (nth 1 (assq 'link entry)))) | |
4b1aaa8b | 6832 | (if link (push (cons x link) |
52a244eb S |
6833 | idlwave-completion-help-links)) |
6834 | x)) | |
6835 | list))))) | |
f32b3b91 | 6836 | |
76959b77 | 6837 | (defun idlwave-attach-classes (list type show-classes) |
05a1abfc | 6838 | ;; Attach the proper class list to a LIST of completion items. |
76959b77 S |
6839 | ;; TYPE, when 'kwd, shows classes for method keywords, when |
6840 | ;; 'class-tag, for class tags, and otherwise for methods. | |
f32b3b91 | 6841 | ;; SHOW-CLASSES is the value of `idlwave-completion-show-classes'. |
76959b77 S |
6842 | (if (or (null show-classes) ; don't want to see classes |
6843 | (null class-selector) ; not a method call | |
4b1aaa8b | 6844 | (and |
76959b77 S |
6845 | (stringp class-selector) ; the class is already known |
6846 | (not super-classes))) ; no possibilities for inheritance | |
6847 | ;; In these cases, we do not have to do anything | |
6848 | list | |
05a1abfc CD |
6849 | (let* ((do-prop (and (>= show-classes 0) |
6850 | (>= emacs-major-version 21))) | |
f32b3b91 | 6851 | (do-buf (not (= show-classes 0))) |
76959b77 | 6852 | ;; (do-dots (featurep 'xemacs)) |
05a1abfc | 6853 | (do-dots t) |
76959b77 | 6854 | (inherit (if (and (not (eq type 'class-tag)) super-classes) |
05a1abfc | 6855 | (cons class-selector super-classes))) |
f32b3b91 CD |
6856 | (max (abs show-classes)) |
6857 | (lmax (if do-dots (apply 'max (mapcar 'length list)))) | |
6858 | classes nclasses class-info space) | |
4b1aaa8b | 6859 | (mapcar |
f32b3b91 CD |
6860 | (lambda (x) |
6861 | ;; get the classes | |
76959b77 S |
6862 | (if (eq type 'class-tag) |
6863 | ;; Just one class for tags | |
6864 | (setq classes | |
4b1aaa8b | 6865 | (list |
76959b77 | 6866 | (idlwave-class-or-superclass-with-tag class-selector x))) |
52a244eb | 6867 | ;; Multiple classes for method or method-keyword |
76959b77 S |
6868 | (setq classes |
6869 | (if (eq type 'kwd) | |
6870 | (idlwave-all-method-keyword-classes | |
6871 | method-selector x type-selector) | |
6872 | (idlwave-all-method-classes x type-selector))) | |
6873 | (if inherit | |
4b1aaa8b | 6874 | (setq classes |
76959b77 S |
6875 | (delq nil |
6876 | (mapcar (lambda (x) (if (memq x inherit) x nil)) | |
6877 | classes))))) | |
f32b3b91 CD |
6878 | (setq nclasses (length classes)) |
6879 | ;; Make the separator between item and class-info | |
6880 | (if do-dots | |
6881 | (setq space (concat " " (make-string (- lmax (length x)) ?.))) | |
6882 | (setq space " ")) | |
6883 | (if do-buf | |
6884 | ;; We do want info in the buffer | |
6885 | (if (<= nclasses max) | |
6886 | (setq class-info (concat | |
6887 | space | |
6888 | "<" (mapconcat 'identity classes ",") ">")) | |
6889 | (setq class-info (format "%s<%d classes>" space nclasses))) | |
6890 | (setq class-info nil)) | |
6891 | (when do-prop | |
6892 | ;; We do want properties | |
6893 | (setq x (copy-sequence x)) | |
6894 | (put-text-property 0 (length x) | |
52a244eb S |
6895 | 'help-echo (mapconcat 'identity classes " ") |
6896 | x)) | |
f32b3b91 CD |
6897 | (if class-info |
6898 | (list x class-info) | |
6899 | x)) | |
6900 | list)))) | |
6901 | ||
6902 | (defun idlwave-attach-method-classes (list) | |
6903 | ;; Call idlwave-attach-classes with method parameters | |
76959b77 | 6904 | (idlwave-attach-classes list 'method idlwave-completion-show-classes)) |
f32b3b91 CD |
6905 | (defun idlwave-attach-keyword-classes (list) |
6906 | ;; Call idlwave-attach-classes with keyword parameters | |
76959b77 S |
6907 | (idlwave-attach-classes list 'kwd idlwave-completion-show-classes)) |
6908 | (defun idlwave-attach-class-tag-classes (list) | |
6909 | ;; Call idlwave-attach-classes with class structure tags | |
6910 | (idlwave-attach-classes list 'class-tag idlwave-completion-show-classes)) | |
4b1aaa8b | 6911 | |
f32b3b91 CD |
6912 | |
6913 | ;;---------------------------------------------------------------------- | |
6914 | ;;---------------------------------------------------------------------- | |
6915 | ;;---------------------------------------------------------------------- | |
6916 | ;;---------------------------------------------------------------------- | |
6917 | ;;---------------------------------------------------------------------- | |
5e72c6b2 S |
6918 | (defvar rtn) |
6919 | (defun idlwave-pset (item) | |
6920 | (set 'rtn item)) | |
6921 | ||
6922 | (defun idlwave-popup-select (ev list title &optional sort) | |
6923 | "Select an item in LIST with a popup menu. | |
6924 | TITLE is the title to put atop the popup. If SORT is non-nil, | |
6925 | sort the list before displaying" | |
6926 | (let ((maxpopup idlwave-max-popup-menu-items) | |
6927 | rtn menu resp) | |
6928 | (cond ((null list)) | |
6929 | ((= 1 (length list)) | |
6930 | (setq rtn (car list))) | |
6931 | ((featurep 'xemacs) | |
4b1aaa8b | 6932 | (if sort (setq list (sort list (lambda (a b) |
5e72c6b2 S |
6933 | (string< (upcase a) (upcase b)))))) |
6934 | (setq menu | |
6935 | (append (list title) | |
6936 | (mapcar (lambda (x) (vector x (list 'idlwave-pset | |
6937 | x))) | |
6938 | list))) | |
6939 | (setq menu (idlwave-split-menu-xemacs menu maxpopup)) | |
6940 | (setq resp (get-popup-menu-response menu)) | |
6941 | (funcall (event-function resp) (event-object resp))) | |
6942 | (t | |
4b1aaa8b | 6943 | (if sort (setq list (sort list (lambda (a b) |
5e72c6b2 S |
6944 | (string< (upcase a) (upcase b)))))) |
6945 | (setq menu (cons title | |
6946 | (list | |
6947 | (append (list "") | |
6948 | (mapcar (lambda(x) (cons x x)) list))))) | |
6949 | (setq menu (idlwave-split-menu-emacs menu maxpopup)) | |
6950 | (setq rtn (x-popup-menu ev menu)))) | |
6951 | rtn)) | |
6952 | ||
6953 | (defun idlwave-split-menu-xemacs (menu N) | |
6954 | "Split the MENU into submenus of maximum length N." | |
6955 | (if (<= (length menu) (1+ N)) | |
6956 | ;; No splitting needed | |
6957 | menu | |
6958 | (let* ((title (car menu)) | |
6959 | (entries (cdr menu)) | |
6960 | (menu (list title)) | |
6961 | (cnt 0) | |
6962 | (nextmenu nil)) | |
6963 | (while entries | |
6964 | (while (and entries (< cnt N)) | |
6965 | (setq cnt (1+ cnt) | |
6966 | nextmenu (cons (car entries) nextmenu) | |
6967 | entries (cdr entries))) | |
6968 | (setq nextmenu (nreverse nextmenu)) | |
6969 | (setq nextmenu (cons (format "%s...%s" | |
6970 | (aref (car nextmenu) 0) | |
6971 | (aref (nth (1- cnt) nextmenu) 0)) | |
6972 | nextmenu)) | |
6973 | (setq menu (cons nextmenu menu) | |
6974 | nextmenu nil | |
6975 | cnt 0)) | |
6976 | (nreverse menu)))) | |
6977 | ||
6978 | (defun idlwave-split-menu-emacs (menu N) | |
6979 | "Split the MENU into submenus of maximum length N." | |
6980 | (if (<= (length (nth 1 menu)) (1+ N)) | |
6981 | ;; No splitting needed | |
6982 | menu | |
6983 | (let* ((title (car menu)) | |
6984 | (entries (cdr (nth 1 menu))) | |
6985 | (menu nil) | |
6986 | (cnt 0) | |
6987 | (nextmenu nil)) | |
6988 | (while entries | |
6989 | (while (and entries (< cnt N)) | |
6990 | (setq cnt (1+ cnt) | |
6991 | nextmenu (cons (car entries) nextmenu) | |
6992 | entries (cdr entries))) | |
6993 | (setq nextmenu (nreverse nextmenu)) | |
6994 | (prin1 nextmenu) | |
6995 | (setq nextmenu (cons (format "%s...%s" | |
6996 | (car (car nextmenu)) | |
6997 | (car (nth (1- cnt) nextmenu))) | |
6998 | nextmenu)) | |
6999 | (setq menu (cons nextmenu menu) | |
7000 | nextmenu nil | |
7001 | cnt 0)) | |
7002 | (setq menu (nreverse menu)) | |
7003 | (setq menu (cons title menu)) | |
7004 | menu))) | |
f32b3b91 | 7005 | |
15e42531 CD |
7006 | (defvar idlwave-completion-setup-hook nil) |
7007 | ||
f32b3b91 CD |
7008 | (defun idlwave-scroll-completions (&optional message) |
7009 | "Scroll the completion window on this frame." | |
7010 | (let ((cwin (get-buffer-window "*Completions*" 'visible)) | |
7011 | (win (selected-window))) | |
7012 | (unwind-protect | |
7013 | (progn | |
7014 | (select-window cwin) | |
7015 | (condition-case nil | |
7016 | (scroll-up) | |
7017 | (error (if (and (listp last-command) | |
7018 | (nth 2 last-command)) | |
7019 | (progn | |
7020 | (select-window win) | |
7021 | (eval idlwave-complete-after-success-form)) | |
7022 | (set-window-start cwin (point-min))))) | |
274f1353 | 7023 | (and message (message "%s" message))) |
f32b3b91 CD |
7024 | (select-window win)))) |
7025 | ||
7026 | (defun idlwave-display-completion-list (list &optional message beg complete) | |
7027 | "Display the completions in LIST in the completions buffer and echo MESSAGE." | |
7028 | (unless (and (get-buffer-window "*Completions*") | |
7029 | (idlwave-local-value 'idlwave-completion-p "*Completions*")) | |
7030 | (move-marker idlwave-completion-mark beg) | |
7031 | (setq idlwave-before-completion-wconf (current-window-configuration))) | |
7032 | ||
7033 | (if (featurep 'xemacs) | |
4b1aaa8b | 7034 | (idlwave-display-completion-list-xemacs |
15e42531 | 7035 | list) |
f32b3b91 CD |
7036 | (idlwave-display-completion-list-emacs list)) |
7037 | ||
7038 | ;; Store a special value in `this-command'. When `idlwave-complete' | |
7039 | ;; finds this in `last-command', it will scroll the *Completions* buffer. | |
7040 | (setq this-command (list 'idlwave-display-completion-list message complete)) | |
7041 | ||
7042 | ;; Mark the completions buffer as created by cib | |
7043 | (idlwave-set-local 'idlwave-completion-p t "*Completions*") | |
7044 | ||
7045 | ;; Fontify the classes | |
7046 | (if (and idlwave-completion-fontify-classes | |
7047 | (consp (car list))) | |
7048 | (idlwave-completion-fontify-classes)) | |
7049 | ||
15e42531 CD |
7050 | ;; Run the hook |
7051 | (run-hooks 'idlwave-completion-setup-hook) | |
7052 | ||
f32b3b91 | 7053 | ;; Display the message |
274f1353 | 7054 | (message "%s" (or message "Making completion list...done"))) |
f32b3b91 CD |
7055 | |
7056 | (defun idlwave-choose (function &rest args) | |
7057 | "Call FUNCTION as a completion chooser and pass ARGS to it." | |
7058 | (let ((completion-ignore-case t)) ; install correct value | |
7059 | (apply function args)) | |
15e42531 CD |
7060 | (if (and (eq major-mode 'idlwave-shell-mode) |
7061 | (boundp 'font-lock-mode) | |
7062 | (not font-lock-mode)) | |
52a244eb | 7063 | ;; For the shell, remove the fontification of the word before point |
15e42531 CD |
7064 | (let ((beg (save-excursion |
7065 | (skip-chars-backward "a-zA-Z0-9_") | |
7066 | (point)))) | |
7067 | (remove-text-properties beg (point) '(face nil)))) | |
f32b3b91 CD |
7068 | (eval idlwave-complete-after-success-form-force)) |
7069 | ||
76959b77 S |
7070 | (defun idlwave-keyboard-quit () |
7071 | (interactive) | |
7072 | (unwind-protect | |
7073 | (if (eq (car-safe last-command) 'idlwave-display-completion-list) | |
7074 | (idlwave-restore-wconf-after-completion)) | |
7075 | (keyboard-quit))) | |
7076 | ||
f32b3b91 CD |
7077 | (defun idlwave-restore-wconf-after-completion () |
7078 | "Restore the old (before completion) window configuration." | |
7079 | (and idlwave-completion-restore-window-configuration | |
7080 | idlwave-before-completion-wconf | |
7081 | (set-window-configuration idlwave-before-completion-wconf))) | |
7082 | ||
52a244eb S |
7083 | (defun idlwave-one-key-select (sym prompt delay) |
7084 | "Make the user select an element from the alist in the variable SYM. | |
7085 | The keys of the alist are expected to be strings. The function returns the | |
7086 | car of the selected association. | |
d9271f41 | 7087 | To do this, PROMPT is displayed and the user must hit a letter key to |
52a244eb S |
7088 | select an entry. If the user does not reply within DELAY seconds, a help |
7089 | window with the options is displayed automatically. | |
7090 | The key which is associated with each option is generated automatically. | |
7091 | First, the strings are checked for preselected keys, like in \"[P]rint\". | |
7092 | If these don't exist, a letter in the string is automatically selected." | |
7093 | (let* ((alist (symbol-value sym)) | |
7094 | (temp-buffer-show-hook (if (fboundp 'fit-window-to-buffer) | |
7095 | '(fit-window-to-buffer))) | |
7096 | keys-alist char) | |
7097 | ;; First check the cache | |
7098 | (if (and (eq (symbol-value sym) (get sym :one-key-alist-last))) | |
7099 | (setq keys-alist (get sym :one-key-alist-cache)) | |
7100 | ;; Need to make new list | |
7101 | (setq keys-alist (idlwave-make-one-key-alist alist)) | |
7102 | (put sym :one-key-alist-cache keys-alist) | |
7103 | (put sym :one-key-alist-last alist)) | |
7104 | ;; Display prompt and wait for quick reply | |
7105 | (message "%s[%s]" prompt | |
7106 | (mapconcat (lambda(x) (char-to-string (car x))) | |
7107 | keys-alist "")) | |
7108 | (if (sit-for delay) | |
7109 | ;; No quick reply: Show help | |
7110 | (save-window-excursion | |
7111 | (with-output-to-temp-buffer "*Completions*" | |
7112 | (mapcar (lambda(x) | |
7113 | (princ (nth 1 x)) | |
7114 | (princ "\n")) | |
4b1aaa8b | 7115 | keys-alist)) |
52a244eb S |
7116 | (setq char (read-char))) |
7117 | (setq char (read-char))) | |
7118 | (message nil) | |
7119 | ;; Return the selected result | |
7120 | (nth 2 (assoc char keys-alist)))) | |
7121 | ||
7122 | ;; Used for, e.g., electric debug super-examine. | |
7123 | (defun idlwave-make-one-key-alist (alist) | |
7124 | "Make an alist for single key selection." | |
7125 | (let ((l alist) keys-alist name start char help | |
7126 | (cnt 0) | |
7127 | (case-fold-search nil)) | |
7128 | (while l | |
7129 | (setq name (car (car l)) | |
7130 | l (cdr l)) | |
7131 | (catch 'exit | |
7132 | ;; First check if the configuration predetermined a key | |
7133 | (if (string-match "\\[\\(.\\)\\]" name) | |
7134 | (progn | |
7135 | (setq char (string-to-char (downcase (match-string 1 name))) | |
7136 | help (format "%c: %s" char name) | |
7137 | keys-alist (cons (list char help name) keys-alist)) | |
7138 | (throw 'exit t))) | |
7139 | ;; Then check for capital letters | |
7140 | (setq start 0) | |
7141 | (while (string-match "[A-Z]" name start) | |
7142 | (setq start (match-end 0) | |
7143 | char (string-to-char (downcase (match-string 0 name)))) | |
7144 | (if (not (assoc char keys-alist)) | |
7145 | (progn | |
7146 | (setq help (format "%c: %s" char | |
7147 | (replace-match | |
7148 | (concat "[" (match-string 0 name) "]") | |
7149 | t t name)) | |
7150 | keys-alist (cons (list char help name) keys-alist)) | |
7151 | (throw 'exit t)))) | |
7152 | ;; Now check for lowercase letters | |
7153 | (setq start 0) | |
7154 | (while (string-match "[a-z]" name start) | |
7155 | (setq start (match-end 0) | |
7156 | char (string-to-char (match-string 0 name))) | |
7157 | (if (not (assoc char keys-alist)) | |
7158 | (progn | |
7159 | (setq help (format "%c: %s" char | |
7160 | (replace-match | |
7161 | (concat "[" (match-string 0 name) "]") | |
7162 | t t name)) | |
7163 | keys-alist (cons (list char help name) keys-alist)) | |
7164 | (throw 'exit t)))) | |
7165 | ;; Bummer, nothing found! Use a stupid number | |
7166 | (setq char (string-to-char (int-to-string (setq cnt (1+ cnt)))) | |
7167 | help (format "%c: %s" char name) | |
7168 | keys-alist (cons (list char help name) keys-alist)))) | |
7169 | (nreverse keys-alist))) | |
7170 | ||
f32b3b91 CD |
7171 | (defun idlwave-set-local (var value &optional buffer) |
7172 | "Set the buffer-local value of VAR in BUFFER to VALUE." | |
7173 | (save-excursion | |
7174 | (set-buffer (or buffer (current-buffer))) | |
7175 | (set (make-local-variable var) value))) | |
7176 | ||
7177 | (defun idlwave-local-value (var &optional buffer) | |
7178 | "Return the value of VAR in BUFFER, but only if VAR is local to BUFFER." | |
7179 | (save-excursion | |
7180 | (set-buffer (or buffer (current-buffer))) | |
7181 | (and (local-variable-p var (current-buffer)) | |
7182 | (symbol-value var)))) | |
7183 | ||
15e42531 CD |
7184 | ;; In XEmacs, we can use :activate-callback directly to advice the |
7185 | ;; choose functions. We use the private keymap only for the online | |
7186 | ;; help feature. | |
f32b3b91 | 7187 | |
15e42531 CD |
7188 | (defvar idlwave-completion-map nil |
7189 | "Keymap for completion-list-mode with idlwave-complete.") | |
7190 | ||
7191 | (defun idlwave-display-completion-list-xemacs (list &rest cl-args) | |
f32b3b91 | 7192 | (with-output-to-temp-buffer "*Completions*" |
15e42531 CD |
7193 | (apply 'display-completion-list list |
7194 | ':activate-callback 'idlwave-default-choose-completion | |
7195 | cl-args)) | |
7196 | (save-excursion | |
7197 | (set-buffer "*Completions*") | |
7198 | (use-local-map | |
7199 | (or idlwave-completion-map | |
7200 | (setq idlwave-completion-map | |
7201 | (idlwave-make-modified-completion-map-xemacs | |
7202 | (current-local-map))))))) | |
f32b3b91 CD |
7203 | |
7204 | (defun idlwave-default-choose-completion (&rest args) | |
7205 | "Execute `default-choose-completion' and then restore the win-conf." | |
7206 | (apply 'idlwave-choose 'default-choose-completion args)) | |
7207 | ||
15e42531 CD |
7208 | (defun idlwave-make-modified-completion-map-xemacs (old-map) |
7209 | "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP." | |
7210 | (let ((new-map (copy-keymap old-map))) | |
7211 | (define-key new-map [button3up] 'idlwave-mouse-completion-help) | |
7212 | (define-key new-map [button3] (lambda () | |
7213 | (interactive) | |
7214 | (setq this-command last-command))) | |
7215 | new-map)) | |
f32b3b91 | 7216 | |
76959b77 | 7217 | ;; In Emacs we also replace keybindings in the completion |
15e42531 | 7218 | ;; map in order to install our wrappers. |
f32b3b91 CD |
7219 | |
7220 | (defun idlwave-display-completion-list-emacs (list) | |
7221 | "Display completion list and install the choose wrappers." | |
7222 | (with-output-to-temp-buffer "*Completions*" | |
7223 | (display-completion-list list)) | |
7224 | (save-excursion | |
7225 | (set-buffer "*Completions*") | |
7226 | (use-local-map | |
7227 | (or idlwave-completion-map | |
7228 | (setq idlwave-completion-map | |
15e42531 CD |
7229 | (idlwave-make-modified-completion-map-emacs |
7230 | (current-local-map))))))) | |
7231 | ||
7232 | (defun idlwave-make-modified-completion-map-emacs (old-map) | |
f32b3b91 CD |
7233 | "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP." |
7234 | (let ((new-map (copy-keymap old-map))) | |
4b1aaa8b | 7235 | (substitute-key-definition |
f32b3b91 CD |
7236 | 'choose-completion 'idlwave-choose-completion new-map) |
7237 | (substitute-key-definition | |
7238 | 'mouse-choose-completion 'idlwave-mouse-choose-completion new-map) | |
15e42531 | 7239 | (define-key new-map [mouse-3] 'idlwave-mouse-completion-help) |
f32b3b91 CD |
7240 | new-map)) |
7241 | ||
7242 | (defun idlwave-choose-completion (&rest args) | |
7243 | "Choose the completion that point is in or next to." | |
7244 | (interactive) | |
7245 | (apply 'idlwave-choose 'choose-completion args)) | |
7246 | ||
7247 | (defun idlwave-mouse-choose-completion (&rest args) | |
7248 | "Click on an alternative in the `*Completions*' buffer to choose it." | |
7249 | (interactive "e") | |
7250 | (apply 'idlwave-choose 'mouse-choose-completion args)) | |
7251 | ||
7252 | ;;---------------------------------------------------------------------- | |
7253 | ;;---------------------------------------------------------------------- | |
7254 | ||
05a1abfc | 7255 | ;;; ------------------------------------------------------------------------ |
52a244eb | 7256 | ;;; Stucture parsing code, and code to manage class info |
05a1abfc CD |
7257 | |
7258 | ;; | |
7259 | ;; - Go again over the documentation how to write a completion | |
7260 | ;; plugin. It is in self.el, but currently still very bad. | |
4b1aaa8b PE |
7261 | ;; This could be in a separate file in the distribution, or |
7262 | ;; in an appendix for the manual. | |
52a244eb S |
7263 | |
7264 | (defvar idlwave-struct-skip | |
7265 | "[ \t]*\\(\\$.*\n\\(^[ \t]*\\(\\$[ \t]*\\)?\\(;.*\\)?\n\\)*\\)?[ \t]*" | |
7266 | "Regexp for skipping continued blank or comment-only lines in | |
7267 | structures") | |
7268 | ||
7269 | (defvar idlwave-struct-tag-regexp | |
7270 | (concat "[{,]" ;leading comma/brace | |
7271 | idlwave-struct-skip ; 4 groups | |
7272 | "\\([a-zA-Z][a-zA-Z0-9_]*\\)" ;the tag itself, group 5 | |
7273 | "[ \t]*:") ; the final colon | |
7274 | "Regexp for structure tags.") | |
05a1abfc CD |
7275 | |
7276 | (defun idlwave-struct-tags () | |
7277 | "Return a list of all tags in the structure defined at point. | |
7278 | Point is expected just before the opening `{' of the struct definition." | |
7279 | (save-excursion | |
7280 | (let* ((borders (idlwave-struct-borders)) | |
7281 | (beg (car borders)) | |
7282 | (end (cdr borders)) | |
7283 | tags) | |
7284 | (goto-char beg) | |
52a244eb S |
7285 | (save-restriction |
7286 | (narrow-to-region beg end) | |
7287 | (while (re-search-forward idlwave-struct-tag-regexp end t) | |
7288 | ;; Check if we are still on the top level of the structure. | |
7289 | (if (and (condition-case nil (progn (up-list -1) t) (error nil)) | |
7290 | (= (point) beg)) | |
7291 | (push (match-string-no-properties 5) tags)) | |
7292 | (goto-char (match-end 0)))) | |
7293 | (nreverse tags)))) | |
05a1abfc | 7294 | |
76959b77 S |
7295 | (defun idlwave-find-struct-tag (tag) |
7296 | "Find a given TAG in the structure defined at point." | |
7297 | (let* ((borders (idlwave-struct-borders)) | |
7298 | (beg (car borders)) | |
7299 | (end (cdr borders)) | |
7300 | (case-fold-search t)) | |
4b1aaa8b | 7301 | (re-search-forward (concat "\\(^[ \t]*\\|[,{][ \t]*\\)" tag "[ \t]*:") |
76959b77 S |
7302 | end t))) |
7303 | ||
05a1abfc CD |
7304 | (defun idlwave-struct-inherits () |
7305 | "Return a list of all `inherits' names in the struct at point. | |
7306 | Point is expected just before the opening `{' of the struct definition." | |
7307 | (save-excursion | |
7308 | (let* ((borders (idlwave-struct-borders)) | |
7309 | (beg (car borders)) | |
7310 | (end (cdr borders)) | |
7311 | (case-fold-search t) | |
7312 | names) | |
7313 | (goto-char beg) | |
52a244eb S |
7314 | (save-restriction |
7315 | (narrow-to-region beg end) | |
4b1aaa8b | 7316 | (while (re-search-forward |
52a244eb S |
7317 | (concat "[{,]" ;leading comma/brace |
7318 | idlwave-struct-skip ; 4 groups | |
7319 | "inherits" ; The INHERITS tag | |
7320 | idlwave-struct-skip ; 4 more | |
7321 | "\\([a-zA-Z][a-zA-Z0-9_]*\\)") ; The super-group, #9 | |
7322 | end t) | |
7323 | ;; Check if we are still on the top level of the structure. | |
7324 | (if (and (condition-case nil (progn (up-list -1) t) (error nil)) | |
7325 | (= (point) beg)) | |
7326 | (push (match-string-no-properties 9) names)) | |
7327 | (goto-char (match-end 0)))) | |
05a1abfc CD |
7328 | (nreverse names)))) |
7329 | ||
5e72c6b2 | 7330 | (defun idlwave-in-structure () |
52a244eb | 7331 | "Return t if point is inside an IDL structure definition." |
5e72c6b2 S |
7332 | (let ((beg (point))) |
7333 | (save-excursion | |
7334 | (if (not (or (idlwave-in-comment) (idlwave-in-quote))) | |
7335 | (if (idlwave-find-structure-definition nil nil 'back) | |
7336 | (let ((borders (idlwave-struct-borders))) | |
7337 | (or (= (car borders) (cdr borders)) ;; struct not yet closed... | |
7338 | (and (> beg (car borders)) (< beg (cdr borders)))))))))) | |
05a1abfc CD |
7339 | |
7340 | (defun idlwave-struct-borders () | |
7341 | "Return the borders of the {...} after point as a cons cell." | |
7342 | (let (beg) | |
7343 | (save-excursion | |
7344 | (skip-chars-forward "^{") | |
7345 | (setq beg (point)) | |
7346 | (condition-case nil (forward-list 1) | |
7347 | (error (goto-char beg))) | |
7348 | (cons beg (point))))) | |
7349 | ||
7350 | (defun idlwave-find-structure-definition (&optional var name bound) | |
52a244eb S |
7351 | "Search forward for a structure definition. If VAR is non-nil, |
7352 | search for a structure assigned to variable VAR. If NAME is non-nil, | |
7353 | search for a named structure NAME, if a string, or a generic named | |
7354 | structure otherwise. If BOUND is an integer, limit the search. If | |
7355 | BOUND is the symbol `all', we search first back and then forward | |
7356 | through the entire file. If BOUND is the symbol `back' we search only | |
7357 | backward." | |
76959b77 | 7358 | (let* ((ws "[ \t]*\\(\\$.*\n[ \t]*\\)*") |
05a1abfc CD |
7359 | (case-fold-search t) |
7360 | (lim (if (integerp bound) bound nil)) | |
7361 | (re (concat | |
7362 | (if var | |
7363 | (concat "\\<" (regexp-quote (downcase var)) "\\>" ws) | |
7364 | "\\(\\)") | |
7365 | "=" ws "\\({\\)" | |
4b1aaa8b | 7366 | (if name |
52a244eb | 7367 | (if (stringp name) |
4b1aaa8b | 7368 | (concat ws "\\(\\<" (downcase name) "\\)[^a-zA-Z0-9_$]") |
52a244eb S |
7369 | ;; Just a generic name |
7370 | (concat ws "\\<\\([a-zA-Z_0-9$]+\\)" ws ",")) | |
7371 | "")))) | |
5e72c6b2 | 7372 | (if (or (and (or (eq bound 'all) (eq bound 'back)) |
05a1abfc | 7373 | (re-search-backward re nil t)) |
5e72c6b2 | 7374 | (and (not (eq bound 'back)) (re-search-forward re lim t))) |
52a244eb S |
7375 | (progn |
7376 | (goto-char (match-beginning 3)) | |
7377 | (match-string-no-properties 5))))) | |
7378 | ||
4b1aaa8b | 7379 | (defvar idlwave-class-info nil) |
52a244eb | 7380 | (defvar idlwave-class-reset nil) ; to reset buffer-local classes |
05a1abfc | 7381 | |
05a1abfc | 7382 | (add-hook 'idlwave-update-rinfo-hook |
52a244eb | 7383 | (lambda () (setq idlwave-class-reset t))) |
05a1abfc CD |
7384 | (add-hook 'idlwave-after-load-rinfo-hook |
7385 | (lambda () (setq idlwave-class-info nil))) | |
7386 | ||
7387 | (defun idlwave-class-info (class) | |
7388 | (let (list entry) | |
52a244eb S |
7389 | (if idlwave-class-info |
7390 | (if idlwave-class-reset | |
4b1aaa8b | 7391 | (setq |
52a244eb S |
7392 | idlwave-class-reset nil |
7393 | idlwave-class-info ; Remove any visited in a buffer | |
4b1aaa8b PE |
7394 | (delq nil (mapcar |
7395 | (lambda (x) | |
7396 | (let ((filebuf | |
7397 | (idlwave-class-file-or-buffer | |
52a244eb S |
7398 | (or (cdr (assq 'found-in x)) (car x))))) |
7399 | (if (cdr filebuf) | |
7400 | nil | |
7401 | x))) | |
7402 | idlwave-class-info)))) | |
7403 | ;; Info is nil, put in the system stuff to start. | |
05a1abfc CD |
7404 | (setq idlwave-class-info idlwave-system-class-info) |
7405 | (setq list idlwave-class-info) | |
7406 | (while (setq entry (pop list)) | |
7407 | (idlwave-sintern-class-info entry))) | |
7408 | (setq class (idlwave-sintern-class class)) | |
52a244eb S |
7409 | (or (assq class idlwave-class-info) |
7410 | (progn (idlwave-scan-class-info class) | |
7411 | (assq class idlwave-class-info))))) | |
05a1abfc CD |
7412 | |
7413 | (defun idlwave-sintern-class-info (entry) | |
7414 | "Sintern the class names in a class-info entry." | |
7415 | (let ((taglist (assq 'tags entry)) | |
7416 | (inherits (assq 'inherits entry))) | |
7417 | (setcar entry (idlwave-sintern-class (car entry) 'set)) | |
7418 | (if inherits | |
7419 | (setcdr inherits (mapcar (lambda (x) (idlwave-sintern-class x 'set)) | |
7420 | (cdr inherits)))))) | |
7421 | ||
52a244eb S |
7422 | (defun idlwave-find-class-definition (class &optional all-hook alt-class) |
7423 | "Find class structure definition(s) | |
7424 | If ALL-HOOK is set, find all named structure definitions in a given | |
7425 | class__define routine, on which ALL-HOOK will be run. If ALT-CLASS is | |
7426 | set, look for the name__define pro, and inside of it, for the ALT-CLASS | |
7427 | class/struct definition" | |
7428 | (let ((case-fold-search t) end-lim list name) | |
7429 | (when (re-search-forward | |
7430 | (concat "^[ \t]*pro[ \t]+" (downcase class) "__define" "\\>") nil t) | |
7431 | (if all-hook | |
7432 | (progn | |
7433 | ;; For everything there | |
7434 | (setq end-lim (save-excursion (idlwave-end-of-subprogram) (point))) | |
4b1aaa8b | 7435 | (while (setq name |
52a244eb S |
7436 | (idlwave-find-structure-definition nil t end-lim)) |
7437 | (funcall all-hook name))) | |
7438 | (idlwave-find-structure-definition nil (or alt-class class)))))) | |
76959b77 | 7439 | |
52a244eb S |
7440 | |
7441 | (defun idlwave-class-file-or-buffer (class) | |
7442 | "Find buffer visiting CLASS definition" | |
05a1abfc | 7443 | (let* ((pro (concat (downcase class) "__define")) |
52a244eb S |
7444 | (file (idlwave-routine-source-file |
7445 | (nth 3 (idlwave-rinfo-assoc pro 'pro nil | |
7446 | (idlwave-routines)))))) | |
7447 | (cons file (if file (idlwave-get-buffer-visiting file))))) | |
7448 | ||
7449 | ||
7450 | (defun idlwave-scan-class-info (class) | |
7451 | "Scan all class and named structure info in the class__define pro" | |
7452 | (let* ((idlwave-auto-routine-info-updates nil) | |
7453 | (filebuf (idlwave-class-file-or-buffer class)) | |
7454 | (file (car filebuf)) | |
7455 | (buf (cdr filebuf)) | |
7456 | (class (idlwave-sintern-class class))) | |
7457 | (if (or | |
7458 | (not file) | |
7459 | (and ;; neither a regular file nor a visited buffer | |
7460 | (not buf) | |
7461 | (not (file-regular-p file)))) | |
7462 | nil ; Cannot find the file/buffer to get any info | |
05a1abfc | 7463 | (save-excursion |
52a244eb S |
7464 | (if buf (set-buffer buf) |
7465 | ;; Read the file in temporarily | |
05a1abfc CD |
7466 | (set-buffer (get-buffer-create " *IDLWAVE-tmp*")) |
7467 | (erase-buffer) | |
7468 | (unless (eq major-mode 'idlwave-mode) | |
7469 | (idlwave-mode)) | |
7470 | (insert-file-contents file)) | |
7471 | (save-excursion | |
7472 | (goto-char 1) | |
4b1aaa8b | 7473 | (idlwave-find-class-definition class |
52a244eb S |
7474 | ;; Scan all of the structures found there |
7475 | (lambda (name) | |
7476 | (let* ((this-class (idlwave-sintern-class name)) | |
4b1aaa8b | 7477 | (entry |
52a244eb S |
7478 | (list this-class |
7479 | (cons 'tags (idlwave-struct-tags)) | |
7480 | (cons 'inherits (idlwave-struct-inherits))))) | |
7481 | (if (not (eq this-class class)) | |
7482 | (setq entry (nconc entry (list (cons 'found-in class))))) | |
7483 | (idlwave-sintern-class-info entry) | |
7484 | (push entry idlwave-class-info))))))))) | |
7485 | ||
7486 | (defun idlwave-class-found-in (class) | |
7487 | "Return the FOUND-IN property of the class." | |
7488 | (cdr (assq 'found-in (idlwave-class-info class)))) | |
05a1abfc CD |
7489 | (defun idlwave-class-tags (class) |
7490 | "Return the native tags in CLASS." | |
7491 | (cdr (assq 'tags (idlwave-class-info class)))) | |
7492 | (defun idlwave-class-inherits (class) | |
7493 | "Return the direct superclasses of CLASS." | |
7494 | (cdr (assq 'inherits (idlwave-class-info class)))) | |
7495 | ||
52a244eb | 7496 | |
05a1abfc CD |
7497 | (defun idlwave-all-class-tags (class) |
7498 | "Return a list of native and inherited tags in CLASS." | |
76959b77 S |
7499 | (condition-case err |
7500 | (apply 'append (mapcar 'idlwave-class-tags | |
7501 | (cons class (idlwave-all-class-inherits class)))) | |
4b1aaa8b | 7502 | (error |
76959b77 S |
7503 | (idlwave-class-tag-reset) |
7504 | (error "%s" (error-message-string err))))) | |
7505 | ||
05a1abfc CD |
7506 | |
7507 | (defun idlwave-all-class-inherits (class) | |
7508 | "Return a list of all superclasses of CLASS (recursively expanded). | |
5e72c6b2 | 7509 | The list is cached in `idlwave-class-info' for faster access." |
05a1abfc CD |
7510 | (cond |
7511 | ((not idlwave-support-inheritance) nil) | |
7512 | ((eq class nil) nil) | |
7513 | ((eq class t) nil) | |
7514 | (t | |
7515 | (let ((info (idlwave-class-info class)) | |
7516 | entry) | |
7517 | (if (setq entry (assq 'all-inherits info)) | |
7518 | (cdr entry) | |
76959b77 S |
7519 | ;; Save the depth of inheritance scan to check for circular references |
7520 | (let ((inherits (mapcar (lambda (x) (cons x 0)) | |
7521 | (idlwave-class-inherits class))) | |
05a1abfc CD |
7522 | rtn all-inherits cl) |
7523 | (while inherits | |
7524 | (setq cl (pop inherits) | |
76959b77 S |
7525 | rtn (cons (car cl) rtn) |
7526 | inherits (append (mapcar (lambda (x) | |
7527 | (cons x (1+ (cdr cl)))) | |
7528 | (idlwave-class-inherits (car cl))) | |
7529 | inherits)) | |
7530 | (if (> (cdr cl) 999) | |
7531 | (error | |
7532 | "Class scan: inheritance depth exceeded. Circular inheritance?") | |
7533 | )) | |
05a1abfc CD |
7534 | (setq all-inherits (nreverse rtn)) |
7535 | (nconc info (list (cons 'all-inherits all-inherits))) | |
7536 | all-inherits)))))) | |
7537 | ||
52a244eb | 7538 | (defun idlwave-entry-keywords (entry &optional record-link) |
4b1aaa8b | 7539 | "Return the flat entry keywords alist from routine-info entry. |
52a244eb S |
7540 | If RECORD-LINK is non-nil, the keyword text is copied and a text |
7541 | property indicating the link is added." | |
7542 | (let (kwds) | |
8ffcfb27 | 7543 | (mapc |
4b1aaa8b | 7544 | (lambda (key-list) |
52a244eb S |
7545 | (let ((file (car key-list))) |
7546 | (mapcar (lambda (key-cons) | |
7547 | (let ((key (car key-cons)) | |
7548 | (link (cdr key-cons))) | |
7549 | (when (and record-link file) | |
7550 | (setq key (copy-sequence key)) | |
4b1aaa8b | 7551 | (put-text-property |
52a244eb | 7552 | 0 (length key) |
4b1aaa8b PE |
7553 | 'link |
7554 | (concat | |
7555 | file | |
7556 | (if link | |
52a244eb S |
7557 | (concat idlwave-html-link-sep |
7558 | (number-to-string link)))) | |
7559 | key)) | |
7560 | (push (list key) kwds))) | |
7561 | (cdr key-list)))) | |
7562 | (nthcdr 5 entry)) | |
7563 | (nreverse kwds))) | |
7564 | ||
7565 | (defun idlwave-entry-find-keyword (entry keyword) | |
7566 | "Find keyword KEYWORD in entry ENTRY, and return (with link) if set" | |
7567 | (catch 'exit | |
7568 | (mapc | |
4b1aaa8b | 7569 | (lambda (key-list) |
52a244eb S |
7570 | (let ((file (car key-list)) |
7571 | (kwd (assoc keyword (cdr key-list)))) | |
7572 | (when kwd | |
4b1aaa8b | 7573 | (setq kwd (cons (car kwd) |
52a244eb | 7574 | (if (and file (cdr kwd)) |
4b1aaa8b | 7575 | (concat file |
52a244eb S |
7576 | idlwave-html-link-sep |
7577 | (number-to-string (cdr kwd))) | |
7578 | (cdr kwd)))) | |
7579 | (throw 'exit kwd)))) | |
7580 | (nthcdr 5 entry)))) | |
05a1abfc CD |
7581 | |
7582 | ;;========================================================================== | |
7583 | ;; | |
7584 | ;; Completing class structure tags. This is a completion plugin. | |
7585 | ;; The necessary taglist is constructed dynamically | |
7586 | ||
7587 | (defvar idlwave-current-tags-class nil) | |
7588 | (defvar idlwave-current-class-tags nil) | |
7589 | (defvar idlwave-current-native-class-tags nil) | |
76959b77 | 7590 | (defvar idlwave-sint-class-tags nil) |
1a717047 | 7591 | (declare-function idlwave-sintern-class-tag "idlwave" t t) |
76959b77 | 7592 | (idlwave-new-sintern-type 'class-tag) |
05a1abfc | 7593 | (add-to-list 'idlwave-complete-special 'idlwave-complete-class-structure-tag) |
76959b77 | 7594 | (add-hook 'idlwave-update-rinfo-hook 'idlwave-class-tag-reset) |
05a1abfc CD |
7595 | |
7596 | (defun idlwave-complete-class-structure-tag () | |
7597 | "Complete a structure tag on a `self' argument in an object method." | |
7598 | (interactive) | |
7599 | (let ((pos (point)) | |
7600 | (case-fold-search t)) | |
7601 | (if (save-excursion | |
7602 | ;; Check if the context is right | |
52a244eb | 7603 | (skip-chars-backward "a-zA-Z0-9._$") |
05a1abfc CD |
7604 | (and (< (point) (- pos 4)) |
7605 | (looking-at "self\\."))) | |
76959b77 S |
7606 | (let* ((class-selector (nth 2 (idlwave-current-routine))) |
7607 | (super-classes (idlwave-all-class-inherits class-selector))) | |
05a1abfc | 7608 | ;; Check if we are in a class routine |
76959b77 | 7609 | (unless class-selector |
e8af40ee | 7610 | (error "Not in a method procedure or function")) |
05a1abfc | 7611 | ;; Check if we need to update the "current" class |
76959b77 S |
7612 | (if (not (equal class-selector idlwave-current-tags-class)) |
7613 | (idlwave-prepare-class-tag-completion class-selector)) | |
4b1aaa8b | 7614 | (setq idlwave-completion-help-info |
76959b77 | 7615 | (list 'idlwave-complete-class-structure-tag-help |
4b1aaa8b | 7616 | (idlwave-sintern-routine |
76959b77 S |
7617 | (concat class-selector "__define")) |
7618 | nil)) | |
05a1abfc CD |
7619 | (let ((idlwave-cpl-bold idlwave-current-native-class-tags)) |
7620 | (idlwave-complete-in-buffer | |
4b1aaa8b | 7621 | 'class-tag 'class-tag |
05a1abfc | 7622 | idlwave-current-class-tags nil |
76959b77 S |
7623 | (format "Select a tag of class %s" class-selector) |
7624 | "class tag" | |
7625 | 'idlwave-attach-class-tag-classes)) | |
05a1abfc CD |
7626 | t) ; return t to skip other completions |
7627 | nil))) | |
7628 | ||
76959b77 | 7629 | (defun idlwave-class-tag-reset () |
05a1abfc CD |
7630 | (setq idlwave-current-tags-class nil)) |
7631 | ||
7632 | (defun idlwave-prepare-class-tag-completion (class) | |
7633 | "Find and parse the necessary class definitions for class structure tags." | |
76959b77 | 7634 | (setq idlwave-sint-class-tags nil) |
05a1abfc CD |
7635 | (setq idlwave-current-tags-class class) |
7636 | (setq idlwave-current-class-tags | |
7637 | (mapcar (lambda (x) | |
76959b77 | 7638 | (list (idlwave-sintern-class-tag x 'set))) |
05a1abfc CD |
7639 | (idlwave-all-class-tags class))) |
7640 | (setq idlwave-current-native-class-tags | |
7641 | (mapcar 'downcase (idlwave-class-tags class)))) | |
7642 | ||
7643 | ;=========================================================================== | |
7644 | ;; | |
7645 | ;; Completing system variables and their structure fields | |
52a244eb | 7646 | ;; This is also a plugin. |
05a1abfc CD |
7647 | |
7648 | (defvar idlwave-sint-sysvars nil) | |
7649 | (defvar idlwave-sint-sysvartags nil) | |
1a717047 GM |
7650 | (declare-function idlwave-sintern-sysvar "idlwave" t t) |
7651 | (declare-function idlwave-sintern-sysvartag "idlwave" t t) | |
05a1abfc CD |
7652 | (idlwave-new-sintern-type 'sysvar) |
7653 | (idlwave-new-sintern-type 'sysvartag) | |
7654 | (add-to-list 'idlwave-complete-special 'idlwave-complete-sysvar-or-tag) | |
7655 | (add-hook 'idlwave-update-rinfo-hook 'idlwave-sysvars-reset) | |
05a1abfc CD |
7656 | (add-hook 'idlwave-after-load-rinfo-hook 'idlwave-sintern-sysvar-alist) |
7657 | ||
05a1abfc CD |
7658 | |
7659 | (defun idlwave-complete-sysvar-or-tag () | |
7660 | "Complete a system variable." | |
7661 | (interactive) | |
7662 | (let ((pos (point)) | |
7663 | (case-fold-search t)) | |
7664 | (cond ((save-excursion | |
7665 | ;; Check if the context is right for system variable | |
7666 | (skip-chars-backward "[a-zA-Z0-9_$]") | |
7667 | (equal (char-before) ?!)) | |
7668 | (setq idlwave-completion-help-info '(idlwave-complete-sysvar-help)) | |
4b1aaa8b | 7669 | (idlwave-complete-in-buffer 'sysvar 'sysvar |
05a1abfc CD |
7670 | idlwave-system-variables-alist nil |
7671 | "Select a system variable" | |
7672 | "system variable") | |
7673 | t) ; return t to skip other completions | |
7674 | ((save-excursion | |
7675 | ;; Check if the context is right for sysvar tag | |
52a244eb | 7676 | (skip-chars-backward "a-zA-Z0-9_$.") |
05a1abfc CD |
7677 | (and (equal (char-before) ?!) |
7678 | (looking-at "\\([a-zA-Z][a-zA-Z0-9_$]*\\)\\.") | |
7679 | (<= (match-end 0) pos))) | |
7680 | ;; Complete a system variable tag | |
7681 | (let* ((var (idlwave-sintern-sysvar (match-string 1))) | |
7682 | (entry (assq var idlwave-system-variables-alist)) | |
52a244eb S |
7683 | (tags (cdr (assq 'tags entry)))) |
7684 | (or entry (error "!%s is not a known system variable" var)) | |
05a1abfc CD |
7685 | (or tags (error "System variable !%s is not a structure" var)) |
7686 | (setq idlwave-completion-help-info | |
52a244eb | 7687 | (list 'idlwave-complete-sysvar-tag-help var)) |
4b1aaa8b | 7688 | (idlwave-complete-in-buffer 'sysvartag 'sysvartag |
05a1abfc CD |
7689 | tags nil |
7690 | "Select a system variable tag" | |
7691 | "system variable tag") | |
7692 | t)) ; return t to skip other completions | |
7693 | (t nil)))) | |
7694 | ||
f66f03de S |
7695 | (defvar link) ;dynamic variables set by help callback |
7696 | (defvar props) | |
05a1abfc | 7697 | (defun idlwave-complete-sysvar-help (mode word) |
52a244eb S |
7698 | (let ((word (or (nth 1 idlwave-completion-help-info) word)) |
7699 | (entry (assoc word idlwave-system-variables-alist))) | |
7700 | (cond | |
7701 | ((eq mode 'test) | |
7702 | (and (stringp word) entry (nth 1 (assq 'link entry)))) | |
7703 | ((eq mode 'set) | |
7704 | (if entry (setq link (nth 1 (assq 'link entry))))) ;; setting dynamic!!! | |
7705 | (t (error "This should not happen"))))) | |
7706 | ||
7707 | (defun idlwave-complete-sysvar-tag-help (mode word) | |
7708 | (let* ((var (nth 1 idlwave-completion-help-info)) | |
7709 | (entry (assoc var idlwave-system-variables-alist)) | |
7710 | (tags (cdr (assq 'tags entry))) | |
7711 | (main (nth 1 (assq 'link entry))) | |
7712 | target main-base) | |
7713 | (cond | |
7714 | ((eq mode 'test) ; we can at least link the main | |
7715 | (and (stringp word) entry main)) | |
7716 | ((eq mode 'set) | |
4b1aaa8b PE |
7717 | (if entry |
7718 | (setq link | |
e08734e2 | 7719 | (if (setq target (cdr (assoc-string word tags t))) |
52a244eb S |
7720 | (idlwave-substitute-link-target main target) |
7721 | main)))) ;; setting dynamic!!! | |
7722 | (t (error "This should not happen"))))) | |
7723 | ||
f66f03de S |
7724 | (defun idlwave-split-link-target (link) |
7725 | "Split a given link into link file and anchor." | |
7726 | (if (string-match idlwave-html-link-sep link) | |
7727 | (cons (substring link 0 (match-beginning 0)) | |
7728 | (string-to-number (substring link (match-end 0)))))) | |
7729 | ||
52a244eb S |
7730 | (defun idlwave-substitute-link-target (link target) |
7731 | "Substitute the target anchor for the given link." | |
7732 | (let (main-base) | |
7733 | (setq main-base (if (string-match "#" link) | |
7734 | (substring link 0 (match-beginning 0)) | |
7735 | link)) | |
7736 | (if target | |
7737 | (concat main-base idlwave-html-link-sep (number-to-string target)) | |
7738 | link))) | |
76959b77 S |
7739 | |
7740 | ;; Fake help in the source buffer for class structure tags. | |
52a244eb | 7741 | ;; KWD AND NAME ARE GLOBAL-VARIABLES HERE. |
4b1aaa8b | 7742 | (defvar name) |
52a244eb | 7743 | (defvar kwd) |
76959b77 S |
7744 | (defvar idlwave-help-do-class-struct-tag nil) |
7745 | (defun idlwave-complete-class-structure-tag-help (mode word) | |
7746 | (cond | |
7747 | ((eq mode 'test) ; nothing gets fontified for class tags | |
7748 | nil) | |
7749 | ((eq mode 'set) | |
52a244eb | 7750 | (let (class-with found-in) |
4b1aaa8b PE |
7751 | (when (setq class-with |
7752 | (idlwave-class-or-superclass-with-tag | |
76959b77 S |
7753 | idlwave-current-tags-class |
7754 | word)) | |
4b1aaa8b | 7755 | (if (assq (idlwave-sintern-class class-with) |
76959b77 | 7756 | idlwave-system-class-info) |
ff689efd | 7757 | (error "No help available for system class tags")) |
52a244eb S |
7758 | (if (setq found-in (idlwave-class-found-in class-with)) |
7759 | (setq name (cons (concat found-in "__define") class-with)) | |
7760 | (setq name (concat class-with "__define"))))) | |
76959b77 S |
7761 | (setq kwd word |
7762 | idlwave-help-do-class-struct-tag t)) | |
7763 | (t (error "This should not happen")))) | |
7764 | ||
7765 | (defun idlwave-class-or-superclass-with-tag (class tag) | |
7766 | "Find and return the CLASS or one of its superclass with the | |
7767 | associated TAG, if any." | |
e08734e2 | 7768 | (let ((sclasses (cons class (idlwave-all-class-inherits class))) |
76959b77 S |
7769 | cl) |
7770 | (catch 'exit | |
7771 | (while sclasses | |
7772 | (setq cl (pop sclasses)) | |
7773 | (let ((tags (idlwave-class-tags cl))) | |
7774 | (while tags | |
7775 | (if (eq t (compare-strings tag 0 nil (car tags) 0 nil t)) | |
4b1aaa8b | 7776 | (throw 'exit cl)) |
76959b77 S |
7777 | (setq tags (cdr tags)))))))) |
7778 | ||
05a1abfc CD |
7779 | |
7780 | (defun idlwave-sysvars-reset () | |
7781 | (if (and (fboundp 'idlwave-shell-is-running) | |
52a244eb S |
7782 | (idlwave-shell-is-running) |
7783 | idlwave-idlwave_routine_info-compiled) | |
05a1abfc CD |
7784 | (idlwave-shell-send-command "idlwave_get_sysvars" |
7785 | 'idlwave-process-sysvars 'hide))) | |
7786 | ||
7787 | (defun idlwave-process-sysvars () | |
7788 | (idlwave-shell-filter-sysvars) | |
7789 | (setq idlwave-sint-sysvars nil | |
7790 | idlwave-sint-sysvartags nil) | |
7791 | (idlwave-sintern-sysvar-alist)) | |
7792 | ||
05a1abfc | 7793 | (defun idlwave-sintern-sysvar-alist () |
52a244eb | 7794 | (let ((list idlwave-system-variables-alist) entry tags) |
05a1abfc CD |
7795 | (while (setq entry (pop list)) |
7796 | (setcar entry (idlwave-sintern-sysvar (car entry) 'set)) | |
52a244eb S |
7797 | (setq tags (assq 'tags entry)) |
7798 | (if tags | |
4b1aaa8b PE |
7799 | (setcdr tags |
7800 | (mapcar (lambda (x) | |
52a244eb S |
7801 | (cons (idlwave-sintern-sysvartag (car x) 'set) |
7802 | (cdr x))) | |
7803 | (cdr tags))))))) | |
05a1abfc CD |
7804 | |
7805 | (defvar idlwave-shell-command-output) | |
7806 | (defun idlwave-shell-filter-sysvars () | |
52a244eb | 7807 | "Get any new system variables and tags." |
05a1abfc CD |
7808 | (let ((text idlwave-shell-command-output) |
7809 | (start 0) | |
7810 | (old idlwave-system-variables-alist) | |
52a244eb | 7811 | var tags type name class link old-entry) |
05a1abfc CD |
7812 | (setq idlwave-system-variables-alist nil) |
7813 | (while (string-match "^IDLWAVE-SYSVAR: !\\([a-zA-Z0-9_$]+\\)\\( \\(.*\\)\\)?" | |
7814 | text start) | |
7815 | (setq start (match-end 0) | |
7816 | var (match-string 1 text) | |
4b1aaa8b | 7817 | tags (if (match-end 3) |
52a244eb S |
7818 | (idlwave-split-string (match-string 3 text)))) |
7819 | ;; Maintain old links, if present | |
7820 | (setq old-entry (assq (idlwave-sintern-sysvar var) old)) | |
7821 | (setq link (assq 'link old-entry)) | |
05a1abfc | 7822 | (setq idlwave-system-variables-alist |
4b1aaa8b PE |
7823 | (cons (list var |
7824 | (cons | |
7825 | 'tags | |
7826 | (mapcar (lambda (x) | |
7827 | (cons x | |
7828 | (cdr (assq | |
7829 | (idlwave-sintern-sysvartag x) | |
52a244eb S |
7830 | (cdr (assq 'tags old-entry)))))) |
7831 | tags)) link) | |
05a1abfc CD |
7832 | idlwave-system-variables-alist))) |
7833 | ;; Keep the old value if query was not successful | |
7834 | (setq idlwave-system-variables-alist | |
7835 | (or idlwave-system-variables-alist old)))) | |
7836 | ||
f32b3b91 CD |
7837 | (defun idlwave-completion-fontify-classes () |
7838 | "Goto the *Completions* buffer and fontify the class info." | |
7839 | (when (featurep 'font-lock) | |
7840 | (save-excursion | |
7841 | (set-buffer "*Completions*") | |
7842 | (save-excursion | |
7843 | (goto-char (point-min)) | |
76959b77 S |
7844 | (let ((buffer-read-only nil)) |
7845 | (while (re-search-forward "\\.*<[^>]+>" nil t) | |
7846 | (put-text-property (match-beginning 0) (match-end 0) | |
7847 | 'face 'font-lock-string-face))))))) | |
f32b3b91 CD |
7848 | |
7849 | (defun idlwave-uniquify (list) | |
52a244eb | 7850 | (let ((ht (make-hash-table :size (length list) :test 'equal))) |
4b1aaa8b | 7851 | (delq nil |
52a244eb | 7852 | (mapcar (lambda (x) |
4b1aaa8b | 7853 | (unless (gethash x ht) |
52a244eb S |
7854 | (puthash x t ht) |
7855 | x)) | |
7856 | list)))) | |
f32b3b91 CD |
7857 | |
7858 | (defun idlwave-after-successful-completion (type slash &optional verify) | |
7859 | "Add `=' or `(' after successful completion of keyword and function. | |
7860 | Restore the pre-completion window configuration if possible." | |
7861 | (cond | |
7862 | ((eq type 'procedure) | |
7863 | nil) | |
7864 | ((eq type 'function) | |
7865 | (cond | |
7866 | ((equal idlwave-function-completion-adds-paren nil) nil) | |
7867 | ((or (equal idlwave-function-completion-adds-paren t) | |
7868 | (equal idlwave-function-completion-adds-paren 1)) | |
7869 | (insert "(")) | |
7870 | ((equal idlwave-function-completion-adds-paren 2) | |
7871 | (insert "()") | |
7872 | (backward-char 1)) | |
7873 | (t nil))) | |
7874 | ((eq type 'keyword) | |
7875 | (if (and idlwave-keyword-completion-adds-equal | |
7876 | (not slash)) | |
7877 | (progn (insert "=") t) | |
7878 | nil))) | |
7879 | ||
7880 | ;; Restore the pre-completion window configuration if this is safe. | |
4b1aaa8b PE |
7881 | |
7882 | (if (or (eq verify 'force) ; force | |
7883 | (and | |
f32b3b91 | 7884 | (get-buffer-window "*Completions*") ; visible |
4b1aaa8b | 7885 | (idlwave-local-value 'idlwave-completion-p |
f32b3b91 CD |
7886 | "*Completions*") ; cib-buffer |
7887 | (eq (marker-buffer idlwave-completion-mark) | |
7888 | (current-buffer)) ; buffer OK | |
7889 | (equal (marker-position idlwave-completion-mark) | |
7890 | verify))) ; pos OK | |
7891 | (idlwave-restore-wconf-after-completion)) | |
7892 | (move-marker idlwave-completion-mark nil) | |
7893 | (setq idlwave-before-completion-wconf nil)) | |
7894 | ||
15e42531 CD |
7895 | (defun idlwave-mouse-context-help (ev &optional arg) |
7896 | "Call `idlwave-context-help' on the clicked location." | |
7897 | (interactive "eP") | |
7898 | (mouse-set-point ev) | |
7899 | (idlwave-context-help arg)) | |
7900 | ||
7901 | (defvar idlwave-last-context-help-pos nil) | |
7902 | (defun idlwave-context-help (&optional arg) | |
7903 | "Display IDL Online Help on context. | |
76959b77 S |
7904 | If point is on a keyword, help for that keyword will be shown. If |
7905 | point is on a routine name or in the argument list of a routine, help | |
7906 | for that routine will be displayed. Works for system routines and | |
7907 | keywords, it pulls up text help. For other routies and keywords, | |
7908 | visits the source file, finding help in the header (if | |
7909 | `idlwave-help-source-try-header' is non-nil) or the routine definition | |
7910 | itself." | |
f32b3b91 | 7911 | (interactive "P") |
15e42531 CD |
7912 | (idlwave-do-context-help arg)) |
7913 | ||
7914 | (defun idlwave-mouse-completion-help (ev) | |
7915 | "Display online help about the completion at point." | |
7916 | (interactive "eP") | |
52a244eb S |
7917 | ;; Restore last-command for next command, to make |
7918 | ;; scrolling/cancelling of completions work. | |
15e42531 CD |
7919 | (setq this-command last-command) |
7920 | (idlwave-do-mouse-completion-help ev)) | |
15e42531 | 7921 | |
f32b3b91 | 7922 | (defun idlwave-routine-info (&optional arg external) |
52a244eb S |
7923 | "Display a routines calling sequence and list of keywords. When |
7924 | point is on the name a function or procedure, or in the argument list | |
7925 | of a function or procedure, this command displays a help buffer with | |
7926 | the information. When called with prefix arg, enforce class query. | |
f32b3b91 CD |
7927 | |
7928 | When point is on an object operator `->', display the class stored in | |
7929 | this arrow, if any (see `idlwave-store-inquired-class'). With a | |
7930 | prefix arg, the class property is cleared out." | |
7931 | ||
7932 | (interactive "P") | |
7933 | (idlwave-routines) | |
7934 | (if (string-match "->" (buffer-substring | |
7935 | (max (point-min) (1- (point))) | |
7936 | (min (+ 2 (point)) (point-max)))) | |
7937 | ;; Cursor is on an arrow | |
7938 | (if (get-text-property (point) 'idlwave-class) | |
7939 | ;; arrow has class property | |
7940 | (if arg | |
7941 | ;; Remove property | |
7942 | (save-excursion | |
7943 | (backward-char 1) | |
7944 | (when (looking-at ".?\\(->\\)") | |
7945 | (remove-text-properties (match-beginning 1) (match-end 1) | |
7946 | '(idlwave-class nil face nil)) | |
7947 | (message "Class property removed from arrow"))) | |
7948 | ;; Echo class property | |
7949 | (message "Arrow has text property identifying object to be class %s" | |
7950 | (get-text-property (point) 'idlwave-class))) | |
7951 | ;; No property found | |
7952 | (message "Arrow has no class text property")) | |
7953 | ||
7954 | ;; Not on an arrow... | |
7955 | (let* ((idlwave-query-class nil) | |
7956 | (idlwave-force-class-query (equal arg '(4))) | |
7957 | (module (idlwave-what-module))) | |
15e42531 | 7958 | (if (car module) |
05a1abfc CD |
7959 | (apply 'idlwave-display-calling-sequence |
7960 | (idlwave-fix-module-if-obj_new module)) | |
e8af40ee | 7961 | (error "Don't know which calling sequence to show"))))) |
f32b3b91 CD |
7962 | |
7963 | (defun idlwave-resolve (&optional arg) | |
52a244eb | 7964 | "Call RESOLVE_ROUTINE on the module name at point. |
f32b3b91 CD |
7965 | Like `idlwave-routine-info', this looks for a routine call at point. |
7966 | After confirmation in the minibuffer, it will use the shell to issue | |
7967 | a RESOLVE call for this routine, to attempt to make it defined and its | |
7968 | routine info available for IDLWAVE. If the routine is a method call, | |
7969 | both `class__method' and `class__define' will be tried. | |
7970 | With ARG, enforce query for the class of object methods." | |
7971 | (interactive "P") | |
7972 | (let* ((idlwave-query-class nil) | |
7973 | (idlwave-force-class-query (equal arg '(4))) | |
7974 | (module (idlwave-what-module)) | |
7975 | (name (idlwave-make-full-name (nth 2 module) (car module))) | |
7976 | (type (if (eq (nth 1 module) 'pro) "pro" "function")) | |
7977 | (resolve (read-string "Resolve: " (format "%s %s" type name))) | |
7978 | (kwd "") | |
7979 | class) | |
7980 | (if (string-match "\\(pro\\|function\\)[ \t]+\\(\\(.*\\)::\\)?\\(.*\\)" | |
7981 | resolve) | |
7982 | (setq type (match-string 1 resolve) | |
4b1aaa8b | 7983 | class (if (match-beginning 2) |
f32b3b91 CD |
7984 | (match-string 3 resolve) |
7985 | nil) | |
7986 | name (match-string 4 resolve))) | |
7987 | (if (string= (downcase type) "function") | |
7988 | (setq kwd ",/is_function")) | |
7989 | ||
7990 | (cond | |
7991 | ((null class) | |
4b1aaa8b | 7992 | (idlwave-shell-send-command |
f32b3b91 CD |
7993 | (format "resolve_routine,'%s'%s" (downcase name) kwd) |
7994 | 'idlwave-update-routine-info | |
7995 | nil t)) | |
7996 | (t | |
4b1aaa8b | 7997 | (idlwave-shell-send-command |
f32b3b91 | 7998 | (format "resolve_routine,'%s__define'%s" (downcase class) kwd) |
4b1aaa8b PE |
7999 | (list 'idlwave-shell-send-command |
8000 | (format "resolve_routine,'%s__%s'%s" | |
f32b3b91 CD |
8001 | (downcase class) (downcase name) kwd) |
8002 | '(idlwave-update-routine-info) | |
8003 | nil t)))))) | |
8004 | ||
3938cb82 S |
8005 | (defun idlwave-find-module-this-file () |
8006 | (interactive) | |
8007 | (idlwave-find-module '(4))) | |
8008 | ||
f32b3b91 CD |
8009 | (defun idlwave-find-module (&optional arg) |
8010 | "Find the source code of an IDL module. | |
52a244eb S |
8011 | Works for modules for which IDLWAVE has routine info available. The |
8012 | function offers as default the module name `idlwave-routine-info' | |
8013 | would use. With ARG limit to this buffer. With two prefix ARG's | |
8014 | force class query for object methods." | |
f32b3b91 CD |
8015 | (interactive "P") |
8016 | (let* ((idlwave-query-class nil) | |
52a244eb S |
8017 | (idlwave-force-class-query (equal arg '(16))) |
8018 | (this-buffer (equal arg '(4))) | |
05a1abfc | 8019 | (module (idlwave-fix-module-if-obj_new (idlwave-what-module))) |
52a244eb | 8020 | (default (if module |
4b1aaa8b | 8021 | (concat (idlwave-make-full-name |
52a244eb S |
8022 | (nth 2 module) (car module)) |
8023 | (if (eq (nth 1 module) 'pro) "<p>" "<f>")) | |
8024 | "none")) | |
4b1aaa8b | 8025 | (list |
52a244eb S |
8026 | (idlwave-uniquify |
8027 | (delq nil | |
4b1aaa8b | 8028 | (mapcar (lambda (x) |
52a244eb S |
8029 | (if (eq 'system (car-safe (nth 3 x))) |
8030 | ;; Take out system routines with no source. | |
8031 | nil | |
8032 | (list | |
4b1aaa8b | 8033 | (concat (idlwave-make-full-name |
52a244eb S |
8034 | (nth 2 x) (car x)) |
8035 | (if (eq (nth 1 x) 'pro) "<p>" "<f>"))))) | |
8036 | (if this-buffer | |
8037 | (idlwave-save-buffer-update) | |
8038 | (idlwave-routines)))))) | |
f32b3b91 | 8039 | (name (idlwave-completing-read |
52a244eb S |
8040 | (if (or (not this-buffer) |
8041 | (assoc default list)) | |
8042 | (format "Module (Default %s): " default) | |
8043 | (format "Module in this file: ")) | |
f32b3b91 CD |
8044 | list)) |
8045 | type class) | |
8046 | (if (string-match "\\`\\s-*\\'" name) | |
8047 | ;; Nothing, use the default. | |
8048 | (setq name default)) | |
8049 | (if (string-match "<[fp]>" name) | |
8050 | (setq type (substring name -2 -1) | |
8051 | name (substring name 0 -3))) | |
8052 | (if (string-match "\\(.*\\)::\\(.*\\)" name) | |
8053 | (setq class (match-string 1 name) | |
8054 | name (match-string 2 name))) | |
8055 | (setq name (idlwave-sintern-routine-or-method name class) | |
8056 | class (idlwave-sintern-class class) | |
8057 | type (cond ((equal type "f") 'fun) | |
8058 | ((equal type "p") 'pro) | |
8059 | (t t))) | |
52a244eb | 8060 | (idlwave-do-find-module name type class nil this-buffer))) |
f32b3b91 | 8061 | |
4b1aaa8b | 8062 | (defun idlwave-do-find-module (name type class |
52a244eb | 8063 | &optional force-source this-buffer) |
f32b3b91 | 8064 | (let ((name1 (idlwave-make-full-name class name)) |
4b1aaa8b | 8065 | source buf1 entry |
f32b3b91 | 8066 | (buf (current-buffer)) |
05a1abfc | 8067 | (pos (point)) |
52a244eb S |
8068 | file name2) |
8069 | (setq entry (idlwave-best-rinfo-assq name type class (idlwave-routines) | |
8070 | 'WITH-FILE) | |
05a1abfc CD |
8071 | source (or force-source (nth 3 entry)) |
8072 | name2 (if (nth 2 entry) | |
8073 | (idlwave-make-full-name (nth 2 entry) name) | |
775591f7 | 8074 | name1)) |
4b1aaa8b | 8075 | (if source |
52a244eb S |
8076 | (setq file (idlwave-routine-source-file source))) |
8077 | (unless file ; Try to find it on the path. | |
4b1aaa8b PE |
8078 | (setq file |
8079 | (idlwave-expand-lib-file-name | |
52a244eb S |
8080 | (if class |
8081 | (format "%s__define.pro" (downcase class)) | |
8082 | (format "%s.pro" (downcase name)))))) | |
f32b3b91 CD |
8083 | (cond |
8084 | ((or (null name) (equal name "")) | |
8085 | (error "Abort")) | |
f32b3b91 | 8086 | ((eq (car source) 'system) |
4b1aaa8b | 8087 | (error "Source code for system routine %s is not available" |
05a1abfc | 8088 | name2)) |
52a244eb | 8089 | ((or (not file) (not (file-regular-p file))) |
e8af40ee | 8090 | (error "Source code for routine %s is not available" |
05a1abfc | 8091 | name2)) |
52a244eb S |
8092 | (t |
8093 | (when (not this-buffer) | |
4b1aaa8b | 8094 | (setq buf1 |
52a244eb S |
8095 | (idlwave-find-file-noselect file 'find)) |
8096 | (pop-to-buffer buf1 t)) | |
15e42531 | 8097 | (goto-char (point-max)) |
f32b3b91 | 8098 | (let ((case-fold-search t)) |
15e42531 | 8099 | (if (re-search-backward |
f32b3b91 | 8100 | (concat "^[ \t]*\\<" |
52a244eb S |
8101 | (cond ((eq type 'fun) "function") |
8102 | ((eq type 'pro) "pro") | |
f32b3b91 | 8103 | (t "\\(pro\\|function\\)")) |
4b1aaa8b | 8104 | "\\>[ \t]+" |
05a1abfc | 8105 | (regexp-quote (downcase name2)) |
f32b3b91 CD |
8106 | "[^a-zA-Z0-9_$]") |
8107 | nil t) | |
8108 | (goto-char (match-beginning 0)) | |
8109 | (pop-to-buffer buf) | |
8110 | (goto-char pos) | |
05a1abfc | 8111 | (error "Could not find routine %s" name2))))))) |
f32b3b91 CD |
8112 | |
8113 | (defun idlwave-what-module () | |
8114 | "Return a default module for stuff near point. | |
8115 | Used by `idlwave-routine-info' and `idlwave-find-module'." | |
8116 | (idlwave-routines) | |
15e42531 CD |
8117 | (if (let ((case-fold-search t)) |
8118 | (save-excursion | |
8119 | (idlwave-beginning-of-statement) | |
8120 | (looking-at "[ \t]*\\(pro\\|function\\)[ \t]+\\(\\([a-zA-Z0-9_$]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)\\([, \t\n]\\|$\\)"))) | |
8121 | ;; This is a function or procedure definition statement | |
8122 | ;; We return the defined routine as module. | |
8123 | (list | |
52a244eb S |
8124 | (idlwave-sintern-routine-or-method (match-string-no-properties 4) |
8125 | (match-string-no-properties 2)) | |
15e42531 CD |
8126 | (if (equal (downcase (match-string 1)) "pro") 'pro 'fun) |
8127 | (idlwave-sintern-class (match-string 3))) | |
8128 | ||
52a244eb | 8129 | ;; Not a definition statement - analyze precise position. |
15e42531 CD |
8130 | (let* ((where (idlwave-where)) |
8131 | (cw (nth 2 where)) | |
8132 | (pro (car (nth 0 where))) | |
8133 | (func (car (nth 1 where))) | |
8134 | (this-word (idlwave-this-word "a-zA-Z0-9$_")) | |
8135 | (next-char (save-excursion (skip-chars-forward "a-zA-Z0-9$_") | |
8136 | (following-char))) | |
8137 | ) | |
8138 | (cond | |
8139 | ((and (eq cw 'procedure) | |
8140 | (not (equal this-word ""))) | |
4b1aaa8b | 8141 | (setq this-word (idlwave-sintern-routine-or-method |
15e42531 CD |
8142 | this-word (nth 2 (nth 3 where)))) |
8143 | (list this-word 'pro | |
4b1aaa8b | 8144 | (idlwave-determine-class |
15e42531 CD |
8145 | (cons this-word (cdr (nth 3 where))) |
8146 | 'pro))) | |
4b1aaa8b | 8147 | ((and (eq cw 'function) |
15e42531 CD |
8148 | (not (equal this-word "")) |
8149 | (or (eq next-char ?\() ; exclude arrays, vars. | |
8150 | (looking-at "[a-zA-Z0-9_]*[ \t]*("))) | |
4b1aaa8b | 8151 | (setq this-word (idlwave-sintern-routine-or-method |
15e42531 CD |
8152 | this-word (nth 2 (nth 3 where)))) |
8153 | (list this-word 'fun | |
8154 | (idlwave-determine-class | |
8155 | (cons this-word (cdr (nth 3 where))) | |
8156 | 'fun))) | |
8157 | ((and (memq cw '(function-keyword procedure-keyword)) | |
8158 | (not (equal this-word "")) | |
8159 | (eq next-char ?\()) ; A function! | |
8160 | (setq this-word (idlwave-sintern-routine this-word)) | |
8161 | (list this-word 'fun nil)) | |
8162 | (func | |
8163 | (list func 'fun (idlwave-determine-class (nth 1 where) 'fun))) | |
8164 | (pro | |
8165 | (list pro 'pro (idlwave-determine-class (nth 0 where) 'pro))) | |
8166 | (t nil))))) | |
f32b3b91 | 8167 | |
05a1abfc CD |
8168 | (defun idlwave-what-module-find-class () |
8169 | "Call idlwave-what-module and find the inherited class if necessary." | |
8170 | (let* ((module (idlwave-what-module)) | |
8171 | (class (nth 2 module)) | |
8172 | classes) | |
8173 | (if (and (= (length module) 3) | |
8174 | (stringp class)) | |
8175 | (list (car module) | |
8176 | (nth 1 module) | |
8177 | (apply 'idlwave-find-inherited-class module)) | |
8178 | module))) | |
8179 | ||
8180 | (defun idlwave-find-inherited-class (name type class) | |
8181 | "Find the class which defines TYPE NAME and is CLASS or inherited by CLASS." | |
8182 | (let ((entry (idlwave-best-rinfo-assoc name type class (idlwave-routines)))) | |
8183 | (if entry | |
8184 | (nth 2 entry) | |
8185 | class))) | |
8186 | ||
8187 | (defun idlwave-fix-module-if-obj_new (module) | |
4b1aaa8b | 8188 | "Check if MODULE points to obj_new. |
52a244eb S |
8189 | If yes, and if the cursor is in the keyword region, change to the |
8190 | appropriate Init method." | |
05a1abfc CD |
8191 | (let* ((name (car module)) |
8192 | (pos (point)) | |
8193 | (case-fold-search t) | |
8194 | string) | |
8195 | (if (and (stringp name) | |
8196 | (equal (downcase name) "obj_new") | |
8197 | (save-excursion | |
8198 | (idlwave-beginning-of-statement) | |
8199 | (setq string (buffer-substring (point) pos)) | |
8200 | (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)" | |
8201 | string))) | |
8202 | (let ((name "Init") | |
8203 | (class (match-string 1 string))) | |
8204 | (setq module (list (idlwave-sintern-method "Init") | |
8205 | 'fun | |
8206 | (idlwave-sintern-class class))))) | |
8207 | module)) | |
8208 | ||
4b1aaa8b | 8209 | (defun idlwave-fix-keywords (name type class keywords |
3938cb82 | 8210 | &optional super-classes system) |
52a244eb S |
8211 | "Update a list of keywords. |
8212 | Translate OBJ_NEW, adding all super-class keywords, or all keywords | |
3938cb82 S |
8213 | from all classes if class equals t. If SYSTEM is non-nil, don't |
8214 | demand _EXTRA in the keyword list." | |
5e72c6b2 | 8215 | (let ((case-fold-search t)) |
f32b3b91 CD |
8216 | |
8217 | ;; If this is the OBJ_NEW function, try to figure out the class and use | |
8218 | ;; the keywords from the corresponding INIT method. | |
5e72c6b2 | 8219 | (if (and (equal (upcase name) "OBJ_NEW") |
05a1abfc CD |
8220 | (or (eq major-mode 'idlwave-mode) |
8221 | (eq major-mode 'idlwave-shell-mode))) | |
f32b3b91 CD |
8222 | (let* ((bos (save-excursion (idlwave-beginning-of-statement) (point))) |
8223 | (string (buffer-substring bos (point))) | |
8224 | (case-fold-search t) | |
8225 | class) | |
8226 | (and (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)" | |
8227 | string) | |
8228 | (setq class (idlwave-sintern-class (match-string 1 string))) | |
15e42531 | 8229 | (setq idlwave-current-obj_new-class class) |
4b1aaa8b PE |
8230 | (setq keywords |
8231 | (append keywords | |
52a244eb S |
8232 | (idlwave-entry-keywords |
8233 | (idlwave-rinfo-assq | |
8234 | (idlwave-sintern-method "INIT") | |
8235 | 'fun | |
8236 | class | |
8237 | (idlwave-routines)) 'do-link)))))) | |
4b1aaa8b | 8238 | |
f32b3b91 CD |
8239 | ;; If the class is `t', combine all keywords of all methods NAME |
8240 | (when (eq class t) | |
52a244eb S |
8241 | (mapc (lambda (entry) |
8242 | (and | |
8243 | (nth 2 entry) ; non-nil class | |
8244 | (eq (nth 1 entry) type) ; correct type | |
4b1aaa8b PE |
8245 | (setq keywords |
8246 | (append keywords | |
52a244eb S |
8247 | (idlwave-entry-keywords entry 'do-link))))) |
8248 | (idlwave-all-assq name (idlwave-routines))) | |
5e72c6b2 | 8249 | (setq keywords (idlwave-uniquify keywords))) |
4b1aaa8b | 8250 | |
5e72c6b2 | 8251 | ;; If we have inheritance, add all keywords from superclasses, if |
52a244eb | 8252 | ;; the user indicated that method in `idlwave-keyword-class-inheritance' |
4b1aaa8b | 8253 | (when (and |
52a244eb | 8254 | super-classes |
5e72c6b2 S |
8255 | idlwave-keyword-class-inheritance |
8256 | (stringp class) | |
4b1aaa8b | 8257 | (or |
3938cb82 S |
8258 | system |
8259 | (assq (idlwave-sintern-keyword "_extra") keywords) | |
8260 | (assq (idlwave-sintern-keyword "_ref_extra") keywords)) | |
5e72c6b2 S |
8261 | ;; Check if one of the keyword-class regexps matches the name |
8262 | (let ((regexps idlwave-keyword-class-inheritance) re) | |
8263 | (catch 'exit | |
8264 | (while (setq re (pop regexps)) | |
8265 | (if (string-match re name) (throw 'exit t)))))) | |
52a244eb S |
8266 | |
8267 | (loop for entry in (idlwave-routines) do | |
8268 | (and (nth 2 entry) ; non-nil class | |
8269 | (memq (nth 2 entry) super-classes) ; an inherited class | |
8270 | (eq (nth 1 entry) type) ; correct type | |
8271 | (eq (car entry) name) ; correct name | |
8ffcfb27 GM |
8272 | (mapc (lambda (k) (add-to-list 'keywords k)) |
8273 | (idlwave-entry-keywords entry 'do-link)))) | |
f32b3b91 | 8274 | (setq keywords (idlwave-uniquify keywords))) |
4b1aaa8b | 8275 | |
f32b3b91 CD |
8276 | ;; Return the final list |
8277 | keywords)) | |
8278 | ||
15e42531 | 8279 | (defun idlwave-expand-keyword (keyword module) |
2e8b9c7d | 8280 | "Expand KEYWORD to one of the valid keyword parameters of MODULE. |
15e42531 CD |
8281 | KEYWORD may be an exact match or an abbreviation of a keyword. |
8282 | If the match is exact, KEYWORD itself is returned, even if there may be other | |
8283 | keywords of which KEYWORD is an abbreviation. This is necessary because some | |
8284 | system routines have keywords which are prefixes of other keywords. | |
8285 | If KEYWORD is an abbreviation of several keywords, a list of all possible | |
8286 | completions is returned. | |
8287 | If the abbreviation was unique, the correct keyword is returned. | |
8288 | If it cannot be a keyword, the function return nil. | |
8289 | If we do not know about MODULE, just return KEYWORD literally." | |
8290 | (let* ((name (car module)) | |
8291 | (type (nth 1 module)) | |
8292 | (class (nth 2 module)) | |
8293 | (kwd (idlwave-sintern-keyword keyword)) | |
8294 | (entry (idlwave-best-rinfo-assoc name type class (idlwave-routines))) | |
52a244eb | 8295 | (kwd-alist (idlwave-entry-keywords entry)) |
15e42531 CD |
8296 | (extra (or (assq (idlwave-sintern-keyword "_EXTRA") kwd-alist) |
8297 | (assq (idlwave-sintern-keyword "_REF_EXTRA") kwd-alist))) | |
8298 | (completion-ignore-case t) | |
8299 | candidates) | |
4b1aaa8b | 8300 | (cond ((assq kwd kwd-alist) |
15e42531 CD |
8301 | kwd) |
8302 | ((setq candidates (all-completions kwd kwd-alist)) | |
8303 | (if (= (length candidates) 1) | |
8304 | (car candidates) | |
8305 | candidates)) | |
8306 | ((and entry extra) | |
4b1aaa8b | 8307 | ;; Inheritance may cause this keyword to be correct |
15e42531 CD |
8308 | keyword) |
8309 | (entry | |
8310 | ;; We do know the function, which does not have the keyword. | |
8311 | nil) | |
8312 | (t | |
8313 | ;; We do not know the function, so this just might be a correct | |
8314 | ;; keyword - return it as it is. | |
8315 | keyword)))) | |
8316 | ||
8317 | (defvar idlwave-rinfo-mouse-map (make-sparse-keymap)) | |
f32b3b91 | 8318 | (defvar idlwave-rinfo-map (make-sparse-keymap)) |
4b1aaa8b | 8319 | (define-key idlwave-rinfo-mouse-map |
f32b3b91 CD |
8320 | (if (featurep 'xemacs) [button2] [mouse-2]) |
8321 | 'idlwave-mouse-active-rinfo) | |
4b1aaa8b | 8322 | (define-key idlwave-rinfo-mouse-map |
15e42531 CD |
8323 | (if (featurep 'xemacs) [(shift button2)] [(shift mouse-2)]) |
8324 | 'idlwave-mouse-active-rinfo-shift) | |
4b1aaa8b | 8325 | (define-key idlwave-rinfo-mouse-map |
f32b3b91 CD |
8326 | (if (featurep 'xemacs) [button3] [mouse-3]) |
8327 | 'idlwave-mouse-active-rinfo-right) | |
15e42531 CD |
8328 | (define-key idlwave-rinfo-mouse-map " " 'idlwave-active-rinfo-space) |
8329 | (define-key idlwave-rinfo-map "q" 'idlwave-quit-help) | |
8330 | (define-key idlwave-rinfo-mouse-map "q" 'idlwave-quit-help) | |
8331 | (defvar idlwave-popup-source nil) | |
8332 | (defvar idlwave-rinfo-marker (make-marker)) | |
8333 | ||
8334 | (defun idlwave-quit-help () | |
8335 | (interactive) | |
8336 | (let ((ri-window (get-buffer-window "*Help*")) | |
8337 | (olh-window (get-buffer-window "*IDLWAVE Help*"))) | |
8338 | (when (and olh-window | |
8339 | (fboundp 'idlwave-help-quit)) | |
8340 | (select-window olh-window) | |
8341 | (idlwave-help-quit)) | |
8342 | (when (window-live-p ri-window) | |
8343 | (delete-window ri-window)))) | |
f32b3b91 | 8344 | |
05a1abfc CD |
8345 | (defun idlwave-display-calling-sequence (name type class |
8346 | &optional initial-class) | |
f32b3b91 | 8347 | ;; Display the calling sequence of module NAME, type TYPE in class CLASS. |
05a1abfc CD |
8348 | (let* ((initial-class (or initial-class class)) |
8349 | (entry (or (idlwave-best-rinfo-assq name type class | |
15e42531 | 8350 | (idlwave-routines)) |
4b1aaa8b | 8351 | (idlwave-rinfo-assq name type class |
15e42531 | 8352 | idlwave-unresolved-routines))) |
f32b3b91 CD |
8353 | (name (or (car entry) name)) |
8354 | (class (or (nth 2 entry) class)) | |
05a1abfc | 8355 | (superclasses (idlwave-all-class-inherits initial-class)) |
15e42531 CD |
8356 | (twins (idlwave-routine-twins entry)) |
8357 | (dtwins (idlwave-study-twins twins)) | |
8358 | (all dtwins) | |
52a244eb | 8359 | (system (eq (car (nth 3 entry)) 'system)) |
f32b3b91 | 8360 | (calling-seq (nth 4 entry)) |
52a244eb S |
8361 | (keywords (idlwave-entry-keywords entry 'do-link)) |
8362 | (html-file (car (nth 5 entry))) | |
15e42531 | 8363 | (help-echo-kwd |
52a244eb | 8364 | "Button2: Insert KEYWORD (SHIFT=`/KEYWORD') | Button3: Online Help ") |
15e42531 | 8365 | (help-echo-use |
52a244eb | 8366 | "Button2/3: Online Help") |
15e42531 | 8367 | (help-echo-src |
52a244eb | 8368 | "Button2: Jump to source and back | Button3: Source in Help window.") |
05a1abfc CD |
8369 | (help-echo-class |
8370 | "Button2: Display info about same method in superclass") | |
f32b3b91 | 8371 | (col 0) |
52a244eb | 8372 | (data (list name type class (current-buffer) nil initial-class)) |
f32b3b91 | 8373 | (km-prop (if (featurep 'xemacs) 'keymap 'local-map)) |
f66f03de | 8374 | (face 'idlwave-help-link) |
15e42531 | 8375 | beg props win cnt total) |
4b1aaa8b | 8376 | ;; Fix keywords, but don't add chained super-classes, since these |
52a244eb | 8377 | ;; are shown separately for that super-class |
f32b3b91 CD |
8378 | (setq keywords (idlwave-fix-keywords name type class keywords)) |
8379 | (cond | |
8380 | ((null entry) | |
05a1abfc CD |
8381 | (error "No %s %s known %s" type name |
8382 | (if initial-class (concat "in class " initial-class) ""))) | |
f32b3b91 | 8383 | ((or (null name) (equal name "")) |
e8af40ee | 8384 | (error "No function or procedure call at point")) |
f32b3b91 | 8385 | ((null calling-seq) |
52a244eb | 8386 | (error "Calling sequence of %s %s not available" type name)) |
f32b3b91 CD |
8387 | (t |
8388 | (save-excursion | |
15e42531 | 8389 | (move-marker idlwave-rinfo-marker (point)) |
f32b3b91 | 8390 | (set-buffer (get-buffer-create "*Help*")) |
15e42531 | 8391 | (use-local-map idlwave-rinfo-map) |
f32b3b91 CD |
8392 | (setq buffer-read-only nil) |
8393 | (erase-buffer) | |
8394 | (set (make-local-variable 'idlwave-popup-source) nil) | |
15e42531 CD |
8395 | (set (make-local-variable 'idlwave-current-obj_new-class) |
8396 | idlwave-current-obj_new-class) | |
05a1abfc CD |
8397 | (when superclasses |
8398 | (setq props (list 'mouse-face 'highlight | |
8399 | km-prop idlwave-rinfo-mouse-map | |
8400 | 'help-echo help-echo-class | |
8401 | 'data (cons 'class data))) | |
8402 | (let ((classes (cons initial-class superclasses)) c) | |
8403 | (insert "Classes: ") | |
8404 | (while (setq c (pop classes)) | |
8405 | (insert " ") | |
8406 | (setq beg (point)) | |
8407 | (insert c) | |
8408 | (if (equal (downcase c) (downcase class)) | |
8409 | (add-text-properties beg (point) (list 'face 'bold)) | |
52a244eb | 8410 | ;; If Method exists in a different class link it |
05a1abfc CD |
8411 | (if (idlwave-rinfo-assq name type c (idlwave-routines)) |
8412 | (add-text-properties beg (point) props)))) | |
8413 | (insert "\n"))) | |
52a244eb S |
8414 | (setq props (list 'mouse-face 'highlight |
8415 | km-prop idlwave-rinfo-mouse-map | |
8416 | 'help-echo help-echo-use | |
8417 | 'data (cons 'usage data))) | |
4b1aaa8b | 8418 | (if html-file (setq props (append (list 'face face 'link html-file) |
52a244eb | 8419 | props))) |
f32b3b91 CD |
8420 | (insert "Usage: ") |
8421 | (setq beg (point)) | |
8422 | (insert (if class | |
52a244eb S |
8423 | (format calling-seq class name class name class name) |
8424 | (format calling-seq name name name name)) | |
f32b3b91 CD |
8425 | "\n") |
8426 | (add-text-properties beg (point) props) | |
4b1aaa8b | 8427 | |
f32b3b91 CD |
8428 | (insert "Keywords:") |
8429 | (if (null keywords) | |
8430 | (insert " No keywords accepted.") | |
8431 | (setq col 9) | |
8ffcfb27 | 8432 | (mapc |
f32b3b91 | 8433 | (lambda (x) |
4b1aaa8b | 8434 | (if (>= (+ col 1 (length (car x))) |
f32b3b91 CD |
8435 | (window-width)) |
8436 | (progn | |
8437 | (insert "\n ") | |
8438 | (setq col 9))) | |
8439 | (insert " ") | |
8440 | (setq beg (point) | |
52a244eb | 8441 | ;; Relevant keywords already have link property attached |
f32b3b91 | 8442 | props (list 'mouse-face 'highlight |
15e42531 | 8443 | km-prop idlwave-rinfo-mouse-map |
f32b3b91 | 8444 | 'data (cons 'keyword data) |
15e42531 | 8445 | 'help-echo help-echo-kwd |
f32b3b91 | 8446 | 'keyword (car x))) |
52a244eb | 8447 | (if system (setq props (append (list 'face face) props))) |
f32b3b91 CD |
8448 | (insert (car x)) |
8449 | (add-text-properties beg (point) props) | |
8450 | (setq col (+ col 1 (length (car x))))) | |
8451 | keywords)) | |
4b1aaa8b | 8452 | |
15e42531 | 8453 | (setq cnt 1 total (length all)) |
52a244eb | 8454 | ;; Here entry is (key file (list of type-conses)) |
15e42531 CD |
8455 | (while (setq entry (pop all)) |
8456 | (setq props (list 'mouse-face 'highlight | |
8457 | km-prop idlwave-rinfo-mouse-map | |
8458 | 'help-echo help-echo-src | |
52a244eb S |
8459 | 'source (list (car (car (nth 2 entry))) ;type |
8460 | (nth 1 entry) | |
8461 | nil | |
8462 | (cdr (car (nth 2 entry)))) | |
15e42531 CD |
8463 | 'data (cons 'source data))) |
8464 | (idlwave-insert-source-location | |
4b1aaa8b | 8465 | (format "\n%-8s %s" |
15e42531 CD |
8466 | (if (equal cnt 1) |
8467 | (if (> total 1) "Sources:" "Source:") | |
8468 | "") | |
8469 | (if (> total 1) "- " "")) | |
8470 | entry props) | |
8471 | (incf cnt) | |
8472 | (when (and all (> cnt idlwave-rinfo-max-source-lines)) | |
8473 | ;; No more source lines, please | |
4b1aaa8b | 8474 | (insert (format |
15e42531 CD |
8475 | "\n Source information truncated to %d entries." |
8476 | idlwave-rinfo-max-source-lines)) | |
8477 | (setq all nil))) | |
10c8e594 | 8478 | (goto-char (point-min)) |
f32b3b91 CD |
8479 | (setq buffer-read-only t)) |
8480 | (display-buffer "*Help*") | |
8481 | (if (and (setq win (get-buffer-window "*Help*")) | |
8482 | idlwave-resize-routine-help-window) | |
8483 | (progn | |
8484 | (let ((ww (selected-window))) | |
8485 | (unwind-protect | |
8486 | (progn | |
8487 | (select-window win) | |
4b1aaa8b | 8488 | (enlarge-window (- (/ (frame-height) 2) |
f32b3b91 CD |
8489 | (window-height))) |
8490 | (shrink-window-if-larger-than-buffer)) | |
8491 | (select-window ww))))))))) | |
8492 | ||
15e42531 CD |
8493 | (defun idlwave-insert-source-location (prefix entry &optional file-props) |
8494 | "Insert a source location into the routine info buffer. | |
52a244eb S |
8495 | Start line with PREFIX. If a file name is inserted, add FILE-PROPS to |
8496 | it." | |
15e42531 CD |
8497 | (let* ((key (car entry)) |
8498 | (file (nth 1 entry)) | |
8499 | (types (nth 2 entry)) | |
52a244eb S |
8500 | (shell-flag (assq 'compiled types)) |
8501 | (buffer-flag (assq 'buffer types)) | |
8502 | (user-flag (assq 'user types)) | |
8503 | (lib-flag (assq 'lib types)) | |
8504 | (ndupl (or (and buffer-flag (idlwave-count-memq 'buffer types)) | |
8505 | (and user-flag (idlwave-count-memq 'user types)) | |
8506 | (and lib-flag (idlwave-count-memq 'lib types)) | |
15e42531 CD |
8507 | 1)) |
8508 | (doflags t) | |
8509 | beg special) | |
8510 | ||
8511 | (insert prefix) | |
8512 | ||
8513 | (cond | |
8514 | ((eq key 'system) | |
8515 | (setq doflags nil) | |
52a244eb S |
8516 | (insert "System ")) |
8517 | ||
15e42531 CD |
8518 | ((eq key 'builtin) |
8519 | (setq doflags nil) | |
52a244eb S |
8520 | (insert "Builtin ")) |
8521 | ||
15e42531 | 8522 | ((and (not file) shell-flag) |
52a244eb S |
8523 | (insert "Unresolved")) |
8524 | ||
4b1aaa8b | 8525 | ((null file) |
52a244eb | 8526 | (insert "ERROR")) |
4b1aaa8b | 8527 | |
15e42531 CD |
8528 | ((idlwave-syslib-p file) |
8529 | (if (string-match "obsolete" (file-name-directory file)) | |
52a244eb S |
8530 | (insert "Obsolete ") |
8531 | (insert "SystemLib "))) | |
8532 | ||
8533 | ;; New special syntax: taken directly from routine-info for | |
8534 | ;; library catalog routines | |
8535 | ((setq special (or (cdr lib-flag) (cdr user-flag))) | |
8536 | (insert (format "%-10s" special))) | |
8537 | ||
8538 | ;; Old special syntax: a matching regexp | |
8539 | ((setq special (idlwave-special-lib-test file)) | |
8540 | (insert (format "%-10s" special))) | |
4b1aaa8b | 8541 | |
52a244eb | 8542 | ;; Catch-all with file |
15e42531 | 8543 | ((idlwave-lib-p file) (insert "Library ")) |
52a244eb S |
8544 | |
8545 | ;; Sanity catch all | |
15e42531 CD |
8546 | (t (insert "Other "))) |
8547 | ||
8548 | (when doflags | |
8549 | (insert (concat | |
8550 | " [" | |
52a244eb S |
8551 | (if lib-flag "L" "-") |
8552 | (if user-flag "C" "-") | |
15e42531 CD |
8553 | (if shell-flag "S" "-") |
8554 | (if buffer-flag "B" "-") | |
8555 | "] "))) | |
4b1aaa8b | 8556 | (when (> ndupl 1) |
15e42531 CD |
8557 | (setq beg (point)) |
8558 | (insert (format "(%dx) " ndupl)) | |
8559 | (add-text-properties beg (point) (list 'face 'bold))) | |
8560 | (when (and file (not (equal file ""))) | |
8561 | (setq beg (point)) | |
8562 | (insert (apply 'abbreviate-file-name | |
8563 | (if (featurep 'xemacs) (list file t) (list file)))) | |
8564 | (if file-props | |
8565 | (add-text-properties beg (point) file-props))))) | |
8566 | ||
8567 | (defun idlwave-special-lib-test (file) | |
8568 | "Check the path of FILE against the regexps which define special libs. | |
8569 | Return the name of the special lib if there is a match." | |
8570 | (let ((alist idlwave-special-lib-alist) | |
8571 | entry rtn) | |
8572 | (cond | |
8573 | ((stringp file) | |
8574 | (while (setq entry (pop alist)) | |
8575 | (if (string-match (car entry) file) | |
8576 | (setq rtn (cdr entry) | |
8577 | alist nil))) | |
8578 | rtn) | |
8579 | (t nil)))) | |
4b1aaa8b | 8580 | |
f32b3b91 CD |
8581 | (defun idlwave-mouse-active-rinfo-right (ev) |
8582 | (interactive "e") | |
8583 | (idlwave-mouse-active-rinfo ev 'right)) | |
8584 | ||
15e42531 | 8585 | (defun idlwave-mouse-active-rinfo-shift (ev) |
f32b3b91 | 8586 | (interactive "e") |
15e42531 CD |
8587 | (idlwave-mouse-active-rinfo ev nil 'shift)) |
8588 | ||
8589 | (defun idlwave-active-rinfo-space () | |
8590 | (interactive) | |
8591 | (idlwave-mouse-active-rinfo nil 'right)) | |
8592 | ||
8593 | (defun idlwave-mouse-active-rinfo (ev &optional right shift) | |
8594 | "Does the mouse actions in the routine info buffer. | |
8595 | Optional args RIGHT and SHIFT indicate, if mouse-3 was used, and if SHIFT | |
8596 | was pressed." | |
8597 | (interactive "e") | |
8598 | (if ev (mouse-set-point ev)) | |
4b1aaa8b | 8599 | (let (data id name type class buf bufwin source link keyword |
3938cb82 | 8600 | word initial-class) |
f32b3b91 | 8601 | (setq data (get-text-property (point) 'data) |
15e42531 | 8602 | source (get-text-property (point) 'source) |
f32b3b91 | 8603 | keyword (get-text-property (point) 'keyword) |
52a244eb | 8604 | link (get-text-property (point) 'link) |
f32b3b91 | 8605 | id (car data) |
15e42531 | 8606 | name (nth 1 data) type (nth 2 data) class (nth 3 data) |
f32b3b91 | 8607 | buf (nth 4 data) |
05a1abfc CD |
8608 | initial-class (nth 6 data) |
8609 | word (idlwave-this-word) | |
f32b3b91 | 8610 | bufwin (get-buffer-window buf t)) |
52a244eb S |
8611 | |
8612 | (cond ((eq id 'class) ; Switch class being displayed | |
05a1abfc | 8613 | (if (window-live-p bufwin) (select-window bufwin)) |
4b1aaa8b | 8614 | (idlwave-display-calling-sequence |
05a1abfc | 8615 | (idlwave-sintern-method name) |
4b1aaa8b | 8616 | type (idlwave-sintern-class word) |
05a1abfc | 8617 | initial-class)) |
52a244eb S |
8618 | ((eq id 'usage) ; Online help on this routine |
8619 | (idlwave-online-help link name type class)) | |
8620 | ((eq id 'source) ; Source in help or buffer | |
8621 | (if right ; In help | |
15e42531 CD |
8622 | (let ((idlwave-extra-help-function 'idlwave-help-with-source) |
8623 | (idlwave-help-source-try-header nil) | |
52a244eb | 8624 | ;; Fake idlwave-routines so help will find the right entry |
15e42531 | 8625 | (idlwave-routines |
52a244eb | 8626 | (list (list name type class source "")))) |
15e42531 | 8627 | (idlwave-help-get-special-help name type class nil)) |
52a244eb | 8628 | ;; Otherwise just pop to the source |
f32b3b91 CD |
8629 | (setq idlwave-popup-source (not idlwave-popup-source)) |
8630 | (if idlwave-popup-source | |
8631 | (condition-case err | |
15e42531 | 8632 | (idlwave-do-find-module name type class source) |
f32b3b91 CD |
8633 | (error |
8634 | (setq idlwave-popup-source nil) | |
8635 | (if (window-live-p bufwin) (select-window bufwin)) | |
8636 | (error (nth 1 err)))) | |
8637 | (if bufwin | |
8638 | (select-window bufwin) | |
15e42531 CD |
8639 | (pop-to-buffer buf)) |
8640 | (goto-char (marker-position idlwave-rinfo-marker))))) | |
f32b3b91 CD |
8641 | ((eq id 'keyword) |
8642 | (if right | |
52a244eb | 8643 | (idlwave-online-help link name type class keyword) |
15e42531 CD |
8644 | (idlwave-rinfo-insert-keyword keyword buf shift)))))) |
8645 | ||
8646 | (defun idlwave-rinfo-insert-keyword (keyword buffer &optional shift) | |
8647 | "Insert KEYWORD in BUFFER. Make sure buffer is displayed in a window." | |
8648 | (let ((bwin (get-buffer-window buffer))) | |
8649 | (if idlwave-complete-empty-string-as-lower-case | |
8650 | (setq keyword (downcase keyword))) | |
8651 | (if bwin | |
8652 | (select-window bwin) | |
8653 | (pop-to-buffer buffer) | |
8654 | (setq bwin (get-buffer-window buffer))) | |
8655 | (if (eq (preceding-char) ?/) | |
8656 | (insert keyword) | |
4b1aaa8b | 8657 | (unless (save-excursion |
15e42531 | 8658 | (re-search-backward |
4b1aaa8b | 8659 | "[(,][ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\)?[ \t]*\\=" |
15e42531 CD |
8660 | (min (- (point) 100) (point-min)) t)) |
8661 | (insert ", ")) | |
8662 | (if shift (insert "/")) | |
8663 | (insert keyword) | |
8664 | (if (and (not shift) | |
8665 | idlwave-keyword-completion-adds-equal) | |
8666 | (insert "="))))) | |
8667 | ||
8668 | (defun idlwave-list-buffer-load-path-shadows (&optional arg) | |
8669 | "List the load path shadows of all routines defined in current buffer." | |
8670 | (interactive "P") | |
8671 | (idlwave-routines) | |
8672 | (if (eq major-mode 'idlwave-mode) | |
8673 | (idlwave-list-load-path-shadows | |
8674 | nil (idlwave-update-current-buffer-info 'save-buffer) | |
8675 | "in current buffer") | |
8676 | (error "Current buffer is not in idlwave-mode"))) | |
8677 | ||
8678 | (defun idlwave-list-shell-load-path-shadows (&optional arg) | |
8679 | "List the load path shadows of all routines compiled under the shell. | |
8680 | This is very useful for checking an IDL application. Just compile the | |
8681 | application, do RESOLVE_ALL, and `C-c C-i' to compile all referenced | |
8682 | routines and update IDLWAVE internal info. Then check for shadowing | |
8683 | with this command." | |
8684 | (interactive "P") | |
8685 | (cond | |
8686 | ((or (not (fboundp 'idlwave-shell-is-running)) | |
8687 | (not (idlwave-shell-is-running))) | |
8688 | (error "Shell is not running")) | |
8689 | ((null idlwave-compiled-routines) | |
e8af40ee | 8690 | (error "No compiled routines. Maybe you need to update with `C-c C-i'")) |
15e42531 CD |
8691 | (t |
8692 | (idlwave-list-load-path-shadows nil idlwave-compiled-routines | |
8693 | "in the shell")))) | |
8694 | ||
8695 | (defun idlwave-list-all-load-path-shadows (&optional arg) | |
8696 | "List the load path shadows of all routines known to IDLWAVE." | |
8697 | (interactive "P") | |
8698 | (idlwave-list-load-path-shadows nil nil "globally")) | |
8699 | ||
8700 | (defun idlwave-list-load-path-shadows (arg &optional special-routines loc) | |
8701 | "List the routines which are defined multiple times. | |
8702 | Search the information IDLWAVE has about IDL routines for multiple | |
8703 | definitions. | |
8704 | When SPECIAL-ROUTINES in non-nil, only look for shadows of these routines. | |
8705 | ||
8706 | When IDL hits a routine call which is not defined, it will search on | |
8707 | the load path in order to find a definition. The output of this | |
8708 | command can be used to detect possible name clashes during this process." | |
8709 | (idlwave-routines) ; Make sure everything is loaded. | |
52a244eb | 8710 | (unless (or idlwave-user-catalog-routines idlwave-library-catalog-routines) |
4b1aaa8b | 8711 | (or (y-or-n-p |
52a244eb | 8712 | "You don't have any user or library catalogs. Continue anyway? ") |
15e42531 CD |
8713 | (error "Abort"))) |
8714 | (let* ((routines (append idlwave-system-routines | |
8715 | idlwave-compiled-routines | |
52a244eb S |
8716 | idlwave-library-catalog-routines |
8717 | idlwave-user-catalog-routines | |
15e42531 CD |
8718 | idlwave-buffer-routines |
8719 | nil)) | |
8720 | (km-prop (if (featurep 'xemacs) 'keymap 'local-map)) | |
8721 | (keymap (make-sparse-keymap)) | |
8722 | (props (list 'mouse-face 'highlight | |
8723 | km-prop keymap | |
4b1aaa8b | 8724 | 'help-echo "Mouse2: Find source")) |
15e42531 | 8725 | (nroutines (length (or special-routines routines))) |
f66f03de | 8726 | (step (/ nroutines 100)) |
15e42531 | 8727 | (n 0) |
15e42531 CD |
8728 | (cnt 0) |
8729 | (idlwave-sort-prefer-buffer-info nil) | |
8730 | routine twins dtwins twin done props1 lroutines) | |
8731 | ||
8732 | (if special-routines | |
8733 | ;; Just looking for shadows of a few special routines | |
8734 | (setq lroutines routines | |
8735 | routines special-routines)) | |
8736 | ||
8737 | (message "Sorting routines...") | |
8738 | (setq routines (sort routines | |
8739 | (lambda (a b) | |
8740 | (string< (downcase (idlwave-make-full-name | |
8741 | (nth 2 a) (car a))) | |
8742 | (downcase (idlwave-make-full-name | |
8743 | (nth 2 b) (car b))))))) | |
8744 | (message "Sorting routines...done") | |
8745 | ||
8746 | (define-key keymap (if (featurep 'xemacs) [(button2)] [(mouse-2)]) | |
4b1aaa8b | 8747 | (lambda (ev) |
15e42531 CD |
8748 | (interactive "e") |
8749 | (mouse-set-point ev) | |
8750 | (apply 'idlwave-do-find-module | |
8751 | (get-text-property (point) 'find-args)))) | |
8752 | (define-key keymap [(return)] | |
4b1aaa8b | 8753 | (lambda () |
15e42531 CD |
8754 | (interactive) |
8755 | (apply 'idlwave-do-find-module | |
8756 | (get-text-property (point) 'find-args)))) | |
8757 | (message "Compiling list...( 0%%)") | |
8758 | (save-excursion | |
8759 | (set-buffer (get-buffer-create "*Shadows*")) | |
8760 | (setq buffer-read-only nil) | |
8761 | (erase-buffer) | |
8762 | (while (setq routine (pop routines)) | |
f66f03de S |
8763 | (if (= (mod (setq n (1+ n)) step) 0) |
8764 | (message "Compiling list...(%2d%%)" (/ (* n 100) nroutines))) | |
8765 | ||
15e42531 CD |
8766 | ;; Get a list of all twins |
8767 | (setq twins (idlwave-routine-twins routine (or lroutines routines))) | |
8768 | (if (memq routine done) | |
8769 | (setq dtwins nil) | |
8770 | (setq dtwins (idlwave-study-twins twins))) | |
5e72c6b2 | 8771 | ;; Mark all twins as dealt with |
15e42531 CD |
8772 | (setq done (append twins done)) |
8773 | (when (or (> (length dtwins) 1) | |
52a244eb S |
8774 | (> (idlwave-count-memq 'lib (nth 2 (car dtwins))) 1) |
8775 | (> (idlwave-count-memq 'user (nth 2 (car dtwins))) 1) | |
8776 | (> (idlwave-count-memq 'buffer (nth 2 (car dtwins))) 1)) | |
15e42531 CD |
8777 | (incf cnt) |
8778 | (insert (format "\n%s%s" | |
4b1aaa8b | 8779 | (idlwave-make-full-name (nth 2 routine) |
52a244eb | 8780 | (car routine)) |
15e42531 CD |
8781 | (if (eq (nth 1 routine) 'fun) "()" ""))) |
8782 | (while (setq twin (pop dtwins)) | |
8783 | (setq props1 (append (list 'find-args | |
4b1aaa8b PE |
8784 | (list (nth 0 routine) |
8785 | (nth 1 routine) | |
52a244eb | 8786 | (nth 2 routine))) |
15e42531 CD |
8787 | props)) |
8788 | (idlwave-insert-source-location "\n - " twin props1)))) | |
8789 | (goto-char (point-min)) | |
8790 | (setq buffer-read-only t)) | |
8791 | (setq loc (or loc "")) | |
8792 | (if (> cnt 0) | |
8793 | (progn | |
8794 | (display-buffer (get-buffer "*Shadows*")) | |
8795 | (message "%d case%s of shadowing found %s" | |
8796 | cnt (if (= cnt 1) "" "s") loc)) | |
8797 | (message "No shadowing conflicts found %s" loc)))) | |
8798 | ||
8799 | (defun idlwave-print-source (routine) | |
8800 | (let* ((source (nth 3 routine)) | |
8801 | (stype (car source)) | |
52a244eb S |
8802 | (sfile (idlwave-routine-source-file source))) |
8803 | (if (idlwave-syslib-p sfile) (setq stype 'syslib)) | |
15e42531 CD |
8804 | (if (and (eq stype 'compiled) |
8805 | (or (not (stringp sfile)) | |
8806 | (not (string-match "\\S-" sfile)))) | |
8807 | (setq stype 'unresolved)) | |
4b1aaa8b | 8808 | (princ (format " %-10s %s\n" |
15e42531 CD |
8809 | stype |
8810 | (if sfile sfile "No source code available"))))) | |
8811 | ||
8812 | (defun idlwave-routine-twins (entry &optional list) | |
8813 | "Return all twin entries of ENTRY in LIST. | |
8814 | LIST defaults to `idlwave-routines'. | |
8815 | Twin entries are those which have the same name, type, and class. | |
8816 | ENTRY will also be returned, as the first item of this list." | |
8817 | (let* ((name (car entry)) | |
8818 | (type (nth 1 entry)) | |
8819 | (class (nth 2 entry)) | |
8820 | (candidates (idlwave-all-assq name (or list (idlwave-routines)))) | |
8821 | twins candidate) | |
8822 | (while (setq candidate (pop candidates)) | |
8823 | (if (and (not (eq candidate entry)) | |
8824 | (eq type (nth 1 candidate)) | |
8825 | (eq class (nth 2 candidate))) | |
8826 | (push candidate twins))) | |
4b1aaa8b | 8827 | (if (setq candidate (idlwave-rinfo-assq name type class |
15e42531 CD |
8828 | idlwave-unresolved-routines)) |
8829 | (push candidate twins)) | |
8830 | (cons entry (nreverse twins)))) | |
8831 | ||
8832 | (defun idlwave-study-twins (entries) | |
4b1aaa8b | 8833 | "Return dangerous twins of first entry in ENTRIES. |
52a244eb S |
8834 | Dangerous twins are routines with same name, but in different files on |
8835 | the load path. If a file is in the system library and has an entry in | |
8836 | the `idlwave-system-routines' list, we omit the latter as | |
8837 | non-dangerous because many IDL routines are implemented as library | |
8838 | routines, and may have been scanned." | |
15e42531 | 8839 | (let* ((entry (car entries)) |
4b1aaa8b | 8840 | (name (car entry)) ; |
15e42531 CD |
8841 | (type (nth 1 entry)) ; Must be bound for |
8842 | (class (nth 2 entry)) ; idlwave-routine-twin-compare | |
8843 | (cnt 0) | |
52a244eb | 8844 | source type type-cons file alist syslibp key) |
15e42531 CD |
8845 | (while (setq entry (pop entries)) |
8846 | (incf cnt) | |
8847 | (setq source (nth 3 entry) | |
8848 | type (car source) | |
52a244eb S |
8849 | type-cons (cons type (nth 3 source)) |
8850 | file (idlwave-routine-source-file source)) | |
8851 | ||
15e42531 CD |
8852 | ;; Make KEY to index entry properly |
8853 | (setq key (cond ((eq type 'system) type) | |
8854 | (file (file-truename file)) | |
8855 | (t 'unresolved))) | |
52a244eb S |
8856 | |
8857 | ;; Check for an entry in the system library | |
4b1aaa8b | 8858 | (if (and file |
15e42531 CD |
8859 | (not syslibp) |
8860 | (idlwave-syslib-p file)) | |
15e42531 | 8861 | (setq syslibp t)) |
4b1aaa8b | 8862 | |
52a244eb S |
8863 | ;; If there's more than one matching entry for the same file, just |
8864 | ;; append the type-cons to the type list. | |
15e42531 | 8865 | (if (setq entry (assoc key alist)) |
52a244eb S |
8866 | (push type-cons (nth 2 entry)) |
8867 | (push (list key file (list type-cons)) alist))) | |
4b1aaa8b | 8868 | |
15e42531 | 8869 | (setq alist (nreverse alist)) |
4b1aaa8b | 8870 | |
15e42531 | 8871 | (when syslibp |
52a244eb S |
8872 | ;; File is in system *library* - remove any 'system entry |
8873 | (setq alist (delq (assq 'system alist) alist))) | |
4b1aaa8b | 8874 | |
52a244eb S |
8875 | ;; If 'system remains and we've scanned the syslib, it's a builtin |
8876 | ;; (rather than a !DIR/lib/.pro file bundled as source). | |
15e42531 CD |
8877 | (when (and (idlwave-syslib-scanned-p) |
8878 | (setq entry (assoc 'system alist))) | |
8879 | (setcar entry 'builtin)) | |
8880 | (sort alist 'idlwave-routine-twin-compare))) | |
8881 | ||
15e42531 CD |
8882 | (defvar type) |
8883 | (defvar class) | |
8884 | (defvar idlwave-sort-prefer-buffer-info t | |
8885 | "Internal variable used to influence `idlwave-routine-twin-compare'.") | |
8886 | ||
8887 | (defmacro idlwave-xor (a b) | |
8888 | `(and (or ,a ,b) | |
8889 | (not (and ,a ,b)))) | |
8890 | ||
8891 | (defun idlwave-routine-entry-compare (a b) | |
8892 | "Compare two routine info entries for sortiung. This is the general case. | |
8893 | It first compates class, names, and type. If it turns out that A and B | |
cef6cafe | 8894 | are twins (same name, class, and type), calls another routine which |
15e42531 CD |
8895 | compares twins on the basis of their file names and path locations." |
8896 | (let ((name (car a)) (type (nth 1 a)) (class (nth 2 a))) | |
8897 | (cond | |
8898 | ((not (equal (idlwave-downcase-safe class) | |
8899 | (idlwave-downcase-safe (nth 2 b)))) | |
8900 | ;; Class decides | |
8901 | (cond ((null (nth 2 b)) nil) | |
8902 | ((null class) t) | |
8903 | (t (string< (downcase class) (downcase (nth 2 b)))))) | |
8904 | ((not (equal (downcase name) (downcase (car b)))) | |
8905 | ;; Name decides | |
8906 | (string< (downcase name) (downcase (car b)))) | |
8907 | ((not (eq type (nth 1 b))) | |
8908 | ;; Type decides | |
8909 | (< (if (eq type 'fun) 1 0) (if (eq (nth 1 b) 'fun) 1 0))) | |
4b1aaa8b | 8910 | (t |
15e42531 CD |
8911 | ;; A and B are twins - so the decision is more complicated. |
8912 | ;; Call twin-compare with the proper arguments. | |
8913 | (idlwave-routine-entry-compare-twins a b))))) | |
8914 | ||
8915 | (defun idlwave-routine-entry-compare-twins (a b) | |
52a244eb S |
8916 | "Compare two routine entries, under the assumption that they are |
8917 | twins. This basically calls `idlwave-routine-twin-compare' with the | |
8918 | correct args." | |
8919 | (let* ((name (car a)) (type (nth 1 a)) (class (nth 2 a)) ; needed outside | |
8920 | (asrc (nth 3 a)) | |
8921 | (atype (car asrc)) | |
8922 | (bsrc (nth 3 b)) | |
8923 | (btype (car bsrc)) | |
8924 | (afile (idlwave-routine-source-file asrc)) | |
8925 | (bfile (idlwave-routine-source-file bsrc))) | |
15e42531 CD |
8926 | (idlwave-routine-twin-compare |
8927 | (if (stringp afile) | |
8928 | (list (file-truename afile) afile (list atype)) | |
8929 | (list atype afile (list atype))) | |
8930 | (if (stringp bfile) | |
8931 | (list (file-truename bfile) bfile (list btype)) | |
8932 | (list btype bfile (list btype)))) | |
8933 | )) | |
8934 | ||
8935 | (defun idlwave-routine-twin-compare (a b) | |
8936 | "Compare two routine twin entries for sorting. | |
8937 | In here, A and B are not normal routine info entries, but special | |
8938 | lists (KEY FILENAME (TYPES...)). | |
8939 | This expects NAME TYPE CLASS to be bound to the right values." | |
8940 | (let* (;; Dis-assemble entries | |
8941 | (akey (car a)) (bkey (car b)) | |
8942 | (afile (nth 1 a)) (bfile (nth 1 b)) | |
8943 | (atypes (nth 2 a)) (btypes (nth 2 b)) | |
8944 | ;; System routines? | |
8945 | (asysp (memq akey '(builtin system))) | |
8946 | (bsysp (memq bkey '(builtin system))) | |
8947 | ;; Compiled routines? | |
8948 | (acompp (memq 'compiled atypes)) | |
8949 | (bcompp (memq 'compiled btypes)) | |
8950 | ;; Unresolved? | |
8951 | (aunresp (or (eq akey 'unresolved) | |
8952 | (and acompp (not afile)))) | |
8953 | (bunresp (or (eq bkey 'unresolved) | |
8954 | (and bcompp (not bfile)))) | |
8955 | ;; Buffer info available? | |
8956 | (abufp (memq 'buffer atypes)) | |
8957 | (bbufp (memq 'buffer btypes)) | |
8958 | ;; On search path? | |
8959 | (tpath-alist (idlwave-true-path-alist)) | |
52a244eb S |
8960 | (apathp (and (stringp akey) |
8961 | (assoc (file-name-directory akey) tpath-alist))) | |
4b1aaa8b | 8962 | (bpathp (and (stringp bkey) |
52a244eb | 8963 | (assoc (file-name-directory bkey) tpath-alist))) |
15e42531 CD |
8964 | ;; How early on search path? High number means early since we |
8965 | ;; measure the tail of the path list | |
8966 | (anpath (length (memq apathp tpath-alist))) | |
8967 | (bnpath (length (memq bpathp tpath-alist))) | |
8968 | ;; Look at file names | |
8969 | (aname (if (stringp afile) (downcase (file-name-nondirectory afile)) "")) | |
8970 | (bname (if (stringp bfile) (downcase (file-name-nondirectory bfile)) "")) | |
8971 | (fname-re (if class (format "\\`%s__\\(%s\\|define\\)\\.pro\\'" | |
8972 | (regexp-quote (downcase class)) | |
8973 | (regexp-quote (downcase name))) | |
8974 | (format "\\`%s\\.pro" (regexp-quote (downcase name))))) | |
8975 | ;; Is file name derived from the routine name? | |
8976 | ;; Method file or class definition file? | |
8977 | (anamep (string-match fname-re aname)) | |
8978 | (adefp (and class anamep (string= "define" (match-string 1 aname)))) | |
8979 | (bnamep (string-match fname-re bname)) | |
8980 | (bdefp (and class bnamep (string= "define" (match-string 1 bname))))) | |
8981 | ||
8982 | ;; Now: follow JD's ideas about sorting. Looks really simple now, | |
8983 | ;; doesn't it? The difficult stuff is hidden above... | |
8984 | (cond | |
8985 | ((idlwave-xor asysp bsysp) asysp) ; System entries first | |
8986 | ((idlwave-xor aunresp bunresp) bunresp) ; Unresolved last | |
8987 | ((and idlwave-sort-prefer-buffer-info | |
8988 | (idlwave-xor abufp bbufp)) abufp) ; Buffers before non-buffers | |
8989 | ((idlwave-xor acompp bcompp) acompp) ; Compiled entries | |
8990 | ((idlwave-xor apathp bpathp) apathp) ; Library before non-library | |
8991 | ((idlwave-xor anamep bnamep) anamep) ; Correct file names first | |
8992 | ((and class anamep bnamep ; both file names match -> | |
8993 | (idlwave-xor adefp bdefp)) bdefp) ; __define after __method | |
8994 | ((> anpath bnpath) t) ; Who is first on path? | |
8995 | (t nil)))) ; Default | |
8996 | ||
52a244eb | 8997 | (defun idlwave-routine-source-file (source) |
4b1aaa8b | 8998 | (if (nth 2 source) |
52a244eb S |
8999 | (expand-file-name (nth 1 source) (nth 2 source)) |
9000 | (nth 1 source))) | |
9001 | ||
15e42531 CD |
9002 | (defun idlwave-downcase-safe (string) |
9003 | "Donwcase if string, else return unchanged." | |
9004 | (if (stringp string) | |
9005 | (downcase string) | |
9006 | string)) | |
9007 | ||
9008 | (defun idlwave-count-eq (elt list) | |
9009 | "How often is ELT in LIST?" | |
9010 | (length (delq nil (mapcar (lambda (x) (eq x elt)) list)))) | |
9011 | ||
52a244eb S |
9012 | (defun idlwave-count-memq (elt alist) |
9013 | "How often is ELT a key in ALIST?" | |
9014 | (length (delq nil (mapcar (lambda (x) (eq (car x) elt)) alist)))) | |
9015 | ||
15e42531 | 9016 | (defun idlwave-syslib-p (file) |
52a244eb | 9017 | "Non-nil if FILE is in the system library." |
15e42531 CD |
9018 | (let* ((true-syslib (file-name-as-directory |
9019 | (file-truename | |
9020 | (expand-file-name "lib" (idlwave-sys-dir))))) | |
9021 | (true-file (file-truename file))) | |
9022 | (string-match (concat "^" (regexp-quote true-syslib)) true-file))) | |
9023 | ||
9024 | (defun idlwave-lib-p (file) | |
9025 | "Non-nil if file is in the library" | |
9026 | (let ((true-dir (file-name-directory (file-truename file)))) | |
9027 | (assoc true-dir (idlwave-true-path-alist)))) | |
9028 | ||
52a244eb S |
9029 | (defun idlwave-path-alist-add-flag (list-entry flag) |
9030 | "Add a flag to the path list entry, if not set." | |
9031 | (let ((flags (cdr list-entry))) | |
9032 | (add-to-list 'flags flag) | |
9033 | (setcdr list-entry flags))) | |
9034 | ||
9035 | (defun idlwave-path-alist-remove-flag (list-entry flag) | |
9036 | "Remove a flag to the path list entry, if set." | |
9037 | (let ((flags (delq flag (cdr list-entry)))) | |
9038 | (setcdr list-entry flags))) | |
9039 | ||
15e42531 CD |
9040 | (defun idlwave-true-path-alist () |
9041 | "Return `idlwave-path-alist' alist with true-names. | |
52a244eb | 9042 | Info is cached, but relies on the functions setting `idlwave-path-alist' |
15e42531 CD |
9043 | to reset the variable `idlwave-true-path-alist' to nil." |
9044 | (or idlwave-true-path-alist | |
9045 | (setq idlwave-true-path-alist | |
9046 | (mapcar (lambda(x) (cons | |
9047 | (file-name-as-directory | |
9048 | (file-truename | |
9049 | (directory-file-name | |
9050 | (car x)))) | |
9051 | (cdr x))) | |
9052 | idlwave-path-alist)))) | |
9053 | ||
9054 | (defun idlwave-syslib-scanned-p () | |
9055 | "Non-nil if the system lib file !DIR/lib has been scanned." | |
9056 | (let* ((true-syslib (file-name-as-directory | |
9057 | (file-truename | |
9058 | (expand-file-name "lib" (idlwave-sys-dir)))))) | |
9059 | (cdr (assoc true-syslib (idlwave-true-path-alist))))) | |
9060 | ||
9061 | ;; ---------------------------------------------------------------------------- | |
9062 | ;; | |
9063 | ;; Online Help display | |
9064 | ||
f32b3b91 CD |
9065 | |
9066 | ;; ---------------------------------------------------------------------------- | |
9067 | ;; | |
9068 | ;; Additions for use with imenu.el and func-menu.el | |
9069 | ;; (pop-up a list of IDL units in the current file). | |
9070 | ;; | |
9071 | ||
9072 | (defun idlwave-prev-index-position () | |
9073 | "Search for the previous procedure or function. | |
9074 | Return nil if not found. For use with imenu.el." | |
9075 | (save-match-data | |
9076 | (cond | |
9077 | ((idlwave-find-key "\\<\\(pro\\|function\\)\\>" -1 'nomark)) | |
9078 | ;; ((idlwave-find-key idlwave-begin-unit-reg 1 'nomark) | |
9079 | (t nil)))) | |
9080 | ||
9081 | (defun idlwave-unit-name () | |
9082 | "Return the unit name. | |
9083 | Assumes that point is at the beginning of the unit as found by | |
9084 | `idlwave-prev-index-position'." | |
9085 | (forward-sexp 2) | |
9086 | (forward-sexp -1) | |
9087 | (let ((begin (point))) | |
4b1aaa8b | 9088 | (re-search-forward |
52a244eb | 9089 | "[a-zA-Z_][a-zA-Z0-9$_]+\\(::[a-zA-Z_][a-zA-Z0-9$_]+\\)?") |
f32b3b91 CD |
9090 | (if (fboundp 'buffer-substring-no-properties) |
9091 | (buffer-substring-no-properties begin (point)) | |
9092 | (buffer-substring begin (point))))) | |
9093 | ||
facebc7b S |
9094 | (defalias 'idlwave-function-menu |
9095 | (condition-case nil | |
f32b3b91 CD |
9096 | (progn |
9097 | (require 'func-menu) | |
facebc7b S |
9098 | 'function-menu) |
9099 | (error (condition-case nil | |
9100 | (progn | |
9101 | (require 'imenu) | |
9102 | 'imenu) | |
9103 | (error nil))))) | |
f32b3b91 | 9104 | |
52a244eb | 9105 | ;; Here we hack func-menu.el in order to support this new mode. |
f32b3b91 CD |
9106 | ;; The latest versions of func-menu.el already have this stuff in, so |
9107 | ;; we hack only if it is not already there. | |
9108 | (when (fboundp 'eval-after-load) | |
9109 | (eval-after-load "func-menu" | |
9110 | '(progn | |
9111 | (or (assq 'idlwave-mode fume-function-name-regexp-alist) | |
9112 | (not (boundp 'fume-function-name-regexp-idl)) ; avoid problems | |
9113 | (setq fume-function-name-regexp-alist | |
9114 | (cons '(idlwave-mode . fume-function-name-regexp-idl) | |
9115 | fume-function-name-regexp-alist))) | |
9116 | (or (assq 'idlwave-mode fume-find-function-name-method-alist) | |
9117 | (not (fboundp 'fume-find-next-idl-function-name)) ; avoid problems | |
9118 | (setq fume-find-function-name-method-alist | |
9119 | (cons '(idlwave-mode . fume-find-next-idl-function-name) | |
9120 | fume-find-function-name-method-alist)))))) | |
9121 | ||
9122 | (defun idlwave-edit-in-idlde () | |
9123 | "Edit the current file in IDL Development environment." | |
9124 | (interactive) | |
9125 | (start-process "idldeclient" nil | |
9126 | idlwave-shell-explicit-file-name "-c" "-e" | |
f66f03de | 9127 | (buffer-file-name))) |
4b1aaa8b | 9128 | |
f66f03de | 9129 | (defvar idlwave-help-use-assistant) |
f32b3b91 CD |
9130 | (defun idlwave-launch-idlhelp () |
9131 | "Start the IDLhelp application." | |
9132 | (interactive) | |
f66f03de S |
9133 | (if idlwave-help-use-assistant |
9134 | (idlwave-help-assistant-raise) | |
9135 | (start-process "idlhelp" nil idlwave-help-application))) | |
4b1aaa8b | 9136 | |
f32b3b91 CD |
9137 | ;; Menus - using easymenu.el |
9138 | (defvar idlwave-mode-menu-def | |
9139 | `("IDLWAVE" | |
9140 | ["PRO/FUNC menu" idlwave-function-menu t] | |
9141 | ("Motion" | |
9142 | ["Subprogram Start" idlwave-beginning-of-subprogram t] | |
9143 | ["Subprogram End" idlwave-end-of-subprogram t] | |
9144 | ["Block Start" idlwave-beginning-of-block t] | |
9145 | ["Block End" idlwave-end-of-block t] | |
9146 | ["Up Block" idlwave-backward-up-block t] | |
9147 | ["Down Block" idlwave-down-block t] | |
9148 | ["Skip Block Backward" idlwave-backward-block t] | |
9149 | ["Skip Block Forward" idlwave-forward-block t]) | |
9150 | ("Mark" | |
9151 | ["Subprogram" idlwave-mark-subprogram t] | |
9152 | ["Block" idlwave-mark-block t] | |
9153 | ["Header" idlwave-mark-doclib t]) | |
9154 | ("Format" | |
4b1aaa8b | 9155 | ["Indent Entire Statement" idlwave-indent-statement |
f66f03de | 9156 | :active t :keys "C-u \\[indent-for-tab-command]" ] |
f32b3b91 | 9157 | ["Indent Subprogram" idlwave-indent-subprogram t] |
f66f03de | 9158 | ["(Un)Comment Region" idlwave-toggle-comment-region t] |
f32b3b91 CD |
9159 | ["Continue/Split line" idlwave-split-line t] |
9160 | "--" | |
9161 | ["Toggle Auto Fill" idlwave-auto-fill-mode :style toggle | |
9162 | :selected (symbol-value idlwave-fill-function)]) | |
9163 | ("Templates" | |
9164 | ["Procedure" idlwave-procedure t] | |
9165 | ["Function" idlwave-function t] | |
9166 | ["Doc Header" idlwave-doc-header t] | |
9167 | ["Log" idlwave-doc-modification t] | |
9168 | "--" | |
9169 | ["Case" idlwave-case t] | |
9170 | ["For" idlwave-for t] | |
9171 | ["Repeat" idlwave-repeat t] | |
9172 | ["While" idlwave-while t] | |
9173 | "--" | |
9174 | ["Close Block" idlwave-close-block t]) | |
15e42531 | 9175 | ("Completion" |
f32b3b91 | 9176 | ["Complete" idlwave-complete t] |
f66f03de | 9177 | ("Complete Specific" |
f32b3b91 CD |
9178 | ["1 Procedure Name" (idlwave-complete 'procedure) t] |
9179 | ["2 Procedure Keyword" (idlwave-complete 'procedure-keyword) t] | |
9180 | "--" | |
9181 | ["3 Function Name" (idlwave-complete 'function) t] | |
9182 | ["4 Function Keyword" (idlwave-complete 'function-keyword) t] | |
9183 | "--" | |
9184 | ["5 Procedure Method Name" (idlwave-complete 'procedure-method) t] | |
9185 | ["6 Procedure Method Keyword" (idlwave-complete 'procedure-method-keyword) t] | |
9186 | "--" | |
9187 | ["7 Function Method Name" (idlwave-complete 'function-method) t] | |
9188 | ["8 Function Method Keyword" (idlwave-complete 'function-method-keyword) t] | |
9189 | "--" | |
15e42531 CD |
9190 | ["9 Class Name" idlwave-complete-class t])) |
9191 | ("Routine Info" | |
f32b3b91 | 9192 | ["Show Routine Info" idlwave-routine-info t] |
52a244eb | 9193 | ["Online Context Help" idlwave-context-help t] |
f32b3b91 CD |
9194 | "--" |
9195 | ["Find Routine Source" idlwave-find-module t] | |
15e42531 | 9196 | ["Resolve Routine" idlwave-resolve (featurep 'idlw-shell)] |
f32b3b91 CD |
9197 | "--" |
9198 | ["Update Routine Info" idlwave-update-routine-info t] | |
f66f03de | 9199 | ["Rescan XML Help Catalog" idlwave-convert-xml-system-routine-info t] |
f32b3b91 | 9200 | "--" |
52a244eb S |
9201 | "IDL User Catalog" |
9202 | ["Select Catalog Directories" (idlwave-create-user-catalog-file nil) t] | |
15e42531 | 9203 | ["Scan Directories" (idlwave-update-routine-info '(16)) |
5e72c6b2 S |
9204 | (and idlwave-path-alist (not idlwave-catalog-process))] |
9205 | ["Scan Directories &" (idlwave-update-routine-info '(64)) | |
9206 | (and idlwave-path-alist (not idlwave-catalog-process))] | |
15e42531 CD |
9207 | "--" |
9208 | "Routine Shadows" | |
9209 | ["Check Current Buffer" idlwave-list-buffer-load-path-shadows t] | |
9210 | ["Check Compiled Routines" idlwave-list-shell-load-path-shadows t] | |
9211 | ["Check Everything" idlwave-list-all-load-path-shadows t]) | |
9212 | ("Misc" | |
9213 | ["Kill auto-created buffers" idlwave-kill-autoloaded-buffers t] | |
9214 | "--" | |
9215 | ["Insert TAB character" idlwave-hard-tab t]) | |
f32b3b91 CD |
9216 | "--" |
9217 | ("External" | |
f32b3b91 CD |
9218 | ["Start IDL shell" idlwave-shell t] |
9219 | ["Edit file in IDLDE" idlwave-edit-in-idlde t] | |
9220 | ["Launch IDL Help" idlwave-launch-idlhelp t]) | |
9221 | "--" | |
9222 | ("Customize" | |
9223 | ["Browse IDLWAVE Group" idlwave-customize t] | |
9224 | "--" | |
4b1aaa8b | 9225 | ["Build Full Customize Menu" idlwave-create-customize-menu |
f32b3b91 CD |
9226 | (fboundp 'customize-menu-create)]) |
9227 | ("Documentation" | |
9228 | ["Describe Mode" describe-mode t] | |
9229 | ["Abbreviation List" idlwave-list-abbrevs t] | |
9230 | "--" | |
9231 | ["Commentary in idlwave.el" idlwave-show-commentary t] | |
595ab50b | 9232 | ["Commentary in idlw-shell.el" idlwave-shell-show-commentary t] |
f32b3b91 CD |
9233 | "--" |
9234 | ["Info" idlwave-info t] | |
9235 | "--" | |
8c43762b | 9236 | ["Help with Topic" idlwave-help-assistant-help-with-topic |
e08734e2 | 9237 | idlwave-help-use-assistant] |
f32b3b91 CD |
9238 | ["Launch IDL Help" idlwave-launch-idlhelp t]))) |
9239 | ||
9240 | (defvar idlwave-mode-debug-menu-def | |
9241 | '("Debug" | |
9242 | ["Start IDL shell" idlwave-shell t] | |
9243 | ["Save and .RUN buffer" idlwave-shell-save-and-run | |
4b1aaa8b | 9244 | (and (boundp 'idlwave-shell-automatic-start) |
f32b3b91 CD |
9245 | idlwave-shell-automatic-start)])) |
9246 | ||
9247 | (if (or (featurep 'easymenu) (load "easymenu" t)) | |
9248 | (progn | |
4b1aaa8b PE |
9249 | (easy-menu-define idlwave-mode-menu idlwave-mode-map |
9250 | "IDL and WAVE CL editing menu" | |
f32b3b91 | 9251 | idlwave-mode-menu-def) |
4b1aaa8b PE |
9252 | (easy-menu-define idlwave-mode-debug-menu idlwave-mode-map |
9253 | "IDL and WAVE CL editing menu" | |
f32b3b91 CD |
9254 | idlwave-mode-debug-menu-def))) |
9255 | ||
9256 | (defun idlwave-customize () | |
9257 | "Call the customize function with idlwave as argument." | |
9258 | (interactive) | |
4b1aaa8b | 9259 | ;; Try to load the code for the shell, so that we can customize it |
f32b3b91 | 9260 | ;; as well. |
22d5821d CD |
9261 | (or (featurep 'idlw-shell) |
9262 | (load "idlw-shell" t)) | |
f32b3b91 CD |
9263 | (customize-browse 'idlwave)) |
9264 | ||
9265 | (defun idlwave-create-customize-menu () | |
9266 | "Create a full customization menu for IDLWAVE, insert it into the menu." | |
9267 | (interactive) | |
9268 | (if (fboundp 'customize-menu-create) | |
9269 | (progn | |
4b1aaa8b | 9270 | ;; Try to load the code for the shell, so that we can customize it |
f32b3b91 | 9271 | ;; as well. |
22d5821d CD |
9272 | (or (featurep 'idlw-shell) |
9273 | (load "idlw-shell" t)) | |
4b1aaa8b | 9274 | (easy-menu-change |
f32b3b91 CD |
9275 | '("IDLWAVE") "Customize" |
9276 | `(["Browse IDLWAVE group" idlwave-customize t] | |
9277 | "--" | |
9278 | ,(customize-menu-create 'idlwave) | |
9279 | ["Set" Custom-set t] | |
9280 | ["Save" Custom-save t] | |
9281 | ["Reset to Current" Custom-reset-current t] | |
9282 | ["Reset to Saved" Custom-reset-saved t] | |
9283 | ["Reset to Standard Settings" Custom-reset-standard t])) | |
9284 | (message "\"IDLWAVE\"-menu now contains full customization menu")) | |
9285 | (error "Cannot expand menu (outdated version of cus-edit.el)"))) | |
9286 | ||
9287 | (defun idlwave-show-commentary () | |
9288 | "Use the finder to view the file documentation from `idlwave.el'." | |
9289 | (interactive) | |
f32b3b91 CD |
9290 | (finder-commentary "idlwave.el")) |
9291 | ||
9292 | (defun idlwave-shell-show-commentary () | |
595ab50b | 9293 | "Use the finder to view the file documentation from `idlw-shell.el'." |
f32b3b91 | 9294 | (interactive) |
595ab50b | 9295 | (finder-commentary "idlw-shell.el")) |
f32b3b91 CD |
9296 | |
9297 | (defun idlwave-info () | |
9298 | "Read documentation for IDLWAVE in the info system." | |
9299 | (interactive) | |
d6a277d0 | 9300 | (info "idlwave")) |
f32b3b91 CD |
9301 | |
9302 | (defun idlwave-list-abbrevs (arg) | |
9303 | "Show the code abbreviations define in IDLWAVE mode. | |
9304 | This lists all abbrevs where the replacement text differs from the input text. | |
9305 | These are the ones the users want to learn to speed up their writing. | |
9306 | ||
9307 | The function does *not* list abbrevs which replace a word with itself | |
9308 | to call a hook. These hooks are used to change the case of words or | |
9309 | to blink the matching `begin', and the user does not need to know them. | |
9310 | ||
9311 | With arg, list all abbrevs with the corresponding hook. | |
9312 | ||
9313 | This function was written since `list-abbrevs' looks terrible for IDLWAVE mode." | |
9314 | ||
9315 | (interactive "P") | |
9316 | (let ((table (symbol-value 'idlwave-mode-abbrev-table)) | |
9317 | abbrevs | |
9318 | str rpl func fmt (len-str 0) (len-rpl 0)) | |
4b1aaa8b | 9319 | (mapatoms |
f32b3b91 CD |
9320 | (lambda (sym) |
9321 | (if (symbol-value sym) | |
9322 | (progn | |
9323 | (setq str (symbol-name sym) | |
9324 | rpl (symbol-value sym) | |
9325 | func (symbol-function sym)) | |
9326 | (if arg | |
9327 | (setq func (prin1-to-string func)) | |
9328 | (if (and (listp func) (stringp (nth 2 func))) | |
9329 | (setq rpl (concat "EVAL: " (nth 2 func)) | |
9330 | func "") | |
9331 | (setq func ""))) | |
9332 | (if (or arg (not (string= rpl str))) | |
9333 | (progn | |
9334 | (setq len-str (max len-str (length str))) | |
9335 | (setq len-rpl (max len-rpl (length rpl))) | |
9336 | (setq abbrevs (cons (list str rpl func) abbrevs))))))) | |
9337 | table) | |
9338 | ;; sort the list | |
9339 | (setq abbrevs (sort abbrevs (lambda (a b) (string< (car a) (car b))))) | |
9340 | ;; Make the format | |
9341 | (setq fmt (format "%%-%ds %%-%ds %%s\n" len-str len-rpl)) | |
9342 | (with-output-to-temp-buffer "*Help*" | |
9343 | (if arg | |
9344 | (progn | |
4b1aaa8b | 9345 | (princ "Abbreviations and Actions in IDLWAVE-Mode\n") |
f32b3b91 CD |
9346 | (princ "=========================================\n\n") |
9347 | (princ (format fmt "KEY" "REPLACE" "HOOK")) | |
9348 | (princ (format fmt "---" "-------" "----"))) | |
9349 | (princ "Code Abbreviations and Templates in IDLWAVE-Mode\n") | |
9350 | (princ "================================================\n\n") | |
9351 | (princ (format fmt "KEY" "ACTION" "")) | |
9352 | (princ (format fmt "---" "------" ""))) | |
9353 | (mapcar | |
9354 | (lambda (list) | |
9355 | (setq str (car list) | |
9356 | rpl (nth 1 list) | |
9357 | func (nth 2 list)) | |
9358 | (princ (format fmt str rpl func))) | |
9359 | abbrevs))) | |
9360 | ;; Make sure each abbreviation uses only one display line | |
9361 | (save-excursion | |
9362 | (set-buffer "*Help*") | |
9363 | (setq truncate-lines t))) | |
9364 | ||
5e72c6b2 S |
9365 | ;; Add .pro files to speedbar for support, if it's loaded |
9366 | (eval-after-load "speedbar" '(speedbar-add-supported-extension ".pro")) | |
9367 | ||
5e72c6b2 S |
9368 | ;; Set an idle timer to load the routine info. |
9369 | ;; Will only work on systems which support this. | |
9370 | (or idlwave-routines (idlwave-start-load-rinfo-timer)) | |
9371 | ||
15e42531 | 9372 | ;; Run the hook |
f32b3b91 CD |
9373 | (run-hooks 'idlwave-load-hook) |
9374 | ||
9375 | (provide 'idlwave) | |
9376 | ||
8df608c1 | 9377 | ;; arch-tag: f77f3b0c-c37c-424f-a328-0886fd42b6fb |
f32b3b91 | 9378 | ;;; idlwave.el ends here |