emacs-devel
[Top][All Lists]
Advanced

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

Re: Add a separate mode for .dir-locals.el


From: Stefan Monnier
Subject: Re: Add a separate mode for .dir-locals.el
Date: Fri, 18 Oct 2019 09:11:19 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

>>    ... other things we may want to fix such as the M-C-x binding which
>>    makes no sense in .dir-locals.el, or the presence of "Byte-compile
>>    this file" in the menu, ...
>
> The former might make sense, because .dir-locals.el can include 'eval'
> forms, right?

No, because those forms won't start in column 0, so C-x C-e might work,
but C-M-x won't.

> If we care about the latter, it can be handled by being
> sensitive to 'no-byte-compile: t' instead.

You really want to have to add `no-byte-compile: t` to every
.dir-locals.el instead of adding an auto-mode-alist rule?

> Or even compare with the file name, as bytecomp.el already does, as do
> other places.

Yes, we can come up with all kinds of hacks, of course.  Not sure why
you'd want to do that instead of using the clean&simple approach of
a separate major mode so you can rely on standard mechanisms like
auto-mode-alist.

> This all sounds to me like "arguments from the future": we don't yet
> have any substantial reasons to define a major mode, but we are trying
> hard to think of any potential reason we might have in the future.

I don't understand what you're getting at.  You seem to think that
creating a major mode is a big deal.  It's not.

I don't need any special reason to define a major mode.
It's not like it's a complex thing to do with far
reaching consequences.  It's a small matter of writing the following
three trivial lines of code:

    (define-derived-mode emacs-lisp-data-mode prog-mode "Emacs-Lisp-Data"
      "Major mode for buffers holding data written in Emacs Lisp syntax."
      :group 'lisp

changing

    (define-derived-mode emacs-lisp-mode prog-mode "Emacs-Lisp"
    (define-derived-mode emacs-lisp-mode emacs-lisp-data-mode "Emacs-Lisp"

and moving three other lines.  This in itself makes no visible
difference to users at all, and it's very easy to see that it's the case
(the main impact is likely the allocation of about 1KB for the syntax
table).

This then lets us solve the original problem by adding a single line
to auto-mode-alist which can be trivially shown to only affect those
files that happen to match the regexp we choose to use there.

So they're all simple and safe steps.

Creating a major mode is cheap and easy.  No need to be afraid.  Even if
it inserts itself inside a pre-existing part of the hierarchy as is the
case here.


        Stefan




reply via email to

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