unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "João Távora" <joaotavora@gmail.com>
To: Alan Mackenzie <acm@muc.de>
Cc: eliz@gnu.org, npostavs@users.sourceforge.net, sdl.web@gmail.com,
	monnier@iro.umontreal.ca, emacs-devel@gnu.org
Subject: Re: [PATCH] Flymake support for C/C++
Date: Sat, 02 Jun 2018 19:13:59 +0100	[thread overview]
Message-ID: <87h8mlt5so.fsf@gmail.com> (raw)
In-Reply-To: <20180602103317.GA4392@ACM> (Alan Mackenzie's message of "Sat, 2 Jun 2018 10:33:17 +0000")

Hi Alan,

Alan Mackenzie <acm@muc.de> writes:

>> Yes. No problem. Will change to flymake-cc.el
> And take all the symbol names out of CC Mode's namespace, please?

Yes, certainly.

> And the setup is also done once per major mode call.  At the moment I
> can't see why these are distinct.  I'll try reading some earlier posts
> again, maybe this will help.

I think Stefan provided a fine example with font-lock.

> The flymake hook which would be put into c-mode-common-hook should be
> designed such that it doesn't matter whether it is executed before or
> after the user's other hook functions.  A user doing something like
> removing something from flymake-diagnostic-functions will surely be doing
> this in flymake-mode-hook, no?

The "hook" put into the hook is a lisp expression, right? Well it
happens that this lisp expression is itself adding something to another,
completely different hook. And when adding things to hooks, order
matters. There is currently no (practival) way to say "add this to the
beginning of a hook so that, no matter what the user or other libraries
do, it is always the first element".

> Hook variables get changed with add-hook and remove-hook.  Anybody using
> setq for this has problems anyway.

I agree. But I'd rather not be the one introducing problems for these
poor souls.

> Calling flymake directly from C Mode would very much be an exception.
> This would go against the fundamental architecture of Emacs.

I agree. But we're not calling into it in any way.

> Cooks should use hooks.

You should thank me for setting you up such a fine maxim :-)

> And just a small point, your proposed patch is lacking clauses like
>    (if (boundp 'flymake-diagnostic-functions) ....)
> to check that flymake mode actually exists, and an assignment to it won't
> throw an error if it doesn't exist.

The boundp call is *not* needed at all. And perhaps this is the source
of our misunderstanding: `add-hook' is especially designed to throw
these errors and to work before or after the hook variable is defined.

So, forgoing my beloved broccoli metaphor:

   (add-hook 'flymake-diagnostic-functions 'flymake-whatever nil t)

to any major-mode in emacs and not break the call to that mode
function. It's only when flymake-mode starts in that buffer that we'll
see its effects.  The dependency is in fact the reverse. It's flymake
that is now susceptible to any mishandling of that line in cc-mode.el

> c-mode-common-hook should, indeed must, be nil on Emacs -Q.  And flymake
> mode must equally remain disabled until explicitly enabled (e.g. by a
> user customisation).  The whole point of -Q is to get an uncustomised
> vanilla Emacs.

In this last-paragraph, we are violent agreement, word for word. 

Let's summarize. I'd to make it so that:

  Emacs -Q
  visit a .c file
  M-x flymake-mode

starts Flymake suitably in that buffer. For this I'd need to add this
line:

  (add-hook 'flymake-diagnostic-functions 'flymake-cc nil t)

to a common point in cc-mode.el. That is, in my humble opinion, the
simplest alternative, and the one I've taken with all other major modes.

Alternatively, I can add to a hook that (a) does *not* need to be nil on
Emacs -Q and (b) is run once every time a buffer is put into the major
mode cc-mode, after kill-all-local-variables.  As it seems,
c-common-mode-hook fits (b) but not (a). So I ask if there is any such
hook in cc-model.el that fits both (a) and (b)?

I see `c-initialization-hook'. I see it run from c-initialize-cc-mode,
but not unconditionally. I cannot parse the exact conditions when it
runs, but perhaps you can. Does it fit (b) and/or (a)?

João



  parent reply	other threads:[~2018-06-02 18:13 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-12 15:09 [PATCH] Flymake support for C/C++ João Távora
2017-10-12 15:50 ` Mark Oteiza
2017-10-12 17:50 ` Alan Mackenzie
2017-10-12 18:45   ` Stefan Monnier
2017-10-12 20:45     ` Alan Mackenzie
2017-10-12 21:03       ` Stefan Monnier
2017-10-13  6:28       ` Eli Zaretskii
2017-10-12 18:46   ` João Távora
2017-10-12 20:39     ` Alan Mackenzie
2017-10-12 21:05       ` Stefan Monnier
2017-10-12 21:24       ` João Távora
2018-06-01 21:07         ` Alan Mackenzie
2018-06-01 21:54           ` João Távora
2018-06-01 22:08             ` Stefan Monnier
2018-06-01 23:23               ` Rolf Ade
2018-06-02 10:33             ` Alan Mackenzie
2018-06-02 14:44               ` Stefan Monnier
2018-06-02 18:13               ` João Távora [this message]
2018-06-03 15:45                 ` Alan Mackenzie
2018-06-03 16:28                   ` João Távora
2018-06-03 16:43                     ` Alan Mackenzie
2018-06-03 17:02                       ` João Távora
2018-06-02 17:16           ` Stefan Monnier
2018-06-02 15:26   ` Stefan Monnier
2018-06-03 13:44     ` Alan Mackenzie
2017-10-14  1:34 ` Richard Stallman
2017-10-14  7:10   ` Reuben Thomas
2017-10-14  7:58     ` Sami Kerola
2017-10-14  8:00     ` Eli Zaretskii
2017-10-14  8:15       ` Reuben Thomas
2017-10-14  8:22         ` Dmitry Gutov
2017-10-14  8:29           ` Reuben Thomas
2017-10-14 10:36             ` Eli Zaretskii
2017-10-14 11:22               ` Reuben Thomas
2017-10-14  8:33         ` Eli Zaretskii
2017-10-17 10:53           ` Phillip Lord
2017-10-17 10:56             ` Reuben Thomas
2017-10-18  4:03               ` Richard Stallman
2017-10-18 10:18                 ` Reuben Thomas
2017-10-19  3:26                   ` Richard Stallman
2017-10-19  7:38                     ` Reuben Thomas
2017-10-22 23:18                       ` Richard Stallman
2017-10-22 23:23                         ` Reuben Thomas
2017-10-24  4:12                           ` Richard Stallman
2017-10-24  9:45                             ` Reuben Thomas
2017-10-24  9:48                               ` Dmitry Gutov
2017-10-24  9:52                                 ` Reuben Thomas
2017-10-24  9:57                                   ` Dmitry Gutov
2017-10-24 10:07                                     ` Reuben Thomas
2017-10-24 10:21                                       ` Dmitry Gutov
2017-10-24 10:28                                         ` Reuben Thomas
2017-10-24 15:44                                   ` Stefan Monnier
2017-10-25 19:30                               ` Richard Stallman
2017-10-27  0:43                                 ` Reuben Thomas
2017-10-28 21:47                                   ` Richard Stallman
2017-10-18 12:16           ` Clément Pit-Claudel
2017-10-18 17:30             ` John Wiegley
2017-10-14 13:55         ` Stefan Monnier
2017-10-14  9:33     ` João Távora
2017-10-14 10:56       ` guillaume papin
2017-10-14 16:29         ` João Távora
2017-10-14 16:36           ` Reuben Thomas
2017-10-18 12:22           ` Clément Pit-Claudel
2017-10-18 14:26             ` João Távora
2017-10-14  9:29   ` João Távora

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87h8mlt5so.fsf@gmail.com \
    --to=joaotavora@gmail.com \
    --cc=acm@muc.de \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=npostavs@users.sourceforge.net \
    --cc=sdl.web@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).