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

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

[elpa] externals/leaf be3b434 16/29: Merge pull request #450 from conao3


From: Stefan Monnier
Subject: [elpa] externals/leaf be3b434 16/29: Merge pull request #450 from conao3/feature#449
Date: Tue, 10 Nov 2020 14:47:42 -0500 (EST)

branch: externals/leaf
commit be3b4346de404f5c736878b167060325b0ddaaf3
Merge: 7520119 6b827f5
Author: Naoya Yamashita <conao3@gmail.com>
Commit: GitHub <noreply@github.com>

    Merge pull request #450 from conao3/feature#449
    
    feature#449
---
 README.org    | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 leaf-tests.el | 23 +++++++++++++++++++
 leaf.el       | 17 +++++++++++++-
 3 files changed, 113 insertions(+), 1 deletion(-)

diff --git a/README.org b/README.org
index 834fa53..c3badca 100644
--- a/README.org
+++ b/README.org
@@ -57,6 +57,7 @@
   - [[#contribution][Contribution]]
     - [[#leafel-mechanism][leaf.el mechanism]]
     - [[#adding-new-keywords][Adding new keywords]]
+    - [[#customize-leaf-keywords][Customize leaf keywords]]
   - [[#migration][Migration]]
     - [[#leaf-v10-to-v20][leaf v3.0 to v4.0]]
     - [[#leaf-v20-to-v30][leaf v2.0 to v3.0]]
@@ -2258,6 +2259,79 @@ In 
[[https://github.com/conao3/leaf-keywords.el][leaf-keywords.el]], you can see
 Note that leaf only contains keywords for packages that come with the Emacs 
standard,
 and that keywords that depend on external packages are added to its repository.
 
+*** Customize leaf keywords
+~leaf~ stores "keyword" and corresponding "expandion" in ~leaf-keywords~.
+You can customize ~leaf~ expandion to customize ~leaf-keywords~.
+
+#+begin_src emacs-lisp
+(leaf-plist-get :custom leaf-keywords)
+;;=> ...
+
+(ppp-macroexpand
+ (leaf foo-package
+   :custom
+   (foo-package-to-enable   . t)
+   (foo-package-to-disable  . nil)
+   (foo-package-to-symbol   . 'symbol)
+   (foo-package-to-function . #'ignore)
+   (foo-package-to-lambda   . (lambda (elm) (message elm)))))
+;;=> (prog1 'foo-package
+;;     (customize-set-variable 'foo-package-to-enable t "Customized with leaf 
in foo-package block")
+;;     (customize-set-variable 'foo-package-to-disable nil "Customized with 
leaf in foo-package block")
+;;     (customize-set-variable 'foo-package-to-symbol 'symbol "Customized with 
leaf in foo-package block")
+;;     (customize-set-variable 'foo-package-to-function #'ignore "Customized 
with leaf in foo-package block")
+;;     (customize-set-variable 'foo-package-to-lambda
+;;                             (lambda (elm)
+;;                               (message elm))
+;;                             "Customized with leaf in foo-package block"))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(setf (leaf-plist-get :custom leaf-keywords)
+      '`(,@(mapcar (lambda (elm) `(customize-set-variable ',(car elm) ,(cdr 
elm) ,(format "leaf block" leaf--name))) leaf--value) ,@leaf--body))
+;;=> ...
+
+(ppp-macroexpand
+ (leaf foo-package
+   :custom
+   (foo-package-to-enable   . t)
+   (foo-package-to-disable  . nil)
+   (foo-package-to-symbol   . 'symbol)
+   (foo-package-to-function . #'ignore)
+   (foo-package-to-lambda   . (lambda (elm) (message elm)))))
+;;=> (prog1 'foo-package
+;;     (customize-set-variable 'foo-package-to-enable t "leaf block")
+;;     (customize-set-variable 'foo-package-to-disable nil "leaf block")
+;;     (customize-set-variable 'foo-package-to-symbol 'symbol "leaf block")
+;;     (customize-set-variable 'foo-package-to-function #'ignore "leaf block")
+;;     (customize-set-variable 'foo-package-to-lambda
+;;                             (lambda (elm)
+;;                               (message elm))
+;;                             "leaf block"))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(setf (leaf-plist-get :custom leaf-keywords)
+      '`(,@(mapcar (lambda (elm) `(setq ',(car elm) ,(cdr elm))) leaf--value) 
,@leaf--body))
+;;=> ...
+
+(ppp-macroexpand
+ (leaf foo-package
+   :custom
+   (foo-package-to-enable   . t)
+   (foo-package-to-disable  . nil)
+   (foo-package-to-symbol   . 'symbol)
+   (foo-package-to-function . #'ignore)
+   (foo-package-to-lambda   . (lambda (elm) (message elm)))))
+;;=> (prog1 'foo-package
+;;     (setq 'foo-package-to-enable t)
+;;     (setq 'foo-package-to-disable nil)
+;;     (setq 'foo-package-to-symbol 'symbol)
+;;     (setq 'foo-package-to-function #'ignore)
+;;     (setq 'foo-package-to-lambda (lambda (elm)
+;;                                    (message elm))))
+#+end_src
+
 ** Migration
 *** leaf v3.0 to v4.0
 **** Drop support for Emacs versions lower than Emacs-24.4
diff --git a/leaf-tests.el b/leaf-tests.el
index 477ccc3..ff47f0e 100644
--- a/leaf-tests.el
+++ b/leaf-tests.el
@@ -2780,6 +2780,29 @@ Example:
        (mapcar 'car (cdr (assoc "Leaf" (funcall 
imenu-create-index-function)))))
      '("scala-mode" "lsp-metals" "*scala-flycheck-integration"))))
 
+(when (version<= "24.3" emacs-version)
+  (require 'cl-lib)
+  (cort-deftest-with-equal leaf/leaf-plist-get
+    '(((let ((target '(:a "a" :b "b" :c "c")))
+         (setf (leaf-plist-get :b target) "modify")
+         target)
+       '(:a "a" :b "modify" :c "c"))
+
+      ((let ((target '(:a "a" :b "b" :c "c")))
+         (cl-rotatef (leaf-plist-get :b target) (leaf-plist-get :c target))
+         target)
+       '(:a "a" :b "c" :c "b"))
+
+      ((let ((target '(:a "a" :b "b" :c "c")))
+         (setf (leaf-plist-get :d target) "modify")
+         target)
+       '(:d "modify" :a "a" :b "b" :c "c"))
+
+      ((let ((target '(:a "a" :b "b" :c "c")))
+         (cl-rotatef (leaf-plist-get :b target) (leaf-plist-get :d target))
+         target)
+       '(:d "b" :a "a" :b nil :c "c")))))
+
 ;; (provide 'leaf-tests)
 
 ;; Local Variables:
diff --git a/leaf.el b/leaf.el
index 03a62c4..aaacf04 100644
--- a/leaf.el
+++ b/leaf.el
@@ -5,7 +5,7 @@
 ;; Author: Naoya Yamashita <conao3@gmail.com>
 ;; Maintainer: Naoya Yamashita <conao3@gmail.com>
 ;; Keywords: lisp settings
-;; Version: 4.2.8
+;; Version: 4.2.9
 ;; URL: https://github.com/conao3/leaf.el
 ;; Package-Requires: ((emacs "24.4"))
 
@@ -542,6 +542,21 @@ Unlike `butlast', it works well with dotlist (last cdr is 
non-nil list)."
   (declare (indent 1))
   (or (and (plist-member plist key) (plist-get plist key)) default))
 
+(when (version<= "24.3" emacs-version)
+  (gv-define-expander leaf-plist-get
+    (lambda (do key plist &optional default)
+      (macroexp-let2 macroexp-copyable-p k key
+        (gv-letplace (getter setter) plist
+          (macroexp-let2 nil p `(plist-member ,getter ,k)
+            (funcall
+             do
+             (if (null default) `(cadr ,p)
+               `(if ,p (cadr ,p) ,default))
+             (lambda (val)
+               `(if (plist-member ,plist ,k)
+                    (setcar (cdr (plist-member ,plist ,k)) ,val)
+                  ,(funcall setter `(cons ,k (cons ,val ,getter))))))))))))
+
 ;;; General alist functions
 
 ;; for Emacs < 25.1



reply via email to

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