Mercurial > emacs
annotate lisp/eshell/esh-io.el @ 58815:7b13efc010a5
(Using Calc): Remove paragraph on installation.
author | Jay Belanger <jay.p.belanger@gmail.com> |
---|---|
date | Tue, 07 Dec 2004 05:05:16 +0000 |
parents | 8e3531a00902 |
children | a72129314db4 4c90ffeb71c5 |
rev | line source |
---|---|
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
32526
diff
changeset
|
1 ;;; esh-io.el --- I/O management |
29876 | 2 |
29934
34b1ab9d583d
Change spelling of the Free Software Foundation.
Gerd Moellmann <gerd@gnu.org>
parents:
29876
diff
changeset
|
3 ;; Copyright (C) 1999, 2000 Free Software Foundation |
29876 | 4 |
32526 | 5 ;; Author: John Wiegley <johnw@gnu.org> |
6 | |
29876 | 7 ;; This file is part of GNU Emacs. |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation; either version 2, or (at your option) | |
12 ;; any later version. | |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
22 ;; Boston, MA 02111-1307, USA. | |
23 | |
24 (provide 'esh-io) | |
25 | |
26 (eval-when-compile (require 'esh-maint)) | |
27 | |
28 (defgroup eshell-io nil | |
29 "Eshell's I/O management code provides a scheme for treating many | |
30 different kinds of objects -- symbols, files, buffers, etc. -- as | |
31 though they were files." | |
32 :tag "I/O management" | |
33 :group 'eshell) | |
34 | |
35 ;;; Commentary: | |
36 | |
37 ;; At the moment, only output redirection is supported in Eshell. To | |
38 ;; use input redirection, the following syntax will work, assuming | |
39 ;; that the command after the pipe is always an external command: | |
40 ;; | |
41 ;; cat <file> | <command> | |
42 ;; | |
43 ;; Otherwise, output redirection and piping are provided in a manner | |
44 ;; consistent with most shells. Therefore, only unique features are | |
45 ;; mentioned here. | |
46 ;; | |
47 ;;;_* Insertion | |
48 ;; | |
49 ;; To insert at the location of point in a buffer, use '>>>': | |
50 ;; | |
51 ;; echo alpha >>> #<buffer *scratch*>; | |
52 ;; | |
53 ;;;_* Pseudo-devices | |
54 ;; | |
55 ;; A few pseudo-devices are provided, since Emacs cannot write | |
56 ;; directly to a UNIX device file: | |
57 ;; | |
58 ;; echo alpha > /dev/null ; the bit bucket | |
59 ;; echo alpha > /dev/kill ; set the kill ring | |
60 ;; echo alpha >> /dev/clip ; append to the clipboard | |
61 ;; | |
62 ;;;_* Multiple output targets | |
63 ;; | |
64 ;; Eshell can write to multiple output targets, including pipes. | |
65 ;; Example: | |
66 ;; | |
67 ;; (+ 1 2) > a > b > c ; prints number to all three files | |
68 ;; (+ 1 2) > a | wc ; prints to 'a', and pipes to 'wc' | |
69 | |
70 ;;; User Variables: | |
71 | |
72 (defcustom eshell-io-load-hook '(eshell-io-initialize) | |
73 "*A hook that gets run when `eshell-io' is loaded." | |
74 :type 'hook | |
75 :group 'eshell-io) | |
76 | |
77 (defcustom eshell-number-of-handles 3 | |
78 "*The number of file handles that eshell supports. | |
79 Currently this is standard input, output and error. But even all of | |
80 these Emacs does not currently support with asynchronous processes | |
81 \(which is what eshell uses so that you can continue doing work in | |
82 other buffers) ." | |
83 :type 'integer | |
84 :group 'eshell-io) | |
85 | |
86 (defcustom eshell-output-handle 1 | |
87 "*The index of the standard output handle." | |
88 :type 'integer | |
89 :group 'eshell-io) | |
90 | |
91 (defcustom eshell-error-handle 2 | |
92 "*The index of the standard error handle." | |
93 :type 'integer | |
94 :group 'eshell-io) | |
95 | |
96 (defcustom eshell-buffer-shorthand nil | |
97 "*If non-nil, a symbol name can be used for a buffer in redirection. | |
98 If nil, redirecting to a buffer requires buffer name syntax. If this | |
99 variable is set, redirection directly to Lisp symbols will be | |
100 impossible. | |
101 | |
102 Example: | |
103 | |
104 echo hello > '*scratch* ; works if `eshell-buffer-shorthand' is t | |
105 echo hello > #<buffer *scratch*> ; always works" | |
106 :type 'boolean | |
107 :group 'eshell-io) | |
108 | |
109 (defcustom eshell-print-queue-size 5 | |
110 "*The size of the print queue, for doing buffered printing. | |
111 This is basically a speed enhancement, to avoid blocking the Lisp code | |
112 from executing while Emacs is redisplaying." | |
113 :type 'integer | |
114 :group 'eshell-io) | |
115 | |
116 (defcustom eshell-virtual-targets | |
117 '(("/dev/eshell" eshell-interactive-print nil) | |
118 ("/dev/kill" (lambda (mode) | |
119 (if (eq mode 'overwrite) | |
120 (kill-new "")) | |
121 'eshell-kill-append) t) | |
122 ("/dev/clip" (lambda (mode) | |
123 (if (eq mode 'overwrite) | |
124 (let ((x-select-enable-clipboard t)) | |
125 (kill-new ""))) | |
126 'eshell-clipboard-append) t)) | |
127 "*Map virtual devices name to Emacs Lisp functions. | |
128 If the user specifies any of the filenames above as a redirection | |
129 target, the function in the second element will be called. | |
130 | |
131 If the third element is non-nil, the redirection mode is passed as an | |
132 argument (which is the symbol `overwrite', `append' or `insert'), and | |
133 the function is expected to return another function -- which is the | |
134 output function. Otherwise, the second element itself is the output | |
135 function. | |
136 | |
31241 | 137 The output function is then called repeatedly with single strings, |
138 which represents successive pieces of the output of the command, until nil | |
29876 | 139 is passed, meaning EOF. |
140 | |
141 NOTE: /dev/null is handled specially as a virtual target, and should | |
142 not be added to this variable." | |
143 :type '(repeat | |
144 (list (string :tag "Target") | |
145 function | |
146 (choice (const :tag "Func returns output-func" t) | |
147 (const :tag "Func is output-func" nil)))) | |
148 :group 'eshell-io) | |
149 | |
150 (put 'eshell-virtual-targets 'risky-local-variable t) | |
151 | |
152 ;;; Internal Variables: | |
153 | |
154 (defvar eshell-current-handles nil) | |
155 | |
156 (defvar eshell-last-command-status 0 | |
157 "The exit code from the last command. 0 if successful.") | |
158 | |
159 (defvar eshell-last-command-result nil | |
160 "The result of the last command. Not related to success.") | |
161 | |
162 (defvar eshell-output-file-buffer nil | |
163 "If non-nil, the current buffer is a file output buffer.") | |
164 | |
165 (defvar eshell-print-count) | |
166 (defvar eshell-current-redirections) | |
167 | |
168 ;;; Functions: | |
169 | |
170 (defun eshell-io-initialize () | |
171 "Initialize the I/O subsystem code." | |
172 (add-hook 'eshell-parse-argument-hook | |
173 'eshell-parse-redirection nil t) | |
174 (make-local-variable 'eshell-current-redirections) | |
175 (add-hook 'eshell-pre-rewrite-command-hook | |
176 'eshell-strip-redirections nil t) | |
177 (add-hook 'eshell-post-rewrite-command-hook | |
178 'eshell-apply-redirections nil t)) | |
179 | |
180 (defun eshell-parse-redirection () | |
181 "Parse an output redirection, such as '2>'." | |
182 (if (and (not eshell-current-quoted) | |
183 (looking-at "\\([0-9]\\)?\\(<\\|>+\\)&?\\([0-9]\\)?\\s-*")) | |
184 (if eshell-current-argument | |
185 (eshell-finish-arg) | |
186 (let ((sh (match-string 1)) | |
187 (oper (match-string 2)) | |
188 ; (th (match-string 3)) | |
189 ) | |
190 (if (string= oper "<") | |
191 (error "Eshell does not support input redirection")) | |
192 (eshell-finish-arg | |
193 (prog1 | |
194 (list 'eshell-set-output-handle | |
195 (or (and sh (string-to-int sh)) 1) | |
196 (list 'quote | |
197 (aref [overwrite append insert] | |
198 (1- (length oper))))) | |
199 (goto-char (match-end 0)))))))) | |
200 | |
201 (defun eshell-strip-redirections (terms) | |
202 "Rewrite any output redirections in TERMS." | |
203 (setq eshell-current-redirections (list t)) | |
204 (let ((tl terms) | |
205 (tt (cdr terms))) | |
206 (while tt | |
207 (if (not (and (consp (car tt)) | |
208 (eq (caar tt) 'eshell-set-output-handle))) | |
209 (setq tt (cdr tt) | |
210 tl (cdr tl)) | |
211 (unless (cdr tt) | |
212 (error "Missing redirection target")) | |
213 (nconc eshell-current-redirections | |
214 (list (list 'ignore | |
215 (append (car tt) (list (cadr tt)))))) | |
216 (setcdr tl (cddr tt)) | |
217 (setq tt (cddr tt)))) | |
218 (setq eshell-current-redirections | |
219 (cdr eshell-current-redirections)))) | |
220 | |
221 (defun eshell-apply-redirections (cmdsym) | |
222 "Apply any redirection which were specified for COMMAND." | |
223 (if eshell-current-redirections | |
224 (set cmdsym | |
225 (append (list 'progn) | |
226 eshell-current-redirections | |
227 (list (symbol-value cmdsym)))))) | |
228 | |
229 (defun eshell-create-handles | |
230 (standard-output output-mode &optional standard-error error-mode) | |
231 "Create a new set of file handles for a command. | |
232 The default location for standard output and standard error will go to | |
31241 | 233 STANDARD-OUTPUT and STANDARD-ERROR, respectively. |
234 OUTPUT-MODE and ERROR-MODE are either `overwrite', `append' or `insert'; | |
235 a nil value of mode defaults to `insert'." | |
29876 | 236 (let ((handles (make-vector eshell-number-of-handles nil)) |
237 (output-target (eshell-get-target standard-output output-mode)) | |
238 (error-target (eshell-get-target standard-error error-mode))) | |
239 (aset handles eshell-output-handle (cons output-target 1)) | |
240 (if standard-error | |
241 (aset handles eshell-error-handle (cons error-target 1)) | |
242 (aset handles eshell-error-handle (cons output-target 1))) | |
243 handles)) | |
244 | |
245 (defun eshell-protect-handles (handles) | |
246 "Protect the handles in HANDLES from a being closed." | |
247 (let ((idx 0)) | |
248 (while (< idx eshell-number-of-handles) | |
249 (if (aref handles idx) | |
250 (setcdr (aref handles idx) | |
251 (1+ (cdr (aref handles idx))))) | |
252 (setq idx (1+ idx)))) | |
253 handles) | |
254 | |
255 (defun eshell-close-target (target status) | |
256 "Close an output TARGET, passing STATUS as the result. | |
257 STATUS should be non-nil on successful termination of the output." | |
258 (cond | |
259 ((symbolp target) nil) | |
260 | |
261 ;; If we were redirecting to a file, save the file and close the | |
262 ;; buffer. | |
263 ((markerp target) | |
264 (let ((buf (marker-buffer target))) | |
265 (when buf ; somebody's already killed it! | |
266 (save-current-buffer | |
267 (set-buffer buf) | |
268 (when eshell-output-file-buffer | |
269 (save-buffer) | |
270 (when (eq eshell-output-file-buffer t) | |
271 (or status (set-buffer-modified-p nil)) | |
272 (kill-buffer buf))))))) | |
273 | |
274 ;; If we're redirecting to a process (via a pipe, or process | |
275 ;; redirection), send it EOF so that it knows we're finished. | |
31241 | 276 ((eshell-processp target) |
29876 | 277 (if (eq (process-status target) 'run) |
278 (process-send-eof target))) | |
279 | |
280 ;; A plain function redirection needs no additional arguments | |
281 ;; passed. | |
282 ((functionp target) | |
283 (funcall target status)) | |
284 | |
285 ;; But a more complicated function redirection (which can only | |
286 ;; happen with aliases at the moment) has arguments that need to be | |
287 ;; passed along with it. | |
288 ((consp target) | |
289 (apply (car target) status (cdr target))))) | |
290 | |
291 (defun eshell-close-handles (exit-code &optional result handles) | |
292 "Close all of the current handles, taking refcounts into account. | |
293 EXIT-CODE is the process exit code; mainly, it is zero, if the command | |
294 completed successfully. RESULT is the quoted value of the last | |
295 command. If nil, then the meta variables for keeping track of the | |
296 last execution result should not be changed." | |
297 (let ((idx 0)) | |
298 (assert (or (not result) (eq (car result) 'quote))) | |
299 (setq eshell-last-command-status exit-code | |
300 eshell-last-command-result (cadr result)) | |
301 (while (< idx eshell-number-of-handles) | |
302 (let ((handles (or handles eshell-current-handles))) | |
303 (when (aref handles idx) | |
304 (setcdr (aref handles idx) | |
305 (1- (cdr (aref handles idx)))) | |
306 (when (= (cdr (aref handles idx)) 0) | |
307 (let ((target (car (aref handles idx)))) | |
308 (if (not (listp target)) | |
309 (eshell-close-target target (= exit-code 0)) | |
310 (while target | |
311 (eshell-close-target (car target) (= exit-code 0)) | |
312 (setq target (cdr target))))) | |
313 (setcar (aref handles idx) nil)))) | |
314 (setq idx (1+ idx))) | |
315 nil)) | |
316 | |
317 (defun eshell-kill-append (string) | |
318 "Call `kill-append' with STRING, if it is indeed a string." | |
319 (if (stringp string) | |
320 (kill-append string nil))) | |
321 | |
322 (defun eshell-clipboard-append (string) | |
323 "Call `kill-append' with STRING, if it is indeed a string." | |
324 (if (stringp string) | |
325 (let ((x-select-enable-clipboard t)) | |
326 (kill-append string nil)))) | |
327 | |
328 (defun eshell-get-target (target &optional mode) | |
329 "Convert TARGET, which is a raw argument, into a valid output target. | |
31241 | 330 MODE is either `overwrite', `append' or `insert'; if it is omitted or nil, |
331 it defaults to `insert'." | |
29876 | 332 (setq mode (or mode 'insert)) |
333 (cond | |
334 ((stringp target) | |
335 (let ((redir (assoc target eshell-virtual-targets))) | |
55613
8e3531a00902
2004-05-15 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
336 (if redir |
8e3531a00902
2004-05-15 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
337 (if (nth 2 redir) |
8e3531a00902
2004-05-15 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
338 (funcall (nth 1 redir) mode) |
8e3531a00902
2004-05-15 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
339 (nth 1 redir)) |
8e3531a00902
2004-05-15 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
340 (let* ((exists (get-file-buffer target)) |
8e3531a00902
2004-05-15 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
341 (buf (find-file-noselect target t))) |
8e3531a00902
2004-05-15 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
342 (with-current-buffer buf |
8e3531a00902
2004-05-15 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
343 (if buffer-read-only |
8e3531a00902
2004-05-15 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
344 (error "Cannot write to read-only file `%s'" target)) |
8e3531a00902
2004-05-15 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
345 (set (make-local-variable 'eshell-output-file-buffer) |
8e3531a00902
2004-05-15 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
346 (if (eq exists buf) 0 t)) |
8e3531a00902
2004-05-15 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
347 (cond ((eq mode 'overwrite) |
8e3531a00902
2004-05-15 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
348 (erase-buffer)) |
8e3531a00902
2004-05-15 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
349 ((eq mode 'append) |
8e3531a00902
2004-05-15 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
350 (goto-char (point-max)))) |
8e3531a00902
2004-05-15 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
351 (point-marker)))))) |
8e3531a00902
2004-05-15 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
352 |
29876 | 353 ((or (bufferp target) |
354 (and (boundp 'eshell-buffer-shorthand) | |
355 (symbol-value 'eshell-buffer-shorthand) | |
356 (symbolp target))) | |
357 (let ((buf (if (bufferp target) | |
358 target | |
359 (get-buffer-create | |
360 (symbol-name target))))) | |
361 (with-current-buffer buf | |
362 (cond ((eq mode 'overwrite) | |
363 (erase-buffer)) | |
364 ((eq mode 'append) | |
365 (goto-char (point-max)))) | |
366 (point-marker)))) | |
55613
8e3531a00902
2004-05-15 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
367 |
8e3531a00902
2004-05-15 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
368 ((functionp target) nil) |
8e3531a00902
2004-05-15 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
369 |
29876 | 370 ((symbolp target) |
371 (if (eq mode 'overwrite) | |
372 (set target nil)) | |
373 target) | |
55613
8e3531a00902
2004-05-15 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
374 |
31241 | 375 ((or (eshell-processp target) |
29876 | 376 (markerp target)) |
377 target) | |
55613
8e3531a00902
2004-05-15 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
378 |
29876 | 379 (t |
380 (error "Illegal redirection target: %s" | |
381 (eshell-stringify target))))) | |
382 | |
383 (eval-when-compile | |
384 (defvar grep-null-device)) | |
385 | |
386 (defun eshell-set-output-handle (index mode &optional target) | |
387 "Set handle INDEX, using MODE, to point to TARGET." | |
388 (when target | |
389 (if (and (stringp target) | |
390 (or (cond | |
391 ((boundp 'null-device) | |
392 (string= target null-device)) | |
393 ((boundp 'grep-null-device) | |
394 (string= target grep-null-device)) | |
395 (t nil)) | |
396 (string= target "/dev/null"))) | |
397 (aset eshell-current-handles index nil) | |
398 (let ((where (eshell-get-target target mode)) | |
399 (current (car (aref eshell-current-handles index)))) | |
400 (if (and (listp current) | |
401 (not (member where current))) | |
402 (setq current (append current (list where))) | |
47971
526a8d279adb
Bob Halley <halley@play-bow.org>: (eshell-set-output-handle): Fix so
John Wiegley <johnw@newartisans.com>
parents:
43337
diff
changeset
|
403 (setq current (list where))) |
29876 | 404 (if (not (aref eshell-current-handles index)) |
405 (aset eshell-current-handles index (cons nil 1))) | |
406 (setcar (aref eshell-current-handles index) current))))) | |
407 | |
408 (defun eshell-interactive-output-p () | |
409 "Return non-nil if current handles are bound for interactive display." | |
410 (and (eq (car (aref eshell-current-handles | |
411 eshell-output-handle)) t) | |
412 (eq (car (aref eshell-current-handles | |
413 eshell-error-handle)) t))) | |
414 | |
415 (defvar eshell-print-queue nil) | |
416 (defvar eshell-print-queue-count -1) | |
417 | |
418 (defun eshell-flush (&optional reset-p) | |
419 "Flush out any lines that have been queued for printing. | |
420 Must be called before printing begins with -1 as its argument, and | |
421 after all printing is over with no argument." | |
422 (ignore | |
423 (if reset-p | |
424 (setq eshell-print-queue nil | |
425 eshell-print-queue-count reset-p) | |
426 (if eshell-print-queue | |
427 (eshell-print eshell-print-queue)) | |
428 (eshell-flush 0)))) | |
429 | |
430 (defun eshell-init-print-buffer () | |
431 "Initialize the buffered printing queue." | |
432 (eshell-flush -1)) | |
433 | |
434 (defun eshell-buffered-print (&rest strings) | |
435 "A buffered print -- *for strings only*." | |
436 (if (< eshell-print-queue-count 0) | |
437 (progn | |
438 (eshell-print (apply 'concat strings)) | |
439 (setq eshell-print-queue-count 0)) | |
440 (if (= eshell-print-queue-count eshell-print-queue-size) | |
441 (eshell-flush)) | |
442 (setq eshell-print-queue | |
443 (concat eshell-print-queue (apply 'concat strings)) | |
444 eshell-print-queue-count (1+ eshell-print-queue-count)))) | |
445 | |
446 (defsubst eshell-print (object) | |
31241 | 447 "Output OBJECT to the standard output handle." |
29876 | 448 (eshell-output-object object eshell-output-handle)) |
449 | |
450 (defsubst eshell-error (object) | |
31241 | 451 "Output OBJECT to the standard error handle." |
29876 | 452 (eshell-output-object object eshell-error-handle)) |
453 | |
454 (defsubst eshell-errorn (object) | |
31241 | 455 "Output OBJECT followed by a newline to the standard error handle." |
29876 | 456 (eshell-error object) |
457 (eshell-error "\n")) | |
458 | |
459 (defsubst eshell-printn (object) | |
31241 | 460 "Output OBJECT followed by a newline to the standard output handle." |
29876 | 461 (eshell-print object) |
462 (eshell-print "\n")) | |
463 | |
464 (defun eshell-output-object-to-target (object target) | |
465 "Insert OBJECT into TARGET. | |
466 Returns what was actually sent, or nil if nothing was sent." | |
467 (cond | |
468 ((functionp target) | |
469 (funcall target object)) | |
470 | |
471 ((symbolp target) | |
472 (if (eq target t) ; means "print to display" | |
473 (eshell-output-filter nil (eshell-stringify object)) | |
474 (if (not (symbol-value target)) | |
475 (set target object) | |
476 (setq object (eshell-stringify object)) | |
477 (if (not (stringp (symbol-value target))) | |
478 (set target (eshell-stringify | |
479 (symbol-value target)))) | |
480 (set target (concat (symbol-value target) object))))) | |
481 | |
482 ((markerp target) | |
483 (if (buffer-live-p (marker-buffer target)) | |
484 (with-current-buffer (marker-buffer target) | |
485 (let ((moving (= (point) target))) | |
486 (save-excursion | |
487 (goto-char target) | |
55613
8e3531a00902
2004-05-15 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
488 (unless (stringp object) |
8e3531a00902
2004-05-15 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
489 (setq object (eshell-stringify object))) |
29876 | 490 (insert-and-inherit object) |
491 (set-marker target (point-marker))) | |
492 (if moving | |
493 (goto-char target)))))) | |
494 | |
31241 | 495 ((eshell-processp target) |
29876 | 496 (when (eq (process-status target) 'run) |
55613
8e3531a00902
2004-05-15 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
497 (unless (stringp object) |
8e3531a00902
2004-05-15 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
498 (setq object (eshell-stringify object))) |
29876 | 499 (process-send-string target object))) |
500 | |
501 ((consp target) | |
502 (apply (car target) object (cdr target)))) | |
503 object) | |
504 | |
505 (defun eshell-output-object (object &optional handle-index handles) | |
506 "Insert OBJECT, using HANDLE-INDEX specifically)." | |
507 (let ((target (car (aref (or handles eshell-current-handles) | |
508 (or handle-index eshell-output-handle))))) | |
509 (if (and target (not (listp target))) | |
510 (eshell-output-object-to-target object target) | |
511 (while target | |
512 (eshell-output-object-to-target object (car target)) | |
513 (setq target (cdr target)))))) | |
514 | |
515 ;;; Code: | |
516 | |
52401 | 517 ;;; arch-tag: 9ca2080f-d5e0-4b26-aa0b-d59194a905a2 |
29876 | 518 ;;; esh-io.el ends here |