From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Greg Minshall Newsgroups: gmane.emacs.devel Subject: (unknown) Date: Fri, 17 Nov 2023 19:13:56 -0800 Message-ID: <1325582.1700277236@archlinux> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11080"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Nov 18 07:37:28 2023 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1r4ExK-0002fw-Lf for ged-emacs-devel@m.gmane-mx.org; Sat, 18 Nov 2023 07:37:26 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r4Ex7-0005nZ-2T; Sat, 18 Nov 2023 01:37:13 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r4Bmb-0006Hy-Cr for emacs-devel@gnu.org; Fri, 17 Nov 2023 22:14:09 -0500 Original-Received: from relay-egress-host.us-east-2.a.mail.umich.edu ([18.216.144.57] helo=lively-olwen.relay-egress.a.mail.umich.edu) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r4BmY-00012H-4L for emacs-devel@gnu.org; Fri, 17 Nov 2023 22:14:09 -0500 Original-Received: from mammoth-yacaruna.authn-relay.a.mail.umich.edu (ip-10-0-73-60.us-east-2.compute.internal [10.0.73.60]) by lively-olwen.relay-egress.a.mail.umich.edu with ESMTPS id 65582BF9.849E8BD.22535AF.60144; Fri, 17 Nov 2023 22:14:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=umich.edu; s=relay-2018-08-29; t=1700277240; bh=9RgnSB/+hmxYLUbv0HYUlTKlNOpRdP1joK1Yh4q13FY=; h=From:To:Subject:Date; b=GCuLG8z/phS6o6CBbZJyyf2XeUJSTJMf08ZrQTB/gJotFb+WHq0x2bF496pDoQhbD wqmsGnv1WlHn68cBqYULLHXccYzrobuEq1r8yUEAunrMkHUWZU7wXYFPPFUgKexeCw +2i+R+gcsOw/sXA/dcpd4x0hqnXOjVAhQQoUDrXkRu+BXqMzkIyFAhgLexFkCLTpDk aZxQ38KYnvGo+qm8CsW+0GU781KM58L2lgsREVH5kjuzpH4w/Y+sAjjSxVL7gYWygH S7e9hI/zXqtWdOwrVtNXhPABCv3bkWNgc5eIbFvstjCn/9tgAPntub0OzB0eL6IMP6 7s23p2Bdq6QvQ== Authentication-Results: mammoth-yacaruna.authn-relay.a.mail.umich.edu; iprev=pass policy.iprev=134.16.93.10 (134-016-093-010.res.spectrum.com); auth=pass smtp.auth=minshall Original-Received: from localhost (134-016-093-010.res.spectrum.com [134.16.93.10]) by mammoth-yacaruna.authn-relay.a.mail.umich.edu with ESMTPSA id 65582BF8.B979845.23BBB744.2227991; Fri, 17 Nov 2023 22:14:00 -0500 X-Mailer: MH-E 8.6+git; nmh 1.7.1; Emacs 30.0.50 Content-ID: <1325581.1700277236.1@archlinux> Received-SPF: pass client-ip=18.216.144.57; envelope-from=minshall@umich.edu; helo=lively-olwen.relay-egress.a.mail.umich.edu X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sat, 18 Nov 2023 01:37:11 -0500 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:312890 Archived-At: 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] =3D=3D '-' && argv[from][2] =3D=3D 0) + /* If we have found "--", or a "-x", don't consider any more + arguments as options. */ + if ((((argv[from][1] =3D=3D '-') || (argv[from][1] =3D=3D 'x')) = && argv[from][2] =3D=3D 0) + || !strcmp(argv[from], "-scripteval")) { /* Leave the "--", and everything following it, at the end. = */ for (; from < argc; from++) ----