aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml4
-rw-r--r--appveyor.yml2
-rw-r--r--busted/outputHandlers/nvim.lua305
-rw-r--r--ci/build.bat2
-rw-r--r--runtime/doc/eval.txt41
-rw-r--r--runtime/doc/options.txt51
-rw-r--r--src/nvim/charset.c72
-rw-r--r--src/nvim/edit.c25
-rw-r--r--src/nvim/eval.c28
-rw-r--r--src/nvim/eval/typval.c14
-rw-r--r--src/nvim/event/libuv_process.c8
-rw-r--r--src/nvim/ex_getln.c5
-rw-r--r--src/nvim/file_search.c2
-rw-r--r--src/nvim/getchar.c4
-rw-r--r--src/nvim/indent.c3
-rw-r--r--src/nvim/indent_c.c1
-rw-r--r--src/nvim/macros.h25
-rw-r--r--src/nvim/mark.h40
-rw-r--r--src/nvim/mbyte.c31
-rw-r--r--src/nvim/memory.c7
-rw-r--r--src/nvim/message.c6
-rw-r--r--src/nvim/misc1.c6
-rw-r--r--src/nvim/ops.c28
-rw-r--r--src/nvim/option.c2
-rw-r--r--src/nvim/options.lua6
-rw-r--r--src/nvim/os/env.c22
-rw-r--r--src/nvim/os/fileio.c2
-rw-r--r--src/nvim/os/shell.c4
-rw-r--r--src/nvim/path.c6
-rw-r--r--src/nvim/regexp.c45
-rw-r--r--src/nvim/regexp_nfa.c32
-rw-r--r--src/nvim/screen.c1
-rw-r--r--src/nvim/search.c25
-rw-r--r--src/nvim/spell.c45
-rw-r--r--src/nvim/spell_defs.h4
-rw-r--r--src/nvim/spellfile.c146
-rw-r--r--src/nvim/strings.c87
-rw-r--r--src/nvim/syntax.c124
-rw-r--r--src/nvim/testdir/test_functions.vim144
-rw-r--r--src/nvim/testdir/test_normal.vim46
-rw-r--r--test/benchmark/bench_re_freeze_spec.lua21
-rw-r--r--test/functional/eval/system_spec.lua108
-rw-r--r--test/functional/ex_cmds/file_spec.lua35
-rw-r--r--test/functional/ex_cmds/recover_spec.lua41
-rw-r--r--test/functional/ex_cmds/syntax_spec.lua17
-rw-r--r--test/functional/helpers.lua36
-rw-r--r--test/functional/insert/ctrl_r_spec.lua19
-rw-r--r--test/functional/normal/lang_spec.lua63
-rw-r--r--test/functional/spell/spellfile_spec.lua110
-rw-r--r--test/functional/terminal/edit_spec.lua5
-rw-r--r--test/functional/ui/inccommand_spec.lua24
-rw-r--r--test/functional/ui/screen.lua19
-rw-r--r--test/helpers.lua9
-rw-r--r--test/unit/os/env_spec.lua27
-rw-r--r--third-party/cmake/BuildLuarocks.cmake2
55 files changed, 1419 insertions, 568 deletions
diff --git a/.travis.yml b/.travis.yml
index b8c4c0172f..1f00b5c880 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -25,7 +25,7 @@ env:
- CMAKE_FLAGS="-DTRAVIS_CI_BUILD=ON
-DCMAKE_BUILD_TYPE=Debug
-DCMAKE_INSTALL_PREFIX:PATH=$INSTALL_PREFIX
- -DBUSTED_OUTPUT_TYPE=gtest
+ -DBUSTED_OUTPUT_TYPE=nvim
-DDEPS_PREFIX=$DEPS_BUILD_DIR/usr
-DMIN_LOG_LEVEL=2"
- DEPS_CMAKE_FLAGS="-DDEPS_DOWNLOAD_DIR:PATH=$DEPS_DOWNLOAD_DIR"
@@ -104,9 +104,11 @@ addons:
- gcc-5-multilib
- gcc-multilib
- gdb
+ - language-pack-tr
- libc6-dev-i386
- libtool
- llvm-3.9-dev
+ - locales
- pkg-config
- unzip
- valgrind
diff --git a/appveyor.yml b/appveyor.yml
index 091e86583a..edb679d223 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -7,7 +7,7 @@ build_script:
- call ci\build.bat
cache:
- C:\msys64\var\cache\pacman\pkg -> ci\build.bat
-- .deps -> third-party/CMakeLists.txt
+- .deps -> third-party\**
artifacts:
- path: build/Neovim.zip
- path: build/bin/nvim.exe
diff --git a/busted/outputHandlers/nvim.lua b/busted/outputHandlers/nvim.lua
new file mode 100644
index 0000000000..b612ead070
--- /dev/null
+++ b/busted/outputHandlers/nvim.lua
@@ -0,0 +1,305 @@
+local s = require 'say'
+local pretty = require 'pl.pretty'
+local term = require 'term'
+
+local colors
+
+local isWindows = package.config:sub(1,1) == '\\'
+
+if isWindows then
+ colors = setmetatable({}, {__index = function() return function(s) return s end end})
+else
+ colors = require 'term.colors'
+end
+
+return function(options)
+ local busted = require 'busted'
+ local handler = require 'busted.outputHandlers.base'()
+
+ local c = {
+ succ = function(s) return colors.bright(colors.green(s)) end,
+ skip = function(s) return colors.bright(colors.yellow(s)) end,
+ fail = function(s) return colors.bright(colors.magenta(s)) end,
+ errr = function(s) return colors.bright(colors.red(s)) end,
+ test = tostring,
+ file = colors.cyan,
+ time = colors.dim,
+ note = colors.yellow,
+ sect = function(s) return colors.green(colors.dim(s)) end,
+ nmbr = colors.bright,
+ }
+
+ local repeatSuiteString = '\nRepeating all tests (run %d of %d) . . .\n\n'
+ local randomizeString = c.note('Note: Randomizing test order with a seed of %d.\n')
+ local globalSetup = c.sect('[----------]') .. ' Global test environment setup.\n'
+ local fileStartString = c.sect('[----------]') .. ' Running tests from ' .. c.file('%s') .. '\n'
+ local runString = c.sect('[ RUN ]') .. ' ' .. c.test('%s') .. ': '
+ local successString = c.succ('OK') .. '\n'
+ local skippedString = c.skip('SKIP') .. '\n'
+ local failureString = c.fail('FAIL') .. '\n'
+ local errorString = c.errr('ERR') .. '\n'
+ local fileEndString = c.sect('[----------]') .. ' '.. c.nmbr('%d') .. ' %s from ' .. c.file('%s') .. ' ' .. c.time('(%.2f ms total)') .. '\n\n'
+ local globalTeardown = c.sect('[----------]') .. ' Global test environment teardown.\n'
+ local suiteEndString = c.sect('[==========]') .. ' ' .. c.nmbr('%d') .. ' %s from ' .. c.nmbr('%d') .. ' test %s ran. ' .. c.time('(%.2f ms total)') .. '\n'
+ local successStatus = c.succ('[ PASSED ]') .. ' ' .. c.nmbr('%d') .. ' %s.\n'
+ local timeString = c.time('%.2f ms')
+
+ local summaryStrings = {
+ skipped = {
+ header = c.skip('[ SKIPPED ]') .. ' ' .. c.nmbr('%d') .. ' %s, listed below:\n',
+ test = c.skip('[ SKIPPED ]') .. ' %s\n',
+ footer = ' ' .. c.nmbr('%d') .. ' SKIPPED %s\n',
+ },
+
+ failure = {
+ header = c.fail('[ FAILED ]') .. ' ' .. c.nmbr('%d') .. ' %s, listed below:\n',
+ test = c.fail('[ FAILED ]') .. ' %s\n',
+ footer = ' ' .. c.nmbr('%d') .. ' FAILED %s\n',
+ },
+
+ error = {
+ header = c.errr('[ ERROR ]') .. ' ' .. c.nmbr('%d') .. ' %s, listed below:\n',
+ test = c.errr('[ ERROR ]') .. ' %s\n',
+ footer = ' ' .. c.nmbr('%d') .. ' %s\n',
+ },
+ }
+
+ c = nil
+
+ local fileCount = 0
+ local fileTestCount = 0
+ local testCount = 0
+ local successCount = 0
+ local skippedCount = 0
+ local failureCount = 0
+ local errorCount = 0
+
+ local pendingDescription = function(pending)
+ local name = pending.name
+ local string = ''
+
+ if type(pending.message) == 'string' then
+ string = string .. pending.message .. '\n'
+ elseif pending.message ~= nil then
+ string = string .. pretty.write(pending.message) .. '\n'
+ end
+
+ return string
+ end
+
+ local failureDescription = function(failure)
+ local string = failure.randomseed and ('Random seed: ' .. failure.randomseed .. '\n') or ''
+ if type(failure.message) == 'string' then
+ string = string .. failure.message
+ elseif failure.message == nil then
+ string = string .. 'Nil error'
+ else
+ string = string .. pretty.write(failure.message)
+ end
+
+ string = string .. '\n'
+
+ if options.verbose and failure.trace and failure.trace.traceback then
+ string = string .. failure.trace.traceback .. '\n'
+ end
+
+ return string
+ end
+
+ local getFileLine = function(element)
+ local fileline = ''
+ if element.trace or element.trace.short_src then
+ fileline = colors.cyan(element.trace.short_src) .. ' @ ' ..
+ colors.cyan(element.trace.currentline) .. ': '
+ end
+ return fileline
+ end
+
+ local getTestList = function(status, count, list, getDescription)
+ local string = ''
+ local header = summaryStrings[status].header
+ if count > 0 and header then
+ local tests = (count == 1 and 'test' or 'tests')
+ local errors = (count == 1 and 'error' or 'errors')
+ string = header:format(count, status == 'error' and errors or tests)
+
+ local testString = summaryStrings[status].test
+ if testString then
+ for _, t in ipairs(list) do
+ local fullname = getFileLine(t.element) .. colors.bright(t.name)
+ string = string .. testString:format(fullname)
+ string = string .. getDescription(t)
+ end
+ end
+ end
+ return string
+ end
+
+ local getSummary = function(status, count)
+ local string = ''
+ local footer = summaryStrings[status].footer
+ if count > 0 and footer then
+ local tests = (count == 1 and 'TEST' or 'TESTS')
+ local errors = (count == 1 and 'ERROR' or 'ERRORS')
+ string = footer:format(count, status == 'error' and errors or tests)
+ end
+ return string
+ end
+
+ local getSummaryString = function()
+ local tests = (successCount == 1 and 'test' or 'tests')
+ local string = successStatus:format(successCount, tests)
+
+ string = string .. getTestList('skipped', skippedCount, handler.pendings, pendingDescription)
+ string = string .. getTestList('failure', failureCount, handler.failures, failureDescription)
+ string = string .. getTestList('error', errorCount, handler.errors, failureDescription)
+
+ string = string .. ((skippedCount + failureCount + errorCount) > 0 and '\n' or '')
+ string = string .. getSummary('skipped', skippedCount)
+ string = string .. getSummary('failure', failureCount)
+ string = string .. getSummary('error', errorCount)
+
+ return string
+ end
+
+ handler.suiteReset = function()
+ fileCount = 0
+ fileTestCount = 0
+ testCount = 0
+ successCount = 0
+ skippedCount = 0
+ failureCount = 0
+ errorCount = 0
+
+ return nil, true
+ end
+
+ handler.suiteStart = function(suite, count, total, randomseed)
+ if total > 1 then
+ io.write(repeatSuiteString:format(count, total))
+ end
+ if randomseed then
+ io.write(randomizeString:format(randomseed))
+ end
+ io.write(globalSetup)
+ io.flush()
+
+ return nil, true
+ end
+
+ local function getElapsedTime(tbl)
+ if tbl.duration then
+ return tbl.duration * 1000
+ else
+ return tonumber('nan')
+ end
+ end
+
+ handler.suiteEnd = function(suite, count, total)
+ local elapsedTime_ms = getElapsedTime(suite)
+ local tests = (testCount == 1 and 'test' or 'tests')
+ local files = (fileCount == 1 and 'file' or 'files')
+ io.write(globalTeardown)
+ io.write(suiteEndString:format(testCount, tests, fileCount, files, elapsedTime_ms))
+ io.write(getSummaryString())
+ io.flush()
+
+ return nil, true
+ end
+
+ handler.fileStart = function(file)
+ fileTestCount = 0
+ io.write(fileStartString:format(file.name))
+ io.flush()
+ return nil, true
+ end
+
+ handler.fileEnd = function(file)
+ local elapsedTime_ms = getElapsedTime(file)
+ local tests = (fileTestCount == 1 and 'test' or 'tests')
+ fileCount = fileCount + 1
+ io.write(fileEndString:format(fileTestCount, tests, file.name, elapsedTime_ms))
+ io.flush()
+ return nil, true
+ end
+
+ handler.testStart = function(element, parent)
+ io.write(runString:format(handler.getFullName(element)))
+ io.flush()
+
+ return nil, true
+ end
+
+ handler.testEnd = function(element, parent, status, debug)
+ local elapsedTime_ms = getElapsedTime(element)
+ local string
+
+ fileTestCount = fileTestCount + 1
+ testCount = testCount + 1
+ if status == 'success' then
+ successCount = successCount + 1
+ string = successString
+ elseif status == 'pending' then
+ skippedCount = skippedCount + 1
+ string = skippedString
+ elseif status == 'failure' then
+ failureCount = failureCount + 1
+ string = nil
+ elseif status == 'error' then
+ errorCount = errorCount + 1
+ string = nil
+ end
+
+ if string ~= nil then
+ if elapsedTime_ms == elapsedTime_ms then
+ string = timeString:format(elapsedTime_ms) .. ' ' .. string
+ end
+ io.write(string)
+ io.flush()
+ end
+
+ return nil, true
+ end
+
+ handler.testFailure = function(element, parent, message, debug)
+ io.write(failureString)
+ io.flush()
+
+ io.write(failureDescription(handler.failures[#handler.failures]))
+ io.flush()
+ return nil, true
+ end
+
+ handler.testError = function(element, parent, message, debug)
+ io.write(errorString)
+ io.flush()
+
+ io.write(failureDescription(handler.errors[#handler.errors]))
+ io.flush()
+ return nil, true
+ end
+
+ handler.error = function(element, parent, message, debug)
+ if element.descriptor ~= 'it' then
+ io.write(failureDescription(handler.errors[#handler.errors]))
+ io.flush()
+ errorCount = errorCount + 1
+ end
+
+ return nil, true
+ end
+
+ busted.subscribe({ 'suite', 'reset' }, handler.suiteReset)
+ busted.subscribe({ 'suite', 'start' }, handler.suiteStart)
+ busted.subscribe({ 'suite', 'end' }, handler.suiteEnd)
+ busted.subscribe({ 'file', 'start' }, handler.fileStart)
+ busted.subscribe({ 'file', 'end' }, handler.fileEnd)
+ busted.subscribe({ 'test', 'start' }, handler.testStart, { predicate = handler.cancelOnPending })
+ busted.subscribe({ 'test', 'end' }, handler.testEnd, { predicate = handler.cancelOnPending })
+ busted.subscribe({ 'failure', 'it' }, handler.testFailure)
+ busted.subscribe({ 'error', 'it' }, handler.testError)
+ busted.subscribe({ 'failure' }, handler.error)
+ busted.subscribe({ 'error' }, handler.error)
+
+ return handler
+end
diff --git a/ci/build.bat b/ci/build.bat
index 87a171b994..9071c0864e 100644
--- a/ci/build.bat
+++ b/ci/build.bat
@@ -38,7 +38,7 @@ cd ..
:: Build Neovim
mkdir build
cd build
-cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DBUSTED_OUTPUT_TYPE=gtest -DGPERF_PRG="C:\msys64\usr\bin\gperf.exe" .. || goto :error
+cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DBUSTED_OUTPUT_TYPE=nvim -DGPERF_PRG="C:\msys64\usr\bin\gperf.exe" .. || goto :error
mingw32-make VERBOSE=1 || goto :error
bin\nvim --version || goto :error
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 16f9a2ea6e..77db2699f8 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -1524,13 +1524,18 @@ v:errors Errors found by assert functions, such as |assert_true()|.
list by the assert function.
*v:event* *event-variable*
-v:event Dictionary of event data for the current |autocommand|. The
- available keys differ per event type and are specified at the
- documentation for each |event|. The possible keys are:
- operator The operation performed. Unlike
- |v:operator|, it is set also for an Ex
- mode command. For instance, |:yank| is
- translated to "|y|".
+v:event Dictionary of event data for the current |autocommand|. Valid
+ only during the autocommand lifetime: storing or passing
+ `v:event` is invalid. Copy it instead: >
+ au TextYankPost * let g:foo = deepcopy(v:event)
+< Keys vary by event; see the documentation for the specific
+ event, e.g. |TextYankPost|.
+ KEY DESCRIPTION ~
+ operator The current |operator|. Also set for
+ Ex commands (unlike |v:operator|). For
+ example if |TextYankPost| is triggered
+ by the |:yank| Ex command then
+ `v:event['operator']` is "y".
regcontents Text stored in the register as a
|readfile()|-style list of lines.
regname Requested register (e.g "x" for "xyy)
@@ -4847,16 +4852,18 @@ jobstart({cmd}[, {opts}]) {Nvim} *jobstart()*
Spawns {cmd} as a job. If {cmd} is a |List| it is run
directly. If {cmd} is a |String| it is processed like this: >
:call jobstart(split(&shell) + split(&shellcmdflag) + ['{cmd}'])
-< NOTE: This only shows the idea; see |shell-unquoting| before
- constructing lists with 'shell' or 'shellcmdflag'.
-
- NOTE: On Windows if {cmd} is a List, cmd[0] must be a valid
- executable (.exe, .com). If the executable is in $PATH it can
- be called by name, with or without an extension: >
- :call jobstart(['ping', 'neovim.io'])
-< If it is a path (not a name), it must include the extension: >
- :call jobstart(['System32\ping.exe', 'neovim.io'])
-<
+< (Only shows the idea; see |shell-unquoting| for full details.)
+
+ NOTE: on Windows if {cmd} is a List:
+ - cmd[0] must be an executable (not a "built-in"). If it is
+ in $PATH it can be called by name, without an extension: >
+ :call jobstart(['ping', 'neovim.io'])
+< If it is a full or partial path, extension is required: >
+ :call jobstart(['System32\ping.exe', 'neovim.io'])
+< - {cmd} is collapsed to a string of quoted args as expected
+ by CommandLineToArgvW https://msdn.microsoft.com/bb776391
+ unless cmd[0] is some form of "cmd.exe".
+
{opts} is a dictionary with these keys:
on_stdout: stdout event handler (function name or |Funcref|)
on_stderr: stderr event handler (function name or |Funcref|)
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index c30a88f48d..9be7dae84d 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -2765,8 +2765,7 @@ A jump table for the options with a short description can be found at |Q_op|.
*'grepprg'* *'gp'*
'grepprg' 'gp' string (default "grep -n ",
- Unix: "grep -n $* /dev/null",
- Win32: "findstr /n" or "grep -n")
+ Unix: "grep -n $* /dev/null")
global or local to buffer |global-local|
Program to use for the |:grep| command. This option may contain '%'
and '#' characters, which are expanded like when used in a command-
@@ -2781,8 +2780,6 @@ A jump table for the options with a short description can be found at |Q_op|.
|:vimgrepadd| and |:lgrepadd| like |:lvimgrepadd|.
See also the section |:make_makeprg|, since most of the comments there
apply equally to 'grepprg'.
- For Win32, the default is "findstr /n" if "findstr.exe" can be found,
- otherwise it's "grep -n".
This option cannot be set from a |modeline| or in the |sandbox|, for
security reasons.
@@ -5251,9 +5248,7 @@ A jump table for the options with a short description can be found at |Q_op|.
security reasons.
*'shellcmdflag'* *'shcf'*
-'shellcmdflag' 'shcf' string (default: "-c";
- Windows, when 'shell' does not
- contain "sh" somewhere: "/c")
+'shellcmdflag' 'shcf' string (default: "-c"; Windows: "/c")
global
Flag passed to the shell to execute "!" and ":!" commands; e.g.,
"bash.exe -c ls" or "cmd.exe /c dir". For Windows
@@ -5264,15 +5259,12 @@ A jump table for the options with a short description can be found at |Q_op|.
See |option-backslash| about including spaces and backslashes.
See |shell-unquoting| which talks about separating this option into
multiple arguments.
- Also see |dos-shell| for Windows.
This option cannot be set from a |modeline| or in the |sandbox|, for
security reasons.
*'shellpipe'* *'sp'*
'shellpipe' 'sp' string (default ">", "| tee", "|& tee" or "2>&1| tee")
global
- {not available when compiled without the |+quickfix|
- feature}
String to be used to put the output of the ":make" command in the
error file. See also |:make_makeprg|. See |option-backslash| about
including spaces and backslashes.
@@ -5314,7 +5306,7 @@ A jump table for the options with a short description can be found at |Q_op|.
third-party shells on Windows systems, such as the MKS Korn Shell
or bash, where it should be "\"". The default is adjusted according
the value of 'shell', to reduce the need to set this option by the
- user. See |dos-shell|.
+ user.
This option cannot be set from a |modeline| or in the |sandbox|, for
security reasons.
@@ -5346,7 +5338,7 @@ A jump table for the options with a short description can be found at |Q_op|.
*'shellslash'* *'ssl'* *'noshellslash'* *'nossl'*
'shellslash' 'ssl' boolean (default off)
global
- {only for MSDOS and MS-Windows}
+ {only for Windows}
When set, a forward slash is used when expanding file names. This is
useful when a Unix-like shell is used instead of command.com or
cmd.exe. Backward slashes can still be typed, but they are changed to
@@ -5363,10 +5355,7 @@ A jump table for the options with a short description can be found at |Q_op|.
global
When on, use temp files for shell commands. When off use a pipe.
When using a pipe is not possible temp files are used anyway.
- Currently a pipe is only supported on Unix and MS-Windows 2K and
- later. You can check it with: >
- :if has("filterpipe")
-< The advantage of using a pipe is that nobody can read the temp file
+ The advantage of using a pipe is that nobody can read the temp file
and the 'shell' command does not need to support redirection.
The advantage of using a temp file is that the file type and encoding
can be detected.
@@ -5376,19 +5365,14 @@ A jump table for the options with a short description can be found at |Q_op|.
|system()| does not respect this option, it always uses pipes.
*'shellxescape'* *'sxe'*
-'shellxescape' 'sxe' string (default: "";
- for Windows: "\"&|<>()@^")
+'shellxescape' 'sxe' string (default: "")
global
When 'shellxquote' is set to "(" then the characters listed in this
option will be escaped with a '^' character. This makes it possible
to execute most external commands with cmd.exe.
*'shellxquote'* *'sxq'*
-'shellxquote' 'sxq' string (default: "";
- for Win32, when 'shell' is cmd.exe: "("
- for Win32, when 'shell' contains "sh"
- somewhere: "\""
- for Unix, when using system(): "\"")
+'shellxquote' 'sxq' string (default: "")
global
Quoting character(s), put around the command passed to the shell, for
the "!" and ":!" commands. Includes the redirection. See
@@ -5397,12 +5381,6 @@ A jump table for the options with a short description can be found at |Q_op|.
When the value is '(' then ')' is appended. When the value is '"('
then ')"' is appended.
When the value is '(' then also see 'shellxescape'.
- This is an empty string by default on most systems, but is known to be
- useful for on Win32 version, either for cmd.exe which automatically
- strips off the first and last quote on a command, or 3rd-party shells
- such as the MKS Korn Shell or bash, where it should be "\"". The
- default is adjusted according the value of 'shell', to reduce the need
- to set this option by the user. See |dos-shell|.
This option cannot be set from a |modeline| or in the |sandbox|, for
security reasons.
@@ -6413,8 +6391,6 @@ A jump table for the options with a short description can be found at |Q_op|.
*'title'* *'notitle'*
'title' boolean (default off, on when title can be restored)
global
- {not available when compiled without the |+title|
- feature}
When on, the title of the window will be set to the value of
'titlestring' (if it is not empty), or to:
filename [+=-] (path) - VIM
@@ -6426,16 +6402,10 @@ A jump table for the options with a short description can be found at |Q_op|.
=+ indicates the file is read-only and modified
(path) is the path of the file being edited
- VIM the server name |v:servername| or "VIM"
- Only works if the terminal supports setting window titles
- (currently Win32 console, all GUI versions and terminals with a non-
- empty 't_ts' option - this is Unix xterm by default, where 't_ts' is
- taken from the builtin termcap).
*'titlelen'*
'titlelen' number (default 85)
global
- {not available when compiled without the |+title|
- feature}
Gives the percentage of 'columns' to use for the length of the window
title. When the title is longer, only the end of the path name is
shown. A '<' character before the path name is used to indicate this.
@@ -6449,8 +6419,6 @@ A jump table for the options with a short description can be found at |Q_op|.
*'titleold'*
'titleold' string (default "Thanks for flying Vim")
global
- {only available when compiled with the |+title|
- feature}
This option will be used for the window title when exiting Vim if the
original title cannot be restored. Only happens if 'title' is on or
'titlestring' is not empty.
@@ -6459,13 +6427,8 @@ A jump table for the options with a short description can be found at |Q_op|.
*'titlestring'*
'titlestring' string (default "")
global
- {not available when compiled without the |+title|
- feature}
When this option is not empty, it will be used for the title of the
window. This happens only when the 'title' option is on.
- Only works if the terminal supports setting window titles (currently
- Win32 console, all GUI versions and terminals with a non-empty 't_ts'
- option).
When this option contains printf-style '%' items, they will be
expanded according to the rules used for 'statusline'.
Example: >
diff --git a/src/nvim/charset.c b/src/nvim/charset.c
index 99d3e2dd88..3037cfe669 100644
--- a/src/nvim/charset.c
+++ b/src/nvim/charset.c
@@ -15,6 +15,7 @@
#include "nvim/func_attr.h"
#include "nvim/indent.h"
#include "nvim/main.h"
+#include "nvim/mark.h"
#include "nvim/mbyte.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
@@ -212,8 +213,8 @@ int buf_init_chartab(buf_T *buf, int global)
// work properly when 'encoding' is "latin1" and the locale is
// "C".
if (!do_isalpha
- || vim_islower(c)
- || vim_isupper(c)
+ || mb_islower(c)
+ || mb_isupper(c)
|| (p_altkeymap && (F_isalpha(c) || F_isdigit(c)))) {
if (i == 0) {
// (re)set ID flag
@@ -417,11 +418,11 @@ char_u* str_foldcase(char_u *str, int orglen, char_u *buf, int buflen)
while (STR_CHAR(i) != NUL) {
int c = utf_ptr2char(STR_PTR(i));
int olen = utf_ptr2len(STR_PTR(i));
- int lc = utf_tolower(c);
+ int lc = mb_tolower(c);
// Only replace the character when it is not an invalid
// sequence (ASCII character or more than one byte) and
- // utf_tolower() doesn't return the original character.
+ // mb_tolower() doesn't return the original character.
if (((c < 0x80) || (olen > 1)) && (c != lc)) {
int nlen = utf_char2len(lc);
@@ -1366,7 +1367,7 @@ void getvcols(win_T *wp, pos_T *pos1, pos_T *pos2, colnr_T *left,
colnr_T to1;
colnr_T to2;
- if (ltp(pos1, pos2)) {
+ if (lt(*pos1, *pos2)) {
getvvcol(wp, pos1, &from1, NULL, &to1);
getvvcol(wp, pos2, &from2, NULL, &to2);
} else {
@@ -1506,67 +1507,6 @@ char_u* skiptohex(char_u *q)
return p;
}
-// Vim's own character class functions. These exist because many library
-// islower()/toupper() etc. do not work properly: they crash when used with
-// invalid values or can't handle latin1 when the locale is C.
-// Speed is most important here.
-
-/// Check that the character is lower-case
-///
-/// @param c character to check
-bool vim_islower(int c)
- FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
-{
- if (c <= '@') {
- return false;
- }
-
- if (c >= 0x80) {
- return utf_islower(c);
- }
- return islower(c);
-}
-
-/// Check that the character is upper-case
-///
-/// @param c character to check
-bool vim_isupper(int c)
- FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
-{
- if (c <= '@') {
- return false;
- }
-
- if (c >= 0x80) {
- return utf_isupper(c);
- }
- return isupper(c);
-}
-
-int vim_toupper(int c)
-{
- if (c <= '@') {
- return c;
- }
-
- if (c >= 0x80) {
- return utf_toupper(c);
- }
- return TOUPPER_LOC(c);
-}
-
-int vim_tolower(int c)
-{
- if (c <= '@') {
- return c;
- }
-
- if (c >= 0x80) {
- return utf_tolower(c);
- }
- return TOLOWER_LOC(c);
-}
-
/// Skip over text until ' ' or '\t' or NUL
///
/// @param[in] p Text to skip over.
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index b35504908e..fe00027dec 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -2037,12 +2037,12 @@ int ins_compl_add_infercase(char_u *str, int len, int icase, char_u *fname, int
} else {
c = *(p++);
}
- if (vim_islower(c)) {
+ if (mb_islower(c)) {
has_lower = true;
- if (vim_isupper(wca[i])) {
+ if (mb_isupper(wca[i])) {
// Rule 1 is satisfied.
for (i = actual_compl_length; i < actual_len; i++) {
- wca[i] = vim_tolower(wca[i]);
+ wca[i] = mb_tolower(wca[i]);
}
break;
}
@@ -2062,14 +2062,14 @@ int ins_compl_add_infercase(char_u *str, int len, int icase, char_u *fname, int
} else {
c = *(p++);
}
- if (was_letter && vim_isupper(c) && vim_islower(wca[i])) {
+ if (was_letter && mb_isupper(c) && mb_islower(wca[i])) {
// Rule 2 is satisfied.
for (i = actual_compl_length; i < actual_len; i++) {
- wca[i] = vim_toupper(wca[i]);
+ wca[i] = mb_toupper(wca[i]);
}
break;
}
- was_letter = vim_islower(c) || vim_isupper(c);
+ was_letter = mb_islower(c) || mb_isupper(c);
}
}
@@ -2082,10 +2082,10 @@ int ins_compl_add_infercase(char_u *str, int len, int icase, char_u *fname, int
} else {
c = *(p++);
}
- if (vim_islower(c)) {
- wca[i] = vim_tolower(wca[i]);
- } else if (vim_isupper(c)) {
- wca[i] = vim_toupper(wca[i]);
+ if (mb_islower(c)) {
+ wca[i] = mb_tolower(wca[i]);
+ } else if (mb_isupper(c)) {
+ wca[i] = mb_toupper(wca[i]);
}
}
}
@@ -2302,9 +2302,10 @@ static void ins_compl_longest_match(compl_T *match)
c1 = *p;
c2 = *s;
}
- if (match->cp_icase ? (vim_tolower(c1) != vim_tolower(c2))
- : (c1 != c2))
+ if (match->cp_icase ? (mb_tolower(c1) != mb_tolower(c2))
+ : (c1 != c2)) {
break;
+ }
if (has_mbyte) {
mb_ptr_adv(p);
mb_ptr_adv(s);
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 124d6acfe9..0663e19b9a 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -16791,30 +16791,9 @@ void timer_teardown(void)
*/
static void f_tolower(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
- char_u *p = (char_u *)xstrdup(tv_get_string(&argvars[0]));
rettv->v_type = VAR_STRING;
- rettv->vval.v_string = p;
-
- while (*p != NUL) {
- 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 {
- *p = TOLOWER_LOC(*p); /* note that tolower() can be a macro */
- ++p;
- }
- }
+ rettv->vval.v_string = (char_u *)strcase_save(tv_get_string(&argvars[0]),
+ false);
}
/*
@@ -16823,7 +16802,8 @@ static void f_tolower(typval_T *argvars, typval_T *rettv, FunPtr fptr)
static void f_toupper(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->v_type = VAR_STRING;
- rettv->vval.v_string = (char_u *)strup_save(tv_get_string(&argvars[0]));
+ rettv->vval.v_string = (char_u *)strcase_save(tv_get_string(&argvars[0]),
+ true);
}
/*
diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c
index 779bb18175..70ec3dfe39 100644
--- a/src/nvim/eval/typval.c
+++ b/src/nvim/eval/typval.c
@@ -136,7 +136,7 @@ void tv_list_watch_fix(list_T *const l, const listitem_T *const item)
///
/// @return [allocated] new list.
list_T *tv_list_alloc(void)
- FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC
+ FUNC_ATTR_NONNULL_RET
{
list_T *const list = xcalloc(1, sizeof(list_T));
@@ -1011,7 +1011,6 @@ void tv_dict_item_free(dictitem_T *const item)
/// @return [allocated] new dictionary item.
static dictitem_T *tv_dict_item_copy(dictitem_T *const di)
FUNC_ATTR_NONNULL_RET FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
- FUNC_ATTR_MALLOC
{
dictitem_T *const new_di = tv_dict_item_alloc((const char *)di->di_key);
tv_copy(&di->di_tv, &new_di->di_tv);
@@ -1040,7 +1039,7 @@ void tv_dict_item_remove(dict_T *const dict, dictitem_T *const item)
///
/// @return [allocated] new dictionary.
dict_T *tv_dict_alloc(void)
- FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_WARN_UNUSED_RESULT
+ FUNC_ATTR_NONNULL_RET FUNC_ATTR_WARN_UNUSED_RESULT
{
dict_T *const d = xmalloc(sizeof(dict_T));
@@ -1577,7 +1576,7 @@ void tv_dict_set_keys_readonly(dict_T *const dict)
///
/// @return [allocated] pointer to the created list.
list_T *tv_list_alloc_ret(typval_T *const ret_tv)
- FUNC_ATTR_NONNULL_ALL FUNC_ATTR_MALLOC
+ FUNC_ATTR_NONNULL_ALL
{
list_T *const l = tv_list_alloc();
ret_tv->vval.v_list = l;
@@ -1837,9 +1836,12 @@ static inline void _nothing_conv_dict_end(typval_T *const tv,
/// @param[in,out] tv Value to free.
void tv_clear(typval_T *const tv)
{
+ static char *objname = NULL; // cached because gettext() is slow. #6437
+ if (objname == NULL) {
+ objname = xstrdup(_("tv_clear() argument"));
+ }
if (tv != NULL && tv->v_type != VAR_UNKNOWN) {
- const int evn_ret = encode_vim_to_nothing(NULL, tv,
- _("tv_clear() argument"));
+ const int evn_ret = encode_vim_to_nothing(NULL, tv, objname);
(void)evn_ret;
assert(evn_ret == OK);
}
diff --git a/src/nvim/event/libuv_process.c b/src/nvim/event/libuv_process.c
index 3da0c386b4..f5a41d151b 100644
--- a/src/nvim/event/libuv_process.c
+++ b/src/nvim/event/libuv_process.c
@@ -8,6 +8,7 @@
#include "nvim/event/process.h"
#include "nvim/event/libuv_process.h"
#include "nvim/log.h"
+#include "nvim/os/os.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "event/libuv_process.c.generated.h"
@@ -24,6 +25,13 @@ int libuv_process_spawn(LibuvProcess *uvproc)
if (proc->detach) {
uvproc->uvopts.flags |= UV_PROCESS_DETACHED;
}
+#ifdef WIN32
+ // libuv collapses the argv to a CommandLineToArgvW()-style string. cmd.exe
+ // expects a different syntax (must be prepared by the caller before now).
+ if (os_shell_is_cmdexe(proc->argv[0])) {
+ uvproc->uvopts.flags |= UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS;
+ }
+#endif
uvproc->uvopts.exit_cb = exit_cb;
uvproc->uvopts.cwd = proc->cwd;
uvproc->uvopts.env = NULL;
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index 8810204c03..0b6036ace9 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -30,6 +30,7 @@
#include "nvim/if_cscope.h"
#include "nvim/indent.h"
#include "nvim/main.h"
+#include "nvim/mark.h"
#include "nvim/mbyte.h"
#include "nvim/memline.h"
#include "nvim/menu.h"
@@ -1231,7 +1232,7 @@ static int command_line_handle_key(CommandLineState *s)
// command line has no uppercase characters, convert
// the character to lowercase
if (p_ic && p_scs && !pat_has_uppercase(ccline.cmdbuff)) {
- s->c = vim_tolower(s->c);
+ s->c = mb_tolower(s->c);
}
if (s->c != NUL) {
@@ -3018,7 +3019,7 @@ ExpandOne (
|| xp->xp_context == EXPAND_FILES
|| xp->xp_context == EXPAND_SHELLCMD
|| xp->xp_context == EXPAND_BUFFERS)) {
- if (vim_tolower(c0) != vim_tolower(ci)) {
+ if (mb_tolower(c0) != mb_tolower(ci)) {
break;
}
} else if (c0 != ci) {
diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c
index 9592235905..db745bdd15 100644
--- a/src/nvim/file_search.c
+++ b/src/nvim/file_search.c
@@ -1057,7 +1057,7 @@ static bool ff_wc_equal(char_u *s1, char_u *s2)
c1 = PTR2CHAR(s1 + i);
c2 = PTR2CHAR(s2 + j);
- if ((p_fic ? vim_tolower(c1) != vim_tolower(c2) : c1 != c2)
+ if ((p_fic ? mb_tolower(c1) != mb_tolower(c2) : c1 != c2)
&& (prev1 != '*' || prev2 != '*')) {
return false;
}
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c
index b83681ad01..3b248c4bc6 100644
--- a/src/nvim/getchar.c
+++ b/src/nvim/getchar.c
@@ -302,13 +302,13 @@ static void add_num_buff(buffheader_T *buf, long n)
*/
static void add_char_buff(buffheader_T *buf, int c)
{
- char bytes[MB_MAXBYTES + 1];
+ uint8_t bytes[MB_MAXBYTES + 1];
int len;
if (IS_SPECIAL(c)) {
len = 1;
} else {
- len = (*mb_char2bytes)(c, (char_u *)bytes);
+ len = mb_char2bytes(c, bytes);
}
for (int i = 0; i < len; i++) {
diff --git a/src/nvim/indent.c b/src/nvim/indent.c
index 7f31bb8c5c..8fbad38495 100644
--- a/src/nvim/indent.c
+++ b/src/nvim/indent.c
@@ -7,6 +7,7 @@
#include "nvim/eval.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
+#include "nvim/mark.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/misc1.h"
@@ -598,7 +599,7 @@ int get_lisp_indent(void)
paren = *pos;
pos = findmatch(NULL, '[');
- if ((pos == NULL) || ltp(pos, &paren)) {
+ if ((pos == NULL) || lt(*pos, paren)) {
pos = &paren;
}
}
diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c
index 4a73fbaf61..8f5547544d 100644
--- a/src/nvim/indent_c.c
+++ b/src/nvim/indent_c.c
@@ -10,6 +10,7 @@
#include "nvim/edit.h"
#include "nvim/indent.h"
#include "nvim/indent_c.h"
+#include "nvim/mark.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/option.h"
diff --git a/src/nvim/macros.h b/src/nvim/macros.h
index a8df6322cf..b816b34b39 100644
--- a/src/nvim/macros.h
+++ b/src/nvim/macros.h
@@ -29,25 +29,6 @@
#define S_LEN(s) (s), (sizeof(s) - 1)
/*
- * Position comparisons
- */
-# define lt(a, b) (((a).lnum != (b).lnum) \
- ? (a).lnum < (b).lnum \
- : (a).col != (b).col \
- ? (a).col < (b).col \
- : (a).coladd < (b).coladd)
-# define ltp(a, b) (((a)->lnum != (b)->lnum) \
- ? (a)->lnum < (b)->lnum \
- : (a)->col != (b)->col \
- ? (a)->col < (b)->col \
- : (a)->coladd < (b)->coladd)
-# define equalpos(a, b) (((a).lnum == (b).lnum) && ((a).col == (b).col) && \
- ((a).coladd == (b).coladd))
-# define clearpos(a) {(a)->lnum = 0; (a)->col = 0; (a)->coladd = 0; }
-
-#define ltoreq(a, b) (lt(a, b) || equalpos(a, b))
-
-/*
* lineempty() - return TRUE if the line is empty
*/
#define lineempty(p) (*ml_get(p) == NUL)
@@ -62,7 +43,7 @@
* toupper() and tolower() that use the current locale.
* Careful: Only call TOUPPER_LOC() and TOLOWER_LOC() with a character in the
* range 0 - 255. toupper()/tolower() on some systems can't handle others.
- * Note: It is often better to use vim_tolower() and vim_toupper(), because many
+ * Note: It is often better to use mb_tolower() and mb_toupper(), because many
* toupper() and tolower() implementations only work for ASCII.
*/
#define TOUPPER_LOC toupper
@@ -120,8 +101,10 @@
/* mch_open_rw(): invoke os_open() with third argument for user R/W. */
#if defined(UNIX) /* open in rw------- mode */
# define mch_open_rw(n, f) os_open((n), (f), (mode_t)0600)
+#elif defined(WIN32)
+# define mch_open_rw(n, f) os_open((n), (f), S_IREAD | S_IWRITE)
#else
-# define mch_open_rw(n, f) os_open((n), (f), 0)
+# define mch_open_rw(n, f) os_open((n), (f), 0)
#endif
# define REPLACE_NORMAL(s) (((s) & REPLACE_FLAG) && !((s) & VREPLACE_FLAG))
diff --git a/src/nvim/mark.h b/src/nvim/mark.h
index c22a102926..a356c1f398 100644
--- a/src/nvim/mark.h
+++ b/src/nvim/mark.h
@@ -4,6 +4,7 @@
#include "nvim/macros.h"
#include "nvim/ascii.h"
#include "nvim/buffer_defs.h"
+#include "nvim/func_attr.h"
#include "nvim/mark_defs.h"
#include "nvim/memory.h"
#include "nvim/pos.h"
@@ -75,6 +76,45 @@ static inline int mark_local_index(const char name)
: -1))));
}
+static inline bool lt(pos_T, pos_T) REAL_FATTR_CONST REAL_FATTR_ALWAYS_INLINE;
+static inline bool equalpos(pos_T, pos_T)
+ REAL_FATTR_CONST REAL_FATTR_ALWAYS_INLINE;
+static inline bool ltoreq(pos_T, pos_T)
+ REAL_FATTR_CONST REAL_FATTR_ALWAYS_INLINE;
+static inline void clearpos(pos_T *) REAL_FATTR_ALWAYS_INLINE;
+
+/// Return true if position a is before (less than) position b.
+static inline bool lt(pos_T a, pos_T b)
+{
+ if (a.lnum != b.lnum) {
+ return a.lnum < b.lnum;
+ } else if (a.col != b.col) {
+ return a.col < b.col;
+ } else {
+ return a.coladd < b.coladd;
+ }
+}
+
+/// Return true if position a and b are equal.
+static inline bool equalpos(pos_T a, pos_T b)
+{
+ return (a.lnum == b.lnum) && (a.col == b.col) && (a.coladd == b.coladd);
+}
+
+/// Return true if position a is less than or equal to b.
+static inline bool ltoreq(pos_T a, pos_T b)
+{
+ return lt(a, b) || equalpos(a, b);
+}
+
+/// Clear the pos_T structure pointed to by a.
+static inline void clearpos(pos_T *a)
+{
+ a->lnum = 0;
+ a->col = 0;
+ a->coladd = 0;
+}
+
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "mark.h.generated.h"
#endif
diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c
index 460528b85f..b18459a2b5 100644
--- a/src/nvim/mbyte.c
+++ b/src/nvim/mbyte.c
@@ -1174,11 +1174,14 @@ int utf_fold(int a)
return utf_convert(a, foldCase, ARRAY_SIZE(foldCase));
}
-/*
- * Return the upper-case equivalent of "a", which is a UCS-4 character. Use
- * simple case folding.
- */
-int utf_toupper(int a)
+// Vim's own character class functions. These exist because many library
+// islower()/toupper() etc. do not work properly: they crash when used with
+// invalid values or can't handle latin1 when the locale is C.
+// Speed is most important here.
+
+/// Return the upper-case equivalent of "a", which is a UCS-4 character. Use
+/// simple case folding.
+int mb_toupper(int a)
{
/* If 'casemap' contains "keepascii" use ASCII style toupper(). */
if (a < 128 && (cmp_flags & CMP_KEEPASCII))
@@ -1198,17 +1201,15 @@ int utf_toupper(int a)
return utf_convert(a, toUpper, ARRAY_SIZE(toUpper));
}
-bool utf_islower(int a)
+bool mb_islower(int a)
{
- /* German sharp s is lower case but has no upper case equivalent. */
- return (utf_toupper(a) != a) || a == 0xdf;
+ // German sharp s is lower case but has no upper case equivalent.
+ return (mb_toupper(a) != a) || a == 0xdf;
}
-/*
- * Return the lower-case equivalent of "a", which is a UCS-4 character. Use
- * simple case folding.
- */
-int utf_tolower(int a)
+/// Return the lower-case equivalent of "a", which is a UCS-4 character. Use
+/// simple case folding.
+int mb_tolower(int a)
{
/* If 'casemap' contains "keepascii" use ASCII style tolower(). */
if (a < 128 && (cmp_flags & CMP_KEEPASCII))
@@ -1228,9 +1229,9 @@ int utf_tolower(int a)
return utf_convert(a, toLower, ARRAY_SIZE(toLower));
}
-bool utf_isupper(int a)
+bool mb_isupper(int a)
{
- return utf_tolower(a) != a;
+ return mb_tolower(a) != a;
}
static int utf_strnicmp(const char_u *s1, const char_u *s2, size_t n1,
diff --git a/src/nvim/memory.c b/src/nvim/memory.c
index b4fdd86a6d..85ec916ba0 100644
--- a/src/nvim/memory.c
+++ b/src/nvim/memory.c
@@ -495,6 +495,13 @@ bool strequal(const char *a, const char *b)
return (a == NULL && b == NULL) || (a && b && strcmp(a, b) == 0);
}
+/// Case-insensitive `strequal`.
+bool striequal(const char *a, const char *b)
+ FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
+{
+ return (a == NULL && b == NULL) || (a && b && STRICMP(a, b) == 0);
+}
+
/*
* Avoid repeating the error message many times (they take 1 second each).
* Did_outofmem_msg is reset when a character is read.
diff --git a/src/nvim/message.c b/src/nvim/message.c
index 1d3609291a..3e4a1e10b6 100644
--- a/src/nvim/message.c
+++ b/src/nvim/message.c
@@ -2730,8 +2730,8 @@ do_dialog (
break;
}
- /* Make the character lowercase, as chars in "hotkeys" are. */
- c = vim_tolower(c);
+ // Make the character lowercase, as chars in "hotkeys" are.
+ c = mb_tolower(c);
retval = 1;
for (i = 0; hotkeys[i]; ++i) {
if (has_mbyte) {
@@ -2777,7 +2777,7 @@ copy_char (
if (has_mbyte) {
if (lowercase) {
- c = vim_tolower((*mb_ptr2char)(from));
+ c = mb_tolower((*mb_ptr2char)(from));
return (*mb_char2bytes)(c, to);
} else {
len = (*mb_ptr2len)(from);
diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c
index 0b74b4437e..8d93505be3 100644
--- a/src/nvim/misc1.c
+++ b/src/nvim/misc1.c
@@ -2678,7 +2678,8 @@ void fast_breakcheck(void)
}
}
-// Call shell. Calls os_call_shell, with 'shellxquote' added.
+// os_call_shell wrapper. Handles 'verbose', :profile, and v:shell_error.
+// Invalidates cached tags.
int call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg)
{
int retval;
@@ -2686,8 +2687,7 @@ int call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg)
if (p_verbose > 3) {
verbose_enter();
- smsg(_("Calling shell to execute: \"%s\""),
- cmd == NULL ? p_sh : cmd);
+ smsg(_("Calling shell to execute: \"%s\""), cmd == NULL ? p_sh : cmd);
ui_putc('\n');
verbose_leave();
}
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index 68ef27222c..5212ec45ab 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -802,7 +802,6 @@ static bool is_append_register(int regname)
/// Returns a copy of contents in register `name`
/// for use in do_put. Should be freed by caller.
yankreg_T *copy_register(int name)
- FUNC_ATTR_MALLOC
FUNC_ATTR_NONNULL_RET
{
yankreg_T *reg = get_yank_register(name, YREG_PASTE);
@@ -1956,16 +1955,18 @@ int swapchar(int op_type, pos_T *pos)
if (enc_dbcs != 0 && c >= 0x100) /* No lower/uppercase letter */
return FALSE;
nc = c;
- if (vim_islower(c)) {
- if (op_type == OP_ROT13)
+ if (mb_islower(c)) {
+ if (op_type == OP_ROT13) {
nc = ROT13(c, 'a');
- else if (op_type != OP_LOWER)
- nc = vim_toupper(c);
- } else if (vim_isupper(c)) {
- if (op_type == OP_ROT13)
+ } else if (op_type != OP_LOWER) {
+ nc = mb_toupper(c);
+ }
+ } else if (mb_isupper(c)) {
+ if (op_type == OP_ROT13) {
nc = ROT13(c, 'A');
- else if (op_type != OP_UPPER)
- nc = vim_tolower(c);
+ } else if (op_type != OP_UPPER) {
+ nc = mb_tolower(c);
+ }
}
if (nc != c) {
if (enc_utf8 && (c >= 0x80 || nc >= 0x80)) {
@@ -3327,10 +3328,11 @@ void ex_display(exarg_T *eap)
get_clipboard(name, &yb, true);
- if (name == vim_tolower(redir_reg)
- || (redir_reg == '"' && yb == y_previous))
- continue; /* do not list register being written to, the
- * pointer can be freed */
+ if (name == mb_tolower(redir_reg)
+ || (redir_reg == '"' && yb == y_previous)) {
+ continue; // do not list register being written to, the
+ // pointer can be freed
+ }
if (yb->y_array != NULL) {
msg_putchar('\n');
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 458d80716c..0070a0056d 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -6974,7 +6974,7 @@ bool signcolumn_on(win_T *wp)
/// Get window or buffer local options
dict_T *get_winbuf_options(const int bufopt)
- FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_MALLOC
+ FUNC_ATTR_WARN_UNUSED_RESULT
{
dict_T *const d = tv_dict_alloc();
diff --git a/src/nvim/options.lua b/src/nvim/options.lua
index 4ca63f2efe..4e7be63b63 100644
--- a/src/nvim/options.lua
+++ b/src/nvim/options.lua
@@ -2051,7 +2051,11 @@ return {
secure=true,
vi_def=true,
varname='p_srr',
- defaults={if_true={vi=">"}}
+ defaults={
+ condition='WIN32',
+ if_true={vi=">%s 2>&1"},
+ if_false={vi=">"}
+ }
},
{
full_name='shellslash', abbreviation='ssl',
diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c
index 12c2da6152..ad51e598c1 100644
--- a/src/nvim/os/env.c
+++ b/src/nvim/os/env.c
@@ -1,11 +1,8 @@
-// env.c -- environment variable access
+// Environment inspection
#include <assert.h>
-
#include <uv.h>
-// vim.h must be included before charset.h (and possibly others) or things
-// blow up
#include "nvim/vim.h"
#include "nvim/ascii.h"
#include "nvim/charset.h"
@@ -919,3 +916,20 @@ bool os_term_is_nice(void)
|| NULL != os_getenv("KONSOLE_DBUS_SESSION");
#endif
}
+
+/// Returns true if `sh` looks like it resolves to "cmd.exe".
+bool os_shell_is_cmdexe(const char *sh)
+ FUNC_ATTR_NONNULL_ALL
+{
+ if (*sh == NUL) {
+ return false;
+ }
+ if (striequal(sh, "$COMSPEC")) {
+ const char *comspec = os_getenv("COMSPEC");
+ return striequal("cmd.exe", (char *)path_tail((char_u *)comspec));
+ }
+ if (striequal(sh, "cmd.exe") || striequal(sh, "cmd")) {
+ return true;
+ }
+ return striequal("cmd.exe", (char *)path_tail((char_u *)sh));
+}
diff --git a/src/nvim/os/fileio.c b/src/nvim/os/fileio.c
index 4b7b53fc7f..3c47c66196 100644
--- a/src/nvim/os/fileio.c
+++ b/src/nvim/os/fileio.c
@@ -100,7 +100,7 @@ int file_open(FileDescriptor *const ret_fp, const char *const fname,
/// @return [allocated] Opened file or NULL in case of error.
FileDescriptor *file_open_new(int *const error, const char *const fname,
const int flags, const int mode)
- FUNC_ATTR_NONNULL_ALL FUNC_ATTR_MALLOC FUNC_ATTR_WARN_UNUSED_RESULT
+ FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{
FileDescriptor *const fp = xmalloc(sizeof(*fp));
if ((*error = file_open(fp, fname, flags, mode)) != 0) {
diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c
index b449cc3d5a..29c0431521 100644
--- a/src/nvim/os/shell.c
+++ b/src/nvim/os/shell.c
@@ -47,7 +47,7 @@ typedef struct {
/// @param extra_args Extra arguments to the shell, or NULL.
/// @return Newly allocated argument vector. Must be freed with shell_free_argv.
char **shell_build_argv(const char *cmd, const char *extra_args)
- FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC
+ FUNC_ATTR_NONNULL_RET
{
size_t argc = tokenize(p_sh, NULL) + (cmd ? tokenize(p_shcf, NULL) : 0);
char **rv = xmalloc((argc + 4) * sizeof(*rv));
@@ -124,11 +124,9 @@ int os_call_shell(char_u *cmd, ShellOpts opts, char_u *extra_args)
}
size_t nread;
-
int exitcode = do_os_system(shell_build_argv((char *)cmd, (char *)extra_args),
input.data, input.len, output_ptr, &nread,
emsg_silent, forward_output);
-
xfree(input.data);
if (output) {
diff --git a/src/nvim/path.c b/src/nvim/path.c
index 6bf42ed2fa..205fc2ed62 100644
--- a/src/nvim/path.c
+++ b/src/nvim/path.c
@@ -1853,7 +1853,7 @@ int pathcmp(const char *p, const char *q, int maxlen)
break;
}
- if ((p_fic ? vim_toupper(c1) != vim_toupper(c2) : c1 != c2)
+ if ((p_fic ? mb_toupper(c1) != mb_toupper(c2) : c1 != c2)
#ifdef BACKSLASH_IN_FILENAME
/* consider '/' and '\\' to be equal */
&& !((c1 == '/' && c2 == '\\')
@@ -1864,8 +1864,8 @@ int pathcmp(const char *p, const char *q, int maxlen)
return -1;
if (vim_ispathsep(c2))
return 1;
- return p_fic ? vim_toupper(c1) - vim_toupper(c2)
- : c1 - c2; /* no match */
+ return p_fic ? mb_toupper(c1) - mb_toupper(c2)
+ : c1 - c2; // no match
}
i += MB_PTR2LEN((char_u *)p + i);
diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c
index 9baa53d2a2..4b5e17b00b 100644
--- a/src/nvim/regexp.c
+++ b/src/nvim/regexp.c
@@ -2350,7 +2350,7 @@ collection:
break;
case CLASS_LOWER:
for (cu = 1; cu <= 255; cu++) {
- if (vim_islower(cu) && cu != 170 && cu != 186) {
+ if (mb_islower(cu) && cu != 170 && cu != 186) {
regmbc(cu);
}
}
@@ -2376,7 +2376,7 @@ collection:
break;
case CLASS_UPPER:
for (cu = 1; cu <= 255; cu++) {
- if (vim_isupper(cu)) {
+ if (mb_isupper(cu)) {
regmbc(cu);
}
}
@@ -3474,7 +3474,7 @@ static long bt_regexec_both(char_u *line,
|| (ireg_ic
&& (((enc_utf8 && utf_fold(prog->regstart) == utf_fold(c)))
|| (c < 255 && prog->regstart < 255
- && vim_tolower(prog->regstart) == vim_tolower(c))))) {
+ && mb_tolower(prog->regstart) == mb_tolower(c))))) {
retval = regtry(prog, col);
} else {
retval = 0;
@@ -4155,7 +4155,7 @@ regmatch (
if (*opnd != *reginput
&& (!ireg_ic
|| (!enc_utf8
- && vim_tolower(*opnd) != vim_tolower(*reginput)))) {
+ && mb_tolower(*opnd) != mb_tolower(*reginput)))) {
status = RA_NOMATCH;
} else if (*opnd == NUL) {
// match empty string always works; happens when "~" is
@@ -4573,12 +4573,14 @@ regmatch (
if (OP(next) == EXACTLY) {
rst.nextb = *OPERAND(next);
if (ireg_ic) {
- if (vim_isupper(rst.nextb))
- rst.nextb_ic = vim_tolower(rst.nextb);
- else
- rst.nextb_ic = vim_toupper(rst.nextb);
- } else
+ if (mb_isupper(rst.nextb)) {
+ rst.nextb_ic = mb_tolower(rst.nextb);
+ } else {
+ rst.nextb_ic = mb_toupper(rst.nextb);
+ }
+ } else {
rst.nextb_ic = rst.nextb;
+ }
} else {
rst.nextb = NUL;
rst.nextb_ic = NUL;
@@ -5339,8 +5341,8 @@ do_class:
* would have been used for it. It does handle single-byte
* characters, such as latin1. */
if (ireg_ic) {
- cu = vim_toupper(*opnd);
- cl = vim_tolower(*opnd);
+ cu = mb_toupper(*opnd);
+ cl = mb_tolower(*opnd);
while (count < maxcount && (*scan == cu || *scan == cl)) {
count++;
scan++;
@@ -6312,14 +6314,15 @@ static char_u *cstrchr(char_u *s, int c)
/* tolower() and toupper() can be slow, comparing twice should be a lot
* faster (esp. when using MS Visual C++!).
* For UTF-8 need to use folded case. */
- if (enc_utf8 && c > 0x80)
+ if (c > 0x80) {
cc = utf_fold(c);
- else if (vim_isupper(c))
- cc = vim_tolower(c);
- else if (vim_islower(c))
- cc = vim_toupper(c);
- else
+ } else if (mb_isupper(c)) {
+ cc = mb_tolower(c);
+ } else if (mb_islower(c)) {
+ cc = mb_toupper(c);
+ } else {
return vim_strchr(s, c);
+ }
if (has_mbyte) {
for (p = s; *p != NUL; p += (*mb_ptr2len)(p)) {
@@ -6348,28 +6351,28 @@ static char_u *cstrchr(char_u *s, int c)
static fptr_T do_upper(int *d, int c)
{
- *d = vim_toupper(c);
+ *d = mb_toupper(c);
return (fptr_T)NULL;
}
static fptr_T do_Upper(int *d, int c)
{
- *d = vim_toupper(c);
+ *d = mb_toupper(c);
return (fptr_T)do_Upper;
}
static fptr_T do_lower(int *d, int c)
{
- *d = vim_tolower(c);
+ *d = mb_tolower(c);
return (fptr_T)NULL;
}
static fptr_T do_Lower(int *d, int c)
{
- *d = vim_tolower(c);
+ *d = mb_tolower(c);
return (fptr_T)do_Lower;
}
diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c
index 5b49ab38f0..caf26fdd35 100644
--- a/src/nvim/regexp_nfa.c
+++ b/src/nvim/regexp_nfa.c
@@ -4373,7 +4373,7 @@ static int check_char_class(int class, int c)
return OK;
break;
case NFA_CLASS_LOWER:
- if (vim_islower(c) && c != 170 && c != 186) {
+ if (mb_islower(c) && c != 170 && c != 186) {
return OK;
}
break;
@@ -4391,8 +4391,9 @@ static int check_char_class(int class, int c)
return OK;
break;
case NFA_CLASS_UPPER:
- if (vim_isupper(c))
+ if (mb_isupper(c)) {
return OK;
+ }
break;
case NFA_CLASS_XDIGIT:
if (ascii_isxdigit(c))
@@ -4892,7 +4893,7 @@ static long find_match_text(colnr_T startcol, int regstart, char_u *match_text)
int c2_len = PTR2LEN(s2);
int c2 = PTR2CHAR(s2);
- if ((c1 != c2 && (!ireg_ic || vim_tolower(c1) != vim_tolower(c2)))
+ if ((c1 != c2 && (!ireg_ic || mb_tolower(c1) != mb_tolower(c2)))
|| c1_len != c2_len) {
match = false;
break;
@@ -5585,22 +5586,24 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start,
break;
}
if (ireg_ic) {
- int curc_low = vim_tolower(curc);
- int done = FALSE;
+ int curc_low = mb_tolower(curc);
+ int done = false;
- for (; c1 <= c2; ++c1)
- if (vim_tolower(c1) == curc_low) {
+ for (; c1 <= c2; c1++) {
+ if (mb_tolower(c1) == curc_low) {
result = result_if_matched;
done = TRUE;
break;
}
- if (done)
+ }
+ if (done) {
break;
+ }
}
} else if (state->c < 0 ? check_char_class(state->c, curc)
: (curc == state->c
- || (ireg_ic && vim_tolower(curc)
- == vim_tolower(state->c)))) {
+ || (ireg_ic && mb_tolower(curc)
+ == mb_tolower(state->c)))) {
result = result_if_matched;
break;
}
@@ -6003,8 +6006,9 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start,
#endif
result = (c == curc);
- if (!result && ireg_ic)
- result = vim_tolower(c) == vim_tolower(curc);
+ if (!result && ireg_ic) {
+ result = mb_tolower(c) == mb_tolower(curc);
+ }
// If ireg_icombine is not set only skip over the character
// itself. When it is set skip over composing characters.
@@ -6152,8 +6156,8 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start,
// Checking if the required start character matches is
// cheaper than adding a state that won't match.
c = PTR2CHAR(reginput + clen);
- if (c != prog->regstart && (!ireg_ic || vim_tolower(c)
- != vim_tolower(prog->regstart))) {
+ if (c != prog->regstart && (!ireg_ic || mb_tolower(c)
+ != mb_tolower(prog->regstart))) {
#ifdef REGEXP_DEBUG
fprintf(log_fd,
" Skipping start state, regstart does not match\n");
diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index d9a21aa81f..febca105e9 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -102,6 +102,7 @@
#include "nvim/indent.h"
#include "nvim/getchar.h"
#include "nvim/main.h"
+#include "nvim/mark.h"
#include "nvim/mbyte.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
diff --git a/src/nvim/search.c b/src/nvim/search.c
index c5c92b41c5..91a558045f 100644
--- a/src/nvim/search.c
+++ b/src/nvim/search.c
@@ -335,23 +335,26 @@ int pat_has_uppercase(char_u *pat)
while (*p != NUL) {
int l;
- if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) {
- if (enc_utf8 && utf_isupper(utf_ptr2char(p)))
- return TRUE;
+ if ((l = mb_ptr2len(p)) > 1) {
+ if (mb_isupper(utf_ptr2char(p))) {
+ return true;
+ }
p += l;
} else if (*p == '\\') {
- if (p[1] == '_' && p[2] != NUL) /* skip "\_X" */
+ if (p[1] == '_' && p[2] != NUL) { // skip "\_X"
p += 3;
- else if (p[1] == '%' && p[2] != NUL) /* skip "\%X" */
+ } else if (p[1] == '%' && p[2] != NUL) { // skip "\%X"
p += 3;
- else if (p[1] != NUL) /* skip "\X" */
+ } else if (p[1] != NUL) { // skip "\X"
p += 2;
- else
+ } else {
p += 1;
- } else if (vim_isupper(*p))
- return TRUE;
- else
- ++p;
+ }
+ } else if (mb_isupper(*p)) {
+ return true;
+ } else {
+ p++;
+ }
}
return FALSE;
}
diff --git a/src/nvim/spell.c b/src/nvim/spell.c
index d4f49bffb2..17016be35f 100644
--- a/src/nvim/spell.c
+++ b/src/nvim/spell.c
@@ -92,6 +92,7 @@
#include "nvim/func_attr.h"
#include "nvim/getchar.h"
#include "nvim/hashtab.h"
+#include "nvim/mark.h"
#include "nvim/mbyte.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
@@ -2526,8 +2527,7 @@ void clear_spell_chartab(spelltab_T *sp)
}
}
-// Init the chartab used for spelling. Only depends on 'encoding'.
-// Called once while starting up and when 'encoding' changes.
+// Init the chartab used for spelling. Called once while starting up.
// The default is to use isalpha(), but the spell file should define the word
// characters to make it possible that 'encoding' differs from the current
// locale. For utf-8 we don't use isalpha() but our own functions.
@@ -2537,36 +2537,17 @@ void init_spell_chartab(void)
did_set_spelltab = false;
clear_spell_chartab(&spelltab);
- if (enc_dbcs) {
- // DBCS: assume double-wide characters are word characters.
- for (i = 128; i <= 255; ++i)
- if (MB_BYTE2LEN(i) == 2)
- spelltab.st_isw[i] = true;
- } else if (enc_utf8) {
- for (i = 128; i < 256; ++i) {
- int f = utf_fold(i);
- int u = utf_toupper(i);
-
- spelltab.st_isu[i] = utf_isupper(i);
- spelltab.st_isw[i] = spelltab.st_isu[i] || utf_islower(i);
- // The folded/upper-cased value is different between latin1 and
- // utf8 for 0xb5, causing E763 for no good reason. Use the latin1
- // value for utf-8 to avoid this.
- spelltab.st_fold[i] = (f < 256) ? f : i;
- spelltab.st_upper[i] = (u < 256) ? u : i;
- }
- } else {
- // Rough guess: use locale-dependent library functions.
- for (i = 128; i < 256; ++i) {
- if (vim_isupper(i)) {
- spelltab.st_isw[i] = true;
- spelltab.st_isu[i] = true;
- spelltab.st_fold[i] = vim_tolower(i);
- } else if (vim_islower(i)) {
- spelltab.st_isw[i] = true;
- spelltab.st_upper[i] = vim_toupper(i);
- }
- }
+ for (i = 128; i < 256; i++) {
+ int f = utf_fold(i);
+ int u = mb_toupper(i);
+
+ spelltab.st_isu[i] = mb_isupper(i);
+ spelltab.st_isw[i] = spelltab.st_isu[i] || mb_islower(i);
+ // The folded/upper-cased value is different between latin1 and
+ // utf8 for 0xb5, causing E763 for no good reason. Use the latin1
+ // value for utf-8 to avoid this.
+ spelltab.st_fold[i] = (f < 256) ? f : i;
+ spelltab.st_upper[i] = (u < 256) ? u : i;
}
}
diff --git a/src/nvim/spell_defs.h b/src/nvim/spell_defs.h
index c54a7f5390..ddd54c724e 100644
--- a/src/nvim/spell_defs.h
+++ b/src/nvim/spell_defs.h
@@ -265,11 +265,11 @@ typedef struct trystate_S {
: (c) < \
256 ? (int)spelltab.st_fold[c] : (int)towlower(c))
-#define SPELL_TOUPPER(c) (enc_utf8 && (c) >= 128 ? utf_toupper(c) \
+#define SPELL_TOUPPER(c) (enc_utf8 && (c) >= 128 ? mb_toupper(c) \
: (c) < \
256 ? (int)spelltab.st_upper[c] : (int)towupper(c))
-#define SPELL_ISUPPER(c) (enc_utf8 && (c) >= 128 ? utf_isupper(c) \
+#define SPELL_ISUPPER(c) (enc_utf8 && (c) >= 128 ? mb_isupper(c) \
: (c) < 256 ? spelltab.st_isu[c] : iswupper(c))
// First language that is loaded, start of the linked list of loaded
diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c
index bbef1f5032..1da71dc4f9 100644
--- a/src/nvim/spellfile.c
+++ b/src/nvim/spellfile.c
@@ -225,6 +225,7 @@
#include <stdio.h>
#include <stdint.h>
#include <wctype.h>
+#include <strings.h>
#include "nvim/vim.h"
#include "nvim/spell_defs.h"
@@ -267,7 +268,7 @@
#define SAL_REM_ACCENTS 4
#define VIMSPELLMAGIC "VIMspell" // string at start of Vim spell file
-#define VIMSPELLMAGICL 8
+#define VIMSPELLMAGICL (sizeof(VIMSPELLMAGIC) - 1)
#define VIMSPELLVERSION 50
// Section IDs. Only renumber them when VIMSPELLVERSION changes!
@@ -494,6 +495,64 @@ typedef struct spellinfo_S {
# include "spellfile.c.generated.h"
#endif
+/// Read n bytes from fd to buf, returning on errors
+///
+/// @param[out] buf Buffer to read to, must be at least n bytes long.
+/// @param[in] n Amount of bytes to read.
+/// @param fd FILE* to read from.
+/// @param exit_code Code to run before returning.
+///
+/// @return Allows to proceed if everything is OK, returns SP_TRUNCERROR if
+/// there are not enough bytes, returns SP_OTHERERROR if reading failed.
+#define SPELL_READ_BYTES(buf, n, fd, exit_code) \
+ do { \
+ const size_t n__SPRB = (n); \
+ FILE *const fd__SPRB = (fd); \
+ char *const buf__SPRB = (buf); \
+ const size_t read_bytes__SPRB = fread(buf__SPRB, 1, n__SPRB, fd__SPRB); \
+ if (read_bytes__SPRB != n__SPRB) { \
+ exit_code; \
+ return feof(fd__SPRB) ? SP_TRUNCERROR : SP_OTHERERROR; \
+ } \
+ } while (0)
+
+/// Like #SPELL_READ_BYTES, but also error out if NUL byte was read
+///
+/// @return Allows to proceed if everything is OK, returns SP_TRUNCERROR if
+/// there are not enough bytes, returns SP_OTHERERROR if reading failed,
+/// returns SP_FORMERROR if read out a NUL byte.
+#define SPELL_READ_NONNUL_BYTES(buf, n, fd, exit_code) \
+ do { \
+ const size_t n__SPRNB = (n); \
+ FILE *const fd__SPRNB = (fd); \
+ char *const buf__SPRNB = (buf); \
+ SPELL_READ_BYTES(buf__SPRNB, n__SPRNB, fd__SPRNB, exit_code); \
+ if (memchr(buf__SPRNB, NUL, (size_t)n__SPRNB)) { \
+ exit_code; \
+ return SP_FORMERROR; \
+ } \
+ } while (0)
+
+/// Check that spell file starts with a magic string
+///
+/// Does not check for version of the file.
+///
+/// @param fd File to check.
+///
+/// @return 0 in case of success, SP_TRUNCERROR if file contains not enough
+/// bytes, SP_FORMERROR if it does not match magic string and
+/// SP_OTHERERROR if reading file failed.
+static inline int spell_check_magic_string(FILE *const fd)
+ FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_ALWAYS_INLINE
+{
+ char buf[VIMSPELLMAGICL];
+ SPELL_READ_BYTES(buf, VIMSPELLMAGICL, fd, ;);
+ if (memcmp(buf, VIMSPELLMAGIC, VIMSPELLMAGICL) != 0) {
+ return SP_FORMERROR;
+ }
+ return 0;
+}
+
// Load one spell file and store the info into a slang_T.
//
// This is invoked in three ways:
@@ -514,9 +573,7 @@ spell_load_file (
)
{
FILE *fd;
- char_u buf[VIMSPELLMAGICL];
char_u *p;
- int i;
int n;
int len;
char_u *save_sourcing_name = sourcing_name;
@@ -558,11 +615,20 @@ spell_load_file (
sourcing_lnum = 0;
// <HEADER>: <fileID>
- for (i = 0; i < VIMSPELLMAGICL; ++i)
- buf[i] = getc(fd); // <fileID>
- if (STRNCMP(buf, VIMSPELLMAGIC, VIMSPELLMAGICL) != 0) {
- EMSG(_("E757: This does not look like a spell file"));
- goto endFAIL;
+ const int scms_ret = spell_check_magic_string(fd);
+ switch (scms_ret) {
+ case SP_FORMERROR:
+ case SP_TRUNCERROR: {
+ emsgf(_("E757: This does not look like a spell file"));
+ goto endFAIL;
+ }
+ case SP_OTHERERROR: {
+ emsgf(_("E5042: Failed to read spell file %s: %s"),
+ fname, strerror(ferror(fd)));
+ }
+ case 0: {
+ break;
+ }
}
c = getc(fd); // <versionnr>
if (c < VIMSPELLVERSION) {
@@ -935,12 +1001,10 @@ static char_u *read_cnt_string(FILE *fd, int cnt_bytes, int *cntp)
// Return SP_*ERROR flags.
static int read_region_section(FILE *fd, slang_T *lp, int len)
{
- int i;
-
- if (len > 16)
+ if (len > 16) {
return SP_FORMERROR;
- for (i = 0; i < len; ++i)
- lp->sl_regions[i] = getc(fd); // <regionname>
+ }
+ SPELL_READ_NONNUL_BYTES((char *)lp->sl_regions, (size_t)len, fd, ;);
lp->sl_regions[len] = NUL;
return 0;
}
@@ -983,35 +1047,30 @@ static int read_charflags_section(FILE *fd)
// Return SP_*ERROR flags.
static int read_prefcond_section(FILE *fd, slang_T *lp)
{
- int cnt;
- int i;
- int n;
- char_u *p;
- char_u buf[MAXWLEN + 1];
-
// <prefcondcnt> <prefcond> ...
- cnt = get2c(fd); // <prefcondcnt>
- if (cnt <= 0)
+ const int cnt = get2c(fd); // <prefcondcnt>
+ if (cnt <= 0) {
return SP_FORMERROR;
+ }
lp->sl_prefprog = xcalloc(cnt, sizeof(regprog_T *));
lp->sl_prefixcnt = cnt;
- for (i = 0; i < cnt; ++i) {
+ for (int i = 0; i < cnt; i++) {
// <prefcond> : <condlen> <condstr>
- n = getc(fd); // <condlen>
- if (n < 0 || n >= MAXWLEN)
+ const int n = getc(fd); // <condlen>
+ if (n < 0 || n >= MAXWLEN) {
return SP_FORMERROR;
+ }
// When <condlen> is zero we have an empty condition. Otherwise
// compile the regexp program used to check for the condition.
if (n > 0) {
- buf[0] = '^'; // always match at one position only
- p = buf + 1;
- while (n-- > 0)
- *p++ = getc(fd); // <condstr>
- *p = NUL;
- lp->sl_prefprog[i] = vim_regcomp(buf, RE_MAGIC + RE_STRING);
+ char buf[MAXWLEN + 1];
+ buf[0] = '^'; // always match at one position only
+ SPELL_READ_NONNUL_BYTES(buf + 1, (size_t)n, fd, ;);
+ buf[n + 1] = NUL;
+ lp->sl_prefprog[i] = vim_regcomp((char_u *)buf, RE_MAGIC | RE_STRING);
}
}
return 0;
@@ -1064,7 +1123,6 @@ static int read_rep_section(FILE *fd, garray_T *gap, int16_t *first)
// Return SP_*ERROR flags.
static int read_sal_section(FILE *fd, slang_T *slang)
{
- int i;
int cnt;
garray_T *gap;
salitem_T *smp;
@@ -1074,13 +1132,16 @@ static int read_sal_section(FILE *fd, slang_T *slang)
slang->sl_sofo = false;
- i = getc(fd); // <salflags>
- if (i & SAL_F0LLOWUP)
+ const int flags = getc(fd); // <salflags>
+ if (flags & SAL_F0LLOWUP) {
slang->sl_followup = true;
- if (i & SAL_COLLAPSE)
+ }
+ if (flags & SAL_COLLAPSE) {
slang->sl_collapse = true;
- if (i & SAL_REM_ACCENTS)
+ }
+ if (flags & SAL_REM_ACCENTS) {
slang->sl_rem_accents = true;
+ }
cnt = get2c(fd); // <salcount>
if (cnt < 0)
@@ -1100,7 +1161,8 @@ static int read_sal_section(FILE *fd, slang_T *slang)
smp->sm_lead = p;
// Read up to the first special char into sm_lead.
- for (i = 0; i < ccnt; ++i) {
+ int i = 0;
+ for (; i < ccnt; ++i) {
c = getc(fd); // <salfrom>
if (vim_strchr((char_u *)"0123456789(-<^$", c) != NULL)
break;
@@ -1126,11 +1188,17 @@ static int read_sal_section(FILE *fd, slang_T *slang)
// Any following chars go in sm_rules.
smp->sm_rules = p;
- if (i < ccnt)
+ if (i < ccnt) {
// store the char we got while checking for end of sm_lead
*p++ = c;
- for (++i; i < ccnt; ++i)
- *p++ = getc(fd); // <salfrom>
+ }
+ i++;
+ if (i < ccnt) {
+ SPELL_READ_NONNUL_BYTES( // <salfrom>
+ (char *)p, (size_t)(ccnt - i), fd, xfree(smp->sm_lead));
+ p += (ccnt - i);
+ i = ccnt;
+ }
*p++ = NUL;
// <saltolen> <salto>
diff --git a/src/nvim/strings.c b/src/nvim/strings.c
index 5dcffe00e0..8a1a3beddd 100644
--- a/src/nvim/strings.c
+++ b/src/nvim/strings.c
@@ -198,8 +198,16 @@ char_u *vim_strsave_shellescape(const char_u *string,
/* First count the number of extra bytes required. */
size_t length = STRLEN(string) + 3; // two quotes and a trailing NUL
for (const char_u *p = string; *p != NUL; mb_ptr_adv(p)) {
- if (*p == '\'')
- length += 3; /* ' => '\'' */
+#ifdef WIN32
+ if (!p_ssl) {
+ if (*p == '"') {
+ length++; // " -> ""
+ }
+ } else
+#endif
+ if (*p == '\'') {
+ length += 3; // ' => '\''
+ }
if ((*p == '\n' && (csh_like || do_newline))
|| (*p == '!' && (csh_like || do_special))) {
++length; /* insert backslash */
@@ -216,10 +224,25 @@ char_u *vim_strsave_shellescape(const char_u *string,
escaped_string = xmalloc(length);
d = escaped_string;
- /* add opening quote */
+ // add opening quote
+#ifdef WIN32
+ if (!p_ssl) {
+ *d++ = '"';
+ } else
+#endif
*d++ = '\'';
for (const char_u *p = string; *p != NUL; ) {
+#ifdef WIN32
+ if (!p_ssl) {
+ if (*p == '"') {
+ *d++ = '"';
+ *d++ = '"';
+ p++;
+ continue;
+ }
+ } else
+#endif
if (*p == '\'') {
*d++ = '\'';
*d++ = '\\';
@@ -246,7 +269,12 @@ char_u *vim_strsave_shellescape(const char_u *string,
MB_COPY_CHAR(p, d);
}
- /* add terminating quote and finish with a NUL */
+ // add terminating quote and finish with a NUL
+# ifdef WIN32
+ if (!p_ssl) {
+ *d++ = '"';
+ } else
+# endif
*d++ = '\'';
*d = NUL;
@@ -291,14 +319,15 @@ void vim_strup(char_u *p)
}
}
-/// Make given string all upper-case
+/// Make given string all upper-case or all lower-case
///
-/// Handels multi-byte characters as good as possible.
+/// Handles multi-byte characters as good as possible.
///
/// @param[in] orig Input string.
+/// @param[in] upper If true make uppercase, otherwise lowercase
///
/// @return [allocated] upper-cased string.
-char *strup_save(const char *const orig)
+char *strcase_save(const char *const orig, bool upper)
FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
{
char *res = xstrdup(orig);
@@ -307,33 +336,25 @@ char *strup_save(const char *const orig)
while (*p != NUL) {
int l;
- if (enc_utf8) {
- int c = utf_ptr2char((const char_u *)p);
- int uc = utf_toupper(c);
-
- // Reallocate string when byte count changes. This is rare,
- // thus it's OK to do another malloc()/free().
- l = utf_ptr2len((const char_u *)p);
- int newl = utf_char2len(uc);
- if (newl != l) {
- // TODO(philix): use xrealloc() in strup_save()
- char *s = xmalloc(STRLEN(res) + (size_t)(1 + newl - l));
- memcpy(s, res, (size_t)(p - res));
- STRCPY(s + (p - res) + newl, p + l);
- p = s + (p - res);
- xfree(res);
- res = s;
- }
-
- utf_char2bytes(uc, (char_u *)p);
- p += newl;
- } else if (has_mbyte && (l = (*mb_ptr2len)((const char_u *)p)) > 1) {
- p += l; // Skip multi-byte character.
- } else {
- // note that toupper() can be a macro
- *p = (char)(uint8_t)TOUPPER_LOC(*p);
- p++;
+ int c = utf_ptr2char((const char_u *)p);
+ int uc = upper ? mb_toupper(c) : mb_tolower(c);
+
+ // Reallocate string when byte count changes. This is rare,
+ // thus it's OK to do another malloc()/free().
+ l = utf_ptr2len((const char_u *)p);
+ int newl = utf_char2len(uc);
+ if (newl != l) {
+ // TODO(philix): use xrealloc() in strup_save()
+ char *s = xmalloc(STRLEN(res) + (size_t)(1 + newl - l));
+ memcpy(s, res, (size_t)(p - res));
+ STRCPY(s + (p - res) + newl, p + l);
+ p = s + (p - res);
+ xfree(res);
+ res = s;
}
+
+ utf_char2bytes(uc, (char_u *)p);
+ p += newl;
}
return res;
diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c
index e36b00d770..1ed65ec52a 100644
--- a/src/nvim/syntax.c
+++ b/src/nvim/syntax.c
@@ -4246,83 +4246,81 @@ static void syn_cmd_keyword(exarg_T *eap, int syncing)
if (rest != NULL) {
syn_id = syn_check_group(arg, (int)(group_name_end - arg));
- if (syn_id != 0)
- /* allocate a buffer, for removing backslashes in the keyword */
+ if (syn_id != 0) {
+ // Allocate a buffer, for removing backslashes in the keyword.
keyword_copy = xmalloc(STRLEN(rest) + 1);
- syn_opt_arg.flags = 0;
- syn_opt_arg.keyword = TRUE;
- syn_opt_arg.sync_idx = NULL;
- syn_opt_arg.has_cont_list = FALSE;
- syn_opt_arg.cont_in_list = NULL;
- syn_opt_arg.next_list = NULL;
-
- /*
- * The options given apply to ALL keywords, so all options must be
- * found before keywords can be created.
- * 1: collect the options and copy the keywords to keyword_copy.
- */
- cnt = 0;
- p = keyword_copy;
- for (; rest != NULL && !ends_excmd(*rest); rest = skipwhite(rest)) {
- rest = get_syn_options(rest, &syn_opt_arg, &conceal_char);
- if (rest == NULL || ends_excmd(*rest))
- break;
- /* Copy the keyword, removing backslashes, and add a NUL. */
- while (*rest != NUL && !ascii_iswhite(*rest)) {
- if (*rest == '\\' && rest[1] != NUL)
- ++rest;
- *p++ = *rest++;
- }
- *p++ = NUL;
- ++cnt;
}
+ if (keyword_copy != NULL) {
+ syn_opt_arg.flags = 0;
+ syn_opt_arg.keyword = true;
+ syn_opt_arg.sync_idx = NULL;
+ syn_opt_arg.has_cont_list = false;
+ syn_opt_arg.cont_in_list = NULL;
+ syn_opt_arg.next_list = NULL;
+
+ // The options given apply to ALL keywords, so all options must be
+ // found before keywords can be created.
+ // 1: collect the options and copy the keywords to keyword_copy.
+ cnt = 0;
+ p = keyword_copy;
+ for (; rest != NULL && !ends_excmd(*rest); rest = skipwhite(rest)) {
+ rest = get_syn_options(rest, &syn_opt_arg, &conceal_char);
+ if (rest == NULL || ends_excmd(*rest)) {
+ break;
+ }
+ // Copy the keyword, removing backslashes, and add a NUL.
+ while (*rest != NUL && !ascii_iswhite(*rest)) {
+ if (*rest == '\\' && rest[1] != NUL) {
+ rest++;
+ }
+ *p++ = *rest++;
+ }
+ *p++ = NUL;
+ cnt++;
+ }
- if (!eap->skip) {
- /* Adjust flags for use of ":syn include". */
- syn_incl_toplevel(syn_id, &syn_opt_arg.flags);
+ if (!eap->skip) {
+ // Adjust flags for use of ":syn include".
+ syn_incl_toplevel(syn_id, &syn_opt_arg.flags);
- /*
- * 2: Add an entry for each keyword.
- */
- for (kw = keyword_copy; --cnt >= 0; kw += STRLEN(kw) + 1) {
- for (p = vim_strchr(kw, '[');; ) {
- if (p != NULL)
- *p = NUL;
- add_keyword(kw, syn_id, syn_opt_arg.flags,
- syn_opt_arg.cont_in_list,
- syn_opt_arg.next_list, conceal_char);
- if (p == NULL)
- break;
- if (p[1] == NUL) {
- EMSG2(_("E789: Missing ']': %s"), kw);
- goto error;
- }
- if (p[1] == ']') {
- if (p[2] != NUL) {
- EMSG3(_("E890: trailing char after ']': %s]%s"),
- kw, &p[2]);
+ // 2: Add an entry for each keyword.
+ for (kw = keyword_copy; --cnt >= 0; kw += STRLEN(kw) + 1) {
+ for (p = vim_strchr(kw, '[');; ) {
+ if (p != NULL) {
+ *p = NUL;
+ }
+ add_keyword(kw, syn_id, syn_opt_arg.flags,
+ syn_opt_arg.cont_in_list,
+ syn_opt_arg.next_list, conceal_char);
+ if (p == NULL) {
+ break;
+ }
+ if (p[1] == NUL) {
+ emsgf(_("E789: Missing ']': %s"), kw);
goto error;
}
- kw = p + 1;
- break; // skip over the "]"
- }
- if (has_mbyte) {
- int l = (*mb_ptr2len)(p + 1);
+ if (p[1] == ']') {
+ if (p[2] != NUL) {
+ emsgf(_("E890: trailing char after ']': %s]%s"),
+ kw, &p[2]);
+ goto error;
+ }
+ kw = p + 1;
+ break; // skip over the "]"
+ }
+ const int l = (*mb_ptr2len)(p + 1);
memmove(p, p + 1, l);
p += l;
- } else {
- p[0] = p[1];
- ++p;
}
}
}
- }
error:
- xfree(keyword_copy);
- xfree(syn_opt_arg.cont_in_list);
- xfree(syn_opt_arg.next_list);
+ xfree(keyword_copy);
+ xfree(syn_opt_arg.cont_in_list);
+ xfree(syn_opt_arg.next_list);
+ }
}
if (rest != NULL)
diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim
index 81cb6314ce..3c258299c1 100644
--- a/src/nvim/testdir/test_functions.vim
+++ b/src/nvim/testdir/test_functions.vim
@@ -29,3 +29,147 @@ func Test_setbufvar_options()
bwipe!
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
+
+
diff --git a/src/nvim/testdir/test_normal.vim b/src/nvim/testdir/test_normal.vim
index a22dca35cc..6261625801 100644
--- a/src/nvim/testdir/test_normal.vim
+++ b/src/nvim/testdir/test_normal.vim
@@ -1606,6 +1606,52 @@ fun! Test_normal30_changecase()
norm! V~
call assert_equal('THIS IS A simple test: äüöss', getline('.'))
+ " Turkish ASCII turns to multi-byte. On some systems Turkish locale
+ " is available but toupper()/tolower() don't do the right thing.
+ try
+ lang tr_TR.UTF-8
+ set casemap=
+ let iupper = toupper('i')
+ if iupper == "\u0130"
+ call setline(1, 'iI')
+ 1normal gUU
+ call assert_equal("\u0130I", getline(1))
+ call assert_equal("\u0130I", toupper("iI"))
+
+ call setline(1, 'iI')
+ 1normal guu
+ call assert_equal("i\u0131", getline(1))
+ call assert_equal("i\u0131", tolower("iI"))
+ elseif iupper == "I"
+ call setline(1, 'iI')
+ 1normal gUU
+ call assert_equal("II", getline(1))
+ call assert_equal("II", toupper("iI"))
+
+ call setline(1, 'iI')
+ 1normal guu
+ call assert_equal("ii", getline(1))
+ call assert_equal("ii", tolower("iI"))
+ else
+ call assert_true(false, "expected toupper('i') to be either 'I' or '\u0131'")
+ endif
+ set casemap&
+ call setline(1, 'iI')
+ 1normal gUU
+ call assert_equal("II", getline(1))
+ call assert_equal("II", toupper("iI"))
+
+ call setline(1, 'iI')
+ 1normal guu
+ call assert_equal("ii", getline(1))
+ call assert_equal("ii", tolower("iI"))
+
+ lang en_US.UTF-8
+ catch /E197:/
+ " can't use Turkish locale
+ throw 'Skipped: Turkish locale not available'
+ endtry
+
" clean up
bw!
endfunc
diff --git a/test/benchmark/bench_re_freeze_spec.lua b/test/benchmark/bench_re_freeze_spec.lua
index 53041b042b..ea41953014 100644
--- a/test/benchmark/bench_re_freeze_spec.lua
+++ b/test/benchmark/bench_re_freeze_spec.lua
@@ -1,8 +1,8 @@
-- Test for benchmarking RE engine.
-local helpers = require('test.functional.helpers')
+local helpers = require('test.functional.helpers')(after_each)
local insert, source = helpers.insert, helpers.source
-local clear, execute, wait = helpers.clear, helpers.execute, helpers.wait
+local clear, command = helpers.clear, helpers.command
-- Temporary file for gathering benchmarking results for each regexp engine.
local result_file = 'benchmark.out'
@@ -31,7 +31,7 @@ describe('regexp search', function()
clear()
source(measure_script)
insert('" Benchmark_results:')
- execute('write! ' .. result_file)
+ command('write! ' .. result_file)
end)
-- At the end of the test run we just print the contents of the result file
@@ -46,22 +46,19 @@ describe('regexp search', function()
it('is working with regexpengine=0', function()
local regexpengine = 0
- execute(string.format(measure_cmd, regexpengine))
- execute('write')
- wait()
+ command(string.format(measure_cmd, regexpengine))
+ command('write')
end)
it('is working with regexpengine=1', function()
local regexpengine = 1
- execute(string.format(measure_cmd, regexpengine))
- execute('write')
- wait()
+ command(string.format(measure_cmd, regexpengine))
+ command('write')
end)
it('is working with regexpengine=2', function()
local regexpengine = 2
- execute(string.format(measure_cmd, regexpengine))
- execute('write')
- wait()
+ command(string.format(measure_cmd, regexpengine))
+ command('write')
end)
end)
diff --git a/test/functional/eval/system_spec.lua b/test/functional/eval/system_spec.lua
index bf95752e3b..7e213e2156 100644
--- a/test/functional/eval/system_spec.lua
+++ b/test/functional/eval/system_spec.lua
@@ -4,6 +4,8 @@ local nvim_dir = helpers.nvim_dir
local eq, call, clear, eval, feed_command, feed, nvim =
helpers.eq, helpers.call, helpers.clear, helpers.eval, helpers.feed_command,
helpers.feed, helpers.nvim
+local command = helpers.command
+local iswin = helpers.iswin
local Screen = require('test.functional.ui.screen')
@@ -33,8 +35,7 @@ describe('system()', function()
describe('command passed as a List', function()
local function printargs_path()
- return nvim_dir..'/printargs-test'
- .. (helpers.os_name() == 'windows' and '.exe' or '')
+ return nvim_dir..'/printargs-test' .. (iswin() and '.exe' or '')
end
it('sets v:shell_error if cmd[0] is not executable', function()
@@ -88,23 +89,32 @@ describe('system()', function()
end)
it('does NOT run in shell', function()
- if helpers.os_name() ~= 'windows' then
+ if not iswin() then
eq("* $PATH %PATH%\n", eval("system(['echo', '*', '$PATH', '%PATH%'])"))
end
end)
end)
- if helpers.pending_win32(pending) then return end
-
it('sets v:shell_error', function()
- eval([[system("sh -c 'exit'")]])
- eq(0, eval('v:shell_error'))
- eval([[system("sh -c 'exit 1'")]])
- eq(1, eval('v:shell_error'))
- eval([[system("sh -c 'exit 5'")]])
- eq(5, eval('v:shell_error'))
- eval([[system('this-should-not-exist')]])
- eq(127, eval('v:shell_error'))
+ if iswin() then
+ eval([[system("cmd.exe /c exit")]])
+ eq(0, eval('v:shell_error'))
+ eval([[system("cmd.exe /c exit 1")]])
+ eq(1, eval('v:shell_error'))
+ eval([[system("cmd.exe /c exit 5")]])
+ eq(5, eval('v:shell_error'))
+ eval([[system('this-should-not-exist')]])
+ eq(1, eval('v:shell_error'))
+ else
+ eval([[system("sh -c 'exit'")]])
+ eq(0, eval('v:shell_error'))
+ eval([[system("sh -c 'exit 1'")]])
+ eq(1, eval('v:shell_error'))
+ eval([[system("sh -c 'exit 5'")]])
+ eq(5, eval('v:shell_error'))
+ eval([[system('this-should-not-exist')]])
+ eq(127, eval('v:shell_error'))
+ end
end)
describe('executes shell function if passed a string', function()
@@ -120,6 +130,40 @@ describe('system()', function()
screen:detach()
end)
+ if iswin() then
+ it('with shell=cmd.exe', function()
+ command('set shell=cmd.exe')
+ eq('""\n', eval([[system('echo ""')]]))
+ eq('"a b"\n', eval([[system('echo "a b"')]]))
+ eq('a \nb\n', eval([[system('echo a & echo b')]]))
+ eq('a \n', eval([[system('echo a 2>&1')]]))
+ eval([[system('cd "C:\Program Files"')]])
+ eq(0, eval('v:shell_error'))
+ end)
+
+ it('with shell=cmd', function()
+ command('set shell=cmd')
+ eq('"a b"\n', eval([[system('echo "a b"')]]))
+ end)
+
+ it('with shell=$COMSPEC', function()
+ local comspecshell = eval("fnamemodify($COMSPEC, ':t')")
+ if comspecshell == 'cmd.exe' then
+ command('set shell=$COMSPEC')
+ eq('"a b"\n', eval([[system('echo "a b"')]]))
+ else
+ pending('$COMSPEC is not cmd.exe: ' .. comspecshell)
+ end
+ end)
+
+ it('works with powershell', function()
+ helpers.set_shell_powershell()
+ eq('a\nb\n', eval([[system('echo a b')]]))
+ eq('C:\\\n', eval([[system('cd c:\; (Get-Location).Path')]]))
+ eq('a b\n', eval([[system('echo "a b"')]]))
+ end)
+ end
+
it('`echo` and waits for its return', function()
feed(':call system("echo")<cr>')
screen:expect([[
@@ -180,7 +224,11 @@ describe('system()', function()
describe('passing no input', function()
it('returns the program output', function()
- eq("echoed", eval('system("echo -n echoed")'))
+ if iswin() then
+ eq("echoed\n", eval('system("echo echoed")'))
+ else
+ eq("echoed", eval('system("echo -n echoed")'))
+ end
end)
it('to backgrounded command does not crash', function()
-- This is indeterminate, just exercise the codepath. May get E5677.
@@ -277,21 +325,30 @@ describe('system()', function()
end)
end)
-if helpers.pending_win32(pending) then return end
-
describe('systemlist()', function()
-- Similar to `system()`, but returns List instead of String.
before_each(clear)
- it('sets the v:shell_error variable', function()
- eval([[systemlist("sh -c 'exit'")]])
- eq(0, eval('v:shell_error'))
- eval([[systemlist("sh -c 'exit 1'")]])
- eq(1, eval('v:shell_error'))
- eval([[systemlist("sh -c 'exit 5'")]])
- eq(5, eval('v:shell_error'))
- eval([[systemlist('this-should-not-exist')]])
- eq(127, eval('v:shell_error'))
+ it('sets v:shell_error', function()
+ if iswin() then
+ eval([[systemlist("cmd.exe /c exit")]])
+ eq(0, eval('v:shell_error'))
+ eval([[systemlist("cmd.exe /c exit 1")]])
+ eq(1, eval('v:shell_error'))
+ eval([[systemlist("cmd.exe /c exit 5")]])
+ eq(5, eval('v:shell_error'))
+ eval([[systemlist('this-should-not-exist')]])
+ eq(1, eval('v:shell_error'))
+ else
+ eval([[systemlist("sh -c 'exit'")]])
+ eq(0, eval('v:shell_error'))
+ eval([[systemlist("sh -c 'exit 1'")]])
+ eq(1, eval('v:shell_error'))
+ eval([[systemlist("sh -c 'exit 5'")]])
+ eq(5, eval('v:shell_error'))
+ eval([[systemlist('this-should-not-exist')]])
+ eq(127, eval('v:shell_error'))
+ end
end)
describe('exectues shell function', function()
@@ -389,6 +446,7 @@ describe('systemlist()', function()
after_each(delete_file(fname))
it('replaces NULs by newline characters', function()
+ if helpers.pending_win32(pending) then return end
eq({'part1\npart2\npart3'}, eval('systemlist("cat '..fname..'")'))
end)
end)
diff --git a/test/functional/ex_cmds/file_spec.lua b/test/functional/ex_cmds/file_spec.lua
new file mode 100644
index 0000000000..771c283134
--- /dev/null
+++ b/test/functional/ex_cmds/file_spec.lua
@@ -0,0 +1,35 @@
+local helpers = require('test.functional.helpers')(after_each)
+local lfs = require('lfs')
+local clear = helpers.clear
+local command = helpers.command
+local eq = helpers.eq
+local funcs = helpers.funcs
+local rmdir = helpers.rmdir
+
+describe(':file', function()
+ local swapdir = lfs.currentdir()..'/Xtest-file_spec'
+ before_each(function()
+ clear()
+ rmdir(swapdir)
+ lfs.mkdir(swapdir)
+ end)
+ after_each(function()
+ command('%bwipeout!')
+ rmdir(swapdir)
+ end)
+
+ it("rename does not lose swapfile #6487", function()
+ local testfile = 'test-file_spec'
+ local testfile_renamed = testfile..'-renamed'
+ -- Note: `set swapfile` *must* go after `set directory`: otherwise it may
+ -- attempt to create a swapfile in different directory.
+ command('set directory^='..swapdir..'//')
+ command('set swapfile fileformat=unix undolevels=-1')
+
+ command('edit! '..testfile)
+ -- Before #6487 this gave "E301: Oops, lost the swap file !!!" on Windows.
+ command('file '..testfile_renamed)
+ eq(testfile_renamed..'.swp',
+ string.match(funcs.execute('swapname'), '[^%%]+$'))
+ end)
+end)
diff --git a/test/functional/ex_cmds/recover_spec.lua b/test/functional/ex_cmds/recover_spec.lua
index 36bf85015a..cb68c29b9a 100644
--- a/test/functional/ex_cmds/recover_spec.lua
+++ b/test/functional/ex_cmds/recover_spec.lua
@@ -1,12 +1,11 @@
--- Tests for :recover
-
local helpers = require('test.functional.helpers')(after_each)
local lfs = require('lfs')
local feed_command, eq, clear, eval, feed, expect, source =
helpers.feed_command, helpers.eq, helpers.clear, helpers.eval, helpers.feed,
helpers.expect, helpers.source
-
-if helpers.pending_win32(pending) then return end
+local command = helpers.command
+local ok = helpers.ok
+local rmdir = helpers.rmdir
describe(':recover', function()
before_each(clear)
@@ -23,30 +22,29 @@ describe(':preserve', function()
local swapdir = lfs.currentdir()..'/testdir_recover_spec'
before_each(function()
clear()
- helpers.rmdir(swapdir)
+ rmdir(swapdir)
lfs.mkdir(swapdir)
end)
after_each(function()
- helpers.rmdir(swapdir)
+ command('%bwipeout!')
+ rmdir(swapdir)
end)
it("saves to custom 'directory' and (R)ecovers (issue #1836)", function()
local testfile = 'testfile_recover_spec'
+ -- Put swapdir at the start of the 'directory' list. #1836
-- Note: `set swapfile` *must* go after `set directory`: otherwise it may
-- attempt to create a swapfile in different directory.
local init = [[
- set directory^=]]..swapdir..[[//
+ set directory^=]]..swapdir:gsub([[\]], [[\\]])..[[//
set swapfile fileformat=unix undolevels=-1
]]
source(init)
- feed_command('set swapfile fileformat=unix undolevels=-1')
- -- Put swapdir at the start of the 'directory' list. #1836
- feed_command('set directory^='..swapdir..'//')
- feed_command('edit '..testfile)
+ command('edit! '..testfile)
feed('isometext<esc>')
- feed_command('preserve')
- source('redir => g:swapname | swapname | redir END')
+ command('preserve')
+ source('redir => g:swapname | silent swapname | redir END')
local swappath1 = eval('g:swapname')
@@ -59,19 +57,20 @@ describe(':preserve', function()
source(init)
-- Use the "SwapExists" event to choose the (R)ecover choice at the dialog.
- feed_command('autocmd SwapExists * let v:swapchoice = "r"')
- feed_command('silent edit '..testfile)
- source('redir => g:swapname | swapname | redir END')
+ command('autocmd SwapExists * let v:swapchoice = "r"')
+ command('silent edit! '..testfile)
+ source('redir => g:swapname | silent swapname | redir END')
local swappath2 = eval('g:swapname')
+ expect('sometext')
-- swapfile from session 1 should end in .swp
- assert(testfile..'.swp' == string.match(swappath1, '[^%%]+$'))
-
+ eq(testfile..'.swp', string.match(swappath1, '[^%%]+$'))
-- swapfile from session 2 should end in .swo
- assert(testfile..'.swo' == string.match(swappath2, '[^%%]+$'))
-
- expect('sometext')
+ eq(testfile..'.swo', string.match(swappath2, '[^%%]+$'))
+ -- Verify that :swapname was not truncated (:help 'shortmess').
+ ok(nil == string.find(swappath1, '%.%.%.'))
+ ok(nil == string.find(swappath2, '%.%.%.'))
end)
end)
diff --git a/test/functional/ex_cmds/syntax_spec.lua b/test/functional/ex_cmds/syntax_spec.lua
new file mode 100644
index 0000000000..c9e96703de
--- /dev/null
+++ b/test/functional/ex_cmds/syntax_spec.lua
@@ -0,0 +1,17 @@
+local helpers = require('test.functional.helpers')(after_each)
+
+local eq = helpers.eq
+local clear = helpers.clear
+local exc_exec = helpers.exc_exec
+
+describe(':syntax', function()
+ before_each(clear)
+
+ describe('keyword', function()
+ it('does not crash when group name contains unprintable characters',
+ function()
+ eq('Vim(syntax):E669: Unprintable character in group name',
+ exc_exec('syntax keyword \024 foo bar'))
+ end)
+ end)
+end)
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index 13b06e7f1b..5882758b5a 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -32,20 +32,15 @@ local nvim_set = 'set shortmess+=I background=light noswapfile noautoindent'
..' belloff= noshowcmd noruler nomore'
local nvim_argv = {nvim_prog, '-u', 'NONE', '-i', 'NONE', '-N',
'--cmd', nvim_set, '--embed'}
-
-local mpack = require('mpack')
-
-local tmpname = global_helpers.tmpname
-local uname = global_helpers.uname
-
--- Formulate a path to the directory containing nvim. We use this to
--- help run test executables. It helps to keep the tests working, even
--- when the build is not in the default location.
+-- Directory containing nvim.
local nvim_dir = nvim_prog:gsub("[/\\][^/\\]+$", "")
if nvim_dir == nvim_prog then
nvim_dir = "."
end
+local mpack = require('mpack')
+local tmpname = global_helpers.tmpname
+local uname = global_helpers.uname
local prepend_argv
if os.getenv('VALGRIND') then
@@ -353,7 +348,7 @@ end
local function set_shell_powershell()
source([[
set shell=powershell shellquote=\" shellpipe=\| shellredir=>
- set shellcmdflag=\ -ExecutionPolicy\ RemoteSigned\ -Command
+ set shellcmdflag=\ -NoProfile\ -ExecutionPolicy\ RemoteSigned\ -Command
let &shellxquote=' '
]])
end
@@ -430,21 +425,27 @@ end
local function do_rmdir(path)
if lfs.attributes(path, 'mode') ~= 'directory' then
- return nil
+ return -- Don't complain.
end
for file in lfs.dir(path) do
if file ~= '.' and file ~= '..' then
local abspath = path..'/'..file
if lfs.attributes(abspath, 'mode') == 'directory' then
- local ret = do_rmdir(abspath) -- recurse
- if not ret then
- return nil
- end
+ do_rmdir(abspath) -- recurse
else
local ret, err = os.remove(abspath)
if not ret then
- error('os.remove: '..err)
- return nil
+ if not session then
+ error('os.remove: '..err)
+ else
+ -- Try Nvim delete(): it handles `readonly` attribute on Windows,
+ -- and avoids Lua cross-version/platform incompatibilities.
+ if -1 == nvim_call('delete', abspath) then
+ local hint = (os_name() == 'windows'
+ and ' (hint: try :%bwipeout! before rmdir())' or '')
+ error('delete() failed'..hint..': '..abspath)
+ end
+ end
end
end
end
@@ -453,7 +454,6 @@ local function do_rmdir(path)
if not ret then
error('lfs.rmdir('..path..'): '..err)
end
- return ret
end
local function rmdir(path)
diff --git a/test/functional/insert/ctrl_r_spec.lua b/test/functional/insert/ctrl_r_spec.lua
new file mode 100644
index 0000000000..adc3c4b406
--- /dev/null
+++ b/test/functional/insert/ctrl_r_spec.lua
@@ -0,0 +1,19 @@
+local helpers = require('test.functional.helpers')(after_each)
+local clear, feed = helpers.clear, helpers.feed
+local expect, command = helpers.expect, helpers.command
+
+describe('insert-mode Ctrl-R', function()
+ before_each(clear)
+
+ it('works', function()
+ command("let @@ = 'test'")
+ feed('i<C-r>"')
+ expect('test')
+ end)
+
+ it('works with multi-byte text', function()
+ command("let @@ = 'påskägg'")
+ feed('i<C-r>"')
+ expect('påskägg')
+ end)
+end)
diff --git a/test/functional/normal/lang_spec.lua b/test/functional/normal/lang_spec.lua
new file mode 100644
index 0000000000..24d1262f5f
--- /dev/null
+++ b/test/functional/normal/lang_spec.lua
@@ -0,0 +1,63 @@
+local helpers = require('test.functional.helpers')(after_each)
+local clear, insert, eq = helpers.clear, helpers.insert, helpers.eq
+local command, expect = helpers.command, helpers.expect
+local feed, eval = helpers.feed, helpers.eval
+local exc_exec = helpers.exc_exec
+
+describe('gu and gU', function()
+ before_each(clear)
+
+ it('works in any locale with default casemap', function()
+ eq('internal,keepascii', eval('&casemap'))
+ insert("iI")
+ feed("VgU")
+ expect("II")
+ feed("Vgu")
+ expect("ii")
+ end)
+
+ describe('works in Turkish locale', function()
+ clear()
+
+ local err = exc_exec('lang ctype tr_TR.UTF-8')
+ if err ~= 0 then
+ pending("Locale tr_TR.UTF-8 not supported", function() end)
+ return
+ end
+
+ before_each(function()
+ command('lang ctype tr_TR.UTF-8')
+ end)
+
+ it('with default casemap', function()
+ eq('internal,keepascii', eval('&casemap'))
+ -- expect ASCII behavior
+ insert("iI")
+ feed("VgU")
+ expect("II")
+ feed("Vgu")
+ expect("ii")
+ end)
+
+ it('with casemap=""', function()
+ command('set casemap=')
+ -- expect either Turkish locale behavior or ASCII behavior
+ local iupper = eval("toupper('i')")
+ if iupper == "İ" then
+ insert("iI")
+ feed("VgU")
+ expect("İI")
+ feed("Vgu")
+ expect("iı")
+ elseif iupper == "I" then
+ insert("iI")
+ feed("VgU")
+ expect("II")
+ feed("Vgu")
+ expect("ii")
+ else
+ error("expected toupper('i') to be either 'I' or 'İ'")
+ end
+ end)
+ end)
+end)
diff --git a/test/functional/spell/spellfile_spec.lua b/test/functional/spell/spellfile_spec.lua
new file mode 100644
index 0000000000..afd2c1bce4
--- /dev/null
+++ b/test/functional/spell/spellfile_spec.lua
@@ -0,0 +1,110 @@
+local helpers = require('test.functional.helpers')(after_each)
+local lfs = require('lfs')
+
+local eq = helpers.eq
+local clear = helpers.clear
+local meths = helpers.meths
+local exc_exec = helpers.exc_exec
+local rmdir = helpers.rmdir
+local write_file = helpers.write_file
+
+local testdir = 'Xtest-functional-spell-spellfile.d'
+
+describe('spellfile', function()
+ before_each(function()
+ clear()
+ rmdir(testdir)
+ lfs.mkdir(testdir)
+ lfs.mkdir(testdir .. '/spell')
+ end)
+ after_each(function()
+ rmdir(testdir)
+ end)
+ -- ┌ Magic string (#VIMSPELLMAGIC)
+ -- │ ┌ Spell file version (#VIMSPELLVERSION)
+ local spellheader = 'VIMspell\050'
+ it('errors out when prefcond section is truncated', function()
+ meths.set_option('runtimepath', testdir)
+ write_file(testdir .. '/spell/en.ascii.spl',
+ -- ┌ Section identifier (#SN_PREFCOND)
+ -- │ ┌ Section flags (#SNF_REQUIRED or zero)
+ -- │ │ ┌ Section length (4 bytes, MSB first)
+ spellheader .. '\003\001\000\000\000\003'
+ -- ┌ Number of regexes in section (2 bytes, MSB first)
+ -- │ ┌ Condition length (1 byte)
+ -- │ │ ┌ Condition regex (missing!)
+ .. '\000\001\001')
+ meths.set_option('spelllang', 'en')
+ eq('Vim(set):E758: Truncated spell file',
+ exc_exec('set spell'))
+ end)
+ it('errors out when prefcond regexp contains NUL byte', function()
+ meths.set_option('runtimepath', testdir)
+ write_file(testdir .. '/spell/en.ascii.spl',
+ -- ┌ Section identifier (#SN_PREFCOND)
+ -- │ ┌ Section flags (#SNF_REQUIRED or zero)
+ -- │ │ ┌ Section length (4 bytes, MSB first)
+ spellheader .. '\003\001\000\000\000\008'
+ -- ┌ Number of regexes in section (2 bytes, MSB first)
+ -- │ ┌ Condition length (1 byte)
+ -- │ │ ┌ Condition regex
+ -- │ │ │ ┌ End of sections marker
+ .. '\000\001\005ab\000cd\255'
+ -- ┌ LWORDTREE tree length (4 bytes)
+ -- │ ┌ KWORDTREE tree length (4 bytes)
+ -- │ │ ┌ PREFIXTREE tree length
+ .. '\000\000\000\000\000\000\000\000\000\000\000\000')
+ meths.set_option('spelllang', 'en')
+ eq('Vim(set):E759: Format error in spell file',
+ exc_exec('set spell'))
+ end)
+ it('errors out when region contains NUL byte', function()
+ meths.set_option('runtimepath', testdir)
+ write_file(testdir .. '/spell/en.ascii.spl',
+ -- ┌ Section identifier (#SN_REGION)
+ -- │ ┌ Section flags (#SNF_REQUIRED or zero)
+ -- │ │ ┌ Section length (4 bytes, MSB first)
+ spellheader .. '\000\001\000\000\000\008'
+ -- ┌ Regions ┌ End of sections marker
+ .. '01234\00067\255'
+ -- ┌ LWORDTREE tree length (4 bytes)
+ -- │ ┌ KWORDTREE tree length (4 bytes)
+ -- │ │ ┌ PREFIXTREE tree length
+ .. '\000\000\000\000\000\000\000\000\000\000\000\000')
+ meths.set_option('spelllang', 'en')
+ eq('Vim(set):E759: Format error in spell file',
+ exc_exec('set spell'))
+ end)
+ it('errors out when SAL section contains NUL byte', function()
+ meths.set_option('runtimepath', testdir)
+ write_file(testdir .. '/spell/en.ascii.spl',
+ -- ┌ Section identifier (#SN_SAL)
+ -- │ ┌ Section flags (#SNF_REQUIRED or zero)
+ -- │ │ ┌ Section length (4 bytes, MSB first)
+ spellheader .. '\005\001\000\000\000\008'
+ -- ┌ salflags
+ -- │ ┌ salcount (2 bytes, MSB first)
+ -- │ │ ┌ salfromlen (1 byte)
+ -- │ │ │ ┌ Special character
+ -- │ │ │ │┌ salfrom (should not contain NUL)
+ -- │ │ │ ││ ┌ saltolen
+ -- │ │ │ ││ │ ┌ salto
+ -- │ │ │ ││ │ │┌ End of sections marker
+ .. '\000\000\001\0024\000\0017\255'
+ -- ┌ LWORDTREE tree length (4 bytes)
+ -- │ ┌ KWORDTREE tree length (4 bytes)
+ -- │ │ ┌ PREFIXTREE tree length
+ .. '\000\000\000\000\000\000\000\000\000\000\000\000')
+ meths.set_option('spelllang', 'en')
+ eq('Vim(set):E759: Format error in spell file',
+ exc_exec('set spell'))
+ end)
+ it('errors out when spell header contains NUL bytes', function()
+ meths.set_option('runtimepath', testdir)
+ write_file(testdir .. '/spell/en.ascii.spl',
+ spellheader:sub(1, -3) .. '\000\000')
+ meths.set_option('spelllang', 'en')
+ eq('Vim(set):E757: This does not look like a spell file',
+ exc_exec('set spell'))
+ end)
+end)
diff --git a/test/functional/terminal/edit_spec.lua b/test/functional/terminal/edit_spec.lua
index 42a5c768bb..d2b2d8a60c 100644
--- a/test/functional/terminal/edit_spec.lua
+++ b/test/functional/terminal/edit_spec.lua
@@ -45,11 +45,8 @@ describe(':edit term://*', function()
local bufcontents = {}
local winheight = curwinmeths.get_height()
local buf_cont_start = rep_size - sb - winheight + 2
- local function bufline (i)
- return ('%d: foobar'):format(i)
- end
for i = buf_cont_start,(rep_size - 1) do
- bufcontents[#bufcontents + 1] = bufline(i)
+ bufcontents[#bufcontents + 1] = ('%d: foobar'):format(i)
end
bufcontents[#bufcontents + 1] = ''
bufcontents[#bufcontents + 1] = '[Process exited 0]'
diff --git a/test/functional/ui/inccommand_spec.lua b/test/functional/ui/inccommand_spec.lua
index b7a33cb64d..a7be1a9dc8 100644
--- a/test/functional/ui/inccommand_spec.lua
+++ b/test/functional/ui/inccommand_spec.lua
@@ -1,6 +1,7 @@
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local clear = helpers.clear
+local command = helpers.command
local curbufmeths = helpers.curbufmeths
local eq = helpers.eq
local eval = helpers.eval
@@ -21,9 +22,9 @@ local default_text = [[
local function common_setup(screen, inccommand, text)
if screen then
- feed_command("syntax on")
- feed_command("set nohlsearch")
- feed_command("hi Substitute guifg=red guibg=yellow")
+ command("syntax on")
+ command("set nohlsearch")
+ command("hi Substitute guifg=red guibg=yellow")
screen:attach()
screen:set_default_attr_ids({
[1] = {foreground = Screen.colors.Fuchsia},
@@ -46,7 +47,7 @@ local function common_setup(screen, inccommand, text)
})
end
- feed_command("set inccommand=" .. (inccommand and inccommand or ""))
+ command("set inccommand=" .. (inccommand and inccommand or ""))
if text then
insert(text)
@@ -456,7 +457,7 @@ describe(":substitute, 'inccommand' preserves undo", function()
insert("X")
feed("IY<esc>")
feed(":%s/tw/MO/<esc>")
- -- execute("undo") here would cause "Press ENTER".
+ -- feed_command("undo") here would cause "Press ENTER".
feed("u")
expect(default_text:gsub("Inc", "XInc"))
feed("u")
@@ -514,7 +515,7 @@ describe(":substitute, 'inccommand' preserves undo", function()
feed("Ay<esc>")
feed("Az<esc>")
feed(":%s/tw/AR<esc>")
- -- using execute("undo") here will result in a "Press ENTER" prompt
+ -- feed_command("undo") here would cause "Press ENTER".
feed("u")
expect(default_text:gsub("lines", "linesxy"))
feed("u")
@@ -603,7 +604,7 @@ describe(":substitute, 'inccommand' preserves undo", function()
feed_command("set undolevels=-1")
feed(":%s/tw/MO/g<enter>")
- -- using execute("undo") here will result in a "Press ENTER" prompt
+ -- feed_command("undo") here will result in a "Press ENTER" prompt
feed("u")
if case == "split" then
screen:expect([[
@@ -804,7 +805,6 @@ describe(":substitute, inccommand=split", function()
it('does not show split window for :s/', function()
feed("2gg")
feed(":s/tw")
- wait()
screen:expect([[
Inc substitution on |
two lines |
@@ -1291,14 +1291,14 @@ describe("'inccommand' and :cnoremap", function()
it('work with remapped characters', function()
for _, case in pairs(cases) do
refresh(case)
- local command = "%s/lines/LINES/g"
+ local cmd = "%s/lines/LINES/g"
- for i = 1, string.len(command) do
- local c = string.sub(command, i, i)
+ for i = 1, string.len(cmd) do
+ local c = string.sub(cmd, i, i)
feed_command("cnoremap ".. c .. " " .. c)
end
- feed_command(command)
+ feed_command(cmd)
expect([[
Inc substitution on
two LINES
diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua
index 2f2cc85dab..afbcd222c7 100644
--- a/test/functional/ui/screen.lua
+++ b/test/functional/ui/screen.lua
@@ -284,18 +284,13 @@ function Screen:wait(check, timeout)
if failure_after_success then
print([[
-Warning: Screen changes have been received after the expected state was seen.
-This is probably due to an indeterminism in the test. Try adding
-`wait()` (or even a separate `screen:expect(...)`) at a point of possible
-indeterminism, typically in between a `feed()` or `execute()` which is non-
-synchronous, and a synchronous api call.
-
-Note that sometimes a `wait` can trigger redraws and consequently generate more
-indeterminism. If adding `wait` calls seems to increase the frequency of these
-messages, try removing every `wait` call in the test.
-
-If everything else fails, use Screen:redraw_debug to help investigate what is
- causing the problem.
+
+Warning: Screen changes were received after the expected state. This indicates
+indeterminism in the test. Try adding wait() (or screen:expect(...)) between
+asynchronous (feed(), nvim_input()) and synchronous API calls.
+ - Use Screen:redraw_debug() to investigate the problem.
+ - wait() can trigger redraws and consequently generate more indeterminism.
+ In that case try removing every wait().
]])
local tb = debug.traceback()
local index = string.find(tb, '\n%s*%[C]')
diff --git a/test/helpers.lua b/test/helpers.lua
index d0b1ad552b..d60d5ba242 100644
--- a/test/helpers.lua
+++ b/test/helpers.lua
@@ -32,6 +32,9 @@ local function glob(initial_path, re, exc_re)
return false
end
+ if is_excluded(initial_path) then
+ return ret
+ end
while #paths_to_check > 0 do
local cur_path = paths_to_check[#paths_to_check]
paths_to_check[#paths_to_check] = nil
@@ -185,7 +188,11 @@ local function check_cores(app, force)
local gdb_db_cmd = 'gdb -n -batch -ex "thread apply all bt full" "$_NVIM_TEST_APP" -c "$_NVIM_TEST_CORE"'
local lldb_db_cmd = 'lldb -Q -o "bt all" -f "$_NVIM_TEST_APP" -c "$_NVIM_TEST_CORE"'
local random_skip = false
- local local_tmpdir = tmpdir_is_local(tmpdir_get()) and tmpdir_get() or nil
+ -- Workspace-local $TMPDIR, scrubbed and pattern-escaped.
+ -- "./Xtest-tmpdir/" => "Xtest%-tmpdir"
+ local local_tmpdir = (tmpdir_is_local(tmpdir_get())
+ and tmpdir_get():gsub('^[ ./]+',''):gsub('%/+$',''):gsub('([^%w])', '%%%1')
+ or nil)
local db_cmd
if hasenv('NVIM_TEST_CORE_GLOB_DIRECTORY') then
initial_path = os.getenv('NVIM_TEST_CORE_GLOB_DIRECTORY')
diff --git a/test/unit/os/env_spec.lua b/test/unit/os/env_spec.lua
index 823b6d6a85..575787a25e 100644
--- a/test/unit/os/env_spec.lua
+++ b/test/unit/os/env_spec.lua
@@ -67,12 +67,37 @@ describe('env function', function()
end)
end)
+ describe('os_shell_is_cmdexe', function()
+ itp('returns true for expected names', function()
+ eq(true, cimp.os_shell_is_cmdexe(to_cstr('cmd.exe')))
+ eq(true, cimp.os_shell_is_cmdexe(to_cstr('cmd')))
+ eq(true, cimp.os_shell_is_cmdexe(to_cstr('CMD.EXE')))
+ eq(true, cimp.os_shell_is_cmdexe(to_cstr('CMD')))
+
+ os_setenv('COMSPEC', '/foo/bar/cmd.exe', 0)
+ eq(true, cimp.os_shell_is_cmdexe(to_cstr('$COMSPEC')))
+ os_setenv('COMSPEC', [[C:\system32\cmd.exe]], 0)
+ eq(true, cimp.os_shell_is_cmdexe(to_cstr('$COMSPEC')))
+ end)
+ itp('returns false for unexpected names', function()
+ eq(false, cimp.os_shell_is_cmdexe(to_cstr('')))
+ eq(false, cimp.os_shell_is_cmdexe(to_cstr('powershell')))
+ eq(false, cimp.os_shell_is_cmdexe(to_cstr(' cmd.exe ')))
+ eq(false, cimp.os_shell_is_cmdexe(to_cstr('cm')))
+ eq(false, cimp.os_shell_is_cmdexe(to_cstr('md')))
+ eq(false, cimp.os_shell_is_cmdexe(to_cstr('cmd.ex')))
+
+ os_setenv('COMSPEC', '/foo/bar/cmd', 0)
+ eq(false, cimp.os_shell_is_cmdexe(to_cstr('$COMSPEC')))
+ end)
+ end)
+
describe('os_getenv', function()
itp('reads an env variable', function()
local name = 'NVIM_UNIT_TEST_GETENV_1N'
local value = 'NVIM_UNIT_TEST_GETENV_1V'
eq(NULL, os_getenv(name))
- -- need to use os_setenv, because lua dosn't have a setenv function
+ -- Use os_setenv because Lua dosen't have setenv.
os_setenv(name, value, 1)
eq(value, os_getenv(name))
end)
diff --git a/third-party/cmake/BuildLuarocks.cmake b/third-party/cmake/BuildLuarocks.cmake
index 9ea96b7cc5..7312b6f91b 100644
--- a/third-party/cmake/BuildLuarocks.cmake
+++ b/third-party/cmake/BuildLuarocks.cmake
@@ -137,7 +137,7 @@ if(USE_BUNDLED_BUSTED)
endif()
add_custom_command(OUTPUT ${BUSTED_EXE}
COMMAND ${LUAROCKS_BINARY}
- ARGS build https://raw.githubusercontent.com/Olivine-Labs/busted/v2.0.rc11-0/busted-2.0.rc11-0.rockspec ${LUAROCKS_BUILDARGS}
+ ARGS build https://raw.githubusercontent.com/Olivine-Labs/busted/v2.0.rc12-1/busted-2.0.rc12-1.rockspec ${LUAROCKS_BUILDARGS}
DEPENDS penlight)
add_custom_target(busted
DEPENDS ${BUSTED_EXE})