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