aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2020-08-01 20:07:22 +0530
committerArun Isaac2020-08-02 03:20:15 +0530
commit5fb7f96d886848f6d3b2401a895fb1e203190ca9 (patch)
treea7beb1a6ee1946a63e01bcde8e6904510c2ecb48
parent0b0f36bf5c574a5f5ccad87a869f6899856c062b (diff)
downloadennum-5fb7f96d886848f6d3b2401a895fb1e203190ca9.tar.gz
ennum-5fb7f96d886848f6d3b2401a895fb1e203190ca9.tar.lz
ennum-5fb7f96d886848f6d3b2401a895fb1e203190ca9.zip
Create a functional setter for ennum-post-translations.
* ennum.el (ennum-make-functional-setter): New macro. (ennum-post-set-translations): New function. (ennum-posts): Use ennum-post-set-translations.
-rw-r--r--ennum.el21
1 files changed, 14 insertions, 7 deletions
diff --git a/ennum.el b/ennum.el
index b92ec2c..00927df 100644
--- a/ennum.el
+++ b/ennum.el
@@ -130,11 +130,20 @@ respectively by - and _, and the pad character = is optional."
(reverse (ennum-directory-files item nil t))))
(ennum-input items))))
+(defmacro ennum-make-functional-setter (name copier accessor)
+ `(defun ,name (object new-value)
+ (let ((object-copy (,copier object)))
+ (setf (,accessor object-copy) new-value)
+ object-copy)))
+
(cl-defstruct (ennum-post (:constructor ennum-make-post)
(:copier ennum-copy-post))
filename slug author date language links tangle
summary tags thumbnail title translation-group translations)
+(ennum-make-functional-setter
+ ennum-post-set-translations ennum-copy-post ennum-post-translations)
+
(cl-defstruct (ennum-link (:constructor ennum-make-link)
(:copier nil))
type path)
@@ -154,13 +163,11 @@ respectively by - and _, and the pad character = is optional."
(ennum-post-slug post)))
posts)))
(seq-map (lambda (post)
- (let ((post-copy (ennum-post-copy post)))
- (setf (ennum-post-translations post-copy)
- (seq-remove (pcase-lambda (`(,_ . ,slug))
- (string= (ennum-post-slug post)
- slug))
- translations))
- post-copy))
+ (ennum-post-set-translations
+ post
+ (seq-remove (pcase-lambda (`(,_ . ,slug))
+ (string= (ennum-post-slug post) slug))
+ translations)))
posts)))
;; Read posts from org files and group them by translation
;; group.