diff options
236 files changed, 13607 insertions, 6974 deletions
diff --git a/.ci/common/build.sh b/.ci/common/build.sh index f635ee4960..06bdab707f 100644 --- a/.ci/common/build.sh +++ b/.ci/common/build.sh @@ -5,6 +5,9 @@ build_deps() { if [[ "${BUILD_MINGW}" == ON ]]; then DEPS_CMAKE_FLAGS="${DEPS_CMAKE_FLAGS} ${CMAKE_FLAGS_MINGW}" fi + if [[ "${FUNCTIONALTEST}" == "functionaltest-lua" ]]; then + DEPS_CMAKE_FLAGS="${DEPS_CMAKE_FLAGS} -DUSE_BUNDLED_LUA=ON" + fi rm -rf "${DEPS_BUILD_DIR}" diff --git a/.ci/common/test.sh b/.ci/common/test.sh index c1bbd8dc9a..8c32b63ab2 100644 --- a/.ci/common/test.sh +++ b/.ci/common/test.sh @@ -53,7 +53,7 @@ run_unittests() { } run_functionaltests() { - if ! ${MAKE_CMD} -C "${BUILD_DIR}" functionaltest; then + if ! ${MAKE_CMD} -C "${BUILD_DIR}" ${FUNCTIONALTEST}; then asan_check "${LOG_DIR}" valgrind_check "${LOG_DIR}" exit 1 diff --git a/.travis.yml b/.travis.yml index 10219690b3..985a5c5381 100644 --- a/.travis.yml +++ b/.travis.yml @@ -53,6 +53,8 @@ env: # if the tests were successful, but don't have this information # available in before_cache (which is run before after_success). - SUCCESS_MARKER="$BUILD_DIR/.tests_successful" + # default target name for functional tests + - FUNCTIONALTEST=functionaltest matrix: include: @@ -61,6 +63,9 @@ matrix: - os: linux compiler: gcc-5 - os: linux + compiler: gcc-5 + env: FUNCTIONALTEST=functionaltest-lua + - os: linux # Travis creates a cache per compiler. # Set a different value here to store 32-bit # dependencies in a separate cache. diff --git a/CMakeLists.txt b/CMakeLists.txt index 3dbe98ab67..98ffc77b15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,10 @@ cmake_minimum_required(VERSION 2.8.7) project(nvim) +if(POLICY CMP0059) + cmake_policy(SET CMP0059 OLD) # Needed until cmake 2.8.12. #4389 +endif() + # Point CMake at any custom modules we may ship list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") @@ -55,7 +59,7 @@ set_property(CACHE CMAKE_BUILD_TYPE PROPERTY # version string, else it is combined with the result of `git describe`. set(NVIM_VERSION_MAJOR 0) set(NVIM_VERSION_MINOR 1) -set(NVIM_VERSION_PATCH 3) +set(NVIM_VERSION_PATCH 5) set(NVIM_VERSION_PRERELEASE "-dev") # for package maintainers file(TO_CMAKE_PATH ${CMAKE_CURRENT_LIST_DIR}/.git FORCED_GIT_DIR) @@ -363,7 +367,7 @@ endforeach() # Find Lua interpreter include(LuaHelpers) -set(LUA_DEPENDENCIES lpeg MessagePack bit) +set(LUA_DEPENDENCIES lpeg mpack bit) if(NOT LUA_PRG) foreach(CURRENT_LUA_PRG luajit lua) # If LUA_PRG is set find_program() will not search @@ -390,6 +394,7 @@ message(STATUS "Using the Lua interpreter ${LUA_PRG}.") # Setup busted. find_program(BUSTED_PRG busted) +find_program(BUSTED_LUA_PRG busted-lua) if(NOT BUSTED_OUTPUT_TYPE) set(BUSTED_OUTPUT_TYPE "utfTerminal") endif() @@ -501,6 +506,20 @@ if(BUSTED_PRG) DEPENDS ${BENCHMARK_PREREQS}) endif() +if(BUSTED_LUA_PRG) + add_custom_target(functionaltest-lua + COMMAND ${CMAKE_COMMAND} + -DBUSTED_PRG=${BUSTED_LUA_PRG} + -DNVIM_PRG=$<TARGET_FILE:nvim> + -DWORKING_DIR=${CMAKE_CURRENT_SOURCE_DIR} + -DBUSTED_OUTPUT_TYPE=${BUSTED_OUTPUT_TYPE} + -DTEST_DIR=${CMAKE_CURRENT_SOURCE_DIR}/test + -DBUILD_DIR=${CMAKE_BINARY_DIR} + -DTEST_TYPE=functional + -P ${PROJECT_SOURCE_DIR}/cmake/RunTests.cmake + DEPENDS ${FUNCTIONALTEST_PREREQS}) +endif() + if(LUACHECK_PRG) add_custom_target(testlint COMMAND ${CMAKE_COMMAND} diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md index 4abcc4eae1..d9fd758177 100644 --- a/ISSUE_TEMPLATE.md +++ b/ISSUE_TEMPLATE.md @@ -1,9 +1,16 @@ - Neovim version: -- Operating system: -- Terminal emulator: +- [ ] Vim behaves differently? Vim version: +- Operating system/version: +- Terminal name/version: +- `$TERM`: ### Actual behaviour ### Expected behaviour -### Steps to reproduce +### Steps to reproduce using `nvim -u NORC` + +``` +nvim -u NORC + +``` @@ -45,6 +45,11 @@ ifneq (,$(USE_BUNDLED_DEPS)) BUNDLED_CMAKE_FLAG := -DUSE_BUNDLED=$(USE_BUNDLED_DEPS) endif +ifneq (,$(findstring functionaltest-lua,$(MAKECMDGOALS))) + BUNDLED_LUA_CMAKE_FLAG := -DUSE_BUNDLED_LUA=ON + $(shell [ -x .deps/usr/bin/lua ] || rm build/.ran-*) +endif + # For use where we want to make sure only a single job is run. This does issue # a warning, but we need to keep SCRIPTS argument. SINGLE_MAKE = export MAKEFLAGS= ; $(MAKE) @@ -74,7 +79,7 @@ build/.ran-third-party-cmake: ifeq ($(call filter-true,$(USE_BUNDLED_DEPS)),) mkdir -p .deps cd .deps && \ - cmake -G '$(BUILD_TYPE)' $(BUNDLED_CMAKE_FLAG) \ + cmake -G '$(BUILD_TYPE)' $(BUNDLED_CMAKE_FLAG) $(BUNDLED_LUA_CMAKE_FLAG) \ $(DEPS_CMAKE_FLAGS) ../third-party endif mkdir -p build @@ -86,6 +91,9 @@ oldtest: | nvim functionaltest: | nvim +$(BUILD_CMD) -C build functionaltest +functionaltest-lua: | nvim + +$(BUILD_CMD) -C build functionaltest-lua + testlint: | nvim $(BUILD_CMD) -C build testlint @@ -191,6 +191,7 @@ _ERROR_CATEGORIES = [ 'readability/nul', 'readability/todo', 'readability/utf8', + 'readability/increment', 'runtime/arrays', 'runtime/int', 'runtime/invalid_increment', @@ -2291,6 +2292,11 @@ def CheckSpacing(filename, clean_lines, linenum, nesting_state, error): # there's too little whitespace, we get concerned. It's hard to tell, # though, so we punt on this one for now. TODO. + match = Search(r'(?:[^ (*/![])+(?<!\+\+|--)\*', line) + if match: + error(filename, linenum, 'whitespace/operators', 2, + 'Missing space before asterisk in %s' % match.group(0)) + # You should always have whitespace around binary operators. # # Check <= and >= first to avoid false positives with < and >, then @@ -3194,6 +3200,23 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension, error(filename, linenum, 'readability/bool', 4, 'Use %s instead of %s.' % (token.lower(), token)) + # Detect preincrement/predecrement + match = Match(r'^\s*(?:\+\+|--)', line) + if match: + error(filename, linenum, 'readability/increment', 5, + 'Do not use preincrement in statements, ' + 'use postincrement instead') + # Detect preincrement/predecrement in for(;; preincrement) + match = Search(r';\s*(\+\+|--)', line) + if match: + end_pos, end_depth = FindEndOfExpressionInLine(line, match.start(1), 1, + '(', ')') + expr = line[match.start(1):end_pos] + if end_depth == 0 and ';' not in expr and ' = ' not in expr: + error(filename, linenum, 'readability/increment', 4, + 'Do not use preincrement in statements, including ' + 'for(;; action)') + def ProcessLine(filename, file_extension, clean_lines, line, include_state, function_state, nesting_state, error, @@ -3484,6 +3507,7 @@ def main(): if __name__ == '__main__': main() +# vim: ts=4 sts=4 sw=4 # Ignore "too complex" warnings when using pymode. # pylama:ignore=C901 diff --git a/runtime/autoload/man.vim b/runtime/autoload/man.vim index 49663d7e5a..0dfcc424e2 100644 --- a/runtime/autoload/man.vim +++ b/runtime/autoload/man.vim @@ -11,6 +11,8 @@ catch /E145:/ " Ignore the error in restricted mode endtry +" Load man page {page} from {section} +" call man#get_page([{section}, ]{page}) function man#get_page(...) abort let invoked_from_man = (&filetype ==# 'man') @@ -20,21 +22,14 @@ function man#get_page(...) abort elseif a:0 > 2 echoerr 'too many arguments' return - elseif a:0 == 2 - let [page, sect] = [a:2, 0 + a:1] - elseif type(1) == type(a:1) - let [page, sect] = ['<cword>', a:1] - else - let [page, sect] = [a:1, ''] endif - if page == '<cword>' - let page = expand('<cword>') - endif + let sect = get(a:000, 0) + let page = get(a:000, 1, sect) let [page, sect] = s:parse_page_and_section(sect, page) - if 0 + sect > 0 && s:find_page(sect, page) == 0 + if !empty(sect) && s:find_page(sect, page) == 0 let sect = '' endif @@ -54,9 +49,9 @@ function man#get_page(...) abort let thiswin = winnr() wincmd b if winnr() > 1 - exe "norm! " . thiswin . "\<C-W>w" + exec thiswin . 'wincmd w' while 1 - if &filetype == 'man' + if &filetype ==# 'man' break endif wincmd w @@ -80,11 +75,11 @@ function man#get_page(...) abort endif silent exec 'r!/usr/bin/man '.s:cmd(sect, page).' | col -b' " Remove blank lines from top and bottom. - while getline(1) =~ '^\s*$' - silent keepjumps norm! gg"_dd + while getline(1) =~# '^\s*$' + silent keepjumps 1delete _ endwhile - while getline('$') =~ '^\s*$' - silent keepjumps norm! G"_dd + while getline('$') =~# '^\s*$' + silent keepjumps $delete _ endwhile setlocal nomodified setlocal filetype=man @@ -118,15 +113,11 @@ endfunction " Expects a string like 'access' or 'access(2)'. function s:parse_page_and_section(sect, str) abort try - let save_isk = &iskeyword - setlocal iskeyword-=(,) - let page = substitute(a:str, '(*\(\k\+\).*', '\1', '') - let sect = substitute(a:str, '\(\k\+\)(\([^()]*\)).*', '\2', '') - if sect == page || -1 == match(sect, '^[0-9 ]\+$') + let [page, sect] = matchlist(a:str, '\v\C([-.[:alnum:]_]+)%(\(([-.[:alnum:]_]+)\))?')[1:2] + if empty(sect) let sect = a:sect endif catch - let &l:iskeyword = save_isk echoerr 'man.vim: failed to parse: "'.a:str.'"' endtry @@ -134,7 +125,7 @@ function s:parse_page_and_section(sect, str) abort endfunction function s:cmd(sect, page) abort - if 0 + a:sect > 0 + if !empty(a:sect) return s:man_sect_arg.' '.a:sect.' '.a:page endif return a:page @@ -142,10 +133,5 @@ endfunction function s:find_page(sect, page) abort let where = system('/usr/bin/man '.s:man_find_arg.' '.s:cmd(a:sect, a:page)) - if where !~ "^/" - if matchstr(where, " [^ ]*$") !~ "^ /" - return 0 - endif - endif - return 1 + return (where =~# '^ */') endfunction diff --git a/runtime/autoload/msgpack.vim b/runtime/autoload/msgpack.vim index 2bb7ec5b02..2e2697c57f 100644 --- a/runtime/autoload/msgpack.vim +++ b/runtime/autoload/msgpack.vim @@ -356,6 +356,8 @@ let s:MSGPACK_STANDARD_TYPES = { \type(''): 'binary', \type([]): 'array', \type({}): 'map', + \type(v:true): 'boolean', + \type(v:null): 'nil', \} "" @@ -379,7 +381,7 @@ endfunction "" " Dump boolean value. function s:msgpack_dump_boolean(v) abort - return a:v._VAL ? 'TRUE' : 'FALSE' + return (a:v is v:true || (a:v isnot v:false && a:v._VAL)) ? 'TRUE' : 'FALSE' endfunction "" diff --git a/runtime/autoload/phpcomplete.vim b/runtime/autoload/phpcomplete.vim index 6dcddfd43e..7f25d9df33 100644 --- a/runtime/autoload/phpcomplete.vim +++ b/runtime/autoload/phpcomplete.vim @@ -3,7 +3,7 @@ " Maintainer: Dávid Szabó ( complex857 AT gmail DOT com ) " Previous Maintainer: Mikolaj Machowski ( mikmach AT wp DOT pl ) " URL: https://github.com/shawncplus/phpcomplete.vim -" Last Change: 2015 Apr 02 +" Last Change: 2015 Jul 13 " " OPTIONS: " @@ -318,7 +318,7 @@ function! phpcomplete#CompleteGeneral(base, current_namespace, imports) " {{{ \ '^&\?\zs[a-zA-Z_\x7f-\xff][a-zA-Z_0-9\x7f-\xff]*\ze') if f_name =~? '^'.substitute(a:base, '\\', '\\\\', 'g') let f_args = matchstr(i, - \ '^&\?[a-zA-Z_\x7f-\xff][a-zA-Z_0-9\x7f-\xff]*\s*(\zs.\{-}\ze)\_s*\({\|$\)') + \ '^&\?[a-zA-Z_\x7f-\xff][a-zA-Z_0-9\x7f-\xff]*\s*(\zs.\{-}\ze)\_s*\(;\|{\|$\)') let int_functions[f_name.'('] = f_args.')' endif endfor @@ -646,7 +646,7 @@ function! phpcomplete#CompleteUnknownClass(base, context) " {{{ let f_name = matchstr(i, \ '^&\?\zs[a-zA-Z_\x7f-\xff][a-zA-Z_0-9\x7f-\xff]*\ze') let f_args = matchstr(i, - \ '^&\?[a-zA-Z_\x7f-\xff][a-zA-Z_0-9\x7f-\xff]*\s*(\zs.\{-}\ze)\_s*\({\|$\)') + \ '^&\?[a-zA-Z_\x7f-\xff][a-zA-Z_0-9\x7f-\xff]*\s*(\zs.\{-}\ze)\_s*\(;\|{\|$\)') let int_functions[f_name.'('] = f_args.')' endfor @@ -981,7 +981,7 @@ function! phpcomplete#CompleteUserClass(context, base, sccontent, visibility) " let f_name = matchstr(i, \ 'function\s*&\?\zs[a-zA-Z_\x7f-\xff][a-zA-Z_0-9\x7f-\xff]*\ze') let f_args = matchstr(i, - \ 'function\s*&\?[a-zA-Z_\x7f-\xff][a-zA-Z_0-9\x7f-\xff]*\s*(\zs.\{-}\ze)\_s*\({\|\_$\)') + \ 'function\s*&\?[a-zA-Z_\x7f-\xff][a-zA-Z_0-9\x7f-\xff]*\s*(\zs.\{-}\ze)\_s*\(;\|{\|\_$\)') if f_name != '' && stridx(f_name, '__') != 0 let c_functions[f_name.'('] = f_args if g:phpcomplete_parse_docblock_comments @@ -1379,8 +1379,8 @@ function! phpcomplete#GetCallChainReturnType(classname_candidate, class_candidat " Get Structured information of all classes and subclasses including namespace and includes " try to find the method's return type in docblock comment for classstructure in classcontents - let doclock_target_pattern = 'function\s\+&\?'.method.'\|\(public\|private\|protected\|var\).\+\$'.method - let doc_str = phpcomplete#GetDocBlock(split(classstructure.content, '\n'), doclock_target_pattern) + let docblock_target_pattern = 'function\s\+&\?'.method.'\|\(public\|private\|protected\|var\).\+\$'.method + let doc_str = phpcomplete#GetDocBlock(split(classstructure.content, '\n'), docblock_target_pattern) if doc_str != '' break endif @@ -1659,7 +1659,7 @@ function! phpcomplete#GetClassName(start_line, context, current_namespace, impor " function declaration line if line =~? 'function\(\s\+'.function_name_pattern.'\)\?\s*(' - let function_lines = join(reverse(lines), " ") + let function_lines = join(reverse(copy(lines)), " ") " search for type hinted arguments if function_lines =~? 'function\(\s\+'.function_name_pattern.'\)\?\s*(.\{-}'.class_name_pattern.'\s\+'.object && !object_is_array let f_args = matchstr(function_lines, '\cfunction\(\s\+'.function_name_pattern.'\)\?\s*(\zs.\{-}\ze)') @@ -1700,10 +1700,12 @@ function! phpcomplete#GetClassName(start_line, context, current_namespace, impor " try to find the next non-comment or string ";" char let start_col = match(line, '^\s*'.object.'\C\s*=\zs&\?\s\+\(clone\)\?\s*'.variable_name_pattern) - let filelines = reverse(lines) - let [pos, char] = s:getNextCharWithPos(filelines, [a:start_line - i - 1, start_col]) + let filelines = reverse(copy(lines)) + let [pos, char] = s:getNextCharWithPos(filelines, [len(filelines) - i, start_col]) let chars_read = 1 let last_pos = pos + " function_boundary == 0 if we are not in a function + let real_lines_offset = len(function_boundary) == 1 ? 1 : function_boundary[0][0] " read while end of the file while char != 'EOF' && chars_read < 1000 let last_pos = pos @@ -1711,7 +1713,11 @@ function! phpcomplete#GetClassName(start_line, context, current_namespace, impor let chars_read += 1 " we got a candidate if char == ';' - let synIDName = synIDattr(synID(pos[0] + 1, pos[1] + 1, 0), 'name') + " pos values is relative to the function's lines, + " line 0 need to be offsetted with the line number + " where te function was started to get the line number + " in real buffer terms + let synIDName = synIDattr(synID(real_lines_offset + pos[0], pos[1] + 1, 0), 'name') " it's not a comment or string, end search if synIDName !~? 'comment\|string' break @@ -1719,7 +1725,7 @@ function! phpcomplete#GetClassName(start_line, context, current_namespace, impor endif endwhile - let prev_context = phpcomplete#GetCurrentInstruction(last_pos[0] + 1, last_pos[1], b:phpbegin) + let prev_context = phpcomplete#GetCurrentInstruction(real_lines_offset + last_pos[0], last_pos[1], b:phpbegin) if prev_context == '' " cannot get previous context give up return @@ -1739,13 +1745,14 @@ function! phpcomplete#GetClassName(start_line, context, current_namespace, impor " assignment for the variable in question with a function on the right hand side if line =~# '^\s*'.object.'\s*=&\?\s*'.function_invocation_pattern - " try to find the next non-comment or string ";" char let start_col = match(line, '\C^\s*'.object.'\s*=\zs&\?\s*'.function_invocation_pattern) - let filelines = reverse(lines) - let [pos, char] = s:getNextCharWithPos(filelines, [a:start_line - i - 1, start_col]) + let filelines = reverse(copy(lines)) + let [pos, char] = s:getNextCharWithPos(filelines, [len(filelines) - i, start_col]) let chars_read = 1 let last_pos = pos + " function_boundary == 0 if we are not in a function + let real_lines_offset = len(function_boundary) == 1 ? 1 : function_boundary[0][0] " read while end of the file while char != 'EOF' && chars_read < 1000 let last_pos = pos @@ -1753,7 +1760,11 @@ function! phpcomplete#GetClassName(start_line, context, current_namespace, impor let chars_read += 1 " we got a candidate if char == ';' - let synIDName = synIDattr(synID(pos[0] + 1, pos[1] + 1, 0), 'name') + " pos values is relative to the function's lines, + " line 0 need to be offsetted with the line number + " where te function was started to get the line number + " in real buffer terms + let synIDName = synIDattr(synID(real_lines_offset + pos[0], pos[1] + 1, 0), 'name') " it's not a comment or string, end search if synIDName !~? 'comment\|string' break @@ -1761,7 +1772,7 @@ function! phpcomplete#GetClassName(start_line, context, current_namespace, impor endif endwhile - let prev_context = phpcomplete#GetCurrentInstruction(last_pos[0] + 1, last_pos[1], b:phpbegin) + let prev_context = phpcomplete#GetCurrentInstruction(real_lines_offset + last_pos[0], last_pos[1], b:phpbegin) if prev_context == '' " cannot get previous context give up return @@ -1864,6 +1875,9 @@ function! phpcomplete#GetClassLocation(classname, namespace) " {{{ if has_key(g:php_builtin_classes, tolower(a:classname)) && (a:namespace == '' || a:namespace == '\') return 'VIMPHP_BUILTINOBJECT' endif + if has_key(g:php_builtin_interfaces, tolower(a:classname)) && (a:namespace == '' || a:namespace == '\') + return 'VIMPHP_BUILTINOBJECT' + endif if a:namespace == '' || a:namespace == '\' let search_namespace = '\' @@ -1876,7 +1890,7 @@ function! phpcomplete#GetClassLocation(classname, namespace) " {{{ let i = 1 while i < line('.') let line = getline(line('.')-i) - if line =~? '^\s*\(abstract\s\+\|final\s\+\)*\s*\(class\|interface\|trait\)\s*'.a:classname.'\(\s\+\|$\)' && tolower(current_namespace) == search_namespace + if line =~? '^\s*\(abstract\s\+\|final\s\+\)*\s*\(class\|interface\|trait\)\s*'.a:classname.'\(\s\+\|$\|{\)' && tolower(current_namespace) == search_namespace return expand('%:p') else let i += 1 @@ -2048,9 +2062,18 @@ function! phpcomplete#GetClassContentsStructure(file_path, file_lines, class_nam let content = join(getline(cfline, endline), "\n") " Catch extends if content =~? 'extends' - let extends_class = matchstr(content, 'class\_s\+'.a:class_name.'\_s\+extends\_s\+\zs'.class_name_pattern.'\ze') + let extends_string = matchstr(content, '\(class\|interface\)\_s\+'.a:class_name.'\_.\+extends\_s\+\zs\('.class_name_pattern.'\(,\|\_s\)*\)\+\ze\(extends\|{\)') + let extended_classes = map(split(extends_string, '\(,\|\_s\)\+'), 'substitute(v:val, "\\_s\\+", "", "g")') + else + let extended_classes = '' + endif + + " Catch implements + if content =~? 'implements' + let implements_string = matchstr(content, 'class\_s\+'.a:class_name.'\_.\+implements\_s\+\zs\('.class_name_pattern.'\(,\|\_s\)*\)\+\ze') + let implemented_interfaces = map(split(implements_string, '\(,\|\_s\)\+'), 'substitute(v:val, "\\_s\\+", "", "g")') else - let extends_class = '' + let implemented_interfaces = [] endif call searchpair('{', '', '}', 'W') let class_closing_bracket_line = line('.') @@ -2108,8 +2131,11 @@ function! phpcomplete#GetClassContentsStructure(file_path, file_lines, class_nam \ }) let all_extends = used_traits - if extends_class != '' - call add(all_extends, extends_class) + if len(extended_classes) > 0 + call extend(all_extends, extended_classes) + endif + if len(implemented_interfaces) > 0 + call extend(all_extends, implemented_interfaces) endif if len(all_extends) > 0 for class in all_extends @@ -2119,11 +2145,16 @@ function! phpcomplete#GetClassContentsStructure(file_path, file_lines, class_nam endif let classlocation = phpcomplete#GetClassLocation(class, namespace) if classlocation == "VIMPHP_BUILTINOBJECT" - let result += [phpcomplete#GenerateBuiltinClassStub(g:php_builtin_classes[tolower(class)])] + if has_key(g:php_builtin_classes, tolower(class)) + let result += [phpcomplete#GenerateBuiltinClassStub('class', g:php_builtin_classes[tolower(class)])] + endif + if has_key(g:php_builtin_interfaces, tolower(class)) + let result += [phpcomplete#GenerateBuiltinClassStub('interface', g:php_builtin_interfaces[tolower(class)])] + endif elseif classlocation != '' && filereadable(classlocation) let full_file_path = fnamemodify(classlocation, ':p') let result += phpcomplete#GetClassContentsStructure(full_file_path, readfile(full_file_path), class) - elseif tolower(current_namespace) == tolower(namespace) + elseif tolower(current_namespace) == tolower(namespace) && match(join(a:file_lines, "\n"), '\c\(class\|interface\|trait\)\_s\+'.class.'\(\>\|$\)') != -1 " try to find the declaration in the same file. let result += phpcomplete#GetClassContentsStructure(full_file_path, a:file_lines, class) endif @@ -2144,43 +2175,53 @@ function! phpcomplete#GetClassContents(classlocation, class_name) " {{{ endfunction " }}} -function! phpcomplete#GenerateBuiltinClassStub(class_info) " {{{ - let re = 'class '.a:class_info['name']." {" - for [name, initializer] in items(a:class_info.constants) - let re .= "\n\tconst ".name." = ".initializer.";" - endfor - for [name, info] in items(a:class_info.properties) - let re .= "\n\t// @var $".name." ".info.type - let re .= "\n\tpublic $".name.";" - endfor - for [name, info] in items(a:class_info.static_properties) - let re .= "\n\t// @var ".name." ".info.type - let re .= "\n\tpublic static ".name." = ".info.initializer.";" - endfor - for [name, info] in items(a:class_info.methods) - if name =~ '^__' - continue - endif - let re .= "\n\t/**" - let re .= "\n\t * ".name - let re .= "\n\t *" - let re .= "\n\t * @return ".info.return_type - let re .= "\n\t */" - let re .= "\n\tpublic function ".name."(".info.signature."){" - let re .= "\n\t}" - endfor - for [name, info] in items(a:class_info.static_methods) - let re .= "\n\t/**" - let re .= "\n\t * ".name - let re .= "\n\t *" - let re .= "\n\t * @return ".info.return_type - let re .= "\n\t */" - let re .= "\n\tpublic static function ".name."(".info.signature."){" - let re .= "\n\t}" - endfor +function! phpcomplete#GenerateBuiltinClassStub(type, class_info) " {{{ + let re = a:type.' '.a:class_info['name']." {" + if has_key(a:class_info, 'constants') + for [name, initializer] in items(a:class_info.constants) + let re .= "\n\tconst ".name." = ".initializer.";" + endfor + endif + if has_key(a:class_info, 'properties') + for [name, info] in items(a:class_info.properties) + let re .= "\n\t// @var $".name." ".info.type + let re .= "\n\tpublic $".name.";" + endfor + endif + if has_key(a:class_info, 'static_properties') + for [name, info] in items(a:class_info.static_properties) + let re .= "\n\t// @var ".name." ".info.type + let re .= "\n\tpublic static ".name." = ".info.initializer.";" + endfor + endif + if has_key(a:class_info, 'methods') + for [name, info] in items(a:class_info.methods) + if name =~ '^__' + continue + endif + let re .= "\n\t/**" + let re .= "\n\t * ".name + let re .= "\n\t *" + let re .= "\n\t * @return ".info.return_type + let re .= "\n\t */" + let re .= "\n\tpublic function ".name."(".info.signature."){" + let re .= "\n\t}" + endfor + endif + if has_key(a:class_info, 'static_methods') + for [name, info] in items(a:class_info.static_methods) + let re .= "\n\t/**" + let re .= "\n\t * ".name + let re .= "\n\t *" + let re .= "\n\t * @return ".info.return_type + let re .= "\n\t */" + let re .= "\n\tpublic static function ".name."(".info.signature."){" + let re .= "\n\t}" + endfor + endif let re .= "\n}" - return { 'class': a:class_info['name'], + return { a:type : a:class_info['name'], \ 'content': re, \ 'namespace': '', \ 'imports': {}, @@ -2204,8 +2245,11 @@ function! phpcomplete#GetDocBlock(sccontent, search) " {{{ " start backward serch for the comment block while l != 0 let line = a:sccontent[l] - " if comment end found save line position and end search - if line =~? '^\s*\*/' + " if it's a one line docblock like comment and we can just return it right away + if line =~? '^\s*\/\*\*.\+\*\/\s*$' + return substitute(line, '\v^\s*(\/\*\*\s*)|(\s*\*\/)\s*$', '', 'g') + "... or if comment end found save line position and end search + elseif line =~? '^\s*\*/' let comment_end = l break " ... or the line doesn't blank (only whitespace or nothing) end search @@ -2227,6 +2271,7 @@ function! phpcomplete#GetDocBlock(sccontent, search) " {{{ endif let l -= 1 endwhile + " no docblock comment start found if comment_start == -1 return '' @@ -2388,7 +2433,15 @@ function! phpcomplete#GetCurrentNameSpace(file_lines) " {{{ break endif let block_end_pos = searchpairpos('{', '', '}\|\%$', 'W', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"') - silent! exec block_start_pos[0].','.block_end_pos[0].'d' + + if block_end_pos != [0, 0] + " end of the block found, just delete it + silent! exec block_start_pos[0].','.block_end_pos[0].'d _' + else + " block pair not found, use block start as beginning and the end + " of the buffer instead + silent! exec block_start_pos[0].',$d _' + endif endwhile normal! G @@ -2407,8 +2460,8 @@ function! phpcomplete#GetCurrentNameSpace(file_lines) " {{{ while i < file_length let line = file_lines[i] - if line =~? '^\s*namespace\s*'.namespace_name_pattern - let current_namespace = matchstr(line, '\c^\s*namespace\s*\zs'.namespace_name_pattern.'\ze') + if line =~? '^\(<?php\)\?\s*namespace\s*'.namespace_name_pattern + let current_namespace = matchstr(line, '\c^\(<?php\)\?\s*namespace\s*\zs'.namespace_name_pattern.'\ze') break endif @@ -2571,7 +2624,7 @@ endfunction function! phpcomplete#ExpandClassName(classname, current_namespace, imports) " {{{ " if there's an imported class, just use that class's information - if has_key(a:imports, a:classname) && (a:imports[a:classname].kind == 'c' || a:imports[a:classname].kind == 'i') + if has_key(a:imports, a:classname) && (a:imports[a:classname].kind == 'c' || a:imports[a:classname].kind == 'i' || a:imports[a:classname].kind == 't') let namespace = has_key(a:imports[a:classname], 'namespace') ? a:imports[a:classname].namespace : '' return [a:imports[a:classname].name, namespace] endif diff --git a/runtime/autoload/provider/clipboard.vim b/runtime/autoload/provider/clipboard.vim index 5ea9df92fe..9f1737639b 100644 --- a/runtime/autoload/provider/clipboard.vim +++ b/runtime/autoload/provider/clipboard.vim @@ -47,6 +47,11 @@ elseif exists('$DISPLAY') && executable('xclip') let s:paste['+'] = 'xclip -o -selection clipboard' let s:copy['*'] = 'xclip -quiet -i -selection primary' let s:paste['*'] = 'xclip -o -selection primary' +elseif executable('lemonade') + let s:copy['+'] = 'lemonade copy' + let s:paste['+'] = 'lemonade paste' + let s:copy['*'] = 'lemonade copy' + let s:paste['*'] = 'lemonade paste' else echom 'clipboard: No clipboard tool available. See :help nvim-clipboard' finish diff --git a/runtime/autoload/provider/python.vim b/runtime/autoload/provider/python.vim index b769895357..cb9d5c5296 100644 --- a/runtime/autoload/provider/python.vim +++ b/runtime/autoload/provider/python.vim @@ -24,12 +24,10 @@ if s:prog == '' finish endif -let s:plugin_path = expand('<sfile>:p:h').'/script_host.py' - " The Python provider plugin will run in a separate instance of the Python " host. call remote#host#RegisterClone('legacy-python-provider', 'python') -call remote#host#RegisterPlugin('legacy-python-provider', s:plugin_path, []) +call remote#host#RegisterPlugin('legacy-python-provider', 'script_host.py', []) function! provider#python#Call(method, args) if s:err != '' diff --git a/runtime/autoload/provider/python3.vim b/runtime/autoload/provider/python3.vim index 2952f76b40..f4a751e7a2 100644 --- a/runtime/autoload/provider/python3.vim +++ b/runtime/autoload/provider/python3.vim @@ -24,12 +24,10 @@ if s:prog == '' finish endif -let s:plugin_path = expand('<sfile>:p:h').'/script_host.py' - " The Python3 provider plugin will run in a separate instance of the Python3 " host. call remote#host#RegisterClone('legacy-python3-provider', 'python3') -call remote#host#RegisterPlugin('legacy-python3-provider', s:plugin_path, []) +call remote#host#RegisterPlugin('legacy-python3-provider', 'script_host.py', []) function! provider#python3#Call(method, args) if s:err != '' diff --git a/runtime/autoload/provider/pythonx.vim b/runtime/autoload/provider/pythonx.vim index 022ef19914..05815a4896 100644 --- a/runtime/autoload/provider/pythonx.vim +++ b/runtime/autoload/provider/pythonx.vim @@ -5,6 +5,32 @@ endif let s:loaded_pythonx_provider = 1 +function! provider#pythonx#Require(host) abort + let ver = (a:host.orig_name ==# 'python') ? 2 : 3 + + " Python host arguments + let args = ['-c', 'import sys; sys.path.remove(""); import neovim; neovim.start_host()'] + + " Collect registered Python plugins into args + let python_plugins = remote#host#PluginsForHost(a:host.name) + for plugin in python_plugins + call add(args, plugin.path) + endfor + + try + let channel_id = rpcstart((ver == '2' ? + \ provider#python#Prog() : provider#python3#Prog()), args) + if rpcrequest(channel_id, 'poll') == 'ok' + return channel_id + endif + catch + echomsg v:throwpoint + echomsg v:exception + endtry + throw remote#host#LoadErrorForHost(a:host.orig_name, + \ '$NVIM_PYTHON_LOG_FILE') +endfunction + function! provider#pythonx#Detect(major_ver) abort let host_var = (a:major_ver == 2) ? \ 'g:python_host_prog' : 'g:python3_host_prog' diff --git a/runtime/autoload/provider/ruby.vim b/runtime/autoload/provider/ruby.vim new file mode 100644 index 0000000000..aad8c09d28 --- /dev/null +++ b/runtime/autoload/provider/ruby.vim @@ -0,0 +1,34 @@ +" The Ruby provider helper +if exists('s:loaded_ruby_provider') + finish +endif + +let s:loaded_ruby_provider = 1 + +function! provider#ruby#Require(host) abort + " Collect registered Ruby plugins into args + let args = [] + let ruby_plugins = remote#host#PluginsForHost(a:host.name) + + for plugin in ruby_plugins + call add(args, plugin.path) + endfor + + try + let channel_id = rpcstart(provider#ruby#Prog(), args) + + if rpcrequest(channel_id, 'poll') == 'ok' + return channel_id + endif + catch + echomsg v:throwpoint + echomsg v:exception + endtry + + throw remote#host#LoadErrorForHost(a:host.orig_name, + \ '$NVIM_RUBY_LOG_FILE') +endfunction + +function! provider#ruby#Prog() abort + return 'neovim-ruby-host' +endfunction diff --git a/runtime/autoload/provider/script_host.py b/runtime/autoload/provider/script_host.py deleted file mode 100644 index 416b4070bb..0000000000 --- a/runtime/autoload/provider/script_host.py +++ /dev/null @@ -1,247 +0,0 @@ -"""Legacy python/python3-vim emulation.""" -import imp -import io -import logging -import os -import sys - -import neovim - -__all__ = ('ScriptHost',) - - -logger = logging.getLogger(__name__) -debug, info, warn = (logger.debug, logger.info, logger.warn,) - -IS_PYTHON3 = sys.version_info >= (3, 0) - -if IS_PYTHON3: - basestring = str - - if sys.version_info >= (3, 4): - from importlib.machinery import PathFinder - - -@neovim.plugin -class ScriptHost(object): - - """Provides an environment for running python plugins created for Vim.""" - - def __init__(self, nvim): - """Initialize the legacy python-vim environment.""" - self.setup(nvim) - # context where all code will run - self.module = imp.new_module('__main__') - nvim.script_context = self.module - # it seems some plugins assume 'sys' is already imported, so do it now - exec('import sys', self.module.__dict__) - self.legacy_vim = nvim.with_hook(LegacyEvalHook()) - sys.modules['vim'] = self.legacy_vim - - def setup(self, nvim): - """Setup import hooks and global streams. - - This will add import hooks for importing modules from runtime - directories and patch the sys module so 'print' calls will be - forwarded to Nvim. - """ - self.nvim = nvim - info('install import hook/path') - self.hook = path_hook(nvim) - sys.path_hooks.append(self.hook) - nvim.VIM_SPECIAL_PATH = '_vim_path_' - sys.path.append(nvim.VIM_SPECIAL_PATH) - info('redirect sys.stdout and sys.stderr') - self.saved_stdout = sys.stdout - self.saved_stderr = sys.stderr - sys.stdout = RedirectStream(lambda data: nvim.out_write(data)) - sys.stderr = RedirectStream(lambda data: nvim.err_write(data)) - - def teardown(self): - """Restore state modified from the `setup` call.""" - for plugin in self.installed_plugins: - if hasattr(plugin, 'on_teardown'): - plugin.teardown() - nvim = self.nvim - info('uninstall import hook/path') - sys.path.remove(nvim.VIM_SPECIAL_PATH) - sys.path_hooks.remove(self.hook) - info('restore sys.stdout and sys.stderr') - sys.stdout = self.saved_stdout - sys.stderr = self.saved_stderr - - @neovim.rpc_export('python_execute', sync=True) - def python_execute(self, script, range_start, range_stop): - """Handle the `python` ex command.""" - self._set_current_range(range_start, range_stop) - exec(script, self.module.__dict__) - - @neovim.rpc_export('python_execute_file', sync=True) - def python_execute_file(self, file_path, range_start, range_stop): - """Handle the `pyfile` ex command.""" - self._set_current_range(range_start, range_stop) - with open(file_path) as f: - script = compile(f.read(), file_path, 'exec') - exec(script, self.module.__dict__) - - @neovim.rpc_export('python_do_range', sync=True) - def python_do_range(self, start, stop, code): - """Handle the `pydo` ex command.""" - self._set_current_range(start, stop) - nvim = self.nvim - start -= 1 - stop -= 1 - fname = '_vim_pydo' - - # define the function - function_def = 'def %s(line, linenr):\n %s' % (fname, code,) - exec(function_def, self.module.__dict__) - # get the function - function = self.module.__dict__[fname] - while start <= stop: - # Process batches of 5000 to avoid the overhead of making multiple - # API calls for every line. Assuming an average line length of 100 - # bytes, approximately 488 kilobytes will be transferred per batch, - # which can be done very quickly in a single API call. - sstart = start - sstop = min(start + 5000, stop) - lines = nvim.current.buffer.get_line_slice(sstart, sstop, True, - True) - - exception = None - newlines = [] - linenr = sstart + 1 - for i, line in enumerate(lines): - result = function(line, linenr) - if result is None: - # Update earlier lines, and skip to the next - if newlines: - end = sstart + len(newlines) - 1 - nvim.current.buffer.set_line_slice(sstart, end, - True, True, - newlines) - sstart += len(newlines) + 1 - newlines = [] - pass - elif isinstance(result, basestring): - newlines.append(result) - else: - exception = TypeError('pydo should return a string ' + - 'or None, found %s instead' - % result.__class__.__name__) - break - linenr += 1 - - start = sstop + 1 - if newlines: - end = sstart + len(newlines) - 1 - nvim.current.buffer.set_line_slice(sstart, end, True, True, - newlines) - if exception: - raise exception - # delete the function - del self.module.__dict__[fname] - - @neovim.rpc_export('python_eval', sync=True) - def python_eval(self, expr): - """Handle the `pyeval` vim function.""" - return eval(expr, self.module.__dict__) - - def _set_current_range(self, start, stop): - current = self.legacy_vim.current - current.range = current.buffer.range(start, stop) - - -class RedirectStream(io.IOBase): - def __init__(self, redirect_handler): - self.redirect_handler = redirect_handler - - def write(self, data): - self.redirect_handler(data) - - def writelines(self, seq): - self.redirect_handler('\n'.join(seq)) - - -class LegacyEvalHook(neovim.SessionHook): - - """Injects legacy `vim.eval` behavior to a Nvim instance.""" - - def __init__(self): - super(LegacyEvalHook, self).__init__(from_nvim=self._string_eval) - - def _string_eval(self, obj, session, method, kind): - if method == 'vim_eval': - if IS_PYTHON3: - if isinstance(obj, (int, float)): - return str(obj) - elif isinstance(obj, (int, long, float)): - return str(obj) - return obj - - -# This was copied/adapted from nvim-python help -def path_hook(nvim): - def _get_paths(): - return discover_runtime_directories(nvim) - - def _find_module(fullname, oldtail, path): - idx = oldtail.find('.') - if idx > 0: - name = oldtail[:idx] - tail = oldtail[idx+1:] - fmr = imp.find_module(name, path) - module = imp.find_module(fullname[:-len(oldtail)] + name, *fmr) - return _find_module(fullname, tail, module.__path__) - else: - return imp.find_module(fullname, path) - - class VimModuleLoader(object): - def __init__(self, module): - self.module = module - - def load_module(self, fullname, path=None): - # Check sys.modules, required for reload (see PEP302). - if fullname in sys.modules: - return sys.modules[fullname] - return imp.load_module(fullname, *self.module) - - class VimPathFinder(object): - @staticmethod - def find_module(fullname, path=None): - "Method for Python 2.7 and 3.3." - try: - return VimModuleLoader( - _find_module(fullname, fullname, path or _get_paths())) - except ImportError: - return None - - @staticmethod - def find_spec(fullname, path=None, target=None): - "Method for Python 3.4+." - return PathFinder.find_spec(fullname, path or _get_paths(), target) - - def hook(path): - if path == nvim.VIM_SPECIAL_PATH: - return VimPathFinder - else: - raise ImportError - - return hook - - -def discover_runtime_directories(nvim): - rv = [] - for path in nvim.list_runtime_paths(): - if not os.path.exists(path): - continue - path1 = os.path.join(path, 'pythonx') - if IS_PYTHON3: - path2 = os.path.join(path, 'python3') - else: - path2 = os.path.join(path, 'python2') - if os.path.exists(path1): - rv.append(path1) - if os.path.exists(path2): - rv.append(path2) - return rv diff --git a/runtime/autoload/python3complete.vim b/runtime/autoload/python3complete.vim index b02200be7f..f0f3aaddb3 100644 --- a/runtime/autoload/python3complete.vim +++ b/runtime/autoload/python3complete.vim @@ -1,7 +1,7 @@ "python3complete.vim - Omni Completion for python " Maintainer: Aaron Griffin <aaronmgriffin@gmail.com> " Version: 0.9 -" Last Updated: 18 Jun 2009 +" Last Updated: 18 Jun 2009 (small fix 2015 Sep 14 from Debian) " " Roland Puntaier: this file contains adaptations for python3 and is parallel to pythoncomplete.vim " @@ -359,6 +359,7 @@ class PyParser: def __init__(self): self.top = Scope('global',0) self.scope = self.top + self.parserline = 0 def _parsedotname(self,pre=None): #returns (dottedname, nexttoken) diff --git a/runtime/autoload/remote/define.vim b/runtime/autoload/remote/define.vim index dd2482998d..b04a5d2280 100644 --- a/runtime/autoload/remote/define.vim +++ b/runtime/autoload/remote/define.vim @@ -1,7 +1,7 @@ function! remote#define#CommandOnHost(host, method, sync, name, opts) let prefix = '' - if has_key(a:opts, 'range') + if has_key(a:opts, 'range') if a:opts.range == '' || a:opts.range == '%' " -range or -range=%, pass the line range in a list let prefix = '<line1>,<line2>' @@ -30,7 +30,7 @@ function! remote#define#CommandOnHost(host, method, sync, name, opts) exe s:GetCommandPrefix(a:name, a:opts) \ .' call remote#define#CommandBootstrap("'.a:host.'"' \ . ', "'.a:method.'"' - \ . ', "'.a:sync.'"' + \ . ', '.string(a:sync) \ . ', "'.a:name.'"' \ . ', '.string(a:opts).'' \ . ', "'.join(forward_args, '').'"' @@ -94,7 +94,7 @@ function! remote#define#AutocmdOnHost(host, method, sync, name, opts) let bootstrap_def = s:GetAutocmdPrefix(a:name, a:opts) \ .' call remote#define#AutocmdBootstrap("'.a:host.'"' \ . ', "'.a:method.'"' - \ . ', "'.a:sync.'"' + \ . ', '.string(a:sync) \ . ', "'.a:name.'"' \ . ', '.string(a:opts).'' \ . ', "'.escape(forward, '"').'"' @@ -133,7 +133,7 @@ function! remote#define#FunctionOnHost(host, method, sync, name, opts) exe 'autocmd! '.group.' FuncUndefined '.a:name \ .' call remote#define#FunctionBootstrap("'.a:host.'"' \ . ', "'.a:method.'"' - \ . ', "'.a:sync.'"' + \ . ', '.string(a:sync) \ . ', "'.a:name.'"' \ . ', '.string(a:opts) \ . ', "'.group.'"' @@ -157,6 +157,9 @@ endfunction function! remote#define#FunctionOnChannel(channel, method, sync, name, opts) let rpcargs = [a:channel, '"'.a:method.'"', 'a:000'] + if has_key(a:opts, 'range') + call add(rpcargs, '[a:firstline, a:lastline]') + endif call s:AddEval(rpcargs, a:opts) let function_def = s:GetFunctionPrefix(a:name, a:opts) @@ -187,7 +190,7 @@ let s:next_gid = 1 function! s:GetNextAutocmdGroup() let gid = s:next_gid let s:next_gid += 1 - + let group_name = 'RPC_DEFINE_AUTOCMD_GROUP_'.gid " Ensure the group is defined exe 'augroup '.group_name.' | augroup END' @@ -218,7 +221,11 @@ endfunction function! s:GetFunctionPrefix(name, opts) - return "function! ".a:name."(...)\n" + let res = "function! ".a:name."(...)" + if has_key(a:opts, 'range') + let res = res." range" + endif + return res."\n" endfunction diff --git a/runtime/autoload/remote/host.vim b/runtime/autoload/remote/host.vim index 24497b10c2..8faeaed2ea 100644 --- a/runtime/autoload/remote/host.vim +++ b/runtime/autoload/remote/host.vim @@ -2,6 +2,7 @@ let s:hosts = {} let s:plugin_patterns = {} let s:remote_plugins_manifest = fnamemodify(expand($MYVIMRC, 1), ':h') \.'/.'.fnamemodify($MYVIMRC, ':t').'-rplugin~' +let s:plugins_for_host = {} " Register a host by associating it with a factory(funcref) @@ -35,6 +36,9 @@ endfunction " Get a host channel, bootstrapping it if necessary function! remote#host#Require(name) abort + if empty(s:plugins_for_host) + call remote#host#LoadRemotePlugins() + endif if !has_key(s:hosts, a:name) throw 'No host named "'.a:name.'" is registered' endif @@ -123,6 +127,13 @@ function! remote#host#LoadRemotePlugins() abort endfunction +function! remote#host#LoadRemotePluginsEvent(event, pattern) abort + autocmd! nvim-rplugin + call remote#host#LoadRemotePlugins() + execute 'silent doautocmd <nomodeline>' a:event a:pattern +endfunction + + function! s:RegistrationCommands(host) abort " Register a temporary host clone for discovering specs let host_id = a:host.'-registration-clone' @@ -138,7 +149,9 @@ function! s:RegistrationCommands(host) abort endfor let channel = remote#host#Require(host_id) let lines = [] + let registered = [] for path in paths + unlet! specs let specs = rpcrequest(channel, 'specs', path) if type(specs) != type([]) " host didn't return a spec list, indicates a failure while loading a @@ -151,9 +164,10 @@ function! s:RegistrationCommands(host) abort call add(lines, " \\ ".string(spec).",") endfor call add(lines, " \\ ])") + call add(registered, path) endfor echomsg printf("remote/host: %s host registered plugins %s", - \ a:host, string(map(copy(paths), "fnamemodify(v:val, ':t')"))) + \ a:host, string(map(registered, "fnamemodify(v:val, ':t')"))) " Delete the temporary host clone call rpcstop(s:hosts[host_id].channel) @@ -163,7 +177,7 @@ function! s:RegistrationCommands(host) abort endfunction -function! s:UpdateRemotePlugins() abort +function! remote#host#UpdateRemotePlugins() abort let commands = [] let hosts = keys(s:hosts) for host in hosts @@ -185,10 +199,6 @@ function! s:UpdateRemotePlugins() abort endfunction -command! UpdateRemotePlugins call s:UpdateRemotePlugins() - - -let s:plugins_for_host = {} function! remote#host#PluginsForHost(host) abort if !has_key(s:plugins_for_host, a:host) let s:plugins_for_host[a:host] = [] @@ -197,40 +207,25 @@ function! remote#host#PluginsForHost(host) abort endfunction -" Registration of standard hosts - -" Python/Python3 {{{ -function! s:RequirePythonHost(host) abort - let ver = (a:host.orig_name ==# 'python') ? 2 : 3 - - " Python host arguments - let args = ['-c', 'import sys; sys.path.remove(""); import neovim; neovim.start_host()'] - - " Collect registered Python plugins into args - let python_plugins = remote#host#PluginsForHost(a:host.name) - for plugin in python_plugins - call add(args, plugin.path) - endfor - - try - let channel_id = rpcstart((ver == '2' ? - \ provider#python#Prog() : provider#python3#Prog()), args) - if rpcrequest(channel_id, 'poll') == 'ok' - return channel_id - endif - catch - echomsg v:throwpoint - echomsg v:exception - endtry - throw 'Failed to load '. a:host.orig_name . ' host. '. +function! remote#host#LoadErrorForHost(host, log) abort + return 'Failed to load '. a:host . ' host. '. \ 'You can try to see what happened '. \ 'by starting Neovim with the environment variable '. - \ '$NVIM_PYTHON_LOG_FILE set to a file and opening '. - \ 'the generated log file. Also, the host stderr will be available '. + \ a:log . ' set to a file and opening the generated '. + \ 'log file. Also, the host stderr will be available '. \ 'in Neovim log, so it may contain useful information. '. \ 'See also ~/.nvimlog.' endfunction -call remote#host#Register('python', '*.py', function('s:RequirePythonHost')) -call remote#host#Register('python3', '*.py', function('s:RequirePythonHost')) -" }}} + +" Registration of standard hosts + +" Python/Python3 +call remote#host#Register('python', '*', + \ function('provider#pythonx#Require')) +call remote#host#Register('python3', '*', + \ function('provider#pythonx#Require')) + +" Ruby +call remote#host#Register('ruby', '*.rb', + \ function('provider#ruby#Require')) diff --git a/runtime/autoload/spellfile.vim b/runtime/autoload/spellfile.vim index c32dd5df9b..a5ffa514ea 100644 --- a/runtime/autoload/spellfile.vim +++ b/runtime/autoload/spellfile.vim @@ -1,6 +1,4 @@ " Vim script to download a missing spell file -" Maintainer: Bram Moolenaar <Bram@vim.org> -" Last Change: 2012 Jan 08 if !exists('g:spellfile_URL') " Prefer using http:// when netrw should be able to use it, since @@ -43,22 +41,23 @@ function! spellfile#LoadFile(lang) if len(dirlist) == 0 let dir_to_create = spellfile#WritableSpellDir() if &verbose || dir_to_create != '' - echomsg 'spellfile#LoadFile(): There is no writable spell directory.' + echomsg 'spellfile#LoadFile(): No (writable) spell directory found.' endif if dir_to_create != '' - if confirm("Shall I create " . dir_to_create, "&Yes\n&No", 2) == 1 - " After creating the directory it should show up in the list. - call mkdir(dir_to_create, "p") - let [dirlist, dirchoices] = spellfile#GetDirChoices() - endif + call mkdir(dir_to_create, "p") + " Now it should show up in the list. + let [dirlist, dirchoices] = spellfile#GetDirChoices() endif if len(dirlist) == 0 + echomsg 'Failed to create: '.dir_to_create return + else + echomsg 'Created '.dir_to_create endif endif - let msg = 'Cannot find spell file for "' . a:lang . '" in ' . &enc - let msg .= "\nDo you want me to try downloading it?" + let msg = 'No spell file for "' . a:lang . '" in ' . &enc + let msg .= "\nDownload it?" if confirm(msg, "&Yes\n&No", 2) == 1 let enc = &encoding if enc == 'iso-8859-15' @@ -78,78 +77,77 @@ function! spellfile#LoadFile(lang) " Careful: Nread() may have opened a new window for the error message, " we need to go back to our own buffer and window. if newbufnr != winbufnr(0) - let winnr = bufwinnr(newbufnr) - if winnr == -1 - " Our buffer has vanished!? Open a new window. - echomsg "download buffer disappeared, opening a new one" - new - setlocal bin fenc= - else - exe winnr . "wincmd w" - endif + let winnr = bufwinnr(newbufnr) + if winnr == -1 + " Our buffer has vanished!? Open a new window. + echomsg "download buffer disappeared, opening a new one" + new + setlocal bin fenc= + else + exe winnr . "wincmd w" + endif endif if newbufnr == winbufnr(0) - " We are back the old buffer, remove any (half-finished) download. - g/^/d + " We are back the old buffer, remove any (half-finished) download. + g/^/d_ else - let newbufnr = winbufnr(0) + let newbufnr = winbufnr(0) endif let fname = a:lang . '.ascii.spl' echo 'Could not find it, trying ' . fname . '...' call spellfile#Nread(fname) if getline(2) !~ 'VIMspell' - echo 'Sorry, downloading failed' - exe newbufnr . "bwipe!" - return + echo 'Download failed' + exe newbufnr . "bwipe!" + return endif endif " Delete the empty first line and mark the file unmodified. - 1d + 1d_ set nomod - let msg = "In which directory do you want to write the file:" - for i in range(len(dirlist)) - let msg .= "\n" . (i + 1) . '. ' . dirlist[i] - endfor - let dirchoice = confirm(msg, dirchoices) - 2 + if len(dirlist) == 1 + let dirchoice = 0 + else + let msg = "In which directory do you want to write the file:" + for i in range(len(dirlist)) + let msg .= "\n" . (i + 1) . '. ' . dirlist[i] + endfor + let dirchoice = confirm(msg, dirchoices) - 2 + endif if dirchoice >= 0 if exists('*fnameescape') - let dirname = fnameescape(dirlist[dirchoice]) + let dirname = fnameescape(dirlist[dirchoice]) else - let dirname = escape(dirlist[dirchoice], ' ') + let dirname = escape(dirlist[dirchoice], ' ') endif setlocal fenc= exe "write " . dirname . '/' . fname - " Also download the .sug file, if the user wants to. - let msg = "Do you want me to try getting the .sug file?\n" - let msg .= "This will improve making suggestions for spelling mistakes,\n" - let msg .= "but it uses quite a bit of memory." - if confirm(msg, "&No\n&Yes") == 2 - g/^/d - let fname = substitute(fname, '\.spl$', '.sug', '') - echo 'Downloading ' . fname . '...' - call spellfile#Nread(fname) - if getline(2) =~ 'VIMsug' - 1d - exe "write " . dirname . '/' . fname - set nomod - else - echo 'Sorry, downloading failed' - " Go back to our own buffer/window, Nread() may have taken us to - " another window. - if newbufnr != winbufnr(0) - let winnr = bufwinnr(newbufnr) - if winnr != -1 - exe winnr . "wincmd w" - endif - endif - if newbufnr == winbufnr(0) - set nomod - endif - endif + " Also download the .sug file. + g/^/d_ + let fname = substitute(fname, '\.spl$', '.sug', '') + echo 'Downloading ' . fname . '...' + call spellfile#Nread(fname) + if getline(2) =~ 'VIMsug' + 1d_ + exe "write " . dirname . '/' . fname + set nomod + else + echo 'Download failed' + " Go back to our own buffer/window, Nread() may have taken us to + " another window. + if newbufnr != winbufnr(0) + let winnr = bufwinnr(newbufnr) + if winnr != -1 + exe winnr . "wincmd w" + endif + endif + if newbufnr == winbufnr(0) + set nomod + endif endif endif diff --git a/runtime/autoload/tohtml.vim b/runtime/autoload/tohtml.vim index 5cb23a6146..d972ad63fe 100644 --- a/runtime/autoload/tohtml.vim +++ b/runtime/autoload/tohtml.vim @@ -1,6 +1,6 @@ " Vim autoload file for the tohtml plugin. " Maintainer: Ben Fritz <fritzophrenic@gmail.com> -" Last Change: 2013 Jun 19 +" Last Change: 2013 Sep 03 " " Additional contributors: " @@ -302,7 +302,7 @@ func! tohtml#Convert2HTML(line1, line2) "{{{ else "{{{ let win_list = [] let buf_list = [] - windo | if &diff | call add(win_list, winbufnr(0)) | endif + windo if &diff | call add(win_list, winbufnr(0)) | endif let s:settings.whole_filler = 1 let g:html_diff_win_num = 0 for window in win_list diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt index ec5818e16f..1aa2a626aa 100644 --- a/runtime/doc/autocmd.txt +++ b/runtime/doc/autocmd.txt @@ -1,4 +1,4 @@ -*autocmd.txt* For Vim version 7.4. Last change: 2015 Mar 21 +*autocmd.txt* For Vim version 7.4. Last change: 2015 Aug 18 VIM REFERENCE MANUAL by Bram Moolenaar @@ -770,13 +770,15 @@ OptionSet After setting an option. The pattern is it's global or local scoped and |<amatch>| indicates what option has been set. - Note: It's a bad idea, to reset an option - during this autocommand, since this will - probably break plugins. You can always use - |:noa| to prevent triggering this autocommand. - Could be used, to check for existence of the - 'backupdir' and 'undodir' options and create - directories, if they don't exist yet. + Usage example: Check for the existence of the + directory in the 'backupdir' and 'undodir' + options, create the directory if it doesn't + exist yet. + + Note: It's a bad idea to reset an option + during this autocommand, this may break a + plugin. You can always use `:noa` to prevent + triggering this autocommand. *QuickFixCmdPre* QuickFixCmdPre Before a quickfix command is run (|:make|, @@ -1100,7 +1102,7 @@ Instead of a pattern buffer-local autocommands use one of these forms: Examples: > :au CursorHold <buffer> echo 'hold' :au CursorHold <buffer=33> echo 'hold' - :au CursorHold <buffer=abuf> echo 'hold' + :au BufNewFile * au CursorHold <buffer=abuf> echo 'hold' All the commands for autocommands also work with buffer-local autocommands, simply use the special string instead of the pattern. Examples: > diff --git a/runtime/doc/change.txt b/runtime/doc/change.txt index cc8699f21f..56b45497dc 100644 --- a/runtime/doc/change.txt +++ b/runtime/doc/change.txt @@ -1,4 +1,4 @@ -*change.txt* For Vim version 7.4. Last change: 2015 Jun 25 +*change.txt* For Vim version 7.4. Last change: 2015 Sep 06 VIM REFERENCE MANUAL by Bram Moolenaar @@ -622,9 +622,9 @@ For MS-Windows: $TMP, $TEMP, $USERPROFILE, current-dir. may add [flags], see |:s_flags|. Note that after `:substitute` the '&' flag can't be used, it's recognized as a pattern separator. - The space between `:substitute` and the 'c', 'g' and - 'r' flags isn't required, but in scripts it's a good - idea to keep it to avoid confusion. + The space between `:substitute` and the 'c', 'g', + 'i', 'I' and 'r' flags isn't required, but in scripts + it's a good idea to keep it to avoid confusion. :[range]~[&][flags] [count] *:~* Repeat last substitute with same substitute string @@ -1102,7 +1102,7 @@ Rationale: In Vi the "y" command followed by a backwards motion would With a linewise yank command the cursor is put in the first line, but the column is unmodified, thus it may not be on the first yanked character. -There are nine types of registers: *registers* *E354* +There are ten types of registers: *registers* *E354* 1. The unnamed register "" 2. 10 numbered registers "0 to "9 3. The small delete register "- diff --git a/runtime/doc/cmdline.txt b/runtime/doc/cmdline.txt index ae808a4a9b..5e02c44709 100644 --- a/runtime/doc/cmdline.txt +++ b/runtime/doc/cmdline.txt @@ -1,4 +1,4 @@ -*cmdline.txt* For Vim version 7.4. Last change: 2014 Sep 06 +*cmdline.txt* For Vim version 7.4. Last change: 2015 Sep 25 VIM REFERENCE MANUAL by Bram Moolenaar @@ -565,6 +565,7 @@ starts editing the three files "foo bar", "goes to" and "school ". When you want to use the special characters '"' or '|' in a command, or want to use '%' or '#' in a file name, precede them with a backslash. The backslash is not required in a range and in the ":substitute" command. +See also |`=|. *:_!* The '!' (bang) character after an Ex command makes the command behave in a @@ -714,13 +715,13 @@ to insert special things while typing you can use the CTRL-R command. For example, "%" stands for the current file name, while CTRL-R % inserts the current file name right away. See |c_CTRL-R|. -Note: If you want to avoid the special characters in a Vim script you may want -to use |fnameescape()|. +Note: If you want to avoid the effects of special characters in a Vim script +you may want to use |fnameescape()|. Also see |`=|. In Ex commands, at places where a file name can be used, the following characters have a special meaning. These can also be used in the expression -function expand() |expand()|. +function |expand()|. % Is replaced with the current file name. *:_%* *c_%* # Is replaced with the alternate file name. *:_#* *c_#* This is remembered for every window. @@ -755,6 +756,7 @@ it, no matter how many backslashes. # alternate.file \# # \\# \# +Also see |`=|. *:<cword>* *:<cWORD>* *:<cfile>* *<cfile>* *:<sfile>* *<sfile>* *:<afile>* *<afile>* @@ -776,13 +778,13 @@ Note: these are typed literally, they are not special keys! <afile> only when the file name isn't used to match with (for FileType, Syntax and SpellFileMissing events). <sfile> When executing a ":source" command, is replaced with the - file name of the sourced file. *E498* - When executing a function, is replaced with - "function {function-name}"; function call nesting is - indicated like this: - "function {function-name1}..{function-name2}". Note that - filename-modifiers are useless when <sfile> is used inside - a function. + file name of the sourced file. *E498* + When executing a function, is replaced with: + "function {function-name}[{lnum}]" + function call nesting is indicated like this: + "function {function-name1}[{lnum}]..{function-name2}[{lnum}]" + Note that filename-modifiers are useless when <sfile> is + used inside a function. <slnum> When executing a ":source" command, is replaced with the line number. *E842* When executing a function it's the line number relative to @@ -844,7 +846,7 @@ These modifiers can be given, in this order: :gs?pat?sub? Substitute all occurrences of "pat" with "sub". Otherwise this works like ":s". - :S Escape special characters for use with a shell command (see + :S Escape special characters for use with a shell command (see |shellescape()|). Must be the last one. Examples: > :!dir <cfile>:S :call system('chmod +w -- ' . expand('%:S')) @@ -897,9 +899,8 @@ name). This is included for backwards compatibility with version 3.0, the Note: Where a file name is expected wildcards expansion is done. On Unix the shell is used for this, unless it can be done internally (for speed). -Backticks also work, like in > +Unless in |restricted-mode|, backticks work also, like in > :n `echo *.c` -(backtick expansion is not possible in |restricted-mode|) But expansion is only done if there are any wildcards before expanding the '%', '#', etc.. This avoids expanding wildcards inside a file name. If you want to expand the result of <cfile>, add a wildcard character to it. @@ -910,6 +911,7 @@ Examples: (alternate file name is "?readme?") :e #.* :e {files matching "?readme?.*"} :cd <cfile> :cd {file name under cursor} :cd <cfile>* :cd {file name under cursor plus "*" and then expanded} +Also see |`=|. When the expanded argument contains a "!" and it is used for a shell command (":!cmd", ":r !cmd" or ":w !cmd"), the "!" is escaped with a backslash to @@ -936,6 +938,8 @@ for the file "$home" in the root directory. A few examples: /\$home file "$home" in root directory \\$home file "\\", followed by expanded $home +Also see |`=|. + ============================================================================== 7. Command-line window *cmdline-window* *cmdwin* *command-line-window* diff --git a/runtime/doc/diff.txt b/runtime/doc/diff.txt index 8c9cdc3800..77603b1e58 100644 --- a/runtime/doc/diff.txt +++ b/runtime/doc/diff.txt @@ -1,4 +1,4 @@ -*diff.txt* For Vim version 7.4. Last change: 2015 Feb 03 +*diff.txt* For Vim version 7.4. Last change: 2015 Jul 03 VIM REFERENCE MANUAL by Bram Moolenaar @@ -124,8 +124,9 @@ file for a moment and come back to the same file and be in diff mode again. if the current window does not have 'diff' set then no options in it are changed. -The ":diffoff" command resets the relevant options to the values they had when -using |:diffsplit|, |:diffpatch| , |:diffthis|. or starting Vim in diff mode. +The `:diffoff` command resets the relevant options to the values they had when +using `:diffsplit`, `:diffpatch` , `:diffthis`. or starting Vim in diff mode. +When using `:diffoff` twice the last saved values are restored. Otherwise they are set to their default value: 'diff' off diff --git a/runtime/doc/editing.txt b/runtime/doc/editing.txt index bcb89f6527..0ad917006f 100644 --- a/runtime/doc/editing.txt +++ b/runtime/doc/editing.txt @@ -1,4 +1,4 @@ -*editing.txt* For Vim version 7.4. Last change: 2015 Apr 18 +*editing.txt* For Vim version 7.4. Last change: 2015 Aug 25 VIM REFERENCE MANUAL by Bram Moolenaar @@ -378,25 +378,38 @@ Finds files: /usr/include/sys/types.h /usr/inc_old/types.h *backtick-expansion* *`-expansion* -On Unix and a few other systems you can also use backticks in the file name, -for example: > - :e `find . -name ver\\*.c -print` -The backslashes before the star are required to prevent "ver*.c" to be -expanded by the shell before executing the find program. +On Unix and a few other systems you can also use backticks for the file name +argument, for example: > + :next `find . -name ver\\*.c -print` + :view `ls -t *.patch \| head -n1` +The backslashes before the star are required to prevent the shell from +expanding "ver*.c" prior to execution of the find program. The backslash +before the shell pipe symbol "|" prevents Vim from parsing it as command +termination. This also works for most other systems, with the restriction that the backticks must be around the whole item. It is not possible to have text directly before the first or just after the last backtick. *`=* -You can have the backticks expanded as a Vim expression, instead of an -external command, by using the syntax `={expr}` e.g.: > +You can have the backticks expanded as a Vim expression, instead of as an +external command, by putting an equal sign right after the first backtick, +e.g.: > :e `=tempname()` The expression can contain just about anything, thus this can also be used to avoid the special meaning of '"', '|', '%' and '#'. However, 'wildignore' does apply like to other wildcards. + +Environment variables in the expression are expanded when evaluating the +expression, thus this works: > + :e `=$HOME . '/.vimrc'` +This does not work, $HOME is inside a string and used literally: > + :e `='$HOME' . '/.vimrc'` + If the expression returns a string then names are to be separated with line breaks. When the result is a |List| then each item is used as a name. Line breaks also separate names. +Note that such expressions are only supported in places where a filename is +expected as an argument to an Ex-command. *++opt* *[++opt]* The [++opt] argument can be used to force the value of 'fileformat', @@ -1203,12 +1216,18 @@ use has("browsefilter"): > ============================================================================== 7. The current directory *current-directory* -You may use the |:cd| and |:lcd| commands to change to another directory, so -you will not have to type that directory name in front of the file names. It -also makes a difference for executing external commands, e.g. ":!ls". +You can use |:cd|, |:tcd| and |:lcd| to change to another directory, so you +will not have to type that directory name in front of the file names. It also +makes a difference for executing external commands, e.g. ":!ls" or ":te ls". + +There are three current-directory "scopes": global, tab and window. The +window-local working directory takes precedence over the tab-local +working directory, which in turn takes precedence over the global +working directory. If a local working directory (tab or window) does not +exist, the next-higher scope in the hierarchy applies. -Changing directory fails when the current buffer is modified, the '.' flag is -present in 'cpoptions' and "!" is not used in the command. +Commands for changing the working directory can be suffixed with a bang "!" +(e.g. |:cd!|) which is ignored, for compatibility with Vim. *:cd* *E747* *E472* :cd[!] On non-Unix systems: Print the current directory @@ -1233,29 +1252,50 @@ present in 'cpoptions' and "!" is not used in the command. *:chd* *:chdir* :chd[ir][!] [path] Same as |:cd|. + *:tc* *:tcd* *E5000* *E5001* *E5002* +:tc[d][!] {path} Like |:cd|, but set the current directory for the + current tab and window. The current directory for + other tabs and windows is not changed. + + *:tcd-* +:tcd[!] - Change to the previous current directory (before the + previous ":tcd {path}" command). + + *:tch* *:tchdir* +:tch[dir][!] Same as |:tcd|. + *:lc* *:lcd* :lc[d][!] {path} Like |:cd|, but only set the current directory for the current window. The current directory for other - windows is not changed. + windows or any tabs is not changed. *:lch* *:lchdir* :lch[dir][!] Same as |:lcd|. + *:lcd-* +:lcd[!] - Change to the previous current directory (before the + previous ":tcd {path}" command). + *:pw* *:pwd* *E187* :pw[d] Print the current directory name. Also see |getcwd()|. -So long as no |:lcd| command has been used, all windows share the same current -directory. Using a command to jump to another window doesn't change anything -for the current directory. -When a |:lcd| command has been used for a window, the specified directory -becomes the current directory for that window. Windows where the |:lcd| -command has not been used stick to the global current directory. When jumping -to another window the current directory will become the last specified local -current directory. If none was specified, the global current directory is -used. -When a |:cd| command is used, the current window will lose his local current -directory and will use the global current directory from now on. +So long as no |:tcd| or |:lcd| command has been used, all windows share the +same "current directory". Using a command to jump to another window doesn't +change anything for the current directory. + +When |:lcd| has been used for a window, the specified directory becomes the +current directory for that window. Windows where the |:lcd| command has not +been used stick to the global or tab-local directory. When jumping to another +window the current directory will become the last specified local current +directory. If none was specified, the global or tab-local directory is used. + +When changing tabs the same behaviour applies. If the current tab has no +local working directory the global working directory is used. When a |:cd| +command is used, the current window and tab will lose their local current +directories and will use the global current directory from now on. When +a |:tcd| command is used, only the current window will lose its local working +directory. After using |:cd| the full path name will be used for reading and writing files. On some networked file systems this may cause problems. The result of @@ -1292,7 +1332,7 @@ There are a few things to remember when editing binary files: and when the file is written the <NL> will be replaced with <CR> <NL>. - <Nul> characters are shown on the screen as ^@. You can enter them with "CTRL-V CTRL-@" or "CTRL-V 000". -- To insert a <NL> character in the file split up a line. When writing the +- To insert a <NL> character in the file split a line. When writing the buffer to a file a <NL> will be written for the <EOL>. - Vim normally appends an <EOL> at the end of the file if there is none. Setting the 'binary' option prevents this. If you want to add the final @@ -1304,9 +1344,7 @@ There are a few things to remember when editing binary files: 9. Encryption *encryption* *:X* *E817* *E818* *E819* *E820* -Support for editing encrypted files has been removed, but may be added back in -the future. See the following discussions for more information: - +Support for editing encrypted files has been removed. https://github.com/neovim/neovim/issues/694 https://github.com/neovim/neovim/issues/701 diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 36613ba6b3..f6bdde2d39 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -1,4 +1,4 @@ -*eval.txt* For Vim version 7.4. Last change: 2015 Jun 26 +*eval.txt* For Vim version 7.4. Last change: 2016 Jan 16 VIM REFERENCE MANUAL by Bram Moolenaar @@ -916,6 +916,11 @@ just above, except that indexes out of range cause an error. Examples: > Using expr8[expr1] or expr8[expr1a : expr1b] on a |Funcref| results in an error. +Watch out for confusion between a namespace and a variable followed by a colon +for a sublist: > + mylist[n:] " uses variable n + mylist[s:] " uses namespace s:, error! + expr8.name entry in a |Dictionary| *expr-entry* @@ -1413,6 +1418,13 @@ v:exception The value of the exception most recently caught and not :endtry < Output: "caught oops". + *v:false* *false-variable* +v:false Special value used to put "false" in JSON and msgpack. See + |json_encode()|. This value is converted to "false" when used + as a String (e.g. in |expr5| with string concatenation + operator) and to zero when used as a Number (e.g. in |expr5| + or |expr7| when used with numeric operators). + *v:fcs_reason* *fcs_reason-variable* v:fcs_reason The reason why the |FileChangedShell| event was triggered. Can be used in an autocommand to decide what to do and/or what @@ -1491,7 +1503,9 @@ v:hlsearch Variable that indicates whether search highlighting is on. this variable to zero acts like the |:nohlsearch| command, setting it to one acts like > let &hlsearch = &hlsearch -< +< Note that the value is restored when returning from a + function. |function-search-undo|. + *v:insertmode* *insertmode-variable* v:insertmode Used for the |InsertEnter| and |InsertChange| autocommand events. Values: @@ -1550,6 +1564,13 @@ v:msgpack_types Dictionary containing msgpack types used by |msgpackparse()| (not editable) empty lists. To check whether some list is one of msgpack types, use |is| operator. + *v:null* *null-variable* +v:null Special value used to put "null" in JSON and NIL in msgpack. + See |json_encode()|. This value is converted to "null" when + used as a String (e.g. in |expr5| with string concatenation + operator) and to zero when used as a Number (e.g. in |expr5| + or |expr7| when used with numeric operators). + *v:oldfiles* *oldfiles-variable* v:oldfiles List of file names that is loaded from the |shada| file on startup. These are the files that Vim remembers marks for. @@ -1715,6 +1736,13 @@ v:throwpoint The point where the exception most recently caught and not :endtry < Output: "Exception from test.vim, line 2" + *v:true* *true-variable* +v:true Special value used to put "true" in JSON and msgpack. See + |json_encode()|. This value is converted to "true" when used + as a String (e.g. in |expr5| with string concatenation + operator) and to one when used as a Number (e.g. in |expr5| or + |expr7| when used with numeric operators). + *v:val* *val-variable* v:val Value of the current item of a |List| or |Dictionary|. Only valid while evaluating the expression used with |map()| and @@ -1735,7 +1763,8 @@ v:version Version number of Vim: Major version number times 100 plus v:warningmsg Last given warning message. It's allowed to set this variable. *v:windowid* *windowid-variable* {Nvim} -v:windowid Is a no-op at the moment; the value is always set to 0. +v:windowid Application-specific window ID ("window handle" in MS-Windows) + which may be set by any attached UI. Defaults to zero. Note: for windows inside Vim use |winnr()|. ============================================================================== @@ -1772,7 +1801,7 @@ bufexists( {expr}) Number TRUE if buffer {expr} exists buflisted( {expr}) Number TRUE if buffer {expr} is listed bufloaded( {expr}) Number TRUE if buffer {expr} is loaded bufname( {expr}) String Name of the buffer {expr} -bufnr( {expr}) Number Number of the buffer {expr} +bufnr( {expr} [, {create}]) Number Number of the buffer {expr} bufwinnr( {expr}) Number window number of buffer {expr} byte2line( {byte}) Number line number at byte count {byte} byteidx( {expr}, {nr}) Number byte index of {nr}'th char in {expr} @@ -1801,7 +1830,7 @@ cursor( {lnum}, {col} [, {off}]) Number move cursor to {lnum}, {col}, {off} cursor( {list}) Number move cursor to position in {list} deepcopy( {expr} [, {noref}]) any make a full copy of {expr} -delete( {fname}) Number delete file {fname} +delete( {fname} [, {flags}]) Number delete the file or directory {fname} dictwatcheradd( {dict}, {pattern}, {callback}) Start watching a dictionary dictwatcherdel( {dict}, {pattern}, {callback}) @@ -1851,12 +1880,13 @@ getbufvar( {expr}, {varname} [, {def}]) any variable {varname} in buffer {expr} getchar( [expr]) Number get one character from the user getcharmod( ) Number modifiers for the last typed character +getcharsearch() Dict last character search getcmdline() String return the current command-line getcmdpos() Number return cursor position in command-line getcmdtype() String return current command-line type getcmdwintype() String return current command-line window type getcurpos() List position of the cursor -getcwd() String the current working directory +getcwd( [{scope}]) String the current working directory getfontname( [{name}]) String name of font being used getfperm( {fname}) String file permissions of file {fname} getfsize( {fname}) Number size in bytes of file {fname} @@ -1924,6 +1954,8 @@ jobstart( {cmd}[, {opts}]) Number Spawns {cmd} as a job jobstop( {job}) Number Stops a job jobwait( {ids}[, {timeout}]) Number Wait for a set of jobs join( {list} [, {sep}]) String join {list} items into one String +json_decode( {expr}) any Convert {expr} from JSON +json_encode( {expr}) String Convert {expr} to JSON keys( {dict}) List keys in {dict} len( {expr}) Number the length of {expr} libcall( {lib}, {func}, {arg}) String call {func} in library {lib} with {arg} @@ -2214,17 +2246,17 @@ assert_equal({expected}, {actual}, [, {msg}]) assert_false({actual}, [, {msg}]) *assert_false()* When {actual} is not false an error message is added to - |v:errors|, like with |assert_equal()|.. - A value is false when it is zero. When "{actual}" is not a - number the assert fails. + |v:errors|, like with |assert_equal()|. + A value is false when it is zero or |v:false|. When "{actual}" + is not a number or |v:false| the assert fails. When {msg} is omitted an error in the form "Expected False but got {actual}" is produced. assert_true({actual}, [, {msg}]) *assert_true()* When {actual} is not true an error message is added to - |v:errors|, like with |assert_equal()|.. - A value is true when it is a non-zeron number. When {actual} - is not a number the assert fails. + |v:errors|, like with |assert_equal()|. + A value is true when it is a non-zero number or |v:true|. + When {actual} is not a number or |v:true| the assert fails. When {msg} is omitted an error in the form "Expected True but got {actual}" is produced. @@ -2738,13 +2770,19 @@ deepcopy({expr}[, {noref}]) *deepcopy()* *E698* {noref} set to 1 will fail. Also see |copy()|. -delete({fname}) *delete()* - Deletes the file by the name {fname}. The result is a Number, - which is 0 if the file was deleted successfully, and non-zero - when the deletion failed. - Use |remove()| to delete an item from a |List|. - To delete a line from the buffer use |:delete|. Use |:exe| - when the line number is in a variable. +delete({fname} [, {flags}]) *delete()* + Without {flags} or with {flags} empty: Deletes the file by the + name {fname}. This also works when {fname} is a symbolic link. + A symbolic link itself is deleted, not what it points to. + + When {flags} is "d": Deletes the directory by the name + {fname}. This fails when directory {fname} is not empty. + + When {flags} is "rf": Deletes the directory by the name + {fname} and everything in it, recursively. BE CAREFUL! + + The result is a Number, which is 0 if the delete operation was + successful and -1 when the deletion failed or partly failed. dictwatcheradd({dict}, {pattern}, {callback}) *dictwatcheradd()* Adds a watcher to a dictionary. A dictionary watcher is @@ -2818,9 +2856,8 @@ diff_hlID({lnum}, {col}) *diff_hlID()* empty({expr}) *empty()* Return the Number 1 if {expr} is empty, zero otherwise. A |List| or |Dictionary| is empty when it does not have any - items. A Number is empty when its value is zero. - For a long |List| this is much faster than comparing the - length with zero. + items. A Number is empty when its value is zero. Special + variable is empty when it is |v:false| or |v:null|. escape({string}, {chars}) *escape()* Escape the characters in {chars} that occur in {string} with a @@ -3528,9 +3565,18 @@ getcurpos() Get the position of the cursor. This is like getpos('.'), but MoveTheCursorAround call setpos('.', save_cursor) < - *getcwd()* -getcwd() The result is a String, which is the name of the current - working directory. +getcwd([{window}[, {tab}]]) *getcwd()* + With no arguments the result is a String, which is the name of + the current effective working directory. With {window} or + {tab} the working directory of that scope is returned. + Tabs and windows are identified by their respective numbers, + 0 means current tab or window. Missing argument implies 0. + Thus the following are equivalent: > + getcwd() + getcwd(0) + getcwd(0, 0) +< If {window} is -1 it is ignored, only the tab is resolved. + getfsize({fname}) *getfsize()* The result is a Number, which is the size in bytes of the @@ -3865,9 +3911,18 @@ has_key({dict}, {key}) *has_key()* The result is a Number, which is 1 if |Dictionary| {dict} has an entry with key {key}. Zero otherwise. -haslocaldir() *haslocaldir()* - The result is a Number, which is 1 when the current - window has set a local path via |:lcd|, and 0 otherwise. +haslocaldir([{window}[, {tab}]]) *haslocaldir()* + The result is a Number, which is 1 when the specified tabpage + or window has a local path set via |:lcd| or |:tcd|, and + 0 otherwise. + + Tabs and windows are identified by their respective numbers, + 0 means current tab or window. Missing argument implies 0. + Thus the following are equivalent: > + haslocaldir() + haslocaldir(0) + haslocaldir(0, 0) +< If {window} is -1 it is ignored, only the tab is resolved. hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()* The result is a Number, which is 1 if there is a mapping that @@ -4283,6 +4338,46 @@ join({list} [, {sep}]) *join()* converted into a string like with |string()|. The opposite function is |split()|. +json_decode({expr}) *json_decode()* + Convert {expr} from JSON object. Accepts |readfile()|-style + list as the input, as well as regular string. May output any + Vim value. When 'encoding' is not UTF-8 string is converted + from UTF-8 to 'encoding', failing conversion fails + json_decode(). In the following cases it will output + |msgpack-special-dict|: + 1. Dictionary contains duplicate key. + 2. Dictionary contains empty key. + 3. String contains NUL byte. Two special dictionaries: for + dictionary and for string will be emitted in case string + with NUL byte was a dictionary key. + + Note: function treats its input as UTF-8 always regardless of + 'encoding' value. This is needed because JSON source is + supposed to be external (e.g. |readfile()|) and JSON standard + allows only a few encodings, of which UTF-8 is recommended and + the only one required to be supported. Non-UTF-8 characters + are an error. + +json_encode({expr}) *json_encode()* + Convert {expr} into a JSON string. Accepts + |msgpack-special-dict| as the input. Converts from 'encoding' + to UTF-8 when encoding strings. Will not convert |Funcref|s, + mappings with non-string keys (can be created as + |msgpack-special-dict|), values with self-referencing + containers, strings which contain non-UTF-8 characters, + pseudo-UTF-8 strings which contain codepoints reserved for + surrogate pairs (such strings are not valid UTF-8 strings). + When converting 'encoding' is taken into account, if it is not + "utf-8", then conversion is performed before encoding strings. + Non-printable characters are converted into "\u1234" escapes + or special escapes like "\t", other are dumped as-is. + + Note: all characters above U+0079 are considered non-printable + when 'encoding' is not UTF-8. This function always outputs + UTF-8 strings as required by the standard thus when 'encoding' + is not unicode resulting string will look incorrect if + "\u1234" notation is not used. + keys({dict}) *keys()* Return a |List| with all the keys of {dict}. The |List| is in arbitrary order. @@ -4594,7 +4689,7 @@ match({expr}, {pat}[, {start}[, {count}]]) *match()* done like 'magic' is set and 'cpoptions' is empty. *matchadd()* *E798* *E799* *E801* -matchadd({group}, {pattern}[, {priority}[, {id}]]) +matchadd({group}, {pattern}[, {priority}[, {id} [, {dict}]]]) Defines a pattern to be highlighted in the current window (a "match"). It will be highlighted with {group}. Returns an identification number (ID), which can be used to delete the @@ -4602,6 +4697,8 @@ matchadd({group}, {pattern}[, {priority}[, {id}]]) Matching is case sensitive and magic, unless case sensitivity or magicness are explicitly overridden in {pattern}. The 'magic', 'smartcase' and 'ignorecase' options are not used. + The "Conceal" value is special, it causes the match to be + concealed. The optional {priority} argument assigns a priority to the match. A match with a high priority will have its @@ -4808,7 +4905,7 @@ msgpackdump({list}) {Nvim} *msgpackdump()* (dictionary with zero items is represented by 0x80 byte in messagepack). - Limitations: *E951* *E952* + Limitations: *E951* *E952* *E953* 1. |Funcref|s cannot be dumped. 2. Containers that reference themselves cannot be dumped. 3. Dictionary keys are always dumped as STR strings. @@ -4843,9 +4940,13 @@ msgpackparse({list}) {Nvim} *msgpackparse()* contains name of the key from |v:msgpack_types|): Key Value ~ - nil Zero, ignored when dumping. - boolean One or zero. When dumping it is only checked that - value is a |Number|. + nil Zero, ignored when dumping. This value cannot + possibly appear in |msgpackparse()| output in Neovim + versions which have |v:null|. + boolean One or zero. When dumping it is only checked that + value is a |Number|. This value cannot possibly + appear in |msgpackparse()| output in Neovim versions + which have |v:true| and |v:false|. integer |List| with four numbers: sign (-1 or 1), highest two bits, number with bits from 62nd to 31st, lowest 31 bits. I.e. to get actual number one will need to use @@ -5176,7 +5277,7 @@ readfile({fname} [, {binary} [, {max}]]) separated with CR will result in a single long line (unless a NL appears somewhere). All NUL characters are replaced with a NL character. - When {binary/append} contains "b" binary mode is used: + When {binary} contains "b" binary mode is used: - When the last line ends in a NL an extra empty list item is added. - No CR characters are removed. @@ -5700,7 +5801,7 @@ setbufvar({expr}, {varname}, {val}) *setbufvar()* :call setbufvar("todo", "myvar", "foobar") < This function is not available in the |sandbox|. -setcharsearch() *setcharsearch()* +setcharsearch({dict}) *setcharsearch()* Set the current character search information to {dict}, which contains one or more of the following entries: @@ -6153,7 +6254,8 @@ split({expr} [, {pattern} [, {keepempty}]]) *split()* :let words = split(getline('.'), '\W\+') < To split a string in individual characters: > :for c in split(mystring, '\zs') -< If you want to keep the separator you can also use '\zs': > +< If you want to keep the separator you can also use '\zs' at + the end of the pattern: > :echo split('abc:def:ghi', ':\zs') < ['abc:', 'def:', 'ghi'] ~ Splitting a table where the first element can be empty: > @@ -6209,6 +6311,24 @@ strchars({expr} [, {skipcc}]) *strchars()* When {skipcc} set to 1, Composing characters are ignored. Also see |strlen()|, |strdisplaywidth()| and |strwidth()|. + + {skipcc} is only available after 7.4.755. For backward + compatibility, you can define a wrapper function: > + if has("patch-7.4.755") + function s:strchars(str, skipcc) + return strchars(a:str, a:skipcc) + endfunction + else + function s:strchars(str, skipcc) + if a:skipcc + return strlen(substitute(a:str, ".", "x", "g")) + else + return strchars(a:str) + endif + endfunction + endif +< + strdisplaywidth({expr}[, {col}]) *strdisplaywidth()* The result is a Number, which is the number of display cells String {expr} occupies on the screen when it starts at {col}. @@ -6405,6 +6525,9 @@ synID({lnum}, {col}, {trans}) *synID()* {col} is 1 for the leftmost column, {lnum} is 1 for the first line. 'synmaxcol' applies, in a longer line zero is returned. + Note that when the position is after the last character, + that's where the cursor can be in Insert mode, synID() returns + zero. When {trans} is non-zero, transparent items are reduced to the item that they reveal. This is useful when wanting to know @@ -6710,12 +6833,14 @@ trunc({expr}) *trunc()* type({expr}) *type()* The result is a Number, depending on the type of {expr}: - Number: 0 - String: 1 + Number: 0 + String: 1 Funcref: 2 - List: 3 + List: 3 Dictionary: 4 - Float: 5 + Float: 5 + Boolean: 6 (|v:true| and |v:false|) + Null: 7 (|v:null|) To avoid the magic numbers it should be used this way: > :if type(myvar) == type(0) :if type(myvar) == type("") @@ -6723,6 +6848,10 @@ type({expr}) *type()* :if type(myvar) == type([]) :if type(myvar) == type({}) :if type(myvar) == type(0.0) + :if type(myvar) == type(v:true) +< In place of checking for |v:null| type it is better to check + for |v:null| directly as it is the only value of this type: > + :if myvar is v:null undofile({name}) *undofile()* Return the name of the undo file that would be used for a file diff --git a/runtime/doc/index.txt b/runtime/doc/index.txt index 2067b0c321..f511b1db6d 100644 --- a/runtime/doc/index.txt +++ b/runtime/doc/index.txt @@ -1,4 +1,4 @@ -*index.txt* For Vim version 7.4. Last change: 2015 Feb 12 +*index.txt* For Vim version 7.4. Last change: 2015 Sep 08 VIM REFERENCE MANUAL by Bram Moolenaar diff --git a/runtime/doc/insert.txt b/runtime/doc/insert.txt index f17410d1dc..f931dfa341 100644 --- a/runtime/doc/insert.txt +++ b/runtime/doc/insert.txt @@ -1,4 +1,4 @@ -*insert.txt* For Vim version 7.4. Last change: 2015 Jun 20 +*insert.txt* For Vim version 7.4. Last change: 2015 Sep 15 VIM REFERENCE MANUAL by Bram Moolenaar @@ -148,7 +148,7 @@ CTRL-R CTRL-R {0-9a-z"%#*+/:.-=} *i_CTRL-R_CTRL-R* CTRL-R a results in "ac". CTRL-R CTRL-R a results in "ab^Hc". < Options 'textwidth', 'formatoptions', etc. still apply. If - you also want to avoid these, use "<C-R><C-O>r", see below. + you also want to avoid these, use CTRL-R CTRL-O, see below. The '.' register (last inserted text) is still inserted as typed. diff --git a/runtime/doc/nvim_clipboard.txt b/runtime/doc/nvim_clipboard.txt index 1183ad7a3c..258fc550f8 100644 --- a/runtime/doc/nvim_clipboard.txt +++ b/runtime/doc/nvim_clipboard.txt @@ -22,6 +22,8 @@ is found in your `$PATH`. - xclip - xsel (newer alternative to xclip) - pbcopy/pbpaste (only for Mac OS X) +- lemonade (useful for SSH machine) + https://github.com/pocke/lemonade The presence of a suitable clipboard tool implicitly enables the '+' and '*' registers. diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 44696d10bb..ebb2f28fa5 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -49,9 +49,12 @@ achieve special effects. These options come in three forms: :se[t] {option}&vi Reset option to its Vi default value. :se[t] {option}&vim Reset option to its Vim default value. -:se[t] all& Set all options, except terminal options, to their - default value. The values of 'lines' and 'columns' - are not changed. +:se[t] all& Set all options to their default value. The values of + these options are not changed: + 'columns' + 'encoding' + 'lines' + Warning: This may have a lot of side effects. *:set-args* *E487* *E521* :se[t] {option}={value} or @@ -704,7 +707,8 @@ A jump table for the options with a short description can be found at |Q_op|. line. When 'smartindent' or 'cindent' is on the indent is changed in a different way. - The 'autoindent' option is reset when the 'paste' option is set. + The 'autoindent' option is reset when the 'paste' option is set and + restored when 'paste' is reset. {small difference from Vi: After the indent is deleted when typing <Esc> or <CR>, the cursor position when moving up or down is after the deleted indent; Vi puts the cursor somewhere in the deleted indent}. @@ -2273,6 +2277,8 @@ A jump table for the options with a short description can be found at |Q_op|. <Tab>. Spaces are used in indents with the '>' and '<' commands and when 'autoindent' is on. To insert a real tab when 'expandtab' is on, use CTRL-V<Tab>. See also |:retab| and |ins-expandtab|. + This option is reset when the 'paste' option is set and restored when + the 'paste' option is reset. *'exrc'* *'ex'* *'noexrc'* *'noex'* 'exrc' 'ex' boolean (default off) @@ -3404,7 +3410,7 @@ A jump table for the options with a short description can be found at |Q_op|. global Ignore case in search patterns. Also used when searching in the tags file. - Also see 'smartcase'. + Also see 'smartcase' and 'tagcase'. Can be overruled by using "\c" or "\C" in the pattern, see |/ignorecase|. @@ -4517,19 +4523,21 @@ A jump table for the options with a short description can be found at |Q_op|. When the 'paste' option is switched on (also when it was already on): - mapping in Insert mode and Command-line mode is disabled - abbreviations are disabled - - 'textwidth' is set to 0 - - 'wrapmargin' is set to 0 - 'autoindent' is reset - - 'smartindent' is reset - - 'softtabstop' is set to 0 + - 'expandtab' is reset + - 'formatoptions' is used like it is empty - 'revins' is reset - 'ruler' is reset - 'showmatch' is reset - - 'formatoptions' is used like it is empty + - 'smartindent' is reset + - 'smarttab' is reset + - 'softtabstop' is set to 0 + - 'textwidth' is set to 0 + - 'wrapmargin' is set to 0 These options keep their value, but their effect is disabled: - - 'lisp' - - 'indentexpr' - 'cindent' + - 'indentexpr' + - 'lisp' NOTE: When you start editing another file while the 'paste' option is on, settings from the modelines or autocommands may change the settings again, causing trouble when pasting text. You might want to @@ -4852,7 +4860,8 @@ A jump table for the options with a short description can be found at |Q_op|. Inserting characters in Insert mode will work backwards. See "typing backwards" |ins-reverse|. This option can be toggled with the CTRL-_ command in Insert mode, when 'allowrevins' is set. - NOTE: This option is reset when 'paste' is set. + This option is reset when 'paste' is set and restored when 'paste' is + reset. *'rightleft'* *'rl'* *'norightleft'* *'norl'* 'rightleft' 'rl' boolean (default off) @@ -4901,7 +4910,8 @@ A jump table for the options with a short description can be found at |Q_op|. separated with a dash. For an empty line "0-1" is shown. For an empty buffer the line number will also be zero: "0,0-1". - This option is reset when the 'paste' option is set. + This option is reset when 'paste' is set and restored when 'paste' is + reset. If you don't want to see the ruler all the time but want to know where you are, use "g CTRL-G" |g_CTRL-G|. @@ -5538,7 +5548,9 @@ A jump table for the options with a short description can be found at |Q_op|. c don't give |ins-completion-menu| messages. For example, "-- XXX completion (YYY)", "match 1 of 2", "The only match", "Pattern not found", "Back at original", etc. - q use "recording" instead of "recording @a" + q use "recording" instead of "recording @a" + F don't give the file info when editing a file, like `:silent` + was used for the command This gives you the opportunity to avoid that a change between buffers requires you to hit <Enter>, but still gives as useful a message as @@ -5607,7 +5619,9 @@ A jump table for the options with a short description can be found at |Q_op|. jump is only done if the match can be seen on the screen. The time to show the match can be set with 'matchtime'. A Beep is given if there is no match (no matter if the match can be - seen or not). This option is reset when the 'paste' option is set. + seen or not). + This option is reset when 'paste' is set and restored when 'paste' is + reset. When the 'm' flag is not included in 'cpoptions', typing a character will immediately move the cursor back to where it belongs. See the "sm" field in 'guicursor' for setting the cursor shape and @@ -5706,7 +5720,8 @@ A jump table for the options with a short description can be found at |Q_op|. mapping: ":inoremap # X^H#", where ^H is entered with CTRL-V CTRL-H. When using the ">>" command, lines starting with '#' are not shifted right. - NOTE: When 'paste' is set smart indenting is disabled. + This option is reset when 'paste' is set and restored when 'paste' is + reset. *'smarttab'* *'sta'* *'nosmarttab'* *'nosta'* 'smarttab' 'sta' boolean (default on) @@ -5721,6 +5736,8 @@ A jump table for the options with a short description can be found at |Q_op|. What gets inserted (a <Tab> or spaces) depends on the 'expandtab' option. Also see |ins-expandtab|. When 'expandtab' is not set, the number of spaces is minimized by using <Tab>s. + This option is reset when 'paste' is set and restored when 'paste' is + reset. *'softtabstop'* *'sts'* 'softtabstop' 'sts' number (default 0) @@ -5733,7 +5750,8 @@ A jump table for the options with a short description can be found at |Q_op|. commands like "x" still work on the actual characters. When 'sts' is zero, this feature is off. When 'sts' is negative, the value of 'shiftwidth' is used. - 'softtabstop' is set to 0 when the 'paste' option is set. + 'softtabstop' is set to 0 when the 'paste' option is set and restored + when 'paste' is reset. See also |ins-expandtab|. When 'expandtab' is not set, the number of spaces is minimized by using <Tab>s. The 'L' flag in 'cpoptions' changes how tabs are used when 'list' is @@ -6303,19 +6321,22 @@ A jump table for the options with a short description can be found at |Q_op|. < [The whitespace before and after the '0' must be a single <Tab>] When a binary search was done and no match was found in any of the - files listed in 'tags', and 'ignorecase' is set or a pattern is used + files listed in 'tags', and case is ignored or a pattern is used instead of a normal tag name, a retry is done with a linear search. Tags in unsorted tags files, and matches with different case will only be found in the retry. If a tag file indicates that it is case-fold sorted, the second, - linear search can be avoided for the 'ignorecase' case. Use a value - of '2' in the "!_TAG_FILE_SORTED" line for this. A tag file can be - case-fold sorted with the -f switch to "sort" in most unices, as in - the command: "sort -f -o tags tags". For "Exuberant ctags" version - 5.x or higher (at least 5.5) the --sort=foldcase switch can be used - for this as well. Note that case must be folded to uppercase for this - to work. + linear search can be avoided when case is ignored. Use a value of '2' + in the "!_TAG_FILE_SORTED" line for this. A tag file can be case-fold + sorted with the -f switch to "sort" in most unices, as in the command: + "sort -f -o tags tags". For "Exuberant ctags" version 5.x or higher + (at least 5.5) the --sort=foldcase switch can be used for this as + well. Note that case must be folded to uppercase for this to work. + + By default, tag searches are case-sensitive. Case is ignored when + 'ignorecase' is set and 'tagcase' is "followic", or when 'tagcase' is + "ignore". When 'tagbsearch' is off, tags searching is slower when a full match exists, but faster when no full match exists. Tags in unsorted tags @@ -6326,6 +6347,16 @@ A jump table for the options with a short description can be found at |Q_op|. This option doesn't affect commands that find all matching tags (e.g., command-line completion and ":help"). + *'tagcase'* *'tc'* +'tagcase' 'tc' string (default "followic") + global or local to buffer |global-local| + {not in Vi} + This option specifies how case is handled when searching the tags + file: + followic Follow the 'ignorecase' option + ignore Ignore case + match Match case + *'taglength'* *'tl'* 'taglength' 'tl' number (default 0) global @@ -6402,8 +6433,10 @@ A jump table for the options with a short description can be found at |Q_op|. local to buffer Maximum width of text that is being inserted. A longer line will be broken after white space to get this width. A zero value disables - this. 'textwidth' is set to 0 when the 'paste' option is set. When - 'textwidth' is zero, 'wrapmargin' may be used. See also + this. + 'textwidth' is set to 0 when the 'paste' option is set and restored + when 'paste' is reset. + When 'textwidth' is zero, 'wrapmargin' may be used. See also 'formatoptions' and |ins-textwidth|. When 'formatexpr' is set it will be used to break the line. diff --git a/runtime/doc/os_dos.txt b/runtime/doc/os_dos.txt deleted file mode 100644 index 1601d65ffd..0000000000 --- a/runtime/doc/os_dos.txt +++ /dev/null @@ -1,279 +0,0 @@ -*os_dos.txt* For Vim version 7.4. Last change: 2006 Mar 30 - - - VIM REFERENCE MANUAL by Bram Moolenaar - - - *dos* *DOS* -This file documents some particularities of the Win32 -version of Vim. Also see |os_win32.txt|. - -1. File locations |dos-locations| -2. Using backslashes |dos-backslash| -3. Standard mappings |dos-standard-mappings| -4. Screen output and colors |dos-colors| -5. File formats |dos-file-formats| -6. :cd command |dos-:cd| -7. Interrupting |dos-CTRL-Break| -8. Temp files |dos-temp-files| -9. Shell option default |dos-shell| - -============================================================================== -1. File locations *dos-locations* - -If you keep the Vim executable in the directory that contains the help and -syntax subdirectories, there is no need to do anything special for Vim to -work. No registry entries or environment variables need to be set. Just make -sure that the directory is in your search path, or use a shortcut on the -desktop. - -Your vimrc files ("_vimrc" and "_gvimrc") are normally located one directory -up from the runtime files. If you want to put them somewhere else, set the -environment variable $VIM to the directory where you keep them. Example: > - set VIM=C:\user\piet -Will find "c:\user\piet\_vimrc". -Note: This would only be needed when the computer is used by several people. -Otherwise it's simpler to keep your _vimrc file in the default place. - -If you move the executable to another location, you also need to set the $VIM -environment variable. The runtime files will be found in "$VIM/vim{version}". -Example: > - set VIM=E:\vim -Will find the version 5.4 runtime files in "e:\vim\vim54". -Note: This is _not_ recommended. The preferred way is to keep the executable -in the runtime directory. - -If you move your executable AND want to put your "_vimrc" and "_gvimrc" files -somewhere else, you must set $VIM to where you vimrc files are, and set -$VIMRUNTIME to the runtime files. Example: > - set VIM=C:\usr\piet - set VIMRUNTIME=E:\vim\vim54 -Will find "c:\user\piet\_vimrc" and the runtime files in "e:\vim\vim54". - -See |$VIM| and |$VIMRUNTIME| for more information. - -You can set environment variables for each user separately under -"Start/Settings/Control Panel->System", or through the properties in the menu -of "My Computer", under the Environment Tab. - -============================================================================== -2. Using backslashes *dos-backslash* - -Using backslashes in file names can be a problem. Vi halves the number of -backslashes for some commands. Vim is a bit more tolerant and does not remove -backslashes from a file name, so ":e c:\foo\bar" works as expected. But when -a backslash occurs before a special character (space, comma, backslash, etc.), -Vim removes the backslash. Use slashes to avoid problems: ":e c:/foo/bar" -works fine. Vim replaces the slashes with backslashes internally to avoid -problems with some MS-DOS programs and Win32 programs. - -When you prefer to use forward slashes, set the 'shellslash' option. Vim will -then replace backslashes with forward slashes when expanding file names. This -is especially useful when using a Unix-like 'shell'. - -============================================================================== -3. Standard mappings *dos-standard-mappings* - -The mappings for CTRL-PageUp and CTRL-PageDown have been removed, they now -jump to the next or previous tab page |<C-PageUp>| |<C-PageDown>| - -If you want them to move to the first and last screen line you can use these -mappings: - -key key code Normal/Visual mode Insert mode ~ -CTRL-PageUp <M-N><M-C-D> H <C-O>H -CTRL-PageDown <M-N>v L$ <C-O>L<C-O>$ - -Additionally, these keys are available for copy/cut/paste. -In the Win32 version, they also use the clipboard. - -Shift-Insert paste text (from clipboard) *<S-Insert>* -CTRL-Insert copy Visual text (to clipboard) *<C-Insert>* -CTRL-Del cut Visual text (to clipboard) *<C-Del>* -Shift-Del cut Visual text (to clipboard) *<S-Del>* - -These mappings accomplish this (Win32 version of Vim): - -key key code Normal Visual Insert ~ -Shift-Insert <M-N><M-T> "*P "-d"*P <C-R><C-O>* -CTRL-Insert <M-N><M-U> "*y -Shift-Del <M-N><M-W> "*d -CTRL-Del <M-N><M-X> "*d - -Or these mappings (non-Win32 version of Vim): - -key key code Normal Visual Insert ~ -Shift-Insert <M-N><M-T> P "-dP <C-R><C-O>" -CTRL-Insert <M-N><M-U> y -Shift-Del <M-N><M-W> d -CTRL-Del <M-N><M-X> d - -When the clipboard is supported, the "* register is used. - -============================================================================== -4. Screen output and colors *dos-colors* - -The default output method for the screen is to use bios calls. This works -right away on most systems. You do not need ansi.sys. You can use ":mode" to -set the current screen mode. See |:mode|. - -To change the screen colors that Vim uses, you can use the |:highlight| -command. The Normal highlight group specifies the colors Vim uses for normal -text. For example, to get grey text on a blue background: > - :hi Normal ctermbg=Blue ctermfg=grey -See |highlight-groups| for other groups that are available. - -A DOS console does not support attributes like bold and underlining. You can -set the color used in five modes with nine terminal options. Note that this -is not necessary since you can set the color directly with the ":highlight" -command; these options are for backward compatibility with older Vim versions. -The |'highlight'| option specifies which of the five modes is used for which -action. > - - :set t_mr=^V^[\|xxm start of invert mode - :set t_md=^V^[\|xxm start of bold mode - :set t_me=^V^[\|xxm back to normal text - - :set t_so=^V^[\|xxm start of standout mode - :set t_se=^V^[\|xxm back to normal text - - :set t_us=^V^[\|xxm start of underline mode - :set t_ue=^V^[\|xxm back to normal text - - :set t_ZH=^V^[\|xxm start of italics mode - :set t_ZR=^V^[\|xxm back to normal text - -^V is CTRL-V -^[ is <Esc> -You must replace xx with a decimal code, which is the foreground color number -and background color number added together: - -COLOR FOREGROUND BACKGROUND ~ -Black 0 0 -DarkBlue 1 16 -DarkGreen 2 32 -DarkCyan 3 48 -DarkRed 4 64 -DarkMagenta 5 80 -Brown, DarkYellow 6 96 -LightGray 7 112 -DarkGray 8 128 * -Blue, LightBlue 9 144 * -Green, LightGreen 10 160 * -Cyan, LightCyan 11 176 * -Red, LightRed 12 192 * -Magenta, LightMagenta 13 208 * -Yellow, LightYellow 14 224 * -White 15 240 * - -* Depending on the display mode, the color codes above 128 may not be - available, and code 128 will make the text blink. - -When you use 0, the color is reset to the one used when you started Vim -(usually 7, lightgray on black, but you can override this. If you have -overridden the default colors in a command prompt, you may need to adjust -some of the highlight colors in your vimrc---see below). -This is the default for t_me. - -The defaults for the various highlight modes are: - t_mr 112 reverse mode: Black text (0) on LightGray (112) - t_md 15 bold mode: White text (15) on Black (0) - t_me 0 normal mode (revert to default) - - t_so 31 standout mode: White (15) text on DarkBlue (16) - t_se 0 standout mode end (revert to default) - - t_czh 225 italic mode: DarkBlue text (1) on Yellow (224) - t_czr 0 italic mode end (revert to default) - - t_us 67 underline mode: DarkCyan text (3) on DarkRed (64) - t_ue 0 underline mode end (revert to default) - -These colors were chosen because they also look good when using an inverted -display, but you can change them to your liking. - -Example: > - :set t_mr=^V^[\|97m " start of invert mode: DarkBlue (1) on Brown (96) - :set t_md=^V^[\|67m " start of bold mode: DarkCyan (3) on DarkRed (64) - :set t_me=^V^[\|112m " back to normal mode: Black (0) on LightGray (112) - - :set t_so=^V^[\|37m " start of standout mode: DarkMagenta (5) on DarkGreen - (32) - :set t_se=^V^[\|112m " back to normal mode: Black (0) on LightGray (112) - -============================================================================== -5. File formats *dos-file-formats* - -If the 'fileformat' option is set to "dos" (which is the default), Vim accepts -a single <NL> or a <CR><NL> pair for end-of-line (<EOL>). When writing a -file, Vim uses <CR><NL>. Thus, if you edit a file and write it, Vim replaces -<NL> with <CR><NL>. - -If the 'fileformat' option is set to "unix", Vim uses a single <NL> for <EOL> -and shows <CR> as ^M. - -You can use Vim to replace <NL> with <CR><NL> by reading in any mode and -writing in Dos mode (":se ff=dos"). -You can use Vim to replace <CR><NL> with <NL> by reading in Dos mode and -writing in Unix mode (":se ff=unix"). - -Vim sets 'fileformat' automatically when 'fileformats' is not empty (which is -the default), so you don't really have to worry about what you are doing. - |'fileformat'| |'fileformats'| - -If you want to edit a script file or a binary file, you should set the -'binary' option before loading the file. Script files and binary files may -contain single <NL> characters which Vim would replace with <CR><NL>. You can -set 'binary' automatically by starting Vim with the "-b" (binary) option. - -============================================================================== -6. :cd command *dos-:cd* - -The ":cd" command recognizes the drive specifier and changes the current -drive. Use ":cd c:" to make drive C the active drive. Use ":cd d:\foo" to go -to the directory "foo" in the root of drive D. Vim also recognizes UNC names -if the system supports them; e.g., ":cd \\server\share\dir". |:cd| - -============================================================================== -7. Interrupting *dos-CTRL-Break* - -Use CTRL-Break instead of CTRL-C to interrupt searches. Vim does not detect -the CTRL-C until it tries to read a key. - -============================================================================== -8. Temp files *dos-temp-files* - -Vim uses standard Windows functions to obtain a temporary file name (for -filtering). The first of these directories that exists and in which Vim can -create a file is used: - $TMP - $TEMP - current directory - -============================================================================== -9. Shell option default *dos-shell* - -The default for the 'sh' ('shell') option is "cmd.exe" on Windows. -If SHELL is defined, Vim uses SHELL instead, and if SHELL is not defined -but COMSPEC is, Vim uses COMSPEC. Vim starts external commands with -"<shell> /c <command_name>". Typing CTRL-Z starts a new command -subshell. Return to Vim with "exit". |'shell'| |CTRL-Z| - -If you are running a third-party shell, you may need to set the -|'shellcmdflag'| ('shcf') and |'shellquote'| ('shq') or |'shellxquote'| -('sxq') options. Unfortunately, this also depends on the version of Vim used. -For example, with the MKS Korn shell or with bash, the values of the options -on Win32 should be: - -'shellcmdflag' -c -'shellquote' (empty) -'shellxquote' " - -For Win32, this starts the shell as: - <shell> -c "command name >file" - -When starting up, Vim checks for the presence of "sh" anywhere in the 'shell' -option. If it is present, Vim sets the 'shellcmdflag' and 'shellquote' or -'shellxquote' options will be set as described above. - - vim:tw=78:ts=8:ft=help:norl: diff --git a/runtime/doc/quickfix.txt b/runtime/doc/quickfix.txt index bcce5a983a..ff4fded0d9 100644 --- a/runtime/doc/quickfix.txt +++ b/runtime/doc/quickfix.txt @@ -1,4 +1,4 @@ -*quickfix.txt* For Vim version 7.4. Last change: 2014 Mar 27 +*quickfix.txt* For Vim version 7.4. Last change: 2015 Sep 08 VIM REFERENCE MANUAL by Bram Moolenaar @@ -302,16 +302,22 @@ EXECUTE A COMMAND IN ALL THE BUFFERS IN QUICKFIX OR LOCATION LIST: etc. < When the current file can't be |abandon|ed and the [!] is not present, the command fails. - When an error is detected on one buffer, further - buffers will not be visited. + When an error is detected excecution stops. The last buffer (or where an error occurred) becomes the current buffer. {cmd} can contain '|' to concatenate several commands. + Only valid entries in the quickfix list are used. + A range can be used to select entries, e.g.: > + :10,$cdo cmd +< To skip entries 1 to 9. + Note: While this command is executing, the Syntax autocommand event is disabled by adding it to 'eventignore'. This considerably speeds up editing each buffer. + {not in Vi} {not available when compiled without the + |+listcmds| feature} Also see |:bufdo|, |:tabdo|, |:argdo|, |:windo|, |:ldo|, |:cfdo| and |:lfdo|. @@ -323,20 +329,9 @@ EXECUTE A COMMAND IN ALL THE BUFFERS IN QUICKFIX OR LOCATION LIST: :cnfile :{cmd} etc. -< When the current file can't be |abandon|ed and the [!] - is not present, the command fails. - When an error is detected on one buffer, further - buffers will not be visited. - The last buffer (or where an error occurred) becomes - the current buffer. - {cmd} can contain '|' to concatenate several commands. - Only valid entries in the quickfix list are used. - Note: While this command is executing, the Syntax - autocommand event is disabled by adding it to - 'eventignore'. This considerably speeds up editing - each buffer. - Also see |:bufdo|, |:tabdo|, |:argdo|, |:windo|, - |:cdo|, |:ldo| and |:lfdo|. +< Otherwise it works the same as `:cdo`. + {not in Vi} {not available when compiled without the + |+listcmds| feature} *:ldo* :ld[o][!] {cmd} Execute {cmd} in each valid entry in the location list @@ -347,20 +342,10 @@ EXECUTE A COMMAND IN ALL THE BUFFERS IN QUICKFIX OR LOCATION LIST: :lnext :{cmd} etc. -< When the current file can't be |abandon|ed and the [!] - is not present, the command fails. - When an error is detected on one buffer, further - buffers will not be visited. - The last buffer (or where an error occurred) becomes - the current buffer. - {cmd} can contain '|' to concatenate several commands. - Only valid entries in the location list are used. - Note: While this command is executing, the Syntax - autocommand event is disabled by adding it to - 'eventignore'. This considerably speeds up editing - each buffer. - Also see |:bufdo|, |:tabdo|, |:argdo|, |:windo|, - |:cdo|, |:cfdo| and |:lfdo|. +< Only valid entries in the location list are used. + Otherwise it works the same as `:cdo`. + {not in Vi} {not available when compiled without the + |+listcmds| feature} *:lfdo* :lfdo[!] {cmd} Execute {cmd} in each file in the location list for @@ -371,20 +356,9 @@ EXECUTE A COMMAND IN ALL THE BUFFERS IN QUICKFIX OR LOCATION LIST: :lnfile :{cmd} etc. -< When the current file can't be |abandon|ed and the [!] - is not present, the command fails. - When an error is detected on one buffer, further - buffers will not be visited. - The last buffer (or where an error occurred) becomes - the current buffer. - {cmd} can contain '|' to concatenate several commands. - Only valid entries in the location list are used. - Note: While this command is executing, the Syntax - autocommand event is disabled by adding it to - 'eventignore'. This considerably speeds up editing - each buffer. - Also see |:bufdo|, |:tabdo|, |:argdo|, |:windo|, - |:cdo|, |:ldo| and |:cfdo|. +< Otherwise it works the same as `:ldo`. + {not in Vi} {not available when compiled without the + |+listcmds| feature} ============================================================================= 2. The error window *quickfix-window* diff --git a/runtime/doc/quickref.txt b/runtime/doc/quickref.txt index ded5e69438..66773875c3 100644 --- a/runtime/doc/quickref.txt +++ b/runtime/doc/quickref.txt @@ -1,4 +1,4 @@ -*quickref.txt* For Vim version 7.4. Last change: 2014 Nov 19 +*quickref.txt* For Vim version 7.4. Last change: 2015 Jul 21 VIM REFERENCE MANUAL by Bram Moolenaar @@ -617,6 +617,7 @@ Short explanation of each option: *option-list* 'balloondelay' 'bdlay' delay in mS before a balloon may pop up 'ballooneval' 'beval' switch on balloon evaluation 'balloonexpr' 'bexpr' expression to show in balloon +'belloff' 'bo' do not ring the bell for these reasons 'binary' 'bin' read/write/edit file in binary mode 'bomb' prepend a Byte Order Mark to the file 'breakat' 'brk' characters that may cause a line break @@ -688,6 +689,7 @@ Short explanation of each option: *option-list* 'fileignorecase' 'fic' ignore case when using file names 'filetype' 'ft' type of file, used for autocommands 'fillchars' 'fcs' characters to use for displaying special items +'fixendofline' 'fixeol' make sure last line in file has <EOL> 'fkmap' 'fk' Farsi keyboard mapping 'foldclose' 'fcl' close a fold when the cursor leaves it 'foldcolumn' 'fdc' width of the column used to indicate folds @@ -702,10 +704,10 @@ Short explanation of each option: *option-list* 'foldnestmax' 'fdn' maximum fold depth 'foldopen' 'fdo' for which commands a fold will be opened 'foldtext' 'fdt' expression used to display for a closed fold +'formatexpr' 'fex' expression used with "gq" command 'formatlistpat' 'flp' pattern used to recognize a list header 'formatoptions' 'fo' how automatic formatting is to be done 'formatprg' 'fp' name of external program used with "gq" command -'formatexpr' 'fex' expression used with "gq" command 'fsync' 'fs' whether to invoke fsync() after file write 'gdefault' 'gd' the ":substitute" flag 'g' is default on 'grepformat' 'gfm' format of 'grepprg' output @@ -873,10 +875,11 @@ Short explanation of each option: *option-list* 'switchbuf' 'swb' sets behavior when switching to another buffer 'synmaxcol' 'smc' maximum column to find syntax items 'syntax' 'syn' syntax to be loaded for current buffer -'tabstop' 'ts' number of spaces that <Tab> in file uses 'tabline' 'tal' custom format for the console tab pages line 'tabpagemax' 'tpm' maximum number of tab pages for |-p| and "tab all" +'tabstop' 'ts' number of spaces that <Tab> in file uses 'tagbsearch' 'tbs' use binary searching in tags files +'tagcase' 'tc' how to handle case when searching in tags files 'taglength' 'tl' number of significant characters for a tag 'tagrelative' 'tr' file names in tag file are relative 'tags' 'tag' list of file names used by the tag command diff --git a/runtime/doc/starting.txt b/runtime/doc/starting.txt index be108d4633..37593aef43 100644 --- a/runtime/doc/starting.txt +++ b/runtime/doc/starting.txt @@ -380,6 +380,8 @@ accordingly. Vim proceeds in this order: Places for your personal initializations: Unix $XDG_CONFIG_HOME/nvim/init.vim (default for $XDG_CONFIG_HOME is ~/.config) + Windows $XDG_CONFIG_HOME/nvim/init.vim + (default for $XDG_CONFIG_HOME is ~/AppData/Local) The files are searched in the order specified above and only the first one that is found is read. diff --git a/runtime/doc/syntax.txt b/runtime/doc/syntax.txt index 6aed7441a0..1f392cd0b5 100644 --- a/runtime/doc/syntax.txt +++ b/runtime/doc/syntax.txt @@ -1,4 +1,4 @@ -*syntax.txt* For Vim version 7.4. Last change: 2015 Mar 29 +*syntax.txt* For Vim version 7.4. Last change: 2015 Sep 29 VIM REFERENCE MANUAL by Bram Moolenaar @@ -417,18 +417,19 @@ and last line to be converted. Example, using the last set Visual area: > *:TOhtml* :[range]TOhtml The ":TOhtml" command is defined in a standard plugin. This command will source |2html.vim| for you. When a - range is given, set |g:html_start_line| and - |g:html_end_line| to the start and end of the range, - respectively. Default range is the entire buffer. - - If the current window is part of a |diff|, unless - |g:html_diff_one_file| is set, :TOhtml will convert - all windows which are part of the diff in the current - tab and place them side-by-side in a <table> element - in the generated HTML. With |g:html_line_ids| you can - jump to lines in specific windows with (for example) - #W1L42 for line 42 in the first diffed window, or - #W3L87 for line 87 in the third. + range is given, this command sets |g:html_start_line| + and |g:html_end_line| to the start and end of the + range, respectively. Default range is the entire + buffer. + + If the current window is part of a |diff|, unless + |g:html_diff_one_file| is set, :TOhtml will convert + all windows which are part of the diff in the current + tab and place them side-by-side in a <table> element + in the generated HTML. With |g:html_line_ids| you can + jump to lines in specific windows with (for example) + #W1L42 for line 42 in the first diffed window, or + #W3L87 for line 87 in the third. Examples: > @@ -742,6 +743,22 @@ and UTF-32 instead, use: > Note that documents encoded in either UTF-32 or UTF-16 have known compatibility problems with some major browsers. + *g:html_font* +Default: "monospace" +You can specify the font or fonts used in the converted document using +g:html_font. If this option is set to a string, then the value will be +surrounded with single quotes. If this option is set to a list then each list +item is surrounded by single quotes and the list is joined with commas. Either +way, "monospace" is added as the fallback generic family name and the entire +result used as the font family (using CSS) or font face (if not using CSS). +Examples: > + + " font-family: 'Consolas', monospace; + :let g:html_font = "Consolas" + + " font-family: 'DejaVu Sans Mono', 'Consolas', monospace; + :let g:html_font = ["DejaVu Sans Mono", "Consolas"] +< *convert-to-XML* *convert-to-XHTML* *g:html_use_xhtml* Default: 0. When 0, generate standard HTML 4.01 (strict when possible). @@ -3430,7 +3447,7 @@ DEFINING KEYWORDS *:syn-keyword* :syntax keyword Type contained int long char :syntax keyword Type int long contained char :syntax keyword Type int long char contained -< *E789* +< *E789* *E890* When you have a keyword with an optional tail, like Ex commands in Vim, you can put the optional characters inside [], to define all the variations at once: > @@ -3684,6 +3701,7 @@ Whether or not it is actually concealed depends on the value of the 'conceallevel' option. The 'concealcursor' option is used to decide whether concealable items in the current line are displayed unconcealed to be able to edit the line. +Another way to conceal text with with |matchadd()|. concealends *:syn-concealends* diff --git a/runtime/doc/tagsrch.txt b/runtime/doc/tagsrch.txt index 7d3697db07..75d820d072 100644 --- a/runtime/doc/tagsrch.txt +++ b/runtime/doc/tagsrch.txt @@ -84,11 +84,13 @@ changed, to avoid confusion when using ":tnext". It is changed when using ":tag {ident}". The ignore-case matches are not found for a ":tag" command when the -'ignorecase' option is off. They are found when a pattern is used (starting -with a "/") and for ":tselect", also when 'ignorecase' is off. Note that -using ignore-case tag searching disables binary searching in the tags file, -which causes a slowdown. This can be avoided by fold-case sorting the tag -file. See the 'tagbsearch' option for an explanation. +'ignorecase' option is off and 'tagcase' is "followic" or when 'tagcase' is +"match". They are found when a pattern is used (starting with a "/") and for +":tselect", also when 'ignorecase' is off and 'tagcase' is "followic" or when +'tagcase' is "match". Note that using ignore-case tag searching disables +binary searching in the tags file, which causes a slowdown. This can be +avoided by fold-case sorting the tag file. See the 'tagbsearch' option for an +explanation. ============================================================================== 2. Tag stack *tag-stack* *tagstack* *E425* @@ -418,12 +420,13 @@ file "tags". It can also be used to access a common tags file. The next file in the list is not used when: - A matching static tag for the current buffer has been found. - A matching global tag has been found. -This also depends on the 'ignorecase' option. If it is off, and the tags file -only has a match without matching case, the next tags file is searched for a -match with matching case. If no tag with matching case is found, the first -match without matching case is used. If 'ignorecase' is on, and a matching -global tag with or without matching case is found, this one is used, no -further tags files are searched. +This also depends on whether case is ignored. Case is ignored when +'ignorecase' is set and 'tagcase' is "followic", or when 'tagcase' is +"ignore". If case is not ignored, and the tags file only has a match without +matching case, the next tags file is searched for a match with matching case. +If no tag with matching case is found, the first match without matching case +is used. If case is ignored, and a matching global tag with or without +matching case is found, this one is used, no further tags files are searched. When a tag file name starts with "./", the '.' is replaced with the path of the current file. This makes it possible to use a tags file in the directory @@ -556,8 +559,10 @@ that indicates if the file was sorted. When this line is found, Vim uses binary searching for the tags file: !_TAG_FILE_SORTED<Tab>1<Tab>{anything} ~ -A tag file may be case-fold sorted to avoid a linear search when 'ignorecase' -is on. See 'tagbsearch' for details. The value '2' should be used then: +A tag file may be case-fold sorted to avoid a linear search when case is +ignored. (Case is ignored when 'ignorecase' is set and 'tagcase' is +"followic", or when 'tagcase' is "ignore".) See 'tagbsearch' for details. +The value '2' should be used then: !_TAG_FILE_SORTED<Tab>2<Tab>{anything} ~ The other tag that Vim recognizes, but only when compiled with the diff --git a/runtime/doc/undo.txt b/runtime/doc/undo.txt index 1342621516..c6c70ab6d2 100644 --- a/runtime/doc/undo.txt +++ b/runtime/doc/undo.txt @@ -250,8 +250,8 @@ ignored if its owner differs from the owner of the edited file, except when the owner of the undo file is the current user. Set 'verbose' to get a message about that when opening a file. -Undo files are normally saved in the same directory as the file. This can be -changed with the 'undodir' option. +Location of the undo files is controlled by the 'undodir' option, by default +they are saved to the dedicated directory in the application data folder. You can also save and restore undo histories by using ":wundo" and ":rundo" respectively: diff --git a/runtime/doc/usr_05.txt b/runtime/doc/usr_05.txt index 86fcf0cc2f..5aecf33557 100644 --- a/runtime/doc/usr_05.txt +++ b/runtime/doc/usr_05.txt @@ -37,9 +37,10 @@ for you), you can edit it this way: > If you don't have a vimrc file yet, see |init.vim| to find out where you can create a vimrc file. -For Unix and Macintosh this file is always used and is recommended: +This file is always used and is recommended: - ~/.config/nvim/init.vim ~ + ~/.config/nvim/init.vim (Unix and OSX) ~ + ~/AppData/Local/nvim/init.vim (Windows) ~ The vimrc file can contain all the commands that you type after a colon. The most simple ones are for setting options. For example, if you want Vim to diff --git a/runtime/doc/usr_06.txt b/runtime/doc/usr_06.txt index 1cb3eb8673..b4b495ff9f 100644 --- a/runtime/doc/usr_06.txt +++ b/runtime/doc/usr_06.txt @@ -152,7 +152,7 @@ You could also write your own color scheme. This is how you do it: directory. For Unix, this should work: > !mkdir -p ~/.config/nvim/colors - !cp $VIMRUNTIME/colors/morning.vim ~/.vim/colors/mine.vim + !cp $VIMRUNTIME/colors/morning.vim ~/.config/nvim/colors/mine.vim < This is done from Vim, because it knows the value of $VIMRUNTIME. diff --git a/runtime/doc/usr_29.txt b/runtime/doc/usr_29.txt index 22de2f6ce6..e495aad06d 100644 --- a/runtime/doc/usr_29.txt +++ b/runtime/doc/usr_29.txt @@ -255,7 +255,8 @@ function. RELATED ITEMS -You can set 'ignorecase' to make case in tag names be ignored. +To make case in tag names be ignored, you can set 'ignorecase' while leaving +'tagcase' as "followic", or set 'tagcase' to "ignore". The 'tagbsearch' option tells if the tags file is sorted or not. The default is to assume a sorted tags file, which makes a tags search a lot faster, but diff --git a/runtime/doc/various.txt b/runtime/doc/various.txt index ff37466a14..3f53e3f507 100644 --- a/runtime/doc/various.txt +++ b/runtime/doc/various.txt @@ -222,6 +222,10 @@ g8 Print the hex values of the bytes used in the modified, but can be forced with "!". See |termopen()| and |nvim-terminal-emulator| for more information. + To switch to terminal mode automatically: +> + autocmd BufEnter term://* startinsert +< *:!cmd* *:!* *E34* :!{cmd} Execute {cmd} with 'shell'. See also |:terminal|. diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index 8722fced26..508712ca75 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -21,19 +21,17 @@ these differences. ============================================================================== 1. Configuration *nvim-configuration* -- Use `$XDG_CONFIG_HOME/nvim/init.vim` instead of `.vimrc` for storing +- Use `$XDG_CONFIG_HOME/nvim/init.vim` instead of `.vimrc` for storing configuration. - Use `$XDG_CONFIG_HOME/nvim` instead of `.vim` to store configuration files. -- Use `$XDG_DATA_HOME/nvim/shada/main.shada` instead of `.viminfo` for persistent +- Use `$XDG_DATA_HOME/nvim/shada/main.shada` instead of `.viminfo` for persistent session information. ============================================================================== 2. Defaults *nvim-defaults* - Syntax highlighting is enabled by default -- Filetype-related plugins and scripts are enabled by default - Note: these defaults can be disabled with the "-u NONE" command line - argument. |-u| +- ":filetype plugin indent on" is enabled by default - 'autoindent' is set by default - 'autoread' is set by default @@ -73,56 +71,72 @@ are always available and may be used simultaneously in separate plugins. The |nvim-python|). |mkdir()| behaviour changed: -1. Assuming /tmp/foo does not exist and /tmp can be written to +1. Assuming /tmp/foo does not exist and /tmp can be written to mkdir('/tmp/foo/bar', 'p', 0700) will create both /tmp/foo and /tmp/foo/bar with 0700 permissions. Vim mkdir will create /tmp/foo with 0755. -2. If you try to create an existing directory with `'p'` (e.g. mkdir('/', +2. If you try to create an existing directory with `'p'` (e.g. mkdir('/', 'p')) mkdir() will silently exit. In Vim this was an error. 3. mkdir() error messages now include strerror() text when mkdir fails. 'encoding' cannot be changed after startup. |string()| and |:echo| behaviour changed: -1. No maximum recursion depth limit is applied to nested container +1. No maximum recursion depth limit is applied to nested container structures. -2. |string()| fails immediately on nested containers, not when recursion limit +2. |string()| fails immediately on nested containers, not when recursion limit was exceeded. 2. When |:echo| encounters duplicate containers like > let l = [] echo [l, l] < - it does not use "[...]" (was: "[[], [...]]", now: "[[], []]"). "..." is + it does not use "[...]" (was: "[[], [...]]", now: "[[], []]"). "..." is only used for recursive containers. -3. |:echo| printing nested containers adds "@level" after "..." designating - the level at which recursive container was printed: |:echo-self-refer|. - Same thing applies to |string()| (though it uses construct like - "{E724@level}"), but this is not reliable because |string()| continues to +3. |:echo| printing nested containers adds "@level" after "..." designating + the level at which recursive container was printed: |:echo-self-refer|. + Same thing applies to |string()| (though it uses construct like + "{E724@level}"), but this is not reliable because |string()| continues to error out. -4. Stringifyed infinite and NaN values now use |str2float()| and can be evaled +4. Stringifyed infinite and NaN values now use |str2float()| and can be evaled back. +5. (internal) Trying to print or stringify VAR_UNKNOWN in Vim results in + nothing, |E908|, in Neovim it is internal error. -Viminfo text files were replaced with binary (messagepack) ShaDa files. +|json_decode()| behaviour changed: +1. It may output |msgpack-special-dict|. +2. |msgpack-special-dict| is emitted also in case of duplicate keys, while in + Vim it errors out. +3. It accepts only valid JSON. Trailing commas are not accepted. + +|json_encode()| behaviour slightly changed: now |msgpack-special-dict| values +are accepted, but |v:none| is not. + +*v:none* variable is absent. In Vim it represents “no value” in “js” strings +like "[,]" parsed as "[v:none]" by |js_decode()|. + +*js_encode()* and *js_decode()* functions are also absent. + +Viminfo text files were replaced with binary (messagepack) ShaDa files. Additional differences: - |shada-c| has no effect. - |shada-s| now limits size of every item and not just registers. -- When reading ShaDa files items are merged according to the timestamp. +- When reading ShaDa files items are merged according to the timestamp. |shada-merging| -- 'viminfo' option got renamed to 'shada'. Old option is kept as an alias for +- 'viminfo' option got renamed to 'shada'. Old option is kept as an alias for compatibility reasons. -- |:wviminfo| was renamed to |:wshada|, |:rviminfo| to |:rshada|. Old +- |:wviminfo| was renamed to |:wshada|, |:rviminfo| to |:rshada|. Old commands are still kept. - |:oldfiles| supports !. -- When writing (|:wshada| without bang or at exit) it merges much more data, - and does this according to the timestamp. Vim merges only marks. +- When writing (|:wshada| without bang or at exit) it merges much more data, + and does this according to the timestamp. Vim merges only marks. |shada-merging| -- ShaDa file format was designed with forward and backward compatibility in +- ShaDa file format was designed with forward and backward compatibility in mind. |shada-compatibility| -- Some errors make ShaDa code keep temporary file in-place for user to decide - what to do with it. Vim deletes temporary file in these cases. +- Some errors make ShaDa code keep temporary file in-place for user to decide + what to do with it. Vim deletes temporary file in these cases. |shada-error-handling| -- Vim keeps no timestamps at all, neither in viminfo file nor in the instance +- Vim keeps no timestamps at all, neither in viminfo file nor in the instance itself. - ShaDa file keeps search direction (|v:searchforward|), viminfo does not. @@ -141,8 +155,8 @@ Meta (alt) chords are recognized (even in the terminal). Note: Meta chords are case-sensitive (<M-a> is distinguished from <M-A>). -Some `CTRL-SHIFT-...` key chords are distinguished from `CTRL-...` variants (even in -the terminal). Specifically, the following are known to work: +Some `CTRL-SHIFT-...` key chords are distinguished from `CTRL-...` variants +(even in the terminal). Specifically, the following are known to work: <C-Tab>, <C-S-Tab> <C-BS>, <C-S-BS> <C-Enter>, <C-S-Enter> diff --git a/runtime/doc/windows.txt b/runtime/doc/windows.txt index eee171b7da..a3f2521318 100644 --- a/runtime/doc/windows.txt +++ b/runtime/doc/windows.txt @@ -1,4 +1,4 @@ -*windows.txt* For Vim version 7.4. Last change: 2015 Jan 31 +*windows.txt* For Vim version 7.4. Last change: 2015 Aug 29 VIM REFERENCE MANUAL by Bram Moolenaar @@ -706,7 +706,7 @@ can also get to them with the buffer list commands, like ":bnext". *:bufdo* :[range]bufdo[!] {cmd} Execute {cmd} in each buffer in the buffer list or if - [range[ is given only for buffers for which their + [range] is given only for buffers for which their buffer name is in the [range]. It works like doing this: > :bfirst @@ -1099,13 +1099,13 @@ list of buffers. |unlisted-buffer| the current buffer remains being edited. See |:buffer-!| for [!]. This will also edit a buffer that is not in the buffer list, without setting the 'buflisted' flag. - Also see ||+cmd|. + Also see |+cmd|. :[N]b[uffer][!] [+cmd] {bufname} Edit buffer for {bufname} from the buffer list. See |:buffer-!| for [!]. This will also edit a buffer that is not in the buffer list, without setting the 'buflisted' flag. - Also see ||+cmd|. + Also see |+cmd|. :[N]sb[uffer] [+cmd] [N] *:sb* *:sbuffer* Split window and edit buffer [N] from the buffer list. If [N] @@ -1113,7 +1113,7 @@ list of buffers. |unlisted-buffer| "useopen" setting of 'switchbuf' when splitting. This will also edit a buffer that is not in the buffer list, without setting the 'buflisted' flag. - Also see ||+cmd|. + Also see |+cmd|. :[N]sb[uffer] [+cmd] {bufname} Split window and edit buffer for {bufname} from the buffer @@ -1122,13 +1122,13 @@ list of buffers. |unlisted-buffer| Note: If what you want to do is split the buffer, make a copy under another name, you can do it this way: > :w foobar | sp # -< Also see ||+cmd|. +< Also see |+cmd|. :[N]bn[ext][!] [+cmd] [N] *:bn* *:bnext* *E87* Go to [N]th next buffer in buffer list. [N] defaults to one. Wraps around the end of the buffer list. See |:buffer-!| for [!]. - Also see ||+cmd|. + Also see |+cmd|. If you are in a help buffer, this takes you to the next help buffer (if there is one). Similarly, if you are in a normal (non-help) buffer, this takes you to the next normal buffer. @@ -1141,21 +1141,21 @@ list of buffers. |unlisted-buffer| :[N]sbn[ext] [+cmd] [N] Split window and go to [N]th next buffer in buffer list. Wraps around the end of the buffer list. Uses 'switchbuf' - Also see ||+cmd|. + Also see |+cmd|. :[N]bN[ext][!] [+cmd] [N] *:bN* *:bNext* *:bp* *:bprevious* *E88* :[N]bp[revious][!] [+cmd] [N] Go to [N]th previous buffer in buffer list. [N] defaults to one. Wraps around the start of the buffer list. See |:buffer-!| for [!] and 'switchbuf'. - Also see ||+cmd|. + Also see |+cmd|. :[N]sbN[ext] [+cmd] [N] *:sbN* *:sbNext* *:sbp* *:sbprevious* :[N]sbp[revious] [+cmd] [N] Split window and go to [N]th previous buffer in buffer list. Wraps around the start of the buffer list. Uses 'switchbuf'. - Also see ||+cmd|. + Also see |+cmd|. :br[ewind][!] [+cmd] *:br* *:brewind* Go to first buffer in buffer list. If the buffer list is diff --git a/runtime/filetype.vim b/runtime/filetype.vim index d60ab65ce7..757b9a0db7 100644 --- a/runtime/filetype.vim +++ b/runtime/filetype.vim @@ -1,7 +1,7 @@ " Vim support file to detect file types " " Maintainer: Bram Moolenaar <Bram@vim.org> -" Last Change: 2015 Apr 06 +" Last Change: 2015 Oct 13 " Listen very carefully, I will say this only once if exists("did_load_filetypes") @@ -139,7 +139,7 @@ au BufNewFile,BufRead .arch-inventory,=tagging-method setf arch au BufNewFile,BufRead *.art setf art " AsciiDoc -au BufNewFile,BufRead *.asciidoc setf asciidoc +au BufNewFile,BufRead *.asciidoc,*.adoc setf asciidoc " ASN.1 au BufNewFile,BufRead *.asn,*.asn1 setf asn @@ -304,6 +304,9 @@ au BufNewFile,BufRead *.bl setf blank " Blkid cache file au BufNewFile,BufRead */etc/blkid.tab,*/etc/blkid.tab.old setf xml +" Bazel (http://bazel.io) +autocmd BufRead,BufNewFile *.bzl,BUILD,WORKSPACE setfiletype bzl + " C or lpc au BufNewFile,BufRead *.c call s:FTlpc() @@ -822,7 +825,7 @@ au BufNewFile,BufRead *.gs setf grads au BufNewFile,BufRead *.gretl setf gretl " Groovy -au BufNewFile,BufRead *.groovy setf groovy +au BufNewFile,BufRead *.gradle,*.groovy setf groovy " GNU Server Pages au BufNewFile,BufRead *.gsp setf gsp @@ -1164,7 +1167,7 @@ func! s:FTm() let n = 1 while n < 10 let line = getline(n) - if line =~ '^\s*\(#\s*\(include\|import\)\>\|/\*\|//\)' + if line =~ '^\s*\(#\s*\(include\|import\)\>\|@import\>\|/\*\|//\)' setf objc return endif @@ -1332,7 +1335,7 @@ func! s:FTmm() let n = 1 while n < 10 let line = getline(n) - if line =~ '^\s*\(#\s*\(include\|import\)\>\|/\*\)' + if line =~ '^\s*\(#\s*\(include\|import\)\>\|@import\>\|/\*\)' setf objcpp return endif @@ -1855,7 +1858,7 @@ au BufNewFile,BufRead sgml.catalog* call s:StarSetf('catalog') " Shell scripts (sh, ksh, bash, bash2, csh); Allow .profile_foo etc. " Gentoo ebuilds and Arch Linux PKGBUILDs are actually bash scripts -au BufNewFile,BufRead .bashrc*,bashrc,bash.bashrc,.bash_profile*,.bash_logout*,.bash_aliases*,*.bash,*.ebuild,PKGBUILD* call SetFileTypeSH("bash") +au BufNewFile,BufRead .bashrc*,bashrc,bash.bashrc,.bash[_-]profile*,.bash[_-]logout*,.bash[_-]aliases*,*.bash,*/{,.}bash[_-]completion{,.d,.sh}{,/*},*.ebuild,*.eclass call SetFileTypeSH("bash") au BufNewFile,BufRead .kshrc*,*.ksh call SetFileTypeSH("ksh") au BufNewFile,BufRead */etc/profile,.profile*,*.sh,*.env call SetFileTypeSH(getline(1)) @@ -2119,6 +2122,9 @@ au BufNewFile,BufRead *.cm setf voscm " Sysctl au BufNewFile,BufRead */etc/sysctl.conf,*/etc/sysctl.d/*.conf setf sysctl +" Systemd unit files +au BufNewFile,BufRead */systemd/*.{automount,mount,path,service,socket,swap,target,timer} setf systemd + " Synopsys Design Constraints au BufNewFile,BufRead *.sdc setf sdc @@ -2174,6 +2180,9 @@ au BufNewFile,BufRead *.tli setf tli " Telix Salt au BufNewFile,BufRead *.slt setf tsalt +" Tera Term Language +au BufRead,BufNewFile *.ttl setf teraterm + " Terminfo au BufNewFile,BufRead *.ti setf terminfo diff --git a/runtime/ftplugin/bzl.vim b/runtime/ftplugin/bzl.vim new file mode 100644 index 0000000000..0296b0c0b8 --- /dev/null +++ b/runtime/ftplugin/bzl.vim @@ -0,0 +1,94 @@ +" Vim filetype plugin file +" Language: Bazel (http://bazel.io) +" Maintainer: David Barnett (https://github.com/google/vim-ft-bzl) +" Last Change: 2015 Aug 11 + +"" +" @section Introduction, intro +" Core settings for the bzl filetype, used for BUILD and *.bzl files for the +" Bazel build system (http://bazel.io/). + +if exists('b:did_ftplugin') + finish +endif + + +" Vim 7.4.051 has opinionated settings in ftplugin/python.vim that try to force +" PEP8 conventions on every python file, but these conflict with Google's +" indentation guidelines. As a workaround, we explicitly source the system +" ftplugin, but save indentation settings beforehand and restore them after. +let s:save_expandtab = &l:expandtab +let s:save_shiftwidth = &l:shiftwidth +let s:save_softtabstop = &l:softtabstop +let s:save_tabstop = &l:tabstop + +" NOTE: Vim versions before 7.3.511 had a ftplugin/python.vim that was broken +" for compatible mode. +let s:save_cpo = &cpo +set cpo&vim + +" Load base python ftplugin (also defines b:did_ftplugin). +source $VIMRUNTIME/ftplugin/python.vim + +" NOTE: Vim versions before 7.4.104 and later set this in ftplugin/python.vim. +setlocal comments=b:#,fb:- + +" Restore pre-existing indentation settings. +let &l:expandtab = s:save_expandtab +let &l:shiftwidth = s:save_shiftwidth +let &l:softtabstop = s:save_softtabstop +let &l:tabstop = s:save_tabstop + +setlocal formatoptions-=t + +" Make gf work with imports in BUILD files. +setlocal includeexpr=substitute(v:fname,'//','','') + +" Enable syntax-based folding, if specified. +if get(g:, 'ft_bzl_fold', 0) + setlocal foldmethod=syntax + setlocal foldtext=BzlFoldText() +endif + +if exists('*BzlFoldText') + finish +endif + +function BzlFoldText() abort + let l:start_num = nextnonblank(v:foldstart) + let l:end_num = prevnonblank(v:foldend) + + if l:end_num <= l:start_num + 1 + " If the fold is empty, don't print anything for the contents. + let l:content = '' + else + " Otherwise look for something matching the content regex. + " And if nothing matches, print an ellipsis. + let l:content = '...' + for l:line in getline(l:start_num + 1, l:end_num - 1) + let l:content_match = matchstr(l:line, '\m\C^\s*name = \zs.*\ze,$') + if !empty(l:content_match) + let l:content = l:content_match + break + endif + endfor + endif + + " Enclose content with start and end + let l:start_text = getline(l:start_num) + let l:end_text = substitute(getline(l:end_num), '^\s*', '', '') + let l:text = l:start_text . ' ' . l:content . ' ' . l:end_text + + " Compute the available width for the displayed text. + let l:width = winwidth(0) - &foldcolumn - (&number ? &numberwidth : 0) + let l:lines_folded = ' ' . string(1 + v:foldend - v:foldstart) . ' lines' + + " Expand tabs, truncate, pad, and concatenate + let l:text = substitute(l:text, '\t', repeat(' ', &tabstop), 'g') + let l:text = strpart(l:text, 0, l:width - len(l:lines_folded)) + let l:padding = repeat(' ', l:width - len(l:lines_folded) - len(l:text)) + return l:text . l:padding . l:lines_folded +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/runtime/ftplugin/j.vim b/runtime/ftplugin/j.vim index 774696836f..9dc1692534 100644 --- a/runtime/ftplugin/j.vim +++ b/runtime/ftplugin/j.vim @@ -2,7 +2,7 @@ " Language: J " Maintainer: David Bürgin <676c7473@gmail.com> " URL: https://github.com/glts/vim-j -" Last Change: 2015-03-27 +" Last Change: 2015-09-27 if exists('b:did_ftplugin') finish @@ -12,13 +12,20 @@ let b:did_ftplugin = 1 let s:save_cpo = &cpo set cpo&vim -setlocal iskeyword=48-57,A-Z,_,a-z +setlocal iskeyword=48-57,A-Z,a-z,_ setlocal comments=:NB. setlocal commentstring=NB.\ %s setlocal formatoptions-=t setlocal matchpairs=(:) +setlocal path-=/usr/include -let b:undo_ftplugin = 'setlocal matchpairs< formatoptions< commentstring< comments< iskeyword<' +" Includes. To make the shorthand form "require 'web/cgi'" work, double the +" last path component. Also strip off leading folder names like "~addons/". +setlocal include=\\v^\\s*(load\|require)\\s*'\\zs\\f+\\ze' +setlocal includeexpr=substitute(substitute(tr(v:fname,'\\','/'),'\\v^[^~][^/.]*(/[^/.]+)$','&\\1',''),'\\v^\\~[^/]+/','','') +setlocal suffixesadd=.ijs + +let b:undo_ftplugin = 'setlocal matchpairs< formatoptions< commentstring< comments< iskeyword< path< include< includeexpr< suffixesadd<' " Section movement with ]] ][ [[ []. The start/end patterns below are amended " inside the function in order to avoid matching on the current cursor line. diff --git a/runtime/ftplugin/man.vim b/runtime/ftplugin/man.vim index 133a28e626..36cd70f203 100644 --- a/runtime/ftplugin/man.vim +++ b/runtime/ftplugin/man.vim @@ -24,11 +24,11 @@ setlocal buftype=nofile noswapfile setlocal nomodifiable readonly bufhidden=hide nobuflisted tabstop=8 if !exists("g:no_plugin_maps") && !exists("g:no_man_maps") - nnoremap <silent> <buffer> <C-]> :call man#get_page(v:count)<CR> + nnoremap <silent> <buffer> <C-]> :call man#get_page(v:count, expand('<cword>'))<CR> nnoremap <silent> <buffer> <C-T> :call man#pop_page()<CR> nnoremap <silent> <nowait><buffer> q <C-W>c if &keywordprg !=# ':Man' - nnoremap <silent> <buffer> K :call man#get_page(v:count)<CR> + nnoremap <silent> <buffer> K :call man#get_page(v:count, expand('<cword>'))<CR> endif endif diff --git a/runtime/ftplugin/spec.vim b/runtime/ftplugin/spec.vim index f972753533..6d5bf4b806 100644 --- a/runtime/ftplugin/spec.vim +++ b/runtime/ftplugin/spec.vim @@ -2,7 +2,7 @@ " Filename: spec.vim " Maintainer: Igor Gnatenko i.gnatenko.brain@gmail.com " Former Maintainer: Gustavo Niemeyer <niemeyer@conectiva.com> (until March 2014) -" Last Change: Fri Feb 20 16:01 MSK 2014 Igor Gnatenko +" Last Change: Mon Jun 01 21:15 MSK 2015 Igor Gnatenko if exists("b:did_ftplugin") finish diff --git a/runtime/ftplugin/systemd.vim b/runtime/ftplugin/systemd.vim new file mode 100644 index 0000000000..60b3fd996d --- /dev/null +++ b/runtime/ftplugin/systemd.vim @@ -0,0 +1,7 @@ +" Vim filetype plugin file +" Language: systemd.unit(5) + +if !exists('b:did_ftplugin') + " Looks a lot like dosini files. + runtime! ftplugin/dosini.vim +endif diff --git a/runtime/indent/bzl.vim b/runtime/indent/bzl.vim new file mode 100644 index 0000000000..24e5b870cd --- /dev/null +++ b/runtime/indent/bzl.vim @@ -0,0 +1,97 @@ +" Vim indent file +" Language: Bazel (http://bazel.io) +" Maintainer: David Barnett (https://github.com/google/vim-ft-bzl) +" Last Change: 2015 Aug 11 + +if exists('b:did_indent') + finish +endif + +" Load base python indent. +if !exists('*GetPythonIndent') + runtime! indent/python.vim +endif + +let b:did_indent = 1 + +" Only enable bzl google indent if python google indent is enabled. +if !get(g:, 'no_google_python_indent') + setlocal indentexpr=GetBzlIndent(v:lnum) +endif + +if exists('*GetBzlIndent') + finish +endif + +let s:save_cpo = &cpo +set cpo-=C + +" Maximum number of lines to look backwards. +let s:maxoff = 50 + +"" +" Determine the correct indent level given an {lnum} in the current buffer. +function GetBzlIndent(lnum) abort + let l:use_recursive_indent = !get(g:, 'no_google_python_recursive_indent') + if l:use_recursive_indent + " Backup and override indent setting variables. + if exists('g:pyindent_nested_paren') + let l:pyindent_nested_paren = g:pyindent_nested_paren + endif + if exists('g:pyindent_open_paren') + let l:pyindent_open_paren = g:pyindent_open_paren + endif + " Vim 7.3.693 and later defines a shiftwidth() function to get the effective + " shiftwidth value. Fall back to &shiftwidth if the function doesn't exist. + let l:sw_expr = exists('*shiftwidth') ? 'shiftwidth()' : '&shiftwidth' + let g:pyindent_nested_paren = l:sw_expr . ' * 2' + let g:pyindent_open_paren = l:sw_expr . ' * 2' + endif + + let l:indent = -1 + + " Indent inside parens. + " Align with the open paren unless it is at the end of the line. + " E.g. + " open_paren_not_at_EOL(100, + " (200, + " 300), + " 400) + " open_paren_at_EOL( + " 100, 200, 300, 400) + call cursor(a:lnum, 1) + let [l:par_line, l:par_col] = searchpairpos('(\|{\|\[', '', ')\|}\|\]', 'bW', + \ "line('.') < " . (a:lnum - s:maxoff) . " ? dummy :" . + \ " synIDattr(synID(line('.'), col('.'), 1), 'name')" . + \ " =~ '\\(Comment\\|String\\)$'") + if l:par_line > 0 + call cursor(l:par_line, 1) + if l:par_col != col('$') - 1 + let l:indent = l:par_col + endif + endif + + " Delegate the rest to the original function. + if l:indent == -1 + let l:indent = GetPythonIndent(a:lnum) + endif + + if l:use_recursive_indent + " Restore global variables. + if exists('l:pyindent_nested_paren') + let g:pyindent_nested_paren = l:pyindent_nested_paren + else + unlet g:pyindent_nested_paren + endif + if exists('l:pyindent_open_paren') + let g:pyindent_open_paren = l:pyindent_open_paren + else + unlet g:pyindent_open_paren + endif + endif + + return l:indent +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/runtime/indent/html.vim b/runtime/indent/html.vim index 7eb963b7b2..8aaf82e21f 100644 --- a/runtime/indent/html.vim +++ b/runtime/indent/html.vim @@ -2,7 +2,7 @@ " Header: "{{{ " Maintainer: Bram Moolenaar " Original Author: Andy Wokula <anwoku@yahoo.de> -" Last Change: 2015 Jun 12 +" Last Change: 2015 Sep 25 " Version: 1.0 " Description: HTML indent script with cached state for faster indenting on a " range of lines. @@ -178,13 +178,15 @@ let s:countonly = 0 " 3 "script" " 4 "style" " 5 comment start +" 6 conditional comment start " -1 closing tag " -2 "/pre" " -3 "/script" " -4 "/style" " -5 comment end +" -6 conditional comment end let s:indent_tags = {} -let s:endtags = [0,0,0,0,0,0] " long enough for the highest index +let s:endtags = [0,0,0,0,0,0,0] " long enough for the highest index "}}} " Add a list of tag names for a pair of <tag> </tag> to "tags". @@ -257,6 +259,7 @@ call s:AddBlockTag('pre', 2) call s:AddBlockTag('script', 3) call s:AddBlockTag('style', 4) call s:AddBlockTag('<!--', 5, '-->') +call s:AddBlockTag('<!--[', 6, '![endif]-->') "}}} " Return non-zero when "tagname" is an opening tag, not being a block tag, for @@ -291,7 +294,7 @@ func! s:CountITags(text) let s:nextrel = 0 " relative indent steps for next line [unit &sw]: let s:block = 0 " assume starting outside of a block let s:countonly = 1 " don't change state - call substitute(a:text, '<\zs/\=\w\+\(-\w\+\)*\>\|<!--\|-->', '\=s:CheckTag(submatch(0))', 'g') + call substitute(a:text, '<\zs/\=\w\+\(-\w\+\)*\>\|<!--\[\|\[endif\]-->\|<!--\|-->', '\=s:CheckTag(submatch(0))', 'g') let s:countonly = 0 endfunc "}}} @@ -303,7 +306,7 @@ func! s:CountTagsAndState(text) let s:nextrel = 0 " relative indent steps for next line [unit &sw]: let s:block = b:hi_newstate.block - let tmp = substitute(a:text, '<\zs/\=\w\+\(-\w\+\)*\>\|<!--\|-->', '\=s:CheckTag(submatch(0))', 'g') + let tmp = substitute(a:text, '<\zs/\=\w\+\(-\w\+\)*\>\|<!--\[\|\[endif\]-->\|<!--\|-->', '\=s:CheckTag(submatch(0))', 'g') if s:block == 3 let b:hi_newstate.scripttype = s:GetScriptType(matchstr(tmp, '\C.*<SCRIPT\>\zs[^>]*')) endif @@ -425,7 +428,7 @@ func! s:FreshState(lnum) " State: " lnum last indented line == prevnonblank(a:lnum - 1) " block = 0 a:lnum located within special tag: 0:none, 2:<pre>, - " 3:<script>, 4:<style>, 5:<!-- + " 3:<script>, 4:<style>, 5:<!--, 6:<!--[ " baseindent use this indent for line a:lnum as a start - kind of " autoindent (if block==0) " scripttype = '' type attribute of a script tag (if block==3) @@ -464,10 +467,13 @@ func! s:FreshState(lnum) " FI " look back for a blocktag - call cursor(a:lnum, 1) - let [stopline, stopcol] = searchpos('\c<\zs\/\=\%(pre\>\|script\>\|style\>\)', "bW") - if stopline > 0 - " fugly ... why isn't there searchstr() + let stopline2 = v:lnum + 1 + if has_key(b:hi_indent, 'block') && b:hi_indent.block > 5 + let [stopline2, stopcol2] = searchpos('<!--', 'bnW') + endif + let [stopline, stopcol] = searchpos('\c<\zs\/\=\%(pre\>\|script\>\|style\>\)', "bnW") + if stopline > 0 && stopline < stopline2 + " ugly ... why isn't there searchstr() let tagline = tolower(getline(stopline)) let blocktag = matchstr(tagline, '\/\=\%(pre\>\|script\>\|style\>\)', stopcol - 1) if blocktag[0] != "/" @@ -487,23 +493,29 @@ func! s:FreshState(lnum) " blocktag == "/..." let swendtag = match(tagline, '^\s*</') >= 0 if !swendtag - let [bline, bcol] = searchpos('<'.blocktag[1:].'\>', "bW") + let [bline, bcol] = searchpos('<'.blocktag[1:].'\>', "bnW") call s:CountITags(tolower(getline(bline)[: bcol-2])) let state.baseindent = indent(bline) + (s:curind + s:nextrel) * s:ShiftWidth() return state endif endif endif + if stopline > stopline2 + let stopline = stopline2 + let stopcol = stopcol2 + endif " else look back for comment - call cursor(a:lnum, 1) - let [comlnum, comcol, found] = searchpos('\(<!--\)\|-->', 'bpW', stopline) - if found == 2 + let [comlnum, comcol, found] = searchpos('\(<!--\[\)\|\(<!--\)\|-->', 'bpnW', stopline) + if found == 2 || found == 3 " comment opener found, assume a:lnum within comment - let state.block = 5 + let state.block = (found == 3 ? 5 : 6) let state.blocklnr = comlnum " check preceding tags in the line: call s:CountITags(tolower(getline(comlnum)[: comcol-2])) + if found == 2 + let state.baseindent = b:hi_indent.baseindent + endif let state.blocktagind = indent(comlnum) + (s:curind + s:nextrel) * s:ShiftWidth() return state endif @@ -819,6 +831,20 @@ func! s:Alien5() return indent(prevlnum) endfunc "}}} +" Return the indent for conditional comment: <!--[ ![endif]--> +func! s:Alien6() + "{{{ + let curtext = getline(v:lnum) + if curtext =~ '\s*\zs<!\[endif\]-->' + " current line starts with end of comment, line up with comment start. + let lnum = search('<!--', 'bn') + if lnum > 0 + return indent(lnum) + endif + endif + return b:hi_indent.baseindent + s:ShiftWidth() +endfunc "}}} + " When the "lnum" line ends in ">" find the line containing the matching "<". func! HtmlIndent_FindTagStart(lnum) "{{{ diff --git a/runtime/indent/sh.vim b/runtime/indent/sh.vim index 0394ee22e8..b2f35b23a7 100644 --- a/runtime/indent/sh.vim +++ b/runtime/indent/sh.vim @@ -1,8 +1,11 @@ " Vim indent file -" Language: Shell Script -" Maintainer: Peter Aronoff <telemachus@arpinum.org> -" Original Author: Nikolai Weibull <now@bitwi.se> -" Latest Revision: 2014-08-22 +" Language: Shell Script +" Maintainer: Christian Brabandt <cb@256bit.org> +" Previous Maintainer: Peter Aronoff <telemachus@arpinum.org> +" Original Author: Nikolai Weibull <now@bitwi.se> +" Latest Revision: 2015-07-28 +" License: Vim (see :h license) +" Repository: https://github.com/chrisbra/vim-sh-indent if exists("b:did_indent") finish @@ -10,7 +13,7 @@ endif let b:did_indent = 1 setlocal indentexpr=GetShIndent() -setlocal indentkeys+=0=then,0=do,0=else,0=elif,0=fi,0=esac,0=done,),0=;;,0=;& +setlocal indentkeys+=0=then,0=do,0=else,0=elif,0=fi,0=esac,0=done,0=end,),0=;;,0=;& setlocal indentkeys+=0=fin,0=fil,0=fip,0=fir,0=fix setlocal indentkeys-=:,0# setlocal nosmartindent @@ -54,8 +57,8 @@ function! GetShIndent() let ind = indent(lnum) let line = getline(lnum) - if line =~ '^\s*\%(if\|then\|do\|else\|elif\|case\|while\|until\|for\|select\)\>' - if line !~ '\<\%(fi\|esac\|done\)\>\s*\%(#.*\)\=$' + if line =~ '^\s*\%(if\|then\|do\|else\|elif\|case\|while\|until\|for\|select\|foreach\)\>' + if line !~ '\<\%(fi\|esac\|done\|end\)\>\s*\%(#.*\)\=$' let ind += s:indent_value('default') endif elseif s:is_case_label(line, pnum) @@ -76,7 +79,7 @@ function! GetShIndent() let pine = line let line = getline(v:lnum) - if line =~ '^\s*\%(then\|do\|else\|elif\|fi\|done\)\>' || line =~ '^\s*}' + if line =~ '^\s*\%(then\|do\|else\|elif\|fi\|done\|end\)\>' || line =~ '^\s*}' let ind -= s:indent_value('default') elseif line =~ '^\s*esac\>' && s:is_case_empty(getline(v:lnum - 1)) let ind -= s:indent_value('default') diff --git a/runtime/indent/systemd.vim b/runtime/indent/systemd.vim new file mode 100644 index 0000000000..a05a87bb1c --- /dev/null +++ b/runtime/indent/systemd.vim @@ -0,0 +1,10 @@ +" Vim indent file +" Language: systemd.unit(5) + +" Only load this indent file when no other was loaded. +if exists("b:did_indent") + finish +endif + +" Looks a lot like dosini files. +runtime! indent/dosini.vim diff --git a/runtime/indent/teraterm.vim b/runtime/indent/teraterm.vim new file mode 100644 index 0000000000..ba24257b02 --- /dev/null +++ b/runtime/indent/teraterm.vim @@ -0,0 +1,67 @@ +" Vim indent file +" Language: Tera Term Language (TTL) +" Based on Tera Term Version 4.86 +" Maintainer: Ken Takata +" URL: https://github.com/k-takata/vim-teraterm +" Last Change: 2015 Jun 4 +" Filenames: *.ttl +" License: VIM License + +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 + +setlocal nosmartindent +setlocal noautoindent +setlocal indentexpr=GetTeraTermIndent(v:lnum) +setlocal indentkeys=!^F,o,O,e +setlocal indentkeys+==elseif,=endif,=loop,=next,=enduntil,=endwhile + +if exists("*GetTeraTermIndent") + finish +endif + +" The shiftwidth() function is relatively new. +" Don't require it to exist. +if exists('*shiftwidth') + function s:sw() abort + return shiftwidth() + endfunction +else + function s:sw() abort + return &shiftwidth + endfunction +endif + +function! GetTeraTermIndent(lnum) + let l:prevlnum = prevnonblank(a:lnum-1) + if l:prevlnum == 0 + " top of file + return 0 + endif + + " grab the previous and current line, stripping comments. + let l:prevl = substitute(getline(l:prevlnum), ';.*$', '', '') + let l:thisl = substitute(getline(a:lnum), ';.*$', '', '') + let l:previ = indent(l:prevlnum) + + let l:ind = l:previ + + if l:prevl =~ '^\s*if\>.*\<then\s*$' + " previous line opened a block + let l:ind += s:sw() + endif + if l:prevl =~ '^\s*\%(elseif\|else\|do\|until\|while\|for\)\>' + " previous line opened a block + let l:ind += s:sw() + endif + if l:thisl =~ '^\s*\%(elseif\|else\|endif\|enduntil\|endwhile\|loop\|next\)\>' + " this line closed a block + let l:ind -= s:sw() + endif + + return l:ind +endfunction + +" vim: ts=8 sw=2 sts=2 diff --git a/runtime/indent/yaml.vim b/runtime/indent/yaml.vim index 1d03715773..95a53b1386 100644 --- a/runtime/indent/yaml.vim +++ b/runtime/indent/yaml.vim @@ -1,6 +1,7 @@ " Vim indent file " Language: YAML " Maintainer: Nikolai Pavlov <zyx.vim@gmail.com> +" Last Change: 2015 Sep 25 " Only load this indent file when no other was loaded. if exists('b:did_indent') @@ -115,8 +116,13 @@ function GetYAMLIndent(lnum) \ s:liststartregex)) elseif line =~# s:mapkeyregex " Same for line containing mapping key - return indent(s:FindPrevLEIndentedLineMatchingRegex(a:lnum, - \ s:mapkeyregex)) + let prevmapline = s:FindPrevLEIndentedLineMatchingRegex(a:lnum, + \ s:mapkeyregex) + if getline(prevmapline) =~# '^\s*- ' + return indent(prevmapline) + 2 + else + return indent(prevmapline) + endif elseif prevline =~# '^\s*- ' " - List with " multiline scalar diff --git a/runtime/macros/less.bat b/runtime/macros/less.bat index bbe619bc92..7395a70003 100644 --- a/runtime/macros/less.bat +++ b/runtime/macros/less.bat @@ -4,7 +4,7 @@ rem Read stdin if no arguments were given. rem Written by Ken Takata. if "%1"=="" ( - vim --cmd "let no_plugin_maps = 1" -c "runtime! macros/less.vim" - + nvim --cmd "let no_plugin_maps = 1" -c "runtime! macros/less.vim" - ) else ( - vim --cmd "let no_plugin_maps = 1" -c "runtime! macros/less.vim" %* + nvim --cmd "let no_plugin_maps = 1" -c "runtime! macros/less.vim" %* ) diff --git a/runtime/macros/less.sh b/runtime/macros/less.sh index e29958f7ad..125162f10a 100755 --- a/runtime/macros/less.sh +++ b/runtime/macros/less.sh @@ -8,9 +8,9 @@ if test -t 1; then echo "Missing filename" 1>&2 exit fi - vim --cmd 'let no_plugin_maps = 1' -c 'runtime! macros/less.vim' - + nvim --cmd 'let no_plugin_maps = 1' -c 'runtime! macros/less.vim' - else - vim --cmd 'let no_plugin_maps = 1' -c 'runtime! macros/less.vim' "$@" + nvim --cmd 'let no_plugin_maps = 1' -c 'runtime! macros/less.vim' "$@" fi else # Output is not a terminal, cat arguments or stdin diff --git a/runtime/makemenu.vim b/runtime/makemenu.vim index b78fdfd601..839dbdac07 100644 --- a/runtime/makemenu.vim +++ b/runtime/makemenu.vim @@ -177,6 +177,7 @@ SynMenu DE.Doxygen.C\ with\ doxygen:c.doxygen SynMenu DE.Doxygen.C++\ with\ doxygen:cpp.doxygen SynMenu DE.Doxygen.IDL\ with\ doxygen:idl.doxygen SynMenu DE.Doxygen.Java\ with\ doxygen:java.doxygen +SynMenu DE.Doxygen.DataScript\ with\ doxygen:datascript.doxygen SynMenu DE.Dracula:dracula SynMenu DE.DSSSL:dsl SynMenu DE.DTD:dtd diff --git a/runtime/optwin.vim b/runtime/optwin.vim index a092f18d23..7050436aab 100644 --- a/runtime/optwin.vim +++ b/runtime/optwin.vim @@ -1,7 +1,7 @@ " These commands create the option window. " " Maintainer: Bram Moolenaar <Bram@vim.org> -" Last Change: 2014 Nov 19 +" Last Change: 2015 Jul 22 " If there already is an option window, jump to that one. if bufwinnr("option-window") > 0 @@ -289,6 +289,10 @@ call append("$", " \tset tl=" . &tl) call append("$", "tags\tlist of file names to search for tags") call append("$", "\t(global or local to buffer)") call <SID>OptionG("tag", &tag) +call append("$", "tagcase\thow to handle case when searching in tags files:") +call append("$", "\t\"followic\" to follow 'ignorecase', \"ignore\" or \"match\"") +call append("$", "\t(global or local to buffer)") +call <SID>OptionG("tc", &tc) call append("$", "tagrelative\tfile names in a tags file are relative to the tags file") call <SID>BinOptionG("tr", &tr) call append("$", "tagstack\ta :tag command will use the tagstack") @@ -673,6 +677,8 @@ call append("$", "errorbells\tring the bell for error messages") call <SID>BinOptionG("eb", &eb) call append("$", "visualbell\tuse a visual bell instead of beeping") call <SID>BinOptionG("vb", &vb) +call append("$", "belloff\tdo not ring the bell for these reasons") +call <SID>OptionG("belloff", &belloff) if has("multi_lang") call append("$", "helplang\tlist of preferred languages for finding help") call <SID>OptionG("hlg", &hlg) @@ -922,7 +928,7 @@ call <SID>BinOptionL("bin") call append("$", "endofline\tlast line in the file has an end-of-line") call append("$", "\t(local to buffer)") call <SID>BinOptionL("eol") -call append("$", "fixeol\tfixes missing end-of-line at end of text file") +call append("$", "fixendofline\tfixes missing end-of-line at end of text file") call append("$", "\t(local to buffer)") call <SID>BinOptionL("fixeol") if has("multi_byte") diff --git a/runtime/plugin/matchit.vim b/runtime/plugin/matchit.vim index 74c1a1eb92..70867b1f93 100644 --- a/runtime/plugin/matchit.vim +++ b/runtime/plugin/matchit.vim @@ -303,7 +303,7 @@ fun! s:CleanUp(options, mode, startline, startcol, ...) let regexp = s:Wholematch(matchline, a:1, currcol-1) let endcol = matchend(matchline, regexp) if endcol > currcol " This is NOT off by one! - execute "normal!" . (endcol - currcol) . "l" + call cursor(0, endcol) endif endif " a:0 endif " a:mode != "o" && etc. diff --git a/runtime/plugin/rplugin.vim b/runtime/plugin/rplugin.vim index 879775ff0e..b4b03032b3 100644 --- a/runtime/plugin/rplugin.vim +++ b/runtime/plugin/rplugin.vim @@ -1,5 +1,16 @@ -if exists('g:loaded_remote_plugins') || &cp +if exists('g:loaded_remote_plugins') finish endif let g:loaded_remote_plugins = 1 -call remote#host#LoadRemotePlugins() + +command! UpdateRemotePlugins call remote#host#UpdateRemotePlugins() + +augroup nvim-rplugin + autocmd! + autocmd FuncUndefined * + \ call remote#host#LoadRemotePluginsEvent( + \ 'FuncUndefined', expand('<amatch>')) + autocmd CmdUndefined * + \ call remote#host#LoadRemotePluginsEvent( + \ 'CmdUndefined', expand('<amatch>')) +augroup END diff --git a/runtime/plugin/spellfile.vim b/runtime/plugin/spellfile.vim index 437296090c..e03659d6d6 100644 --- a/runtime/plugin/spellfile.vim +++ b/runtime/plugin/spellfile.vim @@ -1,15 +1,8 @@ " Vim plugin for downloading spell files -" Maintainer: Bram Moolenaar <Bram@vim.org> -" Last Change: 2006 Feb 01 -" Exit quickly when: -" - this plugin was already loaded -" - when 'compatible' is set -" - some autocommands are already taking care of spell files if exists("loaded_spellfile_plugin") || &cp || exists("#SpellFileMissing") finish endif let loaded_spellfile_plugin = 1 -" The function is in the autoload directory. autocmd SpellFileMissing * call spellfile#LoadFile(expand('<amatch>')) diff --git a/runtime/plugin/tohtml.vim b/runtime/plugin/tohtml.vim index eb47b1a7c3..b438dea811 100644 --- a/runtime/plugin/tohtml.vim +++ b/runtime/plugin/tohtml.vim @@ -1,6 +1,6 @@ " Vim plugin for converting a syntax highlighted file to HTML. " Maintainer: Ben Fritz <fritzophrenic@gmail.com> -" Last Change: 2013 Jul 08 +" Last Change: 2015 Sep 08 " " The core of the code is in $VIMRUNTIME/autoload/tohtml.vim and " $VIMRUNTIME/syntax/2html.vim @@ -67,20 +67,24 @@ if exists('g:loaded_2html_plugin') finish endif -let g:loaded_2html_plugin = 'vim7.4_v1' +let g:loaded_2html_plugin = 'vim7.4_v2' " " Changelog: {{{ -" 7.4_v1 (this version): Fix modeline mangling for new "Vim:" format, and +" 7.4_v2 (this version): Fix error raised when converting a diff containing +" an empty buffer. Jan Stocker: allow g:html_font to +" take a list so it is easier to specfiy fallback +" fonts in the generated CSS. +" 7.4_v1 (Vim 7.4.0000): Fix modeline mangling for new "Vim:" format, and " also for version-specific modelines like "vim>703:". " " 7.3 updates: {{{ -" 7.3_v14 (ad6996a23e3e): Allow suppressing line number anchors using +" 7.3_v14 (Vim 7.3.1246): Allow suppressing line number anchors using " g:html_line_ids=0. Allow customizing " important IDs (like line IDs and fold IDs) using " g:html_id_expr evalutated when the buffer conversion " is started. -" 7.3_v13 (2eb30f341e8d): Keep foldmethod at manual in the generated file and +" 7.3_v13 (Vim 7.3.1088): Keep foldmethod at manual in the generated file and " insert modeline to set it to manual. " Fix bug: diff mode with 2 unsaved buffers creates a " duplicate of one buffer instead of including both. @@ -91,7 +95,7 @@ let g:loaded_2html_plugin = 'vim7.4_v1' " Fix XML validation error: &nsbp; not part of XML. " Allow TOhtml to chain together with other commands " using |. -" 7.3_v12 (9910cbff5f16): Fix modeline mangling to also work for when multiple +" 7.3_v12 (Vim 7.3.0616): Fix modeline mangling to also work for when multiple " highlight groups make up the start-of-modeline text. " Improve render time of page with uncopyable regions " by not using one-input-per-char. Change name of @@ -117,23 +121,23 @@ let g:loaded_2html_plugin = 'vim7.4_v1' " http://groups.google.com/d/topic/vim_dev/B6FSGfq9VoI/discussion. " This patch has not yet been included in Vim, thus " these changes are removed in the next version. -" 7.3_v10 (fd09a9c8468e): Fix error E684 when converting a range wholly inside +" 7.3_v10 (Vim 7.3.0227): Fix error E684 when converting a range wholly inside " multiple nested folds with dynamic folding on. " Also fix problem with foldtext in this situation. -" 7.3_v9 (0877b8d6370e): Add html_pre_wrap option active with html_use_css +" 7.3_v9 (Vim 7.3.0170): Add html_pre_wrap option active with html_use_css " and without html_no_pre, default value same as " 'wrap' option, (Andy Spencer). Don't use " 'fileencoding' for converted document encoding if " 'buftype' indicates a special buffer which isn't " written. -" 7.3_v8 (85c5a72551e2): Add html_expand_tabs option to allow leaving tab +" 7.3_v8 (Vim 7.3.0100): Add html_expand_tabs option to allow leaving tab " characters in generated output (Andy Spencer). " Escape text that looks like a modeline so Vim " doesn't use anything in the converted HTML as a " modeline. Bugfixes: Fix folding when a fold starts " before the conversion range. Remove fold column when " there are no folds. -" 7.3_v7 (840c3cadb842): see betas released on vim_dev below: +" 7.3_v7 (Vim 7-3-0063): see betas released on vim_dev below: " 7.3_v7b3: Fixed bug, convert Unicode to UTF-8 all the way. " 7.3_v7b2: Remove automatic detection of encodings that are not " supported by all major browsers according to @@ -147,23 +151,22 @@ let g:loaded_2html_plugin = 'vim7.4_v1' " charset, and make sure the 'fenc' of the generated " file matches its indicated charset. Add charsets for " all of Vim's natively supported encodings. -" 7.3_v6 (0d3f0e3d289b): Really fix bug with 'nowrapscan', 'magic' and other +" 7.3_v6 (Vim 7.3.0000): Really fix bug with 'nowrapscan', 'magic' and other " user settings interfering with diff mode generation, " trailing whitespace (e.g. line number column) when " using html_no_pre, and bugs when using " html_hover_unfold. " 7.3_v5 ( unreleased ): Fix bug with 'nowrapscan' and also with out-of-sync " folds in diff mode when first line was folded. -" 7.3_v4 (7e008c174cc3): Bugfixes, especially for xhtml markup, and diff mode -" 7.3_v3 (a29075150aee): Refactor option handling and make html_use_css +" 7.3_v4 (Vim 7.3.0000): Bugfixes, especially for xhtml markup, and diff mode +" 7.3_v3 (Vim 7.3.0000): Refactor option handling and make html_use_css " default to true when not set to anything. Use strict " doctypes where possible. Rename use_xhtml option to " html_use_xhtml for consistency. Use .xhtml extension " when using this option. Add meta tag for settings. -" 7.3_v2 (80229a724a11): Fix syntax highlighting in diff mode to use both the +" 7.3_v2 (Vim 7.3.0000): Fix syntax highlighting in diff mode to use both the " diff colors and the normal syntax colors -" 7.3_v1 (e7751177126b): Add conceal support and meta tags in output -" Pre-v1 baseline: Mercurial changeset 3c9324c0800e +" 7.3_v1 (Vim 7.3.0000): Add conceal support and meta tags in output "}}} "}}} diff --git a/runtime/synmenu.vim b/runtime/synmenu.vim index 2db72a2b60..76f60131f2 100644 --- a/runtime/synmenu.vim +++ b/runtime/synmenu.vim @@ -161,6 +161,7 @@ an 50.30.290 &Syntax.DE.Doxygen.C\ with\ doxygen :cal SetSyn("c.doxygen")<CR> an 50.30.300 &Syntax.DE.Doxygen.C++\ with\ doxygen :cal SetSyn("cpp.doxygen")<CR> an 50.30.310 &Syntax.DE.Doxygen.IDL\ with\ doxygen :cal SetSyn("idl.doxygen")<CR> an 50.30.320 &Syntax.DE.Doxygen.Java\ with\ doxygen :cal SetSyn("java.doxygen")<CR> +an 50.30.320 &Syntax.DE.Doxygen.DataScript\ with\ doxygen :cal SetSyn("datascript.doxygen")<CR> an 50.30.330 &Syntax.DE.Dracula :cal SetSyn("dracula")<CR> an 50.30.340 &Syntax.DE.DSSSL :cal SetSyn("dsl")<CR> an 50.30.350 &Syntax.DE.DTD :cal SetSyn("dtd")<CR> diff --git a/runtime/syntax/2html.vim b/runtime/syntax/2html.vim index 187b1be1b0..ddc7819be2 100644 --- a/runtime/syntax/2html.vim +++ b/runtime/syntax/2html.vim @@ -1,6 +1,6 @@ " Vim syntax support file " Maintainer: Ben Fritz <fritzophrenic@gmail.com> -" Last Change: 2013 Jul 08 +" Last Change: 2015 Sep 08 " " Additional contributors: " @@ -26,7 +26,11 @@ let s:end=line('$') " Font if exists("g:html_font") - let s:htmlfont = "'". g:html_font . "', monospace" + if type(g:html_font) == type([]) + let s:htmlfont = "'". join(g:html_font,"','") . "', monospace" + else + let s:htmlfont = "'". g:html_font . "', monospace" + endif else let s:htmlfont = "monospace" endif diff --git a/runtime/syntax/bzl.vim b/runtime/syntax/bzl.vim new file mode 100644 index 0000000000..b0ee9454ff --- /dev/null +++ b/runtime/syntax/bzl.vim @@ -0,0 +1,16 @@ +" Vim syntax file +" Language: Bazel (http://bazel.io) +" Maintainer: David Barnett (https://github.com/google/vim-ft-bzl) +" Last Change: 2015 Aug 11 + +if exists('b:current_syntax') + finish +endif + + +runtime! syntax/python.vim + +let b:current_syntax = 'bzl' + +syn region bzlRule start='^\w\+($' end='^)\n*' transparent fold +syn region bzlList start='\[' end='\]' transparent fold diff --git a/runtime/syntax/cmake.vim b/runtime/syntax/cmake.vim index 8e54d511e0..68b2198de7 100644 --- a/runtime/syntax/cmake.vim +++ b/runtime/syntax/cmake.vim @@ -2,10 +2,10 @@ " Program: CMake - Cross-Platform Makefile Generator " Module: $RCSfile: cmake-syntax.vim,v $ " Language: CMake -" Author: Andy Cedilnik <andy.cedilnik@kitware.com> " Maintainer: Karthik Krishnan <karthik.krishnan@kitware.com> -" Last Change: 2012 Jun 01 -" (Dominique Pelle added @Spell) +" Former Maintainer: Dimitri Merejkowsky <d.merej@gmail.com> +" Author: Andy Cedilnik <andy.cedilnik@kitware.com> +" Last Change: 2015 Sep 29 " Version: $Revision: 1.10 $ " " Licence: The CMake license applies to this file. See @@ -31,9 +31,9 @@ syn region cmakeVariableValue start=/\${/ end=/}/ \ contained oneline contains=CONTAINED,cmakeTodo syn region cmakeEnvironment start=/\$ENV{/ end=/}/ \ contained oneline contains=CONTAINED,cmakeTodo -syn region cmakeString start=/"/ end=/"/ +syn region cmakeString start=/"/ end=/"/ \ contains=CONTAINED,cmakeTodo,cmakeOperators -syn region cmakeArguments start=/(/ end=/)/ +syn region cmakeArguments start=/(/ end=/)/ \ contains=ALLBUT,cmakeArguments,cmakeTodo syn keyword cmakeSystemVariables \ WIN32 UNIX APPLE CYGWIN BORLAND MINGW MSVC MSVC_IDE MSVC60 MSVC70 MSVC71 MSVC80 MSVC90 @@ -44,11 +44,11 @@ syn keyword cmakeDeprecated ABSTRACT_FILES BUILD_NAME SOURCE_FILES SOURCE_FILES_ \ nextgroup=cmakeArguments " The keywords are generated as: cmake --help-command-list | tr "\n" " " -syn keyword cmakeStatement +syn keyword cmakeStatement \ ADD_CUSTOM_COMMAND ADD_CUSTOM_TARGET ADD_DEFINITIONS ADD_DEPENDENCIES ADD_EXECUTABLE ADD_LIBRARY ADD_SUBDIRECTORY ADD_TEST AUX_SOURCE_DIRECTORY BUILD_COMMAND BUILD_NAME CMAKE_MINIMUM_REQUIRED CONFIGURE_FILE CREATE_TEST_SOURCELIST ELSE ELSEIF ENABLE_LANGUAGE ENABLE_TESTING ENDFOREACH ENDFUNCTION ENDIF ENDMACRO ENDWHILE EXEC_PROGRAM EXECUTE_PROCESS EXPORT_LIBRARY_DEPENDENCIES FILE FIND_FILE FIND_LIBRARY FIND_PACKAGE FIND_PATH FIND_PROGRAM FLTK_WRAP_UI FOREACH FUNCTION GET_CMAKE_PROPERTY GET_DIRECTORY_PROPERTY GET_FILENAME_COMPONENT GET_SOURCE_FILE_PROPERTY GET_TARGET_PROPERTY GET_TEST_PROPERTY IF INCLUDE INCLUDE_DIRECTORIES INCLUDE_EXTERNAL_MSPROJECT INCLUDE_REGULAR_EXPRESSION INSTALL INSTALL_FILES INSTALL_PROGRAMS INSTALL_TARGETS LINK_DIRECTORIES LINK_LIBRARIES LIST LOAD_CACHE LOAD_COMMAND MACRO MAKE_DIRECTORY MARK_AS_ADVANCED MATH MESSAGE OPTION OUTPUT_REQUIRED_FILES PROJECT QT_WRAP_CPP QT_WRAP_UI REMOVE REMOVE_DEFINITIONS SEPARATE_ARGUMENTS SET SET_DIRECTORY_PROPERTIES SET_SOURCE_FILES_PROPERTIES SET_TARGET_PROPERTIES SET_TESTS_PROPERTIES SITE_NAME SOURCE_GROUP STRING SUBDIR_DEPENDS SUBDIRS TARGET_LINK_LIBRARIES TRY_COMPILE TRY_RUN UNSET USE_MANGLED_MESA UTILITY_SOURCE VARIABLE_REQUIRES VTK_MAKE_INSTANTIATOR VTK_WRAP_JAVA VTK_WRAP_PYTHON VTK_WRAP_TCL WHILE WRITE_FILE \ nextgroup=cmakeArguments -syn keyword cmakeTodo - \ TODO FIXME XXX +syn keyword cmakeTodo + \ TODO FIXME XXX \ contained " Define the default highlighting. diff --git a/runtime/syntax/cpp.vim b/runtime/syntax/cpp.vim index 526ecbcd53..135b8c9244 100644 --- a/runtime/syntax/cpp.vim +++ b/runtime/syntax/cpp.vim @@ -2,7 +2,7 @@ " Language: C++ " Current Maintainer: vim-jp (https://github.com/vim-jp/vim-cpp) " Previous Maintainer: Ken Shan <ccshan@post.harvard.edu> -" Last Change: 2015 Mar 1 +" Last Change: 2015 May 04 " For version 5.x: Clear all syntax items " For version 6.x: Quit when a syntax file was already loaded @@ -46,7 +46,7 @@ if !exists("cpp_no_cpp11") syn keyword cppConstant ATOMIC_WCHAR_T_LOCK_FREE ATOMIC_SHORT_LOCK_FREE syn keyword cppConstant ATOMIC_INT_LOCK_FREE ATOMIC_LONG_LOCK_FREE syn keyword cppConstant ATOMIC_LLONG_LOCK_FREE ATOMIC_POINTER_LOCK_FREE - syn region cppRawString matchgroup=cppRawDelimiter start=+\%(u8\|[uLU]\)\=R"\z([[:alnum:]_{}[\]#<>%:;.?*\+\-/\^&|~!=,"']\{,16}\)(+ end=+)\z1"+ contains=@Spell + syn region cppRawString matchgroup=cppRawStringDelimiter start=+\%(u8\|[uLU]\)\=R"\z([[:alnum:]_{}[\]#<>%:;.?*\+\-/\^&|~!=,"']\{,16}\)(+ end=+)\z1"+ contains=@Spell endif " The minimum and maximum operators in GNU C++ diff --git a/runtime/syntax/datascript.vim b/runtime/syntax/datascript.vim index 2b4ec513b4..a983b8e34c 100644 --- a/runtime/syntax/datascript.vim +++ b/runtime/syntax/datascript.vim @@ -1,11 +1,12 @@ " Vim syntax file -" Language: Datascript +" Language: DataScript " Maintainer: Dominique Pelle <dominique.pelle@gmail.com> -" Last Change: 2014 Feb 26 +" Last Change: 2015 Jul 30 " " DataScript is a formal language for modelling binary datatypes, " bitstreams or file formats. For more information, see: -" http://datascript.berlios.de/DataScriptLanguageOverview.html +" +" http://dstools.sourceforge.net/DataScriptLanguageOverview.html if version < 600 syntax clear @@ -19,6 +20,8 @@ syn keyword dsPackage import package syn keyword dsType bit bool string syn keyword dsType int int8 int16 int32 int64 syn keyword dsType uint8 uint16 uint32 uint64 +syn keyword dsType varint16 varint32 varint64 +syn keyword dsType varuint16 varuint32 varuint64 syn keyword dsType leint16 leint32 leint64 syn keyword dsType leuint16 leuint32 leuint64 syn keyword dsEndian little big @@ -32,7 +35,8 @@ syn keyword dsOperator sizeof bitsizeof lengthof is sum forall in syn keyword dsStorageClass const syn keyword dsTodo contained TODO FIXME XXX syn keyword dsSql sql sql_table sql_database sql_pragma sql_index -syn keyword dsSql sql_integer sql_metadata sql_key foreign_key +syn keyword dsSql sql_integer sql_metadata sql_key sql_virtual +syn keyword dsSql using reference_key foreign_key to " dsCommentGroup allows adding matches for special things in comments. syn cluster dsCommentGroup contains=dsTodo @@ -61,6 +65,8 @@ syn region dsComment syn region dsString \ start=+L\="+ skip=+\\\\\|\\"+ end=+"+ contains=@Spell +syn sync ccomment dsComment + " Define the default highlighting. hi def link dsType Type hi def link dsEndian StorageClass diff --git a/runtime/syntax/dnsmasq.vim b/runtime/syntax/dnsmasq.vim index 2a31aed77f..9fa32077b6 100644 --- a/runtime/syntax/dnsmasq.vim +++ b/runtime/syntax/dnsmasq.vim @@ -4,8 +4,8 @@ " :3s+-foo++g " Description: highlight dnsmasq configuration files " File: runtime/syntax/dnsmasq.vim -" Version: 2.70 -" Last Change: 2014 Apr 30 +" Version: 2.76 +" Last Change: 2015 Sep 27 " Modeline: vim: ts=8:sw=2:sts=2: " " License: VIM License @@ -131,10 +131,12 @@ syn match DnsmasqKeyword "^\s*dhcp-sequential-ip\>" syn match DnsmasqKeyword "^\s*dhcp-subscrid\>" syn match DnsmasqKeyword "^\s*dhcp-userclass\>" syn match DnsmasqKeyword "^\s*dhcp-vendorclass\>" +syn match DnsmasqKeyword "^\s*dhcp-hostsdir\>" syn match DnsmasqKeyword "^\s*dns-rr\>" syn match DnsmasqKeyword "^\s*dnssec\>" syn match DnsmasqKeyword "^\s*dnssec-check-unsigned\>" syn match DnsmasqKeyword "^\s*dnssec-no-timecheck\>" +syn match DnsmasqKeyword "^\s*dnssec-timestamp\>" syn match DnsmasqKeyword "^\s*dns-forward-max\>" syn match DnsmasqKeyword "^\s*domain\>" syn match DnsmasqKeyword "^\s*domain-needed\>" @@ -150,6 +152,7 @@ syn match DnsmasqKeyword "^\s*host-record\>" syn match DnsmasqKeyword "^\s*interface\>" syn match DnsmasqKeyword "^\s*interface-name\>" syn match DnsmasqKeyword "^\s*ipset\>" +syn match DnsmasqKeyword "^\s*ignore-address\>" syn match DnsmasqKeyword "^\s*keep-in-foreground\>" syn match DnsmasqKeyword "^\s*leasefile-ro\>" syn match DnsmasqKeyword "^\s*listen-address\>" @@ -164,6 +167,7 @@ syn match DnsmasqKeyword "^\s*log-facility\>" syn match DnsmasqKeyword "^\s*log-queries\>" syn match DnsmasqKeyword "^\s*max-ttl\>" syn match DnsmasqKeyword "^\s*max-cache-ttl\>" +syn match DnsmasqKeyword "^\s*min-cache-ttl\>" syn match DnsmasqKeyword "^\s*min-port\>" syn match DnsmasqKeyword "^\s*mx-host\>" syn match DnsmasqKeyword "^\s*mx-target\>" @@ -204,6 +208,7 @@ syn match DnsmasqKeyword "^\s*test\>" syn match DnsmasqKeyword "^\s*tftp-max\>" syn match DnsmasqKeyword "^\s*tftp-lowercase\>" syn match DnsmasqKeyword "^\s*tftp-no-blocksize\>" +syn match DnsmasqKeyword "^\s*tftp-no-fail\>" syn match DnsmasqKeyword "^\s*tftp-port-range\>" syn match DnsmasqKeyword "^\s*tftp-root\>" syn match DnsmasqKeyword "^\s*tftp-secure\>" diff --git a/runtime/syntax/gnuplot.vim b/runtime/syntax/gnuplot.vim index 03d813c99f..d85932d401 100644 --- a/runtime/syntax/gnuplot.vim +++ b/runtime/syntax/gnuplot.vim @@ -1,8 +1,9 @@ " Vim syntax file " Language: gnuplot 4.7.0 -" Maintainer: Andrew Rasmussen andyras@users.sourceforge.net +" Maintainer: Josh Wainwright <wainwright DOT ja AT gmail DOT com> +" Last Maintainer: Andrew Rasmussen andyras@users.sourceforge.net " Original Maintainer: John Hoelzel johnh51@users.sourceforge.net -" Last Change: 2014-02-24 +" Last Change: 2015-08-25 " Filenames: *.gnu *.plt *.gpi *.gih *.gp *.gnuplot scripts: #!*gnuplot " URL: http://www.vim.org/scripts/script.php?script_id=4873 " Original URL: http://johnh51.get.to/vim/syntax/gnuplot.vim @@ -364,18 +365,18 @@ syn keyword gnuplotKeyword samples " set size syn keyword gnuplotKeyword size square nosquare ratio noratio " set style -syn keyword gnuplotKeyword style function data noborder rectangle arrow -syn keyword gnuplotKeyword default nohead head heads size filled empty -syn keyword gnuplotKeyword nofilled front back boxplot range fraction -syn keyword gnuplotKeyword outliers nooutliers pointtype candlesticks -syn keyword gnuplotKeyword separation labels off auto x x2 sorted unsorted -syn keyword gnuplotKeyword fill empty transparent solid pattern border -syn keyword gnuplotKeyword increment userstyles financebars line default -syn keyword gnuplotKeyword linetype lt linecolor lc linewidth lw pointtype -syn keyword gnuplotKeyword pt pointsize ps pointinterval pi palette circle -syn keyword gnuplotKeyword radius graph screen wedge nowedge ellipse size -syn keyword gnuplotKeyword units xx xy yy histogram line textbox opaque -syn keyword gnuplotKeyword border noborder +syn keyword gnuplotKeyword style arrow auto back border boxplot +syn keyword gnuplotKeyword candlesticks circle clustered columnstacked data +syn keyword gnuplotKeyword default ellipse empty fill[ed] financebars +syn keyword gnuplotKeyword fraction front function gap graph head[s] +syn keyword gnuplotKeyword histogram increment labels lc line linecolor +syn keyword gnuplotKeyword linetype linewidth lt lw noborder nofilled +syn keyword gnuplotKeyword nohead nooutliers nowedge off opaque outliers +syn keyword gnuplotKeyword palette pattern pi pointinterval pointsize +syn keyword gnuplotKeyword pointtype ps pt radius range rectangle +syn keyword gnuplotKeyword rowstacked screen separation size solid sorted +syn keyword gnuplotKeyword textbox transparent units unsorted userstyles +syn keyword gnuplotKeyword wedge x x2 xx xy yy " set surface syn keyword gnuplotKeyword surface implicit explicit " set table @@ -496,8 +497,8 @@ syn keyword gnuplotTodo contained TODO FIXME XXX syn keyword gnuplotStatement cd call clear evaluate exit fit help history syn keyword gnuplotStatement load lower pause plot p print pwd quit raise syn keyword gnuplotStatement refresh replot rep reread reset save set show -syn keyword gnuplotStatement shell splot spstats system test undefine unset -syn keyword gnuplotStatement update +syn keyword gnuplotStatement shell splot spstats stats system test undefine +syn keyword gnuplotStatement unset update " ---- Define the default highlighting ---- " " For version 5.7 and earlier: only when not done already diff --git a/runtime/syntax/groovy.vim b/runtime/syntax/groovy.vim index 65dbf17728..42fcf4abac 100644 --- a/runtime/syntax/groovy.vim +++ b/runtime/syntax/groovy.vim @@ -2,9 +2,9 @@ " Language: Groovy " Original Author: Alessio Pace <billy.corgan@tiscali.it> " Maintainer: Tobias Rapp <yahuxo@gmx.de> -" Version: 0.1.13 +" Version: 0.1.14 " URL: http://www.vim.org/scripts/script.php?script_id=945 -" Last Change: 2015 Apr 13 +" Last Change: 2015 Apr 21 " THE ORIGINAL AUTHOR'S NOTES: " diff --git a/runtime/syntax/python.vim b/runtime/syntax/python.vim index c608aeedeb..78d35e4c15 100644 --- a/runtime/syntax/python.vim +++ b/runtime/syntax/python.vim @@ -1,7 +1,7 @@ " Vim syntax file " Language: Python " Maintainer: Zvezdan Petkovic <zpetkovic@acm.org> -" Last Change: 2015 Jun 19 +" Last Change: 2015 Sep 15 " Credits: Neil Schemenauer <nas@python.ca> " Dmitry Vasiliev " @@ -51,24 +51,26 @@ set cpo&vim " Keep Python keywords in alphabetical order inside groups for easy " comparison with the table in the 'Python Language Reference' -" http://docs.python.org/reference/lexical_analysis.html#keywords. +" https://docs.python.org/2/reference/lexical_analysis.html#keywords, +" https://docs.python.org/3/reference/lexical_analysis.html#keywords. " Groups are in the order presented in NAMING CONVENTIONS in syntax.txt. " Exceptions come last at the end of each group (class and def below). " " Keywords 'with' and 'as' are new in Python 2.6 " (use 'from __future__ import with_statement' in Python 2.5). " -" Some compromises had to be made to support both Python 3.0 and 2.6. -" We include Python 3.0 features, but when a definition is duplicated, +" Some compromises had to be made to support both Python 3 and 2. +" We include Python 3 features, but when a definition is duplicated, " the last definition takes precedence. " -" - 'False', 'None', and 'True' are keywords in Python 3.0 but they are -" built-ins in 2.6 and will be highlighted as built-ins below. -" - 'exec' is a built-in in Python 3.0 and will be highlighted as +" - 'False', 'None', and 'True' are keywords in Python 3 but they are +" built-ins in 2 and will be highlighted as built-ins below. +" - 'exec' is a built-in in Python 3 and will be highlighted as " built-in below. -" - 'nonlocal' is a keyword in Python 3.0 and will be highlighted. -" - 'print' is a built-in in Python 3.0 and will be highlighted as -" built-in below (use 'from __future__ import print_function' in 2.6) +" - 'nonlocal' is a keyword in Python 3 and will be highlighted. +" - 'print' is a built-in in Python 3 and will be highlighted as +" built-in below (use 'from __future__ import print_function' in 2) +" - async and await were added in Python 3.5 and are soft keywords. " syn keyword pythonStatement False, None, True syn keyword pythonStatement as assert break continue del exec global @@ -79,6 +81,7 @@ syn keyword pythonRepeat for while syn keyword pythonOperator and in is not or syn keyword pythonException except finally raise try syn keyword pythonInclude from import +syn keyword pythonAsync async await " Decorators (new in Python 2.4) syn match pythonDecorator "@" display nextgroup=pythonFunction skipwhite @@ -147,7 +150,8 @@ endif " - 08e0 or 08j are highlighted, " " and so on, as specified in the 'Python Language Reference'. -" http://docs.python.org/reference/lexical_analysis.html#numeric-literals +" https://docs.python.org/2/reference/lexical_analysis.html#numeric-literals +" https://docs.python.org/3/reference/lexical_analysis.html#numeric-literals if !exists("python_no_number_highlight") " numbers (including longs and complex) syn match pythonNumber "\<0[oO]\=\o\+[Ll]\=\>" @@ -159,54 +163,58 @@ if !exists("python_no_number_highlight") syn match pythonNumber \ "\<\d\+\.\%([eE][+-]\=\d\+\)\=[jJ]\=\%(\W\|$\)\@=" syn match pythonNumber - \ "\%(^\|\W\)\@<=\d*\.\d\+\%([eE][+-]\=\d\+\)\=[jJ]\=\>" + \ "\%(^\|\W\)\zs\d*\.\d\+\%([eE][+-]\=\d\+\)\=[jJ]\=\>" endif " Group the built-ins in the order in the 'Python Library Reference' for " easier comparison. -" http://docs.python.org/library/constants.html -" http://docs.python.org/library/functions.html -" http://docs.python.org/library/functions.html#non-essential-built-in-functions +" https://docs.python.org/2/library/constants.html +" https://docs.python.org/3/library/constants.html +" http://docs.python.org/2/library/functions.html +" http://docs.python.org/3/library/functions.html +" http://docs.python.org/2/library/functions.html#non-essential-built-in-functions +" http://docs.python.org/3/library/functions.html#non-essential-built-in-functions " Python built-in functions are in alphabetical order. if !exists("python_no_builtin_highlight") " built-in constants - " 'False', 'True', and 'None' are also reserved words in Python 3.0 + " 'False', 'True', and 'None' are also reserved words in Python 3 syn keyword pythonBuiltin False True None syn keyword pythonBuiltin NotImplemented Ellipsis __debug__ " built-in functions - syn keyword pythonBuiltin abs all any bin bool chr classmethod - syn keyword pythonBuiltin compile complex delattr dict dir divmod - syn keyword pythonBuiltin enumerate eval filter float format + syn keyword pythonBuiltin abs all any bin bool bytearray callable chr + syn keyword pythonBuiltin classmethod compile complex delattr dict dir + syn keyword pythonBuiltin divmod enumerate eval filter float format syn keyword pythonBuiltin frozenset getattr globals hasattr hash syn keyword pythonBuiltin help hex id input int isinstance syn keyword pythonBuiltin issubclass iter len list locals map max - syn keyword pythonBuiltin min next object oct open ord pow print - syn keyword pythonBuiltin property range repr reversed round set + syn keyword pythonBuiltin memoryview min next object oct open ord pow + syn keyword pythonBuiltin print property range repr reversed round set syn keyword pythonBuiltin setattr slice sorted staticmethod str syn keyword pythonBuiltin sum super tuple type vars zip __import__ - " Python 2.6 only - syn keyword pythonBuiltin basestring callable cmp execfile file + " Python 2 only + syn keyword pythonBuiltin basestring cmp execfile file syn keyword pythonBuiltin long raw_input reduce reload unichr syn keyword pythonBuiltin unicode xrange - " Python 3.0 only - syn keyword pythonBuiltin ascii bytearray bytes exec memoryview - " non-essential built-in functions; Python 2.6 only + " Python 3 only + syn keyword pythonBuiltin ascii bytes exec + " non-essential built-in functions; Python 2 only syn keyword pythonBuiltin apply buffer coerce intern endif " From the 'Python Library Reference' class hierarchy at the bottom. -" http://docs.python.org/library/exceptions.html +" http://docs.python.org/2/library/exceptions.html +" http://docs.python.org/3/library/exceptions.html if !exists("python_no_exception_highlight") - " builtin base exceptions (only used as base classes for other exceptions) + " builtin base exceptions (used mostly as base classes for other exceptions) syn keyword pythonExceptions BaseException Exception - syn keyword pythonExceptions ArithmeticError EnvironmentError + syn keyword pythonExceptions ArithmeticError BufferError syn keyword pythonExceptions LookupError - " builtin base exception removed in Python 3.0 - syn keyword pythonExceptions StandardError + " builtin base exceptions removed in Python 3 + syn keyword pythonExceptions EnvironmentError StandardError " builtin exceptions (actually raised) - syn keyword pythonExceptions AssertionError AttributeError BufferError + syn keyword pythonExceptions AssertionError AttributeError syn keyword pythonExceptions EOFError FloatingPointError GeneratorExit - syn keyword pythonExceptions IOError ImportError IndentationError + syn keyword pythonExceptions ImportError IndentationError syn keyword pythonExceptions IndexError KeyError KeyboardInterrupt syn keyword pythonExceptions MemoryError NameError NotImplementedError syn keyword pythonExceptions OSError OverflowError ReferenceError @@ -214,13 +222,27 @@ if !exists("python_no_exception_highlight") syn keyword pythonExceptions SystemError SystemExit TabError TypeError syn keyword pythonExceptions UnboundLocalError UnicodeError syn keyword pythonExceptions UnicodeDecodeError UnicodeEncodeError - syn keyword pythonExceptions UnicodeTranslateError ValueError VMSError - syn keyword pythonExceptions WindowsError ZeroDivisionError + syn keyword pythonExceptions UnicodeTranslateError ValueError + syn keyword pythonExceptions ZeroDivisionError + " builtin OS exceptions in Python 3 + syn keyword pythonExceptions BlockingIOError BrokenPipeError + syn keyword pythonExceptions ChildProcessError ConnectionAbortedError + syn keyword pythonExceptions ConnectionError ConnectionRefusedError + syn keyword pythonExceptions ConnectionResetError FileExistsError + syn keyword pythonExceptions FileNotFoundError InterruptedError + syn keyword pythonExceptions IsADirectoryError NotADirectoryError + syn keyword pythonExceptions PermissionError ProcessLookupError + syn keyword pythonExceptions RecursionError StopAsyncIteration + syn keyword pythonExceptions TimeoutError + " builtin exceptions deprecated/removed in Python 3 + syn keyword pythonExceptions IOError VMSError WindowsError " builtin warnings syn keyword pythonExceptions BytesWarning DeprecationWarning FutureWarning syn keyword pythonExceptions ImportWarning PendingDeprecationWarning syn keyword pythonExceptions RuntimeWarning SyntaxWarning UnicodeWarning syn keyword pythonExceptions UserWarning Warning + " builtin warnings in Python 3 + syn keyword pythonExceptions ResourceWarning endif if exists("python_space_error_highlight") @@ -267,6 +289,7 @@ if version >= 508 || !exists("did_python_syn_inits") HiLink pythonOperator Operator HiLink pythonException Exception HiLink pythonInclude Include + HiLink pythonAsync Statement HiLink pythonDecorator Define HiLink pythonFunction Function HiLink pythonComment Comment diff --git a/runtime/syntax/rst.vim b/runtime/syntax/rst.vim index c1f25699e7..8b17104be4 100644 --- a/runtime/syntax/rst.vim +++ b/runtime/syntax/rst.vim @@ -2,7 +2,7 @@ " Language: reStructuredText documentation format " Maintainer: Marshall Ward <marshall.ward@gmail.com> " Previous Maintainer: Nikolai Weibull <now@bitwi.se> -" Latest Revision: 2014-10-03 +" Latest Revision: 2015-09-07 if exists("b:current_syntax") finish @@ -81,7 +81,7 @@ syn region rstHyperlinkTarget matchgroup=rstDirective execute 'syn region rstExDirective contained matchgroup=rstDirective' . \ ' start=+' . s:ReferenceName . '::\_s+' . \ ' skip=+^$+' . - \ ' end=+^\s\@!+ contains=@rstCruft' + \ ' end=+^\s\@!+ contains=@rstCruft,rstLiteralBlock' execute 'syn match rstSubstitutionDefinition contained' . \ ' /|' . s:ReferenceName . '|\_s\+/ nextgroup=@rstDirectives' diff --git a/runtime/syntax/screen.vim b/runtime/syntax/screen.vim index 71b3d3efba..d576d29b7a 100644 --- a/runtime/syntax/screen.vim +++ b/runtime/syntax/screen.vim @@ -1,7 +1,8 @@ " Vim syntax file -" Language: screen(1) configuration file -" Maintainer: Nikolai Weibull <now@bitwi.se> -" Latest Revision: 2010-01-03 +" Language: screen(1) configuration file +" Maintainer: Dmitri Vereshchagin <dmitri.vereshchagin@gmail.com> +" Previous Maintainer: Nikolai Weibull <now@bitwi.se> +" Latest Revision: 2015-09-24 if exists("b:current_syntax") finish @@ -76,12 +77,16 @@ syn keyword screenCommands \ break \ breaktype \ bufferfile + \ bumpleft + \ bumpright \ c1 \ caption \ chacl \ charset \ chdir + \ cjkwidth \ clear + \ collapse \ colon \ command \ compacthist @@ -104,6 +109,7 @@ syn keyword screenCommands \ deflogin \ defmode \ defmonitor + \ defmousetrack \ defnonblock \ defobuflimit \ defscrollback @@ -113,6 +119,7 @@ syn keyword screenCommands \ defutf8 \ defwrap \ defwritelock + \ defzombie \ detach \ digraph \ dinfo @@ -126,7 +133,9 @@ syn keyword screenCommands \ fit \ flow \ focus + \ focusminsize \ gr + \ group \ hardcopy \ hardcopy_append \ hardcopydir @@ -155,6 +164,7 @@ syn keyword screenCommands \ maxwin \ meta \ monitor + \ mousetrack \ msgminwait \ msgwait \ multiuser @@ -182,6 +192,7 @@ syn keyword screenCommands \ register \ remove \ removebuf + \ rendition \ reset \ resize \ screen @@ -197,6 +208,7 @@ syn keyword screenCommands \ sleep \ slowpaste \ sorendition + \ sort \ source \ split \ startup_message @@ -210,6 +222,7 @@ syn keyword screenCommands \ time \ title \ umask + \ unbindall \ unsetenv \ utf8 \ vbell @@ -228,6 +241,7 @@ syn keyword screenCommands \ xon \ zmodem \ zombie + \ zombie_timeout hi def link screenEscape Special hi def link screenComment Comment diff --git a/runtime/syntax/sh.vim b/runtime/syntax/sh.vim index 4087aff46e..60f23d2d83 100644 --- a/runtime/syntax/sh.vim +++ b/runtime/syntax/sh.vim @@ -2,8 +2,8 @@ " Language: shell (sh) Korn shell (ksh) bash (sh) " Maintainer: Charles E. Campbell <NdrOchipS@PcampbellAfamily.Mbiz> " Previous Maintainer: Lennart Schultz <Lennart.Schultz@ecmwf.int> -" Last Change: May 29, 2015 -" Version: 137 +" Last Change: Oct 09, 2015 +" Version: 139 " URL: http://www.drchip.org/astronaut/vim/index.html#SYNTAX_SH " For options and settings, please use: :help ft-sh-syntax " This file includes many ideas from ?ric Brunet (eric.brunet@ens.fr) @@ -16,14 +16,14 @@ elseif exists("b:current_syntax") finish endif -" AFAICT "." should be considered part of the iskeyword. Using iskeywords in -" syntax is dicey, so the following code permits the user to +" AFAICT "." should be considered part of the iskeyword for ksh. Using iskeywords +" in syntax is dicey, so the following code permits the user to prevent/override " g:sh_isk set to a string : specify iskeyword. " g:sh_noisk exists : don't change iskeyword -" g:sh_noisk does not exist : (default) append "." to iskeyword +" g:sh_noisk does not exist : (default) append "." to iskeyword for kornshell if exists("g:sh_isk") && type(g:sh_isk) == 1 " user specifying iskeyword exe "setl isk=".g:sh_isk -elseif !exists("g:sh_noisk") " optionally prevent appending '.' to iskeyword +elseif !exists("g:sh_noisk") && exists("b:is_kornshell") " append '.' to iskeyword setl isk+=. endif @@ -128,7 +128,7 @@ syn cluster shIdList contains=shCommandSub,shWrapLineOperator,shSetOption,shDere syn cluster shIfList contains=@shLoopList,shDblBrace,shDblParen,shFunctionKey,shFunctionOne,shFunctionTwo syn cluster shLoopList contains=@shCaseList,@shErrorList,shCaseEsac,shConditional,shDblBrace,shExpr,shFor,shForPP,shIf,shOption,shSet,shTest,shTestOpr syn cluster shSubShList contains=@shCommandSubList,shCaseEsac,shColon,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shIf,shRedir,shSetList,shSource,shStatement,shVariable,shCtrlSeq,shOperator -syn cluster shTestList contains=shCharClass,shCommandSub,shComment,shCtrlSeq,shDeref,shDerefSimple,shDoubleQuote,shExDoubleQuote,shExpr,shExSingleQuote,shNumber,shOperator,shSingleQuote,shTest,shTestOpr +syn cluster shTestList contains=shCharClass,shCommandSub,shCtrlSeq,shDeref,shDerefSimple,shDoubleQuote,shExDoubleQuote,shExpr,shExSingleQuote,shNumber,shOperator,shSingleQuote,shTest,shTestOpr " Echo: {{{1 " ==== " This one is needed INSIDE a CommandSub, so that `echo bla` be correct @@ -321,12 +321,11 @@ elseif !exists("g:sh_no_error") endif syn region shSingleQuote matchgroup=shQuote start=+'+ end=+'+ contains=@Spell syn region shDoubleQuote matchgroup=shQuote start=+\%(\%(\\\\\)*\\\)\@<!"+ skip=+\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial,@Spell -syn region shDoubleQuote matchgroup=shQuote start=+"+ skip=+\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial,@Spell syn match shStringSpecial "[^[:print:] \t]" contained syn match shStringSpecial "\%(\\\\\)*\\[\\"'`$()#]" " COMBAK: why is ,shComment on next line??? -syn match shSpecial "[^\\]\zs\%(\\\\\)*\\[\\"'`$()#]" nextgroup=shMoreSpecial,shComment -syn match shSpecial "^\%(\\\\\)*\\[\\"'`$()#]" nextgroup=shComment +syn match shSpecial "[^\\]\zs\%(\\\\\)*\\[\\"'`$()#]" +syn match shSpecial "^\%(\\\\\)*\\[\\"'`$()#]" syn match shMoreSpecial "\%(\\\\\)*\\[\\"'`$()#]" nextgroup=shMoreSpecial contained " Comments: {{{1 @@ -409,27 +408,27 @@ endif if exists("b:is_bash") if s:sh_fold_functions - syn region shFunctionOne fold matchgroup=shFunction start="^\s*\h[-a-zA-Z_0-9]*\s*()\_s*{" end="}" contains=@shFunctionList skipwhite skipnl nextgroup=shFunctionStart,shQuickComment - syn region shFunctionTwo fold matchgroup=shFunction start="\h[-a-zA-Z_0-9]*\s*\%(()\)\=\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shFunctionStart,shQuickComment - syn region shFunctionThree fold matchgroup=shFunction start="^\s*\h[-a-zA-Z_0-9]*\s*()\_s*(" end=")" contains=@shFunctionList skipwhite skipnl nextgroup=shFunctionStart,shQuickComment - syn region shFunctionFour fold matchgroup=shFunction start="\h[-a-zA-Z_0-9]*\s*\%(()\)\=\_s*)" end=")" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shFunctionStart,shQuickComment + syn region shFunctionOne fold matchgroup=shFunction start="^\s*\h[-a-zA-Z_0-9]*\s*()\_s*{" end="}" contains=@shFunctionList skipwhite skipnl nextgroup=shFunctionStart,shQuickComment + syn region shFunctionTwo fold matchgroup=shFunction start="\<[^d][^o]\&\h[-a-zA-Z_0-9]*\s*\%(()\)\=\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shFunctionStart,shQuickComment + syn region shFunctionThree fold matchgroup=shFunction start="^\s*\h[-a-zA-Z_0-9]*\s*()\_s*(" end=")" contains=@shFunctionList skipwhite skipnl nextgroup=shFunctionStart,shQuickComment + syn region shFunctionFour fold matchgroup=shFunction start="\<[^d][^o]\&\h[-a-zA-Z_0-9]*\s*\%(()\)\=\_s*)" end=")" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shFunctionStart,shQuickComment else - syn region shFunctionOne matchgroup=shFunction start="^\s*\h[-a-zA-Z_0-9]*\s*()\_s*{" end="}" contains=@shFunctionList - syn region shFunctionTwo matchgroup=shFunction start="\h[-a-zA-Z_0-9]*\s*\%(()\)\=\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained - syn region shFunctionThree matchgroup=shFunction start="^\s*\h[-a-zA-Z_0-9]*\s*()\_s*(" end=")" contains=@shFunctionList - syn region shFunctionFour matchgroup=shFunction start="\h[-a-zA-Z_0-9]*\s*\%(()\)\=\_s*(" end=")" contains=shFunctionKey,@shFunctionList contained + syn region shFunctionOne matchgroup=shFunction start="^\s*\h[-a-zA-Z_0-9]*\s*()\_s*{" end="}" contains=@shFunctionList + syn region shFunctionTwo matchgroup=shFunction start="\<[^d][^o]\&\h[-a-zA-Z_0-9]*\s*\%(()\)\=\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained + syn region shFunctionThree matchgroup=shFunction start="^\s*\h[-a-zA-Z_0-9]*\s*()\_s*(" end=")" contains=@shFunctionList + syn region shFunctionFour matchgroup=shFunction start="\<[^d][^o]\&\h[-a-zA-Z_0-9]*\s*\%(()\)\=\_s*(" end=")" contains=shFunctionKey,@shFunctionList contained endif else if s:sh_fold_functions - syn region shFunctionOne fold matchgroup=shFunction start="^\s*\h\w*\s*()\_s*{" end="}" contains=@shFunctionList skipwhite skipnl nextgroup=shFunctionStart,shQuickComment - syn region shFunctionTwo fold matchgroup=shFunction start="\h\w*\s*\%(()\)\=\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shFunctionStart,shQuickComment - syn region shFunctionThree fold matchgroup=shFunction start="^\s*\h\w*\s*()\_s*(" end=")" contains=@shFunctionList skipwhite skipnl nextgroup=shFunctionStart,shQuickComment - syn region shFunctionFour fold matchgroup=shFunction start="\h\w*\s*\%(()\)\=\_s*(" end=")" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shFunctionStart,shQuickComment + syn region shFunctionOne fold matchgroup=shFunction start="^\s*\h\w*\s*()\_s*{" end="}" contains=@shFunctionList skipwhite skipnl nextgroup=shFunctionStart,shQuickComment + syn region shFunctionTwo fold matchgroup=shFunction start="\<[^d][^o]\&\h\w*\s*\%(()\)\=\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shFunctionStart,shQuickComment + syn region shFunctionThree fold matchgroup=shFunction start="^\s*\h\w*\s*()\_s*(" end=")" contains=@shFunctionList skipwhite skipnl nextgroup=shFunctionStart,shQuickComment + syn region shFunctionFour fold matchgroup=shFunction start="\<[^d][^o]\&\h\w*\s*\%(()\)\=\_s*(" end=")" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shFunctionStart,shQuickComment else - syn region shFunctionOne matchgroup=shFunction start="^\s*\h\w*\s*()\_s*{" end="}" contains=@shFunctionList - syn region shFunctionTwo matchgroup=shFunction start="\h\w*\s*\%(()\)\=\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained - syn region shFunctionThree matchgroup=shFunction start="^\s*\h\w*\s*()\_s*(" end=")" contains=@shFunctionList - syn region shFunctionFour matchgroup=shFunction start="\h\w*\s*\%(()\)\=\_s*(" end=")" contains=shFunctionKey,@shFunctionList contained + syn region shFunctionOne matchgroup=shFunction start="^\s*\h\w*\s*()\_s*{" end="}" contains=@shFunctionList + syn region shFunctionTwo matchgroup=shFunction start="\<[^d][^o]\&\h\w*\s*\%(()\)\=\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained + syn region shFunctionThree matchgroup=shFunction start="^\s*\h\w*\s*()\_s*(" end=")" contains=@shFunctionList + syn region shFunctionFour matchgroup=shFunction start="\<[^d][^o]\&\h\w*\s*\%(()\)\=\_s*(" end=")" contains=shFunctionKey,@shFunctionList contained endif endif diff --git a/runtime/syntax/synload.vim b/runtime/syntax/synload.vim index 48b5956b3c..6183f33a59 100644 --- a/runtime/syntax/synload.vim +++ b/runtime/syntax/synload.vim @@ -60,8 +60,8 @@ fun! s:SynSet() endfun -" Handle adding doxygen to other languages (C, C++, C#, IDL) -au Syntax c,cpp,cs,idl,php +" Handle adding doxygen to other languages (C, C++, C#, IDL, java, php, DataScript) +au Syntax c,cpp,cs,idl,java,php,datascript \ if (exists('b:load_doxygen_syntax') && b:load_doxygen_syntax) \ || (exists('g:load_doxygen_syntax') && g:load_doxygen_syntax) \ | runtime! syntax/doxygen.vim diff --git a/runtime/syntax/systemd.vim b/runtime/syntax/systemd.vim new file mode 100644 index 0000000000..5dfba74408 --- /dev/null +++ b/runtime/syntax/systemd.vim @@ -0,0 +1,8 @@ +" Vim syntax file +" Language: systemd.unit(5) + +if !exists('b:current_syntax') + " Looks a lot like dosini files. + runtime! syntax/dosini.vim + let b:current_syntax = 'systemd' +endif diff --git a/runtime/syntax/teraterm.vim b/runtime/syntax/teraterm.vim new file mode 100644 index 0000000000..521331d8ce --- /dev/null +++ b/runtime/syntax/teraterm.vim @@ -0,0 +1,139 @@ +" Vim syntax file +" Language: Tera Term Language (TTL) +" Based on Tera Term Version 4.86 +" Maintainer: Ken Takata +" URL: https://github.com/k-takata/vim-teraterm +" Last Change: 2015 Jun 24 +" Filenames: *.ttl +" License: VIM License + +if exists("b:current_syntax") + finish +endif + +let s:save_cpo = &cpo +set cpo&vim + +syn case ignore + +syn region ttlComment start=";" end="$" contains=@Spell +syn region ttlComment start="/\*" end="\*/" contains=@Spell +syn region ttlFirstComment start="/\*" end="\*/" contained contains=@Spell + \ nextgroup=ttlStatement,ttlFirstComment + +syn match ttlCharacter "#\%(\d\+\|\$\x\+\)\>" +syn match ttlNumber "\%(\<\d\+\|\$\x\+\)\>" +syn match ttlString "'[^']*'" contains=@Spell +syn match ttlString '"[^"]*"' contains=@Spell +syn cluster ttlConstant contains=ttlCharacter,ttlNumber,ttlString + +syn match ttlLabel ":\s*\w\{1,32}\>" + +syn keyword ttlOperator and or xor not + +syn match ttlVar "\<groupmatchstr\d\>" +syn match ttlVar "\<param\d\>" +syn keyword ttlVar inputstr matchstr paramcnt result timeout mtimeout + + +syn match ttlLine nextgroup=ttlStatement "^" +syn match ttlStatement contained "\s*" + \ nextgroup=ttlIf,ttlElseIf,ttlConditional,ttlRepeat, + \ ttlFirstComment,ttlComment,ttlLabel,@ttlCommand + +syn cluster ttlCommand contains=ttlControlCommand,ttlCommunicationCommand, + \ ttlStringCommand,ttlFileCommand,ttlPasswordCommand, + \ ttlMiscCommand + + +syn keyword ttlIf contained nextgroup=ttlIfExpression if +syn keyword ttlElseIf contained nextgroup=ttlElseIfExpression elseif + +syn match ttlIfExpression contained "\s.*" + \ contains=@ttlConstant,ttlVar,ttlOperator,ttlComment,ttlThen, + \ @ttlCommand +syn match ttlElseIfExpression contained "\s.*" + \ contains=@ttlConstant,ttlVar,ttlOperator,ttlComment,ttlThen + +syn keyword ttlThen contained then +syn keyword ttlConditional contained else endif + +syn keyword ttlRepeat contained for next until enduntil while endwhile +syn match ttlRepeat contained + \ "\<\%(do\|loop\)\%(\s\+\%(while\|until\)\)\?\>" +syn keyword ttlControlCommand contained + \ break call continue end execcmnd exit goto include + \ mpause pause return + + +syn keyword ttlCommunicationCommand contained + \ bplusrecv bplussend callmenu changedir clearscreen + \ closett connect cygconnect disconnect dispstr + \ enablekeyb flushrecv gethostname getmodemstatus + \ gettitle kmtfinish kmtget kmtrecv kmtsend loadkeymap + \ logautoclosemode logclose loginfo logopen logpause + \ logrotate logstart logwrite quickvanrecv + \ quickvansend recvln restoresetup scprecv scpsend + \ send sendbreak sendbroadcast sendfile sendkcode + \ sendln sendlnbroadcast sendmulticast setbaud + \ setdebug setdtr setecho setmulticastname setrts + \ setsync settitle showtt testlink unlink wait + \ wait4all waitevent waitln waitn waitrecv waitregex + \ xmodemrecv xmodemsend ymodemrecv ymodemsend + \ zmodemrecv zmodemsend +syn keyword ttlStringCommand contained + \ code2str expandenv int2str regexoption sprintf + \ sprintf2 str2code str2int strcompare strconcat + \ strcopy strinsert strjoin strlen strmatch strremove + \ strreplace strscan strspecial strsplit strtrim + \ tolower toupper +syn keyword ttlFileCommand contained + \ basename dirname fileclose fileconcat filecopy + \ filecreate filedelete filelock filemarkptr fileopen + \ filereadln fileread filerename filesearch fileseek + \ fileseekback filestat filestrseek filestrseek2 + \ filetruncate fileunlock filewrite filewriteln + \ findfirst findnext findclose foldercreate + \ folderdelete foldersearch getdir getfileattr makepath + \ setdir setfileattr +syn keyword ttlPasswordCommand contained + \ delpassword getpassword ispassword passwordbox + \ setpassword +syn keyword ttlMiscCommand contained + \ beep bringupbox checksum8 checksum8file checksum16 + \ checksum16file checksum32 checksum32file closesbox + \ clipb2var crc16 crc16file crc32 crc32file exec + \ dirnamebox filenamebox getdate getenv getipv4addr + \ getipv6addr getspecialfolder gettime getttdir getver + \ ifdefined inputbox intdim listbox messagebox random + \ rotateleft rotateright setdate setdlgpos setenv + \ setexitcode settime show statusbox strdim uptime + \ var2clipb yesnobox + + +hi def link ttlCharacter Character +hi def link ttlNumber Number +hi def link ttlComment Comment +hi def link ttlFirstComment Comment +hi def link ttlString String +hi def link ttlLabel Label +hi def link ttlIf Conditional +hi def link ttlElseIf Conditional +hi def link ttlThen Conditional +hi def link ttlConditional Conditional +hi def link ttlRepeat Repeat +hi def link ttlControlCommand Keyword +hi def link ttlVar Identifier +hi def link ttlOperator Operator +hi def link ttlCommunicationCommand Keyword +hi def link ttlStringCommand Keyword +hi def link ttlFileCommand Keyword +hi def link ttlPasswordCommand Keyword +hi def link ttlMiscCommand Keyword + +let b:current_syntax = "teraterm" + +let &cpo = s:save_cpo +unlet s:save_cpo + +" vim: ts=8 sw=2 sts=2 diff --git a/runtime/syntax/vb.vim b/runtime/syntax/vb.vim index 14f9e64850..0c05b35fbd 100644 --- a/runtime/syntax/vb.vim +++ b/runtime/syntax/vb.vim @@ -223,7 +223,7 @@ syn keyword vbStatement Explicit FileCopy For ForEach Function Get GoSub syn keyword vbStatement GoTo Gosub Implements Kill LSet Let Lib LineInput syn keyword vbStatement Load Lock Loop Mid MkDir Name Next On OnError Open syn keyword vbStatement Option Preserve Private Property Public Put RSet -syn keyword vbStatement RaiseEvent Randomize ReDim Redim Rem Reset Resume +syn keyword vbStatement RaiseEvent Randomize ReDim Redim Reset Resume syn keyword vbStatement Return RmDir SavePicture SaveSetting Seek SendKeys syn keyword vbStatement Sendkeys Set SetAttr Static Step Stop Sub Time syn keyword vbStatement Type Unload Unlock Until Wend While Width With diff --git a/runtime/syntax/vhdl.vim b/runtime/syntax/vhdl.vim index c76b046d8c..da2b975ddc 100644 --- a/runtime/syntax/vhdl.vim +++ b/runtime/syntax/vhdl.vim @@ -3,7 +3,7 @@ " Maintainer: Daniel Kho <daniel.kho@tauhop.com> " Previous Maintainer: Czo <Olivier.Sirol@lip6.fr> " Credits: Stephan Hegel <stephan.hegel@snc.siemens.com.cn> -" Last Changed: 2015 Apr 25 by Daniel Kho +" Last Changed: 2015 Oct 13 by Daniel Kho " $Id: vhdl.vim,v 1.1 2004/06/13 15:34:56 vimboss Exp $ " VHSIC (Very High Speed Integrated Circuit) Hardware Description Language @@ -72,6 +72,7 @@ syn keyword vhdlType boolean_vector integer_vector real_vector time_vector syn keyword vhdlType string severity_level " Predefined standard ieee VHDL types syn keyword vhdlType positive natural signed unsigned +syn keyword vhdlType unresolved_signed unresolved_unsigned u_signed u_unsigned syn keyword vhdlType line text syn keyword vhdlType std_logic std_logic_vector syn keyword vhdlType std_ulogic std_ulogic_vector @@ -92,12 +93,12 @@ syn match vhdlAttribute "\'reverse_range" syn match vhdlAttribute "\'right" syn match vhdlAttribute "\'ascending" " block attributes -syn match vhdlAttribute "\'behaviour" -syn match vhdlAttribute "\'structure" +"syn match vhdlAttribute "\'behaviour" " Non-standard VHDL +"syn match vhdlAttribute "\'structure" " Non-standard VHDL syn match vhdlAttribute "\'simple_name" syn match vhdlAttribute "\'instance_name" syn match vhdlAttribute "\'path_name" -syn match vhdlAttribute "\'foreign" +syn match vhdlAttribute "\'foreign" " VHPI " signal attribute syn match vhdlAttribute "\'active" syn match vhdlAttribute "\'delayed" @@ -112,10 +113,9 @@ syn match vhdlAttribute "\'driving" syn match vhdlAttribute "\'driving_value" " type attributes syn match vhdlAttribute "\'base" -syn match vhdlAttribute "\'high" -syn match vhdlAttribute "\'left" +syn match vhdlAttribute "\'subtype" +syn match vhdlAttribute "\'element" syn match vhdlAttribute "\'leftof" -syn match vhdlAttribute "\'low" syn match vhdlAttribute "\'pos" syn match vhdlAttribute "\'pred" syn match vhdlAttribute "\'rightof" @@ -150,34 +150,76 @@ syn match vhdlNumber "-\=\<\d\+\(E[+\-]\=\d\+\)\>" syn match vhdlNumber "-\=\<\d\+\>" syn match vhdlNumber "0*2#[01_]\+#\(E[+\-]\=\d\+\)\=" syn match vhdlNumber "0*16#[0-9a-f_]\+#\(E[+\-]\=\d\+\)\=" + " operators -syn keyword vhdlOperator and nand or nor xor xnor -syn keyword vhdlOperator rol ror sla sll sra srl -syn keyword vhdlOperator mod rem abs not -syn match vhdlOperator "[&><=:+\-*\/|]" -syn match vhdlSpecial "[().,;]" +syn keyword vhdlOperator and nand or nor xor xnor +syn keyword vhdlOperator rol ror sla sll sra srl +syn keyword vhdlOperator mod rem abs not +" TODO remove the following line. You can't have a sequence of */=+ as an operator for example. +"syn match vhdlOperator "[&><=:+\-*\/|]" +" The following lines match valid and invalid operators. + +" Concatenation and math operators +syn match vhdlOperator "&\|+\|-\|\*\|\/" + +" Equality and comparison operators +syn match vhdlOperator "=\|\/=\|>\|<\|>=" + +" Assignment operators +syn match vhdlOperator "<=\|:=" +syn match vhdlOperator "=>" + +" VHDL-2008 conversion, matching equality/non-equality operators +syn match vhdlOperator "??\|?=\|?\/=\|?<\|?<=\|?>\|?>=" + +" Linting for illegal operators +" '=' +syn match vhdlError "\(=\)[<=&+\-\*\/\\]\+" +syn match vhdlError "[=&+\-\*\\]\+\(=\)" +" '>', '<' +syn match vhdlError "\(>\)[<>&+\-\/\\]\+" +syn match vhdlError "[>&+\-\/\\]\+\(>\)" +syn match vhdlError "\(<\)[<&+\-\/\\]\+" +syn match vhdlError "[<>=&+\-\/\\]\+\(<\)" +" Covers most operators +syn match vhdlError "\(&\|+\|\-\|\*\*\|\/=\|??\|?=\|?\/=\|?<=\|?>=\|>=\|<=\|:=\|=>\)[<>=&+\-\*\\?:]\+" +syn match vhdlError "[<>=&+\-\*\\:]\+\(&\|+\|\-\|\*\*\|\/=\|??\|?=\|?\/=\|?<\|?<=\|?>\|?>=\|>=\|<=\|:=\|=>\)" +syn match vhdlError "\(?<\|?>\)[<>&+\-\*\/\\?:]\+" + +"syn match vhdlError "[?]\+\(&\|+\|\-\|\*\*\|??\|?=\|?\/=\|?<\|?<=\|?>\|?>=\|:=\|=>\)" +" '/' +syn match vhdlError "\(\/\)[<>&+\-\*\/\\?:]\+" +syn match vhdlError "[<>=&+\-\*\/\\:]\+\(\/\)" + +syn match vhdlSpecial "<>" +syn match vhdlSpecial "[().,;]" + + " time syn match vhdlTime "\<\d\+\s\+\(\([fpnum]s\)\|\(sec\)\|\(min\)\|\(hr\)\)\>" syn match vhdlTime "\<\d\+\.\d\+\s\+\(\([fpnum]s\)\|\(sec\)\|\(min\)\|\(hr\)\)\>" +syn case match syn keyword vhdlTodo contained TODO NOTE syn keyword vhdlFixme contained FIXME +syn case ignore + +syn region vhdlComment start="/\*" end="\*/" contains=vhdlTodo,vhdlFixme,@Spell +syn match vhdlComment "\(^\|\s\)--.*" contains=vhdlTodo,vhdlFixme,@Spell -" Regex for space is '\s' -" Any number of spaces: \s* -" At least one space: \s+ -syn region vhdlComment start="/\*" end="\*/" contains=vhdlTodo,vhdlFixme,@Spell -syn match vhdlComment "--.*" contains=vhdlTodo,vhdlFixme,@Spell +" Industry-standard directives. These are not standard VHDL, but are commonly +" used in the industry. syn match vhdlPreProc "/\* synthesis .* \*/" +"syn match vhdlPreProc "/\* simulation .* \*/" syn match vhdlPreProc "/\* pragma .* \*/" syn match vhdlPreProc "/\* synopsys .* \*/" syn match vhdlPreProc "--\s*synthesis .*" +"syn match vhdlPreProc "--\s*simulation .*" syn match vhdlPreProc "--\s*pragma .*" syn match vhdlPreProc "--\s*synopsys .*" -" syn match vhdlGlobal "[\'$#~!%@?\^\[\]{}\\]" "Modify the following as needed. The trade-off is performance versus functionality. -syn sync minlines=200 +syn sync minlines=600 " Define the default highlighting. " For version 5.7 and earlier: only when not done already @@ -203,7 +245,7 @@ if version >= 508 || !exists("did_vhdl_syntax_inits") HiLink vhdlTime Number HiLink vhdlType Type HiLink vhdlOperator Operator -" HiLink vhdlGlobal Error + HiLink vhdlError Error HiLink vhdlAttribute Special HiLink vhdlPreProc PreProc diff --git a/scripts/git-log-pretty-since.sh b/scripts/git-log-pretty-since.sh new file mode 100755 index 0000000000..d8e3282fb3 --- /dev/null +++ b/scripts/git-log-pretty-since.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +# Shows a log with changes grouped next to their merge-commit. +# +# Parameters: +# $1 "since" commit +# $2 "inverse match" regex pattern + +set -e +set -u +set -o pipefail + +__SINCE=$1 +__INVMATCH=$2 + +is_merge_commit() { + git rev-parse $1 >/dev/null 2>&1 \ + || { echo "ERROR: invalid commit: $1"; exit 1; } + git log $1^2 >/dev/null 2>&1 && return 0 || return 1 +} + +for commit in $(git log --format='%H' --first-parent --since $__SINCE); do + if is_merge_commit ${commit} ; then + if [ -z "$__INVMATCH" ] || ! git log --oneline ${commit}^1..${commit}^2 \ + | grep -E "$__INVMATCH" >/dev/null 2>&1 ; then + git log -1 --oneline ${commit} + git log --format=' %h %s' ${commit}^1..${commit}^2 + fi + else + git log -1 --oneline ${commit} + fi +done diff --git a/scripts/msgpack-gen.lua b/scripts/msgpack-gen.lua index d50ebd85a2..c726db3920 100644 --- a/scripts/msgpack-gen.lua +++ b/scripts/msgpack-gen.lua @@ -1,5 +1,5 @@ lpeg = require('lpeg') -msgpack = require('MessagePack') +mpack = require('mpack') -- lpeg grammar for building api metadata from a set of header files. It -- ignores comments and preprocessor commands and parses a very small subset @@ -115,7 +115,7 @@ static const uint8_t msgpack_metadata[] = { ]]) -- serialize the API metadata using msgpack and embed into the resulting -- binary for easy querying by clients -packed = msgpack.pack(functions) +packed = mpack.pack(functions) for i = 1, #packed do output:write(string.byte(packed, i)..', ') if i % 10 == 0 then diff --git a/scripts/release.sh b/scripts/release.sh new file mode 100755 index 0000000000..514e5b380a --- /dev/null +++ b/scripts/release.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash + +# Performs steps to tag a release. +# +# Steps: +# Create the "release" commit: +# - CMakeLists.txt: Unset NVIM_VERSION_PRERELEASE +# - Tag the commit. +# Create the "version bump" commit: +# - CMakeLists.txt: Set NVIM_VERSION_PRERELEASE to "-dev" +# +# Manual steps: +# - CMakeLists.txt: Bump NVIM_VERSION_* as appropriate. +# - git push --follow-tags + +set -e +set -u +set -o pipefail + +cd "$(git rev-parse --show-toplevel)" + +__LAST_TAG=$(git describe --abbrev=0) +[ -z "$__LAST_TAG" ] && { echo 'ERROR: no tag found'; exit 1; } +__VERSION_MAJOR=$(grep 'set(NVIM_VERSION_MAJOR' CMakeLists.txt\ + |sed -r 's/.*NVIM_VERSION_MAJOR ([[:digit:]]).*/\1/') +__VERSION_MINOR=$(grep 'set(NVIM_VERSION_MINOR' CMakeLists.txt\ + |sed -r 's/.*NVIM_VERSION_MINOR ([[:digit:]]).*/\1/') +__VERSION_PATCH=$(grep 'set(NVIM_VERSION_PATCH' CMakeLists.txt\ + |sed -r 's/.*NVIM_VERSION_PATCH ([[:digit:]]).*/\1/') +__VERSION="${__VERSION_MAJOR}.${__VERSION_MINOR}.${__VERSION_PATCH}" +{ [ -z "$__VERSION_MAJOR" ] || [ -z "$__VERSION_MINOR" ] || [ -z "$__VERSION_PATCH" ]; } \ + && { echo "ERROR: version parse failed: '${__VERSION}'"; exit 1; } +__RELEASE_MSG="NVIM v${__VERSION} + +Features: + +Fixes: + +Changes: + +" +__BUMP_MSG="version bump" + +echo "Most recent tag: ${__LAST_TAG}" +echo "Release version: ${__VERSION}" +sed -i -r 's/(NVIM_VERSION_PRERELEASE) "-dev"/\1 ""/' CMakeLists.txt +echo "Building changelog since ${__LAST_TAG}..." +__CHANGELOG="$(./scripts/git-log-pretty-since.sh $__LAST_TAG 'vim-patch:\S')" + +git add CMakeLists.txt +git commit --edit -m "${__RELEASE_MSG} ${__CHANGELOG}" +git tag -a v${__VERSION} -m "NVIM v${__VERSION}" + +sed -i -r 's/(NVIM_VERSION_PRERELEASE) ""/\1 "-dev"/' CMakeLists.txt +nvim -c '/NVIM_VERSION' -c 'echo "Update version numbers"' CMakeLists.txt +git add CMakeLists.txt +git commit -m "$__BUMP_MSG" + +echo " +Next steps: + - Double-check NVIM_VERSION_* in CMakeLists.txt + - git push --follow-tags + - update website: index.html" diff --git a/scripts/vim-patch.sh b/scripts/vim-patch.sh index 7612a2ada0..70777535cb 100755 --- a/scripts/vim-patch.sh +++ b/scripts/vim-patch.sh @@ -65,7 +65,7 @@ get_vim_sources() { if [[ ! -d ${VIM_SOURCE_DIR} ]]; then echo "Cloning Vim sources into '${VIM_SOURCE_DIR}'." - git clone --depth=1000 https://github.com/vim/vim.git "${VIM_SOURCE_DIR}" + git clone https://github.com/vim/vim.git "${VIM_SOURCE_DIR}" cd "${VIM_SOURCE_DIR}" else if [[ ! -d "${VIM_SOURCE_DIR}/.git" ]]; then @@ -86,6 +86,11 @@ commit_message() { "${vim_message}" "${vim_commit_url}" } +find_git_remote() { + git remote -v \ + | awk '$2 ~ /github.com[:/]neovim\/neovim/ && $3 == "(fetch)" {print $1}' +} + assign_commit_details() { if [[ ${1} =~ [0-9]\.[0-9]\.[0-9]{3,4} ]]; then # Interpret parameter as version number (tag). @@ -132,21 +137,23 @@ get_vim_patch() { local neovim_branch="${BRANCH_PREFIX}${vim_version}" cd "${NEOVIM_SOURCE_DIR}" + local git_remote=$(find_git_remote) local checked_out_branch="$(git rev-parse --abbrev-ref HEAD)" + if [[ "${checked_out_branch}" == ${BRANCH_PREFIX}* ]]; then echo "✔ Current branch '${checked_out_branch}' seems to be a vim-patch" echo " branch; not creating a new branch." else echo - echo "Fetching 'upstream/master'." - output="$(git fetch upstream master 2>&1)" && + echo "Fetching '${git_remote}/master'." + output="$(git fetch "${git_remote}" master 2>&1)" && echo "✔ ${output}" || (echo "✘ ${output}"; false) echo - echo "Creating new branch '${neovim_branch}' based on 'upstream/master'." + echo "Creating new branch '${neovim_branch}' based on '${git_remote}/master'." cd "${NEOVIM_SOURCE_DIR}" - output="$(git checkout -b "${neovim_branch}" upstream/master 2>&1)" && + output="$(git checkout -b "${neovim_branch}" "${git_remote}/master" 2>&1)" && echo "✔ ${output}" || (echo "✘ ${output}"; false) fi @@ -195,8 +202,9 @@ submit_pr() { exit 1 fi - local pr_body="$(git log --reverse --format='#### %s%n%n%b%n' upstream/master..HEAD)" - local patches=("$(git log --reverse --format='%s' upstream/master..HEAD)") + local git_remote=$(find_git_remote) + local pr_body="$(git log --reverse --format='#### %s%n%n%b%n' ${git_remote}/master..HEAD)" + local patches=("$(git log --reverse --format='%s' ${git_remote}/master..HEAD)") patches=(${patches[@]//vim-patch:}) # Remove 'vim-patch:' prefix for each item in array. local pr_title="${patches[@]}" # Create space-separated string from array. pr_title="${pr_title// /,}" # Replace spaces with commas. @@ -243,7 +251,7 @@ list_vim_patches() { local patch_number="${vim_tag:5}" # Remove prefix like "v7.4." # Tagged Vim patch, check version.c: is_missing="$(sed -n '/static int included_patches/,/}/p' "${NEOVIM_SOURCE_DIR}/src/nvim/version.c" | - grep -x -e "[[:space:]]*//[[:space:]]${patch_number} NA" -e "[[:space:]]*${patch_number}," >/dev/null && echo "false" || echo "true")" + grep -x -e "[[:space:]]*//[[:space:]]${patch_number} NA.*" -e "[[:space:]]*${patch_number}," >/dev/null && echo "false" || echo "true")" vim_commit="${vim_tag#v}" else # Untagged Vim patch (e.g. runtime updates), check the Neovim git log: diff --git a/src/.clang-format b/src/.clang-format index 35e545ac4b..5a910ff34b 100644 --- a/src/.clang-format +++ b/src/.clang-format @@ -1,4 +1,4 @@ -BasedOnStyle: llvm +BasedOnStyle: Google Language: Cpp ColumnLimit: 80 IndentWidth: 2 @@ -10,3 +10,9 @@ AlignEscapedNewlinesLeft: false AllowShortFunctionsOnASingleLine: false SpacesBeforeTrailingComments: 2 PenaltyReturnTypeOnItsOwnLine: 200 +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +BinPackParameters: false +BreakBeforeBinaryOperators: true +ContinuationIndentWidth: 4 diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index ef9e11fbef..a473f99278 100644 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -41,25 +41,33 @@ include_directories(${GENERATED_DIR}) include_directories(${GENERATED_INCLUDES_DIR}) file(MAKE_DIRECTORY ${GENERATED_DIR}) -file(MAKE_DIRECTORY ${GENERATED_DIR}/os) -file(MAKE_DIRECTORY ${GENERATED_DIR}/api) -file(MAKE_DIRECTORY ${GENERATED_DIR}/api/private) -file(MAKE_DIRECTORY ${GENERATED_DIR}/msgpack_rpc) -file(MAKE_DIRECTORY ${GENERATED_DIR}/tui) -file(MAKE_DIRECTORY ${GENERATED_DIR}/event) file(MAKE_DIRECTORY ${GENERATED_INCLUDES_DIR}) -file(MAKE_DIRECTORY ${GENERATED_INCLUDES_DIR}/os) -file(MAKE_DIRECTORY ${GENERATED_INCLUDES_DIR}/api) -file(MAKE_DIRECTORY ${GENERATED_INCLUDES_DIR}/api/private) -file(MAKE_DIRECTORY ${GENERATED_INCLUDES_DIR}/msgpack_rpc) -file(MAKE_DIRECTORY ${GENERATED_INCLUDES_DIR}/tui) -file(MAKE_DIRECTORY ${GENERATED_INCLUDES_DIR}/event) - -file(GLOB NEOVIM_SOURCES *.c os/*.c api/*.c api/private/*.c msgpack_rpc/*.c - tui/*.c event/*.c) + +file(GLOB NEOVIM_SOURCES *.c) + +foreach(subdir + os + api + api/private + msgpack_rpc + tui + event + eval + ) + file(MAKE_DIRECTORY ${GENERATED_DIR}/${subdir}) + file(MAKE_DIRECTORY ${GENERATED_INCLUDES_DIR}/${subdir}) + file(GLOB sources ${subdir}/*.c) + list(APPEND NEOVIM_SOURCES ${sources}) +endforeach() + file(GLOB_RECURSE NEOVIM_HEADERS *.h) file(GLOB UNIT_TEST_FIXTURES ${PROJECT_SOURCE_DIR}/test/unit/fixtures/*.c) +# Sort file lists to ensure generated files are created in the same order from +# build to build. +list(SORT NEOVIM_SOURCES) +list(SORT NEOVIM_HEADERS) + foreach(sfile ${NEOVIM_SOURCES}) get_filename_component(f ${sfile} NAME) if(${f} MATCHES "^(regexp_nfa.c)$") @@ -72,7 +80,6 @@ list(REMOVE_ITEM NEOVIM_SOURCES ${to_remove}) # Handle legacy files that don't yet pass -Wconversion. set(CONV_SOURCES buffer.c - charset.c diff.c edit.c eval.c @@ -84,10 +91,7 @@ set(CONV_SOURCES mbyte.c memline.c message.c - misc1.c ops.c - path.c - quickfix.c regexp.c screen.c search.c diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index fa4b8e5f7d..55b535c78c 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -45,14 +45,22 @@ Integer buffer_line_count(Buffer buffer, Error *err) /// Gets a buffer line /// +/// @deprecated use buffer_get_lines instead. +/// for positive indices (including 0) use +/// "buffer_get_lines(buffer, index, index+1, true)" +/// for negative indices use +/// "buffer_get_lines(buffer, index-1, index, true)" +/// /// @param buffer The buffer handle /// @param index The line index /// @param[out] err Details of an error that may have occurred /// @return The line string String buffer_get_line(Buffer buffer, Integer index, Error *err) { - String rv = {.size = 0}; - Array slice = buffer_get_line_slice(buffer, index, index, true, true, err); + String rv = { .size = 0 }; + + index = convert_index(index); + Array slice = buffer_get_lines(buffer, index, index+1, true, err); if (!err->set && slice.size) { rv = slice.items[0].data.string; @@ -65,6 +73,12 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err) /// Sets a buffer line /// +/// @deprecated use buffer_set_lines instead. +/// for positive indices use +/// "buffer_set_lines(buffer, index, index+1, true, [line])" +/// for negative indices use +/// "buffer_set_lines(buffer, index-1, index, true, [line])" +/// /// @param buffer The buffer handle /// @param index The line index /// @param line The new line. @@ -72,23 +86,34 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err) void buffer_set_line(Buffer buffer, Integer index, String line, Error *err) { Object l = STRING_OBJ(line); - Array array = {.items = &l, .size = 1}; - buffer_set_line_slice(buffer, index, index, true, true, array, err); + Array array = { .items = &l, .size = 1 }; + index = convert_index(index); + buffer_set_lines(buffer, index, index+1, true, array, err); } /// Deletes a buffer line /// +/// @deprecated use buffer_set_lines instead. +/// for positive indices use +/// "buffer_set_lines(buffer, index, index+1, true, [])" +/// for negative indices use +/// "buffer_set_lines(buffer, index-1, index, true, [])" /// @param buffer The buffer handle /// @param index The line index /// @param[out] err Details of an error that may have occurred void buffer_del_line(Buffer buffer, Integer index, Error *err) { Array array = ARRAY_DICT_INIT; - buffer_set_line_slice(buffer, index, index, true, true, array, err); + index = convert_index(index); + buffer_set_lines(buffer, index, index+1, true, array, err); } /// Retrieves a line range from the buffer /// +/// @deprecated use buffer_get_lines(buffer, newstart, newend, false) +/// where newstart = start + int(not include_start) - int(start < 0) +/// newend = end + int(include_end) - int(end < 0) +/// int(bool) = 1 if bool is true else 0 /// @param buffer The buffer handle /// @param start The first line index /// @param end The last line index @@ -103,16 +128,48 @@ ArrayOf(String) buffer_get_line_slice(Buffer buffer, Boolean include_end, Error *err) { + start = convert_index(start) + !include_start; + end = convert_index(end) + include_end; + return buffer_get_lines(buffer, start , end, false, err); +} + + +/// Retrieves a line range from the buffer +/// +/// Indexing is zero-based, end-exclusive. Negative indices are interpreted +/// as length+1+index, i e -1 refers to the index past the end. So to get the +/// last element set start=-2 and end=-1. +/// +/// Out-of-bounds indices are clamped to the nearest valid value, unless +/// `strict_indexing` is set. +/// +/// @param buffer The buffer handle +/// @param start The first line index +/// @param end The last line index (exclusive) +/// @param strict_indexing whether out-of-bounds should be an error. +/// @param[out] err Details of an error that may have occurred +/// @return An array of lines +ArrayOf(String) buffer_get_lines(Buffer buffer, + Integer start, + Integer end, + Boolean strict_indexing, + Error *err) +{ Array rv = ARRAY_DICT_INIT; buf_T *buf = find_buffer_by_handle(buffer, err); - if (!buf || !inbounds(buf, start)) { + if (!buf) { return rv; } - start = normalize_index(buf, start) + (include_start ? 0 : 1); - include_end = include_end || (end >= buf->b_ml.ml_line_count); - end = normalize_index(buf, end) + (include_end ? 1 : 0); + bool oob = false; + start = normalize_index(buf, start, &oob); + end = normalize_index(buf, end, &oob); + + if (strict_indexing && oob) { + api_set_error(err, Validation, _("Index out of bounds")); + return rv; + } if (start >= end) { // Return 0-length array @@ -152,8 +209,14 @@ end: return rv; } + /// Replaces a line range on the buffer /// +/// @deprecated use buffer_set_lines(buffer, newstart, newend, false, lines) +/// where newstart = start + int(not include_start) + int(start < 0) +/// newend = end + int(include_end) + int(end < 0) +/// int(bool) = 1 if bool is true else 0 +/// /// @param buffer The buffer handle /// @param start The first line index /// @param end The last line index @@ -170,20 +233,52 @@ void buffer_set_line_slice(Buffer buffer, ArrayOf(String) replacement, Error *err) { + start = convert_index(start) + !include_start; + end = convert_index(end) + include_end; + buffer_set_lines(buffer, start, end, false, replacement, err); +} + + +/// Replaces line range on the buffer +/// +/// Indexing is zero-based, end-exclusive. Negative indices are interpreted +/// as length+1+index, i e -1 refers to the index past the end. So to change +/// or delete the last element set start=-2 and end=-1. +/// +/// To insert lines at a given index, set both start and end to the same index. +/// To delete a range of lines, set replacement to an empty array. +/// +/// Out-of-bounds indices are clamped to the nearest valid value, unless +/// `strict_indexing` is set. +/// +/// @param buffer The buffer handle +/// @param start The first line index +/// @param end The last line index (exclusive) +/// @param strict_indexing whether out-of-bounds should be an error. +/// @param replacement An array of lines to use as replacement +/// @param[out] err Details of an error that may have occurred +void buffer_set_lines(Buffer buffer, + Integer start, + Integer end, + Boolean strict_indexing, + ArrayOf(String) replacement, + Error *err) +{ buf_T *buf = find_buffer_by_handle(buffer, err); if (!buf) { return; } - if (!inbounds(buf, start)) { + bool oob = false; + start = normalize_index(buf, start, &oob); + end = normalize_index(buf, end, &oob); + + if (strict_indexing && oob) { api_set_error(err, Validation, _("Index out of bounds")); return; } - start = normalize_index(buf, start) + (include_start ? 0 : 1); - include_end = include_end || (end >= buf->b_ml.ml_line_count); - end = normalize_index(buf, end) + (include_end ? 1 : 0); if (start > end) { api_set_error(err, @@ -328,13 +423,16 @@ Object buffer_get_var(Buffer buffer, String name, Error *err) return dict_get_value(buf->b_vars, name, err); } -/// Sets a buffer-scoped (b:) variable. 'nil' value deletes the variable. +/// Sets a buffer-scoped (b:) variable /// /// @param buffer The buffer handle /// @param name The variable name /// @param value The variable value /// @param[out] err Details of an error that may have occurred -/// @return The old value +/// @return The old value or nil if there was no previous value. +/// +/// @warning It may return nil if there was no previous value +/// or if previous value was `v:null`. Object buffer_set_var(Buffer buffer, String name, Object value, Error *err) { buf_T *buf = find_buffer_by_handle(buffer, err); @@ -343,7 +441,27 @@ Object buffer_set_var(Buffer buffer, String name, Object value, Error *err) return (Object) OBJECT_INIT; } - return dict_set_value(buf->b_vars, name, value, err); + return dict_set_value(buf->b_vars, name, value, false, err); +} + +/// Removes a buffer-scoped (b:) variable +/// +/// @param buffer The buffer handle +/// @param name The variable name +/// @param[out] err Details of an error that may have occurred +/// @return The old value or nil if there was no previous value. +/// +/// @warning It may return nil if there was no previous value +/// or if previous value was `v:null`. +Object buffer_del_var(Buffer buffer, String name, Error *err) +{ + buf_T *buf = find_buffer_by_handle(buffer, err); + + if (!buf) { + return (Object) OBJECT_INIT; + } + + return dict_set_value(buf->b_vars, name, NIL, true, err); } /// Gets a buffer option value @@ -457,6 +575,8 @@ Boolean buffer_is_valid(Buffer buffer) /// Inserts a sequence of lines to a buffer at a certain index /// +/// @deprecated use buffer_set_lines(buffer, lnum, lnum, true, lines) +/// /// @param buffer The buffer handle /// @param lnum Insert the lines after `lnum`. If negative, it will append /// to the end of the buffer. @@ -467,8 +587,9 @@ void buffer_insert(Buffer buffer, ArrayOf(String) lines, Error *err) { - bool end_start = lnum < 0; - buffer_set_line_slice(buffer, lnum, lnum, !end_start, end_start, lines, err); + // "lnum" will be the index of the line after inserting, + // no matter if it is negative or not + buffer_set_lines(buffer, lnum, lnum, true, lines, err); } /// Return a tuple (row,col) representing the position of the named mark @@ -632,20 +753,26 @@ static void fix_cursor(linenr_T lo, linenr_T hi, linenr_T extra) } // Normalizes 0-based indexes to buffer line numbers -static int64_t normalize_index(buf_T *buf, int64_t index) +static int64_t normalize_index(buf_T *buf, int64_t index, bool *oob) { + int64_t line_count = buf->b_ml.ml_line_count; // Fix if < 0 - index = index < 0 ? buf->b_ml.ml_line_count + index : index; + index = index < 0 ? line_count + index +1 : index; + + // Check for oob + if (index > line_count) { + *oob = true; + index = line_count; + } else if (index < 0) { + *oob = true; + index = 0; + } // Convert the index to a vim line number index++; - // Fix if > line_count - index = index > buf->b_ml.ml_line_count ? buf->b_ml.ml_line_count : index; return index; } -// Returns true if the 0-indexed `index` is within the 1-indexed buffer bounds. -static bool inbounds(buf_T *buf, int64_t index) +static int64_t convert_index(int64_t index) { - linenr_T nlines = buf->b_ml.ml_line_count; - return index >= -nlines && index < nlines; + return index < 0 ? index - 1 : index; } diff --git a/src/nvim/api/private/defs.h b/src/nvim/api/private/defs.h index 6c8e324649..fbfa87d5ae 100644 --- a/src/nvim/api/private/defs.h +++ b/src/nvim/api/private/defs.h @@ -99,4 +99,3 @@ struct key_value_pair { #endif // NVIM_API_PRIVATE_DEFS_H - diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 7a0b5191d7..db3e499427 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -90,14 +90,17 @@ Object dict_get_value(dict_T *dict, String key, Error *err) } /// Set a value in a dict. Objects are recursively expanded into their -/// vimscript equivalents. Passing 'nil' as value deletes the key. +/// vimscript equivalents. /// /// @param dict The vimscript dict /// @param key The key /// @param value The new value +/// @param del Delete key in place of setting it. Argument `value` is ignored in +/// this case. /// @param[out] err Details of an error that may have occurred /// @return the old value, if any -Object dict_set_value(dict_T *dict, String key, Object value, Error *err) +Object dict_set_value(dict_T *dict, String key, Object value, bool del, + Error *err) { Object rv = OBJECT_INIT; @@ -118,7 +121,7 @@ Object dict_set_value(dict_T *dict, String key, Object value, Error *err) dictitem_T *di = dict_find(dict, (uint8_t *)key.data, (int)key.size); - if (value.type == kObjectTypeNil) { + if (del) { // Delete the key if (di == NULL) { // Doesn't exist, fail @@ -397,13 +400,13 @@ bool object_to_vim(Object obj, typval_T *tv, Error *err) switch (obj.type) { case kObjectTypeNil: - tv->v_type = VAR_NUMBER; - tv->vval.v_number = 0; + tv->v_type = VAR_SPECIAL; + tv->vval.v_special = kSpecialVarNull; break; case kObjectTypeBoolean: - tv->v_type = VAR_NUMBER; - tv->vval.v_number = obj.data.boolean; + tv->v_type = VAR_SPECIAL; + tv->vval.v_special = obj.data.boolean? kSpecialVarTrue: kSpecialVarFalse; break; case kObjectTypeBuffer: @@ -651,6 +654,21 @@ static Object vim_to_object_rec(typval_T *obj, PMap(ptr_t) *lookup) } switch (obj->v_type) { + case VAR_SPECIAL: + switch (obj->vval.v_special) { + case kSpecialVarTrue: + case kSpecialVarFalse: { + rv.type = kObjectTypeBoolean; + rv.data.boolean = (obj->vval.v_special == kSpecialVarTrue); + break; + } + case kSpecialVarNull: { + rv.type = kObjectTypeNil; + break; + } + } + break; + case VAR_STRING: rv.type = kObjectTypeString; rv.data.string = cstr_to_string((char *) obj->vval.v_string); @@ -730,6 +748,10 @@ static Object vim_to_object_rec(typval_T *obj, PMap(ptr_t) *lookup) } } break; + + case VAR_UNKNOWN: + case VAR_FUNC: + break; } return rv; diff --git a/src/nvim/api/tabpage.c b/src/nvim/api/tabpage.c index 126ee4072d..c8311b0aa0 100644 --- a/src/nvim/api/tabpage.c +++ b/src/nvim/api/tabpage.c @@ -54,13 +54,16 @@ Object tabpage_get_var(Tabpage tabpage, String name, Error *err) return dict_get_value(tab->tp_vars, name, err); } -/// Sets a tab-scoped (t:) variable. 'nil' value deletes the variable. +/// Sets a tab-scoped (t:) variable /// /// @param tabpage handle /// @param name The variable name /// @param value The variable value /// @param[out] err Details of an error that may have occurred -/// @return The tab page handle +/// @return The old value or nil if there was no previous value. +/// +/// @warning It may return nil if there was no previous value +/// or if previous value was `v:null`. Object tabpage_set_var(Tabpage tabpage, String name, Object value, Error *err) { tabpage_T *tab = find_tab_by_handle(tabpage, err); @@ -69,7 +72,27 @@ Object tabpage_set_var(Tabpage tabpage, String name, Object value, Error *err) return (Object) OBJECT_INIT; } - return dict_set_value(tab->tp_vars, name, value, err); + return dict_set_value(tab->tp_vars, name, value, false, err); +} + +/// Removes a tab-scoped (t:) variable +/// +/// @param tabpage handle +/// @param name The variable name +/// @param[out] err Details of an error that may have occurred +/// @return The old value or nil if there was no previous value. +/// +/// @warning It may return nil if there was no previous value +/// or if previous value was `v:null`. +Object tabpage_del_var(Tabpage tabpage, String name, Error *err) +{ + tabpage_T *tab = find_tab_by_handle(tabpage, err); + + if (!tab) { + return (Object) OBJECT_INIT; + } + + return dict_set_value(tab->tp_vars, name, NIL, true, err); } /// Gets the current window in a tab page diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 9279f6b469..243806b3f1 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -291,7 +291,7 @@ void vim_change_directory(String dir, Error *err) return; } - post_chdir(false); + post_chdir(kCdScopeGlobal); try_end(err); } @@ -331,15 +331,31 @@ Object vim_get_var(String name, Error *err) return dict_get_value(&globvardict, name, err); } -/// Sets a global variable. Passing 'nil' as value deletes the variable. +/// Sets a global variable /// /// @param name The variable name /// @param value The variable value /// @param[out] err Details of an error that may have occurred -/// @return the old value if any +/// @return The old value or nil if there was no previous value. +/// +/// @warning It may return nil if there was no previous value +/// or if previous value was `v:null`. Object vim_set_var(String name, Object value, Error *err) { - return dict_set_value(&globvardict, name, value, err); + return dict_set_value(&globvardict, name, value, false, err); +} + +/// Removes a global variable +/// +/// @param name The variable name +/// @param[out] err Details of an error that may have occurred +/// @return The old value or nil if there was no previous value. +/// +/// @warning It may return nil if there was no previous value +/// or if previous value was `v:null`. +Object vim_del_var(String name, Error *err) +{ + return dict_set_value(&globvardict, name, NIL, true, err); } /// Gets a vim variable diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index aad616c7bf..a52f53a3e6 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -197,13 +197,16 @@ Object window_get_var(Window window, String name, Error *err) return dict_get_value(win->w_vars, name, err); } -/// Sets a window-scoped (w:) variable. 'nil' value deletes the variable. +/// Sets a window-scoped (w:) variable /// /// @param window The window handle /// @param name The variable name /// @param value The variable value /// @param[out] err Details of an error that may have occurred -/// @return The old value +/// @return The old value or nil if there was no previous value. +/// +/// @warning It may return nil if there was no previous value +/// or if previous value was `v:null`. Object window_set_var(Window window, String name, Object value, Error *err) { win_T *win = find_window_by_handle(window, err); @@ -212,7 +215,27 @@ Object window_set_var(Window window, String name, Object value, Error *err) return (Object) OBJECT_INIT; } - return dict_set_value(win->w_vars, name, value, err); + return dict_set_value(win->w_vars, name, value, false, err); +} + +/// Removes a window-scoped (w:) variable +/// +/// @param window The window handle +/// @param name The variable name +/// @param[out] err Details of an error that may have occurred +/// @return The old value or nil if there was no previous value. +/// +/// @warning It may return nil if there was no previous value +/// or if previous value was `v:null`. +Object window_del_var(Window window, String name, Error *err) +{ + win_T *win = find_window_by_handle(window, err); + + if (!win) { + return (Object) OBJECT_INIT; + } + + return dict_set_value(win->w_vars, name, NIL, true, err); } /// Gets a window option value diff --git a/src/nvim/assert.h b/src/nvim/assert.h index 3a900aca65..0ce48e4766 100644 --- a/src/nvim/assert.h +++ b/src/nvim/assert.h @@ -8,17 +8,32 @@ // defined(__has_feature) && __has_feature(...). Therefore we define Clang's // __has_feature and __has_extension macro's before referring to them. #ifndef __has_feature - #define __has_feature(x) 0 +# define __has_feature(x) 0 #endif #ifndef __has_extension - #define __has_extension __has_feature +# define __has_extension __has_feature #endif -/// STATIC_ASSERT(condition, message) - assert at compile time if !cond +/// @def STATIC_ASSERT +/// @brief Assert at compile time if condition is not satisfied. /// -/// example: -/// STATIC_ASSERT(sizeof(void *) == 8, "need 64-bits mode"); +/// Should be put on its own line, followed by a semicolon. +/// +/// Example: +/// +/// STATIC_ASSERT(sizeof(void *) == 8, "Expected 64-bit mode"); +/// +/// @param[in] condition Condition to check, should be an integer constant +/// expression. +/// @param[in] message Message which will be given if check fails. + +/// @def STATIC_ASSERT_EXPR +/// @brief Like #STATIC_ASSERT, but can be used where expressions are used. +/// +/// STATIC_ASSERT_EXPR may be put in brace initializer lists. Error message +/// given in this case is not very nice with the current implementation though +/// and `message` argument is ignored. // define STATIC_ASSERT as C11's _Static_assert whenever either C11 mode is // detected or the compiler is known to support it. Note that Clang in C99 @@ -29,50 +44,74 @@ // clearer messages we get from _Static_assert, we suppress the warnings // temporarily. +#define STATIC_ASSERT_PRAGMA_START +#define STATIC_ASSERT_PRAGMA_END +#define STATIC_ASSERT(...) \ + do { \ + STATIC_ASSERT_PRAGMA_START \ + STATIC_ASSERT_STATEMENT(__VA_ARGS__); \ + STATIC_ASSERT_PRAGMA_END \ + } while (0) + // the easiest case, when the mode is C11 (generic compiler) or Clang // advertises explicit support for c_static_assert, meaning it won't warn. #if __STDC_VERSION__ >= 201112L || __has_feature(c_static_assert) - #define STATIC_ASSERT(cond, msg) _Static_assert(cond, msg) +# define STATIC_ASSERT_STATEMENT(cond, msg) _Static_assert(cond, msg) // if we're dealing with gcc >= 4.6 in C99 mode, we can still use // _Static_assert but we need to suppress warnings, this is pretty ugly. #elif (!defined(__clang__) && !defined(__INTEL_COMPILER)) && \ (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) - #define STATIC_ASSERT(cond, msg) \ - _Pragma("GCC diagnostic push") \ - _Pragma("GCC diagnostic ignored \"-pedantic\"") \ - _Static_assert(cond, msg); \ - _Pragma("GCC diagnostic pop") \ + +# define STATIC_ASSERT_STATEMENT(cond, msg) _Static_assert(cond, msg) + +# undef STATIC_ASSERT_PRAGMA_START +# define STATIC_ASSERT_PRAGMA_START \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-pedantic\"") \ + +# undef STATIC_ASSERT_PRAGMA_END +# define STATIC_ASSERT_PRAGMA_END \ + _Pragma("GCC diagnostic pop") \ // the same goes for clang in C99 mode, but we suppress a different warning #elif defined(__clang__) && __has_extension(c_static_assert) - #define STATIC_ASSERT(cond, msg) \ - _Pragma("clang diagnostic push") \ - _Pragma("clang diagnostic ignored \"-Wc11-extensions\"") \ - _Static_assert(cond, msg); \ - _Pragma("clang diagnostic pop") \ + +# define STATIC_ASSERT_STATEMENT(cond, msg) _Static_assert(cond, msg) + +# undef STATIC_ASSERT_PRAGMA_START +# define STATIC_ASSERT_PRAGMA_START \ + _Pragma("clang diagnostic push") \ + _Pragma("clang diagnostic ignored \"-Wc11-extensions\"") \ + +# undef STATIC_ASSERT_PRAGMA_END +# define STATIC_ASSERT_PRAGMA_END \ + _Pragma("clang diagnostic pop") \ // TODO(aktau): verify that this works, don't have MSVC on hand. #elif _MSC_VER >= 1600 - #define STATIC_ASSERT(cond, msg) static_assert(cond, msg) + +# define STATIC_ASSERT_STATEMENT(cond, msg) static_assert(cond, msg) // fallback for compilers that don't support _Static_assert or static_assert // not as pretty but gets the job done. Credit goes to Pádraig Brady and // contributors. #else - #define ASSERT_CONCAT_(a, b) a##b - #define ASSERT_CONCAT(a, b) ASSERT_CONCAT_(a, b) - // These can't be used after statements in c89. - #ifdef __COUNTER__ - #define STATIC_ASSERT(e,m) \ - { enum { ASSERT_CONCAT(static_assert_, __COUNTER__) = 1/(!!(e)) }; } - #else - // This can't be used twice on the same line so ensure if using in headers - // that the headers are not included twice (by wrapping in #ifndef...#endif) - // Note it doesn't cause an issue when used on same line of separate modules - // compiled with gcc -combine -fwhole-program. - #define STATIC_ASSERT(e,m) \ - { enum { ASSERT_CONCAT(assert_line_, __LINE__) = 1/(!!(e)) }; } - #endif +# define STATIC_ASSERT_STATEMENT STATIC_ASSERT_EXPR +#endif + +#define ASSERT_CONCAT_(a, b) a##b +#define ASSERT_CONCAT(a, b) ASSERT_CONCAT_(a, b) +// These can't be used after statements in c89. +#ifdef __COUNTER__ +# define STATIC_ASSERT_EXPR(e, m) \ + ((enum { ASSERT_CONCAT(static_assert_, __COUNTER__) = 1/(!!(e)) }) 0) +#else +// This can't be used twice on the same line so ensure if using in headers +// that the headers are not included twice (by wrapping in #ifndef...#endif) +// Note it doesn't cause an issue when used on same line of separate modules +// compiled with gcc -combine -fwhole-program. +# define STATIC_ASSERT_EXPR(e, m) \ + ((enum { ASSERT_CONCAT(assert_line_, __LINE__) = 1/(!!(e)) }) 0) #endif #endif // NVIM_ASSERT_H diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 62ab7495da..529d0889bd 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -141,14 +141,21 @@ open_buffer ( /* mark cursor position as being invalid */ curwin->w_valid = 0; - if (curbuf->b_ffname != NULL - ) { + if (curbuf->b_ffname != NULL) { + int old_msg_silent = msg_silent; + if (shortmess(SHM_FILEINFO)) { + msg_silent = 1; + } + retval = readfile(curbuf->b_ffname, curbuf->b_fname, - (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, eap, - flags | READ_NEW); - /* Help buffer is filtered. */ - if (curbuf->b_help) + (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, eap, + flags | READ_NEW); + msg_silent = old_msg_silent; + + // Help buffer is filtered. + if (curbuf->b_help) { fix_help_buffer(); + } } else if (read_stdin) { int save_bin = curbuf->b_p_bin; linenr_T line_count; @@ -257,17 +264,16 @@ open_buffer ( return retval; } -/* - * Return TRUE if "buf" points to a valid buffer (in the buffer list). - */ -int buf_valid(buf_T *buf) +/// Check that "buf" points to a valid buffer (in the buffer list). +bool buf_valid(buf_T *buf) + FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { FOR_ALL_BUFFERS(bp) { if (bp == buf) { - return TRUE; + return true; } } - return FALSE; + return false; } /* @@ -1547,6 +1553,7 @@ void free_buf_options(buf_T *buf, int free_p_ff) clear_string_option(&buf->b_p_ep); clear_string_option(&buf->b_p_path); clear_string_option(&buf->b_p_tags); + clear_string_option(&buf->b_p_tc); clear_string_option(&buf->b_p_dict); clear_string_option(&buf->b_p_tsr); clear_string_option(&buf->b_p_qe); @@ -2055,16 +2062,15 @@ void buflist_setfpos(buf_T *const buf, win_T *const win, } -/* - * Return true when "wip" has 'diff' set and the diff is only for another tab - * page. That's because a diff is local to a tab page. - */ +/// Check that "wip" has 'diff' set and the diff is only for another tab page. +/// That's because a diff is local to a tab page. static bool wininfo_other_tab_diff(wininfo_T *wip) + FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { if (wip->wi_opt.wo_diff) { FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { - /* return false when it's a window in the current tab page, thus - * the buffer was in diff mode here */ + // return false when it's a window in the current tab page, thus + // the buffer was in diff mode here if (wip->wi_win == wp) { return false; } @@ -2421,52 +2427,62 @@ void buflist_altfpos(win_T *win) buflist_setfpos(curbuf, win, win->w_cursor.lnum, win->w_cursor.col, TRUE); } -/* - * Return TRUE if 'ffname' is not the same file as current file. - * Fname must have a full path (expanded by path_get_absolute_path()). - */ -int otherfile(char_u *ffname) +/// Check that "ffname" is not the same file as current file. +/// Fname must have a full path (expanded by path_get_absolute_path()). +/// +/// @param ffname full path name to check +bool otherfile(char_u *ffname) + FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { return otherfile_buf(curbuf, ffname, NULL, false); } -static int otherfile_buf(buf_T *buf, char_u *ffname, - FileID *file_id_p, bool file_id_valid) +/// Check that "ffname" is not the same file as the file loaded in "buf". +/// Fname must have a full path (expanded by path_get_absolute_path()). +/// +/// @param buf buffer to check +/// @param ffname full path name to check +/// @param file_id_p information about the file at "ffname". +/// @param file_id_valid whether a valid "file_id_p" was passed in. +static bool otherfile_buf(buf_T *buf, char_u *ffname, FileID *file_id_p, + bool file_id_valid) + FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { - /* no name is different */ + // no name is different if (ffname == NULL || *ffname == NUL || buf->b_ffname == NULL) { - return TRUE; + return true; } if (fnamecmp(ffname, buf->b_ffname) == 0) { - return FALSE; + return false; } { FileID file_id; - /* If no struct stat given, get it now */ + // If no struct stat given, get it now if (file_id_p == NULL) { file_id_p = &file_id; file_id_valid = os_fileid((char *)ffname, file_id_p); } if (!file_id_valid) { // file_id not valid, assume files are different. - return TRUE; + return true; } - /* Use dev/ino to check if the files are the same, even when the names - * are different (possible with links). Still need to compare the - * name above, for when the file doesn't exist yet. - * Problem: The dev/ino changes when a file is deleted (and created - * again) and remains the same when renamed/moved. We don't want to - * stat() each buffer each time, that would be too slow. Get the - * dev/ino again when they appear to match, but not when they appear - * to be different: Could skip a buffer when it's actually the same - * file. */ + // Use dev/ino to check if the files are the same, even when the names + // are different (possible with links). Still need to compare the + // name above, for when the file doesn't exist yet. + // Problem: The dev/ino changes when a file is deleted (and created + // again) and remains the same when renamed/moved. We don't want to + // stat() each buffer each time, that would be too slow. Get the + // dev/ino again when they appear to match, but not when they appear + // to be different: Could skip a buffer when it's actually the same + // file. if (buf_same_file_id(buf, file_id_p)) { buf_set_file_id(buf); - if (buf_same_file_id(buf, file_id_p)) - return FALSE; + if (buf_same_file_id(buf, file_id_p)) { + return false; + } } } - return TRUE; + return true; } // Set file_id for a buffer. @@ -2483,11 +2499,14 @@ void buf_set_file_id(buf_T *buf) } } -// return TRUE if file_id in buffer "buf" matches with "file_id". +/// Check that file_id in buffer "buf" matches with "file_id". +/// +/// @param buf buffer +/// @param file_id file id static bool buf_same_file_id(buf_T *buf, FileID *file_id) + FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { - return buf->file_id_valid - && os_fileid_equal(&(buf->file_id), file_id); + return buf->file_id_valid && os_fileid_equal(&(buf->file_id), file_id); } /* @@ -2770,23 +2789,28 @@ void maketitle(void) resettitle(); } -/* - * Used for title and icon: Check if "str" differs from "*last". Set "*last" - * from "str" if it does. - * Return TRUE when "*last" changed. - */ -static int ti_change(char_u *str, char_u **last) +/// Used for title and icon: Check if "str" differs from "*last". Set "*last" +/// from "str" if it does by freeing the old value of "*last" and duplicating +/// "str". +/// +/// @param str desired title string +/// @param[in,out] last current title string +// +/// @return true when "*last" changed. +static bool ti_change(char_u *str, char_u **last) + FUNC_ATTR_WARN_UNUSED_RESULT { if ((str == NULL) != (*last == NULL) || (str != NULL && *last != NULL && STRCMP(str, *last) != 0)) { xfree(*last); - if (str == NULL) + if (str == NULL) { *last = NULL; - else + } else { *last = vim_strsave(str); - return TRUE; + } + return true; } - return FALSE; + return false; } /* @@ -3014,7 +3038,7 @@ int build_stl_str_hl( && item[groupitem[groupdepth]].minwid == 0) { bool has_normal_items = false; for (long n = groupitem[groupdepth] + 1; n < curitem; n++) { - if (item[n].type == Normal) { + if (item[n].type == Normal || item[n].type == Highlight) { has_normal_items = true; break; } @@ -3922,26 +3946,29 @@ void get_rel_pos(win_T *wp, char_u *buf, int buflen) : (int)(above * 100L / (above + below))); } -/* - * Append (file 2 of 8) to "buf[buflen]", if editing more than one file. - * Return TRUE if it was appended. - */ -static int -append_arg_number ( - win_T *wp, - char_u *buf, - int buflen, - int add_file /* Add "file" before the arg number */ -) +/// Append (file 2 of 8) to "buf[buflen]", if editing more than one file. +/// +/// @param wp window whose buffers to check +/// @param[in,out] buf string buffer to add the text to +/// @param buflen length of the string buffer +/// @param add_file if true, add "file" before the arg number +/// +/// @return true if it was appended. +static bool append_arg_number(win_T *wp, char_u *buf, int buflen, bool add_file) + FUNC_ATTR_NONNULL_ALL { - char_u *p; + // Nothing to do + if (ARGCOUNT <= 1) { + return false; + } + + char_u *p = buf + STRLEN(buf); // go to the end of the buffer - if (ARGCOUNT <= 1) /* nothing to do */ - return FALSE; + // Early out if the string is getting too long + if (p - buf + 35 >= buflen) { + return false; + } - p = buf + STRLEN(buf); /* go to the end of the buffer */ - if (p - buf + 35 >= buflen) /* getting too long */ - return FALSE; *p++ = ' '; *p++ = '('; if (add_file) { @@ -3949,9 +3976,10 @@ append_arg_number ( p += 5; } vim_snprintf((char *)p, (size_t)(buflen - (p - buf)), - wp->w_arg_idx_invalid ? "(%d) of %d)" - : "%d of %d)", wp->w_arg_idx + 1, ARGCOUNT); - return TRUE; + wp->w_arg_idx_invalid + ? "(%d) of %d)" + : "%d of %d)", wp->w_arg_idx + 1, ARGCOUNT); + return true; } /* @@ -4585,11 +4613,16 @@ char_u *buf_spname(buf_T *buf) return NULL; } -/* - * Find a window for buffer "buf". - * If found true is returned and "wp" and "tp" are set to the window and tabpage. - * If not found false is returned. - */ +/// Find a window for buffer "buf". +/// If found true is returned and "wp" and "tp" are set to +/// the window and tabpage. +/// If not found, false is returned. +/// +/// @param buf buffer to find a window for +/// @param[out] wp stores the found window +/// @param[out] tp stores the found tabpage +/// +/// @return true if a window was found for the buffer. bool find_win_for_buf(buf_T *buf, win_T **wp, tabpage_T **tp) { *wp = NULL; @@ -5103,50 +5136,54 @@ void set_buflisted(int on) } } -/* - * Read the file for "buf" again and check if the contents changed. - * Return TRUE if it changed or this could not be checked. - */ -int buf_contents_changed(buf_T *buf) +/// Read the file for "buf" again and check if the contents changed. +/// Return true if it changed or this could not be checked. +/// +/// @param buf buffer to check +/// +/// @return true if the buffer's contents have changed +bool buf_contents_changed(buf_T *buf) + FUNC_ATTR_NONNULL_ALL { - buf_T *newbuf; - int differ = TRUE; - linenr_T lnum; - aco_save_T aco; - exarg_T ea; + bool differ = true; - /* Allocate a buffer without putting it in the buffer list. */ - newbuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY); - if (newbuf == NULL) - return TRUE; + // Allocate a buffer without putting it in the buffer list. + buf_T *newbuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY); + if (newbuf == NULL) { + return true; + } - /* Force the 'fileencoding' and 'fileformat' to be equal. */ + // Force the 'fileencoding' and 'fileformat' to be equal. + exarg_T ea; prep_exarg(&ea, buf); - /* set curwin/curbuf to buf and save a few things */ + // set curwin/curbuf to buf and save a few things + aco_save_T aco; aucmd_prepbuf(&aco, newbuf); if (ml_open(curbuf) == OK && readfile(buf->b_ffname, buf->b_fname, - (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, - &ea, READ_NEW | READ_DUMMY) == OK) { - /* compare the two files line by line */ + (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, + &ea, READ_NEW | READ_DUMMY) == OK) { + // compare the two files line by line if (buf->b_ml.ml_line_count == curbuf->b_ml.ml_line_count) { - differ = FALSE; - for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) - if (STRCMP(ml_get_buf(buf, lnum, FALSE), ml_get(lnum)) != 0) { - differ = TRUE; + differ = false; + for (linenr_T lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) { + if (STRCMP(ml_get_buf(buf, lnum, false), ml_get(lnum)) != 0) { + differ = true; break; } + } } } xfree(ea.cmd); - /* restore curwin/curbuf and a few other things */ + // restore curwin/curbuf and a few other things aucmd_restbuf(&aco); - if (curbuf != newbuf) /* safety check */ - wipe_buffer(newbuf, FALSE); + if (curbuf != newbuf) { // safety check + wipe_buffer(newbuf, false); + } return differ; } diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index 936a14b903..c0cd801cd4 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -533,9 +533,9 @@ struct file_buffer { /* * Character table, only used in charset.c for 'iskeyword' - * 32 bytes of 8 bits: 1 bit per character 0-255. + * bitset with 4*64=256 bits: 1 bit per character 0-255. */ - char_u b_chartab[32]; + uint64_t b_chartab[4]; /* Table used for mappings local to a buffer. */ mapblock_T *(b_maphash[256]); @@ -666,19 +666,21 @@ struct file_buffer { long b_p_wm_nopaste; ///< b_p_wm saved for paste mode char_u *b_p_keymap; ///< 'keymap' - /* local values for options which are normally global */ - char_u *b_p_gp; /* 'grepprg' local value */ - char_u *b_p_mp; /* 'makeprg' local value */ - char_u *b_p_efm; /* 'errorformat' local value */ - char_u *b_p_ep; /* 'equalprg' local value */ - char_u *b_p_path; /* 'path' local value */ - int b_p_ar; /* 'autoread' local value */ - char_u *b_p_tags; /* 'tags' local value */ - char_u *b_p_dict; /* 'dictionary' local value */ - char_u *b_p_tsr; /* 'thesaurus' local value */ - long b_p_ul; /* 'undolevels' local value */ - int b_p_udf; /* 'undofile' */ - char_u *b_p_lw; // 'lispwords' local value + // local values for options which are normally global + char_u *b_p_gp; ///< 'grepprg' local value + char_u *b_p_mp; ///< 'makeprg' local value + char_u *b_p_efm; ///< 'errorformat' local value + char_u *b_p_ep; ///< 'equalprg' local value + char_u *b_p_path; ///< 'path' local value + int b_p_ar; ///< 'autoread' local value + char_u *b_p_tags; ///< 'tags' local value + char_u *b_p_tc; ///< 'tagcase' local value + unsigned b_tc_flags; ///< flags for 'tagcase' + char_u *b_p_dict; ///< 'dictionary' local value + char_u *b_p_tsr; ///< 'thesaurus' local value + long b_p_ul; ///< 'undolevels' local value + int b_p_udf; ///< 'undofile' + char_u *b_p_lw; ///< 'lispwords' local value /* end of buffer options */ @@ -816,10 +818,12 @@ struct tabpage_S { was set */ diff_T *tp_first_diff; buf_T *(tp_diffbuf[DB_COUNT]); - int tp_diff_invalid; /* list of diffs is outdated */ - frame_T *(tp_snapshot[SNAP_COUNT]); /* window layout snapshots */ - dictitem_T tp_winvar; /* variable for "t:" Dictionary */ - dict_T *tp_vars; /* internal variables, local to tab page */ + int tp_diff_invalid; ///< list of diffs is outdated */ + frame_T *(tp_snapshot[SNAP_COUNT]); ///< window layout snapshots + dictitem_T tp_winvar; ///< variable for "t:" Dictionary + dict_T *tp_vars; ///< internal variables, local to tab page + char_u *localdir; ///< Absolute path of local directory or + ///< NULL }; /* @@ -953,16 +957,14 @@ struct window_S { time through cursupdate() to the current virtual column */ - /* - * the next six are used to update the visual part - */ - char w_old_visual_mode; /* last known VIsual_mode */ - linenr_T w_old_cursor_lnum; /* last known end of visual part */ - colnr_T w_old_cursor_fcol; /* first column for block visual part */ - colnr_T w_old_cursor_lcol; /* last column for block visual part */ - linenr_T w_old_visual_lnum; /* last known start of visual part */ - colnr_T w_old_visual_col; /* last known start of visual part */ - colnr_T w_old_curswant; /* last known value of Curswant */ + // the next seven are used to update the visual part + char w_old_visual_mode; ///< last known VIsual_mode + linenr_T w_old_cursor_lnum; ///< last known end of visual part + colnr_T w_old_cursor_fcol; ///< first column for block visual part + colnr_T w_old_cursor_lcol; ///< last column for block visual part + linenr_T w_old_visual_lnum; ///< last known start of visual part + colnr_T w_old_visual_col; ///< last known start of visual part + colnr_T w_old_curswant; ///< last known value of Curswant /* * "w_topline", "w_leftcol" and "w_skipcol" specify the offsets for diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 4e329b5cd8..83e2aaa6e6 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -32,16 +32,16 @@ #endif -static int chartab_initialized = FALSE; +static bool chartab_initialized = false; -// b_chartab[] is an array of 32 bytes, each bit representing one of the +// b_chartab[] is an array with 256 bits, each bit representing one of the // characters 0-255. #define SET_CHARTAB(buf, c) \ - (buf)->b_chartab[(unsigned)(c) >> 3] |= (1 << ((c) & 0x7)) + (buf)->b_chartab[(unsigned)(c) >> 6] |= (1ull << ((c) & 0x3f)) #define RESET_CHARTAB(buf, c) \ - (buf)->b_chartab[(unsigned)(c) >> 3] &= ~(1 << ((c) & 0x7)) + (buf)->b_chartab[(unsigned)(c) >> 6] &= ~(1ull << ((c) & 0x3f)) #define GET_CHARTAB(buf, c) \ - ((buf)->b_chartab[(unsigned)(c) >> 3] & (1 << ((c) & 0x7))) + ((buf)->b_chartab[(unsigned)(c) >> 6] & (1ull << ((c) & 0x3f))) /// Fill chartab[]. Also fills curbuf->b_chartab[] with flags for keyword /// characters for current buffer. @@ -69,12 +69,12 @@ static int chartab_initialized = FALSE; /// an error, OK otherwise. int init_chartab(void) { - return buf_init_chartab(curbuf, TRUE); + return buf_init_chartab(curbuf, true); } /// Helper for init_chartab /// -/// @param global FALSE: only set buf->b_chartab[] +/// @param global false: only set buf->b_chartab[] /// /// @return FAIL if 'iskeyword', 'isident', 'isfname' or 'isprint' option has /// an error, OK otherwise. @@ -84,13 +84,13 @@ int buf_init_chartab(buf_T *buf, int global) int c2; char_u *p; int i; - int tilde; - int do_isalpha; + bool tilde; + bool do_isalpha; if (global) { // Set the default size for printable characters: // From <Space> to '~' is 1 (printable), others are 2 (not printable). - // This also inits all 'isident' and 'isfname' flags to FALSE. + // This also inits all 'isident' and 'isfname' flags to false. c = 0; while (c < ' ') { @@ -133,7 +133,7 @@ int buf_init_chartab(buf_T *buf, int global) } } - // Init word char flags all to FALSE + // Init word char flags all to false memset(buf->b_chartab, 0, (size_t)32); if (enc_dbcs != 0) { @@ -169,11 +169,11 @@ int buf_init_chartab(buf_T *buf, int global) } while (*p) { - tilde = FALSE; - do_isalpha = FALSE; + tilde = false; + do_isalpha = false; if ((*p == '^') && (p[1] != NUL)) { - tilde = TRUE; + tilde = true; ++p; } @@ -212,7 +212,7 @@ int buf_init_chartab(buf_T *buf, int global) // standard function isalpha(). This takes care of locale for // single-byte characters). if (c == '@') { - do_isalpha = TRUE; + do_isalpha = true; c = 1; c2 = 255; } else { @@ -231,7 +231,7 @@ int buf_init_chartab(buf_T *buf, int global) if (i == 0) { // (re)set ID flag if (tilde) { - chartab[c] &= ~CT_ID_CHAR; + chartab[c] &= (uint8_t)~CT_ID_CHAR; } else { chartab[c] |= CT_ID_CHAR; } @@ -244,18 +244,18 @@ int buf_init_chartab(buf_T *buf, int global) || (p_altkeymap && (F_isalpha(c) || F_isdigit(c)))) && !(enc_dbcs && (MB_BYTE2LEN(c) == 2))) { if (tilde) { - chartab[c] = (chartab[c] & ~CT_CELL_MASK) - + ((dy_flags & DY_UHEX) ? 4 : 2); - chartab[c] &= ~CT_PRINT_CHAR; + chartab[c] = (uint8_t)((chartab[c] & ~CT_CELL_MASK) + + ((dy_flags & DY_UHEX) ? 4 : 2)); + chartab[c] &= (uint8_t)~CT_PRINT_CHAR; } else { - chartab[c] = (chartab[c] & ~CT_CELL_MASK) + 1; + chartab[c] = (uint8_t)((chartab[c] & ~CT_CELL_MASK) + 1); chartab[c] |= CT_PRINT_CHAR; } } } else if (i == 2) { // (re)set fname flag if (tilde) { - chartab[c] &= ~CT_FNAME_CHAR; + chartab[c] &= (uint8_t)~CT_FNAME_CHAR; } else { chartab[c] |= CT_FNAME_CHAR; } @@ -280,7 +280,7 @@ int buf_init_chartab(buf_T *buf, int global) } } } - chartab_initialized = TRUE; + chartab_initialized = true; return OK; } @@ -333,7 +333,8 @@ char_u *transstr(char_u *s) FUNC_ATTR_NONNULL_RET { char_u *res; char_u *p; - int l, c; + int c; + size_t l; char_u hexbuf[11]; if (has_mbyte) { @@ -343,7 +344,7 @@ char_u *transstr(char_u *s) FUNC_ATTR_NONNULL_RET p = s; while (*p != NUL) { - if ((l = (*mb_ptr2len)(p)) > 1) { + if ((l = (size_t)(*mb_ptr2len)(p)) > 1) { c = (*mb_ptr2char)(p); p += l; @@ -354,7 +355,7 @@ char_u *transstr(char_u *s) FUNC_ATTR_NONNULL_RET len += STRLEN(hexbuf); } } else { - l = byte2cells(*p++); + l = (size_t)byte2cells(*p++); if (l > 0) { len += l; @@ -366,14 +367,14 @@ char_u *transstr(char_u *s) FUNC_ATTR_NONNULL_RET } res = xmallocz(len); } else { - res = xmallocz(vim_strsize(s)); + res = xmallocz((size_t)vim_strsize(s)); } *res = NUL; p = s; while (*p != NUL) { - if (has_mbyte && ((l = (*mb_ptr2len)(p)) > 1)) { + if (has_mbyte && ((l = (size_t)(*mb_ptr2len)(p)) > 1)) { c = (*mb_ptr2char)(p); if (vim_isprintc(c)) { @@ -477,9 +478,9 @@ char_u* str_foldcase(char_u *str, int orglen, char_u *buf, int buflen) i += (*mb_ptr2len)(STR_PTR(i)); } else { if (buf == NULL) { - GA_CHAR(i) = TOLOWER_LOC(GA_CHAR(i)); + GA_CHAR(i) = (char_u)TOLOWER_LOC(GA_CHAR(i)); } else { - buf[i] = TOLOWER_LOC(buf[i]); + buf[i] = (char_u)TOLOWER_LOC(buf[i]); } ++i; } @@ -493,7 +494,7 @@ char_u* str_foldcase(char_u *str, int orglen, char_u *buf, int buflen) // Catch 22: chartab[] can't be initialized before the options are // initialized, and initializing options may cause transchar() to be called! -// When chartab_initialized == FALSE don't use chartab[]. +// When chartab_initialized == false don't use chartab[]. // Does NOT work for multi-byte characters, c must be <= 255. // Also doesn't work for the first byte of a multi-byte, "c" must be a // character! @@ -518,7 +519,7 @@ char_u* transchar(int c) if ((!chartab_initialized && (((c >= ' ') && (c <= '~')) || F_ischar(c))) || ((c < 256) && vim_isprintc_strict(c))) { // printable character - transchar_buf[i] = c; + transchar_buf[i] = (char_u)c; transchar_buf[i + 1] = NUL; } else { transchar_nonprint(transchar_buf + i, c); @@ -564,7 +565,7 @@ void transchar_nonprint(char_u *buf, int c) // 0x00 - 0x1f and 0x7f buf[0] = '^'; // DEL displayed as ^? - buf[1] = c ^ 0x40; + buf[1] = (char_u)(c ^ 0x40); buf[2] = NUL; } else if (enc_utf8 && (c >= 0x80)) { @@ -572,12 +573,12 @@ void transchar_nonprint(char_u *buf, int c) } else if ((c >= ' ' + 0x80) && (c <= '~' + 0x80)) { // 0xa0 - 0xfe buf[0] = '|'; - buf[1] = c - 0x80; + buf[1] = (char_u)(c - 0x80); buf[2] = NUL; } else { // 0x80 - 0x9f and 0xff buf[0] = '~'; - buf[1] = (c - 0x80) ^ 0x40; + buf[1] = (char_u)((c - 0x80) ^ 0x40); buf[2] = NUL; } } @@ -592,11 +593,11 @@ void transchar_hex(char_u *buf, int c) buf[0] = '<'; if (c > 255) { - buf[++i] = nr2hex((unsigned)c >> 12); - buf[++i] = nr2hex((unsigned)c >> 8); + buf[++i] = (char_u)nr2hex((unsigned)c >> 12); + buf[++i] = (char_u)nr2hex((unsigned)c >> 8); } - buf[++i] = nr2hex((unsigned)c >> 4); - buf[++i] = nr2hex((unsigned)c); + buf[++i] = (char_u)(nr2hex((unsigned)c >> 4)); + buf[++i] = (char_u)(nr2hex((unsigned)c)); buf[++i] = '>'; buf[++i] = NUL; } @@ -734,9 +735,8 @@ int vim_strnsize(char_u *s, int len) /// @return Number of characters. #define RET_WIN_BUF_CHARTABSIZE(wp, buf, p, col) \ if (*(p) == TAB && (!(wp)->w_p_list || lcs_tab1)) { \ - int ts; \ - ts = (buf)->b_p_ts; \ - return (int)(ts - (col % ts)); \ + const int ts = (int) (buf)->b_p_ts; \ + return (ts - (int)(col % ts)); \ } else { \ return ptr2cells(p); \ } @@ -1137,7 +1137,7 @@ static int win_nolbr_chartabsize(win_T *wp, char_u *s, colnr_T col, int *headp) int n; if ((*s == TAB) && (!wp->w_p_list || lcs_tab1)) { - n = wp->w_buffer->b_p_ts; + n = (int)wp->w_buffer->b_p_ts; return n - (col % n); } n = ptr2cells(s); @@ -1205,11 +1205,11 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, char_u *line; // start of the line int incr; int head; - int ts = wp->w_buffer->b_p_ts; + int ts = (int)wp->w_buffer->b_p_ts; int c; vcol = 0; - line = ptr = ml_get_buf(wp->w_buffer, pos->lnum, FALSE); + line = ptr = ml_get_buf(wp->w_buffer, pos->lnum, false); if (pos->col == MAXCOL) { // continue until the NUL @@ -1329,7 +1329,7 @@ colnr_T getvcol_nolist(pos_T *posp) int list_save = curwin->w_p_list; colnr_T vcol; - curwin->w_p_list = FALSE; + curwin->w_p_list = false; getvcol(curwin, posp, NULL, &vcol, NULL); curwin->w_p_list = list_save; return vcol; @@ -1358,7 +1358,7 @@ void getvvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, endadd = 0; // Cannot put the cursor on part of a wide character. - ptr = ml_get_buf(wp->w_buffer, pos->lnum, FALSE); + ptr = ml_get_buf(wp->w_buffer, pos->lnum, false); if (pos->col < (colnr_T)STRLEN(ptr)) { int c = (*mb_ptr2char)(ptr + pos->col); @@ -1595,7 +1595,7 @@ bool vim_islower(int c) if (c >= 0x100) { if (has_mbyte) { - return iswlower(c); + return iswlower((wint_t)c); } // islower() can't handle these chars and may crash @@ -1626,7 +1626,7 @@ bool vim_isupper(int c) if (c >= 0x100) { if (has_mbyte) { - return iswupper(c); + return iswupper((wint_t)c); } // isupper() can't handle these chars and may crash @@ -1653,7 +1653,7 @@ int vim_toupper(int c) if (c >= 0x100) { if (has_mbyte) { - return towupper(c); + return (int)towupper((wint_t)c); } // toupper() can't handle these chars and may crash @@ -1680,7 +1680,7 @@ int vim_tolower(int c) if (c >= 0x100) { if (has_mbyte) { - return towlower(c); + return (int)towlower((wint_t)c); } // tolower() can't handle these chars and may crash diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 0be8b3c514..4826e70727 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -29,7 +29,6 @@ #include "nvim/path.h" #include "nvim/screen.h" #include "nvim/strings.h" -#include "nvim/tempfile.h" #include "nvim/undo.h" #include "nvim/window.h" #include "nvim/os/os.h" @@ -658,9 +657,9 @@ void ex_diffupdate(exarg_T *eap) } // We need three temp file names. - char_u *tmp_orig = vim_tempname(); - char_u *tmp_new = vim_tempname(); - char_u *tmp_diff = vim_tempname(); + char *tmp_orig = (char *) vim_tempname(); + char *tmp_new = (char *) vim_tempname(); + char *tmp_diff = (char *) vim_tempname(); if ((tmp_orig == NULL) || (tmp_new == NULL) || (tmp_diff == NULL)) { goto theend; @@ -670,11 +669,11 @@ void ex_diffupdate(exarg_T *eap) // are no differences. Can't use the return value, it's non-zero when // there are differences. // May try twice, first with "-a" and then without. - int io_error = FALSE; - int ok = FALSE; + int io_error = false; + bool ok = false; for (;;) { - ok = FALSE; - FILE *fd = mch_fopen((char *)tmp_orig, "w"); + ok = false; + FILE *fd = mch_fopen(tmp_orig, "w"); if (fd == NULL) { io_error = TRUE; @@ -683,7 +682,7 @@ void ex_diffupdate(exarg_T *eap) io_error = TRUE; } fclose(fd); - fd = mch_fopen((char *)tmp_new, "w"); + fd = mch_fopen(tmp_new, "w"); if (fd == NULL) { io_error = TRUE; @@ -693,7 +692,7 @@ void ex_diffupdate(exarg_T *eap) } fclose(fd); diff_file(tmp_orig, tmp_new, tmp_diff); - fd = mch_fopen((char *)tmp_diff, "r"); + fd = mch_fopen(tmp_diff, "r"); if (fd == NULL) { io_error = TRUE; @@ -712,10 +711,10 @@ void ex_diffupdate(exarg_T *eap) } fclose(fd); } - os_remove((char *)tmp_diff); - os_remove((char *)tmp_new); + os_remove(tmp_diff); + os_remove(tmp_new); } - os_remove((char *)tmp_orig); + os_remove(tmp_orig); } // When using 'diffexpr' break here. @@ -756,7 +755,7 @@ void ex_diffupdate(exarg_T *eap) // Write the first buffer to a tempfile. buf_T *buf = curtab->tp_diffbuf[idx_orig]; - if (diff_write(buf, tmp_orig) == FAIL) { + if (diff_write(buf, (char_u *) tmp_orig) == FAIL) { goto theend; } @@ -767,17 +766,17 @@ void ex_diffupdate(exarg_T *eap) continue; // skip buffer that isn't loaded } - if (diff_write(buf, tmp_new) == FAIL) { + if (diff_write(buf, (char_u *) tmp_new) == FAIL) { continue; } diff_file(tmp_orig, tmp_new, tmp_diff); // Read the diff output and add each entry to the diff list. - diff_read(idx_orig, idx_new, tmp_diff); - os_remove((char *)tmp_diff); - os_remove((char *)tmp_new); + diff_read(idx_orig, idx_new, (char_u *) tmp_diff); + os_remove(tmp_diff); + os_remove(tmp_new); } - os_remove((char *)tmp_orig); + os_remove(tmp_orig); // force updating cursor position on screen curwin->w_valid_cursor.lnum = 0; @@ -795,15 +794,16 @@ theend: /// @param tmp_orig /// @param tmp_new /// @param tmp_diff -static void diff_file(char_u *tmp_orig, char_u *tmp_new, char_u *tmp_diff) +static void diff_file(const char *const tmp_orig, const char *const tmp_new, + const char *const tmp_diff) { if (*p_dex != NUL) { // Use 'diffexpr' to generate the diff file. eval_diff(tmp_orig, tmp_new, tmp_diff); } else { - size_t len = STRLEN(tmp_orig) + STRLEN(tmp_new) + STRLEN(tmp_diff) - + STRLEN(p_srr) + 27; - char_u *cmd = xmalloc(len); + const size_t len = (strlen(tmp_orig) + strlen(tmp_new) + strlen(tmp_diff) + + STRLEN(p_srr) + 27); + char *const cmd = xmalloc(len); /* We don't want $DIFF_OPTIONS to get in the way. */ if (os_getenv("DIFF_OPTIONS")) { @@ -813,19 +813,17 @@ static void diff_file(char_u *tmp_orig, char_u *tmp_new, char_u *tmp_diff) /* Build the diff command and execute it. Always use -a, binary * differences are of no use. Ignore errors, diff returns * non-zero when differences have been found. */ - vim_snprintf((char *)cmd, len, "diff %s%s%s%s%s %s", - diff_a_works == FALSE ? "" : "-a ", + vim_snprintf(cmd, len, "diff %s%s%s%s%s %s", + diff_a_works ? "-a " : "", "", (diff_flags & DIFF_IWHITE) ? "-b " : "", (diff_flags & DIFF_ICASE) ? "-i " : "", tmp_orig, tmp_new); - append_redir(cmd, (int)len, p_srr, tmp_diff); - block_autocmds(); /* Avoid ShellCmdPost stuff */ - (void)call_shell( - cmd, - kShellOptFilter | kShellOptSilent | kShellOptDoOut, - NULL - ); + append_redir(cmd, len, (char *) p_srr, tmp_diff); + block_autocmds(); // Avoid ShellCmdPost stuff + (void)call_shell((char_u *) cmd, + kShellOptFilter | kShellOptSilent | kShellOptDoOut, + NULL); unblock_autocmds(); xfree(cmd); } @@ -902,9 +900,11 @@ void ex_diffpatch(exarg_T *eap) if (*p_pex != NUL) { // Use 'patchexpr' to generate the new file. #ifdef UNIX - eval_patch(tmp_orig, fullname != NULL ? fullname : eap->arg, tmp_new); + eval_patch((char *) tmp_orig, + (char *) (fullname != NULL ? fullname : eap->arg), + (char *) tmp_new); #else - eval_patch(tmp_orig, eap->arg, tmp_new); + eval_patch((char *) tmp_orig, (char *) eap->arg, (char *) tmp_new); #endif // ifdef UNIX } else { // Build the patch command and execute it. Ignore errors. Switch to diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 6313ea2e81..667ce1e779 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -165,10 +165,6 @@ static int compl_restarting = FALSE; /* don't insert match */ * FALSE the word to be completed must be located. */ static int compl_started = FALSE; -/* Set when doing something for completion that may call edit() recursively, - * which is not allowed. */ -static int compl_busy = FALSE; - static int compl_matches = 0; static char_u *compl_pattern = NULL; static int compl_direction = FORWARD; @@ -203,7 +199,7 @@ typedef struct insert_state { int did_restart_edit; // remember if insert mode was restarted // after a ctrl+o bool nomove; - uint8_t *ptr; + char_u *ptr; } InsertState; @@ -274,8 +270,8 @@ static void insert_enter(InsertState *s) s->ptr = (char_u *)"i"; } - set_vim_var_string(VV_INSERTMODE, s->ptr, 1); - set_vim_var_string(VV_CHAR, NULL, -1); /* clear v:char */ + set_vim_var_string(VV_INSERTMODE, (char *) s->ptr, 1); + set_vim_var_string(VV_CHAR, NULL, -1); apply_autocmds(EVENT_INSERTENTER, NULL, NULL, false, curbuf); // Make sure the cursor didn't move. Do call check_cursor_col() in @@ -887,7 +883,7 @@ static int insert_handle_key(InsertState *s) case Ctrl_T: // Make indent one shiftwidth greater. if (s->c == Ctrl_T && ctrl_x_mode == CTRL_X_THESAURUS) { - if (has_compl_option(false)) { + if (check_compl_option(false)) { insert_do_complete(s); } break; @@ -1102,7 +1098,7 @@ static int insert_handle_key(InsertState *s) case Ctrl_K: // digraph or keyword completion if (ctrl_x_mode == CTRL_X_DICTIONARY) { - if (has_compl_option(true)) { + if (check_compl_option(true)) { insert_do_complete(s); } break; @@ -1264,30 +1260,28 @@ static void insert_do_cindent(InsertState *s) } } -/* - * edit(): Start inserting text. - * - * "cmdchar" can be: - * 'i' normal insert command - * 'a' normal append command - * 'R' replace command - * 'r' "r<CR>" command: insert one <CR>. Note: count can be > 1, for redo, - * but still only one <CR> is inserted. The <Esc> is not used for redo. - * 'g' "gI" command. - * 'V' "gR" command for Virtual Replace mode. - * 'v' "gr" command for single character Virtual Replace mode. - * - * This function is not called recursively. For CTRL-O commands, it returns - * and lets the caller handle the Normal-mode command. - * - * Return TRUE if a CTRL-O command caused the return (insert mode pending). - */ -int -edit ( - int cmdchar, - int startln, /* if set, insert at start of line */ - long count -) +/// edit(): Start inserting text. +/// +/// "cmdchar" can be: +/// 'i' normal insert command +/// 'a' normal append command +/// 'R' replace command +/// 'r' "r<CR>" command: insert one <CR>. +/// Note: count can be > 1, for redo, but still only one <CR> is inserted. +/// <Esc> is not used for redo. +/// 'g' "gI" command. +/// 'V' "gR" command for Virtual Replace mode. +/// 'v' "gr" command for single character Virtual Replace mode. +/// +/// This function is not called recursively. For CTRL-O commands, it returns +/// and lets the caller handle the Normal-mode command. +/// +/// @param cmdchar command that started the insert +/// @param startln if true, insert at start of line +/// @param count repeat count for the command +/// +/// @return true if a CTRL-O command caused the return (insert mode pending). +bool edit(int cmdchar, bool startln, long count) { if (curbuf->terminal) { if (ex_normal_busy) { @@ -1795,33 +1789,37 @@ void backspace_until_column(int col) } } -/* - * Like del_char(), but make sure not to go before column "limit_col". - * Only matters when there are composing characters. - * Return TRUE when something was deleted. - */ -static int del_char_after_col(int limit_col) +/// Like del_char(), but make sure not to go before column "limit_col". +/// Only matters when there are composing characters. +/// +/// @param limit_col only delete the character if it is after this column +// +/// @return true when something was deleted. +static bool del_char_after_col(int limit_col) { if (enc_utf8 && limit_col >= 0) { colnr_T ecol = curwin->w_cursor.col + 1; - /* Make sure the cursor is at the start of a character, but - * skip forward again when going too far back because of a - * composing character. */ + // Make sure the cursor is at the start of a character, but + // skip forward again when going too far back because of a + // composing character. mb_adjust_cursor(); while (curwin->w_cursor.col < (colnr_T)limit_col) { int l = utf_ptr2len(get_cursor_pos_ptr()); - if (l == 0) /* end of line */ + if (l == 0) { // end of line break; + } curwin->w_cursor.col += l; } - if (*get_cursor_pos_ptr() == NUL || curwin->w_cursor.col == ecol) - return FALSE; - del_bytes((long)((int)ecol - curwin->w_cursor.col), FALSE, TRUE); - } else - (void)del_char(FALSE); - return TRUE; + if (*get_cursor_pos_ptr() == NUL || curwin->w_cursor.col == ecol) { + return false; + } + del_bytes(ecol - curwin->w_cursor.col, false, true); + } else { + del_char(false); + } + return true; } /* @@ -1846,47 +1844,48 @@ static void ins_ctrl_x(void) } } -/* - * Return TRUE if the 'dict' or 'tsr' option can be used. - */ -static int has_compl_option(int dict_opt) +/// Check that the "dict" or "tsr" option can be used. +/// +/// @param dict_opt check "dict" when true, "tsr" when false. +static bool check_compl_option(bool dict_opt) { - if (dict_opt ? (*curbuf->b_p_dict == NUL && *p_dict == NUL - && !curwin->w_p_spell - ) + if (dict_opt + ? (*curbuf->b_p_dict == NUL && *p_dict == NUL && !curwin->w_p_spell) : (*curbuf->b_p_tsr == NUL && *p_tsr == NUL)) { ctrl_x_mode = 0; edit_submode = NULL; msg_attr(dict_opt ? (char_u *)_("'dictionary' option is empty") - : (char_u *)_("'thesaurus' option is empty"), - hl_attr(HLF_E)); + : (char_u *)_("'thesaurus' option is empty"), hl_attr(HLF_E)); if (emsg_silent == 0) { vim_beep(BO_COMPL); setcursor(); ui_flush(); os_delay(2000L, false); } - return FALSE; + return false; } - return TRUE; + return true; } -/* - * Is the character 'c' a valid key to go to or keep us in CTRL-X mode? - * This depends on the current mode. - */ -int vim_is_ctrl_x_key(int c) +/// Check that the character "c" a valid key to go to or keep us in CTRL-X mode? +/// This depends on the current mode. +/// +/// @param c character to check +bool vim_is_ctrl_x_key(int c) + FUNC_ATTR_WARN_UNUSED_RESULT { - /* Always allow ^R - let it's results then be checked */ - if (c == Ctrl_R) - return TRUE; + // Always allow ^R - let its results then be checked + if (c == Ctrl_R) { + return true; + } - /* Accept <PageUp> and <PageDown> if the popup menu is visible. */ - if (ins_compl_pum_key(c)) - return TRUE; + // Accept <PageUp> and <PageDown> if the popup menu is visible. + if (ins_compl_pum_key(c)) { + return true; + } switch (ctrl_x_mode) { - case 0: /* Not in any CTRL-X mode */ + case 0: // Not in any CTRL-X mode return c == Ctrl_N || c == Ctrl_P || c == Ctrl_X; case CTRL_X_NOT_DEFINED_YET: return c == Ctrl_X || c == Ctrl_Y || c == Ctrl_E @@ -1924,35 +1923,37 @@ int vim_is_ctrl_x_key(int c) return (c == Ctrl_P || c == Ctrl_N); } EMSG(_(e_internal)); - return FALSE; + return false; } -/* - * Return TRUE when character "c" is part of the item currently being - * completed. Used to decide whether to abandon complete mode when the menu - * is visible. - */ -static int ins_compl_accept_char(int c) +/// Check that character "c" is part of the item currently being +/// completed. Used to decide whether to abandon complete mode when the menu +/// is visible. +/// +/// @param c character to check +static bool ins_compl_accept_char(int c) + FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { - if (ctrl_x_mode & CTRL_X_WANT_IDENT) - /* When expanding an identifier only accept identifier chars. */ + if (ctrl_x_mode & CTRL_X_WANT_IDENT) { + // When expanding an identifier only accept identifier chars. return vim_isIDc(c); + } switch (ctrl_x_mode) { case CTRL_X_FILES: - /* When expanding file name only accept file name chars. But not - * path separators, so that "proto/<Tab>" expands files in - * "proto", not "proto/" as a whole */ + // When expanding file name only accept file name chars. But not + // path separators, so that "proto/<Tab>" expands files in + // "proto", not "proto/" as a whole return vim_isfilec(c) && !vim_ispathsep(c); case CTRL_X_CMDLINE: case CTRL_X_OMNI: - /* Command line and Omni completion can work with just about any - * printable character, but do stop at white space. */ + // Command line and Omni completion can work with just about any + // printable character, but do stop at white space. return vim_isprintc(c) && !ascii_iswhite(c); case CTRL_X_WHOLE_LINE: - /* For while line completion a space can be part of the line. */ + // For while line completion a space can be part of the line. return vim_isprintc(c); } return vim_iswordc(c); @@ -2197,15 +2198,19 @@ ins_compl_add ( return OK; } -/* - * Return TRUE if "str[len]" matches with match->cp_str, considering - * match->cp_icase. - */ -static int ins_compl_equal(compl_T *match, char_u *str, int len) +/// Check that "str[len]" matches with "match->cp_str", considering +/// "match->cp_icase". +/// +/// @param match completion match +/// @param str character string to check +/// @param len lenth of "str" +static bool ins_compl_equal(compl_T *match, char_u *str, size_t len) + FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { - if (match->cp_icase) - return STRNICMP(match->cp_str, str, (size_t)len) == 0; - return STRNCMP(match->cp_str, str, (size_t)len) == 0; + if (match->cp_icase) { + return STRNICMP(match->cp_str, str, len) == 0; + } + return STRNCMP(match->cp_str, str, len) == 0; } /* @@ -2353,13 +2358,13 @@ void set_completion(colnr_T startcol, list_T *list) int save_w_wrow = curwin->w_wrow; compl_curr_match = compl_first_match; - if (compl_no_insert) { + if (compl_no_insert || compl_no_select) { ins_complete(K_DOWN, false); - } else { - ins_complete(Ctrl_N, false); if (compl_no_select) { - ins_complete(Ctrl_P, false); + ins_complete(K_UP, false); } + } else { + ins_complete(Ctrl_N, false); } // Lazily show the popup menu, unless we got interrupted. @@ -2403,44 +2408,33 @@ static void ins_compl_del_pum(void) } } -/* - * Return TRUE if the popup menu should be displayed. - */ -static int pum_wanted(void) +/// Check if the popup menu should be displayed. +static bool pum_wanted(void) + FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { - /* 'completeopt' must contain "menu" or "menuone" */ - if (vim_strchr(p_cot, 'm') == NULL) - return FALSE; - - /* The display looks bad on a B&W display. */ - if (t_colors < 8 - ) - return FALSE; - return TRUE; + // "completeopt" must contain "menu" or "menuone" + return vim_strchr(p_cot, 'm') != NULL; } -/* - * Return TRUE if there are two or more matches to be shown in the popup menu. - * One if 'completopt' contains "menuone". - */ -static int pum_enough_matches(void) +/// Check that there are two or more matches to be shown in the popup menu. +/// One if "completopt" contains "menuone". +static bool pum_enough_matches(void) + FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { - compl_T *compl; - int i; - - /* Don't display the popup menu if there are no matches or there is only - * one (ignoring the original text). */ - compl = compl_first_match; - i = 0; + // Don't display the popup menu if there are no matches or there is only + // one (ignoring the original text). + compl_T *comp = compl_first_match; + int i = 0; do { - if (compl == NULL - || ((compl->cp_flags & ORIGINAL_TEXT) == 0 && ++i == 2)) + if (comp == NULL || ((comp->cp_flags & ORIGINAL_TEXT) == 0 && ++i == 2)) { break; - compl = compl->cp_next; - } while (compl != compl_first_match); + } + comp = comp->cp_next; + } while (comp != compl_first_match); - if (strstr((char *)p_cot, "menuone") != NULL) + if (strstr((char *)p_cot, "menuone") != NULL) { return i >= 1; + } return i >= 2; } @@ -2871,10 +2865,9 @@ static void ins_compl_clear(void) set_vim_var_dict(VV_COMPLETED_ITEM, dict_alloc()); } -/* - * Return TRUE when Insert completion is active. - */ -int ins_compl_active(void) +/// Check that Insert completion is active. +bool ins_compl_active(void) + FUNC_ATTR_PURE { return compl_started; } @@ -2918,14 +2911,13 @@ static int ins_compl_bs(void) return NUL; } -/* - * Return TRUE when we need to find matches again, ins_compl_restart() is to - * be called. - */ -static int ins_compl_need_restart(void) +/// Check that we need to find matches again, ins_compl_restart() is to +/// be called. +static bool ins_compl_need_restart(void) + FUNC_ATTR_PURE { - /* Return TRUE if we didn't complete finding matches or when the - * 'completefunc' returned "always" in the "refresh" dictionary item. */ + // Return true if we didn't complete finding matches or when the + // "completefunc" returned "always" in the "refresh" dictionary item. return compl_was_interrupted || ((ctrl_x_mode == CTRL_X_FUNCTION || ctrl_x_mode == CTRL_X_OMNI) && compl_opt_refresh_always); @@ -3073,16 +3065,16 @@ static void ins_compl_addfrommatch(void) ins_compl_addleader(c); } -/* - * Prepare for Insert mode completion, or stop it. - * Called just after typing a character in Insert mode. - * Returns TRUE when the character is not to be inserted; - */ -static int ins_compl_prep(int c) +/// Prepare for Insert mode completion, or stop it. +/// Called just after typing a character in Insert mode. +/// +/// @param c character that was typed +/// +/// @return true when the character is not to be inserted; +static bool ins_compl_prep(int c) { - char_u *ptr; - int want_cindent; - int retval = FALSE; + char_u *ptr; + bool retval = false; /* Forget any previous 'special' messages if this is actually * a ^X mode key - bar ^R, in which case we wait to see what it gives us. @@ -3092,8 +3084,10 @@ static int ins_compl_prep(int c) /* Ignore end of Select mode mapping and mouse scroll buttons. */ if (c == K_SELECT || c == K_MOUSEDOWN || c == K_MOUSEUP - || c == K_MOUSELEFT || c == K_MOUSERIGHT) + || c == K_MOUSELEFT || c == K_MOUSERIGHT || c == K_EVENT + || c == K_FOCUSGAINED || c == K_FOCUSLOST) { return retval; + } /* Set "compl_get_longest" when finding the first matches. */ if (ctrl_x_mode == CTRL_X_NOT_DEFINED_YET @@ -3247,11 +3241,9 @@ static int ins_compl_prep(int c) ins_compl_fixRedoBufForLeader(ptr); } - want_cindent = (can_cindent && cindent_on()); - /* - * When completing whole lines: fix indent for 'cindent'. - * Otherwise, break line if it's too long. - */ + bool want_cindent = (can_cindent && cindent_on()); + // When completing whole lines: fix indent for 'cindent'. + // Otherwise, break line if it's too long. if (compl_cont_mode == CTRL_X_WHOLE_LINE) { /* re-indent the current line */ if (want_cindent) { @@ -3271,22 +3263,24 @@ static int ins_compl_prep(int c) inc_cursor(); } - /* If the popup menu is displayed pressing CTRL-Y means accepting - * the selection without inserting anything. When - * compl_enter_selects is set the Enter key does the same. */ + // If the popup menu is displayed pressing CTRL-Y means accepting + // the selection without inserting anything. When + // compl_enter_selects is set the Enter key does the same. if ((c == Ctrl_Y || (compl_enter_selects && (c == CAR || c == K_KENTER || c == NL))) - && pum_visible()) - retval = TRUE; + && pum_visible()) { + retval = true; + } /* CTRL-E means completion is Ended, go back to the typed text. */ if (c == Ctrl_E) { ins_compl_delete(); - if (compl_leader != NULL) + if (compl_leader != NULL) { ins_bytes(compl_leader + ins_compl_len()); - else if (compl_first_match != NULL) + } else if (compl_first_match != NULL) { ins_bytes(compl_orig_text + ins_compl_len()); - retval = TRUE; + } + retval = true; } auto_format(FALSE, TRUE); @@ -4245,22 +4239,22 @@ void ins_compl_check_keys(int frequency) static int ins_compl_key2dir(int c) { if (c == Ctrl_P || c == Ctrl_L - || (pum_visible() && (c == K_PAGEUP || c == K_KPAGEUP - || c == K_S_UP || c == K_UP))) + || c == K_PAGEUP || c == K_KPAGEUP + || c == K_S_UP || c == K_UP) { return BACKWARD; + } return FORWARD; } -/* - * Return TRUE for keys that are used for completion only when the popup menu - * is visible. - */ -static int ins_compl_pum_key(int c) +/// Check that "c" is a valid completion key only while the popup menu is shown +/// +/// @param c character to check +static bool ins_compl_pum_key(int c) + FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { return pum_visible() && (c == K_PAGEUP || c == K_KPAGEUP || c == K_S_UP - || c == K_PAGEDOWN || c == K_KPAGEDOWN || c == - K_S_DOWN - || c == K_UP || c == K_DOWN); + || c == K_PAGEDOWN || c == K_KPAGEDOWN + || c == K_S_DOWN || c == K_UP || c == K_DOWN); } /* @@ -4280,11 +4274,12 @@ static int ins_compl_key2count(int c) return 1; } -/* - * Return TRUE if completion with "c" should insert the match, FALSE if only - * to change the currently selected completion. - */ -static int ins_compl_use_match(int c) +/// Check that completion with "c" should insert the match, false if only +/// to change the currently selected completion. +/// +/// @param c character to check +static bool ins_compl_use_match(int c) + FUNC_ATTR_CONST FUNC_ATTR_WARN_UNUSED_RESULT { switch (c) { case K_UP: @@ -4295,9 +4290,9 @@ static int ins_compl_use_match(int c) case K_PAGEUP: case K_KPAGEUP: case K_S_UP: - return FALSE; + return false; } - return TRUE; + return true; } /* @@ -6313,18 +6308,22 @@ char_u *get_last_insert_save(void) return s; } -/* - * Check the word in front of the cursor for an abbreviation. - * Called when the non-id character "c" has been entered. - * When an abbreviation is recognized it is removed from the text and - * the replacement string is inserted in typebuf.tb_buf[], followed by "c". - */ -static int echeck_abbr(int c) +/// Check the word in front of the cursor for an abbreviation. +/// Called when the non-id character "c" has been entered. +/// When an abbreviation is recognized it is removed from the text and +/// the replacement string is inserted in typebuf.tb_buf[], followed by "c". +/// +/// @param c character +/// +/// @return true if the word is a known abbreviation. +static bool echeck_abbr(int c) + FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { - /* Don't check for abbreviation in paste mode, when disabled and just - * after moving around with cursor keys. */ - if (p_paste || no_abbr || arrow_used) - return FALSE; + // Don't check for abbreviation in paste mode, when disabled and just + // after moving around with cursor keys. + if (p_paste || no_abbr || arrow_used) { + return false; + } return check_abbr(c, get_cursor_line_ptr(), curwin->w_cursor.col, curwin->w_cursor.lnum == Insstart.lnum ? Insstart.col : 0); @@ -6560,13 +6559,11 @@ static void replace_do_bs(int limit_col) (void)del_char_after_col(limit_col); } -/* - * Return TRUE if C-indenting is on. - */ -static int cindent_on(void) { - return !p_paste && (curbuf->b_p_cin - || *curbuf->b_p_inde != NUL - ); +/// Check that C-indenting is on. +static bool cindent_on(void) + FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT +{ + return !p_paste && (curbuf->b_p_cin || *curbuf->b_p_inde != NUL); } /* @@ -6596,32 +6593,33 @@ void fix_indent(void) { do_c_expr_indent(); } -/* - * return TRUE if 'cinkeys' contains the key "keytyped", - * when == '*': Only if key is preceded with '*' (indent before insert) - * when == '!': Only if key is preceded with '!' (don't insert) - * when == ' ': Only if key is not preceded with '*'(indent afterwards) - * - * "keytyped" can have a few special values: - * KEY_OPEN_FORW - * KEY_OPEN_BACK - * KEY_COMPLETE just finished completion. - * - * If line_is_empty is TRUE accept keys with '0' before them. - */ -int in_cinkeys(int keytyped, int when, int line_is_empty) +/// Check that "cinkeys" contains the key "keytyped", +/// when == '*': Only if key is preceded with '*' (indent before insert) +/// when == '!': Only if key is preceded with '!' (don't insert) +/// when == ' ': Only if key is not preceded with '*' (indent afterwards) +/// +/// "keytyped" can have a few special values: +/// KEY_OPEN_FORW : +/// KEY_OPEN_BACK : +/// KEY_COMPLETE : Just finished completion. +/// +/// @param keytyped key that was typed +/// @param when condition on when to perform the check +/// @param line_is_empty when true, accept keys with '0' before them. +bool in_cinkeys(int keytyped, int when, bool line_is_empty) { - char_u *look; + char_u *look; int try_match; int try_match_word; - char_u *p; - char_u *line; + char_u *p; + char_u *line; int icase; int i; - if (keytyped == NUL) - /* Can happen with CTRL-Y and CTRL-E on a short line. */ - return FALSE; + if (keytyped == NUL) { + // Can happen with CTRL-Y and CTRL-E on a short line. + return false; + } if (*curbuf->b_p_inde != NUL) look = curbuf->b_p_indk; /* 'indentexpr' set: use 'indentkeys' */ @@ -6637,68 +6635,64 @@ int in_cinkeys(int keytyped, int when, int line_is_empty) case '!': try_match = (*look == '!'); break; default: try_match = (*look != '*'); break; } - if (*look == '*' || *look == '!') - ++look; + if (*look == '*' || *look == '!') { + look++; + } - /* - * If there is a '0', only accept a match if the line is empty. - * But may still match when typing last char of a word. - */ + // If there is a '0', only accept a match if the line is empty. + // But may still match when typing last char of a word. if (*look == '0') { try_match_word = try_match; - if (!line_is_empty) - try_match = FALSE; - ++look; - } else - try_match_word = FALSE; + if (!line_is_empty) { + try_match = false; + } + look++; + } else { + try_match_word = false; + } - /* - * does it look like a control character? - */ - if (*look == '^' - && look[1] >= '?' && look[1] <= '_' - ) { - if (try_match && keytyped == Ctrl_chr(look[1])) - return TRUE; + // Does it look like a control character? + if (*look == '^' && look[1] >= '?' && look[1] <= '_') { + if (try_match && keytyped == Ctrl_chr(look[1])) { + return true; + } look += 2; - } - /* - * 'o' means "o" command, open forward. - * 'O' means "O" command, open backward. - */ - else if (*look == 'o') { - if (try_match && keytyped == KEY_OPEN_FORW) - return TRUE; - ++look; + + // 'o' means "o" command, open forward. + // 'O' means "O" command, open backward. + } else if (*look == 'o') { + if (try_match && keytyped == KEY_OPEN_FORW) { + return true; + } + look++; } else if (*look == 'O') { - if (try_match && keytyped == KEY_OPEN_BACK) - return TRUE; - ++look; - } - /* - * 'e' means to check for "else" at start of line and just before the - * cursor. - */ - else if (*look == 'e') { + if (try_match && keytyped == KEY_OPEN_BACK) { + return true; + } + look++; + + // 'e' means to check for "else" at start of line and just before the + // cursor. + } else if (*look == 'e') { if (try_match && keytyped == 'e' && curwin->w_cursor.col >= 4) { p = get_cursor_line_ptr(); if (skipwhite(p) == p + curwin->w_cursor.col - 4 && - STRNCMP(p + curwin->w_cursor.col - 4, "else", 4) == 0) - return TRUE; + STRNCMP(p + curwin->w_cursor.col - 4, "else", 4) == 0) { + return true; + } } - ++look; - } - /* - * ':' only causes an indent if it is at the end of a label or case - * statement, or when it was before typing the ':' (to fix - * class::method for C++). - */ - else if (*look == ':') { + look++; + + // ':' only causes an indent if it is at the end of a label or case + // statement, or when it was before typing the ':' (to fix + // class::method for C++). + } else if (*look == ':') { if (try_match && keytyped == ':') { p = get_cursor_line_ptr(); - if (cin_iscase(p, FALSE) || cin_isscopedecl(p) || cin_islabel()) - return TRUE; - /* Need to get the line again after cin_islabel(). */ + if (cin_iscase(p, false) || cin_isscopedecl(p) || cin_islabel()) { + return true; + } + // Need to get the line again after cin_islabel(). p = get_cursor_line_ptr(); if (curwin->w_cursor.col > 2 && p[curwin->w_cursor.col - 1] == ':' @@ -6708,28 +6702,27 @@ int in_cinkeys(int keytyped, int when, int line_is_empty) || cin_islabel()); p = get_cursor_line_ptr(); p[curwin->w_cursor.col - 1] = ':'; - if (i) - return TRUE; + if (i) { + return true; + } } } - ++look; - } - /* - * Is it a key in <>, maybe? - */ - else if (*look == '<') { + look++; + + // Is it a key in <>, maybe? + } else if (*look == '<') { if (try_match) { - /* - * make up some named keys <o>, <O>, <e>, <0>, <>>, <<>, <*>, - * <:> and <!> so that people can re-indent on o, O, e, 0, <, - * >, *, : and ! keys if they really really want to. - */ + // make up some named keys <o>, <O>, <e>, <0>, <>>, <<>, <*>, + // <:> and <!> so that people can re-indent on o, O, e, 0, <, + // >, *, : and ! keys if they really really want to. if (vim_strchr((char_u *)"<>!*oOe0:", look[1]) != NULL - && keytyped == look[1]) - return TRUE; + && keytyped == look[1]) { + return true; + } - if (keytyped == get_special_key_code(look + 1)) - return TRUE; + if (keytyped == get_special_key_code(look + 1)) { + return true; + } } while (*look && *look != '>') look++; @@ -6800,18 +6793,18 @@ int in_cinkeys(int keytyped, int when, int line_is_empty) (int)(curwin->w_cursor.col - (p - look))) match = FALSE; } - if (match) - return TRUE; + if (match) { + return true; + } } look = p; - } - /* - * ok, it's a boring generic character. - */ - else { - if (try_match && *look == keytyped) - return TRUE; - ++look; + + // Ok, it's a boring generic character. + } else { + if (try_match && *look == keytyped) { + return true; + } + look++; } /* @@ -6819,7 +6812,7 @@ int in_cinkeys(int keytyped, int when, int line_is_empty) */ look = skip_to_option_part(look); } - return FALSE; + return false; } /* @@ -7046,27 +7039,24 @@ static void ins_ctrl_hat(void) status_redraw_curbuf(); } -/* - * Handle ESC in insert mode. - * Returns TRUE when leaving insert mode, FALSE when going to repeat the - * insert. - */ -static int -ins_esc ( - long *count, - int cmdchar, - int nomove /* don't move cursor */ -) +/// Handle ESC in insert mode. +/// +/// @param[in,out] count repeat count of the insert command +/// @param cmdchar command that started the insert +/// @param nomove when true, don't move the cursor +/// +/// @return true when leaving insert mode, false when repeating the insert. +static bool ins_esc(long *count, int cmdchar, bool nomove) + FUNC_ATTR_NONNULL_ARG(1) { - int temp; - static int disabled_redraw = FALSE; + static bool disabled_redraw = false; check_spell_redraw(); - temp = curwin->w_cursor.col; + int temp = curwin->w_cursor.col; if (disabled_redraw) { - --RedrawingDisabled; - disabled_redraw = FALSE; + RedrawingDisabled--; + disabled_redraw = false; } if (!arrow_used) { /* @@ -7096,9 +7086,10 @@ ins_esc ( if (cmdchar == 'r' || cmdchar == 'v') { stuffRedoReadbuff(ESC_STR); // No ESC in redo buffer } - ++RedrawingDisabled; - disabled_redraw = TRUE; - return FALSE; /* repeat the insert */ + RedrawingDisabled++; + disabled_redraw = true; + // Repeat the insert + return false; } stop_insert(&curwin->w_cursor, TRUE, nomove); undisplay_dollar(); @@ -7148,16 +7139,15 @@ ins_esc ( setmouse(); ui_cursor_shape(); /* may show different cursor shape */ - /* - * When recording or for CTRL-O, need to display the new mode. - * Otherwise remove the mode message. - */ - if (Recording || restart_edit != NUL) + // When recording or for CTRL-O, need to display the new mode. + // Otherwise remove the mode message. + if (Recording || restart_edit != NUL) { showmode(); - else if (p_smd) + } else if (p_smd) { MSG(""); - - return TRUE; /* exit Insert mode */ + } + // Exit Insert mode + return true; } /* @@ -7195,14 +7185,16 @@ static void ins_ctrl_(void) showmode(); } -/* - * If 'keymodel' contains "startsel", may start selection. - * Returns TRUE when a CTRL-O and other keys stuffed. - */ -static int ins_start_select(int c) +/// If 'keymodel' contains "startsel", may start selection. +/// +/// @param c character to check +// +/// @return true when a CTRL-O and other keys stuffed. +static bool ins_start_select(int c) + FUNC_ATTR_WARN_UNUSED_RESULT { if (!km_startsel) { - return FALSE; + return false; } switch (c) { case K_KHOME: @@ -7213,32 +7205,27 @@ static int ins_start_select(int c) case K_KPAGEDOWN: if (!(mod_mask & MOD_MASK_SHIFT)) break; - /* FALLTHROUGH */ + // FALLTHROUGH case K_S_LEFT: case K_S_RIGHT: case K_S_UP: case K_S_DOWN: case K_S_END: case K_S_HOME: - /* Start selection right away, the cursor can move with - * CTRL-O when beyond the end of the line. */ + // Start selection right away, the cursor can move with + // CTRL-O when beyond the end of the line. start_selection(); - /* Execute the key in (insert) Select mode. */ + // Execute the key in (insert) Select mode. stuffcharReadbuff(Ctrl_O); if (mod_mask) { - char_u buf[4]; - - buf[0] = K_SPECIAL; - buf[1] = KS_MODIFIER; - buf[2] = mod_mask; - buf[3] = NUL; + char_u buf[4] = { K_SPECIAL, KS_MODIFIER, mod_mask, NUL }; stuffReadbuff(buf); } stuffcharReadbuff(c); - return TRUE; + return true; } - return FALSE; + return false; } /* @@ -7252,15 +7239,15 @@ static void ins_insert(int replaceState) return; } - set_vim_var_string(VV_INSERTMODE, - (char_u *)((State & REPLACE_FLAG) ? "i" : - replaceState == VREPLACE ? "v" : - "r"), 1); - apply_autocmds(EVENT_INSERTCHANGE, NULL, NULL, FALSE, curbuf); - if (State & REPLACE_FLAG) + set_vim_var_string(VV_INSERTMODE, ((State & REPLACE_FLAG) ? "i" : + replaceState == VREPLACE ? "v" : + "r"), 1); + apply_autocmds(EVENT_INSERTCHANGE, NULL, NULL, false, curbuf); + if (State & REPLACE_FLAG) { State = INSERT | (State & LANGMAP); - else + } else { State = replaceState | (State & LANGMAP); + } AppendCharToRedobuff(K_INS); showmode(); ui_cursor_shape(); /* may show different cursor shape */ @@ -7362,18 +7349,23 @@ static void ins_bs_one(colnr_T *vcolp) (void)del_char(FALSE); } -/* - * Handle Backspace, delete-word and delete-line in Insert mode. - * Return TRUE when backspace was actually used. - */ -static int ins_bs(int c, int mode, int *inserted_space_p) +/// Handle Backspace, delete-word and delete-line in Insert mode. +/// +/// @param c charcter that was typed +/// @param mode backspace mode to use +/// @param[in,out] inserted_space_p whether a space was the last +// character inserted +/// +/// @return true when backspace was actually used. +static bool ins_bs(int c, int mode, int *inserted_space_p) + FUNC_ATTR_NONNULL_ARG(3) { linenr_T lnum; int cc; int temp = 0; /* init for GCC */ colnr_T save_col; colnr_T mincol; - int did_backspace = FALSE; + bool did_backspace = false; int in_indent; int oldState; int cpc[MAX_MCO]; /* composing characters */ @@ -7399,28 +7391,29 @@ static int ins_bs(int c, int mode, int *inserted_space_p) return false; } - if (stop_arrow() == FAIL) - return FALSE; + if (stop_arrow() == FAIL) { + return false; + } in_indent = inindent(0); - if (in_indent) - can_cindent = FALSE; - end_comment_pending = NUL; /* After BS, don't auto-end comment */ - if (revins_on) /* put cursor after last inserted char */ + if (in_indent) { + can_cindent = false; + } + end_comment_pending = NUL; // After BS, don't auto-end comment + if (revins_on) { // put cursor after last inserted char inc_cursor(); - - /* Virtualedit: - * BACKSPACE_CHAR eats a virtual space - * BACKSPACE_WORD eats all coladd - * BACKSPACE_LINE eats all coladd and keeps going - */ + } + // Virtualedit: + // BACKSPACE_CHAR eats a virtual space + // BACKSPACE_WORD eats all coladd + // BACKSPACE_LINE eats all coladd and keeps going if (curwin->w_cursor.coladd > 0) { if (mode == BACKSPACE_CHAR) { - --curwin->w_cursor.coladd; - return TRUE; + curwin->w_cursor.coladd--; + return true; } if (mode == BACKSPACE_WORD) { curwin->w_cursor.coladd = 0; - return TRUE; + return true; } curwin->w_cursor.coladd = 0; } @@ -7432,10 +7425,10 @@ static int ins_bs(int c, int mode, int *inserted_space_p) lnum = Insstart.lnum; if (curwin->w_cursor.lnum == lnum || revins_on) { if (u_save((linenr_T)(curwin->w_cursor.lnum - 2), - (linenr_T)(curwin->w_cursor.lnum + 1)) == FAIL) { - return FALSE; + (linenr_T)(curwin->w_cursor.lnum + 1)) == FAIL) { + return false; } - --Insstart.lnum; + Insstart.lnum--; Insstart.col = MAXCOL; } /* @@ -7677,12 +7670,12 @@ static int ins_bs(int c, int mode, int *inserted_space_p) if (vim_strchr(p_cpo, CPO_BACKSPACE) != NULL && dollar_vcol == -1) dollar_vcol = curwin->w_virtcol; - /* When deleting a char the cursor line must never be in a closed fold. - * E.g., when 'foldmethod' is indent and deleting the first non-white - * char before a Tab. */ - if (did_backspace) + // When deleting a char the cursor line must never be in a closed fold. + // E.g., when 'foldmethod' is indent and deleting the first non-white + // char before a Tab. + if (did_backspace) { foldOpenCursor(); - + } return did_backspace; } @@ -7748,6 +7741,8 @@ static void ins_mousescroll(int dir) (long)(curwin->w_botline - curwin->w_topline)); else scroll_redraw(dir, 3L); + } else { + mouse_scroll_horiz(dir); } did_scroll = TRUE; } @@ -8001,35 +7996,37 @@ static void ins_pagedown(void) } } -/* - * Handle TAB in Insert or Replace mode. - * Return TRUE when the TAB needs to be inserted like a normal character. - */ -static int ins_tab(void) +/// Handle TAB in Insert or Replace mode. +/// +/// @return true when the TAB needs to be inserted like a normal character. +static bool ins_tab(void) + FUNC_ATTR_WARN_UNUSED_RESULT { - int ind; int i; int temp; - if (Insstart_blank_vcol == MAXCOL && curwin->w_cursor.lnum == Insstart.lnum) + if (Insstart_blank_vcol == MAXCOL && curwin->w_cursor.lnum == Insstart.lnum) { Insstart_blank_vcol = get_nolist_virtcol(); - if (echeck_abbr(TAB + ABBR_OFF)) - return FALSE; + } + if (echeck_abbr(TAB + ABBR_OFF)) { + return false; + } - ind = inindent(0); - if (ind) - can_cindent = FALSE; + int ind = inindent(0); + if (ind) { + can_cindent = false; + } - /* - * When nothing special, insert TAB like a normal character - */ + // When nothing special, insert TAB like a normal character if (!curbuf->b_p_et && !(p_sta && ind && curbuf->b_p_ts != get_sw_value(curbuf)) - && get_sts_value() == 0) - return TRUE; + && get_sts_value() == 0) { + return true; + } - if (stop_arrow() == FAIL) - return TRUE; + if (stop_arrow() == FAIL) { + return true; + } did_ai = FALSE; did_si = FALSE; @@ -8037,12 +8034,13 @@ static int ins_tab(void) can_si_back = FALSE; AppendToRedobuff((char_u *)"\t"); - if (p_sta && ind) /* insert tab in indent, use 'shiftwidth' */ + if (p_sta && ind) { // insert tab in indent, use "shiftwidth" temp = get_sw_value(curbuf); - else if (curbuf->b_p_sts != 0) /* use 'softtabstop' when set */ + } else if (curbuf->b_p_sts != 0) { // use "softtabstop" when set temp = get_sts_value(); - else /* otherwise use 'tabstop' */ + } else { // otherwise use "tabstop" temp = (int)curbuf->b_p_ts; + } temp -= get_nolist_virtcol() % temp; /* @@ -8182,21 +8180,20 @@ static int ins_tab(void) curwin->w_p_list = save_list; } - return FALSE; + return false; } -/* - * Handle CR or NL in insert mode. - * Return TRUE when it can't undo. - */ -static int ins_eol(int c) +/// Handle CR or NL in insert mode. +/// +/// @return true when it can't undo. +static bool ins_eol(int c) { - int i; - - if (echeck_abbr(c + ABBR_OFF)) - return FALSE; - if (stop_arrow() == FAIL) - return TRUE; + if (echeck_abbr(c + ABBR_OFF)) { + return false; + } + if (stop_arrow() == FAIL) { + return true; + } undisplay_dollar(); /* @@ -8229,9 +8226,9 @@ static int ins_eol(int c) curwin->w_cursor.col += (colnr_T)STRLEN(get_cursor_pos_ptr()); AppendToRedobuff(NL_STR); - i = open_line(FORWARD, - has_format_option(FO_RET_COMS) ? OPENLINE_DO_COM : - 0, old_indent); + bool i = open_line(FORWARD, + has_format_option(FO_RET_COMS) ? OPENLINE_DO_COM : 0, + old_indent); old_indent = 0; can_cindent = TRUE; /* When inserting a line the cursor line must never be in a closed fold. */ @@ -8485,22 +8482,22 @@ static colnr_T get_nolist_virtcol(void) */ static char_u *do_insert_char_pre(int c) { - char_u buf[MB_MAXBYTES + 1]; + char buf[MB_MAXBYTES + 1]; // Return quickly when there is nothing to do. if (!has_event(EVENT_INSERTCHARPRE)) { return NULL; } if (has_mbyte) { - buf[(*mb_char2bytes)(c, buf)] = NUL; + buf[(*mb_char2bytes)(c, (char_u *) buf)] = NUL; } else { buf[0] = c; buf[1] = NUL; } - /* Lock the text to avoid weird things from happening. */ - ++textlock; - set_vim_var_string(VV_CHAR, buf, -1); /* set v:char */ + // Lock the text to avoid weird things from happening. + textlock++; + set_vim_var_string(VV_CHAR, buf, -1); char_u *res = NULL; if (apply_autocmds(EVENT_INSERTCHARPRE, NULL, NULL, FALSE, curbuf)) { @@ -8511,8 +8508,8 @@ static char_u *do_insert_char_pre(int c) res = vim_strsave(get_vim_var_str(VV_CHAR)); } - set_vim_var_string(VV_CHAR, NULL, -1); /* clear v:char */ - --textlock; + set_vim_var_string(VV_CHAR, NULL, -1); + textlock--; return res; } diff --git a/src/nvim/edit.h b/src/nvim/edit.h index 0289b2c3a6..0d61f26bcc 100644 --- a/src/nvim/edit.h +++ b/src/nvim/edit.h @@ -36,12 +36,6 @@ typedef int (*IndentGetter)(void); #define INSCHAR_NO_FEX 8 /* don't use 'formatexpr' */ #define INSCHAR_COM_LIST 16 /* format comments with list/2nd line indent */ -/* direction for nv_mousescroll() and ins_mousescroll() */ -#define MSCR_DOWN 0 /* DOWN must be FALSE */ -#define MSCR_UP 1 -#define MSCR_LEFT -1 -#define MSCR_RIGHT -2 - #ifdef INCLUDE_GENERATED_DECLARATIONS # include "edit.h.generated.h" #endif diff --git a/src/nvim/eval.c b/src/nvim/eval.c index b2370e7047..a68d09575b 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -66,13 +66,14 @@ #include "nvim/strings.h" #include "nvim/syntax.h" #include "nvim/tag.h" -#include "nvim/tempfile.h" #include "nvim/ui.h" #include "nvim/mouse.h" #include "nvim/terminal.h" #include "nvim/undo.h" #include "nvim/version.h" #include "nvim/window.h" +#include "nvim/eval/encode.h" +#include "nvim/eval/decode.h" #include "nvim/os/os.h" #include "nvim/event/libuv_process.h" #include "nvim/event/pty_process.h" @@ -87,7 +88,6 @@ #include "nvim/os/dl.h" #include "nvim/os/input.h" #include "nvim/event/loop.h" -#include "nvim/lib/kvec.h" #include "nvim/lib/queue.h" #define DICT_MAXNEST 100 /* maximum nesting of lists and dicts */ @@ -142,13 +142,6 @@ typedef struct lval_S { char_u *ll_newkey; /* New key for Dict in alloc. mem or NULL. */ } lval_T; -/// Structure defining state for read_from_list() -typedef struct { - const listitem_T *li; ///< Item currently read. - size_t offset; ///< Byte offset inside the read item. - size_t li_length; ///< Length of the string inside the read item. -} ListReaderState; - static char *e_letunexp = N_("E18: Unexpected characters in :let"); static char *e_listidx = N_("E684: list index out of range: %" PRId64); @@ -160,6 +153,7 @@ static char *e_listdictarg = N_( static char *e_emptykey = N_("E713: Cannot use empty key for Dictionary"); static char *e_listreq = N_("E714: List required"); static char *e_dictreq = N_("E715: Dictionary required"); +static char *e_strreq = N_("E114: String required"); static char *e_toomanyarg = N_("E118: Too many arguments for function: %s"); static char *e_dictkey = N_("E716: Key not present in Dictionary: %s"); static char *e_funcexts = N_( @@ -173,6 +167,7 @@ static char *e_illvar = N_("E461: Illegal variable name: %s"); static char *e_float_as_string = N_("E806: using Float as a String"); static char_u * const empty_string = (char_u *)""; +static char_u * const namespace_char = (char_u *)"abglstvw"; static dictitem_T globvars_var; /* variable used for g: */ #define globvarht globvardict.dv_hashtab @@ -183,17 +178,7 @@ static dictitem_T globvars_var; /* variable used for g: */ */ static hashtab_T compat_hashtab; -/* - * When recursively copying lists and dicts we need to remember which ones we - * have done to avoid endless recursiveness. This unique ID is used for that. - * The last bit is used for previous_funccal, ignored when comparing. - */ -static int current_copyID = 0; -#define COPYID_INC 2 -#define COPYID_MASK (~0x1) - -/// Abort conversion to string after a recursion error. -static bool did_echo_string_emsg = false; +hashtab_T func_hashtab; /* * Array to hold the hashtab with variables local to each sourced script. @@ -296,94 +281,112 @@ typedef enum { #define VV_RO 2 /* read-only */ #define VV_RO_SBX 4 /* read-only in the sandbox */ -#define VV_NAME(s, t) s, {{t, 0, {0}}, 0, {0}}, {0} +#define VV(idx, name, type, flags) \ + [idx] = { \ + .vv_name = name, \ + .vv_di = { \ + .di_tv = { .v_type = type }, \ + .di_flags = 0, \ + }, \ + .vv_filler = { 0 }, \ + .vv_flags = flags, \ + } // Array to hold the value of v: variables. // The value is in a dictitem, so that it can also be used in the v: scope. // The reason to use this table anyway is for very quick access to the // variables with the VV_ defines. static struct vimvar { - char *vv_name; /* name of variable, without v: */ - dictitem_T vv_di; /* value and name for key */ - char vv_filler[16]; /* space for LONGEST name below!!! */ - char vv_flags; /* VV_COMPAT, VV_RO, VV_RO_SBX */ -} vimvars[VV_LEN] = -{ - /* - * The order here must match the VV_ defines in eval.h! - * Initializing a union does not work, leave tv.vval empty to get zero's. - */ - { VV_NAME("count", VAR_NUMBER), VV_COMPAT+VV_RO }, - { VV_NAME("count1", VAR_NUMBER), VV_RO }, - { VV_NAME("prevcount", VAR_NUMBER), VV_RO }, - { VV_NAME("errmsg", VAR_STRING), VV_COMPAT }, - { VV_NAME("warningmsg", VAR_STRING), 0 }, - { VV_NAME("statusmsg", VAR_STRING), 0 }, - { VV_NAME("shell_error", VAR_NUMBER), VV_COMPAT+VV_RO }, - { VV_NAME("this_session", VAR_STRING), VV_COMPAT }, - { VV_NAME("version", VAR_NUMBER), VV_COMPAT+VV_RO }, - { VV_NAME("lnum", VAR_NUMBER), VV_RO_SBX }, - { VV_NAME("termresponse", VAR_STRING), VV_RO }, - { VV_NAME("fname", VAR_STRING), VV_RO }, - { VV_NAME("lang", VAR_STRING), VV_RO }, - { VV_NAME("lc_time", VAR_STRING), VV_RO }, - { VV_NAME("ctype", VAR_STRING), VV_RO }, - { VV_NAME("charconvert_from", VAR_STRING), VV_RO }, - { VV_NAME("charconvert_to", VAR_STRING), VV_RO }, - { VV_NAME("fname_in", VAR_STRING), VV_RO }, - { VV_NAME("fname_out", VAR_STRING), VV_RO }, - { VV_NAME("fname_new", VAR_STRING), VV_RO }, - { VV_NAME("fname_diff", VAR_STRING), VV_RO }, - { VV_NAME("cmdarg", VAR_STRING), VV_RO }, - { VV_NAME("foldstart", VAR_NUMBER), VV_RO_SBX }, - { VV_NAME("foldend", VAR_NUMBER), VV_RO_SBX }, - { VV_NAME("folddashes", VAR_STRING), VV_RO_SBX }, - { VV_NAME("foldlevel", VAR_NUMBER), VV_RO_SBX }, - { VV_NAME("progname", VAR_STRING), VV_RO }, - { VV_NAME("servername", VAR_STRING), VV_RO }, - { VV_NAME("dying", VAR_NUMBER), VV_RO }, - { VV_NAME("exception", VAR_STRING), VV_RO }, - { VV_NAME("throwpoint", VAR_STRING), VV_RO }, - { VV_NAME("register", VAR_STRING), VV_RO }, - { VV_NAME("cmdbang", VAR_NUMBER), VV_RO }, - { VV_NAME("insertmode", VAR_STRING), VV_RO }, - { VV_NAME("val", VAR_UNKNOWN), VV_RO }, - { VV_NAME("key", VAR_UNKNOWN), VV_RO }, - { VV_NAME("profiling", VAR_NUMBER), VV_RO }, - { VV_NAME("fcs_reason", VAR_STRING), VV_RO }, - { VV_NAME("fcs_choice", VAR_STRING), 0 }, - { VV_NAME("beval_bufnr", VAR_NUMBER), VV_RO }, - { VV_NAME("beval_winnr", VAR_NUMBER), VV_RO }, - { VV_NAME("beval_lnum", VAR_NUMBER), VV_RO }, - { VV_NAME("beval_col", VAR_NUMBER), VV_RO }, - { VV_NAME("beval_text", VAR_STRING), VV_RO }, - { VV_NAME("scrollstart", VAR_STRING), 0 }, - { VV_NAME("swapname", VAR_STRING), VV_RO }, - { VV_NAME("swapchoice", VAR_STRING), 0 }, - { VV_NAME("swapcommand", VAR_STRING), VV_RO }, - { VV_NAME("char", VAR_STRING), 0 }, - { VV_NAME("mouse_win", VAR_NUMBER), 0 }, - { VV_NAME("mouse_lnum", VAR_NUMBER), 0 }, - { VV_NAME("mouse_col", VAR_NUMBER), 0 }, - { VV_NAME("operator", VAR_STRING), VV_RO }, - { VV_NAME("searchforward", VAR_NUMBER), 0 }, - { VV_NAME("hlsearch", VAR_NUMBER), 0 }, - { VV_NAME("oldfiles", VAR_LIST), 0 }, - { VV_NAME("windowid", VAR_NUMBER), VV_RO }, - { VV_NAME("progpath", VAR_STRING), VV_RO }, - { VV_NAME("command_output", VAR_STRING), 0 }, - { VV_NAME("completed_item", VAR_DICT), VV_RO }, - { VV_NAME("option_new", VAR_STRING), VV_RO }, - { VV_NAME("option_old", VAR_STRING), VV_RO }, - { VV_NAME("option_type", VAR_STRING), VV_RO }, - { VV_NAME("errors", VAR_LIST), 0 }, - { VV_NAME("msgpack_types", VAR_DICT), VV_RO }, - { VV_NAME("event", VAR_DICT), VV_RO }, + char *vv_name; ///< Name of the variable, without v:. + dictitem_T vv_di; ///< Value of the variable, with name. + char vv_filler[16]; ///< Space for longest name from below. + char vv_flags; ///< Flags: #VV_COMPAT, #VV_RO, #VV_RO_SBX. +} vimvars[] = +{ + // VV_ tails differing from upcased string literals: + // VV_CC_FROM "charconvert_from" + // VV_CC_TO "charconvert_to" + // VV_SEND_SERVER "servername" + // VV_REG "register" + // VV_OP "operator" + VV(VV_COUNT, "count", VAR_NUMBER, VV_COMPAT+VV_RO), + VV(VV_COUNT1, "count1", VAR_NUMBER, VV_RO), + VV(VV_PREVCOUNT, "prevcount", VAR_NUMBER, VV_RO), + VV(VV_ERRMSG, "errmsg", VAR_STRING, VV_COMPAT), + VV(VV_WARNINGMSG, "warningmsg", VAR_STRING, 0), + VV(VV_STATUSMSG, "statusmsg", VAR_STRING, 0), + VV(VV_SHELL_ERROR, "shell_error", VAR_NUMBER, VV_COMPAT+VV_RO), + VV(VV_THIS_SESSION, "this_session", VAR_STRING, VV_COMPAT), + VV(VV_VERSION, "version", VAR_NUMBER, VV_COMPAT+VV_RO), + VV(VV_LNUM, "lnum", VAR_NUMBER, VV_RO_SBX), + VV(VV_TERMRESPONSE, "termresponse", VAR_STRING, VV_RO), + VV(VV_FNAME, "fname", VAR_STRING, VV_RO), + VV(VV_LANG, "lang", VAR_STRING, VV_RO), + VV(VV_LC_TIME, "lc_time", VAR_STRING, VV_RO), + VV(VV_CTYPE, "ctype", VAR_STRING, VV_RO), + VV(VV_CC_FROM, "charconvert_from", VAR_STRING, VV_RO), + VV(VV_CC_TO, "charconvert_to", VAR_STRING, VV_RO), + VV(VV_FNAME_IN, "fname_in", VAR_STRING, VV_RO), + VV(VV_FNAME_OUT, "fname_out", VAR_STRING, VV_RO), + VV(VV_FNAME_NEW, "fname_new", VAR_STRING, VV_RO), + VV(VV_FNAME_DIFF, "fname_diff", VAR_STRING, VV_RO), + VV(VV_CMDARG, "cmdarg", VAR_STRING, VV_RO), + VV(VV_FOLDSTART, "foldstart", VAR_NUMBER, VV_RO_SBX), + VV(VV_FOLDEND, "foldend", VAR_NUMBER, VV_RO_SBX), + VV(VV_FOLDDASHES, "folddashes", VAR_STRING, VV_RO_SBX), + VV(VV_FOLDLEVEL, "foldlevel", VAR_NUMBER, VV_RO_SBX), + VV(VV_PROGNAME, "progname", VAR_STRING, VV_RO), + VV(VV_SEND_SERVER, "servername", VAR_STRING, VV_RO), + VV(VV_DYING, "dying", VAR_NUMBER, VV_RO), + VV(VV_EXCEPTION, "exception", VAR_STRING, VV_RO), + VV(VV_THROWPOINT, "throwpoint", VAR_STRING, VV_RO), + VV(VV_REG, "register", VAR_STRING, VV_RO), + VV(VV_CMDBANG, "cmdbang", VAR_NUMBER, VV_RO), + VV(VV_INSERTMODE, "insertmode", VAR_STRING, VV_RO), + VV(VV_VAL, "val", VAR_UNKNOWN, VV_RO), + VV(VV_KEY, "key", VAR_UNKNOWN, VV_RO), + VV(VV_PROFILING, "profiling", VAR_NUMBER, VV_RO), + VV(VV_FCS_REASON, "fcs_reason", VAR_STRING, VV_RO), + VV(VV_FCS_CHOICE, "fcs_choice", VAR_STRING, 0), + VV(VV_BEVAL_BUFNR, "beval_bufnr", VAR_NUMBER, VV_RO), + VV(VV_BEVAL_WINNR, "beval_winnr", VAR_NUMBER, VV_RO), + VV(VV_BEVAL_LNUM, "beval_lnum", VAR_NUMBER, VV_RO), + VV(VV_BEVAL_COL, "beval_col", VAR_NUMBER, VV_RO), + VV(VV_BEVAL_TEXT, "beval_text", VAR_STRING, VV_RO), + VV(VV_SCROLLSTART, "scrollstart", VAR_STRING, 0), + VV(VV_SWAPNAME, "swapname", VAR_STRING, VV_RO), + VV(VV_SWAPCHOICE, "swapchoice", VAR_STRING, 0), + VV(VV_SWAPCOMMAND, "swapcommand", VAR_STRING, VV_RO), + VV(VV_CHAR, "char", VAR_STRING, 0), + VV(VV_MOUSE_WIN, "mouse_win", VAR_NUMBER, 0), + VV(VV_MOUSE_LNUM, "mouse_lnum", VAR_NUMBER, 0), + VV(VV_MOUSE_COL, "mouse_col", VAR_NUMBER, 0), + VV(VV_OP, "operator", VAR_STRING, VV_RO), + VV(VV_SEARCHFORWARD, "searchforward", VAR_NUMBER, 0), + VV(VV_HLSEARCH, "hlsearch", VAR_NUMBER, 0), + VV(VV_OLDFILES, "oldfiles", VAR_LIST, 0), + VV(VV_WINDOWID, "windowid", VAR_NUMBER, VV_RO_SBX), + VV(VV_PROGPATH, "progpath", VAR_STRING, VV_RO), + VV(VV_COMMAND_OUTPUT, "command_output", VAR_STRING, 0), + VV(VV_COMPLETED_ITEM, "completed_item", VAR_DICT, VV_RO), + VV(VV_OPTION_NEW, "option_new", VAR_STRING, VV_RO), + VV(VV_OPTION_OLD, "option_old", VAR_STRING, VV_RO), + VV(VV_OPTION_TYPE, "option_type", VAR_STRING, VV_RO), + VV(VV_ERRORS, "errors", VAR_LIST, 0), + VV(VV_MSGPACK_TYPES, "msgpack_types", VAR_DICT, VV_RO), + VV(VV_EVENT, "event", VAR_DICT, VV_RO), + VV(VV_FALSE, "false", VAR_SPECIAL, VV_RO), + VV(VV_TRUE, "true", VAR_SPECIAL, VV_RO), + VV(VV_NULL, "null", VAR_SPECIAL, VV_RO), + VV(VV__NULL_LIST, "_null_list", VAR_LIST, VV_RO), + VV(VV__NULL_DICT, "_null_dict", VAR_DICT, VV_RO), }; +#undef VV /* shorthand */ #define vv_type vv_di.di_tv.v_type #define vv_nr vv_di.di_tv.vval.v_number +#define vv_special vv_di.di_tv.vval.v_special #define vv_float vv_di.di_tv.vval.v_float #define vv_str vv_di.di_tv.vval.v_string #define vv_list vv_di.di_tv.vval.v_list @@ -417,29 +420,6 @@ typedef struct dict_watcher { bool busy; // prevent recursion if the dict is changed in the callback } DictWatcher; -/// Structure representing current VimL to messagepack conversion state -typedef struct { - enum { - kMPConvDict, ///< Convert dict_T *dictionary. - kMPConvList, ///< Convert list_T *list. - kMPConvPairs, ///< Convert mapping represented as a list_T* of pairs. - } type; - union { - struct { - dict_T *dict; ///< Currently converted dictionary. - hashitem_T *hi; ///< Currently converted dictionary item. - size_t todo; ///< Amount of items left to process. - } d; ///< State of dictionary conversion. - struct { - list_T *list; ///< Currently converted list. - listitem_T *li; ///< Currently converted list item. - } l; ///< State of list or generic mapping conversion. - } data; ///< Data to convert. -} MPConvStackVal; - -/// Stack used to convert VimL values to messagepack. -typedef kvec_t(MPConvStackVal) MPConvStack; - typedef struct { TerminalJobData *data; ufunc_T *callback; @@ -458,17 +438,6 @@ typedef struct { static uint64_t current_job_id = 1; static PMap(uint64_t) *jobs = NULL; -typedef enum { - kMPNil, - kMPBoolean, - kMPInteger, - kMPFloat, - kMPString, - kMPBinary, - kMPArray, - kMPMap, - kMPExt, -} MessagePackType; static const char *const msgpack_type_names[] = { [kMPNil] = "nil", [kMPBoolean] = "boolean", @@ -480,7 +449,7 @@ static const char *const msgpack_type_names[] = { [kMPMap] = "map", [kMPExt] = "ext", }; -static const list_T *msgpack_type_lists[] = { +const list_T *eval_msgpack_type_lists[] = { [kMPNil] = NULL, [kMPBoolean] = NULL, [kMPInteger] = NULL, @@ -497,8 +466,9 @@ static const list_T *msgpack_type_lists[] = { */ void eval_init(void) { + vimvars[VV_VERSION].vv_nr = VIM_VERSION_100; + jobs = pmap_new(uint64_t)(); - int i; struct vimvar *p; init_var_dict(&globvardict, &globvars_var, VAR_DEF_SCOPE); @@ -507,7 +477,7 @@ void eval_init(void) hash_init(&compat_hashtab); hash_init(&func_hashtab); - for (i = 0; i < VV_LEN; ++i) { + for (size_t i = 0; i < ARRAY_SIZE(vimvars); i++) { p = &vimvars[i]; STRCPY(p->vv_di.di_key, p->vv_name); if (p->vv_flags & VV_RO) @@ -536,7 +506,7 @@ void eval_init(void) .v_type = VAR_LIST, .vval = { .v_list = type_list, }, }; - msgpack_type_lists[i] = type_list; + eval_msgpack_type_lists[i] = type_list; if (dict_add(msgpack_types_dict, di) == FAIL) { // There must not be duplicate items in this dictionary by definition. assert(false); @@ -553,7 +523,12 @@ void eval_init(void) set_vim_var_list(VV_ERRORS, list_alloc()); set_vim_var_nr(VV_SEARCHFORWARD, 1L); set_vim_var_nr(VV_HLSEARCH, 1L); - set_reg_var(0); /* default for v:register is not 0 but '"' */ + + set_vim_var_special(VV_FALSE, kSpecialVarFalse); + set_vim_var_special(VV_TRUE, kSpecialVarTrue); + set_vim_var_special(VV_NULL, kSpecialVarNull); + + set_reg_var(0); // default for v:register is not 0 but '"' } #if defined(EXITFREE) @@ -561,7 +536,7 @@ void eval_clear(void) { struct vimvar *p; - for (int i = 0; i < VV_LEN; ++i) { + for (size_t i = 0; i < ARRAY_SIZE(vimvars); i++) { p = &vimvars[i]; if (p->vv_di.di_tv.v_type == VAR_STRING) { xfree(p->vv_str); @@ -796,45 +771,50 @@ void var_redir_stop(void) redir_varname = NULL; } -int eval_charconvert(char_u *enc_from, char_u *enc_to, char_u *fname_from, char_u *fname_to) +int eval_charconvert(const char *const enc_from, const char *const enc_to, + const char *const fname_from, const char *const fname_to) { - int err = FALSE; + int err = false; set_vim_var_string(VV_CC_FROM, enc_from, -1); set_vim_var_string(VV_CC_TO, enc_to, -1); set_vim_var_string(VV_FNAME_IN, fname_from, -1); set_vim_var_string(VV_FNAME_OUT, fname_to, -1); - if (eval_to_bool(p_ccv, &err, NULL, FALSE)) - err = TRUE; + if (eval_to_bool(p_ccv, &err, NULL, false)) { + err = true; + } set_vim_var_string(VV_CC_FROM, NULL, -1); set_vim_var_string(VV_CC_TO, NULL, -1); set_vim_var_string(VV_FNAME_IN, NULL, -1); set_vim_var_string(VV_FNAME_OUT, NULL, -1); - if (err) + if (err) { return FAIL; + } return OK; } -int eval_printexpr(char_u *fname, char_u *args) +int eval_printexpr(const char *const fname, const char *const args) { - int err = FALSE; + int err = false; set_vim_var_string(VV_FNAME_IN, fname, -1); set_vim_var_string(VV_CMDARG, args, -1); - if (eval_to_bool(p_pexpr, &err, NULL, FALSE)) - err = TRUE; + if (eval_to_bool(p_pexpr, &err, NULL, false)) { + err = true; + } set_vim_var_string(VV_FNAME_IN, NULL, -1); set_vim_var_string(VV_CMDARG, NULL, -1); if (err) { - os_remove((char *)fname); + os_remove(fname); return FAIL; } return OK; } -void eval_diff(char_u *origfile, char_u *newfile, char_u *outfile) +void eval_diff(const char *const origfile, const char *const newfile, + const char *const outfile) { int err = FALSE; @@ -847,7 +827,8 @@ void eval_diff(char_u *origfile, char_u *newfile, char_u *outfile) set_vim_var_string(VV_FNAME_OUT, NULL, -1); } -void eval_patch(char_u *origfile, char_u *difffile, char_u *outfile) +void eval_patch(const char *const origfile, const char *const difffile, + const char *const outfile) { int err; @@ -1731,7 +1712,7 @@ static char_u *list_arg_vars(exarg_T *eap, char_u *arg, int *first) } else { int c; - char_u *s = (char_u *) echo_string(&tv, NULL); + char_u *s = (char_u *) encode_tv2echo(&tv, NULL); c = *arg; *arg = NUL; list_one_var_a((char_u *)"", @@ -2415,11 +2396,12 @@ static int tv_op(typval_T *tv1, typval_T *tv2, char_u *op) char_u numbuf[NUMBUFLEN]; char_u *s; - /* Can't do anything with a Funcref or a Dict on the right. */ + // Can't do anything with a Funcref, a Dict or special value on the right. if (tv2->v_type != VAR_FUNC && tv2->v_type != VAR_DICT) { switch (tv1->v_type) { case VAR_DICT: case VAR_FUNC: + case VAR_SPECIAL: break; case VAR_LIST: @@ -2487,6 +2469,9 @@ static int tv_op(typval_T *tv1, typval_T *tv2, char_u *op) tv1->vval.v_float -= f; } return OK; + + case VAR_UNKNOWN: + assert(false); } } @@ -3124,6 +3109,15 @@ static void item_lock(typval_T *tv, int deep, int lock) } } } + break; + case VAR_NUMBER: + case VAR_FLOAT: + case VAR_STRING: + case VAR_FUNC: + case VAR_SPECIAL: + break; + case VAR_UNKNOWN: + assert(false); } --recurse; } @@ -3202,7 +3196,7 @@ char_u *get_user_var_name(expand_T *xp, int idx) static size_t bdone; static size_t wdone; static size_t tdone; - static int vidx; + static size_t vidx; static hashitem_T *hi; hashtab_T *ht; @@ -3264,9 +3258,10 @@ char_u *get_user_var_name(expand_T *xp, int idx) return cat_prefix_varname('t', hi->hi_key); } - /* v: variables */ - if (vidx < VV_LEN) + // v: variables + if (vidx < ARRAY_SIZE(vimvars)) { return cat_prefix_varname('v', (char_u *)vimvars[vidx++].vv_name); + } xfree(varnamebuf); varnamebuf = NULL; @@ -4156,7 +4151,7 @@ static int eval7( if (get_float) { float_T f; - *arg += string2float(*arg, &f); + *arg += string2float((char *) *arg, &f); if (evaluate) { rettv->v_type = VAR_FLOAT; rettv->vval.v_float = f; @@ -4345,14 +4340,37 @@ eval_index ( char_u *s; char_u *key = NULL; - if (rettv->v_type == VAR_FUNC) { - if (verbose) - EMSG(_("E695: Cannot index a Funcref")); - return FAIL; - } else if (rettv->v_type == VAR_FLOAT) { - if (verbose) - EMSG(_(e_float_as_string)); - return FAIL; + switch (rettv->v_type) { + case VAR_FUNC: { + if (verbose) { + EMSG(_("E695: Cannot index a Funcref")); + } + return FAIL; + } + case VAR_FLOAT: { + if (verbose) { + EMSG(_(e_float_as_string)); + } + return FAIL; + } + case VAR_SPECIAL: { + if (verbose) { + EMSG(_("E909: Cannot index a special variable")); + } + return FAIL; + } + case VAR_UNKNOWN: { + if (evaluate) { + return FAIL; + } + // fallthrough + } + case VAR_STRING: + case VAR_NUMBER: + case VAR_LIST: + case VAR_DICT: { + break; + } } init_tv(&var1); @@ -4543,6 +4561,11 @@ eval_index ( *rettv = var1; } break; + case VAR_SPECIAL: + case VAR_FUNC: + case VAR_FLOAT: + case VAR_UNKNOWN: + break; // Not evaluating, skipping over subscript } } @@ -5087,10 +5110,18 @@ tv_equal ( s1 = get_tv_string_buf(tv1, buf1); s2 = get_tv_string_buf(tv2, buf2); return (ic ? mb_stricmp(s1, s2) : STRCMP(s1, s2)) == 0; + + case VAR_SPECIAL: + return tv1->vval.v_special == tv2->vval.v_special; + + case VAR_UNKNOWN: + // VAR_UNKNOWN can be the result of an invalid expression, let’s say it does + // not equal anything, not even self. + return false; } - EMSG2(_(e_intern2), "tv_equal()"); - return TRUE; + assert(false); + return false; } /* @@ -5491,9 +5522,10 @@ static int list_join_inner(garray_T *const gap, list_T *const l, for (item = l->lv_first; item != NULL && !got_int; item = item->li_next) { char *s; size_t len; - s = echo_string(&item->li_tv, &len); - if (s == NULL) + s = encode_tv2echo(&item->li_tv, &len); + if (s == NULL) { return FAIL; + } sumlen += (int) len; @@ -5501,9 +5533,6 @@ static int list_join_inner(garray_T *const gap, list_T *const l, p->tofree = p->s = (char_u *) s; line_breakcheck(); - if (did_echo_string_emsg) { // recursion error, bail out - break; - } } /* Allocate result buffer with its total size, avoid re-allocation and @@ -5555,6 +5584,22 @@ static int list_join(garray_T *const gap, list_T *const l, return retval; } +/// Get next (unique) copy ID +/// +/// Used for traversing nested structures e.g. when serializing them or garbage +/// collecting. +int get_copyID(void) + FUNC_ATTR_WARN_UNUSED_RESULT +{ + // CopyID for recursively traversing lists and dicts + // + // This value is needed to avoid endless recursiveness. Last bit is used for + // previous_funccal and normally ignored when comparing. + static int current_copyID = 0; + current_copyID += COPYID_INC; + return current_copyID; +} + /* * Garbage collection for lists and dictionaries. * @@ -5590,8 +5635,7 @@ bool garbage_collect(void) // We advance by two because we add one for items referenced through // previous_funccal. - current_copyID += COPYID_INC; - int copyID = current_copyID; + const int copyID = get_copyID(); // 1. Go through all accessible variables and mark all lists and dicts // with copyID. @@ -5936,6 +5980,15 @@ bool set_ref_in_item(typval_T *tv, int copyID, ht_stack_T **ht_stack, } break; } + + case VAR_FUNC: + case VAR_UNKNOWN: + case VAR_SPECIAL: + case VAR_FLOAT: + case VAR_NUMBER: + case VAR_STRING: { + break; + } } return abort; } @@ -6527,596 +6580,22 @@ failret: return OK; } -#define CHECK_SELF_REFERENCE(val, copyID_attr, conv_type) \ - do { \ - if ((val)->copyID_attr == copyID) { \ - CONV_RECURSE((val), conv_type); \ - } \ - (val)->copyID_attr = copyID; \ - } while (0) - -/// Define functions which convert VimL value to something else +/// Convert the string to a floating point number /// -/// Creates function `vim_to_{name}(firstargtype firstargname, typval_T *const -/// tv)` which returns OK or FAIL and helper functions. -/// -/// @param firstargtype Type of the first argument. It will be used to return -/// the results. -/// @param firstargname Name of the first argument. -/// @param name Name of the target converter. -#define DEFINE_VIML_CONV_FUNCTIONS(scope, name, firstargtype, firstargname) \ -static int name##_convert_one_value(firstargtype firstargname, \ - MPConvStack *const mpstack, \ - typval_T *const tv, \ - const int copyID, \ - const char *const objname) \ - FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT \ -{ \ - switch (tv->v_type) { \ - case VAR_STRING: { \ - CONV_STRING(tv->vval.v_string, STRLEN(tv->vval.v_string)); \ - break; \ - } \ - case VAR_NUMBER: { \ - CONV_NUMBER(tv->vval.v_number); \ - break; \ - } \ - case VAR_FLOAT: { \ - CONV_FLOAT(tv->vval.v_float); \ - break; \ - } \ - case VAR_FUNC: { \ - CONV_FUNC(tv->vval.v_string); \ - break; \ - } \ - case VAR_LIST: { \ - if (tv->vval.v_list == NULL || tv->vval.v_list->lv_len == 0) { \ - CONV_EMPTY_LIST(); \ - break; \ - } \ - CHECK_SELF_REFERENCE(tv->vval.v_list, lv_copyID, kMPConvList); \ - CONV_LIST_START(tv->vval.v_list); \ - kv_push( \ - MPConvStackVal, \ - *mpstack, \ - ((MPConvStackVal) { \ - .type = kMPConvList, \ - .data = { \ - .l = { \ - .list = tv->vval.v_list, \ - .li = tv->vval.v_list->lv_first, \ - }, \ - }, \ - })); \ - break; \ - } \ - case VAR_DICT: { \ - if (tv->vval.v_dict == NULL \ - || tv->vval.v_dict->dv_hashtab.ht_used == 0) { \ - CONV_EMPTY_DICT(); \ - break; \ - } \ - const dictitem_T *type_di; \ - const dictitem_T *val_di; \ - if (CONV_ALLOW_SPECIAL \ - && tv->vval.v_dict->dv_hashtab.ht_used == 2 \ - && (type_di = dict_find((dict_T *) tv->vval.v_dict, \ - (char_u *) "_TYPE", -1)) != NULL \ - && type_di->di_tv.v_type == VAR_LIST \ - && (val_di = dict_find((dict_T *) tv->vval.v_dict, \ - (char_u *) "_VAL", -1)) != NULL) { \ - size_t i; \ - for (i = 0; i < ARRAY_SIZE(msgpack_type_lists); i++) { \ - if (type_di->di_tv.vval.v_list == msgpack_type_lists[i]) { \ - break; \ - } \ - } \ - if (i == ARRAY_SIZE(msgpack_type_lists)) { \ - goto name##_convert_one_value_regular_dict; \ - } \ - switch ((MessagePackType) i) { \ - case kMPNil: { \ - CONV_SPECIAL_NIL(); \ - break; \ - } \ - case kMPBoolean: { \ - if (val_di->di_tv.v_type != VAR_NUMBER) { \ - goto name##_convert_one_value_regular_dict; \ - } \ - CONV_SPECIAL_BOOL(val_di->di_tv.vval.v_number); \ - break; \ - } \ - case kMPInteger: { \ - const list_T *val_list; \ - varnumber_T sign; \ - varnumber_T highest_bits; \ - varnumber_T high_bits; \ - varnumber_T low_bits; \ - /* List of 4 integers; first is signed (should be 1 or -1, but */ \ - /* this is not checked), second is unsigned and have at most */ \ - /* one (sign is -1) or two (sign is 1) non-zero bits (number of */ \ - /* bits is not checked), other unsigned and have at most 31 */ \ - /* non-zero bits (number of bits is not checked).*/ \ - if (val_di->di_tv.v_type != VAR_LIST \ - || (val_list = val_di->di_tv.vval.v_list) == NULL \ - || val_list->lv_len != 4 \ - || val_list->lv_first->li_tv.v_type != VAR_NUMBER \ - || (sign = val_list->lv_first->li_tv.vval.v_number) == 0 \ - || val_list->lv_first->li_next->li_tv.v_type != VAR_NUMBER \ - || (highest_bits = \ - val_list->lv_first->li_next->li_tv.vval.v_number) < 0 \ - || val_list->lv_last->li_prev->li_tv.v_type != VAR_NUMBER \ - || (high_bits = \ - val_list->lv_last->li_prev->li_tv.vval.v_number) < 0 \ - || val_list->lv_last->li_tv.v_type != VAR_NUMBER \ - || (low_bits = val_list->lv_last->li_tv.vval.v_number) < 0) { \ - goto name##_convert_one_value_regular_dict; \ - } \ - uint64_t number = ((uint64_t) (((uint64_t) highest_bits) << 62) \ - | (uint64_t) (((uint64_t) high_bits) << 31) \ - | (uint64_t) low_bits); \ - if (sign > 0) { \ - CONV_UNSIGNED_NUMBER(number); \ - } else { \ - CONV_NUMBER(-number); \ - } \ - break; \ - } \ - case kMPFloat: { \ - if (val_di->di_tv.v_type != VAR_FLOAT) { \ - goto name##_convert_one_value_regular_dict; \ - } \ - CONV_FLOAT(val_di->di_tv.vval.v_float); \ - break; \ - } \ - case kMPString: \ - case kMPBinary: { \ - const bool is_string = ((MessagePackType) i == kMPString); \ - if (val_di->di_tv.v_type != VAR_LIST) { \ - goto name##_convert_one_value_regular_dict; \ - } \ - size_t len; \ - char *buf; \ - if (!vim_list_to_buf(val_di->di_tv.vval.v_list, &len, &buf)) { \ - goto name##_convert_one_value_regular_dict; \ - } \ - if (is_string) { \ - CONV_STR_STRING(buf, len); \ - } else { \ - CONV_STRING(buf, len); \ - } \ - xfree(buf); \ - break; \ - } \ - case kMPArray: { \ - if (val_di->di_tv.v_type != VAR_LIST) { \ - goto name##_convert_one_value_regular_dict; \ - } \ - CHECK_SELF_REFERENCE(val_di->di_tv.vval.v_list, lv_copyID, \ - kMPConvList); \ - CONV_LIST_START(val_di->di_tv.vval.v_list); \ - kv_push(MPConvStackVal, *mpstack, ((MPConvStackVal) { \ - .type = kMPConvList, \ - .data = { \ - .l = { \ - .list = val_di->di_tv.vval.v_list, \ - .li = val_di->di_tv.vval.v_list->lv_first, \ - }, \ - }, \ - })); \ - break; \ - } \ - case kMPMap: { \ - if (val_di->di_tv.v_type != VAR_LIST) { \ - goto name##_convert_one_value_regular_dict; \ - } \ - if (val_di->di_tv.vval.v_list == NULL) { \ - CONV_EMPTY_DICT(); \ - break; \ - } \ - list_T *const val_list = val_di->di_tv.vval.v_list; \ - for (const listitem_T *li = val_list->lv_first; li != NULL; \ - li = li->li_next) { \ - if (li->li_tv.v_type != VAR_LIST \ - || li->li_tv.vval.v_list->lv_len != 2) { \ - goto name##_convert_one_value_regular_dict; \ - } \ - } \ - CHECK_SELF_REFERENCE(val_list, lv_copyID, kMPConvPairs); \ - CONV_SPECIAL_MAP_START(val_list); \ - kv_push(MPConvStackVal, *mpstack, ((MPConvStackVal) { \ - .type = kMPConvPairs, \ - .data = { \ - .l = { \ - .list = val_list, \ - .li = val_list->lv_first, \ - }, \ - }, \ - })); \ - break; \ - } \ - case kMPExt: { \ - const list_T *val_list; \ - varnumber_T type; \ - if (val_di->di_tv.v_type != VAR_LIST \ - || (val_list = val_di->di_tv.vval.v_list) == NULL \ - || val_list->lv_len != 2 \ - || (val_list->lv_first->li_tv.v_type != VAR_NUMBER) \ - || (type = val_list->lv_first->li_tv.vval.v_number) > INT8_MAX \ - || type < INT8_MIN \ - || (val_list->lv_last->li_tv.v_type != VAR_LIST)) { \ - goto name##_convert_one_value_regular_dict; \ - } \ - size_t len; \ - char *buf; \ - if (!vim_list_to_buf(val_list->lv_last->li_tv.vval.v_list, \ - &len, &buf)) { \ - goto name##_convert_one_value_regular_dict; \ - } \ - CONV_EXT_STRING(buf, len, type); \ - xfree(buf); \ - break; \ - } \ - } \ - break; \ - } \ -name##_convert_one_value_regular_dict: \ - CHECK_SELF_REFERENCE(tv->vval.v_dict, dv_copyID, kMPConvDict); \ - CONV_DICT_START(tv->vval.v_dict); \ - kv_push(MPConvStackVal, *mpstack, ((MPConvStackVal) { \ - .type = kMPConvDict, \ - .data = { \ - .d = { \ - .dict = tv->vval.v_dict, \ - .hi = tv->vval.v_dict->dv_hashtab.ht_array, \ - .todo = tv->vval.v_dict->dv_hashtab.ht_used, \ - }, \ - }, \ - })); \ - break; \ - } \ - default: { \ - EMSG2(_(e_intern2), #name "_convert_one_value()"); \ - return FAIL; \ - } \ - } \ - return OK; \ -} \ -\ -scope int vim_to_##name(firstargtype firstargname, typval_T *const tv, \ - const char *const objname) \ - FUNC_ATTR_WARN_UNUSED_RESULT \ -{ \ - current_copyID += COPYID_INC; \ - const int copyID = current_copyID; \ - MPConvStack mpstack; \ - kv_init(mpstack); \ - if (name##_convert_one_value(firstargname, &mpstack, tv, copyID, objname) \ - == FAIL) { \ - goto vim_to_msgpack_error_ret; \ - } \ - while (kv_size(mpstack)) { \ - MPConvStackVal *cur_mpsv = &kv_A(mpstack, kv_size(mpstack) - 1); \ - typval_T *cur_tv = NULL; \ - switch (cur_mpsv->type) { \ - case kMPConvDict: { \ - if (!cur_mpsv->data.d.todo) { \ - (void) kv_pop(mpstack); \ - cur_mpsv->data.d.dict->dv_copyID = copyID - 1; \ - CONV_DICT_END(cur_mpsv->data.d.dict); \ - continue; \ - } else if (cur_mpsv->data.d.todo \ - != cur_mpsv->data.d.dict->dv_hashtab.ht_used) { \ - CONV_DICT_BETWEEN_ITEMS(cur_mpsv->data.d.dict); \ - } \ - while (HASHITEM_EMPTY(cur_mpsv->data.d.hi)) { \ - cur_mpsv->data.d.hi++; \ - } \ - dictitem_T *const di = HI2DI(cur_mpsv->data.d.hi); \ - cur_mpsv->data.d.todo--; \ - cur_mpsv->data.d.hi++; \ - CONV_STR_STRING(&di->di_key[0], STRLEN(&di->di_key[0])); \ - CONV_DICT_AFTER_KEY(cur_mpsv->data.d.dict); \ - cur_tv = &di->di_tv; \ - break; \ - } \ - case kMPConvList: { \ - if (cur_mpsv->data.l.li == NULL) { \ - (void) kv_pop(mpstack); \ - cur_mpsv->data.l.list->lv_copyID = copyID - 1; \ - CONV_LIST_END(cur_mpsv->data.l.list); \ - continue; \ - } else if (cur_mpsv->data.l.li != cur_mpsv->data.l.list->lv_first) { \ - CONV_LIST_BETWEEN_ITEMS(cur_mpsv->data.l.list); \ - } \ - cur_tv = &cur_mpsv->data.l.li->li_tv; \ - cur_mpsv->data.l.li = cur_mpsv->data.l.li->li_next; \ - break; \ - } \ - case kMPConvPairs: { \ - if (cur_mpsv->data.l.li == NULL) { \ - (void) kv_pop(mpstack); \ - cur_mpsv->data.l.list->lv_copyID = copyID - 1; \ - continue; \ - } \ - const list_T *const kv_pair = cur_mpsv->data.l.li->li_tv.vval.v_list; \ - if (name##_convert_one_value(firstargname, &mpstack, \ - &kv_pair->lv_first->li_tv, copyID, \ - objname) == FAIL) { \ - goto vim_to_msgpack_error_ret; \ - } \ - cur_tv = &kv_pair->lv_last->li_tv; \ - cur_mpsv->data.l.li = cur_mpsv->data.l.li->li_next; \ - break; \ - } \ - } \ - if (name##_convert_one_value(firstargname, &mpstack, cur_tv, copyID, \ - objname) == FAIL) { \ - goto vim_to_msgpack_error_ret; \ - } \ - } \ - kv_destroy(mpstack); \ - return OK; \ -vim_to_msgpack_error_ret: \ - kv_destroy(mpstack); \ - return FAIL; \ -} - -#define CONV_STRING(buf, len) \ - do { \ - const char *const buf_ = (const char *) buf; \ - if (buf == NULL) { \ - ga_concat(gap, (char_u *) "''"); \ - } else { \ - const size_t len_ = (len); \ - size_t num_quotes = 0; \ - for (size_t i = 0; i < len_; i++) { \ - if (buf_[i] == '\'') { \ - num_quotes++; \ - } \ - } \ - ga_grow(gap, 2 + len_ + num_quotes); \ - ga_append(gap, '\''); \ - for (size_t i = 0; i < len_; i++) { \ - if (buf_[i] == '\'') { \ - num_quotes++; \ - ga_append(gap, '\''); \ - } \ - ga_append(gap, buf_[i]); \ - } \ - ga_append(gap, '\''); \ - } \ - } while (0) - -#define CONV_STR_STRING(buf, len) \ - CONV_STRING(buf, len) - -#define CONV_EXT_STRING(buf, len, type) - -#define CONV_NUMBER(num) \ - do { \ - char numbuf[NUMBUFLEN]; \ - vim_snprintf(numbuf, NUMBUFLEN - 1, "%" PRId64, (int64_t) (num)); \ - ga_concat(gap, (char_u *) numbuf); \ - } while (0) - -#define CONV_FLOAT(flt) \ - do { \ - const float_T flt_ = (flt); \ - switch (fpclassify(flt_)) { \ - case FP_NAN: { \ - ga_concat(gap, (char_u *) "str2float('nan')"); \ - break; \ - } \ - case FP_INFINITE: { \ - if (flt_ < 0) { \ - ga_append(gap, '-'); \ - } \ - ga_concat(gap, (char_u *) "str2float('inf')"); \ - break; \ - } \ - default: { \ - char numbuf[NUMBUFLEN]; \ - vim_snprintf(numbuf, NUMBUFLEN - 1, "%g", flt_); \ - ga_concat(gap, (char_u *) numbuf); \ - } \ - } \ - } while (0) - -#define CONV_FUNC(fun) \ - do { \ - ga_concat(gap, (char_u *) "function("); \ - CONV_STRING(fun, STRLEN(fun)); \ - ga_append(gap, ')'); \ - } while (0) - -#define CONV_EMPTY_LIST() \ - ga_concat(gap, (char_u *) "[]") - -#define CONV_LIST_START(lst) \ - ga_append(gap, '[') - -#define CONV_EMPTY_DICT() \ - ga_concat(gap, (char_u *) "{}") - -#define CONV_SPECIAL_NIL() - -#define CONV_SPECIAL_BOOL(num) - -#define CONV_UNSIGNED_NUMBER(num) - -#define CONV_SPECIAL_MAP_START(lst) - -#define CONV_DICT_START(dct) \ - ga_append(gap, '{') - -#define CONV_DICT_END(dct) \ - ga_append(gap, '}') - -#define CONV_DICT_AFTER_KEY(dct) \ - ga_concat(gap, (char_u *) ": ") - -#define CONV_DICT_BETWEEN_ITEMS(dct) \ - ga_concat(gap, (char_u *) ", ") - -#define CONV_LIST_END(lst) \ - ga_append(gap, ']') - -#define CONV_LIST_BETWEEN_ITEMS(lst) \ - CONV_DICT_BETWEEN_ITEMS(NULL) - -#define CONV_RECURSE(val, conv_type) \ - do { \ - if (!did_echo_string_emsg) { \ - /* Only give this message once for a recursive call to avoid */ \ - /* flooding the user with errors. */ \ - did_echo_string_emsg = true; \ - EMSG(_("E724: unable to correctly dump variable " \ - "with self-referencing container")); \ - } \ - char ebuf[NUMBUFLEN + 7]; \ - size_t backref = 0; \ - for (; backref < kv_size(*mpstack); backref++) { \ - const MPConvStackVal mpval = kv_a(MPConvStackVal, *mpstack, backref); \ - if (mpval.type == conv_type) { \ - if (conv_type == kMPConvDict) { \ - if ((void *) mpval.data.d.dict == (void *) (val)) { \ - break; \ - } \ - } else if (conv_type == kMPConvList) { \ - if ((void *) mpval.data.l.list == (void *) (val)) { \ - break; \ - } \ - } \ - } \ - } \ - vim_snprintf(ebuf, NUMBUFLEN + 6, "{E724@%zu}", backref); \ - ga_concat(gap, (char_u *) &ebuf[0]); \ - return OK; \ - } while (0) - -#define CONV_ALLOW_SPECIAL false - -DEFINE_VIML_CONV_FUNCTIONS(static, string, garray_T *const, gap) - -#undef CONV_RECURSE -#define CONV_RECURSE(val, conv_type) \ - do { \ - char ebuf[NUMBUFLEN + 7]; \ - size_t backref = 0; \ - for (; backref < kv_size(*mpstack); backref++) { \ - const MPConvStackVal mpval = kv_a(MPConvStackVal, *mpstack, backref); \ - if (mpval.type == conv_type) { \ - if (conv_type == kMPConvDict) { \ - if ((void *) mpval.data.d.dict == (void *) val) { \ - break; \ - } \ - } else if (conv_type == kMPConvList) { \ - if ((void *) mpval.data.l.list == (void *) val) { \ - break; \ - } \ - } \ - } \ - } \ - if (conv_type == kMPConvDict) { \ - vim_snprintf(ebuf, NUMBUFLEN + 6, "{...@%zu}", backref); \ - } else { \ - vim_snprintf(ebuf, NUMBUFLEN + 6, "[...@%zu]", backref); \ - } \ - ga_concat(gap, (char_u *) &ebuf[0]); \ - return OK; \ - } while (0) - -DEFINE_VIML_CONV_FUNCTIONS(static, echo, garray_T *const, gap) - -#undef CONV_STRING -#undef CONV_STR_STRING -#undef CONV_EXT_STRING -#undef CONV_NUMBER -#undef CONV_FLOAT -#undef CONV_FUNC -#undef CONV_EMPTY_LIST -#undef CONV_LIST_START -#undef CONV_EMPTY_DICT -#undef CONV_SPECIAL_NIL -#undef CONV_SPECIAL_BOOL -#undef CONV_UNSIGNED_NUMBER -#undef CONV_SPECIAL_MAP_START -#undef CONV_DICT_START -#undef CONV_DICT_END -#undef CONV_DICT_AFTER_KEY -#undef CONV_DICT_BETWEEN_ITEMS -#undef CONV_LIST_END -#undef CONV_LIST_BETWEEN_ITEMS -#undef CONV_RECURSE -#undef CONV_ALLOW_SPECIAL - -/// Return a string with the string representation of a variable. -/// Puts quotes around strings, so that they can be parsed back by eval(). -/// -/// @param[in] tv typval_T to convert. -/// @param[out] len Location where length of the result will be saved. -/// -/// @return String representation of the variable or NULL. -static char *tv2string(typval_T *tv, size_t *len) - FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_MALLOC -{ - garray_T ga; - ga_init(&ga, (int)sizeof(char), 80); - vim_to_string(&ga, tv, "tv2string() argument"); - did_echo_string_emsg = false; - if (len != NULL) { - *len = (size_t) ga.ga_len; - } - ga_append(&ga, '\0'); - return (char *) ga.ga_data; -} - -/// Return a string with the string representation of a variable. -/// Does not put quotes around strings, as ":echo" displays values. +/// This uses strtod(). setlocale(LC_NUMERIC, "C") has been used earlier to +/// make sure this always uses a decimal point. /// -/// @param[in] tv typval_T to convert. -/// @param[out] len Location where length of the result will be saved. +/// @param[in] text String to convert. +/// @param[out] ret_value Location where conversion result is saved. /// -/// @return String representation of the variable or NULL. -static char *echo_string(typval_T *tv, size_t *len) - FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_MALLOC -{ - garray_T ga; - ga_init(&ga, (int)sizeof(char), 80); - if (tv->v_type == VAR_STRING || tv->v_type == VAR_FUNC) { - if (tv->vval.v_string != NULL) { - ga_concat(&ga, tv->vval.v_string); - } - } else { - vim_to_echo(&ga, tv, ":echo argument"); - did_echo_string_emsg = false; - } - if (len != NULL) { - *len = (size_t) ga.ga_len; - } - ga_append(&ga, '\0'); - return (char *) ga.ga_data; -} - -/* - * Convert the string "text" to a floating point number. - * This uses strtod(). setlocale(LC_NUMERIC, "C") has been used to make sure - * this always uses a decimal point. - * Returns the length of the text that was consumed. - */ -static int -string2float ( - char_u *text, - float_T *value /* result stored here */ -) +/// @return Length of the text that was consumed. +size_t string2float(const char *const text, float_T *const ret_value) + FUNC_ATTR_NONNULL_ALL { - char *s = (char *)text; - float_T f; + char *s = NULL; - f = strtod(s, &s); - *value = f; - return (int)((char_u *)s - text); + *ret_value = strtod(text, &s); + return (size_t) (s - text); } /// Get the value of an environment variable. @@ -7176,7 +6655,7 @@ static struct fst { } functions[] = { { "abs", 1, 1, f_abs }, - { "acos", 1, 1, f_acos }, // WJMc + { "acos", 1, 1, f_acos }, // WJMc { "add", 2, 2, f_add }, { "and", 2, 2, f_and }, { "append", 2, 2, f_append }, @@ -7193,9 +6672,9 @@ static struct fst { { "browse", 4, 4, f_browse }, { "browsedir", 2, 2, f_browsedir }, { "bufexists", 1, 1, f_bufexists }, - { "buffer_exists", 1, 1, f_bufexists }, // obsolete - { "buffer_name", 1, 1, f_bufname }, // obsolete - { "buffer_number", 1, 1, f_bufnr }, // obsolete + { "buffer_exists", 1, 1, f_bufexists }, // obsolete + { "buffer_name", 1, 1, f_bufname }, // obsolete + { "buffer_number", 1, 1, f_bufnr }, // obsolete { "buflisted", 1, 1, f_buflisted }, { "bufloaded", 1, 1, f_bufloaded }, { "bufname", 1, 1, f_bufname }, @@ -7222,7 +6701,7 @@ static struct fst { { "cscope_connection", 0, 3, f_cscope_connection }, { "cursor", 1, 3, f_cursor }, { "deepcopy", 1, 2, f_deepcopy }, - { "delete", 1, 1, f_delete }, + { "delete", 1, 2, f_delete }, { "dictwatcheradd", 3, 3, f_dictwatcheradd }, { "dictwatcherdel", 3, 3, f_dictwatcherdel }, { "did_filetype", 0, 0, f_did_filetype }, @@ -7239,7 +6718,7 @@ static struct fst { { "expand", 1, 3, f_expand }, { "extend", 2, 3, f_extend }, { "feedkeys", 1, 2, f_feedkeys }, - { "file_readable", 1, 1, f_filereadable }, // obsolete + { "file_readable", 1, 1, f_filereadable }, // obsolete { "filereadable", 1, 1, f_filereadable }, { "filewritable", 1, 1, f_filewritable }, { "filter", 2, 2, f_filter }, @@ -7269,7 +6748,7 @@ static struct fst { { "getcmdtype", 0, 0, f_getcmdtype }, { "getcmdwintype", 0, 0, f_getcmdwintype }, { "getcurpos", 0, 0, f_getcurpos }, - { "getcwd", 0, 0, f_getcwd }, + { "getcwd", 0, 2, f_getcwd }, { "getfontname", 0, 1, f_getfontname }, { "getfperm", 1, 1, f_getfperm }, { "getfsize", 1, 1, f_getfsize }, @@ -7293,7 +6772,7 @@ static struct fst { { "globpath", 2, 5, f_globpath }, { "has", 1, 1, f_has }, { "has_key", 2, 2, f_has_key }, - { "haslocaldir", 0, 0, f_haslocaldir }, + { "haslocaldir", 0, 2, f_haslocaldir }, { "hasmapto", 1, 3, f_hasmapto }, { "highlightID", 1, 1, f_hlID }, // obsolete { "highlight_exists", 1, 1, f_hlexists }, // obsolete @@ -7326,6 +6805,8 @@ static struct fst { { "jobstop", 1, 1, f_jobstop }, { "jobwait", 1, 2, f_jobwait }, { "join", 1, 2, f_join }, + { "json_decode", 1, 1, f_json_decode }, + { "json_encode", 1, 1, f_json_encode }, { "keys", 1, 1, f_keys }, { "last_buffer_nr", 0, 0, f_last_buffer_nr }, // obsolete { "len", 1, 1, f_len }, @@ -8100,19 +7581,19 @@ static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, char_u *tofree; if (opt_msg_tv->v_type != VAR_UNKNOWN) { - tofree = (char_u *) tv2string(opt_msg_tv, NULL); + tofree = (char_u *) encode_tv2string(opt_msg_tv, NULL); ga_concat(gap, tofree); xfree(tofree); } else { ga_concat(gap, (char_u *)"Expected "); if (exp_str == NULL) { - tofree = (char_u *) tv2string(exp_tv, NULL); + tofree = (char_u *) encode_tv2string(exp_tv, NULL); ga_concat(gap, tofree); xfree(tofree); } else { ga_concat(gap, exp_str); } - tofree = (char_u *) tv2string(got_tv, NULL); + tofree = (char_u *) encode_tv2string(got_tv, NULL); ga_concat(gap, (char_u *)" but got "); ga_concat(gap, tofree); xfree(tofree); @@ -8147,16 +7628,21 @@ static void f_assert_equal(typval_T *argvars, typval_T *rettv) } // Common for assert_true() and assert_false(). -static void assert_bool(typval_T *argvars, bool isTrue) +static void assert_bool(typval_T *argvars, bool is_true) { int error = (int)false; garray_T ga; - if (argvars[0].v_type != VAR_NUMBER || - (get_tv_number_chk(&argvars[0], &error) == 0) == isTrue || error) { + if ((argvars[0].v_type != VAR_NUMBER || + (get_tv_number_chk(&argvars[0], &error) == 0) == is_true || error) + && (argvars[0].v_type != VAR_SPECIAL + || (argvars[0].vval.v_special + != (SpecialVarValue) (is_true + ? kSpecialVarTrue + : kSpecialVarFalse)))) { prepare_assert_error(&ga); fill_assert_error(&ga, &argvars[1], - (char_u *)(isTrue ? "True" : "False"), + (char_u *)(is_true ? "True" : "False"), NULL, &argvars[0]); assert_error(&ga); ga_clear(&ga); @@ -8878,25 +8364,51 @@ static void f_deepcopy(typval_T *argvars, typval_T *rettv) if (argvars[1].v_type != VAR_UNKNOWN) noref = get_tv_number_chk(&argvars[1], NULL); - if (noref < 0 || noref > 1) + if (noref < 0 || noref > 1) { EMSG(_(e_invarg)); - else { - current_copyID += COPYID_INC; + } else { var_item_copy(NULL, &argvars[0], rettv, true, (noref == 0 - ? current_copyID + ? get_copyID() : 0)); } } -/* - * "delete()" function - */ +// "delete()" function static void f_delete(typval_T *argvars, typval_T *rettv) { - if (check_restricted() || check_secure()) - rettv->vval.v_number = -1; - else - rettv->vval.v_number = os_remove((char *)get_tv_string(&argvars[0])); + char_u nbuf[NUMBUFLEN]; + char_u *name; + char_u *flags; + + rettv->vval.v_number = -1; + if (check_restricted() || check_secure()) { + return; + } + + name = get_tv_string(&argvars[0]); + if (name == NULL || *name == NUL) { + EMSG(_(e_invarg)); + return; + } + + if (argvars[1].v_type != VAR_UNKNOWN) { + flags = get_tv_string_buf(&argvars[1], nbuf); + } else { + flags = (char_u *)""; + } + + if (*flags == NUL) { + // delete a file + rettv->vval.v_number = os_remove((char *)name) == 0 ? 0 : -1; + } else if (STRCMP(flags, "d") == 0) { + // delete an empty directory + rettv->vval.v_number = os_rmdir((char *)name) == 0 ? 0 : -1; + } else if (STRCMP(flags, "rf") == 0) { + // delete a directory recursively + rettv->vval.v_number = delete_recursive(name); + } else { + EMSG2(_(e_invexpr2), flags); + } } // dictwatcheradd(dict, key, funcref) function @@ -9073,7 +8585,7 @@ static void f_diff_hlID(typval_T *argvars, typval_T *rettv) */ static void f_empty(typval_T *argvars, typval_T *rettv) { - int n; + bool n = true; switch (argvars[0].v_type) { case VAR_STRING: @@ -9095,9 +8607,12 @@ static void f_empty(typval_T *argvars, typval_T *rettv) n = argvars[0].vval.v_dict == NULL || argvars[0].vval.v_dict->dv_hashtab.ht_used == 0; break; - default: - EMSG2(_(e_intern2), "f_empty()"); - n = 0; + case VAR_SPECIAL: + n = argvars[0].vval.v_special != kSpecialVarTrue; + break; + case VAR_UNKNOWN: + EMSG2(_(e_intern2), "f_empty(UNKNOWN)"); + break; } rettv->vval.v_number = n; @@ -10269,22 +9784,143 @@ static void f_getcmdwintype(typval_T *argvars, typval_T *rettv) rettv->vval.v_string[0] = cmdwin_type; } -/* - * "getcwd()" function - */ +/// `getcwd([{win}[, {tab}]])` function +/// +/// Every scope not specified implies the currently selected scope object. +/// +/// @pre The arguments must be of type number. +/// @pre There may not be more than two arguments. +/// @pre An argument may not be -1 if preceding arguments are not all -1. +/// +/// @post The return value will be a string. static void f_getcwd(typval_T *argvars, typval_T *rettv) { - char_u *cwd; + // Possible scope of working directory to return. + CdScope scope = kCdScopeWindow; + + // Numbers of the scope objects (window, tab) we want the working directory + // of. A `-1` means to skip this scope, a `0` means the current object. + int scope_number[] = { + [kCdScopeWindow] = 0, // Number of window to look at. + [kCdScopeTab ] = 0, // Number of tab to look at. + }; + + char_u *cwd = NULL; // Current working directory to print + char_u *from = NULL; // The original string to copy + + tabpage_T *tp = curtab; // The tabpage to look at. + win_T *win = curwin; // The window to look at. rettv->v_type = VAR_STRING; rettv->vval.v_string = NULL; + + // Pre-conditions and scope extraction together + for (int i = 0; i < kCdScopeGlobal; i++) { + if (argvars[i].v_type == VAR_UNKNOWN) { + break; + } + if (argvars[i].v_type != VAR_NUMBER) { + EMSG(_(e_invarg)); + return; + } + scope_number[i] = argvars[i].vval.v_number; + // The scope is the current iteration step. + scope = i; + + if (scope_number[i] < -1) { + EMSG(_(e_invarg)); + return; + } + } + + // Allocate and initialize the string to return. cwd = xmalloc(MAXPATHL); - if (os_dirname(cwd, MAXPATHL) != FAIL) { - rettv->vval.v_string = vim_strsave(cwd); + + // Get the scope and numbers from the arguments + for (int i = 0; i < MAX_CD_SCOPE; i++) { + // If there is no argument there are no more scopes after it, break out. + if (argvars[i].v_type == VAR_UNKNOWN) { + break; + } + scope_number[i] = argvars[i].vval.v_number; + // The scope is the current iteration step. + scope = i; + // It is an error for the scope number to be less than `-1`. + if (scope_number[i] < -1) { + EMSG(_(e_invarg)); + goto end; + } + } + + // If the deepest scope number is `-1` advance the scope. + if (scope_number[scope] < 0) { + scope++; + } + + // Find the tabpage by number + if (scope_number[kCdScopeTab] == -1) { + tp = NULL; + } else if (scope_number[kCdScopeTab] > 0) { + tp = find_tabpage(scope_number[kCdScopeTab]); + if (!tp) { + EMSG(_("E5000: Cannot find tab number.")); + goto end; + } + } + + // Find the window in `tp` by number, `NULL` if none. + if (scope_number[kCdScopeWindow] == -1) { + win = NULL; + } else if (scope_number[kCdScopeWindow] >= 0) { + if (!tp) { + EMSG(_("E5001: Higher scope cannot be -1 if lower scope is >= 0.")); + goto end; + } + + if (scope_number[kCdScopeWindow] > 0) { + win = find_win_by_nr(&argvars[0], curtab); + if (!win) { + EMSG(_("E5002: Cannot find window number.")); + goto end; + } + } + } + + switch (scope) { + case kCdScopeWindow: + from = win->w_localdir; + if (from) { + break; + } + case kCdScopeTab: // FALLTHROUGH + from = tp->localdir; + if (from) { + break; + } + case kCdScopeGlobal: // FALLTHROUGH + // The `globaldir` variable is not always set. + if (globaldir) { + from = globaldir; + } else { + // Copy the OS path directly into output string and jump to the end. + if (os_dirname(cwd, MAXPATHL) == FAIL) { + EMSG(_("E41: Could not display path.")); + goto end; + } + } + break; + } + + if (from) { + xstrlcpy((char *)cwd, (char *)from, MAXPATHL); + } + + rettv->vval.v_string = vim_strsave(cwd); #ifdef BACKSLASH_IN_FILENAME - slash_adjust(rettv->vval.v_string); + slash_adjust(rettv->vval.v_string); #endif - } + +end: xfree(cwd); } @@ -10607,9 +10243,10 @@ static void f_getreg(typval_T *argvars, typval_T *rettv) rettv->v_type = VAR_LIST; rettv->vval.v_list = get_reg_contents(regname, (arg2 ? kGRegExprSrc : 0) | kGRegList); - if (rettv->vval.v_list != NULL) { - rettv->vval.v_list->lv_refcount++; + if (rettv->vval.v_list == NULL) { + rettv->vval.v_list = list_alloc(); } + rettv->vval.v_list->lv_refcount++; } else { rettv->v_type = VAR_STRING; rettv->vval.v_string = get_reg_contents(regname, arg2 ? kGRegExprSrc : 0); @@ -11103,12 +10740,98 @@ static void f_has_key(typval_T *argvars, typval_T *rettv) get_tv_string(&argvars[1]), -1) != NULL; } -/* - * "haslocaldir()" function - */ +/// `haslocaldir([{win}[, {tab}]])` function +/// +/// Returns `1` if the scope object has a local directory, `0` otherwise. If a +/// scope object is not specified the current one is implied. This function +/// share a lot of code with `f_getcwd`. +/// +/// @pre The arguments must be of type number. +/// @pre There may not be more than two arguments. +/// @pre An argument may not be -1 if preceding arguments are not all -1. +/// +/// @post The return value will be either the number `1` or `0`. static void f_haslocaldir(typval_T *argvars, typval_T *rettv) { - rettv->vval.v_number = (curwin->w_localdir != NULL); + // Possible scope of working directory to return. + CdScope scope = kCdScopeWindow; + + // Numbers of the scope objects (window, tab) we want the working directory + // of. A `-1` means to skip this scope, a `0` means the current object. + int scope_number[] = { + [kCdScopeWindow] = 0, // Number of window to look at. + [kCdScopeTab ] = 0, // Number of tab to look at. + }; + + tabpage_T *tp = curtab; // The tabpage to look at. + win_T *win = curwin; // The window to look at. + + rettv->v_type = VAR_NUMBER; + rettv->vval.v_number = 0; + + // Pre-conditions and scope extraction together + for (int i = 0; i < kCdScopeGlobal; i++) { + if (argvars[i].v_type == VAR_UNKNOWN) { + break; + } + if (argvars[i].v_type != VAR_NUMBER) { + EMSG(_(e_invarg)); + return; + } + scope_number[i] = argvars[i].vval.v_number; + // The scope is the current iteration step. + scope = i; + if (scope_number[i] < -1) { + EMSG(_(e_invarg)); + return; + } + } + + // It the deepest scope number is `-1` advance the scope by one. + if (scope_number[scope] < 0) { + ++scope; + } + + // Find the tabpage by number + if (scope_number[kCdScopeTab] == -1) { + tp = NULL; + } else if (scope_number[kCdScopeTab] > 0) { + tp = find_tabpage(scope_number[kCdScopeTab]); + if (!tp) { + EMSG(_("5000: Cannot find tab number.")); + return; + } + } + + // Find the window in `tp` by number, `NULL` if none. + if (scope_number[kCdScopeWindow] == -1) { + win = NULL; + } else if (scope_number[kCdScopeWindow] >= 0) { + if (!tp) { + EMSG(_("E5001: Higher scope cannot be -1 if lower scope is >= 0.")); + return; + } + + if (scope_number[kCdScopeWindow] > 0) { + win = find_win_by_nr(&argvars[0], curtab); + if (!win) { + EMSG(_("E5002: Cannot find window number.")); + return; + } + } + } + + switch (scope) { + case kCdScopeWindow: + rettv->vval.v_number = win->w_localdir ? 1 : 0; + break; + case kCdScopeTab: + rettv->vval.v_number = tp->localdir ? 1 : 0; + break; + case kCdScopeGlobal: + assert(0); + break; + } } /* @@ -12116,6 +11839,47 @@ static void f_join(typval_T *argvars, typval_T *rettv) rettv->vval.v_string = NULL; } +/// json_decode() function +static void f_json_decode(typval_T *argvars, typval_T *rettv) +{ + char numbuf[NUMBUFLEN]; + char *s = NULL; + char *tofree = NULL; + size_t len; + if (argvars[0].v_type == VAR_LIST) { + if (!encode_vim_list_to_buf(argvars[0].vval.v_list, &len, &s)) { + EMSG(_("E474: Failed to convert list to string")); + return; + } + tofree = s; + if (s == NULL) { + assert(len == 0); + s = ""; + } + } else { + s = (char *) get_tv_string_buf_chk(&argvars[0], (char_u *) numbuf); + if (s) { + len = strlen(s); + } else { + return; + } + } + if (json_decode_string(s, len, rettv) == FAIL) { + emsgf(_("E474: Failed to parse %.*s"), (int) len, s); + rettv->v_type = VAR_NUMBER; + rettv->vval.v_number = 0; + } + assert(rettv->v_type != VAR_UNKNOWN); + xfree(tofree); +} + +/// json_encode() function +static void f_json_encode(typval_T *argvars, typval_T *rettv) +{ + rettv->v_type = VAR_STRING; + rettv->vval.v_string = (char_u *) encode_tv2json(&argvars[0], NULL); +} + /* * "keys()" function */ @@ -12157,7 +11921,10 @@ static void f_len(typval_T *argvars, typval_T *rettv) case VAR_DICT: rettv->vval.v_number = dict_len(argvars[0].vval.v_dict); break; - default: + case VAR_UNKNOWN: + case VAR_SPECIAL: + case VAR_FLOAT: + case VAR_FUNC: EMSG(_("E701: Invalid type for len()")); break; } @@ -12480,9 +12247,10 @@ static void find_some_match(typval_T *argvars, typval_T *rettv, int type) break; } xfree(tofree); - tofree = str = (char_u *) echo_string(&li->li_tv, NULL); - if (str == NULL) + tofree = str = (char_u *) encode_tv2echo(&li->li_tv, NULL); + if (str == NULL) { break; + } } match = vim_regexec_nl(®match, str, (colnr_T)startcol); @@ -12880,289 +12648,6 @@ static void f_mode(typval_T *argvars, typval_T *rettv) rettv->v_type = VAR_STRING; } -/// Msgpack callback for writing to readfile()-style list -static int msgpack_list_write(void *data, const char *buf, size_t len) -{ - if (len == 0) { - return 0; - } - list_T *const list = (list_T *) data; - const char *const end = buf + len; - const char *line_end = buf; - if (list->lv_last == NULL) { - list_append_string(list, NULL, 0); - } - listitem_T *li = list->lv_last; - do { - const char *line_start = line_end; - line_end = xmemscan(line_start, NL, end - line_start); - if (line_end == line_start) { - list_append_allocated_string(list, NULL); - } else { - const size_t line_length = line_end - line_start; - char *str; - if (li == NULL) { - str = xmemdupz(line_start, line_length); - } else { - const size_t li_len = (li->li_tv.vval.v_string == NULL - ? 0 - : STRLEN(li->li_tv.vval.v_string)); - li->li_tv.vval.v_string = xrealloc(li->li_tv.vval.v_string, - li_len + line_length + 1); - str = (char *) li->li_tv.vval.v_string + li_len; - memmove(str, line_start, line_length); - str[line_length] = 0; - } - for (size_t i = 0; i < line_length; i++) { - if (str[i] == NUL) { - str[i] = NL; - } - } - if (li == NULL) { - list_append_allocated_string(list, str); - } else { - li = NULL; - } - if (line_end == end - 1) { - list_append_allocated_string(list, NULL); - } - } - line_end++; - } while (line_end < end); - return 0; -} - -/// Convert readfile()-style list to a char * buffer with length -/// -/// @param[in] list Converted list. -/// @param[out] ret_len Resulting buffer length. -/// @param[out] ret_buf Allocated buffer with the result or NULL if ret_len is -/// zero. -/// -/// @return true in case of success, false in case of failure. -static inline bool vim_list_to_buf(const list_T *const list, - size_t *const ret_len, char **const ret_buf) - FUNC_ATTR_NONNULL_ARG(2,3) FUNC_ATTR_WARN_UNUSED_RESULT -{ - size_t len = 0; - if (list != NULL) { - for (const listitem_T *li = list->lv_first; - li != NULL; - li = li->li_next) { - if (li->li_tv.v_type != VAR_STRING) { - return false; - } - len++; - if (li->li_tv.vval.v_string != 0) { - len += STRLEN(li->li_tv.vval.v_string); - } - } - if (len) { - len--; - } - } - *ret_len = len; - if (len == 0) { - *ret_buf = NULL; - return true; - } - ListReaderState lrstate = init_lrstate(list); - char *const buf = xmalloc(len); - size_t read_bytes; - if (read_from_list(&lrstate, buf, len, &read_bytes) != OK) { - assert(false); - } - assert(len == read_bytes); - *ret_buf = buf; - return true; -} - -/// Show a error message when converting to msgpack value -/// -/// @param[in] msg Error message to dump. Must contain exactly two %s that -/// will be replaced with what was being dumped: first with -/// something like “F” or “function argument”, second with path -/// to the failed value. -/// @param[in] mpstack Path to the failed value. -/// @param[in] objname Dumped object name. -/// -/// @return FAIL. -static int conv_error(const char *const msg, const MPConvStack *const mpstack, - const char *const objname) - FUNC_ATTR_NONNULL_ALL -{ - garray_T msg_ga; - ga_init(&msg_ga, (int)sizeof(char), 80); - char *const key_msg = _("key %s"); - char *const key_pair_msg = _("key %s at index %i from special map"); - char *const idx_msg = _("index %i"); - for (size_t i = 0; i < kv_size(*mpstack); i++) { - if (i != 0) { - ga_concat(&msg_ga, (char_u *) ", "); - } - MPConvStackVal v = kv_A(*mpstack, i); - switch (v.type) { - case kMPConvDict: { - typval_T key_tv = { - .v_type = VAR_STRING, - .vval = { .v_string = (v.data.d.hi == NULL - ? v.data.d.dict->dv_hashtab.ht_array - : (v.data.d.hi - 1))->hi_key }, - }; - char *const key = tv2string(&key_tv, NULL); - vim_snprintf((char *) IObuff, IOSIZE, key_msg, key); - xfree(key); - ga_concat(&msg_ga, IObuff); - break; - } - case kMPConvPairs: - case kMPConvList: { - int idx = 0; - const listitem_T *li; - for (li = v.data.l.list->lv_first; - li != NULL && li->li_next != v.data.l.li; - li = li->li_next) { - idx++; - } - if (v.type == kMPConvList - || li == NULL - || (li->li_tv.v_type != VAR_LIST - && li->li_tv.vval.v_list->lv_len <= 0)) { - vim_snprintf((char *) IObuff, IOSIZE, idx_msg, idx); - ga_concat(&msg_ga, IObuff); - } else { - typval_T key_tv = li->li_tv.vval.v_list->lv_first->li_tv; - char *const key = echo_string(&key_tv, NULL); - vim_snprintf((char *) IObuff, IOSIZE, key_pair_msg, key, idx); - xfree(key); - ga_concat(&msg_ga, IObuff); - } - break; - } - } - } - EMSG3(msg, objname, (kv_size(*mpstack) == 0 - ? _("itself") - : (char *) msg_ga.ga_data)); - ga_clear(&msg_ga); - return FAIL; -} - -#define CONV_STRING(buf, len) \ - do { \ - if (buf == NULL) { \ - msgpack_pack_bin(packer, 0); \ - } else { \ - const size_t len_ = (len); \ - msgpack_pack_bin(packer, len_); \ - msgpack_pack_bin_body(packer, buf, len_); \ - } \ - } while (0) - -#define CONV_STR_STRING(buf, len) \ - do { \ - if (buf == NULL) { \ - msgpack_pack_str(packer, 0); \ - } else { \ - const size_t len_ = (len); \ - msgpack_pack_str(packer, len_); \ - msgpack_pack_str_body(packer, buf, len_); \ - } \ - } while (0) - -#define CONV_EXT_STRING(buf, len, type) \ - do { \ - if (buf == NULL) { \ - msgpack_pack_ext(packer, 0, type); \ - } else { \ - const size_t len_ = (len); \ - msgpack_pack_ext(packer, len_, (int8_t) type); \ - msgpack_pack_ext_body(packer, buf, len_); \ - } \ - } while (0) - -#define CONV_NUMBER(num) \ - msgpack_pack_int64(packer, (int64_t) (num)) - -#define CONV_FLOAT(flt) \ - msgpack_pack_double(packer, (double) (flt)) - -#define CONV_FUNC(fun) \ - return conv_error(_("E951: Error while dumping %s, %s: " \ - "attempt to dump function reference"), \ - mpstack, objname) - -#define CONV_EMPTY_LIST() \ - msgpack_pack_array(packer, 0) - -#define CONV_LIST_START(lst) \ - msgpack_pack_array(packer, (lst)->lv_len) - -#define CONV_EMPTY_DICT() \ - msgpack_pack_map(packer, 0) - -#define CONV_SPECIAL_NIL() \ - msgpack_pack_nil(packer) - -#define CONV_SPECIAL_BOOL(num) \ - do { \ - if ((num)) { \ - msgpack_pack_true(packer); \ - } else { \ - msgpack_pack_false(packer); \ - } \ - } while (0) - -#define CONV_UNSIGNED_NUMBER(num) \ - msgpack_pack_uint64(packer, (num)) - -#define CONV_SPECIAL_MAP_START(lst) \ - msgpack_pack_map(packer, (lst)->lv_len) - -#define CONV_DICT_START(dct) \ - msgpack_pack_map(packer, (dct)->dv_hashtab.ht_used) - -#define CONV_DICT_END(dct) - -#define CONV_DICT_AFTER_KEY(dct) - -#define CONV_DICT_BETWEEN_ITEMS(dct) - -#define CONV_LIST_END(lst) - -#define CONV_LIST_BETWEEN_ITEMS(lst) - -#define CONV_RECURSE(val, conv_type) \ - return conv_error(_("E952: Unable to dump %s: " \ - "container references itself in %s"), \ - mpstack, objname) - -#define CONV_ALLOW_SPECIAL true - -DEFINE_VIML_CONV_FUNCTIONS(, msgpack, msgpack_packer *const, packer) - -#undef CONV_STRING -#undef CONV_STR_STRING -#undef CONV_EXT_STRING -#undef CONV_NUMBER -#undef CONV_FLOAT -#undef CONV_FUNC -#undef CONV_EMPTY_LIST -#undef CONV_LIST_START -#undef CONV_EMPTY_DICT -#undef CONV_SPECIAL_NIL -#undef CONV_SPECIAL_BOOL -#undef CONV_UNSIGNED_NUMBER -#undef CONV_SPECIAL_MAP_START -#undef CONV_DICT_START -#undef CONV_DICT_END -#undef CONV_DICT_AFTER_KEY -#undef CONV_DICT_BETWEEN_ITEMS -#undef CONV_LIST_END -#undef CONV_LIST_BETWEEN_ITEMS -#undef CONV_RECURSE -#undef CONV_ALLOW_SPECIAL - /// "msgpackdump()" function static void f_msgpackdump(typval_T *argvars, typval_T *rettv) FUNC_ATTR_NONNULL_ALL @@ -13176,7 +12661,7 @@ static void f_msgpackdump(typval_T *argvars, typval_T *rettv) if (list == NULL) { return; } - msgpack_packer *lpacker = msgpack_packer_new(ret_list, &msgpack_list_write); + msgpack_packer *lpacker = msgpack_packer_new(ret_list, &encode_list_write); const char *const msg = _("msgpackdump() argument, index %i"); // Assume that translation will not take more then 4 times more space char msgbuf[sizeof("msgpackdump() argument, index ") * 4 + NUMBUFLEN]; @@ -13184,307 +12669,13 @@ static void f_msgpackdump(typval_T *argvars, typval_T *rettv) for (listitem_T *li = list->lv_first; li != NULL; li = li->li_next) { vim_snprintf(msgbuf, sizeof(msgbuf), (char *) msg, idx); idx++; - if (vim_to_msgpack(lpacker, &li->li_tv, msgbuf) == FAIL) { + if (encode_vim_to_msgpack(lpacker, &li->li_tv, msgbuf) == FAIL) { break; } } msgpack_packer_free(lpacker); } -/// Read bytes from list -/// -/// @param[in,out] state Structure describing position in list from which -/// reading should start. Is updated to reflect position -/// at which reading ended. -/// @param[out] buf Buffer to write to. -/// @param[in] nbuf Buffer length. -/// @param[out] read_bytes Is set to amount of bytes read. -/// -/// @return OK when reading was finished, FAIL in case of error (i.e. list item -/// was not a string), NOTDONE if reading was successfull, but there are -/// more bytes to read. -static int read_from_list(ListReaderState *const state, char *const buf, - const size_t nbuf, size_t *const read_bytes) - FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT -{ - char *const buf_end = buf + nbuf; - char *p = buf; - while (p < buf_end) { - for (size_t i = state->offset; i < state->li_length && p < buf_end; i++) { - const char ch = state->li->li_tv.vval.v_string[state->offset++]; - *p++ = (ch == NL ? NUL : ch); - } - if (p < buf_end) { - state->li = state->li->li_next; - if (state->li == NULL) { - *read_bytes = (size_t) (p - buf); - return OK; - } - *p++ = NL; - if (state->li->li_tv.v_type != VAR_STRING) { - *read_bytes = (size_t) (p - buf); - return FAIL; - } - state->offset = 0; - state->li_length = (state->li->li_tv.vval.v_string == NULL - ? 0 - : STRLEN(state->li->li_tv.vval.v_string)); - } - } - *read_bytes = nbuf; - return (state->offset < state->li_length || state->li->li_next != NULL - ? NOTDONE - : OK); -} - -/// Initialize ListReaderState structure -static inline ListReaderState init_lrstate(const list_T *const list) - FUNC_ATTR_NONNULL_ALL -{ - return (ListReaderState) { - .li = list->lv_first, - .offset = 0, - .li_length = (list->lv_first->li_tv.vval.v_string == NULL - ? 0 - : STRLEN(list->lv_first->li_tv.vval.v_string)), - }; -} - -/// Convert msgpack object to a VimL one -int msgpack_to_vim(const msgpack_object mobj, typval_T *const rettv) - FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT -{ -#define INIT_SPECIAL_DICT(tv, type, val) \ - do { \ - dict_T *const dict = dict_alloc(); \ - dictitem_T *const type_di = dictitem_alloc((char_u *) "_TYPE"); \ - type_di->di_tv.v_type = VAR_LIST; \ - type_di->di_tv.v_lock = 0; \ - type_di->di_tv.vval.v_list = (list_T *) msgpack_type_lists[type]; \ - type_di->di_tv.vval.v_list->lv_refcount++; \ - dict_add(dict, type_di); \ - dictitem_T *const val_di = dictitem_alloc((char_u *) "_VAL"); \ - val_di->di_tv = val; \ - dict_add(dict, val_di); \ - tv->v_type = VAR_DICT; \ - dict->dv_refcount++; \ - tv->vval.v_dict = dict; \ - } while (0) - switch (mobj.type) { - case MSGPACK_OBJECT_NIL: { - INIT_SPECIAL_DICT(rettv, kMPNil, ((typval_T) { - .v_type = VAR_NUMBER, - .v_lock = 0, - .vval = { .v_number = 0 }, - })); - break; - } - case MSGPACK_OBJECT_BOOLEAN: { - INIT_SPECIAL_DICT(rettv, kMPBoolean, - ((typval_T) { - .v_type = VAR_NUMBER, - .v_lock = 0, - .vval = { - .v_number = (varnumber_T) mobj.via.boolean, - }, - })); - break; - } - case MSGPACK_OBJECT_POSITIVE_INTEGER: { - if (mobj.via.u64 <= VARNUMBER_MAX) { - *rettv = (typval_T) { - .v_type = VAR_NUMBER, - .v_lock = 0, - .vval = { .v_number = (varnumber_T) mobj.via.u64 }, - }; - } else { - list_T *const list = list_alloc(); - list->lv_refcount++; - INIT_SPECIAL_DICT(rettv, kMPInteger, - ((typval_T) { - .v_type = VAR_LIST, - .v_lock = 0, - .vval = { .v_list = list }, - })); - uint64_t n = mobj.via.u64; - list_append_number(list, 1); - list_append_number(list, (varnumber_T) ((n >> 62) & 0x3)); - list_append_number(list, (varnumber_T) ((n >> 31) & 0x7FFFFFFF)); - list_append_number(list, (varnumber_T) (n & 0x7FFFFFFF)); - } - break; - } - case MSGPACK_OBJECT_NEGATIVE_INTEGER: { - if (mobj.via.i64 >= VARNUMBER_MIN) { - *rettv = (typval_T) { - .v_type = VAR_NUMBER, - .v_lock = 0, - .vval = { .v_number = (varnumber_T) mobj.via.i64 }, - }; - } else { - list_T *const list = list_alloc(); - list->lv_refcount++; - INIT_SPECIAL_DICT(rettv, kMPInteger, - ((typval_T) { - .v_type = VAR_LIST, - .v_lock = 0, - .vval = { .v_list = list }, - })); - uint64_t n = -((uint64_t) mobj.via.i64); - list_append_number(list, -1); - list_append_number(list, (varnumber_T) ((n >> 62) & 0x3)); - list_append_number(list, (varnumber_T) ((n >> 31) & 0x7FFFFFFF)); - list_append_number(list, (varnumber_T) (n & 0x7FFFFFFF)); - } - break; - } - case MSGPACK_OBJECT_FLOAT: { - *rettv = (typval_T) { - .v_type = VAR_FLOAT, - .v_lock = 0, - .vval = { .v_float = mobj.via.f64 }, - }; - break; - } - case MSGPACK_OBJECT_STR: { - list_T *const list = list_alloc(); - list->lv_refcount++; - INIT_SPECIAL_DICT(rettv, kMPString, - ((typval_T) { - .v_type = VAR_LIST, - .v_lock = 0, - .vval = { .v_list = list }, - })); - if (msgpack_list_write((void *) list, mobj.via.str.ptr, mobj.via.str.size) - == -1) { - return FAIL; - } - break; - } - case MSGPACK_OBJECT_BIN: { - if (memchr(mobj.via.bin.ptr, NUL, mobj.via.bin.size) == NULL) { - *rettv = (typval_T) { - .v_type = VAR_STRING, - .v_lock = 0, - .vval = { .v_string = xmemdupz(mobj.via.bin.ptr, mobj.via.bin.size) }, - }; - break; - } - list_T *const list = list_alloc(); - list->lv_refcount++; - INIT_SPECIAL_DICT(rettv, kMPBinary, - ((typval_T) { - .v_type = VAR_LIST, - .v_lock = 0, - .vval = { .v_list = list }, - })); - if (msgpack_list_write((void *) list, mobj.via.bin.ptr, mobj.via.bin.size) - == -1) { - return FAIL; - } - break; - } - case MSGPACK_OBJECT_ARRAY: { - list_T *const list = list_alloc(); - list->lv_refcount++; - *rettv = (typval_T) { - .v_type = VAR_LIST, - .v_lock = 0, - .vval = { .v_list = list }, - }; - for (size_t i = 0; i < mobj.via.array.size; i++) { - listitem_T *const li = listitem_alloc(); - li->li_tv.v_type = VAR_UNKNOWN; - list_append(list, li); - if (msgpack_to_vim(mobj.via.array.ptr[i], &li->li_tv) == FAIL) { - return FAIL; - } - } - break; - } - case MSGPACK_OBJECT_MAP: { - for (size_t i = 0; i < mobj.via.map.size; i++) { - if (mobj.via.map.ptr[i].key.type != MSGPACK_OBJECT_STR - || mobj.via.map.ptr[i].key.via.str.size == 0 - || memchr(mobj.via.map.ptr[i].key.via.str.ptr, NUL, - mobj.via.map.ptr[i].key.via.str.size) != NULL) { - goto msgpack_to_vim_generic_map; - } - } - dict_T *const dict = dict_alloc(); - dict->dv_refcount++; - *rettv = (typval_T) { - .v_type = VAR_DICT, - .v_lock = 0, - .vval = { .v_dict = dict }, - }; - for (size_t i = 0; i < mobj.via.map.size; i++) { - dictitem_T *const di = xmallocz(offsetof(dictitem_T, di_key) - + mobj.via.map.ptr[i].key.via.str.size); - memcpy(&di->di_key[0], mobj.via.map.ptr[i].key.via.str.ptr, - mobj.via.map.ptr[i].key.via.str.size); - di->di_tv.v_type = VAR_UNKNOWN; - if (dict_add(dict, di) == FAIL) { - // Duplicate key: fallback to generic map - clear_tv(rettv); - xfree(di); - goto msgpack_to_vim_generic_map; - } - if (msgpack_to_vim(mobj.via.map.ptr[i].val, &di->di_tv) == FAIL) { - return FAIL; - } - } - break; -msgpack_to_vim_generic_map: {} - list_T *const list = list_alloc(); - list->lv_refcount++; - INIT_SPECIAL_DICT(rettv, kMPMap, - ((typval_T) { - .v_type = VAR_LIST, - .v_lock = 0, - .vval = { .v_list = list }, - })); - for (size_t i = 0; i < mobj.via.map.size; i++) { - list_T *const kv_pair = list_alloc(); - list_append_list(list, kv_pair); - listitem_T *const key_li = listitem_alloc(); - key_li->li_tv.v_type = VAR_UNKNOWN; - list_append(kv_pair, key_li); - listitem_T *const val_li = listitem_alloc(); - val_li->li_tv.v_type = VAR_UNKNOWN; - list_append(kv_pair, val_li); - if (msgpack_to_vim(mobj.via.map.ptr[i].key, &key_li->li_tv) == FAIL) { - return FAIL; - } - if (msgpack_to_vim(mobj.via.map.ptr[i].val, &val_li->li_tv) == FAIL) { - return FAIL; - } - } - break; - } - case MSGPACK_OBJECT_EXT: { - list_T *const list = list_alloc(); - list->lv_refcount++; - list_append_number(list, mobj.via.ext.type); - list_T *const ext_val_list = list_alloc(); - list_append_list(list, ext_val_list); - INIT_SPECIAL_DICT(rettv, kMPExt, - ((typval_T) { - .v_type = VAR_LIST, - .v_lock = 0, - .vval = { .v_list = list }, - })); - if (msgpack_list_write((void *) ext_val_list, mobj.via.ext.ptr, - mobj.via.ext.size) == -1) { - return FAIL; - } - break; - } - } -#undef INIT_SPECIAL_DICT - return OK; -} - /// "msgpackparse" function static void f_msgpackparse(typval_T *argvars, typval_T *rettv) FUNC_ATTR_NONNULL_ALL @@ -13502,7 +12693,7 @@ static void f_msgpackparse(typval_T *argvars, typval_T *rettv) EMSG2(_(e_invarg2), "List item is not a string"); return; } - ListReaderState lrstate = init_lrstate(list); + ListReaderState lrstate = encode_init_lrstate(list); msgpack_unpacker *const unpacker = msgpack_unpacker_new(IOSIZE); if (unpacker == NULL) { EMSG(_(e_outofmem)); @@ -13516,7 +12707,7 @@ static void f_msgpackparse(typval_T *argvars, typval_T *rettv) goto f_msgpackparse_exit; } size_t read_bytes; - const int rlret = read_from_list( + const int rlret = encode_read_from_list( &lrstate, msgpack_unpacker_buffer(unpacker), IOSIZE, &read_bytes); if (rlret == FAIL) { EMSG2(_(e_invarg2), "List item is not a string"); @@ -15291,43 +14482,51 @@ static void f_setline(typval_T *argvars, typval_T *rettv) /// replace its content or create a new one. /// @param[in] title_arg New list title. Defaults to caller function name. /// @param[out] rettv Return value: 0 in case of success, -1 otherwise. -static void set_qf_ll_list(win_T *wp, typval_T *list_arg, typval_T *action_arg, - typval_T *title_arg, typval_T *rettv) - FUNC_ATTR_NONNULL_ARG(2, 3, 4, 5) +static void set_qf_ll_list(win_T *wp, typval_T *args, typval_T *rettv) + FUNC_ATTR_NONNULL_ARG(2, 3) { - char_u *act; - int action = ' '; char_u *title = NULL; - + int action = ' '; rettv->vval.v_number = -1; - if (list_arg->v_type != VAR_LIST) + typval_T *list_arg = &args[0]; + if (list_arg->v_type != VAR_LIST) { EMSG(_(e_listreq)); - else { - list_T *l = list_arg->vval.v_list; + return; + } - if (action_arg->v_type != VAR_UNKNOWN) { - act = get_tv_string_chk(action_arg); - if (act == NULL) - return; /* type error; errmsg already given */ - if (*act == 'a' || *act == 'r') - action = *act; - } + typval_T *action_arg = &args[1]; + if (action_arg->v_type == VAR_UNKNOWN) { + // Option argument was not given. + goto skip_args; + } else if (action_arg->v_type != VAR_STRING) { + EMSG(_(e_strreq)); + return; + } + char_u *act = get_tv_string_chk(action_arg); + if (*act == 'a' || *act == 'r') { + action = *act; + } - if (title_arg->v_type == VAR_STRING) { - title = get_tv_string_chk(title_arg); - if (!title) { - return; // type error; errmsg already given - } - } + typval_T *title_arg = &args[2]; + if (title_arg->v_type == VAR_UNKNOWN) { + // Option argument was not given. + goto skip_args; + } + title = get_tv_string_chk(title_arg); + if (!title) { + // Type error. Error already printed by get_tv_string_chk(). + return; + } - if (!title) { - title = (char_u*)(wp ? "setloclist()" : "setqflist()"); - } +skip_args: + if (!title) { + title = (char_u*)(wp ? "setloclist()" : "setqflist()"); + } - if (l && set_errorlist(wp, l, action, title) == OK) { - rettv->vval.v_number = 0; - } + list_T *l = list_arg->vval.v_list; + if (l && set_errorlist(wp, l, action, title) == OK) { + rettv->vval.v_number = 0; } } @@ -15342,7 +14541,7 @@ static void f_setloclist(typval_T *argvars, typval_T *rettv) win = find_win_by_nr(&argvars[0], NULL); if (win != NULL) { - set_qf_ll_list(win, &argvars[1], &argvars[2], &argvars[3], rettv); + set_qf_ll_list(win, &argvars[1], rettv); } } @@ -15479,7 +14678,7 @@ static void f_setpos(typval_T *argvars, typval_T *rettv) */ static void f_setqflist(typval_T *argvars, typval_T *rettv) { - set_qf_ll_list(NULL, &argvars[0], &argvars[1], &argvars[2], rettv); + set_qf_ll_list(NULL, argvars, rettv); } /* @@ -15786,9 +14985,9 @@ static int item_compare(const void *s1, const void *s2, bool keep_zero) return v1 == v2 ? 0 : v1 > v2 ? 1 : -1; } - // tv2string() puts quotes around a string and allocates memory. Don't do - // that for string variables. Use a single quote when comparing with a - // non-string to do what the docs promise. + // encode_tv2string() puts quotes around a string and allocates memory. Don't + // do that for string variables. Use a single quote when comparing with + // a non-string to do what the docs promise. if (tv1->v_type == VAR_STRING) { if (tv2->v_type != VAR_STRING || item_compare_numeric) { p1 = (char_u *)"'"; @@ -15796,7 +14995,7 @@ static int item_compare(const void *s1, const void *s2, bool keep_zero) p1 = tv1->vval.v_string; } } else { - tofree1 = p1 = (char_u *) tv2string(tv1, NULL); + tofree1 = p1 = (char_u *) encode_tv2string(tv1, NULL); } if (tv2->v_type == VAR_STRING) { if (tv1->v_type != VAR_STRING || item_compare_numeric) { @@ -15805,7 +15004,7 @@ static int item_compare(const void *s1, const void *s2, bool keep_zero) p2 = tv2->vval.v_string; } } else { - tofree2 = p2 = (char_u *) tv2string(tv2, NULL); + tofree2 = p2 = (char_u *) encode_tv2string(tv2, NULL); } if (p1 == NULL) p1 = (char_u *)""; @@ -16249,7 +15448,7 @@ static void f_str2float(typval_T *argvars, typval_T *rettv) if (*p == '+') p = skipwhite(p + 1); - (void)string2float(p, &rettv->vval.v_float); + (void) string2float((char *) p, &rettv->vval.v_float); rettv->v_type = VAR_FLOAT; } @@ -16380,7 +15579,7 @@ static void f_stridx(typval_T *argvars, typval_T *rettv) static void f_string(typval_T *argvars, typval_T *rettv) { rettv->v_type = VAR_STRING; - rettv->vval.v_string = (char_u *) tv2string(&argvars[0], NULL); + rettv->vval.v_string = (char_u *) encode_tv2string(&argvars[0], NULL); } /* @@ -17113,9 +16312,9 @@ static void f_termopen(typval_T *argvars, typval_T *rettv) // Save the job id and pid in b:terminal_job_{id,pid} Error err; dict_set_value(curbuf->b_vars, cstr_as_string("terminal_job_id"), - INTEGER_OBJ(rettv->vval.v_number), &err); + INTEGER_OBJ(rettv->vval.v_number), false, &err); dict_set_value(curbuf->b_vars, cstr_as_string("terminal_job_pid"), - INTEGER_OBJ(pid), &err); + INTEGER_OBJ(pid), false, &err); Terminal *term = terminal_open(topts); data->term = term; @@ -17301,16 +16500,33 @@ static void f_trunc(typval_T *argvars, typval_T *rettv) */ static void f_type(typval_T *argvars, typval_T *rettv) { - int n; + int n = -1; switch (argvars[0].v_type) { - case VAR_NUMBER: n = 0; break; - case VAR_STRING: n = 1; break; - case VAR_FUNC: n = 2; break; - case VAR_LIST: n = 3; break; - case VAR_DICT: n = 4; break; - case VAR_FLOAT: n = 5; break; - default: EMSG2(_(e_intern2), "f_type()"); n = 0; break; + case VAR_NUMBER: n = 0; break; + case VAR_STRING: n = 1; break; + case VAR_FUNC: n = 2; break; + case VAR_LIST: n = 3; break; + case VAR_DICT: n = 4; break; + case VAR_FLOAT: n = 5; break; + case VAR_SPECIAL: { + switch (argvars[0].vval.v_special) { + case kSpecialVarTrue: + case kSpecialVarFalse: { + n = 6; + break; + } + case kSpecialVarNull: { + n = 7; + break; + } + } + break; + } + case VAR_UNKNOWN: { + EMSG2(_(e_intern2), "f_type(UNKNOWN)"); + break; + } } rettv->vval.v_number = n; } @@ -17889,21 +17105,28 @@ static int get_env_len(char_u **arg) return len; } -/* - * Get the length of the name of a function or internal variable. - * "arg" is advanced to the first non-white character after the name. - * Return 0 if something is wrong. - */ -static int get_id_len(char_u **arg) -{ - char_u *p; +// Get the length of the name of a function or internal variable. +// "arg" is advanced to the first non-white character after the name. +// Return 0 if something is wrong. +static int get_id_len(char_u **arg) { + char_u *p; int len; - /* Find the end of the name. */ - for (p = *arg; eval_isnamec(*p); ++p) - ; - if (p == *arg) /* no name found */ + // Find the end of the name. + for (p = *arg; eval_isnamec(*p); p++) { + if (*p == ':') { + // "s:" is start of "s:var", but "n:" is not and can be used in + // slice "[n:]". Also "xx:" is not a namespace. + len = (int)(p - *arg); + if (len > 1 + || (len == 1 && vim_strchr(namespace_char, **arg) == NULL)) { + break; + } + } + } + if (p == *arg) { // no name found return 0; + } len = (int)(p - *arg); *arg = skipwhite(p); @@ -17974,28 +17197,29 @@ static int get_name_len(char_u **arg, char_u **alias, int evaluate, int verbose) return len; } -/* - * Find the end of a variable or function name, taking care of magic braces. - * If "expr_start" is not NULL then "expr_start" and "expr_end" are set to the - * start and end of the first magic braces item. - * "flags" can have FNE_INCL_BR and FNE_CHECK_START. - * Return a pointer to just after the name. Equal to "arg" if there is no - * valid name. - */ -static char_u *find_name_end(char_u *arg, char_u **expr_start, char_u **expr_end, int flags) +// Find the end of a variable or function name, taking care of magic braces. +// If "expr_start" is not NULL then "expr_start" and "expr_end" are set to the +// start and end of the first magic braces item. +// "flags" can have FNE_INCL_BR and FNE_CHECK_START. +// Return a pointer to just after the name. Equal to "arg" if there is no +// valid name. +static char_u *find_name_end(char_u *arg, char_u **expr_start, + char_u **expr_end, int flags) { int mb_nest = 0; int br_nest = 0; - char_u *p; + char_u *p; + int len; if (expr_start != NULL) { *expr_start = NULL; *expr_end = NULL; } - /* Quick check for valid starting character. */ - if ((flags & FNE_CHECK_START) && !eval_isnamec1(*arg) && *arg != '{') + // Quick check for valid starting character. + if ((flags & FNE_CHECK_START) && !eval_isnamec1(*arg) && *arg != '{') { return arg; + } for (p = arg; *p != NUL && (eval_isnamec(*p) @@ -18010,30 +17234,44 @@ static char_u *find_name_end(char_u *arg, char_u **expr_start, char_u **expr_end if (*p == NUL) break; } else if (*p == '"') { - /* skip over "str\"ing" to avoid counting [ and ] inside it. */ - for (p = p + 1; *p != NUL && *p != '"'; mb_ptr_adv(p)) - if (*p == '\\' && p[1] != NUL) + // skip over "str\"ing" to avoid counting [ and ] inside it. + for (p = p + 1; *p != NUL && *p != '"'; mb_ptr_adv(p)) { + if (*p == '\\' && p[1] != NUL) { ++p; - if (*p == NUL) + } + } + if (*p == NUL) { + break; + } + } else if (br_nest == 0 && mb_nest == 0 && *p == ':') { + // "s:" is start of "s:var", but "n:" is not and can be used in + // slice "[n:]". Also "xx:" is not a namespace. But {ns}: is. */ + len = (int)(p - arg); + if ((len > 1 && p[-1] != '}') + || (len == 1 && vim_strchr(namespace_char, *arg) == NULL)) { break; + } } if (mb_nest == 0) { - if (*p == '[') + if (*p == '[') { ++br_nest; - else if (*p == ']') + } else if (*p == ']') { --br_nest; + } } if (br_nest == 0) { if (*p == '{') { mb_nest++; - if (expr_start != NULL && *expr_start == NULL) + if (expr_start != NULL && *expr_start == NULL) { *expr_start = p; + } } else if (*p == '}') { mb_nest--; - if (expr_start != NULL && mb_nest == 0 && *expr_end == NULL) + if (expr_start != NULL && mb_nest == 0 && *expr_end == NULL) { *expr_end = p; + } } } } @@ -18115,14 +17353,6 @@ static int eval_isnamec1(int c) } /* - * Set number v: variable to "val". - */ -void set_vim_var_nr(int idx, long val) -{ - vimvars[idx].vv_nr = val; -} - -/* * Get number v: variable value. */ long get_vim_var_nr(int idx) FUNC_ATTR_PURE @@ -18159,11 +17389,11 @@ dict_T *get_vim_var_dict(int idx) FUNC_ATTR_PURE */ void set_vim_var_char(int c) { - char_u buf[MB_MAXBYTES + 1]; + char buf[MB_MAXBYTES + 1]; - if (has_mbyte) - buf[(*mb_char2bytes)(c, buf)] = NUL; - else { + if (has_mbyte) { + buf[(*mb_char2bytes)(c, (char_u *) buf)] = NUL; + } else { buf[0] = c; buf[1] = NUL; } @@ -18182,47 +17412,68 @@ void set_vcount(long count, long count1, int set_prevcount) vimvars[VV_COUNT1].vv_nr = count1; } -/* - * Set string v: variable to a copy of "val". - */ -void set_vim_var_string ( - int idx, - char_u *val, - int len /* length of "val" to use or -1 (whole string) */ -) +/// Set number v: variable to the given value +/// +/// @param[in] idx Index of variable to set. +/// @param[in] val Value to set to. +void set_vim_var_nr(const VimVarIndex idx, const varnumber_T val) { - /* Need to do this (at least) once, since we can't initialize a union. - * Will always be invoked when "v:progname" is set. */ - vimvars[VV_VERSION].vv_nr = VIM_VERSION_100; + vimvars[idx].vv_nr = val; +} + +/// Set special v: variable to the given value +/// +/// @param[in] idx Index of variable to set. +/// @param[in] val Value to set to. +void set_vim_var_special(const VimVarIndex idx, const SpecialVarValue val) +{ + vimvars[idx].vv_special = val; +} +/// Set string v: variable to the given string +/// +/// @param[in] idx Index of variable to set. +/// @param[in] val Value to set to. Will be copied. +/// @param[in] len Legth of that value or -1 in which case strlen() will be +/// used. +void set_vim_var_string(const VimVarIndex idx, const char *const val, + const ptrdiff_t len) +{ xfree(vimvars[idx].vv_str); - if (val == NULL) + if (val == NULL) { vimvars[idx].vv_str = NULL; - else if (len == -1) - vimvars[idx].vv_str = vim_strsave(val); - else - vimvars[idx].vv_str = vim_strnsave(val, len); + } else if (len == -1) { + vimvars[idx].vv_str = (char_u *) xstrdup(val); + } else { + vimvars[idx].vv_str = (char_u *) xstrndup(val, (size_t) len); + } } -/* - * Set List v: variable to "val". - */ -void set_vim_var_list(int idx, list_T *val) +/// Set list v: variable to the given list +/// +/// @param[in] idx Index of variable to set. +/// @param[in,out] val Value to set to. Reference count will be incremented. +void set_vim_var_list(const VimVarIndex idx, list_T *const val) { list_unref(vimvars[idx].vv_list); vimvars[idx].vv_list = val; - if (val != NULL) - ++val->lv_refcount; + if (val != NULL) { + val->lv_refcount++; + } } -/// Set Dictionary v: variable to "val". -void set_vim_var_dict(int idx, dict_T *val) +/// Set Dictionary v: variable to the given dictionary +/// +/// @param[in] idx Index of variable to set. +/// @param[in,out] val Value to set to. Reference count will be incremented. +/// Also keys of the dictionary will be made read-only. +void set_vim_var_dict(const VimVarIndex idx, dict_T *const val) { dict_unref(vimvars[idx].vv_dict); vimvars[idx].vv_dict = val; if (val != NULL) { - ++val->dv_refcount; + val->dv_refcount++; // Set readonly dict_set_keys_readonly(val); } @@ -18233,15 +17484,17 @@ void set_vim_var_dict(int idx, dict_T *val) */ void set_reg_var(int c) { - char_u regname; + char regname; - if (c == 0 || c == ' ') + if (c == 0 || c == ' ') { regname = '"'; - else + } else { regname = c; - /* Avoid free/alloc when the value is already right. */ - if (vimvars[VV_REG].vv_str == NULL || vimvars[VV_REG].vv_str[0] != c) + } + // Avoid free/alloc when the value is already right. + if (vimvars[VV_REG].vv_str == NULL || vimvars[VV_REG].vv_str[0] != c) { set_vim_var_string(VV_REG, ®name, 1); + } } /* @@ -18471,25 +17724,23 @@ void free_tv(typval_T *varp) { if (varp != NULL) { switch (varp->v_type) { - case VAR_FUNC: - func_unref(varp->vval.v_string); - /*FALLTHROUGH*/ - case VAR_STRING: - xfree(varp->vval.v_string); - break; - case VAR_LIST: - list_unref(varp->vval.v_list); - break; - case VAR_DICT: - dict_unref(varp->vval.v_dict); - break; - case VAR_NUMBER: - case VAR_FLOAT: - case VAR_UNKNOWN: - break; - default: - EMSG2(_(e_intern2), "free_tv()"); - break; + case VAR_FUNC: + func_unref(varp->vval.v_string); + // FALLTHROUGH + case VAR_STRING: + xfree(varp->vval.v_string); + break; + case VAR_LIST: + list_unref(varp->vval.v_list); + break; + case VAR_DICT: + dict_unref(varp->vval.v_dict); + break; + case VAR_SPECIAL: + case VAR_NUMBER: + case VAR_FLOAT: + case VAR_UNKNOWN: + break; } xfree(varp); } @@ -18527,10 +17778,11 @@ void clear_tv(typval_T *varp) case VAR_FLOAT: varp->vval.v_float = 0.0; break; + case VAR_SPECIAL: + varp->vval.v_special = kSpecialVarFalse; + break; case VAR_UNKNOWN: break; - default: - EMSG2(_(e_intern2), "clear_tv()"); } varp->v_lock = 0; } @@ -18585,8 +17837,19 @@ long get_tv_number_chk(typval_T *varp, int *denote) case VAR_DICT: EMSG(_("E728: Using a Dictionary as a Number")); break; - default: - EMSG2(_(e_intern2), "get_tv_number()"); + case VAR_SPECIAL: + switch (varp->vval.v_special) { + case kSpecialVarTrue: { + return 1; + } + case kSpecialVarFalse: + case kSpecialVarNull: { + return 0; + } + } + break; + case VAR_UNKNOWN: + EMSG2(_(e_intern2), "get_tv_number(UNKNOWN)"); break; } if (denote == NULL) { @@ -18718,8 +17981,11 @@ static char_u *get_tv_string_buf_chk(const typval_T *varp, char_u *buf) if (varp->vval.v_string != NULL) return varp->vval.v_string; return (char_u *)""; - default: - EMSG2(_(e_intern2), "get_tv_string_buf()"); + case VAR_SPECIAL: + STRCPY(buf, encode_special_var_names[varp->vval.v_special]); + return buf; + case VAR_UNKNOWN: + EMSG(_("E908: using an invalid value as a String")); break; } return NULL; @@ -18990,7 +18256,7 @@ static void delete_var(hashtab_T *ht, hashitem_T *hi) */ static void list_one_var(dictitem_T *v, char_u *prefix, int *first) { - char_u *s = (char_u *) echo_string(&v->di_tv, NULL); + char_u *s = (char_u *) encode_tv2echo(&v->di_tv, NULL); list_one_var_a(prefix, v->di_key, v->di_tv.v_type, s == NULL ? (char_u *)"" : s, first); xfree(s); @@ -19267,42 +18533,34 @@ void copy_tv(typval_T *from, typval_T *to) { to->v_type = from->v_type; to->v_lock = 0; + memmove(&to->vval, &from->vval, sizeof(to->vval)); switch (from->v_type) { - case VAR_NUMBER: - to->vval.v_number = from->vval.v_number; - break; - case VAR_FLOAT: - to->vval.v_float = from->vval.v_float; - break; - case VAR_STRING: - case VAR_FUNC: - if (from->vval.v_string == NULL) - to->vval.v_string = NULL; - else { - to->vval.v_string = vim_strsave(from->vval.v_string); - if (from->v_type == VAR_FUNC) - func_ref(to->vval.v_string); - } - break; - case VAR_LIST: - if (from->vval.v_list == NULL) - to->vval.v_list = NULL; - else { - to->vval.v_list = from->vval.v_list; - ++to->vval.v_list->lv_refcount; - } - break; - case VAR_DICT: - if (from->vval.v_dict == NULL) - to->vval.v_dict = NULL; - else { - to->vval.v_dict = from->vval.v_dict; - ++to->vval.v_dict->dv_refcount; - } - break; - default: - EMSG2(_(e_intern2), "copy_tv()"); - break; + case VAR_NUMBER: + case VAR_FLOAT: + case VAR_SPECIAL: + break; + case VAR_STRING: + case VAR_FUNC: + if (from->vval.v_string != NULL) { + to->vval.v_string = vim_strsave(from->vval.v_string); + if (from->v_type == VAR_FUNC) { + func_ref(to->vval.v_string); + } + } + break; + case VAR_LIST: + if (from->vval.v_list != NULL) { + to->vval.v_list->lv_refcount++; + } + break; + case VAR_DICT: + if (from->vval.v_dict != NULL) { + to->vval.v_dict->dv_refcount++; + } + break; + case VAR_UNKNOWN: + EMSG2(_(e_intern2), "copy_tv(UNKNOWN)"); + break; } } @@ -19342,6 +18600,7 @@ int var_item_copy(const vimconv_T *const conv, case VAR_NUMBER: case VAR_FLOAT: case VAR_FUNC: + case VAR_SPECIAL: copy_tv(from, to); break; case VAR_STRING: @@ -19388,8 +18647,8 @@ int var_item_copy(const vimconv_T *const conv, if (to->vval.v_dict == NULL) ret = FAIL; break; - default: - EMSG2(_(e_intern2), "var_item_copy()"); + case VAR_UNKNOWN: + EMSG2(_(e_intern2), "var_item_copy(UNKNOWN)"); ret = FAIL; } --recurse; @@ -19444,7 +18703,7 @@ void ex_echo(exarg_T *eap) } } else if (eap->cmdidx == CMD_echo) msg_puts_attr((char_u *)" ", echo_attr); - char_u *tofree = p = (char_u *) echo_string(&rettv, NULL); + char_u *tofree = p = (char_u *) encode_tv2echo(&rettv, NULL); if (p != NULL) { for (; *p != NUL && !got_int; ++p) { if (*p == '\n' || *p == '\r' || *p == TAB) { @@ -21058,15 +20317,22 @@ call_user_func ( save_sourcing_name = sourcing_name; save_sourcing_lnum = sourcing_lnum; sourcing_lnum = 1; - // need space for function name + ("function " + 3) or "[number]" + // need space for new sourcing_name: + // * save_sourcing_name + // * "["number"].." or "function " + // * "<SNR>" + fp->uf_name - 3 + // * terminating NUL size_t len = (save_sourcing_name == NULL ? 0 : STRLEN(save_sourcing_name)) - + STRLEN(fp->uf_name) + 20; + + STRLEN(fp->uf_name) + 27; sourcing_name = xmalloc(len); { if (save_sourcing_name != NULL && STRNCMP(save_sourcing_name, "function ", 9) == 0) { - vim_snprintf((char *)sourcing_name, len, "%s[%zu]..", - save_sourcing_name, save_sourcing_lnum); + vim_snprintf((char *)sourcing_name, + len, + "%s[%" PRId64 "]..", + save_sourcing_name, + (int64_t)save_sourcing_lnum); } else { STRCPY(sourcing_name, "function "); } @@ -21089,10 +20355,10 @@ call_user_func ( msg_outnum((long)argvars[i].vval.v_number); } else { // Do not want errors such as E724 here. - ++emsg_off; - char_u *s = (char_u *) tv2string(&argvars[i], NULL); + emsg_off++; + char_u *s = (char_u *) encode_tv2string(&argvars[i], NULL); char_u *tofree = s; - --emsg_off; + emsg_off--; if (s != NULL) { if (vim_strsize(s) > MSG_BUF_CLEN) { trunc_string(s, buf, MSG_BUF_CLEN, MSG_BUF_LEN); @@ -21183,10 +20449,10 @@ call_user_func ( // The value may be very long. Skip the middle part, so that we // have some idea how it starts and ends. smsg() would always // truncate it at the end. Don't want errors such as E724 here. - ++emsg_off; - char_u *s = (char_u *) tv2string(fc->rettv, NULL); + emsg_off++; + char_u *s = (char_u *) encode_tv2string(fc->rettv, NULL); char_u *tofree = s; - --emsg_off; + emsg_off--; if (s != NULL) { if (vim_strsize(s) > MSG_BUF_CLEN) { trunc_string(s, buf, MSG_BUF_CLEN, MSG_BUF_LEN); @@ -21457,7 +20723,7 @@ char_u *get_return_cmd(void *rettv) char_u *tofree = NULL; if (rettv != NULL) { - tofree = s = (char_u *) echo_string((typval_T *) rettv, NULL); + tofree = s = (char_u *) encode_tv2echo((typval_T *) rettv, NULL); } if (s == NULL) { s = (char_u *)""; @@ -22036,7 +21302,15 @@ repeat: } if (src[*usedlen] == ':' && src[*usedlen + 1] == 'S') { + // vim_strsave_shellescape() needs a NUL terminated string. + c = (*fnamep)[*fnamelen]; + if (c != NUL) { + (*fnamep)[*fnamelen] = NUL; + } p = vim_strsave_shellescape(*fnamep, false, false); + if (c != NUL) { + (*fnamep)[*fnamelen] = c; + } xfree(*bufp); *bufp = *fnamep = p; *fnamelen = STRLEN(p); @@ -22332,7 +21606,7 @@ static void on_process_exit(Process *proc, int status, void *d) TerminalJobData *data = d; if (data->term && !data->exited) { data->exited = true; - char msg[22]; + char msg[sizeof("\r\n[Process exited ]") + NUMBUFLEN]; snprintf(msg, sizeof msg, "\r\n[Process exited %d]", proc->status); terminal_close(data->term, msg); } diff --git a/src/nvim/eval.h b/src/nvim/eval.h index f51b0f4921..d6800afd52 100644 --- a/src/nvim/eval.h +++ b/src/nvim/eval.h @@ -1,12 +1,17 @@ #ifndef NVIM_EVAL_H #define NVIM_EVAL_H -#include <msgpack.h> - #include "nvim/profile.h" +#include "nvim/hashtab.h" // For hashtab_T +#include "nvim/garray.h" // For garray_T +#include "nvim/buffer_defs.h" // For scid_T +#include "nvim/ex_cmds_defs.h" // For exarg_T + +#define COPYID_INC 2 +#define COPYID_MASK (~0x1) // All user-defined functions are found in this hashtable. -EXTERN hashtab_T func_hashtab; +extern hashtab_T func_hashtab; // Structure to hold info for a user function. typedef struct ufunc ufunc_T; @@ -46,8 +51,8 @@ EXTERN ufunc_T dumuf; #define HIKEY2UF(p) ((ufunc_T *)(p - (dumuf.uf_name - (char_u *)&dumuf))) #define HI2UF(hi) HIKEY2UF((hi)->hi_key) -/* Defines for Vim variables. These must match vimvars[] in eval.c! */ -enum { +/// Defines for Vim variables +typedef enum { VV_COUNT, VV_COUNT1, VV_PREVCOUNT, @@ -114,15 +119,35 @@ enum { VV_ERRORS, VV_MSGPACK_TYPES, VV_EVENT, - VV_LEN, // number of v: vars -}; + VV_FALSE, + VV_TRUE, + VV_NULL, + VV__NULL_LIST, // List with NULL value. For test purposes only. + VV__NULL_DICT, // Dictionary with NULL value. For test purposes only. +} VimVarIndex; + +/// All recognized msgpack types +typedef enum { + kMPNil, + kMPBoolean, + kMPInteger, + kMPFloat, + kMPString, + kMPBinary, + kMPArray, + kMPMap, + kMPExt, +#define LAST_MSGPACK_TYPE kMPExt +} MessagePackType; + +/// Array mapping values from MessagePackType to corresponding list pointers +extern const list_T *eval_msgpack_type_lists[LAST_MSGPACK_TYPE + 1]; + +#undef LAST_MSGPACK_TYPE /// Maximum number of function arguments #define MAX_FUNC_ARGS 20 -int vim_to_msgpack(msgpack_packer *const, typval_T *const, - const char *const objname); - #ifdef INCLUDE_GENERATED_DECLARATIONS # include "eval.h.generated.h" #endif diff --git a/src/nvim/eval/decode.c b/src/nvim/eval/decode.c new file mode 100644 index 0000000000..0774ef515f --- /dev/null +++ b/src/nvim/eval/decode.c @@ -0,0 +1,1116 @@ +#include <stddef.h> + +#include <msgpack.h> + +#include "nvim/eval_defs.h" +#include "nvim/eval.h" +#include "nvim/eval/encode.h" +#include "nvim/ascii.h" +#include "nvim/message.h" +#include "nvim/charset.h" // vim_str2nr +#include "nvim/lib/kvec.h" +#include "nvim/vim.h" // OK, FAIL + +/// Helper structure for container_struct +typedef struct { + size_t stack_index; ///< Index of current container in stack. + list_T *special_val; ///< _VAL key contents for special maps. + ///< When container is not a special dictionary it is + ///< NULL. + const char *s; ///< Location where container starts. + typval_T container; ///< Container. Either VAR_LIST, VAR_DICT or VAR_LIST + ///< which is _VAL from special dictionary. +} ContainerStackItem; + +/// Helper structure for values struct +typedef struct { + bool is_special_string; ///< Indicates that current value is a special + ///< dictionary with string. + bool didcomma; ///< True if previous token was comma. + bool didcolon; ///< True if previous token was colon. + typval_T val; ///< Actual value. +} ValuesStackItem; + +/// Vector containing values not yet saved in any container +typedef kvec_t(ValuesStackItem) ValuesStack; + +/// Vector containing containers, each next container is located inside previous +typedef kvec_t(ContainerStackItem) ContainerStack; + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "eval/decode.c.generated.h" +#endif + +/// Create special dictionary +/// +/// @param[out] rettv Location where created dictionary will be saved. +/// @param[in] type Type of the dictionary. +/// @param[in] val Value associated with the _VAL key. +static inline void create_special_dict(typval_T *const rettv, + const MessagePackType type, + typval_T val) + FUNC_ATTR_NONNULL_ALL +{ + dict_T *const dict = dict_alloc(); + dictitem_T *const type_di = dictitem_alloc((char_u *) "_TYPE"); + type_di->di_tv.v_type = VAR_LIST; + type_di->di_tv.v_lock = VAR_UNLOCKED; + type_di->di_tv.vval.v_list = (list_T *) eval_msgpack_type_lists[type]; + type_di->di_tv.vval.v_list->lv_refcount++; + dict_add(dict, type_di); + dictitem_T *const val_di = dictitem_alloc((char_u *) "_VAL"); + val_di->di_tv = val; + dict_add(dict, val_di); + dict->dv_refcount++; + *rettv = (typval_T) { + .v_type = VAR_DICT, + .v_lock = VAR_UNLOCKED, + .vval = { .v_dict = dict }, + }; +} + +#define DICT_LEN(dict) (dict)->dv_hashtab.ht_used + +/// Helper function used for working with stack vectors used by JSON decoder +/// +/// @param[in,out] obj New object. Will either be put into the stack (and, +/// probably, also inside container) or freed. +/// @param[out] stack Object stack. +/// @param[out] container_stack Container objects stack. +/// @param[in,out] pp Position in string which is currently being parsed. Used +/// for error reporting and is also set when decoding is +/// restarted due to the necessity of converting regular +/// dictionary to a special map. +/// @param[out] next_map_special Is set to true when dictionary needs to be +/// converted to a special map, otherwise not +/// touched. Indicates that decoding has been +/// restarted. +/// @param[out] didcomma True if previous token was comma. Is set to recorded +/// value when decoder is restarted, otherwise unused. +/// @param[out] didcolon True if previous token was colon. Is set to recorded +/// value when decoder is restarted, otherwise unused. +/// +/// @return OK in case of success, FAIL in case of error. +static inline int json_decoder_pop(ValuesStackItem obj, + ValuesStack *const stack, + ContainerStack *const container_stack, + const char **const pp, + bool *const next_map_special, + bool *const didcomma, + bool *const didcolon) + FUNC_ATTR_NONNULL_ALL +{ + if (kv_size(*container_stack) == 0) { + kv_push(ValuesStackItem, *stack, obj); + return OK; + } + ContainerStackItem last_container = kv_last(*container_stack); + const char *val_location = *pp; + if (obj.val.v_type == last_container.container.v_type + // vval.v_list and vval.v_dict should have the same size and offset + && ((void *) obj.val.vval.v_list + == (void *) last_container.container.vval.v_list)) { + (void) kv_pop(*container_stack); + val_location = last_container.s; + last_container = kv_last(*container_stack); + } + if (last_container.container.v_type == VAR_LIST) { + if (last_container.container.vval.v_list->lv_len != 0 + && !obj.didcomma) { + EMSG2(_("E474: Expected comma before list item: %s"), val_location); + clear_tv(&obj.val); + return FAIL; + } + assert(last_container.special_val == NULL); + listitem_T *obj_li = listitem_alloc(); + obj_li->li_tv = obj.val; + list_append(last_container.container.vval.v_list, obj_li); + } else if (last_container.stack_index == kv_size(*stack) - 2) { + if (!obj.didcolon) { + EMSG2(_("E474: Expected colon before dictionary value: %s"), + val_location); + clear_tv(&obj.val); + return FAIL; + } + ValuesStackItem key = kv_pop(*stack); + if (last_container.special_val == NULL) { + // These cases should have already been handled. + assert(!(key.is_special_string + || key.val.vval.v_string == NULL + || *key.val.vval.v_string == NUL)); + dictitem_T *obj_di = dictitem_alloc(key.val.vval.v_string); + clear_tv(&key.val); + if (dict_add(last_container.container.vval.v_dict, obj_di) + == FAIL) { + assert(false); + } + obj_di->di_tv = obj.val; + } else { + list_T *const kv_pair = list_alloc(); + list_append_list(last_container.special_val, kv_pair); + listitem_T *const key_li = listitem_alloc(); + key_li->li_tv = key.val; + list_append(kv_pair, key_li); + listitem_T *const val_li = listitem_alloc(); + val_li->li_tv = obj.val; + list_append(kv_pair, val_li); + } + } else { + // Object with key only + if (!obj.is_special_string && obj.val.v_type != VAR_STRING) { + EMSG2(_("E474: Expected string key: %s"), *pp); + clear_tv(&obj.val); + return FAIL; + } else if (!obj.didcomma + && (last_container.special_val == NULL + && (DICT_LEN(last_container.container.vval.v_dict) != 0))) { + EMSG2(_("E474: Expected comma before dictionary key: %s"), val_location); + clear_tv(&obj.val); + return FAIL; + } + // Handle empty key and key represented as special dictionary + if (last_container.special_val == NULL + && (obj.is_special_string + || obj.val.vval.v_string == NULL + || *obj.val.vval.v_string == NUL + || dict_find(last_container.container.vval.v_dict, + obj.val.vval.v_string, -1))) { + clear_tv(&obj.val); + + // Restart + (void) kv_pop(*container_stack); + ValuesStackItem last_container_val = + kv_A(*stack, last_container.stack_index); + while (kv_size(*stack) > last_container.stack_index) { + clear_tv(&(kv_pop(*stack).val)); + } + *pp = last_container.s; + *didcomma = last_container_val.didcomma; + *didcolon = last_container_val.didcolon; + *next_map_special = true; + return OK; + } + kv_push(ValuesStackItem, *stack, obj); + } + return OK; +} + +#define LENP(p, e) \ + ((int) ((e) - (p))), (p) +#define OBJ(obj_tv, is_sp_string, didcomma_, didcolon_) \ + ((ValuesStackItem) { \ + .is_special_string = (is_sp_string), \ + .val = (obj_tv), \ + .didcomma = (didcomma_), \ + .didcolon = (didcolon_), \ + }) + +#define POP(obj_tv, is_sp_string) \ + do { \ + if (json_decoder_pop(OBJ(obj_tv, is_sp_string, *didcomma, *didcolon), \ + stack, container_stack, \ + &p, next_map_special, didcomma, didcolon) \ + == FAIL) { \ + goto parse_json_string_fail; \ + } \ + if (*next_map_special) { \ + goto parse_json_string_ret; \ + } \ + } while (0) + +/// Parse JSON double-quoted string +/// +/// @param[in] conv Defines conversion necessary to convert UTF-8 string to +/// &encoding. +/// @param[in] buf Buffer being converted. +/// @param[in] buf_len Length of the buffer. +/// @param[in,out] pp Pointer to the start of the string. Must point to '"'. +/// Is advanced to the closing '"'. Also see +/// json_decoder_pop(), it may set pp to another location +/// and alter next_map_special, didcomma and didcolon. +/// @param[out] stack Object stack. +/// @param[out] container_stack Container objects stack. +/// @param[out] next_map_special Is set to true when dictionary is converted +/// to a special map, otherwise not touched. +/// @param[out] didcomma True if previous token was comma. Is set to recorded +/// value when decoder is restarted, otherwise unused. +/// @param[out] didcolon True if previous token was colon. Is set to recorded +/// value when decoder is restarted, otherwise unused. +/// +/// @return OK in case of success, FAIL in case of error. +static inline int parse_json_string(vimconv_T *const conv, + const char *const buf, const size_t buf_len, + const char **const pp, + ValuesStack *const stack, + ContainerStack *const container_stack, + bool *const next_map_special, + bool *const didcomma, + bool *const didcolon) + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_ALWAYS_INLINE +{ + const char *const e = buf + buf_len; + const char *p = *pp; + size_t len = 0; + const char *const s = ++p; + int ret = OK; + while (p < e && *p != '"') { + if (*p == '\\') { + p++; + if (p == e) { + emsgf(_("E474: Unfinished escape sequence: %.*s"), + (int) buf_len, buf); + goto parse_json_string_fail; + } + switch (*p) { + case 'u': { + if (p + 4 >= e) { + emsgf(_("E474: Unfinished unicode escape sequence: %.*s"), + (int) buf_len, buf); + goto parse_json_string_fail; + } else if (!ascii_isxdigit(p[1]) + || !ascii_isxdigit(p[2]) + || !ascii_isxdigit(p[3]) + || !ascii_isxdigit(p[4])) { + emsgf(_("E474: Expected four hex digits after \\u: %.*s"), + LENP(p - 1, e)); + goto parse_json_string_fail; + } + // One UTF-8 character below U+10000 can take up to 3 bytes, + // above up to 6, but they are encoded using two \u escapes. + len += 3; + p += 5; + break; + } + case '\\': + case '/': + case '"': + case 't': + case 'b': + case 'n': + case 'r': + case 'f': { + len++; + p++; + break; + } + default: { + emsgf(_("E474: Unknown escape sequence: %.*s"), LENP(p - 1, e)); + goto parse_json_string_fail; + } + } + } else { + uint8_t p_byte = (uint8_t) *p; + // unescaped = %x20-21 / %x23-5B / %x5D-10FFFF + if (p_byte < 0x20) { + emsgf(_("E474: ASCII control characters cannot be present " + "inside string: %.*s"), LENP(p, e)); + goto parse_json_string_fail; + } + const int ch = utf_ptr2char((char_u *) p); + // All characters above U+007F are encoded using two or more bytes + // and thus cannot possibly be equal to *p. But utf_ptr2char({0xFF, + // 0}) will return 0xFF, even though 0xFF cannot start any UTF-8 + // code point at all. + // + // The only exception is U+00C3 which is represented as 0xC3 0x83. + if (ch >= 0x80 && p_byte == ch + && !(ch == 0xC3 && p + 1 < e && (uint8_t) p[1] == 0x83)) { + emsgf(_("E474: Only UTF-8 strings allowed: %.*s"), LENP(p, e)); + goto parse_json_string_fail; + } else if (ch > 0x10FFFF) { + emsgf(_("E474: Only UTF-8 code points up to U+10FFFF " + "are allowed to appear unescaped: %.*s"), LENP(p, e)); + goto parse_json_string_fail; + } + const size_t ch_len = (size_t) utf_char2len(ch); + assert(ch_len == (size_t) (ch ? utf_ptr2len((char_u *) p) : 1)); + len += ch_len; + p += ch_len; + } + } + if (p == e || *p != '"') { + emsgf(_("E474: Expected string end: %.*s"), (int) buf_len, buf); + goto parse_json_string_fail; + } + if (len == 0) { + POP(((typval_T) { + .v_type = VAR_STRING, + .vval = { .v_string = NULL }, + }), false); + goto parse_json_string_ret; + } + char *str = xmalloc(len + 1); + int fst_in_pair = 0; + char *str_end = str; + bool hasnul = false; +#define PUT_FST_IN_PAIR(fst_in_pair, str_end) \ + do { \ + if (fst_in_pair != 0) { \ + str_end += utf_char2bytes(fst_in_pair, (char_u *) str_end); \ + fst_in_pair = 0; \ + } \ + } while (0) + for (const char *t = s; t < p; t++) { + if (t[0] != '\\' || t[1] != 'u') { + PUT_FST_IN_PAIR(fst_in_pair, str_end); + } + if (*t == '\\') { + t++; + switch (*t) { + case 'u': { + const char ubuf[] = { t[1], t[2], t[3], t[4] }; + t += 4; + unsigned long ch; + vim_str2nr((char_u *) ubuf, NULL, NULL, + STR2NR_HEX | STR2NR_FORCE, NULL, &ch, 4); + if (ch == 0) { + hasnul = true; + } + if (SURROGATE_HI_START <= ch && ch <= SURROGATE_HI_END) { + PUT_FST_IN_PAIR(fst_in_pair, str_end); + fst_in_pair = (int) ch; + } else if (SURROGATE_LO_START <= ch && ch <= SURROGATE_LO_END + && fst_in_pair != 0) { + const int full_char = ( + (int) (ch - SURROGATE_LO_START) + + ((fst_in_pair - SURROGATE_HI_START) << 10) + + SURROGATE_FIRST_CHAR); + str_end += utf_char2bytes(full_char, (char_u *) str_end); + fst_in_pair = 0; + } else { + PUT_FST_IN_PAIR(fst_in_pair, str_end); + str_end += utf_char2bytes((int) ch, (char_u *) str_end); + } + break; + } + case '\\': + case '/': + case '"': + case 't': + case 'b': + case 'n': + case 'r': + case 'f': { + static const char escapes[] = { + ['\\'] = '\\', + ['/'] = '/', + ['"'] = '"', + ['t'] = TAB, + ['b'] = BS, + ['n'] = NL, + ['r'] = CAR, + ['f'] = FF, + }; + *str_end++ = escapes[(int) *t]; + break; + } + default: { + assert(false); + } + } + } else { + *str_end++ = *t; + } + } + PUT_FST_IN_PAIR(fst_in_pair, str_end); +#undef PUT_FST_IN_PAIR + if (conv->vc_type != CONV_NONE) { + size_t str_len = (size_t) (str_end - str); + char *const new_str = (char *) string_convert(conv, (char_u *) str, + &str_len); + if (new_str == NULL) { + emsgf(_("E474: Failed to convert string \"%.*s\" from UTF-8"), + (int) str_len, str); + xfree(str); + goto parse_json_string_fail; + } + xfree(str); + str = new_str; + str_end = new_str + str_len; + } + if (hasnul) { + typval_T obj; + list_T *const list = list_alloc(); + list->lv_refcount++; + create_special_dict(&obj, kMPString, ((typval_T) { + .v_type = VAR_LIST, + .v_lock = VAR_UNLOCKED, + .vval = { .v_list = list }, + })); + if (encode_list_write((void *) list, str, (size_t) (str_end - str)) + == -1) { + clear_tv(&obj); + goto parse_json_string_fail; + } + xfree(str); + POP(obj, true); + } else { + *str_end = NUL; + POP(((typval_T) { + .v_type = VAR_STRING, + .vval = { .v_string = (char_u *) str }, + }), false); + } + goto parse_json_string_ret; +parse_json_string_fail: + ret = FAIL; +parse_json_string_ret: + *pp = p; + return ret; +} + +#undef POP + +/// Parse JSON number: both floating-point and integer +/// +/// Number format: `-?\d+(?:.\d+)?(?:[eE][+-]?\d+)?`. +/// +/// @param[in] buf Buffer being converted. +/// @param[in] buf_len Length of the buffer. +/// @param[in,out] pp Pointer to the start of the number. Must point to +/// a digit or a minus sign. Is advanced to the last +/// character of the number. Also see json_decoder_pop(), it +/// may set pp to another location and alter +/// next_map_special, didcomma and didcolon. +/// @param[out] stack Object stack. +/// @param[out] container_stack Container objects stack. +/// @param[out] next_map_special Is set to true when dictionary is converted +/// to a special map, otherwise not touched. +/// @param[out] didcomma True if previous token was comma. Is set to recorded +/// value when decoder is restarted, otherwise unused. +/// @param[out] didcolon True if previous token was colon. Is set to recorded +/// value when decoder is restarted, otherwise unused. +/// +/// @return OK in case of success, FAIL in case of error. +static inline int parse_json_number(const char *const buf, const size_t buf_len, + const char **const pp, + ValuesStack *const stack, + ContainerStack *const container_stack, + bool *const next_map_special, + bool *const didcomma, + bool *const didcolon) + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_ALWAYS_INLINE +{ + const char *const e = buf + buf_len; + const char *p = *pp; + int ret = OK; + const char *const s = p; + const char *ints = NULL; + const char *fracs = NULL; + const char *exps = NULL; + const char *exps_s = NULL; + if (*p == '-') { + p++; + } + ints = p; + if (p >= e) { + goto parse_json_number_check; + } + while (p < e && ascii_isdigit(*p)) { + p++; + } + if (p != ints + 1 && *ints == '0') { + emsgf(_("E474: Leading zeroes are not allowed: %.*s"), LENP(s, e)); + goto parse_json_number_fail; + } + if (p >= e || p == ints) { + goto parse_json_number_check; + } + if (*p == '.') { + p++; + fracs = p; + while (p < e && ascii_isdigit(*p)) { + p++; + } + if (p >= e || p == fracs) { + goto parse_json_number_check; + } + } + if (*p == 'e' || *p == 'E') { + p++; + exps_s = p; + if (p < e && (*p == '-' || *p == '+')) { + p++; + } + exps = p; + while (p < e && ascii_isdigit(*p)) { + p++; + } + } +parse_json_number_check: + if (p == ints) { + emsgf(_("E474: Missing number after minus sign: %.*s"), LENP(s, e)); + goto parse_json_number_fail; + } else if (p == fracs || exps_s == fracs + 1) { + emsgf(_("E474: Missing number after decimal dot: %.*s"), LENP(s, e)); + goto parse_json_number_fail; + } else if (p == exps) { + emsgf(_("E474: Missing exponent: %.*s"), LENP(s, e)); + goto parse_json_number_fail; + } + typval_T tv = { + .v_type = VAR_NUMBER, + .v_lock = VAR_UNLOCKED, + }; + const size_t exp_num_len = (size_t) (p - s); + if (fracs || exps) { + // Convert floating-point number + const size_t num_len = string2float(s, &tv.vval.v_float); + if (exp_num_len != num_len) { + emsgf(_("E685: internal error: while converting number \"%.*s\" " + "to float string2float consumed %zu bytes in place of %zu"), + (int) exp_num_len, s, num_len, exp_num_len); + } + tv.v_type = VAR_FLOAT; + } else { + // Convert integer + long nr; + int num_len; + vim_str2nr((char_u *) s, NULL, &num_len, 0, &nr, NULL, (int) (p - s)); + if ((int) exp_num_len != num_len) { + emsgf(_("E685: internal error: while converting number \"%.*s\" " + "to integer vim_str2nr consumed %i bytes in place of %zu"), + (int) exp_num_len, s, num_len, exp_num_len); + } + tv.vval.v_number = (varnumber_T) nr; + } + if (json_decoder_pop(OBJ(tv, false, *didcomma, *didcolon), + stack, container_stack, + &p, next_map_special, didcomma, didcolon) == FAIL) { + goto parse_json_number_fail; + } + if (*next_map_special) { + goto parse_json_number_ret; + } + p--; + goto parse_json_number_ret; +parse_json_number_fail: + ret = FAIL; +parse_json_number_ret: + *pp = p; + return ret; +} + +#define POP(obj_tv, is_sp_string) \ + do { \ + if (json_decoder_pop(OBJ(obj_tv, is_sp_string, didcomma, didcolon), \ + &stack, &container_stack, \ + &p, &next_map_special, &didcomma, &didcolon) \ + == FAIL) { \ + goto json_decode_string_fail; \ + } \ + if (next_map_special) { \ + goto json_decode_string_cycle_start; \ + } \ + } while (0) + +/// Convert JSON string into VimL object +/// +/// @param[in] buf String to convert. UTF-8 encoding is assumed. +/// @param[in] buf_len Length of the string. +/// @param[out] rettv Location where to save results. +/// +/// @return OK in case of success, FAIL otherwise. +int json_decode_string(const char *const buf, const size_t buf_len, + typval_T *const rettv) + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT +{ + const char *p = buf; + const char *const e = buf + buf_len; + while (p < e && (*p == ' ' || *p == TAB || *p == NL || *p == CAR)) { + p++; + } + if (p == e) { + EMSG(_("E474: Attempt to decode a blank string")); + return FAIL; + } + vimconv_T conv = { .vc_type = CONV_NONE }; + convert_setup(&conv, (char_u *) "utf-8", p_enc); + conv.vc_fail = true; + int ret = OK; + ValuesStack stack; + kv_init(stack); + ContainerStack container_stack; + kv_init(container_stack); + rettv->v_type = VAR_UNKNOWN; + bool didcomma = false; + bool didcolon = false; + bool next_map_special = false; + for (; p < e; p++) { +json_decode_string_cycle_start: + assert(*p == '{' || next_map_special == false); + switch (*p) { + case '}': + case ']': { + if (kv_size(container_stack) == 0) { + emsgf(_("E474: No container to close: %.*s"), LENP(p, e)); + goto json_decode_string_fail; + } + ContainerStackItem last_container = kv_last(container_stack); + if (*p == '}' && last_container.container.v_type != VAR_DICT) { + emsgf(_("E474: Closing list with curly bracket: %.*s"), LENP(p, e)); + goto json_decode_string_fail; + } else if (*p == ']' && last_container.container.v_type != VAR_LIST) { + emsgf(_("E474: Closing dictionary with square bracket: %.*s"), + LENP(p, e)); + goto json_decode_string_fail; + } else if (didcomma) { + emsgf(_("E474: Trailing comma: %.*s"), LENP(p, e)); + goto json_decode_string_fail; + } else if (didcolon) { + emsgf(_("E474: Expected value after colon: %.*s"), LENP(p, e)); + goto json_decode_string_fail; + } else if (last_container.stack_index != kv_size(stack) - 1) { + assert(last_container.stack_index < kv_size(stack) - 1); + emsgf(_("E474: Expected value: %.*s"), LENP(p, e)); + goto json_decode_string_fail; + } + if (kv_size(stack) == 1) { + p++; + (void) kv_pop(container_stack); + goto json_decode_string_after_cycle; + } else { + if (json_decoder_pop(kv_pop(stack), &stack, &container_stack, &p, + &next_map_special, &didcomma, &didcolon) + == FAIL) { + goto json_decode_string_fail; + } + assert(!next_map_special); + break; + } + } + case ',': { + if (kv_size(container_stack) == 0) { + emsgf(_("E474: Comma not inside container: %.*s"), LENP(p, e)); + goto json_decode_string_fail; + } + ContainerStackItem last_container = kv_last(container_stack); + if (didcomma) { + emsgf(_("E474: Duplicate comma: %.*s"), LENP(p, e)); + goto json_decode_string_fail; + } else if (didcolon) { + emsgf(_("E474: Comma after colon: %.*s"), LENP(p, e)); + goto json_decode_string_fail; + } else if (last_container.container.v_type == VAR_DICT + && last_container.stack_index != kv_size(stack) - 1) { + emsgf(_("E474: Using comma in place of colon: %.*s"), LENP(p, e)); + goto json_decode_string_fail; + } else if (last_container.special_val == NULL + ? (last_container.container.v_type == VAR_DICT + ? (DICT_LEN(last_container.container.vval.v_dict) == 0) + : (last_container.container.vval.v_list->lv_len == 0)) + : (last_container.special_val->lv_len == 0)) { + emsgf(_("E474: Leading comma: %.*s"), LENP(p, e)); + goto json_decode_string_fail; + } + didcomma = true; + continue; + } + case ':': { + if (kv_size(container_stack) == 0) { + emsgf(_("E474: Colon not inside container: %.*s"), LENP(p, e)); + goto json_decode_string_fail; + } + ContainerStackItem last_container = kv_last(container_stack); + if (last_container.container.v_type != VAR_DICT) { + emsgf(_("E474: Using colon not in dictionary: %.*s"), LENP(p, e)); + goto json_decode_string_fail; + } else if (last_container.stack_index != kv_size(stack) - 2) { + emsgf(_("E474: Unexpected colon: %.*s"), LENP(p, e)); + goto json_decode_string_fail; + } else if (didcomma) { + emsgf(_("E474: Colon after comma: %.*s"), LENP(p, e)); + goto json_decode_string_fail; + } else if (didcolon) { + emsgf(_("E474: Duplicate colon: %.*s"), LENP(p, e)); + goto json_decode_string_fail; + } + didcolon = true; + continue; + } + case ' ': + case TAB: + case NL: + case CAR: { + continue; + } + case 'n': { + if ((p + 3) >= e || strncmp(p + 1, "ull", 3) != 0) { + emsgf(_("E474: Expected null: %.*s"), LENP(p, e)); + goto json_decode_string_fail; + } + p += 3; + POP(((typval_T) { + .v_type = VAR_SPECIAL, + .v_lock = VAR_UNLOCKED, + .vval = { .v_special = kSpecialVarNull }, + }), false); + break; + } + case 't': { + if ((p + 3) >= e || strncmp(p + 1, "rue", 3) != 0) { + emsgf(_("E474: Expected true: %.*s"), LENP(p, e)); + goto json_decode_string_fail; + } + p += 3; + POP(((typval_T) { + .v_type = VAR_SPECIAL, + .v_lock = VAR_UNLOCKED, + .vval = { .v_special = kSpecialVarTrue }, + }), false); + break; + } + case 'f': { + if ((p + 4) >= e || strncmp(p + 1, "alse", 4) != 0) { + emsgf(_("E474: Expected false: %.*s"), LENP(p, e)); + goto json_decode_string_fail; + } + p += 4; + POP(((typval_T) { + .v_type = VAR_SPECIAL, + .v_lock = VAR_UNLOCKED, + .vval = { .v_special = kSpecialVarFalse }, + }), false); + break; + } + case '"': { + if (parse_json_string(&conv, buf, buf_len, &p, &stack, &container_stack, + &next_map_special, &didcomma, &didcolon) + == FAIL) { + // Error message was already given + goto json_decode_string_fail; + } + if (next_map_special) { + goto json_decode_string_cycle_start; + } + break; + } + case '-': + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': { + if (parse_json_number(buf, buf_len, &p, &stack, &container_stack, + &next_map_special, &didcomma, &didcolon) + == FAIL) { + // Error message was already given + goto json_decode_string_fail; + } + if (next_map_special) { + goto json_decode_string_cycle_start; + } + break; + } + case '[': { + list_T *list = list_alloc(); + list->lv_refcount++; + typval_T tv = { + .v_type = VAR_LIST, + .v_lock = VAR_UNLOCKED, + .vval = { .v_list = list }, + }; + kv_push(ContainerStackItem, container_stack, ((ContainerStackItem) { + .stack_index = kv_size(stack), + .s = p, + .container = tv, + .special_val = NULL, + })); + kv_push(ValuesStackItem, stack, OBJ(tv, false, didcomma, didcolon)); + break; + } + case '{': { + typval_T tv; + list_T *val_list = NULL; + if (next_map_special) { + next_map_special = false; + val_list = list_alloc(); + val_list->lv_refcount++; + create_special_dict(&tv, kMPMap, ((typval_T) { + .v_type = VAR_LIST, + .v_lock = VAR_UNLOCKED, + .vval = { .v_list = val_list }, + })); + } else { + dict_T *dict = dict_alloc(); + dict->dv_refcount++; + tv = (typval_T) { + .v_type = VAR_DICT, + .v_lock = VAR_UNLOCKED, + .vval = { .v_dict = dict }, + }; + } + kv_push(ContainerStackItem, container_stack, ((ContainerStackItem) { + .stack_index = kv_size(stack), + .s = p, + .container = tv, + .special_val = val_list, + })); + kv_push(ValuesStackItem, stack, OBJ(tv, false, didcomma, didcolon)); + break; + } + default: { + emsgf(_("E474: Unidentified byte: %.*s"), LENP(p, e)); + goto json_decode_string_fail; + } + } + didcomma = false; + didcolon = false; + if (kv_size(container_stack) == 0) { + p++; + break; + } + } +json_decode_string_after_cycle: + for (; p < e; p++) { + switch (*p) { + case NL: + case ' ': + case TAB: + case CAR: { + break; + } + default: { + emsgf(_("E474: Trailing characters: %.*s"), LENP(p, e)); + goto json_decode_string_fail; + } + } + } + if (kv_size(stack) == 1 && kv_size(container_stack) == 0) { + *rettv = kv_pop(stack).val; + goto json_decode_string_ret; + } + emsgf(_("E474: Unexpected end of input: %.*s"), (int) buf_len, buf); +json_decode_string_fail: + ret = FAIL; + while (kv_size(stack)) { + clear_tv(&(kv_pop(stack).val)); + } +json_decode_string_ret: + kv_destroy(stack); + kv_destroy(container_stack); + return ret; +} + +#undef LENP +#undef POP + +#undef OBJ + +#undef DICT_LEN + +/// Convert msgpack object to a VimL one +int msgpack_to_vim(const msgpack_object mobj, typval_T *const rettv) + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT +{ + switch (mobj.type) { + case MSGPACK_OBJECT_NIL: { + *rettv = (typval_T) { + .v_type = VAR_SPECIAL, + .v_lock = VAR_UNLOCKED, + .vval = { .v_special = kSpecialVarNull }, + }; + break; + } + case MSGPACK_OBJECT_BOOLEAN: { + *rettv = (typval_T) { + .v_type = VAR_SPECIAL, + .v_lock = VAR_UNLOCKED, + .vval = { + .v_special = mobj.via.boolean ? kSpecialVarTrue : kSpecialVarFalse + }, + }; + break; + } + case MSGPACK_OBJECT_POSITIVE_INTEGER: { + if (mobj.via.u64 <= VARNUMBER_MAX) { + *rettv = (typval_T) { + .v_type = VAR_NUMBER, + .v_lock = VAR_UNLOCKED, + .vval = { .v_number = (varnumber_T) mobj.via.u64 }, + }; + } else { + list_T *const list = list_alloc(); + list->lv_refcount++; + create_special_dict(rettv, kMPInteger, ((typval_T) { + .v_type = VAR_LIST, + .v_lock = VAR_UNLOCKED, + .vval = { .v_list = list }, + })); + uint64_t n = mobj.via.u64; + list_append_number(list, 1); + list_append_number(list, (varnumber_T) ((n >> 62) & 0x3)); + list_append_number(list, (varnumber_T) ((n >> 31) & 0x7FFFFFFF)); + list_append_number(list, (varnumber_T) (n & 0x7FFFFFFF)); + } + break; + } + case MSGPACK_OBJECT_NEGATIVE_INTEGER: { + if (mobj.via.i64 >= VARNUMBER_MIN) { + *rettv = (typval_T) { + .v_type = VAR_NUMBER, + .v_lock = VAR_UNLOCKED, + .vval = { .v_number = (varnumber_T) mobj.via.i64 }, + }; + } else { + list_T *const list = list_alloc(); + list->lv_refcount++; + create_special_dict(rettv, kMPInteger, ((typval_T) { + .v_type = VAR_LIST, + .v_lock = VAR_UNLOCKED, + .vval = { .v_list = list }, + })); + uint64_t n = -((uint64_t) mobj.via.i64); + list_append_number(list, -1); + list_append_number(list, (varnumber_T) ((n >> 62) & 0x3)); + list_append_number(list, (varnumber_T) ((n >> 31) & 0x7FFFFFFF)); + list_append_number(list, (varnumber_T) (n & 0x7FFFFFFF)); + } + break; + } + case MSGPACK_OBJECT_FLOAT: { + *rettv = (typval_T) { + .v_type = VAR_FLOAT, + .v_lock = VAR_UNLOCKED, + .vval = { .v_float = mobj.via.f64 }, + }; + break; + } + case MSGPACK_OBJECT_STR: { + list_T *const list = list_alloc(); + list->lv_refcount++; + create_special_dict(rettv, kMPString, ((typval_T) { + .v_type = VAR_LIST, + .v_lock = VAR_UNLOCKED, + .vval = { .v_list = list }, + })); + if (encode_list_write((void *) list, mobj.via.str.ptr, mobj.via.str.size) + == -1) { + return FAIL; + } + break; + } + case MSGPACK_OBJECT_BIN: { + if (memchr(mobj.via.bin.ptr, NUL, mobj.via.bin.size) == NULL) { + *rettv = (typval_T) { + .v_type = VAR_STRING, + .v_lock = VAR_UNLOCKED, + .vval = { .v_string = xmemdupz(mobj.via.bin.ptr, mobj.via.bin.size) }, + }; + break; + } + list_T *const list = list_alloc(); + list->lv_refcount++; + create_special_dict(rettv, kMPBinary, ((typval_T) { + .v_type = VAR_LIST, + .v_lock = VAR_UNLOCKED, + .vval = { .v_list = list }, + })); + if (encode_list_write((void *) list, mobj.via.bin.ptr, mobj.via.bin.size) + == -1) { + return FAIL; + } + break; + } + case MSGPACK_OBJECT_ARRAY: { + list_T *const list = list_alloc(); + list->lv_refcount++; + *rettv = (typval_T) { + .v_type = VAR_LIST, + .v_lock = VAR_UNLOCKED, + .vval = { .v_list = list }, + }; + for (size_t i = 0; i < mobj.via.array.size; i++) { + listitem_T *const li = listitem_alloc(); + li->li_tv.v_type = VAR_UNKNOWN; + list_append(list, li); + if (msgpack_to_vim(mobj.via.array.ptr[i], &li->li_tv) == FAIL) { + return FAIL; + } + } + break; + } + case MSGPACK_OBJECT_MAP: { + for (size_t i = 0; i < mobj.via.map.size; i++) { + if (mobj.via.map.ptr[i].key.type != MSGPACK_OBJECT_STR + || mobj.via.map.ptr[i].key.via.str.size == 0 + || memchr(mobj.via.map.ptr[i].key.via.str.ptr, NUL, + mobj.via.map.ptr[i].key.via.str.size) != NULL) { + goto msgpack_to_vim_generic_map; + } + } + dict_T *const dict = dict_alloc(); + dict->dv_refcount++; + *rettv = (typval_T) { + .v_type = VAR_DICT, + .v_lock = VAR_UNLOCKED, + .vval = { .v_dict = dict }, + }; + for (size_t i = 0; i < mobj.via.map.size; i++) { + dictitem_T *const di = xmallocz(offsetof(dictitem_T, di_key) + + mobj.via.map.ptr[i].key.via.str.size); + memcpy(&di->di_key[0], mobj.via.map.ptr[i].key.via.str.ptr, + mobj.via.map.ptr[i].key.via.str.size); + di->di_tv.v_type = VAR_UNKNOWN; + if (dict_add(dict, di) == FAIL) { + // Duplicate key: fallback to generic map + clear_tv(rettv); + xfree(di); + goto msgpack_to_vim_generic_map; + } + if (msgpack_to_vim(mobj.via.map.ptr[i].val, &di->di_tv) == FAIL) { + return FAIL; + } + } + break; +msgpack_to_vim_generic_map: {} + list_T *const list = list_alloc(); + list->lv_refcount++; + create_special_dict(rettv, kMPMap, ((typval_T) { + .v_type = VAR_LIST, + .v_lock = VAR_UNLOCKED, + .vval = { .v_list = list }, + })); + for (size_t i = 0; i < mobj.via.map.size; i++) { + list_T *const kv_pair = list_alloc(); + list_append_list(list, kv_pair); + listitem_T *const key_li = listitem_alloc(); + key_li->li_tv.v_type = VAR_UNKNOWN; + list_append(kv_pair, key_li); + listitem_T *const val_li = listitem_alloc(); + val_li->li_tv.v_type = VAR_UNKNOWN; + list_append(kv_pair, val_li); + if (msgpack_to_vim(mobj.via.map.ptr[i].key, &key_li->li_tv) == FAIL) { + return FAIL; + } + if (msgpack_to_vim(mobj.via.map.ptr[i].val, &val_li->li_tv) == FAIL) { + return FAIL; + } + } + break; + } + case MSGPACK_OBJECT_EXT: { + list_T *const list = list_alloc(); + list->lv_refcount++; + list_append_number(list, mobj.via.ext.type); + list_T *const ext_val_list = list_alloc(); + list_append_list(list, ext_val_list); + create_special_dict(rettv, kMPExt, ((typval_T) { + .v_type = VAR_LIST, + .v_lock = VAR_UNLOCKED, + .vval = { .v_list = list }, + })); + if (encode_list_write((void *) ext_val_list, mobj.via.ext.ptr, + mobj.via.ext.size) == -1) { + return FAIL; + } + break; + } + } + return OK; +} diff --git a/src/nvim/eval/decode.h b/src/nvim/eval/decode.h new file mode 100644 index 0000000000..5c25a64f7a --- /dev/null +++ b/src/nvim/eval/decode.h @@ -0,0 +1,13 @@ +#ifndef NVIM_EVAL_DECODE_H +#define NVIM_EVAL_DECODE_H + +#include <stddef.h> + +#include <msgpack.h> + +#include "nvim/eval_defs.h" + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "eval/decode.h.generated.h" +#endif +#endif // NVIM_EVAL_DECODE_H diff --git a/src/nvim/eval/encode.c b/src/nvim/eval/encode.c new file mode 100644 index 0000000000..c651a50be9 --- /dev/null +++ b/src/nvim/eval/encode.c @@ -0,0 +1,1296 @@ +/// @file encode.c +/// +/// File containing functions for encoding and decoding VimL values. +/// +/// Split out from eval.c. + +#include <msgpack.h> +#include <inttypes.h> +#include <assert.h> +#include <math.h> + +#include "nvim/eval/encode.h" +#include "nvim/buffer_defs.h" // vimconv_T +#include "nvim/eval.h" +#include "nvim/eval_defs.h" +#include "nvim/garray.h" +#include "nvim/mbyte.h" +#include "nvim/message.h" +#include "nvim/memory.h" +#include "nvim/charset.h" // vim_isprintc() +#include "nvim/macros.h" +#include "nvim/ascii.h" +#include "nvim/vim.h" // For _() +#include "nvim/lib/kvec.h" + +#define ga_concat(a, b) ga_concat(a, (char_u *)b) +#define utf_ptr2char(b) utf_ptr2char((char_u *)b) +#define utf_ptr2len(b) ((size_t)utf_ptr2len((char_u *)b)) +#define utf_char2len(b) ((size_t)utf_char2len(b)) +#define string_convert(a, b, c) \ + ((char *)string_convert((vimconv_T *)a, (char_u *)b, c)) +#define convert_setup(vcp, from, to) \ + (convert_setup(vcp, (char_u *)from, (char_u *)to)) + +/// Structure representing current VimL to messagepack conversion state +typedef struct { + enum { + kMPConvDict, ///< Convert dict_T *dictionary. + kMPConvList, ///< Convert list_T *list. + kMPConvPairs, ///< Convert mapping represented as a list_T* of pairs. + } type; + union { + struct { + dict_T *dict; ///< Currently converted dictionary. + hashitem_T *hi; ///< Currently converted dictionary item. + size_t todo; ///< Amount of items left to process. + } d; ///< State of dictionary conversion. + struct { + list_T *list; ///< Currently converted list. + listitem_T *li; ///< Currently converted list item. + } l; ///< State of list or generic mapping conversion. + } data; ///< Data to convert. +} MPConvStackVal; + +/// Stack used to convert VimL values to messagepack. +typedef kvec_t(MPConvStackVal) MPConvStack; + +const char *const encode_special_var_names[] = { + [kSpecialVarNull] = "null", + [kSpecialVarTrue] = "true", + [kSpecialVarFalse] = "false", +}; + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "eval/encode.c.generated.h" +#endif + +/// Msgpack callback for writing to readfile()-style list +int encode_list_write(void *data, const char *buf, size_t len) +{ + if (len == 0) { + return 0; + } + list_T *const list = (list_T *) data; + const char *const end = buf + len; + const char *line_end = buf; + listitem_T *li = list->lv_last; + + // Continue the last list element + if (li != NULL) { + line_end = xmemscan(buf, NL, len); + if (line_end != buf) { + const size_t line_length = (size_t)(line_end - buf); + char *str = (char *)li->li_tv.vval.v_string; + const size_t li_len = (str == NULL ? 0 : strlen(str)); + li->li_tv.vval.v_string = xrealloc(str, li_len + line_length + 1); + str = (char *)li->li_tv.vval.v_string + li_len; + memcpy(str, buf, line_length); + str[line_length] = 0; + memchrsub(str, NUL, NL, line_length); + } + line_end++; + } + + while (line_end < end) { + const char *line_start = line_end; + line_end = xmemscan(line_start, NL, (size_t) (end - line_start)); + char *str = NULL; + if (line_end != line_start) { + const size_t line_length = (size_t)(line_end - line_start); + str = xmemdupz(line_start, line_length); + memchrsub(str, NUL, NL, line_length); + } + list_append_allocated_string(list, str); + line_end++; + } + if (line_end == end) { + list_append_allocated_string(list, NULL); + } + return 0; +} + +/// Abort conversion to string after a recursion error. +static bool did_echo_string_emsg = false; + +/// Show a error message when converting to msgpack value +/// +/// @param[in] msg Error message to dump. Must contain exactly two %s that +/// will be replaced with what was being dumped: first with +/// something like “F” or “function argument”, second with path +/// to the failed value. +/// @param[in] mpstack Path to the failed value. +/// @param[in] objname Dumped object name. +/// +/// @return FAIL. +static int conv_error(const char *const msg, const MPConvStack *const mpstack, + const char *const objname) + FUNC_ATTR_NONNULL_ALL +{ + garray_T msg_ga; + ga_init(&msg_ga, (int)sizeof(char), 80); + char *const key_msg = _("key %s"); + char *const key_pair_msg = _("key %s at index %i from special map"); + char *const idx_msg = _("index %i"); + for (size_t i = 0; i < kv_size(*mpstack); i++) { + if (i != 0) { + ga_concat(&msg_ga, ", "); + } + MPConvStackVal v = kv_A(*mpstack, i); + switch (v.type) { + case kMPConvDict: { + typval_T key_tv = { + .v_type = VAR_STRING, + .vval = { .v_string = (v.data.d.hi == NULL + ? v.data.d.dict->dv_hashtab.ht_array + : (v.data.d.hi - 1))->hi_key }, + }; + char *const key = encode_tv2string(&key_tv, NULL); + vim_snprintf((char *) IObuff, IOSIZE, key_msg, key); + xfree(key); + ga_concat(&msg_ga, IObuff); + break; + } + case kMPConvPairs: + case kMPConvList: { + int idx = 0; + const listitem_T *li; + for (li = v.data.l.list->lv_first; + li != NULL && li->li_next != v.data.l.li; + li = li->li_next) { + idx++; + } + if (v.type == kMPConvList + || li == NULL + || (li->li_tv.v_type != VAR_LIST + && li->li_tv.vval.v_list->lv_len <= 0)) { + vim_snprintf((char *) IObuff, IOSIZE, idx_msg, idx); + ga_concat(&msg_ga, IObuff); + } else { + typval_T key_tv = li->li_tv.vval.v_list->lv_first->li_tv; + char *const key = encode_tv2echo(&key_tv, NULL); + vim_snprintf((char *) IObuff, IOSIZE, key_pair_msg, key, idx); + xfree(key); + ga_concat(&msg_ga, IObuff); + } + break; + } + } + } + EMSG3(msg, objname, (kv_size(*mpstack) == 0 + ? _("itself") + : (char *) msg_ga.ga_data)); + ga_clear(&msg_ga); + return FAIL; +} + +/// Convert readfile()-style list to a char * buffer with length +/// +/// @param[in] list Converted list. +/// @param[out] ret_len Resulting buffer length. +/// @param[out] ret_buf Allocated buffer with the result or NULL if ret_len is +/// zero. +/// +/// @return true in case of success, false in case of failure. +bool encode_vim_list_to_buf(const list_T *const list, size_t *const ret_len, + char **const ret_buf) + FUNC_ATTR_NONNULL_ARG(2, 3) FUNC_ATTR_WARN_UNUSED_RESULT +{ + size_t len = 0; + if (list != NULL) { + for (const listitem_T *li = list->lv_first; + li != NULL; + li = li->li_next) { + if (li->li_tv.v_type != VAR_STRING) { + return false; + } + len++; + if (li->li_tv.vval.v_string != 0) { + len += STRLEN(li->li_tv.vval.v_string); + } + } + if (len) { + len--; + } + } + *ret_len = len; + if (len == 0) { + *ret_buf = NULL; + return true; + } + ListReaderState lrstate = encode_init_lrstate(list); + char *const buf = xmalloc(len); + size_t read_bytes; + if (encode_read_from_list(&lrstate, buf, len, &read_bytes) != OK) { + assert(false); + } + assert(len == read_bytes); + *ret_buf = buf; + return true; +} + +/// Read bytes from list +/// +/// @param[in,out] state Structure describing position in list from which +/// reading should start. Is updated to reflect position +/// at which reading ended. +/// @param[out] buf Buffer to write to. +/// @param[in] nbuf Buffer length. +/// @param[out] read_bytes Is set to amount of bytes read. +/// +/// @return OK when reading was finished, FAIL in case of error (i.e. list item +/// was not a string), NOTDONE if reading was successfull, but there are +/// more bytes to read. +int encode_read_from_list(ListReaderState *const state, char *const buf, + const size_t nbuf, size_t *const read_bytes) + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT +{ + char *const buf_end = buf + nbuf; + char *p = buf; + while (p < buf_end) { + for (size_t i = state->offset; i < state->li_length && p < buf_end; i++) { + const char ch = (char) state->li->li_tv.vval.v_string[state->offset++]; + *p++ = (char) ((char) ch == (char) NL ? (char) NUL : (char) ch); + } + if (p < buf_end) { + state->li = state->li->li_next; + if (state->li == NULL) { + *read_bytes = (size_t) (p - buf); + return OK; + } + *p++ = NL; + if (state->li->li_tv.v_type != VAR_STRING) { + *read_bytes = (size_t) (p - buf); + return FAIL; + } + state->offset = 0; + state->li_length = (state->li->li_tv.vval.v_string == NULL + ? 0 + : STRLEN(state->li->li_tv.vval.v_string)); + } + } + *read_bytes = nbuf; + return (state->offset < state->li_length || state->li->li_next != NULL + ? NOTDONE + : OK); +} + +/// Code for checking whether container references itself +/// +/// @param[in,out] val Container to check. +/// @param copyID_attr Name of the container attribute that holds copyID. +/// After checking whether value of this attribute is +/// copyID (variable) it is set to copyID. +#define CHECK_SELF_REFERENCE(val, copyID_attr, conv_type) \ + do { \ + if ((val)->copyID_attr == copyID) { \ + CONV_RECURSE((val), conv_type); \ + } \ + (val)->copyID_attr = copyID; \ + } while (0) + +#define TV_STRLEN(tv) \ + (tv->vval.v_string == NULL ? 0 : STRLEN(tv->vval.v_string)) + +/// Define functions which convert VimL value to something else +/// +/// Creates function `vim_to_{name}(firstargtype firstargname, typval_T *const +/// tv)` which returns OK or FAIL and helper functions. +/// +/// @param firstargtype Type of the first argument. It will be used to return +/// the results. +/// @param firstargname Name of the first argument. +/// @param name Name of the target converter. +#define DEFINE_VIML_CONV_FUNCTIONS(scope, name, firstargtype, firstargname) \ +static int name##_convert_one_value(firstargtype firstargname, \ + MPConvStack *const mpstack, \ + typval_T *const tv, \ + const int copyID, \ + const char *const objname) \ + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT \ +{ \ + switch (tv->v_type) { \ + case VAR_STRING: { \ + CONV_STRING(tv->vval.v_string, TV_STRLEN(tv)); \ + break; \ + } \ + case VAR_NUMBER: { \ + CONV_NUMBER(tv->vval.v_number); \ + break; \ + } \ + case VAR_FLOAT: { \ + CONV_FLOAT(tv->vval.v_float); \ + break; \ + } \ + case VAR_FUNC: { \ + CONV_FUNC(tv->vval.v_string); \ + break; \ + } \ + case VAR_LIST: { \ + if (tv->vval.v_list == NULL || tv->vval.v_list->lv_len == 0) { \ + CONV_EMPTY_LIST(); \ + break; \ + } \ + CHECK_SELF_REFERENCE(tv->vval.v_list, lv_copyID, kMPConvList); \ + CONV_LIST_START(tv->vval.v_list); \ + kv_push(MPConvStackVal, *mpstack, ((MPConvStackVal) { \ + .type = kMPConvList, \ + .data = { \ + .l = { \ + .list = tv->vval.v_list, \ + .li = tv->vval.v_list->lv_first, \ + }, \ + }, \ + })); \ + break; \ + } \ + case VAR_SPECIAL: { \ + switch (tv->vval.v_special) { \ + case kSpecialVarNull: { \ + CONV_NIL(); \ + break; \ + } \ + case kSpecialVarTrue: \ + case kSpecialVarFalse: { \ + CONV_BOOL(tv->vval.v_special == kSpecialVarTrue); \ + break; \ + } \ + } \ + break; \ + } \ + case VAR_DICT: { \ + if (tv->vval.v_dict == NULL \ + || tv->vval.v_dict->dv_hashtab.ht_used == 0) { \ + CONV_EMPTY_DICT(); \ + break; \ + } \ + const dictitem_T *type_di; \ + const dictitem_T *val_di; \ + if (CONV_ALLOW_SPECIAL \ + && tv->vval.v_dict->dv_hashtab.ht_used == 2 \ + && (type_di = dict_find((dict_T *) tv->vval.v_dict, \ + (char_u *) "_TYPE", -1)) != NULL \ + && type_di->di_tv.v_type == VAR_LIST \ + && (val_di = dict_find((dict_T *) tv->vval.v_dict, \ + (char_u *) "_VAL", -1)) != NULL) { \ + size_t i; \ + for (i = 0; i < ARRAY_SIZE(eval_msgpack_type_lists); i++) { \ + if (type_di->di_tv.vval.v_list == eval_msgpack_type_lists[i]) { \ + break; \ + } \ + } \ + if (i == ARRAY_SIZE(eval_msgpack_type_lists)) { \ + goto name##_convert_one_value_regular_dict; \ + } \ + switch ((MessagePackType) i) { \ + case kMPNil: { \ + CONV_NIL(); \ + break; \ + } \ + case kMPBoolean: { \ + if (val_di->di_tv.v_type != VAR_NUMBER) { \ + goto name##_convert_one_value_regular_dict; \ + } \ + CONV_BOOL(val_di->di_tv.vval.v_number); \ + break; \ + } \ + case kMPInteger: { \ + const list_T *val_list; \ + varnumber_T sign; \ + varnumber_T highest_bits; \ + varnumber_T high_bits; \ + varnumber_T low_bits; \ + /* List of 4 integers; first is signed (should be 1 or -1, but */ \ + /* this is not checked), second is unsigned and have at most */ \ + /* one (sign is -1) or two (sign is 1) non-zero bits (number of */ \ + /* bits is not checked), other unsigned and have at most 31 */ \ + /* non-zero bits (number of bits is not checked).*/ \ + if (val_di->di_tv.v_type != VAR_LIST \ + || (val_list = val_di->di_tv.vval.v_list) == NULL \ + || val_list->lv_len != 4 \ + || val_list->lv_first->li_tv.v_type != VAR_NUMBER \ + || (sign = val_list->lv_first->li_tv.vval.v_number) == 0 \ + || val_list->lv_first->li_next->li_tv.v_type != VAR_NUMBER \ + || (highest_bits = \ + val_list->lv_first->li_next->li_tv.vval.v_number) < 0 \ + || val_list->lv_last->li_prev->li_tv.v_type != VAR_NUMBER \ + || (high_bits = \ + val_list->lv_last->li_prev->li_tv.vval.v_number) < 0 \ + || val_list->lv_last->li_tv.v_type != VAR_NUMBER \ + || (low_bits = val_list->lv_last->li_tv.vval.v_number) < 0) { \ + goto name##_convert_one_value_regular_dict; \ + } \ + uint64_t number = ((uint64_t) (((uint64_t) highest_bits) << 62) \ + | (uint64_t) (((uint64_t) high_bits) << 31) \ + | (uint64_t) low_bits); \ + if (sign > 0) { \ + CONV_UNSIGNED_NUMBER(number); \ + } else { \ + CONV_NUMBER(-number); \ + } \ + break; \ + } \ + case kMPFloat: { \ + if (val_di->di_tv.v_type != VAR_FLOAT) { \ + goto name##_convert_one_value_regular_dict; \ + } \ + CONV_FLOAT(val_di->di_tv.vval.v_float); \ + break; \ + } \ + case kMPString: \ + case kMPBinary: { \ + const bool is_string = ((MessagePackType) i == kMPString); \ + if (val_di->di_tv.v_type != VAR_LIST) { \ + goto name##_convert_one_value_regular_dict; \ + } \ + size_t len; \ + char *buf; \ + if (!encode_vim_list_to_buf(val_di->di_tv.vval.v_list, &len, \ + &buf)) { \ + goto name##_convert_one_value_regular_dict; \ + } \ + if (is_string) { \ + CONV_STR_STRING(buf, len); \ + } else { \ + CONV_STRING(buf, len); \ + } \ + xfree(buf); \ + break; \ + } \ + case kMPArray: { \ + if (val_di->di_tv.v_type != VAR_LIST) { \ + goto name##_convert_one_value_regular_dict; \ + } \ + CHECK_SELF_REFERENCE(val_di->di_tv.vval.v_list, lv_copyID, \ + kMPConvList); \ + CONV_LIST_START(val_di->di_tv.vval.v_list); \ + kv_push(MPConvStackVal, *mpstack, ((MPConvStackVal) { \ + .type = kMPConvList, \ + .data = { \ + .l = { \ + .list = val_di->di_tv.vval.v_list, \ + .li = val_di->di_tv.vval.v_list->lv_first, \ + }, \ + }, \ + })); \ + break; \ + } \ + case kMPMap: { \ + if (val_di->di_tv.v_type != VAR_LIST) { \ + goto name##_convert_one_value_regular_dict; \ + } \ + list_T *const val_list = val_di->di_tv.vval.v_list; \ + if (val_list == NULL || val_list->lv_len == 0) { \ + CONV_EMPTY_DICT(); \ + break; \ + } \ + for (const listitem_T *li = val_list->lv_first; li != NULL; \ + li = li->li_next) { \ + if (li->li_tv.v_type != VAR_LIST \ + || li->li_tv.vval.v_list->lv_len != 2) { \ + goto name##_convert_one_value_regular_dict; \ + } \ + } \ + CHECK_SELF_REFERENCE(val_list, lv_copyID, kMPConvPairs); \ + CONV_DICT_START(val_list->lv_len); \ + kv_push(MPConvStackVal, *mpstack, ((MPConvStackVal) { \ + .type = kMPConvPairs, \ + .data = { \ + .l = { \ + .list = val_list, \ + .li = val_list->lv_first, \ + }, \ + }, \ + })); \ + break; \ + } \ + case kMPExt: { \ + const list_T *val_list; \ + varnumber_T type; \ + if (val_di->di_tv.v_type != VAR_LIST \ + || (val_list = val_di->di_tv.vval.v_list) == NULL \ + || val_list->lv_len != 2 \ + || (val_list->lv_first->li_tv.v_type != VAR_NUMBER) \ + || (type = val_list->lv_first->li_tv.vval.v_number) > INT8_MAX \ + || type < INT8_MIN \ + || (val_list->lv_last->li_tv.v_type != VAR_LIST)) { \ + goto name##_convert_one_value_regular_dict; \ + } \ + size_t len; \ + char *buf; \ + if (!encode_vim_list_to_buf(val_list->lv_last->li_tv.vval.v_list, \ + &len, &buf)) { \ + goto name##_convert_one_value_regular_dict; \ + } \ + CONV_EXT_STRING(buf, len, type); \ + xfree(buf); \ + break; \ + } \ + } \ + break; \ + } \ +name##_convert_one_value_regular_dict: \ + CHECK_SELF_REFERENCE(tv->vval.v_dict, dv_copyID, kMPConvDict); \ + CONV_DICT_START(tv->vval.v_dict->dv_hashtab.ht_used); \ + kv_push(MPConvStackVal, *mpstack, ((MPConvStackVal) { \ + .type = kMPConvDict, \ + .data = { \ + .d = { \ + .dict = tv->vval.v_dict, \ + .hi = tv->vval.v_dict->dv_hashtab.ht_array, \ + .todo = tv->vval.v_dict->dv_hashtab.ht_used, \ + }, \ + }, \ + })); \ + break; \ + } \ + case VAR_UNKNOWN: { \ + EMSG2(_(e_intern2), #name "_convert_one_value()"); \ + return FAIL; \ + } \ + } \ + return OK; \ +} \ +\ +scope int encode_vim_to_##name(firstargtype firstargname, typval_T *const tv, \ + const char *const objname) \ + FUNC_ATTR_WARN_UNUSED_RESULT \ +{ \ + const int copyID = get_copyID(); \ + MPConvStack mpstack; \ + kv_init(mpstack); \ + if (name##_convert_one_value(firstargname, &mpstack, tv, copyID, objname) \ + == FAIL) { \ + goto encode_vim_to_##name##_error_ret; \ + } \ + while (kv_size(mpstack)) { \ + MPConvStackVal *cur_mpsv = &kv_A(mpstack, kv_size(mpstack) - 1); \ + typval_T *cur_tv = NULL; \ + switch (cur_mpsv->type) { \ + case kMPConvDict: { \ + if (!cur_mpsv->data.d.todo) { \ + (void) kv_pop(mpstack); \ + cur_mpsv->data.d.dict->dv_copyID = copyID - 1; \ + CONV_DICT_END(); \ + continue; \ + } else if (cur_mpsv->data.d.todo \ + != cur_mpsv->data.d.dict->dv_hashtab.ht_used) { \ + CONV_DICT_BETWEEN_ITEMS(); \ + } \ + while (HASHITEM_EMPTY(cur_mpsv->data.d.hi)) { \ + cur_mpsv->data.d.hi++; \ + } \ + dictitem_T *const di = HI2DI(cur_mpsv->data.d.hi); \ + cur_mpsv->data.d.todo--; \ + cur_mpsv->data.d.hi++; \ + CONV_STR_STRING(&di->di_key[0], STRLEN(&di->di_key[0])); \ + CONV_DICT_AFTER_KEY(); \ + cur_tv = &di->di_tv; \ + break; \ + } \ + case kMPConvList: { \ + if (cur_mpsv->data.l.li == NULL) { \ + (void) kv_pop(mpstack); \ + cur_mpsv->data.l.list->lv_copyID = copyID - 1; \ + CONV_LIST_END(cur_mpsv->data.l.list); \ + continue; \ + } else if (cur_mpsv->data.l.li != cur_mpsv->data.l.list->lv_first) { \ + CONV_LIST_BETWEEN_ITEMS(); \ + } \ + cur_tv = &cur_mpsv->data.l.li->li_tv; \ + cur_mpsv->data.l.li = cur_mpsv->data.l.li->li_next; \ + break; \ + } \ + case kMPConvPairs: { \ + if (cur_mpsv->data.l.li == NULL) { \ + (void) kv_pop(mpstack); \ + cur_mpsv->data.l.list->lv_copyID = copyID - 1; \ + CONV_DICT_END(); \ + continue; \ + } else if (cur_mpsv->data.l.li != cur_mpsv->data.l.list->lv_first) { \ + CONV_DICT_BETWEEN_ITEMS(); \ + } \ + const list_T *const kv_pair = cur_mpsv->data.l.li->li_tv.vval.v_list; \ + CONV_SPECIAL_DICT_KEY_CHECK(name, kv_pair); \ + if (name##_convert_one_value(firstargname, &mpstack, \ + &kv_pair->lv_first->li_tv, copyID, \ + objname) == FAIL) { \ + goto encode_vim_to_##name##_error_ret; \ + } \ + CONV_DICT_AFTER_KEY(); \ + cur_tv = &kv_pair->lv_last->li_tv; \ + cur_mpsv->data.l.li = cur_mpsv->data.l.li->li_next; \ + break; \ + } \ + } \ + assert(cur_tv != NULL); \ + if (name##_convert_one_value(firstargname, &mpstack, cur_tv, copyID, \ + objname) == FAIL) { \ + goto encode_vim_to_##name##_error_ret; \ + } \ + } \ + kv_destroy(mpstack); \ + return OK; \ +encode_vim_to_##name##_error_ret: \ + kv_destroy(mpstack); \ + return FAIL; \ +} + +#define CONV_STRING(buf, len) \ + do { \ + const char *const buf_ = (const char *) buf; \ + if (buf == NULL) { \ + ga_concat(gap, "''"); \ + } else { \ + const size_t len_ = (len); \ + ga_grow(gap, (int) (2 + len_ + memcnt(buf_, '\'', len_))); \ + ga_append(gap, '\''); \ + for (size_t i = 0; i < len_; i++) { \ + if (buf_[i] == '\'') { \ + ga_append(gap, '\''); \ + } \ + ga_append(gap, buf_[i]); \ + } \ + ga_append(gap, '\''); \ + } \ + } while (0) + +#define CONV_STR_STRING(buf, len) \ + CONV_STRING(buf, len) + +#define CONV_EXT_STRING(buf, len, type) + +#define CONV_NUMBER(num) \ + do { \ + char numbuf[NUMBUFLEN]; \ + vim_snprintf(numbuf, ARRAY_SIZE(numbuf), "%" PRId64, (int64_t) (num)); \ + ga_concat(gap, numbuf); \ + } while (0) + +#define CONV_FLOAT(flt) \ + do { \ + const float_T flt_ = (flt); \ + switch (fpclassify(flt_)) { \ + case FP_NAN: { \ + ga_concat(gap, (char_u *) "str2float('nan')"); \ + break; \ + } \ + case FP_INFINITE: { \ + if (flt_ < 0) { \ + ga_append(gap, '-'); \ + } \ + ga_concat(gap, (char_u *) "str2float('inf')"); \ + break; \ + } \ + default: { \ + char numbuf[NUMBUFLEN]; \ + vim_snprintf(numbuf, ARRAY_SIZE(numbuf), "%g", flt_); \ + ga_concat(gap, (char_u *) numbuf); \ + } \ + } \ + } while (0) + +#define CONV_FUNC(fun) \ + do { \ + ga_concat(gap, "function("); \ + CONV_STRING(fun, STRLEN(fun)); \ + ga_append(gap, ')'); \ + } while (0) + +#define CONV_EMPTY_LIST() \ + ga_concat(gap, "[]") + +#define CONV_LIST_START(lst) \ + ga_append(gap, '[') + +#define CONV_EMPTY_DICT() \ + ga_concat(gap, "{}") + +#define CONV_NIL() \ + ga_concat(gap, "v:null") + +#define CONV_BOOL(num) \ + ga_concat(gap, ((num)? "v:true": "v:false")) + +#define CONV_UNSIGNED_NUMBER(num) + +#define CONV_DICT_START(len) \ + ga_append(gap, '{') + +#define CONV_DICT_END() \ + ga_append(gap, '}') + +#define CONV_DICT_AFTER_KEY() \ + ga_concat(gap, ": ") + +#define CONV_DICT_BETWEEN_ITEMS() \ + ga_concat(gap, ", ") + +#define CONV_SPECIAL_DICT_KEY_CHECK(name, kv_pair) + +#define CONV_LIST_END(lst) \ + ga_append(gap, ']') + +#define CONV_LIST_BETWEEN_ITEMS() \ + CONV_DICT_BETWEEN_ITEMS() + +#define CONV_RECURSE(val, conv_type) \ + do { \ + if (!did_echo_string_emsg) { \ + /* Only give this message once for a recursive call to avoid */ \ + /* flooding the user with errors. */ \ + did_echo_string_emsg = true; \ + EMSG(_("E724: unable to correctly dump variable " \ + "with self-referencing container")); \ + } \ + char ebuf[NUMBUFLEN + 7]; \ + size_t backref = 0; \ + for (; backref < kv_size(*mpstack); backref++) { \ + const MPConvStackVal mpval = kv_A(*mpstack, backref); \ + if (mpval.type == conv_type) { \ + if (conv_type == kMPConvDict) { \ + if ((void *) mpval.data.d.dict == (void *) (val)) { \ + break; \ + } \ + } else if (conv_type == kMPConvList) { \ + if ((void *) mpval.data.l.list == (void *) (val)) { \ + break; \ + } \ + } \ + } \ + } \ + vim_snprintf(ebuf, ARRAY_SIZE(ebuf), "{E724@%zu}", backref); \ + ga_concat(gap, &ebuf[0]); \ + return OK; \ + } while (0) + +#define CONV_ALLOW_SPECIAL false + +DEFINE_VIML_CONV_FUNCTIONS(static, string, garray_T *const, gap) + +#undef CONV_RECURSE +#define CONV_RECURSE(val, conv_type) \ + do { \ + char ebuf[NUMBUFLEN + 7]; \ + size_t backref = 0; \ + for (; backref < kv_size(*mpstack); backref++) { \ + const MPConvStackVal mpval = kv_A(*mpstack, backref); \ + if (mpval.type == conv_type) { \ + if (conv_type == kMPConvDict) { \ + if ((void *) mpval.data.d.dict == (void *) val) { \ + break; \ + } \ + } else if (conv_type == kMPConvList) { \ + if ((void *) mpval.data.l.list == (void *) val) { \ + break; \ + } \ + } \ + } \ + } \ + if (conv_type == kMPConvDict) { \ + vim_snprintf(ebuf, ARRAY_SIZE(ebuf), "{...@%zu}", backref); \ + } else { \ + vim_snprintf(ebuf, ARRAY_SIZE(ebuf), "[...@%zu]", backref); \ + } \ + ga_concat(gap, &ebuf[0]); \ + return OK; \ + } while (0) + +DEFINE_VIML_CONV_FUNCTIONS(, echo, garray_T *const, gap) + +#undef CONV_RECURSE +#define CONV_RECURSE(val, conv_type) \ + do { \ + if (!did_echo_string_emsg) { \ + /* Only give this message once for a recursive call to avoid */ \ + /* flooding the user with errors. */ \ + did_echo_string_emsg = true; \ + EMSG(_("E724: unable to correctly dump variable " \ + "with self-referencing container")); \ + } \ + return OK; \ + } while (0) + +#undef CONV_ALLOW_SPECIAL +#define CONV_ALLOW_SPECIAL true + +#undef CONV_NIL +#define CONV_NIL() \ + ga_concat(gap, "null") + +#undef CONV_BOOL +#define CONV_BOOL(num) \ + ga_concat(gap, ((num)? "true": "false")) + +#undef CONV_UNSIGNED_NUMBER +#define CONV_UNSIGNED_NUMBER(num) \ + do { \ + char numbuf[NUMBUFLEN]; \ + vim_snprintf(numbuf, ARRAY_SIZE(numbuf), "%" PRIu64, (num)); \ + ga_concat(gap, numbuf); \ + } while (0) + +#undef CONV_FLOAT +#define CONV_FLOAT(flt) \ + do { \ + const float_T flt_ = (flt); \ + switch (fpclassify(flt_)) { \ + case FP_NAN: { \ + EMSG(_("E474: Unable to represent NaN value in JSON")); \ + return FAIL; \ + } \ + case FP_INFINITE: { \ + EMSG(_("E474: Unable to represent infinity in JSON")); \ + return FAIL; \ + } \ + default: { \ + char numbuf[NUMBUFLEN]; \ + vim_snprintf(numbuf, ARRAY_SIZE(numbuf), "%g", flt_); \ + ga_concat(gap, (char_u *) numbuf); \ + break; \ + } \ + } \ + } while (0) + +/// Last used p_enc value +/// +/// Generic pointer: it is not used as a string, only pointer comparisons are +/// performed. Must not be freed. +static const void *last_p_enc = NULL; + +/// Conversion setup for converting from last_p_enc to UTF-8 +static vimconv_T p_enc_conv = { + .vc_type = CONV_NONE, +}; + +/// Escape sequences used in JSON +static const char escapes[][3] = { + [BS] = "\\b", + [TAB] = "\\t", + [NL] = "\\n", + [CAR] = "\\r", + ['"'] = "\\\"", + ['\\'] = "\\\\", + [FF] = "\\f", +}; + +static const char xdigits[] = "0123456789ABCDEF"; + +/// Convert given string to JSON string +/// +/// @param[out] gap Garray where result will be saved. +/// @param[in] buf Converted string. +/// @param[in] len Converted string length. +/// +/// @return OK in case of success, FAIL otherwise. +static inline int convert_to_json_string(garray_T *const gap, + const char *const buf, + const size_t len) + FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_ALWAYS_INLINE +{ + const char *utf_buf = buf; + if (utf_buf == NULL) { + ga_concat(gap, "\"\""); + } else { + size_t utf_len = len; + char *tofree = NULL; + if (last_p_enc != (const void *) p_enc) { + p_enc_conv.vc_type = CONV_NONE; + convert_setup(&p_enc_conv, p_enc, "utf-8"); + p_enc_conv.vc_fail = true; + last_p_enc = p_enc; + } + if (p_enc_conv.vc_type != CONV_NONE) { + tofree = string_convert(&p_enc_conv, buf, &utf_len); + if (tofree == NULL) { + emsgf(_("E474: Failed to convert string \"%.*s\" to UTF-8"), + utf_len, utf_buf); + return FAIL; + } + utf_buf = tofree; + } + size_t str_len = 0; + // Encode character as \u0000 if + // 1. It is an ASCII control character (0x0 .. 0x1F, 0x7F). + // 2. &encoding is not UTF-8 and code point is above 0x7F. + // 3. &encoding is UTF-8 and code point is not printable according to + // utf_printable(). + // This is done to make it possible to :echo values when &encoding is not + // UTF-8. +#define ENCODE_RAW(p_enc_conv, ch) \ + (ch >= 0x20 && (p_enc_conv.vc_type == CONV_NONE \ + ? utf_printable(ch) \ + : ch < 0x7F)) + for (size_t i = 0; i < utf_len;) { + const int ch = utf_ptr2char(utf_buf + i); + const size_t shift = (ch == 0? 1: utf_ptr2len(utf_buf + i)); + assert(shift > 0); + i += shift; + switch (ch) { + case BS: + case TAB: + case NL: + case FF: + case CAR: + case '"': + case '\\': { + str_len += 2; + break; + } + default: { + if (ch > 0x7F && shift == 1) { + emsgf(_("E474: String \"%.*s\" contains byte that does not start " + "any UTF-8 character"), + utf_len - (i - shift), utf_buf + i - shift); + xfree(tofree); + return FAIL; + } else if ((SURROGATE_HI_START <= ch && ch <= SURROGATE_HI_END) + || (SURROGATE_LO_START <= ch && ch <= SURROGATE_LO_END)) { + emsgf(_("E474: UTF-8 string contains code point which belongs " + "to a surrogate pair: %.*s"), + utf_len - (i - shift), utf_buf + i - shift); + xfree(tofree); + return FAIL; + } else if (ENCODE_RAW(p_enc_conv, ch)) { + str_len += shift; + } else { + str_len += ((sizeof("\\u1234") - 1) + * (size_t) (1 + (ch >= SURROGATE_FIRST_CHAR))); + } + break; + } + } + } + ga_append(gap, '"'); + ga_grow(gap, (int) str_len); + for (size_t i = 0; i < utf_len;) { + const int ch = utf_ptr2char(utf_buf + i); + const size_t shift = (ch == 0? 1: utf_char2len(ch)); + assert(shift > 0); + // Is false on invalid unicode, but this should already be handled. + assert(ch == 0 || shift == utf_ptr2len(utf_buf + i)); + switch (ch) { + case BS: + case TAB: + case NL: + case FF: + case CAR: + case '"': + case '\\': { + ga_concat_len(gap, escapes[ch], 2); + break; + } + default: { + if (ENCODE_RAW(p_enc_conv, ch)) { + ga_concat_len(gap, utf_buf + i, shift); + } else if (ch < SURROGATE_FIRST_CHAR) { + ga_concat_len(gap, ((const char[]) { + '\\', 'u', + xdigits[(ch >> (4 * 3)) & 0xF], + xdigits[(ch >> (4 * 2)) & 0xF], + xdigits[(ch >> (4 * 1)) & 0xF], + xdigits[(ch >> (4 * 0)) & 0xF], + }), sizeof("\\u1234") - 1); + } else { + const int tmp = ch - SURROGATE_FIRST_CHAR; + const int hi = SURROGATE_HI_START + ((tmp >> 10) & ((1 << 10) - 1)); + const int lo = SURROGATE_LO_END + ((tmp >> 0) & ((1 << 10) - 1)); + ga_concat_len(gap, ((const char[]) { + '\\', 'u', + xdigits[(hi >> (4 * 3)) & 0xF], + xdigits[(hi >> (4 * 2)) & 0xF], + xdigits[(hi >> (4 * 1)) & 0xF], + xdigits[(hi >> (4 * 0)) & 0xF], + '\\', 'u', + xdigits[(lo >> (4 * 3)) & 0xF], + xdigits[(lo >> (4 * 2)) & 0xF], + xdigits[(lo >> (4 * 1)) & 0xF], + xdigits[(lo >> (4 * 0)) & 0xF], + }), (sizeof("\\u1234") - 1) * 2); + } + break; + } + } + i += shift; + } + ga_append(gap, '"'); + xfree(tofree); + } + return OK; +} + +#undef CONV_STRING +#define CONV_STRING(buf, len) \ + do { \ + if (convert_to_json_string(gap, (const char *) (buf), (len)) != OK) { \ + return FAIL; \ + } \ + } while (0) + +#undef CONV_EXT_STRING +#define CONV_EXT_STRING(buf, len, type) \ + do { \ + xfree(buf); \ + EMSG(_("E474: Unable to convert EXT string to JSON")); \ + return FAIL; \ + } while (0) + +#undef CONV_FUNC +#define CONV_FUNC(fun) \ + return conv_error(_("E474: Error while dumping %s, %s: " \ + "attempt to dump function reference"), \ + mpstack, objname) + +/// Check whether given key can be used in json_encode() +/// +/// @param[in] tv Key to check. +static inline bool check_json_key(const typval_T *const tv) + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE + FUNC_ATTR_ALWAYS_INLINE +{ + if (tv->v_type == VAR_STRING) { + return true; + } + if (tv->v_type != VAR_DICT) { + return false; + } + const dict_T *const spdict = tv->vval.v_dict; + if (spdict->dv_hashtab.ht_used != 2) { + return false; + } + const dictitem_T *type_di; + const dictitem_T *val_di; + if ((type_di = dict_find((dict_T *) spdict, (char_u *) "_TYPE", -1)) == NULL + || type_di->di_tv.v_type != VAR_LIST + || (type_di->di_tv.vval.v_list != eval_msgpack_type_lists[kMPString] + && type_di->di_tv.vval.v_list != eval_msgpack_type_lists[kMPBinary]) + || (val_di = dict_find((dict_T *) spdict, (char_u *) "_VAL", -1)) == NULL + || val_di->di_tv.v_type != VAR_LIST) { + return false; + } + if (val_di->di_tv.vval.v_list == NULL) { + return true; + } + for (const listitem_T *li = val_di->di_tv.vval.v_list->lv_first; + li != NULL; li = li->li_next) { + if (li->li_tv.v_type != VAR_STRING) { + return false; + } + } + return true; +} + +#undef CONV_SPECIAL_DICT_KEY_CHECK +#define CONV_SPECIAL_DICT_KEY_CHECK(name, kv_pair) \ + do { \ + if (!check_json_key(&kv_pair->lv_first->li_tv)) { \ + EMSG(_("E474: Invalid key in special dictionary")); \ + goto encode_vim_to_##name##_error_ret; \ + } \ + } while (0) + +DEFINE_VIML_CONV_FUNCTIONS(static, json, garray_T *const, gap) + +#undef CONV_STRING +#undef CONV_STR_STRING +#undef CONV_EXT_STRING +#undef CONV_NUMBER +#undef CONV_FLOAT +#undef CONV_FUNC +#undef CONV_EMPTY_LIST +#undef CONV_LIST_START +#undef CONV_EMPTY_DICT +#undef CONV_NIL +#undef CONV_BOOL +#undef CONV_UNSIGNED_NUMBER +#undef CONV_DICT_START +#undef CONV_DICT_END +#undef CONV_DICT_AFTER_KEY +#undef CONV_DICT_BETWEEN_ITEMS +#undef CONV_SPECIAL_DICT_KEY_CHECK +#undef CONV_LIST_END +#undef CONV_LIST_BETWEEN_ITEMS +#undef CONV_RECURSE +#undef CONV_ALLOW_SPECIAL + +/// Return a string with the string representation of a variable. +/// Puts quotes around strings, so that they can be parsed back by eval(). +/// +/// @param[in] tv typval_T to convert. +/// @param[out] len Location where length of the result will be saved. +/// +/// @return String representation of the variable or NULL. +char *encode_tv2string(typval_T *tv, size_t *len) + FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_MALLOC +{ + garray_T ga; + ga_init(&ga, (int)sizeof(char), 80); + encode_vim_to_string(&ga, tv, "encode_tv2string() argument"); + did_echo_string_emsg = false; + if (len != NULL) { + *len = (size_t) ga.ga_len; + } + ga_append(&ga, '\0'); + return (char *) ga.ga_data; +} + +/// Return a string with the string representation of a variable. +/// Does not put quotes around strings, as ":echo" displays values. +/// +/// @param[in] tv typval_T to convert. +/// @param[out] len Location where length of the result will be saved. +/// +/// @return String representation of the variable or NULL. +char *encode_tv2echo(typval_T *tv, size_t *len) + FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_MALLOC +{ + garray_T ga; + ga_init(&ga, (int)sizeof(char), 80); + if (tv->v_type == VAR_STRING || tv->v_type == VAR_FUNC) { + if (tv->vval.v_string != NULL) { + ga_concat(&ga, tv->vval.v_string); + } + } else { + encode_vim_to_echo(&ga, tv, ":echo argument"); + } + if (len != NULL) { + *len = (size_t) ga.ga_len; + } + ga_append(&ga, '\0'); + return (char *) ga.ga_data; +} + +/// Return a string with the string representation of a variable. +/// Puts quotes around strings, so that they can be parsed back by eval(). +/// +/// @param[in] tv typval_T to convert. +/// @param[out] len Location where length of the result will be saved. +/// +/// @return String representation of the variable or NULL. +char *encode_tv2json(typval_T *tv, size_t *len) + FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_MALLOC +{ + garray_T ga; + ga_init(&ga, (int)sizeof(char), 80); + encode_vim_to_json(&ga, tv, "encode_tv2json() argument"); + did_echo_string_emsg = false; + if (len != NULL) { + *len = (size_t) ga.ga_len; + } + ga_append(&ga, '\0'); + return (char *) ga.ga_data; +} + +#define CONV_STRING(buf, len) \ + do { \ + if (buf == NULL) { \ + msgpack_pack_bin(packer, 0); \ + } else { \ + const size_t len_ = (len); \ + msgpack_pack_bin(packer, len_); \ + msgpack_pack_bin_body(packer, buf, len_); \ + } \ + } while (0) + +#define CONV_STR_STRING(buf, len) \ + do { \ + if (buf == NULL) { \ + msgpack_pack_str(packer, 0); \ + } else { \ + const size_t len_ = (len); \ + msgpack_pack_str(packer, len_); \ + msgpack_pack_str_body(packer, buf, len_); \ + } \ + } while (0) + +#define CONV_EXT_STRING(buf, len, type) \ + do { \ + if (buf == NULL) { \ + msgpack_pack_ext(packer, 0, (int8_t) type); \ + } else { \ + const size_t len_ = (len); \ + msgpack_pack_ext(packer, len_, (int8_t) type); \ + msgpack_pack_ext_body(packer, buf, len_); \ + } \ + } while (0) + +#define CONV_NUMBER(num) \ + msgpack_pack_int64(packer, (int64_t) (num)) + +#define CONV_FLOAT(flt) \ + msgpack_pack_double(packer, (double) (flt)) + +#define CONV_FUNC(fun) \ + return conv_error(_("E951: Error while dumping %s, %s: " \ + "attempt to dump function reference"), \ + mpstack, objname) + +#define CONV_EMPTY_LIST() \ + msgpack_pack_array(packer, 0) + +#define CONV_LIST_START(lst) \ + msgpack_pack_array(packer, (size_t) (lst)->lv_len) + +#define CONV_EMPTY_DICT() \ + msgpack_pack_map(packer, 0) + +#define CONV_NIL() \ + msgpack_pack_nil(packer) + +#define CONV_BOOL(num) \ + do { \ + if ((num)) { \ + msgpack_pack_true(packer); \ + } else { \ + msgpack_pack_false(packer); \ + } \ + } while (0) + +#define CONV_UNSIGNED_NUMBER(num) \ + msgpack_pack_uint64(packer, (num)) + +#define CONV_DICT_START(len) \ + msgpack_pack_map(packer, (size_t) (len)) + +#define CONV_DICT_END() + +#define CONV_DICT_AFTER_KEY() + +#define CONV_DICT_BETWEEN_ITEMS() + +#define CONV_SPECIAL_DICT_KEY_CHECK(name, kv_pair) + +#define CONV_LIST_END(lst) + +#define CONV_LIST_BETWEEN_ITEMS() + +#define CONV_RECURSE(val, conv_type) \ + return conv_error(_("E952: Unable to dump %s: " \ + "container references itself in %s"), \ + mpstack, objname) + +#define CONV_ALLOW_SPECIAL true + +DEFINE_VIML_CONV_FUNCTIONS(, msgpack, msgpack_packer *const, packer) + +#undef CONV_STRING +#undef CONV_STR_STRING +#undef CONV_EXT_STRING +#undef CONV_NUMBER +#undef CONV_FLOAT +#undef CONV_FUNC +#undef CONV_EMPTY_LIST +#undef CONV_LIST_START +#undef CONV_EMPTY_DICT +#undef CONV_NIL +#undef CONV_BOOL +#undef CONV_UNSIGNED_NUMBER +#undef CONV_DICT_START +#undef CONV_DICT_END +#undef CONV_DICT_AFTER_KEY +#undef CONV_DICT_BETWEEN_ITEMS +#undef CONV_SPECIAL_DICT_KEY_CHECK +#undef CONV_LIST_END +#undef CONV_LIST_BETWEEN_ITEMS +#undef CONV_RECURSE +#undef CONV_ALLOW_SPECIAL diff --git a/src/nvim/eval/encode.h b/src/nvim/eval/encode.h new file mode 100644 index 0000000000..9bc665253b --- /dev/null +++ b/src/nvim/eval/encode.h @@ -0,0 +1,75 @@ +#ifndef NVIM_EVAL_ENCODE_H +#define NVIM_EVAL_ENCODE_H + +#include <stddef.h> + +#include <msgpack.h> + +#include "nvim/eval.h" +#include "nvim/garray.h" +#include "nvim/vim.h" // For STRLEN + +/// Convert VimL value to msgpack string +/// +/// @param[out] packer Packer to save results in. +/// @param[in] tv Dumped value. +/// @param[in] objname Object name, used for error message. +/// +/// @return OK in case of success, FAIL otherwise. +int encode_vim_to_msgpack(msgpack_packer *const packer, + typval_T *const tv, + const char *const objname); + +/// Convert VimL value to :echo output +/// +/// @param[out] packer Packer to save results in. +/// @param[in] tv Dumped value. +/// @param[in] objname Object name, used for error message. +/// +/// @return OK in case of success, FAIL otherwise. +int encode_vim_to_echo(garray_T *const packer, + typval_T *const tv, + const char *const objname); + +/// Structure defining state for read_from_list() +typedef struct { + const listitem_T *li; ///< Item currently read. + size_t offset; ///< Byte offset inside the read item. + size_t li_length; ///< Length of the string inside the read item. +} ListReaderState; + +/// Initialize ListReaderState structure +static inline ListReaderState encode_init_lrstate(const list_T *const list) + FUNC_ATTR_NONNULL_ALL +{ + return (ListReaderState) { + .li = list->lv_first, + .offset = 0, + .li_length = (list->lv_first->li_tv.vval.v_string == NULL + ? 0 + : STRLEN(list->lv_first->li_tv.vval.v_string)), + }; +} + +/// Array mapping values from SpecialVarValue enum to names +extern const char *const encode_special_var_names[]; + +/// First codepoint in high surrogates block +#define SURROGATE_HI_START 0xD800 + +/// Last codepoint in high surrogates block +#define SURROGATE_HI_END 0xDBFF + +/// First codepoint in low surrogates block +#define SURROGATE_LO_START 0xDC00 + +/// Last codepoint in low surrogates block +#define SURROGATE_LO_END 0xDFFF + +/// First character that needs to be encoded as surrogate pair +#define SURROGATE_FIRST_CHAR 0x10000 + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "eval/encode.h.generated.h" +#endif +#endif // NVIM_EVAL_ENCODE_H diff --git a/src/nvim/eval_defs.h b/src/nvim/eval_defs.h index cdad1f3197..8ffc0c98ce 100644 --- a/src/nvim/eval_defs.h +++ b/src/nvim/eval_defs.h @@ -16,39 +16,52 @@ typedef double float_T; typedef struct listvar_S list_T; typedef struct dictvar_S dict_T; -/* - * Structure to hold an internal variable without a name. - */ +/// Special variable values +typedef enum { + kSpecialVarFalse, ///< v:false + kSpecialVarTrue, ///< v:true + kSpecialVarNull, ///< v:null +} SpecialVarValue; + +/// Variable lock status for typval_T.v_lock +typedef enum { + VAR_UNLOCKED = 0, ///< Not locked. + VAR_LOCKED, ///< User lock, can be unlocked. + VAR_FIXED, ///< Locked forever. +} VarLockStatus; + +/// VimL variable types, for use in typval_T.v_type +typedef enum { + VAR_UNKNOWN = 0, ///< Unknown (unspecified) value. + VAR_NUMBER, ///< Number, .v_number is used. + VAR_STRING, ///< String, .v_string is used. + VAR_FUNC, ///< Function referene, .v_string is used for function name. + VAR_LIST, ///< List, .v_list is used. + VAR_DICT, ///< Dictionary, .v_dict is used. + VAR_FLOAT, ///< Floating-point value, .v_float is used. + VAR_SPECIAL, ///< Special value (true, false, null), .v_special + ///< is used. +} VarType; + +/// Structure that holds an internal variable value typedef struct { - char v_type; /* see below: VAR_NUMBER, VAR_STRING, etc. */ - char v_lock; /* see below: VAR_LOCKED, VAR_FIXED */ + VarType v_type; ///< Variable type. + VarLockStatus v_lock; ///< Variable lock status. union { - varnumber_T v_number; /* number value */ - float_T v_float; /* floating number value */ - char_u *v_string; /* string value (can be NULL!) */ - list_T *v_list; /* list value (can be NULL!) */ - dict_T *v_dict; /* dict value (can be NULL!) */ - } vval; + varnumber_T v_number; ///< Number, for VAR_NUMBER. + SpecialVarValue v_special; ///< Special value, for VAR_SPECIAL. + float_T v_float; ///< Floating-point number, for VAR_FLOAT. + char_u *v_string; ///< String, for VAR_STRING and VAR_FUNC, can be NULL. + list_T *v_list; ///< List for VAR_LIST, can be NULL. + dict_T *v_dict; ///< Dictionary for VAR_DICT, can be NULL. + } vval; ///< Actual value. } typval_T; -/* Values for "v_type". */ -#define VAR_UNKNOWN 0 -#define VAR_NUMBER 1 /* "v_number" is used */ -#define VAR_STRING 2 /* "v_string" is used */ -#define VAR_FUNC 3 /* "v_string" is function name */ -#define VAR_LIST 4 /* "v_list" is used */ -#define VAR_DICT 5 /* "v_dict" is used */ -#define VAR_FLOAT 6 /* "v_float" is used */ - /* Values for "dv_scope". */ #define VAR_SCOPE 1 /* a:, v:, s:, etc. scope dictionaries */ #define VAR_DEF_SCOPE 2 /* l:, g: scope dictionaries: here funcrefs are not allowed to mask existing functions */ -/* Values for "v_lock". */ -#define VAR_LOCKED 1 /* locked with lock(), can use unlock() */ -#define VAR_FIXED 2 /* locked forever */ - /* * Structure to hold an item of a list: an internal variable without a name. */ @@ -107,19 +120,18 @@ typedef struct dictitem_S dictitem_T; #define DI_FLAGS_LOCK 8 // "di_flags" value: locked variable #define DI_FLAGS_ALLOC 16 // "di_flags" value: separately allocated -/* - * Structure to hold info about a Dictionary. - */ +/// Structure representing a Dictionary struct dictvar_S { - char dv_lock; /* zero, VAR_LOCKED, VAR_FIXED */ - char dv_scope; /* zero, VAR_SCOPE, VAR_DEF_SCOPE */ - int dv_refcount; /* reference count */ - int dv_copyID; /* ID used by deepcopy() */ - hashtab_T dv_hashtab; /* hashtab that refers to the items */ - dict_T *dv_copydict; /* copied dict used by deepcopy() */ - dict_T *dv_used_next; /* next dict in used dicts list */ - dict_T *dv_used_prev; /* previous dict in used dicts list */ - QUEUE watchers; // dictionary key watchers set by user code + VarLockStatus dv_lock; ///< Whole dictionary lock status. + char dv_scope; ///< Non-zero (#VAR_SCOPE, #VAR_DEF_SCOPE) if + ///< dictionary represents a scope (i.e. g:, l: …). + int dv_refcount; ///< Reference count. + int dv_copyID; ///< ID used when recursivery traversing a value. + hashtab_T dv_hashtab; ///< Hashtab containing all items. + dict_T *dv_copydict; ///< Copied dict used by deepcopy(). + dict_T *dv_used_next; ///< Next dictionary in used dictionaries list. + dict_T *dv_used_prev; ///< Previous dictionary in used dictionaries list. + QUEUE watchers; ///< Dictionary key watchers set by user code. }; // structure used for explicit stack while garbage collecting hash tables diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index bfaa6d8e2a..ecc6e2b7e8 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -51,7 +51,6 @@ #include "nvim/strings.h" #include "nvim/syntax.h" #include "nvim/tag.h" -#include "nvim/tempfile.h" #include "nvim/ui.h" #include "nvim/undo.h" #include "nvim/window.h" @@ -1358,15 +1357,17 @@ char_u *make_filter_cmd(char_u *cmd, char_u *itmp, char_u *otmp) #endif size_t len = STRLEN(cmd) + 1; // At least enough space for cmd + NULL. - + len += is_fish_shell ? sizeof("begin; ""; end") - 1 : sizeof("("")") - 1; - if (itmp != NULL) + if (itmp != NULL) { len += STRLEN(itmp) + sizeof(" { "" < "" } ") - 1; - if (otmp != NULL) + } + if (otmp != NULL) { len += STRLEN(otmp) + STRLEN(p_srr) + 2; // two extra spaces (" "), - char_u *buf = xmalloc(len); + } + char *const buf = xmalloc(len); #if defined(UNIX) // Put delimiters around the command (for concatenated commands) when @@ -1374,19 +1375,19 @@ char_u *make_filter_cmd(char_u *cmd, char_u *itmp, char_u *otmp) if (itmp != NULL || otmp != NULL) { char *fmt = is_fish_shell ? "begin; %s; end" : "(%s)"; - vim_snprintf((char *)buf, len, fmt, (char *)cmd); + vim_snprintf(buf, len, fmt, (char *)cmd); } else { - STRCPY(buf, cmd); + strncpy(buf, (char *) cmd, len); } if (itmp != NULL) { - STRCAT(buf, " < "); - STRCAT(buf, itmp); + strncat(buf, " < ", len); + strncat(buf, (char *) itmp, len); } #else // For shells that don't understand braces around commands, at least allow // the use of commands in a pipe. - STRCPY(buf, cmd); + strncpy(buf, cmd, len); if (itmp != NULL) { char_u *p; @@ -1394,55 +1395,56 @@ char_u *make_filter_cmd(char_u *cmd, char_u *itmp, char_u *otmp) // Don't do this when 'shellquote' is not empty, otherwise the // redirection would be inside the quotes. if (*p_shq == NUL) { - p = vim_strchr(buf, '|'); - if (p != NULL) + p = strchr(buf, '|'); + if (p != NULL) { *p = NUL; + } } - STRCAT(buf, " < "); - STRCAT(buf, itmp); + strncat(buf, " < ", len); + strncat(buf, (char *) itmp, len); if (*p_shq == NUL) { - p = vim_strchr(cmd, '|'); + p = strchr(cmd, '|'); if (p != NULL) { - STRCAT(buf, " "); // Insert a space before the '|' for DOS - STRCAT(buf, p); + strncat(buf, " ", len); // Insert a space before the '|' for DOS + strncat(buf, p, len); } } } #endif - if (otmp != NULL) - append_redir(buf, (int)len, p_srr, otmp); - - return buf; + if (otmp != NULL) { + append_redir(buf, len, (char *) p_srr, (char *) otmp); + } + return (char_u *) buf; } -/* - * Append output redirection for file "fname" to the end of string buffer - * "buf[buflen]" - * Works with the 'shellredir' and 'shellpipe' options. - * The caller should make sure that there is enough room: - * STRLEN(opt) + STRLEN(fname) + 3 - */ -void append_redir(char_u *buf, int buflen, char_u *opt, char_u *fname) +/// Append output redirection for the given file to the end of the buffer +/// +/// @param[out] buf Buffer to append to. +/// @param[in] buflen Buffer length. +/// @param[in] opt Separator or format string to append: will append +/// `printf(' ' . opt, fname)` if `%s` is found in `opt` or +/// a space, opt, a space and then fname if `%s` is not found +/// there. +/// @param[in] fname File name to append. +void append_redir(char *const buf, const size_t buflen, + const char *const opt, const char *const fname) { - char_u *p; - char_u *end; - - end = buf + STRLEN(buf); - /* find "%s" */ - for (p = opt; (p = vim_strchr(p, '%')) != NULL; ++p) { - if (p[1] == 's') /* found %s */ + char *const end = buf + strlen(buf); + // find "%s" + const char *p = opt; + for (; (p = strchr(p, '%')) != NULL; p++) { + if (p[1] == 's') { // found %s break; - if (p[1] == '%') /* skip %% */ - ++p; + } else if (p[1] == '%') { // skip %% + p++; + } } if (p != NULL) { - *end = ' '; /* not really needed? Not with sh, ksh or bash */ - vim_snprintf((char *)end + 1, (size_t)(buflen - (end + 1 - buf)), - (char *)opt, (char *)fname); - } else - vim_snprintf((char *)end, (size_t)(buflen - (end - buf)), - " %s %s", - (char *)opt, (char *)fname); + *end = ' '; // not really needed? Not with sh, ksh or bash + vim_snprintf(end + 1, (size_t) (buflen - (end + 1 - buf)), opt, fname); + } else { + vim_snprintf(end, (size_t) (buflen - (end - buf)), " %s %s", opt, fname); + } } void print_line_no_prefix(linenr_T lnum, int use_number, int list) @@ -1538,8 +1540,11 @@ void ex_file(exarg_T *eap) if (rename_buffer(eap->arg) == FAIL) return; } - /* print full file name if :cd used */ - fileinfo(FALSE, FALSE, eap->forceit); + + if (!shortmess(SHM_FILEINFO)) { + // print full file name if :cd used + fileinfo(false, false, eap->forceit); + } } /* @@ -2122,15 +2127,13 @@ do_ecmd ( if ((command != NULL || newlnum > (linenr_T)0) && *get_vim_var_str(VV_SWAPCOMMAND) == NUL) { - char_u *p; - - /* Set v:swapcommand for the SwapExists autocommands. */ - size_t len = (command != NULL) ? STRLEN(command) + 3 : 30; - p = xmalloc(len); + // Set v:swapcommand for the SwapExists autocommands. + const size_t len = (command != NULL) ? STRLEN(command) + 3 : 30; + char *const p = xmalloc(len); if (command != NULL) { - vim_snprintf((char *)p, len, ":%s\r", command); + vim_snprintf(p, len, ":%s\r", command); } else { - vim_snprintf((char *)p, len, "%" PRId64 "G", (int64_t)newlnum); + vim_snprintf(p, len, "%" PRId64 "G", (int64_t)newlnum); } set_vim_var_string(VV_SWAPCOMMAND, p, -1); did_set_swapcommand = TRUE; @@ -2515,7 +2518,9 @@ do_ecmd ( msg_scroll = msg_scroll_save; msg_scrolled_ign = TRUE; - fileinfo(FALSE, TRUE, FALSE); + if (!shortmess(SHM_FILEINFO)) { + fileinfo(false, true, false); + } msg_scrolled_ign = FALSE; } diff --git a/src/nvim/ex_cmds.lua b/src/nvim/ex_cmds.lua index 6c8835b5c5..04fd88cc8d 100644 --- a/src/nvim/ex_cmds.lua +++ b/src/nvim/ex_cmds.lua @@ -2575,6 +2575,18 @@ return { func='ex_copymove', }, { + command='tcd', + flags=bit.bor(BANG, FILE1, TRLBAR, CMDWIN), + addr_type=ADDR_LINES, + func='ex_cd', + }, + { + command='tchdir', + flags=bit.bor(BANG, FILE1, TRLBAR, CMDWIN), + addr_type=ADDR_LINES, + func='ex_cd', + }, + { command='tNext', flags=bit.bor(RANGE, NOTADR, BANG, TRLBAR, ZEROR), addr_type=ADDR_LINES, diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 71ea170e1c..2c8271c696 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -3168,27 +3168,27 @@ static char_u *get_mess_env(void) */ void set_lang_var(void) { - char_u *loc; + const char *loc; # ifdef HAVE_GET_LOCALE_VAL - loc = (char_u *)get_locale_val(LC_CTYPE); + loc = get_locale_val(LC_CTYPE); # else - /* setlocale() not supported: use the default value */ - loc = (char_u *)"C"; + // setlocale() not supported: use the default value + loc = "C"; # endif set_vim_var_string(VV_CTYPE, loc, -1); /* When LC_MESSAGES isn't defined use the value from $LC_MESSAGES, fall * back to LC_CTYPE if it's empty. */ # ifdef HAVE_WORKING_LIBINTL - loc = get_mess_env(); + loc = (char *) get_mess_env(); # else - loc = (char_u *)get_locale_val(LC_MESSAGES); + loc = get_locale_val(LC_MESSAGES); # endif set_vim_var_string(VV_LANG, loc, -1); # ifdef HAVE_GET_LOCALE_VAL - loc = (char_u *)get_locale_val(LC_TIME); + loc = get_locale_val(LC_TIME); # endif set_vim_var_string(VV_LC_TIME, loc, -1); } diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index a7e98e7f04..2d316cb106 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -2958,8 +2958,11 @@ set_one_cmd_context ( case CMD_chdir: case CMD_lcd: case CMD_lchdir: - if (xp->xp_context == EXPAND_FILES) + case CMD_tcd: + case CMD_tchdir: + if (xp->xp_context == EXPAND_FILES) { xp->xp_context = EXPAND_DIRECTORIES; + } break; case CMD_help: xp->xp_context = EXPAND_HELP; @@ -6814,36 +6817,55 @@ void free_cd_dir(void) #endif -/* - * Deal with the side effects of changing the current directory. - * When "local" is TRUE then this was after an ":lcd" command. - */ -void post_chdir(int local) +/// Deal with the side effects of changing the current directory. +/// +/// @param scope Scope of the function call (global, tab or window). +void post_chdir(CdScope scope) { + // The local directory of the current window is always overwritten. xfree(curwin->w_localdir); curwin->w_localdir = NULL; - if (local) { - /* If still in global directory, need to remember current - * directory as global directory. */ - if (globaldir == NULL && prev_dir != NULL) + + // Overwrite the local directory of the current tab page for `cd` and `tcd` + if (scope >= kCdScopeTab) { + xfree(curtab->localdir); + curtab->localdir = NULL; + } + + if (scope < kCdScopeGlobal) { + // If still in global directory, need to remember current directory as + // global directory. + if (globaldir == NULL && prev_dir != NULL) { globaldir = vim_strsave(prev_dir); - /* Remember this local directory for the window. */ - if (os_dirname(NameBuff, MAXPATHL) == OK) - curwin->w_localdir = vim_strsave(NameBuff); - } else { - /* We are now in the global directory, no need to remember its - * name. */ + } + } + + switch (scope) { + case kCdScopeGlobal: + // We are now in the global directory, no need to remember its name. xfree(globaldir); globaldir = NULL; + break; + case kCdScopeTab: + // Remember this local directory for the tab page. + if (os_dirname(NameBuff, MAXPATHL) == OK) { + curtab->localdir = vim_strsave(NameBuff); + } + break; + case kCdScopeWindow: + // Remember this local directory for the window. + if (os_dirname(NameBuff, MAXPATHL) == OK) { + curwin->w_localdir = vim_strsave(NameBuff); + } + break; } shorten_fnames(TRUE); } -/* - * ":cd", ":lcd", ":chdir" and ":lchdir". - */ + +/// `:cd`, `:tcd`, `:lcd`, `:chdir`, `:tchdir` and `:lchdir`. void ex_cd(exarg_T *eap) { char_u *new_dir; @@ -6884,10 +6906,25 @@ void ex_cd(exarg_T *eap) new_dir = NameBuff; } #endif - if (new_dir == NULL || vim_chdir(new_dir)) + if (vim_chdir(new_dir)) { EMSG(_(e_failed)); - else { - post_chdir(eap->cmdidx == CMD_lcd || eap->cmdidx == CMD_lchdir); + } else { + CdScope scope = kCdScopeGlobal; // Depends on command invoked + + switch (eap->cmdidx) { + case CMD_tcd: + case CMD_tchdir: + scope = kCdScopeTab; + break; + case CMD_lcd: + case CMD_lchdir: + scope = kCdScopeWindow; + break; + default: + break; + } + + post_chdir(scope); /* Echo the new current directory if the command was typed. */ if (KeyTyped || p_verbose >= 5) @@ -7421,10 +7458,10 @@ static int mksession_nl = FALSE; /* use NL only in put_eol() */ static void ex_mkrc(exarg_T *eap) { FILE *fd; - int failed = FALSE; - int view_session = FALSE; - int using_vdir = FALSE; /* using 'viewdir'? */ - char_u *viewFile = NULL; + int failed = false; + int view_session = false; + int using_vdir = false; // using 'viewdir'? + char *viewFile = NULL; unsigned *flagp; if (eap->cmdidx == CMD_mksession || eap->cmdidx == CMD_mkview) { @@ -7435,32 +7472,34 @@ static void ex_mkrc(exarg_T *eap) * short file name when 'acd' is set, that is checked later. */ did_lcd = FALSE; - char_u *fname; - /* ":mkview" or ":mkview 9": generate file name with 'viewdir' */ + char *fname; + // ":mkview" or ":mkview 9": generate file name with 'viewdir' if (eap->cmdidx == CMD_mkview && (*eap->arg == NUL || (ascii_isdigit(*eap->arg) && eap->arg[1] == NUL))) { - eap->forceit = TRUE; - fname = (char_u *)get_view_file(*eap->arg); - if (fname == NULL) + eap->forceit = true; + fname = get_view_file(*eap->arg); + if (fname == NULL) { return; + } viewFile = fname; - using_vdir = TRUE; - } else if (*eap->arg != NUL) - fname = eap->arg; - else if (eap->cmdidx == CMD_mkvimrc) - fname = (char_u *)VIMRC_FILE; - else if (eap->cmdidx == CMD_mksession) - fname = (char_u *)SESSION_FILE; - else - fname = (char_u *)EXRC_FILE; + using_vdir = true; + } else if (*eap->arg != NUL) { + fname = (char *) eap->arg; + } else if (eap->cmdidx == CMD_mkvimrc) { + fname = VIMRC_FILE; + } else if (eap->cmdidx == CMD_mksession) { + fname = SESSION_FILE; + } else { + fname = EXRC_FILE; + } /* When using 'viewdir' may have to create the directory. */ if (using_vdir && !os_isdir(p_vdir)) { vim_mkdir_emsg(p_vdir, 0755); } - fd = open_exfile(fname, eap->forceit, WRITEBIN); + fd = open_exfile((char_u *) fname, eap->forceit, WRITEBIN); if (fd != NULL) { if (eap->cmdidx == CMD_mkview) flagp = &vop_flags; @@ -7504,8 +7543,9 @@ static void ex_mkrc(exarg_T *eap) || os_chdir((char *)dirnow) != 0) *dirnow = NUL; if (*dirnow != NUL && (ssop_flags & SSOP_SESDIR)) { - if (vim_chdirfile(fname) == OK) - shorten_fnames(TRUE); + if (vim_chdirfile((char_u *) fname) == OK) { + shorten_fnames(true); + } } else if (*dirnow != NUL && (ssop_flags & SSOP_CURDIR) && globaldir != NULL) { if (os_chdir((char *)globaldir) == 0) @@ -7550,15 +7590,14 @@ static void ex_mkrc(exarg_T *eap) failed |= fclose(fd); - if (failed) + if (failed) { EMSG(_(e_write)); - else if (eap->cmdidx == CMD_mksession) { - /* successful session write - set this_session var */ - char_u *tbuf; - - tbuf = xmalloc(MAXPATHL); - if (vim_FullName((char *)fname, (char *)tbuf, MAXPATHL, FALSE) == OK) + } else if (eap->cmdidx == CMD_mksession) { + // successful session write - set this_session var + char *const tbuf = xmalloc(MAXPATHL); + if (vim_FullName(fname, tbuf, MAXPATHL, false) == OK) { set_vim_var_string(VV_THIS_SESSION, tbuf, -1); + } xfree(tbuf); } #ifdef MKSESSION_NL diff --git a/src/nvim/ex_docmd.h b/src/nvim/ex_docmd.h index a5a4edbbbf..7af3ee233c 100644 --- a/src/nvim/ex_docmd.h +++ b/src/nvim/ex_docmd.h @@ -19,6 +19,18 @@ #define EXMODE_NORMAL 1 #define EXMODE_VIM 2 +/// The scope of a command. +/// +/// The lower a number, the deeper the scope. +typedef enum { + kCdScopeWindow, ///< Affects one window. + kCdScopeTab, ///< Affects one tab page. + kCdScopeGlobal, ///< Affects the entire instance of NeoVim. +} CdScope; + +/// Last `:cd` scope defined. +#define MAX_CD_SCOPE kCdScopeGlobal + #ifdef INCLUDE_GENERATED_DECLARATIONS # include "ex_docmd.h.generated.h" #endif diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c index bf67047ae8..41ad96a378 100644 --- a/src/nvim/ex_eval.c +++ b/src/nvim/ex_eval.c @@ -378,7 +378,7 @@ char_u *get_exception_string(void *value, int type, char_u *cmdname, int *should char_u *p, *val; if (type == ET_ERROR) { - *should_free = FALSE; + *should_free = true; mesg = ((struct msglist *)value)->throw_msg; if (cmdname != NULL && *cmdname != NUL) { size_t cmdlen = STRLEN(cmdname); @@ -569,17 +569,19 @@ static void catch_exception(except_T *excp) { excp->caught = caught_stack; caught_stack = excp; - set_vim_var_string(VV_EXCEPTION, excp->value, -1); + set_vim_var_string(VV_EXCEPTION, (char *) excp->value, -1); if (*excp->throw_name != NUL) { - if (excp->throw_lnum != 0) + if (excp->throw_lnum != 0) { vim_snprintf((char *)IObuff, IOSIZE, _("%s, line %" PRId64), - excp->throw_name, (int64_t)excp->throw_lnum); - else + excp->throw_name, (int64_t)excp->throw_lnum); + } else { vim_snprintf((char *)IObuff, IOSIZE, "%s", excp->throw_name); - set_vim_var_string(VV_THROWPOINT, IObuff, -1); - } else - /* throw_name not set on an exception from a command that was typed. */ + } + set_vim_var_string(VV_THROWPOINT, (char *) IObuff, -1); + } else { + // throw_name not set on an exception from a command that was typed. set_vim_var_string(VV_THROWPOINT, NULL, -1); + } if (p_verbose >= 13 || debug_break_level > 0) { int save_msg_silent = msg_silent; @@ -614,20 +616,22 @@ static void finish_exception(except_T *excp) EMSG(_(e_internal)); caught_stack = caught_stack->caught; if (caught_stack != NULL) { - set_vim_var_string(VV_EXCEPTION, caught_stack->value, -1); + set_vim_var_string(VV_EXCEPTION, (char *) caught_stack->value, -1); if (*caught_stack->throw_name != NUL) { - if (caught_stack->throw_lnum != 0) + if (caught_stack->throw_lnum != 0) { vim_snprintf((char *)IObuff, IOSIZE, - _("%s, line %" PRId64), caught_stack->throw_name, - (int64_t)caught_stack->throw_lnum); - else + _("%s, line %" PRId64), caught_stack->throw_name, + (int64_t)caught_stack->throw_lnum); + } else { vim_snprintf((char *)IObuff, IOSIZE, "%s", - caught_stack->throw_name); - set_vim_var_string(VV_THROWPOINT, IObuff, -1); - } else - /* throw_name not set on an exception from a command that was - * typed. */ + caught_stack->throw_name); + } + set_vim_var_string(VV_THROWPOINT, (char *) IObuff, -1); + } else { + // throw_name not set on an exception from a command that was + // typed. set_vim_var_string(VV_THROWPOINT, NULL, -1); + } } else { set_vim_var_string(VV_EXCEPTION, NULL, -1); set_vim_var_string(VV_THROWPOINT, NULL, -1); @@ -1370,19 +1374,24 @@ void ex_catch(exarg_T *eap) } save_cpo = p_cpo; p_cpo = (char_u *)""; + // Disable error messages, it will make current exception + // invalid + emsg_off++; regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING); - regmatch.rm_ic = FALSE; - if (end != NULL) + emsg_off--; + regmatch.rm_ic = false; + if (end != NULL) { *end = save_char; + } p_cpo = save_cpo; - if (regmatch.regprog == NULL) + if (regmatch.regprog == NULL) { EMSG2(_(e_invarg2), pat); - else { - /* - * Save the value of got_int and reset it. We don't want - * a previous interruption cancel matching, only hitting - * CTRL-C while matching should abort it. - */ + } else { + // + // Save the value of got_int and reset it. We don't want + // a previous interruption cancel matching, only hitting + // CTRL-C while matching should abort it. + // prev_got_int = got_int; got_int = FALSE; caught = vim_regexec_nl(®match, current_exception->value, diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 39bff9b2ad..cffda1ca55 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1130,7 +1130,7 @@ static int command_line_handle_key(CommandLineState *s) if (!mouse_has(MOUSE_COMMAND)) { return command_line_not_changed(s); // Ignore mouse } - cmdline_paste(0, true, true); + cmdline_paste(eval_has_provider("clipboard") ? '*' : 0, true, true); redrawcmd(); return command_line_changed(s); @@ -2424,20 +2424,17 @@ void restore_cmdline_alloc(char_u *p) xfree(p); } -/* - * paste a yank register into the command line. - * used by CTRL-R command in command-line mode - * insert_reg() can't be used here, because special characters from the - * register contents will be interpreted as commands. - * - * return FAIL for failure, OK otherwise - */ -static int -cmdline_paste ( - int regname, - int literally, /* Insert text literally instead of "as typed" */ - int remcr /* remove trailing CR */ -) +/// Paste a yank register into the command line. +/// Used by CTRL-R command in command-line mode. +/// insert_reg() can't be used here, because special characters from the +/// register contents will be interpreted as commands. +/// +/// @param regname Register name. +/// @param literally Insert text literally instead of "as typed". +/// @param remcr When true, remove trailing CR. +/// +/// @returns FAIL for failure, OK otherwise +static bool cmdline_paste(int regname, bool literally, bool remcr) { long i; char_u *arg; diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 383cd47dbe..c7870b9f69 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -45,7 +45,6 @@ #include "nvim/search.h" #include "nvim/sha256.h" #include "nvim/strings.h" -#include "nvim/tempfile.h" #include "nvim/ui.h" #include "nvim/types.h" #include "nvim/undo.h" @@ -2139,9 +2138,10 @@ readfile_charconvert ( else { close(*fdp); /* close the input file, ignore errors */ *fdp = -1; - if (eval_charconvert(fenc, enc_utf8 ? (char_u *)"utf-8" : p_enc, - fname, tmpname) == FAIL) + if (eval_charconvert((char *) fenc, enc_utf8 ? "utf-8" : (char *) p_enc, + (char *) fname, (char *) tmpname) == FAIL) { errmsg = (char_u *)_("Conversion with 'charconvert' failed"); + } if (errmsg == NULL && (*fdp = os_open((char *)tmpname, O_RDONLY, 0)) < 0) { errmsg = (char_u *)_("can't read output of 'charconvert'"); } @@ -3435,9 +3435,9 @@ restore_backup: * with 'charconvert' to (overwrite) the output file. */ if (end != 0) { - if (eval_charconvert(enc_utf8 ? (char_u *)"utf-8" : p_enc, fenc, - wfname, fname) == FAIL) { - write_info.bw_conv_error = TRUE; + if (eval_charconvert(enc_utf8 ? "utf-8" : (char *) p_enc, (char *) fenc, + (char *) wfname, (char *) fname) == FAIL) { + write_info.bw_conv_error = true; end = 0; } } @@ -4740,7 +4740,6 @@ buf_check_timestamp ( { int retval = 0; char_u *path; - char_u *tbuf; char *mesg = NULL; char *mesg2 = ""; int helpmesg = FALSE; @@ -4810,19 +4809,17 @@ buf_check_timestamp ( else reason = "time"; - /* - * Only give the warning if there are no FileChangedShell - * autocommands. - * Avoid being called recursively by setting "busy". - */ - busy = TRUE; - set_vim_var_string(VV_FCS_REASON, (char_u *)reason, -1); - set_vim_var_string(VV_FCS_CHOICE, (char_u *)"", -1); - ++allbuf_lock; + // Only give the warning if there are no FileChangedShell + // autocommands. + // Avoid being called recursively by setting "busy". + busy = true; + set_vim_var_string(VV_FCS_REASON, reason, -1); + set_vim_var_string(VV_FCS_CHOICE, "", -1); + allbuf_lock++; n = apply_autocmds(EVENT_FILECHANGEDSHELL, - buf->b_fname, buf->b_fname, FALSE, buf); - --allbuf_lock; - busy = FALSE; + buf->b_fname, buf->b_fname, false, buf); + allbuf_lock--; + busy = false; if (n) { if (!buf_valid(buf)) EMSG(_("E246: FileChangedShell autocommand deleted buffer")); @@ -4876,35 +4873,39 @@ buf_check_timestamp ( if (mesg != NULL) { path = home_replace_save(buf, buf->b_fname); - if (!helpmesg) + if (!helpmesg) { mesg2 = ""; - tbuf = xmalloc(STRLEN(path) + STRLEN(mesg) + STRLEN(mesg2) + 2); - sprintf((char *)tbuf, mesg, path); - /* Set warningmsg here, before the unimportant and output-specific - * mesg2 has been appended. */ + } + const size_t tbuf_len = STRLEN(path) + STRLEN(mesg) + STRLEN(mesg2) + 2; + char *const tbuf = xmalloc(tbuf_len); + snprintf(tbuf, tbuf_len, mesg, path); + // Set warningmsg here, before the unimportant and output-specific + // mesg2 has been appended. set_vim_var_string(VV_WARNINGMSG, tbuf, -1); if (can_reload) { if (*mesg2 != NUL) { - STRCAT(tbuf, "\n"); - STRCAT(tbuf, mesg2); + strncat(tbuf, "\n", tbuf_len); + strncat(tbuf, mesg2, tbuf_len); + } + if (do_dialog(VIM_WARNING, (char_u *) _("Warning"), (char_u *) tbuf, + (char_u *) _("&OK\n&Load File"), 1, NULL, true) == 2) { + reload = true; } - if (do_dialog(VIM_WARNING, (char_u *)_("Warning"), tbuf, - (char_u *)_("&OK\n&Load File"), 1, NULL, TRUE) == 2) - reload = TRUE; } else if (State > NORMAL_BUSY || (State & CMDLINE) || already_warned) { if (*mesg2 != NUL) { - STRCAT(tbuf, "; "); - STRCAT(tbuf, mesg2); + strncat(tbuf, "; ", tbuf_len); + strncat(tbuf, mesg2, tbuf_len); } EMSG(tbuf); retval = 2; } else { if (!autocmd_busy) { msg_start(); - msg_puts_attr(tbuf, hl_attr(HLF_E) + MSG_HIST); - if (*mesg2 != NUL) + msg_puts_attr((char_u *) tbuf, hl_attr(HLF_E) + MSG_HIST); + if (*mesg2 != NUL) { msg_puts_attr((char_u *)mesg2, hl_attr(HLF_W) + MSG_HIST); + } msg_clr_eos(); (void)msg_end(); if (emsg_silent == 0) { @@ -5114,6 +5115,147 @@ void forward_slash(char_u *fname) } #endif +/// Name of Vim's own temp dir. Ends in a slash. +static char_u *vim_tempdir = NULL; + +/// Create a directory for private use by this instance of Neovim. +/// This is done once, and the same directory is used for all temp files. +/// This method avoids security problems because of symlink attacks et al. +/// It's also a bit faster, because we only need to check for an existing +/// file when creating the directory and not for each temp file. +static void vim_maketempdir(void) +{ + static const char *temp_dirs[] = TEMP_DIR_NAMES; + // Try the entries in `TEMP_DIR_NAMES` to create the temp directory. + char_u template[TEMP_FILE_PATH_MAXLEN]; + char_u path[TEMP_FILE_PATH_MAXLEN]; + for (size_t i = 0; i < ARRAY_SIZE(temp_dirs); i++) { + // Expand environment variables, leave room for "/nvimXXXXXX/999999999" + expand_env((char_u *)temp_dirs[i], template, TEMP_FILE_PATH_MAXLEN - 22); + if (!os_isdir(template)) { // directory doesn't exist + continue; + } + + add_pathsep((char *)template); + // Concatenate with temporary directory name pattern + STRCAT(template, "nvimXXXXXX"); + + if (os_mkdtemp((const char *)template, (char *)path) != 0) { + continue; + } + + if (vim_settempdir((char *)path)) { + // Successfully created and set temporary directory so stop trying. + break; + } else { + // Couldn't set `vim_tempdir` to `path` so remove created directory. + os_rmdir((char *)path); + } + } +} + +/// Delete "name" and everything in it, recursively. +/// @param name The path which should be deleted. +/// @return 0 for success, -1 if some file was not deleted. +int delete_recursive(char_u *name) +{ + int result = 0; + + if (os_isrealdir(name)) { + snprintf((char *)NameBuff, MAXPATHL, "%s/*", name); // NOLINT + + char_u **files; + int file_count; + char_u *exp = vim_strsave(NameBuff); + if (gen_expand_wildcards(1, &exp, &file_count, &files, + EW_DIR | EW_FILE | EW_SILENT | EW_ALLLINKS + | EW_DODOT | EW_EMPTYOK) == OK) { + for (int i = 0; i < file_count; i++) { + if (delete_recursive(files[i]) != 0) { + result = -1; + } + } + FreeWild(file_count, files); + } else { + result = -1; + } + + xfree(exp); + os_rmdir((char *)name); + } else { + result = os_remove((char *)name) == 0 ? 0 : -1; + } + + return result; +} + +/// Delete the temp directory and all files it contains. +void vim_deltempdir(void) +{ + if (vim_tempdir != NULL) { + // remove the trailing path separator + path_tail(vim_tempdir)[-1] = NUL; + delete_recursive(vim_tempdir); + xfree(vim_tempdir); + vim_tempdir = NULL; + } +} + +/// Get the name of temp directory. This directory would be created on the first +/// call to this function. +char_u *vim_gettempdir(void) +{ + if (vim_tempdir == NULL) { + vim_maketempdir(); + } + + return vim_tempdir; +} + +/// Set Neovim own temporary directory name to `tempdir`. This directory should +/// be already created. Expand this name to a full path and put it in +/// `vim_tempdir`. This avoids that using `:cd` would confuse us. +/// +/// @param tempdir must be no longer than MAXPATHL. +/// +/// @return false if we run out of memory. +static bool vim_settempdir(char *tempdir) +{ + char *buf = verbose_try_malloc(MAXPATHL + 2); + if (!buf) { + return false; + } + vim_FullName(tempdir, buf, MAXPATHL, false); + add_pathsep(buf); + vim_tempdir = (char_u *)xstrdup(buf); + xfree(buf); + return true; +} + +/// Return a unique name that can be used for a temp file. +/// +/// @note The temp file is NOT created. +/// +/// @return pointer to the temp file name or NULL if Neovim can't create +/// temporary directory for its own temporary files. +char_u *vim_tempname(void) +{ + // Temp filename counter. + static uint32_t temp_count; + + char_u *tempdir = vim_gettempdir(); + if (!tempdir) { + return NULL; + } + + // There is no need to check if the file exists, because we own the directory + // and nobody else creates a file in it. + char_u template[TEMP_FILE_PATH_MAXLEN]; + snprintf((char *)template, TEMP_FILE_PATH_MAXLEN, + "%s%" PRIu32, tempdir, temp_count++); + return vim_strsave(template); +} + /* * Code for automatic commands. diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 6c135ef47b..7f46a37315 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -762,6 +762,10 @@ void clearFolding(win_T *win) */ void foldUpdate(win_T *wp, linenr_T top, linenr_T bot) { + if (compl_busy) { + return; + } + fold_T *fp; if (wp->w_buffer->terminal) { return; @@ -1695,14 +1699,14 @@ char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, did_emsg = FALSE; if (*wp->w_p_fdt != NUL) { - char_u dashes[MAX_LEVEL + 2]; + char dashes[MAX_LEVEL + 2]; win_T *save_curwin; int level; char_u *p; - /* Set "v:foldstart" and "v:foldend". */ - set_vim_var_nr(VV_FOLDSTART, lnum); - set_vim_var_nr(VV_FOLDEND, lnume); + // Set "v:foldstart" and "v:foldend". + set_vim_var_nr(VV_FOLDSTART, (varnumber_T) lnum); + set_vim_var_nr(VV_FOLDEND, (varnumber_T) lnume); /* Set "v:folddashes" to a string of "level" dashes. */ /* Set "v:foldlevel" to "level". */ @@ -1712,7 +1716,7 @@ char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, memset(dashes, '-', (size_t)level); dashes[level] = NUL; set_vim_var_string(VV_FOLDDASHES, dashes, -1); - set_vim_var_nr(VV_FOLDLEVEL, (long)level); + set_vim_var_nr(VV_FOLDLEVEL, (varnumber_T) level); /* skip evaluating foldtext on errors */ if (!got_fdt_error) { @@ -2672,7 +2676,7 @@ static void foldlevelExpr(fline_T *flp) win = curwin; curwin = flp->wp; curbuf = flp->wp->w_buffer; - set_vim_var_nr(VV_LNUM, lnum); + set_vim_var_nr(VV_LNUM, (varnumber_T) lnum); flp->start = 0; flp->had_end = flp->end; diff --git a/src/nvim/garray.c b/src/nvim/garray.c index e6cbd9332b..98cec69b54 100644 --- a/src/nvim/garray.c +++ b/src/nvim/garray.c @@ -188,12 +188,23 @@ void ga_concat(garray_T *gap, const char_u *restrict s) return; } - int len = (int)strlen((char *) s); + ga_concat_len(gap, (const char *restrict) s, strlen((char *) s)); +} + +/// Concatenate a string to a growarray which contains characters +/// +/// @param[out] gap Growarray to modify. +/// @param[in] s String to concatenate. +/// @param[in] len String length. +void ga_concat_len(garray_T *const gap, const char *restrict s, + const size_t len) + FUNC_ATTR_NONNULL_ALL +{ if (len) { - ga_grow(gap, len); + ga_grow(gap, (int) len); char *data = gap->ga_data; - memcpy(data + gap->ga_len, s, (size_t)len); - gap->ga_len += len; + memcpy(data + gap->ga_len, s, len); + gap->ga_len += (int) len; } } diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 69e65c3208..49d1de21d9 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -4,17 +4,7 @@ #include <stdbool.h> #include <inttypes.h> -// EXTERN is only defined in main.c. That's where global variables are -// actually defined and initialized. -#ifndef EXTERN -# define EXTERN extern -# define INIT(...) -#else -# ifndef INIT -# define INIT(...) __VA_ARGS__ -# endif -#endif - +#include "nvim/macros.h" #include "nvim/ex_eval.h" #include "nvim/iconv.h" #include "nvim/mbyte.h" @@ -214,6 +204,10 @@ EXTERN int compl_length INIT(= 0); * stop looking for matches. */ EXTERN int compl_interrupted INIT(= FALSE); +// Set when doing something for completion that may call edit() recursively, +// which is not allowed. Also used to disable folding during completion +EXTERN int compl_busy INIT(= false); + /* List of flags for method of completion. */ EXTERN int compl_cont_status INIT(= 0); # define CONT_ADDING 1 /* "normal" or "adding" expansion */ @@ -918,8 +912,8 @@ EXTERN int KeyTyped; // TRUE if user typed current char EXTERN int KeyStuffed; // TRUE if current char from stuffbuf EXTERN int maptick INIT(= 0); // tick for each non-mapped char -EXTERN char_u chartab[256]; /* table used in charset.c; See - init_chartab() for explanation */ +EXTERN uint8_t chartab[256]; // table used in charset.c; See + // init_chartab() for explanation EXTERN int must_redraw INIT(= 0); /* type of redraw necessary */ EXTERN int skip_redraw INIT(= FALSE); /* skip redraw once */ diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index ab8959239b..6ce8954fef 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -32,7 +32,6 @@ #include "nvim/syntax.h" #include "nvim/ui.h" #include "nvim/version.h" -#include "nvim/tempfile.h" #include "nvim/os/os.h" #include "nvim/os/input.h" @@ -2780,11 +2779,13 @@ void mch_print_end(prt_settings_T *psettings) } prt_message((char_u *)_("Sending to printer...")); - /* Not printing to a file: use 'printexpr' to print the file. */ - if (eval_printexpr(prt_ps_file_name, psettings->arguments) == FAIL) + // Not printing to a file: use 'printexpr' to print the file. + if (eval_printexpr((char *) prt_ps_file_name, (char *) psettings->arguments) + == FAIL) { EMSG(_("E365: Failed to print PostScript file")); - else + } else { prt_message((char_u *)_("Print job sent.")); + } } mch_print_cleanup(); diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c index 7169a1d963..daddd7cee4 100644 --- a/src/nvim/if_cscope.c +++ b/src/nvim/if_cscope.c @@ -27,7 +27,6 @@ #include "nvim/quickfix.h" #include "nvim/strings.h" #include "nvim/tag.h" -#include "nvim/tempfile.h" #include "nvim/window.h" #include "nvim/os/os.h" #include "nvim/os/input.h" @@ -2081,12 +2080,13 @@ static int cs_show(exarg_T *eap) if (csinfo[i].fname == NULL) continue; - if (csinfo[i].ppath != NULL) - (void)smsg("%2zu %-5" PRId64 " %-34s %-32s", - i, (long)csinfo[i].pid, csinfo[i].fname, csinfo[i].ppath); - else - (void)smsg("%2zu %-5" PRId64 " %-34s <none>", - i, (long)csinfo[i].pid, csinfo[i].fname); + if (csinfo[i].ppath != NULL) { + (void)smsg("%2zu %-5" PRId64 " %-34s %-32s", i, + (int64_t)csinfo[i].pid, csinfo[i].fname, csinfo[i].ppath); + } else { + (void)smsg("%2zu %-5" PRId64 " %-34s <none>", i, + (int64_t)csinfo[i].pid, csinfo[i].fname); + } } } diff --git a/src/nvim/indent.c b/src/nvim/indent.c index d3008185dc..f197669a97 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -529,7 +529,7 @@ int get_expr_indent(void) save_pos = curwin->w_cursor; save_curswant = curwin->w_curswant; save_set_curswant = curwin->w_set_curswant; - set_vim_var_nr(VV_LNUM, curwin->w_cursor.lnum); + set_vim_var_nr(VV_LNUM, (varnumber_T) curwin->w_cursor.lnum); if (use_sandbox) { sandbox++; diff --git a/src/nvim/lib/kvec.h b/src/nvim/lib/kvec.h index 53ecf232c6..b41ef0cc9f 100644 --- a/src/nvim/lib/kvec.h +++ b/src/nvim/lib/kvec.h @@ -60,6 +60,7 @@ int main() { #define kv_pop(v) ((v).items[--(v).size]) #define kv_size(v) ((v).size) #define kv_max(v) ((v).capacity) +#define kv_last(v) kv_A(v, kv_size(v) - 1) #define kv_resize(type, v, s) ((v).capacity = (s), (v).items = (type*)xrealloc((v).items, sizeof(type) * (v).capacity)) diff --git a/src/nvim/macros.h b/src/nvim/macros.h index 26ab5a7de7..5f69fa2f6a 100644 --- a/src/nvim/macros.h +++ b/src/nvim/macros.h @@ -1,6 +1,17 @@ #ifndef NVIM_MACROS_H #define NVIM_MACROS_H +// EXTERN is only defined in main.c. That's where global variables are +// actually defined and initialized. +#ifndef EXTERN +# define EXTERN extern +# define INIT(...) +#else +# ifndef INIT +# define INIT(...) __VA_ARGS__ +# endif +#endif + #ifndef MIN # define MIN(X, Y) ((X) < (Y) ? (X) : (Y)) #endif diff --git a/src/nvim/main.c b/src/nvim/main.c index 5b5c8a22aa..71a972e8f6 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -238,8 +238,8 @@ int main(int argc, char **argv) check_and_set_isatty(¶ms); // Get the name with which Nvim was invoked, with and without path. - set_vim_var_string(VV_PROGPATH, (char_u *)argv[0], -1); - set_vim_var_string(VV_PROGNAME, path_tail((char_u *)argv[0]), -1); + set_vim_var_string(VV_PROGPATH, argv[0], -1); + set_vim_var_string(VV_PROGNAME, (char *) path_tail((char_u *) argv[0]), -1); event_init(); /* @@ -335,7 +335,7 @@ int main(int argc, char **argv) source_startup_scripts(¶ms); // If using the runtime (-u is not NONE), enable syntax & filetype plugins. - if (params.use_vimrc != NULL && strcmp(params.use_vimrc, "NONE") != 0) { + if (params.use_vimrc == NULL || strcmp(params.use_vimrc, "NONE") != 0) { // Does ":filetype plugin indent on". filetype_maybe_enable(); // Sources syntax/syntax.vim, which calls `:filetype on`. @@ -753,6 +753,7 @@ static void command_line_scan(mparm_T *parmp) putchar(b->data[i]); } + msgpack_packer_free(p); mch_exit(0); } else if (STRICMP(argv[0] + argv_idx, "headless") == 0) { parmp->headless = true; @@ -1140,10 +1141,11 @@ scripterror: /* If there is a "+123" or "-c" command, set v:swapcommand to the first * one. */ if (parmp->n_commands > 0) { - p = xmalloc(STRLEN(parmp->commands[0]) + 3); - sprintf((char *)p, ":%s\r", parmp->commands[0]); - set_vim_var_string(VV_SWAPCOMMAND, p, -1); - xfree(p); + const size_t swcmd_len = STRLEN(parmp->commands[0]) + 3; + char *const swcmd = xmalloc(swcmd_len); + snprintf(swcmd, swcmd_len, ":%s\r", parmp->commands[0]); + set_vim_var_string(VV_SWAPCOMMAND, swcmd, -1); + xfree(swcmd); } TIME_MSG("parsing arguments"); } diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index f0a249919f..3495203c43 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -1304,35 +1304,38 @@ int utfc_ptr2char(const char_u *p, int *pcc) */ int utfc_ptr2char_len(const char_u *p, int *pcc, int maxlen) { - int len; - int c; - int cc; +#define IS_COMPOSING(s1, s2, s3) \ + (i == 0 ? UTF_COMPOSINGLIKE((s1), (s2)) : utf_iscomposing((s3))) + + assert(maxlen > 0); + int i = 0; - c = utf_ptr2char(p); - len = utf_ptr2len_len(p, maxlen); - /* Only accept a composing char when the first char isn't illegal. */ - if ((len > 1 || *p < 0x80) - && len < maxlen - && p[len] >= 0x80 - && UTF_COMPOSINGLIKE(p, p + len)) { - cc = utf_ptr2char(p + len); - for (;; ) { - pcc[i++] = cc; - if (i == MAX_MCO) - break; - len += utf_ptr2len_len(p + len, maxlen - len); - if (len >= maxlen - || p[len] < 0x80 - || !utf_iscomposing(cc = utf_ptr2char(p + len))) + int len = utf_ptr2len_len(p, maxlen); + // Is it safe to use utf_ptr2char()? + bool safe = len > 1 && len <= maxlen; + int c = safe ? utf_ptr2char(p) : *p; + + // Only accept a composing char when the first char isn't illegal. + if ((safe || c < 0x80) && len < maxlen && p[len] >= 0x80) { + for (; i < MAX_MCO; i++) { + int len_cc = utf_ptr2len_len(p + len, maxlen - len); + safe = len_cc > 1 && len_cc <= maxlen - len; + if (!safe || (pcc[i] = utf_ptr2char(p + len)) < 0x80 + || !IS_COMPOSING(p, p + len, pcc[i])) { break; + } + len += len_cc; } } - if (i < MAX_MCO) /* last composing char must be 0 */ + if (i < MAX_MCO) { + // last composing char must be 0 pcc[i] = 0; + } return c; +#undef ISCOMPOSING } /* diff --git a/src/nvim/memfile.c b/src/nvim/memfile.c index 8cf5642a80..6599db787f 100644 --- a/src/nvim/memfile.c +++ b/src/nvim/memfile.c @@ -79,8 +79,6 @@ static size_t total_mem_used = 0; /// total memory used for memfiles /// - NULL, on failure. memfile_T *mf_open(char_u *fname, int flags) { - off_t size; - memfile_T *mfp = xmalloc(sizeof(memfile_T)); if (fname == NULL) { // no file, use memory only @@ -88,11 +86,9 @@ memfile_T *mf_open(char_u *fname, int flags) mfp->mf_ffname = NULL; mfp->mf_fd = -1; } else { // try to open the file - mf_do_open(mfp, fname, flags); - - if (mfp->mf_fd < 0) { // fail if file could not be opened + if (!mf_do_open(mfp, fname, flags)) { xfree(mfp); - return NULL; + return NULL; // fail if file could not be opened } } @@ -115,6 +111,8 @@ memfile_T *mf_open(char_u *fname, int flags) } } + off_t size; + // When recovering, the actual block size will be retrieved from block 0 // in ml_recover(). The size used here may be wrong, therefore mf_blocknr_max // must be rounded up. @@ -171,13 +169,12 @@ memfile_T *mf_open(char_u *fname, int flags) /// FAIL If file could not be opened. int mf_open_file(memfile_T *mfp, char_u *fname) { - mf_do_open(mfp, fname, O_RDWR|O_CREAT|O_EXCL); // try to open the file - - if (mfp->mf_fd < 0) - return FAIL; + if (mf_do_open(mfp, fname, O_RDWR | O_CREAT | O_EXCL)) { + mfp->mf_dirty = true; + return OK; + } - mfp->mf_dirty = true; - return OK; + return FAIL; } /// Close a memory file and optionally delete the associated file. @@ -185,28 +182,28 @@ int mf_open_file(memfile_T *mfp, char_u *fname) /// @param del_file Whether to delete associated file. void mf_close(memfile_T *mfp, bool del_file) { - bhdr_T *hp, *nextp; - if (mfp == NULL) { // safety check return; } if (mfp->mf_fd >= 0 && close(mfp->mf_fd) < 0) { EMSG(_(e_swapclose)); } - if (del_file && mfp->mf_fname != NULL) + if (del_file && mfp->mf_fname != NULL) { os_remove((char *)mfp->mf_fname); + } + // free entries in used list - for (hp = mfp->mf_used_first; hp != NULL; hp = nextp) { + for (bhdr_T *hp = mfp->mf_used_first, *nextp; hp != NULL; hp = nextp) { total_mem_used -= hp->bh_page_count * mfp->mf_page_size; nextp = hp->bh_next; mf_free_bhdr(hp); } - while (mfp->mf_free_first != NULL) // free entries in free list + while (mfp->mf_free_first != NULL) { // free entries in free list xfree(mf_rem_free(mfp)); + } mf_hash_free(&mfp->mf_hash); mf_hash_free_all(&mfp->mf_trans); // free hashtable and its items - xfree(mfp->mf_fname); - xfree(mfp->mf_ffname); + mf_free_fnames(mfp); xfree(mfp); } @@ -216,28 +213,28 @@ void mf_close(memfile_T *mfp, bool del_file) void mf_close_file(buf_T *buf, bool getlines) { memfile_T *mfp = buf->b_ml.ml_mfp; - if (mfp == NULL || mfp->mf_fd < 0) // nothing to close + if (mfp == NULL || mfp->mf_fd < 0) { // nothing to close return; + } if (getlines) { // get all blocks in memory by accessing all lines (clumsy!) mf_dont_release = true; - for (linenr_T lnum = 1; lnum <= buf->b_ml.ml_line_count; ++lnum) + for (linenr_T lnum = 1; lnum <= buf->b_ml.ml_line_count; ++lnum) { (void)ml_get_buf(buf, lnum, false); + } mf_dont_release = false; // TODO(elmart): should check if all blocks are really in core } - if (close(mfp->mf_fd) < 0) // close the file + if (close(mfp->mf_fd) < 0) { // close the file EMSG(_(e_swapclose)); + } mfp->mf_fd = -1; if (mfp->mf_fname != NULL) { os_remove((char *)mfp->mf_fname); // delete the swap file - xfree(mfp->mf_fname); - xfree(mfp->mf_ffname); - mfp->mf_fname = NULL; - mfp->mf_ffname = NULL; + mf_free_fnames(mfp); } } @@ -390,11 +387,11 @@ void mf_put(memfile_T *mfp, bhdr_T *hp, bool dirty, bool infile) /// Signal block as no longer used (may put it in the free list). void mf_free(memfile_T *mfp, bhdr_T *hp) { - xfree(hp->bh_data); // free data + xfree(hp->bh_data); // free data mf_rem_hash(mfp, hp); // get *hp out of the hash list mf_rem_used(mfp, hp); // get *hp out of the used list if (hp->bh_bnum < 0) { - xfree(hp); // don't want negative numbers in free list + xfree(hp); // don't want negative numbers in free list mfp->mf_neg_count--; } else { mf_ins_free(mfp, hp); // put *hp in the free list @@ -475,10 +472,11 @@ int mf_sync(memfile_T *mfp, int flags) /// These are blocks that need to be written to a newly created swapfile. void mf_set_dirty(memfile_T *mfp) { - bhdr_T *hp; - for (hp = mfp->mf_used_last; hp != NULL; hp = hp->bh_prev) - if (hp->bh_bnum > 0) + for (bhdr_T *hp = mfp->mf_used_last; hp != NULL; hp = hp->bh_prev) { + if (hp->bh_bnum > 0) { hp->bh_flags |= BH_DIRTY; + } + } mfp->mf_dirty = true; } @@ -506,10 +504,11 @@ static void mf_ins_used(memfile_T *mfp, bhdr_T *hp) hp->bh_next = mfp->mf_used_first; mfp->mf_used_first = hp; hp->bh_prev = NULL; - if (hp->bh_next == NULL) // list was empty, adjust last pointer + if (hp->bh_next == NULL) { // list was empty, adjust last pointer mfp->mf_used_last = hp; - else + } else { hp->bh_next->bh_prev = hp; + } mfp->mf_used_count += hp->bh_page_count; total_mem_used += hp->bh_page_count * mfp->mf_page_size; } @@ -615,9 +614,10 @@ bool mf_release_all(void) FOR_ALL_BUFFERS(buf) { memfile_T *mfp = buf->b_ml.ml_mfp; if (mfp != NULL) { - // If no swap file yet, may open one. - if (mfp->mf_fd < 0 && buf->b_may_swap) + // If no swap file yet, try to open one. + if (mfp->mf_fd < 0 && buf->b_may_swap) { ml_open_file(buf); + } // Flush as many blocks as possible, only if there is a swapfile. if (mfp->mf_fd >= 0) { @@ -752,7 +752,8 @@ static int mf_write(memfile_T *mfp, bhdr_T *hp) else page_count = hp2->bh_page_count; size = page_size * page_count; - if (mf_write_block(mfp, hp2 == NULL ? hp : hp2, offset, size) == FAIL) { + void *data = (hp2 == NULL) ? hp->bh_data : hp2->bh_data; + if ((unsigned)write_eintr(mfp->mf_fd, data, size) != size) { /// Avoid repeating the error message, this mostly happens when the /// disk is full. We give the message again only after a successful /// write or when hitting a key. We keep on trying, in case some @@ -773,20 +774,6 @@ static int mf_write(memfile_T *mfp, bhdr_T *hp) return OK; } -/// Write block to memfile's file. -/// -/// @return OK On success. -/// FAIL On failure. -static int mf_write_block(memfile_T *mfp, bhdr_T *hp, - off_t offset, unsigned size) -{ - void *data = hp->bh_data; - int result = OK; - if ((unsigned)write_eintr(mfp->mf_fd, data, size) != size) - result = FAIL; - return result; -} - /// Make block number positive and add it to the translation list. /// /// @return OK On success. @@ -856,13 +843,23 @@ blocknr_T mf_trans_del(memfile_T *mfp, blocknr_T old_nr) return new_bnum; } -/// Set full file name of memfile's swapfile, out of simple file name and some -/// other considerations. +/// Frees mf_fname and mf_ffname. +void mf_free_fnames(memfile_T *mfp) +{ + xfree(mfp->mf_fname); + xfree(mfp->mf_ffname); + mfp->mf_fname = NULL; + mfp->mf_ffname = NULL; +} + +/// Set the simple file name and the full file name of memfile's swapfile, out +/// of simple file name and some other considerations. /// /// Only called when creating or renaming the swapfile. Either way it's a new /// name so we must work out the full path name. -void mf_set_ffname(memfile_T *mfp) +void mf_set_fnames(memfile_T *mfp, char_u *fname) { + mfp->mf_fname = fname; mfp->mf_ffname = (char_u *)FullName_save((char *)mfp->mf_fname, false); } @@ -878,7 +875,7 @@ void mf_fullname(memfile_T *mfp) } } -/// Return TRUE if there are any translations pending for memfile. +/// Return true if there are any translations pending for memfile. bool mf_need_trans(memfile_T *mfp) { return mfp->mf_fname != NULL && mfp->mf_neg_count > 0; @@ -889,11 +886,11 @@ bool mf_need_trans(memfile_T *mfp) /// "fname" must be in allocated memory, and is consumed (also when error). /// /// @param flags Flags for open(). -static void mf_do_open(memfile_T *mfp, char_u *fname, int flags) +/// @return A bool indicating success of the `open` call. +static bool mf_do_open(memfile_T *mfp, char_u *fname, int flags) { // fname cannot be NameBuff, because it must have been allocated. - mfp->mf_fname = fname; - mf_set_ffname(mfp); + mf_set_fnames(mfp, fname); /// Extra security check: When creating a swap file it really shouldn't /// exist yet. If there is a symbolic link, this is most likely an attack. @@ -904,26 +901,26 @@ static void mf_do_open(memfile_T *mfp, char_u *fname, int flags) EMSG(_("E300: Swap file already exists (symlink attack?)")); } else { // try to open the file - flags |= O_NOFOLLOW; - mfp->mf_fd = mch_open_rw((char *)mfp->mf_fname, flags); + mfp->mf_fd = mch_open_rw((char *)mfp->mf_fname, flags | O_NOFOLLOW); } // If the file cannot be opened, use memory only if (mfp->mf_fd < 0) { - xfree(mfp->mf_fname); - xfree(mfp->mf_ffname); - mfp->mf_fname = NULL; - mfp->mf_ffname = NULL; - } else { + mf_free_fnames(mfp); + return false; + } + #ifdef HAVE_FD_CLOEXEC - int fdflags = fcntl(mfp->mf_fd, F_GETFD); - if (fdflags >= 0 && (fdflags & FD_CLOEXEC) == 0) - fcntl(mfp->mf_fd, F_SETFD, fdflags | FD_CLOEXEC); + int fdflags = fcntl(mfp->mf_fd, F_GETFD); + if (fdflags >= 0 && (fdflags & FD_CLOEXEC) == 0) { + fcntl(mfp->mf_fd, F_SETFD, fdflags | FD_CLOEXEC); + } #endif #ifdef HAVE_SELINUX - mch_copy_sec(fname, mfp->mf_fname); + mch_copy_sec(fname, mfp->mf_fname); #endif - } + + return true; } // @@ -948,20 +945,21 @@ static void mf_hash_init(mf_hashtab_T *mht) /// The hash table must not be used again without another mf_hash_init() call. static void mf_hash_free(mf_hashtab_T *mht) { - if (mht->mht_buckets != mht->mht_small_buckets) + if (mht->mht_buckets != mht->mht_small_buckets) { xfree(mht->mht_buckets); + } } /// Free the array of a hash table and all the items it contains. static void mf_hash_free_all(mf_hashtab_T *mht) { - mf_hashitem_T *next; - - for (size_t idx = 0; idx <= mht->mht_mask; idx++) + for (size_t idx = 0; idx <= mht->mht_mask; idx++) { + mf_hashitem_T *next; for (mf_hashitem_T *mhi = mht->mht_buckets[idx]; mhi != NULL; mhi = next) { next = mhi->mhi_next; xfree(mhi); } + } mf_hash_free(mht); } diff --git a/src/nvim/memline.c b/src/nvim/memline.c index f58b2ac38f..f82f88a88f 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -65,7 +65,6 @@ #include "nvim/strings.h" #include "nvim/ui.h" #include "nvim/version.h" -#include "nvim/tempfile.h" #include "nvim/undo.h" #include "nvim/window.h" #include "nvim/os/os.h" @@ -426,10 +425,8 @@ void ml_setname(buf_T *buf) /* try to rename the swap file */ if (vim_rename(mfp->mf_fname, fname) == 0) { success = TRUE; - xfree(mfp->mf_fname); - mfp->mf_fname = fname; - xfree(mfp->mf_ffname); - mf_set_ffname(mfp); + mf_free_fnames(mfp); + mf_set_fnames(mfp, fname); ml_upd_block0(buf, UB_SAME_DIR); break; } @@ -3196,7 +3193,7 @@ attention_message ( */ static int do_swapexists(buf_T *buf, char_u *fname) { - set_vim_var_string(VV_SWAPNAME, fname, -1); + set_vim_var_string(VV_SWAPNAME, (char *) fname, -1); set_vim_var_string(VV_SWAPCHOICE, NULL, -1); /* Trigger SwapExists autocommands with <afile> set to the file being diff --git a/src/nvim/message.c b/src/nvim/message.c index 1dd71baaa4..97b098c6d2 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -61,14 +61,8 @@ static int confirm_msg_used = FALSE; /* displaying confirm_msg */ static char_u *confirm_msg = NULL; /* ":confirm" message */ static char_u *confirm_msg_tail; /* tail of confirm_msg */ -struct msg_hist { - struct msg_hist *next; - char_u *msg; - int attr; -}; - -static struct msg_hist *first_msg_hist = NULL; -static struct msg_hist *last_msg_hist = NULL; +MessageHistoryEntry *first_msg_hist = NULL; +MessageHistoryEntry *last_msg_hist = NULL; static int msg_hist_len = 0; static FILE *verbose_fd = NULL; @@ -149,10 +143,11 @@ msg_attr_keep ( { static int entered = 0; int retval; - char_u *buf = NULL; + char_u *buf = NULL; - if (attr == 0) - set_vim_var_string(VV_STATUSMSG, s, -1); + if (attr == 0) { + set_vim_var_string(VV_STATUSMSG, (char *) s, -1); + } /* * It is possible that displaying a messages causes a problem (e.g., @@ -503,8 +498,8 @@ int emsg(char_u *s) return TRUE; } - /* set "v:errmsg", also when using ":silent! cmd" */ - set_vim_var_string(VV_ERRMSG, s, -1); + // set "v:errmsg", also when using ":silent! cmd" + set_vim_var_string(VV_ERRMSG, (char *) s, -1); /* * When using ":silent! cmd" ignore error messages. @@ -563,49 +558,23 @@ int emsg(char_u *s) return msg_attr(s, attr); } -/* - * Print an error message with one "%s" and one string argument. - */ -int emsg2(char_u *s, char_u *a1) -{ - return emsg3(s, a1, NULL); -} - void emsg_invreg(int name) { EMSG2(_("E354: Invalid register name: '%s'"), transchar(name)); } -/// Print an error message with one or two "%s" and one or two string arguments. -int emsg3(char_u *s, char_u *a1, char_u *a2) -{ - if (emsg_not_now()) { - return TRUE; // no error messages at the moment - } - - vim_snprintf((char *)IObuff, IOSIZE, (char *)s, a1, a2); - return emsg(IObuff); -} - -/// Print an error message with one "%" PRId64 and one (int64_t) argument. -int emsgn(char_u *s, int64_t n) +/// Print an error message with unknown number of arguments +bool emsgf(const char *const fmt, ...) { if (emsg_not_now()) { - return TRUE; // no error messages at the moment + return true; } - vim_snprintf((char *)IObuff, IOSIZE, (char *)s, n); - return emsg(IObuff); -} - -/// Print an error message with one "%" PRIu64 and one (uint64_t) argument. -int emsgu(char_u *s, uint64_t n) -{ - if (emsg_not_now()) { - return TRUE; // no error messages at the moment - } + va_list ap; + va_start(ap, fmt); + vim_vsnprintf((char *) IObuff, IOSIZE, fmt, ap, NULL); + va_end(ap); - vim_snprintf((char *)IObuff, IOSIZE, (char *)s, n); return emsg(IObuff); } @@ -1787,25 +1756,24 @@ static void msg_scroll_up(void) static void inc_msg_scrolled(void) { if (*get_vim_var_str(VV_SCROLLSTART) == NUL) { - char_u *p = sourcing_name; - char_u *tofree = NULL; - int len; - - /* v:scrollstart is empty, set it to the script/function name and line - * number */ - if (p == NULL) - p = (char_u *)_("Unknown"); - else { - len = (int)STRLEN(p) + 40; + char *p = (char *) sourcing_name; + char *tofree = NULL; + + // v:scrollstart is empty, set it to the script/function name and line + // number + if (p == NULL) { + p = _("Unknown"); + } else { + size_t len = strlen(p) + 40; tofree = xmalloc(len); - vim_snprintf((char *)tofree, len, _("%s line %" PRId64), - p, (int64_t)sourcing_lnum); + vim_snprintf(tofree, len, _("%s line %" PRId64), + p, (int64_t) sourcing_lnum); p = tofree; } set_vim_var_string(VV_SCROLLSTART, p, -1); xfree(tofree); } - ++msg_scrolled; + msg_scrolled++; } static msgchunk_T *last_msgchunk = NULL; /* last displayed text */ @@ -2572,7 +2540,7 @@ void give_warning(char_u *message, bool hl) FUNC_ATTR_NONNULL_ARG(1) /* Don't want a hit-enter prompt here. */ ++no_wait_return; - set_vim_var_string(VV_WARNINGMSG, message, -1); + set_vim_var_string(VV_WARNINGMSG, (char *) message, -1); xfree(keep_msg); keep_msg = NULL; if (hl) @@ -3086,7 +3054,7 @@ int vim_snprintf_add(char *str, size_t str_m, char *fmt, ...) return str_l; } -int vim_snprintf(char *str, size_t str_m, char *fmt, ...) +int vim_snprintf(char *str, size_t str_m, const char *fmt, ...) { va_list ap; int str_l; @@ -3097,11 +3065,12 @@ int vim_snprintf(char *str, size_t str_m, char *fmt, ...) return str_l; } -int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs) +int vim_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap, + typval_T *tvs) { size_t str_l = 0; bool str_avail = str_l < str_m; - char *p = fmt; + const char *p = fmt; int arg_idx = 1; if (!p) { @@ -3135,7 +3104,7 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs) char tmp[TMP_LEN]; // string address in case of string argument - char *str_arg; + const char *str_arg; // natural field width of arg without padding and sign size_t str_arg_l; diff --git a/src/nvim/message.h b/src/nvim/message.h index 019c7bfb73..d3a16fff93 100644 --- a/src/nvim/message.h +++ b/src/nvim/message.h @@ -4,6 +4,7 @@ #include <stdbool.h> #include <stdarg.h> #include "nvim/eval_defs.h" // for typval_T +#include "nvim/ex_cmds_defs.h" // for exarg_T /* * Types of dialogs passed to do_dialog(). @@ -24,6 +25,56 @@ #define VIM_ALL 5 #define VIM_DISCARDALL 6 +/// Show plain message +#define MSG(s) msg((char_u *)(s)) + +/// Show message highlighted according to the attr +#define MSG_ATTR(s, attr) msg_attr((char_u *)(s), (attr)) + +/// Display error message +/// +/// Sets error flag in process, can be transformed into an exception. +#define EMSG(s) emsg((char_u *)(s)) + +/// Like #EMSG, but for messages with one "%s" inside +#define EMSG2(s, p) emsgf((const char *) (s), (p)) + +/// Like #EMSG, but for messages with two "%s" inside +#define EMSG3(s, p, q) emsgf((const char *) (s), (p), (q)) + +/// Like #EMSG, but for messages with one "%" PRId64 inside +#define EMSGN(s, n) emsgf((const char *) (s), (int64_t)(n)) + +/// Like #EMSG, but for messages with one "%" PRIu64 inside +#define EMSGU(s, n) emsgf((const char *) (s), (uint64_t)(n)) + +/// Display message at the recorded position +#define MSG_PUTS(s) msg_puts((char_u *)(s)) + +/// Display message at the recorded position, highlighted +#define MSG_PUTS_ATTR(s, a) msg_puts_attr((char_u *)(s), (a)) + +/// Like #MSG_PUTS, but highlight like title +#define MSG_PUTS_TITLE(s) msg_puts_title((char_u *)(s)) + +/// Like #MSG_PUTS, but if middle part of too long messages it will be replaced +#define MSG_PUTS_LONG(s) msg_puts_long_attr((char_u *)(s), 0) + +/// Like #MSG_PUTS_ATTR, but if middle part of long messages will be replaced +#define MSG_PUTS_LONG_ATTR(s, a) msg_puts_long_attr((char_u *)(s), (a)) + +/// Message history for `:messages` +typedef struct msg_hist { + struct msg_hist *next; ///< Next message. + char_u *msg; ///< Message text. + int attr; ///< Message highlighting. +} MessageHistoryEntry; + +/// First message +extern MessageHistoryEntry *first_msg_hist; +/// Last message +extern MessageHistoryEntry *last_msg_hist; + #ifdef INCLUDE_GENERATED_DECLARATIONS # include "message.h.generated.h" #endif diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index db303fd54a..43e0dd0c1a 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -43,7 +43,6 @@ #include "nvim/search.h" #include "nvim/strings.h" #include "nvim/tag.h" -#include "nvim/tempfile.h" #include "nvim/ui.h" #include "nvim/undo.h" #include "nvim/window.h" @@ -86,38 +85,32 @@ open_line ( int second_line_indent ) { - char_u *saved_line; /* copy of the original line */ - char_u *next_line = NULL; /* copy of the next line */ - char_u *p_extra = NULL; /* what goes to next line */ - int less_cols = 0; /* less columns for mark in new line */ - int less_cols_off = 0; /* columns to skip for mark adjust */ - pos_T old_cursor; /* old cursor position */ - int newcol = 0; /* new cursor column */ - int newindent = 0; /* auto-indent of the new line */ - int n; - int trunc_line = FALSE; /* truncate current line afterwards */ - int retval = FALSE; /* return value, default is FAIL */ - int extra_len = 0; /* length of p_extra string */ - int lead_len; /* length of comment leader */ - char_u *lead_flags; /* position in 'comments' for comment leader */ - char_u *leader = NULL; /* copy of comment leader */ - char_u *allocated = NULL; /* allocated memory */ - char_u *p; - int saved_char = NUL; /* init for GCC */ - pos_T *pos; - int do_si = (!p_paste && curbuf->b_p_si - && !curbuf->b_p_cin - ); - int no_si = FALSE; /* reset did_si afterwards */ - int first_char = NUL; /* init for GCC */ + char_u *next_line = NULL; // copy of the next line + char_u *p_extra = NULL; // what goes to next line + colnr_T less_cols = 0; // less columns for mark in new line + colnr_T less_cols_off = 0; // columns to skip for mark adjust + pos_T old_cursor; // old cursor position + colnr_T newcol = 0; // new cursor column + int newindent = 0; // auto-indent of the new line + bool trunc_line = false; // truncate current line afterwards + bool retval = false; // return value, default is false + int extra_len = 0; // length of p_extra string + int lead_len; // length of comment leader + char_u *lead_flags; // position in 'comments' for comment leader + char_u *leader = NULL; // copy of comment leader + char_u *allocated = NULL; // allocated memory + char_u *p; + char_u saved_char = NUL; // init for GCC + pos_T *pos; + bool do_si = (!p_paste && curbuf->b_p_si && !curbuf->b_p_cin); + bool no_si = false; // reset did_si afterwards + int first_char = NUL; // init for GCC int vreplace_mode; - int did_append; /* appended a new line */ - int saved_pi = curbuf->b_p_pi; /* copy of preserveindent setting */ + bool did_append; // appended a new line + int saved_pi = curbuf->b_p_pi; // copy of preserveindent setting - /* - * make a copy of the current line so we can mess with it - */ - saved_line = vim_strsave(get_cursor_line_ptr()); + // make a copy of the current line so we can mess with it + char_u *saved_line = vim_strsave(get_cursor_line_ptr()); if (State & VREPLACE_FLAG) { /* @@ -204,7 +197,7 @@ open_line ( char_u *ptr; char_u last_char; - old_cursor = curwin->w_cursor; + pos_T old_cursor = curwin->w_cursor; ptr = saved_line; if (flags & OPENLINE_DO_COM) lead_len = get_leader_len(ptr, NULL, FALSE, TRUE); @@ -401,7 +394,7 @@ open_line ( end_comment_pending = -1; /* means we want to set it */ ++p; } - n = copy_option_part(&p, lead_end, COM_MAX_LEN, ","); + size_t n = copy_option_part(&p, lead_end, COM_MAX_LEN, ","); if (end_comment_pending == -1) /* we can set it now */ end_comment_pending = lead_end[n - 1]; @@ -498,10 +491,11 @@ open_line ( } } if (lead_len > 0) { - /* allocate buffer (may concatenate p_extra later) */ - leader = xmalloc(lead_len + lead_repl_len + extra_space + extra_len - + (second_line_indent > 0 ? second_line_indent : 0) + 1); - allocated = leader; /* remember to free it later */ + // allocate buffer (may concatenate p_extra later) + leader = xmalloc((size_t)(lead_len + lead_repl_len + extra_space + + extra_len + (second_line_indent > 0 + ? second_line_indent : 0) + 1)); + allocated = leader; // remember to free it later STRLCPY(leader, saved_line, lead_len + 1); @@ -598,9 +592,8 @@ open_line ( if (!ascii_iswhite(*p)) { /* Don't put a space before a TAB. */ if (p + 1 < leader + lead_len && p[1] == TAB) { - --lead_len; - memmove(p, p + 1, - (leader + lead_len) - p); + lead_len--; + memmove(p, p + 1, (size_t)(leader + lead_len - p)); } else { int l = (*mb_ptr2len)(p); @@ -611,8 +604,7 @@ open_line ( --l; *p++ = ' '; } - memmove(p + 1, p + l, - (leader + lead_len) - p); + memmove(p + 1, p + l, (size_t)(leader + lead_len - p)); lead_len -= l - 1; } *p = ' '; @@ -813,9 +805,11 @@ open_line ( * In REPLACE mode, for each character in the new indent, there must * be a NUL on the replace stack, for when it is deleted with BS */ - if (REPLACE_NORMAL(State)) - for (n = 0; n < (int)curwin->w_cursor.col; ++n) + if (REPLACE_NORMAL(State)) { + for (colnr_T n = 0; n < curwin->w_cursor.col; n++) { replace_push(NUL); + } + } newcol += curwin->w_cursor.col; if (no_si) did_si = FALSE; @@ -1281,11 +1275,13 @@ int plines_win_nofold(win_T *wp, linenr_T lnum) * Add column offset for 'number', 'relativenumber' and 'foldcolumn'. */ width = wp->w_width - win_col_off(wp); - if (width <= 0) - return 32000; - if (col <= (unsigned int)width) + if (width <= 0) { + return 32000; // bigger than the number of lines of the screen + } + if (col <= (unsigned int)width) { return 1; - col -= width; + } + col -= (unsigned int)width; width += win_col_off2(wp); assert(col <= INT_MAX && (int)col < INT_MAX - (width -1)); return ((int)col + (width - 1)) / width + 1; @@ -1297,15 +1293,9 @@ int plines_win_nofold(win_T *wp, linenr_T lnum) */ int plines_win_col(win_T *wp, linenr_T lnum, long column) { - long col; - char_u *s; - int lines = 0; - int width; - char_u *line; - - /* Check for filler lines above this buffer line. When folded the result - * is one line anyway. */ - lines = diff_check_fill(wp, lnum); + // Check for filler lines above this buffer line. When folded the result + // is one line anyway. + int lines = diff_check_fill(wp, lnum); if (!wp->w_p_wrap) return lines + 1; @@ -1313,30 +1303,29 @@ int plines_win_col(win_T *wp, linenr_T lnum, long column) if (wp->w_width == 0) return lines + 1; - line = s = ml_get_buf(wp->w_buffer, lnum, FALSE); + char_u *line = ml_get_buf(wp->w_buffer, lnum, false); + char_u *s = line; - col = 0; + colnr_T col = 0; while (*s != NUL && --column >= 0) { - col += win_lbr_chartabsize(wp, line, s, (colnr_T)col, NULL); + col += win_lbr_chartabsize(wp, line, s, col, NULL); mb_ptr_adv(s); } - /* - * If *s is a TAB, and the TAB is not displayed as ^I, and we're not in - * INSERT mode, then col must be adjusted so that it represents the last - * screen position of the TAB. This only fixes an error when the TAB wraps - * from one screen line to the next (when 'columns' is not a multiple of - * 'ts') -- webb. - */ - if (*s == TAB && (State & NORMAL) && (!wp->w_p_list || lcs_tab1)) - col += win_lbr_chartabsize(wp, line, s, (colnr_T)col, NULL) - 1; + // If *s is a TAB, and the TAB is not displayed as ^I, and we're not in + // INSERT mode, then col must be adjusted so that it represents the last + // screen position of the TAB. This only fixes an error when the TAB wraps + // from one screen line to the next (when 'columns' is not a multiple of + // 'ts') -- webb. + if (*s == TAB && (State & NORMAL) && (!wp->w_p_list || lcs_tab1)) { + col += win_lbr_chartabsize(wp, line, s, col, NULL) - 1; + } - /* - * Add column offset for 'number', 'relativenumber', 'foldcolumn', etc. - */ - width = wp->w_width - win_col_off(wp); - if (width <= 0) + // Add column offset for 'number', 'relativenumber', 'foldcolumn', etc. + int width = wp->w_width - win_col_off(wp); + if (width <= 0) { return 9999; + } lines += 1; if (col > width) @@ -1349,11 +1338,9 @@ int plines_m_win(win_T *wp, linenr_T first, linenr_T last) int count = 0; while (first <= last) { - int x; - - /* Check if there are any really folded lines, but also included lines - * that are maybe folded. */ - x = foldedCount(wp, first, NULL); + // Check if there are any really folded lines, but also included lines + // that are maybe folded. + linenr_T x = foldedCount(wp, first, NULL); if (x > 0) { ++count; /* count 1 for "+-- folded" line */ first += x; @@ -1374,117 +1361,99 @@ int plines_m_win(win_T *wp, linenr_T first, linenr_T last) */ void ins_bytes(char_u *p) { - ins_bytes_len(p, (int)STRLEN(p)); + ins_bytes_len(p, STRLEN(p)); } -/* - * Insert string "p" with length "len" at the cursor position. - * Handles Replace mode and multi-byte characters. - */ -void ins_bytes_len(char_u *p, int len) +/// Insert string "p" with length "len" at the cursor position. +/// Handles Replace mode and multi-byte characters. +void ins_bytes_len(char_u *p, size_t len) { - int i; - int n; - - if (has_mbyte) - for (i = 0; i < len; i += n) { - if (enc_utf8) - /* avoid reading past p[len] */ - n = utfc_ptr2len_len(p + i, len - i); - else - n = (*mb_ptr2len)(p + i); + if (has_mbyte) { + size_t n; + for (size_t i = 0; i < len; i += n) { + if (enc_utf8) { + // avoid reading past p[len] + n = (size_t)utfc_ptr2len_len(p + i, (int)(len - i)); + } else { + n = (size_t)(*mb_ptr2len)(p + i); + } ins_char_bytes(p + i, n); } - else - for (i = 0; i < len; ++i) + } else { + for (size_t i = 0; i < len; i++) { ins_char(p[i]); + } + } } -/* - * Insert or replace a single character at the cursor position. - * When in REPLACE or VREPLACE mode, replace any existing character. - * Caller must have prepared for undo. - * For multi-byte characters we get the whole character, the caller must - * convert bytes to a character. - */ +/// Insert or replace a single character at the cursor position. +/// When in REPLACE or VREPLACE mode, replace any existing character. +/// Caller must have prepared for undo. +/// For multi-byte characters we get the whole character, the caller must +/// convert bytes to a character. void ins_char(int c) { char_u buf[MB_MAXBYTES + 1]; - int n; + size_t n = (size_t)(*mb_char2bytes)(c, buf); - n = (*mb_char2bytes)(c, buf); - - /* When "c" is 0x100, 0x200, etc. we don't want to insert a NUL byte. - * Happens for CTRL-Vu9900. */ - if (buf[0] == 0) + // When "c" is 0x100, 0x200, etc. we don't want to insert a NUL byte. + // Happens for CTRL-Vu9900. + if (buf[0] == 0) { buf[0] = '\n'; - + } ins_char_bytes(buf, n); } -void ins_char_bytes(char_u *buf, int charlen) +void ins_char_bytes(char_u *buf, size_t charlen) { - int c = buf[0]; - int newlen; /* nr of bytes inserted */ - int oldlen; /* nr of bytes deleted (0 when not replacing) */ - char_u *p; - char_u *newp; - char_u *oldp; - int linelen; /* length of old line including NUL */ - colnr_T col; - linenr_T lnum = curwin->w_cursor.lnum; - int i; - - /* Break tabs if needed. */ - if (virtual_active() && curwin->w_cursor.coladd > 0) + // Break tabs if needed. + if (virtual_active() && curwin->w_cursor.coladd > 0) { coladvance_force(getviscol()); + } - col = curwin->w_cursor.col; - oldp = ml_get(lnum); - linelen = (int)STRLEN(oldp) + 1; + int c = buf[0]; + size_t col = (size_t)curwin->w_cursor.col; + linenr_T lnum = curwin->w_cursor.lnum; + char_u *oldp = ml_get(lnum); + size_t linelen = STRLEN(oldp) + 1; // length of old line including NUL - /* The lengths default to the values for when not replacing. */ - oldlen = 0; - newlen = charlen; + // The lengths default to the values for when not replacing. + size_t oldlen = 0; // nr of bytes inserted + size_t newlen = charlen; // nr of bytes deleted (0 when not replacing) if (State & REPLACE_FLAG) { if (State & VREPLACE_FLAG) { - colnr_T new_vcol = 0; /* init for GCC */ + // Disable 'list' temporarily, unless 'cpo' contains the 'L' flag. + // Returns the old value of list, so when finished, + // curwin->w_p_list should be set back to this. + int old_list = curwin->w_p_list; + if (old_list && vim_strchr(p_cpo, CPO_LISTWM) == NULL) { + curwin->w_p_list = false; + } + // In virtual replace mode each character may replace one or more + // characters (zero if it's a TAB). Count the number of bytes to + // be deleted to make room for the new character, counting screen + // cells. May result in adding spaces to fill a gap. colnr_T vcol; - int old_list; - - /* - * Disable 'list' temporarily, unless 'cpo' contains the 'L' flag. - * Returns the old value of list, so when finished, - * curwin->w_p_list should be set back to this. - */ - old_list = curwin->w_p_list; - if (old_list && vim_strchr(p_cpo, CPO_LISTWM) == NULL) - curwin->w_p_list = FALSE; - - /* - * In virtual replace mode each character may replace one or more - * characters (zero if it's a TAB). Count the number of bytes to - * be deleted to make room for the new character, counting screen - * cells. May result in adding spaces to fill a gap. - */ getvcol(curwin, &curwin->w_cursor, NULL, &vcol, NULL); - new_vcol = vcol + chartabsize(buf, vcol); + colnr_T new_vcol = vcol + chartabsize(buf, vcol); while (oldp[col + oldlen] != NUL && vcol < new_vcol) { vcol += chartabsize(oldp + col + oldlen, vcol); - /* Don't need to remove a TAB that takes us to the right - * position. */ - if (vcol > new_vcol && oldp[col + oldlen] == TAB) + // Don't need to remove a TAB that takes us to the right + // position. + if (vcol > new_vcol && oldp[col + oldlen] == TAB) { break; - oldlen += (*mb_ptr2len)(oldp + col + oldlen); - /* Deleted a bit too much, insert spaces. */ - if (vcol > new_vcol) - newlen += vcol - new_vcol; + } + oldlen += (size_t)(*mb_ptr2len)(oldp + col + oldlen); + // Deleted a bit too much, insert spaces. + if (vcol > new_vcol) { + newlen += (size_t)(vcol - new_vcol); + } } curwin->w_p_list = old_list; } else if (oldp[col] != NUL) { - /* normal replace */ - oldlen = (*mb_ptr2len)(oldp + col); + // normal replace + oldlen = (size_t)(*mb_ptr2len)(oldp + col); } @@ -1493,38 +1462,39 @@ void ins_char_bytes(char_u *buf, int charlen) * done the other way around, so that the first byte is popped off * first (it tells the byte length of the character). */ replace_push(NUL); - for (i = 0; i < oldlen; ++i) { - if (has_mbyte) - i += replace_push_mb(oldp + col + i) - 1; - else + for (size_t i = 0; i < oldlen; i++) { + if (has_mbyte) { + i += (size_t)replace_push_mb(oldp + col + i) - 1; + } else { replace_push(oldp[col + i]); + } } } - newp = (char_u *) xmalloc((size_t)(linelen + newlen - oldlen)); + char_u *newp = (char_u *) xmalloc((size_t)(linelen + newlen - oldlen)); - /* Copy bytes before the cursor. */ - if (col > 0) + // Copy bytes before the cursor. + if (col > 0) { memmove(newp, oldp, (size_t)col); + } - /* Copy bytes after the changed character(s). */ - p = newp + col; - memmove(p + newlen, oldp + col + oldlen, - (size_t)(linelen - col - oldlen)); + // Copy bytes after the changed character(s). + char_u *p = newp + col; + memmove(p + newlen, oldp + col + oldlen, (size_t)(linelen - col - oldlen)); - /* Insert or overwrite the new character. */ + // Insert or overwrite the new character. memmove(p, buf, charlen); - i = charlen; - /* Fill with spaces when necessary. */ - while (i < newlen) - p[i++] = ' '; + // Fill with spaces when necessary. + for (size_t i = charlen; i < newlen; i++) { + p[i] = ' '; + } /* Replace the line in the buffer. */ ml_replace(lnum, newp, FALSE); - /* mark the buffer as changed and prepare for displaying */ - changed_bytes(lnum, col); + // mark the buffer as changed and prepare for displaying + changed_bytes(lnum, (colnr_T)col); /* * If we're in Insert or Replace mode and 'showmatch' is set, then briefly @@ -1541,8 +1511,8 @@ void ins_char_bytes(char_u *buf, int charlen) } if (!p_ri || (State & REPLACE_FLAG)) { - /* Normal insert: move cursor right */ - curwin->w_cursor.col += charlen; + // Normal insert: move cursor right + curwin->w_cursor.col += (int)charlen; } /* * TODO: should try to update w_row here, to avoid recomputing it later. @@ -1595,7 +1565,7 @@ int del_char(int fixpos) return FAIL; return del_chars(1L, fixpos); } - return del_bytes(1L, fixpos, TRUE); + return del_bytes(1, fixpos, true); } /* @@ -1603,7 +1573,7 @@ int del_char(int fixpos) */ int del_chars(long count, int fixpos) { - long bytes = 0; + int bytes = 0; long i; char_u *p; int l; @@ -1617,30 +1587,22 @@ int del_chars(long count, int fixpos) return del_bytes(bytes, fixpos, TRUE); } -/* - * Delete "count" bytes under the cursor. - * If "fixpos" is TRUE, don't leave the cursor on the NUL after the line. - * Caller must have prepared for undo. - * - * return FAIL for failure, OK otherwise - */ -int -del_bytes ( - long count, - int fixpos_arg, - int use_delcombine /* 'delcombine' option applies */ -) +/// Delete "count" bytes under the cursor. +/// If "fixpos" is true, don't leave the cursor on the NUL after the line. +/// Caller must have prepared for undo. +/// +/// @param count number of bytes to be deleted +/// @param fixpos_arg leave the cursor on the NUL after the line +/// @param use_delcombine 'delcombine' option applies +/// +/// @return FAIL for failure, OK otherwise +int del_bytes(colnr_T count, bool fixpos_arg, bool use_delcombine) { - char_u *oldp, *newp; - colnr_T oldlen; linenr_T lnum = curwin->w_cursor.lnum; colnr_T col = curwin->w_cursor.col; - int was_alloced; - long movelen; - int fixpos = fixpos_arg; - - oldp = ml_get(lnum); - oldlen = (int)STRLEN(oldp); + bool fixpos = fixpos_arg; + char_u *oldp = ml_get(lnum); + colnr_T oldlen = (colnr_T)STRLEN(oldp); /* * Can't do anything when the cursor is on the NUL after the line. @@ -1664,14 +1626,12 @@ del_bytes ( count = utf_ptr2len(oldp + n); n += count; } while (UTF_COMPOSINGLIKE(oldp + col, oldp + n)); - fixpos = 0; + fixpos = false; } } - /* - * When count is too big, reduce it. - */ - movelen = (long)oldlen - (long)col - count + 1; /* includes trailing NUL */ + // When count is too big, reduce it. + int movelen = oldlen - col - count + 1; // includes trailing NUL if (movelen <= 1) { /* * If we just took off the last character of a non-blank line, and @@ -1691,15 +1651,14 @@ del_bytes ( movelen = 1; } - /* - * If the old line has been allocated the deletion can be done in the - * existing line. Otherwise a new line has to be allocated. - */ - was_alloced = ml_line_alloced(); /* check if oldp was allocated */ - if (was_alloced) - newp = oldp; /* use same allocated memory */ - else { /* need to allocate a new line */ - newp = xmalloc(oldlen + 1 - count); + // If the old line has been allocated the deletion can be done in the + // existing line. Otherwise a new line has to be allocated. + bool was_alloced = ml_line_alloced(); // check if oldp was allocated + char_u *newp; + if (was_alloced) { + newp = oldp; // use same allocated memory + } else { // need to allocate a new line + newp = xmalloc((size_t)(oldlen + 1 - count)); memmove(newp, oldp, (size_t)col); } memmove(newp + col, oldp + col + count, (size_t)movelen); @@ -1725,12 +1684,12 @@ truncate_line ( linenr_T lnum = curwin->w_cursor.lnum; colnr_T col = curwin->w_cursor.col; - if (col == 0) + if (col == 0) { newp = vim_strsave((char_u *)""); - else - newp = vim_strnsave(ml_get(lnum), col); - - ml_replace(lnum, newp, FALSE); + } else { + newp = vim_strnsave(ml_get(lnum), (size_t)col); + } + ml_replace(lnum, newp, false); /* mark the buffer as changed and prepare for displaying */ changed_bytes(lnum, curwin->w_cursor.col); @@ -2250,7 +2209,7 @@ change_warning ( msg_col = col; msg_source(hl_attr(HLF_W)); MSG_PUTS_ATTR(_(w_readonly), hl_attr(HLF_W) | MSG_HIST); - set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_readonly), -1); + set_vim_var_string(VV_WARNINGMSG, _(w_readonly), -1); msg_clr_eos(); (void)msg_end(); if (msg_silent == 0 && !silent_mode) { @@ -2360,13 +2319,13 @@ int get_keystroke(void) * 5 chars plus NUL). And fix_input_buffer() can triple the number of * bytes. */ maxlen = (buflen - 6 - len) / 3; - if (buf == NULL) - buf = xmalloc(buflen); - else if (maxlen < 10) { - /* Need some more space. This might happen when receiving a long - * escape sequence. */ + if (buf == NULL) { + buf = xmalloc((size_t)buflen); + } else if (maxlen < 10) { + // Need some more space. This might happen when receiving a long + // escape sequence. buflen += 100; - buf = xrealloc(buf, buflen); + buf = xrealloc(buf, (size_t)buflen); maxlen = (buflen - 6 - len) / 3; } @@ -2729,38 +2688,33 @@ void fast_breakcheck(void) } } -/* - * Get the stdout of an external command. - * If "ret_len" is NULL replace NUL characters with NL. When "ret_len" is not - * NULL store the length there. - * Returns an allocated string, or NULL for error. - */ -char_u * -get_cmd_output ( - char_u *cmd, - char_u *infile, /* optional input file name */ - int flags, // can be kShellOptSilent - size_t *ret_len -) +/// Get the stdout of an external command. +/// If "ret_len" is NULL replace NUL characters with NL. When "ret_len" is not +/// NULL store the length there. +/// +/// @param cmd command to execute +/// @param infile optional input file name +/// @param flags can be kShellOptSilent or 0 +/// @param ret_len length of the stdout +/// +/// @return an allocated string, or NULL for error. +char_u *get_cmd_output(char_u *cmd, char_u *infile, ShellOpts flags, + size_t *ret_len) { - char_u *tempname; - char_u *command; - char_u *buffer = NULL; - int len; - int i = 0; - FILE *fd; + char_u *buffer = NULL; if (check_restricted() || check_secure()) return NULL; - /* get a name for the temp file */ - if ((tempname = vim_tempname()) == NULL) { + // get a name for the temp file + char_u *tempname = vim_tempname(); + if (tempname == NULL) { EMSG(_(e_notmp)); return NULL; } - /* Add the redirection stuff */ - command = make_filter_cmd(cmd, infile, tempname); + // Add the redirection stuff + char_u *command = make_filter_cmd(cmd, infile, tempname); /* * Call the shell to execute the command (errors are ignored). @@ -2772,10 +2726,8 @@ get_cmd_output ( xfree(command); - /* - * read the names from the file into memory - */ - fd = mch_fopen((char *)tempname, READBIN); + // read the names from the file into memory + FILE *fd = mch_fopen((char *)tempname, READBIN); if (fd == NULL) { EMSG2(_(e_notopen), tempname); @@ -2783,11 +2735,11 @@ get_cmd_output ( } fseek(fd, 0L, SEEK_END); - len = ftell(fd); /* get size of temp file */ + size_t len = (size_t)ftell(fd); // get size of temp file fseek(fd, 0L, SEEK_SET); buffer = xmalloc(len + 1); - i = (int)fread((char *)buffer, (size_t)1, (size_t)len, fd); + size_t i = fread((char *)buffer, 1, len, fd); fclose(fd); os_remove((char *)tempname); if (i != len) { diff --git a/src/nvim/misc1.h b/src/nvim/misc1.h index 11891d6f7e..f0f66854d8 100644 --- a/src/nvim/misc1.h +++ b/src/nvim/misc1.h @@ -2,6 +2,7 @@ #define NVIM_MISC1_H #include "nvim/vim.h" +#include "nvim/os/shell.h" /* flags for open_line() */ #define OPENLINE_DELSPACES 1 /* delete spaces after cursor */ diff --git a/src/nvim/misc2.c b/src/nvim/misc2.c index 3c0a1414a6..4b64de1be0 100644 --- a/src/nvim/misc2.c +++ b/src/nvim/misc2.c @@ -327,9 +327,10 @@ int call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg) } } - set_vim_var_nr(VV_SHELL_ERROR, (long)retval); - if (do_profiling == PROF_YES) + set_vim_var_nr(VV_SHELL_ERROR, (varnumber_T) retval); + if (do_profiling == PROF_YES) { prof_child_exit(&wait_time); + } return retval; } diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c index 3ae1a6a890..4611b69424 100644 --- a/src/nvim/mouse.c +++ b/src/nvim/mouse.c @@ -14,6 +14,8 @@ #include "nvim/misc1.h" #include "nvim/cursor.h" #include "nvim/buffer_defs.h" +#include "nvim/memline.h" +#include "nvim/charset.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "mouse.c.generated.h" @@ -503,3 +505,95 @@ void set_mouse_topline(win_T *wp) orig_topfill = wp->w_topfill; } +/// +/// Return length of line "lnum" for horizontal scrolling. +/// +static colnr_T scroll_line_len(linenr_T lnum) +{ + colnr_T col = 0; + char_u *line = ml_get(lnum); + if (*line != NUL) { + for (;;) { + int numchar = chartabsize(line, col); + mb_ptr_adv(line); + if (*line == NUL) { // don't count the last character + break; + } + col += numchar; + } + } + return col; +} + +/// +/// Find longest visible line number. +/// +static linenr_T find_longest_lnum(void) +{ + linenr_T ret = 0; + + // Calculate maximum for horizontal scrollbar. Check for reasonable + // line numbers, topline and botline can be invalid when displaying is + // postponed. + if (curwin->w_topline <= curwin->w_cursor.lnum && + curwin->w_botline > curwin->w_cursor.lnum && + curwin->w_botline <= curbuf->b_ml.ml_line_count + 1) { + long max = 0; + + // Use maximum of all visible lines. Remember the lnum of the + // longest line, closest to the cursor line. Used when scrolling + // below. + for (linenr_T lnum = curwin->w_topline; lnum < curwin->w_botline; lnum++) { + colnr_T len = scroll_line_len(lnum); + if (len > (colnr_T)max) { + max = len; + ret = lnum; + } else if (len == (colnr_T)max + && abs((int)(lnum - curwin->w_cursor.lnum)) + < abs((int)(ret - curwin->w_cursor.lnum))) { + ret = lnum; + } + } + } else { + // Use cursor line only. + ret = curwin->w_cursor.lnum; + } + + return ret; +} + +/// +/// Do a horizontal scroll. Return TRUE if the cursor moved, FALSE otherwise. +/// +bool mouse_scroll_horiz(int dir) +{ + if (curwin->w_p_wrap) { + return false; + } + + int step = 6; + if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) { + step = curwin->w_width; + } + + int leftcol = curwin->w_leftcol + (dir == MSCR_RIGHT ? -step : +step); + if (leftcol < 0) { + leftcol = 0; + } + + if (curwin->w_leftcol == leftcol) { + return false; + } + + curwin->w_leftcol = (colnr_T)leftcol; + + // When the line of the cursor is too short, move the cursor to the + // longest visible line. + if (!virtual_active() + && (colnr_T)leftcol > scroll_line_len(curwin->w_cursor.lnum)) { + curwin->w_cursor.lnum = find_longest_lnum(); + curwin->w_cursor.col = 0; + } + + return leftcol_changed(); +} diff --git a/src/nvim/mouse.h b/src/nvim/mouse.h index c824bcc8f0..0149f7c7c0 100644 --- a/src/nvim/mouse.h +++ b/src/nvim/mouse.h @@ -34,6 +34,12 @@ #define MOUSE_X1 0x300 // Mouse-button X1 (6th) #define MOUSE_X2 0x400 // Mouse-button X2 +// Direction for nv_mousescroll() and ins_mousescroll() +#define MSCR_DOWN 0 // DOWN must be FALSE +#define MSCR_UP 1 +#define MSCR_LEFT -1 +#define MSCR_RIGHT -2 + #ifdef INCLUDE_GENERATED_DECLARATIONS # include "mouse.h.generated.h" diff --git a/src/nvim/msgpack_rpc/server.c b/src/nvim/msgpack_rpc/server.c index 474e25ffeb..6cc56ba3dd 100644 --- a/src/nvim/msgpack_rpc/server.c +++ b/src/nvim/msgpack_rpc/server.c @@ -14,7 +14,7 @@ #include "nvim/vim.h" #include "nvim/memory.h" #include "nvim/log.h" -#include "nvim/tempfile.h" +#include "nvim/fileio.h" #include "nvim/path.h" #include "nvim/strings.h" @@ -59,7 +59,7 @@ static void set_vservername(garray_T *srvs) char *default_server = (srvs->ga_len > 0) ? ((SocketWatcher **)srvs->ga_data)[0]->addr : NULL; - set_vim_var_string(VV_SEND_SERVER, (char_u *)default_server, -1); + set_vim_var_string(VV_SEND_SERVER, default_server, -1); } /// Teardown the server module diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 2895816b8f..9173ea2d17 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -3927,6 +3927,8 @@ static void nv_mousescroll(cmdarg_T *cap) cap->count0 = 3; nv_scroll_line(cap); } + } else { + mouse_scroll_horiz(cap->arg); } curwin->w_redr_status = true; @@ -7057,18 +7059,17 @@ static void nv_operator(cmdarg_T *cap) */ static void set_op_var(int optype) { - char_u opchars[3]; - - if (optype == OP_NOP) + if (optype == OP_NOP) { set_vim_var_string(VV_OP, NULL, 0); - else { + } else { + char opchars[3]; int opchar0 = get_op_char(optype); assert(opchar0 >= 0 && opchar0 <= UCHAR_MAX); - opchars[0] = (char_u)opchar0; + opchars[0] = (char) opchar0; int opchar1 = get_extra_op_char(optype); assert(opchar1 >= 0 && opchar1 <= UCHAR_MAX); - opchars[1] = (char_u)opchar1; + opchars[1] = (char) opchar1; opchars[2] = NUL; set_vim_var_string(VV_OP, opchars, -1); diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 8c7805ba04..601890d133 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -1261,21 +1261,18 @@ get_spec_reg ( return FALSE; } -/* - * Paste a yank register into the command line. - * Only for non-special registers. - * Used by CTRL-R command in command-line mode - * insert_reg() can't be used here, because special characters from the - * register contents will be interpreted as commands. - * - * return FAIL for failure, OK otherwise - */ -int -cmdline_paste_reg ( - int regname, - int literally, /* Insert text literally instead of "as typed" */ - int remcr /* don't add trailing CR */ -) +/// Paste a yank register into the command line. +/// Only for non-special registers. +/// Used by CTRL-R command in command-line mode +/// insert_reg() can't be used here, because special characters from the +/// register contents will be interpreted as commands. +/// +/// @param regname Register name. +/// @param literally Insert text literally instead of "as typed". +/// @param remcr When true, don't add CR characters. +/// +/// @returns FAIL for failure, OK otherwise +bool cmdline_paste_reg(int regname, bool literally, bool remcr) { long i; @@ -1286,13 +1283,9 @@ cmdline_paste_reg ( for (i = 0; i < reg->y_size; i++) { cmdline_paste_str(reg->y_array[i], literally); - /* Insert ^M between lines and after last line if type is MLINE. - * Don't do this when "remcr" is TRUE and the next line is empty. */ - if (reg->y_type == MLINE - || (i < reg->y_size - 1 - && !(remcr - && i == reg->y_size - 2 - && *reg->y_array[i + 1] == NUL))) { + // Insert ^M between lines and after last line if type is MLINE. + // Don't do this when "remcr" is true. + if ((reg->y_type == MLINE || i < reg->y_size - 1) && !remcr) { cmdline_paste_str((char_u *)"\r", literally); } @@ -3996,7 +3989,7 @@ format_lines ( if (line_count < 0 && u_save_cursor() == FAIL) break; if (next_leader_len > 0) { - (void)del_bytes((long)next_leader_len, FALSE, FALSE); + (void)del_bytes(next_leader_len, false, false); mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L, (long)-next_leader_len); } else if (second_indent > 0) { /* the "leader" for FO_Q_SECOND */ diff --git a/src/nvim/option.c b/src/nvim/option.c index 5efd71444a..3376348d6f 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1448,7 +1448,7 @@ do_set ( char_u *oldval = NULL; // previous value if *varp char_u *newval; char_u *origval = NULL; - char_u *saved_origval = NULL; + char *saved_origval = NULL; unsigned newlen; int comma; int bs; @@ -1725,7 +1725,7 @@ do_set ( if (!starting && origval != NULL) { // origval may be freed by // did_set_string_option(), make a copy. - saved_origval = vim_strsave(origval); + saved_origval = xstrdup((char *) origval); } /* Handle side effects, and set the global value for @@ -1740,11 +1740,10 @@ do_set ( } if (saved_origval != NULL) { - char_u buf_type[7]; - vim_snprintf((char *)buf_type, ARRAY_SIZE(buf_type), "%s", + char buf_type[7]; + vim_snprintf(buf_type, ARRAY_SIZE(buf_type), "%s", (opt_flags & OPT_LOCAL) ? "local" : "global"); - set_vim_var_string(VV_OPTION_NEW, - *(char_u **)varp, -1); + set_vim_var_string(VV_OPTION_NEW, *(char **) varp, -1); set_vim_var_string(VV_OPTION_OLD, saved_origval, -1); set_vim_var_string(VV_OPTION_TYPE, buf_type, -1); apply_autocmds(EVENT_OPTIONSET, @@ -2058,6 +2057,7 @@ static void didset_options(void) (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, true); (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, true); (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, true); + (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, false); (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, true); (void)spell_check_msm(); (void)spell_check_sps(); @@ -2145,6 +2145,7 @@ void check_buf_options(buf_T *buf) check_string_option(&buf->b_p_ep); check_string_option(&buf->b_p_path); check_string_option(&buf->b_p_tags); + check_string_option(&buf->b_p_tc); check_string_option(&buf->b_p_dict); check_string_option(&buf->b_p_tsr); check_string_option(&buf->b_p_lw); @@ -2324,7 +2325,7 @@ set_string_option ( char_u *s; char_u **varp; char_u *oldval; - char_u *saved_oldval = NULL; + char *saved_oldval = NULL; char_u *r = NULL; if (options[opt_idx].var == NULL) /* don't set hidden option */ @@ -2340,7 +2341,7 @@ set_string_option ( *varp = s; if (!starting) { - saved_oldval = vim_strsave(oldval); + saved_oldval = xstrdup((char *) oldval); } if ((r = did_set_string_option(opt_idx, varp, (int)true, oldval, NULL, @@ -2349,10 +2350,10 @@ set_string_option ( // call autocommand after handling side effects if (saved_oldval != NULL) { - char_u buf_type[7]; - vim_snprintf((char *)buf_type, ARRAY_SIZE(buf_type), "%s", + char buf_type[7]; + vim_snprintf(buf_type, ARRAY_SIZE(buf_type), "%s", (opt_flags & OPT_LOCAL) ? "local" : "global"); - set_vim_var_string(VV_OPTION_NEW, *varp, -1); + set_vim_var_string(VV_OPTION_NEW, (char *) (*varp), -1); set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1); set_vim_var_string(VV_OPTION_TYPE, buf_type, -1); apply_autocmds(EVENT_OPTIONSET, @@ -2984,6 +2985,24 @@ did_set_string_option ( if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, true) != OK) { errmsg = e_invarg; } + } else if (gvarp == &p_tc) { // 'tagcase' + unsigned int *flags; + + if (opt_flags & OPT_LOCAL) { + p = curbuf->b_p_tc; + flags = &curbuf->b_tc_flags; + } else { + p = p_tc; + flags = &tc_flags; + } + + if ((opt_flags & OPT_LOCAL) && *p == NUL) { + // make the local value empty: use the global value + *flags = 0; + } else if (*p == NUL + || opt_strings_flags(p, p_tc_values, flags, false) != OK) { + errmsg = e_invarg; + } } else if (varp == &p_cmp) { // 'casemap' if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, true) != OK) errmsg = e_invarg; @@ -3800,7 +3819,7 @@ set_bool_option ( msg_source(hl_attr(HLF_W)); MSG_ATTR(_(w_arabic), hl_attr(HLF_W)); - set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1); + set_vim_var_string(VV_WARNINGMSG, _(w_arabic), -1); } /* set 'delcombine' */ @@ -3847,14 +3866,14 @@ set_bool_option ( options[opt_idx].flags |= P_WAS_SET; if (!starting) { - char_u buf_old[2]; - char_u buf_new[2]; - char_u buf_type[7]; - vim_snprintf((char *)buf_old, ARRAY_SIZE(buf_old), "%d", + char buf_old[2]; + char buf_new[2]; + char buf_type[7]; + vim_snprintf(buf_old, ARRAY_SIZE(buf_old), "%d", old_value ? true: false); - vim_snprintf((char *)buf_new, ARRAY_SIZE(buf_new), "%d", + vim_snprintf(buf_new, ARRAY_SIZE(buf_new), "%d", value ? true: false); - vim_snprintf((char *)buf_type, ARRAY_SIZE(buf_type), "%s", + vim_snprintf(buf_type, ARRAY_SIZE(buf_type), "%s", (opt_flags & OPT_LOCAL) ? "local" : "global"); set_vim_var_string(VV_OPTION_NEW, buf_new, -1); set_vim_var_string(VV_OPTION_OLD, buf_old, -1); @@ -4237,12 +4256,12 @@ set_num_option ( options[opt_idx].flags |= P_WAS_SET; if (!starting && errmsg == NULL) { - char_u buf_old[NUMBUFLEN]; - char_u buf_new[NUMBUFLEN]; - char_u buf_type[7]; - vim_snprintf((char *)buf_old, ARRAY_SIZE(buf_old), "%ld", old_value); - vim_snprintf((char *)buf_new, ARRAY_SIZE(buf_new), "%ld", value); - vim_snprintf((char *)buf_type, ARRAY_SIZE(buf_type), "%s", + char buf_old[NUMBUFLEN]; + char buf_new[NUMBUFLEN]; + char buf_type[7]; + vim_snprintf(buf_old, ARRAY_SIZE(buf_old), "%ld", old_value); + vim_snprintf(buf_new, ARRAY_SIZE(buf_new), "%ld", value); + vim_snprintf(buf_type, ARRAY_SIZE(buf_type), "%s", (opt_flags & OPT_LOCAL) ? "local" : "global"); set_vim_var_string(VV_OPTION_NEW, buf_new, -1); set_vim_var_string(VV_OPTION_OLD, buf_old, -1); @@ -5112,6 +5131,10 @@ void unset_global_local_option(char *name, void *from) case PV_TAGS: clear_string_option(&buf->b_p_tags); break; + case PV_TC: + clear_string_option(&buf->b_p_tc); + buf->b_tc_flags = 0; + break; case PV_DEF: clear_string_option(&buf->b_p_def); break; @@ -5165,6 +5188,7 @@ static char_u *get_varp_scope(vimoption_T *p, int opt_flags) case PV_PATH: return (char_u *)&(curbuf->b_p_path); case PV_AR: return (char_u *)&(curbuf->b_p_ar); case PV_TAGS: return (char_u *)&(curbuf->b_p_tags); + case PV_TC: return (char_u *)&(curbuf->b_p_tc); case PV_DEF: return (char_u *)&(curbuf->b_p_def); case PV_INC: return (char_u *)&(curbuf->b_p_inc); case PV_DICT: return (char_u *)&(curbuf->b_p_dict); @@ -5202,6 +5226,8 @@ static char_u *get_varp(vimoption_T *p) ? (char_u *)&(curbuf->b_p_ar) : p->var; case PV_TAGS: return *curbuf->b_p_tags != NUL ? (char_u *)&(curbuf->b_p_tags) : p->var; + case PV_TC: return *curbuf->b_p_tc != NUL + ? (char_u *)&(curbuf->b_p_tc) : p->var; case PV_BKC: return *curbuf->b_p_bkc != NUL ? (char_u *)&(curbuf->b_p_bkc) : p->var; case PV_DEF: return *curbuf->b_p_def != NUL @@ -5581,6 +5607,8 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_p_kp = empty_option; buf->b_p_path = empty_option; buf->b_p_tags = empty_option; + buf->b_p_tc = empty_option; + buf->b_tc_flags = 0; buf->b_p_def = empty_option; buf->b_p_inc = empty_option; buf->b_p_inex = vim_strsave(p_inex); diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h index 547bd9442c..87a9a7398c 100644 --- a/src/nvim/option_defs.h +++ b/src/nvim/option_defs.h @@ -4,6 +4,7 @@ #include <stdbool.h> #include "nvim/types.h" +#include "nvim/macros.h" // For EXTERN // option_defs.h: definition of global variables for settable options @@ -172,6 +173,7 @@ enum { SHM_INTRO = 'I', ///< Intro messages. SHM_COMPLETIONMENU = 'c', ///< Completion menu messages. SHM_RECORDING = 'q', ///< Short recording message. + SHM_FILEINFO = 'F', ///< No file info messages. }; /// Represented by 'a' flag. #define SHM_ALL_ABBREVIATIONS ((char_u[]) { \ @@ -183,7 +185,7 @@ enum { SHM_RO, SHM_MOD, SHM_FILE, SHM_LAST, SHM_TEXT, SHM_LINES, SHM_NEW, SHM_WRI, \ SHM_ABBREVIATIONS, SHM_WRITE, SHM_TRUNC, SHM_TRUNCALL, SHM_OVER, \ SHM_OVERALL, SHM_SEARCH, SHM_ATTENTION, SHM_INTRO, SHM_COMPLETIONMENU, \ - SHM_RECORDING, \ + SHM_RECORDING, SHM_FILEINFO, \ 0, \ }) @@ -595,6 +597,14 @@ static char *(p_swb_values[]) = #define SWB_NEWTAB 0x008 #define SWB_VSPLIT 0x010 EXTERN int p_tbs; ///< 'tagbsearch' +EXTERN char_u *p_tc; ///< 'tagcase' +EXTERN unsigned tc_flags; ///< flags from 'tagcase' +#ifdef IN_OPTION_C +static char *(p_tc_values[]) = { "followic", "ignore", "match", NULL }; +#endif +#define TC_FOLLOWIC 0x01 +#define TC_IGNORE 0x02 +#define TC_MATCH 0x04 EXTERN long p_tl; ///< 'taglength' EXTERN int p_tr; ///< 'tagrelative' EXTERN char_u *p_tags; ///< 'tags' @@ -735,6 +745,7 @@ enum { , BV_SW , BV_SWF , BV_TAGS + , BV_TC , BV_TS , BV_TW , BV_TX diff --git a/src/nvim/options.lua b/src/nvim/options.lua index df77c374ec..a743e8c605 100644 --- a/src/nvim/options.lua +++ b/src/nvim/options.lua @@ -2332,6 +2332,13 @@ return { defaults={if_true={vi=true}} }, { + full_name='tagcase', abbreviation='tc', + type='string', scope={'global', 'buffer'}, + vim=true, + varname='p_tc', + defaults={if_true={vi="followic", vim="followic"}} + }, + { full_name='taglength', abbreviation='tl', type='number', scope={'global'}, vi_def=true, diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 2e671653ed..bc2d37764d 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -59,6 +59,23 @@ int os_dirname(char_u *buf, size_t len) return OK; } +/// Check if the given path is a directory and not a symlink to a directory. +/// @return `true` if `name` is a directory and NOT a symlink to a directory. +/// `false` if `name` is not a directory or if an error occurred. +bool os_isrealdir(const char_u *name) + FUNC_ATTR_NONNULL_ALL +{ + uv_fs_t request; + if (uv_fs_lstat(&fs_loop, &request, (char *)name, NULL) != kLibuvSuccess) { + return false; + } + if (S_ISLNK(request.statbuf.st_mode)) { + return false; + } else { + return S_ISDIR(request.statbuf.st_mode); + } +} + /// Check if the given path is a directory or not. /// /// @return `true` if `fname` is a directory. @@ -166,7 +183,7 @@ static bool is_executable_in_path(const char_u *name, char_u **abspath) // Glue together the given directory from $PATH with name and save into // buf. STRLCPY(buf, path, e - path + 1); - append_path((char *) buf, (const char *) name, (int)buf_len); + append_path((char *) buf, (const char *) name, buf_len); if (is_executable(buf)) { // Check if the caller asked for a copy of the path. diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c index c9631a434c..81ceb919c4 100644 --- a/src/nvim/os/stdpaths.c +++ b/src/nvim/os/stdpaths.c @@ -22,9 +22,9 @@ static const char *xdg_env_vars[] = { static const char *const xdg_defaults[] = { #ifdef WIN32 // Windows - [kXDGConfigHome] = "$LOCALAPPDATA\\nvim\\config", - [kXDGDataHome] = "$LOCALAPPDATA\\nvim\\data", - [kXDGCacheHome] = "$LOCALAPPDATA\\nvim\\cache", + [kXDGConfigHome] = "$LOCALAPPDATA", + [kXDGDataHome] = "$LOCALAPPDATA", + [kXDGCacheHome] = "$TEMP", [kXDGRuntimeDir] = NULL, [kXDGConfigDirs] = NULL, [kXDGDataDirs] = NULL, @@ -66,12 +66,21 @@ char *stdpaths_get_xdg_var(const XDGVarType idx) /// @param[in] idx XDG directory to use. /// /// @return [allocated] `{xdg_directory}/nvim` +/// +/// In WIN32 get_xdg_home(kXDGDataHome) returns `{xdg_directory}/nvim-data` to +/// avoid storing configuration and data files in the same path. static char *get_xdg_home(const XDGVarType idx) FUNC_ATTR_WARN_UNUSED_RESULT { char *dir = stdpaths_get_xdg_var(idx); if (dir) { +#if defined(WIN32) + dir = concat_fnames_realloc(dir, + (idx == kXDGDataHome ? "nvim-data" : "nvim"), + true); +#else dir = concat_fnames_realloc(dir, "nvim", true); +#endif } return dir; } diff --git a/src/nvim/os_unix.c b/src/nvim/os_unix.c index cb9a58cc77..2a859a0f7a 100644 --- a/src/nvim/os_unix.c +++ b/src/nvim/os_unix.c @@ -34,7 +34,6 @@ #include "nvim/screen.h" #include "nvim/strings.h" #include "nvim/syntax.h" -#include "nvim/tempfile.h" #include "nvim/ui.h" #include "nvim/types.h" #include "nvim/os/os.h" diff --git a/src/nvim/path.c b/src/nvim/path.c index 5cd93ab811..d3df9bc059 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -268,16 +268,13 @@ char_u *shorten_dir(char_u *str) */ bool dir_of_file_exists(char_u *fname) { - char_u *p; - int c; - bool retval; - - p = path_tail_with_sep(fname); - if (p == fname) + char_u *p = path_tail_with_sep(fname); + if (p == fname) { return true; - c = *p; + } + char_u c = *p; *p = NUL; - retval = os_isdir(fname); + bool retval = os_isdir(fname); *p = c; return retval; } @@ -539,15 +536,10 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, size_t wildoff, int flags, bool didstar) FUNC_ATTR_NONNULL_ALL { - char_u *buf; - char_u *p, *s, *e; int start_len = gap->ga_len; - char_u *pat; - int starts_with_dot; - int matches; - int len; + size_t len; bool starstar = false; - static int stardepth = 0; /* depth for "**" expansion */ + static int stardepth = 0; // depth for "**" expansion /* Expanding "**" may take a long time, check for CTRL-C. */ if (stardepth > 0) { @@ -558,16 +550,14 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, // Make room for file name. When doing encoding conversion the actual // length may be quite a bit longer, thus use the maximum possible length. - buf = xmalloc(MAXPATHL); - - /* - * Find the first part in the path name that contains a wildcard. - * When EW_ICASE is set every letter is considered to be a wildcard. - * Copy it into "buf", including the preceding characters. - */ - p = buf; - s = buf; - e = NULL; + char_u *buf = xmalloc(MAXPATHL); + + // Find the first part in the path name that contains a wildcard. + // When EW_ICASE is set every letter is considered to be a wildcard. + // Copy it into "buf", including the preceding characters. + char_u *p = buf; + char_u *s = buf; + char_u *e = NULL; const char_u *path_end = path; while (*path_end != NUL) { /* May ignore a wildcard that has a backslash before it; it will @@ -588,7 +578,7 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, e = p; } if (has_mbyte) { - len = (*mb_ptr2len)(path_end); + len = (size_t)(*mb_ptr2len)(path_end); STRNCPY(p, path_end, len); p += len; path_end += len; @@ -613,9 +603,9 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, if (p[0] == '*' && p[1] == '*') starstar = true; - /* convert the file pattern to a regexp pattern */ - starts_with_dot = (*s == '.'); - pat = file_pat_to_reg_pat(s, e, NULL, FALSE); + // convert the file pattern to a regexp pattern + int starts_with_dot = *s == '.'; + char_u *pat = file_pat_to_reg_pat(s, e, NULL, false); if (pat == NULL) { xfree(buf); return 0; @@ -646,9 +636,9 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, if (!didstar && stardepth < 100 && starstar && e - s == 2 && *path_end == '/') { STRCPY(s, path_end + 1); - ++stardepth; - (void)do_path_expand(gap, buf, (int)(s - buf), flags, true); - --stardepth; + stardepth++; + (void)do_path_expand(gap, buf, (size_t)(s - buf), flags, true); + stardepth--; } *s = NUL; @@ -657,9 +647,12 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, if (os_file_is_readable(dirpath) && os_scandir(&dir, dirpath)) { // Find all matching entries. char_u *name; - scandir_next_with_dots(NULL /* initialize */); - while((name = (char_u *) scandir_next_with_dots(&dir)) && name != NULL) { - if ((name[0] != '.' || starts_with_dot) + scandir_next_with_dots(NULL); // initialize + while ((name = (char_u *) scandir_next_with_dots(&dir)) && name != NULL) { + if ((name[0] != '.' + || starts_with_dot + || ((flags & EW_DODOT) + && name[1] != NUL && (name[1] != '.' || name[2] != NUL))) && ((regmatch.regprog != NULL && vim_regexec(®match, name, 0)) || ((flags & EW_NOTWILD) && fnamencmp(path + (s - buf), name, e - s) == 0))) { @@ -703,10 +696,11 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, xfree(buf); vim_regfree(regmatch.regprog); - matches = gap->ga_len - start_len; - if (matches > 0) + size_t matches = (size_t)(gap->ga_len - start_len); + if (matches > 0) { qsort(((char_u **)gap->ga_data) + start_len, matches, - sizeof(char_u *), pstrcmp); + sizeof(char_u *), pstrcmp); + } return matches; } @@ -736,27 +730,24 @@ static int find_previous_pathsep(char_u *path, char_u **psep) */ static bool is_unique(char_u *maybe_unique, garray_T *gap, int i) { - int candidate_len; - int other_path_len; - char_u **other_paths = (char_u **)gap->ga_data; - char_u *rival; + char_u **other_paths = (char_u **)gap->ga_data; for (int j = 0; j < gap->ga_len; j++) { - if (j == i) - continue; /* don't compare it with itself */ - - candidate_len = (int)STRLEN(maybe_unique); - other_path_len = (int)STRLEN(other_paths[j]); - if (other_path_len < candidate_len) - continue; /* it's different when it's shorter */ - - rival = other_paths[j] + other_path_len - candidate_len; + if (j == i) { + continue; // don't compare it with itself + } + size_t candidate_len = STRLEN(maybe_unique); + size_t other_path_len = STRLEN(other_paths[j]); + if (other_path_len < candidate_len) { + continue; // it's different when it's shorter + } + char_u *rival = other_paths[j] + other_path_len - candidate_len; if (fnamecmp(maybe_unique, rival) == 0 - && (rival == other_paths[j] || vim_ispathsep(*(rival - 1)))) - return false; /* match */ + && (rival == other_paths[j] || vim_ispathsep(*(rival - 1)))) { + return false; // match + } } - - return true; /* no match found */ + return true; // no match found } /* @@ -770,12 +761,8 @@ static bool is_unique(char_u *maybe_unique, garray_T *gap, int i) */ static void expand_path_option(char_u *curdir, garray_T *gap) { - char_u *path_option = *curbuf->b_p_path == NUL - ? p_path : curbuf->b_p_path; - char_u *buf; - int len; - - buf = xmalloc(MAXPATHL); + char_u *path_option = *curbuf->b_p_path == NUL ? p_path : curbuf->b_p_path; + char_u *buf = xmalloc(MAXPATHL); while (*path_option != NUL) { copy_option_part(&path_option, buf, MAXPATHL, " ,"); @@ -787,26 +774,27 @@ static void expand_path_option(char_u *curdir, garray_T *gap) if (curbuf->b_ffname == NULL) continue; char_u *p = path_tail(curbuf->b_ffname); - len = (int)(p - curbuf->b_ffname); - if (len + (int)STRLEN(buf) >= MAXPATHL) + size_t len = (size_t)(p - curbuf->b_ffname); + if (len + STRLEN(buf) >= MAXPATHL) { continue; - if (buf[1] == NUL) + } + if (buf[1] == NUL) { buf[len] = NUL; - else + } else { STRMOVE(buf + len, buf + 2); + } memmove(buf, curbuf->b_ffname, len); simplify_filename(buf); - } else if (buf[0] == NUL) - /* relative to current directory */ - STRCPY(buf, curdir); - else if (path_with_url((char *)buf)) - /* URL can't be used here */ - continue; - else if (!path_is_absolute_path(buf)) { - /* Expand relative path to their full path equivalent */ - len = (int)STRLEN(curdir); - if (len + (int)STRLEN(buf) + 3 > MAXPATHL) + } else if (buf[0] == NUL) { + STRCPY(buf, curdir); // relative to current directory + } else if (path_with_url((char *)buf)) { + continue; // URL can't be used here + } else if (!path_is_absolute_path(buf)) { + // Expand relative path to their full path equivalent + size_t len = STRLEN(curdir); + if (len + STRLEN(buf) + 3 > MAXPATHL) { continue; + } STRMOVE(buf + len + 1, buf); STRCPY(buf, curdir); buf[len] = PATHSEP; @@ -860,31 +848,25 @@ static char_u *get_path_cutoff(char_u *fname, garray_T *gap) */ static void uniquefy_paths(garray_T *gap, char_u *pattern) { - int len; - char_u **fnames = (char_u **)gap->ga_data; + char_u **fnames = (char_u **)gap->ga_data; bool sort_again = false; - char_u *pat; - char_u *file_pattern; - char_u *curdir; regmatch_T regmatch; garray_T path_ga; - char_u **in_curdir = NULL; - char_u *short_name; + char_u **in_curdir = NULL; + char_u *short_name; ga_remove_duplicate_strings(gap); ga_init(&path_ga, (int)sizeof(char_u *), 1); - /* - * We need to prepend a '*' at the beginning of file_pattern so that the - * regex matches anywhere in the path. FIXME: is this valid for all - * possible patterns? - */ - len = (int)STRLEN(pattern); - file_pattern = xmalloc(len + 2); + // We need to prepend a '*' at the beginning of file_pattern so that the + // regex matches anywhere in the path. FIXME: is this valid for all + // possible patterns? + size_t len = STRLEN(pattern); + char_u *file_pattern = xmalloc(len + 2); file_pattern[0] = '*'; file_pattern[1] = NUL; STRCAT(file_pattern, pattern); - pat = file_pat_to_reg_pat(file_pattern, NULL, NULL, TRUE); + char_u *pat = file_pat_to_reg_pat(file_pattern, NULL, NULL, true); xfree(file_pattern); if (pat == NULL) return; @@ -895,11 +877,11 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern) if (regmatch.regprog == NULL) return; - curdir = xmalloc(MAXPATHL); + char_u *curdir = xmalloc(MAXPATHL); os_dirname(curdir, MAXPATHL); expand_path_option(curdir, &path_ga); - in_curdir = xcalloc(gap->ga_len, sizeof(char_u *)); + in_curdir = xcalloc((size_t)gap->ga_len, sizeof(char_u *)); for (int i = 0; i < gap->ga_len && !got_int; i++) { char_u *path = fnames[i]; @@ -908,7 +890,7 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern) char_u *pathsep_p; char_u *path_cutoff; - len = (int)STRLEN(path); + len = STRLEN(path); is_in_curdir = fnamencmp(curdir, path, dir_end - path) == 0 && curdir[dir_end - path] == NUL; if (is_in_curdir) @@ -1113,9 +1095,8 @@ static bool has_special_wildchar(char_u *p) int gen_expand_wildcards(int num_pat, char_u **pat, int *num_file, char_u ***file, int flags) { - int i; garray_T ga; - char_u *p; + char_u *p; static bool recursive = false; int add_pat; bool did_expand_in_path = false; @@ -1140,11 +1121,11 @@ int gen_expand_wildcards(int num_pat, char_u **pat, int *num_file, * avoids starting the shell for each argument separately. * For `=expr` do use the internal function. */ - for (i = 0; i < num_pat; i++) { + for (int i = 0; i < num_pat; i++) { if (has_special_wildchar(pat[i]) - && !(vim_backtick(pat[i]) && pat[i][1] == '=') - ) + && !(vim_backtick(pat[i]) && pat[i][1] == '=')) { return mch_expand_wildcards(num_pat, pat, num_file, file, flags); + } } #endif @@ -1155,7 +1136,7 @@ int gen_expand_wildcards(int num_pat, char_u **pat, int *num_file, */ ga_init(&ga, (int)sizeof(char_u *), 30); - for (i = 0; i < num_pat; ++i) { + for (int i = 0; i < num_pat; ++i) { add_pat = -1; p = pat[i]; @@ -1212,7 +1193,9 @@ int gen_expand_wildcards(int num_pat, char_u **pat, int *num_file, recursive = true; did_expand_in_path = true; } else { - add_pat = path_expand(&ga, p, flags); + size_t tmp_add_pat = path_expand(&ga, p, flags); + assert(tmp_add_pat <= INT_MAX); + add_pat = (int)tmp_add_pat; } } } @@ -1240,7 +1223,7 @@ int gen_expand_wildcards(int num_pat, char_u **pat, int *num_file, recursive = false; - return (ga.ga_data != NULL) ? OK : FAIL; + return ((flags & EW_EMPTYOK) || ga.ga_data != NULL) ? OK : FAIL; } @@ -1261,14 +1244,12 @@ static int expand_backtick( int flags /* EW_* flags */ ) { - char_u *p; - char_u *cmd; - char_u *buffer; + char_u *p; + char_u *buffer; int cnt = 0; - int i; - /* Create the command: lop off the backticks. */ - cmd = vim_strnsave(pat + 1, (int)STRLEN(pat) - 2); + // Create the command: lop off the backticks. + char_u *cmd = vim_strnsave(pat + 1, STRLEN(pat) - 2); if (*cmd == '=') /* `={expr}`: Expand expression */ buffer = eval_to_string(cmd + 1, &p, TRUE); @@ -1288,7 +1269,7 @@ static int expand_backtick( ++p; /* add an entry if it is not empty */ if (p > cmd) { - i = *p; + char_u i = *p; *p = NUL; addfile(gap, cmd, flags); *p = i; @@ -1517,13 +1498,12 @@ void simplify_filename(char_u *filename) } while (*p != NUL); } -static char_u *eval_includeexpr(char_u *ptr, size_t len) +static char *eval_includeexpr(const char *const ptr, const size_t len) { - assert(len <= INT_MAX); - set_vim_var_string(VV_FNAME, ptr, (int)len); - char_u *res = eval_to_string_safe(curbuf->b_p_inex, NULL, - was_set_insecurely((char_u *)"includeexpr", - OPT_LOCAL)); + set_vim_var_string(VV_FNAME, ptr, (ptrdiff_t) len); + char *res = (char *) eval_to_string_safe( + curbuf->b_p_inex, NULL, was_set_insecurely((char_u *)"includeexpr", + OPT_LOCAL)); set_vim_var_string(VV_FNAME, NULL, 0); return res; } @@ -1541,12 +1521,11 @@ find_file_name_in_path ( char_u *rel_fname /* file we are searching relative to */ ) { - char_u *file_name; - int c; - char_u *tofree = NULL; + char_u *file_name; + char_u *tofree = NULL; if ((options & FNAME_INCL) && *curbuf->b_p_inex != NUL) { - tofree = eval_includeexpr(ptr, len); + tofree = (char_u *) eval_includeexpr((char *) ptr, len); if (tofree != NULL) { ptr = tofree; len = STRLEN(ptr); @@ -1554,8 +1533,8 @@ find_file_name_in_path ( } if (options & FNAME_EXP) { - file_name = find_file_in_path(ptr, len, options & ~FNAME_MESS, - TRUE, rel_fname); + file_name = find_file_in_path(ptr, len, options & ~FNAME_MESS, true, + rel_fname); /* * If the file could not be found in a normal way, try applying @@ -1563,7 +1542,7 @@ find_file_name_in_path ( */ if (file_name == NULL && !(options & FNAME_INCL) && *curbuf->b_p_inex != NUL) { - tofree = eval_includeexpr(ptr, len); + tofree = (char_u *) eval_includeexpr((char *) ptr, len); if (tofree != NULL) { ptr = tofree; len = STRLEN(ptr); @@ -1572,7 +1551,7 @@ find_file_name_in_path ( } } if (file_name == NULL && (options & FNAME_MESS)) { - c = ptr[len]; + char_u c = ptr[len]; ptr[len] = NUL; EMSG2(_("E447: Can't find file \"%s\" in path"), ptr); ptr[len] = c; @@ -1631,7 +1610,7 @@ bool vim_isAbsName(char_u *name) /// @param force is a flag to force expanding even if the path is absolute /// /// @return FAIL for failure, OK otherwise -int vim_FullName(const char *fname, char *buf, int len, bool force) +int vim_FullName(const char *fname, char *buf, size_t len, bool force) FUNC_ATTR_NONNULL_ARG(2) { int retval = OK; @@ -2017,14 +1996,12 @@ int expand_wildcards(int num_pat, char_u **pat, int *num_file, char_u ***file, */ int match_suffix(char_u *fname) { - int fnamelen, setsuflen; - char_u *setsuf; -#define MAXSUFLEN 30 /* maximum length of a file suffix */ +#define MAXSUFLEN 30 // maximum length of a file suffix char_u suf_buf[MAXSUFLEN]; - fnamelen = (int)STRLEN(fname); - setsuflen = 0; - for (setsuf = p_su; *setsuf; ) { + size_t fnamelen = STRLEN(fname); + size_t setsuflen = 0; + for (char_u *setsuf = p_su; *setsuf; ) { setsuflen = copy_option_part(&setsuf, suf_buf, MAXSUFLEN, ".,"); if (setsuflen == 0) { char_u *tail = path_tail(fname); @@ -2035,10 +2012,10 @@ int match_suffix(char_u *fname) break; } } else { - if (fnamelen >= setsuflen - && fnamencmp(suf_buf, fname + fnamelen - setsuflen, - (size_t)setsuflen) == 0) + if (fnamelen >= setsuflen && + fnamencmp(suf_buf, fname + fnamelen - setsuflen, setsuflen) == 0) { break; + } setsuflen = 0; } } @@ -2049,7 +2026,7 @@ int match_suffix(char_u *fname) /// /// @param directory Directory name, relative to current directory. /// @return `FAIL` for failure, `OK` for success. -int path_full_dir_name(char *directory, char *buffer, int len) +int path_full_dir_name(char *directory, char *buffer, size_t len) { int SUCCESS = 0; int retval = OK; @@ -2091,10 +2068,10 @@ int path_full_dir_name(char *directory, char *buffer, int len) // Append to_append to path with a slash in between. // Append to_append to path with a slash in between. -int append_path(char *path, const char *to_append, int max_len) +int append_path(char *path, const char *to_append, size_t max_len) { - int current_length = STRLEN(path); - int to_append_length = STRLEN(to_append); + size_t current_length = strlen(path); + size_t to_append_length = strlen(to_append); // Do not append empty strings. if (to_append_length == 0) { @@ -2129,12 +2106,14 @@ int append_path(char *path, const char *to_append, int max_len) /// Expand a given file to its absolute path. /// -/// @param fname The filename which should be expanded. -/// @param buf Buffer to store the absolute path of `fname`. -/// @param len Length of `buf`. -/// @param force Also expand when `fname` is already absolute. -/// @return `FAIL` for failure, `OK` for success. -static int path_get_absolute_path(const char_u *fname, char_u *buf, int len, int force) +/// @param fname filename which should be expanded. +/// @param buf buffer to store the absolute path of "fname". +/// @param len length of "buf". +/// @param force also expand when "fname" is already absolute. +/// +/// @return FAIL for failure, OK for success. +static int path_get_absolute_path(const char_u *fname, char_u *buf, + size_t len, int force) { char_u *p; *buf = NUL; diff --git a/src/nvim/path.h b/src/nvim/path.h index eac367d0ac..88e5935c24 100644 --- a/src/nvim/path.h +++ b/src/nvim/path.h @@ -21,6 +21,8 @@ /* Note: mostly EW_NOTFOUND and EW_SILENT are mutually exclusive: EW_NOTFOUND * is used when executing commands and EW_SILENT for interactive expanding. */ #define EW_ALLLINKS 0x1000 // also links not pointing to existing file +#define EW_DODOT 0x4000 // also files starting with a dot +#define EW_EMPTYOK 0x8000 // no matches is not an error /// Return value for the comparison of two files. Also @see path_full_compare. typedef enum file_comparison { diff --git a/src/nvim/po/eo.po b/src/nvim/po/eo.po index 8215b31e65..5b0cb2260b 100644 --- a/src/nvim/po/eo.po +++ b/src/nvim/po/eo.po @@ -23,8 +23,8 @@ msgid "" msgstr "" "Project-Id-Version: Vim(Esperanto)\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2014-05-26 14:21+0200\n" -"PO-Revision-Date: 2013-05-27 04:55+0200\n" +"POT-Creation-Date: 2015-07-30 17:54+0200\n" +"PO-Revision-Date: 2015-07-30 18:00+0200\n" "Last-Translator: Dominique PELLÉ <dominique.pelle@gmail.com>\n" "Language-Team: \n" "Language: eo\n" @@ -115,11 +115,6 @@ msgstr "E84: Neniu modifita bufro trovita" msgid "E85: There is no listed buffer" msgstr "E85: Estas neniu listigita bufro" -#: ../buffer.c:913 -#, c-format -msgid "E86: Buffer %<PRId64> does not exist" -msgstr "E86: La bufro %<PRId64> ne ekzistas" - #: ../buffer.c:915 msgid "E87: Cannot go beyond last buffer" msgstr "E87: Ne eblas iri preter la lastan bufron" @@ -692,6 +687,10 @@ msgstr "E696: Mankas komo en Listo: %s" msgid "E697: Missing end of List ']': %s" msgstr "E697: Mankas fino de Listo ']': %s" +#: ../eval.c:5750 +msgid "Not enough memory to set references, garbage collection aborted!" +msgstr "Ne sufiĉa memory por valorigi referencojn, senrubigado ĉesigita!" + #: ../eval.c:6475 #, c-format msgid "E720: Missing colon in Dictionary: %s" @@ -1616,14 +1615,13 @@ msgstr "E173: %<PRId64> pliaj redaktendaj dosieroj" msgid "E174: Command already exists: add ! to replace it" msgstr "E174: La komando jam ekzistas: aldonu ! por anstataŭigi ĝin" -# DP: malfacilas traduki tion, kaj samtempe honori spacetojn #: ../ex_docmd.c:4432 msgid "" "\n" -" Name Args Range Complete Definition" +" Name Args Address Complete Definition" msgstr "" "\n" -" Nomo Arg Interv Kompleto Difino" +" Nomo Argumentoj Adreso Kompleto Difino" #: ../ex_docmd.c:4516 msgid "No user-defined commands found" @@ -1649,6 +1647,10 @@ msgstr "E178: Nevalida defaŭlta valoro de kvantoro" msgid "E179: argument required for -complete" msgstr "E179: argumento bezonata por -complete" +#: ../ex_docmd.c:4933 +msgid "E179: argument required for -addr" +msgstr "E179: argumento bezonata por -addr" + #: ../ex_docmd.c:4635 #, c-format msgid "E181: Invalid attribute: %s" @@ -1671,6 +1673,11 @@ msgstr "E841: Rezervita nomo, neuzebla por komando difinita de uzanto" msgid "E184: No such user-defined command: %s" msgstr "E184: Neniu komando-difinita-de-uzanto kiel: %s" +#: ../ex_docmd.c:5516 +#, c-format +msgid "E180: Invalid address type value: %s" +msgstr "E180: Nevalida valoro de tipo de adreso: %s" + #: ../ex_docmd.c:5219 #, c-format msgid "E180: Invalid complete value: %s" @@ -2951,6 +2958,11 @@ msgstr "E363: ŝablono uzas pli da memoro ol 'maxmempattern'" msgid "E749: empty buffer" msgstr "E749: malplena bufro" +#: ../globals.h:1226 +#, c-format +msgid "E86: Buffer %<PRId64> does not exist" +msgstr "E86: La bufro %<PRId64> ne ekzistas" + #: ../globals.h:1108 msgid "E682: Invalid search pattern or delimiter" msgstr "E682: Nevalida serĉa ŝablono aŭ disigilo" @@ -4599,6 +4611,11 @@ msgstr "E522: Netrovita en termcap" msgid "E539: Illegal character <%s>" msgstr "E539: Nevalida signo <%s>" +#: ../option.c:2253 +#, c-format +msgid "For option %s" +msgstr "Por opcio %s" + #: ../option.c:3862 msgid "E529: Cannot set 'term' to empty string" msgstr "E529: Ne eblas agordi 'term' al malplena ĉeno" @@ -6552,15 +6569,15 @@ msgstr "E446: Neniu dosiernomo sub la kursoro" #~ msgid "Reading from stdin..." #~ msgstr "Legado el stdin..." -#~ msgid "[blowfish]" -#~ msgstr "[blowfish]" - #~ msgid "[crypted]" #~ msgstr "[ĉifrita]" #~ msgid "E821: File is encrypted with unknown method" #~ msgstr "E821: Dosiero estas ĉifrata per nekonata metodo" +#~ msgid "Warning: Using a weak encryption method; see :help 'cm'" +#~ msgstr "Averto: uzo de malfortika ĉifrada metodo; vidu :help 'cm'" + #~ msgid "NetBeans disallows writes of unmodified buffers" #~ msgstr "NetBeans malpermesas skribojn de neŝanĝitaj bufroj" @@ -6676,8 +6693,8 @@ msgstr "E446: Neniu dosiernomo sub la kursoro" #~ msgid "Vim: Received \"die\" request from session manager\n" #~ msgstr "Vim: Ricevis peton \"die\" (morti) el la seanca administrilo\n" -#~ msgid "Close" -#~ msgstr "Fermi" +#~ msgid "Close tab" +#~ msgstr "Fermi langeton" #~ msgid "New tab" #~ msgstr "Nova langeto" @@ -6733,9 +6750,6 @@ msgstr "E446: Neniu dosiernomo sub la kursoro" #~ msgid "E672: Unable to open window inside MDI application" #~ msgstr "E672: Ne eblas malfermi fenestron interne de aplikaĵo MDI" -#~ msgid "Close tab" -#~ msgstr "Fermi langeton" - #~ msgid "Open tab..." #~ msgstr "Malfermi langeton..." diff --git a/src/nvim/po/es.po b/src/nvim/po/es.po index 1a5ef991dc..8a9c86e88d 100644 --- a/src/nvim/po/es.po +++ b/src/nvim/po/es.po @@ -4276,7 +4276,8 @@ msgstr "" "&Abrir para lectura únicamente\n" "&Editar de todas formas\n" "&Recuperar\n" -"&Borrar&Salir\n" +"&Borrar\n" +"&Salir\n" "&Abortar" #. diff --git a/src/nvim/po/fr.po b/src/nvim/po/fr.po index 9b2d44ce7d..41efd5c5e3 100644 --- a/src/nvim/po/fr.po +++ b/src/nvim/po/fr.po @@ -6,7 +6,7 @@ # FIRST AUTHOR DindinX <David.Odin@bigfoot.com> 2000. # SECOND AUTHOR Adrien Beau <version.francaise@free.fr> 2002, 2003. # THIRD AUTHOR David Blanchet <david.blanchet@free.fr> 2006, 2008. -# FOURTH AUTHOR Dominique Pell <dominique.pelle@gmail.com> 2008, 2013. +# FOURTH AUTHOR Dominique Pell <dominique.pelle@gmail.com> 2008, 2015. # # Latest translation available at: # http://dominique.pelle.free.fr/vim-fr.php @@ -15,8 +15,8 @@ msgid "" msgstr "" "Project-Id-Version: Vim(Franais)\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2014-05-26 14:21+0200\n" -"PO-Revision-Date: 2013-05-27 10:22+0200\n" +"POT-Creation-Date: 2015-07-30 17:54+0200\n" +"PO-Revision-Date: 2015-07-30 18:00+0200\n" "Last-Translator: Dominique Pell <dominique.pelle@gmail.com>\n" "Language-Team: \n" "Language: fr\n" @@ -113,11 +113,6 @@ msgstr "E84: Aucun tampon n'est modifi" msgid "E85: There is no listed buffer" msgstr "E85: Aucun tampon n'est list" -#: ../buffer.c:913 -#, c-format -msgid "E86: Buffer %<PRId64> does not exist" -msgstr "E86: Le tampon %<PRId64> n'existe pas" - # AB - Je ne suis pas sr que l'on puisse obtenir ce message. #: ../buffer.c:915 msgid "E87: Cannot go beyond last buffer" @@ -756,6 +751,11 @@ msgstr "E696: Il manque une virgule dans la Liste %s" msgid "E697: Missing end of List ']': %s" msgstr "E697: Il manque ']' la fin de la Liste %s" +#: ../eval.c:5750 +msgid "Not enough memory to set references, garbage collection aborted!" +msgstr "" +"Pas assez de mmoire pour les rfrences, arrt du ramassage de mites !" + #: ../eval.c:6475 #, c-format msgid "E720: Missing colon in Dictionary: %s" @@ -832,15 +832,15 @@ msgstr "E785: complete() n'est utilisable que dans le mode Insertion" msgid "&Ok" msgstr "&Ok" -#: ../eval.c:8676 -#, c-format -msgid "E737: Key already exists: %s" -msgstr "E737: un mappage existe dj pour %s" - #: ../eval.c:8692 msgid "extend() argument" msgstr "argument de extend()" +#: ../eval.c:9345 +#, c-format +msgid "E737: Key already exists: %s" +msgstr "E737: un mappage existe dj pour %s" + #: ../eval.c:8915 msgid "map() argument" msgstr "argument de map()" @@ -1798,10 +1798,10 @@ msgstr "E174: La commande existe dj : ajoutez ! pour la redfinir" #: ../ex_docmd.c:4432 msgid "" "\n" -" Name Args Range Complete Definition" +" Name Args Address Complete Definition" msgstr "" "\n" -" Nom Args Plage Complet. Dfinition" +" Nom Args Adresse Complet. Dfinition" #: ../ex_docmd.c:4516 msgid "No user-defined commands found" @@ -1827,6 +1827,10 @@ msgstr "E178: La valeur par dfaut du quantificateur est invalide" msgid "E179: argument required for -complete" msgstr "E179: argument requis avec -complete" +#: ../ex_docmd.c:4933 +msgid "E179: argument required for -addr" +msgstr "E179: argument requis avec -addr" + #: ../ex_docmd.c:4635 #, c-format msgid "E181: Invalid attribute: %s" @@ -1850,6 +1854,11 @@ msgstr "" msgid "E184: No such user-defined command: %s" msgstr "E184: Aucune commande %s dfinie par l'utilisateur" +#: ../ex_docmd.c:5516 +#, c-format +msgid "E180: Invalid address type value: %s" +msgstr "E180: Valeur de type d'adresse invalide : %s" + #: ../ex_docmd.c:5219 #, c-format msgid "E180: Invalid complete value: %s" @@ -3155,6 +3164,11 @@ msgstr "E363: le motif utilise plus de mmoire que 'maxmempattern'" msgid "E749: empty buffer" msgstr "E749: tampon vide" +#: ../buffer.c:1587 +#, c-format +msgid "E86: Buffer %<PRId64> does not exist" +msgstr "E86: Le tampon %<PRId64> n'existe pas" + #: ../globals.h:1108 msgid "E682: Invalid search pattern or delimiter" msgstr "E682: Dlimiteur ou motif de recherche invalide" @@ -4308,7 +4322,7 @@ msgid "" " to recover the changes (see \":help recovery\").\n" msgstr "" "\"\n" -" pour rcuprer le fichier (voir \":help recovery\").\n" +" pour rcuprer le fichier (consultez \":help recovery\").\n" #: ../memline.c:3250 msgid " If you did this already, delete the swap file \"" @@ -4805,6 +4819,11 @@ msgstr "E522: Introuvable dans termcap" msgid "E539: Illegal character <%s>" msgstr "E539: Caractre <%s> invalide" +#: ../option.c:2253 +#, c-format +msgid "For option %s" +msgstr "Pour l'option %s" + #: ../option.c:3862 msgid "E529: Cannot set 'term' to empty string" msgstr "E529: 'term' ne doit pas tre une chane vide" @@ -6779,9 +6798,6 @@ msgstr "E446: Aucun nom de fichier sous le curseur" #~ msgid "Reading from stdin..." #~ msgstr "Lecture de stdin..." -#~ msgid "[blowfish]" -#~ msgstr "[blowfish]" - #~ msgid "[crypted]" #~ msgstr "[chiffr]" @@ -6909,8 +6925,8 @@ msgstr "E446: Aucun nom de fichier sous le curseur" #~ msgstr "" #~ "Vim : Une requte \"die\" a t reue par le gestionnaire de session\n" -#~ msgid "Close" -#~ msgstr "Fermer" +#~ msgid "Close tab" +#~ msgstr "Fermer l'onglet" #~ msgid "New tab" #~ msgstr "Nouvel onglet" @@ -6968,13 +6984,6 @@ msgstr "E446: Aucun nom de fichier sous le curseur" #~ msgid "E672: Unable to open window inside MDI application" #~ msgstr "E672: Impossible d'ouvrir une fentre dans une application MDI" -# DB - Les quelques messages qui suivent se retrouvent aussi ici : -# gui_gtk_x11.c:3170 et suivants. -# Les libells changent un peu (majuscule par exemple). -# La VF tche de les unifier. -#~ msgid "Close tab" -#~ msgstr "Fermer l'onglet" - #~ msgid "Open tab..." #~ msgstr "Ouvrir dans un onglet..." @@ -7148,9 +7157,6 @@ msgstr "E446: Aucun nom de fichier sous le curseur" #~ msgid "E836: This Vim cannot execute :python after using :py3" #~ msgstr "E836: Vim ne peut pas excuter :python aprs avoir utilis :py3" -#~ msgid "only string keys are allowed" -#~ msgstr "seule une chaine est autorise comme cl" - #~ msgid "" #~ "E263: Sorry, this command is disabled, the Python library could not be " #~ "loaded." @@ -7684,12 +7690,6 @@ msgstr "E446: Aucun nom de fichier sous le curseur" #~ msgid "E338: Sorry, no file browser in console mode" #~ msgstr "E338: Dsol, pas de slecteur de fichiers en mode console" -#~ msgid "Vim: preserving files...\n" -#~ msgstr "Vim : prservation des fichiers...\n" - -#~ msgid "Vim: Finished.\n" -#~ msgstr "Vim : Fini.\n" - #~ msgid "ERROR: " #~ msgstr "ERREUR : " @@ -7718,6 +7718,10 @@ msgstr "E446: Aucun nom de fichier sous le curseur" #~ msgid "E547: Illegal mouseshape" #~ msgstr "E547: Forme de curseur invalide" +#~ msgid "Warning: Using a weak encryption method; see :help 'cm'" +#~ msgstr "" +#~ "Alerte : utilisation d'une mthode de chiffrage faible ; consultez :help 'cm'" + #~ msgid "Enter encryption key: " #~ msgstr "Tapez la cl de chiffrement : " @@ -7861,15 +7865,6 @@ msgstr "E446: Aucun nom de fichier sous le curseur" #~ msgid "E245: Illegal char '%c' in font name \"%s\"" #~ msgstr "E245: Caractre '%c' invalide dans le nom de fonte \"%s\"" -#~ msgid "Vim: Double signal, exiting\n" -#~ msgstr "Vim : Double signal, sortie\n" - -#~ msgid "Vim: Caught deadly signal %s\n" -#~ msgstr "Vim : Signal mortel %s intercept\n" - -#~ msgid "Vim: Caught deadly signal\n" -#~ msgstr "Vim : Signal mortel intercept\n" - #~ msgid "Opening the X display took %<PRId64> msec" #~ msgstr "L'ouverture du display X a pris %<PRId64> ms" @@ -7970,7 +7965,7 @@ msgstr "E446: Aucun nom de fichier sous le curseur" #~ msgstr "" #~ "VIMRUN.EXE est introuvable votre $PATH.\n" #~ "Les commandes externes ne feront pas de pause une fois termines.\n" -#~ "Voir :help win32-vimrun pour plus d'informations." +#~ "Consultez :help win32-vimrun pour plus d'informations." #~ msgid "Vim Warning" #~ msgstr "Alerte Vim" @@ -7982,11 +7977,6 @@ msgstr "E446: Aucun nom de fichier sous le curseur" #~ msgstr "" #~ "E868: Erreur lors de la construction du NFA avec classe d'quivalence" -#~ msgid "E999: (NFA regexp internal error) Should not process NOT node !" -#~ msgstr "" -#~ "E999: (erreur interne du regexp NFA) Un noeud 'NOT' ne devrait pas tre " -#~ "trait !" - #~ msgid "E878: (NFA) Could not allocate memory for branch traversal!" #~ msgstr "" #~ "E878: (NFA) Impossible d'allouer la mmoire pour parcourir les branches!" @@ -8306,30 +8296,18 @@ msgstr "E446: Aucun nom de fichier sous le curseur" #~ msgid "can't delete OutputObject attributes" #~ msgstr "impossible d'effacer les attributs d'OutputObject" -#~ msgid "softspace must be an integer" -#~ msgstr "softspace doit tre un nombre entier" - #~ msgid "invalid attribute" #~ msgstr "attribut invalide" -#~ msgid "writelines() requires list of strings" -#~ msgstr "writelines() requiert une liste de chanes" - #~ msgid "E264: Python: Error initialising I/O objects" #~ msgstr "E264: Python : Erreur d'initialisation des objets d'E/S" #~ msgid "empty keys are not allowed" #~ msgstr "les cls vides ne sont pas autorises" -#~ msgid "Cannot delete DictionaryObject attributes" -#~ msgstr "Impossible d'effacer les attributs de DictionaryObject" - #~ msgid "Cannot modify fixed dictionary" #~ msgstr "Impossible de modifier un dictionnaire fixe" -#~ msgid "Cannot set this attribute" -#~ msgstr "Impossible d'initialiser cet attribut" - #~ msgid "dict is locked" #~ msgstr "dictionnaire est verrouill" @@ -8348,15 +8326,9 @@ msgstr "E446: Aucun nom de fichier sous le curseur" #~ msgid "Failed to add item to list" #~ msgstr "Ajout la liste a chou" -#~ msgid "can only assign lists to slice" -#~ msgstr "seules des tranches peuvent tre assignes aux listes" - #~ msgid "internal error: failed to add item to list" #~ msgstr "erreur interne : ajout d'lment la liste a chou" -#~ msgid "can only concatenate with lists" -#~ msgstr "on ne peut que concatner avec des listes" - #~ msgid "cannot delete vim.dictionary attributes" #~ msgstr "impossible d'effacer les attributs de vim.dictionary" @@ -8366,9 +8338,6 @@ msgstr "E446: Aucun nom de fichier sous le curseur" #~ msgid "cannot set this attribute" #~ msgstr "impossible d'initialiser cet attribut" -#~ msgid "'self' argument must be a dictionary" -#~ msgstr "l'argument 'self' doit tre un dictionnaire" - #~ msgid "failed to run function" #~ msgstr "excution de la fonction a chou" @@ -8378,24 +8347,9 @@ msgstr "E446: Aucun nom de fichier sous le curseur" #~ msgid "unable to unset option without global value" #~ msgstr "impossible de dsactiver une option sans une valeur globale" -#~ msgid "object must be integer" -#~ msgstr "objet doit tre un nombre entier" - -#~ msgid "object must be string" -#~ msgstr "objet doit tre de type string" - #~ msgid "attempt to refer to deleted tab page" #~ msgstr "tentative de rfrencer un onglet effac" -#~ msgid "<tabpage object (deleted) at %p>" -#~ msgstr "<objet onglet (effac) %p>" - -#~ msgid "<tabpage object (unknown) at %p>" -#~ msgstr "<objet onglet (inconnu) %p>" - -#~ msgid "<tabpage %d>" -#~ msgstr "<onglet %d>" - #~ msgid "no such tab page" #~ msgstr "cet onglet n'existe pas" @@ -8408,27 +8362,12 @@ msgstr "E446: Aucun nom de fichier sous le curseur" #~ msgid "cursor position outside buffer" #~ msgstr "curseur positionn en dehors du tampon" -#~ msgid "<window object (deleted) at %p>" -#~ msgstr "<objet fentre (effac) %p>" - -#~ msgid "<window object (unknown) at %p>" -#~ msgstr "<objet fentre (inconnu) %p>" - -#~ msgid "<window %d>" -#~ msgstr "<fentre %d>" - #~ msgid "no such window" #~ msgstr "Cette fentre n'existe pas" #~ msgid "attempt to refer to deleted buffer" #~ msgstr "tentative de rfrencer un tampon effac" -#~ msgid "<buffer object (deleted) at %p>" -#~ msgstr "<objet tampon (effac) %p>" - -#~ msgid "key must be integer" -#~ msgstr "la cl doit tre un nombre entier" - #~ msgid "expected vim.buffer object" #~ msgstr "objet vim.buffer attendu" @@ -8467,18 +8406,3 @@ msgstr "E446: Aucun nom de fichier sous le curseur" #~ msgid "internal error: invalid value type" #~ msgstr "erreur interne : type de valeur invalide" - -#~ msgid "E860: Eval did not return a valid python 3 object" -#~ msgstr "E860: Eval n'a pas retourn un object python 3 valid" - -#~ msgid "E861: Failed to convert returned python 3 object to vim value" -#~ msgstr "E861: Conversion d'objet python 3 une valeur de vim a chou" - -#~ msgid "E863: return value must be an instance of str" -#~ msgstr "E863: valeur de retour doit tre une instance de Str" - -#~ msgid "Only boolean objects are allowed" -#~ msgstr "Seuls les objets boolens sont autoriss" - -#~ msgid "no such key in dictionary" -#~ msgstr "cette cl est inexistante dans le dictionnaire" diff --git a/src/nvim/po/it.po b/src/nvim/po/it.po index 729697eee3..171e155689 100644 --- a/src/nvim/po/it.po +++ b/src/nvim/po/it.po @@ -11,10 +11,10 @@ # msgid "" msgstr "" -"Project-Id-Version: vim 7.4b\n" +"Project-Id-Version: vim 7.4\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2014-05-26 14:21+0200\n" -"PO-Revision-Date: 2013-08-03 17:14+0200\n" +"POT-Creation-Date: 2015-08-11 20:58+0200\n" +"PO-Revision-Date: 2015-08-11 22:02+0200\n" "Last-Translator: Vlad Sandrini <vlad.gently@gmail.com>\n" "Language-Team: Italian Antonio Colombo <azc100@gmail." "com> Vlad Sandrini <vlad.gently@gmail." @@ -104,11 +104,6 @@ msgstr "E84: Nessun buffer risulta modificato" msgid "E85: There is no listed buffer" msgstr "E85: Non c' alcun buffer elencato" -#: ../buffer.c:913 -#, c-format -msgid "E86: Buffer %<PRId64> does not exist" -msgstr "E86: Non esiste il buffer %<PRId64>" - #: ../buffer.c:915 msgid "E87: Cannot go beyond last buffer" msgstr "E87: Non posso oltrepassare l'ultimo buffer" @@ -128,7 +123,7 @@ msgstr "" #. wrap around (may cause duplicates) #: ../buffer.c:1423 msgid "W14: Warning: List of file names overflow" -msgstr "W14: Attenzione: Superato limite della lista dei nomi di file" +msgstr "W14: Avviso: Superato limite della lista dei nomi di file" #: ../buffer.c:1555 ../quickfix.c:3361 #, c-format @@ -148,7 +143,7 @@ msgstr "E94: Nessun buffer corrispondente a %s" #: ../buffer.c:2161 #, c-format msgid "line %<PRId64>" -msgstr "linea %<PRId64>" +msgstr "riga %<PRId64>" #: ../buffer.c:2233 msgid "E95: Buffer with this name already exists" @@ -181,17 +176,17 @@ msgstr "[in sola lettura]" #: ../buffer.c:2524 #, c-format msgid "1 line --%d%%--" -msgstr "1 linea --%d%%--" +msgstr "1 riga --%d%%--" #: ../buffer.c:2526 #, c-format msgid "%<PRId64> lines --%d%%--" -msgstr "%<PRId64> linee --%d%%--" +msgstr "%<PRId64> righe --%d%%--" #: ../buffer.c:2530 #, c-format msgid "line %<PRId64> of %<PRId64> --%d%%-- col " -msgstr "linea %<PRId64> di %<PRId64> --%d%%-- col " +msgstr "riga %<PRId64> di %<PRId64> --%d%%-- col " #: ../buffer.c:2632 ../buffer.c:4292 ../memline.c:1554 msgid "[No Name]" @@ -250,7 +245,7 @@ msgstr "Segni per %s:" #: ../buffer.c:4543 #, c-format msgid " line=%<PRId64> id=%d name=%s" -msgstr " linea=%<PRId64> id=%d, nome=%s" +msgstr " riga=%<PRId64> id=%d, nome=%s" #: ../cursor_shape.c:68 msgid "E545: Missing colon" @@ -346,11 +341,11 @@ msgstr " modalit ^X (^]^D^E^F^I^K^L^N^O^Ps^U^V^Y)" #: ../edit.c:85 msgid " Whole line completion (^L^N^P)" -msgstr " Completamento Linea Intera (^L^N^P)" +msgstr " Completamento riga intera (^L^N^P)" #: ../edit.c:86 msgid " File name completion (^F^N^P)" -msgstr " Completamento nomi File (^F^N^P)" +msgstr " Completamento nomi file (^F^N^P)" #: ../edit.c:87 msgid " Tag completion (^]^N^P)" @@ -374,7 +369,7 @@ msgstr " Completamento Thesaurus (^T^N^P)" #: ../edit.c:93 msgid " Command-line completion (^V^N^P)" -msgstr " Completamento linea comandi (^V^N^P)" +msgstr " Completamento riga comandi (^V^N^P)" #: ../edit.c:94 msgid " User defined completion (^U^N^P)" @@ -452,7 +447,7 @@ msgstr "Ritorno all'originale" #: ../edit.c:4621 msgid "Word from other line" -msgstr "Parola da un'altra linea" +msgstr "Parola da un'altra riga" #: ../edit.c:4624 msgid "The only match" @@ -680,6 +675,11 @@ msgstr "E696: Manca virgola nella Lista: %s" msgid "E697: Missing end of List ']': %s" msgstr "E697: Manca ']' a fine Lista: %s" +#: ../eval.c:5750 +#, c-format +msgid "Not enough memory to set references, garbage collection aborted!" +msgstr "Memoria insufficiente per impostarlo, recupero memoria fallito!" + #: ../eval.c:6475 #, c-format msgid "E720: Missing colon in Dictionary: %s" @@ -754,15 +754,15 @@ msgstr "E785: complete() pu essere usata solo in modalit inserimento" msgid "&Ok" msgstr "&OK" -#: ../eval.c:8676 -#, c-format -msgid "E737: Key already exists: %s" -msgstr "E737: Chiave gi esistente: %s" - #: ../eval.c:8692 msgid "extend() argument" msgstr "argomento di extend()" +#: ../eval.c:9345 +#, c-format +msgid "E737: Key already exists: %s" +msgstr "E737: Chiave gi esistente: %s" + #: ../eval.c:8915 msgid "map() argument" msgstr "argomento di map()" @@ -774,7 +774,7 @@ msgstr "argomento di filter()" #: ../eval.c:9229 #, c-format msgid "+-%s%3ld lines: " -msgstr "+-%s%3ld linee: " +msgstr "+-%s%3ld righe: " #: ../eval.c:9291 #, c-format @@ -1043,21 +1043,21 @@ msgstr "> %d, Esa %08x, Ottale %o" #: ../ex_cmds.c:684 msgid "E134: Move lines into themselves" -msgstr "E134: Movimento di linee verso se stesse" +msgstr "E134: Movimento di righe verso se stesse" #: ../ex_cmds.c:747 msgid "1 line moved" -msgstr "1 linea mossa" +msgstr "1 riga mossa" #: ../ex_cmds.c:749 #, c-format msgid "%<PRId64> lines moved" -msgstr "%<PRId64> linee mosse" +msgstr "%<PRId64> righe mosse" #: ../ex_cmds.c:1175 #, c-format msgid "%<PRId64> lines filtered" -msgstr "%<PRId64> linee filtrate" +msgstr "%<PRId64> righe filtrate" #: ../ex_cmds.c:1194 msgid "E135: *Filter* Autocommands must not change current buffer" @@ -1070,7 +1070,7 @@ msgstr "[Non salvato dopo l'ultima modifica]\n" #: ../ex_cmds.c:1424 #, c-format msgid "%sviminfo: %s in line: " -msgstr "%sviminfo: %s nella linea: " +msgstr "%sviminfo: %s nella riga: " #: ../ex_cmds.c:1431 msgid "E136: viminfo: Too many errors, skipping rest of file" @@ -1239,12 +1239,12 @@ msgstr "%<PRId64> sostituzioni" #: ../ex_cmds.c:4392 msgid " on 1 line" -msgstr " in 1 linea" +msgstr " in 1 riga" #: ../ex_cmds.c:4395 #, c-format msgid " on %<PRId64> lines" -msgstr " in %<PRId64> linee" +msgstr " in %<PRId64> righe" #: ../ex_cmds.c:4438 msgid "E147: Cannot do :global recursive" @@ -1257,7 +1257,7 @@ msgstr "E148: Manca espressione regolare nel comando 'global'" #: ../ex_cmds.c:4508 #, c-format msgid "Pattern found in every line: %s" -msgstr "Espressione trovata su ogni linea: %s" +msgstr "Espressione trovata su ogni riga: %s" #: ../ex_cmds.c:4510 #, c-format @@ -1355,6 +1355,11 @@ msgstr "E158: Nome buffer non valido: %s" msgid "E157: Invalid sign ID: %<PRId64>" msgstr "E157: ID 'sign' non valido: %<PRId64>" +#: ../ex_cmds.c:5517 +#, c-format +msgid "E885: Not possible to change sign %s" +msgstr "E885: Impossibile cambiare segno %s" + #: ../ex_cmds.c:6066 msgid " (not supported)" msgstr " (non supportata)" @@ -1370,7 +1375,7 @@ msgstr "Entro modalit Debug. Batti \"cont\" per continuare." #: ../ex_cmds2.c:143 ../ex_docmd.c:759 #, c-format msgid "line %<PRId64>: %s" -msgstr "linea %<PRId64>: %s" +msgstr "riga %<PRId64>: %s" #: ../ex_cmds2.c:145 #, c-format @@ -1380,7 +1385,7 @@ msgstr "com: %s" #: ../ex_cmds2.c:322 #, c-format msgid "Breakpoint in \"%s%s\" line %<PRId64>" -msgstr "Pausa in \"%s%s\" linea %<PRId64>" +msgstr "Pausa in \"%s%s\" riga %<PRId64>" #: ../ex_cmds2.c:581 #, c-format @@ -1394,7 +1399,7 @@ msgstr "Nessun 'breakpoint' definito" #: ../ex_cmds2.c:617 #, c-format msgid "%3d %s %s line %<PRId64>" -msgstr "%3d %s %s linea %<PRId64>" +msgstr "%3d %s %s riga %<PRId64>" #: ../ex_cmds2.c:942 msgid "E750: First use \":profile start {fname}\"" @@ -1417,7 +1422,7 @@ msgstr "E162: Buffer \"%s\" non salvato dopo modifica" #: ../ex_cmds2.c:1480 msgid "Warning: Entered other buffer unexpectedly (check autocommands)" msgstr "" -"Attenzione: Entrato in altro buffer inaspettatamente (controllare " +"Avviso: Entrato in altro buffer inaspettatamente (controllare " "autocomandi)" #: ../ex_cmds2.c:1826 @@ -1465,7 +1470,7 @@ msgstr "non riesco ad eseguire \"%s\"" #: ../ex_cmds2.c:2520 #, c-format msgid "line %<PRId64>: could not source \"%s\"" -msgstr "linea %<PRId64>: non riesco ad eseguire \"%s\"" +msgstr "riga %<PRId64>: non riesco ad eseguire \"%s\"" #: ../ex_cmds2.c:2535 #, c-format @@ -1475,7 +1480,7 @@ msgstr "eseguo \"%s\"" #: ../ex_cmds2.c:2537 #, c-format msgid "line %<PRId64>: sourcing \"%s\"" -msgstr "linea %<PRId64>: eseguo \"%s\"" +msgstr "riga %<PRId64>: eseguo \"%s\"" #: ../ex_cmds2.c:2693 #, c-format @@ -1504,7 +1509,7 @@ msgstr "gestore di errore" #: ../ex_cmds2.c:3020 msgid "W15: Warning: Wrong line separator, ^M may be missing" -msgstr "W15: Attenzione: Separatore di linea errato, forse manca ^M" +msgstr "W15: Avviso: Separatore di riga errato, forse manca ^M" #: ../ex_cmds2.c:3139 msgid "E167: :scriptencoding used outside of a sourced file" @@ -1606,10 +1611,10 @@ msgstr "E174: Il comando esiste gi: aggiungi ! per sostituirlo" #: ../ex_docmd.c:4432 msgid "" "\n" -" Name Args Range Complete Definition" +" Name Args Address Complete Definition" msgstr "" "\n" -" Nome Arg. Inter Completo Definizione" +" Nome Arg. Indir. Completo Definizione" #: ../ex_docmd.c:4516 msgid "No user-defined commands found" @@ -1635,6 +1640,10 @@ msgstr "E178: Valore predefinito del contatore non valido" msgid "E179: argument required for -complete" msgstr "E179: argomento necessario per -complete" +#: ../ex_docmd.c:4923 +msgid "E179: argument required for -addr" +msgstr "E179: argomento necessario per -addr" + #: ../ex_docmd.c:4635 #, c-format msgid "E181: Invalid attribute: %s" @@ -1658,6 +1667,11 @@ msgstr "E841: Nome riservato, non usabile in un comando definito dall'utente" msgid "E184: No such user-defined command: %s" msgstr "E184: Comando definito dall'utente %s inesistente" +#: ../ex_docmd.c:5516 +#, c-format +msgid "E180: Invalid address type value: %s" +msgstr "E180: Tipo di indirizzo non valido: %s" + #: ../ex_docmd.c:5219 #, c-format msgid "E180: Invalid complete value: %s" @@ -1666,7 +1680,7 @@ msgstr "E180: Valore %s non valido per 'complete'" #: ../ex_docmd.c:5225 msgid "E468: Completion argument only allowed for custom completion" msgstr "" -"E468: Argomento di completamento permesso solo per completamento " +"E468: Argomento di completamento consentito solo per completamento " "personalizzato" #: ../ex_docmd.c:5231 @@ -1815,7 +1829,7 @@ msgstr "Eccezione scartata: %s" #: ../ex_eval.c:588 ../ex_eval.c:634 #, c-format msgid "%s, line %<PRId64>" -msgstr "%s, linea %<PRId64>" +msgstr "%s, riga %<PRId64>" #. always scroll up, don't overwrite #: ../ex_eval.c:608 @@ -1961,7 +1975,7 @@ msgstr "" #: ../ex_getln.c:5047 msgid "Command Line" -msgstr "Linea di Comando" +msgstr "Riga di Comando" #: ../ex_getln.c:5048 msgid "Search String" @@ -1973,7 +1987,7 @@ msgstr "Espressione" #: ../ex_getln.c:5050 msgid "Input Line" -msgstr "Linea di Input" +msgstr "Riga di Input" #: ../ex_getln.c:5117 msgid "E198: cmd_pchar beyond the command length" @@ -2091,7 +2105,7 @@ msgstr "[manca CR]" #: ../fileio.c:1819 msgid "[long lines split]" -msgstr "[linee lunghe divise]" +msgstr "[righe lunghe divise]" #: ../fileio.c:1823 ../fileio.c:3512 msgid "[NOT converted]" @@ -2104,12 +2118,12 @@ msgstr "[convertito]" #: ../fileio.c:1831 #, c-format msgid "[CONVERSION ERROR in line %<PRId64>]" -msgstr "[ERRORE DI CONVERSIONE alla linea %<PRId64>]" +msgstr "[ERRORE DI CONVERSIONE alla riga %<PRId64>]" #: ../fileio.c:1835 #, c-format msgid "[ILLEGAL BYTE in line %<PRId64>]" -msgstr "[BYTE NON VALIDO alla linea %<PRId64>]" +msgstr "[BYTE NON VALIDO alla riga %<PRId64>]" #: ../fileio.c:1838 msgid "[READ ERRORS]" @@ -2137,7 +2151,7 @@ msgstr "E203: Buffer in scrittura cancellato o scaricato dagli autocomandi" #: ../fileio.c:2486 msgid "E204: Autocommand changed number of lines in unexpected way" -msgstr "E204: L'autocomando ha modificato numero linee in maniera imprevista" +msgstr "E204: L'autocomando ha modificato numero righe in maniera imprevista" #: ../fileio.c:2548 ../fileio.c:2565 msgid "is not a file or writable device" @@ -2213,7 +2227,7 @@ msgid "" "E513: write error, conversion failed in line %<PRId64> (make 'fenc' empty to " "override)" msgstr "" -"E513: errore in scrittura, conversione fallita alla linea %<PRId64> (rendere " +"E513: errore in scrittura, conversione fallita alla riga %<PRId64> (rendere " "'fenc' nullo per eseguire comunque)" #: ../fileio.c:3448 @@ -2227,7 +2241,7 @@ msgstr " ERRORE DI CONVERSIONE" #: ../fileio.c:3509 #, c-format msgid " in line %<PRId64>;" -msgstr " alla linea %<PRId64>;" +msgstr " alla riga %<PRId64>;" #: ../fileio.c:3519 msgid "[Device]" @@ -2271,7 +2285,7 @@ msgid "" "WARNING: Original file may be lost or damaged\n" msgstr "" "\n" -"ATTENZIONE: Il file originale pu essere perso o danneggiato\n" +"AVVISO: Il file originale pu essere perso o danneggiato\n" #: ../fileio.c:3675 msgid "don't quit the editor until the file is successfully written!" @@ -2303,12 +2317,12 @@ msgstr "[in formato UNIX]" #: ../fileio.c:3831 msgid "1 line, " -msgstr "1 linea, " +msgstr "1 riga, " #: ../fileio.c:3833 #, c-format msgid "%<PRId64> lines, " -msgstr "%<PRId64> linee," +msgstr "%<PRId64> righe," #: ../fileio.c:3836 msgid "1 character" @@ -2325,14 +2339,14 @@ msgstr "[noeol]" #: ../fileio.c:3849 msgid "[Incomplete last line]" -msgstr "[Manca carattere di fine linea]" +msgstr "[Manca carattere di fine riga]" #. don't overwrite messages here #. must give this prompt #. don't use emsg() here, don't want to flush the buffers #: ../fileio.c:3865 msgid "WARNING: The file has been changed since reading it!!!" -msgstr "ATTENZIONE: File modificato dopo essere stato letto dall'Editor!!!" +msgstr "AVVISO: File modificato dopo essere stato letto dall'Editor!!!" #: ../fileio.c:3867 msgid "Do you really want to write to it" @@ -2368,7 +2382,7 @@ msgid "" "W12: Warning: File \"%s\" has changed and the buffer was changed in Vim as " "well" msgstr "" -"W12: Attenzione: File \"%s\" modificato su disco ed anche nel buffer di Vim" +"W12: Avviso: File \"%s\" modificato su disco ed anche nel buffer di Vim" #: ../fileio.c:4907 msgid "See \":help W12\" for more info." @@ -2377,7 +2391,7 @@ msgstr "Vedere \":help W12\" per ulteriori informazioni." #: ../fileio.c:4910 #, c-format msgid "W11: Warning: File \"%s\" has changed since editing started" -msgstr "W11: Attenzione: File \"%s\" modificato dopo l'apertura" +msgstr "W11: Avviso: File \"%s\" modificato dopo l'apertura" #: ../fileio.c:4911 msgid "See \":help W11\" for more info." @@ -2386,7 +2400,7 @@ msgstr "Vedere \":help W11\" per ulteriori informazioni." #: ../fileio.c:4914 #, c-format msgid "W16: Warning: Mode of file \"%s\" has changed since editing started" -msgstr "W16: Attenzione: Modo File \"%s\" modificato dopo l'apertura" +msgstr "W16: Avviso: Modo File \"%s\" modificato dopo l'apertura" #: ../fileio.c:4915 msgid "See \":help W16\" for more info." @@ -2395,11 +2409,11 @@ msgstr "Vedere \":help W16\" per ulteriori informazioni." #: ../fileio.c:4927 #, c-format msgid "W13: Warning: File \"%s\" has been created after editing started" -msgstr "W13: Attenzione: Il file \"%s\" risulta creato dopo l'apertura" +msgstr "W13: Avviso: Il file \"%s\" risulta creato dopo l'apertura" #: ../fileio.c:4947 msgid "Warning" -msgstr "Attenzione" +msgstr "Avviso" #: ../fileio.c:4948 msgid "" @@ -2513,7 +2527,7 @@ msgstr "E351: Non posso cancellare piegatura con il 'foldmethod' in uso" #: ../fold.c:1784 #, c-format msgid "+--%3ld lines folded " -msgstr "+--%3ld linee piegate" +msgstr "+--%3ld righe piegate" #. buffer has already been read #: ../getchar.c:273 @@ -2679,7 +2693,7 @@ msgstr "E364: Chiamata a libreria fallita per \"%s()\"" #: ../globals.h:1026 msgid "E19: Mark has invalid line number" -msgstr "E19: 'Mark' con numero linea non valido" +msgstr "E19: 'Mark' con numero riga non valido" #: ../globals.h:1027 msgid "E20: Mark not set" @@ -2720,7 +2734,7 @@ msgstr "E29: Ancora nessun testo inserito" #: ../globals.h:1038 msgid "E30: No previous command line" -msgstr "E30: Nessuna linea comandi precedente" +msgstr "E30: Nessuna riga comandi precedente" #: ../globals.h:1039 msgid "E31: No such mapping" @@ -2947,6 +2961,11 @@ msgstr "E363: l'espressione usa troppa memoria rispetto a 'maxmempattern'" msgid "E749: empty buffer" msgstr "E749: buffer vuoto" +#: ../globals.h:1226 +#, c-format +msgid "E86: Buffer %<PRId64> does not exist" +msgstr "E86: Non esiste il buffer %<PRId64>" + #: ../globals.h:1108 msgid "E682: Invalid search pattern or delimiter" msgstr "E682: Espressione o delimitatore di ricerca non validi" @@ -3260,11 +3279,11 @@ msgid "" " # line" msgstr "" "\n" -" # linea" +" # riga" #: ../if_cscope.c:1713 msgid "filename / context / line\n" -msgstr "nomefile / contest / linea\n" +msgstr "nomefile / contest / riga\n" #: ../if_cscope.c:1809 #, c-format @@ -3326,16 +3345,16 @@ msgstr "Non posso aprire come script output: \"" #: ../main.c:1622 msgid "Vim: Warning: Output is not to a terminal\n" -msgstr "Vim: Attenzione: Output non diretto a un terminale\n" +msgstr "Vim: Avviso: Output non diretto a un terminale\n" #: ../main.c:1624 msgid "Vim: Warning: Input is not from a terminal\n" -msgstr "Vim: Attenzione: Input non proveniente da un terminale\n" +msgstr "Vim: Avviso: Input non proveniente da un terminale\n" #. just in case.. #: ../main.c:1891 msgid "pre-vimrc command line" -msgstr "linea comandi prima di vimrc" +msgstr "riga comandi prima di vimrc" #: ../main.c:1964 #, c-format @@ -3528,7 +3547,7 @@ msgstr "+\t\t\tPosizionati alla fine del file" #: ../main.c:2231 msgid "+<lnum>\t\tStart at line <lnum>" -msgstr "+<lnum>\t\tPosizionati alla linea <lnum>" +msgstr "+<lnum>\t\tPosizionati alla riga <lnum>" #: ../main.c:2232 msgid "--cmd <command>\tExecute <command> before loading any vimrc file" @@ -3589,7 +3608,7 @@ msgid "" "mark line col file/text" msgstr "" "\n" -"mark linea col.file/testo" +"mark riga col.file/testo" #. Highlight title #: ../mark.c:789 @@ -3598,7 +3617,7 @@ msgid "" " jump line col file/text" msgstr "" "\n" -" salt.linea col.file/testo" +" salt.riga col.file/testo" #. Highlight title #: ../mark.c:831 @@ -3607,7 +3626,7 @@ msgid "" "change line col text" msgstr "" "\n" -"modif linea col testo" +"modif riga col testo" #: ../mark.c:1238 msgid "" @@ -3767,7 +3786,7 @@ msgstr "File originale \"%s\"" #: ../memline.c:995 msgid "E308: Warning: Original file may have been changed" msgstr "" -"E308: Attenzione: il file originale pu essere stato modificato nel frattempo" +"E308: Avviso: il file originale pu essere stato modificato nel frattempo" #: ../memline.c:1061 #, c-format @@ -3776,7 +3795,7 @@ msgstr "E309: Impossibile leggere blocco 1 da %s" #: ../memline.c:1065 msgid "???MANY LINES MISSING" -msgstr "???MOLTE LINEE MANCANTI" +msgstr "???MOLTE RIGHE MANCANTI" #: ../memline.c:1076 msgid "???LINE COUNT WRONG" @@ -3788,7 +3807,7 @@ msgstr "???BLOCCO VUOTO" #: ../memline.c:1103 msgid "???LINES MISSING" -msgstr "???LINEE MANCANTI" +msgstr "???RIGHE MANCANTI" #: ../memline.c:1128 #, c-format @@ -3801,12 +3820,12 @@ msgstr "???BLOCCO MANCANTE" #: ../memline.c:1147 msgid "??? from here until ???END lines may be messed up" -msgstr "??? da qui fino a ???END le linee possono essere fuori ordine" +msgstr "??? da qui fino a ???END le righe possono essere fuori ordine" #: ../memline.c:1164 msgid "??? from here until ???END lines may have been inserted/deleted" msgstr "" -"??? da qui fino a ???END linee possono essere state inserite/cancellate" +"??? da qui fino a ???END righe possono essere state inserite/cancellate" #: ../memline.c:1181 msgid "???END" @@ -3819,7 +3838,7 @@ msgstr "E311: Recupero Interrotto" #: ../memline.c:1243 msgid "" "E312: Errors detected while recovering; look for lines starting with ???" -msgstr "E312: Errori durante recupero; controlla linee che iniziano con ???" +msgstr "E312: Errori durante recupero; controlla righe che iniziano con ???" #: ../memline.c:1245 msgid "See \":help E312\" for more information." @@ -3980,12 +3999,12 @@ msgstr "E314: Preservazione fallita" #: ../memline.c:1819 #, c-format msgid "E315: ml_get: invalid lnum: %<PRId64>" -msgstr "E315: ml_get: numero linea non valido: %<PRId64>" +msgstr "E315: ml_get: numero riga non valido: %<PRId64>" #: ../memline.c:1851 #, c-format msgid "E316: ml_get: cannot find line %<PRId64>" -msgstr "E316: ml_get: non riesco a trovare la linea %<PRId64>" +msgstr "E316: ml_get: non riesco a trovare la riga %<PRId64>" #: ../memline.c:2236 msgid "E317: pointer block id wrong 3" @@ -4010,7 +4029,7 @@ msgstr "cancellato blocco 1?" #: ../memline.c:2707 #, c-format msgid "E320: Cannot find line %<PRId64>" -msgstr "E320: Non riesco a trovare la linea %<PRId64>" +msgstr "E320: Non riesco a trovare la riga %<PRId64>" #: ../memline.c:2916 msgid "E317: pointer block id wrong" @@ -4023,12 +4042,12 @@ msgstr "pe_line_count a zero" #: ../memline.c:2955 #, c-format msgid "E322: line number out of range: %<PRId64> past the end" -msgstr "E322: numero linea non ammissibile: %<PRId64> dopo la fine" +msgstr "E322: numero riga non ammissibile: %<PRId64> dopo la fine" #: ../memline.c:2959 #, c-format msgid "E323: line count wrong in block %<PRId64>" -msgstr "E323: contatore linee errato nel blocco %<PRId64>" +msgstr "E323: contatore righe errato nel blocco %<PRId64>" #: ../memline.c:2999 msgid "Stack size increases" @@ -4242,7 +4261,7 @@ msgstr "Errore/i eseguendo %s:" #: ../message.c:445 #, c-format msgid "line %4ld:" -msgstr "linea %4ld:" +msgstr "riga %4ld:" #: ../message.c:617 #, c-format @@ -4264,7 +4283,7 @@ msgstr "Premi INVIO o un comando per proseguire" #: ../message.c:1843 #, c-format msgid "%s line %<PRId64>" -msgstr "%s linea %<PRId64>" +msgstr "%s riga %<PRId64>" #: ../message.c:2392 msgid "-- More --" @@ -4272,7 +4291,7 @@ msgstr "-- Ancora --" #: ../message.c:2398 msgid " SPACE/d/j: screen/page/line down, b/u/k: up, q: quit " -msgstr " SPAZIO/d/j: schermo/pagina/linea gi, b/u/k: su, q: abbandona " +msgstr " SPAZIO/d/j: schermo/pagina/riga gi, b/u/k: su, q: abbandona " #: ../message.c:3021 ../message.c:3031 msgid "Question" @@ -4324,7 +4343,7 @@ msgstr "E767: Troppi argomenti per printf()" #: ../misc1.c:2256 msgid "W10: Warning: Changing a readonly file" -msgstr "W10: Attenzione: Modifica a un file in sola-lettura" +msgstr "W10: Avviso: Modifica a un file in sola-lettura" #: ../misc1.c:2537 msgid "Type number and <Enter> or click with mouse (empty cancels): " @@ -4337,21 +4356,21 @@ msgstr "Inserire numero e <Invio> (vuoto per annullare): " #: ../misc1.c:2585 msgid "1 more line" -msgstr "1 linea in pi" +msgstr "1 riga in pi" #: ../misc1.c:2588 msgid "1 line less" -msgstr "1 linea in meno" +msgstr "1 riga in meno" #: ../misc1.c:2593 #, c-format msgid "%<PRId64> more lines" -msgstr "%<PRId64> linee in pi" +msgstr "%<PRId64> righe in pi" #: ../misc1.c:2596 #, c-format msgid "%<PRId64> fewer lines" -msgstr "%<PRId64> linee in meno" +msgstr "%<PRId64> righe in meno" #: ../misc1.c:2599 msgid " (Interrupted)" @@ -4376,7 +4395,7 @@ msgstr "E774: opzione 'operatorfunc' non impostata" #: ../normal.c:2637 msgid "Warning: terminal cannot highlight" -msgstr "Attenzione: il terminale non in grado di evidenziare" +msgstr "Avviso: il terminale non in grado di evidenziare" #: ../normal.c:2807 msgid "E348: No string under cursor" @@ -4405,36 +4424,36 @@ msgstr "Batti :quit<Invio> per uscire da Vim" #: ../ops.c:248 #, c-format msgid "1 line %sed 1 time" -msgstr "1 linea %sa 1 volta" +msgstr "1 riga %sa 1 volta" #: ../ops.c:250 #, c-format msgid "1 line %sed %d times" -msgstr "1 linea %sa %d volte" +msgstr "1 riga %sa %d volte" #: ../ops.c:253 #, c-format msgid "%<PRId64> lines %sed 1 time" -msgstr "%<PRId64> linee %se 1 volta" +msgstr "%<PRId64> righe %se 1 volta" #: ../ops.c:256 #, c-format msgid "%<PRId64> lines %sed %d times" -msgstr "%<PRId64> linee %se %d volte" +msgstr "%<PRId64> righe %se %d volte" #: ../ops.c:592 #, c-format msgid "%<PRId64> lines to indent... " -msgstr "%<PRId64> linee da rientrare... " +msgstr "%<PRId64> righe da rientrare... " #: ../ops.c:634 msgid "1 line indented " -msgstr "1 linea rientrata " +msgstr "1 riga rientrata " #: ../ops.c:636 #, c-format msgid "%<PRId64> lines indented " -msgstr "%<PRId64> linee rientrate " +msgstr "%<PRId64> righe rientrate " #: ../ops.c:938 msgid "E748: No previously used register" @@ -4447,30 +4466,30 @@ msgstr "non riesco a salvare in un registro; cancello comunque" #: ../ops.c:1929 msgid "1 line changed" -msgstr "1 linea cambiata" +msgstr "1 riga cambiata" #: ../ops.c:1931 #, c-format msgid "%<PRId64> lines changed" -msgstr "%<PRId64> linee cambiate" +msgstr "%<PRId64> righe cambiate" #: ../ops.c:2521 msgid "block of 1 line yanked" -msgstr "blocco di 1 linea messo in registro" +msgstr "blocco di 1 riga messo in registro" #: ../ops.c:2523 msgid "1 line yanked" -msgstr "1 linea messa in registro" +msgstr "1 riga messa in registro" #: ../ops.c:2525 #, c-format msgid "block of %<PRId64> lines yanked" -msgstr "blocco di %<PRId64> linee messo in registro" +msgstr "blocco di %<PRId64> righe messo in registro" #: ../ops.c:2528 #, c-format msgid "%<PRId64> lines yanked" -msgstr "%<PRId64> linee messe in registro" +msgstr "%<PRId64> righe messe in registro" #: ../ops.c:2710 #, c-format @@ -4503,6 +4522,13 @@ msgstr "" msgid "E574: Unknown register type %d" msgstr "E574: Tipo di registro sconosciuto: %d" +#: ../ops.c:4897 +msgid "" +"E883: search pattern and expression register may not contain two or more " +"lines" +msgstr "E883: espressione di ricerca e registro dell'espressione non possono " +"contenere due o pi righe" + #: ../ops.c:5089 #, c-format msgid "%<PRId64> Cols; " @@ -4514,7 +4540,7 @@ msgid "" "Selected %s%<PRId64> of %<PRId64> Lines; %<PRId64> of %<PRId64> Words; " "%<PRId64> of %<PRId64> Bytes" msgstr "" -"Selezionate %s%<PRId64> di %<PRId64> Linee; %<PRId64> di %<PRId64> Parole; " +"Selezionate %s%<PRId64> di %<PRId64> Righe; %<PRId64> di %<PRId64> Parole; " "%<PRId64> di %<PRId64> Caratt." #: ../ops.c:5105 @@ -4523,7 +4549,7 @@ msgid "" "Selected %s%<PRId64> of %<PRId64> Lines; %<PRId64> of %<PRId64> Words; " "%<PRId64> of %<PRId64> Chars; %<PRId64> of %<PRId64> Bytes" msgstr "" -"Selezionate %s%<PRId64> di %<PRId64> Linee; %<PRId64> di %<PRId64> Parole; " +"Selezionate %s%<PRId64> di %<PRId64> Righe; %<PRId64> di %<PRId64> Parole; " "%<PRId64> di %<PRId64> Caratt.; %<PRId64> di %<PRId64> Byte" #: ../ops.c:5123 @@ -4532,7 +4558,7 @@ msgid "" "Col %s of %s; Line %<PRId64> of %<PRId64>; Word %<PRId64> of %<PRId64>; Byte " "%<PRId64> of %<PRId64>" msgstr "" -"Col. %s di %s; Linea %<PRId64> di %<PRId64>; Parola %<PRId64> di %<PRId64>; " +"Col. %s di %s; Riga %<PRId64> di %<PRId64>; Parola %<PRId64> di %<PRId64>; " "Caratt. %<PRId64> di %<PRId64>" #: ../ops.c:5133 @@ -4541,7 +4567,7 @@ msgid "" "Col %s of %s; Line %<PRId64> of %<PRId64>; Word %<PRId64> of %<PRId64>; Char " "%<PRId64> of %<PRId64>; Byte %<PRId64> of %<PRId64>" msgstr "" -"Col. %s di %s; Linea %<PRId64> di %<PRId64>; Parola %<PRId64> di %<PRId64>; " +"Col. %s di %s; Riga %<PRId64> di %<PRId64>; Parola %<PRId64> di %<PRId64>; " "Caratt. %<PRId64> di %<PRId64>; Byte %<PRId64> di %<PRId64>" #: ../ops.c:5146 @@ -4587,6 +4613,11 @@ msgstr "E522: Non trovato in 'termcap'" msgid "E539: Illegal character <%s>" msgstr "E539: Carattere non ammesso <%s>" +#: ../option.c:2253 +#, c-format +msgid "For option %s" +msgstr "Per opzione %s" + #: ../option.c:3862 msgid "E529: Cannot set 'term' to empty string" msgstr "E529: Non posso assegnare a 'term' il valore 'stringa nulla'" @@ -4665,7 +4696,7 @@ msgstr "W17: Arabo richiede UTF-8, esegui ':set encoding=utf-8'" #: ../option.c:5623 #, c-format msgid "E593: Need at least %d lines" -msgstr "E593: Servono almeno %d linee" +msgstr "E593: Servono almeno %d righe" #: ../option.c:5631 #, c-format @@ -4822,7 +4853,7 @@ msgstr "(%d di %d)%s%s: " #: ../quickfix.c:1676 msgid " (line deleted)" -msgstr " (linea cancellata)" +msgstr " (riga cancellata)" #: ../quickfix.c:1863 msgid "E380: At bottom of quickfix stack" @@ -4973,6 +5004,10 @@ msgstr "E554: Errore sintattico in %s{...}" msgid "External submatches:\n" msgstr "Sotto-corrispondenze esterne:\n" +#: ../regexp.c:2470 +msgid "E888: (NFA regexp) cannot repeat %s" +msgstr "E888: (NFA regexp) non riesco a ripetere %s" + #: ../regexp.c:7022 msgid "" "E864: \\%#= can only be followed by 0, 1, or 2. The automatic engine will be " @@ -4981,6 +5016,10 @@ msgstr "" "E864: \\%#= pu essere seguito solo da 0, 1 o 2. Sar usato il motore " "automatico " +#: ../regexp.c:7039 +msgid "Switching to backtracking RE engine for pattern: " +msgstr "Passo alla ricerca di RE col vecchio metodo: " + #: ../regexp_nfa.c:239 msgid "E865: (NFA) Regexp end encountered prematurely" msgstr "E865: (NFA) Fine prematura dell'espressione regolare" @@ -5113,7 +5152,7 @@ msgstr " VISUALE" #: ../screen.c:7470 msgid " VISUAL LINE" -msgstr " VISUALE LINEA" +msgstr " VISUALE RIGA" #: ../screen.c:7471 msgid " VISUAL BLOCK" @@ -5125,7 +5164,7 @@ msgstr " SELEZIONA" #: ../screen.c:7473 msgid " SELECT LINE" -msgstr " SELEZIONA LINEA" +msgstr " SELEZIONA RIGA" #: ../screen.c:7474 msgid " SELECT BLOCK" @@ -5191,7 +5230,7 @@ msgstr "Cerco nel file incluso: %s" #: ../search.c:4405 msgid "E387: Match is on current line" -msgstr "E387: Corrispondenza nella linea corrente" +msgstr "E387: Corrispondenza nella riga corrente" #: ../search.c:4517 msgid "All included files were found" @@ -5235,12 +5274,12 @@ msgstr "E758: File ortografico troncato" #: ../spell.c:953 #, c-format msgid "Trailing text in %s line %d: %s" -msgstr "Testo in eccesso in %s linea %d: %s" +msgstr "Testo in eccesso in %s riga %d: %s" #: ../spell.c:954 #, c-format msgid "Affix name too long in %s line %d: %s" -msgstr "Nome affisso troppo lungo in %s linea %d: %s" +msgstr "Nome affisso troppo lungo in %s riga %d: %s" #: ../spell.c:955 msgid "E761: Format error in affix file FOL, LOW or UPP" @@ -5261,7 +5300,7 @@ msgstr "E756: Controllo ortografico non abilitato" #: ../spell.c:2249 #, c-format msgid "Warning: Cannot find word list \"%s.%s.spl\" or \"%s.ascii.spl\"" -msgstr "Attenzione: Non trovo lista parole \"%s.%s.spl\" o \"%s.ascii.spl\"" +msgstr "Avviso: Non trovo lista parole \"%s.%s.spl\" o \"%s.ascii.spl\"" #: ../spell.c:2473 #, c-format @@ -5287,7 +5326,7 @@ msgstr "E770: Sezione non supportata nel file ortografico" #: ../spell.c:3762 #, c-format msgid "Warning: region %s not supported" -msgstr "Attenzione: regione %s non supportata" +msgstr "Avviso: regione %s non supportata" #: ../spell.c:4550 #, c-format @@ -5297,7 +5336,7 @@ msgstr "Lettura file affissi %s ..." #: ../spell.c:4589 ../spell.c:5635 ../spell.c:6140 #, c-format msgid "Conversion failure for word in %s line %d: %s" -msgstr "Conversione fallita per una parola in %s linea %d: %s" +msgstr "Conversione fallita per una parola in %s riga %d: %s" #: ../spell.c:4630 ../spell.c:6170 #, c-format @@ -5307,12 +5346,12 @@ msgstr "Conversione in %s non supportata: da %s a %s" #: ../spell.c:4642 #, c-format msgid "Invalid value for FLAG in %s line %d: %s" -msgstr "Valore di FLAG non valido in %s linea %d: %s" +msgstr "Valore di FLAG non valido in %s riga %d: %s" #: ../spell.c:4655 #, c-format msgid "FLAG after using flags in %s line %d: %s" -msgstr "FLAG dopo l'uso di flags in %s linea %d: %s" +msgstr "FLAG dopo l'uso di flags in %s riga %d: %s" #: ../spell.c:4723 #, c-format @@ -5321,7 +5360,7 @@ msgid "" "%d" msgstr "" "Definire COMPOUNDFORBIDFLAG dopo l'elemento PFX potrebbe dare risultati " -"errati in %s linea %d" +"errati in %s riga %d" #: ../spell.c:4731 #, c-format @@ -5330,43 +5369,43 @@ msgid "" "%d" msgstr "" "Definire COMPOUNDPERMITFLAG dopo l'elemento PFX potrebbe dare risultati " -"errati in %s linea %d" +"errati in %s riga %d" #: ../spell.c:4747 #, c-format msgid "Wrong COMPOUNDRULES value in %s line %d: %s" -msgstr "Valore errato per COMPOUNDRULES in %s linea %d: %s" +msgstr "Valore errato per COMPOUNDRULES in %s riga %d: %s" #: ../spell.c:4771 #, c-format msgid "Wrong COMPOUNDWORDMAX value in %s line %d: %s" -msgstr "Valore errato per COMPOUNDWORDMAX in %s linea %d: %s" +msgstr "Valore errato per COMPOUNDWORDMAX in %s riga %d: %s" #: ../spell.c:4777 #, c-format msgid "Wrong COMPOUNDMIN value in %s line %d: %s" -msgstr "Valore errato per COMPOUNDMIN in %s linea %d: %s" +msgstr "Valore errato per COMPOUNDMIN in %s riga %d: %s" #: ../spell.c:4783 #, c-format msgid "Wrong COMPOUNDSYLMAX value in %s line %d: %s" -msgstr "Valore errato per COMPOUNDSYLMAX in %s linea %d: %s" +msgstr "Valore errato per COMPOUNDSYLMAX in %s riga %d: %s" #: ../spell.c:4795 #, c-format msgid "Wrong CHECKCOMPOUNDPATTERN value in %s line %d: %s" -msgstr "Valore errato per CHECKCOMPOUNDPATTERN in %s linea %d: %s" +msgstr "Valore errato per CHECKCOMPOUNDPATTERN in %s riga %d: %s" #: ../spell.c:4847 #, c-format msgid "Different combining flag in continued affix block in %s line %d: %s" msgstr "" -"Flag combinazione diverso in blocco affissi continuo in %s linea %d: %s" +"Flag combinazione diverso in blocco affissi continuo in %s riga %d: %s" #: ../spell.c:4850 #, c-format msgid "Duplicate affix in %s line %d: %s" -msgstr "Affisso duplicato in %s linea %d: %s" +msgstr "Affisso duplicato in %s riga %d: %s" #: ../spell.c:4871 #, c-format @@ -5375,42 +5414,42 @@ msgid "" "line %d: %s" msgstr "" "Affisso usato anche per BAD/RARE/KEEPCASE/NEEDAFFIX/NEEDCOMPOUND/NOSUGGEST " -"in %s linea %d: %s" +"in %s riga %d: %s" #: ../spell.c:4893 #, c-format msgid "Expected Y or N in %s line %d: %s" -msgstr "Y o N deve essere presente in %s linea %d: %s" +msgstr "Y o N deve essere presente in %s riga %d: %s" #: ../spell.c:4968 #, c-format msgid "Broken condition in %s line %d: %s" -msgstr "Condizione non rispettata in %s linea %d: %s" +msgstr "Condizione non rispettata in %s riga %d: %s" #: ../spell.c:5091 #, c-format msgid "Expected REP(SAL) count in %s line %d" -msgstr "Contatore REP(SAL) necessario in %s linea %d" +msgstr "Contatore REP(SAL) necessario in %s riga %d" #: ../spell.c:5120 #, c-format msgid "Expected MAP count in %s line %d" -msgstr "Contatore MAP necessario in %s linea %d" +msgstr "Contatore MAP necessario in %s riga %d" #: ../spell.c:5132 #, c-format msgid "Duplicate character in MAP in %s line %d" -msgstr "Carattere duplicato in MAP in %s linea %d" +msgstr "Carattere duplicato in MAP in %s riga %d" #: ../spell.c:5176 #, c-format msgid "Unrecognized or duplicate item in %s line %d: %s" -msgstr "Elemento non riconosciuto o duplicato in %s linea %d: %s" +msgstr "Elemento non riconosciuto o duplicato in %s riga %d: %s" #: ../spell.c:5197 #, c-format msgid "Missing FOL/LOW/UPP line in %s" -msgstr "Linea FOL/LOW/UPP mancante in %s" +msgstr "Riga FOL/LOW/UPP mancante in %s" #: ../spell.c:5220 msgid "COMPOUNDSYLMAX used without SYLLABLE" @@ -5431,22 +5470,22 @@ msgstr "Troppi suffissi e/o flag composti" #: ../spell.c:5250 #, c-format msgid "Missing SOFO%s line in %s" -msgstr "Linea SOFO%s mancante in %s" +msgstr "Riga SOFO%s mancante in %s" #: ../spell.c:5253 #, c-format msgid "Both SAL and SOFO lines in %s" -msgstr "Linee sia SAL che SOFO in %s" +msgstr "Riga sia SAL che SOFO in %s" #: ../spell.c:5331 #, c-format msgid "Flag is not a number in %s line %d: %s" -msgstr "Il flag non un numero in %s linea %d: %s" +msgstr "Il flag non un numero in %s riga %d: %s" #: ../spell.c:5334 #, c-format msgid "Illegal flag in %s line %d: %s" -msgstr "Flag non ammesso in %s linea %d: %s" +msgstr "Flag non ammesso in %s riga %d: %s" #: ../spell.c:5493 ../spell.c:5501 #, c-format @@ -5466,17 +5505,17 @@ msgstr "E760: Nessun contatore parole in %s" #: ../spell.c:5669 #, c-format msgid "line %6d, word %6d - %s" -msgstr "linea %6d, parola %6d - %s" +msgstr "riga %6d, parola %6d - %s" #: ../spell.c:5691 #, c-format msgid "Duplicate word in %s line %d: %s" -msgstr "Parola duplicata in %s linea %d: %s" +msgstr "Parola duplicata in %s riga %d: %s" #: ../spell.c:5694 #, c-format msgid "First duplicate word in %s line %d: %s" -msgstr "Prima parola duplicata in %s linea %d: %s" +msgstr "Prima parola duplicata in %s riga %d: %s" #: ../spell.c:5746 #, c-format @@ -5496,37 +5535,37 @@ msgstr "Lettura file parole %s ..." #: ../spell.c:6155 #, c-format msgid "Duplicate /encoding= line ignored in %s line %d: %s" -msgstr "Linea /encoding= duplicata ignorata in %s linea %d: %s" +msgstr "Riga /encoding= duplicata ignorata in %s riga %d: %s" #: ../spell.c:6159 #, c-format msgid "/encoding= line after word ignored in %s line %d: %s" -msgstr "Linea /encoding= dopo parola ignorata in %s linea %d: %s" +msgstr "Riga /encoding= dopo parola ignorata in %s riga %d: %s" #: ../spell.c:6180 #, c-format msgid "Duplicate /regions= line ignored in %s line %d: %s" -msgstr "Linea /regions= duplicata ignorata in %s linea %d: %s" +msgstr "Riga /regions= duplicata ignorata in %s riga %d: %s" #: ../spell.c:6185 #, c-format msgid "Too many regions in %s line %d: %s" -msgstr "Troppe regioni in %s linea %d: %s" +msgstr "Troppe regioni in %s riga %d: %s" #: ../spell.c:6198 #, c-format msgid "/ line ignored in %s line %d: %s" -msgstr "Linea / ignorata in %s linea %d: %s" +msgstr "Riga / ignorata in %s riga %d: %s" #: ../spell.c:6224 #, c-format msgid "Invalid region nr in %s line %d: %s" -msgstr "N. regione non valido in %s linea %d: %s" +msgstr "N. regione non valido in %s riga %d: %s" #: ../spell.c:6230 #, c-format msgid "Unrecognized flags in %s line %d: %s" -msgstr "Flag non riconosciuti in %s linea %d: %s" +msgstr "Flag non riconosciuti in %s riga %d: %s" #: ../spell.c:6257 #, c-format @@ -5583,7 +5622,7 @@ msgstr "E755: Regione non valida in %s" #: ../spell.c:7907 msgid "Warning: both compounding and NOBREAK specified" -msgstr "Attenzione: specificati sia composizione sia NOBREAK" +msgstr "Avviso: specificati sia composizione sia NOBREAK" #: ../spell.c:7920 #, c-format @@ -5700,7 +5739,7 @@ msgstr "la sincronizzazione inizia " #: ../syntax.c:3443 ../syntax.c:3506 msgid " lines before top line" -msgstr " linee prima della linea iniziale" +msgstr " righe prima della riga iniziale" #: ../syntax.c:3448 msgid "" @@ -5745,7 +5784,7 @@ msgstr "; corrisp. " #: ../syntax.c:3515 msgid " line breaks" -msgstr " interruzioni di linea" +msgstr " interruzioni di riga" #: ../syntax.c:4076 msgid "E395: contains argument not accepted here" @@ -5809,7 +5848,7 @@ msgstr "E402: Spazzatura dopo espressione: %s" #: ../syntax.c:5120 msgid "E403: syntax sync: line continuations pattern specified twice" msgstr "" -"E403: syntax sync: espressione di continuazione linea specificata due volte" +"E403: syntax sync: espressione di continuazione riga specificata due volte" #: ../syntax.c:5169 #, c-format @@ -5998,7 +6037,7 @@ msgid "" " # TO tag FROM line in file/text" msgstr "" "\n" -" # A tag DA__ linea in file/testo" +" # A tag DA__ riga in file/testo" #: ../tag.c:1303 #, c-format @@ -6007,7 +6046,7 @@ msgstr "Ricerca nel tag file %s" #: ../tag.c:1545 msgid "Ignoring long line in tags file" -msgstr "Linea lunga ignorata nel tag file" +msgstr "Riga lunga ignorata nel tag file" #: ../tag.c:1915 #, c-format @@ -6177,23 +6216,23 @@ msgstr "E830: Undo numero %<PRId64> non trovato" #: ../undo.c:1979 msgid "E438: u_undo: line numbers wrong" -msgstr "E438: u_undo: numeri linee errati" +msgstr "E438: u_undo: numeri righe errati" #: ../undo.c:2183 msgid "more line" -msgstr "linea in pi" +msgstr "riga in pi" #: ../undo.c:2185 msgid "more lines" -msgstr "linee in pi" +msgstr "righe in pi" #: ../undo.c:2187 msgid "line less" -msgstr "linea in meno" +msgstr "riga in meno" #: ../undo.c:2189 msgid "fewer lines" -msgstr "linee in meno" +msgstr "righe in meno" #: ../undo.c:2193 msgid "change" @@ -6239,7 +6278,7 @@ msgstr "E439: lista 'undo' non valida" #: ../undo.c:2495 msgid "E440: undo line missing" -msgstr "E440: linea di 'undo' mancante" +msgstr "E440: riga di 'undo' mancante" #: ../version.c:600 msgid "" @@ -6439,6 +6478,10 @@ msgstr "E445: Altre finestre contengono modifiche" msgid "E446: No file name under cursor" msgstr "E446: Nessun nome file sotto il cursore" +#: ../window.c:5484 +msgid "List or number required" +msgstr " necessaria una lista o un numero" + #~ msgid "E831: bf_key_init() called with empty password" #~ msgstr "E831: chiamata a bf_key_init() con password nulla" @@ -6524,15 +6567,6 @@ msgstr "E446: Nessun nome file sotto il cursore" #~ msgid "Reading from stdin..." #~ msgstr "Leggo da 'stdin'..." -#~ msgid "[blowfish]" -#~ msgstr "[blowfish]" - -#~ msgid "[crypted]" -#~ msgstr "[cifrato]" - -#~ msgid "E821: File is encrypted with unknown method" -#~ msgstr "E821: File cifrato con metodo sconosciuto" - #~ msgid "NetBeans disallows writes of unmodified buffers" #~ msgstr "NetBeans non permette la scrittura di un buffer non modificato" @@ -6648,8 +6682,8 @@ msgstr "E446: Nessun nome file sotto il cursore" #~ msgid "Vim: Received \"die\" request from session manager\n" #~ msgstr "Vim: Ricevuta richiesta \"die\" dal session manager\n" -#~ msgid "Close" -#~ msgstr "Chiusura" +#~ msgid "Close tab" +#~ msgstr "Chiudi linguetta" #~ msgid "New tab" #~ msgstr "Nuova linguetta" @@ -6705,9 +6739,6 @@ msgstr "E446: Nessun nome file sotto il cursore" #~ msgid "E672: Unable to open window inside MDI application" #~ msgstr "E672: Non posso aprire la finestra in un'applicazione MDI" -#~ msgid "Close tab" -#~ msgstr "Chiudi linguetta" - #~ msgid "Open tab..." #~ msgstr "Apri linguetta..." @@ -6830,13 +6861,13 @@ msgstr "E446: Nessun nome file sotto il cursore" #~ msgstr "non sono riuscito ad aprire il buffer" #~ msgid "cannot delete line" -#~ msgstr "non posso cancellare la linea" +#~ msgstr "non posso cancellare la riga" #~ msgid "cannot replace line" -#~ msgstr "non posso sostituire la linea" +#~ msgstr "non posso sostituire la riga" #~ msgid "cannot insert line" -#~ msgstr "non posso inserire la linea" +#~ msgstr "non posso inserire la riga" #~ msgid "string cannot contain newlines" #~ msgstr "la stringa non pu contenere caratteri 'A CAPO'" @@ -6857,7 +6888,7 @@ msgstr "E446: Nessun nome file sotto il cursore" #~ msgstr "finestra non valida" #~ msgid "linenr out of range" -#~ msgstr "numero linea non nell'intervallo" +#~ msgstr "numero riga non nell'intervallo" #~ msgid "not allowed in the Vim sandbox" #~ msgstr "non ammesso in ambiente protetto" @@ -6865,9 +6896,6 @@ msgstr "E446: Nessun nome file sotto il cursore" #~ msgid "E836: This Vim cannot execute :python after using :py3" #~ msgstr "E836: Python: Impossibile usare :py e :py3 nella stessa sessione" -#~ msgid "E837: This Vim cannot execute :py3 after using :python" -#~ msgstr "E837: Impossibile usare ora :py3 dopo aver usato :python" - #~ msgid "" #~ "E263: Sorry, this command is disabled, the Python library could not be " #~ "loaded." @@ -6875,14 +6903,18 @@ msgstr "E446: Nessun nome file sotto il cursore" #~ "E263: Spiacente, comando non disponibile, non riesco a caricare libreria " #~ "programmi Python." +#~ msgid "" +#~ "E887: Sorry, this command is disabled, the Python's site module could not be " +#~ "loaded." +#~ msgstr "" +#~ "E887: Spiacente, comando non disponibile, non riesco a caricare il modulo " +#~ "Python locale." + #~ msgid "E659: Cannot invoke Python recursively" #~ msgstr "E659: Python non pu essere chiamato ricorsivamente" -#~ msgid "line number out of range" -#~ msgstr "numero linea non nell'intervallo" - -#~ msgid "invalid mark name" -#~ msgstr "nome di mark non valido" +#~ msgid "E837: This Vim cannot execute :py3 after using :python" +#~ msgstr "E837: Impossibile usare ora :py3 dopo aver usato :python" #~ msgid "E265: $_ must be an instance of String" #~ msgstr "E265: $_ deve essere un'istanza di String" @@ -7010,7 +7042,10 @@ msgstr "E446: Nessun nome file sotto il cursore" #~ msgstr "non ancora implementato" #~ msgid "cannot set line(s)" -#~ msgstr "non posso impostare linea(e)" +#~ msgstr "non posso impostare riga(he)" + +#~ msgid "invalid mark name" +#~ msgstr "nome di mark non valido" #~ msgid "mark not set" #~ msgstr "mark non impostato" @@ -7019,7 +7054,10 @@ msgstr "E446: Nessun nome file sotto il cursore" #~ msgstr "riga %d colonna %d" #~ msgid "cannot insert/append line" -#~ msgstr "non riesco a inserire/aggiungere linea" +#~ msgstr "non riesco a inserire/aggiungere riga" + +#~ msgid "line number out of range" +#~ msgstr "numero linea non nell'intervallo" #~ msgid "unknown flag: " #~ msgstr "opzione inesistente: " @@ -7067,7 +7105,7 @@ msgstr "E446: Nessun nome file sotto il cursore" #~ msgstr "E572: codice di uscita %d" #~ msgid "cannot get line" -#~ msgstr "non riesco a ottenere la linea" +#~ msgstr "non riesco a ottenere la riga" #~ msgid "Unable to register a command server name" #~ msgstr "Non riesco a registrare un nome di server comando" @@ -7293,7 +7331,7 @@ msgstr "E446: Nessun nome file sotto il cursore" #~ msgstr "E286: Apertura 'input method' fallita" #~ msgid "E287: Warning: Could not set destroy callback to IM" -#~ msgstr "E287: Attenzione: Non posso assegnare IM a 'destroy callback'" +#~ msgstr "E287: Avviso: Non posso assegnare IM a 'destroy callback'" #~ msgid "E288: input method doesn't support any style" #~ msgstr "E288: 'input method' non sopporta alcuno stile" @@ -7365,12 +7403,6 @@ msgstr "E446: Nessun nome file sotto il cursore" #~ msgid "E338: Sorry, no file browser in console mode" #~ msgstr "E338: Spiacente, niente esplorazione file in modalit console" -#~ msgid "Vim: preserving files...\n" -#~ msgstr "Vim: preservo file...\n" - -#~ msgid "Vim: Finished.\n" -#~ msgstr "Vim: Finito.\n" - #~ msgid "ERROR: " #~ msgstr "ERRORE: " @@ -7391,7 +7423,7 @@ msgstr "E446: Nessun nome file sotto il cursore" #~ "\n" #~ msgid "E340: Line is becoming too long" -#~ msgstr "E340: La linea sta diventando troppo lunga" +#~ msgstr "E340: La riga sta diventando troppo lunga" #~ msgid "E341: Internal error: lalloc(%<PRId64>, )" #~ msgstr "E341: Errore interno: lalloc(%<PRId64>, )" @@ -7399,15 +7431,6 @@ msgstr "E446: Nessun nome file sotto il cursore" #~ msgid "E547: Illegal mouseshape" #~ msgstr "E547: Forma del mouse non valida" -#~ msgid "Enter encryption key: " -#~ msgstr "Immetti chiave di cifratura: " - -#~ msgid "Enter same key again: " -#~ msgstr "Ribatti per conferma la stessa chiave: " - -#~ msgid "Keys don't match!" -#~ msgstr "Le chiavi non corrispondono!" - #~ msgid "Cannot connect to Netbeans #2" #~ msgstr "Non posso connettermi a Netbeans #2" @@ -7437,7 +7460,7 @@ msgstr "E446: Nessun nome file sotto il cursore" #~ msgstr "E775: Funzionalit [eval] non disponibile" #~ msgid "freeing %<PRId64> lines" -#~ msgstr "libero %<PRId64> linee" +#~ msgstr "libero %<PRId64> righe" #~ msgid "E530: Cannot change term in GUI" #~ msgstr "E530: Non posso modificare 'term' mentre sono nella GUI" @@ -7538,15 +7561,6 @@ msgstr "E446: Nessun nome file sotto il cursore" #~ msgid "E245: Illegal char '%c' in font name \"%s\"" #~ msgstr "E245: Carattere non ammesso '%c' nel font di nome \"%s\"" -#~ msgid "Vim: Double signal, exiting\n" -#~ msgstr "Vim: Segnale doppio, esco\n" - -#~ msgid "Vim: Caught deadly signal %s\n" -#~ msgstr "Vim: Intercettato segnale fatale %s\n" - -#~ msgid "Vim: Caught deadly signal\n" -#~ msgstr "Vim: Intercettato segnale fatale\n" - #~ msgid "Opening the X display took %<PRId64> msec" #~ msgstr "Attivazione visualizzazione X ha richiesto %<PRId64> msec" @@ -7610,7 +7624,7 @@ msgstr "E446: Nessun nome file sotto il cursore" #~ msgstr "XSMP SmcOpenConnection fallita: %s" #~ msgid "At line" -#~ msgstr "Alla linea" +#~ msgstr "Alla riga" #~ msgid "Could not load vim32.dll!" #~ msgstr "Non riesco a caricare vim32.dll!" @@ -7875,7 +7889,7 @@ msgstr "E446: Nessun nome file sotto il cursore" #~ msgstr " modo Vim predefinito " #~ msgid "WARNING: Windows 95/98/ME detected" -#~ msgstr "ATTENZIONE: Trovato Windows 95/98/ME" +#~ msgstr "AVVISO: Trovato Windows 95/98/ME" #~ msgid "type :help windows95<Enter> for info on this" #~ msgstr "batti :help windows95<Enter> per info al riguardo" @@ -7962,6 +7976,22 @@ msgstr "E446: Nessun nome file sotto il cursore" #~ msgid "Need encryption key for \"%s\"" #~ msgstr "Serve una chiave di cifratura per \"%s\"" +#~ msgid "empty keys are not allowed" +#~ msgstr "chiavi nulle non consentite" + +#~ msgid "dictionary is locked" +#~ msgstr "il dizionario bloccato" + +#~ msgid "list is locked" +#~ msgstr "la lista bloccata" + +#~ msgid "failed to add key '%s' to dictionary" +#~ msgstr "non non riusciato ad aggiungere la chiave '%s' al dizionario" + +#~ #, c-format +#~ msgid "index must be int or slice, not %s" +#~ msgstr "l'indice deve'essere un intero o un intervallo, non %s" + #~ msgid "expected str() or unicode() instance, but got %s" #~ msgstr "attesa istanza di str() o unicode(), trovato invece %s" @@ -7985,8 +8015,8 @@ msgstr "E446: Nessun nome file sotto il cursore" #~ msgid "value is too small to fit into C int type" #~ msgstr "valore troppo piccolo per il tipo int del C" -#~ msgid "number must be greater then zero" -#~ msgstr "il numero dev'essere maggiore di zero" +#~ msgid "number must be greater than zero" +#~ msgstr "il numero deve essere maggiore di zero" #~ msgid "number must be greater or equal to zero" #~ msgstr "il numero dev'essere maggiore o uguale a zero" @@ -8005,7 +8035,8 @@ msgstr "E446: Nessun nome file sotto il cursore" #~ msgid "expected 3-tuple as imp.find_module() result, but got %s" #~ msgstr "" -#~ "atteso terzetto come risultato di imp.find_module(), trovato invece %s" +#~ "atteso terzetto come risultato di imp.find_module(), trovato invece tuple di " +#~ "dimens. %d" #~ msgid "" #~ "expected 3-tuple as imp.find_module() result, but got tuple of size %d" @@ -8042,15 +8073,30 @@ msgstr "E446: Nessun nome file sotto il cursore" #~ msgid "internal error: failed to get vim list item %d" #~ msgstr "errore interno: non ho potuto ottenere l'elemento di vim list %d" -#~ msgid "failed to add item to list" -#~ msgstr "non ho potuto aggiungere un elemento alla lista" +#~ msgid "slice step cannot be zero" +#~ msgstr "il passo scorrendo un intervallo non pu essere zero" + +#~ #, c-format +#~ msgid "attempt to assign sequence of size greater than %d to extended slice" +#~ msgstr "tentativo di assegnare una sequenza maggiore di %d a un intervallo " +#~ "esteso" #~ msgid "internal error: no vim list item %d" #~ msgstr "errore interno: non c' un elemento di vim list %d" +#~ msgid "internal error: not enough list items" +#~ msgstr "errore interno: non ci sono abbastanza elementi per la lista" + #~ msgid "internal error: failed to add item to list" #~ msgstr "errore interno: non ho potuto aggiungere un elemento alla lista" +#~ msgid "attempt to assign sequence of size %d to extended slice of size %d" +#~ msgstr "tentativo di assegnare sequenza di dimensione %d a un intervallo " +#~ " esteso di dimensione %d" + +#~ msgid "failed to add item to list" +#~ msgstr "non ho potuto aggiungere un elemento alla lista" + #~ msgid "cannot delete vim.List attributes" #~ msgstr "non riesco a cancellare gli attributi vim.List" diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 4a8391430b..97db69d3f3 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -39,7 +39,6 @@ #include "nvim/search.h" #include "nvim/strings.h" #include "nvim/ui.h" -#include "nvim/tempfile.h" #include "nvim/window.h" #include "nvim/os/os.h" #include "nvim/os/input.h" @@ -200,9 +199,8 @@ qf_init_ext ( char_u *pattern; char_u *fmtstr = NULL; int col = 0; - char_u use_viscol = FALSE; - int type = 0; - int valid; + bool use_viscol = false; + char_u type = 0; linenr_T buflnum = lnumfirst; long lnum = 0L; int enr = 0; @@ -220,16 +218,16 @@ qf_init_ext ( int i; int round; int idx = 0; - int multiline = FALSE; - int multiignore = FALSE; - int multiscan = FALSE; - int retval = -1; /* default: return error flag */ - char_u *directory = NULL; - char_u *currfile = NULL; - char_u *tail = NULL; - char_u *p_str = NULL; - listitem_T *p_li = NULL; - struct dir_stack_T *file_stack = NULL; + bool multiline = false; + bool multiignore = false; + bool multiscan = false; + int retval = -1; // default: return error flag + char_u *directory = NULL; + char_u *currfile = NULL; + char_u *tail = NULL; + char_u *p_str = NULL; + listitem_T *p_li = NULL; + struct dir_stack_T *file_stack = NULL; regmatch_T regmatch; static struct fmtpattern { char_u convchar; @@ -278,15 +276,16 @@ qf_init_ext ( /* * Get some space to modify the format string into. */ - i = 3 * FMT_PATTERNS + 4 * (int)STRLEN(efm); - for (round = FMT_PATTERNS; round > 0; ) - i += (int)STRLEN(fmt_pat[--round].pattern); + size_t fmtstr_size = 3 * FMT_PATTERNS + 4 * STRLEN(efm); + for (round = FMT_PATTERNS; round > 0; ) { + fmtstr_size += STRLEN(fmt_pat[--round].pattern); + } #ifdef COLON_IN_FILENAME - i += 12; /* "%f" can become twelve chars longer */ + fmtstr_size += 12; // "%f" can become twelve chars longer #else - i += 2; /* "%f" can become two chars longer */ + fmtstr_size += 2; // "%f" can become two chars longer #endif - fmtstr = xmalloc(i); + fmtstr = xmalloc(fmtstr_size); while (efm[0] != NUL) { /* @@ -530,11 +529,9 @@ qf_init_ext ( fmt_start = NULL; } - /* - * Try to match each part of 'errorformat' until we find a complete - * match or no match. - */ - valid = TRUE; + // Try to match each part of 'errorformat' until we find a complete + // match or no match. + bool valid = true; restofline: for (; fmt_ptr != NULL; fmt_ptr = fmt_ptr->next) { idx = fmt_ptr->prefix; @@ -546,7 +543,7 @@ restofline: errmsg[0] = NUL; lnum = 0; col = 0; - use_viscol = FALSE; + use_viscol = false; enr = -1; type = 0; tail = NULL; @@ -555,25 +552,23 @@ restofline: int r = vim_regexec(®match, IObuff, (colnr_T)0); fmt_ptr->prog = regmatch.regprog; if (r) { - if ((idx == 'C' || idx == 'Z') && !multiline) + if ((idx == 'C' || idx == 'Z') && !multiline) { continue; - if (vim_strchr((char_u *)"EWI", idx) != NULL) - type = idx; - else + } + if (vim_strchr((char_u *)"EWI", idx) != NULL) { + type = (char_u)idx; + } else { type = 0; - /* - * Extract error message data from matched line. - * We check for an actual submatch, because "\[" and "\]" in - * the 'errorformat' may cause the wrong submatch to be used. - */ - if ((i = (int)fmt_ptr->addr[0]) > 0) { /* %f */ - int c; - - if (regmatch.startp[i] == NULL || regmatch.endp[i] == NULL) + } + // Extract error message data from matched line. + // We check for an actual submatch, because "\[" and "\]" in + // the 'errorformat' may cause the wrong submatch to be used. + if ((i = (int)fmt_ptr->addr[0]) > 0) { // %f + if (regmatch.startp[i] == NULL || regmatch.endp[i] == NULL) { continue; - - /* Expand ~/file and $HOME/file to full path. */ - c = *regmatch.endp[i]; + } + // Expand ~/file and $HOME/file to full path. + char_u c = *regmatch.endp[i]; *regmatch.endp[i] = NUL; expand_env(regmatch.startp[i], namebuf, CMDBUFFSIZE); *regmatch.endp[i] = c; @@ -629,14 +624,14 @@ restofline: col -= col % 8; } } - ++col; - use_viscol = TRUE; + col++; + use_viscol = true; } if ((i = (int)fmt_ptr->addr[8]) > 0) { /* %v */ if (regmatch.startp[i] == NULL) continue; col = (int)atol((char *)regmatch.startp[i]); - use_viscol = TRUE; + use_viscol = true; } if ((i = (int)fmt_ptr->addr[9]) > 0) { /* %s */ if (regmatch.startp[i] == NULL || regmatch.endp[i] == NULL) @@ -653,7 +648,7 @@ restofline: break; } } - multiscan = FALSE; + multiscan = false; if (fmt_ptr == NULL || idx == 'D' || idx == 'X') { if (fmt_ptr != NULL) { @@ -667,20 +662,21 @@ restofline: } else if (idx == 'X') /* leave directory */ directory = qf_pop_dir(&dir_stack); } - namebuf[0] = NUL; /* no match found, remove file name */ - lnum = 0; /* don't jump to this line */ - valid = FALSE; - STRCPY(errmsg, IObuff); /* copy whole line to error message */ - if (fmt_ptr == NULL) - multiline = multiignore = FALSE; + namebuf[0] = NUL; // no match found, remove file name + lnum = 0; // don't jump to this line + valid = false; + STRCPY(errmsg, IObuff); // copy whole line to error message + if (fmt_ptr == NULL) { + multiline = multiignore = false; + } } else if (fmt_ptr != NULL) { /* honor %> item */ if (fmt_ptr->conthere) fmt_start = fmt_ptr; if (vim_strchr((char_u *)"AEWI", idx) != NULL) { - multiline = TRUE; /* start of a multi-line message */ - multiignore = FALSE; /* reset continuation */ + multiline = true; // start of a multi-line message + multiignore = false; // reset continuation } else if (vim_strchr((char_u *)"CZ", idx) != NULL) { /* continuation of multi-line msg */ if (qfprev == NULL) @@ -702,15 +698,17 @@ restofline: qfprev->qf_viscol = use_viscol; if (!qfprev->qf_fnum) qfprev->qf_fnum = qf_get_fnum(directory, - *namebuf || directory ? namebuf - : currfile && valid ? currfile : 0); - if (idx == 'Z') - multiline = multiignore = FALSE; + *namebuf + || directory ? namebuf : currfile + && valid ? currfile : 0); + if (idx == 'Z') { + multiline = multiignore = false; + } line_breakcheck(); continue; } else if (vim_strchr((char_u *)"OPQ", idx) != NULL) { - /* global file names */ - valid = FALSE; + // global file names + valid = false; if (*namebuf == NUL || os_file_exists(namebuf)) { if (*namebuf && idx == 'P') currfile = qf_push_dir(namebuf, &file_stack); @@ -719,14 +717,15 @@ restofline: *namebuf = NUL; if (tail && *tail) { STRMOVE(IObuff, skipwhite(tail)); - multiscan = TRUE; + multiscan = true; goto restofline; } } } - if (fmt_ptr->flags == '-') { /* generally exclude this line */ - if (multiline) - multiignore = TRUE; /* also exclude continuation lines */ + if (fmt_ptr->flags == '-') { // generally exclude this line + if (multiline) { + multiignore = true; // also exclude continuation lines + } continue; } } @@ -867,26 +866,27 @@ void qf_free_all(win_T *wp) qf_free(qi, i); } -/* - * Add an entry to the end of the list of errors. - * Returns OK or FAIL. - */ -static int -qf_add_entry ( - qf_info_T *qi, /* quickfix list */ - qfline_T **prevp, /* nonnull pointer (to previously added entry or NULL) */ - char_u *dir, /* optional directory name */ - char_u *fname, /* file name or NULL */ - int bufnum, /* buffer number or zero */ - char_u *mesg, /* message */ - long lnum, /* line number */ - int col, /* column */ - int vis_col, /* using visual column */ - char_u *pattern, /* search pattern */ - int nr, /* error number */ - int type, /* type character */ - int valid /* valid entry */ -) +/// Add an entry to the end of the list of errors. +/// +/// @param qi quickfix list +/// @param prevp nonnull pointer (to previously added entry or NULL) +/// @param dir optional directory name +/// @param fname file name or NULL +/// @param bufnum buffer number or zero +/// @param mesg message +/// @param lnum line number +/// @param col column +/// @param vis_col using visual column +/// @param pattern search pattern +/// @param nr error number +/// @param type type character +/// @param valid valid entry +/// +/// @returns OK or FAIL. +static int qf_add_entry(qf_info_T *qi, qfline_T **prevp, char_u *dir, + char_u *fname, int bufnum, char_u *mesg, long lnum, + int col, char_u vis_col, char_u *pattern, int nr, + char_u type, char_u valid) { qfline_T *qfp = xmalloc(sizeof(qfline_T)); @@ -1657,12 +1657,13 @@ win_found: * flag is present in 'shortmess'; But when not jumping, print the * whole message. */ i = msg_scroll; - if (curbuf == old_curbuf && curwin->w_cursor.lnum == old_lnum) - msg_scroll = TRUE; - else if (!msg_scrolled && shortmess(SHM_OVERALL)) - msg_scroll = FALSE; - msg_attr_keep(IObuff, 0, TRUE); - msg_scroll = i; + if (curbuf == old_curbuf && curwin->w_cursor.lnum == old_lnum) { + msg_scroll = true; + } else if (!msg_scrolled && shortmess(SHM_OVERALL)) { + msg_scroll = false; + } + msg_attr_keep(IObuff, 0, true); + msg_scroll = (int)i; } } else { if (opened_window) @@ -1827,10 +1828,12 @@ void qf_age(exarg_T *eap) } } - if (eap->addr_count != 0) - count = eap->line2; - else + if (eap->addr_count != 0) { + assert(eap->line2 <= INT_MAX); + count = (int)eap->line2; + } else { count = 1; + } while (count--) { if (eap->cmdidx == CMD_colder || eap->cmdidx == CMD_lolder) { if (qi->qf_curlist == 0) { @@ -1882,6 +1885,8 @@ static void qf_free(qf_info_T *qi, int idx) --qi->qf_lists[idx].qf_count; } xfree(qi->qf_lists[idx].qf_title); + qi->qf_lists[idx].qf_start = NULL; + qi->qf_lists[idx].qf_ptr = NULL; qi->qf_lists[idx].qf_title = NULL; qi->qf_lists[idx].qf_index = 0; } @@ -1948,7 +1953,7 @@ static char_u *qf_types(int c, int nr) p = (char_u *)""; else { cc[0] = ' '; - cc[1] = c; + cc[1] = (char_u)c; cc[2] = NUL; p = cc; } @@ -2036,12 +2041,13 @@ void ex_copen(exarg_T *eap) } } - if (eap->addr_count != 0) - height = eap->line2; - else + if (eap->addr_count != 0) { + assert(eap->line2 <= INT_MAX); + height = (int)eap->line2; + } else { height = QF_WINHEIGHT; - - reset_VIsual_and_resel(); /* stop Visual mode */ + } + reset_VIsual_and_resel(); // stop Visual mode /* * Find existing quickfix window, or open a new one. @@ -2433,8 +2439,6 @@ int grep_internal(cmdidx_T cmdidx) void ex_make(exarg_T *eap) { char_u *fname; - char_u *cmd; - unsigned len; win_T *wp = NULL; qf_info_T *qi = &ql_info; int res; @@ -2472,29 +2476,28 @@ void ex_make(exarg_T *eap) return; os_remove((char *)fname); // in case it's not unique - /* - * If 'shellpipe' empty: don't redirect to 'errorfile'. - */ - len = (unsigned)STRLEN(p_shq) * 2 + (unsigned)STRLEN(eap->arg) + 1; - if (*p_sp != NUL) - len += (unsigned)STRLEN(p_sp) + (unsigned)STRLEN(fname) + 3; - cmd = xmalloc(len); - sprintf((char *)cmd, "%s%s%s", (char *)p_shq, (char *)eap->arg, - (char *)p_shq); - if (*p_sp != NUL) - append_redir(cmd, len, p_sp, fname); - /* - * Output a newline if there's something else than the :make command that - * was typed (in which case the cursor is in column 0). - */ - if (msg_col == 0) - msg_didout = FALSE; + // If 'shellpipe' empty: don't redirect to 'errorfile'. + const size_t len = (STRLEN(p_shq) * 2 + STRLEN(eap->arg) + 1 + + (*p_sp == NUL + ? 0 + : STRLEN(p_sp) + STRLEN(fname) + 3)); + char *const cmd = xmalloc(len); + snprintf(cmd, len, "%s%s%s", (char *)p_shq, (char *)eap->arg, + (char *)p_shq); + if (*p_sp != NUL) { + append_redir(cmd, len, (char *) p_sp, (char *) fname); + } + // Output a newline if there's something else than the :make command that + // was typed (in which case the cursor is in column 0). + if (msg_col == 0) { + msg_didout = false; + } msg_start(); MSG_PUTS(":!"); - msg_outtrans(cmd); /* show what we are doing */ + msg_outtrans((char_u *) cmd); // show what we are doing - /* let the shell know if we are redirecting output or not */ - do_shell(cmd, *p_sp != NUL ? kShellOptDoOut : 0); + // let the shell know if we are redirecting output or not + do_shell((char_u *) cmd, *p_sp != NUL ? kShellOptDoOut : 0); res = qf_init(wp, fname, (eap->cmdidx != CMD_make @@ -2548,11 +2551,11 @@ static char_u *get_mef_name(void) /* Keep trying until the name doesn't exist yet. */ for (;; ) { - if (start == -1) - start = os_get_pid(); - else + if (start == -1) { + start = (int)os_get_pid(); + } else { off += 19; - + } name = xmalloc(STRLEN(p_mef) + 30); STRCPY(name, p_mef); sprintf((char *)name + (p - p_mef), "%d%d", start, off); @@ -2899,7 +2902,7 @@ void ex_vimgrep(exarg_T *eap) int found_match; buf_T *first_match_buf = NULL; time_t seconds = 0; - int save_mls; + long save_mls; char_u *save_ei = NULL; aco_save_T aco; int flags = 0; @@ -3456,18 +3459,12 @@ int get_errorlist(win_T *wp, list_T *list) */ int set_errorlist(win_T *wp, list_T *list, int action, char_u *title) { - listitem_T *li; - dict_T *d; - char_u *filename, *pattern, *text, *type; - int bufnum; - long lnum; - int col, nr; - int vcol; - qfline_T *prevp = NULL; - int valid, status; + listitem_T *li; + dict_T *d; + qfline_T *prevp = NULL; int retval = OK; - qf_info_T *qi = &ql_info; - int did_bufnr_emsg = FALSE; + qf_info_T *qi = &ql_info; + bool did_bufnr_emsg = false; if (wp != NULL) { qi = ll_get_or_alloc_list(wp); @@ -3494,21 +3491,22 @@ int set_errorlist(win_T *wp, list_T *list, int action, char_u *title) if (d == NULL) continue; - filename = get_dict_string(d, (char_u *)"filename", TRUE); - bufnum = get_dict_number(d, (char_u *)"bufnr"); - lnum = get_dict_number(d, (char_u *)"lnum"); - col = get_dict_number(d, (char_u *)"col"); - vcol = get_dict_number(d, (char_u *)"vcol"); - nr = get_dict_number(d, (char_u *)"nr"); - type = get_dict_string(d, (char_u *)"type", TRUE); - pattern = get_dict_string(d, (char_u *)"pattern", TRUE); - text = get_dict_string(d, (char_u *)"text", TRUE); - if (text == NULL) + char_u *filename = get_dict_string(d, (char_u *)"filename", true); + int bufnum = (int)get_dict_number(d, (char_u *)"bufnr"); + long lnum = get_dict_number(d, (char_u *)"lnum"); + int col = (int)get_dict_number(d, (char_u *)"col"); + char_u vcol = (char_u)get_dict_number(d, (char_u *)"vcol"); + int nr = (int)get_dict_number(d, (char_u *)"nr"); + char_u *type = get_dict_string(d, (char_u *)"type", true); + char_u *pattern = get_dict_string(d, (char_u *)"pattern", true); + char_u *text = get_dict_string(d, (char_u *)"text", true); + if (text == NULL) { text = vim_strsave((char_u *)""); - - valid = TRUE; - if ((filename == NULL && bufnum == 0) || (lnum == 0 && pattern == NULL)) - valid = FALSE; + } + bool valid = true; + if ((filename == NULL && bufnum == 0) || (lnum == 0 && pattern == NULL)) { + valid = false; + } /* Mark entries with non-existing buffer number as not valid. Give the * error message only once. */ @@ -3517,22 +3515,23 @@ int set_errorlist(win_T *wp, list_T *list, int action, char_u *title) did_bufnr_emsg = TRUE; EMSGN(_("E92: Buffer %" PRId64 " not found"), bufnum); } - valid = FALSE; + valid = false; bufnum = 0; } - status = qf_add_entry(qi, &prevp, - NULL, /* dir */ - filename, - bufnum, - text, - lnum, - col, - vcol, /* vis_col */ - pattern, /* search pattern */ - nr, - type == NULL ? NUL : *type, - valid); + int status = qf_add_entry(qi, + &prevp, + NULL, // dir + filename, + bufnum, + text, + lnum, + col, + vcol, // vis_col + pattern, // search pattern + nr, + (char_u)(type == NULL ? NUL : *type), + valid); xfree(filename); xfree(pattern); diff --git a/src/nvim/shada.c b/src/nvim/shada.c index def2de9b1a..32a02b0fb7 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -31,7 +31,6 @@ #include "nvim/misc2.h" #include "nvim/ex_getln.h" #include "nvim/search.h" -#include "nvim/eval.h" #include "nvim/regexp.h" #include "nvim/eval_defs.h" #include "nvim/version.h" @@ -39,6 +38,8 @@ #include "nvim/fileio.h" #include "nvim/strings.h" #include "nvim/quickfix.h" +#include "nvim/eval/encode.h" +#include "nvim/eval/decode.h" #include "nvim/lib/khash.h" #include "nvim/lib/kvec.h" @@ -65,9 +66,6 @@ KHASH_SET_INIT_STR(strset) ((char *) copy_option_part((char_u **) src, (char_u *) dest, __VA_ARGS__)) #define find_shada_parameter(...) \ ((const char *) find_shada_parameter(__VA_ARGS__)) -#define emsg2(a, b) emsg2((char_u *) a, (char_u *) b) -#define emsg3(a, b, c) emsg3((char_u *) a, (char_u *) b, (char_u *) c) -#define emsgu(a, ...) emsgu((char_u *) a, __VA_ARGS__) #define home_replace_save(a, b) \ ((char *)home_replace_save(a, (char_u *)b)) #define home_replace(a, b, c, d, e) \ @@ -761,7 +759,7 @@ static void close_sd_writer(ShaDaWriteDef *const sd_writer) { const int fd = (int)(intptr_t) sd_writer->cookie; if (os_fsync(fd) < 0) { - emsg2(_(SERR "System error while synchronizing ShaDa file: %s"), + emsgf(_(SERR "System error while synchronizing ShaDa file: %s"), os_strerror(errno)); errno = 0; } @@ -811,11 +809,11 @@ static ShaDaReadResult sd_reader_skip(ShaDaReadDef *const sd_reader, { if (sd_reader->skip(sd_reader, offset) != OK) { if (sd_reader->error != NULL) { - emsg2(_(SERR "System error while skipping in ShaDa file: %s"), + emsgf(_(SERR "System error while skipping in ShaDa file: %s"), sd_reader->error); return kSDReadStatusReadError; } else if (sd_reader->eof) { - emsgu(_(RCERR "Error while reading ShaDa file: " + emsgf(_(RCERR "Error while reading ShaDa file: " "last entry specified that it occupies %" PRIu64 " bytes, " "but file ended earlier"), (uint64_t) offset); @@ -849,7 +847,7 @@ open_file_start: goto open_file_start; } if (fd != UV_EEXIST) { - emsg3(_(SERR "System error while opening ShaDa file %s: %s"), + emsgf(_(SERR "System error while opening ShaDa file %s: %s"), fname, os_strerror(fd)); } return fd; @@ -897,7 +895,7 @@ close_file_start: errno = 0; goto close_file_start; } else { - emsg2(_(SERR "System error while closing ShaDa file: %s"), + emsgf(_(SERR "System error while closing ShaDa file: %s"), strerror(errno)); errno = 0; } @@ -934,7 +932,7 @@ static int msgpack_sd_writer_write(void *data, const char *buf, size_t len) ShaDaWriteDef *const sd_writer = (ShaDaWriteDef *) data; ptrdiff_t written_bytes = sd_writer->write(sd_writer, buf, len); if (written_bytes == -1) { - emsg2(_(SERR "System error while writing ShaDa file: %s"), + emsgf(_(SERR "System error while writing ShaDa file: %s"), sd_writer->error); return -1; } @@ -981,7 +979,7 @@ static int shada_read_file(const char *const file, const int flags) if (of_ret != 0) { if (of_ret == UV_ENOENT && (flags & kShaDaMissingError)) { - emsg3(_(SERR "System error while opening ShaDa file %s for reading: %s"), + emsgf(_(SERR "System error while opening ShaDa file %s for reading: %s"), fname, os_strerror(of_ret)); } xfree(fname); @@ -1687,8 +1685,9 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, do { \ if ((src) != NULL) { \ for (listitem_T *li = (src)->lv_first; li != NULL; li = li->li_next) { \ - if (vim_to_msgpack(spacker, &li->li_tv, \ - _("additional elements of ShaDa " what)) == FAIL) { \ + if (encode_vim_to_msgpack(spacker, &li->li_tv, \ + _("additional elements of ShaDa " what)) \ + == FAIL) { \ goto shada_pack_entry_error; \ } \ } \ @@ -1706,8 +1705,9 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, const size_t key_len = strlen((const char *) hi->hi_key); \ msgpack_pack_str(spacker, key_len); \ msgpack_pack_str_body(spacker, (const char *) hi->hi_key, key_len); \ - if (vim_to_msgpack(spacker, &di->di_tv, \ - _("additional data of ShaDa " what)) == FAIL) { \ + if (encode_vim_to_msgpack(spacker, &di->di_tv, \ + _("additional data of ShaDa " what)) \ + == FAIL) { \ goto shada_pack_entry_error; \ } \ } \ @@ -1757,7 +1757,7 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, char vardesc[256] = "variable g:"; memcpy(&vardesc[sizeof("variable g:") - 1], varname.data, varname.size + 1); - if (vim_to_msgpack(spacker, &entry.data.global_var.value, vardesc) + if (encode_vim_to_msgpack(spacker, &entry.data.global_var.value, vardesc) == FAIL) { ret = kSDWriteIgnError; EMSG2(_(WERR "Failed to write variable %s"), @@ -2159,7 +2159,7 @@ shada_parse_msgpack_read_next: {} break; } case MSGPACK_UNPACK_PARSE_ERROR: { - emsgu(_(RCERR "Failed to parse ShaDa file due to a msgpack parser error " + emsgf(_(RCERR "Failed to parse ShaDa file due to a msgpack parser error " "at position %" PRIu64), (uint64_t) initial_fpos); ret = kSDReadStatusNotShaDa; @@ -2176,7 +2176,7 @@ shada_parse_msgpack_read_next: {} break; } case MSGPACK_UNPACK_CONTINUE: { - emsgu(_(RCERR "Failed to parse ShaDa file: incomplete msgpack string " + emsgf(_(RCERR "Failed to parse ShaDa file: incomplete msgpack string " "at position %" PRIu64), (uint64_t) initial_fpos); ret = kSDReadStatusNotShaDa; @@ -2184,7 +2184,7 @@ shada_parse_msgpack_read_next: {} } case MSGPACK_UNPACK_EXTRA_BYTES: { shada_parse_msgpack_extra_bytes: - emsgu(_(RCERR "Failed to parse ShaDa file: extra bytes in msgpack string " + emsgf(_(RCERR "Failed to parse ShaDa file: extra bytes in msgpack string " "at position %" PRIu64), (uint64_t) initial_fpos); ret = kSDReadStatusNotShaDa; @@ -3265,11 +3265,11 @@ static ShaDaReadResult fread_len(ShaDaReadDef *const sd_reader, (void) read_bytes; if (sd_reader->error != NULL) { - emsg2(_(SERR "System error while reading ShaDa file: %s"), + emsgf(_(SERR "System error while reading ShaDa file: %s"), sd_reader->error); return kSDReadStatusReadError; } else if (sd_reader->eof) { - emsgu(_(RCERR "Error while reading ShaDa file: " + emsgf(_(RCERR "Error while reading ShaDa file: " "last entry specified that it occupies %" PRIu64 " bytes, " "but file ended earlier"), (uint64_t) length); @@ -3304,11 +3304,11 @@ static ShaDaReadResult msgpack_read_uint64(ShaDaReadDef *const sd_reader, if (first_char == EOF) { if (sd_reader->error) { - emsg2(_(SERR "System error while reading integer from ShaDa file: %s"), + emsgf(_(SERR "System error while reading integer from ShaDa file: %s"), sd_reader->error); return kSDReadStatusReadError; } else if (sd_reader->eof) { - emsgu(_(RCERR "Error while reading ShaDa file: " + emsgf(_(RCERR "Error while reading ShaDa file: " "expected positive integer at position %" PRIu64 ", but got nothing"), (uint64_t) fpos); @@ -3339,7 +3339,7 @@ static ShaDaReadResult msgpack_read_uint64(ShaDaReadDef *const sd_reader, break; } default: { - emsgu(_(RCERR "Error while reading ShaDa file: " + emsgf(_(RCERR "Error while reading ShaDa file: " "expected positive integer at position %" PRIu64), (uint64_t) fpos); return kSDReadStatusNotShaDa; @@ -3403,18 +3403,18 @@ static inline char *get_converted_string(const vimconv_T *const sd_conv, proc) \ do { \ if (!(condition)) { \ - emsgu(_(READERR(entry_name, error_desc)), initial_fpos); \ + emsgf(_(READERR(entry_name, error_desc)), initial_fpos); \ CLEAR_GA_AND_ERROR_OUT(ad_ga); \ } \ tgt = proc(obj.via.attr); \ } while (0) #define CHECK_KEY_IS_STR(entry_name) \ if (unpacked.data.via.map.ptr[i].key.type != MSGPACK_OBJECT_STR) { \ - emsgu(_(READERR(entry_name, "has key which is not a string")), \ + emsgf(_(READERR(entry_name, "has key which is not a string")), \ initial_fpos); \ CLEAR_GA_AND_ERROR_OUT(ad_ga); \ } else if (unpacked.data.via.map.ptr[i].key.via.str.size == 0) { \ - emsgu(_(READERR(entry_name, "has empty key")), initial_fpos); \ + emsgf(_(READERR(entry_name, "has empty key")), initial_fpos); \ CLEAR_GA_AND_ERROR_OUT(ad_ga); \ } #define CHECKED_KEY(entry_name, name, error_desc, tgt, condition, attr, proc) \ @@ -3477,7 +3477,7 @@ static inline char *get_converted_string(const vimconv_T *const sd_conv, typval_T adtv; \ if (msgpack_to_vim(obj, &adtv) == FAIL \ || adtv.v_type != VAR_DICT) { \ - emsgu(_(READERR(name, \ + emsgf(_(READERR(name, \ "cannot be converted to a VimL dictionary")), \ initial_fpos); \ ga_clear(&ad_ga); \ @@ -3502,7 +3502,7 @@ static inline char *get_converted_string(const vimconv_T *const sd_conv, }; \ typval_T aetv; \ if (msgpack_to_vim(obj, &aetv) == FAIL) { \ - emsgu(_(READERR(name, "cannot be converted to a VimL list")), \ + emsgf(_(READERR(name, "cannot be converted to a VimL list")), \ initial_fpos); \ clear_tv(&aetv); \ goto shada_read_next_item_error; \ @@ -3570,7 +3570,7 @@ shada_read_next_item_start: // kSDItemUnknown cannot possibly pass that far because it is -1 and that // will fail in msgpack_read_uint64. But kSDItemMissing may and it will // otherwise be skipped because (1 << 0) will never appear in flags. - emsgu(_(RCERR "Error while reading ShaDa file: " + emsgf(_(RCERR "Error while reading ShaDa file: " "there is an item at position %" PRIu64 " " "that must not be there: Missing items are " "for internal uses only"), @@ -3640,14 +3640,14 @@ shada_read_next_item_start: switch ((ShadaEntryType) type_u64) { case kSDItemHeader: { if (!msgpack_rpc_to_dictionary(&(unpacked.data), &(entry->data.header))) { - emsgu(_(READERR("header", "is not a dictionary")), initial_fpos); + emsgf(_(READERR("header", "is not a dictionary")), initial_fpos); goto shada_read_next_item_error; } break; } case kSDItemSearchPattern: { if (unpacked.data.type != MSGPACK_OBJECT_MAP) { - emsgu(_(READERR("search pattern", "is not a dictionary")), + emsgf(_(READERR("search pattern", "is not a dictionary")), initial_fpos); goto shada_read_next_item_error; } @@ -3678,7 +3678,7 @@ shada_read_next_item_start: ADDITIONAL_KEY } if (entry->data.search_pattern.pat == NULL) { - emsgu(_(READERR("search pattern", "has no pattern")), initial_fpos); + emsgf(_(READERR("search pattern", "has no pattern")), initial_fpos); CLEAR_GA_AND_ERROR_OUT(ad_ga); } SET_ADDITIONAL_DATA(entry->data.search_pattern.additional_data, @@ -3690,7 +3690,7 @@ shada_read_next_item_start: case kSDItemGlobalMark: case kSDItemLocalMark: { if (unpacked.data.type != MSGPACK_OBJECT_MAP) { - emsgu(_(READERR("mark", "is not a dictionary")), initial_fpos); + emsgf(_(READERR("mark", "is not a dictionary")), initial_fpos); goto shada_read_next_item_error; } garray_T ad_ga; @@ -3699,7 +3699,7 @@ shada_read_next_item_start: CHECK_KEY_IS_STR("mark") if (CHECK_KEY(unpacked.data.via.map.ptr[i].key, KEY_NAME_CHAR)) { if (type_u64 == kSDItemJump || type_u64 == kSDItemChange) { - emsgu(_(READERR("mark", "has n key which is only valid for " + emsgf(_(READERR("mark", "has n key which is only valid for " "local and global mark entries")), initial_fpos); CLEAR_GA_AND_ERROR_OUT(ad_ga); } @@ -3716,15 +3716,15 @@ shada_read_next_item_start: ADDITIONAL_KEY } if (entry->data.filemark.fname == NULL) { - emsgu(_(READERR("mark", "is missing file name")), initial_fpos); + emsgf(_(READERR("mark", "is missing file name")), initial_fpos); CLEAR_GA_AND_ERROR_OUT(ad_ga); } if (entry->data.filemark.mark.lnum <= 0) { - emsgu(_(READERR("mark", "has invalid line number")), initial_fpos); + emsgf(_(READERR("mark", "has invalid line number")), initial_fpos); CLEAR_GA_AND_ERROR_OUT(ad_ga); } if (entry->data.filemark.mark.col < 0) { - emsgu(_(READERR("mark", "has invalid column number")), initial_fpos); + emsgf(_(READERR("mark", "has invalid column number")), initial_fpos); CLEAR_GA_AND_ERROR_OUT(ad_ga); } SET_ADDITIONAL_DATA(entry->data.filemark.additional_data, "mark"); @@ -3732,7 +3732,7 @@ shada_read_next_item_start: } case kSDItemRegister: { if (unpacked.data.type != MSGPACK_OBJECT_MAP) { - emsgu(_(READERR("register", "is not a dictionary")), initial_fpos); + emsgf(_(READERR("register", "is not a dictionary")), initial_fpos); goto shada_read_next_item_error; } garray_T ad_ga; @@ -3742,14 +3742,14 @@ shada_read_next_item_start: if (CHECK_KEY(unpacked.data.via.map.ptr[i].key, REG_KEY_CONTENTS)) { if (unpacked.data.via.map.ptr[i].val.type != MSGPACK_OBJECT_ARRAY) { - emsgu(_(READERR("register", + emsgf(_(READERR("register", "has " REG_KEY_CONTENTS " key with non-array value")), initial_fpos); CLEAR_GA_AND_ERROR_OUT(ad_ga); } if (unpacked.data.via.map.ptr[i].val.via.array.size == 0) { - emsgu(_(READERR("register", + emsgf(_(READERR("register", "has " REG_KEY_CONTENTS " key with empty array")), initial_fpos); CLEAR_GA_AND_ERROR_OUT(ad_ga); @@ -3758,7 +3758,7 @@ shada_read_next_item_start: unpacked.data.via.map.ptr[i].val.via.array; for (size_t i = 0; i < arr.size; i++) { if (arr.ptr[i].type != MSGPACK_OBJECT_BIN) { - emsgu(_(READERR("register", "has " REG_KEY_CONTENTS " array " + emsgf(_(READERR("register", "has " REG_KEY_CONTENTS " array " "with non-binary value")), initial_fpos); CLEAR_GA_AND_ERROR_OUT(ad_ga); } @@ -3778,7 +3778,7 @@ shada_read_next_item_start: ADDITIONAL_KEY } if (entry->data.reg.contents == NULL) { - emsgu(_(READERR("register", "has missing " REG_KEY_CONTENTS " array")), + emsgf(_(READERR("register", "has missing " REG_KEY_CONTENTS " array")), initial_fpos); CLEAR_GA_AND_ERROR_OUT(ad_ga); } @@ -3787,29 +3787,29 @@ shada_read_next_item_start: } case kSDItemHistoryEntry: { if (unpacked.data.type != MSGPACK_OBJECT_ARRAY) { - emsgu(_(READERR("history", "is not an array")), initial_fpos); + emsgf(_(READERR("history", "is not an array")), initial_fpos); goto shada_read_next_item_error; } if (unpacked.data.via.array.size < 2) { - emsgu(_(READERR("history", "does not have enough elements")), + emsgf(_(READERR("history", "does not have enough elements")), initial_fpos); goto shada_read_next_item_error; } if (unpacked.data.via.array.ptr[0].type != MSGPACK_OBJECT_POSITIVE_INTEGER) { - emsgu(_(READERR("history", "has wrong history type type")), + emsgf(_(READERR("history", "has wrong history type type")), initial_fpos); goto shada_read_next_item_error; } if (unpacked.data.via.array.ptr[1].type != MSGPACK_OBJECT_BIN) { - emsgu(_(READERR("history", "has wrong history string type")), + emsgf(_(READERR("history", "has wrong history string type")), initial_fpos); goto shada_read_next_item_error; } if (memchr(unpacked.data.via.array.ptr[1].via.bin.ptr, 0, unpacked.data.via.array.ptr[1].via.bin.size) != NULL) { - emsgu(_(READERR("history", "contains string with zero byte inside")), + emsgf(_(READERR("history", "contains string with zero byte inside")), initial_fpos); goto shada_read_next_item_error; } @@ -3819,13 +3819,13 @@ shada_read_next_item_start: entry->data.history_item.histtype == HIST_SEARCH; if (is_hist_search) { if (unpacked.data.via.array.size < 3) { - emsgu(_(READERR("search history", + emsgf(_(READERR("search history", "does not have separator character")), initial_fpos); goto shada_read_next_item_error; } if (unpacked.data.via.array.ptr[2].type != MSGPACK_OBJECT_POSITIVE_INTEGER) { - emsgu(_(READERR("search history", + emsgf(_(READERR("search history", "has wrong history separator type")), initial_fpos); goto shada_read_next_item_error; } @@ -3867,22 +3867,16 @@ shada_read_next_item_hist_no_conv: } case kSDItemVariable: { if (unpacked.data.type != MSGPACK_OBJECT_ARRAY) { - emsgu(_(READERR("variable", "is not an array")), initial_fpos); + emsgf(_(READERR("variable", "is not an array")), initial_fpos); goto shada_read_next_item_error; } if (unpacked.data.via.array.size < 2) { - emsgu(_(READERR("variable", "does not have enough elements")), + emsgf(_(READERR("variable", "does not have enough elements")), initial_fpos); goto shada_read_next_item_error; } if (unpacked.data.via.array.ptr[0].type != MSGPACK_OBJECT_BIN) { - emsgu(_(READERR("variable", "has wrong variable name type")), - initial_fpos); - goto shada_read_next_item_error; - } - if (unpacked.data.via.array.ptr[1].type == MSGPACK_OBJECT_NIL - || unpacked.data.via.array.ptr[1].type == MSGPACK_OBJECT_EXT) { - emsgu(_(READERR("variable", "has wrong variable value type")), + emsgf(_(READERR("variable", "has wrong variable name type")), initial_fpos); goto shada_read_next_item_error; } @@ -3891,7 +3885,7 @@ shada_read_next_item_hist_no_conv: unpacked.data.via.array.ptr[0].via.bin.size); if (msgpack_to_vim(unpacked.data.via.array.ptr[1], &(entry->data.global_var.value)) == FAIL) { - emsgu(_(READERR("variable", "has value that cannot " + emsgf(_(READERR("variable", "has value that cannot " "be converted to the VimL value")), initial_fpos); goto shada_read_next_item_error; } @@ -3912,16 +3906,16 @@ shada_read_next_item_hist_no_conv: } case kSDItemSubString: { if (unpacked.data.type != MSGPACK_OBJECT_ARRAY) { - emsgu(_(READERR("sub string", "is not an array")), initial_fpos); + emsgf(_(READERR("sub string", "is not an array")), initial_fpos); goto shada_read_next_item_error; } if (unpacked.data.via.array.size < 1) { - emsgu(_(READERR("sub string", "does not have enough elements")), + emsgf(_(READERR("sub string", "does not have enough elements")), initial_fpos); goto shada_read_next_item_error; } if (unpacked.data.via.array.ptr[0].type != MSGPACK_OBJECT_BIN) { - emsgu(_(READERR("sub string", "has wrong sub string type")), + emsgf(_(READERR("sub string", "has wrong sub string type")), initial_fpos); goto shada_read_next_item_error; } @@ -3934,7 +3928,7 @@ shada_read_next_item_hist_no_conv: } case kSDItemBufferList: { if (unpacked.data.type != MSGPACK_OBJECT_ARRAY) { - emsgu(_(READERR("buffer list", "is not an array")), initial_fpos); + emsgf(_(READERR("buffer list", "is not an array")), initial_fpos); goto shada_read_next_item_error; } if (unpacked.data.via.array.size == 0) { @@ -3951,7 +3945,7 @@ shada_read_next_item_hist_no_conv: { msgpack_unpacked unpacked = unpacked_2; if (unpacked.data.type != MSGPACK_OBJECT_MAP) { - emsgu(_(RERR "Error while reading ShaDa file: " + emsgf(_(RERR "Error while reading ShaDa file: " "buffer list at position %" PRIu64 " " "contains entry that is not a dictionary"), initial_fpos); @@ -3976,21 +3970,21 @@ shada_read_next_item_hist_no_conv: } } if (entry->data.buffer_list.buffers[i].pos.lnum <= 0) { - emsgu(_(RERR "Error while reading ShaDa file: " + emsgf(_(RERR "Error while reading ShaDa file: " "buffer list at position %" PRIu64 " " "contains entry with invalid line number"), initial_fpos); CLEAR_GA_AND_ERROR_OUT(ad_ga); } if (entry->data.buffer_list.buffers[i].pos.col < 0) { - emsgu(_(RERR "Error while reading ShaDa file: " + emsgf(_(RERR "Error while reading ShaDa file: " "buffer list at position %" PRIu64 " " "contains entry with invalid column number"), initial_fpos); CLEAR_GA_AND_ERROR_OUT(ad_ga); } if (entry->data.buffer_list.buffers[i].fname == NULL) { - emsgu(_(RERR "Error while reading ShaDa file: " + emsgf(_(RERR "Error while reading ShaDa file: " "buffer list at position %" PRIu64 " " "contains entry that does not have a file name"), initial_fpos); diff --git a/src/nvim/spell.c b/src/nvim/spell.c index cc7dc6210c..0acaa9ae2b 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -319,7 +319,6 @@ #include "nvim/strings.h" #include "nvim/syntax.h" #include "nvim/ui.h" -#include "nvim/tempfile.h" #include "nvim/undo.h" #include "nvim/os/os.h" #include "nvim/os/input.h" @@ -2332,14 +2331,17 @@ static void spell_load_lang(char_u *lang) if (r == FAIL) { if (starting) { - // Some startup file sets &spell, but the necessary files don't exist: - // try to prompt the user at VimEnter. Also set spell again. #3027 - do_cmdline_cmd( - "autocmd VimEnter * call spellfile#LoadFile(&spelllang)|set spell"); + // Prompt the user at VimEnter if spell files are missing. #3027 + // Plugins aren't loaded yet, so spellfile.vim cannot handle this case. + char autocmd_buf[128] = { 0 }; + snprintf(autocmd_buf, sizeof(autocmd_buf), + "autocmd VimEnter * call spellfile#LoadFile('%s')|set spell", + lang); + do_cmdline_cmd(autocmd_buf); } else { smsg( _("Warning: Cannot find word list \"%s.%s.spl\" or \"%s.ascii.spl\""), - lang, spell_enc(), lang); + lang, spell_enc(), lang); } } else if (sl.sl_slang != NULL) { // At least one file was loaded, now load ALL the additions. diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 478fa973a1..26f0a6c94b 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -5533,25 +5533,29 @@ char_u *get_syntax_name(expand_T *xp, int idx) } -/* - * Function called for expression evaluation: get syntax ID at file position. - */ -int -syn_get_id ( +// Function called for expression evaluation: get syntax ID at file position. +int syn_get_id( win_T *wp, long lnum, colnr_T col, - int trans, /* remove transparency */ - bool *spellp, /* return: can do spell checking */ - int keep_state /* keep state of char at "col" */ + int trans, // remove transparency + bool *spellp, // return: can do spell checking + int keep_state // keep state of char at "col" ) { - /* When the position is not after the current position and in the same - * line of the same buffer, need to restart parsing. */ + // When the position is not after the current position and in the same + // line of the same buffer, need to restart parsing. if (wp->w_buffer != syn_buf || lnum != current_lnum - || col < current_col) + || col < current_col) { syntax_start(wp, lnum); + } else if (wp->w_buffer == syn_buf + && lnum == current_lnum + && col > current_col) { + // next_match may not be correct when moving around, e.g. with the + // "skip" expression in searchpair() + next_match_idx = -1; + } (void)get_syntax_attr(col, spellp, keep_state); @@ -6391,7 +6395,7 @@ do_highlight ( HL_TABLE()[idx].sg_cterm_bg = color + 1; if (is_normal_group) { cterm_normal_bg_color = color + 1; - { + if (!ui_rgb_attached()) { must_redraw = CLEAR; if (color >= 0) { if (t_colors < 16) diff --git a/src/nvim/tag.c b/src/nvim/tag.c index 8fcb02c3b6..da84106454 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -872,7 +872,7 @@ do_tag ( /* Let the SwapExists event know what tag we are jumping to. */ vim_snprintf((char *)IObuff, IOSIZE, ":ta %s\r", name); - set_vim_var_string(VV_SWAPCOMMAND, IObuff, -1); + set_vim_var_string(VV_SWAPCOMMAND, (char *) IObuff, -1); /* * Jump to the desired match. @@ -1147,6 +1147,22 @@ find_tags ( int get_it_again = FALSE; int use_cscope = (flags & TAG_CSCOPE); int verbose = (flags & TAG_VERBOSE); + int save_p_ic = p_ic; + + // Change the value of 'ignorecase' according to 'tagcase' for the + // duration of this function. + switch (curbuf->b_tc_flags ? curbuf->b_tc_flags : tc_flags) { + case TC_FOLLOWIC: + break; + case TC_IGNORE: + p_ic = true; + break; + case TC_MATCH: + p_ic = false; + break; + default: + assert(false); + } help_save = curbuf->b_help; orgpat.pat = pat; @@ -1955,6 +1971,8 @@ findtag_end: curbuf->b_help = help_save; xfree(saved_pat); + p_ic = save_p_ic; + return retval; } diff --git a/src/nvim/tempfile.c b/src/nvim/tempfile.c deleted file mode 100644 index a218c03fdb..0000000000 --- a/src/nvim/tempfile.c +++ /dev/null @@ -1,138 +0,0 @@ -#include <inttypes.h> -#include <stdbool.h> -#include <stdlib.h> -#include <stdio.h> - -#include "nvim/ascii.h" -#include "nvim/memory.h" -#include "nvim/misc1.h" -#include "nvim/os/os.h" -#include "nvim/os/os_defs.h" -#include "nvim/path.h" -#include "nvim/strings.h" -#include "nvim/tempfile.h" - -#ifdef INCLUDE_GENERATED_DECLARATIONS -# include "tempfile.c.generated.h" -#endif - -/// Name of Vim's own temp dir. Ends in a slash. -static char_u *vim_tempdir = NULL; - -/// Create a directory for private use by this instance of Neovim. -/// This is done once, and the same directory is used for all temp files. -/// This method avoids security problems because of symlink attacks et al. -/// It's also a bit faster, because we only need to check for an existing -/// file when creating the directory and not for each temp file. -static void vim_maketempdir(void) -{ - static const char *temp_dirs[] = TEMP_DIR_NAMES; - // Try the entries in `TEMP_DIR_NAMES` to create the temp directory. - char_u template[TEMP_FILE_PATH_MAXLEN]; - char_u path[TEMP_FILE_PATH_MAXLEN]; - for (size_t i = 0; i < ARRAY_SIZE(temp_dirs); ++i) { - // Expand environment variables, leave room for "/nvimXXXXXX/999999999" - expand_env((char_u *)temp_dirs[i], template, TEMP_FILE_PATH_MAXLEN - 22); - if (!os_isdir(template)) { // directory doesn't exist - continue; - } - - add_pathsep((char *)template); - // Concatenate with temporary directory name pattern - STRCAT(template, "nvimXXXXXX"); - - if (os_mkdtemp((const char *)template, (char *)path) != 0) { - continue; - } - - if (vim_settempdir((char *)path)) { - // Successfully created and set temporary directory so stop trying. - break; - } else { - // Couldn't set `vim_tempdir` to `path` so remove created directory. - os_rmdir((char *)path); - } - } -} - -/// Delete the temp directory and all files it contains. -void vim_deltempdir(void) -{ - if (vim_tempdir != NULL) { - snprintf((char *)NameBuff, MAXPATHL, "%s*", vim_tempdir); - - char_u **files; - int file_count; - - // Note: We cannot just do `&NameBuff` because it is a statically - // sized array so `NameBuff == &NameBuff` according to C semantics. - char_u *buff_list[1] = {NameBuff}; - if (gen_expand_wildcards(1, buff_list, &file_count, &files, - EW_DIR|EW_FILE|EW_SILENT) == OK) { - for (int i = 0; i < file_count; ++i) { - os_remove((char *)files[i]); - } - FreeWild(file_count, files); - } - path_tail(NameBuff)[-1] = NUL; - os_rmdir((char *)NameBuff); - - xfree(vim_tempdir); - vim_tempdir = NULL; - } -} - -/// Get the name of temp directory. This directory would be created on the first -/// call to this function. -char_u *vim_gettempdir(void) -{ - if (vim_tempdir == NULL) { - vim_maketempdir(); - } - - return vim_tempdir; -} - -/// Set Neovim own temporary directory name to `tempdir`. This directory should -/// be already created. Expand this name to a full path and put it in -/// `vim_tempdir`. This avoids that using `:cd` would confuse us. -/// -/// @param tempdir must be no longer than MAXPATHL. -/// -/// @return false if we run out of memory. -static bool vim_settempdir(char *tempdir) -{ - char *buf = verbose_try_malloc(MAXPATHL + 2); - if (!buf) { - return false; - } - vim_FullName(tempdir, buf, MAXPATHL, false); - add_pathsep(buf); - vim_tempdir = (char_u *)xstrdup(buf); - xfree(buf); - return true; -} - -/// Return a unique name that can be used for a temp file. -/// -/// @note The temp file is NOT created. -/// -/// @return pointer to the temp file name or NULL if Neovim can't create -/// temporary directory for its own temporary files. -char_u *vim_tempname(void) -{ - // Temp filename counter. - static uint32_t temp_count; - - char_u *tempdir = vim_gettempdir(); - if (!tempdir) { - return NULL; - } - - // There is no need to check if the file exists, because we own the directory - // and nobody else creates a file in it. - char_u template[TEMP_FILE_PATH_MAXLEN]; - snprintf((char *)template, TEMP_FILE_PATH_MAXLEN, - "%s%" PRIu32, tempdir, temp_count++); - return vim_strsave(template); -} diff --git a/src/nvim/tempfile.h b/src/nvim/tempfile.h deleted file mode 100644 index c030a70eeb..0000000000 --- a/src/nvim/tempfile.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef NVIM_TEMPFILE_H -#define NVIM_TEMPFILE_H - -#ifdef INCLUDE_GENERATED_DECLARATIONS -# include "tempfile.h.generated.h" -#endif - -#endif // NVIM_TEMPFILE_H diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 42fd81f643..0440272eb9 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -411,6 +411,10 @@ static int terminal_execute(VimState *state, int key) apply_autocmds(EVENT_FOCUSLOST, NULL, NULL, false, curbuf); break; + // Temporary fix until paste events gets implemented + case K_PASTE: + break; + case K_LEFTMOUSE: case K_LEFTDRAG: case K_LEFTRELEASE: @@ -623,6 +627,7 @@ static int term_settermprop(VTermProp prop, VTermValue *val, void *data) api_free_object(dict_set_value(buf->b_vars, cstr_as_string("term_title"), STRING_OBJ(cstr_as_string(val->string)), + false, &err)); break; } diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index b760811585..4debdd9acc 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -32,14 +32,16 @@ SCRIPTS := \ test69.out \ test73.out \ test79.out \ - test88.out \ test_listlbr.out \ test_breakindent.out \ test_close_count.out \ test_marks.out \ -NEW_TESTS := \ - test_alot.res \ +# Tests using runtest.vim.vim. +# Keep test_alot*.res as the last one, sort the others. +NEW_TESTS = \ + test_viml.res \ + test_alot.res SCRIPTS_GUI := test16.out diff --git a/src/nvim/testdir/runtest.vim b/src/nvim/testdir/runtest.vim index 8314a45d0c..1c610eab51 100644 --- a/src/nvim/testdir/runtest.vim +++ b/src/nvim/testdir/runtest.vim @@ -33,6 +33,15 @@ if &lines < 24 || &columns < 80 cquit endif +" This also enables use of line continuation. +set viminfo+=nviminfo + +" Avoid stopping at the "hit enter" prompt +set nomore + +" Output all messages in English. +lang mess C + " Source the test script. First grab the file name, in case the script " navigates away. let testname = expand('%') @@ -40,12 +49,17 @@ let done = 0 let fail = 0 let errors = [] let messages = [] -try +if expand('%') =~ 'test_viml.vim' + " this test has intentional errors, don't use try/catch. source % -catch - let fail += 1 - call add(errors, 'Caught exception: ' . v:exception . ' @ ' . v:throwpoint) -endtry +else + try + source % + catch + let fail += 1 + call add(errors, 'Caught exception: ' . v:exception . ' @ ' . v:throwpoint) + endtry +endif " Locate Test_ functions and execute them. redir @q diff --git a/src/nvim/testdir/test17.in b/src/nvim/testdir/test17.in index 7fef87d383..a8c81b832d 100644 --- a/src/nvim/testdir/test17.in +++ b/src/nvim/testdir/test17.in @@ -41,17 +41,17 @@ STARTTEST :!mkdir Xdir1 :!mkdir "Xdir1/dir2" :e! Xdir1/dir2/foo.a -i#include "bar.a" +i#include "bar.a": :w :e Xdir1/dir2/bar.a -i#include "baz.a" +i#include "baz.a": :w :e Xdir1/dir2/baz.a -i#include "foo.a" +i#include "foo.a": :w :e Xbase.a :set path=Xdir1/dir2 -i#include <foo.a> +i#include <foo.a>: :w :redir! >>test.out :checkpath! @@ -71,17 +71,17 @@ STARTTEST :endfunction :let &includeexpr='DotsToSlashes()' :e! Xdir1/dir2/foo.b -i%inc /bar/ +i%inc /bar/: :w :e Xdir1/dir2/bar.b -i%inc /baz/ +i%inc /baz/: :w :e Xdir1/dir2/baz.b -i%inc /foo/ +i%inc /foo/: :w :e Xbase.b :set path=Xdir1/dir2 -i%inc /foo/ +i%inc /foo/: :w :redir! >>test.out :checkpath! @@ -104,20 +104,20 @@ STARTTEST :endfunction :let &includeexpr='StripNewlineChar()' :e! Xdir1/dir2/foo.c -i%inc bar.c +i%inc bar.c: :w :e Xdir1/dir2/bar.c -i%inc baz.c +i%inc baz.c: :w :e Xdir1/dir2/baz.c -i%inc foo.c +i%inc foo.c: :w :e Xdir1/dir2/FALSE.c -i%inc foo.c +i%inc foo.c: :w :e Xbase.c :set path=Xdir1/dir2 -i%inc FALSE.c foo.c +i%inc FALSE.c foo.c: :w :redir! >>test.out :checkpath! diff --git a/src/nvim/testdir/test49.ok b/src/nvim/testdir/test49.ok index bf1ceed9af..50fc5d2cef 100644 --- a/src/nvim/testdir/test49.ok +++ b/src/nvim/testdir/test49.ok @@ -1,19 +1,4 @@ Results of test49.vim: -*** Test 1: OK (34695) -*** Test 2: OK (34695) -*** Test 3: OK (1384648195) -*** Test 4: OK (32883) -*** Test 5: OK (32883) -*** Test 6: OK (603978947) -*** Test 7: OK (90563) -*** Test 8: OK (562493431) -*** Test 9: OK (363) -*** Test 10: OK (559615) -*** Test 11: OK (2049) -*** Test 12: OK (352256) -*** Test 13: OK (145) -*** Test 14: OK (42413) -*** Test 15: OK (42413) *** Test 16: OK (8722) *** Test 17: OK (285127993) *** Test 18: OK (67224583) diff --git a/src/nvim/testdir/test49.vim b/src/nvim/testdir/test49.vim index 70d388b06a..edd49a2b63 100644 --- a/src/nvim/testdir/test49.vim +++ b/src/nvim/testdir/test49.vim @@ -1,6 +1,6 @@ " Vim script language tests " Author: Servatius Brandt <Servatius.Brandt@fujitsu-siemens.com> -" Last Change: 2015 Sep 25 +" Last Change: 2016 Feb 07 "------------------------------------------------------------------------------- " Test environment {{{1 @@ -608,850 +608,8 @@ com! -nargs=1 -bar ExecAsScript call ExecAsScript(<f-args>) " END_OF_TEST_ENVIRONMENT - do not change or remove this line. -"------------------------------------------------------------------------------- -" Test 1: :endwhile in function {{{1 -" -" Detect if a broken loop is (incorrectly) reactivated by the -" :endwhile. Use a :return to prevent an endless loop, and make -" this test first to get a meaningful result on an error before other -" tests will hang. -"------------------------------------------------------------------------------- - -XpathINIT - -function! F() - Xpath 1 " X: 1 - let first = 1 - XloopINIT 2 8 - while 1 - Xloop 1 " X: 2 + 0 * 16 - if first - Xloop 2 " X: 4 + 0 * 32 - let first = 0 - XloopNEXT - break - else - Xloop 4 " X: 0 + 0 * 64 - return - endif - endwhile -endfunction - -call F() -Xpath 128 " X: 128 - -function! G() - Xpath 256 " X: 256 + 0 * 2048 - let first = 1 - XloopINIT 512 8 - while 1 - Xloop 1 " X: 512 + 0 * 4096 - if first - Xloop 2 " X: 1024 + 0 * 8192 - let first = 0 - XloopNEXT - break - else - Xloop 4 " X: 0 + 0 * 16384 - return - endif - if 1 " unmatched :if - endwhile -endfunction - -call G() -Xpath 32768 " X: 32768 - -Xcheck 34695 - -" Leave F and G for execution as scripts in the next test. - - -"------------------------------------------------------------------------------- -" Test 2: :endwhile in script {{{1 -" -" Detect if a broken loop is (incorrectly) reactivated by the -" :endwhile. Use a :finish to prevent an endless loop, and place -" this test before others that might hang to get a meaningful result -" on an error. -" -" This test executes the bodies of the functions F and G from the -" previous test as script files (:return replaced by :finish). -"------------------------------------------------------------------------------- - -XpathINIT - -ExecAsScript F " X: 1 + 2 + 4 -Xpath 128 " X: 128 - -ExecAsScript G " X: 256 + 512 + 1024 -Xpath 32768 " X: 32768 - -unlet first -delfunction F -delfunction G - -Xcheck 34695 - - -"------------------------------------------------------------------------------- -" Test 3: :if, :elseif, :while, :continue, :break {{{1 -"------------------------------------------------------------------------------- - -XpathINIT -if 1 - Xpath 1 " X: 1 - let loops = 3 - XloopINIT 2 512 - while loops > -1 " main loop: loops == 3, 2, 1 (which breaks) - if loops <= 0 - let break_err = 1 - let loops = -1 - else " 3: 2: 1: - Xloop 1 " X: 2 + 2*512 + 2*512*512 - endif - if (loops == 2) - while loops == 2 " dummy loop - Xloop 2 " X: 4*512 - let loops = loops - 1 - continue " stop dummy loop - Xloop 4 " X: 0 - endwhile - XloopNEXT - continue " continue main loop - Xloop 8 " X: 0 - elseif (loops == 1) - let p = 1 - while p " dummy loop - Xloop 16 " X: 32*512*512 - let p = 0 - break " break dummy loop - Xloop 32 " X: 0 - endwhile - Xloop 64 " X: 128*512*512 - unlet p - break " break main loop - Xloop 128 " X: 0 - endif - if (loops > 0) - Xloop 256 " X: 512 - endif - while loops == 3 " dummy loop - let loops = loops - 1 - endwhile " end dummy loop - XloopNEXT - endwhile " end main loop - Xpath 268435456 " X: 1024*512*512 -else - Xpath 536870912 " X: 0 -endif -Xpath 1073741824 " X: 4096*512*512 -if exists("break_err") - " The Xpath command does not accept 2^31 (negative); add explicitly: - let Xpath = Xpath + 2147483648 " X: 0 - unlet break_err -endif - -unlet loops - -Xcheck 1384648195 - - -"------------------------------------------------------------------------------- -" Test 4: :return {{{1 -"------------------------------------------------------------------------------- - -XpathINIT - -function! F() - if 1 - Xpath 1 " X: 1 - let loops = 3 - XloopINIT 2 16 - while loops > 0 " 3: 2: 1: - Xloop 1 " X: 2 + 2*16 + 0*16*16 - if (loops == 2) - Xloop 2 " X: 4*16 - return - Xloop 4 " X: 0 - endif - Xloop 8 " X: 16 - let loops = loops - 1 - XloopNEXT - endwhile - Xpath 8192 " X: 0 - else - Xpath 16384 " X: 0 - endif -endfunction - -call F() -Xpath 32768 " X: 8*16*16*16 - -Xcheck 32883 - -" Leave F for execution as a script in the next test. - - -"------------------------------------------------------------------------------- -" Test 5: :finish {{{1 -" -" This test executes the body of the function F from the previous test -" as a script file (:return replaced by :finish). -"------------------------------------------------------------------------------- - -XpathINIT - -ExecAsScript F " X: 1 + 2 + 2*16 + 4*16 + 16 -Xpath 32768 " X: 32768 - -unlet loops -delfunction F - -Xcheck 32883 - - -"------------------------------------------------------------------------------- -" Test 6: Defining functions in :while loops {{{1 -" -" Functions can be defined inside other functions. An inner function -" gets defined when the outer function is executed. Functions may -" also be defined inside while loops. Expressions in braces for -" defining the function name are allowed. -"------------------------------------------------------------------------------- - -XpathINIT - -if ExtraVim() - - " The command CALL collects the argument of all its invocations in "calls" - " when used from a function (that is, when the global variable "calls" needs - " the "g:" prefix). This is to check that the function code is skipped when - " the function is defined. For inner functions, do so only if the outer - " function is not being executed. - " - let calls = "" - com! -nargs=1 CALL - \ if !exists("calls") && !exists("outer") | - \ let g:calls = g:calls . <args> | - \ endif - - - XloopINIT! 1 16 - - let i = 0 - while i < 3 - - XloopNEXT - let i = i + 1 - - if i == 1 - Xloop 1 " X: 1 - function! F1(arg) - CALL a:arg - let outer = 1 - - XloopINIT! 4096 4 - let j = 0 - while j < 1 - XloopNEXT - Xloop 1 " X: 4096 - let j = j + 1 - function! G1(arg) - CALL a:arg - endfunction - Xloop 2 " X: 8192 - endwhile - endfunction - Xloop 2 " X: 2 - - continue - endif - - Xloop 4 " X: 4 * (16 + 256) - function! F{i}(i, arg) - CALL a:arg - let outer = 1 - - XloopINIT! 16384 4 - if a:i == 3 - XloopNEXT - XloopNEXT - XloopNEXT - endif - let k = 0 - while k < 3 - XloopNEXT - Xloop 1 " X: 16384*(1+4+16+64+256+1024) - let k = k + 1 - function! G{a:i}{k}(arg) - CALL a:arg - endfunction - Xloop 2 " X: 32768*(1+4+16+64+256+1024) - endwhile - endfunction - Xloop 8 " X: 8 * (16 + 256) - - endwhile - - if exists("*G1") - Xpath 67108864 " X: 0 - endif - if exists("*F1") - call F1("F1") - if exists("*G1") - call G1("G1") - endif - endif - - if exists("G21") || exists("G21") || exists("G21") - Xpath 134217728 " X: 0 - endif - if exists("*F2") - call F2(2, "F2") - if exists("*G21") - call G21("G21") - endif - if exists("*G22") - call G22("G22") - endif - if exists("*G23") - call G23("G23") - endif - endif - - if exists("G31") || exists("G31") || exists("G31") - Xpath 268435456 " X: 0 - endif - if exists("*F3") - call F3(3, "F3") - if exists("*G31") - call G31("G31") - endif - if exists("*G32") - call G32("G32") - endif - if exists("*G33") - call G33("G33") - endif - endif - - Xpath 536870912 " X: 536870912 - - if calls != "F1G1F2G21G22G23F3G31G32G33" - Xpath 1073741824 " X: 0 - Xout "calls is" calls - endif - - delfunction F1 - delfunction G1 - delfunction F2 - delfunction G21 - delfunction G22 - delfunction G23 - delfunction G31 - delfunction G32 - delfunction G33 - -endif - -Xcheck 603978947 - - -"------------------------------------------------------------------------------- -" Test 7: Continuing on errors outside functions {{{1 -" -" On an error outside a function, the script processing continues -" at the line following the outermost :endif or :endwhile. When not -" inside an :if or :while, the script processing continues at the next -" line. -"------------------------------------------------------------------------------- - -XpathINIT - -if 1 - Xpath 1 " X: 1 - while 1 - Xpath 2 " X: 2 - asdf - Xpath 4 " X: 0 - break - endwhile | Xpath 8 " X: 0 - Xpath 16 " X: 0 -endif | Xpath 32 " X: 0 -Xpath 64 " X: 64 - -while 1 - Xpath 128 " X: 128 - if 1 - Xpath 256 " X: 256 - asdf - Xpath 512 " X: 0 - endif | Xpath 1024 " X: 0 - Xpath 2048 " X: 0 - break -endwhile | Xpath 4096 " X: 0 -Xpath 8192 " X: 8192 - -asdf -Xpath 16384 " X: 16384 - -asdf | Xpath 32768 " X: 0 -Xpath 65536 " X: 65536 - -Xcheck 90563 - - -"------------------------------------------------------------------------------- -" Test 8: Aborting and continuing on errors inside functions {{{1 -" -" On an error inside a function without the "abort" attribute, the -" script processing continues at the next line (unless the error was -" in a :return command). On an error inside a function with the -" "abort" attribute, the function is aborted and the script processing -" continues after the function call; the value -1 is returned then. -"------------------------------------------------------------------------------- - -XpathINIT - -function! F() - if 1 - Xpath 1 " X: 1 - while 1 - Xpath 2 " X: 2 - asdf - Xpath 4 " X: 4 - asdf | Xpath 8 " X: 0 - Xpath 16 " X: 16 - break - endwhile - Xpath 32 " X: 32 - endif | Xpath 64 " X: 64 - Xpath 128 " X: 128 - - while 1 - Xpath 256 " X: 256 - if 1 - Xpath 512 " X: 512 - asdf - Xpath 1024 " X: 1024 - asdf | Xpath 2048 " X: 0 - Xpath 4096 " X: 4096 - endif - Xpath 8192 " X: 8192 - break - endwhile | Xpath 16384 " X: 16384 - Xpath 32768 " X: 32768 - - return novar " returns (default return value 0) - Xpath 65536 " X: 0 - return 1 " not reached -endfunction - -function! G() abort - if 1 - Xpath 131072 " X: 131072 - while 1 - Xpath 262144 " X: 262144 - asdf " returns -1 - Xpath 524288 " X: 0 - break - endwhile - Xpath 1048576 " X: 0 - endif | Xpath 2097152 " X: 0 - Xpath Xpath 4194304 " X: 0 - - return -4 " not reached -endfunction - -function! H() abort - while 1 - Xpath 8388608 " X: 8388608 - if 1 - Xpath 16777216 " X: 16777216 - asdf " returns -1 - Xpath 33554432 " X: 0 - endif - Xpath 67108864 " X: 0 - break - endwhile | Xpath 134217728 " X: 0 - Xpath 268435456 " X: 0 - - return -4 " not reached -endfunction - -" Aborted functions (G and H) return -1. -let sum = (F() + 1) - 4*G() - 8*H() -Xpath 536870912 " X: 536870912 -if sum != 13 - Xpath 1073741824 " X: 0 - Xout "sum is" sum -endif - -unlet sum -delfunction F -delfunction G -delfunction H - -Xcheck 562493431 - - -"------------------------------------------------------------------------------- -" Test 9: Continuing after aborted functions {{{1 -" -" When a function with the "abort" attribute is aborted due to an -" error, the next function back in the call hierarchy without an -" "abort" attribute continues; the value -1 is returned then. -"------------------------------------------------------------------------------- - -XpathINIT - -function! F() abort - Xpath 1 " X: 1 - let result = G() " not aborted - Xpath 2 " X: 2 - if result != 2 - Xpath 4 " X: 0 - endif - return 1 -endfunction - -function! G() " no abort attribute - Xpath 8 " X: 8 - if H() != -1 " aborted - Xpath 16 " X: 0 - endif - Xpath 32 " X: 32 - return 2 -endfunction - -function! H() abort - Xpath 64 " X: 64 - call I() " aborted - Xpath 128 " X: 0 - return 4 -endfunction - -function! I() abort - Xpath 256 " X: 256 - asdf " error - Xpath 512 " X: 0 - return 8 -endfunction - -if F() != 1 - Xpath 1024 " X: 0 -endif - -delfunction F -delfunction G -delfunction H -delfunction I - -Xcheck 363 - - -"------------------------------------------------------------------------------- -" Test 10: :if, :elseif, :while argument parsing {{{1 -" -" A '"' or '|' in an argument expression must not be mixed up with -" a comment or a next command after a bar. Parsing errors should -" be recognized. -"------------------------------------------------------------------------------- - -XpathINIT - -function! MSG(enr, emsg) - let english = v:lang == "C" || v:lang =~ '^[Ee]n' - if a:enr == "" - Xout "TODO: Add message number for:" a:emsg - let v:errmsg = ":" . v:errmsg - endif - let match = 1 - if v:errmsg !~ '^'.a:enr.':' || (english && v:errmsg !~ a:emsg) - let match = 0 - if v:errmsg == "" - Xout "Message missing." - else - let v:errmsg = escape(v:errmsg, '"') - Xout "Unexpected message:" v:errmsg - endif - endif - return match -endfunction - -if 1 || strlen("\"") | Xpath 1 " X: 1 - Xpath 2 " X: 2 -endif -Xpath 4 " X: 4 - -if 0 -elseif 1 || strlen("\"") | Xpath 8 " X: 8 - Xpath 16 " X: 16 -endif -Xpath 32 " X: 32 - -while 1 || strlen("\"") | Xpath 64 " X: 64 - Xpath 128 " X: 128 - break -endwhile -Xpath 256 " X: 256 - -let v:errmsg = "" -if 1 ||| strlen("\"") | Xpath 512 " X: 0 - Xpath 1024 " X: 0 -endif -Xpath 2048 " X: 2048 -if !MSG('E15', "Invalid expression") - Xpath 4096 " X: 0 -endif - -let v:errmsg = "" -if 0 -elseif 1 ||| strlen("\"") | Xpath 8192 " X: 0 - Xpath 16384 " X: 0 -endif -Xpath 32768 " X: 32768 -if !MSG('E15', "Invalid expression") - Xpath 65536 " X: 0 -endif - -let v:errmsg = "" -while 1 ||| strlen("\"") | Xpath 131072 " X: 0 - Xpath 262144 " X: 0 - break -endwhile -Xpath 524288 " X: 524288 -if !MSG('E15', "Invalid expression") - Xpath 1048576 " X: 0 -endif - -delfunction MSG - -Xcheck 559615 - - -"------------------------------------------------------------------------------- -" Test 11: :if, :elseif, :while argument evaluation after abort {{{1 -" -" When code is skipped over due to an error, the boolean argument to -" an :if, :elseif, or :while must not be evaluated. -"------------------------------------------------------------------------------- - -XpathINIT - -let calls = 0 - -function! P(num) - let g:calls = g:calls + a:num " side effect on call - return 0 -endfunction - -if 1 - Xpath 1 " X: 1 - asdf " error - Xpath 2 " X: 0 - if P(1) " should not be called - Xpath 4 " X: 0 - elseif !P(2) " should not be called - Xpath 8 " X: 0 - else - Xpath 16 " X: 0 - endif - Xpath 32 " X: 0 - while P(4) " should not be called - Xpath 64 " X: 0 - endwhile - Xpath 128 " X: 0 -endif - -if calls % 2 - Xpath 256 " X: 0 -endif -if (calls/2) % 2 - Xpath 512 " X: 0 -endif -if (calls/4) % 2 - Xpath 1024 " X: 0 -endif -Xpath 2048 " X: 2048 - -unlet calls -delfunction P - -Xcheck 2049 - - -"------------------------------------------------------------------------------- -" Test 12: Expressions in braces in skipped code {{{1 -" -" In code skipped over due to an error or inactive conditional, -" an expression in braces as part of a variable or function name -" should not be evaluated. -"------------------------------------------------------------------------------- - -XpathINIT - -XloopINIT 1 8 - -function! NULL() - Xloop 1 " X: 0 - return 0 -endfunction - -function! ZERO() - Xloop 2 " X: 0 - return 0 -endfunction - -function! F0() - Xloop 4 " X: 0 -endfunction - -function! F1(arg) - Xpath 4096 " X: 0 -endfunction - -let V0 = 1 - -Xpath 8192 " X: 8192 -echo 0 ? F{NULL() + V{ZERO()}}() : 1 -XloopNEXT - -Xpath 16384 " X: 16384 -if 0 - Xpath 32768 " X: 0 - call F{NULL() + V{ZERO()}}() -endif -XloopNEXT - -Xpath 65536 " X: 65536 -if 1 - asdf " error - Xpath 131072 " X: 0 - call F1(F{NULL() + V{ZERO()}}()) -endif -XloopNEXT - -Xpath 262144 " X: 262144 -if 1 - asdf " error - Xpath 524288 " X: 0 - call F{NULL() + V{ZERO()}}() -endif - -Xcheck 352256 - - -"------------------------------------------------------------------------------- -" Test 13: Failure in argument evaluation for :while {{{1 -" -" A failure in the expression evaluation for the condition of a :while -" causes the whole :while loop until the matching :endwhile being -" ignored. Continuation is at the next following line. -"------------------------------------------------------------------------------- - -XpathINIT - -Xpath 1 " X: 1 -while asdf - Xpath 2 " X: 0 - while 1 - Xpath 4 " X: 0 - break - endwhile - Xpath 8 " X: 0 - break -endwhile -Xpath 16 " X: 16 - -while asdf | Xpath 32 | endwhile | Xpath 64 " X: 0 -Xpath 128 " X: 128 - -Xcheck 145 - - -"------------------------------------------------------------------------------- -" Test 14: Failure in argument evaluation for :if {{{1 -" -" A failure in the expression evaluation for the condition of an :if -" does not cause the corresponding :else or :endif being matched to -" a previous :if/:elseif. Neither of both branches of the failed :if -" are executed. -"------------------------------------------------------------------------------- - -XpathINIT -XloopINIT 1 256 - -function! F() - Xloop 1 " X: 1 + 256 * 1 - let x = 0 - if x " false - Xloop 2 " X: 0 + 256 * 0 - elseif !x " always true - Xloop 4 " X: 4 + 256 * 4 - let x = 1 - if g:boolvar " possibly undefined - Xloop 8 " X: 8 + 256 * 0 - else - Xloop 16 " X: 0 + 256 * 0 - endif - Xloop 32 " X: 32 + 256 * 32 - elseif x " never executed - Xloop 64 " X: 0 + 256 * 0 - endif - Xloop 128 " X: 128 + 256 * 128 -endfunction - -let boolvar = 1 -call F() - -XloopNEXT -unlet boolvar -call F() - -delfunction F - -Xcheck 42413 - - -"------------------------------------------------------------------------------- -" Test 15: Failure in argument evaluation for :if (bar) {{{1 -" -" Like previous test, except that the failing :if ... | ... | :endif -" is in a single line. -"------------------------------------------------------------------------------- - -XpathINIT -XloopINIT 1 256 - -function! F() - Xloop 1 " X: 1 + 256 * 1 - let x = 0 - if x " false - Xloop 2 " X: 0 + 256 * 0 - elseif !x " always true - Xloop 4 " X: 4 + 256 * 4 - let x = 1 - if g:boolvar | Xloop 8 | else | Xloop 16 | endif " X: 8 - Xloop 32 " X: 32 + 256 * 32 - elseif x " never executed - Xloop 64 " X: 0 + 256 * 0 - endif - Xloop 128 " X: 128 + 256 * 128 -endfunction - -let boolvar = 1 -call F() - -XloopNEXT -unlet boolvar -call F() - -delfunction F - -Xcheck 42413 - +" Tests 1 to 15 were moved to test_viml.vim +let Xtest = 16 "------------------------------------------------------------------------------- " Test 16: Double :else or :elseif after :else {{{1 @@ -6591,8 +5749,7 @@ function! F() if !caught && !$VIMNOERRTHROW Xpath 8192 " X: 0 endif - if caught ? !MSG('E55', 'Unmatched \\)') - \ : !MSG('E475', "Invalid argument") + if !MSG('E475', "Invalid argument") Xpath 16384 " X: 0 endif if !caught diff --git a/src/nvim/testdir/test88.in b/src/nvim/testdir/test88.in deleted file mode 100644 index 9e43f703e9..0000000000 --- a/src/nvim/testdir/test88.in +++ /dev/null @@ -1,99 +0,0 @@ -vim: set ft=vim - -Tests for correct display (cursor column position) with +conceal and -tabulators. - -STARTTEST -:so small.vim -:if !has('conceal') - e! test.ok - wq! test.out -:endif -:" Conceal settings. -:set conceallevel=2 -:set concealcursor=nc -:syntax match test /|/ conceal -:" Save current cursor position. Only works in <expr> mode, can't be used -:" with :normal because it moves the cursor to the command line. Thanks to ZyX -:" <zyx.vim@gmail.com> for the idea to use an <expr> mapping. -:let positions = [] -:nnoremap <expr> GG ":let positions += ['".screenrow().":".screencol()."']\n" -:" Start test. -/^start: -:normal ztj -GGk -:" We should end up in the same column when running these commands on the two -:" lines. -:normal ft -GGk -:normal $ -GGk -:normal 0j -GGk -:normal ft -GGk -:normal $ -GGk -:normal 0j0j -GGk -:" Same for next test block. -:normal ft -GGk -:normal $ -GGk -:normal 0j -GGk -:normal ft -GGk -:normal $ -GGk -:normal 0j0j -GGk -:" And check W with multiple tabs and conceals in a line. -:normal W -GGk -:normal W -GGk -:normal W -GGk -:normal $ -GGk -:normal 0j -GGk -:normal W -GGk -:normal W -GGk -:normal W -GGk -:normal $ -GGk -:set lbr -:normal $ -GGk -:set list listchars=tab:>- -:normal 0 -GGk -:normal W -GGk -:normal W -GGk -:normal W -GGk -:normal $ -GGk -:" Display result. -:call append('$', 'end:') -:call append('$', positions) -:/^end/,$wq! test.out -ENDTEST - -start: -.concealed. text -|concealed| text - - .concealed. text - |concealed| text - -.a. .b. .c. .d. -|a| |b| |c| |d| diff --git a/src/nvim/testdir/test88.ok b/src/nvim/testdir/test88.ok deleted file mode 100644 index 12949f274a..0000000000 --- a/src/nvim/testdir/test88.ok +++ /dev/null @@ -1,29 +0,0 @@ -end: -2:1 -2:17 -2:20 -3:1 -3:17 -3:20 -5:8 -5:25 -5:28 -6:8 -6:25 -6:28 -8:1 -8:9 -8:17 -8:25 -8:27 -9:1 -9:9 -9:17 -9:25 -9:26 -9:26 -9:1 -9:9 -9:17 -9:25 -9:26 diff --git a/src/nvim/testdir/test_marks.in b/src/nvim/testdir/test_marks.in deleted file mode 100644 index 23c2fb65fe..0000000000 --- a/src/nvim/testdir/test_marks.in +++ /dev/null @@ -1,34 +0,0 @@ -Tests for marks. - -STARTTEST -:so small.vim -:" test that a deleted mark is restored after delete-undo-redo-undo -:/^\t/+1 -:set nocp viminfo+=nviminfo -madduu -:let a = string(getpos("'a")) -:$put ='Mark after delete-undo-redo-undo: '.a -:'' -ENDTEST - - textline A - textline B - textline C - -STARTTEST -:" test that CTRL-A and CTRL-X updates last changed mark '[, ']. -:/^123/ -:execute "normal! \<C-A>`[v`]rAjwvjw\<C-X>`[v`]rX" -ENDTEST - -CTRL-A CTRL-X: -123 123 123 -123 123 123 -123 123 123 - -STARTTEST -:g/^STARTTEST/.,/^ENDTEST/d -:wq! test.out -ENDTEST - -Results: diff --git a/src/nvim/testdir/test_marks.ok b/src/nvim/testdir/test_marks.ok deleted file mode 100644 index e6c02ee7b0..0000000000 --- a/src/nvim/testdir/test_marks.ok +++ /dev/null @@ -1,16 +0,0 @@ -Tests for marks. - - - textline A - textline B - textline C - - -CTRL-A CTRL-X: -AAA 123 123 -123 XXXXXXX -XXX 123 123 - - -Results: -Mark after delete-undo-redo-undo: [0, 15, 2, 0] diff --git a/src/nvim/testdir/test_viml.vim b/src/nvim/testdir/test_viml.vim new file mode 100644 index 0000000000..9f0618bd45 --- /dev/null +++ b/src/nvim/testdir/test_viml.vim @@ -0,0 +1,930 @@ +" Test various aspects of the Vim language. +" Most of this was formerly in test49. + +"------------------------------------------------------------------------------- +" Test environment {{{1 +"------------------------------------------------------------------------------- + +com! XpathINIT let g:Xpath = '' +com! -nargs=1 -bar Xpath let g:Xpath = g:Xpath . <args> + +" Append a message to the "messages" file +func! Xout(text) + split messages + $put =a:text + wq +endfunc + +com! -nargs=1 Xout call Xout(<args>) + +" MakeScript() - Make a script file from a function. {{{2 +" +" Create a script that consists of the body of the function a:funcname. +" Replace any ":return" by a ":finish", any argument variable by a global +" variable, and and every ":call" by a ":source" for the next following argument +" in the variable argument list. This function is useful if similar tests are +" to be made for a ":return" from a function call or a ":finish" in a script +" file. +function! MakeScript(funcname, ...) + let script = tempname() + execute "redir! >" . script + execute "function" a:funcname + redir END + execute "edit" script + " Delete the "function" and the "endfunction" lines. Do not include the + " word "function" in the pattern since it might be translated if LANG is + " set. When MakeScript() is being debugged, this deletes also the debugging + " output of its line 3 and 4. + exec '1,/.*' . a:funcname . '(.*)/d' + /^\d*\s*endfunction\>/,$d + %s/^\d*//e + %s/return/finish/e + %s/\<a:\(\h\w*\)/g:\1/ge + normal gg0 + let cnt = 0 + while search('\<call\s*\%(\u\|s:\)\w*\s*(.*)', 'W') > 0 + let cnt = cnt + 1 + s/\<call\s*\%(\u\|s:\)\w*\s*(.*)/\='source ' . a:{cnt}/ + endwhile + g/^\s*$/d + write + bwipeout + return script +endfunction + +" ExecAsScript - Source a temporary script made from a function. {{{2 +" +" Make a temporary script file from the function a:funcname, ":source" it, and +" delete it afterwards. +function! ExecAsScript(funcname) + " Make a script from the function passed as argument. + let script = MakeScript(a:funcname) + + " Source and delete the script. + exec "source" script + call delete(script) +endfunction + +com! -nargs=1 -bar ExecAsScript call ExecAsScript(<f-args>) + + +"------------------------------------------------------------------------------- +" Test 1: :endwhile in function {{{1 +" +" Detect if a broken loop is (incorrectly) reactivated by the +" :endwhile. Use a :return to prevent an endless loop, and make +" this test first to get a meaningful result on an error before other +" tests will hang. +"------------------------------------------------------------------------------- + +function! T1_F() + Xpath 'a' + let first = 1 + while 1 + Xpath 'b' + if first + Xpath 'c' + let first = 0 + break + else + Xpath 'd' + return + endif + endwhile +endfunction + +function! T1_G() + Xpath 'h' + let first = 1 + while 1 + Xpath 'i' + if first + Xpath 'j' + let first = 0 + break + else + Xpath 'k' + return + endif + if 1 " unmatched :if + endwhile +endfunction + +func Test_endwhile_function() + XpathINIT + call T1_F() + Xpath 'F' + + try + call T1_G() + catch + " Catch missing :endif + call assert_true(v:exception =~ 'E171') + Xpath 'x' + endtry + Xpath 'G' + + call assert_equal('abcFhijxG', g:Xpath) +endfunc + +"------------------------------------------------------------------------------- +" Test 2: :endwhile in script {{{1 +" +" Detect if a broken loop is (incorrectly) reactivated by the +" :endwhile. Use a :finish to prevent an endless loop, and place +" this test before others that might hang to get a meaningful result +" on an error. +" +" This test executes the bodies of the functions T1_F and T1_G from +" the previous test as script files (:return replaced by :finish). +"------------------------------------------------------------------------------- + +func Test_endwhile_script() + XpathINIT + ExecAsScript T1_F + Xpath 'F' + + try + ExecAsScript T1_G + catch + " Catch missing :endif + call assert_true(v:exception =~ 'E171') + Xpath 'x' + endtry + Xpath 'G' + + call assert_equal('abcFhijxG', g:Xpath) +endfunc + +"------------------------------------------------------------------------------- +" Test 3: :if, :elseif, :while, :continue, :break {{{1 +"------------------------------------------------------------------------------- + +function Test_if_while() + XpathINIT + if 1 + Xpath 'a' + let loops = 3 + while loops > -1 " main loop: loops == 3, 2, 1 (which breaks) + if loops <= 0 + let break_err = 1 + let loops = -1 + else + Xpath 'b' . loops + endif + if (loops == 2) + while loops == 2 " dummy loop + Xpath 'c' . loops + let loops = loops - 1 + continue " stop dummy loop + Xpath 'd' . loops + endwhile + continue " continue main loop + Xpath 'e' . loops + elseif (loops == 1) + let p = 1 + while p " dummy loop + Xpath 'f' . loops + let p = 0 + break " break dummy loop + Xpath 'g' . loops + endwhile + Xpath 'h' . loops + unlet p + break " break main loop + Xpath 'i' . loops + endif + if (loops > 0) + Xpath 'j' . loops + endif + while loops == 3 " dummy loop + let loops = loops - 1 + endwhile " end dummy loop + endwhile " end main loop + Xpath 'k' + else + Xpath 'l' + endif + Xpath 'm' + if exists("break_err") + Xpath 'm' + unlet break_err + endif + + unlet loops + + call assert_equal('ab3j3b2c2b1f1h1km', g:Xpath) +endfunc + +"------------------------------------------------------------------------------- +" Test 4: :return {{{1 +"------------------------------------------------------------------------------- + +function! T4_F() + if 1 + Xpath 'a' + let loops = 3 + while loops > 0 " 3: 2: 1: + Xpath 'b' . loops + if (loops == 2) + Xpath 'c' . loops + return + Xpath 'd' . loops + endif + Xpath 'e' . loops + let loops = loops - 1 + endwhile + Xpath 'f' + else + Xpath 'g' + endif +endfunction + +function Test_return() + XpathINIT + call T4_F() + Xpath '4' + + call assert_equal('ab3e3b2c24', g:Xpath) +endfunction + + +"------------------------------------------------------------------------------- +" Test 5: :finish {{{1 +" +" This test executes the body of the function T4_F from the previous +" test as a script file (:return replaced by :finish). +"------------------------------------------------------------------------------- + +function Test_finish() + XpathINIT + ExecAsScript T4_F + Xpath '5' + + call assert_equal('ab3e3b2c25', g:Xpath) +endfunction + + + +"------------------------------------------------------------------------------- +" Test 6: Defining functions in :while loops {{{1 +" +" Functions can be defined inside other functions. An inner function +" gets defined when the outer function is executed. Functions may +" also be defined inside while loops. Expressions in braces for +" defining the function name are allowed. +" +" The functions are defined when sourcing the script, only the +" resulting path is checked in the test function. +"------------------------------------------------------------------------------- + +XpathINIT + +" The command CALL collects the argument of all its invocations in "calls" +" when used from a function (that is, when the global variable "calls" needs +" the "g:" prefix). This is to check that the function code is skipped when +" the function is defined. For inner functions, do so only if the outer +" function is not being executed. +" +let calls = "" +com! -nargs=1 CALL + \ if !exists("calls") && !exists("outer") | + \ let g:calls = g:calls . <args> | + \ endif + +let i = 0 +while i < 3 + let i = i + 1 + if i == 1 + Xpath 'a' + function! F1(arg) + CALL a:arg + let outer = 1 + + let j = 0 + while j < 1 + Xpath 'b' + let j = j + 1 + function! G1(arg) + CALL a:arg + endfunction + Xpath 'c' + endwhile + endfunction + Xpath 'd' + + continue + endif + + Xpath 'e' . i + function! F{i}(i, arg) + CALL a:arg + let outer = 1 + + if a:i == 3 + Xpath 'f' + endif + let k = 0 + while k < 3 + Xpath 'g' . k + let k = k + 1 + function! G{a:i}{k}(arg) + CALL a:arg + endfunction + Xpath 'h' . k + endwhile + endfunction + Xpath 'i' + +endwhile + +if exists("*G1") + Xpath 'j' +endif +if exists("*F1") + call F1("F1") + if exists("*G1") + call G1("G1") + endif +endif + +if exists("G21") || exists("G22") || exists("G23") + Xpath 'k' +endif +if exists("*F2") + call F2(2, "F2") + if exists("*G21") + call G21("G21") + endif + if exists("*G22") + call G22("G22") + endif + if exists("*G23") + call G23("G23") + endif +endif + +if exists("G31") || exists("G32") || exists("G33") + Xpath 'l' +endif +if exists("*F3") + call F3(3, "F3") + if exists("*G31") + call G31("G31") + endif + if exists("*G32") + call G32("G32") + endif + if exists("*G33") + call G33("G33") + endif +endif + +Xpath 'm' + +let g:test6_result = g:Xpath +let g:test6_calls = calls + +unlet calls +delfunction F1 +delfunction G1 +delfunction F2 +delfunction G21 +delfunction G22 +delfunction G23 +delfunction G31 +delfunction G32 +delfunction G33 + +function Test_defining_functions() + call assert_equal('ade2ie3ibcg0h1g1h2g2h3fg0h1g1h2g2h3m', g:test6_result) + call assert_equal('F1G1F2G21G22G23F3G31G32G33', g:test6_calls) +endfunc + +"------------------------------------------------------------------------------- +" Test 7: Continuing on errors outside functions {{{1 +" +" On an error outside a function, the script processing continues +" at the line following the outermost :endif or :endwhile. When not +" inside an :if or :while, the script processing continues at the next +" line. +"------------------------------------------------------------------------------- + +XpathINIT + +if 1 + Xpath 'a' + while 1 + Xpath 'b' + asdf + Xpath 'c' + break + endwhile | Xpath 'd' + Xpath 'e' +endif | Xpath 'f' +Xpath 'g' + +while 1 + Xpath 'h' + if 1 + Xpath 'i' + asdf + Xpath 'j' + endif | Xpath 'k' + Xpath 'l' + break +endwhile | Xpath 'm' +Xpath 'n' + +asdf +Xpath 'o' + +asdf | Xpath 'p' +Xpath 'q' + +let g:test7_result = g:Xpath + +func Test_error_in_script() + call assert_equal('abghinoq', g:test7_result) +endfunc + +"------------------------------------------------------------------------------- +" Test 8: Aborting and continuing on errors inside functions {{{1 +" +" On an error inside a function without the "abort" attribute, the +" script processing continues at the next line (unless the error was +" in a :return command). On an error inside a function with the +" "abort" attribute, the function is aborted and the script processing +" continues after the function call; the value -1 is returned then. +"------------------------------------------------------------------------------- + +XpathINIT + +function! T8_F() + if 1 + Xpath 'a' + while 1 + Xpath 'b' + asdf + Xpath 'c' + asdf | Xpath 'd' + Xpath 'e' + break + endwhile + Xpath 'f' + endif | Xpath 'g' + Xpath 'h' + + while 1 + Xpath 'i' + if 1 + Xpath 'j' + asdf + Xpath 'k' + asdf | Xpath 'l' + Xpath 'm' + endif + Xpath 'n' + break + endwhile | Xpath 'o' + Xpath 'p' + + return novar " returns (default return value 0) + Xpath 'q' + return 1 " not reached +endfunction + +function! T8_G() abort + if 1 + Xpath 'r' + while 1 + Xpath 's' + asdf " returns -1 + Xpath 't' + break + endwhile + Xpath 'v' + endif | Xpath 'w' + Xpath 'x' + + return -4 " not reached +endfunction + +function! T8_H() abort + while 1 + Xpath 'A' + if 1 + Xpath 'B' + asdf " returns -1 + Xpath 'C' + endif + Xpath 'D' + break + endwhile | Xpath 'E' + Xpath 'F' + + return -4 " not reached +endfunction + +" Aborted functions (T8_G and T8_H) return -1. +let g:test8_sum = (T8_F() + 1) - 4 * T8_G() - 8 * T8_H() +Xpath 'X' +let g:test8_result = g:Xpath + +func Test_error_in_function() + call assert_equal(13, g:test8_sum) + call assert_equal('abcefghijkmnoprsABX', g:test8_result) + + delfunction T8_F + delfunction T8_G + delfunction T8_H +endfunc + + +"------------------------------------------------------------------------------- +" Test 9: Continuing after aborted functions {{{1 +" +" When a function with the "abort" attribute is aborted due to an +" error, the next function back in the call hierarchy without an +" "abort" attribute continues; the value -1 is returned then. +"------------------------------------------------------------------------------- + +XpathINIT + +function! F() abort + Xpath 'a' + let result = G() " not aborted + Xpath 'b' + if result != 2 + Xpath 'c' + endif + return 1 +endfunction + +function! G() " no abort attribute + Xpath 'd' + if H() != -1 " aborted + Xpath 'e' + endif + Xpath 'f' + return 2 +endfunction + +function! H() abort + Xpath 'g' + call I() " aborted + Xpath 'h' + return 4 +endfunction + +function! I() abort + Xpath 'i' + asdf " error + Xpath 'j' + return 8 +endfunction + +if F() != 1 + Xpath 'k' +endif + +let g:test9_result = g:Xpath + +delfunction F +delfunction G +delfunction H +delfunction I + +func Test_func_abort() + call assert_equal('adgifb', g:test9_result) +endfunc + + +"------------------------------------------------------------------------------- +" Test 10: :if, :elseif, :while argument parsing {{{1 +" +" A '"' or '|' in an argument expression must not be mixed up with +" a comment or a next command after a bar. Parsing errors should +" be recognized. +"------------------------------------------------------------------------------- + +XpathINIT + +function! MSG(enr, emsg) + let english = v:lang == "C" || v:lang =~ '^[Ee]n' + if a:enr == "" + Xout "TODO: Add message number for:" a:emsg + let v:errmsg = ":" . v:errmsg + endif + let match = 1 + if v:errmsg !~ '^'.a:enr.':' || (english && v:errmsg !~ a:emsg) + let match = 0 + if v:errmsg == "" + Xout "Message missing." + else + let v:errmsg = escape(v:errmsg, '"') + Xout "Unexpected message:" v:errmsg + endif + endif + return match +endfunction + +if 1 || strlen("\"") | Xpath 'a' + Xpath 'b' +endif +Xpath 'c' + +if 0 +elseif 1 || strlen("\"") | Xpath 'd' + Xpath 'e' +endif +Xpath 'f' + +while 1 || strlen("\"") | Xpath 'g' + Xpath 'h' + break +endwhile +Xpath 'i' + +let v:errmsg = "" +if 1 ||| strlen("\"") | Xpath 'j' + Xpath 'k' +endif +Xpath 'l' +if !MSG('E15', "Invalid expression") + Xpath 'm' +endif + +let v:errmsg = "" +if 0 +elseif 1 ||| strlen("\"") | Xpath 'n' + Xpath 'o' +endif +Xpath 'p' +if !MSG('E15', "Invalid expression") + Xpath 'q' +endif + +let v:errmsg = "" +while 1 ||| strlen("\"") | Xpath 'r' + Xpath 's' + break +endwhile +Xpath 't' +if !MSG('E15', "Invalid expression") + Xpath 'u' +endif + +let g:test10_result = g:Xpath +delfunction MSG + +func Test_expr_parsing() + call assert_equal('abcdefghilpt', g:test10_result) +endfunc + + +"------------------------------------------------------------------------------- +" Test 11: :if, :elseif, :while argument evaluation after abort {{{1 +" +" When code is skipped over due to an error, the boolean argument to +" an :if, :elseif, or :while must not be evaluated. +"------------------------------------------------------------------------------- + +XpathINIT + +let calls = 0 + +function! P(num) + let g:calls = g:calls + a:num " side effect on call + return 0 +endfunction + +if 1 + Xpath 'a' + asdf " error + Xpath 'b' + if P(1) " should not be called + Xpath 'c' + elseif !P(2) " should not be called + Xpath 'd' + else + Xpath 'e' + endif + Xpath 'f' + while P(4) " should not be called + Xpath 'g' + endwhile + Xpath 'h' +endif +Xpath 'x' + +let g:test11_calls = calls +let g:test11_result = g:Xpath + +unlet calls +delfunction P + +func Test_arg_abort() + call assert_equal(0, g:test11_calls) + call assert_equal('ax', g:test11_result) +endfunc + + +"------------------------------------------------------------------------------- +" Test 12: Expressions in braces in skipped code {{{1 +" +" In code skipped over due to an error or inactive conditional, +" an expression in braces as part of a variable or function name +" should not be evaluated. +"------------------------------------------------------------------------------- + +XpathINIT + +function! NULL() + Xpath 'a' + return 0 +endfunction + +function! ZERO() + Xpath 'b' + return 0 +endfunction + +function! F0() + Xpath 'c' +endfunction + +function! F1(arg) + Xpath 'e' +endfunction + +let V0 = 1 + +Xpath 'f' +echo 0 ? F{NULL() + V{ZERO()}}() : 1 + +Xpath 'g' +if 0 + Xpath 'h' + call F{NULL() + V{ZERO()}}() +endif + +Xpath 'i' +if 1 + asdf " error + Xpath 'j' + call F1(F{NULL() + V{ZERO()}}()) +endif + +Xpath 'k' +if 1 + asdf " error + Xpath 'l' + call F{NULL() + V{ZERO()}}() +endif + +let g:test12_result = g:Xpath + +func Test_braces_skipped() + call assert_equal('fgik', g:test12_result) +endfunc + + +"------------------------------------------------------------------------------- +" Test 13: Failure in argument evaluation for :while {{{1 +" +" A failure in the expression evaluation for the condition of a :while +" causes the whole :while loop until the matching :endwhile being +" ignored. Continuation is at the next following line. +"------------------------------------------------------------------------------- + +XpathINIT + +Xpath 'a' +while asdf + Xpath 'b' + while 1 + Xpath 'c' + break + endwhile + Xpath 'd' + break +endwhile +Xpath 'e' + +while asdf | Xpath 'f' | endwhile | Xpath 'g' +Xpath 'h' +let g:test13_result = g:Xpath + +func Test_while_fail() + call assert_equal('aeh', g:test13_result) +endfunc + + +"------------------------------------------------------------------------------- +" Test 14: Failure in argument evaluation for :if {{{1 +" +" A failure in the expression evaluation for the condition of an :if +" does not cause the corresponding :else or :endif being matched to +" a previous :if/:elseif. Neither of both branches of the failed :if +" are executed. +"------------------------------------------------------------------------------- + +XpathINIT + +function! F() + Xpath 'a' + let x = 0 + if x " false + Xpath 'b' + elseif !x " always true + Xpath 'c' + let x = 1 + if g:boolvar " possibly undefined + Xpath 'd' + else + Xpath 'e' + endif + Xpath 'f' + elseif x " never executed + Xpath 'g' + endif + Xpath 'h' +endfunction + +let boolvar = 1 +call F() +Xpath '-' + +unlet boolvar +call F() +let g:test14_result = g:Xpath + +delfunction F + +func Test_if_fail() + call assert_equal('acdfh-acfh', g:test14_result) +endfunc + + +"------------------------------------------------------------------------------- +" Test 15: Failure in argument evaluation for :if (bar) {{{1 +" +" Like previous test, except that the failing :if ... | ... | :endif +" is in a single line. +"------------------------------------------------------------------------------- + +XpathINIT + +function! F() + Xpath 'a' + let x = 0 + if x " false + Xpath 'b' + elseif !x " always true + Xpath 'c' + let x = 1 + if g:boolvar | Xpath 'd' | else | Xpath 'e' | endif + Xpath 'f' + elseif x " never executed + Xpath 'g' + endif + Xpath 'h' +endfunction + +let boolvar = 1 +call F() +Xpath '-' + +unlet boolvar +call F() +let g:test15_result = g:Xpath + +delfunction F + +func Test_if_bar_fail() + call assert_equal('acdfh-acfh', g:test15_result) +endfunc + + +"------------------------------------------------------------------------------- +" Test 16: Recognizing {} in variable name. {{{1 +"------------------------------------------------------------------------------- + +func Test_curlies() + let s:var = 66 + let ns = 's' + call assert_equal(66, {ns}:var) + + let g:a = {} + let g:b = 't' + let g:a[g:b] = 77 + call assert_equal(77, g:a['t']) +endfunc + + +"------------------------------------------------------------------------------- +" Modelines {{{1 +" vim: ts=8 sw=4 tw=80 fdm=marker +" vim: fdt=substitute(substitute(foldtext(),\ '\\%(^+--\\)\\@<=\\(\\s*\\)\\(.\\{-}\\)\:\ \\%(\"\ \\)\\=\\(Test\ \\d*\\)\:\\s*',\ '\\3\ (\\2)\:\ \\1',\ \"\"),\ '\\(Test\\s*\\)\\(\\d\\)\\D\\@=',\ '\\1\ \\2',\ "") +"------------------------------------------------------------------------------- diff --git a/src/nvim/undo.c b/src/nvim/undo.c index 4a8a24d79d..7d9b2c7c3b 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -1782,7 +1782,13 @@ void undo_time(long step, int sec, int file, int absolute) /* "target" is the node below which we want to be. * Init "closest" to a value we can't reach. */ if (absolute) { - target = step; + if (step == 0) { + // target 0 does not exist, got to 1 and above it. + target = 1; + above = true; + } else { + target = step; + } closest = -1; } else { /* When doing computations with time_t subtract starttime, because diff --git a/src/nvim/version.c b/src/nvim/version.c index d04bc42db5..ddc1b5a9a8 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -69,8 +69,395 @@ static char *features[] = { // clang-format off static int included_patches[] = { - 1366, + 1757, + 1755, + 1654, + 1652, + 1643, + 1641, + + // 1600 NA + // 1599 NA + // 1598 NA + // 1597 NA + // 1596, + // 1595 NA + // 1594 NA + // 1593 NA + // 1592, + // 1591, + // 1590, + // 1589, + // 1588, + // 1587 NA + // 1586, + // 1585, + // 1584 NA + // 1583 NA + // 1582, + // 1581, + // 1580, + // 1579, + // 1578, + // 1577, + 1576, + // 1575 NA + 1574, + // 1573, + // 1572 NA + // 1571, + 1570, + 1569, + // 1568, + // 1567, + // 1566 NA + // 1565, + // 1564, + // 1563, + // 1562, + // 1561 NA + // 1560, + // 1559, + // 1558, + // 1557, + // 1556, + // 1555, + // 1554, + // 1553, + // 1552, + // 1551, + // 1550, + // 1549, + // 1548, + // 1547, + // 1546, + // 1545 NA + // 1544 NA + // 1543 NA + // 1542 NA + // 1541 NA + // 1540 NA + // 1539 NA + // 1538 NA + // 1537 NA + // 1536 NA + // 1535, + // 1534 NA + // 1533, + // 1532 NA + // 1531 NA + // 1530 NA + // 1529 NA + // 1528, + // 1527 NA + // 1526 NA + // 1525 NA + // 1524 NA + // 1523 NA + // 1522 NA + // 1521, + // 1520 NA + // 1519 NA + // 1518 NA + // 1517 NA + // 1516, + // 1515 NA + // 1514 NA + // 1513, + // 1512 NA + 1511, + // 1510 NA + // 1509 NA + // 1508 NA + // 1507 NA + // 1506 NA + // 1505 NA + // 1504 NA + // 1503 NA + // 1502 NA + // 1501 NA + 1500, + // 1499, + // 1498 NA + // 1497 NA + // 1496 NA + // 1495 NA + // 1494, + // 1493 NA + // 1492, + // 1491, + // 1490 NA + // 1489 NA + // 1488 NA + // 1487 NA + // 1486, + // 1485 NA + // 1484 NA + // 1483 NA + // 1482 NA + // 1481 NA + // 1480, + // 1479, + // 1478, + // 1477, + // 1476 NA + // 1475 NA + // 1474 NA + // 1473 NA + // 1472 NA + // 1471 NA + // 1470 NA + // 1469 NA + // 1468, + // 1467 NA + // 1466 NA + // 1465 NA + // 1464, + // 1463 NA + // 1462 NA + // 1461 NA + // 1460 NA + // 1459 NA + // 1458 NA + // 1457 NA + // 1456, + // 1455 NA + // 1454 NA + // 1453 NA + // 1452 NA + // 1451 NA + // 1450 NA + // 1449 NA + // 1448 NA + // 1447 NA + // 1446 NA + // 1445 NA + // 1444 NA + // 1443 NA + // 1442 NA + // 1441 NA + // 1440 NA + // 1439 NA + // 1438 NA + // 1437 NA + // 1436 NA + // 1435 NA + // 1434 NA + // 1433 NA + // 1432 NA + // 1431 NA + // 1430 NA + // 1429 NA + // 1428 NA + // 1427 NA + // 1426 NA + 1425, + // 1424 NA + // 1423 NA + // 1422 NA + // 1421 NA + // 1420 NA + // 1419 NA + // 1418 NA + // 1417 NA + // 1416 NA + // 1415 NA + // 1414 NA + // 1413 NA + // 1412 NA + // 1411 NA + 1410, + // 1409 NA + // 1408 NA + // 1407 NA + 1406, + 1405, + // 1404 NA + // 1403 NA + // 1402 NA + // 1401, + // 1400 NA + // 1399 NA + // 1398 NA + // 1397, + // 1396, + // 1395 NA + // 1394, + // 1393 NA + // 1392 NA + // 1391 NA + // 1390 NA + // 1389 NA + // 1388, + // 1387 NA + // 1386 NA + // 1385 NA + // 1384, + // 1383 NA + // 1382 NA + // 1381 NA + // 1380 NA + // 1379 NA + // 1378 NA + // 1377 NA + // 1376 NA + // 1375 NA + // 1374 NA + // 1373 NA + // 1372 NA + // 1371 NA + // 1370 NA + // 1369 NA + // 1368 NA + // 1367 NA + 1366, + // 1365, + // 1364 NA + // 1363 NA + // 1362 NA + // 1361 NA + // 1360 NA + // 1359 NA + // 1358 NA + // 1357 NA + // 1356 NA + // 1355 NA + // 1354 NA + // 1353 NA + // 1352, + // 1351 NA + // 1350 NA + // 1349 NA + // 1348 NA + // 1347, + 1346, + // 1345 NA + // 1344 NA + // 1343 NA + // 1342 NA + // 1341 NA + // 1340 NA + // 1339 NA + // 1338 NA + // 1337 NA + // 1336 NA + // 1335 NA + // 1334 NA + // 1333 NA + // 1332 NA + // 1331 NA + // 1330 NA + // 1329 NA + // 1328 NA + // 1327 NA + // 1326 NA + // 1325 NA + // 1324 NA + // 1323 NA + // 1322 NA + // 1321 NA + // 1320 NA + // 1319 NA + // 1318 NA + // 1317 NA + // 1316 NA + // 1315 NA + // 1314 NA + // 1313 NA + // 1312 NA + // 1311 NA + // 1310 NA + 1309, + // 1308 NA + // 1307 NA + // 1306 NA + // 1305, + 1304, + // 1303 NA + // 1302 NA + // 1301 NA + // 1300, + // 1299 NA + // 1298 NA + // 1297 NA + // 1296, + // 1295 NA + // 1294 NA + // 1293 NA + 1292, + // 1291 NA + // 1290 NA + // 1289 NA + // 1288 NA + // 1287 NA + // 1286 NA + // 1285, + 1284, + // 1283 NA + 1282, + // 1281, + // 1280 NA + // 1279 NA + // 1278 NA + // 1277 NA + // 1276, + // 1275 NA + // 1274 NA + // 1273, + // 1272 NA + 1271, + // 1270 NA + 1269, + // 1268 NA + 1267, + // 1266 + // 1265 NA + // 1264 NA + // 1263 NA + // 1262 NA + // 1261 NA + // 1260 NA + // 1259, + // 1258 NA + // 1257 NA + // 1256 NA + // 1255 NA + // 1254 NA + // 1253 NA + // 1252 NA + // 1251 NA + // 1250 NA + // 1249 NA + // 1248 NA + // 1247 NA + // 1246 NA + // 1245 NA + // 1244 NA + // 1243 NA + // 1242 NA + // 1241 NA + // 1240 NA + // 1239 NA + // 1238 NA + // 1237, + // 1236, + // 1235 NA + // 1234 NA + // 1233 NA + // 1232 NA + // 1231 NA + // 1230 NA + // 1229 NA + 1228, + // 1227 NA + // 1226 NA + // 1225 NA + // 1224 NA + // 1223, + // 1222 NA + // 1221 NA + // 1220 NA // 1219 NA // 1218 NA // 1217 NA @@ -102,41 +489,41 @@ static int included_patches[] = { // 1191 NA // 1190 NA // 1189 NA - // 1188, + // 1188 NA // 1187 NA // 1186, // 1185 NA // 1184 NA // 1183 NA // 1182 NA - // 1181, + 1181, 1180, // 1179, - // 1178, + 1178, // 1177 NA // 1176 NA // 1175 NA // 1174 NA - // 1173, + 1173, // 1172 NA // 1171 NA // 1170 NA // 1169 NA - // 1168, - // 1167, - // 1166, + 1168, + 1167, + 1166, // 1165 NA - // 1164, - // 1163, + 1164, + 1163, // 1162 NA // 1161, - // 1160, + 1160, // 1159 NA // 1158 NA - // 1157, - // 1156, + 1157, + // 1156 NA // 1155 NA - // 1154, + // 1154 NA // 1153, // 1152 NA // 1151, @@ -149,14 +536,14 @@ static int included_patches[] = { 1144, 1143, // 1142, - // 1141, + 1141, // 1140, // 1139 NA // 1138 NA 1137, // 1136, - // 1135 NA, - // 1134 NA, + // 1135 NA + // 1134 NA // 1133 NA // 1132, // 1131 NA @@ -170,22 +557,22 @@ static int included_patches[] = { // 1123, // 1122 NA // 1121, - // 1120, + 1120, // 1119, // 1118, - // 1117, - // 1116, + 1117, + 1116, // 1115 NA - // 1114, - // 1113, + 1114, + 1113, 1112, // 1111, // 1110, // 1109 NA // 1108, - // 1107, + 1107, // 1106 NA - // 1105, + 1105, // 1104 NA // 1103 NA // 1102, @@ -207,30 +594,30 @@ static int included_patches[] = { // 1086, 1085, 1084, - // 1083 NA, - // 1082 NA, + // 1083 NA + // 1082 NA 1081, - // 1080 NA, + // 1080 NA // 1079, - // 1078 NA, - // 1077 NA, + // 1078 NA + // 1077 NA 1076, // 1075, - // 1074 NA, + // 1074 NA // 1073, 1072, // 1071, - // 1070 NA, - // 1069 NA, + // 1070 NA + // 1069 NA // 1068, - // 1067 NA, - // 1066 NA, + // 1067 NA + // 1066 NA 1065, // 1064, - // 1063 NA, - // 1062 NA, + // 1063 NA + // 1062 NA // 1061, - // 1060 NA, + // 1060 NA // 1059, // 1058, // 1057, @@ -245,52 +632,52 @@ static int included_patches[] = { // 1048, // 1047, // 1046, - // 1045 NA, - // 1044 NA, - // 1043 NA, + // 1045 NA + // 1044 NA + // 1043 NA // 1042, 1041, - // 1040 NA, + // 1040 NA // 1039, - // 1038 NA, + // 1038 NA // 1037, // 1036, // 1035, // 1034, - // 1033 NA, + // 1033 NA 1032, // 1031 NA, - // 1030, + 1030, 1029, - // 1028 NA, + // 1028 NA 1027, - // 1026 NA, - // 1025 NA, - // 1024 NA, - // 1023 NA, - // 1022 NA, - // 1021 NA, - // 1020 NA, - // 1019 NA, + // 1026 NA + // 1025 NA + // 1024 NA + // 1023 NA + // 1022 NA + // 1021 NA + // 1020 NA + // 1019 NA // 1018, // 1017, - // 1016 NA, + // 1016 NA // 1015, - // 1014 NA, + // 1014 NA 1013, - // 1012 NA, - // 1011 NA, + // 1012 NA + // 1011 NA // 1010, - // 1009 NA, - // 1008 NA, + // 1009 NA + // 1008 NA // 1007, // 1006, // 1005, // 1004 NA, // 1003 NA, // 1002 NA, - // 1001, - // 1000, + 1001, + 1000, // 999 NA // 998, // 997 NA @@ -317,7 +704,7 @@ static int included_patches[] = { // 976 NA 975, 974, - // 973, + 973, 972, // 971 NA // 970 NA @@ -332,8 +719,8 @@ static int included_patches[] = { 961, // 960 NA // 959 NA - // 958, - // 957, + 958, + 957, // 956 NA 955, // 954 NA @@ -348,8 +735,8 @@ static int included_patches[] = { 945, 944, // 943 NA - // 942, - // 941, + 942, + 941, // 940 NA 939, // 938 NA @@ -471,7 +858,7 @@ static int included_patches[] = { // 822, // 821 NA 820, - // 819, + 819, 818, 817, 816, @@ -1046,13 +1433,13 @@ static int included_patches[] = { 247, // 246 NA 245, - // 244, + // 244 NA 243, 242, 241, 240, 239, - // 238, + // 238 NA 237, 236, 235, diff --git a/src/nvim/vim.h b/src/nvim/vim.h index 545b903d2f..623ea19e36 100644 --- a/src/nvim/vim.h +++ b/src/nvim/vim.h @@ -271,26 +271,11 @@ enum { # define vim_strpbrk(s, cs) (char_u *)strpbrk((char *)(s), (char *)(cs)) -#define MSG(s) msg((char_u *)(s)) -#define MSG_ATTR(s, attr) msg_attr((char_u *)(s), (attr)) -#define EMSG(s) emsg((char_u *)(s)) -#define EMSG2(s, p) emsg2((char_u *)(s), (char_u *)(p)) -#define EMSG3(s, p, q) emsg3((char_u *)(s), (char_u *)(p), \ - (char_u *)(q)) -#define EMSGN(s, n) emsgn((char_u *)(s), (int64_t)(n)) -#define EMSGU(s, n) emsgu((char_u *)(s), (uint64_t)(n)) -#define OUT_STR(s) out_str((char_u *)(s)) -#define OUT_STR_NF(s) out_str_nf((char_u *)(s)) -#define MSG_PUTS(s) msg_puts((char_u *)(s)) -#define MSG_PUTS_ATTR(s, a) msg_puts_attr((char_u *)(s), (a)) -#define MSG_PUTS_TITLE(s) msg_puts_title((char_u *)(s)) -#define MSG_PUTS_LONG(s) msg_puts_long_attr((char_u *)(s), 0) -#define MSG_PUTS_LONG_ATTR(s, a) msg_puts_long_attr((char_u *)(s), (a)) - -/* Prefer using emsg3(), because perror() may send the output to the wrong - * destination and mess up the screen. */ -#define PERROR(msg) \ - (void) emsg3((char_u *) "%s: %s", (char_u *)msg, (char_u *)strerror(errno)) +#include "nvim/message.h" + +// Prefer using emsgf(), because perror() may send the output to the wrong +// destination and mess up the screen. +#define PERROR(msg) (void) emsgf("%s: %s", msg, strerror(errno)) #define SHOWCMD_COLS 10 /* columns needed by shown command */ #define STL_MAX_ITEM 80 /* max nr of %<flag> in statusline */ diff --git a/src/nvim/window.c b/src/nvim/window.c index 1b8c953596..93a7a58678 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -2948,7 +2948,7 @@ void free_tabpage(tabpage_T *tp) unref_var_dict(tp->tp_vars); - + xfree(tp->localdir); // Free tab-local working directory xfree(tp); } @@ -3560,18 +3560,24 @@ static void win_enter_ext(win_T *wp, bool undo_sync, int curwin_invalid, int tri curwin->w_cursor.coladd = 0; changed_line_abv_curs(); /* assume cursor position needs updating */ - if (curwin->w_localdir != NULL) { - /* Window has a local directory: Save current directory as global - * directory (unless that was done already) and change to the local - * directory. */ + // The new directory is either the local directory of the window, of the tab + // or NULL. + char_u *new_dir = curwin->w_localdir ? curwin->w_localdir : curtab->localdir; + + if (new_dir) { + // Window/tab has a local directory: Save current directory as global + // directory (unless that was done already) and change to the local + // directory. if (globaldir == NULL) { char_u cwd[MAXPATHL]; - if (os_dirname(cwd, MAXPATHL) == OK) + if (os_dirname(cwd, MAXPATHL) == OK) { globaldir = vim_strsave(cwd); + } + } + if (os_chdir((char *)new_dir) == 0) { + shorten_fnames(true); } - if (os_chdir((char *)curwin->w_localdir) == 0) - shorten_fnames(TRUE); } else if (globaldir != NULL) { /* Window doesn't have a local directory and we are not in the global * directory: Change to the global directory. */ diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index c924988d06..0eefa25a13 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -1,8 +1,9 @@ -- Sanity checks for buffer_* API calls via msgpack-rpc local helpers = require('test.functional.helpers') -local clear, nvim, buffer, curbuf, curwin, eq, ok = - helpers.clear, helpers.nvim, helpers.buffer, helpers.curbuf, helpers.curwin, - helpers.eq, helpers.ok +local clear, nvim, buffer = helpers.clear, helpers.nvim, helpers.buffer +local curbuf, curwin, eq = helpers.curbuf, helpers.curwin, helpers.eq +local curbufmeths, ok = helpers.curbufmeths, helpers.ok +local funcs = helpers.funcs describe('buffer_* functions', function() before_each(clear) @@ -35,10 +36,11 @@ describe('buffer_* functions', function() eq('', curbuf('get_line', 0)) end) - it('get_line: out-of-bounds returns empty string', function() + it('get_line: out-of-bounds is an error', function() curbuf('set_line', 0, 'line1.a') - eq('', curbuf('get_line', 1)) - eq('', curbuf('get_line', -2)) + eq(1, curbuf('line_count')) -- sanity + eq(false, pcall(curbuf, 'get_line', 1)) + eq(false, pcall(curbuf, 'get_line', -2)) end) it('set_line, del_line: out-of-bounds is an error', function() @@ -68,14 +70,16 @@ describe('buffer_* functions', function() eq({}, curbuf('get_line_slice', -4, -5, true, true)) end) - it('set_line_slice: out-of-bounds is an error', function() + it('set_line_slice: out-of-bounds extends past end', function() curbuf('set_line_slice', 0, 0, true, true, {'a', 'b', 'c'}) eq({'a', 'b', 'c'}, curbuf('get_line_slice', 0, 2, true, true)) --sanity eq({'c'}, curbuf('get_line_slice', -1, 4, true, true)) eq({'a', 'b', 'c'}, curbuf('get_line_slice', 0, 5, true, true)) - eq(false, pcall(curbuf, 'set_line_slice', 4, 5, true, true, {'d'})) - eq(false, pcall(curbuf, 'set_line_slice', -4, -5, true, true, {'d'})) + curbuf('set_line_slice', 4, 5, true, true, {'d'}) + eq({'a', 'b', 'c', 'd'}, curbuf('get_line_slice', 0, 5, true, true)) + curbuf('set_line_slice', -4, -5, true, true, {'e'}) + eq({'e', 'a', 'b', 'c', 'd'}, curbuf('get_line_slice', 0, 5, true, true)) end) it('works', function() @@ -101,11 +105,144 @@ describe('buffer_* functions', function() end) end) - describe('{get,set}_var', function() + describe('{get,set}_lines', function() + local get_lines, set_lines = curbufmeths.get_lines, curbufmeths.set_lines + local line_count = curbufmeths.line_count + + it('has correct line_count when inserting and deleting', function() + eq(1, line_count()) + set_lines(-1, -1, true, {'line'}) + eq(2, line_count()) + set_lines(-1, -1, true, {'line'}) + eq(3, line_count()) + set_lines(-2, -1, true, {}) + eq(2, line_count()) + set_lines(-2, -1, true, {}) + set_lines(-2, -1, true, {}) + -- There's always at least one line + eq(1, line_count()) + end) + + it('can get, set and delete a single line', function() + eq({''}, get_lines(0, 1, true)) + set_lines(0, 1, true, {'line1'}) + eq({'line1'}, get_lines(0, 1, true)) + set_lines(0, 1, true, {'line2'}) + eq({'line2'}, get_lines(0, 1, true)) + set_lines(0, 1, true, {}) + eq({''}, get_lines(0, 1, true)) + end) + + it('can get a single line with strict indexing', function() + set_lines(0, 1, true, {'line1.a'}) + eq(1, line_count()) -- sanity + eq(false, pcall(get_lines, 1, 2, true)) + eq(false, pcall(get_lines, -3, -2, true)) + end) + + it('can get a single line with non-strict indexing', function() + set_lines(0, 1, true, {'line1.a'}) + eq(1, line_count()) -- sanity + eq({}, get_lines(1, 2, false)) + eq({}, get_lines(-3, -2, false)) + end) + + it('can set and delete a single line with strict indexing', function() + set_lines(0, 1, true, {'line1.a'}) + eq(false, pcall(set_lines, 1, 2, true, {'line1.b'})) + eq(false, pcall(set_lines, -3, -2, true, {'line1.c'})) + eq({'line1.a'}, get_lines(0, -1, true)) + eq(false, pcall(set_lines, 1, 2, true, {})) + eq(false, pcall(set_lines, -3, -2, true, {})) + eq({'line1.a'}, get_lines(0, -1, true)) + end) + + it('can set and delete a single line with non-strict indexing', function() + set_lines(0, 1, true, {'line1.a'}) + set_lines(1, 2, false, {'line1.b'}) + set_lines(-4, -3, false, {'line1.c'}) + eq({'line1.c', 'line1.a', 'line1.b'}, get_lines(0, -1, true)) + set_lines(3, 4, false, {}) + set_lines(-5, -4, false, {}) + eq({'line1.c', 'line1.a', 'line1.b'}, get_lines(0, -1, true)) + end) + + it('can handle NULs', function() + set_lines(0, 1, true, {'ab\0cd'}) + eq({'ab\0cd'}, get_lines(0, -1, true)) + end) + + it('works with multiple lines', function() + eq({''}, get_lines(0, -1, true)) + -- Replace buffer + for _, mode in pairs({false, true}) do + set_lines(0, -1, mode, {'a', 'b', 'c'}) + eq({'a', 'b', 'c'}, get_lines(0, -1, mode)) + eq({'b', 'c'}, get_lines(1, -1, mode)) + eq({'b'}, get_lines(1, 2, mode)) + eq({}, get_lines(1, 1, mode)) + eq({'a', 'b'}, get_lines(0, -2, mode)) + eq({'b'}, get_lines(1, -2, mode)) + eq({'b', 'c'}, get_lines(-3, -1, mode)) + set_lines(1, 2, mode, {'a', 'b', 'c'}) + eq({'a', 'a', 'b', 'c', 'c'}, get_lines(0, -1, mode)) + set_lines(-2, -1, mode, {'a', 'b', 'c'}) + eq({'a', 'a', 'b', 'c', 'a', 'b', 'c'}, + get_lines(0, -1, mode)) + set_lines(0, -4, mode, {}) + eq({'a', 'b', 'c'}, get_lines(0, -1, mode)) + set_lines(0, -1, mode, {}) + eq({''}, get_lines(0, -1, mode)) + end + end) + + it('can get line ranges with non-strict indexing', function() + set_lines(0, -1, true, {'a', 'b', 'c'}) + eq({'a', 'b', 'c'}, get_lines(0, -1, true)) --sanity + + eq({}, get_lines(3, 4, false)) + eq({}, get_lines(3, 10, false)) + eq({}, get_lines(-5, -5, false)) + eq({}, get_lines(3, -1, false)) + eq({}, get_lines(-3, -4, false)) + end) + + it('can get line ranges with strict indexing', function() + set_lines(0, -1, true, {'a', 'b', 'c'}) + eq({'a', 'b', 'c'}, get_lines(0, -1, true)) --sanity + + eq(false, pcall(get_lines, 3, 4, true)) + eq(false, pcall(get_lines, 3, 10, true)) + eq(false, pcall(get_lines, -5, -5, true)) + -- empty or inverted ranges are not errors + eq({}, get_lines(3, -1, true)) + eq({}, get_lines(-3, -4, true)) + end) + + it('set_line_slice: out-of-bounds can extend past end', function() + set_lines(0, -1, true, {'a', 'b', 'c'}) + eq({'a', 'b', 'c'}, get_lines(0, -1, true)) --sanity + + eq({'c'}, get_lines(-2, 5, false)) + eq({'a', 'b', 'c'}, get_lines(0, 6, false)) + eq(false, pcall(set_lines, 4, 6, true, {'d'})) + set_lines(4, 6, false, {'d'}) + eq({'a', 'b', 'c', 'd'}, get_lines(0, -1, true)) + eq(false, pcall(set_lines, -6, -6, true, {'e'})) + set_lines(-6, -6, false, {'e'}) + eq({'e', 'a', 'b', 'c', 'd'}, get_lines(0, -1, true)) + end) + + end) + + describe('{get,set,del}_var', function() it('works', function() curbuf('set_var', 'lua', {1, 2, {['3'] = 1}}) eq({1, 2, {['3'] = 1}}, curbuf('get_var', 'lua')) eq({1, 2, {['3'] = 1}}, nvim('eval', 'b:lua')) + eq(1, funcs.exists('b:lua')) + curbufmeths.del_var('lua') + eq(0, funcs.exists('b:lua')) end) end) diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua index c0099e44c4..1b33275803 100644 --- a/test/functional/api/server_requests_spec.lua +++ b/test/functional/api/server_requests_spec.lua @@ -165,8 +165,8 @@ describe('server -> client', function() eq('SOME TEXT', eval("rpcrequest(vim, 'buffer_get_line', "..buf..", 0)")) - -- Call get_line_slice(buf, range [0,0], includes start, includes end) - eq({'SOME TEXT'}, eval("rpcrequest(vim, 'buffer_get_line_slice', "..buf..", 0, 0, 1, 1)")) + -- Call get_lines(buf, range [0,0], strict_indexing) + eq({'SOME TEXT'}, eval("rpcrequest(vim, 'buffer_get_lines', "..buf..", 0, 1, 1)")) end) it('returns an error if the request failed', function() diff --git a/test/functional/api/tabpage_spec.lua b/test/functional/api/tabpage_spec.lua index 9937e0c72e..0f59bbea7b 100644 --- a/test/functional/api/tabpage_spec.lua +++ b/test/functional/api/tabpage_spec.lua @@ -3,6 +3,9 @@ local helpers = require('test.functional.helpers') local clear, nvim, tabpage, curtab, eq, ok = helpers.clear, helpers.nvim, helpers.tabpage, helpers.curtab, helpers.eq, helpers.ok +local wait = helpers.wait +local curtabmeths = helpers.curtabmeths +local funcs = helpers.funcs describe('tabpage_* functions', function() before_each(clear) @@ -21,11 +24,14 @@ describe('tabpage_* functions', function() end) end) - describe('{get,set}_var', function() + describe('{get,set,del}_var', function() it('works', function() curtab('set_var', 'lua', {1, 2, {['3'] = 1}}) eq({1, 2, {['3'] = 1}}, curtab('get_var', 'lua')) eq({1, 2, {['3'] = 1}}, nvim('eval', 't:lua')) + eq(1, funcs.exists('t:lua')) + curtabmeths.del_var('lua') + eq(0, funcs.exists('t:lua')) end) end) diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 9c9759adf6..389badb423 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3,7 +3,9 @@ local helpers = require('test.functional.helpers') local Screen = require('test.functional.ui.screen') local clear, nvim, eq, neq = helpers.clear, helpers.nvim, helpers.eq, helpers.neq local ok, nvim_async, feed = helpers.ok, helpers.nvim_async, helpers.feed -local os_is_windows = helpers.os_is_windows +local os_name = helpers.os_name +local meths = helpers.meths +local funcs = helpers.funcs describe('vim_* functions', function() before_each(clear) @@ -17,7 +19,7 @@ describe('vim_* functions', function() nvim('command', 'w') local f = io.open(fname) ok(f ~= nil) - if os_is_windows() then + if os_name() == 'windows' then eq('testing\r\napi\r\n', f:read('*a')) else eq('testing\napi\n', f:read('*a')) @@ -70,20 +72,31 @@ describe('vim_* functions', function() end) end) - describe('{get,set}_var', function() + describe('{get,set,del}_var', function() it('works', function() nvim('set_var', 'lua', {1, 2, {['3'] = 1}}) eq({1, 2, {['3'] = 1}}, nvim('get_var', 'lua')) eq({1, 2, {['3'] = 1}}, nvim('eval', 'g:lua')) + eq(1, funcs.exists('g:lua')) + meths.del_var('lua') + eq(0, funcs.exists('g:lua')) end) it('set_var returns the old value', function() local val1 = {1, 2, {['3'] = 1}} local val2 = {4, 7} - eq(nil, nvim('set_var', 'lua', val1)) + eq(NIL, nvim('set_var', 'lua', val1)) eq(val1, nvim('set_var', 'lua', val2)) end) + it('del_var returns the old value', function() + local val1 = {1, 2, {['3'] = 1}} + local val2 = {4, 7} + eq(NIL, meths.set_var('lua', val1)) + eq(val1, meths.set_var('lua', val2)) + eq(val2, meths.del_var('lua')) + end) + it('truncates values with NULs in them', function() nvim('set_var', 'xxx', 'ab\0cd') eq('ab', nvim('get_var', 'xxx')) diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index 17aacafe9b..92a33b4cdb 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -5,6 +5,8 @@ local clear, nvim, curbuf, curbuf_contents, window, curwin, eq, neq, helpers.curbuf_contents, helpers.window, helpers.curwin, helpers.eq, helpers.neq, helpers.ok, helpers.feed, helpers.insert, helpers.eval local wait = helpers.wait +local curwinmeths = helpers.curwinmeths +local funcs = helpers.funcs -- check if str is visible at the beginning of some line local function is_visible(str) @@ -126,11 +128,14 @@ describe('window_* functions', function() end) end) - describe('{get,set}_var', function() + describe('{get,set,del}_var', function() it('works', function() curwin('set_var', 'lua', {1, 2, {['3'] = 1}}) eq({1, 2, {['3'] = 1}}, curwin('get_var', 'lua')) eq({1, 2, {['3'] = 1}}, nvim('eval', 'w:lua')) + eq(1, funcs.exists('w:lua')) + curwinmeths.del_var('lua') + eq(0, funcs.exists('w:lua')) end) end) diff --git a/test/functional/autocmd/autocmd_spec.lua b/test/functional/autocmd/autocmd_spec.lua new file mode 100644 index 0000000000..3c813abc2e --- /dev/null +++ b/test/functional/autocmd/autocmd_spec.lua @@ -0,0 +1,31 @@ +local helpers = require('test.functional.helpers') + +local clear = helpers.clear +local command = helpers.command +local eval = helpers.eval + +describe('autocmds:', function() + before_each(clear) + + it(':tabnew triggers events in the correct order', function() + local expected = { + 'WinLeave', + 'TabLeave', + 'TabNew', + 'WinEnter', + 'TabEnter', + 'BufLeave', + 'BufEnter' + } + command('let g:foo = []') + command('autocmd BufEnter * :call add(g:foo, "BufEnter")') + command('autocmd BufLeave * :call add(g:foo, "BufLeave")') + command('autocmd TabEnter * :call add(g:foo, "TabEnter")') + command('autocmd TabLeave * :call add(g:foo, "TabLeave")') + command('autocmd TabNew * :call add(g:foo, "TabNew")') + command('autocmd WinEnter * :call add(g:foo, "WinEnter")') + command('autocmd WinLeave * :call add(g:foo, "WinLeave")') + command('tabnew') + assert.same(expected, eval('g:foo')) + end) +end) diff --git a/test/functional/autocmd/tabnew_spec.lua b/test/functional/autocmd/tabnew_spec.lua index 5ab504889b..aaf9db0a99 100644 --- a/test/functional/autocmd/tabnew_spec.lua +++ b/test/functional/autocmd/tabnew_spec.lua @@ -1,22 +1,28 @@ local helpers = require('test.functional.helpers') -local clear, nvim, eq = helpers.clear, helpers.nvim, helpers.eq -describe('TabNew', function() - setup(clear) - describe('au TabNew', function() - describe('with * as <afile>', function() - it('matches when opening any new tab', function() - nvim('command', 'au! TabNew * echom "tabnew:".tabpagenr().":".bufnr("")') - eq("\ntabnew:2:1", nvim('command_output', 'tabnew')) - eq("\ntabnew:3:2\n\"test.x\" [New File]", nvim('command_output', 'tabnew test.x')) - end) - end) - describe('with FILE as <afile>', function() - it('matches when opening a new tab for FILE', function() - local tmp_path = nvim('eval', 'tempname()') - nvim('command', 'au! TabNew '..tmp_path..' echom "tabnew:match"') - eq("\ntabnew:4:3\ntabnew:match\n\""..tmp_path.."\" [New File]", nvim('command_output', 'tabnew '..tmp_path)) - end) - end) - end) +local clear = helpers.clear +local command = helpers.command +local eq = helpers.eq +local eval = helpers.eval + +describe('autocmd TabNew', function() + before_each(clear) + + it('matches when opening any new tab', function() + command('autocmd! TabNew * let g:test = "tabnew:".tabpagenr().":".bufnr("")') + command('tabnew') + eq('tabnew:2:1', eval('g:test')) + command('tabnew test.x') + eq('tabnew:3:2', eval('g:test')) + end) + + it('matches when opening a new tab for FILE', function() + local tmp_path = helpers.funcs.tempname() + command('let g:test = "foo"') + command('autocmd! TabNew ' .. tmp_path .. ' let g:test = "bar"') + command('tabnew ' .. tmp_path ..'X') + eq('foo', eval('g:test')) + command('tabnew ' .. tmp_path) + eq('bar', eval('g:test')) + end) end) diff --git a/test/functional/autocmd/textyankpost_spec.lua b/test/functional/autocmd/textyankpost_spec.lua index 965b19581a..0e46aa5641 100644 --- a/test/functional/autocmd/textyankpost_spec.lua +++ b/test/functional/autocmd/textyankpost_spec.lua @@ -14,7 +14,7 @@ describe('TextYankPost', function() execute('autocmd TextYankPost * let g:event = copy(v:event)') execute('autocmd TextYankPost * let g:count += 1') - curbufmeths.set_line_slice(0, -1, true, true, { + curbufmeths.set_lines(0, -1, true, { 'foo\0bar', 'baz text', }) diff --git a/test/functional/eval/json_functions_spec.lua b/test/functional/eval/json_functions_spec.lua new file mode 100644 index 0000000000..1cece78ce1 --- /dev/null +++ b/test/functional/eval/json_functions_spec.lua @@ -0,0 +1,799 @@ +local helpers = require('test.functional.helpers') +local clear = helpers.clear +local funcs = helpers.funcs +local meths = helpers.meths +local eq = helpers.eq +local eval = helpers.eval +local execute = helpers.execute +local exc_exec = helpers.exc_exec +local redir_exec = helpers.redir_exec + +describe('json_decode() function', function() + local restart = function(cmd) + clear(cmd) + execute('language C') + execute([[ + function Eq(exp, act) + let act = a:act + let exp = a:exp + if type(exp) != type(act) + return 0 + endif + if type(exp) == type({}) + if sort(keys(exp)) !=# sort(keys(act)) + return 0 + endif + if sort(keys(exp)) ==# ['_TYPE', '_VAL'] + let exp_typ = v:msgpack_types[exp._TYPE] + let act_typ = act._TYPE + if exp_typ isnot act_typ + return 0 + endif + return Eq(exp._VAL, act._VAL) + else + return empty(filter(copy(exp), '!Eq(v:val, act[v:key])')) + endif + else + if type(exp) == type([]) + if len(exp) != len(act) + return 0 + endif + return empty(filter(copy(exp), '!Eq(v:val, act[v:key])')) + endif + return exp ==# act + endif + return 1 + endfunction + ]]) + execute([[ + function EvalEq(exp, act_expr) + let act = eval(a:act_expr) + if Eq(a:exp, act) + return 1 + else + return string(act) + endif + endfunction + ]]) + end + before_each(restart) + + local speq = function(expected, actual_expr) + eq(1, funcs.EvalEq(expected, actual_expr)) + end + + it('accepts readfile()-style list', function() + eq({Test=1}, funcs.json_decode({ + '{', + '\t"Test": 1', + '}', + })) + end) + + it('accepts strings with newlines', function() + eq({Test=1}, funcs.json_decode([[ + { + "Test": 1 + } + ]])) + end) + + it('parses null, true, false', function() + eq(NIL, funcs.json_decode('null')) + eq(true, funcs.json_decode('true')) + eq(false, funcs.json_decode('false')) + end) + + it('fails to parse incomplete null, true, false', function() + eq('Vim(call):E474: Expected null: n', + exc_exec('call json_decode("n")')) + eq('Vim(call):E474: Expected null: nu', + exc_exec('call json_decode("nu")')) + eq('Vim(call):E474: Expected null: nul', + exc_exec('call json_decode("nul")')) + eq('Vim(call):E474: Expected null: nul\n\t', + exc_exec('call json_decode("nul\\n\\t")')) + + eq('Vim(call):E474: Expected true: t', + exc_exec('call json_decode("t")')) + eq('Vim(call):E474: Expected true: tr', + exc_exec('call json_decode("tr")')) + eq('Vim(call):E474: Expected true: tru', + exc_exec('call json_decode("tru")')) + eq('Vim(call):E474: Expected true: tru\t\n', + exc_exec('call json_decode("tru\\t\\n")')) + + eq('Vim(call):E474: Expected false: f', + exc_exec('call json_decode("f")')) + eq('Vim(call):E474: Expected false: fa', + exc_exec('call json_decode("fa")')) + eq('Vim(call):E474: Expected false: fal', + exc_exec('call json_decode("fal")')) + eq('Vim(call):E474: Expected false: fal <', + exc_exec('call json_decode(" fal <")')) + eq('Vim(call):E474: Expected false: fals', + exc_exec('call json_decode("fals")')) + end) + + it('parses integer numbers', function() + eq(100000, funcs.json_decode('100000')) + eq(-100000, funcs.json_decode('-100000')) + eq(100000, funcs.json_decode(' 100000 ')) + eq(-100000, funcs.json_decode(' -100000 ')) + eq(0, funcs.json_decode('0')) + eq(0, funcs.json_decode('-0')) + end) + + it('fails to parse +numbers and .number', function() + eq('Vim(call):E474: Unidentified byte: +1000', + exc_exec('call json_decode("+1000")')) + eq('Vim(call):E474: Unidentified byte: .1000', + exc_exec('call json_decode(".1000")')) + end) + + it('fails to parse numbers with leading zeroes', function() + eq('Vim(call):E474: Leading zeroes are not allowed: 00.1', + exc_exec('call json_decode("00.1")')) + eq('Vim(call):E474: Leading zeroes are not allowed: 01', + exc_exec('call json_decode("01")')) + eq('Vim(call):E474: Leading zeroes are not allowed: -01', + exc_exec('call json_decode("-01")')) + eq('Vim(call):E474: Leading zeroes are not allowed: -001.0', + exc_exec('call json_decode("-001.0")')) + end) + + it('fails to parse incomplete numbers', function() + eq('Vim(call):E474: Missing number after minus sign: -.1', + exc_exec('call json_decode("-.1")')) + eq('Vim(call):E474: Missing number after minus sign: -', + exc_exec('call json_decode("-")')) + eq('Vim(call):E474: Missing number after decimal dot: -1.', + exc_exec('call json_decode("-1.")')) + eq('Vim(call):E474: Missing number after decimal dot: 0.', + exc_exec('call json_decode("0.")')) + eq('Vim(call):E474: Missing exponent: 0.0e', + exc_exec('call json_decode("0.0e")')) + eq('Vim(call):E474: Missing exponent: 0.0e+', + exc_exec('call json_decode("0.0e+")')) + eq('Vim(call):E474: Missing exponent: 0.0e-', + exc_exec('call json_decode("0.0e-")')) + eq('Vim(call):E474: Missing exponent: 0.0e-', + exc_exec('call json_decode("0.0e-")')) + eq('Vim(call):E474: Missing number after decimal dot: 1.e5', + exc_exec('call json_decode("1.e5")')) + eq('Vim(call):E474: Missing number after decimal dot: 1.e+5', + exc_exec('call json_decode("1.e+5")')) + eq('Vim(call):E474: Missing number after decimal dot: 1.e+', + exc_exec('call json_decode("1.e+")')) + end) + + it('parses floating-point numbers', function() + eq('100000.0', eval('string(json_decode("100000.0"))')) + eq(100000.5, funcs.json_decode('100000.5')) + eq(-100000.5, funcs.json_decode('-100000.5')) + eq(-100000.5e50, funcs.json_decode('-100000.5e50')) + eq(100000.5e50, funcs.json_decode('100000.5e50')) + eq(100000.5e50, funcs.json_decode('100000.5e+50')) + eq(-100000.5e-50, funcs.json_decode('-100000.5e-50')) + eq(100000.5e-50, funcs.json_decode('100000.5e-50')) + eq(100000e-50, funcs.json_decode('100000e-50')) + eq(0.5, funcs.json_decode('0.5')) + eq(0.005, funcs.json_decode('0.005')) + eq(0.005, funcs.json_decode('0.00500')) + eq(0.5, funcs.json_decode('0.00500e+002')) + eq(0.00005, funcs.json_decode('0.00500e-002')) + + eq(-0.0, funcs.json_decode('-0.0')) + eq(-0.0, funcs.json_decode('-0.0e0')) + eq(-0.0, funcs.json_decode('-0.0e+0')) + eq(-0.0, funcs.json_decode('-0.0e-0')) + eq(-0.0, funcs.json_decode('-0e-0')) + eq(-0.0, funcs.json_decode('-0e-2')) + eq(-0.0, funcs.json_decode('-0e+2')) + + eq(0.0, funcs.json_decode('0.0')) + eq(0.0, funcs.json_decode('0.0e0')) + eq(0.0, funcs.json_decode('0.0e+0')) + eq(0.0, funcs.json_decode('0.0e-0')) + eq(0.0, funcs.json_decode('0e-0')) + eq(0.0, funcs.json_decode('0e-2')) + eq(0.0, funcs.json_decode('0e+2')) + end) + + it('fails to parse numbers with spaces inside', function() + eq('Vim(call):E474: Missing number after minus sign: - 1000', + exc_exec('call json_decode("- 1000")')) + eq('Vim(call):E474: Missing number after decimal dot: 0. ', + exc_exec('call json_decode("0. ")')) + eq('Vim(call):E474: Missing number after decimal dot: 0. 0', + exc_exec('call json_decode("0. 0")')) + eq('Vim(call):E474: Missing exponent: 0.0e 1', + exc_exec('call json_decode("0.0e 1")')) + eq('Vim(call):E474: Missing exponent: 0.0e+ 1', + exc_exec('call json_decode("0.0e+ 1")')) + eq('Vim(call):E474: Missing exponent: 0.0e- 1', + exc_exec('call json_decode("0.0e- 1")')) + end) + + it('fails to parse "," and ":"', function() + eq('Vim(call):E474: Comma not inside container: , ', + exc_exec('call json_decode(" , ")')) + eq('Vim(call):E474: Colon not inside container: : ', + exc_exec('call json_decode(" : ")')) + end) + + it('parses empty containers', function() + eq({}, funcs.json_decode('[]')) + eq('[]', eval('string(json_decode("[]"))')) + end) + + it('fails to parse "[" and "{"', function() + eq('Vim(call):E474: Unexpected end of input: {', + exc_exec('call json_decode("{")')) + eq('Vim(call):E474: Unexpected end of input: [', + exc_exec('call json_decode("[")')) + end) + + it('fails to parse "}" and "]"', function() + eq('Vim(call):E474: No container to close: ]', + exc_exec('call json_decode("]")')) + eq('Vim(call):E474: No container to close: }', + exc_exec('call json_decode("}")')) + end) + + it('fails to parse containers which are closed by different brackets', + function() + eq('Vim(call):E474: Closing dictionary with square bracket: ]', + exc_exec('call json_decode("{]")')) + eq('Vim(call):E474: Closing list with curly bracket: }', + exc_exec('call json_decode("[}")')) + end) + + it('fails to parse concat inside container', function() + eq('Vim(call):E474: Expected comma before list item: []]', + exc_exec('call json_decode("[[][]]")')) + eq('Vim(call):E474: Expected comma before list item: {}]', + exc_exec('call json_decode("[{}{}]")')) + eq('Vim(call):E474: Expected comma before list item: ]', + exc_exec('call json_decode("[1 2]")')) + eq('Vim(call):E474: Expected comma before dictionary key: ": 4}', + exc_exec('call json_decode("{\\"1\\": 2 \\"3\\": 4}")')) + eq('Vim(call):E474: Expected colon before dictionary value: , "3" 4}', + exc_exec('call json_decode("{\\"1\\" 2, \\"3\\" 4}")')) + end) + + it('fails to parse containers with leading comma or colon', function() + eq('Vim(call):E474: Leading comma: ,}', + exc_exec('call json_decode("{,}")')) + eq('Vim(call):E474: Leading comma: ,]', + exc_exec('call json_decode("[,]")')) + eq('Vim(call):E474: Using colon not in dictionary: :]', + exc_exec('call json_decode("[:]")')) + eq('Vim(call):E474: Unexpected colon: :}', + exc_exec('call json_decode("{:}")')) + end) + + it('fails to parse containers with trailing comma', function() + eq('Vim(call):E474: Trailing comma: ]', + exc_exec('call json_decode("[1,]")')) + eq('Vim(call):E474: Trailing comma: }', + exc_exec('call json_decode("{\\"1\\": 2,}")')) + end) + + it('fails to parse dictionaries with missing value', function() + eq('Vim(call):E474: Expected value after colon: }', + exc_exec('call json_decode("{\\"1\\":}")')) + eq('Vim(call):E474: Expected value: }', + exc_exec('call json_decode("{\\"1\\"}")')) + end) + + it('fails to parse containers with two commas or colons', function() + eq('Vim(call):E474: Duplicate comma: , "2": 2}', + exc_exec('call json_decode("{\\"1\\": 1,, \\"2\\": 2}")')) + eq('Vim(call):E474: Duplicate comma: , "2", 2]', + exc_exec('call json_decode("[\\"1\\", 1,, \\"2\\", 2]")')) + eq('Vim(call):E474: Duplicate colon: : 2}', + exc_exec('call json_decode("{\\"1\\": 1, \\"2\\":: 2}")')) + eq('Vim(call):E474: Comma after colon: , 2}', + exc_exec('call json_decode("{\\"1\\": 1, \\"2\\":, 2}")')) + eq('Vim(call):E474: Unexpected colon: : "2": 2}', + exc_exec('call json_decode("{\\"1\\": 1,: \\"2\\": 2}")')) + eq('Vim(call):E474: Unexpected colon: :, "2": 2}', + exc_exec('call json_decode("{\\"1\\": 1:, \\"2\\": 2}")')) + end) + + it('fails to parse concat of two values', function() + eq('Vim(call):E474: Trailing characters: []', + exc_exec('call json_decode("{}[]")')) + end) + + it('parses containers', function() + eq({1}, funcs.json_decode('[1]')) + eq({NIL, 1}, funcs.json_decode('[null, 1]')) + eq({['1']=2}, funcs.json_decode('{"1": 2}')) + eq({['1']=2, ['3']={{['4']={['5']={{}, 1}}}}}, + funcs.json_decode('{"1": 2, "3": [{"4": {"5": [[], 1]}}]}')) + end) + + it('fails to parse incomplete strings', function() + eq('Vim(call):E474: Expected string end: \t"', + exc_exec('call json_decode("\\t\\"")')) + eq('Vim(call):E474: Expected string end: \t"abc', + exc_exec('call json_decode("\\t\\"abc")')) + eq('Vim(call):E474: Unfinished escape sequence: \t"abc\\', + exc_exec('call json_decode("\\t\\"abc\\\\")')) + eq('Vim(call):E474: Unfinished unicode escape sequence: \t"abc\\u', + exc_exec('call json_decode("\\t\\"abc\\\\u")')) + eq('Vim(call):E474: Unfinished unicode escape sequence: \t"abc\\u0', + exc_exec('call json_decode("\\t\\"abc\\\\u0")')) + eq('Vim(call):E474: Unfinished unicode escape sequence: \t"abc\\u00', + exc_exec('call json_decode("\\t\\"abc\\\\u00")')) + eq('Vim(call):E474: Unfinished unicode escape sequence: \t"abc\\u000', + exc_exec('call json_decode("\\t\\"abc\\\\u000")')) + eq('Vim(call):E474: Expected four hex digits after \\u: \\u" ', + exc_exec('call json_decode("\\t\\"abc\\\\u\\" ")')) + eq('Vim(call):E474: Expected four hex digits after \\u: \\u0" ', + exc_exec('call json_decode("\\t\\"abc\\\\u0\\" ")')) + eq('Vim(call):E474: Expected four hex digits after \\u: \\u00" ', + exc_exec('call json_decode("\\t\\"abc\\\\u00\\" ")')) + eq('Vim(call):E474: Expected four hex digits after \\u: \\u000" ', + exc_exec('call json_decode("\\t\\"abc\\\\u000\\" ")')) + eq('Vim(call):E474: Expected string end: \t"abc\\u0000', + exc_exec('call json_decode("\\t\\"abc\\\\u0000")')) + end) + + it('fails to parse unknown escape sequnces', function() + eq('Vim(call):E474: Unknown escape sequence: \\a"', + exc_exec('call json_decode("\\t\\"\\\\a\\"")')) + end) + + it('parses strings properly', function() + eq('\n', funcs.json_decode('"\\n"')) + eq('', funcs.json_decode('""')) + eq('\\/"\t\b\n\r\f', funcs.json_decode([["\\\/\"\t\b\n\r\f"]])) + eq('/a', funcs.json_decode([["\/a"]])) + -- Unicode characters: 2-byte, 3-byte, 4-byte + eq({ + '«', + 'ફ', + '\240\144\128\128', + }, funcs.json_decode({ + '[', + '"«",', + '"ફ",', + '"\240\144\128\128"', + ']', + })) + end) + + it('fails on strings with invalid bytes', function() + eq('Vim(call):E474: Only UTF-8 strings allowed: \255"', + exc_exec('call json_decode("\\t\\"\\xFF\\"")')) + eq('Vim(call):E474: ASCII control characters cannot be present inside string: ', + exc_exec('call json_decode(["\\"\\n\\""])')) + -- 0xC2 starts 2-byte unicode character + eq('Vim(call):E474: Only UTF-8 strings allowed: \194"', + exc_exec('call json_decode("\\t\\"\\xC2\\"")')) + -- 0xE0 0xAA starts 3-byte unicode character + eq('Vim(call):E474: Only UTF-8 strings allowed: \224"', + exc_exec('call json_decode("\\t\\"\\xE0\\"")')) + eq('Vim(call):E474: Only UTF-8 strings allowed: \224\170"', + exc_exec('call json_decode("\\t\\"\\xE0\\xAA\\"")')) + -- 0xF0 0x90 0x80 starts 4-byte unicode character + eq('Vim(call):E474: Only UTF-8 strings allowed: \240"', + exc_exec('call json_decode("\\t\\"\\xF0\\"")')) + eq('Vim(call):E474: Only UTF-8 strings allowed: \240\144"', + exc_exec('call json_decode("\\t\\"\\xF0\\x90\\"")')) + eq('Vim(call):E474: Only UTF-8 strings allowed: \240\144\128"', + exc_exec('call json_decode("\\t\\"\\xF0\\x90\\x80\\"")')) + -- 0xF9 0x80 0x80 0x80 starts 5-byte unicode character + eq('Vim(call):E474: Only UTF-8 strings allowed: \249"', + exc_exec('call json_decode("\\t\\"\\xF9\\"")')) + eq('Vim(call):E474: Only UTF-8 strings allowed: \249\128"', + exc_exec('call json_decode("\\t\\"\\xF9\\x80\\"")')) + eq('Vim(call):E474: Only UTF-8 strings allowed: \249\128\128"', + exc_exec('call json_decode("\\t\\"\\xF9\\x80\\x80\\"")')) + eq('Vim(call):E474: Only UTF-8 strings allowed: \249\128\128\128"', + exc_exec('call json_decode("\\t\\"\\xF9\\x80\\x80\\x80\\"")')) + -- 0xFC 0x90 0x80 0x80 0x80 starts 6-byte unicode character + eq('Vim(call):E474: Only UTF-8 strings allowed: \252"', + exc_exec('call json_decode("\\t\\"\\xFC\\"")')) + eq('Vim(call):E474: Only UTF-8 strings allowed: \252\144"', + exc_exec('call json_decode("\\t\\"\\xFC\\x90\\"")')) + eq('Vim(call):E474: Only UTF-8 strings allowed: \252\144\128"', + exc_exec('call json_decode("\\t\\"\\xFC\\x90\\x80\\"")')) + eq('Vim(call):E474: Only UTF-8 strings allowed: \252\144\128\128"', + exc_exec('call json_decode("\\t\\"\\xFC\\x90\\x80\\x80\\"")')) + eq('Vim(call):E474: Only UTF-8 strings allowed: \252\144\128\128\128"', + exc_exec('call json_decode("\\t\\"\\xFC\\x90\\x80\\x80\\x80\\"")')) + -- Specification does not allow unquoted characters above 0x10FFFF + eq('Vim(call):E474: Only UTF-8 code points up to U+10FFFF are allowed to appear unescaped: \249\128\128\128\128"', + exc_exec('call json_decode("\\t\\"\\xF9\\x80\\x80\\x80\\x80\\"")')) + eq('Vim(call):E474: Only UTF-8 code points up to U+10FFFF are allowed to appear unescaped: \252\144\128\128\128\128"', + exc_exec('call json_decode("\\t\\"\\xFC\\x90\\x80\\x80\\x80\\x80\\"")')) + -- '"\249\128\128\128\128"', + -- '"\252\144\128\128\128\128"', + end) + + it('parses surrogate pairs properly', function() + eq('\240\144\128\128', funcs.json_decode('"\\uD800\\uDC00"')) + eq('\237\160\128a\237\176\128', funcs.json_decode('"\\uD800a\\uDC00"')) + eq('\237\160\128\t\237\176\128', funcs.json_decode('"\\uD800\\t\\uDC00"')) + + eq('\237\160\128', funcs.json_decode('"\\uD800"')) + eq('\237\160\128a', funcs.json_decode('"\\uD800a"')) + eq('\237\160\128\t', funcs.json_decode('"\\uD800\\t"')) + + eq('\237\176\128', funcs.json_decode('"\\uDC00"')) + eq('\237\176\128a', funcs.json_decode('"\\uDC00a"')) + eq('\237\176\128\t', funcs.json_decode('"\\uDC00\\t"')) + + eq('\237\176\128', funcs.json_decode('"\\uDC00"')) + eq('a\237\176\128', funcs.json_decode('"a\\uDC00"')) + eq('\t\237\176\128', funcs.json_decode('"\\t\\uDC00"')) + + eq('\237\160\128¬', funcs.json_decode('"\\uD800\\u00AC"')) + + eq('\237\160\128\237\160\128', funcs.json_decode('"\\uD800\\uD800"')) + end) + + local sp_decode_eq = function(expected, json) + meths.set_var('__json', json) + speq(expected, 'json_decode(g:__json)') + execute('unlet! g:__json') + end + + it('parses strings with NUL properly', function() + sp_decode_eq({_TYPE='string', _VAL={'\n'}}, '"\\u0000"') + sp_decode_eq({_TYPE='string', _VAL={'\n', '\n'}}, '"\\u0000\\n\\u0000"') + sp_decode_eq({_TYPE='string', _VAL={'\n«\n'}}, '"\\u0000\\u00AB\\u0000"') + end) + + it('parses dictionaries with duplicate keys to special maps', function() + sp_decode_eq({_TYPE='map', _VAL={{'a', 1}, {'a', 2}}}, + '{"a": 1, "a": 2}') + sp_decode_eq({_TYPE='map', _VAL={{'b', 3}, {'a', 1}, {'a', 2}}}, + '{"b": 3, "a": 1, "a": 2}') + sp_decode_eq({_TYPE='map', _VAL={{'b', 3}, {'a', 1}, {'c', 4}, {'a', 2}}}, + '{"b": 3, "a": 1, "c": 4, "a": 2}') + sp_decode_eq({_TYPE='map', _VAL={{'b', 3}, {'a', 1}, {'c', 4}, {'a', 2}, {'c', 4}}}, + '{"b": 3, "a": 1, "c": 4, "a": 2, "c": 4}') + sp_decode_eq({{_TYPE='map', _VAL={{'b', 3}, {'a', 1}, {'c', 4}, {'a', 2}, {'c', 4}}}}, + '[{"b": 3, "a": 1, "c": 4, "a": 2, "c": 4}]') + sp_decode_eq({{d={_TYPE='map', _VAL={{'b', 3}, {'a', 1}, {'c', 4}, {'a', 2}, {'c', 4}}}}}, + '[{"d": {"b": 3, "a": 1, "c": 4, "a": 2, "c": 4}}]') + sp_decode_eq({1, {d={_TYPE='map', _VAL={{'b', 3}, {'a', 1}, {'c', 4}, {'a', 2}, {'c', 4}}}}}, + '[1, {"d": {"b": 3, "a": 1, "c": 4, "a": 2, "c": 4}}]') + sp_decode_eq({1, {a={}, d={_TYPE='map', _VAL={{'b', 3}, {'a', 1}, {'c', 4}, {'a', 2}, {'c', 4}}}}}, + '[1, {"a": [], "d": {"b": 3, "a": 1, "c": 4, "a": 2, "c": 4}}]') + end) + + it('parses dictionaries with empty keys to special maps', function() + sp_decode_eq({_TYPE='map', _VAL={{'', 4}}}, + '{"": 4}') + sp_decode_eq({_TYPE='map', _VAL={{'b', 3}, {'a', 1}, {'c', 4}, {'d', 2}, {'', 4}}}, + '{"b": 3, "a": 1, "c": 4, "d": 2, "": 4}') + sp_decode_eq({_TYPE='map', _VAL={{'', 3}, {'a', 1}, {'c', 4}, {'d', 2}, {'', 4}}}, + '{"": 3, "a": 1, "c": 4, "d": 2, "": 4}') + sp_decode_eq({{_TYPE='map', _VAL={{'', 3}, {'a', 1}, {'c', 4}, {'d', 2}, {'', 4}}}}, + '[{"": 3, "a": 1, "c": 4, "d": 2, "": 4}]') + end) + + it('parses dictionaries with keys with NUL bytes to special maps', function() + sp_decode_eq({_TYPE='map', _VAL={{{_TYPE='string', _VAL={'a\n', 'b'}}, 4}}}, + '{"a\\u0000\\nb": 4}') + sp_decode_eq({_TYPE='map', _VAL={{{_TYPE='string', _VAL={'a\n', 'b', ''}}, 4}}}, + '{"a\\u0000\\nb\\n": 4}') + sp_decode_eq({_TYPE='map', _VAL={{'b', 3}, {'a', 1}, {'c', 4}, {'d', 2}, {{_TYPE='string', _VAL={'\n'}}, 4}}}, + '{"b": 3, "a": 1, "c": 4, "d": 2, "\\u0000": 4}') + end) + + it('converts strings to latin1 when &encoding is latin1', function() + restart('set encoding=latin1') + eq('\171', funcs.json_decode('"\\u00AB"')) + sp_decode_eq({_TYPE='string', _VAL={'\n\171\n'}}, '"\\u0000\\u00AB\\u0000"') + end) + + it('fails to convert string to latin1 if it is impossible', function() + restart('set encoding=latin1') + eq('Vim(call):E474: Failed to convert string "ꯍ" from UTF-8', + exc_exec('call json_decode(\'"\\uABCD"\')')) + end) + + it('parses U+00C3 correctly', function() + eq('\195\131', funcs.json_decode('"\195\131"')) + end) + + it('fails to parse empty string', function() + eq('Vim(call):E474: Attempt to decode a blank string', + exc_exec('call json_decode("")')) + eq('Vim(call):E474: Attempt to decode a blank string', + exc_exec('call json_decode([])')) + eq('Vim(call):E474: Attempt to decode a blank string', + exc_exec('call json_decode([""])')) + eq('Vim(call):E474: Attempt to decode a blank string', + exc_exec('call json_decode(" ")')) + eq('Vim(call):E474: Attempt to decode a blank string', + exc_exec('call json_decode("\\t")')) + eq('Vim(call):E474: Attempt to decode a blank string', + exc_exec('call json_decode("\\n")')) + eq('Vim(call):E474: Attempt to decode a blank string', + exc_exec('call json_decode(" \\t\\n \\n\\t\\t \\n\\t\\n \\n \\t\\n\\t ")')) + end) + + it('accepts all spaces in every position where space may be put', function() + local s = ' \t\n\r \t\r\n \n\t\r \n\r\t \r\t\n \r\n\t\t \n\r\t \r\n\t\n \r\t\n\r \t\r \n\t\r\n \n \t\r\n \r\t\n\t \r\n\t\r \n\r \t\n\r\t \r \t\n\r \n\t\r\t \n\r\t\n \r\n \t\r\n\t' + local str = ('%s{%s"key"%s:%s[%s"val"%s,%s"val2"%s]%s,%s"key2"%s:%s1%s}%s'):gsub('%%s', s) + eq({key={'val', 'val2'}, key2=1}, funcs.json_decode(str)) + end) + + it('always treats input as UTF-8', function() + -- When &encoding is latin1 string "«" is U+00C2 U+00AB U+00C2: «Â. So if + -- '"«"' was parsed as latin1 json_decode would return three characters, and + -- only one U+00AB when this string is parsed as latin1. + restart('set encoding=latin1') + eq(('%c'):format(0xAB), funcs.json_decode('"«"')) + end) + + it('does not overflow when writing error message about decoding ["", ""]', + function() + eq('\nE474: Attempt to decode a blank string' + .. '\nE474: Failed to parse \n', + redir_exec('call json_decode(["", ""])')) + end) +end) + +describe('json_encode() function', function() + before_each(function() + clear() + execute('language C') + end) + + it('dumps strings', function() + eq('"Test"', funcs.json_encode('Test')) + eq('""', funcs.json_encode('')) + eq('"\\t"', funcs.json_encode('\t')) + eq('"\\n"', funcs.json_encode('\n')) + eq('"\\u001B"', funcs.json_encode('\27')) + eq('"þÿþ"', funcs.json_encode('þÿþ')) + end) + + it('dumps numbers', function() + eq('0', funcs.json_encode(0)) + eq('10', funcs.json_encode(10)) + eq('-10', funcs.json_encode(-10)) + end) + + it('dumps floats', function() + eq('0.0', eval('json_encode(0.0)')) + eq('10.5', funcs.json_encode(10.5)) + eq('-10.5', funcs.json_encode(-10.5)) + eq('-1.0e-5', funcs.json_encode(-1e-5)) + eq('1.0e50', eval('json_encode(1.0e50)')) + end) + + it('fails to dump NaN and infinite values', function() + eq('Vim(call):E474: Unable to represent NaN value in JSON', + exc_exec('call json_encode(str2float("nan"))')) + eq('Vim(call):E474: Unable to represent infinity in JSON', + exc_exec('call json_encode(str2float("inf"))')) + eq('Vim(call):E474: Unable to represent infinity in JSON', + exc_exec('call json_encode(-str2float("inf"))')) + end) + + it('dumps lists', function() + eq('[]', funcs.json_encode({})) + eq('[[]]', funcs.json_encode({{}})) + eq('[[], []]', funcs.json_encode({{}, {}})) + end) + + it('dumps dictionaries', function() + eq('{}', eval('json_encode({})')) + eq('{"d": []}', funcs.json_encode({d={}})) + eq('{"d": [], "e": []}', funcs.json_encode({d={}, e={}})) + end) + + it('cannot dump generic mapping with generic mapping keys and values', + function() + execute('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": []}') + execute('let todumpv1 = {"_TYPE": v:msgpack_types.map, "_VAL": []}') + execute('let todumpv2 = {"_TYPE": v:msgpack_types.map, "_VAL": []}') + execute('call add(todump._VAL, [todumpv1, todumpv2])') + eq('Vim(call):E474: Invalid key in special dictionary', exc_exec('call json_encode(todump)')) + end) + + it('cannot dump generic mapping with ext key', function() + execute('let todump = {"_TYPE": v:msgpack_types.ext, "_VAL": [5, ["",""]]}') + execute('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[todump, 1]]}') + eq('Vim(call):E474: Invalid key in special dictionary', exc_exec('call json_encode(todump)')) + end) + + it('cannot dump generic mapping with array key', function() + execute('let todump = {"_TYPE": v:msgpack_types.array, "_VAL": [5, [""]]}') + execute('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[todump, 1]]}') + eq('Vim(call):E474: Invalid key in special dictionary', exc_exec('call json_encode(todump)')) + end) + + it('cannot dump generic mapping with UINT64_MAX key', function() + execute('let todump = {"_TYPE": v:msgpack_types.integer}') + execute('let todump._VAL = [1, 3, 0x7FFFFFFF, 0x7FFFFFFF]') + execute('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[todump, 1]]}') + eq('Vim(call):E474: Invalid key in special dictionary', exc_exec('call json_encode(todump)')) + end) + + it('cannot dump generic mapping with floating-point key', function() + execute('let todump = {"_TYPE": v:msgpack_types.float, "_VAL": 0.125}') + execute('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[todump, 1]]}') + eq('Vim(call):E474: Invalid key in special dictionary', exc_exec('call json_encode(todump)')) + end) + + it('can dump generic mapping with STR special key and NUL', function() + execute('let todump = {"_TYPE": v:msgpack_types.string, "_VAL": ["\\n"]}') + execute('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[todump, 1]]}') + eq('{"\\u0000": 1}', eval('json_encode(todump)')) + end) + + it('can dump generic mapping with BIN special key and NUL', function() + execute('let todump = {"_TYPE": v:msgpack_types.binary, "_VAL": ["\\n"]}') + execute('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[todump, 1]]}') + eq('{"\\u0000": 1}', eval('json_encode(todump)')) + end) + + it('can dump STR special mapping with NUL and NL', function() + execute('let todump = {"_TYPE": v:msgpack_types.string, "_VAL": ["\\n", ""]}') + eq('"\\u0000\\n"', eval('json_encode(todump)')) + end) + + it('can dump BIN special mapping with NUL and NL', function() + execute('let todump = {"_TYPE": v:msgpack_types.binary, "_VAL": ["\\n", ""]}') + eq('"\\u0000\\n"', eval('json_encode(todump)')) + end) + + it('cannot dump special ext mapping', function() + execute('let todump = {"_TYPE": v:msgpack_types.ext, "_VAL": [5, ["",""]]}') + eq('Vim(call):E474: Unable to convert EXT string to JSON', exc_exec('call json_encode(todump)')) + end) + + it('can dump special array mapping', function() + execute('let todump = {"_TYPE": v:msgpack_types.array, "_VAL": [5, [""]]}') + eq('[5, [""]]', eval('json_encode(todump)')) + end) + + it('can dump special UINT64_MAX mapping', function() + execute('let todump = {"_TYPE": v:msgpack_types.integer}') + execute('let todump._VAL = [1, 3, 0x7FFFFFFF, 0x7FFFFFFF]') + eq('18446744073709551615', eval('json_encode(todump)')) + end) + + it('can dump special INT64_MIN mapping', function() + execute('let todump = {"_TYPE": v:msgpack_types.integer}') + execute('let todump._VAL = [-1, 2, 0, 0]') + eq('-9223372036854775808', eval('json_encode(todump)')) + end) + + it('can dump special BOOLEAN true mapping', function() + execute('let todump = {"_TYPE": v:msgpack_types.boolean, "_VAL": 1}') + eq('true', eval('json_encode(todump)')) + end) + + it('can dump special BOOLEAN false mapping', function() + execute('let todump = {"_TYPE": v:msgpack_types.boolean, "_VAL": 0}') + eq('false', eval('json_encode(todump)')) + end) + + it('can dump special NIL mapping', function() + execute('let todump = {"_TYPE": v:msgpack_types.nil, "_VAL": 0}') + eq('null', eval('json_encode(todump)')) + end) + + it('fails to dump a function reference', function() + eq('Vim(call):E474: Error while dumping encode_tv2json() argument, itself: attempt to dump function reference', + exc_exec('call json_encode(function("tr"))')) + end) + + it('fails to dump a function reference in a list', function() + eq('Vim(call):E474: Error while dumping encode_tv2json() argument, index 0: attempt to dump function reference', + exc_exec('call json_encode([function("tr")])')) + end) + + it('fails to dump a recursive list', function() + execute('let todump = [[[]]]') + execute('call add(todump[0][0], todump)') + eq('Vim(call):E724: unable to correctly dump variable with self-referencing container', + exc_exec('call json_encode(todump)')) + end) + + it('fails to dump a recursive dict', function() + execute('let todump = {"d": {"d": {}}}') + execute('call extend(todump.d.d, {"d": todump})') + eq('Vim(call):E724: unable to correctly dump variable with self-referencing container', + exc_exec('call json_encode([todump])')) + end) + + it('can dump dict with two same dicts inside', function() + execute('let inter = {}') + execute('let todump = {"a": inter, "b": inter}') + eq('{"a": {}, "b": {}}', eval('json_encode(todump)')) + end) + + it('can dump list with two same lists inside', function() + execute('let inter = []') + execute('let todump = [inter, inter]') + eq('[[], []]', eval('json_encode(todump)')) + end) + + it('fails to dump a recursive list in a special dict', function() + execute('let todump = {"_TYPE": v:msgpack_types.array, "_VAL": []}') + execute('call add(todump._VAL, todump)') + eq('Vim(call):E724: unable to correctly dump variable with self-referencing container', + exc_exec('call json_encode(todump)')) + end) + + it('fails to dump a recursive (val) map in a special dict', function() + execute('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": []}') + execute('call add(todump._VAL, ["", todump])') + eq('Vim(call):E724: unable to correctly dump variable with self-referencing container', + exc_exec('call json_encode([todump])')) + end) + + it('fails to dump a recursive (val) map in a special dict, _VAL reference', function() + execute('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [["", []]]}') + execute('call add(todump._VAL[0][1], todump._VAL)') + eq('Vim(call):E724: unable to correctly dump variable with self-referencing container', + exc_exec('call json_encode(todump)')) + end) + + it('fails to dump a recursive (val) special list in a special dict', + function() + execute('let todump = {"_TYPE": v:msgpack_types.array, "_VAL": []}') + execute('call add(todump._VAL, ["", todump._VAL])') + eq('Vim(call):E724: unable to correctly dump variable with self-referencing container', + exc_exec('call json_encode(todump)')) + end) + + it('fails when called with no arguments', function() + eq('Vim(call):E119: Not enough arguments for function: json_encode', + exc_exec('call json_encode()')) + end) + + it('fails when called with two arguments', function() + eq('Vim(call):E118: Too many arguments for function: json_encode', + exc_exec('call json_encode(["", ""], 1)')) + end) + + it('converts strings from latin1 when &encoding is latin1', function() + clear('set encoding=latin1') + eq('"\\u00AB"', funcs.json_encode('\171')) + eq('"\\u0000\\u00AB\\u0000"', eval('json_encode({"_TYPE": v:msgpack_types.string, "_VAL": ["\\n\171\\n"]})')) + end) + + it('ignores improper values in &isprint', function() + meths.set_option('isprint', '1') + eq(1, eval('"\1" =~# "\\\\p"')) + eq('"\\u0001"', funcs.json_encode('\1')) + end) + + it('fails when using surrogate character in a UTF-8 string', function() + eq('Vim(call):E474: UTF-8 string contains code point which belongs to a surrogate pair: \237\160\128', + exc_exec('call json_encode("\237\160\128")')) + eq('Vim(call):E474: UTF-8 string contains code point which belongs to a surrogate pair: \237\175\191', + exc_exec('call json_encode("\237\175\191")')) + end) + + it('dumps control characters as expected', function() + eq([["\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000B\f\r\u000E\u000F\u0010\u0011\u0012\u0013"]], + eval('json_encode({"_TYPE": v:msgpack_types.string, "_VAL": ["\n\1\2\3\4\5\6\7\8\9", "\11\12\13\14\15\16\17\18\19"]})')) + end) + + it('can dump NULL string', function() + eq('""', eval('json_encode($XXX_UNEXISTENT_VAR_XXX)')) + end) + + it('can dump NULL list', function() + eq('[]', eval('json_encode(v:_null_list)')) + end) + + it('can dump NULL dictionary', function() + eq('{}', eval('json_encode(v:_null_dict)')) + end) +end) diff --git a/test/functional/eval/msgpack_functions_spec.lua b/test/functional/eval/msgpack_functions_spec.lua index 41b0faf76c..9e501353a5 100644 --- a/test/functional/eval/msgpack_functions_spec.lua +++ b/test/functional/eval/msgpack_functions_spec.lua @@ -1,5 +1,6 @@ local helpers = require('test.functional.helpers') local clear = helpers.clear +local funcs = helpers.funcs local eval, eq = helpers.eval, helpers.eq local execute = helpers.execute local nvim = helpers.nvim @@ -382,30 +383,32 @@ describe('msgpack*() functions', function() eq({"\n"}, eval('parsed')) eq(1, eval('dumped ==# dumped2')) end) + + it('dump and restore special mapping with floating-point value', function() + execute('let todump = {"_TYPE": v:msgpack_types.float, "_VAL": 0.125}') + eq({0.125}, eval('msgpackparse(msgpackdump([todump]))')) + end) end) describe('msgpackparse() function', function() before_each(clear) - it('restores nil as special dict', function() + it('restores nil as v:null', function() execute('let dumped = ["\\xC0"]') execute('let parsed = msgpackparse(dumped)') - eq({{_TYPE={}, _VAL=0}}, eval('parsed')) - eq(1, eval('g:parsed[0]._TYPE is v:msgpack_types.nil')) + eq('[v:null]', eval('string(parsed)')) end) - it('restores boolean false as zero', function() + it('restores boolean false as v:false', function() execute('let dumped = ["\\xC2"]') execute('let parsed = msgpackparse(dumped)') - eq({{_TYPE={}, _VAL=0}}, eval('parsed')) - eq(1, eval('g:parsed[0]._TYPE is v:msgpack_types.boolean')) + eq({false}, eval('parsed')) end) - it('restores boolean true as one', function() + it('restores boolean true as v:true', function() execute('let dumped = ["\\xC3"]') execute('let parsed = msgpackparse(dumped)') - eq({{_TYPE={}, _VAL=1}}, eval('parsed')) - eq(1, eval('g:parsed[0]._TYPE is v:msgpack_types.boolean')) + eq({true}, eval('parsed')) end) it('restores FIXSTR as special dict', function() @@ -512,33 +515,55 @@ describe('msgpackdump() function', function() eq({'\129\128\128'}, eval('msgpackdump([todump])')) end) - it('can dump generic mapping with ext', function() + it('can dump v:true', function() + eq({'\195'}, funcs.msgpackdump({true})) + end) + + it('can dump v:false', function() + eq({'\194'}, funcs.msgpackdump({false})) + end) + + it('can v:null', function() + execute('let todump = v:null') + end) + + it('can dump special bool mapping (true)', function() + execute('let todump = {"_TYPE": v:msgpack_types.boolean, "_VAL": 1}') + eq({'\195'}, eval('msgpackdump([todump])')) + end) + + it('can dump special bool mapping (false)', function() + execute('let todump = {"_TYPE": v:msgpack_types.boolean, "_VAL": 0}') + eq({'\194'}, eval('msgpackdump([todump])')) + end) + + it('can dump special nil mapping', function() + execute('let todump = {"_TYPE": v:msgpack_types.nil, "_VAL": 0}') + eq({'\192'}, eval('msgpackdump([todump])')) + end) + + it('can dump special ext mapping', function() execute('let todump = {"_TYPE": v:msgpack_types.ext, "_VAL": [5, ["",""]]}') eq({'\212\005', ''}, eval('msgpackdump([todump])')) end) - it('can dump generic mapping with array', function() + it('can dump special array mapping', function() execute('let todump = {"_TYPE": v:msgpack_types.array, "_VAL": [5, [""]]}') eq({'\146\005\145\196\n'}, eval('msgpackdump([todump])')) end) - it('can dump generic mapping with UINT64_MAX', function() + it('can dump special UINT64_MAX mapping', function() execute('let todump = {"_TYPE": v:msgpack_types.integer}') execute('let todump._VAL = [1, 3, 0x7FFFFFFF, 0x7FFFFFFF]') eq({'\207\255\255\255\255\255\255\255\255'}, eval('msgpackdump([todump])')) end) - it('can dump generic mapping with INT64_MIN', function() + it('can dump special INT64_MIN mapping', function() execute('let todump = {"_TYPE": v:msgpack_types.integer}') execute('let todump._VAL = [-1, 2, 0, 0]') eq({'\211\128\n\n\n\n\n\n\n'}, eval('msgpackdump([todump])')) end) - it('dump and restore generic mapping with floating-point value', function() - execute('let todump = {"_TYPE": v:msgpack_types.float, "_VAL": 0.125}') - eq({0.125}, eval('msgpackparse(msgpackdump([todump]))')) - end) - it('fails to dump a function reference', function() execute('let Todump = function("tr")') eq('Vim(call):E951: Error while dumping msgpackdump() argument, index 0, itself: attempt to dump function reference', @@ -654,4 +679,25 @@ describe('msgpackdump() function', function() eq('Vim(call):E686: Argument of msgpackdump() must be a List', exc_exec('call msgpackdump(0.0)')) end) + + it('fails to dump special value', function() + for _, val in ipairs({'v:true', 'v:false', 'v:null'}) do + eq('Vim(call):E686: Argument of msgpackdump() must be a List', + exc_exec('call msgpackdump(' .. val .. ')')) + end + end) + + it('can dump NULL string', function() + eq({'\196\n'}, eval('msgpackdump([$XXX_UNEXISTENT_VAR_XXX])')) + eq({'\196\n'}, eval('msgpackdump([{"_TYPE": v:msgpack_types.binary, "_VAL": [$XXX_UNEXISTENT_VAR_XXX]}])')) + eq({'\160'}, eval('msgpackdump([{"_TYPE": v:msgpack_types.string, "_VAL": [$XXX_UNEXISTENT_VAR_XXX]}])')) + end) + + it('can dump NULL list', function() + eq({'\144'}, eval('msgpackdump([v:_null_list])')) + end) + + it('can dump NULL dictionary', function() + eq({'\128'}, eval('msgpackdump([v:_null_dict])')) + end) end) diff --git a/test/functional/server/server_spec.lua b/test/functional/eval/server_spec.lua index 649e9dbabe..7f53522c08 100644 --- a/test/functional/server/server_spec.lua +++ b/test/functional/eval/server_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers') local nvim, eq, neq, eval = helpers.nvim, helpers.eq, helpers.neq, helpers.eval local clear, funcs, meths = helpers.clear, helpers.funcs, helpers.meths -local os_is_windows = helpers.os_is_windows +local os_name = helpers.os_name describe('serverstart(), serverstop()', function() before_each(clear) @@ -39,7 +39,7 @@ describe('serverstart(), serverstop()', function() eq('', meths.get_vvar('servername')) -- v:servername will take the next available server. - local servername = (os_is_windows() + local servername = (os_name() == 'windows' and [[\\.\pipe\Xtest-functional-server-server-pipe]] or 'Xtest-functional-server-server-socket') funcs.serverstart(servername) diff --git a/test/functional/eval/special_vars_spec.lua b/test/functional/eval/special_vars_spec.lua new file mode 100644 index 0000000000..6ab4e6a7d7 --- /dev/null +++ b/test/functional/eval/special_vars_spec.lua @@ -0,0 +1,171 @@ +local helpers = require('test.functional.helpers') +local exc_exec = helpers.exc_exec +local execute = helpers.execute +local meths = helpers.meths +local funcs = helpers.funcs +local meths = helpers.meths +local clear = helpers.clear +local eval = helpers.eval +local eq = helpers.eq + +describe('Special values', function() + before_each(clear) + + it('do not cause error when freed', function() + execute([[ + function Test() + try + return v:true + finally + return 'something else' + endtry + endfunction + ]]) + eq(0, exc_exec('call Test()')) + end) + + it('work with empty()', function() + eq(0, funcs.empty(true)) + eq(1, funcs.empty(false)) + eq(1, funcs.empty(NIL)) + end) + + it('can be stringified and eval’ed back', function() + eq(true, funcs.eval(funcs.string(true))) + eq(false, funcs.eval(funcs.string(false))) + eq(NIL, funcs.eval(funcs.string(NIL))) + end) + + it('work with is/isnot properly', function() + eq(1, eval('v:null is v:null')) + eq(0, eval('v:null is v:true')) + eq(0, eval('v:null is v:false')) + eq(1, eval('v:true is v:true')) + eq(0, eval('v:true is v:false')) + eq(1, eval('v:false is v:false')) + + eq(0, eval('v:null is 0')) + eq(0, eval('v:true is 0')) + eq(0, eval('v:false is 0')) + + eq(0, eval('v:null is 1')) + eq(0, eval('v:true is 1')) + eq(0, eval('v:false is 1')) + + eq(0, eval('v:null is ""')) + eq(0, eval('v:true is ""')) + eq(0, eval('v:false is ""')) + + eq(0, eval('v:null is "null"')) + eq(0, eval('v:true is "true"')) + eq(0, eval('v:false is "false"')) + + eq(0, eval('v:null is []')) + eq(0, eval('v:true is []')) + eq(0, eval('v:false is []')) + + eq(0, eval('v:null isnot v:null')) + eq(1, eval('v:null isnot v:true')) + eq(1, eval('v:null isnot v:false')) + eq(0, eval('v:true isnot v:true')) + eq(1, eval('v:true isnot v:false')) + eq(0, eval('v:false isnot v:false')) + + eq(1, eval('v:null isnot 0')) + eq(1, eval('v:true isnot 0')) + eq(1, eval('v:false isnot 0')) + + eq(1, eval('v:null isnot 1')) + eq(1, eval('v:true isnot 1')) + eq(1, eval('v:false isnot 1')) + + eq(1, eval('v:null isnot ""')) + eq(1, eval('v:true isnot ""')) + eq(1, eval('v:false isnot ""')) + + eq(1, eval('v:null isnot "null"')) + eq(1, eval('v:true isnot "true"')) + eq(1, eval('v:false isnot "false"')) + + eq(1, eval('v:null isnot []')) + eq(1, eval('v:true isnot []')) + eq(1, eval('v:false isnot []')) + end) + + it('work with +/-/* properly', function() + eq(1, eval('0 + v:true')) + eq(0, eval('0 + v:null')) + eq(0, eval('0 + v:false')) + + eq(-1, eval('0 - v:true')) + eq( 0, eval('0 - v:null')) + eq( 0, eval('0 - v:false')) + + eq(1, eval('1 * v:true')) + eq(0, eval('1 * v:null')) + eq(0, eval('1 * v:false')) + end) + + it('does not work with +=/-=/.=', function() + meths.set_var('true', true) + meths.set_var('false', false) + execute('let null = v:null') + + eq('Vim(let):E734: Wrong variable type for +=', exc_exec('let true += 1')) + eq('Vim(let):E734: Wrong variable type for +=', exc_exec('let false += 1')) + eq('Vim(let):E734: Wrong variable type for +=', exc_exec('let null += 1')) + + eq('Vim(let):E734: Wrong variable type for -=', exc_exec('let true -= 1')) + eq('Vim(let):E734: Wrong variable type for -=', exc_exec('let false -= 1')) + eq('Vim(let):E734: Wrong variable type for -=', exc_exec('let null -= 1')) + + eq('Vim(let):E734: Wrong variable type for .=', exc_exec('let true .= 1')) + eq('Vim(let):E734: Wrong variable type for .=', exc_exec('let false .= 1')) + eq('Vim(let):E734: Wrong variable type for .=', exc_exec('let null .= 1')) + end) + + it('work with . (concat) properly', function() + eq("true", eval('"" . v:true')) + eq("null", eval('"" . v:null')) + eq("false", eval('"" . v:false')) + end) + + it('work with type()', function() + eq(6, funcs.type(true)) + eq(6, funcs.type(false)) + eq(7, funcs.type(NIL)) + end) + + it('work with copy() and deepcopy()', function() + eq(true, funcs.deepcopy(true)) + eq(false, funcs.deepcopy(false)) + eq(NIL, funcs.deepcopy(NIL)) + + eq(true, funcs.copy(true)) + eq(false, funcs.copy(false)) + eq(NIL, funcs.copy(NIL)) + end) + + it('fails in index', function() + eq('Vim(echo):E909: Cannot index a special variable', exc_exec('echo v:true[0]')) + eq('Vim(echo):E909: Cannot index a special variable', exc_exec('echo v:false[0]')) + eq('Vim(echo):E909: Cannot index a special variable', exc_exec('echo v:null[0]')) + end) + + it('is accepted by assert_true and assert_false', function() + funcs.assert_false(false) + funcs.assert_false(true) + funcs.assert_false(NIL) + + funcs.assert_true(false) + funcs.assert_true(true) + funcs.assert_true(NIL) + + eq({ + 'Expected False but got v:true', + 'Expected False but got v:null', + 'Expected True but got v:false', + 'Expected True but got v:null', + }, meths.get_vvar('errors')) + end) +end) diff --git a/test/functional/eval/string_spec.lua b/test/functional/eval/string_spec.lua index f7f5dca70a..0fd7587edb 100644 --- a/test/functional/eval/string_spec.lua +++ b/test/functional/eval/string_spec.lua @@ -28,6 +28,15 @@ describe('string() function', function() eq('0.0', eval('string(0.0)')) end) + it('dumps special v: values', function() + eq('v:true', eval('string(v:true)')) + eq('v:false', eval('string(v:false)')) + eq('v:null', eval('string(v:null)')) + eq('v:true', funcs.string(true)) + eq('v:false', funcs.string(false)) + eq('v:null', funcs.string(NIL)) + end) + it('dumps values with at most six digits after the decimal point', function() eq('1.234568e-20', funcs.string(1.23456789123456789123456789e-020)) @@ -78,6 +87,18 @@ describe('string() function', function() eq('\'\'\'b\'\'\'\'d\'', funcs.string('\'b\'\'d')) eq('\'a\'\'b\'\'c\'\'d\'', funcs.string('a\'b\'c\'d')) end) + + it('dumps NULL strings', function() + eq('\'\'', eval('string($XXX_UNEXISTENT_VAR_XXX)')) + end) + + it('dumps NULL lists', function() + eq('[]', eval('string(v:_null_list)')) + end) + + it('dumps NULL dictionaries', function() + eq('{}', eval('string(v:_null_dict)')) + end) end) describe('used to represent funcrefs', function() diff --git a/test/functional/ex_cmds/cd_spec.lua b/test/functional/ex_cmds/cd_spec.lua new file mode 100644 index 0000000000..f5cce65104 --- /dev/null +++ b/test/functional/ex_cmds/cd_spec.lua @@ -0,0 +1,148 @@ +-- Specs for :cd, :tcd, :lcd and getcwd() + +local helpers = require('test.functional.helpers') +local execute, eq, clear, eval, exc_exec = + helpers.execute, helpers.eq, helpers.clear, helpers.eval, helpers.exc_exec + + +-- These directories will be created for testing +local directories = { + 'Xtest-functional-ex_cmds-cd_spec.1', -- Tab + 'Xtest-functional-ex_cmds-cd_spec.2', -- Window + 'Xtest-functional-ex_cmds-cd_spec.3', -- New global +} + +-- Shorthand writing to get the current working directory +local cwd = function() return eval('getcwd( )') end -- effective working dir +local wcwd = function() return eval('getcwd( 0 )') end -- window dir +local tcwd = function() return eval('getcwd(-1, 0)') end -- tab dir +local gcwd = function() return eval('getcwd(-1, -1)') end -- global dir + +-- Same, except these tell us if there is a working directory at all +local lwd = function() return eval('haslocaldir( )') end -- effective working dir +local wlwd = function() return eval('haslocaldir( 0 )') end -- window dir +local tlwd = function() return eval('haslocaldir(-1, 0)') end -- tab dir +local glwd = function() return eval('haslocaldir(-1, -1)') end -- global dir + +-- Test both the `cd` and `chdir` variants +for _, cmd in ipairs {'cd', 'chdir'} do + describe(':*' .. cmd, function() + before_each(function() + clear() + for _, d in ipairs(directories) do + lfs.mkdir(d) + end + end) + + after_each(function() + for _, d in ipairs(directories) do + lfs.rmdir(d) + end + end) + + it('works', function() + -- Store the initial working directory + local globalDir = cwd() + + -- Create a new tab first and verify that is has the same working dir + execute('tabnew') + eq(globalDir, cwd()) + eq(globalDir, tcwd()) -- has no tab-local directory + eq(0, tlwd()) + eq(globalDir, wcwd()) -- has no window-local directory + eq(0, wlwd()) + + -- Change tab-local working directory and verify it is different + execute('t' .. cmd .. ' ' .. directories[1]) + eq(globalDir .. '/' .. directories[1], cwd()) + eq(cwd(), tcwd()) -- working directory maches tab directory + eq(1, tlwd()) + eq(cwd(), wcwd()) -- still no window-directory + eq(0, wlwd()) + + -- Create a new window in this tab to test `:lcd` + execute('new') + eq(1, tlwd()) -- Still tab-local working directory + eq(0, wlwd()) -- Still no window-local working directory + eq(globalDir .. '/' .. directories[1], cwd()) + execute('l' .. cmd .. ' ../' .. directories[2]) + eq(globalDir .. '/' .. directories[2], cwd()) + eq(globalDir .. '/' .. directories[1], tcwd()) + eq(1, wlwd()) + + -- Verify the first window still has the tab local directory + execute('wincmd w') + eq(globalDir .. '/' .. directories[1], cwd()) + eq(globalDir .. '/' .. directories[1], tcwd()) + eq(0, wlwd()) -- No window-local directory + + -- Change back to initial tab and verify working directory has stayed + execute('tabnext') + eq(globalDir, cwd() ) + eq(0, tlwd()) + eq(0, wlwd()) + + -- Verify global changes don't affect local ones + execute('' .. cmd .. ' ' .. directories[3]) + eq(globalDir .. '/' .. directories[3], cwd()) + execute('tabnext') + eq(globalDir .. '/' .. directories[1], cwd()) + eq(globalDir .. '/' .. directories[1], tcwd()) + eq(0, wlwd()) -- Still no window-local directory in this window + + -- Unless the global change happened in a tab with local directory + execute('' .. cmd .. ' ..') + eq(globalDir, cwd() ) + eq(0 , tlwd()) + eq(0 , wlwd()) + -- Which also affects the first tab + execute('tabnext') + eq(globalDir, cwd()) + + -- But not in a window with its own local directory + execute('tabnext | wincmd w') + eq(globalDir .. '/' .. directories[2], cwd() ) + eq(0 , tlwd()) + eq(globalDir .. '/' .. directories[2], wcwd()) + end) + end) +end + +-- Test legal parameters for 'getcwd' and 'haslocaldir' +for _, cmd in ipairs {'getcwd', 'haslocaldir'} do + describe(cmd..'()', function() + -- Test invalid argument types + local expected = 'Vim(call):E474: Invalid argument' + it('fails on string', function() + eq(expected, exc_exec('call ' .. cmd .. '("some string")')) + end) + it('fails on float', function() + eq(expected, exc_exec('call ' .. cmd .. '(1.0)')) + end) + it('fails on list', function() + eq(expected, exc_exec('call ' .. cmd .. '([1, 2])')) + end) + it('fails on dictionary', function() + eq(expected, exc_exec('call ' .. cmd .. '({"key": "value"})')) + end) + it('fails on funcref', function() + eq(expected, exc_exec('call ' .. cmd .. '(function("tr"))')) + end) + + -- Test invalid numbers + it('fails on number less than -1', function() + eq(expected, exc_exec('call ' .. cmd .. '(-2)')) + end) + local expected = 'Vim(call):E5001: Higher scope cannot be -1 if lower scope is >= 0.' + it('fails on -1 if previous arg is >=0', function() + eq(expected, exc_exec('call ' .. cmd .. '(0, -1)')) + end) + + -- Test wrong number of arguments + local expected = 'Vim(call):E118: Too many arguments for function: ' .. cmd + it('fails to parse more than one argument', function() + eq(expected, exc_exec('call ' .. cmd .. '(0, 0, 0)')) + end) + end) +end + diff --git a/test/functional/ex_cmds/oldfiles_spec.lua b/test/functional/ex_cmds/oldfiles_spec.lua index dac6757a97..5bba1a0e7c 100644 --- a/test/functional/ex_cmds/oldfiles_spec.lua +++ b/test/functional/ex_cmds/oldfiles_spec.lua @@ -2,7 +2,7 @@ local Screen = require('test.functional.ui.screen') local helpers = require('test.functional.helpers') local buf, eq, execute = helpers.curbufmeths, helpers.eq, helpers.execute -local feed, nvim_prog = helpers.feed, helpers.nvim_prog +local feed, nvim_prog, wait = helpers.feed, helpers.nvim_prog, helpers.wait local ok, set_session, spawn = helpers.ok, helpers.set_session, helpers.spawn local shada_file = 'test.shada' @@ -59,9 +59,13 @@ describe(':oldfiles!', function() execute('edit testfile2') filename2 = buf.get_name() execute('wshada ' .. shada_file) + wait() _clear() execute('rshada! ' .. shada_file) + -- Ensure nvim is out of "Press ENTER..." screen + feed('<cr>') + -- Ensure v:oldfiles isn't busted. Since things happen so fast, -- the ordering of v:oldfiles is unstable (it uses qsort() under-the-hood). -- Let's verify the contents and the length of v:oldfiles before moving on. diff --git a/test/functional/ex_cmds/wundo_spec.lua b/test/functional/ex_cmds/wundo_spec.lua index c3147e1c0f..969dfea3d9 100644 --- a/test/functional/ex_cmds/wundo_spec.lua +++ b/test/functional/ex_cmds/wundo_spec.lua @@ -24,6 +24,6 @@ describe('u_* functions', function() '-c', 'set undodir=. undofile'}) set_session(session) execute('echo "True"') -- Should not error out due to crashed Neovim - session:exit(0) + session:close() end) end) diff --git a/test/functional/ex_cmds/wviminfo_spec.lua b/test/functional/ex_cmds/wviminfo_spec.lua index 207d94124f..21f14be62c 100644 --- a/test/functional/ex_cmds/wviminfo_spec.lua +++ b/test/functional/ex_cmds/wviminfo_spec.lua @@ -9,7 +9,7 @@ describe(':wshada', function() before_each(function() if session then - session:exit(0) + session:close() end -- Override the default session because we need 'swapfile' for these tests. diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 1fba15c2c3..a382641cff 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -1,10 +1,8 @@ require('coxpcall') -local ffi = require('ffi') +NIL = require('mpack').NIL local lfs = require('lfs') local assert = require('luassert') -local Loop = require('nvim.loop') -local MsgpackStream = require('nvim.msgpack_stream') -local AsyncSession = require('nvim.async_session') +local ChildProcessStream = require('nvim.child_process_stream') local Session = require('nvim.session') local nvim_prog = os.getenv('NVIM_PROG') or 'build/bin/nvim' @@ -60,6 +58,9 @@ end local session, loop_running, last_error local function set_session(s) + if session then + session:close() + end session = s end @@ -133,6 +134,22 @@ local function nvim_eval(expr) return request('vim_eval', expr) end +local os_name = (function() + local name = nil + return (function() + if not name then + if nvim_eval('has("win32")') == 1 then + name = 'windows' + elseif nvim_eval('has("macunix")') == 1 then + name = 'osx' + else + name = 'unix' + end + end + return name + end) +end)() + local function nvim_call(name, ...) return request('vim_call_function', name, {...}) end @@ -194,24 +211,17 @@ local function merge_args(...) end local function spawn(argv, merge) - local loop = Loop.new() - local msgpack_stream = MsgpackStream.new(loop) - local async_session = AsyncSession.new(msgpack_stream) - local sess = Session.new(async_session) - loop:spawn(merge and merge_args(prepend_argv, argv) or argv) - return sess + local child_stream = ChildProcessStream.spawn(merge and merge_args(prepend_argv, argv) or argv) + return Session.new(child_stream) end local function clear(extra_cmd) - if session then - session:exit(0) - end local args = {unpack(nvim_argv)} if extra_cmd ~= nil then table.insert(args, '--cmd') table.insert(args, extra_cmd) end - session = spawn(args) + set_session(spawn(args)) end local function insert(...) @@ -247,7 +257,7 @@ end local function source(code) local tmpname = os.tmpname() - if ffi.os == 'OSX' and string.match(tmpname, '^/tmp') then + if os_name() == 'osx' and string.match(tmpname, '^/tmp') then tmpname = '/private'..tmpname end write_file(tmpname, code) @@ -305,7 +315,7 @@ local function curbuf_contents() -- previously sent keys are processed(vim_eval is a deferred function, and -- only processed after all input) wait() - return table.concat(curbuf('get_line_slice', 0, -1, true, true), '\n') + return table.concat(curbuf('get_lines', 0, -1, true), '\n') end local function curwin(method, ...) @@ -328,24 +338,18 @@ local function expect(contents) return eq(dedent(contents), curbuf_contents()) end -local function os_is_windows() - return nvim_eval('has("win32")') == 1 -end - local function rmdir(path) if lfs.attributes(path, 'mode') ~= 'directory' then return nil end for file in lfs.dir(path) do - if file == '.' or file == '..' then - goto continue - end - local ret, err = os.remove(path..'/'..file) - if not ret then - error('os.remove: '..err) - return nil + if file ~= '.' and file ~= '..' then + local ret, err = os.remove(path..'/'..file) + if not ret then + error('os.remove: '..err) + return nil + end end - ::continue:: end local ret, err = os.remove(path) if not ret then @@ -434,7 +438,7 @@ return { wait = wait, set_session = set_session, write_file = write_file, - os_is_windows = os_is_windows, + os_name = os_name, rmdir = rmdir, mkdir = lfs.mkdir, exc_exec = exc_exec, diff --git a/test/functional/legacy/036_regexp_character_classes_spec.lua b/test/functional/legacy/036_regexp_character_classes_spec.lua index 3c264423ff..de080f4b43 100644 --- a/test/functional/legacy/036_regexp_character_classes_spec.lua +++ b/test/functional/legacy/036_regexp_character_classes_spec.lua @@ -1,9 +1,9 @@ -- Test character classes in regexp using regexpengine 0, 1, 2. local helpers = require('test.functional.helpers') -local ffi = require('ffi') local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect local source, write_file = helpers.source, helpers.write_file +local os_name = helpers.os_name local function sixlines(text) local result = '' @@ -15,7 +15,7 @@ end local function diff(text, nodedent) local tmpname = os.tmpname() - if ffi.os == 'OSX' and string.match(tmpname, '^/tmp') then + if os_name() == 'osx' and string.match(tmpname, '^/tmp') then tmpname = '/private'..tmpname end execute('w! '..tmpname) @@ -30,7 +30,7 @@ local function diff(text, nodedent) end describe('character classes in regexp', function() - local ctrl1 = '\t\x0c\r' + local ctrl1 = '\t\012\r' local punct1 = " !\"#$%&'()#+'-./" local digits = '0123456789' local punct2 = ':;<=>?@' @@ -38,8 +38,8 @@ describe('character classes in regexp', function() local punct3 = '[\\]^_`' local lower = 'abcdefghiwxyz' local punct4 = '{|}~' - local ctrl2 = '\x7f\x80\x82\x90\x9b' - local iso_text = '\xa6\xb1\xbc\xc7\xd3\xe9' -- "¦±¼ÇÓé" in utf-8 + local ctrl2 = '\127\128\130\144\155' + local iso_text = '\166\177\188\199\211\233' -- "¦±¼ÇÓé" in utf-8 setup(function() -- The original test32.in file was not in utf-8 encoding and did also -- contain some control characters. We use lua escape sequences to write diff --git a/test/functional/legacy/039_visual_block_mode_commands_spec.lua b/test/functional/legacy/039_visual_block_mode_commands_spec.lua index 6e1879035b..7195d7d11d 100644 --- a/test/functional/legacy/039_visual_block_mode_commands_spec.lua +++ b/test/functional/legacy/039_visual_block_mode_commands_spec.lua @@ -187,7 +187,7 @@ describe('Visual block mode', function() 98<Nul>65 98<Nul>65]] expected = expected:gsub('<CR>', '\r') - expected = expected:gsub('<Nul>', '\x00') + expected = expected:gsub('<Nul>', '\000') expect(expected) end) diff --git a/test/functional/legacy/061_undo_tree_spec.lua b/test/functional/legacy/061_undo_tree_spec.lua index ceb114b2a7..6db37bf1ff 100644 --- a/test/functional/legacy/061_undo_tree_spec.lua +++ b/test/functional/legacy/061_undo_tree_spec.lua @@ -191,7 +191,7 @@ describe('undo tree:', function() end) it('undo an expression-register', function() - local normal_commands = 'o1\x1ba2\x12=string(123)\n\x1b' + local normal_commands = 'o1\027a2\018=string(123)\n\027' write_file('Xtest.source', normal_commands) feed('oa<esc>') diff --git a/test/functional/legacy/062_tab_pages_spec.lua b/test/functional/legacy/062_tab_pages_spec.lua index c3cdcac471..f1c8b8d58b 100644 --- a/test/functional/legacy/062_tab_pages_spec.lua +++ b/test/functional/legacy/062_tab_pages_spec.lua @@ -139,7 +139,6 @@ describe('tab pages', function() autocmd TabLeave * :call add(g:r, 'TabLeave') autocmd WinLeave * :call add(g:r, 'WinLeave') autocmd BufLeave * :call add(g:r, 'BufLeave') - autocmd TabNew * :call add(g:r, 'TabNew') let t:a='a' C tab split let t:a='b' @@ -186,13 +185,11 @@ describe('tab pages', function() === tab split === WinLeave TabLeave - TabNew WinEnter TabEnter === tabnew === WinLeave TabLeave - TabNew WinEnter TabEnter BufLeave @@ -225,7 +222,6 @@ describe('tab pages', function() === tabnew === WinLeave TabLeave - TabNew WinEnter TabEnter BufLeave diff --git a/test/functional/legacy/083_tag_search_with_file_encoding_spec.lua b/test/functional/legacy/083_tag_search_with_file_encoding_spec.lua index dc6df007e6..6b5ee60568 100644 --- a/test/functional/legacy/083_tag_search_with_file_encoding_spec.lua +++ b/test/functional/legacy/083_tag_search_with_file_encoding_spec.lua @@ -24,7 +24,7 @@ describe('tag search with !_TAG_FILE_ENCODING', function() ]]) write_file('test83-tags2', '!_TAG_FILE_ENCODING cp932 //\n' .. - '\x82`\x82a\x82b Xtags2.txt /\x82`\x82a\x82b\n' + '\130`\130a\130b Xtags2.txt /\130`\130a\130b\n' ) -- The last file is very long but repetetive and can be generated on the -- fly. @@ -32,7 +32,7 @@ describe('tag search with !_TAG_FILE_ENCODING', function() !_TAG_FILE_SORTED 1 // !_TAG_FILE_ENCODING cp932 // ]]) - local line = ' Xtags3.txt /\x82`\x82a\x82b\n' + local line = ' Xtags3.txt /\130`\130a\130b\n' for i = 1, 100 do text = text .. 'abc' .. i .. line end diff --git a/test/functional/legacy/088_conceal_tabs_spec.lua b/test/functional/legacy/088_conceal_tabs_spec.lua new file mode 100644 index 0000000000..c78f4e5c3e --- /dev/null +++ b/test/functional/legacy/088_conceal_tabs_spec.lua @@ -0,0 +1,96 @@ +-- Tests for correct display (cursor column position) with +conceal and +-- tabulators. + +local helpers = require('test.functional.helpers') +local feed, insert, clear, execute = + helpers.feed, helpers.insert, helpers.clear, helpers.execute + +local expect_pos = function(row, col) + return helpers.eq({row, col}, helpers.eval('[screenrow(), screencol()]')) +end + +describe('cursor and column position with conceal and tabulators', function() + setup(clear) + + it('are working', function() + insert([[ + start: + .concealed. text + |concealed| text + + .concealed. text + |concealed| text + + .a. .b. .c. .d. + |a| |b| |c| |d|]]) + + -- Conceal settings. + execute('set conceallevel=2') + execute('set concealcursor=nc') + execute('syntax match test /|/ conceal') + -- Start test. + execute('/^start:') + feed('ztj') + expect_pos(2, 1) + -- We should end up in the same column when running these commands on the + -- two lines. + feed('ft') + expect_pos(2, 17) + feed('$') + expect_pos(2, 20) + feed('0j') + expect_pos(3, 1) + feed('ft') + expect_pos(3, 17) + feed('$') + expect_pos(3, 20) + feed('j0j') + expect_pos(5, 8) + -- Same for next test block. + feed('ft') + expect_pos(5, 25) + feed('$') + expect_pos(5, 28) + feed('0j') + expect_pos(6, 8) + feed('ft') + expect_pos(6, 25) + feed('$') + expect_pos(6, 28) + feed('0j0j') + expect_pos(8, 1) + -- And check W with multiple tabs and conceals in a line. + feed('W') + expect_pos(8, 9) + feed('W') + expect_pos(8, 17) + feed('W') + expect_pos(8, 25) + feed('$') + expect_pos(8, 27) + feed('0j') + expect_pos(9, 1) + feed('W') + expect_pos(9, 9) + feed('W') + expect_pos(9, 17) + feed('W') + expect_pos(9, 25) + feed('$') + expect_pos(9, 26) + execute('set lbr') + feed('$') + expect_pos(9, 26) + execute('set list listchars=tab:>-') + feed('0') + expect_pos(9, 1) + feed('W') + expect_pos(9, 9) + feed('W') + expect_pos(9, 17) + feed('W') + expect_pos(9, 25) + feed('$') + expect_pos(9, 26) + end) +end) diff --git a/test/functional/legacy/105_filename_modifiers_spec.lua b/test/functional/legacy/105_filename_modifiers_spec.lua deleted file mode 100644 index 3413667022..0000000000 --- a/test/functional/legacy/105_filename_modifiers_spec.lua +++ /dev/null @@ -1,81 +0,0 @@ --- Test filename modifiers. - -local helpers = require('test.functional.helpers') -local clear = helpers.clear -local execute, expect = helpers.execute, helpers.expect - -describe('filename modifiers', function() - setup(clear) - - it('is working', function() - local tmpdir = helpers.nvim('eval', 'resolve("/tmp")') - - execute('cd ' .. tmpdir) - execute([=[set shell=sh]=]) - execute([=[set shellslash]=]) - execute([=[let tab="\t"]=]) - execute([=[command -nargs=1 Put :let expr=<q-args> | $put =expr.tab.strtrans(string(eval(expr)))]=]) - execute([=[let $HOME=fnamemodify('.', ':p:h:h:h')]=]) - execute([=[Put fnamemodify('.', ':p' )[-1:]]=]) - execute([=[Put fnamemodify('.', ':p:h' )[-1:]]=]) - execute([=[Put fnamemodify('test.out', ':p' )[-1:]]=]) - execute([=[Put fnamemodify('test.out', ':.' )]=]) - execute([=[Put fnamemodify('../testdir/a', ':.' )]=]) - execute([=[Put fnamemodify('test.out', ':~' )]=]) - execute([=[Put fnamemodify('../testdir/a', ':~' )]=]) - execute([=[Put fnamemodify('../testdir/a', ':t' )]=]) - execute([=[Put fnamemodify('.', ':p:t' )]=]) - execute([=[Put fnamemodify('test.out', ':p:t' )]=]) - execute([=[Put fnamemodify('test.out', ':p:e' )]=]) - execute([=[Put fnamemodify('test.out', ':p:t:e' )]=]) - execute([=[Put fnamemodify('abc.fb2.tar.gz', ':r' )]=]) - execute([=[Put fnamemodify('abc.fb2.tar.gz', ':r:r' )]=]) - execute([=[Put fnamemodify('abc.fb2.tar.gz', ':r:r:r' )]=]) - execute([=[Put substitute(fnamemodify('abc.fb2.tar.gz', ':p:r:r'), '.*\(nvim/testdir/.*\)', '\1', '')]=]) - execute([=[Put fnamemodify('abc.fb2.tar.gz', ':e' )]=]) - execute([=[Put fnamemodify('abc.fb2.tar.gz', ':e:e' )]=]) - execute([=[Put fnamemodify('abc.fb2.tar.gz', ':e:e:e' )]=]) - execute([=[Put fnamemodify('abc.fb2.tar.gz', ':e:e:e:e')]=]) - execute([=[Put fnamemodify('abc.fb2.tar.gz', ':e:e:r' )]=]) - execute([=[Put fnamemodify('abc def', ':S' )]=]) - execute([=[Put fnamemodify('abc" "def', ':S' )]=]) - execute([=[Put fnamemodify('abc"%"def', ':S' )]=]) - execute([=[Put fnamemodify('abc'' ''def', ':S' )]=]) - execute([=[Put fnamemodify('abc''%''def', ':S' )]=]) - execute([=[Put fnamemodify("abc\ndef", ':S' )]=]) - execute([=[set shell=tcsh]=]) - execute([=[Put fnamemodify("abc\ndef", ':S' )]=]) - execute([=[1 delete _]=]) - - -- Assert buffer contents. - expect([=[ - fnamemodify('.', ':p' )[-1:] '/' - fnamemodify('.', ':p:h' )[-1:] 'p' - fnamemodify('test.out', ':p' )[-1:] 't' - fnamemodify('test.out', ':.' ) 'test.out' - fnamemodify('../testdir/a', ':.' ) '../testdir/a' - fnamemodify('test.out', ':~' ) 'test.out' - fnamemodify('../testdir/a', ':~' ) '../testdir/a' - fnamemodify('../testdir/a', ':t' ) 'a' - fnamemodify('.', ':p:t' ) '' - fnamemodify('test.out', ':p:t' ) 'test.out' - fnamemodify('test.out', ':p:e' ) 'out' - fnamemodify('test.out', ':p:t:e' ) 'out' - fnamemodify('abc.fb2.tar.gz', ':r' ) 'abc.fb2.tar' - fnamemodify('abc.fb2.tar.gz', ':r:r' ) 'abc.fb2' - fnamemodify('abc.fb2.tar.gz', ':r:r:r' ) 'abc' - substitute(fnamemodify('abc.fb2.tar.gz', ':p:r:r'), '.*\(nvim/testdir/.*\)', '\1', '') ']=] .. tmpdir .. [=[/abc.fb2' - fnamemodify('abc.fb2.tar.gz', ':e' ) 'gz' - fnamemodify('abc.fb2.tar.gz', ':e:e' ) 'tar.gz' - fnamemodify('abc.fb2.tar.gz', ':e:e:e' ) 'fb2.tar.gz' - fnamemodify('abc.fb2.tar.gz', ':e:e:e:e') 'fb2.tar.gz' - fnamemodify('abc.fb2.tar.gz', ':e:e:r' ) 'tar' - fnamemodify('abc def', ':S' ) '''abc def''' - fnamemodify('abc" "def', ':S' ) '''abc" "def''' - fnamemodify('abc"%"def', ':S' ) '''abc"%"def''' - fnamemodify('abc'' ''def', ':S' ) '''abc''\'''' ''\''''def''' - fnamemodify('abc''%''def', ':S' ) '''abc''\''''%''\''''def''' - fnamemodify("abc\ndef", ':S' ) '''abc^@def''' - fnamemodify("abc\ndef", ':S' ) '''abc\^@def''']=]) - end) -end) diff --git a/test/functional/legacy/delete_spec.lua b/test/functional/legacy/delete_spec.lua new file mode 100644 index 0000000000..cd18a8f750 --- /dev/null +++ b/test/functional/legacy/delete_spec.lua @@ -0,0 +1,99 @@ +local helpers = require('test.functional.helpers') +local clear, source = helpers.clear, helpers.source +local eq, eval, execute = helpers.eq, helpers.eval, helpers.execute + +describe('Test for delete()', function() + before_each(clear) + + it('file delete', function() + execute('split Xfile') + execute("call setline(1, ['a', 'b'])") + execute('wq') + eq(eval("['a', 'b']"), eval("readfile('Xfile')")) + eq(0, eval("delete('Xfile')")) + eq(-1, eval("delete('Xfile')")) + end) + + it('directory delete', function() + execute("call mkdir('Xdir1')") + eq(1, eval("isdirectory('Xdir1')")) + eq(0, eval("delete('Xdir1', 'd')")) + eq(0, eval("isdirectory('Xdir1')")) + eq(-1, eval("delete('Xdir1', 'd')")) + end) + it('recursive delete', function() + execute("call mkdir('Xdir1')") + execute("call mkdir('Xdir1/subdir')") + execute("call mkdir('Xdir1/empty')") + execute('split Xdir1/Xfile') + execute("call setline(1, ['a', 'b'])") + execute('w') + execute('w Xdir1/subdir/Xfile') + execute('close') + + eq(1, eval("isdirectory('Xdir1')")) + eq(eval("['a', 'b']"), eval("readfile('Xdir1/Xfile')")) + eq(1, eval("isdirectory('Xdir1/subdir')")) + eq(eval("['a', 'b']"), eval("readfile('Xdir1/subdir/Xfile')")) + eq(1, eval("isdirectory('Xdir1/empty')")) + eq(0, eval("delete('Xdir1', 'rf')")) + eq(0, eval("isdirectory('Xdir1')")) + eq(-1, eval("delete('Xdir1', 'd')")) + end) + + it('symlink delete', function() + source([[ + split Xfile + call setline(1, ['a', 'b']) + wq + silent !ln -s Xfile Xlink + ]]) + -- Delete the link, not the file + eq(0, eval("delete('Xlink')")) + eq(-1, eval("delete('Xlink')")) + eq(0, eval("delete('Xfile')")) + end) + + it('symlink directory delete', function() + execute("call mkdir('Xdir1')") + execute("silent !ln -s Xdir1 Xlink") + eq(1, eval("isdirectory('Xdir1')")) + eq(1, eval("isdirectory('Xlink')")) + -- Delete the link, not the directory + eq(0, eval("delete('Xlink')")) + eq(-1, eval("delete('Xlink')")) + eq(0, eval("delete('Xdir1', 'd')")) + end) + + it('symlink recursive delete', function() + source([[ + call mkdir('Xdir3') + call mkdir('Xdir3/subdir') + call mkdir('Xdir4') + split Xdir3/Xfile + call setline(1, ['a', 'b']) + w + w Xdir3/subdir/Xfile + w Xdir4/Xfile + close + silent !ln -s ../Xdir4 Xdir3/Xlink + ]]) + + eq(1, eval("isdirectory('Xdir3')")) + eq(eval("['a', 'b']"), eval("readfile('Xdir3/Xfile')")) + eq(1, eval("isdirectory('Xdir3/subdir')")) + eq(eval("['a', 'b']"), eval("readfile('Xdir3/subdir/Xfile')")) + eq(1, eval("isdirectory('Xdir4')")) + eq(1, eval("isdirectory('Xdir3/Xlink')")) + eq(eval("['a', 'b']"), eval("readfile('Xdir4/Xfile')")) + + eq(0, eval("delete('Xdir3', 'rf')")) + eq(0, eval("isdirectory('Xdir3')")) + eq(-1, eval("delete('Xdir3', 'd')")) + -- symlink is deleted, not the directory it points to + eq(1, eval("isdirectory('Xdir4')")) + eq(eval("['a', 'b']"), eval("readfile('Xdir4/Xfile')")) + eq(0, eval("delete('Xdir4/Xfile')")) + eq(0, eval("delete('Xdir4', 'd')")) + end) +end) diff --git a/test/functional/legacy/eval_spec.lua b/test/functional/legacy/eval_spec.lua index 1c81b47ed6..3ff1092a4b 100644 --- a/test/functional/legacy/eval_spec.lua +++ b/test/functional/legacy/eval_spec.lua @@ -54,8 +54,8 @@ describe('eval', function() expect([[ ": type v; value: abc (['abc']), expr: abc (['abc']) - ": type V; value: abc]].."\x00 (['abc']), expr: abc\x00"..[[ (['abc']) - ": type V; value: abc]].."\r\x00 (['abc\r']), expr: abc\r\x00 (['abc\r"..[[']) + ": type V; value: abc]].."\000 (['abc']), expr: abc\000"..[[ (['abc']) + ": type V; value: abc]].."\r\000 (['abc\r']), expr: abc\r\000 (['abc\r"..[[']) =: type v; value: abc (['abc']), expr: "abc" (['"abc"'])]]) end) @@ -97,29 +97,29 @@ describe('eval', function() == =abcB= {{{2 setreg('c', 'abcC', 'l') - c: type V; value: abcC]].."\x00 (['abcC']), expr: abcC\x00"..[[ (['abcC']) + c: type V; value: abcC]].."\000 (['abcC']), expr: abcC\000"..[[ (['abcC']) == abcC == {{{2 setreg('d', 'abcD', 'V') - d: type V; value: abcD]].."\x00 (['abcD']), expr: abcD\x00"..[[ (['abcD']) + d: type V; value: abcD]].."\000 (['abcD']), expr: abcD\000"..[[ (['abcD']) == abcD == {{{2 setreg('e', 'abcE', 'b') - e: type ]]..'\x16'..[[4; value: abcE (['abcE']), expr: abcE (['abcE']) + e: type ]]..'\022'..[[4; value: abcE (['abcE']), expr: abcE (['abcE']) == =abcE= - {{{2 setreg('f', 'abcF', ']]..'\x16'..[[') - f: type ]]..'\x16'..[[4; value: abcF (['abcF']), expr: abcF (['abcF']) + {{{2 setreg('f', 'abcF', ']]..'\022'..[[') + f: type ]]..'\022'..[[4; value: abcF (['abcF']), expr: abcF (['abcF']) == =abcF= {{{2 setreg('g', 'abcG', 'b10') - g: type ]]..'\x16'..[[10; value: abcG (['abcG']), expr: abcG (['abcG']) + g: type ]]..'\022'..[[10; value: abcG (['abcG']), expr: abcG (['abcG']) == =abcG = - {{{2 setreg('h', 'abcH', ']]..'\x16'..[[10') - h: type ]]..'\x16'..[[10; value: abcH (['abcH']), expr: abcH (['abcH']) + {{{2 setreg('h', 'abcH', ']]..'\022'..[[10') + h: type ]]..'\022'..[[10; value: abcH (['abcH']), expr: abcH (['abcH']) == =abcH = {{{2 setreg('I', 'abcI') @@ -132,12 +132,12 @@ describe('eval', function() == =abcAabcAc= {{{2 setreg('A', 'abcAl', 'l') - A: type V; value: abcAabcAcabcAl]].."\x00 (['abcAabcAcabcAl']), expr: abcAabcAcabcAl\x00"..[[ (['abcAabcAcabcAl']) + A: type V; value: abcAabcAcabcAl]].."\000 (['abcAabcAcabcAl']), expr: abcAabcAcabcAl\000"..[[ (['abcAabcAcabcAl']) == abcAabcAcabcAl == {{{2 setreg('A', 'abcAc2', 'c') - A: type v; value: abcAabcAcabcAl]].."\x00abcAc2 (['abcAabcAcabcAl', 'abcAc2']), expr: abcAabcAcabcAl\x00"..[[abcAc2 (['abcAabcAcabcAl', 'abcAc2']) + A: type v; value: abcAabcAcabcAl]].."\000abcAc2 (['abcAabcAcabcAl', 'abcAc2']), expr: abcAabcAcabcAl\000"..[[abcAc2 (['abcAabcAcabcAl', 'abcAc2']) == =abcAabcAcabcAl abcAc2= @@ -146,50 +146,50 @@ describe('eval', function() == =abcBabcBc= {{{2 setreg('b', 'abcBb', 'ba') - b: type ]]..'\x16'..[[5; value: abcBabcBcabcBb (['abcBabcBcabcBb']), expr: abcBabcBcabcBb (['abcBabcBcabcBb']) + b: type ]]..'\022'..[[5; value: abcBabcBcabcBb (['abcBabcBcabcBb']), expr: abcBabcBcabcBb (['abcBabcBcabcBb']) == =abcBabcBcabcBb= {{{2 setreg('b', 'abcBc2', 'ca') - b: type v; value: abcBabcBcabcBb]].."\x00abcBc2 (['abcBabcBcabcBb', 'abcBc2']), expr: abcBabcBcabcBb\x00"..[[abcBc2 (['abcBabcBcabcBb', 'abcBc2']) + b: type v; value: abcBabcBcabcBb]].."\000abcBc2 (['abcBabcBcabcBb', 'abcBc2']), expr: abcBabcBcabcBb\000"..[[abcBc2 (['abcBabcBcabcBb', 'abcBc2']) == =abcBabcBcabcBb abcBc2= {{{2 setreg('b', 'abcBb2', 'b50a') - b: type ]].."\x1650; value: abcBabcBcabcBb\x00abcBc2abcBb2 (['abcBabcBcabcBb', 'abcBc2abcBb2']), expr: abcBabcBcabcBb\x00"..[[abcBc2abcBb2 (['abcBabcBcabcBb', 'abcBc2abcBb2']) + b: type ]].."\02250; value: abcBabcBcabcBb\000abcBc2abcBb2 (['abcBabcBcabcBb', 'abcBc2abcBb2']), expr: abcBabcBcabcBb\000"..[[abcBc2abcBb2 (['abcBabcBcabcBb', 'abcBc2abcBb2']) == =abcBabcBcabcBb = abcBc2abcBb2 {{{2 setreg('C', 'abcCl', 'l') - C: type V; value: abcC]].."\x00abcCl\x00 (['abcC', 'abcCl']), expr: abcC\x00abcCl\x00"..[[ (['abcC', 'abcCl']) + C: type V; value: abcC]].."\000abcCl\000 (['abcC', 'abcCl']), expr: abcC\000abcCl\000"..[[ (['abcC', 'abcCl']) == abcC abcCl == {{{2 setreg('C', 'abcCc', 'c') - C: type v; value: abcC]].."\x00abcCl\x00abcCc (['abcC', 'abcCl', 'abcCc']), expr: abcC\x00abcCl\x00"..[[abcCc (['abcC', 'abcCl', 'abcCc']) + C: type v; value: abcC]].."\000abcCl\000abcCc (['abcC', 'abcCl', 'abcCc']), expr: abcC\000abcCl\000"..[[abcCc (['abcC', 'abcCl', 'abcCc']) == =abcC abcCl abcCc= {{{2 setreg('D', 'abcDb', 'b') - D: type ]].."\x165; value: abcD\x00abcDb (['abcD', 'abcDb']), expr: abcD\x00"..[[abcDb (['abcD', 'abcDb']) + D: type ]].."\0225; value: abcD\000abcDb (['abcD', 'abcDb']), expr: abcD\000"..[[abcDb (['abcD', 'abcDb']) == =abcD = abcDb {{{2 setreg('E', 'abcEb', 'b') - E: type ]].."\x165; value: abcE\x00abcEb (['abcE', 'abcEb']), expr: abcE\x00"..[[abcEb (['abcE', 'abcEb']) + E: type ]].."\0225; value: abcE\000abcEb (['abcE', 'abcEb']), expr: abcE\000"..[[abcEb (['abcE', 'abcEb']) == =abcE = abcEb {{{2 setreg('E', 'abcEl', 'l') - E: type V; value: abcE]].."\x00abcEb\x00abcEl\x00 (['abcE', 'abcEb', 'abcEl']), expr: abcE\x00abcEb\x00abcEl\x00"..[[ (['abcE', 'abcEb', 'abcEl']) + E: type V; value: abcE]].."\000abcEb\000abcEl\000 (['abcE', 'abcEb', 'abcEl']), expr: abcE\000abcEb\000abcEl\000"..[[ (['abcE', 'abcEb', 'abcEl']) == abcE abcEb abcEl == {{{2 setreg('F', 'abcFc', 'c') - F: type v; value: abcF]].."\x00abcFc (['abcF', 'abcFc']), expr: abcF\x00"..[[abcFc (['abcF', 'abcFc']) + F: type v; value: abcF]].."\000abcFc (['abcF', 'abcFc']), expr: abcF\000"..[[abcFc (['abcF', 'abcFc']) == =abcF abcFc=]]) @@ -219,36 +219,36 @@ describe('eval', function() execute([[call SetReg('F', "\n", 'b')]]) expect([[ - {{{2 setreg('A', ']]..'\x00'..[[') - A: type V; value: abcA2]].."\x00 (['abcA2']), expr: abcA2\x00"..[[ (['abcA2']) + {{{2 setreg('A', ']]..'\000'..[[') + A: type V; value: abcA2]].."\000 (['abcA2']), expr: abcA2\000"..[[ (['abcA2']) == abcA2 == - {{{2 setreg('B', ']]..'\x00'..[[', 'c') - B: type v; value: abcB2]].."\x00 (['abcB2', '']), expr: abcB2\x00"..[[ (['abcB2', '']) + {{{2 setreg('B', ']]..'\000'..[[', 'c') + B: type v; value: abcB2]].."\000 (['abcB2', '']), expr: abcB2\000"..[[ (['abcB2', '']) == =abcB2 = - {{{2 setreg('C', ']]..'\x00'..[[') - C: type V; value: abcC2]].."\x00\x00 (['abcC2', '']), expr: abcC2\x00\x00"..[[ (['abcC2', '']) + {{{2 setreg('C', ']]..'\000'..[[') + C: type V; value: abcC2]].."\000\000 (['abcC2', '']), expr: abcC2\000\000"..[[ (['abcC2', '']) == abcC2 == - {{{2 setreg('D', ']]..'\x00'..[[', 'l') - D: type V; value: abcD2]].."\x00\x00 (['abcD2', '']), expr: abcD2\x00\x00"..[[ (['abcD2', '']) + {{{2 setreg('D', ']]..'\000'..[[', 'l') + D: type V; value: abcD2]].."\000\000 (['abcD2', '']), expr: abcD2\000\000"..[[ (['abcD2', '']) == abcD2 == - {{{2 setreg('E', ']]..'\x00'..[[') - E: type V; value: abcE2]].."\x00\x00 (['abcE2', '']), expr: abcE2\x00\x00"..[[ (['abcE2', '']) + {{{2 setreg('E', ']]..'\000'..[[') + E: type V; value: abcE2]].."\000\000 (['abcE2', '']), expr: abcE2\000\000"..[[ (['abcE2', '']) == abcE2 == - {{{2 setreg('F', ']]..'\x00'..[[', 'b') - F: type ]].."\x160; value: abcF2\x00 (['abcF2', '']), expr: abcF2\x00"..[[ (['abcF2', '']) + {{{2 setreg('F', ']]..'\000'..[[', 'b') + F: type ]].."\0220; value: abcF2\000 (['abcF2', '']), expr: abcF2\000"..[[ (['abcF2', '']) == =abcF2= ]]) @@ -282,21 +282,21 @@ describe('eval', function() == =abcA3= {{{2 setreg('b', ['abcB3'], 'l') - b: type V; value: abcB3]].."\x00 (['abcB3']), expr: abcB3\x00"..[[ (['abcB3']) + b: type V; value: abcB3]].."\000 (['abcB3']), expr: abcB3\000"..[[ (['abcB3']) == abcB3 == {{{2 setreg('c', ['abcC3'], 'b') - c: type ]]..'\x16'..[[5; value: abcC3 (['abcC3']), expr: abcC3 (['abcC3']) + c: type ]]..'\022'..[[5; value: abcC3 (['abcC3']), expr: abcC3 (['abcC3']) == =abcC3= {{{2 setreg('d', ['abcD3']) - d: type V; value: abcD3]].."\x00 (['abcD3']), expr: abcD3\x00"..[[ (['abcD3']) + d: type V; value: abcD3]].."\000 (['abcD3']), expr: abcD3\000"..[[ (['abcD3']) == abcD3 == {{{2 setreg('e', [1, 2, 'abc', 3]) - e: type V; value: 1]].."\x002\x00abc\x003\x00 (['1', '2', 'abc', '3']), expr: 1\x002\x00abc\x003\x00"..[[ (['1', '2', 'abc', '3']) + e: type V; value: 1]].."\0002\000abc\0003\000 (['1', '2', 'abc', '3']), expr: 1\0002\000abc\0003\000"..[[ (['1', '2', 'abc', '3']) == 1 2 @@ -304,7 +304,7 @@ describe('eval', function() 3 == {{{2 setreg('f', [1, 2, 3]) - f: type V; value: 1]].."\x002\x003\x00 (['1', '2', '3']), expr: 1\x002\x003\x00"..[[ (['1', '2', '3']) + f: type V; value: 1]].."\0002\0003\000 (['1', '2', '3']), expr: 1\0002\0003\000"..[[ (['1', '2', '3']) == 1 2 @@ -312,49 +312,49 @@ describe('eval', function() == {{{1 Appending lists with setreg() {{{2 setreg('A', ['abcA3c'], 'c') - A: type v; value: abcA3]].."\x00abcA3c (['abcA3', 'abcA3c']), expr: abcA3\x00"..[[abcA3c (['abcA3', 'abcA3c']) + A: type v; value: abcA3]].."\000abcA3c (['abcA3', 'abcA3c']), expr: abcA3\000"..[[abcA3c (['abcA3', 'abcA3c']) == =abcA3 abcA3c= {{{2 setreg('b', ['abcB3l'], 'la') - b: type V; value: abcB3]].."\x00abcB3l\x00 (['abcB3', 'abcB3l']), expr: abcB3\x00abcB3l\x00"..[[ (['abcB3', 'abcB3l']) + b: type V; value: abcB3]].."\000abcB3l\000 (['abcB3', 'abcB3l']), expr: abcB3\000abcB3l\000"..[[ (['abcB3', 'abcB3l']) == abcB3 abcB3l == {{{2 setreg('C', ['abcC3b'], 'lb') - C: type ]].."\x166; value: abcC3\x00abcC3b (['abcC3', 'abcC3b']), expr: abcC3\x00"..[[abcC3b (['abcC3', 'abcC3b']) + C: type ]].."\0226; value: abcC3\000abcC3b (['abcC3', 'abcC3b']), expr: abcC3\000"..[[abcC3b (['abcC3', 'abcC3b']) == =abcC3 = abcC3b {{{2 setreg('D', ['abcD32']) - D: type V; value: abcD3]].."\x00abcD32\x00 (['abcD3', 'abcD32']), expr: abcD3\x00abcD32\x00"..[[ (['abcD3', 'abcD32']) + D: type V; value: abcD3]].."\000abcD32\000 (['abcD3', 'abcD32']), expr: abcD3\000abcD32\000"..[[ (['abcD3', 'abcD32']) == abcD3 abcD32 == {{{2 setreg('A', ['abcA32']) - A: type V; value: abcA3]].."\x00abcA3c\x00abcA32\x00 (['abcA3', 'abcA3c', 'abcA32']), expr: abcA3\x00abcA3c\x00abcA32\x00"..[[ (['abcA3', 'abcA3c', 'abcA32']) + A: type V; value: abcA3]].."\000abcA3c\000abcA32\000 (['abcA3', 'abcA3c', 'abcA32']), expr: abcA3\000abcA3c\000abcA32\000"..[[ (['abcA3', 'abcA3c', 'abcA32']) == abcA3 abcA3c abcA32 == {{{2 setreg('B', ['abcB3c'], 'c') - B: type v; value: abcB3]].."\x00abcB3l\x00abcB3c (['abcB3', 'abcB3l', 'abcB3c']), expr: abcB3\x00abcB3l\x00"..[[abcB3c (['abcB3', 'abcB3l', 'abcB3c']) + B: type v; value: abcB3]].."\000abcB3l\000abcB3c (['abcB3', 'abcB3l', 'abcB3c']), expr: abcB3\000abcB3l\000"..[[abcB3c (['abcB3', 'abcB3l', 'abcB3c']) == =abcB3 abcB3l abcB3c= {{{2 setreg('C', ['abcC3l'], 'l') - C: type V; value: abcC3]].."\x00abcC3b\x00abcC3l\x00 (['abcC3', 'abcC3b', 'abcC3l']), expr: abcC3\x00abcC3b\x00abcC3l\x00"..[[ (['abcC3', 'abcC3b', 'abcC3l']) + C: type V; value: abcC3]].."\000abcC3b\000abcC3l\000 (['abcC3', 'abcC3b', 'abcC3l']), expr: abcC3\000abcC3b\000abcC3l\000"..[[ (['abcC3', 'abcC3b', 'abcC3l']) == abcC3 abcC3b abcC3l == {{{2 setreg('D', ['abcD3b'], 'b') - D: type ]].."\x166; value: abcD3\x00abcD32\x00abcD3b (['abcD3', 'abcD32', 'abcD3b']), expr: abcD3\x00abcD32\x00"..[[abcD3b (['abcD3', 'abcD32', 'abcD3b']) + D: type ]].."\0226; value: abcD3\000abcD32\000abcD3b (['abcD3', 'abcD32', 'abcD3b']), expr: abcD3\000abcD32\000"..[[abcD3b (['abcD3', 'abcD32', 'abcD3b']) == =abcD3 = abcD32 @@ -370,50 +370,50 @@ describe('eval', function() expect( '\n'.. '{{{1 Appending lists with NL with setreg()\n'.. - "{{{2 setreg('A', ['\x00', 'abcA3l2'], 'l')\n".. - "A: type V; value: abcA3\x00abcA3c\x00abcA32\x00\x00\x00abcA3l2\x00 (['abcA3', 'abcA3c', 'abcA32', '\x00', 'abcA3l2']), expr: abcA3\x00abcA3c\x00abcA32\x00\x00\x00abcA3l2\x00 (['abcA3', 'abcA3c', 'abcA32', '\x00', 'abcA3l2'])\n".. + "{{{2 setreg('A', ['\000', 'abcA3l2'], 'l')\n".. + "A: type V; value: abcA3\000abcA3c\000abcA32\000\000\000abcA3l2\000 (['abcA3', 'abcA3c', 'abcA32', '\000', 'abcA3l2']), expr: abcA3\000abcA3c\000abcA32\000\000\000abcA3l2\000 (['abcA3', 'abcA3c', 'abcA32', '\000', 'abcA3l2'])\n".. '==\n'.. 'abcA3\n'.. 'abcA3c\n'.. 'abcA32\n'.. - '\x00\n'.. + '\000\n'.. 'abcA3l2\n'.. '==') execute('%delete') execute([=[call SetReg('B', ["\n", 'abcB3c2'], 'c')]=]) expect( '\n'.. - "{{{2 setreg('B', ['\x00', 'abcB3c2'], 'c')\n".. - "B: type v; value: abcB3\x00abcB3l\x00abcB3c\x00\x00\x00abcB3c2 (['abcB3', 'abcB3l', 'abcB3c', '\x00', 'abcB3c2']), expr: abcB3\x00abcB3l\x00abcB3c\x00\x00\x00abcB3c2 (['abcB3', 'abcB3l', 'abcB3c', '\x00', 'abcB3c2'])\n".. + "{{{2 setreg('B', ['\000', 'abcB3c2'], 'c')\n".. + "B: type v; value: abcB3\000abcB3l\000abcB3c\000\000\000abcB3c2 (['abcB3', 'abcB3l', 'abcB3c', '\000', 'abcB3c2']), expr: abcB3\000abcB3l\000abcB3c\000\000\000abcB3c2 (['abcB3', 'abcB3l', 'abcB3c', '\000', 'abcB3c2'])\n".. '==\n'.. '=abcB3\n'.. 'abcB3l\n'.. 'abcB3c\n'.. - '\x00\n'.. + '\000\n'.. 'abcB3c2=') execute('%delete') execute([=[call SetReg('C', ["\n", 'abcC3b2'], 'b')]=]) expect( '\n'.. - "{{{2 setreg('C', ['\x00', 'abcC3b2'], 'b')\n".. - "C: type \x167; value: abcC3\x00abcC3b\x00abcC3l\x00\x00\x00abcC3b2 (['abcC3', 'abcC3b', 'abcC3l', '\x00', 'abcC3b2']), expr: abcC3\x00abcC3b\x00abcC3l\x00\x00\x00abcC3b2 (['abcC3', 'abcC3b', 'abcC3l', '\x00', 'abcC3b2'])\n".. + "{{{2 setreg('C', ['\000', 'abcC3b2'], 'b')\n".. + "C: type \0227; value: abcC3\000abcC3b\000abcC3l\000\000\000abcC3b2 (['abcC3', 'abcC3b', 'abcC3l', '\000', 'abcC3b2']), expr: abcC3\000abcC3b\000abcC3l\000\000\000abcC3b2 (['abcC3', 'abcC3b', 'abcC3l', '\000', 'abcC3b2'])\n".. '==\n'.. '=abcC3 =\n'.. ' abcC3b\n'.. ' abcC3l\n'.. - ' \x00\n'.. + ' \000\n'.. ' abcC3b2') execute('%delete') execute([=[call SetReg('D', ["\n", 'abcD3b50'],'b50')]=]) expect( '\n'.. - "{{{2 setreg('D', ['\x00', 'abcD3b50'], 'b50')\n".. - "D: type \x1650; value: abcD3\x00abcD32\x00abcD3b\x00\x00\x00abcD3b50 (['abcD3', 'abcD32', 'abcD3b', '\x00', 'abcD3b50']), expr: abcD3\x00abcD32\x00abcD3b\x00\x00\x00abcD3b50 (['abcD3', 'abcD32', 'abcD3b', '\x00', 'abcD3b50'])\n".. + "{{{2 setreg('D', ['\000', 'abcD3b50'], 'b50')\n".. + "D: type \02250; value: abcD3\000abcD32\000abcD3b\000\000\000abcD3b50 (['abcD3', 'abcD32', 'abcD3b', '\000', 'abcD3b50']), expr: abcD3\000abcD32\000abcD3b\000\000\000abcD3b50 (['abcD3', 'abcD32', 'abcD3b', '\000', 'abcD3b50'])\n".. '==\n'.. '=abcD3 =\n'.. ' abcD32\n'.. ' abcD3b\n'.. - ' \x00\n'.. + ' \000\n'.. ' abcD3b50') end) @@ -425,14 +425,14 @@ describe('eval', function() execute([=[call SetReg('a', ['abcA4-0', "\n", "abcA4-2\n", "\nabcA4-3", "abcA4-4\nabcA4-4-2"])]=]) expect( '\n'.. - "{{{2 setreg('a', ['abcA4-0', '\x00', 'abcA4-2\x00', '\x00abcA4-3', 'abcA4-4\x00abcA4-4-2'])\n".. - "a: type V; value: abcA4-0\x00\x00\x00abcA4-2\x00\x00\x00abcA4-3\x00abcA4-4\x00abcA4-4-2\x00 (['abcA4-0', '\x00', 'abcA4-2\x00', '\x00abcA4-3', 'abcA4-4\x00abcA4-4-2']), expr: abcA4-0\x00\x00\x00abcA4-2\x00\x00\x00abcA4-3\x00abcA4-4\x00abcA4-4-2\x00 (['abcA4-0', '\x00', 'abcA4-2\x00', '\x00abcA4-3', 'abcA4-4\x00abcA4-4-2'])\n".. + "{{{2 setreg('a', ['abcA4-0', '\000', 'abcA4-2\000', '\000abcA4-3', 'abcA4-4\000abcA4-4-2'])\n".. + "a: type V; value: abcA4-0\000\000\000abcA4-2\000\000\000abcA4-3\000abcA4-4\000abcA4-4-2\000 (['abcA4-0', '\000', 'abcA4-2\000', '\000abcA4-3', 'abcA4-4\000abcA4-4-2']), expr: abcA4-0\000\000\000abcA4-2\000\000\000abcA4-3\000abcA4-4\000abcA4-4-2\000 (['abcA4-0', '\000', 'abcA4-2\000', '\000abcA4-3', 'abcA4-4\000abcA4-4-2'])\n".. '==\n'.. 'abcA4-0\n'.. - '\x00\n'.. - 'abcA4-2\x00\n'.. - '\x00abcA4-3\n'.. - 'abcA4-4\x00abcA4-4-2\n'.. + '\000\n'.. + 'abcA4-2\000\n'.. + '\000abcA4-3\n'.. + 'abcA4-4\000abcA4-4-2\n'.. '==') end) @@ -441,14 +441,14 @@ describe('eval', function() execute([=[call SetReg('b', ['abcB4c-0', "\n", "abcB4c-2\n", "\nabcB4c-3", "abcB4c-4\nabcB4c-4-2"], 'c')]=]) expect( '\n'.. - "{{{2 setreg('b', ['abcB4c-0', '\x00', 'abcB4c-2\x00', '\x00abcB4c-3', 'abcB4c-4\x00abcB4c-4-2'], 'c')\n".. - "b: type v; value: abcB4c-0\x00\x00\x00abcB4c-2\x00\x00\x00abcB4c-3\x00abcB4c-4\x00abcB4c-4-2 (['abcB4c-0', '\x00', 'abcB4c-2\x00', '\x00abcB4c-3', 'abcB4c-4\x00abcB4c-4-2']), expr: abcB4c-0\x00\x00\x00abcB4c-2\x00\x00\x00abcB4c-3\x00abcB4c-4\x00abcB4c-4-2 (['abcB4c-0', '\x00', 'abcB4c-2\x00', '\x00abcB4c-3', 'abcB4c-4\x00abcB4c-4-2'])\n".. + "{{{2 setreg('b', ['abcB4c-0', '\000', 'abcB4c-2\000', '\000abcB4c-3', 'abcB4c-4\000abcB4c-4-2'], 'c')\n".. + "b: type v; value: abcB4c-0\000\000\000abcB4c-2\000\000\000abcB4c-3\000abcB4c-4\000abcB4c-4-2 (['abcB4c-0', '\000', 'abcB4c-2\000', '\000abcB4c-3', 'abcB4c-4\000abcB4c-4-2']), expr: abcB4c-0\000\000\000abcB4c-2\000\000\000abcB4c-3\000abcB4c-4\000abcB4c-4-2 (['abcB4c-0', '\000', 'abcB4c-2\000', '\000abcB4c-3', 'abcB4c-4\000abcB4c-4-2'])\n".. '==\n'.. '=abcB4c-0\n'.. - '\x00\n'.. - 'abcB4c-2\x00\n'.. - '\x00abcB4c-3\n'.. - 'abcB4c-4\x00abcB4c-4-2=') + '\000\n'.. + 'abcB4c-2\000\n'.. + '\000abcB4c-3\n'.. + 'abcB4c-4\000abcB4c-4-2=') end) it('setting lists with NLs with setreg(), part 3', function() @@ -456,14 +456,14 @@ describe('eval', function() execute([=[call SetReg('c', ['abcC4l-0', "\n", "abcC4l-2\n", "\nabcC4l-3", "abcC4l-4\nabcC4l-4-2"], 'l')]=]) expect( '\n'.. - "{{{2 setreg('c', ['abcC4l-0', '\x00', 'abcC4l-2\x00', '\x00abcC4l-3', 'abcC4l-4\x00abcC4l-4-2'], 'l')\n".. - "c: type V; value: abcC4l-0\x00\x00\x00abcC4l-2\x00\x00\x00abcC4l-3\x00abcC4l-4\x00abcC4l-4-2\x00 (['abcC4l-0', '\x00', 'abcC4l-2\x00', '\x00abcC4l-3', 'abcC4l-4\x00abcC4l-4-2']), expr: abcC4l-0\x00\x00\x00abcC4l-2\x00\x00\x00abcC4l-3\x00abcC4l-4\x00abcC4l-4-2\x00 (['abcC4l-0', '\x00', 'abcC4l-2\x00', '\x00abcC4l-3', 'abcC4l-4\x00abcC4l-4-2'])\n".. + "{{{2 setreg('c', ['abcC4l-0', '\000', 'abcC4l-2\000', '\000abcC4l-3', 'abcC4l-4\000abcC4l-4-2'], 'l')\n".. + "c: type V; value: abcC4l-0\000\000\000abcC4l-2\000\000\000abcC4l-3\000abcC4l-4\000abcC4l-4-2\000 (['abcC4l-0', '\000', 'abcC4l-2\000', '\000abcC4l-3', 'abcC4l-4\000abcC4l-4-2']), expr: abcC4l-0\000\000\000abcC4l-2\000\000\000abcC4l-3\000abcC4l-4\000abcC4l-4-2\000 (['abcC4l-0', '\000', 'abcC4l-2\000', '\000abcC4l-3', 'abcC4l-4\000abcC4l-4-2'])\n".. '==\n'.. 'abcC4l-0\n'.. - '\x00\n'.. - 'abcC4l-2\x00\n'.. - '\x00abcC4l-3\n'.. - 'abcC4l-4\x00abcC4l-4-2\n'.. + '\000\n'.. + 'abcC4l-2\000\n'.. + '\000abcC4l-3\n'.. + 'abcC4l-4\000abcC4l-4-2\n'.. '==') end) it('setting lists with NLs with setreg(), part 4', function() @@ -471,28 +471,50 @@ describe('eval', function() execute([=[call SetReg('d', ['abcD4b-0', "\n", "abcD4b-2\n", "\nabcD4b-3", "abcD4b-4\nabcD4b-4-2"], 'b')]=]) expect( '\n'.. - "{{{2 setreg('d', ['abcD4b-0', '\x00', 'abcD4b-2\x00', '\x00abcD4b-3', 'abcD4b-4\x00abcD4b-4-2'], 'b')\n".. - "d: type \x1619; value: abcD4b-0\x00\x00\x00abcD4b-2\x00\x00\x00abcD4b-3\x00abcD4b-4\x00abcD4b-4-2 (['abcD4b-0', '\x00', 'abcD4b-2\x00', '\x00abcD4b-3', 'abcD4b-4\x00abcD4b-4-2']), expr: abcD4b-0\x00\x00\x00abcD4b-2\x00\x00\x00abcD4b-3\x00abcD4b-4\x00abcD4b-4-2 (['abcD4b-0', '\x00', 'abcD4b-2\x00', '\x00abcD4b-3', 'abcD4b-4\x00abcD4b-4-2'])\n".. + "{{{2 setreg('d', ['abcD4b-0', '\000', 'abcD4b-2\000', '\000abcD4b-3', 'abcD4b-4\000abcD4b-4-2'], 'b')\n".. + "d: type \02219; value: abcD4b-0\000\000\000abcD4b-2\000\000\000abcD4b-3\000abcD4b-4\000abcD4b-4-2 (['abcD4b-0', '\000', 'abcD4b-2\000', '\000abcD4b-3', 'abcD4b-4\000abcD4b-4-2']), expr: abcD4b-0\000\000\000abcD4b-2\000\000\000abcD4b-3\000abcD4b-4\000abcD4b-4-2 (['abcD4b-0', '\000', 'abcD4b-2\000', '\000abcD4b-3', 'abcD4b-4\000abcD4b-4-2'])\n".. '==\n'.. '=abcD4b-0 =\n'.. - ' \x00\n'.. - ' abcD4b-2\x00\n'.. - ' \x00abcD4b-3\n'.. - ' abcD4b-4\x00abcD4b-4-2') + ' \000\n'.. + ' abcD4b-2\000\n'.. + ' \000abcD4b-3\n'.. + ' abcD4b-4\000abcD4b-4-2') end) it('setting lists with NLs with setreg(), part 5', function() execute('so test_eval_setup.vim') execute([=[call SetReg('e', ['abcE4b10-0', "\n", "abcE4b10-2\n", "\nabcE4b10-3", "abcE4b10-4\nabcE4b10-4-2"], 'b10')]=]) expect( '\n'.. - "{{{2 setreg('e', ['abcE4b10-0', '\x00', 'abcE4b10-2\x00', '\x00abcE4b10-3', 'abcE4b10-4\x00abcE4b10-4-2'], 'b10')\n".. - "e: type \x1610; value: abcE4b10-0\x00\x00\x00abcE4b10-2\x00\x00\x00abcE4b10-3\x00abcE4b10-4\x00abcE4b10-4-2 (['abcE4b10-0', '\x00', 'abcE4b10-2\x00', '\x00abcE4b10-3', 'abcE4b10-4\x00abcE4b10-4-2']), expr: abcE4b10-0\x00\x00\x00abcE4b10-2\x00\x00\x00abcE4b10-3\x00abcE4b10-4\x00abcE4b10-4-2 (['abcE4b10-0', '\x00', 'abcE4b10-2\x00', '\x00abcE4b10-3', 'abcE4b10-4\x00abcE4b10-4-2'])\n".. + "{{{2 setreg('e', ['abcE4b10-0', '\000', 'abcE4b10-2\000', '\000abcE4b10-3', 'abcE4b10-4\000abcE4b10-4-2'], 'b10')\n".. + "e: type \02210; value: abcE4b10-0\000\000\000abcE4b10-2\000\000\000abcE4b10-3\000abcE4b10-4\000abcE4b10-4-2 (['abcE4b10-0', '\000', 'abcE4b10-2\000', '\000abcE4b10-3', 'abcE4b10-4\000abcE4b10-4-2']), expr: abcE4b10-0\000\000\000abcE4b10-2\000\000\000abcE4b10-3\000abcE4b10-4\000abcE4b10-4-2 (['abcE4b10-0', '\000', 'abcE4b10-2\000', '\000abcE4b10-3', 'abcE4b10-4\000abcE4b10-4-2'])\n".. '==\n'.. '=abcE4b10-0=\n'.. - ' \x00\n'.. - ' abcE4b10-2\x00\n'.. - ' \x00abcE4b10-3\n'.. - ' abcE4b10-4\x00abcE4b10-4-2') + ' \000\n'.. + ' abcE4b10-2\000\n'.. + ' \000abcE4b10-3\n'.. + ' abcE4b10-4\000abcE4b10-4-2') + end) + + it('getreg("a",1,1) returns a valid list when "a is unset', function() + -- Precondition: "a is actually unset and "0 is nonempty + eq('', eval("getregtype('a')")) + eq('', eval("getreg('a')")) + execute("call setreg('0','text')") + + -- This used to return a NULL list + -- which setreg didn't handle + execute("let x = getreg('a',1,1)") + execute("call setreg('0',x)") + + -- nvim didn't crash and "0 was emptied + eq(2, eval("1+1")) + eq({}, eval("getreg('0',1,1)")) + + -- x is a mutable list + execute("let y = x") + eq({}, eval("y")) + execute("call add(x, 'item')") + eq({'item'}, eval("y")) end) it('search and expressions', function() @@ -507,14 +529,14 @@ describe('eval', function() /: type v; value: abc/ (['abc/']), expr: abc/ (['abc/']) == =abc/= - {{{2 setreg('/', ['abc/]]..'\x00'..[[']) - /: type v; value: abc/]].."\x00 (['abc/\x00']), expr: abc/\x00 (['abc/\x00"..[[']) + {{{2 setreg('/', ['abc/]]..'\000'..[[']) + /: type v; value: abc/]].."\000 (['abc/\000']), expr: abc/\000 (['abc/\000"..[[']) == - =abc/]]..'\x00'..[[= + =abc/]]..'\000'..[[= {{{2 setreg('=', ['"abc/"']) =: type v; value: abc/ (['abc/']), expr: "abc/" (['"abc/"']) - {{{2 setreg('=', ['"abc/]]..'\x00'..[["']) - =: type v; value: abc/]].."\x00 (['abc/\x00"..[[']), expr: "abc/]]..'\x00'..[[" (['"abc/]]..'\x00'..[["'])]]) + {{{2 setreg('=', ['"abc/]]..'\000'..[["']) + =: type v; value: abc/]].."\000 (['abc/\000"..[[']), expr: "abc/]]..'\000'..[[" (['"abc/]]..'\000'..[["'])]]) end) if has_clipboard() then @@ -693,4 +715,22 @@ describe('eval', function() start: 6]]) end) + + it('substring and variable name', function() + execute("let str = 'abcdef'") + execute('let n = 3') + eq('def', eval('str[n:]')) + eq('abcd', eval('str[:n]')) + eq('d', eval('str[n:n]')) + execute('unlet n') + execute('let nn = 3') + eq('def', eval('str[nn:]')) + eq('abcd', eval('str[:nn]')) + eq('d', eval('str[nn:nn]')) + execute('unlet nn') + execute('let b:nn = 4') + eq('ef', eval('str[b:nn:]')) + eq('abcde', eval('str[:b:nn]')) + eq('e', eval('str[b:nn:b:nn]')) + end) end) diff --git a/test/functional/legacy/fnamemodify_spec.lua b/test/functional/legacy/fnamemodify_spec.lua new file mode 100644 index 0000000000..2a32aea127 --- /dev/null +++ b/test/functional/legacy/fnamemodify_spec.lua @@ -0,0 +1,75 @@ +-- Test filename modifiers. + +local helpers = require('test.functional.helpers') +local clear, source = helpers.clear, helpers.source +local call, eq, nvim = helpers.call, helpers.eq, helpers.meths + +local function expected_empty() + eq({}, nvim.get_vvar('errors')) +end + +describe('filename modifiers', function() + before_each(function() + clear() + + source([=[ + func Test_fnamemodify() + let tmpdir = resolve('/tmp') + execute 'cd '. tmpdir + set shell=sh + set shellslash + let $HOME=fnamemodify('.', ':p:h:h:h') + call assert_equal('/', fnamemodify('.', ':p')[-1:]) + call assert_equal('p', fnamemodify('.', ':p:h')[-1:]) + call assert_equal('t', fnamemodify('test.out', ':p')[-1:]) + call assert_equal('test.out', fnamemodify('test.out', ':.')) + call assert_equal('../testdir/a', fnamemodify('../testdir/a', ':.')) + call assert_equal('test.out', fnamemodify('test.out', ':~')) + call assert_equal('../testdir/a', fnamemodify('../testdir/a', ':~')) + call assert_equal('a', fnamemodify('../testdir/a', ':t')) + call assert_equal('', fnamemodify('.', ':p:t')) + call assert_equal('test.out', fnamemodify('test.out', ':p:t')) + call assert_equal('out', fnamemodify('test.out', ':p:e')) + call assert_equal('out', fnamemodify('test.out', ':p:t:e')) + call assert_equal('abc.fb2.tar', fnamemodify('abc.fb2.tar.gz', ':r')) + call assert_equal('abc.fb2', fnamemodify('abc.fb2.tar.gz', ':r:r')) + call assert_equal('abc', fnamemodify('abc.fb2.tar.gz', ':r:r:r')) + call assert_equal(tmpdir .'/abc.fb2', substitute(fnamemodify('abc.fb2.tar.gz', ':p:r:r'), '.*\(nvim/testdir/.*\)', '\1', '')) + call assert_equal('gz', fnamemodify('abc.fb2.tar.gz', ':e')) + call assert_equal('tar.gz', fnamemodify('abc.fb2.tar.gz', ':e:e')) + call assert_equal('fb2.tar.gz', fnamemodify('abc.fb2.tar.gz', ':e:e:e')) + call assert_equal('fb2.tar.gz', fnamemodify('abc.fb2.tar.gz', ':e:e:e:e')) + call assert_equal('tar', fnamemodify('abc.fb2.tar.gz', ':e:e:r')) + call assert_equal('''abc def''', fnamemodify('abc def', ':S')) + call assert_equal('''abc" "def''', fnamemodify('abc" "def', ':S')) + call assert_equal('''abc"%"def''', fnamemodify('abc"%"def', ':S')) + call assert_equal('''abc''\'''' ''\''''def''', fnamemodify('abc'' ''def', ':S')) + call assert_equal('''abc''\''''%''\''''def''', fnamemodify('abc''%''def', ':S')) + new foo.txt + call assert_equal(expand('%:r:S'), shellescape(expand('%:r'))) + call assert_equal('foo,''foo'',foo.txt', join([expand('%:r'), expand('%:r:S'), expand('%')], ',')) + quit + + call assert_equal("'abc\ndef'", fnamemodify("abc\ndef", ':S')) + set shell=tcsh + call assert_equal("'abc\\\ndef'", fnamemodify("abc\ndef", ':S')) + endfunc + + func Test_expand() + new + call assert_equal("", expand('%:S')) + quit + endfunc + ]=]) + end) + + it('is working', function() + call('Test_fnamemodify') + expected_empty() + end) + + it('works for :S in an unnamed buffer', function() + call('Test_expand') + expected_empty() + end) +end) diff --git a/test/functional/legacy/marks_spec.lua b/test/functional/legacy/marks_spec.lua new file mode 100644 index 0000000000..8e9ceb1653 --- /dev/null +++ b/test/functional/legacy/marks_spec.lua @@ -0,0 +1,53 @@ +local helpers = require('test.functional.helpers') +local feed, insert, source = helpers.feed, helpers.insert, helpers.source +local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect + +describe('marks', function() + before_each(function() + clear() + end) + + it('restores a deleted mark after delete-undo-redo-undo', function() + insert([[ + + textline A + textline B + textline C + + Results:]]) + + execute([[:/^\t/+1]]) + feed([[maddu<C-R>u]]) + source([[ + let g:a = string(getpos("'a")) + $put ='Mark after delete-undo-redo-undo: '.g:a + ]]) + + expect([=[ + + textline A + textline B + textline C + + Results: + Mark after delete-undo-redo-undo: [0, 3, 2, 0]]=]) + end) + + it("CTRL-A and CTRL-X updates last changed mark '[, ']", function() + insert([[ + CTRL-A CTRL-X: + 123 123 123 + 123 123 123 + 123 123 123]]) + + source([[ + /^123/ + execute "normal! \<C-A>`[v`]rAjwvjw\<C-X>`[v`]rX"]]) + + expect([=[ + CTRL-A CTRL-X: + AAA 123 123 + 123 XXXXXXX + XXX 123 123]=]) + end) +end) diff --git a/test/functional/legacy/tagcase_spec.lua b/test/functional/legacy/tagcase_spec.lua new file mode 100644 index 0000000000..9a8c6fbe42 --- /dev/null +++ b/test/functional/legacy/tagcase_spec.lua @@ -0,0 +1,150 @@ +local helpers = require('test.functional.helpers') +local clear = helpers.clear +local eq = helpers.eq +local eval = helpers.eval +local exc_exec = helpers.exc_exec +local expect = helpers.expect +local insert = helpers.insert +local source = helpers.source +local write_file = helpers.write_file + +describe("'tagcase' option", function() + setup(function() + write_file('Xtags', [[ + Bar Xtext 3 + Foo Xtext 2 + foo Xtext 4]]) + end) + + before_each(function() + clear() + source([[ + lang mess C + set tags=Xtags]]) + end) + + teardown(function() + os.remove('Xtags') + end) + + it('should have correct default values', function() + source([[ + set ic& + setg tc& + setl tc& + ]]) + + eq(0, eval('&ic')) + eq('followic', eval('&g:tc')) + eq('followic', eval('&l:tc')) + eq('followic', eval('&tc')) + end) + + it('should accept <empty> only for setlocal', function() + -- Verify that the local setting accepts <empty> but that the global setting + -- does not. The first of these (setting the local value to <empty>) should + -- succeed; the other two should fail. + eq(0, exc_exec('setl tc=')) + eq('Vim(setglobal):E474: Invalid argument: tc=', exc_exec('setg tc=')) + eq('Vim(set):E474: Invalid argument: tc=', exc_exec('set tc=')) + end) + + it("should work with 'ignorecase' correctly in all combinations", function() + -- Verify that the correct number of matching tags is found for all values of + -- 'ignorecase' and global and local values 'tagcase', in all combinations. + insert([[ + + Foo + Bar + foo + + end text]]) + + source([[ + for &ic in [0, 1] + for &g:tc in ["followic", "ignore", "match"] + for &l:tc in ["", "followic", "ignore", "match"] + call append('$', "ic=".&ic." g:tc=".&g:tc." l:tc=".&l:tc." tc=".&tc) + call append('$', len(taglist("^foo$"))) + call append('$', len(taglist("^Foo$"))) + endfor + endfor + endfor + + 1,/^end text$/d]]) + + expect([[ + ic=0 g:tc=followic l:tc= tc=followic + 1 + 1 + ic=0 g:tc=followic l:tc=followic tc=followic + 1 + 1 + ic=0 g:tc=followic l:tc=ignore tc=ignore + 2 + 2 + ic=0 g:tc=followic l:tc=match tc=match + 1 + 1 + ic=0 g:tc=ignore l:tc= tc=ignore + 2 + 2 + ic=0 g:tc=ignore l:tc=followic tc=followic + 1 + 1 + ic=0 g:tc=ignore l:tc=ignore tc=ignore + 2 + 2 + ic=0 g:tc=ignore l:tc=match tc=match + 1 + 1 + ic=0 g:tc=match l:tc= tc=match + 1 + 1 + ic=0 g:tc=match l:tc=followic tc=followic + 1 + 1 + ic=0 g:tc=match l:tc=ignore tc=ignore + 2 + 2 + ic=0 g:tc=match l:tc=match tc=match + 1 + 1 + ic=1 g:tc=followic l:tc= tc=followic + 2 + 2 + ic=1 g:tc=followic l:tc=followic tc=followic + 2 + 2 + ic=1 g:tc=followic l:tc=ignore tc=ignore + 2 + 2 + ic=1 g:tc=followic l:tc=match tc=match + 1 + 1 + ic=1 g:tc=ignore l:tc= tc=ignore + 2 + 2 + ic=1 g:tc=ignore l:tc=followic tc=followic + 2 + 2 + ic=1 g:tc=ignore l:tc=ignore tc=ignore + 2 + 2 + ic=1 g:tc=ignore l:tc=match tc=match + 1 + 1 + ic=1 g:tc=match l:tc= tc=match + 1 + 1 + ic=1 g:tc=match l:tc=followic tc=followic + 2 + 2 + ic=1 g:tc=match l:tc=ignore tc=ignore + 2 + 2 + ic=1 g:tc=match l:tc=match tc=match + 1 + 1]]) + end) +end) diff --git a/test/functional/options/defaults_spec.lua b/test/functional/options/defaults_spec.lua new file mode 100644 index 0000000000..7f0892ee3a --- /dev/null +++ b/test/functional/options/defaults_spec.lua @@ -0,0 +1,85 @@ +local helpers = require('test.functional.helpers') +local Screen = require('test.functional.ui.screen') +local clear, feed = helpers.clear, helpers.feed +local eval, eq, neq = helpers.eval, helpers.eq, helpers.neq +local execute, source, expect = helpers.execute, helpers.source, helpers.expect + +local function init_session(...) + local args = { helpers.nvim_prog, '-i', 'NONE', '--embed', + '--cmd', 'set shortmess+=I background=light noswapfile noautoindent', + '--cmd', 'set laststatus=1 undodir=. directory=. viewdir=. backupdir=.' + } + for _, v in ipairs({...}) do + table.insert(args, v) + end + helpers.set_session(helpers.spawn(args)) +end + +describe('startup defaults', function() + before_each(function() + clear() + end) + + describe(':filetype', function() + local function expect_filetype(expected) + local screen = Screen.new(48, 4) + screen:attach() + execute('filetype') + screen:expect([[ + ^ | + ~ | + ~ | + ]]..expected + ) + end + + it('enabled by `-u NORC`', function() + init_session('-u', 'NORC') + expect_filetype( + 'filetype detection:ON plugin:ON indent:ON |') + end) + + it('disabled by `-u NONE`', function() + init_session('-u', 'NONE') + expect_filetype( + 'filetype detection:OFF plugin:OFF indent:OFF |') + end) + + it('overridden by early `filetype on`', function() + init_session('-u', 'NORC', '--cmd', 'filetype on') + expect_filetype( + 'filetype detection:ON plugin:OFF indent:OFF |') + end) + + it('overridden by early `filetype plugin on`', function() + init_session('-u', 'NORC', '--cmd', 'filetype plugin on') + expect_filetype( + 'filetype detection:ON plugin:ON indent:OFF |') + end) + + it('overridden by early `filetype indent on`', function() + init_session('-u', 'NORC', '--cmd', 'filetype indent on') + expect_filetype( + 'filetype detection:ON plugin:OFF indent:ON |') + end) + end) + + describe('syntax', function() + it('enabled by `-u NORC`', function() + init_session('-u', 'NORC') + eq(1, eval('g:syntax_on')) + end) + + it('disabled by `-u NONE`', function() + init_session('-u', 'NONE') + eq(0, eval('exists("g:syntax_on")')) + end) + + it('overridden by early `syntax off`', function() + init_session('-u', 'NORC', '--cmd', 'syntax off') + eq(0, eval('exists("g:syntax_on")')) + end) + end) +end) + + diff --git a/test/functional/options/shortmess_spec.lua b/test/functional/options/shortmess_spec.lua new file mode 100644 index 0000000000..04a64d2943 --- /dev/null +++ b/test/functional/options/shortmess_spec.lua @@ -0,0 +1,39 @@ +local helpers = require('test.functional.helpers') +local Screen = require('test.functional.ui.screen') +local clear, feed, execute = helpers.clear, helpers.feed, helpers.execute + +describe("'shortmess'", function() + local screen + + before_each(function() + clear() + screen = Screen.new(25, 5) + screen:attach() + end) + + after_each(function() + screen:detach() + end) + + describe('"F" flag', function() + it('hides messages about the files read', function() + execute('e test') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + "test" is a directory | + ]]) + execute('set shortmess=F') + execute('e test') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + :e test | + ]]) + end) + end) +end) diff --git a/test/functional/plugin/helpers.lua b/test/functional/plugin/helpers.lua index cc76794267..5b6ea88c34 100644 --- a/test/functional/plugin/helpers.lua +++ b/test/functional/plugin/helpers.lua @@ -25,7 +25,7 @@ local session = nil local reset = function(...) if session then - session:exit(0) + session:close() end session = spawn(nvim_argv(...)) set_session(session) diff --git a/test/functional/plugin/msgpack_spec.lua b/test/functional/plugin/msgpack_spec.lua index 18ff0f5156..246b26188f 100644 --- a/test/functional/plugin/msgpack_spec.lua +++ b/test/functional/plugin/msgpack_spec.lua @@ -1,6 +1,8 @@ local helpers = require('test.functional.helpers') +local meths = helpers.meths local eq, nvim_eval, nvim_command, exc_exec = helpers.eq, helpers.eval, helpers.command, helpers.exc_exec +local ok = helpers.ok local plugin_helpers = require('test.functional.plugin.helpers') local reset = plugin_helpers.reset @@ -21,10 +23,8 @@ describe('In autoload/msgpack.vim', function() end local nan = -(1.0/0.0-1.0/0.0) - local minus_nan = 1.0/0.0-1.0/0.0 local inf = 1.0/0.0 local minus_inf = -(1.0/0.0) - local has_minus_nan = tostring(nan) ~= tostring(minus_nan) describe('function msgpack#equal', function() local msgpack_eq = function(expected, a, b) @@ -160,9 +160,9 @@ describe('In autoload/msgpack.vim', function() it('compares raw floats correctly', function() msgpack_eq(1, '0.0', '0.0') msgpack_eq(1, '(1.0/0.0-1.0/0.0)', '(1.0/0.0-1.0/0.0)') - if has_minus_nan then - msgpack_eq(0, '(1.0/0.0-1.0/0.0)', '-(1.0/0.0-1.0/0.0)') - end + -- both (1.0/0.0-1.0/0.0) and -(1.0/0.0-1.0/0.0) now return + -- str2float('nan'). ref: @18d1ba3422d + msgpack_eq(1, '(1.0/0.0-1.0/0.0)', '-(1.0/0.0-1.0/0.0)') msgpack_eq(1, '-(1.0/0.0-1.0/0.0)', '-(1.0/0.0-1.0/0.0)') msgpack_eq(1, '1.0/0.0', '1.0/0.0') msgpack_eq(1, '-(1.0/0.0)', '-(1.0/0.0)') @@ -178,10 +178,8 @@ describe('In autoload/msgpack.vim', function() it('compares float specials with raw floats correctly', function() msgpack_eq(1, sp('float', '0.0'), '0.0') msgpack_eq(1, sp('float', '(1.0/0.0-1.0/0.0)'), '(1.0/0.0-1.0/0.0)') - if has_minus_nan then - msgpack_eq(0, sp('float', '(1.0/0.0-1.0/0.0)'), '-(1.0/0.0-1.0/0.0)') - msgpack_eq(0, sp('float', '-(1.0/0.0-1.0/0.0)'), '(1.0/0.0-1.0/0.0)') - end + msgpack_eq(1, sp('float', '(1.0/0.0-1.0/0.0)'), '-(1.0/0.0-1.0/0.0)') + msgpack_eq(1, sp('float', '-(1.0/0.0-1.0/0.0)'), '(1.0/0.0-1.0/0.0)') msgpack_eq(1, sp('float', '-(1.0/0.0-1.0/0.0)'), '-(1.0/0.0-1.0/0.0)') msgpack_eq(1, sp('float', '1.0/0.0'), '1.0/0.0') msgpack_eq(1, sp('float', '-(1.0/0.0)'), '-(1.0/0.0)') @@ -207,10 +205,8 @@ describe('In autoload/msgpack.vim', function() msgpack_eq(0, sp('float', '0.0'), sp('float', '-(1.0/0.0)')) msgpack_eq(0, sp('float', '1.0/0.0'), sp('float', '-(1.0/0.0)')) msgpack_eq(0, sp('float', '(1.0/0.0-1.0/0.0)'), sp('float', '-(1.0/0.0)')) - if has_minus_nan then - msgpack_eq(0, sp('float', '(1.0/0.0-1.0/0.0)'), - sp('float', '-(1.0/0.0-1.0/0.0)')) - end + msgpack_eq(1, sp('float', '(1.0/0.0-1.0/0.0)'), + sp('float', '-(1.0/0.0-1.0/0.0)')) msgpack_eq(1, sp('float', '-(1.0/0.0-1.0/0.0)'), sp('float', '-(1.0/0.0-1.0/0.0)')) msgpack_eq(0, sp('float', '(1.0/0.0-1.0/0.0)'), sp('float', '1.0/0.0')) @@ -392,9 +388,7 @@ describe('In autoload/msgpack.vim', function() string_eq('0.0', sp('float', '0.0')) string_eq('inf', sp('float', '(1.0/0.0)')) string_eq('-inf', sp('float', '-(1.0/0.0)')) - if has_minus_nan then - string_eq('-nan', sp('float', '(1.0/0.0-1.0/0.0)')) - end + string_eq('nan', sp('float', '(1.0/0.0-1.0/0.0)')) string_eq('nan', sp('float', '-(1.0/0.0-1.0/0.0)')) string_eq('FALSE', sp('boolean', '0')) string_eq('TRUE', sp('boolean', '1')) @@ -413,11 +407,15 @@ describe('In autoload/msgpack.vim', function() string_eq('0.0', '0.0') string_eq('inf', '(1.0/0.0)') string_eq('-inf', '-(1.0/0.0)') - if has_minus_nan then - string_eq('-nan', '(1.0/0.0-1.0/0.0)') - end + string_eq('nan', '(1.0/0.0-1.0/0.0)') string_eq('nan', '-(1.0/0.0-1.0/0.0)') end) + + it('works for special v: values like v:true', function() + string_eq('TRUE', 'v:true') + string_eq('FALSE', 'v:false') + string_eq('NIL', 'v:null') + end) end) describe('function msgpack#deepcopy', function() @@ -532,6 +530,20 @@ describe('In autoload/msgpack.vim', function() eq(2.0, nvim_eval('flt2')) eq('abc', nvim_eval('bin2')) end) + + it('works for special v: values like v:true', function() + meths.set_var('true', true) + meths.set_var('false', false) + meths.set_var('nil', NIL) + + nvim_command('let true2 = msgpack#deepcopy(true)') + nvim_command('let false2 = msgpack#deepcopy(false)') + nvim_command('let nil2 = msgpack#deepcopy(nil)') + + eq(true, meths.get_var('true')) + eq(false, meths.get_var('false')) + eq(NIL, meths.get_var('nil')) + end) end) describe('function msgpack#eval', function() @@ -547,8 +559,11 @@ describe('In autoload/msgpack.vim', function() end if expected_val_full == expected_val_full then eq(expected_val_full, nvim_eval('g:__val')) - else - eq(tostring(expected_val_full), tostring(nvim_eval('g:__val'))) + else -- NaN + local nvim_nan = tostring(nvim_eval('g:__val')) + -- -NaN is a hardware-specific detail, there's no need to test for it. + -- Accept ether 'nan' or '-nan' as the response. + ok(nvim_nan == 'nan' or nvim_nan == '-nan') end nvim_command('unlet g:__val') end @@ -615,7 +630,6 @@ describe('In autoload/msgpack.vim', function() eval_eq('float', inf, 'inf') eval_eq('float', minus_inf, '-inf') eval_eq('float', nan, 'nan') - eval_eq('float', minus_nan, '-nan') eval_eq('float', 1.0e10, '1.0e10') eval_eq('float', 1.0e10, '1.0e+10') eval_eq('float', -1.0e10, '-1.0e+10') diff --git a/test/functional/plugin/shada_spec.lua b/test/functional/plugin/shada_spec.lua index 4100a30452..aad0e366bf 100644 --- a/test/functional/plugin/shada_spec.lua +++ b/test/functional/plugin/shada_spec.lua @@ -4,7 +4,7 @@ local eq, nvim_eval, nvim_command, nvim, exc_exec, funcs, nvim_feed, curbuf = helpers.funcs, helpers.feed, helpers.curbuf local neq = helpers.neq -local msgpack = require('MessagePack') +local mpack = require('mpack') local plugin_helpers = require('test.functional.plugin.helpers') local reset = plugin_helpers.reset @@ -15,13 +15,13 @@ local get_shada_rw = shada_helpers.get_shada_rw local mpack_eq = function(expected, mpack_result) local mpack_keys = {'type', 'timestamp', 'length', 'value'} - local unpacker = msgpack.unpacker(mpack_result) + local unpack = mpack.Unpacker() local actual = {} - local cur + local cur, val local i = 0 - while true do - local off, val = unpacker() - if not off then break end + local off = 1 + while off <= #mpack_result do + val, off = unpack(mpack_result, off) if i % 4 == 0 then cur = {} actual[#actual + 1] = cur @@ -78,36 +78,6 @@ describe('In autoload/shada.vim', function() return ('{"_TYPE": v:msgpack_types.%s, "_VAL": %s}'):format(typ, val) end - local st_meta = { - __pairs=function(table) - local ret = {} - local next_key = nil - local num_keys = 0 - while true do - next_key = next(table, next_key) - if next_key == nil then - break - end - num_keys = num_keys + 1 - ret[num_keys] = {next_key, table[next_key]} - end - table.sort(ret, function(a, b) - return a[1] < b[1] - end) - local state = {i=0} - return (function(state_, _) - state_.i = state_.i + 1 - if ret[state_.i] then - return table.unpack(ret[state_.i]) - end - end), state - end - } - - local st = function(table) - return setmetatable(table, st_meta) - end - describe('function shada#mpack_to_sd', function() local mpack2sd = function(arg) return ('shada#mpack_to_sd(%s)'):format(arg) @@ -184,7 +154,7 @@ describe('In autoload/shada.vim', function() ' + b 2', ' + c column 3', ' + d 4', - }, {{type=1, timestamp=0, data=st({a=1, b=2, c=3, d=4})}}) + }, {{type=1, timestamp=0, data={a=1, b=2, c=3, d=4}}}) sd2strings_eq({ 'Header with timestamp ' .. epoch .. ':', ' % Key Value', @@ -2215,7 +2185,7 @@ describe('In plugin/shada.vim', function() describe('event BufWriteCmd', function() it('works', function() nvim('set_var', 'shada#add_own_header', 0) - curbuf('set_line_slice', 0, 0, true, true, { + curbuf('set_lines', 0, 1, true, { 'Jump with timestamp ' .. epoch .. ':', ' % Key________ Description Value', ' + n name \'A\'', @@ -2271,7 +2241,7 @@ describe('In plugin/shada.vim', function() describe('event FileWriteCmd', function() it('works', function() nvim('set_var', 'shada#add_own_header', 0) - curbuf('set_line_slice', 0, 0, true, true, { + curbuf('set_lines', 0, 1, true, { 'Jump with timestamp ' .. epoch .. ':', ' % Key________ Description Value', ' + n name \'A\'', @@ -2310,7 +2280,7 @@ describe('In plugin/shada.vim', function() describe('event FileAppendCmd', function() it('works', function() nvim('set_var', 'shada#add_own_header', 0) - curbuf('set_line_slice', 0, 0, true, true, { + curbuf('set_lines', 0, 1, true, { 'Jump with timestamp ' .. epoch .. ':', ' % Key________ Description Value', ' + n name \'A\'', @@ -2512,7 +2482,7 @@ describe('syntax/shada.vim', function() it('works', function() nvim_command('syntax on') nvim_command('setlocal syntax=shada') - curbuf('set_line_slice', 0, 0, true, true, { + curbuf('set_lines', 0, 1, true, { 'Header with timestamp ' .. epoch .. ':', ' % Key Value', ' + t "test"', @@ -2848,3 +2818,4 @@ describe('syntax/shada.vim', function() eq(exp, act) end) end) + diff --git a/test/functional/preload.lua b/test/functional/preload.lua index 5f34f7fa6e..1971ef77cc 100644 --- a/test/functional/preload.lua +++ b/test/functional/preload.lua @@ -1,5 +1,4 @@ -- Modules loaded here will not be cleared and reloaded by Busted. -- Busted started doing this to help provide more isolation. See issue #62 -- for more information about this. -local ffi = require('ffi') local helpers = require('test.functional.helpers') diff --git a/test/functional/provider/define_spec.lua b/test/functional/provider/define_spec.lua index 6e8a3b89cd..c30ad6d8c2 100644 --- a/test/functional/provider/define_spec.lua +++ b/test/functional/provider/define_spec.lua @@ -64,153 +64,137 @@ local function command_specs_for(fn, sync, first_arg_factory, init) args = args..', "RpcCommand"' end) - describe('without options', function() - it('ok', function() - call(fn, args..', {}') - local function on_setup() - command('RpcCommand') - end + it('without options', function() + call(fn, args..', {}') + local function on_setup() + command('RpcCommand') + end - local function handler(method) - eq('test-handler', method) - return '' - end + local function handler(method) + eq('test-handler', method) + return '' + end - runx(sync, handler, on_setup) - end) + runx(sync, handler, on_setup) end) - describe('with nargs', function() - it('ok', function() - call(fn, args..', {"nargs": "*"}') - local function on_setup() - command('RpcCommand arg1 arg2 arg3') - end + it('with nargs', function() + call(fn, args..', {"nargs": "*"}') + local function on_setup() + command('RpcCommand arg1 arg2 arg3') + end - local function handler(method, arguments) - eq('test-handler', method) - eq({'arg1', 'arg2', 'arg3'}, arguments[1]) - return '' - end + local function handler(method, arguments) + eq('test-handler', method) + eq({'arg1', 'arg2', 'arg3'}, arguments[1]) + return '' + end - runx(sync, handler, on_setup) - end) + runx(sync, handler, on_setup) end) - describe('with range', function() - it('ok', function() - call(fn,args..', {"range": ""}') - local function on_setup() - command('1,1RpcCommand') - end + it('with range', function() + call(fn,args..', {"range": ""}') + local function on_setup() + command('1,1RpcCommand') + end - local function handler(method, arguments) - eq('test-handler', method) - eq({1, 1}, arguments[1]) - return '' - end + local function handler(method, arguments) + eq('test-handler', method) + eq({1, 1}, arguments[1]) + return '' + end - runx(sync, handler, on_setup) - end) + runx(sync, handler, on_setup) end) - describe('with nargs/range', function() - it('ok', function() - call(fn, args..', {"nargs": "1", "range": ""}') - local function on_setup() - command('1,1RpcCommand arg') - end + it('with nargs/range', function() + call(fn, args..', {"nargs": "1", "range": ""}') + local function on_setup() + command('1,1RpcCommand arg') + end - local function handler(method, arguments) - eq('test-handler', method) - eq({'arg'}, arguments[1]) - eq({1, 1}, arguments[2]) - return '' - end + local function handler(method, arguments) + eq('test-handler', method) + eq({'arg'}, arguments[1]) + eq({1, 1}, arguments[2]) + return '' + end - runx(sync, handler, on_setup) - end) + runx(sync, handler, on_setup) end) - describe('with nargs/count', function() - it('ok', function() - call(fn, args..', {"nargs": "1", "range": "5"}') - local function on_setup() - command('5RpcCommand arg') - end + it('with nargs/count', function() + call(fn, args..', {"nargs": "1", "range": "5"}') + local function on_setup() + command('5RpcCommand arg') + end - local function handler(method, arguments) - eq('test-handler', method) - eq({'arg'}, arguments[1]) - eq(5, arguments[2]) - return '' - end + local function handler(method, arguments) + eq('test-handler', method) + eq({'arg'}, arguments[1]) + eq(5, arguments[2]) + return '' + end - runx(sync, handler, on_setup) - end) + runx(sync, handler, on_setup) end) - describe('with nargs/count/bang', function() - it('ok', function() - call(fn, args..', {"nargs": "1", "range": "5", "bang": ""}') - local function on_setup() - command('5RpcCommand! arg') - end + it('with nargs/count/bang', function() + call(fn, args..', {"nargs": "1", "range": "5", "bang": ""}') + local function on_setup() + command('5RpcCommand! arg') + end - local function handler(method, arguments) - eq('test-handler', method) - eq({'arg'}, arguments[1]) - eq(5, arguments[2]) - eq(1, arguments[3]) - return '' - end + local function handler(method, arguments) + eq('test-handler', method) + eq({'arg'}, arguments[1]) + eq(5, arguments[2]) + eq(1, arguments[3]) + return '' + end - runx(sync, handler, on_setup) - end) + runx(sync, handler, on_setup) end) - describe('with nargs/count/bang/register', function() - it('ok', function() - call(fn, args..', {"nargs": "1", "range": "5", "bang": "",'.. - ' "register": ""}') - local function on_setup() - command('5RpcCommand! b arg') - end + it('with nargs/count/bang/register', function() + call(fn, args..', {"nargs": "1", "range": "5", "bang": "",'.. + ' "register": ""}') + local function on_setup() + command('5RpcCommand! b arg') + end - local function handler(method, arguments) - eq('test-handler', method) - eq({'arg'}, arguments[1]) - eq(5, arguments[2]) - eq(1, arguments[3]) - eq('b', arguments[4]) - return '' - end + local function handler(method, arguments) + eq('test-handler', method) + eq({'arg'}, arguments[1]) + eq(5, arguments[2]) + eq(1, arguments[3]) + eq('b', arguments[4]) + return '' + end - runx(sync, handler, on_setup) - end) + runx(sync, handler, on_setup) end) - describe('with nargs/count/bang/register/eval', function() - it('ok', function() - call(fn, args..', {"nargs": "1", "range": "5", "bang": "",'.. - ' "register": "", "eval": "@<reg>"}') - local function on_setup() - command('let @b = "regb"') - command('5RpcCommand! b arg') - end + it('with nargs/count/bang/register/eval', function() + call(fn, args..', {"nargs": "1", "range": "5", "bang": "",'.. + ' "register": "", "eval": "@<reg>"}') + local function on_setup() + command('let @b = "regb"') + command('5RpcCommand! b arg') + end - local function handler(method, arguments) - eq('test-handler', method) - eq({'arg'}, arguments[1]) - eq(5, arguments[2]) - eq(1, arguments[3]) - eq('b', arguments[4]) - eq('regb', arguments[5]) - return '' - end + local function handler(method, arguments) + eq('test-handler', method) + eq({'arg'}, arguments[1]) + eq(5, arguments[2]) + eq(1, arguments[3]) + eq('b', arguments[4]) + eq('regb', arguments[5]) + return '' + end - runx(sync, handler, on_setup) - end) + runx(sync, handler, on_setup) end) end) end) @@ -236,37 +220,33 @@ local function autocmd_specs_for(fn, sync, first_arg_factory, init) args = args..', "BufEnter"' end) - describe('without options', function() - it('ok', function() - call(fn, args..', {}') - local function on_setup() - command('doautocmd BufEnter x.c') - end + it('without options', function() + call(fn, args..', {}') + local function on_setup() + command('doautocmd BufEnter x.c') + end - local function handler(method) - eq('test-handler', method) - return '' - end + local function handler(method) + eq('test-handler', method) + return '' + end - runx(sync, handler, on_setup) - end) + runx(sync, handler, on_setup) end) - describe('with eval', function() - it('ok', function() - call(fn, args..[[, {'eval': 'expand("<afile>")'}]]) - local function on_setup() - command('doautocmd BufEnter x.c') - end + it('with eval', function() + call(fn, args..[[, {'eval': 'expand("<afile>")'}]]) + local function on_setup() + command('doautocmd BufEnter x.c') + end - local function handler(method, arguments) - eq('test-handler', method) - eq('x.c', arguments[1]) - return '' - end + local function handler(method, arguments) + eq('test-handler', method) + eq('x.c', arguments[1]) + return '' + end - runx(sync, handler, on_setup) - end) + runx(sync, handler, on_setup) end) end) end) @@ -292,46 +272,77 @@ local function function_specs_for(fn, sync, first_arg_factory, init) args = args..', "TestFunction"' end) - describe('without options', function() - it('ok', function() - call(fn, args..', {}') - local function on_setup() - if sync then - eq('rv', eval('TestFunction(1, "a", ["b", "c"])')) - else - eq(1, eval('TestFunction(1, "a", ["b", "c"])')) - end + it('without options', function() + call(fn, args..', {}') + local function on_setup() + if sync then + eq('rv', eval('TestFunction(1, "a", ["b", "c"])')) + else + eq(1, eval('TestFunction(1, "a", ["b", "c"])')) end + end - local function handler(method, arguments) - eq('test-handler', method) - eq({{1, 'a', {'b', 'c'}}}, arguments) - return 'rv' - end + local function handler(method, arguments) + eq('test-handler', method) + eq({{1, 'a', {'b', 'c'}}}, arguments) + return 'rv' + end - runx(sync, handler, on_setup) - end) + runx(sync, handler, on_setup) end) - describe('with eval', function() - it('ok', function() - call(fn, args..[[, {'eval': '2 + 2'}]]) - local function on_setup() - if sync then - eq('rv', eval('TestFunction(1, "a", ["b", "c"])')) - else - eq(1, eval('TestFunction(1, "a", ["b", "c"])')) - end + it('with eval', function() + call(fn, args..[[, {'eval': '2 + 2'}]]) + local function on_setup() + if sync then + eq('rv', eval('TestFunction(1, "a", ["b", "c"])')) + else + eq(1, eval('TestFunction(1, "a", ["b", "c"])')) end + end - local function handler(method, arguments) - eq('test-handler', method) - eq({{1, 'a', {'b', 'c'}}, 4}, arguments) - return 'rv' - end + local function handler(method, arguments) + eq('test-handler', method) + eq({{1, 'a', {'b', 'c'}}, 4}, arguments) + return 'rv' + end + + runx(sync, handler, on_setup) + end) + + it('with range', function() + helpers.insert([[ + foo + bar + baz + zub]]) + call(fn, args..[[, {'range': ''}]]) + local function on_setup() + command('2,3call TestFunction(1, "a", ["b", "c"])') + end + + local function handler(method, arguments) + eq('test-handler', method) + eq({{1, 'a', {'b', 'c'}}, {2, 3}}, arguments) + return 'rv' + end + + runx(sync, handler, on_setup) + end) + + it('with eval/range', function() + call(fn, args..[[, {'eval': '4', 'range': ''}]]) + local function on_setup() + command('%call TestFunction(1, "a", ["b", "c"])') + end + + local function handler(method, arguments) + eq('test-handler', method) + eq({{1, 'a', {'b', 'c'}}, {1, 1}, 4}, arguments) + return 'rv' + end - runx(sync, handler, on_setup) - end) + runx(sync, handler, on_setup) end) end) end) diff --git a/test/functional/shada/compatibility_spec.lua b/test/functional/shada/compatibility_spec.lua index 2ca0b16e75..1fa88c58e5 100644 --- a/test/functional/shada/compatibility_spec.lua +++ b/test/functional/shada/compatibility_spec.lua @@ -270,9 +270,7 @@ describe('ShaDa forward compatibility support code', function() it('works with register item with type 10', function() wshada('\005\001\019\132\161na\162rX\194\162rc\145\196\001-\162rt\010') eq(0, exc_exec(sdrcmd(true))) - -- getreg may return empty list as list with NULL pointer which API - -- translates into nil for some reason. - eq({}, funcs.getreg('a', 1, 1) or {}) + eq({}, funcs.getreg('a', 1, 1)) eq('', funcs.getregtype('a')) nvim_command('wshada ' .. shada_fname) local found = 0 diff --git a/test/functional/shada/helpers.lua b/test/functional/shada/helpers.lua index 146ae8d51e..d4eb7f57bd 100644 --- a/test/functional/shada/helpers.lua +++ b/test/functional/shada/helpers.lua @@ -3,7 +3,7 @@ local spawn, set_session, meths, nvim_prog = helpers.spawn, helpers.set_session, helpers.meths, helpers.nvim_prog local write_file, merge_args = helpers.write_file, helpers.merge_args -local msgpack = require('MessagePack') +local mpack = require('mpack') local tmpname = os.tmpname() local additional_cmd = '' @@ -20,14 +20,8 @@ local function nvim_argv() end end -local session = nil - local reset = function() - if session then - session:exit(0) - end - session = spawn(nvim_argv()) - set_session(session) + set_session(spawn(nvim_argv())) meths.set_var('tmpname', tmpname) end @@ -66,13 +60,13 @@ local read_shada_file = function(fname) local fd = io.open(fname, 'r') local mstring = fd:read('*a') fd:close() - local unpacker = msgpack.unpacker(mstring) + local unpack = mpack.Unpacker() local ret = {} - local cur + local cur, val local i = 0 - while true do - local off, val = unpacker() - if not off then break end + local off = 1 + while off <= #mstring do + val, off = unpack(mstring, off) if i % 4 == 0 then cur = {} ret[#ret + 1] = cur diff --git a/test/functional/shada/registers_spec.lua b/test/functional/shada/registers_spec.lua index f0133b1086..4043d94a69 100644 --- a/test/functional/shada/registers_spec.lua +++ b/test/functional/shada/registers_spec.lua @@ -43,9 +43,9 @@ describe('ShaDa support code', function() setreg('b', {'bca', 'abc', 'cba'}, 'b3') nvim_command('qall') reset() - eq({nil, ''}, getreg('c')) - eq({nil, ''}, getreg('l')) - eq({nil, ''}, getreg('b')) + eq({{}, ''}, getreg('c')) + eq({{}, ''}, getreg('l')) + eq({{}, ''}, getreg('b')) end) it('does restore registers with zero <', function() @@ -67,9 +67,9 @@ describe('ShaDa support code', function() setreg('b', {'bca', 'abc', 'cba'}, 'b3') nvim_command('qall') reset() - eq({nil, ''}, getreg('c')) - eq({nil, ''}, getreg('l')) - eq({nil, ''}, getreg('b')) + eq({{}, ''}, getreg('c')) + eq({{}, ''}, getreg('l')) + eq({{}, ''}, getreg('b')) end) it('does restore registers with zero "', function() @@ -103,7 +103,7 @@ describe('ShaDa support code', function() nvim_command('qall') reset() eq({{'d'}, 'v'}, getreg('o')) - eq({nil, ''}, getreg('t')) + eq({{}, ''}, getreg('t')) end) it('does limit number of lines according to "', function() @@ -113,7 +113,7 @@ describe('ShaDa support code', function() nvim_command('qall') reset() eq({{'d'}, 'v'}, getreg('o')) - eq({nil, ''}, getreg('t')) + eq({{}, ''}, getreg('t')) end) it('does limit number of lines according to < rather then "', function() @@ -125,7 +125,7 @@ describe('ShaDa support code', function() reset() eq({{'d'}, 'v'}, getreg('o')) eq({{'a', 'b', 'cde'}, 'V'}, getreg('t')) - eq({nil, ''}, getreg('h')) + eq({{}, ''}, getreg('h')) end) it('dumps and loads register correctly when &encoding is not UTF-8', diff --git a/test/functional/shada/shada_spec.lua b/test/functional/shada/shada_spec.lua index 822ab3913c..683d520627 100644 --- a/test/functional/shada/shada_spec.lua +++ b/test/functional/shada/shada_spec.lua @@ -8,7 +8,7 @@ local write_file, spawn, set_session, nvim_prog, exc_exec = local lfs = require('lfs') local paths = require('test.config.paths') -local msgpack = require('MessagePack') +local mpack = require('mpack') local shada_helpers = require('test.functional.shada.helpers') local reset, clear, get_shada_rw = @@ -107,7 +107,7 @@ describe('ShaDa support code', function() end) it('reads correctly various timestamps', function() - local mpack = { + local msgpack = { '\100', -- Positive fixnum 100 '\204\255', -- uint 8 255 '\205\010\003', -- uint 16 2563 @@ -116,23 +116,23 @@ describe('ShaDa support code', function() } local s = '\100' local e = '\001\192' - wshada(s .. table.concat(mpack, e .. s) .. e) + wshada(s .. table.concat(msgpack, e .. s) .. e) eq(0, exc_exec('wshada ' .. shada_fname)) local found = 0 - local typ = select(2, msgpack.unpacker(s)()) + local typ = mpack.unpack(s) for _, v in ipairs(read_shada_file(shada_fname)) do if v.type == typ then found = found + 1 - eq(select(2, msgpack.unpacker(mpack[found])()), v.timestamp) + eq(mpack.unpack(msgpack[found]), v.timestamp) end end - eq(#mpack, found) + eq(#msgpack, found) end) it('does not write NONE file', function() local session = spawn({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed', '--cmd', 'qall'}, true) - session:exit(0) + session:close() eq(nil, lfs.attributes('NONE')) eq(nil, lfs.attributes('NONE.tmp.a')) end) @@ -143,7 +143,7 @@ describe('ShaDa support code', function() true) set_session(session) eq('', funcs.getreg('a')) - session:exit(0) + session:close() os.remove('NONE') end) diff --git a/test/functional/shada/variables_spec.lua b/test/functional/shada/variables_spec.lua index 3becf1bc32..7ceeafdc71 100644 --- a/test/functional/shada/variables_spec.lua +++ b/test/functional/shada/variables_spec.lua @@ -22,12 +22,17 @@ describe('ShaDa support code', function() eq('foo', meths.get_var('STRVAR')) end) - local autotest = function(tname, varname, varval) + local autotest = function(tname, varname, varval, val_is_expr) it('is able to dump and read back ' .. tname .. ' variable automatically', function() set_additional_cmd('set shada+=!') reset() - meths.set_var(varname, varval) + if val_is_expr then + nvim_command('let g:' .. varname .. ' = ' .. varval) + varval = meths.get_var(varname) + else + meths.set_var(varname, varval) + end -- Exit during `reset` is not a regular exit: it does not write shada -- automatically nvim_command('qall') @@ -41,6 +46,10 @@ describe('ShaDa support code', function() autotest('float', 'FLTVAR', 42.5) autotest('dictionary', 'DCTVAR', {a=10}) autotest('list', 'LSTVAR', {{a=10}, {b=10.5}, {c='str'}}) + autotest('true', 'TRUEVAR', true) + autotest('false', 'FALSEVAR', false) + autotest('null', 'NULLVAR', 'v:null', true) + autotest('ext', 'EXTVAR', '{"_TYPE": v:msgpack_types.ext, "_VAL": [2, ["", ""]]}', true) it('does not read back variables without `!` in &shada', function() meths.set_var('STRVAR', 'foo') diff --git a/test/functional/terminal/cursor_spec.lua b/test/functional/terminal/cursor_spec.lua index e9cb010003..c15da2f760 100644 --- a/test/functional/terminal/cursor_spec.lua +++ b/test/functional/terminal/cursor_spec.lua @@ -59,7 +59,7 @@ describe('terminal cursor', function() ]]) end) - it('is positioned correctly when focused', function() + pending('is positioned correctly when focused', function() feed('i') screen:expect([[ 1 tty ready | diff --git a/test/functional/terminal/edit_spec.lua b/test/functional/terminal/edit_spec.lua index 6da1521121..dcc4a54610 100644 --- a/test/functional/terminal/edit_spec.lua +++ b/test/functional/terminal/edit_spec.lua @@ -70,6 +70,6 @@ describe(':edit term://*', function() end exp_screen = exp_screen .. (' '):rep(columns) .. '|\n' scr:expect(exp_screen) - eq(bufcontents, curbufmeths.get_line_slice(1, -1, true, true)) + eq(bufcontents, curbufmeths.get_lines(1, -1, true)) end) end) diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 838d05a6df..48376a344f 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -41,7 +41,7 @@ describe('tui', function() -- INSERT -- | -- TERMINAL -- | ]]) - feed('\x1b') + feed('\027') screen:expect([[ abc | test1 | @@ -57,7 +57,7 @@ describe('tui', function() local keys = 'dfghjkl' for c in keys:gmatch('.') do execute('nnoremap <a-'..c..'> ialt-'..c..'<cr><esc>') - feed('\x1b'..c) + feed('\027'..c) end screen:expect([[ alt-j | @@ -87,7 +87,7 @@ describe('tui', function() -- Example: for input ALT+j: -- * Vim (Nvim prior to #3982) sets high-bit, inserts "ê". -- * Nvim (after #3982) inserts "j". - feed('i\x1bj') + feed('i\027j') screen:expect([[ j{1: } | ~ | @@ -101,9 +101,9 @@ describe('tui', function() it('accepts ascii control sequences', function() feed('i') - feed('\x16\x07') -- ctrl+g - feed('\x16\x16') -- ctrl+v - feed('\x16\x0d') -- ctrl+m + feed('\022\007') -- ctrl+g + feed('\022\022') -- ctrl+v + feed('\022\013') -- ctrl+m screen:expect([[ {3:^G^V^M}{1: } | ~ | @@ -116,7 +116,7 @@ describe('tui', function() end) it('automatically sends <Paste> for bracketed paste sequences', function() - feed('i\x1b[200~') + feed('i\027[200~') screen:expect([[ {1: } | ~ | @@ -136,7 +136,7 @@ describe('tui', function() -- INSERT (paste) -- | -- TERMINAL -- | ]]) - feed('\x1b[201~') + feed('\027[201~') screen:expect([[ pasted from terminal{1: } | ~ | @@ -154,9 +154,9 @@ describe('tui', function() for i = 1, 3000 do t[i] = 'item ' .. tostring(i) end - feed('i\x1b[200~') + feed('i\027[200~') feed(table.concat(t, '\n')) - feed('\x1b[201~') + feed('\027[201~') screen:expect([[ item 2997 | item 2998 | @@ -204,7 +204,7 @@ describe('tui focus event handling', function() end) it('can handle focus events in normal mode', function() - feed('\x1b[I') + feed('\027[I') screen:expect([[ {1: } | ~ | @@ -215,7 +215,7 @@ describe('tui focus event handling', function() -- TERMINAL -- | ]]) - feed('\x1b[O') + feed('\027[O') screen:expect([[ {1: } | ~ | @@ -230,7 +230,7 @@ describe('tui focus event handling', function() it('can handle focus events in insert mode', function() execute('set noshowmode') feed('i') - feed('\x1b[I') + feed('\027[I') screen:expect([[ {1: } | ~ | @@ -240,7 +240,7 @@ describe('tui focus event handling', function() gained | -- TERMINAL -- | ]]) - feed('\x1b[O') + feed('\027[O') screen:expect([[ {1: } | ~ | @@ -254,7 +254,7 @@ describe('tui focus event handling', function() it('can handle focus events in cmdline mode', function() feed(':') - feed('\x1b[I') + feed('\027[I') screen:expect([[ | ~ | @@ -264,7 +264,7 @@ describe('tui focus event handling', function() g{1:a}ined | -- TERMINAL -- | ]]) - feed('\x1b[O') + feed('\027[O') screen:expect([[ | ~ | @@ -281,7 +281,7 @@ describe('tui focus event handling', function() execute('set laststatus=0') execute('set noshowmode') execute('terminal') - feed('\x1b[I') + feed('\027[I') screen:expect([[ ready $ | [Process exited 0]{1: } | @@ -291,7 +291,7 @@ describe('tui focus event handling', function() gained | -- TERMINAL -- | ]]) - feed('\x1b[O') + feed('\027[O') screen:expect([[ ready $ | [Process exited 0]{1: } | diff --git a/test/functional/ui/mouse_spec.lua b/test/functional/ui/mouse_spec.lua index da9d6a0cd2..d0d791308b 100644 --- a/test/functional/ui/mouse_spec.lua +++ b/test/functional/ui/mouse_spec.lua @@ -426,4 +426,35 @@ describe('Mouse input', function() | ]]) end) + + it('horizontal scrolling', function() + feed("<esc>:set nowrap<cr>") + + feed("a <esc>20Ab<esc>") + screen:expect([[ + | + | + bbbbbbbbbbbbbbb^b | + ~ | + | + ]]) + + feed("<ScrollWheelLeft><0,0>") + screen:expect([[ + | + | + n bbbbbbbbbbbbbbbbbbb^b | + ~ | + | + ]]) + + feed("^<ScrollWheelRight><0,0>") + screen:expect([[ + g | + | + ^t and selection bbbbbbbbb| + ~ | + | + ]]) + end) end) diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index b35e0cde69..a11fab18a2 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -138,7 +138,7 @@ do -- this is just a helper to get any canonical name of a color colornames[rgb] = name end - session:exit(0) + session:close() Screen.colors = colors Screen.colornames = colornames end diff --git a/test/functional/viml/completion_spec.lua b/test/functional/viml/completion_spec.lua index 4bb9707cda..322d777ab6 100644 --- a/test/functional/viml/completion_spec.lua +++ b/test/functional/viml/completion_spec.lua @@ -1,12 +1,27 @@ local helpers = require('test.functional.helpers') +local Screen = require('test.functional.ui.screen') local clear, feed = helpers.clear, helpers.feed local eval, eq, neq = helpers.eval, helpers.eq, helpers.neq local execute, source, expect = helpers.execute, helpers.source, helpers.expect describe('completion', function() + local screen + before_each(function() clear() + screen = Screen.new(60, 8) + screen:attach() + screen:set_default_attr_ignore({{bold=true, foreground=Screen.colors.Blue}}) + screen:set_default_attr_ids({ + [1] = {background = Screen.colors.LightMagenta}, + [2] = {background = Screen.colors.Grey}, + [3] = {bold = true}, + [4] = {bold = true, foreground = Screen.colors.SeaGreen}, + [5] = {foreground = Screen.colors.Red}, + [6] = {background = Screen.colors.Black}, + [7] = {foreground = Screen.colors.White, background = Screen.colors.Red}, + }) end) describe('v:completed_item', function() @@ -14,18 +29,40 @@ describe('completion', function() eq({}, eval('v:completed_item')) end) it('is empty dict if the candidate is not inserted', function() - feed('ifoo<ESC>o<C-x><C-n><C-e><ESC>') + feed('ifoo<ESC>o<C-x><C-n>') + screen:expect([[ + foo | + foo^ | + ~ | + ~ | + ~ | + ~ | + ~ | + {3:-- Keyword Local completion (^N^P) The only match} | + ]]) + feed('<C-e>') + screen:expect([[ + foo | + ^ | + ~ | + ~ | + ~ | + ~ | + ~ | + {3:-- INSERT --} | + ]]) + feed('<ESC>') eq({}, eval('v:completed_item')) end) it('returns expected dict in normal completion', function() - feed('ifoo<ESC>o<C-x><C-n><ESC>') + feed('ifoo<ESC>o<C-x><C-n>') eq('foo', eval('getline(2)')) eq({word = 'foo', abbr = '', menu = '', info = '', kind = ''}, eval('v:completed_item')) end) it('is readonly', function() + screen:try_resize(80, 8) feed('ifoo<ESC>o<C-x><C-n><ESC>') - execute('let v:completed_item.word = "bar"') neq(nil, string.find(eval('v:errmsg'), '^E46: ')) execute('let v:errmsg = ""') @@ -50,17 +87,29 @@ describe('completion', function() source([[ function! TestOmni(findstart, base) abort return a:findstart ? 0 : [{'word': 'foo', 'abbr': 'bar', - \ 'menu': 'baz', 'info': 'foobar', 'kind': 'foobaz'}] + \ 'menu': 'baz', 'info': 'foobar', 'kind': 'foobaz'}, + \ {'word': 'word', 'abbr': 'abbr', 'menu': 'menu', 'info': 'info', 'kind': 'kind'}] endfunction setlocal omnifunc=TestOmni ]]) - feed('i<C-x><C-o><ESC>') + feed('i<C-x><C-o>') eq('foo', eval('getline(1)')) + screen:expect([[ + foo^ | + {2:bar foobaz baz } | + {1:abbr kind menu } | + ~ | + ~ | + ~ | + ~ | + {3:-- Omni completion (^O^N^P) }{4:match 1 of 2} | + ]]) eq({word = 'foo', abbr = 'bar', menu = 'baz', info = 'foobar', kind = 'foobaz'}, eval('v:completed_item')) end) end) + describe('completeopt', function() before_each(function() source([[ @@ -73,32 +122,196 @@ describe('completion', function() it('inserts the first candidate if default', function() execute('set completeopt+=menuone') - feed('ifoo<ESC>o<C-x><C-n>bar<ESC>') + feed('ifoo<ESC>o') + screen:expect([[ + foo | + ^ | + ~ | + ~ | + ~ | + ~ | + ~ | + {3:-- INSERT --} | + ]]) + feed('<C-x>') + -- the ^X prompt, only test this once + screen:expect([[ + foo | + ^ | + ~ | + ~ | + ~ | + ~ | + ~ | + {3:-- ^X mode (^]^D^E^F^I^K^L^N^O^Ps^U^V^Y)} | + ]]) + feed('<C-n>') + screen:expect([[ + foo | + foo^ | + {2:foo } | + ~ | + ~ | + ~ | + ~ | + {3:-- Keyword Local completion (^N^P) The only match} | + ]]) + feed('bar<ESC>') eq('foobar', eval('getline(2)')) - feed('o<C-r>=TestComplete()<CR><ESC>') + feed('o<C-r>=TestComplete()<CR>') + screen:expect([[ + foo | + foobar | + foo^ | + {2:foo } | + ~ | + ~ | + ~ | + {3:-- INSERT --} | + ]]) eq('foo', eval('getline(3)')) end) it('selects the first candidate if noinsert', function() execute('set completeopt+=menuone,noinsert') - feed('ifoo<ESC>o<C-x><C-n><C-y><ESC>') + feed('ifoo<ESC>o<C-x><C-n>') + screen:expect([[ + foo | + ^ | + {2:foo } | + ~ | + ~ | + ~ | + ~ | + {3:-- Keyword Local completion (^N^P) The only match} | + ]]) + feed('<C-y>') + screen:expect([[ + foo | + foo^ | + ~ | + ~ | + ~ | + ~ | + ~ | + {3:-- INSERT --} | + ]]) + feed('<ESC>') eq('foo', eval('getline(2)')) - feed('o<C-r>=TestComplete()<CR><C-y><ESC>') + feed('o<C-r>=TestComplete()<CR>') + screen:expect([[ + foo | + foo | + ^ | + {2:foo } | + ~ | + ~ | + ~ | + {3:-- INSERT --} | + ]]) + feed('<C-y><ESC>') eq('foo', eval('getline(3)')) end) it('does not insert the first candidate if noselect', function() execute('set completeopt+=menuone,noselect') - feed('ifoo<ESC>o<C-x><C-n>bar<ESC>') + feed('ifoo<ESC>o<C-x><C-n>') + screen:expect([[ + foo | + ^ | + {1:foo } | + ~ | + ~ | + ~ | + ~ | + {3:-- Keyword Local completion (^N^P) }{5:Back at original} | + ]]) + feed('b') + screen:expect([[ + foo | + b^ | + ~ | + ~ | + ~ | + ~ | + ~ | + {3:-- Keyword Local completion (^N^P) }{5:Back at original} | + ]]) + feed('ar<ESC>') eq('bar', eval('getline(2)')) - feed('o<C-r>=TestComplete()<CR>bar<ESC>') + feed('o<C-r>=TestComplete()<CR>') + screen:expect([[ + foo | + bar | + ^ | + {1:foo } | + ~ | + ~ | + ~ | + {3:-- INSERT --} | + ]]) + feed('bar<ESC>') eq('bar', eval('getline(3)')) end) it('does not select/insert the first candidate if noselect and noinsert', function() execute('set completeopt+=menuone,noselect,noinsert') - feed('ifoo<ESC>o<C-x><C-n><ESC>') + feed('ifoo<ESC>o<C-x><C-n>') + screen:expect([[ + foo | + ^ | + {1:foo } | + ~ | + ~ | + ~ | + ~ | + {3:-- Keyword Local completion (^N^P) }{5:Back at original} | + ]]) + feed('<ESC>') + screen:expect([[ + foo | + ^ | + ~ | + ~ | + ~ | + ~ | + ~ | + | + ]]) eq('', eval('getline(2)')) - feed('o<C-r>=TestComplete()<CR><ESC>') + feed('o<C-r>=TestComplete()<CR>') + screen:expect([[ + foo | + | + ^ | + {1:foo } | + ~ | + ~ | + ~ | + {3:-- INSERT --} | + ]]) + feed('<ESC>') + screen:expect([[ + foo | + | + ^ | + ~ | + ~ | + ~ | + ~ | + | + ]]) eq('', eval('getline(3)')) end) + it('does not change modified state if noinsert', function() + execute('set completeopt+=menuone,noinsert') + execute('setlocal nomodified') + feed('i<C-r>=TestComplete()<CR><ESC>') + eq(0, eval('&l:modified')) + end) + it('does not change modified state if noselect', function() + execute('set completeopt+=menuone,noselect') + execute('setlocal nomodified') + feed('i<C-r>=TestComplete()<CR><ESC>') + eq(0, eval('&l:modified')) + end) end) describe("refresh:always", function() @@ -129,16 +342,378 @@ describe('completion', function() end ) it('completes on each input char', function () - feed('i<C-x><C-u>gu<Down><C-y>') + feed('i<C-x><C-u>') + screen:expect([[ + ^ | + {1:January }{6: } | + {1:February }{6: } | + {1:March }{6: } | + {1:April }{2: } | + {1:May }{2: } | + {1:June }{2: } | + {3:-- User defined completion (^U^N^P) }{5:Back at original} | + ]]) + feed('u') + screen:expect([[ + u^ | + {1:January } | + {1:February } | + {1:June } | + {1:July } | + {1:August } | + ~ | + {3:-- User defined completion (^U^N^P) }{5:Back at original} | + ]]) + feed('g') + screen:expect([[ + ug^ | + {1:August } | + ~ | + ~ | + ~ | + ~ | + ~ | + {3:-- User defined completion (^U^N^P) }{5:Back at original} | + ]]) + feed('<Down>') + screen:expect([[ + ug^ | + {2:August } | + ~ | + ~ | + ~ | + ~ | + ~ | + {3:-- User defined completion (^U^N^P) The only match} | + ]]) + feed('<C-y>') + screen:expect([[ + August^ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + {3:-- INSERT --} | + ]]) expect('August') end) it("repeats correctly after backspace #2674", function () - feed('o<C-x><C-u>Ja<BS><C-n><C-n><Esc>') + feed('o<C-x><C-u>Ja') + screen:expect([[ + | + Ja^ | + {1:January } | + ~ | + ~ | + ~ | + ~ | + {3:-- User defined completion (^U^N^P) }{5:Back at original} | + ]]) + feed('<BS>') + screen:expect([[ + | + J^ | + {1:January } | + {1:June } | + {1:July } | + ~ | + ~ | + {3:-- User defined completion (^U^N^P) }{5:Back at original} | + ]]) + feed('<C-n>') + screen:expect([[ + | + January^ | + {2:January } | + {1:June } | + {1:July } | + ~ | + ~ | + {3:-- User defined completion (^U^N^P) }{4:match 1 of 3} | + ]]) + feed('<C-n>') + screen:expect([[ + | + June^ | + {1:January } | + {2:June } | + {1:July } | + ~ | + ~ | + {3:-- User defined completion (^U^N^P) }{4:match 2 of 3} | + ]]) + feed('<Esc>') + screen:expect([[ + | + Jun^e | + ~ | + ~ | + ~ | + ~ | + ~ | + | + ]]) feed('.') + screen:expect([[ + | + June | + Jun^e | + ~ | + ~ | + ~ | + ~ | + | + ]]) expect([[ June June]]) end) end) + + describe('with a lot of items', function() + before_each(function() + source([[ + function! TestComplete() abort + call complete(1, map(range(0,100), "string(v:val)")) + return '' + endfunction + ]]) + execute("set completeopt=menuone,noselect") + end) + + it("works", function() + feed('i<C-r>=TestComplete()<CR>') + screen:expect([[ + ^ | + {1:0 }{6: } | + {1:1 }{2: } | + {1:2 }{2: } | + {1:3 }{2: } | + {1:4 }{2: } | + {1:5 }{2: } | + {3:-- INSERT --} | + ]]) + feed('7') + screen:expect([[ + 7^ | + {1:7 }{6: } | + {1:70 }{6: } | + {1:71 }{6: } | + {1:72 }{2: } | + {1:73 }{2: } | + {1:74 }{2: } | + {3:-- INSERT --} | + ]]) + feed('<c-n>') + screen:expect([[ + 7^ | + {2:7 }{6: } | + {1:70 }{6: } | + {1:71 }{6: } | + {1:72 }{2: } | + {1:73 }{2: } | + {1:74 }{2: } | + {3:-- INSERT --} | + ]]) + feed('<c-n>') + screen:expect([[ + 70^ | + {1:7 }{6: } | + {2:70 }{6: } | + {1:71 }{6: } | + {1:72 }{2: } | + {1:73 }{2: } | + {1:74 }{2: } | + {3:-- INSERT --} | + ]]) + end) + + it('can be navigated with <PageDown>, <PageUp>', function() + feed('i<C-r>=TestComplete()<CR>') + screen:expect([[ + ^ | + {1:0 }{6: } | + {1:1 }{2: } | + {1:2 }{2: } | + {1:3 }{2: } | + {1:4 }{2: } | + {1:5 }{2: } | + {3:-- INSERT --} | + ]]) + feed('<PageDown>') + screen:expect([[ + ^ | + {1:0 }{6: } | + {1:1 }{2: } | + {1:2 }{2: } | + {2:3 } | + {1:4 }{2: } | + {1:5 }{2: } | + {3:-- INSERT --} | + ]]) + feed('<PageDown>') + screen:expect([[ + ^ | + {1:5 }{6: } | + {1:6 }{2: } | + {2:7 } | + {1:8 }{2: } | + {1:9 }{2: } | + {1:10 }{2: } | + {3:-- INSERT --} | + ]]) + feed('<Down>') + screen:expect([[ + ^ | + {1:5 }{6: } | + {1:6 }{2: } | + {1:7 }{2: } | + {2:8 } | + {1:9 }{2: } | + {1:10 }{2: } | + {3:-- INSERT --} | + ]]) + feed('<PageUp>') + screen:expect([[ + ^ | + {1:2 }{6: } | + {1:3 }{2: } | + {2:4 } | + {1:5 }{2: } | + {1:6 }{2: } | + {1:7 }{2: } | + {3:-- INSERT --} | + ]]) + feed('<PageUp>') -- stop on first item + screen:expect([[ + ^ | + {2:0 }{6: } | + {1:1 }{2: } | + {1:2 }{2: } | + {1:3 }{2: } | + {1:4 }{2: } | + {1:5 }{2: } | + {3:-- INSERT --} | + ]]) + feed('<PageUp>') -- when on first item, unselect + screen:expect([[ + ^ | + {1:0 }{6: } | + {1:1 }{2: } | + {1:2 }{2: } | + {1:3 }{2: } | + {1:4 }{2: } | + {1:5 }{2: } | + {3:-- INSERT --} | + ]]) + feed('<PageUp>') -- when unselected, select last item + screen:expect([[ + ^ | + {1:95 }{2: } | + {1:96 }{2: } | + {1:97 }{2: } | + {1:98 }{2: } | + {1:99 }{2: } | + {2:100 }{6: } | + {3:-- INSERT --} | + ]]) + feed('<PageUp>') + screen:expect([[ + ^ | + {1:94 }{2: } | + {1:95 }{2: } | + {2:96 } | + {1:97 }{2: } | + {1:98 }{2: } | + {1:99 }{6: } | + {3:-- INSERT --} | + ]]) + feed('<cr>') + screen:expect([[ + 96^ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + {3:-- INSERT --} | + ]]) + end) + end) + + + it('disables folding during completion', function () + execute("set foldmethod=indent") + feed('i<Tab>foo<CR><Tab>bar<Esc>gg') + screen:expect([[ + ^foo | + bar | + ~ | + ~ | + ~ | + ~ | + ~ | + | + ]]) + feed('A<C-x><C-l>') + screen:expect([[ + foo^ | + bar | + ~ | + ~ | + ~ | + ~ | + ~ | + {3:-- Whole line completion (^L^N^P) }{7:Pattern not found} | + ]]) + eq(-1, eval('foldclosed(1)')) + end) + + it('popupmenu is not interrupted by events', function () + execute("set complete=.") + + feed('ifoobar fooegg<cr>f<c-p>') + screen:expect([[ + foobar fooegg | + fooegg^ | + {1:foobar } | + {2:fooegg } | + ~ | + ~ | + ~ | + {3:-- Keyword completion (^N^P) }{4:match 1 of 2} | + ]]) + + eval('1 + 1') + -- popupmenu still visible + screen:expect([[ + foobar fooegg | + fooegg^ | + {1:foobar } | + {2:fooegg } | + ~ | + ~ | + ~ | + {3:-- Keyword completion (^N^P) }{4:match 1 of 2} | + ]]) + + feed('<c-p>') + -- Didn't restart completion: old matches still used + screen:expect([[ + foobar fooegg | + foobar^ | + {2:foobar } | + {1:fooegg } | + ~ | + ~ | + ~ | + {3:-- Keyword completion (^N^P) }{4:match 2 of 2} | + ]]) + end) + end) + diff --git a/test/functional/viml/errorlist_spec.lua b/test/functional/viml/errorlist_spec.lua index 78e25297f2..30cb86f8d1 100644 --- a/test/functional/viml/errorlist_spec.lua +++ b/test/functional/viml/errorlist_spec.lua @@ -3,32 +3,44 @@ local helpers = require('test.functional.helpers') local clear = helpers.clear local command = helpers.command local eq = helpers.eq +local exc_exec = helpers.exc_exec local get_cur_win_var = helpers.curwinmeths.get_var --- local exc_exec = helpers.exc_exec describe('setqflist()', function() local setqflist = helpers.funcs.setqflist before_each(clear) + it('requires a list for {list}', function() + eq('Vim(call):E714: List required', exc_exec('call setqflist("foo")')) + eq('Vim(call):E714: List required', exc_exec('call setqflist(5)')) + eq('Vim(call):E714: List required', exc_exec('call setqflist({})')) + end) + + it('requires a string for {action}', function() + eq('Vim(call):E114: String required', exc_exec('call setqflist([], 5)')) + eq('Vim(call):E114: String required', exc_exec('call setqflist([], [])')) + eq('Vim(call):E114: String required', exc_exec('call setqflist([], {})')) + end) + it('sets w:quickfix_title', function() setqflist({''}, 'r', 'foo') command('copen') eq(':foo', get_cur_win_var('quickfix_title')) end) - it('expects a proper type for {title}', function() + it('requires string or number for {title}', function() command('copen') - setqflist({''}, 'r', '5') + setqflist({}, 'r', '5') eq(':5', get_cur_win_var('quickfix_title')) - setqflist({''}, 'r', 6) - eq(':setqflist()', get_cur_win_var('quickfix_title')) - -- local exc = exc_exec('call setqflist([""], "r", function("function"))') - -- eq('Vim(call):E729: using Funcref as a String', exc) - -- exc = exc_exec('call setqflist([""], "r", [])') - -- eq('Vim(call):E730: using List as a String', exc) - -- exc = exc_exec('call setqflist([""], "r", {})') - -- eq('Vim(call):E731: using Dictionary as a String', exc) + setqflist({}, 'r', 6) + eq(':6', get_cur_win_var('quickfix_title')) + local exc = exc_exec('call setqflist([], "r", function("function"))') + eq('Vim(call):E729: using Funcref as a String', exc) + exc = exc_exec('call setqflist([], "r", [])') + eq('Vim(call):E730: using List as a String', exc) + exc = exc_exec('call setqflist([], "r", {})') + eq('Vim(call):E731: using Dictionary as a String', exc) end) end) @@ -37,10 +49,22 @@ describe('setloclist()', function() before_each(clear) + it('requires a list for {list}', function() + eq('Vim(call):E714: List required', exc_exec('call setloclist(0, "foo")')) + eq('Vim(call):E714: List required', exc_exec('call setloclist(0, 5)')) + eq('Vim(call):E714: List required', exc_exec('call setloclist(0, {})')) + end) + + it('requires a string for {action}', function() + eq('Vim(call):E114: String required', exc_exec('call setloclist(0, [], 5)')) + eq('Vim(call):E114: String required', exc_exec('call setloclist(0, [], [])')) + eq('Vim(call):E114: String required', exc_exec('call setloclist(0, [], {})')) + end) + it('sets w:quickfix_title for the correct window', function() command('rightbelow vsplit') - setloclist(1, {''}, 'r', 'foo') - setloclist(2, {''}, 'r', 'bar') + setloclist(1, {}, 'r', 'foo') + setloclist(2, {}, 'r', 'bar') command('lopen') eq(':bar', get_cur_win_var('quickfix_title')) command('lclose | wincmd w | lopen') diff --git a/test/unit/buffer_spec.lua b/test/unit/buffer_spec.lua index a2e7bd91af..b7f82064d7 100644 --- a/test/unit/buffer_spec.lua +++ b/test/unit/buffer_spec.lua @@ -41,13 +41,13 @@ describe('buffer functions', function() describe('buf_valid', function() it('should view NULL as an invalid buffer', function() - eq(0, buffer.buf_valid(NULL)) + eq(false, buffer.buf_valid(NULL)) end) it('should view an open buffer as valid', function() local buf = buflist_new(path1, buffer.BLN_LISTED) - eq(1, buffer.buf_valid(buf)) + eq(true, buffer.buf_valid(buf)) end) it('should view a closed and hidden buffer as valid', function() @@ -55,7 +55,7 @@ describe('buffer functions', function() close_buffer(NULL, buf, 0, 0) - eq(1, buffer.buf_valid(buf)) + eq(true, buffer.buf_valid(buf)) end) it('should view a closed and unloaded buffer as valid', function() @@ -63,7 +63,7 @@ describe('buffer functions', function() close_buffer(NULL, buf, buffer.DOBUF_UNLOAD, 0) - eq(1, buffer.buf_valid(buf)) + eq(true, buffer.buf_valid(buf)) end) it('should view a closed and wiped buffer as invalid', function() @@ -71,7 +71,7 @@ describe('buffer functions', function() close_buffer(NULL, buf, buffer.DOBUF_WIPE, 0) - eq(0, buffer.buf_valid(buf)) + eq(false, buffer.buf_valid(buf)) end) end) diff --git a/test/unit/eval/decode_spec.lua b/test/unit/eval/decode_spec.lua new file mode 100644 index 0000000000..d94d809c14 --- /dev/null +++ b/test/unit/eval/decode_spec.lua @@ -0,0 +1,142 @@ +local helpers = require('test.unit.helpers') + +local cimport = helpers.cimport +local to_cstr = helpers.to_cstr +local eq = helpers.eq +local neq = helpers.neq +local ffi = helpers.ffi + +local decode = cimport('./src/nvim/eval/decode.h', './src/nvim/eval_defs.h', + './src/nvim/globals.h', './src/nvim/memory.h', + './src/nvim/message.h') + +describe('json_decode_string()', function() + local saved_p_enc = nil + + before_each(function() + saved_p_enc = decode.p_enc + end) + + after_each(function() + decode.emsg_silent = 0 + decode.p_enc = saved_p_enc + while decode.delete_first_msg() == 1 do + -- Delete all messages + end + end) + + local char = function(c) + return ffi.gc(decode.xmemdup(c, 1), decode.xfree) + end + + it('does not overflow when running with `n…`, `t…`, `f…`', function() + local rettv = ffi.new('typval_T', {v_type=decode.VAR_UNKNOWN}) + decode.emsg_silent = 1 + -- This will not crash, but if `len` argument will be ignored it will parse + -- `null` as `null` and if not it will parse `null` as `n`. + eq(0, decode.json_decode_string('null', 1, rettv)) + eq(decode.VAR_UNKNOWN, rettv.v_type) + eq(0, decode.json_decode_string('true', 1, rettv)) + eq(decode.VAR_UNKNOWN, rettv.v_type) + eq(0, decode.json_decode_string('false', 1, rettv)) + eq(decode.VAR_UNKNOWN, rettv.v_type) + eq(0, decode.json_decode_string('null', 2, rettv)) + eq(decode.VAR_UNKNOWN, rettv.v_type) + eq(0, decode.json_decode_string('true', 2, rettv)) + eq(decode.VAR_UNKNOWN, rettv.v_type) + eq(0, decode.json_decode_string('false', 2, rettv)) + eq(decode.VAR_UNKNOWN, rettv.v_type) + eq(0, decode.json_decode_string('null', 3, rettv)) + eq(decode.VAR_UNKNOWN, rettv.v_type) + eq(0, decode.json_decode_string('true', 3, rettv)) + eq(decode.VAR_UNKNOWN, rettv.v_type) + eq(0, decode.json_decode_string('false', 3, rettv)) + eq(decode.VAR_UNKNOWN, rettv.v_type) + eq(0, decode.json_decode_string('false', 4, rettv)) + eq(decode.VAR_UNKNOWN, rettv.v_type) + end) + + it('does not overflow and crash when running with `n`, `t`, `f`', function() + local rettv = ffi.new('typval_T', {v_type=decode.VAR_UNKNOWN}) + decode.emsg_silent = 1 + eq(0, decode.json_decode_string(char('n'), 1, rettv)) + eq(decode.VAR_UNKNOWN, rettv.v_type) + eq(0, decode.json_decode_string(char('t'), 1, rettv)) + eq(decode.VAR_UNKNOWN, rettv.v_type) + eq(0, decode.json_decode_string(char('f'), 1, rettv)) + eq(decode.VAR_UNKNOWN, rettv.v_type) + end) + + it('does not overflow when running with `"…`', function() + local rettv = ffi.new('typval_T', {v_type=decode.VAR_UNKNOWN}) + decode.emsg_silent = 1 + eq(0, decode.json_decode_string('"t"', 2, rettv)) + eq(decode.VAR_UNKNOWN, rettv.v_type) + eq(0, decode.json_decode_string('""', 1, rettv)) + eq(decode.VAR_UNKNOWN, rettv.v_type) + end) + + local check_failure = function(s, len, msg) + local rettv = ffi.new('typval_T', {v_type=decode.VAR_UNKNOWN}) + eq(0, decode.json_decode_string(s, len, rettv)) + eq(decode.VAR_UNKNOWN, rettv.v_type) + neq(nil, decode.last_msg_hist) + eq(msg, ffi.string(decode.last_msg_hist.msg)) + end + + it('does not overflow in error messages', function() + check_failure(']test', 1, 'E474: No container to close: ]') + check_failure('[}test', 2, 'E474: Closing list with curly bracket: }') + check_failure('{]test', 2, + 'E474: Closing dictionary with square bracket: ]') + check_failure('[1,]test', 4, 'E474: Trailing comma: ]') + check_failure('{"1":}test', 6, 'E474: Expected value after colon: }') + check_failure('{"1"}test', 5, 'E474: Expected value: }') + check_failure(',test', 1, 'E474: Comma not inside container: ,') + check_failure('[1,,1]test', 6, 'E474: Duplicate comma: ,1]') + check_failure('{"1":,}test', 7, 'E474: Comma after colon: ,}') + check_failure('{"1",}test', 6, 'E474: Using comma in place of colon: ,}') + check_failure('{,}test', 3, 'E474: Leading comma: ,}') + check_failure('[,]test', 3, 'E474: Leading comma: ,]') + check_failure(':test', 1, 'E474: Colon not inside container: :') + check_failure('[:]test', 3, 'E474: Using colon not in dictionary: :]') + check_failure('{:}test', 3, 'E474: Unexpected colon: :}') + check_failure('{"1"::1}test', 8, 'E474: Duplicate colon: :1}') + check_failure('ntest', 1, 'E474: Expected null: n') + check_failure('ttest', 1, 'E474: Expected true: t') + check_failure('ftest', 1, 'E474: Expected false: f') + check_failure('"\\test', 2, 'E474: Unfinished escape sequence: "\\') + check_failure('"\\u"test', 4, + 'E474: Unfinished unicode escape sequence: "\\u"') + check_failure('"\\uXXXX"est', 8, + 'E474: Expected four hex digits after \\u: \\uXXXX"') + check_failure('"\\?"test', 4, 'E474: Unknown escape sequence: \\?"') + check_failure( + '"\t"test', 3, + 'E474: ASCII control characters cannot be present inside string: \t"') + check_failure('"\194"test', 3, 'E474: Only UTF-8 strings allowed: \194"') + check_failure('"\252\144\128\128\128\128"test', 8, 'E474: Only UTF-8 code points up to U+10FFFF are allowed to appear unescaped: \252\144\128\128\128\128"') + check_failure('"test', 1, 'E474: Expected string end: "') + decode.p_enc = to_cstr('latin1') + check_failure('"\\uABCD"test', 8, + 'E474: Failed to convert string "ꯍ" from UTF-8') + decode.p_enc = saved_p_enc + check_failure('-test', 1, 'E474: Missing number after minus sign: -') + check_failure('-1.test', 3, 'E474: Missing number after decimal dot: -1.') + check_failure('-1.0etest', 5, 'E474: Missing exponent: -1.0e') + check_failure('?test', 1, 'E474: Unidentified byte: ?') + check_failure('1?test', 2, 'E474: Trailing characters: ?') + check_failure('[1test', 2, 'E474: Unexpected end of input: [1') + end) + + it('does not overflow with `-`', function() + check_failure('-0', 1, 'E474: Missing number after minus sign: -') + end) + + it('does not overflow and crash when running with `"`', function() + local rettv = ffi.new('typval_T', {v_type=decode.VAR_UNKNOWN}) + decode.emsg_silent = 1 + eq(0, decode.json_decode_string(char('"'), 1, rettv)) + eq(decode.VAR_UNKNOWN, rettv.v_type) + end) +end) diff --git a/test/unit/eval/encode_spec.lua b/test/unit/eval/encode_spec.lua new file mode 100644 index 0000000000..f151a191fb --- /dev/null +++ b/test/unit/eval/encode_spec.lua @@ -0,0 +1,100 @@ +local helpers = require('test.unit.helpers') +local eval_helpers = require('test.unit.eval.helpers') + +local cimport = helpers.cimport +local to_cstr = helpers.to_cstr +local eq = helpers.eq + +local list = eval_helpers.list +local lst2tbl = eval_helpers.lst2tbl +local type_key = eval_helpers.type_key +local list_type = eval_helpers.list_type +local null_string = eval_helpers.null_string + +local encode = cimport('./src/nvim/eval/encode.h') + +describe('encode_list_write()', function() + local encode_list_write = function(l, s) + return encode.encode_list_write(l, to_cstr(s), #s) + end + + it('writes empty string', function() + local l = list() + eq(0, encode_list_write(l, '')) + eq({[type_key]=list_type}, lst2tbl(l)) + end) + + it('writes ASCII string literal with printable characters', function() + local l = list() + eq(0, encode_list_write(l, 'abc')) + eq({[type_key]=list_type, 'abc'}, lst2tbl(l)) + end) + + it('writes string starting with NL', function() + local l = list() + eq(0, encode_list_write(l, '\nabc')) + eq({[type_key]=list_type, null_string, 'abc'}, lst2tbl(l)) + end) + + it('writes string starting with NL twice', function() + local l = list() + eq(0, encode_list_write(l, '\nabc')) + eq({[type_key]=list_type, null_string, 'abc'}, lst2tbl(l)) + eq(0, encode_list_write(l, '\nabc')) + eq({[type_key]=list_type, null_string, 'abc', 'abc'}, lst2tbl(l)) + end) + + it('writes string ending with NL', function() + local l = list() + eq(0, encode_list_write(l, 'abc\n')) + eq({[type_key]=list_type, 'abc', null_string}, lst2tbl(l)) + end) + + it('writes string ending with NL twice', function() + local l = list() + eq(0, encode_list_write(l, 'abc\n')) + eq({[type_key]=list_type, 'abc', null_string}, lst2tbl(l)) + eq(0, encode_list_write(l, 'abc\n')) + eq({[type_key]=list_type, 'abc', 'abc', null_string}, lst2tbl(l)) + end) + + it('writes string starting, ending and containing NL twice', function() + local l = list() + eq(0, encode_list_write(l, '\na\nb\n')) + eq({[type_key]=list_type, null_string, 'a', 'b', null_string}, lst2tbl(l)) + eq(0, encode_list_write(l, '\na\nb\n')) + eq({[type_key]=list_type, null_string, 'a', 'b', null_string, 'a', 'b', null_string}, lst2tbl(l)) + end) + + it('writes string starting, ending and containing NUL with NL between twice', function() + local l = list() + eq(0, encode_list_write(l, '\0\n\0\n\0')) + eq({[type_key]=list_type, '\n', '\n', '\n'}, lst2tbl(l)) + eq(0, encode_list_write(l, '\0\n\0\n\0')) + eq({[type_key]=list_type, '\n', '\n', '\n\n', '\n', '\n'}, lst2tbl(l)) + end) + + it('writes string starting, ending and containing NL with NUL between twice', function() + local l = list() + eq(0, encode_list_write(l, '\n\0\n\0\n')) + eq({[type_key]=list_type, null_string, '\n', '\n', null_string}, lst2tbl(l)) + eq(0, encode_list_write(l, '\n\0\n\0\n')) + eq({[type_key]=list_type, null_string, '\n', '\n', null_string, '\n', '\n', null_string}, lst2tbl(l)) + end) + + it('writes string containing a single NL twice', function() + local l = list() + eq(0, encode_list_write(l, '\n')) + eq({[type_key]=list_type, null_string, null_string}, lst2tbl(l)) + eq(0, encode_list_write(l, '\n')) + eq({[type_key]=list_type, null_string, null_string, null_string}, lst2tbl(l)) + end) + + it('writes string containing a few NLs twice', function() + local l = list() + eq(0, encode_list_write(l, '\n\n\n')) + eq({[type_key]=list_type, null_string, null_string, null_string, null_string}, lst2tbl(l)) + eq(0, encode_list_write(l, '\n\n\n')) + eq({[type_key]=list_type, null_string, null_string, null_string, null_string, null_string, null_string, null_string}, lst2tbl(l)) + end) +end) diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua new file mode 100644 index 0000000000..da2f5626ff --- /dev/null +++ b/test/unit/eval/helpers.lua @@ -0,0 +1,72 @@ +local helpers = require('test.unit.helpers') + +local cimport = helpers.cimport +local to_cstr = helpers.to_cstr +local ffi = helpers.ffi +local eq = helpers.eq + +local eval = cimport('./src/nvim/eval.h', './src/nvim/eval_defs.h') + +local null_string = {[true]='NULL string'} +local null_list = {[true]='NULL list'} +local type_key = {[true]='type key'} +local list_type = {[true]='list type'} + +local list = function(...) + local ret = ffi.gc(eval.list_alloc(), eval.list_unref) + eq(0, ret.lv_refcount) + ret.lv_refcount = 1 + for i = 1, select('#', ...) do + local val = select(i, ...) + local typ = type(val) + if typ == 'string' then + eval.list_append_string(ret, to_cstr(val)) + elseif typ == 'table' and val == null_string then + eval.list_append_string(ret, nil) + elseif typ == 'table' and val == null_list then + eval.list_append_list(ret, nil) + elseif typ == 'table' and val[type_key] == list_type then + local itemlist = ffi.gc(list(table.unpack(val)), nil) + eq(1, itemlist.lv_refcount) + itemlist.lv_refcount = 0 + eval.list_append_list(ret, itemlist) + else + assert(false, 'Not implemented yet') + end + end + return ret +end + +local lst2tbl = function(l) + local ret = {[type_key]=list_type} + if l == nil then + return ret + end + local li = l.lv_first + -- (listitem_T *) NULL is equal to nil, but yet it is not false. + while li ~= nil do + local typ = li.li_tv.v_type + if typ == eval.VAR_STRING then + str = li.li_tv.vval.v_string + if str == nil then + ret[#ret + 1] = null_string + else + ret[#ret + 1] = ffi.string(str) + end + else + assert(false, 'Not implemented yet') + end + li = li.li_next + end + return ret +end + +return { + null_string=null_string, + null_list=null_list, + list_type=list_type, + type_key=type_key, + + list=list, + lst2tbl=lst2tbl, +} diff --git a/test/unit/eval/tricks_spec.lua b/test/unit/eval/tricks_spec.lua new file mode 100644 index 0000000000..4c5184995c --- /dev/null +++ b/test/unit/eval/tricks_spec.lua @@ -0,0 +1,43 @@ +local helpers = require('test.unit.helpers') + +local cimport = helpers.cimport +local to_cstr = helpers.to_cstr +local ffi = helpers.ffi +local eq = helpers.eq + +local eval = cimport('./src/nvim/eval.h', './src/nvim/memory.h') + +local eval_expr = function(expr) + return ffi.gc(eval.eval_expr(to_cstr(expr), nil), function(tv) + eval.clear_tv(tv) + eval.xfree(tv) + end) +end + +describe('NULL typval_T', function() + it('is produced by $XXX_UNEXISTENT_VAR_XXX', function() + -- Required for various tests which need to check whether typval_T with NULL + -- string works correctly. This test checks that unexistent environment + -- variable produces NULL string, not that some specific environment + -- variable does not exist. Last bit is left for the test writers. + local unexistent_env = 'XXX_UNEXISTENT_VAR_XXX' + while os.getenv(unexistent_env) ~= nil do + unexistent_env = unexistent_env .. '_XXX' + end + local rettv = eval_expr('$' .. unexistent_env) + eq(eval.VAR_STRING, rettv.v_type) + eq(nil, rettv.vval.v_string) + end) + + it('is produced by v:_null_list', function() + local rettv = eval_expr('v:_null_list') + eq(eval.VAR_LIST, rettv.v_type) + eq(nil, rettv.vval.v_list) + end) + + it('is produced by v:_null_dict', function() + local rettv = eval_expr('v:_null_dict') + eq(eval.VAR_DICT, rettv.v_type) + eq(nil, rettv.vval.v_dict) + end) +end) diff --git a/test/unit/formatc.lua b/test/unit/formatc.lua index 3f86c5f1b1..00637e0b8d 100644 --- a/test/unit/formatc.lua +++ b/test/unit/formatc.lua @@ -238,7 +238,7 @@ local function standalone(...) -- luacheck: ignore end -- uncomment this line (and comment the `return`) for standalone debugging -- example usage: --- ../../.deps/usr/bin/luajit formatc.lua ../../include/tempfile.h.generated.h +-- ../../.deps/usr/bin/luajit formatc.lua ../../include/fileio.h.generated.h -- ../../.deps/usr/bin/luajit formatc.lua /usr/include/malloc.h -- standalone(...) return formatc diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 7b43b2218c..426ae2d9e0 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -28,8 +28,10 @@ local function filter_complex_blocks(body) local result = {} for line in body:gmatch("[^\r\n]+") do - if not (string.find(line, "(^)", 1, true) ~= nil or - string.find(line, "_ISwupper", 1, true)) then + if not (string.find(line, "(^)", 1, true) ~= nil + or string.find(line, "_ISwupper", 1, true) + or string.find(line, "msgpack_zone_push_finalizer") + or string.find(line, "msgpack_unpacker_reserve_buffer")) then result[#result + 1] = line end end @@ -103,6 +105,11 @@ local function cimport(...) -- request a sorted version of the new lines (same relative order as the -- original preprocessed file) and feed that to the LuaJIT ffi local new_lines = new_cdefs:to_table() + if os.getenv('NVIM_TEST_PRINT_CDEF') == '1' then + for lnum, line in ipairs(new_lines) do + print(lnum, line) + end + end ffi.cdef(table.concat(new_lines, "\n")) return libnvim @@ -133,6 +140,7 @@ do local time = cimport('./src/nvim/os/time.h') time.time_init() main.early_init() + main.event_init() end -- C constants. diff --git a/test/unit/mbyte_spec.lua b/test/unit/mbyte_spec.lua new file mode 100644 index 0000000000..e1b401c76d --- /dev/null +++ b/test/unit/mbyte_spec.lua @@ -0,0 +1,277 @@ +local helpers = require("test.unit.helpers") + +local ffi = helpers.ffi +local eq = helpers.eq + +local globals = helpers.cimport("./src/nvim/globals.h") +local mbyte = helpers.cimport("./src/nvim/mbyte.h") + +describe('mbyte', function() + + -- Array for composing characters + local intp = ffi.typeof('int[?]') + local function to_intp() + -- how to get MAX_MCO from globals.h? + return intp(7, 1) + end + + -- Convert from bytes to string + local function to_string(bytes) + s = {} + for i = 1, #bytes do + s[i] = string.char(bytes[i]) + end + return table.concat(s) + end + + before_each(function() + end) + + it('utf_ptr2char', function() + -- For strings with length 1 the first byte is returned. + for c = 0, 255 do + eq(c, mbyte.utf_ptr2char(to_string({c, 0}))) + end + + -- Some ill formed byte sequences that should not be recognized as UTF-8 + -- First byte: 0xc0 or 0xc1 + -- Second byte: 0x80 .. 0xbf + --eq(0x00c0, mbyte.utf_ptr2char(to_string({0xc0, 0x80}))) + --eq(0x00c1, mbyte.utf_ptr2char(to_string({0xc1, 0xbf}))) + -- + -- Sequences with more than four bytes + end) + + + describe('utfc_ptr2char_len', function() + + it('1-byte sequences', function() + local pcc = to_intp() + for c = 0, 255 do + eq(c, mbyte.utfc_ptr2char_len(to_string({c}), pcc, 1)) + eq(0, pcc[0]) + end + end) + + it('2-byte sequences', function() + local pcc = to_intp() + -- No combining characters + eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0x7f}), pcc, 2)) + eq(0, pcc[0]) + -- No combining characters + local pcc = to_intp() + eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0x80}), pcc, 2)) + eq(0, pcc[0]) + + -- No UTF-8 sequence + local pcc = to_intp() + eq(0x00c2, mbyte.utfc_ptr2char_len(to_string({0xc2, 0x7f}), pcc, 2)) + eq(0, pcc[0]) + -- One UTF-8 character + local pcc = to_intp() + eq(0x0080, mbyte.utfc_ptr2char_len(to_string({0xc2, 0x80}), pcc, 2)) + eq(0, pcc[0]) + -- No UTF-8 sequence + local pcc = to_intp() + eq(0x00c2, mbyte.utfc_ptr2char_len(to_string({0xc2, 0xc0}), pcc, 2)) + eq(0, pcc[0]) + end) + + it('3-byte sequences', function() + local pcc = to_intp() + + -- No second UTF-8 character + eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0x80, 0x80}), pcc, 3)) + eq(0, pcc[0]) + -- No combining character + local pcc = to_intp() + eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0xc2, 0x80}), pcc, 3)) + eq(0, pcc[0]) + + -- Combining character is U+0300 + local pcc = to_intp() + eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0xcc, 0x80}), pcc, 3)) + eq(0x0300, pcc[0]) + eq(0x0000, pcc[1]) + + -- No UTF-8 sequence + local pcc = to_intp() + eq(0x00c2, mbyte.utfc_ptr2char_len(to_string({0xc2, 0x7f, 0xcc}), pcc, 3)) + eq(0, pcc[0]) + -- Incomplete combining character + local pcc = to_intp() + eq(0x0080, mbyte.utfc_ptr2char_len(to_string({0xc2, 0x80, 0xcc}), pcc, 3)) + eq(0, pcc[0]) + + -- One UTF-8 character + local pcc = to_intp() + eq(0x20d0, mbyte.utfc_ptr2char_len(to_string({0xe2, 0x83, 0x90}), pcc, 3)) + eq(0, pcc[0]) + end) + + it('4-byte sequences', function() + local pcc = to_intp() + + -- No following combining character + eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0x7f, 0xcc, 0x80}), pcc, 4)) + eq(0, pcc[0]) + -- No second UTF-8 character + local pcc = to_intp() + eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0xc2, 0xcc, 0x80}), pcc, 4)) + eq(0, pcc[0]) + + -- Combining character U+0300 + local pcc = to_intp() + eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0xcc, 0x80, 0xcc}), pcc, 4)) + eq(0x0300, pcc[0]) + eq(0x0000, pcc[1]) + + -- No UTF-8 sequence + local pcc = to_intp() + eq(0x00c2, mbyte.utfc_ptr2char_len(to_string({0xc2, 0x7f, 0xcc, 0x80}), pcc, 4)) + eq(0, pcc[0]) + -- No following UTF-8 character + local pcc = to_intp() + eq(0x0080, mbyte.utfc_ptr2char_len(to_string({0xc2, 0x80, 0xcc, 0xcc}), pcc, 4)) + eq(0, pcc[0]) + -- Combining character U+0301 + local pcc = to_intp() + eq(0x0080, mbyte.utfc_ptr2char_len(to_string({0xc2, 0x80, 0xcc, 0x81}), pcc, 4)) + eq(0x0301, pcc[0]) + eq(0x0000, pcc[1]) + + -- One UTF-8 character + local pcc = to_intp() + eq(0x100000, mbyte.utfc_ptr2char_len(to_string({0xf4, 0x80, 0x80, 0x80}), pcc, 4)) + eq(0, pcc[0]) + end) + + it('5+-byte sequences', function() + local pcc = to_intp() + + -- No following combining character + eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0x7f, 0xcc, 0x80, 0x80}), pcc, 5)) + eq(0, pcc[0]) + -- No second UTF-8 character + local pcc = to_intp() + eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0xc2, 0xcc, 0x80, 0x80}), pcc, 5)) + eq(0, pcc[0]) + + -- Combining character U+0300 + local pcc = to_intp() + eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0xcc, 0x80, 0xcc}), pcc, 5)) + eq(0x0300, pcc[0]) + eq(0x0000, pcc[1]) + + -- Combining characters U+0300 and U+0301 + local pcc = to_intp() + eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0xcc, 0x80, 0xcc, 0x81}), pcc, 5)) + eq(0x0300, pcc[0]) + eq(0x0301, pcc[1]) + eq(0x0000, pcc[2]) + -- Combining characters U+0300, U+0301, U+0302 + local pcc = to_intp() + eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0xcc, 0x80, 0xcc, 0x81, 0xcc, 0x82}), pcc, 7)) + eq(0x0300, pcc[0]) + eq(0x0301, pcc[1]) + eq(0x0302, pcc[2]) + eq(0x0000, pcc[3]) + -- Combining characters U+0300, U+0301, U+0302, U+0303 + local pcc = to_intp() + eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0xcc, 0x80, 0xcc, 0x81, 0xcc, 0x82, 0xcc, 0x83}), pcc, 9)) + eq(0x0300, pcc[0]) + eq(0x0301, pcc[1]) + eq(0x0302, pcc[2]) + eq(0x0303, pcc[3]) + eq(0x0000, pcc[4]) + -- Combining characters U+0300, U+0301, U+0302, U+0303, U+0304 + local pcc = to_intp() + eq(0x007f, mbyte.utfc_ptr2char_len(to_string( + {0x7f, 0xcc, 0x80, 0xcc, 0x81, 0xcc, 0x82, 0xcc, 0x83, 0xcc, 0x84}), pcc, 11)) + eq(0x0300, pcc[0]) + eq(0x0301, pcc[1]) + eq(0x0302, pcc[2]) + eq(0x0303, pcc[3]) + eq(0x0304, pcc[4]) + eq(0x0000, pcc[5]) + -- Combining characters U+0300, U+0301, U+0302, U+0303, U+0304, + -- U+0305 + local pcc = to_intp() + eq(0x007f, mbyte.utfc_ptr2char_len(to_string( + {0x7f, 0xcc, 0x80, 0xcc, 0x81, 0xcc, 0x82, 0xcc, 0x83, 0xcc, 0x84, 0xcc, 0x85}), pcc, 13)) + eq(0x0300, pcc[0]) + eq(0x0301, pcc[1]) + eq(0x0302, pcc[2]) + eq(0x0303, pcc[3]) + eq(0x0304, pcc[4]) + eq(0x0305, pcc[5]) + eq(1, pcc[6]) + + -- Combining characters U+0300, U+0301, U+0302, U+0303, U+0304, + -- U+0305, U+0306, but only save six (= MAX_MCO). + local pcc = to_intp() + eq(0x007f, mbyte.utfc_ptr2char_len(to_string( + {0x7f, 0xcc, 0x80, 0xcc, 0x81, 0xcc, 0x82, 0xcc, 0x83, 0xcc, 0x84, 0xcc, 0x85, 0xcc, 0x86}), pcc, 15)) + eq(0x0300, pcc[0]) + eq(0x0301, pcc[1]) + eq(0x0302, pcc[2]) + eq(0x0303, pcc[3]) + eq(0x0304, pcc[4]) + eq(0x0305, pcc[5]) + eq(0x0001, pcc[6]) + + -- Only three following combining characters U+0300, U+0301, U+0302 + local pcc = to_intp() + eq(0x007f, mbyte.utfc_ptr2char_len(to_string( + {0x7f, 0xcc, 0x80, 0xcc, 0x81, 0xcc, 0x82, 0xc2, 0x80, 0xcc, 0x84, 0xcc, 0x85}), pcc, 13)) + eq(0x0300, pcc[0]) + eq(0x0301, pcc[1]) + eq(0x0302, pcc[2]) + eq(0x0000, pcc[3]) + + + -- No UTF-8 sequence + local pcc = to_intp() + eq(0x00c2, mbyte.utfc_ptr2char_len(to_string({0xc2, 0x7f, 0xcc, 0x80, 0x80}), pcc, 5)) + eq(0, pcc[0]) + -- No following UTF-8 character + local pcc = to_intp() + eq(0x0080, mbyte.utfc_ptr2char_len(to_string({0xc2, 0x80, 0xcc, 0xcc, 0x80}), pcc, 5)) + eq(0, pcc[0]) + -- Combining character U+0301 + local pcc = to_intp() + eq(0x0080, mbyte.utfc_ptr2char_len(to_string({0xc2, 0x80, 0xcc, 0x81, 0x7f}), pcc, 5)) + eq(0x0301, pcc[0]) + eq(0x0000, pcc[1]) + -- Combining character U+0301 + local pcc = to_intp() + eq(0x0080, mbyte.utfc_ptr2char_len(to_string({0xc2, 0x80, 0xcc, 0x81, 0xcc}), pcc, 5)) + eq(0x0301, pcc[0]) + eq(0x0000, pcc[1]) + + -- One UTF-8 character + local pcc = to_intp() + eq(0x100000, mbyte.utfc_ptr2char_len(to_string({0xf4, 0x80, 0x80, 0x80, 0x7f}), pcc, 5)) + eq(0, pcc[0]) + + -- One UTF-8 character + local pcc = to_intp() + eq(0x100000, mbyte.utfc_ptr2char_len(to_string({0xf4, 0x80, 0x80, 0x80, 0x80}), pcc, 5)) + eq(0, pcc[0]) + -- One UTF-8 character + local pcc = to_intp() + eq(0x100000, mbyte.utfc_ptr2char_len(to_string({0xf4, 0x80, 0x80, 0x80, 0xcc}), pcc, 5)) + eq(0, pcc[0]) + + -- Combining characters U+1AB0 and U+0301 + local pcc = to_intp() + eq(0x100000, mbyte.utfc_ptr2char_len(to_string( + {0xf4, 0x80, 0x80, 0x80, 0xe1, 0xaa, 0xb0, 0xcc, 0x81}), pcc, 9)) + eq(0x1ab0, pcc[0]) + eq(0x0301, pcc[1]) + eq(0x0000, pcc[2]) + end) + + end) + +end) diff --git a/test/unit/os/shell_spec.lua b/test/unit/os/shell_spec.lua index 6d1a9f3589..93103e4e8c 100644 --- a/test/unit/os/shell_spec.lua +++ b/test/unit/os/shell_spec.lua @@ -11,7 +11,7 @@ if allowed_os[jit.os] ~= true then end local helpers = require('test.unit.helpers') -local shell = helpers.cimport( +local cimported = helpers.cimport( './src/nvim/os/shell.h', './src/nvim/option_defs.h', './src/nvim/main.h', @@ -25,18 +25,17 @@ local NULL = ffi.cast('void *', 0) describe('shell functions', function() setup(function() - shell.event_init() -- os_system() can't work when the p_sh and p_shcf variables are unset - shell.p_sh = to_cstr('/bin/bash') - shell.p_shcf = to_cstr('-c') + cimported.p_sh = to_cstr('/bin/bash') + cimported.p_shcf = to_cstr('-c') end) teardown(function() - shell.event_teardown() + cimported.event_teardown() end) local function shell_build_argv(cmd, extra_args) - local res = shell.shell_build_argv( + local res = cimported.shell_build_argv( cmd and to_cstr(cmd), extra_args and to_cstr(extra_args)) local argc = 0 @@ -45,10 +44,10 @@ describe('shell functions', function() -- crash. while res[argc] ~= nil do ret[#ret + 1] = ffi.string(res[argc]) - shell.xfree(res[argc]) + cimported.xfree(res[argc]) argc = argc + 1 end - shell.xfree(res) + cimported.xfree(res) return ret end @@ -59,8 +58,8 @@ describe('shell functions', function() local nread = ffi.new('size_t[1]') local argv = ffi.cast('char**', - shell.shell_build_argv(to_cstr(cmd), nil)) - local status = shell.os_system(argv, input_or, input_len, output, nread) + cimported.shell_build_argv(to_cstr(cmd), nil)) + local status = cimported.os_system(argv, input_or, input_len, output, nread) return status, intern(output[0], nread[0]) end @@ -97,13 +96,13 @@ describe('shell functions', function() local saved_opts = {} setup(function() - saved_opts.p_sh = shell.p_sh - saved_opts.p_shcf = shell.p_shcf + saved_opts.p_sh = cimported.p_sh + saved_opts.p_shcf = cimported.p_shcf end) teardown(function() - shell.p_sh = saved_opts.p_sh - shell.p_shcf = saved_opts.p_shcf + cimported.p_sh = saved_opts.p_sh + cimported.p_shcf = saved_opts.p_shcf end) it('works with NULL arguments', function() @@ -123,8 +122,8 @@ describe('shell functions', function() end) it('splits and unquotes &shell and &shellcmdflag', function() - shell.p_sh = to_cstr('/Program" "Files/zsh -f') - shell.p_shcf = to_cstr('-x -o "sh word split" "-"c') + cimported.p_sh = to_cstr('/Program" "Files/zsh -f') + cimported.p_shcf = to_cstr('-x -o "sh word split" "-"c') eq({'/Program Files/zsh', '-f', 'ghi jkl', '-x', '-o', 'sh word split', diff --git a/test/unit/tempfile_spec.lua b/test/unit/tempfile_spec.lua index e558ff04c8..b3e84db132 100644 --- a/test/unit/tempfile_spec.lua +++ b/test/unit/tempfile_spec.lua @@ -2,7 +2,7 @@ local lfs = require 'lfs' local helpers = require 'test.unit.helpers' local os = helpers.cimport './src/nvim/os/os.h' -local tempfile = helpers.cimport './src/nvim/tempfile.h' +local tempfile = helpers.cimport './src/nvim/fileio.h' describe('tempfile related functions', function() after_each(function() diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index 08e76ceef0..f584815499 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -21,6 +21,10 @@ option(USE_BUNDLED_LIBUV "Use the bundled libuv." ${USE_BUNDLED}) option(USE_BUNDLED_MSGPACK "Use the bundled msgpack." ${USE_BUNDLED}) option(USE_BUNDLED_LUAJIT "Use the bundled version of luajit." ${USE_BUNDLED}) option(USE_BUNDLED_LUAROCKS "Use the bundled version of luarocks." ${USE_BUNDLED}) +option(USE_BUNDLED_LUV "Use the bundled version of luv." ${USE_BUNDLED}) +#XXX(tarruda): Lua is only used for debugging the functional test client, no +# build it unless explicitly requested +option(USE_BUNDLED_LUA "Use the bundled version of lua." OFF) option(USE_EXISTING_SRC_DIR "Skip download of deps sources in case of existing source directory." OFF) @@ -80,6 +84,9 @@ set(MSGPACK_SHA256 afda64ca445203bb7092372b822bae8b2539fdcebbfc3f753f393628c2bcf set(LUAJIT_URL https://github.com/neovim/deps/raw/master/opt/LuaJIT-2.0.4.tar.gz) set(LUAJIT_SHA256 620fa4eb12375021bef6e4f237cbd2dd5d49e56beb414bee052c746beef1807d) +set(LUA_URL https://github.com/lua/lua/archive/5.1.5.tar.gz) +set(LUA_SHA256 1cd642c4c39778306a14e62ccddace5c7a4fb2257b0b06f43bc81cf305c7415f) + set(LUAROCKS_URL https://github.com/keplerproject/luarocks/archive/5d8a16526573b36d5b22aa74866120c998466697.tar.gz) set(LUAROCKS_SHA256 cae709111c5701235770047dfd7169f66b82ae1c7b9b79207f9df0afb722bfd9) @@ -89,11 +96,14 @@ set(UNIBILIUM_SHA256 623af1099515e673abfd3cae5f2fa808a09ca55dda1c65a7b5c9424eb30 set(LIBTERMKEY_URL http://www.leonerd.org.uk/code/libtermkey/libtermkey-0.18.tar.gz) set(LIBTERMKEY_SHA256 239746de41c845af52bb3c14055558f743292dd6c24ac26c2d6567a5a6093926) -set(LIBVTERM_URL https://github.com/neovim/libvterm/archive/1b745d29d45623aa8d22a7b9288c7b0e331c7088.tar.gz) -set(LIBVTERM_SHA256 3fc75908256c0d158d6c2a32d39f34e86bfd26364f5404b7d9c03bb70cdc3611) +set(LIBVTERM_URL https://github.com/neovim/libvterm/archive/a9c7c6fd20fa35e0ad3e0e98901ca12dfca9c25c.tar.gz) +set(LIBVTERM_SHA256 1a4272be91d9614dc183a503786df83b6584e4afaab7feaaa5409f841afbd796) set(JEMALLOC_URL https://github.com/jemalloc/jemalloc/releases/download/4.0.2/jemalloc-4.0.2.tar.bz2) set(JEMALLOC_SHA256 0d8a9c8a98adb6983e0ccb521d45d9db1656ef3e71d0b14fb333f2c8138f4611) + +set(LUV_URL https://github.com/luvit/luv/archive/146f1ce4c08c3b67f604c9ee1e124b1cf5c15cf3.tar.gz) +set(LUV_SHA256 3d537f8eb9fa5adb146a083eae22af886aee324ec268e2aa0fa75f2f1c52ca7a) if(USE_BUNDLED_UNIBILIUM) include(BuildUnibilium) @@ -119,6 +129,10 @@ if(USE_BUNDLED_LUAJIT) include(BuildLuajit) endif() +if(USE_BUNDLED_LUA AND NOT CMAKE_CROSSCOMPILING) + include(BuildLua) +endif() + if(USE_BUNDLED_LUAROCKS) include(BuildLuarocks) endif() @@ -127,6 +141,10 @@ if(USE_BUNDLED_JEMALLOC) include(BuildJeMalloc) endif() +if(USE_BUNDLED_LUV) + include(BuildLuv) +endif() + add_custom_target(clean-shared-libraries COMMAND ${CMAKE_COMMAND} -DREMOVE_FILE_GLOB=${DEPS_INSTALL_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}*${CMAKE_SHARED_LIBRARY_SUFFIX}* diff --git a/third-party/cmake/BuildLua.cmake b/third-party/cmake/BuildLua.cmake new file mode 100644 index 0000000000..1c5e2a186c --- /dev/null +++ b/third-party/cmake/BuildLua.cmake @@ -0,0 +1,85 @@ +include(CMakeParseArguments) + +# BuildLua(CONFIGURE_COMMAND ... BUILD_COMMAND ... INSTALL_COMMAND ...) +# Reusable function to build lua, wraps ExternalProject_Add. +# Failing to pass a command argument will result in no command being run +function(BuildLua) + cmake_parse_arguments(_lua + "" + "" + "CONFIGURE_COMMAND;BUILD_COMMAND;INSTALL_COMMAND" + ${ARGN}) + + if(NOT _lua_CONFIGURE_COMMAND AND NOT _lua_BUILD_COMMAND + AND NOT _lua_INSTALL_COMMAND) + message(FATAL_ERROR "Must pass at least one of CONFIGURE_COMMAND, BUILD_COMMAND, INSTALL_COMMAND") + endif() + + ExternalProject_Add(lua + PREFIX ${DEPS_BUILD_DIR} + URL ${LUA_URL} + DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/lua + DOWNLOAD_COMMAND ${CMAKE_COMMAND} + -DPREFIX=${DEPS_BUILD_DIR} + -DDOWNLOAD_DIR=${DEPS_DOWNLOAD_DIR}/lua + -DURL=${LUA_URL} + -DEXPECTED_SHA256=${LUA_SHA256} + -DTARGET=lua + -DUSE_EXISTING_SRC_DIR=${USE_EXISTING_SRC_DIR} + -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake + CONFIGURE_COMMAND "${_lua_CONFIGURE_COMMAND}" + BUILD_IN_SOURCE 1 + BUILD_COMMAND "${_lua_BUILD_COMMAND}" + INSTALL_COMMAND "${_lua_INSTALL_COMMAND}") +endfunction() + +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + set(LUA_TARGET linux) +elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + set(LUA_TARGET macosx) +elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") + set(LUA_TARGET freebsd) +elseif(CMAKE_SYSTEM_NAME MATCHES "BSD") + set(CMAKE_LUA_TARGET bsd) +elseif(SYSTEM_NAME MATCHES "^MINGW") + set(CMAKE_LUA_TARGET mingw) +else() + if(UNIX) + set(LUA_TARGET posix) + else() + set(LUA_TARGET generic) + endif() +endif() + +set(LUA_CONFIGURE_COMMAND + sed -e "/^CC/s@gcc@${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}@" + -e "/^CFLAGS/s@-O2@-g3@" + -e "s@-lreadline@@g" + -e "s@-lhistory@@g" + -e "s@-lncurses@@g" + -i ${DEPS_BUILD_DIR}/src/lua/src/Makefile && + sed -e "/#define LUA_USE_READLINE/d" + -i ${DEPS_BUILD_DIR}/src/lua/src/luaconf.h) +set(LUA_BUILD_COMMAND + ${MAKE_PRG} ${LUA_TARGET}) +set(LUA_INSTALL_COMMAND + ${MAKE_PRG} INSTALL_TOP=${DEPS_INSTALL_DIR} install) + +message(STATUS "Lua target is ${LUA_TARGET}") + +BuildLua(CONFIGURE_COMMAND ${LUA_CONFIGURE_COMMAND} + BUILD_COMMAND ${LUA_BUILD_COMMAND} + INSTALL_COMMAND ${LUA_INSTALL_COMMAND}) +list(APPEND THIRD_PARTY_DEPS lua) +add_dependencies(lua busted) + +set(BUSTED ${DEPS_INSTALL_DIR}/bin/busted) +set(BUSTED_LUA ${BUSTED}-lua) + +add_custom_command(OUTPUT ${BUSTED_LUA} + COMMAND sed -e 's/^exec/exec $$LUA_DEBUGGER/' -e 's/jit//g' < ${BUSTED} > ${BUSTED_LUA} && chmod +x ${BUSTED_LUA} + DEPENDS lua) +add_custom_target(busted-lua + DEPENDS ${DEPS_INSTALL_DIR}/bin/busted-lua) + +list(APPEND THIRD_PARTY_DEPS busted-lua) diff --git a/third-party/cmake/BuildLuarocks.cmake b/third-party/cmake/BuildLuarocks.cmake index a6126af789..1662f89b24 100644 --- a/third-party/cmake/BuildLuarocks.cmake +++ b/third-party/cmake/BuildLuarocks.cmake @@ -89,25 +89,26 @@ list(APPEND THIRD_PARTY_DEPS luarocks) if(USE_BUNDLED_LUAJIT) add_dependencies(luarocks luajit) + if(MINGW AND CMAKE_CROSSCOMPILING) + add_dependencies(luarocks luajit_host) + endif() endif() # Each target depends on the previous module, this serializes all calls to # luarocks since it is unhappy to be called in parallel. -add_custom_command(OUTPUT ${HOSTDEPS_LIB_DIR}/luarocks/rocks/lua-messagepack +add_custom_command(OUTPUT ${HOSTDEPS_LIB_DIR}/luarocks/rocks/mpack COMMAND ${LUAROCKS_BINARY} - ARGS build lua-messagepack ${LUAROCKS_BUILDARGS} + ARGS build mpack ${LUAROCKS_BUILDARGS} DEPENDS luarocks) -add_custom_target(lua-messagepack - DEPENDS ${HOSTDEPS_LIB_DIR}/luarocks/rocks/lua-messagepack) -list(APPEND THIRD_PARTY_DEPS lua-messagepack) +add_custom_target(mpack + DEPENDS ${HOSTDEPS_LIB_DIR}/luarocks/rocks/mpack) +list(APPEND THIRD_PARTY_DEPS mpack) -# Like before, depend on lua-messagepack to ensure serialization of install -# commands add_custom_command(OUTPUT ${HOSTDEPS_LIB_DIR}/luarocks/rocks/lpeg COMMAND ${LUAROCKS_BINARY} ARGS build lpeg ${LUAROCKS_BUILDARGS} - DEPENDS lua-messagepack) + DEPENDS mpack) add_custom_target(lpeg DEPENDS ${HOSTDEPS_LIB_DIR}/luarocks/rocks/lpeg) @@ -117,7 +118,7 @@ if(USE_BUNDLED_BUSTED) add_custom_command(OUTPUT ${HOSTDEPS_BIN_DIR}/busted COMMAND ${LUAROCKS_BINARY} ARGS build https://raw.githubusercontent.com/Olivine-Labs/busted/v2.0.rc11-0/busted-2.0.rc11-0.rockspec ${LUAROCKS_BUILDARGS} - DEPENDS luarocks) + DEPENDS lpeg) add_custom_target(busted DEPENDS ${HOSTDEPS_BIN_DIR}/busted) @@ -128,10 +129,22 @@ if(USE_BUNDLED_BUSTED) add_custom_target(luacheck DEPENDS ${HOSTDEPS_BIN_DIR}/luacheck) + set(LUV_DEPS luacheck luv-static) + if(MINGW AND CMAKE_CROSSCOMPILING) + set(LUV_DEPS ${LUV_DEPS} libuv_host) + endif() + add_custom_command(OUTPUT ${HOSTDEPS_LIB_DIR}/luarocks/rocks/luv + COMMAND ${LUAROCKS_BINARY} + ARGS make ${LUAROCKS_BUILDARGS} LIBUV_DIR=${HOSTDEPS_INSTALL_DIR} CFLAGS='-O0 -g3 -fPIC' + WORKING_DIRECTORY ${DEPS_BUILD_DIR}/src/luv + DEPENDS ${LUV_DEPS}) + add_custom_target(luv + DEPENDS ${HOSTDEPS_LIB_DIR}/luarocks/rocks/luv) + add_custom_command(OUTPUT ${HOSTDEPS_LIB_DIR}/luarocks/rocks/nvim-client COMMAND ${LUAROCKS_BINARY} - ARGS build https://raw.githubusercontent.com/neovim/lua-client/0.0.1-14/nvim-client-0.0.1-14.rockspec ${LUAROCKS_BUILDARGS} LIBUV_DIR=${HOSTDEPS_INSTALL_DIR} - DEPENDS luacheck libuv) + ARGS build https://raw.githubusercontent.com/neovim/lua-client/0.0.1-24/nvim-client-0.0.1-24.rockspec ${LUAROCKS_BUILDARGS} + DEPENDS luv) add_custom_target(nvim-client DEPENDS ${HOSTDEPS_LIB_DIR}/luarocks/rocks/nvim-client) diff --git a/third-party/cmake/BuildLuv.cmake b/third-party/cmake/BuildLuv.cmake new file mode 100644 index 0000000000..3060590bce --- /dev/null +++ b/third-party/cmake/BuildLuv.cmake @@ -0,0 +1,90 @@ +include(CMakeParseArguments) + +# BuildLuv(PATCH_COMMAND ... CONFIGURE_COMMAND ... BUILD_COMMAND ... INSTALL_COMMAND ...) +# Reusable function to build luv, wraps ExternalProject_Add. +# Failing to pass a command argument will result in no command being run +function(BuildLuv) + cmake_parse_arguments(_luv + "" + "" + "PATCH_COMMAND;CONFIGURE_COMMAND;BUILD_COMMAND;INSTALL_COMMAND" + ${ARGN}) + + if(NOT _luv_CONFIGURE_COMMAND AND NOT _luv_BUILD_COMMAND + AND NOT _luv_INSTALL_COMMAND) + message(FATAL_ERROR "Must pass at least one of CONFIGURE_COMMAND, BUILD_COMMAND, INSTALL_COMMAND") + endif() + + ExternalProject_Add(luv-static + PREFIX ${DEPS_BUILD_DIR} + URL ${LUV_URL} + DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/luv + DOWNLOAD_COMMAND ${CMAKE_COMMAND} + -DPREFIX=${DEPS_BUILD_DIR} + -DDOWNLOAD_DIR=${DEPS_DOWNLOAD_DIR}/luv + -DURL=${LUV_URL} + -DEXPECTED_SHA256=${LUV_SHA256} + -DTARGET=luv + -DUSE_EXISTING_SRC_DIR=${USE_EXISTING_SRC_DIR} + -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake + PATCH_COMMAND "${_luv_PATCH_COMMAND}" + CONFIGURE_COMMAND "${_luv_CONFIGURE_COMMAND}" + BUILD_COMMAND "${_luv_BUILD_COMMAND}" + INSTALL_COMMAND "${_luv_INSTALL_COMMAND}") +endfunction() + +set(LUV_SRC_DIR ${DEPS_BUILD_DIR}/src/luv) +set(LUV_INCLUDE_FLAGS + "-I${DEPS_INSTALL_DIR}/include -I${DEPS_INSTALL_DIR}/include/luajit-2.0") + +set(LUV_PATCH_COMMAND + ${CMAKE_COMMAND} -DLUV_SRC_DIR=${LUV_SRC_DIR} + -P ${PROJECT_SOURCE_DIR}/cmake/PatchLuv.cmake) + +set(LUV_CONFIGURE_COMMAND_COMMON + ${CMAKE_COMMAND} ${LUV_SRC_DIR} + -DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR} + -DLUA_BUILD_TYPE=System + -DWITH_SHARED_LIBUV=ON + -DBUILD_SHARED_LIBS=OFF + -DBUILD_MODULE=OFF) + +if(MINGW AND CMAKE_CROSSCOMPILING) + get_filename_component(TOOLCHAIN ${CMAKE_TOOLCHAIN_FILE} REALPATH) + set(LUV_CONFIGURE_COMMAND + ${LUV_CONFIGURE_COMMAND_COMMON} + # Pass toolchain + -DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN} + "-DCMAKE_C_FLAGS:STRING=${LUV_INCLUDE_FLAGS} -D_WIN32_WINNT=0x0600" + # Hack to avoid -rdynamic in Mingw + -DCMAKE_SHARED_LIBRARY_LINK_C_FLAGS="") +elseif(MSVC) + set(LUV_CONFIGURE_COMMAND + ${LUV_CONFIGURE_COMMAND_COMMON} + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + # Same as Unix without fPIC + "-DCMAKE_C_FLAGS:STRING=${CMAKE_C_COMPILER_ARG1} ${LUV_INCLUDE_FLAGS}" + # Make sure we use the same generator, otherwise we may + # accidentaly end up using different MSVC runtimes + -DCMAKE_GENERATOR=${CMAKE_GENERATOR} + # Use static runtime + -DCMAKE_C_FLAGS_DEBUG="-MTd" + -DCMAKE_C_FLAGS_RELEASE="-MT") +else() + set(LUV_CONFIGURE_COMMAND + ${LUV_CONFIGURE_COMMAND_COMMON} + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + "-DCMAKE_C_FLAGS:STRING=${CMAKE_C_COMPILER_ARG1} ${LUV_INCLUDE_FLAGS} -fPIC") +endif() + +set(LUV_BUILD_COMMAND ${CMAKE_COMMAND} --build .) +set(LUV_INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install) + +BuildLuv(PATCH_COMMAND ${LUV_PATCH_COMMAND} + CONFIGURE_COMMAND ${LUV_CONFIGURE_COMMAND} + BUILD_COMMAND ${LUV_BUILD_COMMAND} + INSTALL_COMMAND ${LUV_INSTALL_COMMAND}) + +list(APPEND THIRD_PARTY_DEPS luv-static) +add_dependencies(luv-static luajit) +add_dependencies(luv-static libuv) diff --git a/third-party/cmake/PatchLuv.cmake b/third-party/cmake/PatchLuv.cmake new file mode 100644 index 0000000000..96595a2f30 --- /dev/null +++ b/third-party/cmake/PatchLuv.cmake @@ -0,0 +1,29 @@ +# replace luv default rockspec with the alternate one under the "rockspecs" +# directory +file(GLOB LUV_ROCKSPEC RELATIVE ${LUV_SRC_DIR} ${LUV_SRC_DIR}/*.rockspec) +file(RENAME ${LUV_SRC_DIR}/rockspecs/${LUV_ROCKSPEC} ${LUV_SRC_DIR}/${LUV_ROCKSPEC}) + +# Some versions of mingw are missing defines required by luv dns module, add +# them now +set(LUV_SRC_DNS_C_DEFS +"#ifndef AI_NUMERICSERV +# define AI_NUMERICSERV 0x0008 +#endif +#ifndef AI_ALL +# define AI_ALL 0x00000100 +#endif +#ifndef AI_ADDRCONFIG +# define AI_ADDRCONFIG 0x00000400 +#endif +#ifndef AI_V4MAPPED +# define AI_V4MAPPED 0x00000800 +#endif") + +file(READ ${LUV_SRC_DIR}/src/dns.c LUV_SRC_DNS_C) +string(REPLACE + "\n#include <netdb.h>" + "\n#include <netdb.h>\n#else\n${LUV_SRC_DNS_C_DEFS}" + LUV_SRC_DNS_C_PATCHED + "${LUV_SRC_DNS_C}") +file(WRITE ${LUV_SRC_DIR}/src/dns.c "${LUV_SRC_DNS_C_PATCHED}") + |