From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs Subject: bug#32731: 26.1.50; Ibuffer filter by mode: Handle >1 mode names Date: Mon, 24 Sep 2018 17:36:34 +0900 Message-ID: <87tvmf70ml.fsf@calancha-pc.dy.bbexcite.jp> References: <87bm919s5y.fsf@calancha-pc.dy.bbexcite.jp> <874let9lps.fsf@calancha-pc.dy.bbexcite.jp> <87ftydezmi.fsf@gmail.com> <87worn86l5.fsf@calancha-pc.dy.bbexcite.jp> <878t43rkxd.fsf@gmail.com> <87sh2881dv.fsf@calancha-pc.dy.bbexcite.jp> <871s9qqtq1.fsf@gmail.com> <877ejh96xj.fsf@calancha-pc.dy.bbexcite.jp> <83sh25escb.fsf@gnu.org> <87zhwb6yb0.fsf@calancha-pc.dy.bbexcite.jp> <87r2hloffp.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1537778109 5659 195.159.176.226 (24 Sep 2018 08:35:09 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 24 Sep 2018 08:35:09 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: 32731@debbugs.gnu.org To: Noam Postavsky Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Sep 24 10:35:04 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g4MKe-0001NY-EU for geb-bug-gnu-emacs@m.gmane.org; Mon, 24 Sep 2018 10:35:04 +0200 Original-Received: from localhost ([::1]:44073 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g4MMk-0006O2-Uz for geb-bug-gnu-emacs@m.gmane.org; Mon, 24 Sep 2018 04:37:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34641) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g4MMb-0006NG-RP for bug-gnu-emacs@gnu.org; Mon, 24 Sep 2018 04:37:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g4MMY-0004q2-JC for bug-gnu-emacs@gnu.org; Mon, 24 Sep 2018 04:37:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:47051) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g4MMY-0004pn-Et for bug-gnu-emacs@gnu.org; Mon, 24 Sep 2018 04:37:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1g4MMY-0001xO-8J for bug-gnu-emacs@gnu.org; Mon, 24 Sep 2018 04:37:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 24 Sep 2018 08:37:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32731 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 32731-submit@debbugs.gnu.org id=B32731.15377782087502 (code B ref 32731); Mon, 24 Sep 2018 08:37:02 +0000 Original-Received: (at 32731) by debbugs.gnu.org; 24 Sep 2018 08:36:48 +0000 Original-Received: from localhost ([127.0.0.1]:51309 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g4MMJ-0001ww-Tv for submit@debbugs.gnu.org; Mon, 24 Sep 2018 04:36:48 -0400 Original-Received: from mail-wm1-f50.google.com ([209.85.128.50]:52716) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g4MMH-0001wf-Sy for 32731@debbugs.gnu.org; Mon, 24 Sep 2018 04:36:46 -0400 Original-Received: by mail-wm1-f50.google.com with SMTP id l7-v6so3933159wme.2 for <32731@debbugs.gnu.org>; Mon, 24 Sep 2018 01:36:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=R9S/LSPn/1j0oCPN1NzyggB9FDdOm6sAGP8PjD2d018=; b=csyUIxEtboxNR8rbfOuMwxx0ZU6hGxEvHlj0nSaqVaaYp6PoLM2jn+koqvYPNSOC3H w7jeNphXI1Q4pMtJYNWPY8eNX5dd1Qxcs9C8U7jnUm311iMIsu44o2uOnnTy2NSu3heQ tTU2f3YIzOviaGbAMZ2vCj5S/ax5+/kG5eCd7olVd3/79DAI8fJICcQFxa9SIEvpkUKj bReuvQc6mo09WBlFo6NEIlBdhS++Mb8pQPgn6f7BOz54hXmDKgcqQoCzgBKmKoMU62wn CTzFPAxBwmjGQRgZUWmtkfnMqZ/IUaqQQT9XrHFXo3EdG8ZNh4K9dlLEQct/CQ5ZLi/K kK1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=R9S/LSPn/1j0oCPN1NzyggB9FDdOm6sAGP8PjD2d018=; b=s6qdP3AyfTPOUS/I90b1n4+B757gq7GtV0QLA0cYhEhHZGxEQ4PA2GsPiKT1oI+2ys aAGmIEk32ez0vUxvOtbxpk47uZ015JEvRBGSUgHhf/f0FOiQFEhc+JPIPNQNC6A0e58b CUYT2oiGvNUi5tnbIg/lT+wFn/I6mcPzjtI/PyhZeRxMMFJS0+/R2+QeJ+BYj2UpRzR8 t/HuHYnbXpFXLd5pRa0TM5ZL4UdPwskWbf9ttVBs/cNSJByGEriu0I+HzP8PSBWNU0ej No0CKrSi8D6sez5RqZ+VFGggOZKs96i8axvDdFQWlc3DEUls36eTzfreQC1OP5bu3gif i34A== X-Gm-Message-State: ABuFfoix4quAsn+OVFBpXu7RFgsnm/eCr0gf53eM8xjY3OT3rmgjWwZd TapGVHoJkgebbVNyrytGUrocse60 X-Google-Smtp-Source: ANB0VdYq8ZVHCTarhUY/1uDPVzF37pQbiWDp/bVs2OT0Ew5nt8tYLiDKXW2hLR3xtDBzRkPoFqqdGw== X-Received: by 2002:a1c:f11a:: with SMTP id p26-v6mr6220111wmh.92.1537778199721; Mon, 24 Sep 2018 01:36:39 -0700 (PDT) Original-Received: from calancha-pc.dy.bbexcite.jp (15.red-83-50-151.dynamicip.rima-tde.net. [83.50.151.15]) by smtp.gmail.com with ESMTPSA id t70-v6sm11793128wmt.30.2018.09.24.01.36.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 24 Sep 2018 01:36:39 -0700 (PDT) In-Reply-To: <87r2hloffp.fsf@gmail.com> (Noam Postavsky's message of "Sat, 22 Sep 2018 09:00:10 -0400") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:150590 Archived-At: Noam Postavsky writes: > Tino Calancha writes: > >> commit 72e332c986304775e91020c88ded1ba9d7226023 >> Author: Tino Calancha >> Date: Fri Sep 21 17:32:57 2018 +0900 >> >> Ibuffer filter by modes: Accept several mode names >> >> Extend all mode filters so that they handle >1 mode. >> For instance, if the user wants to filter all buffers in >> C or C++ mode, then s?he can call the filter interactively > > If you'll pardon another nit, I suggest using "they" instead of "s?he" > which has the advantage of being a pronounceable English word. I changed to she/he. > I think this hunk is just changing spaces to tabs (shouldn't .dir-locals > be setting indent-tabs-mode to nil though?). I droped my hand-added tabs (also those I added in ibuf-ext.el). Actually I don't like tabs in source code (just added as a sign of respect to the library author). --8<-----------------------------cut here---------------start------------->8--- commit d385f8077ffed38046231bb29448598484352543 Author: Tino Calancha Date: Mon Sep 24 17:29:48 2018 +0900 Ibuffer filter by modes: Accept several mode names Extend all mode filters so that they handle >1 mode. For instance, if the user wants to filter all buffers in C or C++ mode, then she/he can call the filter interactively with input: 'c-mode,c++-mode' (Bug#32731). * lisp/ibuf-macs.el(define-ibuffer-filter): Add key :accept-list. If the value of this key is non-nil, then the filter accepts either a single qualifier or a list of them; in the latter case, the resultant filter is the `or' composition of the individual ones. * lisp/ibuf-ext.el (ibuffer-filter-by-used-mode) (ibuffer-filter-by-mode, ibuffer-filter-by-derived-mode) Set :accept-list value non-nil. Interactively, accept a comma separated list of mode names. * etc/NEWS(Ibuffer): Announce this change. Co-authored-by: Noam Postavsky diff --git a/etc/NEWS b/etc/NEWS index bc6791b05b..8126354ab8 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -62,6 +62,11 @@ to reduce differences between developer and production builds. ** Ibuffer --- +*** All mode filters can now accept a list of symbols. +This means you can now easily filter several major modes, as well +as a single mode. + +--- *** New toggle 'ibuffer-do-toggle-lock', bound to 'L'. ** Gnus diff --git a/lisp/ibuf-ext.el b/lisp/ibuf-ext.el index d9949d2835..32ec91db97 100644 --- a/lisp/ibuf-ext.el +++ b/lisp/ibuf-ext.el @@ -1228,28 +1228,33 @@ ibuffer-list-buffer-modes ;;;###autoload (autoload 'ibuffer-filter-by-mode "ibuf-ext") (define-ibuffer-filter mode - "Limit current view to buffers with major mode QUALIFIER." + "Limit current view to buffers with major mode(s) specified by QUALIFIER. +QUALIFIER is the mode name as a symbol or a list of symbols. +Called interactively, accept a comma separated list of mode names." (:description "major mode" :reader (let* ((buf (ibuffer-current-buffer)) (default (if (and buf (buffer-live-p buf)) (symbol-name (buffer-local-value 'major-mode buf))))) - (intern - (completing-read + (mapcar #'intern + (completing-read-multiple (if default (format "Filter by major mode (default %s): " default) "Filter by major mode: ") obarray - #'(lambda (e) - (string-match "-mode\\'" (symbol-name e))) - t nil nil default)))) + (lambda (e) + (string-match "-mode\\'" (if (symbolp e) (symbol-name e) e))) + t nil nil default))) + :accept-list t) (eq qualifier (buffer-local-value 'major-mode buf))) ;;;###autoload (autoload 'ibuffer-filter-by-used-mode "ibuf-ext") (define-ibuffer-filter used-mode - "Limit current view to buffers with major mode QUALIFIER. -Called interactively, this function allows selection of modes + "Limit current view to buffers with major mode(s) specified by QUALIFIER. +QUALIFIER is the mode name as a symbol or a list of symbols. + +Called interactively, accept a comma separated list of mode names currently used by buffers." (:description "major mode in use" :reader @@ -1257,23 +1262,29 @@ used-mode (default (if (and buf (buffer-live-p buf)) (symbol-name (buffer-local-value 'major-mode buf))))) - (intern - (completing-read + (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)))) + (ibuffer-list-buffer-modes) nil t nil nil default))) + :accept-list t) (eq qualifier (buffer-local-value 'major-mode buf))) ;;;###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." + "Limit current view to buffers with major mode(s) specified by QUALIFIER. +QUALIFIER is the mode name as a symbol or a list of symbols. + Restrict the view to buffers whose major mode derivates + from modes specified by QUALIFIER. +Called interactively, accept a comma separated list of mode names." (:description "derived mode" - :reader - (intern - (completing-read "Filter by derived mode: " - (ibuffer-list-buffer-modes t) - nil t))) + :reader + (mapcar #'intern + (completing-read-multiple "Filter by derived mode: " + (ibuffer-list-buffer-modes t) + nil t)) + :accept-list t) (with-current-buffer buf (derived-mode-p qualifier))) ;;;###autoload (autoload 'ibuffer-filter-by-name "ibuf-ext") diff --git a/lisp/ibuf-macs.el b/lisp/ibuf-macs.el index 6a70a8341a..72a35a5331 100644 --- a/lisp/ibuf-macs.el +++ b/lisp/ibuf-macs.el @@ -280,14 +280,18 @@ ibuffer-save-marks ;;;###autoload (cl-defmacro define-ibuffer-filter (name documentation - (&key - reader - description) - &rest body) + (&key + reader + description + accept-list) + &rest body) "Define a filter named NAME. DOCUMENTATION is the documentation of the function. READER is a form which should read a qualifier from the user. DESCRIPTION is a short string describing the filter. +ACCEPT-LIST is a boolean; if non-nil, the filter accepts either +a single condition or a list of them; in the latter +case the filter is the `or' composition of the conditions. BODY should contain forms which will be evaluated to test whether or not a particular buffer should be displayed or not. The forms in BODY @@ -296,30 +300,41 @@ ibuffer-save-marks \(fn NAME DOCUMENTATION (&key READER DESCRIPTION) &rest BODY)" (declare (indent 2) (doc-string 2)) - (let ((fn-name (intern (concat "ibuffer-filter-by-" (symbol-name name))))) + (let ((fn-name (intern (concat "ibuffer-filter-by-" (symbol-name name)))) + (filter (make-symbol "ibuffer-filter")) + (qualifier-str (make-symbol "ibuffer-qualifier-str"))) `(progn (defun ,fn-name (qualifier) - ,(or documentation "This filter is not documented.") - (interactive (list ,reader)) - (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))) + ,(or documentation "This filter is not documented.") + (interactive (list ,reader)) + (let ((,filter (cons ',name qualifier)) + (,qualifier-str qualifier)) + ,(when accept-list + `(progn + (unless (listp qualifier) (setq qualifier (list qualifier))) + ;; Reject equivalent filters: (or f1 f2) is same as (or f2 f1). + (setq qualifier (sort (delete-dups qualifier) #'string-lessp)) + (setq ,filter (cons ',name (car qualifier))) + (setq ,qualifier-str + (mapconcat (lambda (m) (if (symbolp m) (symbol-name m) m)) + qualifier ",")) + (when (cdr qualifier) ; Compose individual filters with `or'. + (setq ,filter `(or ,@(mapcar (lambda (m) (cons ',name m)) qualifier)))))) + (if (null (ibuffer-push-filter ,filter)) + (message ,(format "Filter by %s already applied: %%s" description) + ,qualifier-str) + (message ,(format "Filter by %s added: %%s" description) + ,qualifier-str) + (ibuffer-update nil t)))) (push (list ',name ,description - (lambda (buf qualifier) - (condition-case nil - (progn ,@body) - (error (ibuffer-pop-filter) - (when (eq ',name 'predicate) - (error "Wrong filter predicate: %S" - qualifier)))))) - ibuffer-filtering-alist) + (lambda (buf qualifier) + (condition-case nil + (progn ,@body) + (error (ibuffer-pop-filter) + (when (eq ',name 'predicate) + (error "Wrong filter predicate: %S" + qualifier)))))) + ibuffer-filtering-alist) :autoload-end))) (provide 'ibuf-macs) --8<-----------------------------cut here---------------end--------------->8---