Compare commits

...

8 Commits

Author SHA1 Message Date
Justin M. Keyes 56bf418d09
Merge 6c8c982213 into 435dee74bb 2024-04-26 16:05:27 -07: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 6c8c982213
Update runtime/doc/news.txt
Co-authored-by: zeertzjq <zeertzjq@outlook.com>
2024-04-22 06:08:47 -07:00
Justin M. Keyes 4b34ae4ce3 refactor(api): rename nvim_win_remove_ns
Problem:
nvim_win_remove_ns does not follow `help dev-naming` API naming conventions.

Solution:
Rename it.
2024-04-22 14:34:31 +02:00
16 changed files with 144 additions and 53 deletions

View File

@ -2833,16 +2833,7 @@ nvim_win_add_ns({window}, {ns_id}) *nvim_win_add_ns()*
Return: ~
true if the namespace was added, else false
nvim_win_get_ns({window}) *nvim_win_get_ns()*
Gets all the namespaces scopes associated with a window.
Parameters: ~
• {window} Window handle, or 0 for current window
Return: ~
a list of namespaces ids
nvim_win_remove_ns({window}, {ns_id}) *nvim_win_remove_ns()*
nvim_win_del_ns({window}, {ns_id}) *nvim_win_del_ns()*
Removes the namespace scope from the window.
Parameters: ~
@ -2852,6 +2843,15 @@ nvim_win_remove_ns({window}, {ns_id}) *nvim_win_remove_ns()*
Return: ~
true if the namespace was removed, else false
nvim_win_get_ns({window}) *nvim_win_get_ns()*
Gets all the namespaces scopes associated with a window.
Parameters: ~
• {window} Window handle, or 0 for current window
Return: ~
a list of namespaces ids
==============================================================================
Window Functions *api-window*

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

@ -375,7 +375,7 @@ Use existing common {verb} names (actions) if possible:
- enable: Enables/disables functionality. Signature should be
`enable(enable?:boolean, filter?:table)`.
- eval: Evaluates an expression
- exec: Executes code
- exec: Executes code, may return a result
- fmt: Formats
- get: Gets things (often by a query)
- inspect: Presents a high-level, often interactive, view
@ -393,8 +393,8 @@ Do NOT use these deprecated verbs:
- show: Redundant with "print", "echo"
- toggle: Prefer `enable(not is_enabled())`.
Use consistent names for {noun} (nouns) in API functions: buffer is called
"buf" everywhere, not "buffer" in some places and "buf" in others.
Use consistent names for {topic} in API functions: buffer is called "buf"
everywhere, not "buffer" in some places and "buf" in others.
- buf: Buffer
- chan: |channel|
- cmd: Command
@ -407,10 +407,10 @@ Use consistent names for {noun} (nouns) in API functions: buffer is called
- win: Window
Do NOT use these deprecated nouns:
- buffer
- buffer Use "buf" instead
- callback Use on_foo instead
- command
- window
- command Use "cmd" instead
- window Use "win" instead
*dev-name-events*
Use the "on_" prefix to name event-handling callbacks and also the interface for
@ -428,12 +428,13 @@ Example: >
<
*dev-name-api*
Use this format to name new RPC |API| functions: >
nvim_{noun}_{verb}_{arbitrary-qualifiers}
nvim_{topic}_{verb}_{arbitrary-qualifiers}
If the function acts on an object then {noun} is the name of that object
(e.g. "buf" or "win"). If the function operates in a "global" context then
{noun} is usually omitted (but consider "namespacing" your global operations
with a {noun} that groups functions under a common concept).
Do not add new nvim_buf/nvim_win/nvim_tabpage APIs, unless you are certain the
concept will NEVER be applied to more than one "scope". That is, {topic}
should be the TOPIC ("ns", "extmark", "option", …) that acts on the scope(s)
(buf/win/tabpage/global), it should NOT be the scope. The scope should be
a parameter.
- Example: `nvim_get_keymap('v')` operates in a global context (first
parameter is not a Buffer). The "get" verb indicates that it gets anything
@ -443,6 +444,59 @@ with a {noun} that groups functions under a common concept).
and uses the "del" {verb}.
INTERFACE PATTERNS *dev-patterns*
Prefer adding a single `nvim_{topic}_{verb}_…` interface for a given topic.
Example: >
nvim_ns_add(
ns_id: int,
filter: {
handle: integer (buf/win/tabpage id)
scope: "global" | "win" | "buf" | "tabpage"
}
): { ok: boolean }
nvim_ns_get(
ns_id: int,
filter: {
handle: integer (buf/win/tabpage id)
scope: "global" | "win" | "buf" | "tabpage"
}
): { ids: int[] }
nvim_ns_del(
ns_id: int,
filter: {
handle: integer (buf/win/tabpage id)
scope: "global" | "win" | "buf" | "tabpage"
}
): { ok: boolean }
Anti-Example:
Creating separate `nvim_xx`, `nvim_buf_xx`, `nvim_win_xx`, and
`nvim_tabpage_xx`, functions all for the same `xx` topic, requires 4x the
amount of documentation, boilerplate, and function interfaces. Thus the
following is generally NOT recommended (compare these 12(!) functions to the
above 3 functions! All of these require separate docs, which users must read,
maintainers must maintain, ...): >
nvim_add_ns(…)
nvim_buf_add_ns(…)
nvim_win_add_ns(…)
nvim_tabpage_add_ns(…)
nvim_del_ns(…)
nvim_buf_del_ns(…)
nvim_win_del_ns(…)
nvim_tabpage_del_ns(…)
nvim_get_ns(…)
nvim_buf_get_ns(…)
nvim_win_get_ns(…)
nvim_tabpage_get_ns(…)
API-CLIENT *dev-api-client*
*api-client*

View File

@ -193,7 +193,17 @@ The following new APIs and features were added.
• |'smoothscroll'| option to scroll by screen line rather than by text line
when |'wrap'| is set.
• |nvim_buf_set_extmark()| supports inline virtual text.
• API enhancements
• |nvim_buf_set_extmark()| supports inline virtual text.
• |nvim_win_text_height()| computes the number of screen lines occupied
by a range of text in a given window.
• New RPC client type `msgpack-rpc` is added for |nvim_set_client_info()| to
support fully MessagePack-RPC compliant clients.
• Floating windows can now be hidden by setting `hide` in |nvim_open_win()| or
|nvim_win_set_config()|.
• |nvim_input_mouse()| supports mouse buttons "x1" and "x2".
• |nvim_tabpage_set_win()| sets the current window of a tabpage.
• |namespace| can now have window scopes. |nvim_ns_add()|
• 'foldtext' now supports virtual text format. |fold-foldtext|
@ -205,9 +215,6 @@ The following new APIs and features were added.
• |vim.lpeg| and |vim.re| expose the bundled Lpeg expression grammar parser
and its regex interface.
• |nvim_win_text_height()| computes the number of screen lines occupied
by a range of text in a given window.
• Mapping APIs now support abbreviations when mode short-name has suffix "a".
• Better cmdline completion for string option value. |complete-set-option|
@ -303,15 +310,9 @@ The following new APIs and features were added.
• Functions that take a severity as an optional parameter (e.g.
|vim.diagnostic.get()|) now also accept a list of severities |vim.diagnostic.severity|
• New RPC client type `msgpack-rpc` is added for |nvim_set_client_info()| to
support fully MessagePack-RPC compliant clients.
• Floating windows can now show footer with new `footer` and `footer_pos`
config fields. Uses |hl-FloatFooter| by default.
• Floating windows can now be hidden by setting `hide` in |nvim_open_win()| or
|nvim_win_set_config()|.
• |:terminal| command now accepts some |:command-modifiers| (specifically
|:horizontal| and those that affect splitting a window).
@ -342,8 +343,6 @@ The following new APIs and features were added.
• 'completeopt' option supports "popup" flag to show extra information in a
floating window.
• |nvim_input_mouse()| supports mouse buttons "x1" and "x2".
• |v_Q-default| and |v_@-default| repeat a register for each line of a linewise
visual selection.
@ -367,12 +366,8 @@ The following new APIs and features were added.
highlight attribute. The TUI will display URLs using the OSC 8 control
sequence, enabling clickable text in supporting terminals.
• Added |nvim_tabpage_set_win()| to set the current window of a tabpage.
• Clicking on a tabpage in the tabline with the middle mouse button closes it.
• |namespace| can now have window scopes. |nvim_win_add_ns()|
• |extmarks| option `scoped`: only show the extmarks in its namespace's scope.
• Added built-in |commenting| support.

View File

@ -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

@ -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

@ -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

@ -2114,6 +2114,13 @@ function vim.api.nvim_win_call(window, fun) end
--- hidden, even if 'hidden' is not set.
function vim.api.nvim_win_close(window, force) end
--- Removes the namespace scope from the window.
---
--- @param window integer Window handle, or 0 for current window
--- @param ns_id integer the namespace to remove
--- @return boolean
function vim.api.nvim_win_del_ns(window, ns_id) end
--- Removes a window-scoped (w:) variable
---
--- @param window integer Window handle, or 0 for current window
@ -2209,13 +2216,6 @@ function vim.api.nvim_win_hide(window) end
--- @return boolean
function vim.api.nvim_win_is_valid(window) end
--- Removes the namespace scope from the window.
---
--- @param window integer Window handle, or 0 for current window
--- @param ns_id integer the namespace to remove
--- @return boolean
function vim.api.nvim_win_remove_ns(window, ns_id) end
--- Sets the current buffer in a window, without side effects
---
--- @param window integer Window handle, or 0 for current window

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

@ -158,7 +158,7 @@ function M.on_yank(opts)
yank_timer = nil
yank_cancel = nil
pcall(vim.api.nvim_buf_clear_namespace, bufnr, yank_ns, 0, -1)
pcall(vim.api.nvim_win_remove_ns, winid, yank_ns)
pcall(vim.api.nvim_win_del_ns, winid, yank_ns)
end
yank_timer = vim.defer_fn(yank_cancel, timeout)

View File

@ -1277,7 +1277,7 @@ ArrayOf(Integer) nvim_win_get_ns(Window window, Arena *arena, Error *err)
/// @param window Window handle, or 0 for current window
/// @param ns_id the namespace to remove
/// @return true if the namespace was removed, else false
Boolean nvim_win_remove_ns(Window window, Integer ns_id, Error *err)
Boolean nvim_win_del_ns(Window window, Integer ns_id, Error *err)
FUNC_API_SINCE(12)
{
win_T *win = find_window_by_handle(window, err);

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

@ -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

@ -5742,7 +5742,7 @@ describe('decorations: window scoped', function()
|
]]}
api.nvim_win_remove_ns(0, ns)
api.nvim_win_del_ns(0, ns)
screen:expect(noextmarks)
end)
@ -5947,7 +5947,7 @@ describe('decorations: window scoped', function()
|
]]}
eq(true, api.nvim_win_remove_ns(0, ns))
eq(true, api.nvim_win_del_ns(0, ns))
eq({}, api.nvim_win_get_ns(0))
screen:expect(noextmarks)

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