summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp/easy-mmode.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/emacs-lisp/easy-mmode.el')
-rw-r--r--lisp/emacs-lisp/easy-mmode.el100
1 files changed, 46 insertions, 54 deletions
diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el
index da63a0db925..ba0f8bad393 100644
--- a/lisp/emacs-lisp/easy-mmode.el
+++ b/lisp/emacs-lisp/easy-mmode.el
@@ -132,7 +132,7 @@ it is disabled.")
(string-replace "'" "\\='" (format "%S" getter)))))
(let ((start (point)))
(insert argdoc)
- (when (fboundp 'fill-region)
+ (when (fboundp 'fill-region) ;Don't break bootstrap!
(fill-region start (point) 'left t))))
;; Finally, insert the keymap.
(when (and (boundp keymap-sym)
@@ -143,8 +143,6 @@ it is disabled.")
(buffer-string)))))
;;;###autoload
-(defalias 'easy-mmode-define-minor-mode #'define-minor-mode)
-;;;###autoload
(defmacro define-minor-mode (mode doc &rest body)
"Define a new minor mode MODE.
This defines the toggle command MODE and (by default) a control variable
@@ -250,7 +248,8 @@ INIT-VALUE LIGHTER KEYMAP.
(warnwrap (if (or (null body) (keywordp (car body))) #'identity
(lambda (exp)
(macroexp-warn-and-return
- "Use keywords rather than deprecated positional arguments to `define-minor-mode'"
+ (format-message
+ "Use keywords rather than deprecated positional arguments to `define-minor-mode'")
exp))))
keyw keymap-sym tmp)
@@ -417,6 +416,8 @@ No problems result if this variable is not bound.
`(defvar ,keymap-sym
(let ((m ,keymap))
(cond ((keymapp m) m)
+ ;; FIXME: `easy-mmode-define-keymap' is obsolete,
+ ;; so this form should also be obsolete somehow.
((listp m)
(with-suppressed-warnings ((obsolete
easy-mmode-define-keymap))
@@ -440,8 +441,6 @@ No problems result if this variable is not bound.
;;;
;;;###autoload
-(defalias 'easy-mmode-define-global-mode #'define-globalized-minor-mode)
-;;;###autoload
(defalias 'define-global-minor-mode #'define-globalized-minor-mode)
;;;###autoload
(defmacro define-globalized-minor-mode (global-mode mode turn-on &rest body)
@@ -494,11 +493,8 @@ on if the hook has explicitly disabled it.
(extra-keywords nil)
(MODE-variable mode)
(MODE-buffers (intern (concat global-mode-name "-buffers")))
- (MODE-enable-in-buffers
- (intern (concat global-mode-name "-enable-in-buffers")))
- (MODE-check-buffers
- (intern (concat global-mode-name "-check-buffers")))
- (MODE-cmhh (intern (concat global-mode-name "-cmhh")))
+ (MODE-enable-in-buffer
+ (intern (concat global-mode-name "-enable-in-buffer")))
(minor-MODE-hook (intern (concat mode-name "-hook")))
(MODE-set-explicitly (intern (concat mode-name "-set-explicitly")))
(MODE-major-mode (intern (concat (symbol-name mode) "-major-mode")))
@@ -558,14 +554,9 @@ Disable the mode if ARG is a negative number.\n\n"
;; Setup hook to handle future mode changes and new buffers.
(if ,global-mode
- (progn
- (add-hook 'after-change-major-mode-hook
- #',MODE-enable-in-buffers)
- (add-hook 'find-file-hook #',MODE-check-buffers)
- (add-hook 'change-major-mode-hook #',MODE-cmhh))
- (remove-hook 'after-change-major-mode-hook #',MODE-enable-in-buffers)
- (remove-hook 'find-file-hook #',MODE-check-buffers)
- (remove-hook 'change-major-mode-hook #',MODE-cmhh))
+ (add-hook 'after-change-major-mode-hook
+ #',MODE-enable-in-buffer)
+ (remove-hook 'after-change-major-mode-hook #',MODE-enable-in-buffer))
;; Go through existing buffers.
(dolist (buf (buffer-list))
@@ -589,7 +580,20 @@ modes derived from `text-mode'\". An element with value t means \"use\"
and nil means \"don't use\". There's an implicit nil at the end of the
list."
mode)
- :type '(repeat sexp)
+ :type '(choice
+ (const :tag "Enable in all major modes" t)
+ (const :tag "Don't enable in any major mode" nil)
+ (repeat
+ :tag "Rules (earlier takes precedence)..."
+ (choice
+ (const :tag "Enable in all (other) modes" t)
+ (const :tag "Don't enable in any (other) mode" nil)
+ (symbol :value fundamental-mode
+ :tag "Enable in major mode")
+ (cons :tag "Don't enable in major modes"
+ (const :tag "Don't enable in..." not)
+ (repeat (symbol :value fundamental-mode
+ :tag "Major mode"))))))
,@group))
;; Autoloading define-globalized-minor-mode autoloads everything
@@ -610,36 +614,19 @@ list."
;; List of buffers left to process.
(defvar ,MODE-buffers nil)
- ;; The function that calls TURN-ON in each buffer.
- (defun ,MODE-enable-in-buffers ()
- (let ((buffers ,MODE-buffers))
- ;; Clear MODE-buffers to avoid scanning the same list of
- ;; buffers in recursive calls to MODE-enable-in-buffers.
- ;; Otherwise it could lead to infinite recursion.
- (setq ,MODE-buffers nil)
- (dolist (buf buffers)
- (when (buffer-live-p buf)
- (with-current-buffer buf
- (unless ,MODE-set-explicitly
- (unless (eq ,MODE-major-mode major-mode)
- (if ,MODE-variable
- (progn
- (,mode -1)
- (funcall ,turn-on-function))
- (funcall ,turn-on-function))))
- (setq ,MODE-major-mode major-mode))))))
- (put ',MODE-enable-in-buffers 'definition-name ',global-mode)
-
- (defun ,MODE-check-buffers ()
- (,MODE-enable-in-buffers)
- (remove-hook 'post-command-hook #',MODE-check-buffers))
- (put ',MODE-check-buffers 'definition-name ',global-mode)
-
- ;; The function that catches kill-all-local-variables.
- (defun ,MODE-cmhh ()
- (add-to-list ',MODE-buffers (current-buffer))
- (add-hook 'post-command-hook #',MODE-check-buffers))
- (put ',MODE-cmhh 'definition-name ',global-mode))))
+ ;; The function that calls TURN-ON in the current buffer.
+ (defun ,MODE-enable-in-buffer ()
+ ;; Remove ourselves from the list of pending buffers.
+ (setq ,MODE-buffers (delq (current-buffer) ,MODE-buffers))
+ (unless ,MODE-set-explicitly
+ (unless (eq ,MODE-major-mode major-mode)
+ (if ,MODE-variable
+ (progn
+ (,mode -1)
+ (funcall ,turn-on-function))
+ (funcall ,turn-on-function))))
+ (setq ,MODE-major-mode major-mode))
+ (put ',MODE-enable-in-buffer 'definition-name ',global-mode))))
(defun easy-mmode--globalized-predicate-p (predicate)
(cond
@@ -662,7 +649,7 @@ list."
(throw 'found nil))
((and (consp elem)
(eq (car elem) 'not))
- (when (apply #'derived-mode-p (cdr elem))
+ (when (derived-mode-p (cdr elem))
(throw 'found nil)))
((symbolp elem)
(when (derived-mode-p elem)
@@ -693,6 +680,7 @@ Valid keywords and arguments are:
:group Ignored.
:suppress Non-nil to call `suppress-keymap' on keymap,
`nodigits' to suppress digits as prefix arguments."
+ (declare (obsolete define-keymap "29.1"))
(let (inherit dense suppress)
(while args
(let ((key (pop args))
@@ -733,9 +721,7 @@ The M, BS, and ARGS arguments are as per that function. DOC is
the constant's documentation.
This macro is deprecated; use `defvar-keymap' instead."
- ;; FIXME: Declare obsolete in favor of `defvar-keymap'. It is still
- ;; used for `gud-menu-map' and `gud-minor-mode-map', so fix that first.
- (declare (doc-string 3) (indent 1))
+ (declare (doc-string 3) (indent 1) (obsolete defvar-keymap "29.1"))
`(defconst ,m
(easy-mmode-define-keymap ,bs nil (if (boundp ',m) ,m) ,(cons 'list args))
,doc))
@@ -839,6 +825,12 @@ Interactively, COUNT is the prefix numeric argument, and defaults to 1."
,@body))
(put ',prev-sym 'definition-name ',base))))
+;; When deleting these two, also delete them from loaddefs-gen.el.
+;;;###autoload
+(define-obsolete-function-alias 'easy-mmode-define-minor-mode #'define-minor-mode "30.1")
+;;;###autoload
+(define-obsolete-function-alias 'easy-mmode-define-global-mode #'define-globalized-minor-mode "30.1")
+
(provide 'easy-mmode)
;;; easy-mmode.el ends here