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