aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/eshell
diff options
context:
space:
mode:
authorStefan Monnier2013-09-17 11:19:12 -0400
committerStefan Monnier2013-09-17 11:19:12 -0400
commite8b66a6a262b12405e2f29f3693a1f2d57061e2b (patch)
tree897f3271a1d9248e597987b3a0cf0b7c8724cfea /lisp/eshell
parent4e0bf886e03d5b3f4b73b3196c8aa54974209676 (diff)
downloademacs-e8b66a6a262b12405e2f29f3693a1f2d57061e2b.tar.gz
emacs-e8b66a6a262b12405e2f29f3693a1f2d57061e2b.zip
* lisp/eshell/esh-cmd.el (eshell-post-rewrite-command-function): New var.
(eshell-post-rewrite-command-hook): Make obsolete. (eshell-parse-command): Simplify. (eshell-structure-basic-command): Remove unused arg `vocal-test'. (eshell--cmd): Declare. (eshell-parse-pipeline): Remove unused var `final-p'. Pass a dynvar to eshell-post-rewrite-command-hook. Implement the new eshell-post-rewrite-command-function. (eshell-invoke-directly): Remove unused arg `input'. * lisp/eshell/esh-io.el (eshell-io-initialize): Use eshell-post-rewrite-command-function. (eshell--apply-redirections): Rename from eshell-apply-redirections; adjust to new calling convention. (eshell-create-handles): Rename args to avoid clashing with dynvar `standard-output'. Fixes: debbugs:15399
Diffstat (limited to 'lisp/eshell')
-rw-r--r--lisp/eshell/esh-cmd.el58
-rw-r--r--lisp/eshell/esh-io.el27
-rw-r--r--lisp/eshell/esh-mode.el2
3 files changed, 43 insertions, 44 deletions
diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el
index 75e0e1d27c8..87c72d2caf5 100644
--- a/lisp/eshell/esh-cmd.el
+++ b/lisp/eshell/esh-cmd.el
@@ -205,12 +205,16 @@ forms or strings)."
205 :type 'hook 205 :type 'hook
206 :group 'eshell-cmd) 206 :group 'eshell-cmd)
207 207
208(defcustom eshell-post-rewrite-command-hook nil 208(defvar eshell-post-rewrite-command-function #'identity
209 "Function run after command rewriting is finished.
210Takes the (rewritten) command, modifies it as it sees fit and returns
211the new result to use instead.")
212(defvar eshell-post-rewrite-command-hook nil
209 "A hook run after command rewriting is finished. 213 "A hook run after command rewriting is finished.
210Each function is passed the symbol containing the rewritten command, 214Each function is passed the symbol containing the rewritten command,
211which may be modified directly. Any return value is ignored." 215which may be modified directly. Any return value is ignored.")
212 :type 'hook 216(make-obsolete-variable 'eshell-post-rewrite-command-hook
213 :group 'eshell-cmd) 217 'eshell-post-rewrite-command-function "24.4")
214 218
215(defcustom eshell-complex-commands '("ls") 219(defcustom eshell-complex-commands '("ls")
216 "A list of commands names or functions, that determine complexity. 220 "A list of commands names or functions, that determine complexity.
@@ -335,10 +339,10 @@ otherwise t.")
335 339
336;; Command parsing 340;; Command parsing
337 341
338(defun eshell-parse-command (command &optional args top-level) 342(defun eshell-parse-command (command &optional args toplevel)
339 "Parse the COMMAND, adding ARGS if given. 343 "Parse the COMMAND, adding ARGS if given.
340COMMAND can either be a string, or a cons cell demarcating a buffer 344COMMAND can either be a string, or a cons cell demarcating a buffer
341region. TOP-LEVEL, if non-nil, means that the outermost command (the 345region. TOPLEVEL, if non-nil, means that the outermost command (the
342user's input command) is being parsed, and that pre and post command 346user's input command) is being parsed, and that pre and post command
343hooks should be run before and after the command." 347hooks should be run before and after the command."
344 (let* (sep-terms 348 (let* (sep-terms
@@ -363,7 +367,7 @@ hooks should be run before and after the command."
363 (setq cmd 367 (setq cmd
364 (if (or (not (car sep-terms)) 368 (if (or (not (car sep-terms))
365 (string= (car sep-terms) ";")) 369 (string= (car sep-terms) ";"))
366 (eshell-parse-pipeline cmd (not (car sep-terms))) 370 (eshell-parse-pipeline cmd)
367 `(eshell-do-subjob 371 `(eshell-do-subjob
368 (list ,(eshell-parse-pipeline cmd))))) 372 (list ,(eshell-parse-pipeline cmd)))))
369 (setq sep-terms (cdr sep-terms)) 373 (setq sep-terms (cdr sep-terms))
@@ -376,17 +380,12 @@ hooks should be run before and after the command."
376 (if (cdr cmd) 380 (if (cdr cmd)
377 (setcar cmd `(eshell-commands ,(car cmd)))) 381 (setcar cmd `(eshell-commands ,(car cmd))))
378 (setq cmd (cdr cmd)))) 382 (setq cmd (cdr cmd))))
379 (setq commands 383 (if toplevel
380 `(progn 384 `(eshell-commands (progn
381 ,@(if top-level 385 (run-hooks 'eshell-pre-command-hook)
382 '((run-hooks 'eshell-pre-command-hook))) 386 (catch 'top-level (progn ,@commands))
383 ,@(if (not top-level) 387 (run-hooks 'eshell-post-command-hook)))
384 commands 388 (macroexp-progn commands))))
385 `((catch 'top-level (progn ,@commands))
386 (run-hooks 'eshell-post-command-hook)))))
387 (if top-level
388 `(eshell-commands ,commands)
389 commands)))
390 389
391(defun eshell-debug-command (tag subform) 390(defun eshell-debug-command (tag subform)
392 "Output a debugging message to '*eshell last cmd*'." 391 "Output a debugging message to '*eshell last cmd*'."
@@ -509,14 +508,11 @@ implemented via rewriting, rather than as a function."
509 (list 'quote eshell-last-command-result)))))) 508 (list 'quote eshell-last-command-result))))))
510 509
511(defun eshell-structure-basic-command (func names keyword test body 510(defun eshell-structure-basic-command (func names keyword test body
512 &optional else vocal-test) 511 &optional else)
513 "With TERMS, KEYWORD, and two NAMES, structure a basic command. 512 "With TERMS, KEYWORD, and two NAMES, structure a basic command.
514The first of NAMES should be the positive form, and the second the 513The first of NAMES should be the positive form, and the second the
515negative. It's not likely that users should ever need to call this 514negative. It's not likely that users should ever need to call this
516function. 515function."
517
518If VOCAL-TEST is non-nil, it means output from the test should be
519shown, as well as output from the body."
520 ;; If the test form begins with `eshell-convert', it means 516 ;; If the test form begins with `eshell-convert', it means
521 ;; something data-wise will be returned, and we should let 517 ;; something data-wise will be returned, and we should let
522 ;; that determine the truth of the statement. 518 ;; that determine the truth of the statement.
@@ -586,7 +582,9 @@ For an external command, it means an exit code of 0."
586 eshell-last-command-result 582 eshell-last-command-result
587 (= eshell-last-command-status 0))) 583 (= eshell-last-command-status 0)))
588 584
589(defun eshell-parse-pipeline (terms &optional final-p) 585(defvar eshell--cmd)
586
587(defun eshell-parse-pipeline (terms)
590 "Parse a pipeline from TERMS, return the appropriate Lisp forms." 588 "Parse a pipeline from TERMS, return the appropriate Lisp forms."
591 (let* (sep-terms 589 (let* (sep-terms
592 (bigpieces (eshell-separate-commands terms "\\(&&\\|||\\)" 590 (bigpieces (eshell-separate-commands terms "\\(&&\\|||\\)"
@@ -603,8 +601,11 @@ For an external command, it means an exit code of 0."
603 (run-hook-with-args 'eshell-pre-rewrite-command-hook cmd) 601 (run-hook-with-args 'eshell-pre-rewrite-command-hook cmd)
604 (setq cmd (run-hook-with-args-until-success 602 (setq cmd (run-hook-with-args-until-success
605 'eshell-rewrite-command-hook cmd)) 603 'eshell-rewrite-command-hook cmd))
606 (run-hook-with-args 'eshell-post-rewrite-command-hook 'cmd) 604 (let ((eshell--cmd cmd))
607 (setcar p cmd)) 605 (run-hook-with-args 'eshell-post-rewrite-command-hook
606 'eshell--cmd)
607 (setq cmd eshell--cmd))
608 (setcar p (funcall eshell-post-rewrite-command-function cmd)))
608 (setq p (cdr p))) 609 (setq p (cdr p)))
609 (nconc results 610 (nconc results
610 (list 611 (list
@@ -625,8 +626,7 @@ For an external command, it means an exit code of 0."
625 (setq final (eshell-structure-basic-command 626 (setq final (eshell-structure-basic-command
626 'if (string= (car sep-terms) "&&") "if" 627 'if (string= (car sep-terms) "&&") "if"
627 `(eshell-protect ,(car results)) 628 `(eshell-protect ,(car results))
628 `(eshell-protect ,final) 629 `(eshell-protect ,final))
629 nil t)
630 results (cdr results) 630 results (cdr results)
631 sep-terms (cdr sep-terms))) 631 sep-terms (cdr sep-terms)))
632 final)) 632 final))
@@ -916,7 +916,7 @@ at the moment are:
916 "Completion for the `debug' command." 916 "Completion for the `debug' command."
917 (while (pcomplete-here '("errors" "commands")))) 917 (while (pcomplete-here '("errors" "commands"))))
918 918
919(defun eshell-invoke-directly (command input) 919(defun eshell-invoke-directly (command)
920 (let ((base (cadr (nth 2 (nth 2 (cadr command))))) name) 920 (let ((base (cadr (nth 2 (nth 2 (cadr command))))) name)
921 (if (and (eq (car base) 'eshell-trap-errors) 921 (if (and (eq (car base) 'eshell-trap-errors)
922 (eq (car (cadr base)) 'eshell-named-command)) 922 (eq (car (cadr base)) 'eshell-named-command))
diff --git a/lisp/eshell/esh-io.el b/lisp/eshell/esh-io.el
index f620890ee6b..c4c0bd43790 100644
--- a/lisp/eshell/esh-io.el
+++ b/lisp/eshell/esh-io.el
@@ -179,8 +179,8 @@ not be added to this variable."
179 (make-local-variable 'eshell-current-redirections) 179 (make-local-variable 'eshell-current-redirections)
180 (add-hook 'eshell-pre-rewrite-command-hook 180 (add-hook 'eshell-pre-rewrite-command-hook
181 'eshell-strip-redirections nil t) 181 'eshell-strip-redirections nil t)
182 (add-hook 'eshell-post-rewrite-command-hook 182 (add-function :filter-return (local 'eshell-post-rewrite-command-function)
183 'eshell-apply-redirections nil t)) 183 #'eshell--apply-redirections))
184 184
185(defun eshell-parse-redirection () 185(defun eshell-parse-redirection ()
186 "Parse an output redirection, such as '2>'." 186 "Parse an output redirection, such as '2>'."
@@ -223,28 +223,27 @@ not be added to this variable."
223 (setq eshell-current-redirections 223 (setq eshell-current-redirections
224 (cdr eshell-current-redirections)))) 224 (cdr eshell-current-redirections))))
225 225
226(defun eshell-apply-redirections (cmdsym) 226(defun eshell--apply-redirections (cmd)
227 "Apply any redirection which were specified for COMMAND." 227 "Apply any redirection which were specified for COMMAND."
228 (if eshell-current-redirections 228 (if eshell-current-redirections
229 (set cmdsym 229 `(progn
230 (append (list 'progn) 230 ,@eshell-current-redirections
231 eshell-current-redirections 231 ,cmd)
232 (list (symbol-value cmdsym)))))) 232 cmd))
233 233
234(defun eshell-create-handles 234(defun eshell-create-handles
235 (standard-output output-mode &optional standard-error error-mode) 235 (stdout output-mode &optional stderr error-mode)
236 "Create a new set of file handles for a command. 236 "Create a new set of file handles for a command.
237The default location for standard output and standard error will go to 237The default location for standard output and standard error will go to
238STANDARD-OUTPUT and STANDARD-ERROR, respectively. 238STDOUT and STDERR, respectively.
239OUTPUT-MODE and ERROR-MODE are either `overwrite', `append' or `insert'; 239OUTPUT-MODE and ERROR-MODE are either `overwrite', `append' or `insert';
240a nil value of mode defaults to `insert'." 240a nil value of mode defaults to `insert'."
241 (let ((handles (make-vector eshell-number-of-handles nil)) 241 (let ((handles (make-vector eshell-number-of-handles nil))
242 (output-target (eshell-get-target standard-output output-mode)) 242 (output-target (eshell-get-target stdout output-mode))
243 (error-target (eshell-get-target standard-error error-mode))) 243 (error-target (eshell-get-target stderr error-mode)))
244 (aset handles eshell-output-handle (cons output-target 1)) 244 (aset handles eshell-output-handle (cons output-target 1))
245 (if standard-error 245 (aset handles eshell-error-handle
246 (aset handles eshell-error-handle (cons error-target 1)) 246 (cons (if stderr error-target output-target) 1))
247 (aset handles eshell-error-handle (cons output-target 1)))
248 handles)) 247 handles))
249 248
250(defun eshell-protect-handles (handles) 249(defun eshell-protect-handles (handles)
diff --git a/lisp/eshell/esh-mode.el b/lisp/eshell/esh-mode.el
index 1a80e3894e1..e770c773920 100644
--- a/lisp/eshell/esh-mode.el
+++ b/lisp/eshell/esh-mode.el
@@ -671,7 +671,7 @@ newline."
671 (run-hooks 'eshell-input-filter-functions) 671 (run-hooks 'eshell-input-filter-functions)
672 (and (catch 'eshell-terminal 672 (and (catch 'eshell-terminal
673 (ignore 673 (ignore
674 (if (eshell-invoke-directly cmd input) 674 (if (eshell-invoke-directly cmd)
675 (eval cmd) 675 (eval cmd)
676 (eshell-eval-command cmd input)))) 676 (eshell-eval-command cmd input))))
677 (eshell-life-is-too-much))))) 677 (eshell-life-is-too-much)))))