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