aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/lua/vim/lsp/log.lua8
-rw-r--r--runtime/lua/vim/treesitter/language.lua4
-rw-r--r--runtime/lua/vim/treesitter/languagetree.lua22
-rw-r--r--runtime/lua/vim/treesitter/query.lua18
-rw-r--r--src/nvim/api/vim.c20
-rw-r--r--src/nvim/autocmd.c4
-rw-r--r--src/nvim/buffer.c8
-rw-r--r--src/nvim/buffer_defs.h14
-rw-r--r--src/nvim/context.c2
-rw-r--r--src/nvim/diff.c2
-rw-r--r--src/nvim/eval.c45
-rw-r--r--src/nvim/eval.h4
-rw-r--r--src/nvim/eval/funcs.c4
-rw-r--r--src/nvim/ex_cmds.c14
-rw-r--r--src/nvim/ex_cmds2.c4
-rw-r--r--src/nvim/ex_cmds_defs.h4
-rw-r--r--src/nvim/ex_docmd.c11
-rw-r--r--src/nvim/ex_getln.c2
-rw-r--r--src/nvim/fileio.c5
-rw-r--r--src/nvim/log.h9
-rw-r--r--src/nvim/lua/vim.lua27
-rw-r--r--src/nvim/main.c6
-rw-r--r--src/nvim/memline_defs.h8
-rw-r--r--src/nvim/menu.c8
-rw-r--r--src/nvim/option.c19
-rw-r--r--src/nvim/quickfix.c4
-rw-r--r--src/nvim/screen.c21
-rw-r--r--src/nvim/sign_defs.h4
-rw-r--r--src/nvim/spell.c2
-rw-r--r--src/nvim/syntax.c8
-rw-r--r--test/functional/api/vim_spec.lua9
31 files changed, 185 insertions, 135 deletions
diff --git a/runtime/lua/vim/lsp/log.lua b/runtime/lua/vim/lsp/log.lua
index b6e91e37b9..4e8d2d4202 100644
--- a/runtime/lua/vim/lsp/log.lua
+++ b/runtime/lua/vim/lsp/log.lua
@@ -10,13 +10,7 @@ local log = {}
-- Can be used to lookup the number from the name or the name from the number.
-- Levels by name: 'trace', 'debug', 'info', 'warn', 'error'
-- Level numbers begin with 'trace' at 0
-log.levels = {
- TRACE = 0;
- DEBUG = 1;
- INFO = 2;
- WARN = 3;
- ERROR = 4;
-}
+log.levels = vim.log.levels
-- Default log level is warn.
local current_log_level = log.levels.WARN
diff --git a/runtime/lua/vim/treesitter/language.lua b/runtime/lua/vim/treesitter/language.lua
index d60cd2d0c7..eed28e0e41 100644
--- a/runtime/lua/vim/treesitter/language.lua
+++ b/runtime/lua/vim/treesitter/language.lua
@@ -2,12 +2,12 @@ local a = vim.api
local M = {}
---- Asserts that the provided language is installed, and optionnaly provide a path for the parser
+--- Asserts that the provided language is installed, and optionally provide a path for the parser
--
-- Parsers are searched in the `parser` runtime directory.
--
-- @param lang The language the parser should parse
--- @param path Optionnal path the parser is located at
+-- @param path Optional path the parser is located at
-- @param silent Don't throw an error if language not found
function M.require_language(lang, path, silent)
if vim._ts_has_language(lang) then
diff --git a/runtime/lua/vim/treesitter/languagetree.lua b/runtime/lua/vim/treesitter/languagetree.lua
index c864fe5878..6d47ed8365 100644
--- a/runtime/lua/vim/treesitter/languagetree.lua
+++ b/runtime/lua/vim/treesitter/languagetree.lua
@@ -6,14 +6,14 @@ local LanguageTree = {}
LanguageTree.__index = LanguageTree
-- Represents a single treesitter parser for a language.
--- The language can contain child languages with in it's range,
+-- The language can contain child languages with in its range,
-- hence the tree.
--
-- @param source Can be a bufnr or a string of text to parse
-- @param lang The language this tree represents
-- @param opts Options table
--- @param opts.queries A table of language to injection query strings
--- This is useful for overridding the built in runtime file
+-- @param opts.queries A table of language to injection query strings.
+-- This is useful for overriding the built-in runtime file
-- searching for the injection language query per language.
function LanguageTree.new(source, lang, opts)
language.require_language(lang)
@@ -21,8 +21,8 @@ function LanguageTree.new(source, lang, opts)
local custom_queries = opts.queries or {}
local self = setmetatable({
- _source=source,
- _lang=lang,
+ _source = source,
+ _lang = lang,
_children = {},
_regions = {},
_trees = {},
@@ -44,7 +44,7 @@ function LanguageTree.new(source, lang, opts)
return self
end
--- Invalidates this parser and all it's children
+-- Invalidates this parser and all its children
function LanguageTree:invalidate()
self._valid = false
@@ -97,7 +97,7 @@ function LanguageTree:parse()
self._trees = {}
-- If there are no ranges, set to an empty list
- -- so the included ranges in the parser ar cleared.
+ -- so the included ranges in the parser are cleared.
if self._regions and #self._regions > 0 then
for i, ranges in ipairs(self._regions) do
local old_tree = old_trees[i]
@@ -214,7 +214,7 @@ function LanguageTree:remove_child(lang)
end
end
--- Destroys this language tree and all it's children.
+-- Destroys this language tree and all its children.
-- Any cleanup logic should be performed here.
-- Note, this DOES NOT remove this tree from a parent.
-- `remove_child` must be called on the parent to remove it.
@@ -241,7 +241,7 @@ end
--
-- Note, this call invalidates the tree and requires it to be parsed again.
--
--- @param regions A list of regions this tree should manange and parse.
+-- @param regions A list of regions this tree should manage and parse.
function LanguageTree:set_included_regions(regions)
-- Transform the tables from 4 element long to 6 element long (with byte offset)
for _, region in ipairs(regions) do
@@ -400,11 +400,11 @@ end
--- Registers callbacks for the parser
-- @param cbs An `nvim_buf_attach`-like table argument with the following keys :
-- `on_bytes` : see `nvim_buf_attach`, but this will be called _after_ the parsers callback.
--- `on_changedtree` : a callback that will be called everytime the tree has syntactical changes.
+-- `on_changedtree` : a callback that will be called every time the tree has syntactical changes.
-- it will only be passed one argument, that is a table of the ranges (as node ranges) that
-- changed.
-- `on_child_added` : emitted when a child is added to the tree.
--- `on_child_removed` : emitted when a child is remvoed from the tree.
+-- `on_child_removed` : emitted when a child is removed from the tree.
function LanguageTree:register_cbs(cbs)
if not cbs then return end
diff --git a/runtime/lua/vim/treesitter/query.lua b/runtime/lua/vim/treesitter/query.lua
index e49f54681d..8b94348994 100644
--- a/runtime/lua/vim/treesitter/query.lua
+++ b/runtime/lua/vim/treesitter/query.lua
@@ -111,7 +111,7 @@ end
--- Gets the text corresponding to a given node
-- @param node the node
--- @param bufnr the buffer from which the node in extracted.
+-- @param bufnr the buffer from which the node is extracted.
function M.get_node_text(node, source)
local start_row, start_col, start_byte = node:start()
local end_row, end_col, end_byte = node:end_()
@@ -215,10 +215,10 @@ predicate_handlers["vim-match?"] = predicate_handlers["match?"]
local directive_handlers = {
["set!"] = function(_, _, _, pred, metadata)
if #pred == 4 then
- -- (set! @capture "key" "value")
+ -- (#set! @capture "key" "value")
metadata[pred[2]][pred[3]] = pred[4]
else
- -- (set! "key" "value")
+ -- (#set! "key" "value")
metadata[pred[2]] = pred[3]
end
end,
@@ -245,7 +245,7 @@ local directive_handlers = {
end
}
---- Adds a new predicates to be used in queries
+--- Adds a new predicate to be used in queries
--
-- @param name the name of the predicate, without leading #
-- @param handler the handler function to be used
@@ -355,10 +355,10 @@ end
--- Iterates of the captures of self on a given range.
--
--- @param node The node under witch the search will occur
+-- @param node The node under which the search will occur
-- @param buffer The source buffer to search
-- @param start The starting line of the search
--- @param stop The stoping line of the search (end-exclusive)
+-- @param stop The stopping line of the search (end-exclusive)
--
-- @returns The matching capture id
-- @returns The captured node
@@ -388,12 +388,12 @@ function Query:iter_captures(node, source, start, stop)
return iter
end
---- Iterates of the matches of self on a given range.
+--- Iterates the matches of self on a given range.
--
--- @param node The node under witch the search will occur
+-- @param node The node under which the search will occur
-- @param buffer The source buffer to search
-- @param start The starting line of the search
--- @param stop The stoping line of the search (end-exclusive)
+-- @param stop The stopping line of the search (end-exclusive)
--
-- @returns The matching pattern id
-- @returns The matching match
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index 09895a2119..b94c99dc5e 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -545,6 +545,26 @@ Object nvim_exec_lua(String code, Array args, Error *err)
return nlua_exec(code, args, err);
}
+/// Notify the user with a message
+///
+/// Relays the call to vim.notify . By default forwards your message in the
+/// echo area but can be overriden to trigger desktop notifications.
+///
+/// @param msg Message to display to the user
+/// @param log_level The log level
+/// @param opts Reserved for future use.
+/// @param[out] err Error details, if any
+Object nvim_notify(String msg, Integer log_level, Dictionary opts, Error *err)
+ FUNC_API_SINCE(7)
+{
+ FIXED_TEMP_ARRAY(args, 3);
+ args.items[0] = STRING_OBJ(msg);
+ args.items[1] = INTEGER_OBJ(log_level);
+ args.items[2] = DICTIONARY_OBJ(opts);
+
+ return nlua_exec(STATIC_CSTR_AS_STRING("return vim.notify(...)"), args, err);
+}
+
/// Calls a VimL function.
///
/// @param fn Function name
diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c
index 140a9c6bcb..3de2e0f342 100644
--- a/src/nvim/autocmd.c
+++ b/src/nvim/autocmd.c
@@ -544,7 +544,7 @@ char_u *au_event_disable(char *what)
} else {
STRCAT(new_ei, what);
}
- set_string_option_direct((char_u *)"ei", -1, new_ei, OPT_FREE, SID_NONE);
+ set_string_option_direct("ei", -1, new_ei, OPT_FREE, SID_NONE);
xfree(new_ei);
return save_ei;
@@ -553,7 +553,7 @@ char_u *au_event_disable(char *what)
void au_event_restore(char_u *old_ei)
{
if (old_ei != NULL) {
- set_string_option_direct((char_u *)"ei", -1, old_ei, OPT_FREE, SID_NONE);
+ set_string_option_direct("ei", -1, old_ei, OPT_FREE, SID_NONE);
xfree(old_ei);
}
}
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 7116b25b29..19ce02700f 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -3236,7 +3236,7 @@ void maketitle(void)
0, maxlen, NULL, NULL);
title_str = (char_u *)buf;
if (called_emsg) {
- set_string_option_direct((char_u *)"titlestring", -1, (char_u *)"",
+ set_string_option_direct("titlestring", -1, (char_u *)"",
OPT_FREE, SID_ERROR);
}
called_emsg |= save_called_emsg;
@@ -3346,7 +3346,7 @@ void maketitle(void)
p_iconstring, use_sandbox,
0, 0, NULL, NULL);
if (called_emsg) {
- set_string_option_direct((char_u *)"iconstring", -1,
+ set_string_option_direct("iconstring", -1,
(char_u *)"", OPT_FREE, SID_ERROR);
}
called_emsg |= save_called_emsg;
@@ -3940,9 +3940,9 @@ int build_stl_str_hl(
// Store the current buffer number as a string variable
vim_snprintf((char *)buf_tmp, sizeof(buf_tmp), "%d", curbuf->b_fnum);
- set_internal_string_var((char_u *)"g:actual_curbuf", buf_tmp);
+ set_internal_string_var("g:actual_curbuf", buf_tmp);
vim_snprintf((char *)win_tmp, sizeof(win_tmp), "%d", curwin->handle);
- set_internal_string_var((char_u *)"g:actual_curwin", win_tmp);
+ set_internal_string_var("g:actual_curwin", win_tmp);
buf_T *const save_curbuf = curbuf;
win_T *const save_curwin = curwin;
diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h
index cc09b7e989..360616609c 100644
--- a/src/nvim/buffer_defs.h
+++ b/src/nvim/buffer_defs.h
@@ -296,13 +296,11 @@ typedef struct arglist {
int id; ///< id of this arglist
} alist_T;
-/*
- * For each argument remember the file name as it was given, and the buffer
- * number that contains the expanded file name (required for when ":cd" is
- * used.
- *
- * TODO: move aentry_T to another header
- */
+// For each argument remember the file name as it was given, and the buffer
+// number that contains the expanded file name (required for when ":cd" is
+// used).
+//
+// TODO(Felipe): move aentry_T to another header
typedef struct argentry {
char_u *ae_fname; // file name as specified
int ae_fnum; // buffer number with expanded file name
@@ -1036,10 +1034,10 @@ struct matchitem {
int id; ///< match ID
int priority; ///< match priority
char_u *pattern; ///< pattern to highlight
- int hlg_id; ///< highlight group ID
regmmatch_T match; ///< regexp program for pattern
posmatch_T pos; ///< position matches
match_T hl; ///< struct for doing the actual highlighting
+ int hlg_id; ///< highlight group ID
int conceal_char; ///< cchar for Conceal highlighting
};
diff --git a/src/nvim/context.c b/src/nvim/context.c
index 1ae0510762..4162daa6ca 100644
--- a/src/nvim/context.c
+++ b/src/nvim/context.c
@@ -126,7 +126,7 @@ bool ctx_restore(Context *ctx, const int flags)
}
char_u *op_shada;
- get_option_value((char_u *)"shada", NULL, &op_shada, OPT_GLOBAL);
+ get_option_value("shada", NULL, &op_shada, OPT_GLOBAL);
set_option_value("shada", 0L, "!,'100,%", OPT_GLOBAL);
if (flags & kCtxRegs) {
diff --git a/src/nvim/diff.c b/src/nvim/diff.c
index 93bc34fa4b..358725239c 100644
--- a/src/nvim/diff.c
+++ b/src/nvim/diff.c
@@ -1375,7 +1375,7 @@ void diff_win_options(win_T *wp, int addbuf)
}
wp->w_p_fdm_save = vim_strsave(wp->w_p_fdm);
}
- set_string_option_direct((char_u *)"fdm", -1, (char_u *)"diff",
+ set_string_option_direct("fdm", -1, (char_u *)"diff",
OPT_LOCAL | OPT_FREE, 0);
curwin = old_curwin;
curbuf = curwin->w_buffer;
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index a25b140b2f..d07618d2c0 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -455,14 +455,15 @@ void eval_clear(void)
* Set an internal variable to a string value. Creates the variable if it does
* not already exist.
*/
-void set_internal_string_var(char_u *name, char_u *value)
+void set_internal_string_var(const char *name, char_u *value)
+ FUNC_ATTR_NONNULL_ARG(1)
{
- const typval_T tv = {
+ typval_T tv = {
.v_type = VAR_STRING,
.vval.v_string = value,
};
- set_var((const char *)name, STRLEN(name), (typval_T *)&tv, true);
+ set_var(name, strlen(name), &tv, true);
}
static lval_T *redir_lval = NULL;
@@ -522,9 +523,9 @@ var_redir_start(
tv.v_type = VAR_STRING;
tv.vval.v_string = (char_u *)"";
if (append) {
- set_var_lval(redir_lval, redir_endp, &tv, true, false, (char_u *)".");
+ set_var_lval(redir_lval, redir_endp, &tv, true, false, ".");
} else {
- set_var_lval(redir_lval, redir_endp, &tv, true, false, (char_u *)"=");
+ set_var_lval(redir_lval, redir_endp, &tv, true, false, "=");
}
clear_lval(redir_lval);
err = did_emsg;
@@ -584,7 +585,7 @@ void var_redir_stop(void)
redir_endp = (char_u *)get_lval(redir_varname, NULL, redir_lval,
false, false, 0, FNE_CHECK_START);
if (redir_endp != NULL && redir_lval->ll_name != NULL) {
- set_var_lval(redir_lval, redir_endp, &tv, false, false, (char_u *)".");
+ set_var_lval(redir_lval, redir_endp, &tv, false, false, ".");
}
clear_lval(redir_lval);
}
@@ -1847,7 +1848,7 @@ static char_u *ex_let_one(char_u *arg, typval_T *const tv,
s = tv_get_string_chk(tv); // != NULL if number or string.
}
if (s != NULL && op != NULL && *op != '=') {
- opt_type = get_option_value(arg, &numval, (char_u **)&stringval,
+ opt_type = get_option_value((char *)arg, &numval, (char_u **)&stringval,
opt_flags);
if ((opt_type == 1 && *op == '.')
|| (opt_type == 0 && *op != '.')) {
@@ -1924,7 +1925,7 @@ static char_u *ex_let_one(char_u *arg, typval_T *const tv,
if (endchars != NULL && vim_strchr(endchars, *skipwhite(p)) == NULL) {
EMSG(_(e_letunexp));
} else {
- set_var_lval(&lv, p, tv, copy, is_const, op);
+ set_var_lval(&lv, p, tv, copy, is_const, (const char *)op);
arg_end = p;
}
}
@@ -2121,9 +2122,10 @@ char_u *get_lval(char_u *const name, typval_T *const rettv,
return NULL;
}
}
- lp->ll_range = TRUE;
- } else
- lp->ll_range = FALSE;
+ lp->ll_range = true;
+ } else {
+ lp->ll_range = false;
+ }
if (*p != ']') {
if (!quiet) {
@@ -2240,12 +2242,10 @@ char_u *get_lval(char_u *const name, typval_T *const rettv,
return NULL;
}
- /*
- * May need to find the item or absolute index for the second
- * index of a range.
- * When no index given: "lp->ll_empty2" is TRUE.
- * Otherwise "lp->ll_n2" is set to the second index.
- */
+ // May need to find the item or absolute index for the second
+ // index of a range.
+ // When no index given: "lp->ll_empty2" is true.
+ // Otherwise "lp->ll_n2" is set to the second index.
if (lp->ll_range && !lp->ll_empty2) {
lp->ll_n2 = (long)tv_get_number(&var2); // Is number or string.
tv_clear(&var2);
@@ -2299,7 +2299,7 @@ void clear_lval(lval_T *lp)
* "%" for "%=", "." for ".=" or "=" for "=".
*/
static void set_var_lval(lval_T *lp, char_u *endp, typval_T *rettv,
- int copy, const bool is_const, const char_u *op)
+ int copy, const bool is_const, const char *op)
{
int cc;
listitem_T *ri;
@@ -2326,7 +2326,7 @@ static void set_var_lval(lval_T *lp, char_u *endp, typval_T *rettv,
TV_CSTRING)
&& !tv_check_lock(di->di_tv.v_lock, (const char *)lp->ll_name,
TV_CSTRING)))
- && eexe_mod_op(&tv, rettv, (const char *)op) == OK) {
+ && eexe_mod_op(&tv, rettv, op) == OK) {
set_var(lp->ll_name, lp->ll_name_len, &tv, false);
}
tv_clear(&tv);
@@ -2369,8 +2369,7 @@ static void set_var_lval(lval_T *lp, char_u *endp, typval_T *rettv,
*/
for (ri = tv_list_first(rettv->vval.v_list); ri != NULL; ) {
if (op != NULL && *op != '=') {
- eexe_mod_op(TV_LIST_ITEM_TV(lp->ll_li), TV_LIST_ITEM_TV(ri),
- (const char *)op);
+ eexe_mod_op(TV_LIST_ITEM_TV(lp->ll_li), TV_LIST_ITEM_TV(ri), op);
} else {
tv_clear(TV_LIST_ITEM_TV(lp->ll_li));
tv_copy(TV_LIST_ITEM_TV(ri), TV_LIST_ITEM_TV(lp->ll_li));
@@ -2428,7 +2427,7 @@ static void set_var_lval(lval_T *lp, char_u *endp, typval_T *rettv,
}
if (op != NULL && *op != '=') {
- eexe_mod_op(lp->ll_tv, rettv, (const char *)op);
+ eexe_mod_op(lp->ll_tv, rettv, op);
goto notify;
} else {
tv_clear(lp->ll_tv);
@@ -4538,7 +4537,7 @@ int get_option_tv(const char **const arg, typval_T *const rettv,
c = *option_end;
*option_end = NUL;
- opt_type = get_option_value((char_u *)(*arg), &numval,
+ opt_type = get_option_value(*arg, &numval,
rettv == NULL ? NULL : &stringval, opt_flags);
if (opt_type == -3) { // invalid name
diff --git a/src/nvim/eval.h b/src/nvim/eval.h
index 06b7f9e21d..c1891758ea 100644
--- a/src/nvim/eval.h
+++ b/src/nvim/eval.h
@@ -56,10 +56,10 @@ typedef struct lval_S {
///< isn't NULL it's the Dict to which to add the item.
listitem_T *ll_li; ///< The list item or NULL.
list_T *ll_list; ///< The list or NULL.
- int ll_range; ///< TRUE when a [i:j] range was used.
+ bool ll_range; ///< true when a [i:j] range was used.
+ bool ll_empty2; ///< Second index is empty: [i:].
long ll_n1; ///< First index for list.
long ll_n2; ///< Second index for list range.
- int ll_empty2; ///< Second index is empty: [i:].
dict_T *ll_dict; ///< The Dictionary or NULL.
dictitem_T *ll_di; ///< The dictitem or NULL.
char_u *ll_newkey; ///< New key for Dict in allocated memory or NULL.
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
index 8788d7ea88..fae5711b9c 100644
--- a/src/nvim/eval/funcs.c
+++ b/src/nvim/eval/funcs.c
@@ -2149,7 +2149,7 @@ static void f_menu_get(typval_T *argvars, typval_T *rettv, FunPtr fptr)
tv_list_alloc_ret(rettv, kListLenMayKnow);
int modes = MENU_ALL_MODES;
if (argvars[1].v_type == VAR_STRING) {
- const char_u *const strmodes = (char_u *)tv_get_string(&argvars[1]);
+ const char *const strmodes = tv_get_string(&argvars[1]);
modes = get_menu_cmd_modes(strmodes, false, NULL, NULL);
}
menu_get((char_u *)tv_get_string(&argvars[0]), modes, rettv->vval.v_list);
@@ -3170,7 +3170,7 @@ static void f_getcompletion(typval_T *argvars, typval_T *rettv, FunPtr fptr)
}
if (xpc.xp_context == EXPAND_MENUS) {
- set_context_in_menu_cmd(&xpc, (char_u *)"menu", xpc.xp_pattern, false);
+ set_context_in_menu_cmd(&xpc, "menu", xpc.xp_pattern, false);
xpc.xp_pattern_len = STRLEN(xpc.xp_pattern);
}
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index 6d26c5f69c..cd7ff9a00b 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -4227,7 +4227,7 @@ skip:
size_t subsize = preview_lines.subresults.size;
if (preview && !aborting()) {
if (got_quit || profile_passed_limit(timeout)) { // Too slow, disable.
- set_string_option_direct((char_u *)"icm", -1, (char_u *)"", OPT_FREE,
+ set_string_option_direct("icm", -1, (char_u *)"", OPT_FREE,
SID_NONE);
} else if (*p_icm != NUL && pat != NULL) {
if (pre_src_id == 0) {
@@ -4528,7 +4528,7 @@ prepare_tagpreview (
RESET_BINDING(curwin); /* don't take over 'scrollbind'
and 'cursorbind' */
curwin->w_p_diff = false; // no 'diff'
- set_string_option_direct((char_u *)"fdc", -1, // no 'foldcolumn'
+ set_string_option_direct("fdc", -1, // no 'foldcolumn'
(char_u *)"0", OPT_FREE, SID_NONE);
return true;
}
@@ -5023,7 +5023,7 @@ int find_help_tags(const char_u *arg, int *num_matches, char_u ***matches,
static void prepare_help_buffer(void)
{
curbuf->b_help = true;
- set_string_option_direct((char_u *)"buftype", -1, (char_u *)"help",
+ set_string_option_direct("buftype", -1, (char_u *)"help",
OPT_FREE|OPT_LOCAL, 0);
// Always set these options after jumping to a help tag, because the
@@ -5033,13 +5033,13 @@ static void prepare_help_buffer(void)
// Only set it when needed, buf_init_chartab() is some work.
char_u *p = (char_u *)"!-~,^*,^|,^\",192-255";
if (STRCMP(curbuf->b_p_isk, p) != 0) {
- set_string_option_direct((char_u *)"isk", -1, p, OPT_FREE|OPT_LOCAL, 0);
+ set_string_option_direct("isk", -1, p, OPT_FREE|OPT_LOCAL, 0);
check_buf_options(curbuf);
(void)buf_init_chartab(curbuf, FALSE);
}
// Don't use the global foldmethod.
- set_string_option_direct((char_u *)"fdm", -1, (char_u *)"manual",
+ set_string_option_direct("fdm", -1, (char_u *)"manual",
OPT_FREE|OPT_LOCAL, 0);
curbuf->b_p_ts = 8; // 'tabstop' is 8.
@@ -5659,7 +5659,7 @@ static buf_T *show_sub(exarg_T *eap, pos_T old_cusr,
cmdmod.tab = 0; // disable :tab modifier
cmdmod.noswapfile = true; // disable swap for preview buffer
// disable file info message
- set_string_option_direct((char_u *)"shm", -1, (char_u *)"F", OPT_FREE,
+ set_string_option_direct("shm", -1, (char_u *)"F", OPT_FREE,
SID_NONE);
bool outside_curline = (eap->line1 != old_cusr.lnum
@@ -5782,7 +5782,7 @@ static buf_T *show_sub(exarg_T *eap, pos_T old_cusr,
update_screen(SOME_VALID);
RedrawingDisabled = save_rd;
- set_string_option_direct((char_u *)"shm", -1, save_shm_p, OPT_FREE, SID_NONE);
+ set_string_option_direct("shm", -1, save_shm_p, OPT_FREE, SID_NONE);
xfree(save_shm_p);
cmdmod = save_cmdmod;
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c
index e49bb99aa0..2598b13079 100644
--- a/src/nvim/ex_cmds2.c
+++ b/src/nvim/ex_cmds2.c
@@ -2375,13 +2375,13 @@ void ex_compiler(exarg_T *eap)
// Set "b:current_compiler" from "current_compiler".
p = get_var_value("g:current_compiler");
if (p != NULL) {
- set_internal_string_var((char_u *)"b:current_compiler", p);
+ set_internal_string_var("b:current_compiler", p);
}
// Restore "current_compiler" for ":compiler {name}".
if (!eap->forceit) {
if (old_cur_comp != NULL) {
- set_internal_string_var((char_u *)"g:current_compiler",
+ set_internal_string_var("g:current_compiler",
old_cur_comp);
xfree(old_cur_comp);
} else {
diff --git a/src/nvim/ex_cmds_defs.h b/src/nvim/ex_cmds_defs.h
index ca84d375ce..f928c61ea4 100644
--- a/src/nvim/ex_cmds_defs.h
+++ b/src/nvim/ex_cmds_defs.h
@@ -188,8 +188,8 @@ struct exarg {
// used for completion on the command line
struct expand {
- int xp_context; // type of expansion
char_u *xp_pattern; // start of item to expand
+ int xp_context; // type of expansion
size_t xp_pattern_len; // bytes in xp_pattern before cursor
char_u *xp_arg; // completion function
sctx_T xp_script_ctx; // SCTX for completion function
@@ -199,9 +199,9 @@ struct expand {
// characters need to be escaped
#endif
int xp_numfiles; // number of files found by file name completion
+ int xp_col; // cursor position in line
char_u **xp_files; // list of files
char_u *xp_line; // text being completed
- int xp_col; // cursor position in line
};
// values for xp_backslash
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index f55344e77e..6cc915c8c2 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -2179,7 +2179,7 @@ int parse_command_modifiers(exarg_T *eap, char_u **errormsg, bool skip_only)
// Set 'eventignore' to "all". Restore the
// existing option value later.
cmdmod.save_ei = vim_strsave(p_ei);
- set_string_option_direct((char_u *)"ei", -1,
+ set_string_option_direct("ei", -1,
(char_u *)"all", OPT_FREE, SID_NONE);
}
continue;
@@ -2291,9 +2291,8 @@ static void undo_cmdmod(const exarg_T *eap, int save_msg_scroll)
}
if (cmdmod.save_ei != NULL) {
- /* Restore 'eventignore' to the value before ":noautocmd". */
- set_string_option_direct((char_u *)"ei", -1, cmdmod.save_ei,
- OPT_FREE, SID_NONE);
+ // Restore 'eventignore' to the value before ":noautocmd".
+ set_string_option_direct("ei", -1, cmdmod.save_ei, OPT_FREE, SID_NONE);
free_string_option(cmdmod.save_ei);
}
@@ -3519,7 +3518,7 @@ const char * set_one_cmd_context(
// EX_XFILE: file names are handled above.
if (!(ea.argt & EX_XFILE)) {
if (context == EXPAND_MENUS) {
- return (const char *)set_context_in_menu_cmd(xp, (char_u *)cmd,
+ return (const char *)set_context_in_menu_cmd(xp, cmd,
(char_u *)arg, forceit);
} else if (context == EXPAND_COMMANDS) {
return arg;
@@ -3599,7 +3598,7 @@ const char * set_one_cmd_context(
case CMD_tmenu: case CMD_tunmenu:
case CMD_popup: case CMD_emenu:
return (const char *)set_context_in_menu_cmd(
- xp, (char_u *)cmd, (char_u *)arg, forceit);
+ xp, cmd, (char_u *)arg, forceit);
case CMD_colorscheme:
xp->xp_context = EXPAND_COLORS;
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index cf6bb6d492..7776191869 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -886,7 +886,7 @@ static uint8_t *command_line_enter(int firstc, long count, int indent)
need_wait_return = false;
}
- set_string_option_direct((char_u *)"icm", -1, s->save_p_icm, OPT_FREE,
+ set_string_option_direct("icm", -1, s->save_p_icm, OPT_FREE,
SID_NONE);
State = s->save_State;
setmouse();
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index a542bb19dd..b240e7b134 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -1644,8 +1644,7 @@ failed:
save_file_ff(curbuf);
// If editing a new file: set 'fenc' for the current buffer.
// Also for ":read ++edit file".
- set_string_option_direct((char_u *)"fenc", -1, fenc,
- OPT_FREE | OPT_LOCAL, 0);
+ set_string_option_direct("fenc", -1, fenc, OPT_FREE | OPT_LOCAL, 0);
}
if (fenc_alloced)
xfree(fenc);
@@ -2002,7 +2001,7 @@ void set_forced_fenc(exarg_T *eap)
{
if (eap->force_enc != 0) {
char_u *fenc = enc_canonize(eap->cmd + eap->force_enc);
- set_string_option_direct((char_u *)"fenc", -1, fenc, OPT_FREE|OPT_LOCAL, 0);
+ set_string_option_direct("fenc", -1, fenc, OPT_FREE|OPT_LOCAL, 0);
xfree(fenc);
}
}
diff --git a/src/nvim/log.h b/src/nvim/log.h
index f2e74df031..17d754c033 100644
--- a/src/nvim/log.h
+++ b/src/nvim/log.h
@@ -17,10 +17,11 @@
#endif
-#define DEBUG_LOG_LEVEL 0
-#define INFO_LOG_LEVEL 1
-#define WARN_LOG_LEVEL 2
-#define ERROR_LOG_LEVEL 3
+#define TRACE_LOG_LEVEL 0
+#define DEBUG_LOG_LEVEL 1
+#define INFO_LOG_LEVEL 2
+#define WARN_LOG_LEVEL 3
+#define ERROR_LOG_LEVEL 4
#define DLOG(...)
#define DLOGN(...)
diff --git a/src/nvim/lua/vim.lua b/src/nvim/lua/vim.lua
index dbf4f6014c..00a4fe26d3 100644
--- a/src/nvim/lua/vim.lua
+++ b/src/nvim/lua/vim.lua
@@ -39,6 +39,16 @@ assert(vim)
vim.inspect = package.loaded['vim.inspect']
assert(vim.inspect)
+vim.log = {
+ levels = {
+ TRACE = 0;
+ DEBUG = 1;
+ INFO = 2;
+ WARN = 3;
+ ERROR = 4;
+ }
+}
+
-- Internal-only until comments in #8107 are addressed.
-- Returns:
-- {errcode}, {output}
@@ -478,6 +488,23 @@ function vim.defer_fn(fn, timeout)
return timer
end
+
+--- Notification provider
+--- without a runtime, writes to :Messages
+-- see :help nvim_notify
+--@param msg Content of the notification to show to the user
+--@param log_level Optional log level
+--@param opts Dictionary with optional options (timeout, etc)
+function vim.notify(msg, log_level, _opts)
+
+ if log_level == vim.log.levels.ERROR then
+ vim.api.nvim_err_writeln(msg)
+ else
+ vim.api.nvim_echo(msg)
+ end
+end
+
+
local on_keystroke_callbacks = {}
--- Register a lua {fn} with an {id} to be run after every keystroke.
diff --git a/src/nvim/main.c b/src/nvim/main.c
index 9f71df3a46..7064f2a068 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -1404,9 +1404,9 @@ static void load_plugins(void)
static void handle_quickfix(mparm_T *paramp)
{
if (paramp->edit_type == EDIT_QF) {
- if (paramp->use_ef != NULL)
- set_string_option_direct((char_u *)"ef", -1,
- paramp->use_ef, OPT_FREE, SID_CARG);
+ if (paramp->use_ef != NULL) {
+ set_string_option_direct("ef", -1, paramp->use_ef, OPT_FREE, SID_CARG);
+ }
vim_snprintf((char *)IObuff, IOSIZE, "cfile %s", p_ef);
if (qf_init(NULL, p_ef, p_efm, true, IObuff, p_menc) < 0) {
msg_putchar('\n');
diff --git a/src/nvim/memline_defs.h b/src/nvim/memline_defs.h
index 9a6f29a908..dc4755f83d 100644
--- a/src/nvim/memline_defs.h
+++ b/src/nvim/memline_defs.h
@@ -45,16 +45,16 @@ typedef struct memline {
memfile_T *ml_mfp; // pointer to associated memfile
+ infoptr_T *ml_stack; // stack of pointer blocks (array of IPTRs)
+ int ml_stack_top; // current top of ml_stack
+ int ml_stack_size; // total number of entries in ml_stack
+
#define ML_EMPTY 1 // empty buffer
#define ML_LINE_DIRTY 2 // cached line was changed and allocated
#define ML_LOCKED_DIRTY 4 // ml_locked was changed
#define ML_LOCKED_POS 8 // ml_locked needs positive block number
int ml_flags;
- infoptr_T *ml_stack; // stack of pointer blocks (array of IPTRs)
- int ml_stack_top; // current top of ml_stack
- int ml_stack_size; // total number of entries in ml_stack
-
linenr_T ml_line_lnum; // line number of cached line, 0 if not valid
char_u *ml_line_ptr; // pointer to cached line
size_t ml_line_offset; // cached byte offset of ml_line_lnum
diff --git a/src/nvim/menu.c b/src/nvim/menu.c
index 7094d3be90..ac3b7768e6 100644
--- a/src/nvim/menu.c
+++ b/src/nvim/menu.c
@@ -81,7 +81,7 @@ ex_menu(exarg_T *eap)
// kFalse for "menu disable
vimmenu_T menuarg;
- modes = get_menu_cmd_modes(eap->cmd, eap->forceit, &noremap, &unmenu);
+ modes = get_menu_cmd_modes((char *)eap->cmd, eap->forceit, &noremap, &unmenu);
arg = eap->arg;
for (;; ) {
@@ -912,7 +912,9 @@ static int expand_emenu; /* TRUE for ":emenu" command */
/*
* Work out what to complete when doing command line completion of menu names.
*/
-char_u *set_context_in_menu_cmd(expand_T *xp, char_u *cmd, char_u *arg, int forceit)
+char_u *set_context_in_menu_cmd(expand_T *xp, const char *cmd, char_u *arg,
+ bool forceit)
+ FUNC_ATTR_NONNULL_ALL
{
char_u *after_dot;
char_u *p;
@@ -1178,7 +1180,7 @@ static bool menu_namecmp(const char_u *const name, const char_u *const mname)
/// to whether the command is an "unmenu" command.
int
get_menu_cmd_modes(
- const char_u * cmd,
+ const char *cmd,
bool forceit,
int *noremap,
int *unmenu
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 7cc83399e5..ac25c86b5f 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -2120,9 +2120,9 @@ static int shada_idx = -1;
// "set_sid".
void
set_string_option_direct(
- char_u *name,
+ const char *name,
int opt_idx,
- char_u *val,
+ const char_u *val,
int opt_flags, // OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL
int set_sid
)
@@ -2133,7 +2133,7 @@ set_string_option_direct(
int idx = opt_idx;
if (idx == -1) { // Use name.
- idx = findoption((const char *)name);
+ idx = findoption(name);
if (idx < 0) { // Not found (should not happen).
internal_error("set_string_option_direct()");
IEMSG2(_("For option %s"), name);
@@ -3791,7 +3791,7 @@ static char *set_bool_option(const int opt_idx, char_u *const varp,
if (p_terse && p == NULL) {
STRCPY(IObuff, p_shm);
STRCAT(IObuff, "s");
- set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
+ set_string_option_direct("shm", -1, IObuff, OPT_FREE, 0);
} else if (!p_terse && p != NULL) { // remove 's' from p_shm
STRMOVE(p, p + 1);
}
@@ -4531,7 +4531,7 @@ bool is_tty_option(const char *name)
#define TCO_BUFFER_SIZE 8
/// @param name TUI-related option
/// @param[out,allocated] value option string value
-bool get_tty_option(char *name, char **value)
+bool get_tty_option(const char *name, char **value)
{
if (strequal(name, "t_Co")) {
if (value) {
@@ -4597,6 +4597,7 @@ bool set_tty_option(const char *name, char *value)
///
/// @return Option index or -1 if option was not found.
static int findoption(const char *const arg)
+ FUNC_ATTR_NONNULL_ALL
{
return findoption_len(arg, strlen(arg));
}
@@ -4610,17 +4611,17 @@ static int findoption(const char *const arg)
/// hidden String option: -2.
/// unknown option: -3.
int get_option_value(
- char_u *name,
+ const char *name,
long *numval,
char_u **stringval, ///< NULL when only checking existence
int opt_flags
)
{
- if (get_tty_option((char *)name, (char **)stringval)) {
+ if (get_tty_option(name, (char **)stringval)) {
return 0;
}
- int opt_idx = findoption((const char *)name);
+ int opt_idx = findoption(name);
if (opt_idx < 0) { // Unknown option.
return -3;
}
@@ -7054,7 +7055,7 @@ void set_fileformat(int eol_style, int opt_flags)
// p is NULL if "eol_style" is EOL_UNKNOWN.
if (p != NULL) {
- set_string_option_direct((char_u *)"ff",
+ set_string_option_direct("ff",
-1,
(char_u *)p,
OPT_FREE | opt_flags,
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c
index e074f73d04..dfd38a6eca 100644
--- a/src/nvim/quickfix.c
+++ b/src/nvim/quickfix.c
@@ -3665,7 +3665,7 @@ static int qf_open_new_cwindow(qf_info_T *qi, int height)
static void qf_set_title_var(qf_list_T *qfl)
{
if (qfl->qf_title != NULL) {
- set_internal_string_var((char_u *)"w:quickfix_title", qfl->qf_title);
+ set_internal_string_var("w:quickfix_title", qfl->qf_title);
}
}
@@ -4951,7 +4951,7 @@ void ex_cfile(exarg_T *eap)
}
}
if (*eap->arg != NUL) {
- set_string_option_direct((char_u *)"ef", -1, eap->arg, OPT_FREE, 0);
+ set_string_option_direct("ef", -1, eap->arg, OPT_FREE, 0);
}
char_u *enc = (*curbuf->b_p_menc != NUL) ? curbuf->b_p_menc : p_menc;
diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index a78f905a70..6b6c51d836 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -5092,9 +5092,9 @@ static void redraw_custom_statusline(win_T *wp)
// When there is an error disable the statusline, otherwise the
// display is messed up with errors and a redraw triggers the problem
// again and again.
- set_string_option_direct((char_u *)"statusline", -1,
- (char_u *)"", OPT_FREE | (*wp->w_p_stl != NUL
- ? OPT_LOCAL : OPT_GLOBAL), SID_ERROR);
+ set_string_option_direct("statusline", -1, (char_u *)"",
+ OPT_FREE | (*wp->w_p_stl != NUL
+ ? OPT_LOCAL : OPT_GLOBAL), SID_ERROR);
}
did_emsg |= saved_did_emsg;
entered = false;
@@ -5175,7 +5175,7 @@ get_keymap_str (
static void
win_redr_custom (
win_T *wp,
- int draw_ruler /* TRUE or FALSE */
+ bool draw_ruler
)
{
static int entered = FALSE;
@@ -6852,7 +6852,7 @@ void draw_tabline(void)
did_emsg = false;
win_redr_custom(NULL, false);
if (did_emsg) {
- set_string_option_direct((char_u *)"tabline", -1,
+ set_string_option_direct("tabline", -1,
(char_u *)"", OPT_FREE, SID_ERROR);
}
did_emsg |= saved_did_emsg;
@@ -7114,11 +7114,12 @@ static void win_redr_ruler(win_T *wp, int always)
if (*p_ruf) {
int save_called_emsg = called_emsg;
- called_emsg = FALSE;
- win_redr_custom(wp, TRUE);
- if (called_emsg)
- set_string_option_direct((char_u *)"rulerformat", -1,
- (char_u *)"", OPT_FREE, SID_ERROR);
+ called_emsg = false;
+ win_redr_custom(wp, true);
+ if (called_emsg) {
+ set_string_option_direct("rulerformat", -1, (char_u *)"",
+ OPT_FREE, SID_ERROR);
+ }
called_emsg |= save_called_emsg;
return;
}
diff --git a/src/nvim/sign_defs.h b/src/nvim/sign_defs.h
index c898dba890..19c0263cf1 100644
--- a/src/nvim/sign_defs.h
+++ b/src/nvim/sign_defs.h
@@ -24,11 +24,11 @@ typedef struct signlist signlist_T;
struct signlist
{
int id; // unique identifier for each placed sign
- linenr_T lnum; // line number which has this sign
int typenr; // typenr of sign
+ int priority; // priority for highlighting
bool has_text_or_icon; // has text or icon
+ linenr_T lnum; // line number which has this sign
signgroup_T *group; // sign group
- int priority; // priority for highlighting
signlist_T *next; // next signlist entry
signlist_T *prev; // previous entry -- for easy reordering
};
diff --git a/src/nvim/spell.c b/src/nvim/spell.c
index 6425c9fed5..fd1e01395a 100644
--- a/src/nvim/spell.c
+++ b/src/nvim/spell.c
@@ -6624,7 +6624,7 @@ void ex_spelldump(exarg_T *eap)
if (no_spell_checking(curwin)) {
return;
}
- get_option_value((char_u *)"spl", &dummy, &spl, OPT_LOCAL);
+ get_option_value("spl", &dummy, &spl, OPT_LOCAL);
// Create a new empty buffer in a new window.
do_cmdline_cmd("new");
diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c
index f99eca7953..547d953be9 100644
--- a/src/nvim/syntax.c
+++ b/src/nvim/syntax.c
@@ -3419,7 +3419,7 @@ static void syn_cmd_on(exarg_T *eap, int syncing)
*/
static void syn_cmd_enable(exarg_T *eap, int syncing)
{
- set_internal_string_var((char_u *)"syntax_cmd", (char_u *)"enable");
+ set_internal_string_var("syntax_cmd", (char_u *)"enable");
syn_cmd_onoff(eap, "syntax");
do_unlet(S_LEN("g:syntax_cmd"), true);
}
@@ -3432,7 +3432,7 @@ static void syn_cmd_reset(exarg_T *eap, int syncing)
{
eap->nextcmd = check_nextcmd(eap->arg);
if (!eap->skip) {
- set_internal_string_var((char_u *)"syntax_cmd", (char_u *)"reset");
+ set_internal_string_var("syntax_cmd", (char_u *)"reset");
do_cmdline_cmd("runtime! syntax/syncolor.vim");
do_unlet(S_LEN("g:syntax_cmd"), true);
}
@@ -5614,14 +5614,14 @@ void ex_ownsyntax(exarg_T *eap)
// Move value of b:current_syntax to w:current_syntax.
new_value = get_var_value("b:current_syntax");
if (new_value != NULL) {
- set_internal_string_var((char_u *)"w:current_syntax", new_value);
+ set_internal_string_var("w:current_syntax", new_value);
}
// Restore value of b:current_syntax.
if (old_value == NULL) {
do_unlet(S_LEN("b:current_syntax"), true);
} else {
- set_internal_string_var((char_u *)"b:current_syntax", old_value);
+ set_internal_string_var("b:current_syntax", old_value);
xfree(old_value);
}
}
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index 3ff3efb8c9..85baff412b 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -475,6 +475,15 @@ describe('API', function()
end)
end)
+ describe('nvim_notify', function()
+ it('can be overriden', function()
+ command("lua vim.notify = function(...) return 42 end")
+ eq(42, meths.exec_lua("return vim.notify('Hello world')", {}))
+ nvim("notify", "hello world", 4, {})
+ end)
+ end)
+
+
describe('nvim_input', function()
it("VimL error: does NOT fail, updates v:errmsg", function()
local status, _ = pcall(nvim, "input", ":call bogus_fn()<CR>")