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>
* files.el (convert-standard-filename): Doc fix.
......@@ -11,8 +22,8 @@
(todo-cmd-raise): Fix typo.
(todo-top-priorities): Change temp buffer name.
(todo-category-alist): Avoid redundant lambda.
(todo-mode): Set paragraph-separate, outline-regexp from
todo-prefix. Use outline-next-heading.
(todo-mode): Set paragraph-separate, outline-regexp from todo-prefix.
Use outline-next-heading.
* autoarg.el: Rewritten to use define-minor-mode.
(autoarg-kp-digits, autoarg-kp-mode-map): New variable.
......@@ -24,6 +35,10 @@
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.
2000-06-01 Dave Love <fx@gnu.org>
......
......@@ -57,6 +57,7 @@ MODE is the so defined function that toggles the mode.
optional DOC is its associated documentation.
BODY is executed after the toggling and before running MODE-hook."
(let* ((mode-name (symbol-name mode))
(pretty-name (easy-mmode-derive-name mode-name))
(hook (intern (concat mode-name "-hook")))
(hook-on (intern (concat mode-name "-on-hook")))
(hook-off (intern (concat mode-name "-off-hook")))
......@@ -64,7 +65,7 @@ BODY is executed after the toggling and before running MODE-hook."
(format "With no argument, toggle %s.
With universal prefix ARG turn mode on.
With zero or negative ARG turn mode off.
\\{%s}" mode-name (concat mode-name "-map")))))
\\{%s}" pretty-name (concat mode-name "-map")))))
`(progn
(defcustom ,hook nil
,(format "Hook called at the end of function `%s'." mode-name)
......@@ -82,13 +83,14 @@ With zero or negative ARG turn mode off.
(run-hooks ',hook (if ,mode ',hook-on ',hook-off))
;; Return the new setting.
(if (interactive-p)
(message ,(format "%s %%sabled"
(replace-regexp-in-string
"-Mode" " mode"
(capitalize (symbol-name mode)) t))
(message ,(format "%s %%sabled" pretty-name)
(if ,mode "en" "dis")))
,mode))))
(defun easy-mmode-derive-name (mode)
(replace-regexp-in-string
"-Mode" " mode" (capitalize (symbol-name mode)) t))
;;;###autoload
(defalias 'easy-mmode-define-minor-mode 'define-minor-mode)
;;;###autoload
......@@ -118,9 +120,11 @@ It will be executed after any toggling but before running the hooks."
`(progn
;; Define the variable to enable or disable the mode.
,(if globalp
`(defcustom ,mode ,init-value ,(format "Toggle %s.
`(defcustom ,mode ,init-value
,(format "Toggle %s.
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)))
:initialize 'custom-initialize-default
:type 'boolean)
......@@ -166,9 +170,9 @@ Use the function `%s' to change this variable." mode))
(defun easy-mmode-define-keymap (bs &optional name m args)
"Return a keymap built from bindings BS.
BS must be a list of (KEY . BINDING) where
KEY and BINDINGS are suited as for define-key.
optional NAME is passed to `make-sparse-keymap'.
optional map M can be used to modify an existing map.
KEY and BINDINGS are suitable for `define-key'.
Optional NAME is passed to `make-sparse-keymap'.
Optional map M can be used to modify an existing map.
ARGS is a list of additional arguments."
(let (inherit dense suppress)
(while args
......@@ -273,6 +277,8 @@ been generated automatically, with a reference to the keymap."
(abbrev (intern (concat child-name "-abbrev-table")))
(hook (intern (concat child-name "-hook"))))
(unless parent (setq parent 'fundamental-mode))
(when (and docstring (not (stringp docstring)))
;; DOCSTRING is really the first command and there's no docstring
(push docstring body)
......@@ -311,6 +317,7 @@ which more-or-less shadow %s's corresponding tables."
(defvar ,map (make-sparse-keymap))
(defvar ,syntax (make-char-table 'syntax-table nil))
(defvar ,abbrev (progn (define-abbrev-table ',abbrev nil) ,abbrev))
(put ',child 'derived-mode-parent ',parent)
(defun ,child ()
,docstring
......@@ -346,6 +353,15 @@ which more-or-less shadow %s's corresponding tables."
; Run the hooks, if any.
(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
......
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