[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: executable-set-magic update
From: |
Andrew L. Moore |
Subject: |
Re: executable-set-magic update |
Date: |
Mon, 24 Jul 2017 18:41:54 -0400 |
> On Jul 24, 2017, at 2:22 PM, Andrew L. Moore <address@hidden> wrote:
>
>>> It would also be nice if `executable-set-magic’ were supported beyond
>>> `sh-set-shell’ (in lisp/progmodes/sh-script.el), so I implemented
>>> a minor mode that adds the following hook to find-file:
>>>
>>> (defun script-set-magic ()
>>> "Look up interpreter associated with current major mode in
>>> `script-set-magic-alist' and call `executable-set-magic'."
>>> (let ((interpreter (alist-get major-mode script-set-magic-alist)))
>>> (if interpreter (executable-set-magic interpreter)))
>>> )
>
>> Stefan Monnier wrote:
>> Doesn't this add a #! to every file using modes like
>> js/ruby/awk/perl/python/...?
>>
>> In multi-file programs, only the main file needs a "#!", so I don't
>> understand why adding #! to all files would make sense.
>
> Stefan,
> Sorry I missed your comment. Yeah, script libraries don’t use magic numbers,
> so
> I updated the minor mode with a variable that allows skipping files in
> “project”
> directories. And since the minor mode leverages executable-set-magic, it's
> been
> renamed `executable-set-magic-mode’:
>
> https://github.com/slewsys/emacs-extensions/blob/master/executable-set-magic.el
>
> The current implementation searches for a “project root” in the file path
> by brute force. Hopefully that can be updated with something more elegant.
>
> In the mean time, function `executable-set-magic' only seems to be leveraged
> by lisp/progmodes/sh-script.el for shell scripts. So an alternative to
> extending it might be removing it, e.g., to an external library.
> -AM
Oops, the “project root” search was ugly too. Reversing the order of the
functions,
hopefully it’s just inelegant now.
-AM