emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master c3a6bca 1/2: Add new utility function custom-add-choice


From: Lars Ingebrigtsen
Subject: master c3a6bca 1/2: Add new utility function custom-add-choice
Date: Sat, 8 Aug 2020 07:45:40 -0400 (EDT)

branch: master
commit c3a6bcac86fd386a31a3287a9818aa7c3568769c
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Add new utility function custom-add-choice
    
    * lisp/custom.el (custom-add-choice): New function (bug#41225).
---
 etc/NEWS       |  5 +++++
 lisp/custom.el | 14 ++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index de10b4a..2b3cc80 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -782,6 +782,11 @@ have now been removed.
 
 * Lisp Changes in Emacs 28.1
 
+---
+** New function 'custom-add-choice'.
+This function can be used by modes to add elements to the
+'choice' customization type of a variable.
+
 +++
 ** New function 'file-modes-number-to-symbolic' to convert a numeric
 file mode specification into symbolic form.
diff --git a/lisp/custom.el b/lisp/custom.el
index 885c486..0cb1363 100644
--- a/lisp/custom.el
+++ b/lisp/custom.el
@@ -1541,6 +1541,20 @@ Each of the arguments ARGS has this form:
 This means reset VARIABLE.  (The argument IGNORED is ignored)."
     (apply #'custom-theme-reset-variables 'user args))
 
+(defun custom-add-choice (variable choice)
+  "Add CHOICE to the custom type of VARIABLE.
+If a choice with the same tag already exists, no action is taken."
+  (let ((choices (get 'tab-bar-new-tab-choice 'custom-type)))
+    (unless (eq (car choices) 'choice)
+      (error "Not a choice type: %s" choices))
+    (unless (seq-find (lambda (elem)
+                        (equal (caddr (member :tag elem))
+                               (caddr (member :tag choice))))
+                      (cdr choices))
+      ;; Put the new choice at the end.
+      (put variable 'custom-type
+           (append (get variable 'custom-type) (list choice))))))
+
 ;;; The End.
 
 (provide 'custom)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]