~martanne/devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH] lua: complete-word: stay in current mode

Details
Message ID
<20240325175810.3046364-1-florian.fischer@muhq.space>
DKIM signature
permerror
Download raw message
Patch: +3 -0
Completing word causes vis to exit insert mode, since we changed
complete-words to use vis' regex in 004800e348cba1bf5f4536876b4e0eafbcf1ea58.

Simply remember the current mode and restore it after the completion.
---
 lua/plugins/complete-word.lua | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lua/plugins/complete-word.lua b/lua/plugins/complete-word.lua
index 78127514..f330e598 100644
--- a/lua/plugins/complete-word.lua
+++ b/lua/plugins/complete-word.lua
@@ -13,6 +13,8 @@ vis:map(vis.modes.INSERT, "<C-n>", function()
	local prefix = file:content(range)
	if not prefix then return end

	local mode = vis.mode

	vis:feedkeys("<vis-selections-save><Escape><Escape>")
	-- collect words starting with prefix
	vis:command("x/\\b" .. prefix .. "\\w+/")
@@ -33,4 +35,5 @@ vis:map(vis.modes.INSERT, "<C-n>", function()
	out = out:sub(#prefix + 1, #out - 1)
	file:insert(pos, out)
	win.selection.pos = pos + #out
	vis.mode = mode
end, "Complete word in file")
-- 
2.44.0
Details
Message ID
<37G1YBUPAY6UN.3NJ7QJ3K79J6J@homearch.localdomain>
In-Reply-To
<20240325175810.3046364-1-florian.fischer@muhq.space> (view parent)
DKIM signature
missing
Download raw message
Florian Fischer <florian.fischer@muhq.space> wrote:
> Completing word causes vis to exit insert mode, since we changed
> complete-words to use vis' regex in 004800e348cba1bf5f4536876b4e0eafbcf1ea58.
> 
> Simply remember the current mode and restore it after the completion.

LGTM!

Cheers,
Silvan

> ---
>  lua/plugins/complete-word.lua | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/lua/plugins/complete-word.lua b/lua/plugins/complete-word.lua
> index 78127514..f330e598 100644
> --- a/lua/plugins/complete-word.lua
> +++ b/lua/plugins/complete-word.lua
> @@ -13,6 +13,8 @@ vis:map(vis.modes.INSERT, "<C-n>", function()
>  	local prefix = file:content(range)
>  	if not prefix then return end
>  
> +	local mode = vis.mode
> +
>  	vis:feedkeys("<vis-selections-save><Escape><Escape>")
>  	-- collect words starting with prefix
>  	vis:command("x/\\b" .. prefix .. "\\w+/")
> @@ -33,4 +35,5 @@ vis:map(vis.modes.INSERT, "<C-n>", function()
>  	out = out:sub(#prefix + 1, #out - 1)
>  	file:insert(pos, out)
>  	win.selection.pos = pos + #out
> +	vis.mode = mode
>  end, "Complete word in file")
Details
Message ID
<267EM0X5I8E5Y.2GOWV804O1IF7@rnpnr.xyz>
In-Reply-To
<20240325175810.3046364-1-florian.fischer@muhq.space> (view parent)
DKIM signature
permerror
Download raw message
Florian Fischer <florian.fischer@muhq.space> wrote:
> Completing word causes vis to exit insert mode, since we changed
> complete-words to use vis' regex in 004800e348cba1bf5f4536876b4e0eafbcf1ea58.
> 
> Simply remember the current mode and restore it after the completion.
> ---
>  lua/plugins/complete-word.lua | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/lua/plugins/complete-word.lua b/lua/plugins/complete-word.lua
> index 78127514..f330e598 100644
> --- a/lua/plugins/complete-word.lua
> +++ b/lua/plugins/complete-word.lua
> @@ -13,6 +13,8 @@ vis:map(vis.modes.INSERT, "<C-n>", function()
>  	local prefix = file:content(range)
>  	if not prefix then return end
>  
> +	local mode = vis.mode
> +
>  	vis:feedkeys("<vis-selections-save><Escape><Escape>")
>  	-- collect words starting with prefix
>  	vis:command("x/\\b" .. prefix .. "\\w+/")
> @@ -33,4 +35,5 @@ vis:map(vis.modes.INSERT, "<C-n>", function()
>  	out = out:sub(#prefix + 1, #out - 1)
>  	file:insert(pos, out)
>  	win.selection.pos = pos + #out
> +	vis.mode = mode
>  end, "Complete word in file")

Hi Florian,

Thanks for the patch; I guess I forgot to commit the fix when I
noticed this earlier. I will go with just explicitly setting mode
back to INSERT on exit since this keybinding is only valid in INSERT
mode.

- Randy

-- 
https://rnpnr.xyz/
GPG Fingerprint: B8F0 CF4C B6E9 415C 1B27 A8C4 C8D2 F782 86DF 2DC5
Reply to thread Export thread (mbox)