(shell-mode): Use define-derived-mode.
[emacs.git] / lisp / progmodes / idlw-shell.el
blob07d703e6efaac4c6bf83149060f0186bf5ee54f6
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>
8 ;; Version: 4.2
9 ;; Date: $Date: 2000/06/20 12:49:42 $
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)
17 ;; any later version.
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; 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.
29 ;;; Commentary:
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'.
43 ;; INSTALLATION:
44 ;; =============
45 ;;
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)
53 ;; SOURCE
54 ;; ======
56 ;; The newest version of this file can be found on the maintainers
57 ;; web site.
58 ;;
59 ;; http://www.strw.leidenuniv.el/~dominik/Tools/idlwave
60 ;;
61 ;; DOCUMENTATION
62 ;; =============
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)
69 ;; KNOWN PROBLEMS
70 ;; ==============
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.
83 ;;
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 ;;--------------------------------------------------------------------------
95 ;;; Code:
97 (require 'comint)
98 (require 'idlwave)
100 (eval-when-compile (require 'cl))
102 (defvar idlwave-shell-have-new-custom nil)
103 (eval-and-compile
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)
108 (fboundp 'defface))
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."
120 :prefix "idlwave"
121 :group 'idlwave)
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
128 process buffer.
130 This is a fine thing to set in your `.emacs' file."
131 :group 'idlwave-shell-general-setup
132 :type 'regexp)
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
138 :type 'string)
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
145 :type 'boolean)
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
152 :type 'string)
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
157 :type 'boolean)
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
165 :type '(repeat
166 (cons symbol sexp)))
168 (defcustom idlwave-shell-use-toolbar t
169 "Non-nil means, use the debugging toolbar in all IDL related buffers.
170 Starting the shell will then add the toolbar to all idlwave-mode buffers.
171 Exiting the shell will removed everywhere.
172 Available on XEmacs and on Emacs 21.x or later.
173 At any time you can toggle the display of the toolbar with
174 `C-c C-d C-t' (`idlwave-shell-toggle-toolbar')."
175 :group 'idlwave-shell-general-setup
176 :type 'boolean)
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
184 :type 'string)
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
197 :type 'string)
199 (defcustom idlwave-shell-activate-prefix-keybindings t
200 "Non-nil means, the debug commands will be bound to the prefix key.
201 The prefix key itself is given in the option `idlwave-shell-prefix-key'.
202 So by default setting a breakpoint will be on C-c C-d C-b."
203 :group 'idlwave-shell-general-setup
204 :type 'boolean)
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
210 :type 'boolean)
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
218 reuse that buffer.
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
223 :type 'boolean)
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
230 :type 'string)
232 (defcustom idlwave-shell-mode-hook '()
233 "*Hook for customising `idlwave-shell-mode'."
234 :group 'idlwave-shell-general-setup
235 :type 'hook)
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
244 :type 'symbol)
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
253 :type 'boolean)
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
278 REPEAT BEGIN
279 A = GET_KBRD(1)
280 PRINT, BYTE(A)
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
286 answer = GET_KBRD(1)
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.
292 Usage:
293 ======
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>'
306 endif
307 end"
308 :group 'idlwave-shell-general-setup
309 :type '(list
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."
318 :prefix "idlwave"
319 :group 'idlwave)
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
324 are:
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
337 :type '(choice
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
350 :type 'string)
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
357 :type 'symbol)
359 (defcustom idlwave-shell-mark-breakpoints t
360 "*Non-nil means, mark breakpoints in the source files.
361 Legal values are:
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
368 :type '(choice
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
382 :type 'symbol)
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"))
388 (t (:underline t)))
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
399 :type 'symbol)
401 ;;; End user customization variables
403 ;;; External variables
404 (defvar comint-last-input-start)
405 (defvar comint-last-input-end)
407 ;; Other variables
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))
442 (condition-case nil
443 (require 'overlay)
444 (error nil)))
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.
462 (cond
463 ((or (null idlwave-shell-mark-stop-line)
464 (eq idlwave-shell-mark-stop-line 'arrow))
465 ;; Leave the overlay nil
466 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
474 (progn
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
481 (if window-system
482 (progn
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
504 buffer.")
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
523 with `*'s."
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.
531 ;;;
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"
544 "^% Interrupted at:"
545 "^% Stepped to:"
546 "^% 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
565 '("^% Stepped to:"
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.
593 1. Shell Interaction
594 -----------------
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
598 end of the buffer.
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'.
604 2. Completion
605 ----------
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'.
611 3. Routine Info
612 ------------
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.
624 4. Debugging
625 ---------
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
633 installed.
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.
642 5. Hooks
643 -----
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'.
655 7. Keybindings
656 -----------
657 \\{idlwave-shell-mode-map}"
659 (interactive)
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
673 '(""
674 mode-line-modified
675 mode-line-buffer-identification
677 global-mode-string
678 " %[("
679 mode-name
680 mode-line-process
681 minor-mode-alist
682 "%n"
683 ")%]-"
684 idlwave-shell-mode-line-info
685 "---"
686 (line-number-mode "L%l--")
687 (column-number-mode "C%c--")
688 (-3 . "%p")
689 "-%-"))
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
710 nil 'local)
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 ";")
720 (setq abbrev-mode t)
721 (make-local-hook 'post-command-hook)
722 (add-hook 'post-command-hook 'idlwave-command-hook nil t)
724 ;; Run the hooks.
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)
730 nil 'hide)
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
735 'hide)))
737 (defun idlwave-shell-get-path-info ()
738 (let* ((rpl (idlwave-shell-path-filter))
739 (sysdir (car rpl))
740 (dirs (cdr rpl)))
741 (setq idlwave-sys-dir sysdir)
742 (setq idlwave-path-alist (mapcar (lambda(x) (cons x nil))
743 dirs))))
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)
767 (make-frame)
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)))))
785 ;;;###autoload
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
793 separate frames.
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.)"
802 (interactive "P")
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)
821 (set-buffer buf)
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."
836 (interactive "P")
837 (let ((window (selected-window)))
838 (idlwave-shell arg)
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
857 (let (buf proc)
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)
862 (error
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))))
869 ;; Still nothing
870 (error "Problem with autostarting IDL shell"))))
872 (save-excursion
873 (set-buffer buf)
874 (goto-char (process-mark proc))
875 ;; To make this easy, always push CMD onto pending commands
876 (if cmd
877 (setq idlwave-shell-pending-commands
878 (if preempt
879 ;; Put at front.
880 (append (list (list cmd pcmd hide))
881 idlwave-shell-pending-commands)
882 ;; Put at end.
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
888 (save-excursion
889 ;; Using (forward-line 0) instead of beginning-of-line
890 ;; avoids any field constraints.
891 (forward-line 0)
892 (looking-at idlwave-shell-prompt-pattern)))
893 ;; IDL ready for command
894 (if idlwave-shell-pending-commands
895 ;; execute command
896 (let* ((lcmd (car idlwave-shell-pending-commands))
897 (cmd (car lcmd))
898 (pcmd (nth 1 lcmd))
899 (hide (nth 2 lcmd)))
900 ;; If this is an executive command, reset the stack pointer
901 (if (eq (string-to-char cmd) ?.)
902 (setq idlwave-shell-calling-stack-index 0))
903 ;; Set post-command
904 (setq idlwave-shell-post-command-hook pcmd)
905 ;; Output hiding
906 ;;; Debug code
907 ;;; (setq idlwave-shell-hide-output nil)
908 (setq idlwave-shell-hide-output hide)
909 ;; Pop command
910 (setq idlwave-shell-pending-commands
911 (cdr idlwave-shell-pending-commands))
912 ;; Send command for execution
913 (set-marker comint-last-input-start (point))
914 (set-marker comint-last-input-end (point))
915 (comint-simple-send proc cmd)
916 (setq idlwave-shell-ready nil)))))))
918 (defun idlwave-shell-send-char (c &optional no-error)
919 "Send one character to the shell, without a newline."
920 (interactive "cChar to send to IDL: ")
921 (let ((errf (if (interactive-p) 'error 'message))
922 buf proc)
923 (if (or (not (setq buf (get-buffer (idlwave-shell-buffer))))
924 (not (setq proc (get-buffer-process buf))))
925 (funcall errf "Shell is not running"))
926 (if (equal c ?\C-g)
927 (funcall errf "Abort")
928 (comint-send-string proc (char-to-string c)))))
930 (defvar idlwave-shell-char-mode-active)
931 (defun idlwave-shell-input-mode-magic (string)
932 "Check STRING for magic words and toggle character input mode.
933 See also the variable `idlwave-shell-input-mode-spells'."
934 (cond
935 ((string-match (car idlwave-shell-input-mode-spells) string)
936 (call-interactively 'idlwave-shell-send-char))
937 ((and (boundp 'idlwave-shell-char-mode-active)
938 (string-match (nth 2 idlwave-shell-input-mode-spells) string))
939 (setq idlwave-shell-char-mode-active 'exit))
940 ((string-match (nth 1 idlwave-shell-input-mode-spells) string)
941 ;; Set a timer which will soon start the character loop
942 (if (fboundp 'start-itimer)
943 (start-itimer "IDLWAVE Char Mode" 'idlwave-shell-char-mode-loop 0.5
944 nil nil t 'no-error)
945 (run-at-time 0.5 nil 'idlwave-shell-char-mode-loop 'no-error)))))
947 (defvar keyboard-quit)
948 (defun idlwave-shell-char-mode-loop (&optional no-error)
949 "Enter a loop which accepts single characters and sends them to IDL.
950 Characters are sent one by one, without newlines. The loop is blocking
951 and intercepts all input events to Emacs. You can use this command
952 to interact with the IDL command GET_KBRD.
953 The loop can be aborted by typing `C-g'. The loop also exits automatically
954 when the IDL prompt gets displayed again after the current IDL command."
955 (interactive)
957 ;; First check if there is a shell waiting for input
958 (let ((idlwave-shell-char-mode-active t)
959 (errf (if no-error 'message 'error))
960 buf proc c)
961 (if (or (not (setq buf (get-buffer (idlwave-shell-buffer))))
962 (not (setq proc (get-buffer-process buf))))
963 (funcall errf "Shell is not running"))
964 (if idlwave-shell-ready
965 (funcall errf "No IDL program seems to be waiting for input"))
967 ;; OK, start the loop
968 (message "Character mode on: Sending single chars (`C-g' to exit)")
969 (message
970 (catch 'exit
971 (while t
972 ;; Wait for input
973 ;; FIXME: Is it too dangerous to inhibit quit here?
974 (let ((inhibit-quit t))
975 ;; We wait and check frequently if we should abort
976 (while (sit-for 0.3)
977 (and idlwave-shell-ready
978 (throw 'exit "Character mode off (prompt displayed)"))
979 (and (eq idlwave-shell-char-mode-active 'exit)
980 (throw 'exit "Character mode off (closing spell incantation)")))
981 ;; Interpret input as a character - ignore non-char input
982 (condition-case nil
983 (setq c (read-char))
984 (error (setq c nil)))
985 (cond
986 ((null c) ; Non-char event: ignore
987 (ding))
988 ((equal c ?\C-g) ; Abort the loop
989 (setq keyboard-quit nil)
990 (ding)
991 (throw 'exit "Character mode off (keyboard quit)"))
992 (t ; Send the character and continue the loop
993 (comint-send-string proc (char-to-string c))))
994 (and (eq idlwave-shell-char-mode-active 'exit)
995 (throw 'exit "Single char loop exited"))))))))
998 ;; There was a report that a newer version of comint.el changed the
999 ;; name of comint-filter to comint-output-filter. Unfortunately, we
1000 ;; have yet to upgrade.
1002 (defun idlwave-shell-comint-filter (process string) nil)
1003 (if (fboundp 'comint-output-filter)
1004 (fset 'idlwave-shell-comint-filter (symbol-function 'comint-output-filter))
1005 (fset 'idlwave-shell-comint-filter (symbol-function 'comint-filter)))
1007 (defun idlwave-shell-is-running ()
1008 "Return t if the shell process is running."
1009 (eq (process-status idlwave-shell-process-name) 'run))
1011 (defvar idlwave-shell-hidden-output-buffer " *idlwave-shell-hidden-output*"
1012 "Buffer containing hidden output from IDL commands.")
1014 (defun idlwave-shell-filter (proc string)
1015 "Replace Carriage returns in output. Watch for prompt.
1016 When the IDL prompt is received executes `idlwave-shell-post-command-hook'
1017 and then calls `idlwave-shell-send-command' for any pending commands."
1018 ;; We no longer do the cleanup here - this is done by the process sentinel
1019 (when (eq (process-status idlwave-shell-process-name) 'run)
1020 ;; OK, process is still running, so we can use it.
1021 (let ((data (match-data)))
1022 (unwind-protect
1023 (progn
1024 ;; May change the original match data.
1025 (let (p)
1026 (while (setq p (string-match "\C-M" string))
1027 (aset string p ? )))
1028 ;;; Test/Debug code
1029 ;; (save-excursion (set-buffer (get-buffer-create "*test*"))
1030 ;; (goto-char (point-max))
1031 ;; (insert "%%%" string))
1033 ;; Keep output
1035 ; Should not keep output because the concat is costly. If hidden put
1036 ; the output in a hide-buffer. Then when the output is needed in post
1037 ; processing can access either the hide buffer or the idlwave-shell
1038 ; buffer. Then watching for the prompt is easier. Furthermore, if it
1039 ; is hidden and there is no post command, could throw away output.
1040 ; (setq idlwave-shell-command-output
1041 ; (concat idlwave-shell-command-output string))
1042 ;; Insert the string. Do this before getting the
1043 ;; state.
1044 (if idlwave-shell-hide-output
1045 (save-excursion
1046 (set-buffer
1047 (get-buffer-create idlwave-shell-hidden-output-buffer))
1048 (goto-char (point-max))
1049 (insert string))
1050 (idlwave-shell-comint-filter proc string))
1051 ;; Watch for prompt - need to accumulate the current line
1052 ;; since it may not be sent all at once.
1053 (if (string-match "\n" string)
1054 (progn
1055 (if idlwave-shell-use-input-mode-magic
1056 (idlwave-shell-input-mode-magic
1057 (concat idlwave-shell-accumulation string)))
1058 (setq idlwave-shell-accumulation
1059 (substring string
1060 (progn (string-match "\\(.*\n\\)*" string)
1061 (match-end 0)))))
1062 (setq idlwave-shell-accumulation
1063 (concat idlwave-shell-accumulation string)))
1066 ;; Check for prompt in current line
1067 (if (setq idlwave-shell-ready
1068 (string-match idlwave-shell-prompt-pattern
1069 idlwave-shell-accumulation))
1070 (progn
1071 (if idlwave-shell-hide-output
1072 (save-excursion
1073 (set-buffer idlwave-shell-hidden-output-buffer)
1074 (goto-char (point-min))
1075 (re-search-forward idlwave-shell-prompt-pattern nil t)
1076 (setq idlwave-shell-command-output
1077 (buffer-substring (point-min) (point)))
1078 (delete-region (point-min) (point)))
1079 (setq idlwave-shell-command-output
1080 (save-excursion
1081 (set-buffer
1082 (process-buffer proc))
1083 (buffer-substring
1084 (progn
1085 (goto-char (process-mark proc))
1086 (beginning-of-line nil)
1087 (point))
1088 comint-last-input-end))))
1089 ;;; Test/Debug code
1090 ;; (save-excursion (set-buffer
1091 ;; (get-buffer-create "*idlwave-shell-output*"))
1092 ;; (goto-char (point-max))
1093 ;; (insert "%%%" string))
1094 ;; Scan for state and do post command - bracket them
1095 ;; with idlwave-shell-ready=nil since they
1096 ;; may call idlwave-shell-send-command.
1097 (let ((idlwave-shell-ready nil))
1098 (idlwave-shell-scan-for-state)
1099 ;; Unset idlwave-shell-ready to prevent sending
1100 ;; commands to IDL while running hook.
1101 (if (listp idlwave-shell-post-command-hook)
1102 (eval idlwave-shell-post-command-hook)
1103 (funcall idlwave-shell-post-command-hook))
1104 ;; Reset to default state for next command.
1105 ;; Also we do not want to find this prompt again.
1106 (setq idlwave-shell-accumulation nil
1107 idlwave-shell-command-output nil
1108 idlwave-shell-post-command-hook nil
1109 idlwave-shell-hide-output nil))
1110 ;; Done with post command. Do pending command if
1111 ;; any.
1112 (idlwave-shell-send-command))))
1113 (store-match-data data)))))
1115 (defun idlwave-shell-sentinel (process event)
1116 "The sentinel function for the IDLWAVE shell process."
1117 (let* ((buf (idlwave-shell-buffer))
1118 (win (get-buffer-window buf)))
1119 (when (get-buffer buf)
1120 (save-excursion
1121 (set-buffer (idlwave-shell-buffer))
1122 (goto-char (point-max))
1123 (insert (format "\n\n Process %s %s" process event))))
1124 (when (and (> (length (frame-list)) 1)
1125 (frame-live-p idlwave-shell-idl-wframe))
1126 (delete-frame idlwave-shell-idl-wframe)
1127 (setq idlwave-shell-idl-wframe nil
1128 idlwave-shell-display-wframe nil))
1129 (when (and (window-live-p win)
1130 (not (one-window-p)))
1131 (delete-window win))
1132 (idlwave-shell-cleanup)))
1134 (defun idlwave-shell-scan-for-state ()
1135 "Scan for state info.
1136 Looks for messages in output from last IDL command indicating where
1137 IDL has stopped. The types of messages we are interested in are
1138 execution halted, stepped, breakpoint, interrupted at and trace
1139 messages. We ignore error messages otherwise.
1140 For breakpoint messages process any attached count or command
1141 parameters.
1142 Update the windows if a message is found."
1143 (let (update)
1144 (cond
1145 ;; Make sure we have output
1146 ((not idlwave-shell-command-output))
1148 ;; Various types of HALT messages.
1149 ((string-match idlwave-shell-halt-messages-re
1150 idlwave-shell-command-output)
1151 ;; Grab the file and line state info.
1152 (setq idlwave-shell-calling-stack-index 0)
1153 (setq idlwave-shell-halt-frame
1154 (idlwave-shell-parse-line
1155 (substring idlwave-shell-command-output (match-end 0)))
1156 update t))
1158 ;; Handle breakpoints separately
1159 ((string-match idlwave-shell-break-message
1160 idlwave-shell-command-output)
1161 (setq idlwave-shell-calling-stack-index 0)
1162 (setq idlwave-shell-halt-frame
1163 (idlwave-shell-parse-line
1164 (substring idlwave-shell-command-output (match-end 0)))
1165 update t)
1166 ;; We used to to counting hits on breakpoints
1167 ;; this is no longer supported since IDL breakpoints
1168 ;; have learned counting.
1169 ;; Do breakpoint command processing
1170 (let ((bp (assoc
1171 (list
1172 (nth 0 idlwave-shell-halt-frame)
1173 (nth 1 idlwave-shell-halt-frame))
1174 idlwave-shell-bp-alist)))
1175 (if bp
1176 (let ((cmd (idlwave-shell-bp-get bp 'cmd)))
1177 (if cmd
1178 ;; Execute command
1179 (if (listp cmd)
1180 (eval cmd)
1181 (funcall cmd))))
1182 ;; A breakpoint that we did not know about - perhaps it was
1183 ;; set by the user or IDL isn't reporting breakpoints like
1184 ;; we expect. Lets update our list.
1185 (idlwave-shell-bp-query)))))
1187 ;; Handle compilation errors in addition to the above
1188 (if (and idlwave-shell-command-output
1189 (or (string-match
1190 idlwave-shell-syntax-error idlwave-shell-command-output)
1191 (string-match
1192 idlwave-shell-other-error idlwave-shell-command-output)))
1193 (progn
1194 (save-excursion
1195 (set-buffer
1196 (get-buffer-create idlwave-shell-error-buffer))
1197 (erase-buffer)
1198 (insert idlwave-shell-command-output)
1199 (goto-char (point-min))
1200 (setq idlwave-shell-error-last (point)))
1201 (idlwave-shell-goto-next-error)))
1203 ;; Do update
1204 (when update
1205 (idlwave-shell-display-line (idlwave-shell-pc-frame)))))
1208 (defvar idlwave-shell-error-buffer " *idlwave-shell-errors*"
1209 "Buffer containing syntax errors from IDL compilations.")
1212 ;; FIXME: the following two variables do not currently allow line breaks
1213 ;; in module and file names. I am not sure if it will be necessary to
1214 ;; change this. Currently it seems to work the way it is.
1215 (defvar idlwave-shell-syntax-error
1216 "^% Syntax error.\\s-*\n\\s-*At:\\s-*\\(.*\\),\\s-*Line\\s-*\\(.*\\)"
1217 "A regular expression to match an IDL syntax error.
1218 The first \(..\) pair should match the file name. The second pair
1219 should match the line number.")
1221 (defvar idlwave-shell-other-error
1222 "^% .*\n\\s-*At:\\s-*\\(.*\\),\\s-*Line\\s-*\\(.*\\)"
1223 "A regular expression to match any IDL error.
1224 The first \(..\) pair should match the file name. The second pair
1225 should match the line number.")
1227 (defvar idlwave-shell-file-line-message
1228 (concat
1229 "\\(" ; program name group (1)
1230 "\\<[a-zA-Z][a-zA-Z0-9_$:]*" ; start with a letter, followed by [..]
1231 "\\([ \t]*\n[ \t]*[a-zA-Z0-9_$:]+\\)*"; continuation lines program name (2)
1232 "\\)" ; end program name group (1)
1233 "[ \t\n]+" ; white space
1234 "\\(" ; line number group (3)
1235 "[0-9]+" ; the line number (the fix point)
1236 "\\([ \t]*\n[ \t]*[0-9]+\\)*" ; continuation lines number (4)
1237 "\\)" ; end line number group (3)
1238 "[ \t\n]+" ; white space
1239 "\\(" ; file name group (5)
1240 "[^ \t\n]+" ; file names can contain any non-white
1241 "\\([ \t]*\n[ \t]*[^ \t\n]+\\)*" ; continuation lines file name (6)
1242 "\\)" ; end line number group (5)
1244 "*A regular expression to parse out the file name and line number.
1245 The 1st group should match the subroutine name.
1246 The 3rd group is the line number.
1247 The 5th group is the file name.
1248 All parts may contain linebreaks surrounded by spaces. This is important
1249 in IDL5 which inserts random linebreaks in long module and file names.")
1251 (defun idlwave-shell-parse-line (string)
1252 "Parse IDL message for the subroutine, file name and line number.
1253 We need to work hard here to remove the stupid line breaks inserted by
1254 IDL5. These line breaks can be right in the middle of procedure
1255 or file names.
1256 It is very difficult to come up with a robust solution. This one seems
1257 to be pretty good though.
1259 Here is in what ways it improves over the previous solution:
1261 1. The procedure name can be split and will be restored.
1262 2. The number can be split. I have never seen this, but who knows.
1263 3. We do not require the `.pro' extension for files.
1265 This function can still break when the file name ends on a end line
1266 and the message line contains an additional line with garbage. Then
1267 the first part of that garbage will be added to the file name.
1268 However, the function checks the existence of the files with and
1269 without this last part - thus the function only breaks if file name
1270 plus garbage match an existing regular file. This is hopefully very
1271 unlikely."
1273 (let (number procedure file)
1274 (when (string-match idlwave-shell-file-line-message string)
1275 (setq procedure (match-string 1 string)
1276 number (match-string 3 string)
1277 file (match-string 5 string))
1279 ;; Repair the strings
1280 (setq procedure (idlwave-shell-repair-string procedure))
1281 (setq number (idlwave-shell-repair-string number))
1282 (setq file (idlwave-shell-repair-file-name file))
1284 ;; If we have a file, return the frame list
1285 (if file
1286 (list (idlwave-shell-file-name file)
1287 (string-to-int number)
1288 procedure)
1289 ;; No success finding a file
1290 nil))))
1292 (defun idlwave-shell-repair-string (string)
1293 "Repair a string by taking out all linebreaks. This is destructive!"
1294 (while (string-match "[ \t]*\n[ \t]*" string)
1295 (setq string (replace-match "" t t string)))
1296 string)
1298 (defun idlwave-shell-repair-file-name (file)
1299 "Repair a file name string by taking out all linebreaks.
1300 The last line of STRING may be garbage - we check which one makes a valid
1301 file name."
1302 (let ((file1 "") (file2 "") (start 0))
1303 ;; We scan no further than to the next "^%" line
1304 (if (string-match "^%" file)
1305 (setq file (substring file 0 (match-beginning 0))))
1306 ;; Take out the line breaks
1307 (while (string-match "[ \t]*\n[ \t]*" file start)
1308 (setq file1 (concat file1 (substring file start (match-beginning 0)))
1309 start (match-end 0)))
1310 (setq file2 (concat file1 (substring file start)))
1311 (cond
1312 ((file-regular-p file2) file2)
1313 ((file-regular-p file1) file1)
1314 ;; If we cannot veryfy the existence of the file, we return the shorter
1315 ;; name. The idea behind this is that this may be a relative file name
1316 ;; and our idea about the current working directory may be wrong.
1317 ;; If it is a relative file name, it hopefully is short.
1318 ((not (string= "" file1)) file1)
1319 ((not (string= "" file2)) file2)
1320 (t nil))))
1322 (defun idlwave-shell-cleanup ()
1323 "Do necessary cleanup for a terminated IDL process."
1324 (setq idlwave-shell-step-frame nil
1325 idlwave-shell-halt-frame nil
1326 idlwave-shell-pending-commands nil
1327 idlwave-shell-command-line-to-execute nil
1328 idlwave-shell-bp-alist nil
1329 idlwave-shell-calling-stack-index 0
1330 idlwave-idlwave_routine_info-compiled nil)
1331 (idlwave-shell-delete-temp-files)
1332 (idlwave-shell-display-line nil)
1333 (idlwave-shell-update-bp-overlays) ; kill old overlays
1334 (idlwave-shell-kill-buffer idlwave-shell-hidden-output-buffer)
1335 (idlwave-shell-kill-buffer idlwave-shell-bp-buffer)
1336 (idlwave-shell-kill-buffer idlwave-shell-error-buffer)
1337 ;; (idlwave-shell-kill-buffer (idlwave-shell-buffer))
1338 (and (get-buffer (idlwave-shell-buffer))
1339 (bury-buffer (get-buffer (idlwave-shell-buffer))))
1340 (run-hooks 'idlwave-shell-cleanup-hook))
1342 (defun idlwave-shell-kill-buffer (buf)
1343 "Kill buffer BUF if it exists."
1344 (if (setq buf (get-buffer buf))
1345 (kill-buffer buf)))
1347 (defun idlwave-shell-kill-shell-buffer-confirm ()
1348 (when (idlwave-shell-is-running)
1349 (ding)
1350 (unless (y-or-n-p "IDL shell is running. Are you sure you want to kill the buffer? ")
1351 (error "Abort"))
1352 (message "Killing buffer *idl* and the associated process")))
1354 (defun idlwave-shell-resync-dirs ()
1355 "Resync the buffer's idea of the current directory stack.
1356 This command queries IDL with the command bound to
1357 `idlwave-shell-dirstack-query' (default \"printd\"), reads the
1358 output for the new directory stack."
1359 (interactive)
1360 (idlwave-shell-send-command idlwave-shell-dirstack-query
1361 'idlwave-shell-filter-directory
1362 'hide))
1364 (defun idlwave-shell-retall (&optional arg)
1365 "Return from the entire calling stack."
1366 (interactive "P")
1367 (idlwave-shell-send-command "retall"))
1369 (defun idlwave-shell-closeall (&optional arg)
1370 "Close all open files."
1371 (interactive "P")
1372 (idlwave-shell-send-command "close,/all"))
1374 (defun idlwave-shell-quit (&optional arg)
1375 "Exit the idl process after confirmation.
1376 With prefix ARG, exit without confirmation."
1377 (interactive "P")
1378 (if (not (idlwave-shell-is-running))
1379 (error "Shell is not running")
1380 (if (or arg (y-or-n-p "Exit the IDLWAVE Shell? "))
1381 (condition-case nil
1382 (idlwave-shell-send-command "exit")
1383 (error nil)))))
1385 (defun idlwave-shell-reset (&optional hidden)
1386 "Reset IDL. Return to main level and destroy the leaftover variables.
1387 This issues the following commands:
1388 RETALL
1389 WIDGET_CONTROL,/RESET
1390 CLOSE, /ALL
1391 HEAP_GC, /VERBOSE"
1392 ;; OBJ_DESTROY, OBJ_VALID() FIXME: should this be added?
1393 (interactive "P")
1394 (message "Resetting IDL")
1395 (setq idlwave-shell-calling-stack-index 0)
1396 (idlwave-shell-send-command "retall" nil hidden)
1397 (idlwave-shell-send-command "widget_control,/reset" nil hidden)
1398 (idlwave-shell-send-command "close,/all" nil hidden)
1399 ;; (idlwave-shell-send-command "obj_destroy, obj_valid()" nil hidden)
1400 (idlwave-shell-send-command "heap_gc,/verbose" nil hidden)
1401 (idlwave-shell-display-line nil))
1403 (defun idlwave-shell-path-filter ()
1404 ;; Convert the output of the path query into a list of directories
1405 (let ((path-string idlwave-shell-command-output)
1406 (case-fold-search t)
1407 (start 0)
1408 dirs sysdir)
1409 (while (string-match "^PATH:[ \t]*\\(.*\\)\n" path-string start)
1410 (push (match-string 1 path-string) dirs)
1411 (setq start (match-end 0)))
1412 (setq dirs (mapcar 'file-name-as-directory dirs))
1413 (if (string-match "^SYSDIR:[ \t]*\\(.*\\)\n" path-string)
1414 (setq sysdir (file-name-as-directory
1415 (match-string 1 path-string))))
1416 (cons sysdir (nreverse dirs))))
1418 (defun idlwave-shell-routine-info-filter ()
1419 "Function which parses the special output from idlwave_routine_info.pro."
1420 (let ((text idlwave-shell-command-output)
1421 (start 0)
1422 sep sep-re file type spec specs name cs key keys class entry)
1423 ;; Initialize variables
1424 (setq idlwave-compiled-routines nil
1425 idlwave-unresolved-routines nil)
1426 ;; Cut out the correct part of the output.
1427 (if (string-match
1428 "^>>>BEGIN OF IDLWAVE ROUTINE INFO (\"\\(.+\\)\" IS THE SEPARATOR.*"
1429 text)
1430 (setq sep (match-string 1 text)
1431 sep-re (concat (regexp-quote sep) " *")
1432 text (substring text (match-end 0)))
1433 ;; Set dummy values and kill the text
1434 (setq sep "@" sep-re "@ *" text "")
1435 (message "Routine Info warning: No match for BEGIN line"))
1436 (if (string-match "^>>>END OF IDLWAVE ROUTINE INFO.*" text)
1437 (setq text (substring text 0 (match-beginning 0)))
1438 (message "Routine Info warning: No match for END line"))
1439 (if (string-match "\\S-" text)
1440 ;; Obviously, the pro worked. Make a note that we have it now.
1441 (setq idlwave-idlwave_routine_info-compiled t))
1442 ;; Match the output lines
1443 (while (string-match "^IDLWAVE-\\(PRO\\|FUN\\): \\(.*\\)" text start)
1444 (setq start (match-end 0))
1445 (setq type (match-string 1 text)
1446 spec (match-string 2 text)
1447 specs (idlwave-split-string spec sep-re)
1448 name (nth 0 specs)
1449 class (if (equal (nth 1 specs) "") nil (nth 1 specs))
1450 file (nth 2 specs)
1451 cs (nth 3 specs)
1452 key (nth 4 specs)
1453 keys (if (and (stringp key)
1454 (not (string-match "\\` *\\'" key)))
1455 (mapcar 'list
1456 (delete "" (idlwave-split-string key " +")))))
1457 (setq name (idlwave-sintern-routine-or-method name class t)
1458 class (idlwave-sintern-class class t)
1459 file (if (equal file "") nil file)
1460 keys (mapcar (lambda (x)
1461 (list (idlwave-sintern-keyword (car x) t))) keys))
1462 ;; Make sure we use the same string object for the same file
1463 (setq file (idlwave-sintern-file file t))
1464 ;; FIXME: What should I do with routines from the temp file???
1465 ;; Maybe just leave it in - there is a chance that the
1466 ;; routine is still in there.
1467 ;; (if (equal file idlwave-shell-temp-pro-file)
1468 ;; (setq file nil))
1470 ;; In the following ignore routines already defined in buffers,
1471 ;; assuming that if the buffer stuff differs, it is a "new"
1472 ;; version.
1473 ;; We could do the same for the library to avoid duplicates -
1474 ;; but I think frequently a user might have several versions of
1475 ;; the same function in different programs, and in this case the
1476 ;; compiled one will be the best guess of all version.
1477 ;; Therefore, we leave duplicates of library routines in.
1479 (cond ((string= name "$MAIN$")) ; ignore this one
1480 ((and (string= type "PRO")
1481 ;; FIXME: is it OK to make the buffer routines dominate?
1482 (or t (null file)
1483 (not (idlwave-rinfo-assq name 'pro class
1484 idlwave-buffer-routines)))
1485 ;; FIXME: is it OK to make the library routines dominate?
1486 ;;(not (idlwave-rinfo-assq name 'pro class
1487 ;; idlwave-library-routines))
1489 (setq entry (list name 'pro class (cons 'compiled file) cs keys))
1490 (if file
1491 (push entry idlwave-compiled-routines)
1492 (push entry idlwave-unresolved-routines)))
1494 ((and (string= type "FUN")
1495 ;; FIXME: is it OK to make the buffer routines dominate?
1496 (or t (not file)
1497 (not (idlwave-rinfo-assq name 'fun class
1498 idlwave-buffer-routines)))
1499 ;; FIXME: is it OK to make the library routines dominate?
1500 ;; (not (idlwave-rinfo-assq name 'fun class
1501 ;; idlwave-library-routines))
1503 (setq entry (list name 'fun class (cons 'compiled file) cs keys))
1504 (if file
1505 (push entry idlwave-compiled-routines)
1506 (push entry idlwave-unresolved-routines))))))
1507 ;; Reverse the definitions so that they are alphabetically sorted.
1508 (setq idlwave-compiled-routines (nreverse idlwave-compiled-routines)
1509 idlwave-unresolved-routines (nreverse idlwave-unresolved-routines)))
1511 (defun idlwave-shell-filter-directory ()
1512 "Get the current directory from `idlwave-shell-command-output'.
1513 Change the default directory for the process buffer to concur."
1514 (save-excursion
1515 (set-buffer (idlwave-shell-buffer))
1516 (if (string-match "Current Directory: *\\(\\S-*\\) *$"
1517 idlwave-shell-command-output)
1518 (let ((dir (substring idlwave-shell-command-output
1519 (match-beginning 1) (match-end 1))))
1520 (message "Setting Emacs wd to %s" dir)
1521 (setq idlwave-shell-default-directory dir)
1522 (setq default-directory (file-name-as-directory dir))))))
1524 (defun idlwave-shell-complete (&optional arg)
1525 "Do completion in the idlwave-shell buffer.
1526 Calls `idlwave-shell-complete-filename' after some executive commands or
1527 in strings. Otherwise, calls `idlwave-complete' to complete modules and
1528 keywords."
1529 ;;FIXME: batch files?
1530 (interactive "P")
1531 (let (cmd)
1532 (cond
1533 ((setq cmd (idlwave-shell-executive-command))
1534 ;; We are in a command line with an executive command
1535 (if (member (upcase cmd)
1536 '(".R" ".RU" ".RUN" ".RN" ".RNE" ".RNEW"
1537 ".COM" ".COMP" ".COMPI" ".COMPIL" ".COMPILE"))
1538 ;; This command expects file names
1539 (idlwave-shell-complete-filename)))
1540 ((and (idlwave-shell-filename-string)
1541 (save-excursion
1542 (beginning-of-line)
1543 (let ((case-fold-search t))
1544 (not (looking-at ".*obj_new"))))
1545 ;; In a string, could be a file name to here
1546 (idlwave-shell-complete-filename)))
1548 ;; Default completion of modules and keywords
1549 (idlwave-complete arg)))))
1551 (defun idlwave-shell-complete-filename (&optional arg)
1552 "Complete a file name at point if after a file name.
1553 We assume that we are after a file name when completing one of the
1554 args of an executive .run, .rnew or .compile. Also, in a string
1555 constant we complete file names. Otherwise return nil, so that
1556 other completion functions can do thier work."
1557 (let* ((comint-file-name-chars idlwave-shell-file-name-chars)
1558 (completion-ignore-case (default-value 'completion-ignore-case)))
1559 (comint-dynamic-complete-filename)))
1561 (defun idlwave-shell-executive-command ()
1562 "Return the name of the current executive command, if any."
1563 (save-excursion
1564 (idlwave-beginning-of-statement)
1565 (if (looking-at "[ \t]*\\([.][^ \t\n\r]*\\)")
1566 (match-string 1))))
1568 (defun idlwave-shell-filename-string ()
1569 "Return t if in a string and after what could be a file name."
1570 (let ((limit (save-excursion (beginning-of-line) (point))))
1571 (save-excursion
1572 ;; Skip backwards over file name chars
1573 (skip-chars-backward idlwave-shell-file-name-chars limit)
1574 ;; Check of the next char is a string delimiter
1575 (memq (preceding-char) '(?\' ?\")))))
1578 ;;; This section contains code for debugging IDL programs. --------------------
1581 (defun idlwave-shell-redisplay (&optional hide)
1582 "Tries to resync the display with where execution has stopped.
1583 Issues a \"help,/trace\" command followed by a call to
1584 `idlwave-shell-display-line'. Also updates the breakpoint
1585 overlays."
1586 (interactive)
1587 (setq idlwave-shell-calling-stack-index 0)
1588 (idlwave-shell-send-command
1589 "help,/trace"
1590 '(idlwave-shell-display-line
1591 (idlwave-shell-pc-frame))
1592 hide)
1593 (idlwave-shell-bp-query))
1595 (defun idlwave-shell-display-level-in-calling-stack (&optional hide)
1596 (idlwave-shell-send-command
1597 "help,/trace"
1598 `(progn
1599 ;; scanning for the state will reset the stack level - restore it
1600 (setq idlwave-shell-calling-stack-index
1601 ,idlwave-shell-calling-stack-index)
1602 ;; parse the stack and visit the selected frame
1603 (idlwave-shell-parse-stack-and-display))
1604 hide))
1606 (defun idlwave-shell-parse-stack-and-display ()
1607 (let* ((lines (delete "" (idlwave-split-string
1608 idlwave-shell-command-output "^%")))
1609 (stack (delq nil (mapcar 'idlwave-shell-parse-line lines)))
1610 (nmax (1- (length stack)))
1611 (nmin 0) message)
1612 (cond
1613 ((< nmax nmin)
1614 (setq idlwave-shell-calling-stack-index 0)
1615 (ding)
1616 (message "Problem with calling stack"))
1617 ((> idlwave-shell-calling-stack-index nmax)
1618 (ding)
1619 (setq idlwave-shell-calling-stack-index nmax
1620 message (format "%d is the highest calling stack level - can't go further up"
1621 (- nmax))))
1622 ((< idlwave-shell-calling-stack-index nmin)
1623 (ding)
1624 (setq idlwave-shell-calling-stack-index nmin
1625 message (format "%d is the current calling stack level - can't go further down"
1626 (- nmin)))))
1627 (setq idlwave-shell-calling-stack-routine
1628 (nth 2 (nth idlwave-shell-calling-stack-index stack)))
1629 (idlwave-shell-display-line
1630 (nth idlwave-shell-calling-stack-index stack))
1631 (message (or message
1632 (format "In routine %s (stack level %d)"
1633 idlwave-shell-calling-stack-routine
1634 (- idlwave-shell-calling-stack-index))))))
1636 (defun idlwave-shell-stack-up ()
1637 "Display the source code one step up the calling stack."
1638 (interactive)
1639 (incf idlwave-shell-calling-stack-index)
1640 (idlwave-shell-display-level-in-calling-stack 'hide))
1641 (defun idlwave-shell-stack-down ()
1642 "Display the source code one step down the calling stack."
1643 (interactive)
1644 (decf idlwave-shell-calling-stack-index)
1645 (idlwave-shell-display-level-in-calling-stack 'hide))
1647 (defun idlwave-shell-goto-frame (&optional frame)
1648 "Set buffer to FRAME with point at the frame line.
1649 If the optional argument FRAME is nil then idlwave-shell-pc-frame is
1650 used. Does nothing if the resulting frame is nil."
1651 (if frame ()
1652 (setq frame (idlwave-shell-pc-frame)))
1653 (cond
1654 (frame
1655 (set-buffer (idlwave-find-file-noselect (car frame) 'shell))
1656 (widen)
1657 (goto-line (nth 1 frame)))))
1659 (defun idlwave-shell-pc-frame ()
1660 "Returns the frame for IDL execution."
1661 (and idlwave-shell-halt-frame
1662 (list (nth 0 idlwave-shell-halt-frame)
1663 (nth 1 idlwave-shell-halt-frame)
1664 (nth 2 idlwave-shell-halt-frame))))
1666 (defun idlwave-shell-valid-frame (frame)
1667 "Check that frame is for an existing file."
1668 (file-readable-p (car frame)))
1670 (defun idlwave-shell-display-line (frame &optional col)
1671 "Display FRAME file in other window with overlay arrow.
1673 FRAME is a list of file name, line number, and subroutine name.
1674 If FRAME is nil then remove overlay."
1675 (if (not frame)
1676 ;; Remove stop-line overlay from old position
1677 (progn
1678 (setq overlay-arrow-string nil)
1679 (setq idlwave-shell-mode-line-info nil)
1680 (setq idlwave-shell-is-stopped nil)
1681 (if idlwave-shell-stop-line-overlay
1682 (delete-overlay idlwave-shell-stop-line-overlay)))
1683 (if (not (idlwave-shell-valid-frame frame))
1684 ;; FIXME: errors are dangerous in shell filters. But I think I
1685 ;; have never encountered this one.
1686 (error (concat "Invalid frame - unable to access file: " (car frame)))
1688 ;;; buffer : the buffer to display a line in.
1689 ;;; select-shell: current buffer is the shell.
1690 ;;;
1691 (setq idlwave-shell-mode-line-info
1692 (if (nth 2 frame)
1693 (format "[%d:%s]"
1694 (- idlwave-shell-calling-stack-index)
1695 (nth 2 frame))))
1696 (let* ((buffer (idlwave-find-file-noselect (car frame) 'shell))
1697 (select-shell (equal (buffer-name) (idlwave-shell-buffer)))
1698 window pos)
1700 ;; First make sure the shell window is visible
1701 (idlwave-display-buffer (idlwave-shell-buffer)
1702 nil (idlwave-shell-shell-frame))
1704 ;; Now display the buffer and remember which window it is.
1705 (setq window (idlwave-display-buffer buffer
1706 nil (idlwave-shell-source-frame)))
1708 ;; Enter the buffer and mark the line
1709 (save-excursion
1710 (set-buffer buffer)
1711 (save-restriction
1712 (widen)
1713 (goto-line (nth 1 frame))
1714 (setq pos (point))
1715 (setq idlwave-shell-is-stopped t)
1716 (if idlwave-shell-stop-line-overlay
1717 ;; Move overlay
1718 (move-overlay idlwave-shell-stop-line-overlay
1719 (point) (save-excursion (end-of-line) (point))
1720 (current-buffer))
1721 ;; Use the arrow instead, but only if marking is wanted.
1722 (if idlwave-shell-mark-stop-line
1723 (setq overlay-arrow-string idlwave-shell-overlay-arrow))
1724 (or overlay-arrow-position ; create the marker if necessary
1725 (setq overlay-arrow-position (make-marker)))
1726 (set-marker overlay-arrow-position (point) buffer)))
1728 ;; If the point is outside the restriction, widen the buffer.
1729 (if (or (< pos (point-min)) (> pos (point-max)))
1730 (progn
1731 (widen)
1732 (goto-char pos)))
1734 ;; If we have the column of the error, move the cursor there.
1735 (if col (move-to-column col))
1736 (setq pos (point)))
1738 ;; Make sure pos is really displayed in the window.
1739 (set-window-point window pos)
1741 ;; FIXME: the following frame redraw was taken out because it
1742 ;; flashes. I think it is not needed. The code is left here in
1743 ;; case we have to put it back in.
1744 ;; (redraw-frame (window-frame window))
1746 ;; If we came from the shell, go back there. Otherwise select
1747 ;; the window where the error is displayed.
1748 (if (and (equal (buffer-name) (idlwave-shell-buffer))
1749 (not select-shell))
1750 (select-window window))))))
1753 (defun idlwave-shell-step (arg)
1754 "Step one source line. If given prefix argument ARG, step ARG source lines."
1755 (interactive "p")
1756 (or (not arg) (< arg 1)
1757 (setq arg 1))
1758 (idlwave-shell-send-command
1759 (concat ".s " (if (integerp arg) (int-to-string arg) arg))))
1761 (defun idlwave-shell-stepover (arg)
1762 "Stepover one source line.
1763 If given prefix argument ARG, step ARG source lines.
1764 Uses IDL's stepover executive command which does not enter called functions."
1765 (interactive "p")
1766 (or (not arg) (< arg 1)
1767 (setq arg 1))
1768 (idlwave-shell-send-command
1769 (concat ".so " (if (integerp arg) (int-to-string arg) arg))))
1771 (defun idlwave-shell-break-here (&optional count cmd)
1772 "Set breakpoint at current line.
1774 If Count is nil then an ordinary breakpoint is set. We treat a count
1775 of 1 as a temporary breakpoint using the ONCE keyword. Counts greater
1776 than 1 use the IDL AFTER=count keyword to break only after reaching
1777 the statement count times.
1779 Optional argument CMD is a list or function to evaluate upon reaching
1780 the breakpoint."
1782 (interactive "P")
1783 (if (listp count)
1784 (setq count nil))
1785 (idlwave-shell-set-bp
1786 ;; Create breakpoint
1787 (idlwave-shell-bp (idlwave-shell-current-frame)
1788 (list count cmd)
1789 (idlwave-shell-current-module))))
1791 (defun idlwave-shell-set-bp-check (bp)
1792 "Check for failure to set breakpoint.
1793 This is run on `idlwave-shell-post-command-hook'.
1794 Offers to recompile the procedure if we failed. This usually fixes
1795 the problem with not being able to set the breakpoint."
1796 ;; Scan for message
1797 (if (and idlwave-shell-command-output
1798 (string-match "% BREAKPOINT: *Unable to find code"
1799 idlwave-shell-command-output))
1800 ;; Offer to recompile
1801 (progn
1802 (if (progn
1803 (beep)
1804 (y-or-n-p
1805 (concat "Okay to recompile file "
1806 (idlwave-shell-bp-get bp 'file) " ")))
1807 ;; Recompile
1808 (progn
1809 ;; Clean up before retrying
1810 (idlwave-shell-command-failure)
1811 (idlwave-shell-send-command
1812 (concat ".run " (idlwave-shell-bp-get bp 'file)) nil nil)
1813 ;; Try setting breakpoint again
1814 (idlwave-shell-set-bp bp))
1815 (beep)
1816 (message "Unable to set breakpoint.")
1817 (idlwave-shell-command-failure)
1819 ;; return non-nil if no error found
1820 nil)
1821 'okay))
1823 (defun idlwave-shell-command-failure ()
1824 "Do any necessary clean up when an IDL command fails.
1825 Call this from a function attached to `idlwave-shell-post-command-hook'
1826 that detects the failure of a command.
1827 For example, this is called from `idlwave-shell-set-bp-check' when a
1828 breakpoint can not be set."
1829 ;; Clear pending commands
1830 (setq idlwave-shell-pending-commands nil))
1832 (defun idlwave-shell-cont ()
1833 "Continue executing."
1834 (interactive)
1835 (idlwave-shell-send-command ".c" '(idlwave-shell-redisplay 'hide)))
1837 (defun idlwave-shell-go ()
1838 "Run .GO. This starts the main program of the last compiled file."
1839 (interactive)
1840 (idlwave-shell-send-command ".go" '(idlwave-shell-redisplay 'hide)))
1842 (defun idlwave-shell-return ()
1843 "Run .RETURN (continue to next return, but stay in subprogram)."
1844 (interactive)
1845 (idlwave-shell-send-command ".return" '(idlwave-shell-redisplay 'hide)))
1847 (defun idlwave-shell-skip ()
1848 "Run .SKIP (skip one line, then step)."
1849 (interactive)
1850 (idlwave-shell-send-command ".skip" '(idlwave-shell-redisplay 'hide)))
1852 (defun idlwave-shell-clear-bp (bp)
1853 "Clear breakpoint BP.
1854 Clears in IDL and in `idlwave-shell-bp-alist'."
1855 (let ((index (idlwave-shell-bp-get bp)))
1856 (if index
1857 (progn
1858 (idlwave-shell-send-command
1859 (concat "breakpoint,/clear,"
1860 (if (integerp index) (int-to-string index) index)))
1861 (idlwave-shell-bp-query)))))
1863 (defun idlwave-shell-current-frame ()
1864 "Return a list containing the current file name and line point is in.
1865 If in the IDL shell buffer, returns `idlwave-shell-pc-frame'."
1866 (if (eq (current-buffer) (get-buffer (idlwave-shell-buffer)))
1867 ;; In IDL shell
1868 (idlwave-shell-pc-frame)
1869 ;; In source
1870 (list (idlwave-shell-file-name (buffer-file-name))
1871 (save-restriction
1872 (widen)
1873 (save-excursion
1874 (beginning-of-line)
1875 (1+ (count-lines 1 (point))))))))
1877 (defun idlwave-shell-current-module ()
1878 "Return the name of the module for the current file.
1879 Returns nil if unable to obtain a module name."
1880 (if (eq (current-buffer) (get-buffer (idlwave-shell-buffer)))
1881 ;; In IDL shell
1882 (nth 2 idlwave-shell-halt-frame)
1883 ;; In pro file
1884 (save-restriction
1885 (widen)
1886 (save-excursion
1887 (if (idlwave-prev-index-position)
1888 (upcase (idlwave-unit-name)))))))
1890 (defun idlwave-shell-clear-current-bp ()
1891 "Remove breakpoint at current line.
1892 This command can be called from the shell buffer if IDL is currently stopped
1893 at a breakpoint."
1894 (interactive)
1895 (let ((bp (idlwave-shell-find-bp (idlwave-shell-current-frame))))
1896 (if bp (idlwave-shell-clear-bp bp)
1897 ;; Try moving to beginning of statement
1898 (save-excursion
1899 (idlwave-shell-goto-frame)
1900 (idlwave-beginning-of-statement)
1901 (setq bp (idlwave-shell-find-bp (idlwave-shell-current-frame)))
1902 (if bp (idlwave-shell-clear-bp bp)
1903 (beep)
1904 (message "Cannot identify breakpoint for this line"))))))
1906 (defun idlwave-shell-to-here ()
1907 "Set a breakpoint with count 1 then continue."
1908 (interactive)
1909 (idlwave-shell-break-here 1)
1910 (idlwave-shell-cont))
1912 (defun idlwave-shell-break-in (&optional module)
1913 "Look for a module name near point and set a break point for it.
1914 The command looks for an identifier near point and sets a breakpoint
1915 for the first line of the corresponding module."
1916 (interactive)
1917 ;; get the identifier
1918 (let (module)
1919 (save-excursion
1920 (skip-chars-backward "a-zA-Z0-9_$")
1921 (if (looking-at idlwave-identifier)
1922 (setq module (match-string 0))
1923 (error "No identifier at point")))
1924 (idlwave-shell-send-command
1925 idlwave-shell-sources-query
1926 `(progn
1927 (idlwave-shell-sources-filter)
1928 (idlwave-shell-set-bp-in-module ,module))
1929 'hide)))
1931 (defun idlwave-shell-set-bp-in-module (module)
1932 "Set breakpoint in module. Assumes that `idlwave-shell-sources-alist'
1933 contains an entry for that module."
1934 (let ((source-file (car-safe
1935 (cdr-safe
1936 (assoc (upcase module)
1937 idlwave-shell-sources-alist))))
1938 buf)
1939 (if (or (not source-file)
1940 (not (file-regular-p source-file))
1941 (not (setq buf
1942 (or (idlwave-get-buffer-visiting source-file)
1943 (find-file-noselect source-file)))))
1944 (progn
1945 (message "The source file for module %s is probably not compiled"
1946 module)
1947 (beep))
1948 (save-excursion
1949 (set-buffer buf)
1950 (save-excursion
1951 (goto-char (point-min))
1952 (let ((case-fold-search t))
1953 (if (re-search-forward
1954 (concat "^[ \t]*\\(pro\\|function\\)[ \t]+"
1955 (downcase module)
1956 "[ \t\n,]") nil t)
1957 (progn
1958 (goto-char (match-beginning 1))
1959 (message "Setting breakpoint for module %s" module)
1960 (idlwave-shell-break-here))
1961 (message "Cannot find module %s in file %s" module source-file)
1962 (beep))))))))
1964 (defun idlwave-shell-up ()
1965 "Run to end of current block.
1966 Sets a breakpoint with count 1 at end of block, then continues."
1967 (interactive)
1968 (if (idlwave-shell-pc-frame)
1969 (save-excursion
1970 (idlwave-shell-goto-frame)
1971 ;; find end of subprogram
1972 (let ((eos (save-excursion
1973 (idlwave-beginning-of-subprogram)
1974 (idlwave-forward-block)
1975 (point))))
1976 (idlwave-backward-up-block -1)
1977 ;; move beyond end block line - IDL will not break there.
1978 ;; That is, you can put a breakpoint there but when IDL does
1979 ;; break it will report that it is at the next line.
1980 (idlwave-next-statement)
1981 (idlwave-end-of-statement)
1982 ;; Make sure we are not beyond subprogram
1983 (if (< (point) eos)
1984 ;; okay
1986 ;; Move back inside subprogram
1987 (goto-char eos)
1988 (idlwave-previous-statement))
1989 (idlwave-shell-to-here)))))
1991 (defun idlwave-shell-out ()
1992 "Attempt to run until this procedure exits.
1993 Runs to the last statement and then steps 1 statement. Use the .out command."
1994 (interactive)
1995 (idlwave-shell-send-command (concat ".o")))
1997 (defun idlwave-shell-help-expression (arg)
1998 "Print help on current expression. See `idlwave-shell-print'."
1999 (interactive "P")
2000 (idlwave-shell-print arg 'help))
2002 (defun idlwave-shell-mouse-print (event)
2003 "Call `idlwave-shell-print' at the mouse position."
2004 (interactive "e")
2005 (mouse-set-point event)
2006 (idlwave-shell-print nil nil 'mouse))
2008 (defun idlwave-shell-mouse-help (event)
2009 "Call `idlwave-shell-print' at the mouse position."
2010 (interactive "e")
2011 (mouse-set-point event)
2012 (idlwave-shell-print nil 'help 'mouse))
2014 (defun idlwave-shell-print (arg &optional help mouse)
2015 "Print current expression. With HELP, show help on expression.
2016 An expression is an identifier plus 1 pair of matched parentheses
2017 directly following the identifier - an array or function
2018 call. Alternatively, an expression is the contents of any matched
2019 parentheses when the open parentheses is not directly preceded by an
2020 identifier. If point is at the beginning or within an expression
2021 return the inner-most containing expression, otherwise, return the
2022 preceding expression.
2024 With prefix arg ARG, or when called from the shell buffer, prompt
2025 for an expression."
2026 (interactive "P")
2027 (save-excursion
2028 (let (expr beg end cmd)
2029 (if (and (not mouse)
2030 (or arg (eq major-mode 'idlwave-shell-mode)))
2031 (setq expr (read-string "Expression: "))
2032 ;; Move to beginning of current or previous expression
2033 (if (looking-at "\\<\\|(")
2034 ;; At beginning of expression, don't move backwards unless
2035 ;; this is at the end of an indentifier.
2036 (if (looking-at "\\>")
2037 (backward-sexp))
2038 (backward-sexp))
2039 (if (looking-at "\\>")
2040 ;; Move to beginning of identifier - must be an array or
2041 ;; function expression.
2042 (backward-sexp))
2043 ;; Move to end of expression
2044 (setq beg (point))
2045 (forward-sexp)
2046 (while (looking-at "\\>[[(]\\|\\.")
2047 ;; an array
2048 (forward-sexp))
2049 (setq end (point))
2050 (setq expr (buffer-substring beg end)))
2051 (when (and beg end idlwave-shell-expression-overlay)
2052 (move-overlay idlwave-shell-expression-overlay beg end
2053 (current-buffer))
2054 (add-hook 'pre-command-hook 'idlwave-shell-delete-expression-overlay))
2055 (if (and (integerp idlwave-shell-calling-stack-index)
2056 (> idlwave-shell-calling-stack-index 0))
2057 (setq cmd (idlwave-retrieve-expression-from-level
2058 expr
2059 idlwave-shell-calling-stack-index
2060 idlwave-shell-calling-stack-routine
2061 help))
2062 (setq cmd (concat (if help "help," "print,") expr)))
2063 (if idlwave-shell-print-expression-function
2064 (idlwave-shell-send-command
2066 (list idlwave-shell-print-expression-function expr)
2067 'hide)
2068 (idlwave-shell-recenter-shell-window)
2069 (idlwave-shell-send-command cmd)))))
2071 (defun idlwave-retrieve-expression-from-level (expr level routine help)
2072 "Return IDL command to print the expression EXPR from stack level LEVEL.
2074 It does not seem possible to evaluate an expression on a differnt
2075 level than the current. Therefore, this function retrieves *copies* of
2076 the variables involved in the expression from the desired level in the
2077 calling stack. The copies are given some unlikely names on the
2078 *current* level, and the expression is then evaluated on the *current*
2079 level.
2081 Since this function depends upon the undocumented IDL routine routine_names,
2082 there is no guarantie that this will work with future versions of IDL."
2083 (let ((prefix "___") ;; No real variables should starts with this.
2084 (fetch (- 0 level))
2085 (start 0)
2086 var tvar fetch-vars pre post)
2088 ;; FIXME: In the following we try to find the variables in expression
2089 ;; This is quite empirical - I don't know in what situations this will
2090 ;; break. We will look for identifiers and exclude cases where we
2091 ;; know it is not a variable. To distinguish array references from
2092 ;; function calls, we require that arrays use [] instead of ()
2094 (while (string-match
2095 "\\(\\`\\|[^a-zA-Z0-9$_]\\)\\([a-zA-Z][a-zA-Z0-9$_]*\\)\\([^a-zA-Z0-9$_]\\|\\'\\)" expr start)
2096 (setq var (match-string 2 expr)
2097 tvar (concat prefix var)
2098 start (match-beginning 2)
2099 pre (substring expr 0 (match-beginning 2))
2100 post (substring expr (match-end 2)))
2101 (cond
2102 ;; Exclude identifiers which are not variables
2103 ((string-match ",[ \t]*/\\'" pre)) ;; a `/' KEYWORD
2104 ((and (string-match "[,(][ \t]*\\'" pre)
2105 (string-match "\\`[ \t]*=" post))) ;; a `=' KEYWORD
2106 ((string-match "\\`(" post)) ;; a function
2107 ((string-match "->[ \t]*\\'" pre)) ;; a method
2108 ((string-match "\\.\\'" pre)) ;; structure member
2109 (t ;; seems to be a variable - arrange to get it and replace
2110 ;; its name in the expression with the temproary name.
2111 (push (cons var tvar) fetch-vars)
2112 (setq expr (concat pre tvar post)))))
2113 ;; Make a command line that first copies the relevant variables
2114 ;; and then prints the expression.
2115 (concat
2116 (mapconcat
2117 (lambda (x)
2118 (format "%s = routine_names('%s',fetch=%d)" (cdr x) (car x) fetch))
2119 (nreverse fetch-vars)
2120 " & ")
2121 (if idlwave-shell-print-expression-function " & " "\n")
2122 (if help "help, " "print, ")
2123 expr
2124 (format " ; [-%d:%s]" level routine))))
2126 (defun idlwave-shell-delete-expression-overlay ()
2127 (condition-case nil
2128 (if idlwave-shell-expression-overlay
2129 (delete-overlay idlwave-shell-expression-overlay))
2130 (error nil))
2131 (remove-hook 'pre-command-hook 'idlwave-shell-delete-expression-overlay))
2133 (defvar idlwave-shell-bp-alist nil
2134 "Alist of breakpoints.
2135 A breakpoint is a cons cell \(\(file line\) . \(\(index module\) data\)\)
2137 The car is the frame for the breakpoint:
2138 file - full path file name.
2139 line - line number of breakpoint - integer.
2141 The first element of the cdr is a list of internal IDL data:
2142 index - the index number of the breakpoint internal to IDL.
2143 module - the module for breakpoint internal to IDL.
2145 Remaining elements of the cdr:
2146 data - Data associated with the breakpoint by idlwave-shell currently
2147 contains two items:
2149 count - number of times to execute breakpoint. When count reaches 0
2150 the breakpoint is cleared and removed from the alist.
2151 command - command to execute when breakpoint is reached, either a
2152 lisp function to be called with `funcall' with no arguments or a
2153 list to be evaluated with `eval'.")
2155 (defun idlwave-shell-run-region (beg end &optional n)
2156 "Compile and run the region using the IDL process.
2157 Copies the region to a temporary file `idlwave-shell-temp-pro-file'
2158 and issues the IDL .run command for the file. Because the
2159 region is compiled and run as a main program there is no
2160 problem with begin-end blocks extending over multiple
2161 lines - which would be a problem if `idlwave-shell-evaluate-region'
2162 was used. An END statement is appended to the region if necessary.
2164 If there is a prefix argument, display IDL process."
2165 (interactive "r\nP")
2166 (let ((oldbuf (current-buffer)))
2167 (save-excursion
2168 (set-buffer (idlwave-find-file-noselect
2169 idlwave-shell-temp-pro-file 'tmp))
2170 (erase-buffer)
2171 (insert-buffer-substring oldbuf beg end)
2172 (if (not (save-excursion
2173 (idlwave-previous-statement)
2174 (idlwave-look-at "\\<end\\>")))
2175 (insert "\nend\n"))
2176 (save-buffer 0)))
2177 (idlwave-shell-send-command (concat ".run " idlwave-shell-temp-pro-file))
2178 (if n
2179 (idlwave-display-buffer (idlwave-shell-buffer)
2180 nil (idlwave-shell-shell-frame))))
2182 (defun idlwave-shell-evaluate-region (beg end &optional n)
2183 "Send region to the IDL process.
2184 If there is a prefix argument, display IDL process.
2185 Does not work for a region with multiline blocks - use
2186 `idlwave-shell-run-region' for this."
2187 (interactive "r\nP")
2188 (idlwave-shell-send-command (buffer-substring beg end))
2189 (if n
2190 (idlwave-display-buffer (idlwave-shell-buffer)
2191 nil (idlwave-shell-shell-frame))))
2193 (defun idlwave-shell-delete-temp-files ()
2194 "Delete the temporary files and kill associated buffers."
2195 (if (stringp idlwave-shell-temp-pro-file)
2196 (condition-case nil
2197 (let ((buf (idlwave-get-buffer-visiting
2198 idlwave-shell-temp-pro-file)))
2199 (if (buffer-live-p buf)
2200 (kill-buffer buf))
2201 (delete-file idlwave-shell-temp-pro-file))
2202 (error nil)))
2203 (if (stringp idlwave-shell-temp-rinfo-save-file)
2204 (condition-case nil
2205 (delete-file idlwave-shell-temp-rinfo-save-file)
2206 (error nil))))
2208 (defun idlwave-display-buffer (buf not-this-window-p &optional frame)
2209 (if (or (< emacs-major-version 20)
2210 (and (= emacs-major-version 20)
2211 (< emacs-minor-version 3)))
2212 ;; Only two args.
2213 (display-buffer buf not-this-window-p)
2214 ;; Three ares possible.
2215 (display-buffer buf not-this-window-p frame)))
2217 (defvar idlwave-shell-bp-buffer " *idlwave-shell-bp*"
2218 "Scratch buffer for parsing IDL breakpoint lists and other stuff.")
2220 (defun idlwave-shell-bp-query ()
2221 "Reconcile idlwave-shell's breakpoint list with IDL's.
2222 Queries IDL using the string in `idlwave-shell-bp-query'."
2223 (interactive)
2224 (idlwave-shell-send-command idlwave-shell-bp-query
2225 'idlwave-shell-filter-bp
2226 'hide))
2228 (defun idlwave-shell-bp-get (bp &optional item)
2229 "Get a value for a breakpoint.
2230 BP has the form of elements in idlwave-shell-bp-alist.
2231 Optional second arg ITEM is the particular value to retrieve.
2232 ITEM can be 'file, 'line, 'index, 'module, 'count, 'cmd, or 'data.
2233 'data returns a list of 'count and 'cmd.
2234 Defaults to 'index."
2235 (cond
2236 ;; Frame
2237 ((eq item 'line) (nth 1 (car bp)))
2238 ((eq item 'file) (nth 0 (car bp)))
2239 ;; idlwave-shell breakpoint data
2240 ((eq item 'data) (cdr (cdr bp)))
2241 ((eq item 'count) (nth 0 (cdr (cdr bp))))
2242 ((eq item 'cmd) (nth 1 (cdr (cdr bp))))
2243 ;; IDL breakpoint info
2244 ((eq item 'module) (nth 1 (car (cdr bp))))
2245 ;; index - default
2246 (t (nth 0 (car (cdr bp))))))
2248 (defun idlwave-shell-filter-bp ()
2249 "Get the breakpoints from `idlwave-shell-command-output'.
2250 Create `idlwave-shell-bp-alist' updating breakpoint count and command data
2251 from previous breakpoint list."
2252 (save-excursion
2253 (set-buffer (get-buffer-create idlwave-shell-bp-buffer))
2254 (erase-buffer)
2255 (insert idlwave-shell-command-output)
2256 (goto-char (point-min))
2257 (let ((old-bp-alist idlwave-shell-bp-alist)
2258 file line index module)
2259 (setq idlwave-shell-bp-alist (list nil))
2260 (when (re-search-forward "^\\s-*Index.*\n\\s-*-" nil t)
2261 ;; There seems to be a breakpoint listing here.
2262 ;; Parse breakpoint lines.
2263 ;; Breakpoints have the form:
2264 ;; Index Module Line File
2265 ;; All seperated by whitespace.
2266 ;; Module may be missing if the file is not compiled.
2268 (while (re-search-forward
2269 "^[ \t]*\\([0-9]+\\)[ \t]+\\(\\S-+\\)?[ \t]+\\([0-9]+\\)[ \t]+\\(\\S-+\\)" nil t)
2270 (setq index (match-string 1)
2271 module (match-string 2)
2272 line (string-to-int (match-string 3))
2273 file (idlwave-shell-file-name (match-string 4)))
2274 ;; Add the breakpoint info to the list
2275 (nconc idlwave-shell-bp-alist
2276 (list (cons (list file line)
2277 (list
2278 (list index module)
2279 ;; idlwave-shell data: count, command
2280 nil nil))))))
2281 (setq idlwave-shell-bp-alist (cdr idlwave-shell-bp-alist))
2282 ;; Update count, commands of breakpoints
2283 (mapcar 'idlwave-shell-update-bp old-bp-alist)))
2284 ;; Update the breakpoint overlays
2285 (idlwave-shell-update-bp-overlays)
2286 ;; Return the new list
2287 idlwave-shell-bp-alist)
2289 (defun idlwave-shell-update-bp (bp)
2290 "Update BP data in breakpoint list.
2291 If BP frame is in `idlwave-shell-bp-alist' updates the breakpoint data."
2292 (let ((match (assoc (car bp) idlwave-shell-bp-alist)))
2293 (if match (setcdr (cdr match) (cdr (cdr bp))))))
2295 (defun idlwave-shell-set-bp-data (bp data)
2296 "Set the data of BP to DATA."
2297 (setcdr (cdr bp) data))
2299 (defun idlwave-shell-bp (frame &optional data module)
2300 "Create a breakpoint structure containing FRAME and DATA. Second
2301 and third args, DATA and MODULE, are optional. Returns a breakpoint
2302 of the format used in `idlwave-shell-bp-alist'. Can be used in commands
2303 attempting match a breakpoint in `idlwave-shell-bp-alist'."
2304 (cons frame (cons (list nil module) data)))
2306 (defvar idlwave-shell-old-bp nil
2307 "List of breakpoints previous to setting a new breakpoint.")
2309 (defun idlwave-shell-sources-bp (bp)
2310 "Check `idlwave-shell-sources-alist' for source of breakpoint using BP.
2311 If an equivalency is found, return the IDL internal source name.
2312 Otherwise return the filename in bp."
2313 (let*
2314 ((bp-file (idlwave-shell-bp-get bp 'file))
2315 (bp-module (idlwave-shell-bp-get bp 'module))
2316 (internal-file-list (cdr (assoc bp-module idlwave-shell-sources-alist))))
2317 (if (and internal-file-list
2318 (equal bp-file (nth 0 internal-file-list)))
2319 (nth 1 internal-file-list)
2320 bp-file)))
2322 (defun idlwave-shell-set-bp (bp)
2323 "Try to set a breakpoint BP.
2325 The breakpoint will be placed at the beginning of the statement on the
2326 line specified by BP or at the next IDL statement if that line is not
2327 a statement.
2328 Determines IDL's internal representation for the breakpoint which may
2329 have occured at a different line then used with the breakpoint
2330 command."
2332 ;; Get and save the old breakpoints
2333 (idlwave-shell-send-command
2334 idlwave-shell-bp-query
2335 '(progn
2336 (idlwave-shell-filter-bp)
2337 (setq idlwave-shell-old-bp idlwave-shell-bp-alist))
2338 'hide)
2339 ;; Get sources for IDL compiled procedures followed by setting
2340 ;; breakpoint.
2341 (idlwave-shell-send-command
2342 idlwave-shell-sources-query
2343 (` (progn
2344 (idlwave-shell-sources-filter)
2345 (idlwave-shell-set-bp2 (quote (, bp)))))
2346 'hide))
2348 (defun idlwave-shell-set-bp2 (bp)
2349 "Use results of breakpoint and sources query to set bp.
2350 Use the count argument with IDLs breakpoint command.
2351 We treat a count of 1 as a temporary breakpoint.
2352 Counts greater than 1 use the IDL AFTER=count keyword to break
2353 only after reaching the statement count times."
2354 (let*
2355 ((arg (idlwave-shell-bp-get bp 'count))
2356 (key (cond
2357 ((not (and arg (numberp arg))) "")
2358 ((= arg 1)
2359 ",/once")
2360 ((> arg 1)
2361 (format ",after=%d" arg))))
2362 (line (idlwave-shell-bp-get bp 'line)))
2363 (idlwave-shell-send-command
2364 (concat "breakpoint,'"
2365 (idlwave-shell-sources-bp bp) "',"
2366 (if (integerp line) (setq line (int-to-string line)))
2367 key)
2368 ;; Check for failure and look for breakpoint in IDL's list
2369 (` (progn
2370 (if (idlwave-shell-set-bp-check (quote (, bp)))
2371 (idlwave-shell-set-bp3 (quote (, bp)))))
2373 ;; do not hide output
2375 'preempt)))
2377 (defun idlwave-shell-set-bp3 (bp)
2378 "Find the breakpoint in IDL's internal list of breakpoints."
2379 (idlwave-shell-send-command idlwave-shell-bp-query
2380 (` (progn
2381 (idlwave-shell-filter-bp)
2382 (idlwave-shell-new-bp (quote (, bp)))))
2383 'hide
2384 'preempt))
2386 (defun idlwave-shell-find-bp (frame)
2387 "Return breakpoint from `idlwave-shell-bp-alist' for frame.
2388 Returns nil if frame not found."
2389 (assoc frame idlwave-shell-bp-alist))
2391 (defun idlwave-shell-new-bp (bp)
2392 "Find the new breakpoint in IDL's list and update with DATA.
2393 The actual line number for a breakpoint in IDL may be different than
2394 the line number used with the IDL breakpoint command.
2395 Looks for a new breakpoint index number in the list. This is
2396 considered the new breakpoint if the file name of frame matches."
2397 (let ((obp-index (mapcar 'idlwave-shell-bp-get idlwave-shell-old-bp))
2398 (bpl idlwave-shell-bp-alist))
2399 (while (and (member (idlwave-shell-bp-get (car bpl)) obp-index)
2400 (setq bpl (cdr bpl))))
2401 (if (and
2402 (not bpl)
2403 ;; No additional breakpoint.
2404 ;; Need to check if we are just replacing a breakpoint.
2405 (setq bpl (assoc (car bp) idlwave-shell-bp-alist)))
2406 (setq bpl (list bpl)))
2407 (if (and bpl
2408 (equal (idlwave-shell-bp-get (setq bpl (car bpl)) 'file)
2409 (idlwave-shell-bp-get bp 'file)))
2410 ;; Got the breakpoint - add count, command to it.
2411 ;; This updates `idlwave-shell-bp-alist' because a deep copy was
2412 ;; not done for bpl.
2413 (idlwave-shell-set-bp-data bpl (idlwave-shell-bp-get bp 'data))
2414 (beep)
2415 (message "Failed to identify breakpoint in IDL"))))
2417 (defvar idlwave-shell-bp-overlays nil
2418 "List of overlays marking breakpoints")
2420 (defun idlwave-shell-update-bp-overlays ()
2421 "Update the overlays which mark breakpoints in the source code.
2422 Existing overlays are recycled, in order to minimize consumption."
2423 ;; FIXME: we could cache them all, but that would be more work.
2424 (when idlwave-shell-mark-breakpoints
2425 (let ((bp-list idlwave-shell-bp-alist)
2426 (ov-list idlwave-shell-bp-overlays)
2427 ov bp)
2428 ;; Delete the old overlays from their buffers
2429 (while (setq ov (pop ov-list))
2430 (delete-overlay ov))
2431 (setq ov-list idlwave-shell-bp-overlays
2432 idlwave-shell-bp-overlays nil)
2433 (while (setq bp (pop bp-list))
2434 (save-excursion
2435 (idlwave-shell-goto-frame (car bp))
2436 (let* ((end (progn (end-of-line 1) (point)))
2437 (beg (progn (beginning-of-line 1) (point)))
2438 (ov (or (pop ov-list)
2439 (idlwave-shell-make-new-bp-overlay))))
2440 (move-overlay ov beg end)
2441 (push ov idlwave-shell-bp-overlays)))))))
2443 (defvar idlwave-shell-bp-glyph)
2444 (defun idlwave-shell-make-new-bp-overlay ()
2445 "Make a new overlay for highlighting breakpoints.
2446 This stuff is stringly dependant upon the version of Emacs."
2447 (let ((ov (make-overlay 1 1)))
2448 (if (featurep 'xemacs)
2449 ;; This is XEmacs
2450 (progn
2451 (cond
2452 ((eq (console-type) 'tty)
2453 ;; tty's cannot display glyphs
2454 (set-extent-property ov 'face idlwave-shell-breakpoint-face))
2455 ((and (memq idlwave-shell-mark-breakpoints '(t glyph))
2456 idlwave-shell-bp-glyph)
2457 ;; use the glyph
2458 (set-extent-property ov 'begin-glyph idlwave-shell-bp-glyph))
2459 (idlwave-shell-mark-breakpoints
2460 ;; use the face
2461 (set-extent-property ov 'face idlwave-shell-breakpoint-face))
2463 ;; no marking
2464 nil))
2465 (set-extent-priority ov -1)) ; make stop line face prevail
2466 ;; This is Emacs
2467 (cond
2468 (window-system
2469 (if (and (memq idlwave-shell-mark-breakpoints '(t glyph))
2470 idlwave-shell-bp-glyph) ; this var knows if glyph's possible
2471 ;; use a glyph
2472 (let ((string "@"))
2473 (put-text-property 0 1
2474 'display idlwave-shell-bp-glyph
2475 string)
2476 (overlay-put ov 'before-string string))
2477 (overlay-put ov 'face idlwave-shell-breakpoint-face)))
2478 (idlwave-shell-mark-breakpoints
2479 ;; use a face
2480 (overlay-put ov 'face idlwave-shell-breakpoint-face))
2482 ;; No marking
2483 nil)))
2484 ov))
2486 (defun idlwave-shell-edit-default-command-line (arg)
2487 "Edit the current execute command."
2488 (interactive "P")
2489 (setq idlwave-shell-command-line-to-execute
2490 (read-string "IDL> " idlwave-shell-command-line-to-execute)))
2492 (defun idlwave-shell-execute-default-command-line (arg)
2493 "Execute a command line. On first use, ask for the command.
2494 Also with prefix arg, ask for the command. You can also uase the command
2495 `idlwave-shell-edit-default-command-line' to edit the line."
2496 (interactive "P")
2497 (if (or (not idlwave-shell-command-line-to-execute)
2498 arg)
2499 (setq idlwave-shell-command-line-to-execute
2500 (read-string "IDL> " idlwave-shell-command-line-to-execute)))
2501 (idlwave-shell-reset 'hidden)
2502 (idlwave-shell-send-command idlwave-shell-command-line-to-execute
2503 '(idlwave-shell-redisplay 'hide)))
2505 (defun idlwave-shell-save-and-run ()
2506 "Save file and run it in IDL.
2507 Runs `save-buffer' and sends a '.RUN' command for the associated file to IDL.
2508 When called from the shell buffer, re-run the file which was last handled by
2509 one of the save-and-.. commands."
2510 (interactive)
2511 (idlwave-shell-save-and-action 'run))
2513 (defun idlwave-shell-save-and-compile ()
2514 "Save file and run it in IDL.
2515 Runs `save-buffer' and sends '.COMPILE' command for the associated file to IDL.
2516 When called from the shell buffer, re-compile the file which was last handled by
2517 one of the save-and-.. commands."
2518 (interactive)
2519 (idlwave-shell-save-and-action 'compile))
2521 (defun idlwave-shell-save-and-batch ()
2522 "Save file and batch it in IDL.
2523 Runs `save-buffer' and sends a '@file' command for the associated file to IDL.
2524 When called from the shell buffer, re-batch the file which was last handled by
2525 one of the save-and-.. commands."
2526 (interactive)
2527 (idlwave-shell-save-and-action 'batch))
2529 (defun idlwave-shell-save-and-action (action)
2530 "Save file and compile it in IDL.
2531 Runs `save-buffer' and sends a '.RUN' command for the associated file to IDL.
2532 When called from the shell buffer, re-compile the file which was last
2533 handled by this command."
2534 ;; Remove the stop overlay.
2535 (if idlwave-shell-stop-line-overlay
2536 (delete-overlay idlwave-shell-stop-line-overlay))
2537 (setq idlwave-shell-is-stopped nil)
2538 (setq overlay-arrow-string nil)
2539 (let (buf)
2540 (cond
2541 ((eq major-mode 'idlwave-mode)
2542 (save-buffer)
2543 (setq idlwave-shell-last-save-and-action-file (buffer-file-name)))
2544 (idlwave-shell-last-save-and-action-file
2545 (if (setq buf (idlwave-get-buffer-visiting
2546 idlwave-shell-last-save-and-action-file))
2547 (save-excursion
2548 (set-buffer buf)
2549 (save-buffer))))
2550 (t (setq idlwave-shell-last-save-and-action-file
2551 (read-file-name "File: ")))))
2552 (if (file-regular-p idlwave-shell-last-save-and-action-file)
2553 (progn
2554 (idlwave-shell-send-command
2555 (concat (cond ((eq action 'run) ".run ")
2556 ((eq action 'compile) ".compile ")
2557 ((eq action 'batch) "@")
2558 (t (error "Unknown action %s" action)))
2559 idlwave-shell-last-save-and-action-file)
2560 'idlwave-shell-maybe-update-routine-info
2561 nil)
2562 (idlwave-shell-bp-query))
2563 (let ((msg (format "No such file %s"
2564 idlwave-shell-last-save-and-action-file)))
2565 (setq idlwave-shell-last-save-and-action-file nil)
2566 (error msg))))
2568 (defun idlwave-shell-maybe-update-routine-info ()
2569 "Update the routine info if the shell is not stopped at an error."
2570 (if (and (not idlwave-shell-is-stopped)
2571 (or (eq t idlwave-auto-routine-info-updates)
2572 (memq 'compile-buffer idlwave-auto-routine-info-updates))
2573 idlwave-query-shell-for-routine-info
2574 idlwave-routines)
2575 (idlwave-shell-update-routine-info t)))
2577 (defvar idlwave-shell-sources-query "help,/source"
2578 "IDL command to obtain source files for compiled procedures.")
2580 (defvar idlwave-shell-sources-alist nil
2581 "Alist of IDL procedure names and compiled source files.
2582 Elements of the alist have the form:
2584 (module name . (source-file-truename idlwave-internal-filename)).")
2586 (defun idlwave-shell-sources-query ()
2587 "Determine source files for IDL compiled procedures.
2588 Queries IDL using the string in `idlwave-shell-sources-query'."
2589 (interactive)
2590 (idlwave-shell-send-command idlwave-shell-sources-query
2591 'idlwave-shell-sources-filter
2592 'hide))
2594 (defun idlwave-shell-sources-filter ()
2595 "Get source files from `idlwave-shell-sources-query' output.
2596 Create `idlwave-shell-sources-alist' consisting of
2597 list elements of the form:
2598 (module name . (source-file-truename idlwave-internal-filename))."
2599 (save-excursion
2600 (set-buffer (get-buffer-create idlwave-shell-bp-buffer))
2601 (erase-buffer)
2602 (insert idlwave-shell-command-output)
2603 (goto-char (point-min))
2604 (let (cpro cfun)
2605 (if (re-search-forward "Compiled Procedures:" nil t)
2606 (progn
2607 (forward-line) ; Skip $MAIN$
2608 (setq cpro (point))))
2609 (if (re-search-forward "Compiled Functions:" nil t)
2610 (progn
2611 (setq cfun (point))
2612 (setq idlwave-shell-sources-alist
2613 (append
2614 ;; compiled procedures
2615 (progn
2616 (beginning-of-line)
2617 (narrow-to-region cpro (point))
2618 (goto-char (point-min))
2619 (idlwave-shell-sources-grep))
2620 ;; compiled functions
2621 (progn
2622 (widen)
2623 (goto-char cfun)
2624 (idlwave-shell-sources-grep)))))))))
2626 (defun idlwave-shell-sources-grep ()
2627 (save-excursion
2628 (let ((al (list nil)))
2629 (while (and
2630 (not (progn (forward-line) (eobp)))
2631 (re-search-forward
2632 "\\s-*\\(\\S-+\\)\\s-+\\(\\S-+\\)" nil t))
2633 (nconc al
2634 (list
2635 (cons
2636 (buffer-substring ; name
2637 (match-beginning 1) (match-end 1))
2638 (let ((internal-filename
2639 (buffer-substring ; source
2640 (match-beginning 2) (match-end 2))))
2641 (list
2642 (idlwave-shell-file-name internal-filename)
2643 internal-filename))
2644 ))))
2645 (cdr al))))
2648 (defun idlwave-shell-clear-all-bp ()
2649 "Remove all breakpoints in IDL."
2650 (interactive)
2651 (idlwave-shell-send-command
2652 idlwave-shell-bp-query
2653 '(progn
2654 (idlwave-shell-filter-bp)
2655 (mapcar 'idlwave-shell-clear-bp idlwave-shell-bp-alist))
2656 'hide))
2658 (defun idlwave-shell-list-all-bp ()
2659 "List all breakpoints in IDL."
2660 (interactive)
2661 (idlwave-shell-send-command
2662 idlwave-shell-bp-query))
2664 (defvar idlwave-shell-error-last 0
2665 "Position of last syntax error in `idlwave-shell-error-buffer'.")
2667 (defun idlwave-shell-goto-next-error ()
2668 "Move point to next IDL syntax error."
2669 (interactive)
2670 (let (frame col)
2671 (save-excursion
2672 (set-buffer idlwave-shell-error-buffer)
2673 (goto-char idlwave-shell-error-last)
2674 (if (or (re-search-forward idlwave-shell-syntax-error nil t)
2675 (re-search-forward idlwave-shell-other-error nil t))
2676 (progn
2677 (setq frame
2678 (list
2679 (save-match-data
2680 (idlwave-shell-file-name
2681 (buffer-substring (match-beginning 1) (match-end 1))))
2682 (string-to-int
2683 (buffer-substring (match-beginning 2)
2684 (match-end 2)))))
2685 ;; Try to find the column of the error
2686 (save-excursion
2687 (setq col
2688 (if (re-search-backward "\\^" nil t)
2689 (current-column)
2690 0)))))
2691 (setq idlwave-shell-error-last (point)))
2692 (if frame
2693 (progn
2694 (idlwave-shell-display-line frame col))
2695 (beep)
2696 (message "No more errors."))))
2698 (defun idlwave-shell-file-name (name)
2699 "If `idlwave-shell-use-truename' is non-nil, convert file name to true name.
2700 Otherwise, just expand the file name."
2701 (let ((def-dir (if (eq major-mode 'idlwave-shell-mode)
2702 default-directory
2703 idlwave-shell-default-directory)))
2704 (if idlwave-shell-use-truename
2705 (file-truename name def-dir)
2706 (expand-file-name name def-dir))))
2709 ;; Keybindings --------------------------------------------------------------
2711 (defvar idlwave-shell-mode-map (copy-keymap comint-mode-map)
2712 "Keymap for idlwave-mode.")
2713 (defvar idlwave-shell-mode-prefix-map (make-sparse-keymap))
2714 (fset 'idlwave-shell-mode-prefix-map idlwave-shell-mode-prefix-map)
2716 ;(define-key idlwave-shell-mode-map "\M-?" 'comint-dynamic-list-completions)
2717 ;(define-key idlwave-shell-mode-map "\t" 'comint-dynamic-complete)
2718 (define-key idlwave-shell-mode-map "\t" 'idlwave-shell-complete)
2719 (define-key idlwave-shell-mode-map "\M-\t" 'idlwave-shell-complete)
2720 (define-key idlwave-shell-mode-map "\C-c\C-s" 'idlwave-shell)
2721 (define-key idlwave-shell-mode-map "\C-c?" 'idlwave-routine-info)
2722 (define-key idlwave-shell-mode-map "\M-?" 'idlwave-context-help)
2723 (define-key idlwave-shell-mode-map "\C-c\C-i" 'idlwave-update-routine-info)
2724 (define-key idlwave-shell-mode-map "\C-c\C-y" 'idlwave-shell-char-mode-loop)
2725 (define-key idlwave-shell-mode-map "\C-c\C-x" 'idlwave-shell-send-char)
2726 (define-key idlwave-shell-mode-map "\C-c=" 'idlwave-resolve)
2727 (define-key idlwave-shell-mode-map "\C-c\C-v" 'idlwave-find-module)
2728 (define-key idlwave-shell-mode-map "\C-c\C-k" 'idlwave-kill-autoloaded-buffers)
2729 (define-key idlwave-shell-mode-map idlwave-shell-prefix-key
2730 'idlwave-shell-debug-map)
2731 (define-key idlwave-mode-map "\C-c\C-y" 'idlwave-shell-char-mode-loop)
2732 (define-key idlwave-mode-map "\C-c\C-x" 'idlwave-shell-send-char)
2733 (define-key idlwave-mode-map
2734 (if (featurep 'xemacs) [(shift button2)] [(shift mouse-2)])
2735 'idlwave-shell-mouse-print)
2736 (define-key idlwave-mode-map
2737 (if (featurep 'xemacs) [(shift control button2)] [(shift control mouse-2)])
2738 'idlwave-shell-mouse-help)
2739 (define-key idlwave-shell-mode-map
2740 (if (featurep 'xemacs) [(shift button2)] [(shift mouse-2)])
2741 'idlwave-shell-mouse-print)
2742 (define-key idlwave-shell-mode-map
2743 (if (featurep 'xemacs) [(shift control button2)] [(shift control mouse-2)])
2744 'idlwave-shell-mouse-help)
2745 (define-key idlwave-shell-mode-map
2746 (if (featurep 'xemacs) [(shift button3)] [(shift mouse-3)])
2747 'idlwave-mouse-context-help)
2750 ;; The following set of bindings is used to bind the debugging keys.
2751 ;; If `idlwave-shell-activate-prefix-keybindings' is non-nil, the first key
2752 ;; in the list gets bound the C-c C-d prefix map.
2753 ;; If `idlwave-shell-activate-alt-keybindings' is non-nil, the second key
2754 ;; in the list gets bound directly in both idlwave-mode-map and
2755 ;; idlwave-shell-mode-map.
2757 ;; Used keys: abcde hi klmnopqrs u wxyz
2758 ;; Unused keys: fg j t v
2759 (let ((specs
2760 '(([(control ?b)] [(alt ?b)] idlwave-shell-break-here)
2761 ([(control ?i)] [(alt ?i)] idlwave-shell-break-in)
2762 ([(control ?d)] [(alt ?d)] idlwave-shell-clear-current-bp)
2763 ([(control ?a)] [(alt ?a)] idlwave-shell-clear-all-bp)
2764 ([(control ?s)] [(alt ?s)] idlwave-shell-step)
2765 ([(control ?n)] [(alt ?n)] idlwave-shell-stepover)
2766 ([(control ?k)] [(alt ?k)] idlwave-shell-skip)
2767 ([(control ?u)] [(alt ?u)] idlwave-shell-up)
2768 ([(control ?o)] [(alt ?o)] idlwave-shell-out)
2769 ([(control ?m)] [(alt ?m)] idlwave-shell-return)
2770 ([(control ?h)] [(alt ?h)] idlwave-shell-to-here)
2771 ([(control ?r)] [(alt ?r)] idlwave-shell-cont)
2772 ([(control ?y)] [(alt ?y)] idlwave-shell-execute-default-command-line)
2773 ([(control ?z)] [(alt ?z)] idlwave-shell-reset)
2774 ([(control ?q)] [(alt ?q)] idlwave-shell-quit)
2775 ([(control ?p)] [(alt ?p)] idlwave-shell-print)
2776 ([(??)] [(alt ??)] idlwave-shell-help-expression)
2777 ([(control ?c)] [(alt ?c)] idlwave-shell-save-and-run)
2778 ([( ?@)] [(alt ?@)] idlwave-shell-save-and-batch)
2779 ([(control ?x)] [(alt ?x)] idlwave-shell-goto-next-error)
2780 ([(control ?e)] [(alt ?e)] idlwave-shell-run-region)
2781 ([(control ?w)] [(alt ?w)] idlwave-shell-resync-dirs)
2782 ([(control ?l)] [(alt ?l)] idlwave-shell-redisplay)
2783 ([(control ?t)] [(alt ?t)] idlwave-shell-toggle-toolbar)
2784 ([(control up)] [(alt up)] idlwave-shell-stack-up)
2785 ([(control down)] [(alt down)] idlwave-shell-stack-down)
2787 s k1 k2 cmd)
2788 (while (setq s (pop specs))
2789 (setq k1 (nth 0 s)
2790 k2 (nth 1 s)
2791 cmd (nth 2 s))
2792 (when idlwave-shell-activate-prefix-keybindings
2793 (and k1 (define-key idlwave-shell-mode-prefix-map k1 cmd)))
2794 (when idlwave-shell-activate-alt-keybindings
2795 (and k2 (define-key idlwave-mode-map k2 cmd))
2796 (and k2 (define-key idlwave-shell-mode-map k2 cmd)))))
2798 ;; Enter the prefix map at the two places.
2799 (fset 'idlwave-debug-map idlwave-shell-mode-prefix-map)
2800 (fset 'idlwave-shell-debug-map idlwave-shell-mode-prefix-map)
2802 ;; The Menus --------------------------------------------------------------
2804 (defvar idlwave-shell-menu-def
2805 '("Debug"
2806 ["Save and .RUN" idlwave-shell-save-and-run
2807 (or (eq major-mode 'idlwave-mode)
2808 idlwave-shell-last-save-and-action-file)]
2809 ["Save and .COMPILE" idlwave-shell-save-and-compile
2810 (or (eq major-mode 'idlwave-mode)
2811 idlwave-shell-last-save-and-action-file)]
2812 ["Save and @Batch" idlwave-shell-save-and-batch
2813 (or (eq major-mode 'idlwave-mode)
2814 idlwave-shell-last-save-and-action-file)]
2815 ["Goto Next Error" idlwave-shell-goto-next-error t]
2816 "--"
2817 ["Execute Default Cmd" idlwave-shell-execute-default-command-line t]
2818 ["Edit Default Cmd" idlwave-shell-edit-default-command-line t]
2819 "--"
2820 ["Set Breakpoint" idlwave-shell-break-here
2821 (eq major-mode 'idlwave-mode)]
2822 ["Break in Module" idlwave-shell-break-in t]
2823 ["Clear Breakpoint" idlwave-shell-clear-current-bp t]
2824 ["Clear All Breakpoints" idlwave-shell-clear-all-bp t]
2825 ["List All Breakpoints" idlwave-shell-list-all-bp t]
2826 "--"
2827 ["Step (into)" idlwave-shell-step t]
2828 ["Step (over)" idlwave-shell-stepover t]
2829 ["Skip One Statement" idlwave-shell-skip t]
2830 ["Continue" idlwave-shell-cont t]
2831 ("Continue to"
2832 ["End of Block" idlwave-shell-up t]
2833 ["End of Subprog" idlwave-shell-return t]
2834 ["End of Subprog+1" idlwave-shell-out t]
2835 ["Here (Cursor Line)" idlwave-shell-to-here
2836 (eq major-mode 'idlwave-mode)])
2837 "--"
2838 ["Print expression" idlwave-shell-print t]
2839 ["Help on expression" idlwave-shell-help-expression t]
2840 ["Evaluate Region" idlwave-shell-evaluate-region
2841 (eq major-mode 'idlwave-mode)]
2842 ["Run Region" idlwave-shell-run-region (eq major-mode 'idlwave-mode)]
2843 "--"
2844 ["Redisplay" idlwave-shell-redisplay t]
2845 ["Stack Up" idlwave-shell-stack-up t]
2846 ["Stack Down" idlwave-shell-stack-down t]
2847 "--"
2848 ["Update Working Dir" idlwave-shell-resync-dirs t]
2849 ["Reset IDL" idlwave-shell-reset t]
2850 "--"
2851 ["Toggle Toolbar" idlwave-shell-toggle-toolbar t]
2852 ["Exit IDL" idlwave-shell-quit t]))
2853 ;;FIXME: Which menu???
2854 (setq idlwave-shell-menu-def
2855 '("Debug"
2856 ("Compile & Run"
2857 ["Save and .RUN" idlwave-shell-save-and-run
2858 (or (eq major-mode 'idlwave-mode)
2859 idlwave-shell-last-save-and-action-file)]
2860 ["Save and .COMPILE" idlwave-shell-save-and-compile
2861 (or (eq major-mode 'idlwave-mode)
2862 idlwave-shell-last-save-and-action-file)]
2863 ["Save and @Batch" idlwave-shell-save-and-batch
2864 (or (eq major-mode 'idlwave-mode)
2865 idlwave-shell-last-save-and-action-file)]
2866 ["Goto Next Error" idlwave-shell-goto-next-error t]
2867 "--"
2868 ["Run Region" idlwave-shell-run-region (eq major-mode 'idlwave-mode)]
2869 "--"
2870 ["Execute Default Cmd" idlwave-shell-execute-default-command-line t]
2871 ["Edit Default Cmd" idlwave-shell-edit-default-command-line t])
2872 ("Breakpoints"
2873 ["Set Breakpoint" idlwave-shell-break-here
2874 (eq major-mode 'idlwave-mode)]
2875 ["Break in Module" idlwave-shell-break-in t]
2876 ["Clear Breakpoint" idlwave-shell-clear-current-bp t]
2877 ["Clear All Breakpoints" idlwave-shell-clear-all-bp t]
2878 ["List All Breakpoints" idlwave-shell-list-all-bp t])
2879 ("Step"
2880 ["Step (into)" idlwave-shell-step t]
2881 ["Step (over)" idlwave-shell-stepover t]
2882 ["Skip One Statement" idlwave-shell-skip t]
2883 ["Continue" idlwave-shell-cont t]
2884 ["... to End of Block" idlwave-shell-up t]
2885 ["... to End of Subprog" idlwave-shell-return t]
2886 ["... to End of Subprog+1" idlwave-shell-out t]
2887 ["... to Here (Cursor Line)" idlwave-shell-to-here
2888 (eq major-mode 'idlwave-mode)])
2889 ("Print Expression"
2890 ["Print expression" idlwave-shell-print t]
2891 ["Help on expression" idlwave-shell-help-expression t]
2892 ["Evaluate Region" idlwave-shell-evaluate-region
2893 (eq major-mode 'idlwave-mode)]
2894 "--"
2895 ["Redisplay" idlwave-shell-redisplay t]
2896 ["Stack Up" idlwave-shell-stack-up t]
2897 ["Stack Down" idlwave-shell-stack-down t])
2898 ("Input Mode"
2899 ["Send one char" idlwave-shell-send-char t]
2900 ["Temporary Character Mode" idlwave-shell-char-mode-loop t]
2901 "--"
2902 ["Use Input Mode Magic"
2903 (setq idlwave-shell-use-input-mode-magic
2904 (not idlwave-shell-use-input-mode-magic))
2905 :style toggle :selected idlwave-shell-use-input-mode-magic])
2906 "--"
2907 ["Update Working Dir" idlwave-shell-resync-dirs t]
2908 ["Reset IDL" idlwave-shell-reset t]
2909 "--"
2910 ["Toggle Toolbar" idlwave-shell-toggle-toolbar t]
2911 ["Exit IDL" idlwave-shell-quit t]))
2913 (if (or (featurep 'easymenu) (load "easymenu" t))
2914 (progn
2915 (easy-menu-define
2916 idlwave-shell-mode-menu idlwave-shell-mode-map "IDL shell menus"
2917 idlwave-shell-menu-def)
2918 (easy-menu-define
2919 idlwave-mode-debug-menu idlwave-mode-map "IDL debugging menus"
2920 idlwave-shell-menu-def)
2921 (save-excursion
2922 (mapcar (lambda (buf)
2923 (set-buffer buf)
2924 (if (eq major-mode 'idlwave-mode)
2925 (progn
2926 (easy-menu-remove idlwave-mode-debug-menu)
2927 (easy-menu-add idlwave-mode-debug-menu))))
2928 (buffer-list)))))
2930 ;; The Breakpoint Glyph -------------------------------------------------------
2932 (defvar idlwave-shell-bp-glyph nil
2933 "The glyph to mark breakpoint lines in the source code.")
2935 (let ((image-string "/* XPM */
2936 static char * file[] = {
2937 \"14 12 3 1\",
2938 \" c #FFFFFFFFFFFF s backgroundColor\",
2939 \". c #4B4B4B4B4B4B\",
2940 \"R c #FFFF00000000\",
2941 \" \",
2942 \" \",
2943 \" RRRR \",
2944 \" RRRRRR \",
2945 \" RRRRRRRR \",
2946 \" RRRRRRRR \",
2947 \" RRRRRRRR \",
2948 \" RRRRRRRR \",
2949 \" RRRRRR \",
2950 \" RRRR \",
2951 \" \",
2952 \" \"};"))
2954 (setq idlwave-shell-bp-glyph
2955 (cond ((and (featurep 'xemacs)
2956 (featurep 'xpm))
2957 (make-glyph image-string))
2958 ((and (not (featurep 'xemacs))
2959 (fboundp 'image-type-available-p)
2960 (image-type-available-p 'xpm))
2961 (list 'image :type 'xpm :data image-string))
2962 (t nil))))
2964 (provide 'idlw-shell)
2965 (provide 'idlwave-shell)
2967 ;;; Load the toolbar when wanted by the user.
2969 (autoload 'idlwave-toolbar-toggle "idlw-toolbar"
2970 "Toggle the IDLWAVE toolbar")
2971 (autoload 'idlwave-toolbar-add-everywhere "idlw-toolbar"
2972 "Add IDLWAVE toolbar")
2973 (defun idlwave-shell-toggle-toolbar ()
2974 "Toggle the display of the debugging toolbar."
2975 (interactive)
2976 (idlwave-toolbar-toggle))
2978 (if idlwave-shell-use-toolbar
2979 (add-hook 'idlwave-shell-mode-hook 'idlwave-toolbar-add-everywhere))
2981 ;;; idlw-shell.el ends here