diff options
40 files changed, 744 insertions, 434 deletions
diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt index aab4b5c23d..a46f686d7c 100644 --- a/config/CMakeLists.txt +++ b/config/CMakeLists.txt @@ -5,6 +5,7 @@ include(CheckIncludeFiles) check_type_size("int" SIZEOF_INT) check_type_size("long" SIZEOF_LONG) +check_type_size("intmax_t" SIZEOF_INTMAX_T) check_type_size("off_t" SIZEOF_OFF_T) check_type_size("void *" SIZEOF_VOID_PTR) diff --git a/runtime/autoload/phpcomplete.vim b/runtime/autoload/phpcomplete.vim index c00e55cc1e..82ba894b2a 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: 2014 Jul 24 +" Last Change: 2014 Aug 10 " " OPTIONS: " @@ -94,9 +94,9 @@ function! phpcomplete#CompletePHP(findstart, base) " {{{ " Check if we are inside of PHP markup let pos = getpos('.') let phpbegin = searchpairpos('<?', '', '?>', 'bWn', - \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\|comment"') + \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"') let phpend = searchpairpos('<?', '', '?>', 'Wn', - \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\|comment"') + \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"') if phpbegin == [0,0] && phpend == [0,0] " We are outside of any PHP markup. Complete HTML @@ -803,7 +803,7 @@ function! phpcomplete#CompleteClassName(base, kinds, current_namespace, imports) endif let relative_name = namespace_part.tag.name " match base without the namespace part for namespaced base but not namespaced tags, for tagfiles with old ctags - if !has_key(tag, 'namespace') && index(kinds, tag.kind) != -1 && stridx(tag.name, base[len(namespace_part):]) == 0 + if !has_key(tag, 'namespace') && index(kinds, tag.kind) != -1 && stridx(tolower(tag.name), tolower(base[len(namespace_part):])) == 0 call add(no_namespace_matches, {'word': leading_slash.relative_name, 'kind': tag.kind, 'menu': tag.filename, 'info': tag.filename }) endif if has_key(tag, 'namespace') && index(kinds, tag.kind) != -1 && tag.namespace ==? namespace_for_class @@ -1607,6 +1607,7 @@ function! phpcomplete#GetClassName(start_line, context, current_namespace, impor for arg in args if arg =~# object.'\(,\|$\)' let classname_candidate = matchstr(arg, '\s*\zs'.class_name_pattern.'\ze\s\+'.object) + let [classname_candidate, class_candidate_namespace] = phpcomplete#ExpandClassName(classname_candidate, a:current_namespace, a:imports) break endif endfor @@ -1625,6 +1626,7 @@ function! phpcomplete#GetClassName(start_line, context, current_namespace, impor for param in docblock.params if param.name =~? object let classname_candidate = matchstr(param.type, class_name_pattern.'\(\[\]\)\?') + let [classname_candidate, class_candidate_namespace] = phpcomplete#ExpandClassName(classname_candidate, a:current_namespace, a:imports) break endif endfor @@ -1934,7 +1936,7 @@ function! phpcomplete#GetClassContentsStructure(file_path, file_lines, class_nam call search('{') let endline = line('.') - let content = join(getline(cfline, endline),"\n") + let content = join(getline(cfline, endline), "\n") " Catch extends if content =~? 'extends' let extends_class = matchstr(content, 'class\_s\+'.a:class_name.'\_s\+extends\_s\+\zs'.class_name_pattern.'\ze') diff --git a/runtime/doc/helphelp.txt b/runtime/doc/helphelp.txt index 52b61394e3..ca109cf4ca 100644 --- a/runtime/doc/helphelp.txt +++ b/runtime/doc/helphelp.txt @@ -1,4 +1,4 @@ -*helphelp.txt* For Vim version 7.4. Last change: 2012 Nov 28 +*helphelp.txt* For Vim version 7.4. Last change: 2014 Sep 19 VIM REFERENCE MANUAL by Bram Moolenaar @@ -97,7 +97,7 @@ Help on help files *helphelp* current file. See |help-translated|. *:helpc* *:helpclose* -:helpc[lose] Close one help window. +:helpc[lose] Close one help window, if there is one. *:helpg* *:helpgrep* :helpg[rep] {pattern}[@xx] diff --git a/runtime/doc/index.txt b/runtime/doc/index.txt index a4d25681ca..3eedb234f3 100644 --- a/runtime/doc/index.txt +++ b/runtime/doc/index.txt @@ -1,4 +1,4 @@ -*index.txt* For Vim version 7.4. Last change: 2014 Mar 25 +*index.txt* For Vim version 7.4. Last change: 2014 Sep 19 VIM REFERENCE MANUAL by Bram Moolenaar diff --git a/runtime/doc/spell.txt b/runtime/doc/spell.txt index 2ae0d27690..eb8f130833 100644 --- a/runtime/doc/spell.txt +++ b/runtime/doc/spell.txt @@ -1,4 +1,4 @@ -*spell.txt* For Vim version 7.4. Last change: 2014 Jul 02 +*spell.txt* For Vim version 7.4. Last change: 2014 Sep 19 VIM REFERENCE MANUAL by Bram Moolenaar diff --git a/runtime/doc/todo.txt b/runtime/doc/todo.txt index 2d5a89ce8e..06500e36a0 100644 --- a/runtime/doc/todo.txt +++ b/runtime/doc/todo.txt @@ -1,4 +1,4 @@ -*todo.txt* For Vim version 7.4. Last change: 2014 Sep 09 +*todo.txt* For Vim version 7.4. Last change: 2014 Sep 19 VIM REFERENCE MANUAL by Bram Moolenaar @@ -61,42 +61,11 @@ Breaks test_eval. Inefficient, can we only compute y_width when needed? Problem that a previous silent ":throw" causes a following try/catch not to work. (ZyX, 2013 Sep 28) -Update for Romanian spell file. (Vanilla Ice, 2014 Aug 13) -Still produces errors. -Add flag to ignore fifth argument of SFX. -Conversion from utf-8 to cp1250 can't be without errors. - -Patch to remove ETO_IGNORELANGUAGE, it causes Chinese characters not to show -up. (Paul Moore, 2014 Jul 30) -Should it depend on the Windows version? Waiting for feedback. -No longer needed after including DirectX patch? -Related to issue 255? - -Problem with linebreak, adds a test that fails. (Nazri Ramliy, 2014 Sep 6) - Patch to avoid problems with encoding conversion with diff.vim. (Yasuhiro Matsumoto, 2014 Sep 1. +Depends on current language, language of file can be different. -Patch by Marcin Szamotulski to add count to :close (2014 Aug 10, update Aug -14, Aug 30) - Make ":1close" close the first window. - Make ":+1close" close the next window. - Make ":-1close" close the previous window. -Can't easily close the help window, like ":pc" closes the preview window and -":ccl" closes the quickfix window. Add ":hclose". (Chris Gaal) -Patch for :helpclose, Christian Brabandt, 2010 Sep 6. - -Patch to fix line formatting bug. (Christian Brabandt, 2014 Sep 7) - -Patch to fix ml_get error. (Christian Brabandt, 2014 Sep 7) - -Patch by Marcin Szamotulski to add +cmd to buffer commands. -(2014 Aug 18) - -Patch to fix encoding of arguments when setting 'encoding'. (Yasuhiro -Matsumoto, 2014 Sep 4) - -Patch to fix that system() with empty input fails. (Olaf Dabrunz, 2014 Aug 19) +Patch for C/C++ syntax string handling. (Brian Bi, 2014 Sep 13) When using a visual selection of multiple words and doing CTRL-W_] it jumps to the tag matching the word under the cursor, not the selected text. @@ -105,6 +74,9 @@ Patch by Christian, 2014 Aug 8. Completion for :buf does not use 'wildignorecase'. (Akshay H, 2014 May 31) +'backupcopy' should be global-local, so that some files can be written in a +different way. Patch by Christian, 2014 Sep 17. + Patch to handle list with some items locked. (ZyX, 2014 Aug 17) Prefer the second solution. @@ -113,6 +85,13 @@ Issue 252. Patch by Christian, 2014 Aug 26. ":cd C:\Windows\System32\drivers\etc*" does not work, even though the directory exists. (Sergio Gallelli, 2013 Dec 29) +Patch by Marcin Szamotulski to add count to :close (2014 Aug 10, update Aug +14, Aug 30) + Make ":1close" close the first window. + Make ":+1close" close the next window. + Make ":-1close" close the previous window. +Doesn't look right, asked for updates. + Patch to add a special key name for K_CURSORHOLD. (Hirohito Higashi, 2014 Aug 10) @@ -129,6 +108,9 @@ inconsistent with the documentation. MS-Windows: Crash opening very long file name starting with "\\". (Christian Brock, 2012 Jun 29) +ml_updatechunk() is slow when retrying for another encoding. (John Little, +2014 Sep 11) + Syntax highlighting slow (hangs) in SASS file. (Niek Bosch, 2013 Aug 21) Patch to allow for a different icon on MS-Windows. (Yasuhiro Matsumoto, 2014 @@ -136,11 +118,16 @@ Sep 7). Adding "~" to 'cdpath' doesn't work for completion? (Davido, 2013 Aug 19) +Patch to make closed folds line up. (Charles Campbell, 2014 Sep 12) + "hi link" does not respect groups with GUI settings only. (Mark Lodato, 2014 Jun 8) No error for missing endwhile. (ZyX, 2014 Mar 20) +start_global_changes() plus end_global_changes() causes problem for +clip_unnamed_plus. (Jason Pleau, 2014 Sep 12) + Patch to add :arglocal and :arglists. (Marcin Szamotulski, 2014 Aug 6) PHP syntax is extremely slow. (Anhad Jai Singh, 2014 Jan 19) @@ -238,7 +225,8 @@ Patch to support sorting on floating point number. (Alex Jakushev, 2010 Oct Patch to support expression argument to sort() instead of a function name. Yasuhiro Matsumoto, 2013 May 31. -Or should we add a more general mechanism, like lambda functions? +Or should we add a more general mechanism, like a lambda() function? +Patch by Yasuhiro Matsumoto, 2014 Sep 16. Patch for XDG base directory support. (Jean François Bignolles, 2014 Mar 4) Remark on the docs. Should not be a compile time feature. But then what? diff --git a/runtime/indent/ada.vim b/runtime/indent/ada.vim index a553756715..575f326454 100644 --- a/runtime/indent/ada.vim +++ b/runtime/indent/ada.vim @@ -148,7 +148,7 @@ function s:StatementIndent( current_indent, prev_lnum ) " Get previous non-blank/non-comment-only line while 1 let line = substitute( getline(lnum), g:ada#Comment, '', '' ) - + if line !~ '^\s*$' && line !~ '^\s*#' break endif diff --git a/runtime/indent/vim.vim b/runtime/indent/vim.vim index 8c215733b3..ff4af027b4 100644 --- a/runtime/indent/vim.vim +++ b/runtime/indent/vim.vim @@ -1,7 +1,7 @@ " Vim indent file " Language: Vim script " Maintainer: Bram Moolenaar <Bram@vim.org> -" Last Change: 2012 Aug 02 +" Last Change: 2014 Sep 19 " Only load this indent file when no other was loaded. if exists("b:did_indent") @@ -37,7 +37,8 @@ function GetVimIndentIntern() " If the current line doesn't start with '\' and below a line that starts " with '\', use the indent of the line above it. - if getline(v:lnum) !~ '^\s*\\' + let cur_text = getline(v:lnum) + if cur_text !~ '^\s*\\' while lnum > 0 && getline(lnum) =~ '^\s*\\' let lnum = lnum - 1 endwhile @@ -47,27 +48,30 @@ function GetVimIndentIntern() if lnum == 0 return 0 endif + let prev_text = getline(lnum) " Add a 'shiftwidth' after :if, :while, :try, :catch, :finally, :function " and :else. Add it three times for a line that starts with '\' after " a line that doesn't (or g:vim_indent_cont if it exists). let ind = indent(lnum) - if getline(v:lnum) =~ '^\s*\\' && v:lnum > 1 && getline(lnum) !~ '^\s*\\' + if cur_text =~ '^\s*\\' && v:lnum > 1 && prev_text !~ '^\s*\\' if exists("g:vim_indent_cont") let ind = ind + g:vim_indent_cont else let ind = ind + &sw * 3 endif - elseif getline(lnum) =~ '^\s*aug\%[roup]' && getline(lnum) !~ '^\s*aug\%[roup]\s*!\=\s\+END' + elseif prev_text =~ '^\s*aug\%[roup]' && prev_text !~ '^\s*aug\%[roup]\s*!\=\s\+END' let ind = ind + &sw else - let line = getline(lnum) - let i = match(line, '\(^\||\)\s*\(if\|wh\%[ile]\|for\|try\|cat\%[ch]\|fina\%[lly]\|fu\%[nction]\|el\%[seif]\)\>') - if i >= 0 - let ind += &sw - if strpart(line, i, 1) == '|' && has('syntax_items') - \ && synIDattr(synID(lnum, i, 1), "name") =~ '\(Comment\|String\)$' - let ind -= &sw + " A line starting with :au does not increment/decrement indent. + if prev_text !~ '^\s*au\%[tocmd]' + let i = match(prev_text, '\(^\||\)\s*\(if\|wh\%[ile]\|for\|try\|cat\%[ch]\|fina\%[lly]\|fu\%[nction]\|el\%[seif]\)\>') + if i >= 0 + let ind += &sw + if strpart(prev_text, i, 1) == '|' && has('syntax_items') + \ && synIDattr(synID(lnum, i, 1), "name") =~ '\(Comment\|String\)$' + let ind -= &sw + endif endif endif endif @@ -75,9 +79,8 @@ function GetVimIndentIntern() " If the previous line contains an "end" after a pipe, but not in an ":au" " command. And not when there is a backslash before the pipe. " And when syntax HL is enabled avoid a match inside a string. - let line = getline(lnum) - let i = match(line, '[^\\]|\s*\(ene\@!\)') - if i > 0 && line !~ '^\s*au\%[tocmd]' + let i = match(prev_text, '[^\\]|\s*\(ene\@!\)') + if i > 0 && prev_text !~ '^\s*au\%[tocmd]' if !has('syntax_items') || synIDattr(synID(lnum, i + 2, 1), "name") !~ '\(Comment\|String\)$' let ind = ind - &sw endif @@ -86,7 +89,7 @@ function GetVimIndentIntern() " Subtract a 'shiftwidth' on a :endif, :endwhile, :catch, :finally, :endtry, " :endfun, :else and :augroup END. - if getline(v:lnum) =~ '^\s*\(ene\@!\|cat\|fina\|el\|aug\%[roup]\s*!\=\s\+END\)' + if cur_text =~ '^\s*\(ene\@!\|cat\|fina\|el\|aug\%[roup]\s*!\=\s\+END\)' let ind = ind - &sw endif diff --git a/runtime/syntax/php.vim b/runtime/syntax/php.vim index 26d60a9382..860181e0e6 100644 --- a/runtime/syntax/php.vim +++ b/runtime/syntax/php.vim @@ -1,7 +1,7 @@ " Vim syntax file " Language: php PHP 3/4/5 " Maintainer: Jason Woofenden <jason@jasonwoof.com> -" Last Change: Aug 28, 2013 +" Last Change: Sep 18, 2014 " URL: https://gitorious.org/jasonwoof/vim-syntax/blobs/master/php.vim " Former Maintainers: Peter Hodge <toomuchphp-vim@yahoo.com> " Debian VIM Maintainers <pkg-vim-maintainers@lists.alioth.debian.org> @@ -123,7 +123,11 @@ syn keyword phpEnvVar GATEWAY_INTERFACE SERVER_NAME SERVER_SOFTWARE SERVER_PROTO syn keyword phpIntVar GLOBALS PHP_ERRMSG PHP_SELF HTTP_GET_VARS HTTP_POST_VARS HTTP_COOKIE_VARS HTTP_POST_FILES HTTP_ENV_VARS HTTP_SERVER_VARS HTTP_SESSION_VARS HTTP_RAW_POST_DATA HTTP_STATE_VARS _GET _POST _COOKIE _FILES _SERVER _ENV _SERVER _REQUEST _SESSION contained " Constants -syn keyword phpCoreConstant PHP_VERSION PHP_OS DEFAULT_INCLUDE_PATH PEAR_INSTALL_DIR PEAR_EXTENSION_DIR PHP_EXTENSION_DIR PHP_BINDIR PHP_LIBDIR PHP_DATADIR PHP_SYSCONFDIR PHP_LOCALSTATEDIR PHP_CONFIG_FILE_PATH PHP_OUTPUT_HANDLER_START PHP_OUTPUT_HANDLER_CONT PHP_OUTPUT_HANDLER_END E_ERROR E_WARNING E_PARSE E_NOTICE E_CORE_ERROR E_CORE_WARNING E_COMPILE_ERROR E_COMPILE_WARNING E_USER_ERROR E_USER_WARNING E_USER_NOTICE E_ALL contained +syn keyword phpCoreConstant PHP_VERSION PHP_OS DEFAULT_INCLUDE_PATH PEAR_INSTALL_DIR PEAR_EXTENSION_DIR PHP_EXTENSION_DIR PHP_BINDIR PHP_LIBDIR PHP_DATADIR PHP_SYSCONFDIR PHP_LOCALSTATEDIR PHP_CONFIG_FILE_PATH PHP_OUTPUT_HANDLER_START PHP_OUTPUT_HANDLER_CONT PHP_OUTPUT_HANDLER_END contained + +" Predefined constants +" Generated by: curl -q http://php.net/manual/en/errorfunc.constants.php | grep -oP 'E_\w+' | sort -u +syn keyword phpCoreConstant E_ALL E_COMPILE_ERROR E_COMPILE_WARNING E_CORE_ERROR E_CORE_WARNING E_DEPRECATED E_ERROR E_NOTICE E_PARSE E_RECOVERABLE_ERROR E_STRICT E_USER_DEPRECATED E_USER_ERROR E_USER_NOTICE E_USER_WARNING E_WARNING contained syn case ignore @@ -502,11 +506,6 @@ syn keyword phpStructure trait " Some of these changes (highlighting isset/unset/echo etc) are not so " critical, but they make things more colourful. :-) -" highlight constant E_STRICT -syntax case match -syntax keyword phpCoreConstant E_STRICT contained -syntax case ignore - " different syntax highlighting for 'echo', 'print', 'switch', 'die' and 'list' keywords " to better indicate what they are. syntax keyword phpDefine echo print contained diff --git a/runtime/syntax/sisu.vim b/runtime/syntax/sisu.vim index 23d73254eb..0e0f2dbe0a 100644 --- a/runtime/syntax/sisu.vim +++ b/runtime/syntax/sisu.vim @@ -1,8 +1,9 @@ " SiSU Vim syntax file -" SiSU Maintainer: Ralph Amissah <ralph@amissah.com> -" SiSU Markup: SiSU (sisu-4.0.9) -" Last Change: 2013-02-22 -" URL (sisu-4.1.0): <http://git.sisudoc.org/?p=code/sisu.git;a=blob;f=data/sisu/conf/editor-syntax-etc/vim/syntax/sisu.vim;hb=HEAD> +" SiSU Maintainer: Ralph Amissah <ralph.amissah@gmail.com> +" SiSU Markup: SiSU (sisu-5.6.7) +" Last Change: 2014-09-14 +" URL: <http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=blob;f=data/sisu/conf/editor-syntax-etc/vim/syntax/sisu.vim;hb=HEAD> +" <http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=blob_plain;f=data/sisu/conf/editor-syntax-etc/vim/syntax/sisu.vim;hb=HEAD> "(originally looked at Ruby Vim by Mirko Nasato) if version < 600 @@ -23,15 +24,14 @@ if !exists("sisu_no_identifiers") syn match sisu_break contains=@NoSpell " \\\\\( \|$\)\|<br>\|<br />" syn match sisu_control contains=@NoSpell "^\(-\\\\-\|=\\\\=\|-\.\.-\|<:p[bn]>\)\s*$" syn match sisu_control contains=@NoSpell "^<:\(bo\|---\)>\s*$" + syn match sisu_marktail contains=@NoSpell "^--[+~-]#\s*$" syn match sisu_marktail "[~-]#" syn match sisu_control "\"" syn match sisu_underline "\(^\| \)_[a-zA-Z0-9]\+_\([ .,]\|$\)" syn match sisu_number contains=@NoSpell "[0-9a-f]\{32\}\|[0-9a-f]\{64\}" syn match sisu_link contains=@NoSpell "\(_\?https\?://\|\.\.\/\)\S\+" syn match sisu_link " \*\~\S\+" - syn match sisu_action "^<:insert\d\+>" - syn match sisu_require contains=@NoSpell "^<<\s*[a-zA-Z0-9^._-]\+\.ss[it]$" - syn match sisu_require contains=@NoSpell "^<<{[a-zA-Z0-9^._-]\+\.ss[it]}$" + syn match sisu_require contains=@NoSpell "^<<\s*[a-zA-Z0-9^./_-]\+\.ss[it]$" syn match sisu_structure "^:A\~$" "% "Document Sub Headers: @@ -44,6 +44,8 @@ if !exists("sisu_no_identifiers") syn match sisu_sub_header_original "^\s\+:\(publisher\|date\|language\|lang_char\|institution\|nationality\|source\):\s" syn match sisu_sub_header_make "^\s\+:\(headings\|num_top\|breaks\|language\|italics\|bold\|emphasis\|substitute\|omit\|plaintext_wrap\|texpdf_font_mono\|texpdf_font\|stamp\|promo\|ad\|manpage\|home_button_text\|home_button_image\|cover_image\|footer\):\s" syn match sisu_sub_header_notes "^\s\+:\(description\|abstract\|comment\|coverage\|relation\|source\|history\|type\|format\|prefix\|prefix_[ab]\|suffix\):\s" + syn match sisu_within_index_ignore "\S\+[:;]\(\s\+\|$\)" + syn match sisu_within_index "[:|;]\|+\d\+" "% "semantic markers: (ignore) syn match sisu_sem_marker ";{\|};[a-z._]*[a-z]" @@ -93,17 +95,25 @@ syn region sisu_header_content contains=sisu_error,sisu_comment,sisu_break,sisu_ syn region sisu_header_content contains=sisu_error,sisu_comment,sisu_break,sisu_link,sisu_sub_header_make matchgroup=sisu_header start="^[@]make:[+-]\?\(\s\|\n\)"rs=e-1 end="\n$" "% "Headings: -syn region sisu_heading contains=sisu_mark_endnote,sisu_content_endnote,sisu_marktail,sisu_strikeout,sisu_number,sisu_bold,sisu_control,sisu_identifier,sisu_ocn,sisu_error,sisu_error_wspace matchgroup=sisu_structure start="^\([1-8]\|:\?[A-C]\)\~\(\S\+\|[^-]\)" end="$" +syn region sisu_heading contains=sisu_mark_endnote,sisu_content_endnote,sisu_marktail,sisu_strikeout,sisu_number,sisu_bold,sisu_control,sisu_identifier,sisu_ocn,sisu_error,sisu_error_wspace matchgroup=sisu_structure start="^\([1-4]\|:\?[A-D]\)\~\(\S\+\|[^-]\)" end="$" "% "Block Group Text: " table syn region sisu_content_alt contains=sisu_strikeout,sisu_number,sisu_bold,sisu_control,sisu_identifier,sisu_error matchgroup=sisu_contain start="^table{.\+" end="}table" " table +syn region sisu_content_alt contains=sisu_strikeout,sisu_number,sisu_bold,sisu_control,sisu_identifier,sisu_error matchgroup=sisu_contain start="^```\s\+table" end="^```\(\s\|$\)" syn region sisu_content_alt contains=sisu_strikeout,sisu_number,sisu_bold,sisu_control,sisu_identifier,sisu_error matchgroup=sisu_contain start="^{\(t\|table\)\(\~h\)\?\(\sc[0-9]\+;\)\?[0-9; ]*}" end="\n$" " block, group, poem, alt -syn region sisu_content_alt contains=sisu_mark_endnote,sisu_content_endnote,sisu_link,sisu_mark,sisu_strikeout,sisu_number,sisu_control,sisu_identifier,sisu_error matchgroup=sisu_contain start="^\(block\|group\|poem\|alt\){" end="^}\(block\|group\|poem\|alt\)" +syn region sisu_content_alt contains=sisu_mark_endnote,sisu_content_endnote,sisu_link,sisu_mark,sisu_strikeout,sisu_number,sisu_control,sisu_identifier,sisu_error matchgroup=sisu_contain start="^\(block\|group\|poem\|alt\){" end="^}\1" +syn region sisu_content_alt contains=sisu_mark_endnote,sisu_content_endnote,sisu_link,sisu_mark,sisu_strikeout,sisu_number,sisu_control,sisu_identifier,sisu_error matchgroup=sisu_contain start="^```\s\+\(block\|group\|poem\|alt\)" end="^```\(\s\|$\)" +" box +syn region sisu_content_alt contains=sisu_mark_endnote,sisu_content_endnote,sisu_link,sisu_mark,sisu_strikeout,sisu_number,sisu_control,sisu_identifier,sisu_error matchgroup=sisu_contain start="^box\(\.[a-z]\+\)\?{" end="^}box" +syn region sisu_content_alt contains=sisu_mark_endnote,sisu_content_endnote,sisu_link,sisu_mark,sisu_strikeout,sisu_number,sisu_control,sisu_identifier,sisu_error matchgroup=sisu_contain start="^```\s\+\box\(\.[a-z]\+\)\?" end="^```\(\s\|$\)" " code -syn region sisu_content_alt contains=sisu_error matchgroup=sisu_contain start="^code{" end="^}code" +syn region sisu_content_alt contains=sisu_error,@NoSpell matchgroup=sisu_contain start="^code\(\.[a-z][0-9a-z_]\+\)\?{" end="^}code" +syn region sisu_content_alt contains=sisu_error,@NoSpell matchgroup=sisu_contain start="^```\s\+code\(\.[a-z][0-9a-z_]\+\)\?" end="^```\(\s\|$\)" +" quote +syn region sisu_normal contains=sisu_fontface,sisu_bold,sisu_control,sisu_identifier,sisu_content_endnote,sisu_mark_endnote,sisu_link,sisu_sem_block,sisu_sem_content,sisu_sem_marker_block,sisu_sem_marker,sisu_sem_ex_marker_block,sisu_sem_ex_marker,sisu_linked,sisu_error,sisu_error_wspace matchgroup=sisu_contain start="^```\s\+quote" end="^```\(\s\|$\)" "% "Endnotes: " regular endnote or asterisk or plus sign endnote @@ -138,7 +148,7 @@ syn region sisu_normal contains=sisu_strikeout,sisu_identifier,sisu_content_endn "% "Font Face Curly Brackets: "syn region sisu_identifier contains=sisu_strikeout,sisu_number,sisu_control,sisu_identifier,sisu_error matchgroup=sisu_sem start="\S\+:{" end="}:[^<>,.!?:; ]\+" oneline " book index: -syn region sisu_index matchgroup=sisu_index_block start="^={" end="}" +syn region sisu_index contains=sisu_within_index_ignore,sisu_within_index matchgroup=sisu_index_block start="^={" end="}" " emphasis: syn region sisu_bold contains=sisu_strikeout,sisu_number,sisu_bold,sisu_control,sisu_identifier,sisu_error matchgroup=sisu_fontface start="\*{" end="}\*" " bold: @@ -246,6 +256,8 @@ hi def link sisu_index SpecialKey hi def link sisu_index_block Visual hi def link sisu_content_endnote Special hi def link sisu_control Delimiter +hi def link sisu_within_index Delimiter +hi def link sisu_within_index_ignore SpecialKey hi def link sisu_ocn Include hi def link sisu_number Number hi def link sisu_identifier Function diff --git a/scripts/genex_cmds.lua b/scripts/genex_cmds.lua index 7fd258a6c3..75739bda74 100644 --- a/scripts/genex_cmds.lua +++ b/scripts/genex_cmds.lua @@ -67,7 +67,7 @@ for i, cmd in ipairs(defs) do [%s] = { .cmd_name = (char_u *) "%s", .cmd_func = &%s, - .cmd_argt = %uL + .cmd_argt = %u }]], enumname, cmd.command, cmd.func, cmd.flags)) end defsfile:write([[ diff --git a/scripts/vim-patch.sh b/scripts/vim-patch.sh index f6b4793184..4c9a141bd2 100755 --- a/scripts/vim-patch.sh +++ b/scripts/vim-patch.sh @@ -7,114 +7,189 @@ NEOVIM_SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" VIM_SOURCE_DIR_DEFAULT=${NEOVIM_SOURCE_DIR}/.vim-src VIM_SOURCE_DIR="${VIM_SOURCE_DIR:-${VIM_SOURCE_DIR_DEFAULT}}" -if [[ ${#} != 1 ]]; then +usage() { >&2 echo "Helper script for porting Vim patches. For more information," >&2 echo "see https://github.com/neovim/neovim/wiki/Merging-patches-from-upstream-vim." >&2 echo - >&2 echo "Usage: ${0} vim-revision" + >&2 echo "Usage: ${0} [option]" + >&2 echo " ${0} vim-revision" + >&2 echo + >&2 echo "Options:" + >&2 echo " --help Show this message." + >&2 echo " --list Show list of Vim patches missing from Neovim." + >&2 echo >&2 echo "vim-revision can be a version number in format '7.4.xxx'" >&2 echo "or a Mercurial commit hash." >&2 echo >&2 echo "Set VIM_SOURCE_DIR to change where Vim's sources are stored." >&2 echo "The default is '${VIM_SOURCE_DIR_DEFAULT}'." +} + +get_vim_sources() { + echo "Retrieving Vim sources." + if [[ ! -d ${VIM_SOURCE_DIR} ]]; then + echo "Cloning Vim sources into '${VIM_SOURCE_DIR}'." + hg clone https://code.google.com/p/vim ${VIM_SOURCE_DIR} + cd ${VIM_SOURCE_DIR} + else + echo "Updating Vim sources in '${VIM_SOURCE_DIR}'." + cd ${VIM_SOURCE_DIR} + hg pull --update && + echo "✔ Updated Vim sources." || + echo "✘ Could not update Vim sources; ignoring error." + fi +} + +get_vim_patch() { + if [[ "${1}" =~ [0-9]\.[0-9]\.[0-9]{3,4} ]]; then + # Interpret parameter as version number. + vim_version="${1}" + vim_commit="v${1//./-}" + strip_commit_line=true + else + # Interpret parameter as commit hash. + vim_version="${1:0:7}" + vim_commit="${1}" + strip_commit_line=false + fi + + hg log --rev ${vim_commit} >/dev/null 2>&1 || { + >&2 echo "✘ Couldn't find Vim revision '${vim_commit}'." + exit 3 + } + echo + echo "✔ Found Vim revision '${vim_commit}'." + + # Collect patch details and store into variables. + vim_full="$(hg log --patch --git --verbose --rev ${vim_commit})" + vim_message="$(hg log --template "{desc}" --rev ${vim_commit})" + if [[ "${strip_commit_line}" == "true" ]]; then + # Remove first line of commit message. + vim_message="$(echo "${vim_message}" | sed -e '1d')" + fi + vim_diff="$(hg diff --show-function --git --change ${vim_commit} \ + | sed -e 's/\( [ab]\/src\)/\1\/nvim/g')" # Change directory to src/nvim. + neovim_message=" + vim-patch:${vim_version} + + ${vim_message} + + https://code.google.com/p/vim/source/detail?r=${vim_commit}" + neovim_pr=" + \`\`\` + ${vim_message} + \`\`\` + + https://code.google.com/p/vim/source/detail?r=${vim_commit} + + Original patch: + + \`\`\`diff + ${vim_diff} + \`\`\`" + neovim_branch="vim-${vim_version}" + + echo + echo "Creating Git branch." + cd ${NEOVIM_SOURCE_DIR} + output="$(git checkout -b "${neovim_branch}" 2>&1)" && + echo "✔ ${output}" || + (echo "✘ ${output}"; false) + + echo + echo "Creating empty commit with correct commit message." + output="$(git commit --allow-empty --file 2>&1 - <<< "${neovim_message}")" && + echo "✔ ${output}" || + (echo "✘ ${output}"; false) + + echo + echo "Creating files." + echo "${vim_diff}" > ${NEOVIM_SOURCE_DIR}/${neovim_branch}.diff + echo "✔ Saved patch to '${NEOVIM_SOURCE_DIR}/${neovim_branch}.diff'." + echo "${vim_full}" > ${NEOVIM_SOURCE_DIR}/${neovim_branch}.patch + echo "✔ Saved full commit details to '${NEOVIM_SOURCE_DIR}/${neovim_branch}.patch'." + echo "${neovim_pr}" > ${NEOVIM_SOURCE_DIR}/${neovim_branch}.pr + echo "✔ Saved suggested PR description to '${NEOVIM_SOURCE_DIR}/${neovim_branch}.pr'." + echo "You can use 'git clean' to remove these files when you're done." + + echo + echo "Instructions:" + echo + echo " Proceed to port the patch." + echo " You might want to try 'patch -p1 < ${neovim_branch}.diff' first." + echo + echo " Stage your changes ('git add ...') and use 'git commit --amend' to commit." + echo + echo " Push your changes with 'git push origin ${neovim_branch}' and create a" + echo " pull request called '[RFC] vim-patch:${vim_version}'. You might want " + echo " to use the text in '${neovim_branch}.pr' as the description of this pull request." + echo + echo " See https://github.com/neovim/neovim/wiki/Merging-patches-from-upstream-vim" + echo " for more information." +} + +list_vim_patches() { + echo + echo "Vim patches missing from Neovim:" + + # Get vim patches and runtime file updates. + # Start from 7.4.442. The runtime was re-integrated from 7.4.384, but + # runtime patches before between 384 and 442 have already been ported + # to Neovim as of the creation of this script. + local vim_commits=$(cd ${VIM_SOURCE_DIR} && \ + hg log --removed --template='{if(startswith("Added tag", firstline(desc)), + "{latesttag}\n", + "{if(startswith(\"updated for version\", firstline(desc)), + \"\", + \"{node}\n\")}")}' -r tip:v7-4-442) + # Append remaining vim patches. + # Start from 7.4.160, where Neovim was forked. + local vim_old_commits=$(cd ${VIM_SOURCE_DIR} && \ + hg log --removed --template='{if(startswith("Added tag", + firstline(desc)), + "{latesttag}\n")}' -r v7-4-442:v7-4-161) + + local vim_commit + for vim_commit in ${vim_commits} ${vim_old_commits}; do + local is_missing + if [[ "${vim_commit}" =~ v([0-9]-[0-9]-([0-9]{3,4})) ]]; then + local patch_number="${BASH_REMATCH[2]}" + # "Proper" 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]//-/.}" + else + # Untagged Vim patch, e.g. runtime updates. + # Check Neovim log: + is_missing="$(cd ${NEOVIM_SOURCE_DIR} && + git log -1 --no-merges --grep="vim\-patch:${vim_commit:0:7}" --pretty=format:"false")" + fi + + if [[ "${is_missing}" != "false" ]]; then + echo " • ${vim_commit}" + fi + done + + echo + echo "Instructions:" + echo + echo " To port one of the above patches to Neovim, execute" + echo " this script with the patch revision as argument." + echo + echo " Examples: './scripts/vim-patch.sh 7.4.487'" + echo " './scripts/vim-patch.sh 1e8ebf870720e7b671f98f22d653009826304c4f'" +} + +if [[ ${#} != 1 || "${1}" == "--help" ]]; then + usage exit 1 fi -echo "Retrieving Vim sources." -if [[ ! -d ${VIM_SOURCE_DIR} ]]; then - echo "Cloning Vim sources into '${VIM_SOURCE_DIR}'." - hg clone https://code.google.com/p/vim ${VIM_SOURCE_DIR} - cd ${VIM_SOURCE_DIR} -else - echo "Updating Vim sources in '${VIM_SOURCE_DIR}'." - cd ${VIM_SOURCE_DIR} - hg pull --update || echo "✘ Could not update Vim sources." -fi +get_vim_sources -if [[ "${1}" =~ [0-9]\.[0-9]\.[0-9]{3,4} ]]; then - # Interpret parameter as version number. - vim_version="${1}" - vim_commit="v${1//./-}" - strip_commit_line=true +if [[ "${1}" == "--list" ]]; then + list_vim_patches else - # Interpret parameter as commit hash. - vim_version="${1:0:7}" - vim_commit="${1}" - strip_commit_line=false -fi - -hg log --rev ${vim_commit} >/dev/null 2>&1 || { - >&2 echo "✘ Couldn't find Vim revision '${vim_commit}'." - exit 3 -} -echo "✔ Found Vim revision '${vim_commit}'." - -# Collect patch details and store into variables. -vim_full="$(hg log --patch --git --verbose --rev ${vim_commit})" -vim_message="$(hg log --template "{desc}" --rev ${vim_commit})" -if [[ "${strip_commit_line}" == "true" ]]; then - # Remove first line of commit message. - vim_message="$(echo "${vim_message}" | sed -e '1d')" + get_vim_patch ${1} fi -vim_diff="$(hg diff --show-function --git --change ${vim_commit} \ - | sed -e 's/\( [ab]\/src\)/\1\/nvim/g')" # Change directory to src/nvim. -neovim_message=" -vim-patch:${vim_version} - -${vim_message} - -https://code.google.com/p/vim/source/detail?r=${vim_commit}" -neovim_pr=" -\`\`\` -${vim_message} -\`\`\` - -https://code.google.com/p/vim/source/detail?r=${vim_commit} - -Original patch: - -\`\`\`diff -${vim_diff} -\`\`\`" -neovim_branch="vim-${vim_version}" - -echo -echo "Creating Git branch." -cd ${NEOVIM_SOURCE_DIR} -echo -n "✘ " -# 'git checkout -b' writes to stderr in case of success :-( -# Re-add newline (stripped by echo -n) in error case. -git checkout -b "${neovim_branch}" 2>&1 | xargs echo -n || (echo; false) -echo -n "." # Add trailing dot. -echo -e "\r✔ " # Replace ✘ with ✔ - -echo -echo "Creating empty commit with correct commit message." -echo -n "✘ " -git commit --allow-empty --file - <<< "${neovim_message}" | xargs echo -n -echo -e "\r✔ " # Replace ✘ with ✔ - -echo -echo "Creating files." -echo "${vim_diff}" > ${NEOVIM_SOURCE_DIR}/${neovim_branch}.diff -echo "✔ Saved patch to '${NEOVIM_SOURCE_DIR}/${neovim_branch}.diff'." -echo "${vim_full}" > ${NEOVIM_SOURCE_DIR}/${neovim_branch}.patch -echo "✔ Saved full commit details to '${NEOVIM_SOURCE_DIR}/${neovim_branch}.patch'." -echo "${neovim_pr}" > ${NEOVIM_SOURCE_DIR}/${neovim_branch}.pr -echo "✔ Saved suggested PR description to '${NEOVIM_SOURCE_DIR}/${neovim_branch}.pr'." -echo "You can use 'git clean' to remove these files when you're done." - -echo -echo "Instructions:" -echo -echo " Proceed to port the patch." -echo " You might want to try 'patch -p1 < ${neovim_branch}.diff' first." -echo -echo " Stage your changes ('git add ...') and use 'git commit --amend' to commit." -echo -echo " Push your changes with 'git push origin ${neovim_branch}' and create a" -echo " pull request called '[RFC] vim-patch:${vim_version}'. You might want " -echo " to use the text in '${neovim_branch}.pr' as the description of this pull request." -echo -echo " See https://github.com/neovim/neovim/wiki/Merging-patches-from-upstream-vim" -echo " for more information." diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index 5fe52e3323..4acc4b172d 100644 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -72,7 +72,6 @@ set(CONV_SOURCES move.c normal.c ops.c - option.c os_unix.c path.c popupmnu.c diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index ff5f7853a3..d9684db3bc 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -2,6 +2,7 @@ #define NVIM_BUFFER_DEFS_H #include <stdbool.h> +#include <stdint.h> // for FILE #include <stdio.h> @@ -626,12 +627,12 @@ struct file_buffer { char_u *b_p_def; /* 'define' local value */ char_u *b_p_inc; /* 'include' */ char_u *b_p_inex; /* 'includeexpr' */ - long_u b_p_inex_flags; /* flags for 'includeexpr' */ + uint32_t b_p_inex_flags; /* flags for 'includeexpr' */ char_u *b_p_inde; /* 'indentexpr' */ - long_u b_p_inde_flags; /* flags for 'indentexpr' */ + uint32_t b_p_inde_flags; /* flags for 'indentexpr' */ char_u *b_p_indk; /* 'indentkeys' */ char_u *b_p_fex; /* 'formatexpr' */ - long_u b_p_fex_flags; /* flags for 'formatexpr' */ + uint32_t b_p_fex_flags; /* flags for 'formatexpr' */ char_u *b_p_kp; /* 'keywordprg' */ int b_p_lisp; /* 'lisp' */ char_u *b_p_mps; /* 'matchpairs' */ @@ -1082,9 +1083,9 @@ struct window_S { winopt_T w_allbuf_opt; /* A few options have local flags for P_INSECURE. */ - long_u w_p_stl_flags; /* flags for 'statusline' */ - long_u w_p_fde_flags; /* flags for 'foldexpr' */ - long_u w_p_fdt_flags; /* flags for 'foldtext' */ + uint32_t w_p_stl_flags; /* flags for 'statusline' */ + uint32_t w_p_fde_flags; /* flags for 'foldexpr' */ + uint32_t w_p_fdt_flags; /* flags for 'foldtext' */ int *w_p_cc_cols; /* array of columns to highlight or NULL */ int w_p_brimin; /* minimum width for breakindent */ int w_p_brishift; /* additional shift for breakindent */ diff --git a/src/nvim/charset.c b/src/nvim/charset.c index b3d0949722..86d6acc60b 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -791,15 +791,17 @@ int linetabsize_col(int startcol, char_u *s) /// @param len /// /// @return Number of characters the string will take on the screen. -int win_linetabsize(win_T *wp, char_u *line, colnr_T len) +unsigned int win_linetabsize(win_T *wp, char_u *line, colnr_T len) { colnr_T col = 0; - char_u *s; - for (s = line; *s != NUL && (len == MAXCOL || s < line + len); mb_ptr_adv(s)) { + for (char_u *s = line; + *s != NUL && (len == MAXCOL || s < line + len); + mb_ptr_adv(s)) { col += win_lbr_chartabsize(wp, line, s, col, NULL); } - return (int)col; + + return (unsigned int)col; } /// Return TRUE if 'c' is a normal identifier character: @@ -1695,7 +1697,9 @@ intmax_t getdigits(char_u **pp) int getdigits_int(char_u **pp) { intmax_t number = getdigits(pp); +#if SIZEOF_INTMAX_T > SIZEOF_INT assert(number >= INT_MIN && number <= INT_MAX); +#endif return (int)number; } @@ -1705,7 +1709,9 @@ int getdigits_int(char_u **pp) long getdigits_long(char_u **pp) { intmax_t number = getdigits(pp); +#if SIZEOF_INTMAX_T > SIZEOF_LONG assert(number >= LONG_MIN && number <= LONG_MAX); +#endif return (long)number; } diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 6cc75e948c..b8fa3c24a2 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -2017,17 +2017,24 @@ int diff_infold(win_T *wp, linenr_T lnum) } /// "dp" and "do" commands. -/// -/// @param put -void nv_diffgetput(int put) +void nv_diffgetput(bool put, size_t count) { exarg_T ea; - ea.arg = (char_u *)""; + char buf[30]; + + if (count == 0) { + ea.arg = (char_u *)""; + } else { + vim_snprintf(buf, 30, "%zu", count); + ea.arg = (char_u *)buf; + } + if (put) { ea.cmdidx = CMD_diffput; } else { ea.cmdidx = CMD_diffget; } + ea.addr_count = 0; ea.line1 = curwin->w_cursor.lnum; ea.line2 = curwin->w_cursor.lnum; diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 4c00547daa..f6ca11761a 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -5751,8 +5751,12 @@ stop_insert ( } if (curwin->w_cursor.lnum != tpos.lnum) curwin->w_cursor = tpos; - else if (cc != NUL) - ++curwin->w_cursor.col; /* put cursor back on the NUL */ + else { + tpos.col++; + if (cc != NUL && gchar_pos(&tpos) == NUL) { + ++curwin->w_cursor.col; // put cursor back on the NUL + } + } /* <C-S-Right> may have started Visual mode, adjust the position for * deleted characters. */ diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 1833461fa9..87a5ed80e7 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -9604,7 +9604,7 @@ static void f_gettabvar(typval_T *argvars, typval_T *rettv) tabpage_T *tp, *oldtabpage; dictitem_T *v; char_u *varname; - int done = FALSE; + bool done = false; rettv->v_type = VAR_STRING; rettv->vval.v_string = NULL; @@ -9614,14 +9614,14 @@ static void f_gettabvar(typval_T *argvars, typval_T *rettv) if (tp != NULL && varname != NULL) { /* Set tp to be our tabpage, temporarily. Also set the window to the * first window in the tabpage, otherwise the window is not valid. */ - switch_win(&oldcurwin, &oldtabpage, tp->tp_firstwin, tp, TRUE); - - /* look up the variable */ - /* Let gettabvar({nr}, "") return the "t:" dictionary. */ - v = find_var_in_ht(&tp->tp_vars->dv_hashtab, 't', varname, FALSE); - if (v != NULL) { - copy_tv(&v->di_tv, rettv); - done = TRUE; + if (switch_win(&oldcurwin, &oldtabpage, tp->tp_firstwin, tp, TRUE) == OK) { + // look up the variable + // Let gettabvar({nr}, "") return the "t:" dictionary. + v = find_var_in_ht(&tp->tp_vars->dv_hashtab, 't', varname, FALSE); + if (v != NULL) { + copy_tv(&v->di_tv, rettv); + done = true; + } } /* restore previous notion of curwin */ @@ -9712,7 +9712,7 @@ getwinvar ( dictitem_T *v; tabpage_T *tp = NULL; tabpage_T *oldtabpage = NULL; - int done = FALSE; + bool done = false; if (off == 1) tp = find_tabpage((int)get_tv_number_chk(&argvars[0], NULL)); @@ -9728,18 +9728,18 @@ getwinvar ( if (win != NULL && varname != NULL) { /* Set curwin to be our win, temporarily. Also set the tabpage, * otherwise the window is not valid. */ - switch_win(&oldcurwin, &oldtabpage, win, tp, TRUE); - - if (*varname == '&') { /* window-local-option */ - if (get_option_tv(&varname, rettv, 1) == OK) - done = TRUE; - } else { - /* Look up the variable. */ - /* Let getwinvar({nr}, "") return the "w:" dictionary. */ - v = find_var_in_ht(&win->w_vars->dv_hashtab, 'w', varname, FALSE); - if (v != NULL) { - copy_tv(&v->di_tv, rettv); - done = TRUE; + if (switch_win(&oldcurwin, &oldtabpage, win, tp, TRUE) == OK) { + if (*varname == '&') { /* window-local-option */ + if (get_option_tv(&varname, rettv, 1) == OK) + done = true; + } else { + // Look up the variable. + // Let getwinvar({nr}, "") return the "w:" dictionary. + v = find_var_in_ht(&win->w_vars->dv_hashtab, 'w', varname, FALSE); + if (v != NULL) { + copy_tv(&v->di_tv, rettv); + done = true; + } } } @@ -10332,7 +10332,7 @@ static void get_user_input(typval_T *argvars, typval_T *rettv, int inputdialog) if (!inputdialog && argvars[2].v_type != VAR_UNKNOWN) { char_u *xp_name; int xp_namelen; - long argt; + uint32_t argt; /* input() with a third argument: completion */ rettv->vval.v_string = NULL; @@ -13494,10 +13494,8 @@ static void setwinvar(typval_T *argvars, typval_T *rettv, int off) varname = get_tv_string_chk(&argvars[off + 1]); varp = &argvars[off + 2]; - if (win != NULL && varname != NULL && varp != NULL) { - if (switch_win(&save_curwin, &save_curtab, win, tp, TRUE) == FAIL) - return; - + if (win != NULL && varname != NULL && varp != NULL + && switch_win(&save_curwin, &save_curtab, win, tp, TRUE) == OK) { if (*varname == '&') { long numval; char_u *strval; @@ -13515,7 +13513,6 @@ static void setwinvar(typval_T *argvars, typval_T *rettv, int off) set_var(winvarname, varp, TRUE); free(winvarname); } - restore_win(save_curwin, save_curtab, TRUE); } } diff --git a/src/nvim/ex_cmds_defs.h b/src/nvim/ex_cmds_defs.h index 0e13574321..1b920511b6 100644 --- a/src/nvim/ex_cmds_defs.h +++ b/src/nvim/ex_cmds_defs.h @@ -8,6 +8,7 @@ #define NVIM_EX_CMDS_DEFS_H #include <stdbool.h> +#include <stdint.h> #include "nvim/pos.h" // for linenr_T #include "nvim/normal.h" @@ -59,13 +60,13 @@ #define USECTRLV 0x2000 /* do not remove CTRL-V from argument */ #define NOTADR 0x4000 /* number before command is not an address */ #define EDITCMD 0x8000 /* allow "+command" argument */ -#define BUFNAME 0x10000L /* accepts buffer name */ -#define BUFUNL 0x20000L /* accepts unlisted buffer too */ -#define ARGOPT 0x40000L /* allow "++opt=val" argument */ -#define SBOXOK 0x80000L /* allowed in the sandbox */ -#define CMDWIN 0x100000L /* allowed in cmdline window */ -#define MODIFY 0x200000L /* forbidden in non-'modifiable' buffer */ -#define EXFLAGS 0x400000L /* allow flags after count in argument */ +#define BUFNAME 0x10000 /* accepts buffer name */ +#define BUFUNL 0x20000 /* accepts unlisted buffer too */ +#define ARGOPT 0x40000 /* allow "++opt=val" argument */ +#define SBOXOK 0x80000 /* allowed in the sandbox */ +#define CMDWIN 0x100000 /* allowed in cmdline window */ +#define MODIFY 0x200000 /* forbidden in non-'modifiable' buffer */ +#define EXFLAGS 0x400000 /* allow flags after count in argument */ #define FILES (XFILE | EXTRA) /* multiple extra files allowed */ #define WORD1 (EXTRA | NOSPC) /* one extra word allowed */ #define FILE1 (FILES | NOSPC) /* 1 file allowed, defaults to current file */ @@ -85,7 +86,7 @@ typedef char_u *(*LineGetter)(int, void *, int); typedef struct cmdname { char_u *cmd_name; ///< Name of the command. ex_func_T cmd_func; ///< Function with implementation of this command. - long_u cmd_argt; ///< Relevant flags from the declared above. + uint32_t cmd_argt; ///< Relevant flags from the declared above. } CommandDefinition; /// Arguments used for Ex commands. @@ -95,7 +96,7 @@ struct exarg { char_u *cmd; ///< the name of the command (except for :make) char_u **cmdlinep; ///< pointer to pointer of allocated cmdline cmdidx_T cmdidx; ///< the index for the command - long argt; ///< flags for the command + uint32_t argt; ///< flags for the command int skip; ///< don't execute the command, only parse it int forceit; ///< TRUE if ! present int addr_count; ///< the number of addresses given diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index b4dfe99aed..065c27013e 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -12,6 +12,7 @@ #include <string.h> #include <stdbool.h> +#include <stdint.h> #include <errno.h> #include <inttypes.h> @@ -77,7 +78,7 @@ static int ex_pressedreturn = FALSE; typedef struct ucmd { char_u *uc_name; /* The command name */ - long_u uc_argt; /* The argument type */ + uint32_t uc_argt; /* The argument type */ char_u *uc_rep; /* The command's replacement string */ long uc_def; /* The default value for a range/count */ int uc_compl; /* completion type */ @@ -1422,7 +1423,7 @@ static char_u * do_one_cmd(char_u **cmdlinep, goto doend; if (*ea.cmd == '|' || (exmode_active && ea.line1 != ea.line2)) { ea.cmdidx = CMD_print; - ea.argt = RANGE+COUNT+TRLBAR; + ea.argt = RANGE | COUNT | TRLBAR; if ((errormsg = invalid_range(&ea)) == NULL) { correct_range(&ea); ex_print(&ea); @@ -1509,7 +1510,7 @@ static char_u * do_one_cmd(char_u **cmdlinep, * 5. parse arguments */ if (!IS_USER_CMDIDX(ea.cmdidx)) { - ea.argt = (long)cmdnames[(int)ea.cmdidx].cmd_argt; + ea.argt = cmdnames[(int)ea.cmdidx].cmd_argt; } if (!ea.skip) { @@ -2204,7 +2205,7 @@ find_ucmd ( eap->cmdidx = CMD_USER; else eap->cmdidx = CMD_USER_BUF; - eap->argt = (long)uc->uc_argt; + eap->argt = uc->uc_argt; eap->useridx = j; if (compl != NULL) @@ -2470,7 +2471,7 @@ set_one_cmd_context ( * 5. parse arguments */ if (!IS_USER_CMDIDX(ea.cmdidx)) { - ea.argt = (long)cmdnames[(int)ea.cmdidx].cmd_argt; + ea.argt = cmdnames[(int)ea.cmdidx].cmd_argt; } arg = skipwhite(p); @@ -4122,7 +4123,9 @@ char_u *get_command_name(expand_T *xp, int idx) } -static int uc_add_command(char_u *name, size_t name_len, char_u *rep, long argt, long def, int flags, int compl, char_u *compl_arg, int force) +static int uc_add_command(char_u *name, size_t name_len, char_u *rep, + uint32_t argt, long def, int flags, int compl, + char_u *compl_arg, int force) { ucmd_T *cmd = NULL; char_u *p; @@ -4257,7 +4260,7 @@ static void uc_list(char_u *name, size_t name_len) int found = FALSE; ucmd_T *cmd; int len; - long a; + uint32_t a; garray_T *gap; gap = &curbuf->b_ucmds; @@ -4265,7 +4268,7 @@ static void uc_list(char_u *name, size_t name_len) int i; for (i = 0; i < gap->ga_len; ++i) { cmd = USER_CMD_GA(gap, i); - a = (long)cmd->uc_argt; + a = cmd->uc_argt; /* Skip commands which don't match the requested prefix */ if (STRNCMP(name, cmd->uc_name, name_len) != 0) @@ -4296,7 +4299,7 @@ static void uc_list(char_u *name, size_t name_len) len = 0; /* Arguments */ - switch ((int)(a & (EXTRA|NOSPC|NEEDARG))) { + switch (a & (EXTRA|NOSPC|NEEDARG)) { case 0: IObuff[len++] = '0'; break; case (EXTRA): IObuff[len++] = '*'; break; case (EXTRA|NOSPC): IObuff[len++] = '?'; break; @@ -4374,7 +4377,7 @@ static char_u *uc_fun_cmd(void) return IObuff; } -static int uc_scan_attr(char_u *attr, size_t len, long *argt, long *def, int *flags, int *compl, char_u **compl_arg) +static int uc_scan_attr(char_u *attr, size_t len, uint32_t *argt, long *def, int *flags, int *compl, char_u **compl_arg) { char_u *p; @@ -4493,7 +4496,7 @@ static void ex_command(exarg_T *eap) char_u *name; char_u *end; char_u *p; - long argt = 0; + uint32_t argt = 0; long def = -1; int flags = 0; int compl = EXPAND_NOTHING; @@ -5026,7 +5029,8 @@ char_u *get_user_cmd_complete(expand_T *xp, int idx) * copied to allocated memory and stored in "*compl_arg". * Returns FAIL if something is wrong. */ -int parse_compl_arg(char_u *value, int vallen, int *complp, long *argt, char_u **compl_arg) +int parse_compl_arg(char_u *value, int vallen, int *complp, + uint32_t *argt, char_u **compl_arg) { char_u *arg = NULL; size_t arglen = 0; diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index 993ec143bb..92abcbada4 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -14,6 +14,7 @@ #include <errno.h> #include <string.h> #include <inttypes.h> +#include <stdint.h> #include "nvim/vim.h" #include "nvim/ascii.h" @@ -726,8 +727,7 @@ void ex_hardcopy(exarg_T *eap) if (got_int || settings.user_abort) goto print_fail; - assert(prtpos.bytes_printed == 0 - || prtpos.bytes_printed * 100 > prtpos.bytes_printed); + assert(prtpos.bytes_printed <= SIZE_MAX / 100); sprintf((char *)IObuff, _("Printing page %d (%zu%%)"), page_count + 1 + side, prtpos.bytes_printed * 100 / bytes_to_print); diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index 56276db3ce..9c636ebbcc 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -1805,6 +1805,7 @@ int get_c_indent(void) } if (trypos != NULL) { + our_paren_pos = *trypos; /* * If the matching paren is more than one line away, use the indent of * a previous non-empty line that matches the same paren. @@ -1814,7 +1815,6 @@ int get_c_indent(void) amount = get_indent_lnum(curwin->w_cursor.lnum - 1); /* XXX */ } else { amount = -1; - our_paren_pos = *trypos; for (lnum = cur_curpos.lnum - 1; lnum > our_paren_pos.lnum; --lnum) { l = skipwhite(ml_get(lnum)); if (cin_nocode(l)) /* skip comment lines */ diff --git a/src/nvim/memory.c b/src/nvim/memory.c index a2274a25fe..c954ab3c7b 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -489,7 +489,8 @@ void free_all_mem(void) return; entered = true; - block_autocmds(); /* don't want to trigger autocommands here */ + // Don't want to trigger autocommands from here on. + block_autocmds(); /* Close all tabs and windows. Reset 'equalalways' to avoid redraws. */ p_ea = FALSE; diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index f756201efb..aa4d2b38db 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -10,6 +10,7 @@ * misc1.c: functions that didn't seem to fit elsewhere */ +#include <assert.h> #include <errno.h> #include <inttypes.h> #include <stdbool.h> @@ -1271,7 +1272,7 @@ plines_win_nofill ( int plines_win_nofold(win_T *wp, linenr_T lnum) { char_u *s; - long col; + unsigned int col; int width; s = ml_get_buf(wp->w_buffer, lnum, FALSE); @@ -1292,11 +1293,12 @@ int plines_win_nofold(win_T *wp, linenr_T lnum) width = wp->w_width - win_col_off(wp); if (width <= 0) return 32000; - if (col <= width) + if (col <= (unsigned int)width) return 1; col -= width; width += win_col_off2(wp); - return (col + (width - 1)) / width + 1; + assert(col <= INT_MAX && (int)col < INT_MAX - (width -1)); + return ((int)col + (width - 1)) / width + 1; } /* diff --git a/src/nvim/normal.c b/src/nvim/normal.c index e1aed23e8c..5b138f2d88 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -7248,7 +7248,8 @@ static void nv_put(cmdarg_T *cap) /* "dp" is ":diffput" */ if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'p') { clearop(cap->oap); - nv_diffgetput(true); + assert(cap->opcount >= 0); + nv_diffgetput(true, (size_t)cap->opcount); } else clearopbeep(cap->oap); } else { @@ -7350,7 +7351,8 @@ static void nv_open(cmdarg_T *cap) /* "do" is ":diffget" */ if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'o') { clearop(cap->oap); - nv_diffgetput(false); + assert(cap->opcount >= 0); + nv_diffgetput(false, (size_t)cap->opcount); } else if (VIsual_active) /* switch start and end of visual */ v_swap_corners(cap->cmdchar); else diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 8fb3ba7f08..90fc89ee21 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -4234,8 +4234,7 @@ int do_addsub(int command, linenr_T Prenum1) char_u buf2[NUMBUFLEN]; int hex; /* 'X' or 'x': hex; '0': octal */ static int hexupper = FALSE; /* 0xABC */ - unsigned long n; - long_u oldn; + unsigned long n, oldn; char_u *ptr; int c; int length = 0; /* character length of the number */ diff --git a/src/nvim/option.c b/src/nvim/option.c index 88108b14a2..0199c5fc6c 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -31,9 +31,11 @@ */ #define IN_OPTION_C +#include <assert.h> #include <errno.h> #include <inttypes.h> #include <stdbool.h> +#include <stdint.h> #include <string.h> #include <stdint.h> #include <stdlib.h> @@ -297,10 +299,10 @@ static long p_wm_nopaste; static long p_sts_nopaste; static int p_ai_nopaste; -struct vimoption { +typedef struct vimoption { char *fullname; /* full option name */ char *shortname; /* permissible abbreviation */ - long_u flags; /* see below */ + uint32_t flags; /* see below */ char_u *var; /* global option: pointer to variable; * window-local option: VAR_WIN; * buffer-local option: global value */ @@ -309,7 +311,7 @@ struct vimoption { char_u *def_val[2]; /* default values for variable (vi and vim) */ scid_T scriptID; /* script in which the option was last set */ # define SCRIPTID_INIT , 0 -}; +} vimoption_T; #define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */ #define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */ @@ -317,43 +319,43 @@ struct vimoption { /* * Flags */ -#define P_BOOL 0x01 /* the option is boolean */ -#define P_NUM 0x02 /* the option is numeric */ -#define P_STRING 0x04 /* the option is a string */ -#define P_ALLOCED 0x08 /* the string option is in allocated memory, - must use free_string_option() when - assigning new value. Not set if default is - the same. */ -#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can - never be used for local or hidden options! */ -#define P_NODEFAULT 0x40 /* don't set to default value */ -#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must +#define P_BOOL 0x01U /* the option is boolean */ +#define P_NUM 0x02U /* the option is numeric */ +#define P_STRING 0x04U /* the option is a string */ +#define P_ALLOCED 0x08U /* the string option is in allocated memory, + must use free_string_option() when + assigning new value. Not set if default is + the same. */ +#define P_EXPAND 0x10U /* environment expansion. NOTE: P_EXPAND can + never be used for local or hidden options */ +#define P_NODEFAULT 0x40U /* don't set to default value */ +#define P_DEF_ALLOCED 0x80U /* default value is in allocated memory, must use free() when assigning new value */ -#define P_WAS_SET 0x100 /* option has been set/reset */ -#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */ -#define P_VI_DEF 0x400 /* Use Vi default for Vim */ -#define P_VIM 0x800 /* Vim option, reset when 'cp' set */ +#define P_WAS_SET 0x100U /* option has been set/reset */ +#define P_NO_MKRC 0x200U /* don't include in :mkvimrc output */ +#define P_VI_DEF 0x400U /* Use Vi default for Vim */ +#define P_VIM 0x800U /* Vim option, reset when 'cp' set */ /* when option changed, what to display: */ -#define P_RSTAT 0x1000 /* redraw status lines */ -#define P_RWIN 0x2000 /* redraw current window */ -#define P_RBUF 0x4000 /* redraw current buffer */ -#define P_RALL 0x6000 /* redraw all windows */ -#define P_RCLR 0x7000 /* clear and redraw all */ - -#define P_COMMA 0x8000 /* comma separated list */ -#define P_NODUP 0x10000L /* don't allow duplicate strings */ -#define P_FLAGLIST 0x20000L /* list of single-char flags */ - -#define P_SECURE 0x40000L /* cannot change in modeline or secure mode */ -#define P_GETTEXT 0x80000L /* expand default value with _() */ -#define P_NOGLOB 0x100000L /* do not use local value for global vimrc */ -#define P_NFNAME 0x200000L /* only normal file name chars allowed */ -#define P_INSECURE 0x400000L /* option was set from a modeline */ -#define P_PRI_MKRC 0x800000L /* priority for :mkvimrc (setting option has +#define P_RSTAT 0x1000U /* redraw status lines */ +#define P_RWIN 0x2000U /* redraw current window */ +#define P_RBUF 0x4000U /* redraw current buffer */ +#define P_RALL 0x6000U /* redraw all windows */ +#define P_RCLR 0x7000U /* clear and redraw all */ + +#define P_COMMA 0x8000U /* comma separated list */ +#define P_NODUP 0x10000U /* don't allow duplicate strings */ +#define P_FLAGLIST 0x20000U /* list of single-char flags */ + +#define P_SECURE 0x40000U /* cannot change in modeline or secure mode */ +#define P_GETTEXT 0x80000U /* expand default value with _() */ +#define P_NOGLOB 0x100000U /* do not use local value for global vimrc */ +#define P_NFNAME 0x200000U /* only normal file name chars allowed */ +#define P_INSECURE 0x400000U /* option was set from a modeline */ +#define P_PRI_MKRC 0x800000U /* priority for :mkvimrc (setting option has side effects) */ -#define P_NO_ML 0x1000000L /* not allowed in modeline */ -#define P_CURSWANT 0x2000000L /* update curswant required; not needed when +#define P_NO_ML 0x1000000U /* not allowed in modeline */ +#define P_CURSWANT 0x2000000U /* update curswant required; not needed when * there is a redraw flag */ #define ISK_LATIN1 (char_u *)"@,48-57,_,192-255" @@ -379,7 +381,7 @@ struct vimoption { * The options with a NULL variable are 'hidden': a set command for them is * ignored and they are not printed. */ -static struct vimoption +static vimoption_T options[] = { {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT, @@ -1848,7 +1850,6 @@ void set_init_1(void) { char_u *p; int opt_idx; - long_u n; langmap_init(); @@ -1884,7 +1885,7 @@ void set_init_1(void) int mustfree; ga_init(&ga, 1, 100); - for (n = 0; n < (long)ARRAY_SIZE(names); ++n) { + for (size_t n = 0; n < ARRAY_SIZE(names); ++n) { mustfree = FALSE; # ifdef UNIX if (*names[n] == NUL) @@ -1919,10 +1920,11 @@ void set_init_1(void) if (opt_idx >= 0) { { /* Use half of amount of memory available to Vim. */ - /* If too much to fit in long_u, get long_u max */ + /* If too much to fit in uintptr_t, get uintptr_t max */ uint64_t available_kib = os_get_total_mem_kib(); - n = available_kib / 2 > ULONG_MAX ? ULONG_MAX - : (long_u)(available_kib /2); + uintptr_t n = available_kib / 2 > UINTPTR_MAX + ? UINTPTR_MAX + : (uintptr_t)(available_kib /2); options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n; opt_idx = findoption((char_u *)"maxmem"); if (opt_idx >= 0) { @@ -2133,12 +2135,10 @@ set_option_default ( { char_u *varp; /* pointer to variable for current option */ int dvi; /* index in def_val[] */ - long_u flags; - long_u *flagsp; int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0; varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags); - flags = options[opt_idx].flags; + uint32_t flags = options[opt_idx].flags; if (varp != NULL) { /* skip hidden option, nothing to do for it */ dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT; if (flags & P_STRING) { @@ -2177,7 +2177,7 @@ set_option_default ( } /* The default value is not insecure. */ - flagsp = insecure_flag(opt_idx, opt_flags); + uint32_t *flagsp = insecure_flag(opt_idx, opt_flags); *flagsp = *flagsp & ~P_INSECURE; } @@ -2425,8 +2425,8 @@ void set_helplang_default(char_u *lang) p_hlg = vim_strsave(lang); /* zh_CN becomes "cn", zh_TW becomes "tw". */ if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5) { - p_hlg[0] = TOLOWER_ASC(p_hlg[3]); - p_hlg[1] = TOLOWER_ASC(p_hlg[4]); + p_hlg[0] = (char_u)TOLOWER_ASC(p_hlg[3]); + p_hlg[1] = (char_u)TOLOWER_ASC(p_hlg[4]); } p_hlg[2] = NUL; options[idx].flags |= P_ALLOCED; @@ -2444,7 +2444,7 @@ void set_helplang_default(char_u *lang) void set_title_defaults(void) { int idx1; - long val; + int val; /* * If GUI is (going to be) used, we can always set the window title and @@ -2454,13 +2454,13 @@ void set_title_defaults(void) idx1 = findoption((char_u *)"title"); if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET)) { val = mch_can_restore_title(); - options[idx1].def_val[VI_DEFAULT] = (char_u *)val; + options[idx1].def_val[VI_DEFAULT] = (char_u *)(intptr_t)val; p_title = val; } idx1 = findoption((char_u *)"icon"); if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET)) { val = mch_can_restore_icon(); - options[idx1].def_val[VI_DEFAULT] = (char_u *)val; + options[idx1].def_val[VI_DEFAULT] = (char_u *)(intptr_t)val; p_icon = val; } } @@ -2491,13 +2491,13 @@ do_set ( char_u errbuf[80]; char_u *startarg; int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */ - int nextchar; /* next non-white char after option name */ + char_u nextchar; /* next non-white char after option name */ int afterchar; /* character just after option name */ int len; int i; long value; int key; - long_u flags; /* flags for current option */ + uint32_t flags; /* flags for current option */ char_u *varp = NULL; /* pointer to variable for current option */ int did_show = FALSE; /* already showed one value */ int adding; /* "opt+=arg" */ @@ -2632,11 +2632,11 @@ do_set ( } else { flags = P_STRING; if (key < 0) { - key_name[0] = KEY2TERMCAP0(key); + key_name[0] = (char_u)KEY2TERMCAP0(key); key_name[1] = KEY2TERMCAP1(key); } else { key_name[0] = KS_KEY; - key_name[1] = (key & 0xff); + key_name[1] = (char_u)(key & 0xff); } } @@ -3185,7 +3185,8 @@ skip: if (i + (arg - startarg) < IOSIZE) { /* append the argument with the error */ STRCAT(IObuff, ": "); - memmove(IObuff + i, startarg, (arg - startarg)); + assert(arg >= startarg); + memmove(IObuff + i, startarg, (size_t)(arg - startarg)); IObuff[i + (arg - startarg)] = NUL; } /* make sure all characters are printable */ @@ -3227,14 +3228,12 @@ did_set_option ( int new_value /* value was replaced completely */ ) { - long_u *p; - options[opt_idx].flags |= P_WAS_SET; /* When an option is set in the sandbox, from a modeline or in secure mode * set the P_INSECURE flag. Otherwise, if a new value is stored reset the * flag. */ - p = insecure_flag(opt_idx, opt_flags); + uint32_t *p = insecure_flag(opt_idx, opt_flags); if (secure #ifdef HAVE_SANDBOX || sandbox != 0 @@ -3581,10 +3580,9 @@ void set_term_option_alloced(char_u **p) int was_set_insecurely(char_u *opt, int opt_flags) { int idx = findoption(opt); - long_u *flagp; if (idx >= 0) { - flagp = insecure_flag(idx, opt_flags); + uint32_t *flagp = insecure_flag(idx, opt_flags); return (*flagp & P_INSECURE) != 0; } EMSG2(_(e_intern2), "was_set_insecurely()"); @@ -3595,7 +3593,7 @@ int was_set_insecurely(char_u *opt, int opt_flags) * Get a pointer to the flags used for the P_INSECURE flag of option * "opt_idx". For some local options a local flags field is used. */ -static long_u *insecure_flag(int opt_idx, int opt_flags) +static uint32_t *insecure_flag(int opt_idx, int opt_flags) { if (opt_flags & OPT_LOCAL) switch ((int)options[opt_idx].indir) { @@ -3755,7 +3753,7 @@ did_set_string_option ( char_u *s, *p; int did_chartab = FALSE; char_u **gvarp; - long_u free_oldval = (options[opt_idx].flags & P_ALLOCED); + bool free_oldval = (options[opt_idx].flags & P_ALLOCED); /* Get the global option to compare with, otherwise we would have to check * two values for all local options. */ @@ -3796,16 +3794,21 @@ did_set_string_option ( flags = &curbuf->b_bkc_flags; } - if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK) { - errmsg = e_invarg; - } + if ((opt_flags & OPT_LOCAL) && *bkc == NUL) { + // make the local value empty: use the global value + *flags = 0; + } else { + if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK) { + errmsg = e_invarg; + } - if (((*flags & BKC_AUTO) != 0) - + ((*flags & BKC_YES) != 0) - + ((*flags & BKC_NO) != 0) != 1) { - /* Must have exactly one of "auto", "yes" and "no". */ - (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE); - errmsg = e_invarg; + if (((*flags & BKC_AUTO) != 0) + + ((*flags & BKC_YES) != 0) + + ((*flags & BKC_NO) != 0) != 1) { + // Must have exactly one of "auto", "yes" and "no". + (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE); + errmsg = e_invarg; + } } } /* 'backupext' and 'patchmode' */ @@ -4649,9 +4652,8 @@ char_u *check_colorcolumn(win_T *wp) { char_u *s; int col; - int count = 0; + unsigned int count = 0; int color_cols[256]; - int i; int j = 0; if (wp->w_buffer == NULL) @@ -4667,7 +4669,13 @@ char_u *check_colorcolumn(win_T *wp) col = col * getdigits_int(&s); if (wp->w_buffer->b_p_tw == 0) goto skip; /* 'textwidth' not set, skip this item */ - col += wp->w_buffer->b_p_tw; + assert((col >= 0 + && wp->w_buffer->b_p_tw <= INT_MAX - col + && wp->w_buffer->b_p_tw + col >= INT_MIN) + || (col < 0 + && wp->w_buffer->b_p_tw >= INT_MIN - col + && wp->w_buffer->b_p_tw + col <= INT_MAX)); + col += (int)wp->w_buffer->b_p_tw; if (col < 0) goto skip; } else if (VIM_ISDIGIT(*s)) @@ -4693,7 +4701,7 @@ skip: * win_line() */ qsort(color_cols, count, sizeof(int), int_cmp); - for (i = 0; i < count; ++i) + for (unsigned int i = 0; i < count; ++i) /* skip duplicates */ if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i]) wp->w_p_cc_cols[j++] = color_cols[i]; @@ -5558,8 +5566,10 @@ set_num_option ( /* Postpone the resizing; check the size and cmdline position for * messages. */ check_shellsize(); - if (cmdline_row > Rows - p_ch && Rows > p_ch) - cmdline_row = Rows - p_ch; + if (cmdline_row > Rows - p_ch && Rows > p_ch) { + assert(p_ch >= 0 && Rows - p_ch <= INT_MAX); + cmdline_row = (int)(Rows - p_ch); + } } if (p_window >= Rows || !option_was_set((char_u *)"window")) p_window = Rows - 1; @@ -5648,11 +5658,11 @@ set_num_option ( /* * Called after an option changed: check if something needs to be redrawn. */ -static void check_redraw(long_u flags) +static void check_redraw(uint32_t flags) { /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */ - int doclear = (flags & P_RCLR) == P_RCLR; - int all = ((flags & P_RALL) == P_RALL || doclear); + bool doclear = (flags & P_RCLR) == P_RCLR; + bool all = ((flags & P_RALL) == P_RALL || doclear); if ((flags & P_RSTAT) || all) /* mark all status lines dirty */ status_redraw_all(); @@ -5673,7 +5683,6 @@ static void check_redraw(long_u flags) */ static int findoption(char_u *arg) { - int opt_idx; char *s, *p; static short quick_tab[27] = {0, 0}; /* quick access table */ int is_term_opt; @@ -5685,12 +5694,12 @@ static int findoption(char_u *arg) */ if (quick_tab[1] == 0) { p = options[0].fullname; - for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++) { + for (short int i = 1; (s = options[i].fullname) != NULL; i++) { if (s[0] != p[0]) { if (s[0] == 't' && s[1] == '_') - quick_tab[26] = opt_idx; + quick_tab[26] = i; else - quick_tab[CharOrdLow(s[0])] = opt_idx; + quick_tab[CharOrdLow(s[0])] = i; } p = s; } @@ -5702,6 +5711,7 @@ static int findoption(char_u *arg) if (arg[0] < 'a' || arg[0] > 'z') return -1; + int opt_idx; is_term_opt = (arg[0] == 't' && arg[1] == '_'); if (is_term_opt) opt_idx = quick_tab[26]; @@ -5799,7 +5809,7 @@ int get_option_value_strict(char *name, void *from) { char_u *varp = NULL; - struct vimoption *p; + vimoption_T *p; int rv = 0; int opt_idx = findoption((uint8_t *)name); if (opt_idx < 0) { @@ -5911,13 +5921,12 @@ set_option_value ( { int opt_idx; char_u *varp; - long_u flags; opt_idx = findoption(name); if (opt_idx < 0) EMSG2(_("E355: Unknown option: %s"), name); else { - flags = options[opt_idx].flags; + uint32_t flags = options[opt_idx].flags; #ifdef HAVE_SANDBOX /* Disallow changing some options in the sandbox */ if (sandbox > 0 && (flags & P_SECURE)) { @@ -6035,7 +6044,7 @@ showoptions ( int opt_flags /* OPT_LOCAL and/or OPT_GLOBAL */ ) { - struct vimoption *p; + vimoption_T *p; int col; int isterm; char_u *varp; @@ -6049,7 +6058,7 @@ showoptions ( #define INC 20 #define GAP 3 - struct vimoption **items = xmalloc(sizeof(struct vimoption *) * PARAM_COUNT); + vimoption_T **items = xmalloc(sizeof(vimoption_T *) * PARAM_COUNT); /* Highlight title */ if (all == 2) @@ -6099,7 +6108,11 @@ showoptions ( * display the items */ if (run == 1) { - cols = (Columns + GAP - 3) / INC; + assert(Columns <= LONG_MAX - GAP + && Columns + GAP >= LONG_MIN + 3 + && (Columns + GAP - 3) / INC >= INT_MIN + && (Columns + GAP - 3) / INC <= INT_MAX); + cols = (int)((Columns + GAP - 3) / INC); if (cols == 0) cols = 1; rows = (item_count + cols - 1) / cols; @@ -6125,7 +6138,7 @@ showoptions ( /* * Return TRUE if option "p" has its default value. */ -static int optval_default(struct vimoption *p, char_u *varp) +static int optval_default(vimoption_T *p, char_u *varp) { int dvi; @@ -6146,7 +6159,7 @@ static int optval_default(struct vimoption *p, char_u *varp) */ static void showoneopt ( - struct vimoption *p, + vimoption_T *p, int opt_flags /* OPT_LOCAL or OPT_GLOBAL */ ) { @@ -6202,7 +6215,7 @@ showoneopt ( */ int makeset(FILE *fd, int opt_flags, int local_only) { - struct vimoption *p; + vimoption_T *p; char_u *varp; /* currently used value */ char_u *varp_fresh; /* local value */ char_u *varp_local = NULL; /* fresh value */ @@ -6406,7 +6419,7 @@ void clear_termoptions(void) void free_termoptions(void) { - struct vimoption *p; + vimoption_T *p; for (p = &options[0]; p->fullname != NULL; p++) if (istermoption(p)) { @@ -6428,7 +6441,7 @@ void free_termoptions(void) */ void free_one_termoption(char_u *var) { - struct vimoption *p; + vimoption_T *p; for (p = &options[0]; p->fullname != NULL; p++) if (p->var == var) { @@ -6446,7 +6459,7 @@ void free_one_termoption(char_u *var) */ void set_term_defaults(void) { - struct vimoption *p; + vimoption_T *p; for (p = &options[0]; p->fullname != NULL; p++) { if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var)) { @@ -6466,7 +6479,7 @@ void set_term_defaults(void) /* * return TRUE if 'p' starts with 't_' */ -static int istermoption(struct vimoption *p) +static int istermoption(vimoption_T *p) { return p->fullname[0] == 't' && p->fullname[1] == '_'; } @@ -6497,8 +6510,14 @@ void comp_col(void) if (!p_ru || last_has_status) /* no need for separating space */ ++sc_col; } - sc_col = Columns - sc_col; - ru_col = Columns - ru_col; + assert(sc_col >= 0 + && INT_MIN + sc_col <= Columns + && Columns - sc_col <= INT_MAX); + sc_col = (int)(Columns - sc_col); + assert(ru_col >= 0 + && INT_MIN + ru_col <= Columns + && Columns - ru_col <= INT_MAX); + ru_col = (int)(Columns - ru_col); if (sc_col <= 0) /* screen too narrow, will become a mess */ sc_col = 1; if (ru_col <= 0) @@ -6508,7 +6527,7 @@ void comp_col(void) // Unset local option value, similar to ":set opt<". void unset_global_local_option(char *name, void *from) { - struct vimoption *p; + vimoption_T *p; buf_T *buf = (buf_T *)from; int opt_idx = findoption((uint8_t *)name); @@ -6576,7 +6595,7 @@ void unset_global_local_option(char *name, void *from) /* * Get pointer to option variable, depending on local or global scope. */ -static char_u *get_varp_scope(struct vimoption *p, int opt_flags) +static char_u *get_varp_scope(vimoption_T *p, int opt_flags) { if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE) { if (p->var == VAR_WIN) @@ -6610,7 +6629,7 @@ static char_u *get_varp_scope(struct vimoption *p, int opt_flags) /* * Get pointer to option variable. */ -static char_u *get_varp(struct vimoption *p) +static char_u *get_varp(vimoption_T *p) { /* hidden option, always return NULL */ if (p->var == NULL) @@ -7088,8 +7107,8 @@ set_context_in_set_cmd ( int opt_flags /* OPT_GLOBAL and/or OPT_LOCAL */ ) { - int nextchar; - long_u flags = 0; /* init for GCC */ + char_u nextchar; + uint32_t flags = 0; /* init for GCC */ int opt_idx = 0; /* init for GCC */ char_u *p; char_u *s; @@ -7142,7 +7161,7 @@ set_context_in_set_cmd ( } nextchar = *++p; is_term_option = TRUE; - expand_option_name[2] = KEY2TERMCAP0(key); + expand_option_name[2] = (char_u)KEY2TERMCAP0(key); expand_option_name[3] = KEY2TERMCAP1(key); } else { if (p[0] == 't' && p[1] == '_') { @@ -7382,7 +7401,7 @@ int ExpandSettings(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u *** *num_file = num_term; else return OK; - *file = (char_u **)xmalloc(*num_file * sizeof(char_u *)); + *file = (char_u **)xmalloc((size_t)(*num_file) * sizeof(char_u *)); } } return OK; @@ -7437,7 +7456,7 @@ void ExpandOldSetting(int *num_file, char_u ***file) */ static void option_value2string ( - struct vimoption *opp, + vimoption_T *opp, int opt_flags /* OPT_GLOBAL and/or OPT_LOCAL */ ) { @@ -7512,12 +7531,13 @@ static garray_T langmap_mapga = GA_EMPTY_INIT_VALUE; static void langmap_set_entry(int from, int to) { langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data); - int a = 0; - int b = langmap_mapga.ga_len; + unsigned int a = 0; + assert(langmap_mapga.ga_len >= 0); + unsigned int b = (unsigned int)langmap_mapga.ga_len; /* Do a binary search for an existing entry. */ while (a != b) { - int i = (a + b) / 2; + unsigned int i = (a + b) / 2; int d = entries[i].from - from; if (d == 0) { @@ -7535,7 +7555,7 @@ static void langmap_set_entry(int from, int to) /* insert new entry at position "a" */ entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a; memmove(entries + 1, entries, - (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T)); + ((unsigned int)langmap_mapga.ga_len - a) * sizeof(langmap_entry_T)); ++langmap_mapga.ga_len; entries[0].from = from; entries[0].to = to; @@ -7566,10 +7586,8 @@ int langmap_adjust_mb(int c) static void langmap_init(void) { - int i; - - for (i = 0; i < 256; i++) - langmap_mapchar[i] = i; /* we init with a one-to-one map */ + for (int i = 0; i < 256; i++) + langmap_mapchar[i] = (char_u)i; /* we init with a one-to-one map */ ga_init(&langmap_mapga, sizeof(langmap_entry_T), 8); } @@ -7627,8 +7645,10 @@ static void langmap_set(void) if (from >= 256) langmap_set_entry(from, to); - else - langmap_mapchar[from & 255] = to; + else { + assert(to <= UCHAR_MAX); + langmap_mapchar[from & 255] = (char_u)to; + } /* Advance to next pair */ mb_ptr_adv(p); @@ -7867,20 +7887,19 @@ opt_strings_flags ( int list /* when TRUE: accept a list of values */ ) { - int i; - int len; - unsigned new_flags = 0; + unsigned int new_flags = 0; while (*val) { - for (i = 0;; ++i) { + for (unsigned int i = 0;; ++i) { if (values[i] == NULL) /* val not found in values[] */ return FAIL; - len = (int)STRLEN(values[i]); + size_t len = STRLEN(values[i]); if (STRNCMP(values[i], val, len) == 0 && ((list && val[len] == ',') || val[len] == NUL)) { val += len + (val[len] == ','); - new_flags |= (1 << i); + assert(i < sizeof(1U) * 8); + new_flags |= (1U << i); break; /* check next item in val list */ } } @@ -8104,7 +8123,7 @@ void find_mps_values(int *initc, int *findc, int *backwards, int switchit) static bool briopt_check(win_T *wp) { int bri_shift = 0; - long bri_min = 20; + int bri_min = 20; bool bri_sbr = false; char_u *p = wp->w_p_briopt; @@ -8119,7 +8138,7 @@ static bool briopt_check(win_T *wp) else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4])) { p += 4; - bri_min = getdigits_long(&p); + bri_min = getdigits_int(&p); } else if (STRNCMP(p, "sbr", 3) == 0) { diff --git a/src/nvim/os/job.c b/src/nvim/os/job.c index 17872ab9c9..8db5e3cc39 100644 --- a/src/nvim/os/job.c +++ b/src/nvim/os/job.c @@ -310,8 +310,15 @@ int job_wait(Job *job, int ms) FUNC_ATTR_NONNULL_ALL // we'll assume that a user frantically hitting interrupt doesn't like // the current job. Signal that it has to be killed. if (got_int) { + got_int = false; job_stop(job); - event_poll(0); + if (ms == -1) { + // We can only return, if all streams/handles are closed and the job + // exited. + event_poll_until(-1, job->refcount == 1); + } else { + event_poll(0); + } } if (job->refcount == 1) { diff --git a/src/nvim/os/signal.c b/src/nvim/os/signal.c index ca3ba052d7..d074ace884 100644 --- a/src/nvim/os/signal.c +++ b/src/nvim/os/signal.c @@ -4,7 +4,6 @@ #include "nvim/lib/klist.h" -#include "nvim/types.h" #include "nvim/ascii.h" #include "nvim/vim.h" #include "nvim/globals.h" diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index fafd99c046..4af09915d5 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -1693,7 +1693,7 @@ static char_u *regpiece(int *flagp) if (lop == BEHIND || lop == NOBEHIND) { if (nr < 0) nr = 0; /* no limit is same as zero limit */ - reginsert_nr(lop, nr, ret); + reginsert_nr(lop, (uint32_t)nr, ret); } else reginsert(lop, ret); break; @@ -2122,14 +2122,14 @@ static char_u *regatom(int *flagp) default: if (VIM_ISDIGIT(c) || c == '<' || c == '>' || c == '\'') { - long_u n = 0; + uint32_t n = 0; int cmp; cmp = c; if (cmp == '<' || cmp == '>') c = getchr(); while (VIM_ISDIGIT(c)) { - n = n * 10 + (c - '0'); + n = n * 10 + (uint32_t)(c - '0'); c = getchr(); } if (c == '\'' && n == 0) { @@ -2155,7 +2155,7 @@ static char_u *regatom(int *flagp) else { /* put the number and the optional * comparator after the opcode */ - regcode = re_put_long(regcode, n); + regcode = re_put_uint32(regcode, n); *regcode++ = cmp; } break; @@ -2580,7 +2580,8 @@ static void reginsert_nr(int op, long val, char_u *opnd) *place++ = op; *place++ = NUL; *place++ = NUL; - re_put_long(place, (long_u)val); + assert(val >= 0 && (uintmax_t)val <= UINT32_MAX); + re_put_uint32(place, (uint32_t)val); } /* @@ -2609,15 +2610,17 @@ static void reginsert_limits(int op, long minval, long maxval, char_u *opnd) *place++ = op; *place++ = NUL; *place++ = NUL; - place = re_put_long(place, (long_u)minval); - place = re_put_long(place, (long_u)maxval); + assert(minval >= 0 && (uintmax_t)minval <= UINT32_MAX); + place = re_put_uint32(place, (uint32_t)minval); + assert(maxval >= 0 && (uintmax_t)maxval <= UINT32_MAX); + place = re_put_uint32(place, (uint32_t)maxval); regtail(opnd, place); } /* - * Write a long as four bytes at "p" and return pointer to the next char. + * Write a four bytes number at "p" and return pointer to the next char. */ -static char_u *re_put_long(char_u *p, long_u val) +static char_u *re_put_uint32(char_u *p, uint32_t val) { *p++ = (char_u) ((val >> 24) & 0377); *p++ = (char_u) ((val >> 16) & 0377); @@ -3643,7 +3646,6 @@ static int reg_match_visual(void) int mode; colnr_T start, end; colnr_T start2, end2; - colnr_T cols; /* Check if the buffer is the current buffer. */ if (reg_buf != curbuf || VIsual.lnum == 0) @@ -3686,7 +3688,10 @@ static int reg_match_visual(void) end = end2; if (top.col == MAXCOL || bot.col == MAXCOL) end = MAXCOL; - cols = win_linetabsize(wp, regline, (colnr_T)(reginput - regline)); + unsigned int cols_u = win_linetabsize(wp, regline, + (colnr_T)(reginput - regline)); + assert(cols_u <= MAXCOL); + colnr_T cols = (colnr_T)cols_u; if (cols < start || cols > end - (*p_sel == 'e')) return FALSE; } @@ -3862,20 +3867,25 @@ regmatch ( break; case RE_LNUM: - if (!REG_MULTI || !re_num_cmp((long_u)(reglnum + reg_firstlnum), - scan)) + assert(reglnum + reg_firstlnum >= 0 + && (uintmax_t)(reglnum + reg_firstlnum) <= UINT32_MAX); + if (!REG_MULTI || !re_num_cmp((uint32_t)(reglnum + reg_firstlnum), + scan)) status = RA_NOMATCH; break; case RE_COL: - if (!re_num_cmp((long_u)(reginput - regline) + 1, scan)) + assert(reginput - regline + 1 >= 0 + && (uintmax_t)(reginput - regline + 1) <= UINT32_MAX); + if (!re_num_cmp((uint32_t)(reginput - regline + 1), scan)) status = RA_NOMATCH; break; case RE_VCOL: - if (!re_num_cmp((long_u)win_linetabsize( - reg_win == NULL ? curwin : reg_win, - regline, (colnr_T)(reginput - regline)) + 1, scan)) + if (!re_num_cmp(win_linetabsize(reg_win == NULL ? curwin : reg_win, + regline, + (colnr_T)(reginput - regline)) + 1, + scan)) status = RA_NOMATCH; break; @@ -5599,9 +5609,9 @@ static void save_se_one(save_se_T *savep, char_u **pp) /* * Compare a number with the operand of RE_LNUM, RE_COL or RE_VCOL. */ -static int re_num_cmp(long_u val, char_u *scan) +static int re_num_cmp(uint32_t val, char_u *scan) { - long_u n = OPERAND_MIN(scan); + uint32_t n = (uint32_t)OPERAND_MIN(scan); if (OPERAND_CMP(scan) == '>') return val > n; diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index fc3e73c396..b082903282 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -4,8 +4,10 @@ * This file is included in "regexp.c". */ +#include <assert.h> #include <inttypes.h> #include <stdbool.h> +#include <stdint.h> #include "nvim/ascii.h" #include "nvim/misc2.h" @@ -4403,7 +4405,7 @@ static void nfa_restore_listids(nfa_regprog_T *prog, int *list) } } -static int nfa_re_num_cmp(long_u val, int op, long_u pos) +static bool nfa_re_num_cmp(uintmax_t val, int op, uintmax_t pos) { if (op == 1) return pos > val; if (op == 2) return pos < val; @@ -5684,9 +5686,14 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, regsubs_T *subm case NFA_LNUM: case NFA_LNUM_GT: case NFA_LNUM_LT: - result = (REG_MULTI && - nfa_re_num_cmp(t->state->val, t->state->c - NFA_LNUM, - (long_u)(reglnum + reg_firstlnum))); + assert(t->state->val >= 0 + && !((reg_firstlnum > 0 && reglnum > LONG_MAX - reg_firstlnum) + || (reg_firstlnum <0 && reglnum < LONG_MIN + reg_firstlnum)) + && reglnum + reg_firstlnum >= 0); + result = (REG_MULTI + && nfa_re_num_cmp((uintmax_t)t->state->val, + t->state->c - NFA_LNUM, + (uintmax_t)(reglnum + reg_firstlnum))); if (result) { add_here = TRUE; add_state = t->state->out; @@ -5696,8 +5703,12 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, regsubs_T *subm case NFA_COL: case NFA_COL_GT: case NFA_COL_LT: - result = nfa_re_num_cmp(t->state->val, t->state->c - NFA_COL, - (long_u)(reginput - regline) + 1); + assert(t->state->val >= 0 + && reginput >= regline + && (uintmax_t)(reginput - regline) <= UINTMAX_MAX - 1); + result = nfa_re_num_cmp((uintmax_t)t->state->val, + t->state->c - NFA_COL, + (uintmax_t)(reginput - regline + 1)); if (result) { add_here = TRUE; add_state = t->state->out; @@ -5707,13 +5718,18 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, regsubs_T *subm case NFA_VCOL: case NFA_VCOL_GT: case NFA_VCOL_LT: - result = nfa_re_num_cmp(t->state->val, t->state->c - NFA_VCOL, - (long_u)win_linetabsize( - reg_win == NULL ? curwin : reg_win, - regline, (colnr_T)(reginput - regline)) + 1); - if (result) { - add_here = TRUE; - add_state = t->state->out; + { + uintmax_t lts = win_linetabsize(reg_win == NULL ? curwin : reg_win, + regline, + (colnr_T)(reginput - regline)); + assert(t->state->val >= 0); + result = nfa_re_num_cmp((uintmax_t)t->state->val, + t->state->c - NFA_VCOL, + lts + 1); + if (result) { + add_here = TRUE; + add_state = t->state->out; + } } break; diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 5e69a935ca..bb995fe3c2 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -289,6 +289,7 @@ #include <inttypes.h> #include <limits.h> #include <stdbool.h> +#include <stdint.h> #include <string.h> #include <stdlib.h> #include <wctype.h> @@ -6546,7 +6547,7 @@ node_compress ( n = np->wn_flags + (np->wn_region << 8) + (np->wn_affixID << 16); else // byte node: use the byte value and the child pointer - n = (unsigned)(np->wn_byte + ((long_u)np->wn_child << 8)); + n = (unsigned)(np->wn_byte + ((uintptr_t)np->wn_child << 8)); nr = nr * 101 + n; } diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 3980a4d8e6..f24b2aa80a 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -3837,7 +3837,7 @@ static void add_keyword(char_u *name, } kp->next_list = copy_id_list(next_list); - long_u hash = hash_hash(kp->keyword); + hash_T hash = hash_hash(kp->keyword); hashtab_T *ht = (curwin->w_s->b_syn_ic) ? &curwin->w_s->b_keywtab_ic : &curwin->w_s->b_keywtab; hashitem_T *hi = hash_lookup(ht, kp->keyword, hash); diff --git a/src/nvim/types.h b/src/nvim/types.h index c18c6abb4b..a87122d24b 100644 --- a/src/nvim/types.h +++ b/src/nvim/types.h @@ -13,11 +13,6 @@ // dummy to pass an ACL to a function typedef void *vim_acl_T; -// According to the vanilla Vim docs, long_u needs to be big enough to hold -// a pointer for the platform. On C99, this is easy to do with the uintptr_t -// type in lieu of the platform-specific typedefs that existed before. -typedef uintptr_t long_u; - /* * Shorthand for unsigned variables. Many systems, but not all, have u_char * already defined, so we use char_u to avoid trouble. diff --git a/src/nvim/version.c b/src/nvim/version.c index 3e214bfd30..83dc3c700b 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -253,9 +253,9 @@ static int included_patches[] = { //495 NA 494, 493, - //492, + 492, 491, - //490, + 490, 489, 488, 487, @@ -283,7 +283,7 @@ static int included_patches[] = { //465 NA //464 NA 463, - //462, + 462, //461 NA //460 NA //459 NA @@ -299,7 +299,7 @@ static int included_patches[] = { 449, //448 NA 447, - //446, + 446, //445, 444, //443 NA diff --git a/src/nvim/window.c b/src/nvim/window.c index cf0977e280..52a1853f4b 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -1024,7 +1024,7 @@ static void win_init(win_T *newp, win_T *oldp, int flags) } /* - * Initialize window "newp" from window"old". + * Initialize window "newp" from window "old". * Only the essential things are copied. */ static void win_init_some(win_T *newp, win_T *oldp) @@ -5190,8 +5190,8 @@ static win_T *restore_snapshot_rec(frame_T *sn, frame_T *fr) /* * Set "win" to be the curwin and "tp" to be the current tab page. - * restore_win() MUST be called to undo. - * No autocommands will be executed. + * restore_win() MUST be called to undo, also when FAIL is returned. + * No autocommands will be executed until restore_win() is called. * When "no_display" is TRUE the display won't be affected, no redraw is * triggered, another tabpage access is limited. * Returns FAIL if switching to "win" failed. @@ -5212,7 +5212,6 @@ int switch_win(win_T **save_curwin, tabpage_T **save_curtab, win_T *win, tabpage goto_tabpage_tp(tp, FALSE, FALSE); } if (!win_valid(win)) { - unblock_autocmds(); return FAIL; } curwin = win; diff --git a/test/functional/legacy/004_bufenter_with_modelines_spec.lua b/test/functional/legacy/004_bufenter_with_modelines_spec.lua index 6f009b52dd..34e702b798 100644 --- a/test/functional/legacy/004_bufenter_with_modelines_spec.lua +++ b/test/functional/legacy/004_bufenter_with_modelines_spec.lua @@ -46,6 +46,12 @@ describe('BufEnter with modelines', function() -- Include Xxx in the current file feed('G:r Xxx<CR>') + -- Vim issue #57 do not move cursor on <c-o> when autoindent is set + execute('set fo+=r') + feed('G') + feed('o# abcdef<Esc>2hi<CR><c-o>d0<Esc>') + feed('o# abcdef<Esc>2hi<c-o>d0<Esc>') + expect([[ startstart start of test file Xxx @@ -63,7 +69,10 @@ describe('BufEnter with modelines', function() this is a test this is a test this should be in column 1 - end of test file Xxx]]) + end of test file Xxx + # abc + def + def]]) end) teardown(function() diff --git a/test/functional/shell/viml_system_spec.lua b/test/functional/shell/viml_system_spec.lua index 48dc518d7b..25d2b5bc2c 100644 --- a/test/functional/shell/viml_system_spec.lua +++ b/test/functional/shell/viml_system_spec.lua @@ -6,6 +6,8 @@ local helpers = require('test.functional.helpers') local eq, clear, eval, feed, nvim = helpers.eq, helpers.clear, helpers.eval, helpers.feed, helpers.nvim +local Screen = require('test.functional.ui.screen') + local function create_file_with_nuls(name) return function() @@ -42,6 +44,81 @@ describe('system()', function() eq(127, eval('v:shell_error')) end) + describe('executes shell function', function() + local screen + + before_each(function() + clear() + screen = Screen.new() + screen:attach() + end) + + after_each(function() + screen:detach() + end) + + it('`echo` and waits for its return', function() + feed(':call system("echo")<cr>') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + :call system("echo") | + ]]) + end) + + it('`yes` and is directly interrupted with CTRL-C', function() + feed(':call system("yes")<cr><c-c>') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + Type :quit<Enter> to exit Vim | + ]]) + end) + + it('`yes` and is a little bit later interrupted with CTRL-C', function() + feed(':call system("yes")<cr>') + feed('<c-c>') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + Type :quit<Enter> to exit Vim | + ]]) + end) + end) + describe('passing no input', function() it('returns the program output', function() eq("echoed", eval('system("echo -n echoed")')) @@ -137,6 +214,81 @@ describe('systemlist()', function() eq(127, eval('v:shell_error')) end) + describe('exectues shell function', function() + local screen + + before_each(function() + clear() + screen = Screen.new() + screen:attach() + end) + + after_each(function() + screen:detach() + end) + + it('`echo` and waits for its return', function() + feed(':call systemlist("echo")<cr>') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + :call systemlist("echo") | + ]]) + end) + + it('`yes` and is directly interrupted with CTRL-C', function() + feed(':call systemlist("echo")<cr><c-c>') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + Type :quit<Enter> to exit Vim | + ]]) + end) + + it('`yes` and is a little bit later interrupted with CTRL-C', function() + feed(':call systemlist("echo")<cr>') + feed('<c-c>') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + Type :quit<Enter> to exit Vim | + ]]) + end) + end) + describe('passing string with linefeed characters as input', function() it('splits the output on linefeed characters', function() eq({'abc', 'def', 'ghi'}, eval([[systemlist("cat -", "abc\ndef\nghi")]])) diff --git a/test/unit/formatc.lua b/test/unit/formatc.lua index 792894f349..f9397eaec6 100644 --- a/test/unit/formatc.lua +++ b/test/unit/formatc.lua @@ -149,8 +149,7 @@ local C_keywords = set { -- }; -- -- would become: --- struct mystruct --- { int a; int b; }; +-- struct mystruct { int a; int b; }; -- -- The first one will have a lot of false positives (the line '{' for -- example), the second one is more unique. @@ -179,7 +178,8 @@ local function formatc(str) -- static and/or inline usually indicate an inline header function, -- which has no trailing ';', so we have to add a newline after the -- '}' ourselves. - if token[1] == 'static' or token[1] == 'inline' then + local tok = token[1] + if tok == 'static' or tok == 'inline' or tok == '__inline' then end_at_brace = true end elseif typ == 'preprocessor' then diff --git a/test/unit/os/fs_spec.lua b/test/unit/os/fs_spec.lua index 2d54dc6003..90f5a0b7de 100644 --- a/test/unit/os/fs_spec.lua +++ b/test/unit/os/fs_spec.lua @@ -33,11 +33,11 @@ local absolute_executable = nil local executable_name = nil local function assert_file_exists(filepath) - eq(false, nil == (lfs.attributes(filepath, 'r'))) + neq(nil, lfs.attributes(filepath)) end local function assert_file_does_not_exist(filepath) - eq(true, nil == (lfs.attributes(filepath, 'r'))) + eq(nil, lfs.attributes(filepath)) end describe('fs function', function() |