comparison lisp/eshell/esh-io.el @ 55613:8e3531a00902

2004-05-15 John Wiegley <johnw@newartisans.com> * eshell/esh-io.el (eshell-get-target): whitespace changes. (eshell-output-object-to-target): Improve output speed 20% by not calling `eshell-stringify' if something is already known to be a string.
author John Wiegley <johnw@newartisans.com>
date Sat, 15 May 2004 22:45:35 +0000
parents 695cf19ef79e
children a72129314db4 4c90ffeb71c5
comparison
equal deleted inserted replaced
55612:eee95823e97c 55613:8e3531a00902
331 it defaults to `insert'." 331 it defaults to `insert'."
332 (setq mode (or mode 'insert)) 332 (setq mode (or mode 'insert))
333 (cond 333 (cond
334 ((stringp target) 334 ((stringp target)
335 (let ((redir (assoc target eshell-virtual-targets))) 335 (let ((redir (assoc target eshell-virtual-targets)))
336 (if redir 336 (if redir
337 (if (nth 2 redir) 337 (if (nth 2 redir)
338 (funcall (nth 1 redir) mode) 338 (funcall (nth 1 redir) mode)
339 (nth 1 redir)) 339 (nth 1 redir))
340 (let* ((exists (get-file-buffer target)) 340 (let* ((exists (get-file-buffer target))
341 (buf (find-file-noselect target t))) 341 (buf (find-file-noselect target t)))
342 (with-current-buffer buf 342 (with-current-buffer buf
343 (if buffer-read-only 343 (if buffer-read-only
344 (error "Cannot write to read-only file `%s'" target)) 344 (error "Cannot write to read-only file `%s'" target))
345 (set (make-local-variable 'eshell-output-file-buffer) 345 (set (make-local-variable 'eshell-output-file-buffer)
346 (if (eq exists buf) 0 t)) 346 (if (eq exists buf) 0 t))
347 (cond ((eq mode 'overwrite) 347 (cond ((eq mode 'overwrite)
348 (erase-buffer)) 348 (erase-buffer))
349 ((eq mode 'append) 349 ((eq mode 'append)
350 (goto-char (point-max)))) 350 (goto-char (point-max))))
351 (point-marker)))))) 351 (point-marker))))))
352
352 ((or (bufferp target) 353 ((or (bufferp target)
353 (and (boundp 'eshell-buffer-shorthand) 354 (and (boundp 'eshell-buffer-shorthand)
354 (symbol-value 'eshell-buffer-shorthand) 355 (symbol-value 'eshell-buffer-shorthand)
355 (symbolp target))) 356 (symbolp target)))
356 (let ((buf (if (bufferp target) 357 (let ((buf (if (bufferp target)
361 (cond ((eq mode 'overwrite) 362 (cond ((eq mode 'overwrite)
362 (erase-buffer)) 363 (erase-buffer))
363 ((eq mode 'append) 364 ((eq mode 'append)
364 (goto-char (point-max)))) 365 (goto-char (point-max))))
365 (point-marker)))) 366 (point-marker))))
366 ((functionp target) 367
367 nil) 368 ((functionp target) nil)
369
368 ((symbolp target) 370 ((symbolp target)
369 (if (eq mode 'overwrite) 371 (if (eq mode 'overwrite)
370 (set target nil)) 372 (set target nil))
371 target) 373 target)
374
372 ((or (eshell-processp target) 375 ((or (eshell-processp target)
373 (markerp target)) 376 (markerp target))
374 target) 377 target)
378
375 (t 379 (t
376 (error "Illegal redirection target: %s" 380 (error "Illegal redirection target: %s"
377 (eshell-stringify target))))) 381 (eshell-stringify target)))))
378 382
379 (eval-when-compile 383 (eval-when-compile
479 (if (buffer-live-p (marker-buffer target)) 483 (if (buffer-live-p (marker-buffer target))
480 (with-current-buffer (marker-buffer target) 484 (with-current-buffer (marker-buffer target)
481 (let ((moving (= (point) target))) 485 (let ((moving (= (point) target)))
482 (save-excursion 486 (save-excursion
483 (goto-char target) 487 (goto-char target)
484 (setq object (eshell-stringify object)) 488 (unless (stringp object)
489 (setq object (eshell-stringify object)))
485 (insert-and-inherit object) 490 (insert-and-inherit object)
486 (set-marker target (point-marker))) 491 (set-marker target (point-marker)))
487 (if moving 492 (if moving
488 (goto-char target)))))) 493 (goto-char target))))))
489 494
490 ((eshell-processp target) 495 ((eshell-processp target)
491 (when (eq (process-status target) 'run) 496 (when (eq (process-status target) 'run)
492 (setq object (eshell-stringify object)) 497 (unless (stringp object)
498 (setq object (eshell-stringify object)))
493 (process-send-string target object))) 499 (process-send-string target object)))
494 500
495 ((consp target) 501 ((consp target)
496 (apply (car target) object (cdr target)))) 502 (apply (car target) object (cdr target))))
497 object) 503 object)