1 |
;;; easy-mmode.el --- easy definition for major and minor modes |
;;; easy-mmode.el --- easy definition for major and minor modes |
2 |
|
|
3 |
;; Copyright (C) 1997, 2000, 2001 Free Software Foundation, Inc. |
;; Copyright (C) 1997, 2000, 2001, 2003 Free Software Foundation, Inc. |
4 |
|
|
5 |
;; Author: Georges Brun-Cottan <Georges.Brun-Cottan@inria.fr> |
;; Author: Georges Brun-Cottan <Georges.Brun-Cottan@inria.fr> |
6 |
;; Maintainer: Stefan Monnier <monnier@gnu.org> |
;; Maintainer: Stefan Monnier <monnier@gnu.org> |
98 |
By default, the mode is buffer-local. |
By default, the mode is buffer-local. |
99 |
:init-value VAL Same as the INIT-VALUE argument. |
:init-value VAL Same as the INIT-VALUE argument. |
100 |
:lighter SPEC Same as the LIGHTER argument. |
:lighter SPEC Same as the LIGHTER argument. |
101 |
|
:keymap MAP Same as the KEYMAP argument. |
102 |
:require SYM Same as in `defcustom'. |
:require SYM Same as in `defcustom'. |
103 |
|
|
104 |
For example, you could write |
For example, you could write |
105 |
(define-minor-mode foo-mode \"If enabled, foo on you!\" |
(define-minor-mode foo-mode \"If enabled, foo on you!\" |
106 |
:lighter \" Foo\" :require 'foo :global t :group 'hassle :version \"27.5\" |
:lighter \" Foo\" :require 'foo :global t :group 'hassle :version \"27.5\" |
107 |
...BODY CODE...)" |
...BODY CODE...)" |
108 |
|
(declare (debug (&define name stringp |
109 |
|
[&optional [¬ keywordp] sexp |
110 |
|
&optional [¬ keywordp] sexp |
111 |
|
&optional [¬ keywordp] sexp] |
112 |
|
[&rest [keywordp sexp]] |
113 |
|
def-body))) |
114 |
|
|
115 |
;; Allow skipping the first three args. |
;; Allow skipping the first three args. |
116 |
(cond |
(cond |
128 |
(extra-args nil) |
(extra-args nil) |
129 |
(extra-keywords nil) |
(extra-keywords nil) |
130 |
(require t) |
(require t) |
|
(keymap-sym (if (and keymap (symbolp keymap)) keymap |
|
|
(intern (concat mode-name "-map")))) |
|
131 |
(hook (intern (concat mode-name "-hook"))) |
(hook (intern (concat mode-name "-hook"))) |
132 |
(hook-on (intern (concat mode-name "-on-hook"))) |
(hook-on (intern (concat mode-name "-on-hook"))) |
133 |
(hook-off (intern (concat mode-name "-off-hook"))) |
(hook-off (intern (concat mode-name "-off-hook"))) |
134 |
keyw) |
keyw keymap-sym) |
135 |
|
|
136 |
;; Check keys. |
;; Check keys. |
137 |
(while (keywordp (setq keyw (car body))) |
(while (keywordp (setq keyw (car body))) |
143 |
(:extra-args (setq extra-args (pop body))) |
(:extra-args (setq extra-args (pop body))) |
144 |
(:group (setq group (nconc group (list :group (pop body))))) |
(:group (setq group (nconc group (list :group (pop body))))) |
145 |
(:require (setq require (pop body))) |
(:require (setq require (pop body))) |
146 |
|
(:keymap (setq keymap (pop body))) |
147 |
(t (push keyw extra-keywords) (push (pop body) extra-keywords)))) |
(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")))) |
151 |
|
|
152 |
(unless group |
(unless group |
153 |
;; We might as well provide a best-guess default group. |
;; We might as well provide a best-guess default group. |
154 |
(setq group |
(setq group |
213 |
(progn |
(progn |
214 |
,(if globalp `(customize-mark-as-set ',mode)) |
,(if globalp `(customize-mark-as-set ',mode)) |
215 |
(unless (current-message) |
(unless (current-message) |
216 |
(message ,(format "%s %%sabled" pretty-name) |
(message ,(format "%s %%sabled" pretty-name) |
217 |
(if ,mode "en" "dis"))))) |
(if ,mode "en" "dis"))))) |
218 |
(force-mode-line-update) |
(force-mode-line-update) |
219 |
;; Return the new setting. |
;; Return the new setting. |
220 |
,mode) |
,mode) |
221 |
|
|
222 |
;; Autoloading an easy-mmode-define-minor-mode autoloads |
;; Autoloading an easy-mmode-define-minor-mode autoloads |
223 |
;; everything up-to-here. |
;; everything up-to-here. |
224 |
:autoload-end |
:autoload-end |