(eshell-var): Fix typo in docstring.
[bpt/emacs.git] / lisp / eshell / esh-cmd.el
index 0b5cf0c..355369d 100644 (file)
@@ -1,4 +1,4 @@
-;;; esh-cmd --- command invocation
+;;; esh-cmd.el --- command invocation
 
 ;; Copyright (C) 1999, 2000 Free Software Foundation
 
@@ -30,7 +30,7 @@
 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:
@@ -295,28 +295,24 @@ command line.")
   (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)))
 
@@ -613,10 +609,10 @@ must be implemented via rewriting, rather than as a function."
        (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))))
@@ -625,7 +621,9 @@ must be implemented via rewriting, rather than as a function."
   "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)))
 
@@ -711,7 +709,7 @@ For an external command, it means an exit code of 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))
@@ -759,7 +757,7 @@ nil)' if none)."
 
 (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))
@@ -1006,11 +1004,12 @@ at the moment are:
     (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."
@@ -1060,7 +1059,7 @@ at the moment are:
   object)
 
 (defconst function-p-func
-  (if (eshell-under-xemacs-p)
+  (if (fboundp 'compiled-function-p)
       'compiled-function-p
     'byte-code-function-p))
 
@@ -1231,7 +1230,7 @@ be finished later after the completion of an asynchronous subprocess."
   "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)
@@ -1246,9 +1245,8 @@ be finished later after the completion of an asynchronous subprocess."
        (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
@@ -1265,6 +1263,8 @@ be finished later after the completion of an asynchronous subprocess."
                                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."
@@ -1284,7 +1284,7 @@ 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)))
+        (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
@@ -1383,13 +1383,28 @@ messages, and errors."
 
 (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
@@ -1400,4 +1415,5 @@ messages, and errors."
 
 (defalias 'eshell-lisp-command* 'eshell-lisp-command)
 
+;;; arch-tag: 8e4f3867-a0c5-441f-96ba-ddd142d94366
 ;;; esh-cmd.el ends here