mawww / kakoune

mawww's experiment for a better code editor
http://kakoune.org
The Unlicense
9.95k stars 716 forks source link

[REQUEST] Hook for text insertion and deletion #4742

Open ZakharEl opened 2 years ago

ZakharEl commented 2 years ago

Feature

It would be nice if there would be a hook trigger for when text is inserted or deleted irregardless of the mode.

To More Easily trigger commands based of file or buffer change

mawww commented 2 years ago

Those hooks do not exist mostly for performance reason (imagine what happens if we paste while having thousands of selections). the suggested alternative is to keep track of the buffer timestamp and run on one of Idle hooks to check if the buffer has changed.

Could you describe your use case in more details ?

ZakharEl commented 2 years ago

Use case would be deletion of text in normal mode (like with d and c keys).

Screwtapello commented 2 years ago

It's possible to delete text in normal mode without a hook. What would you want the hook to do when text is deleted?

ZakharEl commented 2 years ago

The hook could give out the selection of text that was deleted in normal mode. For example, if 2.4,3.5 7.3,9.3 was deleted then indicate that. I am currently trying to write a text editor and platform independent file mark (or file location daemon and client). I am not merely just writing this daemon as a standalone deamon but also as al library to be used in a text editor and platform independent snippet manager daemon and client.

ZakharEl commented 2 years ago

Thanks for all the work on this text editor. The power of multiple selection with regex based selection is incrediblely efficient!

krobelus commented 2 years ago

If you can assume default keybindings you can use

hook global NormalKey d|<a-d>|c|<a-c>|<backspace> %{
    echo -debug about to delete %val{selections_desc}
}

Alternatively, at least for a prototype, you can use the idle hooks and compute the diff yourself. The diff may not match the true insertions but the result is the same.