Mercurial > emacs
comparison lisp/emacs-lisp/easy-mmode.el @ 47463:2b213bd55695
(define-minor-mode): Add a :require arg.
Don't call the function during init if mode is on by default.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Fri, 13 Sep 2002 14:16:02 +0000 |
parents | 360c6fcdde04 |
children | e8df9e898436 |
comparison
equal
deleted
inserted
replaced
47462:1bbef0cbbf67 | 47463:2b213bd55695 |
---|---|
88 | 88 |
89 BODY contains code that will be executed each time the mode is (dis)activated. | 89 BODY contains code that will be executed each time the mode is (dis)activated. |
90 It will be executed after any toggling but before running the hooks. | 90 It will be executed after any toggling but before running the hooks. |
91 BODY can start with a list of CL-style keys specifying additional arguments. | 91 BODY can start with a list of CL-style keys specifying additional arguments. |
92 The following keyword arguments are supported: | 92 The following keyword arguments are supported: |
93 :group Followed by the group name to use for any generated `defcustom'. | 93 :group GROUP Group name to use for any generated `defcustom'. |
94 :global If non-nil specifies that the minor mode is not meant to be | 94 :global GLOBAL If non-nil specifies that the minor mode is not meant to be |
95 buffer-local. By default, the variable is made buffer-local. | 95 buffer-local. By default, the variable is made buffer-local. |
96 :init-value Same as the INIT-VALUE argument. | 96 :init-value VAL Same as the INIT-VALUE argument. |
97 :lighter Same as the LIGHTER argument." | 97 :lighter SPEC Same as the LIGHTER argument. |
98 :require SYM Same as defcustom's :require argument." | |
98 ;; Allow skipping the first three args. | 99 ;; Allow skipping the first three args. |
99 (cond | 100 (cond |
100 ((keywordp init-value) | 101 ((keywordp init-value) |
101 (setq body (list* init-value lighter keymap body) | 102 (setq body (list* init-value lighter keymap body) |
102 init-value nil lighter nil keymap nil)) | 103 init-value nil lighter nil keymap nil)) |
107 (let* ((mode-name (symbol-name mode)) | 108 (let* ((mode-name (symbol-name mode)) |
108 (pretty-name (easy-mmode-pretty-mode-name mode lighter)) | 109 (pretty-name (easy-mmode-pretty-mode-name mode lighter)) |
109 (globalp nil) | 110 (globalp nil) |
110 (group nil) | 111 (group nil) |
111 (extra-args nil) | 112 (extra-args nil) |
113 (require t) | |
112 (keymap-sym (if (and keymap (symbolp keymap)) keymap | 114 (keymap-sym (if (and keymap (symbolp keymap)) keymap |
113 (intern (concat mode-name "-map")))) | 115 (intern (concat mode-name "-map")))) |
114 (hook (intern (concat mode-name "-hook"))) | 116 (hook (intern (concat mode-name "-hook"))) |
115 (hook-on (intern (concat mode-name "-on-hook"))) | 117 (hook-on (intern (concat mode-name "-on-hook"))) |
116 (hook-off (intern (concat mode-name "-off-hook")))) | 118 (hook-off (intern (concat mode-name "-off-hook")))) |
121 (:init-value (setq init-value (pop body))) | 123 (:init-value (setq init-value (pop body))) |
122 (:lighter (setq lighter (pop body))) | 124 (:lighter (setq lighter (pop body))) |
123 (:global (setq globalp (pop body))) | 125 (:global (setq globalp (pop body))) |
124 (:extra-args (setq extra-args (pop body))) | 126 (:extra-args (setq extra-args (pop body))) |
125 (:group (setq group (nconc group (list :group (pop body))))) | 127 (:group (setq group (nconc group (list :group (pop body))))) |
128 (:require (setq require (pop body))) | |
126 (t (pop body)))) | 129 (t (pop body)))) |
127 | 130 |
128 (unless group | 131 (unless group |
129 ;; We might as well provide a best-guess default group. | 132 ;; We might as well provide a best-guess default group. |
130 (setq group | 133 (setq group |
157 pretty-name mode mode) | 160 pretty-name mode mode) |
158 :set (lambda (symbol value) (funcall symbol (or value 0))) | 161 :set (lambda (symbol value) (funcall symbol (or value 0))) |
159 :initialize 'custom-initialize-default | 162 :initialize 'custom-initialize-default |
160 ,@group | 163 ,@group |
161 :type 'boolean | 164 :type 'boolean |
162 ,@(when curfile | 165 ,@(cond |
163 (list | 166 ((not (and curfile require)) nil) |
164 :require | 167 ((not (eq require t)) `(:require ,require)) |
165 (list 'quote | 168 (t `(:require |
166 (intern (file-name-nondirectory | 169 ',(intern (file-name-nondirectory |
167 (file-name-sans-extension curfile))))))))) | 170 (file-name-sans-extension curfile))))))))) |
168 | 171 |
169 ;; The actual function. | 172 ;; The actual function. |
170 (defun ,mode (&optional arg ,@extra-args) | 173 (defun ,mode (&optional arg ,@extra-args) |
171 ,(or doc | 174 ,(or doc |
172 (format (concat "Toggle %s on or off. | 175 (format (concat "Toggle %s on or off. |
222 ,(if keymap keymap-sym | 225 ,(if keymap keymap-sym |
223 `(if (boundp ',keymap-sym) | 226 `(if (boundp ',keymap-sym) |
224 (symbol-value ',keymap-sym)))) | 227 (symbol-value ',keymap-sym)))) |
225 | 228 |
226 ;; If the mode is global, call the function according to the default. | 229 ;; If the mode is global, call the function according to the default. |
227 ,(if globalp | 230 ,(if (and globalp (null init-value)) |
228 `(if (and load-file-name ,mode) | 231 `(if (and load-file-name ,mode) |
229 (eval-after-load load-file-name '(,mode 1))))))) | 232 (eval-after-load load-file-name '(,mode 1))))))) |
230 | 233 |
231 ;;; | 234 ;;; |
232 ;;; make global minor mode | 235 ;;; make global minor mode |