Compare commits

...

10 Commits

Author SHA1 Message Date
luukvbaal ef78ed74cd
Merge a73a222397 into 435dee74bb 2024-04-27 02:55:24 +02: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
Mathias Fußenegger 9b8a075539
fix(lsp): change `silent` in lsp.start.Opts to optional (#28524) 2024-04-26 20:26:21 +02:00
Gregory Anders 73034611c2
feat(diagnostic): add default mappings for diagnostics (#16230) 2024-04-26 13:16:12 -05:00
Brian Cao 3a7c30dc93
fix(man.vim): q quits after jump to different tag in MANPAGER modified (#28495) 2024-04-26 13:14:45 -05:00
Luuk van Baal a73a222397 fix(ui): flush ext_cmdline events before doing 'cmdpreview'
Problem:  An ext_cmdline implementation for the TUI through
          vim.ui_attach() needs to perform it's own :redraw's.
          This messes with the ephemeral screen state of 'inccommand'.
Solution: Flush the cmdline ui before redrawing for the cmdpreview.
          Stop re-emitting cmdline events after redraw, incremental search etc.
2024-04-23 17:33:39 +02:00
24 changed files with 169 additions and 103 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

@ -869,7 +869,7 @@ start({config}, {opts}) *vim.lsp.start()*
re-uses a client if name and root_dir matches.
• {bufnr} (`integer`) Buffer handle to attach to if starting
or re-using a client (0 for current).
• {silent} (`boolean`) Suppress error reporting if the LSP
• {silent}? (`boolean`) Suppress error reporting if the LSP
server fails to start (default false).
Return: ~

View File

@ -412,6 +412,10 @@ The following changes to existing APIs or features add new behavior.
• |crr| in Normal and Visual mode maps to |vim.lsp.buf.code_action()|.
• "gr" in Normal mode maps to |vim.lsp.buf.references()| |gr-default|
• |i_CTRL-S| in Insert mode maps to |vim.lsp.buf.signature_help()|
• "]d" and "[d" in Normal mode map to |vim.diagnostic.goto_next()| and
|vim.diagnostic.goto_prev()|, respectively. |]d-default| |[d-default|
• <C-W>d (and <C-W><C-D>) map to |vim.diagnostic.open_float()|
|CTRL-W_d-default|
• Automatic linting of treesitter query files (see |ft-query-plugin|).
Can be disabled via: >lua
vim.g.query_lint_on = {}

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

@ -780,9 +780,17 @@ CTRL-W i Open a new window, with the cursor on the first line
beginning of the file. If a count is given, the
count'th matching line is displayed.
*[d-default*
Mapped to |vim.diagnostic.goto_prev()| by default.
|default-mappings|
*]d*
]d like "[d", but start at the current cursor position.
*]d-default*
Mapped to |vim.diagnostic.goto_next()| by default.
|default-mappings|
*:ds* *:dsearch*
:[range]ds[earch][!] [count] [/]string[/]
Like "[d" and "]d", but search in [range] lines
@ -829,6 +837,10 @@ CTRL-W d Open a new window, with the cursor on the first
beginning of the file. If a count is given, the
count'th matching line is jumped to.
*CTRL-W_d-default*
Mapped to |vim.diagnostic.open_float()| by default.
|default-mappings|
*:dsp* *:dsplit*
:[range]dsp[lit][!] [count] [/]string[/]
Like "CTRL-W d", but search in [range] lines

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

@ -141,6 +141,9 @@ of these in your config by simply removing the mapping, e.g. ":unmap Y".
- |crr|
- gr |gr-default|
- <C-S> |i_CTRL-S|
- ]d |]d-default|
- [d |[d-default|
- <C-W>d |CTRL-W_d-default|
- Nvim LSP client defaults |lsp-defaults|
- K |K-lsp-default|

View File

@ -24,7 +24,7 @@ if !exists('g:no_plugin_maps') && !exists('g:no_man_maps')
nnoremap <silent> <buffer> k gk
nnoremap <silent> <buffer> gO :lua require'man'.show_toc()<CR>
nnoremap <silent> <buffer> <2-LeftMouse> :Man<CR>
if get(b:, 'pager')
if get(g:, 'pager')
nnoremap <silent> <buffer> <nowait> q :lclose<CR><C-W>q
else
nnoremap <silent> <buffer> <nowait> q :lclose<CR><C-W>c

View File

@ -411,15 +411,13 @@ local function find_man()
return false
end
---@param pager boolean
local function set_options(pager)
local function set_options()
vim.bo.swapfile = false
vim.bo.buftype = 'nofile'
vim.bo.bufhidden = 'unload'
vim.bo.modified = false
vim.bo.readonly = true
vim.bo.modifiable = false
vim.b.pager = pager
vim.bo.filetype = 'man'
end
@ -475,7 +473,7 @@ local function put_page(page)
vim.cmd([[silent! keeppatterns keepjumps %s/\s\{199,}/\=repeat(' ', 10)/g]])
vim.cmd('1') -- Move cursor to first line
highlight_man_page()
set_options(false)
set_options()
end
local function format_candidate(path, psect)
@ -662,7 +660,8 @@ function M.init_pager()
vim.cmd.file({ 'man://' .. fn.fnameescape(ref):lower(), mods = { silent = true } })
end
set_options(true)
vim.g.pager = true
set_options()
end
---@param count integer
@ -730,7 +729,7 @@ function M.open_page(count, smods, args)
if not ok then
error(ret)
else
set_options(false)
set_options()
end
vim.b.man_sect = sect

View File

@ -127,7 +127,9 @@ do
end, { desc = gx_desc })
end
--- Default maps for built-in commenting
--- Default maps for built-in commenting.
---
--- See |gc-default| and |gcc-default|.
do
local operator_rhs = function()
return require('vim._comment').operator()
@ -169,6 +171,35 @@ do
vim.lsp.buf.signature_help()
end, { desc = 'vim.lsp.buf.signature_help()' })
end
--- Map [d and ]d to move to the previous/next diagnostic. Map <C-W>d to open a floating window
--- for the diagnostic under the cursor.
---
--- See |[d-default|, |]d-default|, and |CTRL-W_d-default|.
do
vim.keymap.set('n', ']d', function()
vim.diagnostic.goto_next({ float = false })
end, {
desc = 'Jump to the next diagnostic with the highest severity',
})
vim.keymap.set('n', '[d', function()
vim.diagnostic.goto_prev({ float = false })
end, {
desc = 'Jump to the previous diagnostic with the highest severity',
})
vim.keymap.set('n', '<C-W>d', function()
vim.diagnostic.open_float({ border = 'rounded' })
end, {
desc = 'Open a floating window showing diagnostics under the cursor',
})
vim.keymap.set('n', '<C-W><C-D>', '<C-W>d', {
remap = true,
desc = 'Open a floating window showing diagnostics under the cursor',
})
end
end
--- Default menus

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

@ -201,7 +201,7 @@ end
--- @field bufnr integer
---
--- Suppress error reporting if the LSP server fails to start (default false).
--- @field silent boolean
--- @field silent? boolean
--- Create a new LSP client and start a language server or reuses an already
--- running client if one is found matching `name` and `root_dir`.

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

@ -551,7 +551,6 @@ int update_screen(void)
if (type == UPD_CLEAR) { // first clear screen
screenclear(); // will reset clear_cmdline
// and set UPD_NOT_VALID for each window
cmdline_screen_cleared(); // clear external cmdline state
type = UPD_NOT_VALID;
// must_redraw may be set indirectly, avoid another redraw later
must_redraw = 0;

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

@ -2583,6 +2583,8 @@ static bool cmdpreview_may_show(CommandLineState *s)
cmdpreview_type = 1;
}
// Flush to avoid clearing cmdpreview later.
cmdline_ui_flush();
// If preview callback return value is nonzero, update screen now.
if (cmdpreview_type != 0) {
int save_rd = RedrawingDisabled;
@ -3420,38 +3422,15 @@ void ui_ext_cmdline_block_leave(void)
ui_call_cmdline_block_hide();
}
/// Extra redrawing needed for redraw! and on ui_attach
/// assumes "redrawcmdline()" will already be invoked
void cmdline_screen_cleared(void)
{
if (!ui_has(kUICmdline)) {
return;
}
if (cmdline_block.size) {
ui_call_cmdline_block_show(cmdline_block);
}
int prev_level = ccline.level - 1;
CmdlineInfo *line = ccline.prev_ccline;
while (prev_level > 0 && line) {
if (line->level == prev_level) {
// don't redraw a cmdline already shown in the cmdline window
if (prev_level != cmdwin_level) {
line->redraw_state = kCmdRedrawAll;
}
prev_level--;
}
line = line->prev_ccline;
}
}
/// called by ui_flush, do what redraws necessary to keep cmdline updated.
void cmdline_ui_flush(void)
{
if (!ui_has(kUICmdline)) {
static bool flushing = false;
if (!ui_has(kUICmdline) || flushing) {
return;
}
flushing = true; // avoid recursion: callback may flush again.
int level = ccline.level;
CmdlineInfo *line = &ccline;
while (level > 0 && line) {
@ -3466,6 +3445,7 @@ void cmdline_ui_flush(void)
}
line = line->prev_ccline;
}
flushing = false;
}
// Put a character on the command line. Shifts the following text to the
@ -3754,7 +3734,7 @@ void cmdline_paste_str(const char *s, bool literally)
// overwritten.
void redrawcmdline(void)
{
if (cmd_silent) {
if (ui_has(kUICmdline) || cmd_silent) {
return;
}
need_wait_return = false;
@ -4338,7 +4318,6 @@ static int open_cmdwin(void)
// Set "cmdwin_..." variables before any autocommands may mess things up.
cmdwin_type = get_cmdline_type();
cmdwin_level = ccline.level;
cmdwin_win = curwin;
cmdwin_old_curwin = old_curwin;
@ -4360,7 +4339,6 @@ static int open_cmdwin(void)
}
cmdwin_type = 0;
cmdwin_level = 0;
cmdwin_win = NULL;
cmdwin_old_curwin = NULL;
beep_flush();
@ -4462,7 +4440,6 @@ static int open_cmdwin(void)
KeyTyped = save_KeyTyped;
cmdwin_type = 0;
cmdwin_level = 0;
cmdwin_buf = NULL;
cmdwin_win = NULL;
cmdwin_old_curwin = NULL;

View File

@ -749,7 +749,6 @@ EXTERN bool km_startsel INIT( = false);
EXTERN int cmdwin_type INIT( = 0); ///< type of cmdline window or 0
EXTERN int cmdwin_result INIT( = 0); ///< result of cmdline window or 0
EXTERN int cmdwin_level INIT( = 0); ///< cmdline recursion level
EXTERN buf_T *cmdwin_buf INIT( = NULL); ///< buffer of cmdline window or NULL
EXTERN win_T *cmdwin_win INIT( = NULL); ///< window of cmdline window or NULL
EXTERN win_T *cmdwin_old_curwin INIT( = NULL); ///< curwin before opening cmdline window or NULL

View File

@ -43,7 +43,7 @@ typedef enum {
kRetLuaref, ///< return value becomes a single Luaref, regardless of type (except NIL)
} LuaRetMode;
/// To use with kRetNilBool for quick thuthyness check
/// To use with kRetNilBool for quick truthiness check
#define LUARET_TRUTHY(res) ((res).type == kObjectTypeBoolean && (res).data.boolean == true)
#ifdef INCLUDE_GENERATED_DECLARATIONS

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

@ -37,6 +37,9 @@ describe('vim.ui_attach', function()
[2] = { bold = true },
[3] = { background = Screen.colors.Grey },
[4] = { background = Screen.colors.LightMagenta },
[5] = { reverse = true },
[6] = { reverse = true, bold = true },
[7] = { background = Screen.colors.Yellow1 },
})
screen:attach()
end)
@ -155,6 +158,56 @@ describe('vim.ui_attach', function()
},
}, actual, vim.inspect(actual))
end)
it("preserved 'incsearch/command' screen state after :redraw from ext_cmdline", function()
exec_lua([[
vim.cmd.norm('ifoobar')
vim.cmd('1split cmdline')
local buf = vim.api.nvim_get_current_buf()
vim.cmd.wincmd('p')
vim.ui_attach(ns, { ext_cmdline = true }, function(event, ...)
if event == 'cmdline_show' then
local content = select(1, ...)
vim.api.nvim_buf_set_lines(buf, -2, -1, false, {content[1][2]})
vim.cmd('redraw')
end
return true
end)
]])
-- Updates a cmdline window
feed(':cmdline')
screen:expect({
grid = [[
cmdline |
{5:cmdline [+] }|
fooba^r |
{6:[No Name] [+] }|
|
]],
})
-- Does not clear 'incsearch' highlighting
feed('<Esc>/foo')
screen:expect({
grid = [[
{7:foo} |
{5:cmdline [+] }|
{5:foo}ba^r |
{6:[No Name] [+] }|
|
]],
})
-- Does not clear 'inccommand' screen
feed('<Esc>:%s/bar/baz')
screen:expect({
grid = [[
%s/bar/baz |
{5:cmdline [+] }|
foo{7:ba^z} |
{6:[No Name] [+] }|
|
]],
})
end)
end)
describe('vim.ui_attach', function()

View File

@ -192,6 +192,7 @@ describe(':Man', function()
'--headless',
'+autocmd VimLeave * echo "quit works!!"',
'+Man!',
'+tag ls',
'+call nvim_input("q")',
}
matches('quit works!!', fn.system(args, { 'manpage contents' }))

View File

@ -203,18 +203,6 @@ local function test_cmdline(linegrid)
cmdline = expectation,
}
-- erase information, so we check if it is retransmitted
command('mode')
screen:expect {
grid = [[
^ |
{1:~ }|*3
|
]],
cmdline = expectation,
reset = true,
}
feed('<cr>')
screen:expect {
grid = [[
@ -283,28 +271,6 @@ local function test_cmdline(linegrid)
},
}
command('mode')
screen:expect {
grid = [[
^ |
{1:~ }|*3
|
]],
cmdline = {
{
indent = 2,
firstc = ':',
content = { { '' } },
pos = 0,
},
},
cmdline_block = {
{ { 'function Foo()' } },
{ { ' line1' } },
},
reset = true,
}
feed('endfunction<cr>')
screen:expect {
grid = [[
@ -393,26 +359,6 @@ local function test_cmdline(linegrid)
},
}
command('mode')
screen:expect {
grid = [[
|
{2:[No Name] }|
{1::}make^ |
{3:[Command Line] }|
|
]],
cmdline = {
nil,
{
firstc = ':',
content = { { 'yank' } },
pos = 4,
},
},
reset = true,
}
feed('<c-c>')
screen:expect {
grid = [[

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