From 5fb7f96d886848f6d3b2401a895fb1e203190ca9 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Sat, 1 Aug 2020 20:07:22 +0530 Subject: 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. --- ennum.el | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'ennum.el') 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. -- cgit v1.2.3