Add new helper macros for minor modes to restore variables

* doc/lispref/modes.texi (Defining Minor Modes): Document it.

* lisp/emacs-lisp/easy-mmode.el (buffer-local-set-state): New macro.
(buffer-local-set-state--get): Helper function.
(buffer-local-restore-state): New function.

* lisp/textmodes/word-wrap-mode.el (word-wrap-whitespace-mode):
Use it to simplify code.
This commit is contained in:
Lars Ingebrigtsen 2022-05-06 13:10:45 +02:00
parent 0bda1803bb
commit b13356487f
5 changed files with 66 additions and 19 deletions

View file

@ -60,6 +60,16 @@
(easy-mmode-test-mode 'toggle)
(should (eq easy-mmode-test-mode t))))
(provide 'easy-mmode-tests)
(ert-deftest test-local-set-state ()
(setq global 1)
(with-temp-buffer
(setq-local local 2)
(let ((state (buffer-local-set-state global 10
local 20
unexist 30)))
(buffer-local-restore-state state)
(should (= global 1))
(should (= local 2))
(should-not (boundp 'unexist)))))
;;; easy-mmode-tests.el ends here