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: First fontification of a buffer happens before font lock is fully initialised. Date: Thu, 23 Feb 2012 11:39:31 +0000 Message-ID: <20120223113931.GA3015@acm.acm> References: <20120125124804.GB3638@acm.acm> <20120125182651.GA3624@acm.acm> <20120204120319.GC3347@acm.acm> <20120207101008.GB3314@acm.acm> <20120208214318.GC31761@acm.acm> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1329997233 31351 80.91.229.3 (23 Feb 2012 11:40:33 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 23 Feb 2012 11:40:33 +0000 (UTC) Cc: Hannu Koivisto , emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Feb 23 12:40:30 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1S0X2D-0000fi-8t for ged-emacs-devel@m.gmane.org; Thu, 23 Feb 2012 12:40:29 +0100 Original-Received: from localhost ([::1]:55978 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S0X2C-0008Ii-Mp for ged-emacs-devel@m.gmane.org; Thu, 23 Feb 2012 06:40:28 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:60459) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S0X20-0008IT-Ls for emacs-devel@gnu.org; Thu, 23 Feb 2012 06:40:26 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S0X1u-0005f9-6s for emacs-devel@gnu.org; Thu, 23 Feb 2012 06:40:16 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:59937 helo=mail.muc.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S0X1t-0005eZ-MF for emacs-devel@gnu.org; Thu, 23 Feb 2012 06:40:10 -0500 Original-Received: (qmail 90942 invoked by uid 3782); 23 Feb 2012 11:40:06 -0000 Original-Received: from acm.muc.de (pD955627E.dip.t-dialin.net [217.85.98.126]) by colin.muc.de (tmda-ofmipd) with ESMTP; Thu, 23 Feb 2012 12:40:02 +0100 Original-Received: (qmail 3838 invoked by uid 1000); 23 Feb 2012 11:39:31 -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: Genre and OS details not recognized. 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:148724 Archived-At: Hello, Stefan. [Quick summary: adding the new parameter ":after-hook" to define-minor-mode, and adapting font-core/font-lock to use it.] On Fri, Feb 10, 2012 at 09:27:20AM -0500, Stefan Monnier wrote: > > + :after-hooks A single lisp form which is evaluated after the mode hooks > > + have been run. It should be quoted. > Don't quote it. OK > > ! ,@(when after-hooks `(,(eval after-hooks))) > And don't call `eval'. OK2. > Also, I'd move the after-hooks code to after the customize-mark-as-set&message. OK3. Here's an amended patch for easy-mmode.el and a patch for font-core/lock which uses the :after-hook param. Should I install it? === modified file 'doc/lispref/modes.texi' *** doc/lispref/modes.texi 2012-02-19 05:54:33 +0000 --- doc/lispref/modes.texi 2012-02-22 20:51:42 +0000 *************** *** 1594,1608 **** @var{place} can also be a cons @code{(@var{get} . @var{set})}, where @var{get} is an expression that returns the current state, and @var{set} is a function of one argument (a state) that sets it. @end table Any other keyword arguments are passed directly to the @code{defcustom} generated for the variable @var{mode}. ! The command named @var{mode} first performs the standard actions such ! as setting the variable named @var{mode} and then executes the ! @var{body} forms, if any. It finishes by running the mode hook ! variable @code{@var{mode}-hook}. @end defmac The initial value must be @code{nil} except in cases where (1) the --- 1594,1613 ---- @var{place} can also be a cons @code{(@var{get} . @var{set})}, where @var{get} is an expression that returns the current state, and @var{set} is a function of one argument (a state) that sets it. + + @item :after-hook @var{after-hook} + This defines a single lisp form which is evaluated after the mode hooks + have run. It should not be quoted. @end table Any other keyword arguments are passed directly to the @code{defcustom} generated for the variable @var{mode}. ! The command named @var{mode} first performs the standard actions such as ! setting the variable named @var{mode} and then executes the @var{body} ! forms, if any. It then runs the mode hook variable ! @code{@var{mode}-hook} and finishes by evaluating any form in ! @code{:after-hook}. @end defmac The initial value must be @code{nil} except in cases where (1) the === modified file 'lisp/emacs-lisp/easy-mmode.el' *** lisp/emacs-lisp/easy-mmode.el 2012-02-07 08:26:54 +0000 --- lisp/emacs-lisp/easy-mmode.el 2012-02-22 20:11:14 +0000 *************** *** 135,140 **** --- 135,142 ---- the new state, and sets it. If you specify a :variable, this function does not define a MODE variable (nor any of the terms used in :variable). + :after-hook A single lisp form which is evaluated after the mode hooks + have been run. It should not be quoted. For example, you could write (define-minor-mode foo-mode \"If enabled, foo on you!\" *************** *** 170,175 **** --- 172,178 ---- (setter nil) ;The function (if any) to set the mode var. (modefun mode) ;The minor mode function name we're defining. (require t) + (after-hook nil) (hook (intern (concat mode-name "-hook"))) (hook-on (intern (concat mode-name "-on-hook"))) (hook-off (intern (concat mode-name "-off-hook"))) *************** *** 197,202 **** --- 200,206 ---- (setq mode variable) (setq mode (car variable)) (setq setter (cdr variable)))) + (:after-hook (setq after-hook (pop body))) (t (push keyw extra-keywords) (push (pop body) extra-keywords)))) (setq keymap-sym (if (and keymap (symbolp keymap)) keymap *************** *** 275,281 **** (not (equal ,last-message (current-message)))) (message ,(format "%s %%sabled" pretty-name) ! (if ,mode "en" "dis")))))) (force-mode-line-update) ;; Return the new setting. ,mode) --- 279,286 ---- (not (equal ,last-message (current-message)))) (message ,(format "%s %%sabled" pretty-name) ! (if ,mode "en" "dis"))))) ! ,@(when after-hook `(,after-hook))) (force-mode-line-update) ;; Return the new setting. ,mode) === modified file 'lisp/font-core.el' *** lisp/font-core.el 2012-01-19 07:21:25 +0000 --- lisp/font-core.el 2012-02-23 11:10:32 +0000 *************** *** 138,143 **** --- 138,144 ---- your own function which is called when `font-lock-mode' is toggled via `font-lock-function'. " nil nil nil + :after-hook (if font-lock-mode (font-lock-initial-fontify)) ;; Don't turn on Font Lock mode if we don't have a display (we're running a ;; batch job) or if the buffer is invisible (the name starts with a space). (when (or noninteractive (eq (aref (buffer-name) 0) ?\s)) === modified file 'lisp/font-lock.el' *** lisp/font-lock.el 2012-02-10 15:59:29 +0000 --- lisp/font-lock.el 2012-02-23 11:15:14 +0000 *************** *** 629,649 **** ;; Shut up the byte compiler. (defvar font-lock-face-attributes)) ; Obsolete but respected if set. (defun font-lock-mode-internal (arg) ;; Turn on Font Lock mode. (when arg (add-hook 'after-change-functions 'font-lock-after-change-function t t) (font-lock-set-defaults) ! (font-lock-turn-on-thing-lock) ! ;; Fontify the buffer if we have to. ! (let ((max-size (font-lock-value-in-major-mode font-lock-maximum-size))) ! (cond (font-lock-fontified ! nil) ! ((or (null max-size) (> max-size (buffer-size))) ! (font-lock-fontify-buffer)) ! (font-lock-verbose ! (message "Fontifying %s...buffer size greater than font-lock-maximum-size" ! (buffer-name)))))) ;; Turn off Font Lock mode. (unless font-lock-mode (remove-hook 'after-change-functions 'font-lock-after-change-function t) --- 629,652 ---- ;; Shut up the byte compiler. (defvar font-lock-face-attributes)) ; Obsolete but respected if set. + (defun font-lock-initial-fontify () + ;; The first fontification after turning the mode on. This must + ;; only be called after the mode hooks have been run. + (let ((max-size (font-lock-value-in-major-mode font-lock-maximum-size))) + (cond (font-lock-fontified + nil) + ((or (null max-size) (> max-size (buffer-size))) + (font-lock-fontify-buffer)) + (font-lock-verbose + (message "Fontifying %s...buffer size greater than font-lock-maximum-size" + (buffer-name)))))) + (defun font-lock-mode-internal (arg) ;; Turn on Font Lock mode. (when arg (add-hook 'after-change-functions 'font-lock-after-change-function t t) (font-lock-set-defaults) ! (font-lock-turn-on-thing-lock)) ;; Turn off Font Lock mode. (unless font-lock-mode (remove-hook 'after-change-functions 'font-lock-after-change-function t) > Stefan -- Alan Mackenzie (Nuremberg, Germany).