comparison runtime/doc/tagsrch.txt @ 16447:54ffc82f38a8 v8.1.1228

patch 8.1.1228: not possible to process tags with a function commit https://github.com/vim/vim/commit/45e18cbdc40afd8144d20dcc07ad2d981636f4c9 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Apr 28 18:05:35 2019 +0200 patch 8.1.1228: not possible to process tags with a function Problem: Not possible to process tags with a function. Solution: Add tagfunc() (Christian Brabandt, Andy Massimino, closes https://github.com/vim/vim/issues/4010)
author Bram Moolenaar <Bram@vim.org>
date Sun, 28 Apr 2019 18:15:07 +0200
parents 4d7ee5609652
children 0e473e9e70c2
comparison
equal deleted inserted replaced
16446:cee0719a1b4b 16447:54ffc82f38a8
1 *tagsrch.txt* For Vim version 8.1. Last change: 2019 Mar 30 1 *tagsrch.txt* For Vim version 8.1. Last change: 2019 Apr 28
2 2
3 3
4 VIM REFERENCE MANUAL by Bram Moolenaar 4 VIM REFERENCE MANUAL by Bram Moolenaar
5 5
6 6
12 2. Tag stack |tag-stack| 12 2. Tag stack |tag-stack|
13 3. Tag match list |tag-matchlist| 13 3. Tag match list |tag-matchlist|
14 4. Tags details |tag-details| 14 4. Tags details |tag-details|
15 5. Tags file format |tags-file-format| 15 5. Tags file format |tags-file-format|
16 6. Include file searches |include-search| 16 6. Include file searches |include-search|
17 7. Using 'tagfunc' |tag-function|
17 18
18 ============================================================================== 19 ==============================================================================
19 1. Jump to a tag *tag-commands* 20 1. Jump to a tag *tag-commands*
20 21
21 *tag* *tags* 22 *tag* *tags*
869 next command can be appended with '|'. Example: > 870 next command can be appended with '|'. Example: >
870 :isearch /string/ | echo "the last one" 871 :isearch /string/ | echo "the last one"
871 < For a ":djump", ":dsplit", ":dlist" and ":dsearch" command the pattern 872 < For a ":djump", ":dsplit", ":dlist" and ":dsearch" command the pattern
872 is used as a literal string, not as a search pattern. 873 is used as a literal string, not as a search pattern.
873 874
875 ==============================================================================
876 7. Using 'tagfunc' *tag-function*
877
878 It is possible to provide Vim with a function which will generate a list of
879 tags used for commands like |:tag|, |:tselect| and Normal mode tag commands
880 like |CTRL-]|.
881
882 The function used for generating the taglist is specified by setting the
883 'tagfunc' option. The function will be called with three arguments:
884 a:pattern The tag identifier used during the tag search.
885 a:flags List of flags to control the function behavior.
886 a:info Dict containing the following entries:
887 buf_ffname Full filename which can be used for priority.
888 user_data Custom data String, if stored in the tag
889 stack previously by tagfunc.
890
891 Currently two flags may be passed to the tag function:
892 'c' The function was invoked by a normal command being processed
893 (mnemonic: the tag function may use the context around the
894 cursor to perform a better job of generating the tag list.)
895 'i' In Insert mode, the user was completing a tag (with
896 |i_CTRL-X_CTRL-]|).
897
898 Note that when 'tagfunc' is set, the priority of the tags described in
899 |tag-priority| does not apply. Instead, the priority is exactly as the
900 ordering of the elements in the list returned by the function.
901 *E987*
902 The function should return a List of Dict entries. Each Dict must at least
903 include the following entries and each value must be a string:
904 name Name of the tag.
905 filename Name of the file where the tag is defined. It is
906 either relative to the current directory or a full path.
907 cmd Ex command used to locate the tag in the file. This
908 can be either an Ex search pattern or a line number.
909 Note that the format is similar to that of |taglist()|, which makes it possible
910 to use its output to generate the result.
911 The following fields are optional:
912 kind Type of the tag.
913 user_data String of custom data stored in the tag stack which
914 can be used to disambiguate tags between operations.
915
916 If the function returns |v:null| instead of a List, a standard tag lookup will
917 be performed instead.
918
919 It is not allowed to change the tagstack from inside 'tagfunc'. *E986*
920
921 The following is a hypothetical example of a function used for 'tagfunc'. It
922 uses the output of |taglist()| to generate the result: a list of tags in the
923 inverse order of file names.
924 >
925 function! TagFunc(pattern, flags, info)
926 function! CompareFilenames(item1, item2)
927 let f1 = a:item1['filename']
928 let f2 = a:item2['filename']
929 return f1 >=# f2 ?
930 \ -1 : f1 <=# f2 ? 1 : 0
931 endfunction
932
933 let result = taglist(a:pattern)
934 call sort(result, "CompareFilenames")
935
936 return result
937 endfunc
938 set tagfunc=TagFunc
939 <
940
874 vim:tw=78:ts=8:noet:ft=help:norl: 941 vim:tw=78:ts=8:noet:ft=help:norl: