diff options
158 files changed, 4203 insertions, 1275 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index e3c67c55cd..4e427eea26 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -83,6 +83,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") endif() if(WIN32 OR CMAKE_SYSTEM_NAME STREQUAL "Darwin") + # Ignore case when comparing filenames on Windows and Mac. + set(CASE_INSENSITIVE_FILENAME TRUE) # Enable fixing case-insensitive filenames for Windows and Mac. set(USE_FNAME_CASE TRUE) endif() diff --git a/ci/build.ps1 b/ci/build.ps1 index db7026ac66..53e4328e02 100644 --- a/ci/build.ps1 +++ b/ci/build.ps1 @@ -88,11 +88,14 @@ elseif ($compiler -eq 'MSVC') { if (-not $NoTests) { # Setup python (use AppVeyor system python) - C:\hostedtoolcache\windows\Python\2.7.18\x64\python.exe -m pip install pynvim ; exitIfFailed - C:\hostedtoolcache\windows\Python\3.5.4\x64\python.exe -m pip install pynvim ; exitIfFailed - # Disambiguate python3 - move C:\hostedtoolcache\windows\Python\3.5.4\x64\python.exe C:\hostedtoolcache\windows\Python\3.5.4\x64\python3.exe - $env:PATH = "C:\hostedtoolcache\windows\Python\3.5.4\x64;C:\hostedtoolcache\windows\Python\2.7.18\x64;$env:PATH" + # Disambiguate python3, if needed + if (-not (Test-Path -Path C:\hostedtoolcache\windows\Python\3.5.4\x64\python3.exe) ) { + move C:\hostedtoolcache\windows\Python\3.5.4\x64\python.exe C:\hostedtoolcache\windows\Python\3.5.4\x64\python3.exe + } + $env:PATH = "C:\hostedtoolcache\windows\Python\2.7.18\x64;C:\hostedtoolcache\windows\Python\3.5.4\x64;$env:PATH" + + python -m pip install pynvim ; exitIfFailed + python3 -m pip install pynvim ; exitIfFailed # Sanity check python -c "import pynvim; print(str(pynvim))" ; exitIfFailed python3 -c "import pynvim; print(str(pynvim))" ; exitIfFailed diff --git a/config/config.h.in b/config/config.h.in index 95e2c872a3..275bff79a0 100644 --- a/config/config.h.in +++ b/config/config.h.in @@ -40,6 +40,7 @@ #cmakedefine HAVE_WORKING_LIBINTL #cmakedefine HAVE_WSL #cmakedefine UNIX +#cmakedefine CASE_INSENSITIVE_FILENAME #cmakedefine USE_FNAME_CASE #cmakedefine HAVE_SYS_UIO_H #ifdef HAVE_SYS_UIO_H diff --git a/contrib/flake.lock b/contrib/flake.lock new file mode 100644 index 0000000000..521b7629d9 --- /dev/null +++ b/contrib/flake.lock @@ -0,0 +1,43 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1610051610, + "narHash": "sha256-U9rPz/usA1/Aohhk7Cmc2gBrEEKRzcW4nwPWMPwja4Y=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "3982c9903e93927c2164caa727cd3f6a0e6d14cc", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1613226215, + "narHash": "sha256-3rA5cGIrBHD6yeKhNhsF7/t461ww25oJY8KyBb0IhjU=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "ff96a0fa5635770390b184ae74debea75c3fd534", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/contrib/flake.nix b/contrib/flake.nix index d18534215c..c86bba6809 100644 --- a/contrib/flake.nix +++ b/contrib/flake.nix @@ -27,22 +27,31 @@ }); # a development binary to help debug issues - neovim-debug = (neovim.override { - stdenv = if pkgs.stdenv.isLinux then pkgs.llvmPackages_latest.stdenv else pkgs.stdenv; + neovim-debug = let + stdenv = pkgs.stdenvAdapters.keepDebugInfo (if pkgs.stdenv.isLinux then pkgs.llvmPackages_latest.stdenv else pkgs.stdenv); + in + pkgs.enableDebugging ((neovim.override { lua = pkgs.enableDebugging pkgs.luajit; + inherit stdenv; }).overrideAttrs (oa: { cmakeBuildType = "Debug"; cmakeFlags = oa.cmakeFlags ++ [ "-DMIN_LOG_LEVEL=0" ]; - }); - # for neovim developers, very slow + disallowedReferences = []; + })); + + # for neovim developers, builds a slow binary + # huge closure size but aims at covering all scripts # brings development tools as well neovim-developer = let lib = nixpkgs.lib; - pythonEnv = pkgs.python3; + pythonEnv = pkgs.python3.withPackages(ps: [ + ps.msgpack + ps.flake8 # for 'make pylint' + ]); luacheck = pkgs.luaPackages.luacheck; in (neovim-debug.override ({ doCheck = pkgs.stdenv.isLinux; })).overrideAttrs (oa: { @@ -51,7 +60,7 @@ "-DMIN_LOG_LEVEL=0" "-DENABLE_LTO=OFF" "-DUSE_BUNDLED=OFF" - ] ++ pkgs.stdenv.lib.optionals pkgs.stdenv.isLinux [ + ] ++ pkgs.lib.optionals pkgs.stdenv.isLinux [ # https://github.com/google/sanitizers/wiki/AddressSanitizerFlags # https://clang.llvm.org/docs/AddressSanitizer.html#symbolizing-the-reports "-DCLANG_ASAN_UBSAN=ON" @@ -61,7 +70,8 @@ pythonEnv include-what-you-use # for scripts/check-includes.py jq # jq for scripts/vim-patch.sh -r - doxygen + shellcheck # for `make shlint` + doxygen # for script/gen_vimdoc.py ]); shellHook = oa.shellHook + '' @@ -97,6 +107,5 @@ defaultApp = apps.nvim; devShell = pkgs.neovim-developer; - } - ); + }); } diff --git a/runtime/autoload/haskellcomplete.vim b/runtime/autoload/haskellcomplete.vim index 520ab93700..48fbac7f9f 100644 --- a/runtime/autoload/haskellcomplete.vim +++ b/runtime/autoload/haskellcomplete.vim @@ -2,7 +2,7 @@ " Language: Haskell " Maintainer: Daniel Campoverde <alx@sillybytes.net> " URL: https://github.com/alx741/haskellcomplete.vim -" Last Change: 2018 Aug 26 +" Last Change: 2019 May 14 " Usage: setlocal omnifunc=haskellcomplete#Complete @@ -63,6 +63,7 @@ function! haskellcomplete#Complete(findstart, base) call add(l:matches, extension) endif endfor + let b:completingLangExtension = 0 return l:matches endif @@ -78,6 +79,7 @@ function! haskellcomplete#Complete(findstart, base) call add(l:matches, flag) endif endfor + let b:completingOptionsGHC = 0 return l:matches endif @@ -93,6 +95,7 @@ function! haskellcomplete#Complete(findstart, base) call add(l:matches, module) endif endfor + let b:completingModule = 0 return l:matches endif diff --git a/runtime/autoload/health/nvim.vim b/runtime/autoload/health/nvim.vim index 8b734bbb6f..0bb343e198 100644 --- a/runtime/autoload/health/nvim.vim +++ b/runtime/autoload/health/nvim.vim @@ -42,7 +42,7 @@ function! s:check_config() abort endif let writeable = v:true - let shadafile = substitute(matchstr( + let shadafile = empty(&shada) ? &shada : substitute(matchstr( \ split(&shada, ',')[-1], '^n.\+'), '^n', '', '') let shadafile = empty(&shadafile) ? empty(shadafile) ? \ stdpath('data').'/shada/main.shada' : expand(shadafile) @@ -247,6 +247,10 @@ function! s:check_terminal() abort let kdch1_entry = matchstr(out, 'key_dc=[^,[:space:]]*') if v:shell_error + \ && (!has('win32') + \ || empty(matchstr(out, + \ 'infocmp: couldn''t open terminfo file .\+' + \ ..'\%(conemu\|vtpcon\|win32con\)'))) call health#report_error('command failed: '.cmd."\n".out) else call health#report_info('key_backspace (kbs) terminfo entry: ' diff --git a/runtime/autoload/man.vim b/runtime/autoload/man.vim index 78a86315a3..c629923cd3 100644 --- a/runtime/autoload/man.vim +++ b/runtime/autoload/man.vim @@ -51,7 +51,7 @@ function! man#open_page(count, mods, ...) abort let [l:buf, l:save_tfu] = [bufnr(), &tagfunc] try - set tagfunc=man#goto_tag + setlocal tagfunc=man#goto_tag let l:target = l:name . '(' . l:sect . ')' if a:mods !~# 'tab' && s:find_man() execute 'silent keepalt tag' l:target diff --git a/runtime/autoload/netrw.vim b/runtime/autoload/netrw.vim index b69ad7187a..7a799abb13 100644 --- a/runtime/autoload/netrw.vim +++ b/runtime/autoload/netrw.vim @@ -1,8 +1,8 @@ " netrw.vim: Handles file transfer and remote directory listing across " AUTOLOAD SECTION -" Date: Jul 16, 2019 -" Version: 165 -" Maintainer: Charles E Campbell <NdrOchip@ScampbellPfamily.AbizM-NOSPAM> +" Date: Jan 07, 2020 +" Version: 168 +" Maintainer: Charles E Campbell <NcampObell@SdrPchip.AorgM-NOSPAM> " GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim " Copyright: Copyright (C) 2016 Charles E. Campbell {{{1 " Permission is hereby granted to use and distribute this code, @@ -13,6 +13,10 @@ " expressed or implied. By using this plugin, you agree that " in no event will the copyright holder be liable for any damages " resulting from the use of this software. +" +" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing +" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7). +" "redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore() " " But be doers of the Word, and not only hearers, deluding your own selves {{{1 @@ -39,7 +43,7 @@ if exists("s:needspatches") endfor endif -let g:loaded_netrw = "v165" +let g:loaded_netrw = "v168" if !exists("s:NOTE") let s:NOTE = 0 let s:WARNING = 1 @@ -64,7 +68,7 @@ setl cpo&vim " Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number) " netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number) " (this function can optionally take a list of messages) -" Mar 21, 2017 : max errnum currently is 105 +" Dec 2, 2019 : max errnum currently is 106 fun! netrw#ErrorMsg(level,msg,errnum) " call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow) @@ -232,12 +236,12 @@ if !exists("g:netrw_ftp_options") let g:netrw_ftp_options= "-i -n" endif if !exists("g:netrw_http_cmd") - if executable("curl") - let g:netrw_http_cmd = "curl" - call s:NetrwInit("g:netrw_http_xcmd","-L -o") - elseif executable("wget") + if executable("wget") let g:netrw_http_cmd = "wget" call s:NetrwInit("g:netrw_http_xcmd","-q -O") + elseif executable("curl") + let g:netrw_http_cmd = "curl" + call s:NetrwInit("g:netrw_http_xcmd","-L -o") elseif executable("elinks") let g:netrw_http_cmd = "elinks" call s:NetrwInit("g:netrw_http_xcmd","-source >") @@ -443,23 +447,9 @@ if !exists("g:netrw_localmovecmd") let g:netrw_localmovecmd= "" endif endif -if v:version < 704 || (v:version == 704 && !has("patch1107")) - " 1109 provides for delete(tmpdir,"d") which is what will be used - if exists("g:netrw_local_rmdir") - let g:netrw_localrmdir= g:netrw_local_rmdir - call netrw#ErrorMsg(s:NOTE,"g:netrw_local_rmdir is deprecated in favor of g:netrw_localrmdir",86) - endif - if has("win32") || has("win95") || has("win64") || has("win16") - if g:netrw_cygwin - call s:NetrwInit("g:netrw_localrmdir","rmdir") - else - let g:netrw_localrmdir = expand("$COMSPEC") - let g:netrw_localrmdiropt= " /c rmdir" - endif - else - call s:NetrwInit("g:netrw_localrmdir","rmdir") - endif -endif +" following serves as an example for how to insert a version&patch specific test +"if v:version < 704 || (v:version == 704 && !has("patch1107")) +"endif call s:NetrwInit("g:netrw_liststyle" , s:THINLIST) " sanity checks if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST @@ -1500,7 +1490,8 @@ fun! netrw#Obtain(islocal,fname,...) " -i : turns off interactive prompting from ftp " -n unix : DON'T use <.netrc>, even though it exists " -n win32: quit being obnoxious about password - NetrwKeepj norm! 1Gdd + " Note: using "_dd to delete to the black hole register; avoids messing up @@ + NetrwKeepj norm! 1G"_dd call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options) " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) if getline(1) !~ "^$" @@ -1614,7 +1605,6 @@ fun! s:NetrwOptionsSave(vt) let {a:vt}netrw_cpokeep = &l:cpo let {a:vt}netrw_diffkeep = &l:diff let {a:vt}netrw_fenkeep = &l:fen -" call Decho("saving current settings: got here#1",'~'.expand("<slnum>")) if !exists("g:netrw_ffkeep") || g:netrw_ffkeep let {a:vt}netrw_ffkeep = &l:ff endif @@ -1633,7 +1623,6 @@ fun! s:NetrwOptionsSave(vt) let {a:vt}netrw_rokeep = &l:ro let {a:vt}netrw_selkeep = &l:sel let {a:vt}netrw_spellkeep = &l:spell -" call Decho("saving current settings: got here#2",'~'.expand("<slnum>")) if !g:netrw_use_noswf let {a:vt}netrw_swfkeep = &l:swf endif @@ -1647,6 +1636,7 @@ fun! s:NetrwOptionsSave(vt) " call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>")) if g:netrw_keepdir let {a:vt}netrw_dirkeep = getcwd() +" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>")) endif sil! let {a:vt}netrw_slashkeep= @/ @@ -1713,6 +1703,7 @@ fun! s:NetrwOptionsRestore(vt) " call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$")) " call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>")) if !exists("{a:vt}netrw_optionsave") +" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>")) " call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>")) " call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>")) " call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist") @@ -1854,7 +1845,7 @@ endfun " Used by s:NetrwOptionsRestore() to restore each netrw-senstive setting " keepvars are set up by s:NetrwOptionsSave fun! s:NetrwRestoreSetting(keepvar,setting) -"" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)") +""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)") " typically called from s:NetrwOptionsRestore " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option') @@ -1869,7 +1860,7 @@ fun! s:NetrwRestoreSetting(keepvar,setting) "" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">") if setting != keepvarval -"" call Decho("restore setting<".a:setting."=".setting."> to keepvarval<".keepvarval.">") +"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">") if type(a:setting) == 0 exe "let ".a:setting."= ".keepvarval elseif type(a:setting) == 1 @@ -2159,7 +2150,7 @@ fun! netrw#NetRead(mode,...) " -i : turns off interactive prompting from ftp " -n unix : DON'T use <.netrc>, even though it exists " -n win32: quit being obnoxious about password - NetrwKeepj norm! 1Gdd + NetrwKeepj norm! 1G"_dd call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options) " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) if getline(1) !~ "^$" @@ -2259,7 +2250,7 @@ fun! netrw#NetRead(mode,...) NetrwKeepj put ='quit' " perform cadaver operation: - NetrwKeepj norm! 1Gdd + NetrwKeepj norm! 1G"_dd call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd) keepj bd! endif @@ -2575,7 +2566,7 @@ fun! netrw#NetWrite(...) range " -i : turns off interactive prompting from ftp " -n unix : DON'T use <.netrc>, even though it exists " -n win32: quit being obnoxious about password - NetrwKeepj norm! 1Gdd + NetrwKeepj norm! 1G"_dd call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options) " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) if getline(1) !~ "^$" @@ -2641,7 +2632,7 @@ fun! netrw#NetWrite(...) range NetrwKeepj put ='put '.tmpfile.' '.netrw_fname " perform cadaver operation: - NetrwKeepj norm! 1Gdd + NetrwKeepj norm! 1G"_dd call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd) " remove enew buffer (quietly) @@ -2827,7 +2818,7 @@ fun! s:NetrwGetFile(readcmd, tfile, method) " readcmd=='t': simply do nothing if a:readcmd == 't' " call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>")) -" call Dret("NetrwGetFile : skip read of <".a:tfile.">") +" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">") return endif @@ -4323,7 +4314,7 @@ fun! s:NetrwGetWord() let curline= getline('.') if curline =~# '"\s*Sorted by\s' - NetrwKeepj norm! s + NetrwKeepj norm! "_s let s:netrw_skipbrowse= 1 echo 'Pressing "s" also works' @@ -5158,17 +5149,31 @@ fun! s:NetrwBrowseUpDir(islocal) endfun " --------------------------------------------------------------------- -" netrw#BrowseX: (implements "x") executes a special "viewer" script or program for the {{{2 +" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2 " given filename; typically this means given their extension. " 0=local, 1=remote fun! netrw#BrowseX(fname,remote) -" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.")") - - " if its really just a local directory, then do a "gf" instead - if (a:remote == 0 && isdirectory(a:fname)) || (a:remote == 1 && a:fname =~ '/$' && a:fname !~ '^https\=:') + let use_ctrlo= 1 +" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps") + + if a:remote == 0 && isdirectory(a:fname) + " if its really just a local directory, then do a "gf" instead +" call Decho("remote≡0 and a:fname<".a:fname."> ".(isdirectory(a:fname)? "is a directory" : "is not a directory"),'~'.expand("<slnum>")) +" call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>")) + exe "e ".a:fname +" call Dret("netrw#BrowseX") + return + elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$' + " remote directory, not a webpage access, looks like an attempt to do a directory listing +" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>")) +" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>")) +" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>")) +" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>")) norm! gf -" call Dret("(netrw#BrowseX) did gf instead") +" call Dret("netrw#BrowseX") + return endif +" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>")) let ykeep = @@ let screenposn = winsaveview() @@ -5266,10 +5271,9 @@ fun! netrw#BrowseX(fname,remote) endif " call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>")) - " extract any viewing options. Assumes that they're set apart by quotes. -" call Decho("extract any viewing options",'~'.expand("<slnum>")) + " extract any viewing options. Assumes that they're set apart by spaces. if exists("g:netrw_browsex_viewer") -" call Decho("g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>")) +" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>")) if g:netrw_browsex_viewer =~ '\s' let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','') let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." " @@ -5292,16 +5296,16 @@ fun! netrw#BrowseX(fname,remote) " execute the file handler " call Decho("execute the file handler (if any)",'~'.expand("<slnum>")) if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-' -" call Decho("g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>")) +" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>")) let ret= netrwFileHandlers#Invoke(exten,fname) elseif exists("g:netrw_browsex_viewer") && executable(viewer) -" call Decho("g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>")) +" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>")) call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir) let ret= v:shell_error elseif has("win32") || has("win64") -" call Decho("win".(has("win32")? "32" : "64")",'~'.expand("<slnum>")) +" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>")) if executable("start") call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1)) elseif executable("rundll32") @@ -5309,56 +5313,68 @@ fun! netrw#BrowseX(fname,remote) else call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74) endif - " call inputsave()|call input("Press <cr> to continue")|call inputrestore() let ret= v:shell_error elseif has("win32unix") let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g') -" call Decho("cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>")) +" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>")) if executable("start") +" call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>")) call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1)) elseif executable("rundll32") +" call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>")) call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1)) elseif executable("cygstart") +" call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>")) call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1)) else call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74) endif - " call inputsave()|call input("Press <cr> to continue")|call inputrestore() let ret= v:shell_error elseif has("unix") && executable("kfmclient") && s:CheckIfKde() -" call Decho("unix and kfmclient",'~'.expand("<slnum>")) +" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>")) call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir) let ret= v:shell_error elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid") -" call Decho("unix, exo-open, xdg-open",'~'.expand("<slnum>")) +" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>")) call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir) let ret= v:shell_error elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril") -" call Decho("unix and atril",'~'.expand("<slnum>")) - call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir) +" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>")) + if a:fname =~ '^https\=://' + " atril does not appear to understand how to handle html -- so use gvim to edit the document + let use_ctrlo= 0 +" call Decho("(COMBAK) fname<".fname.">") +" call Decho("(COMBAK) a:fname<".a:fname.">") + call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"') + + else + call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir) + endif let ret= v:shell_error elseif has("unix") && executable("xdg-open") -" call Decho("unix and xdg-open",'~'.expand("<slnum>")) +" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>")) call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir) let ret= v:shell_error elseif has("macunix") && executable("open") -" call Decho("macunix and open",'~'.expand("<slnum>")) +" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>")) call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir) let ret= v:shell_error else " netrwFileHandlers#Invoke() always returns 0 +" call Decho("(netrw#BrowseX) use netrwFileHandlers",'~'.expand("<slnum>")) let ret= netrwFileHandlers#Invoke(exten,fname) endif " if unsuccessful, attempt netrwFileHandlers#Invoke() if ret +" call Decho("(netrw#BrowseX) ret=".ret," indicates unsuccessful thus far",'~'.expand("<slnum>")) let ret= netrwFileHandlers#Invoke(exten,fname) endif @@ -5380,8 +5396,9 @@ fun! netrw#BrowseX(fname,remote) if g:netrw_use_noswf setl noswf endif - exe "sil! NetrwKeepj norm! \<c-o>" -" redraw! + if use_ctrlo + exe "sil! NetrwKeepj norm! \<c-o>" + endif endif " call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>")) call winrestview(screenposn) @@ -5410,11 +5427,11 @@ endfun " netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2 fun! netrw#BrowseXVis() " call Dfunc("netrw#BrowseXVis()") - let atkeep = @@ - norm! gvy -" call Decho("@@<".@@.">",'~'.expand("<slnum>")) - call netrw#BrowseX(@@,netrw#CheckIfRemote(@@)) - let @@ = atkeep + let akeep = @a + norm! gv"ay + let gxfile= @a + let @a = akeep + call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile)) " call Dret("netrw#BrowseXVis") endfun @@ -5764,22 +5781,7 @@ fun! s:NetrwHome() if exists("g:netrw_home") let home= expand(g:netrw_home) else - " go to vim plugin home - for home in split(&rtp,',') + [''] - if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif - let basehome= substitute(home,'[/\\]\.vim$','','') - if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome)) - let home= basehome."/.vim" - break - endif - endfor - if home == "" - " just pick the first directory - let home= substitute(&rtp,',.*$','','') - endif - if (has("win32") || has("win95") || has("win64") || has("win16")) - let home= substitute(home,'/','\\','g') - endif + let home = stdpath('data') endif " insure that the home directory exists if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home)) @@ -6039,13 +6041,12 @@ fun! s:NetrwSLeftrelease(islocal) endfun " --------------------------------------------------------------------- -" s:NetrwListHide: uses [range]g~...~d to delete files that match comma {{{2 -" separated patterns given in g:netrw_list_hide +" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2 +" comma-separated patterns given in g:netrw_list_hide fun! s:NetrwListHide() " call Dfunc("s:NetrwListHide() g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">") " call Decho("initial: ".string(getline(w:netrw_bannercnt,'$'))) let ykeep= @@ -" call DechoBuf(bufnr("%"),"COMBAK#3") " find a character not in the "hide" string to use as a separator for :g and :v commands " How-it-works: take the hiding command, convert it into a range. @@ -6054,8 +6055,8 @@ fun! s:NetrwListHide() " Use the first character left as a separator character. " call Decho("find a character not in the hide string to use as a separator") let listhide= g:netrw_list_hide - let sep = strpart(substitute('/~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1) -" call Decho("sep=".sep,'~'.expand("<slnum>")) + let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1) +" call Decho("sep=".sep," (sep not in hide string)'~'.expand("<slnum>")) while listhide != "" if listhide =~ ',' @@ -6065,10 +6066,19 @@ fun! s:NetrwListHide() let hide = listhide let listhide = "" endif -" call Decho("hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>")) +" call Decho("..extracted from listhide: hide<".hide."> g:netrw_sort_by<".g:netrw_sort_by.'>','~'.expand("<slnum>")) + if g:netrw_sort_by =~ '^[ts]' + if hide =~ '^\^' +" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>")) + let hide= substitute(hide,'^\^','^\(\\d\\+/\)','') + elseif hide =~ '^\\(\^' + let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','') + endif +" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>")) + endif " Prune the list by hiding any files which match -" call Decho("prune the list by hiding any files which ",((g:netrw_hide == 1)? "" : "don't")." match hide<".hide.">") +" call Decho("..prune the list by hiding any files which ",((g:netrw_hide == 1)? "" : "don't")." match hide<".hide.">") if g:netrw_hide == 1 " call Decho("..hiding<".hide.">",'~'.expand("<slnum>")) exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d' @@ -6089,7 +6099,6 @@ fun! s:NetrwListHide() " remove any blank lines that have somehow remained. " This seems to happen under Windows. exe 'sil! NetrwKeepj 1,$g@^\s*$@d' -" call DechoBuf(bufnr("%"),"COMBAK#4") let @@= ykeep " call Dret("s:NetrwListHide") @@ -6297,7 +6306,7 @@ fun! s:NetrwMaps(islocal) " generate default <Plug> maps {{{3 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif - if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir |endif + if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif @@ -6614,9 +6623,9 @@ fun! s:NetrwMarkFiles(islocal,...) while i <= a:0 if a:islocal if v:version > 704 || (v:version == 704 && has("patch656")) - let mffiles= glob(fnameescape(a:{i}),0,1,1) + let mffiles= glob(a:{i},0,1,1) else - let mffiles= glob(fnameescape(a:{i}),0,1) + let mffiles= glob(a:{i},0,1) endif else let mffiles= [a:{i}] @@ -6757,13 +6766,15 @@ fun! s:NetrwMarkFile(islocal,fname) if index(s:netrwmarkfilelist,dname) == -1 " append new filename to global markfilelist call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname)) -" call Decho("append filename<".a:fname."> to global markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>")) +" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>")) else " remove new filename from global markfilelist -" call Decho("filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>")) +" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>")) +" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>")) call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"') -" call Decho("ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>")) +" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>")) if s:netrwmarkfilelist == [] +" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>")) unlet s:netrwmarkfilelist endif endif @@ -6787,7 +6798,8 @@ fun! s:NetrwMarkFile(islocal,fname) endif endif let @@= ykeep -" call Dret("s:NetrwMarkFile : s:netrwmarkfilelist_".curbufnr."<".(exists("s:netrwmarkfilelist_{curbufnr}")? string(s:netrwmarkfilelist_{curbufnr}) : " doesn't exist").">") +" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>")) +" call Dret("s:NetrwMarkFile : s:netrwmarkfilelist_".curbufnr."<".(exists("s:netrwmarkfilelist_{curbufnr}")? string(s:netrwmarkfilelist_{curbufnr}) : " doesn't exist")."> (buf#".curbufnr."list)") endfun " --------------------------------------------------------------------- @@ -7078,17 +7090,8 @@ fun! s:NetrwMarkFileCopy(islocal,...) " call Dret("s:NetrwMarkFileCopy : lcd failure") return endif - if v:version < 704 || (v:version == 704 && !has("patch1107")) - call s:NetrwExe("sil !".g:netrw_localrmdir.g:netrw_localrmdiropt." ".s:ShellEscape(tmpdir,1)) - if v:shell_error != 0 - call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localrmdir<".g:netrw_localrmdir."> to something that works",80) -" " call Dret("s:NetrwMarkFileCopy : failed: sil !".g:netrw_localrmdir." ".s:ShellEscape(tmpdir,1) ) - return - endif - else - if delete(tmpdir,"d") - call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103) - endif + if delete(tmpdir,"d") + call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103) endif else if s:NetrwLcd(curdir) @@ -7542,8 +7545,9 @@ fun! s:NetrwMarkFileGrep(islocal) let curdir = s:NetrwGetCurdir(a:islocal) if exists("s:netrwmarkfilelist") -" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>")) +" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>")) let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)")) +" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))" call s:NetrwUnmarkAll() else " call Decho('no marked files, using "*"','~'.expand("<slnum>")) @@ -7551,6 +7555,7 @@ fun! s:NetrwMarkFileGrep(islocal) endif " ask user for pattern +" call Decho("ask user for search pattern",'~'.expand("<slnum>")) call inputsave() let pat= input("Enter pattern: ","") call inputrestore() @@ -8663,7 +8668,7 @@ fun! s:NetrwUpload(fname,tgt,...) " -i : turns off interactive prompting from ftp " -n unix : DON'T use <.netrc>, even though it exists " -n win32: quit being obnoxious about password - NetrwKeepj norm! 1Gdd + NetrwKeepj norm! 1G"_dd call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options) " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) sil NetrwKeepj g/Local directory now/d @@ -9501,15 +9506,19 @@ fun! s:NetrwWideListing() " fpl: filenames per line " fpc: filenames per column setl ma noro + let keepa= @a " call Decho("setl ma noro",'~'.expand("<slnum>")) let b:netrw_cpf= 0 if line("$") >= w:netrw_bannercnt + " determine the maximum filename size; use that to set cpf exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif' NetrwKeepj call histdel("/",-1) else + let @a= keepa " call Dret("NetrwWideListing") return endif + " allow for two spaces to separate columns let b:netrw_cpf= b:netrw_cpf + 2 " call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>")) @@ -9532,10 +9541,11 @@ fun! s:NetrwWideListing() if newcolend > line("$") | let newcolend= line("$") | endif let newcolqty= newcolend - newcolstart exe newcolstart + " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @* if newcolqty == 0 - exe "sil! NetrwKeepj norm! 0\<c-v>$hx".w:netrw_bannercnt."G$p" + exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap" else - exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$hx'.w:netrw_bannercnt.'G$p' + exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap' endif exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _' exe 'sil! NetrwKeepj '.w:netrw_bannercnt @@ -9546,6 +9556,7 @@ fun! s:NetrwWideListing() exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>" " call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>")) exe "setl ".g:netrw_bufsettings + let @a= keepa " call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>")) " call Dret("NetrwWideListing") return @@ -9743,6 +9754,7 @@ fun! s:PerformListing(islocal) exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options endif endif + " remove priority pattern prefix " call Decho("remove priority pattern prefix",'~'.expand("<slnum>")) exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e' @@ -9781,6 +9793,7 @@ fun! s:PerformListing(islocal) " call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>")) exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options endif +" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>")) exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e' NetrwKeepj call histdel("/",-1) endif @@ -9843,6 +9856,7 @@ fun! s:PerformListing(islocal) " call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>")) exe "setl ts=".(g:netrw_maxfilenamelen+1) endif +" call Decho("PerformListing buffer:",'~'.expand("<slnum>")) " call DechoBuf(bufnr("%")) if exists("s:treecurpos") @@ -10810,7 +10824,6 @@ fun! s:LocalListing() for filename in filelist " call Decho(" ",'~'.expand("<slnum>")) " call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>")) -" call DechoBuf(bufnr("%"),"COMBAK#1") if getftype(filename) == "link" " indicate a symbolic link @@ -10868,10 +10881,10 @@ fun! s:LocalListing() if w:netrw_liststyle == s:LONGLIST let sz = getfsize(filename) + let fsz = strpart(" ",1,15-strlen(sz)).sz if g:netrw_sizestyle =~# "[hH]" let sz= s:NetrwHumanReadable(sz) endif - let fsz = strpart(" ",1,15-strlen(sz)).sz let longfile= printf("%-".(g:netrw_maxfilenamelen+1)."s",pfile) let pfile = longfile.fsz." ".strftime(g:netrw_timefmt,getftime(filename)) " call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>")) @@ -10879,10 +10892,11 @@ fun! s:LocalListing() if g:netrw_sort_by =~# "^t" " sort by time (handles time up to 1 quintillion seconds, US) + " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time. " call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>")) let t = getftime(filename) let ft = strpart("000000000000000000",1,18-strlen(t)).t -" call Decho("exe NetrwKeepj put ='".ft.'/'.filename."'",'~'.expand("<slnum>")) +" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>")) let ftpfile= ft.'/'.pfile sil! NetrwKeepj put=ftpfile @@ -10903,7 +10917,7 @@ fun! s:LocalListing() " call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>")) sil! NetrwKeepj put=pfile endif -" call DechoBuf(bufnr("%"),"COMBAK#2") +" call DechoBuf(bufnr("%"),"bufnr(%)") endfor " cleanup any windows mess at end-of-line @@ -10950,9 +10964,10 @@ fun! s:NetrwLocalRename(path) range " call Dfunc("NetrwLocalRename(path<".a:path.">)") " preparation for removing multiple files/directories - let ykeep = @@ - let ctr = a:firstline - let svpos = winsaveview() + let ykeep = @@ + let ctr = a:firstline + let svpos = winsaveview() + let all = 0 " call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>")) " rename files given by the markfilelist @@ -10980,6 +10995,23 @@ fun! s:NetrwLocalRename(path) range let newname = substitute(oldname,subfrom,subto,'') endif endif + if !all && filereadable(newname) + call inputsave() + let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ") + call inputrestore() + if response == "all" + let all= 1 + elseif response != "y" && response != "yes" + " refresh the directory +" call Decho("refresh the directory listing",'~'.expand("<slnum>")) + NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./')) +" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>")) + NetrwKeepj call winrestview(svpos) + let @@= ykeep +" call Dret("NetrwLocalRename") + return + endif + endif call rename(oldname,newname) endfor call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir) @@ -11003,14 +11035,14 @@ fun! s:NetrwLocalRename(path) range NetrwKeepj norm! 0 let oldname= s:ComposePath(a:path,curword) -" call Decho("oldname<".oldname.">",'~'.expand("<slnum>")) +" call Decho("oldname<".oldname.">",'~'.expand("<slnum>")) call inputsave() let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e')) call inputrestore() call rename(oldname,newname) -" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>")) +" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>")) let ctr= ctr + 1 endwhile @@ -11220,7 +11252,9 @@ fun! netrw#Expose(varname) " call Dfunc("netrw#Expose(varname<".a:varname.">)") if exists("s:".a:varname) exe "let retval= s:".a:varname +" call Decho("retval=".retval,'~'.expand("<slnum>")) if exists("g:netrw_pchk") +" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>")) if type(retval) == 3 let retval = copy(retval) let i = 0 @@ -11229,10 +11263,13 @@ fun! netrw#Expose(varname) let i = i + 1 endwhile endif -" call Dret("netrw#Expose ".string(retval)) +" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>")) return string(retval) + else +" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>")) endif else +" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>")) let retval= "n/a" endif @@ -11793,6 +11830,9 @@ fun! s:NetrwExe(cmd) " call Decho("exe ".a:cmd,'~'.expand("<slnum>")) exe a:cmd endif + if v:shell_error + call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106) + endif " call Dret("s:NetrwExe : v:shell_error=".v:shell_error) endfun diff --git a/runtime/autoload/netrwSettings.vim b/runtime/autoload/netrwSettings.vim index 327db6a540..bed5cfc455 100644 --- a/runtime/autoload/netrwSettings.vim +++ b/runtime/autoload/netrwSettings.vim @@ -1,6 +1,6 @@ " netrwSettings.vim: makes netrw settings simpler " Date: Nov 09, 2016 -" Maintainer: Charles E Campbell <drchipNOSPAM at campbellfamily dot biz> +" Maintainer: Charles E Campbell <NcampObell@SdrPchip.AorgM-NOSPAM> " Version: 16 " Copyright: Copyright (C) 1999-2007 Charles E. Campbell {{{1 " Permission is hereby granted to use and distribute this code, diff --git a/runtime/autoload/netrw_gitignore.vim b/runtime/autoload/netrw_gitignore.vim index da3f50bca0..1b55e2488a 100644 --- a/runtime/autoload/netrw_gitignore.vim +++ b/runtime/autoload/netrw_gitignore.vim @@ -18,61 +18,5 @@ " holder be liable for any damages resulting from the use " of this software. function! netrw_gitignore#Hide(...) - let additional_files = a:000 - - let default_files = ['.gitignore', '.git/info/exclude'] - - " get existing global/system gitignore files - let global_gitignore = expand(substitute(system("git config --global core.excludesfile"), '\n', '', 'g')) - if global_gitignore !=# '' - let default_files = add(default_files, global_gitignore) - endif - let system_gitignore = expand(substitute(system("git config --system core.excludesfile"), '\n', '', 'g')) - if system_gitignore !=# '' - let default_files = add(default_files, system_gitignore) - endif - - " append additional files if given as function arguments - if additional_files !=# [] - let files = extend(default_files, additional_files) - else - let files = default_files - endif - - " keep only existing/readable files - let gitignore_files = [] - for file in files - if filereadable(file) - let gitignore_files = add(gitignore_files, file) - endif - endfor - - " get contents of gitignore patterns from those files - let gitignore_lines = [] - for file in gitignore_files - for line in readfile(file) - " filter empty lines and comments - if line !~# '^#' && line !~# '^$' - let gitignore_lines = add(gitignore_lines, line) - endif - endfor - endfor - - " convert gitignore patterns to Netrw/Vim regex patterns - let escaped_lines = [] - for line in gitignore_lines - let escaped = line - let escaped = substitute(escaped, '\*\*', '*', 'g') - let escaped = substitute(escaped, '\.', '\\.', 'g') - let escaped = substitute(escaped, '\$', '\\$', 'g') - let escaped = substitute(escaped, '*', '.*', 'g') - " correction: dot, dollar and asterisks chars shouldn't be escaped when - " within regex matching groups. - let escaped = substitute(escaped, '\(\[[^]]*\)\zs\\\.', '\.', 'g') - let escaped = substitute(escaped, '\(\[[^]]*\)\zs\\\$', '\$', 'g') - let escaped = substitute(escaped, '\(\[[^]]*\)\zs\.\*', '*', 'g') - let escaped_lines = add(escaped_lines, escaped) - endfor - - return join(escaped_lines, ',') + return substitute(substitute(system('git ls-files --other --ignored --exclude-standard --directory'), '\n', ',', 'g'), ',$', '', '') endfunction diff --git a/runtime/autoload/tar.vim b/runtime/autoload/tar.vim index dc670dbd14..b6c4c660b8 100644 --- a/runtime/autoload/tar.vim +++ b/runtime/autoload/tar.vim @@ -1,13 +1,13 @@ " tar.vim: Handles browsing tarfiles " AUTOLOAD PORTION -" Date: Apr 17, 2013 -" Version: 29 -" Maintainer: Charles E Campbell <NdrOchip@ScampbellPfamily.AbizM-NOSPAM> -" License: Vim License (see vim's :help license) +" Date: Jan 07, 2020 +" Version: 32 +" Maintainer: Charles E Campbell <NcampObell@SdrPchip.AorgM-NOSPAM> +" License: Vim License (see vim's :help license) " " Contains many ideas from Michael Toren's <tar.vim> " -" Copyright: Copyright (C) 2005-2011 Charles E. Campbell {{{1 +" Copyright: Copyright (C) 2005-2017 Charles E. Campbell {{{1 " Permission is hereby granted to use and distribute this code, " with or without modifications, provided that this copyright " notice is copied with it. Like anything else that's free, @@ -22,7 +22,7 @@ if &cp || exists("g:loaded_tar") finish endif -let g:loaded_tar= "v29" +let g:loaded_tar= "v32" if v:version < 702 echohl WarningMsg echo "***warning*** this version of tar needs vim 7.2" @@ -48,6 +48,9 @@ endif if !exists("g:tar_writeoptions") let g:tar_writeoptions= "uf" endif +if !exists("g:tar_delfile") + let g:tar_delfile="--delete -f" +endif if !exists("g:netrw_cygwin") if has("win32") || has("win95") || has("win64") || has("win16") if &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$' @@ -109,6 +112,7 @@ fun! tar#Browse(tarfile) " sanity checks if !executable(g:tar_cmd) redraw! +" call Decho('***error*** (tar#Browse) "'.g:tar_cmd.'" not available on your system') echohl Error | echo '***error*** (tar#Browse) "'.g:tar_cmd.'" not available on your system' let &report= repkeep " call Dret("tar#Browse") @@ -119,6 +123,7 @@ fun! tar#Browse(tarfile) if a:tarfile !~# '^\a\+://' " if it's an url, don't complain, let url-handlers such as vim do its thing redraw! +" call Decho("***error*** (tar#Browse) File not readable<".a:tarfile.">") echohl Error | echo "***error*** (tar#Browse) File not readable<".a:tarfile.">" | echohl None endif let &report= repkeep @@ -152,12 +157,29 @@ fun! tar#Browse(tarfile) " assuming cygwin let tarfile=substitute(system("cygpath -u ".shellescape(tarfile,0)),'\n$','','e') endif - let curlast= line("$") - if tarfile =~# '\.\(gz\|tgz\)$' - let gzip_command = s:get_gzip_command(tarfile) + + if tarfile =~# '\.\(gz\)$' " call Decho("1: exe silent r! gzip -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - ") - exe "sil! r! " . gzip_command . " -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " + exe "sil! r! gzip -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " + + elseif tarfile =~# '\.\(tgz\)$' || tarfile =~# '\.\(tbz\)$' || tarfile =~# '\.\(txz\)$' || tarfile =~# '\.\(tzs\)$' + if has("unix") && executable("file") + let filekind= system("file ".shellescape(tarfile,1)) =~ "bzip2" + else + let filekind= "" + endif + + if filekind =~ "bzip2" + exe "sil! r! bzip2 -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " + elseif filekind =~ "XZ" + exe "sil! r! xz -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " + elseif filekind =~ "Zstandard" + exe "sil! r! zstd --decompress --stdout -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " + else + exe "sil! r! gzip -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " + endif + elseif tarfile =~# '\.lrp' " call Decho("2: exe silent r! cat -- ".shellescape(tarfile,1)."|gzip -d -c -|".g:tar_cmd." -".g:tar_browseoptions." - ") exe "sil! r! cat -- ".shellescape(tarfile,1)."|gzip -d -c -|".g:tar_cmd." -".g:tar_browseoptions." - " @@ -170,6 +192,8 @@ fun! tar#Browse(tarfile) elseif tarfile =~# '\.\(xz\|txz\)$' " call Decho("3: exe silent r! xz --decompress --stdout -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - ") exe "sil! r! xz --decompress --stdout -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " + elseif tarfile =~# '\.\(zst\|tzs\)$' + exe "sil! r! zstd --decompress --stdout -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " else if tarfile =~ '^\s*-' " A file name starting with a dash is taken as an option. Prepend ./ to avoid that. @@ -184,7 +208,7 @@ fun! tar#Browse(tarfile) " call Dret("tar#Browse : a:tarfile<".a:tarfile.">") return endif - if line("$") == curlast || ( line("$") == (curlast + 1) && getline("$") =~ '\c\%(warning\|error\|inappropriate\|unrecognized\)') + if line("$") == curlast || ( line("$") == (curlast + 1) && getline("$") =~# '\c\%(warning\|error\|inappropriate\|unrecognized\)') redraw! echohl WarningMsg | echo "***warning*** (tar#Browse) ".a:tarfile." doesn't appear to be a tar file" | echohl None keepj sil! %d @@ -197,8 +221,13 @@ fun! tar#Browse(tarfile) return endif + " set up maps supported for tar setlocal noma nomod ro - noremap <silent> <buffer> <cr> :call <SID>TarBrowseSelect()<cr> + noremap <silent> <buffer> <cr> :call <SID>TarBrowseSelect()<cr> + noremap <silent> <buffer> x :call tar#Extract()<cr> + if &mouse != "" + noremap <silent> <buffer> <leftmouse> <leftmouse>:call <SID>TarBrowseSelect()<cr> + endif let &report= repkeep " call Dret("tar#Browse : b:tarfile<".b:tarfile.">") @@ -235,7 +264,8 @@ fun! s:TarBrowseSelect() let tarfile=substitute(system("cygpath -u ".shellescape(tarfile,0)),'\n$','','e') endif - new + " open a new window (tar#Read will read a file into it) + noswapfile new if !exists("g:tar_nomax") || g:tar_nomax == 0 wincmd _ endif @@ -267,7 +297,7 @@ fun! tar#Read(fname,mode) if fname =~ '\.bz2$' && executable("bzcat") let decmp= "|bzcat" let doro = 1 - elseif fname =~ '\.gz$' && executable("zcat") + elseif fname =~ '\.t\=gz$' && executable("zcat") let decmp= "|zcat" let doro = 1 elseif fname =~ '\.lzma$' && executable("lzcat") @@ -276,6 +306,9 @@ fun! tar#Read(fname,mode) elseif fname =~ '\.xz$' && executable("xzcat") let decmp= "|xzcat" let doro = 1 + elseif fname =~ '\.zst$' && executable("zstdcat") + let decmp= "|zstdcat" + let doro = 1 else let decmp="" let doro = 0 @@ -291,20 +324,31 @@ fun! tar#Read(fname,mode) endif if tarfile =~# '\.bz2$' -" call Decho("7: exe silent r! bzip2 -d -c ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp) exe "sil! r! bzip2 -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp - elseif tarfile =~# '\.\(gz\|tgz\)$' - let gzip_command = s:get_gzip_command(tarfile) -" call Decho("5: exe silent r! gzip -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd.' -'.g:tar_readoptions.' - '.tar_secure.shellescape(fname,1)) - exe "sil! r! " . gzip_command . " -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp + elseif tarfile =~# '\.\(gz\)$' + exe "sil! r! gzip -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp + + elseif tarfile =~# '\(\.tgz\|\.tbz\|\.txz\)' + if has("unix") && executable("file") + let filekind= system("file ".shellescape(tarfile,1)) + else + let filekind= "" + endif + if filekind =~ "bzip2" + exe "sil! r! bzip2 -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp + elseif filekind =~ "XZ" + exe "sil! r! xz -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp + elseif filekind =~ "Zstandard" + exe "sil! r! zstd --decompress --stdout -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp + else + exe "sil! r! gzip -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp + endif + elseif tarfile =~# '\.lrp$' -" call Decho("6: exe silent r! cat ".shellescape(tarfile,1)." | gzip -d -c - | ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp) exe "sil! r! cat -- ".shellescape(tarfile,1)." | gzip -d -c - | ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp elseif tarfile =~# '\.lzma$' -" call Decho("7: exe silent r! lzma -d -c ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp) exe "sil! r! lzma -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp elseif tarfile =~# '\.\(xz\|txz\)$' -" call Decho("3: exe silent r! xz --decompress --stdout -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp) exe "sil! r! xz --decompress --stdout -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp else if tarfile =~ '^\s*-' @@ -348,13 +392,14 @@ fun! tar#Write(fname) " sanity checks if !executable(g:tar_cmd) redraw! - echohl Error | echo '***error*** (tar#Browse) "'.g:tar_cmd.'" not available on your system' +" call Decho('***error*** (tar#Browse) "'.g:tar_cmd.'" not available on your system') let &report= repkeep " call Dret("tar#Write") return endif if !exists("*mkdir") redraw! +" call Decho("***error*** (tar#Write) sorry, mkdir() doesn't work on your system") echohl Error | echo "***error*** (tar#Write) sorry, mkdir() doesn't work on your system" | echohl None let &report= repkeep " call Dret("tar#Write") @@ -375,6 +420,7 @@ fun! tar#Write(fname) exe "cd ".fnameescape(tmpdir) catch /^Vim\%((\a\+)\)\=:E344/ redraw! +" call Decho("***error*** (tar#Write) cannot cd to temporary directory") echohl Error | echo "***error*** (tar#Write) cannot cd to temporary directory" | Echohl None let &report= repkeep " call Dret("tar#Write") @@ -393,8 +439,6 @@ fun! tar#Write(fname) let tarfile = substitute(b:tarfile,'tarfile:\(.\{-}\)::.*$','\1','') let fname = substitute(b:tarfile,'tarfile:.\{-}::\(.*\)$','\1','') - let gzip_command = s:get_gzip_command(tarfile) - " handle compressed archives if tarfile =~# '\.bz2' call system("bzip2 -d -- ".shellescape(tarfile,0)) @@ -402,12 +446,12 @@ fun! tar#Write(fname) let compress= "bzip2 -- ".shellescape(tarfile,0) " call Decho("compress<".compress.">") elseif tarfile =~# '\.gz' - call system(gzip_command . " -d -- ".shellescape(tarfile,0)) + call system("gzip -d -- ".shellescape(tarfile,0)) let tarfile = substitute(tarfile,'\.gz','','e') let compress= "gzip -- ".shellescape(tarfile,0) " call Decho("compress<".compress.">") elseif tarfile =~# '\.tgz' - call system(gzip_command . " -d -- ".shellescape(tarfile,0)) + call system("gzip -d -- ".shellescape(tarfile,0)) let tarfile = substitute(tarfile,'\.tgz','.tar','e') let compress= "gzip -- ".shellescape(tarfile,0) let tgz = 1 @@ -417,6 +461,10 @@ fun! tar#Write(fname) let tarfile = substitute(tarfile,'\.xz','','e') let compress= "xz -- ".shellescape(tarfile,0) " call Decho("compress<".compress.">") + elseif tarfile =~# '\.zst' + call system("zstd --decompress -- ".shellescape(tarfile,0)) + let tarfile = substitute(tarfile,'\.zst','','e') + let compress= "zstd -- ".shellescape(tarfile,0) elseif tarfile =~# '\.lzma' call system("lzma -d -- ".shellescape(tarfile,0)) let tarfile = substitute(tarfile,'\.lzma','','e') @@ -427,6 +475,7 @@ fun! tar#Write(fname) if v:shell_error != 0 redraw! +" call Decho("***error*** (tar#Write) sorry, unable to update ".tarfile." with ".fname) echohl Error | echo "***error*** (tar#Write) sorry, unable to update ".tarfile." with ".fname | echohl None else @@ -459,10 +508,11 @@ fun! tar#Write(fname) endif " delete old file from tarfile -" call Decho("system(".g:tar_cmd." --delete -f ".shellescape(tarfile,0)." -- ".shellescape(fname,0).")") - call system(g:tar_cmd." --delete -f ".shellescape(tarfile,0).tar_secure.shellescape(fname,0)) +" call Decho("system(".g:tar_cmd." ".g:tar_delfile." ".shellescape(tarfile,0)." -- ".shellescape(fname,0).")") + call system(g:tar_cmd." ".g:tar_delfile." ".shellescape(tarfile,0).tar_secure.shellescape(fname,0)) if v:shell_error != 0 redraw! +" call Decho("***error*** (tar#Write) sorry, unable to update ".fnameescape(tarfile)." with ".fnameescape(fname)) echohl Error | echo "***error*** (tar#Write) sorry, unable to update ".fnameescape(tarfile)." with ".fnameescape(fname) | echohl None else @@ -471,6 +521,7 @@ fun! tar#Write(fname) call system(g:tar_cmd." -".g:tar_writeoptions." ".shellescape(tarfile,0).tar_secure.shellescape(fname,0)) if v:shell_error != 0 redraw! +" call Decho("***error*** (tar#Write) sorry, unable to update ".fnameescape(tarfile)." with ".fnameescape(fname)) echohl Error | echo "***error*** (tar#Write) sorry, unable to update ".fnameescape(tarfile)." with ".fnameescape(fname) | echohl None elseif exists("compress") " call Decho("call system(".compress.")") @@ -486,11 +537,11 @@ fun! tar#Write(fname) if s:tblfile_{winnr()} =~ '^\a\+://' " call Decho("handle writing <".tarfile."> across network to <".s:tblfile_{winnr()}.">") let tblfile= s:tblfile_{winnr()} - 1split|enew + 1split|noswapfile enew let binkeep= &l:binary let eikeep = &ei set binary ei=all - exe "e! ".fnameescape(tarfile) + exe "noswapfile e! ".fnameescape(tarfile) call netrw#NetWrite(tblfile) let &ei = eikeep let &l:binary = binkeep @@ -524,7 +575,7 @@ fun! tar#Diff(userfname,fname) " sets up b:tardiff_otherbuf variables so each buffer knows about the other (for closing purposes) diffthis wincmd v - exe "e ".fnameescape(fname) + exe "noswapfile e ".fnameescape(fname) diffthis else redraw! @@ -534,6 +585,141 @@ fun! tar#Diff(userfname,fname) endfun " --------------------------------------------------------------------- +" tar#Extract: extract a file from a (possibly compressed) tar archive {{{2 +fun! tar#Extract() +" call Dfunc("tar#Extract()") + + let repkeep= &report + set report=10 + let fname= getline(".") +" call Decho("fname<".fname.">") + + if !exists("g:tar_secure") && fname =~ '^\s*-\|\s\+-' + redraw! + echohl WarningMsg | echo '***warning*** (tar#BrowseSelect) rejecting tarfile member<'.fname.'> because of embedded "-"' +" call Dret('tar#BrowseSelect : rejecting tarfile member<'.fname.'> because of embedded "-"') + return + endif + + " sanity check + if fname =~ '^"' + let &report= repkeep +" call Dret("TarBrowseSelect") + return + endif + + let tarball = expand("%") +" call Decho("tarball<".tarball.">") + let tarbase = substitute(tarball,'\..*$','','') +" call Decho("tarbase<".tarbase.">") + + let extractcmd= netrw#WinPath(g:tar_extractcmd) + if filereadable(tarbase.".tar") +" call Decho("system(".extractcmd." ".shellescape(tarbase).".tar ".shellescape(fname).")") + call system(extractcmd." ".shellescape(tarbase).".tar ".shellescape(fname)) + if v:shell_error != 0 + echohl Error | echo "***error*** ".extractcmd." ".tarbase.".tar ".fname.": failed!" | echohl NONE +" call Decho("***error*** ".extractcmd." ".tarbase.".tar ".fname.": failed!") + else + echo "***note*** successfully extracted ".fname + endif + + elseif filereadable(tarbase.".tgz") + let extractcmd= substitute(extractcmd,"-","-z","") +" call Decho("system(".extractcmd." ".shellescape(tarbase).".tgz ".shellescape(fname).")") + call system(extractcmd." ".shellescape(tarbase).".tgz ".shellescape(fname)) + if v:shell_error != 0 + echohl Error | echo "***error*** ".extractcmd." ".tarbase.".tgz ".fname.": failed!" | echohl NONE +" call Decho("***error*** ".extractcmd."t ".tarbase.".tgz ".fname.": failed!") + else + echo "***note*** successfully extracted ".fname + endif + + elseif filereadable(tarbase.".tar.gz") + let extractcmd= substitute(extractcmd,"-","-z","") +" call Decho("system(".extractcmd." ".shellescape(tarbase).".tar.gz ".shellescape(fname).")") + call system(extractcmd." ".shellescape(tarbase).".tar.gz ".shellescape(fname)) + if v:shell_error != 0 + echohl Error | echo "***error*** ".extractcmd." ".tarbase.".tar.gz ".fname.": failed!" | echohl NONE +" call Decho("***error*** ".extractcmd." ".tarbase.".tar.gz ".fname.": failed!") + else + echo "***note*** successfully extracted ".fname + endif + + elseif filereadable(tarbase.".tbz") + let extractcmd= substitute(extractcmd,"-","-j","") +" call Decho("system(".extractcmd." ".shellescape(tarbase).".tbz ".shellescape(fname).")") + call system(extractcmd." ".shellescape(tarbase).".tbz ".shellescape(fname)) + if v:shell_error != 0 + echohl Error | echo "***error*** ".extractcmd."j ".tarbase.".tbz ".fname.": failed!" | echohl NONE +" call Decho("***error*** ".extractcmd."j ".tarbase.".tbz ".fname.": failed!") + else + echo "***note*** successfully extracted ".fname + endif + + elseif filereadable(tarbase.".tar.bz2") + let extractcmd= substitute(extractcmd,"-","-j","") +" call Decho("system(".extractcmd." ".shellescape(tarbase).".tar.bz2 ".shellescape(fname).")") + call system(extractcmd." ".shellescape(tarbase).".tar.bz2 ".shellescape(fname)) + if v:shell_error != 0 + echohl Error | echo "***error*** ".extractcmd."j ".tarbase.".tar.bz2 ".fname.": failed!" | echohl NONE +" call Decho("***error*** ".extractcmd."j ".tarbase.".tar.bz2 ".fname.": failed!") + else + echo "***note*** successfully extracted ".fname + endif + + elseif filereadable(tarbase.".txz") + let extractcmd= substitute(extractcmd,"-","-J","") +" call Decho("system(".extractcmd." ".shellescape(tarbase).".txz ".shellescape(fname).")") + call system(extractcmd." ".shellescape(tarbase).".txz ".shellescape(fname)) + if v:shell_error != 0 + echohl Error | echo "***error*** ".extractcmd." ".tarbase.".txz ".fname.": failed!" | echohl NONE +" call Decho("***error*** ".extractcmd." ".tarbase.".txz ".fname.": failed!") + else + echo "***note*** successfully extracted ".fname + endif + + elseif filereadable(tarbase.".tar.xz") + let extractcmd= substitute(extractcmd,"-","-J","") +" call Decho("system(".extractcmd." ".shellescape(tarbase).".tar.xz ".shellescape(fname).")") + call system(extractcmd." ".shellescape(tarbase).".tar.xz ".shellescape(fname)) + if v:shell_error != 0 + echohl Error | echo "***error*** ".extractcmd." ".tarbase.".tar.xz ".fname.": failed!" | echohl NONE +" call Decho("***error*** ".extractcmd." ".tarbase.".tar.xz ".fname.": failed!") + else + echo "***note*** successfully extracted ".fname + endif + + elseif filereadable(tarbase.".tzs") + let extractcmd= substitute(extractcmd,"-","--zstd","") +" call Decho("system(".extractcmd." ".shellescape(tarbase).".tzs ".shellescape(fname).")") + call system(extractcmd." ".shellescape(tarbase).".txz ".shellescape(fname)) + if v:shell_error != 0 + echohl Error | echo "***error*** ".extractcmd." ".tarbase.".tzs ".fname.": failed!" | echohl NONE +" call Decho("***error*** ".extractcmd." ".tarbase.".tzs ".fname.": failed!") + else + echo "***note*** successfully extracted ".fname + endif + + elseif filereadable(tarbase.".tar.zst") + let extractcmd= substitute(extractcmd,"-","--zstd","") +" call Decho("system(".extractcmd." ".shellescape(tarbase).".tar.zst ".shellescape(fname).")") + call system(extractcmd." ".shellescape(tarbase).".tar.xz ".shellescape(fname)) + if v:shell_error != 0 + echohl Error | echo "***error*** ".extractcmd." ".tarbase.".tar.zst ".fname.": failed!" | echohl NONE +" call Decho("***error*** ".extractcmd." ".tarbase.".tar.zst ".fname.": failed!") + else + echo "***note*** successfully extracted ".fname + endif + endif + + " restore option + let &report= repkeep + +" call Dret("tar#Extract") +endfun + +" --------------------------------------------------------------------- " s:Rmdir: {{{2 fun! s:Rmdir(fname) " call Dfunc("Rmdir(fname<".a:fname.">)") @@ -587,10 +773,7 @@ fun! tar#Vimuntar(...) " if necessary, decompress the tarball; then, extract it if tartail =~ '\.tgz' - let gzip_command = s:get_gzip_command(tarfile) - if executable(gzip_command) - silent exe "!" . gzip_command . " -d ".shellescape(tartail) - elseif executable("gunzip") + if executable("gunzip") silent exe "!gunzip ".shellescape(tartail) elseif executable("gzip") silent exe "!gzip -d ".shellescape(tartail) @@ -628,28 +811,6 @@ fun! tar#Vimuntar(...) " call Dret("tar#Vimuntar") endfun -func s:get_gzip_command(file) - " Try using the "file" command to get the actual compression type, since - " there is no standard way for the naming: ".tgz", ".tbz", ".txz", etc. - " If the "file" command doesn't work fall back to just using the file name. - if a:file =~# 'z$' - let filetype = system('file ' . a:file) - if filetype =~ 'bzip2 compressed' && executable('bzip2') - return 'bzip2' - endif - if filetype =~ 'XZ compressed' && executable('xz') - return 'xz' - endif - endif - if a:file =~# 'bz2$' - return 'bzip2' - endif - if a:file =~# 'xz$' - return 'xz' - endif - return 'gzip' -endfunc - " ===================================================================== " Modelines And Restoration: {{{1 let &cpo= s:keepcpo diff --git a/runtime/doc/api.txt b/runtime/doc/api.txt index dd3469372e..bd34411065 100644 --- a/runtime/doc/api.txt +++ b/runtime/doc/api.txt @@ -1148,6 +1148,18 @@ nvim_load_context({dict}) *nvim_load_context()* Parameters: ~ {dict} |Context| map. +nvim_notify({msg}, {log_level}, {opts}) *nvim_notify()* + Notify the user with a message + + Relays the call to vim.notify . By default forwards your + message in the echo area but can be overriden to trigger + desktop notifications. + + Parameters: ~ + {msg} Message to display to the user + {log_level} The log level + {opts} Reserved for future use. + nvim_open_win({buffer}, {enter}, {config}) *nvim_open_win()* Open a new window. @@ -1403,9 +1415,9 @@ nvim_put({lines}, {type}, {after}, {follow}) *nvim_put()* • "c" |charwise| mode • "l" |linewise| mode • "" guess by contents, see |setreg()| - {after} Insert after cursor (like |p|), or before (like + {after} If true insert after cursor (like |p|), or before (like |P|). - {follow} Place cursor at end of inserted text. + {follow} If true place cursor at end of inserted text. *nvim_replace_termcodes()* nvim_replace_termcodes({str}, {from_part}, {do_lt}, {special}) @@ -1800,6 +1812,25 @@ nvim_buf_attach({buffer}, {send_buffer}, {opts}) *nvim_buf_attach()* • deleted_codeunits (if `utf_sizes` is true) + • on_bytes: lua callback invoked on change. + This callback receives more granular + information about the change compared to + on_lines. Return`true`to detach. Args: + • the string "bytes" + • buffer handle + • b:changedtick + • start row of the changed text + (zero-indexed) + • start column of the changed text + • byte offset of the changed text (from + the start of the buffer) + • old end row of the changed text + • old end column of the changed text + • old end byte length of the changed text + • new end row of the changed text + • new end column of the changed text + • new end byte length of the changed text + • on_changedtick: Lua callback invoked on changedtick increment without text change. Args: @@ -1812,6 +1843,12 @@ nvim_buf_attach({buffer}, {send_buffer}, {opts}) *nvim_buf_attach()* • the string "detach" • buffer handle + • on_reload: Lua callback invoked on + reload. The entire buffer content should + be considered changed. Args: + • the string "detach" + • buffer handle + • utf_sizes: include UTF-32 and UTF-16 size of the replaced region, as args to `on_lines` . @@ -2158,6 +2195,13 @@ nvim_buf_set_extmark({buffer}, {ns_id}, {line}, {col}, {opts}) • hl_group : name of the highlight group used to highlight this mark. • virt_text : virtual text to link to this mark. + • virt_text_pos : positioning of virtual text. + Possible values: + • "eol": right after eol character (default) + • "overlay": display over the specified + column, without shifting the underlying + text. + • ephemeral : for use with |nvim_set_decoration_provider| callbacks. The mark will only be used for the current redraw diff --git a/runtime/doc/diff.txt b/runtime/doc/diff.txt index 2a972483ff..3544882ceb 100644 --- a/runtime/doc/diff.txt +++ b/runtime/doc/diff.txt @@ -48,7 +48,7 @@ In each of the edited files these options are set: 'scrollbind' on 'cursorbind' on 'scrollopt' includes "hor" - 'wrap' off + 'wrap' off, or leave as-is if 'diffopt' includes "followwrap" 'foldmethod' "diff" 'foldcolumn' value from 'diffopt', default is 2 @@ -132,7 +132,7 @@ Otherwise they are set to their default value: 'scrollbind' off 'cursorbind' off 'scrollopt' without "hor" - 'wrap' on + 'wrap' on, or leave as-is if 'diffopt' includes "followwrap" 'foldmethod' "manual" 'foldcolumn' 0 diff --git a/runtime/doc/editing.txt b/runtime/doc/editing.txt index ac398ec494..aa964a521f 100644 --- a/runtime/doc/editing.txt +++ b/runtime/doc/editing.txt @@ -90,7 +90,7 @@ g CTRL-G Prints the current position of the cursor in five :buffers :files :ls List all the currently known file names. See - 'windows.txt' |:files| |:buffers| |:ls|. + |windows.txt| |:files| |:buffers| |:ls|. Vim will remember the full path name of a file name that you enter. In most cases when the file name is displayed only the name you typed is shown, but @@ -1190,7 +1190,7 @@ The syntax is best shown via some examples: > < Open the browser in the C:/bar directory, with the current buffer filename as default, and save the buffer under the filename chosen. -Also see the |'browsedir'| option. +Also see the 'browsedir' option. For versions of Vim where browsing is not supported, the command is executed unmodified. diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 384bdd63a4..be7c026f5a 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -1541,7 +1541,10 @@ v:dying Normally zero. When a deadly signal is caught it's set to VimLeave autocommands will not be executed. *v:exiting* *exiting-variable* -v:exiting Exit code, or |v:null| if not exiting. |VimLeave| +v:exiting Exit code, or |v:null| before invoking the |VimLeavePre| + and |VimLeave| autocmds. See |:q|, |:x| and |:cquit|. + Example: > + :au VimLeave * echo "Exit value is " .. v:exiting *v:echospace* *echospace-variable* v:echospace Number of screen cells that can be used for an `:echo` message @@ -2074,6 +2077,8 @@ changenr() Number current change number chanclose({id}[, {stream}]) Number Closes a channel or one of its streams chansend({id}, {data}) Number Writes {data} to channel char2nr({expr}[, {utf8}]) Number ASCII/UTF8 value of first char in {expr} +charidx({string}, {idx} [, {countcc}]) + Number char index of byte {idx} in {string} cindent({lnum}) Number C indent for line {lnum} clearmatches([{win}]) none clear all matches col({expr}) Number column nr of cursor or mark @@ -3024,6 +3029,29 @@ char2nr({expr} [, {utf8}]) *char2nr()* A combining character is a separate character. |nr2char()| does the opposite. + *charidx()* +charidx({string}, {idx} [, {countcc}]) + Return the character index of the byte at {idx} in {string}. + The index of the first character is zero. + If there are no multibyte characters the returned value is + equal to {idx}. + When {countcc} is omitted or zero, then composing characters + are not counted separately, their byte length is added to the + preceding base character. + When {countcc} is set to 1, then composing characters are + counted as separate characters. + Returns -1 if the arguments are invalid or if {idx} is greater + than the index of the last byte in {string}. An error is + given if the first argument is not a string, the second + argument is not a number or when the third argument is present + and is not zero or one. + See |byteidx()| and |byteidxcomp()| for getting the byte index + from the character index. + Examples: > + echo charidx('áb́ć', 3) returns 1 + echo charidx('áb́ć', 6, 1) returns 4 + echo charidx('áb́ć', 16) returns -1 + cindent({lnum}) *cindent()* Get the amount of indent for line {lnum} according the C indenting rules, as with 'cindent'. @@ -4449,11 +4477,12 @@ getcompletion({pat}, {type} [, {filtered}]) *getcompletion()* augroup autocmd groups buffer buffer names behave :behave suboptions - cmdline |cmdline-completion| + cmdline |cmdline-completion| result color color schemes command Ex command (and arguments) compiler compilers cscope |:cscope| suboptions + diff_buffer |:diffget| and |:diffput| completion dir directory names environment environment variable names event autocommand events @@ -4481,14 +4510,19 @@ getcompletion({pat}, {type} [, {filtered}]) *getcompletion()* user user names var user variables - If {pat} is an empty string then all matches are returned. - Otherwise only items matching {pat} are returned. See - |wildcards| for the use of special characters in {pat}. + If {pat} is an empty string, then all the matches are + returned. Otherwise only items matching {pat} are returned. + See |wildcards| for the use of special characters in {pat}. If the optional {filtered} flag is set to 1, then 'wildignore' is applied to filter the results. Otherwise all the matches are returned. The 'wildignorecase' option always applies. + If {type} is "cmdline", then the |cmdline-completion| result is + returned. For example, to complete the possible values after + a ":call" command: > + echo getcompletion('call ', 'cmdline') +< If there are no matches, an empty list is returned. An invalid value for {type} produces an error. @@ -5091,6 +5125,8 @@ has({feature}) Returns 1 if {feature} is supported, 0 otherwise. The iconv Can use |iconv()| for conversion. +shellslash Can use backslashes in filenames (Windows) clipboard |clipboard| provider is available. + fname_case Case in file names matters (for Darwin and MS-Windows + this is not present). mac MacOS system. nvim This is Nvim. python2 Legacy Vim |python2| interface. |has-python| @@ -5607,7 +5643,6 @@ jobstart({cmd}[, {opts}]) *jobstart()* before invoking `on_stderr`. |channel-buffered| stdout_buffered: (boolean) Collect data until EOF (stream closed) before invoking `on_stdout`. |channel-buffered| - TERM: (string) Sets the `pty` $TERM environment variable. width: (number) Width of the `pty` terminal. {opts} is passed as |self| dictionary to the callback; the @@ -9771,15 +9806,49 @@ change their contents. Thus you can pass a |List| to a function and have the function add an item to it. If you want to make sure the function cannot change a |List| or |Dictionary| use |:lockvar|. -When not using "...", the number of arguments in a function call must be equal -to the number of named arguments. When using "...", the number of arguments -may be larger. - It is also possible to define a function without any arguments. You must still supply the () then. It is allowed to define another function inside a function body. + *optional-function-argument* +You can provide default values for positional named arguments. This makes +them optional for function calls. When a positional argument is not +specified at a call, the default expression is used to initialize it. +This only works for functions declared with |function|, not for lambda +expressions |expr-lambda|. + +Example: > + function Something(key, value = 10) + echo a:key .. ": " .. a:value + endfunction + call Something('empty') "empty: 10" + call Something('key', 20) "key: 20" + +The argument default expressions are evaluated at the time of the function +call, not definition. Thus it is possible to use an expression which is +invalid the moment the function is defined. The expressions are also only +evaluated when arguments are not specified during a call. + + *E989* +Optional arguments with default expressions must occur after any mandatory +arguments. You can use "..." after all optional named arguments. + +It is possible for later argument defaults to refer to prior arguments, +but not the other way around. They must be prefixed with "a:", as with all +arguments. + +Example that works: > + :function Okay(mandatory, optional = a:mandatory) + :endfunction +Example that does NOT work: > + :function NoGood(first = a:second, second = 10) + :endfunction +< +When not using "...", the number of arguments in a function call must be equal +to the number of mandatory named arguments. When using "...", the number of +arguments may be larger. + *local-variables* Inside a function local variables can be used. These will disappear when the function returns. Global variables need to be accessed with "g:". diff --git a/runtime/doc/index.txt b/runtime/doc/index.txt index 172821ac28..c824a9f9f6 100644 --- a/runtime/doc/index.txt +++ b/runtime/doc/index.txt @@ -1144,6 +1144,7 @@ tag command action ~ |:bNext| :bN[ext] go to previous buffer in the buffer list |:ball| :ba[ll] open a window for each buffer in the buffer list |:badd| :bad[d] add buffer to the buffer list +|:balt| :balt like ":badd" but also set the alternate file |:bdelete| :bd[elete] remove a buffer from the buffer list |:behave| :be[have] set mouse and selection behavior |:belowright| :bel[owright] make split window appear right or below diff --git a/runtime/doc/insert.txt b/runtime/doc/insert.txt index c4b93a2a27..6902ed5fd4 100644 --- a/runtime/doc/insert.txt +++ b/runtime/doc/insert.txt @@ -287,8 +287,7 @@ character is written at the end of each line. Thus if you want to insert a *i_CTRL-X* *insert_expand* CTRL-X enters a sub-mode where several commands can be used. Most of these -commands do keyword completion; see |ins-completion|. These are not available -when Vim was compiled without the |+insert_expand| feature. +commands do keyword completion; see |ins-completion|. Two commands can be used to scroll the window up or down, without exiting insert mode: @@ -592,9 +591,6 @@ In Insert and Replace mode, there are several commands to complete part of a keyword or line that has been typed. This is useful if you are using complicated keywords (e.g., function names with capitals and underscores). -These commands are not available when the |+insert_expand| feature was -disabled at compile time. - Completion can be done for: 1. Whole lines |i_CTRL-X_CTRL-L| diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt index 06666c3a27..d2d88fb9ba 100644 --- a/runtime/doc/lsp.txt +++ b/runtime/doc/lsp.txt @@ -397,6 +397,11 @@ LSP HIGHLIGHT *lsp-highlight* Reference Highlights: +Highlight groups that are meant to be used by |vim.lsp.buf.document_highlight()|. + +You can see more about the differences in types here: +https://microsoft.github.io/language-server-protocol/specification#textDocument_documentHighlight + *hl-LspReferenceText* LspReferenceText used for highlighting "text" references *hl-LspReferenceRead* @@ -932,15 +937,21 @@ definition() *vim.lsp.buf.definition()* Jumps to the definition of the symbol under the cursor. document_highlight() *vim.lsp.buf.document_highlight()* - Send request to server to resolve document highlights for the - current text document position. This request can be associated - to key mapping or to events such as `CursorHold` , eg: + Send request to the server to resolve document highlights for + the current text document position. This request can be + triggered by a key mapping or by events such as `CursorHold` , + eg: > vim.api.nvim_command [[autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()]] vim.api.nvim_command [[autocmd CursorHoldI <buffer> lua vim.lsp.buf.document_highlight()]] vim.api.nvim_command [[autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()]] < + Note: Usage of |vim.lsp.buf.document_highlight()| requires the + following highlight groups to be defined or you won't be able + to see the actual highlights. |LspReferenceText| + |LspReferenceRead| |LspReferenceWrite| + document_symbol() *vim.lsp.buf.document_symbol()* Lists all symbols in the current buffer in the quickfix window. @@ -1307,6 +1318,17 @@ on_publish_diagnostics({_}, {_}, {params}, {client_id}, {_}, {config}) • Update diagnostics in InsertMode or wait until InsertLeave +reset({client_id}, {buffer_client_map}) *vim.lsp.diagnostic.reset()* + Clear diagnotics and diagnostic cache + + Handles saving diagnostics from multiple clients in the same + buffer. + + Parameters: ~ + {client_id} number + {buffer_client_map} table map of buffers to active + clients + save({diagnostics}, {bufnr}, {client_id}) *vim.lsp.diagnostic.save()* Save diagnostics to the current buffer. diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index a497efa47e..c4d5df84cf 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -1971,6 +1971,8 @@ A jump table for the options with a short description can be found at |Q_op|. foldcolumn:{n} Set the 'foldcolumn' option to {n} when starting diff mode. Without this 2 is used. + followwrap Follow the 'wrap' option and leave as it is. + internal Use the internal diff library. This is ignored when 'diffexpr' is set. *E960* When running out of memory when writing a @@ -4088,8 +4090,6 @@ A jump table for the options with a short description can be found at |Q_op|. In the "popup" model the right mouse button produces a pop-up menu. You need to define this first, see |popup-menu|. - In a terminal the popup menu works if Vim is compiled with the - |+insert_expand| option. Note that you can further refine the meaning of buttons with mappings. See |mouse-overview|. But mappings are NOT used for modeless selection. @@ -4856,7 +4856,9 @@ A jump table for the options with a short description can be found at |Q_op|. local to window Number of lines to scroll with CTRL-U and CTRL-D commands. Will be set to half the number of lines in the window when the window size - changes. If you give a count to the CTRL-U or CTRL-D command it will + changes. This may happen when enabling the |status-line| or + 'tabline' option after setting the 'scroll' option. + If you give a count to the CTRL-U or CTRL-D command it will be used as the new value for 'scroll'. Reset to half the window height with ":set scroll=0". @@ -6289,6 +6291,29 @@ A jump table for the options with a short description can be found at |Q_op|. attributes instead of "cterm" attributes. |highlight-guifg| Requires an ISO-8613-3 compatible terminal. + *'termpastefilter'* *'tpf'* +'termpastefilter' 'tpf' string (default: "BS,HT,ESC,DEL") + global + A comma separated list of options for specifying control characters + to be removed from the text pasted into the terminal window. The + supported values are: + + BS Backspace + + HT TAB + + FF Form feed + + ESC Escape + + DEL DEL + + C0 Other control characters, excluding Line feed and + Carriage return < ' ' + + C1 Control characters 0x80...0x9F + + *'terse'* *'noterse'* 'terse' boolean (default off) global diff --git a/runtime/doc/pi_netrw.txt b/runtime/doc/pi_netrw.txt index 9a75a95f23..7312ab721b 100644 --- a/runtime/doc/pi_netrw.txt +++ b/runtime/doc/pi_netrw.txt @@ -1,9 +1,9 @@ -*pi_netrw.txt* For Vim version 8.1. Last change: 2019 Jul 17 +*pi_netrw.txt* For Vim version 8.2. Last change: 2020 Aug 15 ------------------------------------------------ NETRW REFERENCE MANUAL by Charles E. Campbell ------------------------------------------------ -Author: Charles E. Campbell <NdrOchip@ScampbellPfamily.AbizM> +Author: Charles E. Campbell <NcampObell@SdrPchip.AorgM-NOSPAM> (remove NOSPAM from Campbell's email first) Copyright: Copyright (C) 2017 Charles E Campbell *netrw-copyright* @@ -1565,8 +1565,8 @@ So, for example: > file.rcs,v -> NFH_rcsCOMMAv() < If more such translations are necessary, please send me email: > - NdrOchip at ScampbellPfamily.AbizM - NOSPAM -with a request. + NcampObell@SdrPchip.AorgM-NOSPAM +with a request. (remove the embedded NOSPAM first) Associated setting variable: |g:netrw_browsex_viewer| @@ -2744,9 +2744,8 @@ your browsing preferences. (see also: |netrw-settings|) *g:netrw_home* The home directory for where bookmarks and history are saved (as .netrwbook and .netrwhist). - Netrw uses |expand()|on the string. - default: the first directory on the - |'runtimepath'| + Netrw uses |expand()| on the string. + default: stdpath('data') (see |stdpath()|) *g:netrw_keepdir* =1 (default) keep current directory immune from the browsing directory. @@ -3054,7 +3053,7 @@ your browsing preferences. (see also: |netrw-settings|) (see |netrw-c-tab|). *g:netrw_xstrlen* Controls how netrw computes string lengths, - including multi-byte characters' string + including multibyte characters' string length. (thanks to N Weibull, T Mechelynck) =0: uses Vim's built-in strlen() =1: number of codepoints (Latin a + combining @@ -3229,7 +3228,8 @@ If there are marked files: (see |netrw-mf|) R [query: reply with s/^\(.*\)\.c$/\1.cpp/] < This example will mark all *.c files and then rename them to *.cpp - files. + files. Netrw will protect you from overwriting local files without + confirmation, but not remote ones. The ctrl-X character has special meaning for renaming files: > @@ -3512,7 +3512,7 @@ Example: Clear netrw's marked file list via a mapping on gu > - Click "Add..." - Set External Editor (adjust path as needed, include the quotes and !.! at the end): - "c:\Program Files\Vim\vim70\gvim.exe" !.! + "c:\Program Files\Vim\vim82\gvim.exe" !.! - Check that the filetype in the box below is {asterisk}.{asterisk} (all files), or whatever types you want (cec: change {asterisk} to * ; I had to @@ -3762,8 +3762,8 @@ by obtaining a copy of the latest (often developmental) netrw at: The <netrw.vim> script is typically installed on systems as something like: > - /usr/local/share/vim/vim7x/plugin/netrwPlugin.vim - /usr/local/share/vim/vim7x/autoload/netrw.vim + /usr/local/share/vim/vim8x/plugin/netrwPlugin.vim + /usr/local/share/vim/vim8x/autoload/netrw.vim (see output of :echo &rtp) < which is loaded automatically at startup (assuming :set nocp). If you @@ -3836,12 +3836,30 @@ netrw: Please send that information to <netrw.vim>'s maintainer along with the o/s you're using and the vim version that you're using - (see |:version|) > - NdrOchip at ScampbellPfamily.AbizM - NOSPAM + (see |:version|) (remove the embedded NOSPAM first) > + NcampObell@SdrPchip.AorgM-NOSPAM < ============================================================================== 12. History *netrw-history* {{{1 + v169: Dec 20, 2019 * (reported by amkarthik) that netrw's x + (|netrw-x|) would throw an error when + attempting to open a local directory. + v168: Dec 12, 2019 * scp timeout error message not reported, + hopefully now fixed (Shane Xb Qian) + + v167: Nov 29, 2019 * netrw does a save&restore on @* and @+. + That causes problems with the clipboard. + Now restores occurs only if @* or @+ have + been changed. + * netrw will change @* or @+ less often. + Never if I happen to have caught all the + operations that modify the unnamed + register (which also writes @*). + * Modified hiding behavior so that "s" + will not ignore hiding. + v166: Nov 06, 2019 * Removed a space from a nmap for "-" + * Numerous debugging statement changes v163: Dec 05, 2017 * (Cristi Balan) reported that a setting ('sel') was left changed * (Holger Mitschke) reported a problem with @@ -3852,6 +3870,8 @@ netrw: * (Holger Mitschke) amended this help file with additional |g:netrw_special_syntax| items + * Prioritized wget over curl for + g:netrw_http_cmd v162: Sep 19, 2016 * (haya14busa) pointed out two syntax errors with a patch; these are now fixed. Oct 26, 2016 * I started using mate-terminal and found that @@ -4265,7 +4285,7 @@ netrw: Vim editor by Bram Moolenaar (Thanks, Bram!) dav support by C Campbell fetch support by Bram Moolenaar and C Campbell - ftp support by C Campbell <NdrOchip@ScampbellPfamily.AbizM> + ftp support by C Campbell <NcampObell@SdrPchip.AorgM-NOSPAM> http support by Bram Moolenaar <bram@moolenaar.net> rcp rsync support by C Campbell (suggested by Erik Warendorph) diff --git a/runtime/doc/pi_tar.txt b/runtime/doc/pi_tar.txt index 59b318b7fd..c6c0596ea0 100644 --- a/runtime/doc/pi_tar.txt +++ b/runtime/doc/pi_tar.txt @@ -1,12 +1,12 @@ -*pi_tar.txt* Nvim +*pi_tar.txt* For Vim version 8.2. Last change: 2020 Jan 07 +====================+ | Tar File Interface | +====================+ -Author: Charles E. Campbell <NdrOchip@ScampbellPfamily.AbizM> +Author: Charles E. Campbell <NcampObell@SdrPchip.AorgM-NOSPAM> (remove NOSPAM from Campbell's email first) -Copyright 2005-2012: *tar-copyright* +Copyright 2005-2017: *tar-copyright* The VIM LICENSE (see |copyright|) applies to the files in this package, including tarPlugin.vim, tar.vim, and pi_tar.txt. Like anything else that's except use "tar.vim" instead of "VIM". Like @@ -104,48 +104,67 @@ Copyright 2005-2012: *tar-copyright* ============================================================================== 4. History *tar-history* - - v28 Jun 23, 2011 * a few more decompression options (tbz tb2 txz) - v27 May 31, 2011 * moved cygwin detection before g:tar_copycmd handling - * inserted additional |:keepj| modifiers - * changed silent to sil! (|:silent|) - v26 Aug 09, 2010 * uses buffer-local instead of window variables to hold - tarfile name - * inserted keepj before 0d to protect jump list - v25 Jun 19, 2010 * (Jan Steffens) added support for xz compression - v24 Apr 07, 2009 * :Untarvim command implemented - Sep 28, 2009 * Added lzma support - v22 Aug 08, 2008 * security fixes - v16 Jun 06, 2008 * tarfile:: used instead of tarfile: when editing files - inside tarballs. Fixes a problem with tarballs called - things like c:\abc.tar. (tnx to Bill McCarthy) - v14 May 09, 2008 * arno caught a security bug - May 28, 2008 * various security improvements. Now requires patch 299 - which provides the fnameescape() function - May 30, 2008 * allows one to view *.gz and *.bz2 files that are in - *.tar files. - v12 Sep 07, 2007 * &shq now used if not the empty string for g:tar_shq - v10 May 02, 2006 * now using "redraw then echo" to show messages, instead - of "echo and prompt user" - v9 May 02, 2006 * improved detection of masquerading as tar file - v8 May 02, 2006 * allows editing of files that merely masquerade as tar - files - v7 Mar 22, 2006 * work on making tar plugin work across network - Mar 27, 2006 * g:tar_cmd now available for users to change the name - of the tar program to be used. By default, of course, - it's "tar". - v6 Dec 21, 2005 * writing to files not in directories caused problems - - fixed (pointed out by Christian Robinson) - v5 Nov 22, 2005 * report option workaround installed - v3 Sep 16, 2005 * handles writing files in an archive back to the - archive - Oct 18, 2005 * <amatch> used instead of <afile> in autocmds - Oct 18, 2005 * handles writing to compressed archives - Nov 03, 2005 * handles writing tarfiles across a network using - netrw#NetWrite() - v2 * converted to use Vim7's new autoload feature by - Bram Moolenaar - v1 (original) * Michael Toren (see http://michael.toren.net/code/) + v31 Apr 02, 2017 * (klartext) reported that browsing encrypted + files in a zip archive created unencrypted + swap files. I am applying a similar fix + used on zip.vim to tar.vim: new buffers + are opened with |:noswapfile|. + May 16, 2017 * When the mouse option isn't empty, the + leftmouse can be used to select a file + in the tar-file listing. + v30 Apr 22, 2014 * .tgz files are ambiguous: they may have been + compressed with either gzip or bzip2. Tar.vim + disambiguates by using unix's "file" command. + Feb 18, 2016 * Changed =~ to =~# where appropriate + Feb 18, 2017 * Now also permits xz decompression + v28 Jun 23, 2011 * a few more decompression options (tbz tb2 txz) + v27 May 31, 2011 * moved cygwin detection before g:tar_copycmd + handling + * inserted additional |:keepj| modifiers + * changed silent to sil! (|:silent|) + v26 Aug 09, 2010 * uses buffer-local instead of window variables + to hold tarfile name + * inserted keepj before 0d to protect jump list + v25 Jun 19, 2010 * (Jan Steffens) added support for xz + compression + v24 Apr 07, 2009 * :Untarvim command implemented + Sep 28, 2009 * Added lzma support + v22 Aug 08, 2008 * security fixes + v16 Jun 06, 2008 * tarfile:: used instead of tarfile: when + editing files inside tarballs. Fixes a + problem with tarballs called things like + c:\abc.tar. (tnx to Bill McCarthy) + v14 May 09, 2008 * arno caught a security bug + May 28, 2008 * various security improvements. Now requires + patch 299 which provides the fnameescape() + function + May 30, 2008 * allows one to view *.gz and *.bz2 files that + are in *.tar files. + v12 Sep 07, 2007 * &shq now used if not the empty string for + g:tar_shq + v10 May 02, 2006 * now using "redraw then echo" to show messages, + instead of "echo and prompt user" + v9 May 02, 2006 * improved detection of masquerading as tar file + v8 May 02, 2006 * allows editing of files that merely masquerade + as tar files + v7 Mar 22, 2006 * work on making tar plugin work across network + Mar 27, 2006 * g:tar_cmd now available for users to change + the name of the tar program to be used. By + default, of course, it's "tar". + v6 Dec 21, 2005 * writing to files not in directories caused + problems - fixed (pointed out by + Christian Robinson) + v5 Nov 22, 2005 * report option workaround installed + v3 Sep 16, 2005 * handles writing files in an archive back to + the archive + Oct 18, 2005 * <amatch> used instead of <afile> in autocmds + Oct 18, 2005 * handles writing to compressed archives + Nov 03, 2005 * handles writing tarfiles across a network + using netrw#NetWrite() + v2 * converted to use Vim7's new autoload feature + by Bram Moolenaar + v1 (original) * Michael Toren + (see http://michael.toren.net/code/) ============================================================================== vim:tw=78:ts=8:noet:ft=help diff --git a/runtime/doc/starting.txt b/runtime/doc/starting.txt index 4a99aa47bf..d3647246fa 100644 --- a/runtime/doc/starting.txt +++ b/runtime/doc/starting.txt @@ -106,8 +106,6 @@ argument. This can be used to find out where time is spent while loading your |config|, plugins and opening the first file. When {fname} already exists new messages are appended. - (Only available when compiled with the |+startuptime| - feature). *-+* +[num] The cursor will be positioned on line "num" for the first diff --git a/runtime/doc/syntax.txt b/runtime/doc/syntax.txt index 7da886dabd..b45e9ed450 100644 --- a/runtime/doc/syntax.txt +++ b/runtime/doc/syntax.txt @@ -1715,7 +1715,7 @@ There are several html preprocessor languages out there. html.vim has been written such that it should be trivial to include it. To do so add the following two lines to the syntax coloring file for that language (the example comes from the asp.vim file): - +> runtime! syntax/html.vim syn cluster htmlPreproc add=asp diff --git a/runtime/doc/usr_41.txt b/runtime/doc/usr_41.txt index e92e464c6a..63c899da0c 100644 --- a/runtime/doc/usr_41.txt +++ b/runtime/doc/usr_41.txt @@ -613,6 +613,7 @@ String manipulation: *string-functions* iconv() convert text from one encoding to another byteidx() byte index of a character in a string byteidxcomp() like byteidx() but count composing characters + charidx() character index of a byte in a string repeat() repeat a string multiple times eval() evaluate a string expression execute() execute an Ex command and get the output diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index 808af5f544..0c1e216164 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -144,7 +144,6 @@ Command-line highlighting: removed in the future). Commands: - |:autocmd| accepts the `++once` flag |:checkhealth| |:drop| is always available |:Man| is available by default, with many improvements such as completion @@ -157,8 +156,6 @@ Events: |TermOpen| |UIEnter| |UILeave| - |VimResume| - |VimSuspend| |WinClosed| Functions: @@ -195,11 +192,10 @@ Options: 'cpoptions' flags: |cpo-_| 'display' flags: "msgsep" minimizes scrolling when showing messages 'guicursor' works in the terminal - 'fillchars' flags: "msgsep" (see 'display'), "eob" for |hl-EndOfBuffer| - marker, "foldopen", "foldsep", "foldclose" + 'fillchars' flags: "msgsep" (see 'display'), "foldopen", "foldsep", + "foldclose" 'foldcolumn' supports up to 9 dynamic/fixed columns 'inccommand' shows interactive results for |:substitute|-like commands - 'listchars' local to window 'pumblend' pseudo-transparent popupmenu 'scrollback' 'signcolumn' supports up to 9 dynamic/fixed columns diff --git a/runtime/doc/windows.txt b/runtime/doc/windows.txt index 2c3ffcbe9a..35efb1bbce 100644 --- a/runtime/doc/windows.txt +++ b/runtime/doc/windows.txt @@ -1039,6 +1039,11 @@ list of buffers. |unlisted-buffer| line when the buffer is first entered. Note that other commands after the + will be ignored. + *:balt* +:balt [+lnum] {fname} + Like `:badd` and also set the alternate file for the current + window to {fname}. + :[N]bd[elete][!] *:bd* *:bdel* *:bdelete* *E516* :bd[elete][!] [N] Unload buffer [N] (default: current buffer) and delete it from diff --git a/runtime/filetype.vim b/runtime/filetype.vim index 53fd66c4df..6a13e67ac5 100644 --- a/runtime/filetype.vim +++ b/runtime/filetype.vim @@ -212,6 +212,9 @@ au BufNewFile,BufRead *.bc setf bc " BDF font au BufNewFile,BufRead *.bdf setf bdf +" Beancount +au BufNewFile,BufRead *.beancount setf beancount + " BibTeX bibliography database file au BufNewFile,BufRead *.bib setf bib @@ -1491,6 +1494,9 @@ au BufNewFile,BufRead *.sdl,*.pr setf sdl " sed au BufNewFile,BufRead *.sed setf sed +" svelte +au BufNewFile,BufRead *.svelte setf svelte + " Sieve (RFC 3028, 5228) au BufNewFile,BufRead *.siv,*.sieve setf sieve diff --git a/runtime/indent/tcl.vim b/runtime/indent/tcl.vim index d77081841d..eafb8dd568 100644 --- a/runtime/indent/tcl.vim +++ b/runtime/indent/tcl.vim @@ -1,8 +1,8 @@ " Vim indent file " Language: Tcl -" Previous Maintainer: Nikolai Weibull <now@bitwi.se> " Latest Update: Chris Heithoff <chrisheithoff@gmail.com> -" Latest Revision: 2018-12-05 +" Previous Maintainer: Nikolai Weibull <now@bitwi.se> +" Latest Revision: 2018-12-05 if exists("b:did_indent") finish diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index a6f118abde..841c365cbe 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -16,10 +16,7 @@ local validate = vim.validate local lsp = { protocol = protocol; - -- TODO(tjdevries): Add in the warning that `callbacks` is no longer supported. - -- util.warn_once("vim.lsp.callbacks is deprecated. Use vim.lsp.handlers instead.") handlers = default_handlers; - callbacks = default_handlers; buf = require'vim.lsp.buf'; diagnostic = require'vim.lsp.diagnostic'; @@ -219,8 +216,6 @@ local function validate_client_config(config) } validate { root_dir = { config.root_dir, is_dir, "directory" }; - -- TODO(remove-callbacks) - callbacks = { config.callbacks, "t", true }; handlers = { config.handlers, "t", true }; capabilities = { config.capabilities, "t", true }; cmd_cwd = { config.cmd_cwd, optional_validator(is_dir), "directory" }; @@ -235,13 +230,6 @@ local function validate_client_config(config) flags = { config.flags, "t", true }; } - -- TODO(remove-callbacks) - if config.handlers and config.callbacks then - error(debug.traceback( - "Unable to configure LSP with both 'config.handlers' and 'config.callbacks'. Use 'config.handlers' exclusively." - )) - end - local cmd, cmd_args = lsp._cmd_parts(config.cmd) local offset_encoding = valid_encodings.UTF16 if config.offset_encoding then @@ -473,8 +461,7 @@ function lsp.start_client(config) local client_id = next_client_id() - -- TODO(remove-callbacks) - local handlers = config.handlers or config.callbacks or {} + local handlers = config.handlers or {} local name = config.name or tostring(client_id) local log_prefix = string.format("LSP[%s]", name) @@ -548,19 +535,20 @@ function lsp.start_client(config) function dispatch.on_exit(code, signal) active_clients[client_id] = nil uninitialized_clients[client_id] = nil - local active_buffers = {} - for bufnr, client_ids in pairs(all_buffer_active_clients) do - if client_ids[client_id] then - table.insert(active_buffers, bufnr) - end + + lsp.diagnostic.reset(client_id, all_buffer_active_clients) + all_client_active_buffers[client_id] = nil + for _, client_ids in pairs(all_buffer_active_clients) do client_ids[client_id] = nil end - -- Buffer level cleanup - vim.schedule(function() - for _, bufnr in ipairs(active_buffers) do - lsp.diagnostic.clear(bufnr) - end - end) + + if code ~= 0 or (signal ~= 0 and signal ~= 15) then + local msg = string.format("Client %s quit with exit code %s and signal %s", client_id, code, signal) + vim.schedule(function() + vim.notify(msg, vim.log.levels.WARN) + end) + end + if config.on_exit then pcall(config.on_exit, code, signal, client_id) end @@ -579,8 +567,6 @@ function lsp.start_client(config) offset_encoding = offset_encoding; config = config; - -- TODO(remove-callbacks) - callbacks = handlers; handlers = handlers; -- for $/progress report messages = { name = name, messages = {}, progress = {}, status = {} } @@ -751,6 +737,13 @@ function lsp.start_client(config) --- --@param force (bool, optional) function client.stop(force) + + lsp.diagnostic.reset(client_id, all_buffer_active_clients) + all_client_active_buffers[client_id] = nil + for _, client_ids in pairs(all_buffer_active_clients) do + client_ids[client_id] = nil + end + local handle = rpc.handle if handle:is_closing() then return @@ -1016,23 +1009,12 @@ end function lsp.stop_client(client_id, force) local ids = type(client_id) == 'table' and client_id or {client_id} for _, id in ipairs(ids) do - local resolved_client_id if type(id) == 'table' and id.stop ~= nil then id.stop(force) - resolved_client_id = id.id elseif active_clients[id] then active_clients[id].stop(force) - resolved_client_id = id elseif uninitialized_clients[id] then uninitialized_clients[id].stop(true) - resolved_client_id = id - end - if resolved_client_id then - local client_buffers = lsp.get_buffers_by_client_id(resolved_client_id) - for idx = 1, #client_buffers do - lsp.diagnostic.clear(client_buffers[idx], resolved_client_id) - end - all_client_active_buffers[resolved_client_id] = nil end end end diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua index 00219b6d98..31116985e2 100644 --- a/runtime/lua/vim/lsp/buf.lua +++ b/runtime/lua/vim/lsp/buf.lua @@ -310,15 +310,21 @@ function M.workspace_symbol(query) request('workspace/symbol', params) end ---- Send request to server to resolve document highlights for the ---- current text document position. This request can be associated ---- to key mapping or to events such as `CursorHold`, eg: +--- Send request to the server to resolve document highlights for the current +--- text document position. This request can be triggered by a key mapping or +--- by events such as `CursorHold`, eg: --- --- <pre> --- vim.api.nvim_command [[autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()]] --- vim.api.nvim_command [[autocmd CursorHoldI <buffer> lua vim.lsp.buf.document_highlight()]] --- vim.api.nvim_command [[autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()]] --- </pre> +--- +--- Note: Usage of |vim.lsp.buf.document_highlight()| requires the following highlight groups +--- to be defined or you won't be able to see the actual highlights. +--- |LspReferenceText| +--- |LspReferenceRead| +--- |LspReferenceWrite| function M.document_highlight() local params = util.make_position_params() request('textDocument/documentHighlight', params) diff --git a/runtime/lua/vim/lsp/callbacks.lua b/runtime/lua/vim/lsp/callbacks.lua deleted file mode 100644 index 1da92b900d..0000000000 --- a/runtime/lua/vim/lsp/callbacks.lua +++ /dev/null @@ -1,4 +0,0 @@ -local util = require 'vim.lsp.util' - -util._warn_once("require('vim.lsp.callbacks') is deprecated. Use vim.lsp.handlers instead.") -return require('vim.lsp.handlers') diff --git a/runtime/lua/vim/lsp/diagnostic.lua b/runtime/lua/vim/lsp/diagnostic.lua index a625098bab..a1f24706c0 100644 --- a/runtime/lua/vim/lsp/diagnostic.lua +++ b/runtime/lua/vim/lsp/diagnostic.lua @@ -264,10 +264,14 @@ local function set_diagnostic_cache(diagnostics, bufnr, client_id) -- The diagnostic's severity. Can be omitted. If omitted it is up to the -- client to interpret diagnostics as error, warning, info or hint. -- TODO: Replace this with server-specific heuristics to infer severity. + local buf_line_count = vim.api.nvim_buf_line_count(bufnr) for _, diagnostic in ipairs(diagnostics) do if diagnostic.severity == nil then diagnostic.severity = DiagnosticSeverity.Error end + -- Account for servers that place diagnostics on terminating newline + local start = diagnostic.range.start + start.line = math.min(start.line, buf_line_count - 1) end diagnostic_cache[bufnr][client_id] = diagnostics @@ -1158,6 +1162,24 @@ local loclist_type_map = { [DiagnosticSeverity.Hint] = 'I', } + +--- Clear diagnotics and diagnostic cache +--- +--- Handles saving diagnostics from multiple clients in the same buffer. +---@param client_id number +---@param buffer_client_map table map of buffers to active clients +function M.reset(client_id, buffer_client_map) + buffer_client_map = vim.deepcopy(buffer_client_map) + vim.schedule(function() + for bufnr, client_ids in pairs(buffer_client_map) do + if client_ids[client_id] then + clear_diagnostic_cache(bufnr, client_id) + M.clear(bufnr, client_id) + end + end + end) +end + --- Sets the location list ---@param opts table|nil Configuration table. Keys: --- - {open_loclist}: (boolean, default true) diff --git a/runtime/lua/vim/lsp/handlers.lua b/runtime/lua/vim/lsp/handlers.lua index 7eac3febd9..0cf80e1443 100644 --- a/runtime/lua/vim/lsp/handlers.lua +++ b/runtime/lua/vim/lsp/handlers.lua @@ -13,7 +13,7 @@ local M = {} --- Writes to error buffer. --@param ... (table of strings) Will be concatenated before being written local function err_message(...) - api.nvim_err_writeln(table.concat(vim.tbl_flatten{...})) + vim.notify(table.concat(vim.tbl_flatten{...}), vim.log.levels.ERROR) api.nvim_command("redraw") end @@ -26,7 +26,7 @@ end -- @msg of type ProgressParams -- Basically a token of type number/string -local function progress_callback(_, _, params, client_id) +local function progress_handler(_, _, params, client_id) local client = vim.lsp.get_client_by_id(client_id) local client_name = client and client.name or string.format("id=%d", client_id) if not client then @@ -62,7 +62,7 @@ local function progress_callback(_, _, params, client_id) end --@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#progress -M['$/progress'] = progress_callback +M['$/progress'] = progress_handler --@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window_workDoneProgress_create M['window/workDoneProgress/create'] = function(_, _, params, client_id) @@ -409,7 +409,7 @@ for k, fn in pairs(M) do }) if err then - error(tostring(err)) + return err_message(tostring(err)) end return fn(err, method, params, client_id, bufnr, config) diff --git a/runtime/lua/vim/lsp/log.lua b/runtime/lua/vim/lsp/log.lua index b6e91e37b9..331e980e67 100644 --- a/runtime/lua/vim/lsp/log.lua +++ b/runtime/lua/vim/lsp/log.lua @@ -10,13 +10,7 @@ local log = {} -- Can be used to lookup the number from the name or the name from the number. -- Levels by name: 'trace', 'debug', 'info', 'warn', 'error' -- Level numbers begin with 'trace' at 0 -log.levels = { - TRACE = 0; - DEBUG = 1; - INFO = 2; - WARN = 3; - ERROR = 4; -} +log.levels = vim.log.levels -- Default log level is warn. local current_log_level = log.levels.WARN @@ -38,6 +32,8 @@ do vim.fn.mkdir(vim.fn.stdpath('cache'), "p") local logfile = assert(io.open(logfilename, "a+")) + -- Start message for logging + logfile:write(string.format("[ START ] %s ] LSP logging initiated\n", os.date(log_date_format))) for level, levelnr in pairs(log.levels) do -- Also export the log level on the root object. log[level] = levelnr @@ -74,8 +70,6 @@ do logfile:flush() end end - -- Add some space to make it easier to distinguish different neovim runs. - logfile:write("\n") end -- This is put here on purpose after the loop above so that it doesn't diff --git a/runtime/lua/vim/lsp/protocol.lua b/runtime/lua/vim/lsp/protocol.lua index 3e111c154a..388f65c180 100644 --- a/runtime/lua/vim/lsp/protocol.lua +++ b/runtime/lua/vim/lsp/protocol.lua @@ -938,7 +938,7 @@ function protocol.resolve_capabilities(server_capabilities) text_document_did_change = textDocumentSync; text_document_will_save = false; text_document_will_save_wait_until = false; - text_document_save = false; + text_document_save = true; text_document_save_include_text = false; } elseif type(textDocumentSync) == 'table' then diff --git a/runtime/lua/vim/lsp/rpc.lua b/runtime/lua/vim/lsp/rpc.lua index 90f51dfc5a..4e2dd7c8e8 100644 --- a/runtime/lua/vim/lsp/rpc.lua +++ b/runtime/lua/vim/lsp/rpc.lua @@ -376,6 +376,9 @@ local function start(cmd, cmd_args, dispatchers, extra_spawn_params) spawn_params.env = env_merge(extra_spawn_params.env) end handle, pid = uv.spawn(cmd, spawn_params, onexit) + if handle == nil then + error(string.format("start `%s` failed: %s", cmd, pid)) + end end --@private @@ -386,7 +389,7 @@ local function start(cmd, cmd_args, dispatchers, extra_spawn_params) --@returns true if the payload could be scheduled, false if the main event-loop is in the process of closing. local function encode_and_send(payload) local _ = log.debug() and log.debug("rpc.send.payload", payload) - if handle:is_closing() then return false end + if handle == nil or handle:is_closing() then return false end -- TODO(ashkan) remove this once we have a Lua json_encode schedule(function() local encoded = assert(json_encode(payload)) diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index e33e0109b6..6fb9f09c99 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -18,14 +18,6 @@ end local M = {} --- TODO(remove-callbacks) -M.diagnostics_by_buf = setmetatable({}, { - __index = function(_, bufnr) - warn_once("diagnostics_by_buf is deprecated. Use 'vim.lsp.diagnostic.get'") - return vim.lsp.diagnostic.get(bufnr) - end -}) - --@private local function split_lines(value) return split(value, '\n', true) @@ -211,7 +203,7 @@ function M.apply_text_edits(text_edits, bufnr) local lines = api.nvim_buf_get_lines(bufnr, start_line, finish_line + 1, false) local fix_eol = api.nvim_buf_get_option(bufnr, 'fixeol') local set_eol = fix_eol and api.nvim_buf_line_count(bufnr) <= finish_line + 1 - if set_eol and #lines[#lines] ~= 0 then + if set_eol and (#lines == 0 or #lines[#lines] ~= 0) then table.insert(lines, '') end @@ -726,7 +718,7 @@ function M.focusable_float(unique_name, fn) local bufnr = api.nvim_get_current_buf() do local win = find_window_by_var(unique_name, bufnr) - if win and api.nvim_win_is_valid(win) and not vim.fn.pumvisible() then + if win and api.nvim_win_is_valid(win) and vim.fn.pumvisible() == 0 then api.nvim_set_current_win(win) api.nvim_command("stopinsert") return @@ -1027,78 +1019,6 @@ function M.open_floating_preview(contents, filetype, opts) return floating_bufnr, floating_winnr end --- TODO(remove-callbacks) -do - --@deprecated - function M.get_severity_highlight_name(severity) - warn_once("vim.lsp.util.get_severity_highlight_name is deprecated.") - return vim.lsp.diagnostic._get_severity_highlight_name(severity) - end - - --@deprecated - function M.buf_clear_diagnostics(bufnr, client_id) - warn_once("buf_clear_diagnostics is deprecated. Use vim.lsp.diagnostic.clear") - return vim.lsp.diagnostic.clear(bufnr, client_id) - end - - --@deprecated - function M.get_line_diagnostics() - warn_once("get_line_diagnostics is deprecated. Use vim.lsp.diagnostic.get_line_diagnostics") - - local bufnr = api.nvim_get_current_buf() - local line_nr = api.nvim_win_get_cursor(0)[1] - 1 - - return vim.lsp.diagnostic.get_line_diagnostics(bufnr, line_nr) - end - - --@deprecated - function M.show_line_diagnostics() - warn_once("show_line_diagnostics is deprecated. Use vim.lsp.diagnostic.show_line_diagnostics") - - local bufnr = api.nvim_get_current_buf() - local line_nr = api.nvim_win_get_cursor(0)[1] - 1 - - return vim.lsp.diagnostic.show_line_diagnostics(bufnr, line_nr) - end - - --@deprecated - function M.buf_diagnostics_save_positions(bufnr, diagnostics, client_id) - warn_once("buf_diagnostics_save_positions is deprecated. Use vim.lsp.diagnostic.save") - return vim.lsp.diagnostic.save(diagnostics, bufnr, client_id) - end - - --@deprecated - function M.buf_diagnostics_get_positions(bufnr, client_id) - warn_once("buf_diagnostics_get_positions is deprecated. Use vim.lsp.diagnostic.get") - return vim.lsp.diagnostic.get(bufnr, client_id) - end - - --@deprecated - function M.buf_diagnostics_underline(bufnr, diagnostics, client_id) - warn_once("buf_diagnostics_underline is deprecated. Use 'vim.lsp.diagnostic.set_underline'") - return vim.lsp.diagnostic.set_underline(diagnostics, bufnr, client_id) - end - - --@deprecated - function M.buf_diagnostics_virtual_text(bufnr, diagnostics, client_id) - warn_once("buf_diagnostics_virtual_text is deprecated. Use 'vim.lsp.diagnostic.set_virtual_text'") - return vim.lsp.diagnostic.set_virtual_text(diagnostics, bufnr, client_id) - end - - --@deprecated - function M.buf_diagnostics_signs(bufnr, diagnostics, client_id) - warn_once("buf_diagnostics_signs is deprecated. Use 'vim.lsp.diagnostic.set_signs'") - return vim.lsp.diagnostic.set_signs(diagnostics, bufnr, client_id) - end - - --@deprecated - function M.buf_diagnostics_count(kind, client_id) - warn_once("buf_diagnostics_count is deprecated. Use 'vim.lsp.diagnostic.get_count'") - return vim.lsp.diagnostic.get_count(vim.api.nvim_get_current_buf(), client_id, kind) - end - -end - do --[[ References ]] local reference_ns = api.nvim_create_namespace("vim_lsp_references") diff --git a/runtime/lua/vim/treesitter.lua b/runtime/lua/vim/treesitter.lua index 38ac182e32..3af66b134c 100644 --- a/runtime/lua/vim/treesitter.lua +++ b/runtime/lua/vim/treesitter.lua @@ -44,13 +44,18 @@ function M._create_parser(bufnr, lang, opts) self:_on_bytes(...) end - local function detach_cb() + local function detach_cb(_, ...) if parsers[bufnr] == self then parsers[bufnr] = nil end + self:_on_detach(...) end - a.nvim_buf_attach(self:source(), false, {on_bytes=bytes_cb, on_detach=detach_cb, preview=true}) + local function reload_cb(_, ...) + self:_on_reload(...) + end + + a.nvim_buf_attach(self:source(), false, {on_bytes=bytes_cb, on_detach=detach_cb, on_reload=reload_cb, preview=true}) self:parse() diff --git a/runtime/lua/vim/treesitter/highlighter.lua b/runtime/lua/vim/treesitter/highlighter.lua index 275e960e28..6b833c6d35 100644 --- a/runtime/lua/vim/treesitter/highlighter.lua +++ b/runtime/lua/vim/treesitter/highlighter.lua @@ -113,8 +113,9 @@ function TSHighlighter.new(tree, opts) opts = opts or {} self.tree = tree tree:register_cbs { - on_changedtree = function(...) self:on_changedtree(...) end, - on_bytes = function(...) self:on_bytes(...) end + on_changedtree = function(...) self:on_changedtree(...) end; + on_bytes = function(...) self:on_bytes(...) end; + on_detach = function(...) self:on_detach(...) end; } self.bufnr = tree:source() @@ -176,6 +177,10 @@ function TSHighlighter:on_bytes(_, _, start_row, _, _, _, _, _, new_end) a.nvim__buf_redraw_range(self.bufnr, start_row, start_row + new_end + 1) end +function TSHighlighter:on_detach() + self:destroy() +end + function TSHighlighter:on_changedtree(changes) for _, ch in ipairs(changes or {}) do a.nvim__buf_redraw_range(self.bufnr, ch[1], ch[3]+1) diff --git a/runtime/lua/vim/treesitter/language.lua b/runtime/lua/vim/treesitter/language.lua index d60cd2d0c7..eed28e0e41 100644 --- a/runtime/lua/vim/treesitter/language.lua +++ b/runtime/lua/vim/treesitter/language.lua @@ -2,12 +2,12 @@ local a = vim.api local M = {} ---- Asserts that the provided language is installed, and optionnaly provide a path for the parser +--- Asserts that the provided language is installed, and optionally provide a path for the parser -- -- Parsers are searched in the `parser` runtime directory. -- -- @param lang The language the parser should parse --- @param path Optionnal path the parser is located at +-- @param path Optional path the parser is located at -- @param silent Don't throw an error if language not found function M.require_language(lang, path, silent) if vim._ts_has_language(lang) then diff --git a/runtime/lua/vim/treesitter/languagetree.lua b/runtime/lua/vim/treesitter/languagetree.lua index c864fe5878..4168c1e365 100644 --- a/runtime/lua/vim/treesitter/languagetree.lua +++ b/runtime/lua/vim/treesitter/languagetree.lua @@ -6,14 +6,14 @@ local LanguageTree = {} LanguageTree.__index = LanguageTree -- Represents a single treesitter parser for a language. --- The language can contain child languages with in it's range, +-- The language can contain child languages with in its range, -- hence the tree. -- -- @param source Can be a bufnr or a string of text to parse -- @param lang The language this tree represents -- @param opts Options table --- @param opts.queries A table of language to injection query strings --- This is useful for overridding the built in runtime file +-- @param opts.queries A table of language to injection query strings. +-- This is useful for overriding the built-in runtime file -- searching for the injection language query per language. function LanguageTree.new(source, lang, opts) language.require_language(lang) @@ -21,8 +21,8 @@ function LanguageTree.new(source, lang, opts) local custom_queries = opts.queries or {} local self = setmetatable({ - _source=source, - _lang=lang, + _source = source, + _lang = lang, _children = {}, _regions = {}, _trees = {}, @@ -35,6 +35,7 @@ function LanguageTree.new(source, lang, opts) _callbacks = { changedtree = {}, bytes = {}, + detach = {}, child_added = {}, child_removed = {} }, @@ -44,12 +45,17 @@ function LanguageTree.new(source, lang, opts) return self end --- Invalidates this parser and all it's children -function LanguageTree:invalidate() +-- Invalidates this parser and all its children +function LanguageTree:invalidate(reload) self._valid = false + -- buffer was reloaded, reparse all trees + if reload then + self._trees = {} + end + for _, child in ipairs(self._children) do - child:invalidate() + child:invalidate(reload) end end @@ -97,7 +103,7 @@ function LanguageTree:parse() self._trees = {} -- If there are no ranges, set to an empty list - -- so the included ranges in the parser ar cleared. + -- so the included ranges in the parser are cleared. if self._regions and #self._regions > 0 then for i, ranges in ipairs(self._regions) do local old_tree = old_trees[i] @@ -214,7 +220,7 @@ function LanguageTree:remove_child(lang) end end --- Destroys this language tree and all it's children. +-- Destroys this language tree and all its children. -- Any cleanup logic should be performed here. -- Note, this DOES NOT remove this tree from a parent. -- `remove_child` must be called on the parent to remove it. @@ -241,19 +247,19 @@ end -- -- Note, this call invalidates the tree and requires it to be parsed again. -- --- @param regions A list of regions this tree should manange and parse. +-- @param regions A list of regions this tree should manage and parse. function LanguageTree:set_included_regions(regions) - -- Transform the tables from 4 element long to 6 element long (with byte offset) - for _, region in ipairs(regions) do - for i, range in ipairs(region) do - if type(range) == "table" and #range == 4 then - -- TODO(vigoux): I don't think string parsers are useful for now - if type(self._source) == "number" then + -- TODO(vigoux): I don't think string parsers are useful for now + if type(self._source) == "number" then + -- Transform the tables from 4 element long to 6 element long (with byte offset) + for _, region in ipairs(regions) do + for i, range in ipairs(region) do + if type(range) == "table" and #range == 4 then local start_row, start_col, end_row, end_col = unpack(range) -- Easy case, this is a buffer parser -- TODO(vigoux): proper byte computation here, and account for EOL ? - local start_byte = a.nvim_buf_get_offset(self.bufnr, start_row) + start_col - local end_byte = a.nvim_buf_get_offset(self.bufnr, end_row) + end_col + local start_byte = a.nvim_buf_get_offset(self._source, start_row) + start_col + local end_byte = a.nvim_buf_get_offset(self._source, end_row) + end_col region[i] = { start_row, start_col, start_byte, end_row, end_col, end_byte } end @@ -397,14 +403,24 @@ function LanguageTree:_on_bytes(bufnr, changed_tick, new_row, new_col, new_byte) end +function LanguageTree:_on_reload() + self:invalidate(true) +end + + +function LanguageTree:_on_detach(...) + self:invalidate(true) + self:_do_callback('detach', ...) +end + --- Registers callbacks for the parser -- @param cbs An `nvim_buf_attach`-like table argument with the following keys : -- `on_bytes` : see `nvim_buf_attach`, but this will be called _after_ the parsers callback. --- `on_changedtree` : a callback that will be called everytime the tree has syntactical changes. +-- `on_changedtree` : a callback that will be called every time the tree has syntactical changes. -- it will only be passed one argument, that is a table of the ranges (as node ranges) that -- changed. -- `on_child_added` : emitted when a child is added to the tree. --- `on_child_removed` : emitted when a child is remvoed from the tree. +-- `on_child_removed` : emitted when a child is removed from the tree. function LanguageTree:register_cbs(cbs) if not cbs then return end @@ -416,6 +432,10 @@ function LanguageTree:register_cbs(cbs) table.insert(self._callbacks.bytes, cbs.on_bytes) end + if cbs.on_detach then + table.insert(self._callbacks.detach, cbs.on_detach) + end + if cbs.on_child_added then table.insert(self._callbacks.child_added, cbs.on_child_added) end diff --git a/runtime/lua/vim/treesitter/query.lua b/runtime/lua/vim/treesitter/query.lua index e49f54681d..8b94348994 100644 --- a/runtime/lua/vim/treesitter/query.lua +++ b/runtime/lua/vim/treesitter/query.lua @@ -111,7 +111,7 @@ end --- Gets the text corresponding to a given node -- @param node the node --- @param bufnr the buffer from which the node in extracted. +-- @param bufnr the buffer from which the node is extracted. function M.get_node_text(node, source) local start_row, start_col, start_byte = node:start() local end_row, end_col, end_byte = node:end_() @@ -215,10 +215,10 @@ predicate_handlers["vim-match?"] = predicate_handlers["match?"] local directive_handlers = { ["set!"] = function(_, _, _, pred, metadata) if #pred == 4 then - -- (set! @capture "key" "value") + -- (#set! @capture "key" "value") metadata[pred[2]][pred[3]] = pred[4] else - -- (set! "key" "value") + -- (#set! "key" "value") metadata[pred[2]] = pred[3] end end, @@ -245,7 +245,7 @@ local directive_handlers = { end } ---- Adds a new predicates to be used in queries +--- Adds a new predicate to be used in queries -- -- @param name the name of the predicate, without leading # -- @param handler the handler function to be used @@ -355,10 +355,10 @@ end --- Iterates of the captures of self on a given range. -- --- @param node The node under witch the search will occur +-- @param node The node under which the search will occur -- @param buffer The source buffer to search -- @param start The starting line of the search --- @param stop The stoping line of the search (end-exclusive) +-- @param stop The stopping line of the search (end-exclusive) -- -- @returns The matching capture id -- @returns The captured node @@ -388,12 +388,12 @@ function Query:iter_captures(node, source, start, stop) return iter end ---- Iterates of the matches of self on a given range. +--- Iterates the matches of self on a given range. -- --- @param node The node under witch the search will occur +-- @param node The node under which the search will occur -- @param buffer The source buffer to search -- @param start The starting line of the search --- @param stop The stoping line of the search (end-exclusive) +-- @param stop The stopping line of the search (end-exclusive) -- -- @returns The matching pattern id -- @returns The matching match diff --git a/runtime/menu.vim b/runtime/menu.vim index 3756787e7f..cd56eb5583 100644 --- a/runtime/menu.vim +++ b/runtime/menu.vim @@ -356,8 +356,8 @@ func! s:SetupColorSchemes() abort let s:did_setup_color_schemes = 1 let n = globpath(&runtimepath, "colors/*.vim", 1, 1) - let n += globpath(&runtimepath, "pack/*/start/*/colors/*.vim", 1, 1) - let n += globpath(&runtimepath, "pack/*/opt/*/colors/*.vim", 1, 1) + let n += globpath(&packpath, "pack/*/start/*/colors/*.vim", 1, 1) + let n += globpath(&packpath, "pack/*/opt/*/colors/*.vim", 1, 1) " Ignore case for VMS and windows, sort on name let names = sort(map(n, 'substitute(v:val, "\\c.*[/\\\\:\\]]\\([^/\\\\:]*\\)\\.vim", "\\1", "")'), 1) diff --git a/runtime/plugin/netrwPlugin.vim b/runtime/plugin/netrwPlugin.vim index 2d67f6a4e4..87302cf23b 100644 --- a/runtime/plugin/netrwPlugin.vim +++ b/runtime/plugin/netrwPlugin.vim @@ -1,7 +1,7 @@ " netrwPlugin.vim: Handles file transfer and remote directory listing across a network " PLUGIN SECTION -" Date: Feb 08, 2016 -" Maintainer: Charles E Campbell <NdrOchip@ScampbellPfamily.AbizM-NOSPAM> +" Date: Feb 08, 2016 - Jan 07, 2020 +" Maintainer: Charles E Campbell <NcampObell@SdrPchip.AorgM-NOSPAM> " GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim " Copyright: Copyright (C) 1999-2013 Charles E. Campbell {{{1 " Permission is hereby granted to use and distribute this code, @@ -20,7 +20,7 @@ if &cp || exists("g:loaded_netrwPlugin") finish endif -let g:loaded_netrwPlugin = "v165" +let g:loaded_netrwPlugin = "v168" let s:keepcpo = &cpo set cpo&vim "DechoRemOn @@ -81,7 +81,7 @@ if !exists("g:netrw_nogx") if !hasmapto('<Plug>NetrwBrowseX') nmap <unique> gx <Plug>NetrwBrowseX endif - nno <silent> <Plug>NetrwBrowseX :call netrw#BrowseX(expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>')),netrw#CheckIfRemote())<cr> + nno <silent> <Plug>NetrwBrowseX :call netrw#BrowseX(netrw#GX(),netrw#CheckIfRemote(netrw#GX()))<cr> endif if maparg('gx','v') == "" if !hasmapto('<Plug>NetrwBrowseXVis') diff --git a/runtime/plugin/tarPlugin.vim b/runtime/plugin/tarPlugin.vim index 6d9e6bd540..d55492a93e 100644 --- a/runtime/plugin/tarPlugin.vim +++ b/runtime/plugin/tarPlugin.vim @@ -14,7 +14,7 @@ if &cp || exists("g:loaded_tarPlugin") finish endif -let g:loaded_tarPlugin = "v29" +let g:loaded_tarPlugin = "v32" let s:keepcpo = &cpo set cpo&vim @@ -39,11 +39,13 @@ augroup tar au BufReadCmd *.lrp call tar#Browse(expand("<amatch>")) au BufReadCmd *.tar.bz2 call tar#Browse(expand("<amatch>")) au BufReadCmd *.tar.Z call tar#Browse(expand("<amatch>")) - au BufReadCmd *.tgz call tar#Browse(expand("<amatch>")) au BufReadCmd *.tbz call tar#Browse(expand("<amatch>")) + au BufReadCmd *.tgz call tar#Browse(expand("<amatch>")) au BufReadCmd *.tar.lzma call tar#Browse(expand("<amatch>")) au BufReadCmd *.tar.xz call tar#Browse(expand("<amatch>")) au BufReadCmd *.txz call tar#Browse(expand("<amatch>")) + au BufReadCmd *.tar.zst call tar#Browse(expand("<amatch>")) + au BufReadCmd *.tzs call tar#Browse(expand("<amatch>")) augroup END com! -nargs=? -complete=file Vimuntar call tar#Vimuntar(<q-args>) diff --git a/runtime/syntax/cabal.vim b/runtime/syntax/cabal.vim index 8af47d4042..92e6b8331e 100644 --- a/runtime/syntax/cabal.vim +++ b/runtime/syntax/cabal.vim @@ -4,7 +4,7 @@ " Maintainer: Marcin Szamotulski <profunctor@pm.me> " Previous Maintainer: Vincent Berthoux <twinside@gmail.com> " File Types: .cabal -" Last Change: 15 May 2018 +" Last Change: 21 Nov 2020 " v1.5: Incorporated changes from " https://github.com/sdiehl/haskell-vim-proto/blob/master/vim/syntax/cabal.vim " Use `syn keyword` instead of `syn match`. @@ -62,11 +62,12 @@ syn keyword cabalCategory contained \ source-repository \ flag \ custom-setup + \ common syn match cabalCategoryTitle contained /[^{]*\ze{\?/ syn match cabalCategoryRegion \ contains=cabalCategory,cabalCategoryTitle \ nextgroup=cabalCategory skipwhite - \ /^\c\s*\(contained\|executable\|library\|benchmark\|test-suite\|source-repository\|flag\|custom-setup\)\+\s*\%(.*$\|$\)/ + \ /^\c\s*\(contained\|executable\|library\|benchmark\|test-suite\|source-repository\|flag\|custom-setup\|common\)\+\s*\%(.*$\|$\)/ syn keyword cabalTruth true false " cabalStatementRegion which limits the scope of cabalStatement keywords, this @@ -76,10 +77,14 @@ syn keyword cabalStatement contained containedin=cabalStatementRegion \ default-language \ default-extensions \ author + \ autogen-modules + \ asm-sources + \ asm-options \ branch \ bug-reports \ build-depends \ build-tools + \ build-tools-depends \ build-type \ buildable \ c-sources @@ -87,32 +92,46 @@ syn keyword cabalStatement contained containedin=cabalStatementRegion \ category \ cc-options \ copyright + \ cmm-sources + \ cmm-options \ cpp-options + \ cxx-sources \ data-dir \ data-files \ default + \ default-extensions \ description \ executable \ exposed-modules \ exposed \ extensions - \ extra-tmp-files + \ extra-bundled-libraries \ extra-doc-files + \ extra-dynamic-library-flavours + \ extra-framework-dirs + \ extra-ghci-libraries \ extra-lib-dirs \ extra-libraries + \ extra-library-flavours \ extra-source-files - \ exta-tmp-files + \ extra-tmp-files \ for example \ frameworks \ ghc-options \ ghc-prof-options \ ghc-shared-options + \ ghcjs-options + \ ghcjs-prof-options + \ ghcjs-shared-options \ homepage + \ hs-source-dir \ hs-source-dirs \ hugs-options + \ import \ include-dirs \ includes \ install-includes + \ js-sources \ ld-options \ license \ license-file @@ -120,10 +139,13 @@ syn keyword cabalStatement contained containedin=cabalStatementRegion \ main-is \ maintainer \ manual + \ mixins \ module \ name \ nhc98-options \ other-extensions + \ other-language + \ other-languages \ other-modules \ package-url \ pkgconfig-depends diff --git a/runtime/syntax/cabalconfig.vim b/runtime/syntax/cabalconfig.vim new file mode 100644 index 0000000000..0165725c06 --- /dev/null +++ b/runtime/syntax/cabalconfig.vim @@ -0,0 +1,30 @@ +" Vim syntax file +" Language: Cabal Config +" Maintainer: profunctor@pm.me +" Last Change: Marcin Szamotulski +" Original Author: Marcin Szamotulski + +if exists("b:current_syntax") + finish +endif + +syn match CabalConfigSection /^\S[[:alpha:]]\+\%(-[[:alpha:]]\+\)*[^:]*$/ +syn region CabalConfigRegion matchgroup=CabalConfigKey start=/^\s*[[:alpha:]]\+\%(-[[:alpha:]]\+\)*:/ matchgroup=NONE end=/$/ contains=CabalConfigSeparator,CabalConfigKeyword,CabalConfigPath keepend +syn match CabalConfigComment /^\s*--.*$/ +syn match CabalConfigValue /.*$/ contained +syn match CabalConfigKey /[[:alpha:]]\+\%(-[[:alpha:]]\+\)*\ze:/ +syn keyword CabalConfigSeparator : contained +syn match CabalConfigVariable /\$[[:alpha:]]\+/ +syn keyword CabalConfigKeyword True False ghc +syn match CabalConfigPath /\%([[:alpha:]]\+:\)\?\%(\/[[:print:]]\+\)\+/ + +hi def link CabalConfigComment Comment +hi def link CabalConfigSection Title +hi def link CabalConfigKey Statement +hi def link CabalConfigSeparator NonText +hi def link CabalConfigValue Normal +hi def link CabalConfigVariable Identifier +hi def link CabalConfigKeyword Keyword +hi def link CabalConfigPath Directory + +let b:current_syntax = "cabal.config" diff --git a/runtime/syntax/cabalproject.vim b/runtime/syntax/cabalproject.vim new file mode 100644 index 0000000000..12143b9ee9 --- /dev/null +++ b/runtime/syntax/cabalproject.vim @@ -0,0 +1,28 @@ +" Vim syntax file +" Language: Cabal Project +" Maintainer: profunctor@pm.me +" Last Change: Marcin Szamotulski +" Original Author: Marcin Szamotulski + +if exists("b:current_syntax") + finish +endif + +syn match CabalProjectComment /^\s*--.*/ contains=@Spell +syn match CabalProjectField /^\w\%(\w\|-\)\+/ contains=@NoSpell + +syn keyword CabalProjectBoolean true false True False +syn keyword CabalProjectCompiler ghc ghcjs jhc lhc uhc haskell-suite +syn match CabalProjectNat /\<\d\+\>/ +syn keyword CabalProjectJobs $ncpus +syn keyword CabalProjectProfilingLevel default none exported-functions toplevel-functions all-functions + +hi def link CabalProjectComment Comment +hi def link CabalProjectField Statement +hi def link CabalProjectBoolean Boolean +hi def link CabalProjectCompiler Identifier +hi def link CabalProjectNat Number +hi def link CabalProjectJobs Number +hi def link CabalProjectProfilingLevel Statement + +let b:current_syntax = "cabal.project" diff --git a/runtime/syntax/haskell.vim b/runtime/syntax/haskell.vim index e5128a12ab..1b70b9344a 100644 --- a/runtime/syntax/haskell.vim +++ b/runtime/syntax/haskell.vim @@ -1,7 +1,7 @@ " Vim syntax file " Language: Haskell " Maintainer: Haskell Cafe mailinglist <haskell-cafe@haskell.org> -" Last Change: 2018 Mar 29 by Marcin Szamotulski +" Last Change: 2020 Oct 4 by Marcin Szamotulski <profunctor@pm.me> " Original Author: John Williams <jrw@pobox.com> " " Thanks to Ryan Crumley for suggestions and John Meacham for @@ -38,8 +38,8 @@ if exists("b:current_syntax") endif " (Qualified) identifiers (no default highlighting) -syn match ConId "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=\<[A-Z][a-zA-Z0-9_']*\>" contains=@NoSpell -syn match VarId "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=\<[a-z][a-zA-Z0-9_']*\>" contains=@NoSpell +syn match ConId "\(\<[A-Z][a-zA-Z0-9_']*\.\)*\<[A-Z][a-zA-Z0-9_']*\>" contains=@NoSpell +syn match VarId "\(\<[A-Z][a-zA-Z0-9_']*\.\)*\<[a-z][a-zA-Z0-9_']*\>" contains=@NoSpell " Infix operators--most punctuation characters and any (qualified) identifier " enclosed in `backquotes`. An operator starting with : is a constructor, @@ -49,8 +49,11 @@ syn match hsConSym "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=:[-!#$%&\*\+./<=>\?@\\^|~:]*" syn match hsVarSym "`\(\<[A-Z][a-zA-Z0-9_']*\.\)\=[a-z][a-zA-Z0-9_']*`" syn match hsConSym "`\(\<[A-Z][a-zA-Z0-9_']*\.\)\=[A-Z][a-zA-Z0-9_']*`" +" (Non-qualified) identifiers which start with # are labels +syn match hsLabel "#[a-z][a-zA-Z0-9_']*\>" + " Reserved symbols--cannot be overloaded. -syn match hsDelimiter "(\|)\|\[\|\]\|,\|;\|_\|{\|}" +syn match hsDelimiter "(\|)\|\[\|\]\|,\|;\|{\|}" " Strings and constants syn match hsSpecialChar contained "\\\([0-9]\+\|o[0-7]\+\|x[0-9a-fA-F]\+\|[\"\\'&\\abfnrtv]\|^[A-Z^_\[\\\]]\)" @@ -62,37 +65,41 @@ syn match hsCharacter "^'\([^\\]\|\\[^']\+\|\\'\)'" contains=hsSpecialChar,hs syn match hsNumber "\v<[0-9]%(_*[0-9])*>|<0[xX]_*[0-9a-fA-F]%(_*[0-9a-fA-F])*>|<0[oO]_*%(_*[0-7])*>|<0[bB]_*[01]%(_*[01])*>" syn match hsFloat "\v<[0-9]%(_*[0-9])*\.[0-9]%(_*[0-9])*%(_*[eE][-+]?[0-9]%(_*[0-9])*)?>|<[0-9]%(_*[0-9])*_*[eE][-+]?[0-9]%(_*[0-9])*>|<0[xX]_*[0-9a-fA-F]%(_*[0-9a-fA-F])*\.[0-9a-fA-F]%(_*[0-9a-fA-F])*%(_*[pP][-+]?[0-9]%(_*[0-9])*)?>|<0[xX]_*[0-9a-fA-F]%(_*[0-9a-fA-F])*_*[pP][-+]?[0-9]%(_*[0-9])*>" -" Keyword definitions. These must be patterns instead of keywords -" because otherwise they would match as keywords at the start of a -" "literate" comment (see lhs.vim). -syn match hsModule "\<module\>" -syn match hsImport "\<import\>.*"he=s+6 contains=hsImportMod,hsLineComment,hsBlockComment,@NoSpell -syn match hsImportMod contained "\<\(as\|qualified\|hiding\)\>" contains=@NoSpell -syn match hsInfix "\<\(infix\|infixl\|infixr\)\>" -syn match hsStructure "\<\(class\|data\|deriving\|instance\|default\|where\)\>" -syn match hsTypedef "\<\(type\|newtype\)\>" -syn match hsStatement "\<\(do\|case\|of\|let\|in\)\>" -syn match hsConditional "\<\(if\|then\|else\)\>" +" Keyword definitions. +syn keyword hsModule module +syn match hsImportGroup "\<import\>.*" contains=hsImport,hsImportModuleName,hsImportMod,hsLineComment,hsBlockComment,hsImportList,@NoSpell nextgroup=hsImport +syn keyword hsImport import contained nextgroup=hsImportModuleName +syn match hsImportModuleName '\<[A-Z][A-Za-z.]*' contained +syn region hsImportList start='(' skip='([^)]\{-})' end=')' keepend contained contains=ConId,VarId,hsDelimiter,hsBlockComment,hsTypedef,@NoSpell + +syn keyword hsImportMod contained as qualified hiding +syn keyword hsInfix infix infixl infixr +syn keyword hsStructure class data deriving instance default where +syn keyword hsTypedef type +syn keyword hsNewtypedef newtype +syn keyword hsTypeFam family +syn keyword hsStatement mdo do case of let in +syn keyword hsConditional if then else " Not real keywords, but close. if exists("hs_highlight_boolean") " Boolean constants from the standard prelude. - syn match hsBoolean "\<\(True\|False\)\>" + syn keyword hsBoolean True False endif if exists("hs_highlight_types") " Primitive types from the standard prelude and libraries. - syn match hsType "\<\(Int\|Integer\|Char\|Bool\|Float\|Double\|IO\|Void\|Addr\|Array\|String\)\>" + syn keyword hsType Int Integer Char Bool Float Double IO Void Addr Array String endif if exists("hs_highlight_more_types") " Types from the standard prelude libraries. - syn match hsType "\<\(Maybe\|Either\|Ratio\|Complex\|Ordering\|IOError\|IOResult\|ExitCode\)\>" - syn match hsMaybe "\<Nothing\>" - syn match hsExitCode "\<\(ExitSuccess\)\>" - syn match hsOrdering "\<\(GT\|LT\|EQ\)\>" + syn keyword hsType Maybe Either Ratio Complex Ordering IOError IOResult ExitCode + syn keyword hsMaybe Nothing + syn keyword hsExitCode ExitSuccess + syn keyword hsOrdering GT LT EQ endif if exists("hs_highlight_debug") " Debugging functions from the standard prelude. - syn match hsDebug "\<\(undefined\|error\|trace\)\>" + syn keyword hsDebug undefined error trace endif @@ -133,12 +140,14 @@ hi def link hsImportMod hsImport hi def link hsInfix PreProc hi def link hsStructure Structure hi def link hsStatement Statement -hi def link hsConditional Conditional -hi def link hsSpecialChar SpecialChar +hi def link hsConditional Conditional +hi def link hsSpecialChar SpecialChar hi def link hsTypedef Typedef +hi def link hsNewtypedef Typedef hi def link hsVarSym hsOperator hi def link hsConSym hsOperator hi def link hsOperator Operator +hi def link hsTypeFam Structure if exists("hs_highlight_delimiters") " Some people find this highlighting distracting. hi def link hsDelimiter Delimiter @@ -160,22 +169,22 @@ hi def link hsMaybe hsEnumConst hi def link hsOrdering hsEnumConst hi def link hsEnumConst Constant hi def link hsDebug Debug - -hi def link cCppString hsString -hi def link cCommentStart hsComment -hi def link cCommentError hsError -hi def link cCommentStartError hsError -hi def link cInclude Include -hi def link cPreProc PreProc -hi def link cDefine Macro -hi def link cIncluded hsString -hi def link cError Error -hi def link cPreCondit PreCondit -hi def link cComment Comment -hi def link cCppSkip cCppOut -hi def link cCppOut2 cCppOut -hi def link cCppOut Comment - +hi def link hsLabel Special + +hi def link cCppString hsString +hi def link cCommentStart hsComment +hi def link cCommentError hsError +hi def link cCommentStartError hsError +hi def link cInclude Include +hi def link cPreProc PreProc +hi def link cDefine Macro +hi def link cIncluded hsString +hi def link cError Error +hi def link cPreCondit PreCondit +hi def link cComment Comment +hi def link cCppSkip cCppOut +hi def link cCppOut2 cCppOut +hi def link cCppOut Comment let b:current_syntax = "haskell" diff --git a/runtime/syntax/netrw.vim b/runtime/syntax/netrw.vim index c4d3cf5fda..83ae17445d 100644 --- a/runtime/syntax/netrw.vim +++ b/runtime/syntax/netrw.vim @@ -1,7 +1,7 @@ " Language : Netrw Listing Syntax " Maintainer : Charles E. Campbell -" Last change: Oct 31, 2016 -" Version : 20 NOT RELEASED +" Last change: Nov 07, 2019 +" Version : 20 " --------------------------------------------------------------------- if exists("b:current_syntax") finish diff --git a/scripts/gen_vimdoc.py b/scripts/gen_vimdoc.py index 0507e4b7b6..b4d896fecc 100755 --- a/scripts/gen_vimdoc.py +++ b/scripts/gen_vimdoc.py @@ -48,6 +48,7 @@ import textwrap import subprocess import collections import msgpack +import logging from xml.dom import minidom @@ -57,10 +58,18 @@ if sys.version_info < MIN_PYTHON_VERSION: print("requires Python {}.{}+".format(*MIN_PYTHON_VERSION)) sys.exit(1) -DEBUG = ('DEBUG' in os.environ) +# DEBUG = ('DEBUG' in os.environ) INCLUDE_C_DECL = ('INCLUDE_C_DECL' in os.environ) INCLUDE_DEPRECATED = ('INCLUDE_DEPRECATED' in os.environ) +log = logging.getLogger(__name__) + +LOG_LEVELS = { + logging.getLevelName(level): level for level in [ + logging.DEBUG, logging.INFO, logging.ERROR + ] +} + fmt_vimhelp = False # HACK text_width = 78 script_path = os.path.abspath(__file__) @@ -157,7 +166,7 @@ CONFIG = { ]), 'file_patterns': '*.lua', 'fn_name_prefix': '', - 'section_name': {}, + 'section_name': {'lsp.lua': 'lsp'}, 'section_fmt': lambda name: ( 'Lua module: vim.lsp' if name.lower() == 'lsp' @@ -726,8 +735,8 @@ def extract_from_xml(filename, target, width): if desc: for child in desc.childNodes: paras.append(para_as_map(child)) - if DEBUG: - print(textwrap.indent( + log.debug( + textwrap.indent( re.sub(r'\n\s*\n+', '\n', desc.toprettyxml(indent=' ', newl='\n')), ' ' * 16)) @@ -885,12 +894,13 @@ def main(config, args): os.remove(mpack_file) output_dir = out_dir.format(target=target) + debug = args.log_level >= logging.DEBUG p = subprocess.Popen( ['doxygen', '-'], stdin=subprocess.PIPE, # silence warnings # runtime/lua/vim/lsp.lua:209: warning: argument 'foo' not found - stderr=(subprocess.STDOUT if DEBUG else subprocess.DEVNULL)) + stderr=(subprocess.STDOUT if debug else subprocess.DEVNULL)) p.communicate( config.format( input=CONFIG[target]['files'], @@ -1039,6 +1049,10 @@ def filter_source(filename): def parse_args(): targets = ', '.join(CONFIG.keys()) ap = argparse.ArgumentParser() + ap.add_argument( + "--log-level", "-l", choices=LOG_LEVELS.keys(), + default=logging.getLevelName(logging.ERROR), help="Set log verbosity" + ) ap.add_argument('source_filter', nargs='*', help="Filter source file(s)") ap.add_argument('-k', '--keep-tmpfiles', action='store_true', @@ -1085,6 +1099,10 @@ Doxyfile = textwrap.dedent(''' if __name__ == "__main__": args = parse_args() + print("Setting log level to %s" % args.log_level) + args.log_level = LOG_LEVELS[args.log_level] + log.setLevel(args.log_level) + if len(args.source_filter) > 0: filter_source(args.source_filter[0]) else: diff --git a/scripts/lua2dox_filter b/scripts/lua2dox_filter index 61577527c4..8760f12176 100755 --- a/scripts/lua2dox_filter +++ b/scripts/lua2dox_filter @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash ########################################################################### # Copyright (C) 2012 by Simon Dales # diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index db77931c16..2c9d655a15 100644 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -284,7 +284,7 @@ foreach(sfile ${NVIM_SOURCES} endif() add_custom_command( OUTPUT "${gf_c_h}" "${gf_h_h}" - COMMAND ${CMAKE_C_COMPILER} ${sfile} ${PREPROC_OUTPUT} ${gen_cflags} ${C_FLAGS_ARRAY} + COMMAND ${CMAKE_C_COMPILER} ${sfile} ${PREPROC_OUTPUT} ${gen_cflags} COMMAND "${LUA_PRG}" "${HEADER_GENERATOR}" "${sfile}" "${gf_c_h}" "${gf_h_h}" "${gf_i}" DEPENDS ${depends}) list(APPEND NVIM_GENERATED_FOR_SOURCES "${gf_c_h}") @@ -513,8 +513,44 @@ if(WIN32) tidy.exe win32yank.exe winpty-agent.exe + winpty.dll xxd.exe + # Dependencies for neovim-qt + bearer/qgenericbearer.dll + iconengines/qsvgicon.dll + imageformats/qgif.dll + imageformats/qicns.dll + imageformats/qico.dll + imageformats/qjpeg.dll + imageformats/qsvg.dll + imageformats/qtga.dll + imageformats/qtiff.dll + imageformats/qwbmp.dll + imageformats/qwebp.dll + platforms/qwindows.dll + styles/qwindowsvistastyle.dll + translations/qt_ar.qm + translations/qt_bg.qm + translations/qt_ca.qm + translations/qt_cs.qm + translations/qt_da.qm + translations/qt_de.qm + translations/qt_en.qm + translations/qt_es.qm + translations/qt_fi.qm + translations/qt_fr.qm + translations/qt_gd.qm + translations/qt_he.qm + translations/qt_hu.qm + translations/qt_it.qm + translations/qt_ja.qm + translations/qt_ko.qm + translations/qt_lv.qm + translations/qt_pl.qm + translations/qt_ru.qm + translations/qt_sk.qm + translations/qt_uk.qm D3Dcompiler_47.dll libEGL.dll libgcc_s_dw2-1.dll @@ -522,14 +558,13 @@ if(WIN32) libstdc++-6.dll libwinpthread-1.dll nvim-qt.exe + opengl32sw.dll Qt5Core.dll Qt5Gui.dll Qt5Network.dll Qt5Svg.dll Qt5Widgets.dll - winpty.dll - platforms/qwindows.dll ) get_filename_component(DEP_FILE_DIR ${DEP_FILE} DIRECTORY) set(EXTERNAL_BLOBS_SCRIPT "${EXTERNAL_BLOBS_SCRIPT}\n" diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 67f4f92bf6..2c2e8a024f 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -111,6 +111,24 @@ Integer nvim_buf_line_count(Buffer buffer, Error *err) /// - byte count of previous contents /// - deleted_codepoints (if `utf_sizes` is true) /// - deleted_codeunits (if `utf_sizes` is true) +/// - on_bytes: lua callback invoked on change. +/// This callback receives more granular information about the +/// change compared to on_lines. +/// Return `true` to detach. +/// Args: +/// - the string "bytes" +/// - buffer handle +/// - b:changedtick +/// - start row of the changed text (zero-indexed) +/// - start column of the changed text +/// - byte offset of the changed text (from the start of +/// the buffer) +/// - old end row of the changed text +/// - old end column of the changed text +/// - old end byte length of the changed text +/// - new end row of the changed text +/// - new end column of the changed text +/// - new end byte length of the changed text /// - on_changedtick: Lua callback invoked on changedtick /// increment without text change. Args: /// - the string "changedtick" @@ -119,6 +137,10 @@ Integer nvim_buf_line_count(Buffer buffer, Error *err) /// - on_detach: Lua callback invoked on detach. Args: /// - the string "detach" /// - buffer handle +/// - on_reload: Lua callback invoked on reload. The entire buffer +/// content should be considered changed. Args: +/// - the string "detach" +/// - buffer handle /// - utf_sizes: include UTF-32 and UTF-16 size of the replaced /// region, as args to `on_lines`. /// - preview: also attach to command preview (i.e. 'inccommand') @@ -141,50 +163,57 @@ Boolean nvim_buf_attach(uint64_t channel_id, bool is_lua = (channel_id == LUA_INTERNAL_CALL); BufUpdateCallbacks cb = BUF_UPDATE_CALLBACKS_INIT; + struct { + const char *name; + LuaRef *dest; + } cbs[] = { + { "on_lines", &cb.on_lines }, + { "on_bytes", &cb.on_bytes }, + { "on_changedtick", &cb.on_changedtick }, + { "on_detach", &cb.on_detach }, + { "on_reload", &cb.on_reload }, + { NULL, NULL }, + }; + for (size_t i = 0; i < opts.size; i++) { String k = opts.items[i].key; Object *v = &opts.items[i].value; - if (is_lua && strequal("on_lines", k.data)) { - if (v->type != kObjectTypeLuaRef) { - api_set_error(err, kErrorTypeValidation, "callback is not a function"); - goto error; - } - cb.on_lines = v->data.luaref; - v->data.luaref = LUA_NOREF; - } else if (is_lua && strequal("on_bytes", k.data)) { - if (v->type != kObjectTypeLuaRef) { - api_set_error(err, kErrorTypeValidation, "callback is not a function"); - goto error; - } - cb.on_bytes = v->data.luaref; - v->data.luaref = LUA_NOREF; - } else if (is_lua && strequal("on_changedtick", k.data)) { - if (v->type != kObjectTypeLuaRef) { - api_set_error(err, kErrorTypeValidation, "callback is not a function"); - goto error; - } - cb.on_changedtick = v->data.luaref; - v->data.luaref = LUA_NOREF; - } else if (is_lua && strequal("on_detach", k.data)) { - if (v->type != kObjectTypeLuaRef) { - api_set_error(err, kErrorTypeValidation, "callback is not a function"); - goto error; - } - cb.on_detach = v->data.luaref; - v->data.luaref = LUA_NOREF; - } else if (is_lua && strequal("utf_sizes", k.data)) { - if (v->type != kObjectTypeBoolean) { - api_set_error(err, kErrorTypeValidation, "utf_sizes must be boolean"); - goto error; + bool key_used = false; + if (is_lua) { + for (size_t j = 0; cbs[j].name; j++) { + if (strequal(cbs[j].name, k.data)) { + if (v->type != kObjectTypeLuaRef) { + api_set_error(err, kErrorTypeValidation, + "%s is not a function", cbs[j].name); + goto error; + } + *(cbs[j].dest) = v->data.luaref; + v->data.luaref = LUA_NOREF; + key_used = true; + break; + } } - cb.utf_sizes = v->data.boolean; - } else if (is_lua && strequal("preview", k.data)) { - if (v->type != kObjectTypeBoolean) { - api_set_error(err, kErrorTypeValidation, "preview must be boolean"); - goto error; + + if (key_used) { + continue; + } else if (strequal("utf_sizes", k.data)) { + if (v->type != kObjectTypeBoolean) { + api_set_error(err, kErrorTypeValidation, "utf_sizes must be boolean"); + goto error; + } + cb.utf_sizes = v->data.boolean; + key_used = true; + } else if (strequal("preview", k.data)) { + if (v->type != kObjectTypeBoolean) { + api_set_error(err, kErrorTypeValidation, "preview must be boolean"); + goto error; + } + cb.preview = v->data.boolean; + key_used = true; } - cb.preview = v->data.boolean; - } else { + } + + if (!key_used) { api_set_error(err, kErrorTypeValidation, "unexpected key: %s", k.data); goto error; } @@ -722,7 +751,8 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, kExtmarkUndo); - changed_lines((linenr_T)start_row, 0, (linenr_T)end_row, (long)extra, true); + changed_lines((linenr_T)start_row, 0, (linenr_T)end_row + 1, + (long)extra, true); // adjust cursor like an extmark ( i e it was inside last_part_len) if (curwin->w_cursor.lnum == end_row && curwin->w_cursor.col > end_col) { @@ -1395,6 +1425,11 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, /// - hl_group : name of the highlight group used to highlight /// this mark. /// - virt_text : virtual text to link to this mark. +/// - virt_text_pos : positioning of virtual text. Possible +/// values: +/// - "eol": right after eol character (default) +/// - "overlay": display over the specified column, without +/// shifting the underlying text. /// - ephemeral : for use with |nvim_set_decoration_provider| /// callbacks. The mark will only be used for the current /// redraw cycle, and not be permantently stored in the @@ -1444,8 +1479,9 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, uint64_t id = 0; int line2 = -1, hl_id = 0; DecorPriority priority = DECOR_PRIORITY_BASE; - colnr_T col2 = 0; + colnr_T col2 = -1; VirtText virt_text = KV_INITIAL_VALUE; + VirtTextPos virt_text_pos = kVTEndOfLine; bool right_gravity = true; bool end_right_gravity = false; bool end_gravity_set = false; @@ -1514,6 +1550,22 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, if (ERROR_SET(err)) { goto error; } + } else if (strequal("virt_text_pos", k.data)) { + if (v->type != kObjectTypeString) { + api_set_error(err, kErrorTypeValidation, + "virt_text_pos is not a String"); + goto error; + } + String str = v->data.string; + if (strequal("eol", str.data)) { + virt_text_pos = kVTEndOfLine; + } else if (strequal("overlay", str.data)) { + virt_text_pos = kVTOverlay; + } else { + api_set_error(err, kErrorTypeValidation, + "virt_text_pos: invalid value"); + goto error; + } } else if (strequal("ephemeral", k.data)) { ephemeral = api_object_to_bool(*v, "ephemeral", false, err); if (ERROR_SET(err)) { @@ -1555,7 +1607,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, // Only error out if they try to set end_right_gravity without // setting end_col or end_line - if (line2 == -1 && col2 == 0 && end_gravity_set) { + if (line2 == -1 && col2 == -1 && end_gravity_set) { api_set_error(err, kErrorTypeValidation, "cannot set end_right_gravity " "without setting end_line or end_col"); @@ -1579,30 +1631,28 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, col2 = 0; } + Decoration *decor = NULL, tmp = { 0 }; + + if (kv_size(virt_text) || priority != DECOR_PRIORITY_BASE) { + // TODO(bfredl): this is a bit sketchy. eventually we should + // have predefined decorations for both marks/ephemerals + decor = ephemeral ? &tmp : xcalloc(1, sizeof(*decor)); + decor->hl_id = hl_id; + decor->virt_text = virt_text; + decor->priority = priority; + decor->virt_text_pos = virt_text_pos; + } else if (hl_id) { + decor = decor_hl(hl_id); + } + // TODO(bfredl): synergize these two branches even more if (ephemeral && decor_state.buf == buf) { - int attr_id = hl_id > 0 ? syn_id2attr(hl_id) : 0; - VirtText *vt_allocated = NULL; - if (kv_size(virt_text)) { - vt_allocated = xmalloc(sizeof *vt_allocated); - *vt_allocated = virt_text; - } - decor_add_ephemeral(attr_id, (int)line, (colnr_T)col, - (int)line2, (colnr_T)col2, priority, vt_allocated); + decor_add_ephemeral((int)line, (int)col, line2, col2, decor, 0); } else { if (ephemeral) { api_set_error(err, kErrorTypeException, "not yet implemented"); goto error; } - Decoration *decor = NULL; - if (kv_size(virt_text)) { - decor = xcalloc(1, sizeof(*decor)); - decor->hl_id = hl_id; - decor->virt_text = virt_text; - } else if (hl_id) { - decor = decor_hl(hl_id); - decor->priority = priority; - } id = extmark_set(buf, (uint64_t)ns_id, id, (int)line, (colnr_T)col, line2, col2, decor, right_gravity, @@ -1673,7 +1723,7 @@ Boolean nvim_buf_del_extmark(Buffer buffer, /// @param[out] err Error details, if any /// @return The ns_id that was used Integer nvim_buf_add_highlight(Buffer buffer, - Integer src_id, + Integer ns_id, String hl_group, Integer line, Integer col_start, @@ -1698,18 +1748,18 @@ Integer nvim_buf_add_highlight(Buffer buffer, col_end = MAXCOL; } - uint64_t ns_id = src2ns(&src_id); + uint64_t ns = src2ns(&ns_id); if (!(line < buf->b_ml.ml_line_count)) { // safety check, we can't add marks outside the range - return src_id; + return ns_id; } int hl_id = 0; if (hl_group.size > 0) { hl_id = syn_check_group((char_u *)hl_group.data, (int)hl_group.size); } else { - return src_id; + return ns_id; } int end_line = (int)line; @@ -1718,11 +1768,11 @@ Integer nvim_buf_add_highlight(Buffer buffer, end_line++; } - extmark_set(buf, ns_id, 0, + extmark_set(buf, ns, 0, (int)line, (colnr_T)col_start, end_line, (colnr_T)col_end, decor_hl(hl_id), true, false, kExtmarkNoUndo); - return src_id; + return ns_id; } /// Clears namespaced objects (highlights, extmarks, virtual text) from @@ -1918,7 +1968,6 @@ static void fix_cursor(linenr_T lo, linenr_T hi, linenr_T extra) curwin->w_cursor.lnum += extra; check_cursor_col(); } else if (extra < 0) { - curwin->w_cursor.lnum = lo; check_cursor(); } else { check_cursor_col(); diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 09895a2119..586123aac1 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -545,6 +545,26 @@ Object nvim_exec_lua(String code, Array args, Error *err) return nlua_exec(code, args, err); } +/// Notify the user with a message +/// +/// Relays the call to vim.notify . By default forwards your message in the +/// echo area but can be overriden to trigger desktop notifications. +/// +/// @param msg Message to display to the user +/// @param log_level The log level +/// @param opts Reserved for future use. +/// @param[out] err Error details, if any +Object nvim_notify(String msg, Integer log_level, Dictionary opts, Error *err) + FUNC_API_SINCE(7) +{ + FIXED_TEMP_ARRAY(args, 3); + args.items[0] = STRING_OBJ(msg); + args.items[1] = INTEGER_OBJ(log_level); + args.items[2] = DICTIONARY_OBJ(opts); + + return nlua_exec(STATIC_CSTR_AS_STRING("return vim.notify(...)"), args, err); +} + /// Calls a VimL function. /// /// @param fn Function name @@ -1526,8 +1546,8 @@ theend: /// - "c" |charwise| mode /// - "l" |linewise| mode /// - "" guess by contents, see |setreg()| -/// @param after Insert after cursor (like |p|), or before (like |P|). -/// @param follow Place cursor at end of inserted text. +/// @param after If true insert after cursor (like |p|), or before (like |P|). +/// @param follow If true place cursor at end of inserted text. /// @param[out] err Error details, if any void nvim_put(ArrayOf(String) lines, String type, Boolean after, Boolean follow, Error *err) diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c index 140a9c6bcb..3de2e0f342 100644 --- a/src/nvim/autocmd.c +++ b/src/nvim/autocmd.c @@ -544,7 +544,7 @@ char_u *au_event_disable(char *what) } else { STRCAT(new_ei, what); } - set_string_option_direct((char_u *)"ei", -1, new_ei, OPT_FREE, SID_NONE); + set_string_option_direct("ei", -1, new_ei, OPT_FREE, SID_NONE); xfree(new_ei); return save_ei; @@ -553,7 +553,7 @@ char_u *au_event_disable(char *what) void au_event_restore(char_u *old_ei) { if (old_ei != NULL) { - set_string_option_direct((char_u *)"ei", -1, old_ei, OPT_FREE, SID_NONE); + set_string_option_direct("ei", -1, old_ei, OPT_FREE, SID_NONE); xfree(old_ei); } } diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index ec39de14f5..c42a0e2dad 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -596,7 +596,7 @@ void close_buffer(win_T *win, buf_T *buf, int action, bool abort_if_last) // Disable buffer-updates for the current buffer. // No need to check `unload_buf`: in that case the function returned above. - buf_updates_unregister_all(buf); + buf_updates_unload(buf, false); /* * Remove the buffer from the list. @@ -821,7 +821,7 @@ static void free_buffer_stuff(buf_T *buf, int free_flags) map_clear_int(buf, MAP_ALL_MODES, true, true); // clear local abbrevs XFREE_CLEAR(buf->b_start_fenc); - buf_updates_unregister_all(buf); + buf_updates_unload(buf, false); } /* @@ -1726,7 +1726,8 @@ buf_T *buflist_new(char_u *ffname_arg, char_u *sfname_arg, linenr_T lnum, file_id_valid)) != NULL) { xfree(ffname); if (lnum != 0) { - buflist_setfpos(buf, curwin, lnum, (colnr_T)0, false); + buflist_setfpos(buf, (flags & BLN_NOCURWIN) ? NULL : curwin, + lnum, (colnr_T)0, false); } if ((flags & BLN_NOOPT) == 0) { // Copy the options now, if 'cpo' doesn't have 's' and not done already. @@ -2308,6 +2309,10 @@ int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, int options) *num_file = 0; // return values in case of FAIL *file = NULL; + if ((options & BUF_DIFF_FILTER) && !curwin->w_p_diff) { + return FAIL; + } + // Make a copy of "pat" and change "^" to "\(^\|[\/]\)". if (*pat == '^') { patc = xmalloc(STRLEN(pat) + 11); @@ -2344,6 +2349,13 @@ int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, int options) if (!buf->b_p_bl) { // skip unlisted buffers continue; } + if (options & BUF_DIFF_FILTER) { + // Skip buffers not suitable for + // :diffget or :diffput completion. + if (buf == curbuf || !diff_mode_buf(buf)) { + continue; + } + } p = buflist_match(®match, buf, p_wic); if (p != NULL) { if (round == 1) { @@ -2486,6 +2498,7 @@ buflist_nr2name( /// /// @param[in,out] buf Buffer for which line and column are set. /// @param[in,out] win Window for which line and column are set. +/// May be NULL when using :badd. /// @param[in] lnum Line number to be set. If it is zero then only /// options are touched. /// @param[in] col Column number to be set. @@ -2493,7 +2506,7 @@ buflist_nr2name( void buflist_setfpos(buf_T *const buf, win_T *const win, linenr_T lnum, colnr_T col, bool copy_options) - FUNC_ATTR_NONNULL_ALL + FUNC_ATTR_NONNULL_ARG(1) { wininfo_T *wip; @@ -2528,7 +2541,7 @@ void buflist_setfpos(buf_T *const buf, win_T *const win, wip->wi_fpos.lnum = lnum; wip->wi_fpos.col = col; } - if (copy_options) { + if (copy_options && win != NULL) { // Save the window-specific option values. copy_winopt(&win->w_onebuf_opt, &wip->wi_opt); wip->wi_fold_manual = win->w_fold_manual; @@ -2566,29 +2579,39 @@ static bool wininfo_other_tab_diff(wininfo_T *wip) return false; } -/* - * Find info for the current window in buffer "buf". - * If not found, return the info for the most recently used window. - * When "skip_diff_buffer" is true avoid windows with 'diff' set that is in - * another tab page. - * Returns NULL when there isn't any info. - */ -static wininfo_T *find_wininfo(buf_T *buf, int skip_diff_buffer) +// Find info for the current window in buffer "buf". +// If not found, return the info for the most recently used window. +// When "need_options" is true skip entries where wi_optset is false. +// When "skip_diff_buffer" is true avoid windows with 'diff' set that is in +// another tab page. +// Returns NULL when there isn't any info. +static wininfo_T *find_wininfo(buf_T *buf, bool need_options, + bool skip_diff_buffer) + FUNC_ATTR_NONNULL_ALL { wininfo_T *wip; - for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next) + for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next) { if (wip->wi_win == curwin && (!skip_diff_buffer || !wininfo_other_tab_diff(wip)) - ) + && (!need_options || wip->wi_optset)) { break; + } + } - /* If no wininfo for curwin, use the first in the list (that doesn't have - * 'diff' set and is in another tab page). */ + // If no wininfo for curwin, use the first in the list (that doesn't have + // 'diff' set and is in another tab page). + // If "need_options" is true skip entries that don't have options set, + // unless the window is editing "buf", so we can copy from the window + // itself. if (wip == NULL) { if (skip_diff_buffer) { for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next) { - if (!wininfo_other_tab_diff(wip)) { + if (!wininfo_other_tab_diff(wip) + && (!need_options + || wip->wi_optset + || (wip->wi_win != NULL + && wip->wi_win->w_buffer == buf))) { break; } } @@ -2607,12 +2630,10 @@ static wininfo_T *find_wininfo(buf_T *buf, int skip_diff_buffer) */ void get_winopts(buf_T *buf) { - wininfo_T *wip; - clear_winopt(&curwin->w_onebuf_opt); clearFolding(curwin); - wip = find_wininfo(buf, true); + wininfo_T *const wip = find_wininfo(buf, true, true); if (wip != NULL && wip->wi_win != curwin && wip->wi_win != NULL && wip->wi_win->w_buffer == buf) { win_T *wp = wip->wi_win; @@ -2649,7 +2670,7 @@ pos_T *buflist_findfpos(buf_T *buf) { static pos_T no_position = { 1, 0, 0 }; - wininfo_T *wip = find_wininfo(buf, false); + wininfo_T *const wip = find_wininfo(buf, false, false); return (wip == NULL) ? &no_position : &(wip->wi_fpos); } @@ -3236,7 +3257,7 @@ void maketitle(void) 0, maxlen, NULL, NULL); title_str = (char_u *)buf; if (called_emsg) { - set_string_option_direct((char_u *)"titlestring", -1, (char_u *)"", + set_string_option_direct("titlestring", -1, (char_u *)"", OPT_FREE, SID_ERROR); } called_emsg |= save_called_emsg; @@ -3346,7 +3367,7 @@ void maketitle(void) p_iconstring, use_sandbox, 0, 0, NULL, NULL); if (called_emsg) { - set_string_option_direct((char_u *)"iconstring", -1, + set_string_option_direct("iconstring", -1, (char_u *)"", OPT_FREE, SID_ERROR); } called_emsg |= save_called_emsg; @@ -3486,7 +3507,7 @@ int build_stl_str_hl( stl_items = xmalloc(sizeof(stl_item_t) * stl_items_len); stl_groupitems = xmalloc(sizeof(int) * stl_items_len); stl_hltab = xmalloc(sizeof(stl_hlrec_t) * stl_items_len); - stl_tabtab = xmalloc(sizeof(stl_hlrec_t) * stl_items_len); + stl_tabtab = xmalloc(sizeof(StlClickRecord) * stl_items_len); stl_separator_locations = xmalloc(sizeof(int) * stl_items_len); } @@ -3940,9 +3961,9 @@ int build_stl_str_hl( // Store the current buffer number as a string variable vim_snprintf((char *)buf_tmp, sizeof(buf_tmp), "%d", curbuf->b_fnum); - set_internal_string_var((char_u *)"g:actual_curbuf", buf_tmp); + set_internal_string_var("g:actual_curbuf", buf_tmp); vim_snprintf((char *)win_tmp, sizeof(win_tmp), "%d", curwin->handle); - set_internal_string_var((char_u *)"g:actual_curwin", win_tmp); + set_internal_string_var("g:actual_curwin", win_tmp); buf_T *const save_curbuf = curbuf; win_T *const save_curwin = curwin; @@ -4482,22 +4503,15 @@ int build_stl_str_hl( int num_separators = 0; for (int i = 0; i < itemcnt; i++) { if (stl_items[i].type == Separate) { + // Create an array of the start location for each + // separator mark. + stl_separator_locations[num_separators] = i; num_separators++; } } // If we have separated groups, then we deal with it now if (num_separators) { - // Create an array of the start location for each - // separator mark. - int index = 0; - for (int i = 0; i < itemcnt; i++) { - if (stl_items[i].type == Separate) { - stl_separator_locations[index] = i; - index++; - } - } - int standard_spaces = (maxwidth - width) / num_separators; int final_spaces = (maxwidth - width) - standard_spaces * (num_separators - 1); diff --git a/src/nvim/buffer.h b/src/nvim/buffer.h index ee3fda5f6d..ac7ead5f92 100644 --- a/src/nvim/buffer.h +++ b/src/nvim/buffer.h @@ -33,6 +33,9 @@ enum bln_values { BLN_DUMMY = 4, // Allocating dummy buffer BLN_NEW = 8, // create a new buffer BLN_NOOPT = 16, // Don't copy options to existing buffer + // BLN_DUMMY_OK = 32, // also find an existing dummy buffer + // BLN_REUSE = 64, // may re-use number from buf_reuse + BLN_NOCURWIN = 128, // buffer is not associated with curwin }; // Values for action argument for do_buffer() diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index cc09b7e989..a05bd6fcc7 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -296,13 +296,11 @@ typedef struct arglist { int id; ///< id of this arglist } alist_T; -/* - * For each argument remember the file name as it was given, and the buffer - * number that contains the expanded file name (required for when ":cd" is - * used. - * - * TODO: move aentry_T to another header - */ +// For each argument remember the file name as it was given, and the buffer +// number that contains the expanded file name (required for when ":cd" is +// used). +// +// TODO(Felipe): move aentry_T to another header typedef struct argentry { char_u *ae_fname; // file name as specified int ae_fnum; // buffer number with expanded file name @@ -490,11 +488,12 @@ typedef struct { LuaRef on_bytes; LuaRef on_changedtick; LuaRef on_detach; + LuaRef on_reload; bool utf_sizes; bool preview; } BufUpdateCallbacks; #define BUF_UPDATE_CALLBACKS_INIT { LUA_NOREF, LUA_NOREF, LUA_NOREF, \ - LUA_NOREF, false, false } + LUA_NOREF, LUA_NOREF, false, false } EXTERN int curbuf_splice_pending INIT(= 0); @@ -1036,10 +1035,10 @@ struct matchitem { int id; ///< match ID int priority; ///< match priority char_u *pattern; ///< pattern to highlight - int hlg_id; ///< highlight group ID regmmatch_T match; ///< regexp program for pattern posmatch_T pos; ///< position matches match_T hl; ///< struct for doing the actual highlighting + int hlg_id; ///< highlight group ID int conceal_char; ///< cchar for Conceal highlighting }; diff --git a/src/nvim/buffer_updates.c b/src/nvim/buffer_updates.c index 68e123896b..97562eace6 100644 --- a/src/nvim/buffer_updates.c +++ b/src/nvim/buffer_updates.c @@ -135,7 +135,7 @@ void buf_updates_unregister(buf_T *buf, uint64_t channelid) } } -void buf_updates_unregister_all(buf_T *buf) +void buf_updates_unload(buf_T *buf, bool can_reload) { size_t size = kv_size(buf->update_channels); if (size) { @@ -146,9 +146,20 @@ void buf_updates_unregister_all(buf_T *buf) kv_init(buf->update_channels); } + size_t j = 0; for (size_t i = 0; i < kv_size(buf->update_callbacks); i++) { BufUpdateCallbacks cb = kv_A(buf->update_callbacks, i); - if (cb.on_detach != LUA_NOREF) { + LuaRef thecb = LUA_NOREF; + + bool keep = false; + if (can_reload && cb.on_reload != LUA_NOREF) { + keep = true; + thecb = cb.on_reload; + } else if (cb.on_detach != LUA_NOREF) { + thecb = cb.on_detach; + } + + if (thecb != LUA_NOREF) { Array args = ARRAY_DICT_INIT; Object items[1]; args.size = 1; @@ -158,15 +169,24 @@ void buf_updates_unregister_all(buf_T *buf) args.items[0] = BUFFER_OBJ(buf->handle); textlock++; - nlua_call_ref(cb.on_detach, "detach", args, false, NULL); + nlua_call_ref(thecb, keep ? "reload" : "detach", args, false, NULL); textlock--; } - free_update_callbacks(cb); + + if (keep) { + kv_A(buf->update_callbacks, j++) = kv_A(buf->update_callbacks, i); + } else { + free_update_callbacks(cb); + } + } + kv_size(buf->update_callbacks) = j; + if (kv_size(buf->update_callbacks) == 0) { + kv_destroy(buf->update_callbacks); + kv_init(buf->update_callbacks); } - kv_destroy(buf->update_callbacks); - kv_init(buf->update_callbacks); } + void buf_updates_send_changes(buf_T *buf, linenr_T firstline, int64_t num_added, diff --git a/src/nvim/channel.c b/src/nvim/channel.c index 5628ede2e6..09a34ca9fe 100644 --- a/src/nvim/channel.c +++ b/src/nvim/channel.c @@ -292,7 +292,6 @@ static void close_cb(Stream *stream, void *data) /// directory if `cwd` is NULL /// @param[in] pty_width Width of the pty, ignored if `pty` is false /// @param[in] pty_height Height of the pty, ignored if `pty` is false -/// @param[in] term_name `$TERM` for the pty /// @param[in] env Nvim's configured environment is used if this is NULL, /// otherwise defines all environment variables /// @param[out] status_out 0 for invalid arguments, > 0 for the channel id, @@ -304,8 +303,7 @@ Channel *channel_job_start(char **argv, CallbackReader on_stdout, bool pty, bool rpc, bool overlapped, bool detach, const char *cwd, uint16_t pty_width, uint16_t pty_height, - char *term_name, dict_T *env, - varnumber_T *status_out) + dict_T *env, varnumber_T *status_out) { assert(cwd == NULL || os_isdir_executable(cwd)); @@ -318,7 +316,9 @@ Channel *channel_job_start(char **argv, CallbackReader on_stdout, if (detach) { EMSG2(_(e_invarg2), "terminal/pty job cannot be detached"); shell_free_argv(argv); - xfree(term_name); + if (env) { + tv_dict_free(env); + } channel_destroy_early(chan); *status_out = 0; return NULL; @@ -330,9 +330,6 @@ Channel *channel_job_start(char **argv, CallbackReader on_stdout, if (pty_height > 0) { chan->stream.pty.height = pty_height; } - if (term_name) { - chan->stream.pty.term_name = term_name; - } } else { chan->stream.uv = libuv_process_init(&main_loop, chan); } @@ -362,9 +359,6 @@ Channel *channel_job_start(char **argv, CallbackReader on_stdout, if (proc->env) { tv_dict_free(proc->env); } - if (proc->type == kProcessTypePty) { - xfree(chan->stream.pty.term_name); - } channel_destroy_early(chan); *status_out = proc->status; return NULL; diff --git a/src/nvim/charset.c b/src/nvim/charset.c index be265e3f27..5ad1fe0dfd 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -708,7 +708,7 @@ int ptr2cells(const char_u *p) /// @return number of character cells. int vim_strsize(char_u *s) { - return vim_strnsize(s, (int)MAXCOL); + return vim_strnsize(s, MAXCOL); } /// Return the number of character cells string "s[len]" will take on the diff --git a/src/nvim/context.c b/src/nvim/context.c index 1ae0510762..4162daa6ca 100644 --- a/src/nvim/context.c +++ b/src/nvim/context.c @@ -126,7 +126,7 @@ bool ctx_restore(Context *ctx, const int flags) } char_u *op_shada; - get_option_value((char_u *)"shada", NULL, &op_shada, OPT_GLOBAL); + get_option_value("shada", NULL, &op_shada, OPT_GLOBAL); set_option_value("shada", 0L, "!,'100,%", OPT_GLOBAL); if (flags & kCtxRegs) { diff --git a/src/nvim/decoration.c b/src/nvim/decoration.c index f3ee42fab1..a1289f202a 100644 --- a/src/nvim/decoration.c +++ b/src/nvim/decoration.c @@ -188,20 +188,21 @@ bool decor_redraw_start(buf_T *buf, int top_row, DecorState *state) goto next_mark; } - int attr_id = decor->hl_id > 0 ? syn_id2attr(decor->hl_id) : 0; - VirtText *vt = kv_size(decor->virt_text) ? &decor->virt_text : NULL; - HlRange range; if (mark.id&MARKTREE_END_FLAG) { - range = (HlRange){ altpos.row, altpos.col, mark.row, mark.col, - attr_id, decor->priority, vt, false }; + decor_add(state, altpos.row, altpos.col, mark.row, mark.col, + decor, false, 0); } else { - range = (HlRange){ mark.row, mark.col, altpos.row, - altpos.col, attr_id, decor->priority, vt, false }; + if (altpos.row == -1) { + altpos.row = mark.row; + altpos.col = mark.col; + } + decor_add(state, mark.row, mark.col, altpos.row, altpos.col, + decor, false, 0); } - hlrange_activate(range, state); next_mark: if (marktree_itr_node_done(state->itr)) { + marktree_itr_next(buf->b_marktree, state->itr); break; } marktree_itr_next(buf->b_marktree, state->itr); @@ -220,41 +221,39 @@ bool decor_redraw_line(buf_T *buf, int row, DecorState *state) return true; // TODO(bfredl): be more precise } -static void hlrange_activate(HlRange range, DecorState *state) +static void decor_add(DecorState *state, int start_row, int start_col, + int end_row, int end_col, Decoration *decor, bool owned, + DecorPriority priority) { - // Get size before preparing the push, to have the number of elements - size_t s = kv_size(state->active); - - kv_pushp(state->active); + int attr_id = decor->hl_id > 0 ? syn_id2attr(decor->hl_id) : 0; - size_t dest_index = 0; + HlRange range = { start_row, start_col, end_row, end_col, + attr_id, MAX(priority, decor->priority), + kv_size(decor->virt_text) ? &decor->virt_text : NULL, + decor->virt_text_pos, + kv_size(decor->virt_text) && owned, -1 }; - // Determine insertion dest_index - while (dest_index < s) { - HlRange item = kv_A(state->active, dest_index); - if (item.priority > range.priority) { + kv_pushp(state->active); + size_t index; + for (index = kv_size(state->active)-1; index > 0; index--) { + HlRange item = kv_A(state->active, index-1); + if (item.priority <= range.priority) { break; } - - dest_index++; - } - - // Splice - for (size_t index = s; index > dest_index; index--) { kv_A(state->active, index) = kv_A(state->active, index-1); } - - // Insert - kv_A(state->active, dest_index) = range; + kv_A(state->active, index) = range; } -int decor_redraw_col(buf_T *buf, int col, DecorState *state) +int decor_redraw_col(buf_T *buf, int col, int virt_col, DecorState *state) { if (col <= state->col_until) { return state->current; } state->col_until = MAXCOL; while (true) { + // TODO(bfredl): check duplicate entry in "intersection" + // branch mtmark_t mark = marktree_itr_current(state->itr); if (mark.row < 0 || mark.row > state->row) { break; @@ -278,6 +277,11 @@ int decor_redraw_col(buf_T *buf, int col, DecorState *state) } Decoration *decor = item->decor; + if (endpos.row == -1) { + endpos.row = mark.row; + endpos.col = mark.col; + } + if (endpos.row < mark.row || (endpos.row == mark.row && endpos.col <= mark.col)) { if (!kv_size(decor->virt_text)) { @@ -285,12 +289,8 @@ int decor_redraw_col(buf_T *buf, int col, DecorState *state) } } - int attr_id = decor->hl_id > 0 ? syn_id2attr(decor->hl_id) : 0; - VirtText *vt = kv_size(decor->virt_text) ? &decor->virt_text : NULL; - hlrange_activate((HlRange){ mark.row, mark.col, - endpos.row, endpos.col, - attr_id, decor->priority, - vt, false }, state); + decor_add(state, mark.row, mark.col, endpos.row, endpos.col, + decor, false, 0); next_mark: marktree_itr_next(buf->b_marktree, state->itr); @@ -310,7 +310,7 @@ next_mark: if (item.start_row < state->row || (item.start_row == state->row && item.start_col <= col)) { active = true; - if (item.end_row == state->row) { + if (item.end_row == state->row && item.end_col > col) { state->col_until = MIN(state->col_until, item.end_col-1); } } else { @@ -322,8 +322,12 @@ next_mark: if (active && item.attr_id > 0) { attr = hl_combine_attr(attr, item.attr_id); } + if ((item.start_row == state->row && item.start_col <= col) + && item.virt_text && item.virt_col == -1) { + item.virt_col = virt_col; + } if (keep) { - kv_A(state->active, j++) = kv_A(state->active, i); + kv_A(state->active, j++) = item; } else if (item.virt_text_owned) { clear_virttext(item.virt_text); xfree(item.virt_text); @@ -341,21 +345,20 @@ void decor_redraw_end(DecorState *state) VirtText *decor_redraw_virt_text(buf_T *buf, DecorState *state) { - decor_redraw_col(buf, MAXCOL, state); + decor_redraw_col(buf, MAXCOL, MAXCOL, state); for (size_t i = 0; i < kv_size(state->active); i++) { HlRange item = kv_A(state->active, i); - if (item.start_row == state->row && item.virt_text) { + if (item.start_row == state->row && item.virt_text + && item.virt_text_pos == kVTEndOfLine) { return item.virt_text; } } return NULL; } -void decor_add_ephemeral(int attr_id, int start_row, int start_col, - int end_row, int end_col, DecorPriority priority, - VirtText *virt_text) +void decor_add_ephemeral(int start_row, int start_col, int end_row, int end_col, + Decoration *decor, DecorPriority priority) { -hlrange_activate(((HlRange){ start_row, start_col, end_row, end_col, attr_id, - priority, virt_text, virt_text != NULL }), - &decor_state); + decor_add(&decor_state, start_row, start_col, end_row, end_col, decor, true, + priority); } diff --git a/src/nvim/decoration.h b/src/nvim/decoration.h index 2533a641dd..47bd9abbc3 100644 --- a/src/nvim/decoration.h +++ b/src/nvim/decoration.h @@ -18,10 +18,16 @@ typedef kvec_t(VirtTextChunk) VirtText; typedef uint16_t DecorPriority; #define DECOR_PRIORITY_BASE 0x1000 +typedef enum { + kVTEndOfLine, + kVTOverlay, +} VirtTextPos; + struct Decoration { int hl_id; // highlight group VirtText virt_text; + VirtTextPos virt_text_pos; // TODO(bfredl): style, signs, etc DecorPriority priority; bool shared; // shared decoration, don't free @@ -35,7 +41,9 @@ typedef struct { int attr_id; DecorPriority priority; VirtText *virt_text; + VirtTextPos virt_text_pos; bool virt_text_owned; + int virt_col; } HlRange; typedef struct { diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 93bc34fa4b..31b7b1bd8f 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -58,6 +58,7 @@ static bool diff_need_update = false; // ex_diffupdate needs to be called #define DIFF_HIDDEN_OFF 0x100 // diffoff when hidden #define DIFF_INTERNAL 0x200 // use internal xdiff algorithm #define DIFF_CLOSE_OFF 0x400 // diffoff when closing window +#define DIFF_FOLLOWWRAP 0x800 // follow the wrap option #define ALL_WHITE_DIFF (DIFF_IWHITE | DIFF_IWHITEALL | DIFF_IWHITEEOL) static int diff_flags = DIFF_INTERNAL | DIFF_FILLER | DIFF_CLOSE_OFF; @@ -1361,11 +1362,12 @@ void diff_win_options(win_T *wp, int addbuf) wp->w_p_crb_save = wp->w_p_crb; } wp->w_p_crb = true; - - if (!wp->w_p_diff) { - wp->w_p_wrap_save = wp->w_p_wrap; + if (!(diff_flags & DIFF_FOLLOWWRAP)) { + if (!wp->w_p_diff) { + wp->w_p_wrap_save = wp->w_p_wrap; + } + wp->w_p_wrap = false; } - wp->w_p_wrap = false; curwin = wp; // -V519 curbuf = curwin->w_buffer; @@ -1375,7 +1377,7 @@ void diff_win_options(win_T *wp, int addbuf) } wp->w_p_fdm_save = vim_strsave(wp->w_p_fdm); } - set_string_option_direct((char_u *)"fdm", -1, (char_u *)"diff", + set_string_option_direct("fdm", -1, (char_u *)"diff", OPT_LOCAL | OPT_FREE, 0); curwin = old_curwin; curbuf = curwin->w_buffer; @@ -1437,11 +1439,11 @@ void ex_diffoff(exarg_T *eap) if (wp->w_p_crb) { wp->w_p_crb = wp->w_p_crb_save; } - - if (!wp->w_p_wrap) { - wp->w_p_wrap = wp->w_p_wrap_save; + if (!(diff_flags & DIFF_FOLLOWWRAP)) { + if (!wp->w_p_wrap) { + wp->w_p_wrap = wp->w_p_wrap_save; + } } - free_string_option(wp->w_p_fdm); wp->w_p_fdm = vim_strsave(*wp->w_p_fdm_save ? wp->w_p_fdm_save @@ -2158,6 +2160,9 @@ int diffopt_changed(void) } else if (STRNCMP(p, "closeoff", 8) == 0) { p += 8; diff_flags_new |= DIFF_CLOSE_OFF; + } else if (STRNCMP(p, "followwrap", 10) == 0) { + p += 10; + diff_flags_new |= DIFF_FOLLOWWRAP; } else if (STRNCMP(p, "indent-heuristic", 16) == 0) { p += 16; diff_indent_heuristic = XDF_INDENT_HEURISTIC; diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 100e88e261..68c7438ea3 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -1024,7 +1024,7 @@ static int insert_handle_key(InsertState *s) break; case K_EVENT: // some event - multiqueue_process_events(main_loop.events); + state_handle_k_event(); goto check_pum; case K_COMMAND: // some command @@ -1627,11 +1627,11 @@ static void init_prompt(int cmdchar_todo) ml_append(curbuf->b_ml.ml_line_count, prompt, 0, false); } curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; - coladvance((colnr_T)MAXCOL); + coladvance(MAXCOL); changed_bytes(curbuf->b_ml.ml_line_count, 0); } if (cmdchar_todo == 'A') { - coladvance((colnr_T)MAXCOL); + coladvance(MAXCOL); } if (cmdchar_todo == 'I' || curwin->w_cursor.col <= (int)STRLEN(prompt)) { curwin->w_cursor.col = STRLEN(prompt); @@ -6246,9 +6246,10 @@ void auto_format( if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) { // "cannot happen" curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; - coladvance((colnr_T)MAXCOL); - } else + coladvance(MAXCOL); + } else { check_cursor_col(); + } // Insert mode: If the cursor is now after the end of the line while it // previously wasn't, the line was broken. Because of the rule above we @@ -8432,8 +8433,8 @@ static void ins_left(void) // if 'whichwrap' set for cursor in insert mode may go to previous line. // always break undo when moving upwards/downwards, else undo may break start_arrow(&tpos); - --(curwin->w_cursor.lnum); - coladvance((colnr_T)MAXCOL); + curwin->w_cursor.lnum--; + coladvance(MAXCOL); curwin->w_set_curswant = true; // so we stay at the end } else { vim_beep(BO_CRSR); @@ -8467,7 +8468,7 @@ static void ins_end(int c) tpos = curwin->w_cursor; if (c == K_C_END) curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; - coladvance((colnr_T)MAXCOL); + coladvance(MAXCOL); curwin->w_curswant = MAXCOL; start_arrow(&tpos); diff --git a/src/nvim/eval.c b/src/nvim/eval.c index a25b140b2f..6d97310c1c 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -176,7 +176,6 @@ static struct vimvar { VV(VV_DYING, "dying", VAR_NUMBER, VV_RO), VV(VV_EXCEPTION, "exception", VAR_STRING, VV_RO), VV(VV_THROWPOINT, "throwpoint", VAR_STRING, VV_RO), - VV(VV_STDERR, "stderr", VAR_NUMBER, VV_RO), VV(VV_REG, "register", VAR_STRING, VV_RO), VV(VV_CMDBANG, "cmdbang", VAR_NUMBER, VV_RO), VV(VV_INSERTMODE, "insertmode", VAR_STRING, VV_RO), @@ -211,13 +210,9 @@ static struct vimvar { VV(VV_OPTION_OLD, "option_old", VAR_STRING, VV_RO), VV(VV_OPTION_TYPE, "option_type", VAR_STRING, VV_RO), VV(VV_ERRORS, "errors", VAR_LIST, 0), - VV(VV_MSGPACK_TYPES, "msgpack_types", VAR_DICT, VV_RO), - VV(VV_EVENT, "event", VAR_DICT, VV_RO), VV(VV_FALSE, "false", VAR_BOOL, VV_RO), VV(VV_TRUE, "true", VAR_BOOL, VV_RO), VV(VV_NULL, "null", VAR_SPECIAL, VV_RO), - VV(VV__NULL_LIST, "_null_list", VAR_LIST, VV_RO), - VV(VV__NULL_DICT, "_null_dict", VAR_DICT, VV_RO), VV(VV_VIM_DID_ENTER, "vim_did_enter", VAR_NUMBER, VV_RO), VV(VV_TESTING, "testing", VAR_NUMBER, 0), VV(VV_TYPE_NUMBER, "t_number", VAR_NUMBER, VV_RO), @@ -227,10 +222,16 @@ static struct vimvar { VV(VV_TYPE_DICT, "t_dict", VAR_NUMBER, VV_RO), VV(VV_TYPE_FLOAT, "t_float", VAR_NUMBER, VV_RO), VV(VV_TYPE_BOOL, "t_bool", VAR_NUMBER, VV_RO), + VV(VV_EVENT, "event", VAR_DICT, VV_RO), VV(VV_ECHOSPACE, "echospace", VAR_NUMBER, VV_RO), + VV(VV_ARGV, "argv", VAR_LIST, VV_RO), VV(VV_EXITING, "exiting", VAR_NUMBER, VV_RO), + // Neovim + VV(VV_STDERR, "stderr", VAR_NUMBER, VV_RO), + VV(VV_MSGPACK_TYPES, "msgpack_types", VAR_DICT, VV_RO), + VV(VV__NULL_LIST, "_null_list", VAR_LIST, VV_RO), + VV(VV__NULL_DICT, "_null_dict", VAR_DICT, VV_RO), VV(VV_LUA, "lua", VAR_PARTIAL, VV_RO), - VV(VV_ARGV, "argv", VAR_LIST, VV_RO), }; #undef VV @@ -455,14 +456,15 @@ void eval_clear(void) * Set an internal variable to a string value. Creates the variable if it does * not already exist. */ -void set_internal_string_var(char_u *name, char_u *value) +void set_internal_string_var(const char *name, char_u *value) + FUNC_ATTR_NONNULL_ARG(1) { - const typval_T tv = { + typval_T tv = { .v_type = VAR_STRING, .vval.v_string = value, }; - set_var((const char *)name, STRLEN(name), (typval_T *)&tv, true); + set_var(name, strlen(name), &tv, true); } static lval_T *redir_lval = NULL; @@ -522,9 +524,9 @@ var_redir_start( tv.v_type = VAR_STRING; tv.vval.v_string = (char_u *)""; if (append) { - set_var_lval(redir_lval, redir_endp, &tv, true, false, (char_u *)"."); + set_var_lval(redir_lval, redir_endp, &tv, true, false, "."); } else { - set_var_lval(redir_lval, redir_endp, &tv, true, false, (char_u *)"="); + set_var_lval(redir_lval, redir_endp, &tv, true, false, "="); } clear_lval(redir_lval); err = did_emsg; @@ -584,7 +586,7 @@ void var_redir_stop(void) redir_endp = (char_u *)get_lval(redir_varname, NULL, redir_lval, false, false, 0, FNE_CHECK_START); if (redir_endp != NULL && redir_lval->ll_name != NULL) { - set_var_lval(redir_lval, redir_endp, &tv, false, false, (char_u *)"."); + set_var_lval(redir_lval, redir_endp, &tv, false, false, "."); } clear_lval(redir_lval); } @@ -1847,7 +1849,7 @@ static char_u *ex_let_one(char_u *arg, typval_T *const tv, s = tv_get_string_chk(tv); // != NULL if number or string. } if (s != NULL && op != NULL && *op != '=') { - opt_type = get_option_value(arg, &numval, (char_u **)&stringval, + opt_type = get_option_value((char *)arg, &numval, (char_u **)&stringval, opt_flags); if ((opt_type == 1 && *op == '.') || (opt_type == 0 && *op != '.')) { @@ -1924,7 +1926,7 @@ static char_u *ex_let_one(char_u *arg, typval_T *const tv, if (endchars != NULL && vim_strchr(endchars, *skipwhite(p)) == NULL) { EMSG(_(e_letunexp)); } else { - set_var_lval(&lv, p, tv, copy, is_const, op); + set_var_lval(&lv, p, tv, copy, is_const, (const char *)op); arg_end = p; } } @@ -2121,9 +2123,10 @@ char_u *get_lval(char_u *const name, typval_T *const rettv, return NULL; } } - lp->ll_range = TRUE; - } else - lp->ll_range = FALSE; + lp->ll_range = true; + } else { + lp->ll_range = false; + } if (*p != ']') { if (!quiet) { @@ -2240,12 +2243,10 @@ char_u *get_lval(char_u *const name, typval_T *const rettv, return NULL; } - /* - * May need to find the item or absolute index for the second - * index of a range. - * When no index given: "lp->ll_empty2" is TRUE. - * Otherwise "lp->ll_n2" is set to the second index. - */ + // May need to find the item or absolute index for the second + // index of a range. + // When no index given: "lp->ll_empty2" is true. + // Otherwise "lp->ll_n2" is set to the second index. if (lp->ll_range && !lp->ll_empty2) { lp->ll_n2 = (long)tv_get_number(&var2); // Is number or string. tv_clear(&var2); @@ -2299,7 +2300,7 @@ void clear_lval(lval_T *lp) * "%" for "%=", "." for ".=" or "=" for "=". */ static void set_var_lval(lval_T *lp, char_u *endp, typval_T *rettv, - int copy, const bool is_const, const char_u *op) + int copy, const bool is_const, const char *op) { int cc; listitem_T *ri; @@ -2326,7 +2327,7 @@ static void set_var_lval(lval_T *lp, char_u *endp, typval_T *rettv, TV_CSTRING) && !tv_check_lock(di->di_tv.v_lock, (const char *)lp->ll_name, TV_CSTRING))) - && eexe_mod_op(&tv, rettv, (const char *)op) == OK) { + && eexe_mod_op(&tv, rettv, op) == OK) { set_var(lp->ll_name, lp->ll_name_len, &tv, false); } tv_clear(&tv); @@ -2369,8 +2370,7 @@ static void set_var_lval(lval_T *lp, char_u *endp, typval_T *rettv, */ for (ri = tv_list_first(rettv->vval.v_list); ri != NULL; ) { if (op != NULL && *op != '=') { - eexe_mod_op(TV_LIST_ITEM_TV(lp->ll_li), TV_LIST_ITEM_TV(ri), - (const char *)op); + eexe_mod_op(TV_LIST_ITEM_TV(lp->ll_li), TV_LIST_ITEM_TV(ri), op); } else { tv_clear(TV_LIST_ITEM_TV(lp->ll_li)); tv_copy(TV_LIST_ITEM_TV(ri), TV_LIST_ITEM_TV(lp->ll_li)); @@ -2428,7 +2428,7 @@ static void set_var_lval(lval_T *lp, char_u *endp, typval_T *rettv, } if (op != NULL && *op != '=') { - eexe_mod_op(lp->ll_tv, rettv, (const char *)op); + eexe_mod_op(lp->ll_tv, rettv, op); goto notify; } else { tv_clear(lp->ll_tv); @@ -4538,7 +4538,7 @@ int get_option_tv(const char **const arg, typval_T *const rettv, c = *option_end; *option_end = NUL; - opt_type = get_option_value((char_u *)(*arg), &numval, + opt_type = get_option_value(*arg, &numval, rettv == NULL ? NULL : &stringval, opt_flags); if (opt_type == -3) { // invalid name diff --git a/src/nvim/eval.h b/src/nvim/eval.h index 06b7f9e21d..4f03d5d259 100644 --- a/src/nvim/eval.h +++ b/src/nvim/eval.h @@ -56,10 +56,10 @@ typedef struct lval_S { ///< isn't NULL it's the Dict to which to add the item. listitem_T *ll_li; ///< The list item or NULL. list_T *ll_list; ///< The list or NULL. - int ll_range; ///< TRUE when a [i:j] range was used. + bool ll_range; ///< true when a [i:j] range was used. + bool ll_empty2; ///< Second index is empty: [i:]. long ll_n1; ///< First index for list. long ll_n2; ///< Second index for list range. - int ll_empty2; ///< Second index is empty: [i:]. dict_T *ll_dict; ///< The Dictionary or NULL. dictitem_T *ll_di; ///< The dictitem or NULL. char_u *ll_newkey; ///< New key for Dict in allocated memory or NULL. @@ -105,7 +105,6 @@ typedef enum { VV_DYING, VV_EXCEPTION, VV_THROWPOINT, - VV_STDERR, VV_REG, VV_CMDBANG, VV_INSERTMODE, @@ -140,13 +139,9 @@ typedef enum { VV_OPTION_OLD, VV_OPTION_TYPE, VV_ERRORS, - VV_MSGPACK_TYPES, - VV_EVENT, VV_FALSE, VV_TRUE, VV_NULL, - VV__NULL_LIST, // List with NULL value. For test purposes only. - VV__NULL_DICT, // Dictionary with NULL value. For test purposes only. VV_VIM_DID_ENTER, VV_TESTING, VV_TYPE_NUMBER, @@ -156,10 +151,16 @@ typedef enum { VV_TYPE_DICT, VV_TYPE_FLOAT, VV_TYPE_BOOL, + VV_EVENT, VV_ECHOSPACE, + VV_ARGV, VV_EXITING, + // Neovim + VV_STDERR, + VV_MSGPACK_TYPES, + VV__NULL_LIST, // List with NULL value. For test purposes only. + VV__NULL_DICT, // Dictionary with NULL value. For test purposes only. VV_LUA, - VV_ARGV, } VimVarIndex; /// All recognized msgpack types diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index 952fa35b83..eac0feafcf 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -63,6 +63,7 @@ return { chanclose={args={1, 2}}, chansend={args=2}, char2nr={args={1, 2}}, + charidx={args={2, 3}}, cindent={args=1}, clearmatches={args={0, 1}}, col={args=1}, diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 1a7bbf2d0e..60229e1ebc 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -940,6 +940,52 @@ static void f_char2nr(typval_T *argvars, typval_T *rettv, FunPtr fptr) (const char_u *)tv_get_string(&argvars[0])); } +// "charidx()" function +static void f_charidx(typval_T *argvars, typval_T *rettv, FunPtr fptr) +{ + rettv->vval.v_number = -1; + + if (argvars[0].v_type != VAR_STRING + || argvars[1].v_type != VAR_NUMBER + || (argvars[2].v_type != VAR_UNKNOWN + && argvars[2].v_type != VAR_NUMBER)) { + EMSG(_(e_invarg)); + return; + } + + const char *str = tv_get_string_chk(&argvars[0]); + varnumber_T idx = tv_get_number_chk(&argvars[1], NULL); + if (str == NULL || idx < 0) { + return; + } + int countcc = 0; + if (argvars[2].v_type != VAR_UNKNOWN) { + countcc = (int)tv_get_number(&argvars[2]); + } + if (countcc < 0 || countcc > 1) { + EMSG(_(e_invarg)); + return; + } + + int (*ptr2len)(const char_u *); + if (countcc) { + ptr2len = utf_ptr2len; + } else { + ptr2len = utfc_ptr2len; + } + + const char *p; + int len; + for (p = str, len = 0; p <= str + idx; len++) { + if (*p == NUL) { + return; + } + p += ptr2len((const char_u *)p); + } + + rettv->vval.v_number = len > 0 ? len - 1 : 0; +} + /* * "cindent(lnum)" function */ @@ -1629,27 +1675,26 @@ static void f_deletebufline(typval_T *argvars, typval_T *rettv, FunPtr fptr) if (u_save(first - 1, last + 1) == FAIL) { rettv->vval.v_number = 1; // FAIL - return; - } - - for (linenr_T lnum = first; lnum <= last; lnum++) { - ml_delete(first, true); - } + } else { + for (linenr_T lnum = first; lnum <= last; lnum++) { + ml_delete(first, true); + } - FOR_ALL_TAB_WINDOWS(tp, wp) { - if (wp->w_buffer == buf) { - if (wp->w_cursor.lnum > last) { - wp->w_cursor.lnum -= count; - } else if (wp->w_cursor.lnum> first) { - wp->w_cursor.lnum = first; - } - if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) { - wp->w_cursor.lnum = wp->w_buffer->b_ml.ml_line_count; + FOR_ALL_TAB_WINDOWS(tp, wp) { + if (wp->w_buffer == buf) { + if (wp->w_cursor.lnum > last) { + wp->w_cursor.lnum -= count; + } else if (wp->w_cursor.lnum> first) { + wp->w_cursor.lnum = first; + } + if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) { + wp->w_cursor.lnum = wp->w_buffer->b_ml.ml_line_count; + } } } + check_cursor_col(); + deleted_lines_mark(first, count); } - check_cursor_col(); - deleted_lines_mark(first, count); if (!is_curbuf) { curbuf = curbuf_save; @@ -2149,7 +2194,7 @@ static void f_menu_get(typval_T *argvars, typval_T *rettv, FunPtr fptr) tv_list_alloc_ret(rettv, kListLenMayKnow); int modes = MENU_ALL_MODES; if (argvars[1].v_type == VAR_STRING) { - const char_u *const strmodes = (char_u *)tv_get_string(&argvars[1]); + const char *const strmodes = tv_get_string(&argvars[1]); modes = get_menu_cmd_modes(strmodes, false, NULL, NULL); } menu_get((char_u *)tv_get_string(&argvars[0]), modes, rettv->vval.v_list); @@ -2984,10 +3029,11 @@ static void f_getchar(typval_T *argvars, typval_T *rettv, FunPtr fptr) if (argvars[0].v_type == VAR_UNKNOWN) { // getchar(): blocking wait. + // TODO(bfredl): deduplicate shared logic with state_enter ? if (!(char_avail() || using_script() || input_available())) { (void)os_inchar(NULL, 0, -1, 0, main_loop.events); if (!multiqueue_empty(main_loop.events)) { - multiqueue_process_events(main_loop.events); + state_handle_k_event(); continue; } } @@ -3135,6 +3181,12 @@ static void f_getcompletion(typval_T *argvars, typval_T *rettv, FunPtr fptr) int options = WILD_SILENT | WILD_USE_NL | WILD_ADD_SLASH | WILD_NO_BEEP; + if (argvars[1].v_type != VAR_STRING) { + EMSG2(_(e_invarg2), "type must be a string"); + return; + } + const char *const type = tv_get_string(&argvars[1]); + if (argvars[2].v_type != VAR_UNKNOWN) { filtered = (bool)tv_get_number_chk(&argvars[2], NULL); } @@ -3148,12 +3200,12 @@ static void f_getcompletion(typval_T *argvars, typval_T *rettv, FunPtr fptr) options |= WILD_KEEP_ALL; } - if (argvars[0].v_type != VAR_STRING || argvars[1].v_type != VAR_STRING) { + if (argvars[0].v_type != VAR_STRING) { EMSG(_(e_invarg)); return; } - if (strcmp(tv_get_string(&argvars[1]), "cmdline") == 0) { + if (strcmp(type, "cmdline") == 0) { set_one_cmd_context(&xpc, tv_get_string(&argvars[0])); xpc.xp_pattern_len = STRLEN(xpc.xp_pattern); goto theend; @@ -3162,15 +3214,14 @@ static void f_getcompletion(typval_T *argvars, typval_T *rettv, FunPtr fptr) ExpandInit(&xpc); xpc.xp_pattern = (char_u *)tv_get_string(&argvars[0]); xpc.xp_pattern_len = STRLEN(xpc.xp_pattern); - xpc.xp_context = cmdcomplete_str_to_type( - (char_u *)tv_get_string(&argvars[1])); + xpc.xp_context = cmdcomplete_str_to_type(type); if (xpc.xp_context == EXPAND_NOTHING) { - EMSG2(_(e_invarg2), argvars[1].vval.v_string); + EMSG2(_(e_invarg2), type); return; } if (xpc.xp_context == EXPAND_MENUS) { - set_context_in_menu_cmd(&xpc, (char_u *)"menu", xpc.xp_pattern, false); + set_context_in_menu_cmd(&xpc, "menu", xpc.xp_pattern, false); xpc.xp_pattern_len = STRLEN(xpc.xp_pattern); } @@ -4081,7 +4132,9 @@ static void f_has(typval_T *argvars, typval_T *rettv, FunPtr fptr) #ifdef _WIN64 "win64", #endif +#ifndef CASE_INSENSITIVE_FILENAME "fname_case", +#endif #ifdef HAVE_ACL "acl", #endif @@ -4912,7 +4965,8 @@ static const char *required_env_vars[] = { static dict_T *create_environment(const dictitem_T *job_env, const bool clear_env, - const bool pty) + const bool pty, + const char * const pty_term_name) { dict_T * env = tv_dict_alloc(); @@ -4946,6 +5000,18 @@ static dict_T *create_environment(const dictitem_T *job_env, } } + // For a pty, we need a sane $TERM set. We can't rely on nvim's environment, + // because the child process is going to be communicating with nvim, not the + // parent terminal. Set a sane default, but let the user override it in the + // job's environment if they want. + if (pty) { + dictitem_T *dv = tv_dict_find(env, S_LEN("TERM")); + if (dv) { + tv_dict_item_remove(env, dv); + } + tv_dict_add_str(env, S_LEN("TERM"), pty_term_name); + } + if (job_env) { tv_dict_extend(env, job_env->di_tv.vval.v_dict, "force"); } @@ -5055,20 +5121,25 @@ static void f_jobstart(typval_T *argvars, typval_T *rettv, FunPtr fptr) } } - env = create_environment(job_env, clear_env, pty); - uint16_t width = 0, height = 0; char *term_name = NULL; if (pty) { width = (uint16_t)tv_dict_get_number(job_opts, "width"); height = (uint16_t)tv_dict_get_number(job_opts, "height"); - term_name = tv_dict_get_string(job_opts, "TERM", true); + // Legacy method, before env option existed, to specify $TERM. No longer + // documented, but still usable to avoid breaking scripts. + term_name = tv_dict_get_string(job_opts, "TERM", false); + if (!term_name) { + term_name = "ansi"; + } } + env = create_environment(job_env, clear_env, pty, term_name); + Channel *chan = channel_job_start(argv, on_stdout, on_stderr, on_exit, pty, rpc, overlapped, detach, cwd, width, height, - term_name, env, &rettv->vval.v_number); + env, &rettv->vval.v_number); if (chan) { channel_create_event(chan, NULL); } @@ -7511,7 +7582,7 @@ static void f_rpcstart(typval_T *argvars, typval_T *rettv, FunPtr fptr) Channel *chan = channel_job_start(argv, CALLBACK_READER_INIT, CALLBACK_READER_INIT, CALLBACK_NONE, false, true, false, false, NULL, 0, 0, - NULL, NULL, &rettv->vval.v_number); + NULL, &rettv->vval.v_number); if (chan) { channel_create_event(chan, NULL); } @@ -10618,7 +10689,7 @@ static void f_termopen(typval_T *argvars, typval_T *rettv, FunPtr fptr) } } - env = create_environment(job_env, clear_env, pty); + env = create_environment(job_env, clear_env, pty, "xterm-256color"); const bool rpc = false; const bool overlapped = false; @@ -10627,8 +10698,7 @@ static void f_termopen(typval_T *argvars, typval_T *rettv, FunPtr fptr) Channel *chan = channel_job_start(argv, on_stdout, on_stderr, on_exit, pty, rpc, overlapped, detach, cwd, term_width, curwin->w_height_inner, - xstrdup("xterm-256color"), env, - &rettv->vval.v_number); + env, &rettv->vval.v_number); if (rettv->vval.v_number <= 0) { return; } diff --git a/src/nvim/eval/typval.h b/src/nvim/eval/typval.h index d8ede1e3ba..6fcb01aace 100644 --- a/src/nvim/eval/typval.h +++ b/src/nvim/eval/typval.h @@ -315,6 +315,7 @@ struct ufunc { int uf_calls; ///< nr of active calls bool uf_cleared; ///< func_clear() was already called garray_T uf_args; ///< arguments + garray_T uf_def_args; ///< default argument expressions garray_T uf_lines; ///< function lines int uf_profiling; ///< true when func is being profiled int uf_prof_initialized; diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 70c998ef39..689d05e079 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -67,7 +67,7 @@ void func_init(void) /// Get function arguments. static int get_function_args(char_u **argp, char_u endchar, garray_T *newargs, - int *varargs, bool skip) + int *varargs, garray_T *default_args, bool skip) { bool mustend = false; char_u *arg = *argp; @@ -78,12 +78,16 @@ static int get_function_args(char_u **argp, char_u endchar, garray_T *newargs, if (newargs != NULL) { ga_init(newargs, (int)sizeof(char_u *), 3); } + if (default_args != NULL) { + ga_init(default_args, (int)sizeof(char_u *), 3); + } if (varargs != NULL) { *varargs = false; } // Isolate the arguments: "arg1, arg2, ...)" + bool any_default = false; while (*p != endchar) { if (p[0] == '.' && p[1] == '.' && p[2] == '.') { if (varargs != NULL) { @@ -123,6 +127,38 @@ static int get_function_args(char_u **argp, char_u endchar, garray_T *newargs, *p = c; } + if (*skipwhite(p) == '=' && default_args != NULL) { + typval_T rettv; + + any_default = true; + p = skipwhite(p) + 1; + p = skipwhite(p); + char_u *expr = p; + if (eval1(&p, &rettv, false) != FAIL) { + ga_grow(default_args, 1); + + // trim trailing whitespace + while (p > expr && ascii_iswhite(p[-1])) { + p--; + } + c = *p; + *p = NUL; + expr = vim_strsave(expr); + if (expr == NULL) { + *p = c; + goto err_ret; + } + ((char_u **)(default_args->ga_data)) + [default_args->ga_len] = expr; + default_args->ga_len++; + *p = c; + } else { + mustend = true; + } + } else if (any_default) { + EMSG(_("E989: Non-default argument follows default argument")); + mustend = true; + } if (*p == ',') { p++; } else { @@ -149,6 +185,9 @@ err_ret: if (newargs != NULL) { ga_clear_strings(newargs); } + if (default_args != NULL) { + ga_clear_strings(default_args); + } return FAIL; } @@ -195,7 +234,7 @@ int get_lambda_tv(char_u **arg, typval_T *rettv, bool evaluate) bool eval_lavars = false; // First, check if this is a lambda expression. "->" must exists. - ret = get_function_args(&start, '-', NULL, NULL, true); + ret = get_function_args(&start, '-', NULL, NULL, NULL, true); if (ret == FAIL || *start != '>') { return NOTDONE; } @@ -207,7 +246,7 @@ int get_lambda_tv(char_u **arg, typval_T *rettv, bool evaluate) pnewargs = NULL; } *arg = skipwhite(*arg + 1); - ret = get_function_args(arg, '-', pnewargs, &varargs, false); + ret = get_function_args(arg, '-', pnewargs, &varargs, NULL, false); if (ret == FAIL || **arg != '>') { goto errret; } @@ -259,6 +298,7 @@ int get_lambda_tv(char_u **arg, typval_T *rettv, bool evaluate) STRCPY(fp->uf_name, name); hash_add(&func_hashtab, UF2HIKEY(fp)); fp->uf_args = newargs; + ga_init(&fp->uf_def_args, (int)sizeof(char_u *), 1); fp->uf_lines = newlines; if (current_funccal != NULL && eval_lavars) { flags |= FC_CLOSURE; @@ -715,6 +755,7 @@ static bool func_remove(ufunc_T *fp) static void func_clear_items(ufunc_T *fp) { ga_clear_strings(&(fp->uf_args)); + ga_clear_strings(&(fp->uf_def_args)); ga_clear_strings(&(fp->uf_lines)); if (fp->uf_cb_free != NULL) { @@ -857,12 +898,13 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, } // Init a: variables, unless none found (in lambda). - // Set a:0 to "argcount". + // Set a:0 to "argcount" less number of named arguments, if >= 0. // Set a:000 to a list with room for the "..." arguments. init_var_dict(&fc->l_avars, &fc->l_avars_var, VAR_SCOPE); if ((fp->uf_flags & FC_NOARGS) == 0) { add_nr_var(&fc->l_avars, (dictitem_T *)&fc->fixvar[fixvar_idx++], "0", - (varnumber_T)(argcount - fp->uf_args.ga_len)); + (varnumber_T)(argcount >= fp->uf_args.ga_len + ? argcount - fp->uf_args.ga_len : 0)); } fc->l_avars.dv_lock = VAR_FIXED; if ((fp->uf_flags & FC_NOARGS) == 0) { @@ -892,8 +934,11 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, add_nr_var(&fc->l_avars, (dictitem_T *)&fc->fixvar[fixvar_idx++], "lastline", (varnumber_T)lastline); } - for (int i = 0; i < argcount; i++) { + bool default_arg_err = false; + for (int i = 0; i < argcount || i < fp->uf_args.ga_len; i++) { bool addlocal = false; + bool isdefault = false; + typval_T def_rettv; ai = i - fp->uf_args.ga_len; if (ai < 0) { @@ -902,6 +947,21 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, if (islambda) { addlocal = true; } + + // evaluate named argument default expression + isdefault = ai + fp->uf_def_args.ga_len >= 0 && i >= argcount; + if (isdefault) { + char_u *default_expr = NULL; + def_rettv.v_type = VAR_NUMBER; + def_rettv.vval.v_number = -1; + + default_expr = ((char_u **)(fp->uf_def_args.ga_data)) + [ai + fp->uf_def_args.ga_len]; + if (eval1(&default_expr, &def_rettv, true) == FAIL) { + default_arg_err = true; + break; + } + } } else { if ((fp->uf_flags & FC_NOARGS) != 0) { // Bail out if no a: arguments used (in lambda). @@ -922,7 +982,7 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, // Note: the values are copied directly to avoid alloc/free. // "argvars" must have VAR_FIXED for v_lock. - v->di_tv = argvars[i]; + v->di_tv = isdefault ? def_rettv : argvars[i]; v->di_tv.v_lock = VAR_FIXED; if (addlocal) { @@ -1046,7 +1106,9 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, save_did_emsg = did_emsg; did_emsg = FALSE; - if (islambda) { + if (default_arg_err && (fp->uf_flags & FC_ABORT)) { + did_emsg = true; + } else if (islambda) { char_u *p = *(char_u **)fp->uf_lines.ga_data + 7; // A Lambda always has the command "return {expr}". It is much faster @@ -1490,7 +1552,7 @@ call_func( if (fp->uf_flags & FC_RANGE) { *doesrange = true; } - if (argcount < fp->uf_args.ga_len) { + if (argcount < fp->uf_args.ga_len - fp->uf_def_args.ga_len) { error = ERROR_TOOFEW; } else if (!fp->uf_varargs && argcount > fp->uf_args.ga_len) { error = ERROR_TOOMANY; @@ -1573,6 +1635,11 @@ static void list_func_head(ufunc_T *fp, int indent, bool force) msg_puts(", "); } msg_puts((const char *)FUNCARG(fp, j)); + if (j >= fp->uf_args.ga_len - fp->uf_def_args.ga_len) { + msg_puts(" = "); + msg_puts(((char **)(fp->uf_def_args.ga_data)) + [j - fp->uf_args.ga_len + fp->uf_def_args.ga_len]); + } } if (fp->uf_varargs) { if (j) { @@ -1836,6 +1903,7 @@ void ex_function(exarg_T *eap) char_u *arg; char_u *line_arg = NULL; garray_T newargs; + garray_T default_args; garray_T newlines; int varargs = false; int flags = 0; @@ -2039,7 +2107,8 @@ void ex_function(exarg_T *eap) } } - if (get_function_args(&p, ')', &newargs, &varargs, eap->skip) == FAIL) { + if (get_function_args(&p, ')', &newargs, &varargs, + &default_args, eap->skip) == FAIL) { goto errret_2; } @@ -2458,6 +2527,7 @@ void ex_function(exarg_T *eap) fp->uf_refcount = 1; } fp->uf_args = newargs; + fp->uf_def_args = default_args; fp->uf_lines = newlines; if ((flags & FC_CLOSURE) != 0) { register_closure(fp); @@ -2480,6 +2550,7 @@ void ex_function(exarg_T *eap) erret: ga_clear_strings(&newargs); + ga_clear_strings(&default_args); errret_2: ga_clear_strings(&newlines); ret_free: diff --git a/src/nvim/event/process.c b/src/nvim/event/process.c index 8e9964bd37..b93d6cc0ab 100644 --- a/src/nvim/event/process.c +++ b/src/nvim/event/process.c @@ -270,9 +270,6 @@ static void process_close_event(void **argv) { Process *proc = argv[0]; shell_free_argv(proc->argv); - if (proc->type == kProcessTypePty) { - xfree(((PtyProcess *)proc)->term_name); - } if (proc->cb) { // "on_exit" for jobstart(). See channel_job_start(). proc->cb(proc, proc->status, proc->data); } diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 2da8c205c1..854faf5377 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -790,7 +790,10 @@ void ex_retab(exarg_T *eap) for (col = 0; col < len; col++) { ptr[col] = (col < num_tabs) ? '\t' : ' '; } - ml_replace(lnum, new_line, false); + if (ml_replace(lnum, new_line, false) == OK) { + // "new_line" may have been copied + new_line = curbuf->b_ml.ml_line_ptr; + } if (first_line == 0) { first_line = lnum; } @@ -1404,19 +1407,20 @@ do_shell( * For autocommands we want to get the output on the current screen, to * avoid having to type return below. */ - msg_putchar('\r'); /* put cursor at start of line */ - msg_putchar('\n'); /* may shift screen one line up */ + msg_putchar('\r'); // put cursor at start of line + msg_putchar('\n'); // may shift screen one line up - /* warning message before calling the shell */ + // warning message before calling the shell if (p_warn && !autocmd_busy - && msg_silent == 0) + && msg_silent == 0) { FOR_ALL_BUFFERS(buf) { if (bufIsChanged(buf)) { MSG_PUTS(_("[No write since last change]\n")); break; } } + } // This ui_cursor_goto is required for when the '\n' resulted in a "delete line // 1" command to the terminal. @@ -2178,6 +2182,8 @@ theend: /// ECMD_OLDBUF: use existing buffer if it exists /// ECMD_FORCEIT: ! used for Ex command /// ECMD_ADDBUF: don't edit, just add to buffer list +/// ECMD_ALTBUF: like ECMD_ADDBUF and also set the alternate +/// file /// @param oldwin Should be "curwin" when editing a new buffer in the current /// window, NULL when splitting the window first. When not NULL /// info of the previous buffer for "oldwin" is stored. @@ -2234,8 +2240,10 @@ int do_ecmd( path_fix_case(sfname); // set correct case for sfname #endif - if ((flags & ECMD_ADDBUF) && (ffname == NULL || *ffname == NUL)) + if ((flags & (ECMD_ADDBUF | ECMD_ALTBUF)) + && (ffname == NULL || *ffname == NUL)) { goto theend; + } if (ffname == NULL) other_file = TRUE; @@ -2265,15 +2273,16 @@ int do_ecmd( // If the file was changed we may not be allowed to abandon it: // - if we are going to re-edit the same file // - or if we are the only window on this file and if ECMD_HIDE is FALSE - if ( ((!other_file && !(flags & ECMD_OLDBUF)) - || (curbuf->b_nwindows == 1 - && !(flags & (ECMD_HIDE | ECMD_ADDBUF)))) - && check_changed(curbuf, (p_awa ? CCGD_AW : 0) - | (other_file ? 0 : CCGD_MULTWIN) - | ((flags & ECMD_FORCEIT) ? CCGD_FORCEIT : 0) - | (eap == NULL ? 0 : CCGD_EXCMD))) { - if (fnum == 0 && other_file && ffname != NULL) + if (((!other_file && !(flags & ECMD_OLDBUF)) + || (curbuf->b_nwindows == 1 + && !(flags & (ECMD_HIDE | ECMD_ADDBUF | ECMD_ALTBUF)))) + && check_changed(curbuf, (p_awa ? CCGD_AW : 0) + | (other_file ? 0 : CCGD_MULTWIN) + | ((flags & ECMD_FORCEIT) ? CCGD_FORCEIT : 0) + | (eap == NULL ? 0 : CCGD_EXCMD))) { + if (fnum == 0 && other_file && ffname != NULL) { (void)setaltfname(ffname, sfname, newlnum < 0 ? 0 : newlnum); + } goto theend; } @@ -2303,25 +2312,35 @@ int do_ecmd( * Otherwise we re-use the current buffer. */ if (other_file) { - if (!(flags & ECMD_ADDBUF)) { - if (!cmdmod.keepalt) + if (!(flags & (ECMD_ADDBUF | ECMD_ALTBUF))) { + if (!cmdmod.keepalt) { curwin->w_alt_fnum = curbuf->b_fnum; - if (oldwin != NULL) + } + if (oldwin != NULL) { buflist_altfpos(oldwin); + } } if (fnum) { buf = buflist_findnr(fnum); } else { - if (flags & ECMD_ADDBUF) { - linenr_T tlnum = 1L; + if (flags & (ECMD_ADDBUF | ECMD_ALTBUF)) { + // Default the line number to zero to avoid that a wininfo item + // is added for the current window. + linenr_T tlnum = 0; if (command != NULL) { tlnum = atol((char *)command); if (tlnum <= 0) tlnum = 1L; } - (void)buflist_new(ffname, sfname, tlnum, BLN_LISTED); + // Add BLN_NOCURWIN to avoid a new wininfo items are associated + // with the current window. + const buf_T *const newbuf + = buflist_new(ffname, sfname, tlnum, BLN_LISTED | BLN_NOCURWIN); + if (newbuf != NULL && (flags & ECMD_ALTBUF)) { + curwin->w_alt_fnum = newbuf->b_fnum; + } goto theend; } buf = buflist_new(ffname, sfname, 0L, @@ -2413,7 +2432,10 @@ int do_ecmd( (flags & ECMD_HIDE) || curbuf->terminal ? 0 : DOBUF_UNLOAD, false); - the_curwin->w_closing = false; + // Autocommands may have closed the window. + if (win_valid(the_curwin)) { + the_curwin->w_closing = false; + } buf->b_locked--; // autocmds may abort script processing @@ -2464,8 +2486,7 @@ int do_ecmd( curwin->w_pcmark.lnum = 1; curwin->w_pcmark.col = 0; } else { // !other_file - if ((flags & ECMD_ADDBUF) - || check_fname() == FAIL) { + if ((flags & (ECMD_ADDBUF | ECMD_ALTBUF)) || check_fname() == FAIL) { goto theend; } oldbuf = (flags & ECMD_OLDBUF); @@ -2531,13 +2552,13 @@ int do_ecmd( goto theend; } u_unchanged(curbuf); - buf_updates_unregister_all(curbuf); + buf_updates_unload(curbuf, false); buf_freeall(curbuf, BFA_KEEP_UNDO); // Tell readfile() not to clear or reload undo info. readfile_flags = READ_KEEP_UNDO; } else { - buf_updates_unregister_all(curbuf); + buf_updates_unload(curbuf, false); buf_freeall(curbuf, 0); // Free all things for buffer. } // If autocommands deleted the buffer we were going to re-edit, give @@ -3310,11 +3331,7 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, int save_b_changed = curbuf->b_changed; bool preview = (State & CMDPREVIEW); - // inccommand tests fail without this check - if (!preview) { - // Required for Undo to work for extmarks. - u_save_cursor(); - } + bool did_save = false; if (!global_busy) { sub_nsubs = 0; @@ -3991,6 +4008,11 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, int matchcols = end.col - ((end.lnum == start.lnum) ? start.col : 0); int subcols = new_endcol - ((lnum == lnum_start) ? start_col : 0); + if (!did_save) { + // Required for Undo to work for extmarks. + u_save_cursor(); + did_save = true; + } extmark_splice(curbuf, lnum_start-1, start_col, end.lnum-start.lnum, matchcols, replaced_bytes, lnum-lnum_start, subcols, sublen-1, kExtmarkUndo); @@ -4177,7 +4199,7 @@ skip: // when interactive leave cursor on the match if (!subflags.do_ask) { if (endcolumn) { - coladvance((colnr_T)MAXCOL); + coladvance(MAXCOL); } else { beginline(BL_WHITE | BL_FIX); } @@ -4220,7 +4242,7 @@ skip: size_t subsize = preview_lines.subresults.size; if (preview && !aborting()) { if (got_quit || profile_passed_limit(timeout)) { // Too slow, disable. - set_string_option_direct((char_u *)"icm", -1, (char_u *)"", OPT_FREE, + set_string_option_direct("icm", -1, (char_u *)"", OPT_FREE, SID_NONE); } else if (*p_icm != NUL && pat != NULL) { if (pre_src_id == 0) { @@ -4521,7 +4543,7 @@ prepare_tagpreview ( RESET_BINDING(curwin); /* don't take over 'scrollbind' and 'cursorbind' */ curwin->w_p_diff = false; // no 'diff' - set_string_option_direct((char_u *)"fdc", -1, // no 'foldcolumn' + set_string_option_direct("fdc", -1, // no 'foldcolumn' (char_u *)"0", OPT_FREE, SID_NONE); return true; } @@ -4999,7 +5021,7 @@ int find_help_tags(const char_u *arg, int *num_matches, char_u ***matches, if (keep_lang) { flags |= TAG_KEEP_LANG; } - if (find_tags(IObuff, num_matches, matches, flags, (int)MAXCOL, NULL) == OK + if (find_tags(IObuff, num_matches, matches, flags, MAXCOL, NULL) == OK && *num_matches > 0) { /* Sort the matches found on the heuristic number that is after the * tag name. */ @@ -5016,7 +5038,7 @@ int find_help_tags(const char_u *arg, int *num_matches, char_u ***matches, static void prepare_help_buffer(void) { curbuf->b_help = true; - set_string_option_direct((char_u *)"buftype", -1, (char_u *)"help", + set_string_option_direct("buftype", -1, (char_u *)"help", OPT_FREE|OPT_LOCAL, 0); // Always set these options after jumping to a help tag, because the @@ -5026,13 +5048,13 @@ static void prepare_help_buffer(void) // Only set it when needed, buf_init_chartab() is some work. char_u *p = (char_u *)"!-~,^*,^|,^\",192-255"; if (STRCMP(curbuf->b_p_isk, p) != 0) { - set_string_option_direct((char_u *)"isk", -1, p, OPT_FREE|OPT_LOCAL, 0); + set_string_option_direct("isk", -1, p, OPT_FREE|OPT_LOCAL, 0); check_buf_options(curbuf); (void)buf_init_chartab(curbuf, FALSE); } // Don't use the global foldmethod. - set_string_option_direct((char_u *)"fdm", -1, (char_u *)"manual", + set_string_option_direct("fdm", -1, (char_u *)"manual", OPT_FREE|OPT_LOCAL, 0); curbuf->b_p_ts = 8; // 'tabstop' is 8. @@ -5652,7 +5674,7 @@ static buf_T *show_sub(exarg_T *eap, pos_T old_cusr, cmdmod.tab = 0; // disable :tab modifier cmdmod.noswapfile = true; // disable swap for preview buffer // disable file info message - set_string_option_direct((char_u *)"shm", -1, (char_u *)"F", OPT_FREE, + set_string_option_direct("shm", -1, (char_u *)"F", OPT_FREE, SID_NONE); bool outside_curline = (eap->line1 != old_cusr.lnum @@ -5775,7 +5797,7 @@ static buf_T *show_sub(exarg_T *eap, pos_T old_cusr, update_screen(SOME_VALID); RedrawingDisabled = save_rd; - set_string_option_direct((char_u *)"shm", -1, save_shm_p, OPT_FREE, SID_NONE); + set_string_option_direct("shm", -1, save_shm_p, OPT_FREE, SID_NONE); xfree(save_shm_p); cmdmod = save_cmdmod; diff --git a/src/nvim/ex_cmds.h b/src/nvim/ex_cmds.h index b564cde56c..1b54b3a898 100644 --- a/src/nvim/ex_cmds.h +++ b/src/nvim/ex_cmds.h @@ -16,7 +16,7 @@ #define ECMD_OLDBUF 0x04 // use existing buffer if it exists #define ECMD_FORCEIT 0x08 // ! used in Ex command #define ECMD_ADDBUF 0x10 // don't edit, just add to buffer list - +#define ECMD_ALTBUF 0x20 // like ECMD_ADDBUF and set the alternate file /* for lnum argument in do_ecmd() */ #define ECMD_LASTL (linenr_T)0 /* use last position in loaded file */ diff --git a/src/nvim/ex_cmds.lua b/src/nvim/ex_cmds.lua index e9046da800..2965ea7496 100644 --- a/src/nvim/ex_cmds.lua +++ b/src/nvim/ex_cmds.lua @@ -176,6 +176,12 @@ module.cmds = { func='ex_edit', }, { + command='balt', + flags=bit.bor(NEEDARG, FILE1, CMDARG, TRLBAR, CMDWIN), + addr_type='ADDR_NONE', + func='ex_edit', + }, + { command='bdelete', flags=bit.bor(BANG, RANGE, BUFNAME, COUNT, EXTRA, TRLBAR), addr_type='ADDR_BUFFERS', @@ -2515,8 +2521,8 @@ module.cmds = { }, { command='source', - flags=bit.bor(BANG, FILE1, TRLBAR, SBOXOK, CMDWIN), - addr_type='ADDR_NONE', + flags=bit.bor(RANGE, DFLALL, WHOLEFOLD, BANG, FILE1, TRLBAR, SBOXOK, CMDWIN), + addr_type='ADDR_LINES', func='ex_source', }, { diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index e49bb99aa0..c4c18c4324 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -29,6 +29,7 @@ #include "nvim/getchar.h" #include "nvim/mark.h" #include "nvim/mbyte.h" +#include "nvim/memline.h" #include "nvim/message.h" #include "nvim/misc1.h" #include "nvim/garray.h" @@ -1657,9 +1658,11 @@ int get_arglist_exp(char_u *str, int *fcountp, char_u ***fnamesp, bool wig) /// AL_DEL: remove files in 'str' from the argument list. /// @param after /// 0 means before first one +/// @param will_edit will edit added argument /// /// @return FAIL for failure, OK otherwise. -static int do_arglist(char_u *str, int what, int after) +static int do_arglist(char_u *str, int what, int after, bool will_edit) + FUNC_ATTR_NONNULL_ALL { garray_T new_ga; int exp_count; @@ -1733,10 +1736,11 @@ static int do_arglist(char_u *str, int what, int after) } if (what == AL_ADD) { - (void)alist_add_list(exp_count, exp_files, after); + alist_add_list(exp_count, exp_files, after, will_edit); xfree(exp_files); - } else { // what == AL_SET - alist_set(ALIST(curwin), exp_count, exp_files, false, NULL, 0); + } else { + assert(what == AL_SET); + alist_set(ALIST(curwin), exp_count, exp_files, will_edit, NULL, 0); } } @@ -1956,7 +1960,7 @@ void ex_next(exarg_T *eap) | (eap->forceit ? CCGD_FORCEIT : 0) | CCGD_EXCMD)) { if (*eap->arg != NUL) { // redefine file list - if (do_arglist(eap->arg, AL_SET, 0) == FAIL) { + if (do_arglist(eap->arg, AL_SET, 0, true) == FAIL) { return; } i = 0; @@ -1974,7 +1978,7 @@ void ex_argedit(exarg_T *eap) // Whether curbuf will be reused, curbuf->b_ffname will be set. bool curbuf_is_reusable = curbuf_reusable(); - if (do_arglist(eap->arg, AL_ADD, i) == FAIL) { + if (do_arglist(eap->arg, AL_ADD, i, true) == FAIL) { return; } maketitle(); @@ -1994,7 +1998,8 @@ void ex_argedit(exarg_T *eap) void ex_argadd(exarg_T *eap) { do_arglist(eap->arg, AL_ADD, - eap->addr_count > 0 ? (int)eap->line2 : curwin->w_arg_idx + 1); + eap->addr_count > 0 ? (int)eap->line2 : curwin->w_arg_idx + 1, + false); maketitle(); } @@ -2041,7 +2046,7 @@ void ex_argdelete(exarg_T *eap) } } } else { - do_arglist(eap->arg, AL_DEL, 0); + do_arglist(eap->arg, AL_DEL, 0, false); } maketitle(); } @@ -2292,9 +2297,9 @@ void ex_listdo(exarg_T *eap) /// Files[] itself is not taken over. /// /// @param after: where to add: 0 = before first one -/// -/// @return index of first added argument -static int alist_add_list(int count, char_u **files, int after) +/// @param will_edit will edit adding argument +static void alist_add_list(int count, char_u **files, int after, bool will_edit) + FUNC_ATTR_NONNULL_ALL { int old_argcount = ARGCOUNT; ga_grow(&ALIST(curwin)->al_ga, count); @@ -2310,15 +2315,15 @@ static int alist_add_list(int count, char_u **files, int after) (size_t)(ARGCOUNT - after) * sizeof(aentry_T)); } for (int i = 0; i < count; i++) { + const int flags = BLN_LISTED | (will_edit ? BLN_CURBUF : 0); ARGLIST[after + i].ae_fname = files[i]; - ARGLIST[after + i].ae_fnum = buflist_add(files[i], - BLN_LISTED | BLN_CURBUF); + ARGLIST[after + i].ae_fnum = buflist_add(files[i], flags); } ALIST(curwin)->al_ga.ga_len += count; if (old_argcount > 0 && curwin->w_arg_idx >= after) { curwin->w_arg_idx += count; } - return after; + return; } } @@ -2375,13 +2380,13 @@ void ex_compiler(exarg_T *eap) // Set "b:current_compiler" from "current_compiler". p = get_var_value("g:current_compiler"); if (p != NULL) { - set_internal_string_var((char_u *)"b:current_compiler", p); + set_internal_string_var("b:current_compiler", p); } // Restore "current_compiler" for ":compiler {name}". if (!eap->forceit) { if (old_cur_comp != NULL) { - set_internal_string_var((char_u *)"g:current_compiler", + set_internal_string_var("g:current_compiler", old_cur_comp); xfree(old_cur_comp); } else { @@ -2522,7 +2527,7 @@ void ex_pyxdo(exarg_T *eap) } } -/// ":source {fname}" +/// ":source [{fname}]" void ex_source(exarg_T *eap) { cmd_source(eap->arg, eap); @@ -2531,7 +2536,7 @@ void ex_source(exarg_T *eap) static void cmd_source(char_u *fname, exarg_T *eap) { if (*fname == NUL) { - EMSG(_(e_argreq)); + cmd_source_buffer(eap); } else if (eap != NULL && eap->forceit) { // ":source!": read Normal mode commands // Need to execute the commands directly. This is required at least @@ -2549,6 +2554,37 @@ static void cmd_source(char_u *fname, exarg_T *eap) } } +typedef struct { + linenr_T curr_lnum; + const linenr_T final_lnum; +} GetBufferLineCookie; + +/// Get one line from the current selection in the buffer. +/// Called by do_cmdline() when it's called from cmd_source_buffer(). +/// +/// @return pointer to allocated line, or NULL for end-of-file or +/// some error. +static char_u *get_buffer_line(int c, void *cookie, int indent, bool do_concat) +{ + GetBufferLineCookie *p = cookie; + if (p->curr_lnum > p->final_lnum) { + return NULL; + } + char_u *curr_line = ml_get(p->curr_lnum); + p->curr_lnum++; + return (char_u *)xstrdup((const char *)curr_line); +} + +static void cmd_source_buffer(exarg_T *eap) +{ + GetBufferLineCookie cookie = { + .curr_lnum = eap->line1, + .final_lnum = eap->line2, + }; + source_using_linegetter((void *)&cookie, get_buffer_line, + ":source (no file)"); +} + /// ":source" and associated commands. /// /// @return address holding the next breakpoint line for a source cookie @@ -2620,10 +2656,9 @@ static char_u *get_str_line(int c, void *cookie, int indent, bool do_concat) return (char_u *)xstrdup(buf); } -/// Executes lines in `src` as Ex commands. -/// -/// @see do_source() -int do_source_str(const char *cmd, const char *traceback_name) +static int source_using_linegetter(void *cookie, + LineGetter fgetline, + const char *traceback_name) { char_u *save_sourcing_name = sourcing_name; linenr_T save_sourcing_lnum = sourcing_lnum; @@ -2638,22 +2673,33 @@ int do_source_str(const char *cmd, const char *traceback_name) } sourcing_lnum = 0; - GetStrLineCookie cookie = { - .buf = (char_u *)cmd, - .offset = 0, - }; const sctx_T save_current_sctx = current_sctx; current_sctx.sc_sid = SID_STR; current_sctx.sc_seq = 0; current_sctx.sc_lnum = save_sourcing_lnum; - int retval = do_cmdline(NULL, get_str_line, (void *)&cookie, + funccal_entry_T entry; + save_funccal(&entry); + int retval = do_cmdline(NULL, fgetline, cookie, DOCMD_VERBOSE | DOCMD_NOWAIT | DOCMD_REPEAT); - current_sctx = save_current_sctx; sourcing_lnum = save_sourcing_lnum; sourcing_name = save_sourcing_name; + current_sctx = save_current_sctx; + restore_funccal(); return retval; } +/// Executes lines in `src` as Ex commands. +/// +/// @see do_source() +int do_source_str(const char *cmd, const char *traceback_name) +{ + GetStrLineCookie cookie = { + .buf = (char_u *)cmd, + .offset = 0, + }; + return source_using_linegetter((void *)&cookie, get_str_line, traceback_name); +} + /// Reads the file `fname` and executes its lines as Ex commands. /// /// This function may be called recursively! @@ -2978,6 +3024,7 @@ void scriptnames_slash_adjust(void) # endif /// Get a pointer to a script name. Used for ":verbose set". +/// Message appended to "Last set from " char_u *get_scriptname(LastSet last_set, bool *should_free) { *should_free = false; @@ -2993,6 +3040,8 @@ char_u *get_scriptname(LastSet last_set, bool *should_free) return (char_u *)_("environment variable"); case SID_ERROR: return (char_u *)_("error handler"); + case SID_WINLAYOUT: + return (char_u *)_("changed window size"); case SID_LUA: return (char_u *)_("Lua"); case SID_API_CLIENT: @@ -3766,7 +3815,7 @@ void ex_drop(exarg_T *eap) // and mostly only one file is dropped. // This also ignores wildcards, since it is very unlikely the user is // editing a file name with a wildcard character. - do_arglist(eap->arg, AL_SET, 0); + do_arglist(eap->arg, AL_SET, 0, false); // Expanding wildcards may result in an empty argument list. E.g. when // editing "foo.pyc" and ".pyc" is in 'wildignore'. Assume that we diff --git a/src/nvim/ex_cmds_defs.h b/src/nvim/ex_cmds_defs.h index ca84d375ce..f928c61ea4 100644 --- a/src/nvim/ex_cmds_defs.h +++ b/src/nvim/ex_cmds_defs.h @@ -188,8 +188,8 @@ struct exarg { // used for completion on the command line struct expand { - int xp_context; // type of expansion char_u *xp_pattern; // start of item to expand + int xp_context; // type of expansion size_t xp_pattern_len; // bytes in xp_pattern before cursor char_u *xp_arg; // completion function sctx_T xp_script_ctx; // SCTX for completion function @@ -199,9 +199,9 @@ struct expand { // characters need to be escaped #endif int xp_numfiles; // number of files found by file name completion + int xp_col; // cursor position in line char_u **xp_files; // list of files char_u *xp_line; // text being completed - int xp_col; // cursor position in line }; // values for xp_backslash diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 52da7fe4f6..bc3d29a03f 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -2179,7 +2179,7 @@ int parse_command_modifiers(exarg_T *eap, char_u **errormsg, bool skip_only) // Set 'eventignore' to "all". Restore the // existing option value later. cmdmod.save_ei = vim_strsave(p_ei); - set_string_option_direct((char_u *)"ei", -1, + set_string_option_direct("ei", -1, (char_u *)"all", OPT_FREE, SID_NONE); } continue; @@ -2291,9 +2291,8 @@ static void undo_cmdmod(const exarg_T *eap, int save_msg_scroll) } if (cmdmod.save_ei != NULL) { - /* Restore 'eventignore' to the value before ":noautocmd". */ - set_string_option_direct((char_u *)"ei", -1, cmdmod.save_ei, - OPT_FREE, SID_NONE); + // Restore 'eventignore' to the value before ":noautocmd". + set_string_option_direct("ei", -1, cmdmod.save_ei, OPT_FREE, SID_NONE); free_string_option(cmdmod.save_ei); } @@ -3513,13 +3512,20 @@ const char * set_one_cmd_context( xp->xp_context = EXPAND_BUFFERS; xp->xp_pattern = (char_u *)arg; break; + case CMD_diffget: + case CMD_diffput: + // If current buffer is in diff mode, complete buffer names + // which are in diff mode, and different than current buffer. + xp->xp_context = EXPAND_DIFF_BUFFERS; + xp->xp_pattern = (char_u *)arg; + break; case CMD_USER: case CMD_USER_BUF: if (context != EXPAND_NOTHING) { // EX_XFILE: file names are handled above. if (!(ea.argt & EX_XFILE)) { if (context == EXPAND_MENUS) { - return (const char *)set_context_in_menu_cmd(xp, (char_u *)cmd, + return (const char *)set_context_in_menu_cmd(xp, cmd, (char_u *)arg, forceit); } else if (context == EXPAND_COMMANDS) { return arg; @@ -3599,7 +3605,7 @@ const char * set_one_cmd_context( case CMD_tmenu: case CMD_tunmenu: case CMD_popup: case CMD_emenu: return (const char *)set_context_in_menu_cmd( - xp, (char_u *)cmd, (char_u *)arg, forceit); + xp, cmd, (char_u *)arg, forceit); case CMD_colorscheme: xp->xp_context = EXPAND_COLORS; @@ -5175,6 +5181,7 @@ static const char *command_complete[] = [EXPAND_CSCOPE] = "cscope", [EXPAND_USER_DEFINED] = "custom", [EXPAND_USER_LIST] = "customlist", + [EXPAND_DIFF_BUFFERS] = "diff_buffer", [EXPAND_DIRECTORIES] = "dir", [EXPAND_ENV_VARS] = "environment", [EXPAND_EVENTS] = "event", @@ -6275,14 +6282,14 @@ int parse_compl_arg(const char_u *value, int vallen, int *complp, return OK; } -int cmdcomplete_str_to_type(char_u *complete_str) +int cmdcomplete_str_to_type(const char *complete_str) { for (int i = 0; i < (int)(ARRAY_SIZE(command_complete)); i++) { char *cmd_compl = get_command_complete(i); if (cmd_compl == NULL) { continue; } - if (STRCMP(complete_str, command_complete[i]) == 0) { + if (strcmp(complete_str, command_complete[i]) == 0) { return i; } } @@ -7272,9 +7279,7 @@ static void ex_find(exarg_T *eap) } } -/* - * ":edit", ":badd", ":visual". - */ +/// ":edit", ":badd", ":balt", ":visual". static void ex_edit(exarg_T *eap) { do_exedit(eap, NULL); @@ -7348,7 +7353,9 @@ do_exedit( else if (eap->cmdidx == CMD_enew) readonlymode = FALSE; /* 'readonly' doesn't make sense in an empty buffer */ - setpcmark(); + if (eap->cmdidx != CMD_balt && eap->cmdidx != CMD_badd) { + setpcmark(); + } if (do_ecmd(0, (eap->cmdidx == CMD_enew ? NULL : eap->arg), NULL, eap, eap->do_ecmd_lnum, (buf_hide(curbuf) ? ECMD_HIDE : 0) @@ -7356,6 +7363,7 @@ do_exedit( // After a split we can use an existing buffer. + (old_curwin != NULL ? ECMD_OLDBUF : 0) + (eap->cmdidx == CMD_badd ? ECMD_ADDBUF : 0) + + (eap->cmdidx == CMD_balt ? ECMD_ALTBUF : 0) , old_curwin == NULL ? curwin : NULL) == FAIL) { // Editing the file failed. If the window was split, close it. if (old_curwin != NULL) { @@ -7756,6 +7764,11 @@ static void do_exmap(exarg_T *eap, int isabbrev) static void ex_winsize(exarg_T *eap) { char_u *arg = eap->arg; + + if (!ascii_isdigit(*arg)) { + EMSG2(_(e_invarg2), arg); + return; + } int w = getdigits_int(&arg, false, 10); arg = skipwhite(arg); char_u *p = arg; @@ -8721,7 +8734,7 @@ ssize_t find_cmdline_var(const char_u *src, size_t *usedlen) * Evaluate cmdline variables. * * change '%' to curbuf->b_ffname - * '#' to curwin->w_altfile + * '#' to curwin->w_alt_fnum * '<cword>' to word under the cursor * '<cWORD>' to WORD under the cursor * '<cexpr>' to C-expression under the cursor diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index cf6bb6d492..5979f4d3a0 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -886,7 +886,7 @@ static uint8_t *command_line_enter(int firstc, long count, int indent) need_wait_return = false; } - set_string_option_direct((char_u *)"icm", -1, s->save_p_icm, OPT_FREE, + set_string_option_direct("icm", -1, s->save_p_icm, OPT_FREE, SID_NONE); State = s->save_State; setmouse(); @@ -935,7 +935,7 @@ static int command_line_execute(VimState *state, int key) if (s->c == K_EVENT || s->c == K_COMMAND) { if (s->c == K_EVENT) { - multiqueue_process_events(main_loop.events); + state_handle_k_event(); } else { do_cmdline(NULL, getcmdkeycmd, NULL, DOCMD_NOWAIT); } @@ -5084,9 +5084,13 @@ ExpandFromContext ( } if (xp->xp_context == EXPAND_BUFFERS) return ExpandBufnames(pat, num_file, file, options); + if (xp->xp_context == EXPAND_DIFF_BUFFERS) { + return ExpandBufnames(pat, num_file, file, options | BUF_DIFF_FILTER); + } if (xp->xp_context == EXPAND_TAGS - || xp->xp_context == EXPAND_TAGS_LISTFILES) + || xp->xp_context == EXPAND_TAGS_LISTFILES) { return expand_tags(xp->xp_context == EXPAND_TAGS, pat, num_file, file); + } if (xp->xp_context == EXPAND_COLORS) { char *directories[] = { "colors", NULL }; return ExpandRTDir(pat, DIP_START + DIP_OPT, num_file, file, directories); @@ -6441,7 +6445,7 @@ static int open_cmdwin(void) cmdwin_level = ccline.level; // Create empty command-line buffer. - buf_open_scratch(0, "[Command Line]"); + buf_open_scratch(0, _("[Command Line]")); // Command-line buffer has bufhidden=wipe, unlike a true "scratch" buffer. set_option_value("bh", 0L, "wipe", OPT_LOCAL); curwin->w_p_rl = cmdmsg_rl; @@ -6770,6 +6774,6 @@ static void set_search_match(pos_T *t) t->col = search_match_endcol; if (t->lnum > curbuf->b_ml.ml_line_count) { t->lnum = curbuf->b_ml.ml_line_count; - coladvance((colnr_T)MAXCOL); + coladvance(MAXCOL); } } diff --git a/src/nvim/ex_getln.h b/src/nvim/ex_getln.h index dc4395e081..3727aa5e62 100644 --- a/src/nvim/ex_getln.h +++ b/src/nvim/ex_getln.h @@ -32,6 +32,7 @@ #define WILD_IGNORE_COMPLETESLASH 0x400 #define WILD_NOERROR 0x800 // sets EW_NOERROR #define WILD_BUFLASTUSED 0x1000 +#define BUF_DIFF_FILTER 0x2000 /// Present history tables typedef enum { diff --git a/src/nvim/ex_session.c b/src/nvim/ex_session.c index 14dac9a126..63789b3981 100644 --- a/src/nvim/ex_session.c +++ b/src/nvim/ex_session.c @@ -384,6 +384,18 @@ static int put_view( xfree(fname_esc); } + if (wp->w_alt_fnum) { + buf_T *const alt = buflist_findnr(wp->w_alt_fnum); + + // Set the alternate file. + if ((flagp == &ssop_flags) && alt != NULL && alt->b_fname != NULL + && *alt->b_fname != NUL + && (fputs("balt ", fd) < 0 + || ses_fname(fd, alt, flagp, true) == FAIL)) { + return FAIL; + } + } + // // Local mappings and abbreviations. // @@ -438,9 +450,9 @@ static int put_view( "let s:l = %" PRId64 " - ((%" PRId64 " * winheight(0) + %" PRId64 ") / %" PRId64 ")\n" "if s:l < 1 | let s:l = 1 | endif\n" - "exe s:l\n" + "keepjumps exe s:l\n" "normal! zt\n" - "%" PRId64 "\n", + "keepjumps %" PRId64 "\n", (int64_t)wp->w_cursor.lnum, (int64_t)(wp->w_cursor.lnum - wp->w_topline), (int64_t)(wp->w_height_inner / 2), diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index a542bb19dd..714bbb5780 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -1644,8 +1644,7 @@ failed: save_file_ff(curbuf); // If editing a new file: set 'fenc' for the current buffer. // Also for ":read ++edit file". - set_string_option_direct((char_u *)"fenc", -1, fenc, - OPT_FREE | OPT_LOCAL, 0); + set_string_option_direct("fenc", -1, fenc, OPT_FREE | OPT_LOCAL, 0); } if (fenc_alloced) xfree(fenc); @@ -2002,7 +2001,7 @@ void set_forced_fenc(exarg_T *eap) { if (eap->force_enc != 0) { char_u *fenc = enc_canonize(eap->cmd + eap->force_enc); - set_string_option_direct((char_u *)"fenc", -1, fenc, OPT_FREE|OPT_LOCAL, 0); + set_string_option_direct("fenc", -1, fenc, OPT_FREE|OPT_LOCAL, 0); xfree(fenc); } } @@ -5077,7 +5076,8 @@ void buf_reload(buf_T *buf, int orig_mode) // Mark all undo states as changed. u_unchanged(curbuf); } - buf_updates_unregister_all(curbuf); + buf_updates_unload(curbuf, true); + curbuf->b_mod_set = true; } } xfree(ea.cmd); diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 0593c16999..5032646d7e 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -2999,7 +2999,6 @@ static void foldlevelDiff(fline_T *flp) static void foldlevelExpr(fline_T *flp) { win_T *win; - int n; int c; linenr_T lnum = flp->lnum + flp->off; @@ -3017,7 +3016,7 @@ static void foldlevelExpr(fline_T *flp) /* KeyTyped may be reset to 0 when calling a function which invokes * do_cmdline(). To make 'foldopen' work correctly restore KeyTyped. */ const bool save_keytyped = KeyTyped; - n = (int)eval_foldexpr(flp->wp->w_p_fde, &c); + const int n = eval_foldexpr(flp->wp->w_p_fde, &c); KeyTyped = save_keytyped; switch (c) { @@ -3202,8 +3201,10 @@ int put_folds(FILE *fd, win_T *wp) { if (foldmethodIsManual(wp)) { if (put_line(fd, "silent! normal! zE") == FAIL - || put_folds_recurse(fd, &wp->w_folds, (linenr_T)0) == FAIL) + || put_folds_recurse(fd, &wp->w_folds, (linenr_T)0) == FAIL + || put_line(fd, "let &fdl = &fdl") == FAIL) { return FAIL; + } } /* If some folds are manually opened/closed, need to restore that. */ diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 22f06941aa..7b8e809de7 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -180,6 +180,11 @@ EXTERN int compl_cont_status INIT(= 0); # define CONT_LOCAL 32 // for ctrl_x_mode 0, ^X^P/^X^N do a local // expansion, (eg use complete=.) +EXTERN char_u *edit_submode INIT(= NULL); // msg for CTRL-X submode +EXTERN char_u *edit_submode_pre INIT(= NULL); // prepended to edit_submode +EXTERN char_u *edit_submode_extra INIT(= NULL); // appended to edit_submode +EXTERN hlf_T edit_submode_highl; // highl. method for extra info + // state for putting characters in the message area EXTERN int cmdmsg_rl INIT(= false); // cmdline is drawn right to left EXTERN int msg_col; @@ -328,9 +333,10 @@ EXTERN int garbage_collect_at_exit INIT(= false); #define SID_ENV -4 // for sourcing environment variable #define SID_ERROR -5 // option was reset because of an error #define SID_NONE -6 // don't set scriptID -#define SID_LUA -7 // for Lua scripts/chunks -#define SID_API_CLIENT -8 // for API clients -#define SID_STR -9 // for sourcing a string +#define SID_WINLAYOUT -7 // changing window size +#define SID_LUA -8 // for Lua scripts/chunks +#define SID_API_CLIENT -9 // for API clients +#define SID_STR -10 // for sourcing a string // Script CTX being sourced or was sourced to define the current function. EXTERN sctx_T current_sctx INIT(= { 0 COMMA 0 COMMA 0 }); @@ -639,10 +645,6 @@ EXTERN int arrow_used; // Normally false, set to true after // to call u_sync() EXTERN bool ins_at_eol INIT(= false); // put cursor after eol when // restarting edit after CTRL-O -EXTERN char_u *edit_submode INIT(= NULL); // msg for CTRL-X submode -EXTERN char_u *edit_submode_pre INIT(= NULL); // prepended to edit_submode -EXTERN char_u *edit_submode_extra INIT(= NULL); // appended to edit_submode -EXTERN hlf_T edit_submode_highl; // highl. method for extra info EXTERN int no_abbr INIT(= true); // true when no abbreviations loaded diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c index 2dad8fb781..31615e744a 100644 --- a/src/nvim/if_cscope.c +++ b/src/nvim/if_cscope.c @@ -1865,7 +1865,7 @@ static void cs_release_csp(size_t i, bool freefnpp) alive = false; // cscope process no longer exists break; } - os_delay(50L, false); // sleep 50ms + os_delay(50L, false); // sleep 50 ms } } if (alive) diff --git a/src/nvim/log.h b/src/nvim/log.h index f2e74df031..17d754c033 100644 --- a/src/nvim/log.h +++ b/src/nvim/log.h @@ -17,10 +17,11 @@ #endif -#define DEBUG_LOG_LEVEL 0 -#define INFO_LOG_LEVEL 1 -#define WARN_LOG_LEVEL 2 -#define ERROR_LOG_LEVEL 3 +#define TRACE_LOG_LEVEL 0 +#define DEBUG_LOG_LEVEL 1 +#define INFO_LOG_LEVEL 2 +#define WARN_LOG_LEVEL 3 +#define ERROR_LOG_LEVEL 4 #define DLOG(...) #define DLOGN(...) diff --git a/src/nvim/lua/vim.lua b/src/nvim/lua/vim.lua index fd53bffe94..eb54ff28ee 100644 --- a/src/nvim/lua/vim.lua +++ b/src/nvim/lua/vim.lua @@ -39,6 +39,16 @@ assert(vim) vim.inspect = package.loaded['vim.inspect'] assert(vim.inspect) +vim.log = { + levels = { + TRACE = 0; + DEBUG = 1; + INFO = 2; + WARN = 3; + ERROR = 4; + } +} + -- Internal-only until comments in #8107 are addressed. -- Returns: -- {errcode}, {output} @@ -485,6 +495,23 @@ function vim.defer_fn(fn, timeout) return timer end + +--- Notification provider +--- without a runtime, writes to :Messages +-- see :help nvim_notify +--@param msg Content of the notification to show to the user +--@param log_level Optional log level +--@param opts Dictionary with optional options (timeout, etc) +function vim.notify(msg, log_level, _opts) + + if log_level == vim.log.levels.ERROR then + vim.api.nvim_err_writeln(msg) + else + vim.api.nvim_echo({{msg}}, true, {}) + end +end + + local on_keystroke_callbacks = {} --- Register a lua {fn} with an {id} to be run after every keystroke. diff --git a/src/nvim/main.c b/src/nvim/main.c index 9f71df3a46..7064f2a068 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -1404,9 +1404,9 @@ static void load_plugins(void) static void handle_quickfix(mparm_T *paramp) { if (paramp->edit_type == EDIT_QF) { - if (paramp->use_ef != NULL) - set_string_option_direct((char_u *)"ef", -1, - paramp->use_ef, OPT_FREE, SID_CARG); + if (paramp->use_ef != NULL) { + set_string_option_direct("ef", -1, paramp->use_ef, OPT_FREE, SID_CARG); + } vim_snprintf((char *)IObuff, IOSIZE, "cfile %s", p_ef); if (qf_init(NULL, p_ef, p_efm, true, IObuff, p_menc) < 0) { msg_putchar('\n'); diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 31dc6b3649..293a4d01db 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -4142,7 +4142,7 @@ void goto_byte(long cnt) if (lnum < 1) { // past the end curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; curwin->w_curswant = MAXCOL; - coladvance((colnr_T)MAXCOL); + coladvance(MAXCOL); } else { curwin->w_cursor.lnum = lnum; curwin->w_cursor.col = (colnr_T)boff; diff --git a/src/nvim/memline_defs.h b/src/nvim/memline_defs.h index 9a6f29a908..dc4755f83d 100644 --- a/src/nvim/memline_defs.h +++ b/src/nvim/memline_defs.h @@ -45,16 +45,16 @@ typedef struct memline { memfile_T *ml_mfp; // pointer to associated memfile + infoptr_T *ml_stack; // stack of pointer blocks (array of IPTRs) + int ml_stack_top; // current top of ml_stack + int ml_stack_size; // total number of entries in ml_stack + #define ML_EMPTY 1 // empty buffer #define ML_LINE_DIRTY 2 // cached line was changed and allocated #define ML_LOCKED_DIRTY 4 // ml_locked was changed #define ML_LOCKED_POS 8 // ml_locked needs positive block number int ml_flags; - infoptr_T *ml_stack; // stack of pointer blocks (array of IPTRs) - int ml_stack_top; // current top of ml_stack - int ml_stack_size; // total number of entries in ml_stack - linenr_T ml_line_lnum; // line number of cached line, 0 if not valid char_u *ml_line_ptr; // pointer to cached line size_t ml_line_offset; // cached byte offset of ml_line_lnum diff --git a/src/nvim/menu.c b/src/nvim/menu.c index 7094d3be90..ac3b7768e6 100644 --- a/src/nvim/menu.c +++ b/src/nvim/menu.c @@ -81,7 +81,7 @@ ex_menu(exarg_T *eap) // kFalse for "menu disable vimmenu_T menuarg; - modes = get_menu_cmd_modes(eap->cmd, eap->forceit, &noremap, &unmenu); + modes = get_menu_cmd_modes((char *)eap->cmd, eap->forceit, &noremap, &unmenu); arg = eap->arg; for (;; ) { @@ -912,7 +912,9 @@ static int expand_emenu; /* TRUE for ":emenu" command */ /* * Work out what to complete when doing command line completion of menu names. */ -char_u *set_context_in_menu_cmd(expand_T *xp, char_u *cmd, char_u *arg, int forceit) +char_u *set_context_in_menu_cmd(expand_T *xp, const char *cmd, char_u *arg, + bool forceit) + FUNC_ATTR_NONNULL_ALL { char_u *after_dot; char_u *p; @@ -1178,7 +1180,7 @@ static bool menu_namecmp(const char_u *const name, const char_u *const mname) /// to whether the command is an "unmenu" command. int get_menu_cmd_modes( - const char_u * cmd, + const char *cmd, bool forceit, int *noremap, int *unmenu diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index fcffe64595..34c43da0f7 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -412,7 +412,7 @@ int plines_win_nofold(win_T *wp, linenr_T lnum) s = ml_get_buf(wp->w_buffer, lnum, FALSE); if (*s == NUL) /* empty line */ return 1; - col = win_linetabsize(wp, s, (colnr_T)MAXCOL); + col = win_linetabsize(wp, s, MAXCOL); // If list mode is on, then the '$' at the end of the line may take up one // extra column. diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c index ff471ea978..f28658aa29 100644 --- a/src/nvim/mouse.c +++ b/src/nvim/mouse.c @@ -72,9 +72,7 @@ int jump_to_mouse(int flags, int row = mouse_row; int col = mouse_col; int grid = mouse_grid; - int mouse_char; int fdc = 0; - ScreenGrid *gp = &default_grid; mouse_past_bottom = false; mouse_past_eol = false; @@ -303,25 +301,6 @@ retnomove: } } - // Remember the character under the mouse, might be one of foldclose or - // foldopen fillchars in the fold column. - if (ui_has(kUIMultigrid)) { - gp = &curwin->w_grid; - } - if (row >= 0 && row < Rows && col >= 0 && col <= Columns - && gp->chars != NULL) { - mouse_char = utf_ptr2char(gp->chars[gp->line_offset[row] - + (unsigned)col]); - } else { - mouse_char = ' '; - } - - // Check for position outside of the fold column. - if (curwin->w_p_rl ? col < curwin->w_width_inner - fdc : - col >= fdc + (cmdwin_type == 0 ? 0 : 1)) { - mouse_char = ' '; - } - // compute the position in the buffer line from the posn on the screen if (mouse_comp_pos(curwin, &row, &col, &curwin->w_cursor.lnum)) { mouse_past_bottom = true; @@ -362,11 +341,7 @@ retnomove: count |= CURSOR_MOVED; // Cursor has moved } - if (mouse_char == curwin->w_p_fcs_chars.foldclosed) { - count |= MOUSE_FOLD_OPEN; - } else if (mouse_char != ' ') { - count |= MOUSE_FOLD_CLOSE; - } + count |= mouse_check_fold(); return count; } @@ -738,3 +713,47 @@ static int mouse_adjust_click(win_T *wp, int row, int col) return col + nudge; } + +// Check clicked cell is foldcolumn +int mouse_check_fold(void) +{ + int grid = mouse_grid; + int row = mouse_row; + int col = mouse_col; + int mouse_char = ' '; + + win_T *wp; + + wp = mouse_find_win(&grid, &row, &col); + + if (wp && mouse_row >= 0 && mouse_row < Rows + && mouse_col >= 0 && mouse_col <= Columns) { + int multigrid = ui_has(kUIMultigrid); + ScreenGrid *gp = multigrid ? &wp->w_grid : &default_grid; + int fdc = win_fdccol_count(wp); + + row = multigrid && mouse_grid == 0 ? row : mouse_row; + col = multigrid && mouse_grid == 0 ? col : mouse_col; + + // Remember the character under the mouse, might be one of foldclose or + // foldopen fillchars in the fold column. + if (gp->chars != NULL) { + mouse_char = utf_ptr2char(gp->chars[gp->line_offset[row] + + (unsigned)col]); + } + + // Check for position outside of the fold column. + if (wp->w_p_rl ? col < wp->w_width_inner - fdc : + col >= fdc + (cmdwin_type == 0 ? 0 : 1)) { + mouse_char = ' '; + } + } + + if (mouse_char == wp->w_p_fcs_chars.foldclosed) { + return MOUSE_FOLD_OPEN; + } else if (mouse_char != ' ') { + return MOUSE_FOLD_CLOSE; + } + + return 0; +} diff --git a/src/nvim/move.c b/src/nvim/move.c index a6afdc27d9..1210a3365a 100644 --- a/src/nvim/move.c +++ b/src/nvim/move.c @@ -888,11 +888,11 @@ void curs_columns( } else { n = plines; } - if ((colnr_T)n >= wp->w_height_inner + wp->w_skipcol / width) { + if ((colnr_T)n >= wp->w_height_inner + wp->w_skipcol / width - so) { extra += 2; } - if (extra == 3 || plines < so * 2) { + if (extra == 3 || plines <= so * 2) { // not enough room for 'scrolloff', put cursor in the middle n = wp->w_virtcol / width; if (n > wp->w_height_inner / 2) { diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 8f22243348..0b4e2e1f23 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -2404,8 +2404,8 @@ do_mouse ( start_visual.lnum = 0; - /* Check for clicking in the tab page line. */ - if (mouse_row == 0 && firstwin->w_winrow > 0) { + // Check for clicking in the tab page line. + if (mouse_grid <= 1 && mouse_row == 0 && firstwin->w_winrow > 0) { if (is_drag) { if (in_tab_line) { move_tab_to_mouse(); @@ -5225,16 +5225,13 @@ static void nv_left(cmdarg_T *cap) * 'h' wraps to previous line if 'whichwrap' has 'h'. * CURS_LEFT wraps to previous line if 'whichwrap' has '<'. */ - if ( (((cap->cmdchar == K_BS - || cap->cmdchar == Ctrl_H) - && vim_strchr(p_ww, 'b') != NULL) - || (cap->cmdchar == 'h' - && vim_strchr(p_ww, 'h') != NULL) - || (cap->cmdchar == K_LEFT - && vim_strchr(p_ww, '<') != NULL)) - && curwin->w_cursor.lnum > 1) { - --(curwin->w_cursor.lnum); - coladvance((colnr_T)MAXCOL); + if ((((cap->cmdchar == K_BS || cap->cmdchar == Ctrl_H) + && vim_strchr(p_ww, 'b') != NULL) + || (cap->cmdchar == 'h' && vim_strchr(p_ww, 'h') != NULL) + || (cap->cmdchar == K_LEFT && vim_strchr(p_ww, '<') != NULL)) + && curwin->w_cursor.lnum > 1) { + curwin->w_cursor.lnum--; + coladvance(MAXCOL); curwin->w_set_curswant = true; // When the NL before the first char has to be deleted we @@ -5792,16 +5789,20 @@ static void nv_percent(cmdarg_T *cap) } else { cap->oap->motion_type = kMTLineWise; setpcmark(); - /* Round up, so CTRL-G will give same value. Watch out for a - * large line count, the line number must not go negative! */ - if (curbuf->b_ml.ml_line_count > 1000000) + // Round up, so 'normal 100%' always jumps at the line line. + // Beyond 21474836 lines, (ml_line_count * 100 + 99) would + // overflow on 32-bits, so use a formula with less accuracy + // to avoid overflows. + if (curbuf->b_ml.ml_line_count >= 21474836) { curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count + 99L) / 100L * cap->count0; - else + } else { curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count * cap->count0 + 99L) / 100L; - if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) + } + if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) { curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; + } beginline(BL_SOL | BL_FIX); } } else { // "%" : go to matching paren @@ -6467,7 +6468,7 @@ static void nv_visual(cmdarg_T *cap) } if (resel_VIsual_vcol == MAXCOL) { curwin->w_curswant = MAXCOL; - coladvance((colnr_T)MAXCOL); + coladvance(MAXCOL); } else if (VIsual_mode == Ctrl_V) { validate_virtcol(); assert(cap->count0 >= INT_MIN && cap->count0 <= INT_MAX); @@ -7570,6 +7571,12 @@ static void nv_esc(cmdarg_T *cap) got_int = false; /* don't stop executing autocommands et al. */ return; } + } else if (cmdwin_type != 0 && ex_normal_busy) { + // When :normal runs out of characters while in the command line window + // vgetorpeek() will return ESC. Exit the cmdline window to break the + // loop. + cmdwin_result = K_IGNORE; + return; } if (VIsual_active) { @@ -7600,7 +7607,7 @@ void set_cursor_for_append_to_line(void) // Pretend Insert mode here to allow the cursor on the // character past the end of the line State = INSERT; - coladvance((colnr_T)MAXCOL); + coladvance(MAXCOL); State = save_State; } else { curwin->w_cursor.col += (colnr_T)STRLEN(get_cursor_pos_ptr()); @@ -7988,7 +7995,7 @@ static void nv_put_opt(cmdarg_T *cap, bool fix_indent) * line. */ if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) { curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; - coladvance((colnr_T)MAXCOL); + coladvance(MAXCOL); } } auto_format(false, true); @@ -8096,7 +8103,7 @@ static void nv_event(cmdarg_T *cap) // lists or dicts being used. may_garbage_collect = false; bool may_restart = (restart_edit != 0); - multiqueue_process_events(main_loop.events); + state_handle_k_event(); finish_op = false; if (may_restart) { // Tricky: if restart_edit was set before the handler we are in ctrl-o mode, diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 87d092281a..3038fad894 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -3422,15 +3422,11 @@ error: if (dir == FORWARD) curbuf->b_op_start.lnum++; } - // Skip mark_adjust when adding lines after the last one, there - // can't be marks there. - if (curbuf->b_op_start.lnum + (y_type == kMTCharWise) - 1 + nr_lines - < curbuf->b_ml.ml_line_count) { - ExtmarkOp kind = (y_type == kMTLineWise && !(flags & PUT_LINE_SPLIT)) - ? kExtmarkUndo : kExtmarkNOOP; - mark_adjust(curbuf->b_op_start.lnum + (y_type == kMTCharWise), - (linenr_T)MAXLNUM, nr_lines, 0L, kind); - } + + ExtmarkOp kind = (y_type == kMTLineWise && !(flags & PUT_LINE_SPLIT)) + ? kExtmarkUndo : kExtmarkNOOP; + mark_adjust(curbuf->b_op_start.lnum + (y_type == kMTCharWise), + (linenr_T)MAXLNUM, nr_lines, 0L, kind); // note changed text for displaying and folding if (y_type == kMTCharWise) { @@ -4309,11 +4305,12 @@ format_lines( * tabs and spaces, according to current options */ (void)set_indent(get_indent(), SIN_CHANGED); - /* put cursor on last non-space */ - State = NORMAL; /* don't go past end-of-line */ - coladvance((colnr_T)MAXCOL); - while (curwin->w_cursor.col && ascii_isspace(gchar_cursor())) + // put cursor on last non-space + State = NORMAL; // don't go past end-of-line + coladvance(MAXCOL); + while (curwin->w_cursor.col && ascii_isspace(gchar_cursor())) { dec_cursor(); + } /* do the formatting, without 'showmode' */ State = INSERT; /* for open_line() */ diff --git a/src/nvim/option.c b/src/nvim/option.c index 74bf6f0590..ac25c86b5f 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1942,6 +1942,7 @@ static void didset_options(void) (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, true); (void)opt_strings_flags(p_rdb, p_rdb_values, &rdb_flags, true); (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, false); + (void)opt_strings_flags(p_tpf, p_tpf_values, &tpf_flags, true); (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, true); (void)opt_strings_flags(p_wop, p_wop_values, &wop_flags, true); (void)opt_strings_flags(p_jop, p_jop_values, &jop_flags, true); @@ -2119,9 +2120,9 @@ static int shada_idx = -1; // "set_sid". void set_string_option_direct( - char_u *name, + const char *name, int opt_idx, - char_u *val, + const char_u *val, int opt_flags, // OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL int set_sid ) @@ -2132,7 +2133,7 @@ set_string_option_direct( int idx = opt_idx; if (idx == -1) { // Use name. - idx = findoption((const char *)name); + idx = findoption(name); if (idx < 0) { // Not found (should not happen). internal_error("set_string_option_direct()"); IEMSG2(_("For option %s"), name); @@ -3077,6 +3078,10 @@ ambw_end: if (!parse_winhl_opt(curwin)) { errmsg = e_invarg; } + } else if (varp == &p_tpf) { + if (opt_strings_flags(p_tpf, p_tpf_values, &tpf_flags, true) != OK) { + errmsg = e_invarg; + } } else { // Options that are a list of flags. p = NULL; @@ -3786,7 +3791,7 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, if (p_terse && p == NULL) { STRCPY(IObuff, p_shm); STRCAT(IObuff, "s"); - set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0); + set_string_option_direct("shm", -1, IObuff, OPT_FREE, 0); } else if (!p_terse && p != NULL) { // remove 's' from p_shm STRMOVE(p, p + 1); } @@ -4526,7 +4531,7 @@ bool is_tty_option(const char *name) #define TCO_BUFFER_SIZE 8 /// @param name TUI-related option /// @param[out,allocated] value option string value -bool get_tty_option(char *name, char **value) +bool get_tty_option(const char *name, char **value) { if (strequal(name, "t_Co")) { if (value) { @@ -4592,6 +4597,7 @@ bool set_tty_option(const char *name, char *value) /// /// @return Option index or -1 if option was not found. static int findoption(const char *const arg) + FUNC_ATTR_NONNULL_ALL { return findoption_len(arg, strlen(arg)); } @@ -4605,17 +4611,17 @@ static int findoption(const char *const arg) /// hidden String option: -2. /// unknown option: -3. int get_option_value( - char_u *name, + const char *name, long *numval, char_u **stringval, ///< NULL when only checking existence int opt_flags ) { - if (get_tty_option((char *)name, (char **)stringval)) { + if (get_tty_option(name, (char **)stringval)) { return 0; } - int opt_idx = findoption((const char *)name); + int opt_idx = findoption(name); if (opt_idx < 0) { // Unknown option. return -3; } @@ -7049,7 +7055,7 @@ void set_fileformat(int eol_style, int opt_flags) // p is NULL if "eol_style" is EOL_UNKNOWN. if (p != NULL) { - set_string_option_direct((char_u *)"ff", + set_string_option_direct("ff", -1, (char_u *)p, OPT_FREE | opt_flags, diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h index 683afc670e..43b0107800 100644 --- a/src/nvim/option_defs.h +++ b/src/nvim/option_defs.h @@ -621,6 +621,19 @@ EXTERN int p_sta; // 'smarttab' EXTERN int p_sb; // 'splitbelow' EXTERN long p_tpm; // 'tabpagemax' EXTERN char_u *p_tal; // 'tabline' +EXTERN char_u *p_tpf; // 'termpastefilter' +EXTERN unsigned int tpf_flags; ///< flags from 'termpastefilter' +#ifdef IN_OPTION_C +static char *(p_tpf_values[]) = + { "BS", "HT", "FF", "ESC", "DEL", "C0", "C1", NULL }; +#endif +# define TPF_BS 0x001 +# define TPF_HT 0x002 +# define TPF_FF 0x004 +# define TPF_ESC 0x008 +# define TPF_DEL 0x010 +# define TPF_C0 0x020 +# define TPF_C1 0x040 EXTERN char_u *p_sps; // 'spellsuggest' EXTERN int p_spr; // 'splitright' EXTERN int p_sol; // 'startofline' diff --git a/src/nvim/options.lua b/src/nvim/options.lua index df2bfbce34..fe108ef1cc 100644 --- a/src/nvim/options.lua +++ b/src/nvim/options.lua @@ -2821,6 +2821,14 @@ return { defaults={if_true={vi=false}} }, { + full_name='termpastefilter', abbreviation='tpf', + type='string', list='onecomma', scope={'global'}, + deny_duplicates=true, + vim=true, + varname='p_tpf', + defaults={if_true={vi="", vim="BS,HT,ESC,DEL"}} + }, + { full_name='terse', short_desc=N_("hides notification of search wrap"), type='bool', scope={'global'}, diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index 9d6518841a..eca245650a 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -159,16 +159,28 @@ bool os_char_avail(void) return inbuf_poll(0, NULL) == kInputAvail; } -// Check for CTRL-C typed by reading all available characters. +/// Poll for fast events. `got_int` will be set to `true` if CTRL-C was typed. +/// +/// This invokes a full libuv loop iteration which can be quite costly. +/// Prefer `line_breakcheck()` if called in a busy inner loop. +/// +/// Caller must at least check `got_int` before calling this function again. +/// checking for other low-level input state like `input_available()` might +/// also be relevant (i e to throttle idle processing when user input is +/// available) void os_breakcheck(void) { + if (got_int) { + return; + } + int save_us = updating_screen; // We do not want screen_resize() to redraw here. + // TODO(bfredl): we are already special casing redraw events, is this + // hack still needed? updating_screen++; - if (!got_int) { - loop_poll_events(&main_loop, 0); - } + loop_poll_events(&main_loop, 0); updating_screen = save_us; } diff --git a/src/nvim/os/pty_process_unix.c b/src/nvim/os/pty_process_unix.c index 348a139e79..d794969ab5 100644 --- a/src/nvim/os/pty_process_unix.c +++ b/src/nvim/os/pty_process_unix.c @@ -182,8 +182,6 @@ static void init_child(PtyProcess *ptyproc) char *prog = ptyproc->process.argv[0]; assert(proc->env); - tv_dict_add_str(proc->env, S_LEN("TERM"), - ptyproc->term_name ? ptyproc->term_name : "ansi"); environ = tv_dict_to_env(proc->env); execvp(prog, proc->argv); ELOG("execvp failed: %s: %s", strerror(errno), prog); diff --git a/src/nvim/os/pty_process_unix.h b/src/nvim/os/pty_process_unix.h index f7c57b3839..8c822eafad 100644 --- a/src/nvim/os/pty_process_unix.h +++ b/src/nvim/os/pty_process_unix.h @@ -17,7 +17,6 @@ static inline PtyProcess pty_process_init(Loop *loop, void *data) { PtyProcess rv; rv.process = process_init(loop, kProcessTypePty, data); - rv.term_name = NULL; rv.width = 80; rv.height = 24; rv.tty_fd = -1; diff --git a/src/nvim/os/pty_process_win.h b/src/nvim/os/pty_process_win.h index 8ad5ba7286..f8ec79a3d6 100644 --- a/src/nvim/os/pty_process_win.h +++ b/src/nvim/os/pty_process_win.h @@ -37,7 +37,6 @@ static inline PtyProcess pty_process_init(Loop *loop, void *data) { PtyProcess rv; rv.process = process_init(loop, kProcessTypePty, data); - rv.term_name = NULL; rv.width = 80; rv.height = 24; rv.object.winpty = NULL; diff --git a/src/nvim/path.c b/src/nvim/path.c index 2de7e00ddb..3e1713fbdd 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -342,7 +342,7 @@ int path_fnamencmp(const char *const fname1, const char *const fname2, p1 += utfc_ptr2len((const char_u *)p1); p2 += utfc_ptr2len((const char_u *)p2); } - return c1 - c2; + return p_fic ? CH_FOLD(c1) - CH_FOLD(c2) : c1 - c2; #else if (p_fic) { return mb_strnicmp((const char_u *)fname1, (const char_u *)fname2, len); diff --git a/src/nvim/pos.h b/src/nvim/pos.h index 8e86ea08c5..b7c4b6ef92 100644 --- a/src/nvim/pos.h +++ b/src/nvim/pos.h @@ -1,6 +1,9 @@ #ifndef NVIM_POS_H #define NVIM_POS_H +// for INT_MAX, LONG_MAX et al. +#include <limits.h> + typedef long linenr_T; // line number type /// Format used to print values which have linenr_T type #define PRIdLINENR "ld" @@ -12,8 +15,8 @@ typedef int colnr_T; /// Maximal (invalid) line number enum { MAXLNUM = 0x7fffffff }; -/// Maximal column number, 31 bits -enum { MAXCOL = 0x7fffffff }; +/// Maximal column number +enum { MAXCOL = INT_MAX }; // Minimum line number enum { MINLNUM = 1 }; // minimum column number diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index e074f73d04..dfd38a6eca 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -3665,7 +3665,7 @@ static int qf_open_new_cwindow(qf_info_T *qi, int height) static void qf_set_title_var(qf_list_T *qfl) { if (qfl->qf_title != NULL) { - set_internal_string_var((char_u *)"w:quickfix_title", qfl->qf_title); + set_internal_string_var("w:quickfix_title", qfl->qf_title); } } @@ -4951,7 +4951,7 @@ void ex_cfile(exarg_T *eap) } } if (*eap->arg != NUL) { - set_string_option_direct((char_u *)"ef", -1, eap->arg, OPT_FREE, 0); + set_string_option_direct("ef", -1, eap->arg, OPT_FREE, 0); } char_u *enc = (*curbuf->b_p_menc != NUL) ? curbuf->b_p_menc : p_menc; diff --git a/src/nvim/screen.c b/src/nvim/screen.c index a78f905a70..20e3cc0a2e 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -143,7 +143,7 @@ long tab_page_click_defs_size = 0; // for line_putchar. Contains the state that needs to be remembered from // putting one character to the next. typedef struct { - const char_u *p; + const char *p; int prev_c; // previous Arabic character int prev_c1; // first composing char for prev_c } LineState; @@ -1857,7 +1857,7 @@ static int compute_foldcolumn(win_T *wp, int col) /// Handles composing chars and arabic shaping state. static int line_putchar(LineState *s, schar_T *dest, int maxcells, bool rl) { - const char_u *p = s->p; + const char_u *p = (char_u *)s->p; int cells = utf_ptr2cells(p); int c_len = utfc_ptr2len(p); int u8c, u8cc[MAX_MCO]; @@ -2082,7 +2082,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int line_attr_lowprio = 0; // low-priority attribute for the line matchitem_T *cur; // points to the match list match_T *shl; // points to search_hl or a match - int shl_flag; // flag to indicate whether search_hl + bool shl_flag; // flag to indicate whether search_hl // has been processed or not bool prevcol_hl_flag; // flag to indicate whether prevcol // equals startcol of search_hl or one @@ -2870,6 +2870,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, && vcol >= (long)wp->w_virtcol) || (number_only && draw_state > WL_NR)) && filler_todo <= 0) { + draw_virt_text(buf, &col, grid->Columns); grid_put_linebuf(grid, row, 0, col, -grid->Columns, wp->w_p_rl, wp, wp->w_hl_attr_normal, false); // Pretend we have finished updating the window. Except when @@ -2950,16 +2951,15 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, */ v = (long)(ptr - line); cur = wp->w_match_head; - shl_flag = FALSE; - while (cur != NULL || shl_flag == FALSE) { - if (shl_flag == FALSE - && ((cur != NULL - && cur->priority > SEARCH_HL_PRIORITY) - || cur == NULL)) { + shl_flag = false; + while (cur != NULL || !shl_flag) { + if (!shl_flag + && (cur == NULL || cur->priority > SEARCH_HL_PRIORITY)) { shl = &search_hl; - shl_flag = TRUE; - } else + shl_flag = true; + } else { shl = &cur->hl; + } if (cur != NULL) { cur->pos.cur = 0; } @@ -2984,7 +2984,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, has_match_conc = v == (long)shl->startcol ? 2 : 1; match_conc = cur->conceal_char; } else { - has_match_conc = match_conc = 0; + has_match_conc = 0; } } else if (v == (long)shl->endcol) { shl->attr_cur = 0; @@ -3026,16 +3026,15 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, search_attr_from_match = false; search_attr = search_hl.attr_cur; cur = wp->w_match_head; - shl_flag = FALSE; - while (cur != NULL || shl_flag == FALSE) { - if (shl_flag == FALSE - && ((cur != NULL - && cur->priority > SEARCH_HL_PRIORITY) - || cur == NULL)) { + shl_flag = false; + while (cur != NULL || !shl_flag) { + if (!shl_flag + && (cur == NULL || cur->priority > SEARCH_HL_PRIORITY)) { shl = &search_hl; - shl_flag = TRUE; - } else + shl_flag = true; + } else { shl = &cur->hl; + } if (shl->attr_cur != 0) { search_attr = shl->attr_cur; search_attr_from_match = shl != &search_hl; @@ -3048,6 +3047,12 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, && (wp->w_p_list && lcs_eol_one == -1)) { search_attr = 0; } + + // Do not allow a conceal over EOL otherwise EOL will be missed + // and bad things happen. + if (*ptr == NUL) { + has_match_conc = 0; + } } if (diff_hlf != (hlf_T)0) { @@ -3393,7 +3398,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, } if (has_decor && v > 0) { - int extmark_attr = decor_redraw_col(wp->w_buffer, (colnr_T)v-1, + int extmark_attr = decor_redraw_col(wp->w_buffer, (colnr_T)v-1, off, &decor_state); if (extmark_attr != 0) { if (!attr_pri) { @@ -3672,12 +3677,13 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, && vim_strchr(wp->w_p_cocu, 'v') == NULL)) { char_attr = conceal_attr; if ((prev_syntax_id != syntax_seqnr || has_match_conc > 1) - && (syn_get_sub_char() != NUL || match_conc + && (syn_get_sub_char() != NUL + || (has_match_conc && match_conc) || wp->w_p_cole == 1) && wp->w_p_cole != 3) { // First time at this concealed item: display one // character. - if (match_conc) { + if (has_match_conc && match_conc) { c = match_conc; } else if (syn_get_sub_char() != NUL) { c = syn_get_sub_char(); @@ -3837,16 +3843,15 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, // 'search_hl' and the match list. char_attr = search_hl.attr; cur = wp->w_match_head; - shl_flag = FALSE; - while (cur != NULL || shl_flag == FALSE) { - if (shl_flag == FALSE - && ((cur != NULL - && cur->priority > SEARCH_HL_PRIORITY) - || cur == NULL)) { + shl_flag = false; + while (cur != NULL || !shl_flag) { + if (!shl_flag + && (cur == NULL || cur->priority > SEARCH_HL_PRIORITY)) { shl = &search_hl; - shl_flag = TRUE; - } else + shl_flag = true; + } else { shl = &cur->hl; + } if ((ptr - line) - 1 == (long)shl->startcol && (shl == &search_hl || !shl->is_addpos)) { char_attr = shl->attr; @@ -3915,7 +3920,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int i; size_t virt_pos = 0; - LineState s = LINE_STATE((char_u *)""); + LineState s = LINE_STATE(""); int virt_attr = 0; // Make sure alignment is the same regardless @@ -3959,7 +3964,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, if (do_virttext && !delay_virttext) { if (*s.p == NUL) { if (virt_pos < virt_text.size) { - s.p = (char_u *)kv_A(virt_text, virt_pos).text; + s.p = kv_A(virt_text, virt_pos).text; int hl_id = kv_A(virt_text, virt_pos).hl_id; virt_attr = hl_id > 0 ? syn_id2attr(hl_id) : 0; virt_pos++; @@ -4025,6 +4030,8 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, col += n; } } + + draw_virt_text(buf, &col, grid->Columns); grid_put_linebuf(grid, row, 0, col, grid->Columns, wp->w_p_rl, wp, wp->w_hl_attr_normal, false); row++; @@ -4243,7 +4250,10 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, && (grid->Columns == Columns // Window spans the width of the screen, || ui_has(kUIMultigrid)) // or has dedicated grid. && !wp->w_p_rl; // Not right-to-left. - grid_put_linebuf(grid, row, 0, col - boguscols, grid->Columns, wp->w_p_rl, + + int draw_col = col - boguscols; + draw_virt_text(buf, &draw_col, grid->Columns); + grid_put_linebuf(grid, row, 0, draw_col, grid->Columns, wp->w_p_rl, wp, wp->w_hl_attr_normal, wrap); if (wrap) { ScreenGrid *current_grid = grid; @@ -4319,6 +4329,43 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, return row; } +void draw_virt_text(buf_T *buf, int *end_col, int max_col) +{ + DecorState *state = &decor_state; + for (size_t i = 0; i < kv_size(state->active); i++) { + HlRange *item = &kv_A(state->active, i); + if (item->start_row == state->row && item->virt_text + && item->virt_text_pos == kVTOverlay + && item->virt_col >= 0) { + VirtText vt = *item->virt_text; + LineState s = LINE_STATE(""); + int virt_attr = 0; + int col = item->virt_col; + size_t virt_pos = 0; + item->virt_col = -2; // deactivate + + while (col < max_col) { + if (!*s.p) { + if (virt_pos == kv_size(vt)) { + break; + } + s.p = kv_A(vt, virt_pos).text; + int hl_id = kv_A(vt, virt_pos).hl_id; + virt_attr = hl_id > 0 ? syn_id2attr(hl_id) : 0; + virt_pos++; + continue; + } + int cells = line_putchar(&s, &linebuf_char[col], 2, false); + linebuf_attr[col++] = virt_attr; + if (cells > 1) { + linebuf_attr[col++] = virt_attr; + } + } + *end_col = MAX(*end_col, col); + } + } +} + /// Determine if dedicated window grid should be used or the default_grid /// /// If UI did not request multigrid support, draw all windows on the @@ -5092,9 +5139,9 @@ static void redraw_custom_statusline(win_T *wp) // When there is an error disable the statusline, otherwise the // display is messed up with errors and a redraw triggers the problem // again and again. - set_string_option_direct((char_u *)"statusline", -1, - (char_u *)"", OPT_FREE | (*wp->w_p_stl != NUL - ? OPT_LOCAL : OPT_GLOBAL), SID_ERROR); + set_string_option_direct("statusline", -1, (char_u *)"", + OPT_FREE | (*wp->w_p_stl != NUL + ? OPT_LOCAL : OPT_GLOBAL), SID_ERROR); } did_emsg |= saved_did_emsg; entered = false; @@ -5175,7 +5222,7 @@ get_keymap_str ( static void win_redr_custom ( win_T *wp, - int draw_ruler /* TRUE or FALSE */ + bool draw_ruler ) { static int entered = FALSE; @@ -6852,7 +6899,7 @@ void draw_tabline(void) did_emsg = false; win_redr_custom(NULL, false); if (did_emsg) { - set_string_option_direct((char_u *)"tabline", -1, + set_string_option_direct("tabline", -1, (char_u *)"", OPT_FREE, SID_ERROR); } did_emsg |= saved_did_emsg; @@ -7105,20 +7152,23 @@ static void win_redr_ruler(win_T *wp, int always) if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) return; - /* Don't draw the ruler while doing insert-completion, it might overwrite - * the (long) mode message. */ - if (wp == lastwin && lastwin->w_status_height == 0) - if (edit_submode != NULL) + // Don't draw the ruler while doing insert-completion, it might overwrite + // the (long) mode message. + if (wp == lastwin && lastwin->w_status_height == 0) { + if (edit_submode != NULL) { return; + } + } if (*p_ruf) { int save_called_emsg = called_emsg; - called_emsg = FALSE; - win_redr_custom(wp, TRUE); - if (called_emsg) - set_string_option_direct((char_u *)"rulerformat", -1, - (char_u *)"", OPT_FREE, SID_ERROR); + called_emsg = false; + win_redr_custom(wp, true); + if (called_emsg) { + set_string_option_direct("rulerformat", -1, (char_u *)"", + OPT_FREE, SID_ERROR); + } called_emsg |= save_called_emsg; return; } diff --git a/src/nvim/search.c b/src/nvim/search.c index 2802da6f7f..84b71d56a0 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -2685,8 +2685,9 @@ fwd_word( while (--count >= 0) { /* When inside a range of folded lines, move to the last char of the * last line. */ - if (hasFolding(curwin->w_cursor.lnum, NULL, &curwin->w_cursor.lnum)) - coladvance((colnr_T)MAXCOL); + if (hasFolding(curwin->w_cursor.lnum, NULL, &curwin->w_cursor.lnum)) { + coladvance(MAXCOL); + } sclass = cls(); /* @@ -2803,8 +2804,9 @@ int end_word(long count, int bigword, int stop, int empty) while (--count >= 0) { /* When inside a range of folded lines, move to the last char of the * last line. */ - if (hasFolding(curwin->w_cursor.lnum, NULL, &curwin->w_cursor.lnum)) - coladvance((colnr_T)MAXCOL); + if (hasFolding(curwin->w_cursor.lnum, NULL, &curwin->w_cursor.lnum)) { + coladvance(MAXCOL); + } sclass = cls(); if (inc_cursor() == -1) return FAIL; diff --git a/src/nvim/sign_defs.h b/src/nvim/sign_defs.h index c898dba890..19c0263cf1 100644 --- a/src/nvim/sign_defs.h +++ b/src/nvim/sign_defs.h @@ -24,11 +24,11 @@ typedef struct signlist signlist_T; struct signlist { int id; // unique identifier for each placed sign - linenr_T lnum; // line number which has this sign int typenr; // typenr of sign + int priority; // priority for highlighting bool has_text_or_icon; // has text or icon + linenr_T lnum; // line number which has this sign signgroup_T *group; // sign group - int priority; // priority for highlighting signlist_T *next; // next signlist entry signlist_T *prev; // previous entry -- for easy reordering }; diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 6425c9fed5..55f9594de2 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -112,6 +112,7 @@ #include "nvim/strings.h" #include "nvim/syntax.h" #include "nvim/undo.h" +#include "nvim/ui.h" #include "nvim/os/os.h" #include "nvim/os/input.h" @@ -2889,8 +2890,14 @@ void spell_suggest(int count) msg_col = 0; // Ask for choice. selected = prompt_for_number(&mouse_used); - if (mouse_used) + + if (ui_has(kUIMessages)) { + ui_call_msg_clear(); + } + + if (mouse_used) { selected -= lines_left; + } lines_left = Rows; // avoid more prompt // don't delay for 'smd' in normal_cmd() msg_scroll = msg_scroll_save; @@ -6624,7 +6631,7 @@ void ex_spelldump(exarg_T *eap) if (no_spell_checking(curwin)) { return; } - get_option_value((char_u *)"spl", &dummy, &spl, OPT_LOCAL); + get_option_value("spl", &dummy, &spl, OPT_LOCAL); // Create a new empty buffer in a new window. do_cmdline_cmd("new"); diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 90af010164..3c125959a9 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -5387,7 +5387,8 @@ spell_add_word ( len, word, NameBuff); } } - if (fseek(fd, fpos_next, SEEK_SET) <= 0) { + if (fseek(fd, fpos_next, SEEK_SET) != 0) { + PERROR(_("Seek error in spellfile")); break; } } diff --git a/src/nvim/state.c b/src/nvim/state.c index b195c1d96b..a3c74789d1 100644 --- a/src/nvim/state.c +++ b/src/nvim/state.c @@ -75,6 +75,34 @@ getkey: } } +/// process events on main_loop, but interrupt if input is available +/// +/// This should be used to handle K_EVENT in states accepting input +/// otherwise bursts of events can block break checking indefinitely. +void state_handle_k_event(void) +{ + while (true) { + Event event = multiqueue_get(main_loop.events); + if (event.handler) { + event.handler(event.argv); + } + + if (multiqueue_empty(main_loop.events)) { + // don't breakcheck before return, caller should return to main-loop + // and handle input already. + return; + } + + // TODO(bfredl): as an further micro-optimization, we could check whether + // event.handler already checked input. + os_breakcheck(); + if (input_available() || got_int) { + return; + } + } +} + + /// Return true if in the current mode we need to use virtual. bool virtual_active(void) { diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index f99eca7953..547d953be9 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -3419,7 +3419,7 @@ static void syn_cmd_on(exarg_T *eap, int syncing) */ static void syn_cmd_enable(exarg_T *eap, int syncing) { - set_internal_string_var((char_u *)"syntax_cmd", (char_u *)"enable"); + set_internal_string_var("syntax_cmd", (char_u *)"enable"); syn_cmd_onoff(eap, "syntax"); do_unlet(S_LEN("g:syntax_cmd"), true); } @@ -3432,7 +3432,7 @@ static void syn_cmd_reset(exarg_T *eap, int syncing) { eap->nextcmd = check_nextcmd(eap->arg); if (!eap->skip) { - set_internal_string_var((char_u *)"syntax_cmd", (char_u *)"reset"); + set_internal_string_var("syntax_cmd", (char_u *)"reset"); do_cmdline_cmd("runtime! syntax/syncolor.vim"); do_unlet(S_LEN("g:syntax_cmd"), true); } @@ -5614,14 +5614,14 @@ void ex_ownsyntax(exarg_T *eap) // Move value of b:current_syntax to w:current_syntax. new_value = get_var_value("b:current_syntax"); if (new_value != NULL) { - set_internal_string_var((char_u *)"w:current_syntax", new_value); + set_internal_string_var("w:current_syntax", new_value); } // Restore value of b:current_syntax. if (old_value == NULL) { do_unlet(S_LEN("b:current_syntax"), true); } else { - set_internal_string_var((char_u *)"b:current_syntax", old_value); + set_internal_string_var("b:current_syntax", old_value); xfree(old_value); } } diff --git a/src/nvim/tag.c b/src/nvim/tag.c index 84ca240734..4ea298fba9 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -3152,7 +3152,7 @@ int get_tags(list_T *list, char_u *pat, char_u *buf_fname) bool is_static; ret = find_tags(pat, &num_matches, &matches, - TAG_REGEXP | TAG_NOIC, (int)MAXCOL, buf_fname); + TAG_REGEXP | TAG_NOIC, MAXCOL, buf_fname); if (ret == OK && num_matches > 0) { for (i = 0; i < num_matches; ++i) { int parse_result = parse_match(matches[i], &tp); diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 39e2ca6171..f6995cddb6 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -457,7 +457,7 @@ static int terminal_execute(VimState *state, int key) case K_EVENT: // We cannot let an event free the terminal yet. It is still needed. s->term->refcount++; - multiqueue_process_events(main_loop.events); + state_handle_k_event(); s->term->refcount--; if (s->term->buf_handle == 0) { s->close = true; @@ -535,8 +535,44 @@ void terminal_send(Terminal *term, char *data, size_t size) term->opts.write_cb(data, size, term->opts.data); } +static bool is_filter_char(int c) +{ + unsigned int flag = 0; + switch (c) { + case 0x08: + flag = TPF_BS; + break; + case 0x09: + flag = TPF_HT; + break; + case 0x0A: + case 0x0D: + break; + case 0x0C: + flag = TPF_FF; + break; + case 0x1b: + flag = TPF_ESC; + break; + case 0x7F: + flag = TPF_DEL; + break; + default: + if (c < ' ') { + flag = TPF_C0; + } else if (c >= 0x80 && c <= 0x9F) { + flag = TPF_C1; + } + } + return !!(tpf_flags & flag); +} + void terminal_paste(long count, char_u **y_array, size_t y_size) { + vterm_keyboard_start_paste(curbuf->terminal->vt); + terminal_flush_output(curbuf->terminal); + size_t buff_len = STRLEN(y_array[0]); + char_u *buff = xmalloc(buff_len); for (int i = 0; i < count; i++) { // -V756 // feed the lines to the terminal for (size_t j = 0; j < y_size; j++) { @@ -544,9 +580,28 @@ void terminal_paste(long count, char_u **y_array, size_t y_size) // terminate the previous line terminal_send(curbuf->terminal, "\n", 1); } - terminal_send(curbuf->terminal, (char *)y_array[j], STRLEN(y_array[j])); + size_t len = STRLEN(y_array[j]); + if (len > buff_len) { + buff = xrealloc(buff, len); + buff_len = len; + } + char_u *dst = buff; + char_u *src = y_array[j]; + while (*src != '\0') { + len = (size_t)utf_ptr2len(src); + int c = utf_ptr2char(src); + if (!is_filter_char(c)) { + memcpy(dst, src, len); + dst += len; + } + src += len; + } + terminal_send(curbuf->terminal, (char *)buff, (size_t)(dst - buff)); } } + xfree(buff); + vterm_keyboard_end_paste(curbuf->terminal->vt); + terminal_flush_output(curbuf->terminal); } void terminal_flush_output(Terminal *term) diff --git a/src/nvim/testdir/test_alot.vim b/src/nvim/testdir/test_alot.vim index 4f056abdc0..daf3c9c110 100644 --- a/src/nvim/testdir/test_alot.vim +++ b/src/nvim/testdir/test_alot.vim @@ -37,7 +37,6 @@ source test_recover.vim source test_scroll_opt.vim source test_sort.vim source test_sha256.vim -source test_statusline.vim source test_suspend.vim source test_syn_attr.vim source test_tabline.vim diff --git a/src/nvim/testdir/test_arglist.vim b/src/nvim/testdir/test_arglist.vim index 92fedf9bfb..a1ef8325ec 100644 --- a/src/nvim/testdir/test_arglist.vim +++ b/src/nvim/testdir/test_arglist.vim @@ -80,6 +80,24 @@ func Test_argadd() call assert_equal(0, len(argv())) endfunc +func Test_argadd_empty_curbuf() + new + let curbuf = bufnr('%') + call writefile(['test', 'Xargadd'], 'Xargadd') + " must not re-use the current buffer. + argadd Xargadd + call assert_equal(curbuf, bufnr('%')) + call assert_equal('', bufname('%')) + call assert_equal(1, line('$')) + rew + call assert_notequal(curbuf, bufnr('%')) + call assert_equal('Xargadd', bufname('%')) + call assert_equal(2, line('$')) + + %argd + bwipe! +endfunc + func Init_abc() args a b c next diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 374ad65aa9..1f3a45a9ab 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -1939,4 +1939,15 @@ func Test_autocmd_window() %bw! endfunc +func Test_autocmd_closes_window() + au BufNew,BufWinLeave * e %e + file yyy + au BufNew,BufWinLeave * ball + call assert_fails('n xxx', 'E143:') + + bwipe % + au! BufNew + au! BufWinLeave +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_breakindent.vim b/src/nvim/testdir/test_breakindent.vim index a4c1f62a43..d53acb77d7 100644 --- a/src/nvim/testdir/test_breakindent.vim +++ b/src/nvim/testdir/test_breakindent.vim @@ -353,14 +353,19 @@ func Test_breakindent19_sbr_nextpage() " Scroll down one screen line setl scrolloff=5 norm! 5gj - redraw! let lines = s:screen_lines(1, 20) let expect = [ - \ "> aaaaaaaaaaaaaaaaaa", + \ "aaaaaaaaaaaaaaaaaaaa", \ "> aaaaaaaaaaaaaaaaaa", \ "> aaaaaaaaaaaaaaaaaa", \ ] call s:compare_lines(expect, lines) + redraw! + " moving the cursor doesn't change the text offset + norm! l + redraw! + let lines = s:screen_lines(1, 20) + call s:compare_lines(expect, lines) setl breakindent briopt=min:18 sbr=> norm! 5gj diff --git a/src/nvim/testdir/test_buffer.vim b/src/nvim/testdir/test_buffer.vim new file mode 100644 index 0000000000..40111fdf06 --- /dev/null +++ b/src/nvim/testdir/test_buffer.vim @@ -0,0 +1,33 @@ +" Tests for Vim buffer + +func Test_buffer_error() + new foo1 + new foo2 + + call assert_fails('buffer foo', 'E93:') + call assert_fails('buffer bar', 'E94:') + call assert_fails('buffer 0', 'E939:') + + %bwipe +endfunc + +func Test_badd_options() + new SomeNewBuffer + setlocal numberwidth=3 + wincmd p + badd +1 SomeNewBuffer + new SomeNewBuffer + call assert_equal(3, &numberwidth) + close + close + bwipe! SomeNewBuffer +endfunc + +func Test_balt() + new SomeNewBuffer + balt +3 OtherBuffer + e # + call assert_equal('OtherBuffer', bufname()) +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_bufline.vim b/src/nvim/testdir/test_bufline.vim index 076f03fdd8..e038bce08e 100644 --- a/src/nvim/testdir/test_bufline.vim +++ b/src/nvim/testdir/test_bufline.vim @@ -112,6 +112,17 @@ func Test_deletebufline() call assert_equal(0, deletebufline(b, 1)) call assert_equal(['b', 'c'], getbufline(b, 1, 2)) exe "bwipe! " . b + + edit XbufOne + let one = bufnr() + call setline(1, ['a', 'b', 'c']) + setlocal nomodifiable + split XbufTwo + let two = bufnr() + call assert_fails('call deletebufline(one, 1)', 'E21:') + call assert_equal(two, bufnr()) + bwipe! XbufTwo + bwipe! XbufOne endfunc func Test_appendbufline_redraw() diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 39f865144a..a66aee5e02 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -442,6 +442,7 @@ func Test_getcompletion() set tags& call assert_fails('call getcompletion("", "burp")', 'E475:') + call assert_fails('call getcompletion("abc", [])', 'E475:') endfunc func Test_shellcmd_completion() diff --git a/src/nvim/testdir/test_command_count.vim b/src/nvim/testdir/test_command_count.vim index 7262789ab4..55b230373f 100644 --- a/src/nvim/testdir/test_command_count.vim +++ b/src/nvim/testdir/test_command_count.vim @@ -158,7 +158,9 @@ endfunc func Test_command_count_4() %argd let bufnr = bufnr('$') - arga aa bb cc dd ee ff + next aa bb cc dd ee ff + call assert_equal(bufnr, bufnr('%')) + 3argu let args = [] .,$-argdo call add(args, expand('%')) diff --git a/src/nvim/testdir/test_conceal.vim b/src/nvim/testdir/test_conceal.vim new file mode 100644 index 0000000000..1306dbe5cf --- /dev/null +++ b/src/nvim/testdir/test_conceal.vim @@ -0,0 +1,282 @@ +" Tests for 'conceal'. + +source check.vim +CheckFeature conceal + +source screendump.vim +" CheckScreendump + +func Test_conceal_two_windows() + CheckScreendump + let code =<< trim [CODE] + let lines = ["one one one one one", "two |hidden| here", "three |hidden| three"] + call setline(1, lines) + syntax match test /|hidden|/ conceal + set conceallevel=2 + set concealcursor= + exe "normal /here\r" + new + call setline(1, lines) + call setline(4, "Second window") + syntax match test /|hidden|/ conceal + set conceallevel=2 + set concealcursor=nc + exe "normal /here\r" + [CODE] + + call writefile(code, 'XTest_conceal') + " Check that cursor line is concealed + let buf = RunVimInTerminal('-S XTest_conceal', {}) + call VerifyScreenDump(buf, 'Test_conceal_two_windows_01', {}) + + " Check that with concealed text vertical cursor movement is correct. + call term_sendkeys(buf, "k") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_02', {}) + + " Check that with cursor line is not concealed + call term_sendkeys(buf, "j") + call term_sendkeys(buf, ":set concealcursor=\r") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_03', {}) + + " Check that with cursor line is not concealed when moving cursor down + call term_sendkeys(buf, "j") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_04', {}) + + " Check that with cursor line is not concealed when switching windows + call term_sendkeys(buf, "\<C-W>\<C-W>") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_05', {}) + + " Check that with cursor line is only concealed in Normal mode + call term_sendkeys(buf, ":set concealcursor=n\r") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_06n', {}) + call term_sendkeys(buf, "a") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_06i', {}) + call term_sendkeys(buf, "\<Esc>/e") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_06c', {}) + call term_sendkeys(buf, "\<Esc>v") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_06v', {}) + call term_sendkeys(buf, "\<Esc>") + + " Check that with cursor line is only concealed in Insert mode + call term_sendkeys(buf, ":set concealcursor=i\r") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_07n', {}) + call term_sendkeys(buf, "a") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_07i', {}) + call term_sendkeys(buf, "\<Esc>/e") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_07c', {}) + call term_sendkeys(buf, "\<Esc>v") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_07v', {}) + call term_sendkeys(buf, "\<Esc>") + + " Check that with cursor line is only concealed in Command mode + call term_sendkeys(buf, ":set concealcursor=c\r") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_08n', {}) + call term_sendkeys(buf, "a") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_08i', {}) + call term_sendkeys(buf, "\<Esc>/e") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_08c', {}) + call term_sendkeys(buf, "\<Esc>v") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_08v', {}) + call term_sendkeys(buf, "\<Esc>") + + " Check that with cursor line is only concealed in Visual mode + call term_sendkeys(buf, ":set concealcursor=v\r") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_09n', {}) + call term_sendkeys(buf, "a") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_09i', {}) + call term_sendkeys(buf, "\<Esc>/e") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_09c', {}) + call term_sendkeys(buf, "\<Esc>v") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_09v', {}) + call term_sendkeys(buf, "\<Esc>") + + " Check moving the cursor while in insert mode. + call term_sendkeys(buf, ":set concealcursor=\r") + call term_sendkeys(buf, "a") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_10', {}) + call term_sendkeys(buf, "\<Down>") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_11', {}) + call term_sendkeys(buf, "\<Esc>") + + " Check the "o" command + call VerifyScreenDump(buf, 'Test_conceal_two_windows_12', {}) + call term_sendkeys(buf, "o") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_13', {}) + call term_sendkeys(buf, "\<Esc>") + + " clean up + call StopVimInTerminal(buf) + call delete('XTest_conceal') +endfunc + +func Test_conceal_with_cursorline() + CheckScreendump + " Opens a help window, where 'conceal' is set, switches to the other window + " where 'cursorline' needs to be updated when the cursor moves. + let code =<< trim [CODE] + set cursorline + normal othis is a test + new + call setline(1, ["one", "two", "three", "four", "five"]) + set ft=help + normal M + [CODE] + + call writefile(code, 'XTest_conceal_cul') + let buf = RunVimInTerminal('-S XTest_conceal_cul', {}) + call VerifyScreenDump(buf, 'Test_conceal_cul_01', {}) + + call term_sendkeys(buf, ":wincmd w\r") + call VerifyScreenDump(buf, 'Test_conceal_cul_02', {}) + + call term_sendkeys(buf, "k") + call VerifyScreenDump(buf, 'Test_conceal_cul_03', {}) + + " clean up + call StopVimInTerminal(buf) + call delete('XTest_conceal_cul') +endfunc + +func Test_conceal_resize_term() + CheckScreendump + let code =<< trim [CODE] + call setline(1, '`one` `two` `three` `four` `five`, the backticks should be concealed') + setl cocu=n cole=3 + syn region CommentCodeSpan matchgroup=Comment start=/`/ end=/`/ concealends + normal fb + [CODE] + call writefile(code, 'XTest_conceal_resize') + let buf = RunVimInTerminal('-S XTest_conceal_resize', {'rows': 6}) + call VerifyScreenDump(buf, 'Test_conceal_resize_01', {}) + + call win_execute(buf->win_findbuf()[0], 'wincmd +') + call TermWait(buf) + call VerifyScreenDump(buf, 'Test_conceal_resize_02', {}) + + " clean up + call StopVimInTerminal(buf) + call delete('XTest_conceal_resize') +endfunc + +" Tests for correct display (cursor column position) with +conceal and +" tabulators. Need to run this test in a separate Vim instance. Otherwise the +" screen is not updated (lazy redraw) and the cursor position is wrong. +func Test_conceal_cursor_pos() + let code =<< trim [CODE] + :let l = ['start:', '.concealed. text', "|concealed|\ttext"] + :let l += ['', "\t.concealed.\ttext", "\t|concealed|\ttext", ''] + :let l += [".a.\t.b.\t.c.\t.d.", "|a|\t|b|\t|c|\t|d|"] + :call append(0, l) + :call cursor(1, 1) + :" Conceal settings. + :set conceallevel=2 + :set concealcursor=nc + :syntax match test /|/ conceal + :" Save current cursor position. Only works in <expr> mode, can't be used + :" with :normal because it moves the cursor to the command line. Thanks + :" to ZyX <zyx.vim@gmail.com> for the idea to use an <expr> mapping. + :let curpos = [] + :nnoremap <expr> GG ":let curpos += ['".screenrow().":".screencol()."']\n" + :normal ztj + GGk + :" We should end up in the same column when running these commands on the + :" two lines. + :normal ft + GGk + :normal $ + GGk + :normal 0j + GGk + :normal ft + GGk + :normal $ + GGk + :normal 0j0j + GGk + :" Same for next test block. + :normal ft + GGk + :normal $ + GGk + :normal 0j + GGk + :normal ft + GGk + :normal $ + GGk + :normal 0j0j + GGk + :" And check W with multiple tabs and conceals in a line. + :normal W + GGk + :normal W + GGk + :normal W + GGk + :normal $ + GGk + :normal 0j + GGk + :normal W + GGk + :normal W + GGk + :normal W + GGk + :normal $ + GGk + :set lbr + :normal $ + GGk + :set list listchars=tab:>- + :normal 0 + GGk + :normal W + GGk + :normal W + GGk + :normal W + GGk + :normal $ + GGk + :call writefile(curpos, 'Xconceal_curpos.out') + :q! + + [CODE] + call writefile(code, 'XTest_conceal_curpos') + + if RunVim([], [], '-s XTest_conceal_curpos') + call assert_equal([ + \ '2:1', '2:17', '2:20', '3:1', '3:17', '3:20', '5:8', '5:25', + \ '5:28', '6:8', '6:25', '6:28', '8:1', '8:9', '8:17', '8:25', + \ '8:27', '9:1', '9:9', '9:17', '9:25', '9:26', '9:26', '9:1', + \ '9:9', '9:17', '9:25', '9:26'], readfile('Xconceal_curpos.out')) + endif + + call delete('Xconceal_curpos.out') + call delete('XTest_conceal_curpos') +endfunc + +func Test_conceal_eol() + new! + setlocal concealcursor=n conceallevel=1 + call setline(1, ["x", ""]) + call matchaddpos('Conceal', [[2, 1, 1]], 2, -1, {'conceal': 1}) + redraw! + + call assert_notequal(screenchar(1, 1), screenchar(2, 2)) + call assert_equal(screenattr(1, 1), screenattr(1, 2)) + call assert_equal(screenattr(1, 2), screenattr(2, 2)) + call assert_equal(screenattr(2, 1), screenattr(2, 2)) + + set list + redraw! + + call assert_equal(screenattr(1, 1), screenattr(2, 2)) + call assert_notequal(screenattr(1, 1), screenattr(1, 2)) + call assert_notequal(screenattr(1, 2), screenattr(2, 1)) + + set nolist +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_diffmode.vim b/src/nvim/testdir/test_diffmode.vim index f09a64c329..21c1f98283 100644 --- a/src/nvim/testdir/test_diffmode.vim +++ b/src/nvim/testdir/test_diffmode.vim @@ -242,6 +242,63 @@ func Test_diffput_two() bwipe! b endfunc +" :diffput and :diffget completes names of buffers which +" are in diff mode and which are different then current buffer. +" No completion when the current window is not in diff mode. +func Test_diffget_diffput_completion() + e Xdiff1 | diffthis + botright new Xdiff2 + botright new Xdiff3 | split | diffthis + botright new Xdiff4 | diffthis + + wincmd t + call assert_equal('Xdiff1', bufname('%')) + call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"diffput Xdiff3 Xdiff4', @:) + call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"diffget Xdiff3 Xdiff4', @:) + call assert_equal(['Xdiff3', 'Xdiff4'], getcompletion('', 'diff_buffer')) + + " Xdiff2 is not in diff mode, so no completion for :diffput, :diffget + wincmd j + call assert_equal('Xdiff2', bufname('%')) + call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"diffput ', @:) + call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"diffget ', @:) + call assert_equal([], getcompletion('', 'diff_buffer')) + + " Xdiff3 is split in 2 windows, only the top one is in diff mode. + " So completion of :diffput :diffget only happens in the top window. + wincmd j + call assert_equal('Xdiff3', bufname('%')) + call assert_equal(1, &diff) + call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"diffput Xdiff1 Xdiff4', @:) + call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"diffget Xdiff1 Xdiff4', @:) + call assert_equal(['Xdiff1', 'Xdiff4'], getcompletion('', 'diff_buffer')) + + wincmd j + call assert_equal('Xdiff3', bufname('%')) + call assert_equal(0, &diff) + call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"diffput ', @:) + call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"diffget ', @:) + call assert_equal([], getcompletion('', 'diff_buffer')) + + wincmd j + call assert_equal('Xdiff4', bufname('%')) + call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"diffput Xdiff1 Xdiff3', @:) + call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"diffget Xdiff1 Xdiff3', @:) + call assert_equal(['Xdiff1', 'Xdiff3'], getcompletion('', 'diff_buffer')) + + %bwipe +endfunc + func Test_dp_do_buffer() e! one let bn1=bufnr('%') @@ -964,6 +1021,21 @@ func Test_diff_closeoff() enew! endfunc +func Test_diff_followwrap() + new + set diffopt+=followwrap + set wrap + diffthis + call assert_equal(1, &wrap) + diffoff + set nowrap + diffthis + call assert_equal(0, &wrap) + diffoff + set diffopt& + bwipe! +endfunc + func Test_diff_rnu() CheckScreendump @@ -992,6 +1064,18 @@ func Test_diff_rnu() call delete('Xtest_diff_rnu') endfunc +func Test_diff_multilineconceal() + new + diffthis + + new + call matchadd('Conceal', 'a\nb', 9, -1, {'conceal': 'Y'}) + set cole=2 cocu=n + call setline(1, ["a", "b"]) + diffthis + redraw +endfunc + func Test_diff_and_scroll() " this was causing an ml_get error set ls=2 diff --git a/src/nvim/testdir/test_digraph.vim b/src/nvim/testdir/test_digraph.vim index b6d9687560..d23748a3e3 100644 --- a/src/nvim/testdir/test_digraph.vim +++ b/src/nvim/testdir/test_digraph.vim @@ -211,6 +211,8 @@ func Test_digraphs() call Put_Dig("00") call Put_Dig("el") call assert_equal(['␀', 'ü', '∞', 'l'], getline(line('.')-3,line('.'))) + call assert_fails('digraph xy z', 'E39:') + call assert_fails('digraph x', 'E474:') bw! endfunc diff --git a/src/nvim/testdir/test_excmd.vim b/src/nvim/testdir/test_excmd.vim index 20508b12d3..98a3e60368 100644 --- a/src/nvim/testdir/test_excmd.vim +++ b/src/nvim/testdir/test_excmd.vim @@ -131,3 +131,11 @@ func Test_confirm_cmd_cancel() \ term_getline(buf, 20))}, 1000) call StopVimInTerminal(buf) endfunc + +" Test for the :winsize command +func Test_winsize_cmd() + call assert_fails('winsize 1', 'E465:') + call assert_fails('winsize 1 x', 'E465:') + call assert_fails('win_getid(1)', 'E475: Invalid argument: _getid(1)') + " Actually changing the window size would be flaky. +endfunc diff --git a/src/nvim/testdir/test_exit.vim b/src/nvim/testdir/test_exit.vim index 99a401d4a4..bd3e9eb4d4 100644 --- a/src/nvim/testdir/test_exit.vim +++ b/src/nvim/testdir/test_exit.vim @@ -81,3 +81,32 @@ func Test_exiting() endif call delete('Xtestout') endfunc + +" Test for getting the Vim exit code from v:exiting +func Test_exit_code() + call assert_equal(v:null, v:exiting) + + let before =<< trim [CODE] + au QuitPre * call writefile(['qp = ' .. v:exiting], 'Xtestout', 'a') + au ExitPre * call writefile(['ep = ' .. v:exiting], 'Xtestout', 'a') + au VimLeavePre * call writefile(['lp = ' .. v:exiting], 'Xtestout', 'a') + au VimLeave * call writefile(['l = ' .. v:exiting], 'Xtestout', 'a') + [CODE] + + if RunVim(before, ['quit'], '') + call assert_equal(['qp = null', 'ep = null', 'lp = 0', 'l = 0'], readfile('Xtestout')) + endif + call delete('Xtestout') + + if RunVim(before, ['cquit'], '') + call assert_equal(['lp = 1', 'l = 1'], readfile('Xtestout')) + endif + call delete('Xtestout') + + if RunVim(before, ['cquit 4'], '') + call assert_equal(['lp = 4', 'l = 4'], readfile('Xtestout')) + endif + call delete('Xtestout') +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_expr.vim b/src/nvim/testdir/test_expr.vim index 7b90ba56e0..09d79979ce 100644 --- a/src/nvim/testdir/test_expr.vim +++ b/src/nvim/testdir/test_expr.vim @@ -399,7 +399,11 @@ function Test_printf_errors() call assert_fails('echo printf("%d", [])', 'E745:') call assert_fails('echo printf("%d", 1, 2)', 'E767:') call assert_fails('echo printf("%*d", 1)', 'E766:') - call assert_fails('echo printf("%d", 1.2)', 'E805:') + call assert_fails('echo printf("%s")', 'E766:') + if has('float') + call assert_fails('echo printf("%d", 1.2)', 'E805:') + call assert_fails('echo printf("%f")') + endif endfunc function Test_max_min_errors() diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index f9f0ade1f6..6bc5fba5db 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -79,6 +79,7 @@ let s:filename_checks = { \ 'bc': ['file.bc'], \ 'bdf': ['file.bdf'], \ 'bib': ['file.bib'], + \ 'beancount': ['file.beancount'], \ 'bindzone': ['named.root'], \ 'blank': ['file.bl'], \ 'bsdl': ['file.bsd', 'file.bsdl'], @@ -427,6 +428,7 @@ let s:filename_checks = { \ 'slrnrc': ['.slrnrc'], \ 'slrnsc': ['file.score'], \ 'sm': ['sendmail.cf'], + \ 'svelte': ['file.svelte'], \ 'smarty': ['file.tpl'], \ 'smcl': ['file.hlp', 'file.ihlp', 'file.smcl'], \ 'smith': ['file.smt', 'file.smith'], diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 917a5e8eca..5dae8d681a 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -833,6 +833,31 @@ func Test_byte2line_line2byte() bw! endfunc +" Test for charidx() +func Test_charidx() + let a = 'xáb́y' + call assert_equal(0, charidx(a, 0)) + call assert_equal(1, charidx(a, 3)) + call assert_equal(2, charidx(a, 4)) + call assert_equal(3, charidx(a, 7)) + call assert_equal(-1, charidx(a, 8)) + call assert_equal(-1, charidx('', 0)) + + " count composing characters + call assert_equal(0, charidx(a, 0, 1)) + call assert_equal(2, charidx(a, 2, 1)) + call assert_equal(3, charidx(a, 4, 1)) + call assert_equal(5, charidx(a, 7, 1)) + call assert_equal(-1, charidx(a, 8, 1)) + call assert_equal(-1, charidx('', 0, 1)) + + call assert_fails('let x = charidx([], 1)', 'E474:') + call assert_fails('let x = charidx("abc", [])', 'E474:') + call assert_fails('let x = charidx("abc", 1, [])', 'E474:') + call assert_fails('let x = charidx("abc", 1, -1)', 'E474:') + call assert_fails('let x = charidx("abc", 1, 2)', 'E474:') +endfunc + func Test_count() let l = ['a', 'a', 'A', 'b'] call assert_equal(2, count(l, 'a')) @@ -930,10 +955,20 @@ func Test_Executable() " get "cat" path and remove the leading / let catcmd = exepath('cat')[1:] new + " check that the relative path works in / lcd / call assert_equal(1, executable(catcmd)) - call assert_equal('/' .. catcmd, exepath(catcmd)) + " let result = catcmd->exepath() + let result = exepath(catcmd) + " when using chroot looking for sbin/cat can return bin/cat, that is OK + if catcmd =~ '\<sbin\>' && result =~ '\<bin\>' + call assert_equal('/' .. substitute(catcmd, '\<sbin\>', 'bin', ''), result) + else + call assert_equal('/' .. catcmd, result) + endif bwipe + else + throw 'Skipped: does not work on this platform' endif endfunc diff --git a/src/nvim/testdir/test_matchadd_conceal.vim b/src/nvim/testdir/test_matchadd_conceal.vim index f9e40a9b43..2cbaf5cb76 100644 --- a/src/nvim/testdir/test_matchadd_conceal.vim +++ b/src/nvim/testdir/test_matchadd_conceal.vim @@ -59,9 +59,9 @@ func Test_matchadd_and_conceallevel_3() setlocal filetype=conf syntax on - 1put='# This is a Test' - " 1234567890123456 - let expect = '#ThisisaTest' + 1put='# This is a Test $' + " 1234567890123 + let expect = '#ThisisaTest$' call cursor(1, 1) call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'X'}) @@ -69,22 +69,25 @@ func Test_matchadd_and_conceallevel_3() let lnum = 2 call assert_equal(expect, Screenline(lnum)) call assert_equal(screenattr(lnum, 1), screenattr(lnum, 2)) - call assert_equal(screenattr(lnum, 2), screenattr(lnum, 7)) - call assert_equal(screenattr(lnum, 2), screenattr(lnum, 10)) - call assert_equal(screenattr(lnum, 2), screenattr(lnum, 12)) + call assert_equal(screenattr(lnum, 1), screenattr(lnum, 7)) + call assert_equal(screenattr(lnum, 1), screenattr(lnum, 10)) + call assert_equal(screenattr(lnum, 1), screenattr(lnum, 12)) + call assert_equal(screenattr(lnum, 1), screenattr(lnum, 13)) + call assert_notequal(screenattr(lnum, 1), screenattr(lnum, 14)) call assert_notequal(screenattr(lnum, 1), screenattr(lnum, 16)) " more matchadd() - " 1234567890123456 - let expect = '#Thisisa Test' + " 12345678901234 + let expect = '#Thisisa Test$' call matchadd('ErrorMsg', '\%2l Test', 20, -1, {'conceal': 'X'}) redraw! call assert_equal(expect, Screenline(lnum)) call assert_equal(screenattr(lnum, 1) , screenattr(lnum, 2)) - call assert_equal(screenattr(lnum, 2) , screenattr(lnum, 7)) + call assert_equal(screenattr(lnum, 1) , screenattr(lnum, 7)) call assert_notequal(screenattr(lnum, 1) , screenattr(lnum, 10)) - call assert_equal(screenattr(lnum, 10), screenattr(lnum, 12)) + call assert_equal(screenattr(lnum, 10), screenattr(lnum, 13)) + call assert_equal(screenattr(lnum, 1), screenattr(lnum, 14)) call assert_notequal(screenattr(lnum, 1) , screenattr(lnum, 16)) call assert_notequal(screenattr(lnum, 10), screenattr(lnum, 16)) @@ -132,15 +135,29 @@ func Test_syn_and_match_conceal() new setlocal concealcursor=n conceallevel=1 - 1put='# This is a Test' - " 1234567890123456 - let expect = '#ZThisZisZaZTest' + 1put='# This is a Test ' + let lnum = 2 call cursor(1, 1) + + " 123456789012345678 + let expect = '#ZThisZisZaZTestZZ' call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'Z'}) + syntax match MyConceal /\%2l / conceal containedin=ALL + hi MyConceal ctermbg=4 ctermfg=2 + redraw! + + call assert_equal(expect, Screenline(lnum)) + call assert_notequal(screenattr(lnum, 1), screenattr(lnum, 2)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 7)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 10)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 12)) + call assert_equal(screenattr(lnum, 1), screenattr(lnum, 16)) + + syntax clear MyConceal syntax match MyConceal /\%2l / conceal containedin=ALL cchar=* redraw! - let lnum = 2 + call assert_equal(expect, Screenline(lnum)) call assert_notequal(screenattr(lnum, 1), screenattr(lnum, 2)) call assert_equal(screenattr(lnum, 2), screenattr(lnum, 7)) @@ -148,8 +165,8 @@ func Test_syn_and_match_conceal() call assert_equal(screenattr(lnum, 2), screenattr(lnum, 12)) call assert_equal(screenattr(lnum, 1), screenattr(lnum, 16)) - " 1234567890123456 - let expect = '#*This*is*a*Test' + " 123456789012345678 + let expect = '#*This*is*a*Test**' call clearmatches() redraw! @@ -160,6 +177,48 @@ func Test_syn_and_match_conceal() call assert_equal(screenattr(lnum, 2), screenattr(lnum, 12)) call assert_equal(screenattr(lnum, 1), screenattr(lnum, 16)) + " 123456789012345678 + let expect = '#*ThisXis*a*Test**' + call matchadd('Conceal', '\%2l\%7c ', 10, -1, {'conceal': 'X'}) + redraw! + + call assert_equal(expect, Screenline(lnum)) + call assert_notequal(screenattr(lnum, 1), screenattr(lnum, 2)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 7)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 10)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 12)) + call assert_equal(screenattr(lnum, 1), screenattr(lnum, 16)) + + " 123456789012345678 + let expect = '#*ThisXis*a*Test**' + call matchadd('ErrorMsg', '\%2l Test', 20, -1) + redraw! + + call assert_equal(expect, Screenline(lnum)) + call assert_notequal(screenattr(lnum, 1), screenattr(lnum, 2)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 12)) + call assert_notequal(screenattr(lnum, 12), screenattr(lnum, 13)) + call assert_equal(screenattr(lnum, 13), screenattr(lnum, 16)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 17)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 18)) + call assert_notequal(screenattr(lnum, 18), screenattr(lnum, 19)) + + " 123456789012345678 + let expect = '# ThisXis a Test' + syntax clear MyConceal + syntax match MyConceal /\%2l / conceal containedin=ALL + redraw! + + call assert_equal(expect, Screenline(lnum)) + call assert_notequal(screenattr(lnum, 1), screenattr(lnum, 2)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 12)) + call assert_notequal(screenattr(lnum, 1), screenattr(lnum, 12)) + call assert_notequal(screenattr(lnum, 12), screenattr(lnum, 13)) + call assert_equal(screenattr(lnum, 13), screenattr(lnum, 16)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 17)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 18)) + call assert_notequal(screenattr(lnum, 18), screenattr(lnum, 19)) + syntax off quit! endfunc diff --git a/src/nvim/testdir/test_messages.vim b/src/nvim/testdir/test_messages.vim index 30239a90c2..3ebd048f46 100644 --- a/src/nvim/testdir/test_messages.vim +++ b/src/nvim/testdir/test_messages.vim @@ -31,6 +31,8 @@ func Test_messages() finally let &more = oldmore endtry + + call assert_fails('message 1', 'E474:') endfunc " Patch 7.4.1696 defined the "clearmode()" command for clearing the mode diff --git a/src/nvim/testdir/test_mksession.vim b/src/nvim/testdir/test_mksession.vim index f71da92bf8..7c7804212b 100644 --- a/src/nvim/testdir/test_mksession.vim +++ b/src/nvim/testdir/test_mksession.vim @@ -291,6 +291,46 @@ endfunc endif +func Test_mkview_open_folds() + enew! + + call append(0, ['a', 'b', 'c']) + 1,3fold + " zR affects 'foldlevel', make sure the option is applied after the folds + " have been recreated. + normal zR + write! Xtestfile + + call assert_equal(-1, foldclosed(1)) + call assert_equal(-1, foldclosed(2)) + call assert_equal(-1, foldclosed(3)) + + mkview! Xtestview + source Xtestview + + call assert_equal(-1, foldclosed(1)) + call assert_equal(-1, foldclosed(2)) + call assert_equal(-1, foldclosed(3)) + + call delete('Xtestview') + call delete('Xtestfile') + %bwipe +endfunc + +func Test_mkview_no_balt() + edit Xtestfile1 + edit Xtestfile2 + + mkview! Xtestview + bdelete Xtestfile1 + + source Xtestview + call assert_equal(0, buflisted('Xtestfile1')) + + call delete('Xtestview') + %bwipe +endfunc + " Test :mkview with a file argument. func Test_mkview_file() " Create a view with line number and a fold. @@ -373,6 +413,58 @@ func Test_mkview_no_file_name() %bwipe endfunc +func Test_mkview_loadview_jumplist() + set viewdir=Xviewdir + au BufWinLeave * silent mkview + " au BufWinEnter * silent loadview + + edit Xfile1 + call setline(1, ['a', 'bbbbbbb', 'c']) + normal j3l + call assert_equal([2, 4], getcurpos()[1:2]) + write + + edit Xfile2 + call setline(1, ['d', 'eeeeeee', 'f']) + normal j5l + call assert_equal([2, 6], getcurpos()[1:2]) + write + + edit Xfile3 + call setline(1, ['g', 'h', 'iiiii']) + normal jj3l + call assert_equal([3, 4], getcurpos()[1:2]) + write + + " The commented :au above was moved here so that :mkview (on BufWinLeave) can + " run before :loadview. This is needed because Nvim's :loadview raises E484 if + " the view can't be opened, while Vim's silently fails instead. + au BufWinEnter * silent loadview + + edit Xfile1 + call assert_equal([2, 4], getcurpos()[1:2]) + edit Xfile2 + call assert_equal([2, 6], getcurpos()[1:2]) + edit Xfile3 + call assert_equal([3, 4], getcurpos()[1:2]) + + exe "normal \<C-O>" + call assert_equal('Xfile2', expand('%')) + call assert_equal([2, 6], getcurpos()[1:2]) + exe "normal \<C-O>" + call assert_equal('Xfile1', expand('%')) + call assert_equal([2, 4], getcurpos()[1:2]) + + au! BufWinLeave + au! BufWinEnter + bwipe! + call delete('Xviewdir', 'rf') + call delete('Xfile1') + call delete('Xfile2') + call delete('Xfile3') + set viewdir& +endfunc + " A clean session (one empty buffer, one window, and one tab) should not " set any error messages when sourced because no commands should fail. func Test_mksession_no_errmsg() @@ -663,4 +755,27 @@ func Test_scrolloff() set sessionoptions& endfunc +func Test_altfile() + edit Xone + split Xtwo + edit Xtwoalt + edit # + wincmd w + edit Xonealt + edit # + mksession! Xtest_altfile + only + bwipe Xonealt + bwipe Xtwoalt + bwipe! + source Xtest_altfile + call assert_equal('Xone', bufname()) + call assert_equal('Xonealt', bufname('#')) + wincmd w + call assert_equal('Xtwo', bufname()) + call assert_equal('Xtwoalt', bufname('#')) + only + bwipe! +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_options.vim b/src/nvim/testdir/test_options.vim index 84d99ebb74..1202b842fd 100644 --- a/src/nvim/testdir/test_options.vim +++ b/src/nvim/testdir/test_options.vim @@ -1,5 +1,7 @@ " Test for options +source check.vim + func Test_whichwrap() set whichwrap=b,s call assert_equal('b,s', &whichwrap) @@ -330,12 +332,10 @@ func Test_set_ttytype() set ttytype=xterm call assert_equal('xterm', &ttytype) call assert_equal(&ttytype, &term) - " "set ttytype=" gives E522 instead of E529 - " in travis on some builds. Why? Catch both for now try set ttytype= call assert_report('set ttytype= did not fail') - catch /E529\|E522/ + catch /E529/ endtry " Some systems accept any terminal name and return dumb settings, @@ -606,6 +606,27 @@ func Test_opt_boolean() set number& endfunc +func Test_opt_winminheight_term() + " See test/functional/legacy/options_spec.lua + CheckRunVimInTerminal + + " The tabline should be taken into account. + let lines =<< trim END + set wmh=0 stal=2 + below sp | wincmd _ + below sp | wincmd _ + below sp | wincmd _ + below sp + END + call writefile(lines, 'Xwinminheight') + let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11}) + call term_sendkeys(buf, ":set wmh=1\n") + call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))}) + + call StopVimInTerminal(buf) + call delete('Xwinminheight') +endfunc + " Test for setting option value containing spaces with isfname+=32 func Test_isfname_with_options() set isfname+=32 @@ -615,4 +636,23 @@ func Test_isfname_with_options() setlocal keywordprg& endfunc +" Test that resetting laststatus does change scroll option +func Test_opt_reset_scroll() + " See test/functional/legacy/options_spec.lua + CheckRunVimInTerminal + let vimrc =<< trim [CODE] + set scroll=2 + set laststatus=2 + [CODE] + call writefile(vimrc, 'Xscroll') + let buf = RunVimInTerminal('-S Xscroll', {'rows': 16, 'cols': 45}) + call term_sendkeys(buf, ":verbose set scroll?\n") + call WaitForAssert({-> assert_match('Last set.*window size', term_getline(buf, 15))}) + call assert_match('^\s*scroll=7$', term_getline(buf, 14)) + call StopVimInTerminal(buf) + + " clean up + call delete('Xscroll') +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_statusline.vim b/src/nvim/testdir/test_statusline.vim index 4e38f7ebd8..ce2ef4dcd8 100644 --- a/src/nvim/testdir/test_statusline.vim +++ b/src/nvim/testdir/test_statusline.vim @@ -1,12 +1,12 @@ " Test 'statusline' " " Not tested yet: -" %a " %N " %T " %X source view_util.vim +source check.vim source term_util.vim func s:get_statusline() @@ -61,7 +61,19 @@ func Test_statusline_will_be_disabled_with_error() endfunc func Test_statusline() - new Xstatusline + CheckFeature quickfix + + " %a: Argument list ({current} of {max}) + set statusline=%a + call assert_match('^\s*$', s:get_statusline()) + arglocal a1 a2 + rewind + call assert_match('^ (1 of 2)\s*$', s:get_statusline()) + next + call assert_match('^ (2 of 2)\s*$', s:get_statusline()) + e Xstatusline + call assert_match('^ ((2) of 2)\s*$', s:get_statusline()) + only set laststatus=2 set splitbelow diff --git a/src/nvim/testdir/test_user_func.vim b/src/nvim/testdir/test_user_func.vim index 67701ee3ca..e9e181ce3d 100644 --- a/src/nvim/testdir/test_user_func.vim +++ b/src/nvim/testdir/test_user_func.vim @@ -95,6 +95,59 @@ func Test_user_func() enew! endfunc +func Log(val, base = 10) + return log(a:val) / log(a:base) +endfunc + +func Args(mandatory, optional = v:null, ...) + return deepcopy(a:) +endfunc + +func Args2(a = 1, b = 2, c = 3) + return deepcopy(a:) +endfunc + +func MakeBadFunc() + func s:fcn(a, b=1, c) + endfunc +endfunc + +func Test_default_arg() + call assert_equal(1.0, Log(10)) + call assert_equal(log(10), Log(10, exp(1))) + call assert_fails("call Log(1,2,3)", 'E118') + + let res = Args(1) + call assert_equal(res.mandatory, 1) + call assert_equal(res.optional, v:null) + call assert_equal(res['0'], 0) + + let res = Args(1,2) + call assert_equal(res.mandatory, 1) + call assert_equal(res.optional, 2) + call assert_equal(res['0'], 0) + + let res = Args(1,2,3) + call assert_equal(res.mandatory, 1) + call assert_equal(res.optional, 2) + call assert_equal(res['0'], 1) + + call assert_fails("call MakeBadFunc()", 'E989') + call assert_fails("fu F(a=1 ,) | endf", 'E475') + + " Since neovim does not have v:none, the ability to use the default + " argument with the intermediate argument set to v:none has been omitted. + " Therefore, this test is not performed. + " let d = Args2(7, v:none, 9) + " call assert_equal([7, 2, 9], [d.a, d.b, d.c]) + + call assert_equal("\n" + \ .. " function Args2(a = 1, b = 2, c = 3)\n" + \ .. "1 return deepcopy(a:)\n" + \ .. " endfunction", + \ execute('func Args2')) +endfunc + func Test_failed_call_in_try() try | call UnknownFunc() | catch | endtry endfunc diff --git a/src/nvim/testdir/test_version.vim b/src/nvim/testdir/test_version.vim index 46cf34979f..5fd38f7cdc 100644 --- a/src/nvim/testdir/test_version.vim +++ b/src/nvim/testdir/test_version.vim @@ -1,5 +1,8 @@ " Test :version Ex command +so check.vim +so shared.vim + func Test_version() " version should always return the same string. let v1 = execute('version') @@ -9,4 +12,15 @@ func Test_version() call assert_match("^\n\nNVIM v[0-9]\\+\\.[0-9]\\+\\.[0-9]\\+.*", v1) endfunc +func Test_version_redirect() + CheckNotGui + CheckCanRunGui + CheckUnix + + call RunVim([], [], '--clean -g --version >Xversion 2>&1') + call assert_match('Features included', readfile('Xversion')->join()) + + call delete('Xversion') +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c index 3e683a4926..6705ab98c2 100644 --- a/src/nvim/tui/input.c +++ b/src/nvim/tui/input.c @@ -557,8 +557,8 @@ HandleState ut_handle_background_color(TermInput *input) static void handle_raw_buffer(TermInput *input, bool force) { - HandleState is_paste; - HandleState is_bc; + HandleState is_paste = kNotApplicable; + HandleState is_bc = kNotApplicable; do { if (!force diff --git a/src/nvim/undo.c b/src/nvim/undo.c index da464c56dc..f52850f6f3 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -580,6 +580,10 @@ int u_savecommon(linenr_T top, linenr_T bot, linenr_T newbot, int reload) uep->ue_array = NULL; uep->ue_next = curbuf->b_u_newhead->uh_entry; curbuf->b_u_newhead->uh_entry = uep; + if (reload) { + // buffer was reloaded, notify text change subscribers + curbuf->b_u_newhead->uh_flags |= UH_RELOAD; + } curbuf->b_u_synced = false; undo_undoes = false; @@ -590,13 +594,20 @@ int u_savecommon(linenr_T top, linenr_T bot, linenr_T newbot, int reload) } -# define UF_START_MAGIC "Vim\237UnDo\345" /* magic at start of undofile */ +// magic at start of undofile +# define UF_START_MAGIC "Vim\237UnDo\345" # define UF_START_MAGIC_LEN 9 -# define UF_HEADER_MAGIC 0x5fd0 /* magic at start of header */ -# define UF_HEADER_END_MAGIC 0xe7aa /* magic after last header */ -# define UF_ENTRY_MAGIC 0xf518 /* magic at start of entry */ -# define UF_ENTRY_END_MAGIC 0x3581 /* magic after last entry */ -# define UF_VERSION 2 /* 2-byte undofile version number */ +// magic at start of header +# define UF_HEADER_MAGIC 0x5fd0 +// magic after last header +# define UF_HEADER_END_MAGIC 0xe7aa +// magic at start of entry +# define UF_ENTRY_MAGIC 0xf518 +// magic after last entry +# define UF_ENTRY_END_MAGIC 0x3581 + +// 2-byte undofile version number +# define UF_VERSION 3 /* extra fields for header */ # define UF_LAST_SAVE_NR 1 @@ -843,6 +854,15 @@ static bool serialize_uhp(bufinfo_T *bi, u_header_T *uhp) } } undo_write_bytes(bi, (uintmax_t)UF_ENTRY_END_MAGIC, 2); + + // Write all extmark undo objects + for (size_t i = 0; i < kv_size(uhp->uh_extmark); i++) { + if (!serialize_extmark(bi, kv_A(uhp->uh_extmark, i))) { + return false; + } + } + undo_write_bytes(bi, (uintmax_t)UF_ENTRY_END_MAGIC, 2); + return true; } @@ -924,9 +944,95 @@ static u_header_T *unserialize_uhp(bufinfo_T *bi, return NULL; } + // Unserialize all extmark undo information + ExtmarkUndoObject *extup; + kv_init(uhp->uh_extmark); + + while ((c = undo_read_2c(bi)) == UF_ENTRY_MAGIC) { + bool error = false; + extup = unserialize_extmark(bi, &error, file_name); + if (error) { + kv_destroy(uhp->uh_extmark); + xfree(extup); + return NULL; + } + kv_push(uhp->uh_extmark, *extup); + xfree(extup); + } + if (c != UF_ENTRY_END_MAGIC) { + corruption_error("entry end", file_name); + u_free_uhp(uhp); + return NULL; + } + return uhp; } +static bool serialize_extmark(bufinfo_T *bi, ExtmarkUndoObject extup) +{ + if (extup.type == kExtmarkSplice) { + undo_write_bytes(bi, (uintmax_t)UF_ENTRY_MAGIC, 2); + undo_write_bytes(bi, (uintmax_t)extup.type, 4); + if (!undo_write(bi, (uint8_t *)&(extup.data.splice), + sizeof(ExtmarkSplice))) { + return false; + } + } else if (extup.type == kExtmarkMove) { + undo_write_bytes(bi, (uintmax_t)UF_ENTRY_MAGIC, 2); + undo_write_bytes(bi, (uintmax_t)extup.type, 4); + if (!undo_write(bi, (uint8_t *)&(extup.data.move), sizeof(ExtmarkMove))) { + return false; + } + } + // Note: We do not serialize ExtmarkSavePos information, since + // buffer marktrees are not retained when closing/reopening a file + return true; +} + +static ExtmarkUndoObject *unserialize_extmark(bufinfo_T *bi, bool *error, + const char *filename) +{ + UndoObjectType type; + uint8_t *buf = NULL; + size_t n_elems; + + ExtmarkUndoObject *extup = xmalloc(sizeof(ExtmarkUndoObject)); + + type = (UndoObjectType)undo_read_4c(bi); + extup->type = type; + if (type == kExtmarkSplice) { + n_elems = (size_t)sizeof(ExtmarkSplice) / sizeof(uint8_t); + buf = xcalloc(sizeof(uint8_t), n_elems); + if (!undo_read(bi, buf, n_elems)) { + goto error; + } + extup->data.splice = *(ExtmarkSplice *)buf; + } else if (type == kExtmarkMove) { + n_elems = (size_t)sizeof(ExtmarkMove) / sizeof(uint8_t); + buf = xcalloc(sizeof(uint8_t), n_elems); + if (!undo_read(bi, buf, n_elems)) { + goto error; + } + extup->data.move = *(ExtmarkMove *)buf; + } else { + goto error; + } + + if (buf) { + xfree(buf); + } + + return extup; + +error: + xfree(extup); + if (buf) { + xfree(buf); + } + *error = true; + return NULL; +} + /// Serializes "uep". /// /// @param bi The buffer information @@ -2157,8 +2263,9 @@ static void u_undoredo(int undo, bool do_buf_event) u_check(FALSE); #endif old_flags = curhead->uh_flags; - new_flags = (curbuf->b_changed ? UH_CHANGED : 0) + - ((curbuf->b_ml.ml_flags & ML_EMPTY) ? UH_EMPTYBUF : 0); + new_flags = (curbuf->b_changed ? UH_CHANGED : 0) + | ((curbuf->b_ml.ml_flags & ML_EMPTY) ? UH_EMPTYBUF : 0) + | (old_flags & UH_RELOAD); setpcmark(); /* @@ -2299,6 +2406,11 @@ static void u_undoredo(int undo, bool do_buf_event) extmark_apply_undo(undo_info, undo); } } + if (curhead->uh_flags & UH_RELOAD) { + // TODO(bfredl): this is a bit crude. When 'undoreload' is used we + // should have all info to send a buffer-reloaing on_lines/on_bytes event + buf_updates_unload(curbuf, true); + } // finish Adjusting extmarks diff --git a/src/nvim/undo_defs.h b/src/nvim/undo_defs.h index cc2c39a711..b46295a15d 100644 --- a/src/nvim/undo_defs.h +++ b/src/nvim/undo_defs.h @@ -69,9 +69,10 @@ struct u_header { #endif }; -/* values for uh_flags */ -#define UH_CHANGED 0x01 /* b_changed flag before undo/after redo */ -#define UH_EMPTYBUF 0x02 /* buffer was empty */ +// values for uh_flags +#define UH_CHANGED 0x01 // b_changed flag before undo/after redo +#define UH_EMPTYBUF 0x02 // buffer was empty +#define UH_RELOAD 0x04 // buffer was reloaded /// Structure passed around between undofile functions. typedef struct { diff --git a/src/nvim/vim.h b/src/nvim/vim.h index e70749795b..0245c472ef 100644 --- a/src/nvim/vim.h +++ b/src/nvim/vim.h @@ -158,6 +158,7 @@ enum { EXPAND_MESSAGES, EXPAND_MAPCLEAR, EXPAND_ARGLIST, + EXPAND_DIFF_BUFFERS, EXPAND_CHECKHEALTH, EXPAND_LUA, }; diff --git a/src/nvim/window.c b/src/nvim/window.c index 00f49724b6..0f717a2f90 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -5501,7 +5501,7 @@ void win_setminheight(void) // loop until there is a 'winminheight' that is possible while (p_wmh > 0) { - const int room = Rows - p_ch; + const int room = Rows - p_ch - tabline_height(); const int needed = frame_minheight(topframe, NULL); if (room >= needed) { break; @@ -5960,9 +5960,17 @@ void win_new_width(win_T *wp, int width) void win_comp_scroll(win_T *wp) { + const long old_w_p_scr = wp->w_p_scr; + wp->w_p_scr = wp->w_height / 2; - if (wp->w_p_scr == 0) + if (wp->w_p_scr == 0) { wp->w_p_scr = 1; + } + if (wp->w_p_scr != old_w_p_scr) { + // Used by "verbose set scroll". + wp->w_p_script_ctx[WV_SCROLL].script_ctx.sc_sid = SID_WINLAYOUT; + wp->w_p_script_ctx[WV_SCROLL].script_ctx.sc_lnum = 0; + } } /* diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index fb8ed6a9d7..81fad206da 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -513,6 +513,28 @@ describe('api/buf', function() eq({0, 8}, curbufmeths.get_extmark_by_id(ns, id2, {})) eq({0, 8}, curbufmeths.get_extmark_by_id(ns, id3, {})) end) + + it("correctly marks changed region for redraw #13890", function() + local screen = Screen.new(20, 5) + screen:attach() + + insert([[ + AAA + BBB + ]]) + + curbufmeths.set_text(0, 0, 1, 3, {'XXX', 'YYY'}) + + screen:expect([[ + XXX | + YYY | + ^ | + ~ | + | + + ]]) + + end) end) describe('nvim_buf_get_offset', function() diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 3ff3efb8c9..437a1858f3 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -475,6 +475,18 @@ describe('API', function() end) end) + describe('nvim_notify', function() + it('can notify a info message', function() + nvim("notify", "hello world", 2, {}) + end) + + it('can be overriden', function() + command("lua vim.notify = function(...) return 42 end") + eq(42, meths.exec_lua("return vim.notify('Hello world')", {})) + nvim("notify", "hello world", 4, {}) + end) + end) + describe('nvim_input', function() it("VimL error: does NOT fail, updates v:errmsg", function() local status, _ = pcall(nvim, "input", ":call bogus_fn()<CR>") diff --git a/test/functional/ex_cmds/source_spec.lua b/test/functional/ex_cmds/source_spec.lua new file mode 100644 index 0000000000..16d0dfb6a1 --- /dev/null +++ b/test/functional/ex_cmds/source_spec.lua @@ -0,0 +1,47 @@ +local helpers = require('test.functional.helpers')(after_each) +local command = helpers.command +local insert = helpers.insert +local eq = helpers.eq +local clear = helpers.clear +local meths = helpers.meths +local feed = helpers.feed +local feed_command = helpers.feed_command + +describe(':source', function() + before_each(function() + clear() + end) + + it('current buffer', function() + insert('let a = 2') + command('source') + eq('2', meths.exec('echo a', true)) + end) + + it('selection in current buffer', function() + insert( + 'let a = 2\n'.. + 'let a = 3\n'.. + 'let a = 4\n') + + -- Source the 2nd line only + feed('ggjV') + feed_command(':source') + eq('3', meths.exec('echo a', true)) + + -- Source from 2nd line to end of file + feed('ggjVG') + feed_command(':source') + eq('4', meths.exec('echo a', true)) + end) + + it('multiline heredoc command', function() + insert( + 'lua << EOF\n'.. + 'y = 4\n'.. + 'EOF\n') + + command('source') + eq('4', meths.exec('echo luaeval("y")', true)) + end) +end) diff --git a/test/functional/fixtures/fake-lsp-server.lua b/test/functional/fixtures/fake-lsp-server.lua index 252db88b6b..3bbb4c4517 100644 --- a/test/functional/fixtures/fake-lsp-server.lua +++ b/test/functional/fixtures/fake-lsp-server.lua @@ -70,11 +70,11 @@ local function expect_notification(method, params, ...) ..., "expect_notification", "message") end -local function expect_request(method, callback, ...) +local function expect_request(method, handler, ...) local req = read_message() assert_eq(method, req.method, ..., "expect_request", "method") - local err, result = callback(req.params) + local err, result = handler(req.params) respond(req.id, err, result) end diff --git a/test/functional/legacy/options_spec.lua b/test/functional/legacy/options_spec.lua index 1db7afc7a7..d7f5df3a1e 100644 --- a/test/functional/legacy/options_spec.lua +++ b/test/functional/legacy/options_spec.lua @@ -1,6 +1,10 @@ +-- See also: src/nvim/testdir/test_options.vim local helpers = require('test.functional.helpers')(after_each) local command, clear = helpers.command, helpers.clear local source, expect = helpers.source, helpers.expect +local exc_exec = helpers.exc_exec; +local matches = helpers.matches; +local Screen = require('test.functional.ui.screen') describe('options', function() setup(clear) @@ -11,7 +15,7 @@ describe('options', function() end) describe('set', function() - setup(clear) + before_each(clear) it("should keep two comma when 'path' is changed", function() source([[ @@ -24,4 +28,45 @@ describe('set', function() foo,,bar]]) end) + + it('winminheight works', function() + local screen = Screen.new(20, 11) + screen:attach() + source([[ + set wmh=0 stal=2 + below sp | wincmd _ + below sp | wincmd _ + below sp | wincmd _ + below sp + ]]) + matches('E36: Not enough room', exc_exec('set wmh=1')) + end) + + it('scroll works', function() + local screen = Screen.new(42, 16) + screen:attach() + source([[ + set scroll=2 + set laststatus=2 + ]]) + command('verbose set scroll?') + screen:expect([[ + | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + ~ | + | + scroll=7 | + Last set from changed window size | + Press ENTER or type command to continue^ | + ]]) + end) end) diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua index 67dc5f5a16..7a6b5be8bc 100644 --- a/test/functional/lua/buffer_updates_spec.lua +++ b/test/functional/lua/buffer_updates_spec.lua @@ -1,5 +1,6 @@ -- Test suite for testing interactions with API bindings local helpers = require('test.functional.helpers')(after_each) +local lfs = require('lfs') local command = helpers.command local meths = helpers.meths @@ -9,8 +10,9 @@ local eq = helpers.eq local fail = helpers.fail local exec_lua = helpers.exec_lua local feed = helpers.feed -local deepcopy = helpers.deepcopy local expect_events = helpers.expect_events +local write_file = helpers.write_file +local dedent = helpers.dedent local origlines = {"original line 1", "original line 2", @@ -20,19 +22,20 @@ local origlines = {"original line 1", "original line 6", " indented line"} -local function attach_buffer(evname) - exec_lua([[ +before_each(function () + clear() + exec_lua [[ local evname = ... local events = {} - function test_register(bufnr, id, changedtick, utf_sizes, preview) + function test_register(bufnr, evname, id, changedtick, utf_sizes, preview) local function callback(...) table.insert(events, {id, ...}) if test_unreg == id then return true end end - local opts = {[evname]=callback, on_detach=callback, utf_sizes=utf_sizes, preview=preview} + local opts = {[evname]=callback, on_detach=callback, on_reload=callback, utf_sizes=utf_sizes, preview=preview} if changedtick then opts.on_changedtick = callback end @@ -44,41 +47,30 @@ local function attach_buffer(evname) events = {} return ret_events end - ]], evname) -end + ]] +end) describe('lua buffer event callbacks: on_lines', function() - before_each(function() - clear() - attach_buffer('on_lines') - end) - - - -- verifying the sizes with nvim_buf_get_offset is nice (checks we cannot - -- assert the wrong thing), but masks errors with unflushed lines (as - -- nvim_buf_get_offset forces a flush of the memline). To be safe run the - -- test both ways. - local function check(verify,utf_sizes) + local function setup_eventcheck(verify, utf_sizes, lines) local lastsize - meths.buf_set_lines(0, 0, -1, true, origlines) + meths.buf_set_lines(0, 0, -1, true, lines) if verify then lastsize = meths.buf_get_offset(0, meths.buf_line_count(0)) end - exec_lua("return test_register(...)", 0, "test1",false,utf_sizes) - local tick = meths.buf_get_changedtick(0) - + exec_lua("return test_register(...)", 0, "on_lines", "test1",false,utf_sizes) local verify_name = "test1" + local function check_events(expected) local events = exec_lua("return get_events(...)" ) if utf_sizes then -- this test case uses ASCII only, so sizes should be the same. -- Unicode is tested below. for _, event in ipairs(expected) do - event[9] = event[8] - event[10] = event[8] + event[9] = event[9] or event[8] + event[10] = event[10] or event[9] end end - eq(expected, events) + expect_events(expected, events, "line updates") if verify then for _, event in ipairs(events) do if event[1] == verify_name and event[2] == "lines" then @@ -92,25 +84,38 @@ describe('lua buffer event callbacks: on_lines', function() end end end + return check_events, function(new) verify_name = new end + end + + -- verifying the sizes with nvim_buf_get_offset is nice (checks we cannot + -- assert the wrong thing), but masks errors with unflushed lines (as + -- nvim_buf_get_offset forces a flush of the memline). To be safe run the + -- test both ways. + local function check(verify,utf_sizes) + local check_events, verify_name = setup_eventcheck(verify, utf_sizes, origlines) + + local tick = meths.buf_get_changedtick(0) command('set autoindent') command('normal! GyyggP') tick = tick + 1 - check_events({{ "test1", "lines", 1, tick, 0, 0, 1, 0}}) + check_events {{ "test1", "lines", 1, tick, 0, 0, 1, 0}} meths.buf_set_lines(0, 3, 5, true, {"changed line"}) tick = tick + 1 - check_events({{ "test1", "lines", 1, tick, 3, 5, 4, 32 }}) + check_events {{ "test1", "lines", 1, tick, 3, 5, 4, 32 }} - exec_lua("return test_register(...)", 0, "test2", true, utf_sizes) + exec_lua("return test_register(...)", 0, "on_lines", "test2", true, utf_sizes) tick = tick + 1 command('undo') -- plugins can opt in to receive changedtick events, or choose -- to only receive actual changes. - check_events({{ "test1", "lines", 1, tick, 3, 4, 5, 13 }, - { "test2", "lines", 1, tick, 3, 4, 5, 13 }, - { "test2", "changedtick", 1, tick+1 } }) + check_events { + { "test1", "lines", 1, tick, 3, 4, 5, 13 }; + { "test2", "lines", 1, tick, 3, 4, 5, 13 }; + { "test2", "changedtick", 1, tick+1 }; + } tick = tick + 1 -- simulate next callback returning true @@ -121,38 +126,40 @@ describe('lua buffer event callbacks: on_lines', function() -- plugins can opt in to receive changedtick events, or choose -- to only receive actual changes. - check_events({{ "test1", "lines", 1, tick, 6, 7, 9, 16 }, - { "test2", "lines", 1, tick, 6, 7, 9, 16 }}) + check_events { + { "test1", "lines", 1, tick, 6, 7, 9, 16 }; + { "test2", "lines", 1, tick, 6, 7, 9, 16 }; + } - verify_name = "test2" + verify_name "test2" meths.buf_set_lines(0, 1, 1, true, {"added"}) tick = tick + 1 - check_events({{ "test2", "lines", 1, tick, 1, 1, 2, 0 }}) + check_events {{ "test2", "lines", 1, tick, 1, 1, 2, 0 }} feed('wix') tick = tick + 1 - check_events({{ "test2", "lines", 1, tick, 4, 5, 5, 16 }}) + check_events {{ "test2", "lines", 1, tick, 4, 5, 5, 16 }} -- check hot path for multiple insert feed('yz') tick = tick + 1 - check_events({{ "test2", "lines", 1, tick, 4, 5, 5, 17 }}) + check_events {{ "test2", "lines", 1, tick, 4, 5, 5, 17 }} feed('<bs>') tick = tick + 1 - check_events({{ "test2", "lines", 1, tick, 4, 5, 5, 19 }}) + check_events {{ "test2", "lines", 1, tick, 4, 5, 5, 19 }} feed('<esc>Go') tick = tick + 1 - check_events({{ "test2", "lines", 1, tick, 11, 11, 12, 0 }}) + check_events {{ "test2", "lines", 1, tick, 11, 11, 12, 0 }} feed('x') tick = tick + 1 - check_events({{ "test2", "lines", 1, tick, 11, 12, 12, 5 }}) + check_events {{ "test2", "lines", 1, tick, 11, 12, 12, 5 }} command('bwipe!') - check_events({{ "test2", "detach", 1 }}) + check_events {{ "test2", "detach", 1 }} end it('works', function() @@ -167,51 +174,63 @@ describe('lua buffer event callbacks: on_lines', function() check(false,true) end) - it('works with utf_sizes and unicode text', function() + local function check_unicode(verify) local unicode_text = {"ascii text", "latin text åäö", "BMP text ɧ αλφά", "BMP text 汉语 ↥↧", "SMP 🤦 🦄🦃", "combining å بِيَّة"} - meths.buf_set_lines(0, 0, -1, true, unicode_text) - feed('gg') - exec_lua("return test_register(...)", 0, "test1", false, true) + local check_events, verify_name = setup_eventcheck(verify, true, unicode_text) + local tick = meths.buf_get_changedtick(0) - feed('dd') + feed('ggdd') tick = tick + 1 - eq({{ "test1", "lines", 1, tick, 0, 1, 0, 11, 11, 11 }}, exec_lua("return get_events(...)" )) + check_events {{ "test1", "lines", 1, tick, 0, 1, 0, 11, 11, 11 }} feed('A<bs>') tick = tick + 1 - eq({{ "test1", "lines", 1, tick, 0, 1, 1, 18, 15, 15 }}, exec_lua("return get_events(...)" )) + check_events {{ "test1", "lines", 1, tick, 0, 1, 1, 18, 15, 15 }} feed('<esc>jylp') tick = tick + 1 - eq({{ "test1", "lines", 1, tick, 1, 2, 2, 21, 16, 16 }}, exec_lua("return get_events(...)" )) + check_events {{ "test1", "lines", 1, tick, 1, 2, 2, 21, 16, 16 }} feed('+eea<cr>') tick = tick + 1 - eq({{ "test1", "lines", 1, tick, 2, 3, 4, 23, 15, 15 }}, exec_lua("return get_events(...)" )) + check_events {{ "test1", "lines", 1, tick, 2, 3, 4, 23, 15, 15 }} feed('<esc>jdw') tick = tick + 1 -- non-BMP chars count as 2 UTF-2 codeunits - eq({{ "test1", "lines", 1, tick, 4, 5, 5, 18, 9, 12 }}, exec_lua("return get_events(...)" )) + check_events {{ "test1", "lines", 1, tick, 4, 5, 5, 18, 9, 12 }} feed('+rx') tick = tick + 1 -- count the individual codepoints of a composed character. - eq({{ "test1", "lines", 1, tick, 5, 6, 6, 27, 20, 20 }}, exec_lua("return get_events(...)" )) + check_events {{ "test1", "lines", 1, tick, 5, 6, 6, 27, 20, 20 }} feed('kJ') tick = tick + 1 + -- verification fails with multiple line updates, sorry about that + verify_name "" -- NB: this is inefficient (but not really wrong). - eq({{ "test1", "lines", 1, tick, 4, 5, 5, 14, 5, 8 }, - { "test1", "lines", 1, tick+1, 5, 6, 5, 27, 20, 20 }}, exec_lua("return get_events(...)" )) + check_events { + { "test1", "lines", 1, tick, 4, 5, 5, 14, 5, 8 }; + { "test1", "lines", 1, tick+1, 5, 6, 5, 27, 20, 20 }; + } + end + + it('works with utf_sizes and unicode text', function() + check_unicode(false) end) + it('works with utf_sizes and unicode text with verify', function() + check_unicode(true) + end) + + it('has valid cursor position while shifting', function() meths.buf_set_lines(0, 0, -1, true, {'line1'}) exec_lua([[ @@ -225,6 +244,14 @@ describe('lua buffer event callbacks: on_lines', function() eq(1, meths.get_var('listener_cursor_line')) end) + it('has valid cursor position while deleting lines', function() + meths.buf_set_lines(0, 0, -1, true, { "line_1", "line_2", "line_3", "line_4"}) + meths.win_set_cursor(0, {2, 0}) + eq(2, meths.win_get_cursor(0)[1]) + meths.buf_set_lines(0, 0, -1, true, { "line_1", "line_2", "line_3"}) + eq(2, meths.win_get_cursor(0)[1]) + end) + it('does not SEGFAULT when calling win_findbuf in on_detach', function() exec_lua[[ @@ -272,26 +299,24 @@ describe('lua buffer event callbacks: on_lines', function() end) describe('lua: nvim_buf_attach on_bytes', function() - before_each(function() - clear() - attach_buffer('on_bytes') - end) - -- verifying the sizes with nvim_buf_get_offset is nice (checks we cannot -- assert the wrong thing), but masks errors with unflushed lines (as -- nvim_buf_get_offset forces a flush of the memline). To be safe run the -- test both ways. local function setup_eventcheck(verify, start_txt) - meths.buf_set_lines(0, 0, -1, true, start_txt) - local shadow = deepcopy(start_txt) - local shadowbytes = table.concat(shadow, '\n') .. '\n' + if start_txt then + meths.buf_set_lines(0, 0, -1, true, start_txt) + else + start_txt = meths.buf_get_lines(0, 0, -1, true) + end + local shadowbytes = table.concat(start_txt, '\n') .. '\n' -- TODO: while we are brewing the real strong coffe, -- verify should check buf_get_offset after every check_events if verify then local len = meths.buf_get_offset(0, meths.buf_line_count(0)) eq(len == -1 and 1 or len, string.len(shadowbytes)) end - exec_lua("return test_register(...)", 0, "test1", false, false, true) + exec_lua("return test_register(...)", 0, "on_bytes", "test1", false, false, true) meths.buf_get_changedtick(0) local verify_name = "test1" @@ -318,6 +343,8 @@ describe('lua: nvim_buf_attach on_bytes', function() local unknown = string.rep('\255', new_byte) local after = string.sub(shadowbytes, start_byte + old_byte + 1) shadowbytes = before .. unknown .. after + elseif event[1] == verify_name and event[2] == "reload" then + shadowbytes = table.concat(meths.buf_get_lines(0, 0, -1, true), '\n') .. '\n' end end @@ -495,20 +522,34 @@ describe('lua: nvim_buf_attach on_bytes', function() end) - it('inccomand=nosplit and substitute', function() - if verify then pending("Verification can't be done when previewing") end + it("linewise paste", function() + local check_events = setup_eventcheck(verify, origlines) + + feed'yyp' + check_events { + { "test1", "bytes", 1, 3, 1, 0, 16, 0, 0, 0, 1, 0, 16 }; + } + feed'Gyyp' + check_events { + { "test1", "bytes", 1, 4, 8, 0, 130, 0, 0, 0, 1, 0, 18 }; + } + end) + + it('inccomand=nosplit and substitute', function() local check_events = setup_eventcheck(verify, {"abcde"}) meths.set_option('inccommand', 'nosplit') feed ':%s/bcd/' check_events { { "test1", "bytes", 1, 3, 0, 1, 1, 0, 3, 3, 0, 0, 0 }; + { "test1", "bytes", 1, 5, 0, 1, 1, 0, 0, 0, 0, 3, 3 }; } feed 'a' check_events { { "test1", "bytes", 1, 3, 0, 1, 1, 0, 3, 3, 0, 1, 1 }; + { "test1", "bytes", 1, 5, 0, 1, 1, 0, 1, 1, 0, 3, 3 }; } end) @@ -575,6 +616,113 @@ describe('lua: nvim_buf_attach on_bytes', function() "original line 5", "original line 6" }, meths.buf_get_lines(0, 0, -1, true)) end) + + it('checktime autoread', function() + write_file("Xtest-reload", dedent [[ + old line 1 + old line 2]]) + lfs.touch("Xtest-reload", os.time() - 10) + command "e Xtest-reload" + command "set autoread" + + local check_events = setup_eventcheck(verify, nil) + + write_file("Xtest-reload", dedent [[ + new line 1 + new line 2 + new line 3]]) + + command "checktime" + check_events { + { "test1", "reload", 1 }; + } + + feed 'ggJ' + check_events { + { "test1", "bytes", 1, 5, 0, 10, 10, 1, 0, 1, 0, 1, 1 }; + } + + eq({'new line 1 new line 2', 'new line 3'}, meths.buf_get_lines(0, 0, -1, true)) + + -- check we can undo and redo a reload event. + feed 'u' + check_events { + { "test1", "bytes", 1, 8, 0, 10, 10, 0, 1, 1, 1, 0, 1 }; + } + + feed 'u' + check_events { + { "test1", "reload", 1 }; + } + + feed '<c-r>' + check_events { + { "test1", "reload", 1 }; + } + + feed '<c-r>' + check_events { + { "test1", "bytes", 1, 14, 0, 10, 10, 1, 0, 1, 0, 1, 1 }; + } + end) + + it("sends events when undoing with undofile", function() + write_file("Xtest-undofile", dedent([[ + 12345 + hello world + ]])) + + command("e! Xtest-undofile") + command("set undodir=. | set undofile") + + local ns = helpers.request('nvim_create_namespace', "ns1") + meths.buf_set_extmark(0, ns, 0, 0, {}) + + eq({"12345", "hello world"}, meths.buf_get_lines(0, 0, -1, true)) + + -- splice + feed("gg0d2l") + + eq({"345", "hello world"}, meths.buf_get_lines(0, 0, -1, true)) + + -- move + command(".m+1") + + eq({"hello world", "345"}, meths.buf_get_lines(0, 0, -1, true)) + + -- reload undofile and undo changes + command("w") + command("set noundofile") + command("bw!") + command("e! Xtest-undofile") + + command("set undofile") + + local check_events = setup_eventcheck(verify, nil) + + feed("u") + eq({"345", "hello world"}, meths.buf_get_lines(0, 0, -1, true)) + + check_events { + { "test1", "bytes", 2, 6, 1, 0, 12, 1, 0, 4, 0, 0, 0 }, + { "test1", "bytes", 2, 6, 0, 0, 0, 0, 0, 0, 1, 0, 4 } + } + + feed("u") + eq({"12345", "hello world"}, meths.buf_get_lines(0, 0, -1, true)) + + check_events { + { "test1", "bytes", 2, 8, 0, 0, 0, 0, 0, 0, 0, 2, 2 } + } + command("bw!") + end) + + + teardown(function() + os.remove "Xtest-reload" + os.remove "Xtest-undofile" + os.remove ".Xtest-undofile.un~" + end) end describe('(with verify) handles', function() diff --git a/test/functional/plugin/lsp/diagnostic_spec.lua b/test/functional/plugin/lsp/diagnostic_spec.lua index 4705a76465..8c91c4ab2c 100644 --- a/test/functional/plugin/lsp/diagnostic_spec.lua +++ b/test/functional/plugin/lsp/diagnostic_spec.lua @@ -208,6 +208,69 @@ describe('vim.lsp.diagnostic', function() ]])) end) + describe('reset', function() + it('diagnostic count is 0 and displayed diagnostics are 0 after call', function() + -- 1 Error (1) + -- 1 Warning (2) + -- 1 Warning (2) + 1 Warning (1) + -- 2 highlights and 2 underlines (since error) + -- 1 highlight + 1 underline + local all_highlights = {1, 1, 2, 4, 2} + eq(all_highlights, exec_lua [[ + local server_1_diags = { + make_error("Error 1", 1, 1, 1, 5), + make_warning("Warning on Server 1", 2, 1, 2, 5), + } + local server_2_diags = { + make_warning("Warning 1", 2, 1, 2, 5), + } + + vim.lsp.diagnostic.on_publish_diagnostics(nil, nil, { uri = fake_uri, diagnostics = server_1_diags }, 1) + vim.lsp.diagnostic.on_publish_diagnostics(nil, nil, { uri = fake_uri, diagnostics = server_2_diags }, 2) + return { + vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Error", 1), + vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Warning", 2), + vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Warning", nil), + count_of_extmarks_for_client(diagnostic_bufnr, 1), + count_of_extmarks_for_client(diagnostic_bufnr, 2), + } + ]]) + + -- Reset diagnostics from server 1 + exec_lua([[ vim.lsp.diagnostic.reset(1, { [ diagnostic_bufnr ] = { [ 1 ] = true ; [ 2 ] = true } } )]]) + + -- Make sure we have the right diagnostic count + eq({0, 1, 1, 0, 2} , exec_lua [[ + local diagnostic_count = {} + vim.wait(100, function () diagnostic_count = { + vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Error", 1), + vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Warning", 2), + vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Warning", nil), + count_of_extmarks_for_client(diagnostic_bufnr, 1), + count_of_extmarks_for_client(diagnostic_bufnr, 2), + } end ) + return diagnostic_count + ]]) + + -- Reset diagnostics from server 2 + exec_lua([[ vim.lsp.diagnostic.reset(2, { [ diagnostic_bufnr ] = { [ 1 ] = true ; [ 2 ] = true } } )]]) + + -- Make sure we have the right diagnostic count + eq({0, 0, 0, 0, 0}, exec_lua [[ + local diagnostic_count = {} + vim.wait(100, function () diagnostic_count = { + vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Error", 1), + vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Warning", 2), + vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Warning", nil), + count_of_extmarks_for_client(diagnostic_bufnr, 1), + count_of_extmarks_for_client(diagnostic_bufnr, 2), + } end ) + return diagnostic_count + ]]) + + end) + end) + describe('get_next_diagnostic_pos', function() it('can find the next pos with only one client', function() eq({1, 1}, exec_lua [[ diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 981e2a96a8..d5791fbbfa 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -41,10 +41,10 @@ local function fake_lsp_server_setup(test_name, timeout_ms) "-c", string.format("lua TIMEOUT = %d", timeout), "-c", "luafile "..fixture_filename, }; - callbacks = setmetatable({}, { + handlers = setmetatable({}, { __index = function(t, method) return function(...) - return vim.rpcrequest(1, 'callback', ...) + return vim.rpcrequest(1, 'handler', ...) end end; }); @@ -89,7 +89,7 @@ local function test_rpc_server(config) end return NIL end - if method == 'callback' then + if method == 'handler' then if config.on_callback then config.on_callback(unpack(args)) end @@ -205,7 +205,7 @@ describe('LSP', function() } test_rpc_server { test_name = "basic_init"; - on_init = function(client, _init_result) + on_init = function(client, _) -- client is a dummy object which will queue up commands to be run -- once the server initializes. It can't accept lua callbacks or -- other types that may be unserializable for now. @@ -257,6 +257,7 @@ describe('LSP', function() eq(0, client.resolved_capabilities().text_document_did_change) client.request('shutdown') client.notify('exit') + client.stop() end; on_exit = function(code, signal) eq(0, code, "exit code", fake_lsp_logfile) @@ -333,6 +334,7 @@ describe('LSP', function() client.stop() local full_kind = exec_lua("return require'vim.lsp.protocol'.TextDocumentSyncKind.Full") eq(full_kind, client.resolved_capabilities().text_document_did_change) + eq(true, client.resolved_capabilities().text_document_save) end; on_exit = function(code, signal) eq(0, code, "exit code", fake_lsp_logfile) @@ -386,7 +388,7 @@ describe('LSP', function() exec_lua([=[ BUFFER = vim.api.nvim_get_current_buf() lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID) - vim.lsp.callbacks['textDocument/typeDefinition'] = function(err, method) + vim.lsp.handlers['textDocument/typeDefinition'] = function(err, method) vim.lsp._last_lsp_callback = { err = err; method = method } end vim.lsp._unsupported_method = function(method) @@ -425,7 +427,7 @@ describe('LSP', function() test_name = "capabilities_for_client_supports_method"; on_setup = function() exec_lua([=[ - vim.lsp.callbacks['textDocument/typeDefinition'] = function(err, method) + vim.lsp.handlers['textDocument/typeDefinition'] = function(err, method) vim.lsp._last_lsp_callback = { err = err; method = method } end vim.lsp._unsupported_method = function(method) @@ -897,8 +899,8 @@ describe('LSP', function() eq(0, code, "exit code", fake_lsp_logfile) eq(0, signal, "exit signal", fake_lsp_logfile) end; - on_callback = function(err, method, params, client_id) - eq(table.remove(expected_callbacks), {err, method, params, client_id}, "expected callback") + on_handler = function(err, method, params, client_id) + eq(table.remove(expected_callbacks), {err, method, params, client_id}, "expected handler") end; } end) @@ -1032,6 +1034,20 @@ describe('LSP', function() 'å ä ɧ 汉语 ↥ 🤦 🦄'; }, buf_lines(1)) end) + it('applies text edits at the end of the document', function() + local edits = { + make_edit(5, 0, 5, 0, "foobar"); + } + exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1) + eq({ + 'First line of text'; + 'Second line of text'; + 'Third line of text'; + 'Fourth line of text'; + 'å å ɧ 汉语 ↥ 🤦 🦄'; + 'foobar'; + }, buf_lines(1)) + end) describe('with LSP end line after what Vim considers to be the end line', function() it('applies edits when the last linebreak is considered a new line', function() @@ -1765,8 +1781,8 @@ describe('LSP', function() uri = "file:///src/main.rs" } } } - local callback = require'vim.lsp.handlers'['callHierarchy/outgoingCalls'] - callback(nil, nil, rust_analyzer_response) + local handler = require'vim.lsp.handlers'['callHierarchy/outgoingCalls'] + handler(nil, nil, rust_analyzer_response) return vim.fn.getqflist() ]=]) @@ -1837,8 +1853,8 @@ describe('LSP', function() } } } } - local callback = require'vim.lsp.handlers'['callHierarchy/incomingCalls'] - callback(nil, nil, rust_analyzer_response) + local handler = require'vim.lsp.handlers'['callHierarchy/incomingCalls'] + handler(nil, nil, rust_analyzer_response) return vim.fn.getqflist() ]=]) diff --git a/test/functional/ui/decorations_spec.lua b/test/functional/ui/decorations_spec.lua index 781fdf7203..7a87521a6b 100644 --- a/test/functional/ui/decorations_spec.lua +++ b/test/functional/ui/decorations_spec.lua @@ -302,3 +302,98 @@ describe('decorations providers', function() ]]} end) end) + +describe('extmark decorations', function() + local screen + before_each( function() + clear() + screen = Screen.new(50, 15) + screen:attach() + screen:set_default_attr_ids { + [1] = {bold=true, foreground=Screen.colors.Blue}; + [2] = {foreground = Screen.colors.Brown}; + [3] = {bold = true, foreground = Screen.colors.SeaGreen}; + [4] = {background = Screen.colors.Red1, foreground = Screen.colors.Gray100}; + } + end) + + it('can have virtual text of overlay style', function() + insert [[ +for _,item in ipairs(items) do + local text, hl_id_cell, count = unpack(item) + if hl_id_cell ~= nil then + hl_id = hl_id_cell + end + for _ = 1, (count or 1) do + local cell = line[colpos] + cell.text = text + cell.hl_id = hl_id + colpos = colpos+1 + end +end]] + feed 'gg' + + local ns = meths.create_namespace 'test' + for i = 1,9 do + meths.buf_set_extmark(0, ns, i, 0, { virt_text={{'|', 'LineNr'}}, virt_text_pos='overlay'}) + if i == 3 or (i >= 6 and i <= 9) then + meths.buf_set_extmark(0, ns, i, 4, { virt_text={{'|', 'NonText'}}, virt_text_pos='overlay'}) + end + end + meths.buf_set_extmark(0, ns, 9, 10, { virt_text={{'foo'}, {'bar', 'MoreMsg'}, {'!!', 'ErrorMsg'}}, virt_text_pos='overlay'}) + + -- can "float" beyond end of line + meths.buf_set_extmark(0, ns, 5, 28, { virt_text={{'loopy', 'ErrorMsg'}}, virt_text_pos='overlay'}) + -- bound check: right edge of window + meths.buf_set_extmark(0, ns, 2, 26, { virt_text={{'bork bork bork ' }, {'bork bork bork', 'ErrorMsg'}}, virt_text_pos='overlay'}) + + screen:expect{grid=[[ + ^for _,item in ipairs(items) do | + {2:|} local text, hl_id_cell, count = unpack(item) | + {2:|} if hl_id_cell ~= nil tbork bork bork {4:bork bork}| + {2:|} {1:|} hl_id = hl_id_cell | + {2:|} end | + {2:|} for _ = 1, (count or 1) {4:loopy} | + {2:|} {1:|} local cell = line[colpos] | + {2:|} {1:|} cell.text = text | + {2:|} {1:|} cell.hl_id = hl_id | + {2:|} {1:|} cofoo{3:bar}{4:!!}olpos+1 | + end | + end | + {1:~ }| + {1:~ }| + | + ]]} + + + -- handles broken lines + screen:try_resize(22, 25) + screen:expect{grid=[[ + ^for _,item in ipairs(i| + tems) do | + {2:|} local text, hl_id_| + cell, count = unpack(i| + tem) | + {2:|} if hl_id_cell ~= n| + il tbork bork bork {4:bor}| + {2:|} {1:|} hl_id = hl_id_| + cell | + {2:|} end | + {2:|} for _ = 1, (count | + or 1) {4:loopy} | + {2:|} {1:|} local cell = l| + ine[colpos] | + {2:|} {1:|} cell.text = te| + xt | + {2:|} {1:|} cell.hl_id = h| + l_id | + {2:|} {1:|} cofoo{3:bar}{4:!!}olpo| + s+1 | + end | + end | + {1:~ }| + {1:~ }| + | + ]]} + end) +end) diff --git a/test/functional/ui/fold_spec.lua b/test/functional/ui/fold_spec.lua index 6ce8b33a63..d3b1d33956 100644 --- a/test/functional/ui/fold_spec.lua +++ b/test/functional/ui/fold_spec.lua @@ -38,7 +38,9 @@ describe("folded lines", function() [6] = {background = Screen.colors.Yellow}, [7] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.WebGray}, [8] = {foreground = Screen.colors.Brown }, - [9] = {bold = true, foreground = Screen.colors.Brown} + [9] = {bold = true, foreground = Screen.colors.Brown}, + [10] = {background = Screen.colors.LightGrey, underline = true}, + [11] = {bold=true}, }) end) @@ -290,6 +292,369 @@ describe("folded lines", function() end end) + it("works with split", function() + insert([[ + aa + bb + cc + dd + ee + ff]]) + feed_command('2') + command("set foldcolumn=1") + feed('zf3j') + feed_command('1') + feed('zf2j') + feed('zO') + feed_command("rightbelow new") + insert([[ + aa + bb + cc + dd + ee + ff]]) + feed_command('2') + command("set foldcolumn=1") + feed('zf3j') + feed_command('1') + feed('zf2j') + if multigrid then + meths.input_mouse('left', 'press', '', 4, 0, 0) + screen:expect([[ + ## grid 1 + [2:---------------------------------------------]| + [2:---------------------------------------------]| + {2:[No Name] [+] }| + [4:---------------------------------------------]| + [4:---------------------------------------------]| + [4:---------------------------------------------]| + {3:[No Name] [+] }| + [3:---------------------------------------------]| + ## grid 2 + {7:-}aa | + {7:-}bb | + ## grid 3 + :1 | + ## grid 4 + {7:-}^aa | + {7:+}{5:+--- 4 lines: bb···························}| + {7:│}ff | + ]]) + else + meths.input_mouse('left', 'press', '', 0, 3, 0) + screen:expect([[ + {7:-}aa | + {7:-}bb | + {2:[No Name] [+] }| + {7:-}^aa | + {7:+}{5:+--- 4 lines: bb···························}| + {7:│}ff | + {3:[No Name] [+] }| + :1 | + ]]) + end + + if multigrid then + meths.input_mouse('left', 'press', '', 4, 1, 0) + screen:expect([[ + ## grid 1 + [2:---------------------------------------------]| + [2:---------------------------------------------]| + {2:[No Name] [+] }| + [4:---------------------------------------------]| + [4:---------------------------------------------]| + [4:---------------------------------------------]| + {3:[No Name] [+] }| + [3:---------------------------------------------]| + ## grid 2 + {7:-}aa | + {7:-}bb | + ## grid 3 + :1 | + ## grid 4 + {7:-}^aa | + {7:-}bb | + {7:2}cc | + ]]) + else + meths.input_mouse('left', 'press', '', 0, 4, 0) + screen:expect([[ + {7:-}aa | + {7:-}bb | + {2:[No Name] [+] }| + {7:-}^aa | + {7:-}bb | + {7:2}cc | + {3:[No Name] [+] }| + :1 | + ]]) + end + + if multigrid then + meths.input_mouse('left', 'press', '', 2, 1, 0) + screen:expect([[ + ## grid 1 + [2:---------------------------------------------]| + [2:---------------------------------------------]| + {3:[No Name] [+] }| + [4:---------------------------------------------]| + [4:---------------------------------------------]| + [4:---------------------------------------------]| + {2:[No Name] [+] }| + [3:---------------------------------------------]| + ## grid 2 + {7:-}aa | + {7:+}{5:^+--- 4 lines: bb···························}| + ## grid 3 + :1 | + ## grid 4 + {7:-}aa | + {7:-}bb | + {7:2}cc | + ]]) + else + meths.input_mouse('left', 'press', '', 0, 1, 0) + screen:expect([[ + {7:-}aa | + {7:+}{5:^+--- 4 lines: bb···························}| + {3:[No Name] [+] }| + {7:-}aa | + {7:-}bb | + {7:2}cc | + {2:[No Name] [+] }| + :1 | + ]]) + end + + if multigrid then + meths.input_mouse('left', 'press', '', 2, 0, 0) + screen:expect([[ + ## grid 1 + [2:---------------------------------------------]| + [2:---------------------------------------------]| + {3:[No Name] [+] }| + [4:---------------------------------------------]| + [4:---------------------------------------------]| + [4:---------------------------------------------]| + {2:[No Name] [+] }| + [3:---------------------------------------------]| + ## grid 2 + {7:+}{5:^+-- 6 lines: aa····························}| + {1:~ }| + ## grid 3 + :1 | + ## grid 4 + {7:-}aa | + {7:-}bb | + {7:2}cc | + ]]) + else + meths.input_mouse('left', 'press', '', 0, 0, 0) + screen:expect([[ + {7:+}{5:^+-- 6 lines: aa····························}| + {1:~ }| + {3:[No Name] [+] }| + {7:-}aa | + {7:-}bb | + {7:2}cc | + {2:[No Name] [+] }| + :1 | + ]]) + end + end) + + it("works with tab", function() + insert([[ + aa + bb + cc + dd + ee + ff]]) + feed_command('2') + command("set foldcolumn=2") + feed('zf3j') + feed_command('1') + feed('zf2j') + feed('zO') + feed_command("tab split") + if multigrid then + meths.input_mouse('left', 'press', '', 4, 1, 1) + screen:expect([[ + ## grid 1 + {10: + [No Name] }{11: + [No Name] }{2: }{10:X}| + [4:---------------------------------------------]| + [4:---------------------------------------------]| + [4:---------------------------------------------]| + [4:---------------------------------------------]| + [4:---------------------------------------------]| + [4:---------------------------------------------]| + [3:---------------------------------------------]| + ## grid 2 (hidden) + {7:- }aa | + {7:│-}bb | + {7:││}cc | + {7:││}dd | + {7:││}ee | + {7:│ }ff | + {1:~ }| + ## grid 3 + :tab split | + ## grid 4 + {7:- }^aa | + {7:│+}{5:+--- 4 lines: bb··························}| + {7:│ }ff | + {1:~ }| + {1:~ }| + {1:~ }| + ]]) + else + meths.input_mouse('left', 'press', '', 0, 2, 1) + screen:expect([[ + {10: + [No Name] }{11: + [No Name] }{2: }{10:X}| + {7:- }^aa | + {7:│+}{5:+--- 4 lines: bb··························}| + {7:│ }ff | + {1:~ }| + {1:~ }| + {1:~ }| + :tab split | + ]]) + end + + if multigrid then + meths.input_mouse('left', 'press', '', 4, 0, 0) + screen:expect([[ + ## grid 1 + {10: + [No Name] }{11: + [No Name] }{2: }{10:X}| + [4:---------------------------------------------]| + [4:---------------------------------------------]| + [4:---------------------------------------------]| + [4:---------------------------------------------]| + [4:---------------------------------------------]| + [4:---------------------------------------------]| + [3:---------------------------------------------]| + ## grid 2 (hidden) + {7:- }aa | + {7:│-}bb | + {7:││}cc | + {7:││}dd | + {7:││}ee | + {7:│ }ff | + {1:~ }| + ## grid 3 + :tab split | + ## grid 4 + {7:+ }{5:^+-- 6 lines: aa···························}| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + ]]) + else + meths.input_mouse('left', 'press', '', 0, 1, 0) + screen:expect([[ + {10: + [No Name] }{11: + [No Name] }{2: }{10:X}| + {7:+ }{5:^+-- 6 lines: aa···························}| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + :tab split | + ]]) + end + + feed_command("tabnext") + if multigrid then + meths.input_mouse('left', 'press', '', 2, 1, 1) + screen:expect([[ + ## grid 1 + {11: + [No Name] }{10: + [No Name] }{2: }{10:X}| + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [3:---------------------------------------------]| + ## grid 2 + {7:- }^aa | + {7:│+}{5:+--- 4 lines: bb··························}| + {7:│ }ff | + {1:~ }| + {1:~ }| + {1:~ }| + ## grid 3 + :tabnext | + ## grid 4 (hidden) + {7:+ }{5:+-- 6 lines: aa···························}| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + ]]) + else + meths.input_mouse('left', 'press', '', 0, 2, 1) + screen:expect([[ + {11: + [No Name] }{10: + [No Name] }{2: }{10:X}| + {7:- }^aa | + {7:│+}{5:+--- 4 lines: bb··························}| + {7:│ }ff | + {1:~ }| + {1:~ }| + {1:~ }| + :tabnext | + ]]) + end + + if multigrid then + meths.input_mouse('left', 'press', '', 2, 0, 0) + screen:expect([[ + ## grid 1 + {11: + [No Name] }{10: + [No Name] }{2: }{10:X}| + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [2:---------------------------------------------]| + [3:---------------------------------------------]| + ## grid 2 + {7:+ }{5:^+-- 6 lines: aa···························}| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + ## grid 3 + :tabnext | + ## grid 4 (hidden) + {7:+ }{5:+-- 6 lines: aa···························}| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + ]]) + else + meths.input_mouse('left', 'press', '', 0, 1, 0) + screen:expect([[ + {11: + [No Name] }{10: + [No Name] }{2: }{10:X}| + {7:+ }{5:^+-- 6 lines: aa···························}| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + :tabnext | + ]]) + end + end) + it("works with multibyte text", function() -- Currently the only allowed value of 'maxcombine' eq(6, meths.get_option('maxcombine')) diff --git a/test/functional/ui/input_spec.lua b/test/functional/ui/input_spec.lua index 9313a35708..ea8968a653 100644 --- a/test/functional/ui/input_spec.lua +++ b/test/functional/ui/input_spec.lua @@ -1,16 +1,18 @@ local helpers = require('test.functional.helpers')(after_each) -local clear, feed_command, nvim = helpers.clear, helpers.feed_command, helpers.nvim +local clear, feed_command = helpers.clear, helpers.feed_command local feed, next_msg, eq = helpers.feed, helpers.next_msg, helpers.eq local command = helpers.command local expect = helpers.expect +local meths = helpers.meths +local exec_lua = helpers.exec_lua local write_file = helpers.write_file local Screen = require('test.functional.ui.screen') -describe('mappings', function() - local cid +before_each(clear) +describe('mappings', function() local add_mapping = function(mapping, send) - local cmd = "nnoremap "..mapping.." :call rpcnotify("..cid..", 'mapped', '" + local cmd = "nnoremap "..mapping.." :call rpcnotify(1, 'mapped', '" ..send:gsub('<', '<lt>').."')<cr>" feed_command(cmd) end @@ -21,8 +23,6 @@ describe('mappings', function() end before_each(function() - clear() - cid = nvim('get_api_info')[1] add_mapping('<C-L>', '<C-L>') add_mapping('<C-S-L>', '<C-S-L>') add_mapping('<s-up>', '<s-up>') @@ -115,7 +115,6 @@ describe('mappings', function() end) describe('input utf sequences that contain CSI/K_SPECIAL', function() - before_each(clear) it('ok', function() feed('i…<esc>') expect('…') @@ -129,7 +128,6 @@ describe('input non-printable chars', function() it("doesn't crash when echoing them back", function() write_file("Xtest-overwrite", [[foobar]]) - clear() local screen = Screen.new(60,8) screen:set_default_attr_ids({ [1] = {bold = true, foreground = Screen.colors.Blue1}, @@ -215,3 +213,27 @@ describe('input non-printable chars', function() ]]) end) end) + +describe("event processing and input", function() + it('not blocked by event bursts', function() + meths.set_keymap('', '<f2>', "<cmd>lua vim.rpcnotify(1, 'stop') winning = true <cr>", {noremap=true}) + + exec_lua [[ + winning = false + burst = vim.schedule_wrap(function(tell) + if tell then + vim.rpcnotify(1, 'start') + end + -- Are we winning, son? + if not winning then + burst(false) + end + end) + burst(true) + ]] + + eq({'notification', 'start', {}}, next_msg()) + feed '<f2>' + eq({'notification', 'stop', {}}, next_msg()) + end) +end) diff --git a/test/functional/ui/messages_spec.lua b/test/functional/ui/messages_spec.lua index 5df4a1d533..1fe3a4128e 100644 --- a/test/functional/ui/messages_spec.lua +++ b/test/functional/ui/messages_spec.lua @@ -29,6 +29,7 @@ describe('ui/ext_messages', function() [6] = {bold = true, reverse = true}, [7] = {background = Screen.colors.Yellow}, [8] = {foreground = Screen.colors.Red}, + [9] = {special = Screen.colors.Red, undercurl = true}, }) end) after_each(function() @@ -795,6 +796,45 @@ describe('ui/ext_messages', function() pos = 9, }}} end) + + it('hides prompt_for_number messages', function() + command('set spell') + feed('ihelllo<esc>') + + feed('z=') + screen:expect{grid=[[ + {9:helllo} | + {1:~ }| + {1:~ }| + {1:~ }| + {1:^~ }| + ]], messages={ + {content = { { 'Change "helllo" to:\n 1 "Hello"\n 2 "Hallo"\n 3 "Helli"\nType number and <Enter> or click with mouse (empty cancels): ' } }, kind = ""} + }} + + feed('1') + screen:expect{grid=[[ + {9:helllo} | + {1:~ }| + {1:~ }| + {1:~ }| + {1:^~ }| + ]], messages={ + {content = { { 'Change "helllo" to:\n 1 "Hello"\n 2 "Hallo"\n 3 "Helli"\nType number and <Enter> or click with mouse (empty cancels): ' } }, kind = ""}, + { content = { { "1" } }, kind = "" } + }} + + feed('<cr>') + screen:expect{grid=[[ + ^Hello | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + ]]} + + end) + end) describe('ui/builtin messages', function() |