aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
4 files changed, 62 insertions, 12 deletions
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`).