[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Add a separate mode for .dir-locals.el
From: |
Clément Pit-Claudel |
Subject: |
Re: Add a separate mode for .dir-locals.el |
Date: |
Sat, 19 Oct 2019 08:53:23 -0400 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 |
On 2019-10-19 05:52, Eli Zaretskii wrote:
> Clément, you've reported the original problem, so could you please
> tell more details about it? What triggers the problem, and how does
> it manifest itself to the user? Is it just due to an attempt to
> byte-compile .dir-locals.el, or is it due to something else Flymake
> does? Thanks.
Hi Eli,
Yes, I can describe in more details. In fact, I was first made aware of the
problem while working on Flycheck, and noticed that it appeared in Flymake too.
Over the years, we've had multiple user complaints that opening .dir-locals.el
files in Flycheck cause spurious warnings to appear (e.g.
https://github.com/flycheck/flycheck/issues/908). This is because Flycheck,
like Flymake, tries to byte-compile these files, and runs checkdoc on them.
Both of these return spurious warnings.
Flycheck tries to run the byte-compiler and checkdoc because of the major-mode
in which .dir-locals.el files are opened. The reasoning is that, if these
files are Emacs Lisp files, then they should conform to Emacs Lisp coding
conventions: they should include proper headers, licenses, a `provide' form at
the end, etc. This is how Flycheck works in general: each checker is enabled
by one or multiple major modes. Flymake works in a slightly different fashion:
major modes add local hooks to run the relevant checkers.
Of course, .dir-locals.el are not proper Emacs Lisp files, and as a result both
the byte compiler and checkdoc produce spurious warnings — but Flycheck doesn't
know that, since it relies on the current major mode to decide which checkers
to run.
One workaround is to change Flycheck to pattern match on the name of the
current file in addition to its major mode, so that .dir-locals.el files are
not checked. This is the solution that I will apply if we decide against
introducing a separate mode for dir-locals.el. On the Flymake side, the
definition of emacs-lisp-mode would check the name of the current file, and
only add the relevant Flymake hooks if the current file isn't called
.dir-locals.el.
My motivation for proposing a separate mode was that we already have a
mechanism (atuo-mode-alist) to attach specific behaviors to specific file
names, so it seemed natural to reuse that mechanism to run different code for
regular ELisp files and dir-locals files. IOW, I thought it was an
anti-pattern to do file-name checks in a major-mode definition.
Finally, what motivated me to propose a split was the fact that a fix was
needed in two places (Flymake and Flycheck), and likely in others (company and
completion-at-point-functions should ideally work differently in
.dir-locals.el; imenu doesn't make much sense there, ELisp syntax-highlighting
is sub-optimal for these files outside of `eval' forms, etc.).
Thanks for your patience and your dedication,
Clément.
- Re: Add a separate mode for .dir-locals.el, (continued)
- Re: Add a separate mode for .dir-locals.el, João Távora, 2019/10/18
- Re: Add a separate mode for .dir-locals.el, Dmitry Gutov, 2019/10/18
- Re: Add a separate mode for .dir-locals.el, Eli Zaretskii, 2019/10/19
- Re: Add a separate mode for .dir-locals.el, João Távora, 2019/10/19
- Re: Add a separate mode for .dir-locals.el, João Távora, 2019/10/19
- Re: Add a separate mode for .dir-locals.el, Eli Zaretskii, 2019/10/19
- Re: Add a separate mode for .dir-locals.el, Clément Pit-Claudel, 2019/10/19
- Re: Add a separate mode for .dir-locals.el, João Távora, 2019/10/19
- Re: Add a separate mode for .dir-locals.el, Eli Zaretskii, 2019/10/19
- Re: Add a separate mode for .dir-locals.el, João Távora, 2019/10/19
- Re: Add a separate mode for .dir-locals.el,
Clément Pit-Claudel <=
- Re: Add a separate mode for .dir-locals.el, Eli Zaretskii, 2019/10/19
- Re: Add a separate mode for .dir-locals.el, Clément Pit-Claudel, 2019/10/19
- Re: Add a separate mode for .dir-locals.el, Dmitry Gutov, 2019/10/19
- Re: Add a separate mode for .dir-locals.el, Alan Mackenzie, 2019/10/19
- Re: Add a separate mode for .dir-locals.el, Dmitry Gutov, 2019/10/19
- Re: Add a separate mode for .dir-locals.el, Eli Zaretskii, 2019/10/20
- Re: Add a separate mode for .dir-locals.el, João Távora, 2019/10/20
- Re: Add a separate mode for .dir-locals.el, Juri Linkov, 2019/10/20
- Re: Add a separate mode for .dir-locals.el, João Távora, 2019/10/20
- Re: Add a separate mode for .dir-locals.el, Dmitry Gutov, 2019/10/21