From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Re: Redundant (harmful) duplication of run-hooks in define-globalized-minor-mode [patch] Date: Mon, 14 Jan 2013 16:30:03 +0000 Message-ID: <20130114163003.GC3274@acm.acm> References: <20130113192854.GA4853@acm.acm> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1358181424 4720 80.91.229.3 (14 Jan 2013 16:37:04 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 14 Jan 2013 16:37:04 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jan 14 17:37:23 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Tun2I-0007B9-HI for ged-emacs-devel@m.gmane.org; Mon, 14 Jan 2013 17:37:22 +0100 Original-Received: from localhost ([::1]:52574 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tun22-0005t9-6I for ged-emacs-devel@m.gmane.org; Mon, 14 Jan 2013 11:37:06 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:49895) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tun1u-0005t0-R4 for emacs-devel@gnu.org; Mon, 14 Jan 2013 11:37:05 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tun1o-0005Js-I3 for emacs-devel@gnu.org; Mon, 14 Jan 2013 11:36:58 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:38531 helo=mail.muc.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tun1o-0005Ji-88 for emacs-devel@gnu.org; Mon, 14 Jan 2013 11:36:52 -0500 Original-Received: (qmail 73703 invoked by uid 3782); 14 Jan 2013 16:36:48 -0000 Original-Received: from acm.muc.de (pD951A9EE.dip.t-dialin.net [217.81.169.238]) by colin.muc.de (tmda-ofmipd) with ESMTP; Mon, 14 Jan 2013 17:36:47 +0100 Original-Received: (qmail 2154 invoked by uid 1000); 14 Jan 2013 16:30:03 -0000 Content-Disposition: inline In-Reply-To: <20130113192854.GA4853@acm.acm> User-Agent: Mutt/1.5.21 (2010-09-15) X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-detected-operating-system: by eggs.gnu.org: FreeBSD 8.x X-Received-From: 193.149.48.1 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 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-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:156341 Archived-At: Hi, Emacs. On Sun, Jan 13, 2013 at 07:28:54PM +0000, Alan Mackenzie wrote: > The situation here is the direct cause of bug #11152, where in CC Mode, > doc comments whose fontification is specified in a mode hook don't get > fontified properly, or at all. It would be good to fix this bug for > Emacs 24.3. > In define-globalized-minor-mode L72-75, the newly defined -enable- > function is added to both the following hooks: > change-major-mode-after-body-hook > after-change-major-mode-hook > . (These hooks are run before and after the major mode hook.) > It seems the hacker who formulated this macro was undecided whether to > run the -enable- function before or after the mode hooks, so decided > upon both as a compromise. This isn't harmless. > In particular, running `global-font-lock-mode-enable-in-buffers' before > the objc-mode-hook causes a one-time font-lock-keywords initialisation > to happen before a critical initialisation has been performed by that > hook. > Can some means be found so that `font-lock-mode' isn't called twice? > (For that matter, `global-hi-lock-mode-enable-in-buffers' doesn't need > calling twice, either.) Such a means might be the addition of another > parameter to define-globalized-minor-mode specifying when the -enable- > call should take place. I propose to amend define-globalized-minor-mode such that the generated -enable- function gets added to precisely one of the following hooks, not both: change-major-mode-after-body-hook after-change-major-mode-hook , the latter one by default. To change this default, the new keyword-parameter :call-before-hook is introduced. I think this amendment should go into Emacs 24.3 (it "solves" bug #11152). There are 6 invocations of define-globalized-minor-mode in Emacs, 1 global-visual-line-mode 2 global-hi-lock-mode 3 global-font-lock-mode 4 global-cwarn-mode 5 global-linum-mode 6 global-highlight-changes-mode . 2 and 3 appear to work fine with the amended macro. I haven't tested the others. Here is the patch to the .el file (another will be needed for NEWS): === modified file 'lisp/emacs-lisp/easy-mmode.el' *** lisp/emacs-lisp/easy-mmode.el 2013-01-01 09:11:05 +0000 --- lisp/emacs-lisp/easy-mmode.el 2013-01-14 15:50:50 +0000 *************** *** 329,335 **** and that should try to turn MODE on if applicable for that buffer. KEYS is a list of CL-style keyword arguments. As the minor mode defined by this function is always global, any :global keyword is ! ignored. Other keywords have the same meaning as in `define-minor-mode', which see. In particular, :group specifies the custom group. The most useful keywords are those that are passed on to the `defcustom'. It normally makes no sense to pass the :lighter --- 329,338 ---- and that should try to turn MODE on if applicable for that buffer. KEYS is a list of CL-style keyword arguments. As the minor mode defined by this function is always global, any :global keyword is ! ignored. If :call-before-hook is present with a non-nil argument, TURN-ON ! will be called before running the major mode's hook, otherwise it will be ! called afterwards. ! Other keywords have the same meaning as in `define-minor-mode', which see. In particular, :group specifies the custom group. The most useful keywords are those that are passed on to the `defcustom'. It normally makes no sense to pass the :lighter *************** *** 346,351 **** --- 349,355 ---- (pretty-name (easy-mmode-pretty-mode-name mode)) (pretty-global-name (easy-mmode-pretty-mode-name global-mode)) (group nil) + (call-before-hook nil) (extra-keywords nil) (MODE-buffers (intern (concat global-mode-name "-buffers"))) (MODE-enable-in-buffers *************** *** 362,367 **** --- 366,372 ---- (pcase keyw (`:group (setq group (nconc group (list :group (pop keys))))) (`:global (setq keys (cdr keys))) + (`:call-before-hook (setq call-before-hook (pop keys))) (_ (push keyw extra-keywords) (push (pop keys) extra-keywords)))) (unless group *************** *** 394,402 **** ;; Setup hook to handle future mode changes and new buffers. (if ,global-mode (progn ! (add-hook 'after-change-major-mode-hook ! ',MODE-enable-in-buffers) ! (add-hook 'change-major-mode-after-body-hook ',MODE-enable-in-buffers) (add-hook 'find-file-hook ',MODE-check-buffers) (add-hook 'change-major-mode-hook ',MODE-cmhh)) --- 399,407 ---- ;; Setup hook to handle future mode changes and new buffers. (if ,global-mode (progn ! (add-hook ',(if call-before-hook ! 'change-major-mode-after-body-hook ! 'after-change-major-mode-hook) ',MODE-enable-in-buffers) (add-hook 'find-file-hook ',MODE-check-buffers) (add-hook 'change-major-mode-hook ',MODE-cmhh)) -- Alan Mackenzie (Nuremberg, Germany).