Open notramo opened 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.
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.
Sorry, I don't understand your example. Care to elaborate?
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
.
The
edit:before-readline
andedit:after-readline
hooks are only executed when a job finish / readline content accepted (before running a command/ after running a command). There should beedit:before-insert-start
andedit:after-insert-start
, that are executed before the insert mode start, and after the insert mode started. Also, there should beedit:before-insert-end
, andedit:after-insert-end
, that are the same as above, but for insert mode end.edit:before-readline
.Tab
.before-insert-end
hook.insert
mode exits.after-insert-end
hook, thencompletion
mode.completion
mode exits.before-insert-start
hook is run.insert
mode.after-insert-start
.Enter
.edit:after-readline
, thenlaunches the job.
EDITED:
I think a much cleaner (and more powerful) solution would be using mode change hook. It would be similar to the recently introduced
ModeChange
hook of the Kakoune editor. It constructs a string from the previous mode and the started mode name (e.g.normal/prompt
,insert/normal
), and matches it to a regex that was given when the hook was registered. This solution allows selecting hooks with more flexibility: the previous mode can also control if a hook will run(insert)|(completion)/history
,insert/.*
. Theedit:before-readline
, andedit:after-readline
hooks could be substituted with the special modeclosed
oroff
. It should support running hooks before the mode change, between (the first mode closed, but the second isn't started), and after the mode change.