Subject: Re: bug#16759: CC Mode modes: mode hooks are called twice.

From: Stefan Monnier <[email-masked]>
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