Compare commits

...

9 Commits

Author SHA1 Message Date
Justin M. Keyes 313558b5c3
Merge 45a75a662d into 435dee74bb 2024-04-26 21:36:15 -04:00
zeertzjq 435dee74bb
vim-patch:9.1.0374: wrong botline in BufEnter (#28530)
Problem:  When :edit an existing buffer, line('w$') may return a
          wrong result.
Solution: Reset w_valid in curwin_init() (Jaehwang Jung)

`do_ecmd()` reinitializes the current window (`curwin_init()`) whose
`w_valid` field may have `VALID_BOTLINE` set. Resetting `w_botline`
without marking it as invalid makes subsequent `validate_botline()`
calls a no-op, thus resulting in wrong `line('w$')` value.

closes: vim/vim#14642

eb80b8304e

Co-authored-by: Jaehwang Jung <tomtomjhj@gmail.com>
2024-04-27 06:32:25 +08:00
zeertzjq 694756252b
Merge pull request #28529 from zeertzjq/vim-fe1e2b5e2d65
vim-patch: clarify syntax vs matching mechanism
2024-04-27 06:31:55 +08:00
zeertzjq e81eb34aa1 vim-patch:9525f6213604
runtime(doc): fix typo synconcealend -> synconcealed (vim/vim#14644)

9525f62136

Co-authored-by: Philip H <47042125+pheiduck@users.noreply.github.com>
2024-04-27 05:52:47 +08:00
zeertzjq a1568f5df0 vim-patch:00ae5c5cba7b
runtime(doc): fix typo

00ae5c5cba

Co-authored-by: Christian Brabandt <cb@256bit.org>
2024-04-27 05:52:15 +08:00
zeertzjq f1f5fb911b vim-patch:fe1e2b5e2d65
runtime(doc): clarify syntax vs matching mechanism

fixes: vim/vim#14643

fe1e2b5e2d

Co-authored-by: Christian Brabandt <cb@256bit.org>
2024-04-27 05:51:52 +08:00
Justin M. Keyes 45a75a662d smurf 2024-04-25 15:28:45 +02:00
Justin M. Keyes c592617dd5 wip
- constrain ignore_parse_error()
2024-04-25 15:28:45 +02:00
Justin M. Keyes f9db95e5f9 feat(docs): parse [optional] 2024-04-25 15:27:50 +02:00
21 changed files with 127 additions and 64 deletions

View File

@ -8208,6 +8208,10 @@ synconcealed({lnum}, {col}) *synconcealed()*
synconcealed(lnum, 5) [1, 'X', 2]
synconcealed(lnum, 6) [0, '', 0]
Note: Doesn't consider |matchadd()| highlighting items,
since syntax and matching highlighting are two different
mechanisms |syntax-vs-match|.
synstack({lnum}, {col}) *synstack()*
Return a |List|, which is the stack of syntax items at the
position {lnum} and {col} in the current window. {lnum} is

View File

@ -652,7 +652,7 @@ list of the current window.
list.
If [count] is omitted, the {name}s are added just
after the current entry in the argument list.
Otherwise they are added after the [count]'th file.
Otherwise they are added after the [count]th file.
If the argument list is "a b c", and "b" is the
current argument, then these commands result in:
command new argument list ~

View File

@ -926,13 +926,13 @@ a `return` statement, then the function returns with no results.
*lua-colonsyntax*
The colon syntax is used for defining methods, that is, functions that have an
implicit extra parameter `self`. Thus, the statement
implicit extra parameter `self`. Thus, the statement >
`function t.a.b.c:f (` `params` `)` `body` `end`
function t.a.b.c:f ( params ) body end
is syntactic sugar for
is syntactic sugar for >
`t.a.b.c:f = function (` `self`, `params` `)` `body` `end`
t.a.b.c:f = function ( self, params ) body end
==============================================================================
2.6 Visibility Rules *lua-visibility*

View File

@ -161,7 +161,7 @@ h or *h*
<Left> or *<Left>*
CTRL-H or *CTRL-H* *<BS>*
<BS> [count] characters to the left. |exclusive| motion.
Note: If you prefer <BS> to delete a character, use
Nxte: If [you] prefer <BS> to delete a character, use
the mapping:
:map CTRL-V<BS> X
(to enter "CTRL-V<BS>" type the CTRL-V key, followed
@ -256,7 +256,7 @@ g<End> Like |g$| but to the last non-blank character
|exclusive| motion. Ceci n'est pas une pipe.
*f*
f{char} To [count]'th occurrence of {char} to the right. The
f{char} To [count]th occurrence of {char} to the right. The
cursor is placed on {char} |inclusive|.
{char} can be entered as a digraph |digraph-arg|.
When 'encoding' is set to Unicode, composing
@ -266,18 +266,18 @@ f{char} To [count]'th occurrence of {char} to the right. The
|i_CTRL-^|.
*F*
F{char} To the [count]'th occurrence of {char} to the left.
F{char} To the [count]th occurrence of {char} to the left.
The cursor is placed on {char} |exclusive|.
{char} can be entered like with the |f| command.
*t*
t{char} Till before [count]'th occurrence of {char} to the
t{char} Till before [count]th occurrence of {char} to the
right. The cursor is placed on the character left of
{char} |inclusive|.
{char} can be entered like with the |f| command.
*T*
T{char} Till after [count]'th occurrence of {char} to the
T{char} Till after [count]th occurrence of {char} to the
left. The cursor is placed on the character right of
{char} |exclusive|.
{char} can be entered like with the |f| command.
@ -604,14 +604,14 @@ ib "inner block", select [count] blocks, from "[count] [("
a> *v_a>* *v_a<* *a>* *a<*
a< "a <> block", select [count] <> blocks, from the
[count]'th unmatched '<' backwards to the matching
[count]th unmatched '<' backwards to the matching
'>', including the '<' and '>'. The |cpo-M| option flag
is used to handle escaped '<' and '>'.
When used in Visual mode it is made charwise.
i> *v_i>* *v_i<* *i>* *i<*
i< "inner <> block", select [count] <> blocks, from
the [count]'th unmatched '<' backwards to the matching
the [count]th unmatched '<' backwards to the matching
'>', excluding the '<' and '>'. It's an error to
select an empty inner block like "<>". The |cpo-M|
option flag is used to handle escaped '<' and '>'.
@ -619,14 +619,14 @@ i< "inner <> block", select [count] <> blocks, from
*v_at* *at*
at "a tag block", select [count] tag blocks, from the
[count]'th unmatched "<aaa>" backwards to the matching
[count]th unmatched "<aaa>" backwards to the matching
"</aaa>", including the "<aaa>" and "</aaa>".
See |tag-blocks| about the details.
When used in Visual mode it is made charwise.
*v_it* *it*
it "inner tag block", select [count] tag blocks, from the
[count]'th unmatched "<aaa>" backwards to the matching
[count]th unmatched "<aaa>" backwards to the matching
"</aaa>", excluding the "<aaa>" and "</aaa>".
See |tag-blocks| about the details.
When used in Visual mode it is made charwise.

View File

@ -4,7 +4,7 @@
NVIM REFERENCE MANUAL
Notable changes in Nvim 0.9 from 0.8 *news-0.9*
Notable changes in Nvim 0.9 since 0.8 *news-0.9*
Type |gO| to see the table of contents.

View File

@ -4,9 +4,7 @@
NVIM REFERENCE MANUAL
Notable changes in Nvim 0.10 from 0.9 *news*
For changes in Nvim 0.9, see |news-0.9|.
Notable changes in Nvim 0.10 since 0.9 (see also |news-0.9|) *news*
Type |gO| to see the table of contents.

View File

@ -15,36 +15,36 @@ explanations are in chapter 27 |usr_27.txt|.
1. Search commands *search-commands*
*/*
/{pattern}[/]<CR> Search forward for the [count]'th occurrence of
/{pattern}[/]<CR> Search forward for the [count]th occurrence of
{pattern} |exclusive|.
/{pattern}/{offset}<CR> Search forward for the [count]'th occurrence of
/{pattern}/{offset}<CR> Search forward for the [count]th occurrence of
{pattern} and go |{offset}| lines up or down.
|linewise|.
*/<CR>*
/<CR> Search forward for the [count]'th occurrence of the
/<CR> Search forward for the [count]th occurrence of the
latest used pattern |last-pattern| with latest used
|{offset}|.
//{offset}<CR> Search forward for the [count]'th occurrence of the
//{offset}<CR> Search forward for the [count]th occurrence of the
latest used pattern |last-pattern| with new
|{offset}|. If {offset} is empty no offset is used.
*?*
?{pattern}[?]<CR> Search backward for the [count]'th previous
?{pattern}[?]<CR> Search backward for the [count]th previous
occurrence of {pattern} |exclusive|.
?{pattern}?{offset}<CR> Search backward for the [count]'th previous
?{pattern}?{offset}<CR> Search backward for the [count]th previous
occurrence of {pattern} and go |{offset}| lines up or
down |linewise|.
*?<CR>*
?<CR> Search backward for the [count]'th occurrence of the
?<CR> Search backward for the [count]th occurrence of the
latest used pattern |last-pattern| with latest used
|{offset}|.
??{offset}<CR> Search backward for the [count]'th occurrence of the
??{offset}<CR> Search backward for the [count]th occurrence of the
latest used pattern |last-pattern| with new
|{offset}|. If {offset} is empty no offset is used.
@ -59,7 +59,7 @@ N Repeat the latest "/" or "?" [count] times in
opposite direction. |last-pattern|
*star* *E348* *E349*
* Search forward for the [count]'th occurrence of the
* Search forward for the [count]th occurrence of the
word nearest to the cursor. The word used for the
search is the first of:
1. the keyword under the cursor |'iskeyword'|
@ -1375,6 +1375,19 @@ Finally, these constructs are unique to Perl:
==============================================================================
10. Highlighting matches *match-highlight*
*syntax-vs-match*
Note that the match highlight mechanism is independent
of |syntax-highlighting|, which is (usually) a buffer-local
highlighting, while matching is window-local, both methods
can be freely mixed. Match highlighting functions give you
a bit more flexibility in when and how to apply, but are
typically only used for temporary highlighting, without strict
rules. Both methods can be used to conceal text.
Thus the matching functions like |matchadd()| won't consider
syntax rules and functions like |synconcealed()| and the
other way around.
*:mat* *:match*
:mat[ch] {group} /{pattern}/
Define a pattern to highlight in the current window. It will

View File

@ -213,7 +213,7 @@ N is used to indicate an optional count that can be given before the command.
*Q_ta* Using tags
|:ta| :ta[g][!] {tag} jump to tag {tag}
|:ta| :[count]ta[g][!] jump to [count]'th newer tag in tag list
|:ta| :[count]ta[g][!] jump to [count]th newer tag in tag list
|CTRL-]| CTRL-] jump to the tag under cursor, unless changes
have been made
|:ts| :ts[elect][!] [tag] list matching tags and select one to jump to
@ -224,10 +224,10 @@ N is used to indicate an optional count that can be given before the command.
|:tags| :tags print tag list
|CTRL-T| N CTRL-T jump back from Nth older tag in tag list
|:po| :[count]po[p][!] jump back from [count]'th older tag in tag list
|:tnext| :[count]tn[ext][!] jump to [count]'th next matching tag
|:tp| :[count]tp[revious][!] jump to [count]'th previous matching tag
|:tr| :[count]tr[ewind][!] jump to [count]'th matching tag
|:po| :[count]po[p][!] jump back from [count]th older tag in tag list
|:tnext| :[count]tn[ext][!] jump to [count]th next matching tag
|:tp| :[count]tp[revious][!] jump to [count]th previous matching tag
|:tr| :[count]tr[ewind][!] jump to [count]th matching tag
|:tl| :tl[ast][!] jump to last matching tag
|:ptag| :pt[ag] {tag} open a preview window to show tag {tag}

View File

@ -3825,7 +3825,9 @@ Whether or not it is actually concealed depends on the value of the
'conceallevel' option. The 'concealcursor' option is used to decide whether
concealable items in the current line are displayed unconcealed to be able to
edit the line.
Another way to conceal text is with |matchadd()|.
Another way to conceal text is with |matchadd()|, but internally this works a
bit differently |syntax-vs-match|.
concealends *:syn-concealends*
@ -3833,7 +3835,9 @@ When the "concealends" argument is given, the start and end matches of
the region, but not the contents of the region, are marked as concealable.
Whether or not they are actually concealed depends on the setting on the
'conceallevel' option. The ends of a region can only be concealed separately
in this way when they have their own highlighting via "matchgroup"
in this way when they have their own highlighting via "matchgroup". The
|synconcealed()| function can be used to retrieve information about conealed
items.
cchar *:syn-cchar*
*E844*

View File

@ -953,10 +953,7 @@ get_lang({filetype}) *vim.treesitter.language.get_lang()*
(`string?`)
inspect({lang}) *vim.treesitter.language.inspect()*
Inspects the provided language.
Inspecting provides some useful information on the language like node
names, ...
Gets some useful information on the language like node names, ...
Parameters: ~
• {lang} (`string`) Language

View File

@ -948,7 +948,7 @@ Syntax and highlighting: *syntax-functions* *highlighting-functions*
synIDattr() get a specific attribute of a syntax ID
synIDtrans() get translated syntax ID
synstack() get list of syntax IDs at a specific position
synconcealed() get info about concealing
synconcealed() get info about (syntax) concealing
diff_hlID() get highlight ID for diff mode at a position
matchadd() define a pattern to highlight (a "match")
matchaddpos() define a list of positions to highlight

View File

@ -9752,6 +9752,10 @@ function vim.fn.synIDtrans(synID) end
--- synconcealed(lnum, 5) [1, 'X', 2]
--- synconcealed(lnum, 6) [0, '', 0]
---
--- Note: Doesn't consider |matchadd()| highlighting items,
--- since syntax and matching highlighting are two different
--- mechanisms |syntax-vs-match|.
---
--- @param lnum integer
--- @param col integer
--- @return {[1]: integer, [2]: string, [3]: integer}

View File

@ -72,12 +72,12 @@ local function valid_lang(lang)
return lang and lang ~= ''
end
--- Returns the parser for a specific buffer and attaches it to the buffer
--- Gets the parser for a buffer and attaches it to the buffer.
---
--- If needed, this will create the parser.
--- Creates the parser, if needed.
---
---@param bufnr (integer|nil) Buffer the parser should be tied to (default: current buffer)
---@param lang (string|nil) Language of this parser (default: from buffer filetype)
---@param bufnr (integer|nil) Buffer to parse (default: current buffer)
---@param lang (string|nil) Language of this parser (default: buffer 'filetype')
---@param opts (table|nil) Options to pass to the created language tree
---
---@return vim.treesitter.LanguageTree object to use for parsing
@ -96,15 +96,13 @@ function M.get_parser(bufnr, lang, opts)
if not parsers[bufnr] then
error(
string.format(
'There is no parser available for buffer %d and one could not be'
.. ' created because lang could not be determined. Either pass lang'
.. ' or set the buffer filetype',
"No parser for buffer %d with unknown lang. Either pass lang or set 'filetype'.",
bufnr
)
)
end
elseif parsers[bufnr] == nil or parsers[bufnr]:lang() ~= lang then
assert(lang, 'lang should be valid')
assert(lang, 'invalid lang')
parsers[bufnr] = M._create_parser(bufnr, lang, opts)
end

View File

@ -106,6 +106,7 @@ function M.add(lang, opts)
path = paths[1]
end
vim._ts_remove_language(lang)
vim._ts_add_language(path, lang, symbol_name)
M.register(lang, filetype)
end
@ -139,9 +140,7 @@ function M.register(lang, filetype)
end
end
--- Inspects the provided language.
---
--- Inspecting provides some useful information on the language like node names, ...
--- Gets some useful information on the language like node names, ...
---
---@param lang string Language
---@return table

View File

@ -10,13 +10,13 @@
--
-- USAGE (GENERATE HTML):
-- 1. `:helptags ALL` first; this script depends on vim.fn.taglist().
-- 2. nvim -V1 -es --clean +"lua require('scripts.gen_help_html').gen('./runtime/doc', 'target/dir/')" +q
-- 2. rm -rf build/runtime/doc/ && make && nvim -V1 -es --clean +"lua require('scripts.gen_help_html').gen('./runtime/doc', 'target/dir/')" +q
-- - Read the docstring at gen().
-- 3. cd target/dir/ && jekyll serve --host 0.0.0.0
-- 4. Visit http://localhost:4000/…/help.txt.html
--
-- USAGE (VALIDATE):
-- 1. nvim -V1 -es +"lua require('scripts.gen_help_html').validate('./runtime/doc')" +q
-- 1. rm -rf build/runtime/doc/ && make && nvim -V1 -es +"lua require('scripts.gen_help_html').validate('./runtime/doc')" +q
-- - validate() is 10x faster than gen(), so it is used in CI.
--
-- SELF-TEST MODE:
@ -28,6 +28,7 @@
-- * visit_node() is the core function used by gen() to traverse the document tree and produce HTML.
-- * visit_validate() is the core function used by validate().
-- * Files in `new_layout` will be generated with a "flow" layout instead of preformatted/fixed-width layout.
-- All Nvim-owned files should migrate to "flow" layout.
local tagmap = nil ---@type table<string, string>
local helpfiles = nil ---@type string[]
@ -57,6 +58,7 @@ local M = {}
-- These files are generated with "flow" layout (non fixed-width, wrapped text paragraphs).
-- All other files are "legacy" files which require fixed-width layout.
-- All Nvim-owned files should migrate to "flow" layout.
local new_layout = {
['api.txt'] = true,
['lsp.txt'] = true,
@ -328,7 +330,7 @@ local function ignore_parse_error(fname, s)
end
-- Ignore parse errors for unclosed tag.
-- This is common in vimdocs and is treated as plaintext by :help.
return s:find("^[`'|*]")
return s:find('^``') or s:find("^['|]")
end
---@param node TSNode
@ -607,11 +609,20 @@ local function visit_node(root, level, lang_tree, headings, opt, stats)
s = fix_tab_after_conceal(s, node_text(root:next_sibling()))
end
return s
elseif vim.list_contains({ 'codespan', 'keycode' }, node_name) then
elseif vim.list_contains({ 'codespan', 'keycode', 'optional' }, node_name) then
if root:has_error() then
return text
end
local s = ('%s<code>%s</code>'):format(ws(), trimmed)
local class = node_name == 'optional' and ' class="optional"' or ''
if node_name == 'optional' then
return ('%s<code%s>%s</code>'):format(ws(), class, trimmed)
end
local s = (
node_name == 'keycode'
-- TODO: use <kbd>. Currently has a layout issue, example: ":help _".
and ('%s<code>%s</code>'):format(ws(), trimmed)
or ('%s<code%s>%s</code>'):format(ws(), class, trimmed)
)
if opt.old and node_name == 'codespan' then
s = fix_tab_after_conceal(s, node_text(root:next_sibling()))
end
@ -765,9 +776,10 @@ local function parse_buf(fname, parser_path)
vim.cmd('sbuffer ' .. tostring(fname)) -- Buffer number.
end
if parser_path then
vim.treesitter.language.add('vimdoc', { path = parser_path })
vim.treesitter.language.add('vimdoc2', { path = parser_path })
end
local lang_tree = vim.treesitter.get_parser(buf)
local lang_tree = vim.treesitter.get_parser(buf, 'vimdoc2')
-- vim.print(lang_tree)
return lang_tree, buf
end
@ -1013,11 +1025,13 @@ local function gen_css(fname)
local css = [[
:root {
--code-color: #004b4b;
--kbd-color: red;
--tag-color: #095943;
}
@media (prefers-color-scheme: dark) {
:root {
--code-color: #00c243;
--kbd-color: red;
--tag-color: #00b7b7;
}
}
@ -1087,7 +1101,7 @@ local function gen_css(fname)
/* Tabs are used for alignment in old docs, so we must match Vim's 8-char expectation. */
tab-size: 8;
white-space: pre;
font-size: 16px;
font-size: 15px;
font-family: ui-monospace,SFMono-Regular,SF Mono,Menlo,Consolas,Liberation Mono,monospace;
}
.old-help-para pre {
@ -1146,7 +1160,14 @@ local function gen_css(fname)
}
code {
color: var(--code-color);
font-size: 16px;
font-size: 15px;
}
code.optional {
color: yellow;
}
kbd {
/* color: var(--kbd-color); */
font-size: 15px;
}
pre {
/* Tabs are used in codeblocks only for indentation, not alignment, so we can aggressively shrink them. */
@ -1155,7 +1176,7 @@ local function gen_css(fname)
line-height: 1.3; /* Important for ascii art. */
overflow: visible;
/* font-family: ui-monospace,SFMono-Regular,SF Mono,Menlo,Consolas,Liberation Mono,monospace; */
font-size: 16px;
font-size: 15px;
margin-top: 10px;
}
pre:last-child {

View File

@ -953,6 +953,8 @@ add_dependencies(doc doc-vim doc-eval)
add_target(lintdoc
COMMAND $<TARGET_FILE:nvim_bin> -u NONE -l scripts/lintdoc.lua
DEPENDS ${DOCFILES}
DEPENDS
${DOCFILES}
${PROJECT_SOURCE_DIR}/scripts/gen_help_html.lua
CUSTOM_COMMAND_ARGS USES_TERMINAL)
add_dependencies(lintdoc nvim)

View File

@ -47,8 +47,8 @@ typedef struct {
#define VALID_VIRTCOL 0x04 // w_virtcol (file col) is valid
#define VALID_CHEIGHT 0x08 // w_cline_height and w_cline_folded valid
#define VALID_CROW 0x10 // w_cline_row is valid
#define VALID_BOTLINE 0x20 // w_botine and w_empty_rows are valid
#define VALID_BOTLINE_AP 0x40 // w_botine is approximated
#define VALID_BOTLINE 0x20 // w_botline and w_empty_rows are valid
#define VALID_BOTLINE_AP 0x40 // w_botline is approximated
#define VALID_TOPLINE 0x80 // w_topline is valid (for cursor position)
// flags for b_flags

View File

@ -11621,6 +11621,10 @@ M.funcs = {
synconcealed(lnum, 4) [1, 'X', 2]
synconcealed(lnum, 5) [1, 'X', 2]
synconcealed(lnum, 6) [0, '', 0]
Note: Doesn't consider |matchadd()| highlighting items,
since syntax and matching highlighting are two different
mechanisms |syntax-vs-match|.
]=],
name = 'synconcealed',
params = { { 'lnum', 'integer' }, { 'col', 'integer' } },

View File

@ -91,7 +91,7 @@ static TSLanguage *load_language(lua_State *L, const char *path, const char *lan
return lang;
}
// Creates the language into the internal language map.
// Creates and adds a language to the internal language map.
//
// Returns true if the language is correctly loaded in the language map
int tslua_add_language(lua_State *L)
@ -121,6 +121,12 @@ int tslua_add_language(lua_State *L)
TREE_SITTER_LANGUAGE_VERSION, lang_version);
}
bool present = map_has(cstr_t, &langs, lang_name);
if (present) {
cstr_t key;
pmap_del(cstr_t)(&langs, lang_name, &key);
xfree((void *)key);
}
pmap_put(cstr_t)(&langs, xstrdup(lang_name), lang);
lua_pushboolean(L, true);

View File

@ -2467,6 +2467,7 @@ void win_init_empty(win_T *wp)
wp->w_topline = 1;
wp->w_topfill = 0;
wp->w_botline = 2;
wp->w_valid = 0;
wp->w_s = &wp->w_buffer->b_s;
}

View File

@ -4105,4 +4105,16 @@ func Test_SwapExists_set_other_buf_modified()
bwipe!
endfunc
func Test_BufEnter_botline()
set hidden
call writefile(range(10), 'Xxx1', 'D')
call writefile(range(20), 'Xxx2', 'D')
edit Xxx1
edit Xxx2
au BufEnter Xxx1 call assert_true(line('w$') > 1)
edit Xxx1
au! BufEnter Xxx1
set hidden&vim
endfunc
" vim: shiftwidth=2 sts=2 expandtab