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

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

[elpa] externals/setup 87fcdf4 12/17: Improve (append ...) and (prepend


From: Stefan Monnier
Subject: [elpa] externals/setup 87fcdf4 12/17: Improve (append ...) and (prepend ...) support
Date: Sat, 13 Mar 2021 18:15:14 -0500 (EST)

branch: externals/setup
commit 87fcdf42ef7abc1b58c149f8dadbc5086c7d7a71
Author: Philip K <philipk@posteo.net>
Commit: Philip K <philipk@posteo.net>

    Improve (append ...) and (prepend ...) support
---
 setup.el | 50 ++++++++++++++++++++++++++++++++------------------
 1 file changed, 32 insertions(+), 18 deletions(-)

diff --git a/setup.el b/setup.el
index 2f1df75..d3bda35 100644
--- a/setup.el
+++ b/setup.el
@@ -290,27 +290,28 @@ A documentation string."
 
 (setup-define :option
   (lambda (var val)
-    (cond ((symbolp var)
-           `(customize-set-variable ',var ,val "Modified by `setup'"))
+    (cond ((symbolp var) t)
           ((eq (car-safe var) 'append)
-           `(customize-set-variable
-             ',(cadr var)
-             (append (funcall (or (get ',(cadr var) 'custom-get) 'symbol-value)
-                              ',(cadr var))
-                     (list ,val))
-             "Modified by `setup'"))
+           (setq var (cadr var)
+                 val `(append (funcall (or (get ',var 'custom-get)
+                                           #'symbol-value)
+                                       ',var)
+                              (list ,val))))
           ((eq (car-safe var) 'prepend)
-           `(customize-set-variable
-             ',(cadr var)
-             (cons ,val (funcall (or (get ',(cadr var) 'custom-get) 
'symbol-value)
-                                ',(cadr var)))
-             "Modified by `setup'"))))
+           (setq var (cadr var)
+                 val `(cons ,val
+                            (funcall (or (get ',var 'custom-get)
+                                         #'symbol-value)
+                                     ',var))))
+          ((error "Invalid variable %S" var)))
+    `(customize-set-variable ',var ,val "Modified by `setup'"))
   :signature '(NAME VAL ...)
   :documentation "Set the option NAME to VAL.
 
 NAME may be a symbol, or a cons-cell.  If NAME is a cons-cell, it
 will use the car value to modify the behaviour.  If NAME has the
-form (append VAR), "
+form (append VAR), VAL is appended to VAR.  If NAME has the
+form (prepend VAR), VAL is prepended to VAR."
   :repeatable t)
 
 (setup-define :hide-mode
@@ -321,10 +322,23 @@ form (append VAR), "
   :after-loaded t)
 
 (setup-define :local-set
-  (lambda (var val)
-    `(add-hook setup-hook (lambda () (setq-local ,var ,val))))
-  :signature '(VAR VAL ...)
-  :documentation "Set the value of VAR to VAL in buffers of the current mode."
+  (lambda (name val)
+    (cond ((symbolp name) t)
+          ((eq (car-safe name) 'append)
+           (setq name (cadr name)
+                 val `(append ,name (list val))))
+          ((eq (car-safe name) 'prepend)
+           (setq name (cadr name)
+                 val `(cons ,val ,name)))
+          ((error "Invalid variable %S" name)))
+    `(add-hook setup-hook (lambda () (setq-local ,name ,val))))
+  :signature '(name VAL ...)
+  :documentation "Set the value of NAME to VAL in buffers of the current mode.
+
+NAME may be a symbol, or a cons-cell.  If NAME is a cons-cell, it
+will use the car value to modify the behaviour.  If NAME has the
+form (append VAR), VAL is appended to VAR.  If NAME has the
+form (prepend VAR), VAL is prepended to VAR."
   :repeatable t)
 
 (setup-define :local-hook



reply via email to

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