Hi Prot,
I am using beframe with the consult-buffer integration that you mention in the manual. I noticed that, when using it,
the first buffer in the list is the current buffer, which contradicts the behaviour of `beframe-switch-buffer', which itself
mimics `switch-to-buffer''s behaviour by placing the buffer returned by `other-buffer' at the top of the list.
I suggest that the default behaviour look like this instead:
┌────
│ (defun beframe-buffer-sort-other (buffers)
│ "Sort BUFFERS by placing the most recently selected buffer first.
│
│ Return a sequence that first lists the result of `other-buffer', then the other
│ buffers.
│
│ This function can be used as the :sort key of
│ beframe-buffer-list or beframe-buffer-names."
│ (let ((bufs (seq-group-by
│ (lambda (buf)
│ (if (eq buf (other-buffer))
│ :other
│ :rest))
│ buffers)))
│ (nconc (alist-get :other bufs)
│ (alist-get :rest bufs))))
│
│ (defun beframe-buffer-names-other (&optional frame)
│ "Call `beframe-buffer-names' with `beframe-buffer-sort-other' as the sort key."
│ (beframe-buffer-names frame :sort #'beframe-buffer-sort-other))
└────
What do you think?
Take care,
Edgar
Re: beframe: in Consult integration, return '(other-buffer)' first?
> From: Edgar Vincent <e-v@posteo.net>> Date: Sun, 25 Jun 2023 14:13:48 +0000>> Hi Prot,
Hello Edgar,
> I am using beframe with the consult-buffer integration that you> mention in the manual. I noticed that, when using it, the first buffer> in the list is the current buffer, which contradicts the behaviour of> `beframe-switch-buffer', which itself mimics `switch-to-buffer''s> behaviour by placing the buffer returned by `other-buffer' at the top> of the list.>> I suggest that the default behaviour look like this instead:>> ┌────> │ (defun beframe-buffer-sort-other (buffers)> │ "Sort BUFFERS by placing the most recently selected buffer first.> │ > │ Return a sequence that first lists the result of `other-buffer', then the other> │ buffers.> │ > │ This function can be used as the :sort key of> │ beframe-buffer-list or beframe-buffer-names."> │ (let ((bufs (seq-group-by> │ (lambda (buf)> │ (if (eq buf (other-buffer))> │ :other> │ :rest))> │ buffers)))> │ (nconc (alist-get :other bufs)> │ (alist-get :rest bufs))))> │ > │ (defun beframe-buffer-names-other (&optional frame)> │ "Call `beframe-buffer-names' with `beframe-buffer-sort-other' as the sort key."> │ (beframe-buffer-names frame :sort #'beframe-buffer-sort-other))> └────>> What do you think?
This makes sense to me though I don't know/remember the specifics of how
Consult handles sorting. I add Tony Zorman in CC. Tony introduced the
relevant feature and may have an opinion about it:
<https://lists.sr.ht/~protesilaos/general-issues/%3C87edq4n3qt.fsf%40hyperspace%3E>.
All the best,
Prot
--
Protesilaos Stavrou
https://protesilaos.com
Re: beframe: in Consult integration, return '(other-buffer)' first?
Hi,
On Mon, Jun 26 2023 09:29, Protesilaos Stavrou wrote:
>> From: Edgar Vincent <e-v@posteo.net>>>> I am using beframe with the consult-buffer integration that you>> mention in the manual. I noticed that, when using it, the first buffer>> in the list is the current buffer, which contradicts the behaviour of>> `beframe-switch-buffer', which itself mimics `switch-to-buffer''s>> behaviour by placing the buffer returned by `other-buffer' at the top>> of the list.>>>> I suggest that the default behaviour look like this instead:>>>> […]>>>> What do you think?>> This makes sense to me though I don't know/remember the specifics of how> Consult handles sorting. I add Tony Zorman in CC. Tony introduced the> relevant feature and may have an opinion about it:> <https://lists.sr.ht/~protesilaos/general-issues/%3C87edq4n3qt.fsf%40hyperspace%3E>.
maybe I'm misreading this, but to me it sounds like Edgar is exactly
talking about the functionality that was implemented in that patch. At
least, the commit mimics what `consult--buffer-sort-visibility' does for
consult, which seems to produce the desired behaviour.
@Edgar: maybe you missed it in the manual (or use an older version of
beframe), but `beframe-buffer-names' can take a sorting function, like
this:
(defun my/beframe-items (&optional frame)
(beframe-buffer-names frame :sort #'beframe-buffer-sort-visibility))
In the consult integration, `my/beframe-items' can now be used in place
of `beframe-buffer-names':
(defvar beframe-consult-source
`( :name "Frame-specific buffers (current frame)"
:narrow ?F
:category buffer
:face beframe-buffer
:history beframe-history
:items ,#'my/beframe-items ; <- HERE
:action ,#'switch-to-buffer
:state ,#'consult--buffer-state))
I've used this for a while now, and the current buffer is indeed pushed
to the very back of the buffer list.
Maybe this helps; if not, feel free to yell at me for having
misunderstood you :)
Best,
Tony
--
Tony Zorman | https://tony-zorman.com/
Re: beframe: in Consult integration, return '(other-buffer)' first?
Tony Zorman <soliditsallgood@mailbox.org> writes:
> Hi,
Hello Tony,
> maybe I'm misreading this, but to me it sounds like Edgar is exactly> talking about the functionality that was implemented in that patch. At> least, the commit mimics what `consult–buffer-sort-visibility' does for> consult, which seems to produce the desired behaviour.>> @Edgar: maybe you missed it in the manual (or use an older version of> beframe), but `beframe-buffer-names' can take a sorting function, like> this:>> (defun my/beframe-items (&optional frame)> (beframe-buffer-names frame :sort #'beframe-buffer-sort-visibility))>> In the consult integration, `my/beframe-items' can now be used in place> of `beframe-buffer-names':>> (defvar beframe-consult-source> `( :name "Frame-specific buffers (current frame)"> :narrow ?F> :category buffer> :face beframe-buffer> :history beframe-history> :items ,#'my/beframe-items ; <- HERE> :action ,#'switch-to-buffer> :state ,#'consult–buffer-state))>> I've used this for a while now, and the current buffer is indeed pushed> to the very back of the buffer list.
You are quite right. I had noticed the sorting function, and actually defined a new one
in my original message. However, I had misunderstood the purpose of `beframe-buffer-sort-visibility'.
Its behaviour is indeed very much like the one I described.
Prot, might I suggest that the behaviour described by Tony become the default? For the moment, when using the snippet from
the manual, the first candidate is the current buffer, which I don't think anyone would find useful – especially
given that it does not mimic `beframe-switch-buffer'.
> Maybe this helps; if not, feel free to yell at me for having> misunderstood you :)>> Best,> Tony
Thanks again for your reply, Tony.
Edgar