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