diff --git a/elfeed-prune.el b/elfeed-prune.el index 5044424..a547143 100644 --- a/elfeed-prune.el +++ b/elfeed-prune.el @@ -64,20 +64,25 @@ to t you are aware of the risks." :group 'elfeed-prune :type 'boolean) -(defcustom elfeed-prune-predicate #'elfeed-prune--elfeed-prune-entry-p - "Function that determines which entries should be pruned. +(defcustom elfeed-prune-predicates + (list #'elfeed-prune--entry-too-old-p) + "Entries that match *any* of these predicates are pruned. -The function accepts two parameters: the entry and the feed it -belongs to. These are the data structures defined in the -elfeed-db.el package. - -Look inside `elfeed-prune--elfeed-prune-entry-p' for examples of -using these data structures. Otherwise consult the elfeed-db.el -sources." +Each predicate accepts an entry and a feed object and should +return t when the entry should be pruned, unless any of the +predicates in `elfeed-prune-keep-predicates' returns t." :group 'elfeed-prune - :type 'function) + :type 'list) -(defun elfeed-prune--entry-too-old-p (entry) +(defcustom elfeed-prune-keep-predicates nil + "Always keep entries that match one of these predicates. + +Each predicate accepts an entry and a feed object and should +return t when the entry should be kept." + :group 'elfeed-prune + :type 'list) + +(defun elfeed-prune--entry-too-old-p (entry _) "Return t if the given ENTRY is considered too old. The thresholds are configured through the variables @@ -92,30 +97,6 @@ The thresholds are configured through the variables (entry-age (- current-time entry-time))) (> entry-age threshold-seconds))) -(defun elfeed-prune--elfeed-prune-entry-p (entry feed) - "Return t if the ENTRY should be removed from the database. - -FEED can be used to remove entries for a whole feed. - -Conditions, any of: -- non-existing feed (not in `elfeed-feeds') -- has tag `rm' -- older than 90 days - -Unless: -- score > 2 -- has star tag" - (let ((tags (elfeed-entry-tags entry)) - (score (elfeed-score-scoring-get-score-from-entry entry))) - (and (or (seq-contains-p tags 'rm) - (elfeed-prune--entry-too-old-p entry) - (not (seq-contains-p (mapcar #'car elfeed-feeds) - (elfeed-feed-url feed) - #'string=)) - (<= score -5)) - (not (> score 2)) - (not (seq-contains-p tags 'star))))) - (defun elfeed-prune (&optional dry-run) "Prune the database entries. @@ -135,12 +116,18 @@ area." (elfeed-db-entries-copy (copy-hash-table elfeed-db-entries))) ;; Remove entries (with-elfeed-db-visit (entry feed) - ;; The `with-elfeed-db-visit' declares the variable `id' that - ;; contains the entry ID. - (when (funcall elfeed-prune-predicate entry feed) - (setq removed-entries (1+ removed-entries)) - (avl-tree-delete elfeed-db-index-copy id) - (remhash id elfeed-db-entries-copy))) + (let ((prune-p (seq-some + (lambda (f) (funcall f entry feed)) + elfeed-prune-predicates)) + (keep-p (seq-some + (lambda (f) (funcall f entry feed)) + elfeed-prune-keep-predicates))) + (when (and prune-p (not keep-p)) + ;; The `with-elfeed-db-visit' declares the variable `id' that + ;; contains the entry ID. + (setq removed-entries (1+ removed-entries)) + (avl-tree-delete elfeed-db-index-copy id) + (remhash id elfeed-db-entries-copy)))) (when (and elfeed-prune-enabled (not dry-run)