Merge pull request #21324 from zeertzjq/vim-8.2.1768

vim-patch:8.2.1768,0e6adf8a29d5,fa3b72348d88
This commit is contained in:
zeertzjq 2022-12-07 14:51:36 +08:00 committed by GitHub
commit 0caae2376e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 65 additions and 17 deletions

View File

@ -872,28 +872,56 @@ Here is an example that counts the number of spaces with <F4>: >
" doubling <F4> works on a line
nnoremap <expr> <F4><F4> CountSpaces() .. '_'
function CountSpaces(type = '') abort
function CountSpaces(context = {}, type = '') abort
if a:type == ''
set opfunc=CountSpaces
let context = #{
\ dot_command: v:false,
\ extend_block: '',
\ virtualedit: [&l:virtualedit, &g:virtualedit],
\ }
let &operatorfunc = function('CountSpaces', [context])
set virtualedit=block
return 'g@'
endif
let sel_save = &selection
let reg_save = getreginfo('"')
let cb_save = &clipboard
let visual_marks_save = [getpos("'<"), getpos("'>")]
let save = #{
\ clipboard: &clipboard,
\ selection: &selection,
\ virtualedit: [&l:virtualedit, &g:virtualedit],
\ register: getreginfo('"'),
\ visual_marks: [getpos("'<"), getpos("'>")],
\ }
try
set clipboard= selection=inclusive
let commands = #{line: "'[V']y", char: "`[v`]y", block: "`[\<c-v>`]y"}
silent exe 'noautocmd keepjumps normal! ' .. get(commands, a:type, '')
echom count(getreg('"'), ' ')
set clipboard= selection=inclusive virtualedit=
let commands = #{
\ line: "'[V']",
\ char: "`[v`]",
\ block: "`[\<C-V>`]",
\ }[a:type]
let [_, _, col, off] = getpos("']")
if off != 0
let vcol = getline("'[")->strpart(0, col + off)->strdisplaywidth()
if vcol >= [line("'["), '$']->virtcol() - 1
let a:context.extend_block = '$'
else
let a:context.extend_block = vcol .. '|'
endif
endif
if a:context.extend_block != ''
let commands ..= 'oO' .. a:context.extend_block
endif
let commands ..= 'y'
execute 'silent noautocmd keepjumps normal! ' .. commands
echomsg getreg('"')->count(' ')
finally
call setreg('"', reg_save)
call setpos("'<", visual_marks_save[0])
call setpos("'>", visual_marks_save[1])
let &clipboard = cb_save
let &selection = sel_save
call setreg('"', save.register)
call setpos("'<", save.visual_marks[0])
call setpos("'>", save.visual_marks[1])
let &clipboard = save.clipboard
let &selection = save.selection
let [&l:virtualedit, &g:virtualedit] = get(a:context.dot_command ? save : a:context, 'virtualedit')
let a:context.dot_command = v:true
endtry
endfunction

View File

@ -324,7 +324,7 @@ the name, e.g. "<lambda>123". Examples:
set opfunc={a\ ->\ MyOpFunc(a)}
" set using a funcref variable
let Fn = function('MyTagFunc')
let &tagfunc = string(Fn)
let &tagfunc = Fn
" set using a lambda expression
let &tagfunc = {t -> MyTagFunc(t)}
" set using a variable with lambda expression

View File

@ -2,7 +2,7 @@
" You can also use this as a start for your own set of menus.
"
" Maintainer: Bram Moolenaar <Bram@vim.org>
" Last Change: 2020 Mar 29
" Last Change: 2021 Dec 22
" Note that ":an" (short for ":anoremenu") is often used to make a menu work
" in all modes and avoid side effects from mappings defined by the user.
@ -89,6 +89,21 @@ an 9999.75 &Help.-sep2- <Nop>
an 9999.80 &Help.&Version :version<CR>
an 9999.90 &Help.&About :intro<CR>
if exists(':tlmenu')
tlnoremenu 9999.10 &Help.&Overview<Tab><F1> <C-W>:help<CR>
tlnoremenu 9999.20 &Help.&User\ Manual <C-W>:help usr_toc<CR>
tlnoremenu 9999.30 &Help.&How-To\ Links <C-W>:help how-to<CR>
tlnoremenu <silent> 9999.40 &Help.&Find\.\.\. <C-W>:call <SID>Helpfind()<CR>
tlnoremenu 9999.45 &Help.-sep1- <Nop>
tlnoremenu 9999.50 &Help.&Credits <C-W>:help credits<CR>
tlnoremenu 9999.60 &Help.Co&pying <C-W>:help copying<CR>
tlnoremenu 9999.70 &Help.&Sponsor/Register <C-W>:help sponsor<CR>
tlnoremenu 9999.70 &Help.O&rphans <C-W>:help kcc<CR>
tlnoremenu 9999.75 &Help.-sep2- <Nop>
tlnoremenu 9999.80 &Help.&Version <C-W>:version<CR>
tlnoremenu 9999.90 &Help.&About <C-W>:intro<CR>
endif
fun! s:Helpfind()
if !exists("g:menutrans_help_dialog")
let g:menutrans_help_dialog = "Enter a command or word to find help on:\n\nPrepend i_ for Input mode commands (e.g.: i_CTRL-X)\nPrepend c_ for command-line editing commands (e.g.: c_<Del>)\nPrepend ' for an option name (e.g.: 'shiftwidth')"
@ -702,6 +717,11 @@ func s:BMCanAdd(name, num)
return 0
endif
" no name with control characters
if a:name =~ '[\x01-\x1f]'
return 0
endif
" no special buffer, such as terminal or popup
let buftype = getbufvar(a:num, '&buftype')
if buftype != '' && buftype != 'nofile' && buftype != 'nowrite'