append-to-last, tags-add - clarify code

This commit is contained in:
contrapunctus 2020-05-15 13:00:39 +05:30
parent 4fbce30490
commit 5840e6bc27

View File

@ -73,15 +73,19 @@ be removed."
(old-start (plist-get old-expr :start)) (old-start (plist-get old-expr :start))
(old-stop (plist-get old-expr :stop)) (old-stop (plist-get old-expr :stop))
(old-tags (plist-get old-expr :tags)) (old-tags (plist-get old-expr :tags))
;; Anything that's left will be the user's key-values.
(old-kvs (chronometrist-plist-remove old-expr :name :tags :start :stop)) (old-kvs (chronometrist-plist-remove old-expr :name :tags :start :stop))
(plist-clean (chronometrist-plist-remove plist :name :tags :start :stop)) ;; Prevent the user from adding reserved key-values.
(plist (chronometrist-plist-remove plist :name :tags :start :stop))
(new-tags (if old-tags (new-tags (if old-tags
(-> (append old-tags tags) (-> (append old-tags tags)
(cl-remove-duplicates :test #'equal)) (cl-remove-duplicates :test #'equal))
tags)) tags))
;; In case there is an overlap in key-values, we use
;; plist-put to replace old ones with new ones.
(new-kvs (cl-copy-list old-expr)) (new-kvs (cl-copy-list old-expr))
(new-kvs (if plist-clean (new-kvs (if plist
(-> (cl-loop for (key val) on plist-clean by #'cddr (-> (cl-loop for (key val) on plist by #'cddr
do (plist-put new-kvs key val) do (plist-put new-kvs key val)
finally return new-kvs) finally return new-kvs)
(chronometrist-plist-remove :name :tags :start :stop)) (chronometrist-plist-remove :name :tags :start :stop))
@ -182,11 +186,11 @@ used in `chronometrist-before-out-functions'."
(chronometrist-tags-prompt last-name) (chronometrist-tags-prompt last-name)
(chronometrist-maybe-string-to-symbol)))) (chronometrist-maybe-string-to-symbol))))
(when input (when input
(-> (append last-tags input) (--> (append last-tags input)
(reverse) (reverse it)
(cl-remove-duplicates :test #'equal) (cl-remove-duplicates it :test #'equal)
(reverse) (reverse it)
(chronometrist-append-to-last nil))) (chronometrist-append-to-last it nil)))
t)) t))
;;;; KEY-VALUES ;;;; ;;;; KEY-VALUES ;;;;