GNU bug report logs - #31220
25.3; emacs --script breaks command-line arguments handling

Previous Next

Package: emacs;

Reported by: Thibault Polge <thibault <at> thb.lt>

Date: Thu, 19 Apr 2018 20:03:02 UTC

Severity: minor

Found in version 25.3

Done: Thibault Polge <thibault <at> thb.lt>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Phil Sainty <psainty <at> orcon.net.nz>
To: Thibault Polge <thibault <at> thb.lt>
Cc: 31220 <at> debbugs.gnu.org, bug-gnu-emacs <bug-gnu-emacs-bounces+psainty=orcon.net.nz <at> gnu.org>
Subject: bug#31220: 25.3; emacs --script breaks command-line arguments handling
Date: Fri, 20 Apr 2018 11:26:04 +1200
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:

#!/bin/sh
":"; 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






This bug report was last modified 7 years and 94 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.