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: Tue, 15 Jan 2013 14:08:55 +0000 Message-ID: <20130115140855.GA3430@acm.acm> References: <20130113192854.GA4853@acm.acm> <20130114163003.GC3274@acm.acm> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1358259351 585 80.91.229.3 (15 Jan 2013 14:15:51 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 15 Jan 2013 14:15:51 +0000 (UTC) Cc: Chong Yidong , emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jan 15 15:16:08 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 1Tv7J7-0002lF-2y for ged-emacs-devel@m.gmane.org; Tue, 15 Jan 2013 15:16:05 +0100 Original-Received: from localhost ([::1]:58861 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tv7Iq-00071x-El for ged-emacs-devel@m.gmane.org; Tue, 15 Jan 2013 09:15:48 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:47477) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tv7In-00071E-3O for emacs-devel@gnu.org; Tue, 15 Jan 2013 09:15:46 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tv7Il-0002dT-BC for emacs-devel@gnu.org; Tue, 15 Jan 2013 09:15:44 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:63052 helo=mail.muc.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tv7Ik-0002cr-Uk for emacs-devel@gnu.org; Tue, 15 Jan 2013 09:15:43 -0500 Original-Received: (qmail 56467 invoked by uid 3782); 15 Jan 2013 14:15:41 -0000 Original-Received: from acm.muc.de (pD951B697.dip.t-dialin.net [217.81.182.151]) by colin.muc.de (tmda-ofmipd) with ESMTP; Tue, 15 Jan 2013 15:15:39 +0100 Original-Received: (qmail 4294 invoked by uid 1000); 15 Jan 2013 14:08:55 -0000 Content-Disposition: inline In-Reply-To: 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:156380 Archived-At: Hi, Stefan. On Mon, Jan 14, 2013 at 09:12:15PM -0500, Stefan Monnier wrote: > > ! (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) > I think we first need to understand why we currently use both. This is difficult. The change was in revision 106202. Previously, MODE-enable-in-buffers was simply add-hooked into after-change-major-mode-hook. The relevant ChangeLog entry runs: + 2011-10-27 Chong Yidong + + * subr.el (change-major-mode-after-body-hook): New hook. + (run-mode-hooks): Run it. + + * emacs-lisp/easy-mmode.el (define-globalized-minor-mode): Use + change-major-mode-before-body-hook. + + * simple.el (fundamental-mode): + * emacs-lisp/derived.el (define-derived-mode): Revert 2010-04-28 + change introducing fundamental-mode-hook. + The new hook change-major-mode-after-body-hook came into existence after a naming competition in the thread starting at: From: Christoph Scholtes To: emacs-devel@gnu.org Subject: Fundamental mode vs. special mode Date: Sat, 22 Oct 2011 14:13:03 -0600 Message-ID: <86sjmkvl80.fsf@googlemail.com> That thread mainly discussed the propriety of fundamental-mode-hook, and prompted Yidong to remove it, putting change-major-mode-after-body-hook in its place. Here is his email proposing this: > I propose to remove the fundamental-mode-hook variable introduced in > that change, and introduce `run-mode-hooks-hook'[*], which > `run-mode-hooks' runs before all the other hooks. Then minor modes > can use `run-mode-hooks-hook', and the "turning off global modes" > feature will be available to non-derived modes. [*] renamed to `change-major-mode-after-body-hook' before implementation. > Also, the MODE-enable-in-buffers function should enable the mode only > once, normally, even if called via both hooks. I think that's true. My problem is that font-lock-mode is being called too soon, before the mode has been fully set up by the major mode hook. That first call of f-l-m sets up font-lock-keywords to include entries for fontifying "doc comments". A buffer local variable specifies what sort of doc comments. It has to be admitted that the CC Mode code here isn't totally correct; a complete solution to this bug probably involves making font-lock-keywords buffer local when doc comments are specified. I don't want to make this change (which would be somewhat involved) before Emacs 24.3. ;-( Postponing `font-lock-mode' until after the mode hook seems a safer bet at the moment. > So if you see a problem, maybe it's because (eq ,MODE-major-mode > major-mode) is not true the second time around, i.e. because > `major-mode' has changed between the two hooks. Is that the case? > If so, why? > Stefan -- Alan Mackenzie (Nuremberg, Germany).