From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Bastien Newsgroups: gmane.emacs.devel Subject: [PATCH] Filter list-buffers by a regexp (interactively) Date: Mon, 28 Jul 2014 19:32:08 +0200 Message-ID: <87oaw9fkyv.fsf@bzg.ath.cx> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1406570568 15815 80.91.229.3 (28 Jul 2014 18:02:48 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 28 Jul 2014 18:02:48 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jul 28 20:02:40 2014 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XBpFs-0001AW-1W for ged-emacs-devel@m.gmane.org; Mon, 28 Jul 2014 20:02:36 +0200 Original-Received: from localhost ([::1]:41689 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XBpFr-0001ci-NI for ged-emacs-devel@m.gmane.org; Mon, 28 Jul 2014 14:02:35 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33624) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XBomn-0003Dn-9O for emacs-devel@gnu.org; Mon, 28 Jul 2014 13:32:41 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XBome-0000de-M7 for emacs-devel@gnu.org; Mon, 28 Jul 2014 13:32:33 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:46365) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XBome-0000bW-6L for emacs-devel@gnu.org; Mon, 28 Jul 2014 13:32:24 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1XBomb-0004kp-Vo for emacs-devel@gnu.org; Mon, 28 Jul 2014 19:32:21 +0200 Original-Received: from mar75-2-81-56-68-112.fbx.proxad.net ([81.56.68.112]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 28 Jul 2014 19:32:21 +0200 Original-Received: from bzg by mar75-2-81-56-68-112.fbx.proxad.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 28 Jul 2014 19:32:21 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 237 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: mar75-2-81-56-68-112.fbx.proxad.net User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux) Cancel-Lock: sha1:HPEsIg2CwB2I7rD1SnWhZ/Kcbpw= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:173222 Archived-At: --=-=-= Content-Type: text/plain The patch below allows to use C-u C-u C-x C-b to interactively enter a regular expression to only list buffers with a matching name. The need came up on Org-mode when people have many agenda buffers and want to only list those. Any comment and/or improvement appreciated, thanks! --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=buff-menu.el.patch === modified file 'lisp/buff-menu.el' *** lisp/buff-menu.el 2014-07-21 05:38:17 +0000 --- lisp/buff-menu.el 2014-07-28 13:12:57 +0000 *************** *** 127,132 **** --- 127,133 ---- (define-key map "b" 'Buffer-menu-bury) (define-key map "V" 'Buffer-menu-view) (define-key map "T" 'Buffer-menu-toggle-files-only) + (define-key map "*" 'Buffer-menu-filter-by-regexp) (define-key map (kbd "M-s a C-s") 'Buffer-menu-isearch-buffers) (define-key map (kbd "M-s a M-C-s") 'Buffer-menu-isearch-buffers-regexp) (define-key map (kbd "M-s a C-o") 'Buffer-menu-multi-occur) *************** *** 146,151 **** --- 147,155 ---- '(menu-item "Show Only File Buffers" Buffer-menu-toggle-files-only :button (:toggle . Buffer-menu-files-only) :help "Toggle whether the current buffer-menu displays only file buffers")) + (bindings--define-key menu-map [tr] + '(menu-item "Filter List by Regexp" Buffer-menu-filter-by-regexp + :help "Filter the list of buffers by a regular expression")) (bindings--define-key menu-map [s1] menu-bar-separator) ;; FIXME: The "Select" entries could use better names... (bindings--define-key menu-map [sel] *************** *** 243,258 **** \\[Buffer-menu-toggle-read-only] Toggle read-only status of buffer on this line. \\[revert-buffer] Update the list of buffers. \\[Buffer-menu-toggle-files-only] Toggle whether the menu displays only file buffers. \\[Buffer-menu-bury] Bury the buffer listed on this line." (set (make-local-variable 'buffer-stale-function) (lambda (&optional _noconfirm) 'fast)) (add-hook 'tabulated-list-revert-hook 'list-buffers--refresh nil t)) ! (defun buffer-menu (&optional arg) "Switch to the Buffer Menu. By default, the Buffer Menu lists all buffers except those whose names start with a space (which are for internal use). With ! prefix argument ARG, show only buffers that are visiting files. In the Buffer Menu, the first column (denoted \"C\") shows \".\" for the buffer from which you came, \">\" for buffers you mark to --- 247,267 ---- \\[Buffer-menu-toggle-read-only] Toggle read-only status of buffer on this line. \\[revert-buffer] Update the list of buffers. \\[Buffer-menu-toggle-files-only] Toggle whether the menu displays only file buffers. + \\[Buffer-menu-filter-by-regexp] Prompt for a regexp and display matching buffers. \\[Buffer-menu-bury] Bury the buffer listed on this line." (set (make-local-variable 'buffer-stale-function) (lambda (&optional _noconfirm) 'fast)) (add-hook 'tabulated-list-revert-hook 'list-buffers--refresh nil t)) ! (defun buffer-menu (&optional arg regexp) "Switch to the Buffer Menu. By default, the Buffer Menu lists all buffers except those whose names start with a space (which are for internal use). With ! a prefix argument ARG, show only buffers that are visiting files. ! With two universal prefix argument, prompt for a regular expression ! to only display buffers with a matching name. ! ! When REGEXP is non-nil, only list buffers matching the regexp. In the Buffer Menu, the first column (denoted \"C\") shows \".\" for the buffer from which you came, \">\" for buffers you mark to *************** *** 268,300 **** See `Buffer-menu-mode' for the keybindings available the Buffer Menu." (interactive "P") ! (switch-to-buffer (list-buffers-noselect arg)) ! (message ! "Commands: d, s, x, u; f, o, 1, 2, m, v; ~, %%; q to quit; ? for help.")) ! (defun buffer-menu-other-window (&optional arg) "Display the Buffer Menu in another window. See `buffer-menu' for a description of the Buffer Menu. By default, all buffers are listed except those whose names start ! with a space (which are for internal use). With prefix argument ! ARG, show only buffers that are visiting files." (interactive "P") ! (switch-to-buffer-other-window (list-buffers-noselect arg)) ! (message ! "Commands: d, s, x, u; f, o, 1, 2, m, v; ~, %%; q to quit; ? for help.")) ;;;###autoload ! (defun list-buffers (&optional arg) "Display a list of existing buffers. The list is displayed in a buffer named \"*Buffer List*\". See `buffer-menu' for a description of the Buffer Menu. By default, all buffers are listed except those whose names start with a space (which are for internal use). With prefix argument ! ARG, show only buffers that are visiting files." (interactive "P") ! (display-buffer (list-buffers-noselect arg))) (defun Buffer-menu-toggle-files-only (arg) "Toggle whether the current buffer-menu displays only file buffers. --- 277,353 ---- See `Buffer-menu-mode' for the keybindings available the Buffer Menu." (interactive "P") ! (let ((re-filter ! (or regexp ! (and (equal arg '(16)) ! (read-from-minibuffer "Regexp filter: "))))) ! (switch-to-buffer ! (list-buffers-noselect ! arg ! (if re-filter ! (delq ! nil ! (mapcar (lambda (b) ! (if (string-match re-filter (buffer-name b)) b)) ! (buffer-list))))) ! (message ! "Commands: d, s, x, u; f, o, 1, 2, m, v; ~, %%; q to quit; ? for help.")))) ! (defun buffer-menu-other-window (&optional arg regexp) "Display the Buffer Menu in another window. See `buffer-menu' for a description of the Buffer Menu. By default, all buffers are listed except those whose names start ! with a space (which are for internal use). With a single prefix ! argument ARG, show only buffers that are visiting files. With two ! universal prefix argument, prompt for a regular expression to only ! display buffers with a matching name. ! ! When REGEXP is non-nil, only list buffers matching the regexp." (interactive "P") ! (let ((re-filter ! (or regexp ! (and (equal arg '(16)) ! (read-from-minibuffer "Regexp filter: "))))) ! (switch-to-buffer-other-window ! (list-buffers-noselect ! arg ! (if re-filter ! (delq ! nil ! (mapcar (lambda (b) ! (if (string-match re-filter (buffer-name b)) b)) ! (buffer-list)))))) ! (message ! "Commands: d, s, x, u; f, o, 1, 2, m, v; ~, %%; q to quit; ? for help."))) ;;;###autoload ! (defun list-buffers (&optional arg regexp) "Display a list of existing buffers. The list is displayed in a buffer named \"*Buffer List*\". See `buffer-menu' for a description of the Buffer Menu. By default, all buffers are listed except those whose names start with a space (which are for internal use). With prefix argument ! ARG, show only buffers that are visiting files. With two universal ! prefix argument, prompt for a regular expression to only display ! buffers with a matching name. ! ! When REGEXP is non-nil, only list buffers matching the regexp." (interactive "P") ! (let ((re-filter ! (or regexp ! (and (equal arg '(16)) ! (read-from-minibuffer "Regexp filter: "))))) ! (display-buffer ! (list-buffers-noselect ! arg ! (if re-filter ! (delq ! nil ! (mapcar (lambda (b) ! (if (string-match re-filter (buffer-name b)) b)) ! (buffer-list)))))))) (defun Buffer-menu-toggle-files-only (arg) "Toggle whether the current buffer-menu displays only file buffers. *************** *** 309,314 **** --- 362,373 ---- "Showing all non-internal buffers.")) (revert-buffer)) + (defun Buffer-menu-filter-by-regexp () + "Limit the buffer list to buffers which name matches a regexp." + (interactive) + (list-buffers '(16)) + (message "Hit `g' to remove the filter")) + (defalias 'Buffer-menu-sort 'tabulated-list-sort) *************** *** 588,594 **** (with-current-buffer buffer (Buffer-menu-mode) (setq Buffer-menu-files-only ! (and files-only (>= (prefix-numeric-value files-only) 0))) (list-buffers--refresh buffer-list old-buffer) (tabulated-list-print)) buffer)) --- 647,654 ---- (with-current-buffer buffer (Buffer-menu-mode) (setq Buffer-menu-files-only ! (and (equal '(4) files-only) ! (>= (prefix-numeric-value files-only) 0))) (list-buffers--refresh buffer-list old-buffer) (tabulated-list-print)) buffer)) --=-=-= Content-Type: text/plain -- Bastien --=-=-=--