aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/api.txt16
-rw-r--r--runtime/doc/filetype.txt5
-rw-r--r--runtime/doc/ui.txt3
-rw-r--r--runtime/lua/vim/diagnostic.lua24
-rw-r--r--runtime/lua/vim/lsp/handlers.lua5
-rw-r--r--runtime/lua/vim/lsp/util.lua24
-rw-r--r--src/nvim/api/autocmd.c16
-rw-r--r--src/nvim/api/ui.c28
-rw-r--r--src/nvim/option.c17
-rw-r--r--src/nvim/tui/input.c13
-rw-r--r--test/functional/lua/diagnostic_spec.lua19
-rw-r--r--test/functional/ui/options_spec.lua40
12 files changed, 149 insertions, 61 deletions
diff --git a/runtime/doc/api.txt b/runtime/doc/api.txt
index 9e0002db48..5b045f80ff 100644
--- a/runtime/doc/api.txt
+++ b/runtime/doc/api.txt
@@ -3221,6 +3221,22 @@ nvim_create_autocmd({event}, {*opts}) *nvim_create_autocmd()*
})
<
+ Lua functions receive a table with information about the
+ autocmd event as an argument. To use a function which itself
+ accepts another (optional) parameter, wrap the function in a
+ lambda:
+>
+ -- Lua function with an optional parameter.
+ -- The autocmd callback would pass a table as argument but this
+ -- function expects number|nil
+ local myluafun = function(bufnr) bufnr = bufnr or vim.api.nvim_get_current_buf() end
+
+ vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"}, {
+ pattern = {"*.c", "*.h"},
+ callback = function() myluafun() end,
+ })
+<
+
Example using command: >
vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"}, {
pattern = {"*.c", "*.h"},
diff --git a/runtime/doc/filetype.txt b/runtime/doc/filetype.txt
index e1b0e88c95..c50ccc7a91 100644
--- a/runtime/doc/filetype.txt
+++ b/runtime/doc/filetype.txt
@@ -257,7 +257,10 @@ C. If your file type can be detected by the file name or extension.
disabled by setting the did_load_filetypes global variable. If this
variable exists, $VIMRUNTIME/filetype.vim will not run.
Example: >
- " Disable filetype.vim
+ " Disable filetype.vim (but still load filetype.lua if enabled)
+ let g:did_load_filetypes = 0
+
+ " Disable filetype.vim and filetype.lua
let g:did_load_filetypes = 1
< 3. To use the new filetype detection you must restart Vim.
diff --git a/runtime/doc/ui.txt b/runtime/doc/ui.txt
index c5e3b60079..f9110cd59b 100644
--- a/runtime/doc/ui.txt
+++ b/runtime/doc/ui.txt
@@ -49,6 +49,9 @@ with these (optional) keys:
'wildmenu'. |ui-popupmenu|
`ext_tabline` Externalize the tabline. |ui-tabline|
`ext_termcolors` Use external default colors.
+ `term_name` Sets the name of the terminal 'term'.
+ `term_colors` Sets the number of supported colors 't_Co'.
+ `term_background` Sets the default value of 'background'.
Specifying an unknown option is an error; UIs can check the |api-metadata|
`ui_options` key for supported options.
diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua
index 1ec66d7c55..80ce1f331d 100644
--- a/runtime/lua/vim/diagnostic.lua
+++ b/runtime/lua/vim/diagnostic.lua
@@ -668,14 +668,10 @@ function M.set(namespace, bufnr, diagnostics, opts)
M.show(namespace, bufnr, nil, opts)
end
- vim.api.nvim_buf_call(bufnr, function()
- vim.api.nvim_command(
- string.format(
- "doautocmd <nomodeline> DiagnosticChanged %s",
- vim.fn.fnameescape(vim.api.nvim_buf_get_name(bufnr))
- )
- )
- end)
+ vim.api.nvim_exec_autocmds("DiagnosticChanged", {
+ modeline = false,
+ buffer = bufnr,
+ })
end
--- Get namespace metadata.
@@ -1382,14 +1378,10 @@ function M.reset(namespace, bufnr)
M.hide(iter_namespace, iter_bufnr)
end
- vim.api.nvim_buf_call(iter_bufnr, function()
- vim.api.nvim_command(
- string.format(
- "doautocmd <nomodeline> DiagnosticChanged %s",
- vim.fn.fnameescape(vim.api.nvim_buf_get_name(iter_bufnr))
- )
- )
- end)
+ vim.api.nvim_exec_autocmds("DiagnosticChanged", {
+ modeline = false,
+ buffer = iter_bufnr,
+ })
end
end
diff --git a/runtime/lua/vim/lsp/handlers.lua b/runtime/lua/vim/lsp/handlers.lua
index 9871f00677..71b4d33ec0 100644
--- a/runtime/lua/vim/lsp/handlers.lua
+++ b/runtime/lua/vim/lsp/handlers.lua
@@ -33,7 +33,7 @@ local function progress_handler(_, result, ctx, _)
local val = result.value -- unspecified yet
local token = result.token -- string or number
-
+ if type(val) ~= 'table' then val = { content=val } end
if val.kind then
if val.kind == 'begin' then
client.messages.progress[token] = {
@@ -53,7 +53,8 @@ local function progress_handler(_, result, ctx, _)
end
end
else
- table.insert(client.messages, {content = val, show_once = true, shown = 0})
+ client.messages.progress[token] = val
+ client.messages.progress[token].done = true
end
vim.api.nvim_command("doautocmd <nomodeline> User LspProgressUpdate")
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua
index 30587afb38..1f1a34b04a 100644
--- a/runtime/lua/vim/lsp/util.lua
+++ b/runtime/lua/vim/lsp/util.lua
@@ -302,7 +302,6 @@ end
function M.get_progress_messages()
local new_messages = {}
- local msg_remove = {}
local progress_remove = {}
for _, client in ipairs(vim.lsp.get_active_clients()) do
@@ -325,29 +324,6 @@ function M.get_progress_messages()
end
end
- for i, msg in ipairs(data.messages) do
- if msg.show_once then
- msg.shown = msg.shown + 1
- if msg.shown > 1 then
- table.insert(msg_remove, {client = client, idx = i})
- end
- end
-
- table.insert(new_messages, {name = data.name, content = msg.content})
- end
-
- if next(data.status) ~= nil then
- table.insert(new_messages, {
- name = data.name,
- content = data.status.content,
- uri = data.status.uri,
- status = true
- })
- end
- for _, item in ipairs(msg_remove) do
- table.remove(client.messages, item.idx)
- end
-
end
for _, item in ipairs(progress_remove) do
diff --git a/src/nvim/api/autocmd.c b/src/nvim/api/autocmd.c
index a012f3d7fc..45972ec8ea 100644
--- a/src/nvim/api/autocmd.c
+++ b/src/nvim/api/autocmd.c
@@ -346,6 +346,22 @@ cleanup:
/// })
/// </pre>
///
+/// Lua functions receive a table with information about the autocmd event as an argument. To use
+/// a function which itself accepts another (optional) parameter, wrap the function
+/// in a lambda:
+///
+/// <pre>
+/// -- Lua function with an optional parameter.
+/// -- The autocmd callback would pass a table as argument but this
+/// -- function expects number|nil
+/// local myluafun = function(bufnr) bufnr = bufnr or vim.api.nvim_get_current_buf() end
+///
+/// vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"}, {
+/// pattern = {"*.c", "*.h"},
+/// callback = function() myluafun() end,
+/// })
+/// </pre>
+///
/// Example using command:
/// <pre>
/// vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"}, {
diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c
index d86aecc318..383c9c16ab 100644
--- a/src/nvim/api/ui.c
+++ b/src/nvim/api/ui.c
@@ -14,6 +14,7 @@
#include "nvim/map.h"
#include "nvim/memory.h"
#include "nvim/msgpack_rpc/channel.h"
+#include "nvim/option.h"
#include "nvim/popupmnu.h"
#include "nvim/screen.h"
#include "nvim/ui.h"
@@ -255,6 +256,33 @@ static void ui_set_option(UI *ui, bool init, String name, Object value, Error *e
return;
}
+ if (strequal(name.data, "term_name")) {
+ if (value.type != kObjectTypeString) {
+ api_set_error(error, kErrorTypeValidation, "term_name must be a String");
+ return;
+ }
+ set_tty_option("term", xstrdup(value.data.string.data));
+ return;
+ }
+
+ if (strequal(name.data, "term_colors")) {
+ if (value.type != kObjectTypeInteger) {
+ api_set_error(error, kErrorTypeValidation, "term_colors must be a Integer");
+ return;
+ }
+ t_colors = (int)value.data.integer;
+ return;
+ }
+
+ if (strequal(name.data, "term_background")) {
+ if (value.type != kObjectTypeString) {
+ api_set_error(error, kErrorTypeValidation, "term_background must be a String");
+ return;
+ }
+ set_tty_background(value.data.string.data);
+ return;
+ }
+
// LEGACY: Deprecated option, use `ext_cmdline` instead.
bool is_popupmenu = strequal(name.data, "popupmenu_external");
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 897c12a6c4..3aa76f7767 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -4921,6 +4921,23 @@ bool set_tty_option(const char *name, char *value)
return false;
}
+void set_tty_background(const char *value)
+{
+ if (option_was_set("bg") || strequal((char *)p_bg, value)) {
+ // background is already set... ignore
+ return;
+ }
+ if (starting) {
+ // Wait until after startup, so OptionSet is triggered.
+ do_cmdline_cmd((value[0] == 'l')
+ ? "autocmd VimEnter * ++once ++nested set bg=light"
+ : "autocmd VimEnter * ++once ++nested set bg=dark");
+ } else {
+ set_option_value("bg", 0L, value, 0);
+ reset_option_was_set("bg");
+ }
+}
+
/// Find index for an option
///
/// @param[in] arg Option name.
diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c
index 17656c5ddc..691b2ea9da 100644
--- a/src/nvim/tui/input.c
+++ b/src/nvim/tui/input.c
@@ -442,18 +442,7 @@ static HandleState handle_bracketed_paste(TermInput *input)
static void set_bg_deferred(void **argv)
{
char *bgvalue = argv[0];
- if (!option_was_set("bg") && !strequal((char *)p_bg, bgvalue)) {
- // Value differs, apply it.
- if (starting) {
- // Wait until after startup, so OptionSet is triggered.
- do_cmdline_cmd((bgvalue[0] == 'l')
- ? "autocmd VimEnter * ++once ++nested set bg=light"
- : "autocmd VimEnter * ++once ++nested set bg=dark");
- } else {
- set_option_value("bg", 0L, bgvalue, 0);
- reset_option_was_set("bg");
- }
- }
+ set_tty_background(bgvalue);
}
// During startup, tui.c requests the background color (see `ext.get_bg`).
diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua
index b58fad1cab..7f929db8bf 100644
--- a/test/functional/lua/diagnostic_spec.lua
+++ b/test/functional/lua/diagnostic_spec.lua
@@ -1939,24 +1939,31 @@ describe('vim.diagnostic', function()
end)
it('triggers the autocommand when diagnostics are set', function()
- eq(1, exec_lua [[
+ eq(true, exec_lua [[
+ -- Set a different buffer as current to test that <abuf> is being set properly in
+ -- DiagnosticChanged callbacks
+ local tmp = vim.api.nvim_create_buf(false, true)
+ vim.api.nvim_set_current_buf(tmp)
+
vim.g.diagnostic_autocmd_triggered = 0
- vim.cmd('autocmd DiagnosticChanged * let g:diagnostic_autocmd_triggered = 1')
+ vim.cmd('autocmd DiagnosticChanged * let g:diagnostic_autocmd_triggered = +expand("<abuf>")')
vim.api.nvim_buf_set_name(diagnostic_bufnr, "test | test")
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, {
make_error('Diagnostic', 0, 0, 0, 0)
})
- return vim.g.diagnostic_autocmd_triggered
+ return vim.g.diagnostic_autocmd_triggered == diagnostic_bufnr
]])
end)
it('triggers the autocommand when diagnostics are cleared', function()
- eq(1, exec_lua [[
+ eq(true, exec_lua [[
+ local tmp = vim.api.nvim_create_buf(false, true)
+ vim.api.nvim_set_current_buf(tmp)
vim.g.diagnostic_autocmd_triggered = 0
- vim.cmd('autocmd DiagnosticChanged * let g:diagnostic_autocmd_triggered = 1')
+ vim.cmd('autocmd DiagnosticChanged * let g:diagnostic_autocmd_triggered = +expand("<abuf>")')
vim.api.nvim_buf_set_name(diagnostic_bufnr, "test | test")
vim.diagnostic.reset(diagnostic_ns, diagnostic_bufnr)
- return vim.g.diagnostic_autocmd_triggered
+ return vim.g.diagnostic_autocmd_triggered == diagnostic_bufnr
]])
end)
end)
diff --git a/test/functional/ui/options_spec.lua b/test/functional/ui/options_spec.lua
index 2f113f6ac6..82f856e4df 100644
--- a/test/functional/ui/options_spec.lua
+++ b/test/functional/ui/options_spec.lua
@@ -4,6 +4,7 @@ local clear = helpers.clear
local command = helpers.command
local eq = helpers.eq
local shallowcopy = helpers.shallowcopy
+local eval = helpers.eval
describe('UI receives option updates', function()
local screen
@@ -168,3 +169,42 @@ describe('UI receives option updates', function()
it('from startup options with --headless', function() startup_test(true) end)
it('from startup options with --embed', function() startup_test(false) end)
end)
+
+describe('UI can set terminal option', function()
+ local screen
+ before_each(function()
+ -- by default we implicity "--cmd 'set bg=light'" which ruins everything
+ clear{args_rm={'--cmd'}}
+ screen = Screen.new(20,5)
+ end)
+
+ it('term_background', function()
+ eq('dark', eval '&background')
+
+ screen:attach {term_background='light'}
+ eq('light', eval '&background')
+ end)
+
+ it("term_background but not if 'background' already set by user", function()
+ eq('dark', eval '&background')
+ command 'set background=dark'
+
+ screen:attach {term_background='light'}
+
+ eq('dark', eval '&background')
+ end)
+
+ it('term_name', function()
+ eq('nvim', eval '&term')
+
+ screen:attach {term_name='xterm'}
+ eq('xterm', eval '&term')
+ end)
+
+ it('term_colors', function()
+ eq('256', eval '&t_Co')
+
+ screen:attach {term_colors=8}
+ eq('8', eval '&t_Co')
+ end)
+end)