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