unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Greg Minshall <minshall@umich.edu>
To: emacs-devel@gnu.org
Subject: (unknown)
Date: Fri, 17 Nov 2023 19:13:56 -0800	[thread overview]
Message-ID: <1325582.1700277236@archlinux> (raw)

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++)
----



             reply	other threads:[~2023-11-18  3:13 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-18  3:13 Greg Minshall [this message]
2023-11-18  7:05 ` (unknown) Jim Porter
2023-11-18 14:10   ` (unknown) -x behavior change Greg Minshall
2023-11-18  7:36 ` Emacs script options Eli Zaretskii
2023-11-18 14:38   ` Greg Minshall
2023-11-18 16:20     ` Eli Zaretskii
2023-11-18 19:36       ` Greg Minshall
2023-11-19  5:55         ` Eli Zaretskii
2023-11-27  3:29   ` Greg Minshall
2023-11-27 12:59     ` Eli Zaretskii
2023-11-27 19:32       ` Greg Minshall
2023-11-18 19:18 ` Sebastian Miele
2023-11-18 19:49   ` Greg Minshall
2023-11-19 21:39     ` Jens Schmidt
2023-11-19 21:47       ` Jens Schmidt
2023-11-20  1:19         ` Greg Minshall
2023-11-21 21:13           ` Jens Schmidt
2023-11-22 18:17             ` Sebastian Miele
2023-11-22 20:18               ` Jens Schmidt
2023-11-24  4:22             ` Greg Minshall
2023-11-26 18:07               ` Jens Schmidt
2023-11-20  6:10         ` Sebastian Miele
2023-11-20 20:10           ` Jens Schmidt
2023-11-21  8:51             ` Sebastian Miele
2023-11-19  5:04   ` Bob Rogers
2023-11-19  6:21     ` Eli Zaretskii
  -- strict thread matches above, loose matches on Subject: below --
2024-03-13 12:48 (unknown) Eli Zaretskii
2023-03-13  6:32 (unknown) Pedro Andres Aranda Gutierrez
2023-03-13  6:18 (unknown) Pedro Andres Aranda Gutierrez
2022-10-03  6:30 (unknown) Pedro Andres Aranda Gutierrez
2022-07-21 11:36 (unknown) Gregory Heytings
2022-05-29  6:06 (unknown) Pedro Andres Aranda Gutierrez
2021-12-20  2:29 (unknown) Davin Pearson
2021-08-23 18:37 (unknown) telegraph
2021-08-23 18:36 (unknown) telegraph
2021-07-27 23:54 (unknown) Troy Hinckley
2020-09-06  7:04 (unknown) Ag Ibragimov
2018-04-09 23:58 (unknown) siraben
2017-08-30 19:33 (unknown) Mark Oteiza
2017-03-19 16:48 (unknown) Paul Pogonyshev
2017-03-19 19:16 ` (unknown) Mark Oteiza
2017-03-19 19:36   ` (unknown) Paul Pogonyshev
2016-12-28  7:15 (unknown) Chris Gregory
2016-12-28  8:58 ` (unknown) Andreas Schwab
2016-09-28 12:26 (unknown) Takesi Ayanokoji
2016-09-29 13:52 ` (unknown) Byung-Hee HWANG (황병희, 黃炳熙)
2016-02-20 15:28 (unknown) Anders Lindgren
2016-02-08  7:54 (unknown) steve
2016-02-08  8:01 ` (unknown) Steve Purcell
2015-08-10 13:59 (unknown) David Kastrup
2015-08-10 14:02 ` (unknown) David Kastrup
2014-11-13 15:21 (unknown) Eli Zaretskii
2014-11-13 15:30 ` (unknown) Lars Magne Ingebrigtsen
2013-07-04  7:50 (unknown) João Távora
2013-07-06 15:22 ` (unknown) Lars Ingebrigtsen
2013-07-06 17:58   ` (unknown) João Távora
2013-07-06 18:01     ` (unknown) Lars Ingebrigtsen
2012-06-29 13:20 (unknown) Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1325582.1700277236@archlinux \
    --to=minshall@umich.edu \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).