Mercurial > vim
comparison src/testdir/test_edit.vim @ 25974:416237f1de22 v8.2.3520
patch 8.2.3520: cannot define a function for thesaurus completion
Commit: https://github.com/vim/vim/commit/160e994d768d03a3c826b58115cde94df8fce607
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Sat Oct 16 15:41:29 2021 +0100
patch 8.2.3520: cannot define a function for thesaurus completion
Problem: Cannot define a function for thesaurus completion.
Solution: Add 'thesaurusfunc'. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/8987,
closes 8950)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 16 Oct 2021 16:45:04 +0200 |
parents | fc39d7352cb6 |
children | ac330e2fecc4 |
comparison
equal
deleted
inserted
replaced
25973:3b34837f4538 | 25974:416237f1de22 |
---|---|
886 let v:testing = 0 | 886 let v:testing = 0 |
887 endtry | 887 endtry |
888 call assert_equal(['mad'], getline(1, '$')) | 888 call assert_equal(['mad'], getline(1, '$')) |
889 call delete('Xthesaurus') | 889 call delete('Xthesaurus') |
890 bw! | 890 bw! |
891 endfunc | |
892 | |
893 " Test 'thesaurusfunc' | |
894 func MyThesaurus(findstart, base) | |
895 let mythesaurus = [ | |
896 \ #{word: "happy", | |
897 \ synonyms: "cheerful,blissful,flying high,looking good,peppy"}, | |
898 \ #{word: "kind", | |
899 \ synonyms: "amiable,bleeding-heart,heart in right place"}] | |
900 if a:findstart | |
901 " locate the start of the word | |
902 let line = getline('.') | |
903 let start = col('.') - 1 | |
904 while start > 0 && line[start - 1] =~ '\a' | |
905 let start -= 1 | |
906 endwhile | |
907 return start | |
908 else | |
909 " find strings matching with "a:base" | |
910 let res = [] | |
911 for w in mythesaurus | |
912 if w.word =~ '^' . a:base | |
913 call add(res, w.word) | |
914 call extend(res, split(w.synonyms, ",")) | |
915 endif | |
916 endfor | |
917 return res | |
918 endif | |
919 endfunc | |
920 | |
921 func Test_thesaurus_func() | |
922 new | |
923 set thesaurus= | |
924 set thesaurusfunc=MyThesaurus | |
925 call setline(1, "an ki") | |
926 call cursor(1, 1) | |
927 call feedkeys("A\<c-x>\<c-t>\<c-n>\<cr>\<esc>", 'tnix') | |
928 call assert_equal(['an amiable', ''], getline(1, '$')) | |
929 set thesaurusfunc=NonExistingFunc | |
930 call assert_fails("normal $a\<C-X>\<C-T>", 'E117:') | |
931 set thesaurusfunc& | |
932 %bw! | |
891 endfunc | 933 endfunc |
892 | 934 |
893 func Test_edit_CTRL_U() | 935 func Test_edit_CTRL_U() |
894 " Test 'completefunc' | 936 " Test 'completefunc' |
895 new | 937 new |