[Top][All Lists]

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

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

From: Eli Zaretskii
Subject: Re: Add a separate mode for .dir-locals.el
Date: Sat, 19 Oct 2019 17:03:41 +0300

> From: João Távora <address@hidden>
> Date: Sat, 19 Oct 2019 14:36:21 +0100
> Cc: Clément Pit-Claudel <address@hidden>, 
>       Stefan Monnier <address@hidden>, emacs-devel <address@hidden>
> On Sat, Oct 19, 2019 at 12:56 PM Eli Zaretskii <address@hidden> wrote:
> > I thought it was just a guess, and I wanted us to be sure.  Are we
> > sure the problem is triggered by an attempt to invoke the byte
> > compiler on the file?
> It was a guess because another Flymake backend, such as checkdoc, could
> have been producing similar bogus data.  I also didn't try Flycheck.
> Anyway the guess is confirmed for Flymake, though apparently for
> Flycheck the problem also extends to its checkdoc checker.

OK, thanks.  In that case, my proposed fix is below.

> > > > Creating a major mode for this issue is like shooting sparrows with
> > > > cannons.  Why not extend emacs-lisp-mode to DTRT with
> > > > data-that-doesn't-make-sense-as-code instead?
> > > That is _exactly_ what Clément proposed in his original patch.
> > My understanding is that Clément proposed a new major mode.
> Yes, he did.  By "extension" (to a major mode) I understood
> "derivation", as in basic OO's "Dog extends Mammal extends Animal", so a
> new major mode.  Now I see you didn't mean that.

Indeed, "extend" is ambiguous in this context, sorry about not being
more clear.

> If you mean just putting if-guards in emacs-lisp-mode, then I would't
> call it an "extension", really.

No, I wouldn't call it "extension", either.  I meant to teach
elisp-mode to recognize files that have only ELisp data structures in
them, and adapting itself to such files.  I think the distinction is
mostly on the syntax level, so I'd expect it to be detected on that
level.  Since use of such files is inherent in customizing Emacs, it
would IMO make sense to have elisp-mode support them.

> But never mind nomenclature, the point
> is that, it (1) doesn't avoid Clément's need to put the very same
> if-guards in his Flycheck code, (2) isn't reusable to work for other
> file types (3) just doesn't work for other stuff that people put in
> emacs-lisp-mode-hook, for which we have no possible way to if-guard
> against.  It is an anti-pattern, precisely the one that simple
> inheritance is designed to avoid.

I agree that this is not a complete solution, but I don't think we
have a good understanding of the more general problem at this time,
and producing a major mode that needs to be manually turned on in any
file but .dir-locals.el doesn't sound like a great idea to me,
especially as I'd like elisp-mode to support such files as a built-in
feature.  The latter would be in-line with our other major modes,
which in most cases turn themselves on automatically, given some
tell-tale indications in the file's contents or its name.

Here's the patch I propose to fix this problem for Flymake:

diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
index 516e4f9..3e4a4c0 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -256,8 +256,20 @@ emacs-lisp-mode
   (setq-local project-vc-external-roots-function #'elisp-load-path-roots)
   (add-hook 'completion-at-point-functions
             #'elisp-completion-at-point nil 'local)
-  (add-hook 'flymake-diagnostic-functions #'elisp-flymake-checkdoc nil t)
-  (add-hook 'flymake-diagnostic-functions #'elisp-flymake-byte-compile nil t))
+  ;; .dir-locals.el fileswill cause the byte-compiler and checkdoc
+  ;; emit spurious warnings, because they don't follow the conventions
+  ;; of Emacs Lisp sources.  Until we have a better fix, like teach
+  ;; elisp-mode about files that only hold data strucvtures, we
+  ;; disable the ELisp Flymake backend for these files.
+  (unless
+      (let* ((bfname (buffer-file-name))
+             (fname (and (stringp bfname) (file-name-nondirectory bfname))))
+        (or (not (stringp fname))
+            (string-match "\\`\\.#" fname)
+            (string-equal dir-locals-file fname)))
+    (add-hook 'flymake-diagnostic-functions #'elisp-flymake-checkdoc nil t)
+    (add-hook 'flymake-diagnostic-functions
+              #'elisp-flymake-byte-compile nil t)))
 ;; Font-locking support.

reply via email to

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