aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2000-06-02 23:07:08 +0000
committerStefan Monnier2000-06-02 23:07:08 +0000
commit3837de12504430e57aa0d3211ea64049de8119d5 (patch)
tree6513844680f06745451e9e835d9e1bb5366b1aa3
parentf905e56a7390c165cf7b7bade9188fd60d41043e (diff)
downloademacs-3837de12504430e57aa0d3211ea64049de8119d5.tar.gz
emacs-3837de12504430e57aa0d3211ea64049de8119d5.zip
(easy-mmode-derive-name): New function.
(easy-mmode-define-toggle, define-minor-mode): Use it. (easy-mmode-define-keymap): Docstring fix. (define-derived-mode): Default PARENT to fundamental-mode. Add the derived-mode-parent symbol-property. (easy-mmode-derived-mode-p): New function.
-rw-r--r--lisp/ChangeLog19
-rw-r--r--lisp/emacs-lisp/easy-mmode.el36
2 files changed, 43 insertions, 12 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 20b78b024c1..5389fe9cff5 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,14 @@
12000-06-02 Stefan Monnier <monnier@cs.yale.edu>
2
3 * log-edit.el (log-edit-done): Thinko in the "same comment" detection.
4
5 * emacs-lisp/easy-mmode.el (easy-mmode-derive-name): New function.
6 (easy-mmode-define-toggle, define-minor-mode): Use it.
7 (easy-mmode-define-keymap): Docstring fix.
8 (define-derived-mode): Default PARENT to fundamental-mode.
9 Add the derived-mode-parent symbol-property.
10 (easy-mmode-derived-mode-p): New function.
11
12000-06-02 Dave Love <fx@gnu.org> 122000-06-02 Dave Love <fx@gnu.org>
2 13
3 * files.el (convert-standard-filename): Doc fix. 14 * files.el (convert-standard-filename): Doc fix.
@@ -11,8 +22,8 @@
11 (todo-cmd-raise): Fix typo. 22 (todo-cmd-raise): Fix typo.
12 (todo-top-priorities): Change temp buffer name. 23 (todo-top-priorities): Change temp buffer name.
13 (todo-category-alist): Avoid redundant lambda. 24 (todo-category-alist): Avoid redundant lambda.
14 (todo-mode): Set paragraph-separate, outline-regexp from 25 (todo-mode): Set paragraph-separate, outline-regexp from todo-prefix.
15 todo-prefix. Use outline-next-heading. 26 Use outline-next-heading.
16 27
17 * autoarg.el: Rewritten to use define-minor-mode. 28 * autoarg.el: Rewritten to use define-minor-mode.
18 (autoarg-kp-digits, autoarg-kp-mode-map): New variable. 29 (autoarg-kp-digits, autoarg-kp-mode-map): New variable.
@@ -24,6 +35,10 @@
24 35
252000-06-01 Stefan Monnier <monnier@cs.yale.edu> 362000-06-01 Stefan Monnier <monnier@cs.yale.edu>
26 37
38 * log-edit.el (log-edit-mode): Make vc-comment-ring-index local.
39 (log-edit-done): Only add the comment to the ring if it's different
40 from the last comment entered.
41
27 * isearch.el (isearch-highlight): Turn internal-find-face into facep. 42 * isearch.el (isearch-highlight): Turn internal-find-face into facep.
28 43
292000-06-01 Dave Love <fx@gnu.org> 442000-06-01 Dave Love <fx@gnu.org>
diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el
index c84555eae5f..130cc6877a4 100644
--- a/lisp/emacs-lisp/easy-mmode.el
+++ b/lisp/emacs-lisp/easy-mmode.el
@@ -57,6 +57,7 @@ MODE is the so defined function that toggles the mode.
57optional DOC is its associated documentation. 57optional DOC is its associated documentation.
58BODY is executed after the toggling and before running MODE-hook." 58BODY is executed after the toggling and before running MODE-hook."
59 (let* ((mode-name (symbol-name mode)) 59 (let* ((mode-name (symbol-name mode))
60 (pretty-name (easy-mmode-derive-name mode-name))
60 (hook (intern (concat mode-name "-hook"))) 61 (hook (intern (concat mode-name "-hook")))
61 (hook-on (intern (concat mode-name "-on-hook"))) 62 (hook-on (intern (concat mode-name "-on-hook")))
62 (hook-off (intern (concat mode-name "-off-hook"))) 63 (hook-off (intern (concat mode-name "-off-hook")))
@@ -64,7 +65,7 @@ BODY is executed after the toggling and before running MODE-hook."
64 (format "With no argument, toggle %s. 65 (format "With no argument, toggle %s.
65With universal prefix ARG turn mode on. 66With universal prefix ARG turn mode on.
66With zero or negative ARG turn mode off. 67With zero or negative ARG turn mode off.
67\\{%s}" mode-name (concat mode-name "-map"))))) 68\\{%s}" pretty-name (concat mode-name "-map")))))
68 `(progn 69 `(progn
69 (defcustom ,hook nil 70 (defcustom ,hook nil
70 ,(format "Hook called at the end of function `%s'." mode-name) 71 ,(format "Hook called at the end of function `%s'." mode-name)
@@ -82,13 +83,14 @@ With zero or negative ARG turn mode off.
82 (run-hooks ',hook (if ,mode ',hook-on ',hook-off)) 83 (run-hooks ',hook (if ,mode ',hook-on ',hook-off))
83 ;; Return the new setting. 84 ;; Return the new setting.
84 (if (interactive-p) 85 (if (interactive-p)
85 (message ,(format "%s %%sabled" 86 (message ,(format "%s %%sabled" pretty-name)
86 (replace-regexp-in-string
87 "-Mode" " mode"
88 (capitalize (symbol-name mode)) t))
89 (if ,mode "en" "dis"))) 87 (if ,mode "en" "dis")))
90 ,mode)))) 88 ,mode))))
91 89
90(defun easy-mmode-derive-name (mode)
91 (replace-regexp-in-string
92 "-Mode" " mode" (capitalize (symbol-name mode)) t))
93
92;;;###autoload 94;;;###autoload
93(defalias 'easy-mmode-define-minor-mode 'define-minor-mode) 95(defalias 'easy-mmode-define-minor-mode 'define-minor-mode)
94;;;###autoload 96;;;###autoload
@@ -118,9 +120,11 @@ It will be executed after any toggling but before running the hooks."
118 `(progn 120 `(progn
119 ;; Define the variable to enable or disable the mode. 121 ;; Define the variable to enable or disable the mode.
120 ,(if globalp 122 ,(if globalp
121 `(defcustom ,mode ,init-value ,(format "Toggle %s. 123 `(defcustom ,mode ,init-value
124 ,(format "Toggle %s.
122Setting this variable directly does not take effect; 125Setting this variable directly does not take effect;
123use either \\[customize] or the function `%s'." mode mode) 126use either \\[customize] or the function `%s'."
127 (easy-mmode-derive-name mode) mode)
124 :set (lambda (symbol value) (funcall symbol (or value 0))) 128 :set (lambda (symbol value) (funcall symbol (or value 0)))
125 :initialize 'custom-initialize-default 129 :initialize 'custom-initialize-default
126 :type 'boolean) 130 :type 'boolean)
@@ -166,9 +170,9 @@ Use the function `%s' to change this variable." mode))
166(defun easy-mmode-define-keymap (bs &optional name m args) 170(defun easy-mmode-define-keymap (bs &optional name m args)
167 "Return a keymap built from bindings BS. 171 "Return a keymap built from bindings BS.
168BS must be a list of (KEY . BINDING) where 172BS must be a list of (KEY . BINDING) where
169KEY and BINDINGS are suited as for define-key. 173KEY and BINDINGS are suitable for `define-key'.
170optional NAME is passed to `make-sparse-keymap'. 174Optional NAME is passed to `make-sparse-keymap'.
171optional map M can be used to modify an existing map. 175Optional map M can be used to modify an existing map.
172ARGS is a list of additional arguments." 176ARGS is a list of additional arguments."
173 (let (inherit dense suppress) 177 (let (inherit dense suppress)
174 (while args 178 (while args
@@ -273,6 +277,8 @@ been generated automatically, with a reference to the keymap."
273 (abbrev (intern (concat child-name "-abbrev-table"))) 277 (abbrev (intern (concat child-name "-abbrev-table")))
274 (hook (intern (concat child-name "-hook")))) 278 (hook (intern (concat child-name "-hook"))))
275 279
280 (unless parent (setq parent 'fundamental-mode))
281
276 (when (and docstring (not (stringp docstring))) 282 (when (and docstring (not (stringp docstring)))
277 ;; DOCSTRING is really the first command and there's no docstring 283 ;; DOCSTRING is really the first command and there's no docstring
278 (push docstring body) 284 (push docstring body)
@@ -311,6 +317,7 @@ which more-or-less shadow %s's corresponding tables."
311 (defvar ,map (make-sparse-keymap)) 317 (defvar ,map (make-sparse-keymap))
312 (defvar ,syntax (make-char-table 'syntax-table nil)) 318 (defvar ,syntax (make-char-table 'syntax-table nil))
313 (defvar ,abbrev (progn (define-abbrev-table ',abbrev nil) ,abbrev)) 319 (defvar ,abbrev (progn (define-abbrev-table ',abbrev nil) ,abbrev))
320 (put ',child 'derived-mode-parent ',parent)
314 321
315 (defun ,child () 322 (defun ,child ()
316 ,docstring 323 ,docstring
@@ -346,6 +353,15 @@ which more-or-less shadow %s's corresponding tables."
346 ; Run the hooks, if any. 353 ; Run the hooks, if any.
347 (run-hooks ',hook))))) 354 (run-hooks ',hook)))))
348 355
356;; Inspired from derived-mode-class in derived.el
357(defun easy-mmode-derived-mode-p (mode)
358 "Non-nil if the current major mode is derived from MODE.
359Uses the `derived-mode-parent' property of the symbol to trace backwards."
360 (let ((parent major-mode))
361 (while (and (not (eq parent mode))
362 (setq parent (get parent 'derived-mode-parent))))
363 parent))
364
349 365
350;;; 366;;;
351;;; easy-mmode-define-navigation 367;;; easy-mmode-define-navigation