1 ;;; idlw-shell.el --- Run IDL or WAVE as an inferior process of Emacs.
2 ;; Copyright (c) 1994-1996 Chris Chase
3 ;; Copyright (c) 1999 Carsten Dominik
4 ;; Copyright (c) 1999, 2000 Free Software Foundation
6 ;; Author: Chris Chase <chase@att.com>
7 ;; Maintainer: Carsten Dominik <dominik@strw.leidenuniv.nl>
9 ;; Date: $Date: 2000/06/15 17:58:23 $
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 4 or later. It should work on Emacs
32 ;; or XEmacs version 19 or later.
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'.
46 ;; Follow the instructions in the INSTALL file of the distribution.
47 ;; In short, put this file on your load path and add the following
48 ;; lines to your .emacs file:
50 ;; (autoload 'idlwave-shell "idlw-shell" "IDLWAVE Shell" t)
56 ;; The newest version of this file can be found on the maintainers
59 ;; http://www.strw.leidenuniv.el/~dominik/Tools/idlwave
64 ;; IDLWAVE is documented online in info format.
65 ;; A printable version of the documentation is available from the
66 ;; maintainers webpage (see under SOURCE)
72 ;; I don't plan on implementing directory tracking by watching the IDL
73 ;; commands entered at the prompt, since too often an IDL procedure
74 ;; will change the current directory. If you want the the idl process
75 ;; buffer to match the IDL current working just execute `M-x
76 ;; idlwave-shell-resync-dirs' (bound to "\C-c\C-d\C-w" by default.)
78 ;; Under XEmacs the Debug menu in the shell does not display the
79 ;; keybindings in the prefix map. There bindings are available anyway - so
80 ;; it is a bug in XEmacs.
81 ;; The Debug menu in source buffers *does* display the bindings correctly.
84 ;; CUSTOMIZATION VARIABLES
85 ;; =======================
87 ;; IDLWAVE has customize support - so if you want to learn about
88 ;; the variables which control the behavior of the mode, use
89 ;; `M-x idlwave-customize'.
91 ;;--------------------------------------------------------------------------
100 (eval-when-compile (require 'cl))
102 (defvar idlwave-shell-have-new-custom nil)
104 ;; Kludge to allow `defcustom' for Emacs 19.
105 (condition-case () (require 'custom) (error nil))
106 (if (and (featurep 'custom)
107 (fboundp 'custom-declare-variable)
109 ;; We've got what we needed
110 (setq idlwave-shell-have-new-custom t)
111 ;; We have the old or no custom-library, hack around it!
112 (defmacro defgroup (&rest args) nil)
113 (defmacro defcustom (var value doc &rest args)
114 (` (defvar (, var) (, value) (, doc))))))
116 ;;; Customizations: idlwave-shell group
118 (defgroup idlwave-shell-general-setup nil
119 "Indentation options for IDL/WAVE mode."
123 (defcustom idlwave-shell-prompt-pattern "^ ?IDL> "
124 "*Regexp to match IDL prompt at beginning of a line.
125 For example, \"^IDL> \" or \"^WAVE> \".
126 The \"^\" means beginning of line.
127 This variable is used to initialise `comint-prompt-regexp' in the
130 This is a fine thing to set in your `.emacs' file."
131 :group 'idlwave-shell-general-setup
134 (defcustom idlwave-shell-process-name "idl"
135 "*Name to be associated with the IDL process. The buffer for the
136 process output is made by surrounding this name with `*'s."
137 :group 'idlwave-shell-general-setup
140 (defcustom idlwave-shell-automatic-start nil
141 "*If non-nil attempt invoke idlwave-shell if not already running.
142 This is checked when an attempt to send a command to an
143 IDL process is made."
144 :group 'idlwave-shell-general-setup
147 (defcustom idlwave-shell-initial-commands "!more=0"
148 "Initial commands, separated by newlines, to send to IDL.
149 This string is sent to the IDL process by `idlwave-shell-mode' which is
150 invoked by `idlwave-shell'."
151 :group 'idlwave-shell-initial-commands
154 (defcustom idlwave-shell-use-dedicated-frame nil
155 "*Non-nil means, IDLWAVE should use a special frame to display shell buffer."
156 :group 'idlwave-shell-general-setup
159 (defcustom idlwave-shell-frame-parameters
160 '((height . 30) (unsplittable . nil))
161 "The frame parameters for a dedicated idlwave-shell frame.
162 See also `idlwave-shell-use-dedicated-frame'.
163 The default makes the frame splittable, so that completion works correctly."
164 :group 'idlwave-shell-general-setup
168 (defcustom idlwave-shell-use-toolbar t
169 "Non-nil means, use the debugging toolbar in all IDL related buffers.
170 Starting the shell will then add the toolbar to all idlwave-mode buffers.
171 Exiting the shell will removed everywhere.
172 Available on XEmacs and on Emacs 21.x or later.
173 At any time you can toggle the display of the toolbar with
174 `C-c C-d C-t' (`idlwave-shell-toggle-toolbar')."
175 :group 'idlwave-shell-general-setup
178 (defcustom idlwave-shell-temp-pro-prefix "/tmp/idltemp"
179 "*The prefix for temporary IDL files used when compiling regions.
180 It should be an absolute pathname.
181 The full temporary file name is obtained by to using `make-temp-name'
182 so that the name will be unique among multiple Emacs processes."
183 :group 'idlwave-shell-general-setup
186 (defvar idlwave-shell-fix-inserted-breaks nil
187 "*OBSOLETE VARIABLE, is no longer used.
189 The documentation of this variable used to be:
190 If non-nil then run `idlwave-shell-remove-breaks' to clean up IDL messages.")
192 (defcustom idlwave-shell-prefix-key "\C-c\C-d"
193 "*The prefix key for the debugging map `idlwave-shell-mode-prefix-map'.
194 This variable must already be set when idlwave-shell.el is loaded.
195 Seting it in the mode-hook is too late."
196 :group 'idlwave-shell-general-setup
199 (defcustom idlwave-shell-activate-prefix-keybindings t
200 "Non-nil means, the debug commands will be bound to the prefix key.
201 The prefix key itself is given in the option `idlwave-shell-prefix-key'.
202 So by default setting a breakpoint will be on C-c C-d C-b."
203 :group 'idlwave-shell-general-setup
206 (defcustom idlwave-shell-activate-alt-keybindings nil
207 "Non-nil means, the debug commands will be bound to alternate keys.
208 So for example setting a breakpoint will be on A-b."
209 :group 'idlwave-shell-general-setup
212 (defcustom idlwave-shell-use-truename nil
213 "*Non-nil means, use use `file-truename' when looking for buffers.
214 If this variable is non-nil, Emacs will use the function `file-truename' to
215 resolve symbolic links in the file paths printed by e.g., STOP commands.
216 This means, unvisited files will be loaded under their truename.
217 However, when a file is already visited under a different name, IDLWAVE will
219 This option was once introduced in order to avoid multiple buffers visiting
220 the same file. However, IDLWAVE no longer makes this mistake, so it is safe
221 to set this option to nil."
222 :group 'idlwave-shell-general-setup
225 (defcustom idlwave-shell-file-name-chars "~/A-Za-z0-9+@:_.$#%={}-"
226 "The characters allowed in file names, as a string.
227 Used for file name completion. Must not contain `'', `,' and `\"'
228 because these are used as separators by IDL."
229 :group 'idlwave-shell-general-setup
232 (defcustom idlwave-shell-mode-hook '()
233 "*Hook for customising `idlwave-shell-mode'."
234 :group 'idlwave-shell-general-setup
237 (defcustom idlwave-shell-print-expression-function nil
238 "When non-nil, a function to handle display of evaluated expressions.
239 This can be used to arrange for displaying the value of an expression
240 in (e.g.) a special frame. The function must accept one argument:
241 the expression which was evaluated. The output from IDL will be
242 available in the variable `idlwave-shell-command-output'."
243 :group 'idlwave-shell-highlighting-and-faces
246 (defcustom idlwave-shell-use-input-mode-magic nil
247 "*Non-nil means, IDLWAVE should check for input mode spells in output.
248 The spells are strings printed by your IDL program and matched
249 by the regular expressions in `idlwave-shell-input-mode-spells'.
250 When these expressions match, IDLWAVE switches to character input mode and
251 back, respectively. See `idlwave-shell-input-mode-spells' for details."
252 :group 'idlwave-shell-general-setup
255 (defcustom idlwave-shell-input-mode-spells
256 '("^<onechar>$" "^<chars>$" "^</chars>$")
257 "The three regular expressions which match the magic spells for input modes.
259 When the first regexp matches in the output streem of IDL, IDLWAVE
260 prompts for a single character and sends it immediately to IDL, similar
261 to the command \\[idlwave-shell-send-char].
263 When the second regexp matches, IDLWAVE switches to a blocking
264 single-character input mode. This is the same mode which can be entered
265 manually with \\[idlwave-shell-char-mode-loop].
266 This input mode exits when the third regexp matches in the output,
267 or when the IDL prompt is encountered.
269 The variable `idlwave-shell-use-input-mode-magic' must be non-nil to enable
270 scanning for these expressions. If the IDL program produces lots of
271 output, shell operation may be slowed down.
273 This mechanism is useful for correct interaction with the IDL function
274 GET_KBRD, because in normal operation IDLWAVE only sends \\n terminated
275 strings. Here is some example code which makes use of teh default spells.
277 print,'<chars>' ; Make IDLWAVE switch to character mode
281 ENDREP UNTIL A EQ 'q'
282 print,'</chars>' ; Make IDLWAVE switch back to line mode
284 print,'Quit the program, y or n?'
285 print,'<onechar>' ; Ask IDLWAVE to send one character
288 Since the IDLWAVE shell defines the system variable `!IDLWAVE_VERSION',
289 you could actually check if you are running under Emacs before printing
290 the magic strings. Here is a procedure which uses this.
294 idlwave_char_input ; Make IDLWAVE send one character
295 idlwave_char_input,/on ; Start the loop to send characters
296 idlwave_char_input,/off ; End the loop to send chracters
299 pro idlwave_char_input,on=on,off=off
300 ;; Test if we are running under Emacs
301 defsysv,'!idlwave_version',exists=running_emacs
302 if running_emacs then begin
303 if keyword_set(on) then print,'<chars>' $
304 else if keyword_set(off) then print,'</chars>' $
305 else print,'<onechar>'
308 :group 'idlwave-shell-general-setup
310 (regexp :tag "One-char regexp")
311 (regexp :tag "Char-mode regexp")
312 (regexp :tag "Line-mode regexp")))
314 ;;; Breakpoint Overlays etc
316 (defgroup idlwave-shell-highlighting-and-faces nil
317 "Indentation options for IDL/WAVE mode."
321 (defcustom idlwave-shell-mark-stop-line t
322 "*Non-nil means, mark the source code line where IDL is currently stopped.
323 Value decides about the method which is used to mark the line. Legal values
326 nil Do not mark the line
327 'arrow Use the overlay arrow
328 'face Use `idlwave-shell-stop-line-face' to highlight the line.
329 t Use what IDLWAVE things is best. Will be a face where possible,
330 otherwise the overlay arrow.
331 The overlay-arrow has the disadvantage to hide the first chars of a line.
332 Since many people do not have the main block of IDL programs indented,
333 a face highlighting may be better.
334 On Emacs 21, the overlay arrow is displayed in a special area and never
335 hides any code, so setting this to 'arrow on Emacs 21 sounds like a good idea."
336 :group 'idlwave-shell-highlighting-and-faces
338 (const :tag "No marking" nil)
339 (const :tag "Use overlay arrow" arrow)
340 (const :tag "Highlight with face" face)
341 (const :tag "Face or arrow." t)))
343 (defcustom idlwave-shell-overlay-arrow ">"
344 "*The overlay arrow to display at source lines where execution halts.
345 We use a single character by default, since the main block of IDL procedures
346 often has no indentation. Where possible, IDLWAVE will use overlays to
347 display the stop-lines. The arrow is only used on character-based terminals.
348 See also `idlwave-shell-use-overlay-arrow'."
349 :group 'idlwave-shell-highlighting-and-faces
352 (defcustom idlwave-shell-stop-line-face 'highlight
353 "*The face for `idlwave-shell-stop-line-overlay'.
354 Allows you to choose the font, color and other properties for
355 line where IDL is stopped. See also `idlwave-shell-mark-stop-line'."
356 :group 'idlwave-shell-highlighting-and-faces
359 (defcustom idlwave-shell-mark-breakpoints t
360 "*Non-nil means, mark breakpoints in the source files.
362 nil Do not mark breakpoints.
363 'face Highlight line with `idlwave-shell-breakpoint-face'.
364 'glyph Red dot at the beginning of line. If the display does not
365 support glyphs, will use 'face instead.
366 t Glyph when possible, otherwise face (same effect as 'glyph)."
367 :group 'idlwave-shell-highlighting-and-faces
369 (const :tag "No marking" nil)
370 (const :tag "Highlight with face" face)
371 (const :tag "Display glyph (red dot)" glyph)
372 (const :tag "Glyph or face." t)))
374 (defvar idlwave-shell-use-breakpoint-glyph t
375 "Obsolete variable. See `idlwave-shell-mark-breakpoints.")
377 (defcustom idlwave-shell-breakpoint-face 'idlwave-shell-bp-face
378 "*The face for breakpoint lines in the source code.
379 Allows you to choose the font, color and other properties for
380 lines which have a breakpoint. See also `idlwave-shell-mark-breakpoints'."
381 :group 'idlwave-shell-highlighting-and-faces
384 (if idlwave-shell-have-new-custom
385 ;; We have the new customize - use it to define a customizable face
386 (defface idlwave-shell-bp-face
387 '((((class color)) (:foreground "Black" :background "Pink"))
389 "Face for highlighting lines-with-breakpoints."
390 :group 'idlwave-shell-highlighting-and-faces)
391 ;; Just copy the underline face to be on the safe side.
392 (copy-face 'underline 'idlwave-shell-bp-face))
394 (defcustom idlwave-shell-expression-face 'secondary-selection
395 "*The face for `idlwave-shell-expression-overlay'.
396 Allows you to choose the font, color and other properties for
397 the expression printed by IDL."
398 :group 'idlwave-shell-highlighting-and-faces
401 ;;; End user customization variables
403 ;;; External variables
404 (defvar comint-last-input-start)
405 (defvar comint-last-input-end)
409 (defvar idlwave-shell-temp-file-base
410 (make-temp-name idlwave-shell-temp-pro-prefix)
411 "Base name of the temporary files.")
413 (defvar idlwave-shell-temp-pro-file
414 (concat idlwave-shell-temp-file-base ".pro")
415 "Absolute pathname for temporary IDL file for compiling regions")
417 (defvar idlwave-shell-temp-rinfo-save-file
418 (concat idlwave-shell-temp-file-base ".sav")
419 "Absolute pathname for temporary IDL file save file for routine_info.
420 This is used to speed up the reloading of the routine info procedure
421 before use by the shell.")
424 (defvar idlwave-shell-dirstack-query "printd"
425 "Command used by `idlwave-shell-resync-dirs' to query IDL for
426 the directory stack.")
428 (defvar idlwave-shell-path-query "__pa=expand_path(!path,/array)&for i=0,n_elements(__pa)-1 do print,'PATH:',__pa[i]&print,'SYSDIR:',!dir"
429 "The command which gets !PATH and !DIR infor from the shell.")
431 (defvar idlwave-shell-mode-line-info nil
432 "Additional info displayed in the mode line")
434 (defvar idlwave-shell-default-directory nil
435 "The default directory in the idlwave-shell buffer, of outside use.")
437 (defvar idlwave-shell-last-save-and-action-file nil
438 "The last file which was compiled with `idlwave-shell-save-and-...'.")
440 ;; Highlighting uses overlays. When necessary, require the emulation.
441 (if (not (fboundp 'make-overlay))
446 (defvar idlwave-shell-stop-line-overlay nil
447 "The overlay for where IDL is currently stopped.")
448 (defvar idlwave-shell-is-stopped nil)
449 (defvar idlwave-shell-expression-overlay nil
450 "The overlay for where IDL is currently stopped.")
451 ;; If these were already overlays, delete them. This probably means that we
452 ;; are reloading this file.
453 (if (overlayp idlwave-shell-stop-line-overlay)
454 (delete-overlay idlwave-shell-stop-line-overlay))
455 (if (overlayp idlwave-shell-expression-overlay)
456 (delete-overlay idlwave-shell-expression-overlay))
457 ;; Set to nil initially
458 (setq idlwave-shell-stop-line-overlay nil
459 idlwave-shell-expression-overlay nil)
461 ;; Define the shell stop overlay. When left nil, the arrow will be used.
463 ((or (null idlwave-shell-mark-stop-line)
464 (eq idlwave-shell-mark-stop-line 'arrow))
465 ;; Leave the overlay nil
468 ((eq idlwave-shell-mark-stop-line 'face)
469 ;; Try to use a face. If not possible, arrow will be used anyway
470 ;; So who can display faces?
471 (when (or (featurep 'xemacs) ; XEmacs can do also ttys
472 (fboundp 'tty-defined-colors) ; Emacs 21 as well
473 window-system) ; Window systems always
475 (setq idlwave-shell-stop-line-overlay (make-overlay 1 1))
476 (overlay-put idlwave-shell-stop-line-overlay
477 'face idlwave-shell-stop-line-face))))
480 ;; IDLWAVE may decide. Will use a face on window systems, arrow elsewhere
483 (setq idlwave-shell-stop-line-overlay (make-overlay 1 1))
484 (overlay-put idlwave-shell-stop-line-overlay
485 'face idlwave-shell-stop-line-face)))))
487 ;; Now the expression overlay
488 (setq idlwave-shell-expression-overlay (make-overlay 1 1))
489 (overlay-put idlwave-shell-expression-overlay
490 'face idlwave-shell-expression-face)
491 (defvar idlwave-shell-bp-query "help,/breakpoints"
492 "Command to obtain list of breakpoints")
494 (defvar idlwave-shell-command-output nil
495 "String for accumulating current command output.")
497 (defvar idlwave-shell-post-command-hook nil
498 "Lisp list expression or function to run when an IDL command is finished.
499 The current command is finished when the IDL prompt is displayed.
500 This is evaluated if it is a list or called with funcall.")
502 (defvar idlwave-shell-hide-output nil
503 "If non-nil the process output is not inserted into the output
506 (defvar idlwave-shell-accumulation nil
507 "Accumulate last line of output.")
509 (defvar idlwave-shell-command-line-to-execute nil)
510 (defvar idlwave-shell-cleanup-hook nil
511 "List of functions to do cleanup when the shell exits.")
513 (defvar idlwave-shell-pending-commands nil
514 "List of commands to be sent to IDL.
515 Each element of the list is list of \(CMD PCMD HIDE\), where CMD is a
516 string to be sent to IDL and PCMD is a post-command to be placed on
517 `idlwave-shell-post-command-hook'. If HIDE is non-nil, hide the output
518 from command CMD. PCMD and HIDE are optional.")
520 (defun idlwave-shell-buffer ()
521 "Name of buffer associated with IDL process.
522 The name of the buffer is made by surrounding `idlwave-shell-process-name
524 (concat "*" idlwave-shell-process-name "*"))
526 (defvar idlwave-shell-ready nil
527 "If non-nil can send next command to IDL process.")
529 ;;; The following are the types of messages we attempt to catch to
530 ;;; resync our idea of where IDL execution currently is.
533 (defvar idlwave-shell-halt-frame nil
534 "The frame associated with halt/breakpoint messages.")
536 (defvar idlwave-shell-step-frame nil
537 "The frame associated with step messages.")
539 (defvar idlwave-shell-trace-frame nil
540 "The frame associated with trace messages.")
542 (defconst idlwave-shell-halt-messages
543 '("^% Execution halted at"
547 "^% Stop encountered:"
549 "*A list of regular expressions matching IDL messages.
550 These are the messages containing file and line information where
551 IDL is currently stopped.")
553 (defconst idlwave-shell-halt-messages-re
554 (mapconcat 'identity idlwave-shell-halt-messages "\\|")
555 "The regular expression computed from idlwave-shell-halt-messages")
557 (defconst idlwave-shell-trace-messages
558 '("^% At " ;; First line of a trace message
560 "*A list of regular expressions matching IDL trace messages.
561 These are the messages containing file and line information where
562 IDL will begin looking for the next statement to execute.")
564 (defconst idlwave-shell-step-messages
567 "*A list of regular expressions matching stepped execution messages.
568 These are IDL messages containing file and line information where
569 IDL has currently stepped.")
571 (defvar idlwave-shell-break-message "^% Breakpoint at:"
572 "*Regular expression matching an IDL breakpoint message line.")
575 (defvar idlwave-shell-bp-alist)
576 ;(defvar idlwave-shell-post-command-output)
577 (defvar idlwave-shell-sources-alist)
578 (defvar idlwave-shell-menu-def)
579 (defvar idlwave-shell-mode-menu)
580 (defvar idlwave-shell-initial-commands)
581 (defvar idlwave-shell-syntax-error)
582 (defvar idlwave-shell-other-error)
583 (defvar idlwave-shell-error-buffer)
584 (defvar idlwave-shell-error-last)
585 (defvar idlwave-shell-bp-buffer)
586 (defvar idlwave-shell-sources-query)
587 (defvar idlwave-shell-mode-map)
588 (defvar idlwave-shell-calling-stack-index)
590 (defun idlwave-shell-mode ()
591 "Major mode for interacting with an inferior IDL process.
595 RET after the end of the process' output sends the text from the
596 end of process to the end of the current line. RET before end of
597 process output copies the current line (except for the prompt) to the
600 Command history, searching of previous commands, command line
601 editing are available via the comint-mode key bindings, by default
602 mostly on the key `C-c'.
606 TAB and M-TAB do completion of IDL routines, classes and keywords -
607 similar to M-TAB in `idlwave-mode'. In executive commands and
608 strings, it completes file names. Abbreviations are also expanded
609 like in `idlwave-mode'.
613 `\\[idlwave-routine-info]' displays information about an IDL routine near point,
614 just like in `idlwave-mode'. The module used is the one at point or
615 the one whose argument list is being edited.
616 To update IDLWAVE's knowledge about compiled or edited modules, use
617 \\[idlwave-update-routine-info].
618 \\[idlwave-find-module] find the source of a module.
619 \\[idlwave-resolve] tells IDL to compile an unresolved module.
620 \\[idlwave-context-help] shows the online help on the item at
621 point, if online help has been installed.
626 A complete set of commands for compiling and debugging IDL programs
627 is available from the menu. Also keybindings starting with a
628 `C-c C-d' prefix are available for most commands in the *idl* buffer
629 and also in source buffers. The best place to learn about the
630 keybindings is again the menu.
632 On Emacs versions where this is possible, a debugging toolbar is
635 When IDL is halted in the middle of a procedure, the corresponding
636 line of that procedure file is displayed with an overlay in another
637 window. Breakpoints are also highlighted in the source.
639 \\[idlwave-shell-resync-dirs] queries IDL in order to change Emacs current directory
640 to correspond to the IDL process current directory.
644 Turning on `idlwave-shell-mode' runs `comint-mode-hook' and
645 `idlwave-shell-mode-hook' (in that order).
647 6. Documentation and Customization
648 -------------------------------
649 Info documentation for this package is available. Use \\[idlwave-info]
650 to display (complain to your sysadmin if that does not work).
651 For Postscript and HTML versions of the documentation, check IDLWAVE's
652 homepage at `http://www.strw.leidenuniv.nl/~dominik/Tools/idlwave'.
653 IDLWAVE has customize support - see the group `idlwave'.
657 \\{idlwave-shell-mode-map}"
660 (setq comint-prompt-regexp idlwave-shell-prompt-pattern)
661 (setq comint-process-echoes t)
662 ;; Can not use history expansion because "!" is used for system variables.
663 (setq comint-input-autoexpand nil)
664 (setq comint-input-ring-size 64)
665 (make-local-variable 'comint-completion-addsuffix)
666 (set (make-local-variable 'completion-ignore-case) t)
667 (setq comint-completion-addsuffix '("/" . ""))
668 (setq comint-input-ignoredups t)
669 (setq major-mode 'idlwave-shell-mode)
670 (setq mode-name "IDL-Shell")
671 (setq idlwave-shell-mode-line-info nil)
672 (setq mode-line-format
675 mode-line-buffer-identification
684 idlwave-shell-mode-line-info
686 (line-number-mode "L%l--")
687 (column-number-mode "C%c--")
690 ;; (make-local-variable 'idlwave-shell-bp-alist)
691 (setq idlwave-shell-halt-frame nil
692 idlwave-shell-trace-frame nil
693 idlwave-shell-command-output nil
694 idlwave-shell-step-frame nil)
695 (idlwave-shell-display-line nil)
696 (setq idlwave-shell-calling-stack-index 0)
698 ;; Make sure comint-last-input-end does not go to beginning of
699 ;; buffer (in case there were other processes already in this buffer).
700 (set-marker comint-last-input-end (point))
701 (setq idlwave-idlwave_routine_info-compiled nil)
702 (setq idlwave-shell-ready nil)
703 (setq idlwave-shell-bp-alist nil)
704 (idlwave-shell-update-bp-overlays) ; Throw away old overlays
705 (setq idlwave-shell-sources-alist nil)
706 (setq idlwave-shell-default-directory default-directory)
707 (setq idlwave-shell-hide-output nil)
708 (make-local-hook 'kill-buffer-hook)
709 (add-hook 'kill-buffer-hook 'idlwave-shell-kill-shell-buffer-confirm
711 (add-hook 'kill-buffer-hook 'idlwave-shell-delete-temp-files nil 'local)
712 (add-hook 'kill-emacs-hook 'idlwave-shell-delete-temp-files)
713 (use-local-map idlwave-shell-mode-map)
714 (easy-menu-add idlwave-shell-mode-menu idlwave-shell-mode-map)
716 ;; IDLWAVE syntax, and turn on abbreviations
717 (setq local-abbrev-table idlwave-mode-abbrev-table)
718 (set-syntax-table idlwave-mode-syntax-table)
719 (setq comment-start ";")
721 (make-local-hook 'post-command-hook)
722 (add-hook 'post-command-hook 'idlwave-command-hook nil t)
725 (run-hooks 'idlwave-shell-mode-hook)
726 (idlwave-shell-send-command idlwave-shell-initial-commands nil 'hide)
727 ;; Define a system variable which knows the version of IDLWAVE
728 (idlwave-shell-send-command
729 (format "defsysv,'!idlwave_version','%s',1" idlwave-mode-version)
731 (if (and (not idlwave-path-alist)
732 (not idlwave-sys-dir))
733 (idlwave-shell-send-command idlwave-shell-path-query
734 'idlwave-shell-get-path-info
737 (defun idlwave-shell-get-path-info ()
738 (let* ((rpl (idlwave-shell-path-filter))
741 (setq idlwave-sys-dir sysdir)
742 (setq idlwave-path-alist (mapcar (lambda(x) (cons x nil))
745 (if (not (fboundp 'idl-shell))
746 (fset 'idl-shell 'idlwave-shell))
748 (defvar idlwave-shell-idl-wframe nil
749 "Frame for displaying the idl shell window.")
750 (defvar idlwave-shell-display-wframe nil
751 "Frame for displaying the idl source files.")
753 (defvar idlwave-shell-calling-stack-index 0)
754 (defvar idlwave-shell-calling-stack-routine nil)
756 (defun idlwave-shell-source-frame ()
757 "Return the frame to be used for source display."
758 (if idlwave-shell-use-dedicated-frame
759 ;; We want separate frames for source and shell
760 (if (frame-live-p idlwave-shell-display-wframe)
761 ;; The frame exists, so we use it.
762 idlwave-shell-display-wframe
763 ;; The frame does not exist. We use the current frame.
764 ;; However, if the current is the shell frame, we make a new frame.
765 (setq idlwave-shell-display-wframe
766 (if (eq (selected-frame) idlwave-shell-idl-wframe)
768 (selected-frame))))))
770 (defun idlwave-shell-shell-frame ()
771 "Return the frame to be used for the shell buffer."
772 (if idlwave-shell-use-dedicated-frame
773 ;; We want a dedicated frame
774 (if (frame-live-p idlwave-shell-idl-wframe)
775 ;; It does exist, so we use it.
776 idlwave-shell-idl-wframe
777 ;; It does not exist. Check if we have a source frame.
778 (if (not (frame-live-p idlwave-shell-display-wframe))
779 ;; We do not have a source frame, so we use this one.
780 (setq idlwave-shell-display-wframe (selected-frame)))
781 ;; Return a new frame
782 (setq idlwave-shell-idl-wframe
783 (make-frame idlwave-shell-frame-parameters)))))
786 (defun idlwave-shell (&optional arg)
787 "Run an inferior IDL, with I/O through buffer `(idlwave-shell-buffer)'.
788 If buffer exists but shell process is not running, start new IDL.
789 If buffer exists and shell process is running, just switch to the buffer.
791 When called with a prefix ARG, or when `idlwave-shell-use-dedicated-frame'
792 is non-nil, the shell buffer and the source buffers will be in
795 The command to run comes from variable `idlwave-shell-explicit-file-name'.
797 The buffer is put in `idlwave-shell-mode', providing commands for sending
798 input and controlling the IDL job. See help on `idlwave-shell-mode'.
799 See also the variable `idlwave-shell-prompt-pattern'.
801 \(Type \\[describe-mode] in the shell buffer for a list of commands.)"
804 ;; A non-nil arg means, we want a dedicated frame. This will last
805 ;; for the current editing session.
806 (if arg (setq idlwave-shell-use-dedicated-frame t))
807 (if (equal arg '(16)) (setq idlwave-shell-use-dedicated-frame nil))
809 ;; Check if the process still exists. If not, create it.
810 (unless (comint-check-proc (idlwave-shell-buffer))
811 (let* ((prg (or idlwave-shell-explicit-file-name "idl"))
812 (buf (apply 'make-comint
813 idlwave-shell-process-name prg nil
814 idlwave-shell-command-line-options))
815 ;; FIXME: the next line can go?
816 ;(buf (make-comint idlwave-shell-process-name prg))
817 (process (get-buffer-process buf)))
818 (setq idlwave-idlwave_routine_info-compiled nil)
819 (set-process-filter process 'idlwave-shell-filter)
820 (set-process-sentinel process 'idlwave-shell-sentinel)
822 (idlwave-shell-mode)))
823 (let ((window (idlwave-display-buffer (idlwave-shell-buffer) nil
824 (idlwave-shell-shell-frame)))
825 (current-window (selected-window)))
826 (select-window window)
827 (goto-char (point-max))
828 (select-window current-window)
829 (raise-frame (window-frame window))
830 (if (eq (selected-frame) (window-frame window))
831 (select-window window))
834 (defun idlwave-shell-recenter-shell-window (&optional arg)
835 "Run `idlwave-shell', but make sure the current window stays selected."
837 (let ((window (selected-window)))
839 (select-window window)))
841 (defun idlwave-shell-send-command (&optional cmd pcmd hide preempt)
842 "Send a command to IDL process.
844 \(CMD PCMD HIDE\) are placed at the end of `idlwave-shell-pending-commands'.
845 If IDL is ready the first command, CMD, in
846 `idlwave-shell-pending-commands' is sent to the IDL process. If optional
847 second argument PCMD is non-nil it will be placed on
848 `idlwave-shell-post-command-hook' when CMD is executed. If the optional
849 third argument HIDE is non-nil, then hide output from CMD.
850 If optional fourth argument PREEMPT is non-nil CMD is put at front of
851 `idlwave-shell-pending-commands'.
853 IDL is considered ready if the prompt is present
854 and if `idlwave-shell-ready' is non-nil."
856 ;(setq hide nil) ; FIXME: turn this on for debugging only
858 ;; Get or make the buffer and its process
859 (if (or (not (setq buf (get-buffer (idlwave-shell-buffer))))
860 (not (setq proc (get-buffer-process buf))))
861 (if (not idlwave-shell-automatic-start)
863 (substitute-command-keys
864 "You need to first start an IDL shell with \\[idlwave-shell]"))
865 (idlwave-shell-recenter-shell-window)
866 (setq buf (get-buffer (idlwave-shell-buffer)))
867 (if (or (not (setq buf (get-buffer (idlwave-shell-buffer))))
868 (not (setq proc (get-buffer-process buf))))
870 (error "Problem with autostarting IDL shell"))))
874 (goto-char (process-mark proc))
875 ;; To make this easy, always push CMD onto pending commands
877 (setq idlwave-shell-pending-commands
880 (append (list (list cmd pcmd hide))
881 idlwave-shell-pending-commands)
883 (append idlwave-shell-pending-commands
884 (list (list cmd pcmd hide))))))
885 ;; Check if IDL ready
886 (if (and idlwave-shell-ready
887 ;; Check for IDL prompt
890 (looking-at idlwave-shell-prompt-pattern)))
891 ;; IDL ready for command
892 (if idlwave-shell-pending-commands
894 (let* ((lcmd (car idlwave-shell-pending-commands))
898 ;; If this is an executive command, reset the stack pointer
899 (if (eq (string-to-char cmd) ?.)
900 (setq idlwave-shell-calling-stack-index 0))
902 (setq idlwave-shell-post-command-hook pcmd)
905 ;;; (setq idlwave-shell-hide-output nil)
906 (setq idlwave-shell-hide-output hide)
908 (setq idlwave-shell-pending-commands
909 (cdr idlwave-shell-pending-commands))
910 ;; Send command for execution
911 (set-marker comint-last-input-start (point))
912 (set-marker comint-last-input-end (point))
913 (comint-simple-send proc cmd)
914 (setq idlwave-shell-ready nil)))))))
916 (defun idlwave-shell-send-char (c &optional no-error)
917 "Send one character to the shell, without a newline."
918 (interactive "cChar to send to IDL: ")
919 (let ((errf (if (interactive-p) 'error 'message))
921 (if (or (not (setq buf (get-buffer (idlwave-shell-buffer))))
922 (not (setq proc (get-buffer-process buf))))
923 (funcall errf "Shell is not running"))
925 (funcall errf "Abort")
926 (comint-send-string proc (char-to-string c)))))
928 (defvar idlwave-shell-char-mode-active)
929 (defun idlwave-shell-input-mode-magic (string)
930 "Check STRING for magic words and toggle character input mode.
931 See also the variable `idlwave-shell-input-mode-spells'."
933 ((string-match (car idlwave-shell-input-mode-spells) string)
934 (call-interactively 'idlwave-shell-send-char))
935 ((and (boundp 'idlwave-shell-char-mode-active)
936 (string-match (nth 2 idlwave-shell-input-mode-spells) string))
937 (setq idlwave-shell-char-mode-active 'exit))
938 ((string-match (nth 1 idlwave-shell-input-mode-spells) string)
939 ;; Set a timer which will soon start the character loop
940 (if (fboundp 'start-itimer)
941 (start-itimer "IDLWAVE Char Mode" 'idlwave-shell-char-mode-loop 0.5
943 (run-at-time 0.5 nil 'idlwave-shell-char-mode-loop 'no-error)))))
945 (defvar keyboard-quit)
946 (defun idlwave-shell-char-mode-loop (&optional no-error)
947 "Enter a loop which accepts single characters and sends them to IDL.
948 Characters are sent one by one, without newlines. The loop is blocking
949 and intercepts all input events to Emacs. You can use this command
950 to interact with the IDL command GET_KBRD.
951 The loop can be aborted by typing `C-g'. The loop also exits automatically
952 when the IDL prompt gets displayed again after the current IDL command."
955 ;; First check if there is a shell waiting for input
956 (let ((idlwave-shell-char-mode-active t)
957 (errf (if no-error 'message 'error))
959 (if (or (not (setq buf (get-buffer (idlwave-shell-buffer))))
960 (not (setq proc (get-buffer-process buf))))
961 (funcall errf "Shell is not running"))
962 (if idlwave-shell-ready
963 (funcall errf "No IDL program seems to be waiting for input"))
965 ;; OK, start the loop
966 (message "Character mode on: Sending single chars (`C-g' to exit)")
971 ;; FIXME: Is it too dangerous to inhibit quit here?
972 (let ((inhibit-quit t))
973 ;; We wait and check frequently if we should abort
975 (and idlwave-shell-ready
976 (throw 'exit "Character mode off (prompt displayed)"))
977 (and (eq idlwave-shell-char-mode-active 'exit)
978 (throw 'exit "Character mode off (closing spell incantation)")))
979 ;; Interpret input as a character - ignore non-char input
982 (error (setq c nil)))
984 ((null c) ; Non-char event: ignore
986 ((equal c ?\C-g) ; Abort the loop
987 (setq keyboard-quit nil)
989 (throw 'exit "Character mode off (keyboard quit)"))
990 (t ; Send the character and continue the loop
991 (comint-send-string proc (char-to-string c))))
992 (and (eq idlwave-shell-char-mode-active 'exit)
993 (throw 'exit "Single char loop exited"))))))))
996 ;; There was a report that a newer version of comint.el changed the
997 ;; name of comint-filter to comint-output-filter. Unfortunately, we
998 ;; have yet to upgrade.
1000 (defun idlwave-shell-comint-filter (process string) nil)
1001 (if (fboundp 'comint-output-filter)
1002 (fset 'idlwave-shell-comint-filter (symbol-function 'comint-output-filter))
1003 (fset 'idlwave-shell-comint-filter (symbol-function 'comint-filter)))
1005 (defun idlwave-shell-is-running ()
1006 "Return t if the shell process is running."
1007 (eq (process-status idlwave-shell-process-name) 'run))
1009 (defvar idlwave-shell-hidden-output-buffer " *idlwave-shell-hidden-output*"
1010 "Buffer containing hidden output from IDL commands.")
1012 (defun idlwave-shell-filter (proc string)
1013 "Replace Carriage returns in output. Watch for prompt.
1014 When the IDL prompt is received executes `idlwave-shell-post-command-hook'
1015 and then calls `idlwave-shell-send-command' for any pending commands."
1016 ;; We no longer do the cleanup here - this is done by the process sentinel
1017 (when (eq (process-status idlwave-shell-process-name) 'run)
1018 ;; OK, process is still running, so we can use it.
1019 (let ((data (match-data)))
1022 ;; May change the original match data.
1024 (while (setq p (string-match "\C-M" string))
1025 (aset string p ? )))
1027 ;; (save-excursion (set-buffer (get-buffer-create "*test*"))
1028 ;; (goto-char (point-max))
1029 ;; (insert "%%%" string))
1033 ; Should not keep output because the concat is costly. If hidden put
1034 ; the output in a hide-buffer. Then when the output is needed in post
1035 ; processing can access either the hide buffer or the idlwave-shell
1036 ; buffer. Then watching for the prompt is easier. Furthermore, if it
1037 ; is hidden and there is no post command, could throw away output.
1038 ; (setq idlwave-shell-command-output
1039 ; (concat idlwave-shell-command-output string))
1040 ;; Insert the string. Do this before getting the
1042 (if idlwave-shell-hide-output
1045 (get-buffer-create idlwave-shell-hidden-output-buffer))
1046 (goto-char (point-max))
1048 (idlwave-shell-comint-filter proc string))
1049 ;; Watch for prompt - need to accumulate the current line
1050 ;; since it may not be sent all at once.
1051 (if (string-match "\n" string)
1053 (if idlwave-shell-use-input-mode-magic
1054 (idlwave-shell-input-mode-magic
1055 (concat idlwave-shell-accumulation string)))
1056 (setq idlwave-shell-accumulation
1058 (progn (string-match "\\(.*\n\\)*" string)
1060 (setq idlwave-shell-accumulation
1061 (concat idlwave-shell-accumulation string)))
1064 ;; Check for prompt in current line
1065 (if (setq idlwave-shell-ready
1066 (string-match idlwave-shell-prompt-pattern
1067 idlwave-shell-accumulation))
1069 (if idlwave-shell-hide-output
1071 (set-buffer idlwave-shell-hidden-output-buffer)
1072 (goto-char (point-min))
1073 (re-search-forward idlwave-shell-prompt-pattern nil t)
1074 (setq idlwave-shell-command-output
1075 (buffer-substring (point-min) (point)))
1076 (delete-region (point-min) (point)))
1077 (setq idlwave-shell-command-output
1080 (process-buffer proc))
1083 (goto-char (process-mark proc))
1084 (beginning-of-line nil)
1086 comint-last-input-end))))
1088 ;; (save-excursion (set-buffer
1089 ;; (get-buffer-create "*idlwave-shell-output*"))
1090 ;; (goto-char (point-max))
1091 ;; (insert "%%%" string))
1092 ;; Scan for state and do post command - bracket them
1093 ;; with idlwave-shell-ready=nil since they
1094 ;; may call idlwave-shell-send-command.
1095 (let ((idlwave-shell-ready nil))
1096 (idlwave-shell-scan-for-state)
1097 ;; Unset idlwave-shell-ready to prevent sending
1098 ;; commands to IDL while running hook.
1099 (if (listp idlwave-shell-post-command-hook)
1100 (eval idlwave-shell-post-command-hook)
1101 (funcall idlwave-shell-post-command-hook))
1102 ;; Reset to default state for next command.
1103 ;; Also we do not want to find this prompt again.
1104 (setq idlwave-shell-accumulation nil
1105 idlwave-shell-command-output nil
1106 idlwave-shell-post-command-hook nil
1107 idlwave-shell-hide-output nil))
1108 ;; Done with post command. Do pending command if
1110 (idlwave-shell-send-command))))
1111 (store-match-data data)))))
1113 (defun idlwave-shell-sentinel (process event)
1114 "The sentinel function for the IDLWAVE shell process."
1115 (let* ((buf (idlwave-shell-buffer))
1116 (win (get-buffer-window buf)))
1117 (when (get-buffer buf)
1119 (set-buffer (idlwave-shell-buffer))
1120 (goto-char (point-max))
1121 (insert (format "\n\n Process %s %s" process event))))
1122 (when (and (> (length (frame-list)) 1)
1123 (frame-live-p idlwave-shell-idl-wframe))
1124 (delete-frame idlwave-shell-idl-wframe)
1125 (setq idlwave-shell-idl-wframe nil
1126 idlwave-shell-display-wframe nil))
1127 (when (and (window-live-p win)
1128 (not (one-window-p)))
1129 (delete-window win))
1130 (idlwave-shell-cleanup)))
1132 (defun idlwave-shell-scan-for-state ()
1133 "Scan for state info.
1134 Looks for messages in output from last IDL command indicating where
1135 IDL has stopped. The types of messages we are interested in are
1136 execution halted, stepped, breakpoint, interrupted at and trace
1137 messages. We ignore error messages otherwise.
1138 For breakpoint messages process any attached count or command
1140 Update the windows if a message is found."
1143 ;; Make sure we have output
1144 ((not idlwave-shell-command-output))
1146 ;; Various types of HALT messages.
1147 ((string-match idlwave-shell-halt-messages-re
1148 idlwave-shell-command-output)
1149 ;; Grab the file and line state info.
1150 (setq idlwave-shell-calling-stack-index 0)
1151 (setq idlwave-shell-halt-frame
1152 (idlwave-shell-parse-line
1153 (substring idlwave-shell-command-output (match-end 0)))
1156 ;; Handle breakpoints separately
1157 ((string-match idlwave-shell-break-message
1158 idlwave-shell-command-output)
1159 (setq idlwave-shell-calling-stack-index 0)
1160 (setq idlwave-shell-halt-frame
1161 (idlwave-shell-parse-line
1162 (substring idlwave-shell-command-output (match-end 0)))
1164 ;; We used to to counting hits on breakpoints
1165 ;; this is no longer supported since IDL breakpoints
1166 ;; have learned counting.
1167 ;; Do breakpoint command processing
1170 (nth 0 idlwave-shell-halt-frame)
1171 (nth 1 idlwave-shell-halt-frame))
1172 idlwave-shell-bp-alist)))
1174 (let ((cmd (idlwave-shell-bp-get bp 'cmd)))
1180 ;; A breakpoint that we did not know about - perhaps it was
1181 ;; set by the user or IDL isn't reporting breakpoints like
1182 ;; we expect. Lets update our list.
1183 (idlwave-shell-bp-query)))))
1185 ;; Handle compilation errors in addition to the above
1186 (if (and idlwave-shell-command-output
1188 idlwave-shell-syntax-error idlwave-shell-command-output)
1190 idlwave-shell-other-error idlwave-shell-command-output)))
1194 (get-buffer-create idlwave-shell-error-buffer))
1196 (insert idlwave-shell-command-output)
1197 (goto-char (point-min))
1198 (setq idlwave-shell-error-last (point)))
1199 (idlwave-shell-goto-next-error)))
1203 (idlwave-shell-display-line (idlwave-shell-pc-frame)))))
1206 (defvar idlwave-shell-error-buffer " *idlwave-shell-errors*"
1207 "Buffer containing syntax errors from IDL compilations.")
1210 ;; FIXME: the following two variables do not currently allow line breaks
1211 ;; in module and file names. I am not sure if it will be necessary to
1212 ;; change this. Currently it seems to work the way it is.
1213 (defvar idlwave-shell-syntax-error
1214 "^% Syntax error.\\s-*\n\\s-*At:\\s-*\\(.*\\),\\s-*Line\\s-*\\(.*\\)"
1215 "A regular expression to match an IDL syntax error.
1216 The first \(..\) pair should match the file name. The second pair
1217 should match the line number.")
1219 (defvar idlwave-shell-other-error
1220 "^% .*\n\\s-*At:\\s-*\\(.*\\),\\s-*Line\\s-*\\(.*\\)"
1221 "A regular expression to match any IDL error.
1222 The first \(..\) pair should match the file name. The second pair
1223 should match the line number.")
1225 (defvar idlwave-shell-file-line-message
1227 "\\(" ; program name group (1)
1228 "\\<[a-zA-Z][a-zA-Z0-9_$:]*" ; start with a letter, followed by [..]
1229 "\\([ \t]*\n[ \t]*[a-zA-Z0-9_$:]+\\)*"; continuation lines program name (2)
1230 "\\)" ; end program name group (1)
1231 "[ \t\n]+" ; white space
1232 "\\(" ; line number group (3)
1233 "[0-9]+" ; the line number (the fix point)
1234 "\\([ \t]*\n[ \t]*[0-9]+\\)*" ; continuation lines number (4)
1235 "\\)" ; end line number group (3)
1236 "[ \t\n]+" ; white space
1237 "\\(" ; file name group (5)
1238 "[^ \t\n]+" ; file names can contain any non-white
1239 "\\([ \t]*\n[ \t]*[^ \t\n]+\\)*" ; continuation lines file name (6)
1240 "\\)" ; end line number group (5)
1242 "*A regular expression to parse out the file name and line number.
1243 The 1st group should match the subroutine name.
1244 The 3rd group is the line number.
1245 The 5th group is the file name.
1246 All parts may contain linebreaks surrounded by spaces. This is important
1247 in IDL5 which inserts random linebreaks in long module and file names.")
1249 (defun idlwave-shell-parse-line (string)
1250 "Parse IDL message for the subroutine, file name and line number.
1251 We need to work hard here to remove the stupid line breaks inserted by
1252 IDL5. These line breaks can be right in the middle of procedure
1254 It is very difficult to come up with a robust solution. This one seems
1255 to be pretty good though.
1257 Here is in what ways it improves over the previous solution:
1259 1. The procedure name can be split and will be restored.
1260 2. The number can be split. I have never seen this, but who knows.
1261 3. We do not require the `.pro' extension for files.
1263 This function can still break when the file name ends on a end line
1264 and the message line contains an additional line with garbage. Then
1265 the first part of that garbage will be added to the file name.
1266 However, the function checks the existence of the files with and
1267 without this last part - thus the function only breaks if file name
1268 plus garbage match an existing regular file. This is hopefully very
1271 (let (number procedure file)
1272 (when (string-match idlwave-shell-file-line-message string)
1273 (setq procedure (match-string 1 string)
1274 number (match-string 3 string)
1275 file (match-string 5 string))
1277 ;; Repair the strings
1278 (setq procedure (idlwave-shell-repair-string procedure))
1279 (setq number (idlwave-shell-repair-string number))
1280 (setq file (idlwave-shell-repair-file-name file))
1282 ;; If we have a file, return the frame list
1284 (list (idlwave-shell-file-name file)
1285 (string-to-int number)
1287 ;; No success finding a file
1290 (defun idlwave-shell-repair-string (string)
1291 "Repair a string by taking out all linebreaks. This is destructive!"
1292 (while (string-match "[ \t]*\n[ \t]*" string)
1293 (setq string (replace-match "" t t string)))
1296 (defun idlwave-shell-repair-file-name (file)
1297 "Repair a file name string by taking out all linebreaks.
1298 The last line of STRING may be garbage - we check which one makes a valid
1300 (let ((file1 "") (file2 "") (start 0))
1301 ;; We scan no further than to the next "^%" line
1302 (if (string-match "^%" file)
1303 (setq file (substring file 0 (match-beginning 0))))
1304 ;; Take out the line breaks
1305 (while (string-match "[ \t]*\n[ \t]*" file start)
1306 (setq file1 (concat file1 (substring file start (match-beginning 0)))
1307 start (match-end 0)))
1308 (setq file2 (concat file1 (substring file start)))
1310 ((file-regular-p file2) file2)
1311 ((file-regular-p file1) file1)
1312 ;; If we cannot veryfy the existence of the file, we return the shorter
1313 ;; name. The idea behind this is that this may be a relative file name
1314 ;; and our idea about the current working directory may be wrong.
1315 ;; If it is a relative file name, it hopefully is short.
1316 ((not (string= "" file1)) file1)
1317 ((not (string= "" file2)) file2)
1320 (defun idlwave-shell-cleanup ()
1321 "Do necessary cleanup for a terminated IDL process."
1322 (setq idlwave-shell-step-frame nil
1323 idlwave-shell-halt-frame nil
1324 idlwave-shell-pending-commands nil
1325 idlwave-shell-command-line-to-execute nil
1326 idlwave-shell-bp-alist nil
1327 idlwave-shell-calling-stack-index 0
1328 idlwave-idlwave_routine_info-compiled nil)
1329 (idlwave-shell-delete-temp-files)
1330 (idlwave-shell-display-line nil)
1331 (idlwave-shell-update-bp-overlays) ; kill old overlays
1332 (idlwave-shell-kill-buffer idlwave-shell-hidden-output-buffer)
1333 (idlwave-shell-kill-buffer idlwave-shell-bp-buffer)
1334 (idlwave-shell-kill-buffer idlwave-shell-error-buffer)
1335 ;; (idlwave-shell-kill-buffer (idlwave-shell-buffer))
1336 (and (get-buffer (idlwave-shell-buffer))
1337 (bury-buffer (get-buffer (idlwave-shell-buffer))))
1338 (run-hooks 'idlwave-shell-cleanup-hook))
1340 (defun idlwave-shell-kill-buffer (buf)
1341 "Kill buffer BUF if it exists."
1342 (if (setq buf (get-buffer buf))
1345 (defun idlwave-shell-kill-shell-buffer-confirm ()
1346 (when (idlwave-shell-is-running)
1348 (unless (y-or-n-p "IDL shell is running. Are you sure you want to kill the buffer? ")
1350 (message "Killing buffer *idl* and the associated process")))
1352 (defun idlwave-shell-resync-dirs ()
1353 "Resync the buffer's idea of the current directory stack.
1354 This command queries IDL with the command bound to
1355 `idlwave-shell-dirstack-query' (default \"printd\"), reads the
1356 output for the new directory stack."
1358 (idlwave-shell-send-command idlwave-shell-dirstack-query
1359 'idlwave-shell-filter-directory
1362 (defun idlwave-shell-retall (&optional arg)
1363 "Return from the entire calling stack."
1365 (idlwave-shell-send-command "retall"))
1367 (defun idlwave-shell-closeall (&optional arg)
1368 "Close all open files."
1370 (idlwave-shell-send-command "close,/all"))
1372 (defun idlwave-shell-quit (&optional arg)
1373 "Exit the idl process after confirmation.
1374 With prefix ARG, exit without confirmation."
1376 (if (not (idlwave-shell-is-running))
1377 (error "Shell is not running")
1378 (if (or arg (y-or-n-p "Exit the IDLWAVE Shell? "))
1380 (idlwave-shell-send-command "exit")
1383 (defun idlwave-shell-reset (&optional hidden)
1384 "Reset IDL. Return to main level and destroy the leaftover variables.
1385 This issues the following commands:
1387 WIDGET_CONTROL,/RESET
1390 ;; OBJ_DESTROY, OBJ_VALID() FIXME: should this be added?
1392 (message "Resetting IDL")
1393 (setq idlwave-shell-calling-stack-index 0)
1394 (idlwave-shell-send-command "retall" nil hidden)
1395 (idlwave-shell-send-command "widget_control,/reset" nil hidden)
1396 (idlwave-shell-send-command "close,/all" nil hidden)
1397 ;; (idlwave-shell-send-command "obj_destroy, obj_valid()" nil hidden)
1398 (idlwave-shell-send-command "heap_gc,/verbose" nil hidden)
1399 (idlwave-shell-display-line nil))
1401 (defun idlwave-shell-path-filter ()
1402 ;; Convert the output of the path query into a list of directories
1403 (let ((path-string idlwave-shell-command-output)
1404 (case-fold-search t)
1407 (while (string-match "^PATH:[ \t]*\\(.*\\)\n" path-string start)
1408 (push (match-string 1 path-string) dirs)
1409 (setq start (match-end 0)))
1410 (setq dirs (mapcar 'file-name-as-directory dirs))
1411 (if (string-match "^SYSDIR:[ \t]*\\(.*\\)\n" path-string)
1412 (setq sysdir (file-name-as-directory
1413 (match-string 1 path-string))))
1414 (cons sysdir (nreverse dirs))))
1416 (defun idlwave-shell-routine-info-filter ()
1417 "Function which parses the special output from idlwave_routine_info.pro."
1418 (let ((text idlwave-shell-command-output)
1420 sep sep-re file type spec specs name cs key keys class entry)
1421 ;; Initialize variables
1422 (setq idlwave-compiled-routines nil
1423 idlwave-unresolved-routines nil)
1424 ;; Cut out the correct part of the output.
1426 "^>>>BEGIN OF IDLWAVE ROUTINE INFO (\"\\(.+\\)\" IS THE SEPARATOR.*"
1428 (setq sep (match-string 1 text)
1429 sep-re (concat (regexp-quote sep) " *")
1430 text (substring text (match-end 0)))
1431 ;; Set dummy values and kill the text
1432 (setq sep "@" sep-re "@ *" text "")
1433 (message "Routine Info warning: No match for BEGIN line"))
1434 (if (string-match "^>>>END OF IDLWAVE ROUTINE INFO.*" text)
1435 (setq text (substring text 0 (match-beginning 0)))
1436 (message "Routine Info warning: No match for END line"))
1437 (if (string-match "\\S-" text)
1438 ;; Obviously, the pro worked. Make a note that we have it now.
1439 (setq idlwave-idlwave_routine_info-compiled t))
1440 ;; Match the output lines
1441 (while (string-match "^IDLWAVE-\\(PRO\\|FUN\\): \\(.*\\)" text start)
1442 (setq start (match-end 0))
1443 (setq type (match-string 1 text)
1444 spec (match-string 2 text)
1445 specs (idlwave-split-string spec sep-re)
1447 class (if (equal (nth 1 specs) "") nil (nth 1 specs))
1451 keys (if (and (stringp key)
1452 (not (string-match "\\` *\\'" key)))
1454 (delete "" (idlwave-split-string key " +")))))
1455 (setq name (idlwave-sintern-routine-or-method name class t)
1456 class (idlwave-sintern-class class t)
1457 file (if (equal file "") nil file)
1458 keys (mapcar (lambda (x)
1459 (list (idlwave-sintern-keyword (car x) t))) keys))
1460 ;; Make sure we use the same string object for the same file
1461 (setq file (idlwave-sintern-file file t))
1462 ;; FIXME: What should I do with routines from the temp file???
1463 ;; Maybe just leave it in - there is a chance that the
1464 ;; routine is still in there.
1465 ;; (if (equal file idlwave-shell-temp-pro-file)
1468 ;; In the following ignore routines already defined in buffers,
1469 ;; assuming that if the buffer stuff differs, it is a "new"
1471 ;; We could do the same for the library to avoid duplicates -
1472 ;; but I think frequently a user might have several versions of
1473 ;; the same function in different programs, and in this case the
1474 ;; compiled one will be the best guess of all version.
1475 ;; Therefore, we leave duplicates of library routines in.
1477 (cond ((string= name "$MAIN$")) ; ignore this one
1478 ((and (string= type "PRO")
1479 ;; FIXME: is it OK to make the buffer routines dominate?
1481 (not (idlwave-rinfo-assq name 'pro class
1482 idlwave-buffer-routines)))
1483 ;; FIXME: is it OK to make the library routines dominate?
1484 ;;(not (idlwave-rinfo-assq name 'pro class
1485 ;; idlwave-library-routines))
1487 (setq entry (list name 'pro class (cons 'compiled file) cs keys))
1489 (push entry idlwave-compiled-routines)
1490 (push entry idlwave-unresolved-routines)))
1492 ((and (string= type "FUN")
1493 ;; FIXME: is it OK to make the buffer routines dominate?
1495 (not (idlwave-rinfo-assq name 'fun class
1496 idlwave-buffer-routines)))
1497 ;; FIXME: is it OK to make the library routines dominate?
1498 ;; (not (idlwave-rinfo-assq name 'fun class
1499 ;; idlwave-library-routines))
1501 (setq entry (list name 'fun class (cons 'compiled file) cs keys))
1503 (push entry idlwave-compiled-routines)
1504 (push entry idlwave-unresolved-routines))))))
1505 ;; Reverse the definitions so that they are alphabetically sorted.
1506 (setq idlwave-compiled-routines (nreverse idlwave-compiled-routines)
1507 idlwave-unresolved-routines (nreverse idlwave-unresolved-routines)))
1509 (defun idlwave-shell-filter-directory ()
1510 "Get the current directory from `idlwave-shell-command-output'.
1511 Change the default directory for the process buffer to concur."
1513 (set-buffer (idlwave-shell-buffer))
1514 (if (string-match "Current Directory: *\\(\\S-*\\) *$"
1515 idlwave-shell-command-output)
1516 (let ((dir (substring idlwave-shell-command-output
1517 (match-beginning 1) (match-end 1))))
1518 (message "Setting Emacs wd to %s" dir)
1519 (setq idlwave-shell-default-directory dir)
1520 (setq default-directory (file-name-as-directory dir))))))
1522 (defun idlwave-shell-complete (&optional arg)
1523 "Do completion in the idlwave-shell buffer.
1524 Calls `idlwave-shell-complete-filename' after some executive commands or
1525 in strings. Otherwise, calls `idlwave-complete' to complete modules and
1527 ;;FIXME: batch files?
1531 ((setq cmd (idlwave-shell-executive-command))
1532 ;; We are in a command line with an executive command
1533 (if (member (upcase cmd)
1534 '(".R" ".RU" ".RUN" ".RN" ".RNE" ".RNEW"
1535 ".COM" ".COMP" ".COMPI" ".COMPIL" ".COMPILE"))
1536 ;; This command expects file names
1537 (idlwave-shell-complete-filename)))
1538 ((and (idlwave-shell-filename-string)
1541 (let ((case-fold-search t))
1542 (not (looking-at ".*obj_new"))))
1543 ;; In a string, could be a file name to here
1544 (idlwave-shell-complete-filename)))
1546 ;; Default completion of modules and keywords
1547 (idlwave-complete arg)))))
1549 (defun idlwave-shell-complete-filename (&optional arg)
1550 "Complete a file name at point if after a file name.
1551 We assume that we are after a file name when completing one of the
1552 args of an executive .run, .rnew or .compile. Also, in a string
1553 constant we complete file names. Otherwise return nil, so that
1554 other completion functions can do thier work."
1555 (let* ((comint-file-name-chars idlwave-shell-file-name-chars)
1556 (completion-ignore-case (default-value 'completion-ignore-case)))
1557 (comint-dynamic-complete-filename)))
1559 (defun idlwave-shell-executive-command ()
1560 "Return the name of the current executive command, if any."
1562 (idlwave-beginning-of-statement)
1563 (if (looking-at "[ \t]*\\([.][^ \t\n\r]*\\)")
1566 (defun idlwave-shell-filename-string ()
1567 "Return t if in a string and after what could be a file name."
1568 (let ((limit (save-excursion (beginning-of-line) (point))))
1570 ;; Skip backwards over file name chars
1571 (skip-chars-backward idlwave-shell-file-name-chars limit)
1572 ;; Check of the next char is a string delimiter
1573 (memq (preceding-char) '(?\' ?\")))))
1576 ;;; This section contains code for debugging IDL programs. --------------------
1579 (defun idlwave-shell-redisplay (&optional hide)
1580 "Tries to resync the display with where execution has stopped.
1581 Issues a \"help,/trace\" command followed by a call to
1582 `idlwave-shell-display-line'. Also updates the breakpoint
1585 (setq idlwave-shell-calling-stack-index 0)
1586 (idlwave-shell-send-command
1588 '(idlwave-shell-display-line
1589 (idlwave-shell-pc-frame))
1591 (idlwave-shell-bp-query))
1593 (defun idlwave-shell-display-level-in-calling-stack (&optional hide)
1594 (idlwave-shell-send-command
1597 ;; scanning for the state will reset the stack level - restore it
1598 (setq idlwave-shell-calling-stack-index
1599 ,idlwave-shell-calling-stack-index)
1600 ;; parse the stack and visit the selected frame
1601 (idlwave-shell-parse-stack-and-display))
1604 (defun idlwave-shell-parse-stack-and-display ()
1605 (let* ((lines (delete "" (idlwave-split-string
1606 idlwave-shell-command-output "^%")))
1607 (stack (delq nil (mapcar 'idlwave-shell-parse-line lines)))
1608 (nmax (1- (length stack)))
1612 (setq idlwave-shell-calling-stack-index 0)
1614 (message "Problem with calling stack"))
1615 ((> idlwave-shell-calling-stack-index nmax)
1617 (setq idlwave-shell-calling-stack-index nmax
1618 message (format "%d is the highest calling stack level - can't go further up"
1620 ((< idlwave-shell-calling-stack-index nmin)
1622 (setq idlwave-shell-calling-stack-index nmin
1623 message (format "%d is the current calling stack level - can't go further down"
1625 (setq idlwave-shell-calling-stack-routine
1626 (nth 2 (nth idlwave-shell-calling-stack-index stack)))
1627 (idlwave-shell-display-line
1628 (nth idlwave-shell-calling-stack-index stack))
1629 (message (or message
1630 (format "In routine %s (stack level %d)"
1631 idlwave-shell-calling-stack-routine
1632 (- idlwave-shell-calling-stack-index))))))
1634 (defun idlwave-shell-stack-up ()
1635 "Display the source code one step up the calling stack."
1637 (incf idlwave-shell-calling-stack-index)
1638 (idlwave-shell-display-level-in-calling-stack 'hide))
1639 (defun idlwave-shell-stack-down ()
1640 "Display the source code one step down the calling stack."
1642 (decf idlwave-shell-calling-stack-index)
1643 (idlwave-shell-display-level-in-calling-stack 'hide))
1645 (defun idlwave-shell-goto-frame (&optional frame)
1646 "Set buffer to FRAME with point at the frame line.
1647 If the optional argument FRAME is nil then idlwave-shell-pc-frame is
1648 used. Does nothing if the resulting frame is nil."
1650 (setq frame (idlwave-shell-pc-frame)))
1653 (set-buffer (idlwave-find-file-noselect (car frame) 'shell))
1655 (goto-line (nth 1 frame)))))
1657 (defun idlwave-shell-pc-frame ()
1658 "Returns the frame for IDL execution."
1659 (and idlwave-shell-halt-frame
1660 (list (nth 0 idlwave-shell-halt-frame)
1661 (nth 1 idlwave-shell-halt-frame)
1662 (nth 2 idlwave-shell-halt-frame))))
1664 (defun idlwave-shell-valid-frame (frame)
1665 "Check that frame is for an existing file."
1666 (file-readable-p (car frame)))
1668 (defun idlwave-shell-display-line (frame &optional col)
1669 "Display FRAME file in other window with overlay arrow.
1671 FRAME is a list of file name, line number, and subroutine name.
1672 If FRAME is nil then remove overlay."
1674 ;; Remove stop-line overlay from old position
1676 (setq overlay-arrow-string nil)
1677 (setq idlwave-shell-mode-line-info nil)
1678 (setq idlwave-shell-is-stopped nil)
1679 (if idlwave-shell-stop-line-overlay
1680 (delete-overlay idlwave-shell-stop-line-overlay)))
1681 (if (not (idlwave-shell-valid-frame frame))
1682 ;; FIXME: errors are dangerous in shell filters. But I think I
1683 ;; have never encountered this one.
1684 (error (concat "Invalid frame - unable to access file: " (car frame)))
1686 ;;; buffer : the buffer to display a line in.
1687 ;;; select-shell: current buffer is the shell.
1689 (setq idlwave-shell-mode-line-info
1692 (- idlwave-shell-calling-stack-index)
1694 (let* ((buffer (idlwave-find-file-noselect (car frame) 'shell))
1695 (select-shell (equal (buffer-name) (idlwave-shell-buffer)))
1698 ;; First make sure the shell window is visible
1699 (idlwave-display-buffer (idlwave-shell-buffer)
1700 nil (idlwave-shell-shell-frame))
1702 ;; Now display the buffer and remember which window it is.
1703 (setq window (idlwave-display-buffer buffer
1704 nil (idlwave-shell-source-frame)))
1706 ;; Enter the buffer and mark the line
1711 (goto-line (nth 1 frame))
1713 (setq idlwave-shell-is-stopped t)
1714 (if idlwave-shell-stop-line-overlay
1716 (move-overlay idlwave-shell-stop-line-overlay
1717 (point) (save-excursion (end-of-line) (point))
1719 ;; Use the arrow instead, but only if marking is wanted.
1720 (if idlwave-shell-mark-stop-line
1721 (setq overlay-arrow-string idlwave-shell-overlay-arrow))
1722 (or overlay-arrow-position ; create the marker if necessary
1723 (setq overlay-arrow-position (make-marker)))
1724 (set-marker overlay-arrow-position (point) buffer)))
1726 ;; If the point is outside the restriction, widen the buffer.
1727 (if (or (< pos (point-min)) (> pos (point-max)))
1732 ;; If we have the column of the error, move the cursor there.
1733 (if col (move-to-column col))
1736 ;; Make sure pos is really displayed in the window.
1737 (set-window-point window pos)
1739 ;; FIXME: the following frame redraw was taken out because it
1740 ;; flashes. I think it is not needed. The code is left here in
1741 ;; case we have to put it back in.
1742 ;; (redraw-frame (window-frame window))
1744 ;; If we came from the shell, go back there. Otherwise select
1745 ;; the window where the error is displayed.
1746 (if (and (equal (buffer-name) (idlwave-shell-buffer))
1748 (select-window window))))))
1751 (defun idlwave-shell-step (arg)
1752 "Step one source line. If given prefix argument ARG, step ARG source lines."
1754 (or (not arg) (< arg 1)
1756 (idlwave-shell-send-command
1757 (concat ".s " (if (integerp arg) (int-to-string arg) arg))))
1759 (defun idlwave-shell-stepover (arg)
1760 "Stepover one source line.
1761 If given prefix argument ARG, step ARG source lines.
1762 Uses IDL's stepover executive command which does not enter called functions."
1764 (or (not arg) (< arg 1)
1766 (idlwave-shell-send-command
1767 (concat ".so " (if (integerp arg) (int-to-string arg) arg))))
1769 (defun idlwave-shell-break-here (&optional count cmd)
1770 "Set breakpoint at current line.
1772 If Count is nil then an ordinary breakpoint is set. We treat a count
1773 of 1 as a temporary breakpoint using the ONCE keyword. Counts greater
1774 than 1 use the IDL AFTER=count keyword to break only after reaching
1775 the statement count times.
1777 Optional argument CMD is a list or function to evaluate upon reaching
1783 (idlwave-shell-set-bp
1784 ;; Create breakpoint
1785 (idlwave-shell-bp (idlwave-shell-current-frame)
1787 (idlwave-shell-current-module))))
1789 (defun idlwave-shell-set-bp-check (bp)
1790 "Check for failure to set breakpoint.
1791 This is run on `idlwave-shell-post-command-hook'.
1792 Offers to recompile the procedure if we failed. This usually fixes
1793 the problem with not being able to set the breakpoint."
1795 (if (and idlwave-shell-command-output
1796 (string-match "% BREAKPOINT: *Unable to find code"
1797 idlwave-shell-command-output))
1798 ;; Offer to recompile
1803 (concat "Okay to recompile file "
1804 (idlwave-shell-bp-get bp 'file) " ")))
1807 ;; Clean up before retrying
1808 (idlwave-shell-command-failure)
1809 (idlwave-shell-send-command
1810 (concat ".run " (idlwave-shell-bp-get bp 'file)) nil nil)
1811 ;; Try setting breakpoint again
1812 (idlwave-shell-set-bp bp))
1814 (message "Unable to set breakpoint.")
1815 (idlwave-shell-command-failure)
1817 ;; return non-nil if no error found
1821 (defun idlwave-shell-command-failure ()
1822 "Do any necessary clean up when an IDL command fails.
1823 Call this from a function attached to `idlwave-shell-post-command-hook'
1824 that detects the failure of a command.
1825 For example, this is called from `idlwave-shell-set-bp-check' when a
1826 breakpoint can not be set."
1827 ;; Clear pending commands
1828 (setq idlwave-shell-pending-commands nil))
1830 (defun idlwave-shell-cont ()
1831 "Continue executing."
1833 (idlwave-shell-send-command ".c" '(idlwave-shell-redisplay 'hide)))
1835 (defun idlwave-shell-go ()
1836 "Run .GO. This starts the main program of the last compiled file."
1838 (idlwave-shell-send-command ".go" '(idlwave-shell-redisplay 'hide)))
1840 (defun idlwave-shell-return ()
1841 "Run .RETURN (continue to next return, but stay in subprogram)."
1843 (idlwave-shell-send-command ".return" '(idlwave-shell-redisplay 'hide)))
1845 (defun idlwave-shell-skip ()
1846 "Run .SKIP (skip one line, then step)."
1848 (idlwave-shell-send-command ".skip" '(idlwave-shell-redisplay 'hide)))
1850 (defun idlwave-shell-clear-bp (bp)
1851 "Clear breakpoint BP.
1852 Clears in IDL and in `idlwave-shell-bp-alist'."
1853 (let ((index (idlwave-shell-bp-get bp)))
1856 (idlwave-shell-send-command
1857 (concat "breakpoint,/clear,"
1858 (if (integerp index) (int-to-string index) index)))
1859 (idlwave-shell-bp-query)))))
1861 (defun idlwave-shell-current-frame ()
1862 "Return a list containing the current file name and line point is in.
1863 If in the IDL shell buffer, returns `idlwave-shell-pc-frame'."
1864 (if (eq (current-buffer) (get-buffer (idlwave-shell-buffer)))
1866 (idlwave-shell-pc-frame)
1868 (list (idlwave-shell-file-name (buffer-file-name))
1873 (1+ (count-lines 1 (point))))))))
1875 (defun idlwave-shell-current-module ()
1876 "Return the name of the module for the current file.
1877 Returns nil if unable to obtain a module name."
1878 (if (eq (current-buffer) (get-buffer (idlwave-shell-buffer)))
1880 (nth 2 idlwave-shell-halt-frame)
1885 (if (idlwave-prev-index-position)
1886 (upcase (idlwave-unit-name)))))))
1888 (defun idlwave-shell-clear-current-bp ()
1889 "Remove breakpoint at current line.
1890 This command can be called from the shell buffer if IDL is currently stopped
1893 (let ((bp (idlwave-shell-find-bp (idlwave-shell-current-frame))))
1894 (if bp (idlwave-shell-clear-bp bp)
1895 ;; Try moving to beginning of statement
1897 (idlwave-shell-goto-frame)
1898 (idlwave-beginning-of-statement)
1899 (setq bp (idlwave-shell-find-bp (idlwave-shell-current-frame)))
1900 (if bp (idlwave-shell-clear-bp bp)
1902 (message "Cannot identify breakpoint for this line"))))))
1904 (defun idlwave-shell-to-here ()
1905 "Set a breakpoint with count 1 then continue."
1907 (idlwave-shell-break-here 1)
1908 (idlwave-shell-cont))
1910 (defun idlwave-shell-break-in (&optional module)
1911 "Look for a module name near point and set a break point for it.
1912 The command looks for an identifier near point and sets a breakpoint
1913 for the first line of the corresponding module."
1915 ;; get the identifier
1918 (skip-chars-backward "a-zA-Z0-9_$")
1919 (if (looking-at idlwave-identifier)
1920 (setq module (match-string 0))
1921 (error "No identifier at point")))
1922 (idlwave-shell-send-command
1923 idlwave-shell-sources-query
1925 (idlwave-shell-sources-filter)
1926 (idlwave-shell-set-bp-in-module ,module))
1929 (defun idlwave-shell-set-bp-in-module (module)
1930 "Set breakpoint in module. Assumes that `idlwave-shell-sources-alist'
1931 contains an entry for that module."
1932 (let ((source-file (car-safe
1934 (assoc (upcase module)
1935 idlwave-shell-sources-alist))))
1937 (if (or (not source-file)
1938 (not (file-regular-p source-file))
1940 (or (idlwave-get-buffer-visiting source-file)
1941 (find-file-noselect source-file)))))
1943 (message "The source file for module %s is probably not compiled"
1949 (goto-char (point-min))
1950 (let ((case-fold-search t))
1951 (if (re-search-forward
1952 (concat "^[ \t]*\\(pro\\|function\\)[ \t]+"
1956 (goto-char (match-beginning 1))
1957 (message "Setting breakpoint for module %s" module)
1958 (idlwave-shell-break-here))
1959 (message "Cannot find module %s in file %s" module source-file)
1962 (defun idlwave-shell-up ()
1963 "Run to end of current block.
1964 Sets a breakpoint with count 1 at end of block, then continues."
1966 (if (idlwave-shell-pc-frame)
1968 (idlwave-shell-goto-frame)
1969 ;; find end of subprogram
1970 (let ((eos (save-excursion
1971 (idlwave-beginning-of-subprogram)
1972 (idlwave-forward-block)
1974 (idlwave-backward-up-block -1)
1975 ;; move beyond end block line - IDL will not break there.
1976 ;; That is, you can put a breakpoint there but when IDL does
1977 ;; break it will report that it is at the next line.
1978 (idlwave-next-statement)
1979 (idlwave-end-of-statement)
1980 ;; Make sure we are not beyond subprogram
1984 ;; Move back inside subprogram
1986 (idlwave-previous-statement))
1987 (idlwave-shell-to-here)))))
1989 (defun idlwave-shell-out ()
1990 "Attempt to run until this procedure exits.
1991 Runs to the last statement and then steps 1 statement. Use the .out command."
1993 (idlwave-shell-send-command (concat ".o")))
1995 (defun idlwave-shell-help-expression (arg)
1996 "Print help on current expression. See `idlwave-shell-print'."
1998 (idlwave-shell-print arg 'help))
2000 (defun idlwave-shell-mouse-print (event)
2001 "Call `idlwave-shell-print' at the mouse position."
2003 (mouse-set-point event)
2004 (idlwave-shell-print nil nil 'mouse))
2006 (defun idlwave-shell-mouse-help (event)
2007 "Call `idlwave-shell-print' at the mouse position."
2009 (mouse-set-point event)
2010 (idlwave-shell-print nil 'help 'mouse))
2012 (defun idlwave-shell-print (arg &optional help mouse)
2013 "Print current expression. With HELP, show help on expression.
2014 An expression is an identifier plus 1 pair of matched parentheses
2015 directly following the identifier - an array or function
2016 call. Alternatively, an expression is the contents of any matched
2017 parentheses when the open parentheses is not directly preceded by an
2018 identifier. If point is at the beginning or within an expression
2019 return the inner-most containing expression, otherwise, return the
2020 preceding expression.
2022 With prefix arg ARG, or when called from the shell buffer, prompt
2026 (let (expr beg end cmd)
2027 (if (and (not mouse)
2028 (or arg (eq major-mode 'idlwave-shell-mode)))
2029 (setq expr (read-string "Expression: "))
2030 ;; Move to beginning of current or previous expression
2031 (if (looking-at "\\<\\|(")
2032 ;; At beginning of expression, don't move backwards unless
2033 ;; this is at the end of an indentifier.
2034 (if (looking-at "\\>")
2037 (if (looking-at "\\>")
2038 ;; Move to beginning of identifier - must be an array or
2039 ;; function expression.
2041 ;; Move to end of expression
2044 (while (looking-at "\\>[[(]\\|\\.")
2048 (setq expr (buffer-substring beg end)))
2049 (when (and beg end idlwave-shell-expression-overlay)
2050 (move-overlay idlwave-shell-expression-overlay beg end
2052 (add-hook 'pre-command-hook 'idlwave-shell-delete-expression-overlay))
2053 (if (and (integerp idlwave-shell-calling-stack-index)
2054 (> idlwave-shell-calling-stack-index 0))
2055 (setq cmd (idlwave-retrieve-expression-from-level
2057 idlwave-shell-calling-stack-index
2058 idlwave-shell-calling-stack-routine
2060 (setq cmd (concat (if help "help," "print,") expr)))
2061 (if idlwave-shell-print-expression-function
2062 (idlwave-shell-send-command
2064 (list idlwave-shell-print-expression-function expr)
2066 (idlwave-shell-recenter-shell-window)
2067 (idlwave-shell-send-command cmd)))))
2069 (defun idlwave-retrieve-expression-from-level (expr level routine help)
2070 "Return IDL command to print the expression EXPR from stack level LEVEL.
2072 It does not seem possible to evaluate an expression on a differnt
2073 level than the current. Therefore, this function retrieves *copies* of
2074 the variables involved in the expression from the desired level in the
2075 calling stack. The copies are given some unlikely names on the
2076 *current* level, and the expression is then evaluated on the *current*
2079 Since this function depends upon the undocumented IDL routine routine_names,
2080 there is no guarantie that this will work with future versions of IDL."
2081 (let ((prefix "___") ;; No real variables should starts with this.
2084 var tvar fetch-vars pre post)
2086 ;; FIXME: In the following we try to find the variables in expression
2087 ;; This is quite empirical - I don't know in what situations this will
2088 ;; break. We will look for identifiers and exclude cases where we
2089 ;; know it is not a variable. To distinguish array references from
2090 ;; function calls, we require that arrays use [] instead of ()
2092 (while (string-match
2093 "\\(\\`\\|[^a-zA-Z0-9$_]\\)\\([a-zA-Z][a-zA-Z0-9$_]*\\)\\([^a-zA-Z0-9$_]\\|\\'\\)" expr start)
2094 (setq var (match-string 2 expr)
2095 tvar (concat prefix var)
2096 start (match-beginning 2)
2097 pre (substring expr 0 (match-beginning 2))
2098 post (substring expr (match-end 2)))
2100 ;; Exclude identifiers which are not variables
2101 ((string-match ",[ \t]*/\\'" pre)) ;; a `/' KEYWORD
2102 ((and (string-match "[,(][ \t]*\\'" pre)
2103 (string-match "\\`[ \t]*=" post))) ;; a `=' KEYWORD
2104 ((string-match "\\`(" post)) ;; a function
2105 ((string-match "->[ \t]*\\'" pre)) ;; a method
2106 ((string-match "\\.\\'" pre)) ;; structure member
2107 (t ;; seems to be a variable - arrange to get it and replace
2108 ;; its name in the expression with the temproary name.
2109 (push (cons var tvar) fetch-vars)
2110 (setq expr (concat pre tvar post)))))
2111 ;; Make a command line that first copies the relevant variables
2112 ;; and then prints the expression.
2116 (format "%s = routine_names('%s',fetch=%d)" (cdr x) (car x) fetch))
2117 (nreverse fetch-vars)
2119 (if idlwave-shell-print-expression-function " & " "\n")
2120 (if help "help, " "print, ")
2122 (format " ; [-%d:%s]" level routine))))
2124 (defun idlwave-shell-delete-expression-overlay ()
2126 (if idlwave-shell-expression-overlay
2127 (delete-overlay idlwave-shell-expression-overlay))
2129 (remove-hook 'pre-command-hook 'idlwave-shell-delete-expression-overlay))
2131 (defvar idlwave-shell-bp-alist nil
2132 "Alist of breakpoints.
2133 A breakpoint is a cons cell \(\(file line\) . \(\(index module\) data\)\)
2135 The car is the frame for the breakpoint:
2136 file - full path file name.
2137 line - line number of breakpoint - integer.
2139 The first element of the cdr is a list of internal IDL data:
2140 index - the index number of the breakpoint internal to IDL.
2141 module - the module for breakpoint internal to IDL.
2143 Remaining elements of the cdr:
2144 data - Data associated with the breakpoint by idlwave-shell currently
2147 count - number of times to execute breakpoint. When count reaches 0
2148 the breakpoint is cleared and removed from the alist.
2149 command - command to execute when breakpoint is reached, either a
2150 lisp function to be called with `funcall' with no arguments or a
2151 list to be evaluated with `eval'.")
2153 (defun idlwave-shell-run-region (beg end &optional n)
2154 "Compile and run the region using the IDL process.
2155 Copies the region to a temporary file `idlwave-shell-temp-pro-file'
2156 and issues the IDL .run command for the file. Because the
2157 region is compiled and run as a main program there is no
2158 problem with begin-end blocks extending over multiple
2159 lines - which would be a problem if `idlwave-shell-evaluate-region'
2160 was used. An END statement is appended to the region if necessary.
2162 If there is a prefix argument, display IDL process."
2163 (interactive "r\nP")
2164 (let ((oldbuf (current-buffer)))
2166 (set-buffer (idlwave-find-file-noselect
2167 idlwave-shell-temp-pro-file 'tmp))
2169 (insert-buffer-substring oldbuf beg end)
2170 (if (not (save-excursion
2171 (idlwave-previous-statement)
2172 (idlwave-look-at "\\<end\\>")))
2175 (idlwave-shell-send-command (concat ".run " idlwave-shell-temp-pro-file))
2177 (idlwave-display-buffer (idlwave-shell-buffer)
2178 nil (idlwave-shell-shell-frame))))
2180 (defun idlwave-shell-evaluate-region (beg end &optional n)
2181 "Send region to the IDL process.
2182 If there is a prefix argument, display IDL process.
2183 Does not work for a region with multiline blocks - use
2184 `idlwave-shell-run-region' for this."
2185 (interactive "r\nP")
2186 (idlwave-shell-send-command (buffer-substring beg end))
2188 (idlwave-display-buffer (idlwave-shell-buffer)
2189 nil (idlwave-shell-shell-frame))))
2191 (defun idlwave-shell-delete-temp-files ()
2192 "Delete the temporary files and kill associated buffers."
2193 (if (stringp idlwave-shell-temp-pro-file)
2195 (let ((buf (idlwave-get-buffer-visiting
2196 idlwave-shell-temp-pro-file)))
2197 (if (buffer-live-p buf)
2199 (delete-file idlwave-shell-temp-pro-file))
2201 (if (stringp idlwave-shell-temp-rinfo-save-file)
2203 (delete-file idlwave-shell-temp-rinfo-save-file)
2206 (defun idlwave-display-buffer (buf not-this-window-p &optional frame)
2207 (if (or (< emacs-major-version 20)
2208 (and (= emacs-major-version 20)
2209 (< emacs-minor-version 3)))
2211 (display-buffer buf not-this-window-p)
2212 ;; Three ares possible.
2213 (display-buffer buf not-this-window-p frame)))
2215 (defvar idlwave-shell-bp-buffer " *idlwave-shell-bp*"
2216 "Scratch buffer for parsing IDL breakpoint lists and other stuff.")
2218 (defun idlwave-shell-bp-query ()
2219 "Reconcile idlwave-shell's breakpoint list with IDL's.
2220 Queries IDL using the string in `idlwave-shell-bp-query'."
2222 (idlwave-shell-send-command idlwave-shell-bp-query
2223 'idlwave-shell-filter-bp
2226 (defun idlwave-shell-bp-get (bp &optional item)
2227 "Get a value for a breakpoint.
2228 BP has the form of elements in idlwave-shell-bp-alist.
2229 Optional second arg ITEM is the particular value to retrieve.
2230 ITEM can be 'file, 'line, 'index, 'module, 'count, 'cmd, or 'data.
2231 'data returns a list of 'count and 'cmd.
2232 Defaults to 'index."
2235 ((eq item 'line) (nth 1 (car bp)))
2236 ((eq item 'file) (nth 0 (car bp)))
2237 ;; idlwave-shell breakpoint data
2238 ((eq item 'data) (cdr (cdr bp)))
2239 ((eq item 'count) (nth 0 (cdr (cdr bp))))
2240 ((eq item 'cmd) (nth 1 (cdr (cdr bp))))
2241 ;; IDL breakpoint info
2242 ((eq item 'module) (nth 1 (car (cdr bp))))
2244 (t (nth 0 (car (cdr bp))))))
2246 (defun idlwave-shell-filter-bp ()
2247 "Get the breakpoints from `idlwave-shell-command-output'.
2248 Create `idlwave-shell-bp-alist' updating breakpoint count and command data
2249 from previous breakpoint list."
2251 (set-buffer (get-buffer-create idlwave-shell-bp-buffer))
2253 (insert idlwave-shell-command-output)
2254 (goto-char (point-min))
2255 (let ((old-bp-alist idlwave-shell-bp-alist)
2256 file line index module)
2257 (setq idlwave-shell-bp-alist (list nil))
2258 (when (re-search-forward "^\\s-*Index.*\n\\s-*-" nil t)
2259 ;; There seems to be a breakpoint listing here.
2260 ;; Parse breakpoint lines.
2261 ;; Breakpoints have the form:
2262 ;; Index Module Line File
2263 ;; All seperated by whitespace.
2264 ;; Module may be missing if the file is not compiled.
2266 (while (re-search-forward
2267 "^[ \t]*\\([0-9]+\\)[ \t]+\\(\\S-+\\)?[ \t]+\\([0-9]+\\)[ \t]+\\(\\S-+\\)" nil t)
2268 (setq index (match-string 1)
2269 module (match-string 2)
2270 line (string-to-int (match-string 3))
2271 file (idlwave-shell-file-name (match-string 4)))
2272 ;; Add the breakpoint info to the list
2273 (nconc idlwave-shell-bp-alist
2274 (list (cons (list file line)
2277 ;; idlwave-shell data: count, command
2279 (setq idlwave-shell-bp-alist (cdr idlwave-shell-bp-alist))
2280 ;; Update count, commands of breakpoints
2281 (mapcar 'idlwave-shell-update-bp old-bp-alist)))
2282 ;; Update the breakpoint overlays
2283 (idlwave-shell-update-bp-overlays)
2284 ;; Return the new list
2285 idlwave-shell-bp-alist)
2287 (defun idlwave-shell-update-bp (bp)
2288 "Update BP data in breakpoint list.
2289 If BP frame is in `idlwave-shell-bp-alist' updates the breakpoint data."
2290 (let ((match (assoc (car bp) idlwave-shell-bp-alist)))
2291 (if match (setcdr (cdr match) (cdr (cdr bp))))))
2293 (defun idlwave-shell-set-bp-data (bp data)
2294 "Set the data of BP to DATA."
2295 (setcdr (cdr bp) data))
2297 (defun idlwave-shell-bp (frame &optional data module)
2298 "Create a breakpoint structure containing FRAME and DATA. Second
2299 and third args, DATA and MODULE, are optional. Returns a breakpoint
2300 of the format used in `idlwave-shell-bp-alist'. Can be used in commands
2301 attempting match a breakpoint in `idlwave-shell-bp-alist'."
2302 (cons frame (cons (list nil module) data)))
2304 (defvar idlwave-shell-old-bp nil
2305 "List of breakpoints previous to setting a new breakpoint.")
2307 (defun idlwave-shell-sources-bp (bp)
2308 "Check `idlwave-shell-sources-alist' for source of breakpoint using BP.
2309 If an equivalency is found, return the IDL internal source name.
2310 Otherwise return the filename in bp."
2312 ((bp-file (idlwave-shell-bp-get bp 'file))
2313 (bp-module (idlwave-shell-bp-get bp 'module))
2314 (internal-file-list (cdr (assoc bp-module idlwave-shell-sources-alist))))
2315 (if (and internal-file-list
2316 (equal bp-file (nth 0 internal-file-list)))
2317 (nth 1 internal-file-list)
2320 (defun idlwave-shell-set-bp (bp)
2321 "Try to set a breakpoint BP.
2323 The breakpoint will be placed at the beginning of the statement on the
2324 line specified by BP or at the next IDL statement if that line is not
2326 Determines IDL's internal representation for the breakpoint which may
2327 have occured at a different line then used with the breakpoint
2330 ;; Get and save the old breakpoints
2331 (idlwave-shell-send-command
2332 idlwave-shell-bp-query
2334 (idlwave-shell-filter-bp)
2335 (setq idlwave-shell-old-bp idlwave-shell-bp-alist))
2337 ;; Get sources for IDL compiled procedures followed by setting
2339 (idlwave-shell-send-command
2340 idlwave-shell-sources-query
2342 (idlwave-shell-sources-filter)
2343 (idlwave-shell-set-bp2 (quote (, bp)))))
2346 (defun idlwave-shell-set-bp2 (bp)
2347 "Use results of breakpoint and sources query to set bp.
2348 Use the count argument with IDLs breakpoint command.
2349 We treat a count of 1 as a temporary breakpoint.
2350 Counts greater than 1 use the IDL AFTER=count keyword to break
2351 only after reaching the statement count times."
2353 ((arg (idlwave-shell-bp-get bp 'count))
2355 ((not (and arg (numberp arg))) "")
2359 (format ",after=%d" arg))))
2360 (line (idlwave-shell-bp-get bp 'line)))
2361 (idlwave-shell-send-command
2362 (concat "breakpoint,'"
2363 (idlwave-shell-sources-bp bp) "',"
2364 (if (integerp line) (setq line (int-to-string line)))
2366 ;; Check for failure and look for breakpoint in IDL's list
2368 (if (idlwave-shell-set-bp-check (quote (, bp)))
2369 (idlwave-shell-set-bp3 (quote (, bp)))))
2371 ;; do not hide output
2375 (defun idlwave-shell-set-bp3 (bp)
2376 "Find the breakpoint in IDL's internal list of breakpoints."
2377 (idlwave-shell-send-command idlwave-shell-bp-query
2379 (idlwave-shell-filter-bp)
2380 (idlwave-shell-new-bp (quote (, bp)))))
2384 (defun idlwave-shell-find-bp (frame)
2385 "Return breakpoint from `idlwave-shell-bp-alist' for frame.
2386 Returns nil if frame not found."
2387 (assoc frame idlwave-shell-bp-alist))
2389 (defun idlwave-shell-new-bp (bp)
2390 "Find the new breakpoint in IDL's list and update with DATA.
2391 The actual line number for a breakpoint in IDL may be different than
2392 the line number used with the IDL breakpoint command.
2393 Looks for a new breakpoint index number in the list. This is
2394 considered the new breakpoint if the file name of frame matches."
2395 (let ((obp-index (mapcar 'idlwave-shell-bp-get idlwave-shell-old-bp))
2396 (bpl idlwave-shell-bp-alist))
2397 (while (and (member (idlwave-shell-bp-get (car bpl)) obp-index)
2398 (setq bpl (cdr bpl))))
2401 ;; No additional breakpoint.
2402 ;; Need to check if we are just replacing a breakpoint.
2403 (setq bpl (assoc (car bp) idlwave-shell-bp-alist)))
2404 (setq bpl (list bpl)))
2406 (equal (idlwave-shell-bp-get (setq bpl (car bpl)) 'file)
2407 (idlwave-shell-bp-get bp 'file)))
2408 ;; Got the breakpoint - add count, command to it.
2409 ;; This updates `idlwave-shell-bp-alist' because a deep copy was
2410 ;; not done for bpl.
2411 (idlwave-shell-set-bp-data bpl (idlwave-shell-bp-get bp 'data))
2413 (message "Failed to identify breakpoint in IDL"))))
2415 (defvar idlwave-shell-bp-overlays nil
2416 "List of overlays marking breakpoints")
2418 (defun idlwave-shell-update-bp-overlays ()
2419 "Update the overlays which mark breakpoints in the source code.
2420 Existing overlays are recycled, in order to minimize consumption."
2421 ;; FIXME: we could cache them all, but that would be more work.
2422 (when idlwave-shell-mark-breakpoints
2423 (let ((bp-list idlwave-shell-bp-alist)
2424 (ov-list idlwave-shell-bp-overlays)
2426 ;; Delete the old overlays from their buffers
2427 (while (setq ov (pop ov-list))
2428 (delete-overlay ov))
2429 (setq ov-list idlwave-shell-bp-overlays
2430 idlwave-shell-bp-overlays nil)
2431 (while (setq bp (pop bp-list))
2433 (idlwave-shell-goto-frame (car bp))
2434 (let* ((end (progn (end-of-line 1) (point)))
2435 (beg (progn (beginning-of-line 1) (point)))
2436 (ov (or (pop ov-list)
2437 (idlwave-shell-make-new-bp-overlay))))
2438 (move-overlay ov beg end)
2439 (push ov idlwave-shell-bp-overlays)))))))
2441 (defvar idlwave-shell-bp-glyph)
2442 (defun idlwave-shell-make-new-bp-overlay ()
2443 "Make a new overlay for highlighting breakpoints.
2444 This stuff is stringly dependant upon the version of Emacs."
2445 (let ((ov (make-overlay 1 1)))
2446 (if (featurep 'xemacs)
2450 ((eq (console-type) 'tty)
2451 ;; tty's cannot display glyphs
2452 (set-extent-property ov 'face idlwave-shell-breakpoint-face))
2453 ((and (memq idlwave-shell-mark-breakpoints '(t glyph))
2454 idlwave-shell-bp-glyph)
2456 (set-extent-property ov 'begin-glyph idlwave-shell-bp-glyph))
2457 (idlwave-shell-mark-breakpoints
2459 (set-extent-property ov 'face idlwave-shell-breakpoint-face))
2463 (set-extent-priority ov -1)) ; make stop line face prevail
2467 (if (and (memq idlwave-shell-mark-breakpoints '(t glyph))
2468 idlwave-shell-bp-glyph) ; this var knows if glyph's possible
2471 (put-text-property 0 1
2472 'display idlwave-shell-bp-glyph
2474 (overlay-put ov 'before-string string))
2475 (overlay-put ov 'face idlwave-shell-breakpoint-face)))
2476 (idlwave-shell-mark-breakpoints
2478 (overlay-put ov 'face idlwave-shell-breakpoint-face))
2484 (defun idlwave-shell-edit-default-command-line (arg)
2485 "Edit the current execute command."
2487 (setq idlwave-shell-command-line-to-execute
2488 (read-string "IDL> " idlwave-shell-command-line-to-execute)))
2490 (defun idlwave-shell-execute-default-command-line (arg)
2491 "Execute a command line. On first use, ask for the command.
2492 Also with prefix arg, ask for the command. You can also uase the command
2493 `idlwave-shell-edit-default-command-line' to edit the line."
2495 (if (or (not idlwave-shell-command-line-to-execute)
2497 (setq idlwave-shell-command-line-to-execute
2498 (read-string "IDL> " idlwave-shell-command-line-to-execute)))
2499 (idlwave-shell-reset 'hidden)
2500 (idlwave-shell-send-command idlwave-shell-command-line-to-execute
2501 '(idlwave-shell-redisplay 'hide)))
2503 (defun idlwave-shell-save-and-run ()
2504 "Save file and run it in IDL.
2505 Runs `save-buffer' and sends a '.RUN' command for the associated file to IDL.
2506 When called from the shell buffer, re-run the file which was last handled by
2507 one of the save-and-.. commands."
2509 (idlwave-shell-save-and-action 'run))
2511 (defun idlwave-shell-save-and-compile ()
2512 "Save file and run it in IDL.
2513 Runs `save-buffer' and sends '.COMPILE' command for the associated file to IDL.
2514 When called from the shell buffer, re-compile the file which was last handled by
2515 one of the save-and-.. commands."
2517 (idlwave-shell-save-and-action 'compile))
2519 (defun idlwave-shell-save-and-batch ()
2520 "Save file and batch it in IDL.
2521 Runs `save-buffer' and sends a '@file' command for the associated file to IDL.
2522 When called from the shell buffer, re-batch the file which was last handled by
2523 one of the save-and-.. commands."
2525 (idlwave-shell-save-and-action 'batch))
2527 (defun idlwave-shell-save-and-action (action)
2528 "Save file and compile it in IDL.
2529 Runs `save-buffer' and sends a '.RUN' command for the associated file to IDL.
2530 When called from the shell buffer, re-compile the file which was last
2531 handled by this command."
2532 ;; Remove the stop overlay.
2533 (if idlwave-shell-stop-line-overlay
2534 (delete-overlay idlwave-shell-stop-line-overlay))
2535 (setq idlwave-shell-is-stopped nil)
2536 (setq overlay-arrow-string nil)
2539 ((eq major-mode 'idlwave-mode)
2541 (setq idlwave-shell-last-save-and-action-file (buffer-file-name)))
2542 (idlwave-shell-last-save-and-action-file
2543 (if (setq buf (idlwave-get-buffer-visiting
2544 idlwave-shell-last-save-and-action-file))
2548 (t (setq idlwave-shell-last-save-and-action-file
2549 (read-file-name "File: ")))))
2550 (if (file-regular-p idlwave-shell-last-save-and-action-file)
2552 (idlwave-shell-send-command
2553 (concat (cond ((eq action 'run) ".run ")
2554 ((eq action 'compile) ".compile ")
2555 ((eq action 'batch) "@")
2556 (t (error "Unknown action %s" action)))
2557 idlwave-shell-last-save-and-action-file)
2558 'idlwave-shell-maybe-update-routine-info
2560 (idlwave-shell-bp-query))
2561 (let ((msg (format "No such file %s"
2562 idlwave-shell-last-save-and-action-file)))
2563 (setq idlwave-shell-last-save-and-action-file nil)
2566 (defun idlwave-shell-maybe-update-routine-info ()
2567 "Update the routine info if the shell is not stopped at an error."
2568 (if (and (not idlwave-shell-is-stopped)
2569 (or (eq t idlwave-auto-routine-info-updates)
2570 (memq 'compile-buffer idlwave-auto-routine-info-updates))
2571 idlwave-query-shell-for-routine-info
2573 (idlwave-shell-update-routine-info t)))
2575 (defvar idlwave-shell-sources-query "help,/source"
2576 "IDL command to obtain source files for compiled procedures.")
2578 (defvar idlwave-shell-sources-alist nil
2579 "Alist of IDL procedure names and compiled source files.
2580 Elements of the alist have the form:
2582 (module name . (source-file-truename idlwave-internal-filename)).")
2584 (defun idlwave-shell-sources-query ()
2585 "Determine source files for IDL compiled procedures.
2586 Queries IDL using the string in `idlwave-shell-sources-query'."
2588 (idlwave-shell-send-command idlwave-shell-sources-query
2589 'idlwave-shell-sources-filter
2592 (defun idlwave-shell-sources-filter ()
2593 "Get source files from `idlwave-shell-sources-query' output.
2594 Create `idlwave-shell-sources-alist' consisting of
2595 list elements of the form:
2596 (module name . (source-file-truename idlwave-internal-filename))."
2598 (set-buffer (get-buffer-create idlwave-shell-bp-buffer))
2600 (insert idlwave-shell-command-output)
2601 (goto-char (point-min))
2603 (if (re-search-forward "Compiled Procedures:" nil t)
2605 (forward-line) ; Skip $MAIN$
2606 (setq cpro (point))))
2607 (if (re-search-forward "Compiled Functions:" nil t)
2610 (setq idlwave-shell-sources-alist
2612 ;; compiled procedures
2615 (narrow-to-region cpro (point))
2616 (goto-char (point-min))
2617 (idlwave-shell-sources-grep))
2618 ;; compiled functions
2622 (idlwave-shell-sources-grep)))))))))
2624 (defun idlwave-shell-sources-grep ()
2626 (let ((al (list nil)))
2628 (not (progn (forward-line) (eobp)))
2630 "\\s-*\\(\\S-+\\)\\s-+\\(\\S-+\\)" nil t))
2634 (buffer-substring ; name
2635 (match-beginning 1) (match-end 1))
2636 (let ((internal-filename
2637 (buffer-substring ; source
2638 (match-beginning 2) (match-end 2))))
2640 (idlwave-shell-file-name internal-filename)
2646 (defun idlwave-shell-clear-all-bp ()
2647 "Remove all breakpoints in IDL."
2649 (idlwave-shell-send-command
2650 idlwave-shell-bp-query
2652 (idlwave-shell-filter-bp)
2653 (mapcar 'idlwave-shell-clear-bp idlwave-shell-bp-alist))
2656 (defun idlwave-shell-list-all-bp ()
2657 "List all breakpoints in IDL."
2659 (idlwave-shell-send-command
2660 idlwave-shell-bp-query))
2662 (defvar idlwave-shell-error-last 0
2663 "Position of last syntax error in `idlwave-shell-error-buffer'.")
2665 (defun idlwave-shell-goto-next-error ()
2666 "Move point to next IDL syntax error."
2670 (set-buffer idlwave-shell-error-buffer)
2671 (goto-char idlwave-shell-error-last)
2672 (if (or (re-search-forward idlwave-shell-syntax-error nil t)
2673 (re-search-forward idlwave-shell-other-error nil t))
2678 (idlwave-shell-file-name
2679 (buffer-substring (match-beginning 1) (match-end 1))))
2681 (buffer-substring (match-beginning 2)
2683 ;; Try to find the column of the error
2686 (if (re-search-backward "\\^" nil t)
2689 (setq idlwave-shell-error-last (point)))
2692 (idlwave-shell-display-line frame col))
2694 (message "No more errors."))))
2696 (defun idlwave-shell-file-name (name)
2697 "If `idlwave-shell-use-truename' is non-nil, convert file name to true name.
2698 Otherwise, just expand the file name."
2699 (let ((def-dir (if (eq major-mode 'idlwave-shell-mode)
2701 idlwave-shell-default-directory)))
2702 (if idlwave-shell-use-truename
2703 (file-truename name def-dir)
2704 (expand-file-name name def-dir))))
2707 ;; Keybindings --------------------------------------------------------------
2709 (defvar idlwave-shell-mode-map (copy-keymap comint-mode-map)
2710 "Keymap for idlwave-mode.")
2711 (defvar idlwave-shell-mode-prefix-map (make-sparse-keymap))
2712 (fset 'idlwave-shell-mode-prefix-map idlwave-shell-mode-prefix-map)
2714 ;(define-key idlwave-shell-mode-map "\M-?" 'comint-dynamic-list-completions)
2715 ;(define-key idlwave-shell-mode-map "\t" 'comint-dynamic-complete)
2716 (define-key idlwave-shell-mode-map "\t" 'idlwave-shell-complete)
2717 (define-key idlwave-shell-mode-map "\M-\t" 'idlwave-shell-complete)
2718 (define-key idlwave-shell-mode-map "\C-c\C-s" 'idlwave-shell)
2719 (define-key idlwave-shell-mode-map "\C-c?" 'idlwave-routine-info)
2720 (define-key idlwave-shell-mode-map "\M-?" 'idlwave-context-help)
2721 (define-key idlwave-shell-mode-map "\C-c\C-i" 'idlwave-update-routine-info)
2722 (define-key idlwave-shell-mode-map "\C-c\C-y" 'idlwave-shell-char-mode-loop)
2723 (define-key idlwave-shell-mode-map "\C-c\C-x" 'idlwave-shell-send-char)
2724 (define-key idlwave-shell-mode-map "\C-c=" 'idlwave-resolve)
2725 (define-key idlwave-shell-mode-map "\C-c\C-v" 'idlwave-find-module)
2726 (define-key idlwave-shell-mode-map "\C-c\C-k" 'idlwave-kill-autoloaded-buffers)
2727 (define-key idlwave-shell-mode-map idlwave-shell-prefix-key
2728 'idlwave-shell-debug-map)
2729 (define-key idlwave-mode-map "\C-c\C-y" 'idlwave-shell-char-mode-loop)
2730 (define-key idlwave-mode-map "\C-c\C-x" 'idlwave-shell-send-char)
2731 (define-key idlwave-mode-map
2732 (if (featurep 'xemacs) [(shift button2)] [(shift mouse-2)])
2733 'idlwave-shell-mouse-print)
2734 (define-key idlwave-mode-map
2735 (if (featurep 'xemacs) [(shift control button2)] [(shift control mouse-2)])
2736 'idlwave-shell-mouse-help)
2737 (define-key idlwave-shell-mode-map
2738 (if (featurep 'xemacs) [(shift button2)] [(shift mouse-2)])
2739 'idlwave-shell-mouse-print)
2740 (define-key idlwave-shell-mode-map
2741 (if (featurep 'xemacs) [(shift control button2)] [(shift control mouse-2)])
2742 'idlwave-shell-mouse-help)
2743 (define-key idlwave-shell-mode-map
2744 (if (featurep 'xemacs) [(shift button3)] [(shift mouse-3)])
2745 'idlwave-mouse-context-help)
2748 ;; The following set of bindings is used to bind the debugging keys.
2749 ;; If `idlwave-shell-activate-prefix-keybindings' is non-nil, the first key
2750 ;; in the list gets bound the C-c C-d prefix map.
2751 ;; If `idlwave-shell-activate-alt-keybindings' is non-nil, the second key
2752 ;; in the list gets bound directly in both idlwave-mode-map and
2753 ;; idlwave-shell-mode-map.
2755 ;; Used keys: abcde hi klmnopqrs u wxyz
2756 ;; Unused keys: fg j t v
2758 '(([(control ?b)] [(alt ?b)] idlwave-shell-break-here)
2759 ([(control ?i)] [(alt ?i)] idlwave-shell-break-in)
2760 ([(control ?d)] [(alt ?d)] idlwave-shell-clear-current-bp)
2761 ([(control ?a)] [(alt ?a)] idlwave-shell-clear-all-bp)
2762 ([(control ?s)] [(alt ?s)] idlwave-shell-step)
2763 ([(control ?n)] [(alt ?n)] idlwave-shell-stepover)
2764 ([(control ?k)] [(alt ?k)] idlwave-shell-skip)
2765 ([(control ?u)] [(alt ?u)] idlwave-shell-up)
2766 ([(control ?o)] [(alt ?o)] idlwave-shell-out)
2767 ([(control ?m)] [(alt ?m)] idlwave-shell-return)
2768 ([(control ?h)] [(alt ?h)] idlwave-shell-to-here)
2769 ([(control ?r)] [(alt ?r)] idlwave-shell-cont)
2770 ([(control ?y)] [(alt ?y)] idlwave-shell-execute-default-command-line)
2771 ([(control ?z)] [(alt ?z)] idlwave-shell-reset)
2772 ([(control ?q)] [(alt ?q)] idlwave-shell-quit)
2773 ([(control ?p)] [(alt ?p)] idlwave-shell-print)
2774 ([(??)] [(alt ??)] idlwave-shell-help-expression)
2775 ([(control ?c)] [(alt ?c)] idlwave-shell-save-and-run)
2776 ([( ?@)] [(alt ?@)] idlwave-shell-save-and-batch)
2777 ([(control ?x)] [(alt ?x)] idlwave-shell-goto-next-error)
2778 ([(control ?e)] [(alt ?e)] idlwave-shell-run-region)
2779 ([(control ?w)] [(alt ?w)] idlwave-shell-resync-dirs)
2780 ([(control ?l)] [(alt ?l)] idlwave-shell-redisplay)
2781 ([(control ?t)] [(alt ?t)] idlwave-shell-toggle-toolbar)
2782 ([(control up)] [(alt up)] idlwave-shell-stack-up)
2783 ([(control down)] [(alt down)] idlwave-shell-stack-down)
2786 (while (setq s (pop specs))
2790 (when idlwave-shell-activate-prefix-keybindings
2791 (and k1 (define-key idlwave-shell-mode-prefix-map k1 cmd)))
2792 (when idlwave-shell-activate-alt-keybindings
2793 (and k2 (define-key idlwave-mode-map k2 cmd))
2794 (and k2 (define-key idlwave-shell-mode-map k2 cmd)))))
2796 ;; Enter the prefix map at the two places.
2797 (fset 'idlwave-debug-map idlwave-shell-mode-prefix-map)
2798 (fset 'idlwave-shell-debug-map idlwave-shell-mode-prefix-map)
2800 ;; The Menus --------------------------------------------------------------
2802 (defvar idlwave-shell-menu-def
2804 ["Save and .RUN" idlwave-shell-save-and-run
2805 (or (eq major-mode 'idlwave-mode)
2806 idlwave-shell-last-save-and-action-file)]
2807 ["Save and .COMPILE" idlwave-shell-save-and-compile
2808 (or (eq major-mode 'idlwave-mode)
2809 idlwave-shell-last-save-and-action-file)]
2810 ["Save and @Batch" idlwave-shell-save-and-batch
2811 (or (eq major-mode 'idlwave-mode)
2812 idlwave-shell-last-save-and-action-file)]
2813 ["Goto Next Error" idlwave-shell-goto-next-error t]
2815 ["Execute Default Cmd" idlwave-shell-execute-default-command-line t]
2816 ["Edit Default Cmd" idlwave-shell-edit-default-command-line t]
2818 ["Set Breakpoint" idlwave-shell-break-here
2819 (eq major-mode 'idlwave-mode)]
2820 ["Break in Module" idlwave-shell-break-in t]
2821 ["Clear Breakpoint" idlwave-shell-clear-current-bp t]
2822 ["Clear All Breakpoints" idlwave-shell-clear-all-bp t]
2823 ["List All Breakpoints" idlwave-shell-list-all-bp t]
2825 ["Step (into)" idlwave-shell-step t]
2826 ["Step (over)" idlwave-shell-stepover t]
2827 ["Skip One Statement" idlwave-shell-skip t]
2828 ["Continue" idlwave-shell-cont t]
2830 ["End of Block" idlwave-shell-up t]
2831 ["End of Subprog" idlwave-shell-return t]
2832 ["End of Subprog+1" idlwave-shell-out t]
2833 ["Here (Cursor Line)" idlwave-shell-to-here
2834 (eq major-mode 'idlwave-mode)])
2836 ["Print expression" idlwave-shell-print t]
2837 ["Help on expression" idlwave-shell-help-expression t]
2838 ["Evaluate Region" idlwave-shell-evaluate-region
2839 (eq major-mode 'idlwave-mode)]
2840 ["Run Region" idlwave-shell-run-region (eq major-mode 'idlwave-mode)]
2842 ["Redisplay" idlwave-shell-redisplay t]
2843 ["Stack Up" idlwave-shell-stack-up t]
2844 ["Stack Down" idlwave-shell-stack-down t]
2846 ["Update Working Dir" idlwave-shell-resync-dirs t]
2847 ["Reset IDL" idlwave-shell-reset t]
2849 ["Toggle Toolbar" idlwave-shell-toggle-toolbar t]
2850 ["Exit IDL" idlwave-shell-quit t]))
2851 ;;FIXME: Which menu???
2852 (setq idlwave-shell-menu-def
2855 ["Save and .RUN" idlwave-shell-save-and-run
2856 (or (eq major-mode 'idlwave-mode)
2857 idlwave-shell-last-save-and-action-file)]
2858 ["Save and .COMPILE" idlwave-shell-save-and-compile
2859 (or (eq major-mode 'idlwave-mode)
2860 idlwave-shell-last-save-and-action-file)]
2861 ["Save and @Batch" idlwave-shell-save-and-batch
2862 (or (eq major-mode 'idlwave-mode)
2863 idlwave-shell-last-save-and-action-file)]
2864 ["Goto Next Error" idlwave-shell-goto-next-error t]
2866 ["Run Region" idlwave-shell-run-region (eq major-mode 'idlwave-mode)]
2868 ["Execute Default Cmd" idlwave-shell-execute-default-command-line t]
2869 ["Edit Default Cmd" idlwave-shell-edit-default-command-line t])
2871 ["Set Breakpoint" idlwave-shell-break-here
2872 (eq major-mode 'idlwave-mode)]
2873 ["Break in Module" idlwave-shell-break-in t]
2874 ["Clear Breakpoint" idlwave-shell-clear-current-bp t]
2875 ["Clear All Breakpoints" idlwave-shell-clear-all-bp t]
2876 ["List All Breakpoints" idlwave-shell-list-all-bp t])
2878 ["Step (into)" idlwave-shell-step t]
2879 ["Step (over)" idlwave-shell-stepover t]
2880 ["Skip One Statement" idlwave-shell-skip t]
2881 ["Continue" idlwave-shell-cont t]
2882 ["... to End of Block" idlwave-shell-up t]
2883 ["... to End of Subprog" idlwave-shell-return t]
2884 ["... to End of Subprog+1" idlwave-shell-out t]
2885 ["... to Here (Cursor Line)" idlwave-shell-to-here
2886 (eq major-mode 'idlwave-mode)])
2888 ["Print expression" idlwave-shell-print t]
2889 ["Help on expression" idlwave-shell-help-expression t]
2890 ["Evaluate Region" idlwave-shell-evaluate-region
2891 (eq major-mode 'idlwave-mode)]
2893 ["Redisplay" idlwave-shell-redisplay t]
2894 ["Stack Up" idlwave-shell-stack-up t]
2895 ["Stack Down" idlwave-shell-stack-down t])
2897 ["Send one char" idlwave-shell-send-char t]
2898 ["Temporary Character Mode" idlwave-shell-char-mode-loop t]
2900 ["Use Input Mode Magic"
2901 (setq idlwave-shell-use-input-mode-magic
2902 (not idlwave-shell-use-input-mode-magic))
2903 :style toggle :selected idlwave-shell-use-input-mode-magic])
2905 ["Update Working Dir" idlwave-shell-resync-dirs t]
2906 ["Reset IDL" idlwave-shell-reset t]
2908 ["Toggle Toolbar" idlwave-shell-toggle-toolbar t]
2909 ["Exit IDL" idlwave-shell-quit t]))
2911 (if (or (featurep 'easymenu) (load "easymenu" t))
2914 idlwave-shell-mode-menu idlwave-shell-mode-map "IDL shell menus"
2915 idlwave-shell-menu-def)
2917 idlwave-mode-debug-menu idlwave-mode-map "IDL debugging menus"
2918 idlwave-shell-menu-def)
2920 (mapcar (lambda (buf)
2922 (if (eq major-mode 'idlwave-mode)
2924 (easy-menu-remove idlwave-mode-debug-menu)
2925 (easy-menu-add idlwave-mode-debug-menu))))
2928 ;; The Breakpoint Glyph -------------------------------------------------------
2930 (defvar idlwave-shell-bp-glyph nil
2931 "The glyph to mark breakpoint lines in the source code.")
2933 (let ((image-string "/* XPM */
2934 static char * file[] = {
2936 \" c #FFFFFFFFFFFF s backgroundColor\",
2937 \". c #4B4B4B4B4B4B\",
2938 \"R c #FFFF00000000\",
2952 (setq idlwave-shell-bp-glyph
2953 (cond ((and (featurep 'xemacs)
2955 (make-glyph image-string))
2956 ((and (not (featurep 'xemacs))
2957 (fboundp 'image-type-available-p)
2958 (image-type-available-p 'xpm))
2959 (list 'image :type 'xpm :data image-string))
2962 (provide 'idlw-shell)
2963 (provide 'idlwave-shell)
2965 ;;; Load the toolbar when wanted by the user.
2967 (autoload 'idlwave-toolbar-toggle "idlw-toolbar"
2968 "Toggle the IDLWAVE toolbar")
2969 (autoload 'idlwave-toolbar-add-everywhere "idlw-toolbar"
2970 "Add IDLWAVE toolbar")
2971 (defun idlwave-shell-toggle-toolbar ()
2972 "Toggle the display of the debugging toolbar."
2974 (idlwave-toolbar-toggle))
2976 (if idlwave-shell-use-toolbar
2977 (add-hook 'idlwave-shell-mode-hook 'idlwave-toolbar-add-everywhere))
2979 ;;; idlw-shell.el ends here