]> code.delx.au - gnu-emacs/blobdiff - lisp/eshell/esh-cmd.el
* completion.el (add-completion-to-head, add-completion): Doc fixes.
[gnu-emacs] / lisp / eshell / esh-cmd.el
index c28ba970c415e6e3a4c2d9cf933fd04d3600c8d8..2e47fd718c24d3c1e62e99894a24d5f6ae553805 100644 (file)
@@ -1,7 +1,7 @@
 ;;; esh-cmd.el --- command invocation
 
-;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
-;;   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
+;;   200 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
 (require 'esh-ext)
 
 (eval-when-compile
+  (require 'cl)
   (require 'pcomplete))
 
 
@@ -397,8 +398,7 @@ hooks should be run before and after the command."
   "Output a debugging message to '*eshell last cmd*'."
   (let ((buf (get-buffer-create "*eshell last cmd*"))
        (text (eshell-stringify eshell-current-command)))
-    (save-excursion
-      (set-buffer buf)
+    (with-current-buffer buf
       (if (not tag)
          (erase-buffer)
        (insert "\n\C-l\n" tag "\n\n" text
@@ -477,9 +477,8 @@ hooks should be run before and after the command."
   "Execute named command"
   (eshell-command-result-p "+ 1 2" "3\n"))
 
-(eval-when-compile
-  (defvar eshell-command-body)
-  (defvar eshell-test-body))
+(defvar eshell-command-body)
+(defvar eshell-test-body)
 
 (defsubst eshell-invokify-arg (arg &optional share-output silent)
   "Change ARG so it can be invoked from a structured command.
@@ -840,7 +839,11 @@ this grossness will be made to disappear by using `call/cc'..."
              (setcar head
                      (intern-soft
                       (concat (symbol-name (car head)) "*"))))))
-       ,(car pipeline)))))
+       ;; Indicate to the command if it is the last in the pipeline.
+       ;; Currently only used by eshell-ls-files.
+       ;; Perhaps nil, rather than 'last, would be OK?
+       (let ((eshell-in-pipeline-p ,(if (cdr pipeline) t (quote 'last))))
+         ,(car pipeline))))))
 
 (defmacro eshell-do-pipelines-synchronously (pipeline)
   "Execute the commands in PIPELINE in sequence synchronously.
@@ -998,11 +1001,9 @@ at the moment are:
                          (list 'eshell-do-eval
                                (list 'quote command)))))
     (and eshell-debug-command
-        (save-excursion
-          (let ((buf (get-buffer-create "*eshell last cmd*")))
-            (set-buffer buf)
-            (erase-buffer)
-            (insert "command: \"" input "\"\n"))))
+         (with-current-buffer (get-buffer-create "*eshell last cmd*")
+           (erase-buffer)
+           (insert "command: \"" input "\"\n")))
     (setq eshell-current-command command)
     (let ((delim (catch 'eshell-incomplete
                   (eshell-resume-eval))))
@@ -1042,7 +1043,9 @@ at the moment are:
 
 (defmacro eshell-manipulate (tag &rest commands)
   "Manipulate a COMMAND form, with TAG as a debug identifier."
-  (if (not eshell-debug-command)
+  ;; Check `bound'ness since at compile time the code until here has not
+  ;; executed yet.
+  (if (not (and (boundp 'eshell-debug-command) eshell-debug-command))
       `(progn ,@commands)
     `(progn
        (eshell-debug-command ,(eval tag) form)
@@ -1254,9 +1257,12 @@ be finished later after the completion of an asynchronous subprocess."
                              (prog1
                                  (describe-function sym)
                                (message nil))))))
-               (setq desc (substring desc 0
-                                     (1- (or (string-match "\n" desc)
-                                             (length desc)))))
+               (setq desc (if desc (substring desc 0
+                                              (1- (or (string-match "\n" desc)
+                                                      (length desc))))
+                            ;; This should not happen.
+                            (format "%s is defined, \
+but no documentation was found" name)))
                (if (buffer-live-p (get-buffer "*Help*"))
                    (kill-buffer "*Help*"))
                (setq program (or desc name))))))