GNU bug report logs - #16759
CC Mode modes: mode hooks are called twice.

Previous Next

Packages: emacs, cc-mode;

Reported by: Alan Mackenzie <acm <at> muc.de>

Date: Fri, 14 Feb 2014 22:21:02 UTC

Severity: normal

Done: Alan Mackenzie <acm <at> muc.de>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 16759 in the body.
You can then email your comments to 16759 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#16759; Package emacs. (Fri, 14 Feb 2014 22:21:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Alan Mackenzie <acm <at> muc.de>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 14 Feb 2014 22:21:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: bug-gnu-emacs <at> gnu.org
Subject: CC Mode modes: mode hooks are called twice.
Date: Fri, 14 Feb 2014 22:09:34 +0000
In C Mode, etc., c-mode-hook, etc. gets called twice at mode
initialisation.  This is bad, since there will be, at least occasionally,
mode hooks which must not be called twice.

The cause of this is that there is an invocation of run-mode-hooks
generated by the macro define-derived-mode as well as an explicit call to
run-mode-hooks which is not at the end of the mode function.

-- 
Alan Mackenzie (Nuremberg, Germany).




Information forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#16759; Package emacs,cc-mode. (Wed, 19 Feb 2014 17:30:03 GMT) Full text and rfc822 format available.

Message #8 received at 16759 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Alan Mackenzie <acm <at> muc.de>
Cc: 16759 <at> debbugs.gnu.org
Subject: Re: bug#16759: CC Mode modes: mode hooks are called twice.
Date: Wed, 19 Feb 2014 12:29:24 -0500
Alan Mackenzie wrote:

> The cause of this is that there is an invocation of run-mode-hooks
> generated by the macro define-derived-mode as well as an explicit call to
> run-mode-hooks which is not at the end of the mode function.

IIUC, this is because you want to run some C-mode stuff after the hooks.
A simple solution would be to add :after-hook to define-derived-mode.
You already did this for define-minor-mode.
It would be good for symmetry/consistency if nothing else, and seems
pre-approved:

http://lists.gnu.org/archive/html/emacs-devel/2012-02/msg00140.html

:)




Information forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#16759; Package emacs,cc-mode. (Wed, 19 Feb 2014 18:50:02 GMT) Full text and rfc822 format available.

Message #11 received at 16759 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Glenn Morris <rgm <at> gnu.org>
Cc: Alan Mackenzie <acm <at> muc.de>, 16759 <at> debbugs.gnu.org
Subject: Re: bug#16759: CC Mode modes: mode hooks are called twice.
Date: Wed, 19 Feb 2014 13:49:43 -0500
>> The cause of this is that there is an invocation of run-mode-hooks
>> generated by the macro define-derived-mode as well as an explicit call to
>> run-mode-hooks which is not at the end of the mode function.
> IIUC, this is because you want to run some C-mode stuff after the hooks.

More specifically, it's always c-update-modeline, AFAICT.
A good solution would be to get rid of it and use something like

  (let ((lighters '("/" (c-electric-flag "l")
                        (c-electric-flag (c-auto-newline "a"))
                        (c-hungry-delete-key "h")
                        (subword-mode "w"))))
    (setq c-mode-options-format
          `(c-electric-flag ,lighters
            (c-hungry-delete-key ,lighters)
             (subword-mode ,lighters)))
    (cond
     ((memq 'c-mode-options-format mode-line-process) nil)
     ((equal "" (car-safe mode-line-process))
      (push 'c-mode-options-format (cdr mode-line-process)))
     (t (setq mode-line-process
              `("" c-mode-options-format ,mode-line-process)))))

> A simple solution would be to add :after-hook to define-derived-mode.
> You already did this for define-minor-mode.
> It would be good for symmetry/consistency if nothing else, and seems
> pre-approved:

I wouldn't say pre-approved.  But, yes, I guess it'd be OK.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#16759; Package emacs,cc-mode. (Wed, 19 Feb 2014 19:04:02 GMT) Full text and rfc822 format available.

Message #14 received at 16759 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Alan Mackenzie <acm <at> muc.de>, 16759 <at> debbugs.gnu.org
Subject: Re: bug#16759: CC Mode modes: mode hooks are called twice.
Date: Wed, 19 Feb 2014 14:03:33 -0500
Stefan Monnier wrote:

>                         (subword-mode "w"))))

BTW, since subword-mode is now a generic minor mode with its own lighter,
I don't believe that cc-mode needs to report its status at all.




Information forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#16759; Package emacs,cc-mode. (Thu, 20 Mar 2014 16:48:01 GMT) Full text and rfc822 format available.

Message #17 received at 16759 <at> debbugs.gnu.org (full text, mbox):

From: Stefan <monnier <at> iro.umontreal.ca>
To: Glenn Morris <rgm <at> gnu.org>
Cc: Alan Mackenzie <acm <at> muc.de>, 16759 <at> debbugs.gnu.org
Subject: Re: bug#16759: CC Mode modes: mode hooks are called twice.
Date: Thu, 20 Mar 2014 12:47:23 -0400
> IIUC, this is because you want to run some C-mode stuff after the hooks.

Note that "after the hooks" also means "after the code of the child
mode" if someone defines a child mode (since hooks get delayed to
after the child mode's code).

The need to "run things after the hooks" is not frequent but is not
exceptional either, so we should provide a good solution for it.
So far, the best solution I know is to use hack-local-variables-hook,
but that is not run if you use M-x c-mode RET.


        Stefan




Reply sent to Alan Mackenzie <acm <at> muc.de>:
You have taken responsibility. (Mon, 09 May 2016 18:32:02 GMT) Full text and rfc822 format available.

Notification sent to Alan Mackenzie <acm <at> muc.de>:
bug acknowledged by developer. (Mon, 09 May 2016 18:32:02 GMT) Full text and rfc822 format available.

Message #22 received at 16759-done <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: 16759-done <at> debbugs.gnu.org
Cc: Alan Mackenzie <acm <at> muc.de>
Subject: Re: bug#16759: CC Mode modes: mode hooks are called twice.
Date: 9 May 2016 18:31:23 -0000
Bug fixed in the master branch.

-- 
Alan Mackenzie (Nuremberg, Germany).







bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 07 Jun 2016 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 9 years and 72 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.