Mercurial > emacs
changeset 29548:71b284c55162
(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.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Sun, 11 Jun 2000 04:55:57 +0000 |
parents | 57aeae00b4df |
children | eafd45bcdcc1 |
files | lisp/emacs-lisp/easy-mmode.el |
diffstat | 1 files changed, 41 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/emacs-lisp/easy-mmode.el Sun Jun 11 03:54:29 2000 +0000 +++ b/lisp/emacs-lisp/easy-mmode.el Sun Jun 11 04:55:57 2000 +0000 @@ -92,7 +92,8 @@ (group (list 'quote (intern (replace-regexp-in-string "-mode\\'" "" mode-name)))) - (keymap-sym (intern (concat mode-name "-map"))) + (keymap-sym (if (and keymap (symbolp keymap)) keymap + (intern (concat mode-name "-map")))) (hook (intern (concat mode-name "-hook"))) (hook-on (intern (concat mode-name "-on-hook"))) (hook-off (intern (concat mode-name "-off-hook")))) @@ -126,21 +127,31 @@ Use the function `%s' to change this variable." pretty-name mode)) (make-variable-buffer-local ',mode)) - `(defcustom ,mode ,init-value - ,(format "Toggle %s. + (let ((curfile (or (and (boundp 'byte-compile-current-file) + byte-compile-current-file) + load-file-name))) + `(defcustom ,mode ,init-value + ,(format "Toggle %s. Setting this variable directly does not take effect; use either \\[customize] or the function `%s'." - pretty-name mode) - :set (lambda (symbol value) (funcall symbol (or value 0))) - :initialize 'custom-initialize-default - :group ,group - :type 'boolean)) + pretty-name mode) + :set (lambda (symbol value) (funcall symbol (or value 0))) + :initialize 'custom-initialize-default + :group ,group + :type 'boolean + ,@(when curfile + (list + :require + (list 'quote + (intern (file-name-nondirectory + (file-name-sans-extension curfile))))))))) - ;; The toggle's hook. - (defcustom ,hook nil - ,(format "Hook run at the end of function `%s'." mode-name) - :group ,group - :type 'hook) + ;; The toggle's hook. Wrapped in `progn' to prevent autoloading. + (progn + (defcustom ,hook nil + ,(format "Hook run at the end of function `%s'." mode-name) + :group ,group + :type 'hook)) ;; The actual function. (defun ,mode (&optional arg) @@ -163,16 +174,22 @@ (if ,mode "en" "dis"))) ,mode) + ;; Autoloading an easy-mmode-define-minor-mode autoloads + ;; everything up-to-here. + :autoload-end + ;; Define the minor-mode keymap. - ,(when keymap + ,(unless (symbolp keymap) ;nil is also a symbol. `(defvar ,keymap-sym - (cond ((keymapp ,keymap) ,keymap) - ((listp ,keymap) (easy-mmode-define-keymap ,keymap)) - (t (error "Invalid keymap %S" ,keymap))) + (let ((m ,keymap)) + (cond ((keymapp m) m) + ((listp m) (easy-mmode-define-keymap m)) + (t (error "Invalid keymap %S" ,keymap)))) ,(format "Keymap for `%s'." mode-name))) (add-minor-mode ',mode ',lighter - (if (boundp ',keymap-sym) (symbol-value ',keymap-sym))) + ,(if keymap keymap-sym + `(if (boundp ',keymap-sym) ,keymap-sym))) ;; If the mode is global, call the function according to the default. ,(if globalp `(if ,mode (,mode 1)))))) @@ -229,6 +246,10 @@ (with-current-buffer buf (if ,global-mode (,turn-on) (,mode -1))))) + ;; Autoloading easy-mmode-define-global-mode + ;; autoloads everything up-to-here. + :autoload-end + ;; List of buffers left to process. (defvar ,buffers nil) @@ -410,7 +431,8 @@ `(progn (defvar ,map (make-sparse-keymap)) (defvar ,syntax (make-char-table 'syntax-table nil)) - (defvar ,abbrev (progn (define-abbrev-table ',abbrev nil) ,abbrev)) + (defvar ,abbrev) + (define-abbrev-table ',abbrev nil) (put ',child 'derived-mode-parent ',parent) (defun ,child ()