You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Originally, Kakoune had four hooks for mode-change events: InsertBegin, InsertEnd, NormalBegin and NormalEnd. However, Kakoune does have other modes, and adding "begin" and "end" hooks for all of them would be prohibitive. In fact, it would be impossible, since Kakoune has user-defined modes as well.
In #1772, a new ModeChange hook was introduced, aiming to be a general replacement for the previous mode-change hooks. For example, InsertEnd could be replaced with a ModeChange insert:.* hook. Unfortunately, that didn't quite work out because Kakoune maintains a stack of current modes. For example, from normal mode i pushes an insert mode, and from the insert mode <a-;> pushes a second normal mode. That transition from insert mode to the second normal mode counts as a ModeChange insert:normal because the active mode changes, but it does not count as an InsertEnd because the insert mode doesn't end, it just gets temporarily replaced. See also #2122
To fully generally replace the original events, we should have PushMode and PopMode events with the same parameter string as ModeChange. That is:
InsertBegin can be replaced with PushMode .*:insert
InsertEnd can be replaced with PopMode insert:.*
NormalBegin can be replaced with PushMode .*:normal
NormalEnd can be replaced with PopMode normal:.*
ModeChange X:Y can be replaced with hooking both PushMode X:Y and PopMode X:Y
In the style of the existing hooks documentation:
PushModeX:Y: triggered when a command in mode X starts a new Y mode; for example, when <a-;> temporarily enters normal mode from insert mode, PushMode insert:normal will trigger
PopModeX:Y: triggered when a command in mode X exits that mode, returning to mode Y; for example, when <esc> exits insert mode, PopMode insert:normal will trigger
The text was updated successfully, but these errors were encountered:
Yes, mawww stated multiple times that the ModeChange hook was not that good in the end. PushMode and PopMode are indeed nice improvements! Thanks.
But I feel that the same ambiguity remain:
normal → PushMode → insert
Will the commands done during the PushMode hook be treated as normal or insert commands?
The hook seats right in the middle and there's no way to know to which context it belongs.
So maybe we need 4 hooks:
normal → PushModePre → PushModePost → insert → PopModePre → PopModePost → normal
PushModePre and PopModePre are executed in the mode we're leaving, while PushModePost and PopModePost in the mode we're entering.
By "commands" you specifically mean an evaluate-keys command in the hook "commands" block, or in a function called from that block, yes?
The "pre" hooks seem dangerous: what if somebody does:
hook global PushModePre normal:view %{execute keys i}
After the hook executes, will Kakoune be in "view" or "insert" modes? Or how about:
hook global PushModePre normal:insert %{execute keys i}
...will that cause an infinite loop?
Unless there's an important use-case for *ModePre hooks, I'd rather just declare that PushMode and PopMode always execute after the mode change has occurred.
Originally, Kakoune had four hooks for mode-change events:
InsertBegin
,InsertEnd
,NormalBegin
andNormalEnd
. However, Kakoune does have other modes, and adding "begin" and "end" hooks for all of them would be prohibitive. In fact, it would be impossible, since Kakoune has user-defined modes as well.In #1772, a new
ModeChange
hook was introduced, aiming to be a general replacement for the previous mode-change hooks. For example,InsertEnd
could be replaced with aModeChange insert:.*
hook. Unfortunately, that didn't quite work out because Kakoune maintains a stack of current modes. For example, from normal modei
pushes an insert mode, and from the insert mode<a-;>
pushes a second normal mode. That transition from insert mode to the second normal mode counts as aModeChange insert:normal
because the active mode changes, but it does not count as anInsertEnd
because the insert mode doesn't end, it just gets temporarily replaced. See also #2122To fully generally replace the original events, we should have
PushMode
andPopMode
events with the same parameter string asModeChange
. That is:InsertBegin
can be replaced withPushMode .*:insert
InsertEnd
can be replaced withPopMode insert:.*
NormalBegin
can be replaced withPushMode .*:normal
NormalEnd
can be replaced withPopMode normal:.*
ModeChange X:Y
can be replaced with hooking bothPushMode X:Y
andPopMode X:Y
In the style of the existing hooks documentation:
PushMode
X:Y
: triggered when a command in mode X starts a new Y mode; for example, when<a-;>
temporarily enters normal mode from insert mode,PushMode insert:normal
will triggerPopMode
X:Y
: triggered when a command in mode X exits that mode, returning to mode Y; for example, when<esc>
exits insert mode,PopMode insert:normal
will triggerThe text was updated successfully, but these errors were encountered: