elves / elvish

Powerful scripting language & versatile interactive shell
https://elv.sh/
BSD 2-Clause "Simplified" License
5.65k stars 299 forks source link

Readline mode change hook #550

Open notramo opened 6 years ago

notramo commented 6 years ago

The edit:before-readline and edit:after-readline hooks are only executed when a job finish / readline content accepted (before running a command/ after running a command). There should be edit:before-insert-start and edit:after-insert-start, that are executed before the insert mode start, and after the insert mode started. Also, there should be edit:before-insert-end, and edit:after-insert-end, that are the same as above, but for insert mode end.

xiaq commented 6 years ago

The alternative I prefer is to have separate hooks for each mode, in their own namespaces. For instance, the hook that is triggered before entering and after quiting the insert mode can be $edit:insert:before-enter and $edit:insert:after-quit.

I don't see a practical benefit in unifying the mode change hooks with the {before,after}-readline hooks. In particular, these hooks need to be run when the editor is not active (c.f #593), so the analog is not a very accurate one.

notramo commented 6 years ago

The benefit of unifying the mode change hooks can be run between mode changes, and a hook can depend on the previous hook. For example, how would you do the following with your proposal: ((history|insert|navigation)/location)|(location/(history|navigation))|([^/]*/insert)

If some hooks need to be run, when the editor is not active, the closed mode should support only the before hook.

xiaq commented 6 years ago

Sorry, I don't understand your example. Care to elaborate?

notramo commented 6 years ago

This hook is run when the mode changes from history or insert or navigation to location or lastcmd, from location to history or navigation, and from any mode to insert. The string matched with the regex is oldmode/newmode.