From 22ee290ca7a7b625fa9f1a1bb420a08fc94e51a7 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Fri, 4 Mar 2022 14:17:42 -0600 Subject: cleaned up merge-into-cache --- src/lib.lisp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'src/lib.lisp') diff --git a/src/lib.lisp b/src/lib.lisp index b5256fe..ec44bca 100644 --- a/src/lib.lisp +++ b/src/lib.lisp @@ -76,19 +76,18 @@ (uiop:delete-file-if-exists (cached-oneliners-file))) (defun merge-into-cache (new-ols) - (if (uiop:file-exists-p (cached-oneliners-file)) - (let ((cached-ols (with-open-file (input (cached-oneliners-file)) (read input)))) - (with-open-file (out (cached-oneliners-file) :direction :output :if-exists :supersede) - (print - (nconc - new-ols - (remove-if - (lambda (old) - (find (getf old :id) new-ols :key (lambda (x) (getf x :id)))) - cached-ols)) - out))) - (with-open-file (out (cached-oneliners-file) :direction :output) - (print new-ols out)))) + (let* ((cached + (when (uiop:file-exists-p (cached-oneliners-file)) + (with-open-file (input (cached-oneliners-file)) (read input)))) + (updated + (append + new-ols + (loop for old in cached + for id = (getf old :id) + unless (find id new-ols :key (lambda (x) (getf x :id))) + collect old)))) + (with-open-file (output (cached-oneliners-file) :direction :output :if-exists :supersede) + (print updated output)))) ;;; UTILITIES (defun make-temp-file-name () @@ -115,7 +114,9 @@ the directories that appear in the value of that variable." (make-pathname :name name :directory directory)))) (defun tags-from-oneliner (oneliner) - (remove-if-not #'executable-on-system-p (ppcre:split " +" oneliner))) + (remove-duplicates + (remove-if-not #'executable-on-system-p (ppcre:split " +" oneliner)) + :test #'equal)) (defun prompt (prompt &key -- cgit v1.2.3