aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS.org1
-rw-r--r--compat-31.el4
-rw-r--r--compat-tests.el17
-rw-r--r--compat.texi5
4 files changed, 26 insertions, 1 deletions
diff --git a/NEWS.org b/NEWS.org
index bc0fc46..b1974a2 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -17,6 +17,7 @@
- compat-31: New function =hash-table-contains-p=.
- compat-31: New function =remove-display-text-property=.
- compat-31: New functions =drop-while=, =take-while=, =member-if=, =any=, =all=.
+- compat-31: New function =set-local=.
- Drop support for Emacs 24.x. Emacs 25.1 is required now. In case
Emacs 24.x support is still needed, Compat 30 can be used.
diff --git a/compat-31.el b/compat-31.el
index 1e4f24f..4133bdb 100644
--- a/compat-31.el
+++ b/compat-31.el
@@ -29,6 +29,10 @@
;;;; Defined in subr.el
+(compat-defun set-local (variable value) ;; <compat-tests:set-local>
+ "Make VARIABLE buffer local and set it to VALUE."
+ (set (make-local-variable variable) value))
+
(compat-defun take-while (pred list) ;; <compat-tests:take-while>
"Return the longest prefix of LIST whose elements satisfy PRED."
(let ((r nil))
diff --git a/compat-tests.el b/compat-tests.el
index 241149d..0ad9b42 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -967,7 +967,22 @@
compat-tests--local-c 3)
(should-equal compat-tests--local-a 1)
(should-equal compat-tests--local-b 2)
- (should-equal compat-tests--local-c 3))
+ (should-equal compat-tests--local-c 3)
+ (compat-call setq-local
+ compat-tests--local-a nil
+ compat-tests--local-b nil
+ compat-tests--local-c nil))
+
+(ert-deftest compat-set-local ()
+ (set-local 'compat-tests--local-a 1)
+ (set-local 'compat-tests--local-b 2)
+ (set-local 'compat-tests--local-c 3)
+ (should-equal compat-tests--local-a 1)
+ (should-equal compat-tests--local-b 2)
+ (should-equal compat-tests--local-c 3)
+ (set-local 'compat-tests--local-a nil)
+ (set-local 'compat-tests--local-b nil)
+ (set-local 'compat-tests--local-c nil))
(defvar compat-tests--global)
(defvar compat-tests--local)
diff --git a/compat.texi b/compat.texi
index 3786e91..6b2862a 100644
--- a/compat.texi
+++ b/compat.texi
@@ -3459,6 +3459,11 @@ older than 31.1. Note that due to upstream changes, it might happen
that there will be the need for changes, so use these functions with
care.
+@c based on lisp/subr.el
+@defun set-local variable value
+Make @var{variable} buffer local and set it to @var{value}.
+@end defun
+
@c copied from lispref/lists.texi
@defun drop-while pred list
This function skips leading list elements for which the predicate @var{pred}