summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp/easy-mmode.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2000-06-11 04:55:57 +0000
committerStefan Monnier <monnier@iro.umontreal.ca>2000-06-11 04:55:57 +0000
commit1328a6dfa20b62cba2f7275e572c9cff700fe2b2 (patch)
tree78ab0c03d82a403aed78c7cfa29926d047908f56 /lisp/emacs-lisp/easy-mmode.el
parent1499d2dd8a652689b44195fe5a2bfbb975958bcd (diff)
downloademacs-1328a6dfa20b62cba2f7275e572c9cff700fe2b2.tar.gz
emacs-1328a6dfa20b62cba2f7275e572c9cff700fe2b2.tar.bz2
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.
Diffstat (limited to 'lisp/emacs-lisp/easy-mmode.el')
-rw-r--r--lisp/emacs-lisp/easy-mmode.el62
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.
(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 @@ BODY contains code that will be executed each time the mode is (dis)activated.
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))
-
- ;; The toggle's hook.
- (defcustom ,hook nil
- ,(format "Hook run at the end of function `%s'." mode-name)
- :group ,group
- :type 'hook)
+ 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. 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 @@ With zero or negative ARG turn mode off.
(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 @@ in which `%s' turns it on."
(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 @@ which more-or-less shadow %s's corresponding tables."
`(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 ()