[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 9ad73f92617 1/2: New value 'permanent-only' for defcustom :local
From: |
Stefan Kangas |
Subject: |
master 9ad73f92617 1/2: New value 'permanent-only' for defcustom :local keyword |
Date: |
Tue, 1 Oct 2024 20:36:23 -0400 (EDT) |
branch: master
commit 9ad73f92617da1286724f9774b34bb7ce6a4299d
Author: Stefan Kangas <stefankangas@gmail.com>
Commit: Stefan Kangas <stefankangas@gmail.com>
New value 'permanent-only' for defcustom :local keyword
* lisp/custom.el (custom-declare-variable): Make the :local keyword
accept the symbol 'permanent-local', meaning that the variable is
permanent but not marked as automatically buffer-local.
(defcustom):
* doc/lispref/customize.texi (Variable Definitions): Document the
above change.
* test/lisp/custom-tests.el
(custom-tests-defcustom-:local-keyword): New test.
---
doc/lispref/customize.texi | 5 ++++-
etc/NEWS | 5 +++++
lisp/custom.el | 4 +++-
test/lisp/custom-tests.el | 29 +++++++++++++++++++++++++++++
4 files changed, 41 insertions(+), 2 deletions(-)
diff --git a/doc/lispref/customize.texi b/doc/lispref/customize.texi
index 33708d7faaa..b32f9dbb903 100644
--- a/doc/lispref/customize.texi
+++ b/doc/lispref/customize.texi
@@ -448,7 +448,10 @@ the build-time context. This also has the side-effect
that the
@kindex local@r{, @code{defcustom} keyword}
If the @var{value} is @code{t}, mark @var{option} as automatically
buffer-local; if the value is @code{permanent}, also set @var{option}s
-@code{permanent-local} property to @code{t}. @xref{Creating Buffer-Local}.
+@code{permanent-local} property to @code{t}. Finally, if the value is
+@code{permanent-only}, set @var{option}s @code{permanent-local} property
+to @code{t} without marking it as automatically buffer-local.
+@xref{Creating Buffer-Local}.
@item :risky @var{value}
@kindex risky@r{, @code{defcustom} keyword}
diff --git a/etc/NEWS b/etc/NEWS
index bc1d0cf52c8..6262405cdd2 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -492,6 +492,11 @@ sup-mouse.el, terminal.el, vi.el, vip.el, ws-mode.el, and
yow.el.
* Lisp Changes in Emacs 31.1
++++
+** The 'defcustom' :local keyword can now be 'permanent-only'.
+This means that the variable's 'permanent-local' property is set to t,
+without marking it as automatically buffer-local.
+
---
** The obsolete face attribute ':reverse-video' has been removed.
Use ':inverse-video' instead.
diff --git a/lisp/custom.el b/lisp/custom.el
index c7ce47d4e57..1eb6bb7d64d 100644
--- a/lisp/custom.el
+++ b/lisp/custom.el
@@ -204,7 +204,7 @@ set to nil, as the value is no longer rogue."
((eq keyword :local)
(when (memq value '(t permanent))
(setq buffer-local t))
- (when (eq value 'permanent)
+ (when (memq value '(permanent permanent-only))
(put symbol 'permanent-local t)))
((eq keyword :type)
(put symbol 'custom-type (purecopy value)))
@@ -300,6 +300,8 @@ The following keywords are meaningful:
:local If VALUE is t, mark SYMBOL as automatically buffer-local.
If VALUE is `permanent', also set SYMBOL's `permanent-local'
property to t.
+ If VALUE is `permanent-only', set SYMBOL's `permanent-local'
+ property to t, but do not mark it as automatically buffer-local.
The following common keywords are also meaningful.
diff --git a/test/lisp/custom-tests.el b/test/lisp/custom-tests.el
index c009abfe0d1..e963314fcca 100644
--- a/test/lisp/custom-tests.el
+++ b/test/lisp/custom-tests.el
@@ -325,4 +325,33 @@
;; But it was only for the current session, so this should not happen.
(should-not (get 'custom--test-bug-21355-after 'saved-value)))))
+(defcustom custom-tests--:local-nil nil
+ "Not local or permanent."
+ :type 'number
+ :group 'emacs)
+(defcustom custom-tests--:local-t nil
+ "Automatically local but not permanent."
+ :type 'number
+ :local t
+ :group 'emacs)
+(defcustom custom-tests--:local-permanent nil
+ "Automatically local and permanent."
+ :type 'number
+ :local 'permanent
+ :group 'emacs)
+(defcustom custom-tests--:local-permanent-only nil
+ "Permanent but not automatically local."
+ :type 'number
+ :local 'permanent-only
+ :group 'emacs)
+(ert-deftest custom-tests-defcustom-:local-keyword ()
+ (should-not (local-variable-if-set-p 'custom-tests--:local-nil))
+ (should-not (get 'custom-tests--:local-nil 'permanent-local))
+ (should (local-variable-if-set-p 'custom-tests--:local-t))
+ (should-not (get 'custom-tests--:local-t 'permanent-local))
+ (should (local-variable-if-set-p 'custom-tests--:local-permanent))
+ (should (get 'custom-tests--:local-permanent 'permanent-local))
+ (should-not (local-variable-if-set-p 'custom-tests--:local-permanent-only))
+ (should (get 'custom-tests--:local-permanent-only 'permanent-local)))
+
;;; custom-tests.el ends here