summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2019-08-26 13:43:55 +0530
committerArun Isaac2019-08-26 13:43:55 +0530
commitc4c87049805730f791a69a8a47702a13afe31c07 (patch)
treed2de017f2b8645ef5f7434d82af323de69e0903c
parentc8bb99b30e770668675128ddd3fb67e87c9376e1 (diff)
downloadennum-c4c87049805730f791a69a8a47702a13afe31c07.tar.gz
ennum-c4c87049805730f791a69a8a47702a13afe31c07.tar.lz
ennum-c4c87049805730f791a69a8a47702a13afe31c07.zip
Replace plist-put* by non-destructive ennu-plist-map-to-plist.
* ennu.el (plist-put*): Delete function. (ennu-plist-map-to-plist): New function. (ennu--post-metadata-memoized): Replace plist-put* by non-destructive ennu-plist-map-to-plist.
-rw-r--r--ennu.el27
1 files changed, 16 insertions, 11 deletions
diff --git a/ennu.el b/ennu.el
index 7169b9a..76485a3 100644
--- a/ennu.el
+++ b/ennu.el
@@ -241,12 +241,15 @@ last form in BODY."
(when (member link-type (list "image" "static" "video"))
(cons link-type (org-element-property :path link))))))))))
-(defun plist-put* (plist &rest key-value-pairs)
- (pcase key-value-pairs
- (`(,key ,value)
- (plist-put plist key value))
- (`(,key ,value . ,tail)
- (apply 'plist-put* (plist-put plist key value) tail))))
+(defun ennu-plist-map-to-plist (function plist)
+ "Apply FUNCTION to each key-value pair of PLIST and return the
+result as a plist with keys being the keys in PLIST and the
+values being the values returned by FUNCTION. FUNCTION is called
+with two arguments -- the key and the value."
+ (seq-mapcat
+ (pcase-lambda (`(,key ,value))
+ (list key (funcall function key value)))
+ (seq-partition plist 2)))
(defun ennu-post-metadata (post)
(ennu--post-metadata-memoized
@@ -261,11 +264,13 @@ last form in BODY."
(unless (plist-member metadata key)
(user-error "Metadata %s not specified" key)))
ennu-mandatory-metadata)
- (plist-put*
- metadata
- :title (funcall export (first (plist-get metadata :title)))
- :date (org-timestamp-to-time (first (plist-get metadata :date)))
- :author (funcall export (first (plist-get metadata :author)))))))
+ (ennu-plist-map-to-plist
+ (lambda (key value)
+ (pcase key
+ (:title (funcall export (first (plist-get metadata :title))))
+ (:date (org-timestamp-to-time (first (plist-get metadata :date))))
+ (:author (funcall export (first (plist-get metadata :author))))))
+ metadata))))
(defvar ennu-mandatory-metadata
(list :title :date))