minad / consult

:mag: consult.el - Consulting completing-read
GNU General Public License v3.0
1.14k stars 99 forks source link

Separate special buffers into another group #838

Closed grolongo closed 9 months ago

grolongo commented 9 months ago

Hi minad,
I'm trying to have all non-user buffers with asterisks to fall into a Special group, while keeping some of them into the main source, like this:

---- Buffer ----------------
file1.el
*eshell*
file2.py
*scratch*
---- Special ---------------
*Messages*
*Help*

Notice how scratch and eshell don't fall into the Special category.
I've created:

(defvar my/consult-dont-filter-buffers '("*scratch*" "*eshell*" "*ielm*"))

(defun my/consult-special-buffers (name)
  "Filter out all non-user buffers except those listed in `my/consult-dont-filter-buffers'."
  (and (string-match "^\*" name)
       (not (member name my/consult-dont-filter-buffers))))

but I don't how to integrate that function into a buffer source list with :items, as well as removing the Special buffers from the "main" list at the same time.

minad commented 9 months ago

In order to achieve this set the :items to a new function, see for example consult--source-hidden-buffer and consult--source-buffer. The function consult--buffer-query takes an :exclude and :include argument which you can use. The :exclude argument is set to consult-buffer-filter by default and you probably want to override this. I hope this helps!

grolongo commented 9 months ago

Thank you for putting me in the good direction, :exclude and :include did the trick :)

grolongo commented 9 months ago

minad, I've a weird problem witch I think is related to :exclude

(defvar gnus-buffer-source
  (list :name     "Gnus"
        :hidden   t
        :narrow   ?g
        :category 'buffer
        :state    #'consult--buffer-state
        :items    '(lambda () (consult--buffer-query :sort    'visibility
                                                     :as      #'buffer-name
                                                     :include (mapcar #'buffer-name (gnus-buffers))))))

when I C-b followed by g + <space> and if I have the buffers below open, they get shown as expected:

-- Gnus -----------------------------------------
*Group*
*Article nntp+news.gmane.io:gmane.emacs.announce*
*Summary nntp+news.gmane.io:gmane.emacs.announce*

instead, if I have these buffers open, only *Group* is showing (I just show them here so you can see their names, but only *Group* is there):

-- Gnus -----------------------------------------
*Group*
*Article nnimap+icloud:INBOX*
*Summary nnimap+icloud:INBOX*

Do you have any idea why "nnimap+icloud:INBOX" would get filtered out of the results? I have the default consult-buffer-filter value, and there is nothing inside it that matches this pattern.
Also, when I'm doing C-b without filtering with "g", both buffers name (nnimap...) are listed.
I am so confused.