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