From 5b9aacba827bb61cdffa21ba724bb8cb198bc9e7 Mon Sep 17 00:00:00 2001 From: 0xhenrique Date: Sat, 31 May 2025 05:12:32 +0100 Subject: refactor read function and add flush cache function --- esb.el | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/esb.el b/esb.el index 83eb947..0aba035 100644 --- a/esb.el +++ b/esb.el @@ -45,14 +45,20 @@ "Read and decrypt bookmarks from file." (esb--ensure-epa-setup) (if (file-exists-p esb-bookmarks-file) - (with-temp-buffer - (insert-file-contents esb-bookmarks-file) - (condition-case err - (json-parse-string (buffer-string) :array-type 'list :object-type 'alist) - (json-error - (message "Error parsing bookmarks file: %s" err) - nil))) - nil)) + (with-temp-buffer + (insert-file-contents esb-bookmarks-file) + (let ((content (string-trim (buffer-string)))) + (if (string-empty-p content) + '() + (condition-case err + (let ((parsed (json-parse-string content :array-type 'list :object-type 'alist))) + (if (eq parsed :null) + '() + parsed)) + (json-error + (message "Error parsing bookmarks file: %s" err) + '()))))) + '())) (defun esb--write-bookmarks (bookmarks) "Encrypt and write BOOKMARKS to file." @@ -178,6 +184,15 @@ (esb--write-bookmarks '()) (message "Initialized empty bookmark file at: %s" esb-bookmarks-file))) +;;;###autoload +(defun esb-flush-cache () + "Flush the bookmark cache and force reload from file." + (interactive) + (setq esb-bookmarks-cache nil) + (setq esb-cache-dirty nil) + (message "Bookmark cache flushed")) + + ;;;###autoload -- cgit v1.3