~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
7 5

[PATCH vis] complete-filename: complete tilda as $HOME as well

Details
Message ID
<20250115223459.2546636-1-mcepl@cepl.eu>
Sender timestamp
1736984080
DKIM signature
pass
Download raw message
Patch: +3 -0
References: https://github.com/martanne/vis/pull/1148#issuecomment-1792649763
---
 lua/plugins/complete-filename.lua | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lua/plugins/complete-filename.lua b/lua/plugins/complete-filename.lua
index 43cf14b1..588ff877 100644
--- a/lua/plugins/complete-filename.lua
+++ b/lua/plugins/complete-filename.lua
@@ -22,6 +22,9 @@ local complete_filename = function(expand)
		range.finish = pos
	end

	-- Expand tilda for the home directory
	prefix = prefix:gsub("^~", os.getenv("HOME"), 1)

	local cmdfmt = "vis-complete --file '%s'"
	if expand then cmdfmt = "vis-open -- '%s'*" end
	local status, out, err = vis:pipe(cmdfmt:format(prefix:gsub("'", "'\\''")))
-- 
2.47.1
Silvan Jegen <s.jegen@gmail.com>
Details
Message ID
<3L5RQLXNG5H39.30EF16TMJ6PE1@homearch.localdomain>
In-Reply-To
<20250115223459.2546636-1-mcepl@cepl.eu> (view parent)
Sender timestamp
1737289095
DKIM signature
pass
Download raw message
Matěj Cepl <mcepl@cepl.eu> wrote:
> References: https://github.com/martanne/vis/pull/1148#issuecomment-1792649763

With this patch applied, doing <C-x><C-o> expands the tilde character to $HOME.
Not sure why it doesn't do the same when typing <C-x><C-f> but either way this
LGTM!


Cheers,
Silvan
Details
Message ID
<D760O3GZ8S8H.1Y8FM8NTY20CJ@cepl.eu>
In-Reply-To
<3L5RQLXNG5H39.30EF16TMJ6PE1@homearch.localdomain> (view parent)
Sender timestamp
1737290107
DKIM signature
pass
Download raw message
On Sun Jan 19, 2025 at 12:18 PM CET, Silvan Jegen wrote:
>> References: https://github.com/martanne/vis/pull/1148#issuecomment-1792649763
>
> With this patch applied, doing <C-x><C-o> expands the tilde character to $HOME.
> Not sure why it doesn't do the same when typing <C-x><C-f> but either way this
> LGTM!

See the discussion on the referred GitHub pull request, I believe
this is the correct way how to do it, and certainly it is the way
it more matters to me, because <C-x><C-o> is bound to <TAB> in
`:open` prompt [1], so `~` is thus expanded there.

Thank you for checking this,

Matěj

[1] https://git.sr.ht/~martanne/vis/tree/master/item/vis-prompt.c#L154
-- 
http://matej.ceplovi.cz/blog/, @mcepl@en.osm.town
GPG Finger: 3C76 A027 CA45 AD70 98B5  BC1D 7920 5802 880B C9D8
 
We are told that [St. Anthony] once fell into dejection, finding
uninterrupted contemplation above his strength; but was taught to
apply himself at intervals to manual labour by a vision of an
angel who appeared platting mats of palm-tree leaves, then rising
to pray, and after some time sitting down again to work; and who
at length said to him, “Do thus, and thou shalt be saved.”
    -- Life of St. Anthony
Details
Message ID
<3266ONSS85PVY.38B526JLFEF5Z@homearch.localdomain>
In-Reply-To
<D760O3GZ8S8H.1Y8FM8NTY20CJ@cepl.eu> (view parent)
Sender timestamp
1737290540
DKIM signature
missing
Download raw message
Matěj Cepl <mcepl@cepl.eu> wrote:
> On Sun Jan 19, 2025 at 12:18 PM CET, Silvan Jegen wrote:
> >> References: https://github.com/martanne/vis/pull/1148#issuecomment-1792649763
> >
> > With this patch applied, doing <C-x><C-o> expands the tilde character to $HOME.
> > Not sure why it doesn't do the same when typing <C-x><C-f> but either way this
> > LGTM!
> 
> See the discussion on the referred GitHub pull request, I believe
> this is the correct way how to do it, and certainly it is the way
> it more matters to me, because <C-x><C-o> is bound to <TAB> in
> `:open` prompt [1], so `~` is thus expanded there.

Works for me as well! :) Thanks for the explanation!

> 
> Thank you for checking this,

NP!


Cheers,
Silvan
Details
Message ID
<2ID892TCURPNP.2O8F4AK3Q6H7P@rnpnr.xyz>
In-Reply-To
<20250115223459.2546636-1-mcepl@cepl.eu> (view parent)
Sender timestamp
1737278597
DKIM signature
permerror
Download raw message
Matěj Cepl <mcepl@cepl.eu> wrote:
> References: https://github.com/martanne/vis/pull/1148#issuecomment-1792649763
> ---
>  lua/plugins/complete-filename.lua | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/lua/plugins/complete-filename.lua b/lua/plugins/complete-filename.lua
> index 43cf14b1..588ff877 100644
> --- a/lua/plugins/complete-filename.lua
> +++ b/lua/plugins/complete-filename.lua
> @@ -22,6 +22,9 @@ local complete_filename = function(expand)
>  		range.finish = pos
>  	end
>  
> +	-- Expand tilda for the home directory
> +	prefix = prefix:gsub("^~", os.getenv("HOME"), 1)
> +
>  	local cmdfmt = "vis-complete --file '%s'"
>  	if expand then cmdfmt = "vis-open -- '%s'*" end
>  	local status, out, err = vis:pipe(cmdfmt:format(prefix:gsub("'", "'\\''")))

Hi,

Can you please move the return from os.getenv to a seperate
variable so that it can be checked for validity? string.gsub()
gives a very useless error message if it is passed nil. Probably
you can do all of that in a block that is conditional on '^~'
being present at the start of prefix (string.find()).

Randy

-- 
https://rnpnr.xyz/
GPG Fingerprint: B8F0 CF4C B6E9 415C 1B27 A8C4 C8D2 F782 86DF 2DC5

[PATCH vis v2] complete-filename: complete tilda as $HOME as well

Details
Message ID
<20250119163522.1230400-2-mcepl@cepl.eu>
In-Reply-To
<2ID892TCURPNP.2O8F4AK3Q6H7P@rnpnr.xyz> (view parent)
Sender timestamp
1737308049
DKIM signature
pass
Download raw message
Patch: +6 -0
References: https://github.com/martanne/vis/pull/1148#issuecomment-1792649763
---
I am not certain whether this is truly necessary (that
string.find condition is implicitly included in string.gsub
itself), but if it makes you happy.

 lua/plugins/complete-filename.lua | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/lua/plugins/complete-filename.lua b/lua/plugins/complete-filename.lua
index 43cf14b1..02b9f3a9 100644
--- a/lua/plugins/complete-filename.lua
+++ b/lua/plugins/complete-filename.lua
@@ -22,6 +22,12 @@ local complete_filename = function(expand)
		range.finish = pos
	end

	-- Expand tilda for the home directory
	if prefix:find('^~') then
		local home = assert(os.getenv("HOME"), "$HOME variable not set!")
		prefix = prefix:gsub("^~", home, 1)
	end

	local cmdfmt = "vis-complete --file '%s'"
	if expand then cmdfmt = "vis-open -- '%s'*" end
	local status, out, err = vis:pipe(cmdfmt:format(prefix:gsub("'", "'\\''")))
-- 
2.48.0

Re: [PATCH vis v2] complete-filename: complete tilda as $HOME as well

Details
Message ID
<38C5KPLDQ3ZY3.3QPMWACPBJTUV@rnpnr.xyz>
In-Reply-To
<20250119163522.1230400-2-mcepl@cepl.eu> (view parent)
Sender timestamp
1737321373
DKIM signature
permerror
Download raw message
Matěj Cepl <mcepl@cepl.eu> wrote:
> References: https://github.com/martanne/vis/pull/1148#issuecomment-1792649763
> ---
> I am not certain whether this is truly necessary (that
> string.find condition is implicitly included in string.gsub
> itself), but if it makes you happy.

Technically you can be more efficient by storing the start and end
index given by string.find and then use string.sub to avoid having
to do the match again (as well as saving the getenv call when its
not needed) but I'm not going to rat-hole on that.

Applied!

-- 
https://rnpnr.xyz/
GPG Fingerprint: B8F0 CF4C B6E9 415C 1B27 A8C4 C8D2 F782 86DF 2DC5

[PATCH vis] complete-filename: speed-up the tilda handling

Details
Message ID
<20250120074741.3536730-2-mcepl@cepl.eu>
In-Reply-To
<38C5KPLDQ3ZY3.3QPMWACPBJTUV@rnpnr.xyz> (view parent)
Sender timestamp
1737362851
DKIM signature
pass
Download raw message
Patch: +3 -2
When profiling (on 100,000 calls) with this test:

```lua
start_t = os.clock()
for i = 1, 100000 do
    _ = home .. prefix
end
end_t = os.clock()
print(end_t - start_t)
```

I get on my computer this (warm):

    os.getenv("HOME") 0.005506
    str:gsub("^~", home) 0.009333
    str:find("^~") 0.006041
    str:sub(2) 0.005455
    a .. b 0.003603

Difference between gsub and sub + .. seems negligible, but just
to make it correct, here we are.
---
 lua/plugins/complete-filename.lua | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lua/plugins/complete-filename.lua b/lua/plugins/complete-filename.lua
index 02b9f3a9..604361c2 100644
--- a/lua/plugins/complete-filename.lua
+++ b/lua/plugins/complete-filename.lua
@@ -23,9 +23,10 @@ local complete_filename = function(expand)
	end

	-- Expand tilda for the home directory
	if prefix:find('^~') then
	_, j = prefix:find('^~')
	if j ~= nil then
		local home = assert(os.getenv("HOME"), "$HOME variable not set!")
		prefix = prefix:gsub("^~", home, 1)
		prefix = home .. prefix:sub(j + 1)
	end

	local cmdfmt = "vis-complete --file '%s'"
-- 
2.48.0
Reply to thread Export thread (mbox)