From 5f69c222f47dfb339304b57083cb68c1da340271 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Sun, 31 Jan 2021 14:55:53 +0100 Subject: Prefer defvar-local in emacs-lisp/*.el * lisp/emacs-lisp/chart.el (chart-local-object): * lisp/emacs-lisp/easy-mmode.el (define-minor-mode) (define-globalized-minor-mode): * lisp/emacs-lisp/edebug.el: * lisp/emacs-lisp/generic.el (generic-font-lock-keywords): * lisp/emacs-lisp/re-builder.el (reb-regexp, reb-regexp-src) (reb-overlays): * lisp/emacs-lisp/syntax.el (syntax-propertize-extend-region-functions): Prefer defvar-local. --- lisp/emacs-lisp/easy-mmode.el | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'lisp/emacs-lisp/easy-mmode.el') diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el index f4dbcee4d69..54c0cf08b78 100644 --- a/lisp/emacs-lisp/easy-mmode.el +++ b/lisp/emacs-lisp/easy-mmode.el @@ -278,11 +278,10 @@ For example, you could write ((not globalp) `(progn :autoload-end - (defvar ,mode ,init-value + (defvar-local ,mode ,init-value ,(concat (format "Non-nil if %s is enabled.\n" pretty-name) (internal--format-docstring-line - "Use the command `%s' to change this variable." mode))) - (make-variable-buffer-local ',mode))) + "Use the command `%s' to change this variable." mode))))) (t (let ((base-doc-string (concat "Non-nil if %s is enabled. @@ -453,8 +452,7 @@ on if the hook has explicitly disabled it. (progn (put ',global-mode 'globalized-minor-mode t) :autoload-end - (defvar ,MODE-major-mode nil) - (make-variable-buffer-local ',MODE-major-mode)) + (defvar-local ,MODE-major-mode nil)) ;; The actual global minor-mode (define-minor-mode ,global-mode ,(concat (format "Toggle %s in all buffers.\n" pretty-name) -- cgit v1.2.3 From e1d54bb638dfb017acb778a45092f97bb0d3427c Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Thu, 4 Feb 2021 15:22:40 +0100 Subject: Allow a :variable keyword in define-globalized-minor-mode * doc/lispref/modes.texi (Defining Minor Modes): Document it. * lisp/emacs-lisp/easy-mmode.el (define-globalized-minor-mode): Allow specifying a :variable to be used if the underlying mode has a divergent variable to store the state (bug#29081). --- doc/lispref/modes.texi | 5 +++++ lisp/emacs-lisp/easy-mmode.el | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'lisp/emacs-lisp/easy-mmode.el') diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi index abc12546410..ce7727b87eb 100644 --- a/doc/lispref/modes.texi +++ b/doc/lispref/modes.texi @@ -1826,6 +1826,11 @@ starts, for example by providing a @code{:require} keyword. Use @code{:group @var{group}} in @var{keyword-args} to specify the custom group for the mode variable of the global minor mode. +By default, the buffer-local minor mode variable that says whether the +mode is switched on or off is the same as the name of the mode itself. +Use @code{:variable @var{variable}} if that's not the case--some minor +modes use a different variable to store this state information. + Generally speaking, when you define a globalized minor mode, you should also define a non-globalized version, so that people can use (or disable) it in individual buffers. This also allows them to disable a diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el index 54c0cf08b78..2916ae4adea 100644 --- a/lisp/emacs-lisp/easy-mmode.el +++ b/lisp/emacs-lisp/easy-mmode.el @@ -418,6 +418,7 @@ on if the hook has explicitly disabled it. (pretty-global-name (easy-mmode-pretty-mode-name global-mode)) (group nil) (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"))) @@ -439,6 +440,7 @@ on if the hook has explicitly disabled it. (pcase keyw (:group (setq group (nconc group (list :group (pop body))))) (:global (pop body)) + (:variable (setq MODE-variable (pop body))) (:predicate (setq predicate (list (pop body))) (setq turn-on-function @@ -541,7 +543,7 @@ list." (with-current-buffer buf (unless ,MODE-set-explicitly (unless (eq ,MODE-major-mode major-mode) - (if ,mode + (if ,MODE-variable (progn (,mode -1) (funcall ,turn-on-function)) -- cgit v1.2.3