aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/eshell/em-script.el
diff options
context:
space:
mode:
authorJim Porter2023-09-17 21:06:46 -0700
committerJim Porter2023-09-17 21:10:28 -0700
commit9ab8b968d63d9287639bbc574873bf8fde769fea (patch)
tree9d70e6ef15be15f1c1771c85218cbe1d8c916c9d /lisp/eshell/em-script.el
parent4e46df96510335c086a3764e002c99348e0e9624 (diff)
downloademacs-9ab8b968d63d9287639bbc574873bf8fde769fea.tar.gz
emacs-9ab8b968d63d9287639bbc574873bf8fde769fea.zip
Use 'eshell-with-temp-command' (indirectly) to parse Eshell script files
* lisp/eshell/esh-cmd.el (eshell--region-p): New function. (eshell-with-temp-command, eshell-parse-command): Support '(:file . FILENAME)' to use the contents of FILENAME. * lisp/eshell/em-script.el (eshell-source-file): Call 'eshell-parse-command' and use backticks.
Diffstat (limited to 'lisp/eshell/em-script.el')
-rw-r--r--lisp/eshell/em-script.el27
1 files changed, 7 insertions, 20 deletions
diff --git a/lisp/eshell/em-script.el b/lisp/eshell/em-script.el
index 55a05076342..9f6f720b8b0 100644
--- a/lisp/eshell/em-script.el
+++ b/lisp/eshell/em-script.el
@@ -89,26 +89,13 @@ This includes when running `eshell-command'."
89(defun eshell-source-file (file &optional args subcommand-p) 89(defun eshell-source-file (file &optional args subcommand-p)
90 "Execute a series of Eshell commands in FILE, passing ARGS. 90 "Execute a series of Eshell commands in FILE, passing ARGS.
91Comments begin with `#'." 91Comments begin with `#'."
92 (let ((orig (point)) 92 (let ((cmd (eshell-parse-command `(:file . ,file))))
93 (here (point-max))) 93 (when subcommand-p
94 (goto-char (point-max)) 94 (setq cmd `(eshell-as-subcommand ,cmd)))
95 (with-silent-modifications 95 (throw 'eshell-replace-command
96 ;; FIXME: Why not use a temporary buffer and avoid this 96 `(let ((eshell-command-name ',file)
97 ;; "insert&delete" business? --Stef 97 (eshell-command-arguments ',args))
98 (insert-file-contents file) 98 ,cmd))))
99 (goto-char (point-max))
100 (throw 'eshell-replace-command
101 (prog1
102 (list 'let
103 (list (list 'eshell-command-name (list 'quote file))
104 (list 'eshell-command-arguments
105 (list 'quote args)))
106 (let ((cmd (eshell-parse-command (cons here (point)))))
107 (if subcommand-p
108 (setq cmd (list 'eshell-as-subcommand cmd)))
109 cmd))
110 (delete-region here (point))
111 (goto-char orig))))))
112 99
113(defun eshell/source (&rest args) 100(defun eshell/source (&rest args)
114 "Source a file in a subshell environment." 101 "Source a file in a subshell environment."