]> code.delx.au - gnu-emacs/commitdiff
Add new parameter :after-hook to define-minor-mode. Use this in the
authorAlan Mackenzie <acm@muc.de>
Thu, 23 Feb 2012 18:51:22 +0000 (18:51 +0000)
committerAlan Mackenzie <acm@muc.de>
Thu, 23 Feb 2012 18:51:22 +0000 (18:51 +0000)
definition of font-lock-mode.

doc/lispref/ChangeLog
doc/lispref/modes.texi
lisp/ChangeLog
lisp/emacs-lisp/easy-mmode.el
lisp/font-core.el
lisp/font-lock.el

index 4c69a309ca8dad872afa3e7a59ae4aab89df0aec..151a6388c7f4ad4c39346576f5f77bfb5c98751e 100644 (file)
@@ -1,3 +1,8 @@
+2012-02-23  Alan Mackenzie  <acm@muc.de>
+
+       * modes.texi (Defining Minor Modes): Document the new keyword
+       :after-hook.
+
 2012-02-21  Chong Yidong  <cyd@gnu.org>
 
        * files.texi (Files): Mention magic file names as arguments.
index 09a96f23c5ee561f32df240d9887d5f615259877..a4ee6f8327f88096af4df09d8de20399bae6b8a9 100644 (file)
@@ -1594,15 +1594,20 @@ anything that can be used with the @code{setf} function
 @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 finishes by running the mode hook
-variable @code{@var{mode}-hook}.
+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
index d5951bbbe2612d8217e035adb6122dfbcffeee60..798df418e7d3f2a37f38e1ddafbc26774bfd8c29 100644 (file)
@@ -1,3 +1,15 @@
+2012-02-23  Alan Mackenzie  <acm@muc.de>
+
+       * emacs-lisp/easy-mmode.el (define-minor-mode): Add extra
+       parameter "after-hook:" to allow the expansion to run code after
+       the execution of the mode hooks.
+
+       * font-lock.el (font-lock-initial-fontify): New function extracted
+       from font-lock-mode-interal.
+
+       * font-core.el (font-lock-mode): call font-lock-initial-fontify in
+       :after-hook.
+
 2012-02-23  Stefan Monnier  <monnier@iro.umontreal.ca>
 
        * minibuffer.el: Make sure cycling is reset upon edit with icomplete.el.
index dbacba6cd29febe0d272c9c6056b3cb33ee025ac..88698a1f0697bb8f1fe3c224dc417737a4aeed7e 100644 (file)
@@ -135,6 +135,8 @@ BODY contains code to execute each time the mode is enabled or disabled.
                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,6 +172,7 @@ For example, you could write
          (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,6 +200,7 @@ For example, you could write
              (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,7 +279,8 @@ the mode if ARG is omitted or nil, and toggle it if ARG is `toggle'.
                               (not (equal ,last-message
                                           (current-message))))
                    (message ,(format "%s %%sabled" pretty-name)
-                            (if ,mode "en" "dis"))))))
+                            (if ,mode "en" "dis")))))
+          ,@(when after-hook `(,after-hook)))
         (force-mode-line-update)
         ;; Return the new setting.
         ,mode)
index f6701c0c79f1171a1a2cd3848b09d717c9b92a31..9b655319bc966f4c30d7ea193640a2ca102a5819 100644 (file)
@@ -138,6 +138,7 @@ The above is the default behavior of `font-lock-mode'; you may specify
 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))
index 9f9445bdea96e01d42636d3b9fb24ffc72fffd51..a65a2c94c7dd6bad9439efc73d035b111b8ce88d 100644 (file)
@@ -629,21 +629,24 @@ Major/minor modes can set this variable if they know which option applies.")
   ;; 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)
-    ;; 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))))))
+    (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)