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