]> git.eshelyaron.com Git - emacs.git/commitdiff
Make ibuffer filters idempotent
authorTino Calancha <tino.calancha@gmail.com>
Fri, 20 Oct 2017 13:11:39 +0000 (22:11 +0900)
committerTino Calancha <tino.calancha@gmail.com>
Fri, 20 Oct 2017 13:11:39 +0000 (22:11 +0900)
* 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
lisp/ibuf-macs.el

index 686bc392b6051fc98f1864a812e6f435f9e6777d..2c841fa7e0a20d8d569e6dda5645ae6a865167c5 100644 (file)
@@ -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 ()
index e0c91e20edd6391f136144ef8ebd0aa8b1d530b2..c30067f2f58c64a2a01a472c35c8a349d96624e4 100644 (file)
@@ -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