1 ;; idlw-shell.el --- run IDL as an inferior process of Emacs.
3 ;; Copyright (C) 1999-2015 Free Software Foundation, Inc.
5 ;; Authors: J.D. Smith <jdsmith@as.arizona.edu>
6 ;; Carsten Dominik <dominik@astro.uva.nl>
7 ;; Chris Chase <chase@att.com>
8 ;; Maintainer: J.D. Smith <jdsmith@as.arizona.edu>
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
29 ;; This mode is for IDL version 5 or later. It should work on
30 ;; Emacs>20.3 or XEmacs>20.4.
32 ;; Runs IDL as an inferior process of Emacs, much like the Emacs
33 ;; `shell' or `telnet' commands. Provides command history and
34 ;; searching. Provides debugging commands available in buffers
35 ;; visiting IDL procedure files, e.g., breakpoint setting, stepping,
36 ;; execution until a certain line, printing expressions under point,
37 ;; visual line pointer for current execution line, etc.
39 ;; Documentation should be available online with `M-x idlwave-info'.
41 ;; New versions of IDLWAVE, documentation, and more information
43 ;; http://github.com/jdtsmith/idlwave
48 ;; Follow the instructions in the INSTALL file of the distribution.
49 ;; In short, put this file on your load path and add the following
50 ;; lines to your init file:
52 ;; (autoload 'idlwave-shell "idlw-shell" "IDLWAVE Shell" t)
58 ;; The newest version of this file can be found on the maintainers
61 ;; http://github.com/jdtsmith/idlwave
66 ;; IDLWAVE is documented online in info format.
67 ;; A printable version of the documentation is available from the
68 ;; maintainers webpage (see under SOURCE)
74 ;; Under XEmacs the Debug menu in the shell does not display the
75 ;; keybindings in the prefix map. There bindings are available anyway - so
76 ;; it is a bug in XEmacs.
77 ;; The Debug menu in source buffers *does* display the bindings correctly.
80 ;; CUSTOMIZATION VARIABLES
81 ;; =======================
83 ;; IDLWAVE has customize support - so if you want to learn about
84 ;; the variables which control the behavior of the mode, use
85 ;; `M-x idlwave-customize'.
87 ;;--------------------------------------------------------------------------
95 (eval-when-compile (require 'cl
))
97 (defvar idlwave-shell-have-new-custom nil
)
99 ;;; Customizations: idlwave-shell group
101 ;; General/Misc. customizations
102 (defgroup idlwave-shell-general-setup nil
103 "General setup of the Shell interaction for IDLWAVE/Shell."
104 :prefix
"idlwave-shell"
107 (defcustom idlwave-shell-prompt-pattern
"^\r? ?IDL> "
108 "Regexp to match IDL prompt at beginning of a line.
109 For example, \"^\r?IDL> \" or \"^\r?WAVE> \".
110 The \"^\r?\" is needed, to indicate the beginning of the line, with
111 optional return character (which IDL seems to output randomly).
112 This variable is used to initialize `comint-prompt-regexp' in the
114 :group
'idlwave-shell-general-setup
117 (defcustom idlwave-shell-process-name
"idl"
118 "Name to be associated with the IDL process. The buffer for the
119 process output is made by surrounding this name with `*'s."
120 :group
'idlwave-shell-general-setup
123 ;; (defcustom idlwave-shell-automatic-start...) See idlwave.el
125 (defcustom idlwave-shell-use-dedicated-window nil
126 "Non-nil means, never replace the shell frame with another buffer."
127 :group
'idlwave-shell-general-setup
130 (defcustom idlwave-shell-use-dedicated-frame nil
131 "Non-nil means, IDLWAVE should use a special frame to display shell buffer."
132 :group
'idlwave-shell-general-setup
135 (defcustom idlwave-shell-frame-parameters
136 '((height .
30) (unsplittable . nil
))
137 "The frame parameters for a dedicated idlwave-shell frame.
138 See also `idlwave-shell-use-dedicated-frame'.
139 The default makes the frame splittable, so that completion works correctly."
140 :group
'idlwave-shell-general-setup
144 (defcustom idlwave-shell-raise-frame t
145 "Non-nil means, `idlwave-shell' raises the frame showing the shell window."
146 :group
'idlwave-shell-general-setup
149 (defcustom idlwave-shell-arrows-do-history t
150 "Non-nil means UP and DOWN arrows move through command history.
151 This variable can have 3 values:
152 nil Arrows just move the cursor
153 t Arrows force the cursor back to the current command line and
155 `cmdline' When the cursor is in the current command line, arrows walk the
156 history. Everywhere else in the buffer, arrows move the cursor."
157 :group
'idlwave-shell-general-setup
159 (const :tag
"never" nil
)
160 (const :tag
"everywhere" t
)
161 (const :tag
"in command line only" cmdline
)))
163 ;; FIXME: add comint-input-ring-size?
165 (defcustom idlwave-shell-use-toolbar t
166 "Non-nil means, use the debugging toolbar in all IDL related buffers.
167 Starting the shell will then add the toolbar to all idlwave-mode buffers.
168 Exiting the shell will removed everywhere.
169 Available on XEmacs and on Emacs 21.x or later.
170 At any time you can toggle the display of the toolbar with
171 `C-c C-d C-t' (`idlwave-shell-toggle-toolbar')."
172 :group
'idlwave-shell-general-setup
175 (defcustom idlwave-shell-temp-pro-prefix
"/tmp/idltemp"
176 "The prefix for temporary IDL files used when compiling regions.
177 It should be an absolute pathname.
178 The full temporary file name is obtained by using `make-temp-file'
179 so that the name will be unique among multiple Emacs processes."
180 :group
'idlwave-shell-general-setup
183 (defcustom idlwave-shell-prefix-key
"\C-c\C-d"
184 "The prefix key for the debugging map `idlwave-shell-mode-prefix-map'.
185 This variable must already be set when idlwave-shell.el is loaded.
186 Setting it in the mode-hook is too late."
187 :group
'idlwave-shell-general-setup
190 (defcustom idlwave-shell-activate-prefix-keybindings t
191 "Non-nil means, the debug commands will be bound to the prefix key.
192 The prefix key itself is given in the option `idlwave-shell-prefix-key'.
193 So by default setting a breakpoint will be on C-c C-d C-b."
194 :group
'idlwave-shell-general-setup
197 (defcustom idlwave-shell-automatic-electric-debug
'breakpoint
198 "Enter the electric-debug minor mode automatically.
199 This occurs at a breakpoint or any other halt. The mode is exited
200 upon return to the main level. Can be set to 'breakpoint to enter
201 electric debug mode only when breakpoints are tripped."
202 :group
'idlwave-shell-general-setup
204 (const :tag
"never" nil
)
205 (const :tag
"always" t
)
206 (const :tag
"for breakpoints only" breakpoint
)))
208 (defcustom idlwave-shell-electric-zap-to-file t
209 "When entering electric debug mode, select the window displaying the
210 file at which point is stopped. This takes point away from the shell
211 window, but is useful for stepping, etc."
212 :group
'idlwave-shell-general-setup
215 ;; (defcustom idlwave-shell-debug-modifiers... See idlwave.el
217 (defcustom idlwave-shell-use-truename nil
218 "Non-nil means, use `file-truename' when looking for buffers.
219 If this variable is non-nil, Emacs will use the function `file-truename' to
220 resolve symbolic links in the file paths printed by e.g., STOP commands.
221 This means, unvisited files will be loaded under their truename.
222 However, when a file is already visited under a different name, IDLWAVE will
224 This option was once introduced in order to avoid multiple buffers visiting
225 the same file. However, IDLWAVE no longer makes this mistake, so it is safe
226 to set this option to nil."
227 :group
'idlwave-shell-general-setup
230 (defcustom idlwave-shell-file-name-chars
"~/A-Za-z0-9+:_.$#%={}\\- "
231 "The characters allowed in file names, as a string.
232 Used for file name completion. Must not contain `\\='', `,' and `\"'
233 because these are used as separators by IDL."
234 :group
'idlwave-shell-general-setup
237 (defcustom idlwave-shell-mode-hook
'()
238 "Hook for customizing `idlwave-shell-mode'."
239 :group
'idlwave-shell-general-setup
242 (defcustom idlwave-shell-graphics-window-size
'(500 400)
243 "Size of IDL graphics windows popped up by special IDLWAVE command.
244 The command is `C-c C-d C-f' and accepts as a prefix the window nr.
245 A command like `WINDOW,N,xsize=XX,ysize=YY' is sent to IDL."
246 :group
'idlwave-shell-general-setup
248 (integer :tag
"x size")
249 (integer :tag
"y size")))
252 ;; Commands Sent to Shell... etc.
253 (defgroup idlwave-shell-command-setup nil
254 "Setup for command parameters of the Shell interaction for IDLWAVE."
255 :prefix
"idlwave-shell"
258 (defcustom idlwave-shell-initial-commands
"!more=0 & defsysv,'!ERROR_STATE',EXISTS=__e & if __e then begin & !ERROR_STATE.MSG_PREFIX=\"% \" & delvar,__e & endif"
259 "Initial commands, separated by newlines, to send to IDL.
260 This string is sent to the IDL process by `idlwave-shell-mode' which is
261 invoked by `idlwave-shell'."
262 :group
'idlwave-shell-command-setup
265 (defcustom idlwave-shell-save-command-history t
266 "Non-nil means preserve command history between sessions.
267 The file `idlwave-shell-command-history-file' is used to save and restore
269 :group
'idlwave-shell-command-setup
272 (defcustom idlwave-shell-command-history-file
"idlwhist"
273 "The file in which the command history of the idlwave shell is saved.
274 In order to change the size of the history, see the variable
275 `comint-input-ring-size'.
276 The history is only saved if the variable `idlwave-shell-save-command-history'
278 :group
'idlwave-shell-command-setup
281 (defcustom idlwave-shell-show-commands
282 '(run misc breakpoint
)
283 "A list of command types to show output from in the shell.
284 Possibilities are 'run, 'debug, 'breakpoint, and 'misc. Unselected
285 types are not displayed in the shell. The type 'everything causes all
286 the copious shell traffic to be displayed."
287 :group
'idlwave-shell-command-setup
290 (set :tag
"Checklist" :greedy t
291 (const :tag
"All .run and .compile commands" run
)
292 (const :tag
"All breakpoint commands" breakpoint
)
293 (const :tag
"All debug and stepping commands" debug
)
294 (const :tag
"Close, window, retall, etc. commands" misc
))))
296 (defcustom idlwave-shell-max-print-length
200
297 "Maximum number of array elements to print when examining."
298 :group
'idlwave-shell-command-setup
301 (defcustom idlwave-shell-examine-alist
302 `(("Print" .
,(concat "idlwave_print_safe,___,"
304 idlwave-shell-max-print-length
)))
305 ("Help" .
"help,___")
306 ("Structure Help" .
"help,___,/STRUCTURE")
307 ("Dimensions" .
"print,size(___,/DIMENSIONS)")
308 ("Type" .
"print,size(___,/TNAME)")
309 ("N_Elements" .
"print,n_elements(___)")
310 ("All Size Info" .
"help,(__IWsz__=size(___,/STRUCTURE)),/STRUCTURE & print,__IWsz__.DIMENSIONS")
311 ("Ptr Valid" .
"print,ptr_valid(___)")
312 ("Arg Present" .
"print,arg_present(___)")
313 ("Widget Valid" .
"print,widget_info(___,/VALID)")
314 ("Widget Geometry" .
"help,widget_info(___,/GEOMETRY)"))
315 "Alist of special examine commands for popup selection.
316 The keys are used in the selection popup created by
317 `idlwave-shell-examine-select', and the corresponding value is sent as
318 a command to the shell, with special sequence `___' replaced by the
319 expression being examined."
320 :group
'idlwave-shell-command-setup
323 (string :tag
"Label ")
324 (string :tag
"Command"))))
326 (defcustom idlwave-shell-separate-examine-output t
327 "Non-nil means, put output of examine commands in their own buffer."
328 :group
'idlwave-shell-command-setup
331 (defcustom idlwave-shell-comint-settings
332 '((comint-scroll-to-bottom-on-input . t
)
333 (comint-scroll-to-bottom-on-output . t
)
334 (comint-scroll-show-maximum-output . nil
)
335 (comint-prompt-read-only . t
))
337 "Alist of special settings for the comint variables in the IDLWAVE Shell.
338 Each entry is a cons cell with the name of a variable and a value.
339 The function `idlwave-shell-mode' will make local variables out of each entry.
340 Changes to this variable will only be active when the shell buffer is
342 :group
'idlwave-shell-command-setup
344 (cons variable sexp
)))
346 (defcustom idlwave-shell-query-for-class t
347 "Non-nil means query the shell for object class on object completions."
348 :group
'idlwave-shell-command-setup
351 (defcustom idlwave-shell-use-input-mode-magic nil
352 "Non-nil means, IDLWAVE should check for input mode spells in output.
353 The spells are strings printed by your IDL program and matched
354 by the regular expressions in `idlwave-shell-input-mode-spells'.
355 When these expressions match, IDLWAVE switches to character input mode and
356 back, respectively. See `idlwave-shell-input-mode-spells' for details."
357 :group
'idlwave-shell-command-setup
360 (defcustom idlwave-shell-input-mode-spells
361 '("^<onechar>$" "^<chars>$" "^</chars>$")
362 "The three regular expressions which match the magic spells for input modes.
364 When the first regexp matches in the output stream of IDL, IDLWAVE
365 prompts for a single character and sends it immediately to IDL, similar
366 to the command \\[idlwave-shell-send-char].
368 When the second regexp matches, IDLWAVE switches to a blocking
369 single-character input mode. This is the same mode which can be entered
370 manually with \\[idlwave-shell-char-mode-loop].
371 This input mode exits when the third regexp matches in the output,
372 or when the IDL prompt is encountered.
374 The variable `idlwave-shell-use-input-mode-magic' must be non-nil to enable
375 scanning for these expressions. If the IDL program produces lots of
376 output, shell operation may be slowed down.
378 This mechanism is useful for correct interaction with the IDL function
379 GET_KBRD, because in normal operation IDLWAVE only sends \\n terminated
380 strings. Here is some example code which makes use of the default spells.
382 print,\\='<chars>\\=' ; Make IDLWAVE switch to character mode
386 ENDREP UNTIL A EQ \\='q\\='
387 print,\\='</chars>\\=' ; Make IDLWAVE switch back to line mode
389 print,\\='Quit the program, y or n?\\='
390 print,\\='<onechar>\\=' ; Ask IDLWAVE to send one character
393 Since the IDLWAVE shell defines the system variable `!IDLWAVE_VERSION',
394 you could actually check if you are running under Emacs before printing
395 the magic strings. Here is a procedure which uses this.
399 idlwave_char_input ; Make IDLWAVE send one character
400 idlwave_char_input,/on ; Start the loop to send characters
401 idlwave_char_input,/off ; End the loop to send characters
404 pro idlwave_char_input,on=on,off=off
405 ;; Test if we are running under Emacs
406 defsysv,\\='!idlwave_version\\=',exists=running_emacs
407 if running_emacs then begin
408 if keyword_set(on) then print,\\='<chars>\\=' $
409 else if keyword_set(off) then print,\\='</chars>\\=' $
410 else print,\\='<onechar>\\='
413 :group
'idlwave-shell-command-setup
415 (regexp :tag
"One-char regexp")
416 (regexp :tag
"Char-mode regexp")
417 (regexp :tag
"Line-mode regexp")))
419 (defcustom idlwave-shell-breakpoint-popup-menu t
420 "If non-nil, provide a menu on mouse-3 on breakpoint lines, and
421 popup help text on the line."
422 :group
'idlwave-shell-command-setup
425 (defcustom idlwave-shell-reset-no-prompt nil
426 "If non-nil, skip the yes/no prompt when resetting the IDL session."
427 :group
'idlwave-shell-command-setup
430 ;; Breakpoint Overlays etc
431 (defgroup idlwave-shell-highlighting-and-faces nil
432 "Highlighting and faces used by the IDLWAVE Shell mode."
433 :prefix
"idlwave-shell"
436 (defcustom idlwave-shell-mark-stop-line t
437 "Non-nil means, mark the source code line where IDL is currently stopped.
438 Value decides about the method which is used to mark the line. Valid values
441 nil Do not mark the line
442 `arrow' Use the overlay arrow
443 `face' Use `idlwave-shell-stop-line-face' to highlight the line.
444 t Use what IDLWAVE thinks is best. Will be a face where possible,
445 otherwise the overlay arrow.
446 The overlay-arrow has the disadvantage to hide the first chars of a line.
447 Since many people do not have the main block of IDL programs indented,
448 a face highlighting may be better."
449 :group
'idlwave-shell-highlighting-and-faces
451 (const :tag
"No marking" nil
)
452 (const :tag
"Use overlay arrow" arrow
)
453 (const :tag
"Highlight with face" face
)
454 (const :tag
"Face or arrow." t
)))
456 (defcustom idlwave-shell-overlay-arrow
">"
457 "The overlay arrow to display at source lines where execution halts.
458 We use a single character by default, since the main block of IDL procedures
459 often has no indentation. Where possible, IDLWAVE will use overlays to
460 display the stop-lines. The arrow is only used on character-based terminals.
461 See also `idlwave-shell-use-overlay-arrow'."
462 :group
'idlwave-shell-highlighting-and-faces
465 (defcustom idlwave-shell-stop-line-face
'highlight
466 "The face for `idlwave-shell-stop-line-overlay'.
467 Allows you to choose the font, color and other properties for
468 line where IDL is stopped. See also `idlwave-shell-mark-stop-line'."
469 :group
'idlwave-shell-highlighting-and-faces
472 (defcustom idlwave-shell-electric-stop-color
"Violet"
473 "The color for the default face or overlay arrow when stopped."
474 :group
'idlwave-shell-highlighting-and-faces
477 (defcustom idlwave-shell-electric-stop-line-face
479 (copy-face 'mode-line
'idlwave-shell-electric-stop-line
)
480 (set-face-background 'idlwave-shell-electric-stop-line
481 idlwave-shell-electric-stop-color
)
483 (set-face-foreground 'idlwave-shell-electric-stop-line nil
)
485 "The face for `idlwave-shell-stop-line-overlay' when in electric debug mode.
486 Allows you to choose the font, color and other properties for the line
487 where IDL is stopped, when in Electric Debug Mode."
488 :group
'idlwave-shell-highlighting-and-faces
491 (defcustom idlwave-shell-mark-breakpoints t
492 "Non-nil means, mark breakpoints in the source files.
494 nil Do not mark breakpoints.
495 `face' Highlight line with `idlwave-shell-breakpoint-face'.
496 `glyph' Red dot at the beginning of line. If the display does not
497 support glyphs, will use `face' instead.
498 t Glyph when possible, otherwise face (same effect as `glyph')."
499 :group
'idlwave-shell-highlighting-and-faces
501 (const :tag
"No marking" nil
)
502 (const :tag
"Highlight with face" face
)
503 (const :tag
"Display glyph (red dot)" glyph
)
504 (const :tag
"Glyph or face." t
)))
506 (defcustom idlwave-shell-breakpoint-face
'idlwave-shell-bp
507 "The face for breakpoint lines in the source code.
508 Allows you to choose the font, color and other properties for
509 lines which have a breakpoint. See also `idlwave-shell-mark-breakpoints'."
510 :group
'idlwave-shell-highlighting-and-faces
513 (if (not idlwave-shell-have-new-custom
)
514 ;; Just copy the underline face to be on the safe side.
515 (copy-face 'underline
'idlwave-shell-bp
)
516 ;; We have the new customize - use it to define a customizable face
517 (defface idlwave-shell-bp
518 '((((class color
)) (:foreground
"Black" :background
"Pink"))
520 "Face for highlighting lines with breakpoints."
521 :group
'idlwave-shell-highlighting-and-faces
))
523 (defcustom idlwave-shell-disabled-breakpoint-face
524 'idlwave-shell-disabled-bp
525 "The face for disabled breakpoint lines in the source code.
526 Allows you to choose the font, color and other properties for
527 lines which have a breakpoint. See also `idlwave-shell-mark-breakpoints'."
528 :group
'idlwave-shell-highlighting-and-faces
531 (if (not idlwave-shell-have-new-custom
)
532 ;; Just copy the underline face to be on the safe side.
533 (copy-face 'underline
'idlwave-shell-disabled-bp
)
534 ;; We have the new customize - use it to define a customizable face
535 (defface idlwave-shell-disabled-bp
536 '((((class color
)) (:foreground
"Black" :background
"gray"))
538 "Face for highlighting lines with breakpoints."
539 :group
'idlwave-shell-highlighting-and-faces
))
542 (defcustom idlwave-shell-expression-face
'secondary-selection
543 "The face for `idlwave-shell-expression-overlay'.
544 Allows you to choose the font, color and other properties for
545 the expression printed by IDL."
546 :group
'idlwave-shell-highlighting-and-faces
549 (defcustom idlwave-shell-output-face
'secondary-selection
550 "The face for `idlwave-shell-output-overlay'.
551 Allows you to choose the font, color and other properties for
552 the expression output by IDL."
553 :group
'idlwave-shell-highlighting-and-faces
556 ;;; End user customization variables
558 ;;; External variables
559 (defvar comint-last-input-start
)
560 (defvar comint-last-input-end
)
563 (defvar idlwave-shell-temp-pro-file nil
564 "Absolute pathname for temporary IDL file for compiling regions")
566 (defvar idlwave-shell-temp-rinfo-save-file nil
567 "Absolute pathname for temporary IDL file save file for routine_info.
568 This is used to speed up the reloading of the routine info procedure
569 before use by the shell.")
571 (defun idlwave-shell-temp-file (type)
572 "Return a temp file, creating it if necessary.
574 TYPE is either 'pro' or 'rinfo', and `idlwave-shell-temp-pro-file' or
575 `idlwave-shell-temp-rinfo-save-file' is set (respectively)."
578 (or idlwave-shell-temp-rinfo-save-file
579 (setq idlwave-shell-temp-rinfo-save-file
580 (idlwave-shell-make-temp-file idlwave-shell-temp-pro-prefix
))))
582 (or idlwave-shell-temp-pro-file
583 (setq idlwave-shell-temp-pro-file
584 (idlwave-shell-make-temp-file idlwave-shell-temp-pro-prefix
))))
585 (t (error "Wrong argument (idlwave-shell-temp-file): %s"
586 (symbol-name type
)))))
589 (defun idlwave-shell-make-temp-file (prefix)
590 "Create a temporary file."
591 (if (featurep 'emacs
)
592 (make-temp-file prefix
)
593 (if (fboundp 'make-temp-file
)
594 (make-temp-file prefix
)
596 (temp-file-dir (if (boundp 'temporary-file-directory
)
597 temporary-file-directory
599 (while (condition-case ()
603 (expand-file-name prefix temp-file-dir
)))
604 (if (featurep 'xemacs
)
605 (write-region "" nil file nil
'silent nil
)
606 (write-region "" nil file nil
'silent nil
'excl
))
608 (file-already-exists t
))
609 ;; the file was somehow created by someone else between
610 ;; `make-temp-name' and `write-region', let's try again.
615 (defvar idlwave-shell-dirstack-query
"cd,current=___cur & print,___cur"
616 "Command used by `idlwave-shell-resync-dirs' to query IDL for
617 the directory stack.")
619 (defvar idlwave-shell-path-query
"print,'PATH:<'+transpose(expand_path(!PATH,/ARRAY))+'>' & print,'SYSDIR:<'+!dir+'>'"
621 "The command which gets !PATH and !DIR info from the shell.")
623 (defvar idlwave-shell-mode-line-info nil
624 "Additional info displayed in the mode line.")
626 (defvar idlwave-shell-default-directory nil
627 "The default directory in the idlwave-shell buffer, of outside use.")
629 (defvar idlwave-shell-last-save-and-action-file nil
630 "The last file which was compiled with `idlwave-shell-save-and-...'.")
632 ;; Highlighting uses overlays. When necessary, require the emulation.
633 (if (not (fboundp 'make-overlay
))
638 (defvar idlwave-shell-stop-line-overlay nil
639 "The overlay for where IDL is currently stopped.")
640 (defvar idlwave-shell-is-stopped nil
)
641 (defvar idlwave-shell-expression-overlay nil
642 "The overlay for the examined expression.")
643 (defvar idlwave-shell-output-overlay nil
644 "The overlay for the last IDL output.")
646 ;; If these were already overlays, delete them. This probably means that we
647 ;; are reloading this file.
648 (if (overlayp idlwave-shell-stop-line-overlay
)
649 (delete-overlay idlwave-shell-stop-line-overlay
))
650 (if (overlayp idlwave-shell-expression-overlay
)
651 (delete-overlay idlwave-shell-expression-overlay
))
652 (if (overlayp idlwave-shell-output-overlay
)
653 (delete-overlay idlwave-shell-output-overlay
))
655 ;; Set to nil initially
656 (setq idlwave-shell-stop-line-overlay nil
657 idlwave-shell-expression-overlay nil
658 idlwave-shell-output-overlay nil
)
660 ;; Define the shell stop overlay. When left nil, the arrow will be used.
662 ((or (null idlwave-shell-mark-stop-line
)
663 (eq idlwave-shell-mark-stop-line
'arrow
))
664 ;; Leave the overlay nil
667 ((eq idlwave-shell-mark-stop-line
'face
)
668 ;; Try to use a face. If not possible, arrow will be used anyway
669 ;; So who can display faces?
670 (when (or (featurep 'xemacs
) ; XEmacs can do also ttys
671 (fboundp 'tty-defined-colors
) ; Emacs 21 as well
672 window-system
) ; Window systems always
674 (setq idlwave-shell-stop-line-overlay
(make-overlay 1 1))
675 (overlay-put idlwave-shell-stop-line-overlay
676 'face idlwave-shell-stop-line-face
))))
679 ;; IDLWAVE may decide. Will use a face on window systems, arrow elsewhere
682 (setq idlwave-shell-stop-line-overlay
(make-overlay 1 1))
683 (overlay-put idlwave-shell-stop-line-overlay
684 'face idlwave-shell-stop-line-face
)))))
686 ;; Now the expression and output overlays
687 (setq idlwave-shell-expression-overlay
(make-overlay 1 1))
688 (overlay-put idlwave-shell-expression-overlay
689 'face idlwave-shell-expression-face
)
690 (overlay-put idlwave-shell-expression-overlay
692 (setq idlwave-shell-output-overlay
(make-overlay 1 1))
693 (overlay-put idlwave-shell-output-overlay
694 'face idlwave-shell-output-face
)
696 (copy-face idlwave-shell-stop-line-face
697 'idlwave-shell-pending-stop
)
698 (copy-face idlwave-shell-electric-stop-line-face
699 'idlwave-shell-pending-electric-stop
)
700 (set-face-background 'idlwave-shell-pending-stop
"gray70")
701 (set-face-background 'idlwave-shell-pending-electric-stop
"gray70")
705 (defvar idlwave-shell-bp-query
"help,/breakpoints"
706 "Command to obtain list of breakpoints.")
708 (defvar idlwave-shell-command-output nil
709 "String for accumulating current command output.")
711 (defvar idlwave-shell-post-command-hook nil
712 "Lisp list expression or function to run when an IDL command is finished.
713 The current command is finished when the IDL prompt is displayed.
714 This is evaluated if it is a list or called with funcall.")
716 (defvar idlwave-shell-sentinel-hook nil
717 "Hook run when the IDL process exits.")
719 (defvar idlwave-shell-hide-output nil
720 "If non-nil the process output is not inserted into the output buffer.")
722 (defvar idlwave-shell-show-if-error nil
723 "If non-nil the process output is inserted into the output buffer if
724 it contains an error message, even if hide-output is non-nil.")
726 (defvar idlwave-shell-accumulation nil
727 "Accumulate last line of output.")
729 (defvar idlwave-shell-command-line-to-execute nil
)
730 (defvar idlwave-shell-cleanup-hook nil
731 "List of functions to do cleanup when the shell exits.")
733 (defvar idlwave-shell-pending-commands nil
734 "List of commands to be sent to IDL.
735 Each element of the list is list of \(CMD PCMD HIDE), where CMD is a
736 string to be sent to IDL and PCMD is a post-command to be placed on
737 `idlwave-shell-post-command-hook'. If HIDE is non-nil, hide the output
738 from command CMD. PCMD and HIDE are optional.")
740 (defun idlwave-shell-buffer ()
741 "Name of buffer associated with IDL process.
742 The name of the buffer is made by surrounding `idlwave-shell-process-name'
744 (concat "*" idlwave-shell-process-name
"*"))
746 (defvar idlwave-shell-ready nil
747 "If non-nil can send next command to IDL process.")
749 ;;; The following are the types of messages we attempt to catch to
750 ;;; resync our idea of where IDL execution currently is.
753 (defvar idlwave-shell-halt-frame nil
754 "The frame associated with halt/breakpoint messages.")
756 (defvar idlwave-shell-step-frame nil
757 "The frame associated with step messages.")
759 (defvar idlwave-shell-trace-frame nil
760 "The frame associated with trace messages.")
762 (defconst idlwave-shell-halt-messages
763 '("^% Interrupted at:"
766 "^% Stop encountered:"
768 "A list of regular expressions matching IDL messages.
769 These are the messages containing file and line information where
770 IDL is currently stopped.")
773 (defconst idlwave-shell-halt-messages-re
774 (mapconcat 'identity idlwave-shell-halt-messages
"\\|")
775 "The regular expression computed from `idlwave-shell-halt-messages'.")
777 (defconst idlwave-shell-trace-message-re
778 "^% At " ;; First line of a trace message
779 "A regular expression matching IDL trace messages. These are the
780 messages containing file and line information of a current
783 (defconst idlwave-shell-step-messages
786 "A list of regular expressions matching stepped execution messages.
787 These are IDL messages containing file and line information where
788 IDL has currently stepped.")
790 (defvar idlwave-shell-break-message
"^% Breakpoint at:"
791 "Regular expression matching an IDL breakpoint message line.")
793 (defconst idlwave-shell-electric-debug-help
794 " ==> IDLWAVE Electric Debug Mode Help <==
796 Break Point Setting and Clearing:
797 b Set breakpoint ([C-u b] for conditional, [C-n b] nth hit, etc.).
798 d Clear nearby breakpoint.
799 a Clear all breakpoints.
800 i Set breakpoint in routine named here.
801 j Set breakpoint at beginning of containing routine.
802 \\ Toggle breakpoint disable
803 ] Go to next breakpoint in file.
804 [ Go to previous breakpoint in file.
806 Stepping, Continuing, and the Stack:
807 s or SPACE Step, into function calls.
808 n Step, over function calls.
809 k Skip one statement.
810 m Continue to end of function.
811 o Continue past end of function.
812 u Continue to end of block.
813 h Continue to line at cursor position.
814 r Continue execution to next breakpoint, if any.
815 + or = Show higher level in calling stack.
816 - or _ Show lower level in calling stack.
818 Examining Expressions (with prefix for examining the region):
819 p Print expression near point or in region ([C-u p]).
820 ? Help on expression near point or in region ([C-u ?]).
821 x Examine expression near point or in region ([C-u x]) with
822 letter completion of the examine type.
823 e Prompt for an expression to print.
826 q Quit - end debugging session and return to the Shell's main level.
827 v Turn Electric Debugging Mode off (C-c C-d C-v to return).
828 t Print a calling-level traceback in the shell.
830 C-? Show this help menu.")
832 (defvar idlwave-shell-bp-alist
)
833 ;(defvar idlwave-shell-post-command-output)
834 (defvar idlwave-shell-sources-alist
)
835 (defvar idlwave-shell-menu-def
)
836 (defvar idlwave-shell-mode-menu
)
837 (defvar idlwave-shell-initial-commands
)
838 (defvar idlwave-shell-syntax-error
)
839 (defvar idlwave-shell-other-error
)
840 (defvar idlwave-shell-error-buffer
)
841 (defvar idlwave-shell-error-last
)
842 (defvar idlwave-shell-bp-buffer
)
843 (defvar idlwave-shell-sources-query
)
844 (defvar idlwave-shell-mode-map
)
845 (defvar idlwave-shell-calling-stack-index
)
846 (defvar idlwave-shell-only-prompt-pattern nil
)
847 (defvar tool-bar-map
)
849 (define-derived-mode idlwave-shell-mode comint-mode
"IDL-Shell"
850 "Major mode for interacting with an inferior IDL process.
854 RET after the end of the process' output sends the text from the
855 end of process to the end of the current line. RET before end of
856 process output copies the current line (except for the prompt) to
857 the end of the buffer.
859 Command history, searching of previous commands, command line
860 editing are available via the comint-mode key bindings, by default
861 mostly on the key `C-c'. Command history is also available with
862 the arrow keys UP and DOWN.
866 TAB and M-TAB do completion of IDL routines, classes and keywords -
867 similar to M-TAB in `idlwave-mode'. In executive commands and
868 strings, it completes file names. Abbreviations are also expanded
869 like in `idlwave-mode'.
873 `\\[idlwave-routine-info]' displays information about an IDL routine near point,
874 just like in `idlwave-mode'. The module used is the one at point or
875 the one whose argument list is being edited.
876 To update IDLWAVE's knowledge about compiled or edited modules, use
877 \\[idlwave-update-routine-info].
878 \\[idlwave-find-module] find the source of a module.
879 \\[idlwave-resolve] tells IDL to compile an unresolved module.
880 \\[idlwave-context-help] shows the online help on the item at
881 point, if online help has been installed.
886 A complete set of commands for compiling and debugging IDL programs
887 is available from the menu. Also keybindings starting with a
888 `C-c C-d' prefix are available for most commands in the *idl* buffer
889 and also in source buffers. The best place to learn about the
890 keybindings is again the menu.
892 On Emacs versions where this is possible, a debugging toolbar is
895 When IDL is halted in the middle of a procedure, the corresponding
896 line of that procedure file is displayed with an overlay in another
897 window. Breakpoints are also highlighted in the source.
899 \\[idlwave-shell-resync-dirs] queries IDL in order to change Emacs current directory
900 to correspond to the IDL process current directory.
902 5. Expression Examination
903 ----------------------
905 Expressions near point can be examined with print,
906 \\[idlwave-shell-print] or \\[idlwave-shell-mouse-print] with the
907 mouse, help, \\[idlwave-shell-help-expression] or
908 \\[idlwave-shell-mouse-help] with the mouse, or with a
909 configurable set of custom examine commands using
910 \\[idlwave-shell-examine-select]. The mouse examine commands can
911 also work by click and drag, to select an expression for
916 Turning on `idlwave-shell-mode' runs `comint-mode-hook' and
917 `idlwave-shell-mode-hook' (in that order).
919 7. Documentation and Customization
920 -------------------------------
921 Info documentation for this package is available. Use \\[idlwave-info]
922 to display (complain to your sysadmin if that does not work).
923 For PostScript and HTML versions of the documentation, check IDLWAVE's
924 homepage at URL `http://github.com/jdtsmith/idlwave'.
925 IDLWAVE has customize support - see the group `idlwave'.
929 \\{idlwave-shell-mode-map}"
930 :abbrev-table idlwave-mode-abbrev-table
931 (idlwave-setup) ; Make sure config files and paths, etc. are available.
932 (unless (file-name-absolute-p idlwave-shell-command-history-file
)
933 (setq idlwave-shell-command-history-file
934 (expand-file-name idlwave-shell-command-history-file
935 idlwave-config-directory
)))
937 (setq comint-prompt-regexp idlwave-shell-prompt-pattern
)
938 (setq comint-process-echoes t
)
940 ;; Can not use history expansion because "!" is used for system variables.
941 (setq comint-input-autoexpand nil
)
942 ;; (setq comint-input-ring-size 64)
944 (set (make-local-variable 'completion-ignore-case
) t
)
945 (set (make-local-variable 'comint-completion-addsuffix
) '("/" .
""))
946 (setq comint-input-ignoredups t
)
947 (setq idlwave-shell-mode-line-info nil
)
948 (setq mode-line-format
951 mode-line-buffer-identification
960 idlwave-shell-mode-line-info
962 (line-number-mode "L%l--")
963 (column-number-mode "C%c--")
966 ;; (make-local-variable 'idlwave-shell-bp-alist)
967 (setq idlwave-shell-halt-frame nil
968 idlwave-shell-trace-frame nil
969 idlwave-shell-command-output nil
970 idlwave-shell-step-frame nil
)
971 (idlwave-shell-display-line nil
)
972 (setq idlwave-shell-calling-stack-index
0)
973 (setq idlwave-shell-only-prompt-pattern
974 (concat "\\`[ \t\n]*"
975 (substring idlwave-shell-prompt-pattern
1)
978 (when idlwave-shell-query-for-class
979 (add-to-list (make-local-variable 'idlwave-determine-class-special
)
980 'idlwave-shell-get-object-class
)
981 (setq idlwave-store-inquired-class t
))
983 ;; Make sure comint-last-input-end does not go to beginning of
984 ;; buffer (in case there were other processes already in this buffer).
985 (set-marker comint-last-input-end
(point))
986 (setq idlwave-idlwave_routine_info-compiled nil
)
987 (setq idlwave-shell-ready nil
)
988 (setq idlwave-shell-bp-alist nil
)
989 (idlwave-shell-update-bp-overlays) ; Throw away old overlays
990 (setq idlwave-shell-post-command-hook nil
;clean up any old stuff
991 idlwave-shell-sources-alist nil
)
992 (setq idlwave-shell-default-directory default-directory
)
993 (setq idlwave-shell-hide-output nil
)
995 ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
996 ;; (make-local-hook 'kill-buffer-hook)
997 (add-hook 'kill-buffer-hook
'idlwave-shell-kill-shell-buffer-confirm
999 (add-hook 'kill-buffer-hook
'idlwave-shell-delete-temp-files nil
'local
)
1000 (add-hook 'kill-emacs-hook
'idlwave-shell-delete-temp-files
)
1001 (easy-menu-add idlwave-shell-mode-menu idlwave-shell-mode-map
)
1003 ;; Set the optional comint variables
1004 (when idlwave-shell-comint-settings
1005 (let ((list idlwave-shell-comint-settings
) entry
)
1006 (while (setq entry
(pop list
))
1007 (set (make-local-variable (car entry
)) (cdr entry
)))))
1010 (unless (memq 'comint-carriage-motion
1011 (default-value 'comint-output-filter-functions
))
1012 ;; Strip those pesky ctrl-m's.
1013 (add-hook 'comint-output-filter-functions
1015 (when (string-match "\r" string
)
1016 (let ((pmark (process-mark (get-buffer-process
1017 (current-buffer)))))
1019 ;; bare CR -> delete preceding line
1020 (goto-char comint-last-output-start
)
1021 (while (search-forward "\r" pmark t
)
1022 (delete-region (point) (line-beginning-position)))))))
1024 (add-hook 'comint-output-filter-functions
'comint-strip-ctrl-m nil
'local
))
1026 ;; Python-mode, bundled with many Emacs installs, quite cavalierly
1027 ;; adds this function to the global default hook. It interferes
1028 ;; with overlay-arrows.
1029 (remove-hook 'comint-output-filter-functions
'py-pdbtrack-track-stack-file
)
1031 ;; IDLWAVE syntax, and turn on abbreviations
1032 (set (make-local-variable 'comment-start
) ";")
1033 (setq abbrev-mode t
)
1035 ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
1036 ;; make-local-hook 'post-command-hook)
1037 (add-hook 'post-command-hook
'idlwave-command-hook nil t
)
1039 ;; Read the command history?
1040 (when (and idlwave-shell-save-command-history
1041 (stringp idlwave-shell-command-history-file
))
1042 (set (make-local-variable 'comint-input-ring-file-name
)
1043 idlwave-shell-command-history-file
)
1044 (if (file-regular-p idlwave-shell-command-history-file
)
1045 (comint-read-input-ring)))
1047 ;; Turn off the non-debug toolbar buttons (open,save,etc.)
1048 (set (make-local-variable 'tool-bar-map
) nil
)
1050 (idlwave-shell-send-command idlwave-shell-initial-commands nil
'hide
)
1051 ;; Turn off IDL's ^d interpreting, and define a system
1052 ;; variable which knows the version of IDLWAVE
1053 (idlwave-shell-send-command
1054 (format "defsysv,'!idlwave_version','%s',1" idlwave-mode-version
)
1056 ;; Read the paths, and save if they changed
1057 (idlwave-shell-send-command idlwave-shell-path-query
1058 'idlwave-shell-get-path-info
1061 (defvar idlwave-system-directory
)
1062 (defun idlwave-shell-get-path-info (&optional no-write
)
1063 "Get the path lists, writing to file unless NO-WRITE is set."
1064 (let* ((rpl (idlwave-shell-path-filter))
1067 (old-path-alist idlwave-path-alist
)
1068 (old-sys-dir idlwave-system-directory
)
1069 path-changed sysdir-changed
)
1071 (setq idlwave-system-directory sysdir
)
1072 (if (setq sysdir-changed
1073 (not (string= idlwave-system-directory old-sys-dir
)))
1074 (put 'idlwave-system-directory
'from-shell t
)))
1075 ;; Preserve any existing flags
1076 (setq idlwave-path-alist
1078 (let ((old-entry (assoc x old-path-alist
)))
1080 (cons x
(cdr old-entry
))
1083 (if (setq path-changed
(not (equal idlwave-path-alist old-path-alist
)))
1084 (put 'idlwave-path-alist
'from-shell t
))
1085 (if idlwave-path-alist
1086 (if (and (not no-write
)
1087 idlwave-auto-write-paths
1088 (or sysdir-changed path-changed
)
1089 (not idlwave-library-path
))
1090 (idlwave-write-paths))
1092 (setq idlwave-path-alist old-path-alist
))))
1094 (if (not (fboundp 'idl-shell
))
1095 (fset 'idl-shell
'idlwave-shell
))
1097 (defvar idlwave-shell-idl-wframe nil
1098 "Frame for displaying the IDL shell window.")
1099 (defvar idlwave-shell-display-wframe nil
1100 "Frame for displaying the IDL source files.")
1102 (defvar idlwave-shell-calling-stack-index
0)
1103 (defvar idlwave-shell-calling-stack-routine nil
)
1105 (defun idlwave-shell-source-frame ()
1106 "Return the frame to be used for source display."
1107 (if idlwave-shell-use-dedicated-frame
1108 ;; We want separate frames for source and shell
1109 (if (frame-live-p idlwave-shell-display-wframe
)
1110 ;; The frame exists, so we use it.
1111 idlwave-shell-display-wframe
1112 ;; The frame does not exist. We use the current frame.
1113 ;; However, if the current is the shell frame, we make a new frame,
1114 ;; or recycle the first existing visible frame
1115 (setq idlwave-shell-display-wframe
1116 (if (eq (selected-frame) idlwave-shell-idl-wframe
)
1118 (let ((flist (visible-frame-list))
1119 (frame (selected-frame)))
1122 (if (not (eq (car flist
)
1123 idlwave-shell-idl-wframe
))
1124 (throw 'exit
(car flist
))
1125 (setq flist
(cdr flist
))))))
1127 (selected-frame))))))
1129 (defun idlwave-shell-shell-frame ()
1130 "Return the frame to be used for the shell buffer."
1131 (if idlwave-shell-use-dedicated-frame
1132 ;; We want a dedicated frame
1133 (if (frame-live-p idlwave-shell-idl-wframe
)
1134 ;; It does exist, so we use it.
1135 idlwave-shell-idl-wframe
1136 ;; It does not exist. Check if we have a source frame.
1137 (if (not (frame-live-p idlwave-shell-display-wframe
))
1138 ;; We do not have a source frame, so we use this one.
1139 (setq idlwave-shell-display-wframe
(selected-frame)))
1140 ;; Return a new frame
1141 (setq idlwave-shell-idl-wframe
1142 (make-frame idlwave-shell-frame-parameters
)))))
1145 (defun idlwave-shell (&optional arg quick
)
1146 "Run an inferior IDL, with I/O through buffer `(idlwave-shell-buffer)'.
1147 If buffer exists but shell process is not running, start new IDL.
1148 If buffer exists and shell process is running, just switch to the buffer.
1150 When called with a prefix ARG, or when `idlwave-shell-use-dedicated-frame'
1151 is non-nil, the shell buffer and the source buffers will be in
1154 The command to run comes from variable `idlwave-shell-explicit-file-name',
1155 with options taken from `idlwave-shell-command-line-options'.
1157 The buffer is put in `idlwave-shell-mode', providing commands for sending
1158 input and controlling the IDL job. See help on `idlwave-shell-mode'.
1159 See also the variable `idlwave-shell-prompt-pattern'.
1161 \(Type \\[describe-mode] in the shell buffer for a list of commands.)"
1165 (let ((idlwave-shell-use-dedicated-frame nil
))
1167 (delete-other-windows))
1168 (and idlwave-shell-use-dedicated-frame
1169 (setq idlwave-shell-idl-wframe
(selected-frame)))
1170 (add-hook 'idlwave-shell-sentinel-hook
1171 'save-buffers-kill-emacs t
))
1173 ;; A non-nil arg means, we want a dedicated frame. This will last
1174 ;; for the current editing session.
1175 (if arg
(setq idlwave-shell-use-dedicated-frame t
))
1176 (if (equal arg
'(16)) (setq idlwave-shell-use-dedicated-frame nil
))
1178 ;; Check if the process still exists. If not, create it.
1179 (unless (comint-check-proc (idlwave-shell-buffer))
1180 (let* ((prg (or idlwave-shell-explicit-file-name
"idl"))
1181 (buf (apply 'make-comint
1182 idlwave-shell-process-name prg nil
1183 (if (stringp idlwave-shell-command-line-options
)
1184 (idlwave-split-string
1185 idlwave-shell-command-line-options
)
1186 idlwave-shell-command-line-options
)))
1187 (process (get-buffer-process buf
)))
1188 (setq idlwave-idlwave_routine_info-compiled nil
)
1189 (set-process-filter process
'idlwave-shell-filter
)
1190 (set-process-sentinel process
'idlwave-shell-sentinel
)
1192 (idlwave-shell-mode)))
1193 (let ((window (idlwave-display-buffer (idlwave-shell-buffer) nil
1194 (idlwave-shell-shell-frame)))
1195 (current-window (selected-window)))
1196 (select-window window
)
1197 (goto-char (point-max))
1198 (if idlwave-shell-use-dedicated-window
1199 (set-window-dedicated-p window t
))
1200 (select-window current-window
)
1201 (if idlwave-shell-ready
1202 (raise-frame (window-frame window
)))
1203 (if (eq (selected-frame) (window-frame window
))
1204 (select-window window
))))
1205 ;; Save the paths at the end, if they are from the Shell and new.
1206 (add-hook 'idlwave-shell-sentinel-hook
1209 idlwave-auto-write-paths
1211 (not idlwave-library-path
)
1212 (get 'idlwave-path-alist
'from-shell
))
1213 (idlwave-write-paths)))))
1215 (defun idlwave-shell-recenter-shell-window (&optional arg
)
1216 "Run `idlwave-shell', but make sure the current window stays selected."
1218 (let ((window (selected-window)))
1220 (select-window window
)))
1222 (defun idlwave-shell-hide-p (type &optional list
)
1223 "Whether to hide this type of command.
1224 Return either nil or 'hide."
1225 (let ((list (or list idlwave-shell-show-commands
)))
1227 (if (not (memq type list
)) 'hide
))))
1229 (defun idlwave-shell-add-or-remove-show (type)
1230 "Add or remove a show command from the list."
1231 (if (listp idlwave-shell-show-commands
)
1232 (setq idlwave-shell-show-commands
1233 (if (memq type idlwave-shell-show-commands
)
1234 (delq type idlwave-shell-show-commands
)
1235 (add-to-list'idlwave-shell-show-commands type
)))
1236 (setq idlwave-shell-show-commands
(list type
))))
1239 (defun idlwave-shell-send-command (&optional cmd pcmd hide preempt
1241 "Send a command to IDL process.
1243 \(CMD PCMD HIDE) are placed at the end of `idlwave-shell-pending-commands'.
1244 If IDL is ready the first command in `idlwave-shell-pending-commands',
1245 CMD, is sent to the IDL process.
1247 If optional second argument PCMD is non-nil it will be placed on
1248 `idlwave-shell-post-command-hook' when CMD is executed.
1250 If the optional third argument HIDE is non-nil, then hide output from
1251 CMD, unless it is the symbol 'mostly, in which case only output
1252 beginning with \"%\" is hidden, and all other output (i.e., the
1253 results of a PRINT command), is shown. This helps with, e.g.,
1254 stepping through code with output.
1256 If optional fourth argument PREEMPT is non-nil CMD is put at front of
1257 `idlwave-shell-pending-commands'. If PREEMPT is 'wait, wait for all
1258 output to complete and the next prompt to arrive before returning
1259 \(useful if you need an answer now). IDL is considered ready if the
1260 prompt is present and if `idlwave-shell-ready' is non-nil.
1262 If SHOW-IF-ERROR is non-nil, show the output if it contains an error
1263 message, independent of what HIDE is set to."
1265 ; (setq hide nil) ; FIXME: turn this on for debugging only
1268 ; (message "SENDING Pending commands: %s"
1269 ; (prin1-to-string idlwave-shell-pending-commands)))
1270 ; (message "SENDING %s|||%s" cmd pcmd))
1271 (if (and (symbolp idlwave-shell-show-commands
)
1272 (eq idlwave-shell-show-commands
'everything
))
1274 (let ((save-buffer (current-buffer))
1276 ;; Get or make the buffer and its process
1277 (if (or (not (setq buf
(get-buffer (idlwave-shell-buffer))))
1278 (not (setq proc
(get-buffer-process buf
))))
1279 (if (not idlwave-shell-automatic-start
)
1281 (substitute-command-keys
1282 "You need to first start an IDL shell with \\[idlwave-shell]"))
1283 (idlwave-shell-recenter-shell-window)
1284 (setq buf
(get-buffer (idlwave-shell-buffer)))
1285 (if (or (not (setq buf
(get-buffer (idlwave-shell-buffer))))
1286 (not (setq proc
(get-buffer-process buf
))))
1288 (error "Problem with autostarting IDL shell"))))
1289 (when (or cmd idlwave-shell-pending-commands
)
1291 ;; To make this easy, always push CMD onto pending commands
1293 (setq idlwave-shell-pending-commands
1296 (append (list (list cmd pcmd hide show-if-error
))
1297 idlwave-shell-pending-commands
)
1299 (append idlwave-shell-pending-commands
1300 (list (list cmd pcmd hide show-if-error
))))))
1301 ;; Check if IDL ready
1302 (let ((save-point (point-marker)))
1303 (goto-char (process-mark proc
))
1304 (if (and idlwave-shell-ready
1305 ;; Check for IDL prompt
1308 ;; (beginning-of-line) ; Changed for Emacs 21
1309 (looking-at idlwave-shell-prompt-pattern
)
1310 (goto-char (process-mark proc
))))
1311 ;; IDL ready for command, execute it
1312 (let* ((lcmd (car idlwave-shell-pending-commands
))
1316 (show-if-error (nth 3 lcmd
)))
1317 ;; If this is an executive command, reset the stack pointer
1318 (if (eq (string-to-char cmd
) ?.
)
1319 (setq idlwave-shell-calling-stack-index
0))
1321 (setq idlwave-shell-post-command-hook pcmd
)
1323 (setq idlwave-shell-hide-output hide
)
1325 (setq idlwave-shell-show-if-error show-if-error
)
1327 (setq idlwave-shell-pending-commands
1328 (cdr idlwave-shell-pending-commands
))
1329 ;; Send command for execution
1330 (set-marker comint-last-input-start
(point))
1331 (set-marker comint-last-input-end
(point))
1332 (comint-simple-send proc cmd
)
1333 (setq idlwave-shell-ready nil
)
1334 (if (equal preempt
'wait
) ; Get all the output at once
1335 (while (not idlwave-shell-ready
)
1336 (when (not (accept-process-output proc
6)) ; long wait
1337 (setq idlwave-shell-pending-commands nil
)
1338 (error "Process timed out"))))))
1339 (goto-char save-point
))
1340 (set-buffer save-buffer
))))
1342 (defun idlwave-shell-send-char (c &optional error
)
1343 "Send one character to the shell, without a newline."
1344 (interactive "cChar to send to IDL: \np")
1345 (let ((errf (if error
'error
'message
))
1347 (if (or (not (setq buf
(get-buffer (idlwave-shell-buffer))))
1348 (not (setq proc
(get-buffer-process buf
))))
1349 (funcall errf
"Shell is not running"))
1351 (funcall errf
"Abort")
1352 (comint-send-string proc
(char-to-string c
)))))
1354 (defvar idlwave-shell-char-mode-active
)
1355 (defun idlwave-shell-input-mode-magic (string)
1356 "Check STRING for magic words and toggle character input mode.
1357 See also the variable `idlwave-shell-input-mode-spells'."
1359 ((string-match (car idlwave-shell-input-mode-spells
) string
)
1360 (call-interactively 'idlwave-shell-send-char
))
1361 ((and (boundp 'idlwave-shell-char-mode-active
)
1362 (string-match (nth 2 idlwave-shell-input-mode-spells
) string
))
1363 (setq idlwave-shell-char-mode-active
'exit
))
1364 ((string-match (nth 1 idlwave-shell-input-mode-spells
) string
)
1365 ;; Set a timer which will soon start the character loop
1366 (if (fboundp 'start-itimer
)
1367 (start-itimer "IDLWAVE Char Mode" 'idlwave-shell-char-mode-loop
0.5
1368 nil nil t
'no-error
)
1369 (run-at-time 0.5 nil
'idlwave-shell-char-mode-loop
'no-error
)))))
1371 (defvar keyboard-quit
)
1372 (defun idlwave-shell-char-mode-loop (&optional no-error
)
1373 "Enter a loop which accepts single characters and sends them to IDL.
1374 Characters are sent one by one, without newlines. The loop is blocking
1375 and intercepts all input events to Emacs. You can use this command
1376 to interact with the IDL command GET_KBRD.
1377 The loop can be aborted by typing `C-g'. The loop also exits automatically
1378 when the IDL prompt gets displayed again after the current IDL command."
1381 ;; First check if there is a shell waiting for input
1382 (let ((idlwave-shell-char-mode-active t
)
1383 (errf (if no-error
'message
'error
))
1385 (if (or (not (setq buf
(get-buffer (idlwave-shell-buffer))))
1386 (not (setq proc
(get-buffer-process buf
))))
1387 (funcall errf
"Shell is not running"))
1388 (if idlwave-shell-ready
1389 (funcall errf
"No IDL program seems to be waiting for input"))
1391 ;; OK, start the loop
1392 (message "Character mode on: Sending single chars (`C-g' to exit)")
1397 ;; FIXME: Is it too dangerous to inhibit quit here?
1398 (let ((inhibit-quit t
))
1399 ;; We wait and check frequently if we should abort
1400 (while (sit-for 0.3)
1401 (and idlwave-shell-ready
1402 (throw 'exit
"Character mode off (prompt displayed)"))
1403 (and (eq idlwave-shell-char-mode-active
'exit
)
1404 (throw 'exit
"Character mode off (closing spell incantation)")))
1405 ;; Interpret input as a character - ignore non-char input
1407 (setq c
(read-char))
1408 (error (ding) (throw 'exit
"Character mode off")))
1410 ((null c
) ; Non-char event: ignore
1412 ((equal c ?\C-g
) ; Abort the loop
1413 (setq keyboard-quit nil
)
1415 (throw 'exit
"Character mode off (keyboard quit)"))
1416 (t ; Send the character and continue the loop
1417 (comint-send-string proc
(char-to-string c
))))
1418 (and (eq idlwave-shell-char-mode-active
'exit
)
1419 (throw 'exit
"Single char loop exited"))))))))
1421 (defun idlwave-shell-move-or-history (up &optional arg
)
1422 "When in last line of process buffer, do `comint-previous-input'.
1423 Otherwise just move the line. Move down unless UP is non-nil."
1424 (let* ((proc-pos (marker-position
1425 (process-mark (get-buffer-process (current-buffer)))))
1427 (arg (if up arg
(- arg
))))
1428 (if (eq t idlwave-shell-arrows-do-history
) (goto-char proc-pos
))
1429 (if (and idlwave-shell-arrows-do-history
1430 (>= (1+ (point-at-eol)) proc-pos
))
1431 (comint-previous-input arg
)
1432 (forward-line (- arg
)))))
1434 (defun idlwave-shell-up-or-history (&optional arg
)
1435 "When in last line of process buffer, move to previous input.
1436 Otherwise just go up one line."
1438 (idlwave-shell-move-or-history t arg
))
1440 (defun idlwave-shell-down-or-history (&optional arg
)
1441 "When in last line of process buffer, move to next input.
1442 Otherwise just go down one line."
1444 (idlwave-shell-move-or-history nil arg
))
1446 (define-obsolete-function-alias 'idlwave-shell-comint-filter
1447 'comint-output-filter
"25.1")
1449 (defun idlwave-shell-is-running ()
1450 "Return t if the shell process is running."
1451 (eq (process-status idlwave-shell-process-name
) 'run
))
1453 (defun idlwave-shell-filter-hidden-output (output)
1454 "Filter hidden output, leaving the good stuff.
1456 Remove everything to the first newline, and all lines with % in front
1457 of them, with optional follow-on lines starting with two spaces. This
1458 works well enough, since any print output typically arrives before
1459 error messages, etc."
1460 (setq output
(substring output
(string-match "\n" output
)))
1461 (while (string-match "\\(\n\\|\\`\\)%.*\\(\n .*\\)*" output
)
1462 (setq output
(replace-match "" nil t output
)))
1464 (string-match idlwave-shell-only-prompt-pattern output
)
1467 (defvar idlwave-shell-hidden-output-buffer
" *idlwave-shell-hidden-output*"
1468 "Buffer containing hidden output from IDL commands.")
1469 (defvar idlwave-shell-current-state nil
)
1471 (defun idlwave-shell-filter (proc string
)
1472 "Watch for IDL prompt and filter incoming text.
1473 When the IDL prompt is received executes `idlwave-shell-post-command-hook'
1474 and then calls `idlwave-shell-send-command' for any pending commands."
1475 ;; We no longer do the cleanup here - this is done by the process sentinel
1476 (if (eq (process-status idlwave-shell-process-name
) 'run
)
1477 ;; OK, process is still running, so we can use it.
1478 (let ((data (match-data)) p full-output
)
1481 ;; Ring the bell if necessary
1482 (while (setq p
(string-match "\C-G" string
))
1484 (aset string p ?\C-j
))
1485 (if idlwave-shell-hide-output
1487 (while (setq p
(string-match "\C-M" string
))
1488 (aset string p ?\
))
1490 (get-buffer-create idlwave-shell-hidden-output-buffer
))
1491 (goto-char (point-max))
1493 (comint-output-filter proc string
))
1494 ;; Watch for magic - need to accumulate the current line
1495 ;; since it may not be sent all at once.
1496 (if (string-match "\n" string
)
1498 (if idlwave-shell-use-input-mode-magic
1499 (idlwave-shell-input-mode-magic
1500 (concat idlwave-shell-accumulation string
)))
1501 (setq idlwave-shell-accumulation
1503 (progn (string-match "\\(.*[\n\r]+\\)*"
1506 (setq idlwave-shell-accumulation
1507 (concat idlwave-shell-accumulation string
)))
1510 ;; ;; Test/Debug code
1511 ;;(with-current-buffer
1512 ;; (get-buffer-create "*idlwave-shell-output*")
1513 ;; (goto-char (point-max))
1514 ;; (insert "\nReceived STRING\n===>\n" string "\n<====\n"))
1516 ;; Check for prompt in current accumulating output
1517 (when (setq idlwave-shell-ready
1518 (string-match idlwave-shell-prompt-pattern
1519 idlwave-shell-accumulation
))
1520 ;; Gather the command output
1521 (if idlwave-shell-hide-output
1522 (with-current-buffer idlwave-shell-hidden-output-buffer
1523 (setq full-output
(buffer-string))
1524 (goto-char (point-max))
1525 (re-search-backward idlwave-shell-prompt-pattern nil t
)
1526 (goto-char (match-end 0))
1527 (setq idlwave-shell-command-output
1528 (buffer-substring-no-properties
1529 (point-min) (point)))
1530 (delete-region (point-min) (point)))
1531 (setq idlwave-shell-command-output
1532 (with-current-buffer (process-buffer proc
)
1533 (buffer-substring-no-properties
1535 (goto-char (process-mark proc
))
1536 (forward-line 0) ; Emacs 21 (beginning-of-line nil)
1538 comint-last-input-end
))))
1540 ;; Scan for state and do post commands - bracket
1541 ;; them with idlwave-shell-ready=nil since they may
1542 ;; call idlwave-shell-send-command themselves.
1543 (let ((idlwave-shell-ready nil
))
1544 (idlwave-shell-scan-for-state)
1545 ;; Show the output in the shell if it contains an error
1546 (if idlwave-shell-hide-output
1547 (if (and idlwave-shell-show-if-error
1548 (eq idlwave-shell-current-state
'error
))
1549 (comint-output-filter proc full-output
)
1550 ;; If it's only *mostly* hidden, filter % lines,
1551 ;; and show anything that remains
1552 (if (eq idlwave-shell-hide-output
'mostly
)
1554 (idlwave-shell-filter-hidden-output
1557 (comint-output-filter
1560 ;; Call the post-command hook
1561 (if (listp idlwave-shell-post-command-hook
)
1563 ;;(message "Calling list")
1564 ;;(prin1 idlwave-shell-post-command-hook)
1565 (eval idlwave-shell-post-command-hook
))
1566 ;;(message "Calling command function")
1567 (funcall idlwave-shell-post-command-hook
))
1569 ;; Reset to default state for next command.
1570 ;; Also we do not want to find this prompt again.
1571 (setq idlwave-shell-accumulation nil
1572 idlwave-shell-command-output nil
1573 idlwave-shell-post-command-hook nil
1574 idlwave-shell-hide-output nil
1575 idlwave-shell-show-if-error nil
))
1576 ;; Done with post command. Do pending command if
1578 (idlwave-shell-send-command)))
1579 (store-match-data data
)))))
1581 (defun idlwave-shell-sentinel (process event
)
1582 "The sentinel function for the IDLWAVE shell process."
1583 (let* ((buf (idlwave-shell-buffer))
1584 (win (get-buffer-window buf
)))
1585 (when (get-buffer buf
)
1586 (with-current-buffer (idlwave-shell-buffer)
1587 (goto-char (point-max))
1588 (insert (format "\n\n Process %s %s" process event
))
1589 (if (and idlwave-shell-save-command-history
1590 (stringp idlwave-shell-command-history-file
))
1592 (comint-write-input-ring)
1595 (when (and (> (length (frame-list)) 1)
1596 (frame-live-p idlwave-shell-idl-wframe
))
1597 (delete-frame idlwave-shell-idl-wframe
)
1598 (setq idlwave-shell-idl-wframe nil
1599 idlwave-shell-display-wframe nil
))
1600 (when (and (window-live-p win
)
1601 (not (one-window-p 'nomini
)))
1602 (delete-window win
))
1603 (idlwave-shell-cleanup)
1604 ;; Run the hook, if possible in the shell buffer.
1605 (if (get-buffer buf
)
1606 (with-current-buffer buf
1607 (run-hooks 'idlwave-shell-sentinel-hook
))
1608 (run-hooks 'idlwave-shell-sentinel-hook
))))
1610 (defvar idlwave-shell-error-buffer
" *idlwave-shell-errors*"
1611 "Buffer containing syntax errors from IDL compilations.")
1613 ;; FIXME: the following two variables do not currently allow line breaks
1614 ;; in module and file names. I am not sure if it will be necessary to
1615 ;; change this. Currently it seems to work the way it is.
1616 (defvar idlwave-shell-syntax-error
1617 "^% Syntax error.\\s-*\n\\s-*At:\\s-*\\(.*\\),\\s-*Line\\s-*\\(.*\\)"
1618 "A regular expression to match an IDL syntax error.
1619 The first pair matches the file name, the second pair matches the line
1622 (defvar idlwave-shell-other-error
1623 "^% .*\n\\s-*At:\\s-*\\(.*\\),\\s-*Line\\s-*\\(.*\\)"
1624 "A regular expression to match any IDL error.")
1626 (defvar idlwave-shell-halting-error
1627 "^% .*\n\\([^%].*\n\\)*% Execution halted at:\\(\\s-*\\S-+\\s-*[0-9]+\\s-*.*\\)\n"
1628 "A regular expression to match errors which halt execution.")
1630 (defvar idlwave-shell-cant-continue-error
1631 "^% Can't continue from this point.\n"
1632 "A regular expression to match errors stepping errors.")
1634 (defvar idlwave-shell-file-line-message
1636 "\\(" ; program name group (1)
1637 "\\$MAIN\\$\\|" ; main level routine
1638 "\\<[a-zA-Z][a-zA-Z0-9_$:]*" ; start with a letter followed by [..]
1639 "\\([ \t]*\n[ \t]*[a-zA-Z0-9_$:]+\\)*"; continuation lines program name (2)
1640 "\\)" ; end program name group (1)
1641 "[ \t\n]+" ; white space
1642 "\\(" ; line number group (3)
1643 "[0-9]+" ; the line number (the fix point)
1644 "\\([ \t]*\n[ \t]*[0-9]+\\)*" ; continuation lines number (4)
1645 "\\)" ; end line number group (3)
1646 "[ \t\n]+" ; white space
1647 "\\(" ; file name group (5)
1648 "[^ \t\n]+" ; file names can contain any non-white
1649 "\\([ \t]*\n[ \t]*[^ \t\n]+\\)*" ; continuation lines file name (6)
1650 "\\)" ; end line number group (5)
1652 "A regular expression to parse out the file name and line number.
1653 The 1st group should match the subroutine name.
1654 The 3rd group is the line number.
1655 The 5th group is the file name.
1656 All parts may contain linebreaks surrounded by spaces. This is important
1657 in IDL5 which inserts random linebreaks in long module and file names.")
1659 (defvar idlwave-shell-electric-debug-mode
) ; defined by easy-mmode
1661 (defun idlwave-shell-scan-for-state ()
1662 "Scan for state info.
1663 Looks for messages in output from last IDL command indicating where
1664 IDL has stopped. The types of messages we are interested in are
1665 execution halted, stepped, breakpoint, interrupted at and trace
1666 messages. For breakpoint messages process any attached count or
1667 command parameters. Update the stop line if a message is found.
1668 The variable `idlwave-shell-current-state' is set to 'error, 'halt,
1669 or 'breakpoint, which describes the status, or nil for none of
1673 ;; Make sure we have output
1674 ((not idlwave-shell-command-output
))
1676 ;; First Priority: Syntax and other errors
1678 (string-match idlwave-shell-syntax-error
1679 idlwave-shell-command-output
)
1680 (string-match idlwave-shell-other-error
1681 idlwave-shell-command-output
))
1682 (with-current-buffer
1683 (get-buffer-create idlwave-shell-error-buffer
)
1685 (insert idlwave-shell-command-output
)
1686 (goto-char (point-min))
1687 (setq idlwave-shell-error-last
(point)))
1688 (setq idlwave-shell-current-state
'error
)
1689 (idlwave-shell-goto-next-error))
1691 ;; Second Priority: Halting errors
1692 ((string-match idlwave-shell-halting-error
1693 idlwave-shell-command-output
)
1694 ;; Grab the file and line state info.
1695 (setq idlwave-shell-calling-stack-index
0)
1696 (setq idlwave-shell-halt-frame
1697 (idlwave-shell-parse-line
1698 (substring idlwave-shell-command-output
1699 (match-beginning 2)))
1700 idlwave-shell-current-state
'error
)
1701 (idlwave-shell-display-line (idlwave-shell-pc-frame)))
1703 ;; Third Priority: Various types of innocuous HALT and
1704 ;; TRACEBACK messages.
1705 ((or (setq trace
(string-match idlwave-shell-trace-message-re
1706 idlwave-shell-command-output
))
1707 (string-match idlwave-shell-halt-messages-re
1708 idlwave-shell-command-output
))
1709 ;; Grab the file and line state info.
1710 (setq idlwave-shell-calling-stack-index
0)
1711 (setq idlwave-shell-halt-frame
1712 (idlwave-shell-parse-line
1713 (substring idlwave-shell-command-output
(match-end 0))))
1714 (setq idlwave-shell-current-state
'halt
)
1715 ;; Don't debug trace messages
1716 (idlwave-shell-display-line
1717 (idlwave-shell-pc-frame) nil
1719 (if idlwave-shell-electric-debug-mode
'force
))))
1721 ;; Fourth Priority: Breakpoints
1722 ((string-match idlwave-shell-break-message
1723 idlwave-shell-command-output
)
1724 (setq idlwave-shell-calling-stack-index
0)
1725 (setq idlwave-shell-halt-frame
1726 (idlwave-shell-parse-line
1727 (substring idlwave-shell-command-output
(match-end 0))))
1728 ;; We used to count hits on breakpoints
1729 ;; this is no longer supported since IDL breakpoints
1730 ;; have learned counting.
1731 ;; Do breakpoint command processing
1734 (nth 0 idlwave-shell-halt-frame
)
1735 (nth 1 idlwave-shell-halt-frame
))
1736 idlwave-shell-bp-alist
)))
1737 ;(message "Scanning with %s" bp)
1739 (let ((cmd (idlwave-shell-bp-get bp
'cmd
)))
1740 (if cmd
;; Execute any breakpoint command
1741 (if (listp cmd
) (eval cmd
) (funcall cmd
))))
1742 ;; A breakpoint that we did not know about - perhaps it was
1743 ;; set by the user... Let's update our list.
1744 (idlwave-shell-bp-query)))
1745 (setq idlwave-shell-current-state
'breakpoint
)
1746 (idlwave-shell-display-line (idlwave-shell-pc-frame)))
1748 ;; Last Priority: Can't Step errors
1749 ((string-match idlwave-shell-cant-continue-error
1750 idlwave-shell-command-output
)
1751 (setq idlwave-shell-current-state
'breakpoint
))
1753 ;; Otherwise, no particular state
1754 (t (setq idlwave-shell-current-state nil
)))))
1757 (defun idlwave-shell-parse-line (string &optional skip-main
)
1758 "Parse IDL message for the subroutine, file name and line number."
1759 ;We need to work hard here to remove the stupid line breaks inserted by
1760 ;IDL5. These line breaks can be right in the middle of procedure
1762 ;It is very difficult to come up with a robust solution. This one seems
1763 ;to be pretty good though.
1765 ;Here is in what ways it improves over the previous solution:
1767 ;1. The procedure name can be split and will be restored.
1768 ;2. The number can be split. I have never seen this, but who knows.
1769 ;3. We do not require the `.pro' extension for files.
1771 ;This function can still break when the file name ends on an end line
1772 ;and the message line contains an additional line with garbage. Then
1773 ;the first part of that garbage will be added to the file name.
1774 ;However, the function checks the existence of the files with and
1775 ;without this last part - thus the function only breaks if file name
1776 ;plus garbage match an existing regular file. This is hopefully very
1779 ;If optional arg SKIP-MAIN is non-nil, don't parse $MAIN$ routine stop
1782 (let (number procedure file
)
1783 (when (and (not (if skip-main
(string-match ":\\s-*\\$MAIN" string
)))
1784 (string-match idlwave-shell-file-line-message string
))
1785 (setq procedure
(match-string 1 string
)
1786 number
(match-string 3 string
)
1787 file
(match-string 5 string
))
1789 ;; Repair the strings
1790 (setq procedure
(idlwave-shell-repair-string procedure
))
1791 (setq number
(idlwave-shell-repair-string number
))
1792 (setq file
(idlwave-shell-repair-file-name file
))
1794 ;; If we have a file, return the frame list
1796 (list (idlwave-shell-file-name file
)
1797 (string-to-number number
)
1799 ;; No success finding a file
1802 (defun idlwave-shell-repair-string (string)
1803 "Repair a string by taking out all linebreaks. This is destructive!"
1804 (while (string-match "[ \t]*\n[ \t]*" string
)
1805 (setq string
(replace-match "" t t string
)))
1808 (defun idlwave-shell-repair-file-name (file)
1809 "Repair a file name string by taking out all linebreaks.
1810 The last line of STRING may be garbage - we check which one makes a valid
1812 (let ((file1 "") (file2 "") (start 0))
1813 ;; We scan no further than to the next "^%" line
1814 (if (string-match "^%" file
)
1815 (setq file
(substring file
0 (match-beginning 0))))
1816 ;; Take out the line breaks
1817 (while (string-match "[ \t]*\n[ \t]*" file start
)
1818 (setq file1
(concat file1
(substring file start
(match-beginning 0)))
1819 start
(match-end 0)))
1820 (setq file2
(concat file1
(substring file start
)))
1822 ((file-regular-p file2
) file2
)
1823 ((file-regular-p file1
) file1
)
1824 ;; If we cannot verify the existence of the file, we return the shorter
1825 ;; name. The idea behind this is that this may be a relative file name
1826 ;; and our idea about the current working directory may be wrong.
1827 ;; If it is a relative file name, it hopefully is short.
1828 ((not (string= "" file1
)) file1
)
1829 ((not (string= "" file2
)) file2
)
1832 (defun idlwave-shell-cleanup ()
1833 "Do necessary cleanup for a terminated IDL process."
1834 (setq idlwave-shell-step-frame nil
1835 idlwave-shell-halt-frame nil
1836 idlwave-shell-pending-commands nil
1837 idlwave-shell-command-line-to-execute nil
1838 idlwave-shell-bp-alist nil
1839 idlwave-shell-calling-stack-index
0
1840 idlwave-idlwave_routine_info-compiled nil
)
1841 (idlwave-shell-delete-temp-files)
1842 (idlwave-shell-display-line nil
)
1843 (idlwave-shell-update-bp-overlays) ; kill old overlays
1844 (idlwave-shell-kill-buffer idlwave-shell-hidden-output-buffer
)
1845 (idlwave-shell-kill-buffer idlwave-shell-bp-buffer
)
1846 (idlwave-shell-kill-buffer idlwave-shell-error-buffer
)
1847 ;; (idlwave-shell-kill-buffer (idlwave-shell-buffer))
1848 (and (get-buffer (idlwave-shell-buffer))
1849 (bury-buffer (get-buffer (idlwave-shell-buffer))))
1850 (run-hooks 'idlwave-shell-cleanup-hook
))
1852 (defun idlwave-shell-kill-buffer (buf)
1853 "Kill buffer BUF if it exists."
1854 (if (setq buf
(get-buffer buf
))
1857 (defun idlwave-shell-kill-shell-buffer-confirm ()
1858 (when (idlwave-shell-is-running)
1860 (unless (y-or-n-p "IDL shell is running. Are you sure you want to kill the buffer? ")
1862 (message "Killing buffer *idl* and the associated process")))
1864 (defun idlwave-shell-window (n)
1865 "Issue a `window,N' command to IDL, with special window size.
1866 The size is given by `idlwave-shell-graphics-window-size'."
1868 (let ((n (if n
(prefix-numeric-value n
) 0)))
1869 (idlwave-shell-send-command
1870 (apply 'format
"window,%d,xs=%d,ys=%d"
1871 n idlwave-shell-graphics-window-size
)
1872 nil
(idlwave-shell-hide-p 'misc
) nil t
)))
1874 (defun idlwave-shell-resync-dirs ()
1875 "Resync the buffer's idea of the current directory.
1876 This command queries IDL with the command bound to
1877 `idlwave-shell-dirstack-query', reads the output for the new
1880 (idlwave-shell-send-command idlwave-shell-dirstack-query
1881 'idlwave-shell-filter-directory
1884 (defun idlwave-shell-retall (&optional arg
)
1885 "Return from the entire calling stack.
1886 Also get rid of widget events in the queue."
1888 (save-selected-window
1889 ;;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 &
1890 (idlwave-shell-send-command "retall" nil
1891 (if (idlwave-shell-hide-p 'misc
) 'mostly
)
1893 (idlwave-shell-display-line nil
)))
1895 (defun idlwave-shell-closeall (&optional arg
)
1896 "Close all open files."
1898 (idlwave-shell-send-command "close,/all" nil
1899 (idlwave-shell-hide-p 'misc
) nil t
))
1901 (defun idlwave-shell-quit (&optional arg
)
1902 "Exit the IDL process after confirmation.
1903 With prefix ARG, exit without confirmation."
1905 (if (not (idlwave-shell-is-running))
1906 (error "Shell is not running")
1907 (if (or arg
(y-or-n-p "Exit the IDLWAVE Shell? "))
1909 (idlwave-shell-send-command "exit")
1912 (defun idlwave-shell-reset (&optional hidden
)
1913 "Reset IDL. Return to main level and destroy the leftover variables.
1914 This issues the following commands:
1916 WIDGET_CONTROL,/RESET
1919 ;; OBJ_DESTROY, OBJ_VALID() FIXME: should this be added?
1921 (when (or idlwave-shell-reset-no-prompt
1922 (yes-or-no-p "Really Reset IDL and discard current session? "))
1923 (message "Resetting IDL")
1924 (setq idlwave-shell-calling-stack-index
0)
1925 ;; Give widget exit handlers a chance
1926 (idlwave-shell-send-command "retall" nil hidden
)
1927 (idlwave-shell-send-command "widget_control,/reset" nil hidden
)
1928 (idlwave-shell-send-command "close,/all" nil hidden
)
1929 ;; (idlwave-shell-send-command "obj_destroy, obj_valid()" nil hidden)
1930 (idlwave-shell-send-command "heap_gc,/verbose" nil hidden
)
1931 (idlwave-shell-display-line nil
)))
1933 (defun idlwave-shell-path-filter ()
1934 ;; Convert the output of the path query into a list of directories
1935 (let ((path-string idlwave-shell-command-output
)
1936 (case-fold-search t
)
1939 (while (string-match "^PATH:[ \t]*<\\(.*\\)>[ \t]*\n" path-string start
)
1940 (push (match-string 1 path-string
) dirs
)
1941 (setq start
(match-end 0)))
1942 (setq dirs
(mapcar 'file-name-as-directory dirs
))
1943 (if (string-match "^SYSDIR:[ \t]*<\\(.*\\)>[ \t]*\n" path-string
)
1944 (setq sysdir
(file-name-as-directory
1945 (match-string 1 path-string
))))
1946 (cons sysdir
(nreverse dirs
))))
1948 (defun idlwave-shell-routine-info-filter ()
1949 "Function which parses the special output from idlwave_routine_info.pro."
1950 (let ((text idlwave-shell-command-output
)
1952 sep sep-re file type spec specs name cs key keys class entry
)
1953 ;; (message "GOT: %s" text) ;??????????????????????
1954 ;; Initialize variables
1955 (setq idlwave-compiled-routines nil
1956 idlwave-unresolved-routines nil
)
1957 ;; Cut out the correct part of the output.
1959 "^>>>BEGIN OF IDLWAVE ROUTINE INFO (\"\\(.+\\)\" IS THE SEPARATOR.*"
1961 (setq sep
(match-string 1 text
)
1962 sep-re
(concat (regexp-quote sep
) " *")
1963 text
(substring text
(match-end 0)))
1964 ;; Set dummy values and kill the text
1965 (setq sep
"@" sep-re
"@ *" text
"")
1966 (if idlwave-idlwave_routine_info-compiled
1968 "Routine Info warning: No match for BEGIN line in \n>>>\n%s\n<<<\n"
1969 idlwave-shell-command-output
)))
1970 (if (string-match "^>>>END OF IDLWAVE ROUTINE INFO.*" text
)
1971 (setq text
(substring text
0 (match-beginning 0)))
1972 (if idlwave-idlwave_routine_info-compiled
1974 "Routine Info warning: No match for END line in \n>>>\n%s\n<<<\n"
1975 idlwave-shell-command-output
)))
1976 ;; Match the output lines
1977 (while (string-match "^IDLWAVE-\\(PRO\\|FUN\\): \\(.*\\)" text start
)
1978 (setq start
(match-end 0))
1979 (setq type
(match-string 1 text
)
1980 spec
(match-string 2 text
)
1981 specs
(idlwave-split-string spec sep-re
)
1983 class
(if (equal (nth 1 specs
) "") nil
(nth 1 specs
))
1987 keys
(if (and (stringp key
)
1988 (not (string-match "\\` *\\'" key
)))
1990 (delete "" (idlwave-split-string key
" +")))))
1991 (setq name
(idlwave-sintern-routine-or-method name class t
)
1992 class
(idlwave-sintern-class class t
)
1993 file
(if (equal file
"") nil file
)
1994 keys
(mapcar (lambda (x)
1995 (list (idlwave-sintern-keyword (car x
) t
))) keys
))
1997 ;; In the following ignore routines already defined in buffers,
1998 ;; assuming that if the buffer stuff differs, it is a "new"
1999 ;; version, not yet compiled, and should take precedence.
2000 ;; We could do the same for the library to avoid duplicates -
2001 ;; but I think frequently a user might have several versions of
2002 ;; the same function in different programs, and in this case the
2003 ;; compiled one will be the best guess of all versions.
2004 ;; Therefore, we leave duplicates of library routines in.
2005 (cond ((string= name
"$MAIN$")) ; ignore this one
2006 ((and (string= type
"PRO")
2007 ;; FIXME: is it OK to make the buffer routines dominate?
2009 (not (idlwave-rinfo-assq name
'pro class
2010 idlwave-buffer-routines
)))
2011 ;; FIXME: is it OK to make the library routines dominate?
2012 ;;(not (idlwave-rinfo-assq name 'pro class
2013 ;; idlwave-library-routines))
2015 (setq entry
(list name
'pro class
2019 (file-name-nondirectory file
)
2020 (idlwave-sintern-dir
2021 (file-name-directory file
)))))
2022 cs
(cons nil keys
)))
2024 (push entry idlwave-compiled-routines
)
2025 (push entry idlwave-unresolved-routines
)))
2027 ((and (string= type
"FUN")
2028 ;; FIXME: is it OK to make the buffer routines dominate?
2030 (not (idlwave-rinfo-assq name
'fun class
2031 idlwave-buffer-routines
)))
2032 ;; FIXME: is it OK to make the library routines dominate?
2033 ;; (not (idlwave-rinfo-assq name 'fun class
2034 ;; idlwave-library-routines))
2036 (setq entry
(list name
'fun class
2040 (file-name-nondirectory file
)
2041 (idlwave-sintern-dir
2042 (file-name-directory file
)))))
2043 cs
(cons nil keys
)))
2045 (push entry idlwave-compiled-routines
)
2046 (push entry idlwave-unresolved-routines
))))))
2047 ;; Reverse the definitions so that they are alphabetically sorted.
2048 (setq idlwave-compiled-routines
(nreverse idlwave-compiled-routines
)
2049 idlwave-unresolved-routines
(nreverse idlwave-unresolved-routines
)))
2051 (defun idlwave-shell-filter-directory ()
2052 "Get the current directory from `idlwave-shell-command-output'.
2053 Change the default directory for the process buffer to concur."
2054 (with-current-buffer (idlwave-shell-buffer)
2055 (if (string-match ",___cur[\n\r ]+\\([^\n\r]+\\)[\n\r]"
2056 idlwave-shell-command-output
)
2057 (let ((dir (substring idlwave-shell-command-output
2058 (match-beginning 1) (match-end 1))))
2059 ;; (message "Setting Emacs working dir to %s" dir)
2060 (setq idlwave-shell-default-directory dir
)
2061 (setq default-directory
(file-name-as-directory dir
))))))
2063 (defvar idlwave-shell-get-object-class nil
)
2064 (defun idlwave-shell-get-object-class (apos)
2065 "Query the shell for the class of the object before point."
2066 (let ((bos (save-excursion (idlwave-start-of-substatement 'pre
) (point)))
2067 (bol (save-excursion (forward-line 0) (point)))
2071 (setq expression
(buffer-substring
2074 (if (not (re-search-backward
2075 "[^][.A-Za-z0-9_() ]" bos t
))
2076 (throw 'exit bos
)) ;ran into bos
2077 (if (not (idlwave-is-pointer-dereference bol
))
2078 (throw 'exit
(1+ (point))))))
2080 (when (not (string= expression
""))
2081 (setq idlwave-shell-get-object-class nil
)
2082 (idlwave-shell-send-command
2083 (concat "if obj_valid(" expression
") then print,obj_class("
2085 'idlwave-shell-parse-object-class
2087 ;; If we don't know anything about the class, update shell routines
2088 (if (and idlwave-shell-get-object-class
2089 (not (assoc-string idlwave-shell-get-object-class
2090 (idlwave-class-alist) t
)))
2091 (idlwave-shell-maybe-update-routine-info))
2092 idlwave-shell-get-object-class
)))
2094 (defun idlwave-shell-parse-object-class ()
2095 "Parse the output of the obj_class command."
2096 (let ((match "obj_class([^\n\r]+[\n\r ]"))
2097 (if (string-match (concat match
"\\([A-Za-z_0-9]+\\) *[\n\r]\\("
2098 idlwave-shell-prompt-pattern
"\\)")
2099 idlwave-shell-command-output
)
2100 (setq idlwave-shell-get-object-class
2101 (match-string 1 idlwave-shell-command-output
)))))
2103 (defvar idlwave-sint-sysvars nil
)
2104 (idlwave-new-sintern-type 'execcomm
)
2106 (defun idlwave-shell-complete (&optional arg
)
2107 "Do completion in the idlwave-shell buffer.
2108 Calls `idlwave-shell-complete-filename' after some executive commands or
2109 in strings. Otherwise, calls `idlwave-complete' to complete modules and
2115 (setq exec-cmd
(idlwave-shell-executive-command))
2117 (member (upcase (cdr exec-cmd
))
2118 '(".R" ".RU" ".RUN" ".RN" ".RNE" ".RNEW"
2119 ".COM" ".COMP" ".COMPI" ".COMPIL" ".COMPILE")))
2120 ;; We are in a command line with an executive command
2121 (idlwave-shell-complete-filename))
2123 ((car-safe exec-cmd
)
2124 (setq idlwave-completion-help-info
2125 '(idlwave-shell-complete-execcomm-help))
2126 (idlwave-complete-in-buffer 'execcomm
'execcomm
2127 idlwave-executive-commands-alist nil
2128 "Select an executive command"
2131 ((idlwave-shell-batch-command)
2132 (idlwave-shell-complete-filename))
2134 ((idlwave-shell-shell-command)
2135 (idlwave-shell-complete-filename))
2137 ((and (idlwave-shell-filename-string)
2140 (let ((case-fold-search t
))
2141 (not (looking-at ".*obj_new")))))
2142 (idlwave-shell-complete-filename))
2145 ;; Default completion of modules and keywords
2146 (idlwave-complete arg
)))))
2148 ;; Get rid of opaque dynamic variable passing of idlw-help-link?
2149 (defvar idlw-help-link
) ; dynamic variable from idlwave-do-mouse-completion-help
2150 (defun idlwave-shell-complete-execcomm-help (mode word
)
2151 (let ((word (or (nth 1 idlwave-completion-help-info
) word
))
2152 (entry (assoc-string word idlwave-executive-commands-alist t
)))
2155 (and (stringp word
) entry
(cdr entry
)))
2157 (if entry
(setq idlw-help-link
(cdr entry
)))) ; setting dynamic variable!
2158 (t (error "This should not happen")))))
2160 (defun idlwave-shell-complete-filename (&optional arg
)
2161 "Complete a file name at point if after a file name.
2162 We assume that we are after a file name when completing one of the
2163 args of an executive .run, .rnew or .compile."
2164 ;; CWD might have changed, resync, to set default directory
2165 (idlwave-shell-resync-dirs)
2166 (let ((comint-file-name-chars idlwave-shell-file-name-chars
))
2167 (comint-dynamic-complete-filename)))
2169 (defun idlwave-shell-executive-command ()
2170 "Return the name of the current executive command, if any."
2172 (idlwave-beginning-of-statement)
2173 (cons (looking-at "[ \t]*\\.")
2174 (if (looking-at "[ \t]*[.]\\([^ \t\n\r]+\\)[ \t]")
2175 (match-string 1)))))
2177 (defun idlwave-shell-filename-string ()
2178 "Return t if in a string and after what could be a file name."
2179 (let ((limit (point-at-bol)))
2181 ;; Skip backwards over file name chars
2182 (skip-chars-backward idlwave-shell-file-name-chars limit
)
2183 ;; Check of the next char is a string delimiter
2184 (memq (preceding-char) '(?
\' ?
\")))))
2186 (defun idlwave-shell-batch-command ()
2187 "Return t if we're in a batch command statement like @foo"
2188 (let ((limit (point-at-bol)))
2190 ;; Skip backwards over filename
2191 (skip-chars-backward idlwave-shell-file-name-chars limit
)
2192 (skip-chars-backward " \t" limit
)
2193 (and (eq (preceding-char) ?
@) (not (idlwave-in-quote))))))
2195 (defun idlwave-shell-shell-command ()
2196 "Return t if we're in a shell command statement like $ls"
2198 (idlwave-beginning-of-statement)
2199 (looking-at "\\$")))
2201 ;; Debugging Commands ------------------------------------------------------
2203 (defun idlwave-shell-redisplay (&optional hide
)
2204 "Try to resync the display with where execution has stopped.
2205 Issues a \"help,/trace\" command followed by a call to
2206 `idlwave-shell-display-line'. Also updates the breakpoint
2209 (setq idlwave-shell-calling-stack-index
0)
2210 (idlwave-shell-send-command
2212 '(idlwave-shell-display-line
2213 (idlwave-shell-pc-frame))
2215 (idlwave-shell-bp-query))
2217 (defun idlwave-shell-display-level-in-calling-stack (&optional hide
)
2218 (idlwave-shell-send-command
2221 ;; scanning for the state will reset the stack level - restore it
2222 (setq idlwave-shell-calling-stack-index
2223 ,idlwave-shell-calling-stack-index
)
2224 ;; parse the stack and visit the selected frame
2225 (idlwave-shell-parse-stack-and-display))
2228 (defun idlwave-shell-parse-stack-and-display ()
2229 (let* ((lines (delete "" (idlwave-split-string
2230 idlwave-shell-command-output
"^%")))
2231 (stack (delq nil
(mapcar 'idlwave-shell-parse-line lines
)))
2232 (nmax (1- (length stack
)))
2236 (setq idlwave-shell-calling-stack-index
0)
2238 (message "Problem with calling stack"))
2239 ((> idlwave-shell-calling-stack-index nmax
)
2241 (setq idlwave-shell-calling-stack-index nmax
2242 message
(format "%d is the highest calling stack level - can't go further up"
2244 ((< idlwave-shell-calling-stack-index nmin
)
2246 (setq idlwave-shell-calling-stack-index nmin
2247 message
(format "%d is the current calling stack level - can't go further down"
2249 (setq idlwave-shell-calling-stack-routine
2250 (nth 2 (nth idlwave-shell-calling-stack-index stack
)))
2252 ;; force edebug for this frame if we're in that mode already
2253 (idlwave-shell-display-line
2254 (nth idlwave-shell-calling-stack-index stack
) nil
2255 (if idlwave-shell-electric-debug-mode
'force
))
2256 (message "%s" (or message
2257 (format "In routine %s (stack level %d)"
2258 idlwave-shell-calling-stack-routine
2259 (- idlwave-shell-calling-stack-index
))))))
2261 (defun idlwave-shell-stack-up ()
2262 "Display the source code one step up the calling stack."
2264 (incf idlwave-shell-calling-stack-index
)
2265 (idlwave-shell-display-level-in-calling-stack 'hide
))
2266 (defun idlwave-shell-stack-down ()
2267 "Display the source code one step down the calling stack."
2269 (decf idlwave-shell-calling-stack-index
)
2270 (idlwave-shell-display-level-in-calling-stack 'hide
))
2272 (defun idlwave-shell-goto-frame (&optional frame
)
2273 "Set buffer to FRAME with point at the frame line.
2274 If the optional argument FRAME is nil then `idlwave-shell-pc-frame'
2275 is used. Does nothing if the resulting frame is nil."
2277 (setq frame
(idlwave-shell-pc-frame)))
2280 (set-buffer (idlwave-find-file-noselect (car frame
) 'shell
))
2282 (goto-char (point-min))
2283 (forward-line (1- (nth 1 frame
))))))
2285 (defun idlwave-shell-pc-frame ()
2286 "Return the frame for IDL execution."
2287 (and idlwave-shell-halt-frame
2288 (list (nth 0 idlwave-shell-halt-frame
)
2289 (nth 1 idlwave-shell-halt-frame
)
2290 (nth 2 idlwave-shell-halt-frame
))))
2292 (defun idlwave-shell-valid-frame (frame)
2293 "Check that frame is for an existing file."
2294 (file-readable-p (car frame
)))
2296 (defun idlwave-shell-stop-line-pending ()
2297 ;; Temporarily change the color of the stop line overlay
2298 (if idlwave-shell-stop-line-overlay
2299 (overlay-put idlwave-shell-stop-line-overlay
'face
2300 (if idlwave-shell-electric-debug-mode
2301 'idlwave-shell-pending-electric-stop
2302 'idlwave-shell-pending-stop
))))
2304 (defvar idlwave-shell-suppress-electric-debug nil
)
2305 (defun idlwave-shell-display-line (frame &optional col debug
)
2306 "Display frame file in other window with overlay arrow.
2308 FRAME is a list of file name, line number, and subroutine name. If
2309 FRAME is nil then remove overlay. If COL is set, move point to that
2310 column in the line. If DEBUG is non-nil, enable the electric debug
2311 mode. If it is 'disable, do not enable no matter what the setting of
2312 `idlwave-shell-automatic-electric-debug'. If it is 'force, enable no
2313 matter what the settings of that variable."
2315 ;; remove stop-line overlay from old position
2317 (setq overlay-arrow-string nil
)
2318 (setq idlwave-shell-mode-line-info nil
)
2319 (setq idlwave-shell-is-stopped nil
)
2320 (if idlwave-shell-stop-line-overlay
2321 (delete-overlay idlwave-shell-stop-line-overlay
))
2322 ;; turn off electric debug everywhere, if it's on
2323 (idlwave-shell-electric-debug-all-off))
2324 (if (not (idlwave-shell-valid-frame frame
))
2325 ;; fixme: errors are dangerous in shell filters. but i think i
2326 ;; have never encountered this one.
2327 (error "invalid frame - unable to access file: %s" (car frame
))
2329 ;; buffer : the buffer to display a line in.
2330 ;; select-shell: current buffer is the shell.
2332 (setq idlwave-shell-mode-line-info
2335 (- idlwave-shell-calling-stack-index
)
2337 (let* ((buffer (idlwave-find-file-noselect (car frame
) 'shell
))
2338 (select-shell (equal (buffer-name) (idlwave-shell-buffer)))
2339 window pos electric
)
2341 ;; first make sure the shell window is visible
2342 (idlwave-display-buffer (idlwave-shell-buffer)
2343 nil
(idlwave-shell-shell-frame))
2345 ;; now display the buffer and remember which window it is.
2346 (setq window
(idlwave-display-buffer buffer
2347 nil
(idlwave-shell-source-frame)))
2349 ;; enter the buffer and mark the line
2350 (with-current-buffer buffer
2353 (goto-char (point-min))
2354 (forward-line (1- (nth 1 frame
)))
2356 (setq idlwave-shell-is-stopped t
)
2358 (if idlwave-shell-stop-line-overlay
2360 ;; restore face and move overlay
2361 (overlay-put idlwave-shell-stop-line-overlay
'face
2362 (if idlwave-shell-electric-debug-mode
2363 idlwave-shell-electric-stop-line-face
2364 idlwave-shell-stop-line-face
))
2365 (move-overlay idlwave-shell-stop-line-overlay
2366 (point) (point-at-eol)
2368 ;; use the arrow instead, but only if marking is wanted.
2369 (if idlwave-shell-mark-stop-line
2370 (setq overlay-arrow-string idlwave-shell-overlay-arrow
))
2371 (or overlay-arrow-position
; create the marker if necessary
2372 (setq overlay-arrow-position
(make-marker)))
2373 (set-marker overlay-arrow-position
(point) buffer
)))
2375 ;; if the point is outside the restriction, widen the buffer.
2376 (if (or (< pos
(point-min)) (> pos
(point-max)))
2381 ;; if we have the column of the error, move the cursor there.
2382 (if col
(move-to-column col
))
2385 ;; enter electric debug mode, if not prohibited and not in
2387 (when (and (not idlwave-shell-electric-debug-mode
)
2388 (or (eq debug
'force
)
2390 (not (eq debug
'disable
)) ;; explicitly disabled
2392 (eq idlwave-shell-automatic-electric-debug t
)
2394 (eq idlwave-shell-automatic-electric-debug
2396 (not (eq idlwave-shell-current-state
'error
))))
2397 (not idlwave-shell-suppress-electric-debug
))))
2398 (idlwave-shell-electric-debug-mode t
))
2399 (setq electric idlwave-shell-electric-debug-mode
))
2401 ;; Make sure pos is really displayed in the window.
2402 (set-window-point window pos
)
2404 ;; If we came from the shell, go back there. Otherwise select
2405 ;; the window where the error/halt is displayed.
2406 (if (or (and idlwave-shell-electric-zap-to-file electric
)
2407 (and (equal (buffer-name) (idlwave-shell-buffer))
2408 (not select-shell
)))
2409 (select-window window
))))))
2412 (defun idlwave-shell-step (arg)
2413 "Step one source line.
2414 If given prefix argument ARG, step ARG source lines."
2416 (or (not arg
) (< arg
1)
2418 (idlwave-shell-stop-line-pending)
2419 (idlwave-shell-send-command
2420 (concat ".s " (if (integerp arg
) (int-to-string arg
) arg
))
2421 nil
(if (idlwave-shell-hide-p 'debug
) 'mostly
) nil t
))
2423 (defun idlwave-shell-stepover (arg)
2424 "Stepover one source line.
2425 If given prefix argument ARG, step ARG source lines.
2426 Uses IDL's stepover executive command which does not enter called functions."
2428 (or (not arg
) (< arg
1)
2430 (idlwave-shell-stop-line-pending)
2431 (idlwave-shell-send-command
2432 (concat ".so " (if (integerp arg
) (int-to-string arg
) arg
))
2433 nil
(if (idlwave-shell-hide-p 'debug
) 'mostly
) nil t
))
2435 (defun idlwave-shell-break-here (&optional count cmd condition disabled
2437 "Set breakpoint at current line.
2439 If COUNT is nil then an ordinary breakpoint is set. We treat a COUNT
2440 of 1 as a temporary breakpoint using the ONCE keyword. Counts greater
2441 than 1 use the IDL AFTER=count keyword to break only after reaching
2442 the statement COUNT times.
2444 Optional argument CMD is a list or function to evaluate upon reaching
2445 the breakpoint. CONDITION is a break condition, and DISABLED, if
2446 non-nil disables the breakpoint."
2449 (if (equal (car count
) 4)
2450 (setq condition
(read-string "Break Condition: ")))
2452 (idlwave-shell-set-bp
2453 ;; Create breakpoint
2454 (idlwave-shell-bp (idlwave-shell-current-frame)
2455 (list count cmd condition disabled
)
2456 (idlwave-shell-current-module))
2459 (defun idlwave-shell-set-bp-check (bp)
2460 "Check for failure to set breakpoint.
2461 This is run on `idlwave-shell-post-command-hook'.
2462 Offers to recompile the procedure if we failed. This usually fixes
2463 the problem with not being able to set the breakpoint."
2465 (if idlwave-shell-command-output
2467 ((string-match "% BREAKPOINT: *Unable to find code"
2468 idlwave-shell-command-output
)
2469 ;; Offer to recompile
2473 (concat "Okay to recompile file "
2474 (idlwave-shell-bp-get bp
'file
) "?")))
2477 ;; Clean up before retrying
2478 (idlwave-shell-command-failure)
2479 (idlwave-shell-send-command
2480 (concat ".run \"" (idlwave-shell-bp-get bp
'file
) "\"") nil
2481 (if (idlwave-shell-hide-p 'run
) 'mostly
) nil t
)
2482 ;; Try setting breakpoint again
2483 (idlwave-shell-set-bp bp
))
2485 (message "Unable to set breakpoint.")
2486 (idlwave-shell-command-failure))
2489 ((string-match "% Syntax error" idlwave-shell-command-output
)
2490 (message "Syntax error in condition.")
2491 (idlwave-shell-command-failure)
2496 (defun idlwave-shell-command-failure ()
2497 "Do any necessary clean up when an IDL command fails.
2498 Call this from a function attached to `idlwave-shell-post-command-hook'
2499 that detects the failure of a command.
2500 For example, this is called from `idlwave-shell-set-bp-check' when a
2501 breakpoint can not be set."
2502 ;; Clear pending commands
2503 (setq idlwave-shell-pending-commands nil
))
2505 (defun idlwave-shell-cont (&optional no-show
)
2506 "Continue executing."
2508 (idlwave-shell-stop-line-pending)
2509 (idlwave-shell-send-command ".c" (unless no-show
2510 '(idlwave-shell-redisplay 'hide
))
2511 (if (idlwave-shell-hide-p 'debug
) 'mostly
)
2514 (defun idlwave-shell-go ()
2515 "Run .GO. This starts the main program of the last compiled file."
2517 (idlwave-shell-stop-line-pending)
2518 (idlwave-shell-send-command ".go" '(idlwave-shell-redisplay 'hide
)
2519 (if (idlwave-shell-hide-p 'debug
) 'mostly
)
2522 (defun idlwave-shell-return ()
2523 "Run .RETURN (continue to next return, but stay in subprogram)."
2525 (idlwave-shell-stop-line-pending)
2526 (idlwave-shell-send-command ".return" '(idlwave-shell-redisplay 'hide
)
2527 (if (idlwave-shell-hide-p 'debug
) 'mostly
)
2530 (defun idlwave-shell-skip ()
2531 "Run .SKIP (skip one line, then step)."
2533 (idlwave-shell-stop-line-pending)
2534 (idlwave-shell-send-command ".skip" '(idlwave-shell-redisplay 'hide
)
2535 (if (idlwave-shell-hide-p 'debug
) 'mostly
)
2538 (defun idlwave-shell-clear-bp (bp &optional no-query
)
2539 "Clear breakpoint BP.
2540 Clears in IDL and in `idlwave-shell-bp-alist'."
2541 (let ((index (idlwave-shell-bp-get bp
)))
2544 (idlwave-shell-send-command
2545 (concat "breakpoint,/clear," (int-to-string index
))
2546 nil
(idlwave-shell-hide-p 'breakpoint
) nil t
)
2547 (unless no-query
(idlwave-shell-bp-query))))))
2549 (defun idlwave-shell-current-frame ()
2550 "Return a list containing the current file name and line point is in.
2551 If in the IDL shell buffer, returns `idlwave-shell-pc-frame'."
2552 (if (eq (current-buffer) (get-buffer (idlwave-shell-buffer)))
2554 (idlwave-shell-pc-frame)
2556 (list (idlwave-shell-file-name (buffer-file-name))
2559 (1+ (count-lines 1 (point-at-bol)))))))
2561 (defun idlwave-shell-current-module ()
2562 "Return the name of the module for the current file.
2563 Returns nil if unable to obtain a module name."
2564 (if (eq (current-buffer) (get-buffer (idlwave-shell-buffer)))
2566 (nth 2 idlwave-shell-halt-frame
)
2571 (if (idlwave-prev-index-position)
2572 (let* ((module (idlwave-what-module))
2573 (name (idlwave-make-full-name (nth 2 module
) (car module
)))
2574 (type (nth 1 module
)))
2575 (list (upcase name
) type
)))))))
2577 (defun idlwave-shell-clear-current-bp ()
2578 "Remove breakpoint at current line.
2579 This command can be called from the shell buffer if IDL is currently
2580 stopped at a breakpoint."
2582 (let ((bp (idlwave-shell-find-current-bp)))
2583 (if bp
(idlwave-shell-clear-bp bp
))))
2586 (defun idlwave-shell-toggle-enable-current-bp (&optional bp force
2588 "Disable or enable current breakpoint or a breakpoint passed in BP.
2589 If FORCE is 'disable or 'enable, for that condition instead of
2590 toggling. If NO-UPDATE is non-nil, don't update the breakpoint
2591 list after toggling."
2593 (let* ((bp (or bp
(idlwave-shell-find-current-bp)))
2594 (disabled (idlwave-shell-bp-get bp
'disabled
)))
2595 (cond ((eq force
'disable
) (setq disabled nil
))
2596 ((eq force
'enable
) (setq disabled t
)))
2598 (setf (nth 3 (cdr (cdr bp
))) (not disabled
))
2599 (idlwave-shell-send-command
2600 (concat "breakpoint,"
2601 (if disabled
"/enable," "/disable,")
2602 (int-to-string (idlwave-shell-bp-get bp
)))
2603 nil
(idlwave-shell-hide-p 'breakpoint
) nil t
)
2604 (unless no-update
(idlwave-shell-bp-query)))))
2606 (defun idlwave-shell-enable-all-bp (&optional enable no-update bpl
)
2607 "Disable all breakpoints we know about which need disabling.
2608 If ENABLE is non-nil, enable them instead."
2609 (let ((bpl (or bpl idlwave-shell-bp-alist
)) disabled modified
)
2611 (setq disabled
(idlwave-shell-bp-get (car bpl
) 'disabled
))
2612 (when (idlwave-xor (not disabled
) (eq enable
'enable
))
2613 (idlwave-shell-toggle-enable-current-bp
2614 (car bpl
) (if (eq enable
'enable
) 'enable
'disable
) no-update
)
2615 (push (car bpl
) modified
))
2616 (setq bpl
(cdr bpl
)))
2617 (unless no-update
(idlwave-shell-bp-query))
2620 (defun idlwave-shell-to-here ()
2621 "Set a breakpoint with count 1 then continue."
2623 ;; temporarily disable all other breakpoints
2624 (let ((disabled (idlwave-shell-enable-all-bp 'disable
'no-update
)))
2625 (idlwave-shell-break-here 1 nil nil nil
'no-show
)
2626 (idlwave-shell-cont 'no-show
)
2627 (idlwave-shell-enable-all-bp 'enable
'no-update disabled
))
2628 (idlwave-shell-redisplay)) ; sync up everything at the end
2630 (defun idlwave-shell-break-this-module (&optional arg
)
2633 (idlwave-beginning-of-subprogram)
2634 (idlwave-shell-break-here arg
)))
2636 (defun idlwave-shell-break-in ()
2637 "Look for a module name near point and set a break point for it.
2638 The command looks for an identifier near point and sets a breakpoint
2639 for the first line of the corresponding module. If MODULE is t, set
2640 in the current routine."
2642 (let* ((module (idlwave-fix-module-if-obj_new (idlwave-what-module)))
2643 (type (nth 1 module
))
2645 (class (nth 2 module
)))
2648 (setq module
(idlwave-make-full-name class name
))
2649 (idlwave-shell-module-source-query module type
)
2650 (idlwave-shell-set-bp-in-module name type class
))
2651 (error "No identifier at point"))))
2654 (defun idlwave-shell-set-bp-in-module (name type class
)
2655 "Set breakpoint in module.
2656 Assumes that `idlwave-shell-sources-alist' contains an entry for that module."
2657 (let* ((module (idlwave-make-full-name class name
))
2661 (assoc (upcase module
)
2662 idlwave-shell-sources-alist
)
2663 (nth 3 (idlwave-best-rinfo-assoc name type class
2664 (idlwave-routines)))))))
2666 (if (or (not source-file
)
2667 (not (file-regular-p source-file
))
2669 (or (idlwave-get-buffer-visiting source-file
)
2670 (find-file-noselect source-file
)))))
2672 (message "The source file for module %s is probably not compiled"
2675 (with-current-buffer buf
2677 (goto-char (point-min))
2678 (let ((case-fold-search t
))
2679 (if (re-search-forward
2680 (concat "^[ \t]*\\(pro\\|function\\)[ \t]+"
2684 (goto-char (match-beginning 1))
2685 (message "Setting breakpoint for module %s" module
)
2686 (idlwave-shell-break-here))
2687 (message "Cannot find module %s in file %s" module source-file
)
2690 (defun idlwave-shell-up ()
2691 "Run to end of current block.
2692 Sets a breakpoint with count 1 at end of block, then continues."
2694 (if (idlwave-shell-pc-frame)
2696 (idlwave-shell-goto-frame)
2697 ;; find end of subprogram
2698 (let ((eos (save-excursion
2699 (idlwave-beginning-of-subprogram)
2700 (idlwave-forward-block)
2702 (idlwave-backward-up-block -
1)
2703 ;; move beyond end block line - IDL will not break there.
2704 ;; That is, you can put a breakpoint there but when IDL does
2705 ;; break it will report that it is at the next line.
2706 (idlwave-next-statement)
2707 (idlwave-end-of-statement)
2708 ;; Make sure we are not beyond subprogram
2712 ;; Move back inside subprogram
2714 (idlwave-previous-statement))
2715 (idlwave-shell-to-here)))))
2717 (defun idlwave-shell-out ()
2718 "Attempt to run until this procedure exits.
2719 Runs to the last statement and then steps 1 statement. Use the .out command."
2721 (idlwave-shell-send-command ".o" nil
2722 (if (idlwave-shell-hide-p 'debug
) 'mostly
)
2725 (defun idlwave-shell-goto-previous-bp ()
2726 "Move to the previous breakpoint in the buffer."
2728 (idlwave-shell-move-to-bp -
1))
2729 (defun idlwave-shell-goto-next-bp ()
2730 "Move to the next breakpoint in the buffer."
2732 (idlwave-shell-move-to-bp 1))
2734 (defun idlwave-shell-move-to-bp (dir)
2735 "Move to the next or previous breakpoint, depending on direction DIR."
2736 (let* ((frame (idlwave-shell-current-frame))
2738 (orig-bp-line (nth 1 frame
))
2739 (bp-alist idlwave-shell-bp-alist
)
2740 (orig-func (if (> dir
0) '> '<))
2741 (closer-func (if (> dir
0) '< '>))
2742 bp got-bp bp-line cur-line
)
2743 (while (setq bp
(pop bp-alist
))
2744 (when (string= file
(car (car bp
)))
2746 (setq cur-line
(nth 1 (car bp
)))
2748 (funcall orig-func cur-line orig-bp-line
)
2749 (or (not bp-line
) (funcall closer-func cur-line bp-line
)))
2750 (setq bp-line cur-line
))))
2751 (unless bp-line
(error "No further breakpoints"))
2752 (goto-char (point-min))
2753 (forward-line (1- bp-line
))))
2755 ;; Examine Commands ------------------------------------------------------
2757 (defun idlwave-shell-help-expression (arg)
2758 "Print help on current expression. See `idlwave-shell-print'."
2760 (idlwave-shell-print arg
'help
))
2762 (defmacro idlwave-shell-mouse-examine
(help &optional ev
)
2763 "Create a function for generic examination of expressions."
2765 "Expansion function for expression examination."
2767 (let* ((drag-track (fboundp 'mouse-drag-track
))
2768 (transient-mark-mode t
)
2770 (tracker (if (featurep 'xemacs
)
2772 'default-mouse-track-event-is-with-button
)
2773 'idlwave-xemacs-hack-mouse-track
2775 ;; Emacs 22 no longer completes the drag with
2776 ;; mouse-drag-region, without an additional
2777 ;; event. mouse-drag-track does so.
2778 (if drag-track
'mouse-drag-track
'mouse-drag-region
))))
2779 (funcall tracker event
)
2780 (idlwave-shell-print (if (idlwave-region-active-p) '(4) nil
)
2783 ;; Begin terrible hack section -- XEmacs tests for button2 explicitly
2784 ;; on drag events, calling drag-n-drop code if detected. Ughhh...
2785 (defun idlwave-default-mouse-track-event-is-with-button (event n
)
2788 (defun idlwave-xemacs-hack-mouse-track (event)
2789 (if (featurep 'xemacs
)
2790 (let ((oldfunc (symbol-function
2791 'default-mouse-track-event-is-with-button
)))
2794 (fset 'default-mouse-track-event-is-with-button
2795 'idlwave-default-mouse-track-event-is-with-button
)
2796 (mouse-track event
))
2797 (fset 'default-mouse-track-event-is-with-button oldfunc
)))))
2798 ;;; End terrible hack section
2800 (defun idlwave-shell-mouse-print (event)
2801 "Print value of variable at the mouse position, with `print'."
2803 (funcall (idlwave-shell-mouse-examine nil
) event
))
2805 (defun idlwave-shell-mouse-help (event)
2806 "Print value of variable at the mouse position, with `help'."
2808 (funcall (idlwave-shell-mouse-examine 'help
) event
))
2810 (defun idlwave-shell-examine-select (event)
2811 "Pop-up a list to select from for examining the expression."
2813 (funcall (idlwave-shell-mouse-examine nil event
) event
))
2815 (defmacro idlwave-shell-examine
(help)
2816 "Create a function for key-driven expression examination."
2819 (idlwave-shell-print nil
,help
)))
2821 (defvar idlwave-shell-examine-label nil
2822 "Label to include with examine text if in a separate buffer.")
2823 (defvar idlwave-shell-examine-completion-list nil
)
2825 (defun idlwave-shell-print (arg &optional help ev complete-help-type
)
2826 "Print current expression.
2828 With HELP non-nil, show help on expression. If HELP is a string,
2829 the expression will be put in place of ___, e.g.:
2831 print,size(___,/DIMENSIONS)
2833 HELP can also be a cons cell ( NAME . STRING ) in which case NAME will
2834 be used to label the help print-out.
2836 Otherwise, print is called on the expression.
2838 An expression is an identifier plus 1 pair of matched parentheses
2839 directly following the identifier - an array or function call.
2840 Alternatively, an expression is the contents of any matched
2841 parentheses when the open parenthesis is not directly preceded by an
2842 identifier. If point is at the beginning or within an expression
2843 return the inner-most containing expression, otherwise, return the
2844 preceding expression.
2846 With prefix arg, or if transient mode set and the region is defined,
2847 use the current region as the expression.
2849 With double prefix arg ARG prompt for an expression.
2851 If EV is a valid event passed, pop-up a list from
2852 `idlwave-shell-examine-alist' from which to select the help
2853 command text. If instead COMPLETE-HELP-TYPE is non-nil, choose
2854 from `idlwave-shell-examine-alist' via mini-buffer shortcut key."
2857 ;; For speed: assume the helper routine hasn't been lost, e.g. with
2858 ;; .FULL_RESET_SESSION. We'll recover if necessary
2859 (unless idlwave-idlwave_routine_info-compiled
2860 (idlwave-shell-compile-helper-routines))
2862 (let* ((process (get-buffer-process (current-buffer)))
2863 (process-mark (if process
(process-mark process
)))
2865 (if (and (integerp idlwave-shell-calling-stack-index
)
2866 (> idlwave-shell-calling-stack-index
0))
2868 idlwave-shell-calling-stack-index
2869 idlwave-shell-calling-stack-routine
)))
2873 (setq expr
(read-string "Expression: ")))
2874 ((and (or arg
(idlwave-region-active-p))
2875 (< (- (region-end) (region-beginning)) 2000))
2876 (setq beg
(region-beginning)
2879 (idlwave-with-special-syntax
2880 ;; Move to beginning of current or previous expression
2881 (if (looking-at "\\<\\|(")
2882 ;; At beginning of expression, don't move backwards unless
2883 ;; this is at the end of an identifier.
2884 (if (looking-at "\\>")
2887 (if (looking-at "\\>")
2888 ;; Move to beginning of identifier - must be an array or
2889 ;; function expression.
2891 ;; Move to end of expression
2894 (while (looking-at "\\>[[(]\\|\\.")
2897 (setq end
(point)))))
2899 ;; Get expression, but first move the begin mark if a
2900 ;; process-mark is inside the region, to keep the overlay from
2901 ;; wandering in the Shell.
2903 (if (and process-mark
(> process-mark beg
) (< process-mark end
))
2904 (setq beg
(marker-position process-mark
)))
2905 (setq expr
(buffer-substring beg end
)))
2907 ;; Show the overlay(s) and attach any necessary hooks and filters
2908 (when (and beg end idlwave-shell-expression-overlay
)
2909 (move-overlay idlwave-shell-expression-overlay beg end
2911 (add-hook 'pre-command-hook
2912 'idlwave-shell-delete-expression-overlay
))
2913 (add-hook 'pre-command-hook
2914 'idlwave-shell-delete-output-overlay
)
2916 ;; Remove empty or comment-only lines
2917 (while (string-match "\n[ \t]*\\(;.*\\)?\r*\n" expr
)
2918 (setq expr
(replace-match "\n" t t expr
)))
2919 ;; Concatenate continuation lines
2920 (while (string-match "[ \t]*\\$[ \t]*\\(;.*\\)?\\(\n[ \t]*\\|$\\)" expr
)
2921 (setq expr
(replace-match "" t t expr
)))
2922 ;; Remove final newline
2923 (if (string-match "\n[ \t\r]*\\'" expr
)
2924 (setq expr
(replace-match "" t t expr
)))
2927 ;; Pop-up or complete on the examine selection list, if appropriate
2930 (and ev idlwave-shell-examine-alist
)
2933 (if (consp help
) help
2935 ;; A cons from either a pop-up or mini-buffer completion
2936 (if complete-help-type
2937 (idlwave-one-key-select 'idlwave-shell-examine-alist
2938 "Examine with: " 1.5)
2939 ;; (idlwave-completing-read
2941 ;; idlwave-shell-examine-alist nil nil nil
2942 ;; 'idlwave-shell-examine-completion-list
2944 (idlwave-popup-select
2946 (mapcar 'car idlwave-shell-examine-alist
)
2948 idlwave-shell-examine-alist
))))
2949 (setq help
(cdr help-cons
))
2950 (if (null help
) (throw 'exit nil
))
2951 (if idlwave-shell-separate-examine-output
2952 (setq idlwave-shell-examine-label
2954 (format "==>%s<==\n%s:" expr
(car help-cons
))
2955 stack-label
"\n"))))
2956 ;; The regular help label (no popups, cons cells, etc.)
2957 (setq idlwave-shell-examine-label
2959 (format "==>%s<==\n%s:" expr
2960 (cond ((null help
) "print")
2961 ((stringp help
) help
)
2962 (t (symbol-name help
))))
2967 (setq expr
(idlwave-retrieve-expression-from-level
2969 idlwave-shell-calling-stack-index
)))
2970 (setq cmd
(idlwave-shell-help-statement help expr
))
2971 ;;(idlwave-shell-recenter-shell-window)
2972 (idlwave-shell-send-command
2974 'idlwave-shell-check-compiled-and-display
2975 (if idlwave-shell-separate-examine-output
'hide
))))))
2977 (defvar idlwave-shell-examine-window-alist nil
2978 "Variable to hold the win/height pairs for all *Examine* windows.")
2980 (defvar idlwave-shell-examine-map
(make-sparse-keymap))
2981 (define-key idlwave-shell-examine-map
"q" 'idlwave-shell-examine-display-quit
)
2982 (define-key idlwave-shell-examine-map
"c" 'idlwave-shell-examine-display-clear
)
2985 (defun idlwave-shell-check-compiled-and-display ()
2986 "Check examine output for warning about undefined procedure/function."
2987 (if (string-match "% Attempt to call undefined" idlwave-shell-command-output
)
2988 (idlwave-shell-compile-helper-routines))
2989 (if idlwave-shell-separate-examine-output
2990 (idlwave-shell-examine-display)
2991 (idlwave-shell-examine-highlight)))
2993 (defun idlwave-shell-examine-display ()
2994 "View the examine command output in a separate buffer."
2995 (let (win cur-beg cur-end
)
2996 (with-current-buffer (get-buffer-create "*Examine*")
2997 (use-local-map idlwave-shell-examine-map
)
2998 (setq buffer-read-only nil
)
2999 (goto-char (point-max))
3001 (narrow-to-region (point) (point))
3002 (if (string-match "^% Syntax error." idlwave-shell-command-output
)
3003 (insert "% Syntax error.\n")
3004 (insert idlwave-shell-command-output
)
3005 ;; Just take the last bit between the prompts (if more than one).
3007 (re-search-backward idlwave-shell-prompt-pattern nil t
)
3011 (or (progn (if (re-search-backward
3012 idlwave-shell-prompt-pattern nil t
)
3015 (re-search-forward "\n")))
3016 (str (buffer-substring beg end
)))
3017 (delete-region (point-min) (point-max))
3019 (if idlwave-shell-examine-label
3020 (progn (goto-char (point-min))
3021 (insert idlwave-shell-examine-label
)
3022 (setq idlwave-shell-examine-label nil
)))))
3023 (setq cur-beg
(point-min)
3024 cur-end
(point-max))
3025 (setq buffer-read-only t
)
3026 (move-overlay idlwave-shell-output-overlay cur-beg cur-end
3029 ;; Look for the examine buffer in all windows. If one is
3030 ;; found in a frame all by itself, use that, otherwise, switch
3031 ;; to or create an examine window in this frame, and resize if
3032 ;; it's a newly created window
3033 (let* ((winlist (get-buffer-window-list "*Examine*" nil
'visible
)))
3034 (setq win
(idlwave-display-buffer
3037 (let ((list winlist
) thiswin
)
3039 (save-selected-window
3040 (while (setq thiswin
(pop list
))
3041 (select-window thiswin
)
3043 (throw 'exit
(window-frame thiswin
)))))))))
3044 (set-window-start win
(point-min)) ; Ensure the point is visible.
3045 (save-selected-window
3047 (let ((elt (assoc win idlwave-shell-examine-window-alist
)))
3048 (when (and (not (one-window-p))
3049 (or (not (memq win winlist
)) ;a newly created window
3050 (eq (window-height) (cdr elt
))))
3052 (enlarge-window (- (/ (frame-height) 2)
3054 (shrink-window-if-larger-than-buffer)
3055 ;; Clean the window list of dead windows
3056 (setq idlwave-shell-examine-window-alist
3058 (mapcar (lambda (x) (if (window-live-p (car x
)) x
))
3059 idlwave-shell-examine-window-alist
)))
3060 ;; And add the new value.
3061 (if (setq elt
(assoc win idlwave-shell-examine-window-alist
))
3062 (setcdr elt
(window-height))
3063 (add-to-list 'idlwave-shell-examine-window-alist
3064 (cons win
(window-height)))))))))
3065 ;; Recenter for maximum output, after widened
3066 (save-selected-window
3068 (goto-char (point-max))
3069 (skip-chars-backward "\n")
3072 (defun idlwave-shell-examine-display-quit ()
3074 (let ((win (selected-window)))
3076 (delete-frame (window-frame win
))
3077 (delete-window win
))))
3079 (defun idlwave-shell-examine-display-clear ()
3081 (let ((buf (get-buffer "*Examine*")))
3083 (with-current-buffer buf
3084 (let ((inhibit-read-only t
))
3087 (defun idlwave-retrieve-expression-from-level (expr level
)
3088 "Return IDL command to print the expression EXPR from stack level LEVEL.
3090 It does not seem possible to evaluate an expression on a different
3091 level than the current. Therefore, this function retrieves variables
3092 by reference from other levels, and then includes that variable in
3093 place of the chosen one.
3095 Since this function depends upon the undocumented IDL routine
3096 routine_names, there is no guarantee that this will work with future
3098 (let ((fetch (- 0 level
))
3100 var fetch-start fetch-end pre post
)
3102 ;; FIXME: In the following we try to find the variables in expression
3103 ;; This is quite empirical - I don't know in what situations this will
3104 ;; break. We will look for identifiers and exclude cases where we
3105 ;; know it is not a variable. To distinguish array references from
3106 ;; function calls, we require that arrays use [] instead of ()
3108 (while (string-match
3109 "\\(\\`\\|[^a-zA-Z0-9$_][ \t]*\\)\\([a-zA-Z][a-zA-Z0-9$_]*\\)\\([ \t]*[^a-zA-Z0-9$_]\\|\\'\\)" expr start
)
3110 (setq var
(match-string 2 expr
)
3112 pre
(substring expr
0 (match-beginning 2))
3113 post
(substring expr
(match-end 2)))
3116 ;; Exclude identifiers which are not variables
3117 (string-match ",[ \t$\n]*/\\'" pre
) ;; a `/' KEYWORD
3118 (and (string-match "[,(][ \t\n]*\\'" pre
)
3119 (string-match "\\`[ \t]*=" post
)) ;; a `=' KEYWORD
3120 (string-match "\\`(" post
) ;; a function
3121 (string-match "->[ \t]*\\'" pre
) ;; a method
3122 (string-match "\\.\\'" pre
))) ;; structure member
3124 ;; Skip over strings
3125 ((and (string-match "\\([\"']\\)[^\1]*$" pre
)
3126 (string-match (concat "^[^" (match-string 1 pre
) "]*"
3127 (match-string 1 pre
)) post
))
3128 (setq start
(+ start
(match-end 0))))
3131 ;; seems to be a variable - delimit its name
3133 (put-text-property start
(- start
(length var
)) 'fetch t expr
))))
3136 (while (setq fetch-start
3137 (next-single-property-change start
'fetch expr
))
3138 (if (get-text-property start
'fetch expr
) ; it's on in range
3139 (setq fetch-end fetch-start
;it's off in range
3141 (setq fetch-end
(next-single-property-change fetch-start
'fetch expr
)))
3142 (unless fetch-end
(setq fetch-end
(length expr
)))
3143 (remove-text-properties fetch-start fetch-end
'(fetch) expr
)
3144 (setq expr
(concat (substring expr
0 fetch-start
)
3145 (format "(routine_names('%s',fetch=%d))"
3146 (substring expr fetch-start fetch-end
)
3148 (substring expr fetch-end
)))
3149 (setq start fetch-end
))
3150 (if (get-text-property 0 'fetch expr
) ; Full expression, left over
3151 (setq expr
(format "(routine_names('%s',fetch=%d))" expr fetch
)))
3155 (defun idlwave-shell-help-statement (help expr
)
3156 "Construct a help statement for printing expression EXPR.
3158 HELP can be non-nil for `help,', nil for 'print,' or any string into which
3159 to insert expression in place of the marker ___, e.g.: print,
3160 size(___,/DIMENSIONS)"
3163 (concat "idlwave_print_safe, " expr
","
3164 (number-to-string idlwave-shell-max-print-length
)))
3166 (if (string-match "\\(^\\|[^_]\\)\\(___\\)\\([^_]\\|$\\)" help
)
3167 (concat (substring help
0 (match-beginning 2))
3169 (substring help
(match-end 2)))))
3171 (concat "help, " expr
))))
3174 (defun idlwave-shell-examine-highlight ()
3175 "Highlight the most recent IDL output."
3176 (let* ((buffer (get-buffer (idlwave-shell-buffer)))
3177 (process (get-buffer-process buffer
))
3178 (process-mark (if process
(process-mark process
)))
3179 output-begin output-end
)
3180 (with-current-buffer buffer
3181 (goto-char process-mark
)
3183 (setq output-end
(point))
3184 (re-search-backward idlwave-shell-prompt-pattern nil t
)
3185 (beginning-of-line 2)
3186 (setq output-begin
(point)))
3188 ;; First make sure the shell window is visible
3189 (idlwave-display-buffer (idlwave-shell-buffer)
3190 nil
(idlwave-shell-shell-frame))
3191 (if (and idlwave-shell-output-overlay process-mark
)
3192 (move-overlay idlwave-shell-output-overlay
3193 output-begin output-end buffer
))))
3195 (defun idlwave-shell-delete-output-overlay ()
3196 (unless (or (eq this-command
'idlwave-shell-mouse-nop
)
3197 (eq this-command
'handle-switch-frame
))
3199 (if idlwave-shell-output-overlay
3200 (delete-overlay idlwave-shell-output-overlay
))
3202 (remove-hook 'pre-command-hook
'idlwave-shell-delete-output-overlay
)))
3204 (defun idlwave-shell-delete-expression-overlay ()
3205 (unless (or (eq this-command
'idlwave-shell-mouse-nop
)
3206 (eq this-command
'handle-switch-frame
))
3208 (if idlwave-shell-expression-overlay
3209 (delete-overlay idlwave-shell-expression-overlay
))
3211 (remove-hook 'pre-command-hook
'idlwave-shell-delete-expression-overlay
)))
3213 (defvar idlwave-shell-bp-alist nil
3214 "Alist of breakpoints.
3215 A breakpoint is a cons cell \((file line) . \((index module) data))
3217 The car is the `frame' for the breakpoint:
3218 file - full path file name.
3219 line - line number of breakpoint - integer.
3221 The first element of the cdr is a list of internal IDL data:
3222 index - the index number of the breakpoint internal to IDL.
3223 module - the module for breakpoint internal to IDL.
3225 Remaining elements of the cdr:
3226 data - Data associated with the breakpoint by idlwave-shell currently
3227 contains four items:
3229 count - number of times to execute breakpoint. When count reaches 0
3230 the breakpoint is cleared and removed from the alist.
3232 command - command to execute when breakpoint is reached, either a
3233 lisp function to be called with `funcall' with no arguments or a
3234 list to be evaluated with `eval'.
3236 condition - any condition to apply to the breakpoint.
3238 disabled - whether the bp is disabled.")
3240 (defun idlwave-shell-run-region (beg end
&optional n
)
3241 "Compile and run the region using the IDL process.
3242 Copies the region to a temporary file `idlwave-shell-temp-pro-file'
3243 and issues the IDL .run command for the file. Because the region
3244 is compiled and run as a main program there is no problem with
3245 begin-end blocks extending over multiple lines - which would be
3246 a problem if `idlwave-shell-evaluate-region' was used.
3247 An END statement is appended to the region if necessary.
3249 If there is a prefix argument, display IDL process."
3250 (interactive "r\nP")
3251 (let ((oldbuf (current-buffer)))
3252 (with-current-buffer (idlwave-find-file-noselect
3253 (idlwave-shell-temp-file 'pro
) 'tmp
)
3254 (set (make-local-variable 'comment-start-skip
) ";+[ \t]*")
3255 (set (make-local-variable 'comment-start
) ";")
3257 (insert-buffer-substring oldbuf beg end
)
3258 (if (not (save-excursion
3259 (idlwave-previous-statement)
3260 (idlwave-look-at "\\<end\\>")))
3263 (idlwave-shell-send-command (concat ".run \""
3264 idlwave-shell-temp-pro-file
"\"")
3266 (if (idlwave-shell-hide-p 'run
) 'mostly
)
3269 (idlwave-display-buffer (idlwave-shell-buffer)
3270 nil
(idlwave-shell-shell-frame))))
3272 (defun idlwave-shell-evaluate-region (beg end
&optional n
)
3273 "Send region to the IDL process.
3274 If there is a prefix argument, display IDL process.
3275 Does not work for a region with multiline blocks - use
3276 `idlwave-shell-run-region' for this."
3277 (interactive "r\nP")
3278 (idlwave-shell-send-command (buffer-substring beg end
))
3280 (idlwave-display-buffer (idlwave-shell-buffer)
3281 nil
(idlwave-shell-shell-frame))))
3283 (defun idlwave-shell-delete-temp-files ()
3284 "Delete the temporary files and kill associated buffers."
3285 (if (stringp idlwave-shell-temp-pro-file
)
3287 (let ((buf (idlwave-get-buffer-visiting
3288 idlwave-shell-temp-pro-file
)))
3289 (if (buffer-live-p buf
)
3291 (delete-file idlwave-shell-temp-pro-file
))
3293 (if (stringp idlwave-shell-temp-rinfo-save-file
)
3295 (delete-file idlwave-shell-temp-rinfo-save-file
)
3298 (defun idlwave-display-buffer (buf not-this-window-p
&optional frame
)
3299 (if (featurep 'xemacs
)
3300 ;; The XEmacs version enforces the frame
3301 (display-buffer buf not-this-window-p frame
)
3302 ;; For Emacs, we need to force the frame ourselves.
3303 (let ((this-frame (selected-frame)))
3304 (save-excursion ;; make sure we end up in the same buffer
3305 (if (frame-live-p frame
)
3306 (select-frame frame
))
3307 (if (eq this-frame
(selected-frame))
3308 ;; same frame: use display buffer, to make sure the current
3310 (display-buffer buf
)
3313 ;; only window: switch
3315 (switch-to-buffer buf
)
3316 (selected-window)) ; must return the window.
3317 ;; several windows - use display-buffer
3318 (display-buffer buf not-this-window-p
)))))))
3319 ; (if (not (frame-live-p frame)) (setq frame nil))
3320 ; (display-buffer buf not-this-window-p frame))
3322 (defvar idlwave-shell-bp-buffer
" *idlwave-shell-bp*"
3323 "Scratch buffer for parsing IDL breakpoint lists and other stuff.")
3325 (defun idlwave-shell-bp-query (&optional no-show
)
3326 "Reconcile idlwave-shell's breakpoint list with IDL's.
3327 Queries IDL using the string in `idlwave-shell-bp-query'."
3329 (idlwave-shell-send-command idlwave-shell-bp-query
3331 (idlwave-shell-filter-bp (quote ,no-show
)))
3334 (defun idlwave-shell-bp-get (bp &optional item
)
3335 "Get a value for a breakpoint.
3336 BP has the form of elements in `idlwave-shell-bp-alist'.
3337 Optional second arg ITEM is the particular value to retrieve.
3338 ITEM can be 'file, 'line, 'index, 'module, 'count, 'cmd,
3339 'condition, 'disabled, 'type, or 'data. 'data returns a list
3340 of 'count, 'cmd and 'condition. Defaults to 'index."
3343 ((eq item
'line
) (nth 1 (car bp
)))
3344 ((eq item
'file
) (nth 0 (car bp
)))
3345 ;; idlwave-shell breakpoint data
3346 ((eq item
'data
) (cdr (cdr bp
)))
3347 ((eq item
'count
) (nth 0 (cdr (cdr bp
))))
3348 ((eq item
'cmd
) (nth 1 (cdr (cdr bp
))))
3349 ((eq item
'condition
) (nth 2 (cdr (cdr bp
))))
3350 ((eq item
'disabled
) (nth 3 (cdr (cdr bp
))))
3351 ;; IDL breakpoint info
3353 (let ((module (nth 1 (car (cdr bp
)))))
3354 (if (listp module
) (car module
) module
)))
3356 (let ((module (nth 1 (car (cdr bp
)))))
3357 (if (listp module
) (nth 1 module
))))
3359 (t (nth 0 (car (cdr bp
))))))
3361 (defun idlwave-shell-filter-bp (&optional no-show
)
3362 "Get the breakpoints from `idlwave-shell-command-output'.
3363 Create `idlwave-shell-bp-alist' updating breakpoint count and command
3364 data from previous breakpoint list. If NO-SHOW is set, don't update
3365 the breakpoint overlays."
3366 (with-current-buffer (get-buffer-create idlwave-shell-bp-buffer
)
3368 (insert idlwave-shell-command-output
)
3369 (goto-char (point-min))
3370 (let ((old-bp-alist idlwave-shell-bp-alist
)
3371 ;; Searching the breakpoints
3372 ;; In IDL 5.5, the breakpoint reporting format changed.
3373 (bp-re54 "^[ \t]*\\([0-9]+\\)[ \t]+\\(\\S-+\\)?[ \t]+\\([0-9]+\\)[ \t]+\\(\\S-+\\)")
3376 "^\\s-*\\([0-9]+\\)" ; 1 index
3377 "\\s-+\\([0-9]+\\)" ; 2 line number
3378 "\\s-+\\(Uncompiled\\|" ; 3-6 either uncompiled or routine name
3379 "\\(\\(Func=\\|Pro=\\)\\(\\$?[a-zA-Z][a-zA-Z0-9$_:]*\\$?\\)\\)\\)"
3380 "\\(\\s-*,\\s-*After=[0-9]+/\\([0-9]+\\)?\\)?" ; 7-8 After part
3381 "\\(\\s-*,\\s-*\\(BreakOnce\\)\\)?" ; 9-10 BreakOnce
3382 "\\(\\s-*,\\s-*\\(Condition='\\(.*\\)'\\)\n?\\)?" ; 11-13 Condition
3383 "\\(\\s-*,\\s-*\\(Disabled\\)\n?\\)?" ; 14-15 Disabled
3384 "\\s-+\\(\\S-+\\)")) ; 16 File name
3385 file line index module
3386 count condition disabled
3388 (setq idlwave-shell-bp-alist
(list nil
))
3389 ;; Search for either header type, and set the correct regexp
3391 (if (re-search-forward "^\\s-*Index.*\n\\s-*-" nil t
)
3392 (setq bp-re bp-re54
; versions <= 5.4
3393 indmap
'(1 2 3 4))) ;index module line file
3394 (if (re-search-forward
3395 "^\\s-*Index\\s-*Line\\s-*Attributes\\s-*File" nil t
)
3396 (setq bp-re bp-re55
; versions >= 5.5
3397 indmap
'(1 6 2 16)))) ; index module line file
3398 ;; There seems to be a breakpoint listing here, parse breakpoint lines.
3399 (while (re-search-forward bp-re nil t
)
3400 (setq index
(string-to-number (match-string (nth 0 indmap
)))
3401 module
(match-string (nth 1 indmap
))
3402 line
(string-to-number (match-string (nth 2 indmap
)))
3403 file
(idlwave-shell-file-name (match-string (nth 3 indmap
))))
3404 (if (eq bp-re bp-re55
)
3405 (setq count
(if (match-string 10) 1
3406 (if (match-string 8)
3407 (string-to-number (match-string 8))))
3408 condition
(match-string 13)
3409 disabled
(not (null (match-string 15)))))
3411 ;; Add the breakpoint info to the list
3412 (nconc idlwave-shell-bp-alist
3413 (list (cons (list file line
)
3416 ;; bp data: count, command, condition, disabled
3417 count nil condition disabled
))))))
3418 (setq idlwave-shell-bp-alist
(cdr idlwave-shell-bp-alist
))
3419 ;; Update breakpoint data
3420 (if (eq bp-re bp-re54
)
3421 (mapc 'idlwave-shell-update-bp old-bp-alist
)
3422 (mapc 'idlwave-shell-update-bp-command-only old-bp-alist
))))
3423 ;; Update the breakpoint overlays
3424 (unless no-show
(idlwave-shell-update-bp-overlays))
3425 ;; Return the new list
3426 idlwave-shell-bp-alist
)
3428 (defun idlwave-shell-update-bp-command-only (bp)
3429 (idlwave-shell-update-bp bp t
))
3431 (defun idlwave-shell-update-bp (bp &optional command-only
)
3432 "Update BP data in breakpoint list.
3433 If BP frame is in `idlwave-shell-bp-alist' updates the breakpoint data."
3434 (let ((match (assoc (car bp
) idlwave-shell-bp-alist
)))
3437 (setf (nth 1 (cdr (cdr match
))) (nth 1 (cdr (cdr match
))))
3438 (setcdr (cdr match
) (cdr (cdr bp
)))))))
3440 (defun idlwave-shell-set-bp-data (bp data
)
3441 "Set the data of BP to DATA."
3442 (setcdr (cdr bp
) data
))
3444 (defun idlwave-shell-bp (frame &optional data module
)
3445 "Create a breakpoint structure containing FRAME and DATA.
3446 Second and third args, DATA and MODULE, are optional. Returns
3447 a breakpoint of the format used in `idlwave-shell-bp-alist'.
3448 Can be used in commands attempting match a breakpoint in
3449 `idlwave-shell-bp-alist'."
3450 (cons frame
;; (file line)
3451 (cons (list nil module
) ;; (index_id (module type) | module)
3452 data
))) ;; (count command condition disabled)
3454 (defvar idlwave-shell-old-bp nil
3455 "List of breakpoints previous to setting a new breakpoint.")
3457 (defun idlwave-shell-sources-bp (bp)
3458 "Check `idlwave-shell-sources-alist' for source of breakpoint using BP.
3459 If an equivalency is found, return the IDL internal source name.
3460 Otherwise return the filename in BP."
3462 ((bp-file (idlwave-shell-bp-get bp
'file
))
3463 (bp-module (idlwave-shell-bp-get bp
'module
))
3466 (cdr (assoc bp-module idlwave-shell-sources-alist
)))))
3467 (if (and internal-file-list
3468 (equal bp-file
(nth 0 internal-file-list
)))
3469 (nth 1 internal-file-list
)
3472 (defun idlwave-shell-set-bp (bp &optional no-show
)
3473 "Try to set a breakpoint BP.
3474 The breakpoint will be placed at the beginning of the statement on the
3475 line specified by BP or at the next IDL statement if that line is not
3476 a statement. Determines IDL's internal representation for the
3477 breakpoint, which may have occurred at a different line than
3478 specified. If NO-SHOW is non-nil, don't do any updating."
3479 ;; Get and save the old breakpoints
3480 (idlwave-shell-send-command
3481 idlwave-shell-bp-query
3483 (idlwave-shell-filter-bp (quote ,no-show
))
3484 (setq idlwave-shell-old-bp idlwave-shell-bp-alist
))
3487 ;; Get sources for this routine in the sources list
3488 (idlwave-shell-module-source-query (idlwave-shell-bp-get bp
'module
)
3489 (idlwave-shell-bp-get bp
'type
))
3491 ((count (idlwave-shell-bp-get bp
'count
))
3492 (condition (idlwave-shell-bp-get bp
'condition
))
3493 (disabled (idlwave-shell-bp-get bp
'disabled
))
3494 (key (concat (if (and count
(numberp count
))
3496 ((= count
1) ",/once")
3497 ((> count
1) (format ",after=%d" count
))))
3498 (if condition
(concat ",CONDITION=\"" condition
"\""))
3499 ;; IDL can't simultaneously set a condition/count
3500 ;; and disable a breakpoint, but it does keep both
3501 ;; of these when resetting the same BP. We assume
3502 ;; DISABLE and CONDITION/COUNT are not set
3503 ;; together for a newly created breakpoint.
3504 (if (and disabled
(not condition
) (not count
))
3506 (line (idlwave-shell-bp-get bp
'line
)))
3507 (idlwave-shell-send-command
3508 (concat "breakpoint,'"
3509 (idlwave-shell-sources-bp bp
) "',"
3510 (if (integerp line
) (setq line
(int-to-string line
)))
3512 ;; Check for failure and adjust breakpoint to match IDL's list
3514 (if (idlwave-shell-set-bp-check (quote ,bp
))
3515 (idlwave-shell-set-bp-adjust (quote ,bp
) (quote ,no-show
))))
3517 (idlwave-shell-hide-p 'breakpoint
)
3520 (defun idlwave-shell-set-bp-adjust (bp &optional no-show
)
3521 "Find the breakpoint in IDL's internal list of breakpoints."
3522 (idlwave-shell-send-command
3523 idlwave-shell-bp-query
3525 (idlwave-shell-filter-bp 'no-show
)
3526 (idlwave-shell-new-bp (quote ,bp
))
3527 (unless (quote ,no-show
)
3528 (idlwave-shell-update-bp-overlays)))
3532 (defun idlwave-shell-find-bp (frame)
3533 "Return breakpoint from `idlwave-shell-bp-alist' for frame.
3534 Returns nil if frame not found."
3535 (assoc frame idlwave-shell-bp-alist
))
3537 (defun idlwave-shell-find-current-bp ()
3538 "Find breakpoint here, or at halt location."
3539 (let ((bp (idlwave-shell-find-bp (idlwave-shell-current-frame))))
3541 ;; Try moving to beginning of halted-at statement
3543 (idlwave-shell-goto-frame)
3544 (idlwave-beginning-of-statement)
3545 (setq bp
(idlwave-shell-find-bp (idlwave-shell-current-frame))))
3548 (message "Cannot identify breakpoint for this line")))
3551 (defun idlwave-shell-new-bp (bp)
3552 "Find the new breakpoint in IDL's list and update with DATA.
3553 The actual line number for a breakpoint in IDL may be different than
3554 the line number used with the IDL breakpoint command.
3555 Looks for a new breakpoint index number in the list. This is
3556 considered the new breakpoint if the file name of frame matches."
3557 (let ((obp-index (mapcar 'idlwave-shell-bp-get idlwave-shell-old-bp
))
3558 (bpl idlwave-shell-bp-alist
))
3559 (while (and (member (idlwave-shell-bp-get (car bpl
)) obp-index
)
3560 (setq bpl
(cdr bpl
))))
3563 ;; No additional breakpoint.
3564 ;; Need to check if we are just replacing a breakpoint.
3565 (setq bpl
(assoc (car bp
) idlwave-shell-bp-alist
)))
3566 (setq bpl
(list bpl
)))
3568 (equal (idlwave-shell-bp-get (setq bpl
(car bpl
)) 'file
)
3569 (idlwave-shell-bp-get bp
'file
)))
3570 ;; Got the breakpoint - add count, command to it.
3571 ;; This updates `idlwave-shell-bp-alist' because a deep copy was
3572 ;; not done for bpl.
3573 (idlwave-shell-set-bp-data bpl
(idlwave-shell-bp-get bp
'data
))
3575 (message "Failed to identify breakpoint in IDL"))))
3577 (defvar idlwave-shell-bp-overlays nil
3578 "Alist of overlays marking breakpoints.")
3579 (defvar idlwave-shell-bp-glyph
)
3581 (defvar idlwave-shell-debug-line-map
(make-sparse-keymap))
3582 (define-key idlwave-shell-debug-line-map
3583 (if (featurep 'xemacs
) [button3] [mouse-3])
3584 'idlwave-shell-mouse-active-bp)
3586 (defun idlwave-shell-update-bp-overlays ()
3587 "Update the overlays which mark breakpoints in the source code.
3588 Existing overlays are recycled, in order to minimize consumption."
3589 (when idlwave-shell-mark-breakpoints
3590 (let ((ov-alist (copy-alist idlwave-shell-bp-overlays))
3591 (bp-list idlwave-shell-bp-alist)
3592 (use-glyph (and (memq idlwave-shell-mark-breakpoints '(t glyph))
3593 idlwave-shell-bp-glyph))
3594 ov ov-list bp buf old-buffers win)
3596 ;; Delete the old overlays from their buffers
3598 (while (setq ov-list (pop ov-alist))
3599 (while (setq ov (pop (cdr ov-list)))
3600 (add-to-list 'old-buffers (overlay-buffer ov))
3601 (delete-overlay ov))))
3603 (setq ov-alist idlwave-shell-bp-overlays
3604 idlwave-shell-bp-overlays
3605 (if idlwave-shell-bp-glyph
3606 (mapcar 'list (mapcar 'car idlwave-shell-bp-glyph))
3608 (while (setq bp (pop bp-list))
3610 (idlwave-shell-goto-frame (car bp))
3611 (let* ((end (point-at-eol))
3612 (beg (progn (beginning-of-line 1) (point)))
3613 (condition (idlwave-shell-bp-get bp 'condition))
3614 (count (idlwave-shell-bp-get bp 'count))
3615 (disabled (idlwave-shell-bp-get bp 'disabled))
3616 (type (if idlwave-shell-bp-glyph
3618 (condition 'bp-cond )
3624 (concat "bp-" (number-to-string count))))
3632 (concat "after:" (int-to-string count)))
3634 (concat "condition:" condition))
3635 (if disabled "disabled"))))
3638 (int-to-string (idlwave-shell-bp-get bp))
3642 (mapconcat 'identity help-list ", ")))
3643 (if (and (not count) (not condition))
3644 " (use mouse-3 for breakpoint actions)")))
3645 (full-type (if disabled
3646 (intern (concat (symbol-name type)
3649 (ov-existing (assq full-type ov-alist))
3650 (ov (or (and (cdr ov-existing)
3651 (pop (cdr ov-existing)))
3652 (idlwave-shell-make-new-bp-overlay type disabled)))
3654 (if idlwave-shell-breakpoint-popup-menu
3655 (overlay-put ov 'help-echo help-text))
3656 (move-overlay ov beg end)
3657 (if (setq match (assq full-type idlwave-shell-bp-overlays))
3658 (push ov (cdr match))
3659 (nconc idlwave-shell-bp-overlays
3660 (list (list full-type ov)))))
3661 ;; Take care of margins if using a glyph
3664 (setq old-buffers (delq (current-buffer) old-buffers)))
3665 (if (fboundp 'set-specifier) ;; XEmacs
3666 (set-specifier left-margin-width (cons (current-buffer) 2))
3667 (if (< left-margin-width 2)
3668 (setq left-margin-width 2)))
3669 (let ((window (get-buffer-window (current-buffer) 0)))
3672 window left-margin-width right-margin-width))))))
3674 (while (setq buf (pop old-buffers))
3675 (with-current-buffer buf
3676 (if (fboundp 'set-specifier) ;; XEmacs
3677 (set-specifier left-margin-width (cons (current-buffer) 0))
3678 (setq left-margin-width 0))
3679 (let ((window (get-buffer-window buf 0)))
3682 window left-margin-width right-margin-width)))))))))
3684 (defun idlwave-shell-make-new-bp-overlay (&optional type disabled)
3685 "Make a new overlay for highlighting breakpoints.
3687 This stuff is strongly dependent upon the version of Emacs. If TYPE
3688 is passed, make an overlay of that type ('bp or 'bp-cond, currently
3690 (let ((ov (make-overlay 1 1))
3691 (use-glyph (and (memq idlwave-shell-mark-breakpoints '(t glyph))
3692 idlwave-shell-bp-glyph))
3693 (type (or type 'bp))
3695 idlwave-shell-disabled-breakpoint-face
3696 idlwave-shell-breakpoint-face)))
3697 (if (featurep 'xemacs)
3700 (when idlwave-shell-breakpoint-popup-menu
3701 (set-extent-property ov 'mouse-face 'highlight)
3702 (set-extent-property ov 'keymap idlwave-shell-debug-line-map))
3705 ;; tty's cannot display glyphs
3706 ((eq (console-type) 'tty)
3707 (set-extent-property ov 'face face))
3711 (let ((glyph (cdr (assq type idlwave-shell-bp-glyph))))
3712 (if disabled (setq glyph (car glyph)) (setq glyph (nth 1 glyph)))
3713 (set-extent-property ov 'begin-glyph glyph)
3714 (set-extent-property ov 'begin-glyph-layout 'outside-margin)))
3717 (idlwave-shell-mark-breakpoints
3718 (set-extent-property ov 'face face))
3722 (set-extent-priority ov -1)) ; make stop line face prevail
3724 (when idlwave-shell-breakpoint-popup-menu
3725 (overlay-put ov 'mouse-face 'highlight)
3726 (overlay-put ov 'keymap idlwave-shell-debug-line-map))
3730 (let ((image-props (cdr (assq type idlwave-shell-bp-glyph)))
3733 (if disabled (setq image-props
3735 (list :conversion 'disabled))))
3739 (list (list 'margin 'left-margin)
3741 (overlay-put ov 'before-string string))
3743 (overlay-put ov 'face face)))
3746 (idlwave-shell-mark-breakpoints
3747 (overlay-put ov 'face face))
3753 (defun idlwave-shell-mouse-active-bp (ev)
3754 "Does right-click mouse action on breakpoint lines."
3756 (if ev (mouse-set-point ev))
3757 (let ((bp (idlwave-shell-find-bp (idlwave-shell-current-frame)))
3758 index condition count select cmd disabled)
3760 (error "Breakpoint not found"))
3761 (setq index (int-to-string (idlwave-shell-bp-get bp))
3762 condition (idlwave-shell-bp-get bp 'condition)
3763 cmd (idlwave-shell-bp-get bp 'cmd)
3764 count (idlwave-shell-bp-get bp 'count)
3765 disabled (idlwave-shell-bp-get bp 'disabled))
3766 (setq select (idlwave-popup-select
3769 (list (if disabled "Enable" "Disable")
3772 (if condition "Remove Condition" "Add Condition")
3773 (if condition "Change Condition")
3774 (if count "Remove Repeat Count"
3776 (if count "Change Repeat Count")))
3777 (concat "BreakPoint " index)))
3780 ((string-equal select "Clear All")
3781 (idlwave-shell-clear-all-bp))
3782 ((string-equal select "Clear")
3783 (idlwave-shell-clear-current-bp))
3784 ((string-match "Condition" select)
3785 (idlwave-shell-break-here count cmd
3786 (if (or (not condition)
3787 (string-match "Change" select))
3788 (read-string "Break Condition: "))
3790 ((string-match "Count" select)
3791 (idlwave-shell-break-here (if (or (not count)
3792 (string-match "Change" select))
3794 (read-string "Break After Count: ")))
3795 cmd condition disabled))
3796 ((string-match "able$" select)
3797 (idlwave-shell-toggle-enable-current-bp))
3799 (message "Unimplemented: %s" select))))))
3801 (defun idlwave-shell-edit-default-command-line (arg)
3802 "Edit the current execute command."
3804 (setq idlwave-shell-command-line-to-execute
3805 (read-string "IDL> " idlwave-shell-command-line-to-execute)))
3807 (defun idlwave-shell-execute-default-command-line (arg)
3808 "Execute a command line. On first use, ask for the command.
3809 Also with prefix arg, ask for the command. You can also use the command
3810 `idlwave-shell-edit-default-command-line' to edit the line."
3814 (setq idlwave-shell-command-line-to-execute nil))
3816 (setq idlwave-shell-command-line-to-execute
3817 (read-string "IDL> " idlwave-shell-command-line-to-execute))))
3818 (idlwave-shell-reset 'hidden)
3819 (idlwave-shell-send-command
3820 (or idlwave-shell-command-line-to-execute
3821 (with-current-buffer (idlwave-shell-buffer)
3822 (ring-ref comint-input-ring 0)))
3823 '(idlwave-shell-redisplay 'hide)))
3825 (defun idlwave-shell-save-and-run ()
3826 "Save file and run it in IDL.
3827 Runs `save-buffer' and sends a '.RUN' command for the associated file to IDL.
3828 When called from the shell buffer, re-run the file which was last handled by
3829 one of the save-and-.. commands."
3831 (idlwave-shell-save-and-action 'run))
3833 (defun idlwave-shell-save-and-compile ()
3834 "Save file and run it in IDL.
3835 Runs `save-buffer' and sends '.COMPILE' command for the associated file to IDL.
3836 When called from the shell buffer, re-compile the file which was last handled by
3837 one of the save-and-.. commands."
3839 (idlwave-shell-save-and-action 'compile))
3841 (defun idlwave-shell-save-and-batch ()
3842 "Save file and batch it in IDL.
3843 Runs `save-buffer' and sends a '@file' command for the associated file to IDL.
3844 When called from the shell buffer, re-batch the file which was last handled by
3845 one of the save-and-.. commands."
3847 (idlwave-shell-save-and-action 'batch))
3849 (defun idlwave-shell-save-and-action (action)
3850 "Save file and compile it in IDL.
3851 Runs `save-buffer' and sends a '.RUN' command for the associated file to IDL.
3852 When called from the shell buffer, re-compile the file which was last
3853 handled by this command."
3854 ;; Remove the stop overlay.
3855 (if idlwave-shell-stop-line-overlay
3856 (delete-overlay idlwave-shell-stop-line-overlay))
3857 (if idlwave-shell-is-stopped
3858 (idlwave-shell-electric-debug-all-off))
3859 (setq idlwave-shell-is-stopped nil)
3860 (setq overlay-arrow-string nil)
3863 ((derived-mode-p 'idlwave-mode)
3865 (setq idlwave-shell-last-save-and-action-file (buffer-file-name)))
3866 (idlwave-shell-last-save-and-action-file
3867 (if (setq buf (idlwave-get-buffer-visiting
3868 idlwave-shell-last-save-and-action-file))
3869 (with-current-buffer buf
3871 (t (setq idlwave-shell-last-save-and-action-file
3872 (read-file-name "File: ")))))
3873 (if (file-regular-p idlwave-shell-last-save-and-action-file)
3875 (idlwave-shell-send-command
3876 (concat (cond ((eq action 'run) ".run ")
3877 ((eq action 'compile) ".compile ")
3878 ((eq action 'batch) "@")
3879 (t (error "Unknown action %s" action)))
3881 idlwave-shell-last-save-and-action-file
3883 `(idlwave-shell-maybe-update-routine-info nil
3884 ,idlwave-shell-last-save-and-action-file)
3885 (if (idlwave-shell-hide-p 'run) 'mostly) nil t)
3886 (idlwave-shell-bp-query))
3887 (let ((msg (format "No such file %s"
3888 idlwave-shell-last-save-and-action-file)))
3889 (setq idlwave-shell-last-save-and-action-file nil)
3892 (defun idlwave-shell-maybe-update-routine-info (&optional wait file)
3893 "Update the routine info if the shell is not stopped at an error."
3894 (if (and (not idlwave-shell-is-stopped)
3895 (or (eq t idlwave-auto-routine-info-updates)
3896 (memq 'compile-buffer idlwave-auto-routine-info-updates))
3897 idlwave-query-shell-for-routine-info
3899 (idlwave-shell-update-routine-info t nil wait file)))
3901 (defvar idlwave-shell-sources-query "help,/source,/full"
3902 "IDL command to obtain source files for compiled procedures.")
3904 (defvar idlwave-shell-sources-alist nil
3905 "Alist of IDL procedure names and compiled source files.
3906 Elements of the alist have the form:
3908 (module name . (source-file-truename idlwave-internal-filename))")
3910 (defun idlwave-shell-module-source-query (module &optional type)
3911 "Determine the source file for a given module.
3912 Query as a function if TYPE set to something beside `pro'."
3914 (idlwave-shell-send-command
3915 (format "print,(routine_info('%s',/SOURCE%s)).PATH" module
3916 (if (eq type 'pro) "" ",/FUNCTIONS"))
3917 `(idlwave-shell-module-source-filter ,module)
3920 (defun idlwave-shell-module-source-filter (module)
3921 "Get module source, and update `idlwave-shell-sources-alist'."
3922 (let ((old (assoc (upcase module) idlwave-shell-sources-alist))
3924 (when (string-match ".PATH *[\n\r]\\([^%][^\r\n]+\\)[\n\r]"
3925 idlwave-shell-command-output)
3926 (setq filename (substring idlwave-shell-command-output
3927 (match-beginning 1) (match-end 1)))
3929 (setcdr old (list (idlwave-shell-file-name filename) filename))
3930 (setq idlwave-shell-sources-alist
3931 (append idlwave-shell-sources-alist
3932 (list (cons (upcase module)
3933 (list (idlwave-shell-file-name filename)
3936 (defun idlwave-shell-sources-query ()
3937 "Determine source files for all IDL compiled procedures.
3938 Queries IDL using the string in `idlwave-shell-sources-query'."
3940 (idlwave-shell-send-command idlwave-shell-sources-query
3941 'idlwave-shell-sources-filter
3944 (defun idlwave-shell-sources-filter ()
3945 "Get source files from `idlwave-shell-sources-query' output.
3946 Create `idlwave-shell-sources-alist' consisting of list elements
3948 (module name . (source-file-truename idlwave-internal-filename))"
3949 (with-current-buffer (get-buffer-create idlwave-shell-bp-buffer)
3951 (insert idlwave-shell-command-output)
3952 (goto-char (point-min))
3954 (if (re-search-forward "Compiled Procedures:" nil t)
3956 (forward-line) ; Skip $MAIN$
3957 (setq cpro (point))))
3958 (if (re-search-forward "Compiled Functions:" nil t)
3961 (setq idlwave-shell-sources-alist
3963 ;; compiled procedures
3965 (narrow-to-region cpro (point-at-bol))
3966 (goto-char (point-min))
3967 (idlwave-shell-sources-grep))
3968 ;; compiled functions
3972 (idlwave-shell-sources-grep)))))))))
3974 (defun idlwave-shell-sources-grep ()
3976 (let ((al (list nil)))
3978 (not (progn (forward-line) (eobp)))
3980 "\\s-*\\(\\S-+\\)\\s-+\\(\\S-+\\)" nil t))
3984 (buffer-substring ; name
3985 (match-beginning 1) (match-end 1))
3986 (let ((internal-filename
3987 (buffer-substring ; source
3988 (match-beginning 2) (match-end 2))))
3990 (idlwave-shell-file-name internal-filename)
3995 (defun idlwave-shell-clear-all-bp ()
3996 "Remove all breakpoints in IDL."
3998 (idlwave-shell-send-command
3999 idlwave-shell-bp-query
4001 (idlwave-shell-filter-bp)
4002 (mapcar (lambda (x) (idlwave-shell-clear-bp x 'no-query))
4003 idlwave-shell-bp-alist)
4004 (idlwave-shell-bp-query))
4007 (defun idlwave-shell-list-all-bp ()
4008 "List all breakpoints in IDL."
4010 (idlwave-shell-send-command
4011 idlwave-shell-bp-query))
4013 (defvar idlwave-shell-error-last 0
4014 "Position of last syntax error in `idlwave-shell-error-buffer'.")
4016 (defun idlwave-shell-goto-next-error ()
4017 "Move point to next IDL syntax error."
4020 (with-current-buffer idlwave-shell-error-buffer
4021 (goto-char idlwave-shell-error-last)
4023 (re-search-forward idlwave-shell-syntax-error nil t)
4024 (re-search-forward idlwave-shell-other-error nil t))
4029 (idlwave-shell-file-name
4030 (buffer-substring (match-beginning 1 )
4033 (buffer-substring (match-beginning 2)
4035 ;; Try to find the column of the error
4038 (if (re-search-backward "\\^" nil t)
4041 (setq idlwave-shell-error-last (point)))
4044 (idlwave-shell-display-line frame col 'disable))
4046 (message "No more errors."))))
4048 (defun idlwave-shell-file-name (name)
4049 "If `idlwave-shell-use-truename' is non-nil, convert file name to true name.
4050 Otherwise, just expand the file name."
4051 (let ((def-dir (if (derived-mode-p 'idlwave-shell-mode)
4053 idlwave-shell-default-directory)))
4054 (if idlwave-shell-use-truename
4055 (file-truename name def-dir)
4056 (expand-file-name name def-dir))))
4058 ;; Keybindings ------------------------------------------------------------
4060 (defvar idlwave-shell-mode-map (copy-keymap comint-mode-map)
4061 "Keymap for `idlwave-mode'.")
4062 (defvar idlwave-shell-electric-debug-mode-map (make-sparse-keymap))
4063 (defvar idlwave-shell-mode-prefix-map (make-sparse-keymap))
4064 (fset 'idlwave-shell-mode-prefix-map idlwave-shell-mode-prefix-map)
4065 (defvar idlwave-mode-prefix-map (make-sparse-keymap))
4066 (fset 'idlwave-mode-prefix-map idlwave-mode-prefix-map)
4068 (defun idlwave-shell-define-key-both (key hook)
4069 "Define a key in both the shell and buffer mode maps."
4070 (define-key idlwave-mode-map key hook)
4071 (define-key idlwave-shell-mode-map key hook))
4073 ;(define-key idlwave-shell-mode-map "\M-?" 'comint-dynamic-list-completions)
4074 ;(define-key idlwave-shell-mode-map "\t" 'comint-dynamic-complete)
4076 (define-key idlwave-shell-mode-map "\C-w" 'comint-kill-region)
4077 (define-key idlwave-shell-mode-map "\t" 'idlwave-shell-complete)
4078 (define-key idlwave-shell-mode-map "\M-\t" 'idlwave-shell-complete)
4079 (define-key idlwave-shell-mode-map "\C-c\C-s" 'idlwave-shell)
4080 (define-key idlwave-shell-mode-map "\C-c?" 'idlwave-routine-info)
4081 (define-key idlwave-shell-mode-map "\C-g" 'idlwave-keyboard-quit)
4082 (define-key idlwave-shell-mode-map "\M-?" 'idlwave-context-help)
4083 (define-key idlwave-shell-mode-map [(control meta ?\?)]
4084 'idlwave-help-assistant-help-with-topic)
4085 (define-key idlwave-shell-mode-map "\C-c\C-i" 'idlwave-update-routine-info)
4086 (define-key idlwave-shell-mode-map "\C-c\C-y" 'idlwave-shell-char-mode-loop)
4087 (define-key idlwave-shell-mode-map "\C-c\C-x" 'idlwave-shell-send-char)
4088 (define-key idlwave-shell-mode-map "\C-c=" 'idlwave-resolve)
4089 (define-key idlwave-shell-mode-map "\C-c\C-v" 'idlwave-find-module)
4090 (define-key idlwave-shell-mode-map "\C-c\C-k" 'idlwave-kill-autoloaded-buffers)
4091 (define-key idlwave-shell-mode-map idlwave-shell-prefix-key
4092 'idlwave-shell-debug-map)
4093 (define-key idlwave-shell-mode-map [(up)] 'idlwave-shell-up-or-history)
4094 (define-key idlwave-shell-mode-map [(down)] 'idlwave-shell-down-or-history)
4095 (define-key idlwave-mode-map "\C-c\C-y" 'idlwave-shell-char-mode-loop)
4096 (define-key idlwave-mode-map "\C-c\C-x" 'idlwave-shell-send-char)
4098 ;; The mouse bindings for PRINT and HELP
4099 (idlwave-shell-define-key-both
4100 (if (featurep 'xemacs)
4102 [(shift down-mouse-2)])
4103 'idlwave-shell-mouse-print)
4104 (idlwave-shell-define-key-both
4105 (if (featurep 'xemacs)
4106 [(control meta button2)]
4107 [(control meta down-mouse-2)])
4108 'idlwave-shell-mouse-help)
4109 (idlwave-shell-define-key-both
4110 (if (featurep 'xemacs)
4111 [(control shift button2)]
4112 [(control shift down-mouse-2)])
4113 'idlwave-shell-examine-select)
4114 ;; Add this one from the idlwave-mode-map
4115 (define-key idlwave-shell-mode-map
4116 (if (featurep 'xemacs)
4119 'idlwave-mouse-context-help)
4121 ;; For Emacs, we need to turn off the button release events.
4122 (defun idlwave-shell-mouse-nop (event)
4124 (unless (featurep 'xemacs)
4125 (idlwave-shell-define-key-both
4126 [(shift mouse-2)] 'idlwave-shell-mouse-nop)
4127 (idlwave-shell-define-key-both
4128 [(shift control mouse-2)] 'idlwave-shell-mouse-nop)
4129 (idlwave-shell-define-key-both
4130 [(control meta mouse-2)] 'idlwave-shell-mouse-nop))
4133 ;; The following set of bindings is used to bind the debugging keys.
4134 ;; If `idlwave-shell-activate-prefix-keybindings' is non-nil, the
4135 ;; first key in the list gets bound the C-c C-d prefix map. If
4136 ;; `idlwave-shell-debug-modifiers' is non-nil, the second key in the
4137 ;; list gets bound with the specified modifiers in both
4138 ;; `idlwave-mode-map' and `idlwave-shell-mode-map'. The next list
4139 ;; item, if non-nil, means to bind this as a single key in the
4140 ;; electric-debug-mode-map.
4142 ;; [C-c C-d]-binding debug-modifier-key command bind-electric-debug buf-only
4143 ;; Used keys: abcdef hijklmnopqrstuvwxyz
4146 '(([(control ?b)] ?b idlwave-shell-break-here t t)
4147 ([(control ?i)] ?i idlwave-shell-break-in t t)
4148 ([(control ?j)] ?j idlwave-shell-break-this-module t t)
4149 ([(control ?d)] ?d idlwave-shell-clear-current-bp t)
4150 ([(control ?a)] ?a idlwave-shell-clear-all-bp t)
4151 ([(control ?\\)] ?\\ idlwave-shell-toggle-enable-current-bp t)
4152 ([(control ?s)] ?s idlwave-shell-step t)
4153 ([(control ?n)] ?n idlwave-shell-stepover t)
4154 ([(control ?k)] ?k idlwave-shell-skip t)
4155 ([(control ?u)] ?u idlwave-shell-up t)
4156 ([(control ?o)] ?o idlwave-shell-out t)
4157 ([(control ?m)] ?m idlwave-shell-return t)
4158 ([(control ?h)] ?h idlwave-shell-to-here t t)
4159 ([(control ?r)] ?r idlwave-shell-cont t)
4160 ([(control ?y)] ?y idlwave-shell-execute-default-command-line)
4161 ([(control ?z)] ?z idlwave-shell-reset t)
4162 ([(control ?q)] ?q idlwave-shell-quit)
4163 ([(control ?p)] ?p idlwave-shell-print t)
4164 ([( ??)] ?? idlwave-shell-help-expression t)
4165 ([(control ?v)] ?v idlwave-shell-toggle-electric-debug-mode t t)
4166 ([(control ?x)] ?x idlwave-shell-goto-next-error)
4167 ([(control ?c)] ?c idlwave-shell-save-and-run t)
4168 ([( ?@)] ?@ idlwave-shell-save-and-batch)
4169 ([(control ?e)] ?e idlwave-shell-run-region)
4170 ([(control ?w)] ?w idlwave-shell-resync-dirs)
4171 ([(control ?l)] ?l idlwave-shell-redisplay t)
4172 ([(control ?t)] ?t idlwave-shell-toggle-toolbar)
4173 ([(control up)] up idlwave-shell-stack-up)
4174 ([(control down)] down idlwave-shell-stack-down)
4175 ([( ?[)] ?[ idlwave-shell-goto-previous-bp t t)
4176 ([( ?])] ?] idlwave-shell-goto-next-bp t t)
4177 ([(control ?f)] ?f idlwave-shell-window)))
4178 (mod (and (listp idlwave-shell-debug-modifiers)
4179 idlwave-shell-debug-modifiers))
4180 (shift (memq 'shift mod))
4181 (mod-noshift (delete 'shift (copy-sequence mod)))
4182 s k1 c2 k2 cmd electric only-buffer cannotshift)
4183 (while (setq s (pop specs))
4188 only-buffer (nth 4 s)
4189 cannotshift (and shift (characterp c2) (eq c2 (upcase c2))))
4191 ;; The regular prefix keymap.
4192 (when (and idlwave-shell-activate-prefix-keybindings k1)
4194 (define-key idlwave-shell-mode-prefix-map k1 cmd))
4195 (define-key idlwave-mode-prefix-map k1 cmd))
4196 ;; The debug modifier map
4197 (when (and mod window-system)
4198 (if (char-or-string-p c2)
4199 (setq k2 (vector (append mod-noshift
4200 (list (if shift (upcase c2) c2)))))
4201 (setq k2 (vector (append mod (list c2)))))
4203 (define-key idlwave-mode-map k2 cmd)
4204 (unless only-buffer (define-key idlwave-shell-mode-map k2 cmd))))
4205 ;; The electric debug single-keystroke map
4206 (if (and electric (char-or-string-p c2))
4207 (define-key idlwave-shell-electric-debug-mode-map (char-to-string c2)
4210 ;; A few extras in the electric debug map
4211 (define-key idlwave-shell-electric-debug-mode-map " " 'idlwave-shell-step)
4212 (define-key idlwave-shell-electric-debug-mode-map "+" 'idlwave-shell-stack-up)
4213 (define-key idlwave-shell-electric-debug-mode-map "=" 'idlwave-shell-stack-up)
4214 (define-key idlwave-shell-electric-debug-mode-map "-"
4215 'idlwave-shell-stack-down)
4216 (define-key idlwave-shell-electric-debug-mode-map "_"
4217 'idlwave-shell-stack-down)
4218 (define-key idlwave-shell-electric-debug-mode-map "e"
4219 (lambda () (interactive) (idlwave-shell-print '(16))))
4220 (define-key idlwave-shell-electric-debug-mode-map "q" 'idlwave-shell-retall)
4221 (define-key idlwave-shell-electric-debug-mode-map "t"
4222 (lambda () (interactive) (idlwave-shell-send-command "help,/TRACE")))
4223 (define-key idlwave-shell-electric-debug-mode-map [(control ??)]
4224 'idlwave-shell-electric-debug-help)
4225 (define-key idlwave-shell-electric-debug-mode-map "x"
4226 (lambda (arg) (interactive "P")
4227 (idlwave-shell-print arg nil nil t)))
4230 ; Enter the prefix map in two places.
4231 (fset 'idlwave-debug-map idlwave-mode-prefix-map)
4232 (fset 'idlwave-shell-debug-map idlwave-shell-mode-prefix-map)
4234 ;; The Electric Debug Minor Mode --------------------------------------------
4236 (defun idlwave-shell-toggle-electric-debug-mode ()
4237 "Toggle electric-debug-mode, suppressing re-entry into mode if turned off."
4239 ;; If turning it off, make sure it stays off throughout the debug
4240 ;; session until we return or hit $MAIN$. Cancel this suppression
4241 ;; if it's explicitly turned on.
4242 (if idlwave-shell-electric-debug-mode
4243 (progn ;; Turn it off, and make sure it stays off.
4244 (setq idlwave-shell-suppress-electric-debug t)
4245 (idlwave-shell-electric-debug-mode 0))
4246 (setq idlwave-shell-suppress-electric-debug nil)
4247 (idlwave-shell-electric-debug-mode t)))
4249 (defvar idlwave-shell-electric-debug-read-only)
4250 (defvar idlwave-shell-electric-debug-buffers nil)
4252 (define-minor-mode idlwave-shell-electric-debug-mode
4253 "Toggle Idlwave Shell Electric Debug mode.
4254 With a prefix argument ARG, enable the mode if ARG is positive,
4255 and disable it otherwise. If called from Lisp, enable the mode
4256 if ARG is omitted or nil.
4258 When Idlwave Shell Electric Debug mode is enabled, the Idlwave
4259 Shell debugging commands are available as single key sequences."
4260 nil " *Debugging*" idlwave-shell-electric-debug-mode-map)
4263 'idlwave-shell-electric-debug-mode-on-hook
4265 (set (make-local-variable 'idlwave-shell-electric-debug-read-only)
4267 (setq buffer-read-only t)
4268 (add-to-list 'idlwave-shell-electric-debug-buffers (current-buffer))
4269 (if idlwave-shell-stop-line-overlay
4270 (overlay-put idlwave-shell-stop-line-overlay 'face
4271 idlwave-shell-electric-stop-line-face))
4273 (set-face-foreground 'fringe idlwave-shell-electric-stop-color
4274 (selected-frame)))))
4277 'idlwave-shell-electric-debug-mode-off-hook
4279 ;; Return to previous read-only state
4280 (setq buffer-read-only (if (boundp 'idlwave-shell-electric-debug-read-only)
4281 idlwave-shell-electric-debug-read-only))
4282 (setq idlwave-shell-electric-debug-buffers
4283 (delq (current-buffer) idlwave-shell-electric-debug-buffers))
4284 (if idlwave-shell-stop-line-overlay
4285 (overlay-put idlwave-shell-stop-line-overlay 'face
4286 idlwave-shell-stop-line-face)
4288 (set-face-foreground 'fringe (face-foreground 'default))))))
4290 ;; easy-mmode defines electric-debug-mode for us, so we need to advise it.
4291 (defadvice idlwave-shell-electric-debug-mode (after print-enter activate)
4292 "Print out an entrance message."
4293 (when idlwave-shell-electric-debug-mode
4295 "Electric Debugging mode entered. Press [C-?] for help, [q] to quit"))
4296 (force-mode-line-update))
4298 ;; Turn it off in all relevant buffers
4299 (defvar idlwave-shell-electric-debug-buffers nil)
4300 (defun idlwave-shell-electric-debug-all-off ()
4301 (setq idlwave-shell-suppress-electric-debug nil)
4302 (let ((buffers idlwave-shell-electric-debug-buffers)
4305 (while (setq buf (pop buffers))
4306 (when (buffer-live-p buf)
4308 (when (and (derived-mode-p 'idlwave-mode)
4310 idlwave-shell-electric-debug-mode)
4311 (idlwave-shell-electric-debug-mode 0))))))
4312 (setq idlwave-shell-electric-debug-buffers nil))
4314 ;; Show the help text
4315 (defun idlwave-shell-electric-debug-help ()
4317 (with-output-to-temp-buffer "*IDLWAVE Electric Debug Help*"
4318 (princ idlwave-shell-electric-debug-help))
4319 (let* ((current-window (selected-window))
4320 (window (get-buffer-window "*IDLWAVE Electric Debug Help*"))
4321 (window-lines (window-height window)))
4322 (select-window window)
4323 (enlarge-window (1+ (- (count-lines 1 (point-max)) window-lines)))
4324 (select-window current-window)))
4327 ;; The Menus --------------------------------------------------------------
4328 (defvar idlwave-shell-menu-def
4330 ["Electric Debug Mode"
4331 idlwave-shell-electric-debug-mode
4332 :style toggle :selected idlwave-shell-electric-debug-mode
4333 :included (derived-mode-p 'idlwave-mode) :keys "C-c C-d C-v"]
4336 ["Save and .RUN" idlwave-shell-save-and-run
4337 (or (derived-mode-p 'idlwave-mode)
4338 idlwave-shell-last-save-and-action-file)]
4339 ["Save and .COMPILE" idlwave-shell-save-and-compile
4340 (or (derived-mode-p 'idlwave-mode)
4341 idlwave-shell-last-save-and-action-file)]
4342 ["Save and @Batch" idlwave-shell-save-and-batch
4343 (or (derived-mode-p 'idlwave-mode)
4344 idlwave-shell-last-save-and-action-file)]
4346 ["Goto Next Error" idlwave-shell-goto-next-error t]
4348 ["Compile and Run Region" idlwave-shell-run-region
4349 (derived-mode-p 'idlwave-mode)]
4350 ["Evaluate Region" idlwave-shell-evaluate-region
4351 (derived-mode-p 'idlwave-mode)]
4353 ["Execute Default Cmd" idlwave-shell-execute-default-command-line t]
4354 ["Edit Default Cmd" idlwave-shell-edit-default-command-line t])
4356 ["Set Breakpoint" idlwave-shell-break-here
4357 :keys "C-c C-d C-b" :active (derived-mode-p 'idlwave-mode)]
4358 ("Set Special Breakpoint"
4359 ["Set After Count Breakpoint"
4361 (let ((count (string-to-number (read-string "Break after count: "))))
4362 (if (integerp count) (idlwave-shell-break-here count))))
4363 :active (derived-mode-p 'idlwave-mode)]
4364 ["Set Condition Breakpoint"
4365 (idlwave-shell-break-here '(4))
4366 :active (derived-mode-p 'idlwave-mode)])
4367 ["Break in Module" idlwave-shell-break-in
4368 :keys "C-c C-d C-i" :active (derived-mode-p 'idlwave-mode)]
4369 ["Break in this Module" idlwave-shell-break-this-module
4370 :keys "C-c C-d C-j" :active (derived-mode-p 'idlwave-mode)]
4371 ["Clear Breakpoint" idlwave-shell-clear-current-bp t]
4372 ["Clear All Breakpoints" idlwave-shell-clear-all-bp t]
4373 ["Disable/Enable Breakpoint" idlwave-shell-toggle-enable-current-bp t]
4374 ["Goto Previous Breakpoint" idlwave-shell-goto-previous-bp
4375 :keys "C-c C-d [" :active (derived-mode-p 'idlwave-mode)]
4376 ["Goto Next Breakpoint" idlwave-shell-goto-next-bp
4377 :keys "C-c C-d ]" :active (derived-mode-p 'idlwave-mode)]
4378 ["List All Breakpoints" idlwave-shell-list-all-bp t]
4379 ["Resync Breakpoints" idlwave-shell-bp-query t])
4381 ["Step (into)" idlwave-shell-step t]
4382 ["Step (over)" idlwave-shell-stepover t]
4383 ["Skip One Statement" idlwave-shell-skip t]
4384 ["Continue" idlwave-shell-cont t]
4385 ["... to End of Block" idlwave-shell-up t]
4386 ["... to End of Subprog" idlwave-shell-return t]
4387 ["... to End of Subprog+1" idlwave-shell-out t]
4388 ["... to Here (Cursor Line)" idlwave-shell-to-here
4389 :keys "C-c C-d C-h" :active (derived-mode-p 'idlwave-mode)])
4390 ("Examine Expressions"
4391 ["Print expression" idlwave-shell-print t]
4392 ["Help on expression" idlwave-shell-help-expression t]
4393 ("Examine nearby expression with"
4394 ,@(mapcar (lambda(x)
4395 `[ ,(car x) (idlwave-shell-print nil ',x) t ])
4396 idlwave-shell-examine-alist))
4397 ("Examine region with"
4398 ,@(mapcar (lambda(x)
4399 `[ ,(car x) (idlwave-shell-print '(4) ',x) t ])
4400 idlwave-shell-examine-alist)))
4402 ["Stack Up" idlwave-shell-stack-up t]
4403 ["Stack Down" idlwave-shell-stack-down t]
4405 ["Redisplay and Sync" idlwave-shell-redisplay t])
4407 ["Everything" (if (eq idlwave-shell-show-commands 'everything)
4409 (setq idlwave-shell-show-commands
4410 (get 'idlwave-shell-show-commands 'last-val))
4411 (put 'idlwave-shell-show-commands 'last-val nil))
4412 (put 'idlwave-shell-show-commands 'last-val
4413 idlwave-shell-show-commands)
4414 (setq idlwave-shell-show-commands 'everything))
4415 :style toggle :selected (and (not (listp idlwave-shell-show-commands))
4416 (eq idlwave-shell-show-commands
4419 ["Compiling Commands" (idlwave-shell-add-or-remove-show 'run)
4421 :selected (not (idlwave-shell-hide-p
4423 (get 'idlwave-shell-show-commands 'last-val)))
4424 :active (not (eq idlwave-shell-show-commands 'everything))]
4425 ["Breakpoint Commands" (idlwave-shell-add-or-remove-show 'breakpoint)
4427 :selected (not (idlwave-shell-hide-p
4429 (get 'idlwave-shell-show-commands 'last-val)))
4430 :active (not (eq idlwave-shell-show-commands 'everything))]
4431 ["Debug Commands" (idlwave-shell-add-or-remove-show 'debug)
4433 :selected (not (idlwave-shell-hide-p
4435 (get 'idlwave-shell-show-commands 'last-val)))
4436 :active (not (eq idlwave-shell-show-commands 'everything))]
4437 ["Miscellaneous Commands" (idlwave-shell-add-or-remove-show 'misc)
4439 :selected (not (idlwave-shell-hide-p
4441 (get 'idlwave-shell-show-commands 'last-val)))
4442 :active (not (eq idlwave-shell-show-commands 'everything))])
4444 ["Send one char" idlwave-shell-send-char t]
4445 ["Temporary Character Mode" idlwave-shell-char-mode-loop t]
4447 ["Use Input Mode Magic"
4448 (setq idlwave-shell-use-input-mode-magic
4449 (not idlwave-shell-use-input-mode-magic))
4450 :style toggle :selected idlwave-shell-use-input-mode-magic])
4452 ["Update Working Dir" idlwave-shell-resync-dirs t]
4454 (idlwave-shell-send-command idlwave-shell-path-query
4455 'idlwave-shell-get-path-info
4458 ["Reset IDL" idlwave-shell-reset t]
4460 ["Toggle Toolbar" idlwave-shell-toggle-toolbar t]
4461 ["Exit IDL" idlwave-shell-quit t]))
4463 (if (or (featurep 'easymenu) (load "easymenu" t))
4466 idlwave-mode-debug-menu idlwave-mode-map "IDL debugging menus"
4467 idlwave-shell-menu-def)
4469 idlwave-shell-mode-menu idlwave-shell-mode-map "IDL shell menus"
4470 idlwave-shell-menu-def)
4471 (save-current-buffer
4472 (dolist (buf (buffer-list))
4474 (if (derived-mode-p 'idlwave-mode)
4476 (easy-menu-remove idlwave-mode-debug-menu)
4477 (easy-menu-add idlwave-mode-debug-menu)))))))
4479 ;; The Breakpoint Glyph -------------------------------------------------------
4481 (defvar idlwave-shell-bp-glyph nil
4482 "The glyphs to mark breakpoint lines in the source code.")
4486 static char * file[] = {
4488 \" c None s backgroundColor\",
4489 \". c #4B4B4B4B4B4B\",
4490 \"R c #FFFF00000000\",
4503 (bp-cond . "/* XPM */
4504 static char * file[] = {
4506 \" c None s backgroundColor\",
4507 \". c #4B4B4B4B4B4B\",
4508 \"R c #FFFF00000000\",
4509 \"B c #000000000000\",
4523 static char * file[] = {
4525 \" c None s backgroundColor\",
4526 \". c #4B4B4B4B4B4B\",
4527 \"X c #FFFF00000000\",
4528 \"o c #000000000000\",
4542 static char * file[] = {
4544 \" c None s backgroundColor\",
4545 \". c #4B4B4B4B4B4B\",
4546 \"X c #FFFF00000000\",
4547 \"o c #000000000000\",
4561 static char * file[] = {
4563 \" c None s backgroundColor\",
4564 \". c #4B4B4B4B4B4B\",
4565 \"X c #FFFF00000000\",
4566 \"o c #000000000000\",
4580 static char * file[] = {
4582 \" c None s backgroundColor\",
4583 \". c #4B4B4B4B4B4B\",
4584 \"X c #FFFF00000000\",
4585 \"o c #000000000000\",
4599 static char * file[] = {
4601 \" c None s backgroundColor\",
4602 \". c #4B4B4B4B4B4B\",
4603 \"X c #FFFF00000000\",
4604 \"o c #000000000000\",
4616 \" \"};"))) im-cons im)
4618 (while (setq im-cons (pop image-alist))
4619 (setq im (cond ((and (featurep 'xemacs)
4622 (let ((data (cdr im-cons)))
4623 (string-match "#FFFF00000000" data)
4624 (setq data (replace-match "#8F8F8F8F8F8F" t t data))
4626 (make-glyph (cdr im-cons))))
4627 ((and (not (featurep 'xemacs))
4628 (fboundp 'image-type-available-p)
4629 (image-type-available-p 'xpm))
4630 (list 'image :type 'xpm :data (cdr im-cons)
4633 (if im (push (cons (car im-cons) im) idlwave-shell-bp-glyph))))
4635 (provide 'idlw-shell)
4636 (provide 'idlwave-shell)
4638 ;; Load the toolbar when wanted by the user.
4640 (autoload 'idlwave-toolbar-toggle "idlw-toolbar"
4641 "Toggle the IDLWAVE toolbar.")
4642 (autoload 'idlwave-toolbar-add-everywhere "idlw-toolbar"
4643 "Add IDLWAVE toolbar.")
4644 (defun idlwave-shell-toggle-toolbar ()
4645 "Toggle the display of the debugging toolbar."
4647 (idlwave-toolbar-toggle))
4649 (if idlwave-shell-use-toolbar
4650 (add-hook 'idlwave-shell-mode-hook 'idlwave-toolbar-add-everywhere))
4652 ;;; idlw-shell.el ends here