[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master afc14e4f66: Move buffer-local-set-state to subr because it's used
From: |
Lars Ingebrigtsen |
Subject: |
master afc14e4f66: Move buffer-local-set-state to subr because it's used at runtime |
Date: |
Fri, 6 May 2022 10:10:09 -0400 (EDT) |
branch: master
commit afc14e4f661194969ef1622e2d9310cfbf662aff
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
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.
---
lisp/emacs-lisp/easy-mmode.el | 36 --------------------------------
lisp/ldefs-boot.el | 13 +-----------
lisp/subr.el | 33 +++++++++++++++++++++++++++++
test/lisp/emacs-lisp/easy-mmode-tests.el | 12 -----------
test/lisp/subr-tests.el | 12 +++++++++++
5 files changed, 46 insertions(+), 60 deletions(-)
diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el
index 2568eaeb76..54cac11616 100644
--- a/lisp/emacs-lisp/easy-mmode.el
+++ b/lisp/emacs-lisp/easy-mmode.el
@@ -825,42 +825,6 @@ Interactively, COUNT is the prefix numeric argument, and
defaults to 1."
,@body))
(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)
;;; easy-mmode.el ends here
diff --git a/lisp/ldefs-boot.el b/lisp/ldefs-boot.el
index c0a16f9198..b79c6b2a08 100644
--- a/lisp/ldefs-boot.el
+++ b/lisp/ldefs-boot.el
@@ -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)
-(autoload 'buffer-local-set-state--get "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-"))
+(register-definition-prefixes "easy-mmode" '("easy-mmode-"))
;;;***
diff --git a/lisp/subr.el b/lisp/subr.el
index dec3b9190e..5af802fa18 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -207,6 +207,39 @@ Also see `local-variable-p'."
(:success t)
(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)
"Add NEWELT to the list stored in the generalized variable PLACE.
This is morally equivalent to (setf PLACE (cons NEWELT PLACE)),
diff --git a/test/lisp/emacs-lisp/easy-mmode-tests.el
b/test/lisp/emacs-lisp/easy-mmode-tests.el
index 697bf6c215..f6d0719672 100644
--- a/test/lisp/emacs-lisp/easy-mmode-tests.el
+++ b/test/lisp/emacs-lisp/easy-mmode-tests.el
@@ -60,16 +60,4 @@
(easy-mmode-test-mode 'toggle)
(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
diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el
index 3725f180f3..6bcac2a5eb 100644
--- a/test/lisp/subr-tests.el
+++ b/test/lisp/subr-tests.el
@@ -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-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)
;;; subr-tests.el ends here
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master afc14e4f66: Move buffer-local-set-state to subr because it's used at runtime,
Lars Ingebrigtsen <=