all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tino Calancha <tino.calancha@gmail.com>
To: Noam Postavsky <npostavs@gmail.com>
Cc: 32731@debbugs.gnu.org
Subject: bug#32731: 26.1.50; Ibuffer filter by mode: Handle >1 mode names
Date: Sat, 15 Sep 2018 18:15:18 +0900	[thread overview]
Message-ID: <87worn86l5.fsf@calancha-pc.dy.bbexcite.jp> (raw)
In-Reply-To: <87ftydezmi.fsf@gmail.com> (Noam Postavsky's message of "Thu, 13 Sep 2018 19:39:17 -0400")

Noam Postavsky <npostavs@gmail.com> writes:

> Tino Calancha <tino.calancha@gmail.com> writes:
>
> Yeah, we need special cases for lists of zero and one modes.
No problem.

>> Less important but `define-ibuffer-filter' performs some checks
>> (there is a `condition-case').
>
> The condition-case thing is in a lambda form which goes into
> ibuffer-filtering-alist, so I don't think there is a need to explicitly
> invoke it when constructing a filter of an existing type.
Absolutely.  Sorry for the noise.

>> Next one just use `completing-read-multiple' (keeps calling
>> `'ibuffer-filter-by-used-mode'); I prefer this one:
>
> I would be okay if it was just a matter of repeated ibuffer-filter-*
> calls, but the fact that it produces error messages which then need to
> be hidden makes it unacceptable, IMO.
I agree with you: those messages must not be produced.

BTW, I've noticed following commit is missing in the release branch:
'Make ibuffer filters idempotent'
(ee6fe8378a28444cb4913abca4af742f736e9b45)

I suggest we backport it.
Then, I am OK with the next patch (which uses that commit):
--8<-----------------------------cut here---------------start------------->8---
commit c60a9bb36d4d4092866f36d1d8b246b79c1a2fd8
Author: Tino Calancha <tino.calancha@gmail.com>
Date:   Sat Sep 15 18:01:14 2018 +0900

    Ibuffer filter by modes: Accept several mode names
    
    Extend mode filters so that we can input more than 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.
    
    Co-authored-by: Noam Postavsky <npostavs@gmail.com>

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..7094ae2674 100644
--- a/lisp/ibuf-ext.el
+++ b/lisp/ibuf-ext.el
@@ -1265,6 +1265,35 @@ 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
+              (completing-read-multiple
+               (if default
+                   (format "Filter by major mode (default %s): " default)
+                 "Filter by major mode: ")
+               (ibuffer-list-buffer-modes)
+               nil t nil nil default)))))
+  ;; Sort to avoid adding filter (or mode2 mode1) once we have (or mode1 mode2)
+  (setq modes (sort (delete-dups modes) #'string-lessp))
+  (cond ((null (cdr modes)) (ibuffer-filter-by-used-mode (car modes)))
+        (t (let ((composed-filter
+                  `(or ,@(mapcar (lambda (m) `(used-mode . ,m)) modes)))
+                 (mode-names (mapconcat #'symbol-name modes ",")))
+             (if (null (ibuffer-push-filter composed-filter))
+                 (message "Filter by mode in use already applied: %s" mode-names)
+               (message "Filter by mode in use added: %s" mode-names)
+               (ibuffer-update nil t))))))
+
 ;;;###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.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
Repository revision: 41cdda22c78eb0b00612ce25cdb356dd64322fcc





  reply	other threads:[~2018-09-15  9:15 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-13 18:19 bug#32731: 26.1.50; Ibuffer filter by mode: Handle >1 mode names Tino Calancha
2018-09-13 19:09 ` Noam Postavsky
2018-09-13 20:04   ` Tino Calancha
2018-09-13 20:38   ` Tino Calancha
2018-09-13 23:39     ` Noam Postavsky
2018-09-15  9:15       ` Tino Calancha [this message]
2018-09-15 12:42         ` Noam Postavsky
2018-09-17 17:44           ` Tino Calancha
2018-09-17 18:27             ` Eli Zaretskii
2018-09-17 19:53               ` Tino Calancha
2018-09-18  7:14                 ` Eli Zaretskii
2018-09-18 23:19             ` Noam Postavsky
2018-09-19  9:23               ` Tino Calancha
2018-09-19  9:42                 ` Eli Zaretskii
2018-09-21  8:37                   ` Tino Calancha
2018-09-22  9:14                     ` Eli Zaretskii
2018-09-22 13:00                     ` Noam Postavsky
2018-09-23  1:37                       ` Richard Stallman
2018-09-23 12:01                         ` Noam Postavsky
2018-09-24  8:27                         ` Tino Calancha
2018-09-24 19:58                           ` Richard Stallman
2018-09-24 20:48                             ` Tino Calancha
2018-09-24 21:14                               ` Eli Zaretskii
2018-09-25  8:14                                 ` Robert Pluim
2018-09-25  9:24                                   ` Eli Zaretskii
2018-09-25 23:03                                     ` Richard Stallman
2018-09-29  9:49                                   ` Tino Calancha
2018-09-24  8:36                       ` Tino Calancha

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87worn86l5.fsf@calancha-pc.dy.bbexcite.jp \
    --to=tino.calancha@gmail.com \
    --cc=32731@debbugs.gnu.org \
    --cc=npostavs@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.