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