Subject: bug#32731: closed (Re: bug#32731: 26.1.50; Ibuffer filter by mode: Handle >1 mode names)

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 29 Sep 2018 09:50:02 +0000

Your bug report

#32731: 26.1.50; Ibuffer filter by mode: Handle >1 mode names

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
32731: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=32731
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#32731: 26.1.50; Ibuffer filter by mode: Handle >1 mode names
From: Tino Calancha <[email-masked]>
To: [email-masked]
Date: Sat, 29 Sep 2018 18:49:03 +0900
List-Id: <debbugs-submit.debbugs.gnu.org>

Robert Pluim <[email-masked]> writes:

> Eli Zaretskii <[email-masked]> writes:
>
>>> From: Tino Calancha <[email-masked]>
>>> Date: Tue, 25 Sep 2018 05:48:43 +0900 (JST)
>>> Cc: Tino Calancha <[email-masked]>, [email-masked],
>>> 	[email-masked]
>>> 
>>> > "She/he" seems to exclude nonbinary genders.
>>> > "S?he" does not HAVE to mean "only she or he".
>>> I don't feel excluded if I read "she".  Maybe I have enough 
>>> self-confidence or I know the difference between
>>> sex and gramatical genre.
>>> Anyway, whatever Eli likes is fine for me.
>>
>> I usually just rewrite the text to be in plural, like "the users"
>> instead of "the user".  Then "they" is correct English.
>
> Point of order: singular they has been correct English for the last
> 700 years. Some people donʼt like it, but that doesnʼt make it wrong.
My grandmother used to say:
"You'll never go to bed without learning a new thing"

[I know, every grandmother says that; same as the best
food is the one prepared by the mother of the person you are asking.]

I will write it in plural.  Thank you all for the feedback!

Implemented at master branch as commit
'Ibuffer filter by modes: Accept several mode names'
(2296bf188fc99d66306e71e6decd3d2e176b7ae6)

Subject: 26.1.50; Ibuffer filter by mode: Handle >1 mode names
From: Tino Calancha <[email-masked]>
To: [email-masked]
Date: Fri, 14 Sep 2018 03:19:21 +0900
List-Id: <debbugs-submit.debbugs.gnu.org>

Severity: wishlist

Ibuffer filtering is a great feature.
If you just want to filter by 1 major, then it's quite straight.

/m [mode1-name] RET

Filtering by >1 major mode is still possible; you must
combine the individuals filters with `ibuffer-or-filter':

/m [mode1-name] RET
/m [mode2-name] RET
/|
/m [mode3-name] RET
/|
.
.
.
/m [modeN-name] RET
/|

This become a bit cumbersome with > 2 mode names; you also need to
remember how to combine filters, which I usually forget :-|

Following patch adds a new command `ibuffer-filter-by-used-modes',
similar as `ibuffer-filter-by-used-mode', to simplify this filtering.

The new command accepts a list of mode names, and it takes care
internally of the filter composition.

Interactively, it preserves the interface of `ibuffer-filter-by-used-mode',
with the only difference that the user might input a comma separated
list of mode names.  For instance,

;; Following produces identical result as the original command
M-x ibuffer-filter-by-used-modes RET mode1-mode RET

;; This is equivalent to create the N filters + OR-compose them
M-x ibuffer-filter-by-used-modes RET mode1-mode,mode2-mode,...,modeN-mode RET

--8<-----------------------------cut here---------------start------------->8---
commit e36ff5779764e531cc149e4342e93cb6e37c30ee
Author: Tino Calancha <[email-masked]>
Date:   Fri Sep 14 03:10:11 2018 +0900

    Ibuffer filter by mode: Handle >1 mode names
    
    Extend used mode filtering so that we can input >1 mode.
    For instance, if we want to filter all buffers in
    C or C++ mode, then we can call the filter interactively
    with input: 'c-mode,c++-mode'.
    
    * lisp/ibuf-ext.el (ibuffer-filter-by-used-modes):
    New command.  Accept a list of mode names (symbols).
    Interactively, accept a comma separated list of mode names.
    * lisp/ibuffer.el(ibuffer-mode-map): Rebind '/ m' to
    the new command.
    * etc/NEWS(Ibuffer): Announce this change.

diff --git a/etc/NEWS b/etc/NEWS
index a54ac2db43..6ef6f20b05 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -48,6 +48,11 @@ often cause crashes.  Set it to nil if you really need those fonts.
 ** Ibuffer
 
 ---
+*** The new command 'ibuffer-filter-by-used-modes', bound
+to '/ m', extends 'ibuffer-filter-by-used-mode'; it makes easy
+filtering buffers by a list of major modes.
+
+---
 *** New toggle 'ibuffer-do-toggle-lock', bound to 'L'.
 
 ** Imenu
diff --git a/lisp/ibuf-ext.el b/lisp/ibuf-ext.el
index a3143e5e29..b7c3ae8030 100644
--- a/lisp/ibuf-ext.el
+++ b/lisp/ibuf-ext.el
@@ -1265,6 +1265,34 @@ used-mode
        (ibuffer-list-buffer-modes) nil t nil nil default))))
   (eq qualifier (buffer-local-value 'major-mode buf)))
 
+;;;###autoload
+(defun ibuffer-filter-by-used-modes(modes)
+  "Limit current view to buffers with major mode in MODES.
+MODES is a list of mode names (symbols).
+When called interactively, accept the mode names separated by commas."
+  (interactive
+   (let* ((buf (ibuffer-current-buffer))
+          (default (if (and buf (buffer-live-p buf))
+                       (symbol-name (buffer-local-value
+                                     'major-mode buf)))))
+     (list
+      (mapcar #'intern
+              (split-string
+               (completing-read
+                (if default
+                    (format "Filter by major mode (default %s): " default)
+                  "Filter by major mode: ")
+                (ibuffer-list-buffer-modes)
+                nil nil nil nil default)
+               "\\s-*,\\s-*" t)))))
+  (setq modes (delete-dups modes))
+  (mapc #'ibuffer-filter-by-used-mode modes)
+  (let ((nb_modes (length modes)))
+    (when (>= nb_modes 2)
+      (cl-loop repeat (- nb_modes 2) do (ibuffer-or-filter))
+      (message nil)
+      (ibuffer-or-filter))))
+
 ;;;###autoload (autoload 'ibuffer-filter-by-derived-mode "ibuf-ext")
 (define-ibuffer-filter derived-mode
     "Limit current view to buffers whose major mode inherits from QUALIFIER."
diff --git a/lisp/ibuffer.el b/lisp/ibuffer.el
index 08b0801cb5..f7c20d0da3 100644
--- a/lisp/ibuffer.el
+++ b/lisp/ibuffer.el
@@ -519,7 +519,7 @@ ibuffer-mode-map
     (define-key map (kbd "s m") 'ibuffer-do-sort-by-major-mode)
 
     (define-key map (kbd "/ RET") 'ibuffer-filter-by-mode)
-    (define-key map (kbd "/ m") 'ibuffer-filter-by-used-mode)
+    (define-key map (kbd "/ m") 'ibuffer-filter-by-used-modes)
     (define-key map (kbd "/ M") 'ibuffer-filter-by-derived-mode)
     (define-key map (kbd "/ n") 'ibuffer-filter-by-name)
     (define-key map (kbd "/ *") 'ibuffer-filter-by-starred-name)
--8<-----------------------------cut here---------------end--------------->8---
In GNU Emacs 26.1.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
 of 2018-09-14 built
Repository revision: 41cdda22c78eb0b00612ce25cdb356dd64322fcc