Patch 8.2.4751

6 views
Skip to first unread message

Bram Moolenaar

unread,
Apr 15, 2022, 8:20:27 AM4/15/22
to vim...@googlegroups.com

Patch 8.2.4751 (after 8.2.4748)
Problem: Mapping <SID>name.Func does not work for script in autoload
directory.
Solution: Use the # form for a script in the autoload directory.
(closes #10186)
Files: src/term.c, src/testdir/test_vim9_import.vim


*** ../vim-8.2.4750/src/term.c 2022-04-14 12:58:19.604895030 +0100
--- src/term.c 2022-04-14 21:31:43.251573747 +0100
***************
*** 5963,5986 ****
int do_special; // recognize <> key codes
int do_key_code; // recognize raw key codes
char_u *result; // buffer for resulting string

do_backslash = (vim_strchr(p_cpo, CPO_BSLASH) == NULL);
do_special = (vim_strchr(p_cpo, CPO_SPECI) == NULL)
|| (flags & REPTERM_SPECIAL);
do_key_code = (vim_strchr(p_cpo, CPO_KEYCODE) == NULL);

/*
* Allocate space for the translation. Worst case a single character is
* replaced by 6 bytes (shifted special key), plus a NUL at the end.
*/
! result = alloc(STRLEN(from) * 6 + 1);
! if (result == NULL) // out of memory
{
*bufp = NULL;
return from;
}
!
! src = from;

/*
* Check for #n at start only: function key n
--- 5963,5988 ----
int do_special; // recognize <> key codes
int do_key_code; // recognize raw key codes
char_u *result; // buffer for resulting string
+ garray_T ga;

do_backslash = (vim_strchr(p_cpo, CPO_BSLASH) == NULL);
do_special = (vim_strchr(p_cpo, CPO_SPECI) == NULL)
|| (flags & REPTERM_SPECIAL);
do_key_code = (vim_strchr(p_cpo, CPO_KEYCODE) == NULL);
+ src = from;

/*
* Allocate space for the translation. Worst case a single character is
* replaced by 6 bytes (shifted special key), plus a NUL at the end.
+ * In the rare case more might be needed ga_grow() must be called again.
*/
! ga_init2(&ga, 1L, 100);
! if (ga_grow(&ga, STRLEN(src) * 6 + 1) == FAIL) // out of memory
{
*bufp = NULL;
return from;
}
! result = ga.ga_data;

/*
* Check for #n at start only: function key n
***************
*** 6033,6040 ****

if (imp != NULL)
{
! sid = imp->imp_sid;
src = dot + 1;
}
}

--- 6035,6062 ----

if (imp != NULL)
{
! scriptitem_T *si = SCRIPT_ITEM(imp->imp_sid);
! size_t len;
!
src = dot + 1;
+ if (si->sn_autoload_prefix != NULL)
+ {
+ // Turn "<SID>name.Func"
+ // into "scriptname#Func".
+ len = STRLEN(si->sn_autoload_prefix);
+ if (ga_grow(&ga, STRLEN(src) * 6 + len + 1)
+ == FAIL)
+ {
+ ga_clear(&ga);
+ *bufp = NULL;
+ return from;
+ }
+ result = ga.ga_data;
+ STRCPY(result + dlen, si->sn_autoload_prefix);
+ dlen += len;
+ continue;
+ }
+ sid = imp->imp_sid;
}
}

***************
*** 6048,6054 ****
}
}
#endif
-
slen = trans_special(&src, result + dlen, FSK_KEYCODE
| ((flags & REPTERM_NO_SIMPLIFY) ? 0 : FSK_SIMPLIFY),
did_simplify);
--- 6070,6075 ----
*** ../vim-8.2.4750/src/testdir/test_vim9_import.vim 2022-04-14 12:58:19.604895030 +0100
--- src/testdir/test_vim9_import.vim 2022-04-14 21:29:14.647771265 +0100
***************
*** 669,698 ****
nunmap <F4>
enddef

! def Test_use_autoload_import_in_mapping()
var lines =<< trim END
vim9script
export def Func()
g:result = 42
enddef
END
! writefile(lines, 'XautoloadExport.vim')
lines =<< trim END
vim9script
! import autoload './XautoloadExport.vim' as some
nnoremap <F3> :call <SID>some.Func()<CR>
END
writefile(lines, 'Xmapscript.vim')

source Xmapscript.vim
! assert_match('\d\+ A: .*XautoloadExport.vim', execute('scriptnames')->split("\n")[-1])
feedkeys("\<F3>", "xt")
assert_equal(42, g:result)

unlet g:result
! delete('XautoloadExport.vim')
delete('Xmapscript.vim')
nunmap <F3>
enddef

def Test_use_import_in_command_completion()
--- 669,729 ----
nunmap <F4>
enddef

! def Test_use_relative_autoload_import_in_mapping()
var lines =<< trim END
vim9script
export def Func()
g:result = 42
enddef
END
! writefile(lines, 'XrelautoloadExport.vim')
lines =<< trim END
vim9script
! import autoload './XrelautoloadExport.vim' as some
nnoremap <F3> :call <SID>some.Func()<CR>
END
writefile(lines, 'Xmapscript.vim')

source Xmapscript.vim
! assert_match('\d\+ A: .*XrelautoloadExport.vim', execute('scriptnames')->split("\n")[-1])
feedkeys("\<F3>", "xt")
assert_equal(42, g:result)

unlet g:result
! delete('XrelautoloadExport.vim')
! delete('Xmapscript.vim')
! nunmap <F3>
! enddef
!
! def Test_use_autoload_import_in_mapping()
! var lines =<< trim END
! vim9script
! export def Func()
! g:result = 49
! enddef
! END
! mkdir('Xdir/autoload', 'p')
! writefile(lines, 'Xdir/autoload/XautoloadExport.vim')
! var save_rtp = &rtp
! exe 'set rtp^=' .. getcwd() .. '/Xdir'
!
! lines =<< trim END
! vim9script
! import autoload 'XautoloadExport.vim' as some
! nnoremap <F3> :call <SID>some.Func()<CR>
! END
! writefile(lines, 'Xmapscript.vim')
!
! source Xmapscript.vim
! assert_match('\d\+ A: .*autoload/XautoloadExport.vim', execute('scriptnames')->split("\n")[-1])
! feedkeys("\<F3>", "xt")
! assert_equal(49, g:result)
!
! unlet g:result
delete('Xmapscript.vim')
nunmap <F3>
+ delete('Xdir', 'rf')
+ &rtp = save_rtp
enddef

def Test_use_import_in_command_completion()
*** ../vim-8.2.4750/src/version.c 2022-04-14 20:43:52.642894547 +0100
--- src/version.c 2022-04-14 21:35:15.763284028 +0100
***************
*** 748,749 ****
--- 748,751 ----
{ /* Add new patch number below this line */
+ /**/
+ 4751,
/**/

--
While it's true that many normal people whould prefer not to _date_ an
engineer, most normal people harbor an intense desire to _mate_ with them,
thus producing engineerlike children who will have high-paying jobs long
before losing their virginity.
(Scott Adams - The Dilbert principle)

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages