Anonymous avatar Anonymous committed 50d3747

Merge GNU's eshell changes.

Comments (0)

Files changed (30)

+2008-08-19  It's me FKtPp ;)  <m_pupil@yahoo.com.cn>
+
+	* Upstream version 2.4.2 (the last GPLv2 version avaiable,
+	savannah git version tag: 0fc80a3f6bb3bb59f42e9ff83cc8b89bf90fe658).
+
 2008-07-10  Norbert Koch  <viteno@xemacs.org>
 
 	* Makefile (VERSION): XEmacs package 1.13 released.
-;;; em-alias --- creation and management of command aliases
+;;; em-alias.el --- creation and management of command aliases
 
-;; Copyright (C) 1999, 2000 Free Software Foundation
+;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
 
 ;; 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 'em-alias)
 
 (defgroup eshell-alias nil
   "Command aliases allow for easy definition of alternate commands."
   :tag "Command aliases"
-  :link '(info-link "(eshell)Command aliases")
+  ;; :link '(info-link "(eshell)Command aliases")
   :group 'eshell-module)
 
 ;;; Commentary:
 (defcustom eshell-bad-command-tolerance 3
   "*The number of failed commands to ignore before creating an alias."
   :type 'integer
-  :link '(custom-manual "(eshell)Auto-correction of bad commands")
+  ;; :link '(custom-manual "(eshell)Auto-correction of bad commands")
   :group 'eshell-alias)
 
 ;;;
 (defun eshell-alias-initialize ()
   "Initialize the alias handling code."
   (make-local-variable 'eshell-failed-commands-alist)
-  (make-local-hook 'eshell-alternate-command-hook)
   (add-hook 'eshell-alternate-command-hook 'eshell-fix-bad-commands t t)
   (eshell-read-aliases-list)
-  (make-local-hook 'eshell-named-command-hook)
   (add-hook 'eshell-named-command-hook 'eshell-maybe-replace-by-alias t t)
   (make-local-variable 'eshell-complex-commands)
   (add-to-list 'eshell-complex-commands 'eshell-command-aliased-p))
 
 (defun eshell-command-aliased-p (name)
-  (member name eshell-command-aliases-list))
+  (assoc name eshell-command-aliases-list))
 
 (defun eshell/alias (&optional alias &rest definition)
   "Define an ALIAS in the user's alias list using DEFINITION."
-;;; em-banner --- sample module that displays a login banner
+;;; em-banner.el --- sample module that displays a login banner
 
-;; Copyright (C) 1999, 2000 Free Software Foundation
+;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
 
 ;; 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 'em-banner)
 
 It exists so that others wishing to create their own Eshell extension
 modules may have a simple template to begin with."
   :tag "Login banner"
-  :link '(info-link "(eshell)Login banner")
+  ;; :link '(info-link "(eshell)Login banner")
   :group 'eshell-module)
 
 ;;; Commentary:
-;;; em-basic --- basic shell builtin commands
+;;; em-basic.el --- basic shell builtin commands
 
-;; Copyright (C) 1999, 2000 Free Software Foundation
+;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
 
 ;; 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 'em-basic)
 
-;;; em-cmpl --- completion using the TAB key
+;;; em-cmpl.el --- completion using the TAB key
 
-;; Copyright (C) 1999, 2000 Free Software Foundation
+;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
 
 ;; 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 'em-cmpl)
 
 (eval-when-compile (require 'esh-maint))
+(require 'esh-util)
 
 (defgroup eshell-cmpl nil
   "This module provides a programmable completion function bound to
     ("CC"       . "\\.[Cc]\\([Cc]\\|[Pp][Pp]\\)?\\'")
     ("acc"      . "\\.[Cc]\\([Cc]\\|[Pp][Pp]\\)?\\'")
     ("bcc"      . "\\.[Cc]\\([Cc]\\|[Pp][Pp]\\)?\\'")
-    ("objdump"  . "\\(\\`[^.]*\\|\\.[ao]\\)\\'")
-    ("nm"       . "\\(\\`[^.]*\\|\\.[ao]\\)\\'")
+    ("readelf"  . "\\(\\`[^.]*\\|\\.\\([ao]\\|so\\)\\)\\'")
+    ("objdump"  . "\\(\\`[^.]*\\|\\.\\([ao]\\|so\\)\\)\\'")
+    ("nm"       . "\\(\\`[^.]*\\|\\.\\([ao]\\|so\\)\\)\\'")
     ("gdb"      . "\\`\\([^.]*\\|a\\.out\\)\\'")
     ("dbx"      . "\\`\\([^.]*\\|a\\.out\\)\\'")
     ("sdb"      . "\\`\\([^.]*\\|a\\.out\\)\\'")
   ;; `pcomplete-arg-quote-list' should only be set after all the
   ;; load-hooks for any other extension modules have been run, which
   ;; is true at the time `eshell-mode-hook' is run
-  (make-local-hook 'eshell-mode-hook)
   (add-hook 'eshell-mode-hook
 	    (function
 	     (lambda ()
 	       (set (make-local-variable 'pcomplete-arg-quote-list)
 		    eshell-special-chars-outside-quoting))) nil t)
-  (make-local-hook 'pcomplete-quote-arg-hook)
   (add-hook 'pcomplete-quote-arg-hook 'eshell-quote-backslash nil t)
   (define-key eshell-mode-map [(meta tab)] 'lisp-complete-symbol)
   (define-key eshell-mode-map [(meta control ?i)] 'lisp-complete-symbol)
   "Return the command name, possibly sans globbing."
   (let ((cmd (file-name-nondirectory (pcomplete-arg 'first))))
     (setq cmd (if (and (> (length cmd) 0)
-		       (eq (aref cmd 0) ?*))
+		       (eq (aref cmd 0) eshell-explicit-command-char))
 		  (substring cmd 1)
 		cmd))
     (if (eshell-under-windows-p)
 	   (setq args (nthcdr (1+ l) args)
 		 posns (nthcdr (1+ l) posns))))
     (assert (= (length args) (length posns)))
-    (when (and args (eq (char-syntax (char-before end)) ? ))
+    (when (and args (eq (char-syntax (char-before end)) ? )
+	       (not (eq (char-before (1- end)) ?\\)))
       (nconc args (list ""))
       (nconc posns (list (point))))
     (cons (mapcar
     (if (file-name-directory filename)
 	(pcomplete-executables)
       (if (and (> (length filename) 0)
-	       (eq (aref filename 0) ?*))
+	       (eq (aref filename 0) eshell-explicit-command-char))
 	  (setq filename (substring filename 1)
 		pcomplete-stub filename
 		glob-name t))
-;;; em-dirs --- directory navigation commands
+;;; em-dirs.el --- directory navigation commands
 
-;; Copyright (C) 1999, 2000 Free Software Foundation
+;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
 
 ;; 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 'em-dirs)
 
   :type 'boolean
   :group 'eshell-dirs)
 
-;;; Internal  Variables:
+;;; Internal Variables:
 
 (defvar eshell-dirstack nil
   "List of directories saved by pushd in the Eshell buffer.
 		      'eshell-dirs-substitute-cd)
 		eshell-interpreter-alist)))
 
-  (make-local-hook 'eshell-parse-argument-hook)
   (add-hook 'eshell-parse-argument-hook
 	    'eshell-parse-user-reference nil t)
   (if (eshell-under-windows-p)
 		'eshell-parse-drive-letter nil t))
 
   (when (eshell-using-module 'eshell-cmpl)
-    (make-local-hook 'pcomplete-try-first-hook)
     (add-hook 'pcomplete-try-first-hook
 	      'eshell-complete-user-reference nil t))
 
   (unless eshell-last-dir-ring
     (setq eshell-last-dir-ring (make-ring eshell-last-dir-ring-size)))
 
-  (make-local-hook 'eshell-exit-hook)
   (add-hook 'eshell-exit-hook 'eshell-write-last-dir-ring nil t)
 
   (add-hook 'kill-emacs-hook 'eshell-save-some-last-dir))
 	(setq path
 	      (ring-remove eshell-last-dir-ring
 			   (if index
-			       (string-to-int index)
+			       (string-to-number index)
 			     0)))))
      ((and path (string-match "^=\\(.*\\)$" path))
       (let ((oldpath (eshell-find-previous-directory
 		   (eshell-parse-command "ls" (cdr args))))
 	nil))))
 
+(put 'eshell/cd 'eshell-no-numeric-conversions t)
+
 (defun eshell-add-to-dir-ring (path)
   "Add PATH to the last-dir-ring, if applicable."
   (unless (and (not (ring-empty-p eshell-last-dir-ring))
 	(eshell/dirs t)))))
   nil)
 
+(put 'eshell/pushd 'eshell-no-numeric-conversions t)
+
 ;;; popd [+n]
 (defun eshell/popd (&rest args)
   "Implementation of popd in Lisp."
 	   (error "Couldn't popd"))))
   nil)
 
+(put 'eshell/popd 'eshell-no-numeric-conversions t)
+
 (defun eshell/dirs (&optional if-verbose)
   "Implementation of dirs in Lisp."
   (when (or (not if-verbose) eshell-dirtrack-verbose)
-;;; em-glob --- extended file name globbing
+;;; em-glob.el --- extended file name globbing
 
-;; Copyright (C) 1999, 2000 Free Software Foundation
+;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
 
 ;; 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.
+
+;;; Code:
 
 (provide 'em-glob)
 
 (eval-when-compile (require 'esh-maint))
+(require 'esh-util)
 
 (defgroup eshell-glob nil
   "This module provides extended globbing syntax, similar what is used
   :type 'boolean
   :group 'eshell-glob)
 
-(defcustom eshell-glob-chars-list '(?\] ?\[ ?* ?? ?~ ?\( ?\) ?| ?#)
+(defcustom eshell-glob-chars-list '(?\] ?\[ ?* ?? ?~ ?\( ?\) ?| ?# ?^)
   "*List of additional characters used in extended globbing."
   :type '(repeat character)
   :group 'eshell-glob)
 (defcustom eshell-glob-translate-alist
   '((?\] . "]")
     (?\[ . "[")
+    (?^  . "^")
     (??  . ".")
     (?*  . ".*")
     (?~  . "~")
   :type '(repeat (cons character (choice regexp function)))
   :group 'eshell-glob)
 
-;;; Internal Variables:
-
-(defvar eshell-glob-chars-regexp nil)
-
 ;;; Functions:
 
 (defun eshell-glob-initialize ()
   "Initialize the extended globbing code."
   ;; it's important that `eshell-glob-chars-list' come first
-  (set (make-local-variable 'eshell-special-chars-outside-quoting)
-       (append eshell-glob-chars-list eshell-special-chars-outside-quoting))
-  (set (make-local-variable 'eshell-glob-chars-regexp)
-       (format "[%s]+" (apply 'string eshell-glob-chars-list)))
-  (make-local-hook 'eshell-parse-argument-hook)
+  (when (boundp 'eshell-special-chars-outside-quoting)
+    (set (make-local-variable 'eshell-special-chars-outside-quoting)
+	 (append eshell-glob-chars-list eshell-special-chars-outside-quoting)))
   (add-hook 'eshell-parse-argument-hook 'eshell-parse-glob-chars t t)
-  (make-local-hook 'eshell-pre-rewrite-command-hook)
   (add-hook 'eshell-pre-rewrite-command-hook
 	    'eshell-no-command-globbing nil t))
 
 		  (buffer-substring-no-properties (1- (point)) (1+ end))
 		(goto-char (1+ end))))))))))
 
+(defvar eshell-glob-chars-regexp nil)
+
 (defun eshell-glob-regexp (pattern)
   "Convert glob-pattern PATTERN to a regular expression.
 The basic syntax is:
 resulting regular expression."
   (let ((matched-in-pattern 0)          ; How much of PATTERN handled
 	regexp)
-    (while (string-match eshell-glob-chars-regexp
-			 pattern matched-in-pattern)
+    (while (string-match
+	    (or eshell-glob-chars-regexp
+		(set (make-local-variable 'eshell-glob-chars-regexp)
+		     (format "[%s]+" (apply 'string eshell-glob-chars-list))))
+	    pattern matched-in-pattern)
       (let* ((op-begin (match-beginning 0))
 	     (op-char (aref pattern op-begin)))
 	(setq regexp
 
 (defun eshell-extended-glob (glob)
   "Return a list of files generated from GLOB, perhaps looking for DIRS-ONLY.
- This function almost fully supports zsh style filename generation
- syntax.  Things that are not supported are:
+This function almost fully supports zsh style filename generation
+syntax.  Things that are not supported are:
 
    ^foo        for matching everything but foo
    (foo~bar)   tilde within a parenthesis group
    foo<1-10>   numeric ranges
    foo~x(a|b)  (a|b) will be interpreted as a predicate/modifier list
 
- Mainly they are not supported because file matching is done with Emacs
- regular expressions, and these cannot support the above constructs.
+Mainly they are not supported because file matching is done with Emacs
+regular expressions, and these cannot support the above constructs.
 
- If this routine fails, it returns nil.  Otherwise, it returns a list
- the form:
+If this routine fails, it returns nil.  Otherwise, it returns a list
+the form:
 
    (INCLUDE-REGEXP EXCLUDE-REGEXP (PRED-FUNC-LIST) (MOD-FUNC-LIST))"
   (let ((paths (eshell-split-path glob))
       (eshell-glob-entries (car rdirs) globs recurse-p)
       (setq rdirs (cdr rdirs)))))
 
-;;; Code:
-
 ;;; em-glob.el ends here
-;;; em-hist --- history list management
+;;; em-hist.el --- history list management
 
-;; Copyright (C) 1999, 2000 Free Software Foundation
+;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
 
 ;; 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 'em-hist)
 
 History is always preserved after sanely exiting an Eshell buffer.
 However, when Emacs is being shut down, this variable determines
 whether to prompt the user.
-If set to nil, it means never ask whether history should be saved.
-If set to t, always ask if any Eshell buffers are open at exit time.
-If set to `always', history will always be saved, silently."
+If set to nil, it means never save history on termination of Emacs.
+If set to `ask', ask if any Eshell buffers are open at exit time.
+If set to t, history will always be saved, silently."
   :type '(choice (const :tag "Never" nil)
-		 (const :tag "Ask" t)
-		 (const :tag "Always save" always))
+		 (const :tag "Ask" ask)
+		 (const :tag "Always save" t))
   :group 'eshell-hist)
 
 (defcustom eshell-input-filter
   (define-key eshell-isearch-map [(control ?c)] 'eshell-isearch-cancel-map)
   (define-key eshell-isearch-cancel-map [(control ?c)] 'eshell-isearch-cancel))
 
+(defvar eshell-rebind-keys-alist)
+
 ;;; Functions:
 
 (defun eshell-hist-initialize ()
   "Initialize the history management code for one Eshell buffer."
-  (make-local-hook 'eshell-expand-input-functions)
   (add-hook 'eshell-expand-input-functions
 	    'eshell-expand-history-references nil t)
 
   (when (eshell-using-module 'eshell-cmpl)
-    (make-local-hook 'pcomplete-try-first-hook)
     (add-hook 'pcomplete-try-first-hook
 	      'eshell-complete-history-reference nil t))
 
-  (if (eshell-using-module 'eshell-rebind)
-      (let ((rebind-alist (symbol-value 'eshell-rebind-keys-alist)))
+  (if (and (eshell-using-module 'eshell-rebind)
+	   (not eshell-non-interactive-p))
+      (let ((rebind-alist eshell-rebind-keys-alist))
 	(make-local-variable 'eshell-rebind-keys-alist)
-	(set 'eshell-rebind-keys-alist
-	     (append rebind-alist eshell-hist-rebind-keys-alist))
+	(setq eshell-rebind-keys-alist
+	      (append rebind-alist eshell-hist-rebind-keys-alist))
 	(set (make-local-variable 'search-invisible) t)
 	(set (make-local-variable 'search-exit-option) t)
-	(make-local-hook 'isearch-mode-hook)
 	(add-hook 'isearch-mode-hook
 		  (function
 		   (lambda ()
 		     (if (>= (point) eshell-last-output-end)
 			 (setq overriding-terminal-local-map
 			       eshell-isearch-map)))) nil t)
-	(make-local-hook 'isearch-mode-end-hook)
 	(add-hook 'isearch-mode-end-hook
 		  (function
 		   (lambda ()
 
   (make-local-variable 'eshell-history-index)
   (make-local-variable 'eshell-save-history-index)
-  (make-local-variable 'eshell-history-ring)
-  (if eshell-history-file-name
-      (eshell-read-history nil t))
+
+  (if (minibuffer-window-active-p (selected-window))
+      (set (make-local-variable 'eshell-save-history-on-exit) nil)
+    (set (make-local-variable 'eshell-history-ring) nil)
+    (if eshell-history-file-name
+	(eshell-read-history nil t))
+
+    (add-hook 'eshell-exit-hook 'eshell-write-history nil t))
+
   (unless eshell-history-ring
     (setq eshell-history-ring (make-ring eshell-history-size)))
 
-  (make-local-hook 'eshell-exit-hook)
   (add-hook 'eshell-exit-hook 'eshell-write-history nil t)
 
   (add-hook 'kill-emacs-hook 'eshell-save-some-history)
 	(with-current-buffer buf
 	  (if (and eshell-mode
 		   eshell-history-file-name
-		   eshell-ask-to-save-history
-		   (or (eq eshell-ask-to-save-history 'always)
+		   eshell-save-history-on-exit
+		   (or (eq eshell-save-history-on-exit t)
 		       (y-or-n-p
 			(format "Save input history for Eshell buffer `%s'? "
 				(buffer-name buf)))))
   "Get an input line from the history ring."
   (ring-ref (or ring eshell-history-ring) index))
 
-(defun eshell-add-to-history ()
-  "Add INPUT to the history ring.
-The input is entered into the input history ring, if the value of
+(defun eshell-add-input-to-history (input)
+  "Add the string INPUT to the history ring.
+Input is entered into the input history ring, if the value of
 variable `eshell-input-filter' returns non-nil when called on the
 input."
+  (if (and (funcall eshell-input-filter input)
+	   (or (null eshell-hist-ignoredups)
+	       (not (ring-p eshell-history-ring))
+	       (ring-empty-p eshell-history-ring)
+	       (not (string-equal (eshell-get-history 0) input))))
+      (eshell-put-history input))
+  (setq eshell-save-history-index eshell-history-index)
+  (setq eshell-history-index nil))
+
+(defun eshell-add-command-to-history ()
+  "Add the command entered at `eshell-command's prompt to the history ring.
+The command is added to the input history ring, if the value of
+variable `eshell-input-filter' returns non-nil when called on the
+command.
+
+This function is supposed to be called from the minibuffer, presumably
+as a minibuffer-exit-hook."
+  (eshell-add-input-to-history
+   (buffer-substring (minibuffer-prompt-end) (point-max))))
+
+(defun eshell-add-to-history ()
+  "Add last Eshell command to the history ring.
+The command is entered into the input history ring, if the value of
+variable `eshell-input-filter' returns non-nil when called on the
+command."
   (when (> (1- eshell-last-input-end) eshell-last-input-start)
     (let ((input (buffer-substring eshell-last-input-start
 				   (1- eshell-last-input-end))))
-      (if (and (funcall eshell-input-filter input)
-	       (or (null eshell-hist-ignoredups)
-		   (not (ring-p eshell-history-ring))
-		   (ring-empty-p eshell-history-ring)
-		   (not (string-equal (eshell-get-history 0) input))))
-	  (eshell-put-history input))
-      (setq eshell-save-history-index eshell-history-ring)
-      (setq eshell-history-index nil))))
+      (eshell-add-input-to-history input))))
 
 (defun eshell-read-history (&optional filename silent)
   "Sets the buffer's `eshell-history-ring' from a history file.
 	;; Change "completion" to "history reference"
 	;; to make the display accurate.
 	(with-output-to-temp-buffer history-buffer
-	  (display-completion-list history)
+	  (display-completion-list history prefix)
 	  (set-buffer history-buffer)
 	  (forward-line 3)
 	  (while (search-backward "completion" nil 'move)
    ((string= "^" ref) 1)
    ((string= "$" ref) nil)
    ((string= "%" ref)
-    (error "`%' history word designator not yet implemented"))))
+    (error "`%%' history word designator not yet implemented"))))
 
 (defun eshell-hist-parse-arguments (&optional silent b e)
   "Parse current command arguments in a history-code-friendly way."
     (if (null pos)
 	(error "Not found")
       (setq eshell-history-index pos)
-      (message "History item: %d" (- (ring-length eshell-history-ring) pos))
+      (unless (minibuffer-window-active-p (selected-window))
+	(message "History item: %d" (- (ring-length eshell-history-ring) pos)))
        ;; Can't use kill-region as it sets this-command
-      (delete-region (save-excursion (eshell-bol) (point)) (point))
+      (delete-region eshell-last-output-end (point))
       (insert-and-inherit (eshell-get-history pos)))))
 
 (defun eshell-next-matching-input (regexp arg)
-;;; em-ls --- implementation of ls in Lisp
+;;; em-ls.el --- implementation of ls in Lisp
 
-;; Copyright (C) 1999, 2000 Free Software Foundation
+;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
 
 ;; 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 'em-ls)
 
   :type '(repeat :tag "Arguments" string)
   :group 'eshell-ls)
 
+(defcustom eshell-ls-dired-initial-args nil
+  "*If non-nil, args is included before any call to `ls' in Dired.
+This is useful for enabling human-readable format (-h), for example."
+  :type '(repeat :tag "Arguments" string)
+  :group 'eshell-ls)
+
 (defcustom eshell-ls-use-in-dired nil
-  "*If non-nil, use `eshell-ls' to read directories in dired."
+  "*If non-nil, use `eshell-ls' to read directories in Dired."
   :set (lambda (symbol value)
 	 (if value
 	     (unless (and (boundp 'eshell-ls-use-in-dired)
 
 (defcustom eshell-ls-exclude-regexp nil
   "*Unless -a is specified, files matching this regexp will not be shown."
-  :type 'regexp
+  :type '(choice regexp (const nil))
   :group 'eshell-ls)
 
 (defcustom eshell-ls-exclude-hidden t
   :type 'boolean
   :group 'eshell-ls)
 
-(defface eshell-ls-directory-face
+(defface eshell-ls-directory
   '((((class color) (background light)) (:foreground "Blue" :bold t))
     (((class color) (background dark)) (:foreground "SkyBlue" :bold t))
     (t (:bold t)))
   "*The face used for highlight directories."
   :group 'eshell-ls)
+;; backward-compatibility alias
+(put 'eshell-ls-directory-face 'face-alias 'eshell-ls-directory)
 
-(defface eshell-ls-symlink-face
+(defface eshell-ls-symlink
   '((((class color) (background light)) (:foreground "Dark Cyan" :bold t))
     (((class color) (background dark)) (:foreground "Cyan" :bold t)))
   "*The face used for highlight symbolic links."
   :group 'eshell-ls)
+;; backward-compatibility alias
+(put 'eshell-ls-symlink-face 'face-alias 'eshell-ls-symlink)
 
-(defface eshell-ls-executable-face
+(defface eshell-ls-executable
   '((((class color) (background light)) (:foreground "ForestGreen" :bold t))
     (((class color) (background dark)) (:foreground "Green" :bold t)))
   "*The face used for highlighting executables (not directories, though)."
   :group 'eshell-ls)
+;; backward-compatibility alias
+(put 'eshell-ls-executable-face 'face-alias 'eshell-ls-executable)
 
-(defface eshell-ls-readonly-face
+(defface eshell-ls-readonly
   '((((class color) (background light)) (:foreground "Brown"))
     (((class color) (background dark)) (:foreground "Pink")))
   "*The face used for highlighting read-only files."
   :group 'eshell-ls)
+;; backward-compatibility alias
+(put 'eshell-ls-readonly-face 'face-alias 'eshell-ls-readonly)
 
-(defface eshell-ls-unreadable-face
+(defface eshell-ls-unreadable
   '((((class color) (background light)) (:foreground "Grey30"))
     (((class color) (background dark)) (:foreground "DarkGrey")))
   "*The face used for highlighting unreadable files."
   :group 'eshell-ls)
+;; backward-compatibility alias
+(put 'eshell-ls-unreadable-face 'face-alias 'eshell-ls-unreadable)
 
-(defface eshell-ls-special-face
+(defface eshell-ls-special
   '((((class color) (background light)) (:foreground "Magenta" :bold t))
     (((class color) (background dark)) (:foreground "Magenta" :bold t)))
   "*The face used for highlighting non-regular files."
   :group 'eshell-ls)
+;; backward-compatibility alias
+(put 'eshell-ls-special-face 'face-alias 'eshell-ls-special)
 
-(defface eshell-ls-missing-face
+(defface eshell-ls-missing
   '((((class color) (background light)) (:foreground "Red" :bold t))
     (((class color) (background dark)) (:foreground "Red" :bold t)))
   "*The face used for highlighting non-existant file names."
   :group 'eshell-ls)
+;; backward-compatibility alias
+(put 'eshell-ls-missing-face 'face-alias 'eshell-ls-missing)
 
 (defcustom eshell-ls-archive-regexp
   (concat "\\.\\(t\\(a[rz]\\|gz\\)\\|arj\\|lzh\\|"
   :type 'regexp
   :group 'eshell-ls)
 
-(defface eshell-ls-archive-face
+(defface eshell-ls-archive
   '((((class color) (background light)) (:foreground "Orchid" :bold t))
     (((class color) (background dark)) (:foreground "Orchid" :bold t)))
   "*The face used for highlighting archived and compressed file names."
   :group 'eshell-ls)
+;; backward-compatibility alias
+(put 'eshell-ls-archive-face 'face-alias 'eshell-ls-archive)
 
 (defcustom eshell-ls-backup-regexp
   "\\(\\`\\.?#\\|\\(\\.bak\\|~\\)\\'\\)"
   :type 'regexp
   :group 'eshell-ls)
 
-(defface eshell-ls-backup-face
+(defface eshell-ls-backup
   '((((class color) (background light)) (:foreground "OrangeRed"))
     (((class color) (background dark)) (:foreground "LightSalmon")))
   "*The face used for highlighting backup file names."
   :group 'eshell-ls)
+;; backward-compatibility alias
+(put 'eshell-ls-backup-face 'face-alias 'eshell-ls-backup)
 
 (defcustom eshell-ls-product-regexp
-  "\\.\\(elc\\|o\\(bj\\)?\\|a\\||lib\\|res\\)\\'"
+  "\\.\\(elc\\|o\\(bj\\)?\\|a\\|lib\\|res\\)\\'"
   "*A regular expression that matches names of product files.
 Products are files that get generated from a source file, and hence
 ought to be recreatable if they are deleted."
   :type 'regexp
   :group 'eshell-ls)
 
-(defface eshell-ls-product-face
+(defface eshell-ls-product
   '((((class color) (background light)) (:foreground "OrangeRed"))
     (((class color) (background dark)) (:foreground "LightSalmon")))
   "*The face used for highlighting files that are build products."
   :group 'eshell-ls)
+;; backward-compatibility alias
+(put 'eshell-ls-product-face 'face-alias 'eshell-ls-product)
 
 (defcustom eshell-ls-clutter-regexp
   "\\(^texput\\.log\\|^core\\)\\'"
   :type 'regexp
   :group 'eshell-ls)
 
-(defface eshell-ls-clutter-face
+(defface eshell-ls-clutter
   '((((class color) (background light)) (:foreground "OrangeRed" :bold t))
     (((class color) (background dark)) (:foreground "OrangeRed" :bold t)))
   "*The face used for highlighting junk file names."
   :group 'eshell-ls)
+;; backward-compatibility alias
+(put 'eshell-ls-clutter-face 'face-alias 'eshell-ls-clutter)
 
 (defsubst eshell-ls-filetype-p (attrs type)
   "Test whether ATTRS specifies a directory."
       (if (stringp switches)
 	  (setq switches (split-string switches)))
       (let (eshell-current-handles
-	    eshell-current-subjob-p)
+	    eshell-current-subjob-p
+	    font-lock-mode)
 	;; use the fancy highlighting in `eshell-ls' rather than font-lock
 	(when (and eshell-ls-use-colors
 		   (featurep 'font-lock))
 	  (font-lock-mode -1)
+	  (setq font-lock-defaults nil)
 	  (if (boundp 'font-lock-buffers)
 	      (set 'font-lock-buffers
 		   (delq (current-buffer)
 	(let ((insert-func 'insert)
 	      (error-func 'insert)
 	      (flush-func 'ignore)
-	      eshell-ls-initial-args)
+	      eshell-ls-dired-initial-args)
 	  (eshell-do-ls (append switches (list file))))))))
 
 (defsubst eshell/ls (&rest args)
 	(flush-func 'eshell-flush))
     (eshell-do-ls args)))
 
+(put 'eshell/ls 'eshell-no-numeric-conversions t)
+
 (eval-when-compile
   (defvar block-size)
   (defvar dereference-links)
   (defvar show-recursive)
   (defvar show-size)
   (defvar sort-method)
-  (defvar ange-cache))
+  (defvar ange-cache)
+  (defvar dired-flag))
 
 (defun eshell-do-ls (&rest args)
   "Implementation of \"ls\" in Lisp, passing ARGS."
    `((?a "all" nil show-all
 	 "show all files in directory")
      (?c nil by-ctime sort-method
-	 "sort by modification time")
+	 "sort by last status change time")
      (?d "directory" nil dir-literal
 	 "list directory entries instead of contents")
      (?k "kilobytes" 1024 block-size
 	 "sort alphabetically by entry extension")
      (?1 nil single-column listing-style
 	 "list one file per line")
+     (nil "dired" nil dired-flag
+	  "Here for compatibility with GNU ls.")
      (nil "help" nil nil
 	  "show this usage display")
      :external "ls"
 		     ""))
 		(let* ((str (eshell-ls-printable-size (nth 7 attrs)))
 		       (len (length str)))
-		  (if (< len 8)
-		      (concat (make-string (- 8 len) ? ) str)
+		  (if (< len (or size-width 4))
+		      (concat (make-string (- (or size-width 4) len) ? ) str)
 		    str))
 		" " (format-time-string
 		     (concat
 	(cons col-widths newfiles)))))
 
 (defun eshell-ls-decorated-name (file)
-  "Return FILE, possibly decorated.
-Use TRUENAME for predicate tests, if passed."
+  "Return FILE, possibly decorated."
   (if eshell-ls-use-colors
       (let ((face
 	     (cond
 	      ((not (cdr file))
-	       'eshell-ls-missing-face)
+	       'eshell-ls-missing)
 
 	      ((stringp (cadr file))
-	       'eshell-ls-symlink-face)
+	       'eshell-ls-symlink)
 
 	      ((eq (cadr file) t)
-	       'eshell-ls-directory-face)
+	       'eshell-ls-directory)
 
 	      ((not (eshell-ls-filetype-p (cdr file) ?-))
-	       'eshell-ls-special-face)
+	       'eshell-ls-special)
 
 	      ((and (/= (user-uid) 0) ; root can execute anything
 		    (eshell-ls-applicable (cdr file) 3
 					  'file-executable-p (car file)))
-	       'eshell-ls-executable-face)
+	       'eshell-ls-executable)
 
 	      ((not (eshell-ls-applicable (cdr file) 1
 					  'file-readable-p (car file)))
-	       'eshell-ls-unreadable-face)
+	       'eshell-ls-unreadable)
 
 	      ((string-match eshell-ls-archive-regexp (car file))
-	       'eshell-ls-archive-face)
+	       'eshell-ls-archive)
 
 	      ((string-match eshell-ls-backup-regexp (car file))
-	       'eshell-ls-backup-face)
+	       'eshell-ls-backup)
 
 	      ((string-match eshell-ls-product-regexp (car file))
-	       'eshell-ls-product-face)
+	       'eshell-ls-product)
 
 	      ((string-match eshell-ls-clutter-regexp (car file))
-	       'eshell-ls-clutter-face)
+	       'eshell-ls-clutter)
 
 	      ((not (eshell-ls-applicable (cdr file) 2
 					  'file-writable-p (car file)))
-	       'eshell-ls-readonly-face)
+	       'eshell-ls-readonly)
 	      (eshell-ls-highlight-alist
 	       (let ((tests eshell-ls-highlight-alist)
 		     value)
-;;; em-pred --- argument predicates and modifiers (ala zsh)
+;;; em-pred.el --- argument predicates and modifiers (ala zsh)
 
-;; Copyright (C) 1999, 2000 Free Software Foundation
+;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
 
 ;; 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 'em-pred)
 
 ;; See the zsh docs for more on the syntax ([(zsh.info)Filename
 ;; Generation]).
 
+;;; Code:
+
 ;;; User Variables:
 
 (defcustom eshell-pred-load-hook '(eshell-pred-initialize)
 (put 'eshell-predicate-alist 'risky-local-variable t)
 
 (defcustom eshell-modifier-alist
-  '((?e . '(lambda (lst)
+  '((?E . '(lambda (lst)
 	     (mapcar
 	      (function
 	       (lambda (str)
 
 FILE ATTRIBUTES:
   l[+-]N                 +/-/= N links
-  a[Mwhm][+-](N|'FILE')  access time +/-/= N mnths/weeks/days/mins
-			 if FILE specified, use as comparison basis;
-			 so a+'file.c' shows files accessed before
-			 file.c was last accessed
-  m[Mwhm][+-](N|'FILE')  modification time...
-  c[Mwhm][+-](N|'FILE')  change time...
+  a[Mwhms][+-](N|'FILE') access time +/-/= N mnths/weeks/hours/mins/secs
+			 (days if unspecified) if FILE specified,
+			 use as comparison basis; so a+'file.c'
+			 shows files accessed before file.c was
+			 last accessed
+  m[Mwhms][+-](N|'FILE') modification time...
+  c[Mwhms][+-](N|'FILE') change time...
   L[kmp][+-]N            file size +/-/= N Kb/Mb/blocks
 
 EXAMPLES:
   "Eshell modifier quick reference:
 
 FOR SINGLE ARGUMENTS, or each argument of a list of strings:
-  e  evaluate again
+  E  evaluate again
   L  lowercase
   U  uppercase
   C  capitalize
   q  escape special characters
 
   S       split string at any whitespace character
-  S/PAT/  split string at each occurance of PAT
+  S/PAT/  split string at each occurrence of PAT
 
 FOR LISTS OF ARGUMENTS:
   o  sort alphabetically
   x/PAT/  exclude all members matching PAT
 
   s/pat/match/  substitute PAT with MATCH
-  g/pat/match/  substitute PAT with MATCH for all occurances
+  g/pat/match/  substitute PAT with MATCH for all occurrences
 
 EXAMPLES:
   *.c(:o)  sorted list of .c files")
 
 (defun eshell-pred-initialize ()
   "Initialize the predicate/modifier code."
-  (make-local-hook 'eshell-parse-argument-hook)
   (add-hook 'eshell-parse-argument-hook
 	    'eshell-parse-arg-modifier t t)
   (define-key eshell-command-map [(meta ?q)] 'eshell-display-predicate-help)
   "Return a predicate to test whether a file matches a certain time."
   (let* ((quantum 86400)
 	 qual amount when open close end)
-    (when (memq (char-after) '(?M ?w ?h ?m))
+    (when (memq (char-after) '(?M ?w ?h ?m ?s))
       (setq quantum (char-after))
       (cond
        ((eq quantum ?M)
 	 (lambda (str)
 	   (split-string str ,sep))) lst))))
 
-;;; Code:
-
 ;;; em-pred.el ends here
-;;; em-prompt --- command prompts
+;;; em-prompt.el --- command prompts
 
-;; Copyright (C) 1999, 2000 Free Software Foundation
+;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
 
 ;; 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 'em-prompt)
 
   :type 'boolean
   :group 'eshell-prompt)
 
-(defface eshell-prompt-face
+(defface eshell-prompt
   '((((class color) (background light)) (:foreground "Red" :bold t))
     (((class color) (background dark)) (:foreground "Pink" :bold t))
     (t (:bold t)))
 For highlighting other kinds of strings -- similar to shell mode's
 behavior -- simply use an output filer which changes text properties."
   :group 'eshell-prompt)
+;; backward-compatibility alias
+(put 'eshell-prompt-face 'face-alias 'eshell-prompt)
 
 (defcustom eshell-before-prompt-hook nil
   "*A list of functions to call before outputting the prompt."
 (defun eshell-prompt-initialize ()
   "Initialize the prompting code."
   (unless eshell-non-interactive-p
-    (make-local-hook 'eshell-post-command-hook)
     (add-hook 'eshell-post-command-hook 'eshell-emit-prompt nil t)
 
     (make-local-variable 'eshell-prompt-regexp)
       (and eshell-highlight-prompt
 	   (add-text-properties 0 (length prompt)
 				'(read-only t
-				  face eshell-prompt-face
+				  face eshell-prompt
 				  rear-nonsticky (face read-only))
 				prompt))
       (eshell-interactive-print prompt)))
-;;; em-rebind --- rebind keys when point is at current input
+;;; em-rebind.el --- rebind keys when point is at current input
 
-;; Copyright (C) 1999, 2000 Free Software Foundation
+;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
 
 ;; 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 'em-rebind)
 
     forward-word
     backward-word
     forward-line
-    backward-line
     previous-line
     next-line
     forward-visible-line
 (defun eshell-rebind-initialize ()
   "Initialize the inputing code."
   (unless eshell-non-interactive-p
-    (make-local-hook 'eshell-mode-hook)
     (add-hook 'eshell-mode-hook 'eshell-setup-input-keymap nil t)
-    (make-local-hook 'pre-command-hook)
     (make-local-variable 'eshell-previous-point)
     (add-hook 'pre-command-hook 'eshell-save-previous-point nil t)
-    (make-local-hook 'post-command-hook)
     (make-local-variable 'overriding-local-map)
     (add-hook 'post-command-hook 'eshell-rebind-input-map nil t)
     (set (make-local-variable 'eshell-lock-keymap) nil)
-;;; em-script --- Eshell script files
+;;; em-script.el --- Eshell script files
 
-;; Copyright (C) 1999, 2000 Free Software Foundation
+;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
 
 ;; 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.
+
+;;; Code:
 
 (provide 'em-script)
 
 $2, etc.")
    (eshell-source-file (car args) (cdr args) t)))
 
+(put 'eshell/source 'eshell-no-numeric-conversions t)
+
 (defun eshell/. (&rest args)
   "Source a file in the current environment."
   (eshell-eval-using-options
 environment, binding ARGS to $1, $2, etc.")
    (eshell-source-file (car args) (cdr args))))
 
-;;; Code:
+(put 'eshell/. 'eshell-no-numeric-conversions t)
 
 ;;; em-script.el ends here
-;;; em-smart --- smart display of output
+;;; em-smart.el --- smart display of output
 
-;; Copyright (C) 1999, 2000 Free Software Foundation
+;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
 
 ;; 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 'em-smart)
 
 Most likely you will have to turn this option on and play around with
 it to get a real sense of how it works."
   :tag "Smart display of output"
-  :link '(info-link "(eshell)Smart display of output")
+  ;; :link '(info-link "(eshell)Smart display of output")
   :group 'eshell-module)
 
 ;;; Commentary:
     (set (make-local-variable 'eshell-scroll-to-bottom-on-input) nil)
     (set (make-local-variable 'eshell-scroll-show-maximum-output) t)
 
-    (make-local-hook 'window-scroll-functions)
     (add-hook 'window-scroll-functions 'eshell-smart-scroll-window nil t)
     (add-hook 'window-configuration-change-hook 'eshell-refresh-windows)
 
-    (make-local-hook 'eshell-output-filter-functions)
     (add-hook 'eshell-output-filter-functions 'eshell-refresh-windows t t)
 
-    (make-local-hook 'pre-command-hook)
-    (make-local-hook 'after-change-functions)
     (add-hook 'after-change-functions 'eshell-disable-after-change nil t)
 
-    (make-local-hook 'eshell-input-filter-functions)
     (add-hook 'eshell-input-filter-functions 'eshell-smart-display-setup nil t)
 
     (make-local-variable 'eshell-smart-command-done)
-    (make-local-hook 'eshell-post-command-hook)
     (add-hook 'eshell-post-command-hook
 	      (function
 	       (lambda ()
 
 (defun eshell-smart-maybe-jump-to-end ()
   "Jump to the end of the input buffer.
-This is done whenever a command exits sucessfully and both the command
+This is done whenever a command exits successfully and both the command
 and the end of the buffer are still visible."
   (when (and (= eshell-last-command-status 0)
 	     (if (eq eshell-review-quick-commands 'not-even-short-output)
 (defun eshell-smart-redisplay ()
   "Display as much output as possible, smartly."
   (if (eobp)
-      (recenter -1)
+      (save-excursion
+	(recenter -1)
+	;; trigger the redisplay now, so that we catch any attempted
+	;; point motion; this is to cover for a redisplay bug
+	(eshell-redisplay))
     (let ((top-point (point)))
       (and (memq 'eshell-smart-display-move pre-command-hook)
 	   (>= (point) eshell-last-input-start)
-;;; em-term --- running visual commands
+;;; em-term.el --- running visual commands
 
-;; Copyright (C) 1999, 2000 Free Software Foundation
+;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
 
 ;; 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 'em-term)
 
 ;   (interactive)
 ;   ;; Convert `return' to C-m, etc.
 ;   (if (and (symbolp last-input-char)
-;          (or (get last-input-char 'character-of-keysym)
-;              (get last-input-char 'ascii-character)))
-;       (setq last-input-char 
-; 	    (or (get last-input-char 'character-of-keysym)
-; 		(get last-input-char 'ascii-character))))
+;	   (get last-input-char 'ascii-character))
+;       (setq last-input-char (get last-input-char 'ascii-character)))
 ;   (eshell-term-send-raw-string (make-string 1 last-input-char)))
 
 ; (defun eshell-term-send-raw-meta ()
 ;	    (setq last-input-char (car tmp)))
 ;	(if (symbolp last-input-char)
 ;	    (progn
-;	      (setq tmp (or (get last-input-char 'character-of-keysym)
-;			    (get last-input-char 'ascii-character)))
+;	      (setq tmp (get last-input-char 'ascii-character))
 ;	      (if tmp (setq last-input-char tmp))))))
 ;   (eshell-term-send-raw-string (if (and (numberp last-input-char)
 ;					(> last-input-char 127)
-;;; em-unix --- UNIX command aliases
+;;; em-unix.el --- UNIX command aliases
 
-;; Copyright (C) 1999, 2000 Free Software Foundation
+;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
 
 ;; 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 'em-unix)
 
 
 (defun eshell-unix-initialize ()
   "Initialize the UNIX support/emulation code."
-  (make-local-hook 'eshell-post-command-hook)
   (when (eshell-using-module 'eshell-cmpl)
-    (make-local-hook 'pcomplete-try-first-hook)
     (add-hook 'pcomplete-try-first-hook
 	      'eshell-complete-host-reference nil t))
   (make-local-variable 'eshell-complex-commands)
   "Invoke man, flattening the arguments appropriately."
   (funcall 'man (apply 'eshell-flatten-and-stringify args)))
 
+(put 'eshell/man 'eshell-no-numeric-conversions t)
+
 (defun eshell-remove-entries (path files &optional top-level)
   "From PATH, remove all of the given FILES, perhaps interactively."
   (while files
      (setq args (cdr args)))
    nil))
 
+(put 'eshell/rm 'eshell-no-numeric-conversions t)
+
 (defun eshell/mkdir (&rest args)
   "Implementation of mkdir in Lisp."
   (eshell-eval-using-options
      (setq args (cdr args)))
    nil))
 
+(put 'eshell/mkdir 'eshell-no-numeric-conversions t)
+
 (defun eshell/rmdir (&rest args)
   "Implementation of rmdir in Lisp."
   (eshell-eval-using-options
      (setq args (cdr args)))
    nil))
 
+(put 'eshell/rmdir 'eshell-no-numeric-conversions t)
+
 (eval-when-compile
   (defvar no-dereference)
   (defvar preview)
 		 (eq system-type 'ms-dos))
 	     (setq attr (eshell-file-attributes (car files)))
 	     (nth 10 attr-target) (nth 10 attr)
-	     (= (nth 10 attr-target) (nth 10 attr))
+	     ;; Use equal, not -, since the inode and the device could
+	     ;; cons cells.
+	     (equal (nth 10 attr-target) (nth 10 attr))
 	     (nth 11 attr-target) (nth 11 attr)
-	     (= (nth 11 attr-target) (nth 11 attr)))
+	     (equal (nth 11 attr-target) (nth 11 attr)))
 	(eshell-error (format "%s: `%s' and `%s' are the same file\n"
 			      command (car files) target)))
        (t
 		(let (eshell-warn-dot-directories)
 		  (if (and (not deep)
 			   (eq func 'rename-file)
-			   (= (nth 11 (eshell-file-attributes
-				       (file-name-directory
-					(expand-file-name source))))
-			      (nth 11 (eshell-file-attributes
-				       (file-name-directory
-					(expand-file-name target))))))
+			   ;; Use equal, since the device might be a
+			   ;; cons cell.
+			   (equal (nth 11 (eshell-file-attributes
+					   (file-name-directory
+					    (directory-file-name
+					     (expand-file-name source)))))
+				  (nth 11 (eshell-file-attributes
+					   (file-name-directory
+					    (directory-file-name
+					     (expand-file-name target)))))))
 		      (apply 'eshell-funcalln func source target args)
 		  (unless (file-directory-p target)
 		    (if verbose
 			     eshell-mv-interactive-query
 			     eshell-mv-overwrite-files))))
 
+(put 'eshell/mv 'eshell-no-numeric-conversions t)
+
 (defun eshell/cp (&rest args)
   "Implementation of cp in Lisp."
   (eshell-eval-using-options
 			   eshell-cp-interactive-query
 			   eshell-cp-overwrite-files preserve)))
 
+(put 'eshell/cp 'eshell-no-numeric-conversions t)
+
 (defun eshell/ln (&rest args)
   "Implementation of ln in Lisp."
   (eshell-eval-using-options
 			     eshell-ln-interactive-query
 			     eshell-ln-overwrite-files))))
 
+(put 'eshell/ln 'eshell-no-numeric-conversions t)
+
 (defun eshell/cat (&rest args)
   "Implementation of cat in Lisp.
 If in a pipeline, or the file is not a regular file, directory or
   (if (or eshell-in-pipeline-p
 	  (catch 'special
 	    (eshell-for arg args
-	      (unless (let ((attrs (eshell-file-attributes arg)))
-			(and attrs (memq (aref (nth 8 attrs) 0)
-					 '(?d ?l ?-))))
+	      (unless (or (and (stringp arg)
+			       (> (length arg) 0)
+			       (eq (aref arg 0) ?-))
+			  (let ((attrs (eshell-file-attributes arg)))
+			    (and attrs (memq (aref (nth 8 attrs) 0)
+					     '(?d ?l ?-)))))
 		(throw 'special t)))))
       (let ((ext-cat (eshell-search-path "cat")))
 	(if ext-cat
      ;; if the file does not end in a newline, do not emit one
      (setq eshell-ensure-newline-p nil))))
 
+(put 'eshell/cat 'eshell-no-numeric-conversions t)
+
 ;; special front-end functions for compilation-mode buffers
 
 (defun eshell/make (&rest args)
 	   (eshell-parse-command "*make" (eshell-stringify-list
 					  (eshell-flatten-list args))))))
 
+(put 'eshell/make 'eshell-no-numeric-conversions t)
+
 (defun eshell-occur-mode-goto-occurrence ()
   "Go to the occurrence the current line describes."
   (interactive)
 (defun eshell-occur-mode-mouse-goto (event)
   "In Occur mode, go to the occurrence whose line you click on."
   (interactive "e")
-  (let (buffer pos)
+  (let (pos)
     (save-excursion
       (set-buffer (window-buffer (posn-window (event-end event))))
       (save-excursion
 	(goto-char (posn-point (event-end event)))
-	(setq pos (occur-mode-find-occurrence))
-	(setq buffer occur-buffer)))
+	(setq pos (occur-mode-find-occurrence))))
     (pop-to-buffer (marker-buffer pos))
     (goto-char (marker-position pos))))
 
 		(if string (insert string))
 		(setq string nil
 		      files (cdr files)))))
-	  (setq occur-buffer (current-buffer))
 	  (local-set-key [mouse-2] 'eshell-occur-mode-mouse-goto)
 	  (local-set-key [(control ?c) (control ?c)]
 			 'eshell-occur-mode-goto-occurrence)
 	       (eshell-parse-command (concat "*" command)
 				     (eshell-stringify-list
 				      (eshell-flatten-list args))))
-      (let* ((compilation-process-setup-function
-	      (list 'lambda nil
-		    (list 'setq 'process-environment
-			  (list 'quote (eshell-copy-environment)))))
-	     (args (mapconcat 'identity
+      (let* ((args (mapconcat 'identity
 			      (mapcar 'shell-quote-argument
 				      (eshell-stringify-list
 				       (eshell-flatten-list args)))
        (unless by-bytes
 	 (setq block-size (or block-size 1024)))
        (if (and max-depth (stringp max-depth))
-	   (setq max-depth (string-to-int max-depth)))
+	   (setq max-depth (string-to-number max-depth)))
        ;; filesystem support means nothing under Windows
        (if (eshell-under-windows-p)
 	   (setq only-one-filesystem nil))
 		      (not eshell-in-subcommand-p))))
 	(throw 'eshell-replace-command
 	       (eshell-parse-command "*diff" orig-args))
-      (setq args (eshell-copy-list orig-args))
+      (setq args (copy-sequence orig-args))
       (if (< (length args) 2)
 	  (throw 'eshell-replace-command
 		 (eshell-parse-command "*diff" orig-args)))
 	       (throw 'eshell-replace-command
 		      (eshell-parse-command "*diff" orig-args))))
 	  (when (fboundp 'diff-mode)
-	    (diff-mode)
-	    (set (make-local-variable 'eshell-diff-window-config) config)
-	    (local-set-key [?q] 'eshell-diff-quit)
-	    (if (fboundp 'turn-on-font-lock-if-enabled)
-		(turn-on-font-lock-if-enabled))))
-	(other-window 1)
-	(goto-char (point-min))
-	nil))))
+	    (make-local-variable 'compilation-finish-functions)
+	    (add-hook
+	     'compilation-finish-functions
+	     `(lambda (buff msg)
+		(with-current-buffer buff
+		  (diff-mode)
+		  (set (make-local-variable 'eshell-diff-window-config)
+		       ,config)
+		  (local-set-key [?q] 'eshell-diff-quit)
+		  (if (fboundp 'turn-on-font-lock-if-enabled)
+		      (turn-on-font-lock-if-enabled))
+		  (goto-char (point-min))))))
+	  (pop-to-buffer (current-buffer))))))
+  nil)
+
+(put 'eshell/diff 'eshell-no-numeric-conversions t)
 
 (defun eshell/locate (&rest args)
   "Alias \"locate\" to call Emacs `locate' function."
       (let ((locate-history-list (list (car args))))
 	(locate-with-filter (car args) (cadr args))))))
 
+(put 'eshell/locate 'eshell-no-numeric-conversions t)
+
 (defun eshell/occur (&rest args)
   "Alias \"occur\" to call Emacs `occur' function."
   (let ((inhibit-read-only t))
-    (if args
-	(error "usage: occur: (REGEXP)")
-      (occur (car args)))))
+    (if (> (length args) 2)
+	(error "usage: occur: (REGEXP &optional NLINES)")
+      (apply 'occur args))))
+
+(put 'eshell/occur 'eshell-no-numeric-conversions t)
 
 ;;; Code:
 
-;;; em-xtra --- extra alias functions
+;;; em-xtra.el --- extra alias functions
 
-;; Copyright (C) 1999, 2000 Free Software Foundation
+;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
 
 ;; 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 'em-xtra)
 
-;;; esh-arg --- argument processing
+;;; esh-arg.el --- argument processing
 
-;; Copyright (C) 1999, 2000 Free Software Foundation
+;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
 
 ;; 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-arg)
 
 		 (looking-at eshell-number-regexp)
 		 (eshell-arg-delimiter (match-end 0)))
 	(goto-char (match-end 0))
-	(string-to-number (match-string 0)))))
+	(let ((str (match-string 0)))
+	  (if (> (length str) 0)
+	      (add-text-properties 0 1 '(number t) str))
+	  str))))
 
    ;; parse any non-special characters, based on the current context
    (function
 	    (save-restriction
 	      (forward-char)
 	      (narrow-to-region (point) end)
-	      (list 'eshell-escape-arg
-		    (eshell-parse-argument)))
+	      (let ((arg (eshell-parse-argument)))
+		(if (eq arg nil)
+		    ""
+		  (list 'eshell-escape-arg arg))))
 	  (goto-char (1+ end)))))))
 
 (defun eshell-parse-special-reference ()
-;;; esh-cmd --- command invocation
+;;; esh-cmd.el --- command invocation
 
-;; Copyright (C) 1999, 2000 Free Software Foundation
+;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
 
 ;; 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-cmd)
 
 pressing <RET>.  There are several different kinds of commands,
 however."
   :tag "Command invocation"
-  :link '(info-link "(eshell)Command invocation")
+  ;; :link '(info-link "(eshell)Command invocation")
   :group 'eshell)
 
 ;;; Commentary:
   (set (make-local-variable 'eshell-last-command-name) nil)
   (set (make-local-variable 'eshell-last-async-proc) nil)
 
-  (make-local-hook 'eshell-kill-hook)
   (add-hook 'eshell-kill-hook 'eshell-resume-command nil t)
 
   ;; make sure that if a command is over, and no process is being
   ;; waited for, that `eshell-current-command' is set to nil.  This
   ;; situation can occur, for example, if a Lisp function results in
   ;; `debug' being called, and the user then types \\[top-level]
-  (make-local-hook 'eshell-post-command-hook)
   (add-hook 'eshell-post-command-hook
 	    (function
 	     (lambda ()
 	       (setq eshell-current-command nil
 		     eshell-last-async-proc nil))) nil t)
 
-  (make-local-hook 'eshell-parse-argument-hook)
   (add-hook 'eshell-parse-argument-hook
 	    'eshell-parse-subcommand-argument nil t)
   (add-hook 'eshell-parse-argument-hook
 	    'eshell-parse-lisp-argument nil t)
 
   (when (eshell-using-module 'eshell-cmpl)
-    (make-local-hook 'pcomplete-try-first-hook)
     (add-hook 'pcomplete-try-first-hook
 	      'eshell-complete-lisp-symbols nil t)))
 
 
 (defun eshell-rewrite-named-command (terms)
   "If no other rewriting rule transforms TERMS, assume a named command."
-  (list (if eshell-in-pipeline-p
-	    'eshell-named-command*
-	  'eshell-named-command)
-	(car terms)
-	(and (cdr terms)
-	     (append (list 'list) (cdr terms)))))
+  (let ((sym (if eshell-in-pipeline-p
+		 'eshell-named-command*
+	       'eshell-named-command))
+	(cmd (car terms))
+	(args (cdr terms)))
+    (if args
+	(list sym cmd (append (list 'list) (cdr terms)))
+      (list sym cmd))))
 
 (eshell-deftest cmd named-command
   "Execute named command"
 (defun eshell-rewrite-for-command (terms)
   "Rewrite a `for' command into its equivalent Eshell command form.
 Because the implementation of `for' relies upon conditional evaluation
-of its argumbent (i.e., use of a Lisp special form), it must be
+of its argument (i.e., use of a Lisp special form), it must be
 implemented via rewriting, rather than as a function."
   (if (and (stringp (car terms))
 	   (string= (car terms) "for")
        (eshell-invokify-arg (cadr terms) nil t)
        (list 'eshell-protect
 	     (eshell-invokify-arg
-	      (if (= (length terms) 5)
-		  (car (last terms 3))
+	      (if (= (length terms) 4)
+		  (car (last terms 2))
 		(car (last terms))) t))
-       (if (= (length terms) 5)
+       (if (= (length terms) 4)
 	   (list 'eshell-protect
 		 (eshell-invokify-arg
 		  (car (last terms)))) t))))
   "Return non-nil if the last command was \"successful\".
 For a bit of Lisp code, this means a return value of non-nil.
 For an external command, it means an exit code of 0."
-  (if (string= eshell-last-command-name "#<Lisp>")
+  (if (save-match-data
+	(string-match "#<\\(Lisp object\\|function .*\\)>"
+		      eshell-last-command-name))
       eshell-last-command-result
     (= eshell-last-command-status 0)))
 
 				       reversed last-terms-sym)
   "Separate TERMS using SEPARATOR.
 If REVERSED is non-nil, the list of separated term groups will be
-returned in reverse order.  If LAST-TERMS-SYM is a symbol, it's value
+returned in reverse order.  If LAST-TERMS-SYM is a symbol, its value
 will be set to a list of all the separator operators found (or '(list
 nil)' if none)."
   (let ((sub-terms (list t))
 
 (defmacro eshell-do-subjob (object)
   "Evaluate a command OBJECT as a subjob.
-We indicate thet the process was run in the background by returned it
+We indicate that the process was run in the background by returning it
 ensconced in a list."
   `(let ((eshell-current-subjob-p t))
      ,object))
     (setq eshell-current-command command)
     (let ((delim (catch 'eshell-incomplete
 		   (eshell-resume-eval))))
-      (if delim
-	  (error "Unmatched delimiter: %c"
-		 (if (listp delim)
-		     (car delim)
-		   delim))))))
+      ;; On systems that don't support async subprocesses, eshell-resume
+      ;; can return t.  Don't treat that as an error.
+      (if (listp delim)
+	  (setq delim (car delim)))
+      (if (and delim (not (eq delim t)))
+	  (error "Unmatched delimiter: %c" delim)))))
 
 (defun eshell-resume-command (proc status)
   "Resume the current command when a process ends."
   object)
 
 (defconst function-p-func
-  (if (eshell-under-xemacs-p)
+  (if (fboundp 'compiled-function-p)
       'compiled-function-p
     'byte-code-function-p))
 
   "Identify the COMMAND, and where it is located."
   (eshell-for name (cons command names)
     (let (program alias direct)
-      (if (eq (aref name 0) ?*)
+      (if (eq (aref name 0) eshell-explicit-command-char)
 	  (setq name (substring name 1)
 		direct t))
       (if (and (not direct)
 	(setq program (eshell-search-path name))
 	(let* ((esym (eshell-find-alias-function name))
 	       (sym (or esym (intern-soft name))))
-	  (if (and sym (fboundp sym)
-		   (or esym eshell-prefer-lisp-functions
-		       (not program)))
+	  (if (and (or esym (and sym (fboundp sym)))
+		   (or eshell-prefer-lisp-functions (not direct)))
 	      (let ((desc (let ((inhibit-redisplay t))
 			    (save-window-excursion
 			      (prog1
 				name (getenv "PATH")))
 	(eshell-printn program)))))
 
+(put 'eshell/which 'eshell-no-numeric-conversions t)
+
 (defun eshell-named-command (command &optional args)
   "Insert output from a plain COMMAND, using ARGS.
 COMMAND may result in an alias being executed, or a plain command."
 (defun eshell-find-alias-function (name)
   "Check whether a function called `eshell/NAME' exists."
   (let* ((sym (intern-soft (concat "eshell/" name)))
-	 (file (symbol-file sym))
-	 module-sym)
+	 (file (symbol-file sym 'defun)))
+    ;; If the function exists, but is defined in an eshell module
+    ;; that's not currently enabled, don't report it as found
     (if (and file
 	     (string-match "\\(em\\|esh\\)-\\(.*\\)\\(\\.el\\)?\\'" file))
-	(setq file (concat "eshell-" (match-string 2 file))))
-    (setq module-sym
-	  (and sym file (fboundp 'symbol-file)
+	(let ((module-sym
 	       (intern (file-name-sans-extension
-			(file-name-nondirectory file)))))
-    (and sym (functionp sym)
-	 (or (not module-sym)
-	     (eshell-using-module module-sym)
-	     (memq module-sym (eshell-subgroups 'eshell)))
-	 sym)))
+			(file-name-nondirectory
+			 (concat "eshell-" (match-string 2 file)))))))
+	  (if (and (functionp sym)
+		   (or (null module-sym)
+		       (eshell-using-module module-sym)
+		       (memq module-sym (eshell-subgroups 'eshell))))
+	      sym))
+      ;; Otherwise, if it's bound, return it.
+      (if (functionp sym)
+	  sym))))
 
 (defun eshell-plain-command (command args)
   "Insert output from a plain COMMAND, using ARGS.
 
 (defun eshell-lisp-command (object &optional args)
   "Insert Lisp OBJECT, using ARGS if a function."
-  (setq eshell-last-arguments args
-	eshell-last-command-name "#<Lisp>")
   (catch 'eshell-external               ; deferred to an external command
     (let* ((eshell-ensure-newline-p (eshell-interactive-output-p))
 	   (result
 	    (if (functionp object)
-		(eshell-apply object args)
+		(progn
+		  (setq eshell-last-arguments args
+			eshell-last-command-name
+			(concat "#<function " (symbol-name object) ">"))
+		  ;; if any of the arguments are flagged as numbers
+		  ;; waiting for conversion, convert them now
+		  (unless (get object 'eshell-no-numeric-conversions)
+		    (while args
+		      (let ((arg (car args)))
+			(if (and (stringp arg)
+				 (> (length arg) 0)
+				 (not (text-property-not-all
+				       0 (length arg) 'number t arg)))
+			    (setcar args (string-to-number arg))))
+		      (setq args (cdr args))))
+		  (eshell-apply object eshell-last-arguments))
+	      (setq eshell-last-arguments args
+		    eshell-last-command-name "#<Lisp object>")
 	      (eshell-eval object))))
       (if (and eshell-ensure-newline-p
 	       (save-excursion
-;;; esh-ext --- commands external to Eshell
+;;; esh-ext.el --- commands external to Eshell
 
-;; Copyright (C) 1999, 2000 Free Software Foundation
+;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
 
 ;; 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-ext)
 
 (eval-when-compile (require 'esh-maint))
+(require 'esh-util)
 
 (defgroup eshell-ext nil
   "External commands are invoked when operating system executables are
   :type 'hook
   :group 'eshell-ext)
 
+;; XEmacs specific, GNU have a 'exec-suffixes implemented in C source
+;; code, but XEmacs dont.
 (defcustom eshell-binary-suffixes
   (if (eshell-under-windows-p)
       '(".exe" ".com" ".bat" ".cmd" "")
       (if (string-match "\\(\\`cmdproxy\\|sh\\)\\.\\(com\\|exe\\)"
 			shell-file-name)
 	  (or (eshell-search-path "cmd.exe")
-	      (eshell-search-path "command.exe"))
+	      (eshell-search-path "command.com"))
 	shell-file-name))
   "*The name of the shell command to use for DOS/Windows batch files.
 This defaults to nil on non-Windows systems, where this variable is
 wholly ignored."
-  :type 'file
+  :type '(choice file (const nil))
   :group 'eshell-ext)
 
 (defsubst eshell-invoke-batch-file (&rest args)
   :type 'integer
   :group 'eshell-ext)
 
+(defcustom eshell-explicit-command-char ?*
+  "*If this char occurs before a command name, call it externally.
+That is, although `vi' may be an alias, `\vi' will always call the
+external version."
+  :type 'character
+  :group 'eshell-ext)
+
 ;;; Functions:
 
 (defun eshell-ext-initialize ()
   "Initialize the external command handling code."
-  (make-local-hook 'eshell-named-command-hook)
   (add-hook 'eshell-named-command-hook 'eshell-explicit-command nil t))
 
 (defun eshell-explicit-command (command args)
   "If a command name begins with `*', call it externally always.
 This bypasses all Lisp functions and aliases."
   (when (and (> (length command) 1)
-	     (eq (aref command 0) ?*))
+	     (eq (aref command 0) eshell-explicit-command-char))
     (let ((cmd (eshell-search-path (substring command 1))))
       (if cmd
 	  (or (eshell-external-command cmd args)
 	 (eshell-printn (car paths))
 	 (setq paths (cdr paths)))))))
 
+(put 'eshell/addpath 'eshell-no-numeric-conversions t)
+
 (defun eshell-script-interpreter (file)
   "Extract the script to run from FILE, if it has #!<interp> in it.
 Return nil, or a list of the form:
 	     (file-regular-p file))
 	(with-temp-buffer
 	  (insert-file-contents-literally file nil 0 maxlen)
-	  (if (looking-at "#!\\([^ \t\n]+\\)\\([ \t]+\\(.+\\)\\)?")
+	  (if (looking-at "#![ \t]*\\([^ \r\t\n]+\\)\\([ \t]+\\(.+\\)\\)?")
 	      (if (match-string 3)
 		  (list (match-string 1)
 			(match-string 3)
-;;; esh-io --- I/O management
+;;; esh-io.el --- I/O management
 
-;; Copyright (C) 1999, 2000 Free Software Foundation
+;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
 
 ;; 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-io)
 
 
 (defun eshell-io-initialize ()
   "Initialize the I/O subsystem code."
-  (make-local-hook 'eshell-parse-argument-hook)
   (add-hook 'eshell-parse-argument-hook
 	    'eshell-parse-redirection nil t)
   (make-local-variable 'eshell-current-redirections)
-  (make-local-hook 'eshell-pre-rewrite-command-hook)
   (add-hook 'eshell-pre-rewrite-command-hook
 	    'eshell-strip-redirections nil t)
-  (make-local-hook 'eshell-post-rewrite-command-hook)
   (add-hook 'eshell-post-rewrite-command-hook
 	    'eshell-apply-redirections nil t))
 
 	  (eshell-finish-arg
 	   (prog1
 	       (list 'eshell-set-output-handle
-		     (or (and sh (string-to-int sh)) 1)
+		     (or (and sh (string-to-number sh)) 1)
 		     (list 'quote
 			   (aref [overwrite append insert]
 				 (1- (length oper)))))
   (cond
    ((stringp target)
     (let ((redir (assoc target eshell-virtual-targets)))
-     (if redir
-	 (if (nth 2 redir)
-	     (funcall (nth 1 redir) mode)
-	   (nth 1 redir))
-       (let* ((exists (get-file-buffer target))
-	      (buf (find-file-noselect target t)))
-	 (with-current-buffer buf
-	   (if buffer-read-only
-	       (error "Cannot write to read-only file `%s'" target))
-	   (set (make-local-variable 'eshell-output-file-buffer)
-		(if (eq exists buf) 0 t))
-	   (cond ((eq mode 'overwrite)
-		  (erase-buffer))
-		 ((eq mode 'append)
-		  (goto-char (point-max))))
-	   (point-marker))))))
+      (if redir
+	  (if (nth 2 redir)
+	      (funcall (nth 1 redir) mode)
+	    (nth 1 redir))
+	(let* ((exists (get-file-buffer target))
+	       (buf (find-file-noselect target t)))
+	  (with-current-buffer buf
+	    (if buffer-read-only
+		(error "Cannot write to read-only file `%s'" target))
+	    (set (make-local-variable 'eshell-output-file-buffer)
+		 (if (eq exists buf) 0 t))
+	    (cond ((eq mode 'overwrite)
+		   (erase-buffer))
+		  ((eq mode 'append)
+		   (goto-char (point-max))))
+	    (point-marker))))))
+
    ((or (bufferp target)
 	(and (boundp 'eshell-buffer-shorthand)
 	     (symbol-value 'eshell-buffer-shorthand)
-	     (symbolp target)))
+	     (symbolp target)
+	     (not (memq target '(t nil)))))
     (let ((buf (if (bufferp target)
 		   target
 		 (get-buffer-create
 	      ((eq mode 'append)
 	       (goto-char (point-max))))
 	(point-marker))))
-   ((functionp target)
-    nil)
+
+   ((functionp target) nil)
+
    ((symbolp target)
     (if (eq mode 'overwrite)
 	(set target nil))
     target)
+
    ((or (eshell-processp target)
 	(markerp target))
     target)
+
    (t
-    (error "Illegal redirection target: %s"
+    (error "Invalid redirection target: %s"
 	   (eshell-stringify target)))))
 
 (eval-when-compile
 	(if (and (listp current)
 		 (not (member where current)))
 	    (setq current (append current (list where)))
-	  (setq current where))
+	  (setq current (list where)))
 	(if (not (aref eshell-current-handles index))
 	    (aset eshell-current-handles index (cons nil 1)))
 	(setcar (aref eshell-current-handles index) current)))))
 	  (let ((moving (= (point) target)))
 	    (save-excursion
 	      (goto-char target)
-	      (setq object (eshell-stringify object))
+	      (unless (stringp object)
+		(setq object (eshell-stringify object)))
 	      (insert-and-inherit object)
 	      (set-marker target (point-marker)))
 	    (if moving
 
    ((eshell-processp target)
     (when (eq (process-status target) 'run)
-      (setq object (eshell-stringify object))
+      (unless (stringp object)
+	(setq object (eshell-stringify object)))
       (process-send-string target object)))
 
    ((consp target)
-;;; esh-maint --- init code for building eshell
+;;; esh-maint.el --- init code for building eshell -*- no-byte-compile: t -*-
 
-;; Copyright (C) 1999, 2000 Free Software Foundation
+;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
 
 ;; 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.
 
 ;;; Commentary:
 
 	("(eshell-deftest\\>"        . font-lock-keyword-face)
 	("(eshell-condition-case\\>" . font-lock-keyword-face))))
 
-(add-to-list 'load-path ".")
-
 (if (file-directory-p "../pcomplete")
     (add-to-list 'load-path "../pcomplete"))
 
   (require 'cl)
   (setq cl-optimize-speed 9))
 
-(defun eshell-generate-autoloads ()
-  (interactive)
-  (require 'autoload)
-  (setq generated-autoload-file
-	(expand-file-name (car command-line-args-left)))
-  (setq command-line-args-left (cdr command-line-args-left))
-  (batch-update-autoloads))
+;; (defun eshell-generate-autoloads ()
+;;   (interactive)
+;;   (require 'autoload)
+;;   (setq generated-autoload-file
+;;	(expand-file-name (car command-line-args-left)))
+;;   (setq command-line-args-left (cdr command-line-args-left))
+;;   (batch-update-autoloads))
 
 (require 'eshell)
 (require 'esh-mode)    ; brings in eshell-util
 (require 'esh-opt)
 (require 'esh-test)
 
-(defun eshell-generate-main-menu ()
-  "Create the main menu for the eshell documentation."
-  (insert "@menu
- * The Emacs shell::                 eshell.
+;; (defun eshell-generate-main-menu ()
+;;   "Create the main menu for the eshell documentation."
+;;   (insert "@menu
+;; * The Emacs shell::                 eshell.
 
- Core Functionality\n")
-  (eshell-for module
-      (sort (eshell-subgroups 'eshell)
-	    (function
-	     (lambda (a b)
-	       (string-lessp (symbol-name a)
-			     (symbol-name b)))))
-    (insert (format "* %-34s"
-		    (concat (get module 'custom-tag) "::"))
-	    (symbol-name module) ".\n"))
-  (insert "\nOptional Functionality\n")
-  (eshell-for module
-      (sort (eshell-subgroups 'eshell-module)
-	    (function
-	     (lambda (a b)
-	       (string-lessp (symbol-name a)
-			     (symbol-name b)))))
-    (insert (format "* %-34s"
-		    (concat (get module 'custom-tag) "::"))
-	    (symbol-name module) ".\n"))
-  (insert "@end menu\n"))
+;; Core Functionality\n")
+;;   (eshell-for module
+;;       (sort (eshell-subgroups 'eshell)
+;;	    (function
+;;	     (lambda (a b)
+;;	       (string-lessp (symbol-name a)
+;;			     (symbol-name b)))))
+;;     (insert (format "* %-34s"
+;;		    (concat (get module 'custom-tag) "::"))
+;;	    (symbol-name module) ".\n"))
+;;   (insert "\nOptional Functionality\n")
+;;   (eshell-for module
+;;       (sort (eshell-subgroups 'eshell-module)
+;;	    (function
+;;	     (lambda (a b)
+;;	       (string-lessp (symbol-name a)
+;;			     (symbol-name b)))))
+;;     (insert (format "* %-34s"
+;;		    (concat (get module 'custom-tag) "::"))
+;;	    (symbol-name module) ".\n"))
+;;   (insert "@end menu\n"))
 
-(defun eshell-make-texi ()
-  "Make the eshell.texi file."
-  (interactive)
-  (require 'eshell-auto)
-  (require 'texidoc)
-  (require 'pcomplete)
-  (apply 'texidoc-files 'eshell-generate-main-menu "eshell.doci"
-	 (append
-	  (list "eshell.el")
-	  (sort (mapcar
-		 (function
-		  (lambda (sym)
-		    (let ((name (symbol-name sym)))
-		      (if (string-match "\\`eshell-\\(.*\\)" name)
-			  (setq name (concat "esh-" (match-string 1 name))))
-		      (concat name ".el"))))
-		 (eshell-subgroups 'eshell))
-		'string-lessp)
-	  (sort (mapcar
-		 (function
-		  (lambda (sym)
-		    (let ((name (symbol-name sym)))
-		      (if (string-match "\\`eshell-\\(.*\\)" name)
-			  (setq name (concat "em-" (match-string 1 name))))