diff options
| author | Lars Ingebrigtsen | 2021-02-04 15:22:40 +0100 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2021-02-04 15:22:40 +0100 |
| commit | e1d54bb638dfb017acb778a45092f97bb0d3427c (patch) | |
| tree | 8c6f1c69188826ef7385f8da840bb19673e7f114 | |
| parent | bd795dd659d6f67077f1870bbb775df15ce6001b (diff) | |
| download | emacs-e1d54bb638dfb017acb778a45092f97bb0d3427c.tar.gz emacs-e1d54bb638dfb017acb778a45092f97bb0d3427c.zip | |
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).
| -rw-r--r-- | doc/lispref/modes.texi | 5 | ||||
| -rw-r--r-- | lisp/emacs-lisp/easy-mmode.el | 4 |
2 files changed, 8 insertions, 1 deletions
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. | |||
| 1826 | Use @code{:group @var{group}} in @var{keyword-args} to specify the | 1826 | Use @code{:group @var{group}} in @var{keyword-args} to specify the |
| 1827 | custom group for the mode variable of the global minor mode. | 1827 | custom group for the mode variable of the global minor mode. |
| 1828 | 1828 | ||
| 1829 | By default, the buffer-local minor mode variable that says whether the | ||
| 1830 | mode is switched on or off is the same as the name of the mode itself. | ||
| 1831 | Use @code{:variable @var{variable}} if that's not the case--some minor | ||
| 1832 | modes use a different variable to store this state information. | ||
| 1833 | |||
| 1829 | Generally speaking, when you define a globalized minor mode, you should | 1834 | Generally speaking, when you define a globalized minor mode, you should |
| 1830 | also define a non-globalized version, so that people can use (or | 1835 | also define a non-globalized version, so that people can use (or |
| 1831 | disable) it in individual buffers. This also allows them to disable a | 1836 | 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. | |||
| 418 | (pretty-global-name (easy-mmode-pretty-mode-name global-mode)) | 418 | (pretty-global-name (easy-mmode-pretty-mode-name global-mode)) |
| 419 | (group nil) | 419 | (group nil) |
| 420 | (extra-keywords nil) | 420 | (extra-keywords nil) |
| 421 | (MODE-variable mode) | ||
| 421 | (MODE-buffers (intern (concat global-mode-name "-buffers"))) | 422 | (MODE-buffers (intern (concat global-mode-name "-buffers"))) |
| 422 | (MODE-enable-in-buffers | 423 | (MODE-enable-in-buffers |
| 423 | (intern (concat global-mode-name "-enable-in-buffers"))) | 424 | (intern (concat global-mode-name "-enable-in-buffers"))) |
| @@ -439,6 +440,7 @@ on if the hook has explicitly disabled it. | |||
| 439 | (pcase keyw | 440 | (pcase keyw |
| 440 | (:group (setq group (nconc group (list :group (pop body))))) | 441 | (:group (setq group (nconc group (list :group (pop body))))) |
| 441 | (:global (pop body)) | 442 | (:global (pop body)) |
| 443 | (:variable (setq MODE-variable (pop body))) | ||
| 442 | (:predicate | 444 | (:predicate |
| 443 | (setq predicate (list (pop body))) | 445 | (setq predicate (list (pop body))) |
| 444 | (setq turn-on-function | 446 | (setq turn-on-function |
| @@ -541,7 +543,7 @@ list." | |||
| 541 | (with-current-buffer buf | 543 | (with-current-buffer buf |
| 542 | (unless ,MODE-set-explicitly | 544 | (unless ,MODE-set-explicitly |
| 543 | (unless (eq ,MODE-major-mode major-mode) | 545 | (unless (eq ,MODE-major-mode major-mode) |
| 544 | (if ,mode | 546 | (if ,MODE-variable |
| 545 | (progn | 547 | (progn |
| 546 | (,mode -1) | 548 | (,mode -1) |
| 547 | (funcall ,turn-on-function)) | 549 | (funcall ,turn-on-function)) |