From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Sebastian Miele Newsgroups: gmane.emacs.devel Subject: Re: Emacs script options Date: Sat, 18 Nov 2023 20:18:00 +0100 Message-ID: <8734x2zwnc.fsf@whxvd.name> References: <1325582.1700277236@archlinux> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38133"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Greg Minshall Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Nov 18 20:32:14 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 1r4R38-0009jU-6J for ged-emacs-devel@m.gmane-mx.org; Sat, 18 Nov 2023 20:32:14 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r4R2D-0005Qo-Hh; Sat, 18 Nov 2023 14:31:17 -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 1r4R2A-0005QR-9u for emacs-devel@gnu.org; Sat, 18 Nov 2023 14:31:15 -0500 Original-Received: from mout-p-201.mailbox.org ([80.241.56.171]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256) (Exim 4.90_1) (envelope-from ) id 1r4R27-0006tz-Av for emacs-devel@gnu.org; Sat, 18 Nov 2023 14:31:14 -0500 Original-Received: from smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4SXkQc23SZz9sJ6; Sat, 18 Nov 2023 20:31:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=whxvd.name; s=MBO0001; t=1700335864; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7+egOaP7G64m0hVtcHj/RtwH28arlCli873PqGe7oyM=; b=E/4YlCJhRaV18zBlXivfsXNGYMNwL2QU6NiCwm5ifBM58E3uEs+PKZSEo12uIAIun4v/4K Bhecv/zuCreAe2wlhQZLLMrqNaR8fH3L/SngyOJ2UEhNyUTbsMKYJOBFdXnOMujzyAk42Q p3CSaOczJ/Zq8h+Oc81Irxn/ToaAKkNqLRIkXmndPRYw5sYKTPxCkrZc6NM8cVnN9EV9vw ehKgHg4tOmcmDItWTiWSdRzP419F+52ENPchV0GzUmXz9wEpT+FFbTVP7Vi12qlohVe/Eo K6k10yeSRnDbg1p0gIVy0SPDQvkzb9tAPqgdLgN/dHnyV0BSgYEB9BEgphv+JQ== In-reply-to: <1325582.1700277236@archlinux> Received-SPF: pass client-ip=80.241.56.171; envelope-from=iota@whxvd.name; helo=mout-p-201.mailbox.org X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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-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:312926 Archived-At: > From: Greg Minshall > Date: Fri, 2023-11-17 19:13 -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) > ---- On Linux that can be achieved by defining a custom interpreter. E.g., put the following into =E2=80=98/path/to/emacs-script=E2=80=99: #!/bin/sh script=3D$1 shift exec emacs -Q --batch --load $script -- "$@" Then, with the following in a =E2=80=98test-script=E2=80=99 #!/path/to/emacs-script ;; -*- mode: emacs-lisp; lexical-binding: t -*- (message "%s" command-line-args-left) =E2=80=98test-script --eval=E2=80=99 prints "(-- --eval)". On Linux, and when =E2=80=98emacs-script=E2=80=99 is in the PATH, the =E2= =80=98/path/to/=E2=80=99 in the shebang even can be omitted. However, the workaround is not possible on at least some non-Linux systems, because not all systems allow something interpreted as an interpreter in a shebang, see https://en.wikipedia.org/wiki/Shebang_(Unix)#Syntax.