Commit | Line | Data |
---|---|---|
5e72c6b2 | 1 | ;; idlw-shell.el --- run IDL as an inferior process of Emacs. |
d7a0267c | 2 | |
73b0cd50 | 3 | ;; Copyright (C) 1999-2011 Free Software Foundation, Inc. |
5e72c6b2 | 4 | |
52a244eb S |
5 | ;; Authors: J.D. Smith <jdsmith@as.arizona.edu> |
6 | ;; Carsten Dominik <dominik@astro.uva.nl> | |
7 | ;; Chris Chase <chase@att.com> | |
5e72c6b2 | 8 | ;; Maintainer: J.D. Smith <jdsmith@as.arizona.edu> |
bd78fa1d | 9 | ;; Version: 6.1.22 |
8c7b4ec8 | 10 | ;; Keywords: processes |
aad4679e | 11 | ;; Package: idlwave |
8c7b4ec8 EZ |
12 | |
13 | ;; This file is part of GNU Emacs. | |
14 | ||
b1fc2b50 | 15 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
8c7b4ec8 | 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. | |
8c7b4ec8 EZ |
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/>. |
8c7b4ec8 EZ |
27 | |
28 | ;;; Commentary: | |
5e72c6b2 S |
29 | ;; |
30 | ;; This mode is for IDL version 5 or later. It should work on | |
31 | ;; Emacs>20.3 or XEmacs>20.4. | |
32 | ;; | |
dd5baa1a | 33 | ;; Runs IDL as an inferior process of Emacs, much like the Emacs |
8c7b4ec8 EZ |
34 | ;; `shell' or `telnet' commands. Provides command history and |
35 | ;; searching. Provides debugging commands available in buffers | |
36 | ;; visiting IDL procedure files, e.g., breakpoint setting, stepping, | |
37 | ;; execution until a certain line, printing expressions under point, | |
38 | ;; visual line pointer for current execution line, etc. | |
39 | ;; | |
40 | ;; Documentation should be available online with `M-x idlwave-info'. | |
5e72c6b2 S |
41 | ;; |
42 | ;; New versions of IDLWAVE, documentation, and more information | |
43 | ;; available from: | |
44 | ;; http://idlwave.org | |
45 | ;; | |
8c7b4ec8 EZ |
46 | ;; INSTALLATION: |
47 | ;; ============= | |
5cba7601 | 48 | ;; |
8c7b4ec8 EZ |
49 | ;; Follow the instructions in the INSTALL file of the distribution. |
50 | ;; In short, put this file on your load path and add the following | |
51 | ;; lines to your .emacs file: | |
52 | ;; | |
53 | ;; (autoload 'idlwave-shell "idlw-shell" "IDLWAVE Shell" t) | |
54 | ;; | |
55 | ;; | |
56 | ;; SOURCE | |
57 | ;; ====== | |
58 | ;; | |
59 | ;; The newest version of this file can be found on the maintainers | |
60 | ;; web site. | |
5cba7601 | 61 | ;; |
5e72c6b2 | 62 | ;; http://idlwave.org |
5cba7601 | 63 | ;; |
8c7b4ec8 EZ |
64 | ;; DOCUMENTATION |
65 | ;; ============= | |
66 | ;; | |
67 | ;; IDLWAVE is documented online in info format. | |
68 | ;; A printable version of the documentation is available from the | |
69 | ;; maintainers webpage (see under SOURCE) | |
70 | ;; | |
71 | ;; | |
72 | ;; KNOWN PROBLEMS | |
73 | ;; ============== | |
74 | ;; | |
8c7b4ec8 EZ |
75 | ;; Under XEmacs the Debug menu in the shell does not display the |
76 | ;; keybindings in the prefix map. There bindings are available anyway - so | |
77 | ;; it is a bug in XEmacs. | |
ca660d22 | 78 | ;; The Debug menu in source buffers *does* display the bindings correctly. |
8c7b4ec8 | 79 | ;; |
5cba7601 | 80 | ;; |
8c7b4ec8 EZ |
81 | ;; CUSTOMIZATION VARIABLES |
82 | ;; ======================= | |
83 | ;; | |
84 | ;; IDLWAVE has customize support - so if you want to learn about | |
85 | ;; the variables which control the behavior of the mode, use | |
86 | ;; `M-x idlwave-customize'. | |
87 | ;; | |
88 | ;;-------------------------------------------------------------------------- | |
89 | ;; | |
8c7b4ec8 EZ |
90 | \f |
91 | ;;; Code: | |
92 | ||
93 | (require 'comint) | |
94 | (require 'idlwave) | |
95 | ||
96 | (eval-when-compile (require 'cl)) | |
97 | ||
98 | (defvar idlwave-shell-have-new-custom nil) | |
8c7b4ec8 EZ |
99 | |
100 | ;;; Customizations: idlwave-shell group | |
101 | ||
76959b77 | 102 | ;; General/Misc. customizations |
8c7b4ec8 | 103 | (defgroup idlwave-shell-general-setup nil |
05a1abfc CD |
104 | "General setup of the Shell interaction for IDLWAVE/Shell." |
105 | :prefix "idlwave-shell" | |
8c7b4ec8 EZ |
106 | :group 'idlwave) |
107 | ||
3938cb82 | 108 | (defcustom idlwave-shell-prompt-pattern "^\r? ?IDL> " |
5cba7601 GM |
109 | "*Regexp to match IDL prompt at beginning of a line. |
110 | For example, \"^\r?IDL> \" or \"^\r?WAVE> \". | |
3938cb82 S |
111 | The \"^\r?\" is needed, to indicate the beginning of the line, with |
112 | optional return character (which IDL seems to output randomly). | |
5cba7601 | 113 | This variable is used to initialize `comint-prompt-regexp' in the |
8c7b4ec8 EZ |
114 | process buffer. |
115 | ||
116 | This is a fine thing to set in your `.emacs' file." | |
117 | :group 'idlwave-shell-general-setup | |
118 | :type 'regexp) | |
119 | ||
120 | (defcustom idlwave-shell-process-name "idl" | |
121 | "*Name to be associated with the IDL process. The buffer for the | |
122 | process output is made by surrounding this name with `*'s." | |
123 | :group 'idlwave-shell-general-setup | |
124 | :type 'string) | |
125 | ||
05a1abfc | 126 | ;; (defcustom idlwave-shell-automatic-start...) See idlwave.el |
8c7b4ec8 | 127 | |
f66f03de S |
128 | (defcustom idlwave-shell-use-dedicated-window nil |
129 | "*Non-nil means, never replace the shell frame with another buffer." | |
130 | :group 'idlwave-shell-general-setup | |
5cba7601 | 131 | :type 'boolean) |
f66f03de | 132 | |
8c7b4ec8 EZ |
133 | (defcustom idlwave-shell-use-dedicated-frame nil |
134 | "*Non-nil means, IDLWAVE should use a special frame to display shell buffer." | |
135 | :group 'idlwave-shell-general-setup | |
136 | :type 'boolean) | |
137 | ||
138 | (defcustom idlwave-shell-frame-parameters | |
139 | '((height . 30) (unsplittable . nil)) | |
140 | "The frame parameters for a dedicated idlwave-shell frame. | |
141 | See also `idlwave-shell-use-dedicated-frame'. | |
142 | The default makes the frame splittable, so that completion works correctly." | |
143 | :group 'idlwave-shell-general-setup | |
144 | :type '(repeat | |
145 | (cons symbol sexp))) | |
146 | ||
5e72c6b2 S |
147 | (defcustom idlwave-shell-raise-frame t |
148 | "*Non-nil means, `idlwave-shell' raises the frame showing the shell window." | |
149 | :group 'idlwave-shell-general-setup | |
150 | :type 'boolean) | |
151 | ||
05a1abfc CD |
152 | (defcustom idlwave-shell-arrows-do-history t |
153 | "*Non-nil means UP and DOWN arrows move through command history. | |
154 | This variable can have 3 values: | |
155 | nil Arrows just move the cursor | |
156 | t Arrows force the cursor back to the current command line and | |
157 | walk the history | |
158 | 'cmdline When the cursor is in the current command line, arrows walk the | |
159 | history. Everywhere else in the buffer, arrows move the cursor." | |
160 | :group 'idlwave-shell-general-setup | |
161 | :type '(choice | |
162 | (const :tag "never" nil) | |
163 | (const :tag "everywhere" t) | |
164 | (const :tag "in command line only" cmdline))) | |
165 | ||
5e72c6b2 | 166 | ;; FIXME: add comint-input-ring-size? |
5e72c6b2 | 167 | |
8c7b4ec8 | 168 | (defcustom idlwave-shell-use-toolbar t |
05a1abfc | 169 | "*Non-nil means, use the debugging toolbar in all IDL related buffers. |
ca660d22 CD |
170 | Starting the shell will then add the toolbar to all idlwave-mode buffers. |
171 | Exiting the shell will removed everywhere. | |
8c7b4ec8 | 172 | Available on XEmacs and on Emacs 21.x or later. |
ca660d22 CD |
173 | At any time you can toggle the display of the toolbar with |
174 | `C-c C-d C-t' (`idlwave-shell-toggle-toolbar')." | |
8c7b4ec8 EZ |
175 | :group 'idlwave-shell-general-setup |
176 | :type 'boolean) | |
177 | ||
178 | (defcustom idlwave-shell-temp-pro-prefix "/tmp/idltemp" | |
179 | "*The prefix for temporary IDL files used when compiling regions. | |
180 | It should be an absolute pathname. | |
5e72c6b2 | 181 | The full temporary file name is obtained by using `make-temp-file' |
8c7b4ec8 EZ |
182 | so that the name will be unique among multiple Emacs processes." |
183 | :group 'idlwave-shell-general-setup | |
184 | :type 'string) | |
185 | ||
186 | (defvar idlwave-shell-fix-inserted-breaks nil | |
187 | "*OBSOLETE VARIABLE, is no longer used. | |
188 | ||
189 | The documentation of this variable used to be: | |
190 | If non-nil then run `idlwave-shell-remove-breaks' to clean up IDL messages.") | |
191 | ||
192 | (defcustom idlwave-shell-prefix-key "\C-c\C-d" | |
193 | "*The prefix key for the debugging map `idlwave-shell-mode-prefix-map'. | |
194 | This variable must already be set when idlwave-shell.el is loaded. | |
05a1abfc | 195 | Setting it in the mode-hook is too late." |
8c7b4ec8 EZ |
196 | :group 'idlwave-shell-general-setup |
197 | :type 'string) | |
198 | ||
199 | (defcustom idlwave-shell-activate-prefix-keybindings t | |
200 | "Non-nil means, the debug commands will be bound to the prefix key. | |
201 | The prefix key itself is given in the option `idlwave-shell-prefix-key'. | |
202 | So by default setting a breakpoint will be on C-c C-d C-b." | |
203 | :group 'idlwave-shell-general-setup | |
204 | :type 'boolean) | |
205 | ||
52a244eb | 206 | (defcustom idlwave-shell-automatic-electric-debug 'breakpoint |
5cba7601 | 207 | "Enter the electric-debug minor mode automatically. |
52a244eb S |
208 | This occurs at a breakpoint or any other halt. The mode is exited |
209 | upon return to the main level. Can be set to 'breakpoint to enter | |
210 | electric debug mode only when breakpoints are tripped." | |
211 | :group 'idlwave-shell-general-setup | |
212 | :type '(choice | |
213 | (const :tag "never" nil) | |
214 | (const :tag "always" t) | |
215 | (const :tag "for breakpoints only" breakpoint))) | |
216 | ||
217 | (defcustom idlwave-shell-electric-zap-to-file t | |
218 | "When entering electric debug mode, select the window displaying the | |
219 | file at which point is stopped. This takes point away from the shell | |
220 | window, but is useful for stepping, etc." | |
221 | :group 'idlwave-shell-general-setup | |
222 | :type 'boolean) | |
223 | ||
05a1abfc CD |
224 | ;; (defcustom idlwave-shell-debug-modifiers... See idlwave.el |
225 | ||
226 | (defvar idlwave-shell-activate-alt-keybindings nil | |
227 | "Obsolete variable. See `idlwave-shell-debug-modifiers'.") | |
8c7b4ec8 EZ |
228 | |
229 | (defcustom idlwave-shell-use-truename nil | |
230 | "*Non-nil means, use use `file-truename' when looking for buffers. | |
231 | If this variable is non-nil, Emacs will use the function `file-truename' to | |
232 | resolve symbolic links in the file paths printed by e.g., STOP commands. | |
233 | This means, unvisited files will be loaded under their truename. | |
15e42531 | 234 | However, when a file is already visited under a different name, IDLWAVE will |
8c7b4ec8 EZ |
235 | reuse that buffer. |
236 | This option was once introduced in order to avoid multiple buffers visiting | |
237 | the same file. However, IDLWAVE no longer makes this mistake, so it is safe | |
238 | to set this option to nil." | |
239 | :group 'idlwave-shell-general-setup | |
240 | :type 'boolean) | |
241 | ||
dd5baa1a | 242 | (defcustom idlwave-shell-file-name-chars "~/A-Za-z0-9+:_.$#%={}\\- " |
8c7b4ec8 | 243 | "The characters allowed in file names, as a string. |
5a0c3f56 | 244 | Used for file name completion. Must not contain `'', `,' and `\"' |
8c7b4ec8 EZ |
245 | because these are used as separators by IDL." |
246 | :group 'idlwave-shell-general-setup | |
247 | :type 'string) | |
248 | ||
249 | (defcustom idlwave-shell-mode-hook '() | |
5a0c3f56 | 250 | "*Hook for customizing `idlwave-shell-mode'." |
8c7b4ec8 EZ |
251 | :group 'idlwave-shell-general-setup |
252 | :type 'hook) | |
253 | ||
76959b77 S |
254 | (defcustom idlwave-shell-graphics-window-size '(500 400) |
255 | "Size of IDL graphics windows popped up by special IDLWAVE command. | |
256 | The command is `C-c C-d C-f' and accepts as a prefix the window nr. | |
257 | A command like `WINDOW,N,xsize=XX,ysize=YY' is sent to IDL." | |
258 | :group 'idlwave-shell-general-setup | |
259 | :type '(list | |
260 | (integer :tag "x size") | |
261 | (integer :tag "y size"))) | |
262 | ||
52a244eb | 263 | |
76959b77 S |
264 | ;; Commands Sent to Shell... etc. |
265 | (defgroup idlwave-shell-command-setup nil | |
266 | "Setup for command parameters of the Shell interaction for IDLWAVE." | |
267 | :prefix "idlwave-shell" | |
268 | :group 'idlwave) | |
269 | ||
52a244eb | 270 | (defcustom idlwave-shell-initial-commands "!more=0 & defsysv,'!ERROR_STATE',EXISTS=__e & if __e then begin & !ERROR_STATE.MSG_PREFIX=\"% \" & delvar,__e & endif" |
76959b77 S |
271 | "Initial commands, separated by newlines, to send to IDL. |
272 | This string is sent to the IDL process by `idlwave-shell-mode' which is | |
273 | invoked by `idlwave-shell'." | |
274 | :group 'idlwave-shell-command-setup | |
275 | :type 'string) | |
276 | ||
277 | (defcustom idlwave-shell-save-command-history t | |
278 | "Non-nil means preserve command history between sessions. | |
279 | The file `idlwave-shell-command-history-file' is used to save and restore | |
280 | the history." | |
281 | :group 'idlwave-shell-command-setup | |
282 | :type 'boolean) | |
283 | ||
52a244eb | 284 | (defcustom idlwave-shell-command-history-file "idlwhist" |
76959b77 S |
285 | "The file in which the command history of the idlwave shell is saved. |
286 | In order to change the size of the history, see the variable | |
287 | `comint-input-ring-size'. | |
288 | The history is only saved if the variable `idlwave-shell-save-command-history' | |
289 | is non-nil." | |
290 | :group 'idlwave-shell-command-setup | |
291 | :type 'file) | |
5cba7601 | 292 | |
76959b77 S |
293 | (defcustom idlwave-shell-show-commands |
294 | '(run misc breakpoint) | |
13ae1076 | 295 | "*A list of command types to show output from in the shell. |
52a244eb S |
296 | Possibilities are 'run, 'debug, 'breakpoint, and 'misc. Unselected |
297 | types are not displayed in the shell. The type 'everything causes all | |
298 | the copious shell traffic to be displayed." | |
76959b77 S |
299 | :group 'idlwave-shell-command-setup |
300 | :type '(choice | |
301 | (const everything) | |
302 | (set :tag "Checklist" :greedy t | |
5cba7601 | 303 | (const :tag "All .run and .compile commands" run) |
52a244eb S |
304 | (const :tag "All breakpoint commands" breakpoint) |
305 | (const :tag "All debug and stepping commands" debug) | |
306 | (const :tag "Close, window, retall, etc. commands" misc)))) | |
5e72c6b2 | 307 | |
f66f03de S |
308 | (defcustom idlwave-shell-max-print-length 200 |
309 | "Maximum number of array elements to print when examining." | |
310 | :group 'idlwave-shell-command-setup | |
311 | :type 'integer) | |
312 | ||
5cba7601 GM |
313 | (defcustom idlwave-shell-examine-alist |
314 | `(("Print" . ,(concat "idlwave_print_safe,___," | |
315 | (number-to-string | |
f66f03de | 316 | idlwave-shell-max-print-length))) |
5e72c6b2 S |
317 | ("Help" . "help,___") |
318 | ("Structure Help" . "help,___,/STRUCTURE") | |
319 | ("Dimensions" . "print,size(___,/DIMENSIONS)") | |
320 | ("Type" . "print,size(___,/TNAME)") | |
321 | ("N_Elements" . "print,n_elements(___)") | |
322 | ("All Size Info" . "help,(__IWsz__=size(___,/STRUCTURE)),/STRUCTURE & print,__IWsz__.DIMENSIONS") | |
323 | ("Ptr Valid" . "print,ptr_valid(___)") | |
f66f03de | 324 | ("Arg Present" . "print,arg_present(___)") |
5e72c6b2 S |
325 | ("Widget Valid" . "print,widget_info(___,/VALID)") |
326 | ("Widget Geometry" . "help,widget_info(___,/GEOMETRY)")) | |
5cba7601 | 327 | "Alist of special examine commands for popup selection. |
5e72c6b2 S |
328 | The keys are used in the selection popup created by |
329 | `idlwave-shell-examine-select', and the corresponding value is sent as | |
330 | a command to the shell, with special sequence `___' replaced by the | |
331 | expression being examined." | |
76959b77 | 332 | :group 'idlwave-shell-command-setup |
5e72c6b2 | 333 | :type '(repeat |
5cba7601 | 334 | (cons |
5e72c6b2 S |
335 | (string :tag "Label ") |
336 | (string :tag "Command")))) | |
ca660d22 | 337 | |
76959b77 S |
338 | (defvar idlwave-shell-print-expression-function nil |
339 | "*OBSOLETE VARIABLE, is no longer used.") | |
340 | ||
5e72c6b2 | 341 | (defcustom idlwave-shell-separate-examine-output t |
5a0c3f56 | 342 | "*Non-nil means, put output of examine commands in their own buffer." |
76959b77 | 343 | :group 'idlwave-shell-command-setup |
5e72c6b2 | 344 | :type 'boolean) |
5cba7601 | 345 | |
76959b77 S |
346 | (defcustom idlwave-shell-comint-settings |
347 | '((comint-scroll-to-bottom-on-input . t) | |
348 | (comint-scroll-to-bottom-on-output . t) | |
3938cb82 S |
349 | (comint-scroll-show-maximum-output . nil) |
350 | (comint-prompt-read-only . t)) | |
76959b77 S |
351 | |
352 | "Alist of special settings for the comint variables in the IDLWAVE Shell. | |
353 | Each entry is a cons cell with the name of a variable and a value. | |
354 | The function `idlwave-shell-mode' will make local variables out of each entry. | |
355 | Changes to this variable will only be active when the shell buffer is | |
356 | newly created." | |
357 | :group 'idlwave-shell-command-setup | |
358 | :type '(repeat | |
359 | (cons variable sexp))) | |
360 | ||
361 | (defcustom idlwave-shell-query-for-class t | |
362 | "*Non-nil means query the shell for object class on object completions." | |
363 | :group 'idlwave-shell-command-setup | |
364 | :type 'boolean) | |
365 | ||
15e42531 CD |
366 | (defcustom idlwave-shell-use-input-mode-magic nil |
367 | "*Non-nil means, IDLWAVE should check for input mode spells in output. | |
368 | The spells are strings printed by your IDL program and matched | |
369 | by the regular expressions in `idlwave-shell-input-mode-spells'. | |
370 | When these expressions match, IDLWAVE switches to character input mode and | |
371 | back, respectively. See `idlwave-shell-input-mode-spells' for details." | |
76959b77 | 372 | :group 'idlwave-shell-command-setup |
15e42531 CD |
373 | :type 'boolean) |
374 | ||
375 | (defcustom idlwave-shell-input-mode-spells | |
376 | '("^<onechar>$" "^<chars>$" "^</chars>$") | |
377 | "The three regular expressions which match the magic spells for input modes. | |
378 | ||
52a244eb | 379 | When the first regexp matches in the output stream of IDL, IDLWAVE |
15e42531 CD |
380 | prompts for a single character and sends it immediately to IDL, similar |
381 | to the command \\[idlwave-shell-send-char]. | |
382 | ||
383 | When the second regexp matches, IDLWAVE switches to a blocking | |
384 | single-character input mode. This is the same mode which can be entered | |
385 | manually with \\[idlwave-shell-char-mode-loop]. | |
386 | This input mode exits when the third regexp matches in the output, | |
387 | or when the IDL prompt is encountered. | |
388 | ||
389 | The variable `idlwave-shell-use-input-mode-magic' must be non-nil to enable | |
390 | scanning for these expressions. If the IDL program produces lots of | |
391 | output, shell operation may be slowed down. | |
392 | ||
393 | This mechanism is useful for correct interaction with the IDL function | |
394 | GET_KBRD, because in normal operation IDLWAVE only sends \\n terminated | |
05a1abfc | 395 | strings. Here is some example code which makes use of the default spells. |
15e42531 CD |
396 | |
397 | print,'<chars>' ; Make IDLWAVE switch to character mode | |
398 | REPEAT BEGIN | |
399 | A = GET_KBRD(1) | |
400 | PRINT, BYTE(A) | |
401 | ENDREP UNTIL A EQ 'q' | |
402 | print,'</chars>' ; Make IDLWAVE switch back to line mode | |
403 | ||
404 | print,'Quit the program, y or n?' | |
405 | print,'<onechar>' ; Ask IDLWAVE to send one character | |
406 | answer = GET_KBRD(1) | |
407 | ||
408 | Since the IDLWAVE shell defines the system variable `!IDLWAVE_VERSION', | |
5cba7601 | 409 | you could actually check if you are running under Emacs before printing |
15e42531 CD |
410 | the magic strings. Here is a procedure which uses this. |
411 | ||
412 | Usage: | |
413 | ====== | |
414 | idlwave_char_input ; Make IDLWAVE send one character | |
415 | idlwave_char_input,/on ; Start the loop to send characters | |
52a244eb | 416 | idlwave_char_input,/off ; End the loop to send characters |
15e42531 CD |
417 | |
418 | ||
419 | pro idlwave_char_input,on=on,off=off | |
420 | ;; Test if we are running under Emacs | |
421 | defsysv,'!idlwave_version',exists=running_emacs | |
422 | if running_emacs then begin | |
423 | if keyword_set(on) then print,'<chars>' $ | |
424 | else if keyword_set(off) then print,'</chars>' $ | |
425 | else print,'<onechar>' | |
5cba7601 | 426 | endif |
15e42531 | 427 | end" |
76959b77 | 428 | :group 'idlwave-shell-command-setup |
15e42531 CD |
429 | :type '(list |
430 | (regexp :tag "One-char regexp") | |
431 | (regexp :tag "Char-mode regexp") | |
432 | (regexp :tag "Line-mode regexp"))) | |
433 | ||
3938cb82 S |
434 | (defcustom idlwave-shell-breakpoint-popup-menu t |
435 | "*If non-nil, provide a menu on mouse-3 on breakpoint lines, and | |
436 | popup help text on the line." | |
437 | :group 'idlwave-shell-command-setup | |
438 | :type 'boolean) | |
8c7b4ec8 | 439 | |
f66f03de S |
440 | (defcustom idlwave-shell-reset-no-prompt nil |
441 | "If non-nil, skip the yes/no prompt when resetting the IDL session." | |
442 | :group 'idlwave-shell-command-setup | |
443 | :type 'boolean) | |
444 | ||
76959b77 | 445 | ;; Breakpoint Overlays etc |
8c7b4ec8 | 446 | (defgroup idlwave-shell-highlighting-and-faces nil |
5a0c3f56 | 447 | "Highlighting and faces used by the IDLWAVE Shell mode." |
05a1abfc | 448 | :prefix "idlwave-shell" |
8c7b4ec8 EZ |
449 | :group 'idlwave) |
450 | ||
451 | (defcustom idlwave-shell-mark-stop-line t | |
452 | "*Non-nil means, mark the source code line where IDL is currently stopped. | |
2e8b9c7d | 453 | Value decides about the method which is used to mark the line. Valid values |
8c7b4ec8 EZ |
454 | are: |
455 | ||
456 | nil Do not mark the line | |
457 | 'arrow Use the overlay arrow | |
458 | 'face Use `idlwave-shell-stop-line-face' to highlight the line. | |
05a1abfc | 459 | t Use what IDLWAVE thinks is best. Will be a face where possible, |
8c7b4ec8 EZ |
460 | otherwise the overlay arrow. |
461 | The overlay-arrow has the disadvantage to hide the first chars of a line. | |
462 | Since many people do not have the main block of IDL programs indented, | |
463 | a face highlighting may be better. | |
5e72c6b2 | 464 | In Emacs 21, the overlay arrow is displayed in a special area and never |
8c7b4ec8 EZ |
465 | hides any code, so setting this to 'arrow on Emacs 21 sounds like a good idea." |
466 | :group 'idlwave-shell-highlighting-and-faces | |
467 | :type '(choice | |
468 | (const :tag "No marking" nil) | |
469 | (const :tag "Use overlay arrow" arrow) | |
470 | (const :tag "Highlight with face" face) | |
471 | (const :tag "Face or arrow." t))) | |
472 | ||
473 | (defcustom idlwave-shell-overlay-arrow ">" | |
474 | "*The overlay arrow to display at source lines where execution halts. | |
475 | We use a single character by default, since the main block of IDL procedures | |
476 | often has no indentation. Where possible, IDLWAVE will use overlays to | |
477 | display the stop-lines. The arrow is only used on character-based terminals. | |
478 | See also `idlwave-shell-use-overlay-arrow'." | |
479 | :group 'idlwave-shell-highlighting-and-faces | |
480 | :type 'string) | |
481 | ||
482 | (defcustom idlwave-shell-stop-line-face 'highlight | |
483 | "*The face for `idlwave-shell-stop-line-overlay'. | |
484 | Allows you to choose the font, color and other properties for | |
485 | line where IDL is stopped. See also `idlwave-shell-mark-stop-line'." | |
486 | :group 'idlwave-shell-highlighting-and-faces | |
487 | :type 'symbol) | |
488 | ||
52a244eb S |
489 | (defcustom idlwave-shell-electric-stop-color "Violet" |
490 | "*The color for the default face or overlay arrow when stopped." | |
491 | :group 'idlwave-shell-highlighting-and-faces | |
492 | :type 'string) | |
493 | ||
5cba7601 | 494 | (defcustom idlwave-shell-electric-stop-line-face |
52a244eb | 495 | (prog1 |
f66f03de | 496 | (copy-face 'modeline 'idlwave-shell-electric-stop-line) |
5cba7601 | 497 | (set-face-background 'idlwave-shell-electric-stop-line |
52a244eb S |
498 | idlwave-shell-electric-stop-color) |
499 | (condition-case nil | |
f66f03de | 500 | (set-face-foreground 'idlwave-shell-electric-stop-line nil) |
52a244eb S |
501 | (error nil))) |
502 | "*The face for `idlwave-shell-stop-line-overlay' when in electric debug mode. | |
503 | Allows you to choose the font, color and other properties for the line | |
504 | where IDL is stopped, when in Electric Debug Mode." | |
505 | :group 'idlwave-shell-highlighting-and-faces | |
506 | :type 'symbol) | |
507 | ||
8c7b4ec8 EZ |
508 | (defcustom idlwave-shell-mark-breakpoints t |
509 | "*Non-nil means, mark breakpoints in the source files. | |
2e8b9c7d | 510 | Valid values are: |
8c7b4ec8 EZ |
511 | nil Do not mark breakpoints. |
512 | 'face Highlight line with `idlwave-shell-breakpoint-face'. | |
513 | 'glyph Red dot at the beginning of line. If the display does not | |
514 | support glyphs, will use 'face instead. | |
515 | t Glyph when possible, otherwise face (same effect as 'glyph)." | |
516 | :group 'idlwave-shell-highlighting-and-faces | |
517 | :type '(choice | |
518 | (const :tag "No marking" nil) | |
519 | (const :tag "Highlight with face" face) | |
520 | (const :tag "Display glyph (red dot)" glyph) | |
521 | (const :tag "Glyph or face." t))) | |
522 | ||
523 | (defvar idlwave-shell-use-breakpoint-glyph t | |
5a0c3f56 | 524 | "Obsolete variable. See `idlwave-shell-mark-breakpoints'.") |
8c7b4ec8 | 525 | |
57267a95 | 526 | (defcustom idlwave-shell-breakpoint-face 'idlwave-shell-bp |
8c7b4ec8 EZ |
527 | "*The face for breakpoint lines in the source code. |
528 | Allows you to choose the font, color and other properties for | |
529 | lines which have a breakpoint. See also `idlwave-shell-mark-breakpoints'." | |
530 | :group 'idlwave-shell-highlighting-and-faces | |
531 | :type 'symbol) | |
532 | ||
57267a95 MB |
533 | (if (not idlwave-shell-have-new-custom) |
534 | ;; Just copy the underline face to be on the safe side. | |
535 | (copy-face 'underline 'idlwave-shell-bp) | |
536 | ;; We have the new customize - use it to define a customizable face | |
537 | (defface idlwave-shell-bp | |
538 | '((((class color)) (:foreground "Black" :background "Pink")) | |
539 | (t (:underline t))) | |
540 | "Face for highlighting lines with breakpoints." | |
e95e5f81 | 541 | :group 'idlwave-shell-highlighting-and-faces)) |
8c7b4ec8 | 542 | |
5cba7601 | 543 | (defcustom idlwave-shell-disabled-breakpoint-face |
57267a95 | 544 | 'idlwave-shell-disabled-bp |
52a244eb S |
545 | "*The face for disabled breakpoint lines in the source code. |
546 | Allows you to choose the font, color and other properties for | |
547 | lines which have a breakpoint. See also `idlwave-shell-mark-breakpoints'." | |
548 | :group 'idlwave-shell-highlighting-and-faces | |
549 | :type 'symbol) | |
550 | ||
57267a95 MB |
551 | (if (not idlwave-shell-have-new-custom) |
552 | ;; Just copy the underline face to be on the safe side. | |
553 | (copy-face 'underline 'idlwave-shell-disabled-bp) | |
554 | ;; We have the new customize - use it to define a customizable face | |
555 | (defface idlwave-shell-disabled-bp | |
556 | '((((class color)) (:foreground "Black" :background "gray")) | |
557 | (t (:underline t))) | |
558 | "Face for highlighting lines with breakpoints." | |
e95e5f81 | 559 | :group 'idlwave-shell-highlighting-and-faces)) |
52a244eb | 560 | |
f66f03de | 561 | |
ca660d22 CD |
562 | (defcustom idlwave-shell-expression-face 'secondary-selection |
563 | "*The face for `idlwave-shell-expression-overlay'. | |
564 | Allows you to choose the font, color and other properties for | |
565 | the expression printed by IDL." | |
566 | :group 'idlwave-shell-highlighting-and-faces | |
567 | :type 'symbol) | |
568 | ||
5e72c6b2 S |
569 | (defcustom idlwave-shell-output-face 'secondary-selection |
570 | "*The face for `idlwave-shell-output-overlay'. | |
571 | Allows you to choose the font, color and other properties for | |
572 | the expression output by IDL." | |
573 | :group 'idlwave-shell-highlighting-and-faces | |
574 | :type 'symbol) | |
575 | ||
8c7b4ec8 EZ |
576 | ;;; End user customization variables |
577 | ||
578 | ;;; External variables | |
579 | (defvar comint-last-input-start) | |
580 | (defvar comint-last-input-end) | |
581 | ||
ddd709d1 S |
582 | ;; Other variables |
583 | (defvar idlwave-shell-temp-pro-file nil | |
584 | "Absolute pathname for temporary IDL file for compiling regions") | |
585 | ||
586 | (defvar idlwave-shell-temp-rinfo-save-file nil | |
587 | "Absolute pathname for temporary IDL file save file for routine_info. | |
588 | This is used to speed up the reloading of the routine info procedure | |
589 | before use by the shell.") | |
590 | ||
5e72c6b2 S |
591 | (defun idlwave-shell-temp-file (type) |
592 | "Return a temp file, creating it if necessary. | |
593 | ||
ddd709d1 S |
594 | TYPE is either 'pro' or 'rinfo', and `idlwave-shell-temp-pro-file' or |
595 | `idlwave-shell-temp-rinfo-save-file' is set (respectively)." | |
5cba7601 | 596 | (cond |
5e72c6b2 | 597 | ((eq type 'rinfo) |
5cba7601 GM |
598 | (or idlwave-shell-temp-rinfo-save-file |
599 | (setq idlwave-shell-temp-rinfo-save-file | |
5e72c6b2 S |
600 | (idlwave-shell-make-temp-file idlwave-shell-temp-pro-prefix)))) |
601 | ((eq type 'pro) | |
602 | (or idlwave-shell-temp-pro-file | |
5cba7601 | 603 | (setq idlwave-shell-temp-pro-file |
5e72c6b2 | 604 | (idlwave-shell-make-temp-file idlwave-shell-temp-pro-prefix)))) |
5cba7601 | 605 | (t (error "Wrong argument (idlwave-shell-temp-file): %s" |
5e72c6b2 | 606 | (symbol-name type))))) |
5cba7601 | 607 | |
8c7b4ec8 | 608 | |
5e72c6b2 S |
609 | (defun idlwave-shell-make-temp-file (prefix) |
610 | "Create a temporary file." | |
611 | ; Hard coded make-temp-file for Emacs<21 | |
612 | (if (fboundp 'make-temp-file) | |
613 | (make-temp-file prefix) | |
614 | (let (file | |
615 | (temp-file-dir (if (boundp 'temporary-file-directory) | |
616 | temporary-file-directory | |
617 | "/tmp"))) | |
618 | (while (condition-case () | |
619 | (progn | |
620 | (setq file | |
621 | (make-temp-name | |
622 | (expand-file-name prefix temp-file-dir))) | |
623 | (if (featurep 'xemacs) | |
624 | (write-region "" nil file nil 'silent nil) | |
625 | (write-region "" nil file nil 'silent nil 'excl)) | |
626 | nil) | |
627 | (file-already-exists t)) | |
628 | ;; the file was somehow created by someone else between | |
629 | ;; `make-temp-name' and `write-region', let's try again. | |
630 | nil) | |
631 | file))) | |
15e42531 | 632 | |
52a244eb | 633 | |
76959b77 | 634 | (defvar idlwave-shell-dirstack-query "cd,current=___cur & print,___cur" |
5cba7601 | 635 | "Command used by `idlwave-shell-resync-dirs' to query IDL for |
8c7b4ec8 EZ |
636 | the directory stack.") |
637 | ||
52a244eb S |
638 | (defvar idlwave-shell-path-query "print,'PATH:<'+transpose(expand_path(!PATH,/ARRAY))+'>' & print,'SYSDIR:<'+!dir+'>'" |
639 | ||
640 | "The command which gets !PATH and !DIR info from the shell.") | |
15e42531 | 641 | |
ca660d22 | 642 | (defvar idlwave-shell-mode-line-info nil |
5a0c3f56 | 643 | "Additional info displayed in the mode line.") |
ca660d22 | 644 | |
8c7b4ec8 EZ |
645 | (defvar idlwave-shell-default-directory nil |
646 | "The default directory in the idlwave-shell buffer, of outside use.") | |
647 | ||
648 | (defvar idlwave-shell-last-save-and-action-file nil | |
649 | "The last file which was compiled with `idlwave-shell-save-and-...'.") | |
650 | ||
651 | ;; Highlighting uses overlays. When necessary, require the emulation. | |
652 | (if (not (fboundp 'make-overlay)) | |
653 | (condition-case nil | |
654 | (require 'overlay) | |
655 | (error nil))) | |
656 | ||
657 | (defvar idlwave-shell-stop-line-overlay nil | |
658 | "The overlay for where IDL is currently stopped.") | |
15e42531 | 659 | (defvar idlwave-shell-is-stopped nil) |
8c7b4ec8 | 660 | (defvar idlwave-shell-expression-overlay nil |
f66f03de | 661 | "The overlay for the examined expression.") |
5e72c6b2 S |
662 | (defvar idlwave-shell-output-overlay nil |
663 | "The overlay for the last IDL output.") | |
664 | ||
8c7b4ec8 EZ |
665 | ;; If these were already overlays, delete them. This probably means that we |
666 | ;; are reloading this file. | |
667 | (if (overlayp idlwave-shell-stop-line-overlay) | |
668 | (delete-overlay idlwave-shell-stop-line-overlay)) | |
669 | (if (overlayp idlwave-shell-expression-overlay) | |
670 | (delete-overlay idlwave-shell-expression-overlay)) | |
5e72c6b2 S |
671 | (if (overlayp idlwave-shell-output-overlay) |
672 | (delete-overlay idlwave-shell-output-overlay)) | |
673 | ||
8c7b4ec8 EZ |
674 | ;; Set to nil initially |
675 | (setq idlwave-shell-stop-line-overlay nil | |
5e72c6b2 S |
676 | idlwave-shell-expression-overlay nil |
677 | idlwave-shell-output-overlay nil) | |
8c7b4ec8 EZ |
678 | |
679 | ;; Define the shell stop overlay. When left nil, the arrow will be used. | |
680 | (cond | |
681 | ((or (null idlwave-shell-mark-stop-line) | |
682 | (eq idlwave-shell-mark-stop-line 'arrow)) | |
683 | ;; Leave the overlay nil | |
684 | nil) | |
685 | ||
686 | ((eq idlwave-shell-mark-stop-line 'face) | |
687 | ;; Try to use a face. If not possible, arrow will be used anyway | |
688 | ;; So who can display faces? | |
689 | (when (or (featurep 'xemacs) ; XEmacs can do also ttys | |
690 | (fboundp 'tty-defined-colors) ; Emacs 21 as well | |
691 | window-system) ; Window systems always | |
692 | (progn | |
693 | (setq idlwave-shell-stop-line-overlay (make-overlay 1 1)) | |
5cba7601 | 694 | (overlay-put idlwave-shell-stop-line-overlay |
8c7b4ec8 EZ |
695 | 'face idlwave-shell-stop-line-face)))) |
696 | ||
697 | (t | |
698 | ;; IDLWAVE may decide. Will use a face on window systems, arrow elsewhere | |
699 | (if window-system | |
700 | (progn | |
701 | (setq idlwave-shell-stop-line-overlay (make-overlay 1 1)) | |
5cba7601 | 702 | (overlay-put idlwave-shell-stop-line-overlay |
8c7b4ec8 EZ |
703 | 'face idlwave-shell-stop-line-face))))) |
704 | ||
5e72c6b2 | 705 | ;; Now the expression and output overlays |
8c7b4ec8 EZ |
706 | (setq idlwave-shell-expression-overlay (make-overlay 1 1)) |
707 | (overlay-put idlwave-shell-expression-overlay | |
708 | 'face idlwave-shell-expression-face) | |
f66f03de S |
709 | (overlay-put idlwave-shell-expression-overlay |
710 | 'priority 1) | |
5e72c6b2 S |
711 | (setq idlwave-shell-output-overlay (make-overlay 1 1)) |
712 | (overlay-put idlwave-shell-output-overlay | |
713 | 'face idlwave-shell-output-face) | |
714 | ||
5cba7601 | 715 | (copy-face idlwave-shell-stop-line-face |
f66f03de | 716 | 'idlwave-shell-pending-stop) |
5cba7601 | 717 | (copy-face idlwave-shell-electric-stop-line-face |
f66f03de S |
718 | 'idlwave-shell-pending-electric-stop) |
719 | (set-face-background 'idlwave-shell-pending-stop "gray70") | |
720 | (set-face-background 'idlwave-shell-pending-electric-stop "gray70") | |
721 | ||
722 | ||
723 | ||
8c7b4ec8 | 724 | (defvar idlwave-shell-bp-query "help,/breakpoints" |
5a0c3f56 | 725 | "Command to obtain list of breakpoints.") |
8c7b4ec8 EZ |
726 | |
727 | (defvar idlwave-shell-command-output nil | |
728 | "String for accumulating current command output.") | |
729 | ||
730 | (defvar idlwave-shell-post-command-hook nil | |
731 | "Lisp list expression or function to run when an IDL command is finished. | |
732 | The current command is finished when the IDL prompt is displayed. | |
733 | This is evaluated if it is a list or called with funcall.") | |
734 | ||
5e72c6b2 | 735 | (defvar idlwave-shell-sentinel-hook nil |
5a0c3f56 | 736 | "Hook run when the IDL process exits.") |
5e72c6b2 | 737 | |
8c7b4ec8 | 738 | (defvar idlwave-shell-hide-output nil |
5a0c3f56 | 739 | "If non-nil the process output is not inserted into the output buffer.") |
52a244eb S |
740 | |
741 | (defvar idlwave-shell-show-if-error nil | |
742 | "If non-nil the process output is inserted into the output buffer if | |
743 | it contains an error message, even if hide-output is non-nil.") | |
8c7b4ec8 EZ |
744 | |
745 | (defvar idlwave-shell-accumulation nil | |
746 | "Accumulate last line of output.") | |
747 | ||
748 | (defvar idlwave-shell-command-line-to-execute nil) | |
749 | (defvar idlwave-shell-cleanup-hook nil | |
750 | "List of functions to do cleanup when the shell exits.") | |
751 | ||
752 | (defvar idlwave-shell-pending-commands nil | |
753 | "List of commands to be sent to IDL. | |
754 | Each element of the list is list of \(CMD PCMD HIDE\), where CMD is a | |
755 | string to be sent to IDL and PCMD is a post-command to be placed on | |
5a0c3f56 JB |
756 | `idlwave-shell-post-command-hook'. If HIDE is non-nil, hide the output |
757 | from command CMD. PCMD and HIDE are optional.") | |
8c7b4ec8 EZ |
758 | |
759 | (defun idlwave-shell-buffer () | |
760 | "Name of buffer associated with IDL process. | |
5a0c3f56 | 761 | The name of the buffer is made by surrounding `idlwave-shell-process-name' |
8c7b4ec8 EZ |
762 | with `*'s." |
763 | (concat "*" idlwave-shell-process-name "*")) | |
764 | ||
765 | (defvar idlwave-shell-ready nil | |
766 | "If non-nil can send next command to IDL process.") | |
767 | ||
768 | ;;; The following are the types of messages we attempt to catch to | |
769 | ;;; resync our idea of where IDL execution currently is. | |
5cba7601 | 770 | ;;; |
8c7b4ec8 EZ |
771 | |
772 | (defvar idlwave-shell-halt-frame nil | |
773 | "The frame associated with halt/breakpoint messages.") | |
774 | ||
775 | (defvar idlwave-shell-step-frame nil | |
776 | "The frame associated with step messages.") | |
777 | ||
778 | (defvar idlwave-shell-trace-frame nil | |
779 | "The frame associated with trace messages.") | |
780 | ||
781 | (defconst idlwave-shell-halt-messages | |
52a244eb | 782 | '("^% Interrupted at:" |
8c7b4ec8 | 783 | "^% Stepped to:" |
52a244eb | 784 | "^% Skipped to:" |
8c7b4ec8 EZ |
785 | "^% Stop encountered:" |
786 | ) | |
787 | "*A list of regular expressions matching IDL messages. | |
788 | These are the messages containing file and line information where | |
789 | IDL is currently stopped.") | |
790 | ||
52a244eb | 791 | |
8c7b4ec8 EZ |
792 | (defconst idlwave-shell-halt-messages-re |
793 | (mapconcat 'identity idlwave-shell-halt-messages "\\|") | |
5a0c3f56 | 794 | "The regular expression computed from `idlwave-shell-halt-messages'.") |
8c7b4ec8 | 795 | |
52a244eb S |
796 | (defconst idlwave-shell-trace-message-re |
797 | "^% At " ;; First line of a trace message | |
798 | "*A regular expression matching IDL trace messages. These are the | |
799 | messages containing file and line information of a current | |
800 | traceback.") | |
8c7b4ec8 EZ |
801 | |
802 | (defconst idlwave-shell-step-messages | |
803 | '("^% Stepped to:" | |
804 | ) | |
805 | "*A list of regular expressions matching stepped execution messages. | |
806 | These are IDL messages containing file and line information where | |
807 | IDL has currently stepped.") | |
808 | ||
809 | (defvar idlwave-shell-break-message "^% Breakpoint at:" | |
810 | "*Regular expression matching an IDL breakpoint message line.") | |
811 | ||
52a244eb S |
812 | (defconst idlwave-shell-electric-debug-help |
813 | " ==> IDLWAVE Electric Debug Mode Help <== | |
5cba7601 | 814 | |
52a244eb S |
815 | Break Point Setting and Clearing: |
816 | b Set breakpoint ([C-u b] for conditional, [C-n b] nth hit, etc.). | |
817 | d Clear nearby breakpoint. | |
818 | a Clear all breakpoints. | |
819 | i Set breakpoint in routine named here. | |
820 | j Set breakpoint at beginning of containing routine. | |
821 | \\ Toggle breakpoint disable | |
822 | ] Go to next breakpoint in file. | |
823 | [ Go to previous breakpoint in file. | |
824 | ||
825 | Stepping, Continuing, and the Stack: | |
826 | s or SPACE Step, into function calls. | |
827 | n Step, over function calls. | |
828 | k Skip one statement. | |
829 | m Continue to end of function. | |
830 | o Continue past end of function. | |
831 | u Continue to end of block. | |
832 | h Continue to line at cursor position. | |
833 | r Continue execution to next breakpoint, if any. | |
834 | + or = Show higher level in calling stack. | |
835 | - or _ Show lower level in calling stack. | |
836 | ||
837 | Examining Expressions (with prefix for examining the region): | |
838 | p Print expression near point or in region ([C-u p]). | |
839 | ? Help on expression near point or in region ([C-u ?]). | |
5cba7601 | 840 | x Examine expression near point or in region ([C-u x]) with |
52a244eb | 841 | letter completion of the examine type. |
f66f03de | 842 | e Prompt for an expression to print. |
52a244eb S |
843 | |
844 | Miscellaneous: | |
845 | q Quit - end debugging session and return to the Shell's main level. | |
846 | v Turn Electric Debugging Mode off (C-c C-d C-v to return). | |
847 | t Print a calling-level traceback in the shell. | |
848 | z Reset IDL. | |
849 | C-? Show this help menu.") | |
8c7b4ec8 EZ |
850 | |
851 | (defvar idlwave-shell-bp-alist) | |
852 | ;(defvar idlwave-shell-post-command-output) | |
853 | (defvar idlwave-shell-sources-alist) | |
854 | (defvar idlwave-shell-menu-def) | |
855 | (defvar idlwave-shell-mode-menu) | |
856 | (defvar idlwave-shell-initial-commands) | |
857 | (defvar idlwave-shell-syntax-error) | |
858 | (defvar idlwave-shell-other-error) | |
859 | (defvar idlwave-shell-error-buffer) | |
860 | (defvar idlwave-shell-error-last) | |
861 | (defvar idlwave-shell-bp-buffer) | |
862 | (defvar idlwave-shell-sources-query) | |
863 | (defvar idlwave-shell-mode-map) | |
ca660d22 | 864 | (defvar idlwave-shell-calling-stack-index) |
25d24a50 S |
865 | (defvar idlwave-shell-only-prompt-pattern nil) |
866 | (defvar tool-bar-map) | |
8c7b4ec8 | 867 | |
175069ef | 868 | (define-derived-mode idlwave-shell-mode comint-mode "IDL-Shell" |
8c7b4ec8 EZ |
869 | "Major mode for interacting with an inferior IDL process. |
870 | ||
871 | 1. Shell Interaction | |
872 | ----------------- | |
873 | RET after the end of the process' output sends the text from the | |
874 | end of process to the end of the current line. RET before end of | |
5a0c3f56 JB |
875 | process output copies the current line (except for the prompt) to |
876 | the end of the buffer. | |
8c7b4ec8 EZ |
877 | |
878 | Command history, searching of previous commands, command line | |
879 | editing are available via the comint-mode key bindings, by default | |
05a1abfc CD |
880 | mostly on the key `C-c'. Command history is also available with |
881 | the arrow keys UP and DOWN. | |
8c7b4ec8 EZ |
882 | |
883 | 2. Completion | |
884 | ---------- | |
15e42531 CD |
885 | TAB and M-TAB do completion of IDL routines, classes and keywords - |
886 | similar to M-TAB in `idlwave-mode'. In executive commands and | |
887 | strings, it completes file names. Abbreviations are also expanded | |
888 | like in `idlwave-mode'. | |
8c7b4ec8 EZ |
889 | |
890 | 3. Routine Info | |
891 | ------------ | |
892 | `\\[idlwave-routine-info]' displays information about an IDL routine near point, | |
893 | just like in `idlwave-mode'. The module used is the one at point or | |
894 | the one whose argument list is being edited. | |
5cba7601 | 895 | To update IDLWAVE's knowledge about compiled or edited modules, use |
8c7b4ec8 EZ |
896 | \\[idlwave-update-routine-info]. |
897 | \\[idlwave-find-module] find the source of a module. | |
898 | \\[idlwave-resolve] tells IDL to compile an unresolved module. | |
15e42531 CD |
899 | \\[idlwave-context-help] shows the online help on the item at |
900 | point, if online help has been installed. | |
5cba7601 | 901 | |
8c7b4ec8 EZ |
902 | |
903 | 4. Debugging | |
904 | --------- | |
905 | A complete set of commands for compiling and debugging IDL programs | |
5cba7601 | 906 | is available from the menu. Also keybindings starting with a |
8c7b4ec8 EZ |
907 | `C-c C-d' prefix are available for most commands in the *idl* buffer |
908 | and also in source buffers. The best place to learn about the | |
909 | keybindings is again the menu. | |
910 | ||
911 | On Emacs versions where this is possible, a debugging toolbar is | |
912 | installed. | |
913 | ||
914 | When IDL is halted in the middle of a procedure, the corresponding | |
915 | line of that procedure file is displayed with an overlay in another | |
916 | window. Breakpoints are also highlighted in the source. | |
917 | ||
918 | \\[idlwave-shell-resync-dirs] queries IDL in order to change Emacs current directory | |
919 | to correspond to the IDL process current directory. | |
920 | ||
52a244eb S |
921 | 5. Expression Examination |
922 | ---------------------- | |
923 | ||
924 | Expressions near point can be examined with print, | |
925 | \\[idlwave-shell-print] or \\[idlwave-shell-mouse-print] with the | |
926 | mouse, help, \\[idlwave-shell-help-expression] or | |
927 | \\[idlwave-shell-mouse-help] with the mouse, or with a | |
928 | configureable set of custom examine commands using | |
929 | \\[idlwave-shell-examine-select]. The mouse examine commands can | |
930 | also work by click and drag, to select an expression for | |
931 | examination. | |
932 | ||
933 | 6. Hooks | |
8c7b4ec8 EZ |
934 | ----- |
935 | Turning on `idlwave-shell-mode' runs `comint-mode-hook' and | |
936 | `idlwave-shell-mode-hook' (in that order). | |
937 | ||
52a244eb | 938 | 7. Documentation and Customization |
8c7b4ec8 EZ |
939 | ------------------------------- |
940 | Info documentation for this package is available. Use \\[idlwave-info] | |
941 | to display (complain to your sysadmin if that does not work). | |
942 | For Postscript and HTML versions of the documentation, check IDLWAVE's | |
855b42a2 | 943 | homepage at URL `http://idlwave.org'. |
8c7b4ec8 EZ |
944 | IDLWAVE has customize support - see the group `idlwave'. |
945 | ||
52a244eb | 946 | 8. Keybindings |
8c7b4ec8 EZ |
947 | ----------- |
948 | \\{idlwave-shell-mode-map}" | |
175069ef | 949 | :abbrev-table idlwave-mode-abbrev-table |
52a244eb S |
950 | (idlwave-setup) ; Make sure config files and paths, etc. are available. |
951 | (unless (file-name-absolute-p idlwave-shell-command-history-file) | |
952 | (setq idlwave-shell-command-history-file | |
953 | (expand-file-name idlwave-shell-command-history-file | |
954 | idlwave-config-directory))) | |
955 | ||
8c7b4ec8 EZ |
956 | (setq comint-prompt-regexp idlwave-shell-prompt-pattern) |
957 | (setq comint-process-echoes t) | |
52a244eb | 958 | |
8c7b4ec8 EZ |
959 | ;; Can not use history expansion because "!" is used for system variables. |
960 | (setq comint-input-autoexpand nil) | |
175069ef SM |
961 | ;; (setq comint-input-ring-size 64) |
962 | ||
8c7b4ec8 | 963 | (set (make-local-variable 'completion-ignore-case) t) |
175069ef | 964 | (set (make-local-variable 'comint-completion-addsuffix) '("/" . "")) |
8c7b4ec8 | 965 | (setq comint-input-ignoredups t) |
ca660d22 CD |
966 | (setq idlwave-shell-mode-line-info nil) |
967 | (setq mode-line-format | |
968 | '("" | |
969 | mode-line-modified | |
970 | mode-line-buffer-identification | |
971 | " " | |
972 | global-mode-string | |
973 | " %[(" | |
974 | mode-name | |
975 | mode-line-process | |
976 | minor-mode-alist | |
977 | "%n" | |
978 | ")%]-" | |
979 | idlwave-shell-mode-line-info | |
980 | "---" | |
981 | (line-number-mode "L%l--") | |
982 | (column-number-mode "C%c--") | |
983 | (-3 . "%p") | |
984 | "-%-")) | |
8c7b4ec8 EZ |
985 | ;; (make-local-variable 'idlwave-shell-bp-alist) |
986 | (setq idlwave-shell-halt-frame nil | |
987 | idlwave-shell-trace-frame nil | |
988 | idlwave-shell-command-output nil | |
989 | idlwave-shell-step-frame nil) | |
990 | (idlwave-shell-display-line nil) | |
ca660d22 | 991 | (setq idlwave-shell-calling-stack-index 0) |
52a244eb | 992 | (setq idlwave-shell-only-prompt-pattern |
5cba7601 GM |
993 | (concat "\\`[ \t\n]*" |
994 | (substring idlwave-shell-prompt-pattern 1) | |
52a244eb | 995 | "[ \t\n]*\\'")) |
15e42531 | 996 | |
76959b77 S |
997 | (when idlwave-shell-query-for-class |
998 | (add-to-list (make-local-variable 'idlwave-determine-class-special) | |
999 | 'idlwave-shell-get-object-class) | |
1000 | (setq idlwave-store-inquired-class t)) | |
1001 | ||
8c7b4ec8 EZ |
1002 | ;; Make sure comint-last-input-end does not go to beginning of |
1003 | ;; buffer (in case there were other processes already in this buffer). | |
1004 | (set-marker comint-last-input-end (point)) | |
15e42531 | 1005 | (setq idlwave-idlwave_routine_info-compiled nil) |
8c7b4ec8 EZ |
1006 | (setq idlwave-shell-ready nil) |
1007 | (setq idlwave-shell-bp-alist nil) | |
1008 | (idlwave-shell-update-bp-overlays) ; Throw away old overlays | |
6a8cc02d S |
1009 | (setq idlwave-shell-post-command-hook nil ;clean up any old stuff |
1010 | idlwave-shell-sources-alist nil) | |
8c7b4ec8 | 1011 | (setq idlwave-shell-default-directory default-directory) |
15e42531 | 1012 | (setq idlwave-shell-hide-output nil) |
5e72c6b2 | 1013 | |
f66f03de S |
1014 | ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility |
1015 | ;; (make-local-hook 'kill-buffer-hook) | |
8c7b4ec8 EZ |
1016 | (add-hook 'kill-buffer-hook 'idlwave-shell-kill-shell-buffer-confirm |
1017 | nil 'local) | |
15e42531 CD |
1018 | (add-hook 'kill-buffer-hook 'idlwave-shell-delete-temp-files nil 'local) |
1019 | (add-hook 'kill-emacs-hook 'idlwave-shell-delete-temp-files) | |
8c7b4ec8 | 1020 | (easy-menu-add idlwave-shell-mode-menu idlwave-shell-mode-map) |
15e42531 | 1021 | |
5e72c6b2 S |
1022 | ;; Set the optional comint variables |
1023 | (when idlwave-shell-comint-settings | |
1024 | (let ((list idlwave-shell-comint-settings) entry) | |
1025 | (while (setq entry (pop list)) | |
1026 | (set (make-local-variable (car entry)) (cdr entry))))) | |
05a1abfc | 1027 | |
5cba7601 GM |
1028 | |
1029 | (unless (memq 'comint-carriage-motion | |
52a244eb S |
1030 | (default-value 'comint-output-filter-functions)) |
1031 | ;; Strip those pesky ctrl-m's. | |
1032 | (add-hook 'comint-output-filter-functions | |
1033 | (lambda (string) | |
1034 | (when (string-match "\r" string) | |
5cba7601 | 1035 | (let ((pmark (process-mark (get-buffer-process |
52a244eb S |
1036 | (current-buffer))))) |
1037 | (save-excursion | |
1038 | ;; bare CR -> delete preceding line | |
1039 | (goto-char comint-last-output-start) | |
1040 | (while (search-forward "\r" pmark t) | |
1041 | (delete-region (point) (line-beginning-position))))))) | |
1042 | 'append 'local) | |
1043 | (add-hook 'comint-output-filter-functions 'comint-strip-ctrl-m nil 'local)) | |
1044 | ||
1045 | ;; Python-mode, bundled with many Emacs installs, quite cavalierly | |
1046 | ;; adds this function to the global default hook. It interferes | |
1047 | ;; with overlay-arrows. | |
1048 | (remove-hook 'comint-output-filter-functions 'py-pdbtrack-track-stack-file) | |
1049 | ||
15e42531 | 1050 | ;; IDLWAVE syntax, and turn on abbreviations |
05a1abfc | 1051 | (set (make-local-variable 'comment-start) ";") |
15e42531 | 1052 | (setq abbrev-mode t) |
5e72c6b2 | 1053 | |
f66f03de S |
1054 | ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility |
1055 | ;; make-local-hook 'post-command-hook) | |
15e42531 CD |
1056 | (add-hook 'post-command-hook 'idlwave-command-hook nil t) |
1057 | ||
5e72c6b2 S |
1058 | ;; Read the command history? |
1059 | (when (and idlwave-shell-save-command-history | |
1060 | (stringp idlwave-shell-command-history-file)) | |
1061 | (set (make-local-variable 'comint-input-ring-file-name) | |
1062 | idlwave-shell-command-history-file) | |
1063 | (if (file-regular-p idlwave-shell-command-history-file) | |
1064 | (comint-read-input-ring))) | |
1065 | ||
52a244eb S |
1066 | ;; Turn off the non-debug toolbar buttons (open,save,etc.) |
1067 | (set (make-local-variable 'tool-bar-map) nil) | |
1068 | ||
8c7b4ec8 | 1069 | (idlwave-shell-send-command idlwave-shell-initial-commands nil 'hide) |
52a244eb S |
1070 | ;; Turn off IDL's ^d interpreting, and define a system |
1071 | ;; variable which knows the version of IDLWAVE | |
5cba7601 | 1072 | (idlwave-shell-send-command |
3938cb82 | 1073 | (format "defsysv,'!idlwave_version','%s',1" idlwave-mode-version) |
15e42531 | 1074 | nil 'hide) |
f66f03de S |
1075 | ;; Read the paths, and save if they changed |
1076 | (idlwave-shell-send-command idlwave-shell-path-query | |
1077 | 'idlwave-shell-get-path-info | |
1078 | 'hide)) | |
15e42531 | 1079 | |
f66f03de | 1080 | (defvar idlwave-system-directory) |
52a244eb S |
1081 | (defun idlwave-shell-get-path-info (&optional no-write) |
1082 | "Get the path lists, writing to file unless NO-WRITE is set." | |
15e42531 CD |
1083 | (let* ((rpl (idlwave-shell-path-filter)) |
1084 | (sysdir (car rpl)) | |
52a244eb | 1085 | (dirs (cdr rpl)) |
f66f03de S |
1086 | (old-path-alist idlwave-path-alist) |
1087 | (old-sys-dir idlwave-system-directory) | |
1088 | path-changed sysdir-changed) | |
52a244eb S |
1089 | (when sysdir |
1090 | (setq idlwave-system-directory sysdir) | |
5cba7601 | 1091 | (if (setq sysdir-changed |
f66f03de S |
1092 | (not (string= idlwave-system-directory old-sys-dir))) |
1093 | (put 'idlwave-system-directory 'from-shell t))) | |
52a244eb | 1094 | ;; Preserve any existing flags |
5cba7601 | 1095 | (setq idlwave-path-alist |
52a244eb S |
1096 | (mapcar (lambda (x) |
1097 | (let ((old-entry (assoc x old-path-alist))) | |
1098 | (if old-entry | |
1099 | (cons x (cdr old-entry)) | |
1100 | (list x)))) | |
1101 | dirs)) | |
f66f03de S |
1102 | (if (setq path-changed (not (equal idlwave-path-alist old-path-alist))) |
1103 | (put 'idlwave-path-alist 'from-shell t)) | |
5cba7601 | 1104 | (if idlwave-path-alist |
f66f03de S |
1105 | (if (and (not no-write) |
1106 | idlwave-auto-write-paths | |
1107 | (or sysdir-changed path-changed) | |
1108 | (not idlwave-library-path)) | |
52a244eb S |
1109 | (idlwave-write-paths)) |
1110 | ;; Fall back | |
1111 | (setq idlwave-path-alist old-path-alist)))) | |
8c7b4ec8 EZ |
1112 | |
1113 | (if (not (fboundp 'idl-shell)) | |
1114 | (fset 'idl-shell 'idlwave-shell)) | |
1115 | ||
1116 | (defvar idlwave-shell-idl-wframe nil | |
5a0c3f56 | 1117 | "Frame for displaying the IDL shell window.") |
8c7b4ec8 | 1118 | (defvar idlwave-shell-display-wframe nil |
5a0c3f56 | 1119 | "Frame for displaying the IDL source files.") |
8c7b4ec8 | 1120 | |
8c7b4ec8 | 1121 | (defvar idlwave-shell-calling-stack-index 0) |
ca660d22 | 1122 | (defvar idlwave-shell-calling-stack-routine nil) |
8c7b4ec8 EZ |
1123 | |
1124 | (defun idlwave-shell-source-frame () | |
1125 | "Return the frame to be used for source display." | |
1126 | (if idlwave-shell-use-dedicated-frame | |
1127 | ;; We want separate frames for source and shell | |
1128 | (if (frame-live-p idlwave-shell-display-wframe) | |
1129 | ;; The frame exists, so we use it. | |
1130 | idlwave-shell-display-wframe | |
1131 | ;; The frame does not exist. We use the current frame. | |
5e72c6b2 S |
1132 | ;; However, if the current is the shell frame, we make a new frame, |
1133 | ;; or recycle the first existing visible frame | |
8c7b4ec8 EZ |
1134 | (setq idlwave-shell-display-wframe |
1135 | (if (eq (selected-frame) idlwave-shell-idl-wframe) | |
5e72c6b2 S |
1136 | (or |
1137 | (let ((flist (visible-frame-list)) | |
1138 | (frame (selected-frame))) | |
1139 | (catch 'exit | |
1140 | (while flist | |
5cba7601 GM |
1141 | (if (not (eq (car flist) |
1142 | idlwave-shell-idl-wframe)) | |
5e72c6b2 S |
1143 | (throw 'exit (car flist)) |
1144 | (setq flist (cdr flist)))))) | |
1145 | (make-frame)) | |
8c7b4ec8 EZ |
1146 | (selected-frame)))))) |
1147 | ||
1148 | (defun idlwave-shell-shell-frame () | |
1149 | "Return the frame to be used for the shell buffer." | |
1150 | (if idlwave-shell-use-dedicated-frame | |
1151 | ;; We want a dedicated frame | |
1152 | (if (frame-live-p idlwave-shell-idl-wframe) | |
1153 | ;; It does exist, so we use it. | |
1154 | idlwave-shell-idl-wframe | |
1155 | ;; It does not exist. Check if we have a source frame. | |
1156 | (if (not (frame-live-p idlwave-shell-display-wframe)) | |
1157 | ;; We do not have a source frame, so we use this one. | |
1158 | (setq idlwave-shell-display-wframe (selected-frame))) | |
1159 | ;; Return a new frame | |
5cba7601 | 1160 | (setq idlwave-shell-idl-wframe |
8c7b4ec8 | 1161 | (make-frame idlwave-shell-frame-parameters))))) |
5cba7601 | 1162 | |
8c7b4ec8 | 1163 | ;;;###autoload |
5e72c6b2 | 1164 | (defun idlwave-shell (&optional arg quick) |
8c7b4ec8 EZ |
1165 | "Run an inferior IDL, with I/O through buffer `(idlwave-shell-buffer)'. |
1166 | If buffer exists but shell process is not running, start new IDL. | |
1167 | If buffer exists and shell process is running, just switch to the buffer. | |
1168 | ||
1169 | When called with a prefix ARG, or when `idlwave-shell-use-dedicated-frame' | |
1170 | is non-nil, the shell buffer and the source buffers will be in | |
1171 | separate frames. | |
1172 | ||
5e72c6b2 S |
1173 | The command to run comes from variable `idlwave-shell-explicit-file-name', |
1174 | with options taken from `idlwave-shell-command-line-options'. | |
8c7b4ec8 EZ |
1175 | |
1176 | The buffer is put in `idlwave-shell-mode', providing commands for sending | |
1177 | input and controlling the IDL job. See help on `idlwave-shell-mode'. | |
1178 | See also the variable `idlwave-shell-prompt-pattern'. | |
1179 | ||
1180 | \(Type \\[describe-mode] in the shell buffer for a list of commands.)" | |
1181 | (interactive "P") | |
5e72c6b2 S |
1182 | (if (eq arg 'quick) |
1183 | (progn | |
1184 | (let ((idlwave-shell-use-dedicated-frame nil)) | |
1185 | (idlwave-shell nil) | |
1186 | (delete-other-windows)) | |
1187 | (and idlwave-shell-use-dedicated-frame | |
1188 | (setq idlwave-shell-idl-wframe (selected-frame))) | |
5cba7601 | 1189 | (add-hook 'idlwave-shell-sentinel-hook |
5e72c6b2 S |
1190 | 'save-buffers-kill-emacs t)) |
1191 | ||
1192 | ;; A non-nil arg means, we want a dedicated frame. This will last | |
1193 | ;; for the current editing session. | |
1194 | (if arg (setq idlwave-shell-use-dedicated-frame t)) | |
1195 | (if (equal arg '(16)) (setq idlwave-shell-use-dedicated-frame nil)) | |
5cba7601 | 1196 | |
5e72c6b2 S |
1197 | ;; Check if the process still exists. If not, create it. |
1198 | (unless (comint-check-proc (idlwave-shell-buffer)) | |
1199 | (let* ((prg (or idlwave-shell-explicit-file-name "idl")) | |
1200 | (buf (apply 'make-comint | |
1201 | idlwave-shell-process-name prg nil | |
1202 | (if (stringp idlwave-shell-command-line-options) | |
1203 | (idlwave-split-string | |
1204 | idlwave-shell-command-line-options) | |
1205 | idlwave-shell-command-line-options))) | |
1206 | (process (get-buffer-process buf))) | |
1207 | (setq idlwave-idlwave_routine_info-compiled nil) | |
1208 | (set-process-filter process 'idlwave-shell-filter) | |
1209 | (set-process-sentinel process 'idlwave-shell-sentinel) | |
1210 | (set-buffer buf) | |
1211 | (idlwave-shell-mode))) | |
1212 | (let ((window (idlwave-display-buffer (idlwave-shell-buffer) nil | |
1213 | (idlwave-shell-shell-frame))) | |
1214 | (current-window (selected-window))) | |
1215 | (select-window window) | |
1216 | (goto-char (point-max)) | |
f66f03de S |
1217 | (if idlwave-shell-use-dedicated-window |
1218 | (set-window-dedicated-p window t)) | |
5e72c6b2 S |
1219 | (select-window current-window) |
1220 | (if idlwave-shell-ready | |
1221 | (raise-frame (window-frame window))) | |
1222 | (if (eq (selected-frame) (window-frame window)) | |
52a244eb | 1223 | (select-window window)))) |
f66f03de | 1224 | ;; Save the paths at the end, if they are from the Shell and new. |
5cba7601 | 1225 | (add-hook 'idlwave-shell-sentinel-hook |
52a244eb | 1226 | (lambda () |
5cba7601 | 1227 | (if (and |
52a244eb S |
1228 | idlwave-auto-write-paths |
1229 | idlwave-path-alist | |
1230 | (not idlwave-library-path) | |
1231 | (get 'idlwave-path-alist 'from-shell)) | |
1232 | (idlwave-write-paths))))) | |
8c7b4ec8 EZ |
1233 | |
1234 | (defun idlwave-shell-recenter-shell-window (&optional arg) | |
1235 | "Run `idlwave-shell', but make sure the current window stays selected." | |
1236 | (interactive "P") | |
1237 | (let ((window (selected-window))) | |
1238 | (idlwave-shell arg) | |
1239 | (select-window window))) | |
1240 | ||
52a244eb | 1241 | (defun idlwave-shell-hide-p (type &optional list) |
76959b77 S |
1242 | "Whether to hide this type of command. |
1243 | Return either nil or 'hide." | |
52a244eb S |
1244 | (let ((list (or list idlwave-shell-show-commands))) |
1245 | (if (listp list) | |
1246 | (if (not (memq type list)) 'hide)))) | |
1247 | ||
1248 | (defun idlwave-shell-add-or-remove-show (type) | |
1249 | "Add or remove a show command from the list." | |
76959b77 | 1250 | (if (listp idlwave-shell-show-commands) |
52a244eb S |
1251 | (setq idlwave-shell-show-commands |
1252 | (if (memq type idlwave-shell-show-commands) | |
1253 | (delq type idlwave-shell-show-commands) | |
1254 | (add-to-list'idlwave-shell-show-commands type))) | |
1255 | (setq idlwave-shell-show-commands (list type)))) | |
1256 | ||
76959b77 | 1257 | |
5cba7601 | 1258 | (defun idlwave-shell-send-command (&optional cmd pcmd hide preempt |
52a244eb | 1259 | show-if-error) |
8c7b4ec8 EZ |
1260 | "Send a command to IDL process. |
1261 | ||
5a0c3f56 JB |
1262 | \(CMD PCMD HIDE\) are placed at the end of `idlwave-shell-pending-commands'. |
1263 | If IDL is ready the first command in `idlwave-shell-pending-commands', | |
1264 | CMD, is sent to the IDL process. | |
52a244eb | 1265 | |
76959b77 | 1266 | If optional second argument PCMD is non-nil it will be placed on |
52a244eb S |
1267 | `idlwave-shell-post-command-hook' when CMD is executed. |
1268 | ||
1269 | If the optional third argument HIDE is non-nil, then hide output from | |
1270 | CMD, unless it is the symbol 'mostly, in which case only output | |
1271 | beginning with \"%\" is hidden, and all other output (i.e., the | |
1272 | results of a PRINT command), is shown. This helps with, e.g., | |
1273 | stepping through code with output. | |
1274 | ||
8c7b4ec8 | 1275 | If optional fourth argument PREEMPT is non-nil CMD is put at front of |
76959b77 S |
1276 | `idlwave-shell-pending-commands'. If PREEMPT is 'wait, wait for all |
1277 | output to complete and the next prompt to arrive before returning | |
5a0c3f56 | 1278 | \(useful if you need an answer now\). IDL is considered ready if the |
5cba7601 | 1279 | prompt is present and if `idlwave-shell-ready' is non-nil. |
52a244eb | 1280 | |
6a8cc02d | 1281 | If SHOW-IF-ERROR is non-nil, show the output if it contains an error |
52a244eb | 1282 | message, independent of what HIDE is set to." |
76959b77 S |
1283 | |
1284 | ; (setq hide nil) ; FIXME: turn this on for debugging only | |
5cba7601 | 1285 | ; (if (null cmd) |
76959b77 | 1286 | ; (progn |
5cba7601 | 1287 | ; (message "SENDING Pending commands: %s" |
76959b77 | 1288 | ; (prin1-to-string idlwave-shell-pending-commands))) |
3938cb82 | 1289 | ; (message "SENDING %s|||%s" cmd pcmd)) |
5cba7601 | 1290 | (if (and (symbolp idlwave-shell-show-commands) |
76959b77 S |
1291 | (eq idlwave-shell-show-commands 'everything)) |
1292 | (setq hide nil)) | |
1293 | (let ((save-buffer (current-buffer)) | |
1294 | buf proc) | |
8c7b4ec8 EZ |
1295 | ;; Get or make the buffer and its process |
1296 | (if (or (not (setq buf (get-buffer (idlwave-shell-buffer)))) | |
1297 | (not (setq proc (get-buffer-process buf)))) | |
1298 | (if (not idlwave-shell-automatic-start) | |
768b14f8 | 1299 | (error "%s" |
8c7b4ec8 EZ |
1300 | (substitute-command-keys |
1301 | "You need to first start an IDL shell with \\[idlwave-shell]")) | |
1302 | (idlwave-shell-recenter-shell-window) | |
1303 | (setq buf (get-buffer (idlwave-shell-buffer))) | |
1304 | (if (or (not (setq buf (get-buffer (idlwave-shell-buffer)))) | |
1305 | (not (setq proc (get-buffer-process buf)))) | |
1306 | ;; Still nothing | |
1307 | (error "Problem with autostarting IDL shell")))) | |
76959b77 | 1308 | (when (or cmd idlwave-shell-pending-commands) |
8c7b4ec8 | 1309 | (set-buffer buf) |
8c7b4ec8 EZ |
1310 | ;; To make this easy, always push CMD onto pending commands |
1311 | (if cmd | |
76959b77 S |
1312 | (setq idlwave-shell-pending-commands |
1313 | (if preempt | |
1314 | ;; Put at front. | |
52a244eb | 1315 | (append (list (list cmd pcmd hide show-if-error)) |
76959b77 S |
1316 | idlwave-shell-pending-commands) |
1317 | ;; Put at end. | |
5cba7601 | 1318 | (append idlwave-shell-pending-commands |
52a244eb | 1319 | (list (list cmd pcmd hide show-if-error)))))) |
8c7b4ec8 | 1320 | ;; Check if IDL ready |
76959b77 S |
1321 | (let ((save-point (point-marker))) |
1322 | (goto-char (process-mark proc)) | |
1323 | (if (and idlwave-shell-ready | |
1324 | ;; Check for IDL prompt | |
1325 | (prog2 | |
1326 | (forward-line 0) | |
1327 | ;; (beginning-of-line) ; Changed for Emacs 21 | |
1328 | (looking-at idlwave-shell-prompt-pattern) | |
1329 | (goto-char (process-mark proc)))) | |
1330 | ;; IDL ready for command, execute it | |
1331 | (let* ((lcmd (car idlwave-shell-pending-commands)) | |
1332 | (cmd (car lcmd)) | |
1333 | (pcmd (nth 1 lcmd)) | |
52a244eb S |
1334 | (hide (nth 2 lcmd)) |
1335 | (show-if-error (nth 3 lcmd))) | |
76959b77 S |
1336 | ;; If this is an executive command, reset the stack pointer |
1337 | (if (eq (string-to-char cmd) ?.) | |
1338 | (setq idlwave-shell-calling-stack-index 0)) | |
1339 | ;; Set post-command | |
1340 | (setq idlwave-shell-post-command-hook pcmd) | |
1341 | ;; Output hiding | |
1342 | (setq idlwave-shell-hide-output hide) | |
52a244eb S |
1343 | ;;Showing errors |
1344 | (setq idlwave-shell-show-if-error show-if-error) | |
76959b77 S |
1345 | ;; Pop command |
1346 | (setq idlwave-shell-pending-commands | |
1347 | (cdr idlwave-shell-pending-commands)) | |
1348 | ;; Send command for execution | |
1349 | (set-marker comint-last-input-start (point)) | |
1350 | (set-marker comint-last-input-end (point)) | |
1351 | (comint-simple-send proc cmd) | |
1352 | (setq idlwave-shell-ready nil) | |
3938cb82 S |
1353 | (if (equal preempt 'wait) ; Get all the output at once |
1354 | (while (not idlwave-shell-ready) | |
1355 | (when (not (accept-process-output proc 6)) ; long wait | |
1356 | (setq idlwave-shell-pending-commands nil) | |
1357 | (error "Process timed out")))))) | |
76959b77 S |
1358 | (goto-char save-point)) |
1359 | (set-buffer save-buffer)))) | |
8c7b4ec8 | 1360 | |
6db31cbc | 1361 | (defun idlwave-shell-send-char (c &optional error) |
15e42531 | 1362 | "Send one character to the shell, without a newline." |
6db31cbc RS |
1363 | (interactive "cChar to send to IDL: \np") |
1364 | (let ((errf (if error 'error 'message)) | |
15e42531 CD |
1365 | buf proc) |
1366 | (if (or (not (setq buf (get-buffer (idlwave-shell-buffer)))) | |
1367 | (not (setq proc (get-buffer-process buf)))) | |
1368 | (funcall errf "Shell is not running")) | |
5cba7601 | 1369 | (if (equal c ?\C-g) |
15e42531 CD |
1370 | (funcall errf "Abort") |
1371 | (comint-send-string proc (char-to-string c))))) | |
1372 | ||
1373 | (defvar idlwave-shell-char-mode-active) | |
1374 | (defun idlwave-shell-input-mode-magic (string) | |
1375 | "Check STRING for magic words and toggle character input mode. | |
1376 | See also the variable `idlwave-shell-input-mode-spells'." | |
1377 | (cond | |
1378 | ((string-match (car idlwave-shell-input-mode-spells) string) | |
1379 | (call-interactively 'idlwave-shell-send-char)) | |
1380 | ((and (boundp 'idlwave-shell-char-mode-active) | |
1381 | (string-match (nth 2 idlwave-shell-input-mode-spells) string)) | |
1382 | (setq idlwave-shell-char-mode-active 'exit)) | |
1383 | ((string-match (nth 1 idlwave-shell-input-mode-spells) string) | |
1384 | ;; Set a timer which will soon start the character loop | |
1385 | (if (fboundp 'start-itimer) | |
1386 | (start-itimer "IDLWAVE Char Mode" 'idlwave-shell-char-mode-loop 0.5 | |
1387 | nil nil t 'no-error) | |
1388 | (run-at-time 0.5 nil 'idlwave-shell-char-mode-loop 'no-error))))) | |
1389 | ||
1390 | (defvar keyboard-quit) | |
1391 | (defun idlwave-shell-char-mode-loop (&optional no-error) | |
1392 | "Enter a loop which accepts single characters and sends them to IDL. | |
1393 | Characters are sent one by one, without newlines. The loop is blocking | |
1394 | and intercepts all input events to Emacs. You can use this command | |
1395 | to interact with the IDL command GET_KBRD. | |
1396 | The loop can be aborted by typing `C-g'. The loop also exits automatically | |
1397 | when the IDL prompt gets displayed again after the current IDL command." | |
1398 | (interactive) | |
1399 | ||
1400 | ;; First check if there is a shell waiting for input | |
1401 | (let ((idlwave-shell-char-mode-active t) | |
1402 | (errf (if no-error 'message 'error)) | |
1403 | buf proc c) | |
1404 | (if (or (not (setq buf (get-buffer (idlwave-shell-buffer)))) | |
1405 | (not (setq proc (get-buffer-process buf)))) | |
1406 | (funcall errf "Shell is not running")) | |
1407 | (if idlwave-shell-ready | |
1408 | (funcall errf "No IDL program seems to be waiting for input")) | |
1409 | ||
5cba7601 | 1410 | ;; OK, start the loop |
15e42531 CD |
1411 | (message "Character mode on: Sending single chars (`C-g' to exit)") |
1412 | (message | |
1413 | (catch 'exit | |
1414 | (while t | |
1415 | ;; Wait for input | |
1416 | ;; FIXME: Is it too dangerous to inhibit quit here? | |
1417 | (let ((inhibit-quit t)) | |
1418 | ;; We wait and check frequently if we should abort | |
1419 | (while (sit-for 0.3) | |
1420 | (and idlwave-shell-ready | |
1421 | (throw 'exit "Character mode off (prompt displayed)")) | |
1422 | (and (eq idlwave-shell-char-mode-active 'exit) | |
1423 | (throw 'exit "Character mode off (closing spell incantation)"))) | |
1424 | ;; Interpret input as a character - ignore non-char input | |
1425 | (condition-case nil | |
1426 | (setq c (read-char)) | |
05a1abfc | 1427 | (error (ding) (throw 'exit "Character mode off"))) |
15e42531 CD |
1428 | (cond |
1429 | ((null c) ; Non-char event: ignore | |
1430 | (ding)) | |
1431 | ((equal c ?\C-g) ; Abort the loop | |
1432 | (setq keyboard-quit nil) | |
1433 | (ding) | |
1434 | (throw 'exit "Character mode off (keyboard quit)")) | |
1435 | (t ; Send the character and continue the loop | |
1436 | (comint-send-string proc (char-to-string c)))) | |
1437 | (and (eq idlwave-shell-char-mode-active 'exit) | |
1438 | (throw 'exit "Single char loop exited")))))))) | |
1439 | ||
76959b77 | 1440 | (defun idlwave-shell-move-or-history (up &optional arg) |
05a1abfc | 1441 | "When in last line of process buffer, do `comint-previous-input'. |
76959b77 S |
1442 | Otherwise just move the line. Move down unless UP is non-nil." |
1443 | (let* ((proc-pos (marker-position | |
1444 | (process-mark (get-buffer-process (current-buffer))))) | |
1445 | (arg (or arg 1)) | |
1446 | (arg (if up arg (- arg)))) | |
1447 | (if (eq t idlwave-shell-arrows-do-history) (goto-char proc-pos)) | |
1448 | (if (and idlwave-shell-arrows-do-history | |
e180ab9f | 1449 | (>= (1+ (point-at-eol)) proc-pos)) |
d105bfec | 1450 | (comint-previous-input arg) |
7caf6803 | 1451 | (forward-line (- arg))))) |
76959b77 S |
1452 | |
1453 | (defun idlwave-shell-up-or-history (&optional arg) | |
1454 | "When in last line of process buffer, move to previous input. | |
1455 | Otherwise just go up one line." | |
05a1abfc | 1456 | (interactive "p") |
76959b77 | 1457 | (idlwave-shell-move-or-history t arg)) |
05a1abfc CD |
1458 | |
1459 | (defun idlwave-shell-down-or-history (&optional arg) | |
76959b77 S |
1460 | "When in last line of process buffer, move to next input. |
1461 | Otherwise just go down one line." | |
05a1abfc | 1462 | (interactive "p") |
76959b77 | 1463 | (idlwave-shell-move-or-history nil arg)) |
8c7b4ec8 | 1464 | |
76959b77 S |
1465 | ;; Newer versions of comint.el changed the name of comint-filter to |
1466 | ;; comint-output-filter. | |
8c7b4ec8 EZ |
1467 | (defun idlwave-shell-comint-filter (process string) nil) |
1468 | (if (fboundp 'comint-output-filter) | |
1469 | (fset 'idlwave-shell-comint-filter (symbol-function 'comint-output-filter)) | |
1470 | (fset 'idlwave-shell-comint-filter (symbol-function 'comint-filter))) | |
1471 | ||
1472 | (defun idlwave-shell-is-running () | |
1473 | "Return t if the shell process is running." | |
1474 | (eq (process-status idlwave-shell-process-name) 'run)) | |
1475 | ||
52a244eb S |
1476 | (defun idlwave-shell-filter-hidden-output (output) |
1477 | "Filter hidden output, leaving the good stuff. | |
1478 | ||
1479 | Remove everything to the first newline, and all lines with % in front | |
1480 | of them, with optional follow-on lines starting with two spaces. This | |
1481 | works well enough, since any print output typically arrives before | |
1482 | error messages, etc." | |
1483 | (setq output (substring output (string-match "\n" output))) | |
1484 | (while (string-match "\\(\n\\|\\`\\)%.*\\(\n .*\\)*" output) | |
1485 | (setq output (replace-match "" nil t output))) | |
5cba7601 | 1486 | (unless |
52a244eb S |
1487 | (string-match idlwave-shell-only-prompt-pattern output) |
1488 | output)) | |
1489 | ||
15e42531 CD |
1490 | (defvar idlwave-shell-hidden-output-buffer " *idlwave-shell-hidden-output*" |
1491 | "Buffer containing hidden output from IDL commands.") | |
25d24a50 | 1492 | (defvar idlwave-shell-current-state nil) |
5cba7601 | 1493 | |
8c7b4ec8 | 1494 | (defun idlwave-shell-filter (proc string) |
52a244eb | 1495 | "Watch for IDL prompt and filter incoming text. |
8c7b4ec8 EZ |
1496 | When the IDL prompt is received executes `idlwave-shell-post-command-hook' |
1497 | and then calls `idlwave-shell-send-command' for any pending commands." | |
1498 | ;; We no longer do the cleanup here - this is done by the process sentinel | |
3938cb82 S |
1499 | (if (eq (process-status idlwave-shell-process-name) 'run) |
1500 | ;; OK, process is still running, so we can use it. | |
1501 | (let ((data (match-data)) p full-output) | |
1502 | (unwind-protect | |
1503 | (progn | |
1504 | ;; Ring the bell if necessary | |
1505 | (while (setq p (string-match "\C-G" string)) | |
1506 | (ding) | |
1507 | (aset string p ?\C-j )) | |
1508 | (if idlwave-shell-hide-output | |
1509 | (save-excursion | |
1510 | (while (setq p (string-match "\C-M" string)) | |
1511 | (aset string p ?\ )) | |
1512 | (set-buffer | |
1513 | (get-buffer-create idlwave-shell-hidden-output-buffer)) | |
1514 | (goto-char (point-max)) | |
1515 | (insert string)) | |
1516 | (idlwave-shell-comint-filter proc string)) | |
1517 | ;; Watch for magic - need to accumulate the current line | |
1518 | ;; since it may not be sent all at once. | |
1519 | (if (string-match "\n" string) | |
1520 | (progn | |
1521 | (if idlwave-shell-use-input-mode-magic | |
1522 | (idlwave-shell-input-mode-magic | |
1523 | (concat idlwave-shell-accumulation string))) | |
1524 | (setq idlwave-shell-accumulation | |
5cba7601 GM |
1525 | (substring string |
1526 | (progn (string-match "\\(.*[\n\r]+\\)*" | |
3938cb82 S |
1527 | string) |
1528 | (match-end 0))))) | |
1529 | (setq idlwave-shell-accumulation | |
1530 | (concat idlwave-shell-accumulation string))) | |
5cba7601 GM |
1531 | |
1532 | ||
9a529312 SM |
1533 | ;; ;; Test/Debug code |
1534 | ;;(with-current-buffer | |
1535 | ;; (get-buffer-create "*idlwave-shell-output*") | |
1536 | ;; (goto-char (point-max)) | |
1537 | ;; (insert "\nReceived STRING\n===>\n" string "\n<====\n")) | |
5cba7601 | 1538 | |
3938cb82 S |
1539 | ;; Check for prompt in current accumulating output |
1540 | (when (setq idlwave-shell-ready | |
1541 | (string-match idlwave-shell-prompt-pattern | |
1542 | idlwave-shell-accumulation)) | |
1543 | ;; Gather the command output | |
1544 | (if idlwave-shell-hide-output | |
9a529312 | 1545 | (with-current-buffer idlwave-shell-hidden-output-buffer |
3938cb82 S |
1546 | (setq full-output (buffer-string)) |
1547 | (goto-char (point-max)) | |
1548 | (re-search-backward idlwave-shell-prompt-pattern nil t) | |
1549 | (goto-char (match-end 0)) | |
1550 | (setq idlwave-shell-command-output | |
5cba7601 | 1551 | (buffer-substring-no-properties |
dd5baa1a | 1552 | (point-min) (point))) |
3938cb82 S |
1553 | (delete-region (point-min) (point))) |
1554 | (setq idlwave-shell-command-output | |
1555 | (with-current-buffer (process-buffer proc) | |
f66f03de | 1556 | (buffer-substring-no-properties |
3938cb82 S |
1557 | (save-excursion |
1558 | (goto-char (process-mark proc)) | |
f66f03de | 1559 | (forward-line 0) ; Emacs 21 (beginning-of-line nil) |
3938cb82 S |
1560 | (point)) |
1561 | comint-last-input-end)))) | |
1562 | ||
1563 | ;; Scan for state and do post commands - bracket | |
1564 | ;; them with idlwave-shell-ready=nil since they may | |
1565 | ;; call idlwave-shell-send-command themselves. | |
1566 | (let ((idlwave-shell-ready nil)) | |
1567 | (idlwave-shell-scan-for-state) | |
1568 | ;; Show the output in the shell if it contains an error | |
76959b77 | 1569 | (if idlwave-shell-hide-output |
3938cb82 S |
1570 | (if (and idlwave-shell-show-if-error |
1571 | (eq idlwave-shell-current-state 'error)) | |
1572 | (idlwave-shell-comint-filter proc full-output) | |
5cba7601 | 1573 | ;; If it's only *mostly* hidden, filter % lines, |
3938cb82 S |
1574 | ;; and show anything that remains |
1575 | (if (eq idlwave-shell-hide-output 'mostly) | |
1576 | (let ((filtered | |
5cba7601 | 1577 | (idlwave-shell-filter-hidden-output |
3938cb82 | 1578 | full-output))) |
5cba7601 GM |
1579 | (if filtered |
1580 | (idlwave-shell-comint-filter | |
3938cb82 | 1581 | proc filtered)))))) |
5cba7601 | 1582 | |
3938cb82 S |
1583 | ;; Call the post-command hook |
1584 | (if (listp idlwave-shell-post-command-hook) | |
1585 | (progn | |
f66f03de S |
1586 | ;;(message "Calling list") |
1587 | ;;(prin1 idlwave-shell-post-command-hook) | |
3938cb82 | 1588 | (eval idlwave-shell-post-command-hook)) |
f66f03de | 1589 | ;;(message "Calling command function") |
3938cb82 S |
1590 | (funcall idlwave-shell-post-command-hook)) |
1591 | ||
1592 | ;; Reset to default state for next command. | |
1593 | ;; Also we do not want to find this prompt again. | |
1594 | (setq idlwave-shell-accumulation nil | |
1595 | idlwave-shell-command-output nil | |
1596 | idlwave-shell-post-command-hook nil | |
1597 | idlwave-shell-hide-output nil | |
1598 | idlwave-shell-show-if-error nil)) | |
5a0c3f56 | 1599 | ;; Done with post command. Do pending command if |
3938cb82 S |
1600 | ;; any. |
1601 | (idlwave-shell-send-command))) | |
1602 | (store-match-data data))))) | |
8c7b4ec8 EZ |
1603 | |
1604 | (defun idlwave-shell-sentinel (process event) | |
1605 | "The sentinel function for the IDLWAVE shell process." | |
1606 | (let* ((buf (idlwave-shell-buffer)) | |
1607 | (win (get-buffer-window buf))) | |
1608 | (when (get-buffer buf) | |
9a529312 | 1609 | (with-current-buffer (idlwave-shell-buffer) |
8c7b4ec8 | 1610 | (goto-char (point-max)) |
5e72c6b2 S |
1611 | (insert (format "\n\n Process %s %s" process event)) |
1612 | (if (and idlwave-shell-save-command-history | |
1613 | (stringp idlwave-shell-command-history-file)) | |
1614 | (condition-case nil | |
1615 | (comint-write-input-ring) | |
1616 | (error nil))))) | |
5cba7601 | 1617 | |
8c7b4ec8 EZ |
1618 | (when (and (> (length (frame-list)) 1) |
1619 | (frame-live-p idlwave-shell-idl-wframe)) | |
1620 | (delete-frame idlwave-shell-idl-wframe) | |
1621 | (setq idlwave-shell-idl-wframe nil | |
1622 | idlwave-shell-display-wframe nil)) | |
5e72c6b2 S |
1623 | (when (and (window-live-p win) |
1624 | (not (one-window-p 'nomini))) | |
8c7b4ec8 | 1625 | (delete-window win)) |
5e72c6b2 S |
1626 | (idlwave-shell-cleanup) |
1627 | ;; Run the hook, if possible in the shell buffer. | |
1628 | (if (get-buffer buf) | |
9a529312 | 1629 | (with-current-buffer buf |
5e72c6b2 S |
1630 | (run-hooks 'idlwave-shell-sentinel-hook)) |
1631 | (run-hooks 'idlwave-shell-sentinel-hook)))) | |
8c7b4ec8 | 1632 | |
25d24a50 S |
1633 | (defvar idlwave-shell-error-buffer " *idlwave-shell-errors*" |
1634 | "Buffer containing syntax errors from IDL compilations.") | |
1635 | ||
1636 | ;; FIXME: the following two variables do not currently allow line breaks | |
1637 | ;; in module and file names. I am not sure if it will be necessary to | |
1638 | ;; change this. Currently it seems to work the way it is. | |
1639 | (defvar idlwave-shell-syntax-error | |
5cba7601 GM |
1640 | "^% Syntax error.\\s-*\n\\s-*At:\\s-*\\(.*\\),\\s-*Line\\s-*\\(.*\\)" |
1641 | "A regular expression to match an IDL syntax error. | |
5a0c3f56 | 1642 | The first pair matches the file name, the second pair matches the line |
25d24a50 S |
1643 | number.") |
1644 | ||
1645 | (defvar idlwave-shell-other-error | |
1646 | "^% .*\n\\s-*At:\\s-*\\(.*\\),\\s-*Line\\s-*\\(.*\\)" | |
1647 | "A regular expression to match any IDL error.") | |
1648 | ||
5cba7601 | 1649 | (defvar idlwave-shell-halting-error |
25d24a50 S |
1650 | "^% .*\n\\([^%].*\n\\)*% Execution halted at:\\(\\s-*\\S-+\\s-*[0-9]+\\s-*.*\\)\n" |
1651 | "A regular expression to match errors which halt execution.") | |
1652 | ||
5cba7601 | 1653 | (defvar idlwave-shell-cant-continue-error |
25d24a50 S |
1654 | "^% Can't continue from this point.\n" |
1655 | "A regular expression to match errors stepping errors.") | |
1656 | ||
1657 | (defvar idlwave-shell-file-line-message | |
5cba7601 | 1658 | (concat |
25d24a50 S |
1659 | "\\(" ; program name group (1) |
1660 | "\\$MAIN\\$\\|" ; main level routine | |
1661 | "\\<[a-zA-Z][a-zA-Z0-9_$:]*" ; start with a letter followed by [..] | |
1662 | "\\([ \t]*\n[ \t]*[a-zA-Z0-9_$:]+\\)*"; continuation lines program name (2) | |
1663 | "\\)" ; end program name group (1) | |
1664 | "[ \t\n]+" ; white space | |
1665 | "\\(" ; line number group (3) | |
1666 | "[0-9]+" ; the line number (the fix point) | |
1667 | "\\([ \t]*\n[ \t]*[0-9]+\\)*" ; continuation lines number (4) | |
1668 | "\\)" ; end line number group (3) | |
1669 | "[ \t\n]+" ; white space | |
1670 | "\\(" ; file name group (5) | |
1671 | "[^ \t\n]+" ; file names can contain any non-white | |
1672 | "\\([ \t]*\n[ \t]*[^ \t\n]+\\)*" ; continuation lines file name (6) | |
1673 | "\\)" ; end line number group (5) | |
1674 | ) | |
1675 | "*A regular expression to parse out the file name and line number. | |
5cba7601 | 1676 | The 1st group should match the subroutine name. |
25d24a50 S |
1677 | The 3rd group is the line number. |
1678 | The 5th group is the file name. | |
1679 | All parts may contain linebreaks surrounded by spaces. This is important | |
1680 | in IDL5 which inserts random linebreaks in long module and file names.") | |
1681 | ||
f66f03de S |
1682 | (defvar idlwave-shell-electric-debug-mode) ; defined by easy-mmode |
1683 | ||
8c7b4ec8 | 1684 | (defun idlwave-shell-scan-for-state () |
5a0c3f56 JB |
1685 | "Scan for state info. |
1686 | Looks for messages in output from last IDL command indicating where | |
1687 | IDL has stopped. The types of messages we are interested in are | |
1688 | execution halted, stepped, breakpoint, interrupted at and trace | |
1689 | messages. For breakpoint messages process any attached count or | |
1690 | command parameters. Update the stop line if a message is found. | |
1691 | The variable `idlwave-shell-current-state' is set to 'error, 'halt, | |
1692 | or 'breakpoint, which describes the status, or nil for none of | |
52a244eb S |
1693 | the above." |
1694 | (let (trace) | |
1695 | (cond | |
1696 | ;; Make sure we have output | |
1697 | ((not idlwave-shell-command-output)) | |
5cba7601 | 1698 | |
52a244eb | 1699 | ;; First Priority: Syntax and other errors |
5cba7601 | 1700 | ((or |
52a244eb S |
1701 | (string-match idlwave-shell-syntax-error |
1702 | idlwave-shell-command-output) | |
1703 | (string-match idlwave-shell-other-error | |
1704 | idlwave-shell-command-output)) | |
f66f03de S |
1705 | (with-current-buffer |
1706 | (get-buffer-create idlwave-shell-error-buffer) | |
52a244eb S |
1707 | (erase-buffer) |
1708 | (insert idlwave-shell-command-output) | |
1709 | (goto-char (point-min)) | |
1710 | (setq idlwave-shell-error-last (point))) | |
1711 | (setq idlwave-shell-current-state 'error) | |
1712 | (idlwave-shell-goto-next-error)) | |
5cba7601 | 1713 | |
52a244eb S |
1714 | ;; Second Priority: Halting errors |
1715 | ((string-match idlwave-shell-halting-error | |
1716 | idlwave-shell-command-output) | |
1717 | ;; Grab the file and line state info. | |
1718 | (setq idlwave-shell-calling-stack-index 0) | |
1719 | (setq idlwave-shell-halt-frame | |
5cba7601 GM |
1720 | (idlwave-shell-parse-line |
1721 | (substring idlwave-shell-command-output | |
52a244eb S |
1722 | (match-beginning 2))) |
1723 | idlwave-shell-current-state 'error) | |
1724 | (idlwave-shell-display-line (idlwave-shell-pc-frame))) | |
5cba7601 | 1725 | |
52a244eb S |
1726 | ;; Third Priority: Various types of innocuous HALT and |
1727 | ;; TRACEBACK messages. | |
1728 | ((or (setq trace (string-match idlwave-shell-trace-message-re | |
1729 | idlwave-shell-command-output)) | |
1730 | (string-match idlwave-shell-halt-messages-re | |
1731 | idlwave-shell-command-output)) | |
1732 | ;; Grab the file and line state info. | |
1733 | (setq idlwave-shell-calling-stack-index 0) | |
1734 | (setq idlwave-shell-halt-frame | |
5cba7601 | 1735 | (idlwave-shell-parse-line |
52a244eb S |
1736 | (substring idlwave-shell-command-output (match-end 0)))) |
1737 | (setq idlwave-shell-current-state 'halt) | |
1738 | ;; Don't debug trace messages | |
5cba7601 | 1739 | (idlwave-shell-display-line |
f66f03de S |
1740 | (idlwave-shell-pc-frame) nil |
1741 | (if trace 'disable | |
1742 | (if idlwave-shell-electric-debug-mode 'force)))) | |
5cba7601 GM |
1743 | |
1744 | ;; Fourth Priority: Breakpoints | |
52a244eb S |
1745 | ((string-match idlwave-shell-break-message |
1746 | idlwave-shell-command-output) | |
1747 | (setq idlwave-shell-calling-stack-index 0) | |
5cba7601 GM |
1748 | (setq idlwave-shell-halt-frame |
1749 | (idlwave-shell-parse-line | |
52a244eb S |
1750 | (substring idlwave-shell-command-output (match-end 0)))) |
1751 | ;; We used to count hits on breakpoints | |
1752 | ;; this is no longer supported since IDL breakpoints | |
1753 | ;; have learned counting. | |
1754 | ;; Do breakpoint command processing | |
5cba7601 | 1755 | (let ((bp (assoc |
52a244eb S |
1756 | (list |
1757 | (nth 0 idlwave-shell-halt-frame) | |
1758 | (nth 1 idlwave-shell-halt-frame)) | |
1759 | idlwave-shell-bp-alist))) | |
1760 | ;(message "Scanning with %s" bp) | |
1761 | (if bp | |
1762 | (let ((cmd (idlwave-shell-bp-get bp 'cmd))) | |
1763 | (if cmd ;; Execute any breakpoint command | |
1764 | (if (listp cmd) (eval cmd) (funcall cmd)))) | |
1765 | ;; A breakpoint that we did not know about - perhaps it was | |
1766 | ;; set by the user... Let's update our list. | |
1767 | (idlwave-shell-bp-query))) | |
5cba7601 | 1768 | (setq idlwave-shell-current-state 'breakpoint) |
52a244eb | 1769 | (idlwave-shell-display-line (idlwave-shell-pc-frame))) |
5cba7601 | 1770 | |
52a244eb S |
1771 | ;; Last Priority: Can't Step errors |
1772 | ((string-match idlwave-shell-cant-continue-error | |
1773 | idlwave-shell-command-output) | |
1774 | (setq idlwave-shell-current-state 'breakpoint)) | |
1775 | ||
1776 | ;; Otherwise, no particular state | |
1777 | (t (setq idlwave-shell-current-state nil))))) | |
8c7b4ec8 | 1778 | |
3938cb82 | 1779 | |
52a244eb | 1780 | (defun idlwave-shell-parse-line (string &optional skip-main) |
f66f03de S |
1781 | "Parse IDL message for the subroutine, file name and line number." |
1782 | ;We need to work hard here to remove the stupid line breaks inserted by | |
1783 | ;IDL5. These line breaks can be right in the middle of procedure | |
1784 | ;or file names. | |
1785 | ;It is very difficult to come up with a robust solution. This one seems | |
5cba7601 | 1786 | ;to be pretty good though. |
f66f03de S |
1787 | ; |
1788 | ;Here is in what ways it improves over the previous solution: | |
1789 | ; | |
1790 | ;1. The procedure name can be split and will be restored. | |
1791 | ;2. The number can be split. I have never seen this, but who knows. | |
1792 | ;3. We do not require the `.pro' extension for files. | |
1793 | ; | |
1794 | ;This function can still break when the file name ends on an end line | |
1795 | ;and the message line contains an additional line with garbage. Then | |
1796 | ;the first part of that garbage will be added to the file name. | |
1797 | ;However, the function checks the existence of the files with and | |
1798 | ;without this last part - thus the function only breaks if file name | |
1799 | ;plus garbage match an existing regular file. This is hopefully very | |
1800 | ;unlikely. | |
1801 | ; | |
1802 | ;If optional arg SKIP-MAIN is non-nil, don't parse $MAIN$ routine stop | |
1803 | ;statements. | |
8c7b4ec8 EZ |
1804 | |
1805 | (let (number procedure file) | |
52a244eb S |
1806 | (when (and (not (if skip-main (string-match ":\\s-*\\$MAIN" string))) |
1807 | (string-match idlwave-shell-file-line-message string)) | |
8c7b4ec8 EZ |
1808 | (setq procedure (match-string 1 string) |
1809 | number (match-string 3 string) | |
1810 | file (match-string 5 string)) | |
5cba7601 | 1811 | |
8c7b4ec8 EZ |
1812 | ;; Repair the strings |
1813 | (setq procedure (idlwave-shell-repair-string procedure)) | |
1814 | (setq number (idlwave-shell-repair-string number)) | |
1815 | (setq file (idlwave-shell-repair-file-name file)) | |
1816 | ||
1817 | ;; If we have a file, return the frame list | |
1818 | (if file | |
1819 | (list (idlwave-shell-file-name file) | |
027a4b6b | 1820 | (string-to-number number) |
8c7b4ec8 EZ |
1821 | procedure) |
1822 | ;; No success finding a file | |
1823 | nil)))) | |
1824 | ||
1825 | (defun idlwave-shell-repair-string (string) | |
1826 | "Repair a string by taking out all linebreaks. This is destructive!" | |
1827 | (while (string-match "[ \t]*\n[ \t]*" string) | |
1828 | (setq string (replace-match "" t t string))) | |
1829 | string) | |
1830 | ||
1831 | (defun idlwave-shell-repair-file-name (file) | |
1832 | "Repair a file name string by taking out all linebreaks. | |
1833 | The last line of STRING may be garbage - we check which one makes a valid | |
1834 | file name." | |
1835 | (let ((file1 "") (file2 "") (start 0)) | |
1836 | ;; We scan no further than to the next "^%" line | |
5cba7601 | 1837 | (if (string-match "^%" file) |
8c7b4ec8 EZ |
1838 | (setq file (substring file 0 (match-beginning 0)))) |
1839 | ;; Take out the line breaks | |
1840 | (while (string-match "[ \t]*\n[ \t]*" file start) | |
1841 | (setq file1 (concat file1 (substring file start (match-beginning 0))) | |
1842 | start (match-end 0))) | |
1843 | (setq file2 (concat file1 (substring file start))) | |
1844 | (cond | |
1845 | ((file-regular-p file2) file2) | |
1846 | ((file-regular-p file1) file1) | |
1847 | ;; If we cannot veryfy the existence of the file, we return the shorter | |
1848 | ;; name. The idea behind this is that this may be a relative file name | |
1849 | ;; and our idea about the current working directory may be wrong. | |
1850 | ;; If it is a relative file name, it hopefully is short. | |
1851 | ((not (string= "" file1)) file1) | |
1852 | ((not (string= "" file2)) file2) | |
1853 | (t nil)))) | |
1854 | ||
1855 | (defun idlwave-shell-cleanup () | |
1856 | "Do necessary cleanup for a terminated IDL process." | |
1857 | (setq idlwave-shell-step-frame nil | |
1858 | idlwave-shell-halt-frame nil | |
1859 | idlwave-shell-pending-commands nil | |
1860 | idlwave-shell-command-line-to-execute nil | |
1861 | idlwave-shell-bp-alist nil | |
15e42531 | 1862 | idlwave-shell-calling-stack-index 0 |
8a36f093 | 1863 | idlwave-idlwave_routine_info-compiled nil) |
15e42531 | 1864 | (idlwave-shell-delete-temp-files) |
8c7b4ec8 EZ |
1865 | (idlwave-shell-display-line nil) |
1866 | (idlwave-shell-update-bp-overlays) ; kill old overlays | |
15e42531 | 1867 | (idlwave-shell-kill-buffer idlwave-shell-hidden-output-buffer) |
8c7b4ec8 EZ |
1868 | (idlwave-shell-kill-buffer idlwave-shell-bp-buffer) |
1869 | (idlwave-shell-kill-buffer idlwave-shell-error-buffer) | |
1870 | ;; (idlwave-shell-kill-buffer (idlwave-shell-buffer)) | |
1871 | (and (get-buffer (idlwave-shell-buffer)) | |
1872 | (bury-buffer (get-buffer (idlwave-shell-buffer)))) | |
1873 | (run-hooks 'idlwave-shell-cleanup-hook)) | |
1874 | ||
1875 | (defun idlwave-shell-kill-buffer (buf) | |
1876 | "Kill buffer BUF if it exists." | |
1877 | (if (setq buf (get-buffer buf)) | |
1878 | (kill-buffer buf))) | |
1879 | ||
1880 | (defun idlwave-shell-kill-shell-buffer-confirm () | |
1881 | (when (idlwave-shell-is-running) | |
1882 | (ding) | |
1883 | (unless (y-or-n-p "IDL shell is running. Are you sure you want to kill the buffer? ") | |
1884 | (error "Abort")) | |
1885 | (message "Killing buffer *idl* and the associated process"))) | |
1886 | ||
05a1abfc CD |
1887 | (defun idlwave-shell-window (n) |
1888 | "Issue a `window,N' command to IDL, with special window size. | |
1889 | The size is given by `idlwave-shell-graphics-window-size'." | |
1890 | (interactive "P") | |
1891 | (let ((n (if n (prefix-numeric-value n) 0))) | |
5cba7601 | 1892 | (idlwave-shell-send-command |
05a1abfc | 1893 | (apply 'format "window,%d,xs=%d,ys=%d" |
76959b77 | 1894 | n idlwave-shell-graphics-window-size) |
52a244eb | 1895 | nil (idlwave-shell-hide-p 'misc) nil t))) |
05a1abfc | 1896 | |
8c7b4ec8 | 1897 | (defun idlwave-shell-resync-dirs () |
76959b77 S |
1898 | "Resync the buffer's idea of the current directory. |
1899 | This command queries IDL with the command bound to | |
1900 | `idlwave-shell-dirstack-query', reads the output for the new | |
1901 | directory." | |
8c7b4ec8 EZ |
1902 | (interactive) |
1903 | (idlwave-shell-send-command idlwave-shell-dirstack-query | |
1904 | 'idlwave-shell-filter-directory | |
76959b77 | 1905 | 'hide 'wait)) |
8c7b4ec8 EZ |
1906 | |
1907 | (defun idlwave-shell-retall (&optional arg) | |
52a244eb S |
1908 | "Return from the entire calling stack. |
1909 | Also get rid of widget events in the queue." | |
8c7b4ec8 | 1910 | (interactive "P") |
52a244eb | 1911 | (save-selected-window |
5cba7601 GM |
1912 | ;;if (widget_info(/MANAGED))[0] gt 0 then for i=0,n_elements(widget_info(/MANAGED))-1 do widget_control,(widget_info(/MANAGED))[i],/clear_events & |
1913 | (idlwave-shell-send-command "retall" nil | |
1914 | (if (idlwave-shell-hide-p 'misc) 'mostly) | |
52a244eb S |
1915 | nil t) |
1916 | (idlwave-shell-display-line nil))) | |
8c7b4ec8 EZ |
1917 | |
1918 | (defun idlwave-shell-closeall (&optional arg) | |
1919 | "Close all open files." | |
1920 | (interactive "P") | |
5cba7601 | 1921 | (idlwave-shell-send-command "close,/all" nil |
52a244eb | 1922 | (idlwave-shell-hide-p 'misc) nil t)) |
8c7b4ec8 EZ |
1923 | |
1924 | (defun idlwave-shell-quit (&optional arg) | |
5a0c3f56 | 1925 | "Exit the IDL process after confirmation. |
8c7b4ec8 EZ |
1926 | With prefix ARG, exit without confirmation." |
1927 | (interactive "P") | |
1928 | (if (not (idlwave-shell-is-running)) | |
1929 | (error "Shell is not running") | |
1930 | (if (or arg (y-or-n-p "Exit the IDLWAVE Shell? ")) | |
1931 | (condition-case nil | |
1932 | (idlwave-shell-send-command "exit") | |
1933 | (error nil))))) | |
1934 | ||
ca660d22 | 1935 | (defun idlwave-shell-reset (&optional hidden) |
76959b77 | 1936 | "Reset IDL. Return to main level and destroy the leftover variables. |
5cba7601 | 1937 | This issues the following commands: |
8c7b4ec8 EZ |
1938 | RETALL |
1939 | WIDGET_CONTROL,/RESET | |
1940 | CLOSE, /ALL | |
1941 | HEAP_GC, /VERBOSE" | |
1942 | ;; OBJ_DESTROY, OBJ_VALID() FIXME: should this be added? | |
1943 | (interactive "P") | |
5cba7601 | 1944 | (when (or idlwave-shell-reset-no-prompt |
f66f03de S |
1945 | (yes-or-no-p "Really Reset IDL and discard current session? ")) |
1946 | (message "Resetting IDL") | |
1947 | (setq idlwave-shell-calling-stack-index 0) | |
1948 | ;; Give widget exit handlers a chance | |
1949 | (idlwave-shell-send-command "retall" nil hidden) | |
1950 | (idlwave-shell-send-command "widget_control,/reset" nil hidden) | |
1951 | (idlwave-shell-send-command "close,/all" nil hidden) | |
1952 | ;; (idlwave-shell-send-command "obj_destroy, obj_valid()" nil hidden) | |
1953 | (idlwave-shell-send-command "heap_gc,/verbose" nil hidden) | |
1954 | (idlwave-shell-display-line nil))) | |
8c7b4ec8 | 1955 | |
15e42531 CD |
1956 | (defun idlwave-shell-path-filter () |
1957 | ;; Convert the output of the path query into a list of directories | |
1958 | (let ((path-string idlwave-shell-command-output) | |
1959 | (case-fold-search t) | |
1960 | (start 0) | |
1961 | dirs sysdir) | |
05a1abfc | 1962 | (while (string-match "^PATH:[ \t]*<\\(.*\\)>[ \t]*\n" path-string start) |
15e42531 CD |
1963 | (push (match-string 1 path-string) dirs) |
1964 | (setq start (match-end 0))) | |
1965 | (setq dirs (mapcar 'file-name-as-directory dirs)) | |
05a1abfc | 1966 | (if (string-match "^SYSDIR:[ \t]*<\\(.*\\)>[ \t]*\n" path-string) |
15e42531 CD |
1967 | (setq sysdir (file-name-as-directory |
1968 | (match-string 1 path-string)))) | |
1969 | (cons sysdir (nreverse dirs)))) | |
1970 | ||
1971 | (defun idlwave-shell-routine-info-filter () | |
1972 | "Function which parses the special output from idlwave_routine_info.pro." | |
1973 | (let ((text idlwave-shell-command-output) | |
1974 | (start 0) | |
1975 | sep sep-re file type spec specs name cs key keys class entry) | |
52a244eb | 1976 | ;; (message "GOT: %s" text) ;?????????????????????? |
15e42531 CD |
1977 | ;; Initialize variables |
1978 | (setq idlwave-compiled-routines nil | |
1979 | idlwave-unresolved-routines nil) | |
1980 | ;; Cut out the correct part of the output. | |
1981 | (if (string-match | |
1982 | "^>>>BEGIN OF IDLWAVE ROUTINE INFO (\"\\(.+\\)\" IS THE SEPARATOR.*" | |
1983 | text) | |
1984 | (setq sep (match-string 1 text) | |
1985 | sep-re (concat (regexp-quote sep) " *") | |
1986 | text (substring text (match-end 0))) | |
1987 | ;; Set dummy values and kill the text | |
1988 | (setq sep "@" sep-re "@ *" text "") | |
52a244eb | 1989 | (if idlwave-idlwave_routine_info-compiled |
5cba7601 GM |
1990 | (message |
1991 | "Routine Info warning: No match for BEGIN line in \n>>>\n%s\n<<<\n" | |
52a244eb | 1992 | idlwave-shell-command-output))) |
15e42531 CD |
1993 | (if (string-match "^>>>END OF IDLWAVE ROUTINE INFO.*" text) |
1994 | (setq text (substring text 0 (match-beginning 0))) | |
52a244eb | 1995 | (if idlwave-idlwave_routine_info-compiled |
5cba7601 GM |
1996 | (message |
1997 | "Routine Info warning: No match for END line in \n>>>\n%s\n<<<\n" | |
52a244eb | 1998 | idlwave-shell-command-output))) |
15e42531 CD |
1999 | ;; Match the output lines |
2000 | (while (string-match "^IDLWAVE-\\(PRO\\|FUN\\): \\(.*\\)" text start) | |
2001 | (setq start (match-end 0)) | |
2002 | (setq type (match-string 1 text) | |
2003 | spec (match-string 2 text) | |
2004 | specs (idlwave-split-string spec sep-re) | |
2005 | name (nth 0 specs) | |
2006 | class (if (equal (nth 1 specs) "") nil (nth 1 specs)) | |
2007 | file (nth 2 specs) | |
2008 | cs (nth 3 specs) | |
2009 | key (nth 4 specs) | |
2010 | keys (if (and (stringp key) | |
2011 | (not (string-match "\\` *\\'" key))) | |
5cba7601 | 2012 | (mapcar 'list |
15e42531 CD |
2013 | (delete "" (idlwave-split-string key " +"))))) |
2014 | (setq name (idlwave-sintern-routine-or-method name class t) | |
2015 | class (idlwave-sintern-class class t) | |
2016 | file (if (equal file "") nil file) | |
5cba7601 | 2017 | keys (mapcar (lambda (x) |
15e42531 | 2018 | (list (idlwave-sintern-keyword (car x) t))) keys)) |
5cba7601 | 2019 | |
15e42531 CD |
2020 | ;; In the following ignore routines already defined in buffers, |
2021 | ;; assuming that if the buffer stuff differs, it is a "new" | |
52a244eb | 2022 | ;; version, not yet compiled, and should take precedence. |
15e42531 CD |
2023 | ;; We could do the same for the library to avoid duplicates - |
2024 | ;; but I think frequently a user might have several versions of | |
5cba7601 | 2025 | ;; the same function in different programs, and in this case the |
52a244eb | 2026 | ;; compiled one will be the best guess of all versions. |
15e42531 | 2027 | ;; Therefore, we leave duplicates of library routines in. |
15e42531 CD |
2028 | (cond ((string= name "$MAIN$")) ; ignore this one |
2029 | ((and (string= type "PRO") | |
2030 | ;; FIXME: is it OK to make the buffer routines dominate? | |
2031 | (or t (null file) | |
5cba7601 | 2032 | (not (idlwave-rinfo-assq name 'pro class |
15e42531 CD |
2033 | idlwave-buffer-routines))) |
2034 | ;; FIXME: is it OK to make the library routines dominate? | |
5cba7601 | 2035 | ;;(not (idlwave-rinfo-assq name 'pro class |
15e42531 CD |
2036 | ;; idlwave-library-routines)) |
2037 | ) | |
5cba7601 GM |
2038 | (setq entry (list name 'pro class |
2039 | (cons 'compiled | |
52a244eb S |
2040 | (if file |
2041 | (list | |
2042 | (file-name-nondirectory file) | |
5cba7601 | 2043 | (idlwave-sintern-dir |
52a244eb S |
2044 | (file-name-directory file))))) |
2045 | cs (cons nil keys))) | |
5cba7601 | 2046 | (if file |
15e42531 CD |
2047 | (push entry idlwave-compiled-routines) |
2048 | (push entry idlwave-unresolved-routines))) | |
5cba7601 | 2049 | |
15e42531 CD |
2050 | ((and (string= type "FUN") |
2051 | ;; FIXME: is it OK to make the buffer routines dominate? | |
2052 | (or t (not file) | |
5cba7601 | 2053 | (not (idlwave-rinfo-assq name 'fun class |
15e42531 CD |
2054 | idlwave-buffer-routines))) |
2055 | ;; FIXME: is it OK to make the library routines dominate? | |
5cba7601 | 2056 | ;; (not (idlwave-rinfo-assq name 'fun class |
15e42531 CD |
2057 | ;; idlwave-library-routines)) |
2058 | ) | |
5cba7601 | 2059 | (setq entry (list name 'fun class |
52a244eb S |
2060 | (cons 'compiled |
2061 | (if file | |
2062 | (list | |
2063 | (file-name-nondirectory file) | |
5cba7601 | 2064 | (idlwave-sintern-dir |
52a244eb S |
2065 | (file-name-directory file))))) |
2066 | cs (cons nil keys))) | |
15e42531 CD |
2067 | (if file |
2068 | (push entry idlwave-compiled-routines) | |
2069 | (push entry idlwave-unresolved-routines)))))) | |
2070 | ;; Reverse the definitions so that they are alphabetically sorted. | |
2071 | (setq idlwave-compiled-routines (nreverse idlwave-compiled-routines) | |
2072 | idlwave-unresolved-routines (nreverse idlwave-unresolved-routines))) | |
2073 | ||
8c7b4ec8 EZ |
2074 | (defun idlwave-shell-filter-directory () |
2075 | "Get the current directory from `idlwave-shell-command-output'. | |
2076 | Change the default directory for the process buffer to concur." | |
9a529312 | 2077 | (with-current-buffer (idlwave-shell-buffer) |
dd5baa1a | 2078 | (if (string-match ",___cur[\n\r ]+\\([^\n\r]+\\)[\n\r]" |
8c7b4ec8 | 2079 | idlwave-shell-command-output) |
5cba7601 | 2080 | (let ((dir (substring idlwave-shell-command-output |
8c7b4ec8 | 2081 | (match-beginning 1) (match-end 1)))) |
9a529312 | 2082 | ;; (message "Setting Emacs working dir to %s" dir) |
8c7b4ec8 EZ |
2083 | (setq idlwave-shell-default-directory dir) |
2084 | (setq default-directory (file-name-as-directory dir)))))) | |
2085 | ||
76959b77 S |
2086 | (defvar idlwave-shell-get-object-class nil) |
2087 | (defun idlwave-shell-get-object-class (apos) | |
2088 | "Query the shell for the class of the object before point." | |
2089 | (let ((bos (save-excursion (idlwave-start-of-substatement 'pre) (point))) | |
2090 | (bol (save-excursion (forward-line 0) (point))) | |
2091 | expression) | |
2092 | (save-excursion | |
2093 | (goto-char apos) | |
5cba7601 | 2094 | (setq expression (buffer-substring |
76959b77 S |
2095 | (catch 'exit |
2096 | (while t | |
5cba7601 | 2097 | (if (not (re-search-backward |
76959b77 S |
2098 | "[^][.A-Za-z0-9_() ]" bos t)) |
2099 | (throw 'exit bos)) ;ran into bos | |
2100 | (if (not (idlwave-is-pointer-dereference bol)) | |
2101 | (throw 'exit (1+ (point)))))) | |
2102 | apos))) | |
2103 | (when (not (string= expression "")) | |
2104 | (setq idlwave-shell-get-object-class nil) | |
2105 | (idlwave-shell-send-command | |
5cba7601 | 2106 | (concat "if obj_valid(" expression ") then print,obj_class(" |
3938cb82 | 2107 | expression ")") |
76959b77 S |
2108 | 'idlwave-shell-parse-object-class |
2109 | 'hide 'wait) | |
2110 | ;; If we don't know anything about the class, update shell routines | |
2111 | (if (and idlwave-shell-get-object-class | |
25d24a50 S |
2112 | (not (assoc-string idlwave-shell-get-object-class |
2113 | (idlwave-class-alist) t))) | |
76959b77 S |
2114 | (idlwave-shell-maybe-update-routine-info)) |
2115 | idlwave-shell-get-object-class))) | |
2116 | ||
2117 | (defun idlwave-shell-parse-object-class () | |
2118 | "Parse the output of the obj_class command." | |
3938cb82 | 2119 | (let ((match "obj_class([^\n\r]+[\n\r ]")) |
5cba7601 | 2120 | (if (string-match (concat match "\\([A-Za-z_0-9]+\\) *[\n\r]\\(" |
3938cb82 S |
2121 | idlwave-shell-prompt-pattern "\\)") |
2122 | idlwave-shell-command-output) | |
5cba7601 | 2123 | (setq idlwave-shell-get-object-class |
76959b77 S |
2124 | (match-string 1 idlwave-shell-command-output))))) |
2125 | ||
52a244eb S |
2126 | (defvar idlwave-sint-sysvars nil) |
2127 | (idlwave-new-sintern-type 'execcomm) | |
76959b77 | 2128 | |
8c7b4ec8 EZ |
2129 | (defun idlwave-shell-complete (&optional arg) |
2130 | "Do completion in the idlwave-shell buffer. | |
2131 | Calls `idlwave-shell-complete-filename' after some executive commands or | |
2132 | in strings. Otherwise, calls `idlwave-complete' to complete modules and | |
2133 | keywords." | |
8c7b4ec8 | 2134 | (interactive "P") |
52a244eb | 2135 | (let (exec-cmd) |
8c7b4ec8 | 2136 | (cond |
5cba7601 | 2137 | ((and |
52a244eb S |
2138 | (setq exec-cmd (idlwave-shell-executive-command)) |
2139 | (cdr exec-cmd) | |
2140 | (member (upcase (cdr exec-cmd)) | |
2141 | '(".R" ".RU" ".RUN" ".RN" ".RNE" ".RNEW" | |
2142 | ".COM" ".COMP" ".COMPI" ".COMPIL" ".COMPILE"))) | |
8c7b4ec8 | 2143 | ;; We are in a command line with an executive command |
52a244eb S |
2144 | (idlwave-shell-complete-filename)) |
2145 | ||
2146 | ((car-safe exec-cmd) | |
5cba7601 | 2147 | (setq idlwave-completion-help-info |
52a244eb S |
2148 | '(idlwave-shell-complete-execcomm-help)) |
2149 | (idlwave-complete-in-buffer 'execcomm 'execcomm | |
2150 | idlwave-executive-commands-alist nil | |
2151 | "Select an executive command" | |
2152 | "system variable")) | |
76959b77 S |
2153 | |
2154 | ((idlwave-shell-batch-command) | |
2155 | (idlwave-shell-complete-filename)) | |
2156 | ||
52a244eb S |
2157 | ((idlwave-shell-shell-command) |
2158 | (idlwave-shell-complete-filename)) | |
2159 | ||
15e42531 CD |
2160 | ((and (idlwave-shell-filename-string) |
2161 | (save-excursion | |
2162 | (beginning-of-line) | |
2163 | (let ((case-fold-search t)) | |
76959b77 S |
2164 | (not (looking-at ".*obj_new"))))) |
2165 | (idlwave-shell-complete-filename)) | |
5cba7601 | 2166 | |
8c7b4ec8 EZ |
2167 | (t |
2168 | ;; Default completion of modules and keywords | |
15e42531 | 2169 | (idlwave-complete arg))))) |
8c7b4ec8 | 2170 | |
e7c4fb1e GM |
2171 | ;; Get rid of opaque dynamic variable passing of idlw-help-link? |
2172 | (defvar idlw-help-link) ; dynamic variable from idlwave-do-mouse-completion-help | |
52a244eb S |
2173 | (defun idlwave-shell-complete-execcomm-help (mode word) |
2174 | (let ((word (or (nth 1 idlwave-completion-help-info) word)) | |
25d24a50 | 2175 | (entry (assoc-string word idlwave-executive-commands-alist t))) |
52a244eb S |
2176 | (cond |
2177 | ((eq mode 'test) | |
2178 | (and (stringp word) entry (cdr entry))) | |
2179 | ((eq mode 'set) | |
e7c4fb1e | 2180 | (if entry (setq idlw-help-link (cdr entry)))) ; setting dynamic variable! |
52a244eb S |
2181 | (t (error "This should not happen"))))) |
2182 | ||
8c7b4ec8 EZ |
2183 | (defun idlwave-shell-complete-filename (&optional arg) |
2184 | "Complete a file name at point if after a file name. | |
2185 | We assume that we are after a file name when completing one of the | |
76959b77 S |
2186 | args of an executive .run, .rnew or .compile." |
2187 | ;; CWD might have changed, resync, to set default directory | |
5cba7601 | 2188 | (idlwave-shell-resync-dirs) |
76959b77 | 2189 | (let ((comint-file-name-chars idlwave-shell-file-name-chars)) |
e4157b9c | 2190 | (comint-filename-completion))) |
8c7b4ec8 EZ |
2191 | |
2192 | (defun idlwave-shell-executive-command () | |
2193 | "Return the name of the current executive command, if any." | |
2194 | (save-excursion | |
2195 | (idlwave-beginning-of-statement) | |
52a244eb S |
2196 | (cons (looking-at "[ \t]*\\.") |
2197 | (if (looking-at "[ \t]*[.]\\([^ \t\n\r]+\\)[ \t]") | |
2198 | (match-string 1))))) | |
8c7b4ec8 EZ |
2199 | |
2200 | (defun idlwave-shell-filename-string () | |
2201 | "Return t if in a string and after what could be a file name." | |
e180ab9f | 2202 | (let ((limit (point-at-bol))) |
8c7b4ec8 EZ |
2203 | (save-excursion |
2204 | ;; Skip backwards over file name chars | |
2205 | (skip-chars-backward idlwave-shell-file-name-chars limit) | |
2206 | ;; Check of the next char is a string delimiter | |
2207 | (memq (preceding-char) '(?\' ?\"))))) | |
2208 | ||
76959b77 | 2209 | (defun idlwave-shell-batch-command () |
5a0c3f56 | 2210 | "Return t if we're in a batch command statement like @foo" |
e180ab9f | 2211 | (let ((limit (point-at-bol))) |
76959b77 S |
2212 | (save-excursion |
2213 | ;; Skip backwards over filename | |
2214 | (skip-chars-backward idlwave-shell-file-name-chars limit) | |
2215 | (skip-chars-backward " \t" limit) | |
2216 | (and (eq (preceding-char) ?@) (not (idlwave-in-quote)))))) | |
2217 | ||
52a244eb | 2218 | (defun idlwave-shell-shell-command () |
5a0c3f56 | 2219 | "Return t if we're in a shell command statement like $ls" |
52a244eb S |
2220 | (save-excursion |
2221 | (idlwave-beginning-of-statement) | |
2222 | (looking-at "\\$"))) | |
2223 | ||
2224 | ;; Debugging Commands ------------------------------------------------------ | |
8c7b4ec8 EZ |
2225 | |
2226 | (defun idlwave-shell-redisplay (&optional hide) | |
5a0c3f56 | 2227 | "Try to resync the display with where execution has stopped. |
5cba7601 | 2228 | Issues a \"help,/trace\" command followed by a call to |
8c7b4ec8 EZ |
2229 | `idlwave-shell-display-line'. Also updates the breakpoint |
2230 | overlays." | |
2231 | (interactive) | |
ca660d22 | 2232 | (setq idlwave-shell-calling-stack-index 0) |
8c7b4ec8 EZ |
2233 | (idlwave-shell-send-command |
2234 | "help,/trace" | |
2235 | '(idlwave-shell-display-line | |
2236 | (idlwave-shell-pc-frame)) | |
2237 | hide) | |
2238 | (idlwave-shell-bp-query)) | |
2239 | ||
2240 | (defun idlwave-shell-display-level-in-calling-stack (&optional hide) | |
5cba7601 | 2241 | (idlwave-shell-send-command |
8c7b4ec8 | 2242 | "help,/trace" |
ca660d22 CD |
2243 | `(progn |
2244 | ;; scanning for the state will reset the stack level - restore it | |
2245 | (setq idlwave-shell-calling-stack-index | |
2246 | ,idlwave-shell-calling-stack-index) | |
2247 | ;; parse the stack and visit the selected frame | |
2248 | (idlwave-shell-parse-stack-and-display)) | |
8c7b4ec8 EZ |
2249 | hide)) |
2250 | ||
2251 | (defun idlwave-shell-parse-stack-and-display () | |
2252 | (let* ((lines (delete "" (idlwave-split-string | |
2253 | idlwave-shell-command-output "^%"))) | |
2254 | (stack (delq nil (mapcar 'idlwave-shell-parse-line lines))) | |
2255 | (nmax (1- (length stack))) | |
2256 | (nmin 0) message) | |
8c7b4ec8 EZ |
2257 | (cond |
2258 | ((< nmax nmin) | |
15e42531 CD |
2259 | (setq idlwave-shell-calling-stack-index 0) |
2260 | (ding) | |
2261 | (message "Problem with calling stack")) | |
8c7b4ec8 | 2262 | ((> idlwave-shell-calling-stack-index nmax) |
ca660d22 | 2263 | (ding) |
8c7b4ec8 | 2264 | (setq idlwave-shell-calling-stack-index nmax |
ca660d22 CD |
2265 | message (format "%d is the highest calling stack level - can't go further up" |
2266 | (- nmax)))) | |
8c7b4ec8 | 2267 | ((< idlwave-shell-calling-stack-index nmin) |
ca660d22 | 2268 | (ding) |
8c7b4ec8 | 2269 | (setq idlwave-shell-calling-stack-index nmin |
ca660d22 CD |
2270 | message (format "%d is the current calling stack level - can't go further down" |
2271 | (- nmin))))) | |
5cba7601 | 2272 | (setq idlwave-shell-calling-stack-routine |
ca660d22 | 2273 | (nth 2 (nth idlwave-shell-calling-stack-index stack))) |
52a244eb | 2274 | |
f66f03de | 2275 | ;; force edebug for this frame if we're in that mode already |
5cba7601 | 2276 | (idlwave-shell-display-line |
52a244eb | 2277 | (nth idlwave-shell-calling-stack-index stack) nil |
f66f03de | 2278 | (if idlwave-shell-electric-debug-mode 'force)) |
5cba7601 | 2279 | (message "%s" (or message |
f66f03de S |
2280 | (format "In routine %s (stack level %d)" |
2281 | idlwave-shell-calling-stack-routine | |
2282 | (- idlwave-shell-calling-stack-index)))))) | |
8c7b4ec8 EZ |
2283 | |
2284 | (defun idlwave-shell-stack-up () | |
2285 | "Display the source code one step up the calling stack." | |
2286 | (interactive) | |
2287 | (incf idlwave-shell-calling-stack-index) | |
2288 | (idlwave-shell-display-level-in-calling-stack 'hide)) | |
2289 | (defun idlwave-shell-stack-down () | |
2290 | "Display the source code one step down the calling stack." | |
2291 | (interactive) | |
2292 | (decf idlwave-shell-calling-stack-index) | |
2293 | (idlwave-shell-display-level-in-calling-stack 'hide)) | |
2294 | ||
2295 | (defun idlwave-shell-goto-frame (&optional frame) | |
2296 | "Set buffer to FRAME with point at the frame line. | |
5a0c3f56 JB |
2297 | If the optional argument FRAME is nil then `idlwave-shell-pc-frame' |
2298 | is used. Does nothing if the resulting frame is nil." | |
8c7b4ec8 EZ |
2299 | (if frame () |
2300 | (setq frame (idlwave-shell-pc-frame))) | |
2301 | (cond | |
2302 | (frame | |
15e42531 | 2303 | (set-buffer (idlwave-find-file-noselect (car frame) 'shell)) |
8c7b4ec8 | 2304 | (widen) |
e6ce8c42 GM |
2305 | (goto-char (point-min)) |
2306 | (forward-line (1- (nth 1 frame)))))) | |
8c7b4ec8 EZ |
2307 | |
2308 | (defun idlwave-shell-pc-frame () | |
5a0c3f56 | 2309 | "Return the frame for IDL execution." |
8c7b4ec8 | 2310 | (and idlwave-shell-halt-frame |
5cba7601 | 2311 | (list (nth 0 idlwave-shell-halt-frame) |
ca660d22 CD |
2312 | (nth 1 idlwave-shell-halt-frame) |
2313 | (nth 2 idlwave-shell-halt-frame)))) | |
8c7b4ec8 EZ |
2314 | |
2315 | (defun idlwave-shell-valid-frame (frame) | |
2316 | "Check that frame is for an existing file." | |
2317 | (file-readable-p (car frame))) | |
2318 | ||
f66f03de S |
2319 | (defun idlwave-shell-stop-line-pending () |
2320 | ;; Temporarily change the color of the stop line overlay | |
2321 | (if idlwave-shell-stop-line-overlay | |
2322 | (overlay-put idlwave-shell-stop-line-overlay 'face | |
2323 | (if idlwave-shell-electric-debug-mode | |
2324 | 'idlwave-shell-pending-electric-stop | |
2325 | 'idlwave-shell-pending-stop)))) | |
8c7b4ec8 | 2326 | |
f66f03de S |
2327 | (defvar idlwave-shell-suppress-electric-debug nil) |
2328 | (defun idlwave-shell-display-line (frame &optional col debug) | |
5a0c3f56 | 2329 | "Display frame file in other window with overlay arrow. |
f66f03de | 2330 | |
5a0c3f56 JB |
2331 | FRAME is a list of file name, line number, and subroutine name. If |
2332 | FRAME is nil then remove overlay. If COL is set, move point to that | |
2333 | column in the line. If DEBUG is non-nil, enable the electric debug | |
2334 | mode. If it is 'disable, do not enable no matter what the setting of | |
2335 | `idlwave-shell-automatic-electric-debug'. If it is 'force, enable no | |
f66f03de | 2336 | matter what the settings of that variable." |
8c7b4ec8 | 2337 | (if (not frame) |
f66f03de | 2338 | ;; remove stop-line overlay from old position |
5cba7601 | 2339 | (progn |
8c7b4ec8 | 2340 | (setq overlay-arrow-string nil) |
ca660d22 | 2341 | (setq idlwave-shell-mode-line-info nil) |
15e42531 | 2342 | (setq idlwave-shell-is-stopped nil) |
8c7b4ec8 | 2343 | (if idlwave-shell-stop-line-overlay |
52a244eb | 2344 | (delete-overlay idlwave-shell-stop-line-overlay)) |
f66f03de S |
2345 | ;; turn off electric debug everywhere, if it's on |
2346 | (idlwave-shell-electric-debug-all-off)) | |
8c7b4ec8 | 2347 | (if (not (idlwave-shell-valid-frame frame)) |
f66f03de | 2348 | ;; fixme: errors are dangerous in shell filters. but i think i |
15e42531 | 2349 | ;; have never encountered this one. |
a867ead0 | 2350 | (error "invalid frame - unable to access file: %s" (car frame)) |
9a529312 SM |
2351 | ;; |
2352 | ;; buffer : the buffer to display a line in. | |
2353 | ;; select-shell: current buffer is the shell. | |
2354 | ;; | |
ca660d22 CD |
2355 | (setq idlwave-shell-mode-line-info |
2356 | (if (nth 2 frame) | |
5cba7601 | 2357 | (format "[%d:%s]" |
ca660d22 CD |
2358 | (- idlwave-shell-calling-stack-index) |
2359 | (nth 2 frame)))) | |
15e42531 | 2360 | (let* ((buffer (idlwave-find-file-noselect (car frame) 'shell)) |
8c7b4ec8 | 2361 | (select-shell (equal (buffer-name) (idlwave-shell-buffer))) |
52a244eb | 2362 | window pos electric) |
8c7b4ec8 | 2363 | |
f66f03de | 2364 | ;; first make sure the shell window is visible |
8c7b4ec8 EZ |
2365 | (idlwave-display-buffer (idlwave-shell-buffer) |
2366 | nil (idlwave-shell-shell-frame)) | |
2367 | ||
f66f03de | 2368 | ;; now display the buffer and remember which window it is. |
8c7b4ec8 EZ |
2369 | (setq window (idlwave-display-buffer buffer |
2370 | nil (idlwave-shell-source-frame))) | |
2371 | ||
f66f03de | 2372 | ;; enter the buffer and mark the line |
9a529312 | 2373 | (with-current-buffer buffer |
8c7b4ec8 EZ |
2374 | (save-restriction |
2375 | (widen) | |
e6ce8c42 GM |
2376 | (goto-char (point-min)) |
2377 | (forward-line (1- (nth 1 frame))) | |
8c7b4ec8 | 2378 | (setq pos (point)) |
15e42531 | 2379 | (setq idlwave-shell-is-stopped t) |
5cba7601 | 2380 | |
8c7b4ec8 | 2381 | (if idlwave-shell-stop-line-overlay |
f66f03de | 2382 | (progn |
5cba7601 | 2383 | ;; restore face and move overlay |
f66f03de S |
2384 | (overlay-put idlwave-shell-stop-line-overlay 'face |
2385 | (if idlwave-shell-electric-debug-mode | |
5cba7601 | 2386 | idlwave-shell-electric-stop-line-face |
f66f03de S |
2387 | idlwave-shell-stop-line-face)) |
2388 | (move-overlay idlwave-shell-stop-line-overlay | |
e180ab9f | 2389 | (point) (point-at-eol) |
f66f03de S |
2390 | (current-buffer))) |
2391 | ;; use the arrow instead, but only if marking is wanted. | |
8c7b4ec8 EZ |
2392 | (if idlwave-shell-mark-stop-line |
2393 | (setq overlay-arrow-string idlwave-shell-overlay-arrow)) | |
2394 | (or overlay-arrow-position ; create the marker if necessary | |
2395 | (setq overlay-arrow-position (make-marker))) | |
52a244eb | 2396 | (set-marker overlay-arrow-position (point) buffer))) |
13ae1076 | 2397 | |
f66f03de | 2398 | ;; if the point is outside the restriction, widen the buffer. |
8c7b4ec8 EZ |
2399 | (if (or (< pos (point-min)) (> pos (point-max))) |
2400 | (progn | |
2401 | (widen) | |
2402 | (goto-char pos))) | |
2403 | ||
f66f03de | 2404 | ;; if we have the column of the error, move the cursor there. |
8c7b4ec8 | 2405 | (if col (move-to-column col)) |
52a244eb | 2406 | (setq pos (point)) |
5cba7601 | 2407 | |
f66f03de | 2408 | ;; enter electric debug mode, if not prohibited and not in |
52a244eb | 2409 | ;; it already |
f66f03de S |
2410 | (when (and (not idlwave-shell-electric-debug-mode) |
2411 | (or (eq debug 'force) | |
5cba7601 | 2412 | (and |
f66f03de | 2413 | (not (eq debug 'disable)) ;; explicitly disabled |
5cba7601 | 2414 | (or |
f66f03de | 2415 | (eq idlwave-shell-automatic-electric-debug t) |
5cba7601 GM |
2416 | (and |
2417 | (eq idlwave-shell-automatic-electric-debug | |
f66f03de S |
2418 | 'breakpoint) |
2419 | (not (eq idlwave-shell-current-state 'error)))) | |
2420 | (not idlwave-shell-suppress-electric-debug)))) | |
2421 | (idlwave-shell-electric-debug-mode t)) | |
2422 | (setq electric idlwave-shell-electric-debug-mode)) | |
5cba7601 | 2423 | |
8c7b4ec8 | 2424 | ;; Make sure pos is really displayed in the window. |
52a244eb | 2425 | (set-window-point window pos) |
5cba7601 GM |
2426 | |
2427 | ;; If we came from the shell, go back there. Otherwise select | |
f66f03de | 2428 | ;; the window where the error/halt is displayed. |
52a244eb | 2429 | (if (or (and idlwave-shell-electric-zap-to-file electric) |
5cba7601 | 2430 | (and (equal (buffer-name) (idlwave-shell-buffer)) |
52a244eb | 2431 | (not select-shell))) |
8c7b4ec8 EZ |
2432 | (select-window window)))))) |
2433 | ||
2434 | ||
2435 | (defun idlwave-shell-step (arg) | |
5a0c3f56 JB |
2436 | "Step one source line. |
2437 | If given prefix argument ARG, step ARG source lines." | |
8c7b4ec8 EZ |
2438 | (interactive "p") |
2439 | (or (not arg) (< arg 1) | |
2440 | (setq arg 1)) | |
f66f03de | 2441 | (idlwave-shell-stop-line-pending) |
5cba7601 | 2442 | (idlwave-shell-send-command |
76959b77 | 2443 | (concat ".s " (if (integerp arg) (int-to-string arg) arg)) |
52a244eb | 2444 | nil (if (idlwave-shell-hide-p 'debug) 'mostly) nil t)) |
8c7b4ec8 EZ |
2445 | |
2446 | (defun idlwave-shell-stepover (arg) | |
2447 | "Stepover one source line. | |
5cba7601 | 2448 | If given prefix argument ARG, step ARG source lines. |
8c7b4ec8 EZ |
2449 | Uses IDL's stepover executive command which does not enter called functions." |
2450 | (interactive "p") | |
2451 | (or (not arg) (< arg 1) | |
2452 | (setq arg 1)) | |
f66f03de | 2453 | (idlwave-shell-stop-line-pending) |
5cba7601 | 2454 | (idlwave-shell-send-command |
76959b77 | 2455 | (concat ".so " (if (integerp arg) (int-to-string arg) arg)) |
52a244eb | 2456 | nil (if (idlwave-shell-hide-p 'debug) 'mostly) nil t)) |
8c7b4ec8 | 2457 | |
5cba7601 | 2458 | (defun idlwave-shell-break-here (&optional count cmd condition disabled |
3938cb82 | 2459 | no-show) |
5cba7601 | 2460 | "Set breakpoint at current line. |
8c7b4ec8 | 2461 | |
5a0c3f56 | 2462 | If COUNT is nil then an ordinary breakpoint is set. We treat a COUNT |
8c7b4ec8 EZ |
2463 | of 1 as a temporary breakpoint using the ONCE keyword. Counts greater |
2464 | than 1 use the IDL AFTER=count keyword to break only after reaching | |
5a0c3f56 | 2465 | the statement COUNT times. |
8c7b4ec8 | 2466 | |
027a4b6b | 2467 | Optional argument CMD is a list or function to evaluate upon reaching |
3938cb82 | 2468 | the breakpoint. CONDITION is a break condition, and DISABLED, if |
5a0c3f56 | 2469 | non-nil disables the breakpoint." |
8c7b4ec8 | 2470 | (interactive "P") |
76959b77 | 2471 | (when (listp count) |
5cba7601 | 2472 | (if (equal (car count) 4) |
76959b77 S |
2473 | (setq condition (read-string "Break Condition: "))) |
2474 | (setq count nil)) | |
8c7b4ec8 EZ |
2475 | (idlwave-shell-set-bp |
2476 | ;; Create breakpoint | |
2477 | (idlwave-shell-bp (idlwave-shell-current-frame) | |
3938cb82 | 2478 | (list count cmd condition disabled) |
52a244eb S |
2479 | (idlwave-shell-current-module)) |
2480 | no-show)) | |
8c7b4ec8 EZ |
2481 | |
2482 | (defun idlwave-shell-set-bp-check (bp) | |
2483 | "Check for failure to set breakpoint. | |
2484 | This is run on `idlwave-shell-post-command-hook'. | |
2485 | Offers to recompile the procedure if we failed. This usually fixes | |
2486 | the problem with not being able to set the breakpoint." | |
2487 | ;; Scan for message | |
3938cb82 S |
2488 | (if idlwave-shell-command-output |
2489 | (cond | |
2490 | ((string-match "% BREAKPOINT: *Unable to find code" | |
2491 | idlwave-shell-command-output) | |
2492 | ;; Offer to recompile | |
8c7b4ec8 EZ |
2493 | (if (progn |
2494 | (beep) | |
5cba7601 | 2495 | (y-or-n-p |
8c7b4ec8 | 2496 | (concat "Okay to recompile file " |
f66f03de | 2497 | (idlwave-shell-bp-get bp 'file) "?"))) |
8c7b4ec8 EZ |
2498 | ;; Recompile |
2499 | (progn | |
2500 | ;; Clean up before retrying | |
2501 | (idlwave-shell-command-failure) | |
2502 | (idlwave-shell-send-command | |
5cba7601 | 2503 | (concat ".run \"" (idlwave-shell-bp-get bp 'file) "\"") nil |
52a244eb | 2504 | (if (idlwave-shell-hide-p 'run) 'mostly) nil t) |
8c7b4ec8 EZ |
2505 | ;; Try setting breakpoint again |
2506 | (idlwave-shell-set-bp bp)) | |
2507 | (beep) | |
2508 | (message "Unable to set breakpoint.") | |
3938cb82 S |
2509 | (idlwave-shell-command-failure)) |
2510 | nil) | |
2511 | ||
2512 | ((string-match "% Syntax error" idlwave-shell-command-output) | |
2513 | (message "Syntax error in condition.") | |
2514 | (idlwave-shell-command-failure) | |
2515 | nil) | |
5cba7601 | 2516 | |
3938cb82 | 2517 | (t 'okay)))) |
8c7b4ec8 EZ |
2518 | |
2519 | (defun idlwave-shell-command-failure () | |
2520 | "Do any necessary clean up when an IDL command fails. | |
2521 | Call this from a function attached to `idlwave-shell-post-command-hook' | |
2522 | that detects the failure of a command. | |
2523 | For example, this is called from `idlwave-shell-set-bp-check' when a | |
2524 | breakpoint can not be set." | |
2525 | ;; Clear pending commands | |
2526 | (setq idlwave-shell-pending-commands nil)) | |
2527 | ||
52a244eb | 2528 | (defun idlwave-shell-cont (&optional no-show) |
8c7b4ec8 EZ |
2529 | "Continue executing." |
2530 | (interactive) | |
f66f03de | 2531 | (idlwave-shell-stop-line-pending) |
5cba7601 | 2532 | (idlwave-shell-send-command ".c" (unless no-show |
52a244eb | 2533 | '(idlwave-shell-redisplay 'hide)) |
5cba7601 | 2534 | (if (idlwave-shell-hide-p 'debug) 'mostly) |
52a244eb | 2535 | nil t)) |
8c7b4ec8 EZ |
2536 | |
2537 | (defun idlwave-shell-go () | |
2538 | "Run .GO. This starts the main program of the last compiled file." | |
2539 | (interactive) | |
f66f03de | 2540 | (idlwave-shell-stop-line-pending) |
76959b77 | 2541 | (idlwave-shell-send-command ".go" '(idlwave-shell-redisplay 'hide) |
52a244eb S |
2542 | (if (idlwave-shell-hide-p 'debug) 'mostly) |
2543 | nil t)) | |
8c7b4ec8 EZ |
2544 | |
2545 | (defun idlwave-shell-return () | |
2546 | "Run .RETURN (continue to next return, but stay in subprogram)." | |
2547 | (interactive) | |
f66f03de | 2548 | (idlwave-shell-stop-line-pending) |
76959b77 | 2549 | (idlwave-shell-send-command ".return" '(idlwave-shell-redisplay 'hide) |
52a244eb S |
2550 | (if (idlwave-shell-hide-p 'debug) 'mostly) |
2551 | nil t)) | |
8c7b4ec8 EZ |
2552 | |
2553 | (defun idlwave-shell-skip () | |
2554 | "Run .SKIP (skip one line, then step)." | |
2555 | (interactive) | |
5cba7601 | 2556 | (idlwave-shell-stop-line-pending) |
76959b77 | 2557 | (idlwave-shell-send-command ".skip" '(idlwave-shell-redisplay 'hide) |
52a244eb S |
2558 | (if (idlwave-shell-hide-p 'debug) 'mostly) |
2559 | nil t)) | |
8c7b4ec8 | 2560 | |
815c75b5 | 2561 | (defun idlwave-shell-clear-bp (bp &optional no-query) |
8c7b4ec8 EZ |
2562 | "Clear breakpoint BP. |
2563 | Clears in IDL and in `idlwave-shell-bp-alist'." | |
2564 | (let ((index (idlwave-shell-bp-get bp))) | |
2565 | (if index | |
2566 | (progn | |
2567 | (idlwave-shell-send-command | |
52a244eb S |
2568 | (concat "breakpoint,/clear," (int-to-string index)) |
2569 | nil (idlwave-shell-hide-p 'breakpoint) nil t) | |
815c75b5 | 2570 | (unless no-query (idlwave-shell-bp-query)))))) |
8c7b4ec8 EZ |
2571 | |
2572 | (defun idlwave-shell-current-frame () | |
2573 | "Return a list containing the current file name and line point is in. | |
2574 | If in the IDL shell buffer, returns `idlwave-shell-pc-frame'." | |
2575 | (if (eq (current-buffer) (get-buffer (idlwave-shell-buffer))) | |
2576 | ;; In IDL shell | |
2577 | (idlwave-shell-pc-frame) | |
2578 | ;; In source | |
2579 | (list (idlwave-shell-file-name (buffer-file-name)) | |
2580 | (save-restriction | |
2581 | (widen) | |
9b026d9f | 2582 | (1+ (count-lines 1 (point-at-bol))))))) |
8c7b4ec8 EZ |
2583 | |
2584 | (defun idlwave-shell-current-module () | |
2585 | "Return the name of the module for the current file. | |
2586 | Returns nil if unable to obtain a module name." | |
2587 | (if (eq (current-buffer) (get-buffer (idlwave-shell-buffer))) | |
2588 | ;; In IDL shell | |
2589 | (nth 2 idlwave-shell-halt-frame) | |
2590 | ;; In pro file | |
2591 | (save-restriction | |
2592 | (widen) | |
2593 | (save-excursion | |
2594 | (if (idlwave-prev-index-position) | |
6a8cc02d S |
2595 | (let* ((module (idlwave-what-module)) |
2596 | (name (idlwave-make-full-name (nth 2 module) (car module))) | |
2597 | (type (nth 1 module))) | |
2598 | (list (upcase name) type))))))) | |
8c7b4ec8 EZ |
2599 | |
2600 | (defun idlwave-shell-clear-current-bp () | |
2601 | "Remove breakpoint at current line. | |
5a0c3f56 JB |
2602 | This command can be called from the shell buffer if IDL is currently |
2603 | stopped at a breakpoint." | |
8c7b4ec8 | 2604 | (interactive) |
52a244eb S |
2605 | (let ((bp (idlwave-shell-find-current-bp))) |
2606 | (if bp (idlwave-shell-clear-bp bp)))) | |
8c7b4ec8 | 2607 | |
52a244eb S |
2608 | |
2609 | (defun idlwave-shell-toggle-enable-current-bp (&optional bp force | |
2610 | no-update) | |
6a8cc02d S |
2611 | "Disable or enable current breakpoint or a breakpoint passed in BP. |
2612 | If FORCE is 'disable or 'enable, for that condition instead of | |
2613 | toggling. If NO-UPDATE is non-nil, don't update the breakpoint | |
2614 | list after toggling." | |
52a244eb S |
2615 | (interactive) |
2616 | (let* ((bp (or bp (idlwave-shell-find-current-bp))) | |
2617 | (disabled (idlwave-shell-bp-get bp 'disabled))) | |
2618 | (cond ((eq force 'disable) (setq disabled nil)) | |
2619 | ((eq force 'enable) (setq disabled t))) | |
2620 | (when bp | |
2621 | (setf (nth 3 (cdr (cdr bp))) (not disabled)) | |
5cba7601 | 2622 | (idlwave-shell-send-command |
76959b77 | 2623 | (concat "breakpoint," |
52a244eb S |
2624 | (if disabled "/enable," "/disable,") |
2625 | (int-to-string (idlwave-shell-bp-get bp))) | |
2626 | nil (idlwave-shell-hide-p 'breakpoint) nil t) | |
2627 | (unless no-update (idlwave-shell-bp-query))))) | |
13ae1076 | 2628 | |
52a244eb S |
2629 | (defun idlwave-shell-enable-all-bp (&optional enable no-update bpl) |
2630 | "Disable all breakpoints we know about which need disabling. | |
2631 | If ENABLE is non-nil, enable them instead." | |
2632 | (let ((bpl (or bpl idlwave-shell-bp-alist)) disabled modified) | |
2633 | (while bpl | |
2634 | (setq disabled (idlwave-shell-bp-get (car bpl) 'disabled)) | |
2635 | (when (idlwave-xor (not disabled) (eq enable 'enable)) | |
5cba7601 | 2636 | (idlwave-shell-toggle-enable-current-bp |
52a244eb S |
2637 | (car bpl) (if (eq enable 'enable) 'enable 'disable) no-update) |
2638 | (push (car bpl) modified)) | |
2639 | (setq bpl (cdr bpl))) | |
2640 | (unless no-update (idlwave-shell-bp-query)) | |
2641 | modified)) | |
5cba7601 | 2642 | |
8c7b4ec8 EZ |
2643 | (defun idlwave-shell-to-here () |
2644 | "Set a breakpoint with count 1 then continue." | |
2645 | (interactive) | |
f66f03de | 2646 | ;; temporarily disable all other breakpoints |
52a244eb | 2647 | (let ((disabled (idlwave-shell-enable-all-bp 'disable 'no-update))) |
3938cb82 | 2648 | (idlwave-shell-break-here 1 nil nil nil 'no-show) |
52a244eb S |
2649 | (idlwave-shell-cont 'no-show) |
2650 | (idlwave-shell-enable-all-bp 'enable 'no-update disabled)) | |
2651 | (idlwave-shell-redisplay)) ; sync up everything at the end | |
2652 | ||
2653 | (defun idlwave-shell-break-this-module (&optional arg) | |
2654 | (interactive "P") | |
2655 | (save-excursion | |
2656 | (idlwave-beginning-of-subprogram) | |
2657 | (idlwave-shell-break-here arg))) | |
8c7b4ec8 | 2658 | |
52a244eb | 2659 | (defun idlwave-shell-break-in () |
8c7b4ec8 EZ |
2660 | "Look for a module name near point and set a break point for it. |
2661 | The command looks for an identifier near point and sets a breakpoint | |
52a244eb S |
2662 | for the first line of the corresponding module. If MODULE is `t', set |
2663 | in the current routine." | |
8c7b4ec8 | 2664 | (interactive) |
6a8cc02d S |
2665 | (let* ((module (idlwave-fix-module-if-obj_new (idlwave-what-module))) |
2666 | (type (nth 1 module)) | |
2667 | (name (car module)) | |
2668 | (class (nth 2 module))) | |
3938cb82 | 2669 | (if module |
5cba7601 | 2670 | (progn |
569abf86 | 2671 | (setq module (idlwave-make-full-name class name)) |
6a8cc02d S |
2672 | (idlwave-shell-module-source-query module type) |
2673 | (idlwave-shell-set-bp-in-module name type class)) | |
3938cb82 S |
2674 | (error "No identifier at point")))) |
2675 | ||
8c7b4ec8 | 2676 | |
6a8cc02d | 2677 | (defun idlwave-shell-set-bp-in-module (name type class) |
5a0c3f56 JB |
2678 | "Set breakpoint in module. |
2679 | Assumes that `idlwave-shell-sources-alist' contains an entry for that module." | |
569abf86 | 2680 | (let* ((module (idlwave-make-full-name class name)) |
5cba7601 | 2681 | (source-file |
569abf86 S |
2682 | (car-safe (cdr-safe |
2683 | (or | |
2684 | (assoc (upcase module) | |
2685 | idlwave-shell-sources-alist) | |
5cba7601 | 2686 | (nth 3 (idlwave-best-rinfo-assoc name type class |
569abf86 S |
2687 | (idlwave-routines))))))) |
2688 | buf) | |
8c7b4ec8 EZ |
2689 | (if (or (not source-file) |
2690 | (not (file-regular-p source-file)) | |
2691 | (not (setq buf | |
2692 | (or (idlwave-get-buffer-visiting source-file) | |
2693 | (find-file-noselect source-file))))) | |
2694 | (progn | |
2695 | (message "The source file for module %s is probably not compiled" | |
2696 | module) | |
2697 | (beep)) | |
9a529312 | 2698 | (with-current-buffer buf |
8c7b4ec8 EZ |
2699 | (save-excursion |
2700 | (goto-char (point-min)) | |
2701 | (let ((case-fold-search t)) | |
5cba7601 | 2702 | (if (re-search-forward |
8c7b4ec8 EZ |
2703 | (concat "^[ \t]*\\(pro\\|function\\)[ \t]+" |
2704 | (downcase module) | |
2705 | "[ \t\n,]") nil t) | |
2706 | (progn | |
2707 | (goto-char (match-beginning 1)) | |
2708 | (message "Setting breakpoint for module %s" module) | |
2709 | (idlwave-shell-break-here)) | |
2710 | (message "Cannot find module %s in file %s" module source-file) | |
2711 | (beep)))))))) | |
2712 | ||
2713 | (defun idlwave-shell-up () | |
2714 | "Run to end of current block. | |
2715 | Sets a breakpoint with count 1 at end of block, then continues." | |
2716 | (interactive) | |
2717 | (if (idlwave-shell-pc-frame) | |
2718 | (save-excursion | |
2719 | (idlwave-shell-goto-frame) | |
2720 | ;; find end of subprogram | |
2721 | (let ((eos (save-excursion | |
2722 | (idlwave-beginning-of-subprogram) | |
2723 | (idlwave-forward-block) | |
2724 | (point)))) | |
2725 | (idlwave-backward-up-block -1) | |
2726 | ;; move beyond end block line - IDL will not break there. | |
2727 | ;; That is, you can put a breakpoint there but when IDL does | |
2728 | ;; break it will report that it is at the next line. | |
2729 | (idlwave-next-statement) | |
2730 | (idlwave-end-of-statement) | |
2731 | ;; Make sure we are not beyond subprogram | |
2732 | (if (< (point) eos) | |
2733 | ;; okay | |
2734 | () | |
2735 | ;; Move back inside subprogram | |
2736 | (goto-char eos) | |
2737 | (idlwave-previous-statement)) | |
2738 | (idlwave-shell-to-here))))) | |
2739 | ||
2740 | (defun idlwave-shell-out () | |
2741 | "Attempt to run until this procedure exits. | |
2742 | Runs to the last statement and then steps 1 statement. Use the .out command." | |
2743 | (interactive) | |
5cba7601 | 2744 | (idlwave-shell-send-command ".o" nil |
52a244eb S |
2745 | (if (idlwave-shell-hide-p 'debug) 'mostly) |
2746 | nil t)) | |
2747 | ||
2748 | (defun idlwave-shell-goto-previous-bp () | |
2749 | "Move to the previous breakpoint in the buffer." | |
2750 | (interactive) | |
2751 | (idlwave-shell-move-to-bp -1)) | |
2752 | (defun idlwave-shell-goto-next-bp () | |
2753 | "Move to the next breakpoint in the buffer." | |
2754 | (interactive) | |
2755 | (idlwave-shell-move-to-bp 1)) | |
2756 | ||
2757 | (defun idlwave-shell-move-to-bp (dir) | |
2758 | "Move to the next or previous breakpoint, depending on direction DIR." | |
2759 | (let* ((frame (idlwave-shell-current-frame)) | |
2760 | (file (car frame)) | |
2761 | (orig-bp-line (nth 1 frame)) | |
2762 | (bp-alist idlwave-shell-bp-alist) | |
2763 | (orig-func (if (> dir 0) '> '<)) | |
2764 | (closer-func (if (> dir 0) '< '>)) | |
2765 | bp got-bp bp-line cur-line) | |
2766 | (while (setq bp (pop bp-alist)) | |
2767 | (when (string= file (car (car bp))) | |
2768 | (setq got-bp 1) | |
2769 | (setq cur-line (nth 1 (car bp))) | |
2770 | (if (and | |
2771 | (funcall orig-func cur-line orig-bp-line) | |
2772 | (or (not bp-line) (funcall closer-func cur-line bp-line))) | |
2773 | (setq bp-line cur-line)))) | |
75036288 | 2774 | (unless bp-line (error "No further breakpoints")) |
5f68c1b7 GM |
2775 | (goto-char (point-min)) |
2776 | (forward-line (1- bp-line)))) | |
52a244eb S |
2777 | |
2778 | ;; Examine Commands ------------------------------------------------------ | |
8c7b4ec8 | 2779 | |
15e42531 | 2780 | (defun idlwave-shell-help-expression (arg) |
8c7b4ec8 | 2781 | "Print help on current expression. See `idlwave-shell-print'." |
15e42531 CD |
2782 | (interactive "P") |
2783 | (idlwave-shell-print arg 'help)) | |
8c7b4ec8 | 2784 | |
5e72c6b2 S |
2785 | (defmacro idlwave-shell-mouse-examine (help &optional ev) |
2786 | "Create a function for generic examination of expressions." | |
2787 | `(lambda (event) | |
2788 | "Expansion function for expression examination." | |
2789 | (interactive "e") | |
f66f03de S |
2790 | (let* ((drag-track (fboundp 'mouse-drag-track)) |
2791 | (transient-mark-mode t) | |
2792 | (zmacs-regions t) | |
5cba7601 GM |
2793 | (tracker (if (featurep 'xemacs) |
2794 | (if (fboundp | |
f66f03de S |
2795 | 'default-mouse-track-event-is-with-button) |
2796 | 'idlwave-xemacs-hack-mouse-track | |
2797 | 'mouse-track) | |
2798 | ;; Emacs 22 no longer completes the drag with | |
2799 | ;; mouse-drag-region, without an additional | |
2800 | ;; event. mouse-drag-track does so. | |
2801 | (if drag-track 'mouse-drag-track 'mouse-drag-region)))) | |
5e72c6b2 | 2802 | (funcall tracker event) |
52a244eb | 2803 | (idlwave-shell-print (if (idlwave-region-active-p) '(4) nil) |
5e72c6b2 S |
2804 | ,help ,ev)))) |
2805 | ||
9a529312 SM |
2806 | ;; Begin terrible hack section -- XEmacs tests for button2 explicitly |
2807 | ;; on drag events, calling drag-n-drop code if detected. Ughhh... | |
52a244eb S |
2808 | (defun idlwave-default-mouse-track-event-is-with-button (event n) |
2809 | t) | |
2810 | ||
2811 | (defun idlwave-xemacs-hack-mouse-track (event) | |
f66f03de | 2812 | (if (featurep 'xemacs) |
5cba7601 | 2813 | (let ((oldfunc (symbol-function |
f66f03de | 2814 | 'default-mouse-track-event-is-with-button))) |
c4ae5fdd RS |
2815 | (unwind-protect |
2816 | (progn | |
5cba7601 | 2817 | (fset 'default-mouse-track-event-is-with-button |
c4ae5fdd RS |
2818 | 'idlwave-default-mouse-track-event-is-with-button) |
2819 | (mouse-track event)) | |
2820 | (fset 'default-mouse-track-event-is-with-button oldfunc))))) | |
52a244eb S |
2821 | ;;; End terrible hack section |
2822 | ||
8c7b4ec8 | 2823 | (defun idlwave-shell-mouse-print (event) |
5a0c3f56 | 2824 | "Print value of variable at the mouse position, with `print'." |
8c7b4ec8 | 2825 | (interactive "e") |
5e72c6b2 | 2826 | (funcall (idlwave-shell-mouse-examine nil) event)) |
8c7b4ec8 EZ |
2827 | |
2828 | (defun idlwave-shell-mouse-help (event) | |
5a0c3f56 | 2829 | "Print value of variable at the mouse position, with `help'." |
8c7b4ec8 | 2830 | (interactive "e") |
5e72c6b2 S |
2831 | (funcall (idlwave-shell-mouse-examine 'help) event)) |
2832 | ||
2833 | (defun idlwave-shell-examine-select (event) | |
5a0c3f56 | 2834 | "Pop-up a list to select from for examining the expression." |
5e72c6b2 S |
2835 | (interactive "e") |
2836 | (funcall (idlwave-shell-mouse-examine nil event) event)) | |
2837 | ||
2838 | (defmacro idlwave-shell-examine (help) | |
2839 | "Create a function for key-driven expression examination." | |
2840 | `(lambda () | |
2841 | (interactive) | |
2842 | (idlwave-shell-print nil ,help))) | |
2843 | ||
5e72c6b2 | 2844 | (defvar idlwave-shell-examine-label nil |
52a244eb S |
2845 | "Label to include with examine text if in a separate buffer.") |
2846 | (defvar idlwave-shell-examine-completion-list nil) | |
5e72c6b2 | 2847 | |
52a244eb | 2848 | (defun idlwave-shell-print (arg &optional help ev complete-help-type) |
5cba7601 | 2849 | "Print current expression. |
5e72c6b2 S |
2850 | |
2851 | With HELP non-nil, show help on expression. If HELP is a string, | |
2852 | the expression will be put in place of ___, e.g.: | |
2853 | ||
2854 | print,size(___,/DIMENSIONS) | |
2855 | ||
52a244eb S |
2856 | HELP can also be a cons cell ( NAME . STRING ) in which case NAME will |
2857 | be used to label the help print-out. | |
2858 | ||
5e72c6b2 | 2859 | Otherwise, print is called on the expression. |
8c7b4ec8 | 2860 | |
8c7b4ec8 | 2861 | An expression is an identifier plus 1 pair of matched parentheses |
5e72c6b2 S |
2862 | directly following the identifier - an array or function call. |
2863 | Alternatively, an expression is the contents of any matched | |
2864 | parentheses when the open parenthesis is not directly preceded by an | |
5a0c3f56 | 2865 | identifier. If point is at the beginning or within an expression |
8c7b4ec8 | 2866 | return the inner-most containing expression, otherwise, return the |
15e42531 CD |
2867 | preceding expression. |
2868 | ||
52a244eb S |
2869 | With prefix arg, or if transient mode set and the region is defined, |
2870 | use the current region as the expression. | |
5e72c6b2 | 2871 | |
52a244eb | 2872 | With double prefix arg ARG prompt for an expression. |
5e72c6b2 S |
2873 | |
2874 | If EV is a valid event passed, pop-up a list from | |
5a0c3f56 JB |
2875 | `idlwave-shell-examine-alist' from which to select the help |
2876 | command text. If instead COMPLETE-HELP-TYPE is non-nil, choose | |
2877 | from `idlwave-shell-examine-alist' via mini-buffer shortcut key." | |
15e42531 | 2878 | (interactive "P") |
f66f03de S |
2879 | |
2880 | ;; For speed: assume the helper routine hasn't been lost, e.g. with | |
2881 | ;; .FULL_RESET_SESSION. We'll recover if necessary | |
2882 | (unless idlwave-idlwave_routine_info-compiled | |
2883 | (idlwave-shell-compile-helper-routines)) | |
8c7b4ec8 | 2884 | (save-excursion |
5e72c6b2 S |
2885 | (let* ((process (get-buffer-process (current-buffer))) |
2886 | (process-mark (if process (process-mark process))) | |
5cba7601 | 2887 | (stack-label |
5e72c6b2 S |
2888 | (if (and (integerp idlwave-shell-calling-stack-index) |
2889 | (> idlwave-shell-calling-stack-index 0)) | |
5cba7601 GM |
2890 | (format " [-%d:%s]" |
2891 | idlwave-shell-calling-stack-index | |
5e72c6b2 | 2892 | idlwave-shell-calling-stack-routine))) |
f66f03de | 2893 | expr beg end cmd) |
5e72c6b2 | 2894 | (cond |
52a244eb S |
2895 | ((equal arg '(16)) |
2896 | (setq expr (read-string "Expression: "))) | |
2897 | ((and (or arg (idlwave-region-active-p)) | |
5e72c6b2 S |
2898 | (< (- (region-end) (region-beginning)) 2000)) |
2899 | (setq beg (region-beginning) | |
2900 | end (region-end))) | |
5e72c6b2 | 2901 | (t |
76959b77 | 2902 | (idlwave-with-special-syntax |
05a1abfc CD |
2903 | ;; Move to beginning of current or previous expression |
2904 | (if (looking-at "\\<\\|(") | |
2905 | ;; At beginning of expression, don't move backwards unless | |
2906 | ;; this is at the end of an indentifier. | |
2907 | (if (looking-at "\\>") | |
2908 | (backward-sexp)) | |
2909 | (backward-sexp)) | |
2910 | (if (looking-at "\\>") | |
2911 | ;; Move to beginning of identifier - must be an array or | |
2912 | ;; function expression. | |
2913 | (backward-sexp)) | |
2914 | ;; Move to end of expression | |
2915 | (setq beg (point)) | |
2916 | (forward-sexp) | |
2917 | (while (looking-at "\\>[[(]\\|\\.") | |
2918 | ;; an array | |
2919 | (forward-sexp)) | |
5e72c6b2 | 2920 | (setq end (point))))) |
5cba7601 | 2921 | |
5e72c6b2 S |
2922 | ;; Get expression, but first move the begin mark if a |
2923 | ;; process-mark is inside the region, to keep the overlay from | |
2924 | ;; wandering in the Shell. | |
2925 | (when (and beg end) | |
2926 | (if (and process-mark (> process-mark beg) (< process-mark end)) | |
2927 | (setq beg (marker-position process-mark))) | |
2928 | (setq expr (buffer-substring beg end))) | |
2929 | ||
2930 | ;; Show the overlay(s) and attach any necessary hooks and filters | |
ca660d22 | 2931 | (when (and beg end idlwave-shell-expression-overlay) |
5cba7601 | 2932 | (move-overlay idlwave-shell-expression-overlay beg end |
ca660d22 | 2933 | (current-buffer)) |
5cba7601 | 2934 | (add-hook 'pre-command-hook |
5e72c6b2 | 2935 | 'idlwave-shell-delete-expression-overlay)) |
5e72c6b2 S |
2936 | (add-hook 'pre-command-hook |
2937 | 'idlwave-shell-delete-output-overlay) | |
5cba7601 | 2938 | |
5e72c6b2 S |
2939 | ;; Remove empty or comment-only lines |
2940 | (while (string-match "\n[ \t]*\\(;.*\\)?\r*\n" expr) | |
2941 | (setq expr (replace-match "\n" t t expr))) | |
2942 | ;; Concatenate continuation lines | |
3938cb82 | 2943 | (while (string-match "[ \t]*\\$[ \t]*\\(;.*\\)?\\(\n[ \t]*\\|$\\)" expr) |
5e72c6b2 S |
2944 | (setq expr (replace-match "" t t expr))) |
2945 | ;; Remove final newline | |
2946 | (if (string-match "\n[ \t\r]*\\'" expr) | |
2947 | (setq expr (replace-match "" t t expr))) | |
5cba7601 | 2948 | |
52a244eb S |
2949 | (catch 'exit |
2950 | ;; Pop-up or complete on the examine selection list, if appropriate | |
2951 | (if (or | |
2952 | complete-help-type | |
2953 | (and ev idlwave-shell-examine-alist) | |
2954 | (consp help)) | |
5cba7601 | 2955 | (let ((help-cons |
52a244eb | 2956 | (if (consp help) help |
5cba7601 | 2957 | (assoc |
52a244eb S |
2958 | ;; A cons from either a pop-up or mini-buffer completion |
2959 | (if complete-help-type | |
2960 | (idlwave-one-key-select 'idlwave-shell-examine-alist | |
2961 | "Examine with: " 1.5) | |
2962 | ;; (idlwave-completing-read | |
5cba7601 | 2963 | ;; "Examine with: " |
52a244eb S |
2964 | ;; idlwave-shell-examine-alist nil nil nil |
2965 | ;; 'idlwave-shell-examine-completion-list | |
2966 | ;; "Print") | |
5cba7601 GM |
2967 | (idlwave-popup-select |
2968 | ev | |
2969 | (mapcar 'car idlwave-shell-examine-alist) | |
52a244eb S |
2970 | "Examine with")) |
2971 | idlwave-shell-examine-alist)))) | |
2972 | (setq help (cdr help-cons)) | |
2973 | (if (null help) (throw 'exit nil)) | |
2974 | (if idlwave-shell-separate-examine-output | |
5cba7601 GM |
2975 | (setq idlwave-shell-examine-label |
2976 | (concat | |
52a244eb S |
2977 | (format "==>%s<==\n%s:" expr (car help-cons)) |
2978 | stack-label "\n")))) | |
2979 | ;; The regular help label (no popups, cons cells, etc.) | |
2980 | (setq idlwave-shell-examine-label | |
2981 | (concat | |
5cba7601 | 2982 | (format "==>%s<==\n%s:" expr |
52a244eb S |
2983 | (cond ((null help) "print") |
2984 | ((stringp help) help) | |
2985 | (t (symbol-name help)))) | |
2986 | stack-label "\n"))) | |
2987 | ||
2988 | ;; Send the command | |
2989 | (if stack-label | |
2990 | (setq expr (idlwave-retrieve-expression-from-level | |
2991 | expr | |
2992 | idlwave-shell-calling-stack-index))) | |
2993 | (setq cmd (idlwave-shell-help-statement help expr)) | |
2994 | ;;(idlwave-shell-recenter-shell-window) | |
5cba7601 GM |
2995 | (idlwave-shell-send-command |
2996 | cmd | |
f66f03de | 2997 | 'idlwave-shell-check-compiled-and-display |
52a244eb | 2998 | (if idlwave-shell-separate-examine-output 'hide)))))) |
5e72c6b2 S |
2999 | |
3000 | (defvar idlwave-shell-examine-window-alist nil | |
3001 | "Variable to hold the win/height pairs for all *Examine* windows.") | |
3002 | ||
ddd709d1 S |
3003 | (defvar idlwave-shell-examine-map (make-sparse-keymap)) |
3004 | (define-key idlwave-shell-examine-map "q" 'idlwave-shell-examine-display-quit) | |
3005 | (define-key idlwave-shell-examine-map "c" 'idlwave-shell-examine-display-clear) | |
3006 | ||
f66f03de S |
3007 | |
3008 | (defun idlwave-shell-check-compiled-and-display () | |
3009 | "Check examine output for warning about undefined procedure/function." | |
3010 | (if (string-match "% Attempt to call undefined" idlwave-shell-command-output) | |
3011 | (idlwave-shell-compile-helper-routines)) | |
3012 | (if idlwave-shell-separate-examine-output | |
3013 | (idlwave-shell-examine-display) | |
3014 | (idlwave-shell-examine-highlight))) | |
3015 | ||
5e72c6b2 S |
3016 | (defun idlwave-shell-examine-display () |
3017 | "View the examine command output in a separate buffer." | |
3018 | (let (win cur-beg cur-end) | |
9a529312 | 3019 | (with-current-buffer (get-buffer-create "*Examine*") |
5e72c6b2 S |
3020 | (use-local-map idlwave-shell-examine-map) |
3021 | (setq buffer-read-only nil) | |
3022 | (goto-char (point-max)) | |
3023 | (save-restriction | |
3024 | (narrow-to-region (point) (point)) | |
3025 | (if (string-match "^% Syntax error." idlwave-shell-command-output) | |
3026 | (insert "% Syntax error.\n") | |
3027 | (insert idlwave-shell-command-output) | |
3028 | ;; Just take the last bit between the prompts (if more than one). | |
3029 | (let* ((end (or | |
3030 | (re-search-backward idlwave-shell-prompt-pattern nil t) | |
3031 | (point-max))) | |
5cba7601 | 3032 | (beg (progn |
5e72c6b2 | 3033 | (goto-char |
5cba7601 | 3034 | (or (progn (if (re-search-backward |
5e72c6b2 S |
3035 | idlwave-shell-prompt-pattern nil t) |
3036 | (match-end 0))) | |
3037 | (point-min))) | |
3038 | (re-search-forward "\n"))) | |
3039 | (str (buffer-substring beg end))) | |
3040 | (delete-region (point-min) (point-max)) | |
3041 | (insert str) | |
3042 | (if idlwave-shell-examine-label | |
3043 | (progn (goto-char (point-min)) | |
3044 | (insert idlwave-shell-examine-label) | |
3045 | (setq idlwave-shell-examine-label nil))))) | |
3046 | (setq cur-beg (point-min) | |
3047 | cur-end (point-max)) | |
3048 | (setq buffer-read-only t) | |
3049 | (move-overlay idlwave-shell-output-overlay cur-beg cur-end | |
3050 | (current-buffer)) | |
5cba7601 | 3051 | |
5e72c6b2 S |
3052 | ;; Look for the examine buffer in all windows. If one is |
3053 | ;; found in a frame all by itself, use that, otherwise, switch | |
3054 | ;; to or create an examine window in this frame, and resize if | |
3055 | ;; it's a newly created window | |
3056 | (let* ((winlist (get-buffer-window-list "*Examine*" nil 'visible))) | |
5cba7601 GM |
3057 | (setq win (idlwave-display-buffer |
3058 | "*Examine*" | |
5e72c6b2 S |
3059 | nil |
3060 | (let ((list winlist) thiswin) | |
3061 | (catch 'exit | |
3062 | (save-selected-window | |
3063 | (while (setq thiswin (pop list)) | |
3064 | (select-window thiswin) | |
5cba7601 | 3065 | (if (one-window-p) |
5e72c6b2 S |
3066 | (throw 'exit (window-frame thiswin))))))))) |
3067 | (set-window-start win (point-min)) ; Ensure the point is visible. | |
3068 | (save-selected-window | |
3069 | (select-window win) | |
3070 | (let ((elt (assoc win idlwave-shell-examine-window-alist))) | |
3071 | (when (and (not (one-window-p)) | |
3072 | (or (not (memq win winlist)) ;a newly created window | |
3073 | (eq (window-height) (cdr elt)))) | |
3074 | ;; Autosize it. | |
3075 | (enlarge-window (- (/ (frame-height) 2) | |
3076 | (window-height))) | |
3077 | (shrink-window-if-larger-than-buffer) | |
3078 | ;; Clean the window list of dead windows | |
3079 | (setq idlwave-shell-examine-window-alist | |
3080 | (delq nil | |
3081 | (mapcar (lambda (x) (if (window-live-p (car x)) x)) | |
3082 | idlwave-shell-examine-window-alist))) | |
3083 | ;; And add the new value. | |
3084 | (if (setq elt (assoc win idlwave-shell-examine-window-alist)) | |
3085 | (setcdr elt (window-height)) | |
5cba7601 | 3086 | (add-to-list 'idlwave-shell-examine-window-alist |
5e72c6b2 S |
3087 | (cons win (window-height))))))))) |
3088 | ;; Recenter for maximum output, after widened | |
3089 | (save-selected-window | |
3090 | (select-window win) | |
3091 | (goto-char (point-max)) | |
3092 | (skip-chars-backward "\n") | |
3093 | (recenter -1))))) | |
3094 | ||
5e72c6b2 S |
3095 | (defun idlwave-shell-examine-display-quit () |
3096 | (interactive) | |
3097 | (let ((win (selected-window))) | |
3098 | (if (one-window-p) | |
3099 | (delete-frame (window-frame win)) | |
3100 | (delete-window win)))) | |
3101 | ||
3102 | (defun idlwave-shell-examine-display-clear () | |
3103 | (interactive) | |
9a529312 SM |
3104 | (let ((buf (get-buffer "*Examine*"))) |
3105 | (when (bufferp buf) | |
3106 | (with-current-buffer buf | |
3107 | (let ((inhibit-read-only t)) | |
3108 | (erase-buffer)))))) | |
ca660d22 | 3109 | |
52a244eb | 3110 | (defun idlwave-retrieve-expression-from-level (expr level) |
ca660d22 CD |
3111 | "Return IDL command to print the expression EXPR from stack level LEVEL. |
3112 | ||
52a244eb S |
3113 | It does not seem possible to evaluate an expression on a different |
3114 | level than the current. Therefore, this function retrieves variables | |
3115 | by reference from other levels, and then includes that variable in | |
3116 | place of the chosen one. | |
3117 | ||
3118 | Since this function depends upon the undocumented IDL routine | |
3119 | routine_names, there is no guarantee that this will work with future | |
3120 | versions of IDL." | |
3121 | (let ((fetch (- 0 level)) | |
ca660d22 | 3122 | (start 0) |
3938cb82 | 3123 | var fetch-start fetch-end pre post) |
ca660d22 | 3124 | |
52a244eb | 3125 | ;; FIXME: In the following we try to find the variables in expression |
5e72c6b2 S |
3126 | ;; This is quite empirical - I don't know in what situations this will |
3127 | ;; break. We will look for identifiers and exclude cases where we | |
3128 | ;; know it is not a variable. To distinguish array references from | |
3129 | ;; function calls, we require that arrays use [] instead of () | |
5cba7601 | 3130 | |
5e72c6b2 | 3131 | (while (string-match |
52a244eb | 3132 | "\\(\\`\\|[^a-zA-Z0-9$_][ \t]*\\)\\([a-zA-Z][a-zA-Z0-9$_]*\\)\\([ \t]*[^a-zA-Z0-9$_]\\|\\'\\)" expr start) |
5e72c6b2 | 3133 | (setq var (match-string 2 expr) |
3938cb82 | 3134 | start (match-end 2) |
5e72c6b2 S |
3135 | pre (substring expr 0 (match-beginning 2)) |
3136 | post (substring expr (match-end 2))) | |
5cba7601 | 3137 | (cond |
3938cb82 S |
3138 | ((or |
3139 | ;; Exclude identifiers which are not variables | |
3140 | (string-match ",[ \t$\n]*/\\'" pre) ;; a `/' KEYWORD | |
3141 | (and (string-match "[,(][ \t\n]*\\'" pre) | |
3142 | (string-match "\\`[ \t]*=" post)) ;; a `=' KEYWORD | |
3143 | (string-match "\\`(" post) ;; a function | |
3144 | (string-match "->[ \t]*\\'" pre) ;; a method | |
3145 | (string-match "\\.\\'" pre))) ;; structure member | |
3146 | ||
3147 | ;; Skip over strings | |
52a244eb | 3148 | ((and (string-match "\\([\"\']\\)[^\1]*$" pre) |
5cba7601 | 3149 | (string-match (concat "^[^" (match-string 1 pre) "]*" |
3938cb82 S |
3150 | (match-string 1 pre)) post)) |
3151 | (setq start (+ start (match-end 0)))) | |
3152 | ||
5cba7601 | 3153 | |
3938cb82 | 3154 | ;; seems to be a variable - delimit its name |
5cba7601 | 3155 | (t |
3938cb82 S |
3156 | (put-text-property start (- start (length var)) 'fetch t expr)))) |
3157 | ||
3158 | (setq start 0) | |
3159 | (while (setq fetch-start | |
3160 | (next-single-property-change start 'fetch expr)) | |
3161 | (if (get-text-property start 'fetch expr) ; it's on in range | |
3162 | (setq fetch-end fetch-start ;it's off in range | |
3163 | fetch-start start) | |
3164 | (setq fetch-end (next-single-property-change fetch-start 'fetch expr))) | |
3165 | (unless fetch-end (setq fetch-end (length expr))) | |
3166 | (remove-text-properties fetch-start fetch-end '(fetch) expr) | |
3167 | (setq expr (concat (substring expr 0 fetch-start) | |
5cba7601 | 3168 | (format "(routine_names('%s',fetch=%d))" |
3938cb82 S |
3169 | (substring expr fetch-start fetch-end) |
3170 | fetch) | |
3171 | (substring expr fetch-end))) | |
3172 | (setq start fetch-end)) | |
3173 | (if (get-text-property 0 'fetch expr) ; Full expression, left over | |
3174 | (setq expr (format "(routine_names('%s',fetch=%d))" expr fetch))) | |
52a244eb S |
3175 | expr)) |
3176 | ||
8c7b4ec8 | 3177 | |
5e72c6b2 S |
3178 | (defun idlwave-shell-help-statement (help expr) |
3179 | "Construct a help statement for printing expression EXPR. | |
3180 | ||
3181 | HELP can be non-nil for `help,', nil for 'print,' or any string into which | |
3182 | to insert expression in place of the marker ___, e.g.: print, | |
3183 | size(___,/DIMENSIONS)" | |
3184 | (cond | |
f66f03de | 3185 | ((null help) |
5cba7601 | 3186 | (concat "idlwave_print_safe, " expr "," |
f66f03de | 3187 | (number-to-string idlwave-shell-max-print-length))) |
5cba7601 | 3188 | ((stringp help) |
5e72c6b2 S |
3189 | (if (string-match "\\(^\\|[^_]\\)\\(___\\)\\([^_]\\|$\\)" help) |
3190 | (concat (substring help 0 (match-beginning 2)) | |
3191 | expr | |
3192 | (substring help (match-end 2))))) | |
5cba7601 | 3193 | (t |
f66f03de | 3194 | (concat "help, " expr)))) |
5cba7601 | 3195 | |
5e72c6b2 S |
3196 | |
3197 | (defun idlwave-shell-examine-highlight () | |
3198 | "Highlight the most recent IDL output." | |
3199 | (let* ((buffer (get-buffer (idlwave-shell-buffer))) | |
3200 | (process (get-buffer-process buffer)) | |
3201 | (process-mark (if process (process-mark process))) | |
3202 | output-begin output-end) | |
9a529312 | 3203 | (with-current-buffer buffer |
5e72c6b2 S |
3204 | (goto-char process-mark) |
3205 | (beginning-of-line) | |
3206 | (setq output-end (point)) | |
3207 | (re-search-backward idlwave-shell-prompt-pattern nil t) | |
3208 | (beginning-of-line 2) | |
3209 | (setq output-begin (point))) | |
5cba7601 | 3210 | |
5e72c6b2 S |
3211 | ;; First make sure the shell window is visible |
3212 | (idlwave-display-buffer (idlwave-shell-buffer) | |
3213 | nil (idlwave-shell-shell-frame)) | |
3214 | (if (and idlwave-shell-output-overlay process-mark) | |
5cba7601 | 3215 | (move-overlay idlwave-shell-output-overlay |
5e72c6b2 S |
3216 | output-begin output-end buffer)))) |
3217 | ||
3218 | (defun idlwave-shell-delete-output-overlay () | |
52a244eb S |
3219 | (unless (or (eq this-command 'idlwave-shell-mouse-nop) |
3220 | (eq this-command 'handle-switch-frame)) | |
5e72c6b2 S |
3221 | (condition-case nil |
3222 | (if idlwave-shell-output-overlay | |
3223 | (delete-overlay idlwave-shell-output-overlay)) | |
3224 | (error nil)) | |
3225 | (remove-hook 'pre-command-hook 'idlwave-shell-delete-output-overlay))) | |
5cba7601 | 3226 | |
8c7b4ec8 | 3227 | (defun idlwave-shell-delete-expression-overlay () |
52a244eb S |
3228 | (unless (or (eq this-command 'idlwave-shell-mouse-nop) |
3229 | (eq this-command 'handle-switch-frame)) | |
5e72c6b2 S |
3230 | (condition-case nil |
3231 | (if idlwave-shell-expression-overlay | |
3232 | (delete-overlay idlwave-shell-expression-overlay)) | |
3233 | (error nil)) | |
3234 | (remove-hook 'pre-command-hook 'idlwave-shell-delete-expression-overlay))) | |
8c7b4ec8 EZ |
3235 | |
3236 | (defvar idlwave-shell-bp-alist nil | |
3237 | "Alist of breakpoints. | |
3238 | A breakpoint is a cons cell \(\(file line\) . \(\(index module\) data\)\) | |
3239 | ||
52a244eb | 3240 | The car is the `frame' for the breakpoint: |
8c7b4ec8 EZ |
3241 | file - full path file name. |
3242 | line - line number of breakpoint - integer. | |
3243 | ||
3244 | The first element of the cdr is a list of internal IDL data: | |
3245 | index - the index number of the breakpoint internal to IDL. | |
3246 | module - the module for breakpoint internal to IDL. | |
3247 | ||
3248 | Remaining elements of the cdr: | |
3249 | data - Data associated with the breakpoint by idlwave-shell currently | |
52a244eb | 3250 | contains four items: |
8c7b4ec8 | 3251 | |
5a0c3f56 | 3252 | count - number of times to execute breakpoint. When count reaches 0 |
52a244eb S |
3253 | the breakpoint is cleared and removed from the alist. |
3254 | ||
5cba7601 | 3255 | command - command to execute when breakpoint is reached, either a |
52a244eb S |
3256 | lisp function to be called with `funcall' with no arguments or a |
3257 | list to be evaluated with `eval'. | |
3258 | ||
3259 | condition - any condition to apply to the breakpoint. | |
3260 | ||
5a0c3f56 | 3261 | disabled - whether the bp is disabled.") |
8c7b4ec8 EZ |
3262 | |
3263 | (defun idlwave-shell-run-region (beg end &optional n) | |
3264 | "Compile and run the region using the IDL process. | |
3265 | Copies the region to a temporary file `idlwave-shell-temp-pro-file' | |
5a0c3f56 JB |
3266 | and issues the IDL .run command for the file. Because the region |
3267 | is compiled and run as a main program there is no problem with | |
3268 | begin-end blocks extending over multiple lines - which would be | |
3269 | a problem if `idlwave-shell-evaluate-region' was used. | |
3270 | An END statement is appended to the region if necessary. | |
8c7b4ec8 EZ |
3271 | |
3272 | If there is a prefix argument, display IDL process." | |
3273 | (interactive "r\nP") | |
3274 | (let ((oldbuf (current-buffer))) | |
9a529312 SM |
3275 | (with-current-buffer (idlwave-find-file-noselect |
3276 | (idlwave-shell-temp-file 'pro) 'tmp) | |
5e72c6b2 S |
3277 | (set (make-local-variable 'comment-start-skip) ";+[ \t]*") |
3278 | (set (make-local-variable 'comment-start) ";") | |
8c7b4ec8 EZ |
3279 | (erase-buffer) |
3280 | (insert-buffer-substring oldbuf beg end) | |
3281 | (if (not (save-excursion | |
3282 | (idlwave-previous-statement) | |
3283 | (idlwave-look-at "\\<end\\>"))) | |
3284 | (insert "\nend\n")) | |
3285 | (save-buffer 0))) | |
5cba7601 | 3286 | (idlwave-shell-send-command (concat ".run \"" |
f66f03de | 3287 | idlwave-shell-temp-pro-file "\"") |
5cba7601 | 3288 | nil |
52a244eb S |
3289 | (if (idlwave-shell-hide-p 'run) 'mostly) |
3290 | nil t) | |
8c7b4ec8 | 3291 | (if n |
5cba7601 | 3292 | (idlwave-display-buffer (idlwave-shell-buffer) |
8c7b4ec8 EZ |
3293 | nil (idlwave-shell-shell-frame)))) |
3294 | ||
3295 | (defun idlwave-shell-evaluate-region (beg end &optional n) | |
3296 | "Send region to the IDL process. | |
3297 | If there is a prefix argument, display IDL process. | |
3298 | Does not work for a region with multiline blocks - use | |
3299 | `idlwave-shell-run-region' for this." | |
3300 | (interactive "r\nP") | |
3301 | (idlwave-shell-send-command (buffer-substring beg end)) | |
3302 | (if n | |
5cba7601 | 3303 | (idlwave-display-buffer (idlwave-shell-buffer) |
8c7b4ec8 EZ |
3304 | nil (idlwave-shell-shell-frame)))) |
3305 | ||
15e42531 CD |
3306 | (defun idlwave-shell-delete-temp-files () |
3307 | "Delete the temporary files and kill associated buffers." | |
3308 | (if (stringp idlwave-shell-temp-pro-file) | |
3309 | (condition-case nil | |
3310 | (let ((buf (idlwave-get-buffer-visiting | |
3311 | idlwave-shell-temp-pro-file))) | |
3312 | (if (buffer-live-p buf) | |
3313 | (kill-buffer buf)) | |
3314 | (delete-file idlwave-shell-temp-pro-file)) | |
3315 | (error nil))) | |
3316 | (if (stringp idlwave-shell-temp-rinfo-save-file) | |
3317 | (condition-case nil | |
3318 | (delete-file idlwave-shell-temp-rinfo-save-file) | |
3319 | (error nil)))) | |
3320 | ||
8c7b4ec8 | 3321 | (defun idlwave-display-buffer (buf not-this-window-p &optional frame) |
76959b77 S |
3322 | (if (featurep 'xemacs) |
3323 | ;; The XEmacs version enforces the frame | |
3324 | (display-buffer buf not-this-window-p frame) | |
3325 | ;; For Emacs, we need to force the frame ourselves. | |
3326 | (let ((this-frame (selected-frame))) | |
52a244eb S |
3327 | (save-excursion ;; make sure we end up in the same buffer |
3328 | (if (frame-live-p frame) | |
3329 | (select-frame frame)) | |
3330 | (if (eq this-frame (selected-frame)) | |
3331 | ;; same frame: use display buffer, to make sure the current | |
3332 | ;; window stays. | |
3333 | (display-buffer buf) | |
3334 | ;; different frame | |
3335 | (if (one-window-p) | |
3336 | ;; only window: switch | |
3337 | (progn | |
3338 | (switch-to-buffer buf) | |
3339 | (selected-window)) ; must return the window. | |
3340 | ;; several windows - use display-buffer | |
3341 | (display-buffer buf not-this-window-p))))))) | |
76959b77 S |
3342 | ; (if (not (frame-live-p frame)) (setq frame nil)) |
3343 | ; (display-buffer buf not-this-window-p frame)) | |
8c7b4ec8 | 3344 | |
15e42531 | 3345 | (defvar idlwave-shell-bp-buffer " *idlwave-shell-bp*" |
8c7b4ec8 EZ |
3346 | "Scratch buffer for parsing IDL breakpoint lists and other stuff.") |
3347 | ||
52a244eb | 3348 | (defun idlwave-shell-bp-query (&optional no-show) |
8c7b4ec8 EZ |
3349 | "Reconcile idlwave-shell's breakpoint list with IDL's. |
3350 | Queries IDL using the string in `idlwave-shell-bp-query'." | |
3351 | (interactive) | |
3352 | (idlwave-shell-send-command idlwave-shell-bp-query | |
52a244eb S |
3353 | `(progn |
3354 | (idlwave-shell-filter-bp (quote ,no-show))) | |
8c7b4ec8 EZ |
3355 | 'hide)) |
3356 | ||
3357 | (defun idlwave-shell-bp-get (bp &optional item) | |
5a0c3f56 JB |
3358 | "Get a value for a breakpoint. |
3359 | BP has the form of elements in `idlwave-shell-bp-alist'. | |
3360 | Optional second arg ITEM is the particular value to retrieve. | |
3361 | ITEM can be 'file, 'line, 'index, 'module, 'count, 'cmd, | |
3362 | 'condition, 'disabled, 'type, or 'data. 'data returns a list | |
3363 | of 'count, 'cmd and 'condition. Defaults to 'index." | |
8c7b4ec8 EZ |
3364 | (cond |
3365 | ;; Frame | |
3366 | ((eq item 'line) (nth 1 (car bp))) | |
3367 | ((eq item 'file) (nth 0 (car bp))) | |
3368 | ;; idlwave-shell breakpoint data | |
3369 | ((eq item 'data) (cdr (cdr bp))) | |
3370 | ((eq item 'count) (nth 0 (cdr (cdr bp)))) | |
3371 | ((eq item 'cmd) (nth 1 (cdr (cdr bp)))) | |
76959b77 | 3372 | ((eq item 'condition) (nth 2 (cdr (cdr bp)))) |
52a244eb | 3373 | ((eq item 'disabled) (nth 3 (cdr (cdr bp)))) |
8c7b4ec8 | 3374 | ;; IDL breakpoint info |
5cba7601 | 3375 | ((eq item 'module) |
6a8cc02d S |
3376 | (let ((module (nth 1 (car (cdr bp))))) |
3377 | (if (listp module) (car module) module))) | |
3378 | ((eq item 'type) | |
3379 | (let ((module (nth 1 (car (cdr bp))))) | |
3380 | (if (listp module) (nth 1 module)))) | |
8c7b4ec8 EZ |
3381 | ;; index - default |
3382 | (t (nth 0 (car (cdr bp)))))) | |
3383 | ||
52a244eb | 3384 | (defun idlwave-shell-filter-bp (&optional no-show) |
5a0c3f56 JB |
3385 | "Get the breakpoints from `idlwave-shell-command-output'. |
3386 | Create `idlwave-shell-bp-alist' updating breakpoint count and command | |
3387 | data from previous breakpoint list. If NO-SHOW is set, don't update | |
3388 | the breakpoint overlays." | |
9a529312 | 3389 | (with-current-buffer (get-buffer-create idlwave-shell-bp-buffer) |
8c7b4ec8 EZ |
3390 | (erase-buffer) |
3391 | (insert idlwave-shell-command-output) | |
3392 | (goto-char (point-min)) | |
15e42531 | 3393 | (let ((old-bp-alist idlwave-shell-bp-alist) |
5e72c6b2 S |
3394 | ;; Searching the breakpoints |
3395 | ;; In IDL 5.5, the breakpoint reporting format changed. | |
3396 | (bp-re54 "^[ \t]*\\([0-9]+\\)[ \t]+\\(\\S-+\\)?[ \t]+\\([0-9]+\\)[ \t]+\\(\\S-+\\)") | |
5cba7601 GM |
3397 | (bp-re55 |
3398 | (concat | |
52a244eb S |
3399 | "^\\s-*\\([0-9]+\\)" ; 1 index |
3400 | "\\s-+\\([0-9]+\\)" ; 2 line number | |
3401 | "\\s-+\\(Uncompiled\\|" ; 3-6 either uncompiled or routine name | |
3402 | "\\(\\(Func=\\|Pro=\\)\\(\\$?[a-zA-Z][a-zA-Z0-9$_:]*\\$?\\)\\)\\)" | |
3403 | "\\(\\s-*,\\s-*After=[0-9]+/\\([0-9]+\\)?\\)?" ; 7-8 After part | |
3404 | "\\(\\s-*,\\s-*\\(BreakOnce\\)\\)?" ; 9-10 BreakOnce | |
3405 | "\\(\\s-*,\\s-*\\(Condition='\\(.*\\)'\\)\n?\\)?" ; 11-13 Condition | |
3406 | "\\(\\s-*,\\s-*\\(Disabled\\)\n?\\)?" ; 14-15 Disabled | |
3407 | "\\s-+\\(\\S-+\\)")) ; 16 File name | |
13ae1076 | 3408 | file line index module |
52a244eb | 3409 | count condition disabled |
5e72c6b2 | 3410 | bp-re indmap) |
8c7b4ec8 | 3411 | (setq idlwave-shell-bp-alist (list nil)) |
5e72c6b2 | 3412 | ;; Search for either header type, and set the correct regexp |
5cba7601 | 3413 | (when (or |
5e72c6b2 | 3414 | (if (re-search-forward "^\\s-*Index.*\n\\s-*-" nil t) |
5cba7601 | 3415 | (setq bp-re bp-re54 ; versions <= 5.4 |
52a244eb | 3416 | indmap '(1 2 3 4))) ;index module line file |
5cba7601 | 3417 | (if (re-search-forward |
5e72c6b2 S |
3418 | "^\\s-*Index\\s-*Line\\s-*Attributes\\s-*File" nil t) |
3419 | (setq bp-re bp-re55 ; versions >= 5.5 | |
52a244eb S |
3420 | indmap '(1 6 2 16)))) ; index module line file |
3421 | ;; There seems to be a breakpoint listing here, parse breakpoint lines. | |
5e72c6b2 | 3422 | (while (re-search-forward bp-re nil t) |
027a4b6b | 3423 | (setq index (string-to-number (match-string (nth 0 indmap))) |
5e72c6b2 | 3424 | module (match-string (nth 1 indmap)) |
027a4b6b | 3425 | line (string-to-number (match-string (nth 2 indmap))) |
5e72c6b2 | 3426 | file (idlwave-shell-file-name (match-string (nth 3 indmap)))) |
52a244eb | 3427 | (if (eq bp-re bp-re55) |
3d1ead4b | 3428 | (setq count (if (match-string 10) 1 |
52a244eb | 3429 | (if (match-string 8) |
027a4b6b | 3430 | (string-to-number (match-string 8)))) |
52a244eb S |
3431 | condition (match-string 13) |
3432 | disabled (not (null (match-string 15))))) | |
3d1ead4b | 3433 | |
15e42531 CD |
3434 | ;; Add the breakpoint info to the list |
3435 | (nconc idlwave-shell-bp-alist | |
3436 | (list (cons (list file line) | |
3437 | (list | |
3438 | (list index module) | |
52a244eb S |
3439 | ;; bp data: count, command, condition, disabled |
3440 | count nil condition disabled)))))) | |
8c7b4ec8 | 3441 | (setq idlwave-shell-bp-alist (cdr idlwave-shell-bp-alist)) |
52a244eb | 3442 | ;; Update breakpoint data |
3d1ead4b GM |
3443 | (if (eq bp-re bp-re54) |
3444 | (mapc 'idlwave-shell-update-bp old-bp-alist) | |
3445 | (mapc 'idlwave-shell-update-bp-command-only old-bp-alist)))) | |
8c7b4ec8 | 3446 | ;; Update the breakpoint overlays |
52a244eb | 3447 | (unless no-show (idlwave-shell-update-bp-overlays)) |
8c7b4ec8 EZ |
3448 | ;; Return the new list |
3449 | idlwave-shell-bp-alist) | |
3450 | ||
52a244eb S |
3451 | (defun idlwave-shell-update-bp-command-only (bp) |
3452 | (idlwave-shell-update-bp bp t)) | |
3453 | ||
3454 | (defun idlwave-shell-update-bp (bp &optional command-only) | |
8c7b4ec8 EZ |
3455 | "Update BP data in breakpoint list. |
3456 | If BP frame is in `idlwave-shell-bp-alist' updates the breakpoint data." | |
3457 | (let ((match (assoc (car bp) idlwave-shell-bp-alist))) | |
5cba7601 GM |
3458 | (if match |
3459 | (if command-only | |
52a244eb S |
3460 | (setf (nth 1 (cdr (cdr match))) (nth 1 (cdr (cdr match)))) |
3461 | (setcdr (cdr match) (cdr (cdr bp))))))) | |
8c7b4ec8 EZ |
3462 | |
3463 | (defun idlwave-shell-set-bp-data (bp data) | |
3464 | "Set the data of BP to DATA." | |
3465 | (setcdr (cdr bp) data)) | |
3466 | ||
3467 | (defun idlwave-shell-bp (frame &optional data module) | |
5a0c3f56 JB |
3468 | "Create a breakpoint structure containing FRAME and DATA. |
3469 | Second and third args, DATA and MODULE, are optional. Returns | |
3470 | a breakpoint of the format used in `idlwave-shell-bp-alist'. | |
3471 | Can be used in commands attempting match a breakpoint in | |
3472 | `idlwave-shell-bp-alist'." | |
6a8cc02d S |
3473 | (cons frame ;; (file line) |
3474 | (cons (list nil module) ;; (index_id (module type) | module) | |
3475 | data))) ;; (count command condition disabled) | |
8c7b4ec8 EZ |
3476 | |
3477 | (defvar idlwave-shell-old-bp nil | |
3478 | "List of breakpoints previous to setting a new breakpoint.") | |
3479 | ||
3480 | (defun idlwave-shell-sources-bp (bp) | |
3481 | "Check `idlwave-shell-sources-alist' for source of breakpoint using BP. | |
3482 | If an equivalency is found, return the IDL internal source name. | |
5a0c3f56 | 3483 | Otherwise return the filename in BP." |
8c7b4ec8 EZ |
3484 | (let* |
3485 | ((bp-file (idlwave-shell-bp-get bp 'file)) | |
3486 | (bp-module (idlwave-shell-bp-get bp 'module)) | |
5cba7601 | 3487 | (internal-file-list |
3938cb82 S |
3488 | (if bp-module |
3489 | (cdr (assoc bp-module idlwave-shell-sources-alist))))) | |
8c7b4ec8 EZ |
3490 | (if (and internal-file-list |
3491 | (equal bp-file (nth 0 internal-file-list))) | |
3492 | (nth 1 internal-file-list) | |
3493 | bp-file))) | |
3494 | ||
52a244eb | 3495 | (defun idlwave-shell-set-bp (bp &optional no-show) |
5cba7601 | 3496 | "Try to set a breakpoint BP. |
8c7b4ec8 EZ |
3497 | The breakpoint will be placed at the beginning of the statement on the |
3498 | line specified by BP or at the next IDL statement if that line is not | |
52a244eb | 3499 | a statement. Determines IDL's internal representation for the |
ddd709d1 | 3500 | breakpoint, which may have occurred at a different line than |
52a244eb | 3501 | specified. If NO-SHOW is non-nil, don't do any updating." |
8c7b4ec8 | 3502 | ;; Get and save the old breakpoints |
5cba7601 | 3503 | (idlwave-shell-send-command |
8c7b4ec8 | 3504 | idlwave-shell-bp-query |
52a244eb S |
3505 | `(progn |
3506 | (idlwave-shell-filter-bp (quote ,no-show)) | |
3507 | (setq idlwave-shell-old-bp idlwave-shell-bp-alist)) | |
8c7b4ec8 | 3508 | 'hide) |
8c7b4ec8 | 3509 | |
3938cb82 | 3510 | ;; Get sources for this routine in the sources list |
6a8cc02d S |
3511 | (idlwave-shell-module-source-query (idlwave-shell-bp-get bp 'module) |
3512 | (idlwave-shell-bp-get bp 'type)) | |
8c7b4ec8 | 3513 | (let* |
fbc232f4 | 3514 | ((count (idlwave-shell-bp-get bp 'count)) |
76959b77 | 3515 | (condition (idlwave-shell-bp-get bp 'condition)) |
3938cb82 | 3516 | (disabled (idlwave-shell-bp-get bp 'disabled)) |
fbc232f4 S |
3517 | (key (concat (if (and count (numberp count)) |
3518 | (cond | |
3519 | ((= count 1) ",/once") | |
3520 | ((> count 1) (format ",after=%d" count)))) | |
3521 | (if condition (concat ",CONDITION=\"" condition "\"")) | |
3522 | ;; IDL can't simultaneously set a condition/count | |
3523 | ;; and disable a breakpoint, but it does keep both | |
3524 | ;; of these when resetting the same BP. We assume | |
3525 | ;; DISABLE and CONDITION/COUNT are not set | |
3526 | ;; together for a newly created breakpoint. | |
3527 | (if (and disabled (not condition) (not count)) | |
3528 | ",/DISABLE"))) | |
8c7b4ec8 EZ |
3529 | (line (idlwave-shell-bp-get bp 'line))) |
3530 | (idlwave-shell-send-command | |
5cba7601 | 3531 | (concat "breakpoint,'" |
8c7b4ec8 EZ |
3532 | (idlwave-shell-sources-bp bp) "'," |
3533 | (if (integerp line) (setq line (int-to-string line))) | |
3534 | key) | |
3938cb82 | 3535 | ;; Check for failure and adjust breakpoint to match IDL's list |
8a946354 | 3536 | `(progn |
52a244eb | 3537 | (if (idlwave-shell-set-bp-check (quote ,bp)) |
3938cb82 | 3538 | (idlwave-shell-set-bp-adjust (quote ,bp) (quote ,no-show)))) |
76959b77 S |
3539 | ;; hide output? |
3540 | (idlwave-shell-hide-p 'breakpoint) | |
52a244eb | 3541 | 'preempt t))) |
8c7b4ec8 | 3542 | |
3938cb82 | 3543 | (defun idlwave-shell-set-bp-adjust (bp &optional no-show) |
8c7b4ec8 | 3544 | "Find the breakpoint in IDL's internal list of breakpoints." |
5cba7601 | 3545 | (idlwave-shell-send-command |
3938cb82 S |
3546 | idlwave-shell-bp-query |
3547 | `(progn | |
3548 | (idlwave-shell-filter-bp 'no-show) | |
3549 | (idlwave-shell-new-bp (quote ,bp)) | |
3550 | (unless (quote ,no-show) | |
3551 | (idlwave-shell-update-bp-overlays))) | |
3552 | 'hide | |
3553 | 'preempt)) | |
8c7b4ec8 EZ |
3554 | |
3555 | (defun idlwave-shell-find-bp (frame) | |
3556 | "Return breakpoint from `idlwave-shell-bp-alist' for frame. | |
3557 | Returns nil if frame not found." | |
3558 | (assoc frame idlwave-shell-bp-alist)) | |
3559 | ||
52a244eb S |
3560 | (defun idlwave-shell-find-current-bp () |
3561 | "Find breakpoint here, or at halt location." | |
3562 | (let ((bp (idlwave-shell-find-bp (idlwave-shell-current-frame)))) | |
3563 | (when (not bp) | |
3564 | ;; Try moving to beginning of halted-at statement | |
3565 | (save-excursion | |
3566 | (idlwave-shell-goto-frame) | |
3567 | (idlwave-beginning-of-statement) | |
3568 | (setq bp (idlwave-shell-find-bp (idlwave-shell-current-frame)))) | |
3569 | (unless bp | |
3570 | (beep) | |
3571 | (message "Cannot identify breakpoint for this line"))) | |
3572 | bp)) | |
3573 | ||
8c7b4ec8 EZ |
3574 | (defun idlwave-shell-new-bp (bp) |
3575 | "Find the new breakpoint in IDL's list and update with DATA. | |
3576 | The actual line number for a breakpoint in IDL may be different than | |
3577 | the line number used with the IDL breakpoint command. | |
3578 | Looks for a new breakpoint index number in the list. This is | |
3579 | considered the new breakpoint if the file name of frame matches." | |
3580 | (let ((obp-index (mapcar 'idlwave-shell-bp-get idlwave-shell-old-bp)) | |
3581 | (bpl idlwave-shell-bp-alist)) | |
3582 | (while (and (member (idlwave-shell-bp-get (car bpl)) obp-index) | |
3583 | (setq bpl (cdr bpl)))) | |
3584 | (if (and | |
3585 | (not bpl) | |
3586 | ;; No additional breakpoint. | |
3587 | ;; Need to check if we are just replacing a breakpoint. | |
3588 | (setq bpl (assoc (car bp) idlwave-shell-bp-alist))) | |
3589 | (setq bpl (list bpl))) | |
3590 | (if (and bpl | |
3591 | (equal (idlwave-shell-bp-get (setq bpl (car bpl)) 'file) | |
3592 | (idlwave-shell-bp-get bp 'file))) | |
3593 | ;; Got the breakpoint - add count, command to it. | |
3594 | ;; This updates `idlwave-shell-bp-alist' because a deep copy was | |
3595 | ;; not done for bpl. | |
3596 | (idlwave-shell-set-bp-data bpl (idlwave-shell-bp-get bp 'data)) | |
3597 | (beep) | |
3598 | (message "Failed to identify breakpoint in IDL")))) | |
3599 | ||
3600 | (defvar idlwave-shell-bp-overlays nil | |
5a0c3f56 | 3601 | "Alist of overlays marking breakpoints.") |
25d24a50 | 3602 | (defvar idlwave-shell-bp-glyph) |
8c7b4ec8 | 3603 | |
3938cb82 | 3604 | (defvar idlwave-shell-debug-line-map (make-sparse-keymap)) |
5cba7601 | 3605 | (define-key idlwave-shell-debug-line-map |
3938cb82 S |
3606 | (if (featurep 'xemacs) [button3] [mouse-3]) |
3607 | 'idlwave-shell-mouse-active-bp) | |
3608 | ||
8c7b4ec8 EZ |
3609 | (defun idlwave-shell-update-bp-overlays () |
3610 | "Update the overlays which mark breakpoints in the source code. | |
3611 | Existing overlays are recycled, in order to minimize consumption." | |
8c7b4ec8 | 3612 | (when idlwave-shell-mark-breakpoints |
52a244eb S |
3613 | (let ((ov-alist (copy-alist idlwave-shell-bp-overlays)) |
3614 | (bp-list idlwave-shell-bp-alist) | |
3615 | (use-glyph (and (memq idlwave-shell-mark-breakpoints '(t glyph)) | |
3616 | idlwave-shell-bp-glyph)) | |
3617 | ov ov-list bp buf old-buffers win) | |
3618 | ||
8c7b4ec8 | 3619 | ;; Delete the old overlays from their buffers |
5cba7601 | 3620 | (if ov-alist |
52a244eb S |
3621 | (while (setq ov-list (pop ov-alist)) |
3622 | (while (setq ov (pop (cdr ov-list))) | |
3623 | (add-to-list 'old-buffers (overlay-buffer ov)) | |
3624 | (delete-overlay ov)))) | |
5cba7601 | 3625 | |
52a244eb | 3626 | (setq ov-alist idlwave-shell-bp-overlays |
5cba7601 | 3627 | idlwave-shell-bp-overlays |
52a244eb S |
3628 | (if idlwave-shell-bp-glyph |
3629 | (mapcar 'list (mapcar 'car idlwave-shell-bp-glyph)) | |
3630 | (list (list 'bp)))) | |
8c7b4ec8 EZ |
3631 | (while (setq bp (pop bp-list)) |
3632 | (save-excursion | |
3633 | (idlwave-shell-goto-frame (car bp)) | |
9b026d9f | 3634 | (let* ((end (point-at-eol)) |
8c7b4ec8 | 3635 | (beg (progn (beginning-of-line 1) (point))) |
52a244eb S |
3636 | (condition (idlwave-shell-bp-get bp 'condition)) |
3637 | (count (idlwave-shell-bp-get bp 'count)) | |
3638 | (disabled (idlwave-shell-bp-get bp 'disabled)) | |
3639 | (type (if idlwave-shell-bp-glyph | |
3640 | (cond | |
3641 | (condition 'bp-cond ) | |
3642 | (count | |
3643 | (cond | |
3644 | ((<= count 0) 'bp) | |
3645 | ((<= count 4) | |
3646 | (intern | |
3647 | (concat "bp-" (number-to-string count)))) | |
3648 | (t 'bp-n))) | |
3649 | (t 'bp)) | |
3650 | 'bp)) | |
5cba7601 | 3651 | (help-list |
52a244eb S |
3652 | (delq nil |
3653 | (list | |
3654 | (if count | |
3938cb82 | 3655 | (concat "after:" (int-to-string count))) |
52a244eb | 3656 | (if condition |
3938cb82 | 3657 | (concat "condition:" condition)) |
52a244eb | 3658 | (if disabled "disabled")))) |
5cba7601 GM |
3659 | (help-text (concat |
3660 | "BP " | |
3938cb82 | 3661 | (int-to-string (idlwave-shell-bp-get bp)) |
5cba7601 GM |
3662 | (if help-list |
3663 | (concat | |
3664 | " - " | |
3938cb82 S |
3665 | (mapconcat 'identity help-list ", "))) |
3666 | (if (and (not count) (not condition)) | |
3667 | " (use mouse-3 for breakpoint actions)"))) | |
52a244eb S |
3668 | (full-type (if disabled |
3669 | (intern (concat (symbol-name type) | |
3670 | "-disabled")) | |
3671 | type)) | |
3672 | (ov-existing (assq full-type ov-alist)) | |
3673 | (ov (or (and (cdr ov-existing) | |
3674 | (pop (cdr ov-existing))) | |
3938cb82 | 3675 | (idlwave-shell-make-new-bp-overlay type disabled))) |
52a244eb | 3676 | match) |
3938cb82 S |
3677 | (if idlwave-shell-breakpoint-popup-menu |
3678 | (overlay-put ov 'help-echo help-text)) | |
8c7b4ec8 | 3679 | (move-overlay ov beg end) |
52a244eb S |
3680 | (if (setq match (assq full-type idlwave-shell-bp-overlays)) |
3681 | (push ov (cdr match)) | |
3682 | (nconc idlwave-shell-bp-overlays | |
3683 | (list (list full-type ov))))) | |
3684 | ;; Take care of margins if using a glyph | |
3685 | (when use-glyph | |
5cba7601 | 3686 | (if old-buffers |
52a244eb S |
3687 | (setq old-buffers (delq (current-buffer) old-buffers))) |
3688 | (if (fboundp 'set-specifier) ;; XEmacs | |
3689 | (set-specifier left-margin-width (cons (current-buffer) 2)) | |
815c75b5 S |
3690 | (if (< left-margin-width 2) |
3691 | (setq left-margin-width 2))) | |
3692 | (let ((window (get-buffer-window (current-buffer) 0))) | |
3693 | (if window | |
5cba7601 | 3694 | (set-window-margins |
815c75b5 | 3695 | window left-margin-width right-margin-width)))))) |
52a244eb S |
3696 | (if use-glyph |
3697 | (while (setq buf (pop old-buffers)) | |
3698 | (with-current-buffer buf | |
3699 | (if (fboundp 'set-specifier) ;; XEmacs | |
3700 | (set-specifier left-margin-width (cons (current-buffer) 0)) | |
3701 | (setq left-margin-width 0)) | |
815c75b5 S |
3702 | (let ((window (get-buffer-window buf 0))) |
3703 | (if window | |
5cba7601 | 3704 | (set-window-margins |
815c75b5 | 3705 | window left-margin-width right-margin-width))))))))) |
52a244eb | 3706 | |
3938cb82 | 3707 | (defun idlwave-shell-make-new-bp-overlay (&optional type disabled) |
5cba7601 | 3708 | "Make a new overlay for highlighting breakpoints. |
52a244eb S |
3709 | |
3710 | This stuff is strongly dependant upon the version of Emacs. If TYPE | |
3711 | is passed, make an overlay of that type ('bp or 'bp-cond, currently | |
3938cb82 | 3712 | only for glyphs)." |
52a244eb S |
3713 | (let ((ov (make-overlay 1 1)) |
3714 | (use-glyph (and (memq idlwave-shell-mark-breakpoints '(t glyph)) | |
3715 | idlwave-shell-bp-glyph)) | |
3716 | (type (or type 'bp)) | |
5cba7601 | 3717 | (face (if disabled |
52a244eb S |
3718 | idlwave-shell-disabled-breakpoint-face |
3719 | idlwave-shell-breakpoint-face))) | |
8c7b4ec8 EZ |
3720 | (if (featurep 'xemacs) |
3721 | ;; This is XEmacs | |
3722 | (progn | |
3938cb82 S |
3723 | (when idlwave-shell-breakpoint-popup-menu |
3724 | (set-extent-property ov 'mouse-face 'highlight) | |
3725 | (set-extent-property ov 'keymap idlwave-shell-debug-line-map)) | |
3726 | ||
5cba7601 | 3727 | (cond |
52a244eb | 3728 | ;; tty's cannot display glyphs |
8c7b4ec8 | 3729 | ((eq (console-type) 'tty) |
52a244eb | 3730 | (set-extent-property ov 'face face)) |
5cba7601 | 3731 | |
52a244eb S |
3732 | ;; use the glyph |
3733 | (use-glyph | |
3734 | (let ((glyph (cdr (assq type idlwave-shell-bp-glyph)))) | |
3735 | (if disabled (setq glyph (car glyph)) (setq glyph (nth 1 glyph))) | |
3736 | (set-extent-property ov 'begin-glyph glyph) | |
3737 | (set-extent-property ov 'begin-glyph-layout 'outside-margin))) | |
3738 | ||
3739 | ;; use the face | |
8c7b4ec8 | 3740 | (idlwave-shell-mark-breakpoints |
52a244eb S |
3741 | (set-extent-property ov 'face face)) |
3742 | ||
3743 | ;; no marking | |
3744 | (t nil)) | |
8c7b4ec8 EZ |
3745 | (set-extent-priority ov -1)) ; make stop line face prevail |
3746 | ;; This is Emacs | |
3938cb82 S |
3747 | (when idlwave-shell-breakpoint-popup-menu |
3748 | (overlay-put ov 'mouse-face 'highlight) | |
3749 | (overlay-put ov 'keymap idlwave-shell-debug-line-map)) | |
8c7b4ec8 EZ |
3750 | (cond |
3751 | (window-system | |
52a244eb S |
3752 | (if use-glyph |
3753 | (let ((image-props (cdr (assq type idlwave-shell-bp-glyph))) | |
3754 | string) | |
5cba7601 | 3755 | |
52a244eb | 3756 | (if disabled (setq image-props |
5cba7601 | 3757 | (append image-props |
52a244eb | 3758 | (list :conversion 'disabled)))) |
5cba7601 GM |
3759 | (setq string |
3760 | (propertize "@" | |
3761 | 'display | |
52a244eb | 3762 | (list (list 'margin 'left-margin) |
3938cb82 | 3763 | image-props))) |
8c7b4ec8 | 3764 | (overlay-put ov 'before-string string)) |
52a244eb S |
3765 | ;; just the face |
3766 | (overlay-put ov 'face face))) | |
3767 | ||
3768 | ;; use a face | |
8c7b4ec8 | 3769 | (idlwave-shell-mark-breakpoints |
52a244eb S |
3770 | (overlay-put ov 'face face)) |
3771 | ||
3772 | ;; No marking | |
3773 | (t nil))) | |
8c7b4ec8 EZ |
3774 | ov)) |
3775 | ||
3938cb82 S |
3776 | (defun idlwave-shell-mouse-active-bp (ev) |
3777 | "Does right-click mouse action on breakpoint lines." | |
3778 | (interactive "e") | |
3779 | (if ev (mouse-set-point ev)) | |
3780 | (let ((bp (idlwave-shell-find-bp (idlwave-shell-current-frame))) | |
3781 | index condition count select cmd disabled) | |
3782 | (unless bp | |
3783 | (error "Breakpoint not found")) | |
3784 | (setq index (int-to-string (idlwave-shell-bp-get bp)) | |
3785 | condition (idlwave-shell-bp-get bp 'condition) | |
3786 | cmd (idlwave-shell-bp-get bp 'cmd) | |
3787 | count (idlwave-shell-bp-get bp 'count) | |
3788 | disabled (idlwave-shell-bp-get bp 'disabled)) | |
5cba7601 GM |
3789 | (setq select (idlwave-popup-select |
3790 | ev | |
3791 | (delq nil | |
3938cb82 S |
3792 | (list (if disabled "Enable" "Disable") |
3793 | "Clear" | |
3794 | "Clear All" | |
3795 | (if condition "Remove Condition" "Add Condition") | |
3796 | (if condition "Change Condition") | |
5cba7601 | 3797 | (if count "Remove Repeat Count" |
3938cb82 S |
3798 | "Add Repeat Count") |
3799 | (if count "Change Repeat Count"))) | |
3800 | (concat "BreakPoint " index))) | |
5cba7601 GM |
3801 | (if select |
3802 | (cond | |
3938cb82 S |
3803 | ((string-equal select "Clear All") |
3804 | (idlwave-shell-clear-all-bp)) | |
3805 | ((string-equal select "Clear") | |
3806 | (idlwave-shell-clear-current-bp)) | |
3807 | ((string-match "Condition" select) | |
5cba7601 | 3808 | (idlwave-shell-break-here count cmd |
3938cb82 S |
3809 | (if (or (not condition) |
3810 | (string-match "Change" select)) | |
3811 | (read-string "Break Condition: ")) | |
3812 | disabled)) | |
3813 | ((string-match "Count" select) | |
3814 | (idlwave-shell-break-here (if (or (not count) | |
3815 | (string-match "Change" select)) | |
3816 | (string-to-number | |
3817 | (read-string "Break After Count: "))) | |
3818 | cmd condition disabled)) | |
3819 | ((string-match "able$" select) | |
3820 | (idlwave-shell-toggle-enable-current-bp)) | |
5cba7601 | 3821 | (t |
3938cb82 | 3822 | (message "Unimplemented: %s" select)))))) |
5cba7601 | 3823 | |
8c7b4ec8 EZ |
3824 | (defun idlwave-shell-edit-default-command-line (arg) |
3825 | "Edit the current execute command." | |
3826 | (interactive "P") | |
3827 | (setq idlwave-shell-command-line-to-execute | |
3828 | (read-string "IDL> " idlwave-shell-command-line-to-execute))) | |
3829 | ||
3830 | (defun idlwave-shell-execute-default-command-line (arg) | |
3831 | "Execute a command line. On first use, ask for the command. | |
52a244eb | 3832 | Also with prefix arg, ask for the command. You can also use the command |
8c7b4ec8 EZ |
3833 | `idlwave-shell-edit-default-command-line' to edit the line." |
3834 | (interactive "P") | |
5cba7601 | 3835 | (cond |
52a244eb S |
3836 | ((equal arg '(16)) |
3837 | (setq idlwave-shell-command-line-to-execute nil)) | |
3838 | ((equal arg '(4)) | |
5cba7601 | 3839 | (setq idlwave-shell-command-line-to-execute |
52a244eb | 3840 | (read-string "IDL> " idlwave-shell-command-line-to-execute)))) |
ca660d22 | 3841 | (idlwave-shell-reset 'hidden) |
5cba7601 | 3842 | (idlwave-shell-send-command |
52a244eb S |
3843 | (or idlwave-shell-command-line-to-execute |
3844 | (with-current-buffer (idlwave-shell-buffer) | |
3845 | (ring-ref comint-input-ring 0))) | |
3846 | '(idlwave-shell-redisplay 'hide))) | |
8c7b4ec8 EZ |
3847 | |
3848 | (defun idlwave-shell-save-and-run () | |
3849 | "Save file and run it in IDL. | |
3850 | Runs `save-buffer' and sends a '.RUN' command for the associated file to IDL. | |
3851 | When called from the shell buffer, re-run the file which was last handled by | |
5cba7601 | 3852 | one of the save-and-.. commands." |
8c7b4ec8 EZ |
3853 | (interactive) |
3854 | (idlwave-shell-save-and-action 'run)) | |
3855 | ||
3856 | (defun idlwave-shell-save-and-compile () | |
3857 | "Save file and run it in IDL. | |
3858 | Runs `save-buffer' and sends '.COMPILE' command for the associated file to IDL. | |
3859 | When called from the shell buffer, re-compile the file which was last handled by | |
3860 | one of the save-and-.. commands." | |
3861 | (interactive) | |
3862 | (idlwave-shell-save-and-action 'compile)) | |
3863 | ||
3864 | (defun idlwave-shell-save-and-batch () | |
3865 | "Save file and batch it in IDL. | |
3866 | Runs `save-buffer' and sends a '@file' command for the associated file to IDL. | |
3867 | When called from the shell buffer, re-batch the file which was last handled by | |
5cba7601 | 3868 | one of the save-and-.. commands." |
8c7b4ec8 EZ |
3869 | (interactive) |
3870 | (idlwave-shell-save-and-action 'batch)) | |
3871 | ||
3872 | (defun idlwave-shell-save-and-action (action) | |
3873 | "Save file and compile it in IDL. | |
3874 | Runs `save-buffer' and sends a '.RUN' command for the associated file to IDL. | |
3875 | When called from the shell buffer, re-compile the file which was last | |
3876 | handled by this command." | |
3877 | ;; Remove the stop overlay. | |
3878 | (if idlwave-shell-stop-line-overlay | |
3879 | (delete-overlay idlwave-shell-stop-line-overlay)) | |
52a244eb S |
3880 | (if idlwave-shell-is-stopped |
3881 | (idlwave-shell-electric-debug-all-off)) | |
15e42531 | 3882 | (setq idlwave-shell-is-stopped nil) |
8c7b4ec8 EZ |
3883 | (setq overlay-arrow-string nil) |
3884 | (let (buf) | |
3885 | (cond | |
175069ef | 3886 | ((derived-mode-p 'idlwave-mode) |
8c7b4ec8 EZ |
3887 | (save-buffer) |
3888 | (setq idlwave-shell-last-save-and-action-file (buffer-file-name))) | |
3889 | (idlwave-shell-last-save-and-action-file | |
3890 | (if (setq buf (idlwave-get-buffer-visiting | |
3891 | idlwave-shell-last-save-and-action-file)) | |
9a529312 | 3892 | (with-current-buffer buf |
8c7b4ec8 EZ |
3893 | (save-buffer)))) |
3894 | (t (setq idlwave-shell-last-save-and-action-file | |
3895 | (read-file-name "File: "))))) | |
3896 | (if (file-regular-p idlwave-shell-last-save-and-action-file) | |
3897 | (progn | |
3898 | (idlwave-shell-send-command | |
3899 | (concat (cond ((eq action 'run) ".run ") | |
3900 | ((eq action 'compile) ".compile ") | |
3901 | ((eq action 'batch) "@") | |
3902 | (t (error "Unknown action %s" action))) | |
f66f03de S |
3903 | "\"" |
3904 | idlwave-shell-last-save-and-action-file | |
3905 | "\"") | |
3906 | `(idlwave-shell-maybe-update-routine-info nil | |
3907 | ,idlwave-shell-last-save-and-action-file) | |
52a244eb | 3908 | (if (idlwave-shell-hide-p 'run) 'mostly) nil t) |
8c7b4ec8 | 3909 | (idlwave-shell-bp-query)) |
5cba7601 | 3910 | (let ((msg (format "No such file %s" |
8c7b4ec8 EZ |
3911 | idlwave-shell-last-save-and-action-file))) |
3912 | (setq idlwave-shell-last-save-and-action-file nil) | |
3913 | (error msg)))) | |
3914 | ||
f66f03de | 3915 | (defun idlwave-shell-maybe-update-routine-info (&optional wait file) |
15e42531 CD |
3916 | "Update the routine info if the shell is not stopped at an error." |
3917 | (if (and (not idlwave-shell-is-stopped) | |
3918 | (or (eq t idlwave-auto-routine-info-updates) | |
3919 | (memq 'compile-buffer idlwave-auto-routine-info-updates)) | |
3920 | idlwave-query-shell-for-routine-info | |
3921 | idlwave-routines) | |
f66f03de | 3922 | (idlwave-shell-update-routine-info t nil wait file))) |
15e42531 | 3923 | |
5e72c6b2 | 3924 | (defvar idlwave-shell-sources-query "help,/source,/full" |
8c7b4ec8 EZ |
3925 | "IDL command to obtain source files for compiled procedures.") |
3926 | ||
3927 | (defvar idlwave-shell-sources-alist nil | |
3928 | "Alist of IDL procedure names and compiled source files. | |
3929 | Elements of the alist have the form: | |
3930 | ||
5a0c3f56 | 3931 | (module name . (source-file-truename idlwave-internal-filename))") |
8c7b4ec8 | 3932 | |
6a8cc02d S |
3933 | (defun idlwave-shell-module-source-query (module &optional type) |
3934 | "Determine the source file for a given module. | |
3935 | Query as a function if TYPE set to something beside 'pro." | |
3938cb82 | 3936 | (if module |
5cba7601 | 3937 | (idlwave-shell-send-command |
6a8cc02d S |
3938 | (format "print,(routine_info('%s',/SOURCE%s)).PATH" module |
3939 | (if (eq type 'pro) "" ",/FUNCTIONS")) | |
3938cb82 | 3940 | `(idlwave-shell-module-source-filter ,module) |
6a8cc02d | 3941 | 'hide 'wait))) |
3938cb82 S |
3942 | |
3943 | (defun idlwave-shell-module-source-filter (module) | |
5a0c3f56 | 3944 | "Get module source, and update `idlwave-shell-sources-alist'." |
3938cb82 S |
3945 | (let ((old (assoc (upcase module) idlwave-shell-sources-alist)) |
3946 | filename) | |
6a8cc02d S |
3947 | (when (string-match "\.PATH *[\n\r]\\([^%][^\r\n]+\\)[\n\r]" |
3948 | idlwave-shell-command-output) | |
5cba7601 | 3949 | (setq filename (substring idlwave-shell-command-output |
6a8cc02d S |
3950 | (match-beginning 1) (match-end 1))) |
3951 | (if old | |
3952 | (setcdr old (list (idlwave-shell-file-name filename) filename)) | |
3953 | (setq idlwave-shell-sources-alist | |
5cba7601 | 3954 | (append idlwave-shell-sources-alist |
6a8cc02d | 3955 | (list (cons (upcase module) |
5cba7601 | 3956 | (list (idlwave-shell-file-name filename) |
6a8cc02d | 3957 | filename))))))))) |
5cba7601 | 3958 | |
8c7b4ec8 | 3959 | (defun idlwave-shell-sources-query () |
3938cb82 | 3960 | "Determine source files for all IDL compiled procedures. |
8c7b4ec8 | 3961 | Queries IDL using the string in `idlwave-shell-sources-query'." |
3938cb82 | 3962 | (interactive) |
8c7b4ec8 EZ |
3963 | (idlwave-shell-send-command idlwave-shell-sources-query |
3964 | 'idlwave-shell-sources-filter | |
3965 | 'hide)) | |
3966 | ||
3967 | (defun idlwave-shell-sources-filter () | |
3968 | "Get source files from `idlwave-shell-sources-query' output. | |
5a0c3f56 JB |
3969 | Create `idlwave-shell-sources-alist' consisting of list elements |
3970 | of the form: | |
3971 | (module name . (source-file-truename idlwave-internal-filename))" | |
9a529312 | 3972 | (with-current-buffer (get-buffer-create idlwave-shell-bp-buffer) |
8c7b4ec8 EZ |
3973 | (erase-buffer) |
3974 | (insert idlwave-shell-command-output) | |
3975 | (goto-char (point-min)) | |
3976 | (let (cpro cfun) | |
3977 | (if (re-search-forward "Compiled Procedures:" nil t) | |
3978 | (progn | |
3979 | (forward-line) ; Skip $MAIN$ | |
3980 | (setq cpro (point)))) | |
3981 | (if (re-search-forward "Compiled Functions:" nil t) | |
3982 | (progn | |
3983 | (setq cfun (point)) | |
3984 | (setq idlwave-shell-sources-alist | |
3985 | (append | |
3986 | ;; compiled procedures | |
3987 | (progn | |
9b026d9f | 3988 | (narrow-to-region cpro (point-at-bol)) |
8c7b4ec8 EZ |
3989 | (goto-char (point-min)) |
3990 | (idlwave-shell-sources-grep)) | |
3991 | ;; compiled functions | |
3992 | (progn | |
3993 | (widen) | |
3994 | (goto-char cfun) | |
3995 | (idlwave-shell-sources-grep))))))))) | |
3996 | ||
3997 | (defun idlwave-shell-sources-grep () | |
3998 | (save-excursion | |
3999 | (let ((al (list nil))) | |
4000 | (while (and | |
4001 | (not (progn (forward-line) (eobp))) | |
4002 | (re-search-forward | |
4003 | "\\s-*\\(\\S-+\\)\\s-+\\(\\S-+\\)" nil t)) | |
4004 | (nconc al | |
4005 | (list | |
4006 | (cons | |
4007 | (buffer-substring ; name | |
4008 | (match-beginning 1) (match-end 1)) | |
4009 | (let ((internal-filename | |
4010 | (buffer-substring ; source | |
4011 | (match-beginning 2) (match-end 2)))) | |
4012 | (list | |
4013 | (idlwave-shell-file-name internal-filename) | |
4014 | internal-filename)) | |
4015 | )))) | |
4016 | (cdr al)))) | |
4017 | ||
8c7b4ec8 EZ |
4018 | (defun idlwave-shell-clear-all-bp () |
4019 | "Remove all breakpoints in IDL." | |
4020 | (interactive) | |
4021 | (idlwave-shell-send-command | |
4022 | idlwave-shell-bp-query | |
4023 | '(progn | |
4024 | (idlwave-shell-filter-bp) | |
815c75b5 S |
4025 | (mapcar (lambda (x) (idlwave-shell-clear-bp x 'no-query)) |
4026 | idlwave-shell-bp-alist) | |
4027 | (idlwave-shell-bp-query)) | |
8c7b4ec8 EZ |
4028 | 'hide)) |
4029 | ||
4030 | (defun idlwave-shell-list-all-bp () | |
4031 | "List all breakpoints in IDL." | |
4032 | (interactive) | |
4033 | (idlwave-shell-send-command | |
4034 | idlwave-shell-bp-query)) | |
4035 | ||
4036 | (defvar idlwave-shell-error-last 0 | |
4037 | "Position of last syntax error in `idlwave-shell-error-buffer'.") | |
4038 | ||
4039 | (defun idlwave-shell-goto-next-error () | |
4040 | "Move point to next IDL syntax error." | |
4041 | (interactive) | |
4042 | (let (frame col) | |
9a529312 | 4043 | (with-current-buffer idlwave-shell-error-buffer |
8c7b4ec8 | 4044 | (goto-char idlwave-shell-error-last) |
52a244eb S |
4045 | (if (or |
4046 | (re-search-forward idlwave-shell-syntax-error nil t) | |
4047 | (re-search-forward idlwave-shell-other-error nil t)) | |
8c7b4ec8 EZ |
4048 | (progn |
4049 | (setq frame | |
4050 | (list | |
4051 | (save-match-data | |
4052 | (idlwave-shell-file-name | |
5cba7601 | 4053 | (buffer-substring (match-beginning 1 ) |
52a244eb | 4054 | (match-end 1)))) |
027a4b6b | 4055 | (string-to-number |
8c7b4ec8 EZ |
4056 | (buffer-substring (match-beginning 2) |
4057 | (match-end 2))))) | |
4058 | ;; Try to find the column of the error | |
4059 | (save-excursion | |
4060 | (setq col | |
4061 | (if (re-search-backward "\\^" nil t) | |
4062 | (current-column) | |
4063 | 0))))) | |
4064 | (setq idlwave-shell-error-last (point))) | |
4065 | (if frame | |
4066 | (progn | |
f66f03de | 4067 | (idlwave-shell-display-line frame col 'disable)) |
8c7b4ec8 EZ |
4068 | (beep) |
4069 | (message "No more errors.")))) | |
4070 | ||
4071 | (defun idlwave-shell-file-name (name) | |
15e42531 | 4072 | "If `idlwave-shell-use-truename' is non-nil, convert file name to true name. |
8c7b4ec8 | 4073 | Otherwise, just expand the file name." |
175069ef | 4074 | (let ((def-dir (if (derived-mode-p 'idlwave-shell-mode) |
8c7b4ec8 EZ |
4075 | default-directory |
4076 | idlwave-shell-default-directory))) | |
5e72c6b2 S |
4077 | (if idlwave-shell-use-truename |
4078 | (file-truename name def-dir) | |
8c7b4ec8 EZ |
4079 | (expand-file-name name def-dir)))) |
4080 | ||
52a244eb | 4081 | ;; Keybindings ------------------------------------------------------------ |
8c7b4ec8 EZ |
4082 | |
4083 | (defvar idlwave-shell-mode-map (copy-keymap comint-mode-map) | |
5a0c3f56 | 4084 | "Keymap for `idlwave-mode'.") |
52a244eb | 4085 | (defvar idlwave-shell-electric-debug-mode-map (make-sparse-keymap)) |
8c7b4ec8 EZ |
4086 | (defvar idlwave-shell-mode-prefix-map (make-sparse-keymap)) |
4087 | (fset 'idlwave-shell-mode-prefix-map idlwave-shell-mode-prefix-map) | |
52a244eb S |
4088 | (defvar idlwave-mode-prefix-map (make-sparse-keymap)) |
4089 | (fset 'idlwave-mode-prefix-map idlwave-mode-prefix-map) | |
4090 | ||
4091 | (defun idlwave-shell-define-key-both (key hook) | |
4092 | "Define a key in both the shell and buffer mode maps." | |
4093 | (define-key idlwave-mode-map key hook) | |
4094 | (define-key idlwave-shell-mode-map key hook)) | |
8c7b4ec8 EZ |
4095 | |
4096 | ;(define-key idlwave-shell-mode-map "\M-?" 'comint-dynamic-list-completions) | |
4097 | ;(define-key idlwave-shell-mode-map "\t" 'comint-dynamic-complete) | |
6a8cc02d | 4098 | |
dd5baa1a | 4099 | (define-key idlwave-shell-mode-map "\C-w" 'comint-kill-region) |
8c7b4ec8 EZ |
4100 | (define-key idlwave-shell-mode-map "\t" 'idlwave-shell-complete) |
4101 | (define-key idlwave-shell-mode-map "\M-\t" 'idlwave-shell-complete) | |
4102 | (define-key idlwave-shell-mode-map "\C-c\C-s" 'idlwave-shell) | |
4103 | (define-key idlwave-shell-mode-map "\C-c?" 'idlwave-routine-info) | |
76959b77 | 4104 | (define-key idlwave-shell-mode-map "\C-g" 'idlwave-keyboard-quit) |
15e42531 | 4105 | (define-key idlwave-shell-mode-map "\M-?" 'idlwave-context-help) |
5cba7601 | 4106 | (define-key idlwave-shell-mode-map [(control meta ?\?)] |
dd5baa1a | 4107 | 'idlwave-help-assistant-help-with-topic) |
8c7b4ec8 | 4108 | (define-key idlwave-shell-mode-map "\C-c\C-i" 'idlwave-update-routine-info) |
15e42531 CD |
4109 | (define-key idlwave-shell-mode-map "\C-c\C-y" 'idlwave-shell-char-mode-loop) |
4110 | (define-key idlwave-shell-mode-map "\C-c\C-x" 'idlwave-shell-send-char) | |
8c7b4ec8 EZ |
4111 | (define-key idlwave-shell-mode-map "\C-c=" 'idlwave-resolve) |
4112 | (define-key idlwave-shell-mode-map "\C-c\C-v" 'idlwave-find-module) | |
15e42531 | 4113 | (define-key idlwave-shell-mode-map "\C-c\C-k" 'idlwave-kill-autoloaded-buffers) |
8c7b4ec8 EZ |
4114 | (define-key idlwave-shell-mode-map idlwave-shell-prefix-key |
4115 | 'idlwave-shell-debug-map) | |
05a1abfc CD |
4116 | (define-key idlwave-shell-mode-map [(up)] 'idlwave-shell-up-or-history) |
4117 | (define-key idlwave-shell-mode-map [(down)] 'idlwave-shell-down-or-history) | |
15e42531 CD |
4118 | (define-key idlwave-mode-map "\C-c\C-y" 'idlwave-shell-char-mode-loop) |
4119 | (define-key idlwave-mode-map "\C-c\C-x" 'idlwave-shell-send-char) | |
5e72c6b2 S |
4120 | |
4121 | ;; The mouse bindings for PRINT and HELP | |
4122 | (idlwave-shell-define-key-both | |
5cba7601 GM |
4123 | (if (featurep 'xemacs) |
4124 | [(shift button2)] | |
5e72c6b2 S |
4125 | [(shift down-mouse-2)]) |
4126 | 'idlwave-shell-mouse-print) | |
4127 | (idlwave-shell-define-key-both | |
5cba7601 GM |
4128 | (if (featurep 'xemacs) |
4129 | [(control meta button2)] | |
5e72c6b2 | 4130 | [(control meta down-mouse-2)]) |
15e42531 | 4131 | 'idlwave-shell-mouse-help) |
5e72c6b2 S |
4132 | (idlwave-shell-define-key-both |
4133 | (if (featurep 'xemacs) | |
4134 | [(control shift button2)] | |
4135 | [(control shift down-mouse-2)]) | |
4136 | 'idlwave-shell-examine-select) | |
4137 | ;; Add this one from the idlwave-mode-map | |
5cba7601 | 4138 | (define-key idlwave-shell-mode-map |
5e72c6b2 S |
4139 | (if (featurep 'xemacs) |
4140 | [(shift button3)] | |
4141 | [(shift mouse-3)]) | |
15e42531 CD |
4142 | 'idlwave-mouse-context-help) |
4143 | ||
5e72c6b2 | 4144 | ;; For Emacs, we need to turn off the button release events. |
5cba7601 | 4145 | (defun idlwave-shell-mouse-nop (event) |
5e72c6b2 S |
4146 | (interactive "e")) |
4147 | (unless (featurep 'xemacs) | |
4148 | (idlwave-shell-define-key-both | |
4149 | [(shift mouse-2)] 'idlwave-shell-mouse-nop) | |
4150 | (idlwave-shell-define-key-both | |
4151 | [(shift control mouse-2)] 'idlwave-shell-mouse-nop) | |
4152 | (idlwave-shell-define-key-both | |
4153 | [(control meta mouse-2)] 'idlwave-shell-mouse-nop)) | |
8c7b4ec8 | 4154 | |
5cba7601 | 4155 | |
8c7b4ec8 | 4156 | ;; The following set of bindings is used to bind the debugging keys. |
52a244eb S |
4157 | ;; If `idlwave-shell-activate-prefix-keybindings' is non-nil, the |
4158 | ;; first key in the list gets bound the C-c C-d prefix map. If | |
4159 | ;; `idlwave-shell-debug-modifiers' is non-nil, the second key in the | |
4160 | ;; list gets bound with the specified modifiers in both | |
4161 | ;; `idlwave-mode-map' and `idlwave-shell-mode-map'. The next list | |
4162 | ;; item, if non-nil, means to bind this as a single key in the | |
4163 | ;; electric-debug-mode-map. | |
5cba7601 | 4164 | ;; |
52a244eb | 4165 | ;; [C-c C-d]-binding debug-modifier-key command bind-electric-debug buf-only |
5cba7601 GM |
4166 | ;; Used keys: abcdef hijklmnopqrstuvwxyz |
4167 | ;; Unused keys: g | |
05a1abfc | 4168 | (let* ((specs |
52a244eb S |
4169 | '(([(control ?b)] ?b idlwave-shell-break-here t t) |
4170 | ([(control ?i)] ?i idlwave-shell-break-in t t) | |
4171 | ([(control ?j)] ?j idlwave-shell-break-this-module t t) | |
4172 | ([(control ?d)] ?d idlwave-shell-clear-current-bp t) | |
4173 | ([(control ?a)] ?a idlwave-shell-clear-all-bp t) | |
4174 | ([(control ?\\)] ?\\ idlwave-shell-toggle-enable-current-bp t) | |
4175 | ([(control ?s)] ?s idlwave-shell-step t) | |
4176 | ([(control ?n)] ?n idlwave-shell-stepover t) | |
4177 | ([(control ?k)] ?k idlwave-shell-skip t) | |
4178 | ([(control ?u)] ?u idlwave-shell-up t) | |
4179 | ([(control ?o)] ?o idlwave-shell-out t) | |
4180 | ([(control ?m)] ?m idlwave-shell-return t) | |
4181 | ([(control ?h)] ?h idlwave-shell-to-here t t) | |
4182 | ([(control ?r)] ?r idlwave-shell-cont t) | |
05a1abfc | 4183 | ([(control ?y)] ?y idlwave-shell-execute-default-command-line) |
52a244eb | 4184 | ([(control ?z)] ?z idlwave-shell-reset t) |
05a1abfc | 4185 | ([(control ?q)] ?q idlwave-shell-quit) |
52a244eb S |
4186 | ([(control ?p)] ?p idlwave-shell-print t) |
4187 | ([( ??)] ?? idlwave-shell-help-expression t) | |
4188 | ([(control ?v)] ?v idlwave-shell-toggle-electric-debug-mode t t) | |
05a1abfc | 4189 | ([(control ?x)] ?x idlwave-shell-goto-next-error) |
52a244eb S |
4190 | ([(control ?c)] ?c idlwave-shell-save-and-run t) |
4191 | ([( ?@)] ?@ idlwave-shell-save-and-batch) | |
05a1abfc CD |
4192 | ([(control ?e)] ?e idlwave-shell-run-region) |
4193 | ([(control ?w)] ?w idlwave-shell-resync-dirs) | |
52a244eb | 4194 | ([(control ?l)] ?l idlwave-shell-redisplay t) |
05a1abfc CD |
4195 | ([(control ?t)] ?t idlwave-shell-toggle-toolbar) |
4196 | ([(control up)] up idlwave-shell-stack-up) | |
4197 | ([(control down)] down idlwave-shell-stack-down) | |
52a244eb S |
4198 | ([( ?[)] ?[ idlwave-shell-goto-previous-bp t t) |
4199 | ([( ?])] ?] idlwave-shell-goto-next-bp t t) | |
05a1abfc CD |
4200 | ([(control ?f)] ?f idlwave-shell-window))) |
4201 | (mod (cond ((and idlwave-shell-debug-modifiers | |
4202 | (listp idlwave-shell-debug-modifiers) | |
4203 | (not (equal '() idlwave-shell-debug-modifiers))) | |
4204 | idlwave-shell-debug-modifiers) | |
4205 | (idlwave-shell-activate-alt-keybindings | |
4206 | '(alt)))) | |
4207 | (shift (memq 'shift mod)) | |
4208 | (mod-noshift (delete 'shift (copy-sequence mod))) | |
25d24a50 | 4209 | s k1 c2 k2 cmd electric only-buffer cannotshift) |
8c7b4ec8 EZ |
4210 | (while (setq s (pop specs)) |
4211 | (setq k1 (nth 0 s) | |
05a1abfc | 4212 | c2 (nth 1 s) |
52a244eb S |
4213 | cmd (nth 2 s) |
4214 | electric (nth 3 s) | |
4215 | only-buffer (nth 4 s) | |
5cba7601 GM |
4216 | cannotshift (and shift (characterp c2) (eq c2 (upcase c2)))) |
4217 | ||
52a244eb S |
4218 | ;; The regular prefix keymap. |
4219 | (when (and idlwave-shell-activate-prefix-keybindings k1) | |
5cba7601 | 4220 | (unless only-buffer |
52a244eb S |
4221 | (define-key idlwave-shell-mode-prefix-map k1 cmd)) |
4222 | (define-key idlwave-mode-prefix-map k1 cmd)) | |
4223 | ;; The debug modifier map | |
05a1abfc CD |
4224 | (when (and mod window-system) |
4225 | (if (char-or-string-p c2) | |
4226 | (setq k2 (vector (append mod-noshift | |
4227 | (list (if shift (upcase c2) c2))))) | |
4228 | (setq k2 (vector (append mod (list c2))))) | |
52a244eb S |
4229 | (unless cannotshift |
4230 | (define-key idlwave-mode-map k2 cmd) | |
4231 | (unless only-buffer (define-key idlwave-shell-mode-map k2 cmd)))) | |
4232 | ;; The electric debug single-keystroke map | |
4233 | (if (and electric (char-or-string-p c2)) | |
5cba7601 | 4234 | (define-key idlwave-shell-electric-debug-mode-map (char-to-string c2) |
52a244eb S |
4235 | cmd)))) |
4236 | ||
4237 | ;; A few extras in the electric debug map | |
4238 | (define-key idlwave-shell-electric-debug-mode-map " " 'idlwave-shell-step) | |
4239 | (define-key idlwave-shell-electric-debug-mode-map "+" 'idlwave-shell-stack-up) | |
4240 | (define-key idlwave-shell-electric-debug-mode-map "=" 'idlwave-shell-stack-up) | |
5cba7601 | 4241 | (define-key idlwave-shell-electric-debug-mode-map "-" |
52a244eb | 4242 | 'idlwave-shell-stack-down) |
5cba7601 | 4243 | (define-key idlwave-shell-electric-debug-mode-map "_" |
52a244eb | 4244 | 'idlwave-shell-stack-down) |
5cba7601 | 4245 | (define-key idlwave-shell-electric-debug-mode-map "e" |
4f91a816 | 4246 | (lambda () (interactive) (idlwave-shell-print '(16)))) |
52a244eb | 4247 | (define-key idlwave-shell-electric-debug-mode-map "q" 'idlwave-shell-retall) |
5cba7601 | 4248 | (define-key idlwave-shell-electric-debug-mode-map "t" |
4f91a816 | 4249 | (lambda () (interactive) (idlwave-shell-send-command "help,/TRACE"))) |
52a244eb S |
4250 | (define-key idlwave-shell-electric-debug-mode-map [(control ??)] |
4251 | 'idlwave-shell-electric-debug-help) | |
5cba7601 | 4252 | (define-key idlwave-shell-electric-debug-mode-map "x" |
4f91a816 SM |
4253 | (lambda (arg) (interactive "P") |
4254 | (idlwave-shell-print arg nil nil t))) | |
52a244eb S |
4255 | |
4256 | ||
4257 | ; Enter the prefix map in two places. | |
4258 | (fset 'idlwave-debug-map idlwave-mode-prefix-map) | |
8c7b4ec8 EZ |
4259 | (fset 'idlwave-shell-debug-map idlwave-shell-mode-prefix-map) |
4260 | ||
52a244eb S |
4261 | ;; The Electric Debug Minor Mode -------------------------------------------- |
4262 | ||
4263 | (defun idlwave-shell-toggle-electric-debug-mode () | |
4264 | "Toggle electric-debug-mode, suppressing re-entry into mode if turned off." | |
4265 | (interactive) | |
4266 | ;; If turning it off, make sure it stays off throughout the debug | |
4267 | ;; session until we return or hit $MAIN$. Cancel this suppression | |
4268 | ;; if it's explicitly turned on. | |
4269 | (if idlwave-shell-electric-debug-mode | |
f66f03de S |
4270 | (progn ;; Turn it off, and make sure it stays off. |
4271 | (setq idlwave-shell-suppress-electric-debug t) | |
4272 | (idlwave-shell-electric-debug-mode 0)) | |
4273 | (setq idlwave-shell-suppress-electric-debug nil) | |
4274 | (idlwave-shell-electric-debug-mode t))) | |
52a244eb | 4275 | |
5cba7601 | 4276 | (defvar idlwave-shell-electric-debug-read-only) |
25d24a50 S |
4277 | (defvar idlwave-shell-electric-debug-buffers nil) |
4278 | ||
0f01161d | 4279 | (define-minor-mode idlwave-shell-electric-debug-mode |
52a244eb | 4280 | "Toggle Electric Debug mode. |
5cba7601 | 4281 | With no argument, this command toggles the mode. |
52a244eb S |
4282 | Non-null prefix argument turns on the mode. |
4283 | Null prefix argument turns off the mode. | |
4284 | ||
4285 | When Electric Debug mode is enabled, the many debugging commands are | |
4286 | available as single key sequences." | |
f66f03de S |
4287 | nil |
4288 | " *Debugging*" | |
4289 | idlwave-shell-electric-debug-mode-map) | |
52a244eb | 4290 | |
5cba7601 | 4291 | (add-hook |
52a244eb S |
4292 | 'idlwave-shell-electric-debug-mode-on-hook |
4293 | (lambda () | |
4294 | (set (make-local-variable 'idlwave-shell-electric-debug-read-only) | |
4295 | buffer-read-only) | |
4296 | (setq buffer-read-only t) | |
4297 | (add-to-list 'idlwave-shell-electric-debug-buffers (current-buffer)) | |
4298 | (if idlwave-shell-stop-line-overlay | |
5cba7601 | 4299 | (overlay-put idlwave-shell-stop-line-overlay 'face |
52a244eb S |
4300 | idlwave-shell-electric-stop-line-face)) |
4301 | (if (facep 'fringe) | |
4302 | (set-face-foreground 'fringe idlwave-shell-electric-stop-color | |
4303 | (selected-frame))))) | |
4304 | ||
5cba7601 | 4305 | (add-hook |
52a244eb S |
4306 | 'idlwave-shell-electric-debug-mode-off-hook |
4307 | (lambda () | |
4308 | ;; Return to previous read-only state | |
4309 | (setq buffer-read-only (if (boundp 'idlwave-shell-electric-debug-read-only) | |
4310 | idlwave-shell-electric-debug-read-only)) | |
4311 | (setq idlwave-shell-electric-debug-buffers | |
4312 | (delq (current-buffer) idlwave-shell-electric-debug-buffers)) | |
4313 | (if idlwave-shell-stop-line-overlay | |
5cba7601 | 4314 | (overlay-put idlwave-shell-stop-line-overlay 'face |
52a244eb S |
4315 | idlwave-shell-stop-line-face) |
4316 | (if (facep 'fringe) | |
4317 | (set-face-foreground 'fringe (face-foreground 'default)))))) | |
4318 | ||
4319 | ;; easy-mmode defines electric-debug-mode for us, so we need to advise it. | |
4320 | (defadvice idlwave-shell-electric-debug-mode (after print-enter activate) | |
5a0c3f56 | 4321 | "Print out an entrance message." |
52a244eb S |
4322 | (when idlwave-shell-electric-debug-mode |
4323 | (message | |
4324 | "Electric Debugging mode entered. Press [C-?] for help, [q] to quit")) | |
4325 | (force-mode-line-update)) | |
4326 | ||
4327 | ;; Turn it off in all relevant buffers | |
3938cb82 | 4328 | (defvar idlwave-shell-electric-debug-buffers nil) |
52a244eb S |
4329 | (defun idlwave-shell-electric-debug-all-off () |
4330 | (setq idlwave-shell-suppress-electric-debug nil) | |
4331 | (let ((buffers idlwave-shell-electric-debug-buffers) | |
4332 | buf) | |
4333 | (save-excursion | |
4334 | (while (setq buf (pop buffers)) | |
4335 | (when (buffer-live-p buf) | |
4336 | (set-buffer buf) | |
175069ef | 4337 | (when (and (derived-mode-p 'idlwave-mode) |
52a244eb S |
4338 | buffer-file-name |
4339 | idlwave-shell-electric-debug-mode) | |
f66f03de | 4340 | (idlwave-shell-electric-debug-mode 0)))))) |
52a244eb S |
4341 | (setq idlwave-shell-electric-debug-buffers nil)) |
4342 | ||
4343 | ;; Show the help text | |
4344 | (defun idlwave-shell-electric-debug-help () | |
4345 | (interactive) | |
5cba7601 | 4346 | (with-output-to-temp-buffer "*IDLWAVE Electric Debug Help*" |
52a244eb S |
4347 | (princ idlwave-shell-electric-debug-help)) |
4348 | (let* ((current-window (selected-window)) | |
4349 | (window (get-buffer-window "*IDLWAVE Electric Debug Help*")) | |
4350 | (window-lines (window-height window))) | |
4351 | (select-window window) | |
4352 | (enlarge-window (1+ (- (count-lines 1 (point-max)) window-lines))) | |
4353 | (select-window current-window))) | |
4354 | ||
8c7b4ec8 | 4355 | |
52a244eb | 4356 | ;; The Menus -------------------------------------------------------------- |
8c7b4ec8 | 4357 | (defvar idlwave-shell-menu-def |
52a244eb S |
4358 | `("Debug" |
4359 | ["Electric Debug Mode" | |
4360 | idlwave-shell-electric-debug-mode | |
5cba7601 | 4361 | :style toggle :selected idlwave-shell-electric-debug-mode |
175069ef | 4362 | :included (derived-mode-p 'idlwave-mode) :keys "C-c C-d C-v"] |
8c7b4ec8 | 4363 | "--" |
15e42531 CD |
4364 | ("Compile & Run" |
4365 | ["Save and .RUN" idlwave-shell-save-and-run | |
175069ef | 4366 | (or (derived-mode-p 'idlwave-mode) |
15e42531 CD |
4367 | idlwave-shell-last-save-and-action-file)] |
4368 | ["Save and .COMPILE" idlwave-shell-save-and-compile | |
175069ef | 4369 | (or (derived-mode-p 'idlwave-mode) |
15e42531 CD |
4370 | idlwave-shell-last-save-and-action-file)] |
4371 | ["Save and @Batch" idlwave-shell-save-and-batch | |
175069ef | 4372 | (or (derived-mode-p 'idlwave-mode) |
15e42531 | 4373 | idlwave-shell-last-save-and-action-file)] |
52a244eb | 4374 | "--" |
15e42531 CD |
4375 | ["Goto Next Error" idlwave-shell-goto-next-error t] |
4376 | "--" | |
5cba7601 | 4377 | ["Compile and Run Region" idlwave-shell-run-region |
175069ef | 4378 | (derived-mode-p 'idlwave-mode)] |
5cba7601 | 4379 | ["Evaluate Region" idlwave-shell-evaluate-region |
175069ef | 4380 | (derived-mode-p 'idlwave-mode)] |
15e42531 CD |
4381 | "--" |
4382 | ["Execute Default Cmd" idlwave-shell-execute-default-command-line t] | |
4383 | ["Edit Default Cmd" idlwave-shell-edit-default-command-line t]) | |
4384 | ("Breakpoints" | |
5cba7601 | 4385 | ["Set Breakpoint" idlwave-shell-break-here |
175069ef | 4386 | :keys "C-c C-d C-b" :active (derived-mode-p 'idlwave-mode)] |
52a244eb S |
4387 | ("Set Special Breakpoint" |
4388 | ["Set After Count Breakpoint" | |
4389 | (progn | |
027a4b6b | 4390 | (let ((count (string-to-number (read-string "Break after count: ")))) |
52a244eb | 4391 | (if (integerp count) (idlwave-shell-break-here count)))) |
175069ef | 4392 | :active (derived-mode-p 'idlwave-mode)] |
52a244eb S |
4393 | ["Set Condition Breakpoint" |
4394 | (idlwave-shell-break-here '(4)) | |
175069ef | 4395 | :active (derived-mode-p 'idlwave-mode)]) |
5cba7601 | 4396 | ["Break in Module" idlwave-shell-break-in |
175069ef | 4397 | :keys "C-c C-d C-i" :active (derived-mode-p 'idlwave-mode)] |
52a244eb | 4398 | ["Break in this Module" idlwave-shell-break-this-module |
175069ef | 4399 | :keys "C-c C-d C-j" :active (derived-mode-p 'idlwave-mode)] |
15e42531 CD |
4400 | ["Clear Breakpoint" idlwave-shell-clear-current-bp t] |
4401 | ["Clear All Breakpoints" idlwave-shell-clear-all-bp t] | |
52a244eb | 4402 | ["Disable/Enable Breakpoint" idlwave-shell-toggle-enable-current-bp t] |
5cba7601 | 4403 | ["Goto Previous Breakpoint" idlwave-shell-goto-previous-bp |
175069ef | 4404 | :keys "C-c C-d [" :active (derived-mode-p 'idlwave-mode)] |
5cba7601 | 4405 | ["Goto Next Breakpoint" idlwave-shell-goto-next-bp |
175069ef | 4406 | :keys "C-c C-d ]" :active (derived-mode-p 'idlwave-mode)] |
52a244eb S |
4407 | ["List All Breakpoints" idlwave-shell-list-all-bp t] |
4408 | ["Resync Breakpoints" idlwave-shell-bp-query t]) | |
05a1abfc | 4409 | ("Continue/Step" |
15e42531 CD |
4410 | ["Step (into)" idlwave-shell-step t] |
4411 | ["Step (over)" idlwave-shell-stepover t] | |
4412 | ["Skip One Statement" idlwave-shell-skip t] | |
4413 | ["Continue" idlwave-shell-cont t] | |
4414 | ["... to End of Block" idlwave-shell-up t] | |
4415 | ["... to End of Subprog" idlwave-shell-return t] | |
4416 | ["... to End of Subprog+1" idlwave-shell-out t] | |
4417 | ["... to Here (Cursor Line)" idlwave-shell-to-here | |
175069ef | 4418 | :keys "C-c C-d C-h" :active (derived-mode-p 'idlwave-mode)]) |
52a244eb | 4419 | ("Examine Expressions" |
15e42531 CD |
4420 | ["Print expression" idlwave-shell-print t] |
4421 | ["Help on expression" idlwave-shell-help-expression t] | |
52a244eb S |
4422 | ("Examine nearby expression with" |
4423 | ,@(mapcar (lambda(x) | |
4424 | `[ ,(car x) (idlwave-shell-print nil ',x) t ]) | |
4425 | idlwave-shell-examine-alist)) | |
4426 | ("Examine region with" | |
4427 | ,@(mapcar (lambda(x) | |
4428 | `[ ,(car x) (idlwave-shell-print '(4) ',x) t ]) | |
4429 | idlwave-shell-examine-alist))) | |
4430 | ("Call Stack" | |
15e42531 | 4431 | ["Stack Up" idlwave-shell-stack-up t] |
52a244eb S |
4432 | ["Stack Down" idlwave-shell-stack-down t] |
4433 | "--" | |
4434 | ["Redisplay and Sync" idlwave-shell-redisplay t]) | |
4435 | ("Show Commands" | |
4436 | ["Everything" (if (eq idlwave-shell-show-commands 'everything) | |
5cba7601 | 4437 | (progn |
52a244eb S |
4438 | (setq idlwave-shell-show-commands |
4439 | (get 'idlwave-shell-show-commands 'last-val)) | |
4440 | (put 'idlwave-shell-show-commands 'last-val nil)) | |
5cba7601 | 4441 | (put 'idlwave-shell-show-commands 'last-val |
52a244eb S |
4442 | idlwave-shell-show-commands) |
4443 | (setq idlwave-shell-show-commands 'everything)) | |
4444 | :style toggle :selected (and (not (listp idlwave-shell-show-commands)) | |
5cba7601 | 4445 | (eq idlwave-shell-show-commands |
52a244eb S |
4446 | 'everything))] |
4447 | "--" | |
4448 | ["Compiling Commands" (idlwave-shell-add-or-remove-show 'run) | |
5cba7601 GM |
4449 | :style toggle |
4450 | :selected (not (idlwave-shell-hide-p | |
52a244eb S |
4451 | 'run |
4452 | (get 'idlwave-shell-show-commands 'last-val))) | |
4453 | :active (not (eq idlwave-shell-show-commands 'everything))] | |
4454 | ["Breakpoint Commands" (idlwave-shell-add-or-remove-show 'breakpoint) | |
5cba7601 GM |
4455 | :style toggle |
4456 | :selected (not (idlwave-shell-hide-p | |
52a244eb S |
4457 | 'breakpoint |
4458 | (get 'idlwave-shell-show-commands 'last-val))) | |
4459 | :active (not (eq idlwave-shell-show-commands 'everything))] | |
4460 | ["Debug Commands" (idlwave-shell-add-or-remove-show 'debug) | |
5cba7601 GM |
4461 | :style toggle |
4462 | :selected (not (idlwave-shell-hide-p | |
52a244eb S |
4463 | 'debug |
4464 | (get 'idlwave-shell-show-commands 'last-val))) | |
4465 | :active (not (eq idlwave-shell-show-commands 'everything))] | |
4466 | ["Miscellaneous Commands" (idlwave-shell-add-or-remove-show 'misc) | |
5cba7601 GM |
4467 | :style toggle |
4468 | :selected (not (idlwave-shell-hide-p | |
52a244eb S |
4469 | 'misc |
4470 | (get 'idlwave-shell-show-commands 'last-val))) | |
4471 | :active (not (eq idlwave-shell-show-commands 'everything))]) | |
15e42531 CD |
4472 | ("Input Mode" |
4473 | ["Send one char" idlwave-shell-send-char t] | |
4474 | ["Temporary Character Mode" idlwave-shell-char-mode-loop t] | |
4475 | "--" | |
4476 | ["Use Input Mode Magic" | |
4477 | (setq idlwave-shell-use-input-mode-magic | |
4478 | (not idlwave-shell-use-input-mode-magic)) | |
4479 | :style toggle :selected idlwave-shell-use-input-mode-magic]) | |
4480 | "--" | |
4481 | ["Update Working Dir" idlwave-shell-resync-dirs t] | |
5cba7601 | 4482 | ["Save Path Info" |
52a244eb S |
4483 | (idlwave-shell-send-command idlwave-shell-path-query |
4484 | 'idlwave-shell-get-path-info | |
4485 | 'hide) | |
4486 | t] | |
15e42531 CD |
4487 | ["Reset IDL" idlwave-shell-reset t] |
4488 | "--" | |
4489 | ["Toggle Toolbar" idlwave-shell-toggle-toolbar t] | |
4490 | ["Exit IDL" idlwave-shell-quit t])) | |
8c7b4ec8 EZ |
4491 | |
4492 | (if (or (featurep 'easymenu) (load "easymenu" t)) | |
4493 | (progn | |
3d1ead4b | 4494 | (easy-menu-define |
52a244eb | 4495 | idlwave-mode-debug-menu idlwave-mode-map "IDL debugging menus" |
8c7b4ec8 | 4496 | idlwave-shell-menu-def) |
13ae1076 | 4497 | (easy-menu-define |
52a244eb | 4498 | idlwave-shell-mode-menu idlwave-shell-mode-map "IDL shell menus" |
8c7b4ec8 | 4499 | idlwave-shell-menu-def) |
9a529312 SM |
4500 | (save-current-buffer |
4501 | (dolist (buf (buffer-list)) | |
4502 | (set-buffer buf) | |
175069ef | 4503 | (if (derived-mode-p 'idlwave-mode) |
9a529312 SM |
4504 | (progn |
4505 | (easy-menu-remove idlwave-mode-debug-menu) | |
4506 | (easy-menu-add idlwave-mode-debug-menu))))))) | |
8c7b4ec8 EZ |
4507 | |
4508 | ;; The Breakpoint Glyph ------------------------------------------------------- | |
4509 | ||
4510 | (defvar idlwave-shell-bp-glyph nil | |
52a244eb | 4511 | "The glyphs to mark breakpoint lines in the source code.") |
8c7b4ec8 | 4512 | |
3d1ead4b | 4513 | (let ((image-alist |
52a244eb | 4514 | '((bp . "/* XPM */ |
8c7b4ec8 EZ |
4515 | static char * file[] = { |
4516 | \"14 12 3 1\", | |
5e72c6b2 | 4517 | \" c None s backgroundColor\", |
8c7b4ec8 EZ |
4518 | \". c #4B4B4B4B4B4B\", |
4519 | \"R c #FFFF00000000\", | |
4520 | \" \", | |
52a244eb S |
4521 | \" .... \", |
4522 | \" .RRRR. \", | |
4523 | \" .RRRRRR. \", | |
4524 | \" .RRRRRRRR. \", | |
4525 | \" .RRRRRRRR. \", | |
4526 | \" .RRRRRRRR. \", | |
4527 | \" .RRRRRRRR. \", | |
4528 | \" .RRRRRR. \", | |
4529 | \" .RRRR. \", | |
4530 | \" .... \", | |
4531 | \" \"};") | |
4532 | (bp-cond . "/* XPM */ | |
4533 | static char * file[] = { | |
4534 | \"14 12 4 1\", | |
4535 | \" c None s backgroundColor\", | |
4536 | \". c #4B4B4B4B4B4B\", | |
4537 | \"R c #FFFF00000000\", | |
4538 | \"B c #000000000000\", | |
4539 | \" \", | |
4540 | \" .... \", | |
4541 | \" .RRRR. \", | |
4542 | \" .RRRRRR. \", | |
4543 | \" .RRRRRRRR. \", | |
4544 | \" .RRBBBBRR. \", | |
4545 | \" .RRRRRRRR. \", | |
4546 | \" .RRBBBBRR. \", | |
4547 | \" .RRRRRR. \", | |
4548 | \" .RRRR. \", | |
4549 | \" .... \", | |
4550 | \" \"};") | |
4551 | (bp-1 . "/* XPM */ | |
4552 | static char * file[] = { | |
4553 | \"14 12 4 1\", | |
4554 | \" c None s backgroundColor\", | |
4555 | \". c #4B4B4B4B4B4B\", | |
4556 | \"X c #FFFF00000000\", | |
4557 | \"o c #000000000000\", | |
4558 | \" \", | |
4559 | \" .... \", | |
4560 | \" .XXXX. \", | |
4561 | \" .XXooXX. \", | |
4562 | \" .XXoooXXX. \", | |
4563 | \" .XXXooXXX. \", | |
4564 | \" .XXXooXXX. \", | |
4565 | \" .XXooooXX. \", | |
4566 | \" .XooooX. \", | |
4567 | \" .XXXX. \", | |
4568 | \" .... \", | |
4569 | \" \"};") | |
4570 | (bp-2 . "/* XPM */ | |
4571 | static char * file[] = { | |
4572 | \"14 12 4 1\", | |
4573 | \" c None s backgroundColor\", | |
4574 | \". c #4B4B4B4B4B4B\", | |
4575 | \"X c #FFFF00000000\", | |
4576 | \"o c #000000000000\", | |
4577 | \" \", | |
4578 | \" .... \", | |
4579 | \" .XXXX. \", | |
4580 | \" .XoooXX. \", | |
4581 | \" .XXoXooXX. \", | |
4582 | \" .XXXXooXX. \", | |
4583 | \" .XXXooXXX. \", | |
4584 | \" .XXooXXXX. \", | |
4585 | \" .XooooX. \", | |
4586 | \" .XXXX. \", | |
4587 | \" .... \", | |
4588 | \" \"};") | |
4589 | (bp-3 . "/* XPM */ | |
4590 | static char * file[] = { | |
4591 | \"14 12 4 1\", | |
4592 | \" c None s backgroundColor\", | |
4593 | \". c #4B4B4B4B4B4B\", | |
4594 | \"X c #FFFF00000000\", | |
4595 | \"o c #000000000000\", | |
4596 | \" \", | |
4597 | \" .... \", | |
4598 | \" .XXXX. \", | |
4599 | \" .XoooXX. \", | |
4600 | \" .XXXXooXX. \", | |
4601 | \" .XXXooXXX. \", | |
4602 | \" .XXXXooXX. \", | |
4603 | \" .XXoXooXX. \", | |
4604 | \" .XoooXX. \", | |
4605 | \" .XXXX. \", | |
4606 | \" .... \", | |
4607 | \" \"};") | |
4608 | (bp-4 . "/* XPM */ | |
4609 | static char * file[] = { | |
4610 | \"14 12 4 1\", | |
4611 | \" c None s backgroundColor\", | |
4612 | \". c #4B4B4B4B4B4B\", | |
4613 | \"X c #FFFF00000000\", | |
4614 | \"o c #000000000000\", | |
8c7b4ec8 | 4615 | \" \", |
52a244eb S |
4616 | \" .... \", |
4617 | \" .XXXX. \", | |
4618 | \" .XoXXoX. \", | |
4619 | \" .XXoXXoXX. \", | |
4620 | \" .XXooooXX. \", | |
4621 | \" .XXXXooXX. \", | |
4622 | \" .XXXXooXX. \", | |
4623 | \" .XXXooX. \", | |
4624 | \" .XXXX. \", | |
4625 | \" .... \", | |
4626 | \" \"};") | |
4627 | (bp-n . "/* XPM */ | |
4628 | static char * file[] = { | |
4629 | \"14 12 4 1\", | |
4630 | \" c None s backgroundColor\", | |
4631 | \". c #4B4B4B4B4B4B\", | |
4632 | \"X c #FFFF00000000\", | |
4633 | \"o c #000000000000\", | |
8c7b4ec8 | 4634 | \" \", |
52a244eb S |
4635 | \" .... \", |
4636 | \" .XXXX. \", | |
4637 | \" .XXXXXX. \", | |
4638 | \" .XXoXoXXX. \", | |
4639 | \" .XXooXoXX. \", | |
4640 | \" .XXoXXoXX. \", | |
4641 | \" .XXoXXoXX. \", | |
4642 | \" .XoXXoX. \", | |
4643 | \" .XXXX. \", | |
4644 | \" .... \", | |
4645 | \" \"};"))) im-cons im) | |
5cba7601 | 4646 | |
52a244eb S |
4647 | (while (setq im-cons (pop image-alist)) |
4648 | (setq im (cond ((and (featurep 'xemacs) | |
4649 | (featurep 'xpm)) | |
4650 | (list | |
4651 | (let ((data (cdr im-cons))) | |
4652 | (string-match "#FFFF00000000" data) | |
4653 | (setq data (replace-match "#8F8F8F8F8F8F" t t data)) | |
4654 | (make-glyph data)) | |
4655 | (make-glyph (cdr im-cons)))) | |
4656 | ((and (not (featurep 'xemacs)) | |
4657 | (fboundp 'image-type-available-p) | |
4658 | (image-type-available-p 'xpm)) | |
5cba7601 | 4659 | (list 'image :type 'xpm :data (cdr im-cons) |
52a244eb S |
4660 | :ascent 'center)) |
4661 | (t nil))) | |
4662 | (if im (push (cons (car im-cons) im) idlwave-shell-bp-glyph)))) | |
8c7b4ec8 EZ |
4663 | |
4664 | (provide 'idlw-shell) | |
a98f98c0 | 4665 | (provide 'idlwave-shell) |
8c7b4ec8 | 4666 | |
9a529312 | 4667 | ;; Load the toolbar when wanted by the user. |
8c7b4ec8 | 4668 | |
5cba7601 | 4669 | (autoload 'idlwave-toolbar-toggle "idlw-toolbar" |
5a0c3f56 | 4670 | "Toggle the IDLWAVE toolbar.") |
ca660d22 | 4671 | (autoload 'idlwave-toolbar-add-everywhere "idlw-toolbar" |
5a0c3f56 | 4672 | "Add IDLWAVE toolbar.") |
8c7b4ec8 EZ |
4673 | (defun idlwave-shell-toggle-toolbar () |
4674 | "Toggle the display of the debugging toolbar." | |
4675 | (interactive) | |
ca660d22 | 4676 | (idlwave-toolbar-toggle)) |
8c7b4ec8 | 4677 | |
ca660d22 CD |
4678 | (if idlwave-shell-use-toolbar |
4679 | (add-hook 'idlwave-shell-mode-hook 'idlwave-toolbar-add-everywhere)) | |
8df608c1 | 4680 | |
8c7b4ec8 | 4681 | ;;; idlw-shell.el ends here |