From ee6fe8378a28444cb4913abca4af742f736e9b45 Mon Sep 17 00:00:00 2001 From: Tino Calancha Date: Fri, 20 Oct 2017 22:11:39 +0900 Subject: [PATCH] Make ibuffer filters idempotent * lisp/ibuf-ext.el (ibuffer-push-filter): Check if the filter is already in effect (Bug#28826). * lisp/ibuf-macs.el (define-ibuffer-filter): Report to user if the filter was already enabled. --- lisp/ibuf-ext.el | 7 +++++-- lisp/ibuf-macs.el | 16 ++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lisp/ibuf-ext.el b/lisp/ibuf-ext.el index 686bc392b60..2c841fa7e0a 100644 --- a/lisp/ibuf-ext.el +++ b/lisp/ibuf-ext.el @@ -1033,8 +1033,11 @@ group definitions by setting `ibuffer-filter-groups' to nil." (ibuffer-jump-to-buffer (buffer-name buf))))) (defun ibuffer-push-filter (filter-specification) - "Add FILTER-SPECIFICATION to `ibuffer-filtering-qualifiers'." - (push filter-specification ibuffer-filtering-qualifiers)) + "Add FILTER-SPECIFICATION to `ibuffer-filtering-qualifiers'. +If FILTER-SPECIFICATION is already in the list then return nil. Otherwise, +return the updated list." + (unless (member filter-specification ibuffer-filtering-qualifiers) + (push filter-specification ibuffer-filtering-qualifiers))) ;;;###autoload (defun ibuffer-decompose-filter () diff --git a/lisp/ibuf-macs.el b/lisp/ibuf-macs.el index e0c91e20edd..c30067f2f58 100644 --- a/lisp/ibuf-macs.el +++ b/lisp/ibuf-macs.el @@ -301,12 +301,16 @@ bound to the current value of the filter. (defun ,fn-name (qualifier) ,(or documentation "This filter is not documented.") (interactive (list ,reader)) - (ibuffer-push-filter (cons ',name qualifier)) - (message "%s" - (format ,(concat (format "Filter by %s added: " description) - " %s") - qualifier)) - (ibuffer-update nil t)) + (if (null (ibuffer-push-filter (cons ',name qualifier))) + (message "%s" + (format ,(concat (format "Filter by %s already applied: " description) + " %s") + qualifier)) + (message "%s" + (format ,(concat (format "Filter by %s added: " description) + " %s") + qualifier)) + (ibuffer-update nil t))) (push (list ',name ,description (lambda (buf qualifier) (condition-case nil -- 2.39.2