[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Greg Minshall |
Subject: |
|
Date: |
Fri, 17 Nov 2023 19:13:56 -0800 |
hi. i would like to be able to write Emacs scripts ("#!...") that allow
a user to enter almost any option to the script itself, *without* having
to use double dashes ("--") to avoid colliding with Emacs option
processing.
looking at "--script" and "-x", this doesn't seem possible.
as a test case, given a simple script foo.sh (*), using "-x", and
invoking it with an option "--eval" gives this error:
----
% ./foo.sh --eval
emacs: Option '--eval' requires an argument
----
(that bare "--eval" *should* be an error if it were meant for Emacs
itself; however, it is meant for the Emacs script, which may have other
ideas of the syntax/semantics of "--eval".)
the below patch to src/emacs.c (**) treats a "-x" (and its "partner"
"-scripteval") like a "--" on the command line, and *seems* to allow
arbitrary options on the command line. for example, with this patch
installed:
----
% ./foo.sh --eval
command-line-args-left (--eval)
----
i wonder if this might be of use for Emacs? if there are worries about
backwards compatibility with "-x", well ... "-y" anybody? :)
(i was thinking of writing a test to go with the patch, but the ERT
framework is maybe a bit awkward for tests of essentially
shell-command-line functionality. i may have missed it, but i didn't
see anything in ./test/Makefile.in that seemed to be aimed at testing
command-line invocation of Emacs.)
cheers, Greg
(*) foo.sh
----
#!/usr/bin/env -S emacs -x
(message "command-line-args-left %s" command-line-args-left)
1
----
(**) proposed patch
----
diff --git a/src/emacs.c b/src/emacs.c
index 6101ed4004c..6e140177086 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -2795,9 +2795,10 @@ sort_args (int argc, char **argv)
{
int match;
- /* If we have found "--", don't consider
- any more arguments as options. */
- if (argv[from][1] == '-' && argv[from][2] == 0)
+ /* If we have found "--", or a "-x", don't consider any more
+ arguments as options. */
+ if ((((argv[from][1] == '-') || (argv[from][1] == 'x')) &&
argv[from][2] == 0)
+ || !strcmp(argv[from], "-scripteval"))
{
/* Leave the "--", and everything following it, at the end. */
for (; from < argc; from++)
----
- [no subject],
Greg Minshall <=
Re: Emacs script options, Greg Minshall, 2023/11/26