Compare commits

...

15 Commits

Author SHA1 Message Date
Bram Moolenaar
c7b831ca15 patch 8.0.0254: error message of assert functions is sometimes incomplete
Problem:    When using an assert function one can either specify a message or
            get a message about what failed, not both.
Solution:   Concatenate the error with the message.
2017-01-28 18:08:12 +01:00
Bram Moolenaar
36ae89c550 patch 8.0.0253: error when loading session if winminheight is 2
Problem:    When creating a session when winminheight is 2 or larger and
            loading that session gives an error.
Solution:   Also set winminheight before setting winheight to 1. (Rafael
            Bodill, neovim #5717)
2017-01-28 17:11:14 +01:00
Bram Moolenaar
4019cf90b8 patch 8.0.0252: not properly recognizing word characters between 128 and 255
Problem:    Characters below 256 that are not one byte are not always
            recognized as word characters.
Solution:   Make vim_iswordc() and vim_iswordp() work the same way. Add a test
            for this. (Ozaki Kiichi)
2017-01-28 16:39:34 +01:00
Bram Moolenaar
f42dd3c390 patch 8.0.0251: not easy to select Python 2 or 3
Problem:    It is not so easy to write a script that works with both Python 2
            and Python 3, even when the Python code works with both.
Solution:   Add 'pyxversion', :pyx, etc. (Marc Weber, Ken Takata)
2017-01-28 16:06:38 +01:00
Bram Moolenaar
0c0590d982 patch 8.0.0250: virtcol() does not work well for multi-byte characters
Problem:    When virtcol() gets a column that is not the first byte of a
            multi-byte character the result is unpredictable. (Christian
            Ludwig)
Solution:   Correct the column to the first byte of a multi-byte character.
            Change the utf-8 test to new style.
2017-01-28 13:48:10 +01:00
Bram Moolenaar
4bc2f2e9fd patch 8.0.0249: CI failure when a submit is close to previous one
Problem:    When two submits happen quick after each other, the tests for the
            first one may error out.
Solution:   Use a git depth of 10 instead of 1. (Christian Brabandt)
2017-01-27 22:20:13 +01:00
Bram Moolenaar
45600ce8f2 patch 8.0.0248: vim_strcat() cannot handle overlapping arguments
Problem:    vim_strcat() cannot handle overlapping arguments.
Solution:   Use mch_memmove() instead of strcpy(). (Justin M Keyes,
            closes #1415)
2017-01-27 21:54:07 +01:00
Bram Moolenaar
aed6d0b81a patch 8.0.0247: need to type Ctrl-N twice to select a completion
Problem:    Under some circumstances, one needs to type Ctrl-N or Ctrl-P twice
            to have a menu entry selected. (Lifepillar)
Solution:   call ins_compl_free(). (Christian Brabandt, closes #1411)
2017-01-27 21:48:54 +01:00
Bram Moolenaar
3a118be150 patch 8.0.0246: compiler warnings for int to pointer conversion
Problem:    Compiler warnings for int to pointer conversion.
Solution:   Fix macro for mch_memmove(). (John Marriott)
2017-01-27 21:22:19 +01:00
Bram Moolenaar
16038d50c4 patch 8.0.0245: zh_CN.cp936.po has a conversion error
Problem:    The generated zh_CN.cp936.po message file is not encoded properly.
Solution:   Instead of using zh_CN.po as input, use zh_CN.UTF-8.po.
2017-01-27 20:37:49 +01:00
Bram Moolenaar
d9c60648e5 patch 8.0.0244: making t_BE empty only has an effect before startup
Problem:    When the user sets t_BE empty after startup to disable bracketed
            paste, this has no direct effect.
Solution:   When t_BE is made empty write t_BD.  When t_BE is made non-empty
            write the new value.
2017-01-27 20:03:18 +01:00
Bram Moolenaar
cc5b22b3bf patch 8.0.0243: tolower() does not work if the byte count changes
Problem:    When making a character lower case with tolower() changes the byte
            cound, it is not made lower case.
Solution:   Add strlow_save(). (Dominique Pelle, closes #1406)
2017-01-26 22:51:56 +01:00
Bram Moolenaar
65c836e600 patch 8.0.0242: no tests for user command completion
Problem:    Completion of user defined functions is not covered by tests.
Solution:   Add tests.  Also test various errors of user-defined commands.
            (Dominique Pelle, closes #1413)
2017-01-26 22:07:33 +01:00
Bram Moolenaar
52c0de1de1 patch 8.0.0241: fallback implementation of mch_memmove is unused
Problem:    Vim defines a mch_memmove() function but it doesn't work, thus is
            always unused.
Solution:   Remove the mch_memmove implementation. (suggested by Dominique
            Pelle)
2017-01-26 21:36:34 +01:00
Bram Moolenaar
4f7090b93d patch 8.0.0240: failure with one build on CI
Problem:    The clang build on CI fails with one configuration.
Solution:   Redo a previous patch that was accidentally reverted.
2017-01-26 21:24:02 +01:00
49 changed files with 1270 additions and 216 deletions

1
.gitignore vendored
View File

@@ -81,3 +81,4 @@ src/testdir/viminfo
src/memfile_test
src/json_test
src/message_test
src/kword_test

View File

@@ -25,7 +25,7 @@ env:
sudo: false
git:
depth: 1
depth: 10
# instead of a 2*2*8 matrix (2*os + 2*compiler + 8*env),
# exclude some builds on mac os x and linux
@@ -75,8 +75,10 @@ addons:
- cscope
before_install:
- pip install --user cpp-coveralls
- pip install --user requests[security]
- if [ "$COVERAGE" = "yes" ]; then pip install --user cpp-coveralls; fi
# needed for https support for coveralls
# building cffi only works with gcc, not with clang
- if [ "$COVERAGE" = "yes" ]; then CC=gcc pip install --user pyopenssl ndg-httpsclient pyasn1; fi
# Lua is not installed on Travis OSX
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew install lua; export LUA_PREFIX=/usr/local; fi

View File

@@ -122,6 +122,7 @@ SRC_ALL = \
src/testdir/pythonx/topmodule/submodule/subsubmodule/subsubsubmodule.py \
src/testdir/python_after/*.py \
src/testdir/python_before/*.py \
src/testdir/pyxfile/*.py \
src/testdir/bench*.in \
src/testdir/bench*.vim \
src/testdir/samples/*.txt \

View File

@@ -2239,6 +2239,7 @@ printf({fmt}, {expr1}...) String format text
pumvisible() Number whether popup menu is visible
pyeval({expr}) any evaluate |Python| expression
py3eval({expr}) any evaluate |python3| expression
pyxeval({expr}) any evaluate |python_x| expression
range({expr} [, {max} [, {stride}]])
List items from {expr} to {max}
readfile({fname} [, {binary} [, {max}]])
@@ -6163,6 +6164,14 @@ pyeval({expr}) *pyeval()*
non-string keys result in error.
{only available when compiled with the |+python| feature}
pyxeval({expr}) *pyxeval()*
Evaluate Python expression {expr} and return its result
converted to Vim data structures.
Uses Python 2 or 3, see |python_x| and 'pyxversion'.
See also: |pyeval()|, |py3eval()|
{only available when compiled with the |+python| or the
|+python3| feature}
*E726* *E727*
range({expr} [, {max} [, {stride}]]) *range()*
Returns a |List| with Numbers:
@@ -8402,6 +8411,7 @@ printer Compiled with |:hardcopy| support.
profile Compiled with |:profile| support.
python Compiled with Python 2.x interface. |has-python|
python3 Compiled with Python 3.x interface. |has-python|
pythonx Compiled with |python_x| interface. |has-pythonx|
qnx QNX version of Vim.
quickfix Compiled with |quickfix| support.
reltime Compiled with |reltime()| support.

View File

@@ -16,6 +16,7 @@ The Python Interface to Vim *python* *Python*
8. pyeval(), py3eval() Vim functions |python-pyeval|
9. Dynamic loading |python-dynamic|
10. Python 3 |python3|
11. Python X |python_x|
{Vi does not have any of these commands}
@@ -711,6 +712,7 @@ vim.Function object *python-Function*
To facilitate bi-directional interface, you can use |pyeval()| and |py3eval()|
functions to evaluate Python expressions and pass their values to VimL.
|pyxeval()| is also available.
==============================================================================
9. Dynamic loading *python-dynamic*
@@ -811,5 +813,69 @@ dynamically, these has() calls will try to load them. If only one can be
loaded at a time, just checking if Python 2 or 3 are available will prevent
the other one from being available.
==============================================================================
11. Python X *python_x* *pythonx*
Because most python code can be written so that it works with python 2.6+ and
python 3 the pyx* functions and commands have been writen. They work exactly
the same as the Python 2 and 3 variants, but select the Python version using
the 'pyxversion' setting.
You should set 'pyxversion' in your |.vimrc| to prefer Python 2 or Python 3
for Python commands. If you change this setting at runtime you may risk that
state of plugins (such as initialization) may be lost.
If you want to use a module, you can put it in the {rtp}/pythonx directory.
See |pythonx-directory|.
*:pyx* *:pythonx*
The `:pyx` and `:pythonx` commands work similar to `:python`. A simple check
if the `:pyx` command is working: >
:pyx print("Hello")
To see what version of Python is being used: >
:pyx import sys
:pyx print(sys.version)
<
*:pyxfile* *python_x-special-comments*
The `:pyxfile` command works similar to `:pyfile`. However you can add one of
these comments to force Vim using `:pyfile` or `:py3file`: >
#!/any string/python2 " Shebang. Must be the first line of the file.
#!/any string/python3 " Shebang. Must be the first line of the file.
# requires python 2.x " Maximum lines depend on 'modelines'.
# requires python 3.x " Maximum lines depend on 'modelines'.
Unlike normal modelines, the bottom of the file is not checked.
If none of them are found, the 'pyxversion' setting is used.
*W20* *W21*
If Vim does not support the selected Python version a silent message will be
printed. Use `:messages` to read them.
*:pyxdo*
The `:pyxdo` command works similar to `:pydo`.
*has-pythonx*
You can test if pyx* commands are available with: >
if has('pythonx')
echo 'pyx* commands are available. (Python ' . &pyx . ')'
endif
When compiled with only one of |+python| or |+python3|, the has() returns 1.
When compiled with both |+python| and |+python3|, the test depends on the
'pyxversion' setting. If 'pyxversion' is 0, it tests Python 3 first, and if
it is not available then Python 2. If 'pyxversion' is 2 or 3, it tests only
Python 2 or 3 respectively.
Note that for has('pythonx') to work it may try to dynamically load Python 3
or 2. This may have side effects, especially when Vim can only load one of
the two.
If a user prefers Python 2 and want to fallback to Python 3, he needs to set
'pyxversion' explicitly in his |.vimrc|. E.g.: >
if has('python')
set pyx=2
elseif has('python3')
set pyx=3
endif
==============================================================================
vim:tw=78:ts=8:ft=help:norl:

View File

@@ -1440,6 +1440,10 @@ tag command action ~
|:python| :py[thon] execute Python command
|:pydo| :pyd[o] execute Python command for each line
|:pyfile| :pyf[ile] execute Python script file
|:pyx| :pyx execute |python_x| command
|:pythonx| :pythonx same as :pyx
|:pyxdo| :pyxd[o] execute |python_x| command for each line
|:pyxfile| :pyxf[ile] execute |python_x| script file
|:quit| :q[uit] quit current window (when one window quit Vim)
|:quitall| :quita[ll] quit Vim
|:qall| :qa[ll] quit Vim

View File

@@ -5786,6 +5786,34 @@ A jump table for the options with a short description can be found at |Q_op|.
Specifies the name of the Python 3 shared library. The default is
DYNAMIC_PYTHON3_DLL, which was specified at compile time.
Environment variables are expanded |:set_env|.
This option cannot be set from a |modeline| or in the |sandbox|, for
security reasons.
*'pyxversion'* *'pyx'*
'pyxversion' 'pyx' number (default depends on the build)
global
{not in Vi}
{only available when compiled with the |+python| or
the |+python3| feature}
Specifies the python version used for pyx* functions and commands
|python_x|. The default value is as follows:
Compiled with Default ~
|+python| and |+python3| 0
only |+python| 2
only |+python3| 3
Available values are 0, 2 and 3.
If 'pyxversion' is 0, it is set to 2 or 3 after the first execution of
any python2/3 commands or functions. E.g. `:py` sets to 2, and `:py3`
sets to 3. `:pyx` sets it to 3 if Python 3 is available, otherwise sets
to 2 if Python 2 is available.
See also: |has-pythonx|
If Vim is compiled with only |+python| or |+python3| setting
'pyxversion' has no effect. The pyx* functions and commands are
always the same as the compiled version.
This option cannot be set from a |modeline| or in the |sandbox|, for
security reasons.

View File

@@ -835,6 +835,7 @@ Short explanation of each option: *option-list*
'pumheight' 'ph' maximum height of the popup menu
'pythondll' name of the Python 2 dynamic library
'pythonthreedll' name of the Python 3 dynamic library
'pyxversion' 'pyx' Python version used for pyx* commands
'quoteescape' 'qe' escape characters used in a string
'readonly' 'ro' disallow writing the buffer
'redrawtime' 'rdt' timeout for 'hlsearch' and |:match| highlighting

View File

@@ -923,7 +923,7 @@ if has("folding")
call append("$", "foldmarker\tmarkers used when 'foldmethod' is \"marker\"")
call append("$", "\t(local to window)")
call <SID>OptionL("fmr")
call append("$", "foldnestmax\tmaximum fold depth for when 'foldmethod is \"indent\" or \"syntax\"")
call append("$", "foldnestmax\tmaximum fold depth for when 'foldmethod' is \"indent\" or \"syntax\"")
call append("$", "\t(local to window)")
call <SID>OptionL("fdn")
endif
@@ -1324,6 +1324,10 @@ if exists("&perldll")
call append("$", "perldll\tname of the Perl dynamic library")
call <SID>OptionG("perldll", &perldll)
endif
if has('pythonx')
call append("$", "pyxversion\twhether to use Python 2 or 3")
call append("$", " \tset pyx=" . &wd)
endif
if exists("&pythondll")
call append("$", "pythondll\tname of the Python 2 dynamic library")
call <SID>OptionG("pythondll", &pythondll)

View File

@@ -1584,14 +1584,16 @@ EXTRA_SRC = hangulin.c if_lua.c if_mzsch.c auto/if_perl.c if_perlsfio.c \
# Unittest files
JSON_TEST_SRC = json_test.c
JSON_TEST_TARGET = json_test$(EXEEXT)
KWORD_TEST_SRC = kword_test.c
KWORD_TEST_TARGET = kword_test$(EXEEXT)
MEMFILE_TEST_SRC = memfile_test.c
MEMFILE_TEST_TARGET = memfile_test$(EXEEXT)
MESSAGE_TEST_SRC = message_test.c
MESSAGE_TEST_TARGET = message_test$(EXEEXT)
UNITTEST_SRC = $(JSON_TEST_SRC) $(MEMFILE_TEST_SRC) $(MESSAGE_TEST_SRC)
UNITTEST_TARGETS = $(JSON_TEST_TARGET) $(MEMFILE_TEST_TARGET) $(MESSAGE_TEST_TARGET)
RUN_UNITTESTS = run_json_test run_memfile_test run_message_test
UNITTEST_SRC = $(JSON_TEST_SRC) $(KWORD_TEST_SRC) $(MEMFILE_TEST_SRC) $(MESSAGE_TEST_SRC)
UNITTEST_TARGETS = $(JSON_TEST_TARGET) $(KWORD_TEST_TARGET) $(MEMFILE_TEST_TARGET) $(MESSAGE_TEST_TARGET)
RUN_UNITTESTS = run_json_test run_kword_test run_memfile_test run_message_test
# All sources, also the ones that are not configured
ALL_SRC = $(BASIC_SRC) $(ALL_GUI_SRC) $(UNITTEST_SRC) $(EXTRA_SRC)
@@ -1611,7 +1613,6 @@ OBJ_COMMON = \
objects/arabic.o \
objects/buffer.o \
objects/blowfish.o \
objects/charset.o \
objects/crypt.o \
objects/crypt_zip.o \
objects/dict.o \
@@ -1679,6 +1680,7 @@ OBJ_COMMON = \
# The files included by tests are not in OBJ_COMMON.
OBJ_MAIN = \
objects/charset.o \
objects/json.o \
objects/main.o \
objects/memfile.o \
@@ -1687,13 +1689,23 @@ OBJ_MAIN = \
OBJ = $(OBJ_COMMON) $(OBJ_MAIN)
OBJ_JSON_TEST = \
objects/charset.o \
objects/memfile.o \
objects/message.o \
objects/json_test.o
JSON_TEST_OBJ = $(OBJ_COMMON) $(OBJ_JSON_TEST)
OBJ_KWORD_TEST = \
objects/json.o \
objects/memfile.o \
objects/message.o \
objects/kword_test.o
KWORD_TEST_OBJ = $(OBJ_COMMON) $(OBJ_KWORD_TEST)
OBJ_MEMFILE_TEST = \
objects/charset.o \
objects/json.o \
objects/message.o \
objects/memfile_test.o
@@ -1701,6 +1713,7 @@ OBJ_MEMFILE_TEST = \
MEMFILE_TEST_OBJ = $(OBJ_COMMON) $(OBJ_MEMFILE_TEST)
OBJ_MESSAGE_TEST = \
objects/charset.o \
objects/json.o \
objects/memfile.o \
objects/message_test.o
@@ -1710,6 +1723,7 @@ MESSAGE_TEST_OBJ = $(OBJ_COMMON) $(OBJ_MESSAGE_TEST)
ALL_OBJ = $(OBJ_COMMON) \
$(OBJ_MAIN) \
$(OBJ_JSON_TEST) \
$(OBJ_KWORD_TEST) \
$(OBJ_MEMFILE_TEST) \
$(OBJ_MESSAGE_TEST)
@@ -2036,6 +2050,9 @@ unittest unittests: $(RUN_UNITTESTS)
run_json_test: $(JSON_TEST_TARGET)
$(VALGRIND) ./$(JSON_TEST_TARGET) || exit 1; echo $* passed;
run_kword_test: $(KWORD_TEST_TARGET)
$(VALGRIND) ./$(KWORD_TEST_TARGET) || exit 1; echo $* passed;
run_memfile_test: $(MEMFILE_TEST_TARGET)
$(VALGRIND) ./$(MEMFILE_TEST_TARGET) || exit 1; echo $* passed;
@@ -2058,7 +2075,6 @@ test1 \
test_listlbr \
test_listlbr_utf8 \
test_search_mbyte \
test_utf8 \
test_wordcount \
test3 test4 test5 test6 test7 test8 test9 \
test11 test12 test14 test15 test17 test18 test19 \
@@ -2152,6 +2168,8 @@ test_arglist \
test_popup \
test_profile \
test_put \
test_pyx2 \
test_pyx3 \
test_quickfix \
test_regexp_latin \
test_regexp_utf8 \
@@ -2183,6 +2201,7 @@ test_arglist \
test_undo \
test_unlet \
test_usercommands \
test_utf8 \
test_viminfo \
test_viml \
test_visual \
@@ -2220,6 +2239,13 @@ $(JSON_TEST_TARGET): auto/config.mk objects $(JSON_TEST_OBJ)
MAKE="$(MAKE)" LINK_AS_NEEDED=$(LINK_AS_NEEDED) \
sh $(srcdir)/link.sh
$(KWORD_TEST_TARGET): auto/config.mk objects $(KWORD_TEST_OBJ)
$(CCC) version.c -o objects/version.o
@LINK="$(PURIFY) $(SHRPENV) $(CClink) $(ALL_LIB_DIRS) $(LDFLAGS) \
-o $(KWORD_TEST_TARGET) $(KWORD_TEST_OBJ) $(ALL_LIBS)" \
MAKE="$(MAKE)" LINK_AS_NEEDED=$(LINK_AS_NEEDED) \
sh $(srcdir)/link.sh
$(MEMFILE_TEST_TARGET): auto/config.mk objects $(MEMFILE_TEST_OBJ)
$(CCC) version.c -o objects/version.o
@LINK="$(PURIFY) $(SHRPENV) $(CClink) $(ALL_LIB_DIRS) $(LDFLAGS) \
@@ -2754,6 +2780,7 @@ shadow: runtime pixmaps
../../testdir/*.vim \
../../testdir/*.py \
../../testdir/python* \
../../testdir/pyxfile \
../../testdir/sautest \
../../testdir/samples \
../../testdir/test83-tags? \
@@ -3055,6 +3082,9 @@ objects/json.o: json.c
objects/json_test.o: json_test.c
$(CCC) -o $@ json_test.c
objects/kword_test.o: kword_test.c
$(CCC) -o $@ kword_test.c
objects/list.o: list.c
$(CCC) -o $@ list.c
@@ -3594,6 +3624,10 @@ objects/json_test.o: json_test.c main.c vim.h auto/config.h feature.h os_unix.h
auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h gui_beval.h proto/gui_beval.pro alloc.h ex_cmds.h spell.h \
proto.h globals.h farsi.h arabic.h json.c
objects/kword_test.o: kword_test.c main.c vim.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h gui_beval.h proto/gui_beval.pro alloc.h ex_cmds.h spell.h \
proto.h globals.h farsi.h arabic.h charset.c mbyte.c
objects/memfile_test.o: memfile_test.c main.c vim.h auto/config.h feature.h \
os_unix.h auto/osdef.h ascii.h keymap.h term.h macros.h option.h \
structs.h regexp.h gui.h gui_beval.h proto/gui_beval.pro alloc.h \

View File

@@ -899,16 +899,17 @@ vim_iswordc(int c)
int
vim_iswordc_buf(int c, buf_T *buf)
{
#ifdef FEAT_MBYTE
if (c >= 0x100)
{
#ifdef FEAT_MBYTE
if (enc_dbcs != 0)
return dbcs_class((unsigned)c >> 8, (unsigned)(c & 0xff)) >= 2;
if (enc_utf8)
return utf_class(c) >= 2;
}
return utf_class_buf(c, buf) >= 2;
#endif
return (c > 0 && c < 0x100 && GET_CHARTAB(buf, c) != 0);
return FALSE;
}
return (c > 0 && GET_CHARTAB(buf, c) != 0);
}
/*
@@ -917,21 +918,19 @@ vim_iswordc_buf(int c, buf_T *buf)
int
vim_iswordp(char_u *p)
{
#ifdef FEAT_MBYTE
if (has_mbyte && MB_BYTE2LEN(*p) > 1)
return mb_get_class(p) >= 2;
#endif
return GET_CHARTAB(curbuf, *p) != 0;
return vim_iswordp_buf(p, curbuf);
}
int
vim_iswordp_buf(char_u *p, buf_T *buf)
{
int c = *p;
#ifdef FEAT_MBYTE
if (has_mbyte && MB_BYTE2LEN(*p) > 1)
return mb_get_class(p) >= 2;
if (has_mbyte && MB_BYTE2LEN(c) > 1)
c = (*mb_ptr2char)(p);
#endif
return (GET_CHARTAB(buf, *p) != 0);
return vim_iswordc_buf(c, buf);
}
/*
@@ -1296,7 +1295,14 @@ getvcol(
if (pos->col == MAXCOL)
posptr = NULL; /* continue until the NUL */
else
{
posptr = ptr + pos->col;
#ifdef FEAT_MBYTE
if (has_mbyte)
/* always start on the first byte */
posptr -= (*mb_head_off)(line, posptr);
#endif
}
/*
* This function is used very often, do some speed optimizations.

View File

@@ -2821,6 +2821,7 @@ set_completion(colnr_T startcol, list_T *list)
if (ctrl_x_mode != 0)
ins_compl_prep(' ');
ins_compl_clear();
ins_compl_free();
compl_direction = FORWARD;
if (startcol > curwin->w_cursor.col)

View File

@@ -9240,35 +9240,34 @@ fill_assert_error(
if (opt_msg_tv->v_type != VAR_UNKNOWN)
{
ga_concat(gap, tv2string(opt_msg_tv, &tofree, numbuf, 0));
ga_concat(gap, echo_string(opt_msg_tv, &tofree, numbuf, 0));
vim_free(tofree);
ga_concat(gap, (char_u *)": ");
}
if (atype == ASSERT_MATCH || atype == ASSERT_NOTMATCH)
ga_concat(gap, (char_u *)"Pattern ");
else if (atype == ASSERT_NOTEQUAL)
ga_concat(gap, (char_u *)"Expected not equal to ");
else
ga_concat(gap, (char_u *)"Expected ");
if (exp_str == NULL)
{
ga_concat_esc(gap, tv2string(exp_tv, &tofree, numbuf, 0));
vim_free(tofree);
}
else
ga_concat_esc(gap, exp_str);
if (atype != ASSERT_NOTEQUAL)
{
if (atype == ASSERT_MATCH || atype == ASSERT_NOTMATCH)
ga_concat(gap, (char_u *)"Pattern ");
else if (atype == ASSERT_NOTEQUAL)
ga_concat(gap, (char_u *)"Expected not equal to ");
if (atype == ASSERT_MATCH)
ga_concat(gap, (char_u *)" does not match ");
else if (atype == ASSERT_NOTMATCH)
ga_concat(gap, (char_u *)" does match ");
else
ga_concat(gap, (char_u *)"Expected ");
if (exp_str == NULL)
{
ga_concat_esc(gap, tv2string(exp_tv, &tofree, numbuf, 0));
vim_free(tofree);
}
else
ga_concat_esc(gap, exp_str);
if (atype != ASSERT_NOTEQUAL)
{
if (atype == ASSERT_MATCH)
ga_concat(gap, (char_u *)" does not match ");
else if (atype == ASSERT_NOTMATCH)
ga_concat(gap, (char_u *)" does match ");
else
ga_concat(gap, (char_u *)" but got ");
ga_concat_esc(gap, tv2string(got_tv, &tofree, numbuf, 0));
vim_free(tofree);
}
ga_concat(gap, (char_u *)" but got ");
ga_concat_esc(gap, tv2string(got_tv, &tofree, numbuf, 0));
vim_free(tofree);
}
}

View File

@@ -289,6 +289,9 @@ static void f_py3eval(typval_T *argvars, typval_T *rettv);
#ifdef FEAT_PYTHON
static void f_pyeval(typval_T *argvars, typval_T *rettv);
#endif
#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
static void f_pyxeval(typval_T *argvars, typval_T *rettv);
#endif
static void f_range(typval_T *argvars, typval_T *rettv);
static void f_readfile(typval_T *argvars, typval_T *rettv);
static void f_reltime(typval_T *argvars, typval_T *rettv);
@@ -715,6 +718,9 @@ static struct fst
#endif
#ifdef FEAT_PYTHON
{"pyeval", 1, 1, f_pyeval},
#endif
#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
{"pyxeval", 1, 1, f_pyxeval},
#endif
{"range", 1, 3, f_range},
{"readfile", 1, 3, f_readfile},
@@ -5734,15 +5740,13 @@ f_has(typval_T *argvars, typval_T *rettv)
#ifdef FEAT_PERSISTENT_UNDO
"persistent_undo",
#endif
#ifdef FEAT_PYTHON
#ifndef DYNAMIC_PYTHON
#if defined(FEAT_PYTHON) && !defined(DYNAMIC_PYTHON)
"python",
"pythonx",
#endif
#endif
#ifdef FEAT_PYTHON3
#ifndef DYNAMIC_PYTHON3
#if defined(FEAT_PYTHON3) && !defined(DYNAMIC_PYTHON3)
"python3",
#endif
"pythonx",
#endif
#ifdef FEAT_POSTSCRIPT
"postscript",
@@ -5972,17 +5976,30 @@ f_has(typval_T *argvars, typval_T *rettv)
else if (STRICMP(name, "ruby") == 0)
n = ruby_enabled(FALSE);
#endif
#ifdef FEAT_PYTHON
#ifdef DYNAMIC_PYTHON
else if (STRICMP(name, "python") == 0)
n = python_enabled(FALSE);
#endif
#endif
#ifdef FEAT_PYTHON3
#ifdef DYNAMIC_PYTHON3
else if (STRICMP(name, "python3") == 0)
n = python3_enabled(FALSE);
#endif
#if defined(DYNAMIC_PYTHON) || defined(DYNAMIC_PYTHON3)
else if (STRICMP(name, "pythonx") == 0)
{
# if defined(DYNAMIC_PYTHON) && defined(DYNAMIC_PYTHON3)
if (p_pyx == 0)
n = python3_enabled(FALSE) || python_enabled(FALSE);
else if (p_pyx == 3)
n = python3_enabled(FALSE);
else if (p_pyx == 2)
n = python_enabled(FALSE);
# elif defined(DYNAMIC_PYTHON)
n = python_enabled(FALSE);
# elif defined(DYNAMIC_PYTHON3)
n = python3_enabled(FALSE);
# endif
}
#endif
#ifdef DYNAMIC_PERL
else if (STRICMP(name, "perl") == 0)
@@ -8007,6 +8024,9 @@ f_py3eval(typval_T *argvars, typval_T *rettv)
char_u *str;
char_u buf[NUMBUFLEN];
if (p_pyx == 0)
p_pyx = 3;
str = get_tv_string_buf(&argvars[0], buf);
do_py3eval(str, rettv);
}
@@ -8022,11 +8042,35 @@ f_pyeval(typval_T *argvars, typval_T *rettv)
char_u *str;
char_u buf[NUMBUFLEN];
if (p_pyx == 0)
p_pyx = 2;
str = get_tv_string_buf(&argvars[0], buf);
do_pyeval(str, rettv);
}
#endif
#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
/*
* "pyxeval()" function
*/
static void
f_pyxeval(typval_T *argvars, typval_T *rettv)
{
# if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
init_pyxversion();
if (p_pyx == 2)
f_pyeval(argvars, rettv);
else
f_py3eval(argvars, rettv);
# elif defined(FEAT_PYTHON)
f_pyeval(argvars, rettv);
# elif defined(FEAT_PYTHON3)
f_py3eval(argvars, rettv);
# endif
}
#endif
/*
* "range()" function
*/
@@ -12503,39 +12547,8 @@ f_timer_stopall(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
static void
f_tolower(typval_T *argvars, typval_T *rettv)
{
char_u *p;
p = vim_strsave(get_tv_string(&argvars[0]));
rettv->v_type = VAR_STRING;
rettv->vval.v_string = p;
if (p != NULL)
while (*p != NUL)
{
#ifdef FEAT_MBYTE
int l;
if (enc_utf8)
{
int c, lc;
c = utf_ptr2char(p);
lc = utf_tolower(c);
l = utf_ptr2len(p);
/* TODO: reallocate string when byte count changes. */
if (utf_char2len(lc) == l)
utf_char2bytes(lc, p);
p += l;
}
else if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1)
p += l; /* skip multi-byte character */
else
#endif
{
*p = TOLOWER_LOC(*p); /* note that tolower() can be a macro */
++p;
}
}
rettv->vval.v_string = strlow_save(get_tv_string(&argvars[0]));
}
/*

View File

@@ -1132,6 +1132,18 @@ EX(CMD_python3, "python3", ex_py3,
EX(CMD_py3file, "py3file", ex_py3file,
RANGE|FILE1|NEEDARG|CMDWIN,
ADDR_LINES),
EX(CMD_pyx, "pyx", ex_pyx,
RANGE|EXTRA|NEEDARG|CMDWIN,
ADDR_LINES),
EX(CMD_pyxdo, "pyxdo", ex_pyxdo,
RANGE|DFLALL|EXTRA|NEEDARG|CMDWIN,
ADDR_LINES),
EX(CMD_pythonx, "pythonx", ex_pyx,
RANGE|EXTRA|NEEDARG|CMDWIN,
ADDR_LINES),
EX(CMD_pyxfile, "pyxfile", ex_pyxfile,
RANGE|FILE1|NEEDARG|CMDWIN,
ADDR_LINES),
EX(CMD_quit, "quit", ex_quit,
BANG|RANGE|COUNT|NOTADR|TRLBAR|CMDWIN,
ADDR_WINDOWS),

View File

@@ -3675,6 +3675,194 @@ ex_options(
}
#endif
#if defined(FEAT_PYTHON3) || defined(FEAT_PYTHON) || defined(PROTO)
# if (defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)) || defined(PROTO)
/*
* Detect Python 3 or 2, and initialize 'pyxversion'.
*/
void
init_pyxversion(void)
{
if (p_pyx == 0)
{
if (python3_enabled(FALSE))
p_pyx = 3;
else if (python_enabled(FALSE))
p_pyx = 2;
}
}
# endif
/*
* Does a file contain one of the following strings at the beginning of any
* line?
* "#!(any string)python2" => returns 2
* "#!(any string)python3" => returns 3
* "# requires python 2.x" => returns 2
* "# requires python 3.x" => returns 3
* otherwise return 0.
*/
static int
requires_py_version(char_u *filename)
{
FILE *file;
int requires_py_version = 0;
int i, lines;
lines = (int)p_mls;
if (lines < 0)
lines = 5;
file = mch_fopen((char *)filename, "r");
if (file != NULL)
{
for (i = 0; i < lines; i++)
{
if (vim_fgets(IObuff, IOSIZE, file))
break;
if (i == 0 && IObuff[0] == '#' && IObuff[1] == '!')
{
/* Check shebang. */
if (strstr((char *)IObuff + 2, "python2") != NULL)
{
requires_py_version = 2;
break;
}
if (strstr((char *)IObuff + 2, "python3") != NULL)
{
requires_py_version = 3;
break;
}
}
IObuff[21] = '\0';
if (STRCMP("# requires python 2.x", IObuff) == 0)
{
requires_py_version = 2;
break;
}
if (STRCMP("# requires python 3.x", IObuff) == 0)
{
requires_py_version = 3;
break;
}
}
fclose(file);
}
return requires_py_version;
}
/*
* Source a python file using the requested python version.
*/
static void
source_pyx_file(exarg_T *eap, char_u *fname)
{
exarg_T ex;
int v = requires_py_version(fname);
# if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
init_pyxversion();
# endif
if (v == 0)
{
# if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
/* user didn't choose a preference, 'pyx' is used */
v = p_pyx;
# elif defined(FEAT_PYTHON)
v = 2;
# elif defined(FEAT_PYTHON3)
v = 3;
# endif
}
/*
* now source, if required python version is not supported show
* unobtrusive message.
*/
if (eap == NULL)
vim_memset(&ex, 0, sizeof(ex));
else
ex = *eap;
ex.arg = fname;
ex.cmd = (char_u *)(v == 2 ? "pyfile" : "pyfile3");
if (v == 2)
{
# ifdef FEAT_PYTHON
ex_pyfile(&ex);
# else
vim_snprintf((char *)IObuff, IOSIZE,
_("W20: Required python version 2.x not supported, ignoring file: %s"),
fname);
MSG(IObuff);
# endif
return;
}
else
{
# ifdef FEAT_PYTHON3
ex_py3file(&ex);
# else
vim_snprintf((char *)IObuff, IOSIZE,
_("W21: Required python version 3.x not supported, ignoring file: %s"),
fname);
MSG(IObuff);
# endif
return;
}
}
/*
* ":pyxfile {fname}"
*/
void
ex_pyxfile(exarg_T *eap)
{
source_pyx_file(eap, eap->arg);
}
/*
* ":pyx"
*/
void
ex_pyx(exarg_T *eap)
{
# if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
init_pyxversion();
if (p_pyx == 2)
ex_python(eap);
else
ex_py3(eap);
# elif defined(FEAT_PYTHON)
ex_python(eap);
# elif defined(FEAT_PYTHON3)
ex_py3(eap);
# endif
}
/*
* ":pyxdo"
*/
void
ex_pyxdo(exarg_T *eap)
{
# if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
init_pyxversion();
if (p_pyx == 2)
ex_pydo(eap);
else
ex_py3do(eap);
# elif defined(FEAT_PYTHON)
ex_pydo(eap);
# elif defined(FEAT_PYTHON3)
ex_py3do(eap);
# endif
}
#endif
/*
* ":source {fname}"
*/

View File

@@ -288,6 +288,11 @@ static void ex_popup(exarg_T *eap);
# define ex_py3do ex_ni
# define ex_py3file ex_ni
#endif
#if !defined(FEAT_PYTHON) && !defined(FEAT_PYTHON3)
# define ex_pyx ex_script_ni
# define ex_pyxdo ex_ni
# define ex_pyxfile ex_ni
#endif
#ifndef FEAT_TCL
# define ex_tcl ex_script_ni
# define ex_tcldo ex_ni
@@ -11192,8 +11197,10 @@ makeopens(
* resized when moving between windows.
* Do this before restoring the view, so that the topline and the
* cursor can be set. This is done again below.
* winminheight and winminwidth need to be set to avoid an error if the
* user has set winheight or winwidth.
*/
if (put_line(fd, "set winheight=1 winwidth=1") == FAIL)
if (put_line(fd, "set winminheight=1 winheight=1 winminwidth=1 winwidth=1") == FAIL)
return FAIL;
if (nr > 1 && ses_winsizes(fd, restore_size, tab_firstwin) == FAIL)
return FAIL;
@@ -11263,6 +11270,10 @@ makeopens(
if (fprintf(fd, "set winheight=%ld winwidth=%ld shortmess=%s",
p_wh, p_wiw, p_shm) < 0 || put_eol(fd) == FAIL)
return FAIL;
/* Re-apply 'winminheight' and 'winminwidth'. */
if (fprintf(fd, "set winminheight=%ld winminwidth=%ld",
p_wmh, p_wmw) < 0 || put_eol(fd) == FAIL)
return FAIL;
/*
* Lastly, execute the x.vim file if it exists.

View File

@@ -1114,6 +1114,9 @@ ex_python(exarg_T *eap)
{
char_u *script;
if (p_pyx == 0)
p_pyx = 2;
script = script_get(eap, eap->arg);
if (!eap->skip)
{
@@ -1137,6 +1140,9 @@ ex_pyfile(exarg_T *eap)
const char *file = (char *)eap->arg;
char *p;
if (p_pyx == 0)
p_pyx = 2;
/* Have to do it like this. PyRun_SimpleFile requires you to pass a
* stdio file pointer, but Vim and the Python DLL are compiled with
* different options under Windows, meaning that stdio pointers aren't
@@ -1175,6 +1181,9 @@ ex_pyfile(exarg_T *eap)
void
ex_pydo(exarg_T *eap)
{
if (p_pyx == 0)
p_pyx = 2;
DoPyCommand((char *)eap->arg,
(rangeinitializer) init_range_cmd,
(runner)run_do,

View File

@@ -1004,6 +1004,9 @@ ex_py3(exarg_T *eap)
{
char_u *script;
if (p_pyx == 0)
p_pyx = 3;
script = script_get(eap, eap->arg);
if (!eap->skip)
{
@@ -1028,6 +1031,9 @@ ex_py3file(exarg_T *eap)
char *p;
int i;
if (p_pyx == 0)
p_pyx = 3;
/* Have to do it like this. PyRun_SimpleFile requires you to pass a
* stdio file pointer, but Vim and the Python DLL are compiled with
* different options under Windows, meaning that stdio pointers aren't
@@ -1080,6 +1086,9 @@ ex_py3file(exarg_T *eap)
void
ex_py3do(exarg_T *eap)
{
if (p_pyx == 0)
p_pyx = 3;
DoPyCommand((char *)eap->arg,
(rangeinitializer)init_range_cmd,
(runner)run_do,

85
src/kword_test.c Normal file
View File

@@ -0,0 +1,85 @@
/* vi:set ts=8 sts=4 sw=4 noet:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/
/*
* kword_test.c: Unittests for vim_iswordc() and vim_iswordp().
*/
#undef NDEBUG
#include <assert.h>
/* Must include main.c because it contains much more than just main() */
#define NO_VIM_MAIN
#include "main.c"
/* This file has to be included because the tested functions are static */
#include "charset.c"
#ifdef FEAT_MBYTE
/*
* Test the results of vim_iswordc() and vim_iswordp() are matched.
*/
static void
test_isword_funcs_utf8(void)
{
buf_T buf;
int c;
vim_memset(&buf, 0, sizeof(buf));
p_enc = (char_u *)"utf-8";
p_isi = (char_u *)"";
p_isp = (char_u *)"";
p_isf = (char_u *)"";
buf.b_p_isk = (char_u *)"@,48-57,_,128-167,224-235";
curbuf = &buf;
mb_init(); /* calls init_chartab() */
for (c = 0; c < 0x10000; ++c)
{
char_u p[4] = {0};
int c1;
int retc;
int retp;
utf_char2bytes(c, p);
c1 = utf_ptr2char(p);
if (c != c1)
{
fprintf(stderr, "Failed: ");
fprintf(stderr,
"[c = %#04x, p = {%#02x, %#02x, %#02x}] ",
c, p[0], p[1], p[2]);
fprintf(stderr, "c != utf_ptr2char(p) (=%#04x)\n", c1);
abort();
}
retc = vim_iswordc_buf(c, &buf);
retp = vim_iswordp_buf(p, &buf);
if (retc != retp)
{
fprintf(stderr, "Failed: ");
fprintf(stderr,
"[c = %#04x, p = {%#02x, %#02x, %#02x}] ",
c, p[0], p[1], p[2]);
fprintf(stderr, "vim_iswordc(c) (=%d) != vim_iswordp(p) (=%d)\n",
retc, retp);
abort();
}
}
}
#endif
int
main(void)
{
#ifdef FEAT_MBYTE
test_isword_funcs_utf8();
#endif
return 0;
}

View File

@@ -895,7 +895,7 @@ mb_get_class_buf(char_u *p, buf_T *buf)
if (enc_dbcs != 0 && p[0] != NUL && p[1] != NUL)
return dbcs_class(p[0], p[1]);
if (enc_utf8)
return utf_class(utf_ptr2char(p));
return utf_class_buf(utf_ptr2char(p), buf);
return 0;
}
@@ -2693,6 +2693,12 @@ static struct interval emoji_all[] =
*/
int
utf_class(int c)
{
return utf_class_buf(c, curbuf);
}
int
utf_class_buf(int c, buf_T *buf)
{
/* sorted list of non-overlapping intervals */
static struct clinterval
@@ -2780,7 +2786,7 @@ utf_class(int c)
{
if (c == ' ' || c == '\t' || c == NUL || c == 0xa0)
return 0; /* blank */
if (vim_iswordc(c))
if (vim_iswordc_buf(c, buf))
return 2; /* word character */
return 1; /* punctuation */
}

View File

@@ -1602,7 +1602,10 @@ strup_save(char_u *orig)
{
s = alloc((unsigned)STRLEN(res) + 1 + newl - l);
if (s == NULL)
break;
{
vim_free(res);
return NULL;
}
mch_memmove(s, res, p - res);
STRCPY(s + (p - res) + newl, p + l);
p = s + (p - res);
@@ -1625,6 +1628,69 @@ strup_save(char_u *orig)
return res;
}
/*
* Make string "s" all lower-case and return it in allocated memory.
* Handles multi-byte characters as well as possible.
* Returns NULL when out of memory.
*/
char_u *
strlow_save(char_u *orig)
{
char_u *p;
char_u *res;
res = p = vim_strsave(orig);
if (res != NULL)
while (*p != NUL)
{
# ifdef FEAT_MBYTE
int l;
if (enc_utf8)
{
int c, lc;
int newl;
char_u *s;
c = utf_ptr2char(p);
lc = utf_tolower(c);
/* Reallocate string when byte count changes. This is rare,
* thus it's OK to do another malloc()/free(). */
l = utf_ptr2len(p);
newl = utf_char2len(lc);
if (newl != l)
{
s = alloc((unsigned)STRLEN(res) + 1 + newl - l);
if (s == NULL)
{
vim_free(res);
return NULL;
}
mch_memmove(s, res, p - res);
STRCPY(s + (p - res) + newl, p + l);
p = s + (p - res);
vim_free(res);
res = s;
}
utf_char2bytes(lc, p);
p += newl;
}
else if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1)
p += l; /* skip multi-byte character */
else
# endif
{
*p = TOLOWER_LOC(*p); /* note that tolower() can be a macro */
p++;
}
}
return res;
}
#endif
/*
@@ -1653,7 +1719,7 @@ vim_strncpy(char_u *to, char_u *from, size_t len)
/*
* Like strcat(), but make sure the result fits in "tosize" bytes and is
* always NUL terminated.
* always NUL terminated. "from" and "to" may overlap.
*/
void
vim_strcat(char_u *to, char_u *from, size_t tosize)
@@ -1667,7 +1733,7 @@ vim_strcat(char_u *to, char_u *from, size_t tosize)
to[tosize - 1] = NUL;
}
else
STRCPY(to + tolen, from);
mch_memmove(to + tolen, from, fromlen + 1);
}
/*
@@ -1740,34 +1806,6 @@ vim_memset(void *ptr, int c, size_t size)
}
#endif
/* skipped when generating prototypes, the prototype is in vim.h */
#ifdef VIM_MEMMOVE
/*
* Version of memmove() that handles overlapping source and destination.
* For systems that don't have a function that is guaranteed to do that (SYSV).
*/
void
mch_memmove(void *src_arg, void *dst_arg, size_t len)
{
/*
* A void doesn't have a size, we use char pointers.
*/
char *dst = dst_arg, *src = src_arg;
/* overlap, copy backwards */
if (dst > src && dst < src + len)
{
src += len;
dst += len;
while (len-- > 0)
*--dst = *--src;
}
else /* copy forwards */
while (len-- > 0)
*dst++ = *src++;
}
#endif
#if (!defined(HAVE_STRCASECMP) && !defined(HAVE_STRICMP)) || defined(PROTO)
/*
* Compare two strings, ignoring case, using current locale.

View File

@@ -479,6 +479,17 @@ struct vimoption
# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,t:Title,v:Visual,w:WarningMsg,W:WildMenu,>:SignColumn,*:TabLine,#:TabLineSel,_:TabLineFill"
#endif
/* Default python version for pyx* commands */
#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
# define DEFAULT_PYTHON_VER 0
#elif defined(FEAT_PYTHON3)
# define DEFAULT_PYTHON_VER 3
#elif defined(FEAT_PYTHON)
# define DEFAULT_PYTHON_VER 2
#else
# define DEFAULT_PYTHON_VER 0
#endif
/*
* options[] is initialized here.
* The order of the options MUST be alphabetic for ":set all" and findoption().
@@ -2143,6 +2154,14 @@ static struct vimoption options[] =
{(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
SCRIPTID_INIT},
#endif
{"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
(char_u *)&p_pyx, PV_NONE,
#else
(char_u *)NULL, PV_NONE,
#endif
{(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
SCRIPTID_INIT},
{"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
#ifdef FEAT_TEXTOBJ
(char_u *)&p_qe, PV_QE,
@@ -6619,6 +6638,15 @@ did_set_string_option(
mch_set_normal_colors();
#endif
}
if (varp == &T_BE && termcap_active)
{
if (*T_BE == NUL)
/* When clearing t_BE we assume the user no longer wants
* bracketed paste, thus disable it by writing t_BD. */
out_str(T_BD);
else
out_str(T_BE);
}
}
#ifdef FEAT_LINEBREAK
@@ -8817,6 +8845,15 @@ set_num_option(
mzvim_reset_timer();
#endif
#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
/* 'pyxversion' */
else if (pp == &p_pyx)
{
if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
errmsg = e_invarg;
}
#endif
/* sync undo before 'undolevels' changes */
else if (pp == &p_ul)
{

View File

@@ -694,6 +694,9 @@ EXTERN char_u *p_py3dll; /* 'pythonthreedll' */
#if defined(DYNAMIC_PYTHON)
EXTERN char_u *p_pydll; /* 'pythondll' */
#endif
#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
EXTERN long p_pyx; /* 'pyxversion' */
#endif
#ifdef FEAT_RELTIME
EXTERN long p_rdt; /* 'redrawtime' */
#endif

View File

@@ -423,21 +423,17 @@ typedef struct dsc$descriptor DESC;
# endif
#endif
/* memmove is not present on all systems, use memmove, bcopy, memcpy or our
* own version */
/* Some systems have (void *) arguments, some (char *). If we use (char *) it
/* memmove() is not present on all systems, use memmove, bcopy or memcpy.
* Some systems have (void *) arguments, some (char *). If we use (char *) it
* works for all */
#ifdef USEMEMMOVE
#if defined(USEMEMMOVE) || (!defined(USEBCOPY) && !defined(USEMEMCPY))
# define mch_memmove(to, from, len) memmove((char *)(to), (char *)(from), len)
#else
# ifdef USEBCOPY
# define mch_memmove(to, from, len) bcopy((char *)(from), (char *)(to), len)
# else
# ifdef USEMEMCPY
/* ifdef USEMEMCPY */
# define mch_memmove(to, from, len) memcpy((char *)(to), (char *)(from), len)
# else
# define VIM_MEMMOVE /* found in misc2.c */
# endif
# endif
#endif

View File

@@ -232,12 +232,13 @@ sk.cp1250.po: sk.po
iconv -f iso-8859-2 -t cp1250 sk.po | \
sed -e 's/charset=ISO-8859-2/charset=cp1250/' -e 's/# Original translations/# Generated from sk.po, DO NOT EDIT/' > sk.cp1250.po
# Convert zh_CN.po to create zh_CN.cp936.po.
# set 'charset' to gbk to avoid that msfmt generates a warning
zh_CN.cp936.po: zh_CN.po
# Convert zh_CN.UTF-8.po to create zh_CN.cp936.po.
# Set 'charset' to gbk to avoid that msfmt generates a warning.
# This used to convert from zh_CN.po, but that results in a conversion error.
zh_CN.cp936.po: zh_CN.UTF-8.po
rm -f zh_CN.cp936.po
iconv -f gb2312 -t cp936 zh_CN.po | \
sed -e 's/charset=gb2312/charset=gbk/' -e 's/# Original translations/# Generated from zh_CN.po, DO NOT EDIT/' > zh_CN.cp936.po
iconv -f UTF-8 -t cp936 zh_CN.UTF-8.po | \
sed -e 's/charset=utf-8/charset=gbk/' -e 's/# Original translations/# Generated from zh_CN.po, DO NOT EDIT/' > zh_CN.cp936.po
# Convert ko.UTF-8.po to create ko.po.
ko.po: ko.UTF-8.po

View File

@@ -75,6 +75,10 @@ int do_in_runtimepath(char_u *name, int flags, void (*callback)(char_u *fname, v
void ex_packloadall(exarg_T *eap);
void ex_packadd(exarg_T *eap);
void ex_options(exarg_T *eap);
void init_pyxversion(void);
void ex_pyxfile(exarg_T *eap);
void ex_pyx(exarg_T *eap);
void ex_pyxdo(exarg_T *eap);
void ex_source(exarg_T *eap);
linenr_T *source_breakpoint(void *cookie);
int *source_dbg_tick(void *cookie);

View File

@@ -40,6 +40,7 @@ int utf_char2bytes(int c, char_u *buf);
int utf_iscomposing(int c);
int utf_printable(int c);
int utf_class(int c);
int utf_class_buf(int c, buf_T *buf);
int utf_ambiguous_width(int c);
int utf_fold(int a);
int utf_toupper(int a);

View File

@@ -40,6 +40,7 @@ char_u *vim_strsave_up(char_u *string);
char_u *vim_strnsave_up(char_u *string, int len);
void vim_strup(char_u *p);
char_u *strup_save(char_u *orig);
char_u *strlow_save(char_u *orig);
void del_trailing_spaces(char_u *ptr);
void vim_strncpy(char_u *to, char_u *from, size_t len);
void vim_strcat(char_u *to, char_u *from, size_t tosize);

View File

@@ -84,7 +84,6 @@ SCRIPTS_ALL = \
test_listchars.out \
test_listlbr.out \
test_search_mbyte.out \
test_utf8.out \
test_wordcount.out
@@ -177,6 +176,8 @@ NEW_TESTS = test_arglist.res \
test_packadd.res \
test_perl.res \
test_profile.res \
test_pyx2.res \
test_pyx3.res \
test_quickfix.res \
test_retab.res \
test_ruby.res \

View File

@@ -0,0 +1,4 @@
# requires python 2.x
import sys
print(sys.version)

View File

@@ -0,0 +1,4 @@
#!/usr/bin/python2
import sys
print(sys.version)

View File

@@ -0,0 +1,4 @@
# requires python 3.x
import sys
print(sys.version)

View File

@@ -0,0 +1,4 @@
#!/usr/bin/python3
import sys
print(sys.version)

View File

@@ -0,0 +1,2 @@
import sys
print(sys.version)

View File

@@ -9,3 +9,4 @@ source test_expr_utf8.vim
source test_matchadd_conceal_utf8.vim
source test_regexp_utf8.vim
source test_source_utf8.vim
source test_utf8.vim

View File

@@ -121,6 +121,12 @@ func Test_assert_inrange()
call assert_fails('call assert_inrange(1, 1)', 'E119:')
endfunc
func Test_assert_with_msg()
call assert_equal('foo', 'bar', 'testing')
call assert_match("testing: Expected 'foo' but got 'bar'", v:errors[0])
call remove(v:errors, 0)
endfunc
func Test_user_is_happy()
smile
sleep 300m

View File

@@ -16,3 +16,148 @@ func Test_str2nr()
call assert_equal(123456789, str2nr('123456789'))
call assert_equal(-123456789, str2nr('-123456789'))
endfunc
func Test_tolower()
call assert_equal("", tolower(""))
" Test with all printable ASCII characters.
call assert_equal(' !"#$%&''()*+,-./0123456789:;<=>?@abcdefghijklmnopqrstuvwxyz[\]^_`abcdefghijklmnopqrstuvwxyz{|}~',
\ tolower(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~'))
if !has('multi_byte')
return
endif
" Test with a few uppercase diacritics.
call assert_equal("aàáâãäåāăąǎǟǡả", tolower("AÀÁÂÃÄÅĀĂĄǍǞǠẢ"))
call assert_equal("bḃḇ", tolower("BḂḆ"))
call assert_equal("cçćĉċč", tolower("CÇĆĈĊČ"))
call assert_equal("dďđḋḏḑ", tolower("DĎĐḊḎḐ"))
call assert_equal("eèéêëēĕėęěẻẽ", tolower("EÈÉÊËĒĔĖĘĚẺẼ"))
call assert_equal("fḟ ", tolower("FḞ "))
call assert_equal("gĝğġģǥǧǵḡ", tolower("GĜĞĠĢǤǦǴḠ"))
call assert_equal("hĥħḣḧḩ", tolower("HĤĦḢḦḨ"))
call assert_equal("iìíîïĩīĭįiǐỉ", tolower("IÌÍÎÏĨĪĬĮİǏỈ"))
call assert_equal("jĵ", tolower("JĴ"))
call assert_equal("kķǩḱḵ", tolower("KĶǨḰḴ"))
call assert_equal("lĺļľŀłḻ", tolower("LĹĻĽĿŁḺ"))
call assert_equal("mḿṁ", tolower("MḾṀ"))
call assert_equal("nñńņňṅṉ", tolower("NÑŃŅŇṄṈ"))
call assert_equal("oòóôõöøōŏőơǒǫǭỏ", tolower("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ"))
call assert_equal("pṕṗ", tolower("PṔṖ"))
call assert_equal("q", tolower("Q"))
call assert_equal("rŕŗřṙṟ", tolower("RŔŖŘṘṞ"))
call assert_equal("sśŝşšṡ", tolower("SŚŜŞŠṠ"))
call assert_equal("tţťŧṫṯ", tolower("TŢŤŦṪṮ"))
call assert_equal("uùúûüũūŭůűųưǔủ", tolower("UÙÚÛÜŨŪŬŮŰŲƯǓỦ"))
call assert_equal("vṽ", tolower("VṼ"))
call assert_equal("wŵẁẃẅẇ", tolower("WŴẀẂẄẆ"))
call assert_equal("xẋẍ", tolower("XẊẌ"))
call assert_equal("yýŷÿẏỳỷỹ", tolower("YÝŶŸẎỲỶỸ"))
call assert_equal("zźżžƶẑẕ", tolower("ZŹŻŽƵẐẔ"))
" Test with a few lowercase diacritics, which should remain unchanged.
call assert_equal("aàáâãäåāăąǎǟǡả", tolower("aàáâãäåāăąǎǟǡả"))
call assert_equal("bḃḇ", tolower("bḃḇ"))
call assert_equal("cçćĉċč", tolower("cçćĉċč"))
call assert_equal("dďđḋḏḑ", tolower("dďđḋḏḑ"))
call assert_equal("eèéêëēĕėęěẻẽ", tolower("eèéêëēĕėęěẻẽ"))
call assert_equal("fḟ", tolower("fḟ"))
call assert_equal("gĝğġģǥǧǵḡ", tolower("gĝğġģǥǧǵḡ"))
call assert_equal("hĥħḣḧḩẖ", tolower("hĥħḣḧḩẖ"))
call assert_equal("iìíîïĩīĭįǐỉ", tolower("iìíîïĩīĭįǐỉ"))
call assert_equal("jĵǰ", tolower("jĵǰ"))
call assert_equal("kķǩḱḵ", tolower("kķǩḱḵ"))
call assert_equal("lĺļľŀłḻ", tolower("lĺļľŀłḻ"))
call assert_equal("mḿṁ ", tolower("mḿṁ "))
call assert_equal("nñńņňʼnṅṉ", tolower("nñńņňʼnṅṉ"))
call assert_equal("oòóôõöøōŏőơǒǫǭỏ", tolower("oòóôõöøōŏőơǒǫǭỏ"))
call assert_equal("pṕṗ", tolower("pṕṗ"))
call assert_equal("q", tolower("q"))
call assert_equal("rŕŗřṙṟ", tolower("rŕŗřṙṟ"))
call assert_equal("sśŝşšṡ", tolower("sśŝşšṡ"))
call assert_equal("tţťŧṫṯẗ", tolower("tţťŧṫṯẗ"))
call assert_equal("uùúûüũūŭůűųưǔủ", tolower("uùúûüũūŭůűųưǔủ"))
call assert_equal("vṽ", tolower("vṽ"))
call assert_equal("wŵẁẃẅẇẘ", tolower("wŵẁẃẅẇẘ"))
call assert_equal("ẋẍ", tolower("ẋẍ"))
call assert_equal("yýÿŷẏẙỳỷỹ", tolower("yýÿŷẏẙỳỷỹ"))
call assert_equal("zźżžƶẑẕ", tolower("zźżžƶẑẕ"))
" According to https://twitter.com/jifa/status/625776454479970304
" Ⱥ (U+023A) and Ⱦ (U+023E) are the *only* code points to increase
" in length (2 to 3 bytes) when lowercased. So let's test them.
call assert_equal("ⱥ ⱦ", tolower("Ⱥ Ⱦ"))
endfunc
func Test_toupper()
call assert_equal("", toupper(""))
" Test with all printable ASCII characters.
call assert_equal(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~',
\ toupper(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~'))
if !has('multi_byte')
return
endif
" Test with a few lowercase diacritics.
call assert_equal("AÀÁÂÃÄÅĀĂĄǍǞǠẢ", toupper("aàáâãäåāăąǎǟǡả"))
call assert_equal("BḂḆ", toupper("bḃḇ"))
call assert_equal("CÇĆĈĊČ", toupper("cçćĉċč"))
call assert_equal("DĎĐḊḎḐ", toupper("dďđḋḏḑ"))
call assert_equal("EÈÉÊËĒĔĖĘĚẺẼ", toupper("eèéêëēĕėęěẻẽ"))
call assert_equal("FḞ", toupper("fḟ"))
call assert_equal("GĜĞĠĢǤǦǴḠ", toupper("gĝğġģǥǧǵḡ"))
call assert_equal("HĤĦḢḦḨẖ", toupper("hĥħḣḧḩẖ"))
call assert_equal("IÌÍÎÏĨĪĬĮǏỈ", toupper("iìíîïĩīĭįǐỉ"))
call assert_equal("JĴǰ", toupper("jĵǰ"))
call assert_equal("KĶǨḰḴ", toupper("kķǩḱḵ"))
call assert_equal("LĹĻĽĿŁḺ", toupper("lĺļľŀłḻ"))
call assert_equal("MḾṀ ", toupper("mḿṁ "))
call assert_equal("NÑŃŅŇʼnṄṈ", toupper("nñńņňʼnṅṉ"))
call assert_equal("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ", toupper("oòóôõöøōŏőơǒǫǭỏ"))
call assert_equal("PṔṖ", toupper("pṕṗ"))
call assert_equal("Q", toupper("q"))
call assert_equal("RŔŖŘṘṞ", toupper("rŕŗřṙṟ"))
call assert_equal("SŚŜŞŠṠ", toupper("sśŝşšṡ"))
call assert_equal("TŢŤŦṪṮẗ", toupper("tţťŧṫṯẗ"))
call assert_equal("UÙÚÛÜŨŪŬŮŰŲƯǓỦ", toupper("uùúûüũūŭůűųưǔủ"))
call assert_equal("VṼ", toupper("vṽ"))
call assert_equal("WŴẀẂẄẆẘ", toupper("wŵẁẃẅẇẘ"))
call assert_equal("ẊẌ", toupper("ẋẍ"))
call assert_equal("YÝŸŶẎẙỲỶỸ", toupper("yýÿŷẏẙỳỷỹ"))
call assert_equal("ZŹŻŽƵẐẔ", toupper("zźżžƶẑẕ"))
" Test that uppercase diacritics, which should remain unchanged.
call assert_equal("AÀÁÂÃÄÅĀĂĄǍǞǠẢ", toupper("AÀÁÂÃÄÅĀĂĄǍǞǠẢ"))
call assert_equal("BḂḆ", toupper("BḂḆ"))
call assert_equal("CÇĆĈĊČ", toupper("CÇĆĈĊČ"))
call assert_equal("DĎĐḊḎḐ", toupper("DĎĐḊḎḐ"))
call assert_equal("EÈÉÊËĒĔĖĘĚẺẼ", toupper("EÈÉÊËĒĔĖĘĚẺẼ"))
call assert_equal("FḞ ", toupper("FḞ "))
call assert_equal("GĜĞĠĢǤǦǴḠ", toupper("GĜĞĠĢǤǦǴḠ"))
call assert_equal("HĤĦḢḦḨ", toupper("HĤĦḢḦḨ"))
call assert_equal("IÌÍÎÏĨĪĬĮİǏỈ", toupper("IÌÍÎÏĨĪĬĮİǏỈ"))
call assert_equal("JĴ", toupper("JĴ"))
call assert_equal("KĶǨḰḴ", toupper("KĶǨḰḴ"))
call assert_equal("LĹĻĽĿŁḺ", toupper("LĹĻĽĿŁḺ"))
call assert_equal("MḾṀ", toupper("MḾṀ"))
call assert_equal("NÑŃŅŇṄṈ", toupper("NÑŃŅŇṄṈ"))
call assert_equal("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ", toupper("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ"))
call assert_equal("PṔṖ", toupper("PṔṖ"))
call assert_equal("Q", toupper("Q"))
call assert_equal("RŔŖŘṘṞ", toupper("RŔŖŘṘṞ"))
call assert_equal("SŚŜŞŠṠ", toupper("SŚŜŞŠṠ"))
call assert_equal("TŢŤŦṪṮ", toupper("TŢŤŦṪṮ"))
call assert_equal("UÙÚÛÜŨŪŬŮŰŲƯǓỦ", toupper("UÙÚÛÜŨŪŬŮŰŲƯǓỦ"))
call assert_equal("VṼ", toupper("VṼ"))
call assert_equal("WŴẀẂẄẆ", toupper("WŴẀẂẄẆ"))
call assert_equal("XẊẌ", toupper("XẊẌ"))
call assert_equal("YÝŶŸẎỲỶỸ", toupper("YÝŶŸẎỲỶỸ"))
call assert_equal("ZŹŻŽƵẐẔ", toupper("ZŹŻŽƵẐẔ"))
call assert_equal("ⱥ ⱦ", tolower("Ⱥ Ⱦ"))
endfunc

View File

@@ -101,4 +101,13 @@ func Test_mksession()
let &wrap = wrap_save
endfunc
func Test_mksession_winheight()
new
set winheight=10 winminheight=2
mksession! test_mks.out
source test_mks.out
" call delete('test_mks.out')
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -7,10 +7,10 @@ func! ListMonths()
if g:setting != ''
exe ":set" g:setting
endif
let mth=copy(g:months)
let mth = copy(g:months)
let entered = strcharpart(getline('.'),0,col('.'))
if !empty(entered)
let mth=filter(mth, 'v:val=~"^".entered')
let mth = filter(mth, 'v:val=~"^".entered')
endif
call complete(1, mth)
return ''
@@ -468,7 +468,7 @@ endfunc
" auto-wrap text.
func Test_completion_ctrl_e_without_autowrap()
new
let tw_save=&tw
let tw_save = &tw
set tw=78
let li = [
\ '" zzz',
@@ -478,8 +478,37 @@ func Test_completion_ctrl_e_without_autowrap()
call feedkeys("A\<C-X>\<C-N>\<C-E>\<Esc>", "tx")
call assert_equal(li, getline(1, '$'))
let &tw=tw_save
let &tw = tw_save
q!
endfunc
function! DummyCompleteSix()
call complete(1, ['Hello', 'World'])
return ''
endfunction
" complete() correctly clears the list of autocomplete candidates
" See #1411
func Test_completion_clear_candidate_list()
new
%d
" select first entry from the completion popup
call feedkeys("a xxx\<C-N>\<C-R>=DummyCompleteSix()\<CR>", "tx")
call assert_equal('Hello', getline(1))
%d
" select second entry from the completion popup
call feedkeys("a xxx\<C-N>\<C-R>=DummyCompleteSix()\<CR>\<C-N>", "tx")
call assert_equal('World', getline(1))
%d
" select original text
call feedkeys("a xxx\<C-N>\<C-R>=DummyCompleteSix()\<CR>\<C-N>\<C-N>", "tx")
call assert_equal(' xxx', getline(1))
%d
" back at first entry from completion list
call feedkeys("a xxx\<C-N>\<C-R>=DummyCompleteSix()\<CR>\<C-N>\<C-N>\<C-N>", "tx")
call assert_equal('Hello', getline(1))
bw!
endfunc
" vim: shiftwidth=2 sts=2 expandtab

74
src/testdir/test_pyx2.vim Normal file
View File

@@ -0,0 +1,74 @@
" Test for pyx* commands and functions with Python 2.
set pyx=2
if !has('python')
finish
endif
let s:py2pattern = '^2\.[0-7]\.\d\+'
let s:py3pattern = '^3\.\d\+\.\d\+'
func Test_has_pythonx()
call assert_true(has('pythonx'))
endfunc
func Test_pyx()
redir => var
pyx << EOF
import sys
print(sys.version)
EOF
redir END
call assert_match(s:py2pattern, split(var)[0])
endfunc
func Test_pyxdo()
pyx import sys
enew
pyxdo return sys.version.split("\n")[0]
call assert_match(s:py2pattern, split(getline('.'))[0])
endfunc
func Test_pyxeval()
pyx import sys
call assert_match(s:py2pattern, split(pyxeval('sys.version'))[0])
endfunc
func Test_pyxfile()
" No special comments nor shebangs
redir => var
pyxfile pyxfile/pyx.py
redir END
call assert_match(s:py2pattern, split(var)[0])
" Python 2 special comment
redir => var
pyxfile pyxfile/py2_magic.py
redir END
call assert_match(s:py2pattern, split(var)[0])
" Python 2 shebang
redir => var
pyxfile pyxfile/py2_shebang.py
redir END
call assert_match(s:py2pattern, split(var)[0])
if has('python3')
" Python 3 special comment
redir => var
pyxfile pyxfile/py3_magic.py
redir END
call assert_match(s:py3pattern, split(var)[0])
" Python 3 shebang
redir => var
pyxfile pyxfile/py3_shebang.py
redir END
call assert_match(s:py3pattern, split(var)[0])
endif
endfunc

74
src/testdir/test_pyx3.vim Normal file
View File

@@ -0,0 +1,74 @@
" Test for pyx* commands and functions with Python 3.
set pyx=3
if !has('python3')
finish
endif
let s:py2pattern = '^2\.[0-7]\.\d\+'
let s:py3pattern = '^3\.\d\+\.\d\+'
func Test_has_pythonx()
call assert_true(has('pythonx'))
endfunc
func Test_pyx()
redir => var
pyx << EOF
import sys
print(sys.version)
EOF
redir END
call assert_match(s:py3pattern, split(var)[0])
endfunc
func Test_pyxdo()
pyx import sys
enew
pyxdo return sys.version.split("\n")[0]
call assert_match(s:py3pattern, split(getline('.'))[0])
endfunc
func Test_pyxeval()
pyx import sys
call assert_match(s:py3pattern, split(pyxeval('sys.version'))[0])
endfunc
func Test_pyxfile()
" No special comments nor shebangs
redir => var
pyxfile pyxfile/pyx.py
redir END
call assert_match(s:py3pattern, split(var)[0])
" Python 3 special comment
redir => var
pyxfile pyxfile/py3_magic.py
redir END
call assert_match(s:py3pattern, split(var)[0])
" Python 3 shebang
redir => var
pyxfile pyxfile/py3_shebang.py
redir END
call assert_match(s:py3pattern, split(var)[0])
if has('python')
" Python 2 special comment
redir => var
pyxfile pyxfile/py2_magic.py
redir END
call assert_match(s:py2pattern, split(var)[0])
" Python 2 shebang
redir => var
pyxfile pyxfile/py2_shebang.py
redir END
call assert_match(s:py2pattern, split(var)[0])
endif
endfunc

View File

@@ -102,3 +102,107 @@ func Test_CmdUndefined()
call assert_fails('Dothat', 'E492:')
call assert_equal('yes', g:didnot)
endfunc
func Test_CmdErrors()
call assert_fails('com! docmd :', 'E183:')
call assert_fails('com! \<Tab> :', 'E182:')
call assert_fails('com! _ :', 'E182:')
call assert_fails('com! X :', 'E841:')
call assert_fails('com! - DoCmd :', 'E175:')
call assert_fails('com! -xxx DoCmd :', 'E181:')
call assert_fails('com! -addr DoCmd :', 'E179:')
call assert_fails('com! -complete DoCmd :', 'E179:')
call assert_fails('com! -complete=xxx DoCmd :', 'E180:')
call assert_fails('com! -complete=custom DoCmd :', 'E467:')
call assert_fails('com! -complete=customlist DoCmd :', 'E467:')
call assert_fails('com! -complete=behave,CustomComplete DoCmd :', 'E468:')
call assert_fails('com! -nargs=x DoCmd :', 'E176:')
call assert_fails('com! -count=1 -count=2 DoCmd :', 'E177:')
call assert_fails('com! -count=x DoCmd :', 'E178:')
call assert_fails('com! -range=x DoCmd :', 'E178:')
com! -nargs=0 DoCmd :
call assert_fails('DoCmd x', 'E488:')
com! -nargs=1 DoCmd :
call assert_fails('DoCmd', 'E471:')
com! -nargs=+ DoCmd :
call assert_fails('DoCmd', 'E471:')
call assert_fails('com DoCmd :', 'E174:')
comclear
call assert_fails('delcom DoCmd', 'E184:')
endfunc
func CustomComplete(A, L, P)
return "January\nFebruary\nMars\n"
endfunc
func CustomCompleteList(A, L, P)
return [ "Monday", "Tuesday", "Wednesday" ]
endfunc
func Test_CmdCompletion()
call feedkeys(":com -\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"com -addr bang bar buffer complete count nargs range register', @:)
call feedkeys(":com -nargs=0 -\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"com -nargs=0 -addr bang bar buffer complete count nargs range register', @:)
call feedkeys(":com -nargs=\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"com -nargs=* + 0 1 ?', @:)
call feedkeys(":com -addr=\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"com -addr=arguments buffers lines loaded_buffers quickfix tabs windows', @:)
call feedkeys(":com -complete=co\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"com -complete=color command compiler', @:)
command! DoCmd1 :
command! DoCmd2 :
call feedkeys(":com \<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"com DoCmd1 DoCmd2', @:)
call feedkeys(":DoC\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"DoCmd1 DoCmd2', @:)
call feedkeys(":delcom DoC\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"delcom DoCmd1 DoCmd2', @:)
delcom DoCmd1
call feedkeys(":delcom DoC\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"delcom DoCmd2', @:)
call feedkeys(":com DoC\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"com DoCmd2', @:)
delcom DoCmd2
call feedkeys(":delcom DoC\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"delcom DoC', @:)
call feedkeys(":com DoC\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"com DoC', @:)
com! -complete=behave DoCmd :
call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"DoCmd mswin xterm', @:)
" This does not work. Why?
"call feedkeys(":DoCmd x\<C-A>\<C-B>\"\<CR>", 'tx')
"call assert_equal('"DoCmd xterm', @:)
com! -complete=custom,CustomComplete DoCmd :
call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"DoCmd January February Mars', @:)
com! -complete=customlist,CustomCompleteList DoCmd :
call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"DoCmd Monday Tuesday Wednesday', @:)
com! -complete=custom,CustomCompleteList DoCmd :
call assert_fails("call feedkeys(':DoCmd \<C-D>', 'tx')", 'E730:')
com! -complete=customlist,CustomComp DoCmd :
call assert_fails("call feedkeys(':DoCmd \<C-D>', 'tx')", 'E117:')
endfunc

View File

@@ -1,46 +0,0 @@
Tests for Unicode manipulations vim: set ft=vim :
STARTTEST
:so small.vim
:set encoding=utf-8
:"
:" Visual block Insert adjusts for multi-byte char
:new
:call setline(1, ["aaa", "あああ", "bbb"])
:exe ":norm! gg0l\<C-V>jjIx\<Esc>"
:let r = getline(1, '$')
:"
:bwipeout!
:$put=r
:"
:" Test for built-in function strchars()
:for str in ["a", "あいa", "A\u20dd", "A\u20dd\u20dd", "\u20dd"]
: $put=strchars(str)
: $put=strchars(str, 0)
: $put=strchars(str, 1)
:endfor
:"
:" Test for customlist completion
:function! CustomComplete1(lead, line, pos)
: return ['あ', 'い']
:endfunction
:command -nargs=1 -complete=customlist,CustomComplete1 Test1 echo
:call feedkeys(":Test1 \<C-L>'\<C-B>$put='\<CR>", 'it')
:"
:function! CustomComplete2(lead, line, pos)
: return ['あたし', 'あたま', 'あたりめ']
:endfunction
:command -nargs=1 -complete=customlist,CustomComplete2 Test2 echo
:call feedkeys(":Test2 \<C-L>'\<C-B>$put='\<CR>", 'it')
:"
:function! CustomComplete3(lead, line, pos)
: return ['Nこ', 'Nん', 'Nぶ']
:endfunction
:command -nargs=1 -complete=customlist,CustomComplete3 Test3 echo
:call feedkeys(":Test3 \<C-L>'\<C-B>$put='\<CR>", 'it')
:"
:call garbagecollect(1)
:/^start:/,$wq! test.out
ENDTEST
start:

View File

@@ -1,22 +0,0 @@
start:
axaa
xあああ
bxbb
1
1
1
3
3
3
2
2
1
3
3
1
1
1
1
Test1
Test2 あた
Test3 N

65
src/testdir/test_utf8.vim Normal file
View File

@@ -0,0 +1,65 @@
" Tests for Unicode manipulations
if !has('multi_byte')
finish
endif
" Visual block Insert adjusts for multi-byte char
func Test_visual_block_insert()
new
call setline(1, ["aaa", "あああ", "bbb"])
exe ":norm! gg0l\<C-V>jjIx\<Esc>"
call assert_equal(['axaa', 'xあああ', 'bxbb'], getline(1, '$'))
bwipeout!
endfunc
" Test for built-in function strchars()
func Test_strchars()
let inp = ["a", "あいa", "A\u20dd", "A\u20dd\u20dd", "\u20dd"]
let exp = [[1, 1, 1], [3, 3, 3], [2, 2, 1], [3, 3, 1], [1, 1, 1]]
for i in range(len(inp))
call assert_equal(exp[i][0], strchars(inp[i]))
call assert_equal(exp[i][1], strchars(inp[i], 0))
call assert_equal(exp[i][2], strchars(inp[i], 1))
endfor
endfunc
" Test for customlist completion
function! CustomComplete1(lead, line, pos)
return ['あ', 'い']
endfunction
function! CustomComplete2(lead, line, pos)
return ['あたし', 'あたま', 'あたりめ']
endfunction
function! CustomComplete3(lead, line, pos)
return ['Nこ', 'Nん', 'Nぶ']
endfunction
func Test_customlist_completion()
command -nargs=1 -complete=customlist,CustomComplete1 Test1 echo
call feedkeys(":Test1 \<C-L>\<C-B>\"\<CR>", 'itx')
call assert_equal('"Test1 ', getreg(':'))
command -nargs=1 -complete=customlist,CustomComplete2 Test2 echo
call feedkeys(":Test2 \<C-L>\<C-B>\"\<CR>", 'itx')
call assert_equal('"Test2 あた', getreg(':'))
command -nargs=1 -complete=customlist,CustomComplete3 Test3 echo
call feedkeys(":Test3 \<C-L>\<C-B>\"\<CR>", 'itx')
call assert_equal('"Test3 N', getreg(':'))
call garbagecollect(1)
endfunc
" Yank one 3 byte character and check the mark columns.
func Test_getvcol()
new
call setline(1, "x\u2500x")
normal 0lvy
call assert_equal(2, col("'["))
call assert_equal(4, col("']"))
call assert_equal(2, virtcol("'["))
call assert_equal(2, virtcol("']"))
endfunc

View File

@@ -2102,7 +2102,9 @@ ex_function(exarg_T *eap)
arg = skipwhite(skiptowhite(p));
if (arg[0] == '<' && arg[1] =='<'
&& ((p[0] == 'p' && p[1] == 'y'
&& (!ASCII_ISALPHA(p[2]) || p[2] == 't'))
&& (!ASCII_ISALNUM(p[2]) || p[2] == 't'
|| ((p[2] == '3' || p[2] == 'x')
&& !ASCII_ISALPHA(p[3]))))
|| (p[0] == 'p' && p[1] == 'e'
&& (!ASCII_ISALPHA(p[2]) || p[2] == 'r'))
|| (p[0] == 't' && p[1] == 'c'

View File

@@ -764,6 +764,36 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
254,
/**/
253,
/**/
252,
/**/
251,
/**/
250,
/**/
249,
/**/
248,
/**/
247,
/**/
246,
/**/
245,
/**/
244,
/**/
243,
/**/
242,
/**/
241,
/**/
240,
/**/
239,
/**/

View File

@@ -1714,15 +1714,8 @@ typedef unsigned short disptick_T; /* display tick type */
typedef void *vim_acl_T; /* dummy to pass an ACL to a function */
/*
* Include a prototype for mch_memmove(), it may not be in alloc.pro.
*/
#ifdef VIM_MEMMOVE
void mch_memmove(void *, void *, size_t);
#else
# ifndef mch_memmove
# define mch_memmove(to, from, len) memmove(to, from, len)
# endif
#ifndef mch_memmove
# define mch_memmove(to, from, len) memmove((char*)(to), (char*)(from), (size_t)(len))
#endif
/*