aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiles Bader2000-10-28 06:07:30 +0000
committerMiles Bader2000-10-28 06:07:30 +0000
commiteab6e8b99b0ecd035295de963b26bda463e9abf8 (patch)
tree5307da63308e7249fd23b36a350248ec7cc130b4
parent51a29efc7f274a7f1d2155435487331ecd7f6956 (diff)
downloademacs-eab6e8b99b0ecd035295de963b26bda463e9abf8.tar.gz
emacs-eab6e8b99b0ecd035295de963b26bda463e9abf8.zip
(define-minor-mode): Generate `turn-on-MODE' and `turn-off-MODE'
functions unless the mode is global. If :global is followed by a non-nil but non-t value, make the mode buffer-local, but also generate a `global-MODE' version using `easy-mmode-define-global-mode'. Add :conditional-turn-on keyword argument.
-rw-r--r--lisp/ChangeLog9
-rw-r--r--lisp/emacs-lisp/easy-mmode.el52
2 files changed, 56 insertions, 5 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 14b9e42e22e..d6b2ffcf2fe 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,12 @@
12000-10-28 Miles Bader <miles@gnu.org>
2
3 * emacs-lisp/easy-mmode.el (define-minor-mode): Generate
4 `turn-on-MODE' and `turn-off-MODE' functions unless the mode is
5 global. If :global is followed by a non-nil but non-t value,
6 make the mode buffer-local, but also generate a `global-MODE'
7 version using `easy-mmode-define-global-mode'. Add
8 :conditional-turn-on keyword argument.
9
12000-10-28 Dave Love <fx@gnu.org> 102000-10-28 Dave Love <fx@gnu.org>
2 11
3 * international/latin1-disp.el (latin1-char-displayable-p): Don't 12 * international/latin1-disp.el (latin1-char-displayable-p): Don't
diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el
index c2ff0701eb1..1089d81cd4d 100644
--- a/lisp/emacs-lisp/easy-mmode.el
+++ b/lisp/emacs-lisp/easy-mmode.el
@@ -83,13 +83,26 @@ Optional KEYMAP is the default (defvar) keymap bound to the mode keymap.
83BODY contains code that will be executed each time the mode is (dis)activated. 83BODY contains code that will be executed each time the mode is (dis)activated.
84 It will be executed after any toggling but before running the hooks. 84 It will be executed after any toggling but before running the hooks.
85 BODY can start with a list of CL-style keys specifying additional arguments. 85 BODY can start with a list of CL-style keys specifying additional arguments.
86 Currently two such keyword arguments are supported: 86 Currently three such keyword arguments are supported:
87:group followed by the group name to use for any generated `defcustom'. 87 :group, followed by the group name to use for any generated `defcustom'.
88:global if non-nil specifies that the minor mode is not meant to be 88 :global, followed by a value, which --
89 buffer-local. By default, the variable is made buffer-local." 89 If `t' specifies that the minor mode is not meant to be
90 buffer-local (by default, the variable is made buffer-local).
91 If non-nil, but not `t' (for instance, `:global optionally'), then
92 specifies that the minor mode should be buffer-local, but that a
93 corresponding `global-MODE' function should also be added, which can
94 be used to turn on MODE in every buffer.
95 :conditional-turn-on, followed by a function-name which turns on MODE
96 only when applicable to the current buffer. This is used in
97 conjunction with any `global-MODE' function (see :global above) when
98 turning on the buffer-local minor mode. By default, any generated
99 `global-MODE' function unconditionally turns on the minor mode in
100 every new buffer."
90 (let* ((mode-name (symbol-name mode)) 101 (let* ((mode-name (symbol-name mode))
91 (pretty-name (easy-mmode-pretty-mode-name mode lighter)) 102 (pretty-name (easy-mmode-pretty-mode-name mode lighter))
92 (globalp nil) 103 (globalp nil)
104 (define-global-mode-p nil)
105 (conditional-turn-on nil)
93 ;; We might as well provide a best-guess default group. 106 ;; We might as well provide a best-guess default group.
94 (group 107 (group
95 (list 'quote 108 (list 'quote
@@ -109,8 +122,13 @@ BODY contains code that will be executed each time the mode is (dis)activated.
109 (case (pop body) 122 (case (pop body)
110 (:global (setq globalp (pop body))) 123 (:global (setq globalp (pop body)))
111 (:group (setq group (pop body))) 124 (:group (setq group (pop body)))
125 (:conditional-turn-on (setq conditional-turn-on (pop body)))
112 (t (setq body (cdr body))))) 126 (t (setq body (cdr body)))))
113 127
128 (when (and globalp (not (eq globalp t)))
129 (setq globalp nil)
130 (setq define-global-mode-p t))
131
114 ;; Add default properties to LIGHTER. 132 ;; Add default properties to LIGHTER.
115 (unless (or (not (stringp lighter)) (get-text-property 0 'local-map lighter) 133 (unless (or (not (stringp lighter)) (get-text-property 0 'local-map lighter)
116 (get-text-property 0 'keymap lighter)) 134 (get-text-property 0 'keymap lighter))
@@ -176,6 +194,30 @@ With zero or negative ARG turn mode off.
176 (if ,mode "en" "dis"))) 194 (if ,mode "en" "dis")))
177 ,mode) 195 ,mode)
178 196
197 ,(unless globalp
198 (let ((turn-on (intern (concat "turn-on-" mode-name)))
199 (turn-off (intern (concat "turn-off-" mode-name))))
200 `(progn
201 (defun ,turn-on ()
202 ,(format "Turn on %s.
203
204This function is designed to be added to hooks, for example:
205 (add-hook 'text-mode-hook '%s)"
206 pretty-name
207 turn-on)
208 (interactive)
209 (,mode t))
210 (defun ,turn-off ()
211 ,(format "Turn off %s." pretty-name)
212 (interactive)
213 (,mode -1))
214 ,(when define-global-mode-p
215 `(easy-mmode-define-global-mode
216 ,(intern (concat "global-" mode-name))
217 ,mode
218 ,(or conditional-turn-on turn-on)
219 :group ,group)))))
220
179 ;; Autoloading an easy-mmode-define-minor-mode autoloads 221 ;; Autoloading an easy-mmode-define-minor-mode autoloads
180 ;; everything up-to-here. 222 ;; everything up-to-here.
181 :autoload-end 223 :autoload-end
@@ -193,7 +235,7 @@ With zero or negative ARG turn mode off.
193 ,(if keymap keymap-sym 235 ,(if keymap keymap-sym
194 `(if (boundp ',keymap-sym) 236 `(if (boundp ',keymap-sym)
195 (symbol-value ',keymap-sym)))) 237 (symbol-value ',keymap-sym))))
196 238
197 ;; If the mode is global, call the function according to the default. 239 ;; If the mode is global, call the function according to the default.
198 ,(if globalp `(if ,mode (,mode 1)))))) 240 ,(if globalp `(if ,mode (,mode 1))))))
199 241