From e089914f96caf5e1a74acb75995634c34455a290 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Sun, 2 Nov 2014 13:40:46 -0500 Subject: Simplify filter-store-all by modifying *-store --- stack-filter.el | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'stack-filter.el') diff --git a/stack-filter.el b/stack-filter.el index 91c4875..4210549 100644 --- a/stack-filter.el +++ b/stack-filter.el @@ -76,29 +76,28 @@ or string." "Retrieve named FILTER from `stack-filter-cache-file'." (cdr (assoc filter (stack-cache-get stack-filter-cache-file)))) -(defun stack-filter-store (name filter) +(defun stack-filter-store (name &optional filter) "Store NAME as FILTER in `stack-filter-cache-file'. 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)) - (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 +`stack-filter-compile'. + +If NAME is a cons cell, (car NAME) is taken to be the actual NAME +and (cdr NAME) is taken to be the actual FILTER. In this case, +the second argument is simply ignored." + (let ((name (if (consp name) (car name) name)) + (filter (if (consp name) (cdr name) filter))) + (unless (symbolp name) + (error "Name must be a symbol: %S" name)) + (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)))) + (defun stack-filter-store-all (name-filter-alist) - (when name-filter-alist - (stack-filter-store - (caar name-filter-alist) - (cdar name-filter-alist)) - (stack-filter-store-all - (cdr name-filter-alist)))) + (mapc #'stack-filter-store name-filter-alist)) (provide 'stack-filter) ;;; stack-filter.el ends here -- cgit v1.2.3