Subject: 27.0.50; Ibuffer filters should be idempotent
From: Tino Calancha <[email-masked]>
To: [email-masked]
Date: Sat, 14 Oct 2017 11:56:39 +0900
List-Id: <debbugs-submit.debbugs.gnu.org>

emacs -Q
M-x ibuffer RET
/n s RET
/n s RET ; again
;; ibuffer-filtering-qualifiers contains twice the filter
;; You can read on top:
;; Ibuffer by recency [buffer name: s] [buffer name: s]

--8<-----------------------------cut here---------------start------------->8---
commit d65a5a22981dccc69a6e26cde1e567d109e884b3
Author: Tino Calancha <[email-masked]>
Date:   Sat Oct 14 11:30:32 2017 +0900

    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.

diff --git a/lisp/ibuf-ext.el b/lisp/ibuf-ext.el
index 686bc392b6..097a7b3b43 100644
--- a/lisp/ibuf-ext.el
+++ b/lisp/ibuf-ext.el
@@ -1034,7 +1034,8 @@ ibuffer-pop-filter
 
 (defun ibuffer-push-filter (filter-specification)
   "Add FILTER-SPECIFICATION to `ibuffer-filtering-qualifiers'."
-  (push filter-specification ibuffer-filtering-qualifiers))
+  (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 e0c91e20ed..c30067f2f5 100644
--- a/lisp/ibuf-macs.el
+++ b/lisp/ibuf-macs.el
@@ -301,12 +301,16 @@ ibuffer-save-marks
        (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
--8<-----------------------------cut here---------------end--------------->8---

In GNU Emacs 27.0.50 (build 16, x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
 of 2017-10-14
Repository revision: 78479a3984047a8153b43571e6b5ebfb674223a4