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