From: Lech Lorens Date: Tue, 3 Aug 2010 20:37:50 +0000 (+0200) Subject: feat/tagfunc: if 'tfu' is called during completion, it gets 'i' flag. X-Git-Url: https://repo.or.cz/w/vim_extended.git/commitdiff_plain/82d5c32afd20b4078fa7e83cea3d346a9e0448e7 feat/tagfunc: if 'tfu' is called during completion, it gets 'i' flag. --- diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index d4444a55..b69232aa 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -6702,10 +6702,12 @@ A jump table for the options with a short description can be found at |Q_op|. This option specifies a function to be used to perform tag searches. The function should take two parameters, the first of which is the pattern to be searched, while the second is a set of flags which may - be used by the function to decide on its behaviour. Currently the only - flag that may appear here is 'c', which indicates that the context - around the cursor position can be used to generate more accurate - results. + be used by the function to decide on its behaviour. Currently the + following flags may appear: + 'c' - indicates that the context around the cursor position + can be used to generate more accurate results, + 'i' - the function is being called during insert-mode + completion. See |tag-function| for an explanation of what the function should return and an example of such a function. diff --git a/src/tag.c b/src/tag.c index d0308a04..75c228d1 100644 --- a/src/tag.c +++ b/src/tag.c @@ -1252,10 +1252,15 @@ struct match_found * Return OK if at least 1 tag has been successfully found, FAIL otherwise. * pat - used as the pattern supplied to the user-defined function, * ga - the tags will be placed here, - * match_count - here the number of tags found will be placed. + * match_count - here the number of tags found will be placed, + * flags - used to compose a string containing flags passed to the function. */ static int -find_tfu_tags(char_u *pat, garray_T *ga, int *match_count) +find_tfu_tags(pat, ga, match_count, flags) + char_u *pat; + garray_T *ga; + int *match_count; + int flags; { pos_T pos; list_T *taglist; @@ -1263,13 +1268,19 @@ find_tfu_tags(char_u *pat, garray_T *ga, int *match_count) int ntags = 0; int result = FAIL; char_u *args[2]; - - args[0] = pat; - args[1] = (char_u *) (g_tag_at_cursor? "c": ""); + char_u flagString[3]; if (*curbuf->b_p_tfu == NUL) goto done; + args[0] = pat; + args[1] = flagString; + + vim_snprintf((char *)flagString, sizeof(flagString), + "%s%s", + g_tag_at_cursor ? "c": "", + flags & TAG_INS_COMP ? "i": ""); + pos = curwin->w_cursor; taglist = call_func_retlist(curbuf->b_p_tfu, 2, args, FALSE); curwin->w_cursor = pos; /* restore the cursor position */ @@ -1637,7 +1648,7 @@ find_tags(pat, num_matches, matchesp, flags, mincount, buf_ffname) if (*curbuf->b_p_tfu != NUL && use_tfu && tfu_call_level == 0) { ++tfu_call_level; - retval = find_tfu_tags(pat, &ga_match[0], &match_count); + retval = find_tfu_tags(pat, &ga_match[0], &match_count, flags); --tfu_call_level; goto findtag_end; }