]> git.eshelyaron.com Git - emacs.git/commitdiff
ibuffer-decompose-filter-group avoid unwanted side effects
authorTino Calancha <tino.calancha@gmail.com>
Wed, 7 Dec 2016 12:49:50 +0000 (21:49 +0900)
committerTino Calancha <tino.calancha@gmail.com>
Wed, 7 Dec 2016 12:49:50 +0000 (21:49 +0900)
* lisp/ibuf-ext.el (ibuffer-delete-alist): Remove it.
(ibuffer-remove-alist): New defun; it supersedes 'ibuffer-delete-alist'.
All callers changed (Bug#25058).
* test/lisp/ibuffer-tests.el (ibuffer-test-Bug25058): Add test.

lisp/ibuf-ext.el
test/lisp/ibuffer-tests.el

index cc2942c911902557363911e688f101a4baf6f422..e64be437adc696fff33a9e4cca555d17e30cb693 100644 (file)
   (require 'subr-x))
 
 ;;; Utility functions
-(defun ibuffer-delete-alist (key alist)
-  "Delete all entries in ALIST that have a key equal to KEY."
-  (let (entry)
-    (while (setq entry (assoc key alist))
-      (setq alist (delete entry alist)))
-    alist))
+(defun ibuffer-remove-alist (key alist)
+  "Remove all entries in ALIST that have a key equal to KEY."
+  (while (ibuffer-awhen (assoc key alist)
+           (setq alist (remove it alist)) it))
+  alist)
 
 ;; borrowed from Gnus
 (defun ibuffer-remove-duplicates (list)
@@ -372,7 +371,7 @@ the mode if ARG is omitted or nil."
   (let ((buf (ibuffer-current-buffer)))
     (if (assq 'mode ibuffer-filtering-qualifiers)
        (setq ibuffer-filtering-qualifiers
-             (ibuffer-delete-alist 'mode ibuffer-filtering-qualifiers))
+             (ibuffer-remove-alist 'mode ibuffer-filtering-qualifiers))
       (ibuffer-push-filter (cons 'mode (buffer-local-value 'major-mode buf)))))
   (ibuffer-update nil t))
 
@@ -645,7 +644,7 @@ To evaluate a form without viewing the buffer, see `ibuffer-do-eval'."
                              (append ibuffer-filter-groups
                                      (list (cons "Default" nil))))))
     ;; (dolist (hidden ibuffer-hidden-filter-groups)
-    ;;   (setq filter-group-alist (ibuffer-delete-alist
+    ;;   (setq filter-group-alist (ibuffer-remove-alist
     ;;                            hidden filter-group-alist)))
     (let ((vec (make-vector (length filter-group-alist) nil))
          (i 0))
@@ -729,7 +728,7 @@ To evaluate a form without viewing the buffer, see `ibuffer-do-eval'."
   (interactive
    (list (ibuffer-read-filter-group-name "Decompose filter group: " t)))
   (let ((data (cdr (assoc group ibuffer-filter-groups))))
-    (setq ibuffer-filter-groups (ibuffer-delete-alist
+    (setq ibuffer-filter-groups (ibuffer-remove-alist
                                 group ibuffer-filter-groups)
          ibuffer-filtering-qualifiers data))
   (ibuffer-update nil t))
@@ -777,7 +776,7 @@ The group will be added to `ibuffer-filter-group-kill-ring'."
   (ibuffer-aif (assoc name ibuffer-filter-groups)
       (progn
        (push (copy-tree it) ibuffer-filter-group-kill-ring)
-       (setq ibuffer-filter-groups (ibuffer-delete-alist
+       (setq ibuffer-filter-groups (ibuffer-remove-alist
                                     name ibuffer-filter-groups))
        (setq ibuffer-hidden-filter-groups
              (delete name ibuffer-hidden-filter-groups)))
@@ -867,7 +866,7 @@ They are removed from `ibuffer-saved-filter-groups'."
       (completing-read "Delete saved filter group: "
                       ibuffer-saved-filter-groups nil t))))
   (setq ibuffer-saved-filter-groups
-       (ibuffer-delete-alist name ibuffer-saved-filter-groups))
+       (ibuffer-remove-alist name ibuffer-saved-filter-groups))
   (ibuffer-maybe-save-stuff)
   (ibuffer-update nil t))
 
@@ -1033,7 +1032,7 @@ Interactively, prompt for NAME, and use the current filters."
       (completing-read "Delete saved filters: "
                       ibuffer-saved-filters nil t))))
   (setq ibuffer-saved-filters
-       (ibuffer-delete-alist name ibuffer-saved-filters))
+       (ibuffer-remove-alist name ibuffer-saved-filters))
   (ibuffer-maybe-save-stuff)
   (ibuffer-update nil t))
 
index 799f3fbbdc75d29296f07660b8c0eaddde9f0c57..9fdaaf0e097fda029c02e619dc518da05f204afb 100644 (file)
     (should (equal (cdr (assoc "test2" ibuffer-saved-filters)) test2))
     (should (equal (cdr (assoc "test3" ibuffer-saved-filters)) test3))))
 
+(ert-deftest ibuffer-test-Bug25058 ()
+  "Test for http://debbugs.gnu.org/25058 ."
+  (ibuffer)
+  (let ((orig-filters ibuffer-saved-filter-groups)
+        (tmp-filters '(("saved-filters"
+                        ("Shell"
+                         (used-mode . shell-mode))
+                        ("Elisp"
+                         (or
+                          (used-mode . emacs-lisp-mode)
+                          (used-mode . lisp-interaction-mode)))
+                        ("Dired"
+                         (used-mode . dired-mode))
+                        ("Info"
+                         (or
+                          (used-mode . help-mode)
+                          (used-mode . debugger-mode)
+                          (used-mode . Custom-mode)
+                          (used-mode . completion-list-mode)
+                          (name . "\\`[*]Messages[*]\\'")))))))
+    (unwind-protect
+        (progn
+          (setq ibuffer-saved-filter-groups tmp-filters)
+         (ibuffer-switch-to-saved-filter-groups "saved-filters")
+          (ibuffer-decompose-filter-group "Elisp")
+          (ibuffer-filter-disable)
+          (ibuffer-switch-to-saved-filter-groups "saved-filters")
+          (should (assoc "Elisp" (cdar ibuffer-saved-filter-groups))))
+      (setq ibuffer-saved-filter-groups orig-filters)
+      (ibuffer-awhen (get-buffer "*Ibuffer*")
+        (and (buffer-live-p it) (kill-buffer it))))))
+
+
 (provide 'ibuffer-tests)
 ;; ibuffer-tests.el ends here