Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete file name and file path swapped in doc #1146

Closed
lobre opened this issue Oct 11, 2023 · 4 comments · Fixed by #1148
Closed

Complete file name and file path swapped in doc #1146

lobre opened this issue Oct 11, 2023 · 4 comments · Fixed by #1148

Comments

@lobre
Copy link

lobre commented Oct 11, 2023

Doing :help gives me this:

<C-x><C-f>            Complete file path                                                                                                                                                                                             
<C-x><C-o>            Complete file name

Trying myself, it seems it is the opposite in fact:

<C-x><C-f>            Complete file name                                                                                                                                                                                             
<C-x><C-o>            Complete file path

I don't know if it is the implementation or doc that is wrong.

@mcepl
Copy link
Contributor

mcepl commented Oct 12, 2023

It is all in the script lua/plugins/complete-filename.lua (which badly cries for the refactoring love), and I wonder what’s the actual difference between two commands. Documentation has a lot to be desired.

@rnpnr
Copy link
Collaborator

rnpnr commented Oct 13, 2023

The difference isn't that big. Assuming $PWD = /usr:

<C-x><C-f>: bin/ --> bin/awk
<C-x><C-o>: bin/ --> /usr/bin/awk

Here is my first attempt at cleaning it up, but it could probably be better:

local complete_filename = function(expand)
	local win = vis.win
	local file = win.file
	local pos = win.selection.pos
	if not pos then return end

	-- TODO do something clever here
	local range = file:text_object_longword(pos > 0 and pos-1 or pos);
	if not range then return end
	if range.finish > pos then range.finish = pos end
	if not expand and range.start == range.finish then return end

	local prefix = file:content(range)
	if not prefix then return end

	-- Strip leading delimiters for some progamming languages
	local _, j = prefix:find("[[(<'\"]+")
	if not expand and j then prefix = prefix:sub(j + 1) end
	if expand and prefix:match("^%s*$") then
		prefix = ""
		range.start = pos
		range.finish = pos
	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("'", "'\\''")))
	if status ~= 0 or not out then
		if err then vis:info(err) end
		return
	end
	out = out:gsub("\n$", "")

	if expand then
		file:delete(range)
		file:insert(range.start, out)
		win.selection.pos = range.start + #out
	else
		file:insert(pos, out)
		win.selection.pos = pos + #out
	end
end

-- complete file path at primary selection location using vis-complete(1)
vis:map(vis.modes.INSERT, "<C-x><C-f>", function()
	complete_filename(false);
end, "Complete file name")

-- complete file path at primary selection location using vis-open(1)
vis:map(vis.modes.INSERT, "<C-x><C-o>", function()
	complete_filename(true);
end, "Complete file name (expands path)")

@mcepl
Copy link
Contributor

mcepl commented Oct 13, 2023

Perhaps PR would be better? Something like https://git.sr.ht/~mcepl/vis/commit/620d37d121f76b0fe98d75040d3337fe5d73f5f4 ?

rnpnr added a commit to rnpnr/vis that referenced this issue Oct 13, 2023
There are probably more things to simplify but at least this makes
it easier to see what exactly is different between `<C-x><C-f>` and
`<C-x><C-o>`.

closes martanne#1146
@rnpnr
Copy link
Collaborator

rnpnr commented Oct 13, 2023

Perhaps PR would be better?

Done: #1148. I didn't use yours because your repo has some commit adding expansion of ~ to $HOME. Its probably fine but should be added as a separate commit.

rnpnr added a commit to rnpnr/vis that referenced this issue Oct 17, 2023
There are probably more things to simplify but at least this makes
it easier to see what exactly is different between `<C-x><C-f>` and
`<C-x><C-o>`.

closes martanne#1146: Complete file name and file path swapped in doc
rnpnr added a commit to rnpnr/vis that referenced this issue Oct 17, 2023
There are probably more things to simplify but at least this makes
it easier to see what exactly is different between `<C-x><C-f>` and
`<C-x><C-o>`.

closes martanne#1146: Complete file name and file path swapped in doc
rnpnr added a commit to rnpnr/vis that referenced this issue Oct 17, 2023
There are probably more things to simplify but at least this makes
it easier to see what exactly is different between `<C-x><C-f>` and
`<C-x><C-o>`.

Some differences were removed:
* whitespace in range is treated the same for both actions
* empty range will expand to files in CWD for both actions

closes martanne#1146: Complete file name and file path swapped in doc
rnpnr added a commit to rnpnr/vis that referenced this issue Oct 23, 2023
There are probably more things to simplify but at least this makes
it easier to see what exactly is different between `<C-x><C-f>` and
`<C-x><C-o>`.

Some differences were removed:
* whitespace in range is treated the same for both actions
* empty range will expand to files in CWD for both actions

closes martanne#1146: Complete file name and file path swapped in doc
rnpnr added a commit to rnpnr/vis that referenced this issue Oct 23, 2023
There are probably more things to simplify but at least this makes
it easier to see what exactly is different between `<C-x><C-f>` and
`<C-x><C-o>`.

Some differences were removed:
* whitespace in range is treated the same for both actions
* empty range will expand to files in CWD for both actions

closes martanne#1146: Complete file name and file path swapped in doc
rnpnr added a commit to rnpnr/vis that referenced this issue Oct 24, 2023
There are probably more things to simplify but at least this makes
it easier to see what exactly is different between `<C-x><C-f>` and
`<C-x><C-o>`.

Some differences were removed:
* whitespace in range is treated the same for both actions
* empty range will expand to files in CWD for both actions

closes martanne#1146: Complete file name and file path swapped in doc
rnpnr added a commit to rnpnr/vis that referenced this issue Oct 25, 2023
There are probably more things to simplify but at least this makes
it easier to see what exactly is different between `<C-x><C-f>` and
`<C-x><C-o>`.

Some differences were removed:
* whitespace in range is treated the same for both actions
* empty range will expand to files in CWD for both actions

closes martanne#1146: Complete file name and file path swapped in doc
rnpnr added a commit to rnpnr/vis that referenced this issue Oct 30, 2023
There are probably more things to simplify but at least this makes
it easier to see what exactly is different between `<C-x><C-f>` and
`<C-x><C-o>`.

Some differences were removed:
* whitespace in range is treated the same for both actions
* empty range will expand to files in CWD for both actions

closes martanne#1146: Complete file name and file path swapped in doc
@rnpnr rnpnr closed this as completed in 1e64b1c Nov 3, 2023
jeremybobbin pushed a commit to jeremybobbin/vis that referenced this issue Aug 17, 2024
There are probably more things to simplify but at least this makes
it easier to see what exactly is different between `<C-x><C-f>` and
`<C-x><C-o>`.

Some differences were removed:
* whitespace in range is treated the same for both actions
* empty range will expand to files in CWD for both actions

closes martanne#1146: Complete file name and file path swapped in doc
jeremybobbin pushed a commit to jeremybobbin/vis that referenced this issue Sep 1, 2024
There are probably more things to simplify but at least this makes
it easier to see what exactly is different between `<C-x><C-f>` and
`<C-x><C-o>`.

Some differences were removed:
* whitespace in range is treated the same for both actions
* empty range will expand to files in CWD for both actions

closes martanne#1146: Complete file name and file path swapped in doc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants