~protesilaos/general-issues

3 2

[PATCH 1/1] Beframe: add ability to sort the buffer list

Details
Message ID
<87edq4n3qt.fsf@hyperspace>
DKIM signature
missing
Download raw message
Hi Prot,

first of all: thanks for beframe!  It's the kind of package that I never
knew I wanted, but now I couldn't live without it.

The [manual mentions] that the package can be used with consult, and one
can go for "full integration" by also disabling the regular
`consult--source-buffer` in favour of `beframe--consult-source`.
However, what I noticed was that the former did a bit more than just
listing all buffers—it also sorted them according to their visibility
(that is: first hidden buffers, then visible but not focused ones, and
lastly the current buffer).  This has the advantage that switching
between the two last-used buffers is very fast; plus, it feels—to
me—more intuitive that one is more likely to switch to hidden buffers
over visible ones.

Beframe already does something akin to this in `beframe--buffer-prompt`,
where it uses the previous buffer as the default value, but this gets
lost when trying to integrate the package with other completion
frameworks.

As such, the attached patch adds an key argument (I thought this would
be the least disruptive way) to `beframe--buffer-names` and related
functions.  The argument is a function that can be used to sort (or even
further filter) the list of buffers.  I've added an example sorting
function in the form of `beframe-buffer-sort-visibility`, which realises
the above filtering according to visibility status.  You can try it, for
example, like so:

    (defun my/beframe-items (&optional frame)
      (beframe--buffer-names frame :sort #'beframe-buffer-sort-visibility))
      
    (defvar beframe--consult-source
      `(:name     "Frame-specific buffers (current frame)"
        :narrow   ?F
        :category buffer
        :history  beframe-history
        :items    ,#'my/beframe-items
        :action   ,#'switch-to-buffer
        :state    ,#'consult--buffer-state))
        
    (add-to-list 'consult-buffer-sources 'beframe--consult-source)
    ;; For good measure.
    (setq consult-buffer-sources
          (remove 'consult--source-buffer consult-buffer-sources))
    
I haven't written any user-facing documentation yet, as I'm not sure
this is something that you necessarily want to have in the package.  If
you think it's a good idea, I can of course amend the patch, or create a
new one just for documentation.

Let me know what you think!
  Tony

[manual mentions]: https://protesilaos.com/emacs/beframe#h:1c2d3d64-aa7b-4585-a418-ccedbb548b38

Re: [PATCH 1/1] Beframe: add ability to sort the buffer list

Details
Message ID
<878rgbkd8u.fsf@protesilaos.com>
In-Reply-To
<87edq4n3qt.fsf@hyperspace> (view parent)
DKIM signature
missing
Download raw message
> From: Tony Zorman <soliditsallgood@mailbox.org>
> Date: Sat,  4 Mar 2023 12:40:58 +0100
>
> Hi Prot,

Hello Tony,

> first of all: thanks for beframe!  It's the kind of package that I never
> knew I wanted, but now I couldn't live without it.

You are welcome!

> [... 41 lines elided]

> I haven't written any user-facing documentation yet, as I'm not sure
> this is something that you necessarily want to have in the package.  If
> you think it's a good idea, I can of course amend the patch, or create a
> new one just for documentation.
>
> Let me know what you think!

I installed your patch and included your name in the "Acknowledgements".
Thank you!

Can you prepare a patch for the manual as well?  It can be an addition
to the sample glue code for Consult.  Or you can write a new node, if
you want.  Whatever works for you.  Just so that we mention the sorting
possibility somewhere.

All the best,
Prot

-- 
Protesilaos Stavrou
https://protesilaos.com

Re: [PATCH 1/1] Beframe: add ability to sort the buffer list

Details
Message ID
<875ybfjtdo.fsf@hyperspace>
In-Reply-To
<878rgbkd8u.fsf@protesilaos.com> (view parent)
DKIM signature
missing
Download raw message
Hi,

On Sun, Mar 05 2023 06:56, Protesilaos Stavrou wrote:
> I installed your patch and included your name in the "Acknowledgements".
> Thank you!

why, that was fast; thanks!

> Can you prepare a patch for the manual as well?  It can be an addition
> to the sample glue code for Consult.  Or you can write a new node, if
> you want.  Whatever works for you.  Just so that we mention the sorting
> possibility somewhere.

Sure, you can find it attached.  A new node sounded a bit overkill, and
adding it to the existing consult code seemed too confusing for
first-time readers, so I just added some additional explanations after
the main setup.  Hopefully that struck a decent balance :)

  Tony

Re: [PATCH 1/1] Beframe: add ability to sort the buffer list

Details
Message ID
<87edq2pigl.fsf@protesilaos.com>
In-Reply-To
<875ybfjtdo.fsf@hyperspace> (view parent)
DKIM signature
missing
Download raw message
> From: Tony Zorman <soliditsallgood@mailbox.org>
> Date: Sun,  5 Mar 2023 13:05:23 +0100

> [... 9 lines elided]

>> Can you prepare a patch for the manual as well?  It can be an addition
>> to the sample glue code for Consult.  Or you can write a new node, if
>> you want.  Whatever works for you.  Just so that we mention the sorting
>> possibility somewhere.
>
> Sure, you can find it attached.  A new node sounded a bit overkill, and
> adding it to the existing consult code seemed too confusing for
> first-time readers, so I just added some additional explanations after
> the main setup.  Hopefully that struck a decent balance :)

Just installed it.  Thank you!

Note that I followed it up with the removal of double dashes from the
relevant symbols.  That naming convention is for internal use, whereas
those are public-facing.  I added obsoletion notices, just in case.

-- 
Protesilaos Stavrou
https://protesilaos.com
Reply to thread Export thread (mbox)