From 7121983c45d92349a6532f32dcde9f425e30781e Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 16 Dec 2024 16:16:57 +0000 Subject: refactor(man.lua): various changes - Replace all uses of vim.regex with simpler Lua patterns. - Replace all uses of vim.fn.substitute with string.gsub. - Rework error handling so expected errors are passed back via a return. - These get routed up an passed to `vim.notify()` - Any other errors will cause a stack trace. - Reworked the module initialization of `localfile_arg` - Updated all type annotations. - Refactored CLI completion by introduction a parse_cmdline() function. - Simplified `show_toc()` - Refactor highlighting - Inline some functions - Fix completion on MacOS 13 and earlier. - Prefer `manpath -q` over `man -w` - Make completion more efficient by avoiding vim.fn.sort and vim.fn.uniq - Reimplement using a single loop --- runtime/plugin/man.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'runtime/plugin') diff --git a/runtime/plugin/man.lua b/runtime/plugin/man.lua index 512b1f63e8..d6d90208a2 100644 --- a/runtime/plugin/man.lua +++ b/runtime/plugin/man.lua @@ -8,9 +8,9 @@ vim.api.nvim_create_user_command('Man', function(params) if params.bang then man.init_pager() else - local ok, err = pcall(man.open_page, params.count, params.smods, params.fargs) - if not ok then - vim.notify(man.errormsg or err, vim.log.levels.ERROR) + local err = man.open_page(params.count, params.smods, params.fargs) + if err then + vim.notify('man.lua: ' .. err, vim.log.levels.ERROR) end end end, { @@ -31,6 +31,9 @@ vim.api.nvim_create_autocmd('BufReadCmd', { pattern = 'man://*', nested = true, callback = function(params) - require('man').read_page(vim.fn.matchstr(params.match, 'man://\\zs.*')) + local err = require('man').read_page(assert(params.match:match('man://(.*)'))) + if err then + vim.notify('man.lua: ' .. err, vim.log.levels.ERROR) + end end, }) -- cgit From 39781be14baff508efd4f99c11786c4228ea2c8d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 20 Dec 2024 11:33:05 +0800 Subject: vim-patch:c363ca1: runtime(netrw): change indent size from 1 to 2 (#31648) closes: vim/vim#16248 https://github.com/vim/vim/commit/c363ca1ecd1f8db03663ef98dcf41eeacc3c22c7 Co-authored-by: Luca Saccarola --- runtime/plugin/netrwPlugin.vim | 247 +++++++++++++++++++++-------------------- 1 file changed, 124 insertions(+), 123 deletions(-) (limited to 'runtime/plugin') diff --git a/runtime/plugin/netrwPlugin.vim b/runtime/plugin/netrwPlugin.vim index 775b650e71..d534b36966 100644 --- a/runtime/plugin/netrwPlugin.vim +++ b/runtime/plugin/netrwPlugin.vim @@ -1,12 +1,13 @@ " netrwPlugin.vim: Handles file transfer and remote directory listing across a network " PLUGIN SECTION -" Maintainer: This runtime file is looking for a new maintainer. -" Date: Sep 09, 2021 +" Maintainer: This runtime file is looking for a new maintainer. +" Date: Sep 09, 2021 " Last Change: " 2024 May 08 by Vim Project: cleanup legacy Win9X checks " 2024 Oct 27 by Vim Project: cleanup gx mapping " 2024 Oct 28 by Vim Project: further improvements " 2024 Oct 31 by Vim Project: use autoloaded functions +" 2024 Dec 19 by Vim Project: change style (#16248) " Former Maintainer: Charles E Campbell " GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim " Copyright: Copyright (C) 1999-2021 Charles E. Campbell {{{1 @@ -24,7 +25,7 @@ " =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- " Load Once: {{{1 if &cp || exists("g:loaded_netrwPlugin") - finish + finish endif let g:loaded_netrwPlugin = "v173" let s:keepcpo = &cpo @@ -40,71 +41,71 @@ command -complete=file -nargs=1 Open call netrw#Open(trim()) " " }}} " Local Browsing Autocmds: {{{2 augroup FileExplorer - au! - au BufLeave * if &ft != "netrw"|let w:netrw_prvfile= expand("%:p")|endif - au BufEnter * sil call s:LocalBrowse(expand("")) - au VimEnter * sil call s:VimEnter(expand("")) - if has("win32") - au BufEnter .* sil call s:LocalBrowse(expand("")) - endif + au! + au BufLeave * if &ft != "netrw"|let w:netrw_prvfile= expand("%:p")|endif + au BufEnter * sil call s:LocalBrowse(expand("")) + au VimEnter * sil call s:VimEnter(expand("")) + if has("win32") + au BufEnter .* sil call s:LocalBrowse(expand("")) + endif augroup END " Network Browsing Reading Writing: {{{2 augroup Network - au! - au BufReadCmd file://* call netrw#FileUrlEdit(expand("")) - au BufReadCmd ftp://*,rcp://*,scp://*,http://*,https://*,dav://*,davs://*,rsync://*,sftp://* exe "sil doau BufReadPre ".fnameescape(expand(""))|call netrw#Nread(2,expand(""))|exe "sil doau BufReadPost ".fnameescape(expand("")) - au FileReadCmd ftp://*,rcp://*,scp://*,http://*,file://*,https://*,dav://*,davs://*,rsync://*,sftp://* exe "sil doau FileReadPre ".fnameescape(expand(""))|call netrw#Nread(1,expand(""))|exe "sil doau FileReadPost ".fnameescape(expand("")) - au BufWriteCmd ftp://*,rcp://*,scp://*,http://*,file://*,dav://*,davs://*,rsync://*,sftp://* exe "sil doau BufWritePre ".fnameescape(expand(""))|exe 'Nwrite '.fnameescape(expand(""))|exe "sil doau BufWritePost ".fnameescape(expand("")) - au FileWriteCmd ftp://*,rcp://*,scp://*,http://*,file://*,dav://*,davs://*,rsync://*,sftp://* exe "sil doau FileWritePre ".fnameescape(expand(""))|exe "'[,']".'Nwrite '.fnameescape(expand(""))|exe "sil doau FileWritePost ".fnameescape(expand("")) - try - au SourceCmd ftp://*,rcp://*,scp://*,http://*,file://*,https://*,dav://*,davs://*,rsync://*,sftp://* exe 'Nsource '.fnameescape(expand("")) - catch /^Vim\%((\a\+)\)\=:E216/ - au SourcePre ftp://*,rcp://*,scp://*,http://*,file://*,https://*,dav://*,davs://*,rsync://*,sftp://* exe 'Nsource '.fnameescape(expand("")) - endtry + au! + au BufReadCmd file://* call netrw#FileUrlEdit(expand("")) + au BufReadCmd ftp://*,rcp://*,scp://*,http://*,https://*,dav://*,davs://*,rsync://*,sftp://* exe "sil doau BufReadPre ".fnameescape(expand(""))|call netrw#Nread(2,expand(""))|exe "sil doau BufReadPost ".fnameescape(expand("")) + au FileReadCmd ftp://*,rcp://*,scp://*,http://*,file://*,https://*,dav://*,davs://*,rsync://*,sftp://* exe "sil doau FileReadPre ".fnameescape(expand(""))|call netrw#Nread(1,expand(""))|exe "sil doau FileReadPost ".fnameescape(expand("")) + au BufWriteCmd ftp://*,rcp://*,scp://*,http://*,file://*,dav://*,davs://*,rsync://*,sftp://* exe "sil doau BufWritePre ".fnameescape(expand(""))|exe 'Nwrite '.fnameescape(expand(""))|exe "sil doau BufWritePost ".fnameescape(expand("")) + au FileWriteCmd ftp://*,rcp://*,scp://*,http://*,file://*,dav://*,davs://*,rsync://*,sftp://* exe "sil doau FileWritePre ".fnameescape(expand(""))|exe "'[,']".'Nwrite '.fnameescape(expand(""))|exe "sil doau FileWritePost ".fnameescape(expand("")) + try + au SourceCmd ftp://*,rcp://*,scp://*,http://*,file://*,https://*,dav://*,davs://*,rsync://*,sftp://* exe 'Nsource '.fnameescape(expand("")) + catch /^Vim\%((\a\+)\)\=:E216/ + au SourcePre ftp://*,rcp://*,scp://*,http://*,file://*,https://*,dav://*,davs://*,rsync://*,sftp://* exe 'Nsource '.fnameescape(expand("")) + endtry augroup END " Commands: :Nread, :Nwrite, :NetUserPass {{{2 -com! -count=1 -nargs=* Nread let s:svpos= winsaveview()call netrw#NetRead(,)call winrestview(s:svpos) -com! -range=% -nargs=* Nwrite let s:svpos= winsaveview(),call netrw#NetWrite()call winrestview(s:svpos) -com! -nargs=* NetUserPass call NetUserPass() -com! -nargs=* Nsource let s:svpos= winsaveview()call netrw#NetSource()call winrestview(s:svpos) -com! -nargs=? Ntree call netrw#SetTreetop(1,) +com! -count=1 -nargs=* Nread let s:svpos= winsaveview()call netrw#NetRead(,)call winrestview(s:svpos) +com! -range=% -nargs=* Nwrite let s:svpos= winsaveview(),call netrw#NetWrite()call winrestview(s:svpos) +com! -nargs=* NetUserPass call NetUserPass() +com! -nargs=* Nsource let s:svpos= winsaveview()call netrw#NetSource()call winrestview(s:svpos) +com! -nargs=? Ntree call netrw#SetTreetop(1,) " Commands: :Explore, :Sexplore, Hexplore, Vexplore, Lexplore {{{2 -com! -nargs=* -bar -bang -count=0 -complete=dir Explore call netrw#Explore(,0,0+0,) -com! -nargs=* -bar -bang -count=0 -complete=dir Sexplore call netrw#Explore(,1,0+0,) -com! -nargs=* -bar -bang -count=0 -complete=dir Hexplore call netrw#Explore(,1,2+0,) -com! -nargs=* -bar -bang -count=0 -complete=dir Vexplore call netrw#Explore(,1,4+0,) -com! -nargs=* -bar -count=0 -complete=dir Texplore call netrw#Explore(,0,6 ,) -com! -nargs=* -bar -bang Nexplore call netrw#Explore(-1,0,0,) -com! -nargs=* -bar -bang Pexplore call netrw#Explore(-2,0,0,) -com! -nargs=* -bar -bang -count=0 -complete=dir Lexplore call netrw#Lexplore(,0,) +com! -nargs=* -bar -bang -count=0 -complete=dir Explore call netrw#Explore(,0,0+0,) +com! -nargs=* -bar -bang -count=0 -complete=dir Sexplore call netrw#Explore(,1,0+0,) +com! -nargs=* -bar -bang -count=0 -complete=dir Hexplore call netrw#Explore(,1,2+0,) +com! -nargs=* -bar -bang -count=0 -complete=dir Vexplore call netrw#Explore(,1,4+0,) +com! -nargs=* -bar -count=0 -complete=dir Texplore call netrw#Explore(,0,6 ,) +com! -nargs=* -bar -bang Nexplore call netrw#Explore(-1,0,0,) +com! -nargs=* -bar -bang Pexplore call netrw#Explore(-2,0,0,) +com! -nargs=* -bar -bang -count=0 -complete=dir Lexplore call netrw#Lexplore(,0,) " Commands: NetrwSettings {{{2 -com! -nargs=0 NetrwSettings call netrwSettings#NetrwSettings() -com! -bang NetrwClean call netrw#Clean(0) +com! -nargs=0 NetrwSettings call netrwSettings#NetrwSettings() +com! -bang NetrwClean call netrw#Clean(0) " Maps: if !exists("g:netrw_nogx") - if maparg('gx','n') == "" - if !hasmapto('NetrwBrowseX') - nmap gx NetrwBrowseX + if maparg('gx','n') == "" + if !hasmapto('NetrwBrowseX') + nmap gx NetrwBrowseX + endif + nno NetrwBrowseX :call netrw#BrowseX(netrw#GX(),netrw#CheckIfRemote(netrw#GX())) endif - nno NetrwBrowseX :call netrw#BrowseX(netrw#GX(),netrw#CheckIfRemote(netrw#GX())) - endif - if maparg('gx','x') == "" - if !hasmapto('NetrwBrowseXVis') - xmap gx NetrwBrowseXVis + if maparg('gx','x') == "" + if !hasmapto('NetrwBrowseXVis') + xmap gx NetrwBrowseXVis + endif + xno NetrwBrowseXVis :call netrw#BrowseXVis() endif - xno NetrwBrowseXVis :call netrw#BrowseXVis() - endif endif if exists("g:netrw_usetab") && g:netrw_usetab - if maparg('','n') == "" - nmap NetrwShrink - endif - nno NetrwShrink :call netrw#Shrink() + if maparg('','n') == "" + nmap NetrwShrink + endif + nno NetrwShrink :call netrw#Shrink() endif " --------------------------------------------------------------------- @@ -115,43 +116,43 @@ fun! s:LocalBrowse(dirname) " the DBG buffer are made. if !exists("s:vimentered") - " If s:vimentered doesn't exist, then the VimEnter event hasn't fired. It will, - " and so s:VimEnter() will then be calling this routine, but this time with s:vimentered defined. -" call Dfunc("s:LocalBrowse(dirname<".a:dirname.">) (s:vimentered doesn't exist)") -" call Dret("s:LocalBrowse") - return + " If s:vimentered doesn't exist, then the VimEnter event hasn't fired. It will, + " and so s:VimEnter() will then be calling this routine, but this time with s:vimentered defined. + " call Dfunc("s:LocalBrowse(dirname<".a:dirname.">) (s:vimentered doesn't exist)") + " call Dret("s:LocalBrowse") + return endif -" call Dfunc("s:LocalBrowse(dirname<".a:dirname.">) (s:vimentered=".s:vimentered.")") + " call Dfunc("s:LocalBrowse(dirname<".a:dirname.">) (s:vimentered=".s:vimentered.")") if has("amiga") - " The check against '' is made for the Amiga, where the empty - " string is the current directory and not checking would break - " things such as the help command. -" call Decho("(LocalBrowse) dirname<".a:dirname."> (isdirectory, amiga)") - if a:dirname != '' && isdirectory(a:dirname) - sil! call netrw#LocalBrowseCheck(a:dirname) - if exists("w:netrw_bannercnt") && line('.') < w:netrw_bannercnt - exe w:netrw_bannercnt + " The check against '' is made for the Amiga, where the empty + " string is the current directory and not checking would break + " things such as the help command. + " call Decho("(LocalBrowse) dirname<".a:dirname."> (isdirectory, amiga)") + if a:dirname != '' && isdirectory(a:dirname) + sil! call netrw#LocalBrowseCheck(a:dirname) + if exists("w:netrw_bannercnt") && line('.') < w:netrw_bannercnt + exe w:netrw_bannercnt + endif endif - endif elseif isdirectory(a:dirname) -" call Decho("(LocalBrowse) dirname<".a:dirname."> ft=".&ft." (isdirectory, not amiga)") -" call Dredir("LocalBrowse ft last set: ","verbose set ft") - " Jul 13, 2021: for whatever reason, preceding the following call with - " a sil! causes an unbalanced if-endif vim error - call netrw#LocalBrowseCheck(a:dirname) - if exists("w:netrw_bannercnt") && line('.') < w:netrw_bannercnt - exe w:netrw_bannercnt - endif + " call Decho("(LocalBrowse) dirname<".a:dirname."> ft=".&ft." (isdirectory, not amiga)") + " call Dredir("LocalBrowse ft last set: ","verbose set ft") + " Jul 13, 2021: for whatever reason, preceding the following call with + " a sil! causes an unbalanced if-endif vim error + call netrw#LocalBrowseCheck(a:dirname) + if exists("w:netrw_bannercnt") && line('.') < w:netrw_bannercnt + exe w:netrw_bannercnt + endif else - " not a directory, ignore it -" call Decho("(LocalBrowse) dirname<".a:dirname."> not a directory, ignoring...") + " not a directory, ignore it + " call Decho("(LocalBrowse) dirname<".a:dirname."> not a directory, ignoring...") endif -" call Dret("s:LocalBrowse") + " call Dret("s:LocalBrowse") endfun " --------------------------------------------------------------------- @@ -162,72 +163,72 @@ endfun " It also sets s:vimentered, letting s:LocalBrowse() know that s:VimEnter() " has already been called. fun! s:VimEnter(dirname) -" call Dfunc("s:VimEnter(dirname<".a:dirname.">) expand(%)<".expand("%").">") + " call Dfunc("s:VimEnter(dirname<".a:dirname.">) expand(%)<".expand("%").">") if has('nvim') || v:version < 802 - " Johann Höchtl: reported that the call range... line causes an E488: Trailing characters - " error with neovim. I suspect its because neovim hasn't updated with recent - " vim patches. As is, this code will have problems with popup terminals - " instantiated before the VimEnter event runs. - " Ingo Karkat : E488 also in Vim 8.1.1602 - let curwin = winnr() - let s:vimentered = 1 - windo call s:LocalBrowse(expand("%:p")) - exe curwin."wincmd w" - else - " the following complicated expression comes courtesy of lacygoill; largely does the same thing as the windo and - " wincmd which are commented out, but avoids some side effects. Allows popup terminal before VimEnter. - let s:vimentered = 1 - call range(1, winnr('$'))->map({_, v -> win_execute(win_getid(v), 'call expand("%:p")->s:LocalBrowse()')}) - endif -" call Dret("s:VimEnter") + " Johann Höchtl: reported that the call range... line causes an E488: Trailing characters + " error with neovim. I suspect its because neovim hasn't updated with recent + " vim patches. As is, this code will have problems with popup terminals + " instantiated before the VimEnter event runs. + " Ingo Karkat : E488 also in Vim 8.1.1602 + let curwin = winnr() + let s:vimentered = 1 + windo call s:LocalBrowse(expand("%:p")) + exe curwin."wincmd w" + else + " the following complicated expression comes courtesy of lacygoill; largely does the same thing as the windo and + " wincmd which are commented out, but avoids some side effects. Allows popup terminal before VimEnter. + let s:vimentered = 1 + call range(1, winnr('$'))->map({_, v -> win_execute(win_getid(v), 'call expand("%:p")->s:LocalBrowse()')}) + endif + " call Dret("s:VimEnter") endfun " --------------------------------------------------------------------- " NetrwStatusLine: {{{1 fun! NetrwStatusLine() -" let g:stlmsg= "Xbufnr=".w:netrw_explore_bufnr." bufnr=".bufnr("%")." Xline#".w:netrw_explore_line." line#".line(".") + " let g:stlmsg= "Xbufnr=".w:netrw_explore_bufnr." bufnr=".bufnr("%")." Xline#".w:netrw_explore_line." line#".line(".") if !exists("w:netrw_explore_bufnr") || w:netrw_explore_bufnr != bufnr("%") || !exists("w:netrw_explore_line") || w:netrw_explore_line != line(".") || !exists("w:netrw_explore_list") - let &stl= s:netrw_explore_stl - if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif - if exists("w:netrw_explore_line")|unlet w:netrw_explore_line|endif - return "" + let &stl= s:netrw_explore_stl + if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif + if exists("w:netrw_explore_line")|unlet w:netrw_explore_line|endif + return "" else - return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen + return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen endif endfun " ------------------------------------------------------------------------ " NetUserPass: set username and password for subsequent ftp transfer {{{1 -" Usage: :call NetUserPass() -- will prompt for userid and password -" :call NetUserPass("uid") -- will prompt for password -" :call NetUserPass("uid","password") -- sets global userid and password +" Usage: :call NetUserPass() -- will prompt for userid and password +" :call NetUserPass("uid") -- will prompt for password +" :call NetUserPass("uid","password") -- sets global userid and password fun! NetUserPass(...) - " get/set userid - if a:0 == 0 -" call Dfunc("NetUserPass(a:0<".a:0.">)") - if !exists("g:netrw_uid") || g:netrw_uid == "" - " via prompt - let g:netrw_uid= input('Enter username: ') + " get/set userid + if a:0 == 0 + " call Dfunc("NetUserPass(a:0<".a:0.">)") + if !exists("g:netrw_uid") || g:netrw_uid == "" + " via prompt + let g:netrw_uid= input('Enter username: ') + endif + else " from command line + " call Dfunc("NetUserPass(a:1<".a:1.">) {") + let g:netrw_uid= a:1 + endif + + " get password + if a:0 <= 1 " via prompt + " call Decho("a:0=".a:0." case <=1:") + let g:netrw_passwd= inputsecret("Enter Password: ") + else " from command line + " call Decho("a:0=".a:0." case >1: a:2<".a:2.">") + let g:netrw_passwd=a:2 endif - else " from command line -" call Dfunc("NetUserPass(a:1<".a:1.">) {") - let g:netrw_uid= a:1 - endif - - " get password - if a:0 <= 1 " via prompt -" call Decho("a:0=".a:0." case <=1:") - let g:netrw_passwd= inputsecret("Enter Password: ") - else " from command line -" call Decho("a:0=".a:0." case >1: a:2<".a:2.">") - let g:netrw_passwd=a:2 - endif -" call Dret("NetUserPass") + " call Dret("NetUserPass") endfun " ------------------------------------------------------------------------ " Modelines And Restoration: {{{1 let &cpo= s:keepcpo unlet s:keepcpo -" vim:ts=8 fdm=marker +" vim:ts=8 sts=2 sw=2 et fdm=marker -- cgit From a389dc2f950ef89492dfc2d8334e421d2252cddf Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Tue, 31 Dec 2024 09:59:03 -0600 Subject: feat(clipboard)!: use OSC 52 as fallback clipboard provider (#31730) We currently enable the OSC 52 clipboard provider by setting g:clipboard when a list of conditions are met, one of which is that $SSH_TTY must be set. We include this condition because often OSC 52 is not the best clipboard provider, so if there are "local" providers available Nvim should prefer those over OSC 52. However, if no other providers are available, Nvim should use OSC 52 even when $SSH_TTY is not set. When a user is in an SSH session then the checks for the other clipboard providers will still (typically) fail, so OSC 52 continues to be enabled by default in SSH sessions. This is marked as a breaking change because there are some cases where OSC 52 wasn't enabled before and is now (or vice versa). --- runtime/plugin/osc52.lua | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) (limited to 'runtime/plugin') diff --git a/runtime/plugin/osc52.lua b/runtime/plugin/osc52.lua index 7ffd64342e..c7f1cbe2e3 100644 --- a/runtime/plugin/osc52.lua +++ b/runtime/plugin/osc52.lua @@ -6,7 +6,15 @@ for _, ui in ipairs(vim.api.nvim_list_uis()) do end end -if not tty or vim.g.clipboard ~= nil or vim.o.clipboard ~= '' or not os.getenv('SSH_TTY') then +-- Do not query when any of the following is true: +-- * TUI is not attached +-- * OSC 52 support is explicitly disabled via g:termfeatures +-- * Using a badly behaved terminal +if + not tty + or (vim.g.termfeatures ~= nil and vim.g.termfeatures.osc52 == false) + or vim.env.TERM_PROGRAM == 'Apple_Terminal' +then return end @@ -17,28 +25,13 @@ require('vim.termcap').query('Ms', function(cap, found, seq) assert(cap == 'Ms') - -- Check 'clipboard' and g:clipboard again to avoid a race condition - if vim.o.clipboard ~= '' or vim.g.clipboard ~= nil then - return - end - -- If the terminal reports a sequence other than OSC 52 for the Ms capability -- then ignore it. We only support OSC 52 (for now) if not seq or not seq:match('^\027%]52') then return end - local osc52 = require('vim.ui.clipboard.osc52') - - vim.g.clipboard = { - name = 'OSC 52', - copy = { - ['+'] = osc52.copy('+'), - ['*'] = osc52.copy('*'), - }, - paste = { - ['+'] = osc52.paste('+'), - ['*'] = osc52.paste('*'), - }, - } + local termfeatures = vim.g.termfeatures or {} + termfeatures.osc52 = true + vim.g.termfeatures = termfeatures end) -- cgit From 69aa33d890468c1024beef0d97d0f9424516c9ef Mon Sep 17 00:00:00 2001 From: Emilia Simmons Date: Sun, 15 Dec 2024 13:28:16 -0500 Subject: fix(runtime): let matchit and matchparen skips fallback on treesitter captures When treesitter is enabled, by default syntax groups are not defined, but these groups are used to identify where to skip matches in matchit and matchparen. This patch does three things: 1. If syntax is enabled regardless of treesitter (`vim.bo.syntax='on'`): Use original implementation. 2. If treesitter is enabled and syntax is not: Match the syntax groups (i.e. `comment\|string`) against treesitter captures to check for skipped groups. 3. Add an explicit treesitter syntax for marking captures to skip: matchit uses `b:match_skip` to determine what counts as skippable Where 's:comment\|string' uses a match of the named syntax groups against a regex match of comment\|string, 't:comment\|string' now uses vim regex to match against the names of the treesitter capture groups. --- runtime/plugin/matchparen.vim | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'runtime/plugin') diff --git a/runtime/plugin/matchparen.vim b/runtime/plugin/matchparen.vim index 661a34b578..13d1b6824f 100644 --- a/runtime/plugin/matchparen.vim +++ b/runtime/plugin/matchparen.vim @@ -109,6 +109,10 @@ func s:Highlight_Matching_Pair() if !has("syntax") || !exists("g:syntax_on") let s_skip = "0" + elseif exists("b:ts_highlight") && &syntax != 'on' + let s_skip = "match(v:lua.vim.treesitter.get_captures_at_cursor(), '" + \ .. 'string\|character\|singlequote\|escape\|symbol\|comment' + \ .. "') != -1" else " Build an expression that detects whether the current cursor position is " in certain syntax types (string, comment, etc.), for use as -- cgit From 09e01437c968be4c6e9f6bb3ac8811108c58008c Mon Sep 17 00:00:00 2001 From: Maria José Solano Date: Mon, 13 Jan 2025 19:45:11 -0800 Subject: refactor: use nvim.foo.bar format for autocommand groups --- runtime/plugin/editorconfig.lua | 2 +- runtime/plugin/man.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'runtime/plugin') diff --git a/runtime/plugin/editorconfig.lua b/runtime/plugin/editorconfig.lua index a96919e1fe..357146cabd 100644 --- a/runtime/plugin/editorconfig.lua +++ b/runtime/plugin/editorconfig.lua @@ -1,4 +1,4 @@ -local group = vim.api.nvim_create_augroup('editorconfig', {}) +local group = vim.api.nvim_create_augroup('nvim.editorconfig', {}) vim.api.nvim_create_autocmd({ 'BufNewFile', 'BufRead', 'BufFilePost' }, { group = group, callback = function(args) diff --git a/runtime/plugin/man.lua b/runtime/plugin/man.lua index d6d90208a2..e707b68859 100644 --- a/runtime/plugin/man.lua +++ b/runtime/plugin/man.lua @@ -24,7 +24,7 @@ end, { end, }) -local augroup = vim.api.nvim_create_augroup('man', {}) +local augroup = vim.api.nvim_create_augroup('nvim.man', {}) vim.api.nvim_create_autocmd('BufReadCmd', { group = augroup, -- cgit From e962167245755e900a7bd154075106026dbb4eff Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Fri, 17 Jan 2025 13:48:47 +0100 Subject: vim-patch:9cfdabb: runtime(netrw): change netrw maintainer Dr. Chip retired some time ago and is no longer maintaining the netrw plugin. However as a runtime plugin distributed by Vim, it important to maintain the netrw plugin in the future and fix bugs as they are reported. So, split out the netrw plugin as an additional package, however include some stubs to make sure the plugin is still loaded by default and the documentation is accessible as well. closes: vim/vim#16368 https://github.com/vim/vim/commit/9cfdabb074feefc9848e9f7a4538f201e28c7f06 Co-authored-by: Luca Saccarola --- runtime/plugin/netrwPlugin.vim | 235 +---------------------------------------- 1 file changed, 5 insertions(+), 230 deletions(-) (limited to 'runtime/plugin') diff --git a/runtime/plugin/netrwPlugin.vim b/runtime/plugin/netrwPlugin.vim index d534b36966..6d7a8660ff 100644 --- a/runtime/plugin/netrwPlugin.vim +++ b/runtime/plugin/netrwPlugin.vim @@ -1,234 +1,9 @@ -" netrwPlugin.vim: Handles file transfer and remote directory listing across a network -" PLUGIN SECTION -" Maintainer: This runtime file is looking for a new maintainer. -" Date: Sep 09, 2021 -" Last Change: -" 2024 May 08 by Vim Project: cleanup legacy Win9X checks -" 2024 Oct 27 by Vim Project: cleanup gx mapping -" 2024 Oct 28 by Vim Project: further improvements -" 2024 Oct 31 by Vim Project: use autoloaded functions -" 2024 Dec 19 by Vim Project: change style (#16248) -" Former Maintainer: Charles E Campbell -" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim -" Copyright: Copyright (C) 1999-2021 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, -" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided -" *as is* and comes with no warranty of any kind, either -" 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. -" -" But be doers of the Word, and not only hearers, deluding your own selves {{{1 -" (James 1:22 RSV) -" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -" Load Once: {{{1 -if &cp || exists("g:loaded_netrwPlugin") - finish -endif -let g:loaded_netrwPlugin = "v173" -let s:keepcpo = &cpo -set cpo&vim -"DechoRemOn - -" --------------------------------------------------------------------- -" Public Interface: {{{1 - -" Commands Launch/URL {{{2 -command -complete=shellcmd -nargs=1 Launch call netrw#Launch(trim()) -command -complete=file -nargs=1 Open call netrw#Open(trim()) -" " }}} -" Local Browsing Autocmds: {{{2 -augroup FileExplorer - au! - au BufLeave * if &ft != "netrw"|let w:netrw_prvfile= expand("%:p")|endif - au BufEnter * sil call s:LocalBrowse(expand("")) - au VimEnter * sil call s:VimEnter(expand("")) - if has("win32") - au BufEnter .* sil call s:LocalBrowse(expand("")) - endif -augroup END - -" Network Browsing Reading Writing: {{{2 -augroup Network - au! - au BufReadCmd file://* call netrw#FileUrlEdit(expand("")) - au BufReadCmd ftp://*,rcp://*,scp://*,http://*,https://*,dav://*,davs://*,rsync://*,sftp://* exe "sil doau BufReadPre ".fnameescape(expand(""))|call netrw#Nread(2,expand(""))|exe "sil doau BufReadPost ".fnameescape(expand("")) - au FileReadCmd ftp://*,rcp://*,scp://*,http://*,file://*,https://*,dav://*,davs://*,rsync://*,sftp://* exe "sil doau FileReadPre ".fnameescape(expand(""))|call netrw#Nread(1,expand(""))|exe "sil doau FileReadPost ".fnameescape(expand("")) - au BufWriteCmd ftp://*,rcp://*,scp://*,http://*,file://*,dav://*,davs://*,rsync://*,sftp://* exe "sil doau BufWritePre ".fnameescape(expand(""))|exe 'Nwrite '.fnameescape(expand(""))|exe "sil doau BufWritePost ".fnameescape(expand("")) - au FileWriteCmd ftp://*,rcp://*,scp://*,http://*,file://*,dav://*,davs://*,rsync://*,sftp://* exe "sil doau FileWritePre ".fnameescape(expand(""))|exe "'[,']".'Nwrite '.fnameescape(expand(""))|exe "sil doau FileWritePost ".fnameescape(expand("")) - try - au SourceCmd ftp://*,rcp://*,scp://*,http://*,file://*,https://*,dav://*,davs://*,rsync://*,sftp://* exe 'Nsource '.fnameescape(expand("")) - catch /^Vim\%((\a\+)\)\=:E216/ - au SourcePre ftp://*,rcp://*,scp://*,http://*,file://*,https://*,dav://*,davs://*,rsync://*,sftp://* exe 'Nsource '.fnameescape(expand("")) - endtry -augroup END - -" Commands: :Nread, :Nwrite, :NetUserPass {{{2 -com! -count=1 -nargs=* Nread let s:svpos= winsaveview()call netrw#NetRead(,)call winrestview(s:svpos) -com! -range=% -nargs=* Nwrite let s:svpos= winsaveview(),call netrw#NetWrite()call winrestview(s:svpos) -com! -nargs=* NetUserPass call NetUserPass() -com! -nargs=* Nsource let s:svpos= winsaveview()call netrw#NetSource()call winrestview(s:svpos) -com! -nargs=? Ntree call netrw#SetTreetop(1,) +" Load the netrw package. -" Commands: :Explore, :Sexplore, Hexplore, Vexplore, Lexplore {{{2 -com! -nargs=* -bar -bang -count=0 -complete=dir Explore call netrw#Explore(,0,0+0,) -com! -nargs=* -bar -bang -count=0 -complete=dir Sexplore call netrw#Explore(,1,0+0,) -com! -nargs=* -bar -bang -count=0 -complete=dir Hexplore call netrw#Explore(,1,2+0,) -com! -nargs=* -bar -bang -count=0 -complete=dir Vexplore call netrw#Explore(,1,4+0,) -com! -nargs=* -bar -count=0 -complete=dir Texplore call netrw#Explore(,0,6 ,) -com! -nargs=* -bar -bang Nexplore call netrw#Explore(-1,0,0,) -com! -nargs=* -bar -bang Pexplore call netrw#Explore(-2,0,0,) -com! -nargs=* -bar -bang -count=0 -complete=dir Lexplore call netrw#Lexplore(,0,) - -" Commands: NetrwSettings {{{2 -com! -nargs=0 NetrwSettings call netrwSettings#NetrwSettings() -com! -bang NetrwClean call netrw#Clean(0) - -" Maps: -if !exists("g:netrw_nogx") - if maparg('gx','n') == "" - if !hasmapto('NetrwBrowseX') - nmap gx NetrwBrowseX - endif - nno NetrwBrowseX :call netrw#BrowseX(netrw#GX(),netrw#CheckIfRemote(netrw#GX())) - endif - if maparg('gx','x') == "" - if !hasmapto('NetrwBrowseXVis') - xmap gx NetrwBrowseXVis - endif - xno NetrwBrowseXVis :call netrw#BrowseXVis() - endif -endif -if exists("g:netrw_usetab") && g:netrw_usetab - if maparg('','n') == "" - nmap NetrwShrink - endif - nno NetrwShrink :call netrw#Shrink() +if &cp || exists("g:loaded_netrw") || exists("g:loaded_netrwPlugin") + finish endif -" --------------------------------------------------------------------- -" LocalBrowse: invokes netrw#LocalBrowseCheck() on directory buffers {{{2 -fun! s:LocalBrowse(dirname) - " Unfortunate interaction -- only DechoMsg debugging calls can be safely used here. - " Otherwise, the BufEnter event gets triggered when attempts to write to - " the DBG buffer are made. - - if !exists("s:vimentered") - " If s:vimentered doesn't exist, then the VimEnter event hasn't fired. It will, - " and so s:VimEnter() will then be calling this routine, but this time with s:vimentered defined. - " call Dfunc("s:LocalBrowse(dirname<".a:dirname.">) (s:vimentered doesn't exist)") - " call Dret("s:LocalBrowse") - return - endif - - " call Dfunc("s:LocalBrowse(dirname<".a:dirname.">) (s:vimentered=".s:vimentered.")") - - if has("amiga") - " The check against '' is made for the Amiga, where the empty - " string is the current directory and not checking would break - " things such as the help command. - " call Decho("(LocalBrowse) dirname<".a:dirname."> (isdirectory, amiga)") - if a:dirname != '' && isdirectory(a:dirname) - sil! call netrw#LocalBrowseCheck(a:dirname) - if exists("w:netrw_bannercnt") && line('.') < w:netrw_bannercnt - exe w:netrw_bannercnt - endif - endif - - elseif isdirectory(a:dirname) - " call Decho("(LocalBrowse) dirname<".a:dirname."> ft=".&ft." (isdirectory, not amiga)") - " call Dredir("LocalBrowse ft last set: ","verbose set ft") - " Jul 13, 2021: for whatever reason, preceding the following call with - " a sil! causes an unbalanced if-endif vim error - call netrw#LocalBrowseCheck(a:dirname) - if exists("w:netrw_bannercnt") && line('.') < w:netrw_bannercnt - exe w:netrw_bannercnt - endif - - else - " not a directory, ignore it - " call Decho("(LocalBrowse) dirname<".a:dirname."> not a directory, ignoring...") - endif - - " call Dret("s:LocalBrowse") -endfun - -" --------------------------------------------------------------------- -" s:VimEnter: after all vim startup stuff is done, this function is called. {{{2 -" Its purpose: to look over all windows and run s:LocalBrowse() on -" them, which checks if they're directories and will create a directory -" listing when appropriate. -" It also sets s:vimentered, letting s:LocalBrowse() know that s:VimEnter() -" has already been called. -fun! s:VimEnter(dirname) - " call Dfunc("s:VimEnter(dirname<".a:dirname.">) expand(%)<".expand("%").">") - if has('nvim') || v:version < 802 - " Johann Höchtl: reported that the call range... line causes an E488: Trailing characters - " error with neovim. I suspect its because neovim hasn't updated with recent - " vim patches. As is, this code will have problems with popup terminals - " instantiated before the VimEnter event runs. - " Ingo Karkat : E488 also in Vim 8.1.1602 - let curwin = winnr() - let s:vimentered = 1 - windo call s:LocalBrowse(expand("%:p")) - exe curwin."wincmd w" - else - " the following complicated expression comes courtesy of lacygoill; largely does the same thing as the windo and - " wincmd which are commented out, but avoids some side effects. Allows popup terminal before VimEnter. - let s:vimentered = 1 - call range(1, winnr('$'))->map({_, v -> win_execute(win_getid(v), 'call expand("%:p")->s:LocalBrowse()')}) - endif - " call Dret("s:VimEnter") -endfun - -" --------------------------------------------------------------------- -" NetrwStatusLine: {{{1 -fun! NetrwStatusLine() - " let g:stlmsg= "Xbufnr=".w:netrw_explore_bufnr." bufnr=".bufnr("%")." Xline#".w:netrw_explore_line." line#".line(".") - if !exists("w:netrw_explore_bufnr") || w:netrw_explore_bufnr != bufnr("%") || !exists("w:netrw_explore_line") || w:netrw_explore_line != line(".") || !exists("w:netrw_explore_list") - let &stl= s:netrw_explore_stl - if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif - if exists("w:netrw_explore_line")|unlet w:netrw_explore_line|endif - return "" - else - return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen - endif -endfun - -" ------------------------------------------------------------------------ -" NetUserPass: set username and password for subsequent ftp transfer {{{1 -" Usage: :call NetUserPass() -- will prompt for userid and password -" :call NetUserPass("uid") -- will prompt for password -" :call NetUserPass("uid","password") -- sets global userid and password -fun! NetUserPass(...) - - " get/set userid - if a:0 == 0 - " call Dfunc("NetUserPass(a:0<".a:0.">)") - if !exists("g:netrw_uid") || g:netrw_uid == "" - " via prompt - let g:netrw_uid= input('Enter username: ') - endif - else " from command line - " call Dfunc("NetUserPass(a:1<".a:1.">) {") - let g:netrw_uid= a:1 - endif - - " get password - if a:0 <= 1 " via prompt - " call Decho("a:0=".a:0." case <=1:") - let g:netrw_passwd= inputsecret("Enter Password: ") - else " from command line - " call Decho("a:0=".a:0." case >1: a:2<".a:2.">") - let g:netrw_passwd=a:2 - endif - " call Dret("NetUserPass") -endfun +packadd netrw -" ------------------------------------------------------------------------ -" Modelines And Restoration: {{{1 -let &cpo= s:keepcpo -unlet s:keepcpo -" vim:ts=8 sts=2 sw=2 et fdm=marker +" vim:ts=8 sts=2 sw=2 et -- cgit