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