help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Emacs script that works on all platforms


From: Frédéric Perrin
Subject: Re: Emacs script that works on all platforms
Date: Wed, 08 Dec 2010 15:09:17 -0000
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux)

Johan Andersson <johan.rejeep@gmail.com> writes:
> I have an Emacs script where the first line looks like this:
> #!/usr/bin/emacs --script
>
> However, on Mac OSX, Emacs is installed by default, but with an old
> version.
>
> I have also installed Emacs via Homebrew (compiled from source) and
> can run that with:
> /Usr/local/Cellar/emacs/23.2/Emacs.app/Contents/MacOS/Emacs
>
> So, to run the script with the Homebrew version, I could change the
> first line in my script to:
> #!/Usr/local/Cellar/emacs/23.2/Emacs.app/Contents/MacOS/Emacs
> --script
>
> That works, but I want this script to work on both GNU/Linux and Mac
> OSX (Both default and Homebrew version).
>
> I was thinking I could use env somehow, like this:
> #!/usr/bin/env emacs --script
>
> And then make emacs an alias or function that points to the correct
> binary depending on system. But it's still the default Emacs that is
> used.

In `/usr/bin/env emacs', env(1) will execvp(3) `emacs' ; so it won't
follow your shell aliases or functions.

Ideas :

Put ~/bin as the first thing in your $PATH, and make ~/bin/emacs a
symlink to the emacs you want to use. Then, use the `/usr/bin/env
emacs' trick.

Expand on the sesquicolon as described in [1]. Something like
(untested):

:; [ `uname` == "linux" ] && exec /usr/bin/emacs --batch -l $0 $* || exec 
/Usr/local/.../Emacs --batch -l $0 $*

[1] http://www.emacswiki.org/emacs/EmacsScripts

-- 
Fred


reply via email to

[Prev in Thread] Current Thread [Next in Thread]