emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/setup a3c1e11b39: Add forms to `setup-make-setter` for


From: ELPA Syncer
Subject: [elpa] externals/setup a3c1e11b39: Add forms to `setup-make-setter` for working on lists.
Date: Tue, 20 Sep 2022 04:58:27 -0400 (EDT)

branch: externals/setup
commit a3c1e11b398c231d87e13ebc4ebaee3ea34539c0
Author: Earl Hyatt <okamsn@protonmail.com>
Commit: Philip Kaludercic <philipk@posteo.net>

    Add forms to `setup-make-setter` for working on lists.
    
    Similar to `prepend`, `append`, and `remove`, add the forms `prepend*`,
    `append*`, and `remove*`.  Instead of the values being single items, they 
are
    list of items.
    
    For example,
    
        (setup test
          (:option (remove* my-list) some-list))
    
    would remove all of the items in `some-list` from the user option `my-list`.
    
    Discussed 
https://lists.sr.ht/~pkal/public-inbox/%3Cd78121f9-a854-7efe-5b2d-5ee8cf3cdd3a%40protonmail.com%3E.
---
 setup.el | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/setup.el b/setup.el
index de4a0c9c95..d5e49be715 100644
--- a/setup.el
+++ b/setup.el
@@ -319,6 +319,18 @@ VAL into one s-expression."
                          (if (member ,sym list)
                              list
                            (append list (list ,sym)))))))
+          ((eq (car-safe name) 'append*)
+           (funcall wrap-fn
+                    (cadr name)
+                    (let ((sym (gensym))
+                          (i (gensym)))
+                      `(let ((list ,(funcall old-val-fn (cadr name)))
+                             (,sym nil))
+                         (dolist (,i ,val)
+                           (if (member ,i list)
+                               nil
+                             (push ,i ,sym)))
+                         (append list (nreverse ,sym))))))
           ((eq (car-safe name) 'prepend)
            (funcall wrap-fn
                     (cadr name)
@@ -328,10 +340,30 @@ VAL into one s-expression."
                          (if (member ,sym list)
                              list
                            (cons ,sym list))))))
+          ((eq (car-safe name) 'prepend*)
+           (funcall wrap-fn
+                    (cadr name)
+                    (let ((sym (gensym))
+                          (i (gensym)))
+                      `(let ((list ,(funcall old-val-fn (cadr name)))
+                             (,sym nil))
+                         (dolist (,i ,val)
+                           (if (member ,i list)
+                               nil
+                             (push ,i ,sym)))
+                         (append (nreverse ,sym) list)))))
           ((eq (car-safe name) 'remove)
            (funcall wrap-fn
                     (cadr name)
                     `(remove ,val ,(funcall old-val-fn (cadr name)))))
+          ((eq (car-safe name) 'remove*)
+           (funcall wrap-fn
+                    (cadr name)
+                    (let ((i (gensym)))
+                      `(let ((list ,(funcall old-val-fn (cadr name))))
+                         (dolist (,i ,val)
+                           (setq list (remove ,i list)))
+                         list))))
           ((error "Invalid option %S" name)))))
 
 
@@ -543,6 +575,17 @@ supported:
 (remove VAR)    Assuming VAR designates a list, remove all instances
                 of VAL.
 
+(append* VAR)  Assuming VAR designates a list, add each element
+               of VAL to the end of VAR, keeping their order,
+               unless it is already a member of the list.
+
+(prepend* VAR) Assuming VAR designates a list, add each element
+               of VAL to the start of VAR, keeping their order,
+               unless it is already a member of the list.
+
+(remove* VAR)  Assuming VAR designates a list, remove all
+               instances of each element of VAL.
+
 Note that if the value of an option is modified partially by
 append, prepend, remove, one should ensure that the default value
 has been loaded. Also keep in mind that user options customized



reply via email to

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