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