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