Mercurial > vim
changeset 27362:2ca6dd1f62af v8.2.4209
patch 8.2.4209: partial in 'opfunc' cannot use an imported function
Commit: https://github.com/vim/vim/commit/3e93a2b075e99a2b3ced85227a6373be233712ff
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Jan 24 21:28:01 2022 +0000
patch 8.2.4209: partial in 'opfunc' cannot use an imported function
Problem: partial in 'opfunc' cannot use an imported function.
Solution: Also expand the function name in a partial. (closes https://github.com/vim/vim/issues/9614)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 24 Jan 2022 22:30:04 +0100 |
parents | 73508f35e8ab |
children | a2e082438ef9 |
files | src/evalvars.c src/testdir/test_vim9_import.vim src/version.c |
diffstat | 3 files changed, 60 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/evalvars.c +++ b/src/evalvars.c @@ -4680,27 +4680,44 @@ copy_callback(callback_T *dest, callback void expand_autload_callback(callback_T *cb) { + char_u *name; char_u *p; imported_T *import; - if (!in_vim9script() || cb->cb_name == NULL || !cb->cb_free_name) + if (!in_vim9script() || cb->cb_name == NULL + || (!cb->cb_free_name + && (cb->cb_partial == NULL || cb->cb_partial->pt_name == NULL))) return; - p = vim_strchr(cb->cb_name, '.'); + if (cb->cb_partial != NULL) + name = cb->cb_partial->pt_name; + else + name = cb->cb_name; + p = vim_strchr(name, '.'); if (p == NULL) return; - import = find_imported(cb->cb_name, p - cb->cb_name, FALSE, NULL); + import = find_imported(name, p - name, FALSE, NULL); if (import != NULL && SCRIPT_ID_VALID(import->imp_sid)) { scriptitem_T *si = SCRIPT_ITEM(import->imp_sid); if (si->sn_autoload_prefix != NULL) { - char_u *name = concat_str(si->sn_autoload_prefix, p + 1); - - if (name != NULL) + char_u *newname = concat_str(si->sn_autoload_prefix, p + 1); + + if (newname != NULL) { - vim_free(cb->cb_name); - cb->cb_name = name; + if (cb->cb_partial != NULL) + { + if (cb->cb_name == cb->cb_partial->pt_name) + cb->cb_name = newname; + vim_free(cb->cb_partial->pt_name); + cb->cb_partial->pt_name = newname; + } + else + { + vim_free(cb->cb_name); + cb->cb_name = newname; + } } } }
--- a/src/testdir/test_vim9_import.vim +++ b/src/testdir/test_vim9_import.vim @@ -673,6 +673,39 @@ def Test_use_autoload_import_in_insert_c &rtp = save_rtp enddef +def Test_use_autoload_import_partial_in_opfunc() + mkdir('Xdir/autoload', 'p') + var save_rtp = &rtp + exe 'set rtp^=' .. getcwd() .. '/Xdir' + + var lines =<< trim END + vim9script + export def Opfunc(..._) + g:opfunc_called = 'yes' + enddef + END + writefile(lines, 'Xdir/autoload/opfunc.vim') + + new + lines =<< trim END + vim9script + import autoload 'opfunc.vim' + nnoremap <expr> <F3> TheFunc() + def TheFunc(): string + &operatorfunc = function('opfunc.Opfunc', [0]) + return 'g@' + enddef + feedkeys("\<F3>l", 'xt') + assert_equal('yes', g:opfunc_called) + END + CheckScriptSuccess(lines) + + set opfunc= + bwipe! + delete('Xdir', 'rf') + &rtp = save_rtp +enddef + def Test_use_autoload_import_in_fold_expression() mkdir('Xdir/autoload', 'p') var save_rtp = &rtp