diff options
113 files changed, 4580 insertions, 2329 deletions
diff --git a/.gitignore b/.gitignore index ed452c03a9..23c8fd1957 100644 --- a/.gitignore +++ b/.gitignore @@ -68,4 +68,4 @@ local.mk /runtime/doc/errors.log # clint errors, generated by `make lint` -errors.json +/errors.json diff --git a/CMakeLists.txt b/CMakeLists.txt index 74130debf3..6c3f4d927d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,17 +40,17 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") set(USE_FNAME_CASE TRUE) endif() -# Set available build types for CMake GUIs. -# A different build type can still be set by -DCMAKE_BUILD_TYPE=... -set_property(CACHE CMAKE_BUILD_TYPE PROPERTY - STRINGS "Debug" "Dev" "Release" "MinSizeRel" "RelWithDebInfo") - # Set default build type. if(NOT CMAKE_BUILD_TYPE) message(STATUS "CMAKE_BUILD_TYPE not given, defaulting to 'Dev'.") set(CMAKE_BUILD_TYPE "Dev" CACHE STRING "Choose the type of build." FORCE) endif() +# Set available build types for CMake GUIs. +# A different build type can still be set by -DCMAKE_BUILD_TYPE=... +set_property(CACHE CMAKE_BUILD_TYPE PROPERTY + STRINGS "Debug" "Dev" "Release" "MinSizeRel" "RelWithDebInfo") + # If not in a git repo (e.g., a tarball) these tokens define the complete # version string, else it is combined with the result of `git describe`. set(NVIM_VERSION_MAJOR 0) @@ -426,7 +426,11 @@ if(BUSTED_PRG) if(POLICY CMP0026) cmake_policy(SET CMP0026 OLD) endif() - get_target_property(TEST_LIBNVIM_PATH nvim-test LOCATION) + if(CMAKE_GENERATOR MATCHES "Visual Studio") + set(TEST_LIBNVIM_PATH ${CMAKE_BINARY_DIR}/lib/nvim-test.dll) + else() + get_target_property(TEST_LIBNVIM_PATH nvim-test LOCATION) + endif() configure_file( test/config/paths.lua.in diff --git a/cmake/FindMsgpack.cmake b/cmake/FindMsgpack.cmake index 7d88137915..60afc88839 100644 --- a/cmake/FindMsgpack.cmake +++ b/cmake/FindMsgpack.cmake @@ -7,7 +7,7 @@ if(NOT MSGPACK_USE_BUNDLED) find_package(PkgConfig) if (PKG_CONFIG_FOUND) - pkg_check_modules(PC_MSGPACK QUIET msgpack) + pkg_search_module(PC_MSGPACK QUIET msgpackc>=1.0 msgpack>=1.0) endif() else() set(PC_MSGPACK_INCLUDEDIR) @@ -23,13 +23,14 @@ find_path(MSGPACK_INCLUDE_DIR msgpack.h HINTS ${PC_MSGPACK_INCLUDEDIR} ${PC_MSGPACK_INCLUDE_DIRS} ${LIMIT_SEARCH}) -# If we're asked to use static linkage, add libmsgpack.a as a preferred library name. +# If we're asked to use static linkage, add libmsgpack{,c}.a as a preferred library name. if(MSGPACK_USE_STATIC) list(APPEND MSGPACK_NAMES + "${CMAKE_STATIC_LIBRARY_PREFIX}msgpackc${CMAKE_STATIC_LIBRARY_SUFFIX}" "${CMAKE_STATIC_LIBRARY_PREFIX}msgpack${CMAKE_STATIC_LIBRARY_SUFFIX}") endif() -list(APPEND MSGPACK_NAMES msgpack) +list(APPEND MSGPACK_NAMES msgpackc msgpack) find_library(MSGPACK_LIBRARY NAMES ${MSGPACK_NAMES} HINTS ${PC_MSGPACK_LIBDIR} ${PC_MSGPACK_LIBRARY_DIRS} diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt index 1dcf7e4686..eaf06ba7f2 100644 --- a/config/CMakeLists.txt +++ b/config/CMakeLists.txt @@ -15,7 +15,6 @@ check_type_size("void *" SIZEOF_VOID_PTR) check_symbol_exists(_NSGetEnviron crt_externs.h HAVE__NSGETENVIRON) # Headers -check_include_files(fcntl.h HAVE_FCNTL_H) check_include_files(iconv.h HAVE_ICONV_H) check_include_files(langinfo.h HAVE_LANGINFO_H) check_include_files(locale.h HAVE_LOCALE_H) @@ -28,8 +27,6 @@ if(NOT HAVE_SYS_WAIT_H AND UNIX) endif() check_include_files(sys/utsname.h HAVE_SYS_UTSNAME_H) check_include_files(utime.h HAVE_UTIME_H) -check_include_files(unistd.h HAVE_UNISTD_H) -check_include_files(utime.h HAVE_UTIME_H) # Functions check_function_exists(fseeko HAVE_FSEEKO) diff --git a/config/config.h.in b/config/config.h.in index 84a90301ff..27705f8b38 100644 --- a/config/config.h.in +++ b/config/config.h.in @@ -13,7 +13,6 @@ #endif #cmakedefine HAVE__NSGETENVIRON -#cmakedefine HAVE_FCNTL_H #cmakedefine HAVE_FD_CLOEXEC #cmakedefine HAVE_FSEEKO #cmakedefine HAVE_GETPWENT @@ -40,7 +39,6 @@ #cmakedefine HAVE_STRNCASECMP #cmakedefine HAVE_SYS_UTSNAME_H #cmakedefine HAVE_SYS_WAIT_H -#cmakedefine HAVE_UNISTD_H #cmakedefine HAVE_UTIME #cmakedefine HAVE_UTIME_H #cmakedefine HAVE_UTIMES diff --git a/contrib/YouCompleteMe/ycm_extra_conf.py b/contrib/YouCompleteMe/ycm_extra_conf.py index 12ad080143..7c54677c8f 100644 --- a/contrib/YouCompleteMe/ycm_extra_conf.py +++ b/contrib/YouCompleteMe/ycm_extra_conf.py @@ -9,7 +9,7 @@ def DirectoryOfThisScript(): def GetDatabase(): compilation_database_folder = os.path.join(DirectoryOfThisScript(), - '..', '..', 'build') + '..', 'build') if os.path.exists(compilation_database_folder): return ycm_core.CompilationDatabase(compilation_database_folder) return None diff --git a/man/nvim.1 b/man/nvim.1 index f9c4e24d0b..7e8cd5b809 100644 --- a/man/nvim.1 +++ b/man/nvim.1 @@ -1,4 +1,4 @@ -.Dd November 11, 2015 +.Dd January 28, 2016 .Dt NVIM 1 .Os .Sh NAME @@ -373,8 +373,24 @@ Used to set the 'shell' option, which determines the shell used by the command. .It Ev NVIM_TUI_ENABLE_CURSOR_SHAPE If defined, change the cursor shape to a vertical bar while in insert mode. -Requires that the host terminal support the DECSCUSR CSI escape sequence. +Requires that the host terminal supports the DECSCUSR CSI escape sequence. Has no effect in GUIs. +.Pp +Depending on the terminal emulator, using this option with +.Nm +under +.Xr tmux 1 +might require adding the following to +.Pa ~/.tmux.conf : +.Bd -literal -offset indent +set -ga terminal-overrides ',*:Ss=\eE[%p1%d q:Se=\eE[2 q' +.Ed +.Pp +See +.Ic terminal-overrides +in the +.Xr tmux 1 +manual page for more information. .It Ev NVIM_TUI_ENABLE_TRUE_COLOR If defined, assume the host terminal supports 24 bit colors. Has no effect in GUIs. diff --git a/runtime/autoload/phpcomplete.vim b/runtime/autoload/phpcomplete.vim index dbc40fdf36..6dcddfd43e 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 Feb 28 +" Last Change: 2015 Apr 02 " " OPTIONS: " @@ -141,71 +141,80 @@ function! phpcomplete#CompletePHP(findstart, base) " {{{ if a:base != "" let context = substitute(context, '\s*[$a-zA-Z_0-9\x7f-\xff]*$', '', '') end + else + let context = '' end - let [current_namespace, imports] = phpcomplete#GetCurrentNameSpace(getline(0, line('.'))) + try + let winheight = winheight(0) + let winnr = winnr() - if context =~? '^use\s' || context ==? 'use' - return phpcomplete#CompleteUse(a:base) - endif + let [current_namespace, imports] = phpcomplete#GetCurrentNameSpace(getline(0, line('.'))) - if context =~ '\(->\|::\)$' - " {{{ - " Get name of the class - let classname = phpcomplete#GetClassName(line('.'), context, current_namespace, imports) - - " Get location of class definition, we have to iterate through all - if classname != '' - if classname =~ '\' - " split the last \ segment as a classname, everything else is the namespace - let classname_parts = split(classname, '\') - let namespace = join(classname_parts[0:-2], '\') - let classname = classname_parts[-1] - else - let namespace = '\' - endif - let classlocation = phpcomplete#GetClassLocation(classname, namespace) - else - let classlocation = '' + if context =~? '^use\s' || context ==? 'use' + return phpcomplete#CompleteUse(a:base) endif - if classlocation != '' - if classlocation == 'VIMPHP_BUILTINOBJECT' && has_key(g:php_builtin_classes, tolower(classname)) - return phpcomplete#CompleteBuiltInClass(context, classname, a:base) + if context =~ '\(->\|::\)$' + " {{{ + " Get name of the class + let classname = phpcomplete#GetClassName(line('.'), context, current_namespace, imports) + + " Get location of class definition, we have to iterate through all + if classname != '' + if classname =~ '\' + " split the last \ segment as a classname, everything else is the namespace + let classname_parts = split(classname, '\') + let namespace = join(classname_parts[0:-2], '\') + let classname = classname_parts[-1] + else + let namespace = '\' + endif + let classlocation = phpcomplete#GetClassLocation(classname, namespace) + else + let classlocation = '' endif - if filereadable(classlocation) - let classfile = readfile(classlocation) - let classcontent = '' - let classcontent .= "\n".phpcomplete#GetClassContents(classlocation, classname) - let sccontent = split(classcontent, "\n") - let visibility = expand('%:p') == fnamemodify(classlocation, ':p') ? 'private' : 'public' + if classlocation != '' + if classlocation == 'VIMPHP_BUILTINOBJECT' && has_key(g:php_builtin_classes, tolower(classname)) + return phpcomplete#CompleteBuiltInClass(context, classname, a:base) + endif - return phpcomplete#CompleteUserClass(context, a:base, sccontent, visibility) - endif - endif + if filereadable(classlocation) + let classfile = readfile(classlocation) + let classcontent = '' + let classcontent .= "\n".phpcomplete#GetClassContents(classlocation, classname) + let sccontent = split(classcontent, "\n") + let visibility = expand('%:p') == fnamemodify(classlocation, ':p') ? 'private' : 'public' - return phpcomplete#CompleteUnknownClass(a:base, context) - " }}} - elseif context =~? 'implements' - return phpcomplete#CompleteClassName(a:base, ['i'], current_namespace, imports) - elseif context =~? 'extends\s\+.\+$' && a:base == '' - return ['implements'] - elseif context =~? 'extends' - let kinds = context =~? 'class\s' ? ['c'] : ['i'] - return phpcomplete#CompleteClassName(a:base, kinds, current_namespace, imports) - elseif context =~? 'class [a-zA-Z_\x7f-\xff\\][a-zA-Z_0-9\x7f-\xff\\]*' - " special case when you've typed the class keyword and the name too, only extends and implements allowed there - return filter(['extends', 'implements'], 'stridx(v:val, a:base) == 0') - elseif context =~? 'new' - return phpcomplete#CompleteClassName(a:base, ['c'], current_namespace, imports) - endif + return phpcomplete#CompleteUserClass(context, a:base, sccontent, visibility) + endif + endif - if a:base =~ '^\$' - return phpcomplete#CompleteVariable(a:base) - else - return phpcomplete#CompleteGeneral(a:base, current_namespace, imports) - endif + return phpcomplete#CompleteUnknownClass(a:base, context) + " }}} + elseif context =~? 'implements' + return phpcomplete#CompleteClassName(a:base, ['i'], current_namespace, imports) + elseif context =~? 'extends\s\+.\+$' && a:base == '' + return ['implements'] + elseif context =~? 'extends' + let kinds = context =~? 'class\s' ? ['c'] : ['i'] + return phpcomplete#CompleteClassName(a:base, kinds, current_namespace, imports) + elseif context =~? 'class [a-zA-Z_\x7f-\xff\\][a-zA-Z_0-9\x7f-\xff\\]*' + " special case when you've typed the class keyword and the name too, only extends and implements allowed there + return filter(['extends', 'implements'], 'stridx(v:val, a:base) == 0') + elseif context =~? 'new' + return phpcomplete#CompleteClassName(a:base, ['c'], current_namespace, imports) + endif + + if a:base =~ '^\$' + return phpcomplete#CompleteVariable(a:base) + else + return phpcomplete#CompleteGeneral(a:base, current_namespace, imports) + endif + finally + silent! exec winnr.'resize '.winheight + endtry endfunction " }}} @@ -1523,21 +1532,19 @@ function! phpcomplete#GetClassName(start_line, context, current_namespace, impor return '' endif - if line =~? '\v^\s*(abstract\s+|final\s+)*\s*class' - let class_name = matchstr(line, '\c\s*class\s*\zs'.class_name_pattern.'\ze') + if line =~? '\v^\s*(abstract\s+|final\s+)*\s*class\s' + let class_name = matchstr(line, '\cclass\s\+\zs'.class_name_pattern.'\ze') let extended_class = matchstr(line, '\cclass\s\+'.class_name_pattern.'\s\+extends\s\+\zs'.class_name_pattern.'\ze') let classname_candidate = a:context =~? 'parent::' ? extended_class : class_name - else - let i += 1 - continue + if classname_candidate != '' + let [classname_candidate, class_candidate_namespace] = phpcomplete#GetCallChainReturnType(classname_candidate, class_candidate_namespace, class_candidate_imports, methodstack) + " return absolute classname, without leading \ + return (class_candidate_namespace == '\' || class_candidate_namespace == '') ? classname_candidate : class_candidate_namespace.'\'.classname_candidate + endif endif - if classname_candidate != '' - let [classname_candidate, class_candidate_namespace] = phpcomplete#GetCallChainReturnType(classname_candidate, class_candidate_namespace, class_candidate_imports, methodstack) - " return absolute classname, without leading \ - return (class_candidate_namespace == '\' || class_candidate_namespace == '') ? classname_candidate : class_candidate_namespace.'\'.classname_candidate - endif + let i += 1 endwhile elseif a:context =~? '(\s*new\s\+'.class_name_pattern.'\s*)->' let classname_candidate = matchstr(a:context, '\cnew\s\+\zs'.class_name_pattern.'\ze') @@ -2031,7 +2038,7 @@ function! phpcomplete#GetClassContentsStructure(file_path, file_lines, class_nam " remember the window we started at let phpcomplete_original_window = winnr() - silent! tab 1new + silent! below 1new silent! 0put =cfile call search('\c\(class\|interface\|trait\)\_s\+'.a:class_name.'\(\>\|$\)') let cfline = line('.') @@ -2370,7 +2377,7 @@ endfunction! function! phpcomplete#GetCurrentNameSpace(file_lines) " {{{ let original_window = winnr() - silent! tab 1new + silent! below 1new silent! 0put =a:file_lines normal! G diff --git a/runtime/autoload/provider/clipboard.vim b/runtime/autoload/provider/clipboard.vim index 5d1ce7896d..3728eb9367 100644 --- a/runtime/autoload/provider/clipboard.vim +++ b/runtime/autoload/provider/clipboard.vim @@ -83,6 +83,7 @@ function! s:clipboard.set(lines, regtype, reg) end let selection.data = [a:lines, a:regtype] let argv = split(s:copy[a:reg], " ") + let selection.detach = s:cache_enabled let jobid = jobstart(argv, selection) if jobid <= 0 echohl WarningMsg diff --git a/runtime/autoload/provider/script_host.py b/runtime/autoload/provider/script_host.py index 96d70e0330..416b4070bb 100644 --- a/runtime/autoload/provider/script_host.py +++ b/runtime/autoload/provider/script_host.py @@ -1,5 +1,6 @@ """Legacy python/python3-vim emulation.""" import imp +import io import logging import os import sys @@ -151,7 +152,7 @@ class ScriptHost(object): current.range = current.buffer.range(start, stop) -class RedirectStream(object): +class RedirectStream(io.IOBase): def __init__(self, redirect_handler): self.redirect_handler = redirect_handler @@ -161,9 +162,6 @@ class RedirectStream(object): def writelines(self, seq): self.redirect_handler('\n'.join(seq)) - def flush(self): - pass - class LegacyEvalHook(neovim.SessionHook): diff --git a/runtime/autoload/tutor.vim b/runtime/autoload/tutor.vim index 4d5a10a97c..43d8a87886 100644 --- a/runtime/autoload/tutor.vim +++ b/runtime/autoload/tutor.vim @@ -251,13 +251,14 @@ endfunction " Tutor Cmd: {{{1 function! s:Locale() - let l:lang = "" if exists('v:lang') && v:lang =~ '\a\a' let l:lang = v:lang elseif $LC_ALL =~ '\a\a' let l:lang = $LC_ALL elseif $LANG =~ '\a\a' let l:lang = $LANG + else + let l:lang = 'en_US' endif return split(l:lang, '_') endfunction diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt index 140a2f2e66..e17281821c 100644 --- a/runtime/doc/autocmd.txt +++ b/runtime/doc/autocmd.txt @@ -1,4 +1,4 @@ -*autocmd.txt* For Vim version 7.4. Last change: 2014 Sep 23 +*autocmd.txt* For Vim version 7.4. Last change: 2015 Mar 21 VIM REFERENCE MANUAL by Bram Moolenaar @@ -973,6 +973,13 @@ WinLeave Before leaving a window. If the window to be ============================================================================== 6. Patterns *autocmd-patterns* *{pat}* +The {pat} argument can be a comma separated list. This works as if the +command was given with each pattern separately. Thus this command: > + :autocmd BufRead *.txt,*.info set et +Is equivalent to: > + :autocmd BufRead *.txt set et + :autocmd BufRead *.info set et + The file pattern {pat} is tested for a match against the file name in one of two ways: 1. When there is no '/' in the pattern, Vim checks for a match against only diff --git a/runtime/doc/change.txt b/runtime/doc/change.txt index 0fa383bc67..42dc84e0de 100644 --- a/runtime/doc/change.txt +++ b/runtime/doc/change.txt @@ -371,8 +371,10 @@ CTRL-X Subtract [count] from the number or alphabetic character at or after the cursor. The CTRL-A and CTRL-X commands work for (signed) decimal numbers, unsigned -octal and hexadecimal numbers and alphabetic characters. This depends on the -'nrformats' option. +binary/octal/hexadecimal numbers and alphabetic characters. This +depends on the 'nrformats' option. +- When 'nrformats' includes "bin", Vim considers numbers starting with '0b' or + '0B' as binary. - When 'nrformats' includes "octal", Vim considers numbers starting with a '0' to be octal, unless the number includes a '8' or '9'. Other numbers are decimal and may have a preceding minus sign. @@ -386,6 +388,10 @@ octal and hexadecimal numbers and alphabetic characters. This depends on the under or after the cursor. This is useful to make lists with an alphabetic index. +For decimals a leading negative sign is considered for incrementing or +decrementing, for binary and octal and hex values, it won't be considered. To +ignore the sign Visually select the number before using CTRL-A or CTRL-X. + For numbers with leading zeros (including all octal and hexadecimal numbers), Vim preserves the number of characters in the number when possible. CTRL-A on "0077" results in "0100", CTRL-X on "0x100" results in "0x0ff". @@ -397,6 +403,10 @@ octal number. Note that when 'nrformats' includes "octal", decimal numbers with leading zeros cause mistakes, because they can be confused with octal numbers. +Note similarly, when 'nrformats' includes "bin", binary numbers with a leading +'0x' or '0X' can be interpreted as hexadecimal rather than binary since '0b' +are valid hexadecimal digits. + The CTRL-A command is very useful in a macro. Example: Use the following steps to make a numbered list. @@ -1602,7 +1612,7 @@ Vim has a sorting function and a sorting command. The sorting function can be found here: |sort()|, |uniq()|. *:sor* *:sort* -:[range]sor[t][!] [i][u][r][n][x][o] [/{pattern}/] +:[range]sor[t][!] [i][u][r][n][x][o][b] [/{pattern}/] Sort lines in [range]. When no range is given all lines are sorted. @@ -1622,6 +1632,9 @@ found here: |sort()|, |uniq()|. With [o] sorting is done on the first octal number in the line (after or inside a {pattern} match). + With [b] sorting is done on the first binary number in + the line (after or inside a {pattern} match). + With [u] only keep the first of a sequence of identical lines (ignoring case when [i] is used). Without this flag, a sequence of identical lines diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 1f1dc71f28..6bdfa8dc8a 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -65,14 +65,16 @@ the Number. Examples: Number 0 --> String "0" ~ Number -1 --> String "-1" ~ *octal* -Conversion from a String to a Number is done by converting the first digits -to a number. Hexadecimal "0xf9" and Octal "017" numbers are recognized. If -the String doesn't start with digits, the result is zero. Examples: +Conversion from a String to a Number is done by converting the first digits to +a number. Hexadecimal "0xf9", Octal "017", and Binary "0b10" numbers are +recognized. If the String doesn't start with digits, the result is zero. +Examples: String "456" --> Number 456 ~ String "6bar" --> Number 6 ~ String "foo" --> Number 0 ~ String "0xf1" --> Number 241 ~ String "0100" --> Number 64 ~ + String "0b101" --> Number 5 ~ String "-8" --> Number -8 ~ String "+8" --> Number 0 ~ @@ -522,7 +524,7 @@ Funcref to a Dictionary, but the "self" variable is not available then. To avoid the extra name for the function it can be defined and directly assigned to a Dictionary in this way: > :let mydict = {'data': [0, 1, 2, 3]} - :function mydict.len() dict + :function mydict.len() : return len(self.data) :endfunction :echo mydict.len() @@ -1860,10 +1862,10 @@ getwinposx() Number X coord in pixels of GUI Vim window getwinposy() Number Y coord in pixels of GUI Vim window getwinvar( {nr}, {varname} [, {def}]) any variable {varname} in window {nr} -glob( {expr} [, {nosuf} [, {list}]]) +glob( {expr} [, {nosuf} [, {list} [, {alllinks}]]]) any expand file wildcards in {expr} glob2regpat( {expr}) String convert a glob pat into a search pat -globpath( {path}, {expr} [, {nosuf} [, {list}]]) +globpath( {path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]]) String do glob({expr}) for all dirs in {path} has( {feature}) Number TRUE if feature {feature} supported has_key( {dict}, {key}) Number TRUE if {dict} has entry {key} @@ -1894,6 +1896,7 @@ isdirectory( {directory}) Number TRUE if {directory} is a directory islocked( {expr}) Number TRUE if {expr} is locked items( {dict}) List key-value pairs in {dict} jobclose({job}[, {stream}]) Number Closes a job stream(s) +jobpid({job}) Number Returns pid of a job. jobresize({job}, {width}, {height}) Number Resize {job}'s pseudo terminal window jobsend({job}, {data}) Number Writes {data} to {job}'s stdin @@ -3751,7 +3754,7 @@ getwinvar({winnr}, {varname} [, {def}]) *getwinvar()* :let list_is_on = getwinvar(2, '&list') :echo "myvar = " . getwinvar(1, 'myvar') < -glob({expr} [, {nosuf} [, {list}]]) *glob()* +glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()* Expand the file wildcards in {expr}. See |wildcards| for the use of special characters. @@ -3768,8 +3771,11 @@ glob({expr} [, {nosuf} [, {list}]]) *glob()* matches, they are separated by <NL> characters. If the expansion fails, the result is an empty String or List. + A name for a non-existing file is not included. A symbolic link is only included if it points to an existing file. + However, when the {alllinks} argument is present and it is + non-zero then all symbolic links are included. For most systems backticks can be used to get files names from any external command. Example: > @@ -3789,7 +3795,8 @@ glob2regpat({expr}) *glob2regpat()* < This is equivalent to: > if filename =~ '^Make.*\.mak$' < -globpath({path}, {expr} [, {nosuf} [, {list}]]) *globpath()* + *globpath()* +globpath({path}, {expr} [, {nosuf} [, {list} [, {allinks}]]]) Perform glob() on all directories in {path} and concatenate the results. Example: > :echo globpath(&rtp, "syntax/c.vim") @@ -3815,6 +3822,8 @@ globpath({path}, {expr} [, {nosuf} [, {list}]]) *globpath()* they are separated by <NL> characters. Example: > :echo globpath(&rtp, "syntax/c.vim", 0, 1) < + {allinks} is used as with |glob()|. + The "**" item can be used to search in a directory tree. For example, to find all "README.txt" files in the directories in 'runtimepath' and below: > @@ -4157,6 +4166,9 @@ jobclose({job}[, {stream}]) {Nvim} *jobclose()* Close {job}'s {stream}, which can be one "stdin", "stdout" or "stderr". If {stream} is omitted, all streams are closed. +jobpid({job}) {Nvim} *jobpid()* + Return the pid (process id) of {job}. + jobresize({job}, {width}, {height}) {Nvim} *jobresize()* Resize {job}'s pseudo terminal window to {width} and {height}. This function will fail if used on jobs started without the @@ -4194,6 +4206,10 @@ jobstart({cmd}[, {opts}]) {Nvim} *jobstart()* - width: Width of the terminal screen(only if pty is set) - height: Height of the terminal screen(only if pty is set) - TERM: $TERM environment variable(only if pty is set) + - detach: Detach the job process from the nvim process. The + process won't get killed when nvim exists. If the process + dies before nvim exits, on_exit will still be invoked. + This option is only allowed for non-pty jobs. Either funcrefs or function names can be passed as event handlers. The {opts} object is also used as the "self" argument for the callback, so the caller may pass arbitrary @@ -4911,6 +4927,9 @@ printf({fmt}, {expr1} ...) *printf()* %c single byte %d decimal number %5d decimal number padded with spaces to 5 characters + %b binary number + %08b binary number padded with zeros to at least 8 characters + %B binary number using upper case letters %x hex number %04x hex number padded with zeros to at least 4 characters %X hex number using upper case letters @@ -4997,20 +5016,19 @@ printf({fmt}, {expr1} ...) *printf()* The conversion specifiers and their meanings are: - *printf-d* *printf-o* *printf-x* *printf-X* - doxX The Number argument is converted to signed decimal - (d), unsigned octal (o), or unsigned hexadecimal (x - and X) notation. The letters "abcdef" are used for - x conversions; the letters "ABCDEF" are used for X - conversions. - The precision, if any, gives the minimum number of - digits that must appear; if the converted value - requires fewer digits, it is padded on the left with - zeros. - In no case does a non-existent or small field width - cause truncation of a numeric field; if the result of - a conversion is wider than the field width, the field - is expanded to contain the conversion result. + *printf-d* *printf-b* *printf-B* *printf-o* *printf-x* *printf-X* + dbBoxX The Number argument is converted to signed decimal (d), + unsigned binary (b and B), unsigned octal (o), or + unsigned hexadecimal (x and X) notation. The letters + "abcdef" are used for x conversions; the letters + "ABCDEF" are used for X conversions. The precision, if + any, gives the minimum number of digits that must + appear; if the converted value requires fewer digits, it + is padded on the left with zeros. In no case does a + non-existent or small field width cause truncation of a + numeric field; if the result of a conversion is wider + than the field width, the field is expanded to contain + the conversion result. *printf-c* c The Number argument is converted to a byte, and the @@ -6126,12 +6144,14 @@ str2float( {expr}) *str2float()* str2nr( {expr} [, {base}]) *str2nr()* Convert string {expr} to a number. - {base} is the conversion base, it can be 8, 10 or 16. + {base} is the conversion base, it can be 2, 8, 10 or 16. When {base} is omitted base 10 is used. This also means that a leading zero doesn't cause octal conversion to be used, as with the default String to Number conversion. When {base} is 16 a leading "0x" or "0X" is ignored. With a - different base the result will be zero. + different base the result will be zero. Similarly, when {base} + is 8 a leading "0" is ignored, and when {base} is 2 a leading + "0b" or "0B" is ignored. Text after the number is silently ignored. diff --git a/runtime/doc/help.txt b/runtime/doc/help.txt index 766a440cb3..19bcb35da8 100644 --- a/runtime/doc/help.txt +++ b/runtime/doc/help.txt @@ -1,4 +1,4 @@ -*help.txt* For Vim version 7.4. Last change: 2012 Dec 06 +*help.txt* For Vim version 7.4. Last change: 2015 Apr 15 VIM - main help file k @@ -23,6 +23,7 @@ Get specific help: It is possible to go directly to whatever you want help Command-line editing c_ :help c_<Del> Vim command argument - :help -r Option ' :help 'textwidth' + Regular expression / :help /[ Search for help: Type ":help word", then hit CTRL-D to see matching help entries for "word". Or use ":helpgrep word". |:helpgrep| diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 013e7c742c..bbd9cc1e2b 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -3984,8 +3984,9 @@ A jump table for the options with a short description can be found at |Q_op|. conceal:c Character to show in place of concealed text, when 'conceallevel' is set to 1. A space when omitted. *lcs-nbsp* - nbsp:c Character to show for a non-breakable space (character - 0xA0, 160). Left blank when omitted. + nbsp:c Character to show for a non-breakable space character + (0xA0 (160 decimal) and U+202F). Left blank when + omitted. The characters ':' and ',' should not be used. UTF-8 characters can be used when 'encoding' is "utf-8", otherwise only printable diff --git a/runtime/doc/pattern.txt b/runtime/doc/pattern.txt index 21eeb9bc41..84dce82176 100644 --- a/runtime/doc/pattern.txt +++ b/runtime/doc/pattern.txt @@ -1,4 +1,4 @@ -*pattern.txt* For Vim version 7.4. Last change: 2015 Feb 17 +*pattern.txt* For Vim version 7.4. Last change: 2015 Mar 16 VIM REFERENCE MANUAL by Bram Moolenaar @@ -1052,7 +1052,10 @@ x A single character, with no special meaning, matches itself *E769* When the ']' is not there Vim will not give an error message but assume no collection is used. Useful to search for '['. However, you - do get E769 for internal searching. + do get E769 for internal searching. And be aware that in a + `:substitute` command the whole command becomes the pattern. E.g. + ":s/[/x/" searches for "[/x" and replaces it with nothing. It does + not search for "[" and replaces it with "x"! If the sequence begins with "^", it matches any single character NOT in the collection: "[^xyz]" matches anything but 'x', 'y' and 'z'. diff --git a/runtime/doc/quickref.txt b/runtime/doc/quickref.txt index 14aa3ef603..ded5e69438 100644 --- a/runtime/doc/quickref.txt +++ b/runtime/doc/quickref.txt @@ -983,8 +983,6 @@ Short explanation of each option: *option-list* |dos-CTRL-Break| CTRL-Break Windows: during searches: Interrupt the search |<Del>| <Del> while entering a count: delete last character |:version| :ve[rsion] show version information -|:mode| :mode N Windows: set screen mode to N (number, C80, - C4350, etc.) |:normal| :norm[al][!] {commands} execute Normal mode commands |Q| Q switch to "Ex" mode diff --git a/runtime/doc/repeat.txt b/runtime/doc/repeat.txt index 05a49d9658..21b5eef811 100644 --- a/runtime/doc/repeat.txt +++ b/runtime/doc/repeat.txt @@ -1,4 +1,4 @@ -*repeat.txt* For Vim version 7.4. Last change: 2015 Jan 07 +*repeat.txt* For Vim version 7.4. Last change: 2015 Apr 13 VIM REFERENCE MANUAL by Bram Moolenaar @@ -583,6 +583,7 @@ For example, to profile the one_script.vim script file: > :prof[ile] start {fname} *:prof* *:profile* *E750* Start profiling, write the output in {fname} upon exit. + "~/" and environment variables in {fname} will be expanded. If {fname} already exists it will be silently overwritten. The variable |v:profiling| is set to one. @@ -658,10 +659,6 @@ long you take to respond to the input() prompt is irrelevant. Profiling should give a good indication of where time is spent, but keep in mind there are various things that may clobber the results: -- The accuracy of the time measured depends on the gettimeofday() system - function. It may only be as accurate as 1/100 second, even though the times - are displayed in micro seconds. - - Real elapsed time is measured, if other processes are busy they may cause delays at unpredictable moments. You may want to run the profiling several times and use the lowest results. diff --git a/runtime/doc/syntax.txt b/runtime/doc/syntax.txt index 78d6fdb1e1..6aed7441a0 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 Feb 22 +*syntax.txt* For Vim version 7.4. Last change: 2015 Mar 29 VIM REFERENCE MANUAL by Bram Moolenaar @@ -3307,6 +3307,32 @@ must not click outside of the pixel strings, but feel free to improve it. It will look much better with a font in a quadratic cell size, e.g. for X: > :set guifont=-*-clean-medium-r-*-*-8-*-*-*-*-80-* + +YAML *yaml.vim* *ft-yaml-syntax* + + *g:yaml_schema* *b:yaml_schema* +A YAML schema is a combination of a set of tags and a mechanism for resolving +non-specific tags. For user this means that YAML parser may, depending on +plain scalar contents, treat plain scalar (which can actually be only string +and nothing else) as a value of the other type: null, boolean, floating-point, +integer. `g:yaml_schema` option determines according to which schema values +will be highlighted specially. Supported schemas are + +Schema Description ~ +failsafe No additional highlighting. +json Supports JSON-style numbers, booleans and null. +core Supports more number, boolean and null styles. +pyyaml In addition to core schema supports highlighting timestamps, + but there are some differences in what is recognized as + numbers and many additional boolean values not present in core + schema. + +Default schema is `core`. + +Note that schemas are not actually limited to plain scalars, but this is the +only difference between schemas defined in YAML specification and the only +difference defined in the syntax file. + ============================================================================== 5. Defining a syntax *:syn-define* *E410* @@ -4632,6 +4658,8 @@ ctermbg={color-nr} *highlight-ctermbg* Note that for some color terminals these names may result in the wrong colors! + You can also use "NONE" to remove the color. + *:hi-normal-cterm* When setting the "ctermfg" or "ctermbg" colors for the Normal group, these will become the colors used for the non-highlighted text. diff --git a/runtime/doc/usr_02.txt b/runtime/doc/usr_02.txt index f81a4e3a2c..6a288f8965 100644 --- a/runtime/doc/usr_02.txt +++ b/runtime/doc/usr_02.txt @@ -1,4 +1,4 @@ -*usr_02.txt* For Vim version 7.4. Last change: 2010 Jul 20 +*usr_02.txt* For Vim version 7.4. Last change: 2015 Apr 12 VIM USER MANUAL - by Bram Moolenaar @@ -516,9 +516,11 @@ Summary: *help-summary* > :help subject() < Function "subject". > :help -subject -< Command-line option "-subject". > +< Command-line argument "-subject". > :help +subject < Compile-time feature "+subject". > + :help /* +< Regular expression item "*" > :help EventName < Autocommand event "EventName". > :help digraphs.txt diff --git a/runtime/doc/various.txt b/runtime/doc/various.txt index f028102634..26ff8f0783 100644 --- a/runtime/doc/various.txt +++ b/runtime/doc/various.txt @@ -568,12 +568,6 @@ which it was defined is reported. While sleeping the cursor is positioned in the text, if at a visible position. - - *g_CTRL-A* -g CTRL-A Only when Vim was compiled with MEM_PROFILING defined - (which is very rare): print memory usage statistics. - Only useful for debugging Vim. - ============================================================================== 2. Using Vim like less or more *less* diff --git a/runtime/doc/windows.txt b/runtime/doc/windows.txt index 56f57c21c5..eee171b7da 100644 --- a/runtime/doc/windows.txt +++ b/runtime/doc/windows.txt @@ -681,7 +681,6 @@ can also get to them with the buffer list commands, like ":bnext". When using the |:tab| modifier each argument is opened in a tab page. The last window is used if it's empty. Also see |++opt| and |+cmd|. - {only available when compiled with a GUI} ============================================================================== 8. Do a command in all buffers or windows *list-repeat* diff --git a/runtime/filetype.vim b/runtime/filetype.vim index 5dbd1a9a19..c5b01f0c40 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 Jan 14 +" Last Change: 2015 Apr 06 " Listen very carefully, I will say this only once if exists("did_load_filetypes") @@ -1262,8 +1262,8 @@ au BufNewFile,BufRead */etc/modules.conf,*/etc/modules,*/etc/conf.modules setf m " Mplayer config au BufNewFile,BufRead mplayer.conf,*/.mplayer/config setf mplayerconf -" Moterola S record -au BufNewFile,BufRead *.s19,*.s28,*.s37 setf srec +" Motorola S record +au BufNewFile,BufRead *.s19,*.s28,*.s37,*.mot,*.srec setf srec " Mrxvtrc au BufNewFile,BufRead mrxvtrc,.mrxvtrc setf mrxvtrc @@ -1290,7 +1290,7 @@ au BufNewFile,BufRead *.mush setf mush au BufNewFile,BufRead Mutt{ng,}rc setf muttrc " Nano -au BufNewFile,BufRead */etc/nanorc,.nanorc setf nanorc +au BufNewFile,BufRead */etc/nanorc,*.nanorc setf nanorc " Nastran input/DMAP "au BufNewFile,BufRead *.dat setf nastran diff --git a/runtime/ftplugin/j.vim b/runtime/ftplugin/j.vim index 71ac4c5418..774696836f 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-01-11 +" Last Change: 2015-03-27 if exists('b:did_ftplugin') finish @@ -16,12 +16,9 @@ setlocal iskeyword=48-57,A-Z,_,a-z setlocal comments=:NB. setlocal commentstring=NB.\ %s setlocal formatoptions-=t -setlocal shiftwidth=2 -setlocal softtabstop=2 -setlocal expandtab setlocal matchpairs=(:) -let b:undo_ftplugin = 'setlocal matchpairs< expandtab< softtabstop< shiftwidth< formatoptions< commentstring< comments< iskeyword<' +let b:undo_ftplugin = 'setlocal matchpairs< formatoptions< commentstring< comments< iskeyword<' " 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/indent/html.vim b/runtime/indent/html.vim index b97a905988..71443abe5b 100644 --- a/runtime/indent/html.vim +++ b/runtime/indent/html.vim @@ -245,6 +245,10 @@ call s:AddITags(s:indent_tags, [ \ 'header', 'group', 'keygen', 'mark', 'math', 'meter', 'nav', 'output', \ 'progress', 'ruby', 'section', 'svg', 'texture', 'time', 'video', \ 'wbr', 'text']) + +" Tags added for web components: +call s:AddITags(s:indent_tags, [ + \ 'content', 'shadow', 'template']) "}}} " Add Block Tags: these contain alien content @@ -287,7 +291,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\+\>\|<!--\|-->', '\=s:CheckTag(submatch(0))', 'g') + call substitute(a:text, '<\zs/\=\w\+\(-\w\+\)*\>\|<!--\|-->', '\=s:CheckTag(submatch(0))', 'g') let s:countonly = 0 endfunc "}}} @@ -299,7 +303,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\+\>\|<!--\|-->', '\=s:CheckTag(submatch(0))', 'g') + let tmp = substitute(a:text, '<\zs/\=\w\+\(-\w\+\)*\>\|<!--\|-->', '\=s:CheckTag(submatch(0))', 'g') if s:block == 3 let b:hi_newstate.scripttype = s:GetScriptType(matchstr(tmp, '\C.*<SCRIPT\>\zs[^>]*')) endif @@ -311,6 +315,9 @@ func! s:CheckTag(itag) "{{{ " Returns an empty string or "SCRIPT". " a:itag can be "tag" or "/tag" or "<!--" or "-->" + if (s:CheckCustomTag(a:itag)) + return "" + endif let ind = s:get_tag(a:itag) if ind == -1 " closing tag @@ -365,6 +372,36 @@ func! s:CheckBlockTag(blocktag, ind) return "" endfunc "}}} +" Used by s:CheckTag(). +func! s:CheckCustomTag(ctag) + "{{{ + " Returns 1 if ctag is the tag for a custom element, 0 otherwise. + " a:ctag can be "tag" or "/tag" or "<!--" or "-->" + let pattern = '\%\(\w\+-\)\+\w\+' + if match(a:ctag, pattern) == -1 + return 0 + endif + if matchstr(a:ctag, '\/\ze.\+') == "/" + " closing tag + if s:block != 0 + " ignore ctag within a block + return 1 + endif + if s:nextrel == 0 + let s:curind -= 1 + else + let s:nextrel -= 1 + endif + else + " opening tag + if s:block != 0 + return 1 + endif + let s:nextrel += 1 + endif + return 1 +endfunc "}}} + " Return the <script> type: either "javascript" or "" func! s:GetScriptType(str) "{{{ diff --git a/runtime/syntax/c.vim b/runtime/syntax/c.vim index a520e6317f..ac4909edba 100644 --- a/runtime/syntax/c.vim +++ b/runtime/syntax/c.vim @@ -1,7 +1,7 @@ " Vim syntax file " Language: C " Maintainer: Bram Moolenaar <Bram@vim.org> -" Last Change: 2015 Feb 27 +" Last Change: 2015 Mar 05 " Quit when a (custom) syntax file was already loaded if exists("b:current_syntax") @@ -47,16 +47,17 @@ if !exists("c_no_cformat") endif " cCppString: same as cString, but ends at end of line -if s:ft ==# "cpp" && !exists("cpp_no_cpp11") +if s:ft ==# "cpp" && !exists("cpp_no_cpp11") && !exists("c_no_cformat") " ISO C++11 syn region cString start=+\(L\|u\|u8\|U\|R\|LR\|u8R\|uR\|UR\)\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cFormat,@Spell extend syn region cCppString start=+\(L\|u\|u8\|U\|R\|LR\|u8R\|uR\|UR\)\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial,cFormat,@Spell -elseif s:ft ==# "c" && !exists("c_no_c11") +elseif s:ft ==# "c" && !exists("c_no_c11") && !exists("c_no_cformat") " ISO C99 syn region cString start=+\%(L\|U\|u8\)\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cFormat,@Spell extend syn region cCppString start=+\%(L\|U\|u8\)\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial,cFormat,@Spell else " older C or C++ + syn match cFormat display "%%" contained syn region cString start=+L\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cFormat,@Spell extend syn region cCppString start=+L\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial,cFormat,@Spell endif @@ -80,7 +81,11 @@ syn match cSpecialCharacter display "L'\\x\x\+'" if (s:ft ==# "c" && !exists("c_no_c11")) || (s:ft ==# "cpp" && !exists("cpp_no_cpp11")) " ISO C11 or ISO C++ 11 - syn region cString start=+\%(U\|u8\=\)"+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cFormat,@Spell extend + if exists("c_no_cformat") + syn region cString start=+\%(U\|u8\=\)"+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,@Spell extend + else + syn region cString start=+\%(U\|u8\=\)"+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cFormat,@Spell extend + endif syn match cCharacter "[Uu]'[^\\]'" syn match cCharacter "[Uu]'[^']*'" contains=cSpecial if exists("c_gnu") @@ -389,8 +394,13 @@ endif syn cluster cLabelGroup contains=cUserLabel syn match cUserCont display "^\s*\I\i*\s*:$" contains=@cLabelGroup syn match cUserCont display ";\s*\I\i*\s*:$" contains=@cLabelGroup -syn match cUserCont display "^\s*\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup -syn match cUserCont display ";\s*\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup +if s:ft ==# 'cpp' + syn match cUserCont display "^\s*\%(class\|struct\|enum\)\@!\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup + syn match cUserCont display ";\s*\%(class\|struct\|enum\)\@!\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup +else + syn match cUserCont display "^\s*\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup + syn match cUserCont display ";\s*\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup +endif syn match cUserLabel display "\I\i*" contained diff --git a/runtime/syntax/cpp.vim b/runtime/syntax/cpp.vim index 15f0cbb4ff..526ecbcd53 100644 --- a/runtime/syntax/cpp.vim +++ b/runtime/syntax/cpp.vim @@ -1,8 +1,8 @@ " Vim syntax file " Language: C++ -" Current Maintainer: vim-jp (https://github.com/vim-jp/cpp-vim) +" Current Maintainer: vim-jp (https://github.com/vim-jp/vim-cpp) " Previous Maintainer: Ken Shan <ccshan@post.harvard.edu> -" Last Change: 2014 May 14 +" Last Change: 2015 Mar 1 " For version 5.x: Clear all syntax items " For version 6.x: Quit when a syntax file was already loaded @@ -32,14 +32,21 @@ syn match cppCast "\<\(const\|static\|dynamic\|reinterpret\)_cast\s*$" syn keyword cppStorageClass mutable syn keyword cppStructure class typename template namespace syn keyword cppBoolean true false +syn keyword cppConstant __cplusplus " C++ 11 extensions if !exists("cpp_no_cpp11") syn keyword cppType override final syn keyword cppExceptions noexcept - syn keyword cppStorageClass constexpr decltype + syn keyword cppStorageClass constexpr decltype thread_local syn keyword cppConstant nullptr - syn region cppRawString matchgroup=cppRawDelimiter start=+\%(u8\|[uLU]\)\=R"\z([[:alnum:]_{}[\]#<>%:;.?*\+\-/\^&|~!=,"']\{,16}\)(+ end=+)\z1"+ contains=@Spell + syn keyword cppConstant ATOMIC_FLAG_INIT ATOMIC_VAR_INIT + syn keyword cppConstant ATOMIC_BOOL_LOCK_FREE ATOMIC_CHAR_LOCK_FREE + syn keyword cppConstant ATOMIC_CHAR16_T_LOCK_FREE ATOMIC_CHAR32_T_LOCK_FREE + 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 endif " The minimum and maximum operators in GNU C++ diff --git a/runtime/syntax/csh.vim b/runtime/syntax/csh.vim index a67cb09189..9dc2c4ef56 100644 --- a/runtime/syntax/csh.vim +++ b/runtime/syntax/csh.vim @@ -1,8 +1,8 @@ " Vim syntax file " Language: C-shell (csh) " Maintainer: Charles E. Campbell <NdrOchipS@PcampbellAfamily.Mbiz> -" Version: 11 " Last Change: Oct 23, 2014 +" Version: 11 " URL: http://www.drchip.org/astronaut/vim/index.html#SYNTAX_CSH " For version 5.x: Clear all syntax items diff --git a/runtime/syntax/groovy.vim b/runtime/syntax/groovy.vim index c745960bd5..65dbf17728 100644 --- a/runtime/syntax/groovy.vim +++ b/runtime/syntax/groovy.vim @@ -4,7 +4,7 @@ " Maintainer: Tobias Rapp <yahuxo@gmx.de> " Version: 0.1.13 " URL: http://www.vim.org/scripts/script.php?script_id=945 -" Last Change: 2013 Apr 24 +" Last Change: 2015 Apr 13 " THE ORIGINAL AUTHOR'S NOTES: " @@ -220,7 +220,6 @@ syn region groovyComment start="/\*" end="\*/" contains=@groovyCommen syn match groovyCommentStar contained "^\s*\*[^/]"me=e-1 syn match groovyCommentStar contained "^\s*\*$" syn match groovyLineComment "//.*" contains=@groovyCommentSpecial2,groovyTodo,@Spell -syn match groovyLineComment "#.*" contains=@groovyCommentSpecial2,groovyTodo,@Spell GroovyHiLink groovyCommentString groovyString GroovyHiLink groovyComment2String groovyString GroovyHiLink groovyCommentCharacter groovyCharacter diff --git a/runtime/syntax/hex.vim b/runtime/syntax/hex.vim index 40c655395f..40f7f0dd10 100644 --- a/runtime/syntax/hex.vim +++ b/runtime/syntax/hex.vim @@ -1,7 +1,29 @@ " Vim syntax file -" Language: Intel hex MCS51 -" Maintainer: Sams Ricahrd <sams@ping.at> -" Last Change: 2003 Apr 25 +" Language: Intel HEX +" Maintainer: Markus Heidelberg <markus.heidelberg@web.de> +" Previous version: Sams Ricahrd <sams@ping.at> +" Last Change: 2015 Feb 24 + +" Each record (line) is built as follows: +" +" field digits states +" +" +----------+ +" | start | 1 (':') hexRecStart +" +----------+ +" | count | 2 hexDataByteCount +" +----------+ +" | address | 4 hexNoAddress, hexDataAddress, (hexAddressFieldUnknown) +" +----------+ +" | type | 2 hexRecType, (hexRecTypeUnknown) +" +----------+ +" | data | 0..510 hexDataOdd, hexDataEven, hexExtendedAddress, hexStartAddress, (hexDataFieldUnknown, hexDataUnexpected) +" +----------+ +" | checksum | 2 hexChecksum +" +----------+ +" +" States in parentheses in the upper format description indicate that they +" should not appear in a valid file. " For version 5.x: Clear all syntax items " For version 6.x: Quit when a syntax file was already loaded @@ -11,21 +33,39 @@ elseif exists("b:current_syntax") finish endif -syn case ignore +syn match hexRecStart "^:" + +syn match hexDataByteCount "^:[0-9a-fA-F]\{2}" contains=hexRecStart nextgroup=hexAddress + +syn match hexAddress "[0-9a-fA-F]\{4}" transparent contained nextgroup=hexRecTypeUnknown,hexRecType +" The address field groups include the record type field in the last 2 +" characters, the proper match for highlighting follows below. +syn match hexAddressFieldUnknown "^:[0-9a-fA-F]\{8}" contains=hexDataByteCount nextgroup=hexDataFieldUnknown,hexChecksum +syn match hexDataAddress "^:[0-9a-fA-F]\{6}00" contains=hexDataByteCount nextgroup=hexDataOdd,hexChecksum +syn match hexNoAddress "^:[0-9a-fA-F]\{6}01" contains=hexDataByteCount nextgroup=hexDataUnexpected,hexChecksum +syn match hexNoAddress "^:[0-9a-fA-F]\{6}0[24]" contains=hexDataByteCount nextgroup=hexExtendedAddress +syn match hexNoAddress "^:[0-9a-fA-F]\{6}0[35]" contains=hexDataByteCount nextgroup=hexStartAddress + +syn match hexRecTypeUnknown "[0-9a-fA-F]\{2}" contained +syn match hexRecType "0[0-5]" contained + +syn match hexDataFieldUnknown "[0-9a-fA-F]\{2}" contained nextgroup=hexDataFieldUnknown,hexChecksum +" alternating highlight per byte for easier reading +syn match hexDataOdd "[0-9a-fA-F]\{2}" contained nextgroup=hexDataEven,hexChecksum +syn match hexDataEven "[0-9a-fA-F]\{2}" contained nextgroup=hexDataOdd,hexChecksum +" data bytes which should not exist +syn match hexDataUnexpected "[0-9a-fA-F]\{2}" contained nextgroup=hexDataUnexpected,hexChecksum +" Data digit pair regex usage also results in only highlighting the checksum +" if the number of data characters is even. -" storage types +" special data fields +syn match hexExtendedAddress "[0-9a-fA-F]\{4}" contained nextgroup=hexDataUnexpected,hexChecksum +syn match hexStartAddress "[0-9a-fA-F]\{8}" contained nextgroup=hexDataUnexpected,hexChecksum -syn match hexChecksum "[0-9a-fA-F]\{2}$" -syn match hexAdress "^:[0-9a-fA-F]\{6}" contains=hexDataByteCount -syn match hexRecType "^:[0-9a-fA-F]\{8}" contains=hexAdress -syn match hexDataByteCount contained "^:[0-9a-fA-F]\{2}" contains=hexStart -syn match hexStart contained "^:" -syn match hexExtAdrRec "^:02000002[0-9a-fA-F]\{4}" contains=hexSpecRec -syn match hexExtLinAdrRec "^:02000004[0-9a-fA-F]\{4}" contains=hexSpecRec -syn match hexSpecRec contained "^:0[02]00000[124]" contains=hexStart -syn match hexEOF "^:00000001" contains=hexStart +syn match hexChecksum "[0-9a-fA-F]\{2}$" contained -syn case match +" Folding Data Records below an Extended Segment/Linear Address Record +syn region hexExtAdrBlock start="^:[0-9a-fA-F]\{7}[24]" skip="^:[0-9a-fA-F]\{7}0" end="^:"me=s-1 fold transparent " Define the default highlighting. " For version 5.7 and earlier: only when not done already @@ -38,16 +78,21 @@ if version >= 508 || !exists("did_hex_syntax_inits") command -nargs=+ HiLink hi def link <args> endif - " The default methods for highlighting. Can be overridden later - HiLink hexStart SpecialKey - HiLink hexDataByteCount Constant - HiLink hexAdress Comment - HiLink hexRecType WarningMsg - HiLink hexChecksum Search - HiLink hexExtAdrRec hexAdress - HiLink hexEOF hexSpecRec - HiLink hexExtLinAdrRec hexAdress - HiLink hexSpecRec DiffAdd + " The default methods for highlighting. Can be overridden later + HiLink hexRecStart hexRecType + HiLink hexDataByteCount Constant + hi def hexAddressFieldUnknown term=italic cterm=italic gui=italic + HiLink hexDataAddress Comment + HiLink hexNoAddress DiffAdd + HiLink hexRecTypeUnknown hexRecType + HiLink hexRecType WarningMsg + hi def hexDataFieldUnknown term=italic cterm=italic gui=italic + hi def hexDataOdd term=bold cterm=bold gui=bold + hi def hexDataEven term=NONE cterm=NONE gui=NONE + HiLink hexDataUnexpected Error + HiLink hexExtendedAddress hexDataAddress + HiLink hexStartAddress hexDataAddress + HiLink hexChecksum DiffChange delcommand HiLink endif diff --git a/runtime/syntax/php.vim b/runtime/syntax/php.vim index 860181e0e6..e2d73111e4 100644 --- a/runtime/syntax/php.vim +++ b/runtime/syntax/php.vim @@ -1,8 +1,8 @@ " Vim syntax file " Language: php PHP 3/4/5 " Maintainer: Jason Woofenden <jason@jasonwoof.com> -" Last Change: Sep 18, 2014 -" URL: https://gitorious.org/jasonwoof/vim-syntax/blobs/master/php.vim +" Last Change: Mar 24, 2015 +" URL: https://jasonwoof.com/gitweb/?p=vim-syntax.git;a=blob;f=php.vim;hb=HEAD " Former Maintainers: Peter Hodge <toomuchphp-vim@yahoo.com> " Debian VIM Maintainers <pkg-vim-maintainers@lists.alioth.debian.org> " diff --git a/runtime/syntax/sh.vim b/runtime/syntax/sh.vim index f3218ffcb2..ad0df1f117 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: Jan 08, 2015 -" Version: 134 +" Last Change: Apr 10, 2015 +" Version: 136 " 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) @@ -104,7 +104,7 @@ syn cluster shErrorList contains=shDoError,shIfError,shInError,shCaseError,shEsa if exists("b:is_kornshell") syn cluster ErrorList add=shDTestError endif -syn cluster shArithParenList contains=shArithmetic,shCaseEsac,shComment,shDeref,shDerefSimple,shDo,shEcho,shEscape,shIf,shFor,shNumber,shOperator,shPosnParm,shExSingleQuote,shExDoubleQuote,shRedir,shSingleQuote,shDoubleQuote,shStatement,shVariable,shAlias,shTest,shCtrlSeq,shSpecial,shParen,bashSpecialVariables,bashStatement +syn cluster shArithParenList contains=shArithmetic,shCaseEsac,shComment,shDeref,shDo,shDerefSimple,shEcho,shEscape,shNumber,shOperator,shPosnParm,shExSingleQuote,shExDoubleQuote,shRedir,shSingleQuote,shDoubleQuote,shStatement,shVariable,shAlias,shTest,shCtrlSeq,shSpecial,shParen,bashSpecialVariables,bashStatement,shIf,shFor syn cluster shArithList contains=@shArithParenList,shParenError syn cluster shCaseEsacList contains=shCaseStart,shCase,shCaseBar,shCaseIn,shComment,shDeref,shDerefSimple,shCaseCommandSub,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote,shCtrlSeq,@shErrorList,shStringSpecial,shCaseRange syn cluster shCaseList contains=@shCommandSubList,shCaseEsac,shColon,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shRedir,shSetList,shSource,shStatement,shVariable,shCtrlSeq @@ -127,9 +127,9 @@ syn cluster shHereList contains=shBeginHere,shHerePayload syn cluster shHereListDQ contains=shBeginHere,@shDblQuoteList,shHerePayload syn cluster shIdList contains=shCommandSub,shWrapLineOperator,shSetOption,shDeref,shDerefSimple,shRedir,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shExpr,shCtrlSeq,shStringSpecial,shAtExpr syn cluster shIfList contains=@shLoopList,shDblBrace,shDblParen,shFunctionKey,shFunctionOne,shFunctionTwo -syn cluster shLoopList contains=@shCaseList,shIf,shFor,shForPP,shTestOpr,shExpr,shDblBrace,shConditional,shCaseEsac,shTest,@shErrorList,shSet,shOption +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,shComment,shCommandSub,shDeref,shDerefSimple,shExDoubleQuote,shDoubleQuote,shExpr,shNumber,shOperator,shExSingleQuote,shSingleQuote,shTestOpr,shTest,shCtrlSeq +syn cluster shTestList contains=shCharClass,shCommandSub,shComment,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 @@ -197,13 +197,12 @@ syn region shTest transparent matchgroup=shStatement start="\<test\s" skip=+\\\\ syn match shTestOpr contained "<=\|>=\|!=\|==\|-.\>\|-\(nt\|ot\|ef\|eq\|ne\|lt\|le\|gt\|ge\)\>\|[!<>]" syn match shTestOpr contained '=' skipwhite nextgroup=shTestDoubleQuote,shTestSingleQuote,shTestPattern syn match shTestPattern contained '\w\+' -syn region shTestDoubleQuote contained start='"' skip='\\"' end='"' contains=shBQpairs +syn region shTestDoubleQuote contained start='\%(\%(\\\\\)*\\\)\@<!"' skip=+\\\\\|\\"+ end='"' syn match shTestSingleQuote contained '\\.' syn match shTestSingleQuote contained "'[^']*'" -syn match shBQpairs contained '\\\\' if exists("b:is_kornshell") || exists("b:is_bash") - syn region shDblBrace matchgroup=Delimiter start="\[\[" skip=+\\\\\|\\$+ end="\]\]" contains=@shTestList - syn region shDblParen matchgroup=Delimiter start="((" skip=+\\\\\|\\$+ end="))" contains=@shTestList + syn region shDblBrace matchgroup=Delimiter start="\[\[" skip=+\\\\\|\\$+ end="\]\]" contains=@shTestList,shComment + syn region shDblParen matchgroup=Delimiter start="((" skip=+\\\\\|\\$+ end="))" contains=@shTestList,shComment endif " Character Class In Range: {{{1 @@ -213,15 +212,16 @@ syn match shCharClass contained "\[:\(backspace\|escape\|return\|xdigit\|alnum " Loops: do, if, while, until {{{1 " ====== if s:sh_fold_ifdofor - syn region shDo fold transparent matchgroup=shConditional start="\<do\>" matchgroup=shConditional end="\<done\>" contains=@shLoopList - syn region shIf fold transparent matchgroup=shConditional start="\<if\_s" matchgroup=shConditional skip=+-fi\>+ end="\<;\_s*then\>" end="\<fi\>" contains=@shIfList - syn region shFor fold matchgroup=shLoop start="\<for\ze\_s\s*\%(((\)\@!" end="\<in\_s" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen skipwhite nextgroup=shCurlyIn + syn region shDo fold transparent matchgroup=shConditional start="\<do\>" matchgroup=shConditional end="\<done\>" contains=@shLoopList + syn region shIf fold transparent matchgroup=shConditional start="\<if\_s" matchgroup=shConditional skip=+-fi\>+ end="\<;\_s*then\>" end="\<fi\>" contains=@shIfList + syn region shFor fold matchgroup=shLoop start="\<for\ze\_s\s*\%(((\)\@!" end="\<in\_s" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen skipwhite nextgroup=shCurlyIn + syn region shForPP fold matchgroup=shLoop start='\<for\>\_s*((' end='))' contains=shTestOpr else - syn region shDo transparent matchgroup=shConditional start="\<do\>" matchgroup=shConditional end="\<done\>" contains=@shLoopList - syn region shIf transparent matchgroup=shConditional start="\<if\_s" matchgroup=shConditional skip=+-fi\>+ end="\<;\_s*then\>" end="\<fi\>" contains=@shIfList - syn region shFor matchgroup=shLoop start="\<for\ze\_s\s*\%(((\)\@!" end="\<in\>" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen skipwhite nextgroup=shCurlyIn + syn region shDo transparent matchgroup=shConditional start="\<do\>" matchgroup=shConditional end="\<done\>" contains=@shLoopList + syn region shIf transparent matchgroup=shConditional start="\<if\_s" matchgroup=shConditional skip=+-fi\>+ end="\<;\_s*then\>" end="\<fi\>" contains=@shIfList + syn region shFor matchgroup=shLoop start="\<for\ze\_s\s*\%(((\)\@!" end="\<in\>" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen skipwhite nextgroup=shCurlyIn + syn region shForPP matchgroup=shLoop start='\<for\>\_s*((' end='))' contains=shTestOpr endif -syn region shForPP matchgroup=shLoop start='\<for\>\_s*((' end='))' contains=shTestOpr if exists("b:is_kornshell") || exists("b:is_bash") syn cluster shCaseList add=shRepeat syn cluster shFunctionList add=shRepeat @@ -409,19 +409,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 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 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 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 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 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 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 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 endif endif @@ -577,7 +585,7 @@ hi def link shDoubleQuote shString hi def link shEcho shString hi def link shEchoDelim shOperator hi def link shEchoQuote shString -"hi def link shForPP shLoop +hi def link shForPP shLoop hi def link shEmbeddedEcho shString hi def link shEscape shCommandSub hi def link shExDoubleQuote shDoubleQuote @@ -604,7 +612,6 @@ hi def link shTestOpr shConditional hi def link shTestPattern shString hi def link shTestDoubleQuote shString hi def link shTestSingleQuote shString -hi def link shBQpairs shString hi def link shVariable shSetList hi def link shWrapLineOperator shOperator diff --git a/runtime/syntax/sm.vim b/runtime/syntax/sm.vim index ad96cdb3b5..8fdc14b71a 100644 --- a/runtime/syntax/sm.vim +++ b/runtime/syntax/sm.vim @@ -1,8 +1,8 @@ " Vim syntax file " Language: sendmail " Maintainer: Charles E. Campbell <NdrOchipS@PcampbellAfamily.Mbiz> -" Last Change: Jan 13, 2015 -" Version: 6 +" Last Change: Oct 23, 2014 +" Version: 7 " URL: http://www.drchip.org/astronaut/vim/index.html#SYNTAX_SM if exists("b:current_syntax") diff --git a/runtime/syntax/srec.vim b/runtime/syntax/srec.vim new file mode 100644 index 0000000000..19b6d97426 --- /dev/null +++ b/runtime/syntax/srec.vim @@ -0,0 +1,96 @@ +" Vim syntax file +" Language: Motorola S-Record +" Maintainer: Markus Heidelberg <markus.heidelberg@web.de> +" Last Change: 2015 Feb 24 + +" Each record (line) is built as follows: +" +" field digits states +" +" +----------+ +" | start | 1 ('S') srecRecStart +" +----------+ +" | type | 1 srecRecType, (srecRecTypeUnknown) +" +----------+ +" | count | 2 srecByteCount +" +----------+ +" | address | 4/6/8 srecNoAddress, srecDataAddress, srecRecCount, srecStartAddress, (srecAddressFieldUnknown) +" +----------+ +" | data | 0..504/502/500 srecDataOdd, srecDataEven, (srecDataUnexpected) +" +----------+ +" | checksum | 2 srecChecksum +" +----------+ +" +" States in parentheses in the upper format description indicate that they +" should not appear in a valid file. + +" For version 5.x: Clear all syntax items +" For version 6.x: Quit when a syntax file was already loaded +if version < 600 + syntax clear +elseif exists("b:current_syntax") + finish +endif + +syn match srecRecStart "^S" + +syn match srecRecTypeUnknown "^S." contains=srecRecStart +syn match srecRecType "^S[0-35-9]" contains=srecRecStart + +syn match srecByteCount "^S.[0-9a-fA-F]\{2}" contains=srecRecTypeUnknown nextgroup=srecAddressFieldUnknown,srecChecksum +syn match srecByteCount "^S[0-35-9][0-9a-fA-F]\{2}" contains=srecRecType + +syn match srecAddressFieldUnknown "[0-9a-fA-F]\{2}" contained nextgroup=srecAddressFieldUnknown,srecChecksum + +syn match srecNoAddress "^S0[0-9a-fA-F]\{6}" contains=srecByteCount nextgroup=srecDataOdd,srecChecksum +syn match srecDataAddress "^S1[0-9a-fA-F]\{6}" contains=srecByteCount nextgroup=srecDataOdd,srecChecksum +syn match srecDataAddress "^S2[0-9a-fA-F]\{8}" contains=srecByteCount nextgroup=srecDataOdd,srecChecksum +syn match srecDataAddress "^S3[0-9a-fA-F]\{10}" contains=srecByteCount nextgroup=srecDataOdd,srecChecksum +syn match srecRecCount "^S5[0-9a-fA-F]\{6}" contains=srecByteCount nextgroup=srecDataUnexpected,srecChecksum +syn match srecRecCount "^S6[0-9a-fA-F]\{8}" contains=srecByteCount nextgroup=srecDataUnexpected,srecChecksum +syn match srecStartAddress "^S7[0-9a-fA-F]\{10}" contains=srecByteCount nextgroup=srecDataUnexpected,srecChecksum +syn match srecStartAddress "^S8[0-9a-fA-F]\{8}" contains=srecByteCount nextgroup=srecDataUnexpected,srecChecksum +syn match srecStartAddress "^S9[0-9a-fA-F]\{6}" contains=srecByteCount nextgroup=srecDataUnexpected,srecChecksum + +" alternating highlight per byte for easier reading +syn match srecDataOdd "[0-9a-fA-F]\{2}" contained nextgroup=srecDataEven,srecChecksum +syn match srecDataEven "[0-9a-fA-F]\{2}" contained nextgroup=srecDataOdd,srecChecksum +" data bytes which should not exist +syn match srecDataUnexpected "[0-9a-fA-F]\{2}" contained nextgroup=srecDataUnexpected,srecChecksum +" Data digit pair regex usage also results in only highlighting the checksum +" if the number of data characters is even. + +syn match srecChecksum "[0-9a-fA-F]\{2}$" contained + +" Define the default highlighting. +" For version 5.7 and earlier: only when not done already +" For version 5.8 and later: only when an item doesn't have highlighting yet +if version >= 508 || !exists("did_srec_syntax_inits") + if version < 508 + let did_srec_syntax_inits = 1 + command -nargs=+ HiLink hi link <args> + else + command -nargs=+ HiLink hi def link <args> + endif + + " The default methods for highlighting. Can be overridden later + HiLink srecRecStart srecRecType + HiLink srecRecTypeUnknown srecRecType + HiLink srecRecType WarningMsg + HiLink srecByteCount Constant + hi def srecAddressFieldUnknown term=italic cterm=italic gui=italic + HiLink srecNoAddress DiffAdd + HiLink srecDataAddress Comment + HiLink srecRecCount srecNoAddress + HiLink srecStartAddress srecDataAddress + hi def srecDataOdd term=bold cterm=bold gui=bold + hi def srecDataEven term=NONE cterm=NONE gui=NONE + HiLink srecDataUnexpected Error + HiLink srecChecksum DiffChange + + delcommand HiLink +endif + +let b:current_syntax = "srec" + +" vim: ts=8 diff --git a/runtime/syntax/tex.vim b/runtime/syntax/tex.vim index dcdeca2e6c..f704766877 100644 --- a/runtime/syntax/tex.vim +++ b/runtime/syntax/tex.vim @@ -1,8 +1,8 @@ " Vim syntax file " Language: TeX " Maintainer: Charles E. Campbell <NdrchipO@ScampbellPfamily.AbizM> -" Last Change: Nov 18, 2014 -" Version: 83 +" Last Change: Apr 02, 2015 +" Version: 84 " URL: http://www.drchip.org/astronaut/vim/index.html#SYNTAX_TEX " " Notes: {{{1 @@ -391,10 +391,17 @@ endif " particular support for bold and italic {{{1 if s:tex_fast =~ 'b' if s:tex_conceal =~ 'b' - syn region texBoldStyle matchgroup=texTypeStyle start="\\textbf\s*{" end="}" concealends contains=@texBoldGroup - syn region texBoldItalStyle matchgroup=texTypeStyle start="\\textit\s*{" end="}" concealends contains=@texItalGroup - syn region texItalStyle matchgroup=texTypeStyle start="\\textit\s*{" end="}" concealends contains=@texItalGroup - syn region texItalBoldStyle matchgroup=texTypeStyle start="\\textbf\s*{" end="}" concealends contains=@texBoldGroup + if !exists("g:tex_nospell") || !g:tex_nospell + syn region texBoldStyle matchgroup=texTypeStyle start="\\textbf\s*\ze{" matchgroup=Delimiter end="}" concealends contains=@texBoldGroup,@Spell + syn region texBoldItalStyle matchgroup=texTypeStyle start="\\textit\s*\ze{" matchgroup=Delimiter end="}" concealends contains=@texItalGroup,@Spell + syn region texItalStyle matchgroup=texTypeStyle start="\\textit\s*\ze{" matchgroup=Delimiter end="}" concealends contains=@texItalGroup,@Spell + syn region texItalBoldStyle matchgroup=texTypeStyle start="\\textbf\s*\ze{" matchgroup=Delimiter end="}" concealends contains=@texBoldGroup,@Spell + else + syn region texBoldStyle matchgroup=texTypeStyle start="\\textbf\s*\ze{" matchgroup=Delimiter end="}" concealends contains=@texBoldGroup + syn region texBoldItalStyle matchgroup=texTypeStyle start="\\textit\s*\ze{" matchgroup=Delimiter end="}" concealends contains=@texItalGroup + syn region texItalStyle matchgroup=texTypeStyle start="\\textit\s*\ze{" matchgroup=Delimiter end="}" concealends contains=@texItalGroup + syn region texItalBoldStyle matchgroup=texTypeStyle start="\\textbf\s*\ze{" matchgroup=Delimiter end="}" concealends contains=@texBoldGroup + endif endif endif @@ -576,14 +583,14 @@ else syn match texComment "%.*$" contains=@texCommentGroup if s:tex_fast =~ 'c' syn region texComment start="^\zs\s*%.*\_s*%" skip="^\s*%" end='^\ze\s*[^%]' fold - syn region texNoSpell contained matchgroup=texComment start="%\s*nospell\s*{" end="%\s*nospell\s*}" fold contains=@texFoldGroup,@NoSpell - syn region texSpellZone matchgroup=texComment start="%\s*spellzone_start" end="%\s*spellzone_end" fold contains=@Spell,@texFoldGroup + syn region texNoSpell contained matchgroup=texComment start="%\s*nospell\s*{" end="%\s*nospell\s*}" fold contains=@texFoldGroup,@NoSpell + syn region texSpellZone matchgroup=texComment start="%\s*spellzone_start" end="%\s*spellzone_end" fold contains=@Spell,@texFoldGroup endif else - syn match texComment "%.*$" contains=@texCommentGroup + syn match texComment "%.*$" contains=@texCommentGroup if s:tex_fast =~ 'c' - syn region texNoSpell contained matchgroup=texComment start="%\s*nospell\s*{" end="%\s*nospell\s*}" contains=@texFoldGroup,@NoSpell - syn region texSpellZone matchgroup=texComment start="%\s*spellzone_start" end="%\s*spellzone_end" contains=@Spell,@texFoldGroup + syn region texNoSpell contained matchgroup=texComment start="%\s*nospell\s*{" end="%\s*nospell\s*}" contains=@texFoldGroup,@NoSpell + syn region texSpellZone matchgroup=texComment start="%\s*spellzone_start" end="%\s*spellzone_end" contains=@Spell,@texFoldGroup endif endif endif diff --git a/runtime/syntax/upstreamdat.vim b/runtime/syntax/upstreamdat.vim index 7be806730d..e3b415a4bc 100644 --- a/runtime/syntax/upstreamdat.vim +++ b/runtime/syntax/upstreamdat.vim @@ -1,13 +1,14 @@ " Vim syntax file " Language: Innovation Data Processing upstream.dat file " Maintainer: Rob Owens <rowens@fdrinnovation.com> -" Latest Revision: 2013-06-17 +" Latest Revision: 2013-11-27 " Quit when a syntax file was already loaded if exists("b:current_syntax") finish endif +" Parameters: syn keyword upstreamdat_Parameter ACCEPTPCREMOTE syn keyword upstreamdat_Parameter ACCEPTREMOTE syn keyword upstreamdat_Parameter ACTION @@ -291,6 +292,14 @@ syn keyword upstreamdat_Parameter XFERECORDSIZE syn keyword upstreamdat_Parameter XFERRECSEP syn keyword upstreamdat_Parameter XFERRECUSECR +" File Specs: +syn match upstreamdat_Filespec /file spec\c \d\{1,3}.*/ + +" Comments: +syn match upstreamdat_Comment /^#.*/ + hi def link upstreamdat_Parameter Type +"hi def link upstreamdat_Filespec Underlined +hi def link upstreamdat_Comment Comment let b:current_syntax = "upstreamdat" diff --git a/runtime/syntax/upstreamrpt.vim b/runtime/syntax/upstreamrpt.vim new file mode 100644 index 0000000000..170fc8f509 --- /dev/null +++ b/runtime/syntax/upstreamrpt.vim @@ -0,0 +1,310 @@ +" Vim syntax file +" Language: Innovation Data Processing upstream.rpt file +" Maintainer: Rob Owens <rowens@fdrinnovation.com> +" Latest Revision: 2014-03-13 + +" Quit when a syntax file was already loaded +if exists("b:current_syntax") + finish +endif + +setlocal foldmethod=syntax + +" Parameters: +syn keyword upstreamdat_Parameter ACCEPTPCREMOTE +syn keyword upstreamdat_Parameter ACCEPTREMOTE +syn keyword upstreamdat_Parameter ACTION +syn keyword upstreamdat_Parameter ACTIVATEONENTRY +syn keyword upstreamdat_Parameter ARCHIVEBIT +syn keyword upstreamdat_Parameter ARCHIVEBIT +syn keyword upstreamdat_Parameter ASCTOEBC +syn keyword upstreamdat_Parameter ASRBACKUP +syn keyword upstreamdat_Parameter ATTENDED +syn keyword upstreamdat_Parameter AUTHORITATIVE +syn keyword upstreamdat_Parameter AUTHORITATIVERESTORE +syn keyword upstreamdat_Parameter AUTHORITATIVERESTORE +syn keyword upstreamdat_Parameter BACKUPPROFILE +syn keyword upstreamdat_Parameter BACKUPPROFILE2 +syn keyword upstreamdat_Parameter BACKUPREPARSEFILES +syn keyword upstreamdat_Parameter BACKUPREPARSEFILES +syn keyword upstreamdat_Parameter BACKUPVERIFY +syn keyword upstreamdat_Parameter BLANKTRUNC +syn keyword upstreamdat_Parameter CALCDASDSIZE +syn keyword upstreamdat_Parameter CHANGEDIRATTRIBS +syn keyword upstreamdat_Parameter CHANGEDIRATTRIBS +syn keyword upstreamdat_Parameter COMPRESSLEVEL +syn keyword upstreamdat_Parameter CONTROLFILE +syn keyword upstreamdat_Parameter DASDOVERRIDE +syn keyword upstreamdat_Parameter DATELIMIT +syn keyword upstreamdat_Parameter DATELIMIT +syn keyword upstreamdat_Parameter DAYSOLD +syn keyword upstreamdat_Parameter DAYSOLD +syn keyword upstreamdat_Parameter DELETED +syn keyword upstreamdat_Parameter DELETED +syn keyword upstreamdat_Parameter DELETEPROMPTS +syn keyword upstreamdat_Parameter DELETEPROMPTS +syn keyword upstreamdat_Parameter DESTINATION +syn keyword upstreamdat_Parameter DESTINATION +syn keyword upstreamdat_Parameter DIRDELETE +syn keyword upstreamdat_Parameter DIRECTORVMC +syn keyword upstreamdat_Parameter DIRONLYRESTOREOK +syn keyword upstreamdat_Parameter DIRSONLY +syn keyword upstreamdat_Parameter DIRSONLY +syn keyword upstreamdat_Parameter DISASTERRECOVERY +syn keyword upstreamdat_Parameter DISPLAY +syn keyword upstreamdat_Parameter DRIVEALIAS +syn keyword upstreamdat_Parameter DRIVEALIAS +syn keyword upstreamdat_Parameter DUALCOPY +syn keyword upstreamdat_Parameter DUPDAYS +syn keyword upstreamdat_Parameter DUPLICATE +syn keyword upstreamdat_Parameter EBCTOASC +syn keyword upstreamdat_Parameter ENCRYPT +syn keyword upstreamdat_Parameter ENCRYPTLEVEL +syn keyword upstreamdat_Parameter EXCLUDELISTNAME +syn keyword upstreamdat_Parameter FAILBACKUPONERROR +syn keyword upstreamdat_Parameter FAILBACKUPONERROR +syn keyword upstreamdat_Parameter FAILIFNOFILES +syn keyword upstreamdat_Parameter FAILIFNOFILES +syn keyword upstreamdat_Parameter FAILIFSKIP +syn keyword upstreamdat_Parameter FAILJOB +syn keyword upstreamdat_Parameter FAILRESTOREONERROR +syn keyword upstreamdat_Parameter FAILRESTOREONERROR +syn keyword upstreamdat_Parameter FILEDATE +syn keyword upstreamdat_Parameter FILEDATE +syn keyword upstreamdat_Parameter FILEDELETE +syn keyword upstreamdat_Parameter FILEDELETE +syn keyword upstreamdat_Parameter FILES +syn keyword upstreamdat_Parameter FILES +syn keyword upstreamdat_Parameter FILESOPENFORUPDAT +syn keyword upstreamdat_Parameter FILESOPENFORUPDAT +syn keyword upstreamdat_Parameter FILETRANSFER +syn keyword upstreamdat_Parameter GETREMOTEFILES +syn keyword upstreamdat_Parameter HARDLINKDB +syn keyword upstreamdat_Parameter HARDLINKS +syn keyword upstreamdat_Parameter HARDLINKS +syn keyword upstreamdat_Parameter HIDDENFILES +syn keyword upstreamdat_Parameter HIDDENFILES +syn keyword upstreamdat_Parameter HOLDTAPE +syn keyword upstreamdat_Parameter HOLDUSERDIRS +syn keyword upstreamdat_Parameter HOSTFILENAME +syn keyword upstreamdat_Parameter HOSTRECORD +syn keyword upstreamdat_Parameter HOSTSORT +syn keyword upstreamdat_Parameter IGNOREPLUGINSFORRESTORE +syn keyword upstreamdat_Parameter INCRDB +syn keyword upstreamdat_Parameter INCRDBARCHIVEBIT +syn keyword upstreamdat_Parameter INCRDBDELETEDFILES +syn keyword upstreamdat_Parameter INCREMENTAL +syn keyword upstreamdat_Parameter INCREMENTAL +syn keyword upstreamdat_Parameter INQOPTIONS +syn keyword upstreamdat_Parameter INSTALLWIN2KAGENT +syn keyword upstreamdat_Parameter INSTALLWIN2KAGENT +syn keyword upstreamdat_Parameter JOBOPTIONS +syn keyword upstreamdat_Parameter JOBRETURNCODEMAP +syn keyword upstreamdat_Parameter JOBWAITTIMELIMIT +syn keyword upstreamdat_Parameter KEEPALIVE +syn keyword upstreamdat_Parameter LANINTERFACE +syn keyword upstreamdat_Parameter LANWSNAME +syn keyword upstreamdat_Parameter LANWSPASSWORD +syn keyword upstreamdat_Parameter LASTACCESS +syn keyword upstreamdat_Parameter LASTACCESS +syn keyword upstreamdat_Parameter LATESTDATE +syn keyword upstreamdat_Parameter LATESTDATE +syn keyword upstreamdat_Parameter LATESTTIME +syn keyword upstreamdat_Parameter LATESTTIME +syn keyword upstreamdat_Parameter LATESTVERSION +syn keyword upstreamdat_Parameter LINEBLOCK +syn keyword upstreamdat_Parameter LINETRUNC +syn keyword upstreamdat_Parameter LISTENFORREMOTE +syn keyword upstreamdat_Parameter LOCALBACKUP +syn keyword upstreamdat_Parameter LOCALBACKUPDIR +syn keyword upstreamdat_Parameter LOCALBACKUPMAX +syn keyword upstreamdat_Parameter LOCALBACKUPMAXFILESIZE +syn keyword upstreamdat_Parameter LOCALBACKUPMAXSIZE +syn keyword upstreamdat_Parameter LOCALEXCLUDEFILE +syn keyword upstreamdat_Parameter LOCALPARAMETERS +syn keyword upstreamdat_Parameter LOCALPASSWORD +syn keyword upstreamdat_Parameter LOCALRESTORE +syn keyword upstreamdat_Parameter LOCALUSER +syn keyword upstreamdat_Parameter LOFS +syn keyword upstreamdat_Parameter LOGNONFATAL +syn keyword upstreamdat_Parameter MAXBACKUPFILESFAIL +syn keyword upstreamdat_Parameter MAXBACKUPTIME +syn keyword upstreamdat_Parameter MAXDUPS +syn keyword upstreamdat_Parameter MAXFILENAMESIZE +syn keyword upstreamdat_Parameter MAXKFILESIZE +syn keyword upstreamdat_Parameter MAXLOGDAYS +syn keyword upstreamdat_Parameter MAXRESTOREFILESFAIL +syn keyword upstreamdat_Parameter MAXRESTORETIME +syn keyword upstreamdat_Parameter MAXRETRY +syn keyword upstreamdat_Parameter MAXRPTDAYS +syn keyword upstreamdat_Parameter MERGE +syn keyword upstreamdat_Parameter MIGRBITS +syn keyword upstreamdat_Parameter MIGRBITS +syn keyword upstreamdat_Parameter MINCOMPRESSSIZE +syn keyword upstreamdat_Parameter MINIMIZE +syn keyword upstreamdat_Parameter MODIFYFILE +syn keyword upstreamdat_Parameter MOUNTPOINTS +syn keyword upstreamdat_Parameter MOUNTPOINTS +syn keyword upstreamdat_Parameter NDS +syn keyword upstreamdat_Parameter NDS +syn keyword upstreamdat_Parameter NEWFILECOMPARE +syn keyword upstreamdat_Parameter NFSBELOW +syn keyword upstreamdat_Parameter NODATAOK +syn keyword upstreamdat_Parameter NODIRFORINCREMENTAL +syn keyword upstreamdat_Parameter NODIRFORINCREMENTAL +syn keyword upstreamdat_Parameter NONFILEDATABITMAP +syn keyword upstreamdat_Parameter NONFILEDATABITMAP +syn keyword upstreamdat_Parameter NOPOINTRESTORE +syn keyword upstreamdat_Parameter NOSPECINHERITANCE +syn keyword upstreamdat_Parameter NOTIFYEVENTS +syn keyword upstreamdat_Parameter NOTIFYFAILUREATTACHMENT +syn keyword upstreamdat_Parameter NOTIFYSUCCESSATTACHMENT +syn keyword upstreamdat_Parameter NOTIFYTARGETS +syn keyword upstreamdat_Parameter NOUIDGIDNAMES +syn keyword upstreamdat_Parameter NOUIDGIDNAMES +syn keyword upstreamdat_Parameter NOVELLMIGRATE +syn keyword upstreamdat_Parameter NOVELLMIGRATE +syn keyword upstreamdat_Parameter NOVELLMIGRATEADDEXT +syn keyword upstreamdat_Parameter NOVELLMIGRATEADDEXT +syn keyword upstreamdat_Parameter NOVELLPROFILE +syn keyword upstreamdat_Parameter NOVELLRECALL +syn keyword upstreamdat_Parameter NTFSADDPERMISSION +syn keyword upstreamdat_Parameter NTFSADDPERMISSION +syn keyword upstreamdat_Parameter NTREGRESTORE +syn keyword upstreamdat_Parameter OSTYPE +syn keyword upstreamdat_Parameter OUTPORT +syn keyword upstreamdat_Parameter PACKFLUSHAFTERFILE +syn keyword upstreamdat_Parameter PACKRECSIZE +syn keyword upstreamdat_Parameter PARAMETER +syn keyword upstreamdat_Parameter PASSWORD +syn keyword upstreamdat_Parameter PATHNAME +syn keyword upstreamdat_Parameter PATHNAME +syn keyword upstreamdat_Parameter PERFORMBITMAP +syn keyword upstreamdat_Parameter PERFORMNUMRECORDS +syn keyword upstreamdat_Parameter PERFORMRECORDSIZE +syn keyword upstreamdat_Parameter PLUGIN +syn keyword upstreamdat_Parameter PLUGIN +syn keyword upstreamdat_Parameter PLUGINPARAMETERS +syn keyword upstreamdat_Parameter PLUGINPARAMETERS +syn keyword upstreamdat_Parameter POSTJOB +syn keyword upstreamdat_Parameter PREJOB +syn keyword upstreamdat_Parameter PRTYCLASS +syn keyword upstreamdat_Parameter PRTYLEVEL +syn keyword upstreamdat_Parameter RECALLCLEANUP +syn keyword upstreamdat_Parameter RECALLOFFLINEFILES +syn keyword upstreamdat_Parameter RECALLOFFLINEFILES +syn keyword upstreamdat_Parameter RECORDSIZE +syn keyword upstreamdat_Parameter REMOTEADDR +syn keyword upstreamdat_Parameter REMOTEAPPLPREF +syn keyword upstreamdat_Parameter REMOTEAPPLRETRY +syn keyword upstreamdat_Parameter REMOTECONNECTTYPE +syn keyword upstreamdat_Parameter REMOTEFLAGS +syn keyword upstreamdat_Parameter REMOTEIPADAPTER +syn keyword upstreamdat_Parameter REMOTELOCALPARAMETERS +syn keyword upstreamdat_Parameter REMOTELOGMODE +syn keyword upstreamdat_Parameter REMOTELUNAME +syn keyword upstreamdat_Parameter REMOTEMAXRETRIES +syn keyword upstreamdat_Parameter REMOTEMODENAME +syn keyword upstreamdat_Parameter REMOTEPARAMETERFILE +syn keyword upstreamdat_Parameter REMOTEPORT +syn keyword upstreamdat_Parameter REMOTEREQUEST +syn keyword upstreamdat_Parameter REMOTERESTART +syn keyword upstreamdat_Parameter REMOTEROUTE +syn keyword upstreamdat_Parameter REMOTETARGETNAME +syn keyword upstreamdat_Parameter REMOTETCP +syn keyword upstreamdat_Parameter REMOTETIMEOUT +syn keyword upstreamdat_Parameter REMOTETMAXRETRY +syn keyword upstreamdat_Parameter REMOTETPN +syn keyword upstreamdat_Parameter REMOTEUSAPPL +syn keyword upstreamdat_Parameter REMOTEVERIFY +syn keyword upstreamdat_Parameter REMOTEWTOCOMP +syn keyword upstreamdat_Parameter REPORTNAME +syn keyword upstreamdat_Parameter REPORTOPTIONS +syn keyword upstreamdat_Parameter RESTARTLASTFILE +syn keyword upstreamdat_Parameter RESTART +syn keyword upstreamdat_Parameter RESTARTTYPE +syn keyword upstreamdat_Parameter RESTARTVERSIONDATE +syn keyword upstreamdat_Parameter RESTOREARCHIVEBIT +syn keyword upstreamdat_Parameter RESTORECHECKPOINT +syn keyword upstreamdat_Parameter RESTOREDATELIMIT +syn keyword upstreamdat_Parameter RESTOREDATELIMIT +syn keyword upstreamdat_Parameter RESTOREFILEFAIL +syn keyword upstreamdat_Parameter RESTOREMOUNTPOINTS +syn keyword upstreamdat_Parameter RESTOREMOUNTPOINTS +syn keyword upstreamdat_Parameter RESTORESEGMENTS +syn keyword upstreamdat_Parameter RESTORESEGMENTS +syn keyword upstreamdat_Parameter RESTORETODIFFFS +syn keyword upstreamdat_Parameter RETAIN +syn keyword upstreamdat_Parameter RETAIN +syn keyword upstreamdat_Parameter ROOTENTRY +syn keyword upstreamdat_Parameter ROOTENTRY +syn keyword upstreamdat_Parameter SAN +syn keyword upstreamdat_Parameter SCHEDULENAME +syn keyword upstreamdat_Parameter SEGMENTEDFILESIZE +syn keyword upstreamdat_Parameter SEGMENTEDFILESIZE +syn keyword upstreamdat_Parameter SEGMENTSIZE +syn keyword upstreamdat_Parameter SEGMENTSIZE +syn keyword upstreamdat_Parameter SENDHOSTDETAILS +syn keyword upstreamdat_Parameter SINGLEFS +syn keyword upstreamdat_Parameter SIZETRC +syn keyword upstreamdat_Parameter SKIP +syn keyword upstreamdat_Parameter SKIPBACKUPSCAN +syn keyword upstreamdat_Parameter SKIPOLD +syn keyword upstreamdat_Parameter SKIPOLD +syn keyword upstreamdat_Parameter SMSTARGETSERVICENAME +syn keyword upstreamdat_Parameter SMSTSA +syn keyword upstreamdat_Parameter SOLO +syn keyword upstreamdat_Parameter SORTBACKUP +syn keyword upstreamdat_Parameter SOSDISK +syn keyword upstreamdat_Parameter SOSDISK +syn keyword upstreamdat_Parameter SOSTIMESTAMP +syn keyword upstreamdat_Parameter SOSTIMESTAMP +syn keyword upstreamdat_Parameter SOSTIMESTAMPPATH +syn keyword upstreamdat_Parameter SOSTIMESTAMPPATH +syn keyword upstreamdat_Parameter SPECNUMBER +syn keyword upstreamdat_Parameter SPECNUMBER +syn keyword upstreamdat_Parameter SPECTYPE +syn keyword upstreamdat_Parameter SPECTYPE +syn keyword upstreamdat_Parameter STARTTIME +syn keyword upstreamdat_Parameter STORAGETYPE +syn keyword upstreamdat_Parameter SUBDIRECTORIES +syn keyword upstreamdat_Parameter SUBDIRECTORIES +syn keyword upstreamdat_Parameter SWITCHTOTAPEMB +syn keyword upstreamdat_Parameter TCPADDRESS +syn keyword upstreamdat_Parameter TCPTIMEOUT +syn keyword upstreamdat_Parameter TIMEOVERRIDE +syn keyword upstreamdat_Parameter TRACE +syn keyword upstreamdat_Parameter TRANSLATE +syn keyword upstreamdat_Parameter ULTRACOMP +syn keyword upstreamdat_Parameter ULTREG +syn keyword upstreamdat_Parameter ULTUPD +syn keyword upstreamdat_Parameter UNCMACHINEALIAS +syn keyword upstreamdat_Parameter UNCMACHINEALIAS +syn keyword upstreamdat_Parameter USEALEBRA +syn keyword upstreamdat_Parameter USECONTROLFILE +syn keyword upstreamdat_Parameter USEGID +syn keyword upstreamdat_Parameter USERID +syn keyword upstreamdat_Parameter USEUID +syn keyword upstreamdat_Parameter USNOUIDGIDERRORS +syn keyword upstreamdat_Parameter UTF8 +syn keyword upstreamdat_Parameter VAULTNUMBER +syn keyword upstreamdat_Parameter VERSIONDATE +syn keyword upstreamdat_Parameter WRITESPARSE +syn keyword upstreamdat_Parameter XFERECORDSIZE +syn keyword upstreamdat_Parameter XFERRECSEP +syn keyword upstreamdat_Parameter XFERRECUSECR + +" File Specs: +syn match upstreamdat_Filespec /file spec\c \d\{1,3}.*/ + +" Comments: +syn match upstreamdat_Comment /^#.*/ + +" List Of Parameters: +syn region upstreamdat_Parms start="Current Parameters:" end="End Of Parameters" transparent fold + +hi def link upstreamdat_Parameter Type +"hi def link upstreamdat_Filespec Underlined +hi def link upstreamdat_Comment Comment + +let b:current_syntax = "upstreamdat" diff --git a/runtime/syntax/usw2kagtlog.vim b/runtime/syntax/usw2kagtlog.vim index 0a34128f9b..a112340d12 100644 --- a/runtime/syntax/usw2kagtlog.vim +++ b/runtime/syntax/usw2kagtlog.vim @@ -1,7 +1,7 @@ " Vim syntax file " Language: Innovation Data Processing USW2KAgt.log file " Maintainer: Rob Owens <rowens@fdrinnovation.com> -" Latest Revision: 2013-09-19 +" Latest Revision: 2014-04-01 " Quit when a syntax file was already loaded if exists("b:current_syntax") @@ -17,8 +17,12 @@ syn match usw2kagtlog_MsgI /Msg #\(Agt\|PC\|Srv\)\d\{4,5}I/ nextgroup=usw2kagtlo syn match usw2kagtlog_MsgW /Msg #\(Agt\|PC\|Srv\)\d\{4,5}W/ nextgroup=usw2kagtlog_Process skipwhite " Processes: syn region usw2kagtlog_Process start="(" end=")" contained -syn region usw2kagtlog_Process start="Starting the processing for a \zs\"" end="\ze client request" -syn region usw2kagtlog_Process start="Ending the processing for a \zs\"" end="\ze client request" +"syn region usw2kagtlog_Process start="Starting the processing for a \zs\"" end="\ze client request" +"syn region usw2kagtlog_Process start="Ending the processing for a \zs\"" end="\ze client request" +"syn region usw2kagtlog_Process start="Starting the processing for a \zs\"" end="\ze client\s\{0,1}\r\{0,1}\s\{1,9}request" +"syn region usw2kagtlog_Process start="Ending the processing for a \zs\"" end="\ze client\s\{0,1}\r\{0,1}\s\{1,9}request" +syn region usw2kagtlog_Process start="Starting the processing for a \zs\"" end="\ze client" +syn region usw2kagtlog_Process start="Ending the processing for a \zs\"" end="\ze client" " IP Address: syn match usw2kagtlog_IPaddr / \d\{1,3}\.\d\{1,3}\.\d\{1,3}\.\d\{1,3}/ " Profile: diff --git a/runtime/syntax/yacc.vim b/runtime/syntax/yacc.vim index 9dc6cccb2d..977ffa75e4 100644 --- a/runtime/syntax/yacc.vim +++ b/runtime/syntax/yacc.vim @@ -1,8 +1,8 @@ " Vim syntax file " Language: Yacc " Maintainer: Charles E. Campbell <NdrOchipS@PcampbellAfamily.Mbiz> -" Last Change: Jan 14, 2015 -" Version: 12 +" Last Change: Apr 02, 2015 +" Version: 13 " URL: http://mysite.verizon.net/astronaut/vim/index.html#vimlinks_syntax " " Options: {{{1 diff --git a/runtime/syntax/yaml.vim b/runtime/syntax/yaml.vim index 073dbf7418..626dc8a77f 100644 --- a/runtime/syntax/yaml.vim +++ b/runtime/syntax/yaml.vim @@ -2,7 +2,7 @@ " Language: YAML (YAML Ain't Markup Language) 1.2 " Maintainer: Nikolai Pavlov <zyx.vim@gmail.com> " First author: Nikolai Weibull <now@bitwi.se> -" Latest Revision: 2010-10-08 +" Latest Revision: 2015-03-28 if exists('b:current_syntax') finish @@ -11,13 +11,40 @@ endif let s:cpo_save = &cpo set cpo&vim -let s:ns_char = '\%(\%([\n\r\uFEFF \t]\)\@!\p\)' -let s:ns_word_char = '\%(\w\|-\)' -let s:ns_uri_char = '\%(%\x\x\|'.s:ns_word_char.'\|[#/;?:@&=+$,.!~*''()\[\]]\)' +" Choose the schema to use +" TODO: Validate schema +if !exists('b:yaml_schema') + if exists('g:yaml_schema') + let b:yaml_schema = g:yaml_schema + else + let b:yaml_schema = 'core' + endif +endif + +let s:ns_char = '\%([\n\r\uFEFF \t]\@!\p\)' +let s:ns_word_char = '[[:alnum:]_\-]' +let s:ns_uri_char = '\%(%\x\x\|'.s:ns_word_char.'\|[#/;?:@&=+$,.!~*''()[\]]\)' let s:ns_tag_char = '\%(%\x\x\|'.s:ns_word_char.'\|[#/;?:@&=+$.~*''()]\)' -let s:c_ns_anchor_char = '\%(\%([\n\r\uFEFF \t,\[\]{}]\)\@!\p\)' -let s:c_indicator = '[\-?:,\[\]{}#&*!|>''"%@`]' -let s:c_flow_indicator = '[,\[\]{}]' +let s:c_ns_anchor_char = '\%([\n\r\uFEFF \t,[\]{}]\@!\p\)' +let s:c_indicator = '[\-?:,[\]{}#&*!|>''"%@`]' +let s:c_flow_indicator = '[,[\]{}]' + +let s:ns_char_without_c_indicator = substitute(s:ns_char, '\v\C[\zs', '\=s:c_indicator[1:-2]', '') + +let s:_collection = '[^\@!\(\%(\\\.\|\[^\\\]]\)\+\)]' +let s:_neg_collection = '[^\(\%(\\\.\|\[^\\\]]\)\+\)]' +function s:SimplifyToAssumeAllPrintable(p) + return substitute(a:p, '\V\C\\%('.s:_collection.'\\@!\\p\\)', '[^\1]', '') +endfunction +let s:ns_char = s:SimplifyToAssumeAllPrintable(s:ns_char) +let s:ns_char_without_c_indicator = s:SimplifyToAssumeAllPrintable(s:ns_char_without_c_indicator) +let s:c_ns_anchor_char = s:SimplifyToAssumeAllPrintable(s:c_ns_anchor_char) + +function s:SimplifyAdjacentCollections(p) + return substitute(a:p, '\V\C'.s:_collection.'\\|'.s:_collection, '[\1\2]', 'g') +endfunction +let s:ns_uri_char = s:SimplifyAdjacentCollections(s:ns_uri_char) +let s:ns_tag_char = s:SimplifyAdjacentCollections(s:ns_tag_char) let s:c_verbatim_tag = '!<'.s:ns_uri_char.'\+>' let s:c_named_tag_handle = '!'.s:ns_word_char.'\+!' @@ -46,11 +73,15 @@ let s:ns_tag_prefix = s:ns_local_tag_prefix. let s:ns_plain_safe_out = s:ns_char let s:ns_plain_safe_in = '\%('.s:c_flow_indicator.'\@!'.s:ns_char.'\)' -let s:ns_plain_first_in = '\%('.s:c_indicator.'\@!'.s:ns_char.'\|[?:\-]\%('.s:ns_plain_safe_in.'\)\@=\)' -let s:ns_plain_first_out = '\%('.s:c_indicator.'\@!'.s:ns_char.'\|[?:\-]\%('.s:ns_plain_safe_out.'\)\@=\)' +let s:ns_plain_safe_in = substitute(s:ns_plain_safe_in, '\V\C\\%('.s:_collection.'\\@!'.s:_neg_collection.'\\)', '[^\1\2]', '') +let s:ns_plain_safe_in_without_colhash = substitute(s:ns_plain_safe_in, '\V\C'.s:_neg_collection, '[^\1:#]', '') +let s:ns_plain_safe_out_without_colhash = substitute(s:ns_plain_safe_out, '\V\C'.s:_neg_collection, '[^\1:#]', '') -let s:ns_plain_char_in = '\%('.s:ns_char.'#\|:'.s:ns_plain_safe_in.'\|[:#]\@!'.s:ns_plain_safe_in.'\)' -let s:ns_plain_char_out = '\%('.s:ns_char.'#\|:'.s:ns_plain_safe_out.'\|[:#]\@!'.s:ns_plain_safe_out.'\)' +let s:ns_plain_first_in = '\%('.s:ns_char_without_c_indicator.'\|[?:\-]\%('.s:ns_plain_safe_in.'\)\@=\)' +let s:ns_plain_first_out = '\%('.s:ns_char_without_c_indicator.'\|[?:\-]\%('.s:ns_plain_safe_out.'\)\@=\)' + +let s:ns_plain_char_in = '\%('.s:ns_char.'#\|:'.s:ns_plain_safe_in.'\|'.s:ns_plain_safe_in_without_colhash.'\)' +let s:ns_plain_char_out = '\%('.s:ns_char.'#\|:'.s:ns_plain_safe_out.'\|'.s:ns_plain_safe_out_without_colhash.'\)' let s:ns_plain_out = s:ns_plain_first_out . s:ns_plain_char_out.'*' let s:ns_plain_in = s:ns_plain_first_in . s:ns_plain_char_in.'*' @@ -89,9 +120,11 @@ syn match yamlSingleEscape contained "''" syn match yamlBlockScalarHeader contained '\s\+\zs[|>]\%([+-]\=[1-9]\|[1-9]\=[+-]\)\=' +syn cluster yamlConstant contains=yamlBool,yamlNull + syn cluster yamlFlow contains=yamlFlowString,yamlFlowMapping,yamlFlowCollection syn cluster yamlFlow add=yamlFlowMappingKey,yamlFlowMappingMerge -syn cluster yamlFlow add=yamlConstant,yamlPlainScalar,yamlFloat +syn cluster yamlFlow add=@yamlConstant,yamlPlainScalar,yamlFloat syn cluster yamlFlow add=yamlTimestamp,yamlInteger,yamlMappingKeyStart syn cluster yamlFlow add=yamlComment syn region yamlFlowMapping matchgroup=yamlFlowIndicator start='{' end='}' contains=@yamlFlow @@ -103,15 +136,15 @@ execute 'syn match yamlPlainScalar contained /'.s:ns_plain_in.'/' syn match yamlMappingKeyStart '?\ze\s' syn match yamlMappingKeyStart '?' contained -execute 'syn match yamlFlowMappingKey /'.s:ns_plain_in.'\ze\s*:/ contained '. +execute 'syn match yamlFlowMappingKey /\%#=1'.s:ns_plain_in.'\%(\s\+'.s:ns_plain_in.'\)*\ze\s*:/ contained '. \'nextgroup=yamlKeyValueDelimiter' syn match yamlFlowMappingMerge /<<\ze\s*:/ contained nextgroup=yamlKeyValueDelimiter syn match yamlBlockCollectionItemStart '^\s*\zs-\%(\s\+-\)*\s' nextgroup=yamlBlockMappingKey,yamlBlockMappingMerge " Use the old regexp engine, the NFA engine doesn't like all the \@ items. -execute 'syn match yamlBlockMappingKey /\%#=1^\s*\zs'.s:ns_plain_out.'\ze\s*:\%(\s\|$\)/ '. +execute 'syn match yamlBlockMappingKey /\%#=1^\s*\zs'.s:ns_plain_out.'\%(\s\+'.s:ns_plain_out.'\)*\ze\s*:\%(\s\|$\)/ '. \'nextgroup=yamlKeyValueDelimiter' -execute 'syn match yamlBlockMappingKey /\%#=1\s*\zs'.s:ns_plain_out.'\ze\s*:\%(\s\|$\)/ contained '. +execute 'syn match yamlBlockMappingKey /\%#=1\s*\zs'.s:ns_plain_out.'\%(\s\+'.s:ns_plain_out.'\)*\ze\s*:\%(\s\|$\)/ contained '. \'nextgroup=yamlKeyValueDelimiter' syn match yamlBlockMappingMerge /^\s*\zs<<\ze:\%(\s\|$\)/ nextgroup=yamlKeyValueDelimiter syn match yamlBlockMappingMerge /<<\ze\s*:\%(\s\|$\)/ nextgroup=yamlKeyValueDelimiter contained @@ -119,14 +152,32 @@ syn match yamlBlockMappingMerge /<<\ze\s*:\%(\s\|$\)/ nextgroup=yamlKeyValueDeli syn match yamlKeyValueDelimiter /\s*:/ contained syn match yamlKeyValueDelimiter /\s*:/ contained -syn keyword yamlConstant true True TRUE false False FALSE -syn keyword yamlConstant null Null NULL -syn match yamlConstant '\<\~\>' - -syn match yamlTimestamp /\%([\[\]{}, \t]\@!\p\)\@<!\%(\d\{4}-\d\d\=-\d\d\=\%(\%([Tt]\|\s\+\)\%(\d\d\=\):\%(\d\d\):\%(\d\d\)\%(\.\%(\d*\)\)\=\%(\s*\%(Z\|[+-]\d\d\=\%(:\d\d\)\=\)\)\=\)\=\)\%([\[\]{}, \t]\@!\p\)\@!/ +syn cluster yamlScalarWithSpecials contains=yamlPlainScalar,yamlBlockMappingKey,yamlFlowMappingKey + +let s:_bounder = s:SimplifyToAssumeAllPrintable('\%([[\]{}, \t]\@!\p\)') +if b:yaml_schema is# 'json' + syn keyword yamlNull null contained containedin=@yamlScalarWithSpecials + syn keyword yamlBool true false + exe 'syn match yamlInteger /'.s:_bounder.'\@1<!\%(0\|-\=[1-9][0-9]*\)'.s:_bounder.'\@!/ contained containedin=@yamlScalarWithSpecials' + exe 'syn match yamlFloat /'.s:_bounder.'\@1<!\%(-\=[1-9][0-9]*\%(\.[0-9]*\)\=\(e[-+]\=[0-9]\+\)\=\|0\|-\=\.inf\|\.nan\)'.s:_bounder.'\@!/ contained containedin=@yamlScalarWithSpecials' +elseif b:yaml_schema is# 'core' + syn keyword yamlNull null Null NULL contained containedin=@yamlScalarWithSpecials + syn keyword yamlBool true True TRUE false False FALSE contained containedin=@yamlScalarWithSpecials + exe 'syn match yamlNull /'.s:_bounder.'\@1<!\~'.s:_bounder.'\@!/ contained containedin=@yamlScalarWithSpecials' + exe 'syn match yamlInteger /'.s:_bounder.'\@1<!\%([+-]\=\%(0\%(b[0-1_]\+\|[0-7_]\+\|x[0-9a-fA-F_]\+\)\=\|\%([1-9][0-9_]*\%(:[0-5]\=\d\)\+\)\)\|[1-9][0-9_]*\)'.s:_bounder.'\@!/ contained containedin=@yamlScalarWithSpecials' + exe 'syn match yamlFloat /'.s:_bounder.'\@1<!\%([+-]\=\%(\%(\d[0-9_]*\)\.[0-9_]*\%([eE][+-]\=\d\+\)\=\|\.[0-9_]\+\%([eE][-+]\=[0-9]\+\)\=\|\d[0-9_]*\%(:[0-5]\=\d\)\+\.[0-9_]*\|\.\%(inf\|Inf\|INF\)\)\|\%(\.\%(nan\|NaN\|NAN\)\)\)'.s:_bounder.'\@!/ contained containedin=@yamlScalarWithSpecials' +elseif b:yaml_schema is# 'pyyaml' + syn keyword yamlNull null Null NULL contained containedin=@yamlScalarWithSpecials + syn keyword yamlBool true True TRUE false False FALSE yes Yes YES no No NO on On ON off Off OFF contained containedin=@yamlScalarWithSpecials + exe 'syn match yamlNull /'.s:_bounder.'\@1<!\~'.s:_bounder.'\@!/ contained containedin=@yamlScalarWithSpecials' + exe 'syn match yamlFloat /'.s:_bounder.'\@1<!\%(\v[-+]?%(\d[0-9_]*)\.[0-9_]*%([eE][-+]\d+)?|\.[0-9_]+%([eE][-+]\d+)?|[-+]?\d[0-9_]*%(\:[0-5]?\d)+\.[0-9_]*|[-+]?\.%(inf|Inf|INF)|\.%(nan|NaN|NAN)\m\)'.s:_bounder.'\@!/ contained containedin=@yamlScalarWithSpecials' + exe 'syn match yamlInteger /'.s:_bounder.'\@1<!\%(\v[-+]?0b[0-1_]+|[-+]?0[0-7_]+|[-+]?%(0|[1-9][0-9_]*)|[-+]?0x[0-9a-fA-F_]+|[-+]?[1-9][0-9_]*%(:[0-5]?\d)+\m\)'.s:_bounder.'\@!/ contained containedin=@yamlScalarWithSpecials' + exe 'syn match yamlTimestamp /'.s:_bounder.'\@1<!\%(\v\d\d\d\d\-\d\d\-\d\d|\d\d\d\d \-\d\d? \-\d\d?%([Tt]|[ \t]+)\d\d?\:\d\d \:\d\d %(\.\d*)?%([ \t]*%(Z|[-+]\d\d?%(\:\d\d)?))?\m\)'.s:_bounder.'\@!/ contained containedin=@yamlScalarWithSpecials' +elseif b:yaml_schema is# 'failsafe' + " Nothing +endif +unlet s:_bounder -syn match yamlInteger /\%([\[\]{}, \t]\@!\p\)\@<!\%([+-]\=\%(0\%(b[0-1_]\+\|[0-7_]\+\|x[0-9a-fA-F_]\+\)\=\|\%([1-9][0-9_]*\%(:[0-5]\=\d\)\+\)\)\|[1-9][0-9_]*\)\%([\[\]{}, \t]\@!\p\)\@!/ -syn match yamlFloat /\%([\[\]{}, \t]\@!\p\)\@<!\%([+-]\=\%(\%(\d[0-9_]*\)\.[0-9_]*\%([eE][+-]\d\+\)\=\|\.[0-9_]\+\%([eE][-+][0-9]\+\)\=\|\d[0-9_]*\%(:[0-5]\=\d\)\+\.[0-9_]*\|\.\%(inf\|Inf\|INF\)\)\|\%(\.\%(nan\|NaN\|NAN\)\)\)\%([\[\]{}, \t]\@!\p\)\@!/ execute 'syn match yamlNodeTag '.string(s:c_ns_tag_property) execute 'syn match yamlAnchor '.string(s:c_ns_anchor_property) @@ -170,6 +221,9 @@ hi def link yamlKeyValueDelimiter Special hi def link yamlConstant Constant +hi def link yamlNull yamlConstant +hi def link yamlBool yamlConstant + hi def link yamlAnchor Type hi def link yamlAlias Type hi def link yamlNodeTag Type @@ -180,8 +234,10 @@ hi def link yamlTimestamp Number let b:current_syntax = "yaml" -unlet s:ns_word_char s:ns_uri_char s:c_verbatim_tag s:c_named_tag_handle s:c_secondary_tag_handle s:c_primary_tag_handle s:c_tag_handle s:ns_tag_char s:c_ns_shorthand_tag s:c_non_specific_tag s:c_ns_tag_property s:c_ns_anchor_char s:c_ns_anchor_name s:c_ns_anchor_property s:c_ns_alias_node s:ns_char s:ns_directive_name s:ns_local_tag_prefix s:ns_global_tag_prefix s:ns_tag_prefix s:c_indicator s:ns_plain_safe_out s:c_flow_indicator s:ns_plain_safe_in s:ns_plain_first_in s:ns_plain_first_out s:ns_plain_char_in s:ns_plain_char_out s:ns_plain_out s:ns_plain_in +unlet s:ns_word_char s:ns_uri_char s:c_verbatim_tag s:c_named_tag_handle s:c_secondary_tag_handle s:c_primary_tag_handle s:c_tag_handle s:ns_tag_char s:c_ns_shorthand_tag s:c_non_specific_tag s:c_ns_tag_property s:c_ns_anchor_char s:c_ns_anchor_name s:c_ns_anchor_property s:c_ns_alias_node s:ns_char s:ns_directive_name s:ns_local_tag_prefix s:ns_global_tag_prefix s:ns_tag_prefix s:c_indicator s:ns_plain_safe_out s:c_flow_indicator s:ns_plain_safe_in s:ns_plain_first_in s:ns_plain_first_out s:ns_plain_char_in s:ns_plain_char_out s:ns_plain_out s:ns_plain_in s:ns_char_without_c_indicator s:ns_plain_safe_in_without_colhash s:ns_plain_safe_out_without_colhash +unlet s:_collection s:_neg_collection +delfunction s:SimplifyAdjacentCollections +delfunction s:SimplifyToAssumeAllPrintable let &cpo = s:cpo_save unlet s:cpo_save - diff --git a/runtime/vimrc_example.vim b/runtime/vimrc_example.vim index 97f646b91a..48c7a3535a 100644 --- a/runtime/vimrc_example.vim +++ b/runtime/vimrc_example.vim @@ -34,10 +34,8 @@ augroup vimrcEx " When editing a file, always jump to the last known cursor position. " Don't do it when the position is invalid or when inside an event handler - " Also don't do it when the mark is in the first line, that is the default - " position when opening a file. autocmd BufReadPost * - \ if line("'\"") > 1 && line("'\"") <= line("$") | + \ if line("'\"") >= 1 && line("'\"") <= line("$") | \ execute "normal! g`\"" | \ endif diff --git a/scripts/vim-patch.sh b/scripts/vim-patch.sh index c0934a17e3..bdd3d6209b 100755 --- a/scripts/vim-patch.sh +++ b/scripts/vim-patch.sh @@ -161,29 +161,19 @@ list_vim_patches() { printf "\nVim patches missing from Neovim:\n" - # Get tags since 7.4.442. - local vim_tags=$(cd "${VIM_SOURCE_DIR}" && git tag --contains v7.4.442) - - # Get non-versioned commits since e2719096. - if git log -1 --grep='.' --invert-grep > /dev/null 2>&1 ; then - local vim_runtime_commits=$(cd "${VIM_SOURCE_DIR}" && \ - git log --reverse --format='%H' --grep='^patch' --grep='^updated for version' \ - --invert-grep e2719096250a19ecdd9a35d13702879f163d2a50..HEAD) - else # --invert-grep requires git 2.4+ - echo "Warning: some runtime updates may not be listed (requires git 2.4+)." - local vim_runtime_commits=$(cd "${VIM_SOURCE_DIR}" && \ - git log --reverse --format='%H' --grep='Updated' e2719096250a19ecdd9a35d13702879f163d2a50..HEAD) - fi + # Get commits since 7.4.602. + local vim_commits=$(cd "${VIM_SOURCE_DIR}" && git log --reverse --format='%H' v7.4.602..HEAD) local vim_commit - for vim_commit in ${vim_tags} ${vim_runtime_commits}; do + for vim_commit in ${vim_commits}; do local is_missing - if [[ ${vim_commit} =~ v([0-9].[0-9].([0-9]{3,4})) ]]; then - local patch_number="${BASH_REMATCH[2]}" + local vim_tag=$(cd "${VIM_SOURCE_DIR}" && git describe --tags --exact-match "${vim_commit}" 2>/dev/null) + if [[ -n "${vim_tag}" ]]; then + 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:]]*//${patch_number} NA" -e "[[:space:]]*${patch_number}," >/dev/null && echo "false" || echo "true")" - vim_commit="${BASH_REMATCH[1]//-/.}" + 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: is_missing="$(cd "${NEOVIM_SOURCE_DIR}" && @@ -203,6 +193,9 @@ list_vim_patches() { echo echo " Examples: '${BASENAME} -p 7.4.487'" echo " '${BASENAME} -p 1e8ebf870720e7b671f98f22d653009826304c4f'" + echo + echo " NOTE: Please port the _oldest_ patch if you possibly can." + echo " Out-of-order patches increase the possibility of bugs." } review_pr() { diff --git a/src/nvim/ascii.h b/src/nvim/ascii.h index 2b3e94d5a0..44ff540b40 100644 --- a/src/nvim/ascii.h +++ b/src/nvim/ascii.h @@ -85,10 +85,25 @@ # define PATHSEPSTR "/" #endif -static inline bool ascii_iswhite(int) REAL_FATTR_ALWAYS_INLINE REAL_FATTR_CONST; -static inline bool ascii_isdigit(int) REAL_FATTR_ALWAYS_INLINE REAL_FATTR_CONST; -static inline bool ascii_isxdigit(int) REAL_FATTR_ALWAYS_INLINE REAL_FATTR_CONST; -static inline bool ascii_isspace(int) REAL_FATTR_ALWAYS_INLINE REAL_FATTR_CONST; +static inline bool ascii_iswhite(int) + REAL_FATTR_CONST + REAL_FATTR_ALWAYS_INLINE; + +static inline bool ascii_isdigit(int) + REAL_FATTR_CONST + REAL_FATTR_ALWAYS_INLINE; + +static inline bool ascii_isxdigit(int) + REAL_FATTR_CONST + REAL_FATTR_ALWAYS_INLINE; + +static inline bool ascii_isbdigit(int) + REAL_FATTR_CONST + REAL_FATTR_ALWAYS_INLINE; + +static inline bool ascii_isspace(int) + REAL_FATTR_CONST + REAL_FATTR_ALWAYS_INLINE; /// Checks if `c` is a space or tab character. /// @@ -122,6 +137,14 @@ static inline bool ascii_isxdigit(int c) || (c >= 'A' && c <= 'F'); } +/// Checks if `c` is a binary digit, that is, 0-1. +/// +/// @see {ascii_isdigit} +static inline bool ascii_isbdigit(int c) +{ + return (c == '0' || c == '1'); +} + /// Checks if `c` is a white-space character, that is, /// one of \f, \n, \r, \t, \v. /// diff --git a/src/nvim/charset.c b/src/nvim/charset.c index b93eafbf60..9c63eca1f2 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -1454,6 +1454,24 @@ char_u* skipdigits(char_u *q) return p; } +/// skip over binary digits +/// +/// @param q pointer to string +/// +/// @return Pointer to the character after the skipped digits. +const char* skipbin(const char *q) + FUNC_ATTR_PURE + FUNC_ATTR_NONNULL_ALL + FUNC_ATTR_NONNULL_RET +{ + const char *p = q; + while (ascii_isbdigit(*p)) { + // skip to next non-digit + p++; + } + return p; +} + /// skip over digits and hex characters /// /// @param q @@ -1485,6 +1503,24 @@ char_u* skiptodigit(char_u *q) return p; } +/// skip to binary character (or NUL after the string) +/// +/// @param q pointer to string +/// +/// @return Pointer to the binary character or (NUL after the string). +const char* skiptobin(const char *q) + FUNC_ATTR_PURE + FUNC_ATTR_NONNULL_ALL + FUNC_ATTR_NONNULL_RET +{ + const char *p = q; + while (*p != NUL && !ascii_isbdigit(*p)) { + // skip to next digit + p++; + } + return p; +} + /// skip to hex character (or NUL after the string) /// /// @param q @@ -1720,67 +1756,76 @@ int vim_isblankline(char_u *lbuf) } /// Convert a string into a long and/or unsigned long, taking care of -/// hexadecimal and octal numbers. Accepts a '-' sign. -/// If "hexp" is not NULL, returns a flag to indicate the type of the number: +/// hexadecimal, octal and binary numbers. Accepts a '-' sign. +/// If "prep" is not NULL, returns a flag to indicate the type of the number: /// 0 decimal /// '0' octal +/// 'B' bin +/// 'b' bin /// 'X' hex /// 'x' hex /// If "len" is not NULL, the length of the number in characters is returned. /// If "nptr" is not NULL, the signed result is returned in it. /// If "unptr" is not NULL, the unsigned result is returned in it. +/// If "dobin" is non-zero recognize binary numbers, when > 1 always assume +/// binary number. /// If "dooct" is non-zero recognize octal numbers, when > 1 always assume /// octal number. /// If "dohex" is non-zero recognize hex numbers, when > 1 always assume /// hex number. /// /// @param start -/// @param hexp Returns type of number 0 = decimal, 'x' or 'X' is hex, -// '0' = octal +/// @param prep Returns type of number 0 = decimal, 'x' or 'X' is hex, +// '0' = octal, 'b' or 'B' is bin /// @param len Returns the detected length of number. +/// @param dobin recognize binary number /// @param dooct recognize octal number /// @param dohex recognize hex number /// @param nptr Returns the signed result. /// @param unptr Returns the unsigned result. -void vim_str2nr(char_u *start, int *hexp, int *len, int dooct, int dohex, +void vim_str2nr(char_u *start, int *prep, int *len, + int dobin, int dooct, int dohex, long *nptr, unsigned long *unptr) { char_u *ptr = start; - int hex = 0; // default is decimal - int negative = FALSE; + int pre = 0; // default is decimal + int negative = false; unsigned long un = 0; - int n; if (ptr[0] == '-') { - negative = TRUE; - ++ptr; + negative = true; + ptr++; } - // Recognize hex and octal. + // Recognize hex, octal, and bin. if ((ptr[0] == '0') && (ptr[1] != '8') && (ptr[1] != '9')) { - hex = ptr[1]; + pre = ptr[1]; if (dohex - && ((hex == 'X') || (hex == 'x')) + && ((pre == 'X') || (pre == 'x')) && ascii_isxdigit(ptr[2])) { // hexadecimal ptr += 2; + } else if (dobin + && ((pre == 'B') || (pre == 'b')) + && ascii_isbdigit(ptr[2])) { + // binary + ptr += 2; } else { // default is decimal - hex = 0; + pre = 0; if (dooct) { // Don't interpret "0", "08" or "0129" as octal. - for (n = 1; ascii_isdigit(ptr[n]); ++n) { + for (int n = 1; ascii_isdigit(ptr[n]); ++n) { if (ptr[n] > '7') { // can't be octal - hex = 0; + pre = 0; break; } - if (ptr[n] >= '0') { // assume octal - hex = '0'; + pre = '0'; } } } @@ -1788,13 +1833,19 @@ void vim_str2nr(char_u *start, int *hexp, int *len, int dooct, int dohex, } // Do the string-to-numeric conversion "manually" to avoid sscanf quirks. - if ((hex == '0') || (dooct > 1)) { + if ((pre == 'B') || (pre == 'b') || (dobin > 1)) { + // bin + while ('0' <= *ptr && *ptr <= '1') { + un = 2 * un + (unsigned long)(*ptr - '0'); + ptr++; + } + } else if ((pre == '0') || (dooct > 1)) { // octal while ('0' <= *ptr && *ptr <= '7') { un = 8 * un + (unsigned long)(*ptr - '0'); ptr++; } - } else if ((hex != 0) || (dohex > 1)) { + } else if ((pre == 'X') || (pre == 'x') || dohex > 1) { // hex while (ascii_isxdigit(*ptr)) { un = 16 * un + (unsigned long)hex2nr(*ptr); @@ -1808,8 +1859,8 @@ void vim_str2nr(char_u *start, int *hexp, int *len, int dooct, int dohex, } } - if (hexp != NULL) { - *hexp = hex; + if (prep != NULL) { + *prep = pre; } if (len != NULL) { diff --git a/src/nvim/edit.c b/src/nvim/edit.c index ccfc9b4803..dbbcf4f1b9 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -7586,27 +7586,35 @@ static int ins_bs(int c, int mode, int *inserted_space_p) * happen when using 'sts' and 'linebreak'. */ if (vcol >= start_vcol) ins_bs_one(&vcol); - } - /* - * Delete upto starting point, start of line or previous word. - */ - else do { - if (!revins_on) /* put cursor on char to be deleted */ - dec_cursor(); - /* start of word? */ - if (mode == BACKSPACE_WORD && !ascii_isspace(gchar_cursor())) { - mode = BACKSPACE_WORD_NOT_SPACE; - temp = vim_iswordc(gchar_cursor()); + // Delete upto starting point, start of line or previous word. + } else { + int cclass = 0, prev_cclass = 0; + + if (has_mbyte) { + cclass = mb_get_class(get_cursor_pos_ptr()); + } + do { + if (!revins_on) { // put cursor on char to be deleted + dec_cursor(); } - /* end of word? */ - else if (mode == BACKSPACE_WORD_NOT_SPACE - && (ascii_isspace(cc = gchar_cursor()) - || vim_iswordc(cc) != temp)) { - if (!revins_on) + cc = gchar_cursor(); + // look multi-byte character class + if (has_mbyte) { + prev_cclass = cclass; + cclass = mb_get_class(get_cursor_pos_ptr()); + } + if (mode == BACKSPACE_WORD && !ascii_isspace(cc)) { // start of word? + mode = BACKSPACE_WORD_NOT_SPACE; + temp = vim_iswordc(cc); + } else if (mode == BACKSPACE_WORD_NOT_SPACE + && ((ascii_isspace(cc) || vim_iswordc(cc) != temp) + || prev_cclass != cclass)) { // end of word? + if (!revins_on) { inc_cursor(); - else if (State & REPLACE_FLAG) + } else if (State & REPLACE_FLAG) { dec_cursor(); + } break; } if (State & REPLACE_FLAG) @@ -7639,18 +7647,18 @@ static int ins_bs(int c, int mode, int *inserted_space_p) (curwin->w_cursor.col > mincol && (curwin->w_cursor.lnum != Insstart_orig.lnum || curwin->w_cursor.col != Insstart_orig.col))); - did_backspace = TRUE; + } + did_backspace = true; } - did_si = FALSE; - can_si = FALSE; - can_si_back = FALSE; - if (curwin->w_cursor.col <= 1) - did_ai = FALSE; - /* - * It's a little strange to put backspaces into the redo - * buffer, but it makes auto-indent a lot easier to deal - * with. - */ + did_si = false; + can_si = false; + can_si_back = false; + if (curwin->w_cursor.col <= 1) { + did_ai = false; + } + // It's a little strange to put backspaces into the redo + // buffer, but it makes auto-indent a lot easier to deal + // with. AppendCharToRedobuff(c); /* If deleted before the insertion point, adjust it */ diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 7ac51d7bd7..a1c5f958d1 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -1113,19 +1113,17 @@ typval_T *eval_expr(char_u *arg, char_u **nextcmd) } -/* - * Call some vimL function and return the result in "*rettv". - * Uses argv[argc] for the function arguments. Only Number and String - * arguments are currently supported. - * Returns OK or FAIL. - */ -int -call_vim_function ( +// Call some vimL function and return the result in "*rettv". +// Uses argv[argc] for the function arguments. Only Number and String +// arguments are currently supported. +// +// Return OK or FAIL. +int call_vim_function( char_u *func, int argc, char_u **argv, - int safe, /* use the sandbox */ - int str_arg_only, /* all arguments are strings */ + int safe, // use the sandbox + int str_arg_only, // all arguments are strings typval_T *rettv ) { @@ -1138,18 +1136,19 @@ call_vim_function ( typval_T *argvars = xmalloc((argc + 1) * sizeof(typval_T)); for (int i = 0; i < argc; i++) { - /* Pass a NULL or empty argument as an empty string */ + // Pass a NULL or empty argument as an empty string if (argv[i] == NULL || *argv[i] == NUL) { argvars[i].v_type = VAR_STRING; argvars[i].vval.v_string = (char_u *)""; continue; } - if (str_arg_only) + if (str_arg_only) { len = 0; - else - /* Recognize a number argument, the others must be strings. */ - vim_str2nr(argv[i], NULL, &len, TRUE, TRUE, &n, NULL); + } else { + // Recognize a number argument, the others must be strings. + vim_str2nr(argv[i], NULL, &len, true, true, true, &n, NULL); + } if (len != 0 && len == (int)STRLEN(argv[i])) { argvars[i].v_type = VAR_NUMBER; argvars[i].vval.v_number = n; @@ -1166,16 +1165,17 @@ call_vim_function ( rettv->v_type = VAR_UNKNOWN; /* clear_tv() uses this */ ret = call_func(func, (int)STRLEN(func), rettv, argc, argvars, - curwin->w_cursor.lnum, curwin->w_cursor.lnum, - &doesrange, TRUE, NULL); + curwin->w_cursor.lnum, curwin->w_cursor.lnum, + &doesrange, true, NULL); if (safe) { --sandbox; restore_funccal(save_funccalp); } xfree(argvars); - if (ret == FAIL) + if (ret == FAIL) { clear_tv(rettv); + } return ret; } @@ -2890,9 +2890,12 @@ static int do_unlet_var(lval_T *lp, char_u *name_end, int forceit) else if (do_unlet(lp->ll_name, forceit) == FAIL) ret = FAIL; *name_end = cc; - } else if (tv_check_lock(lp->ll_tv->v_lock, lp->ll_name)) + } else if ((lp->ll_list != NULL + && tv_check_lock(lp->ll_list->lv_lock, lp->ll_name)) + || (lp->ll_dict != NULL + && tv_check_lock(lp->ll_dict->dv_lock, lp->ll_name))) { return FAIL; - else if (lp->ll_range) { + } else if (lp->ll_range) { listitem_T *li; listitem_T *ll_li = lp->ll_li; int ll_n1 = lp->ll_n1; @@ -2953,17 +2956,30 @@ int do_unlet(char_u *name, int forceit) hashtab_T *ht; hashitem_T *hi; char_u *varname; + dict_T *d; dictitem_T *di; dict_T *dict; ht = find_var_ht_dict(name, &varname, &dict); if (ht != NULL && *varname != NUL) { + if (ht == &globvarht) { + d = &globvardict; + } else if (current_funccal != NULL + && ht == ¤t_funccal->l_vars.dv_hashtab) { + d = ¤t_funccal->l_vars; + } else { + di = find_var_in_ht(ht, *name, (char_u *)"", false); + d = di->di_tv.vval.v_dict; + } + hi = hash_find(ht, varname); if (!HASHITEM_EMPTY(hi)) { di = HI2DI(hi); if (var_check_fixed(di->di_flags, name) - || var_check_ro(di->di_flags, name)) + || var_check_ro(di->di_flags, name) + || tv_check_lock(d->dv_lock, name)) { return FAIL; + } typval_T oldtv; bool watched = is_watched(dict); @@ -4025,38 +4041,35 @@ eval6 ( return OK; } -/* - * Handle sixth level expression: - * number number constant - * "string" string constant - * 'string' literal string constant - * &option-name option value - * @r register contents - * identifier variable value - * function() function call - * $VAR environment variable - * (expression) nested expression - * [expr, expr] List - * {key: val, key: val} Dictionary - * - * Also handle: - * ! in front logical NOT - * - in front unary minus - * + in front unary plus (ignored) - * trailing [] subscript in String or List - * trailing .name entry in Dictionary - * - * "arg" must point to the first non-white of the expression. - * "arg" is advanced to the next non-white after the recognized expression. - * - * Return OK or FAIL. - */ -static int -eval7 ( +// Handle sixth level expression: +// number number constant +// "string" string constant +// 'string' literal string constant +// &option-name option value +// @r register contents +// identifier variable value +// function() function call +// $VAR environment variable +// (expression) nested expression +// [expr, expr] List +// {key: val, key: val} Dictionary +// +// Also handle: +// ! in front logical NOT +// - in front unary minus +// + in front unary plus (ignored) +// trailing [] subscript in String or List +// trailing .name entry in Dictionary +// +// "arg" must point to the first non-white of the expression. +// "arg" is advanced to the next non-white after the recognized expression. +// +// Return OK or FAIL. +static int eval7( char_u **arg, typval_T *rettv, int evaluate, - int want_string /* after "." operator */ + int want_string // after "." operator ) { long n; @@ -4066,24 +4079,19 @@ eval7 ( int ret = OK; char_u *alias; - /* - * Initialise variable so that clear_tv() can't mistake this for a - * string and free a string that isn't there. - */ + // Initialise variable so that clear_tv() can't mistake this for a + // string and free a string that isn't there. rettv->v_type = VAR_UNKNOWN; - /* - * Skip '!' and '-' characters. They are handled later. - */ + // Skip '!' and '-' characters. They are handled later. start_leader = *arg; - while (**arg == '!' || **arg == '-' || **arg == '+') + while (**arg == '!' || **arg == '-' || **arg == '+') { *arg = skipwhite(*arg + 1); + } end_leader = *arg; switch (**arg) { - /* - * Number constant. - */ + // Number constant. case '0': case '1': case '2': @@ -4096,27 +4104,30 @@ eval7 ( case '9': { char_u *p = skipdigits(*arg + 1); - int get_float = FALSE; + int get_float = false; - /* We accept a float when the format matches - * "[0-9]\+\.[0-9]\+\([eE][+-]\?[0-9]\+\)\?". This is very - * strict to avoid backwards compatibility problems. - * Don't look for a float after the "." operator, so that - * ":let vers = 1.2.3" doesn't fail. */ + // We accept a float when the format matches + // "[0-9]\+\.[0-9]\+\([eE][+-]\?[0-9]\+\)\?". This is very + // strict to avoid backwards compatibility problems. + // Don't look for a float after the "." operator, so that + // ":let vers = 1.2.3" doesn't fail. if (!want_string && p[0] == '.' && ascii_isdigit(p[1])) { - get_float = TRUE; + get_float = true; p = skipdigits(p + 2); if (*p == 'e' || *p == 'E') { ++p; - if (*p == '-' || *p == '+') + if (*p == '-' || *p == '+') { ++p; - if (!ascii_isdigit(*p)) - get_float = FALSE; - else + } + if (!ascii_isdigit(*p)) { + get_float = false; + } else { p = skipdigits(p + 1); + } + } + if (ASCII_ISALPHA(*p) || *p == '.') { + get_float = false; } - if (ASCII_ISALPHA(*p) || *p == '.') - get_float = FALSE; } if (get_float) { float_T f; @@ -4127,7 +4138,7 @@ eval7 ( rettv->vval.v_float = f; } } else { - vim_str2nr(*arg, NULL, &len, TRUE, TRUE, &n, NULL); + vim_str2nr(*arg, NULL, &len, true, true, true, &n, NULL); *arg += len; if (evaluate) { rettv->v_type = VAR_NUMBER; @@ -4137,62 +4148,47 @@ eval7 ( break; } - /* - * String constant: "string". - */ + // String constant: "string". case '"': ret = get_string_tv(arg, rettv, evaluate); break; - /* - * Literal string constant: 'str''ing'. - */ + // Literal string constant: 'str''ing'. case '\'': ret = get_lit_string_tv(arg, rettv, evaluate); break; - /* - * List: [expr, expr] - */ + // List: [expr, expr] case '[': ret = get_list_tv(arg, rettv, evaluate); break; - /* - * Dictionary: {key: val, key: val} - */ + // Dictionary: {key: val, key: val} case '{': ret = get_dict_tv(arg, rettv, evaluate); break; - /* - * Option value: &name - */ + // Option value: &name case '&': ret = get_option_tv(arg, rettv, evaluate); break; - /* - * Environment variable: $VAR. - */ + // Environment variable: $VAR. case '$': ret = get_env_tv(arg, rettv, evaluate); break; - /* - * Register contents: @r. - */ + // Register contents: @r. case '@': ++*arg; if (evaluate) { rettv->v_type = VAR_STRING; rettv->vval.v_string = get_reg_contents(**arg, kGRegExprSrc); } - if (**arg != NUL) + if (**arg != NUL) { ++*arg; + } break; - /* - * nested expression: (expression). - */ + // nested expression: (expression). case '(': *arg = skipwhite(*arg + 1); - ret = eval1(arg, rettv, evaluate); /* recursive! */ - if (**arg == ')') + ret = eval1(arg, rettv, evaluate); // recursive! + if (**arg == ')') { ++*arg; - else if (ret == OK) { + } else if (ret == OK) { EMSG(_("E110: Missing ')'")); clear_tv(rettv); ret = FAIL; @@ -4204,71 +4200,72 @@ eval7 ( } if (ret == NOTDONE) { - /* - * Must be a variable or function name. - * Can also be a curly-braces kind of name: {expr}. - */ + // Must be a variable or function name. + // Can also be a curly-braces kind of name: {expr}. s = *arg; - len = get_name_len(arg, &alias, evaluate, TRUE); - if (alias != NULL) + len = get_name_len(arg, &alias, evaluate, true); + if (alias != NULL) { s = alias; + } - if (len <= 0) + if (len <= 0) { ret = FAIL; - else { - if (**arg == '(') { /* recursive! */ - /* If "s" is the name of a variable of type VAR_FUNC - * use its contents. */ + } else { + if (**arg == '(') { // recursive! + // If "s" is the name of a variable of type VAR_FUNC + // use its contents. s = deref_func_name(s, &len, !evaluate); - /* Invoke the function. */ + // Invoke the function. ret = get_func_tv(s, len, rettv, arg, curwin->w_cursor.lnum, curwin->w_cursor.lnum, &len, evaluate, NULL); - /* If evaluate is FALSE rettv->v_type was not set in - * get_func_tv, but it's needed in handle_subscript() to parse - * what follows. So set it here. */ + // If evaluate is false rettv->v_type was not set in + // get_func_tv, but it's needed in handle_subscript() to parse + // what follows. So set it here. if (rettv->v_type == VAR_UNKNOWN && !evaluate && **arg == '(') { rettv->vval.v_string = empty_string; rettv->v_type = VAR_FUNC; } - /* Stop the expression evaluation when immediately - * aborting on error, or when an interrupt occurred or - * an exception was thrown but not caught. */ + // Stop the expression evaluation when immediately + // aborting on error, or when an interrupt occurred or + // an exception was thrown but not caught. if (aborting()) { - if (ret == OK) + if (ret == OK) { clear_tv(rettv); + } ret = FAIL; } - } else if (evaluate) - ret = get_var_tv(s, len, rettv, TRUE, FALSE); - else + } else if (evaluate) { + ret = get_var_tv(s, len, rettv, true, false); + } else { ret = OK; + } } xfree(alias); } *arg = skipwhite(*arg); - /* Handle following '[', '(' and '.' for expr[expr], expr.name, - * expr(expr). */ - if (ret == OK) - ret = handle_subscript(arg, rettv, evaluate, TRUE); + // Handle following '[', '(' and '.' for expr[expr], expr.name, + // expr(expr). + if (ret == OK) { + ret = handle_subscript(arg, rettv, evaluate, true); + } - /* - * Apply logical NOT and unary '-', from right to left, ignore '+'. - */ + // Apply logical NOT and unary '-', from right to left, ignore '+'. if (ret == OK && evaluate && end_leader > start_leader) { - int error = FALSE; + int error = false; int val = 0; float_T f = 0.0; - if (rettv->v_type == VAR_FLOAT) + if (rettv->v_type == VAR_FLOAT) { f = rettv->vval.v_float; - else + } else { val = get_tv_number_chk(rettv, &error); + } if (error) { clear_tv(rettv); ret = FAIL; @@ -4276,15 +4273,17 @@ eval7 ( while (end_leader > start_leader) { --end_leader; if (*end_leader == '!') { - if (rettv->v_type == VAR_FLOAT) + if (rettv->v_type == VAR_FLOAT) { f = !f; - else + } else { val = !val; + } } else if (*end_leader == '-') { - if (rettv->v_type == VAR_FLOAT) + if (rettv->v_type == VAR_FLOAT) { f = -f; - else + } else { val = -val; + } } } if (rettv->v_type == VAR_FLOAT) { @@ -4655,10 +4654,13 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate) int n, nr; int c = toupper(*p); - if (c == 'X') + if (c == 'X') { n = 2; - else + } else if (*p == 'u') { n = 4; + } else { + n = 8; + } nr = 0; while (--n >= 0 && ascii_isxdigit(p[1])) { ++p; @@ -6069,7 +6071,7 @@ dictitem_T *dictitem_alloc(char_u *key) FUNC_ATTR_NONNULL_RET #ifndef __clang_analyzer__ STRCPY(di->di_key, key); #endif - di->di_flags = 0; + di->di_flags = DI_FLAGS_ALLOC; return di; } @@ -6081,7 +6083,7 @@ static dictitem_T *dictitem_copy(dictitem_T *org) FUNC_ATTR_NONNULL_RET dictitem_T *di = xmalloc(sizeof(dictitem_T) + STRLEN(org->di_key)); STRCPY(di->di_key, org->di_key); - di->di_flags = 0; + di->di_flags = DI_FLAGS_ALLOC; copy_tv(&org->di_tv, &di->di_tv); return di; @@ -6109,7 +6111,9 @@ static void dictitem_remove(dict_T *dict, dictitem_T *item) void dictitem_free(dictitem_T *item) { clear_tv(&item->di_tv); - xfree(item); + if (item->di_flags & DI_FLAGS_ALLOC) { + xfree(item); + } } /// Make a copy of dictionary @@ -7205,9 +7209,9 @@ static struct fst { { "getwinposx", 0, 0, f_getwinposx }, { "getwinposy", 0, 0, f_getwinposy }, { "getwinvar", 2, 3, f_getwinvar }, - { "glob", 1, 3, f_glob }, + { "glob", 1, 4, f_glob }, { "glob2regpat", 1, 1, f_glob2regpat }, - { "globpath", 2, 4, f_globpath }, + { "globpath", 2, 5, f_globpath }, { "has", 1, 1, f_has }, { "has_key", 2, 2, f_has_key }, { "haslocaldir", 0, 0, f_haslocaldir }, @@ -7236,6 +7240,7 @@ static struct fst { { "islocked", 1, 1, f_islocked }, { "items", 1, 1, f_items }, { "jobclose", 1, 2, f_jobclose }, + { "jobpid", 1, 1, f_jobpid }, { "jobresize", 3, 3, f_jobresize }, { "jobsend", 2, 2, f_jobsend }, { "jobstart", 1, 2, f_jobstart }, @@ -9225,6 +9230,7 @@ void dict_extend(dict_T *d1, dict_T *d2, char_u *action) hashitem_T *hi2; int todo; bool watched = is_watched(d1); + char *arg_errmsg = N_("extend() argument"); todo = (int)d2->dv_hashtab.ht_used; for (hi2 = d2->dv_hashtab.ht_array; todo > 0; ++hi2) { @@ -9258,6 +9264,11 @@ void dict_extend(dict_T *d1, dict_T *d2, char_u *action) } else if (*action == 'f' && HI2DI(hi2) != di1) { typval_T oldtv; + if (tv_check_lock(di1->di_tv.v_lock, (char_u *)_(arg_errmsg)) + || var_check_ro(di1->di_flags, (char_u *)_(arg_errmsg))) { + break; + } + if (watched) { copy_tv(&di1->di_tv, &oldtv); } @@ -9473,12 +9484,14 @@ static void filter_map(typval_T *argvars, typval_T *rettv, int map) if (argvars[0].v_type == VAR_LIST) { if ((l = argvars[0].vval.v_list) == NULL - || tv_check_lock(l->lv_lock, (char_u *)_(arg_errmsg))) + || (!map && tv_check_lock(l->lv_lock, (char_u *)_(arg_errmsg)))) { return; + } } else if (argvars[0].v_type == VAR_DICT) { if ((d = argvars[0].vval.v_dict) == NULL - || tv_check_lock(d->dv_lock, (char_u *)_(arg_errmsg))) + || (!map && tv_check_lock(d->dv_lock, (char_u *)_(arg_errmsg)))) { return; + } } else { EMSG2(_(e_listdictarg), ermsg); return; @@ -9507,17 +9520,26 @@ static void filter_map(typval_T *argvars, typval_T *rettv, int map) for (hi = ht->ht_array; todo > 0; ++hi) { if (!HASHITEM_EMPTY(hi)) { --todo; + di = HI2DI(hi); - if (tv_check_lock(di->di_tv.v_lock, - (char_u *)_(arg_errmsg))) + if (map + && (tv_check_lock(di->di_tv.v_lock, (char_u *)_(arg_errmsg)) + || var_check_ro(di->di_flags, (char_u *)_(arg_errmsg)))) { break; + } + vimvars[VV_KEY].vv_str = vim_strsave(di->di_key); int r = filter_map_one(&di->di_tv, expr, map, &rem); clear_tv(&vimvars[VV_KEY].vv_tv); if (r == FAIL || did_emsg) break; - if (!map && rem) + if (!map && rem) { + if (var_check_fixed(di->di_flags, (char_u *)_(arg_errmsg)) + || var_check_ro(di->di_flags, (char_u *)_(arg_errmsg))) { + break; + } dictitem_remove(d, di); + } } } hash_unlock(ht); @@ -9525,8 +9547,9 @@ static void filter_map(typval_T *argvars, typval_T *rettv, int map) vimvars[VV_KEY].vv_type = VAR_NUMBER; for (li = l->lv_first; li != NULL; li = nli) { - if (tv_check_lock(li->li_tv.v_lock, (char_u *)_(arg_errmsg))) + if (map && tv_check_lock(li->li_tv.v_lock, (char_u *)_(arg_errmsg))) { break; + } nli = li->li_next; vimvars[VV_KEY].vv_nr = idx; if (filter_map_one(&li->li_tv, expr, map, &rem) == FAIL @@ -10717,10 +10740,15 @@ static void f_glob(typval_T *argvars, typval_T *rettv) if (argvars[1].v_type != VAR_UNKNOWN) { if (get_tv_number_chk(&argvars[1], &error)) options |= WILD_KEEP_ALL; - if (argvars[2].v_type != VAR_UNKNOWN - && get_tv_number_chk(&argvars[2], &error)) { - rettv->v_type = VAR_LIST; - rettv->vval.v_list = NULL; + if (argvars[2].v_type != VAR_UNKNOWN) { + if (get_tv_number_chk(&argvars[2], &error)) { + rettv->v_type = VAR_LIST; + rettv->vval.v_list = NULL; + } + if (argvars[3].v_type != VAR_UNKNOWN + && get_tv_number_chk(&argvars[3], &error)) { + options |= WILD_ALLLINKS; + } } } if (!error) { @@ -10759,10 +10787,15 @@ static void f_globpath(typval_T *argvars, typval_T *rettv) flags |= WILD_KEEP_ALL; } - if (argvars[3].v_type != VAR_UNKNOWN - && get_tv_number_chk(&argvars[3], &error)) { - rettv->v_type = VAR_LIST; - rettv->vval.v_list = NULL; + if (argvars[3].v_type != VAR_UNKNOWN) { + if (get_tv_number_chk(&argvars[3], &error)) { + rettv->v_type = VAR_LIST; + rettv->vval.v_list = NULL; + } + if (argvars[4].v_type != VAR_UNKNOWN + && get_tv_number_chk(&argvars[4], &error)) { + flags |= WILD_ALLLINKS; + } } } @@ -10789,15 +10822,15 @@ static void f_globpath(typval_T *argvars, typval_T *rettv) } } -/* - * "glob2regpat()" function - */ +// "glob2regpat()" function static void f_glob2regpat(typval_T *argvars, typval_T *rettv) { - char_u *pat = get_tv_string_chk(&argvars[0]); + char_u *pat = get_tv_string_chk(&argvars[0]); // NULL on type error - rettv->v_type = VAR_STRING; - rettv->vval.v_string = file_pat_to_reg_pat(pat, NULL, NULL, FALSE); + rettv->v_type = VAR_STRING; + rettv->vval.v_string = (pat == NULL) + ? NULL + : file_pat_to_reg_pat(pat, NULL, NULL, false); } /* @@ -11611,6 +11644,31 @@ static void f_jobclose(typval_T *argvars, typval_T *rettv) } } +// "jobpid(id)" function +static void f_jobpid(typval_T *argvars, typval_T *rettv) +{ + rettv->v_type = VAR_NUMBER; + rettv->vval.v_number = 0; + + if (check_restricted() || check_secure()) { + return; + } + + if (argvars[0].v_type != VAR_NUMBER) { + EMSG(_(e_invarg)); + return; + } + + TerminalJobData *data = find_job(argvars[0].vval.v_number); + if (!data) { + EMSG(_(e_invjob)); + return; + } + + Process *proc = (Process *)&data->proc; + rettv->vval.v_number = proc->pid; +} + // "jobsend()" function static void f_jobsend(typval_T *argvars, typval_T *rettv) { @@ -11771,8 +11829,9 @@ static void f_jobstart(typval_T *argvars, typval_T *rettv) } bool pty = job_opts && get_dict_number(job_opts, (uint8_t *)"pty") != 0; + bool detach = job_opts && get_dict_number(job_opts, (uint8_t *)"detach") != 0; TerminalJobData *data = common_job_init(argv, on_stdout, on_stderr, on_exit, - job_opts, pty); + job_opts, pty, detach); Process *proc = (Process *)&data->proc; if (pty) { @@ -13855,9 +13914,10 @@ static void f_remove(typval_T *argvars, typval_T *rettv) key = get_tv_string_chk(&argvars[1]); if (key != NULL) { di = dict_find(d, key, -1); - if (di == NULL) + if (di == NULL) { EMSG2(_(e_dictkey), key); - else { + } else if (!var_check_fixed(di->di_flags, (char_u *)_(arg_errmsg)) + && !var_check_ro(di->di_flags, (char_u *)_(arg_errmsg))) { *rettv = di->di_tv; init_tv(&di->di_tv); dictitem_remove(d, di); @@ -15971,9 +16031,7 @@ static void f_str2float(typval_T *argvars, typval_T *rettv) rettv->v_type = VAR_FLOAT; } -/* - * "str2nr()" function - */ +// "str2nr()" function static void f_str2nr(typval_T *argvars, typval_T *rettv) { int base = 10; @@ -15982,16 +16040,21 @@ static void f_str2nr(typval_T *argvars, typval_T *rettv) if (argvars[1].v_type != VAR_UNKNOWN) { base = get_tv_number(&argvars[1]); - if (base != 8 && base != 10 && base != 16) { + if (base != 2 && base != 8 && base != 10 && base != 16) { EMSG(_(e_invarg)); return; } } p = skipwhite(get_tv_string(&argvars[0])); - if (*p == '+') + if (*p == '+') { p = skipwhite(p + 1); - vim_str2nr(p, NULL, NULL, base == 8 ? 2 : 0, base == 16 ? 2 : 0, &n, NULL); + } + vim_str2nr(p, NULL, NULL, + base == 2 ? 2 : 0, + base == 8 ? 2 : 0, + base == 16 ? 2 : 0, + &n, NULL); rettv->vval.v_number = n; } @@ -16776,7 +16839,7 @@ static void f_termopen(typval_T *argvars, typval_T *rettv) } TerminalJobData *data = common_job_init(argv, on_stdout, on_stderr, on_exit, - job_opts, true); + job_opts, true, false); data->proc.pty.width = curwin->w_width; data->proc.pty.height = curwin->w_height; data->proc.pty.term_name = xstrdup("xterm-256color"); @@ -18271,9 +18334,10 @@ long get_tv_number_chk(typval_T *varp, int *denote) EMSG(_("E703: Using a Funcref as a Number")); break; case VAR_STRING: - if (varp->vval.v_string != NULL) + if (varp->vval.v_string != NULL) { vim_str2nr(varp->vval.v_string, NULL, NULL, - TRUE, TRUE, &n, NULL); + true, true, true, &n, NULL); + } return n; case VAR_LIST: EMSG(_("E745: Using a List as a Number")); @@ -18285,10 +18349,12 @@ long get_tv_number_chk(typval_T *varp, int *denote) EMSG2(_(e_intern2), "get_tv_number()"); break; } - if (denote == NULL) /* useful for values that must be unsigned */ + if (denote == NULL) { + // useful for values that must be unsigned n = -1; - else - *denote = TRUE; + } else { + *denote = true; + } return n; } @@ -18619,14 +18685,16 @@ static void vars_clear_ext(hashtab_T *ht, int free_val) if (!HASHITEM_EMPTY(hi)) { --todo; - /* Free the variable. Don't remove it from the hashtab, - * ht_array might change then. hash_clear() takes care of it - * later. */ + // Free the variable. Don't remove it from the hashtab, + // ht_array might change then. hash_clear() takes care of it + // later. v = HI2DI(hi); - if (free_val) + if (free_val) { clear_tv(&v->di_tv); - if ((v->di_flags & DI_FLAGS_FIX) == 0) + } + if (v->di_flags & DI_FLAGS_ALLOC) { xfree(v); + } } } hash_clear(ht); @@ -18800,7 +18868,7 @@ set_var ( xfree(v); return; } - v->di_flags = 0; + v->di_flags = DI_FLAGS_ALLOC; } if (copy || tv->v_type == VAR_NUMBER || tv->v_type == VAR_FLOAT) { @@ -20691,7 +20759,7 @@ call_user_func ( v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX; } else { v = xmalloc(sizeof(dictitem_T) + STRLEN(name)); - v->di_flags = DI_FLAGS_RO; + v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX | DI_FLAGS_ALLOC; } STRCPY(v->di_key, name); hash_add(&fc->l_avars.dv_hashtab, DI2HIKEY(v)); @@ -21782,8 +21850,13 @@ char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub, char_u *flags) return ret; } -static inline TerminalJobData *common_job_init(char **argv, ufunc_T *on_stdout, - ufunc_T *on_stderr, ufunc_T *on_exit, dict_T *self, bool pty) +static inline TerminalJobData *common_job_init(char **argv, + ufunc_T *on_stdout, + ufunc_T *on_stderr, + ufunc_T *on_exit, + dict_T *self, + bool pty, + bool detach) { TerminalJobData *data = xcalloc(1, sizeof(TerminalJobData)); data->stopped = false; @@ -21806,6 +21879,7 @@ static inline TerminalJobData *common_job_init(char **argv, ufunc_T *on_stdout, } proc->cb = on_process_exit; proc->events = data->events; + proc->detach = detach; return data; } @@ -21833,8 +21907,13 @@ static inline bool common_job_callbacks(dict_T *vopts, ufunc_T **on_stdout, static inline bool common_job_start(TerminalJobData *data, typval_T *rettv) { - data->refcount++; Process *proc = (Process *)&data->proc; + if (proc->type == kProcessTypePty && proc->detach) { + EMSG2(_(e_invarg2), "terminal/pty job cannot be detached"); + return false; + } + + data->refcount++; char *cmd = xstrdup(proc->argv[0]); if (!process_spawn(proc)) { EMSG2(_(e_jobspawn), cmd); diff --git a/src/nvim/eval_defs.h b/src/nvim/eval_defs.h index ed419268d2..cdad1f3197 100644 --- a/src/nvim/eval_defs.h +++ b/src/nvim/eval_defs.h @@ -101,10 +101,11 @@ struct dictitem_S { typedef struct dictitem_S dictitem_T; -#define DI_FLAGS_RO 1 /* "di_flags" value: read-only variable */ -#define DI_FLAGS_RO_SBX 2 /* "di_flags" value: read-only in the sandbox */ -#define DI_FLAGS_FIX 4 /* "di_flags" value: fixed variable, not allocated */ -#define DI_FLAGS_LOCK 8 /* "di_flags" value: locked variable */ +#define DI_FLAGS_RO 1 // "di_flags" value: read-only variable +#define DI_FLAGS_RO_SBX 2 // "di_flags" value: read-only in the sandbox +#define DI_FLAGS_FIX 4 // "di_flags" value: fixed: no :unlet or remove() +#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. diff --git a/src/nvim/event/libuv_process.c b/src/nvim/event/libuv_process.c index 44305c69bc..9ef3468284 100644 --- a/src/nvim/event/libuv_process.c +++ b/src/nvim/event/libuv_process.c @@ -21,6 +21,9 @@ bool libuv_process_spawn(LibuvProcess *uvproc) uvproc->uvopts.args = proc->argv; uvproc->uvopts.flags = UV_PROCESS_WINDOWS_HIDE | UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS; + if (proc->detach) { + uvproc->uvopts.flags |= UV_PROCESS_DETACHED; + } uvproc->uvopts.exit_cb = exit_cb; uvproc->uvopts.cwd = NULL; uvproc->uvopts.env = NULL; diff --git a/src/nvim/event/process.c b/src/nvim/event/process.c index 0336eb880a..e6012595fd 100644 --- a/src/nvim/event/process.c +++ b/src/nvim/event/process.c @@ -29,6 +29,7 @@ } \ } while (0) +static bool process_is_tearing_down = false; bool process_spawn(Process *proc) FUNC_ATTR_NONNULL_ALL { @@ -112,11 +113,22 @@ bool process_spawn(Process *proc) FUNC_ATTR_NONNULL_ALL void process_teardown(Loop *loop) FUNC_ATTR_NONNULL_ALL { + process_is_tearing_down = true; kl_iter(WatcherPtr, loop->children, current) { Process *proc = (*current)->data; - uv_kill(proc->pid, SIGTERM); - proc->term_sent = true; - process_stop(proc); + if (proc->detach) { + // Close handles to process without killing it. + CREATE_EVENT(loop->events, process_close_handles, 1, proc); + } else { + if (proc->type == kProcessTypeUv) { + uv_kill(proc->pid, SIGTERM); + proc->term_sent = true; + process_stop(proc); + } else { // kProcessTypePty + process_close_streams(proc); + pty_process_close_master((PtyProcess *)proc); + } + } } // Wait until all children exit @@ -303,6 +315,10 @@ static void decref(Process *proc) static void process_close(Process *proc) FUNC_ATTR_NONNULL_ARG(1) { + if (process_is_tearing_down && proc->detach && proc->closed) { + // If a detached process dies while tearing down it might get closed twice. + return; + } assert(!proc->closed); proc->closed = true; switch (proc->type) { @@ -333,6 +349,7 @@ static void on_process_exit(Process *proc) DLOG("Stopping process kill timer"); uv_timer_stop(&loop->children_kill_timer); } + // Process handles are closed in the next event loop tick. This is done to // give libuv more time to read data from the OS after the process exits(If // process_close_streams is called with data still in the OS buffer, we lose diff --git a/src/nvim/event/process.h b/src/nvim/event/process.h index 45edc46b95..e23c8ea60f 100644 --- a/src/nvim/event/process.h +++ b/src/nvim/event/process.h @@ -25,7 +25,7 @@ struct process { Stream *in, *out, *err; process_exit_cb cb; internal_process_cb internal_exit_cb, internal_close_cb; - bool closed, term_sent; + bool closed, term_sent, detach; Queue *events; }; @@ -48,7 +48,8 @@ static inline Process process_init(Loop *loop, ProcessType type, void *data) .closed = false, .term_sent = false, .internal_close_cb = NULL, - .internal_exit_cb = NULL + .internal_exit_cb = NULL, + .detach = false }; } diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 29d87d0fc1..407dded6af 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -329,9 +329,7 @@ static int sort_compare(const void *s1, const void *s2) return result; } -/* - * ":sort". - */ +// ":sort". void ex_sort(exarg_T *eap) { regmatch_T regmatch; @@ -343,17 +341,19 @@ void ex_sort(exarg_T *eap) char_u *p; char_u *s; char_u *s2; - char_u c; /* temporary character storage */ - int unique = FALSE; + char_u c; // temporary character storage + int unique = false; long deleted; colnr_T start_col; colnr_T end_col; - int sort_oct; /* sort on octal number */ - int sort_hex; /* sort on hex number */ + int sort_bin; // sort on bin number + int sort_oct; // sort on octal number + int sort_hex; // sort on hex number - /* Sorting one line is really quick! */ - if (count <= 1) + // Sorting one line is really quick! + if (count <= 1) { return; + } if (u_save((linenr_T)(eap->line1 - 1), (linenr_T)(eap->line2 + 1)) == FAIL) return; @@ -362,47 +362,51 @@ void ex_sort(exarg_T *eap) regmatch.regprog = NULL; sorti_T *nrs = xmalloc(count * sizeof(sorti_T)); - sort_abort = sort_ic = sort_rx = sort_nr = sort_oct = sort_hex = 0; + sort_abort = sort_ic = sort_rx = sort_nr = sort_bin = sort_oct = sort_hex = 0; for (p = eap->arg; *p != NUL; ++p) { - if (ascii_iswhite(*p)) - ; - else if (*p == 'i') - sort_ic = TRUE; - else if (*p == 'r') - sort_rx = TRUE; - else if (*p == 'n') + if (ascii_iswhite(*p)) { + } else if (*p == 'i') { + sort_ic = true; + } else if (*p == 'r') { + sort_rx = true; + } else if (*p == 'n') { sort_nr = 2; - else if (*p == 'o') + } else if (*p == 'b') { + sort_bin = 2; + } else if (*p == 'o') { sort_oct = 2; - else if (*p == 'x') + } else if (*p == 'x') { sort_hex = 2; - else if (*p == 'u') - unique = TRUE; - else if (*p == '"') /* comment start */ + } else if (*p == 'u') { + unique = true; + } else if (*p == '"') { + // comment start break; - else if (check_nextcmd(p) != NULL) { + } else if (check_nextcmd(p) != NULL) { eap->nextcmd = check_nextcmd(p); break; } else if (!ASCII_ISALPHA(*p) && regmatch.regprog == NULL) { - s = skip_regexp(p + 1, *p, TRUE, NULL); + s = skip_regexp(p + 1, *p, true, NULL); if (*s != *p) { EMSG(_(e_invalpat)); goto sortend; } *s = NUL; - /* Use last search pattern if sort pattern is empty. */ + // Use last search pattern if sort pattern is empty. if (s == p + 1) { if (last_search_pat() == NULL) { EMSG(_(e_noprevre)); goto sortend; } regmatch.regprog = vim_regcomp(last_search_pat(), RE_MAGIC); - } else + } else { regmatch.regprog = vim_regcomp(p + 1, RE_MAGIC); - if (regmatch.regprog == NULL) + } + if (regmatch.regprog == NULL) { goto sortend; - p = s; /* continue after the regexp */ + } + p = s; // continue after the regexp regmatch.rm_ic = p_ic; } else { EMSG2(_(e_invarg2), p); @@ -410,28 +414,27 @@ void ex_sort(exarg_T *eap) } } - /* Can only have one of 'n', 'o' and 'x'. */ - if (sort_nr + sort_oct + sort_hex > 2) { + // Can only have one of 'n', 'b', 'o' and 'x'. + if (sort_nr + sort_bin + sort_oct + sort_hex > 2) { EMSG(_(e_invarg)); goto sortend; } - /* From here on "sort_nr" is used as a flag for any number sorting. */ - sort_nr += sort_oct + sort_hex; + // From here on "sort_nr" is used as a flag for any number sorting. + sort_nr += sort_bin + sort_oct + sort_hex; - /* - * Make an array with all line numbers. This avoids having to copy all - * the lines into allocated memory. - * When sorting on strings "start_col_nr" is the offset in the line, for - * numbers sorting it's the number to sort on. This means the pattern - * matching and number conversion only has to be done once per line. - * Also get the longest line length for allocating "sortbuf". - */ + // Make an array with all line numbers. This avoids having to copy all + // the lines into allocated memory. + // When sorting on strings "start_col_nr" is the offset in the line, for + // numbers sorting it's the number to sort on. This means the pattern + // matching and number conversion only has to be done once per line. + // Also get the longest line length for allocating "sortbuf". for (lnum = eap->line1; lnum <= eap->line2; ++lnum) { s = ml_get(lnum); len = (int)STRLEN(s); - if (maxlen < len) + if (maxlen < len) { maxlen = len; + } start_col = 0; end_col = len; @@ -439,34 +442,41 @@ void ex_sort(exarg_T *eap) if (sort_rx) { start_col = (colnr_T)(regmatch.startp[0] - s); end_col = (colnr_T)(regmatch.endp[0] - s); - } else + } else { start_col = (colnr_T)(regmatch.endp[0] - s); - } else if (regmatch.regprog != NULL) + } + } else if (regmatch.regprog != NULL) { end_col = 0; + } if (sort_nr) { - /* Make sure vim_str2nr doesn't read any digits past the end - * of the match, by temporarily terminating the string there */ + // Make sure vim_str2nr doesn't read any digits past the end + // of the match, by temporarily terminating the string there s2 = s + end_col; c = *s2; *s2 = NUL; - /* Sorting on number: Store the number itself. */ + // Sorting on number: Store the number itself. p = s + start_col; - if (sort_hex) + if (sort_hex) { s = skiptohex(p); - else + } else if (sort_bin) { + s = (char_u*) skiptobin((char*) p); + } else { s = skiptodigit(p); - if (s > p && s[-1] == '-') - --s; /* include preceding negative sign */ - if (*s == NUL) - /* empty line should sort before any number */ + } + if (s > p && s[-1] == '-') { + --s; // include preceding negative sign + } + if (*s == NUL) { + // empty line should sort before any number nrs[lnum - eap->line1].start_col_nr = -MAXLNUM; - else - vim_str2nr(s, NULL, NULL, sort_oct, sort_hex, - &nrs[lnum - eap->line1].start_col_nr, NULL); + } else { + vim_str2nr(s, NULL, NULL, sort_bin, sort_oct, sort_hex, + &nrs[lnum - eap->line1].start_col_nr, NULL); + } *s2 = c; } else { - /* Store the column to sort at. */ + // Store the column to sort at. nrs[lnum - eap->line1].start_col_nr = start_col; nrs[lnum - eap->line1].end_col_nr = end_col; } @@ -479,17 +489,17 @@ void ex_sort(exarg_T *eap) goto sortend; } - /* Allocate a buffer that can hold the longest line. */ + // Allocate a buffer that can hold the longest line. sortbuf1 = xmalloc(maxlen + 1); sortbuf2 = xmalloc(maxlen + 1); - /* Sort the array of line numbers. Note: can't be interrupted! */ + // Sort the array of line numbers. Note: can't be interrupted! qsort((void *)nrs, count, sizeof(sorti_T), sort_compare); if (sort_abort) goto sortend; - /* Insert the lines in the sorted order below the last one. */ + // Insert the lines in the sorted order below the last one. lnum = eap->line2; for (i = 0; i < count; ++i) { s = ml_get(nrs[eap->forceit ? count - i - 1 : i].lnum); @@ -507,19 +517,22 @@ void ex_sort(exarg_T *eap) goto sortend; } - /* delete the original lines if appending worked */ - if (i == count) - for (i = 0; i < count; ++i) - ml_delete(eap->line1, FALSE); - else + // delete the original lines if appending worked + if (i == count) { + for (i = 0; i < count; ++i) { + ml_delete(eap->line1, false); + } + } else { count = 0; + } - /* Adjust marks for deleted (or added) lines and prepare for displaying. */ + // Adjust marks for deleted (or added) lines and prepare for displaying. deleted = (long)(count - (lnum - eap->line2)); - if (deleted > 0) + if (deleted > 0) { mark_adjust(eap->line2 - deleted, eap->line2, (long)MAXLNUM, -deleted); - else if (deleted < 0) + } else if (deleted < 0) { mark_adjust(eap->line2, MAXLNUM, -deleted, 0L); + } changed_lines(eap->line1, 0, eap->line2 + 1, -deleted); curwin->w_cursor.lnum = eap->line1; @@ -530,8 +543,9 @@ sortend: xfree(sortbuf1); xfree(sortbuf2); vim_regfree(regmatch.regprog); - if (got_int) + if (got_int) { EMSG(_(e_interr)); + } } /* diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index eca62da949..b19331ad06 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -3701,6 +3701,9 @@ ExpandFromContext ( flags |= EW_KEEPALL; if (options & WILD_SILENT) flags |= EW_SILENT; + if (options & WILD_ALLLINKS) { + flags |= EW_ALLLINKS; + } if (xp->xp_context == EXPAND_FILES || xp->xp_context == EXPAND_DIRECTORIES @@ -4767,35 +4770,40 @@ int del_history_idx(int histype, int idx) return TRUE; } -/* - * Get indices "num1,num2" that specify a range within a list (not a range of - * text lines in a buffer!) from a string. Used for ":history" and ":clist". - * Returns OK if parsed successfully, otherwise FAIL. - */ +/// Get indices that specify a range within a list (not a range of text lines +/// in a buffer!) from a string. Used for ":history" and ":clist". +/// +/// @param str string to parse range from +/// @param num1 from +/// @param num2 to +/// +/// @return OK if parsed successfully, otherwise FAIL. int get_list_range(char_u **str, int *num1, int *num2) { int len; - int first = FALSE; + int first = false; long num; *str = skipwhite(*str); - if (**str == '-' || ascii_isdigit(**str)) { /* parse "from" part of range */ - vim_str2nr(*str, NULL, &len, FALSE, FALSE, &num, NULL); + if (**str == '-' || ascii_isdigit(**str)) { // parse "from" part of range + vim_str2nr(*str, NULL, &len, false, false, false, &num, NULL); *str += len; *num1 = (int)num; - first = TRUE; + first = true; } *str = skipwhite(*str); - if (**str == ',') { /* parse "to" part of range */ + if (**str == ',') { // parse "to" part of range *str = skipwhite(*str + 1); - vim_str2nr(*str, NULL, &len, FALSE, FALSE, &num, NULL); + vim_str2nr(*str, NULL, &len, false, false, false, &num, NULL); if (len > 0) { *num2 = (int)num; *str = skipwhite(*str + len); - } else if (!first) /* no number given at all */ + } else if (!first) { // no number given at all return FAIL; - } else if (first) /* only one number given */ + } + } else if (first) { // only one number given *num2 = *num1; + } return OK; } diff --git a/src/nvim/ex_getln.h b/src/nvim/ex_getln.h index c537d681c6..21da8b9d42 100644 --- a/src/nvim/ex_getln.h +++ b/src/nvim/ex_getln.h @@ -14,15 +14,16 @@ #define WILD_LONGEST 7 #define WILD_ALL_KEEP 8 -#define WILD_LIST_NOTFOUND 1 -#define WILD_HOME_REPLACE 2 -#define WILD_USE_NL 4 -#define WILD_NO_BEEP 8 -#define WILD_ADD_SLASH 16 -#define WILD_KEEP_ALL 32 -#define WILD_SILENT 64 -#define WILD_ESCAPE 128 -#define WILD_ICASE 256 +#define WILD_LIST_NOTFOUND 0x01 +#define WILD_HOME_REPLACE 0x02 +#define WILD_USE_NL 0x04 +#define WILD_NO_BEEP 0x08 +#define WILD_ADD_SLASH 0x10 +#define WILD_KEEP_ALL 0x20 +#define WILD_SILENT 0x40 +#define WILD_ESCAPE 0x80 +#define WILD_ICASE 0x100 +#define WILD_ALLLINKS 0x200 /// Present history tables typedef enum { diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index 4f345158cf..b213a42c52 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -1340,6 +1340,7 @@ void free_findfile(void) * * options: * FNAME_MESS give error message when not found + * FNAME_UNESC unescape backslashes * * Uses NameBuff[]! * @@ -1385,6 +1386,14 @@ find_file_in_path_option ( xfree(ff_file_to_find); ff_file_to_find = vim_strsave(NameBuff); + if (options & FNAME_UNESC) { + // Change all "\ " to " ". + for (ptr = ff_file_to_find; *ptr != NUL; ++ptr) { + if (ptr[0] == '\\' && ptr[1] == ' ') { + memmove(ptr, ptr + 1, STRLEN(ptr)); + } + } + } } rel_to_curdir = (ff_file_to_find[0] == '.' diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 97360d1881..badb5b85b0 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -1992,13 +1992,14 @@ failed: } #ifdef OPEN_CHR_FILES -/* - * Returns TRUE if the file name argument is of the form "/dev/fd/\d\+", - * which is the name of files used for process substitution output by - * some shells on some operating systems, e.g., bash on SunOS. - * Do not accept "/dev/fd/[012]", opening these may hang Vim. - */ -static int is_dev_fd_file(char_u *fname) +/// Returns true if the file name argument is of the form "/dev/fd/\d\+", +/// which is the name of files used for process substitution output by +/// some shells on some operating systems, e.g., bash on SunOS. +/// Do not accept "/dev/fd/[012]", opening these may hang Vim. +/// +/// @param fname file name to check +static bool is_dev_fd_file(char_u *fname) + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT { return STRNCMP(fname, "/dev/fd/", 8) == 0 && ascii_isdigit(fname[8]) @@ -3806,29 +3807,30 @@ void msg_add_fname(buf_T *buf, char_u *fname) STRCAT(IObuff, "\" "); } -/* - * Append message for text mode to IObuff. - * Return TRUE if something appended. - */ -static int msg_add_fileformat(int eol_type) +/// Append message for text mode to IObuff. +/// +/// @param eol_type line ending type +/// +/// @return true if something was appended. +static bool msg_add_fileformat(int eol_type) { #ifndef USE_CRNL if (eol_type == EOL_DOS) { STRCAT(IObuff, shortmess(SHM_TEXT) ? _("[dos]") : _("[dos format]")); - return TRUE; + return true; } #endif if (eol_type == EOL_MAC) { STRCAT(IObuff, shortmess(SHM_TEXT) ? _("[mac]") : _("[mac format]")); - return TRUE; + return true; } #ifdef USE_CRNL if (eol_type == EOL_UNIX) { STRCAT(IObuff, shortmess(SHM_TEXT) ? _("[unix]") : _("[unix format]")); - return TRUE; + return true; } #endif - return FALSE; + return false; } /* @@ -3892,7 +3894,11 @@ static int check_mtime(buf_T *buf, FileInfo *file_info) return OK; } -static int time_differs(long t1, long t2) +/// Return true if the times differ +/// +/// @param t1 first time +/// @param t2 second time +static bool time_differs(long t1, long t2) FUNC_ATTR_CONST { #if defined(__linux__) || defined(MSWIN) /* On a FAT filesystem, esp. under Linux, there are only 5 bits to store @@ -4081,19 +4087,17 @@ static int buf_write_bytes(struct bw_info *ip) return (wlen < len) ? FAIL : OK; } -/* - * Convert a Unicode character to bytes. - * Return TRUE for an error, FALSE when it's OK. - */ -static int -ucs2bytes ( - unsigned c, /* in: character */ - char_u **pp, /* in/out: pointer to result */ - int flags /* FIO_ flags */ -) +/// Convert a Unicode character to bytes. +/// +/// @param c character to convert +/// @param[in,out] pp pointer to store the result at +/// @param flags FIO_ flags that specify which encoding to use +/// +/// @return true for an error, false when it's OK. +static bool ucs2bytes(unsigned c, char_u **pp, int flags) FUNC_ATTR_NONNULL_ALL { char_u *p = *pp; - int error = FALSE; + bool error = false; int cc; @@ -4115,8 +4119,9 @@ ucs2bytes ( /* Make two words, ten bits of the character in each. First * word is 0xd800 - 0xdbff, second one 0xdc00 - 0xdfff */ c -= 0x10000; - if (c >= 0x100000) - error = TRUE; + if (c >= 0x100000) { + error = true; + } cc = ((c >> 10) & 0x3ff) + 0xd800; if (flags & FIO_ENDIAN_L) { *p++ = cc; @@ -4126,8 +4131,9 @@ ucs2bytes ( *p++ = cc; } c = (c & 0x3ff) + 0xdc00; - } else - error = TRUE; + } else { + error = true; + } } if (flags & FIO_ENDIAN_L) { *p++ = c; @@ -4138,7 +4144,7 @@ ucs2bytes ( } } else { /* Latin1 */ if (c >= 0x100) { - error = TRUE; + error = true; *p++ = 0xBF; } else *p++ = c; @@ -4148,11 +4154,14 @@ ucs2bytes ( return error; } -/* - * Return TRUE if file encoding "fenc" requires conversion from or to - * 'encoding'. - */ -static int need_conversion(char_u *fenc) +/// Return true if file encoding "fenc" requires conversion from or to +/// 'encoding'. +/// +/// @param fenc file encoding to check +/// +/// @return true if conversion is required +static bool need_conversion(const char_u *fenc) + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT { int same_encoding; int enc_flags; @@ -4179,19 +4188,19 @@ static int need_conversion(char_u *fenc) return !(enc_utf8 && fenc_flags == FIO_UTF8); } -/* - * Check "ptr" for a unicode encoding and return the FIO_ flags needed for the - * internal conversion. - * if "ptr" is an empty string, use 'encoding'. - */ -static int get_fio_flags(char_u *ptr) +/// Return the FIO_ flags needed for the internal conversion if 'name' was +/// unicode or latin1, otherwise 0. If "name" is an empty string, +/// use 'encoding'. +/// +/// @param name string to check for encoding +static int get_fio_flags(const char_u *name) { int prop; - if (*ptr == NUL) - ptr = p_enc; - - prop = enc_canon_props(ptr); + if (*name == NUL) { + name = p_enc; + } + prop = enc_canon_props(name); if (prop & ENC_UNICODE) { if (prop & ENC_2BYTE) { if (prop & ENC_ENDIAN_L) @@ -4423,11 +4432,15 @@ char *modname(const char *fname, const char *ext, bool prepend_dot) return retval; } -/* - * Like fgets(), but if the file line is too long, it is truncated and the - * rest of the line is thrown away. Returns TRUE for end-of-file. - */ -int vim_fgets(char_u *buf, int size, FILE *fp) +/// Like fgets(), but if the file line is too long, it is truncated and the +/// rest of the line is thrown away. +/// +/// @param[out] buf buffer to fill +/// @param size size of the buffer +/// @param fp file to read from +/// +/// @return true for end-of-file. +bool vim_fgets(char_u *buf, int size, FILE *fp) FUNC_ATTR_NONNULL_ALL { char *eof; #define FGETS_SIZE 200 @@ -5326,11 +5339,13 @@ static void au_del_group(char_u *name) } } -/* - * Find the ID of an autocmd group name. - * Return it's ID. Returns AUGROUP_ERROR (< 0) for error. - */ -static int au_find_group(char_u *name) +/// Find the ID of an autocmd group name. +/// +/// @param name augroup name +/// +/// @return the ID or AUGROUP_ERROR (< 0) for error. +static int au_find_group(const char_u *name) + FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { for (int i = 0; i < augroups.ga_len; ++i) { if (AUGROUP_NAME(i) != NULL && STRCMP(AUGROUP_NAME(i), name) == 0) { @@ -5340,10 +5355,11 @@ static int au_find_group(char_u *name) return AUGROUP_ERROR; } -/* - * Return TRUE if augroup "name" exists. - */ -int au_has_group(char_u *name) +/// Return true if augroup "name" exists. +/// +/// @param name augroup name +bool au_has_group(const char_u *name) + FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { return au_find_group(name) != AUGROUP_ERROR; } @@ -5460,21 +5476,24 @@ find_end_event ( return pat; } -/* - * Return TRUE if "event" is included in 'eventignore'. - */ -static int event_ignored(event_T event) +/// Return true if "event" is included in 'eventignore'. +/// +/// @param event event to check +static bool event_ignored(event_T event) + FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { - char_u *p = p_ei; + char_u *p = p_ei; while (*p != NUL) { - if (STRNICMP(p, "all", 3) == 0 && (p[3] == NUL || p[3] == ',')) - return TRUE; - if (event_name2nr(p, &p) == event) - return TRUE; + if (STRNICMP(p, "all", 3) == 0 && (p[3] == NUL || p[3] == ',')) { + return true; + } + if (event_name2nr(p, &p) == event) { + return true; + } } - return FALSE; + return false; } /* @@ -5991,18 +6010,19 @@ void ex_doautoall(exarg_T *eap) check_cursor(); /* just in case lines got deleted */ } -/* - * Check *argp for <nomodeline>. When it is present return FALSE, otherwise - * return TRUE and advance *argp to after it. - * Thus return TRUE when do_modelines() should be called. - */ -int check_nomodeline(char_u **argp) +/// Check *argp for <nomodeline>. When it is present return false, otherwise +/// return true and advance *argp to after it. Thus do_modelines() should be +/// called when true is returned. +/// +/// @param[in,out] argp argument string +bool check_nomodeline(char_u **argp) + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT { if (STRNCMP(*argp, "<nomodeline>", 12) == 0) { *argp = skipwhite(*argp + 12); - return FALSE; + return false; } - return TRUE; + return true; } /* @@ -6179,76 +6199,78 @@ win_found: static int autocmd_nested = FALSE; -/* - * Execute autocommands for "event" and file name "fname". - * Return TRUE if some commands were executed. - */ -int -apply_autocmds ( - event_T event, - char_u *fname, /* NULL or empty means use actual file name */ - char_u *fname_io, /* fname to use for <afile> on cmdline */ - int force, /* when TRUE, ignore autocmd_busy */ - buf_T *buf /* buffer for <abuf> */ -) +/// Execute autocommands for "event" and file name "fname". +/// +/// @param event event that occured +/// @param fname filename, NULL or empty means use actual file name +/// @param fname_io filename to use for <afile> on cmdline +/// @param force When true, ignore autocmd_busy +/// @param buf Buffer for <abuf> +/// +/// @return true if some commands were executed. +bool apply_autocmds(event_T event, char_u *fname, char_u *fname_io, bool force, + buf_T *buf) { return apply_autocmds_group(event, fname, fname_io, force, AUGROUP_ALL, buf, NULL); } -/* - * Like apply_autocmds(), but with extra "eap" argument. This takes care of - * setting v:filearg. - */ -static int apply_autocmds_exarg(event_T event, char_u *fname, char_u *fname_io, int force, buf_T *buf, exarg_T *eap) +/// Like apply_autocmds(), but with extra "eap" argument. This takes care of +/// setting v:filearg. +/// +/// @param event event that occured +/// @param fname NULL or empty means use actual file name +/// @param fname_io fname to use for <afile> on cmdline +/// @param force When true, ignore autocmd_busy +/// @param buf Buffer for <abuf> +/// @param exarg Ex command arguments +/// +/// @return true if some commands were executed. +static bool apply_autocmds_exarg(event_T event, char_u *fname, char_u *fname_io, + bool force, buf_T *buf, exarg_T *eap) { return apply_autocmds_group(event, fname, fname_io, force, AUGROUP_ALL, buf, eap); } -/* - * Like apply_autocmds(), but handles the caller's retval. If the script - * processing is being aborted or if retval is FAIL when inside a try - * conditional, no autocommands are executed. If otherwise the autocommands - * cause the script to be aborted, retval is set to FAIL. - */ -int -apply_autocmds_retval ( - event_T event, - char_u *fname, /* NULL or empty means use actual file name */ - char_u *fname_io, /* fname to use for <afile> on cmdline */ - int force, /* when TRUE, ignore autocmd_busy */ - buf_T *buf, /* buffer for <abuf> */ - int *retval /* pointer to caller's retval */ -) +/// Like apply_autocmds(), but handles the caller's retval. If the script +/// processing is being aborted or if retval is FAIL when inside a try +/// conditional, no autocommands are executed. If otherwise the autocommands +/// cause the script to be aborted, retval is set to FAIL. +/// +/// @param event event that occured +/// @param fname NULL or empty means use actual file name +/// @param fname_io fname to use for <afile> on cmdline +/// @param force When true, ignore autocmd_busy +/// @param buf Buffer for <abuf> +/// @param[in,out] retval caller's retval +/// +/// @return true if some autocommands were executed +bool apply_autocmds_retval(event_T event, char_u *fname, char_u *fname_io, + bool force, buf_T *buf, int *retval) { - int did_cmd; - - if (should_abort(*retval)) - return FALSE; + if (should_abort(*retval)) { + return false; + } - did_cmd = apply_autocmds_group(event, fname, fname_io, force, - AUGROUP_ALL, buf, NULL); - if (did_cmd - && aborting() - ) + bool did_cmd = apply_autocmds_group(event, fname, fname_io, force, + AUGROUP_ALL, buf, NULL); + if (did_cmd && aborting()) { *retval = FAIL; + } return did_cmd; } -/* - * Return TRUE when there is a CursorHold autocommand defined. - */ -int has_cursorhold(void) +/// Return true when there is a CursorHold/CursorHoldI autocommand defined for +/// the current mode. +bool has_cursorhold(void) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { return first_autopat[(int)(get_real_state() == NORMAL_BUSY ? EVENT_CURSORHOLD : EVENT_CURSORHOLDI)] != NULL; } -/* - * Return TRUE if the CursorHold event can be triggered. - */ -int trigger_cursorhold(void) +/// Return true if the CursorHold/CursorHoldI event can be triggered. +bool trigger_cursorhold(void) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { int state; @@ -6259,10 +6281,11 @@ int trigger_cursorhold(void) && !ins_compl_active() ) { state = get_real_state(); - if (state == NORMAL_BUSY || (state & INSERT) != 0) - return TRUE; + if (state == NORMAL_BUSY || (state & INSERT) != 0) { + return true; + } } - return FALSE; + return false; } /// Return true if "event" autocommand is defined. @@ -6273,23 +6296,27 @@ bool has_event(int event) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT return first_autopat[event] != NULL; } -static int -apply_autocmds_group ( - event_T event, - char_u *fname, /* NULL or empty means use actual file name */ - char_u *fname_io, /* fname to use for <afile> on cmdline, NULL means - use fname */ - int force, /* when TRUE, ignore autocmd_busy */ - int group, /* group ID, or AUGROUP_ALL */ - buf_T *buf, /* buffer for <abuf> */ - exarg_T *eap /* command arguments */ -) +/// Execute autocommands for "event" and file name "fname". +/// +/// @param event event that occured +/// @param fname filename, NULL or empty means use actual file name +/// @param fname_io filename to use for <afile> on cmdline, +/// NULL means use `fname`. +/// @param force When true, ignore autocmd_busy +/// @param group autocmd group ID or AUGROUP_ALL +/// @param buf Buffer for <abuf> +/// @param eap Ex command arguments +/// +/// @return true if some commands were executed. +static bool apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io, + bool force, int group, buf_T *buf, + exarg_T *eap) { char_u *sfname = NULL; /* short file name */ char_u *tail; bool save_changed; buf_T *old_curbuf; - int retval = FALSE; + bool retval = false; char_u *save_sourcing_name; linenr_T save_sourcing_lnum; char_u *save_autocmd_fname; @@ -6443,7 +6470,7 @@ apply_autocmds_group ( } if (fname == NULL) { /* out of memory */ xfree(sfname); - retval = FALSE; + retval = false; goto BYPASS_AU; } @@ -6526,17 +6553,19 @@ apply_autocmds_group ( if (eap != NULL) { save_cmdarg = set_cmdarg(eap, NULL); set_vim_var_nr(VV_CMDBANG, (long)eap->forceit); - } else - save_cmdarg = NULL; /* avoid gcc warning */ - retval = TRUE; - /* mark the last pattern, to avoid an endless loop when more patterns - * are added when executing autocommands */ - for (ap = patcmd.curpat; ap->next != NULL; ap = ap->next) - ap->last = FALSE; - ap->last = TRUE; - check_lnums(TRUE); /* make sure cursor and topline are valid */ + } else { + save_cmdarg = NULL; // avoid gcc warning + } + retval = true; + // mark the last pattern, to avoid an endless loop when more patterns + // are added when executing autocommands + for (ap = patcmd.curpat; ap->next != NULL; ap = ap->next) { + ap->last = false; + } + ap->last = true; + check_lnums(true); // make sure cursor and topline are valid do_cmdline(NULL, getnextac, (void *)&patcmd, - DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT); + DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT); if (eap != NULL) { (void)set_cmdarg(NULL, save_cmdarg); set_vim_var_nr(VV_CMDBANG, save_cmdbang); @@ -6752,21 +6781,25 @@ char_u *getnextac(int c, void *cookie, int indent) return retval; } -/* - * Return TRUE if there is a matching autocommand for "fname". - * To account for buffer-local autocommands, function needs to know - * in which buffer the file will be opened. - */ -int has_autocmd(event_T event, char_u *sfname, buf_T *buf) +/// Return true if there is a matching autocommand for "fname". +/// To account for buffer-local autocommands, function needs to know +/// in which buffer the file will be opened. +/// +/// @param event event that occured. +/// @param sfname filename the event occured in. +/// @param buf buffer the file is open in +bool has_autocmd(event_T event, char_u *sfname, buf_T *buf) + FUNC_ATTR_WARN_UNUSED_RESULT { AutoPat *ap; char_u *fname; char_u *tail = path_tail(sfname); - int retval = FALSE; + bool retval = false; - fname = (char_u *)FullName_save((char *)sfname, FALSE); - if (fname == NULL) - return FALSE; + fname = (char_u *)FullName_save((char *)sfname, false); + if (fname == NULL) { + return false; + } #ifdef BACKSLASH_IN_FILENAME // Replace all backslashes with forward slashes. This makes the @@ -6776,16 +6809,16 @@ int has_autocmd(event_T event, char_u *sfname, buf_T *buf) forward_slash(fname); #endif - for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next) + for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next) { if (ap->pat != NULL && ap->cmds != NULL && (ap->buflocal_nr == 0 ? match_file_pat(NULL, &ap->reg_prog, fname, sfname, tail, ap->allow_dirs) - : buf != NULL && ap->buflocal_nr == buf->b_fnum - )) { - retval = TRUE; + : buf != NULL && ap->buflocal_nr == buf->b_fnum)) { + retval = true; break; } + } xfree(fname); #ifdef BACKSLASH_IN_FILENAME @@ -6873,29 +6906,27 @@ char_u *get_event_name(expand_T *xp, int idx) } -/* - * Return TRUE if autocmd is supported. - */ -int autocmd_supported(char_u *name) +/// Return true if autocmd "event" is supported. +bool autocmd_supported(char_u *event) { char_u *p; - return event_name2nr(name, &p) != NUM_EVENTS; + return event_name2nr(event, &p) != NUM_EVENTS; } -/* - * Return TRUE if an autocommand is defined for a group, event and - * pattern: The group can be omitted to accept any group. "event" and "pattern" - * can be NULL to accept any event and pattern. "pattern" can be NULL to accept - * any pattern. Buffer-local patterns <buffer> or <buffer=N> are accepted. - * Used for: - * exists("#Group") or - * exists("#Group#Event") or - * exists("#Group#Event#pat") or - * exists("#Event") or - * exists("#Event#pat") - */ -int au_exists(char_u *arg) +/// Return true if an autocommand is defined for a group, event and +/// pattern: The group can be omitted to accept any group. +/// `event` and `pattern` can be omitted to accept any event and pattern. +/// Buffer-local patterns <buffer> or <buffer=N> are accepted. +/// Used for: +/// exists("#Group") or +/// exists("#Group#Event") or +/// exists("#Group#Event#pat") or +/// exists("#Event") or +/// exists("#Event#pat") +/// +/// @param arg autocommand string +bool au_exists(const char_u *arg) FUNC_ATTR_WARN_UNUSED_RESULT { char_u *arg_save; char_u *pattern = NULL; @@ -6905,7 +6936,7 @@ int au_exists(char_u *arg) AutoPat *ap; buf_T *buflocal_buf = NULL; int group; - int retval = FALSE; + bool retval = false; /* Make a copy so that we can change the '#' chars to a NUL. */ arg_save = vim_strsave(arg); @@ -6921,8 +6952,8 @@ int au_exists(char_u *arg) event_name = arg_save; } else { if (p == NULL) { - /* "Group": group name is present and it's recognized */ - retval = TRUE; + // "Group": group name is present and it's recognized + retval = true; goto theend; } @@ -6964,7 +6995,7 @@ int au_exists(char_u *arg) || (buflocal_buf == NULL ? fnamecmp(ap->pat, pattern) == 0 : ap->buflocal_nr == buflocal_buf->b_fnum))) { - retval = TRUE; + retval = true; break; } @@ -6979,12 +7010,13 @@ theend: /// /// Used for autocommands and 'wildignore'. /// -/// @param pattern the pattern to match with -/// @param prog the pre-compiled regprog or NULL -/// @param fname the full path of the file name -/// @param sfname the short file name or NULL -/// @param tail the tail of the path -/// @param allow_dirs allow matching with dir +/// @param pattern pattern to match with +/// @param prog pre-compiled regprog or NULL +/// @param fname full path of the file name +/// @param sfname short file name or NULL +/// @param tail tail of the path +/// @param allow_dirs Allow matching with dir +/// /// @return true if there is a match, false otherwise static bool match_file_pat(char_u *pattern, regprog_T **prog, char_u *fname, char_u *sfname, char_u *tail, int allow_dirs) @@ -7023,12 +7055,17 @@ static bool match_file_pat(char_u *pattern, regprog_T **prog, char_u *fname, return result; } -/* - * Return TRUE if a file matches with a pattern in "list". - * "list" is a comma-separated list of patterns, like 'wildignore'. - * "sfname" is the short file name or NULL, "ffname" the long file name. - */ -int match_file_list(char_u *list, char_u *sfname, char_u *ffname) +/// Check if a file matches with a pattern in "list". +/// "list" is a comma-separated list of patterns, like 'wildignore'. +/// "sfname" is the short file name or NULL, "ffname" the long file name. +/// +/// @param list list of patterns to match +/// @param sfname short file name +/// @param ffname full file name +/// +/// @return true if there was a match +bool match_file_list(char_u *list, char_u *sfname, char_u *ffname) + FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(1, 3) { char_u buf[100]; char_u *tail; @@ -7039,20 +7076,21 @@ int match_file_list(char_u *list, char_u *sfname, char_u *ffname) tail = path_tail(sfname); - /* try all patterns in 'wildignore' */ + // try all patterns in 'wildignore' p = list; while (*p) { - copy_option_part(&p, buf, 100, ","); - regpat = file_pat_to_reg_pat(buf, NULL, &allow_dirs, FALSE); - if (regpat == NULL) + copy_option_part(&p, buf, ARRAY_SIZE(buf), ","); + regpat = file_pat_to_reg_pat(buf, NULL, &allow_dirs, false); + if (regpat == NULL) { break; - match = match_file_pat(regpat, NULL, ffname, sfname, - tail, (int)allow_dirs); + } + match = match_file_pat(regpat, NULL, ffname, sfname, tail, (int)allow_dirs); xfree(regpat); - if (match) - return TRUE; + if (match) { + return true; + } } - return FALSE; + return false; } /// Convert the given pattern "pat" which has shell style wildcards in it, into @@ -7068,6 +7106,7 @@ char_u * file_pat_to_reg_pat( char *allow_dirs, // Result passed back out in here int no_bslash // Don't use a backward slash as pathsep ) + FUNC_ATTR_NONNULL_ARG(1) { const char_u *endp; char_u *reg_pat; @@ -7080,6 +7119,10 @@ char_u * file_pat_to_reg_pat( if (pat_end == NULL) pat_end = pat + STRLEN(pat); + if (pat_end == pat) { + return (char_u *)xstrdup("^$"); + } + size_t size = 2; // '^' at start, '$' at end. for (p = pat; p < pat_end; p++) { diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 50eda6cb17..b45f13de4c 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -8,11 +8,10 @@ // actually defined and initialized. #ifndef EXTERN # define EXTERN extern -# define INIT(x) +# define INIT(...) #else # ifndef INIT -# define INIT(x) x -# define DO_INIT +# define INIT(...) __VA_ARGS__ # endif #endif @@ -117,12 +116,9 @@ #define DFLT_COLS 80 /* default value for 'columns' */ #define DFLT_ROWS 24 /* default value for 'lines' */ -EXTERN long Rows /* nr of rows in the screen */ -#ifdef DO_INIT - = DFLT_ROWS -#endif -; -EXTERN long Columns INIT(= DFLT_COLS); /* nr of columns in the screen */ +EXTERN long Rows INIT(= DFLT_ROWS); // nr of rows in the screen + +EXTERN long Columns INIT(= DFLT_COLS); // nr of columns in the screen /* * The characters and attributes cached for the screen. @@ -751,11 +747,8 @@ EXTERN int can_si INIT(= FALSE); */ EXTERN int can_si_back INIT(= FALSE); -EXTERN pos_T saved_cursor /* w_cursor before formatting text. */ -#ifdef DO_INIT - = INIT_POS_T(0, 0, 0) -#endif -; +// w_cursor before formatting text. +EXTERN pos_T saved_cursor INIT(= INIT_POS_T(0, 0, 0)); /* * Stuff for insert mode. @@ -917,19 +910,16 @@ EXTERN int RedrawingDisabled INIT(= 0); EXTERN int readonlymode INIT(= FALSE); /* Set to TRUE for "view" */ EXTERN int recoverymode INIT(= FALSE); /* Set to TRUE for "-r" option */ -EXTERN typebuf_T typebuf /* typeahead buffer */ -#ifdef DO_INIT - = {NULL, NULL, 0, 0, 0, 0, 0, 0, 0} -#endif -; -EXTERN int ex_normal_busy INIT(= 0); /* recursiveness of ex_normal() */ -EXTERN int ex_normal_lock INIT(= 0); /* forbid use of ex_normal() */ -EXTERN int ignore_script INIT(= FALSE); /* ignore script input */ -EXTERN int stop_insert_mode; /* for ":stopinsert" and 'insertmode' */ +// typeahead buffer +EXTERN typebuf_T typebuf INIT(= { NULL, NULL, 0, 0, 0, 0, 0, 0, 0 }); -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 int ex_normal_busy INIT(= 0); // recursiveness of ex_normal() +EXTERN int ex_normal_lock INIT(= 0); // forbid use of ex_normal() +EXTERN int ignore_script INIT(= false); // ignore script input +EXTERN int stop_insert_mode; // for ":stopinsert" and 'insertmode' +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 */ @@ -959,30 +949,28 @@ EXTERN reg_extmatch_T *re_extmatch_in INIT(= NULL); /* Used by vim_regexec(): EXTERN reg_extmatch_T *re_extmatch_out INIT(= NULL); /* Set by vim_regexec() * to store \z\(...\) matches */ -EXTERN int did_outofmem_msg INIT(= FALSE); -/* set after out of memory msg */ -EXTERN int did_swapwrite_msg INIT(= FALSE); -/* set after swap write error msg */ -EXTERN int undo_off INIT(= FALSE); /* undo switched off for now */ -EXTERN int global_busy INIT(= 0); /* set when :global is executing */ -EXTERN int listcmd_busy INIT(= FALSE); /* set when :argdo, :windo or - :bufdo is executing */ -EXTERN int need_start_insertmode INIT(= FALSE); -/* start insert mode soon */ -EXTERN char_u *last_cmdline INIT(= NULL); /* last command line (for ":) */ -EXTERN char_u *repeat_cmdline INIT(= NULL); /* command line for "." */ -EXTERN char_u *new_last_cmdline INIT(= NULL); /* new value for last_cmdline */ -EXTERN char_u *autocmd_fname INIT(= NULL); /* fname for <afile> on cmdline */ -EXTERN int autocmd_fname_full; /* autocmd_fname is full path */ -EXTERN int autocmd_bufnr INIT(= 0); /* fnum for <abuf> on cmdline */ -EXTERN char_u *autocmd_match INIT(= NULL); /* name for <amatch> on cmdline */ -EXTERN int did_cursorhold INIT(= FALSE); /* set when CursorHold t'gerd */ -EXTERN pos_T last_cursormoved /* for CursorMoved event */ -# ifdef DO_INIT - = INIT_POS_T(0, 0, 0) -# endif -; -EXTERN int last_changedtick INIT(= 0); /* for TextChanged event */ +EXTERN int did_outofmem_msg INIT(= false); +// set after out of memory msg +EXTERN int did_swapwrite_msg INIT(= false); +// set after swap write error msg +EXTERN int undo_off INIT(= false); // undo switched off for now +EXTERN int global_busy INIT(= 0); // set when :global is executing +EXTERN int listcmd_busy INIT(= false); // set when :argdo, :windo or + // :bufdo is executing +EXTERN int need_start_insertmode INIT(= false); +// start insert mode soon +EXTERN char_u *last_cmdline INIT(= NULL); // last command line (for ":) +EXTERN char_u *repeat_cmdline INIT(= NULL); // command line for "." +EXTERN char_u *new_last_cmdline INIT(= NULL); // new value for last_cmdline +EXTERN char_u *autocmd_fname INIT(= NULL); // fname for <afile> on cmdline +EXTERN int autocmd_fname_full; // autocmd_fname is full path +EXTERN int autocmd_bufnr INIT(= 0); // fnum for <abuf> on cmdline +EXTERN char_u *autocmd_match INIT(= NULL); // name for <amatch> on cmdline +EXTERN int did_cursorhold INIT(= false); // set when CursorHold t'gerd +// for CursorMoved event +EXTERN pos_T last_cursormoved INIT(= INIT_POS_T(0, 0, 0)); + +EXTERN int last_changedtick INIT(= 0); // for TextChanged event EXTERN buf_T *last_changedtick_buf INIT(= NULL); EXTERN int postponed_split INIT(= 0); /* for CTRL-W CTRL-] command */ @@ -1092,13 +1080,9 @@ EXTERN int typebuf_was_filled INIT(= FALSE); /* received text from client #ifdef BACKSLASH_IN_FILENAME -EXTERN char psepc INIT(= '\\'); /* normal path separator character */ -EXTERN char psepcN INIT(= '/'); /* abnormal path separator character */ -EXTERN char pseps[2] /* normal path separator string */ -# ifdef DO_INIT - = {'\\', 0} -# endif -; +EXTERN char psepc INIT(= '\\'); // normal path separator character +EXTERN char psepcN INIT(= '/'); // abnormal path separator character +EXTERN char pseps[2] INIT(= { '\\', 0 }); // normal path separator string #endif /* Set to TRUE when an operator is being executed with virtual editing, MAYBE @@ -1117,12 +1101,8 @@ EXTERN int need_cursor_line_redraw INIT(= FALSE); #ifdef USE_MCH_ERRMSG -/* Grow array to collect error messages in until they can be displayed. */ -EXTERN garray_T error_ga -# ifdef DO_INIT - = GA_EMPTY_INIT_VALUE -# endif -; +// Grow array to collect error messages in until they can be displayed. +EXTERN garray_T error_ga INIT(= GA_EMPTY_INIT_VALUE); #endif diff --git a/src/nvim/keymap.c b/src/nvim/keymap.c index b2fd929714..7054bb822a 100644 --- a/src/nvim/keymap.c +++ b/src/nvim/keymap.c @@ -531,17 +531,14 @@ trans_special ( return dlen; } -/* - * Try translating a <> name at (*srcp)[], return the key and modifiers. - * srcp is advanced to after the <> name. - * returns 0 if there is no match. - */ -int -find_special_key ( +// Try translating a <> name at (*srcp)[], return the key and modifiers. +// srcp is advanced to after the <> name. +// returns 0 if there is no match. +int find_special_key( char_u **srcp, int *modp, - int keycode, /* prefer key code, e.g. K_DEL instead of DEL */ - int keep_x_key /* don't translate xHome to Home key */ + int keycode, // prefer key code, e.g. K_DEL instead of DEL + int keep_x_key // don't translate xHome to Home key ) { char_u *last_dash; @@ -558,24 +555,26 @@ find_special_key ( if (src[0] != '<') return 0; - /* Find end of modifier list */ + // Find end of modifier list last_dash = src; for (bp = src + 1; *bp == '-' || vim_isIDc(*bp); bp++) { if (*bp == '-') { last_dash = bp; if (bp[1] != NUL) { - if (has_mbyte) + if (has_mbyte) { l = mb_ptr2len(bp + 1); - else + } else { l = 1; - if (bp[l + 1] == '>') - bp += l; /* anything accepted, like <C-?> */ + } + if (bp[l + 1] == '>') { + bp += l; // anything accepted, like <C-?> + } } } - if (bp[0] == 't' && bp[1] == '_' && bp[2] && bp[3]) - bp += 3; /* skip t_xx, xx may be '-' or '>' */ - else if (STRNICMP(bp, "char-", 5) == 0) { - vim_str2nr(bp + 5, NULL, &l, TRUE, TRUE, NULL, NULL); + if (bp[0] == 't' && bp[1] == '_' && bp[2] && bp[3]) { + bp += 3; // skip t_xx, xx may be '-' or '>' + } else if (STRNICMP(bp, "char-", 5) == 0) { + vim_str2nr(bp + 5, NULL, &l, true, true, true, NULL, NULL); bp += l + 5; break; } @@ -589,55 +588,53 @@ find_special_key ( for (bp = src + 1; bp < last_dash; bp++) { if (*bp != '-') { bit = name_to_mod_mask(*bp); - if (bit == 0x0) - break; /* Illegal modifier name */ + if (bit == 0x0) { + break; // Illegal modifier name + } modifiers |= bit; } } - /* - * Legal modifier name. - */ + // Legal modifier name. if (bp >= last_dash) { if (STRNICMP(last_dash + 1, "char-", 5) == 0 && ascii_isdigit(last_dash[6])) { - /* <Char-123> or <Char-033> or <Char-0x33> */ - vim_str2nr(last_dash + 6, NULL, NULL, TRUE, TRUE, NULL, &n); + // <Char-123> or <Char-033> or <Char-0x33> + vim_str2nr(last_dash + 6, NULL, NULL, true, true, true, NULL, &n); key = (int)n; } else { /* * Modifier with single letter, or special key name. */ - if (has_mbyte) + if (has_mbyte) { l = mb_ptr2len(last_dash + 1); - else + } else { l = 1; - if (modifiers != 0 && last_dash[l + 1] == '>') + } + if (modifiers != 0 && last_dash[l + 1] == '>') { key = PTR2CHAR(last_dash + 1); - else { + } else { key = get_special_key_code(last_dash + 1); - if (!keep_x_key) + if (!keep_x_key) { key = handle_x_keys(key); + } } } - /* - * get_special_key_code() may return NUL for invalid - * special key name. - */ + // get_special_key_code() may return NUL for invalid + // special key name. if (key != NUL) { - /* - * Only use a modifier when there is no special key code that - * includes the modifier. - */ + // Only use a modifier when there is no special key code that + // includes the modifier. key = simplify_key(key, &modifiers); if (!keycode) { - /* don't want keycode, use single byte code */ - if (key == K_BS) + // don't want keycode, use single byte code + if (key == K_BS) { key = BS; - else if (key == K_DEL || key == K_KDEL) + } else if (key == K_DEL || key == K_KDEL) { key = DEL; + } } // Normal Key with modifier: diff --git a/src/nvim/log.c b/src/nvim/log.c index 5767da03af..773d497881 100644 --- a/src/nvim/log.c +++ b/src/nvim/log.c @@ -10,10 +10,6 @@ #include "nvim/os/os.h" #include "nvim/os/time.h" -#ifdef HAVE_UNISTD_H -# include <unistd.h> -#endif - #define USR_LOG_FILE "$HOME" _PATHSEPSTR ".nvimlog" static uv_mutex_t mutex; diff --git a/src/nvim/message.c b/src/nvim/message.c index 66b8b9b5d2..1dd71baaa4 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -1396,7 +1396,8 @@ void msg_prt_line(char_u *s, int list) c = *p_extra++; } else if (has_mbyte && (l = (*mb_ptr2len)(s)) > 1) { col += (*mb_ptr2cells)(s); - if (lcs_nbsp != NUL && list && mb_ptr2char(s) == 160) { + if (lcs_nbsp != NUL && list + && (mb_ptr2char(s) == 160 || mb_ptr2char(s) == 0x202f)) { mb_char2bytes(lcs_nbsp, buf); buf[(*mb_ptr2len)(buf)] = NUL; } else { @@ -3037,7 +3038,7 @@ static double tv_float(typval_T *tvs, int *idxp) * http://www.ijs.si/software/snprintf/ * * This snprintf() only supports the following conversion specifiers: - * s, c, d, u, o, x, X, p (and synonyms: i, D, U, O - see below) + * s, c, b, B, d, u, o, x, X, p (and synonyms: i, D, U, O - see below) * with flags: '-', '+', ' ', '0' and '#'. * An asterisk is supported for field width as well as precision. * @@ -3103,8 +3104,9 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs) char *p = fmt; int arg_idx = 1; - if (!p) + if (!p) { p = ""; + } while (*p) { if (*p != '%') { // copy up to the next '%' or NUL without any changes @@ -3176,9 +3178,9 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs) if (*p == '*') { p++; int j = tvs ? tv_nr(tvs, &arg_idx) : va_arg(ap, int); - if (j >= 0) + if (j >= 0) { min_field_width = j; - else { + } else { min_field_width = -j; justify_left = 1; } @@ -3187,8 +3189,9 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs) // argument like common implementations do unsigned int uj = *p++ - '0'; - while (ascii_isdigit((int)(*p))) + while (ascii_isdigit((int)(*p))) { uj = 10 * uj + (unsigned int)(*p++ - '0'); + } min_field_width = uj; } @@ -3199,9 +3202,9 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs) if (*p == '*') { int j = tvs ? tv_nr(tvs, &arg_idx) : va_arg(ap, int); p++; - if (j >= 0) + if (j >= 0) { precision = j; - else { + } else { precision_specified = 0; precision = 0; } @@ -3210,8 +3213,9 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs) // treat argument like common implementations do unsigned int uj = *p++ - '0'; - while (ascii_isdigit((int)(*p))) + while (ascii_isdigit((int)(*p))) { uj = 10 * uj + (unsigned int)(*p++ - '0'); + } precision = uj; } } @@ -3262,14 +3266,13 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs) if (!str_arg) { str_arg = "[NULL]"; str_arg_l = 6; - } - // make sure not to address string beyond the specified precision - else if (!precision_specified) + } else if (!precision_specified) { + // make sure not to address string beyond the specified precision str_arg_l = strlen(str_arg); - // truncate string if necessary as requested by precision - else if (precision == 0) + } else if (precision == 0) { + // truncate string if necessary as requested by precision str_arg_l = 0; - else { + } else { // memchr on HP does not like n > 2^31 // TODO(elmart): check if this still holds / is relevant str_arg_l = (size_t)((char *)xmemscan(str_arg, @@ -3283,8 +3286,9 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs) - mb_string2cells((char_u *) str_arg); if (precision) { char_u *p1 = (char_u *)str_arg; - for (size_t i = 0; i < precision && *p1; i++) + for (size_t i = 0; i < precision && *p1; i++) { p1 += mb_ptr2len(p1); + } str_arg_l = precision = p1 - (char_u *)str_arg; } } @@ -3295,9 +3299,14 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs) } break; - case 'd': case 'u': case 'o': case 'x': case 'X': case 'p': { - // u, o, x, X and p conversion specifiers imply the value is unsigned; - // d implies a signed value + case 'd': + case 'u': + case 'b': case 'B': + case 'o': + case 'x': case 'X': + case 'p': { + // u, b, B, o, x, X and p conversion specifiers imply + // the value is unsigned; d implies a signed value // 0 if numeric argument is zero (or if pointer is NULL for 'p'), // +1 if greater than zero (or non NULL for 'p'), @@ -3325,8 +3334,9 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs) if (fmt_spec == 'p') { length_modifier = '\0'; ptr_arg = tvs ? (void *)tv_str(tvs, &arg_idx) : va_arg(ap, void *); - if (ptr_arg) + if (ptr_arg) { arg_sign = 1; + } } else if (fmt_spec == 'd') { // signed switch (length_modifier) { @@ -3334,25 +3344,28 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs) case 'h': // char and short arguments are passed as int int_arg = tvs ? tv_nr(tvs, &arg_idx) : va_arg(ap, int); - if (int_arg > 0) + if (int_arg > 0) { arg_sign = 1; - else if (int_arg < 0) + } else if (int_arg < 0) { arg_sign = -1; + } break; case 'l': long_arg = tvs ? tv_nr(tvs, &arg_idx) : va_arg(ap, long int); - if (long_arg > 0) + if (long_arg > 0) { arg_sign = 1; - else if (long_arg < 0) + } else if (long_arg < 0) { arg_sign = -1; + } break; case '2': long_long_arg = tvs ? tv_nr(tvs, &arg_idx) - : va_arg(ap, long long int); - if (long_long_arg > 0) + : va_arg(ap, long long int); // NOLINT (runtime/int) + if (long_long_arg > 0) { arg_sign = 1; - else if (long_long_arg < 0) + } else if (long_long_arg < 0) { arg_sign = -1; + } break; } } else { @@ -3362,24 +3375,23 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs) case 'h': uint_arg = tvs ? (unsigned)tv_nr(tvs, &arg_idx) : va_arg(ap, unsigned int); - if (uint_arg != 0) - arg_sign = 1; + if (uint_arg != 0) { arg_sign = 1; } break; case 'l': ulong_arg = tvs ? (unsigned long)tv_nr(tvs, &arg_idx) : va_arg(ap, unsigned long int); - if (ulong_arg != 0) - arg_sign = 1; + if (ulong_arg != 0) { arg_sign = 1; } break; case '2': - ulong_long_arg = tvs ? (unsigned long long)tv_nr(tvs, &arg_idx) - : va_arg(ap, unsigned long long int); - if (ulong_long_arg) arg_sign = 1; + ulong_long_arg = tvs + ? (unsigned long long)tv_nr(tvs, &arg_idx) // NOLINT (runtime/int) + : va_arg(ap, unsigned long long int); // NOLINT (runtime/int) + if (ulong_long_arg) { arg_sign = 1; } break; case 'z': size_t_arg = tvs ? (size_t)tv_nr(tvs, &arg_idx) : va_arg(ap, size_t); - if (size_t_arg) arg_sign = 1; + if (size_t_arg) { arg_sign = 1; } break; } } @@ -3390,16 +3402,19 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs) // For d, i, u, o, x, and X conversions, if precision is specified, // '0' flag should be ignored. This is so with Solaris 2.6, Digital UNIX // 4.0, HPUX 10, Linux, FreeBSD, NetBSD; but not with Perl. - if (precision_specified) + if (precision_specified) { zero_padding = 0; + } if (fmt_spec == 'd') { - if (force_sign && arg_sign >= 0) + if (force_sign && arg_sign >= 0) { tmp[str_arg_l++] = space_for_positive ? ' ' : '+'; + } // leave negative numbers for sprintf to handle, to // avoid handling tricky cases like (short int)-32768 } else if (alternate_form) { - if (arg_sign != 0 && (fmt_spec == 'x' || fmt_spec == 'X') ) { + if (arg_sign != 0 && (fmt_spec == 'x' || fmt_spec == 'X' || + fmt_spec == 'b' || fmt_spec == 'B')) { tmp[str_arg_l++] = '0'; tmp[str_arg_l++] = fmt_spec; } @@ -3407,20 +3422,20 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs) } zero_padding_insertion_ind = str_arg_l; - if (!precision_specified) + if (!precision_specified) { precision = 1; // default precision is 1 + } if (precision == 0 && arg_sign == 0) { // when zero value is formatted with an explicit precision 0, - // resulting formatted string is empty (d, i, u, o, x, X, p) + // resulting formatted string is empty (d, i, u, b, B, o, x, X, p) } else { char f[5]; int f_l = 0; // construct a simple format string for sprintf f[f_l++] = '%'; - if (!length_modifier) - ; - else if (length_modifier == '2') { + if (!length_modifier) { + } else if (length_modifier == '2') { f[f_l++] = 'l'; f[f_l++] = 'l'; } else @@ -3441,6 +3456,41 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs) case '2': str_arg_l += sprintf(tmp + str_arg_l, f, long_long_arg); break; } + } else if (fmt_spec == 'b' || fmt_spec == 'B') { + // binary + size_t bits = 0; + switch (length_modifier) { + case '\0': + case 'h': for (bits = sizeof(unsigned) * 8; bits > 0; bits--) { + if ((uint_arg >> (bits - 1)) & 0x1) { break; } } + + while (bits > 0) { + tmp[str_arg_l++] = + ((uint_arg >> --bits) & 0x1) ? '1' : '0'; } + break; + case 'l': for (bits = sizeof(unsigned long) * 8; bits > 0; bits--) { + if ((ulong_arg >> (bits - 1)) & 0x1) { break; } } + + while (bits > 0) { + tmp[str_arg_l++] = + ((ulong_arg >> --bits) & 0x1) ? '1' : '0'; } + break; + case '2': for (bits = sizeof(unsigned long long) * 8; // NOLINT (runtime/int) + bits > 0; bits--) { + if ((ulong_long_arg >> (bits - 1)) & 0x1) { break; } } + + while (bits > 0) { + tmp[str_arg_l++] = + ((ulong_long_arg >> --bits) & 0x1) ? '1' : '0'; } + break; + case 'z': for (bits = sizeof(size_t) * 8; bits > 0; bits--) { + if ((size_t_arg >> (bits - 1)) & 0x1) { break; } } + + while (bits > 0) { + tmp[str_arg_l++] = + ((size_t_arg >> --bits) & 0x1) ? '1' : '0'; } + break; + } } else { // unsigned switch (length_modifier) { @@ -3464,7 +3514,9 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs) if (zero_padding_insertion_ind + 1 < str_arg_l && tmp[zero_padding_insertion_ind] == '0' && (tmp[zero_padding_insertion_ind + 1] == 'x' - || tmp[zero_padding_insertion_ind + 1] == 'X')) + || tmp[zero_padding_insertion_ind + 1] == 'X' + || tmp[zero_padding_insertion_ind + 1] == 'b' + || tmp[zero_padding_insertion_ind + 1] == 'B')) zero_padding_insertion_ind += 2; } @@ -3507,7 +3559,7 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs) // floating point char format[40]; int l; - int remove_trailing_zeroes = FALSE; + int remove_trailing_zeroes = false; double f = tvs ? tv_float(tvs, &arg_idx) : va_arg(ap, double); double abs_f = f < 0 ? -f : f; @@ -3518,7 +3570,7 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs) fmt_spec = 'f'; else fmt_spec = fmt_spec == 'g' ? 'e' : 'E'; - remove_trailing_zeroes = TRUE; + remove_trailing_zeroes = true; } if (fmt_spec == 'f' && abs_f > 1.0e307) { diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 2f57d8c610..a116b5a0bd 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -1430,6 +1430,9 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) || VIsual_active ) && oap->op_type != OP_NOP) { // Avoid a problem with unwanted linebreaks in block mode + if (curwin->w_p_lbr) { + curwin->w_valid &= ~VALID_VIRTCOL; + } curwin->w_p_lbr = false; oap->is_VIsual = VIsual_active; if (oap->motion_force == 'V') @@ -1598,55 +1601,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) virtual_op = virtual_active(); if (VIsual_active || redo_VIsual_busy) { - if (VIsual_mode == Ctrl_V) { /* block mode */ - colnr_T start, end; - - oap->motion_type = MBLOCK; - - getvvcol(curwin, &(oap->start), - &oap->start_vcol, NULL, &oap->end_vcol); - if (!redo_VIsual_busy) { - getvvcol(curwin, &(oap->end), &start, NULL, &end); - - if (start < oap->start_vcol) - oap->start_vcol = start; - if (end > oap->end_vcol) { - if (*p_sel == 'e' && start >= 1 - && start - 1 >= oap->end_vcol) - oap->end_vcol = start - 1; - else - oap->end_vcol = end; - } - } - - /* if '$' was used, get oap->end_vcol from longest line */ - if (curwin->w_curswant == MAXCOL) { - curwin->w_cursor.col = MAXCOL; - oap->end_vcol = 0; - for (curwin->w_cursor.lnum = oap->start.lnum; - curwin->w_cursor.lnum <= oap->end.lnum; - ++curwin->w_cursor.lnum) { - getvvcol(curwin, &curwin->w_cursor, NULL, NULL, &end); - if (end > oap->end_vcol) - oap->end_vcol = end; - } - } else if (redo_VIsual_busy) - oap->end_vcol = oap->start_vcol + redo_VIsual_vcol - 1; - /* - * Correct oap->end.col and oap->start.col to be the - * upper-left and lower-right corner of the block area. - * - * (Actually, this does convert column positions into character - * positions) - */ - curwin->w_cursor.lnum = oap->end.lnum; - coladvance(oap->end_vcol); - oap->end = curwin->w_cursor; - - curwin->w_cursor = oap->start; - coladvance(oap->start_vcol); - oap->start = curwin->w_cursor; - } + get_op_vcol(oap, redo_VIsual_vcol, true); if (!redo_VIsual_busy && !gui_yank) { /* @@ -1894,9 +1849,14 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) else restart_edit_save = 0; restart_edit = 0; + // Restore linebreak, so that when the user edits it looks as before. - curwin->w_p_lbr = lbr_saved; - /* Reset finish_op now, don't want it set inside edit(). */ + if (curwin->w_p_lbr != lbr_saved) { + curwin->w_p_lbr = lbr_saved; + get_op_vcol(oap, redo_VIsual_mode, false); + } + + // Reset finish_op now, don't want it set inside edit(). finish_op = false; if (op_change(oap)) /* will call edit() */ cap->retval |= CA_COMMAND_BUSY; @@ -1974,7 +1934,10 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) restart_edit = 0; // Restore linebreak, so that when the user edits it looks as before. - curwin->w_p_lbr = lbr_saved; + if (curwin->w_p_lbr != lbr_saved) { + curwin->w_p_lbr = lbr_saved; + get_op_vcol(oap, redo_VIsual_mode, false); + } op_insert(oap, cap->count1); @@ -1997,7 +1960,11 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) CancelRedo(); } else { // Restore linebreak, so that when the user edits it looks as before. - curwin->w_p_lbr = lbr_saved; + if (curwin->w_p_lbr != lbr_saved) { + curwin->w_p_lbr = lbr_saved; + get_op_vcol(oap, redo_VIsual_mode, false); + } + op_replace(oap, cap->nchar); } break; @@ -7698,6 +7665,71 @@ static void nv_open(cmdarg_T *cap) n_opencmd(cap); } +// calculate start/end virtual columns for operating in block mode +static void get_op_vcol( + oparg_T *oap, + colnr_T redo_VIsual_vcol, + bool initial // when true: adjust position for 'selectmode' +) +{ + colnr_T start; + colnr_T end; + + if (VIsual_mode != Ctrl_V) { + return; + } + + oap->motion_type = MBLOCK; + + // prevent from moving onto a trail byte + if (has_mbyte) { + mb_adjustpos(curwin->w_buffer, &oap->end); + } + + getvvcol(curwin, &(oap->start), &oap->start_vcol, NULL, &oap->end_vcol); + getvvcol(curwin, &(oap->end), &start, NULL, &end); + + if (start < oap->start_vcol) { + oap->start_vcol = start; + } + if (end > oap->end_vcol) { + if (initial && *p_sel == 'e' + && start >= 1 + && start - 1 >= oap->end_vcol) { + oap->end_vcol = start - 1; + } else { + oap->end_vcol = end; + } + } + // if '$' was used, get oap->end_vcol from longest line + if (curwin->w_curswant == MAXCOL) { + curwin->w_cursor.col = MAXCOL; + oap->end_vcol = 0; + for (curwin->w_cursor.lnum = oap->start.lnum; + curwin->w_cursor.lnum <= oap->end.lnum; ++curwin->w_cursor.lnum) { + getvvcol(curwin, &curwin->w_cursor, NULL, NULL, &end); + if (end > oap->end_vcol) { + oap->end_vcol = end; + } + } + } else if (redo_VIsual_busy) { + oap->end_vcol = oap->start_vcol + redo_VIsual_vcol - 1; + } + + // Correct oap->end.col and oap->start.col to be the + // upper-left and lower-right corner of the block area. + // + // (Actually, this does convert column positions into character + // positions) + curwin->w_cursor.lnum = oap->end.lnum; + coladvance(oap->end_vcol); + oap->end = curwin->w_cursor; + + curwin->w_cursor = oap->start; + coladvance(oap->start_vcol); + oap->start = curwin->w_cursor; +} + // Handle an arbitrary event in normal mode static void nv_event(cmdarg_T *cap) { diff --git a/src/nvim/ops.c b/src/nvim/ops.c index c3d968ca51..19dbd0f9f6 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -1991,6 +1991,7 @@ void op_insert(oparg_T *oap, long count1) char_u *firstline, *ins_text; struct block_def bd; int i; + pos_T t1; /* edit() changes this - record it for OP_APPEND */ bd.is_MAX = (curwin->w_curswant == MAXCOL); @@ -2053,7 +2054,16 @@ void op_insert(oparg_T *oap, long count1) } } - edit(NUL, FALSE, (linenr_T)count1); + t1 = oap->start; + edit(NUL, false, (linenr_T)count1); + + // When a tab was inserted, and the characters in front of the tab + // have been converted to a tab as well, the column of the cursor + // might have actually been reduced, so need to adjust here. */ + if (t1.lnum == curbuf->b_op_start_orig.lnum && + lt(curbuf->b_op_start_orig, t1)) { + oap->start = curbuf->b_op_start_orig; + } /* If user has moved off this line, we don't know what to do, so do * nothing. @@ -2069,21 +2079,23 @@ void op_insert(oparg_T *oap, long count1) if (oap->start.lnum == curbuf->b_op_start_orig.lnum && !bd.is_MAX) { if (oap->op_type == OP_INSERT && oap->start.col + oap->start.coladd - != curbuf->b_op_start_orig.col + curbuf->b_op_start_orig.coladd) { + != curbuf->b_op_start_orig.col + curbuf->b_op_start_orig.coladd) { + size_t t = getviscol2(curbuf->b_op_start_orig.col, + curbuf->b_op_start_orig.coladd); oap->start.col = curbuf->b_op_start_orig.col; - pre_textlen -= getviscol2(oap->start.col, oap->start.coladd) - - oap->start_vcol; - oap->start_vcol = getviscol2(oap->start.col, oap->start.coladd); + pre_textlen -= t - oap->start_vcol; + oap->start_vcol = t; } else if (oap->op_type == OP_APPEND && oap->end.col + oap->end.coladd - >= curbuf->b_op_start_orig.col - + curbuf->b_op_start_orig.coladd) { + >= curbuf->b_op_start_orig.col + + curbuf->b_op_start_orig.coladd) { + size_t t = getviscol2(curbuf->b_op_start_orig.col, + curbuf->b_op_start_orig.coladd); oap->start.col = curbuf->b_op_start_orig.col; /* reset pre_textlen to the value of OP_INSERT */ pre_textlen += bd.textlen; - pre_textlen -= getviscol2(oap->start.col, oap->start.coladd) - - oap->start_vcol; - oap->start_vcol = getviscol2(oap->start.col, oap->start.coladd); + pre_textlen -= t - oap->start_vcol; + oap->start_vcol = t; oap->op_type = OP_INSERT; } } @@ -4186,75 +4198,102 @@ static void reverse_line(char_u *s) # define RLADDSUBFIX(ptr) if (curwin->w_p_rl) reverse_line(ptr); -/* - * add or subtract 'Prenum1' from a number in a line - * 'command' is CTRL-A for add, CTRL-X for subtract - * - * return FAIL for failure, OK otherwise - */ +/// Add or subtract from a number in a line. +/// +/// @param command CTRL-A for add, CTRL-X for subtract +// @param Prenum1 number to add or subtract +/// +/// @return FAIL for failure, OK otherwise int do_addsub(int command, linenr_T Prenum1) { int col; char_u *buf1; char_u buf2[NUMBUFLEN]; - int hex; /* 'X' or 'x': hex; '0': octal */ - static int hexupper = FALSE; /* 0xABC */ + int pre; // 'X' or 'x': hex; '0': octal; 'B' or 'b': bin + static int hexupper = false; // 0xABC unsigned long n, oldn; char_u *ptr; int c; - int length = 0; /* character length of the number */ + int length = 0; // character length of the number int todel; int dohex; int dooct; + int dobin; int doalp; int firstdigit; int negative; int subtract; - dohex = (vim_strchr(curbuf->b_p_nf, 'x') != NULL); /* "heX" */ - dooct = (vim_strchr(curbuf->b_p_nf, 'o') != NULL); /* "Octal" */ - doalp = (vim_strchr(curbuf->b_p_nf, 'p') != NULL); /* "alPha" */ + dohex = (vim_strchr(curbuf->b_p_nf, 'x') != NULL); // "heX" + dooct = (vim_strchr(curbuf->b_p_nf, 'o') != NULL); // "Octal" + dobin = (vim_strchr(curbuf->b_p_nf, 'b') != NULL); // "Bin" + doalp = (vim_strchr(curbuf->b_p_nf, 'p') != NULL); // "alPha" ptr = get_cursor_line_ptr(); RLADDSUBFIX(ptr); - /* - * First check if we are on a hexadecimal number, after the "0x". - */ + // First check if we are on a hexadecimal number, after the "0x". col = curwin->w_cursor.col; - if (dohex) - while (col > 0 && ascii_isxdigit(ptr[col])) - --col; - if ( dohex - && col > 0 - && (ptr[col] == 'X' - || ptr[col] == 'x') - && ptr[col - 1] == '0' - && ascii_isxdigit(ptr[col + 1])) { - /* - * Found hexadecimal number, move to its start. - */ - --col; + + if (dobin) { + while (col > 0 && ascii_isbdigit(ptr[col])) { + col--; + } + } + + if (dohex) { + while (col > 0 && ascii_isxdigit(ptr[col])) { + col--; + } + } + if (dobin + && dohex + && !((col > 0 + && (ptr[col] == 'X' || + ptr[col] == 'x') + && ptr[col - 1] == '0' + && ascii_isxdigit(ptr[col + 1])))) { + // In case of binary/hexadecimal pattern overlap match, rescan + + col = curwin->w_cursor.col; + + while (col > 0 && ascii_isdigit(ptr[col])) { + col--; + } + } + + if ((dohex + && col > 0 + && (ptr[col] == 'X' + || ptr[col] == 'x') + && ptr[col - 1] == '0' + && ascii_isxdigit(ptr[col + 1])) || + (dobin + && col > 0 + && (ptr[col] == 'B' + || ptr[col] == 'b') + && ptr[col - 1] == '0' + && ascii_isbdigit(ptr[col + 1]))) { + // Found hexadecimal or binary number, move to its start. + col--; } else { - /* - * Search forward and then backward to find the start of number. - */ + // Search forward and then backward to find the start of number. col = curwin->w_cursor.col; while (ptr[col] != NUL && !ascii_isdigit(ptr[col]) - && !(doalp && ASCII_ISALPHA(ptr[col]))) - ++col; + && !(doalp && ASCII_ISALPHA(ptr[col]))) { + col++; + } while (col > 0 && ascii_isdigit(ptr[col - 1]) - && !(doalp && ASCII_ISALPHA(ptr[col]))) - --col; + && !(doalp && ASCII_ISALPHA(ptr[col]))) { + col--; + } } - /* - * If a number was found, and saving for undo works, replace the number. - */ + // If a number was found, and saving for undo works, replace the number. firstdigit = ptr[col]; RLADDSUBFIX(ptr); if ((!ascii_isdigit(firstdigit) && !(doalp && ASCII_ISALPHA(firstdigit))) @@ -4263,152 +4302,170 @@ int do_addsub(int command, linenr_T Prenum1) return FAIL; } - /* get ptr again, because u_save() may have changed it */ + // get ptr again, because u_save() may have changed it ptr = get_cursor_line_ptr(); RLADDSUBFIX(ptr); if (doalp && ASCII_ISALPHA(firstdigit)) { - /* decrement or increment alphabetic character */ + // decrement or increment alphabetic character if (command == Ctrl_X) { if (CharOrd(firstdigit) < Prenum1) { - if (isupper(firstdigit)) + if (isupper(firstdigit)) { firstdigit = 'A'; - else + } else { firstdigit = 'a'; - } else + } + } else { firstdigit -= Prenum1; + } } else { if (26 - CharOrd(firstdigit) - 1 < Prenum1) { - if (isupper(firstdigit)) + if (isupper(firstdigit)) { firstdigit = 'Z'; - else + } else { firstdigit = 'z'; - } else + } + } else { firstdigit += Prenum1; + } } curwin->w_cursor.col = col; - (void)del_char(FALSE); + (void)del_char(false); ins_char(firstdigit); } else { - negative = FALSE; - if (col > 0 && ptr[col - 1] == '-') { /* negative number */ + negative = false; + if (col > 0 && ptr[col - 1] == '-') { // negative number --col; - negative = TRUE; + negative = true; } - /* get the number value (unsigned) */ - vim_str2nr(ptr + col, &hex, &length, dooct, dohex, NULL, &n); + // get the number value (unsigned) + vim_str2nr(ptr + col, &pre, &length, dobin, dooct, dohex, NULL, &n); - /* ignore leading '-' for hex and octal numbers */ - if (hex && negative) { + // ignore leading '-' for hex, octal and bin numbers + if (pre && negative) { ++col; --length; - negative = FALSE; + negative = false; } - /* add or subtract */ - subtract = FALSE; - if (command == Ctrl_X) - subtract ^= TRUE; - if (negative) - subtract ^= TRUE; + // add or subtract + subtract = false; + if (command == Ctrl_X) { + subtract ^= true; + } + if (negative) { + subtract ^= true; + } oldn = n; - if (subtract) - n -= (unsigned long)Prenum1; - else - n += (unsigned long)Prenum1; - /* handle wraparound for decimal numbers */ - if (!hex) { + n = subtract ? n - (unsigned long) Prenum1 + : n + (unsigned long) Prenum1; + + // handle wraparound for decimal numbers + if (!pre) { if (subtract) { if (n > oldn) { n = 1 + (n ^ (unsigned long)-1); - negative ^= TRUE; + negative ^= true; } } else { /* add */ if (n < oldn) { n = (n ^ (unsigned long)-1); - negative ^= TRUE; + negative ^= true; } } - if (n == 0) - negative = FALSE; + if (n == 0) { + negative = false; + } } - /* - * Delete the old number. - */ + // Delete the old number. curwin->w_cursor.col = col; todel = length; c = gchar_cursor(); - /* - * Don't include the '-' in the length, only the length of the part - * after it is kept the same. - */ - if (c == '-') + + // Don't include the '-' in the length, only the length of the part + // after it is kept the same. + if (c == '-') { --length; + } while (todel-- > 0) { if (c < 0x100 && isalpha(c)) { - if (isupper(c)) - hexupper = TRUE; - else - hexupper = FALSE; + if (isupper(c)) { + hexupper = true; + } else { + hexupper = false; + } } - /* del_char() will mark line needing displaying */ - (void)del_char(FALSE); + // del_char() will mark line needing displaying + (void)del_char(false); c = gchar_cursor(); } - /* - * Prepare the leading characters in buf1[]. - * When there are many leading zeros it could be very long. Allocate - * a bit too much. - */ + // Prepare the leading characters in buf1[]. + // When there are many leading zeros it could be very long. Allocate + // a bit too much. buf1 = xmalloc(length + NUMBUFLEN); ptr = buf1; if (negative) { *ptr++ = '-'; } - if (hex) { + if (pre) { *ptr++ = '0'; --length; } - if (hex == 'x' || hex == 'X') { - *ptr++ = hex; + if (pre == 'b' || pre == 'B' || + pre == 'x' || pre == 'X') { + *ptr++ = pre; --length; } - /* - * Put the number characters in buf2[]. - */ - if (hex == 0) - sprintf((char *)buf2, "%" PRIu64, (uint64_t)n); - else if (hex == '0') - sprintf((char *)buf2, "%" PRIo64, (uint64_t)n); - else if (hex && hexupper) - sprintf((char *)buf2, "%" PRIX64, (uint64_t)n); - else - sprintf((char *)buf2, "%" PRIx64, (uint64_t)n); + // Put the number characters in buf2[]. + if (pre == 'b' || pre == 'B') { + size_t bits = 0; + size_t pos = 0; + + // leading zeros + for (bits = 8 * sizeof(unsigned long); bits > 0; bits--) { + if ((n >> (bits - 1)) & 0x1) { break; } + } + + while (bits > 0) { + buf2[pos++] = ((n >> --bits) & 0x1) ? '1' : '0'; + } + + buf2[pos] = '\0'; + + } else if (pre == 0) { + snprintf((char *)buf2, NUMBUFLEN, "%" PRIu64, (uint64_t)n); + } else if (pre == '0') { + snprintf((char *)buf2, NUMBUFLEN, "%" PRIo64, (uint64_t)n); + } else if (pre && hexupper) { + snprintf((char *)buf2, NUMBUFLEN, "%" PRIX64, (uint64_t)n); + } else { + snprintf((char *)buf2, NUMBUFLEN, "%" PRIx64, (uint64_t)n); + } length -= (int)STRLEN(buf2); - /* - * Adjust number of zeros to the new number of digits, so the - * total length of the number remains the same. - * Don't do this when - * the result may look like an octal number. - */ - if (firstdigit == '0' && !(dooct && hex == 0)) - while (length-- > 0) + // Adjust number of zeros to the new number of digits, so the + // total length of the number remains the same. + // Don't do this when + // the result may look like an octal number. + if (firstdigit == '0' && !(dooct && pre == 0)) { + while (length-- > 0) { *ptr++ = '0'; + } + } *ptr = NUL; STRCAT(buf1, buf2); ins_str(buf1); /* insert the new number */ xfree(buf1); } --curwin->w_cursor.col; - curwin->w_set_curswant = TRUE; - ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE); + curwin->w_set_curswant = true; + ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, true); RLADDSUBFIX(ptr); return OK; } diff --git a/src/nvim/option.c b/src/nvim/option.c index 2ac1abeeba..b4054dc28c 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -258,30 +258,31 @@ typedef struct vimoption { #define PARAM_COUNT ARRAY_SIZE(options) -static char *(p_ambw_values[]) = {"single", "double", NULL}; -static char *(p_bg_values[]) = {"light", "dark", NULL}; -static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL}; -static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL}; -static char *(p_wop_values[]) = {"tagfile", NULL}; -static char *(p_wak_values[]) = {"yes", "menu", "no", NULL}; -static char *(p_mousem_values[]) = -{"extend", "popup", "popup_setpos", "mac", NULL}; -static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL}; -static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL}; -static char *(p_km_values[]) = {"startsel", "stopsel", NULL}; -static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL}; -static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL}; -static char *(p_ead_values[]) = {"both", "ver", "hor", NULL}; -static char *(p_buftype_values[]) = -{"nofile", "nowrite", "quickfix", "help", "acwrite", "terminal", NULL}; -static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL}; -static char *(p_bs_values[]) = {"indent", "eol", "start", NULL}; -static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax", - "diff", - NULL}; -static char *(p_fcl_values[]) = {"all", NULL}; -static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", - "noinsert", "noselect", NULL}; +static char *(p_ambw_values[]) = { "single", "double", NULL }; +static char *(p_bg_values[]) = { "light", "dark", NULL }; +static char *(p_nf_values[]) = { "bin", "octal", "hex", "alpha", NULL }; +static char *(p_ff_values[]) = { FF_UNIX, FF_DOS, FF_MAC, NULL }; +static char *(p_wop_values[]) = { "tagfile", NULL }; +static char *(p_wak_values[]) = { "yes", "menu", "no", NULL }; +static char *(p_mousem_values[]) = { "extend", "popup", "popup_setpos", + "mac", NULL }; +static char *(p_sel_values[]) = { "inclusive", "exclusive", "old", NULL }; +static char *(p_slm_values[]) = { "mouse", "key", "cmd", NULL }; +static char *(p_km_values[]) = { "startsel", "stopsel", NULL }; +static char *(p_scbopt_values[]) = { "ver", "hor", "jump", NULL }; +static char *(p_debug_values[]) = { "msg", "throw", "beep", NULL }; +static char *(p_ead_values[]) = { "both", "ver", "hor", NULL }; +static char *(p_buftype_values[]) = { "nofile", "nowrite", "quickfix", + "help", "acwrite", "terminal", NULL }; + +static char *(p_bufhidden_values[]) = { "hide", "unload", "delete", + "wipe", NULL }; +static char *(p_bs_values[]) = { "indent", "eol", "start", NULL }; +static char *(p_fdm_values[]) = { "manual", "expr", "marker", "indent", + "syntax", "diff", NULL }; +static char *(p_fcl_values[]) = { "all", NULL }; +static char *(p_cot_values[]) = { "menu", "menuone", "longest", "preview", + "noinsert", "noselect", NULL }; #ifdef INCLUDE_GENERATED_DECLARATIONS # include "option.c.generated.h" @@ -1431,7 +1432,7 @@ do_set ( } else if (*arg == '-' || ascii_isdigit(*arg)) { // Allow negative (for 'undolevels'), octal and // hex numbers. - vim_str2nr(arg, NULL, &i, true, true, &value, NULL); + vim_str2nr(arg, NULL, &i, true, true, true, &value, NULL); if (arg[i] != NUL && !ascii_iswhite(arg[i])) { errmsg = e_invarg; goto skip; diff --git a/src/nvim/options.lua b/src/nvim/options.lua index 0eccf63e15..3dd37cb5dc 100644 --- a/src/nvim/options.lua +++ b/src/nvim/options.lua @@ -1599,7 +1599,7 @@ return { deny_duplicates=true, alloced=true, varname='p_nf', - defaults={if_true={vi="octal,hex", vim="hex"}} + defaults={if_true={vi="bin,octal,hex", vim="bin,hex"}} }, { full_name='number', abbreviation='nu', diff --git a/src/nvim/os/unix_defs.h b/src/nvim/os/unix_defs.h index 78fc9331d1..690a39c3cd 100644 --- a/src/nvim/os/unix_defs.h +++ b/src/nvim/os/unix_defs.h @@ -2,7 +2,7 @@ #define NVIM_OS_UNIX_DEFS_H // Windows doesn't have unistd.h, so we include it here to avoid numerous -// instances of `#ifdef HAVE_UNISTD_H'. +// instances of `#ifdef WIN32'. #include <unistd.h> // POSIX.1-2008 says that NAME_MAX should be in here diff --git a/src/nvim/os/win_defs.h b/src/nvim/os/win_defs.h index ca3cf5d896..242d355f77 100644 --- a/src/nvim/os/win_defs.h +++ b/src/nvim/os/win_defs.h @@ -6,6 +6,10 @@ #include <io.h> #include <stdio.h> +// Windows does not have S_IFLNK but libuv defines it +// and sets the flag for us when calling uv_fs_stat. +#include <uv.h> + #define NAME_MAX _MAX_PATH #define TEMP_DIR_NAMES {"$TMP", "$TEMP", "$USERPROFILE", ""} diff --git a/src/nvim/path.c b/src/nvim/path.c index 5ac3d07f67..8b9a49dfc0 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -681,11 +681,16 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, /* remove backslashes for the remaining components only */ (void)do_path_expand(gap, buf, len + 1, flags, false); } else { - /* no more wildcards, check if there is a match */ - /* remove backslashes for the remaining components only */ - if (*path_end != NUL) + FileInfo file_info; + + // no more wildcards, check if there is a match + // remove backslashes for the remaining components only + if (*path_end != NUL) { backslash_halve(buf + len + 1); - if (os_file_exists(buf)) { /* add existing file */ + } + // add existing file or symbolic link + if ((flags & EW_ALLLINKS) ? os_fileinfo_link((char *)buf, &file_info) + : os_file_exists(buf)) { addfile(gap, buf, flags); } } @@ -1294,26 +1299,28 @@ expand_backtick ( return cnt; } -/* - * Add a file to a file list. Accepted flags: - * EW_DIR add directories - * EW_FILE add files - * EW_EXEC add executable files - * EW_NOTFOUND add even when it doesn't exist - * EW_ADDSLASH add slash after directory name - */ -void -addfile ( +// Add a file to a file list. Accepted flags: +// EW_DIR add directories +// EW_FILE add files +// EW_EXEC add executable files +// EW_NOTFOUND add even when it doesn't exist +// EW_ADDSLASH add slash after directory name +// EW_ALLLINKS add symlink also when the referred file does not exist +void addfile( garray_T *gap, char_u *f, /* filename */ int flags ) { bool isdir; + FileInfo file_info; - /* if the file/dir doesn't exist, may not add it */ - if (!(flags & EW_NOTFOUND) && !os_file_exists(f)) + // if the file/dir/link doesn't exist, may not add it + if (!(flags & EW_NOTFOUND) && + ((flags & EW_ALLLINKS) ? + !os_fileinfo_link((char *)f, &file_info) : !os_file_exists(f))) { return; + } #ifdef FNAME_ILLEGAL /* if the file/dir contains illegal characters, don't add it */ diff --git a/src/nvim/path.h b/src/nvim/path.h index 628ea335ed..eac367d0ac 100644 --- a/src/nvim/path.h +++ b/src/nvim/path.h @@ -20,6 +20,7 @@ #define EW_KEEPDOLLAR 0x800 /* do not escape $, $var is expanded */ /* 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 /// Return value for the comparison of two files. Also @see path_full_compare. typedef enum file_comparison { diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 3abf43cb8c..85c69af192 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -2117,14 +2117,10 @@ void ex_copen(exarg_T *eap) prevwin = win; } - /* - * Fill the buffer with the quickfix list. - */ - qf_fill_buffer(qi); + qf_set_title_var(qi); - if (qi->qf_lists[qi->qf_curlist].qf_title != NULL) { - qf_set_title_var(qi); - } + // Fill the buffer with the quickfix list. + qf_fill_buffer(qi); curwin->w_cursor.lnum = qi->qf_lists[qi->qf_curlist].qf_index; curwin->w_cursor.col = 0; @@ -2256,16 +2252,13 @@ static void qf_update_buffer(qf_info_T *qi) /* set curwin/curbuf to buf and save a few things */ aucmd_prepbuf(&aco, buf); - qf_fill_buffer(qi); - - if (qi->qf_lists[qi->qf_curlist].qf_title != NULL - && (win = qf_find_win(qi)) != NULL) { + if ((win = qf_find_win(qi)) != NULL) { curwin_save = curwin; curwin = win; qf_set_title_var(qi); curwin = curwin_save; - } + qf_fill_buffer(qi); /* restore curwin/curbuf and a few other things */ aucmd_restbuf(&aco); @@ -2274,10 +2267,13 @@ static void qf_update_buffer(qf_info_T *qi) } } +// Set "w:quickfix_title" if "qi" has a title. static void qf_set_title_var(qf_info_T *qi) { - set_internal_string_var((char_u *)"w:quickfix_title", - qi->qf_lists[qi->qf_curlist].qf_title); + if (qi->qf_lists[qi->qf_curlist].qf_title != NULL) { + set_internal_string_var((char_u *)"w:quickfix_title", + qi->qf_lists[qi->qf_curlist].qf_title); + } } /* diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 39001939d8..608aa38466 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -796,13 +796,14 @@ static void reg_equi_class(int c) if (enc_utf8 || STRCMP(p_enc, "latin1") == 0 || STRCMP(p_enc, "iso-8859-15") == 0) { switch (c) { - case 'A': case '\300': case '\301': case '\302': + // Do not use '\300' style, it results in a negative number. + case 'A': case 0xc0: case 0xc1: case 0xc2: + case 0xc3: case 0xc4: case 0xc5: CASEMBC(0x100) CASEMBC(0x102) CASEMBC(0x104) CASEMBC(0x1cd) CASEMBC(0x1de) CASEMBC(0x1e0) CASEMBC(0x1ea2) - case '\303': case '\304': case '\305': - regmbc('A'); regmbc('\300'); regmbc('\301'); - regmbc('\302'); regmbc('\303'); regmbc('\304'); - regmbc('\305'); + regmbc('A'); regmbc(0xc0); regmbc(0xc1); + regmbc(0xc2); regmbc(0xc3); regmbc(0xc4); + regmbc(0xc5); REGMBC(0x100) REGMBC(0x102) REGMBC(0x104) REGMBC(0x1cd) REGMBC(0x1de) REGMBC(0x1e0) REGMBC(0x1ea2) @@ -810,9 +811,9 @@ static void reg_equi_class(int c) case 'B': CASEMBC(0x1e02) CASEMBC(0x1e06) regmbc('B'); REGMBC(0x1e02) REGMBC(0x1e06) return; - case 'C': case '\307': + case 'C': case 0xc7: CASEMBC(0x106) CASEMBC(0x108) CASEMBC(0x10a) CASEMBC(0x10c) - regmbc('C'); regmbc('\307'); + regmbc('C'); regmbc(0xc7); REGMBC(0x106) REGMBC(0x108) REGMBC(0x10a) REGMBC(0x10c) return; @@ -821,11 +822,11 @@ static void reg_equi_class(int c) regmbc('D'); REGMBC(0x10e) REGMBC(0x110) REGMBC(0x1e0a) REGMBC(0x1e0e) REGMBC(0x1e10) return; - case 'E': case '\310': case '\311': case '\312': case '\313': + case 'E': case 0xc8: case 0xc9: case 0xca: case 0xcb: CASEMBC(0x112) CASEMBC(0x114) CASEMBC(0x116) CASEMBC(0x118) CASEMBC(0x11a) CASEMBC(0x1eba) CASEMBC(0x1ebc) - regmbc('E'); regmbc('\310'); regmbc('\311'); - regmbc('\312'); regmbc('\313'); + regmbc('E'); regmbc(0xc8); regmbc(0xc9); + regmbc(0xca); regmbc(0xcb); REGMBC(0x112) REGMBC(0x114) REGMBC(0x116) REGMBC(0x118) REGMBC(0x11a) REGMBC(0x1eba) REGMBC(0x1ebc) @@ -845,11 +846,11 @@ static void reg_equi_class(int c) regmbc('H'); REGMBC(0x124) REGMBC(0x126) REGMBC(0x1e22) REGMBC(0x1e26) REGMBC(0x1e28) return; - case 'I': case '\314': case '\315': case '\316': case '\317': + case 'I': case 0xcc: case 0xcd: case 0xce: case 0xcf: CASEMBC(0x128) CASEMBC(0x12a) CASEMBC(0x12c) CASEMBC(0x12e) CASEMBC(0x130) CASEMBC(0x1cf) CASEMBC(0x1ec8) - regmbc('I'); regmbc('\314'); regmbc('\315'); - regmbc('\316'); regmbc('\317'); + regmbc('I'); regmbc(0xcc); regmbc(0xcd); + regmbc(0xce); regmbc(0xcf); REGMBC(0x128) REGMBC(0x12a) REGMBC(0x12c) REGMBC(0x12e) REGMBC(0x130) REGMBC(0x1cf) REGMBC(0x1ec8) @@ -871,20 +872,20 @@ static void reg_equi_class(int c) case 'M': CASEMBC(0x1e3e) CASEMBC(0x1e40) regmbc('M'); REGMBC(0x1e3e) REGMBC(0x1e40) return; - case 'N': case '\321': + case 'N': case 0xd1: CASEMBC(0x143) CASEMBC(0x145) CASEMBC(0x147) CASEMBC(0x1e44) CASEMBC(0x1e48) - regmbc('N'); regmbc('\321'); + regmbc('N'); regmbc(0xd1); REGMBC(0x143) REGMBC(0x145) REGMBC(0x147) REGMBC(0x1e44) REGMBC(0x1e48) return; - case 'O': case '\322': case '\323': case '\324': case '\325': - case '\326': case '\330': + case 'O': case 0xd2: case 0xd3: case 0xd4: case 0xd5: + case 0xd6: case 0xd8: CASEMBC(0x14c) CASEMBC(0x14e) CASEMBC(0x150) CASEMBC(0x1a0) CASEMBC(0x1d1) CASEMBC(0x1ea) CASEMBC(0x1ec) CASEMBC(0x1ece) - regmbc('O'); regmbc('\322'); regmbc('\323'); - regmbc('\324'); regmbc('\325'); regmbc('\326'); - regmbc('\330'); + regmbc('O'); regmbc(0xd2); regmbc(0xd3); + regmbc(0xd4); regmbc(0xd5); regmbc(0xd6); + regmbc(0xd8); REGMBC(0x14c) REGMBC(0x14e) REGMBC(0x150) REGMBC(0x1a0) REGMBC(0x1d1) REGMBC(0x1ea) REGMBC(0x1ec) REGMBC(0x1ece) @@ -907,12 +908,12 @@ static void reg_equi_class(int c) regmbc('T'); REGMBC(0x162) REGMBC(0x164) REGMBC(0x166) REGMBC(0x1e6a) REGMBC(0x1e6e) return; - case 'U': case '\331': case '\332': case '\333': case '\334': + case 'U': case 0xd9: case 0xda: case 0xdb: case 0xdc: CASEMBC(0x168) CASEMBC(0x16a) CASEMBC(0x16c) CASEMBC(0x16e) CASEMBC(0x170) CASEMBC(0x172) CASEMBC(0x1af) CASEMBC(0x1d3) CASEMBC(0x1ee6) - regmbc('U'); regmbc('\331'); regmbc('\332'); - regmbc('\333'); regmbc('\334'); + regmbc('U'); regmbc(0xd9); regmbc(0xda); + regmbc(0xdb); regmbc(0xdc); REGMBC(0x168) REGMBC(0x16a) REGMBC(0x16c) REGMBC(0x16e) REGMBC(0x170) REGMBC(0x172) REGMBC(0x1af) REGMBC(0x1d3) REGMBC(0x1ee6) @@ -928,10 +929,10 @@ static void reg_equi_class(int c) case 'X': CASEMBC(0x1e8a) CASEMBC(0x1e8c) regmbc('X'); REGMBC(0x1e8a) REGMBC(0x1e8c) return; - case 'Y': case '\335': + case 'Y': case 0xdd: CASEMBC(0x176) CASEMBC(0x178) CASEMBC(0x1e8e) CASEMBC(0x1ef2) CASEMBC(0x1ef6) CASEMBC(0x1ef8) - regmbc('Y'); regmbc('\335'); + regmbc('Y'); regmbc(0xdd); REGMBC(0x176) REGMBC(0x178) REGMBC(0x1e8e) REGMBC(0x1ef2) REGMBC(0x1ef6) REGMBC(0x1ef8) return; @@ -941,13 +942,13 @@ static void reg_equi_class(int c) REGMBC(0x17d) REGMBC(0x1b5) REGMBC(0x1e90) REGMBC(0x1e94) return; - case 'a': case '\340': case '\341': case '\342': - case '\343': case '\344': case '\345': + case 'a': case 0xe0: case 0xe1: case 0xe2: + case 0xe3: case 0xe4: case 0xe5: CASEMBC(0x101) CASEMBC(0x103) CASEMBC(0x105) CASEMBC(0x1ce) CASEMBC(0x1df) CASEMBC(0x1e1) CASEMBC(0x1ea3) - regmbc('a'); regmbc('\340'); regmbc('\341'); - regmbc('\342'); regmbc('\343'); regmbc('\344'); - regmbc('\345'); + regmbc('a'); regmbc(0xe0); regmbc(0xe1); + regmbc(0xe2); regmbc(0xe3); regmbc(0xe4); + regmbc(0xe5); REGMBC(0x101) REGMBC(0x103) REGMBC(0x105) REGMBC(0x1ce) REGMBC(0x1df) REGMBC(0x1e1) REGMBC(0x1ea3) @@ -955,9 +956,9 @@ static void reg_equi_class(int c) case 'b': CASEMBC(0x1e03) CASEMBC(0x1e07) regmbc('b'); REGMBC(0x1e03) REGMBC(0x1e07) return; - case 'c': case '\347': + case 'c': case 0xe7: CASEMBC(0x107) CASEMBC(0x109) CASEMBC(0x10b) CASEMBC(0x10d) - regmbc('c'); regmbc('\347'); + regmbc('c'); regmbc(0xe7); REGMBC(0x107) REGMBC(0x109) REGMBC(0x10b) REGMBC(0x10d) return; @@ -966,11 +967,11 @@ static void reg_equi_class(int c) regmbc('d'); REGMBC(0x10f) REGMBC(0x111) REGMBC(0x1e0b) REGMBC(0x1e0f) REGMBC(0x1e11) return; - case 'e': case '\350': case '\351': case '\352': case '\353': + case 'e': case 0xe8: case 0xe9: case 0xea: case 0xeb: CASEMBC(0x113) CASEMBC(0x115) CASEMBC(0x117) CASEMBC(0x119) CASEMBC(0x11b) CASEMBC(0x1ebb) CASEMBC(0x1ebd) - regmbc('e'); regmbc('\350'); regmbc('\351'); - regmbc('\352'); regmbc('\353'); + regmbc('e'); regmbc(0xe8); regmbc(0xe9); + regmbc(0xea); regmbc(0xeb); REGMBC(0x113) REGMBC(0x115) REGMBC(0x117) REGMBC(0x119) REGMBC(0x11b) REGMBC(0x1ebb) REGMBC(0x1ebd) @@ -991,11 +992,11 @@ static void reg_equi_class(int c) REGMBC(0x1e23) REGMBC(0x1e27) REGMBC(0x1e29) REGMBC(0x1e96) return; - case 'i': case '\354': case '\355': case '\356': case '\357': + case 'i': case 0xec: case 0xed: case 0xee: case 0xef: CASEMBC(0x129) CASEMBC(0x12b) CASEMBC(0x12d) CASEMBC(0x12f) CASEMBC(0x1d0) CASEMBC(0x1ec9) - regmbc('i'); regmbc('\354'); regmbc('\355'); - regmbc('\356'); regmbc('\357'); + regmbc('i'); regmbc(0xec); regmbc(0xed); + regmbc(0xee); regmbc(0xef); REGMBC(0x129) REGMBC(0x12b) REGMBC(0x12d) REGMBC(0x12f) REGMBC(0x1d0) REGMBC(0x1ec9) return; @@ -1016,20 +1017,20 @@ static void reg_equi_class(int c) case 'm': CASEMBC(0x1e3f) CASEMBC(0x1e41) regmbc('m'); REGMBC(0x1e3f) REGMBC(0x1e41) return; - case 'n': case '\361': + case 'n': case 0xf1: CASEMBC(0x144) CASEMBC(0x146) CASEMBC(0x148) CASEMBC(0x149) CASEMBC(0x1e45) CASEMBC(0x1e49) - regmbc('n'); regmbc('\361'); + regmbc('n'); regmbc(0xf1); REGMBC(0x144) REGMBC(0x146) REGMBC(0x148) REGMBC(0x149) REGMBC(0x1e45) REGMBC(0x1e49) return; - case 'o': case '\362': case '\363': case '\364': case '\365': - case '\366': case '\370': + case 'o': case 0xf2: case 0xf3: case 0xf4: case 0xf5: + case 0xf6: case 0xf8: CASEMBC(0x14d) CASEMBC(0x14f) CASEMBC(0x151) CASEMBC(0x1a1) CASEMBC(0x1d2) CASEMBC(0x1eb) CASEMBC(0x1ed) CASEMBC(0x1ecf) - regmbc('o'); regmbc('\362'); regmbc('\363'); - regmbc('\364'); regmbc('\365'); regmbc('\366'); - regmbc('\370'); + regmbc('o'); regmbc(0xf2); regmbc(0xf3); + regmbc(0xf4); regmbc(0xf5); regmbc(0xf6); + regmbc(0xf8); REGMBC(0x14d) REGMBC(0x14f) REGMBC(0x151) REGMBC(0x1a1) REGMBC(0x1d2) REGMBC(0x1eb) REGMBC(0x1ed) REGMBC(0x1ecf) @@ -1052,12 +1053,12 @@ static void reg_equi_class(int c) regmbc('t'); REGMBC(0x163) REGMBC(0x165) REGMBC(0x167) REGMBC(0x1e6b) REGMBC(0x1e6f) REGMBC(0x1e97) return; - case 'u': case '\371': case '\372': case '\373': case '\374': + case 'u': case 0xf9: case 0xfa: case 0xfb: case 0xfc: CASEMBC(0x169) CASEMBC(0x16b) CASEMBC(0x16d) CASEMBC(0x16f) CASEMBC(0x171) CASEMBC(0x173) CASEMBC(0x1b0) CASEMBC(0x1d4) CASEMBC(0x1ee7) - regmbc('u'); regmbc('\371'); regmbc('\372'); - regmbc('\373'); regmbc('\374'); + regmbc('u'); regmbc(0xf9); regmbc(0xfa); + regmbc(0xfb); regmbc(0xfc); REGMBC(0x169) REGMBC(0x16b) REGMBC(0x16d) REGMBC(0x16f) REGMBC(0x171) REGMBC(0x173) REGMBC(0x1b0) REGMBC(0x1d4) REGMBC(0x1ee7) @@ -1074,10 +1075,10 @@ static void reg_equi_class(int c) case 'x': CASEMBC(0x1e8b) CASEMBC(0x1e8d) regmbc('x'); REGMBC(0x1e8b) REGMBC(0x1e8d) return; - case 'y': case '\375': case '\377': + case 'y': case 0xfd: case 0xff: CASEMBC(0x177) CASEMBC(0x1e8f) CASEMBC(0x1e99) CASEMBC(0x1ef3) CASEMBC(0x1ef7) CASEMBC(0x1ef9) - regmbc('y'); regmbc('\375'); regmbc('\377'); + regmbc('y'); regmbc(0xfd); regmbc(0xff); REGMBC(0x177) REGMBC(0x1e8f) REGMBC(0x1e99) REGMBC(0x1ef3) REGMBC(0x1ef7) REGMBC(0x1ef9) return; @@ -4186,7 +4187,7 @@ regmatch ( /* When only a composing char is given match at any * position where that composing char appears. */ status = RA_NOMATCH; - for (i = 0; reginput[i] != NUL; i += utf_char2len(inpc)) { + for (i = 0; reginput[i] != NUL; i += utf_ptr2len(reginput + i)) { inpc = mb_ptr2char(reginput + i); if (!utf_iscomposing(inpc)) { if (i > 0) diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index 1fd024a062..4020fa6e28 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -4762,48 +4762,54 @@ static int skip_to_start(int c, colnr_T *colp) */ static long find_match_text(colnr_T startcol, int regstart, char_u *match_text) { - colnr_T col = startcol; - int c1, c2; - int len1, len2; - int match; +#define PTR2LEN(x) enc_utf8 ? utf_ptr2len(x) : MB_PTR2LEN(x) - for (;; ) { - match = TRUE; - len2 = MB_CHAR2LEN(regstart); /* skip regstart */ - for (len1 = 0; match_text[len1] != NUL; len1 += MB_CHAR2LEN(c1)) { - c1 = PTR2CHAR(match_text + len1); - c2 = PTR2CHAR(regline + col + len2); - if (c1 != c2 && (!ireg_ic || vim_tolower(c1) != vim_tolower(c2))) { - match = FALSE; + colnr_T col = startcol; + int regstart_len = PTR2LEN(regline + startcol); + + for (;;) { + bool match = true; + char_u *s1 = match_text; + char_u *s2 = regline + col + regstart_len; // skip regstart + while (*s1) { + int c1_len = PTR2LEN(s1); + int c1 = PTR2CHAR(s1); + int c2_len = PTR2LEN(s2); + int c2 = PTR2CHAR(s2); + + if ((c1 != c2 && (!ireg_ic || vim_tolower(c1) != vim_tolower(c2))) || + c1_len != c2_len) { + match = false; break; } - len2 += MB_CHAR2LEN(c2); + s1 += c1_len; + s2 += c2_len; } if (match - /* check that no composing char follows */ - && !(enc_utf8 - && STRLEN(regline) > (size_t)(col + len2) - && utf_iscomposing(PTR2CHAR(regline + col + len2))) - ) { + // check that no composing char follows + && !(enc_utf8 && utf_iscomposing(PTR2CHAR(s2)))) { cleanup_subexpr(); if (REG_MULTI) { reg_startpos[0].lnum = reglnum; reg_startpos[0].col = col; reg_endpos[0].lnum = reglnum; - reg_endpos[0].col = col + len2; + reg_endpos[0].col = s2 - regline; } else { reg_startp[0] = regline + col; - reg_endp[0] = regline + col + len2; + reg_endp[0] = s2; } return 1L; } - /* Try finding regstart after the current match. */ - col += MB_CHAR2LEN(regstart); /* skip regstart */ - if (skip_to_start(regstart, &col) == FAIL) + // Try finding regstart after the current match. + col += regstart_len; // skip regstart + if (skip_to_start(regstart, &col) == FAIL) { break; + } } return 0L; + +#undef PTR2LEN } /* diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 1ae2822a93..43bc2c1f68 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -752,10 +752,11 @@ static void win_update(win_T *wp) lnumt = wp->w_lines[i].wl_lastlnum + 1; if (lnumb == MAXLNUM && wp->w_lines[i].wl_lnum >= mod_bot) { lnumb = wp->w_lines[i].wl_lnum; - /* When there is a fold column it might need updating - * in the next line ("J" just above an open fold). */ - if (wp->w_p_fdc > 0) - ++lnumb; + // When there is a fold column it might need updating + // in the next line ("J" just above an open fold). + if (compute_foldcolumn(wp, 0) > 0) { + lnumb++; + } } } @@ -1567,10 +1568,11 @@ static void win_draw_end(win_T *wp, int c1, int c2, int row, int endrow, hlf_T h { int n = 0; # define FDC_OFF n + int fdc = compute_foldcolumn(wp, 0); if (wp->w_p_rl) { - /* No check for cmdline window: should never be right-left. */ - n = wp->w_p_fdc; + // No check for cmdline window: should never be right-left. + n = fdc; if (n > 0) { /* draw the fold column at the right */ @@ -1610,8 +1612,8 @@ static void win_draw_end(win_T *wp, int c1, int c2, int row, int endrow, hlf_T h wp->w_wincol, wp->w_wincol + n, cmdwin_type, ' ', hl_attr(HLF_AT)); } - if (wp->w_p_fdc > 0) { - int nn = n + wp->w_p_fdc; + if (fdc > 0) { + int nn = n + fdc; /* draw the fold column at the left */ if (nn > wp->w_width) @@ -1654,6 +1656,20 @@ static int advance_color_col(int vcol, int **color_cols) return **color_cols >= 0; } +// Compute the width of the foldcolumn. Based on 'foldcolumn' and how much +// space is available for window "wp", minus "col". +static int compute_foldcolumn(win_T *wp, int col) +{ + int fdc = wp->w_p_fdc; + int wmw = wp == curwin && p_wmw == 0 ? 1 : p_wmw; + int wwidth = wp->w_width; + + if (fdc > wwidth - (col + wmw)) { + fdc = wwidth - (col + wmw); + } + return fdc; +} + /* * Display one folded line. */ @@ -1692,12 +1708,9 @@ static void fold_line(win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T ++col; } - /* - * 2. Add the 'foldcolumn' - */ - fdc = wp->w_p_fdc; - if (fdc > wp->w_width - col) - fdc = wp->w_width - col; + // 2. Add the 'foldcolumn' + // Reduce the width when there is not enough space. + fdc = compute_foldcolumn(wp, col); if (fdc > 0) { fill_foldcolumn(buf, wp, TRUE, lnum); if (wp->w_p_rl) { @@ -2018,37 +2031,42 @@ fill_foldcolumn ( int level; int first_level; int empty; + int fdc = compute_foldcolumn(wp, 0); - /* Init to all spaces. */ - memset(p, ' ', (size_t)wp->w_p_fdc); + // Init to all spaces. + memset(p, ' ', (size_t)fdc); level = win_foldinfo.fi_level; if (level > 0) { - /* If there is only one column put more info in it. */ - empty = (wp->w_p_fdc == 1) ? 0 : 1; + // If there is only one column put more info in it. + empty = (fdc == 1) ? 0 : 1; - /* If the column is too narrow, we start at the lowest level that - * fits and use numbers to indicated the depth. */ - first_level = level - wp->w_p_fdc - closed + 1 + empty; - if (first_level < 1) + // If the column is too narrow, we start at the lowest level that + // fits and use numbers to indicated the depth. + first_level = level - fdc - closed + 1 + empty; + if (first_level < 1) { first_level = 1; + } - for (i = 0; i + empty < wp->w_p_fdc; ++i) { + for (i = 0; i + empty < fdc; i++) { if (win_foldinfo.fi_lnum == lnum - && first_level + i >= win_foldinfo.fi_low_level) + && first_level + i >= win_foldinfo.fi_low_level) { p[i] = '-'; - else if (first_level == 1) + } else if (first_level == 1) { p[i] = '|'; - else if (first_level + i <= 9) + } else if (first_level + i <= 9) { p[i] = '0' + first_level + i; - else + } else { p[i] = '>'; - if (first_level + i == level) + } + if (first_level + i == level) { break; + } } } - if (closed) - p[i >= wp->w_p_fdc ? i - 1 : i] = '+'; + if (closed) { + p[i >= fdc ? i - 1 : i] = '+'; + } } /* @@ -2629,11 +2647,13 @@ win_line ( } if (draw_state == WL_FOLD - 1 && n_extra == 0) { + int fdc = compute_foldcolumn(wp, 0); + draw_state = WL_FOLD; - if (wp->w_p_fdc > 0) { - /* Draw the 'foldcolumn'. */ - fill_foldcolumn(extra, wp, FALSE, lnum); - n_extra = wp->w_p_fdc; + if (fdc > 0) { + // Draw the 'foldcolumn'. + fill_foldcolumn(extra, wp, false, lnum); + n_extra = fdc; p_extra = extra; p_extra[n_extra] = NUL; c_extra = NUL; @@ -3182,7 +3202,8 @@ win_line ( // 'list': change char 160 to lcs_nbsp and space to lcs_space. if (wp->w_p_list - && (((c == 160 || (mb_utf8 && mb_c == 160)) && lcs_nbsp) + && (((c == 160 || (mb_utf8 && (mb_c == 160 || mb_c == 0x202f))) + && lcs_nbsp) || (c == ' ' && lcs_space && ptr - line <= trailcol))) { c = (c == ' ') ? lcs_space : lcs_nbsp; if (area_attr == 0 && search_attr == 0) { @@ -3389,7 +3410,7 @@ win_line ( int i; int saved_nextra = n_extra; - if ((is_concealing || boguscols > 0) && vcol_off > 0) { + if (vcol_off > 0) { // there are characters to conceal tab_len += vcol_off; } @@ -3419,25 +3440,31 @@ win_line ( // n_extra will be increased by FIX_FOX_BOGUSCOLS // macro below, so need to adjust for that here - if ((is_concealing || boguscols > 0) && vcol_off > 0) { + if (vcol_off > 0) { n_extra -= vcol_off; } } - /* Tab alignment should be identical regardless of - * 'conceallevel' value. So tab compensates of all - * previous concealed characters, and thus resets vcol_off - * and boguscols accumulated so far in the line. Note that - * the tab can be longer than 'tabstop' when there - * are concealed characters. */ - FIX_FOR_BOGUSCOLS; - // Make sure that the highlighting for the tab char will be correctly - // set further below (effectively reverts the FIX_FOR_BOGSUCOLS - // macro). - if (old_boguscols > 0 && n_extra > tab_len && wp->w_p_list - && lcs_tab1) { - tab_len += n_extra - tab_len; + + { + int vc_saved = vcol_off; + + // Tab alignment should be identical regardless of + // 'conceallevel' value. So tab compensates of all + // previous concealed characters, and thus resets + // vcol_off and boguscols accumulated so far in the + // line. Note that the tab can be longer than + // 'tabstop' when there are concealed characters. + FIX_FOR_BOGUSCOLS; + + // Make sure, the highlighting for the tab char will be + // correctly set further below (effectively reverts the + // FIX_FOR_BOGSUCOLS macro. + if (n_extra == tab_len + vc_saved && wp->w_p_list && lcs_tab1) { + tab_len += vc_saved; + } } - mb_utf8 = FALSE; /* don't draw as UTF-8 */ + + mb_utf8 = (int)false; // don't draw as UTF-8 if (wp->w_p_list) { c = lcs_tab1; if (wp->w_p_lbr) { @@ -3469,11 +3496,11 @@ win_line ( && !(noinvcur && lnum == wp->w_cursor.lnum && (colnr_T)vcol == wp->w_virtcol))) - && lcs_eol_one >= 0) { - /* Display a '$' after the line or highlight an extra - * character if the line break is included. */ - /* For a diff line the highlighting continues after the - * "$". */ + && lcs_eol_one > 0) { + // Display a '$' after the line or highlight an extra + // character if the line break is included. + // For a diff line the highlighting continues after the + // "$". if (diff_hlf == (hlf_T)0 && line_attr == 0) { /* In virtualedit, visual selections may extend * beyond end of line. */ @@ -3948,20 +3975,24 @@ win_line ( ScreenAttrs[off] = char_attr; if (has_mbyte && (*mb_char2cells)(mb_c) > 1) { - /* Need to fill two screen columns. */ - ++off; - ++col; - if (enc_utf8) - /* UTF-8: Put a 0 in the second screen char. */ + // Need to fill two screen columns. + off++; + col++; + if (enc_utf8) { + // UTF-8: Put a 0 in the second screen char. ScreenLines[off] = 0; - else - /* DBCS: Put second byte in the second screen char. */ + } else { + // DBCS: Put second byte in the second screen char. ScreenLines[off] = mb_c & 0xff; - ++vcol; - /* When "tocol" is halfway through a character, set it to the end of - * the character, otherwise highlighting won't stop. */ - if (tocol == vcol) - ++tocol; + } + if (draw_state > WL_NR && filler_todo <= 0) { + vcol++; + } + // When "tocol" is halfway through a character, set it to the end of + // the character, otherwise highlighting won't stop. + if (tocol == vcol) { + tocol++; + } if (wp->w_p_rl) { /* now it's time to backup one cell */ --off; diff --git a/src/nvim/search.c b/src/nvim/search.c index 18a72524cb..d393ee7d02 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -621,43 +621,39 @@ int searchit( break; } matchcol = endpos.col; - /* for empty match: advance one char */ - if (matchcol == matchpos.col - && ptr[matchcol] != NUL) { - if (has_mbyte) - matchcol += - (*mb_ptr2len)(ptr + matchcol); - else - ++matchcol; - } + // for empty match (matchcol == matchpos.col): advance one char } else { + // Prepare to start after first matched character. matchcol = matchpos.col; - if (ptr[matchcol] != NUL) { - if (has_mbyte) - matchcol += (*mb_ptr2len)(ptr - + matchcol); - else - ++matchcol; - } } - if (matchcol == 0 && (options & SEARCH_START)) + + if (matchcol == matchpos.col && ptr[matchcol] != NUL) { + matchcol += MB_PTR2LEN(ptr + matchcol); + } + + if (matchcol == 0 && (options & SEARCH_START)) { break; - if (STRLEN(ptr) <= (size_t)matchcol || ptr[matchcol] == NUL - || (nmatched = vim_regexec_multi(®match, - win, buf, lnum + matchpos.lnum, - matchcol, - tm - )) == 0) { - match_ok = FALSE; + } + + if (ptr[matchcol] == NUL || + (nmatched = vim_regexec_multi(®match, win, buf, lnum, + matchcol, tm)) == 0) { + match_ok = false; break; } matchpos = regmatch.startpos[0]; endpos = regmatch.endpos[0]; submatch = first_submatch(®match); - /* Need to get the line pointer again, a - * multi-line search may have made it invalid. */ - ptr = ml_get_buf(buf, lnum + matchpos.lnum, FALSE); + // This while-loop only works with matchpos.lnum == 0. + // For bigger values the next line pointer ptr might not be a + // buffer line. + if (matchpos.lnum != 0) { + break; + } + // Need to get the line pointer again, a multi-line search may + // have made it invalid. + ptr = ml_get_buf(buf, lnum, false); } if (!match_ok) continue; diff --git a/src/nvim/shada.c b/src/nvim/shada.c index dcdf2195f8..def2de9b1a 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -6,9 +6,6 @@ #include <inttypes.h> #include <errno.h> #include <fcntl.h> -#ifdef HAVE_UNISTD_H -# include <unistd.h> -#endif #include <assert.h> #include <msgpack.h> diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 420e8e2b70..b2028109be 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -1063,8 +1063,7 @@ static char_u *repl_to = NULL; // // Returns the length of the word in bytes, also when it's OK, so that the // caller can skip over the word. -size_t -spell_check ( +size_t spell_check( win_T *wp, // current window char_u *ptr, hlf_T *attrp, @@ -1082,12 +1081,14 @@ spell_check ( // A word never starts at a space or a control character. Return quickly // then, skipping over the character. - if (*ptr <= ' ') + if (*ptr <= ' ') { return 1; + } // Return here when loading language files failed. - if (GA_EMPTY(&wp->w_s->b_langp)) + if (GA_EMPTY(&wp->w_s->b_langp)) { return 1; + } memset(&mi, 0, sizeof(matchinf_T)); @@ -1095,10 +1096,13 @@ spell_check ( // 0X99FF. But always do check spelling to find "3GPP" and "11 // julifeest". if (*ptr >= '0' && *ptr <= '9') { - if (*ptr == '0' && (ptr[1] == 'x' || ptr[1] == 'X')) + if (*ptr == '0' && (ptr[1] == 'b' || ptr[1] == 'B')) { + mi.mi_end = (char_u*) skipbin((char*) ptr + 2); + } else if (*ptr == '0' && (ptr[1] == 'x' || ptr[1] == 'X')) { mi.mi_end = skiphex(ptr + 2); - else + } else { mi.mi_end = skipdigits(ptr); + } nrlen = (size_t)(mi.mi_end - ptr); } @@ -1113,12 +1117,14 @@ spell_check ( if (capcol != NULL && *capcol == 0 && wp->w_s->b_cap_prog != NULL) { // Check word starting with capital letter. c = PTR2CHAR(ptr); - if (!SPELL_ISUPPER(c)) + if (!SPELL_ISUPPER(c)) { wrongcaplen = (size_t)(mi.mi_fend - ptr); + } } } - if (capcol != NULL) + if (capcol != NULL) { *capcol = -1; + } // We always use the characters up to the next non-word character, // also for bad words. @@ -1131,8 +1137,9 @@ spell_check ( // case-fold the word with one non-word character, so that we can check // for the word end. - if (*mi.mi_fend != NUL) + if (*mi.mi_fend != NUL) { mb_ptr_adv(mi.mi_fend); + } (void)spell_casefold(ptr, (int)(mi.mi_fend - ptr), mi.mi_fword, MAXWLEN + 1); mi.mi_fwordlen = (int)STRLEN(mi.mi_fword); @@ -1149,8 +1156,9 @@ spell_check ( // If reloading fails the language is still in the list but everything // has been cleared. - if (mi.mi_lp->lp_slang->sl_fidxs == NULL) + if (mi.mi_lp->lp_slang->sl_fidxs == NULL) { continue; + } // Check for a matching word in case-folded words. find_word(&mi, FIND_FOLDWORD); @@ -1181,18 +1189,18 @@ spell_check ( // If we found a number skip over it. Allows for "42nd". Do flag // rare and local words, e.g., "3GPP". if (nrlen > 0) { - if (mi.mi_result == SP_BAD || mi.mi_result == SP_BANNED) + if (mi.mi_result == SP_BAD || mi.mi_result == SP_BANNED) { return nrlen; - } + } + } else if (!spell_iswordp_nmw(ptr, wp)) { // When we are at a non-word character there is no error, just // skip over the character (try looking for a word after it). - else if (!spell_iswordp_nmw(ptr, wp)) { if (capcol != NULL && wp->w_s->b_cap_prog != NULL) { regmatch_T regmatch; // Check for end of sentence. regmatch.regprog = wp->w_s->b_cap_prog; - regmatch.rm_ic = FALSE; + regmatch.rm_ic = false; int r = vim_regexec(®match, ptr, 0); wp->w_s->b_cap_prog = regmatch.regprog; if (r) { @@ -1204,12 +1212,12 @@ spell_check ( return (size_t)(*mb_ptr2len)(ptr); } return 1; - } else if (mi.mi_end == ptr) + } else if (mi.mi_end == ptr) { // Always include at least one character. Required for when there // is a mixup in "midword". mb_ptr_adv(mi.mi_end); - else if (mi.mi_result == SP_BAD - && LANGP_ENTRY(wp->w_s->b_langp, 0)->lp_slang->sl_nobreak) { + } else if (mi.mi_result == SP_BAD + && LANGP_ENTRY(wp->w_s->b_langp, 0)->lp_slang->sl_nobreak) { char_u *p, *fp; int save_result = mi.mi_result; @@ -1219,11 +1227,12 @@ spell_check ( if (mi.mi_lp->lp_slang->sl_fidxs != NULL) { p = mi.mi_word; fp = mi.mi_fword; - for (;; ) { + for (;;) { mb_ptr_adv(p); mb_ptr_adv(fp); - if (p >= mi.mi_end) + if (p >= mi.mi_end) { break; + } mi.mi_compoff = (int)(fp - mi.mi_fword); find_word(&mi, FIND_COMPOUND); if (mi.mi_result != SP_BAD) { @@ -1235,12 +1244,13 @@ spell_check ( } } - if (mi.mi_result == SP_BAD || mi.mi_result == SP_BANNED) + if (mi.mi_result == SP_BAD || mi.mi_result == SP_BANNED) { *attrp = HLF_SPB; - else if (mi.mi_result == SP_RARE) + } else if (mi.mi_result == SP_RARE) { *attrp = HLF_SPR; - else + } else { *attrp = HLF_SPL; + } } if (wrongcaplen > 0 && (mi.mi_result == SP_OK || mi.mi_result == SP_RARE)) { diff --git a/src/nvim/strings.c b/src/nvim/strings.c index fe91141375..37a0fb82da 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -425,9 +425,13 @@ char_u *vim_strchr(const char_u *string, int c) const char_u *p = string; if (enc_utf8 && c >= 0x80) { while (*p != NUL) { - if (utf_ptr2char(p) == c) + int l = (*mb_ptr2len)(p); + + // Avoid matching an illegal byte here. + if (l > 1 && utf_ptr2char(p) == c) { return (char_u *) p; - p += (*mb_ptr2len)(p); + } + p += l; } return NULL; } diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index b4292dbd4b..41ce2daa91 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -7,14 +7,14 @@ export SHELL := sh VIMPROG := ../../../build/bin/nvim SCRIPTSOURCE := ../../../runtime -SCRIPTS := test_eval.out \ +SCRIPTS := \ test8.out test10.out \ test11.out test12.out test13.out test14.out \ test17.out \ test24.out \ test30.out \ test32.out test34.out \ - test36.out test37.out test39.out test40.out \ + test36.out test37.out test40.out \ test42.out test45.out \ test47.out test48.out test49.out \ test52.out test53.out test55.out \ @@ -22,14 +22,12 @@ SCRIPTS := test_eval.out \ test68.out test69.out \ test73.out \ test79.out \ - test83.out \ test88.out \ test_listlbr.out \ test_breakindent.out \ test_charsearch.out \ test_close_count.out \ test_command_count.out \ - test_cdo.out \ NEW_TESTS = @@ -97,6 +95,7 @@ clean: *.rej \ *.orig \ test.log \ + messages \ $(RM_ON_RUN) \ $(RM_ON_START) \ valgrind.* \ @@ -149,7 +148,7 @@ test1.out: .gdbinit test1.in test49.out: test49.vim nolog: - -rm -f test.log + -rm -f test.log messages # New style of tests uses Vim script with assert calls. These are easier @@ -160,9 +159,9 @@ RUN_VIMTEST = VIMRUNTIME=$(SCRIPTSOURCE); export VIMRUNTIME; $(VALGRIND) $(VIMPR newtests: newtestssilent @/bin/sh -c "if test -f messages && grep -q 'FAILED' messages; then \ cat messages && cat test.log; \ - fi" \ + fi" newtestssilent: $(NEW_TESTS) %.res: %.vim .gdbinit - $(RUN_VIMTEST) -u runtest.vim $*.vim + $(RUN_VIMTEST) -u NONE -S runtest.vim $*.vim diff --git a/src/nvim/testdir/runtest.vim b/src/nvim/testdir/runtest.vim index 0dc142eb97..8314a45d0c 100644 --- a/src/nvim/testdir/runtest.vim +++ b/src/nvim/testdir/runtest.vim @@ -21,9 +21,7 @@ " It will be called after each Test_ function. " Without the +eval feature we can't run these tests, bail out. -if 0 - quit! -endif +so small.vim " Check that the screen size is at least 24 x 80 characters. if &lines < 24 || &columns < 80 @@ -38,7 +36,16 @@ endif " Source the test script. First grab the file name, in case the script " navigates away. let testname = expand('%') -source % +let done = 0 +let fail = 0 +let errors = [] +let messages = [] +try + source % +catch + let fail += 1 + call add(errors, 'Caught exception: ' . v:exception . ' @ ' . v:throwpoint) +endtry " Locate Test_ functions and execute them. redir @q @@ -46,14 +53,12 @@ function /^Test_ redir END let tests = split(substitute(@q, 'function \(\k*()\)', '\1', 'g')) -let done = 0 -let fail = 0 -let errors = [] for test in tests if exists("*SetUp") call SetUp() endif + call add(messages, 'Executing ' . test) let done += 1 try exe 'call ' . test @@ -89,9 +94,20 @@ if len(errors) > 0 write endif -echo 'Executed ' . done . (done > 1 ? ' tests': ' test') +let message = 'Executed ' . done . (done > 1 ? ' tests': ' test') +echo message +call add(messages, message) if fail > 0 - echo fail . ' FAILED' + let message = fail . ' FAILED' + echo message + call add(messages, message) endif +" Append messages to "messages" +split messages +call append(line('$'), '') +call append(line('$'), 'From ' . testname . ':') +call append(line('$'), messages) +write + qall! diff --git a/src/nvim/testdir/test39.in b/src/nvim/testdir/test39.in deleted file mode 100644 index ebbcbd6d0d..0000000000 --- a/src/nvim/testdir/test39.in +++ /dev/null @@ -1,106 +0,0 @@ - -Test Visual block mode commands -And test "U" in Visual mode, also on German sharp S. - -STARTTEST -:so small.vim -:so mbyte.vim -/^abcde -:" Test shift-right of a block -jlllljj>wlljlll> -:" Test shift-left of a block -G$hhhhkk< -:" Test block-insert -GklkkkIxyz -:" Test block-replace -Gllllkkklllrq -:" Test block-change -G$khhhhhkkcmno -:$-4,$w! test.out -:" Test block-insert using cursor keys for movement -/^aaaa/ -:exe ":norm! l\<C-V>jjjlllI\<Right>\<Right> \<Esc>" -:/^aa/,/^$/w >> test.out -/xaaa$/ -:exe ":norm! \<C-V>jjjI<>\<Left>p\<Esc>" -:/xaaa$/,/^$/w >> test.out -:" Test for Visual block was created with the last <C-v>$ -/^A23$/ -:exe ":norm! l\<C-V>j$Aab\<Esc>" -:.,/^$/w >> test.out -:" Test for Visual block was created with the middle <C-v>$ (1) -/^B23$/ -:exe ":norm! l\<C-V>j$hAab\<Esc>" -:.,/^$/w >> test.out -:" Test for Visual block was created with the middle <C-v>$ (2) -/^C23$/ -:exe ":norm! l\<C-V>j$hhAab\<Esc>" -:.,/^$/w >> test.out -:" Test for Visual block insert when virtualedit=all and utf-8 encoding -:set ve=all -:/\t\tline -:exe ":norm! 07l\<C-V>jjIx\<Esc>" -:.,/^$/w >> test.out -:" Test for Visual block append when virtualedit=all -:exe ":norm! 012l\<C-v>jjAx\<Esc>" -:set ve= -:.,/^$/w >> test.out -:" gUe must uppercase a whole word, also when ß changes to SS -Gothe youtußeuu endYpk0wgUe -:" gUfx must uppercase until x, inclusive. -O- youßtußexu -0fogUfx -:" VU must uppercase a whole line -YpkVU -:" same, when it's the last line in the buffer -YPGi111VUddP -:" Uppercase two lines -Oblah di -doh dutVkUj -:" Uppercase part of two lines -ddppi333k0i222fyllvjfuUk -:" visual replace using Enter or NL -G3o1234567892k05l2jr
G3o987652k02l2jr
-G3o1234567892k05l2jr -G3o987652k02l2jr -:" -:" Test cursor position. When ve=block and Visual block mode and $gj -:set ve=block -:exe ":norm! 2k\<C-V>$gj\<Esc>" -:let cpos=getpos("'>") -:$put ='col:'.cpos[2].' off:'.cpos[3] -:/^the/,$w >> test.out -:qa! -ENDTEST - - line1 - line2 - line3 - -aaaaaa -bbbbbb -cccccc -dddddd - -xaaa -bbbb -cccc -dddd - -yaaa -¿¿¿ -bbb - -A23 -4567 - -B23 -4567 - -C23 -4567 - -abcdefghijklm -abcdefghijklm -abcdefghijklm -abcdefghijklm -abcdefghijklm diff --git a/src/nvim/testdir/test39.ok b/src/nvim/testdir/test39.ok Binary files differdeleted file mode 100644 index 198e5b14dc..0000000000 --- a/src/nvim/testdir/test39.ok +++ /dev/null diff --git a/src/nvim/testdir/test55.in b/src/nvim/testdir/test55.in index c4e82d429c..7b6f684caa 100644 --- a/src/nvim/testdir/test55.in +++ b/src/nvim/testdir/test55.in @@ -282,6 +282,166 @@ let l = [0, 1, 2, 3] : $put =ps : endfor :endfor +:" +:" Unletting locked variables +:$put ='Unletting:' +:for depth in range(5) +: $put ='depth is ' . depth +: for u in range(3) +: unlet l +: let l = [0, [1, [2, 3]], {4: 5, 6: {7: 8}}] +: exe "lockvar " . depth . " l" +: if u == 1 +: exe "unlockvar l" +: elseif u == 2 +: exe "unlockvar " . depth . " l" +: endif +: let ps = islocked("l").islocked("l[1]").islocked("l[1][1]").islocked("l[1][1][0]").'-'.islocked("l[2]").islocked("l[2]['6']").islocked("l[2]['6'][7]") +: $put =ps +: let ps = '' +: try +: unlet l[2]['6'][7] +: let ps .= 'p' +: catch +: let ps .= 'F' +: endtry +: try +: unlet l[2][6] +: let ps .= 'p' +: catch +: let ps .= 'F' +: endtry +: try +: unlet l[2] +: let ps .= 'p' +: catch +: let ps .= 'F' +: endtry +: try +: unlet l[1][1][0] +: let ps .= 'p' +: catch +: let ps .= 'F' +: endtry +: try +: unlet l[1][1] +: let ps .= 'p' +: catch +: let ps .= 'F' +: endtry +: try +: unlet l[1] +: let ps .= 'p' +: catch +: let ps .= 'F' +: endtry +: try +: unlet l +: let ps .= 'p' +: catch +: let ps .= 'F' +: endtry +: $put =ps +: endfor +:endfor +:" +:" Locked variables and :unlet or list / dict functions +:$put ='Locks and commands or functions:' +:" +:$put ='No :unlet after lock on dict:' +:unlet! d +:let d = {'a': 99, 'b': 100} +:lockvar 1 d +:try +: unlet d.a +: $put ='did :unlet' +:catch +: $put =v:exception[:16] +:endtry +:$put =string(d) +:" +:$put =':unlet after lock on dict item:' +:unlet! d +:let d = {'a': 99, 'b': 100} +:lockvar d.a +:try +: unlet d.a +: $put ='did :unlet' +:catch +: $put =v:exception[:16] +:endtry +:$put =string(d) +:" +:$put ='filter() after lock on dict item:' +:unlet! d +:let d = {'a': 99, 'b': 100} +:lockvar d.a +:try +: call filter(d, 'v:key != "a"') +: $put ='did filter()' +:catch +: $put =v:exception[:16] +:endtry +:$put =string(d) +:" +:$put ='map() after lock on dict:' +:unlet! d +:let d = {'a': 99, 'b': 100} +:lockvar 1 d +:try +: call map(d, 'v:val + 200') +: $put ='did map()' +:catch +: $put =v:exception[:16] +:endtry +:$put =string(d) +:" +:$put ='No extend() after lock on dict item:' +:unlet! d +:let d = {'a': 99, 'b': 100} +:lockvar d.a +:try +: $put =string(extend(d, {'a': 123})) +: $put ='did extend()' +:catch +: $put =v:exception[:14] +:endtry +:$put =string(d) +:" +:$put ='No remove() of write-protected scope-level variable:' +:fun! Tfunc(this_is_a_loooooooooong_parameter_name) +: try +: $put =string(remove(a:, 'this_is_a_loooooooooong_parameter_name')) +: $put ='did remove()' +: catch +: $put =v:exception[:14] +: endtry +:endfun +:call Tfunc('testval') +:" +:$put ='No extend() of write-protected scope-level variable:' +:fun! Tfunc(this_is_a_loooooooooong_parameter_name) +: try +: $put =string(extend(a:, {'this_is_a_loooooooooong_parameter_name': 1234})) +: $put ='did extend()' +: catch +: $put =v:exception[:14] +: endtry +:endfun +:call Tfunc('testval') +:" +:$put ='No :unlet of variable in locked scope:' +:let b:testvar = 123 +:lockvar 1 b: +:try +: unlet b:testvar +: $put ='b:testvar was :unlet: '. (!exists('b:testvar')) +:catch +: $put =v:exception[:16] +:endtry +:unlockvar 1 b: +:unlet! b:testvar +:" :unlet l :let l = [1, 2, 3, 4] :lockvar! l diff --git a/src/nvim/testdir/test55.ok b/src/nvim/testdir/test55.ok index ba029b2898..4e0303c26e 100644 --- a/src/nvim/testdir/test55.ok +++ b/src/nvim/testdir/test55.ok @@ -86,6 +86,64 @@ FFFFFFF FFpFFpp 0000-000 ppppppp +Unletting: +depth is 0 +0000-000 +ppppppp +0000-000 +ppppppp +0000-000 +ppppppp +depth is 1 +1000-000 +ppFppFp +0000-000 +ppppppp +0000-000 +ppppppp +depth is 2 +1100-100 +pFFpFFp +0000-000 +ppppppp +0000-000 +ppppppp +depth is 3 +1110-110 +FFFFFFp +0010-010 +FppFppp +0000-000 +ppppppp +depth is 4 +1111-111 +FFFFFFp +0011-011 +FppFppp +0000-000 +ppppppp +Locks and commands or functions: +No :unlet after lock on dict: +Vim(unlet):E741: +{'a': 99, 'b': 100} +:unlet after lock on dict item: +did :unlet +{'b': 100} +filter() after lock on dict item: +did filter() +{'b': 100} +map() after lock on dict: +did map() +{'a': 299, 'b': 300} +No extend() after lock on dict item: +Vim(put):E741: +{'a': 99, 'b': 100} +No remove() of write-protected scope-level variable: +Vim(put):E795: +No extend() of write-protected scope-level variable: +Vim(put):E742: +No :unlet of variable in locked scope: +Vim(unlet):E741: [1, 2, 3, 4] [1, 2, 3, 4] [1, 2, 3, 4] diff --git a/src/nvim/testdir/test83-tags2 b/src/nvim/testdir/test83-tags2 deleted file mode 100644 index 7f9f21b0eb..0000000000 --- a/src/nvim/testdir/test83-tags2 +++ /dev/null @@ -1,2 +0,0 @@ -!_TAG_FILE_ENCODING cp932 // -`ab Xtags2.txt /`ab diff --git a/src/nvim/testdir/test83-tags3 b/src/nvim/testdir/test83-tags3 deleted file mode 100644 index 0cb6591562..0000000000 --- a/src/nvim/testdir/test83-tags3 +++ /dev/null @@ -1,102 +0,0 @@ -!_TAG_FILE_SORTED 1 // -!_TAG_FILE_ENCODING cp932 // -abc1 Xtags3.txt /`ab -abc2 Xtags3.txt /`ab -abc3 Xtags3.txt /`ab -abc4 Xtags3.txt /`ab -abc5 Xtags3.txt /`ab -abc6 Xtags3.txt /`ab -abc7 Xtags3.txt /`ab -abc8 Xtags3.txt /`ab -abc9 Xtags3.txt /`ab -abc10 Xtags3.txt /`ab -abc11 Xtags3.txt /`ab -abc12 Xtags3.txt /`ab -abc13 Xtags3.txt /`ab -abc14 Xtags3.txt /`ab -abc15 Xtags3.txt /`ab -abc16 Xtags3.txt /`ab -abc17 Xtags3.txt /`ab -abc18 Xtags3.txt /`ab -abc19 Xtags3.txt /`ab -abc20 Xtags3.txt /`ab -abc21 Xtags3.txt /`ab -abc22 Xtags3.txt /`ab -abc23 Xtags3.txt /`ab -abc24 Xtags3.txt /`ab -abc25 Xtags3.txt /`ab -abc26 Xtags3.txt /`ab -abc27 Xtags3.txt /`ab -abc28 Xtags3.txt /`ab -abc29 Xtags3.txt /`ab -abc30 Xtags3.txt /`ab -abc31 Xtags3.txt /`ab -abc32 Xtags3.txt /`ab -abc33 Xtags3.txt /`ab -abc34 Xtags3.txt /`ab -abc35 Xtags3.txt /`ab -abc36 Xtags3.txt /`ab -abc37 Xtags3.txt /`ab -abc38 Xtags3.txt /`ab -abc39 Xtags3.txt /`ab -abc40 Xtags3.txt /`ab -abc41 Xtags3.txt /`ab -abc42 Xtags3.txt /`ab -abc43 Xtags3.txt /`ab -abc44 Xtags3.txt /`ab -abc45 Xtags3.txt /`ab -abc46 Xtags3.txt /`ab -abc47 Xtags3.txt /`ab -abc48 Xtags3.txt /`ab -abc49 Xtags3.txt /`ab -abc50 Xtags3.txt /`ab -abc51 Xtags3.txt /`ab -abc52 Xtags3.txt /`ab -abc53 Xtags3.txt /`ab -abc54 Xtags3.txt /`ab -abc55 Xtags3.txt /`ab -abc56 Xtags3.txt /`ab -abc57 Xtags3.txt /`ab -abc58 Xtags3.txt /`ab -abc59 Xtags3.txt /`ab -abc60 Xtags3.txt /`ab -abc61 Xtags3.txt /`ab -abc62 Xtags3.txt /`ab -abc63 Xtags3.txt /`ab -abc64 Xtags3.txt /`ab -abc65 Xtags3.txt /`ab -abc66 Xtags3.txt /`ab -abc67 Xtags3.txt /`ab -abc68 Xtags3.txt /`ab -abc69 Xtags3.txt /`ab -abc70 Xtags3.txt /`ab -abc71 Xtags3.txt /`ab -abc72 Xtags3.txt /`ab -abc73 Xtags3.txt /`ab -abc74 Xtags3.txt /`ab -abc75 Xtags3.txt /`ab -abc76 Xtags3.txt /`ab -abc77 Xtags3.txt /`ab -abc78 Xtags3.txt /`ab -abc79 Xtags3.txt /`ab -abc80 Xtags3.txt /`ab -abc81 Xtags3.txt /`ab -abc82 Xtags3.txt /`ab -abc83 Xtags3.txt /`ab -abc84 Xtags3.txt /`ab -abc85 Xtags3.txt /`ab -abc86 Xtags3.txt /`ab -abc87 Xtags3.txt /`ab -abc88 Xtags3.txt /`ab -abc89 Xtags3.txt /`ab -abc90 Xtags3.txt /`ab -abc91 Xtags3.txt /`ab -abc92 Xtags3.txt /`ab -abc93 Xtags3.txt /`ab -abc94 Xtags3.txt /`ab -abc95 Xtags3.txt /`ab -abc96 Xtags3.txt /`ab -abc97 Xtags3.txt /`ab -abc98 Xtags3.txt /`ab -abc99 Xtags3.txt /`ab -abc100 Xtags3.txt /`ab diff --git a/src/nvim/testdir/test83.in b/src/nvim/testdir/test83.in deleted file mode 100644 index d54b1bcddd..0000000000 --- a/src/nvim/testdir/test83.in +++ /dev/null @@ -1,75 +0,0 @@ -Tests for tag search with !_TAG_FILE_ENCODING. - -STARTTEST -:so mbyte.vim -:if !has('iconv') || iconv("\x82\x60", "cp932", "utf-8") != "\uff21" -: e! test.ok -: w! test.out -: qa! -:endif - -:/^text for tags1$/,/^text for tags1$/+1w! Xtags1.txt -:/^text for tags2$/,/^text for tags2$/+1w! Xtags2.txt -:/^text for tags3$/,/^text for tags3$/+1w! Xtags3.txt -:/^tags1$/+1,/^tags1-end$/-1w! Xtags1 - -ggdG - -:call setline('.', 'Results of test83') - -:" case1: -:new -:set tags=Xtags1 -:let v:errmsg = '' -:tag abcdefghijklmnopqrs -:if v:errmsg =~ 'E426:' || getline('.') != 'abcdefghijklmnopqrs' -: close -: put ='case1: failed' -:else -: close -: put ='case1: ok' -:endif - -:" case2: -:new -:set tags=test83-tags2 -:let v:errmsg = '' -:tag /.BC -:if v:errmsg =~ 'E426:' || getline('.') != 'ABC' -: close -: put ='case2: failed' -:else -: close -: put ='case2: ok' -:endif - -:" case3: -:new -:set tags=test83-tags3 -:let v:errmsg = '' -:tag abc50 -:if v:errmsg =~ 'E426:' || getline('.') != 'ABC' -: close -: put ='case3: failed' -:else -: close -: put ='case3: ok' -:endif -:close - -:wq! test.out -ENDTEST - -text for tags1 -abcdefghijklmnopqrs - -text for tags2 -ABC - -text for tags3 -ABC - -tags1 -!_TAG_FILE_ENCODING utf-8 // -abcdefghijklmnopqrs Xtags1.txt /abcdefghijklmnopqrs -tags1-end diff --git a/src/nvim/testdir/test83.ok b/src/nvim/testdir/test83.ok deleted file mode 100644 index 61a1a04a18..0000000000 --- a/src/nvim/testdir/test83.ok +++ /dev/null @@ -1,4 +0,0 @@ -Results of test83 -case1: ok -case2: ok -case3: ok diff --git a/src/nvim/testdir/test88.in b/src/nvim/testdir/test88.in index c2e6a752fa..9e43f703e9 100644 --- a/src/nvim/testdir/test88.in +++ b/src/nvim/testdir/test88.in @@ -71,6 +71,17 @@ 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) diff --git a/src/nvim/testdir/test88.ok b/src/nvim/testdir/test88.ok index e29698b7bd..12949f274a 100644 --- a/src/nvim/testdir/test88.ok +++ b/src/nvim/testdir/test88.ok @@ -22,3 +22,8 @@ end: 9:25 9:26 9:26 +9:1 +9:9 +9:17 +9:25 +9:26 diff --git a/src/nvim/testdir/test_cdo.in b/src/nvim/testdir/test_cdo.in deleted file mode 100644 index fb80ea1164..0000000000 --- a/src/nvim/testdir/test_cdo.in +++ /dev/null @@ -1,107 +0,0 @@ -Tests for the :cdo, :cfdo, :ldo and :lfdo commands - -STARTTEST -:so small.vim -:if !has('quickfix') | e! test.ok | wq! test.out | endif - -:call writefile(["Line1", "Line2", "Line3"], 'Xtestfile1') -:call writefile(["Line1", "Line2", "Line3"], 'Xtestfile2') -:call writefile(["Line1", "Line2", "Line3"], 'Xtestfile3') - -:function RunTests(cchar) -: let nl="\n" - -: enew -: " Try with an empty list -: exe a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" - -: " Populate the list and then try -: exe a:cchar . "getexpr ['non-error 1', 'Xtestfile1:1:3:Line1', 'non-error 2', 'Xtestfile2:2:2:Line2', 'non-error 3', 'Xtestfile3:3:1:Line3']" -: exe a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" - -: " Run command only on selected error lines -: enew -: exe "2,3" . a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" -: " Boundary condition tests -: enew -: exe "1,1" . a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" -: enew -: exe "3" . a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" -: " Range test commands -: enew -: exe "%" . a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" -: enew -: exe "1,$" . a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" -: enew -: exe a:cchar . 'prev' -: exe "." . a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" -: " Invalid error lines test -: enew -: exe "27" . a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" -: exe "4,5" . a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" - -: " Run commands from an unsaved buffer -: let v:errmsg='' -: enew -: setlocal modified -: exe "2,2" . a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" -: if v:errmsg =~# 'No write since last change' -: let g:result .= 'Unsaved file change test passed' . nl -: else -: let g:result .= 'Unsaved file change test failed' . nl -: endif - -: " If the executed command fails, then the operation should be aborted -: enew! -: let subst_count = 0 -: exe a:cchar . "do s/Line/xLine/ | let subst_count += 1" -: if subst_count == 1 && getline('.') == 'xLine1' -: let g:result .= 'Abort command on error test passed' . nl -: else -: let g:result .= 'Abort command on error test failed' . nl -: endif - -: exe "2,2" . a:cchar . "do! let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" - -: " List with no valid error entries -: edit! +2 Xtestfile1 -: exe a:cchar . "getexpr ['non-error 1', 'non-error 2', 'non-error 3']" -: exe a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" -: exe "2" . a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" -: let v:errmsg='' -: exe "%" . a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" -: exe "1,$" . a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" -: exe "." . a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" -: let g:result .= v:errmsg - -: " List with only one valid entry -: exe a:cchar . "getexpr ['Xtestfile3:3:1:Line3']" -: exe a:cchar . "do let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" - -: " Tests for :cfdo and :lfdo commands -: exe a:cchar . "getexpr ['non-error 1', 'Xtestfile1:1:3:Line1', 'Xtestfile1:2:1:Line2', 'non-error 2', 'Xtestfile2:2:2:Line2', 'non-error 3', 'Xtestfile3:2:3:Line2', 'Xtestfile3:3:1:Line3']" -: exe a:cchar . "fdo let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" -: exe "3" . a:cchar . "fdo let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" -: exe "2,3" . a:cchar . "fdo let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" -: exe "%" . a:cchar . "fdo let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" -: exe "1,$" . a:cchar . "fdo let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" -: exe a:cchar . 'pfile' -: exe "." . a:cchar . "fdo let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" - -: " List with only one valid entry -: exe a:cchar . "getexpr ['Xtestfile2:2:5:Line2']" -: exe a:cchar . "fdo let g:result .= expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' . nl" -:endfunction - -:let result='' -:" Tests for the :cdo quickfix list command -:call RunTests('c') -:let result .= "\n" -:" Tests for the :ldo location list command -:call RunTests('l') - -:edit! test.out -:0put =result -:wq! -ENDTEST - diff --git a/src/nvim/testdir/test_cdo.ok b/src/nvim/testdir/test_cdo.ok deleted file mode 100644 index ddcff4bbb8..0000000000 --- a/src/nvim/testdir/test_cdo.ok +++ /dev/null @@ -1,66 +0,0 @@ -Xtestfile1 1L 3C -Xtestfile2 2L 2C -Xtestfile3 3L 1C -Xtestfile2 2L 2C -Xtestfile3 3L 1C -Xtestfile1 1L 3C -Xtestfile3 3L 1C -Xtestfile1 1L 3C -Xtestfile2 2L 2C -Xtestfile3 3L 1C -Xtestfile1 1L 3C -Xtestfile2 2L 2C -Xtestfile3 3L 1C -Xtestfile2 2L 2C -Unsaved file change test passed -Abort command on error test passed -Xtestfile2 2L 2C -Xtestfile3 3L 1C -Xtestfile1 1L 3C -Xtestfile2 2L 2C -Xtestfile3 2L 3C -Xtestfile3 2L 3C -Xtestfile2 2L 2C -Xtestfile3 2L 3C -Xtestfile1 1L 3C -Xtestfile2 2L 2C -Xtestfile3 2L 3C -Xtestfile1 1L 3C -Xtestfile2 2L 2C -Xtestfile3 2L 3C -Xtestfile2 2L 2C -Xtestfile2 2L 5C - -Xtestfile1 1L 3C -Xtestfile2 2L 2C -Xtestfile3 3L 1C -Xtestfile2 2L 2C -Xtestfile3 3L 1C -Xtestfile1 1L 3C -Xtestfile3 3L 1C -Xtestfile1 1L 3C -Xtestfile2 2L 2C -Xtestfile3 3L 1C -Xtestfile1 1L 3C -Xtestfile2 2L 2C -Xtestfile3 3L 1C -Xtestfile2 2L 2C -Unsaved file change test passed -Abort command on error test passed -Xtestfile2 2L 2C -Xtestfile3 3L 1C -Xtestfile1 1L 3C -Xtestfile2 2L 2C -Xtestfile3 2L 3C -Xtestfile3 2L 3C -Xtestfile2 2L 2C -Xtestfile3 2L 3C -Xtestfile1 1L 3C -Xtestfile2 2L 2C -Xtestfile3 2L 3C -Xtestfile1 1L 3C -Xtestfile2 2L 2C -Xtestfile3 2L 3C -Xtestfile2 2L 2C -Xtestfile2 2L 5C - diff --git a/src/nvim/testdir/test_eval.in b/src/nvim/testdir/test_eval.in deleted file mode 100644 index 54cdb03ba2..0000000000 --- a/src/nvim/testdir/test_eval.in +++ /dev/null @@ -1,234 +0,0 @@ -Test for various eval features. vim: set ft=vim : - -Note: system clipboard is saved, changed and restored. - -clipboard contents -something else - -STARTTEST -:so small.vim -:set noswapfile -:lang C -:fun AppendRegContents(reg) - call AppendRegParts(a:reg, getregtype(a:reg), getreg(a:reg), string(getreg(a:reg, 0, 1)), getreg(a:reg, 1), string(getreg(a:reg, 1, 1))) -:endfun -:fun AppendRegParts(reg, type, cont, strcont, cont1, strcont1) - call append('$', printf('%s: type %s; value: %s (%s), expr: %s (%s)', a:reg, a:type, a:cont, a:strcont, a:cont1, a:strcont1)) -endfun -:command -nargs=? AR :call AppendRegContents(<q-args>) -:fun SetReg(...) - call call('setreg', a:000) - call append('$', printf('{{{2 setreg(%s)', string(a:000)[1:-2])) - call AppendRegContents(a:1) - if a:1 isnot# '=' - execute "silent normal! Go==\n==\e\"".a:1."P" - endif -endfun -:fun ErrExe(str) - call append('$', 'Executing '.a:str) - try - execute a:str - catch - $put =v:exception - endtry -endfun -:fun Test() -$put ='{{{1 let tests' -let @" = 'abc' -AR " -let @" = "abc\n" -AR " -let @" = "abc\<C-m>" -AR " -let @= = '"abc"' -AR = - -$put ='{{{1 Basic setreg tests' -call SetReg('a', 'abcA', 'c') -call SetReg('b', 'abcB', 'v') -call SetReg('c', 'abcC', 'l') -call SetReg('d', 'abcD', 'V') -call SetReg('e', 'abcE', 'b') -call SetReg('f', 'abcF', "\<C-v>") -call SetReg('g', 'abcG', 'b10') -call SetReg('h', 'abcH', "\<C-v>10") -call SetReg('I', 'abcI') - -$put ='{{{1 Appending single lines with setreg()' -call SetReg('A', 'abcAc', 'c') -call SetReg('A', 'abcAl', 'l') -call SetReg('A', 'abcAc2','c') -call SetReg('b', 'abcBc', 'ca') -call SetReg('b', 'abcBb', 'ba') -call SetReg('b', 'abcBc2','ca') -call SetReg('b', 'abcBb2','b50a') - -call SetReg('C', 'abcCl', 'l') -call SetReg('C', 'abcCc', 'c') -call SetReg('D', 'abcDb', 'b') - -call SetReg('E', 'abcEb', 'b') -call SetReg('E', 'abcEl', 'l') -call SetReg('F', 'abcFc', 'c') - -$put ='{{{1 Appending NL with setreg()' -call setreg('a', 'abcA2', 'c') -call setreg('b', 'abcB2', 'v') -call setreg('c', 'abcC2', 'l') -call setreg('d', 'abcD2', 'V') -call setreg('e', 'abcE2', 'b') -call setreg('f', 'abcF2', "\<C-v>") -call setreg('g', 'abcG2', 'b10') -call setreg('h', 'abcH2', "\<C-v>10") -call setreg('I', 'abcI2') - -call SetReg('A', "\n") -call SetReg('B', "\n", 'c') -call SetReg('C', "\n") -call SetReg('D', "\n", 'l') -call SetReg('E', "\n") -call SetReg('F', "\n", 'b') - -$put ='{{{1 Setting lists with setreg()' -call SetReg('a', ['abcA3'], 'c') -call SetReg('b', ['abcB3'], 'l') -call SetReg('c', ['abcC3'], 'b') -call SetReg('d', ['abcD3']) -call SetReg('e', [1, 2, 'abc', 3]) -call SetReg('f', [1, 2, 3]) - -$put ='{{{1 Appending lists with setreg()' -call SetReg('A', ['abcA3c'], 'c') -call SetReg('b', ['abcB3l'], 'la') -call SetReg('C', ['abcC3b'], 'lb') -call SetReg('D', ['abcD32']) - -call SetReg('A', ['abcA32']) -call SetReg('B', ['abcB3c'], 'c') -call SetReg('C', ['abcC3l'], 'l') -call SetReg('D', ['abcD3b'], 'b') - -$put ='{{{1 Appending lists with NL with setreg()' -call SetReg('A', ["\n", 'abcA3l2'], 'l') -call SetReg('B', ["\n", 'abcB3c2'], 'c') -call SetReg('C', ["\n", 'abcC3b2'], 'b') -call SetReg('D', ["\n", 'abcD3b50'],'b50') - -$put ='{{{1 Setting lists with NLs with setreg()' -call SetReg('a', ['abcA4-0', "\n", "abcA4-2\n", "\nabcA4-3", "abcA4-4\nabcA4-4-2"]) -call SetReg('b', ['abcB4c-0', "\n", "abcB4c-2\n", "\nabcB4c-3", "abcB4c-4\nabcB4c-4-2"], 'c') -call SetReg('c', ['abcC4l-0', "\n", "abcC4l-2\n", "\nabcC4l-3", "abcC4l-4\nabcC4l-4-2"], 'l') -call SetReg('d', ['abcD4b-0', "\n", "abcD4b-2\n", "\nabcD4b-3", "abcD4b-4\nabcD4b-4-2"], 'b') -call SetReg('e', ['abcE4b10-0', "\n", "abcE4b10-2\n", "\nabcE4b10-3", "abcE4b10-4\nabcE4b10-4-2"], 'b10') - -$put ='{{{1 Search and expressions' -call SetReg('/', ['abc/']) -call SetReg('/', ["abc/\n"]) -call SetReg('=', ['"abc/"']) -call SetReg('=', ["\"abc/\n\""]) -$put ='{{{1 System clipboard' -if has('clipboard') -" Save and restore system clipboard. -" If no connection to X-Server is possible, test should succeed. -let _clipreg = ['*', getreg('*'), getregtype('*')] -let _clipopt = &cb -let &cb='unnamed' -5y -AR * -tabdo :windo :echo "hi" -6y -AR * -let &cb=_clipopt -call call('setreg', _clipreg) -else - call AppendRegParts('*', 'V', "clipboard contents\n", "['clipboard contents']", "clipboard contents\n", "['clipboard contents']") - call AppendRegParts('*', 'V', "something else\n", "['something else']", "something else\n", "['something else']") -endif -$put ='{{{1 Errors' -call ErrExe('call setreg()') -call ErrExe('call setreg(1)') -call ErrExe('call setreg(1, 2, 3, 4)') -call ErrExe('call setreg([], 2)') -call ErrExe('call setreg(1, {})') -call ErrExe('call setreg(1, 2, [])') -call ErrExe('call setreg("/", ["1", "2"])') -call ErrExe('call setreg("=", ["1", "2"])') -call ErrExe('call setreg(1, ["", "", [], ""])') -endfun -:" -:call Test() -:" -:delfunction SetReg -:delfunction AppendRegContents -:delfunction ErrExe -:delfunction Test -:delcommand AR -:call garbagecollect(1) -:" -:/^start:/+1,$wq! test.out -:" vim: et ts=4 isk-=\: fmr=???,??? -:call getchar() -:e test.out -:%d - -:" function name not starting with a capital -:try -: func! g:test() -: echo "test" -: endfunc -:catch -: $put =v:exception -:endtry - -:" function name folowed by # -:try -: func! test2() "# -: echo "test2" -: endfunc -:catch -: $put =v:exception -:endtry - -:" function name includes a colon -:try -: func! b:test() -: echo "test" -: endfunc -:catch -: $put =v:exception -:endtry - -:" function name starting with/without "g:", buffer-local funcref. -:function! g:Foo(n) -: $put ='called Foo(' . a:n . ')' -:endfunction -:let b:my_func = function('Foo') -:call b:my_func(1) -:echo g:Foo(2) -:echo Foo(3) - -:" script-local function used in Funcref must exist. -:so test_eval_func.vim - -:" using $ instead of '$' must give an error -:try -: call append($, 'foobar') -:catch -: $put =v:exception -:endtry - -:$put ='{{{1 getcurpos/setpos' -/^012345678 -6l:let sp = getcurpos() -0:call setpos('.', sp) -jyl:$put - -:/^start:/+1,$wq! test.out -:" vim: et ts=4 isk-=\: fmr=???,??? -:call getchar() -ENDTEST - -012345678 -012345678 - -start: diff --git a/src/nvim/testdir/test_eval.ok b/src/nvim/testdir/test_eval.ok Binary files differdeleted file mode 100644 index cf7a5cd418..0000000000 --- a/src/nvim/testdir/test_eval.ok +++ /dev/null diff --git a/src/nvim/testdir/test_eval_func.vim b/src/nvim/testdir/test_eval_func.vim deleted file mode 100644 index 48d01df27d..0000000000 --- a/src/nvim/testdir/test_eval_func.vim +++ /dev/null @@ -1,12 +0,0 @@ -" Vim script used in test_eval.in. Needed for script-local function. - -func! s:Testje() - return "foo" -endfunc - -let Bar = function('s:Testje') - -$put ='s:Testje exists: ' . exists('s:Testje') -$put ='func s:Testje exists: ' . exists('*s:Testje') -$put ='Bar exists: ' . exists('Bar') -$put ='func Bar exists: ' . exists('*Bar') diff --git a/src/nvim/testdir/test_listlbr.in b/src/nvim/testdir/test_listlbr.in index 36235ea915..57202b46eb 100644 --- a/src/nvim/testdir/test_listlbr.in +++ b/src/nvim/testdir/test_listlbr.in @@ -60,11 +60,21 @@ STARTTEST :set cpo&vim linebreak :let g:test ="Test 6: set linebreak with visual block mode" :let line="REMOVE: this not" +:$put =g:test :$put =line :let line="REMOVE: aaaaaaaaaaaaa" :$put =line :1/^REMOVE: 0jf x:$put +:set cpo&vim linebreak +:let g:test ="Test 7: set linebreak with visual block mode and v_b_A" +:$put =g:test +Golong line: 40afoobar aTARGET at end +:exe "norm! $3B\<C-v>eAx\<Esc>" +:set cpo&vim linebreak sbr= +:let g:test ="Test 8: set linebreak with visual char mode and changing block" +:$put =g:test +Go1111-1111-1111-11-1111-1111-11110f-lv3lc2222bgj. :%w! test.out :qa! ENDTEST diff --git a/src/nvim/testdir/test_listlbr.ok b/src/nvim/testdir/test_listlbr.ok index ee74667661..82881234c4 100644 --- a/src/nvim/testdir/test_listlbr.ok +++ b/src/nvim/testdir/test_listlbr.ok @@ -32,7 +32,12 @@ Sabbbbbb bla ~ ~ ~ +Test 6: set linebreak with visual block mode this not aaaaaaaaaaaaa REMOVE: REMOVE: +Test 7: set linebreak with visual block mode and v_b_A +long line: foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar TARGETx at end +Test 8: set linebreak with visual char mode and changing block +1111-2222-1111-11-1111-2222-1111 diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index 7f7d138358..00e2821075 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -845,7 +845,7 @@ static void fix_terminfo(TUIData *data) if ((term_prog && !strcmp(term_prog, "Konsole")) || os_getenv("KONSOLE_DBUS_SESSION") != NULL) { // Konsole uses a proprietary escape code to set the cursor shape - // and does not suppport DECSCUSR. + // and does not support DECSCUSR. data->unibi_ext.enter_insert_mode = (int)unibi_add_ext_str(ut, NULL, TMUX_WRAP("\x1b]50;CursorShape=1;BlinkingCursorEnabled=1\x07")); data->unibi_ext.enter_replace_mode = (int)unibi_add_ext_str(ut, NULL, @@ -854,13 +854,15 @@ static void fix_terminfo(TUIData *data) TMUX_WRAP("\x1b]50;CursorShape=0;BlinkingCursorEnabled=0\x07")); } else if (!vte_version || atoi(vte_version) >= 3900) { // Assume that the terminal supports DECSCUSR unless it is an - // old VTE based terminal + // old VTE based terminal. This should not get wrapped for tmux, + // which will handle it via its Ss/Se terminfo extension - usually + // according to its terminal-overrides. data->unibi_ext.enter_insert_mode = (int)unibi_add_ext_str(ut, NULL, - TMUX_WRAP("\x1b[5 q")); + "\x1b[5 q"); data->unibi_ext.enter_replace_mode = (int)unibi_add_ext_str(ut, NULL, - TMUX_WRAP("\x1b[3 q")); + "\x1b[3 q"); data->unibi_ext.exit_insert_mode = (int)unibi_add_ext_str(ut, NULL, - TMUX_WRAP("\x1b[2 q")); + "\x1b[2 q"); } end: diff --git a/src/nvim/version.c b/src/nvim/version.c index 1d98afaaa1..30f104562f 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -69,6 +69,16 @@ static char *features[] = { // clang-format off static int included_patches[] = { + 1137, + + + + 1081, + + + + + 1055, // 1054, // 1053, @@ -133,7 +143,7 @@ static int included_patches[] = { // 994 NA // 993, // 992 NA - // 991, + 991, // 990 NA 989, // 988 NA @@ -143,10 +153,10 @@ static int included_patches[] = { // 984, // 983, // 982 NA - // 981, - // 980, + 981, + 980, // 979 NA - // 978, + 978, // 977, // 976 NA 975, @@ -161,7 +171,7 @@ static int included_patches[] = { // 966 NA // 965 NA // 964 NA - // 963, + 963, // 962 NA // 961, // 960 NA @@ -175,7 +185,7 @@ static int included_patches[] = { // 952, // 951, 950, - // 949, + 949, // 948 NA // 947, 946, @@ -371,7 +381,7 @@ static int included_patches[] = { // 756 NA // 755, // 754, - // 753, + 753, // 752, // 751 NA // 750 NA @@ -385,7 +395,7 @@ static int included_patches[] = { // 742, // 741, // 740, - // 739, + 739, // 738 NA // 737, 736, @@ -395,18 +405,18 @@ static int included_patches[] = { // 732, // 731 NA // 730 NA - // 729, + 729, // 728 NA // 727 NA // 726 NA // 725, // 724 NA 723, - // 722, + 722, 721, // 720 NA 719, - // 718, + 718, // 717, 716, 715, @@ -420,13 +430,13 @@ static int included_patches[] = { 707, 706, // 705 NA - // 704, + 704, // 703 NA 702, // 701 NA // 700, 699, - // 698, + 698, // 697, 696, 695, @@ -439,12 +449,12 @@ static int included_patches[] = { // 688, // 687 NA 686, - // 685, + 685, // 684, // 683 NA 682, // 681 NA - // 680, + 680, // 679 NA // 678 NA // 677 NA @@ -468,9 +478,9 @@ static int included_patches[] = { 659, 658, // 657 NA - // 656, + 656, 655, - // 654, + 654, 653, // 652 NA 651, @@ -482,10 +492,10 @@ static int included_patches[] = { 645, // 644 NA // 643, - // 642, + 642, // 641 NA 640, - // 639, + 639, // 638 NA 637, 636, @@ -508,7 +518,7 @@ static int included_patches[] = { // 619 NA // 618 NA 617, - // 616, + 616, 615, 614, // 613, @@ -521,7 +531,7 @@ static int included_patches[] = { 606, 605, 604, - // 603, + 603, 602, 601, 600, diff --git a/src/nvim/vim.h b/src/nvim/vim.h index 71d7556880..2e20d48f90 100644 --- a/src/nvim/vim.h +++ b/src/nvim/vim.h @@ -35,7 +35,7 @@ Error: configure did not run properly.Check auto/config.log. #include "nvim/os/os_defs.h" /* bring lots of system header files */ -#define NUMBUFLEN 30 /* length of a buffer to store a number in ASCII */ +#define NUMBUFLEN 65 // length of a buffer to store a number in ASCII #define MAX_TYPENR 65535 diff --git a/src/nvim/window.c b/src/nvim/window.c index 16ff7dfb14..191cb04d75 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -1044,19 +1044,21 @@ static void win_init_some(win_T *newp, win_T *oldp) } -/* - * Check if "win" is a pointer to an existing window. - */ -int win_valid(win_T *win) +/// Check if "win" is a pointer to an existing window in the current tabpage. +/// +/// @param win window to check +bool win_valid(win_T *win) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { - if (win == NULL) - return FALSE; + if (win == NULL) { + return false; + } + FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { if (wp == win) { - return TRUE; + return true; } } - return FALSE; + return false; } /* @@ -1732,21 +1734,18 @@ close_windows ( shell_new_rows(); } -/* - * Return TRUE if the current window is the only window that exists (ignoring - * "aucmd_win"). - * Returns FALSE if there is a window, possibly in another tab page. - */ -static int last_window(void) +/// Check that current window is the last one. +/// +/// @return true if the current window is the only window that exists, false if +/// there is another, possibly in another tab page. +static bool last_window(void) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { return one_window() && first_tabpage->tp_next == NULL; } -/* - * Return TRUE if there is only one window other than "aucmd_win" in the - * current tab page. - */ -bool one_window(void) +/// Check that current tab page contains no more then one window other than +/// "aucmd_win". +bool one_window(void) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { bool seen_one = false; @@ -1761,14 +1760,20 @@ bool one_window(void) return true; } -/* - * Close the possibly last window in a tab page. - * Returns TRUE when the window was closed already. - */ -static int close_last_window_tabpage(win_T *win, int free_buf, tabpage_T *prev_curtab) +/// Close the possibly last window in a tab page. +/// +/// @param win window to close +/// @param free_buf whether to free the window's current buffer +/// @param prev_curtab previous tabpage that will be closed if "win" is the +/// last window in the tabpage +/// +/// @return true when the window was closed already. +static bool close_last_window_tabpage(win_T *win, bool free_buf, + tabpage_T *prev_curtab) + FUNC_ATTR_NONNULL_ARG(1) { if (firstwin != lastwin) { - return FALSE; + return false; } buf_T *old_curbuf = curbuf; @@ -1809,14 +1814,15 @@ static int close_last_window_tabpage(win_T *win, int free_buf, tabpage_T *prev_c terminal_resize(term, 0, 0); } - /* Since goto_tabpage_tp above did not trigger *Enter autocommands, do - * that now. */ - apply_autocmds(EVENT_TABCLOSED, prev_idx, prev_idx, FALSE, curbuf); - apply_autocmds(EVENT_WINENTER, NULL, NULL, FALSE, curbuf); - apply_autocmds(EVENT_TABENTER, NULL, NULL, FALSE, curbuf); - if (old_curbuf != curbuf) - apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); - return TRUE; + // Since goto_tabpage_tp above did not trigger *Enter autocommands, do + // that now. + apply_autocmds(EVENT_TABCLOSED, prev_idx, prev_idx, false, curbuf); + apply_autocmds(EVENT_WINENTER, NULL, NULL, false, curbuf); + apply_autocmds(EVENT_TABENTER, NULL, NULL, false, curbuf); + if (old_curbuf != curbuf) { + apply_autocmds(EVENT_BUFENTER, NULL, NULL, false, curbuf); + } + return true; } /* @@ -1907,9 +1913,16 @@ int win_close(win_T *win, int free_buf) */ if (win->w_buffer != NULL) { win->w_closing = true; - close_buffer(win, win->w_buffer, free_buf ? DOBUF_UNLOAD : 0, TRUE); - if (win_valid(win)) + close_buffer(win, win->w_buffer, free_buf ? DOBUF_UNLOAD : 0, true); + if (win_valid(win)) { win->w_closing = false; + } + + // Make sure curbuf is valid. It can become invalid if 'bufhidden' is + // "wipe". + if (!buf_valid(curbuf)) { + curbuf = firstbuf; + } } if (only_one_window() && win_valid(win) && win->w_buffer == NULL @@ -2301,20 +2314,22 @@ static win_T *frame2win(frame_T *frp) return frp->fr_win; } -/* - * Return TRUE if frame "frp" contains window "wp". - */ -static int frame_has_win(frame_T *frp, win_T *wp) +/// Check that the frame "frp" contains the window "wp". +/// +/// @param frp frame +/// @param wp window +static bool frame_has_win(frame_T *frp, win_T *wp) + FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(1) { - frame_T *p; - - if (frp->fr_layout == FR_LEAF) + if (frp->fr_layout == FR_LEAF) { return frp->fr_win == wp; - - for (p = frp->fr_child; p != NULL; p = p->fr_next) - if (frame_has_win(p, wp)) - return TRUE; - return FALSE; + } + for (frame_T *p = frp->fr_child; p != NULL; p = p->fr_next) { + if (frame_has_win(p, wp)) { + return true; + } + } + return false; } /* @@ -2406,58 +2421,72 @@ frame_new_height ( topfrp->fr_height = height; } -/* - * Return TRUE if height of frame "frp" should not be changed because of - * the 'winfixheight' option. - */ -static int frame_fixed_height(frame_T *frp) +/// Return true if height of frame "frp" should not be changed because of +/// the 'winfixheight' option. +/// +/// @param frp frame +/// +/// @return true if the frame has a fixed height +static bool frame_fixed_height(frame_T *frp) + FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { - /* frame with one window: fixed height if 'winfixheight' set. */ - if (frp->fr_win != NULL) + // frame with one window: fixed height if 'winfixheight' set. + if (frp->fr_win != NULL) { return frp->fr_win->w_p_wfh; - + } if (frp->fr_layout == FR_ROW) { - /* The frame is fixed height if one of the frames in the row is fixed - * height. */ - for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) - if (frame_fixed_height(frp)) - return TRUE; - return FALSE; + // The frame is fixed height if one of the frames in the row is fixed + // height. + for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) { + if (frame_fixed_height(frp)) { + return true; + } + } + return false; } - /* frp->fr_layout == FR_COL: The frame is fixed height if all of the - * frames in the row are fixed height. */ - for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) - if (!frame_fixed_height(frp)) - return FALSE; - return TRUE; + // frp->fr_layout == FR_COL: The frame is fixed height if all of the + // frames in the row are fixed height. + for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) { + if (!frame_fixed_height(frp)) { + return false; + } + } + return true; } -/* - * Return TRUE if width of frame "frp" should not be changed because of - * the 'winfixwidth' option. - */ -static int frame_fixed_width(frame_T *frp) +/// Return true if width of frame "frp" should not be changed because of +/// the 'winfixwidth' option. +/// +/// @param frp frame +/// +/// @return true if the frame has a fixed width +static bool frame_fixed_width(frame_T *frp) + FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { - /* frame with one window: fixed width if 'winfixwidth' set. */ - if (frp->fr_win != NULL) + // frame with one window: fixed width if 'winfixwidth' set. + if (frp->fr_win != NULL) { return frp->fr_win->w_p_wfw; - + } if (frp->fr_layout == FR_COL) { - /* The frame is fixed width if one of the frames in the row is fixed - * width. */ - for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) - if (frame_fixed_width(frp)) - return TRUE; - return FALSE; + // The frame is fixed width if one of the frames in the row is fixed + // width. + for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) { + if (frame_fixed_width(frp)) { + return true; + } + } + return false; } - /* frp->fr_layout == FR_ROW: The frame is fixed width if all of the - * frames in the row are fixed width. */ - for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) - if (!frame_fixed_width(frp)) - return FALSE; - return TRUE; + // frp->fr_layout == FR_ROW: The frame is fixed width if all of the + // frames in the row are fixed width. + for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) { + if (!frame_fixed_width(frp)) { + return false; + } + } + return true; } /* @@ -3028,10 +3057,10 @@ int make_tabpages(int maxcount) return count - todo; } -/* - * Return TRUE when "tpc" points to a valid tab page. - */ -bool valid_tabpage(tabpage_T *tpc) +/// Check that tpc points to a valid tab page. +/// +/// @param[in] tpc Tabpage to check. +bool valid_tabpage(tabpage_T *tpc) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { FOR_ALL_TABS(tp) { if (tp == tpc) { @@ -4837,17 +4866,15 @@ static void frame_add_height(frame_T *frp, int n) */ char_u *grab_file_name(long count, linenr_T *file_lnum) { + int options = FNAME_MESS | FNAME_EXP | FNAME_REL | FNAME_UNESC; if (VIsual_active) { size_t len; char_u *ptr; if (get_visual_text(NULL, &ptr, &len) == FAIL) return NULL; - return find_file_name_in_path(ptr, len, - FNAME_MESS|FNAME_EXP|FNAME_REL, - count, curbuf->b_ffname); + return find_file_name_in_path(ptr, len, options, count, curbuf->b_ffname); } - return file_name_at_cursor(FNAME_MESS|FNAME_HYP|FNAME_EXP|FNAME_REL, count, - file_lnum); + return file_name_at_cursor(options | FNAME_HYP, count, file_lnum); } /* @@ -4918,12 +4945,18 @@ file_name_in_line ( * Also allow "://" when ':' is not in 'isfname'. */ len = 0; - while (vim_isfilec(ptr[len]) - || ((options & FNAME_HYP) && path_is_url((char *)ptr + len))) - if (has_mbyte) + while (vim_isfilec(ptr[len]) || (ptr[len] == '\\' && ptr[len + 1] == ' ') + || ((options & FNAME_HYP) && path_is_url((char *)ptr + len))) { + if (ptr[len] == '\\' && ptr[len + 1] == ' ') { + // Skip over the "\" in "\ ". + ++len; + } + if (has_mbyte) { len += (size_t)(*mb_ptr2len)(ptr + len); - else + } else { ++len; + } + } /* * If there is trailing punctuation, remove it. @@ -5048,27 +5081,22 @@ int min_rows(void) return total; } -/* - * Return TRUE if there is only one window (in the current tab page), not - * counting a help or preview window, unless it is the current window. - * Does not count "aucmd_win". - */ -int only_one_window(void) +/// Check that there is only one window (and only one tab page), not counting a +/// help or preview window, unless it is the current window. Does not count +/// "aucmd_win". +bool only_one_window(void) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { - int count = 0; - - /* If there is another tab page there always is another window. */ - if (first_tabpage->tp_next != NULL) - return FALSE; + // If there is another tab page there always is another window. + if (first_tabpage->tp_next != NULL) { + return false; + } + int count = 0; FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { if (wp->w_buffer != NULL && (!((wp->w_buffer->b_help && !curbuf->b_help) - || wp->w_p_pvw - ) || wp == curwin) - && wp != aucmd_win - ) { - ++count; + || wp->w_p_pvw) || wp == curwin) && wp != aucmd_win) { + count++; } } return count <= 1; @@ -5567,38 +5595,42 @@ matchitem_T *get_match(win_T *wp, int id) } -/* - * Return TRUE if "topfrp" and its children are at the right height. - */ -static int frame_check_height(frame_T *topfrp, int height) +/// Check that "topfrp" and its children are at the right height. +/// +/// @param topfrp top frame pointer +/// @param height expected height +static bool frame_check_height(frame_T *topfrp, int height) + FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { - frame_T *frp; - - if (topfrp->fr_height != height) - return FALSE; - - if (topfrp->fr_layout == FR_ROW) - for (frp = topfrp->fr_child; frp != NULL; frp = frp->fr_next) - if (frp->fr_height != height) - return FALSE; - - return TRUE; + if (topfrp->fr_height != height) { + return false; + } + if (topfrp->fr_layout == FR_ROW) { + for (frame_T *frp = topfrp->fr_child; frp != NULL; frp = frp->fr_next) { + if (frp->fr_height != height) { + return false; + } + } + } + return true; } -/* - * Return TRUE if "topfrp" and its children are at the right width. - */ -static int frame_check_width(frame_T *topfrp, int width) +/// Check that "topfrp" and its children are at the right width. +/// +/// @param topfrp top frame pointer +/// @param width expected width +static bool frame_check_width(frame_T *topfrp, int width) + FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { - frame_T *frp; - - if (topfrp->fr_width != width) - return FALSE; - - if (topfrp->fr_layout == FR_COL) - for (frp = topfrp->fr_child; frp != NULL; frp = frp->fr_next) - if (frp->fr_width != width) - return FALSE; - - return TRUE; + if (topfrp->fr_width != width) { + return false; + } + if (topfrp->fr_layout == FR_COL) { + for (frame_T *frp = topfrp->fr_child; frp != NULL; frp = frp->fr_next) { + if (frp->fr_width != width) { + return false; + } + } + } + return true; } diff --git a/src/nvim/window.h b/src/nvim/window.h index eccc7835a8..2ac4c00c28 100644 --- a/src/nvim/window.h +++ b/src/nvim/window.h @@ -10,6 +10,7 @@ #define FNAME_INCL 8 /* apply 'includeexpr' */ #define FNAME_REL 16 /* ".." and "./" are relative to the (current) file instead of the current directory */ +#define FNAME_UNESC 32 // remove backslashes used for escaping /* * arguments for win_split() diff --git a/test/functional/eval/printf_spec.lua b/test/functional/eval/printf_spec.lua new file mode 100644 index 0000000000..6180f4156a --- /dev/null +++ b/test/functional/eval/printf_spec.lua @@ -0,0 +1,60 @@ +local helpers = require('test.functional.helpers') +local clear = helpers.clear +local eq = helpers.eq +local funcs = helpers.funcs +local exc_exec = helpers.exc_exec + +describe('printf()', function() + before_each(clear) + + it('works with zero and %b', function() + eq('0', funcs.printf('%lb', 0)) + eq('0', funcs.printf('%llb', 0)) + eq('0', funcs.printf('%zb', 0)) + end) + it('works with one and %b', function() + eq('1', funcs.printf('%b', 1)) + eq('1', funcs.printf('%lb', 1)) + eq('1', funcs.printf('%llb', 1)) + eq('1', funcs.printf('%zb', 1)) + end) + it('works with 0xff and %b', function() + eq('11111111', funcs.printf('%b', 0xff)) + eq('11111111', funcs.printf('%lb', 0xff)) + eq('11111111', funcs.printf('%llb', 0xff)) + eq('11111111', funcs.printf('%zb', 0xff)) + end) + it('accepts width modifier with %b', function() + eq(' 1', funcs.printf('%3b', 1)) + end) + it('accepts prefix modifier with %b', function() + eq('0b1', funcs.printf('%#b', 1)) + end) + it('writes capital B with %B', function() + eq('0B1', funcs.printf('%#B', 1)) + end) + it('accepts prefix, zero-fill and width modifiers with %b', function() + eq('0b001', funcs.printf('%#05b', 1)) + end) + it('accepts prefix and width modifiers with %b', function() + eq(' 0b1', funcs.printf('%#5b', 1)) + end) + it('does not write prefix for zero with prefix and width modifier used with %b', function() + eq(' 0', funcs.printf('%#5b', 0)) + end) + it('accepts precision modifier with %b', function() + eq('00000', funcs.printf('%.5b', 0)) + end) + it('accepts all modifiers with %b at once', function() + -- zero-fill modifier is ignored when used with left-align + -- force-sign and add-blank are ignored + -- use-grouping-characters modifier is ignored always + eq('0b00011 ', funcs.printf('% \'+#0-10.5b', 3)) + end) + it('errors out when %b modifier is used for a list', function() + eq('Vim(call):E745: Using a List as a Number', exc_exec('call printf("%b", [])')) + end) + it('errors out when %b modifier is used for a float', function() + eq('Vim(call):E805: Using a Float as a Number', exc_exec('call printf("%b", 3.1415926535)')) + end) +end) diff --git a/test/functional/job/job_spec.lua b/test/functional/job/job_spec.lua index 0915ab0955..d21b9051e2 100644 --- a/test/functional/job/job_spec.lua +++ b/test/functional/job/job_spec.lua @@ -142,6 +142,35 @@ describe('jobs', function() nvim('command', "call jobstart(['cat', '-'], g:job_opts)") end) + it('can get the pid value using getpid', function() + nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") + local pid = eval('jobpid(j)') + eq(0,os.execute('ps -p '..pid..' > /dev/null')) + nvim('command', 'call jobstop(j)') + eq({'notification', 'exit', {0, 0}}, next_msg()) + neq(0,os.execute('ps -p '..pid..' > /dev/null')) + end) + + it("doesn't survive the exit of nvim", function() + -- use sleep, which doesn't die on stdin close + nvim('command', "let j = jobstart(['sleep', '1000'], g:job_opts)") + local pid = eval('jobpid(j)') + eq(0,os.execute('ps -p '..pid..' > /dev/null')) + clear() + neq(0,os.execute('ps -p '..pid..' > /dev/null')) + end) + + it('can survive the exit of nvim with "detach"', function() + nvim('command', 'let g:job_opts.detach = 1') + nvim('command', "let j = jobstart(['sleep', '1000'], g:job_opts)") + local pid = eval('jobpid(j)') + eq(0,os.execute('ps -p '..pid..' > /dev/null')) + clear() + eq(0,os.execute('ps -p '..pid..' > /dev/null')) + -- clean up after ourselves + os.execute('kill -9 '..pid..' > /dev/null') + end) + it('can pass user data to the callback', function() nvim('command', 'let g:job_opts.user = {"n": 5, "s": "str", "l": [1]}') nvim('command', "call jobstart(['echo'], g:job_opts)") diff --git a/test/functional/legacy/035_increment_and_decrement_spec.lua b/test/functional/legacy/035_increment_and_decrement_spec.lua index 20c0cc4206..e6252c384b 100644 --- a/test/functional/legacy/035_increment_and_decrement_spec.lua +++ b/test/functional/legacy/035_increment_and_decrement_spec.lua @@ -11,34 +11,40 @@ describe('increment and decrement commands', function() it('should work', function() -- Insert some numbers in various bases. insert([[ - 100 0x100 077 0 - 100 0x100 077 + 0b101 100 0x100 077 0 + 0b101 100 0x100 077 100 0x100 077 0xfF 0xFf - 100 0x100 077]]) + 100 0x100 077 + 0x0b101 0b1101]]) -- Increment and decrement numbers in the first row, interpreting the -- numbers as decimal, octal or hexadecimal. - execute('set nrformats=octal,hex', '1') - feed('102ll64128$') + execute('set nrformats=bin,octal,hex', '1') + feed('63l102ll64128$') -- For the second row, treat the numbers as decimal or octal. -- 0x100 should be interpreted as decimal 0, the character x, and decimal 100. execute('set nrformats=octal', '2') - feed('0102l2w65129blx6lD') + feed('0w102l2w65129blx6lD') -- For the third row, treat the numbers as decimal or hexadecimal. -- 077 should be interpreted as decimal 77. execute('set nrformats=hex', '3') feed('0101l257Txldt ') - -- For the last row, interpret all numbers as decimal. + -- For the fourth row, interpret all numbers as decimal. execute('set nrformats=', '4') feed('0200l100w78') + -- For the last row, interpret as binary and hexadecimal. + execute('set nrformats=bin,hex', '5') + feed('010065l6432') + expect([[ - 0 0x0ff 0000 -1 - 0 1x100 0777777 + 0b011 0 0x0ff 0000 -1 + 1b101 0 1x100 0777777 -1 0x0 078 0xFE 0xfe - -100 -100x100 000]]) + -100 -100x100 000 + 0x0b0de 0b0101101]]) end) end) diff --git a/test/functional/legacy/039_visual_block_mode_commands_spec.lua b/test/functional/legacy/039_visual_block_mode_commands_spec.lua new file mode 100644 index 0000000000..55db9169fa --- /dev/null +++ b/test/functional/legacy/039_visual_block_mode_commands_spec.lua @@ -0,0 +1,234 @@ +-- Test Visual block mode commands +-- And test "U" in Visual mode, also on German sharp S. + +local helpers = require('test.functional.helpers') +local nvim, eq = helpers.meths, helpers.eq +local insert, feed = helpers.insert, helpers.feed +local clear, expect = helpers.clear, helpers.expect +local source, execute = helpers.source, helpers.execute + +describe('Visual block mode', function() + + before_each(function() + clear() + + execute('set ts&vi sw&vi sts&vi noet') -- Vim compatible + end) + + it('should shift, insert, replace and change a block', function() + insert([[ + abcdefghijklm + abcdefghijklm + abcdefghijklm + abcdefghijklm + abcdefghijklm]]) + + feed('gg') + -- Test shift-right of a block + feed('jllll<C-v>jj>wll<C-v>jlll><CR>') + -- Test shift-left of a block + feed('G$hhhh<C-v>kk<lt>') + -- Test block-insert + feed('Gkl<C-v>kkkIxyz<ESC>') + -- Test block-replace + feed('Gllll<C-v>kkklllrq') + -- Test block-change + feed('G$khhh<C-v>hhkkcmno<ESC>') + + expect([[ + axyzbcdefghijklm + axyzqqqq mno ghijklm + axyzqqqqef mno ghijklm + axyzqqqqefgmnoklm + abcdqqqqijklm]]) + end) + + it('should insert a block using cursor keys for movement', function() + insert([[ + aaaaaa + bbbbbb + cccccc + dddddd + + xaaa + bbbb + cccc + dddd]]) + + execute('/^aa') + feed('l<C-v>jjjlllI<Right><Right> <ESC>') + execute('/xaaa$') + feed('<C-v>jjjI<lt>><Left>p<ESC>') + + expect([[ + aaa aaa + bbb bbb + ccc ccc + ddd ddd + + <p>xaaa + <p>bbbb + <p>cccc + <p>dddd]]) + end) + + it('should create a block', function() + insert([[ + A23 + 4567 + + B23 + 4567 + + C23 + 4567]]) + + -- Test for Visual block was created with the last <C-v>$. + execute('/^A23$/') + feed('l<C-v>j$Aab<ESC>') + -- Test for Visual block was created with the middle <C-v>$ (1). + execute('/^B23$/') + feed('l<C-v>j$hAab<ESC>') + -- Test for Visual block was created with the middle <C-v>$ (2). + execute('/^C23$/') + feed('l<C-v>j$hhAab<ESC>') + + expect([[ + A23ab + 4567ab + + B23 ab + 4567ab + + C23ab + 456ab7]]) + end) + + it('should insert and append a block when virtualedit=all', function() + insert([[ + line1 + line2 + line3 + ]]) + + -- Test for Visual block insert when virtualedit=all and utf-8 encoding. + execute('set ve=all') + execute('/\t\tline') + feed('07l<C-v>jjIx<ESC>') + + expect([[ + x line1 + x line2 + x line3 + ]]) + + -- Test for Visual block append when virtualedit=all. + feed('012l<C-v>jjAx<ESC>') + + expect([[ + x x line1 + x x line2 + x x line3 + ]]) + end) + + it('should make a selected part uppercase', function() + -- GUe must uppercase a whole word, also when ß changes to SS. + feed('Gothe youtußeuu end<ESC>Ypk0wgUe<CR>') + -- GUfx must uppercase until x, inclusive. + feed('O- youßtußexu -<ESC>0fogUfx<CR>') + -- VU must uppercase a whole line. + feed('YpkVU<CR>') + -- Same, when it's the last line in the buffer. + feed('YPGi111<ESC>VUddP<CR>') + -- Uppercase two lines. + feed('Oblah di<CR>') + feed('doh dut<ESC>VkUj<CR>') + -- Uppercase part of two lines. + feed('ddppi333<ESC>k0i222<esc>fyllvjfuUk<CR>') + + expect([[ + + the YOUTUSSEUU end + - yOUSSTUSSEXu - + THE YOUTUSSEUU END + 111THE YOUTUSSEUU END + BLAH DI + DOH DUT + 222the yoUTUSSEUU END + 333THE YOUTUßeuu end]]) + end) + + it('should replace using Enter or NL', function() + -- Visual replace using Enter or NL. + feed('G3o123456789<ESC>2k05l<C-v>2jr<CR>') + feed('G3o98765<ESC>2k02l<C-v>2jr<C-v><CR>') + feed('G3o123456789<ESC>2k05l<C-v>2jr<CR>') + feed('G3o98765<ESC>2k02l<C-v>2jr<C-v><Nul>') + + local expected = [[ + + 12345 + 789 + 12345 + 789 + 12345 + 789 + 98<CR>65 + 98<CR>65 + 98<CR>65 + 12345 + 789 + 12345 + 789 + 12345 + 789 + 98<Nul>65 + 98<Nul>65 + 98<Nul>65]] + expected = expected:gsub('<CR>', '\r') + expected = expected:gsub('<Nul>', '\x00') + + expect(expected) + end) + + it('should treat cursor position correctly when virtualedit=block', function() + insert([[ + 12345 + 789 + 98765]]) + + -- Test cursor position. When virtualedit=block and Visual block mode and $gj. + execute('set ve=block') + feed('G2l') + feed('2k<C-v>$gj<ESC>') + execute([[let cpos=getpos("'>")]]) + local cpos = nvim.get_var('cpos') + local expected = { + col = 4, + off = 0 + } + local actual = { + col = cpos[3], + off = cpos[4] + } + + eq(expected, actual) + end) + + it('should replace spaces in front of the block with tabs', function() + insert([[ + #define BO_ALL 0x0001 + #define BO_BS 0x0002 + #define BO_CRSR 0x0004]]) + + -- Block_insert when replacing spaces in front of the block with tabs. + execute('set ts=8 sts=4 sw=4') + feed('ggf0<C-v>2jI<TAB><ESC>') + + expect([[ + #define BO_ALL 0x0001 + #define BO_BS 0x0002 + #define BO_CRSR 0x0004]]) + end) +end) diff --git a/test/functional/legacy/057_sort_spec.lua b/test/functional/legacy/057_sort_spec.lua index 585b391198..65defbae96 100644 --- a/test/functional/legacy/057_sort_spec.lua +++ b/test/functional/legacy/057_sort_spec.lua @@ -600,4 +600,39 @@ describe(':sort', function() eq('Vim(sort):E474: Invalid argument', eval('tmpvar')) expect(text) end) + + it('binary', function() + insert([[ + 0b111000 + 0b101100 + 0b101001 + 0b101001 + 0b101000 + 0b000000 + 0b001000 + 0b010000 + 0b101000 + 0b100000 + 0b101010 + 0b100010 + 0b100100 + 0b100010]]) + execute([[sort b]]) + expect([[ + 0b000000 + 0b001000 + 0b010000 + 0b100000 + 0b100010 + 0b100010 + 0b100100 + 0b101000 + 0b101000 + 0b101001 + 0b101001 + 0b101010 + 0b101100 + 0b111000]]) + end) + end) 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 new file mode 100644 index 0000000000..dc6df007e6 --- /dev/null +++ b/test/functional/legacy/083_tag_search_with_file_encoding_spec.lua @@ -0,0 +1,110 @@ +-- Tests for tag search with !_TAG_FILE_ENCODING. + +local helpers = require('test.functional.helpers') +local insert, source, clear, expect, write_file = helpers.insert, + helpers.source, helpers.clear, helpers.expect, helpers.write_file + +local function has_iconv() + clear() -- ensures session + return 1 == helpers.eval('has("iconv")') +end + +describe('tag search with !_TAG_FILE_ENCODING', function() + setup(function() + clear() + -- Create some temp files that are needed for the test run. In the old + -- test suite this was done by putting the text inside the file test83.in + -- and executing some "/first/,/last/w! tmpfile" commands. + write_file('Xtags1.txt', 'text for tags1\nabcdefghijklmnopqrs\n') + write_file('Xtags2.txt', 'text for tags2\nABC\n') + write_file('Xtags3.txt', 'text for tags3\nABC\n') + write_file('Xtags1', [[ + !_TAG_FILE_ENCODING utf-8 // + abcdefghijklmnopqrs Xtags1.txt /abcdefghijklmnopqrs + ]]) + write_file('test83-tags2', + '!_TAG_FILE_ENCODING cp932 //\n' .. + '\x82`\x82a\x82b Xtags2.txt /\x82`\x82a\x82b\n' + ) + -- The last file is very long but repetetive and can be generated on the + -- fly. + local text = helpers.dedent([[ + !_TAG_FILE_SORTED 1 // + !_TAG_FILE_ENCODING cp932 // + ]]) + local line = ' Xtags3.txt /\x82`\x82a\x82b\n' + for i = 1, 100 do + text = text .. 'abc' .. i .. line + end + write_file('test83-tags3', text) + end) + teardown(function() + os.remove('Xtags1') + os.remove('Xtags1.txt') + os.remove('Xtags2.txt') + os.remove('Xtags3.txt') + os.remove('test83-tags2') + os.remove('test83-tags3') + end) + + if not has_iconv() then + pending('skipped (missing iconv)', function() end) + else + it('is working', function() + + insert('Results of test83') + + -- Case1: + source([[ + new + set tags=Xtags1 + let v:errmsg = '' + tag abcdefghijklmnopqrs + if v:errmsg =~ 'E426:' || getline('.') != 'abcdefghijklmnopqrs' + close + put ='case1: failed' + else + close + put ='case1: ok' + endif + ]]) + + -- Case2: + source([[ + new + set tags=test83-tags2 + let v:errmsg = '' + tag /.BC + if v:errmsg =~ 'E426:' || getline('.') != 'ABC' + close + put ='case2: failed' + else + close + put ='case2: ok' + endif + ]]) + + -- Case3: + source([[ + new + set tags=test83-tags3 + let v:errmsg = '' + tag abc50 + if v:errmsg =~ 'E426:' || getline('.') != 'ABC' + close + put ='case3: failed' + else + close + put ='case3: ok' + endif + ]]) + + -- Assert buffer contents. + expect([[ + Results of test83 + case1: ok + case2: ok + case3: ok]]) + end) + end +end) diff --git a/test/functional/legacy/cdo_spec.lua b/test/functional/legacy/cdo_spec.lua new file mode 100644 index 0000000000..4b313ede3f --- /dev/null +++ b/test/functional/legacy/cdo_spec.lua @@ -0,0 +1,226 @@ +-- Tests for the :cdo, :cfdo, :ldo and :lfdo commands + +local helpers = require('test.functional.helpers') +local nvim, clear = helpers.meths, helpers.clear +local call, feed = helpers.call, helpers.feed +local source, eq = helpers.source, helpers.eq + +local function expected_empty() + eq({}, nvim.get_vvar('errors')) +end + +describe('cdo', function() + before_each(function() + clear() + + call('writefile', {'Line1', 'Line2', 'Line3'}, 'Xtestfile1') + call('writefile', {'Line1', 'Line2', 'Line3'}, 'Xtestfile2') + call('writefile', {'Line1', 'Line2', 'Line3'}, 'Xtestfile3') + + source([=[ + " Returns the current line in '<filename> <linenum>L <column>C' format + function GetRuler() + return expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' + endfunction + + " Tests for the :cdo and :ldo commands + function XdoTests(cchar) + enew + + " Shortcuts for calling the cdo and ldo commands + let Xdo = a:cchar . 'do' + let Xgetexpr = a:cchar . 'getexpr' + let Xprev = a:cchar. 'prev' + let XdoCmd = Xdo . ' call add(l, GetRuler())' + + " Try with an empty list + let l = [] + exe XdoCmd + call assert_equal([], l) + + " Populate the list and then try + exe Xgetexpr . " ['non-error 1', 'Xtestfile1:1:3:Line1', 'non-error 2', 'Xtestfile2:2:2:Line2', 'non-error 3', 'Xtestfile3:3:1:Line3']" + + let l = [] + exe XdoCmd + call assert_equal(['Xtestfile1 1L 3C', 'Xtestfile2 2L 2C', 'Xtestfile3 3L 1C'], l) + + " Run command only on selected error lines + let l = [] + enew + exe "2,3" . XdoCmd + call assert_equal(['Xtestfile2 2L 2C', 'Xtestfile3 3L 1C'], l) + + " Boundary condition tests + let l = [] + enew + exe "1,1" . XdoCmd + call assert_equal(['Xtestfile1 1L 3C'], l) + + let l = [] + enew + exe "3" . XdoCmd + call assert_equal(['Xtestfile3 3L 1C'], l) + + " Range test commands + let l = [] + enew + exe "%" . XdoCmd + call assert_equal(['Xtestfile1 1L 3C', 'Xtestfile2 2L 2C', 'Xtestfile3 3L 1C'], l) + + let l = [] + enew + exe "1,$" . XdoCmd + call assert_equal(['Xtestfile1 1L 3C', 'Xtestfile2 2L 2C', 'Xtestfile3 3L 1C'], l) + + let l = [] + enew + exe Xprev + exe "." . XdoCmd + call assert_equal(['Xtestfile2 2L 2C'], l) + + let l = [] + enew + exe "+" . XdoCmd + call assert_equal(['Xtestfile3 3L 1C'], l) + + " Invalid error lines test + let l = [] + enew + exe "silent! 27" . XdoCmd + exe "silent! 4,5" . XdoCmd + call assert_equal([], l) + + " Run commands from an unsaved buffer + let v:errmsg='' + let l = [] + enew + setlocal modified + exe "silent! 2,2" . XdoCmd + if v:errmsg !~# 'No write since last change' + call add(v:errors, 'Unsaved file change test failed') + endif + + " If the executed command fails, then the operation should be aborted + enew! + let subst_count = 0 + exe "silent!" . Xdo . " s/Line/xLine/ | let subst_count += 1" + if subst_count != 1 || getline('.') != 'xLine1' + call add(v:errors, 'Abort command on error test failed') + endif + + let l = [] + exe "2,2" . Xdo . "! call add(l, GetRuler())" + call assert_equal(['Xtestfile2 2L 2C'], l) + + " List with no valid error entries + let l = [] + edit! +2 Xtestfile1 + exe Xgetexpr . " ['non-error 1', 'non-error 2', 'non-error 3']" + exe XdoCmd + call assert_equal([], l) + exe "silent! 2" . XdoCmd + call assert_equal([], l) + let v:errmsg='' + exe "%" . XdoCmd + exe "1,$" . XdoCmd + exe "." . XdoCmd + call assert_equal('', v:errmsg) + + " List with only one valid entry + let l = [] + exe Xgetexpr . " ['Xtestfile3:3:1:Line3']" + exe XdoCmd + call assert_equal(['Xtestfile3 3L 1C'], l) + + endfunction + + " Tests for the :cfdo and :lfdo commands + function XfdoTests(cchar) + enew + + " Shortcuts for calling the cfdo and lfdo commands + let Xfdo = a:cchar . 'fdo' + let Xgetexpr = a:cchar . 'getexpr' + let XfdoCmd = Xfdo . ' call add(l, GetRuler())' + let Xpfile = a:cchar. 'pfile' + + " Clear the quickfix/location list + exe Xgetexpr . " []" + + " Try with an empty list + let l = [] + exe XfdoCmd + call assert_equal([], l) + + " Populate the list and then try + exe Xgetexpr . " ['non-error 1', 'Xtestfile1:1:3:Line1', 'Xtestfile1:2:1:Line2', 'non-error 2', 'Xtestfile2:2:2:Line2', 'non-error 3', 'Xtestfile3:2:3:Line2', 'Xtestfile3:3:1:Line3']" + + let l = [] + exe XfdoCmd + call assert_equal(['Xtestfile1 1L 3C', 'Xtestfile2 2L 2C', 'Xtestfile3 2L 3C'], l) + + " Run command only on selected error lines + let l = [] + exe "2,3" . XfdoCmd + call assert_equal(['Xtestfile2 2L 2C', 'Xtestfile3 2L 3C'], l) + + " Boundary condition tests + let l = [] + exe "3" . XfdoCmd + call assert_equal(['Xtestfile3 2L 3C'], l) + + " Range test commands + let l = [] + exe "%" . XfdoCmd + call assert_equal(['Xtestfile1 1L 3C', 'Xtestfile2 2L 2C', 'Xtestfile3 2L 3C'], l) + + let l = [] + exe "1,$" . XfdoCmd + call assert_equal(['Xtestfile1 1L 3C', 'Xtestfile2 2L 2C', 'Xtestfile3 2L 3C'], l) + + let l = [] + exe Xpfile + exe "." . XfdoCmd + call assert_equal(['Xtestfile2 2L 2C'], l) + + " List with only one valid entry + let l = [] + exe Xgetexpr . " ['Xtestfile2:2:5:Line2']" + exe XfdoCmd + call assert_equal(['Xtestfile2 2L 5C'], l) + + endfunction + ]=]) + end) + + after_each(function() + os.remove('Xtestfile1') + os.remove('Xtestfile2') + os.remove('Xtestfile3') + end) + + it('works for :cdo', function() + -- call('XdoTests', 'c') + feed(":call XdoTests('c')<CR><C-l>") + expected_empty() + end) + + it('works for :cfdo', function() + -- call('XfdoTests', 'c') + feed(":call XfdoTests('c')<CR><C-l>") + expected_empty() + end) + + it('works for :ldo', function() + -- call('XdoTests', 'l') + feed(":call XdoTests('l')<CR><C-l>") + expected_empty() + end) + + it('works for :lfdo', function() + -- call('XfdoTests', 'l') + feed(":call XfdoTests('l')<CR><C-l>") + expected_empty() + end) +end) diff --git a/test/functional/legacy/erasebackword_spec.lua b/test/functional/legacy/erasebackword_spec.lua new file mode 100644 index 0000000000..cb3967b763 --- /dev/null +++ b/test/functional/legacy/erasebackword_spec.lua @@ -0,0 +1,24 @@ +-- Test for CTRL-W in Insert mode + +local helpers = require('test.functional.helpers') +local clear, feed, expect = helpers.clear, helpers.feed, helpers.expect + +describe('CTRL-W in Insert mode', function() + setup(clear) + + it('works for multi-byte characters', function() + + for i = 1, 6 do + feed('o wwwこんにちわ世界ワールドvim ' .. string.rep('<C-w>', i) .. '<esc>') + end + + expect([[ + + wwwこんにちわ世界ワールド + wwwこんにちわ世界 + wwwこんにちわ + www + + ]]) + end) +end) diff --git a/test/functional/legacy/eval_spec.lua b/test/functional/legacy/eval_spec.lua new file mode 100644 index 0000000000..05cd73dbd4 --- /dev/null +++ b/test/functional/legacy/eval_spec.lua @@ -0,0 +1,696 @@ +-- Test for various eval features. + +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 +local eq, eval, wait, write_file = helpers.eq, helpers.eval, helpers.wait, helpers.write_file + +local function has_clipboard() + clear() + return 1 == eval("has('clipboard')") +end + +describe('eval', function() + setup(function() + write_file('test_eval_setup.vim', [[ + set noswapfile + lang C + + fun AppendRegContents(reg) + call AppendRegParts(a:reg, getregtype(a:reg), getreg(a:reg), string(getreg(a:reg, 0, 1)), getreg(a:reg, 1), string(getreg(a:reg, 1, 1))) + endfun + + fun AppendRegParts(reg, type, cont, strcont, cont1, strcont1) + call append('$', printf('%s: type %s; value: %s (%s), expr: %s (%s)', a:reg, a:type, a:cont, a:strcont, a:cont1, a:strcont1)) + endfun + + command -nargs=? AR :call AppendRegContents(<q-args>) + + fun SetReg(...) + call call('setreg', a:000) + call append('$', printf('{{{2 setreg(%s)', string(a:000)[1:-2])) + call AppendRegContents(a:1) + if a:1 isnot# '=' + execute "silent normal! Go==\n==\e\"".a:1."P" + endif + endfun + ]]) + end) + before_each(clear) + teardown(function() + os.remove('test_eval_setup.vim') + end) + + it(':let', function() + execute('so test_eval_setup.vim') + execute([[let @" = 'abc']]) + execute('AR "') + execute([[let @" = "abc\n"]]) + source('AR "') + execute([[let @" = "abc\<C-m>"]]) + execute('AR "') + execute([[let @= = '"abc"']]) + execute('AR =') + 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 (['abc']), expr: "abc" (['"abc"'])]]) + end) + + it('basic setreg() tests', function() + execute('so test_eval_setup.vim') + insert('{{{1 Basic setreg tests') + execute([[call SetReg('a', 'abcA', 'c')]]) + execute([[call SetReg('b', 'abcB', 'v')]]) + execute([[call SetReg('c', 'abcC', 'l')]]) + execute([[call SetReg('d', 'abcD', 'V')]]) + execute([[call SetReg('e', 'abcE', 'b')]]) + execute([[call SetReg('f', 'abcF', "\<C-v>")]]) + execute([[call SetReg('g', 'abcG', 'b10')]]) + execute([[call SetReg('h', 'abcH', "\<C-v>10")]]) + execute([[call SetReg('I', 'abcI')]]) + + feed('Go{{{1 Appending single lines with setreg()<esc>') + execute([[call SetReg('A', 'abcAc', 'c')]]) + execute([[call SetReg('A', 'abcAl', 'l')]]) + execute([[call SetReg('A', 'abcAc2','c')]]) + execute([[call SetReg('b', 'abcBc', 'ca')]]) + execute([[call SetReg('b', 'abcBb', 'ba')]]) + execute([[call SetReg('b', 'abcBc2','ca')]]) + execute([[call SetReg('b', 'abcBb2','b50a')]]) + execute([[call SetReg('C', 'abcCl', 'l')]]) + execute([[call SetReg('C', 'abcCc', 'c')]]) + execute([[call SetReg('D', 'abcDb', 'b')]]) + execute([[call SetReg('E', 'abcEb', 'b')]]) + execute([[call SetReg('E', 'abcEl', 'l')]]) + execute([[call SetReg('F', 'abcFc', 'c')]]) + expect([[ + {{{1 Basic setreg tests + {{{2 setreg('a', 'abcA', 'c') + a: type v; value: abcA (['abcA']), expr: abcA (['abcA']) + == + =abcA= + {{{2 setreg('b', 'abcB', 'v') + b: type v; value: abcB (['abcB']), expr: abcB (['abcB']) + == + =abcB= + {{{2 setreg('c', 'abcC', 'l') + c: type V; value: abcC]].."\x00 (['abcC']), expr: abcC\x00"..[[ (['abcC']) + == + abcC + == + {{{2 setreg('d', 'abcD', 'V') + d: type V; value: abcD]].."\x00 (['abcD']), expr: abcD\x00"..[[ (['abcD']) + == + abcD + == + {{{2 setreg('e', 'abcE', 'b') + e: type ]]..'\x16'..[[4; value: abcE (['abcE']), expr: abcE (['abcE']) + == + =abcE= + {{{2 setreg('f', 'abcF', ']]..'\x16'..[[') + f: type ]]..'\x16'..[[4; value: abcF (['abcF']), expr: abcF (['abcF']) + == + =abcF= + {{{2 setreg('g', 'abcG', 'b10') + g: type ]]..'\x16'..[[10; value: abcG (['abcG']), expr: abcG (['abcG']) + == + =abcG = + {{{2 setreg('h', 'abcH', ']]..'\x16'..[[10') + h: type ]]..'\x16'..[[10; value: abcH (['abcH']), expr: abcH (['abcH']) + == + =abcH = + {{{2 setreg('I', 'abcI') + I: type v; value: abcI (['abcI']), expr: abcI (['abcI']) + == + =abcI= + {{{1 Appending single lines with setreg() + {{{2 setreg('A', 'abcAc', 'c') + A: type v; value: abcAabcAc (['abcAabcAc']), expr: abcAabcAc (['abcAabcAc']) + == + =abcAabcAc= + {{{2 setreg('A', 'abcAl', 'l') + A: type V; value: abcAabcAcabcAl]].."\x00 (['abcAabcAcabcAl']), expr: abcAabcAcabcAl\x00"..[[ (['abcAabcAcabcAl']) + == + abcAabcAcabcAl + == + {{{2 setreg('A', 'abcAc2', 'c') + A: type v; value: abcAabcAcabcAl]].."\x00abcAc2 (['abcAabcAcabcAl', 'abcAc2']), expr: abcAabcAcabcAl\x00"..[[abcAc2 (['abcAabcAcabcAl', 'abcAc2']) + == + =abcAabcAcabcAl + abcAc2= + {{{2 setreg('b', 'abcBc', 'ca') + b: type v; value: abcBabcBc (['abcBabcBc']), expr: abcBabcBc (['abcBabcBc']) + == + =abcBabcBc= + {{{2 setreg('b', 'abcBb', 'ba') + b: type ]]..'\x16'..[[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']) + == + =abcBabcBcabcBb + abcBc2= + {{{2 setreg('b', 'abcBb2', 'b50a') + b: type ]].."\x1650; value: abcBabcBcabcBb\x00abcBc2abcBb2 (['abcBabcBcabcBb', 'abcBc2abcBb2']), expr: abcBabcBcabcBb\x00"..[[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']) + == + 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']) + == + =abcC + abcCl + abcCc= + {{{2 setreg('D', 'abcDb', 'b') + D: type ]].."\x165; value: abcD\x00abcDb (['abcD', 'abcDb']), expr: abcD\x00"..[[abcDb (['abcD', 'abcDb']) + == + =abcD = + abcDb + {{{2 setreg('E', 'abcEb', 'b') + E: type ]].."\x165; value: abcE\x00abcEb (['abcE', 'abcEb']), expr: abcE\x00"..[[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']) + == + abcE + abcEb + abcEl + == + {{{2 setreg('F', 'abcFc', 'c') + F: type v; value: abcF]].."\x00abcFc (['abcF', 'abcFc']), expr: abcF\x00"..[[abcFc (['abcF', 'abcFc']) + == + =abcF + abcFc=]]) + end) + + it('appending NL with setreg()', function() + execute('so test_eval_setup.vim') + + execute([[call setreg('a', 'abcA2', 'c')]]) + execute([[call setreg('b', 'abcB2', 'v')]]) + execute([[call setreg('c', 'abcC2', 'l')]]) + execute([[call setreg('d', 'abcD2', 'V')]]) + execute([[call setreg('e', 'abcE2', 'b')]]) + execute([[call setreg('f', 'abcF2', "\<C-v>")]]) + -- These registers where set like this in the old test_eval.in but never + -- copied to the output buffer with SetReg(). They do not appear in + -- test_eval.ok. Therefore they are commented out. + --execute([[call setreg('g', 'abcG2', 'b10')]]) + --execute([[call setreg('h', 'abcH2', "\<C-v>10")]]) + --execute([[call setreg('I', 'abcI2')]]) + + execute([[call SetReg('A', "\n")]]) + execute([[call SetReg('B', "\n", 'c')]]) + execute([[call SetReg('C', "\n")]]) + execute([[call SetReg('D', "\n", 'l')]]) + execute([[call SetReg('E', "\n")]]) + execute([[call SetReg('F', "\n", 'b')]]) + expect([[ + + {{{2 setreg('A', ']]..'\x00'..[[') + A: type V; value: abcA2]].."\x00 (['abcA2']), expr: abcA2\x00"..[[ (['abcA2']) + == + abcA2 + == + {{{2 setreg('B', ']]..'\x00'..[[', 'c') + B: type v; value: abcB2]].."\x00 (['abcB2', '']), expr: abcB2\x00"..[[ (['abcB2', '']) + == + =abcB2 + = + {{{2 setreg('C', ']]..'\x00'..[[') + C: type V; value: abcC2]].."\x00\x00 (['abcC2', '']), expr: abcC2\x00\x00"..[[ (['abcC2', '']) + == + abcC2 + + == + {{{2 setreg('D', ']]..'\x00'..[[', 'l') + D: type V; value: abcD2]].."\x00\x00 (['abcD2', '']), expr: abcD2\x00\x00"..[[ (['abcD2', '']) + == + abcD2 + + == + {{{2 setreg('E', ']]..'\x00'..[[') + E: type V; value: abcE2]].."\x00\x00 (['abcE2', '']), expr: abcE2\x00\x00"..[[ (['abcE2', '']) + == + abcE2 + + == + {{{2 setreg('F', ']]..'\x00'..[[', 'b') + F: type ]].."\x160; value: abcF2\x00 (['abcF2', '']), expr: abcF2\x00"..[[ (['abcF2', '']) + == + =abcF2= + ]]) + end) + + it('setting and appending list with setreg()', function() + execute('so test_eval_setup.vim') + + execute([[$put ='{{{1 Setting lists with setreg()']]) + execute([=[call SetReg('a', ['abcA3'], 'c')]=]) + execute([=[call SetReg('b', ['abcB3'], 'l')]=]) + execute([=[call SetReg('c', ['abcC3'], 'b')]=]) + execute([=[call SetReg('d', ['abcD3'])]=]) + execute([=[call SetReg('e', [1, 2, 'abc', 3])]=]) + execute([=[call SetReg('f', [1, 2, 3])]=]) + + execute([[$put ='{{{1 Appending lists with setreg()']]) + execute([=[call SetReg('A', ['abcA3c'], 'c')]=]) + execute([=[call SetReg('b', ['abcB3l'], 'la')]=]) + execute([=[call SetReg('C', ['abcC3b'], 'lb')]=]) + execute([=[call SetReg('D', ['abcD32'])]=]) + execute([=[call SetReg('A', ['abcA32'])]=]) + execute([=[call SetReg('B', ['abcB3c'], 'c')]=]) + execute([=[call SetReg('C', ['abcC3l'], 'l')]=]) + execute([=[call SetReg('D', ['abcD3b'], 'b')]=]) + expect([[ + + {{{1 Setting lists with setreg() + {{{2 setreg('a', ['abcA3'], 'c') + a: type v; value: abcA3 (['abcA3']), expr: abcA3 (['abcA3']) + == + =abcA3= + {{{2 setreg('b', ['abcB3'], 'l') + b: type V; value: abcB3]].."\x00 (['abcB3']), expr: abcB3\x00"..[[ (['abcB3']) + == + abcB3 + == + {{{2 setreg('c', ['abcC3'], 'b') + c: type ]]..'\x16'..[[5; value: abcC3 (['abcC3']), expr: abcC3 (['abcC3']) + == + =abcC3= + {{{2 setreg('d', ['abcD3']) + d: type V; value: abcD3]].."\x00 (['abcD3']), expr: abcD3\x00"..[[ (['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']) + == + 1 + 2 + abc + 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']) + == + 1 + 2 + 3 + == + {{{1 Appending lists with setreg() + {{{2 setreg('A', ['abcA3c'], 'c') + A: type v; value: abcA3]].."\x00abcA3c (['abcA3', 'abcA3c']), expr: abcA3\x00"..[[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']) + == + abcB3 + abcB3l + == + {{{2 setreg('C', ['abcC3b'], 'lb') + C: type ]].."\x166; value: abcC3\x00abcC3b (['abcC3', 'abcC3b']), expr: abcC3\x00"..[[abcC3b (['abcC3', 'abcC3b']) + == + =abcC3 = + abcC3b + {{{2 setreg('D', ['abcD32']) + D: type V; value: abcD3]].."\x00abcD32\x00 (['abcD3', 'abcD32']), expr: abcD3\x00abcD32\x00"..[[ (['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']) + == + 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']) + == + =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']) + == + 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']) + == + =abcD3 = + abcD32 + abcD3b]]) + + -- From now on we delete the buffer contents after each expect() to make + -- the next expect() easier to write. This is neccessary because null + -- bytes on a line by itself don't play well together with the dedent + -- function used in expect(). + execute('%delete') + execute([[$put ='{{{1 Appending lists with NL with setreg()']]) + execute([=[call SetReg('A', ["\n", 'abcA3l2'], 'l')]=]) + 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".. + '==\n'.. + 'abcA3\n'.. + 'abcA3c\n'.. + 'abcA32\n'.. + '\x00\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".. + '==\n'.. + '=abcB3\n'.. + 'abcB3l\n'.. + 'abcB3c\n'.. + '\x00\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".. + '==\n'.. + '=abcC3 =\n'.. + ' abcC3b\n'.. + ' abcC3l\n'.. + ' \x00\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".. + '==\n'.. + '=abcD3 =\n'.. + ' abcD32\n'.. + ' abcD3b\n'.. + ' \x00\n'.. + ' abcD3b50') + end) + + -- The tests for setting lists with NLs are split into seperate it() blocks + -- to make the expect() calls easier to write. Otherwise the null byte can + -- make trouble on a line on its own. + it('setting lists with NLs with setreg(), part 1', function() + execute('so test_eval_setup.vim') + 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".. + '==\n'.. + 'abcA4-0\n'.. + '\x00\n'.. + 'abcA4-2\x00\n'.. + '\x00abcA4-3\n'.. + 'abcA4-4\x00abcA4-4-2\n'.. + '==') + end) + + it('setting lists with NLs with setreg(), part 2', function() + execute('so test_eval_setup.vim') + 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".. + '==\n'.. + '=abcB4c-0\n'.. + '\x00\n'.. + 'abcB4c-2\x00\n'.. + '\x00abcB4c-3\n'.. + 'abcB4c-4\x00abcB4c-4-2=') + end) + + it('setting lists with NLs with setreg(), part 3', function() + execute('so test_eval_setup.vim') + 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".. + '==\n'.. + 'abcC4l-0\n'.. + '\x00\n'.. + 'abcC4l-2\x00\n'.. + '\x00abcC4l-3\n'.. + 'abcC4l-4\x00abcC4l-4-2\n'.. + '==') + end) + it('setting lists with NLs with setreg(), part 4', function() + execute('so test_eval_setup.vim') + 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".. + '==\n'.. + '=abcD4b-0 =\n'.. + ' \x00\n'.. + ' abcD4b-2\x00\n'.. + ' \x00abcD4b-3\n'.. + ' abcD4b-4\x00abcD4b-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".. + '==\n'.. + '=abcE4b10-0=\n'.. + ' \x00\n'.. + ' abcE4b10-2\x00\n'.. + ' \x00abcE4b10-3\n'.. + ' abcE4b10-4\x00abcE4b10-4-2') + end) + + it('search and expressions', function() + execute('so test_eval_setup.vim') + execute([=[call SetReg('/', ['abc/'])]=]) + execute([=[call SetReg('/', ["abc/\n"])]=]) + execute([=[call SetReg('=', ['"abc/"'])]=]) + execute([=[call SetReg('=', ["\"abc/\n\""])]=]) + expect([[ + + {{{2 setreg('/', ['abc/']) + /: 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"..[[']) + == + =abc/]]..'\x00'..[[= + {{{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'..[["'])]]) + end) + + if has_clipboard() then + it('system clipboard', function() + insert([[ + Some first line (this text was at the top of the old test_eval.in). + + Note: system clipboard is saved, changed and restored. + + clipboard contents + something else]]) + execute('so test_eval_setup.vim') + -- Save and restore system clipboard. + execute("let _clipreg = ['*', getreg('*'), getregtype('*')]") + execute('let _clipopt = &cb') + execute("let &cb='unnamed'") + execute('5y') + execute('AR *') + execute('tabdo :windo :echo "hi"') + execute('6y') + execute('AR *') + execute('let &cb=_clipopt') + execute("call call('setreg', _clipreg)") + expect([[ + Some first line (this text was at the top of the old test_eval.in). + + Note: system clipboard is saved, changed and restored. + + clipboard contents + something else + *: type V; value: clipboard contents]]..'\00'..[[ (['clipboard contents']), expr: clipboard contents]]..'\00'..[[ (['clipboard contents']) + *: type V; value: something else]]..'\00'..[[ (['something else']), expr: something else]]..'\00'..[[ (['something else'])]]) + end) + else + pending('system clipboard not available', function() end) + end + + it('errors', function() + source([[ + fun ErrExe(str) + call append('$', 'Executing '.a:str) + try + execute a:str + catch + $put =v:exception + endtry + endfun]]) + execute([[call ErrExe('call setreg()')]]) + execute([[call ErrExe('call setreg(1)')]]) + execute([[call ErrExe('call setreg(1, 2, 3, 4)')]]) + execute([=[call ErrExe('call setreg([], 2)')]=]) + execute([[call ErrExe('call setreg(1, {})')]]) + execute([=[call ErrExe('call setreg(1, 2, [])')]=]) + execute([=[call ErrExe('call setreg("/", ["1", "2"])')]=]) + execute([=[call ErrExe('call setreg("=", ["1", "2"])')]=]) + execute([=[call ErrExe('call setreg(1, ["", "", [], ""])')]=]) + expect([[ + + Executing call setreg() + Vim(call):E119: Not enough arguments for function: setreg + Executing call setreg(1) + Vim(call):E119: Not enough arguments for function: setreg + Executing call setreg(1, 2, 3, 4) + Vim(call):E118: Too many arguments for function: setreg + Executing call setreg([], 2) + Vim(call):E730: using List as a String + Executing call setreg(1, {}) + Vim(call):E731: using Dictionary as a String + Executing call setreg(1, 2, []) + Vim(call):E730: using List as a String + Executing call setreg("/", ["1", "2"]) + Vim(call):E883: search pattern and expression register may not contain two or more lines + Executing call setreg("=", ["1", "2"]) + Vim(call):E883: search pattern and expression register may not contain two or more lines + Executing call setreg(1, ["", "", [], ""]) + Vim(call):E730: using List as a String]]) + end) + + it('function name not starting with a capital', function() + execute('try') + execute(' func! g:test()') + execute(' echo "test"') + execute(' endfunc') + execute('catch') + execute(' let tmp = v:exception') + execute('endtry') + eq('Vim(function):E128: Function name must start with a capital or "s:": g:test()', eval('tmp')) + end) + + it('Function name followed by #', function() + execute('try') + execute(' func! test2() "#') + execute(' echo "test2"') + execute(' endfunc') + execute('catch') + execute(' let tmp = v:exception') + execute('endtry') + eq('Vim(function):E128: Function name must start with a capital or "s:": test2() "#', eval('tmp')) + end) + + it('function name includes a colon', function() + execute('try') + execute(' func! b:test()') + execute(' echo "test"') + execute(' endfunc') + execute('catch') + execute(' let tmp = v:exception') + execute('endtry') + eq('Vim(function):E128: Function name must start with a capital or "s:": b:test()', eval('tmp')) + end) + + it('function name starting with/without "g:", buffer-local funcref', function() + execute('function! g:Foo(n)') + execute(" $put ='called Foo(' . a:n . ')'") + execute('endfunction') + execute("let b:my_func = function('Foo')") + execute('call b:my_func(1)') + execute('echo g:Foo(2)') + execute('echo Foo(3)') + expect([[ + + called Foo(1) + called Foo(2) + called Foo(3)]]) + end) + + it('script-local function used in Funcref must exist', function() + source([[ + " Vim script used in test_eval.in. Needed for script-local function. + + func! s:Testje() + return "foo" + endfunc + + let Bar = function('s:Testje') + + $put ='s:Testje exists: ' . exists('s:Testje') + $put ='func s:Testje exists: ' . exists('*s:Testje') + $put ='Bar exists: ' . exists('Bar') + $put ='func Bar exists: ' . exists('*Bar') + ]]) + expect([[ + + s:Testje exists: 0 + func s:Testje exists: 1 + Bar exists: 1 + func Bar exists: 1]]) + end) + + it("using $ instead of '$' must give an error", function() + execute('try') + execute(" call append($, 'foobar')") + execute('catch') + execute(' let tmp = v:exception') + execute('endtry') + eq('Vim(call):E116: Invalid arguments for function append', eval('tmp')) + end) + + it('getcurpos/setpos', function() + insert([[ + 012345678 + 012345678 + + start:]]) + execute('/^012345678') + feed('6l') + execute('let sp = getcurpos()') + feed('0') + execute("call setpos('.', sp)") + feed('jyl') + execute('$put') + expect([[ + 012345678 + 012345678 + + start: + 6]]) + end) +end) diff --git a/test/functional/legacy/glob2regpat_spec.lua b/test/functional/legacy/glob2regpat_spec.lua new file mode 100644 index 0000000000..357128bcb6 --- /dev/null +++ b/test/functional/legacy/glob2regpat_spec.lua @@ -0,0 +1,22 @@ +-- Tests for signs + +local helpers = require('test.functional.helpers') +local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect +local eq, neq, eval = helpers.eq, helpers.neq, helpers.eval + +describe('glob2regpat()', function() + before_each(clear) + + it('handles invalid input', function() + execute('call glob2regpat(1.33)') + helpers.feed('<cr>') + neq(nil, string.find(eval('v:errmsg'), '^E806:')) + end) + it('returns ^$ for empty input', function() + eq('^$', eval("glob2regpat('')")) + end) + it('handles valid input', function() + eq('^foo\\.', eval("glob2regpat('foo.*')")) + eq('\\.vim$', eval("glob2regpat('*.vim')")) + end) +end) diff --git a/test/functional/legacy/listlbr_utf8_spec.lua b/test/functional/legacy/listlbr_utf8_spec.lua index 69e7b87a21..df0e817533 100644 --- a/test/functional/legacy/listlbr_utf8_spec.lua +++ b/test/functional/legacy/listlbr_utf8_spec.lua @@ -2,6 +2,7 @@ local helpers = require('test.functional.helpers') local source = helpers.source +local feed = helpers.feed local clear, expect = helpers.clear, helpers.expect describe('linebreak', function() @@ -32,16 +33,19 @@ describe('linebreak', function() $put =g:line wincmd p endfu + " let g:test ="Test 1: set linebreak + set list + fancy listchars" exe "set linebreak list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6" redraw! let line=ScreenChar(winwidth(0),4) call DoRecordScreen() + " let g:test ="Test 2: set nolinebreak list" set list nolinebreak redraw! let line=ScreenChar(winwidth(0),4) call DoRecordScreen() + " let g:test ="Test 3: set linebreak nolist" $put =\"\t*mask = nil;\" $ @@ -50,6 +54,7 @@ describe('linebreak', function() redraw! let line=ScreenChar(winwidth(0),4) call DoRecordScreen() + " let g:test ="Test 4: set linebreak list listchars and concealing" let c_defines=['#define ABCDE 1','#define ABCDEF 1','#define ABCDEFG 1','#define ABCDEFGH 1', '#define MSG_MODE_FILE 1','#define MSG_MODE_CONSOLE 2','#define MSG_MODE_FILE_AND_CONSOLE 3','#define MSG_MODE_FILE_THEN_CONSOLE 4'] call append('$', c_defines) @@ -61,6 +66,84 @@ describe('linebreak', function() redraw! let line=ScreenChar(winwidth(0),7) call DoRecordScreen() + " + let g:test ="Test 5: set linebreak list listchars and concealing part2" + let c_defines=['bbeeeeee ; some text'] + call append('$', c_defines) + $ + norm! zt + set nowrap ts=2 list linebreak listchars=tab:>- cole=2 concealcursor=n + syn clear + syn match meaning /;\s*\zs.*/ + syn match hasword /^\x\{8}/ contains=word + syn match word /\<\x\{8}\>/ contains=beginword,endword contained + syn match beginword /\<\x\x/ contained conceal + syn match endword /\x\{6}\>/ contained + hi meaning guibg=blue + hi beginword guibg=green + hi endword guibg=red + redraw! + let line=ScreenChar(winwidth(0),1) + call DoRecordScreen() + " + let g:test ="Test 6: Screenattributes for comment" + $put =g:test + call append('$', ' /* and some more */') + exe "set ft=c ts=7 linebreak list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6" + syntax on + hi SpecialKey term=underline ctermfg=red guifg=red + let attr=[] + nnoremap <expr> GG ":let attr += ['".screenattr(screenrow(),screencol())."']\n" + $ + norm! zt0 + ]]) + feed('GGlGGlGGlGGlGGlGGlGGlGGlGGlGGl') + source([[ + call append('$', ['ScreenAttributes for test6:']) + if attr[0] != attr[1] && attr[1] != attr[3] && attr[3] != attr[5] + call append('$', "Attribut 0 and 1 and 3 and 5 are different!") + else + call append('$', "Not all attributes are different") + endif + set cpo&vim linebreak selection=exclusive + let g:test ="Test 8: set linebreak with visual block mode and v_b_A and selection=exclusive and multibyte char" + $put =g:test + ]]) + feed("Golong line: <Esc>40afoobar <Esc>aTARGETÃ' at end<Esc>") + source([[ + exe "norm! $3B\<C-v>eAx\<Esc>" + " + let g:test ="Test 9: a multibyte sign and colorcolumn" + let attr=[] + let attr2=[] + $put ='' + $put ='a b c' + $put ='a b c' + set list nolinebreak cc=3 + ]]) + feed(':sign define foo text=<C-v>uff0b<CR>') + source([[ + sign place 1 name=foo line=50 buffer=2 + norm! 2kztj + let line1=line('.') + ]]) + feed('0GGlGGlGGlGGl') + source([[ + let line2=line('.') + let attr2=attr + let attr=[] + ]]) + feed('0GGlGGlGGlGGl') + source([[ + redraw! + let line=ScreenChar(winwidth(0),3) + call DoRecordScreen() + " expected: attr[2] is different because of colorcolumn + if attr[0] != attr2[0] || attr[1] != attr2[1] || attr[2] != attr2[2] + call append('$', "Screen attributes are different!") + else + call append('$', "Screen attributes are the same!") + endif ]]) -- Assert buffer contents. @@ -102,6 +185,25 @@ describe('linebreak', function() #define >CDEFGH>----1 #define >_FILE>--------->--->---1 #define >_CONSOLE>---------->---2 - #define >_FILE_AND_CONSOLE>---------3 ]]) + #define >_FILE_AND_CONSOLE>---------3 + bbeeeeee ; some text + + Test 5: set linebreak list listchars and concealing part2 + eeeeee>--->-;>some text + Test 6: Screenattributes for comment + /* and some more */ + ScreenAttributes for test6: + Attribut 0 and 1 and 3 and 5 are different! + Test 8: set linebreak with visual block mode and v_b_A and selection=exclusive and multibyte char + long line: foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar TARGETÃx' at end + + a b c + a b c + + Test 9: a multibyte sign and colorcolumn + ¶ + +a b c¶ + a b c¶ + Screen attributes are the same!]]) end) end) diff --git a/test/functional/legacy/quickfix_spec.lua b/test/functional/legacy/quickfix_spec.lua new file mode 100644 index 0000000000..7a9958b949 --- /dev/null +++ b/test/functional/legacy/quickfix_spec.lua @@ -0,0 +1,18 @@ +-- Test for the quickfix commands. + +local helpers = require('test.functional.helpers') +local insert, source = helpers.insert, helpers.source +local clear, expect = helpers.clear, helpers.expect + +describe('helpgrep', function() + before_each(clear) + + it('works', function() + source([[ + helpgrep quickfix + copen + " This wipes out the buffer, make sure that doesn't cause trouble. + cclose + ]]) + end) +end) diff --git a/test/functional/ui/mouse_spec.lua b/test/functional/ui/mouse_spec.lua index 30f37a7463..b3992c4a89 100644 --- a/test/functional/ui/mouse_spec.lua +++ b/test/functional/ui/mouse_spec.lua @@ -14,6 +14,7 @@ describe('Mouse input', function() before_each(function() clear() nvim('set_option', 'mouse', 'a') + nvim('set_option', 'listchars', 'eol:$') -- set mouset to very high value to ensure that even in valgrind/travis, -- nvim will still pick multiple clicks nvim('set_option', 'mouset', 5000) |