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