From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Add a separate mode for .dir-locals.el Date: Sat, 19 Oct 2019 17:03:41 +0300 Message-ID: <83bluc7rya.fsf@gnu.org> References: <2058328b-aee5-8cb1-2659-a793e1354517@mit.edu> <835zkndcz4.fsf@gnu.org> <83ftjrbjhm.fsf@gnu.org> <83ftjr9sx4.fsf@gnu.org> <83eezb9s5b.fsf@gnu.org> <83bluf9qgb.fsf@gnu.org> <835zkn9o01.fsf@gnu.org> <83lfti8ovn.fsf@gnu.org> <83d0eu8c80.fsf@gnu.org> <83lfth6p0y.fsf@gnu.org> <83h8456jaj.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="240157"; mail-complaints-to="usenet@blaine.gmane.org" Cc: cpitclaudel@gmail.com, monnier@iro.umontreal.ca, emacs-devel@gnu.org To: =?utf-8?B?Sm/Do28gVMOhdm9yYQ==?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Oct 19 16:08:39 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iLpPK-0010MQ-GH for ged-emacs-devel@m.gmane.org; Sat, 19 Oct 2019 16:08:38 +0200 Original-Received: from localhost ([::1]:55466 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iLpPJ-0002wZ-CM for ged-emacs-devel@m.gmane.org; Sat, 19 Oct 2019 10:08:37 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40580) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iLpKk-0008BK-N3 for emacs-devel@gnu.org; Sat, 19 Oct 2019 10:03:56 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:35912) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1iLpKk-00081C-Hb; Sat, 19 Oct 2019 10:03:54 -0400 Original-Received: from [176.228.60.248] (port=1074 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1iLpKj-0005kp-QZ; Sat, 19 Oct 2019 10:03:54 -0400 In-reply-to: (message from =?utf-8?B?Sm/Do28gVMOhdm9yYQ==?= on Sat, 19 Oct 2019 14:36:21 +0100) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:241232 Archived-At: > From: João Távora > Date: Sat, 19 Oct 2019 14:36:21 +0100 > Cc: Clément Pit-Claudel , > Stefan Monnier , emacs-devel > > On Sat, Oct 19, 2019 at 12:56 PM Eli Zaretskii 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.