Convert consecutive FSF copyright years to ranges.
[bpt/emacs.git] / lisp / eshell / esh-proc.el
index a838da3..f697a40 100644 (file)
@@ -1,16 +1,15 @@
 ;;; esh-proc.el --- process management
 
-;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
-;;   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 1999-2011  Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; 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 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
 ;; GNU General Public License for more details.
 
 ;; 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., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
+;;; Code:
+
 (provide 'esh-proc)
 
 (eval-when-compile
@@ -40,27 +39,27 @@ finish."
 ;;; User Variables:
 
 (defcustom eshell-proc-load-hook '(eshell-proc-initialize)
-  "*A hook that gets run when `eshell-proc' is loaded."
+  "A hook that gets run when `eshell-proc' is loaded."
   :type 'hook
   :group 'eshell-proc)
 
 (defcustom eshell-process-wait-seconds 0
-  "*The number of seconds to delay waiting for a synchronous process."
+  "The number of seconds to delay waiting for a synchronous process."
   :type 'integer
   :group 'eshell-proc)
 
 (defcustom eshell-process-wait-milliseconds 50
-  "*The number of milliseconds to delay waiting for a synchronous process."
+  "The number of milliseconds to delay waiting for a synchronous process."
   :type 'integer
   :group 'eshell-proc)
 
 (defcustom eshell-done-messages-in-minibuffer t
-  "*If non-nil, subjob \"Done\" messages will display in minibuffer."
+  "If non-nil, subjob \"Done\" messages will display in minibuffer."
   :type 'boolean
   :group 'eshell-proc)
 
 (defcustom eshell-delete-exited-processes t
-  "*If nil, process entries will stick around until `jobs' is run.
+  "If nil, process entries will stick around until `jobs' is run.
 This variable sets the buffer-local value of `delete-exited-processes'
 in Eshell buffers.
 
@@ -81,12 +80,12 @@ variable's value to take effect."
 
 (defcustom eshell-reset-signals
   "^\\(interrupt\\|killed\\|quit\\|stopped\\)"
-  "*If a termination signal matches this regexp, the terminal will be reset."
+  "If a termination signal matches this regexp, the terminal will be reset."
   :type 'regexp
   :group 'eshell-proc)
 
 (defcustom eshell-exec-hook nil
-  "*Called each time a process is exec'd by `eshell-gather-process-output'.
+  "Called each time a process is exec'd by `eshell-gather-process-output'.
 It is passed one argument, which is the process that was just started.
 It is useful for things that must be done each time a process is
 executed in a eshell mode buffer (e.g., `process-kill-without-query').
@@ -96,7 +95,7 @@ is created."
   :group 'eshell-proc)
 
 (defcustom eshell-kill-hook '(eshell-reset-after-proc)
-  "*Called when a process run by `eshell-gather-process-output' has ended.
+  "Called when a process run by `eshell-gather-process-output' has ended.
 It is passed two arguments: the process that was just ended, and the
 termination status (as a string).  Note that the first argument may be
 nil, in which case the user attempted to send a signal, but there was
@@ -238,10 +237,30 @@ The prompt will be set to PROMPT."
   "A marker that tracks the beginning of output of the last subprocess.
 Used only on systems which do not support async subprocesses.")
 
+(defvar eshell-needs-pipe '("bc")
+  "List of commands which need `process-connection-type' to be nil.
+Currently only affects commands in pipelines, and not those at
+the front.  If an element contains a directory part it must match
+the full name of a command, otherwise just the nondirectory part must match.")
+
+(defun eshell-needs-pipe-p (command)
+  "Return non-nil if COMMAND needs `process-connection-type' to be nil.
+See `eshell-needs-pipe'."
+  (and eshell-in-pipeline-p
+       (not (eq eshell-in-pipeline-p 'first))
+       ;; FIXME should this return non-nil for anything that is
+       ;; neither 'first nor 'last?  See bug#1388 discussion.
+       (catch 'found
+        (dolist (exe eshell-needs-pipe)
+          (if (string-equal exe (if (string-match "/" exe)
+                                    command
+                                  (file-name-nondirectory command)))
+              (throw 'found t))))))
+
 (defun eshell-gather-process-output (command args)
   "Gather the output from COMMAND + ARGS."
   (unless (and (file-executable-p command)
-              (file-regular-p command))
+              (file-regular-p (file-truename command)))
     (error "%s: not an executable file" command))
   (let* ((delete-exited-processes
          (if eshell-current-subjob-p
@@ -250,13 +269,16 @@ Used only on systems which do not support async subprocesses.")
         (process-environment (eshell-environment-variables))
         proc decoding encoding changed)
     (cond
-     ((fboundp 'start-process)
+     ((fboundp 'start-file-process)
       (setq proc
-           (apply 'start-process
-                  (file-name-nondirectory command) nil
-                  ;; `start-process' can't deal with relative
-                  ;; filenames
-                  (append (list (expand-file-name command)) args)))
+           (let ((process-connection-type
+                  (unless (eshell-needs-pipe-p command)
+                    process-connection-type))
+                 (command (or (file-remote-p command 'localname) command)))
+             (apply 'start-file-process
+                    (file-name-nondirectory command) nil
+                    ;; `start-process' can't deal with relative filenames.
+                    (append (list (expand-file-name command)) args))))
       (eshell-record-process-object proc)
       (set-process-buffer proc (current-buffer))
       (if (eshell-interactive-output-p)
@@ -395,12 +417,12 @@ If QUERY is non-nil, query the user with QUERY before calling FUNC."
     result))
 
 (defcustom eshell-kill-process-wait-time 5
-  "*Seconds to wait between sending termination signals to a subprocess."
+  "Seconds to wait between sending termination signals to a subprocess."
   :type 'integer
   :group 'eshell-proc)
 
 (defcustom eshell-kill-process-signals '(SIGINT SIGQUIT SIGKILL)
-  "*Signals used to kill processes when an Eshell buffer exits.
+  "Signals used to kill processes when an Eshell buffer exits.
 Eshell calls each of these signals in order when an Eshell buffer is
 killed; if the process is still alive afterwards, Eshell waits a
 number of seconds defined by `eshell-kill-process-wait-time', and
@@ -409,7 +431,7 @@ tries the next signal in the list."
   :group 'eshell-proc)
 
 (defcustom eshell-kill-processes-on-exit nil
-  "*If non-nil, kill active processes when exiting an Eshell buffer.
+  "If non-nil, kill active processes when exiting an Eshell buffer.
 Emacs will only kill processes owned by that Eshell buffer.
 
 If nil, ownership of background and foreground processes reverts to
@@ -504,7 +526,4 @@ See the variable `eshell-kill-processes-on-exit'."
   (eshell-send-input nil nil t)
   (eshell-process-interact 'process-send-eof))
 
-;;; Code:
-
-;;; arch-tag: ac477a3e-ee4d-4b44-8ec6-212010e607bb
 ;;; esh-proc.el ends here