annotate src/testdir/test_pyx2.vim @ 33399:95db67c7b754 v9.0.1958

patch 9.0.1958: cannot complete option values Commit: https://github.com/vim/vim/commit/900894b09a95398dfc75599e9f0aa2ea25723384 Author: Yee Cheng Chin <ychin.git@gmail.com> Date: Fri Sep 29 20:42:32 2023 +0200 patch 9.0.1958: cannot complete option values Problem: cannot complete option values Solution: Add completion functions for several options Add cmdline tab-completion for setting string options Add tab-completion for setting string options on the cmdline using `:set=` (along with `:set+=` and `:set-=`). The existing tab completion for setting options currently only works when nothing is typed yet, and it only fills in with the existing value, e.g. when the user does `:set diffopt=<Tab>` it will be completed to `set diffopt=internal,filler,closeoff` and nothing else. This isn't too useful as a user usually wants auto-complete to suggest all the possible values, such as 'iblank', or 'algorithm:patience'. For set= and set+=, this adds a new optional callback function for each option that can be invoked when doing completion. This allows for each option to have control over how completion works. For example, in 'diffopt', it will suggest the default enumeration, but if `algorithm:` is selected, it will further suggest different algorithm types like 'meyers' and 'patience'. When using set=, the existing option value will be filled in as the first choice to preserve the existing behavior. When using set+= this won't happen as it doesn't make sense. For flag list options (e.g. 'mouse' and 'guioptions'), completion will take into account existing typed values (and in the case of set+=, the existing option value) to make sure it doesn't suggest duplicates. For set-=, there is a new `ExpandSettingSubtract` function which will handle flag list and comma-separated options smartly, by only suggesting values that currently exist in the option. Note that Vim has some existing code that adds special handling for 'filetype', 'syntax', and misc dir options like 'backupdir'. This change preserves them as they already work, instead of converting to the new callback API for each option. closes: #13182 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
author Christian Brabandt <cb@256bit.org>
date Fri, 29 Sep 2023 20:45:04 +0200
parents 5f9c2c7d3d73
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10722
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Test for pyx* commands and functions with Python 2.
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 set pyx=2
17089
8e9e9124c7a2 patch 8.1.1544: some balloon tests don't run when they can
Bram Moolenaar <Bram@vim.org>
parents: 17049
diff changeset
4 source check.vim
8e9e9124c7a2 patch 8.1.1544: some balloon tests don't run when they can
Bram Moolenaar <Bram@vim.org>
parents: 17049
diff changeset
5 CheckFeature python
10722
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 let s:py2pattern = '^2\.[0-7]\.\d\+'
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 let s:py3pattern = '^3\.\d\+\.\d\+'
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 func Test_has_pythonx()
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 call assert_true(has('pythonx'))
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 endfunc
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 func Test_pyx()
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 redir => var
20045
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 17976
diff changeset
18 pyx << trim EOF
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 17976
diff changeset
19 import sys
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 17976
diff changeset
20 print(sys.version)
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 17976
diff changeset
21 EOF
10722
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 redir END
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 call assert_match(s:py2pattern, split(var)[0])
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 endfunc
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 func Test_pyxdo()
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 pyx import sys
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 enew
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 pyxdo return sys.version.split("\n")[0]
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 call assert_match(s:py2pattern, split(getline('.'))[0])
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 endfunc
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 func Test_pyxeval()
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 pyx import sys
17976
6d11a0d5751d patch 8.1.1984: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
37 call assert_match(s:py2pattern, split('sys.version'->pyxeval())[0])
10722
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 endfunc
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 func Test_pyxfile()
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 " No special comments nor shebangs
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 redir => var
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 pyxfile pyxfile/pyx.py
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 redir END
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 call assert_match(s:py2pattern, split(var)[0])
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 " Python 2 special comment
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 redir => var
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 pyxfile pyxfile/py2_magic.py
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 redir END
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 call assert_match(s:py2pattern, split(var)[0])
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 " Python 2 shebang
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 redir => var
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56 pyxfile pyxfile/py2_shebang.py
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 redir END
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58 call assert_match(s:py2pattern, split(var)[0])
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60 if has('python3')
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61 " Python 3 special comment
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 redir => var
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63 pyxfile pyxfile/py3_magic.py
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 redir END
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
65 call assert_match(s:py3pattern, split(var)[0])
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67 " Python 3 shebang
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68 redir => var
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69 pyxfile pyxfile/py3_shebang.py
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70 redir END
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
71 call assert_match(s:py3pattern, split(var)[0])
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72 endif
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73 endfunc
16688
e791f29affae patch 8.1.1346: error for Python exception does not show useful info
Bram Moolenaar <Bram@vim.org>
parents: 10722
diff changeset
74
e791f29affae patch 8.1.1346: error for Python exception does not show useful info
Bram Moolenaar <Bram@vim.org>
parents: 10722
diff changeset
75 func Test_Catch_Exception_Message()
e791f29affae patch 8.1.1346: error for Python exception does not show useful info
Bram Moolenaar <Bram@vim.org>
parents: 10722
diff changeset
76 try
e791f29affae patch 8.1.1346: error for Python exception does not show useful info
Bram Moolenaar <Bram@vim.org>
parents: 10722
diff changeset
77 pyx raise RuntimeError( 'TEST' )
e791f29affae patch 8.1.1346: error for Python exception does not show useful info
Bram Moolenaar <Bram@vim.org>
parents: 10722
diff changeset
78 catch /.*/
e791f29affae patch 8.1.1346: error for Python exception does not show useful info
Bram Moolenaar <Bram@vim.org>
parents: 10722
diff changeset
79 call assert_match( '^Vim(.*):RuntimeError: TEST$', v:exception )
e791f29affae patch 8.1.1346: error for Python exception does not show useful info
Bram Moolenaar <Bram@vim.org>
parents: 10722
diff changeset
80 endtry
e791f29affae patch 8.1.1346: error for Python exception does not show useful info
Bram Moolenaar <Bram@vim.org>
parents: 10722
diff changeset
81 endfunc
20045
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 17976
diff changeset
82
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 17976
diff changeset
83 " Test for various heredoc syntaxes
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 17976
diff changeset
84 func Test_pyx2_heredoc()
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 17976
diff changeset
85 pyx << END
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 17976
diff changeset
86 result='A'
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 17976
diff changeset
87 END
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 17976
diff changeset
88 pyx <<
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 17976
diff changeset
89 result+='B'
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 17976
diff changeset
90 .
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 17976
diff changeset
91 pyx << trim END
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 17976
diff changeset
92 result+='C'
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 17976
diff changeset
93 END
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 17976
diff changeset
94 pyx << trim
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 17976
diff changeset
95 result+='D'
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 17976
diff changeset
96 .
20233
5f9c2c7d3d73 patch 8.2.0672: heredoc in scripts does not accept lower case marker
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
97 pyx << trim eof
5f9c2c7d3d73 patch 8.2.0672: heredoc in scripts does not accept lower case marker
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
98 result+='E'
5f9c2c7d3d73 patch 8.2.0672: heredoc in scripts does not accept lower case marker
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
99 eof
5f9c2c7d3d73 patch 8.2.0672: heredoc in scripts does not accept lower case marker
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
100 call assert_equal('ABCDE', pyxeval('result'))
20045
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 17976
diff changeset
101 endfunc
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 17976
diff changeset
102
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 17976
diff changeset
103 " vim: shiftwidth=2 sts=2 expandtab