Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the emacs search #11

Open
Ergus opened this issue Oct 1, 2020 · 6 comments
Open

Improve the emacs search #11

Ergus opened this issue Oct 1, 2020 · 6 comments

Comments

@Ergus
Copy link

Ergus commented Oct 1, 2020

Hi:

I have a different emacs path in my system so I need to update e2ansi-cat header everytime I download it:

Could you consider to use:
#!/usr/bin/env emacs

?

Thanks in advance,
Ergus

@PhilHudson
Copy link

Good idea. In the meantime, if you are on a Debian-derived distro, you can use the 'alternatives' system to make sure /usr/bin/emacs points to your preferred version. See https://gitlab.com/-/snippets/2015138 for the script I use.

@Lindydancer
Copy link
Owner

Lindydancer commented Oct 2, 2020 via email

@PhilHudson
Copy link

As a possible external workaround, would putting the preferred version's containing directory at the head of the PATH environment variable work?

@phil-s
Copy link

phil-s commented Oct 3, 2020

The best general approach I know for running emacs --script is:

#!/bin/sh
":"; exec emacs -Q --script "$0" -- "$@" # -*-emacs-lisp-*-
(pop argv) ; Remove the "--" argument
;; (setq debug-on-error t) ; if a backtrace is wanted
;; (defun stdout (msg args) (princ (format msg args)))
;; (defun stderr (msg args) (princ (format msg args)
;;                                 #'external-debugging-output))
;; [script body]
(kill-emacs 0) ; Always exit explicitly. This returns the desired exit
               ; status, and also avoids the need to (setq argv nil).

See https://stackoverflow.com/questions/6238331/emacs-shell-scripts-how-to-put-initial-options-into-the-script#6259330 regarding the main trickery at the start. This approach enables you to use any arbitrary command-line, and also to support arbitrary command-line arguments to the script itself.

https://lunaryorn.com/blog/emacs-script-pitfalls/ is a good overview.

@Lindydancer
Copy link
Owner

Lindydancer commented Oct 4, 2020 via email

@phil-s
Copy link

phil-s commented Oct 4, 2020

It's undeniably a hack, but the shell part is POSIX behaviour, and Elisp isn't ever going to stop using ; as a comment starter. IMHO it's about as safe as anyone could ask for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants