Skip to content

[RFC] Add getcmdscreenpos() and getcmdcompltype()#10344

Closed
Shougo wants to merge 10 commits intovim:masterfrom
Shougo:cmdline_funcs
Closed

[RFC] Add getcmdscreenpos() and getcmdcompltype()#10344
Shougo wants to merge 10 commits intovim:masterfrom
Shougo:cmdline_funcs

Conversation

@Shougo
Copy link
Contributor

@Shougo Shougo commented May 3, 2022

Hi. This is the port of neovim/neovim#18284.
It is useful for popup competion in command line mode.

getcmdscreenpos() works for me. But getcmdcompletion() does not work well on Vim.
It works on neovim.

I think the implementation is same with Vim and neovim.
But the completion context seems wrong....

Can you check my implementation?

@LemonBoy
Copy link
Contributor

LemonBoy commented May 3, 2022

But the completion context seems wrong....
Can you check my implementation?

I'll give you a small hint, check Vim's declaration of command_complete array... and compare it to NeoVim's...
Also, you need a char_u cast to let the compiler shut up.

@Shougo
Copy link
Contributor Author

Shougo commented May 4, 2022

Thank you. I have fixed it. But it does not fix my errors.

set_expand_context() does not work as expected...

@Shougo
Copy link
Contributor Author

Shougo commented May 4, 2022

I have fixed the errors.

@brammool
Copy link
Contributor

brammool commented May 5, 2022

Is this still WIP?
Any comments?

@lacygoill
Copy link

From the name of the getcmdcompletion() function, I thought it was giving the currently inserted completion when a pum was visible. But actually, it gives the type of the current completion as specified by the third argument of input() or by the -complete argument of :command. Maybe we could make sure to always mention the word "type" in conjunction with "completion":

diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt
index 6abf76706..2ad34ffcf 100644
--- a/runtime/doc/builtin.txt
+++ b/runtime/doc/builtin.txt
@@ -213,8 +213,8 @@ getcharmod()			Number	modifiers for the last typed character
 getcharpos({expr})		List	position of cursor, mark, etc.
 getcharsearch()			Dict	last character search
 getcharstr([expr])		String	get one character from the user
-getcmdcompletion()		String	return the current command-line
-					completion
+getcmdcompletion()		String	return the type of the current
+					command-line completion
 getcmdline()			String	return the current command-line
 getcmdpos()			Number	return cursor position in command-line
 getcmdscreenpos()		Number	return cursor screen position in
@@ -3213,9 +3213,9 @@ getcharstr([expr])					*getcharstr()*
 		result is converted to a string.
 
 getcmdcompletion()					*getcmdcompletion()*
-		Return the current command-line completion type.  Only works
-		when the command line is being edited, thus requires use of
-		|c_CTRL-\_e| or |c_CTRL-R_=|.
+		Return the type of the current command-line completion.
+		Only works when the command line is being edited, thus requires
+		use of |c_CTRL-\_e| or |c_CTRL-R_=|.
 		See |command-completion| for the return string.
 		Also see |getcmdtype()|, |setcmdpos()| and |getcmdline()|.
 		Returns an empty string when completion is not defined.
diff --git a/runtime/doc/usr_41.txt b/runtime/doc/usr_41.txt
index c9b79e797..abcbd3453 100644
--- a/runtime/doc/usr_41.txt
+++ b/runtime/doc/usr_41.txt
@@ -976,7 +976,8 @@ Buffers, windows and the argument list:
 	swapname()		get the swap file path of a buffer
 
 Command line:					*command-line-functions*
-	getcmdcompletion()	get the current command line completion
+	getcmdcompletion()	get the type of the current command line
+				completion
 	getcmdline()		get the current command line
 	getcmdpos()		get position of the cursor in the command line
 	getcmdscreenpos()	get screen position of the cursor in the

FWIW, if it's not too late, I would also consider including "type" in the name of the function itself:

getcmdcompletion()
getcmdcompletiontype()
                ^--^

I did a quick test, and both getcmdcompletion() as well as getcmdscreenpos() seem to work as intended.

@Shougo Shougo changed the title [WIP] Add getcmdscreenpos() and getcmdcompletion() [RFC] Add getcmdscreenpos() and getcmdcompletion() May 6, 2022
@Shougo
Copy link
Contributor Author

Shougo commented May 6, 2022

Is this still WIP?
Any comments?

Sorry. It is not WIP.

@Shougo
Copy link
Contributor Author

Shougo commented May 6, 2022

I have renamed the function name.

@Shougo Shougo changed the title [RFC] Add getcmdscreenpos() and getcmdcompletion() [RFC] Add getcmdscreenpos() and getcmdcmptype() May 6, 2022
@brammool
Copy link
Contributor

brammool commented May 6, 2022

When I see getcmdcmptype() I guess "cmp" stands for compare, but it means completion.
getcmdcmpltype() ? Perhaps there is a better name. We do have getcmdtype() already.

@Shougo
Copy link
Contributor Author

Shougo commented May 7, 2022

OK. I have renamed.

@zeertzjq
Copy link
Member

zeertzjq commented May 7, 2022

cmpl has never appeared in help files, whereas compl has appeared in several help tags, so compl should be a better abbreviation.

@Shougo Shougo changed the title [RFC] Add getcmdscreenpos() and getcmdcmptype() [RFC] Add getcmdscreenpos() and getcmdcompltype() May 7, 2022
@brammool brammool closed this in 79d599b May 7, 2022
@Shougo Shougo deleted the cmdline_funcs branch May 8, 2022 00:43
zeertzjq pushed a commit to Shougo/neovim that referenced this pull request May 9, 2022
vim-patch:8.2.4903: cannot get the current cmdline completion type and position

Problem:    Cannot get the current cmdline completion type and position.
Solution:   Add getcmdcompltype() and getcmdscreenpos(). (Shougo Matsushita,
            closes vim/vim#10344)
vim/vim@79d599b

vim-patch:8.2.4910: imperfect coding

Problem:    Imperfect coding.
Solution:   Make code nicer.
vim/vim@9ff7d71
zeertzjq pushed a commit to Shougo/neovim that referenced this pull request May 9, 2022
vim-patch:8.2.4903: cannot get the current cmdline completion type and position

Problem:    Cannot get the current cmdline completion type and position.
Solution:   Add getcmdcompltype() and getcmdscreenpos(). (Shougo Matsushita,
            closes vim/vim#10344)
vim/vim@79d599b

vim-patch:8.2.4910: imperfect coding

Problem:    Imperfect coding.
Solution:   Make code nicer.
vim/vim@9ff7d71
zeertzjq pushed a commit to neovim/neovim that referenced this pull request May 9, 2022
vim-patch:8.2.4903: cannot get the current cmdline completion type and position

Problem:    Cannot get the current cmdline completion type and position.
Solution:   Add getcmdcompltype() and getcmdscreenpos(). (Shougo Matsushita,
            closes vim/vim#10344)
vim/vim@79d599b

vim-patch:8.2.4910: imperfect coding

Problem:    Imperfect coding.
Solution:   Make code nicer.
vim/vim@9ff7d71
kraftwerk28 pushed a commit to kraftwerk28/neovim that referenced this pull request Jun 1, 2022
vim-patch:8.2.4903: cannot get the current cmdline completion type and position

Problem:    Cannot get the current cmdline completion type and position.
Solution:   Add getcmdcompltype() and getcmdscreenpos(). (Shougo Matsushita,
            closes vim/vim#10344)
vim/vim@79d599b

vim-patch:8.2.4910: imperfect coding

Problem:    Imperfect coding.
Solution:   Make code nicer.
vim/vim@9ff7d71
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants