unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#16759: CC Mode modes: mode hooks are called twice.
@ 2014-02-14 22:09 Alan Mackenzie
  2014-02-19 17:29 ` Glenn Morris
       [not found] ` <mailman.15156.1392416485.10748.bug-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 6+ messages in thread
From: Alan Mackenzie @ 2014-02-14 22:09 UTC (permalink / raw)
  To: 16759

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).





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#16759: CC Mode modes: mode hooks are called twice.
  2014-02-14 22:09 bug#16759: CC Mode modes: mode hooks are called twice Alan Mackenzie
@ 2014-02-19 17:29 ` Glenn Morris
  2014-02-19 18:49   ` Stefan Monnier
                     ` (2 more replies)
       [not found] ` <mailman.15156.1392416485.10748.bug-gnu-emacs@gnu.org>
  1 sibling, 3 replies; 6+ messages in thread
From: Glenn Morris @ 2014-02-19 17:29 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: 16759

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

:)





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#16759: CC Mode modes: mode hooks are called twice.
  2014-02-19 17:29 ` Glenn Morris
@ 2014-02-19 18:49   ` Stefan Monnier
       [not found]   ` <jwvha7vosnw.fsf-monnier+emacsbugs@gnu.org>
  2014-03-20 16:47   ` Stefan
  2 siblings, 0 replies; 6+ messages in thread
From: Stefan Monnier @ 2014-02-19 18:49 UTC (permalink / raw)
  To: Glenn Morris; +Cc: Alan Mackenzie, 16759

>> 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





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#16759: CC Mode modes: mode hooks are called twice.
       [not found]   ` <jwvha7vosnw.fsf-monnier+emacsbugs@gnu.org>
@ 2014-02-19 19:03     ` Glenn Morris
  0 siblings, 0 replies; 6+ messages in thread
From: Glenn Morris @ 2014-02-19 19:03 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Alan Mackenzie, 16759

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.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#16759: CC Mode modes: mode hooks are called twice.
  2014-02-19 17:29 ` Glenn Morris
  2014-02-19 18:49   ` Stefan Monnier
       [not found]   ` <jwvha7vosnw.fsf-monnier+emacsbugs@gnu.org>
@ 2014-03-20 16:47   ` Stefan
  2 siblings, 0 replies; 6+ messages in thread
From: Stefan @ 2014-03-20 16:47 UTC (permalink / raw)
  To: Glenn Morris; +Cc: Alan Mackenzie, 16759

> 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





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#16759: CC Mode modes: mode hooks are called twice.
       [not found] ` <mailman.15156.1392416485.10748.bug-gnu-emacs@gnu.org>
@ 2016-05-09 18:31   ` Alan Mackenzie
  0 siblings, 0 replies; 6+ messages in thread
From: Alan Mackenzie @ 2016-05-09 18:31 UTC (permalink / raw)
  To: 16759-done; +Cc: Alan Mackenzie

Bug fixed in the master branch.

-- 
Alan Mackenzie (Nuremberg, Germany).








^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-05-09 18:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-14 22:09 bug#16759: CC Mode modes: mode hooks are called twice Alan Mackenzie
2014-02-19 17:29 ` Glenn Morris
2014-02-19 18:49   ` Stefan Monnier
     [not found]   ` <jwvha7vosnw.fsf-monnier+emacsbugs@gnu.org>
2014-02-19 19:03     ` Glenn Morris
2014-03-20 16:47   ` Stefan
     [not found] ` <mailman.15156.1392416485.10748.bug-gnu-emacs@gnu.org>
2016-05-09 18:31   ` Alan Mackenzie

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).