aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2022-08-07 16:01:34 -0600
committerJosh Rahm <joshuarahm@gmail.com>2022-08-07 16:01:34 -0600
commita5f27a311fb28797a72b8aa16ec7122c5a1b15e4 (patch)
tree3732f7339e29431f31310aef6ffc802cf4f6255d /runtime
parent6c909fedc924d9f4257aa204b0168c6177cc5d28 (diff)
parent629169462a82f0fbb7a8911a4554894537d6776c (diff)
downloadrneovim-a5f27a311fb28797a72b8aa16ec7122c5a1b15e4.tar.gz
rneovim-a5f27a311fb28797a72b8aa16ec7122c5a1b15e4.tar.bz2
rneovim-a5f27a311fb28797a72b8aa16ec7122c5a1b15e4.zip
Merge branch 'master' of https://github.com/neovim/neovim into rahm
Diffstat (limited to 'runtime')
-rw-r--r--runtime/CMakeLists.txt4
-rw-r--r--runtime/delmenu.vim25
-rw-r--r--runtime/doc/builtin.txt105
-rw-r--r--runtime/doc/gui.txt4
-rw-r--r--runtime/doc/map.txt101
-rw-r--r--runtime/doc/usr_41.txt17
-rw-r--r--runtime/lua/vim/lsp/handlers.lua22
-rw-r--r--runtime/lua/vim/lsp/util.lua1
-rw-r--r--runtime/menu.vim115
-rw-r--r--runtime/optwin.vim62
10 files changed, 300 insertions, 156 deletions
diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt
index f656f1cbc3..e0a0b34d28 100644
--- a/runtime/CMakeLists.txt
+++ b/runtime/CMakeLists.txt
@@ -117,7 +117,7 @@ endif()
globrecurse_wrapper(RUNTIME_PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR} *.awk *.sh *.bat)
foreach(PROG ${RUNTIME_PROGRAMS})
- get_filename_component(BASEDIR ${PROG} PATH)
+ get_filename_component(BASEDIR ${PROG} DIRECTORY)
install_helper(PROGRAMS ${PROG}
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/nvim/runtime/${BASEDIR})
endforeach()
@@ -126,7 +126,7 @@ globrecurse_wrapper(RUNTIME_FILES ${CMAKE_CURRENT_SOURCE_DIR}
*.vim *.lua *.dict *.py *.rb *.ps *.spl *.tutor *.tutor.json)
foreach(F ${RUNTIME_FILES})
- get_filename_component(BASEDIR ${F} PATH)
+ get_filename_component(BASEDIR ${F} DIRECTORY)
install_helper(FILES ${F}
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/nvim/runtime/${BASEDIR})
endforeach()
diff --git a/runtime/delmenu.vim b/runtime/delmenu.vim
index 040cc09aa9..ef663c73b4 100644
--- a/runtime/delmenu.vim
+++ b/runtime/delmenu.vim
@@ -7,6 +7,31 @@
aunmenu *
tlunmenu *
+if exists('#SetupLazyloadMenus')
+ au! SetupLazyloadMenus
+ augroup! SetupLazyloadMenus
+endif
+
+if exists('#buffer_list')
+ au! buffer_list
+ augroup! buffer_list
+endif
+
+if exists('#LoadBufferMenu')
+ au! LoadBufferMenu
+ augroup! LoadBufferMenu
+endif
+
+if exists('#spellmenu')
+ au! spellmenu
+ augroup! spellmenu
+endif
+
+if exists('#SpellPopupMenu')
+ au! SpellPopupMenu
+ augroup! SpellPopupMenu
+endif
+
unlet! g:did_install_default_menus
unlet! g:did_install_syntax_menu
diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt
index f0f47cddf4..c56ab70774 100644
--- a/runtime/doc/builtin.txt
+++ b/runtime/doc/builtin.txt
@@ -132,12 +132,12 @@ executable({expr}) Number 1 if executable {expr} exists
execute({command}) String execute and capture output of {command}
exepath({expr}) String full path of the command {expr}
exists({expr}) Number |TRUE| if {expr} exists
-extend({expr1}, {expr2} [, {expr3}])
- List/Dict insert items of {expr2} into {expr1}
exp({expr}) Float exponential of {expr}
expand({expr} [, {nosuf} [, {list}]])
any expand special keywords in {expr}
expandcmd({expr}) String expand {expr} like with `:edit`
+extend({expr1}, {expr2} [, {expr3}])
+ List/Dict insert items of {expr2} into {expr1}
feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer
filereadable({file}) Number |TRUE| if {file} is a readable file
filewritable({file}) Number |TRUE| if {file} is a writable file
@@ -243,8 +243,8 @@ histadd({history}, {item}) String add an item to a history
histdel({history} [, {item}]) String remove an item from a history
histget({history} [, {index}]) String get the item {index} from a history
histnr({history}) Number highest index of a history
-hlexists({name}) Number |TRUE| if highlight group {name} exists
hlID({name}) Number syntax ID of highlight group {name}
+hlexists({name}) Number |TRUE| if highlight group {name} exists
hostname() String name of the machine Vim is running on
iconv({expr}, {from}, {to}) String convert encoding of {expr}
indent({lnum}) Number indent of line {lnum}
@@ -319,6 +319,7 @@ matchstrpos({expr}, {pat} [, {start} [, {count}]])
List {count}'th match of {pat} in {expr}
max({expr}) Number maximum value of items in {expr}
menu_get({path} [, {modes}]) List description of |menus| matched by {path}
+menu_info({name} [, {mode}]) Dict get menu item information
min({expr}) Number minimum value of items in {expr}
mkdir({name} [, {path} [, {prot}]])
Number create directory {name}
@@ -340,8 +341,8 @@ prompt_setinterrupt({buf}, {text}) none set prompt interrupt function
prompt_setprompt({buf}, {text}) none set prompt text
pum_getpos() Dict position and size of pum if visible
pumvisible() Number whether popup menu is visible
-pyeval({expr}) any evaluate |Python| expression
py3eval({expr}) any evaluate |python3| expression
+pyeval({expr}) any evaluate |Python| expression
pyxeval({expr}) any evaluate |python_x| expression
rand([{expr}]) Number get pseudo-random number
range({expr} [, {max} [, {stride}]])
@@ -460,10 +461,10 @@ str2list({expr} [, {utf8}]) List convert each character of {expr} to
ASCII/UTF-8 value
str2nr({expr} [, {base} [, {quoted}]])
Number convert String to Number
-strchars({expr} [, {skipcc}]) Number character length of the String {expr}
strcharpart({str}, {start} [, {len}])
String {len} characters of {str} at
character {start}
+strchars({expr} [, {skipcc}]) Number character length of the String {expr}
strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
strftime({format} [, {time}]) String format time with a specified format
strgetchar({str}, {index}) Number get char {index} from {str}
@@ -498,8 +499,8 @@ tabpagebuflist([{arg}]) List list of buffer numbers in tab page
tabpagenr([{arg}]) Number number of current or last tab page
tabpagewinnr({tabarg} [, {arg}])
Number number of current window in tab page
-taglist({expr} [, {filename}]) List list of tags matching {expr}
tagfiles() List tags files used
+taglist({expr} [, {filename}]) List list of tags matching {expr}
tan({expr}) Float tangent of {expr}
tanh({expr}) Float hyperbolic tangent of {expr}
tempname() String name for a temporary file
@@ -2140,7 +2141,7 @@ feedkeys({string} [, {mode}]) *feedkeys()*
script continues.
Note that if you manage to call feedkeys() while
executing commands, thus calling it recursively, then
- all typehead will be consumed by the last call.
+ all typeahead will be consumed by the last call.
'!' When used with 'x' will not end Insert mode. Can be
used in a test when a timer is set to exit Insert mode
a little later. Useful for testing CursorHoldI.
@@ -2173,7 +2174,7 @@ filewritable({file}) *filewritable()*
directory, and we can write to it, the result is 2.
Can also be used as a |method|: >
- GetName()->filewriteable()
+ GetName()->filewritable()
filter({expr1}, {expr2}) *filter()*
{expr1} must be a |List|, |Blob|, or a |Dictionary|.
@@ -3256,7 +3257,7 @@ getmousepos() *getmousepos()*
"screenrow" and "screencol" are valid, the others are zero.
When on the status line below a window or the vertical
- separater right of a window, the "line" and "column" values
+ separator right of a window, the "line" and "column" values
are zero.
When the position is after the text then "column" is the
@@ -4835,7 +4836,7 @@ mapset({mode}, {abbr}, {dict}) *mapset()*
call mapset('n', 0, save_map)
< Note that if you are going to replace a map in several modes,
e.g. with `:map!`, you need to save the mapping for all of
- them, since they can differe.
+ them, since they can differ.
match({expr}, {pat} [, {start} [, {count}]]) *match()*
@@ -5194,6 +5195,7 @@ matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
Can also be used as a |method|: >
GetText()->matchstrpos('word')
<
+
*max()*
max({expr}) Return the maximum value of all items in {expr}. Example: >
echo max([apples, pears, oranges])
@@ -5207,6 +5209,7 @@ max({expr}) Return the maximum value of all items in {expr}. Example: >
Can also be used as a |method|: >
mylist->max()
+
menu_get({path} [, {modes}]) *menu_get()*
Returns a |List| of |Dictionaries| describing |menus| (defined
by |:menu|, |:amenu|, …), including |hidden-menus|.
@@ -5253,7 +5256,81 @@ menu_get({path} [, {modes}]) *menu_get()*
} ]
<
- *min()*
+menu_info({name} [, {mode}]) *menu_info()*
+ Return information about the specified menu {name} in
+ mode {mode}. The menu name should be specified without the
+ shortcut character ('&'). If {name} is "", then the top-level
+ menu names are returned.
+
+ {mode} can be one of these strings:
+ "n" Normal
+ "v" Visual (including Select)
+ "o" Operator-pending
+ "i" Insert
+ "c" Cmd-line
+ "s" Select
+ "x" Visual
+ "t" Terminal-Job
+ "" Normal, Visual and Operator-pending
+ "!" Insert and Cmd-line
+ When {mode} is omitted, the modes for "" are used.
+
+ Returns a |Dictionary| containing the following items:
+ accel menu item accelerator text |menu-text|
+ display display name (name without '&')
+ enabled v:true if this menu item is enabled
+ Refer to |:menu-enable|
+ icon name of the icon file (for toolbar)
+ |toolbar-icon|
+ iconidx index of a built-in icon
+ modes modes for which the menu is defined. In
+ addition to the modes mentioned above, these
+ characters will be used:
+ " " Normal, Visual and Operator-pending
+ name menu item name.
+ noremenu v:true if the {rhs} of the menu item is not
+ remappable else v:false.
+ priority menu order priority |menu-priority|
+ rhs right-hand-side of the menu item. The returned
+ string has special characters translated like
+ in the output of the ":menu" command listing.
+ When the {rhs} of a menu item is empty, then
+ "<Nop>" is returned.
+ script v:true if script-local remapping of {rhs} is
+ allowed else v:false. See |:menu-script|.
+ shortcut shortcut key (character after '&' in
+ the menu name) |menu-shortcut|
+ silent v:true if the menu item is created
+ with <silent> argument |:menu-silent|
+ submenus |List| containing the names of
+ all the submenus. Present only if the menu
+ item has submenus.
+
+ Returns an empty dictionary if the menu item is not found.
+
+ Examples: >
+ :echo menu_info('Edit.Cut')
+ :echo menu_info('File.Save', 'n')
+
+ " Display the entire menu hierarchy in a buffer
+ func ShowMenu(name, pfx)
+ let m = menu_info(a:name)
+ call append(line('$'), a:pfx .. m.display)
+ for child in m->get('submenus', [])
+ call ShowMenu(a:name .. '.' .. escape(child, '.'),
+ \ a:pfx .. ' ')
+ endfor
+ endfunc
+ new
+ for topmenu in menu_info('').submenus
+ call ShowMenu(topmenu, '')
+ endfor
+<
+ Can also be used as a |method|: >
+ GetMenuName()->menu_info('v')
+
+
+< *min()*
min({expr}) Return the minimum value of all items in {expr}. Example: >
echo min([apples, pears, oranges])
@@ -6485,8 +6562,10 @@ searchcount([{options}]) *searchcount()*
recompute |Boolean| if |TRUE|, recompute the count
like |n| or |N| was executed.
otherwise returns the last
- result by |n|, |N|, or this
- function is returned.
+ computed result (when |n| or
+ |N| was used when "S" is not
+ in 'shortmess', or this
+ function was called).
(default: |TRUE|)
pattern |String| recompute if this was given
and different with |@/|.
diff --git a/runtime/doc/gui.txt b/runtime/doc/gui.txt
index 776ff228d6..8f09e5225f 100644
--- a/runtime/doc/gui.txt
+++ b/runtime/doc/gui.txt
@@ -201,9 +201,11 @@ tooltips for menus. See |terminal-input|.
Special characters in a menu name:
+ *menu-shortcut*
& The next character is the shortcut key. Make sure each
shortcut key is only used once in a (sub)menu. If you want to
insert a literal "&" in the menu name use "&&".
+ *menu-text*
<Tab> Separates the menu name from right-aligned text. This can be
used to show the equivalent typed command. The text "<Tab>"
can be used here for convenience. If you are using a real
@@ -561,7 +563,7 @@ item for the keyword under the cursor. The register "z" is used. >
mappings, or put these lines in your gvimrc; "<C-R>" is CTRL-R, "<CR>" is
the <CR> key. |<>|)
-
+ *tooltips* *menu-tips*
Tooltips & Menu tips
See section |42.4| in the user manual.
diff --git a/runtime/doc/map.txt b/runtime/doc/map.txt
index 1e1f4e46af..b0ce2d4164 100644
--- a/runtime/doc/map.txt
+++ b/runtime/doc/map.txt
@@ -1483,74 +1483,79 @@ in the preview namespace.
Here's an example of a command to trim trailing whitespace from lines that
supports incremental command preview:
>
- -- Trims trailing whitespace in the current buffer.
- -- Also performs 'inccommand' preview if invoked as a preview callback
- -- (preview_ns is non-nil).
- local function trim_space(opts, preview_ns, preview_buf)
+ -- If invoked as a preview callback, performs 'inccommand' preview by
+ -- highlighting trailing whitespace in the current buffer.
+ local function trim_space_preview(opts, preview_ns, preview_buf)
local line1 = opts.line1
local line2 = opts.line2
local buf = vim.api.nvim_get_current_buf()
- local lines = vim.api.nvim_buf_get_lines(buf, line1 - 1, line2, 0)
- local new_lines = {}
+ local lines = vim.api.nvim_buf_get_lines(buf, line1 - 1, line2, false)
local preview_buf_line = 0
for i, line in ipairs(lines) do
- local startidx, endidx = string.find(line, '%s+$')
-
- if startidx ~= nil then
- -- Highlight the match if in command preview mode
- if preview_ns ~= nil then
- vim.api.nvim_buf_add_highlight(
- buf, preview_ns, 'Substitute', line1 + i - 2, startidx - 1,
- endidx
- )
-
- -- Add lines and highlight to the preview buffer
- -- if inccommand=split
- if preview_buf ~= nil then
- local prefix = string.format('|%d| ', line1 + i - 1)
-
- vim.api.nvim_buf_set_lines(
- preview_buf, preview_buf_line, preview_buf_line, 0,
- { prefix .. line }
- )
- vim.api.nvim_buf_add_highlight(
- preview_buf, preview_ns, 'Substitute', preview_buf_line,
- #prefix + startidx - 1, #prefix + endidx
- )
-
- preview_buf_line = preview_buf_line + 1
- end
+ local start_idx, end_idx = string.find(line, '%s+$')
+
+ if start_idx then
+ -- Highlight the match
+ vim.api.nvim_buf_add_highlight(
+ buf,
+ preview_ns,
+ 'Substitute',
+ line1 + i - 2,
+ start_idx - 1,
+ end_idx
+ )
+
+ -- Add lines and set highlights in the preview buffer
+ -- if inccommand=split
+ if preview_buf then
+ local prefix = string.format('|%d| ', line1 + i - 1)
+
+ vim.api.nvim_buf_set_lines(
+ preview_buf,
+ preview_buf_line,
+ preview_buf_line,
+ false,
+ { prefix .. line }
+ )
+ vim.api.nvim_buf_add_highlight(
+ preview_buf,
+ preview_ns,
+ 'Substitute',
+ preview_buf_line,
+ #prefix + start_idx - 1,
+ #prefix + end_idx
+ )
+ preview_buf_line = preview_buf_line + 1
end
end
-
- if not preview_ns then
- new_lines[#new_lines+1] = string.gsub(line, '%s+$', '')
- end
end
- -- Don't make any changes to the buffer if previewing
- if not preview_ns then
- vim.api.nvim_buf_set_lines(buf, line1 - 1, line2, 0, new_lines)
- end
+ -- Return the value of the preview type
+ return 2
+ end
- -- When called as a preview callback, return the value of the
- -- preview type
- if preview_ns ~= nil then
- return 2
+ -- Trims all trailing whitespace in the current buffer.
+ local function trim_space(opts)
+ local line1 = opts.line1
+ local line2 = opts.line2
+ local buf = vim.api.nvim_get_current_buf()
+ local lines = vim.api.nvim_buf_get_lines(buf, line1 - 1, line2, false)
+
+ local new_lines = {}
+ for i, line in ipairs(lines) do
+ new_lines[i] = string.gsub(line, '%s+$', '')
end
+ vim.api.nvim_buf_set_lines(buf, line1 - 1, line2, false, new_lines)
end
-- Create the user command
vim.api.nvim_create_user_command(
'TrimTrailingWhitespace',
trim_space,
- { nargs = '?', range = '%', addr = 'lines', preview = trim_space }
+ { nargs = '?', range = '%', addr = 'lines', preview = trim_space_preview }
)
<
-Note that in the above example, the same function is used as both the command
-callback and the preview callback, but you could instead use separate
-functions.
Special cases ~
diff --git a/runtime/doc/usr_41.txt b/runtime/doc/usr_41.txt
index 5acef2f352..008b9b4e58 100644
--- a/runtime/doc/usr_41.txt
+++ b/runtime/doc/usr_41.txt
@@ -648,6 +648,7 @@ List manipulation: *list-functions*
deepcopy() make a full copy of a List
filter() remove selected items from a List
map() change each List item
+ reduce() reduce a List to a value
sort() sort a List
reverse() reverse the order of a List
uniq() remove copies of repeated adjacent items
@@ -705,6 +706,8 @@ Floating point computation: *float-functions*
sinh() hyperbolic sine
cosh() hyperbolic cosine
tanh() hyperbolic tangent
+ isinf() check for infinity
+ isnan() check for not a number
Other computation: *bitwise-function*
and() bitwise AND
@@ -712,6 +715,8 @@ Other computation: *bitwise-function*
or() bitwise OR
xor() bitwise XOR
sha256() SHA-256 hash
+ rand() get a pseudo-random number
+ srand() initialize seed used by rand()
Variables: *var-functions*
type() type of a variable
@@ -765,6 +770,7 @@ Working with text in the current buffer: *text-functions*
prevnonblank() find previous non-blank line
search() find a match for a pattern
searchpos() find a match for a pattern
+ searchcount() get number of matches before/after the cursor
searchpair() find the other end of a start/skip/end
searchpairpos() find the other end of a start/skip/end
searchdecl() search for the declaration of a name
@@ -841,9 +847,11 @@ Buffers, windows and the argument list:
deletebufline() delete lines from a specified buffer
win_findbuf() find windows containing a buffer
win_getid() get window ID of a window
+ win_gettype() get type of window
win_gotoid() go to window with ID
win_id2tabwin() get tab and window nr from window ID
win_id2win() get window nr from window ID
+ win_splitmove() move window to a split of another window
win_move_separator() move window vertical separator
win_move_statusline() move window status line
getbufinfo() get a list with buffer information
@@ -926,6 +934,7 @@ Interactive: *interactive-functions*
confirm() let the user make a choice
getchar() get a character from the user
getcharmod() get modifiers for the last typed character
+ getmousepos() get last known mouse position
feedkeys() put characters in the typeahead queue
input() get a line from the user
inputlist() let the user pick an entry from a list
@@ -963,7 +972,7 @@ Window size and position: *window-size-functions*
winsaveview() get view of current window
winrestview() restore saved view of current window
-Mappings: *mapping-functions*
+Mappings and Menus: *mapping-functions*
digraph_get() get |digraph|
digraph_getlist() get all |digraph|s
digraph_set() register |digraph|
@@ -971,6 +980,8 @@ Mappings: *mapping-functions*
hasmapto() check if a mapping exists
mapcheck() check if a matching mapping exists
maparg() get rhs of a mapping
+ mapset() restore a mapping
+ menu_info() get information about a menu item
wildmenumode() check if the wildmode is active
Signs: *sign-functions*
@@ -1054,10 +1065,12 @@ Various: *various-functions*
wordcount() get byte/word/char count of buffer
- luaeval() evaluate Lua expression
+ luaeval() evaluate |Lua| expression
py3eval() evaluate Python expression (|+python3|)
pyeval() evaluate Python expression (|+python|)
pyxeval() evaluate |python_x| expression
+ rubyeval() evaluate |Ruby| expression
+
debugbreak() interrupt a program being debugged
==============================================================================
diff --git a/runtime/lua/vim/lsp/handlers.lua b/runtime/lua/vim/lsp/handlers.lua
index 1e6ac8dddf..624436bc9b 100644
--- a/runtime/lua/vim/lsp/handlers.lua
+++ b/runtime/lua/vim/lsp/handlers.lua
@@ -348,19 +348,19 @@ local function location_handler(_, result, ctx, config)
-- https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_definition
if vim.tbl_islist(result) then
- util.jump_to_location(result[1], client.offset_encoding, config.reuse_win)
-
- if #result > 1 then
- local title = 'LSP locations'
- local items = util.locations_to_items(result, client.offset_encoding)
+ local title = 'LSP locations'
+ local items = util.locations_to_items(result, client.offset_encoding)
- if config.on_list then
- assert(type(config.on_list) == 'function', 'on_list is not a function')
- config.on_list({ title = title, items = items })
- else
- vim.fn.setqflist({}, ' ', { title = title, items = items })
- api.nvim_command('botright copen')
+ if config.on_list then
+ assert(type(config.on_list) == 'function', 'on_list is not a function')
+ config.on_list({ title = title, items = items })
+ else
+ if #result == 1 then
+ util.jump_to_location(result[1], client.offset_encoding, config.reuse_win)
+ return
end
+ vim.fn.setqflist({}, ' ', { title = title, items = items })
+ api.nvim_command('botright copen')
end
else
util.jump_to_location(result, client.offset_encoding, config.reuse_win)
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua
index 8e89d92a56..eac21db386 100644
--- a/runtime/lua/vim/lsp/util.lua
+++ b/runtime/lua/vim/lsp/util.lua
@@ -106,6 +106,7 @@ end
---@private
local function split_lines(value)
+ value = string.gsub(value, '\r\n?', '\n')
return split(value, '\n', true)
end
diff --git a/runtime/menu.vim b/runtime/menu.vim
index e20720dbd2..0a5ac36095 100644
--- a/runtime/menu.vim
+++ b/runtime/menu.vim
@@ -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: 2019 Dec 10
+" Last Change: 2020 Mar 29
" 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.
@@ -139,11 +139,11 @@ an 10.600 &File.-SEP4- <Nop>
an 10.610 &File.Sa&ve-Exit<Tab>:wqa :confirm wqa<CR>
an 10.620 &File.E&xit<Tab>:qa :confirm qa<CR>
-func! <SID>SelectAll()
+func s:SelectAll()
exe "norm! gg" . (&slm == "" ? "VG" : "gH\<C-O>G")
endfunc
-func! s:FnameEscape(fname)
+func s:FnameEscape(fname)
if exists('*fnameescape')
return fnameescape(a:fname)
endif
@@ -356,7 +356,7 @@ endfun
let s:did_setup_color_schemes = 0
" Setup the Edit.Color Scheme submenu
-func! s:SetupColorSchemes() abort
+func s:SetupColorSchemes() abort
if s:did_setup_color_schemes
return
endif
@@ -388,7 +388,7 @@ endif
if has("keymap")
let s:did_setup_keymaps = 0
- func! s:SetupKeymaps() abort
+ func s:SetupKeymaps() abort
if s:did_setup_keymaps
return
endif
@@ -454,7 +454,7 @@ if has("spell")
an <silent> 40.335.270 &Tools.&Spelling.&Find\ More\ Languages :call <SID>SpellLang()<CR>
let s:undo_spelllang = ['aun &Tools.&Spelling.&Find\ More\ Languages']
- func! s:SpellLang()
+ func s:SpellLang()
for cmd in s:undo_spelllang
exe "silent! " . cmd
endfor
@@ -566,7 +566,7 @@ an <silent> 40.540 &Tools.Conve&rt\ Back<Tab>:%!xxd\ -r
" Use a function to do the conversion, so that it also works with 'insertmode'
" set.
-func! s:XxdConv()
+func s:XxdConv()
let mod = &mod
if has("vms")
%!mc vim:xxd
@@ -580,7 +580,7 @@ func! s:XxdConv()
let &mod = mod
endfun
-func! s:XxdBack()
+func s:XxdBack()
let mod = &mod
if has("vms")
%!mc vim:xxd -r
@@ -593,7 +593,7 @@ func! s:XxdBack()
let &mod = mod
endfun
-func! s:XxdFind()
+func s:XxdFind()
if !exists("g:xxdprogram")
" On the PC xxd may not be in the path but in the install directory
if has("win32") && !executable("xxd")
@@ -610,7 +610,7 @@ endfun
let s:did_setup_compilers = 0
" Setup the Tools.Compiler submenu
-func! s:SetupCompilers() abort
+func s:SetupCompilers() abort
if s:did_setup_compilers
return
endif
@@ -634,7 +634,7 @@ endif
" Load ColorScheme, Compiler Setting and Keymap menus when idle.
if !exists("do_no_lazyload_menus")
- func! s:SetupLazyloadMenus()
+ func s:SetupLazyloadMenus()
call s:SetupColorSchemes()
call s:SetupCompilers()
if has("keymap")
@@ -656,51 +656,75 @@ if !exists("no_buffers_menu")
" startup faster.
let s:bmenu_wait = 1
+" Dictionary of buffer number to name. This helps prevent problems where a
+" buffer as renamed and we didn't keep track of that.
+let s:bmenu_items = {}
+
if !exists("bmenu_priority")
let bmenu_priority = 60
endif
-func! s:BMAdd()
+" invoked from a BufCreate or BufFilePost autocommand
+func s:BMAdd()
if s:bmenu_wait == 0
" when adding too many buffers, redraw in short format
if s:bmenu_count == &menuitems && s:bmenu_short == 0
call s:BMShow()
else
- call <SID>BMFilename(expand("<afile>"), expand("<abuf>"))
- let s:bmenu_count = s:bmenu_count + 1
+ let name = expand("<afile>")
+ let num = expand("<abuf>") + 0 " add zero to convert to a number type
+ if s:BMCanAdd(name, num)
+ call <SID>BMFilename(name, num)
+ let s:bmenu_count += 1
+ endif
endif
endif
endfunc
-func! s:BMRemove()
+" invoked from a BufDelete or BufFilePre autocommand
+func s:BMRemove()
if s:bmenu_wait == 0
- let name = expand("<afile>")
- if isdirectory(name)
- return
+ let bufnum = expand("<abuf>")
+ if s:bmenu_items->has_key(bufnum)
+ let menu_name = s:bmenu_items[bufnum]
+ exe 'silent! aun &Buffers.' . menu_name
+ let s:bmenu_count = s:bmenu_count - 1
+ unlet s:bmenu_items[bufnum]
endif
- let munge = <SID>BMMunge(name, expand("<abuf>"))
+ endif
+endfunc
- if s:bmenu_short == 0
- exe 'silent! aun &Buffers.' . munge
- else
- exe 'silent! aun &Buffers.' . <SID>BMHash2(munge) . munge
- endif
- let s:bmenu_count = s:bmenu_count - 1
+" Return non-zero if buffer with number "name" / "num" is useful to add in the
+" buffer menu.
+func s:BMCanAdd(name, num)
+ " no directory or unlisted buffer
+ if isdirectory(a:name) || !buflisted(a:num)
+ return 0
+ endif
+
+ " no special buffer, such as terminal or popup
+ let buftype = getbufvar(a:num, '&buftype')
+ if buftype != '' && buftype != 'nofile' && buftype != 'nowrite'
+ return 0
endif
+
+ " only existing buffers
+ return bufexists(a:num)
endfunc
" Create the buffer menu (delete an existing one first).
-func! s:BMShow(...)
+func s:BMShow(...)
let s:bmenu_wait = 1
let s:bmenu_short = 1
let s:bmenu_count = 0
+ let s:bmenu_items = {}
"
" get new priority, if exists
if a:0 == 1
let g:bmenu_priority = a:1
endif
- " Remove old menu, if exists; keep one entry to avoid a torn off menu to
+ " Remove old menu, if it exists; keep one entry to avoid a torn off menu to
" disappear. Use try/catch to avoid setting v:errmsg
try | unmenu &Buffers | catch | endtry
exe 'noremenu ' . g:bmenu_priority . ".1 &Buffers.Dummy l"
@@ -721,7 +745,7 @@ func! s:BMShow(...)
" figure out how many buffers there are
let buf = 1
while buf <= bufnr('$')
- if bufexists(buf) && !isdirectory(bufname(buf)) && buflisted(buf)
+ if s:BMCanAdd(bufname(buf), buf)
let s:bmenu_count = s:bmenu_count + 1
endif
let buf = buf + 1
@@ -733,8 +757,9 @@ func! s:BMShow(...)
" iterate through buffer list, adding each buffer to the menu:
let buf = 1
while buf <= bufnr('$')
- if bufexists(buf) && !isdirectory(bufname(buf)) && buflisted(buf)
- call <SID>BMFilename(bufname(buf), buf)
+ let name = bufname(buf)
+ if s:BMCanAdd(name, buf)
+ call <SID>BMFilename(name, buf)
endif
let buf = buf + 1
endwhile
@@ -746,7 +771,7 @@ func! s:BMShow(...)
aug END
endfunc
-func! s:BMHash(name)
+func s:BMHash(name)
" Make name all upper case, so that chars are between 32 and 96
let nm = substitute(a:name, ".*", '\U\0', "")
if has("ebcdic")
@@ -761,7 +786,7 @@ func! s:BMHash(name)
return (char2nr(nm[0]) - sp) * 0x800000 + (char2nr(nm[1]) - sp) * 0x20000 + (char2nr(nm[2]) - sp) * 0x1000 + (char2nr(nm[3]) - sp) * 0x80 + (char2nr(nm[4]) - sp) * 0x20 + (char2nr(nm[5]) - sp)
endfunc
-func! s:BMHash2(name)
+func s:BMHash2(name)
let nm = substitute(a:name, ".", '\L\0', "")
" Not exactly right for EBCDIC...
if nm[0] < 'a' || nm[0] > 'z'
@@ -781,22 +806,22 @@ func! s:BMHash2(name)
endif
endfunc
-" insert a buffer name into the buffer menu:
-func! s:BMFilename(name, num)
- if isdirectory(a:name)
- return
- endif
+" Insert a buffer name into the buffer menu.
+func s:BMFilename(name, num)
let munge = <SID>BMMunge(a:name, a:num)
let hash = <SID>BMHash(munge)
if s:bmenu_short == 0
- let name = 'an ' . g:bmenu_priority . '.' . hash . ' &Buffers.' . munge
+ let s:bmenu_items[a:num] = munge
+ let cmd = 'an ' . g:bmenu_priority . '.' . hash . ' &Buffers.' . munge
else
- let name = 'an ' . g:bmenu_priority . '.' . hash . '.' . hash . ' &Buffers.' . <SID>BMHash2(munge) . munge
+ let menu_name = <SID>BMHash2(munge) . munge
+ let s:bmenu_items[a:num] = menu_name
+ let cmd = 'an ' . g:bmenu_priority . '.' . hash . '.' . hash . ' &Buffers.' . menu_name
endif
" set 'cpo' to include the <CR>
let cpo_save = &cpo
set cpo&vim
- exe name . ' :confirm b' . a:num . '<CR>'
+ exe cmd . ' :confirm b' . a:num . '<CR>'
let &cpo = cpo_save
endfunc
@@ -804,7 +829,7 @@ endfunc
if !exists("g:bmenu_max_pathlen")
let g:bmenu_max_pathlen = 35
endif
-func! s:BMTruncName(fname)
+func s:BMTruncName(fname)
let name = a:fname
if g:bmenu_max_pathlen < 5
let name = ""
@@ -824,7 +849,7 @@ func! s:BMTruncName(fname)
return name
endfunc
-func! s:BMMunge(fname, bnum)
+func s:BMMunge(fname, bnum)
let name = a:fname
if name == ''
if !exists("g:menutrans_no_file")
@@ -941,7 +966,7 @@ cnoremenu <script> <silent> 1.100 PopUp.Select\ &All <C-U>call <SID>SelectAll()<
if has("spell")
" Spell suggestions in the popup menu. Note that this will slow down the
" appearance of the menu!
- func! <SID>SpellPopup()
+ func s:SpellPopup()
if exists("s:changeitem") && s:changeitem != ''
call <SID>SpellDel()
endif
@@ -997,7 +1022,7 @@ if has("spell")
call cursor(0, curcol) " put the cursor back where it was
endfunc
- func! <SID>SpellReplace(n)
+ func s:SpellReplace(n)
let l = getline('.')
" Move the cursor to the start of the word.
call spellbadword()
@@ -1005,7 +1030,7 @@ if has("spell")
\ . strpart(l, col('.') + len(s:fromword) - 1))
endfunc
- func! <SID>SpellDel()
+ func s:SpellDel()
exe "aunmenu PopUp." . s:changeitem
exe "aunmenu PopUp." . s:additem
exe "aunmenu PopUp." . s:ignoreitem
diff --git a/runtime/optwin.vim b/runtime/optwin.vim
index 228336e5a4..02cf573ea3 100644
--- a/runtime/optwin.vim
+++ b/runtime/optwin.vim
@@ -665,12 +665,10 @@ if has("printer")
call append("$", "printencoding\tencoding used to print the PostScript file for :hardcopy")
call <SID>OptionG("penc", &penc)
endif
- if has("multi_byte")
- call append("$", "printmbcharset\tthe CJK character set to be used for CJK output from :hardcopy")
- call <SID>OptionG("pmbcs", &pmbcs)
- call append("$", "printmbfont\tlist of font names to be used for CJK output from :hardcopy")
- call <SID>OptionG("pmbfn", &pmbfn)
- endif
+ call append("$", "printmbcharset\tthe CJK character set to be used for CJK output from :hardcopy")
+ call <SID>OptionG("pmbcs", &pmbcs)
+ call append("$", "printmbfont\tlist of font names to be used for CJK output from :hardcopy")
+ call <SID>OptionG("pmbfn", &pmbfn)
endif
call <SID>Header("messages and info")
@@ -981,11 +979,9 @@ call <SID>BinOptionL("eol")
call append("$", "fixendofline\tfixes missing end-of-line at end of text file")
call append("$", "\t(local to buffer)")
call <SID>BinOptionL("fixeol")
-if has("multi_byte")
- call append("$", "bomb\tprepend a Byte Order Mark to the file")
- call append("$", "\t(local to buffer)")
- call <SID>BinOptionL("bomb")
-endif
+call append("$", "bomb\tprepend a Byte Order Mark to the file")
+call append("$", "\t(local to buffer)")
+call <SID>BinOptionL("bomb")
call append("$", "fileformat\tend-of-line format: \"dos\", \"unix\" or \"mac\"")
call append("$", "\t(local to buffer)")
call <SID>OptionL("ff")
@@ -1204,30 +1200,28 @@ if has("xim")
endif
-if has("multi_byte")
- call <SID>Header("multi-byte characters")
- call <SID>AddOption("encoding", "character encoding used in Nvim: \"utf-8\"")
- call <SID>OptionG("enc", &enc)
- call append("$", "fileencoding\tcharacter encoding for the current file")
- call append("$", "\t" .. s:local_to_buffer)
- call <SID>OptionL("fenc")
- call append("$", "fileencodings\tautomatically detected character encodings")
- call <SID>OptionG("fencs", &fencs)
- call append("$", "charconvert\texpression used for character encoding conversion")
- call <SID>OptionG("ccv", &ccv)
- call append("$", "delcombine\tdelete combining (composing) characters on their own")
- call <SID>BinOptionG("deco", &deco)
- call append("$", "maxcombine\tmaximum number of combining (composing) characters displayed")
- call <SID>OptionG("mco", &mco)
- if has("xim") && has("gui_gtk")
- call append("$", "imactivatekey\tkey that activates the X input method")
- call <SID>OptionG("imak", &imak)
- endif
- call append("$", "ambiwidth\twidth of ambiguous width characters")
- call <SID>OptionG("ambw", &ambw)
- call append("$", "emoji\temoji characters are full width")
- call <SID>BinOptionG("emo", &emo)
+call <SID>Header("multi-byte characters")
+call <SID>AddOption("encoding", "character encoding used in Nvim: \"utf-8\"")
+call <SID>OptionG("enc", &enc)
+call append("$", "fileencoding\tcharacter encoding for the current file")
+call append("$", "\t" .. s:local_to_buffer)
+call <SID>OptionL("fenc")
+call append("$", "fileencodings\tautomatically detected character encodings")
+call <SID>OptionG("fencs", &fencs)
+call append("$", "charconvert\texpression used for character encoding conversion")
+call <SID>OptionG("ccv", &ccv)
+call append("$", "delcombine\tdelete combining (composing) characters on their own")
+call <SID>BinOptionG("deco", &deco)
+call append("$", "maxcombine\tmaximum number of combining (composing) characters displayed")
+call <SID>OptionG("mco", &mco)
+if has("xim") && has("gui_gtk")
+ call append("$", "imactivatekey\tkey that activates the X input method")
+ call <SID>OptionG("imak", &imak)
endif
+call append("$", "ambiwidth\twidth of ambiguous width characters")
+call <SID>OptionG("ambw", &ambw)
+call append("$", "emoji\temoji characters are full width")
+call <SID>BinOptionG("emo", &emo)
call <SID>Header("various")