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