Lindydancer / e2ansi

Syntax highlighting for `less`, powered by Emacs
86 stars 3 forks source link

Improve the emacs search #11

Open Ergus opened 3 years ago

Ergus commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

Hi!

Unfortunately, it doesn't work. I need to pass the --script flag to Emacs.

I've tried with "#!/usr/bin/env emacs --script". On some systems it works. On other systems, "env" see "emacs --script" as one argument (not two) and fails to locate Emacs.

If you have any suggestions on how to fix this, please let me know.

-- Anders

On Fri, Oct 2, 2020 at 8:05 AM Phil Hudson notifications@github.com wrote:

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.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Lindydancer/e2ansi/issues/11#issuecomment-702543517, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAYGGQCZDYBM266MMFY7XCTSIVURTANCNFSM4SA7X76A .

PhilHudson commented 3 years ago

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

phil-s commented 3 years ago

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 commented 3 years ago

Hi!

Personally, I try to stay away from hacks, as they often tend to come back and bite you.

I would rather have an officially sanctioned solution, like an executable which is distributed with emacs that start emacs in batch mode. In fact, that binary could omit everything GUI-related, making it lean and fast, and with sane option parsing rules. (And elisp will take over the scripting world -- don't forget where you heard it first.)

-- Anders

On Sat, Oct 3, 2020 at 5:51 AM phil-s notifications@github.com wrote:

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.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Lindydancer/e2ansi/issues/11#issuecomment-703041179, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAYGGQDJMYZC7QKMTRHCDVLSI2NSZANCNFSM4SA7X76A .

phil-s commented 3 years ago

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.