diff options
| author | Stefan Monnier | 2000-06-11 04:55:57 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2000-06-11 04:55:57 +0000 |
| commit | 1328a6dfa20b62cba2f7275e572c9cff700fe2b2 (patch) | |
| tree | 78ab0c03d82a403aed78c7cfa29926d047908f56 | |
| parent | 1499d2dd8a652689b44195fe5a2bfbb975958bcd (diff) | |
| download | emacs-1328a6dfa20b62cba2f7275e572c9cff700fe2b2.tar.gz emacs-1328a6dfa20b62cba2f7275e572c9cff700fe2b2.zip | |
(define-minor-mode): If KEYMAP is a symbol, just use it.
Use byte-compile-current-file and load-file-name to infer the
proper :require to pass to defcustom.
Wrap the hook var into `progn' so as not to autoload it.
Add a :autoload-end cookie.
Be more careful about the evaluation of KEYMAP.
(easy-mmode-define-global-mode): Add a :autoload-end cookie.
(define-derived-mode): Move define-abbrev-table outside of defvar.
| -rw-r--r-- | lisp/emacs-lisp/easy-mmode.el | 62 |
1 files changed, 42 insertions, 20 deletions
diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el index 32ceecd2996..95a0211769d 100644 --- a/lisp/emacs-lisp/easy-mmode.el +++ b/lisp/emacs-lisp/easy-mmode.el | |||
| @@ -92,7 +92,8 @@ BODY contains code that will be executed each time the mode is (dis)activated. | |||
| 92 | (group | 92 | (group |
| 93 | (list 'quote | 93 | (list 'quote |
| 94 | (intern (replace-regexp-in-string "-mode\\'" "" mode-name)))) | 94 | (intern (replace-regexp-in-string "-mode\\'" "" mode-name)))) |
| 95 | (keymap-sym (intern (concat mode-name "-map"))) | 95 | (keymap-sym (if (and keymap (symbolp keymap)) keymap |
| 96 | (intern (concat mode-name "-map")))) | ||
| 96 | (hook (intern (concat mode-name "-hook"))) | 97 | (hook (intern (concat mode-name "-hook"))) |
| 97 | (hook-on (intern (concat mode-name "-on-hook"))) | 98 | (hook-on (intern (concat mode-name "-on-hook"))) |
| 98 | (hook-off (intern (concat mode-name "-off-hook")))) | 99 | (hook-off (intern (concat mode-name "-off-hook")))) |
| @@ -126,21 +127,31 @@ BODY contains code that will be executed each time the mode is (dis)activated. | |||
| 126 | Use the function `%s' to change this variable." pretty-name mode)) | 127 | Use the function `%s' to change this variable." pretty-name mode)) |
| 127 | (make-variable-buffer-local ',mode)) | 128 | (make-variable-buffer-local ',mode)) |
| 128 | 129 | ||
| 129 | `(defcustom ,mode ,init-value | 130 | (let ((curfile (or (and (boundp 'byte-compile-current-file) |
| 130 | ,(format "Toggle %s. | 131 | byte-compile-current-file) |
| 132 | load-file-name))) | ||
| 133 | `(defcustom ,mode ,init-value | ||
| 134 | ,(format "Toggle %s. | ||
| 131 | Setting this variable directly does not take effect; | 135 | Setting this variable directly does not take effect; |
| 132 | use either \\[customize] or the function `%s'." | 136 | use either \\[customize] or the function `%s'." |
| 133 | pretty-name mode) | 137 | pretty-name mode) |
| 134 | :set (lambda (symbol value) (funcall symbol (or value 0))) | 138 | :set (lambda (symbol value) (funcall symbol (or value 0))) |
| 135 | :initialize 'custom-initialize-default | 139 | :initialize 'custom-initialize-default |
| 136 | :group ,group | 140 | :group ,group |
| 137 | :type 'boolean)) | 141 | :type 'boolean |
| 138 | 142 | ,@(when curfile | |
| 139 | ;; The toggle's hook. | 143 | (list |
| 140 | (defcustom ,hook nil | 144 | :require |
| 141 | ,(format "Hook run at the end of function `%s'." mode-name) | 145 | (list 'quote |
| 142 | :group ,group | 146 | (intern (file-name-nondirectory |
| 143 | :type 'hook) | 147 | (file-name-sans-extension curfile))))))))) |
| 148 | |||
| 149 | ;; The toggle's hook. Wrapped in `progn' to prevent autoloading. | ||
| 150 | (progn | ||
| 151 | (defcustom ,hook nil | ||
| 152 | ,(format "Hook run at the end of function `%s'." mode-name) | ||
| 153 | :group ,group | ||
| 154 | :type 'hook)) | ||
| 144 | 155 | ||
| 145 | ;; The actual function. | 156 | ;; The actual function. |
| 146 | (defun ,mode (&optional arg) | 157 | (defun ,mode (&optional arg) |
| @@ -163,16 +174,22 @@ With zero or negative ARG turn mode off. | |||
| 163 | (if ,mode "en" "dis"))) | 174 | (if ,mode "en" "dis"))) |
| 164 | ,mode) | 175 | ,mode) |
| 165 | 176 | ||
| 177 | ;; Autoloading an easy-mmode-define-minor-mode autoloads | ||
| 178 | ;; everything up-to-here. | ||
| 179 | :autoload-end | ||
| 180 | |||
| 166 | ;; Define the minor-mode keymap. | 181 | ;; Define the minor-mode keymap. |
| 167 | ,(when keymap | 182 | ,(unless (symbolp keymap) ;nil is also a symbol. |
| 168 | `(defvar ,keymap-sym | 183 | `(defvar ,keymap-sym |
| 169 | (cond ((keymapp ,keymap) ,keymap) | 184 | (let ((m ,keymap)) |
| 170 | ((listp ,keymap) (easy-mmode-define-keymap ,keymap)) | 185 | (cond ((keymapp m) m) |
| 171 | (t (error "Invalid keymap %S" ,keymap))) | 186 | ((listp m) (easy-mmode-define-keymap m)) |
| 187 | (t (error "Invalid keymap %S" ,keymap)))) | ||
| 172 | ,(format "Keymap for `%s'." mode-name))) | 188 | ,(format "Keymap for `%s'." mode-name))) |
| 173 | 189 | ||
| 174 | (add-minor-mode ',mode ',lighter | 190 | (add-minor-mode ',mode ',lighter |
| 175 | (if (boundp ',keymap-sym) (symbol-value ',keymap-sym))) | 191 | ,(if keymap keymap-sym |
| 192 | `(if (boundp ',keymap-sym) ,keymap-sym))) | ||
| 176 | 193 | ||
| 177 | ;; If the mode is global, call the function according to the default. | 194 | ;; If the mode is global, call the function according to the default. |
| 178 | ,(if globalp `(if ,mode (,mode 1)))))) | 195 | ,(if globalp `(if ,mode (,mode 1)))))) |
| @@ -229,6 +246,10 @@ in which `%s' turns it on." | |||
| 229 | (with-current-buffer buf | 246 | (with-current-buffer buf |
| 230 | (if ,global-mode (,turn-on) (,mode -1))))) | 247 | (if ,global-mode (,turn-on) (,mode -1))))) |
| 231 | 248 | ||
| 249 | ;; Autoloading easy-mmode-define-global-mode | ||
| 250 | ;; autoloads everything up-to-here. | ||
| 251 | :autoload-end | ||
| 252 | |||
| 232 | ;; List of buffers left to process. | 253 | ;; List of buffers left to process. |
| 233 | (defvar ,buffers nil) | 254 | (defvar ,buffers nil) |
| 234 | 255 | ||
| @@ -410,7 +431,8 @@ which more-or-less shadow %s's corresponding tables." | |||
| 410 | `(progn | 431 | `(progn |
| 411 | (defvar ,map (make-sparse-keymap)) | 432 | (defvar ,map (make-sparse-keymap)) |
| 412 | (defvar ,syntax (make-char-table 'syntax-table nil)) | 433 | (defvar ,syntax (make-char-table 'syntax-table nil)) |
| 413 | (defvar ,abbrev (progn (define-abbrev-table ',abbrev nil) ,abbrev)) | 434 | (defvar ,abbrev) |
| 435 | (define-abbrev-table ',abbrev nil) | ||
| 414 | (put ',child 'derived-mode-parent ',parent) | 436 | (put ',child 'derived-mode-parent ',parent) |
| 415 | 437 | ||
| 416 | (defun ,child () | 438 | (defun ,child () |