mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-11-23 07:19:15 +00:00
Move buffer-local-set-state to subr because it's used at runtime
* lisp/subr.el (buffer-local-set-state) (buffer-local-set-state--get, buffer-local-restore-state): Moved from easy-mmode.el because they have to be available run-time.
This commit is contained in:
parent
92bbe911e9
commit
afc14e4f66
@ -825,42 +825,6 @@ Interactively, COUNT is the prefix numeric argument, and defaults to 1."
|
|||||||
,@body))
|
,@body))
|
||||||
(put ',prev-sym 'definition-name ',base))))
|
(put ',prev-sym 'definition-name ',base))))
|
||||||
|
|
||||||
|
|
||||||
(defmacro buffer-local-set-state (&rest pairs)
|
|
||||||
"Like `setq-local', but allow restoring the previous state of locals later.
|
|
||||||
This macro returns an object that can be passed to `buffer-local-restore-state'
|
|
||||||
in order to restore the state of the local variables set via this macro.
|
|
||||||
|
|
||||||
\(fn [VARIABLE VALUE]...)"
|
|
||||||
(declare (debug setq))
|
|
||||||
(unless (zerop (mod (length pairs) 2))
|
|
||||||
(error "PAIRS must have an even number of variable/value members"))
|
|
||||||
`(prog1
|
|
||||||
(buffer-local-set-state--get ',pairs)
|
|
||||||
(setq-local ,@pairs)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun buffer-local-set-state--get (pairs)
|
|
||||||
(let ((states nil))
|
|
||||||
(while pairs
|
|
||||||
(push (list (car pairs)
|
|
||||||
(and (boundp (car pairs))
|
|
||||||
(local-variable-p (car pairs)))
|
|
||||||
(and (boundp (car pairs))
|
|
||||||
(symbol-value (car pairs))))
|
|
||||||
states)
|
|
||||||
(setq pairs (cddr pairs)))
|
|
||||||
(nreverse states)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun buffer-local-restore-state (states)
|
|
||||||
"Restore values of buffer-local variables recorded in STATES.
|
|
||||||
STATES should be an object returned by `buffer-local-set-state'."
|
|
||||||
(pcase-dolist (`(,variable ,local ,value) states)
|
|
||||||
(if local
|
|
||||||
(set variable value)
|
|
||||||
(kill-local-variable variable))))
|
|
||||||
|
|
||||||
(provide 'easy-mmode)
|
(provide 'easy-mmode)
|
||||||
|
|
||||||
;;; easy-mmode.el ends here
|
;;; easy-mmode.el ends here
|
||||||
|
@ -8852,18 +8852,7 @@ CSS contains a list of syntax specifications of the form (CHAR . SYNTAX).
|
|||||||
|
|
||||||
(function-put 'easy-mmode-defsyntax 'lisp-indent-function '1)
|
(function-put 'easy-mmode-defsyntax 'lisp-indent-function '1)
|
||||||
|
|
||||||
(autoload 'buffer-local-set-state--get "easy-mmode" "\
|
(register-definition-prefixes "easy-mmode" '("easy-mmode-"))
|
||||||
|
|
||||||
|
|
||||||
\(fn PAIRS)" nil nil)
|
|
||||||
|
|
||||||
(autoload 'buffer-local-restore-state "easy-mmode" "\
|
|
||||||
Restore buffer local variable values in STATES.
|
|
||||||
STATES is an object returned by `buffer-local-set-state'.
|
|
||||||
|
|
||||||
\(fn STATES)" nil nil)
|
|
||||||
|
|
||||||
(register-definition-prefixes "easy-mmode" '("buffer-local-set-state" "easy-mmode-"))
|
|
||||||
|
|
||||||
;;;***
|
;;;***
|
||||||
|
|
||||||
|
33
lisp/subr.el
33
lisp/subr.el
@ -207,6 +207,39 @@ Also see `local-variable-p'."
|
|||||||
(:success t)
|
(:success t)
|
||||||
(void-variable nil)))
|
(void-variable nil)))
|
||||||
|
|
||||||
|
(defmacro buffer-local-set-state (&rest pairs)
|
||||||
|
"Like `setq-local', but allow restoring the previous state of locals later.
|
||||||
|
This macro returns an object that can be passed to `buffer-local-restore-state'
|
||||||
|
in order to restore the state of the local variables set via this macro.
|
||||||
|
|
||||||
|
\(fn [VARIABLE VALUE]...)"
|
||||||
|
(declare (debug setq))
|
||||||
|
(unless (zerop (mod (length pairs) 2))
|
||||||
|
(error "PAIRS must have an even number of variable/value members"))
|
||||||
|
`(prog1
|
||||||
|
(buffer-local-set-state--get ',pairs)
|
||||||
|
(setq-local ,@pairs)))
|
||||||
|
|
||||||
|
(defun buffer-local-set-state--get (pairs)
|
||||||
|
(let ((states nil))
|
||||||
|
(while pairs
|
||||||
|
(push (list (car pairs)
|
||||||
|
(and (boundp (car pairs))
|
||||||
|
(local-variable-p (car pairs)))
|
||||||
|
(and (boundp (car pairs))
|
||||||
|
(symbol-value (car pairs))))
|
||||||
|
states)
|
||||||
|
(setq pairs (cddr pairs)))
|
||||||
|
(nreverse states)))
|
||||||
|
|
||||||
|
(defun buffer-local-restore-state (states)
|
||||||
|
"Restore values of buffer-local variables recorded in STATES.
|
||||||
|
STATES should be an object returned by `buffer-local-set-state'."
|
||||||
|
(pcase-dolist (`(,variable ,local ,value) states)
|
||||||
|
(if local
|
||||||
|
(set variable value)
|
||||||
|
(kill-local-variable variable))))
|
||||||
|
|
||||||
(defmacro push (newelt place)
|
(defmacro push (newelt place)
|
||||||
"Add NEWELT to the list stored in the generalized variable PLACE.
|
"Add NEWELT to the list stored in the generalized variable PLACE.
|
||||||
This is morally equivalent to (setf PLACE (cons NEWELT PLACE)),
|
This is morally equivalent to (setf PLACE (cons NEWELT PLACE)),
|
||||||
|
@ -60,16 +60,4 @@
|
|||||||
(easy-mmode-test-mode 'toggle)
|
(easy-mmode-test-mode 'toggle)
|
||||||
(should (eq easy-mmode-test-mode t))))
|
(should (eq easy-mmode-test-mode t))))
|
||||||
|
|
||||||
(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
|
;;; easy-mmode-tests.el ends here
|
||||||
|
@ -1058,5 +1058,17 @@ final or penultimate step during initialization."))
|
|||||||
(should (equal (kbd "C-x ( C-d C-x )") ""))
|
(should (equal (kbd "C-x ( C-d C-x )") ""))
|
||||||
(should (equal (kbd "C-x ( C-x )") "")))
|
(should (equal (kbd "C-x ( C-x )") "")))
|
||||||
|
|
||||||
|
(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)))))
|
||||||
|
|
||||||
(provide 'subr-tests)
|
(provide 'subr-tests)
|
||||||
;;; subr-tests.el ends here
|
;;; subr-tests.el ends here
|
||||||
|
Loading…
Reference in New Issue
Block a user