patch 9.1.0811: :find expansion does not consider 'findexpr'
Problem: :find expansion does not consider 'findexpr'
Solution: Support expanding :find command argument using 'findexpr'
(Yegappan Lakshmanan)
closes: #15929
Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/testdir/test_findfile.vim b/src/testdir/test_findfile.vim
index f8be713..3a1066b 100644
--- a/src/testdir/test_findfile.vim
+++ b/src/testdir/test_findfile.vim
@@ -294,7 +294,6 @@
" basic tests
func FindExpr1()
let fnames = ['Xfindexpr1.c', 'Xfindexpr2.c', 'Xfindexpr3.c']
- "return fnames->copy()->filter('v:val =~? v:fname')->join("\n")
return fnames->copy()->filter('v:val =~? v:fname')
endfunc
@@ -353,8 +352,8 @@
set findexpr=FindExpr2()
call assert_fails('find Xfindexpr1.c', 'find error')
- " Try using a null string as the expression
- set findexpr=test_null_string()
+ " Try using a null List as the expression
+ set findexpr=test_null_list()
call assert_fails('find Xfindexpr1.c', 'E345: Can''t find file "Xfindexpr1.c" in path')
" Try to create a new window from the find expression
@@ -373,6 +372,10 @@
set findexpr=FindExpr4()
call assert_fails('find Xfindexpr1.c', 'E565: Not allowed to change text or change window')
+ " Expression returning a string
+ set findexpr='abc'
+ call assert_fails('find Xfindexpr1.c', 'E1514: findexpr did not return a List type')
+
set findexpr&
delfunc! FindExpr1
delfunc! FindExpr2
@@ -449,4 +452,31 @@
delfunc s:FindExprScript
endfunc
+" Test for expanding the argument to the :find command using 'findexpr'
+func Test_findexpr_expand_arg()
+ func FindExpr1()
+ let fnames = ['Xfindexpr1.c', 'Xfindexpr2.c', 'Xfindexpr3.c']
+ return fnames->copy()->filter('v:val =~? v:fname')
+ endfunc
+ set findexpr=FindExpr1()
+
+ call feedkeys(":find \<Tab>\<C-B>\"\<CR>", "xt")
+ call assert_equal('"find Xfindexpr1.c', @:)
+
+ call feedkeys(":find Xfind\<Tab>\<Tab>\<C-B>\"\<CR>", "xt")
+ call assert_equal('"find Xfindexpr2.c', @:)
+
+ call feedkeys(":find *3*\<Tab>\<C-B>\"\<CR>", "xt")
+ call assert_equal('"find Xfindexpr3.c', @:)
+
+ call feedkeys(":find Xfind\<C-A>\<C-B>\"\<CR>", "xt")
+ call assert_equal('"find Xfindexpr1.c Xfindexpr2.c Xfindexpr3.c', @:)
+
+ call feedkeys(":find abc\<Tab>\<C-B>\"\<CR>", "xt")
+ call assert_equal('"find abc', @:)
+
+ set findexpr&
+ delfunc! FindExpr1
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab