The expand() function can be used to expand special characters. If the special
characters appears anywhere in the command string, then this cannot be used.
Vim supports expanding special characters anywhere in a command string
for internal commands. For example, the 'makeprg' option accepts a command
string where special characters can occur anywhere in the string.
But a Vim plugin cannot support this. So plugins like dispatch.vim use a complicated
function to expand the special characters (look at the dispatch#expand() function in
https://github.com/tpope/vim-dispatch/blob/master/autoload/dispatch.vim).
This patch adds a expandcmd() function that can be used to expand all the
special characters in a command string.
https://github.com/vim/vim/pull/4514
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
Merging #4514 into master will increase coverage by
<.01%.
The diff coverage is100%.
@@ Coverage Diff @@ ## master #4514 +/- ## ========================================== + Coverage 80.63% 80.64% +<.01% ========================================== Files 110 110 Lines 143701 143713 +12 ========================================== + Hits 115874 115898 +24 + Misses 27827 27815 -12
| Impacted Files | Coverage Δ | |
|---|---|---|
| src/evalfunc.c | 89.31% <100%> (+0.02%) |
⬆️ |
| src/if_xcmdsrv.c | 83.84% <0%> (-0.18%) |
⬇️ |
| src/channel.c | 83.37% <0%> (-0.08%) |
⬇️ |
| src/message.c | 76.89% <0%> (+0.04%) |
⬆️ |
| src/window.c | 87.28% <0%> (+0.09%) |
⬆️ |
| src/gui.c | 58.21% <0%> (+0.1%) |
⬆️ |
| src/gui_gtk_x11.c | 49.55% <0%> (+0.44%) |
⬆️ |
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 260addf...4136d34. Read the comment docs.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.![]()
@yegappan Thank you for implementing expandcmd(). I would like to use it but I have 2 questions:
Would it make sense for the function to also expand // into /last search pattern/?
https://github.com/vim/vim/blob/7a3330fc578033f06a94c23de61a23edcc59f95e/runtime/doc/quickfix.txt#L1026-L1027
As an example, it could perform this expansion:
/my pattern
:echo expandcmd('vim //gj %')
vim /my pattern/gj current_file
Also, expandcmd() does not escape special characters when they're generated by an expansion (e.g. a filename containing the literal character %). For %, #, !, I guess it's not an issue, because we can use fnameescape(); but for spaces, it's different:
$ vim /tmp/foo\ bar/baz
:echo expandcmd('vim /pat/ %')
vim /pat/ /tmp/foo bar/baz
In the expansion, how can we know whether the original command was grepping into the file /tmp/foo bar/baz, or in the files /tmp/foo and $PWD/bar/baz?
Shouldn't expandcmd() at least escape a space when it's used in a filename?
vim /pat/ /tmp/foo\ bar/baz
^
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.![]()
@yegappan Thank you for implementing
expandcmd(). I would like to use it but I have 2 questions:Would it make sense for the function to also expand
//into/last search pattern/?
https://github.com/vim/vim/blob/7a3330fc578033f06a94c23de61a23edcc59f95e/runtime/doc/quickfix.txt#L1026-L1027As an example, it could perform this expansion:
/my pattern :echo expandcmd('vim //gj %') vim /my pattern/gj current_file
Also,
expandcmd()does not escape special characters when they're generated by an expansion (e.g. a filename containing the literal character%). For%,#,!, I guess it's not an issue, because we can usefnameescape(); but for spaces, it's different:$ vim /tmp/foo\ bar/baz :echo expandcmd('vim /pat/ %') vim /pat/ /tmp/foo bar/bazIn the expansion, how can we know whether the original command was grepping into the file
/tmp/foo bar/baz, or in the files/tmp/fooand$PWD/bar/baz?Shouldn't
expandcmd()at least escape a space when it's used in a filename?vim /pat/ /tmp/foo\ bar/baz ^
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.![]()
I think you can use the ":S" filename modifier to escape the special characters in the file name.
Ok, but I don't think it works when expanding ## into the filenames of the arglist.
$ cd /tmp
$ vim a\ b c d\ e
:echo expandcmd('vim /pat/ ##:S')
vim /pat/ a b c d e:S
I guess we need to handle ## specially:
:echo expandcmd('vim /pat/ ' .. argv()->map({_, v -> shellescape(v, 1)})->join())
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.![]()