aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmake.deps/CMakeLists.txt8
-rw-r--r--cmake.deps/cmake/BuildTreesitterParsers.cmake6
-rw-r--r--runtime/doc/api.txt8
-rw-r--r--runtime/doc/lua.txt6
-rw-r--r--runtime/doc/news.txt4
-rw-r--r--runtime/doc/treesitter.txt37
-rw-r--r--runtime/lua/vim/loader.lua92
-rw-r--r--runtime/lua/vim/lsp/diagnostic.lua2
-rw-r--r--runtime/lua/vim/shared.lua8
-rw-r--r--runtime/lua/vim/treesitter/health.lua2
-rw-r--r--runtime/lua/vim/treesitter/language.lua4
-rw-r--r--runtime/queries/c/highlights.scm115
-rw-r--r--runtime/queries/c/injections.scm4
-rw-r--r--runtime/queries/lua/highlights.scm43
-rw-r--r--runtime/queries/lua/injections.scm12
-rw-r--r--runtime/queries/vim/highlights.scm2
-rw-r--r--runtime/queries/vimdoc/highlights.scm (renamed from runtime/queries/help/highlights.scm)0
-rw-r--r--runtime/queries/vimdoc/injections.scm (renamed from runtime/queries/help/injections.scm)0
-rw-r--r--scripts/gen_help_html.lua6
-rw-r--r--src/nvim/api/vim.c7
-rw-r--r--src/nvim/channel.c2
-rw-r--r--src/nvim/charset.c4
-rw-r--r--src/nvim/drawscreen.c6
-rw-r--r--src/nvim/eval.c6
-rw-r--r--src/nvim/eval/funcs.c6
-rw-r--r--src/nvim/ex_cmds.c2
-rw-r--r--src/nvim/ex_cmds2.c2
-rw-r--r--src/nvim/ex_session.c2
-rw-r--r--src/nvim/globals.h60
-rw-r--r--src/nvim/grid.c4
-rw-r--r--src/nvim/highlight_group.c26
-rw-r--r--src/nvim/lua/executor.c2
-rw-r--r--src/nvim/lua/stdlib.c2
-rw-r--r--src/nvim/main.c2
-rw-r--r--src/nvim/match.c7
-rw-r--r--src/nvim/message.c59
-rw-r--r--src/nvim/move.c2
-rw-r--r--src/nvim/os/env.c2
-rw-r--r--src/nvim/regexp.c14
-rw-r--r--src/nvim/runtime.c27
-rw-r--r--src/nvim/search.c4
-rw-r--r--src/nvim/spellfile.c4
-rw-r--r--src/nvim/spellsuggest.c10
-rw-r--r--src/nvim/tag.c2
-rw-r--r--test/functional/api/highlight_spec.lua14
-rw-r--r--test/functional/lua/vim_spec.lua9
-rw-r--r--test/functional/treesitter/highlight_spec.lua16
-rw-r--r--test/old/testdir/test_packadd.vim7
48 files changed, 401 insertions, 268 deletions
diff --git a/cmake.deps/CMakeLists.txt b/cmake.deps/CMakeLists.txt
index 1e61d959c6..4659183d19 100644
--- a/cmake.deps/CMakeLists.txt
+++ b/cmake.deps/CMakeLists.txt
@@ -191,11 +191,11 @@ set(TREESITTER_C_SHA256 af66fde03feb0df4faf03750102a0d265b007e5d957057b6b293c131
set(TREESITTER_LUA_URL https://github.com/MunifTanjim/tree-sitter-lua/archive/v0.0.14.tar.gz)
set(TREESITTER_LUA_SHA256 930d0370dc15b66389869355c8e14305b9ba7aafd36edbfdb468c8023395016d)
-set(TREESITTER_VIM_URL https://github.com/vigoux/tree-sitter-viml/archive/55ff1b080c09edeced9b748cf4c16d0b49d17fb9.tar.gz)
-set(TREESITTER_VIM_SHA256 1b1cd39e33c8fb02fa7fe3977e844883c2a8508a7edd621f2d21e39a9aeefa92)
+set(TREESITTER_VIM_URL https://github.com/vigoux/tree-sitter-viml/archive/e39a7bbcfdcfc7900629962b785c7e14503ae590.tar.gz)
+set(TREESITTER_VIM_SHA256 7ca85fa1a5a9e4d057ff3b7ae53d13d31371973e734ada87a83f3f6cbe9c0e32)
-set(TREESITTER_HELP_URL https://github.com/neovim/tree-sitter-vimdoc/archive/v1.3.0.tar.gz)
-set(TREESITTER_HELP_SHA256 f33f6d49c7d71feb2fd68ef2b2684da150f9f8e486ad9726213631d673942331)
+set(TREESITTER_VIMDOC_URL https://github.com/neovim/tree-sitter-vimdoc/archive/b2ec4ec5f7be24cb6f7ccffafd7204477fe5784a.tar.gz)
+set(TREESITTER_VIMDOC_SHA256 0689a57d455243de6c6a6c8737a8ce137e225eb8f32676a7037f7dd13dfaec5d)
set(TREESITTER_QUERY_URL https://github.com/nvim-treesitter/tree-sitter-query/archive/v0.1.0.tar.gz)
set(TREESITTER_QUERY_SHA256 e2b806f80e8bf1c4f4e5a96248393fe6622fc1fc6189d6896d269658f67f914c)
diff --git a/cmake.deps/cmake/BuildTreesitterParsers.cmake b/cmake.deps/cmake/BuildTreesitterParsers.cmake
index 1202e4f7a4..ef7d521249 100644
--- a/cmake.deps/cmake/BuildTreesitterParsers.cmake
+++ b/cmake.deps/cmake/BuildTreesitterParsers.cmake
@@ -38,9 +38,9 @@ BuildTSParser(
CMAKE_FILE TreesitterParserCMakeLists.txt)
BuildTSParser(
- LANG help
- URL ${TREESITTER_HELP_URL}
- SHA256 ${TREESITTER_HELP_SHA256}
+ LANG vimdoc
+ URL ${TREESITTER_VIMDOC_URL}
+ SHA256 ${TREESITTER_VIMDOC_SHA256}
CMAKE_FILE TreesitterParserCMakeLists.txt)
BuildTSParser(
diff --git a/runtime/doc/api.txt b/runtime/doc/api.txt
index b51da8d56f..844bf772f1 100644
--- a/runtime/doc/api.txt
+++ b/runtime/doc/api.txt
@@ -941,6 +941,10 @@ nvim_get_hl({ns_id}, {*opts}) *nvim_get_hl()*
map as in |nvim_set_hl()|, or only a single highlight definition map
if requested by name or id.
+ Note:
+ When the `link` attribute is defined in the highlight definition map,
+ other attributes will not be taking effect (see |:hi-link|).
+
nvim_get_hl_id_by_name({name}) *nvim_get_hl_id_by_name()*
Gets a highlight group by name
@@ -1388,6 +1392,10 @@ nvim_set_hl({ns_id}, {name}, {*val}) *nvim_set_hl()*
values of the Normal group. If the Normal group has not been defined,
using these values results in an error.
+ Note:
+ If `link` is used in combination with other attributes; only the
+ `link` will take effect (see |:hi-link|).
+
Parameters: ~
• {ns_id} Namespace id for this highlight |nvim_create_namespace()|.
Use 0 to set a highlight group globally |:highlight|.
diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt
index 33833fa83e..ebbf8bb463 100644
--- a/runtime/doc/lua.txt
+++ b/runtime/doc/lua.txt
@@ -1635,8 +1635,8 @@ defaulttable({create}) *vim.defaulttable()*
<
Parameters: ~
- • {create} (function|nil) The function called to create a missing
- value.
+ • {create} function?(key:any):any The function called to create a
+ missing value.
Return: ~
(table) Empty table with metamethod
@@ -2065,7 +2065,7 @@ find({modname}, {opts}) *vim.loader.find()*
for `modname="*"`
reset({path}) *vim.loader.reset()*
- Resets the topmods cache for the path, or all the paths if path is nil.
+ Resets the cache for the path, or all the paths if path is nil.
Parameters: ~
• {path} string? path to reset
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt
index 401719b432..671bdee31b 100644
--- a/runtime/doc/news.txt
+++ b/runtime/doc/news.txt
@@ -62,6 +62,10 @@ The following changes may require adaptations in user config or plugins.
• |nvim_exec()| is now deprecated in favor of |nvim_exec2()|.
+• `help` treesitter parser was renamed to `vimdoc`. The only user-visible
+ change is that language-specific highlight groups need to be renamed from
+ `@foo.help` to `@foo.vimdoc`.
+
==============================================================================
NEW FEATURES *news-features*
diff --git a/runtime/doc/treesitter.txt b/runtime/doc/treesitter.txt
index 96021d6272..0298f5a9b1 100644
--- a/runtime/doc/treesitter.txt
+++ b/runtime/doc/treesitter.txt
@@ -195,7 +195,7 @@ treesitter queries from Lua.
TREESITTER QUERY PREDICATES *treesitter-predicates*
Predicates are special scheme nodes that are evaluated to conditionally capture
-nodes. For example, the `eq?` predicate can be used as follows: >
+nodes. For example, the `eq?` predicate can be used as follows: >query
((identifier) @foo (#eq? @foo "foo"))
<
@@ -204,13 +204,13 @@ to only match identifier corresponding to the `"foo"` text.
The following predicates are built in:
`eq?` *treesitter-predicate-eq?*
- Match a string against the text corresponding to a node: >
+ Match a string against the text corresponding to a node: >query
((identifier) @foo (#eq? @foo "foo"))
((node1) @left (node2) @right (#eq? @left @right))
<
`match?` *treesitter-predicate-match?*
`vim-match?` *treesitter-predicate-vim-match?*
- Match a |regexp| against the text corresponding to a node: >
+ Match a |regexp| against the text corresponding to a node: >query
((identifier) @constant (#match? @constant "^[A-Z_]+$"))
< Note: The `^` and `$` anchors will match the start and end of the
node's text.
@@ -220,13 +220,14 @@ The following predicates are built in:
similar to `match?`
`contains?` *treesitter-predicate-contains?*
- Match a string against parts of the text corresponding to a node: >
+ Match a string against parts of the text corresponding to a node:
+ >query
((identifier) @foo (#contains? @foo "foo"))
((identifier) @foo-bar (#contains? @foo-bar "foo" "bar"))
<
`any-of?` *treesitter-predicate-any-of?*
Match any of the given strings against the text corresponding to
- a node: >
+ a node: >query
((identifier) @foo (#any-of? @foo "foo" "bar"))
<
This is the recommended way to check if the node matches one of many
@@ -243,7 +244,7 @@ Use |vim.treesitter.query.list_predicates()| to list all available predicates.
TREESITTER QUERY DIRECTIVES *treesitter-directives*
Treesitter directives store metadata for a node or match and perform side
-effects. For example, the `set!` directive sets metadata on the match or node: >
+effects. For example, the `set!` directive sets metadata on the match or node: >query
((identifier) @foo (#set! "type" "parameter"))
<
@@ -259,7 +260,7 @@ The following directives are built in:
{key}
{value}
- Examples: >
+ Examples: >query
((identifier) @foo (#set! @foo "kind" "parameter"))
((node1) @left (node2) @right (#set! "type" "pair"))
<
@@ -275,7 +276,7 @@ The following directives are built in:
{end_row}
{end_col}
- Example: >
+ Example: >query
((identifier) @constant (#offset! @constant 0 1 0 -1))
<
@@ -304,7 +305,8 @@ currently supported modeline alternatives:
a base depends on your 'runtimepath' value.
Note: These modeline comments must be at the top of the query, but can be
-repeated, for example, the following two modeline blocks are both valid: >
+repeated, for example, the following two modeline blocks are both valid:
+>query
;; inherits: foo,bar
;; extends
@@ -318,13 +320,13 @@ TREESITTER SYNTAX HIGHLIGHTING *treesitter-highlight*
Syntax highlighting is specified through queries named `highlights.scm`,
which match a |TSNode| in the parsed |TSTree| to a `capture` that can be
-assigned a highlight group. For example, the query >
+assigned a highlight group. For example, the query >query
(parameters (identifier) @parameter)
<
matches any `identifier` node inside a function `parameter` node (e.g., the
`bar` in `foo(bar)`) to the capture named `@parameter`. It is also possible to
-match literal expressions (provided the parser returns them): >
+match literal expressions (provided the parser returns them): >query
"return" @keyword.return
<
@@ -409,7 +411,7 @@ The following captures are linked by default to standard |group-name|s:
*treesitter-highlight-spell*
The special `@spell` capture can be used to indicate that a node should be
spell checked by Nvim's builtin |spell| checker. For example, the following
-capture marks comments as to be checked: >
+capture marks comments as to be checked: >query
(comment) @spell
<
@@ -420,14 +422,14 @@ There is also `@nospell` which disables spellchecking regions with `@spell`.
Treesitter highlighting supports |conceal| via the `conceal` metadata. By
convention, nodes to be concealed are captured as `@conceal`, but any capture
can be used. For example, the following query can be used to hide code block
-delimiters in Markdown: >
+delimiters in Markdown: >query
- (fenced_code_block_delimiter) @conceal (#set! conceal "")
+ (fenced_code_block_delimiter @conceal (#set! conceal ""))
<
It is also possible to replace a node with a single character, which (unlike
legacy syntax) can be given a custom highlight. For example, the following
(ill-advised) query replaces the `!=` operator by a Unicode glyph, which is
-still highlighted the same as other operators: >
+still highlighted the same as other operators: >query
"!=" @operator (#set! conceal "≠")
<
@@ -438,9 +440,10 @@ Treesitter uses |nvim_buf_set_extmark()| to set highlights with a default
priority of 100. This enables plugins to set a highlighting priority lower or
higher than tree-sitter. It is also possible to change the priority of an
individual query pattern manually by setting its `"priority"` metadata
-attribute: >
+attribute: >query
- (super_important_node) @ImportantHighlight (#set! "priority" 105)
+ ((super_important_node) @superimportant (#set! "priority" 105))
+<
==============================================================================
TREESITTER LANGUAGE INJECTIONS *treesitter-language-injections*
diff --git a/runtime/lua/vim/loader.lua b/runtime/lua/vim/loader.lua
index 7b6b9cb563..201de18497 100644
--- a/runtime/lua/vim/loader.lua
+++ b/runtime/lua/vim/loader.lua
@@ -5,7 +5,7 @@ local loaders = package.loaders
local M = {}
----@alias CacheHash {mtime: {sec:number, nsec:number}, size:number}
+---@alias CacheHash {mtime: {sec:number, nsec:number}, size:number, type: string}
---@alias CacheEntry {hash:CacheHash, chunk:string}
---@class ModuleFindOpts
@@ -32,6 +32,8 @@ local Loader = {
VERSION = 3,
---@type table<string, table<string,ModuleInfo>>
_indexed = {},
+ ---@type table<string, CacheHash>
+ _hashes = {},
---@type table<string, string[]>
_topmods = {},
_loadfile = loadfile,
@@ -41,6 +43,18 @@ local Loader = {
},
}
+--- @param path string
+--- @return uv.fs_stat.result
+--- @private
+function Loader.get_hash(path)
+ if not Loader._hashes[path] then
+ -- Note we must never save a stat for a non-existent path.
+ -- For non-existent paths fs_stat() will return nil.
+ Loader._hashes[path] = uv.fs_stat(path)
+ end
+ return Loader._hashes[path]
+end
+
---@private
local function normalize(path)
return vim.fs.normalize(path, { expand_env = false })
@@ -102,18 +116,28 @@ function Loader.write(name, entry)
uv.fs_close(f)
end
+--- @param path string
+--- @param mode integer
+--- @return string? data
+--- @private
+local function readfile(path, mode)
+ local f = uv.fs_open(path, 'r', mode)
+ if f then
+ local hash = assert(uv.fs_fstat(f))
+ local data = uv.fs_read(f, hash.size, 0) --[[@as string?]]
+ uv.fs_close(f)
+ return data
+ end
+end
+
--- Loads the cache entry for a given module or file
---@param name string module name or filename
---@return CacheEntry?
---@private
function Loader.read(name)
local cname = Loader.cache_file(name)
- local f = uv.fs_open(cname, 'r', 438)
- if f then
- local hash = uv.fs_fstat(f) --[[@as CacheHash]]
- local data = uv.fs_read(f, hash.size, 0) --[[@as string]]
- uv.fs_close(f)
-
+ local data = readfile(cname, 438)
+ if data then
local zero = data:find('\0', 1, true)
if not zero then
return
@@ -141,7 +165,9 @@ end
function Loader.loader(modname)
local ret = M.find(modname)[1]
if ret then
- local chunk, err = Loader.load(ret.modpath, { hash = ret.stat })
+ -- Make sure to call the global loadfile so we respect any augmentations done elsewhere.
+ -- E.g. profiling
+ local chunk, err = loadfile(ret.modpath)
return chunk or error(err)
end
return '\ncache_loader: module ' .. modname .. ' not found'
@@ -171,17 +197,17 @@ function Loader.loader_lib(modname)
end
--- `loadfile` using the cache
+--- Note this has the mode and env arguments which is supported by LuaJIT and is 5.1 compatible.
---@param filename? string
---@param mode? "b"|"t"|"bt"
---@param env? table
----@param hash? CacheHash
---@return function?, string? error_message
---@private
-- luacheck: ignore 312
-function Loader.loadfile(filename, mode, env, hash)
+function Loader.loadfile(filename, mode, env)
-- ignore mode, since we byte-compile the lua source files
mode = nil
- return Loader.load(normalize(filename), { mode = mode, env = env, hash = hash })
+ return Loader.load(normalize(filename), { mode = mode, env = env })
end
--- Checks whether two cache hashes are the same based on:
@@ -201,8 +227,7 @@ end
--- Loads the given module path using the cache
---@param modpath string
----@param opts? {hash?: CacheHash, mode?: "b"|"t"|"bt", env?:table} (table|nil) Options for loading the module:
---- - hash: (table) the hash of the file to load if it is already known. (defaults to `vim.loop.fs_stat({modpath})`)
+---@param opts? {mode?: "b"|"t"|"bt", env?:table} (table|nil) Options for loading the module:
--- - mode: (string) the mode to load the module with. "b"|"t"|"bt" (defaults to `nil`)
--- - env: (table) the environment to load the module in. (defaults to `nil`)
---@see |luaL_loadfile()|
@@ -210,7 +235,7 @@ end
---@private
function Loader.load(modpath, opts)
opts = opts or {}
- local hash = opts.hash or uv.fs_stat(modpath)
+ local hash = Loader.get_hash(modpath)
---@type function?, string?
local chunk, err
@@ -301,7 +326,7 @@ function M.find(modname, opts)
for _, pattern in ipairs(patterns) do
local modpath = path .. pattern
Loader._stats.find.stat = (Loader._stats.find.stat or 0) + 1
- local hash = uv.fs_stat(modpath)
+ local hash = Loader.get_hash(modpath)
if hash then
results[#results + 1] = { modpath = modpath, stat = hash, modname = modname }
if not continue() then
@@ -337,7 +362,7 @@ function M.find(modname, opts)
return results
end
---- Resets the topmods cache for the path, or all the paths
+--- Resets the cache for the path, or all the paths
--- if path is nil.
---@param path string? path to reset
function M.reset(path)
@@ -346,6 +371,9 @@ function M.reset(path)
else
Loader._indexed = {}
end
+
+ -- Path could be a directory so just clear all the hashes.
+ Loader._hashes = {}
end
--- Enables the experimental Lua module loader:
@@ -399,7 +427,7 @@ function Loader.lsmod(path)
for name, t in vim.fs.dir(path .. '/lua') do
local modpath = path .. '/lua/' .. name
-- HACK: type is not always returned due to a bug in luv
- t = t or uv.fs_stat(modpath).type
+ t = t or Loader.get_hash(modpath).type
---@type string
local topname
local ext = name:sub(-4)
@@ -438,21 +466,27 @@ function Loader.track(stat, f)
end
end
-Loader.get_rtp = Loader.track('get_rtp', Loader.get_rtp)
-Loader.read = Loader.track('read', Loader.read)
-Loader.loader = Loader.track('loader', Loader.loader)
-Loader.loader_lib = Loader.track('loader_lib', Loader.loader_lib)
-Loader.loadfile = Loader.track('loadfile', Loader.loadfile)
-Loader.load = Loader.track('load', Loader.load)
-M.find = Loader.track('find', M.find)
-Loader.lsmod = Loader.track('lsmod', Loader.lsmod)
+---@class ProfileOpts
+---@field loaders? boolean Add profiling to the loaders
--- Debug function that wrapps all loaders and tracks stats
---@private
-function M._profile_loaders()
- for l, loader in pairs(loaders) do
- local loc = debug.getinfo(loader, 'Sn').source:sub(2)
- loaders[l] = Loader.track('loader ' .. l .. ': ' .. loc, loader)
+---@param opts ProfileOpts?
+function M._profile(opts)
+ Loader.get_rtp = Loader.track('get_rtp', Loader.get_rtp)
+ Loader.read = Loader.track('read', Loader.read)
+ Loader.loader = Loader.track('loader', Loader.loader)
+ Loader.loader_lib = Loader.track('loader_lib', Loader.loader_lib)
+ Loader.loadfile = Loader.track('loadfile', Loader.loadfile)
+ Loader.load = Loader.track('load', Loader.load)
+ M.find = Loader.track('find', M.find)
+ Loader.lsmod = Loader.track('lsmod', Loader.lsmod)
+
+ if opts and opts.loaders then
+ for l, loader in pairs(loaders) do
+ local loc = debug.getinfo(loader, 'Sn').source:sub(2)
+ loaders[l] = Loader.track('loader ' .. l .. ': ' .. loc, loader)
+ end
end
end
diff --git a/runtime/lua/vim/lsp/diagnostic.lua b/runtime/lua/vim/lsp/diagnostic.lua
index dcc8f6549c..3efa5c51ff 100644
--- a/runtime/lua/vim/lsp/diagnostic.lua
+++ b/runtime/lua/vim/lsp/diagnostic.lua
@@ -119,7 +119,7 @@ local function diagnostic_lsp_to_vim(diagnostics, bufnr, client_id)
message = diagnostic.message,
source = diagnostic.source,
code = diagnostic.code,
- tags = tags_lsp_to_vim(diagnostic, client_id),
+ _tags = tags_lsp_to_vim(diagnostic, client_id),
user_data = {
lsp = {
-- usage of user_data.lsp.code is deprecated in favor of the top-level code field
diff --git a/runtime/lua/vim/shared.lua b/runtime/lua/vim/shared.lua
index 884929e33a..9e337e93e8 100644
--- a/runtime/lua/vim/shared.lua
+++ b/runtime/lua/vim/shared.lua
@@ -796,13 +796,15 @@ end
--- a.b.c = 1
--- </pre>
---
----@param create function|nil The function called to create a missing value.
+---@param create function?(key:any):any The function called to create a missing value.
---@return table Empty table with metamethod
function vim.defaulttable(create)
- create = create or vim.defaulttable
+ create = create or function(_)
+ return vim.defaulttable()
+ end
return setmetatable({}, {
__index = function(tbl, key)
- rawset(tbl, key, create())
+ rawset(tbl, key, create(key))
return rawget(tbl, key)
end,
})
diff --git a/runtime/lua/vim/treesitter/health.lua b/runtime/lua/vim/treesitter/health.lua
index fd1188fde4..dabf2cdf6c 100644
--- a/runtime/lua/vim/treesitter/health.lua
+++ b/runtime/lua/vim/treesitter/health.lua
@@ -22,7 +22,7 @@ function M.check()
)
)
else
- local lang = ts.language.inspect_language(parsername)
+ local lang = ts.language.inspect(parsername)
health.report_ok(
string.format('Parser: %-10s ABI: %d, path: %s', parsername, lang._abi_version, parser)
)
diff --git a/runtime/lua/vim/treesitter/language.lua b/runtime/lua/vim/treesitter/language.lua
index b1c788e6ba..5b74bb6200 100644
--- a/runtime/lua/vim/treesitter/language.lua
+++ b/runtime/lua/vim/treesitter/language.lua
@@ -4,7 +4,9 @@ local a = vim.api
local M = {}
---@type table<string,string>
-local ft_to_lang = {}
+local ft_to_lang = {
+ help = 'vimdoc',
+}
--- Get the filetypes associated with the parser named {lang}.
--- @param lang string Name of parser
diff --git a/runtime/queries/c/highlights.scm b/runtime/queries/c/highlights.scm
index 33e6df74ab..dee70f9cc7 100644
--- a/runtime/queries/c/highlights.scm
+++ b/runtime/queries/c/highlights.scm
@@ -1,22 +1,19 @@
-(identifier) @variable
+; Lower priority to prefer @parameter when identifier appears in parameter_declaration.
+((identifier) @variable (#set! "priority" 95))
[
- "const"
"default"
"enum"
- "extern"
- "inline"
- "return"
- "sizeof"
- "static"
"struct"
"typedef"
"union"
- "volatile"
"goto"
- "register"
] @keyword
+"sizeof" @keyword.operator
+
+"return" @keyword.return
+
[
"while"
"for"
@@ -32,7 +29,6 @@
"switch"
] @conditional
-"#define" @constant.macro
[
"#if"
"#ifdef"
@@ -41,10 +37,18 @@
"#elif"
"#endif"
(preproc_directive)
-] @keyword
+] @preproc
+
+"#define" @define
"#include" @include
+[ ";" ":" "," ] @punctuation.delimiter
+
+"..." @punctuation.special
+
+[ "(" ")" "[" "]" "{" "}"] @punctuation.bracket
+
[
"="
@@ -62,6 +66,7 @@
">>"
"->"
+ "."
"<"
"<="
@@ -88,35 +93,25 @@
"++"
] @operator
+;; Make sure the comma operator is given a highlight group after the comma
+;; punctuator so the operator is highlighted properly.
+(comma_expression [ "," ] @operator)
+
[
(true)
(false)
] @boolean
-[ "." ";" ":" "," ] @punctuation.delimiter
-
-(conditional_expression [ "?" ":" ] @conditional)
-
-
-[ "(" ")" "[" "]" "{" "}"] @punctuation.bracket
+(conditional_expression [ "?" ":" ] @conditional.ternary)
(string_literal) @string
-(string_literal) @spell
(system_lib_string) @string
+(escape_sequence) @string.escape
(null) @constant.builtin
(number_literal) @number
-(char_literal) @number
+(char_literal) @character
-(call_expression
- function: (identifier) @function)
-(call_expression
- function: (field_expression
- field: (field_identifier) @function))
-(function_declarator
- declarator: (identifier) @function)
-(preproc_function_def
- name: (identifier) @function.macro)
[
(preproc_arg)
(preproc_defined)
@@ -126,18 +121,32 @@
(statement_identifier) @label
[
-(type_identifier)
-(primitive_type)
-(sized_type_specifier)
-(type_descriptor)
- ] @type
+ (type_identifier)
+ (sized_type_specifier)
+ (type_descriptor)
+] @type
+
+(storage_class_specifier) @storageclass
+
+(type_qualifier) @type.qualifier
+
+(linkage_specification
+ "extern" @storageclass)
-(declaration (type_qualifier) @type)
-(cast_expression type: (type_descriptor) @type)
-(sizeof_expression value: (parenthesized_expression (identifier) @type))
+(type_definition
+ declarator: (type_identifier) @type.definition)
+
+(primitive_type) @type.builtin
((identifier) @constant
- (#match? @constant "^[A-Z][A-Z0-9_]+$"))
+ (#lua-match? @constant "^[A-Z][A-Z0-9_]+$"))
+(enumerator
+ name: (identifier) @constant)
+(case_statement
+ value: (identifier) @constant)
+
+((identifier) @constant.builtin
+ (#any-of? @constant.builtin "stderr" "stdin" "stdout"))
;; Preproc def / undef
(preproc_def
@@ -147,9 +156,20 @@
argument: (_) @constant
(#eq? @_u "#undef"))
+(call_expression
+ function: (identifier) @function.call)
+(call_expression
+ function: (field_expression
+ field: (field_identifier) @function.call))
+(function_declarator
+ declarator: (identifier) @function)
+(preproc_function_def
+ name: (identifier) @function.macro)
+
+(comment) @comment @spell
-(comment) @comment
-(comment) @spell
+((comment) @comment.documentation
+ (#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$"))
;; Parameters
(parameter_declaration
@@ -158,7 +178,20 @@
(parameter_declaration
declarator: (pointer_declarator) @parameter)
-(preproc_params
- (identifier)) @parameter
+(preproc_params (identifier) @parameter)
+
+[
+ "__attribute__"
+ "__cdecl"
+ "__clrcall"
+ "__stdcall"
+ "__fastcall"
+ "__thiscall"
+ "__vectorcall"
+ "_unaligned"
+ "__unaligned"
+ "__declspec"
+ (attribute_declaration)
+] @attribute
(ERROR) @error
diff --git a/runtime/queries/c/injections.scm b/runtime/queries/c/injections.scm
index 84ae33683e..3b99c7a444 100644
--- a/runtime/queries/c/injections.scm
+++ b/runtime/queries/c/injections.scm
@@ -1,5 +1,5 @@
-((preproc_arg) @injection.content
- (#set! injection.language "c"))
+; ((preproc_arg) @injection.content
+; (#set! injection.language "c"))
; ((comment) @injection.content
; (#set! injection.language "comment"))
diff --git a/runtime/queries/lua/highlights.scm b/runtime/queries/lua/highlights.scm
index 2c0dc5447a..5fbf8a1833 100644
--- a/runtime/queries/lua/highlights.scm
+++ b/runtime/queries/lua/highlights.scm
@@ -8,8 +8,6 @@
"local"
] @keyword
-(label_statement) @label
-
(break_statement) @keyword
(do_statement
@@ -109,6 +107,7 @@
[
";"
":"
+ "::"
","
"."
] @punctuation.delimiter
@@ -129,12 +128,21 @@
(identifier) @variable
((identifier) @variable.builtin
- (#eq? @variable.builtin "self"))
+ (#any-of? @variable.builtin "_G" "_VERSION" "debug" "io" "jit" "math" "os" "package" "self" "string" "table" "utf8"))
+
+((identifier) @keyword.coroutine
+ (#eq? @keyword.coroutine "coroutine"))
(variable_list
- attribute: (attribute
- (["<" ">"] @punctuation.bracket
- (identifier) @attribute)))
+ attribute: (attribute
+ (["<" ">"] @punctuation.bracket
+ (identifier) @attribute)))
+
+;; Labels
+
+(label_statement (identifier) @label)
+
+(goto_statement (identifier) @label)
;; Constants
@@ -172,7 +180,7 @@
(function_call name: (dot_index_expression field: (identifier) @function.call))
(function_declaration name: (dot_index_expression field: (identifier) @function))
-(method_index_expression method: (identifier) @method)
+(method_index_expression method: (identifier) @method.call)
(function_call
(identifier) @function.builtin
@@ -180,20 +188,27 @@
;; built-in functions in Lua 5.1
"assert" "collectgarbage" "dofile" "error" "getfenv" "getmetatable" "ipairs"
"load" "loadfile" "loadstring" "module" "next" "pairs" "pcall" "print"
- "rawequal" "rawget" "rawset" "require" "select" "setfenv" "setmetatable"
- "tonumber" "tostring" "type" "unpack" "xpcall"))
+ "rawequal" "rawget" "rawlen" "rawset" "require" "select" "setfenv" "setmetatable"
+ "tonumber" "tostring" "type" "unpack" "xpcall"
+ "__add" "__band" "__bnot" "__bor" "__bxor" "__call" "__concat" "__div" "__eq" "__gc"
+ "__idiv" "__index" "__le" "__len" "__lt" "__metatable" "__mod" "__mul" "__name" "__newindex"
+ "__pairs" "__pow" "__shl" "__shr" "__sub" "__tostring" "__unm"))
;; Others
-(comment) @comment
-(comment) @spell
+(comment) @comment @spell
+
+((comment) @comment.documentation
+ (#lua-match? @comment.documentation "^[-][-][-]"))
+
+((comment) @comment.documentation
+ (#lua-match? @comment.documentation "^[-][-](%s?)@"))
-(hash_bang_line) @comment
+(hash_bang_line) @preproc
(number) @number
-(string) @string
-(string) @spell
+(string) @string @spell
;; Error
(ERROR) @error
diff --git a/runtime/queries/lua/injections.scm b/runtime/queries/lua/injections.scm
index 10eb4c4054..1c7bdaf951 100644
--- a/runtime/queries/lua/injections.scm
+++ b/runtime/queries/lua/injections.scm
@@ -11,18 +11,18 @@
name: (_) @_vimcmd_identifier
arguments: (arguments (string content: _ @injection.content)))
(#set! injection.language "vim")
- (#any-of? @_vimcmd_identifier "vim.cmd" "vim.api.nvim_command" "vim.api.nvim_exec" "vim.api.nvim_cmd"))
+ (#any-of? @_vimcmd_identifier "vim.cmd" "vim.api.nvim_command" "vim.api.nvim_exec2" "vim.api.nvim_cmd"))
((function_call
name: (_) @_vimcmd_identifier
arguments: (arguments (string content: _ @injection.content) .))
(#set! injection.language "query")
- (#eq? @_vimcmd_identifier "vim.treesitter.query.set_query"))
+ (#any-of? @_vimcmd_identifier "vim.treesitter.query.set" "vim.treesitter.query.parse"))
-; ;; highlight string as query if starts with `;; query`
-; ((string ("string_content") @injection.content)
-; (#set! injection.language "query")
-; (#lua-match? @injection.content "^%s*;+%s?query"))
+;; highlight string as query if starts with `;; query`
+((string ("string_content") @injection.content)
+ (#set! injection.language "query")
+ (#lua-match? @injection.content "^%s*;+%s?query"))
; ((comment) @injection.content
; (#set! injection.language "comment"))
diff --git a/runtime/queries/vim/highlights.scm b/runtime/queries/vim/highlights.scm
index 239b0a0b37..ce25b13b9f 100644
--- a/runtime/queries/vim/highlights.scm
+++ b/runtime/queries/vim/highlights.scm
@@ -271,7 +271,7 @@
":"
] @punctuation.delimiter
-(ternary_expression ["?" ":"] @conditional)
+(ternary_expression ["?" ":"] @conditional.ternary)
; Options
((set_value) @number
diff --git a/runtime/queries/help/highlights.scm b/runtime/queries/vimdoc/highlights.scm
index c0d88301bc..c0d88301bc 100644
--- a/runtime/queries/help/highlights.scm
+++ b/runtime/queries/vimdoc/highlights.scm
diff --git a/runtime/queries/help/injections.scm b/runtime/queries/vimdoc/injections.scm
index 260a05d863..260a05d863 100644
--- a/runtime/queries/help/injections.scm
+++ b/runtime/queries/vimdoc/injections.scm
diff --git a/scripts/gen_help_html.lua b/scripts/gen_help_html.lua
index 2563f2f410..367ce60765 100644
--- a/scripts/gen_help_html.lua
+++ b/scripts/gen_help_html.lua
@@ -624,7 +624,7 @@ local function get_helptags(help_dir)
return m
end
--- Use the help.so parser defined in the build, not whatever happens to be installed on the system.
+-- Use the vimdoc parser defined in the build, not whatever happens to be installed on the system.
local function ensure_runtimepath()
if not vim.o.runtimepath:find('build/lib/nvim/') then
vim.cmd[[set runtimepath^=./build/lib/nvim/]]
@@ -643,8 +643,8 @@ local function parse_buf(fname)
buf = fname
vim.cmd('sbuffer '..tostring(fname)) -- Buffer number.
end
- -- vim.treesitter.require_language('help', './build/lib/nvim/parser/help.so')
- local lang_tree = vim.treesitter.get_parser(buf, 'help')
+ -- vim.treesitter.require_language('help', './build/lib/nvim/parser/vimdoc.so')
+ local lang_tree = vim.treesitter.get_parser(buf)
return lang_tree, buf
end
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index ca5dd97020..9812313b7b 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -95,6 +95,9 @@ Integer nvim_get_hl_id_by_name(String name)
/// @param[out] err Error details, if any.
/// @return Highlight groups as a map from group name to a highlight definition map as in |nvim_set_hl()|,
/// or only a single highlight definition map if requested by name or id.
+///
+/// @note When the `link` attribute is defined in the highlight definition
+/// map, other attributes will not be taking effect (see |:hi-link|).
Dictionary nvim_get_hl(Integer ns_id, Dict(get_highlight) *opts, Arena *arena, Error *err)
FUNC_API_SINCE(11)
{
@@ -113,6 +116,10 @@ Dictionary nvim_get_hl(Integer ns_id, Dict(get_highlight) *opts, Arena *arena, E
/// values of the Normal group. If the Normal group has not been defined,
/// using these values results in an error.
///
+///
+/// @note If `link` is used in combination with other attributes; only the
+/// `link` will take effect (see |:hi-link|).
+///
/// @param ns_id Namespace id for this highlight |nvim_create_namespace()|.
/// Use 0 to set a highlight group globally |:highlight|.
/// Highlights from non-global namespaces are not active by default, use
diff --git a/src/nvim/channel.c b/src/nvim/channel.c
index f68ee2b39e..a0fe3cc734 100644
--- a/src/nvim/channel.c
+++ b/src/nvim/channel.c
@@ -218,7 +218,7 @@ void channel_create_event(Channel *chan, const char *ext_source)
source = ext_source;
} else {
eval_fmt_source_name_line(IObuff, sizeof(IObuff));
- source = (const char *)IObuff;
+ source = IObuff;
}
assert(chan->id <= VARNUMBER_MAX);
diff --git a/src/nvim/charset.c b/src/nvim/charset.c
index a3aa6783ee..63459495f8 100644
--- a/src/nvim/charset.c
+++ b/src/nvim/charset.c
@@ -755,7 +755,7 @@ int ptr2cells(const char *p_in)
/// @param s
///
/// @return number of character cells.
-int vim_strsize(char *s)
+int vim_strsize(const char *s)
{
return vim_strnsize(s, MAXCOL);
}
@@ -769,7 +769,7 @@ int vim_strsize(char *s)
/// @param len
///
/// @return Number of character cells.
-int vim_strnsize(char *s, int len)
+int vim_strnsize(const char *s, int len)
{
assert(s != NULL);
int size = 0;
diff --git a/src/nvim/drawscreen.c b/src/nvim/drawscreen.c
index 1c8bf56e8e..13e9d1ea49 100644
--- a/src/nvim/drawscreen.c
+++ b/src/nvim/drawscreen.c
@@ -939,9 +939,9 @@ int showmode(void)
}
if (length - vim_strsize(edit_submode) > 0) {
if (edit_submode_pre != NULL) {
- msg_puts_attr((const char *)edit_submode_pre, attr);
+ msg_puts_attr(edit_submode_pre, attr);
}
- msg_puts_attr((const char *)edit_submode, attr);
+ msg_puts_attr(edit_submode, attr);
}
if (edit_submode_extra != NULL) {
msg_puts_attr(" ", attr); // Add a space in between.
@@ -950,7 +950,7 @@ int showmode(void)
} else {
sub_attr = attr;
}
- msg_puts_attr((const char *)edit_submode_extra, sub_attr);
+ msg_puts_attr(edit_submode_extra, sub_attr);
}
}
} else {
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index fc9ddb75ef..edaa2bb809 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -596,7 +596,7 @@ int var_redir_start(char *name, int append)
/// :redir => foo
/// :let foo
/// :redir END
-void var_redir_str(char *value, int value_len)
+void var_redir_str(const char *value, int value_len)
{
if (redir_lval == NULL) {
return;
@@ -2147,10 +2147,10 @@ int pattern_match(const char *pat, const char *text, bool ic)
// avoid 'l' flag in 'cpoptions'
char *save_cpo = p_cpo;
p_cpo = empty_option;
- regmatch.regprog = vim_regcomp((char *)pat, RE_MAGIC + RE_STRING);
+ regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING);
if (regmatch.regprog != NULL) {
regmatch.rm_ic = ic;
- matches = vim_regexec_nl(&regmatch, (char *)text, (colnr_T)0);
+ matches = vim_regexec_nl(&regmatch, text, (colnr_T)0);
vim_regfree(regmatch.regprog);
}
p_cpo = save_cpo;
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
index df8004dc73..25d383d8ea 100644
--- a/src/nvim/eval/funcs.c
+++ b/src/nvim/eval/funcs.c
@@ -4670,7 +4670,7 @@ static void find_some_match(typval_T *const argvars, typval_T *const rettv,
}
}
- regmatch.regprog = vim_regcomp((char *)pat, RE_MAGIC + RE_STRING);
+ regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING);
if (regmatch.regprog != NULL) {
regmatch.rm_ic = p_ic;
@@ -7895,7 +7895,7 @@ static void f_split(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
}
regmatch_T regmatch = {
- .regprog = vim_regcomp((char *)pat, RE_MAGIC + RE_STRING),
+ .regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING),
.startp = { NULL },
.endp = { NULL },
.rm_ic = false,
@@ -7906,7 +7906,7 @@ static void f_split(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
if (*str == NUL) {
match = false; // Empty item at the end.
} else {
- match = vim_regexec_nl(&regmatch, (char *)str, col);
+ match = vim_regexec_nl(&regmatch, str, col);
}
const char *end;
if (match) {
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index ac3c8c4f8e..621cb764f4 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -4742,7 +4742,7 @@ void ex_oldfiles(exarg_T *eap)
}
nr++;
const char *fname = tv_get_string(TV_LIST_ITEM_TV(li));
- if (!message_filtered((char *)fname)) {
+ if (!message_filtered(fname)) {
msg_outnum(nr);
msg_puts(": ");
msg_outtrans((char *)tv_get_string(TV_LIST_ITEM_TV(li)));
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c
index c777efb445..a86676733f 100644
--- a/src/nvim/ex_cmds2.c
+++ b/src/nvim/ex_cmds2.c
@@ -201,7 +201,7 @@ void dialog_changed(buf_T *buf, bool checkall)
.forceit = false,
};
- dialog_msg((char *)buff, _("Save changes to \"%s\"?"), buf->b_fname);
+ dialog_msg(buff, _("Save changes to \"%s\"?"), buf->b_fname);
if (checkall) {
ret = vim_dialog_yesnoallcancel(VIM_QUESTION, NULL, buff, 1);
} else {
diff --git a/src/nvim/ex_session.c b/src/nvim/ex_session.c
index 855a5f7538..d47d40cbee 100644
--- a/src/nvim/ex_session.c
+++ b/src/nvim/ex_session.c
@@ -959,7 +959,7 @@ void ex_mkrc(exarg_T *eap)
// When using 'viewdir' may have to create the directory.
if (using_vdir && !os_isdir(p_vdir)) {
- vim_mkdir_emsg((const char *)p_vdir, 0755);
+ vim_mkdir_emsg(p_vdir, 0755);
}
fd = open_exfile(fname, eap->forceit, WRITEBIN);
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index 816471d7c1..571df45e89 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -169,7 +169,7 @@ EXTERN char *edit_submode_extra INIT(= NULL); // appended to edit_submode
EXTERN hlf_T edit_submode_highl; // highl. method for extra info
// state for putting characters in the message area
-EXTERN int cmdmsg_rl INIT(= false); // cmdline is drawn right to left
+EXTERN bool cmdmsg_rl INIT(= false); // cmdline is drawn right to left
EXTERN int msg_col;
EXTERN int msg_row;
EXTERN int msg_scrolled; // Number of screen lines that windows have
@@ -224,7 +224,7 @@ EXTERN bool did_wait_return INIT(= false); // wait_return() was used and
// nothing written since then
EXTERN bool need_maketitle INIT(= true); // call maketitle() soon
-EXTERN int quit_more INIT(= false); // 'q' hit at "--more--" msg
+EXTERN bool quit_more INIT(= false); // 'q' hit at "--more--" msg
EXTERN int vgetc_busy INIT(= 0); // when inside vgetc() then > 0
EXTERN bool didset_vim INIT(= false); // did set $VIM ourselves
@@ -233,7 +233,7 @@ EXTERN bool didset_vimruntime INIT(= false); // idem for $VIMRUNTIME
/// Lines left before a "more" message. Ex mode needs to be able to reset this
/// after you type something.
EXTERN int lines_left INIT(= -1); // lines left for listing
-EXTERN int msg_no_more INIT(= false); // don't use more prompt, truncate
+EXTERN bool msg_no_more INIT(= false); // don't use more prompt, truncate
// messages
EXTERN int ex_nesting_level INIT(= 0); // nesting level
@@ -275,7 +275,7 @@ EXTERN int trylevel INIT(= 0);
/// non-zero (and ":silent!" was not used) or an exception is being thrown at
/// the time an error is detected. It is set to false when "trylevel" gets
/// zero again and there was no error or interrupt or throw.
-EXTERN int force_abort INIT(= false);
+EXTERN bool force_abort INIT(= false);
/// "msg_list" points to a variable in the stack of do_cmdline() which keeps
/// the list of arguments of several emsg() calls, one of which is to be
@@ -308,8 +308,8 @@ EXTERN except_T *caught_stack INIT(= NULL);
/// "garbage_collect_at_exit" indicates garbagecollect(1) was called.
///
EXTERN bool may_garbage_collect INIT(= false);
-EXTERN int want_garbage_collect INIT(= false);
-EXTERN int garbage_collect_at_exit INIT(= false);
+EXTERN bool want_garbage_collect INIT(= false);
+EXTERN bool garbage_collect_at_exit INIT(= false);
// Special values for current_SID.
#define SID_MODELINE (-1) // when using a modeline
@@ -360,19 +360,19 @@ EXTERN linenr_T search_last_line INIT(= MAXLNUM); // for :{first},{LAST}s/pat
EXTERN bool no_smartcase INIT(= false); // don't use 'smartcase' once
-EXTERN int need_check_timestamps INIT(= false); // need to check file
- // timestamps asap
-EXTERN int did_check_timestamps INIT(= false); // did check timestamps
- // recently
-EXTERN int no_check_timestamps INIT(= 0); // Don't check timestamps
+EXTERN bool need_check_timestamps INIT(= false); // need to check file
+ // timestamps asap
+EXTERN bool did_check_timestamps INIT(= false); // did check timestamps
+ // recently
+EXTERN int no_check_timestamps INIT(= 0); // Don't check timestamps
-EXTERN int autocmd_busy INIT(= false); // Is apply_autocmds() busy?
+EXTERN bool autocmd_busy INIT(= false); // Is apply_autocmds() busy?
EXTERN int autocmd_no_enter INIT(= false); // *Enter autocmds disabled
EXTERN int autocmd_no_leave INIT(= false); // *Leave autocmds disabled
EXTERN int modified_was_set; // did ":set modified"
-EXTERN int did_filetype INIT(= false); // FileType event found
+EXTERN bool did_filetype INIT(= false); // FileType event found
// value for did_filetype when starting to execute autocommands
-EXTERN int keep_filetype INIT(= false);
+EXTERN bool keep_filetype INIT(= false);
// When deleting the current buffer, another one must be loaded.
// If we know which one is preferred, au_new_curbuf is set to it.
@@ -398,7 +398,7 @@ EXTERN int mouse_dragging INIT(= 0); // extending Visual area with
EXTERN vimmenu_T *root_menu INIT(= NULL);
// While defining the system menu, sys_menu is true. This avoids
// overruling of menus that the user already defined.
-EXTERN int sys_menu INIT(= false);
+EXTERN bool sys_menu INIT(= false);
// All windows are linked in a list. firstwin points to the first entry,
// lastwin to the last entry (can be the same as firstwin) and curwin to the
@@ -501,7 +501,7 @@ EXTERN bool stderr_isatty INIT(= true);
EXTERN int stdin_fd INIT(= -1);
// true when doing full-screen output, otherwise only writing some messages.
-EXTERN int full_screen INIT(= false);
+EXTERN bool full_screen INIT(= false);
/// Non-zero when only "safe" commands are allowed
EXTERN int secure INIT(= 0);
@@ -519,14 +519,14 @@ EXTERN int allbuf_lock INIT(= 0);
EXTERN int sandbox INIT(= 0);
/// Batch-mode: "-es", "-Es", "-l" commandline argument was given.
-EXTERN int silent_mode INIT(= false);
+EXTERN bool silent_mode INIT(= false);
/// Start position of active Visual selection.
EXTERN pos_T VIsual;
/// Whether Visual mode is active.
-EXTERN int VIsual_active INIT(= false);
+EXTERN bool VIsual_active INIT(= false);
/// Whether Select mode is active.
-EXTERN int VIsual_select INIT(= false);
+EXTERN bool VIsual_select INIT(= false);
/// Register name for Select mode
EXTERN int VIsual_select_reg INIT(= 0);
/// Restart Select mode when next cmd finished
@@ -536,7 +536,7 @@ EXTERN int VIsual_reselect;
/// Type of Visual mode.
EXTERN int VIsual_mode INIT(= 'v');
/// true when redoing Visual.
-EXTERN int redo_VIsual_busy INIT(= false);
+EXTERN bool redo_VIsual_busy INIT(= false);
// The Visual area is remembered for reselection.
EXTERN int resel_VIsual_mode INIT(= NUL); // 'v', 'V', or Ctrl-V
@@ -704,8 +704,8 @@ EXTERN char os_buf[ ///< Buffer for the os/ layer
// When non-zero, postpone redrawing.
EXTERN int RedrawingDisabled INIT(= 0);
-EXTERN int readonlymode INIT(= false); // Set to true for "view"
-EXTERN int recoverymode INIT(= false); // Set to true for "-r" option
+EXTERN bool readonlymode INIT(= false); // Set to true for "view"
+EXTERN bool recoverymode INIT(= false); // Set to true for "-r" option
// typeahead buffer
EXTERN typebuf_T typebuf INIT(= { NULL, NULL, 0, 0, 0, 0, 0, 0, 0 });
@@ -714,13 +714,13 @@ EXTERN typebuf_T typebuf INIT(= { NULL, NULL, 0, 0, 0, 0, 0, 0, 0 });
/// :normal argument was exhausted.
EXTERN bool typebuf_was_empty INIT(= false);
-EXTERN int ex_normal_busy INIT(= 0); // recursiveness of ex_normal()
-EXTERN int expr_map_lock INIT(= 0); // running expr mapping, prevent use of ex_normal() and text changes
-EXTERN int ignore_script INIT(= false); // ignore script input
-EXTERN int stop_insert_mode; // for ":stopinsert"
-EXTERN bool KeyTyped; // true if user typed current char
-EXTERN int KeyStuffed; // true if current char from stuffbuf
-EXTERN int maptick INIT(= 0); // tick for each non-mapped char
+EXTERN int ex_normal_busy INIT(= 0); // recursiveness of ex_normal()
+EXTERN int expr_map_lock INIT(= 0); // running expr mapping, prevent use of ex_normal() and text changes
+EXTERN bool ignore_script INIT(= false); // ignore script input
+EXTERN int stop_insert_mode; // for ":stopinsert"
+EXTERN bool KeyTyped; // true if user typed current char
+EXTERN int KeyStuffed; // true if current char from stuffbuf
+EXTERN int maptick INIT(= 0); // tick for each non-mapped char
EXTERN int must_redraw INIT(= 0); // type of redraw necessary
EXTERN bool skip_redraw INIT(= false); // skip redraw once
@@ -776,7 +776,7 @@ EXTERN int replace_offset INIT(= 0); // offset for replace_push()
EXTERN char *escape_chars INIT(= " \t\\\"|"); // need backslash in cmd line
-EXTERN int keep_help_flag INIT(= false); // doing :ta from help file
+EXTERN bool keep_help_flag INIT(= false); // doing :ta from help file
// When a string option is NULL (which only happens in out-of-memory
// situations), it is set to empty_option, to avoid having to check for NULL
diff --git a/src/nvim/grid.c b/src/nvim/grid.c
index cd70e98047..3c4b1e9d70 100644
--- a/src/nvim/grid.c
+++ b/src/nvim/grid.c
@@ -197,10 +197,10 @@ void grid_put_schar(ScreenGrid *grid, int row, int col, char *schar, int attr)
/// like grid_puts(), but output "text[len]". When "len" is -1 output up to
/// a NUL.
-int grid_puts_len(ScreenGrid *grid, char *text, int textlen, int row, int col, int attr)
+int grid_puts_len(ScreenGrid *grid, const char *text, int textlen, int row, int col, int attr)
{
size_t off;
- char *ptr = text;
+ const char *ptr = text;
int len = textlen;
int c;
size_t max_off;
diff --git a/src/nvim/highlight_group.c b/src/nvim/highlight_group.c
index 057447c9f4..cce124de77 100644
--- a/src/nvim/highlight_group.c
+++ b/src/nvim/highlight_group.c
@@ -797,9 +797,9 @@ void set_hl_group(int id, HlAttrs attrs, Dict(highlight) *dict, int link_id)
}
HlGroup *g = &hl_table[idx];
+ g->sg_cleared = false;
if (link_id > 0) {
- g->sg_cleared = false;
g->sg_link = link_id;
g->sg_script_ctx = current_sctx;
g->sg_script_ctx.sc_lnum += SOURCING_LNUM;
@@ -809,11 +809,10 @@ void set_hl_group(int id, HlAttrs attrs, Dict(highlight) *dict, int link_id)
g->sg_deflink_sctx = current_sctx;
g->sg_deflink_sctx.sc_lnum += SOURCING_LNUM;
}
- goto update;
+ } else {
+ g->sg_link = 0;
}
- g->sg_cleared = false;
- g->sg_link = 0;
g->sg_gui = attrs.rgb_ae_attr;
g->sg_rgb_fg = attrs.rgb_fg_color;
@@ -865,7 +864,6 @@ void set_hl_group(int id, HlAttrs attrs, Dict(highlight) *dict, int link_id)
}
}
-update:
if (!updating_screen) {
redraw_all_later(UPD_NOT_VALID);
}
@@ -1533,17 +1531,15 @@ static bool hlgroup2dict(Dictionary *hl, NS ns_id, int hl_id, Arena *arena)
}
HlAttrs attr =
syn_attr2entry(ns_id == 0 ? sgp->sg_attr : ns_get_hl(&ns_id, hl_id, false, sgp->sg_set));
+ *hl = arena_dict(arena, HLATTRS_DICT_SIZE + 1);
if (link > 0) {
- *hl = arena_dict(arena, 1);
PUT_C(*hl, "link", STRING_OBJ(cstr_as_string(hl_table[link - 1].sg_name)));
- } else {
- *hl = arena_dict(arena, HLATTRS_DICT_SIZE);
- Dictionary hl_cterm = arena_dict(arena, HLATTRS_DICT_SIZE);
- hlattrs2dict(hl, NULL, attr, true, true);
- hlattrs2dict(hl, &hl_cterm, attr, false, true);
- if (kv_size(hl_cterm)) {
- PUT_C(*hl, "cterm", DICTIONARY_OBJ(hl_cterm));
- }
+ }
+ Dictionary hl_cterm = arena_dict(arena, HLATTRS_DICT_SIZE);
+ hlattrs2dict(hl, NULL, attr, true, true);
+ hlattrs2dict(hl, &hl_cterm, attr, false, true);
+ if (kv_size(hl_cterm)) {
+ PUT_C(*hl, "cterm", DICTIONARY_OBJ(hl_cterm));
}
return true;
}
@@ -1635,7 +1631,7 @@ static bool highlight_list_arg(const int id, bool didh, const int type, int iarg
}
}
- (void)syn_list_header(didh, vim_strsize((char *)ts) + (int)strlen(name) + 1, id, false);
+ (void)syn_list_header(didh, vim_strsize(ts) + (int)strlen(name) + 1, id, false);
didh = true;
if (!got_int) {
if (*name != NUL) {
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c
index dfbbfe9ab5..b5dd7a3e78 100644
--- a/src/nvim/lua/executor.c
+++ b/src/nvim/lua/executor.c
@@ -623,7 +623,7 @@ static bool nlua_init_packages(lua_State *lstate, bool is_standalone)
lua_getglobal(lstate, "require");
lua_pushstring(lstate, "vim._init_packages");
if (nlua_pcall(lstate, 1, 0)) {
- os_errmsg((char *)lua_tostring(lstate, -1));
+ os_errmsg(lua_tostring(lstate, -1));
os_errmsg("\n");
return false;
}
diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c
index ee5676e927..20a99b2836 100644
--- a/src/nvim/lua/stdlib.c
+++ b/src/nvim/lua/stdlib.c
@@ -288,7 +288,7 @@ int nlua_regex(lua_State *lstate)
regprog_T *prog = NULL;
TRY_WRAP(&err, {
- prog = vim_regcomp((char *)text, RE_AUTO | RE_MAGIC | RE_STRICT);
+ prog = vim_regcomp(text, RE_AUTO | RE_MAGIC | RE_STRICT);
});
if (ERROR_SET(&err)) {
diff --git a/src/nvim/main.c b/src/nvim/main.c
index a16badc1a0..1f16ecff76 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -2153,7 +2153,7 @@ static void print_mainerr(const char *errstr, const char *str)
os_errmsg(_(errstr));
if (str != NULL) {
os_errmsg(": \"");
- os_errmsg((char *)str);
+ os_errmsg(str);
os_errmsg("\"");
}
os_errmsg(_("\nMore info with \""));
diff --git a/src/nvim/match.c b/src/nvim/match.c
index 93c8a58051..29d4b7c225 100644
--- a/src/nvim/match.c
+++ b/src/nvim/match.c
@@ -98,7 +98,7 @@ static int match_add(win_T *wp, const char *const grp, const char *const pat, in
if ((hlg_id = syn_check_group(grp, strlen(grp))) == 0) {
return -1;
}
- if (pat != NULL && (regprog = vim_regcomp((char *)pat, RE_MAGIC)) == NULL) {
+ if (pat != NULL && (regprog = vim_regcomp(pat, RE_MAGIC)) == NULL) {
semsg(_(e_invarg2), pat);
return -1;
}
@@ -1232,7 +1232,7 @@ void ex_match(exarg_T *eap)
if (!eap->skip) {
if (*end != NUL && !ends_excmd(*skipwhite(end + 1))) {
xfree(g);
- eap->errmsg = ex_errmsg(e_trailing_arg, (const char *)end);
+ eap->errmsg = ex_errmsg(e_trailing_arg, end);
return;
}
if (*end != *p) {
@@ -1243,8 +1243,7 @@ void ex_match(exarg_T *eap)
c = (uint8_t)(*end);
*end = NUL;
- match_add(curwin, (const char *)g, (const char *)p + 1, 10, id,
- NULL, NULL);
+ match_add(curwin, g, p + 1, 10, id, NULL, NULL);
xfree(g);
*end = (char)c;
}
diff --git a/src/nvim/message.c b/src/nvim/message.c
index aecb46c6bd..98ef6e5cba 100644
--- a/src/nvim/message.c
+++ b/src/nvim/message.c
@@ -216,13 +216,13 @@ void msg_grid_validate(void)
/// When terminal not initialized (yet) os_errmsg(..) is used.
///
/// @return true if wait_return() not called
-int msg(char *s)
+int msg(const char *s)
{
return msg_attr_keep(s, 0, false, false);
}
/// Like msg() but keep it silent when 'verbosefile' is set.
-int verb_msg(char *s)
+int verb_msg(const char *s)
{
verbose_enter();
int n = msg_attr_keep(s, 0, false, false);
@@ -278,8 +278,7 @@ void msg_multiattr(HlMessage hl_msg, const char *kind, bool history)
msg_ext_set_kind(kind);
for (uint32_t i = 0; i < kv_size(hl_msg); i++) {
HlMessageChunk chunk = kv_A(hl_msg, i);
- msg_multiline_attr((const char *)chunk.text.data, chunk.attr,
- true, &need_clear);
+ msg_multiline_attr(chunk.text.data, chunk.attr, true, &need_clear);
}
if (history && kv_size(hl_msg)) {
add_msg_hist_multiattr(NULL, 0, 0, true, hl_msg);
@@ -305,7 +304,7 @@ bool msg_attr_keep(const char *s, int attr, bool keep, bool multiline)
// Skip messages not match ":filter pattern".
// Don't filter when there is an error.
- if (!emsg_on_display && message_filtered((char *)s)) {
+ if (!emsg_on_display && message_filtered(s)) {
return true;
}
@@ -333,7 +332,7 @@ bool msg_attr_keep(const char *s, int attr, bool keep, bool multiline)
// Truncate the message if needed.
msg_start();
- buf = msg_strtrunc((char *)s, false);
+ buf = msg_strtrunc(s, false);
if (buf != NULL) {
s = buf;
}
@@ -349,8 +348,8 @@ bool msg_attr_keep(const char *s, int attr, bool keep, bool multiline)
}
retval = msg_end();
- if (keep && retval && vim_strsize((char *)s) < (Rows - cmdline_row - 1) * Columns + sc_col) {
- set_keep_msg((char *)s, 0);
+ if (keep && retval && vim_strsize(s) < (Rows - cmdline_row - 1) * Columns + sc_col) {
+ set_keep_msg(s, 0);
}
need_fileinfo = false;
@@ -365,7 +364,7 @@ bool msg_attr_keep(const char *s, int attr, bool keep, bool multiline)
/// @return an allocated string or NULL when no truncating is done.
///
/// @param force always truncate
-char *msg_strtrunc(char *s, int force)
+char *msg_strtrunc(const char *s, int force)
{
char *buf = NULL;
@@ -395,7 +394,7 @@ char *msg_strtrunc(char *s, int force)
/// Truncate a string "s" to "buf" with cell width "room".
/// "s" and "buf" may be equal.
-void trunc_string(char *s, char *buf, int room_in, int buflen)
+void trunc_string(const char *s, char *buf, int room_in, int buflen)
{
int room = room_in - 3; // "..." takes 3 chars
int half;
@@ -503,7 +502,7 @@ int smsg_attr(int attr, const char *s, ...)
va_start(arglist, s);
vim_vsnprintf(IObuff, IOSIZE, s, arglist);
va_end(arglist);
- return msg_attr((const char *)IObuff, attr);
+ return msg_attr(IObuff, attr);
}
int smsg_attr_keep(int attr, const char *s, ...)
@@ -514,7 +513,7 @@ int smsg_attr_keep(int attr, const char *s, ...)
va_start(arglist, s);
vim_vsnprintf(IObuff, IOSIZE, s, arglist);
va_end(arglist);
- return msg_attr_keep((const char *)IObuff, attr, true, false);
+ return msg_attr_keep(IObuff, attr, true, false);
}
// Remember the last sourcing name/lnum used in an error message, so that it
@@ -862,7 +861,7 @@ void siemsg(const char *s, ...)
}
/// Give an "Internal error" message.
-void internal_error(char *where)
+void internal_error(const char *where)
{
siemsg(_(e_intern2), where);
}
@@ -1327,7 +1326,7 @@ static void hit_return_msg(void)
}
/// Set "keep_msg" to "s". Free the old value and check for NULL pointer.
-void set_keep_msg(char *s, int attr)
+void set_keep_msg(const char *s, int attr)
{
xfree(keep_msg);
if (s != NULL && msg_silent == 0) {
@@ -1562,7 +1561,7 @@ int msg_outtrans_len_attr(const char *msgstr, int len, int attr)
// If the string starts with a composing character first draw a space on
// which the composing char can be drawn.
- if (utf_iscomposing(utf_ptr2char((char *)msgstr))) {
+ if (utf_iscomposing(utf_ptr2char(msgstr))) {
msg_puts_attr(" ", attr);
}
@@ -1598,7 +1597,7 @@ int msg_outtrans_len_attr(const char *msgstr, int len, int attr)
msg_puts_attr_len(plain_start, str - plain_start, attr);
}
plain_start = str + 1;
- msg_puts_attr((const char *)s, attr == 0 ? HL_ATTR(HLF_8) : attr);
+ msg_puts_attr(s, attr == 0 ? HL_ATTR(HLF_8) : attr);
retval += (int)strlen(s);
} else {
retval++;
@@ -1674,7 +1673,7 @@ int msg_outtrans_special(const char *strstart, bool from, int maxlen)
// single-byte character or illegal byte
text = (char *)transchar_byte_buf(NULL, (uint8_t)text[0]);
}
- const int len = vim_strsize((char *)text);
+ const int len = vim_strsize(text);
if (maxlen > 0 && retval + len >= maxlen) {
break;
}
@@ -1966,7 +1965,7 @@ void msg_prt_line(char *s, int list)
/// Use grid_puts() to output one multi-byte character.
///
/// @return the pointer "s" advanced to the next character.
-static char *screen_puts_mbyte(char *s, int l, int attr)
+static const char *screen_puts_mbyte(const char *s, int l, int attr)
{
int cw;
attr = hl_combine_attr(HL_ATTR(HLF_MSG), attr);
@@ -2212,7 +2211,7 @@ static void msg_puts_display(const char *str, int maxlen, int attr, int recurse)
} else {
l = utfc_ptr2len(s);
}
- s = screen_puts_mbyte((char *)s, l, attr);
+ s = screen_puts_mbyte(s, l, attr);
did_last_char = true;
} else {
did_last_char = false;
@@ -2229,7 +2228,7 @@ static void msg_puts_display(const char *str, int maxlen, int attr, int recurse)
if (p_more) {
// Store text for scrolling back.
- store_sb_text((char **)&sb_str, (char *)s, attr, &sb_col, true);
+ store_sb_text(&sb_str, s, attr, &sb_col, true);
}
inc_msg_scrolled();
@@ -2274,7 +2273,7 @@ static void msg_puts_display(const char *str, int maxlen, int attr, int recurse)
if (wrap && p_more && !recurse) {
// Store text for scrolling back.
- store_sb_text((char **)&sb_str, (char *)s, attr, &sb_col, true);
+ store_sb_text(&sb_str, s, attr, &sb_col, true);
}
if (*s == '\n') { // go to next line
@@ -2312,7 +2311,7 @@ static void msg_puts_display(const char *str, int maxlen, int attr, int recurse)
// characters and draw them all at once later.
if (cmdmsg_rl || (cw > 1 && msg_col + t_col >= Columns - 1)) {
if (l > 1) {
- s = screen_puts_mbyte((char *)s, l, attr) - 1;
+ s = screen_puts_mbyte(s, l, attr) - 1;
} else {
msg_screen_putchar(*s, attr);
}
@@ -2333,7 +2332,7 @@ static void msg_puts_display(const char *str, int maxlen, int attr, int recurse)
t_puts(&t_col, t_s, s, attr);
}
if (p_more && !recurse && !(s == sb_str + 1 && *sb_str == '\n')) {
- store_sb_text((char **)&sb_str, (char *)s, attr, &sb_col, false);
+ store_sb_text(&sb_str, s, attr, &sb_col, false);
}
msg_check();
@@ -2341,7 +2340,7 @@ static void msg_puts_display(const char *str, int maxlen, int attr, int recurse)
/// @return true when ":filter pattern" was used and "msg" does not match
/// "pattern".
-bool message_filtered(char *msg)
+bool message_filtered(const char *msg)
{
if (cmdmod.cmod_filter_regmatch.regprog == NULL) {
return false;
@@ -2507,7 +2506,7 @@ static sb_clear_T do_clear_sb_text = SB_CLEAR_NONE;
/// @param sb_str start of string
/// @param s just after string
/// @param finish line ends
-static void store_sb_text(char **sb_str, char *s, int attr, int *sb_col, int finish)
+static void store_sb_text(const char **sb_str, const char *s, int attr, int *sb_col, int finish)
{
msgchunk_T *mp;
@@ -2681,7 +2680,7 @@ static void t_puts(int *t_col, const char *t_s, const char *s, int attr)
attr = hl_combine_attr(HL_ATTR(HLF_MSG), attr);
// Output postponed text.
msg_didout = true; // Remember that line is not empty.
- grid_puts_len(&msg_grid_adj, (char *)t_s, (int)(s - t_s), msg_row, msg_col, attr);
+ grid_puts_len(&msg_grid_adj, t_s, (int)(s - t_s), msg_row, msg_col, attr);
msg_col += *t_col;
*t_col = 0;
// If the string starts with a composing character don't increment the
@@ -3308,7 +3307,7 @@ static void redir_write(const char *const str, const ptrdiff_t maxlen)
write_reg_contents(redir_reg, s, (ssize_t)len, true);
}
if (redir_vname) {
- var_redir_str((char *)s, (int)maxlen);
+ var_redir_str(s, (int)maxlen);
}
// Write and adjust the current column.
@@ -3417,7 +3416,7 @@ int verbose_open(void)
/// Give a warning message (for searching).
/// Use 'w' highlighting and may repeat the message after redrawing
-void give_warning(char *message, bool hl)
+void give_warning(const char *message, bool hl)
FUNC_ATTR_NONNULL_ARG(1)
{
// Don't do this for ":silent".
@@ -3440,7 +3439,7 @@ void give_warning(char *message, bool hl)
msg_ext_set_kind("wmsg");
}
- if (msg_attr((const char *)message, keep_msg_attr) && msg_scrolled == 0) {
+ if (msg_attr(message, keep_msg_attr) && msg_scrolled == 0) {
set_keep_msg(message, keep_msg_attr);
}
msg_didout = false; // Overwrite this message.
@@ -3450,7 +3449,7 @@ void give_warning(char *message, bool hl)
no_wait_return--;
}
-void give_warning2(char *const message, char *const a1, bool hl)
+void give_warning2(const char *const message, const char *const a1, bool hl)
{
vim_snprintf(IObuff, IOSIZE, message, a1);
give_warning(IObuff, hl);
diff --git a/src/nvim/move.c b/src/nvim/move.c
index a9f7ffaa76..e74dc32fd4 100644
--- a/src/nvim/move.c
+++ b/src/nvim/move.c
@@ -2241,7 +2241,7 @@ void do_check_cursorbind(void)
int old_VIsual_active = VIsual_active;
// loop through the cursorbound windows
- VIsual_select = VIsual_active = 0;
+ VIsual_select = VIsual_active = false;
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
curwin = wp;
curbuf = curwin->w_buffer;
diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c
index 30092b9142..5b8c060e7a 100644
--- a/src/nvim/os/env.c
+++ b/src/nvim/os/env.c
@@ -494,7 +494,7 @@ void init_homedir(void)
// links. Don't do it when we can't return.
if (os_dirname(os_buf, MAXPATHL) == OK && os_chdir(os_buf) == 0) {
if (!os_chdir(var) && os_dirname(IObuff, IOSIZE) == OK) {
- var = (char *)IObuff;
+ var = IObuff;
}
if (os_chdir(os_buf) != 0) {
emsg(_(e_prev_dir));
diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c
index 122f3e2020..0b9a9bbdec 100644
--- a/src/nvim/regexp.c
+++ b/src/nvim/regexp.c
@@ -2304,10 +2304,10 @@ static uint8_t regname[][30] = {
// Returns the program in allocated memory.
// Use vim_regfree() to free the memory.
// Returns NULL for an error.
-regprog_T *vim_regcomp(char *expr_arg, int re_flags)
+regprog_T *vim_regcomp(const char *expr_arg, int re_flags)
{
regprog_T *prog = NULL;
- char *expr = expr_arg;
+ const char *expr = expr_arg;
regexp_engine = (int)p_re;
@@ -2403,7 +2403,7 @@ void free_regexp_stuff(void)
#endif
-static void report_re_switch(char *pat)
+static void report_re_switch(const char *pat)
{
if (p_verbose > 0) {
verbose_enter();
@@ -2425,7 +2425,7 @@ static void report_re_switch(char *pat)
/// @param nl
///
/// @return true if there is a match, false if not.
-static bool vim_regexec_string(regmatch_T *rmp, char *line, colnr_T col, bool nl)
+static bool vim_regexec_string(regmatch_T *rmp, const char *line, colnr_T col, bool nl)
{
regexec_T rex_save;
bool rex_in_use_save = rex_in_use;
@@ -2482,7 +2482,7 @@ static bool vim_regexec_string(regmatch_T *rmp, char *line, colnr_T col, bool nl
// Note: "*prog" may be freed and changed.
// Return true if there is a match, false if not.
-bool vim_regexec_prog(regprog_T **prog, bool ignore_case, char *line, colnr_T col)
+bool vim_regexec_prog(regprog_T **prog, bool ignore_case, const char *line, colnr_T col)
{
regmatch_T regmatch = { .regprog = *prog, .rm_ic = ignore_case };
bool r = vim_regexec_string(&regmatch, line, col, false);
@@ -2492,7 +2492,7 @@ bool vim_regexec_prog(regprog_T **prog, bool ignore_case, char *line, colnr_T co
// Note: "rmp->regprog" may be freed and changed.
// Return true if there is a match, false if not.
-bool vim_regexec(regmatch_T *rmp, char *line, colnr_T col)
+bool vim_regexec(regmatch_T *rmp, const char *line, colnr_T col)
{
return vim_regexec_string(rmp, line, col, false);
}
@@ -2500,7 +2500,7 @@ bool vim_regexec(regmatch_T *rmp, char *line, colnr_T col)
// Like vim_regexec(), but consider a "\n" in "line" to be a line break.
// Note: "rmp->regprog" may be freed and changed.
// Return true if there is a match, false if not.
-bool vim_regexec_nl(regmatch_T *rmp, char *line, colnr_T col)
+bool vim_regexec_nl(regmatch_T *rmp, const char *line, colnr_T col)
{
return vim_regexec_string(rmp, line, col, true);
}
diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c
index c9667d58ed..5d1c104dc5 100644
--- a/src/nvim/runtime.c
+++ b/src/nvim/runtime.c
@@ -914,19 +914,6 @@ static int add_pack_dir_to_rtp(char *fname, bool is_pack)
const char *cur_entry = entry;
copy_option_part((char **)&entry, buf, MAXPATHL, ",");
- if (insp == NULL) {
- add_pathsep(buf);
- char *const rtp_ffname = fix_fname(buf);
- if (rtp_ffname == NULL) {
- goto theend;
- }
- bool match = path_fnamencmp(rtp_ffname, ffname, fname_len) == 0;
- xfree(rtp_ffname);
- if (match) {
- // Insert "ffname" after this entry (and comma).
- insp = entry;
- }
- }
if ((p = strstr(buf, "after")) != NULL
&& p > buf
@@ -940,6 +927,20 @@ static int add_pack_dir_to_rtp(char *fname, bool is_pack)
after_insp = cur_entry;
break;
}
+
+ if (insp == NULL) {
+ add_pathsep(buf);
+ char *const rtp_ffname = fix_fname(buf);
+ if (rtp_ffname == NULL) {
+ goto theend;
+ }
+ bool match = path_fnamencmp(rtp_ffname, ffname, fname_len) == 0;
+ xfree(rtp_ffname);
+ if (match) {
+ // Insert "ffname" after this entry (and comma).
+ insp = entry;
+ }
+ }
}
if (insp == NULL) {
diff --git a/src/nvim/search.c b/src/nvim/search.c
index 67b6f5e6a6..525cec8b02 100644
--- a/src/nvim/search.c
+++ b/src/nvim/search.c
@@ -4159,10 +4159,10 @@ static void show_pat_in_path(char *line, int type, bool did_show, int action, FI
}
if (action == ACTION_SHOW_ALL) {
snprintf(IObuff, IOSIZE, "%3ld: ", count); // Show match nr.
- msg_puts((const char *)IObuff);
+ msg_puts(IObuff);
snprintf(IObuff, IOSIZE, "%4" PRIdLINENR, *lnum); // Show line nr.
// Highlight line numbers.
- msg_puts_attr((const char *)IObuff, HL_ATTR(HLF_N));
+ msg_puts_attr(IObuff, HL_ATTR(HLF_N));
msg_puts(" ");
}
msg_prt_line(line, false);
diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c
index 8927b599d0..c68eee3526 100644
--- a/src/nvim/spellfile.c
+++ b/src/nvim/spellfile.c
@@ -608,7 +608,7 @@ slang_T *spell_load_file(char *fname, char *lang, slang_T *old_lp, bool silent)
semsg(_(e_notopen), fname);
} else if (p_verbose > 2) {
verbose_enter();
- smsg((char *)e_notopen, fname);
+ smsg(e_notopen, fname);
verbose_leave();
}
goto endFAIL;
@@ -4047,7 +4047,7 @@ static int tree_add_word(spellinfo_T *spin, const char_u *word, wordnode_T *root
node = *prev;
}
#ifdef SPELL_PRINTTREE
- smsg((char_u *)"Added \"%s\"", word);
+ smsg("Added \"%s\"", word);
spell_print_tree(root->wn_sibling);
#endif
diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c
index 705e215dfa..d28460a63d 100644
--- a/src/nvim/spellsuggest.c
+++ b/src/nvim/spellsuggest.c
@@ -551,7 +551,7 @@ void spell_suggest(int count)
vim_snprintf(IObuff, IOSIZE, ":ot \"%.*s\" egnahC",
sug.su_badlen, sug.su_badptr);
}
- msg_puts((const char *)IObuff);
+ msg_puts(IObuff);
msg_clr_eos();
msg_putchar('\n');
@@ -570,16 +570,16 @@ void spell_suggest(int count)
if (cmdmsg_rl) {
rl_mirror_ascii(IObuff);
}
- msg_puts((const char *)IObuff);
+ msg_puts(IObuff);
vim_snprintf(IObuff, IOSIZE, " \"%s\"", wcopy);
- msg_puts((const char *)IObuff);
+ msg_puts(IObuff);
// The word may replace more than "su_badlen".
if (sug.su_badlen < stp->st_orglen) {
vim_snprintf(IObuff, IOSIZE, _(" < \"%.*s\""),
stp->st_orglen, sug.su_badptr);
- msg_puts((const char *)IObuff);
+ msg_puts(IObuff);
}
if (p_verbose > 0) {
@@ -597,7 +597,7 @@ void spell_suggest(int count)
rl_mirror_ascii(IObuff + 1);
}
msg_advance(30);
- msg_puts((const char *)IObuff);
+ msg_puts(IObuff);
}
msg_putchar('\n');
}
diff --git a/src/nvim/tag.c b/src/nvim/tag.c
index 852e7e6e7c..2d9d0de951 100644
--- a/src/nvim/tag.c
+++ b/src/nvim/tag.c
@@ -726,7 +726,7 @@ void do_tag(char *tag, int type, int count, int forceit, int verbose)
if ((num_matches > prev_num_matches || new_tag)
&& num_matches > 1) {
if (ic) {
- msg_attr((const char *)IObuff, HL_ATTR(HLF_W));
+ msg_attr(IObuff, HL_ATTR(HLF_W));
} else {
msg(IObuff);
}
diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua
index 65b13bebf7..a4bd574a56 100644
--- a/test/functional/api/highlight_spec.lua
+++ b/test/functional/api/highlight_spec.lua
@@ -561,4 +561,18 @@ describe('API: get highlight', function()
eq({ link = 'String' }, meths.get_hl(0, { name = '@string' }))
eq({ fg = 10937249 }, meths.get_hl(0, { name = '@string.cpp', link = false }))
end)
+
+ it('can get all attributes for a linked group', function()
+ command('hi Bar guifg=red')
+ command('hi Foo guifg=#00ff00 gui=bold,underline')
+ command('hi! link Foo Bar')
+ eq({ link = 'Bar', fg = tonumber('00ff00', 16), bold = true, underline = true }, meths.get_hl(0, { name = 'Foo', link = true }))
+ end)
+
+ it('can set link as well as other attributes', function()
+ command('hi Bar guifg=red')
+ local hl = { link = 'Bar', fg = tonumber('00ff00', 16), bold = true, cterm = { bold = true } }
+ meths.set_hl(0, 'Foo', hl)
+ eq(hl, meths.get_hl(0, { name = 'Foo', link = true }))
+ end)
end)
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua
index a0428ed933..4f401eed8f 100644
--- a/test/functional/lua/vim_spec.lua
+++ b/test/functional/lua/vim_spec.lua
@@ -2915,6 +2915,15 @@ describe('lua stdlib', function()
return a
]])
end)
+
+ it('accepts the key name', function()
+ eq({ b = 'b', c = 'c' }, exec_lua [[
+ local a = vim.defaulttable(function(k) return k end)
+ local _ = a.b
+ local _ = a.c
+ return a
+ ]])
+ end)
end)
it('vim.lua_omnifunc', function()
diff --git a/test/functional/treesitter/highlight_spec.lua b/test/functional/treesitter/highlight_spec.lua
index 44e6500008..faeb4befcd 100644
--- a/test/functional/treesitter/highlight_spec.lua
+++ b/test/functional/treesitter/highlight_spec.lua
@@ -575,14 +575,14 @@ describe('treesitter highlighting', function()
exec_lua [[
local parser = vim.treesitter.get_parser(0, "c")
- test_hl = vim.treesitter.highlighter.new(parser, {queries = {c = hl_query..'\n((translation_unit) @Error (set! "priority" 101))\n'}})
+ test_hl = vim.treesitter.highlighter.new(parser, {queries = {c = hl_query..'\n((translation_unit) @constant (#set! "priority" 101))\n'}})
]]
- -- expect everything to have Error highlight
+ -- expect everything to have Constant highlight
screen:expect{grid=[[
{12:int}{8: x = INT_MAX;} |
- {8:#define READ_STRING(x, y) (}{12:char_u}{8: *)read_string((x), (}{12:size_t}{8:)(y))}|
- {8:#define foo }{12:void}{8: main() { \} |
- {8: }{12:return}{8: 42; \} |
+ {8:#define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y))}|
+ {8:#define foo void main() { \} |
+ {8: return 42; \} |
{8: }} |
^ |
{1:~ }|
@@ -599,13 +599,13 @@ describe('treesitter highlighting', function()
|
]], attr_ids={
[1] = {bold = true, foreground = Screen.colors.Blue1};
- [8] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red};
+ [8] = {foreground = Screen.colors.Magenta1};
-- bold will not be overwritten at the moment
- [12] = {background = Screen.colors.Red, bold = true, foreground = Screen.colors.Grey100};
+ [12] = {bold = true, foreground = Screen.colors.Magenta1};
}}
eq({
- {capture='Error', metadata = { priority='101' }, lang='c' };
+ {capture='constant', metadata = { priority='101' }, lang='c' };
{capture='type', metadata = { }, lang='c' };
}, exec_lua [[ return vim.treesitter.get_captures_at_pos(0, 0, 2) ]])
end)
diff --git a/test/old/testdir/test_packadd.vim b/test/old/testdir/test_packadd.vim
index 3121b3b4d1..64c8fd8659 100644
--- a/test/old/testdir/test_packadd.vim
+++ b/test/old/testdir/test_packadd.vim
@@ -20,6 +20,13 @@ func Test_packadd()
call mkdir(s:plugdir . '/plugin/also', 'p')
call mkdir(s:plugdir . '/ftdetect', 'p')
call mkdir(s:plugdir . '/after', 'p')
+
+ " This used to crash Vim
+ let &rtp = 'nosuchdir,' . s:plugdir . '/after'
+ packadd mytest
+ " plugdir should be inserted before plugdir/after
+ call assert_match('^nosuchdir,' . s:plugdir . ',', &rtp)
+
set rtp&
let rtp = &rtp
filetype on