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