1 ;; idlw-shell.el --- run IDL as an inferior process of Emacs.
2 ;; Copyright (c) 1999,2000,2001,2002,2003 Free Software Foundation
4 ;; Authors: J.D. Smith <jdsmith@as.arizona.edu>
5 ;; Carsten Dominik <dominik@astro.uva.nl>
6 ;; Chris Chase <chase@att.com>
7 ;; Maintainer: J.D. Smith <jdsmith@as.arizona.edu>
9 ;; Date: $Date: 2003-08-12 12:26:18 $
10 ;; Keywords: processes
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 2, or (at your option)
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; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
31 ;; This mode is for IDL version 5 or later. It should work on
32 ;; Emacs>20.3 or XEmacs>20.4.
34 ;; Runs IDL as an inferior process of Emacs, much like the emacs
35 ;; `shell' or `telnet' commands. Provides command history and
36 ;; searching. Provides debugging commands available in buffers
37 ;; visiting IDL procedure files, e.g., breakpoint setting, stepping,
38 ;; execution until a certain line, printing expressions under point,
39 ;; visual line pointer for current execution line, etc.
41 ;; Documentation should be available online with `M-x idlwave-info'.
43 ;; New versions of IDLWAVE, documentation, and more information
50 ;; Follow the instructions in the INSTALL file of the distribution.
51 ;; In short, put this file on your load path and add the following
52 ;; lines to your .emacs file:
54 ;; (autoload 'idlwave-shell "idlw-shell" "IDLWAVE Shell" t)
60 ;; The newest version of this file can be found on the maintainers
68 ;; IDLWAVE is documented online in info format.
69 ;; A printable version of the documentation is available from the
70 ;; maintainers webpage (see under SOURCE)
76 ;; Under XEmacs the Debug menu in the shell does not display the
77 ;; keybindings in the prefix map. There bindings are available anyway - so
78 ;; it is a bug in XEmacs.
79 ;; The Debug menu in source buffers *does* display the bindings correctly.
82 ;; CUSTOMIZATION VARIABLES
83 ;; =======================
85 ;; IDLWAVE has customize support - so if you want to learn about
86 ;; the variables which control the behavior of the mode, use
87 ;; `M-x idlwave-customize'.
89 ;;--------------------------------------------------------------------------
97 (eval-when-compile (require 'cl))
99 (defvar idlwave-shell-have-new-custom nil)
101 ;; Kludge to allow `defcustom' for Emacs 19.
102 (condition-case () (require 'custom) (error nil))
103 (if (and (featurep 'custom)
104 (fboundp 'custom-declare-variable)
106 ;; We've got what we needed
107 (setq idlwave-shell-have-new-custom t)
108 ;; We have the old or no custom-library, hack around it!
109 (defmacro defgroup (&rest args) nil)
110 (defmacro defcustom (var value doc &rest args)
111 `(defvar ,var ,value ,doc))))
113 ;;; Customizations: idlwave-shell group
115 ;; General/Misc. customizations
116 (defgroup idlwave-shell-general-setup nil
117 "General setup of the Shell interaction for IDLWAVE/Shell."
118 :prefix "idlwave-shell"
121 (defcustom idlwave-shell-prompt-pattern "^ ?IDL> "
122 "*Regexp to match IDL prompt at beginning of a line.
123 For example, \"^IDL> \" or \"^WAVE> \".
124 The \"^\" means beginning of line, and is required.
125 This variable is used to initialize `comint-prompt-regexp' in the
128 This is a fine thing to set in your `.emacs' file."
129 :group 'idlwave-shell-general-setup
132 (defcustom idlwave-shell-process-name "idl"
133 "*Name to be associated with the IDL process. The buffer for the
134 process output is made by surrounding this name with `*'s."
135 :group 'idlwave-shell-general-setup
138 ;; (defcustom idlwave-shell-automatic-start...) See idlwave.el
140 (defcustom idlwave-shell-use-dedicated-frame nil
141 "*Non-nil means, IDLWAVE should use a special frame to display shell buffer."
142 :group 'idlwave-shell-general-setup
145 (defcustom idlwave-shell-frame-parameters
146 '((height . 30) (unsplittable . nil))
147 "The frame parameters for a dedicated idlwave-shell frame.
148 See also `idlwave-shell-use-dedicated-frame'.
149 The default makes the frame splittable, so that completion works correctly."
150 :group 'idlwave-shell-general-setup
154 (defcustom idlwave-shell-raise-frame t
155 "*Non-nil means, `idlwave-shell' raises the frame showing the shell window."
156 :group 'idlwave-shell-general-setup
159 (defcustom idlwave-shell-arrows-do-history t
160 "*Non-nil means UP and DOWN arrows move through command history.
161 This variable can have 3 values:
162 nil Arrows just move the cursor
163 t Arrows force the cursor back to the current command line and
165 'cmdline When the cursor is in the current command line, arrows walk the
166 history. Everywhere else in the buffer, arrows move the cursor."
167 :group 'idlwave-shell-general-setup
169 (const :tag "never" nil)
170 (const :tag "everywhere" t)
171 (const :tag "in command line only" cmdline)))
173 ;; FIXME: add comint-input-ring-size?
175 (defcustom idlwave-shell-use-toolbar t
176 "*Non-nil means, use the debugging toolbar in all IDL related buffers.
177 Starting the shell will then add the toolbar to all idlwave-mode buffers.
178 Exiting the shell will removed everywhere.
179 Available on XEmacs and on Emacs 21.x or later.
180 At any time you can toggle the display of the toolbar with
181 `C-c C-d C-t' (`idlwave-shell-toggle-toolbar')."
182 :group 'idlwave-shell-general-setup
185 (defcustom idlwave-shell-temp-pro-prefix "/tmp/idltemp"
186 "*The prefix for temporary IDL files used when compiling regions.
187 It should be an absolute pathname.
188 The full temporary file name is obtained by using `make-temp-file'
189 so that the name will be unique among multiple Emacs processes."
190 :group 'idlwave-shell-general-setup
193 (defvar idlwave-shell-fix-inserted-breaks nil
194 "*OBSOLETE VARIABLE, is no longer used.
196 The documentation of this variable used to be:
197 If non-nil then run `idlwave-shell-remove-breaks' to clean up IDL messages.")
199 (defcustom idlwave-shell-prefix-key "\C-c\C-d"
200 "*The prefix key for the debugging map `idlwave-shell-mode-prefix-map'.
201 This variable must already be set when idlwave-shell.el is loaded.
202 Setting it in the mode-hook is too late."
203 :group 'idlwave-shell-general-setup
206 (defcustom idlwave-shell-activate-prefix-keybindings t
207 "Non-nil means, the debug commands will be bound to the prefix key.
208 The prefix key itself is given in the option `idlwave-shell-prefix-key'.
209 So by default setting a breakpoint will be on C-c C-d C-b."
210 :group 'idlwave-shell-general-setup
213 (defcustom idlwave-shell-automatic-electric-debug 'breakpoint
214 "Enter the electric-debug minor mode automatically.
215 This occurs at a breakpoint or any other halt. The mode is exited
216 upon return to the main level. Can be set to 'breakpoint to enter
217 electric debug mode only when breakpoints are tripped."
218 :group 'idlwave-shell-general-setup
220 (const :tag "never" nil)
221 (const :tag "always" t)
222 (const :tag "for breakpoints only" breakpoint)))
224 (defcustom idlwave-shell-electric-zap-to-file t
225 "When entering electric debug mode, select the window displaying the
226 file at which point is stopped. This takes point away from the shell
227 window, but is useful for stepping, etc."
228 :group 'idlwave-shell-general-setup
231 ;; (defcustom idlwave-shell-debug-modifiers... See idlwave.el
233 (defvar idlwave-shell-activate-alt-keybindings nil
234 "Obsolete variable. See `idlwave-shell-debug-modifiers'.")
236 (defcustom idlwave-shell-use-truename nil
237 "*Non-nil means, use use `file-truename' when looking for buffers.
238 If this variable is non-nil, Emacs will use the function `file-truename' to
239 resolve symbolic links in the file paths printed by e.g., STOP commands.
240 This means, unvisited files will be loaded under their truename.
241 However, when a file is already visited under a different name, IDLWAVE will
243 This option was once introduced in order to avoid multiple buffers visiting
244 the same file. However, IDLWAVE no longer makes this mistake, so it is safe
245 to set this option to nil."
246 :group 'idlwave-shell-general-setup
249 (defcustom idlwave-shell-file-name-chars "~/A-Za-z0-9+:_.$#%={}\\-"
250 "The characters allowed in file names, as a string.
251 Used for file name completion. Must not contain `'', `,' and `\"'
252 because these are used as separators by IDL."
253 :group 'idlwave-shell-general-setup
256 (defcustom idlwave-shell-mode-hook '()
257 "*Hook for customising `idlwave-shell-mode'."
258 :group 'idlwave-shell-general-setup
261 (defcustom idlwave-shell-graphics-window-size '(500 400)
262 "Size of IDL graphics windows popped up by special IDLWAVE command.
263 The command is `C-c C-d C-f' and accepts as a prefix the window nr.
264 A command like `WINDOW,N,xsize=XX,ysize=YY' is sent to IDL."
265 :group 'idlwave-shell-general-setup
267 (integer :tag "x size")
268 (integer :tag "y size")))
271 ;; Commands Sent to Shell... etc.
272 (defgroup idlwave-shell-command-setup nil
273 "Setup for command parameters of the Shell interaction for IDLWAVE."
274 :prefix "idlwave-shell"
277 (defcustom idlwave-shell-initial-commands "!more=0 & defsysv,'!ERROR_STATE',EXISTS=__e & if __e then begin & !ERROR_STATE.MSG_PREFIX=\"% \" & delvar,__e & endif"
278 "Initial commands, separated by newlines, to send to IDL.
279 This string is sent to the IDL process by `idlwave-shell-mode' which is
280 invoked by `idlwave-shell'."
281 :group 'idlwave-shell-command-setup
284 (defcustom idlwave-shell-save-command-history t
285 "Non-nil means preserve command history between sessions.
286 The file `idlwave-shell-command-history-file' is used to save and restore
288 :group 'idlwave-shell-command-setup
291 (defcustom idlwave-shell-command-history-file "idlwhist"
292 "The file in which the command history of the idlwave shell is saved.
293 In order to change the size of the history, see the variable
294 `comint-input-ring-size'.
295 The history is only saved if the variable `idlwave-shell-save-command-history'
297 :group 'idlwave-shell-command-setup
300 (defcustom idlwave-shell-show-commands
301 '(run misc breakpoint)
302 "*A list of command types to show output from in the shell.
303 Possibilities are 'run, 'debug, 'breakpoint, and 'misc. Unselected
304 types are not displayed in the shell. The type 'everything causes all
305 the copious shell traffic to be displayed."
306 :group 'idlwave-shell-command-setup
309 (set :tag "Checklist" :greedy t
310 (const :tag "All .run and .compile commands" run)
311 (const :tag "All breakpoint commands" breakpoint)
312 (const :tag "All debug and stepping commands" debug)
313 (const :tag "Close, window, retall, etc. commands" misc))))
315 (defcustom idlwave-shell-examine-alist
316 '(("Print" . "print,___")
317 ("Help" . "help,___")
318 ("Structure Help" . "help,___,/STRUCTURE")
319 ("Dimensions" . "print,size(___,/DIMENSIONS)")
320 ("Type" . "print,size(___,/TNAME)")
321 ("N_Elements" . "print,n_elements(___)")
322 ("All Size Info" . "help,(__IWsz__=size(___,/STRUCTURE)),/STRUCTURE & print,__IWsz__.DIMENSIONS")
323 ("Ptr Valid" . "print,ptr_valid(___)")
324 ("Widget Valid" . "print,widget_info(___,/VALID)")
325 ("Widget Geometry" . "help,widget_info(___,/GEOMETRY)"))
326 "Alist of special examine commands for popup selection.
327 The keys are used in the selection popup created by
328 `idlwave-shell-examine-select', and the corresponding value is sent as
329 a command to the shell, with special sequence `___' replaced by the
330 expression being examined."
331 :group 'idlwave-shell-command-setup
334 (string :tag "Label ")
335 (string :tag "Command"))))
337 (defvar idlwave-shell-print-expression-function nil
338 "*OBSOLETE VARIABLE, is no longer used.")
340 (defcustom idlwave-shell-separate-examine-output t
341 "*Non-nil mean, put output of examine commands in their own buffer."
342 :group 'idlwave-shell-command-setup
345 (defcustom idlwave-shell-comint-settings
346 '((comint-scroll-to-bottom-on-input . t)
347 (comint-scroll-to-bottom-on-output . t)
348 (comint-scroll-show-maximum-output . nil))
350 "Alist of special settings for the comint variables in the IDLWAVE Shell.
351 Each entry is a cons cell with the name of a variable and a value.
352 The function `idlwave-shell-mode' will make local variables out of each entry.
353 Changes to this variable will only be active when the shell buffer is
355 :group 'idlwave-shell-command-setup
357 (cons variable sexp)))
359 (defcustom idlwave-shell-query-for-class t
360 "*Non-nil means query the shell for object class on object completions."
361 :group 'idlwave-shell-command-setup
364 (defcustom idlwave-shell-use-input-mode-magic nil
365 "*Non-nil means, IDLWAVE should check for input mode spells in output.
366 The spells are strings printed by your IDL program and matched
367 by the regular expressions in `idlwave-shell-input-mode-spells'.
368 When these expressions match, IDLWAVE switches to character input mode and
369 back, respectively. See `idlwave-shell-input-mode-spells' for details."
370 :group 'idlwave-shell-command-setup
373 (defcustom idlwave-shell-input-mode-spells
374 '("^<onechar>$" "^<chars>$" "^</chars>$")
375 "The three regular expressions which match the magic spells for input modes.
377 When the first regexp matches in the output streem of IDL, IDLWAVE
378 prompts for a single character and sends it immediately to IDL, similar
379 to the command \\[idlwave-shell-send-char].
381 When the second regexp matches, IDLWAVE switches to a blocking
382 single-character input mode. This is the same mode which can be entered
383 manually with \\[idlwave-shell-char-mode-loop].
384 This input mode exits when the third regexp matches in the output,
385 or when the IDL prompt is encountered.
387 The variable `idlwave-shell-use-input-mode-magic' must be non-nil to enable
388 scanning for these expressions. If the IDL program produces lots of
389 output, shell operation may be slowed down.
391 This mechanism is useful for correct interaction with the IDL function
392 GET_KBRD, because in normal operation IDLWAVE only sends \\n terminated
393 strings. Here is some example code which makes use of the default spells.
395 print,'<chars>' ; Make IDLWAVE switch to character mode
399 ENDREP UNTIL A EQ 'q'
400 print,'</chars>' ; Make IDLWAVE switch back to line mode
402 print,'Quit the program, y or n?'
403 print,'<onechar>' ; Ask IDLWAVE to send one character
406 Since the IDLWAVE shell defines the system variable `!IDLWAVE_VERSION',
407 you could actually check if you are running under Emacs before printing
408 the magic strings. Here is a procedure which uses this.
412 idlwave_char_input ; Make IDLWAVE send one character
413 idlwave_char_input,/on ; Start the loop to send characters
414 idlwave_char_input,/off ; End the loop to send chracters
417 pro idlwave_char_input,on=on,off=off
418 ;; Test if we are running under Emacs
419 defsysv,'!idlwave_version',exists=running_emacs
420 if running_emacs then begin
421 if keyword_set(on) then print,'<chars>' $
422 else if keyword_set(off) then print,'</chars>' $
423 else print,'<onechar>'
426 :group 'idlwave-shell-command-setup
428 (regexp :tag "One-char regexp")
429 (regexp :tag "Char-mode regexp")
430 (regexp :tag "Line-mode regexp")))
433 ;; Breakpoint Overlays etc
434 (defgroup idlwave-shell-highlighting-and-faces nil
435 "Highlighting and Faces used by the IDLWAVE Shell mode."
436 :prefix "idlwave-shell"
439 (defcustom idlwave-shell-mark-stop-line t
440 "*Non-nil means, mark the source code line where IDL is currently stopped.
441 Value decides about the method which is used to mark the line. Legal values
444 nil Do not mark the line
445 'arrow Use the overlay arrow
446 'face Use `idlwave-shell-stop-line-face' to highlight the line.
447 t Use what IDLWAVE thinks is best. Will be a face where possible,
448 otherwise the overlay arrow.
449 The overlay-arrow has the disadvantage to hide the first chars of a line.
450 Since many people do not have the main block of IDL programs indented,
451 a face highlighting may be better.
452 In Emacs 21, the overlay arrow is displayed in a special area and never
453 hides any code, so setting this to 'arrow on Emacs 21 sounds like a good idea."
454 :group 'idlwave-shell-highlighting-and-faces
456 (const :tag "No marking" nil)
457 (const :tag "Use overlay arrow" arrow)
458 (const :tag "Highlight with face" face)
459 (const :tag "Face or arrow." t)))
461 (defcustom idlwave-shell-overlay-arrow ">"
462 "*The overlay arrow to display at source lines where execution halts.
463 We use a single character by default, since the main block of IDL procedures
464 often has no indentation. Where possible, IDLWAVE will use overlays to
465 display the stop-lines. The arrow is only used on character-based terminals.
466 See also `idlwave-shell-use-overlay-arrow'."
467 :group 'idlwave-shell-highlighting-and-faces
470 (defcustom idlwave-shell-stop-line-face 'highlight
471 "*The face for `idlwave-shell-stop-line-overlay'.
472 Allows you to choose the font, color and other properties for
473 line where IDL is stopped. See also `idlwave-shell-mark-stop-line'."
474 :group 'idlwave-shell-highlighting-and-faces
477 (defcustom idlwave-shell-electric-stop-color "Violet"
478 "*The color for the default face or overlay arrow when stopped."
479 :group 'idlwave-shell-highlighting-and-faces
482 (defcustom idlwave-shell-electric-stop-line-face
484 (copy-face 'modeline 'idlwave-shell-electric-stop-line-face)
485 (set-face-background 'idlwave-shell-electric-stop-line-face
486 idlwave-shell-electric-stop-color)
488 (set-face-foreground 'idlwave-shell-electric-stop-line-face nil)
490 "*The face for `idlwave-shell-stop-line-overlay' when in electric debug mode.
491 Allows you to choose the font, color and other properties for the line
492 where IDL is stopped, when in Electric Debug Mode."
493 :group 'idlwave-shell-highlighting-and-faces
496 (defcustom idlwave-shell-mark-breakpoints t
497 "*Non-nil means, mark breakpoints in the source files.
499 nil Do not mark breakpoints.
500 'face Highlight line with `idlwave-shell-breakpoint-face'.
501 'glyph Red dot at the beginning of line. If the display does not
502 support glyphs, will use 'face instead.
503 t Glyph when possible, otherwise face (same effect as 'glyph)."
504 :group 'idlwave-shell-highlighting-and-faces
506 (const :tag "No marking" nil)
507 (const :tag "Highlight with face" face)
508 (const :tag "Display glyph (red dot)" glyph)
509 (const :tag "Glyph or face." t)))
511 (defvar idlwave-shell-use-breakpoint-glyph t
512 "Obsolete variable. See `idlwave-shell-mark-breakpoints.")
514 (defcustom idlwave-shell-breakpoint-face 'idlwave-shell-bp-face
515 "*The face for breakpoint lines in the source code.
516 Allows you to choose the font, color and other properties for
517 lines which have a breakpoint. See also `idlwave-shell-mark-breakpoints'."
518 :group 'idlwave-shell-highlighting-and-faces
521 (if idlwave-shell-have-new-custom
522 ;; We have the new customize - use it to define a customizable face
523 (defface idlwave-shell-bp-face
524 '((((class color)) (:foreground "Black" :background "Pink"))
526 "Face for highlighting lines-with-breakpoints."
527 :group 'idlwave-shell-highlighting-and-faces)
528 ;; Just copy the underline face to be on the safe side.
529 (copy-face 'underline 'idlwave-shell-bp-face))
531 (defcustom idlwave-shell-expression-face 'secondary-selection
532 "*The face for `idlwave-shell-expression-overlay'.
533 Allows you to choose the font, color and other properties for
534 the expression printed by IDL."
535 :group 'idlwave-shell-highlighting-and-faces
538 (defcustom idlwave-shell-output-face 'secondary-selection
539 "*The face for `idlwave-shell-output-overlay'.
540 Allows you to choose the font, color and other properties for
541 the expression output by IDL."
542 :group 'idlwave-shell-highlighting-and-faces
545 ;;; End user customization variables
547 ;;; External variables
548 (defvar comint-last-input-start)
549 (defvar comint-last-input-end)
551 (defun idlwave-shell-temp-file (type)
552 "Return a temp file, creating it if necessary.
554 TYPE is either 'pro or 'rinfo, and idlwave-shell-temp-pro-file or
555 idlwave-shell-temp-rinfo-save-file is set (respectively)."
558 (or idlwave-shell-temp-rinfo-save-file
559 (setq idlwave-shell-temp-rinfo-save-file
560 (idlwave-shell-make-temp-file idlwave-shell-temp-pro-prefix))))
562 (or idlwave-shell-temp-pro-file
563 (setq idlwave-shell-temp-pro-file
564 (idlwave-shell-make-temp-file idlwave-shell-temp-pro-prefix))))
565 (t (error "Wrong argument (idlwave-shell-temp-file): %s"
566 (symbol-name type)))))
569 (defun idlwave-shell-make-temp-file (prefix)
570 "Create a temporary file."
571 ; Hard coded make-temp-file for Emacs<21
572 (if (fboundp 'make-temp-file)
573 (make-temp-file prefix)
575 (temp-file-dir (if (boundp 'temporary-file-directory)
576 temporary-file-directory
578 (while (condition-case ()
582 (expand-file-name prefix temp-file-dir)))
583 (if (featurep 'xemacs)
584 (write-region "" nil file nil 'silent nil)
585 (write-region "" nil file nil 'silent nil 'excl))
587 (file-already-exists t))
588 ;; the file was somehow created by someone else between
589 ;; `make-temp-name' and `write-region', let's try again.
594 (defvar idlwave-shell-temp-pro-file
596 "Absolute pathname for temporary IDL file for compiling regions")
598 (defvar idlwave-shell-temp-rinfo-save-file
600 "Absolute pathname for temporary IDL file save file for routine_info.
601 This is used to speed up the reloading of the routine info procedure
602 before use by the shell.")
604 (defvar idlwave-shell-dirstack-query "cd,current=___cur & print,___cur"
605 "Command used by `idlwave-shell-resync-dirs' to query IDL for
606 the directory stack.")
608 (defvar idlwave-shell-path-query "print,'PATH:<'+transpose(expand_path(!PATH,/ARRAY))+'>' & print,'SYSDIR:<'+!dir+'>'"
610 "The command which gets !PATH and !DIR info from the shell.")
612 (defvar idlwave-shell-mode-line-info nil
613 "Additional info displayed in the mode line")
615 (defvar idlwave-shell-default-directory nil
616 "The default directory in the idlwave-shell buffer, of outside use.")
618 (defvar idlwave-shell-last-save-and-action-file nil
619 "The last file which was compiled with `idlwave-shell-save-and-...'.")
621 ;; Highlighting uses overlays. When necessary, require the emulation.
622 (if (not (fboundp 'make-overlay))
627 (defvar idlwave-shell-stop-line-overlay nil
628 "The overlay for where IDL is currently stopped.")
629 (defvar idlwave-shell-is-stopped nil)
630 (defvar idlwave-shell-expression-overlay nil
631 "The overlay for where IDL is currently stopped.")
632 (defvar idlwave-shell-output-overlay nil
633 "The overlay for the last IDL output.")
635 ;; If these were already overlays, delete them. This probably means that we
636 ;; are reloading this file.
637 (if (overlayp idlwave-shell-stop-line-overlay)
638 (delete-overlay idlwave-shell-stop-line-overlay))
639 (if (overlayp idlwave-shell-expression-overlay)
640 (delete-overlay idlwave-shell-expression-overlay))
641 (if (overlayp idlwave-shell-output-overlay)
642 (delete-overlay idlwave-shell-output-overlay))
644 ;; Set to nil initially
645 (setq idlwave-shell-stop-line-overlay nil
646 idlwave-shell-expression-overlay nil
647 idlwave-shell-output-overlay nil)
649 ;; Define the shell stop overlay. When left nil, the arrow will be used.
651 ((or (null idlwave-shell-mark-stop-line)
652 (eq idlwave-shell-mark-stop-line 'arrow))
653 ;; Leave the overlay nil
656 ((eq idlwave-shell-mark-stop-line 'face)
657 ;; Try to use a face. If not possible, arrow will be used anyway
658 ;; So who can display faces?
659 (when (or (featurep 'xemacs) ; XEmacs can do also ttys
660 (fboundp 'tty-defined-colors) ; Emacs 21 as well
661 window-system) ; Window systems always
663 (setq idlwave-shell-stop-line-overlay (make-overlay 1 1))
664 (overlay-put idlwave-shell-stop-line-overlay
665 'face idlwave-shell-stop-line-face))))
668 ;; IDLWAVE may decide. Will use a face on window systems, arrow elsewhere
671 (setq idlwave-shell-stop-line-overlay (make-overlay 1 1))
672 (overlay-put idlwave-shell-stop-line-overlay
673 'face idlwave-shell-stop-line-face)))))
675 ;; Now the expression and output overlays
676 (setq idlwave-shell-expression-overlay (make-overlay 1 1))
677 (overlay-put idlwave-shell-expression-overlay
678 'face idlwave-shell-expression-face)
679 (setq idlwave-shell-output-overlay (make-overlay 1 1))
680 (overlay-put idlwave-shell-output-overlay
681 'face idlwave-shell-output-face)
683 (defvar idlwave-shell-bp-query "help,/breakpoints"
684 "Command to obtain list of breakpoints")
686 (defvar idlwave-shell-command-output nil
687 "String for accumulating current command output.")
689 (defvar idlwave-shell-post-command-hook nil
690 "Lisp list expression or function to run when an IDL command is finished.
691 The current command is finished when the IDL prompt is displayed.
692 This is evaluated if it is a list or called with funcall.")
694 (defvar idlwave-shell-sentinel-hook nil
695 "Hook run when the idl process exits.")
697 (defvar idlwave-shell-hide-output nil
698 "If non-nil the process output is not inserted into the output
701 (defvar idlwave-shell-show-if-error nil
702 "If non-nil the process output is inserted into the output buffer if
703 it contains an error message, even if hide-output is non-nil.")
705 (defvar idlwave-shell-accumulation nil
706 "Accumulate last line of output.")
708 (defvar idlwave-shell-command-line-to-execute nil)
709 (defvar idlwave-shell-cleanup-hook nil
710 "List of functions to do cleanup when the shell exits.")
712 (defvar idlwave-shell-pending-commands nil
713 "List of commands to be sent to IDL.
714 Each element of the list is list of \(CMD PCMD HIDE\), where CMD is a
715 string to be sent to IDL and PCMD is a post-command to be placed on
716 `idlwave-shell-post-command-hook'. If HIDE is non-nil, hide the output
717 from command CMD. PCMD and HIDE are optional.")
719 (defun idlwave-shell-buffer ()
720 "Name of buffer associated with IDL process.
721 The name of the buffer is made by surrounding `idlwave-shell-process-name
723 (concat "*" idlwave-shell-process-name "*"))
725 (defvar idlwave-shell-ready nil
726 "If non-nil can send next command to IDL process.")
728 (defvar idlwave-shell-wait-for-output nil
729 "Whether to wait for output to accumulate.")
731 ;;; The following are the types of messages we attempt to catch to
732 ;;; resync our idea of where IDL execution currently is.
735 (defvar idlwave-shell-halt-frame nil
736 "The frame associated with halt/breakpoint messages.")
738 (defvar idlwave-shell-step-frame nil
739 "The frame associated with step messages.")
741 (defvar idlwave-shell-trace-frame nil
742 "The frame associated with trace messages.")
744 (defconst idlwave-shell-halt-messages
745 '("^% Interrupted at:"
748 "^% Stop encountered:"
750 "*A list of regular expressions matching IDL messages.
751 These are the messages containing file and line information where
752 IDL is currently stopped.")
755 (defconst idlwave-shell-halt-messages-re
756 (mapconcat 'identity idlwave-shell-halt-messages "\\|")
757 "The regular expression computed from idlwave-shell-halt-messages")
759 (defconst idlwave-shell-trace-message-re
760 "^% At " ;; First line of a trace message
761 "*A regular expression matching IDL trace messages. These are the
762 messages containing file and line information of a current
765 (defconst idlwave-shell-step-messages
768 "*A list of regular expressions matching stepped execution messages.
769 These are IDL messages containing file and line information where
770 IDL has currently stepped.")
772 (defvar idlwave-shell-break-message "^% Breakpoint at:"
773 "*Regular expression matching an IDL breakpoint message line.")
775 (defconst idlwave-shell-electric-debug-help
776 " ==> IDLWAVE Electric Debug Mode Help <==
778 Break Point Setting and Clearing:
779 b Set breakpoint ([C-u b] for conditional, [C-n b] nth hit, etc.).
780 d Clear nearby breakpoint.
781 a Clear all breakpoints.
782 i Set breakpoint in routine named here.
783 j Set breakpoint at beginning of containing routine.
784 ] Go to next breakpoint in file.
785 [ Go to previous breakpoint in file.
787 Stepping, Continuing, and the Stack:
788 s or SPACE Step, into function calls.
789 n Step, over function calls.
790 k Skip one statement.
791 m Continue to end of function.
792 o Continue past end of function.
793 u Continue to end of block.
794 h Continue to line at cursor position.
795 r Continue execution to next breakpoint, if any.
796 + or = Show higher level in calling stack.
797 - or _ Show lower level in calling stack.
799 Examining Expressions (with prefix for examining the region):
800 p Print expression near point or in region ([C-u p]).
801 ? Help on expression near point or in region ([C-u ?]).
802 x Examine expression near point or in region ([C-u x]) with
803 letter completion of the examine type.
806 q Quit - end debugging session and return to the Shell's main level.
807 v Turn Electric Debugging Mode off (C-c C-d C-v to return).
808 t Print a calling-level traceback in the shell.
810 C-? Show this help menu.")
812 (defvar idlwave-shell-bp-alist)
813 ;(defvar idlwave-shell-post-command-output)
814 (defvar idlwave-shell-sources-alist)
815 (defvar idlwave-shell-menu-def)
816 (defvar idlwave-shell-mode-menu)
817 (defvar idlwave-shell-initial-commands)
818 (defvar idlwave-shell-syntax-error)
819 (defvar idlwave-shell-other-error)
820 (defvar idlwave-shell-error-buffer)
821 (defvar idlwave-shell-error-last)
822 (defvar idlwave-shell-bp-buffer)
823 (defvar idlwave-shell-sources-query)
824 (defvar idlwave-shell-mode-map)
825 (defvar idlwave-shell-calling-stack-index)
827 (defun idlwave-shell-mode ()
828 "Major mode for interacting with an inferior IDL process.
832 RET after the end of the process' output sends the text from the
833 end of process to the end of the current line. RET before end of
834 process output copies the current line (except for the prompt) to the
837 Command history, searching of previous commands, command line
838 editing are available via the comint-mode key bindings, by default
839 mostly on the key `C-c'. Command history is also available with
840 the arrow keys UP and DOWN.
844 TAB and M-TAB do completion of IDL routines, classes and keywords -
845 similar to M-TAB in `idlwave-mode'. In executive commands and
846 strings, it completes file names. Abbreviations are also expanded
847 like in `idlwave-mode'.
851 `\\[idlwave-routine-info]' displays information about an IDL routine near point,
852 just like in `idlwave-mode'. The module used is the one at point or
853 the one whose argument list is being edited.
854 To update IDLWAVE's knowledge about compiled or edited modules, use
855 \\[idlwave-update-routine-info].
856 \\[idlwave-find-module] find the source of a module.
857 \\[idlwave-resolve] tells IDL to compile an unresolved module.
858 \\[idlwave-context-help] shows the online help on the item at
859 point, if online help has been installed.
864 A complete set of commands for compiling and debugging IDL programs
865 is available from the menu. Also keybindings starting with a
866 `C-c C-d' prefix are available for most commands in the *idl* buffer
867 and also in source buffers. The best place to learn about the
868 keybindings is again the menu.
870 On Emacs versions where this is possible, a debugging toolbar is
873 When IDL is halted in the middle of a procedure, the corresponding
874 line of that procedure file is displayed with an overlay in another
875 window. Breakpoints are also highlighted in the source.
877 \\[idlwave-shell-resync-dirs] queries IDL in order to change Emacs current directory
878 to correspond to the IDL process current directory.
880 5. Expression Examination
881 ----------------------
883 Expressions near point can be examined with print,
884 \\[idlwave-shell-print] or \\[idlwave-shell-mouse-print] with the
885 mouse, help, \\[idlwave-shell-help-expression] or
886 \\[idlwave-shell-mouse-help] with the mouse, or with a
887 configureable set of custom examine commands using
888 \\[idlwave-shell-examine-select]. The mouse examine commands can
889 also work by click and drag, to select an expression for
894 Turning on `idlwave-shell-mode' runs `comint-mode-hook' and
895 `idlwave-shell-mode-hook' (in that order).
897 7. Documentation and Customization
898 -------------------------------
899 Info documentation for this package is available. Use \\[idlwave-info]
900 to display (complain to your sysadmin if that does not work).
901 For Postscript and HTML versions of the documentation, check IDLWAVE's
902 homepage at `http://idlwave.org'.
903 IDLWAVE has customize support - see the group `idlwave'.
907 \\{idlwave-shell-mode-map}"
910 (idlwave-setup) ; Make sure config files and paths, etc. are available.
911 (unless (file-name-absolute-p idlwave-shell-command-history-file)
912 (setq idlwave-shell-command-history-file
913 (expand-file-name idlwave-shell-command-history-file
914 idlwave-config-directory)))
916 ;; We don't do `kill-all-local-variables' here, because this is done by
918 (setq comint-prompt-regexp idlwave-shell-prompt-pattern)
919 (setq comint-process-echoes t)
921 ;; Can not use history expansion because "!" is used for system variables.
922 (setq comint-input-autoexpand nil)
923 ; (setq comint-input-ring-size 64)
924 (make-local-variable 'comint-completion-addsuffix)
925 (set (make-local-variable 'completion-ignore-case) t)
926 (setq comint-completion-addsuffix '("/" . ""))
927 (setq comint-input-ignoredups t)
928 (setq major-mode 'idlwave-shell-mode)
929 (setq mode-name "IDL-Shell")
930 (setq idlwave-shell-mode-line-info nil)
931 (setq mode-line-format
934 mode-line-buffer-identification
943 idlwave-shell-mode-line-info
945 (line-number-mode "L%l--")
946 (column-number-mode "C%c--")
949 ;; (make-local-variable 'idlwave-shell-bp-alist)
950 (setq idlwave-shell-halt-frame nil
951 idlwave-shell-trace-frame nil
952 idlwave-shell-command-output nil
953 idlwave-shell-step-frame nil)
954 (idlwave-shell-display-line nil)
955 (setq idlwave-shell-calling-stack-index 0)
956 (setq idlwave-shell-only-prompt-pattern
957 (concat "\\`[ \t\n]*"
958 (substring idlwave-shell-prompt-pattern 1)
961 (when idlwave-shell-query-for-class
962 (add-to-list (make-local-variable 'idlwave-determine-class-special)
963 'idlwave-shell-get-object-class)
964 (setq idlwave-store-inquired-class t))
966 ;; Make sure comint-last-input-end does not go to beginning of
967 ;; buffer (in case there were other processes already in this buffer).
968 (set-marker comint-last-input-end (point))
969 (setq idlwave-idlwave_routine_info-compiled nil)
970 (setq idlwave-shell-ready nil)
971 (setq idlwave-shell-wait-for-output nil)
972 (setq idlwave-shell-bp-alist nil)
973 (idlwave-shell-update-bp-overlays) ; Throw away old overlays
974 (setq idlwave-shell-sources-alist nil)
975 (setq idlwave-shell-default-directory default-directory)
976 (setq idlwave-shell-hide-output nil)
978 ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
979 (make-local-hook 'kill-buffer-hook)
980 (add-hook 'kill-buffer-hook 'idlwave-shell-kill-shell-buffer-confirm
982 (add-hook 'kill-buffer-hook 'idlwave-shell-delete-temp-files nil 'local)
983 (add-hook 'kill-emacs-hook 'idlwave-shell-delete-temp-files)
984 (use-local-map idlwave-shell-mode-map)
985 (easy-menu-add idlwave-shell-mode-menu idlwave-shell-mode-map)
987 ;; Set the optional comint variables
988 (when idlwave-shell-comint-settings
989 (let ((list idlwave-shell-comint-settings) entry)
990 (while (setq entry (pop list))
991 (set (make-local-variable (car entry)) (cdr entry)))))
994 (unless (memq 'comint-carriage-motion
995 (default-value 'comint-output-filter-functions))
996 ;; Strip those pesky ctrl-m's.
997 (add-hook 'comint-output-filter-functions
999 (when (string-match "\r" string)
1000 (let ((pmark (process-mark (get-buffer-process
1001 (current-buffer)))))
1003 ;; bare CR -> delete preceding line
1004 (goto-char comint-last-output-start)
1005 (while (search-forward "\r" pmark t)
1006 (delete-region (point) (line-beginning-position)))))))
1008 (add-hook 'comint-output-filter-functions 'comint-strip-ctrl-m nil 'local))
1010 ;; Python-mode, bundled with many Emacs installs, quite cavalierly
1011 ;; adds this function to the global default hook. It interferes
1012 ;; with overlay-arrows.
1013 (remove-hook 'comint-output-filter-functions 'py-pdbtrack-track-stack-file)
1016 ;; IDLWAVE syntax, and turn on abbreviations
1017 (setq local-abbrev-table idlwave-mode-abbrev-table)
1018 (set-syntax-table idlwave-mode-syntax-table)
1019 (set (make-local-variable 'comment-start) ";")
1020 (setq abbrev-mode t)
1022 ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
1023 (make-local-hook 'post-command-hook)
1024 (add-hook 'post-command-hook 'idlwave-command-hook nil t)
1026 ;; Read the command history?
1027 (when (and idlwave-shell-save-command-history
1028 (stringp idlwave-shell-command-history-file))
1029 (set (make-local-variable 'comint-input-ring-file-name)
1030 idlwave-shell-command-history-file)
1031 (if (file-regular-p idlwave-shell-command-history-file)
1032 (comint-read-input-ring)))
1034 ;; Turn off the non-debug toolbar buttons (open,save,etc.)
1035 (set (make-local-variable 'tool-bar-map) nil)
1038 (run-hooks 'idlwave-shell-mode-hook)
1039 (idlwave-shell-send-command idlwave-shell-initial-commands nil 'hide)
1040 ;; Define a system variable which knows the version of IDLWAVE
1041 (idlwave-shell-send-command
1042 (format "defsysv,'!idlwave_version','%s',1" idlwave-mode-version)
1044 ;; Get the paths if they weren't read in from file
1045 (if (and (not idlwave-path-alist)
1046 (or (not (stringp idlwave-system-directory))
1047 (eq (length idlwave-system-directory) 0)))
1048 (idlwave-shell-send-command idlwave-shell-path-query
1049 'idlwave-shell-get-path-info
1052 (defun idlwave-shell-get-path-info (&optional no-write)
1053 "Get the path lists, writing to file unless NO-WRITE is set."
1054 (let* ((rpl (idlwave-shell-path-filter))
1057 (old-path-alist idlwave-path-alist))
1059 (setq idlwave-system-directory sysdir)
1060 (put 'idlwave-system-directory 'from-shell t))
1061 ;; Preserve any existing flags
1062 (setq idlwave-path-alist
1064 (let ((old-entry (assoc x old-path-alist)))
1066 (cons x (cdr old-entry))
1069 (put 'idlwave-path-alist 'from-shell t)
1070 (if idlwave-path-alist
1071 (if (and idlwave-auto-write-paths
1072 (not idlwave-library-path)
1074 (idlwave-write-paths))
1076 (setq idlwave-path-alist old-path-alist))))
1078 (if (not (fboundp 'idl-shell))
1079 (fset 'idl-shell 'idlwave-shell))
1081 (defvar idlwave-shell-idl-wframe nil
1082 "Frame for displaying the idl shell window.")
1083 (defvar idlwave-shell-display-wframe nil
1084 "Frame for displaying the idl source files.")
1086 (defvar idlwave-shell-calling-stack-index 0)
1087 (defvar idlwave-shell-calling-stack-routine nil)
1089 (defun idlwave-shell-source-frame ()
1090 "Return the frame to be used for source display."
1091 (if idlwave-shell-use-dedicated-frame
1092 ;; We want separate frames for source and shell
1093 (if (frame-live-p idlwave-shell-display-wframe)
1094 ;; The frame exists, so we use it.
1095 idlwave-shell-display-wframe
1096 ;; The frame does not exist. We use the current frame.
1097 ;; However, if the current is the shell frame, we make a new frame,
1098 ;; or recycle the first existing visible frame
1099 (setq idlwave-shell-display-wframe
1100 (if (eq (selected-frame) idlwave-shell-idl-wframe)
1102 (let ((flist (visible-frame-list))
1103 (frame (selected-frame)))
1106 (if (not (eq (car flist)
1107 idlwave-shell-idl-wframe))
1108 (throw 'exit (car flist))
1109 (setq flist (cdr flist))))))
1111 (selected-frame))))))
1113 (defun idlwave-shell-shell-frame ()
1114 "Return the frame to be used for the shell buffer."
1115 (if idlwave-shell-use-dedicated-frame
1116 ;; We want a dedicated frame
1117 (if (frame-live-p idlwave-shell-idl-wframe)
1118 ;; It does exist, so we use it.
1119 idlwave-shell-idl-wframe
1120 ;; It does not exist. Check if we have a source frame.
1121 (if (not (frame-live-p idlwave-shell-display-wframe))
1122 ;; We do not have a source frame, so we use this one.
1123 (setq idlwave-shell-display-wframe (selected-frame)))
1124 ;; Return a new frame
1125 (setq idlwave-shell-idl-wframe
1126 (make-frame idlwave-shell-frame-parameters)))))
1129 (defun idlwave-shell (&optional arg quick)
1130 "Run an inferior IDL, with I/O through buffer `(idlwave-shell-buffer)'.
1131 If buffer exists but shell process is not running, start new IDL.
1132 If buffer exists and shell process is running, just switch to the buffer.
1134 When called with a prefix ARG, or when `idlwave-shell-use-dedicated-frame'
1135 is non-nil, the shell buffer and the source buffers will be in
1138 The command to run comes from variable `idlwave-shell-explicit-file-name',
1139 with options taken from `idlwave-shell-command-line-options'.
1141 The buffer is put in `idlwave-shell-mode', providing commands for sending
1142 input and controlling the IDL job. See help on `idlwave-shell-mode'.
1143 See also the variable `idlwave-shell-prompt-pattern'.
1145 \(Type \\[describe-mode] in the shell buffer for a list of commands.)"
1149 (let ((idlwave-shell-use-dedicated-frame nil))
1151 (delete-other-windows))
1152 (and idlwave-shell-use-dedicated-frame
1153 (setq idlwave-shell-idl-wframe (selected-frame)))
1154 (add-hook 'idlwave-shell-sentinel-hook
1155 'save-buffers-kill-emacs t))
1157 ;; A non-nil arg means, we want a dedicated frame. This will last
1158 ;; for the current editing session.
1159 (if arg (setq idlwave-shell-use-dedicated-frame t))
1160 (if (equal arg '(16)) (setq idlwave-shell-use-dedicated-frame nil))
1162 ;; Check if the process still exists. If not, create it.
1163 (unless (comint-check-proc (idlwave-shell-buffer))
1164 (let* ((prg (or idlwave-shell-explicit-file-name "idl"))
1165 (buf (apply 'make-comint
1166 idlwave-shell-process-name prg nil
1167 (if (stringp idlwave-shell-command-line-options)
1168 (idlwave-split-string
1169 idlwave-shell-command-line-options)
1170 idlwave-shell-command-line-options)))
1171 (process (get-buffer-process buf)))
1172 (setq idlwave-idlwave_routine_info-compiled nil)
1173 (set-process-filter process 'idlwave-shell-filter)
1174 (set-process-sentinel process 'idlwave-shell-sentinel)
1176 (idlwave-shell-mode)))
1177 (let ((window (idlwave-display-buffer (idlwave-shell-buffer) nil
1178 (idlwave-shell-shell-frame)))
1179 (current-window (selected-window)))
1180 (select-window window)
1181 (goto-char (point-max))
1182 (select-window current-window)
1183 (if idlwave-shell-ready
1184 (raise-frame (window-frame window)))
1185 (if (eq (selected-frame) (window-frame window))
1186 (select-window window))))
1187 ;; Save the paths at the end
1188 (add-hook 'idlwave-shell-sentinel-hook
1191 idlwave-auto-write-paths
1193 (not idlwave-library-path)
1194 (get 'idlwave-path-alist 'from-shell))
1195 (idlwave-write-paths)))))
1197 (defun idlwave-shell-recenter-shell-window (&optional arg)
1198 "Run `idlwave-shell', but make sure the current window stays selected."
1200 (let ((window (selected-window)))
1202 (select-window window)))
1204 (defun idlwave-shell-hide-p (type &optional list)
1205 "Whether to hide this type of command.
1206 Return either nil or 'hide."
1207 (let ((list (or list idlwave-shell-show-commands)))
1209 (if (not (memq type list)) 'hide))))
1211 (defun idlwave-shell-add-or-remove-show (type)
1212 "Add or remove a show command from the list."
1213 (if (listp idlwave-shell-show-commands)
1214 (setq idlwave-shell-show-commands
1215 (if (memq type idlwave-shell-show-commands)
1216 (delq type idlwave-shell-show-commands)
1217 (add-to-list'idlwave-shell-show-commands type)))
1218 (setq idlwave-shell-show-commands (list type))))
1221 (defun idlwave-shell-send-command (&optional cmd pcmd hide preempt
1223 "Send a command to IDL process.
1225 \(CMD PCMD HIDE\) are placed at the end of `
1226 idlwave-shell-pending-commands'. If IDL is ready the first command,
1227 CMD, in `idlwave-shell-pending-commands' is sent to the IDL process.
1229 If optional second argument PCMD is non-nil it will be placed on
1230 `idlwave-shell-post-command-hook' when CMD is executed.
1232 If the optional third argument HIDE is non-nil, then hide output from
1233 CMD, unless it is the symbol 'mostly, in which case only output
1234 beginning with \"%\" is hidden, and all other output (i.e., the
1235 results of a PRINT command), is shown. This helps with, e.g.,
1236 stepping through code with output.
1238 If optional fourth argument PREEMPT is non-nil CMD is put at front of
1239 `idlwave-shell-pending-commands'. If PREEMPT is 'wait, wait for all
1240 output to complete and the next prompt to arrive before returning
1241 \(useful if you need an answer now\). IDL is considered ready if the
1242 prompt is present and if `idlwave-shell-ready' is non-nil.
1244 If SHOW-IF-ERROR is non-nil, show the output it it contains an error
1245 message, independent of what HIDE is set to."
1247 ; (setq hide nil) ; FIXME: turn this on for debugging only
1250 ; (message "SENDING Pending commands: %s"
1251 ; (prin1-to-string idlwave-shell-pending-commands)))
1252 ; (message "SENDING %s|||%s" cmd pcmd))
1253 (if (and (symbolp idlwave-shell-show-commands)
1254 (eq idlwave-shell-show-commands 'everything))
1256 (let ((save-buffer (current-buffer))
1258 ;; Get or make the buffer and its process
1259 (if (or (not (setq buf (get-buffer (idlwave-shell-buffer))))
1260 (not (setq proc (get-buffer-process buf))))
1261 (if (not idlwave-shell-automatic-start)
1263 (substitute-command-keys
1264 "You need to first start an IDL shell with \\[idlwave-shell]"))
1265 (idlwave-shell-recenter-shell-window)
1266 (setq buf (get-buffer (idlwave-shell-buffer)))
1267 (if (or (not (setq buf (get-buffer (idlwave-shell-buffer))))
1268 (not (setq proc (get-buffer-process buf))))
1270 (error "Problem with autostarting IDL shell"))))
1271 (when (or cmd idlwave-shell-pending-commands)
1273 ;; To make this easy, always push CMD onto pending commands
1275 (setq idlwave-shell-pending-commands
1278 (append (list (list cmd pcmd hide show-if-error))
1279 idlwave-shell-pending-commands)
1281 (append idlwave-shell-pending-commands
1282 (list (list cmd pcmd hide show-if-error))))))
1283 ;; Check if IDL ready
1284 (let ((save-point (point-marker)))
1285 (goto-char (process-mark proc))
1286 (if (and idlwave-shell-ready
1287 ;; Check for IDL prompt
1290 ;; (beginning-of-line) ; Changed for Emacs 21
1291 (looking-at idlwave-shell-prompt-pattern)
1292 (goto-char (process-mark proc))))
1293 ;; IDL ready for command, execute it
1294 (let* ((lcmd (car idlwave-shell-pending-commands))
1298 (show-if-error (nth 3 lcmd)))
1299 ;; If this is an executive command, reset the stack pointer
1300 (if (eq (string-to-char cmd) ?.)
1301 (setq idlwave-shell-calling-stack-index 0))
1303 (setq idlwave-shell-post-command-hook pcmd)
1305 (setq idlwave-shell-hide-output hide)
1307 (setq idlwave-shell-show-if-error show-if-error)
1309 (setq idlwave-shell-pending-commands
1310 (cdr idlwave-shell-pending-commands))
1311 ;; Send command for execution
1312 (set-marker comint-last-input-start (point))
1313 (set-marker comint-last-input-end (point))
1314 (comint-simple-send proc cmd)
1315 (setq idlwave-shell-ready nil)
1316 (when (equal preempt 'wait) ; Get all the output at once
1317 (setq idlwave-shell-wait-for-output t)
1318 (accept-process-output proc))))
1319 (goto-char save-point))
1320 (set-buffer save-buffer))))
1322 (defun idlwave-shell-send-char (c &optional no-error)
1323 "Send one character to the shell, without a newline."
1324 (interactive "cChar to send to IDL: ")
1325 (let ((errf (if (interactive-p) 'error 'message))
1327 (if (or (not (setq buf (get-buffer (idlwave-shell-buffer))))
1328 (not (setq proc (get-buffer-process buf))))
1329 (funcall errf "Shell is not running"))
1331 (funcall errf "Abort")
1332 (comint-send-string proc (char-to-string c)))))
1334 (defvar idlwave-shell-char-mode-active)
1335 (defun idlwave-shell-input-mode-magic (string)
1336 "Check STRING for magic words and toggle character input mode.
1337 See also the variable `idlwave-shell-input-mode-spells'."
1339 ((string-match (car idlwave-shell-input-mode-spells) string)
1340 (call-interactively 'idlwave-shell-send-char))
1341 ((and (boundp 'idlwave-shell-char-mode-active)
1342 (string-match (nth 2 idlwave-shell-input-mode-spells) string))
1343 (setq idlwave-shell-char-mode-active 'exit))
1344 ((string-match (nth 1 idlwave-shell-input-mode-spells) string)
1345 ;; Set a timer which will soon start the character loop
1346 (if (fboundp 'start-itimer)
1347 (start-itimer "IDLWAVE Char Mode" 'idlwave-shell-char-mode-loop 0.5
1348 nil nil t 'no-error)
1349 (run-at-time 0.5 nil 'idlwave-shell-char-mode-loop 'no-error)))))
1351 (defvar keyboard-quit)
1352 (defun idlwave-shell-char-mode-loop (&optional no-error)
1353 "Enter a loop which accepts single characters and sends them to IDL.
1354 Characters are sent one by one, without newlines. The loop is blocking
1355 and intercepts all input events to Emacs. You can use this command
1356 to interact with the IDL command GET_KBRD.
1357 The loop can be aborted by typing `C-g'. The loop also exits automatically
1358 when the IDL prompt gets displayed again after the current IDL command."
1361 ;; First check if there is a shell waiting for input
1362 (let ((idlwave-shell-char-mode-active t)
1363 (errf (if no-error 'message 'error))
1365 (if (or (not (setq buf (get-buffer (idlwave-shell-buffer))))
1366 (not (setq proc (get-buffer-process buf))))
1367 (funcall errf "Shell is not running"))
1368 (if idlwave-shell-ready
1369 (funcall errf "No IDL program seems to be waiting for input"))
1371 ;; OK, start the loop
1372 (message "Character mode on: Sending single chars (`C-g' to exit)")
1377 ;; FIXME: Is it too dangerous to inhibit quit here?
1378 (let ((inhibit-quit t))
1379 ;; We wait and check frequently if we should abort
1380 (while (sit-for 0.3)
1381 (and idlwave-shell-ready
1382 (throw 'exit "Character mode off (prompt displayed)"))
1383 (and (eq idlwave-shell-char-mode-active 'exit)
1384 (throw 'exit "Character mode off (closing spell incantation)")))
1385 ;; Interpret input as a character - ignore non-char input
1387 (setq c (read-char))
1388 (error (ding) (throw 'exit "Character mode off")))
1390 ((null c) ; Non-char event: ignore
1392 ((equal c ?\C-g) ; Abort the loop
1393 (setq keyboard-quit nil)
1395 (throw 'exit "Character mode off (keyboard quit)"))
1396 (t ; Send the character and continue the loop
1397 (comint-send-string proc (char-to-string c))))
1398 (and (eq idlwave-shell-char-mode-active 'exit)
1399 (throw 'exit "Single char loop exited"))))))))
1401 (defun idlwave-shell-move-or-history (up &optional arg)
1402 "When in last line of process buffer, do `comint-previous-input'.
1403 Otherwise just move the line. Move down unless UP is non-nil."
1404 (let* ((proc-pos (marker-position
1405 (process-mark (get-buffer-process (current-buffer)))))
1407 (arg (if up arg (- arg))))
1408 (if (eq t idlwave-shell-arrows-do-history) (goto-char proc-pos))
1409 (if (and idlwave-shell-arrows-do-history
1410 (>= (1+ (save-excursion (end-of-line) (point))) proc-pos))
1412 ;;(goto-char proc-pos)
1413 (goto-char (point-max))
1414 ;;(and (not (eolp)) (kill-line nil))
1415 (comint-previous-input arg))
1416 (previous-line arg))))
1418 (defun idlwave-shell-up-or-history (&optional arg)
1419 "When in last line of process buffer, move to previous input.
1420 Otherwise just go up one line."
1422 (idlwave-shell-move-or-history t arg))
1424 (defun idlwave-shell-down-or-history (&optional arg)
1425 "When in last line of process buffer, move to next input.
1426 Otherwise just go down one line."
1428 (idlwave-shell-move-or-history nil arg))
1430 ;; Newer versions of comint.el changed the name of comint-filter to
1431 ;; comint-output-filter.
1432 (defun idlwave-shell-comint-filter (process string) nil)
1433 (if (fboundp 'comint-output-filter)
1434 (fset 'idlwave-shell-comint-filter (symbol-function 'comint-output-filter))
1435 (fset 'idlwave-shell-comint-filter (symbol-function 'comint-filter)))
1437 (defun idlwave-shell-is-running ()
1438 "Return t if the shell process is running."
1439 (eq (process-status idlwave-shell-process-name) 'run))
1441 (defvar idlwave-shell-only-prompt-pattern nil)
1442 (defun idlwave-shell-filter-hidden-output (output)
1443 "Filter hidden output, leaving the good stuff.
1445 Remove everything to the first newline, and all lines with % in front
1446 of them, with optional follow-on lines starting with two spaces. This
1447 works well enough, since any print output typically arrives before
1448 error messages, etc."
1449 (setq output (substring output (string-match "\n" output)))
1450 (while (string-match "\\(\n\\|\\`\\)%.*\\(\n .*\\)*" output)
1451 (setq output (replace-match "" nil t output)))
1453 (string-match idlwave-shell-only-prompt-pattern output)
1456 (defvar idlwave-shell-hidden-output-buffer " *idlwave-shell-hidden-output*"
1457 "Buffer containing hidden output from IDL commands.")
1459 (defun idlwave-shell-filter (proc string)
1460 "Watch for IDL prompt and filter incoming text.
1461 When the IDL prompt is received executes `idlwave-shell-post-command-hook'
1462 and then calls `idlwave-shell-send-command' for any pending commands."
1463 ;; We no longer do the cleanup here - this is done by the process sentinel
1464 (when (eq (process-status idlwave-shell-process-name) 'run)
1465 ;; OK, process is still running, so we can use it.
1466 (let ((data (match-data)) p full-output)
1469 ;; Ring the bell if necessary
1470 (while (setq p (string-match "\C-G" string))
1472 (aset string p ?\C-j ))
1473 (if idlwave-shell-hide-output
1475 (while (setq p (string-match "\C-M" string))
1476 (aset string p ?\ ))
1478 (get-buffer-create idlwave-shell-hidden-output-buffer))
1479 (goto-char (point-max))
1481 (idlwave-shell-comint-filter proc string))
1482 ;; Watch for magic - need to accumulate the current line
1483 ;; since it may not be sent all at once.
1484 (if (string-match "\n" string)
1486 (if idlwave-shell-use-input-mode-magic
1487 (idlwave-shell-input-mode-magic
1488 (concat idlwave-shell-accumulation string)))
1489 (setq idlwave-shell-accumulation
1491 (progn (string-match "\\(.*[\n\r]+\\)*"
1494 (setq idlwave-shell-accumulation
1495 (concat idlwave-shell-accumulation string)))
1499 ; (save-excursion (set-buffer
1500 ; (get-buffer-create "*idlwave-shell-output*"))
1501 ; (goto-char (point-max))
1502 ; (insert "\nSTRING===>\n" string "\n<====\n"))
1504 ;; Check for prompt in current accumulating output
1505 (if (setq idlwave-shell-ready
1506 (string-match idlwave-shell-prompt-pattern
1507 idlwave-shell-accumulation))
1509 ;; Gather the command output
1510 (if idlwave-shell-hide-output
1512 (set-buffer idlwave-shell-hidden-output-buffer)
1513 (setq full-output (buffer-string))
1514 (goto-char (point-max))
1515 (re-search-backward idlwave-shell-prompt-pattern nil t)
1516 (goto-char (match-end 0))
1517 (setq idlwave-shell-command-output
1518 (buffer-substring (point-min) (point)))
1519 (delete-region (point-min) (point)))
1520 (setq idlwave-shell-command-output
1521 (with-current-buffer (process-buffer proc)
1524 (goto-char (process-mark proc))
1525 (beginning-of-line nil)
1527 comint-last-input-end))))
1529 ;; Scan for state and do post commands - bracket
1530 ;; them with idlwave-shell-ready=nil since they may
1531 ;; call idlwave-shell-send-command themselves.
1532 (let ((idlwave-shell-ready nil))
1533 (idlwave-shell-scan-for-state)
1534 ;; Show the output in the shell if it contains an error
1535 (if idlwave-shell-hide-output
1536 (if (and idlwave-shell-show-if-error
1537 (eq idlwave-shell-current-state 'error))
1538 (idlwave-shell-comint-filter proc full-output)
1539 ;; If it's only *mostly* hidden, filter % lines,
1540 ;; and show anything that remains
1541 (if (eq idlwave-shell-hide-output 'mostly)
1543 (idlwave-shell-filter-hidden-output
1546 (idlwave-shell-comint-filter
1549 ;; Call the post-command hook
1550 (if (listp idlwave-shell-post-command-hook)
1551 (eval idlwave-shell-post-command-hook)
1552 (funcall idlwave-shell-post-command-hook))
1554 ;; Reset to default state for next command.
1555 ;; Also we do not want to find this prompt again.
1556 (setq idlwave-shell-accumulation nil
1557 idlwave-shell-command-output nil
1558 idlwave-shell-post-command-hook nil
1559 idlwave-shell-hide-output nil
1560 idlwave-shell-show-if-error nil
1561 idlwave-shell-wait-for-output nil))
1562 ;; Done with post command. Do pending command if
1564 (idlwave-shell-send-command))
1565 ;; We didn't get the prompt yet... maybe accept more output
1566 (when idlwave-shell-wait-for-output
1568 ; (save-excursion (set-buffer
1569 ; (get-buffer-create "*idlwave-shell-output*"))
1570 ; (goto-char (point-max))
1571 ; (insert "\n<=== WAITING ON OUTPUT ==>\n"))
1572 (accept-process-output proc 1))))
1573 (store-match-data data)))))
1575 (defun idlwave-shell-sentinel (process event)
1576 "The sentinel function for the IDLWAVE shell process."
1577 (let* ((buf (idlwave-shell-buffer))
1578 (win (get-buffer-window buf)))
1579 (when (get-buffer buf)
1581 (set-buffer (idlwave-shell-buffer))
1582 (goto-char (point-max))
1583 (insert (format "\n\n Process %s %s" process event))
1584 (if (and idlwave-shell-save-command-history
1585 (stringp idlwave-shell-command-history-file))
1587 (comint-write-input-ring)
1590 (when (and (> (length (frame-list)) 1)
1591 (frame-live-p idlwave-shell-idl-wframe))
1592 (delete-frame idlwave-shell-idl-wframe)
1593 (setq idlwave-shell-idl-wframe nil
1594 idlwave-shell-display-wframe nil))
1595 (when (and (window-live-p win)
1596 (not (one-window-p 'nomini)))
1597 (delete-window win))
1598 (idlwave-shell-cleanup)
1599 ;; Run the hook, if possible in the shell buffer.
1600 (if (get-buffer buf)
1603 (run-hooks 'idlwave-shell-sentinel-hook))
1604 (run-hooks 'idlwave-shell-sentinel-hook))))
1606 (defvar idlwave-shell-current-state nil)
1607 (defun idlwave-shell-scan-for-state ()
1608 "Scan for state info. Looks for messages in output from last IDL
1609 command indicating where IDL has stopped. The types of messages we are
1610 interested in are execution halted, stepped, breakpoint, interrupted
1611 at and trace messages. For breakpoint messages process any attached
1612 count or command parameters. Update the stop line if a message is
1613 found. The variable `idlwave-shell-current-state' is set to 'error,
1614 'halt, or 'breakpoint, which describes the status, or nil for none of
1618 ;; Make sure we have output
1619 ((not idlwave-shell-command-output))
1621 ;; First Priority: Syntax and other errors
1623 (string-match idlwave-shell-syntax-error
1624 idlwave-shell-command-output)
1625 (string-match idlwave-shell-other-error
1626 idlwave-shell-command-output))
1629 (get-buffer-create idlwave-shell-error-buffer))
1631 (insert idlwave-shell-command-output)
1632 (goto-char (point-min))
1633 (setq idlwave-shell-error-last (point)))
1634 (setq idlwave-shell-current-state 'error)
1635 (idlwave-shell-goto-next-error))
1637 ;; Second Priority: Halting errors
1638 ((string-match idlwave-shell-halting-error
1639 idlwave-shell-command-output)
1640 ;; Grab the file and line state info.
1641 (setq idlwave-shell-calling-stack-index 0)
1642 (setq idlwave-shell-halt-frame
1643 (idlwave-shell-parse-line
1644 (substring idlwave-shell-command-output
1645 (match-beginning 2)))
1646 idlwave-shell-current-state 'error)
1647 (idlwave-shell-display-line (idlwave-shell-pc-frame)))
1649 ;; Third Priority: Various types of innocuous HALT and
1650 ;; TRACEBACK messages.
1651 ((or (setq trace (string-match idlwave-shell-trace-message-re
1652 idlwave-shell-command-output))
1653 (string-match idlwave-shell-halt-messages-re
1654 idlwave-shell-command-output))
1655 ;; Grab the file and line state info.
1656 (setq idlwave-shell-calling-stack-index 0)
1657 (setq idlwave-shell-halt-frame
1658 (idlwave-shell-parse-line
1659 (substring idlwave-shell-command-output (match-end 0))))
1660 (setq idlwave-shell-current-state 'halt)
1661 ;; Don't debug trace messages
1662 (idlwave-shell-display-line (idlwave-shell-pc-frame) nil
1663 (if trace 'no-debug)))
1665 ;; Fourth Priority: Breakpoints
1666 ((string-match idlwave-shell-break-message
1667 idlwave-shell-command-output)
1668 (setq idlwave-shell-calling-stack-index 0)
1669 (setq idlwave-shell-halt-frame
1670 (idlwave-shell-parse-line
1671 (substring idlwave-shell-command-output (match-end 0))))
1672 ;; We used to count hits on breakpoints
1673 ;; this is no longer supported since IDL breakpoints
1674 ;; have learned counting.
1675 ;; Do breakpoint command processing
1678 (nth 0 idlwave-shell-halt-frame)
1679 (nth 1 idlwave-shell-halt-frame))
1680 idlwave-shell-bp-alist)))
1682 (let ((cmd (idlwave-shell-bp-get bp 'cmd)))
1683 (if cmd ;; Execute any breakpoint command
1684 (if (listp cmd) (eval cmd) (funcall cmd))))
1685 ;; A breakpoint that we did not know about - perhaps it was
1686 ;; set by the user... Let's update our list.
1687 (idlwave-shell-bp-query)))
1688 (setq idlwave-shell-current-state 'breakpoint)
1689 (idlwave-shell-display-line (idlwave-shell-pc-frame)))
1692 ;; Last Priority: Can't Step errors
1693 ((string-match idlwave-shell-cant-continue-error
1694 idlwave-shell-command-output)
1695 (setq idlwave-shell-current-state 'breakpoint))
1697 ;; Otherwise, no particular state
1698 (t (setq idlwave-shell-current-state nil)))))
1700 (defvar idlwave-shell-error-buffer " *idlwave-shell-errors*"
1701 "Buffer containing syntax errors from IDL compilations.")
1703 ;; FIXME: the following two variables do not currently allow line breaks
1704 ;; in module and file names. I am not sure if it will be necessary to
1705 ;; change this. Currently it seems to work the way it is.
1706 (defvar idlwave-shell-syntax-error
1707 "^% Syntax error.\\s-*\n\\s-*At:\\s-*\\(.*\\),\\s-*Line\\s-*\\(.*\\)"
1708 "A regular expression to match an IDL syntax error.
1709 The 1st pair matches the file name, the second pair matches the line
1712 (defvar idlwave-shell-other-error
1713 "^% .*\n\\s-*At:\\s-*\\(.*\\),\\s-*Line\\s-*\\(.*\\)"
1714 "A regular expression to match any IDL error.")
1716 (defvar idlwave-shell-halting-error
1717 "^% .*\n\\([^%].*\n\\)*% Execution halted at:\\(\\s-*\\S-+\\s-*[0-9]+\\s-*.*\\)\n"
1718 "A regular expression to match errors which halt execution.")
1720 (defvar idlwave-shell-cant-continue-error
1721 "^% Can't continue from this point.\n"
1722 "A regular expression to match errors stepping errors.")
1724 (defvar idlwave-shell-file-line-message
1726 "\\(" ; program name group (1)
1727 "\\$MAIN\\$\\|" ; main level routine
1728 "\\<[a-zA-Z][a-zA-Z0-9_$:]*" ; start with a letter followed by [..]
1729 "\\([ \t]*\n[ \t]*[a-zA-Z0-9_$:]+\\)*"; continuation lines program name (2)
1730 "\\)" ; end program name group (1)
1731 "[ \t\n]+" ; white space
1732 "\\(" ; line number group (3)
1733 "[0-9]+" ; the line number (the fix point)
1734 "\\([ \t]*\n[ \t]*[0-9]+\\)*" ; continuation lines number (4)
1735 "\\)" ; end line number group (3)
1736 "[ \t\n]+" ; white space
1737 "\\(" ; file name group (5)
1738 "[^ \t\n]+" ; file names can contain any non-white
1739 "\\([ \t]*\n[ \t]*[^ \t\n]+\\)*" ; continuation lines file name (6)
1740 "\\)" ; end line number group (5)
1742 "*A regular expression to parse out the file name and line number.
1743 The 1st group should match the subroutine name.
1744 The 3rd group is the line number.
1745 The 5th group is the file name.
1746 All parts may contain linebreaks surrounded by spaces. This is important
1747 in IDL5 which inserts random linebreaks in long module and file names.")
1749 (defun idlwave-shell-parse-line (string &optional skip-main)
1750 "Parse IDL message for the subroutine, file name and line number.
1751 We need to work hard here to remove the stupid line breaks inserted by
1752 IDL5. These line breaks can be right in the middle of procedure
1754 It is very difficult to come up with a robust solution. This one seems
1755 to be pretty good though.
1757 Here is in what ways it improves over the previous solution:
1759 1. The procedure name can be split and will be restored.
1760 2. The number can be split. I have never seen this, but who knows.
1761 3. We do not require the `.pro' extension for files.
1763 This function can still break when the file name ends on a end line
1764 and the message line contains an additional line with garbage. Then
1765 the first part of that garbage will be added to the file name.
1766 However, the function checks the existence of the files with and
1767 without this last part - thus the function only breaks if file name
1768 plus garbage match an existing regular file. This is hopefully very
1771 If optional arg SKIP-MAIN is non-nil, don't parse $MAIN$ routine stop
1774 (let (number procedure file)
1775 (when (and (not (if skip-main (string-match ":\\s-*\\$MAIN" string)))
1776 (string-match idlwave-shell-file-line-message string))
1777 (setq procedure (match-string 1 string)
1778 number (match-string 3 string)
1779 file (match-string 5 string))
1781 ;; Repair the strings
1782 (setq procedure (idlwave-shell-repair-string procedure))
1783 (setq number (idlwave-shell-repair-string number))
1784 (setq file (idlwave-shell-repair-file-name file))
1786 ;; If we have a file, return the frame list
1788 (list (idlwave-shell-file-name file)
1789 (string-to-int number)
1791 ;; No success finding a file
1794 (defun idlwave-shell-repair-string (string)
1795 "Repair a string by taking out all linebreaks. This is destructive!"
1796 (while (string-match "[ \t]*\n[ \t]*" string)
1797 (setq string (replace-match "" t t string)))
1800 (defun idlwave-shell-repair-file-name (file)
1801 "Repair a file name string by taking out all linebreaks.
1802 The last line of STRING may be garbage - we check which one makes a valid
1804 (let ((file1 "") (file2 "") (start 0))
1805 ;; We scan no further than to the next "^%" line
1806 (if (string-match "^%" file)
1807 (setq file (substring file 0 (match-beginning 0))))
1808 ;; Take out the line breaks
1809 (while (string-match "[ \t]*\n[ \t]*" file start)
1810 (setq file1 (concat file1 (substring file start (match-beginning 0)))
1811 start (match-end 0)))
1812 (setq file2 (concat file1 (substring file start)))
1814 ((file-regular-p file2) file2)
1815 ((file-regular-p file1) file1)
1816 ;; If we cannot veryfy the existence of the file, we return the shorter
1817 ;; name. The idea behind this is that this may be a relative file name
1818 ;; and our idea about the current working directory may be wrong.
1819 ;; If it is a relative file name, it hopefully is short.
1820 ((not (string= "" file1)) file1)
1821 ((not (string= "" file2)) file2)
1824 (defun idlwave-shell-cleanup ()
1825 "Do necessary cleanup for a terminated IDL process."
1826 (setq idlwave-shell-step-frame nil
1827 idlwave-shell-halt-frame nil
1828 idlwave-shell-pending-commands nil
1829 idlwave-shell-command-line-to-execute nil
1830 idlwave-shell-bp-alist nil
1831 idlwave-shell-calling-stack-index 0
1832 idlwave-idlwave_routine_info-compiled nil)
1833 (idlwave-shell-delete-temp-files)
1834 (idlwave-shell-display-line nil)
1835 (idlwave-shell-update-bp-overlays) ; kill old overlays
1836 (idlwave-shell-kill-buffer idlwave-shell-hidden-output-buffer)
1837 (idlwave-shell-kill-buffer idlwave-shell-bp-buffer)
1838 (idlwave-shell-kill-buffer idlwave-shell-error-buffer)
1839 ;; (idlwave-shell-kill-buffer (idlwave-shell-buffer))
1840 (and (get-buffer (idlwave-shell-buffer))
1841 (bury-buffer (get-buffer (idlwave-shell-buffer))))
1842 (run-hooks 'idlwave-shell-cleanup-hook))
1844 (defun idlwave-shell-kill-buffer (buf)
1845 "Kill buffer BUF if it exists."
1846 (if (setq buf (get-buffer buf))
1849 (defun idlwave-shell-kill-shell-buffer-confirm ()
1850 (when (idlwave-shell-is-running)
1852 (unless (y-or-n-p "IDL shell is running. Are you sure you want to kill the buffer? ")
1854 (message "Killing buffer *idl* and the associated process")))
1856 (defun idlwave-shell-window (n)
1857 "Issue a `window,N' command to IDL, with special window size.
1858 The size is given by `idlwave-shell-graphics-window-size'."
1860 (let ((n (if n (prefix-numeric-value n) 0)))
1861 (idlwave-shell-send-command
1862 (apply 'format "window,%d,xs=%d,ys=%d"
1863 n idlwave-shell-graphics-window-size)
1864 nil (idlwave-shell-hide-p 'misc) nil t)))
1866 (defun idlwave-shell-resync-dirs ()
1867 "Resync the buffer's idea of the current directory.
1868 This command queries IDL with the command bound to
1869 `idlwave-shell-dirstack-query', reads the output for the new
1872 (idlwave-shell-send-command idlwave-shell-dirstack-query
1873 'idlwave-shell-filter-directory
1876 (defun idlwave-shell-retall (&optional arg)
1877 "Return from the entire calling stack.
1878 Also get rid of widget events in the queue."
1880 (save-selected-window
1881 ;;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 &
1882 (idlwave-shell-send-command "retall" nil
1883 (if (idlwave-shell-hide-p 'misc) 'mostly)
1885 (idlwave-shell-display-line nil)))
1887 (defun idlwave-shell-closeall (&optional arg)
1888 "Close all open files."
1890 (idlwave-shell-send-command "close,/all" nil
1891 (idlwave-shell-hide-p 'misc) nil t))
1893 (defun idlwave-shell-quit (&optional arg)
1894 "Exit the idl process after confirmation.
1895 With prefix ARG, exit without confirmation."
1897 (if (not (idlwave-shell-is-running))
1898 (error "Shell is not running")
1899 (if (or arg (y-or-n-p "Exit the IDLWAVE Shell? "))
1901 (idlwave-shell-send-command "exit")
1904 (defun idlwave-shell-reset (&optional hidden)
1905 "Reset IDL. Return to main level and destroy the leftover variables.
1906 This issues the following commands:
1908 WIDGET_CONTROL,/RESET
1911 ;; OBJ_DESTROY, OBJ_VALID() FIXME: should this be added?
1913 (message "Resetting IDL")
1914 (setq idlwave-shell-calling-stack-index 0)
1915 (idlwave-shell-send-command "retall" nil hidden)
1916 (idlwave-shell-send-command "widget_control,/reset" nil hidden)
1917 (idlwave-shell-send-command "close,/all" nil hidden)
1918 ;; (idlwave-shell-send-command "obj_destroy, obj_valid()" nil hidden)
1919 (idlwave-shell-send-command "heap_gc,/verbose" nil hidden)
1920 (idlwave-shell-display-line nil))
1922 (defun idlwave-shell-path-filter ()
1923 ;; Convert the output of the path query into a list of directories
1924 (let ((path-string idlwave-shell-command-output)
1925 (case-fold-search t)
1928 (while (string-match "^PATH:[ \t]*<\\(.*\\)>[ \t]*\n" path-string start)
1929 (push (match-string 1 path-string) dirs)
1930 (setq start (match-end 0)))
1931 (setq dirs (mapcar 'file-name-as-directory dirs))
1932 (if (string-match "^SYSDIR:[ \t]*<\\(.*\\)>[ \t]*\n" path-string)
1933 (setq sysdir (file-name-as-directory
1934 (match-string 1 path-string))))
1935 (cons sysdir (nreverse dirs))))
1937 (defun idlwave-shell-routine-info-filter ()
1938 "Function which parses the special output from idlwave_routine_info.pro."
1939 (let ((text idlwave-shell-command-output)
1941 sep sep-re file type spec specs name cs key keys class entry)
1942 ;; (message "GOT: %s" text) ;??????????????????????
1943 ;; Initialize variables
1944 (setq idlwave-compiled-routines nil
1945 idlwave-unresolved-routines nil)
1946 ;; Cut out the correct part of the output.
1948 "^>>>BEGIN OF IDLWAVE ROUTINE INFO (\"\\(.+\\)\" IS THE SEPARATOR.*"
1950 (setq sep (match-string 1 text)
1951 sep-re (concat (regexp-quote sep) " *")
1952 text (substring text (match-end 0)))
1953 ;; Set dummy values and kill the text
1954 (setq sep "@" sep-re "@ *" text "")
1955 (if idlwave-idlwave_routine_info-compiled
1957 "Routine Info warning: No match for BEGIN line in \n>>>\n%s\n<<<\n"
1958 idlwave-shell-command-output)))
1959 (if (string-match "^>>>END OF IDLWAVE ROUTINE INFO.*" text)
1960 (setq text (substring text 0 (match-beginning 0)))
1961 (if idlwave-idlwave_routine_info-compiled
1963 "Routine Info warning: No match for END line in \n>>>\n%s\n<<<\n"
1964 idlwave-shell-command-output)))
1965 (if (string-match "\\S-" text)
1966 ;; Obviously, the pro worked. Make a note that we have it now.
1967 (setq idlwave-idlwave_routine_info-compiled t))
1968 ;; Match the output lines
1969 (while (string-match "^IDLWAVE-\\(PRO\\|FUN\\): \\(.*\\)" text start)
1970 (setq start (match-end 0))
1971 (setq type (match-string 1 text)
1972 spec (match-string 2 text)
1973 specs (idlwave-split-string spec sep-re)
1975 class (if (equal (nth 1 specs) "") nil (nth 1 specs))
1979 keys (if (and (stringp key)
1980 (not (string-match "\\` *\\'" key)))
1982 (delete "" (idlwave-split-string key " +")))))
1983 (setq name (idlwave-sintern-routine-or-method name class t)
1984 class (idlwave-sintern-class class t)
1985 file (if (equal file "") nil file)
1986 keys (mapcar (lambda (x)
1987 (list (idlwave-sintern-keyword (car x) t))) keys))
1989 ;; In the following ignore routines already defined in buffers,
1990 ;; assuming that if the buffer stuff differs, it is a "new"
1991 ;; version, not yet compiled, and should take precedence.
1992 ;; We could do the same for the library to avoid duplicates -
1993 ;; but I think frequently a user might have several versions of
1994 ;; the same function in different programs, and in this case the
1995 ;; compiled one will be the best guess of all versions.
1996 ;; Therefore, we leave duplicates of library routines in.
1997 (cond ((string= name "$MAIN$")) ; ignore this one
1998 ((and (string= type "PRO")
1999 ;; FIXME: is it OK to make the buffer routines dominate?
2001 (not (idlwave-rinfo-assq name 'pro class
2002 idlwave-buffer-routines)))
2003 ;; FIXME: is it OK to make the library routines dominate?
2004 ;;(not (idlwave-rinfo-assq name 'pro class
2005 ;; idlwave-library-routines))
2007 (setq entry (list name 'pro class
2011 (file-name-nondirectory file)
2012 (idlwave-sintern-dir
2013 (file-name-directory file)))))
2014 cs (cons nil keys)))
2016 (push entry idlwave-compiled-routines)
2017 (push entry idlwave-unresolved-routines)))
2019 ((and (string= type "FUN")
2020 ;; FIXME: is it OK to make the buffer routines dominate?
2022 (not (idlwave-rinfo-assq name 'fun class
2023 idlwave-buffer-routines)))
2024 ;; FIXME: is it OK to make the library routines dominate?
2025 ;; (not (idlwave-rinfo-assq name 'fun class
2026 ;; idlwave-library-routines))
2028 (setq entry (list name 'fun class
2032 (file-name-nondirectory file)
2033 (idlwave-sintern-dir
2034 (file-name-directory file)))))
2035 cs (cons nil keys)))
2037 (push entry idlwave-compiled-routines)
2038 (push entry idlwave-unresolved-routines))))))
2039 ;; Reverse the definitions so that they are alphabetically sorted.
2040 (setq idlwave-compiled-routines (nreverse idlwave-compiled-routines)
2041 idlwave-unresolved-routines (nreverse idlwave-unresolved-routines)))
2043 (defun idlwave-shell-filter-directory ()
2044 "Get the current directory from `idlwave-shell-command-output'.
2045 Change the default directory for the process buffer to concur."
2047 (set-buffer (idlwave-shell-buffer))
2048 (if (string-match ",___cur[\n\r]\\(\\S-*\\) *[\n\r]"
2049 idlwave-shell-command-output)
2050 (let ((dir (substring idlwave-shell-command-output
2051 (match-beginning 1) (match-end 1))))
2052 ; (message "Setting Emacs working dir to %s" dir)
2053 (setq idlwave-shell-default-directory dir)
2054 (setq default-directory (file-name-as-directory dir))))))
2056 (defvar idlwave-shell-get-object-class nil)
2057 (defun idlwave-shell-get-object-class (apos)
2058 "Query the shell for the class of the object before point."
2059 (let ((bos (save-excursion (idlwave-start-of-substatement 'pre) (point)))
2060 (bol (save-excursion (forward-line 0) (point)))
2064 (setq expression (buffer-substring
2067 (if (not (re-search-backward
2068 "[^][.A-Za-z0-9_() ]" bos t))
2069 (throw 'exit bos)) ;ran into bos
2070 (if (not (idlwave-is-pointer-dereference bol))
2071 (throw 'exit (1+ (point))))))
2073 (when (not (string= expression ""))
2074 (setq idlwave-shell-get-object-class nil)
2075 (idlwave-shell-send-command
2076 (concat "print,obj_class(" expression ")")
2077 'idlwave-shell-parse-object-class
2079 ;; If we don't know anything about the class, update shell routines
2080 (if (and idlwave-shell-get-object-class
2081 (not (assoc-ignore-case idlwave-shell-get-object-class
2082 (idlwave-class-alist))))
2083 (idlwave-shell-maybe-update-routine-info))
2084 idlwave-shell-get-object-class)))
2086 (defun idlwave-shell-parse-object-class ()
2087 "Parse the output of the obj_class command."
2088 (let ((match "print,obj_class([^\n\r]+[\n\r ]"))
2090 (not (string-match (concat match match "\\s-*^[\n\r]+"
2092 idlwave-shell-command-output))
2093 (string-match (concat match "\\([A-Za-z_0-9]+\\)")
2094 idlwave-shell-command-output))
2095 (setq idlwave-shell-get-object-class
2096 (match-string 1 idlwave-shell-command-output)))))
2099 (defun idlwave-shell-complete (&optional arg)
2100 "Do completion in the idlwave-shell buffer.
2101 Calls `idlwave-shell-complete-filename' after some executive commands or
2102 in strings. Otherwise, calls `idlwave-complete' to complete modules and
2107 ((setq cmd (idlwave-shell-executive-command))
2108 ;; We are in a command line with an executive command
2109 (if (member (upcase cmd)
2110 '(".R" ".RU" ".RUN" ".RN" ".RNE" ".RNEW"
2111 ".COM" ".COMP" ".COMPI" ".COMPIL" ".COMPILE"))
2112 ;; This command expects file names
2113 (idlwave-shell-complete-filename)))
2115 ((idlwave-shell-batch-command)
2116 (idlwave-shell-complete-filename))
2118 ((idlwave-shell-shell-command)
2119 (idlwave-shell-complete-filename))
2121 ((and (idlwave-shell-filename-string)
2124 (let ((case-fold-search t))
2125 (not (looking-at ".*obj_new")))))
2126 (idlwave-shell-complete-filename))
2129 ;; Default completion of modules and keywords
2130 (idlwave-complete arg)))))
2132 (defun idlwave-shell-complete-filename (&optional arg)
2133 "Complete a file name at point if after a file name.
2134 We assume that we are after a file name when completing one of the
2135 args of an executive .run, .rnew or .compile."
2136 ;; CWD might have changed, resync, to set default directory
2137 (idlwave-shell-resync-dirs)
2138 (let ((comint-file-name-chars idlwave-shell-file-name-chars))
2139 (comint-dynamic-complete-as-filename)))
2141 (defun idlwave-shell-executive-command ()
2142 "Return the name of the current executive command, if any."
2144 (idlwave-beginning-of-statement)
2145 (if (looking-at "[ \t]*\\([.][^ \t\n\r]+\\)")
2148 (defun idlwave-shell-filename-string ()
2149 "Return t if in a string and after what could be a file name."
2150 (let ((limit (save-excursion (beginning-of-line) (point))))
2152 ;; Skip backwards over file name chars
2153 (skip-chars-backward idlwave-shell-file-name-chars limit)
2154 ;; Check of the next char is a string delimiter
2155 (memq (preceding-char) '(?\' ?\")))))
2157 (defun idlwave-shell-batch-command ()
2158 "Returns t if we're in a batch command statement like @foo"
2159 (let ((limit (save-excursion (beginning-of-line) (point))))
2161 ;; Skip backwards over filename
2162 (skip-chars-backward idlwave-shell-file-name-chars limit)
2163 (skip-chars-backward " \t" limit)
2164 (and (eq (preceding-char) ?@) (not (idlwave-in-quote))))))
2166 (defun idlwave-shell-shell-command ()
2167 "Returns t if we're in a shell command statement like $ls"
2169 (idlwave-beginning-of-statement)
2170 (looking-at "\\$")))
2173 ;; Debugging Commands ------------------------------------------------------
2175 (defun idlwave-shell-redisplay (&optional hide)
2176 "Tries to resync the display with where execution has stopped.
2177 Issues a \"help,/trace\" command followed by a call to
2178 `idlwave-shell-display-line'. Also updates the breakpoint
2181 (setq idlwave-shell-calling-stack-index 0)
2182 (idlwave-shell-send-command
2184 '(idlwave-shell-display-line
2185 (idlwave-shell-pc-frame))
2187 (idlwave-shell-bp-query))
2189 (defun idlwave-shell-display-level-in-calling-stack (&optional hide)
2190 (idlwave-shell-send-command
2193 ;; scanning for the state will reset the stack level - restore it
2194 (setq idlwave-shell-calling-stack-index
2195 ,idlwave-shell-calling-stack-index)
2196 ;; parse the stack and visit the selected frame
2197 (idlwave-shell-parse-stack-and-display))
2200 (defun idlwave-shell-parse-stack-and-display ()
2201 (let* ((lines (delete "" (idlwave-split-string
2202 idlwave-shell-command-output "^%")))
2203 (stack (delq nil (mapcar 'idlwave-shell-parse-line lines)))
2204 (nmax (1- (length stack)))
2208 (setq idlwave-shell-calling-stack-index 0)
2210 (message "Problem with calling stack"))
2211 ((> idlwave-shell-calling-stack-index nmax)
2213 (setq idlwave-shell-calling-stack-index nmax
2214 message (format "%d is the highest calling stack level - can't go further up"
2216 ((< idlwave-shell-calling-stack-index nmin)
2218 (setq idlwave-shell-calling-stack-index nmin
2219 message (format "%d is the current calling stack level - can't go further down"
2221 (setq idlwave-shell-calling-stack-routine
2222 (nth 2 (nth idlwave-shell-calling-stack-index stack)))
2224 ;; only edebug if in that mode already
2225 (idlwave-shell-display-line
2226 (nth idlwave-shell-calling-stack-index stack) nil
2227 (unless idlwave-shell-electric-debug-mode 'no-debug))
2228 (message (or message
2229 (format "In routine %s (stack level %d)"
2230 idlwave-shell-calling-stack-routine
2231 (- idlwave-shell-calling-stack-index))))))
2233 (defun idlwave-shell-stack-up ()
2234 "Display the source code one step up the calling stack."
2236 (incf idlwave-shell-calling-stack-index)
2237 (idlwave-shell-display-level-in-calling-stack 'hide))
2238 (defun idlwave-shell-stack-down ()
2239 "Display the source code one step down the calling stack."
2241 (decf idlwave-shell-calling-stack-index)
2242 (idlwave-shell-display-level-in-calling-stack 'hide))
2244 (defun idlwave-shell-goto-frame (&optional frame)
2245 "Set buffer to FRAME with point at the frame line.
2246 If the optional argument FRAME is nil then idlwave-shell-pc-frame is
2247 used. Does nothing if the resulting frame is nil."
2249 (setq frame (idlwave-shell-pc-frame)))
2252 (set-buffer (idlwave-find-file-noselect (car frame) 'shell))
2254 (goto-line (nth 1 frame)))))
2256 (defun idlwave-shell-pc-frame ()
2257 "Returns the frame for IDL execution."
2258 (and idlwave-shell-halt-frame
2259 (list (nth 0 idlwave-shell-halt-frame)
2260 (nth 1 idlwave-shell-halt-frame)
2261 (nth 2 idlwave-shell-halt-frame))))
2263 (defun idlwave-shell-valid-frame (frame)
2264 "Check that frame is for an existing file."
2265 (file-readable-p (car frame)))
2267 (defvar idlwave-shell-suppress-electric-debug nil)
2268 (defun idlwave-shell-display-line (frame &optional col no-debug)
2269 "Display FRAME file in other window with overlay arrow.
2271 FRAME is a list of file name, line number, and subroutine name. If
2272 FRAME is nil then remove overlay. If COL is set, move point to that
2273 column in the line. If NO-DEBUG is non-nil, do *not* toggle the electric
2276 ;; Remove stop-line overlay from old position
2278 (setq overlay-arrow-string nil)
2279 (setq idlwave-shell-mode-line-info nil)
2280 (setq idlwave-shell-is-stopped nil)
2281 (if idlwave-shell-stop-line-overlay
2282 (delete-overlay idlwave-shell-stop-line-overlay))
2283 ;; Turn off electric debug everywhere, if it's on
2284 (if (and (not no-debug)
2285 idlwave-shell-automatic-electric-debug)
2286 (idlwave-shell-electric-debug-all-off)))
2287 (if (not (idlwave-shell-valid-frame frame))
2288 ;; FIXME: errors are dangerous in shell filters. But I think I
2289 ;; have never encountered this one.
2290 (error (concat "Invalid frame - unable to access file: " (car frame)))
2292 ;;; buffer : the buffer to display a line in.
2293 ;;; select-shell: current buffer is the shell.
2295 (setq idlwave-shell-mode-line-info
2298 (- idlwave-shell-calling-stack-index)
2300 (let* ((buffer (idlwave-find-file-noselect (car frame) 'shell))
2301 (select-shell (equal (buffer-name) (idlwave-shell-buffer)))
2302 window pos electric)
2304 ;; First make sure the shell window is visible
2305 (idlwave-display-buffer (idlwave-shell-buffer)
2306 nil (idlwave-shell-shell-frame))
2308 ;; Now display the buffer and remember which window it is.
2309 (setq window (idlwave-display-buffer buffer
2310 nil (idlwave-shell-source-frame)))
2312 ;; Enter the buffer and mark the line
2317 (goto-line (nth 1 frame))
2320 (setq idlwave-shell-is-stopped t)
2322 (if idlwave-shell-stop-line-overlay
2324 (move-overlay idlwave-shell-stop-line-overlay
2325 (point) (save-excursion (end-of-line) (point))
2327 ;; Use the arrow instead, but only if marking is wanted.
2328 (if idlwave-shell-mark-stop-line
2329 (setq overlay-arrow-string idlwave-shell-overlay-arrow))
2330 (or overlay-arrow-position ; create the marker if necessary
2331 (setq overlay-arrow-position (make-marker)))
2332 (set-marker overlay-arrow-position (point) buffer)))
2334 ;; If the point is outside the restriction, widen the buffer.
2335 (if (or (< pos (point-min)) (> pos (point-max)))
2340 ;; If we have the column of the error, move the cursor there.
2341 (if col (move-to-column col))
2344 ;; Enter electric debug mode, if not prohibited and not in
2347 (eq idlwave-shell-automatic-electric-debug t)
2349 (eq idlwave-shell-automatic-electric-debug 'breakpoint)
2350 (not (eq idlwave-shell-current-state 'error))))
2352 (not idlwave-shell-suppress-electric-debug)
2353 (not idlwave-shell-electric-debug-mode))
2354 (idlwave-shell-electric-debug-mode)
2357 ;; Make sure pos is really displayed in the window.
2358 (set-window-point window pos)
2360 ;; If we came from the shell, go back there. Otherwise select
2361 ;; the window where the error is displayed.
2362 (if (or (and idlwave-shell-electric-zap-to-file electric)
2363 (and (equal (buffer-name) (idlwave-shell-buffer))
2364 (not select-shell)))
2365 (select-window window))))))
2368 (defun idlwave-shell-step (arg)
2369 "Step one source line. If given prefix argument ARG, step ARG source lines."
2371 (or (not arg) (< arg 1)
2373 (idlwave-shell-send-command
2374 (concat ".s " (if (integerp arg) (int-to-string arg) arg))
2375 nil (if (idlwave-shell-hide-p 'debug) 'mostly) nil t))
2377 (defun idlwave-shell-stepover (arg)
2378 "Stepover one source line.
2379 If given prefix argument ARG, step ARG source lines.
2380 Uses IDL's stepover executive command which does not enter called functions."
2382 (or (not arg) (< arg 1)
2384 (idlwave-shell-send-command
2385 (concat ".so " (if (integerp arg) (int-to-string arg) arg))
2386 nil (if (idlwave-shell-hide-p 'debug) 'mostly) nil t))
2388 (defun idlwave-shell-break-here (&optional count cmd condition)
2389 "Set breakpoint at current line.
2391 If Count is nil then an ordinary breakpoint is set. We treat a count
2392 of 1 as a temporary breakpoint using the ONCE keyword. Counts greater
2393 than 1 use the IDL AFTER=count keyword to break only after reaching
2394 the statement count times.
2396 Optional argument CMD is a list or function to evaluate upon reaching
2401 (if (equal (car count) 4)
2402 (setq condition (read-string "Break Condition: ")))
2404 (idlwave-shell-set-bp
2405 ;; Create breakpoint
2406 (idlwave-shell-bp (idlwave-shell-current-frame)
2407 (list count cmd condition)
2408 (idlwave-shell-current-module))))
2410 (defun idlwave-shell-set-bp-check (bp)
2411 "Check for failure to set breakpoint.
2412 This is run on `idlwave-shell-post-command-hook'.
2413 Offers to recompile the procedure if we failed. This usually fixes
2414 the problem with not being able to set the breakpoint."
2416 (if (and idlwave-shell-command-output
2417 (string-match "% BREAKPOINT: *Unable to find code"
2418 idlwave-shell-command-output))
2419 ;; Offer to recompile
2424 (concat "Okay to recompile file "
2425 (idlwave-shell-bp-get bp 'file) " ")))
2428 ;; Clean up before retrying
2429 (idlwave-shell-command-failure)
2430 (idlwave-shell-send-command
2431 (concat ".run " (idlwave-shell-bp-get bp 'file)) nil
2432 (if (idlwave-shell-hide-p 'run) 'mostly) nil t)
2433 ;; Try setting breakpoint again
2434 (idlwave-shell-set-bp bp))
2436 (message "Unable to set breakpoint.")
2437 (idlwave-shell-command-failure)
2439 ;; return non-nil if no error found
2443 (defun idlwave-shell-command-failure ()
2444 "Do any necessary clean up when an IDL command fails.
2445 Call this from a function attached to `idlwave-shell-post-command-hook'
2446 that detects the failure of a command.
2447 For example, this is called from `idlwave-shell-set-bp-check' when a
2448 breakpoint can not be set."
2449 ;; Clear pending commands
2450 (setq idlwave-shell-pending-commands nil))
2452 (defun idlwave-shell-cont ()
2453 "Continue executing."
2455 (idlwave-shell-send-command ".c" '(idlwave-shell-redisplay 'hide)
2456 (if (idlwave-shell-hide-p 'debug) 'mostly)
2459 (defun idlwave-shell-go ()
2460 "Run .GO. This starts the main program of the last compiled file."
2462 (idlwave-shell-send-command ".go" '(idlwave-shell-redisplay 'hide)
2463 (if (idlwave-shell-hide-p 'debug) 'mostly)
2466 (defun idlwave-shell-return ()
2467 "Run .RETURN (continue to next return, but stay in subprogram)."
2469 (idlwave-shell-send-command ".return" '(idlwave-shell-redisplay 'hide)
2470 (if (idlwave-shell-hide-p 'debug) 'mostly)
2473 (defun idlwave-shell-skip ()
2474 "Run .SKIP (skip one line, then step)."
2476 (idlwave-shell-send-command ".skip" '(idlwave-shell-redisplay 'hide)
2477 (if (idlwave-shell-hide-p 'debug) 'mostly)
2480 (defun idlwave-shell-clear-bp (bp)
2481 "Clear breakpoint BP.
2482 Clears in IDL and in `idlwave-shell-bp-alist'."
2483 (let ((index (idlwave-shell-bp-get bp)))
2486 (idlwave-shell-send-command
2487 (concat "breakpoint,/clear,"
2488 (if (integerp index) (int-to-string index) index))
2489 nil (idlwave-shell-hide-p 'breakpoint) nil t)
2490 (idlwave-shell-bp-query)))))
2492 (defun idlwave-shell-current-frame ()
2493 "Return a list containing the current file name and line point is in.
2494 If in the IDL shell buffer, returns `idlwave-shell-pc-frame'."
2495 (if (eq (current-buffer) (get-buffer (idlwave-shell-buffer)))
2497 (idlwave-shell-pc-frame)
2499 (list (idlwave-shell-file-name (buffer-file-name))
2504 (1+ (count-lines 1 (point))))))))
2506 (defun idlwave-shell-current-module ()
2507 "Return the name of the module for the current file.
2508 Returns nil if unable to obtain a module name."
2509 (if (eq (current-buffer) (get-buffer (idlwave-shell-buffer)))
2511 (nth 2 idlwave-shell-halt-frame)
2516 (if (idlwave-prev-index-position)
2517 (upcase (idlwave-unit-name)))))))
2519 (defun idlwave-shell-clear-current-bp ()
2520 "Remove breakpoint at current line.
2521 This command can be called from the shell buffer if IDL is currently stopped
2524 (let ((bp (idlwave-shell-find-bp (idlwave-shell-current-frame))))
2525 (if bp (idlwave-shell-clear-bp bp)
2526 ;; Try moving to beginning of statement
2528 (idlwave-shell-goto-frame)
2529 (idlwave-beginning-of-statement)
2530 (setq bp (idlwave-shell-find-bp (idlwave-shell-current-frame)))
2531 (if bp (idlwave-shell-clear-bp bp)
2533 (message "Cannot identify breakpoint for this line"))))))
2535 (defun idlwave-shell-disable-all-bp (&optional enable)
2536 "Disable all breakpoints we know about.
2537 If ENABLE is non-nil, enable them instead."
2538 (let ((bpl idlwave-shell-bp-alist))
2540 (idlwave-shell-send-command
2541 (concat "breakpoint,"
2542 (if enable "/enable," "/disable," )
2543 (idlwave-shell-bp-get (car bpl)))
2544 nil (idlwave-shell-hide-p 'breakpoint) nil t)
2545 (setq bpl (cdr bpl)))))
2547 (defun idlwave-shell-to-here ()
2548 "Set a breakpoint with count 1 then continue."
2550 (idlwave-shell-disable-all-bp)
2551 (idlwave-shell-break-here 1)
2552 (idlwave-shell-cont)
2553 (idlwave-shell-disable-all-bp 'enable))
2555 (defun idlwave-shell-break-this-module (&optional arg)
2558 (idlwave-beginning-of-subprogram)
2559 (idlwave-shell-break-here arg)))
2561 (defun idlwave-shell-break-in ()
2562 "Look for a module name near point and set a break point for it.
2563 The command looks for an identifier near point and sets a breakpoint
2564 for the first line of the corresponding module. If MODULE is `t', set
2565 in the current routine."
2569 (skip-chars-backward "a-zA-Z0-9_$")
2570 (if (looking-at idlwave-identifier)
2571 (setq module (match-string 0))
2572 (error "No identifier at point")))
2573 (idlwave-shell-send-command
2574 idlwave-shell-sources-query
2576 (idlwave-shell-sources-filter)
2577 (idlwave-shell-set-bp-in-module ,module))
2580 (defun idlwave-shell-set-bp-in-module (module)
2581 "Set breakpoint in module. Assumes that `idlwave-shell-sources-alist'
2582 contains an entry for that module."
2583 (let ((source-file (car-safe
2585 (assoc (upcase module)
2586 idlwave-shell-sources-alist))))
2588 (if (or (not source-file)
2589 (not (file-regular-p source-file))
2591 (or (idlwave-get-buffer-visiting source-file)
2592 (find-file-noselect source-file)))))
2594 (message "The source file for module %s is probably not compiled"
2600 (goto-char (point-min))
2601 (let ((case-fold-search t))
2602 (if (re-search-forward
2603 (concat "^[ \t]*\\(pro\\|function\\)[ \t]+"
2607 (goto-char (match-beginning 1))
2608 (message "Setting breakpoint for module %s" module)
2609 (idlwave-shell-break-here))
2610 (message "Cannot find module %s in file %s" module source-file)
2613 (defun idlwave-shell-up ()
2614 "Run to end of current block.
2615 Sets a breakpoint with count 1 at end of block, then continues."
2617 (if (idlwave-shell-pc-frame)
2619 (idlwave-shell-goto-frame)
2620 ;; find end of subprogram
2621 (let ((eos (save-excursion
2622 (idlwave-beginning-of-subprogram)
2623 (idlwave-forward-block)
2625 (idlwave-backward-up-block -1)
2626 ;; move beyond end block line - IDL will not break there.
2627 ;; That is, you can put a breakpoint there but when IDL does
2628 ;; break it will report that it is at the next line.
2629 (idlwave-next-statement)
2630 (idlwave-end-of-statement)
2631 ;; Make sure we are not beyond subprogram
2635 ;; Move back inside subprogram
2637 (idlwave-previous-statement))
2638 (idlwave-shell-to-here)))))
2640 (defun idlwave-shell-out ()
2641 "Attempt to run until this procedure exits.
2642 Runs to the last statement and then steps 1 statement. Use the .out command."
2644 (idlwave-shell-send-command ".o" nil
2645 (if (idlwave-shell-hide-p 'debug) 'mostly)
2648 (defun idlwave-shell-goto-previous-bp ()
2649 "Move to the previous breakpoint in the buffer."
2651 (idlwave-shell-move-to-bp -1))
2652 (defun idlwave-shell-goto-next-bp ()
2653 "Move to the next breakpoint in the buffer."
2655 (idlwave-shell-move-to-bp 1))
2657 (defun idlwave-shell-move-to-bp (dir)
2658 "Move to the next or previous breakpoint, depending on direction DIR."
2659 (let* ((frame (idlwave-shell-current-frame))
2661 (bp-line (nth 1 frame))
2662 (bp-alist idlwave-shell-bp-alist)
2664 (while (setq bp (pop bp-alist))
2665 (when (string= file (car (car bp)))
2667 (if (funcall (if (> dir 0) '> '<)
2668 (nth 1 (car bp)) bp-line)
2669 (setq bp-line (nth 1 (car bp))))))
2670 (unless got-bp (error "No breakpoints set in this file."))
2671 (unless (not (equal bp-line (nth 1 frame)))
2672 (error "No further breakpoints."))
2673 (goto-line bp-line)))
2675 ;; Examine Commands ------------------------------------------------------
2677 (defun idlwave-shell-help-expression (arg)
2678 "Print help on current expression. See `idlwave-shell-print'."
2680 (idlwave-shell-print arg 'help))
2682 (defmacro idlwave-shell-mouse-examine (help &optional ev)
2683 "Create a function for generic examination of expressions."
2685 "Expansion function for expression examination."
2687 (let ((transient-mark-mode t)
2689 (tracker (if (featurep 'xemacs)
2690 (if (fboundp 'default-mouse-track-event-is-with-button)
2691 'idlwave-xemacs-hack-mouse-track
2693 'mouse-drag-region)))
2694 (funcall tracker event)
2695 (idlwave-shell-print (if (idlwave-region-active-p) '(4) nil)
2698 ;;; Begin terrible hack section -- XEmacs tests for button2 explicitly
2699 ;;; on drag events, calling drag-n-drop code if detected. Ughhh...
2700 (defun idlwave-default-mouse-track-event-is-with-button (event n)
2703 (defun idlwave-xemacs-hack-mouse-track (event)
2704 (let ((oldfunc (symbol-function 'default-mouse-track-event-is-with-button)))
2707 (fset 'default-mouse-track-event-is-with-button
2708 'idlwave-default-mouse-track-event-is-with-button)
2709 (mouse-track event))
2710 (fset 'default-mouse-track-event-is-with-button oldfunc))))
2711 ;;; End terrible hack section
2713 (defun idlwave-shell-mouse-print (event)
2714 "Print value of variable at the mouse position, with `help'"
2716 (funcall (idlwave-shell-mouse-examine nil) event))
2718 (defun idlwave-shell-mouse-help (event)
2719 "Print value of variable at the mouse position, with `print'."
2721 (funcall (idlwave-shell-mouse-examine 'help) event))
2723 (defun idlwave-shell-examine-select (event)
2724 "Pop-up a list to select from for examining the expression"
2726 (funcall (idlwave-shell-mouse-examine nil event) event))
2728 (defmacro idlwave-shell-examine (help)
2729 "Create a function for key-driven expression examination."
2732 (idlwave-shell-print nil ,help)))
2734 (defvar idlwave-shell-examine-label nil
2735 "Label to include with examine text if in a separate buffer.")
2736 (defvar idlwave-shell-examine-completion-list nil)
2738 (defun idlwave-shell-print (arg &optional help ev complete-help-type)
2739 "Print current expression.
2741 With HELP non-nil, show help on expression. If HELP is a string,
2742 the expression will be put in place of ___, e.g.:
2744 print,size(___,/DIMENSIONS)
2746 HELP can also be a cons cell ( NAME . STRING ) in which case NAME will
2747 be used to label the help print-out.
2749 Otherwise, print is called on the expression.
2751 An expression is an identifier plus 1 pair of matched parentheses
2752 directly following the identifier - an array or function call.
2753 Alternatively, an expression is the contents of any matched
2754 parentheses when the open parenthesis is not directly preceded by an
2755 identifier. If point is at the beginning or within an expression
2756 return the inner-most containing expression, otherwise, return the
2757 preceding expression.
2759 With prefix arg, or if transient mode set and the region is defined,
2760 use the current region as the expression.
2762 With double prefix arg ARG prompt for an expression.
2764 If EV is a valid event passed, pop-up a list from
2765 idlw-shell-examine-alist from which to select the help command text.
2766 If instead COMPLETE-HELP-TYPE is non-nil, choose from
2767 idlw-shell-examine-alist via mini-buffer shortcut key."
2770 (let* ((process (get-buffer-process (current-buffer)))
2771 (process-mark (if process (process-mark process)))
2773 (if (and (integerp idlwave-shell-calling-stack-index)
2774 (> idlwave-shell-calling-stack-index 0))
2776 idlwave-shell-calling-stack-index
2777 idlwave-shell-calling-stack-routine)))
2778 expr beg end cmd examine-hook)
2781 (setq expr (read-string "Expression: ")))
2782 ((and (or arg (idlwave-region-active-p))
2783 (< (- (region-end) (region-beginning)) 2000))
2784 (setq beg (region-beginning)
2787 (idlwave-with-special-syntax
2788 ;; Move to beginning of current or previous expression
2789 (if (looking-at "\\<\\|(")
2790 ;; At beginning of expression, don't move backwards unless
2791 ;; this is at the end of an indentifier.
2792 (if (looking-at "\\>")
2795 (if (looking-at "\\>")
2796 ;; Move to beginning of identifier - must be an array or
2797 ;; function expression.
2799 ;; Move to end of expression
2802 (while (looking-at "\\>[[(]\\|\\.")
2805 (setq end (point)))))
2807 ;; Get expression, but first move the begin mark if a
2808 ;; process-mark is inside the region, to keep the overlay from
2809 ;; wandering in the Shell.
2811 (if (and process-mark (> process-mark beg) (< process-mark end))
2812 (setq beg (marker-position process-mark)))
2813 (setq expr (buffer-substring beg end)))
2815 ;; Show the overlay(s) and attach any necessary hooks and filters
2816 (when (and beg end idlwave-shell-expression-overlay)
2817 (move-overlay idlwave-shell-expression-overlay beg end
2819 (add-hook 'pre-command-hook
2820 'idlwave-shell-delete-expression-overlay))
2822 (if idlwave-shell-separate-examine-output
2823 'idlwave-shell-examine-display
2824 'idlwave-shell-examine-highlight))
2825 (add-hook 'pre-command-hook
2826 'idlwave-shell-delete-output-overlay)
2828 ;; Remove empty or comment-only lines
2829 (while (string-match "\n[ \t]*\\(;.*\\)?\r*\n" expr)
2830 (setq expr (replace-match "\n" t t expr)))
2831 ;; Concatenate continuation lines
2832 (while (string-match "[ \t]*\\$.*\\(;.*\\)?\\(\n[ \t]*\\|$\\)" expr)
2833 (setq expr (replace-match "" t t expr)))
2834 ;; Remove final newline
2835 (if (string-match "\n[ \t\r]*\\'" expr)
2836 (setq expr (replace-match "" t t expr)))
2839 ;; Pop-up or complete on the examine selection list, if appropriate
2842 (and ev idlwave-shell-examine-alist)
2845 (if (consp help) help
2847 ;; A cons from either a pop-up or mini-buffer completion
2848 (if complete-help-type
2849 (idlwave-one-key-select 'idlwave-shell-examine-alist
2850 "Examine with: " 1.5)
2851 ;; (idlwave-completing-read
2853 ;; idlwave-shell-examine-alist nil nil nil
2854 ;; 'idlwave-shell-examine-completion-list
2856 (idlwave-popup-select
2858 (mapcar 'car idlwave-shell-examine-alist)
2860 idlwave-shell-examine-alist))))
2861 (setq help (cdr help-cons))
2862 (if (null help) (throw 'exit nil))
2863 (if idlwave-shell-separate-examine-output
2864 (setq idlwave-shell-examine-label
2866 (format "==>%s<==\n%s:" expr (car help-cons))
2867 stack-label "\n"))))
2868 ;; The regular help label (no popups, cons cells, etc.)
2869 (setq idlwave-shell-examine-label
2871 (format "==>%s<==\n%s:" expr
2872 (cond ((null help) "print")
2873 ((stringp help) help)
2874 (t (symbol-name help))))
2879 (setq expr (idlwave-retrieve-expression-from-level
2881 idlwave-shell-calling-stack-index)))
2882 (setq cmd (idlwave-shell-help-statement help expr))
2883 ;;(idlwave-shell-recenter-shell-window)
2884 (idlwave-shell-send-command
2887 (if idlwave-shell-separate-examine-output 'hide))))))
2889 (defvar idlwave-shell-examine-window-alist nil
2890 "Variable to hold the win/height pairs for all *Examine* windows.")
2892 (defun idlwave-shell-examine-display ()
2893 "View the examine command output in a separate buffer."
2894 (let (win cur-beg cur-end)
2896 (set-buffer (get-buffer-create "*Examine*"))
2897 (use-local-map idlwave-shell-examine-map)
2898 (setq buffer-read-only nil)
2899 (goto-char (point-max))
2901 (narrow-to-region (point) (point))
2902 (if (string-match "^% Syntax error." idlwave-shell-command-output)
2903 (insert "% Syntax error.\n")
2904 (insert idlwave-shell-command-output)
2905 ;; Just take the last bit between the prompts (if more than one).
2907 (re-search-backward idlwave-shell-prompt-pattern nil t)
2911 (or (progn (if (re-search-backward
2912 idlwave-shell-prompt-pattern nil t)
2915 (re-search-forward "\n")))
2916 (str (buffer-substring beg end)))
2917 (delete-region (point-min) (point-max))
2919 (if idlwave-shell-examine-label
2920 (progn (goto-char (point-min))
2921 (insert idlwave-shell-examine-label)
2922 (setq idlwave-shell-examine-label nil)))))
2923 (setq cur-beg (point-min)
2924 cur-end (point-max))
2925 (setq buffer-read-only t)
2926 (move-overlay idlwave-shell-output-overlay cur-beg cur-end
2929 ;; Look for the examine buffer in all windows. If one is
2930 ;; found in a frame all by itself, use that, otherwise, switch
2931 ;; to or create an examine window in this frame, and resize if
2932 ;; it's a newly created window
2933 (let* ((winlist (get-buffer-window-list "*Examine*" nil 'visible)))
2934 (setq win (idlwave-display-buffer
2937 (let ((list winlist) thiswin)
2939 (save-selected-window
2940 (while (setq thiswin (pop list))
2941 (select-window thiswin)
2943 (throw 'exit (window-frame thiswin)))))))))
2944 (set-window-start win (point-min)) ; Ensure the point is visible.
2945 (save-selected-window
2947 (let ((elt (assoc win idlwave-shell-examine-window-alist)))
2948 (when (and (not (one-window-p))
2949 (or (not (memq win winlist)) ;a newly created window
2950 (eq (window-height) (cdr elt))))
2952 (enlarge-window (- (/ (frame-height) 2)
2954 (shrink-window-if-larger-than-buffer)
2955 ;; Clean the window list of dead windows
2956 (setq idlwave-shell-examine-window-alist
2958 (mapcar (lambda (x) (if (window-live-p (car x)) x))
2959 idlwave-shell-examine-window-alist)))
2960 ;; And add the new value.
2961 (if (setq elt (assoc win idlwave-shell-examine-window-alist))
2962 (setcdr elt (window-height))
2963 (add-to-list 'idlwave-shell-examine-window-alist
2964 (cons win (window-height)))))))))
2965 ;; Recenter for maximum output, after widened
2966 (save-selected-window
2968 (goto-char (point-max))
2969 (skip-chars-backward "\n")
2972 (defvar idlwave-shell-examine-map (make-sparse-keymap))
2973 (define-key idlwave-shell-examine-map "q" 'idlwave-shell-examine-display-quit)
2974 (define-key idlwave-shell-examine-map "c" 'idlwave-shell-examine-display-clear)
2976 (defun idlwave-shell-examine-display-quit ()
2978 (let ((win (selected-window)))
2980 (delete-frame (window-frame win))
2981 (delete-window win))))
2983 (defun idlwave-shell-examine-display-clear ()
2986 (let ((buf (get-buffer "*Examine*")))
2989 (setq buffer-read-only nil)
2991 (setq buffer-read-only t)))))
2993 (defun idlwave-retrieve-expression-from-level (expr level)
2994 "Return IDL command to print the expression EXPR from stack level LEVEL.
2996 It does not seem possible to evaluate an expression on a differnt
2997 level than the current. Therefore, this function retrieves variables
2998 by reference from other levels, and then includes that variable in
2999 place of the chosen one.
3001 Since this function depends upon the undocumented IDL routine
3002 routine_names, there is no guarantee that this will work with future
3004 (let ((fetch (- 0 level))
3008 ;; FIXME: In the following we try to find the variables in expression
3009 ;; This is quite empirical - I don't know in what situations this will
3010 ;; break. We will look for identifiers and exclude cases where we
3011 ;; know it is not a variable. To distinguish array references from
3012 ;; function calls, we require that arrays use [] instead of ()
3014 (while (string-match
3015 "\\(\\`\\|[^a-zA-Z0-9$_][ \t]*\\)\\([a-zA-Z][a-zA-Z0-9$_]*\\)\\([ \t]*[^a-zA-Z0-9$_]\\|\\'\\)" expr start)
3016 (setq var (match-string 2 expr)
3017 start (match-beginning 2)
3018 pre (substring expr 0 (match-beginning 2))
3019 post (substring expr (match-end 2)))
3021 ;; Exclude identifiers which are not variables
3022 ((string-match ",[ \t]*/\\'" pre)) ;; a `/' KEYWORD
3023 ((and (string-match "[,(][ \t]*\\'" pre)
3024 (string-match "\\`[ \t]*=" post))) ;; a `=' KEYWORD
3025 ((string-match "\\`(" post)) ;; a function
3026 ((string-match "->[ \t]*\\'" pre)) ;; a method
3027 ((string-match "\\.\\'" pre)) ;; structure member
3028 ((and (string-match "\\([\"\']\\)[^\1]*$" pre)
3029 (string-match (concat "^[^" (match-string 1 pre) "]*"
3030 (match-string 1 pre)) post)))
3031 (t ;; seems to be a variable - replace its name in the
3032 ;; expression with the fetch.
3033 (setq rnvar (format "(routine_names('%s',fetch=%d))" var fetch)
3034 expr (concat pre rnvar post)
3035 start (+ start (length rnvar))))))
3039 (defun idlwave-shell-help-statement (help expr)
3040 "Construct a help statement for printing expression EXPR.
3042 HELP can be non-nil for `help,', nil for 'print,' or any string into which
3043 to insert expression in place of the marker ___, e.g.: print,
3044 size(___,/DIMENSIONS)"
3046 ((null help) (concat "print, " expr))
3048 (if (string-match "\\(^\\|[^_]\\)\\(___\\)\\([^_]\\|$\\)" help)
3049 (concat (substring help 0 (match-beginning 2))
3051 (substring help (match-end 2)))))
3052 (t (concat "help, " expr))))
3055 (defun idlwave-shell-examine-highlight ()
3056 "Highlight the most recent IDL output."
3057 (let* ((buffer (get-buffer (idlwave-shell-buffer)))
3058 (process (get-buffer-process buffer))
3059 (process-mark (if process (process-mark process)))
3060 output-begin output-end)
3063 (goto-char process-mark)
3065 (setq output-end (point))
3066 (re-search-backward idlwave-shell-prompt-pattern nil t)
3067 (beginning-of-line 2)
3068 (setq output-begin (point)))
3070 ;; First make sure the shell window is visible
3071 (idlwave-display-buffer (idlwave-shell-buffer)
3072 nil (idlwave-shell-shell-frame))
3073 (if (and idlwave-shell-output-overlay process-mark)
3074 (move-overlay idlwave-shell-output-overlay
3075 output-begin output-end buffer))))
3077 (defun idlwave-shell-delete-output-overlay ()
3078 (unless (or (eq this-command 'idlwave-shell-mouse-nop)
3079 (eq this-command 'handle-switch-frame))
3081 (if idlwave-shell-output-overlay
3082 (delete-overlay idlwave-shell-output-overlay))
3084 (remove-hook 'pre-command-hook 'idlwave-shell-delete-output-overlay)))
3086 (defun idlwave-shell-delete-expression-overlay ()
3087 (unless (or (eq this-command 'idlwave-shell-mouse-nop)
3088 (eq this-command 'handle-switch-frame))
3090 (if idlwave-shell-expression-overlay
3091 (delete-overlay idlwave-shell-expression-overlay))
3093 (remove-hook 'pre-command-hook 'idlwave-shell-delete-expression-overlay)))
3095 (defvar idlwave-shell-bp-alist nil
3096 "Alist of breakpoints.
3097 A breakpoint is a cons cell \(\(file line\) . \(\(index module\) data\)\)
3099 The car is the frame for the breakpoint:
3100 file - full path file name.
3101 line - line number of breakpoint - integer.
3103 The first element of the cdr is a list of internal IDL data:
3104 index - the index number of the breakpoint internal to IDL.
3105 module - the module for breakpoint internal to IDL.
3107 Remaining elements of the cdr:
3108 data - Data associated with the breakpoint by idlwave-shell currently
3109 contains three items:
3111 count - number of times to execute breakpoint. When count reaches 0
3112 the breakpoint is cleared and removed from the alist.
3114 command - command to execute when breakpoint is reached, either a
3115 lisp function to be called with `funcall' with no arguments or a
3116 list to be evaluated with `eval'.
3118 condition - any condition to apply to the breakpoint.")
3120 (defun idlwave-shell-run-region (beg end &optional n)
3121 "Compile and run the region using the IDL process.
3122 Copies the region to a temporary file `idlwave-shell-temp-pro-file'
3123 and issues the IDL .run command for the file. Because the
3124 region is compiled and run as a main program there is no
3125 problem with begin-end blocks extending over multiple
3126 lines - which would be a problem if `idlwave-shell-evaluate-region'
3127 was used. An END statement is appended to the region if necessary.
3129 If there is a prefix argument, display IDL process."
3130 (interactive "r\nP")
3131 (let ((oldbuf (current-buffer)))
3133 (set-buffer (idlwave-find-file-noselect
3134 (idlwave-shell-temp-file 'pro) 'tmp))
3135 (set (make-local-variable 'comment-start-skip) ";+[ \t]*")
3136 (set (make-local-variable 'comment-start) ";")
3138 (insert-buffer-substring oldbuf beg end)
3139 (if (not (save-excursion
3140 (idlwave-previous-statement)
3141 (idlwave-look-at "\\<end\\>")))
3144 (idlwave-shell-send-command (concat ".run " idlwave-shell-temp-pro-file)
3146 (if (idlwave-shell-hide-p 'run) 'mostly)
3149 (idlwave-display-buffer (idlwave-shell-buffer)
3150 nil (idlwave-shell-shell-frame))))
3152 (defun idlwave-shell-evaluate-region (beg end &optional n)
3153 "Send region to the IDL process.
3154 If there is a prefix argument, display IDL process.
3155 Does not work for a region with multiline blocks - use
3156 `idlwave-shell-run-region' for this."
3157 (interactive "r\nP")
3158 (idlwave-shell-send-command (buffer-substring beg end))
3160 (idlwave-display-buffer (idlwave-shell-buffer)
3161 nil (idlwave-shell-shell-frame))))
3163 (defun idlwave-shell-delete-temp-files ()
3164 "Delete the temporary files and kill associated buffers."
3165 (if (stringp idlwave-shell-temp-pro-file)
3167 (let ((buf (idlwave-get-buffer-visiting
3168 idlwave-shell-temp-pro-file)))
3169 (if (buffer-live-p buf)
3171 (delete-file idlwave-shell-temp-pro-file))
3173 (if (stringp idlwave-shell-temp-rinfo-save-file)
3175 (delete-file idlwave-shell-temp-rinfo-save-file)
3178 (defun idlwave-display-buffer (buf not-this-window-p &optional frame)
3179 (if (featurep 'xemacs)
3180 ;; The XEmacs version enforces the frame
3181 (display-buffer buf not-this-window-p frame)
3182 ;; For Emacs, we need to force the frame ourselves.
3183 (let ((this-frame (selected-frame)))
3184 (save-excursion ;; make sure we end up in the same buffer
3185 (if (frame-live-p frame)
3186 (select-frame frame))
3187 (if (eq this-frame (selected-frame))
3188 ;; same frame: use display buffer, to make sure the current
3190 (display-buffer buf)
3193 ;; only window: switch
3195 (switch-to-buffer buf)
3196 (selected-window)) ; must return the window.
3197 ;; several windows - use display-buffer
3198 (display-buffer buf not-this-window-p)))))))
3199 ; (if (not (frame-live-p frame)) (setq frame nil))
3200 ; (display-buffer buf not-this-window-p frame))
3202 (defvar idlwave-shell-bp-buffer " *idlwave-shell-bp*"
3203 "Scratch buffer for parsing IDL breakpoint lists and other stuff.")
3205 (defun idlwave-shell-bp-query ()
3206 "Reconcile idlwave-shell's breakpoint list with IDL's.
3207 Queries IDL using the string in `idlwave-shell-bp-query'."
3209 (idlwave-shell-send-command idlwave-shell-bp-query
3210 'idlwave-shell-filter-bp
3213 (defun idlwave-shell-bp-get (bp &optional item)
3214 "Get a value for a breakpoint.
3215 BP has the form of elements in idlwave-shell-bp-alist.
3216 Optional second arg ITEM is the particular value to retrieve.
3217 ITEM can be 'file, 'line, 'index, 'module, 'count, 'cmd, 'condition, or 'data.
3218 'data returns a list of 'count, 'cmd and 'condition.
3219 Defaults to 'index."
3222 ((eq item 'line) (nth 1 (car bp)))
3223 ((eq item 'file) (nth 0 (car bp)))
3224 ;; idlwave-shell breakpoint data
3225 ((eq item 'data) (cdr (cdr bp)))
3226 ((eq item 'count) (nth 0 (cdr (cdr bp))))
3227 ((eq item 'cmd) (nth 1 (cdr (cdr bp))))
3228 ((eq item 'condition) (nth 2 (cdr (cdr bp))))
3229 ;; IDL breakpoint info
3230 ((eq item 'module) (nth 1 (car (cdr bp))))
3232 (t (nth 0 (car (cdr bp))))))
3234 (defun idlwave-shell-filter-bp (&optional no-show)
3235 "Get the breakpoints from `idlwave-shell-command-output'. Create
3236 `idlwave-shell-bp-alist' updating breakpoint count and command data
3237 from previous breakpoint list. If NO-SHOW is set, don't update the
3238 breakpoint overlays."
3240 (set-buffer (get-buffer-create idlwave-shell-bp-buffer))
3242 (insert idlwave-shell-command-output)
3243 (goto-char (point-min))
3244 (let ((old-bp-alist idlwave-shell-bp-alist)
3245 ;; Searching the breakpoints
3246 ;; In IDL 5.5, the breakpoint reporting format changed.
3247 (bp-re54 "^[ \t]*\\([0-9]+\\)[ \t]+\\(\\S-+\\)?[ \t]+\\([0-9]+\\)[ \t]+\\(\\S-+\\)")
3248 (bp-re55 "^\\s-*\\([0-9]+\\)\\s-+\\([0-9]+\\)\\s-+\\(Uncompiled\\|\\(\\(Func=\\|Pro=\\)\\(\\$?[a-zA-Z][a-zA-Z0-9$_:]*\\$?\\)\\)\\)\\(\\s-*,\\s-*After=[0-9]+\\(/[0-9]+\\)?\\)?\\(\\s-*,\\s-*\\(Condition='.*'\\|\\S-+\\)\n?\\)*\\s-+\\(\\S-+\\)")
3249 file line index module
3251 (setq idlwave-shell-bp-alist (list nil))
3252 ;; Search for either header type, and set the correct regexp
3254 (if (re-search-forward "^\\s-*Index.*\n\\s-*-" nil t)
3255 (setq bp-re bp-re54 ; versions <= 5.4
3256 indmap '(1 2 3 4))) ;index module line file
3257 (if (re-search-forward
3258 "^\\s-*Index\\s-*Line\\s-*Attributes\\s-*File" nil t)
3259 (setq bp-re bp-re55 ; versions >= 5.5
3260 indmap '(1 6 2 11))))
3261 ;; There seems to be a breakpoint listing here.
3262 ;; Parse breakpoint lines.
3263 ;; Breakpoints have the form
3265 ;; Index Module Line File
3266 ;; All separated by whitespace.
3267 ;; Module may be missing if the file is not compiled.
3269 ;; Index Line Attributes File
3270 ;; (attributes replaces module, "Uncompiled" included)
3271 (while (re-search-forward bp-re nil t)
3272 (setq index (match-string (nth 0 indmap))
3273 module (match-string (nth 1 indmap))
3274 line (string-to-int (match-string (nth 2 indmap)))
3275 file (idlwave-shell-file-name (match-string (nth 3 indmap))))
3276 ;; Add the breakpoint info to the list
3277 (nconc idlwave-shell-bp-alist
3278 (list (cons (list file line)
3281 ;; idlwave-shell data: count, command, condition
3283 (setq idlwave-shell-bp-alist (cdr idlwave-shell-bp-alist))
3284 ;; Update breakpoint data
3285 (mapcar 'idlwave-shell-update-bp old-bp-alist)))
3286 ;; Update the breakpoint overlays
3287 (unless no-show (idlwave-shell-update-bp-overlays))
3288 ;; Return the new list
3289 idlwave-shell-bp-alist)
3291 (defun idlwave-shell-update-bp (bp)
3292 "Update BP data in breakpoint list.
3293 If BP frame is in `idlwave-shell-bp-alist' updates the breakpoint data."
3294 (let ((match (assoc (car bp) idlwave-shell-bp-alist)))
3295 (if match (setcdr (cdr match) (cdr (cdr bp))))))
3297 (defun idlwave-shell-set-bp-data (bp data)
3298 "Set the data of BP to DATA."
3299 (setcdr (cdr bp) data))
3301 (defun idlwave-shell-bp (frame &optional data module)
3302 "Create a breakpoint structure containing FRAME and DATA. Second
3303 and third args, DATA and MODULE, are optional. Returns a breakpoint
3304 of the format used in `idlwave-shell-bp-alist'. Can be used in commands
3305 attempting match a breakpoint in `idlwave-shell-bp-alist'."
3306 (cons frame (cons (list nil module) data)))
3308 (defvar idlwave-shell-old-bp nil
3309 "List of breakpoints previous to setting a new breakpoint.")
3311 (defun idlwave-shell-sources-bp (bp)
3312 "Check `idlwave-shell-sources-alist' for source of breakpoint using BP.
3313 If an equivalency is found, return the IDL internal source name.
3314 Otherwise return the filename in bp."
3316 ((bp-file (idlwave-shell-bp-get bp 'file))
3317 (bp-module (idlwave-shell-bp-get bp 'module))
3319 (cdr (assoc bp-module idlwave-shell-sources-alist))))
3320 (if (and internal-file-list
3321 (equal bp-file (nth 0 internal-file-list)))
3322 (nth 1 internal-file-list)
3325 (defun idlwave-shell-set-bp (bp)
3326 "Try to set a breakpoint BP.
3327 The breakpoint will be placed at the beginning of the statement on the
3328 line specified by BP or at the next IDL statement if that line is not
3329 a statement. Determines IDL's internal representation for the
3330 breakpoint, which may have occured at a different line than
3332 ;; Get and save the old breakpoints
3333 (idlwave-shell-send-command
3334 idlwave-shell-bp-query
3336 (idlwave-shell-filter-bp)
3337 (setq idlwave-shell-old-bp idlwave-shell-bp-alist))
3339 ;; Get sources for IDL compiled procedures followed by setting
3341 (idlwave-shell-send-command
3342 idlwave-shell-sources-query
3344 (idlwave-shell-sources-filter)
3345 (idlwave-shell-set-bp2 (quote ,bp)))
3348 (defun idlwave-shell-set-bp2 (bp)
3349 "Use results of breakpoint and sources query to set bp.
3350 Use the count argument with IDLs breakpoint command.
3351 We treat a count of 1 as a temporary breakpoint.
3352 Counts greater than 1 use the IDL AFTER=count keyword to break
3353 only after reaching the statement count times."
3355 ((arg (idlwave-shell-bp-get bp 'count))
3357 ((not (and arg (numberp arg))) "")
3361 (format ",after=%d" arg))))
3362 (condition (idlwave-shell-bp-get bp 'condition))
3364 (if condition (concat ",CONDITION=\"" condition "\""))))
3365 (line (idlwave-shell-bp-get bp 'line)))
3366 (idlwave-shell-send-command
3367 (concat "breakpoint,'"
3368 (idlwave-shell-sources-bp bp) "',"
3369 (if (integerp line) (setq line (int-to-string line)))
3371 ;; Check for failure and look for breakpoint in IDL's list
3373 (if (idlwave-shell-set-bp-check (quote ,bp))
3374 (idlwave-shell-set-bp3 (quote ,bp))))
3376 (idlwave-shell-hide-p 'breakpoint)
3379 (defun idlwave-shell-set-bp3 (bp)
3380 "Find the breakpoint in IDL's internal list of breakpoints."
3381 (idlwave-shell-send-command idlwave-shell-bp-query
3383 (idlwave-shell-filter-bp 'no-show)
3384 (idlwave-shell-new-bp (quote ,bp))
3385 (idlwave-shell-update-bp-overlays))
3389 (defun idlwave-shell-find-bp (frame)
3390 "Return breakpoint from `idlwave-shell-bp-alist' for frame.
3391 Returns nil if frame not found."
3392 (assoc frame idlwave-shell-bp-alist))
3394 (defun idlwave-shell-new-bp (bp)
3395 "Find the new breakpoint in IDL's list and update with DATA.
3396 The actual line number for a breakpoint in IDL may be different than
3397 the line number used with the IDL breakpoint command.
3398 Looks for a new breakpoint index number in the list. This is
3399 considered the new breakpoint if the file name of frame matches."
3400 (let ((obp-index (mapcar 'idlwave-shell-bp-get idlwave-shell-old-bp))
3401 (bpl idlwave-shell-bp-alist))
3402 (while (and (member (idlwave-shell-bp-get (car bpl)) obp-index)
3403 (setq bpl (cdr bpl))))
3406 ;; No additional breakpoint.
3407 ;; Need to check if we are just replacing a breakpoint.
3408 (setq bpl (assoc (car bp) idlwave-shell-bp-alist)))
3409 (setq bpl (list bpl)))
3411 (equal (idlwave-shell-bp-get (setq bpl (car bpl)) 'file)
3412 (idlwave-shell-bp-get bp 'file)))
3413 ;; Got the breakpoint - add count, command to it.
3414 ;; This updates `idlwave-shell-bp-alist' because a deep copy was
3415 ;; not done for bpl.
3416 (idlwave-shell-set-bp-data bpl (idlwave-shell-bp-get bp 'data))
3418 (message "Failed to identify breakpoint in IDL"))))
3420 (defvar idlwave-shell-bp-overlays nil
3421 "Alist of overlays marking breakpoints")
3423 (defun idlwave-shell-update-bp-overlays ()
3424 "Update the overlays which mark breakpoints in the source code.
3425 Existing overlays are recycled, in order to minimize consumption."
3426 (when idlwave-shell-mark-breakpoints
3427 (let ((ov-alist (copy-alist idlwave-shell-bp-overlays))
3428 (bp-list idlwave-shell-bp-alist)
3429 (use-glyph (and (memq idlwave-shell-mark-breakpoints '(t glyph))
3430 idlwave-shell-bp-glyph))
3431 ov ov-list bp buf old-buffers win)
3433 ;; Delete the old overlays from their buffers
3435 (while (setq ov-list (pop ov-alist))
3436 (while (setq ov (pop (cdr ov-list)))
3437 (add-to-list 'old-buffers (overlay-buffer ov))
3438 (delete-overlay ov))))
3440 (setq ov-alist idlwave-shell-bp-overlays
3441 idlwave-shell-bp-overlays
3442 (if idlwave-shell-bp-glyph
3443 (mapcar 'list (mapcar 'car idlwave-shell-bp-glyph))
3445 (while (setq bp (pop bp-list))
3447 (idlwave-shell-goto-frame (car bp))
3448 (let* ((end (progn (end-of-line 1) (point)))
3449 (beg (progn (beginning-of-line 1) (point)))
3450 (condition (idlwave-shell-bp-get bp 'condition))
3451 (count (idlwave-shell-bp-get bp 'count))
3452 (type (if idlwave-shell-bp-glyph
3454 (condition 'bp-cond )
3458 (concat "bp-" (number-to-string count)))
3462 (ov-existing (assq type ov-alist))
3463 (ov (or (and (cdr ov-existing)
3464 (pop (cdr ov-existing)))
3465 (idlwave-shell-make-new-bp-overlay type))))
3466 (move-overlay ov beg end)
3467 (push ov (cdr (assq type idlwave-shell-bp-overlays))))
3468 ;; Take care of margins if using a glyph
3471 (setq old-buffers (delq (current-buffer) old-buffers)))
3472 (if (fboundp 'set-specifier) ;; XEmacs
3473 (set-specifier left-margin-width (cons (current-buffer) 2))
3474 (setq left-margin-width 2))
3475 (if (setq win (get-buffer-window (current-buffer) t))
3476 (set-window-buffer win (current-buffer))))))
3478 (while (setq buf (pop old-buffers))
3479 (with-current-buffer buf
3480 (if (fboundp 'set-specifier) ;; XEmacs
3481 (set-specifier left-margin-width (cons (current-buffer) 0))
3482 (setq left-margin-width 0))
3483 (if (setq win (get-buffer-window buf t))
3484 (set-window-buffer win buf))))))))
3487 (defvar idlwave-shell-bp-glyph)
3488 (defun idlwave-shell-make-new-bp-overlay (&optional type)
3489 "Make a new overlay for highlighting breakpoints.
3490 This stuff is strongly dependant upon the version of Emacs. If TYPE
3491 is passed, make an overlay of that type ('bp or 'bp-cond, currently
3493 (let ((ov (make-overlay 1 1))
3494 (use-glyph (and (memq idlwave-shell-mark-breakpoints '(t glyph))
3495 idlwave-shell-bp-glyph))
3496 (type (or type 'bp)))
3497 (if (featurep 'xemacs)
3501 ;; tty's cannot display glyphs
3502 ((eq (console-type) 'tty)
3503 (set-extent-property ov 'face idlwave-shell-breakpoint-face))
3507 (set-extent-property ov 'begin-glyph
3508 (cdr (assq type idlwave-shell-bp-glyph)))
3509 (set-extent-property ov 'begin-glyph-layout 'outside-margin))
3512 (idlwave-shell-mark-breakpoints
3513 (set-extent-property ov 'face idlwave-shell-breakpoint-face))
3517 (set-extent-priority ov -1)) ; make stop line face prevail
3525 (list (list 'margin 'left-margin)
3527 idlwave-shell-bp-glyph))))))
3528 (overlay-put ov 'before-string string))
3530 (overlay-put ov 'face idlwave-shell-breakpoint-face)))
3533 (idlwave-shell-mark-breakpoints
3534 (overlay-put ov 'face idlwave-shell-breakpoint-face))
3540 (defun idlwave-shell-edit-default-command-line (arg)
3541 "Edit the current execute command."
3543 (setq idlwave-shell-command-line-to-execute
3544 (read-string "IDL> " idlwave-shell-command-line-to-execute)))
3546 (defun idlwave-shell-execute-default-command-line (arg)
3547 "Execute a command line. On first use, ask for the command.
3548 Also with prefix arg, ask for the command. You can also uase the command
3549 `idlwave-shell-edit-default-command-line' to edit the line."
3553 (setq idlwave-shell-command-line-to-execute nil))
3555 (setq idlwave-shell-command-line-to-execute
3556 (read-string "IDL> " idlwave-shell-command-line-to-execute))))
3557 (idlwave-shell-reset 'hidden)
3558 (idlwave-shell-send-command
3559 (or idlwave-shell-command-line-to-execute
3560 (with-current-buffer (idlwave-shell-buffer)
3561 (ring-ref comint-input-ring 0)))
3562 '(idlwave-shell-redisplay 'hide)))
3564 (defun idlwave-shell-save-and-run ()
3565 "Save file and run it in IDL.
3566 Runs `save-buffer' and sends a '.RUN' command for the associated file to IDL.
3567 When called from the shell buffer, re-run the file which was last handled by
3568 one of the save-and-.. commands."
3570 (idlwave-shell-save-and-action 'run))
3572 (defun idlwave-shell-save-and-compile ()
3573 "Save file and run it in IDL.
3574 Runs `save-buffer' and sends '.COMPILE' command for the associated file to IDL.
3575 When called from the shell buffer, re-compile the file which was last handled by
3576 one of the save-and-.. commands."
3578 (idlwave-shell-save-and-action 'compile))
3580 (defun idlwave-shell-save-and-batch ()
3581 "Save file and batch it in IDL.
3582 Runs `save-buffer' and sends a '@file' command for the associated file to IDL.
3583 When called from the shell buffer, re-batch the file which was last handled by
3584 one of the save-and-.. commands."
3586 (idlwave-shell-save-and-action 'batch))
3588 (defun idlwave-shell-save-and-action (action)
3589 "Save file and compile it in IDL.
3590 Runs `save-buffer' and sends a '.RUN' command for the associated file to IDL.
3591 When called from the shell buffer, re-compile the file which was last
3592 handled by this command."
3593 ;; Remove the stop overlay.
3594 (if idlwave-shell-stop-line-overlay
3595 (delete-overlay idlwave-shell-stop-line-overlay))
3596 (if idlwave-shell-is-stopped
3597 (idlwave-shell-electric-debug-all-off))
3598 (setq idlwave-shell-is-stopped nil)
3599 (setq overlay-arrow-string nil)
3602 ((eq major-mode 'idlwave-mode)
3604 (setq idlwave-shell-last-save-and-action-file (buffer-file-name)))
3605 (idlwave-shell-last-save-and-action-file
3606 (if (setq buf (idlwave-get-buffer-visiting
3607 idlwave-shell-last-save-and-action-file))
3611 (t (setq idlwave-shell-last-save-and-action-file
3612 (read-file-name "File: ")))))
3613 (if (file-regular-p idlwave-shell-last-save-and-action-file)
3615 (idlwave-shell-send-command
3616 (concat (cond ((eq action 'run) ".run ")
3617 ((eq action 'compile) ".compile ")
3618 ((eq action 'batch) "@")
3619 (t (error "Unknown action %s" action)))
3620 idlwave-shell-last-save-and-action-file)
3621 'idlwave-shell-maybe-update-routine-info
3622 (if (idlwave-shell-hide-p 'run) 'mostly) nil t)
3623 (idlwave-shell-bp-query))
3624 (let ((msg (format "No such file %s"
3625 idlwave-shell-last-save-and-action-file)))
3626 (setq idlwave-shell-last-save-and-action-file nil)
3629 (defun idlwave-shell-maybe-update-routine-info (&optional wait)
3630 "Update the routine info if the shell is not stopped at an error."
3631 (if (and (not idlwave-shell-is-stopped)
3632 (or (eq t idlwave-auto-routine-info-updates)
3633 (memq 'compile-buffer idlwave-auto-routine-info-updates))
3634 idlwave-query-shell-for-routine-info
3636 (idlwave-shell-update-routine-info t nil wait)))
3638 (defvar idlwave-shell-sources-query "help,/source,/full"
3639 "IDL command to obtain source files for compiled procedures.")
3641 (defvar idlwave-shell-sources-alist nil
3642 "Alist of IDL procedure names and compiled source files.
3643 Elements of the alist have the form:
3645 (module name . (source-file-truename idlwave-internal-filename)).")
3647 (defun idlwave-shell-sources-query ()
3648 "Determine source files for IDL compiled procedures.
3649 Queries IDL using the string in `idlwave-shell-sources-query'."
3651 (idlwave-shell-send-command idlwave-shell-sources-query
3652 'idlwave-shell-sources-filter
3655 (defun idlwave-shell-sources-filter ()
3656 "Get source files from `idlwave-shell-sources-query' output.
3657 Create `idlwave-shell-sources-alist' consisting of
3658 list elements of the form:
3659 (module name . (source-file-truename idlwave-internal-filename))."
3661 (set-buffer (get-buffer-create idlwave-shell-bp-buffer))
3663 (insert idlwave-shell-command-output)
3664 (goto-char (point-min))
3666 (if (re-search-forward "Compiled Procedures:" nil t)
3668 (forward-line) ; Skip $MAIN$
3669 (setq cpro (point))))
3670 (if (re-search-forward "Compiled Functions:" nil t)
3673 (setq idlwave-shell-sources-alist
3675 ;; compiled procedures
3678 (narrow-to-region cpro (point))
3679 (goto-char (point-min))
3680 (idlwave-shell-sources-grep))
3681 ;; compiled functions
3685 (idlwave-shell-sources-grep)))))))))
3687 (defun idlwave-shell-sources-grep ()
3689 (let ((al (list nil)))
3691 (not (progn (forward-line) (eobp)))
3693 "\\s-*\\(\\S-+\\)\\s-+\\(\\S-+\\)" nil t))
3697 (buffer-substring ; name
3698 (match-beginning 1) (match-end 1))
3699 (let ((internal-filename
3700 (buffer-substring ; source
3701 (match-beginning 2) (match-end 2))))
3703 (idlwave-shell-file-name internal-filename)
3708 (defun idlwave-shell-clear-all-bp ()
3709 "Remove all breakpoints in IDL."
3711 (idlwave-shell-send-command
3712 idlwave-shell-bp-query
3714 (idlwave-shell-filter-bp)
3715 (mapcar 'idlwave-shell-clear-bp idlwave-shell-bp-alist))
3718 (defun idlwave-shell-list-all-bp ()
3719 "List all breakpoints in IDL."
3721 (idlwave-shell-send-command
3722 idlwave-shell-bp-query))
3724 (defvar idlwave-shell-error-last 0
3725 "Position of last syntax error in `idlwave-shell-error-buffer'.")
3727 (defun idlwave-shell-goto-next-error ()
3728 "Move point to next IDL syntax error."
3732 (set-buffer idlwave-shell-error-buffer)
3733 (goto-char idlwave-shell-error-last)
3735 (re-search-forward idlwave-shell-syntax-error nil t)
3736 (re-search-forward idlwave-shell-other-error nil t))
3741 (idlwave-shell-file-name
3742 (buffer-substring (match-beginning 1 )
3745 (buffer-substring (match-beginning 2)
3747 ;; Try to find the column of the error
3750 (if (re-search-backward "\\^" nil t)
3753 (setq idlwave-shell-error-last (point)))
3756 (idlwave-shell-display-line frame col 'no-debug))
3758 (message "No more errors."))))
3760 (defun idlwave-shell-file-name (name)
3761 "If `idlwave-shell-use-truename' is non-nil, convert file name to true name.
3762 Otherwise, just expand the file name."
3763 (let ((def-dir (if (eq major-mode 'idlwave-shell-mode)
3765 idlwave-shell-default-directory)))
3766 (if idlwave-shell-use-truename
3767 (file-truename name def-dir)
3768 (expand-file-name name def-dir))))
3770 ;; Keybindings ------------------------------------------------------------
3772 (defvar idlwave-shell-mode-map (copy-keymap comint-mode-map)
3773 "Keymap for idlwave-mode.")
3774 (defvar idlwave-shell-electric-debug-mode-map (make-sparse-keymap))
3775 (defvar idlwave-shell-mode-prefix-map (make-sparse-keymap))
3776 (fset 'idlwave-shell-mode-prefix-map idlwave-shell-mode-prefix-map)
3777 (defvar idlwave-mode-prefix-map (make-sparse-keymap))
3778 (fset 'idlwave-mode-prefix-map idlwave-mode-prefix-map)
3780 (defun idlwave-shell-define-key-both (key hook)
3781 "Define a key in both the shell and buffer mode maps."
3782 (define-key idlwave-mode-map key hook)
3783 (define-key idlwave-shell-mode-map key hook))
3785 ;(define-key idlwave-shell-mode-map "\M-?" 'comint-dynamic-list-completions)
3786 ;(define-key idlwave-shell-mode-map "\t" 'comint-dynamic-complete)
3787 (define-key idlwave-shell-mode-map "\t" 'idlwave-shell-complete)
3788 (define-key idlwave-shell-mode-map "\M-\t" 'idlwave-shell-complete)
3789 (define-key idlwave-shell-mode-map "\C-c\C-s" 'idlwave-shell)
3790 (define-key idlwave-shell-mode-map "\C-c?" 'idlwave-routine-info)
3791 (define-key idlwave-shell-mode-map "\C-g" 'idlwave-keyboard-quit)
3792 (define-key idlwave-shell-mode-map "\M-?" 'idlwave-context-help)
3793 (define-key idlwave-shell-mode-map [(control meta ?\?)] 'idlwave-online-help)
3794 (define-key idlwave-shell-mode-map "\C-c\C-i" 'idlwave-update-routine-info)
3795 (define-key idlwave-shell-mode-map "\C-c\C-y" 'idlwave-shell-char-mode-loop)
3796 (define-key idlwave-shell-mode-map "\C-c\C-x" 'idlwave-shell-send-char)
3797 (define-key idlwave-shell-mode-map "\C-c=" 'idlwave-resolve)
3798 (define-key idlwave-shell-mode-map "\C-c\C-v" 'idlwave-find-module)
3799 (define-key idlwave-shell-mode-map "\C-c\C-k" 'idlwave-kill-autoloaded-buffers)
3800 (define-key idlwave-shell-mode-map idlwave-shell-prefix-key
3801 'idlwave-shell-debug-map)
3802 (define-key idlwave-shell-mode-map [(up)] 'idlwave-shell-up-or-history)
3803 (define-key idlwave-shell-mode-map [(down)] 'idlwave-shell-down-or-history)
3804 (define-key idlwave-mode-map "\C-c\C-y" 'idlwave-shell-char-mode-loop)
3805 (define-key idlwave-mode-map "\C-c\C-x" 'idlwave-shell-send-char)
3807 ;; The mouse bindings for PRINT and HELP
3808 (idlwave-shell-define-key-both
3809 (if (featurep 'xemacs)
3811 [(shift down-mouse-2)])
3812 'idlwave-shell-mouse-print)
3813 (idlwave-shell-define-key-both
3814 (if (featurep 'xemacs)
3815 [(control meta button2)]
3816 [(control meta down-mouse-2)])
3817 'idlwave-shell-mouse-help)
3818 (idlwave-shell-define-key-both
3819 (if (featurep 'xemacs)
3820 [(control shift button2)]
3821 [(control shift down-mouse-2)])
3822 'idlwave-shell-examine-select)
3823 ;; Add this one from the idlwave-mode-map
3824 (define-key idlwave-shell-mode-map
3825 (if (featurep 'xemacs)
3828 'idlwave-mouse-context-help)
3830 ;; For Emacs, we need to turn off the button release events.
3831 (defun idlwave-shell-mouse-nop (event)
3833 (unless (featurep 'xemacs)
3834 (idlwave-shell-define-key-both
3835 [(shift mouse-2)] 'idlwave-shell-mouse-nop)
3836 (idlwave-shell-define-key-both
3837 [(shift control mouse-2)] 'idlwave-shell-mouse-nop)
3838 (idlwave-shell-define-key-both
3839 [(control meta mouse-2)] 'idlwave-shell-mouse-nop))
3842 ;; The following set of bindings is used to bind the debugging keys.
3843 ;; If `idlwave-shell-activate-prefix-keybindings' is non-nil, the
3844 ;; first key in the list gets bound the C-c C-d prefix map. If
3845 ;; `idlwave-shell-debug-modifiers' is non-nil, the second key in the
3846 ;; list gets bound with the specified modifiers in both
3847 ;; `idlwave-mode-map' and `idlwave-shell-mode-map'. The next list
3848 ;; item, if non-nil, means to bind this as a single key in the
3849 ;; electric-debug-mode-map.
3851 ;; [C-c C-d]-binding debug-modifier-key command bind-electric-debug buf-only
3852 ;; Used keys: abcdef hijklmnopqrstuvwxyz
3855 '(([(control ?b)] ?b idlwave-shell-break-here t t)
3856 ([(control ?i)] ?i idlwave-shell-break-in t t)
3857 ([(control ?j)] ?j idlwave-shell-break-this-module t t)
3858 ([(control ?d)] ?d idlwave-shell-clear-current-bp t)
3859 ([(control ?a)] ?a idlwave-shell-clear-all-bp t)
3860 ([(control ?s)] ?s idlwave-shell-step t)
3861 ([(control ?n)] ?n idlwave-shell-stepover t)
3862 ([(control ?k)] ?k idlwave-shell-skip t)
3863 ([(control ?u)] ?u idlwave-shell-up t)
3864 ([(control ?o)] ?o idlwave-shell-out t)
3865 ([(control ?m)] ?m idlwave-shell-return t)
3866 ([(control ?h)] ?h idlwave-shell-to-here t t)
3867 ([(control ?r)] ?r idlwave-shell-cont t)
3868 ([(control ?y)] ?y idlwave-shell-execute-default-command-line)
3869 ([(control ?z)] ?z idlwave-shell-reset t)
3870 ([(control ?q)] ?q idlwave-shell-quit)
3871 ([(control ?p)] ?p idlwave-shell-print t)
3872 ([( ??)] ?? idlwave-shell-help-expression t)
3873 ([(control ?v)] ?v idlwave-shell-toggle-electric-debug-mode t t)
3874 ([(control ?x)] ?x idlwave-shell-goto-next-error)
3875 ([(control ?c)] ?c idlwave-shell-save-and-run t)
3876 ([( ?@)] ?@ idlwave-shell-save-and-batch)
3877 ([(control ?e)] ?e idlwave-shell-run-region)
3878 ([(control ?w)] ?w idlwave-shell-resync-dirs)
3879 ([(control ?l)] ?l idlwave-shell-redisplay t)
3880 ([(control ?t)] ?t idlwave-shell-toggle-toolbar)
3881 ([(control up)] up idlwave-shell-stack-up)
3882 ([(control down)] down idlwave-shell-stack-down)
3883 ([( ?[)] ?[ idlwave-shell-goto-previous-bp t t)
3884 ([( ?])] ?] idlwave-shell-goto-next-bp t t)
3885 ([(control ?f)] ?f idlwave-shell-window)))
3886 (mod (cond ((and idlwave-shell-debug-modifiers
3887 (listp idlwave-shell-debug-modifiers)
3888 (not (equal '() idlwave-shell-debug-modifiers)))
3889 idlwave-shell-debug-modifiers)
3890 (idlwave-shell-activate-alt-keybindings
3892 (shift (memq 'shift mod))
3893 (mod-noshift (delete 'shift (copy-sequence mod)))
3894 s k1 c2 k2 cmd cannotshift)
3895 (while (setq s (pop specs))
3900 only-buffer (nth 4 s)
3901 cannotshift (and shift (char-valid-p c2) (eq c2 (upcase c2))))
3903 ;; The regular prefix keymap.
3904 (when (and idlwave-shell-activate-prefix-keybindings k1)
3906 (define-key idlwave-shell-mode-prefix-map k1 cmd))
3907 (define-key idlwave-mode-prefix-map k1 cmd))
3908 ;; The debug modifier map
3909 (when (and mod window-system)
3910 (if (char-or-string-p c2)
3911 (setq k2 (vector (append mod-noshift
3912 (list (if shift (upcase c2) c2)))))
3913 (setq k2 (vector (append mod (list c2)))))
3915 (define-key idlwave-mode-map k2 cmd)
3916 (unless only-buffer (define-key idlwave-shell-mode-map k2 cmd))))
3917 ;; The electric debug single-keystroke map
3918 (if (and electric (char-or-string-p c2))
3919 (define-key idlwave-shell-electric-debug-mode-map (char-to-string c2)
3922 ;; A few extras in the electric debug map
3923 (define-key idlwave-shell-electric-debug-mode-map " " 'idlwave-shell-step)
3924 (define-key idlwave-shell-electric-debug-mode-map "+" 'idlwave-shell-stack-up)
3925 (define-key idlwave-shell-electric-debug-mode-map "=" 'idlwave-shell-stack-up)
3926 (define-key idlwave-shell-electric-debug-mode-map "-"
3927 'idlwave-shell-stack-down)
3928 (define-key idlwave-shell-electric-debug-mode-map "_"
3929 'idlwave-shell-stack-down)
3930 (define-key idlwave-shell-electric-debug-mode-map "q" 'idlwave-shell-retall)
3931 (define-key idlwave-shell-electric-debug-mode-map "t"
3932 '(lambda () (interactive) (idlwave-shell-send-command "help,/TRACE")))
3933 (define-key idlwave-shell-electric-debug-mode-map [(control ??)]
3934 'idlwave-shell-electric-debug-help)
3935 (define-key idlwave-shell-electric-debug-mode-map "x"
3936 '(lambda (arg) (interactive "P")
3937 (idlwave-shell-print arg nil nil t)))
3939 ; Enter the prefix map in two places.
3940 (fset 'idlwave-debug-map idlwave-mode-prefix-map)
3941 (fset 'idlwave-shell-debug-map idlwave-shell-mode-prefix-map)
3943 ;; The Electric Debug Minor Mode --------------------------------------------
3945 (defun idlwave-shell-toggle-electric-debug-mode ()
3946 "Toggle electric-debug-mode, suppressing re-entry into mode if turned off."
3948 ;; If turning it off, make sure it stays off throughout the debug
3949 ;; session until we return or hit $MAIN$. Cancel this suppression
3950 ;; if it's explicitly turned on.
3951 (if idlwave-shell-electric-debug-mode
3952 (setq idlwave-shell-suppress-electric-debug t)
3953 (setq idlwave-shell-suppress-electric-debug nil))
3954 (idlwave-shell-electric-debug-mode))
3956 (easy-mmode-define-minor-mode idlwave-shell-electric-debug-mode
3957 "Toggle Electric Debug mode.
3958 With no argument, this command toggles the mode.
3959 Non-null prefix argument turns on the mode.
3960 Null prefix argument turns off the mode.
3962 When Electric Debug mode is enabled, the many debugging commands are
3963 available as single key sequences."
3966 idlwave-shell-electric-debug-mode-map)
3969 'idlwave-shell-electric-debug-mode-on-hook
3971 (set (make-local-variable 'idlwave-shell-electric-debug-read-only)
3973 (setq buffer-read-only t)
3974 (add-to-list 'idlwave-shell-electric-debug-buffers (current-buffer))
3975 (if idlwave-shell-stop-line-overlay
3976 (overlay-put idlwave-shell-stop-line-overlay 'face
3977 idlwave-shell-electric-stop-line-face))
3979 (set-face-foreground 'fringe idlwave-shell-electric-stop-color
3980 (selected-frame)))))
3983 'idlwave-shell-electric-debug-mode-off-hook
3985 ;; Return to previous read-only state
3986 (setq buffer-read-only (if (boundp 'idlwave-shell-electric-debug-read-only)
3987 idlwave-shell-electric-debug-read-only))
3988 (setq idlwave-shell-electric-debug-buffers
3989 (delq (current-buffer) idlwave-shell-electric-debug-buffers))
3990 (if idlwave-shell-stop-line-overlay
3991 (overlay-put idlwave-shell-stop-line-overlay 'face
3992 idlwave-shell-stop-line-face)
3994 (set-face-foreground 'fringe (face-foreground 'default))))))
3996 ;; easy-mmode defines electric-debug-mode for us, so we need to advise it.
3997 (defadvice idlwave-shell-electric-debug-mode (after print-enter activate)
3998 "Print out an entrance message"
3999 (when idlwave-shell-electric-debug-mode
4001 "Electric Debugging mode entered. Press [C-?] for help, [q] to quit"))
4002 (force-mode-line-update))
4004 ;; Turn it off in all relevant buffers
4005 (defvar idlwave-shell-electric-debug-buffers nil)
4006 (defun idlwave-shell-electric-debug-all-off ()
4007 (setq idlwave-shell-suppress-electric-debug nil)
4008 (let ((buffers idlwave-shell-electric-debug-buffers)
4011 (while (setq buf (pop buffers))
4012 (when (buffer-live-p buf)
4014 (when (and (eq major-mode 'idlwave-mode)
4016 idlwave-shell-electric-debug-mode)
4017 (idlwave-shell-electric-debug-mode))))))
4018 (setq idlwave-shell-electric-debug-buffers nil))
4020 ;; Show the help text
4021 (defun idlwave-shell-electric-debug-help ()
4023 (with-output-to-temp-buffer "*IDLWAVE Electric Debug Help*"
4024 (princ idlwave-shell-electric-debug-help))
4025 (let* ((current-window (selected-window))
4026 (window (get-buffer-window "*IDLWAVE Electric Debug Help*"))
4027 (window-lines (window-height window)))
4028 (select-window window)
4029 (enlarge-window (1+ (- (count-lines 1 (point-max)) window-lines)))
4030 (select-window current-window)))
4033 ;; The Menus --------------------------------------------------------------
4034 (defvar idlwave-shell-menu-def
4036 ["Electric Debug Mode"
4037 idlwave-shell-electric-debug-mode
4038 :style toggle :selected idlwave-shell-electric-debug-mode
4039 :included (eq major-mode 'idlwave-mode) :keys "C-c C-d C-v"]
4040 ["--" nil (eq major-mode 'idlwave-mode)]
4042 ["Save and .RUN" idlwave-shell-save-and-run
4043 (or (eq major-mode 'idlwave-mode)
4044 idlwave-shell-last-save-and-action-file)]
4045 ["Save and .COMPILE" idlwave-shell-save-and-compile
4046 (or (eq major-mode 'idlwave-mode)
4047 idlwave-shell-last-save-and-action-file)]
4048 ["Save and @Batch" idlwave-shell-save-and-batch
4049 (or (eq major-mode 'idlwave-mode)
4050 idlwave-shell-last-save-and-action-file)]
4052 ["Goto Next Error" idlwave-shell-goto-next-error t]
4054 ["Compile and Run Region" idlwave-shell-run-region
4055 (eq major-mode 'idlwave-mode)]
4056 ["Evaluate Region" idlwave-shell-evaluate-region
4057 (eq major-mode 'idlwave-mode)]
4059 ["Execute Default Cmd" idlwave-shell-execute-default-command-line t]
4060 ["Edit Default Cmd" idlwave-shell-edit-default-command-line t])
4062 ["Set Breakpoint" idlwave-shell-break-here
4063 :keys "C-c C-d C-c" :active (eq major-mode 'idlwave-mode)]
4064 ["Break in Module" idlwave-shell-break-in
4065 :keys "C-c C-d C-i" :active (eq major-mode 'idlwave-mode)]
4066 ["Break in this Module" idlwave-shell-break-this-module
4067 :keys "C-c C-d C-j" :active (eq major-mode 'idlwave-mode)]
4068 ["Clear Breakpoint" idlwave-shell-clear-current-bp t]
4069 ["Clear All Breakpoints" idlwave-shell-clear-all-bp t]
4070 ["Goto Previous Breakpoint" idlwave-shell-goto-previous-bp
4071 :keys "C-c C-d [" :active (eq major-mode 'idlwave-mode)]
4072 ["Goto Next Breakpoint" idlwave-shell-goto-next-bp
4073 :keys "C-c C-d ]" :active (eq major-mode 'idlwave-mode)]
4074 ["List All Breakpoints" idlwave-shell-list-all-bp t])
4076 ["Step (into)" idlwave-shell-step t]
4077 ["Step (over)" idlwave-shell-stepover t]
4078 ["Skip One Statement" idlwave-shell-skip t]
4079 ["Continue" idlwave-shell-cont t]
4080 ["... to End of Block" idlwave-shell-up t]
4081 ["... to End of Subprog" idlwave-shell-return t]
4082 ["... to End of Subprog+1" idlwave-shell-out t]
4083 ["... to Here (Cursor Line)" idlwave-shell-to-here
4084 :keys "C-c C-d C-h" :active (eq major-mode 'idlwave-mode)])
4085 ("Examine Expressions"
4086 ["Print expression" idlwave-shell-print t]
4087 ["Help on expression" idlwave-shell-help-expression t]
4088 ("Examine nearby expression with"
4089 ,@(mapcar (lambda(x)
4090 `[ ,(car x) (idlwave-shell-print nil ',x) t ])
4091 idlwave-shell-examine-alist))
4092 ("Examine region with"
4093 ,@(mapcar (lambda(x)
4094 `[ ,(car x) (idlwave-shell-print '(4) ',x) t ])
4095 idlwave-shell-examine-alist)))
4097 ["Stack Up" idlwave-shell-stack-up t]
4098 ["Stack Down" idlwave-shell-stack-down t]
4100 ["Redisplay and Sync" idlwave-shell-redisplay t])
4102 ["Everything" (if (eq idlwave-shell-show-commands 'everything)
4104 (setq idlwave-shell-show-commands
4105 (get 'idlwave-shell-show-commands 'last-val))
4106 (put 'idlwave-shell-show-commands 'last-val nil))
4107 (put 'idlwave-shell-show-commands 'last-val
4108 idlwave-shell-show-commands)
4109 (setq idlwave-shell-show-commands 'everything))
4110 :style toggle :selected (and (not (listp idlwave-shell-show-commands))
4111 (eq idlwave-shell-show-commands
4114 ["Compiling Commands" (idlwave-shell-add-or-remove-show 'run)
4116 :selected (not (idlwave-shell-hide-p
4118 (get 'idlwave-shell-show-commands 'last-val)))
4119 :active (not (eq idlwave-shell-show-commands 'everything))]
4120 ["Breakpoint Commands" (idlwave-shell-add-or-remove-show 'breakpoint)
4122 :selected (not (idlwave-shell-hide-p
4124 (get 'idlwave-shell-show-commands 'last-val)))
4125 :active (not (eq idlwave-shell-show-commands 'everything))]
4126 ["Debug Commands" (idlwave-shell-add-or-remove-show 'debug)
4128 :selected (not (idlwave-shell-hide-p
4130 (get 'idlwave-shell-show-commands 'last-val)))
4131 :active (not (eq idlwave-shell-show-commands 'everything))]
4132 ["Miscellaneous Commands" (idlwave-shell-add-or-remove-show 'misc)
4134 :selected (not (idlwave-shell-hide-p
4136 (get 'idlwave-shell-show-commands 'last-val)))
4137 :active (not (eq idlwave-shell-show-commands 'everything))])
4139 ["Send one char" idlwave-shell-send-char t]
4140 ["Temporary Character Mode" idlwave-shell-char-mode-loop t]
4142 ["Use Input Mode Magic"
4143 (setq idlwave-shell-use-input-mode-magic
4144 (not idlwave-shell-use-input-mode-magic))
4145 :style toggle :selected idlwave-shell-use-input-mode-magic])
4147 ["Update Working Dir" idlwave-shell-resync-dirs t]
4148 ["Save Path Info" idlwave-write-paths idlwave-path-alist]
4149 ["Reset IDL" idlwave-shell-reset t]
4151 ["Toggle Toolbar" idlwave-shell-toggle-toolbar t]
4152 ["Exit IDL" idlwave-shell-quit t]))
4154 (if (or (featurep 'easymenu) (load "easymenu" t))
4157 idlwave-mode-debug-menu idlwave-mode-map "IDL debugging menus"
4158 idlwave-shell-menu-def)
4160 idlwave-shell-mode-menu idlwave-shell-mode-map "IDL shell menus"
4161 idlwave-shell-menu-def)
4163 (mapcar (lambda (buf)
4165 (if (eq major-mode 'idlwave-mode)
4167 (easy-menu-remove idlwave-mode-debug-menu)
4168 (easy-menu-add idlwave-mode-debug-menu))))
4171 ;; The Breakpoint Glyph -------------------------------------------------------
4173 (defvar idlwave-shell-bp-glyph nil
4174 "The glyphs to mark breakpoint lines in the source code.")
4178 static char * file[] = {
4180 \" c None s backgroundColor\",
4181 \". c #4B4B4B4B4B4B\",
4182 \"R c #FFFF00000000\",
4195 (bp-cond . "/* XPM */
4196 static char * file[] = {
4198 \" c None s backgroundColor\",
4199 \". c #4B4B4B4B4B4B\",
4200 \"R c #FFFF00000000\",
4201 \"B c #000000000000\",
4215 static char * file[] = {
4217 \" c None s backgroundColor\",
4218 \". c #4B4B4B4B4B4B\",
4219 \"X c #FFFF00000000\",
4220 \"o c #000000000000\",
4234 static char * file[] = {
4236 \" c None s backgroundColor\",
4237 \". c #4B4B4B4B4B4B\",
4238 \"X c #FFFF00000000\",
4239 \"o c #000000000000\",
4253 static char * file[] = {
4255 \" c None s backgroundColor\",
4256 \". c #4B4B4B4B4B4B\",
4257 \"X c #FFFF00000000\",
4258 \"o c #000000000000\",
4272 static char * file[] = {
4274 \" c None s backgroundColor\",
4275 \". c #4B4B4B4B4B4B\",
4276 \"X c #FFFF00000000\",
4277 \"o c #000000000000\",
4291 static char * file[] = {
4293 \" c None s backgroundColor\",
4294 \". c #4B4B4B4B4B4B\",
4295 \"X c #FFFF00000000\",
4296 \"o c #000000000000\",
4308 \" \"};"))) im-cons im)
4310 (while (setq im-cons (pop image-alist))
4311 (setq im (cond ((and (featurep 'xemacs)
4313 (make-glyph (cdr im-cons)))
4314 ((and (not (featurep 'xemacs))
4315 (fboundp 'image-type-available-p)
4316 (image-type-available-p 'xpm))
4317 (list 'image :type 'xpm :data (cdr im-cons)
4320 (if im (push (cons (car im-cons) im) idlwave-shell-bp-glyph))))
4322 (provide 'idlw-shell)
4323 (provide 'idlwave-shell)
4325 ;;; Load the toolbar when wanted by the user.
4327 (autoload 'idlwave-toolbar-toggle "idlw-toolbar"
4328 "Toggle the IDLWAVE toolbar")
4329 (autoload 'idlwave-toolbar-add-everywhere "idlw-toolbar"
4330 "Add IDLWAVE toolbar")
4331 (defun idlwave-shell-toggle-toolbar ()
4332 "Toggle the display of the debugging toolbar."
4334 (idlwave-toolbar-toggle))
4336 (if idlwave-shell-use-toolbar
4337 (add-hook 'idlwave-shell-mode-hook 'idlwave-toolbar-add-everywhere))
4338 ;;; idlw-shell.el ends here