aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2012-02-23 18:51:22 +0000
committerAlan Mackenzie2012-02-23 18:51:22 +0000
commit2cb228f753fbaea3a86dfc1fd57b61db13624a2d (patch)
treef9f55e68442986ba10b4a25129855beec6b450d2
parentb2e4ca7d12b306cd15d4ec24ce7749db56729e2b (diff)
downloademacs-2cb228f753fbaea3a86dfc1fd57b61db13624a2d.tar.gz
emacs-2cb228f753fbaea3a86dfc1fd57b61db13624a2d.zip
Add new parameter :after-hook to define-minor-mode. Use this in the
definition of font-lock-mode.
-rw-r--r--doc/lispref/ChangeLog5
-rw-r--r--doc/lispref/modes.texi13
-rw-r--r--lisp/ChangeLog12
-rw-r--r--lisp/emacs-lisp/easy-mmode.el7
-rw-r--r--lisp/font-core.el1
-rw-r--r--lisp/font-lock.el23
6 files changed, 46 insertions, 15 deletions
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index 4c69a309ca8..151a6388c7f 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,3 +1,8 @@
12012-02-23 Alan Mackenzie <acm@muc.de>
2
3 * modes.texi (Defining Minor Modes): Document the new keyword
4 :after-hook.
5
12012-02-21 Chong Yidong <cyd@gnu.org> 62012-02-21 Chong Yidong <cyd@gnu.org>
2 7
3 * files.texi (Files): Mention magic file names as arguments. 8 * files.texi (Files): Mention magic file names as arguments.
diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index 09a96f23c5e..a4ee6f8327f 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -1594,15 +1594,20 @@ anything that can be used with the @code{setf} function
1594@var{place} can also be a cons @code{(@var{get} . @var{set})}, 1594@var{place} can also be a cons @code{(@var{get} . @var{set})},
1595where @var{get} is an expression that returns the current state, 1595where @var{get} is an expression that returns the current state,
1596and @var{set} is a function of one argument (a state) that sets it. 1596and @var{set} is a function of one argument (a state) that sets it.
1597
1598@item :after-hook @var{after-hook}
1599This defines a single lisp form which is evaluated after the mode hooks
1600have run. It should not be quoted.
1597@end table 1601@end table
1598 1602
1599Any other keyword arguments are passed directly to the 1603Any other keyword arguments are passed directly to the
1600@code{defcustom} generated for the variable @var{mode}. 1604@code{defcustom} generated for the variable @var{mode}.
1601 1605
1602The command named @var{mode} first performs the standard actions such 1606The command named @var{mode} first performs the standard actions such as
1603as setting the variable named @var{mode} and then executes the 1607setting the variable named @var{mode} and then executes the @var{body}
1604@var{body} forms, if any. It finishes by running the mode hook 1608forms, if any. It then runs the mode hook variable
1605variable @code{@var{mode}-hook}. 1609@code{@var{mode}-hook} and finishes by evaluating any form in
1610@code{:after-hook}.
1606@end defmac 1611@end defmac
1607 1612
1608 The initial value must be @code{nil} except in cases where (1) the 1613 The initial value must be @code{nil} except in cases where (1) the
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index d5951bbbe26..798df418e7d 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,15 @@
12012-02-23 Alan Mackenzie <acm@muc.de>
2
3 * emacs-lisp/easy-mmode.el (define-minor-mode): Add extra
4 parameter "after-hook:" to allow the expansion to run code after
5 the execution of the mode hooks.
6
7 * font-lock.el (font-lock-initial-fontify): New function extracted
8 from font-lock-mode-interal.
9
10 * font-core.el (font-lock-mode): call font-lock-initial-fontify in
11 :after-hook.
12
12012-02-23 Stefan Monnier <monnier@iro.umontreal.ca> 132012-02-23 Stefan Monnier <monnier@iro.umontreal.ca>
2 14
3 * minibuffer.el: Make sure cycling is reset upon edit with icomplete.el. 15 * minibuffer.el: Make sure cycling is reset upon edit with icomplete.el.
diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el
index dbacba6cd29..88698a1f069 100644
--- a/lisp/emacs-lisp/easy-mmode.el
+++ b/lisp/emacs-lisp/easy-mmode.el
@@ -135,6 +135,8 @@ BODY contains code to execute each time the mode is enabled or disabled.
135 the new state, and sets it. If you specify a :variable, 135 the new state, and sets it. If you specify a :variable,
136 this function does not define a MODE variable (nor any of 136 this function does not define a MODE variable (nor any of
137 the terms used in :variable). 137 the terms used in :variable).
138:after-hook A single lisp form which is evaluated after the mode hooks
139 have been run. It should not be quoted.
138 140
139For example, you could write 141For example, you could write
140 (define-minor-mode foo-mode \"If enabled, foo on you!\" 142 (define-minor-mode foo-mode \"If enabled, foo on you!\"
@@ -170,6 +172,7 @@ For example, you could write
170 (setter nil) ;The function (if any) to set the mode var. 172 (setter nil) ;The function (if any) to set the mode var.
171 (modefun mode) ;The minor mode function name we're defining. 173 (modefun mode) ;The minor mode function name we're defining.
172 (require t) 174 (require t)
175 (after-hook nil)
173 (hook (intern (concat mode-name "-hook"))) 176 (hook (intern (concat mode-name "-hook")))
174 (hook-on (intern (concat mode-name "-on-hook"))) 177 (hook-on (intern (concat mode-name "-on-hook")))
175 (hook-off (intern (concat mode-name "-off-hook"))) 178 (hook-off (intern (concat mode-name "-off-hook")))
@@ -197,6 +200,7 @@ For example, you could write
197 (setq mode variable) 200 (setq mode variable)
198 (setq mode (car variable)) 201 (setq mode (car variable))
199 (setq setter (cdr variable)))) 202 (setq setter (cdr variable))))
203 (:after-hook (setq after-hook (pop body)))
200 (t (push keyw extra-keywords) (push (pop body) extra-keywords)))) 204 (t (push keyw extra-keywords) (push (pop body) extra-keywords))))
201 205
202 (setq keymap-sym (if (and keymap (symbolp keymap)) keymap 206 (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'.
275 (not (equal ,last-message 279 (not (equal ,last-message
276 (current-message)))) 280 (current-message))))
277 (message ,(format "%s %%sabled" pretty-name) 281 (message ,(format "%s %%sabled" pretty-name)
278 (if ,mode "en" "dis")))))) 282 (if ,mode "en" "dis")))))
283 ,@(when after-hook `(,after-hook)))
279 (force-mode-line-update) 284 (force-mode-line-update)
280 ;; Return the new setting. 285 ;; Return the new setting.
281 ,mode) 286 ,mode)
diff --git a/lisp/font-core.el b/lisp/font-core.el
index f6701c0c79f..9b655319bc9 100644
--- a/lisp/font-core.el
+++ b/lisp/font-core.el
@@ -138,6 +138,7 @@ The above is the default behavior of `font-lock-mode'; you may specify
138your own function which is called when `font-lock-mode' is toggled via 138your own function which is called when `font-lock-mode' is toggled via
139`font-lock-function'. " 139`font-lock-function'. "
140 nil nil nil 140 nil nil nil
141 :after-hook (if font-lock-mode (font-lock-initial-fontify))
141 ;; Don't turn on Font Lock mode if we don't have a display (we're running a 142 ;; Don't turn on Font Lock mode if we don't have a display (we're running a
142 ;; batch job) or if the buffer is invisible (the name starts with a space). 143 ;; batch job) or if the buffer is invisible (the name starts with a space).
143 (when (or noninteractive (eq (aref (buffer-name) 0) ?\s)) 144 (when (or noninteractive (eq (aref (buffer-name) 0) ?\s))
diff --git a/lisp/font-lock.el b/lisp/font-lock.el
index 9f9445bdea9..a65a2c94c7d 100644
--- a/lisp/font-lock.el
+++ b/lisp/font-lock.el
@@ -629,21 +629,24 @@ Major/minor modes can set this variable if they know which option applies.")
629 ;; Shut up the byte compiler. 629 ;; Shut up the byte compiler.
630 (defvar font-lock-face-attributes)) ; Obsolete but respected if set. 630 (defvar font-lock-face-attributes)) ; Obsolete but respected if set.
631 631
632(defun font-lock-initial-fontify ()
633 ;; The first fontification after turning the mode on. This must
634 ;; only be called after the mode hooks have been run.
635 (let ((max-size (font-lock-value-in-major-mode font-lock-maximum-size)))
636 (cond (font-lock-fontified
637 nil)
638 ((or (null max-size) (> max-size (buffer-size)))
639 (font-lock-fontify-buffer))
640 (font-lock-verbose
641 (message "Fontifying %s...buffer size greater than font-lock-maximum-size"
642 (buffer-name))))))
643
632(defun font-lock-mode-internal (arg) 644(defun font-lock-mode-internal (arg)
633 ;; Turn on Font Lock mode. 645 ;; Turn on Font Lock mode.
634 (when arg 646 (when arg
635 (add-hook 'after-change-functions 'font-lock-after-change-function t t) 647 (add-hook 'after-change-functions 'font-lock-after-change-function t t)
636 (font-lock-set-defaults) 648 (font-lock-set-defaults)
637 (font-lock-turn-on-thing-lock) 649 (font-lock-turn-on-thing-lock))
638 ;; Fontify the buffer if we have to.
639 (let ((max-size (font-lock-value-in-major-mode font-lock-maximum-size)))
640 (cond (font-lock-fontified
641 nil)
642 ((or (null max-size) (> max-size (buffer-size)))
643 (font-lock-fontify-buffer))
644 (font-lock-verbose
645 (message "Fontifying %s...buffer size greater than font-lock-maximum-size"
646 (buffer-name))))))
647 ;; Turn off Font Lock mode. 650 ;; Turn off Font Lock mode.
648 (unless font-lock-mode 651 (unless font-lock-mode
649 (remove-hook 'after-change-functions 'font-lock-after-change-function t) 652 (remove-hook 'after-change-functions 'font-lock-after-change-function t)