Mercurial > vim
diff src/tag.c @ 26268:3aa48d4e3dc8 v8.2.3665
patch 8.2.3665: cannot use a lambda for 'tagfunc'
Commit: https://github.com/vim/vim/commit/19916a8c8920b6a1fd737ffa6d4e363fc7a96319
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Wed Nov 24 16:32:55 2021 +0000
patch 8.2.3665: cannot use a lambda for 'tagfunc'
Problem: Cannot use a lambda for 'tagfunc'.
Solution: Use 'tagfunc' like 'opfunc'. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/9204)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 24 Nov 2021 17:45:03 +0100 |
parents | 336e2d9924e6 |
children | 8aba638e91eb |
line wrap: on
line diff
--- a/src/tag.c +++ b/src/tag.c @@ -103,12 +103,61 @@ static taggy_T ptag_entry = {NULL, {{0, #ifdef FEAT_EVAL static int tfu_in_use = FALSE; // disallow recursive call of tagfunc +static callback_T tfu_cb; // 'tagfunc' callback function #endif // Used instead of NUL to separate tag fields in the growarrays. #define TAG_SEP 0x02 /* + * Reads the 'tagfunc' option value and convert that to a callback value. + * Invoked when the 'tagfunc' option is set. The option value can be a name of + * a function (string), or function(<name>) or funcref(<name>) or a lambda. + */ + int +set_tagfunc_option() +{ +#ifdef FEAT_EVAL + free_callback(&tfu_cb); + free_callback(&curbuf->b_tfu_cb); + + if (*curbuf->b_p_tfu == NUL) + return OK; + + if (option_set_callback_func(curbuf->b_p_tfu, &tfu_cb) == FAIL) + return FAIL; + + copy_callback(&curbuf->b_tfu_cb, &tfu_cb); +#endif + + return OK; +} + +# if defined(EXITFREE) || defined(PROTO) + void +free_tagfunc_option(void) +{ +# ifdef FEAT_EVAL + free_callback(&tfu_cb); +# endif +} +# endif + +/* + * Copy the global 'tagfunc' callback function to the buffer-local 'tagfunc' + * callback for 'buf'. + */ + void +buf_set_tfu_callback(buf_T *buf UNUSED) +{ +#ifdef FEAT_EVAL + free_callback(&buf->b_tfu_cb); + if (tfu_cb.cb_name != NULL && *tfu_cb.cb_name != NUL) + copy_callback(&buf->b_tfu_cb, &tfu_cb); +#endif +} + +/* * Jump to tag; handling of tag commands and tag stack * * *tag != NUL: ":tag {tag}", jump to new tag, add to tag stack @@ -1341,7 +1390,7 @@ find_tagfunc_tags( flags & TAG_REGEXP ? "r": ""); save_pos = curwin->w_cursor; - result = call_vim_function(curbuf->b_p_tfu, 3, args, &rettv); + result = call_callback(&curbuf->b_tfu_cb, 0, &rettv, 3, args); curwin->w_cursor = save_pos; // restore the cursor position --d->dv_refcount;