Commit 3837de12 authored by Stefan Monnier's avatar Stefan Monnier
Browse files

(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.
parent f905e56a
2000-06-02 Stefan Monnier <monnier@cs.yale.edu>
* log-edit.el (log-edit-done): Thinko in the "same comment" detection.
* emacs-lisp/easy-mmode.el (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.
2000-06-02 Dave Love <fx@gnu.org> 2000-06-02 Dave Love <fx@gnu.org>
* files.el (convert-standard-filename): Doc fix. * files.el (convert-standard-filename): Doc fix.
...@@ -11,8 +22,8 @@ ...@@ -11,8 +22,8 @@
(todo-cmd-raise): Fix typo. (todo-cmd-raise): Fix typo.
(todo-top-priorities): Change temp buffer name. (todo-top-priorities): Change temp buffer name.
(todo-category-alist): Avoid redundant lambda. (todo-category-alist): Avoid redundant lambda.
(todo-mode): Set paragraph-separate, outline-regexp from (todo-mode): Set paragraph-separate, outline-regexp from todo-prefix.
todo-prefix. Use outline-next-heading. Use outline-next-heading.
* autoarg.el: Rewritten to use define-minor-mode. * autoarg.el: Rewritten to use define-minor-mode.
(autoarg-kp-digits, autoarg-kp-mode-map): New variable. (autoarg-kp-digits, autoarg-kp-mode-map): New variable.
...@@ -24,6 +35,10 @@ ...@@ -24,6 +35,10 @@
2000-06-01 Stefan Monnier <monnier@cs.yale.edu> 2000-06-01 Stefan Monnier <monnier@cs.yale.edu>
* log-edit.el (log-edit-mode): Make vc-comment-ring-index local.
(log-edit-done): Only add the comment to the ring if it's different
from the last comment entered.
* isearch.el (isearch-highlight): Turn internal-find-face into facep. * isearch.el (isearch-highlight): Turn internal-find-face into facep.
2000-06-01 Dave Love <fx@gnu.org> 2000-06-01 Dave Love <fx@gnu.org>
......
...@@ -57,6 +57,7 @@ MODE is the so defined function that toggles the mode. ...@@ -57,6 +57,7 @@ MODE is the so defined function that toggles the mode.
optional DOC is its associated documentation. optional DOC is its associated documentation.
BODY is executed after the toggling and before running MODE-hook." BODY is executed after the toggling and before running MODE-hook."
(let* ((mode-name (symbol-name mode)) (let* ((mode-name (symbol-name mode))
(pretty-name (easy-mmode-derive-name mode-name))
(hook (intern (concat mode-name "-hook"))) (hook (intern (concat mode-name "-hook")))
(hook-on (intern (concat mode-name "-on-hook"))) (hook-on (intern (concat mode-name "-on-hook")))
(hook-off (intern (concat mode-name "-off-hook"))) (hook-off (intern (concat mode-name "-off-hook")))
...@@ -64,7 +65,7 @@ BODY is executed after the toggling and before running MODE-hook." ...@@ -64,7 +65,7 @@ BODY is executed after the toggling and before running MODE-hook."
(format "With no argument, toggle %s. (format "With no argument, toggle %s.
With universal prefix ARG turn mode on. With universal prefix ARG turn mode on.
With zero or negative ARG turn mode off. With zero or negative ARG turn mode off.
\\{%s}" mode-name (concat mode-name "-map"))))) \\{%s}" pretty-name (concat mode-name "-map")))))
`(progn `(progn
(defcustom ,hook nil (defcustom ,hook nil
,(format "Hook called at the end of function `%s'." mode-name) ,(format "Hook called at the end of function `%s'." mode-name)
...@@ -82,13 +83,14 @@ With zero or negative ARG turn mode off. ...@@ -82,13 +83,14 @@ With zero or negative ARG turn mode off.
(run-hooks ',hook (if ,mode ',hook-on ',hook-off)) (run-hooks ',hook (if ,mode ',hook-on ',hook-off))
;; Return the new setting. ;; Return the new setting.
(if (interactive-p) (if (interactive-p)
(message ,(format "%s %%sabled" (message ,(format "%s %%sabled" pretty-name)
(replace-regexp-in-string
"-Mode" " mode"
(capitalize (symbol-name mode)) t))
(if ,mode "en" "dis"))) (if ,mode "en" "dis")))
,mode)))) ,mode))))
(defun easy-mmode-derive-name (mode)
(replace-regexp-in-string
"-Mode" " mode" (capitalize (symbol-name mode)) t))
;;;###autoload ;;;###autoload
(defalias 'easy-mmode-define-minor-mode 'define-minor-mode) (defalias 'easy-mmode-define-minor-mode 'define-minor-mode)
;;;###autoload ;;;###autoload
...@@ -118,9 +120,11 @@ It will be executed after any toggling but before running the hooks." ...@@ -118,9 +120,11 @@ It will be executed after any toggling but before running the hooks."
`(progn `(progn
;; Define the variable to enable or disable the mode. ;; Define the variable to enable or disable the mode.
,(if globalp ,(if globalp
`(defcustom ,mode ,init-value ,(format "Toggle %s. `(defcustom ,mode ,init-value
,(format "Toggle %s.
Setting this variable directly does not take effect; Setting this variable directly does not take effect;
use either \\[customize] or the function `%s'." mode mode) use either \\[customize] or the function `%s'."
(easy-mmode-derive-name mode) mode)
:set (lambda (symbol value) (funcall symbol (or value 0))) :set (lambda (symbol value) (funcall symbol (or value 0)))
:initialize 'custom-initialize-default :initialize 'custom-initialize-default
:type 'boolean) :type 'boolean)
...@@ -166,9 +170,9 @@ Use the function `%s' to change this variable." mode)) ...@@ -166,9 +170,9 @@ Use the function `%s' to change this variable." mode))
(defun easy-mmode-define-keymap (bs &optional name m args) (defun easy-mmode-define-keymap (bs &optional name m args)
"Return a keymap built from bindings BS. "Return a keymap built from bindings BS.
BS must be a list of (KEY . BINDING) where BS must be a list of (KEY . BINDING) where
KEY and BINDINGS are suited as for define-key. KEY and BINDINGS are suitable for `define-key'.
optional NAME is passed to `make-sparse-keymap'. Optional NAME is passed to `make-sparse-keymap'.
optional map M can be used to modify an existing map. Optional map M can be used to modify an existing map.
ARGS is a list of additional arguments." ARGS is a list of additional arguments."
(let (inherit dense suppress) (let (inherit dense suppress)
(while args (while args
...@@ -273,6 +277,8 @@ been generated automatically, with a reference to the keymap." ...@@ -273,6 +277,8 @@ been generated automatically, with a reference to the keymap."
(abbrev (intern (concat child-name "-abbrev-table"))) (abbrev (intern (concat child-name "-abbrev-table")))
(hook (intern (concat child-name "-hook")))) (hook (intern (concat child-name "-hook"))))
(unless parent (setq parent 'fundamental-mode))
(when (and docstring (not (stringp docstring))) (when (and docstring (not (stringp docstring)))
;; DOCSTRING is really the first command and there's no docstring ;; DOCSTRING is really the first command and there's no docstring
(push docstring body) (push docstring body)
...@@ -311,6 +317,7 @@ which more-or-less shadow %s's corresponding tables." ...@@ -311,6 +317,7 @@ which more-or-less shadow %s's corresponding tables."
(defvar ,map (make-sparse-keymap)) (defvar ,map (make-sparse-keymap))
(defvar ,syntax (make-char-table 'syntax-table nil)) (defvar ,syntax (make-char-table 'syntax-table nil))
(defvar ,abbrev (progn (define-abbrev-table ',abbrev nil) ,abbrev)) (defvar ,abbrev (progn (define-abbrev-table ',abbrev nil) ,abbrev))
(put ',child 'derived-mode-parent ',parent)
(defun ,child () (defun ,child ()
,docstring ,docstring
...@@ -346,6 +353,15 @@ which more-or-less shadow %s's corresponding tables." ...@@ -346,6 +353,15 @@ which more-or-less shadow %s's corresponding tables."
; Run the hooks, if any. ; Run the hooks, if any.
(run-hooks ',hook))))) (run-hooks ',hook)))))
;; Inspired from derived-mode-class in derived.el
(defun easy-mmode-derived-mode-p (mode)
"Non-nil if the current major mode is derived from MODE.
Uses the `derived-mode-parent' property of the symbol to trace backwards."
(let ((parent major-mode))
(while (and (not (eq parent mode))
(setq parent (get parent 'derived-mode-parent))))
parent))
;;; ;;;
;;; easy-mmode-define-navigation ;;; easy-mmode-define-navigation
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment