comparison lisp/emacs-lisp/easy-mmode.el @ 51320:418f1ce2a14e

(define-minor-mode): Add edebug spec. Accept a :keymap argument, as you'd expect.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Thu, 29 May 2003 21:54:35 +0000
parents e0775ee7f599
children 3161ec452b93
comparison
equal deleted inserted replaced
51319:d91863669383 51320:418f1ce2a14e
1 ;;; easy-mmode.el --- easy definition for major and minor modes 1 ;;; easy-mmode.el --- easy definition for major and minor modes
2 2
3 ;; Copyright (C) 1997, 2000, 2001 Free Software Foundation, Inc. 3 ;; Copyright (C) 1997, 2000, 2001, 2003 Free Software Foundation, Inc.
4 4
5 ;; Author: Georges Brun-Cottan <Georges.Brun-Cottan@inria.fr> 5 ;; Author: Georges Brun-Cottan <Georges.Brun-Cottan@inria.fr>
6 ;; Maintainer: Stefan Monnier <monnier@gnu.org> 6 ;; Maintainer: Stefan Monnier <monnier@gnu.org>
7 7
8 ;; Keywords: extensions lisp 8 ;; Keywords: extensions lisp
96 :global GLOBAL If non-nil specifies that the minor mode is not meant to be 96 :global GLOBAL If non-nil specifies that the minor mode is not meant to be
97 buffer-local, so don't make the variable MODE buffer-local. 97 buffer-local, so don't make the variable MODE buffer-local.
98 By default, the mode is buffer-local. 98 By default, the mode is buffer-local.
99 :init-value VAL Same as the INIT-VALUE argument. 99 :init-value VAL Same as the INIT-VALUE argument.
100 :lighter SPEC Same as the LIGHTER argument. 100 :lighter SPEC Same as the LIGHTER argument.
101 :keymap MAP Same as the KEYMAP argument.
101 :require SYM Same as in `defcustom'. 102 :require SYM Same as in `defcustom'.
102 103
103 For example, you could write 104 For example, you could write
104 (define-minor-mode foo-mode \"If enabled, foo on you!\" 105 (define-minor-mode foo-mode \"If enabled, foo on you!\"
105 :lighter \" Foo\" :require 'foo :global t :group 'hassle :version \"27.5\" 106 :lighter \" Foo\" :require 'foo :global t :group 'hassle :version \"27.5\"
106 ...BODY CODE...)" 107 ...BODY CODE...)"
108 (declare (debug (&define name stringp
109 [&optional [&not keywordp] sexp
110 &optional [&not keywordp] sexp
111 &optional [&not keywordp] sexp]
112 [&rest [keywordp sexp]]
113 def-body)))
107 114
108 ;; Allow skipping the first three args. 115 ;; Allow skipping the first three args.
109 (cond 116 (cond
110 ((keywordp init-value) 117 ((keywordp init-value)
111 (setq body (list* init-value lighter keymap body) 118 (setq body (list* init-value lighter keymap body)
119 (globalp nil) 126 (globalp nil)
120 (group nil) 127 (group nil)
121 (extra-args nil) 128 (extra-args nil)
122 (extra-keywords nil) 129 (extra-keywords nil)
123 (require t) 130 (require t)
124 (keymap-sym (if (and keymap (symbolp keymap)) keymap
125 (intern (concat mode-name "-map"))))
126 (hook (intern (concat mode-name "-hook"))) 131 (hook (intern (concat mode-name "-hook")))
127 (hook-on (intern (concat mode-name "-on-hook"))) 132 (hook-on (intern (concat mode-name "-on-hook")))
128 (hook-off (intern (concat mode-name "-off-hook"))) 133 (hook-off (intern (concat mode-name "-off-hook")))
129 keyw) 134 keyw keymap-sym)
130 135
131 ;; Check keys. 136 ;; Check keys.
132 (while (keywordp (setq keyw (car body))) 137 (while (keywordp (setq keyw (car body)))
133 (setq body (cdr body)) 138 (setq body (cdr body))
134 (case keyw 139 (case keyw
136 (:lighter (setq lighter (pop body))) 141 (:lighter (setq lighter (pop body)))
137 (:global (setq globalp (pop body))) 142 (:global (setq globalp (pop body)))
138 (:extra-args (setq extra-args (pop body))) 143 (:extra-args (setq extra-args (pop body)))
139 (:group (setq group (nconc group (list :group (pop body))))) 144 (:group (setq group (nconc group (list :group (pop body)))))
140 (:require (setq require (pop body))) 145 (:require (setq require (pop body)))
146 (:keymap (setq keymap (pop body)))
141 (t (push keyw extra-keywords) (push (pop body) extra-keywords)))) 147 (t (push keyw extra-keywords) (push (pop body) extra-keywords))))
148
149 (setq keymap-sym (if (and keymap (symbolp keymap)) keymap
150 (intern (concat mode-name "-map"))))
142 151
143 (unless group 152 (unless group
144 ;; We might as well provide a best-guess default group. 153 ;; We might as well provide a best-guess default group.
145 (setq group 154 (setq group
146 `(:group ',(or (custom-current-group) 155 `(:group ',(or (custom-current-group)
202 (run-hooks ',hook (if ,mode ',hook-on ',hook-off)) 211 (run-hooks ',hook (if ,mode ',hook-on ',hook-off))
203 (if (interactive-p) 212 (if (interactive-p)
204 (progn 213 (progn
205 ,(if globalp `(customize-mark-as-set ',mode)) 214 ,(if globalp `(customize-mark-as-set ',mode))
206 (unless (current-message) 215 (unless (current-message)
207 (message ,(format "%s %%sabled" pretty-name) 216 (message ,(format "%s %%sabled" pretty-name)
208 (if ,mode "en" "dis"))))) 217 (if ,mode "en" "dis")))))
209 (force-mode-line-update) 218 (force-mode-line-update)
210 ;; Return the new setting. 219 ;; Return the new setting.
211 ,mode) 220 ,mode)
221
212 ;; Autoloading an easy-mmode-define-minor-mode autoloads 222 ;; Autoloading an easy-mmode-define-minor-mode autoloads
213 ;; everything up-to-here. 223 ;; everything up-to-here.
214 :autoload-end 224 :autoload-end
215 225
216 ;; The toggle's hook. 226 ;; The toggle's hook.