Fix typos (sync from the trunk).
[bpt/emacs.git] / lisp / eshell / esh-mode.el
index d0393df..7c66d79 100644 (file)
@@ -1,6 +1,7 @@
-;;; esh-mode --- user interface
+;;; esh-mode.el --- user interface
 
-;; Copyright (C) 1999, 2000 Free Software Foundation
+;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
@@ -8,7 +9,7 @@
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
@@ -18,8 +19,8 @@
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 (provide 'esh-mode)
 
@@ -164,7 +165,8 @@ number, if the function `eshell-truncate-buffer' is on
   :group 'eshell-mode)
 
 (defcustom eshell-output-filter-functions
-  '(eshell-handle-control-codes
+  '(eshell-postoutput-scroll-to-bottom
+    eshell-handle-control-codes
     eshell-watch-for-password-prompt)
   "*Functions to call before output is displayed.
 These functions are only called for output that is displayed
@@ -196,11 +198,6 @@ This is used by `eshell-watch-for-password-prompt'."
   :type 'boolean
   :group 'eshell-mode)
 
-(defvar eshell-non-interactive-p nil
-  "A variable which is non-nil when Eshell is not running interactively.
-Modules should use this variable so that they don't clutter non-interactive
-sessions, such as when using `eshell-command'.")
-
 (defvar eshell-first-time-p t
   "A variable which is non-nil the first time Eshell is loaded.")
 
@@ -310,7 +307,7 @@ sessions, such as when using `eshell-command'.")
 
   (when eshell-status-in-modeline
     (make-local-variable 'eshell-command-running-string)
-    (let ((fmt (eshell-copy-list mode-line-format)))
+    (let ((fmt (copy-sequence mode-line-format)))
       (make-local-variable 'mode-line-format)
       (setq mode-line-format fmt))
     (let ((modeline (memq 'mode-line-modified mode-line-format)))
@@ -387,7 +384,7 @@ sessions, such as when using `eshell-command'.")
   (set (make-local-variable 'eshell-last-output-end) (point-marker))
   (set (make-local-variable 'eshell-last-output-block-begin) (point))
 
-  (let ((modules-list (eshell-copy-list eshell-modules-list)))
+  (let ((modules-list (copy-sequence eshell-modules-list)))
     (make-local-variable 'eshell-modules-list)
     (setq eshell-modules-list modules-list))
 
@@ -420,8 +417,6 @@ sessions, such as when using `eshell-command'.")
       (if (and load-hook (boundp load-hook))
          (run-hooks load-hook))))
 
-  (make-local-hook 'pre-command-hook)
-
   (if eshell-send-direct-to-subprocesses
       (add-hook 'pre-command-hook 'eshell-intercept-commands t t))
 
@@ -432,12 +427,9 @@ sessions, such as when using `eshell-command'.")
     (set (make-local-variable 'scroll-conservatively) 1000))
 
   (when eshell-status-in-modeline
-    (make-local-hook 'eshell-pre-command-hook)
     (add-hook 'eshell-pre-command-hook 'eshell-command-started nil t)
-    (make-local-hook 'eshell-post-command-hook)
     (add-hook 'eshell-post-command-hook 'eshell-command-finished nil t))
 
-  (make-local-hook 'kill-buffer-hook)
   (add-hook 'kill-buffer-hook
            (function
             (lambda ()
@@ -445,7 +437,7 @@ sessions, such as when using `eshell-command'.")
 
   (if eshell-first-time-p
       (run-hooks 'eshell-first-time-mode-hook))
-  (run-hooks 'eshell-mode-hook)
+  (run-mode-hooks 'eshell-mode-hook)
   (run-hooks 'eshell-post-command-hook))
 
 (put 'eshell-mode 'mode-class 'special)
@@ -527,7 +519,8 @@ sessions, such as when using `eshell-command'.")
   (let ((inhibit-read-only t)
        (no-default (eobp))
        (find-tag-default-function 'ignore))
-    (setq tagname (car (find-tag-interactive "Find tag: ")))
+    (with-no-warnings
+      (setq tagname (car (find-tag-interactive "Find tag: "))))
     (find-tag tagname next-p regexp-p)))
 
 (defun eshell-move-argument (limit func property arg)
@@ -673,7 +666,7 @@ waiting for input."
   (eshell-match-result "alpha\n"))
 
 (defun eshell-send-input (&optional use-region queue-p no-newline)
-  "Send the input received to Eshell for parsing and processing..
+  "Send the input received to Eshell for parsing and processing.
 After `eshell-last-output-end', sends all text from that marker to
 point as input.  Before that marker, calls `eshell-get-old-input' to
 retrieve old input, copies it to the end of the buffer, and sends it.
@@ -750,19 +743,19 @@ newline."
               (run-hooks 'eshell-post-command-hook)
               (insert-and-inherit input)))))))))
 
-(eshell-deftest proc send-to-subprocess
-  "Send input to a subprocess"
-  ;; jww (1999-12-06): what about when bc is unavailable?
-  (if (not (eshell-search-path "bc"))
-      t
-    (eshell-insert-command "bc")
-    (eshell-insert-command "1 + 2")
-    (sit-for 1 0)
-    (forward-line -1)
-    (prog1
-       (looking-at "3\n")
-      (eshell-insert-command "quit")
-      (sit-for 1 0))))
+(eshell-deftest proc send-to-subprocess
+  "Send input to a subprocess"
+  ;; jww (1999-12-06): what about when bc is unavailable?
+  (if (not (eshell-search-path "bc"))
+      t
+    (eshell-insert-command "bc")
+    (eshell-insert-command "1 + 2")
+    (sit-for 1 0)
+    (forward-line -1)
+    (prog1
+;      (looking-at "3\n")
+      (eshell-insert-command "quit")
+      (sit-for 1 0))))
 
 (defsubst eshell-kill-new ()
   "Add the last input text to the kill ring."
@@ -782,38 +775,36 @@ This is done after all necessary filtering has been done."
        (setq string (funcall (car functions) string))
        (setq functions (cdr functions))))
     (if (and string oprocbuf (buffer-name oprocbuf))
-       (let ((obuf (current-buffer))
-             opoint obeg oend)
-         (set-buffer oprocbuf)
-         (setq opoint (point))
-         (setq obeg (point-min))
-         (setq oend (point-max))
-         (let ((buffer-read-only nil)
-               (nchars (length string))
-               (ostart nil))
-           (widen)
-           (goto-char eshell-last-output-end)
-           (setq ostart (point))
-           (if (<= (point) opoint)
-               (setq opoint (+ opoint nchars)))
-           (if (< (point) obeg)
-               (setq obeg (+ obeg nchars)))
-           (if (<= (point) oend)
-               (setq oend (+ oend nchars)))
-           (insert-before-markers string)
-           (if (= (window-start (selected-window)) (point))
-               (set-window-start (selected-window)
-                                 (- (point) nchars)))
-           (if (= (point) eshell-last-input-end)
-               (set-marker eshell-last-input-end
-                           (- eshell-last-input-end nchars)))
-           (set-marker eshell-last-output-start ostart)
-           (set-marker eshell-last-output-end (point))
-           (force-mode-line-update))
-         (narrow-to-region obeg oend)
-         (goto-char opoint)
-         (eshell-run-output-filters)
-         (set-buffer obuf)))))
+       (let (opoint obeg oend)
+         (with-current-buffer oprocbuf
+           (setq opoint (point))
+           (setq obeg (point-min))
+           (setq oend (point-max))
+           (let ((buffer-read-only nil)
+                 (nchars (length string))
+                 (ostart nil))
+             (widen)
+             (goto-char eshell-last-output-end)
+             (setq ostart (point))
+             (if (<= (point) opoint)
+                 (setq opoint (+ opoint nchars)))
+             (if (< (point) obeg)
+                 (setq obeg (+ obeg nchars)))
+             (if (<= (point) oend)
+                 (setq oend (+ oend nchars)))
+             (insert-before-markers string)
+             (if (= (window-start (selected-window)) (point))
+                 (set-window-start (selected-window)
+                                   (- (point) nchars)))
+             (if (= (point) eshell-last-input-end)
+                 (set-marker eshell-last-input-end
+                             (- eshell-last-input-end nchars)))
+             (set-marker eshell-last-output-start ostart)
+             (set-marker eshell-last-output-end (point))
+             (force-mode-line-update))
+           (narrow-to-region obeg oend)
+           (goto-char opoint)
+           (eshell-run-output-filters))))))
 
 (defun eshell-run-output-filters ()
   "Run the `eshell-output-filter-functions' on the current output."
@@ -827,7 +818,7 @@ This is done after all necessary filtering has been done."
   "Go to the end of buffer in all windows showing it.
 Movement occurs if point in the selected window is not after the
 process mark, and `this-command' is an insertion command.  Insertion
-commands recognised are `self-insert-command', `yank', and
+commands recognized are `self-insert-command', `yank', and
 `hilit-yank'.  Depends on the value of
 `eshell-scroll-to-bottom-on-input'.
 
@@ -888,9 +879,6 @@ This function should be in the list `eshell-output-filter-functions'."
         nil t)
       (set-buffer current))))
 
-(custom-add-option 'eshell-output-filter-functions
-                  'eshell-postoutput-scroll-to-bottom)
-
 (defun eshell-beginning-of-input ()
   "Return the location of the start of the previous input."
   eshell-last-input-start)
@@ -953,10 +941,11 @@ With a prefix argument, narrows region to last command output."
       (eshell-bol)
       (kill-region (point) here))))
 
-(defun eshell-show-maximum-output ()
-  "Put the end of the buffer at the bottom of the window."
-  (interactive)
-  (if (interactive-p)
+(defun eshell-show-maximum-output (&optional interactive)
+  "Put the end of the buffer at the bottom of the window.
+When run interactively, widen the buffer first."
+  (interactive "p")
+  (if interactive
       (widen))
   (goto-char (point-max))
   (recenter -1))
@@ -1012,7 +1001,7 @@ a key."
       (let ((pos (point)))
        (if (bobp)
            (if (interactive-p)
-               (error "Buffer too short to truncate"))
+               (message "Buffer too short to truncate"))
          (delete-region (point-min) (point))
          (if (interactive-p)
              (message "Truncated buffer from %d to %d lines (%.1fk freed)"
@@ -1022,12 +1011,12 @@ a key."
 (custom-add-option 'eshell-output-filter-functions
                   'eshell-truncate-buffer)
 
-(defun send-invisible (str)
+(defun eshell-send-invisible (str)
   "Read a string without echoing.
 Then send it to the process running in the current buffer."
   (interactive "P")                     ; Defeat snooping via C-x ESC ESC
   (let ((str (read-passwd
-             (format "Password: "
+             (format "%s Password: "
                      (process-name (eshell-interactive-process))))))
     (if (stringp str)
        (process-send-string (eshell-interactive-process)
@@ -1036,7 +1025,7 @@ Then send it to the process running in the current buffer."
 
 (defun eshell-watch-for-password-prompt ()
   "Prompt in the minibuffer for password and send without echoing.
-This function uses `send-invisible' to read and send a password to the
+This function uses `eshell-send-invisible' to read and send a password to the
 buffer's process if STRING contains a password prompt defined by
 `eshell-password-prompt-regexp'.
 
@@ -1047,7 +1036,7 @@ This function could be in the list `eshell-output-filter-functions'."
       (beginning-of-line)
       (if (re-search-forward eshell-password-prompt-regexp
                             eshell-last-output-end t)
-         (send-invisible nil)))))
+         (eshell-send-invisible nil)))))
 
 (custom-add-option 'eshell-output-filter-functions
                   'eshell-watch-for-password-prompt)
@@ -1085,6 +1074,16 @@ This function could be in the list `eshell-output-filter-functions'."
 (custom-add-option 'eshell-output-filter-functions
                   'eshell-handle-control-codes)
 
+(defun eshell-handle-ansi-color ()
+  "Handle ANSI color codes."
+  (require 'ansi-color)
+  (ansi-color-apply-on-region eshell-last-output-start
+                              eshell-last-output-end))
+
+(custom-add-option 'eshell-output-filter-functions
+                  'eshell-handle-ansi-color)
+
 ;;; Code:
 
+;;; arch-tag: ec65bc2b-da14-4547-81d3-a32af3a4dc57
 ;;; esh-mode.el ends here