From f349fe5d764730a0a339045a59a46d53b9a33100 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Sun, 2 Nov 2014 13:11:15 -0500 Subject: Implement and use `stack-cache-get' and `-set' --- stack-filter.el | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'stack-filter.el') diff --git a/stack-filter.el b/stack-filter.el index e5fb54d..91c4875 100644 --- a/stack-filter.el +++ b/stack-filter.el @@ -74,9 +74,7 @@ or string." (defun stack-filter-get (filter) "Retrieve named FILTER from `stack-filter-cache-file'." - (with-current-buffer (stack-cache-get-file stack-filter-cache-file) - (or (cdr (ignore-errors (assoc filter (read (buffer-string))))) - nil))) + (cdr (assoc filter (stack-cache-get stack-filter-cache-file)))) (defun stack-filter-store (name filter) "Store NAME as FILTER in `stack-filter-cache-file'. @@ -85,17 +83,12 @@ NAME should be a symbol and FILTER is a string as compiled by `stack-filter-compile'." (unless (symbolp name) (error "Name must be a symbol: %S" name)) - (with-current-buffer (stack-cache-get-file stack-filter-cache-file) - (let* ((dict (or (ignore-errors - (read (buffer-string))) - nil)) - (entry (assoc name dict))) - (if entry (setf (cdr entry) filter) - (setq dict (cons (cons name filter) dict))) - (erase-buffer) - (insert (prin1-to-string dict)) - (save-buffer) - dict))) + (let* ((dict (stack-cache-get stack-filter-cache-file)) + (entry (assoc name dict))) + (if entry (setcdr entry filter) + (setq dict (cons (cons name filter) dict))) + + (stack-cache-set stack-filter-cache-file dict))) ;;; TODO tail recursion should be made more efficient for the ;;; byte-compiler @@ -104,7 +97,8 @@ NAME should be a symbol and FILTER is a string as compiled by (stack-filter-store (caar name-filter-alist) (cdar name-filter-alist)) - (stack-filter-store-all (cdr name-filter-alist)))) + (stack-filter-store-all + (cdr name-filter-alist)))) (provide 'stack-filter) ;;; stack-filter.el ends here -- cgit v1.2.3