Skip to content

Add findcommand() function#7777

Closed
arp242 wants to merge 2 commits intovim:masterfrom
arp242:findcommand
Closed

Add findcommand() function#7777
arp242 wants to merge 2 commits intovim:masterfrom
arp242:findcommand

Conversation

@arp242
Copy link
Contributor

@arp242 arp242 commented Feb 4, 2021

Right now there is no way to know which shortcut commands refer to which
commands. This adds findcommand() to solve that.

Context: I made a little VimScript to show the help for the command you
typed: pressing while you typed ":syntax" shows the help for
:syntax. But I'd also like this to work for all the shortcut commands,
which is hard without this patch, especially if you want it to be a bit
smarter (i.e. load ":syn-match" if you typed :sy match").

@codecov
Copy link

codecov bot commented Feb 4, 2021

Codecov Report

Merging #7777 (3777274) into master (92bb83e) will increase coverage by 0.22%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7777      +/-   ##
==========================================
+ Coverage   88.70%   88.92%   +0.22%     
==========================================
  Files         148      144       -4     
  Lines      164696   162819    -1877     
==========================================
- Hits       146088   144786    -1302     
+ Misses      18608    18033     -575     
Flag Coverage Δ
huge-clang-none 87.65% <100.00%> (-0.53%) ⬇️
huge-gcc-none 88.49% <100.00%> (-0.01%) ⬇️
huge-gcc-testgui 86.97% <100.00%> (?)
huge-gcc-unittests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/evalfunc.c 95.98% <ø> (+0.43%) ⬆️
src/ex_docmd.c 94.80% <100.00%> (+0.09%) ⬆️
src/json.c 92.08% <0.00%> (-1.14%) ⬇️
src/memfile.c 78.36% <0.00%> (-0.51%) ⬇️
src/message.c 88.55% <0.00%> (-0.48%) ⬇️
src/drawline.c 84.59% <0.00%> (-0.47%) ⬇️
src/xdiff/xutils.c 78.57% <0.00%> (-0.45%) ⬇️
src/syntax.c 86.54% <0.00%> (-0.43%) ⬇️
src/findfile.c 88.54% <0.00%> (-0.41%) ⬇️
src/misc1.c 88.41% <0.00%> (-0.40%) ⬇️
... and 76 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 92bb83e...3777274. Read the comment docs.

@arp242
Copy link
Contributor Author

arp242 commented Feb 4, 2021

Hm, the Windows AppVeyor build fails with:

ex_docmd.c(3685) : error C2275: 'exarg_T' : illegal use of this type as an expression
        c:\projects\vim\src\ex_cmds.h(85) : see declaration of 'exarg_T'

For the line:

exarg_T ea;

Not entirely sure why that should fail, and why it fails only on Windows 🤔

I don't have a Windows machine to test, so if anyone has any hints then that would be appreciated.

@chrisbra
Copy link
Member

chrisbra commented Feb 4, 2021

exarg_T ea;

can you put this at the beginning of the function please?

@k-takata
Copy link
Member

k-takata commented Feb 4, 2021

MSVC 2010 doesn't support to declare a variable in the middle of the block.

Right now there is no way to know which shortcut commands refer to which
commands. This adds findcommand() to solve that.

Context: I made a little VimScript to show the help for the command you
typed: pressing <F1> while you typed ":syntax" shows the help for
:syntax. But I'd also like this to work for all the shortcut commands,
which is hard without this patch, especially if you want it to be a bit
smarter (i.e. load ":syn-match" if you typed :sy match").
@arp242
Copy link
Contributor Author

arp242 commented Feb 4, 2021

Ah thanks: C89 style. I'm so used to writing it like this I didn't think about that 😅 I updated the PR and it seems grand now.

@matveyt
Copy link
Contributor

matveyt commented Feb 4, 2021

Well, but couldn't we instead of this just to omit sorting step while expanding "command" specifically, so both getcompletion("syn", "command") will return ["syntax", "syntime", "syncbind"] in this order, and also :syn<tab> will nicely expand into "syntax" first?

@arp242
Copy link
Contributor Author

arp242 commented Feb 4, 2021

Well, but couldn't we instead of this just to omit sorting step while expanding "command" specifically, so both getcompletion("syn", "command") will return ["syntax", "syntime", "syncbind"] in this order, and also :syn<tab> will nicely expand into "syntax" first?

I wouldn't be in favour of that myself; I think the completion and "shortcut" logic are quite different things, and I don't think many people would expect the cmdline completion behaviour to be modified based on that. Having :substitute on top when doing :s<Tab> seems really weird to me, and would be doubly weird with wildmode=full.

@brammool
Copy link
Contributor

brammool commented Feb 4, 2021

Instead of "shorcut" the term "abbreviation" should be used. This is mentioned in section 20.2 of the user manual.
"findcommand" isn't quite right. How about "fullcommand" ?

@arp242
Copy link
Contributor Author

arp242 commented Feb 5, 2021

I avoided using the word "abbreviation" to avoid confusing between this and :abbr abbreviations.

At any rate, I updated the name to fullcommand() and tweaked the help page a bit.

@brammool brammool closed this in 038e09e Feb 6, 2021
zeertzjq added a commit to zeertzjq/neovim that referenced this pull request Dec 25, 2021
…tened one

Problem:    Not easy to get the full command name from a shortened one.
Solution:   Add fullcommand(). (Martin Tournoij, closes vim/vim#7777)
vim/vim@038e09e
dundargoc pushed a commit to dundargoc/neovim that referenced this pull request Dec 26, 2021
…tened one

Problem:    Not easy to get the full command name from a shortened one.
Solution:   Add fullcommand(). (Martin Tournoij, closes vim/vim#7777)
vim/vim@038e09e
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