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