Source

eshell / esh-io.el

Diff from to

esh-io.el

-;;; 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)