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