Merge from emacs-23
[bpt/emacs.git] / lisp / progmodes / idlw-shell.el
index 3acd396..0cad8cc 100644 (file)
@@ -866,7 +866,7 @@ IDL has currently stepped.")
 (defvar idlwave-shell-only-prompt-pattern nil)
 (defvar tool-bar-map)
 
-(defun idlwave-shell-mode ()
+(define-derived-mode idlwave-shell-mode comint-mode "IDL-Shell"
   "Major mode for interacting with an inferior IDL process.
 
 1. Shell Interaction
@@ -947,28 +947,23 @@ IDL has currently stepped.")
 8. Keybindings
    -----------
 \\{idlwave-shell-mode-map}"
-
-  (interactive)
+  :abbrev-table idlwave-mode-abbrev-table
   (idlwave-setup) ; Make sure config files and paths, etc. are available.
   (unless (file-name-absolute-p idlwave-shell-command-history-file)
     (setq idlwave-shell-command-history-file
          (expand-file-name idlwave-shell-command-history-file
                            idlwave-config-directory)))
 
-  ;; We don't do `kill-all-local-variables' here, because this is done by
-  ;; comint
   (setq comint-prompt-regexp idlwave-shell-prompt-pattern)
   (setq comint-process-echoes t)
 
   ;; Can not use history expansion because "!" is used for system variables.
   (setq comint-input-autoexpand nil)
- (setq comint-input-ring-size 64)
-  (make-local-variable 'comint-completion-addsuffix)
+  ;; (setq comint-input-ring-size 64)
+  
   (set (make-local-variable 'completion-ignore-case) t)
-  (setq comint-completion-addsuffix '("/" . ""))
+  (set (make-local-variable 'comint-completion-addsuffix) '("/" . ""))
   (setq comint-input-ignoredups t)
-  (setq major-mode 'idlwave-shell-mode)
-  (setq mode-name "IDL-Shell")
   (setq idlwave-shell-mode-line-info nil)
   (setq mode-line-format
        '(""
@@ -1023,7 +1018,6 @@ IDL has currently stepped.")
            nil 'local)
   (add-hook 'kill-buffer-hook 'idlwave-shell-delete-temp-files nil 'local)
   (add-hook 'kill-emacs-hook 'idlwave-shell-delete-temp-files)
-  (use-local-map idlwave-shell-mode-map)
   (easy-menu-add idlwave-shell-mode-menu idlwave-shell-mode-map)
 
   ;; Set the optional comint variables
@@ -1054,10 +1048,7 @@ IDL has currently stepped.")
   ;; with overlay-arrows.
   (remove-hook 'comint-output-filter-functions 'py-pdbtrack-track-stack-file)
 
-
   ;; IDLWAVE syntax, and turn on abbreviations
-  (setq local-abbrev-table idlwave-mode-abbrev-table)
-  (set-syntax-table idlwave-mode-syntax-table)
   (set (make-local-variable 'comment-start) ";")
   (setq abbrev-mode t)
 
@@ -1076,8 +1067,6 @@ IDL has currently stepped.")
   ;; Turn off the non-debug toolbar buttons (open,save,etc.)
   (set (make-local-variable 'tool-bar-map) nil)
 
-  ;; Run the hooks.
-  (run-mode-hooks 'idlwave-shell-mode-hook)
   (idlwave-shell-send-command idlwave-shell-initial-commands nil 'hide)
   ;; Turn off IDL's ^d interpreting, and define a system
   ;; variable which knows the version of IDLWAVE
@@ -1458,7 +1447,7 @@ Otherwise just move the line.  Move down unless UP is non-nil."
         (arg (if up arg (- arg))))
     (if (eq t idlwave-shell-arrows-do-history) (goto-char proc-pos))
     (if (and idlwave-shell-arrows-do-history
-            (>= (1+ (save-excursion (end-of-line) (point))) proc-pos))
+            (>= (1+ (point-at-eol)) proc-pos))
        (comint-previous-input arg)
       (forward-line (- arg)))))
 
@@ -2180,8 +2169,8 @@ keywords."
       ;; Default completion of modules and keywords
       (idlwave-complete arg)))))
 
-;; Get rid of opaque dynamic variable passing of link?
-(defvar link) ;dynamic variable
+;; Get rid of opaque dynamic variable passing of idlw-help-link?
+(defvar idlw-help-link) ; dynamic variable from idlwave-do-mouse-completion-help
 (defun idlwave-shell-complete-execcomm-help (mode word)
   (let ((word (or (nth 1 idlwave-completion-help-info) word))
        (entry (assoc-string word idlwave-executive-commands-alist t)))
@@ -2189,7 +2178,7 @@ keywords."
      ((eq mode 'test)
       (and (stringp word) entry (cdr entry)))
      ((eq mode 'set)
-      (if entry (setq link (cdr entry)))) ;; setting dynamic variable!!!
+      (if entry (setq idlw-help-link (cdr entry)))) ; setting dynamic variable!
      (t (error "This should not happen")))))
 
 (defun idlwave-shell-complete-filename (&optional arg)
@@ -2211,7 +2200,7 @@ args of an executive .run, .rnew or .compile."
 
 (defun idlwave-shell-filename-string ()
   "Return t if in a string and after what could be a file name."
-  (let ((limit (save-excursion (beginning-of-line) (point))))
+  (let ((limit (point-at-bol)))
     (save-excursion
       ;; Skip backwards over file name chars
       (skip-chars-backward idlwave-shell-file-name-chars limit)
@@ -2220,7 +2209,7 @@ args of an executive .run, .rnew or .compile."
 
 (defun idlwave-shell-batch-command ()
   "Return t if we're in a batch command statement like @foo"
-  (let ((limit (save-excursion (beginning-of-line) (point))))
+  (let ((limit (point-at-bol)))
     (save-excursion
       ;; Skip backwards over filename
       (skip-chars-backward idlwave-shell-file-name-chars limit)
@@ -2398,7 +2387,7 @@ matter what the settings of that variable."
                                    idlwave-shell-electric-stop-line-face
                                  idlwave-shell-stop-line-face))
                  (move-overlay idlwave-shell-stop-line-overlay
-                               (point) (save-excursion (end-of-line) (point))
+                               (point) (point-at-eol)
                                (current-buffer)))
              ;; use the arrow instead, but only if marking is wanted.
              (if idlwave-shell-mark-stop-line
@@ -2591,9 +2580,7 @@ If in the IDL shell buffer, returns `idlwave-shell-pc-frame'."
     (list (idlwave-shell-file-name (buffer-file-name))
           (save-restriction
             (widen)
-            (save-excursion
-              (beginning-of-line)
-              (1+ (count-lines 1 (point))))))))
+           (1+ (count-lines 1 (point-at-bol)))))))
 
 (defun idlwave-shell-current-module ()
   "Return the name of the module for the current file.
@@ -3645,7 +3632,7 @@ Existing overlays are recycled, in order to minimize consumption."
       (while (setq bp (pop bp-list))
        (save-excursion
          (idlwave-shell-goto-frame (car bp))
-         (let* ((end (progn (end-of-line 1) (point)))
+         (let* ((end (point-at-eol))
                 (beg (progn (beginning-of-line 1) (point)))
                 (condition (idlwave-shell-bp-get bp 'condition))
                 (count (idlwave-shell-bp-get bp 'count))
@@ -3897,7 +3884,7 @@ handled by this command."
   (setq overlay-arrow-string nil)
   (let (buf)
     (cond
-     ((eq major-mode 'idlwave-mode)
+     ((derived-mode-p 'idlwave-mode)
       (save-buffer)
       (setq idlwave-shell-last-save-and-action-file (buffer-file-name)))
      (idlwave-shell-last-save-and-action-file
@@ -3999,8 +3986,7 @@ of the form:
                   (append
                    ;; compiled procedures
                    (progn
-                     (beginning-of-line)
-                     (narrow-to-region cpro (point))
+                     (narrow-to-region cpro (point-at-bol))
                      (goto-char (point-min))
                      (idlwave-shell-sources-grep))
                    ;; compiled functions
@@ -4086,7 +4072,7 @@ of the form:
 (defun idlwave-shell-file-name (name)
   "If `idlwave-shell-use-truename' is non-nil, convert file name to true name.
 Otherwise, just expand the file name."
-  (let ((def-dir (if (eq major-mode 'idlwave-shell-mode)
+  (let ((def-dir (if (derived-mode-p 'idlwave-shell-mode)
                     default-directory
                   idlwave-shell-default-directory)))
     (if idlwave-shell-use-truename
@@ -4349,7 +4335,7 @@ idlwave-shell-electric-debug-mode-map)
       (while (setq buf (pop buffers))
        (when (buffer-live-p buf)
          (set-buffer buf)
-         (when (and (eq major-mode 'idlwave-mode)
+         (when (and (derived-mode-p 'idlwave-mode)
                     buffer-file-name
                     idlwave-shell-electric-debug-mode)
            (idlwave-shell-electric-debug-mode 0))))))
@@ -4374,51 +4360,51 @@ idlwave-shell-electric-debug-mode-map)
     ["Electric Debug Mode"
      idlwave-shell-electric-debug-mode
      :style toggle :selected idlwave-shell-electric-debug-mode
-     :included (eq major-mode 'idlwave-mode) :keys "C-c C-d C-v"]
+     :included (derived-mode-p 'idlwave-mode) :keys "C-c C-d C-v"]
     "--"
     ("Compile & Run"
      ["Save and .RUN" idlwave-shell-save-and-run
-      (or (eq major-mode 'idlwave-mode)
+      (or (derived-mode-p 'idlwave-mode)
          idlwave-shell-last-save-and-action-file)]
      ["Save and .COMPILE" idlwave-shell-save-and-compile
-      (or (eq major-mode 'idlwave-mode)
+      (or (derived-mode-p 'idlwave-mode)
          idlwave-shell-last-save-and-action-file)]
      ["Save and @Batch" idlwave-shell-save-and-batch
-      (or (eq major-mode 'idlwave-mode)
+      (or (derived-mode-p 'idlwave-mode)
          idlwave-shell-last-save-and-action-file)]
      "--"
      ["Goto Next Error" idlwave-shell-goto-next-error t]
      "--"
      ["Compile and Run Region" idlwave-shell-run-region
-      (eq major-mode 'idlwave-mode)]
+      (derived-mode-p 'idlwave-mode)]
      ["Evaluate Region" idlwave-shell-evaluate-region
-      (eq major-mode 'idlwave-mode)]
+      (derived-mode-p 'idlwave-mode)]
      "--"
      ["Execute Default Cmd" idlwave-shell-execute-default-command-line t]
      ["Edit Default Cmd" idlwave-shell-edit-default-command-line t])
     ("Breakpoints"
      ["Set Breakpoint" idlwave-shell-break-here
-      :keys "C-c C-d C-b" :active (eq major-mode 'idlwave-mode)]
+      :keys "C-c C-d C-b" :active (derived-mode-p 'idlwave-mode)]
      ("Set Special Breakpoint"
       ["Set After Count Breakpoint"
        (progn
        (let ((count (string-to-number (read-string "Break after count: "))))
              (if (integerp count) (idlwave-shell-break-here count))))
-       :active (eq major-mode 'idlwave-mode)]
+       :active (derived-mode-p 'idlwave-mode)]
       ["Set Condition Breakpoint"
        (idlwave-shell-break-here '(4))
-       :active (eq major-mode 'idlwave-mode)])
+       :active (derived-mode-p 'idlwave-mode)])
      ["Break in Module" idlwave-shell-break-in
-      :keys "C-c C-d C-i" :active (eq major-mode 'idlwave-mode)]
+      :keys "C-c C-d C-i" :active (derived-mode-p 'idlwave-mode)]
      ["Break in this Module" idlwave-shell-break-this-module
-      :keys "C-c C-d C-j" :active (eq major-mode 'idlwave-mode)]
+      :keys "C-c C-d C-j" :active (derived-mode-p 'idlwave-mode)]
      ["Clear Breakpoint" idlwave-shell-clear-current-bp t]
      ["Clear All Breakpoints" idlwave-shell-clear-all-bp t]
      ["Disable/Enable Breakpoint" idlwave-shell-toggle-enable-current-bp t]
      ["Goto Previous Breakpoint" idlwave-shell-goto-previous-bp
-      :keys "C-c C-d [" :active (eq major-mode 'idlwave-mode)]
+      :keys "C-c C-d [" :active (derived-mode-p 'idlwave-mode)]
      ["Goto Next Breakpoint" idlwave-shell-goto-next-bp
-      :keys "C-c C-d ]" :active (eq major-mode 'idlwave-mode)]
+      :keys "C-c C-d ]" :active (derived-mode-p 'idlwave-mode)]
      ["List All Breakpoints" idlwave-shell-list-all-bp t]
      ["Resync Breakpoints" idlwave-shell-bp-query t])
     ("Continue/Step"
@@ -4430,7 +4416,7 @@ idlwave-shell-electric-debug-mode-map)
      ["... to End of Subprog" idlwave-shell-return t]
      ["... to End of Subprog+1" idlwave-shell-out t]
      ["... to Here (Cursor Line)" idlwave-shell-to-here
-      :keys "C-c C-d C-h" :active (eq major-mode 'idlwave-mode)])
+      :keys "C-c C-d C-h" :active (derived-mode-p 'idlwave-mode)])
     ("Examine Expressions"
      ["Print expression" idlwave-shell-print t]
      ["Help on expression" idlwave-shell-help-expression t]
@@ -4515,7 +4501,7 @@ idlwave-shell-electric-debug-mode-map)
       (save-current-buffer
        (dolist (buf (buffer-list))
           (set-buffer buf)
-          (if (eq major-mode 'idlwave-mode)
+          (if (derived-mode-p 'idlwave-mode)
               (progn
                 (easy-menu-remove idlwave-mode-debug-menu)
                 (easy-menu-add idlwave-mode-debug-menu)))))))
@@ -4693,5 +4679,4 @@ static char * file[] = {
 (if idlwave-shell-use-toolbar
     (add-hook 'idlwave-shell-mode-hook 'idlwave-toolbar-add-everywhere))
 
-;; arch-tag: 20c2e8ce-0709-41d8-a5b6-bb039148440a
 ;;; idlw-shell.el ends here