[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#31220: 25.3; emacs --script breaks command-line arguments handling

From: Phil Sainty
Subject: bug#31220: 25.3; emacs --script breaks command-line arguments handling
Date: Fri, 20 Apr 2018 11:26:04 +1200
User-agent: Orcon Webmail

On 2018-04-20 08:00, Thibault Polge wrote:
When running an Emacs Lisp script with either the `#!emacs --script`
shebang or by invoking `emacs --script script.el`, Emacs:

1. immediately processes command-line arguments it knows, even if they
   were passed *after* --script.  It means, for example, that no script
   can provide a meaningful --help script, because Emacs always
   intercepts help.

Writing elisp scripts is fiddly, but it *is* possible to handle
arbitrary arguments cleanly.

As with many programs, you can use the argument '--' to tell Emacs not
to process further arguments as if they were options. e.g.:

$ emacs --script -- --help

Which will pass '--' and '--help' to the script.

Some boiler-plate for an elisp script is:

":"; exec emacs -Q --script "$0" -- "$@" # -*-emacs-lisp-*-
(pop argv) # Remove the "--" argument
# ...
# Always exit explicitly. This returns the desired exit
# status, and also avoids the need to (setq argv nil).
(kill-emacs 0)

For more information see:

* https://stackoverflow.com/a/6259330/324105
* https://swsnr.de/posts/emacs-script-pitfalls

reply via email to

[Prev in Thread] Current Thread [Next in Thread]