From c4c87049805730f791a69a8a47702a13afe31c07 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Mon, 26 Aug 2019 13:43:55 +0530 Subject: 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. --- ennu.el | 27 ++++++++++++++++----------- 1 file 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)) -- cgit v1.2.3