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