Sel-editor: editable, live selection-summary buffer

This plugin, suggested by @Guest0 and @Screwtapello , renders a summary of the current window’s multiple selections (ranges + contents) in a *selections* buffer.

sel-editor-live-2021-09-13

It can act as a toolsclient, and live-update *selections* based on the… selections. You can edit ranges (but not contents), then use sel-editor-buf2kak to change the actual selections. E.g. you can delete ranges, modify them, or even enter ranges manually.

I’d like to implement selection-contents editing in the summary buffer, but I need to learn more…

Installation / usage

Instructions (brief) at the project page

Notes

I’ve managed to do this in pure kakscript, apparently transcending some language limitations

  • looping: using 999q (macro with count) with a macro calling : exec iter. Alternatively, recursion-based looping also works, but hits a 100-level nesting limit (apparently, no tail-call optimization).
  • apply lambda to arguments: def -override lambda-tmp %reg{a}; lambda-tmp args
  • stopping loops: with exceptions
  • processing lists / shifting arguments: use str-list options, and set global work %arg{@}; set -add global work %arg{1}
  • checking if arguments exhausted / list empty: def nop-0_0 -params 0..0 %{} (call it on any str-list option, or on %arg{@}; it throws unless there are zero elements in the list). Any such param-count check is possible, either with predefined or on-the-fly checkers.

I’ve been able to implement a foreach, zip two lists, concatenate / prefix / suffix a list of strings, and it seems like a lot more is possible…

7 Likes

Looks incredible! But what am I doing wrong? I get:

~/code/kakconf/sel-editor.kak:16:1: '__k9s0ke_tmp_loader': 3:1: 'eval': no selections in context```

It’s probably this; but the currently published version should work. Which sel-editor revision are you using (git log -1 --pretty=%h)? Is this with the current kakoune release, or master?

I’ll probably switch back to a %sh{} loader since it seems there are problems.

I’ll be sure to test in a clean $HOME mock-up from now on… Anyway, the bugs are fixed (thanks @danr for alerting); the latest sel-editor.kak (see the REAMDE / homepage as well) can…

sel-editor-2021-09-16 23-34

Change selection contents

Edit the contents (between | .. |) of a selection, press <ret>w, confirm, and the text in the original buffer will be updated.

Easily select / unselect / remove blocks

There’s a custom user mode for *selections*, triggered by pressing <ret> — the user-mode menu lists all the mappings. E.g. add blocks with <ret>+, instead of combining them with <a-z>, Z as in normal mode, delete blocks with <ret>d etc. Some of them have normal-mode correspondents (>, <, =, <a-ret> = `).

Work on specific selections

Press <ret>= and only the selected blocks will be applied to the original buffer. Press > and all blocks in *selections* will be applied.

Undo

All changes that happen in *selections* go into the buffer’s undo history. You can go back in time. However, if the original buffer contents changes, the selections will have incompatible timestamps and some changes won’t be restore-able (via > or =).

Highlight

… as can be seen in the preview above

Auto-infer clients

You can just call :+=ssl [...] (or sel-editor-live-new [...]); this will call new and set up a live *selections*.

If you do have a toolsclient setup, sel-editor will respect it. If you just call sel-editor-live-enable, it will guess which client is the toolsclient.

Notes / TODO

I’ve been bitten by this customization, which pollutes register z. I’m going to include selection history (N-levels deep) in sel-editor. Whenever there’s a “significant” change in selections (i.e. excluding short, single selections), a NormalIdle hook (if enabled) will add an entry in history.

There’s a bug that prevents selection contents from being made empty. It doesn’t make sense, but I guess new users playing with it could easily trigger it. Just delete unneeded blocks with <ret>d.