diff options
| author | Stefan Monnier | 1999-11-23 09:08:38 +0000 |
|---|---|---|
| committer | Stefan Monnier | 1999-11-23 09:08:38 +0000 |
| commit | 29cc3b845b9a6e503569d030a2b9a368e2a61670 (patch) | |
| tree | ea5d178bbf62da392da65ba2dcdd6522c817c260 | |
| parent | f67a1f3e698075f3e09a4c2ba88299910c398246 (diff) | |
| download | emacs-29cc3b845b9a6e503569d030a2b9a368e2a61670.tar.gz emacs-29cc3b845b9a6e503569d030a2b9a368e2a61670.zip | |
Changed maintainer.
(easy-mmode-define-toggle): New BODY arg; Never append `-mode';
Use defcustom for the hooks; Improve the auto-generated docstrings.
(easy-mmode-define-minor-mode): Renamed `define-minor-mode'.
(define-minor-mode): Add BODY arg; Only declare the keymap if
provided; Improve the auto-generated docstrings.
| -rw-r--r-- | lisp/ChangeLog | 9 | ||||
| -rw-r--r-- | lisp/emacs-lisp/easy-mmode.el | 97 |
2 files changed, 55 insertions, 51 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 02263d03ff4..a42ab729244 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,12 @@ | |||
| 1 | 1999-11-23 Stefan Monnier <monnier@cs.yale.edu> | ||
| 2 | |||
| 3 | * emacs-lisp/easy-mmode.el: Changed maintainer. | ||
| 4 | (easy-mmode-define-toggle): New BODY arg; Never append `-mode'; | ||
| 5 | Use defcustom for the hooks; Improve the auto-generated docstrings. | ||
| 6 | (easy-mmode-define-minor-mode): Renamed `define-minor-mode'. | ||
| 7 | (define-minor-mode): Add BODY arg; Only declare the keymap if | ||
| 8 | provided; Improve the auto-generated docstrings. | ||
| 9 | |||
| 1 | 1999-11-22 Gerd Moellmann <gerd@gnu.org> | 10 | 1999-11-22 Gerd Moellmann <gerd@gnu.org> |
| 2 | 11 | ||
| 3 | * textmodes/text-mode.el (text-mode): Contruct paragraph-start so | 12 | * textmodes/text-mode.el (text-mode): Contruct paragraph-start so |
diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el index fe5b7a6ad07..c39e6b96424 100644 --- a/lisp/emacs-lisp/easy-mmode.el +++ b/lisp/emacs-lisp/easy-mmode.el | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | ;; Copyright (C) 1997 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1997 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 | 7 | ||
| 7 | ;; This file is part of GNU Emacs. | 8 | ;; This file is part of GNU Emacs. |
| 8 | 9 | ||
| @@ -60,10 +61,11 @@ optional MENU-NAME is passed to `make-sparse-keymap'." | |||
| 60 | keymap-alist) | 61 | keymap-alist) |
| 61 | keymap)) | 62 | keymap)) |
| 62 | 63 | ||
| 63 | (defmacro easy-mmode-define-toggle (mode &optional doc) | 64 | (defmacro easy-mmode-define-toggle (mode &optional doc &rest body) |
| 64 | "Define a one arg toggle mode MODE function and associated hooks. | 65 | "Define a one arg toggle mode MODE function and associated hooks. |
| 65 | MODE-mode is the so defined function that toggle the mode. | 66 | MODE is the so defined function that toggles the mode. |
| 66 | optional DOC is its associated documentation. | 67 | optional DOC is its associated documentation. |
| 68 | BODY is executed after the toggling and before running the hooks. | ||
| 67 | 69 | ||
| 68 | Hooks are checked for run, each time MODE-mode is called. | 70 | Hooks are checked for run, each time MODE-mode is called. |
| 69 | They run under the followings conditions: | 71 | They run under the followings conditions: |
| @@ -72,86 +74,79 @@ MODE-on-hook: if the mode is on. | |||
| 72 | MODE-off-hook: if the mode is off. | 74 | MODE-off-hook: if the mode is off. |
| 73 | 75 | ||
| 74 | When the mode is effectively toggled, two hooks may run. | 76 | When the mode is effectively toggled, two hooks may run. |
| 75 | If so MODE-hook is guaranteed to be the first. | 77 | If so MODE-hook is guaranteed to be the first." |
| 76 | 78 | (let* ((mode-name (symbol-name mode)) | |
| 77 | \(defmacro easy-mmode-define-toggle (MODE &optional DOC)" | ||
| 78 | (let* ((mode-name | ||
| 79 | (if (string-match "-mode\\'" (symbol-name mode)) | ||
| 80 | (symbol-name mode) | ||
| 81 | (concat (symbol-name mode) "-mode"))) | ||
| 82 | (hook (intern (concat mode-name "-hook"))) | 79 | (hook (intern (concat mode-name "-hook"))) |
| 83 | (hook-on (intern (concat mode-name "-on-hook"))) | 80 | (hook-on (intern (concat mode-name "-on-hook"))) |
| 84 | (hook-off (intern (concat mode-name "-off-hook"))) | 81 | (hook-off (intern (concat mode-name "-off-hook"))) |
| 85 | (toggle (intern mode-name)) | ||
| 86 | (mode toggle) | ||
| 87 | (toggle-doc (or doc | 82 | (toggle-doc (or doc |
| 88 | (format "With no argument, toggle %s mode. | 83 | (format "With no argument, toggle %s. |
| 89 | With arg turn mode on. | 84 | With universal prefix ARG turn mode on. |
| 90 | With zero or negative arg turn mode off" | 85 | With zero or negative ARG turn mode off. |
| 91 | mode-name)))) | 86 | \\{%s}" mode-name (concat mode-name "-map"))))) |
| 92 | `(progn | 87 | `(progn |
| 93 | (defvar ,hook nil | 88 | (defcustom ,hook nil |
| 94 | ,(format "Hook called when %s mode is toggled" mode-name)) | 89 | ,(format "Hook called when `%s' is toggled" mode-name) |
| 90 | :type 'hook) | ||
| 95 | 91 | ||
| 96 | (defvar ,hook-on nil | 92 | (defcustom ,hook-on nil |
| 97 | ,(format "Hook called when %s mode is turned on" mode-name)) | 93 | ,(format "Hook called when `%s' is turned on" mode-name) |
| 94 | :type 'hook) | ||
| 98 | 95 | ||
| 99 | (defvar ,hook-off nil | 96 | (defcustom ,hook-off nil |
| 100 | ,(format "Hook called when %s mode is turned off" mode-name)) | 97 | ,(format "Hook called when `%s' is turned off" mode-name) |
| 98 | :type 'hook) | ||
| 101 | 99 | ||
| 102 | (defun ,toggle (&optional arg) | 100 | (defun ,mode (&optional arg) |
| 103 | ,toggle-doc | 101 | ,toggle-doc |
| 104 | (interactive "P") | 102 | (interactive "P") |
| 105 | (let ((old-mode ,mode)) | 103 | (let ((old-mode ,mode)) |
| 106 | (setq ,mode | 104 | (setq ,mode |
| 107 | (if arg | 105 | (if arg |
| 108 | (or (listp arg);; C-u alone | 106 | (> (prefix-numeric-value arg) 0) |
| 109 | (> (prefix-numeric-value arg) 0)) | ||
| 110 | (not ,mode))) | 107 | (not ,mode))) |
| 111 | (and ,hook | 108 | ,@body |
| 112 | (not (equal old-mode ,mode)) | 109 | (unless (equal old-mode ,mode) (run-hooks ',hook)) |
| 113 | (run-hooks ',hook)) | 110 | (run-hooks (if ,mode ',hook-on ',hook-off))))))) |
| 114 | (and ,hook-on | ||
| 115 | ,mode | ||
| 116 | (run-hooks ',hook-on)) | ||
| 117 | (and ,hook-off | ||
| 118 | (not ,mode) | ||
| 119 | (run-hooks ',hook-off))))))) | ||
| 120 | 111 | ||
| 121 | ;;;###autoload | 112 | ;;;###autoload |
| 122 | (defmacro easy-mmode-define-minor-mode (mode doc &optional init-value lighter keymap) | 113 | (defalias 'easy-mmode-define-minor-mode 'define-minor-mode) |
| 114 | ;;;###autoload | ||
| 115 | (defmacro define-minor-mode (mode doc &optional init-value lighter keymap &rest body) | ||
| 123 | "Define a new minor mode MODE. | 116 | "Define a new minor mode MODE. |
| 124 | This function defines the associated control variable, keymap, | 117 | This function defines the associated control variable, keymap, |
| 125 | toggle command, and hooks (see `easy-mmode-define-toggle'). | 118 | toggle command, and hooks (see `easy-mmode-define-toggle'). |
| 126 | 119 | ||
| 127 | DOC is the documentation for the mode toggle command. | 120 | DOC is the documentation for the mode toggle command. |
| 121 | Optional INIT-VALUE is the initial value of the mode's variable. | ||
| 128 | Optional LIGHTER is displayed in the mode-bar when the mode is on. | 122 | Optional LIGHTER is displayed in the mode-bar when the mode is on. |
| 129 | Optional KEYMAP is the default (defvar) keymap bound to the mode keymap. | 123 | Optional KEYMAP is the default (defvar) keymap bound to the mode keymap. |
| 130 | If it is a list, it is passed to `easy-mmode-define-keymap' | 124 | If it is a list, it is passed to `easy-mmode-define-keymap' |
| 131 | in order to build a valid keymap. | 125 | in order to build a valid keymap. |
| 132 | 126 | BODY contains code that will be executed each time the mode is (dis)activated. | |
| 133 | \(defmacro easy-mmode-define-minor-mode | 127 | It will be executed after any toggling but before running the hooks." |
| 134 | (MODE DOC &optional INIT-VALUE LIGHTER KEYMAP)...\)" | ||
| 135 | (let* ((mode-name (symbol-name mode)) | 128 | (let* ((mode-name (symbol-name mode)) |
| 136 | (mode-doc (format "Non-nil if %s mode is enabled." mode-name)) | 129 | (mode-doc (format "Non-nil if mode is enabled. |
| 137 | (keymap-name (concat mode-name "-map")) | 130 | Use the function `%s' to change this variable." mode-name)) |
| 138 | (keymap-doc (format "Keymap for %s mode." mode-name))) | 131 | (keymap-sym (intern (concat mode-name "-map"))) |
| 132 | (keymap-doc (format "Keymap for `%s'." mode-name))) | ||
| 139 | `(progn | 133 | `(progn |
| 140 | ;; Define the variable to enable or disable the mode. | 134 | ;; Define the variable to enable or disable the mode. |
| 141 | (defvar ,mode ,init-value ,mode-doc) | 135 | (defvar ,mode ,init-value ,mode-doc) |
| 142 | (make-variable-buffer-local ',mode) | 136 | (make-variable-buffer-local ',mode) |
| 143 | 137 | ||
| 144 | ;; Define the minor-mode keymap. | 138 | ;; Define the minor-mode keymap. |
| 145 | (defvar ,(intern keymap-name) | 139 | ,(when keymap |
| 146 | (cond ((and ,keymap (keymapp ,keymap)) | 140 | `(defvar ,keymap-sym |
| 147 | ,keymap) | 141 | (cond ((and ,keymap (keymapp ,keymap)) |
| 148 | ((listp ,keymap) | 142 | ,keymap) |
| 149 | (easy-mmode-define-keymap ,keymap)) | 143 | ((listp ,keymap) |
| 150 | (t (error "Invalid keymap %S" ,keymap))) | 144 | (easy-mmode-define-keymap ,keymap)) |
| 151 | ,keymap-doc) | 145 | (t (error "Invalid keymap %S" ,keymap))) |
| 146 | ,keymap-doc)) | ||
| 152 | 147 | ||
| 153 | ;; Define the toggle and the hooks. | 148 | ;; Define the toggle and the hooks. |
| 154 | ,(macroexpand `(easy-mmode-define-toggle ,mode ,doc)) | 149 | (easy-mmode-define-toggle ,mode ,doc ,@body) |
| 155 | 150 | ||
| 156 | ;; Update the mode line. | 151 | ;; Update the mode line. |
| 157 | (or (assq ',mode minor-mode-alist) | 152 | (or (assq ',mode minor-mode-alist) |
| @@ -161,10 +156,10 @@ in order to build a valid keymap. | |||
| 161 | 156 | ||
| 162 | ;; Update the minor mode map. | 157 | ;; Update the minor mode map. |
| 163 | (or (assq ',mode minor-mode-map-alist) | 158 | (or (assq ',mode minor-mode-map-alist) |
| 164 | (setq minor-mode-map-alist | 159 | (setq minor-mode-map-alist |
| 165 | (cons (cons ',mode ,(intern keymap-name)) minor-mode-map-alist))) | 160 | (cons (cons ',mode nil) minor-mode-map-alist))) |
| 166 | (setcdr (assq ',mode minor-mode-map-alist) | 161 | (setcdr (assq ',mode minor-mode-map-alist) |
| 167 | ,(intern keymap-name))) )) | 162 | ,keymap-sym)) )) |
| 168 | 163 | ||
| 169 | (provide 'easy-mmode) | 164 | (provide 'easy-mmode) |
| 170 | 165 | ||