[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Emacs script options
From: |
Sebastian Miele |
Subject: |
Re: Emacs script options |
Date: |
Sat, 18 Nov 2023 20:18:00 +0100 |
> From: Greg Minshall <minshall@umich.edu>
> 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 ‘/path/to/emacs-script’:
#!/bin/sh
script=$1
shift
exec emacs -Q --batch --load $script -- "$@"
Then, with the following in a ‘test-script’
#!/path/to/emacs-script
;; -*- mode: emacs-lisp; lexical-binding: t -*-
(message "%s" command-line-args-left)
‘test-script --eval’ prints "(-- --eval)".
On Linux, and when ‘emacs-script’ is in the PATH, the ‘/path/to/’ 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.
- Re: Emacs script options, (continued)
- Re: Emacs script options, Eli Zaretskii, 2023/11/18
- Re: Emacs script options, Greg Minshall, 2023/11/18
- Re: Emacs script options, Eli Zaretskii, 2023/11/18
- Re: Emacs script options, Greg Minshall, 2023/11/18
- Re: Emacs script options, Bob Rogers, 2023/11/19
- Re: Emacs script options, Eli Zaretskii, 2023/11/19
- Re: Emacs script options, Eli Zaretskii, 2023/11/19
- Re: Emacs script options, Greg Minshall, 2023/11/26
- Re: Emacs script options,
Sebastian Miele <=
- Re: Emacs script options, Greg Minshall, 2023/11/18
- Re: Emacs script options, Jens Schmidt, 2023/11/19
- Re: Emacs script options, Jens Schmidt, 2023/11/19
- Re: Emacs script options, Greg Minshall, 2023/11/19
- Re: Emacs script options, Jens Schmidt, 2023/11/21
- Re: Emacs script options, Sebastian Miele, 2023/11/22
- Re: Emacs script options, Jens Schmidt, 2023/11/22
- Re: Emacs script options, Greg Minshall, 2023/11/23
- Re: Emacs script options, Jens Schmidt, 2023/11/26
- Re: Emacs script options, Sebastian Miele, 2023/11/20