summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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.