diff options
author | Lars Ingebrigtsen <larsi@gnus.org> | 2022-04-18 12:58:54 +0200 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2022-04-18 12:59:03 +0200 |
commit | fac640ee8608748f0c4b867080d554c1b94121bd (patch) | |
tree | c246d33bea0a7b08204d892cb17969147bca6404 /lisp/startup.el | |
parent | 89a5aa4ca791b3ffefb0a5d464fa433f310a8398 (diff) | |
download | emacs-fac640ee8608748f0c4b867080d554c1b94121bd.tar.gz |
Make it easier to use Emacs as a script interpreter
* doc/emacs/cmdargs.texi (Initial Options): Document -x.
* lisp/startup.el (command-line-1): Add new -scripteval.
(command-line--eval-script): New function.
* src/emacs.c (main): Transform -x to -scripteval.
(standard_args): Add -x (bug#20682).
Diffstat (limited to 'lisp/startup.el')
-rw-r--r-- | lisp/startup.el | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/lisp/startup.el b/lisp/startup.el index ab7b81a707e..353b5c78f17 100644 --- a/lisp/startup.el +++ b/lisp/startup.el @@ -2664,7 +2664,7 @@ nil default-directory" name) ;; This is used to handle -script. It's not clear ;; we need to document it (it is totally internal). - ((member argi '("-scriptload")) + ((member argi '("-scriptload" "-scripteval")) (let* ((file (command-line-normalize-file-name (or argval (pop command-line-args-left)))) ;; Take file from default dir. @@ -2677,7 +2677,10 @@ nil default-directory" name) ;; actually exist on some systems. (when (file-exists-p truename) (setq file-ex truename)) - (command-line--load-script file-ex))) + (if (equal argi "-scripteval") + ;; This will kill Emacs. + (command-line--eval-script file-ex) + (command-line--load-script file-ex)))) ((equal argi "-insert") (setq inhibit-startup-screen t) @@ -2879,6 +2882,22 @@ nil default-directory" name) (delete-line)) (eval-buffer buffer nil file nil t))))) +(defun command-line--eval-script (file) + (load-with-code-conversion + file file nil t + (lambda (buffer _) + (with-current-buffer buffer + (goto-char (point-min)) + (when (looking-at "#!") + (forward-line)) + (let (value form) + (while (ignore-error 'end-of-file + (setq form (read (current-buffer)))) + (setq value (eval form t))) + (kill-emacs (if (numberp value) + value + 0))))))) + (defun command-line-normalize-file-name (file) "Collapse multiple slashes to one, to handle non-Emacs file names." (save-match-data |