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