Patch 8.2.2228

7 views
Skip to first unread message

Bram Moolenaar

unread,
Dec 27, 2020, 10:55:45 AM12/27/20
to vim...@googlegroups.com

Patch 8.2.2228
Problem: Vim9: cannot use ":e #" because # starts a comment.
Solution: Support using %% instead of #.
Files: src/ex_docmd.c, src/testdir/test_vim9_cmd.vim


*** ../vim-8.2.2227/src/ex_docmd.c 2020-12-26 15:39:24.619550795 +0100
--- src/ex_docmd.c 2020-12-27 16:53:46.569379246 +0100
***************
*** 8535,8552 ****
/*
* Evaluate cmdline variables.
*
! * change '%' to curbuf->b_ffname
! * '#' to curwin->w_alt_fnum
! * '<cword>' to word under the cursor
! * '<cWORD>' to WORD under the cursor
! * '<cexpr>' to C-expression under the cursor
! * '<cfile>' to path name under the cursor
! * '<sfile>' to sourced file name
! * '<stack>' to call stack
! * '<slnum>' to sourced file line number
! * '<afile>' to file name for autocommand
! * '<abuf>' to buffer number for autocommand
! * '<amatch>' to matching name for autocommand
*
* When an error is detected, "errormsg" is set to a non-NULL pointer (may be
* "" for error without a message) and NULL is returned.
--- 8535,8553 ----
/*
* Evaluate cmdline variables.
*
! * change "%" to curbuf->b_ffname
! * "#" to curwin->w_alt_fnum
! * "%%" to curwin->w_alt_fnum in Vim9 script
! * "<cword>" to word under the cursor
! * "<cWORD>" to WORD under the cursor
! * "<cexpr>" to C-expression under the cursor
! * "<cfile>" to path name under the cursor
! * "<sfile>" to sourced file name
! * "<stack>" to call stack
! * "<slnum>" to sourced file line number
! * "<afile>" to file name for autocommand
! * "<abuf>" to buffer number for autocommand
! * "<amatch>" to matching name for autocommand
*
* When an error is detected, "errormsg" is set to a non-NULL pointer (may be
* "" for error without a message) and NULL is returned.
***************
*** 8627,8673 ****
*/
else
{
switch (spec_idx)
{
! case SPEC_PERC: // '%': current file
! if (curbuf->b_fname == NULL)
{
! result = (char_u *)"";
! valid = 0; // Must have ":p:h" to be valid
! }
! else
! {
! result = curbuf->b_fname;
! tilde_file = STRCMP(result, "~") == 0;
}
! break;

case SPEC_HASH: // '#' or "#99": alternate file
! if (src[1] == '#') // "##": the argument list
{
result = arg_all();
resultbuf = result;
! *usedlen = 2;
if (escaped != NULL)
*escaped = TRUE;
skip_mod = TRUE;
break;
}
! s = src + 1;
if (*s == '<') // "#<99" uses v:oldfiles
++s;
i = (int)getdigits(&s);
! if (s == src + 2 && src[1] == '-')
// just a minus sign, don't skip over it
s--;
*usedlen = (int)(s - src); // length of what we expand

! if (src[1] == '<' && i != 0)
{
! if (*usedlen < 2)
{
// Should we give an error message for #<text?
! *usedlen = 1;
return NULL;
}
#ifdef FEAT_EVAL
--- 8628,8684 ----
*/
else
{
+ int off = 0;
+
switch (spec_idx)
{
! case SPEC_PERC:
! if (!in_vim9script() || src[1] != '%')
{
! // '%': current file
! if (curbuf->b_fname == NULL)
! {
! result = (char_u *)"";
! valid = 0; // Must have ":p:h" to be valid
! }
! else
! {
! result = curbuf->b_fname;
! tilde_file = STRCMP(result, "~") == 0;
! }
! break;
}
! // "%%" alternate file
! off = 1;
! // FALLTHROUGH

case SPEC_HASH: // '#' or "#99": alternate file
! if (off == 0 ? src[1] == '#' : src[2] == '%')
{
+ // "##" or "%%%": the argument list
result = arg_all();
resultbuf = result;
! *usedlen = off + 2;
if (escaped != NULL)
*escaped = TRUE;
skip_mod = TRUE;
break;
}
! s = src + off + 1;
if (*s == '<') // "#<99" uses v:oldfiles
++s;
i = (int)getdigits(&s);
! if (s == src + off + 2 && src[off + 1] == '-')
// just a minus sign, don't skip over it
s--;
*usedlen = (int)(s - src); // length of what we expand

! if (src[off + 1] == '<' && i != 0)
{
! if (*usedlen < off + 2)
{
// Should we give an error message for #<text?
! *usedlen = off + 1;
return NULL;
}
#ifdef FEAT_EVAL
***************
*** 8685,8692 ****
}
else
{
! if (i == 0 && src[1] == '<' && *usedlen > 1)
! *usedlen = 1;
buf = buflist_findnr(i);
if (buf == NULL)
{
--- 8696,8703 ----
}
else
{
! if (i == 0 && src[off + 1] == '<' && *usedlen > off + 1)
! *usedlen = off + 1;
buf = buflist_findnr(i);
if (buf == NULL)
{
*** ../vim-8.2.2227/src/testdir/test_vim9_cmd.vim 2020-12-25 19:47:21.581534942 +0100
--- src/testdir/test_vim9_cmd.vim 2020-12-27 16:46:30.559040727 +0100
***************
*** 25,30 ****
--- 25,77 ----
CheckDefFailure(['edit `="foo"'], 'E1083:')
enddef

+ def Test_expand_alternate_file()
+ var lines =<< trim END
+ edit Xfileone
+ var bone = bufnr()
+ edit Xfiletwo
+ var btwo = bufnr()
+ edit Xfilethree
+ var bthree = bufnr()
+
+ edit #
+ assert_equal(bthree, bufnr())
+ edit %%
+ assert_equal(btwo, bufnr())
+ edit %% # comment
+ assert_equal(bthree, bufnr())
+ edit %%yy
+ assert_equal('Xfiletwoyy', bufname())
+
+ exe "edit %%" .. bone
+ assert_equal(bone, bufnr())
+ exe "edit %%" .. btwo .. "xx"
+ assert_equal('Xfiletwoxx', bufname())
+
+ next Xfileone Xfiletwo Xfilethree
+ assert_equal('Xfileone', argv(0))
+ assert_equal('Xfiletwo', argv(1))
+ assert_equal('Xfilethree', argv(2))
+ next %%%zz
+ assert_equal('Xfileone', argv(0))
+ assert_equal('Xfiletwo', argv(1))
+ assert_equal('Xfilethreezz', argv(2))
+
+ v:oldfiles = ['Xonefile', 'Xtwofile']
+ edit %%<1
+ assert_equal('Xonefile', bufname())
+ edit %%<2
+ assert_equal('Xtwofile', bufname())
+ assert_fails('edit %%<3', 'E684:')
+
+ edit Xfileone.vim
+ edit Xfiletwo
+ edit %%:r
+ assert_equal('Xfileone', bufname())
+ END
+ CheckDefAndScriptSuccess(lines)
+ enddef
+
def Test_global_backtick_expansion()
new
setline(1, 'xx')
*** ../vim-8.2.2227/src/version.c 2020-12-27 14:43:23.497570151 +0100
--- src/version.c 2020-12-27 15:59:52.770527843 +0100
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 2228,
/**/

--
"You know, it's at times like this when I'm trapped in a Vogon airlock with
a man from Betelgeuse and about to die of asphyxiation in deep space that I
really wish I'd listened to what my mother told me when I was young!"
"Why, what did she tell you?"
"I don't know, I didn't listen!"
-- Arthur Dent and Ford Prefect in Douglas Adams'
"The Hitchhiker's Guide to the Galaxy"

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Tony Mechelynck

unread,
Dec 27, 2020, 11:07:01 AM12/27/20
to Bram Moolenaar, vim_dev
On Sun, Dec 27, 2020 at 4:55 PM Bram Moolenaar <Br...@moolenaar.net> wrote:
>
>
> Patch 8.2.2228
> Problem: Vim9: cannot use ":e #" because # starts a comment.
> Solution: Support using %% instead of #.
> Files: src/ex_docmd.c, src/testdir/test_vim9_cmd.vim

I get the following compile warning and link error in Tiny and Small
after applying this patch:

linux-2iyu:~/.build/vim/vim-hg/src/shadow-tiny # (make || echo 'exit
status' $? ; date) 2>&1 |tee -a make.log
gcc -c -I. -Iproto -DHAVE_CONFIG_H -O2 -fno-strength-reduce -Wall
-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -o objects/ex_docmd.o
ex_docmd.c
ex_docmd.c: In function ‘eval_vars’:
ex_docmd.c:8636:8: warning: implicit declaration of function
‘in_vim9script’; did you mean ‘ex_vim9script’?
[-Wimplicit-function-declaration]
if (!in_vim9script() || src[1] != '%')
^~~~~~~~~~~~~
ex_vim9script
gcc -c -I. -Iproto -DHAVE_CONFIG_H -O2 -fno-strength-reduce -Wall
-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 version.c -o
objects/version.o
link.sh: $LINK_AS_NEEDED set to 'yes': invoking linker directly.
gcc -L/usr/local/lib -Wl,--as-needed -o vi objects/arabic.o
objects/arglist.o objects/autocmd.o objects/beval.o objects/buffer.o
objects/change.o objects/blob.o objects/blowfish.o objects/cindent.o
objects/clientserver.o objects/clipboard.o objects/cmdexpand.o
objects/cmdhist.o objects/crypt.o objects/crypt_zip.o
objects/debugger.o objects/dict.o objects/diff.o objects/digraph.o
objects/drawline.o objects/drawscreen.o objects/edit.o objects/eval.o
objects/evalbuffer.o objects/evalfunc.o objects/evalvars.o
objects/evalwindow.o objects/ex_cmds.o objects/ex_cmds2.o
objects/ex_docmd.o objects/ex_eval.o objects/ex_getln.o
objects/fileio.o objects/filepath.o objects/findfile.o objects/fold.o
objects/getchar.o objects/gui_xim.o objects/hardcopy.o
objects/hashtab.o objects/help.o objects/highlight.o
objects/if_cscope.o objects/if_xcmdsrv.o objects/indent.o
objects/insexpand.o objects/list.o objects/locale.o objects/map.o
objects/mark.o objects/match.o objects/mbyte.o objects/memline.o
objects/menu.o objects/misc1.o objects/misc2.o objects/mouse.o
objects/move.o objects/normal.o objects/ops.o objects/option.o
objects/optionstr.o objects/os_unix.o objects/pathdef.o
objects/popupmenu.o objects/popupwin.o objects/profiler.o
objects/pty.o objects/quickfix.o objects/regexp.o objects/register.o
objects/screen.o objects/scriptfile.o objects/search.o
objects/session.o objects/sha256.o objects/sign.o objects/sound.o
objects/spell.o objects/spellfile.o objects/spellsuggest.o
objects/syntax.o objects/tag.o objects/term.o objects/terminal.o
objects/testing.o objects/textformat.o objects/textobject.o
objects/textprop.o objects/time.o objects/typval.o objects/ui.o
objects/undo.o objects/usercmd.o objects/userfunc.o objects/version.o
objects/vim9compile.o objects/vim9execute.o objects/vim9script.o
objects/vim9type.o objects/viminfo.o objects/window.o
objects/bufwrite.o objects/xdiffi.o objects/xemit.o
objects/xprepare.o objects/xutils.o objects/xhistogram.o
objects/xpatience.o objects/charset.o objects/json.o objects/main.o
objects/memfile.o objects/message.o -lSM -lICE -lXpm -lXt -lX11
-lXdmcp -lSM -lICE -lm -ltinfo -lelf -lselinux -lgpm -ldl
/usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld:
objects/ex_docmd.o: in function `eval_vars':
ex_docmd.c:(.text+0x5e93): undefined reference to `in_vim9script'
collect2: error: ld returned 1 exit status
link.sh: Linking failed
make: *** [Makefile:2134: vi] Error 1
exit status 2
Sun 27 Dec 17:02:07 CET 2020
linux-2iyu:~/.build/vim/vim-hg/src/shadow-tiny #



Best regards,
Tony.
Reply all
Reply to author
Forward
0 new messages