Commit Graph

17724 Commits

Author SHA1 Message Date
Luuk van Baal 21360523cd fix(intro): still show intro message with floating window
Stop drawing the intro only after a split is opened.
2024-03-27 10:28:59 +01:00
Famiu Haque 63f7b1f31e refactor(options): swap `immutable` and `hidden` option property names
Ref: https://github.com/neovim/neovim/pull/28018#issuecomment-2021622120
2024-03-27 09:27:16 +00:00
Colin Kennedy 61e25b7200
vim-patch:9.1.0208: winfixbuf does not allow to re-edit current buffer (#28054)
Problem:  winfixbuf does not allow to re-edit current buffer
          (Tim Pope, after v9.1.0147)
Solution: Explicitly allow :e even when 'winfixbuf' is set,
          since it just re-loads the current buffer
          (Colin Kennedy)

fixes: vim/vim#14237
closes: vim/vim#14286

65e580bd56
2024-03-27 16:22:33 +08:00
zeertzjq bf7c7adb40
refactor(tui): reorder functions for query and response (#28051)
- Group functions for key encoding together.
- Move the handle_modereport() branch before the handle_unknown_csi()
  branch to match the order of the corresponding functions, but don't
  move handle_term_response() yet, as that will be subject to further
  changes (e.g. for #26744).
2024-03-27 11:10:28 +08:00
zeertzjq 77458e613b
vim-patch:9.1.0207: No autocommand when writing session file (#28048)
Problem:  No autocommand when writing session file
Solution: Add SessionWritePost autocommand
          (Colin Kennedy)

fixes: vim/vim#14242
closes: vim/vim#14288

e5f2280381

Co-authored-by: Colin Kennedy <colinvfx@gmail.com>
2024-03-27 05:41:41 +08:00
Famiu Haque de87197fdc refactor(options): make `immutable` and `hidden` options distinct
Problem: Currently, the `immutable` property of options can be applied for options that are hidden and options whose value simply can't be changed. Which is problematic when attempting to convert an option like `'maxcombine'` into an immutable option, because trying to `:set` an immutable option currently gives an error, which is only desired behavior for hidden options, not options that are actually immutable.

Solution: Separate the `immutable` property into two distinct `hidden` and `immutable` properties. Change all options with the `immutable` property to use the `hidden` property instead. Also add `p_mco` as an `immutable` option, as its value cannot be changed, and the underlying variable is not used anywhere.
2024-03-26 20:56:42 +00:00
zeertzjq 3f3c7299a1
docs: remove remaining mentions of hkmap (#28038) 2024-03-26 18:30:17 +08:00
zeertzjq a142670360
feat(tui): support undercurl in WezTerm (#28037)
Also fix some typos in windows.ti while at it.

Close #21699
2024-03-26 14:25:01 +08:00
zeertzjq 7e38630874
vim-patch:9.1.0204: Backspace inserts spaces with virtual text and 'smarttab' (#28032)
Problem:  Backspace inserts spaces with virtual text and 'smarttab'.
Solution: Ignore virtual text and wrapping when backspacing.
          (zeertzjq)

related: neovim/neovim#28005
closes: vim/vim#14296

0185c77014

Co-authored-by: VanaIgr <vanaigranov@gmail.com>
2024-03-26 05:42:56 +08:00
vanaigr 14839c5d18
fix(edit): backspace adds extra spaces for inline virtual text (#28005)
Problem:  Backspace adds extra spaces for inline virtual text.
Solution: Ignore virtual text and wrapping when backspacing.
2024-03-26 05:12:56 +08:00
Christian Clason 3fd8292aaf vim-patch:ab01adf7c65b
runtime(doc): Update options.txt

closes: vim/vim#14295

ab01adf7c6

Co-authored-by: Song-Tianxiang <149415622+Song-Tianxiang@users.noreply.github.com>
2024-03-25 22:07:17 +01:00
zeertzjq fb4e2dbbeb
vim-patch:9.1.0205: Cannot use modifiers before :-Ntabmove (#28031)
Problem:  Cannot use modifiers before :-Ntabmove.
Solution: Check backwards from the command instead of checking from the
          start of the command line. Slightly adjust docs to make them
          more consistent (zeertzjq).

closes: vim/vim#14289

076faac537
2024-03-26 05:04:57 +08:00
zeertzjq 7dd6fd422b
refactor(backup): remove duplicate os_copy_xattr() (#28020)
The first os_copy_xattr() is inside #ifdef UNIX, while the second isn't,
so the first one isn't actually needed.
2024-03-25 14:39:00 +08:00
Razvan-Adrian Ciochina 02d00cf3ee
fix(backup): E1509 when writing extended attr to symlink (#28014)
Problem:  E1509 when writing extended attributes to a symlink.
Solution: Copy the file before copying extended attributes.

On Fedora, the attribute being set is "security.selinux". For normal,
non-symlink files this attribute doesn't show up and that's why calling
os_copy_xattr() doesn't break in that case.
2024-03-25 07:45:47 +08:00
dundargoc d3e51603bc ci(windows): optionally test windows with ASAN
Add the label `ci:windows-asan` to enable it.
2024-03-23 23:19:29 +01:00
zeertzjq 881f5e5917
vim-patch:9.1.0199: Not enough tests for the slice() function (#27991)
Problem:  Not enough tests for the slice() function.
Solution: Test with multibyte chars, and in both Legacy and Vim9 script.
          Update docs to be clearer about how it treats composing chars.
          (zeertzjq)

closes: vim/vim#14275

ad38769030
2024-03-23 16:33:53 +08:00
zeertzjq d443b438f6 vim-patch:8.2.2605: Vim9: string index and slice does not include composing chars
Problem:    Vim9: string index and slice does not include composing chars.
Solution:   Include composing characters. (issue vim/vim#6563)

0289a093a4

Co-authored-by: Bram Moolenaar <Bram@vim.org>
2024-03-23 08:10:17 +08:00
zeertzjq e4a23b6e0b vim-patch:8.2.2318: Vim9: string and list index work differently
Problem:    Vim9: string and list index work differently.
Solution:   Make string index work like list index. (closes vim/vim#7643)

e7525c5520

Co-authored-by: Bram Moolenaar <Bram@vim.org>
2024-03-23 08:07:05 +08:00
zeertzjq dc110cba3c
Merge pull request #26970 from famiu/refactor/options/set_option_direct
refactor(options): remove `set_string_option_direct()`
2024-03-22 09:14:42 +08:00
zeertzjq dabc44d15c vim-patch:9.1.0195: memleak with ex_drop, NULL dereference
Problem:  memleak with ex_drop(), NULL dereference
          (zeertzjq)
Solution: revert back to ex_rewind(), use curbuf instead of buf

fixes: vim/vim#14246
closes: vim/vim#14251

85a769d466

Co-authored-by: Christian Brabandt <cb@256bit.org>
2024-03-22 06:04:37 +08:00
zeertzjq 271879dd49 vim-patch:9.1.0192: drop: don't rewind when editing the same file
Problem:  :drop tries to :rewind the argumentlist, which results in E37
          (after v9.1.0046)
Solution: instead of calling ex_rewind(), call open_buffer() only when
          re-using the initial empty buffer

fixes: vim/vim#14219
closes: vim/vim#14220

978178823b

Co-authored-by: Christian Brabandt <cb@256bit.org>
2024-03-22 06:04:37 +08:00
zeertzjq 774455dc37
vim-patch:9.1.0194: gcc complains about uninitialized var (#27970)
Problem:  gcc complains about uninitialized var
          (Tony Mechelynck)
Solution: initialize to NULL

9eb236f455

Co-authored-by: Christian Brabandt <cb@256bit.org>
2024-03-22 06:04:11 +08:00
Famiu Haque 1dde678757
refactor(misc): use MSVC compiler builtin for `xctz()`
Problem: `xctz()` uses a fallback algorithm for MSVC, even though a compiler builtin exists.

Solution: Make `xctz()` use the compiler builtin for MSVC compiler.
2024-03-22 01:43:53 +06:00
bfredl 8921d56053 fix(rpc): do not crash when no input is consumed
fixes #23781

Co-authored-by: glacambre <code@lacamb.re>
2024-03-21 15:52:28 +01:00
Famiu Haque 2214f9c19d
refactor(options): remove `set_string_option_direct()`
Problem: `set_string_option_direct()` contains a separate codepath specifically for setting string options. Not only is that unnecessary code duplication, but it's also limited to only string options.

Solution: Replace `set_string_option_direct()` with `set_option_direct()` which calls `set_option()` under the hood. This reduces code duplication and allows directly setting an option of any type.
2024-03-21 15:41:14 +06:00
Famiu Haque 5aa8c02a9d
refactor(options): add `direct` flag to `set_option()` 2024-03-21 15:41:14 +06:00
Famiu Haque 10ab135adf
refactor(options): restructure `set_option` 2024-03-21 15:21:01 +06:00
Evgeni Chasnovski 734848dc1a feat(colorscheme): add semantic tokens modifiers to builtin color scheme 2024-03-21 09:01:37 +01:00
zeertzjq c1c6c1ee12
vim-patch:9.1.0190: complete_info() returns wrong order of items (#27955)
Problem:  complete_info() returns wrong order of items
          (after v9.0.2018)
Solution: Revert Patch v9.0.2018
          (Girish Palya)

bug fix: complete_info() gives wrong results

1) complete_info() reverses list of items during <c-p>
2) 'selected' item index is wrong during <c-p>
3) number of items returnd can be wrong

Solution:
- Decouple 'cp_number' from 'selected' index since they need not be
  correlated
- Do not iterate the list backwards
- Add targeted tests

Regression introduced by 69fb5afb3b
Following are unnecessary commits to patch problems from above:
fef6630166
daef8c7437

All the tests from above commits are retained though.

fixes: vim/vim#14204
closes: vim/vim#14241

8950bf7f8b

Remove EMPTY_IF_NULL() as it has been unnecessary since #12673.

Co-authored-by: Girish Palya <girishji@gmail.com>
2024-03-21 07:50:12 +08:00
luukvbaal c72d877c33
fix(cmdline): wrong 'incsearch' highlighting after :redraw (#27947)
Problem:  Calling :redraw from a timer callback clears 'incsearch' highlighting.
Solution: Re-apply 'incsearch' highlighting if the screen was updated.
2024-03-20 21:59:04 +08:00
Justin M. Keyes 7549845e8d
Merge #27930 nvim_create_buf fixes 2024-03-20 06:15:38 -07:00
Lewis Russell 47388614cb refactor(treesitter): handle coverity warnings better 2024-03-20 12:22:54 +00:00
Lewis Russell 0f85aeb478 fix(treesitter): treecursor regression
- Also address some coverity warnings

Fixes #27942
2024-03-20 10:56:16 +00:00
Lewis Russell 597d4c63bd refactor(treesitter): reorder functions 2024-03-19 18:40:08 +00:00
Lewis Russell aca6c93002 refactor(treesitter): simplify argument checks for userdata 2024-03-19 16:16:54 +00:00
Sean Dewar 6091df6b7a
fix(api): nvim_create_buf assert fails if autocmds set &swapfile
Problem: assertion failure in nvim_create_buf if buflist_new autocommands open
a swapfile when "scratch" is set.

Solution: block autocommands when setting up the buffer; fire them later
instead.

Note that, unlike buflist_new, I don't check if autocommands aborted script
processing; the buffer is already created and configured at that point, so might
as well return the handle anyway.

Rather than repeat try_{start,end} and {un}block_autocmds for each relevant
operation, just do it at the start and near the end. This means that, if
TermResponse fires from unblock_autocmds for whatever reason, it can see the
buffer in an already configured state if we didn't bail due to an error (plus
it's probably a bit cleaner this way).
2024-03-19 16:13:52 +00:00
Sean Dewar d5c23d72a5
fix(api): nvim_create_buf leaks memory if buffer is loaded early
Problem: memory leak in nvim_create_buf if buflist_new autocommands load the
new buffer early.

Solution: do not open a memfile in that case.
2024-03-19 15:43:08 +00:00
Lewis Russell aca2048bcd refactor(treesitter): redesign query iterating
Problem:

  `TSNode:_rawquery()` is complicated, has known issues and the Lua and
  C code is awkwardly coupled (see logic with `active`).

Solution:

  - Add `TSQueryCursor` and `TSQueryMatch` bindings.
  - Replace `TSNode:_rawquery()` with `TSQueryCursor:next_capture()` and `TSQueryCursor:next_match()`
  - Do more stuff in Lua
  - API for `Query:iter_captures()` and `Query:iter_matches()` remains the same.
  - `treesitter.c` no longer contains any logic related to predicates.
  - Add `match_limit` option to `iter_matches()`. Default is still 256.
2024-03-19 14:24:59 +00:00
zeertzjq 16a416cb3c
fix(terminal): don't pass incomplete UTF-8 sequence to libvterm (#27922) 2024-03-19 16:56:51 +08:00
Christian Clason c30ebb17f6 fix(treesitter): document more standard highlight groups
Problem: Not all standard treesitter groups are documented.

Solution: Document them all (without relying on fallback); add default
link for new `*.builtin` groups to `Special` and `@keyword.type` to
`Structure`. Remove `@markup.environment.*` which only made sense for
LaTeX.
2024-03-19 09:41:16 +01:00
zeertzjq e3bd04f2af
fix(pager): handle consecutive newlines properly (#27913) 2024-03-18 22:25:55 +08:00
zeertzjq 66945e11b3
refactor(messages): remove condition that is always true (#27909)
After #25470 the `s` pointer is advanced before calling store_sb_text()
when a newline character is found, and store_sb_text() sets `sb_str` to
`s`, so it's not possible for `s == sb_str + 1` and `*sb_str == '\n'` to
be satisfied at the same time.
2024-03-18 19:01:01 +08:00
zeertzjq 9d315fb8b7
vim-patch:9.1.0186: cursor pos wrong on mouse click after eol with 'rl', 've' and conceal (#27903)
Problem:  Wrong cursor position when clicking after end of line with
          'rightleft', 'virtualedit' and conceal.
Solution: Set values in ScreenCols[] also with SLF_RIGHTLEFT.  Also fix
          off-by-one cursor position with 'colorcolumn' (zeertzjq).

closes: vim/vim#14218

deb2204bff
2024-03-18 10:35:41 +08:00
zeertzjq eabf9de1dc
fix(messages): allow more prompt in headless mode with UI (#27905)
Problem:  More prompt is not shown in headless mode even if there is a
          UI attached.
Solution: Don't skip more prompt when there is a UI active.
2024-03-18 10:34:27 +08:00
zeertzjq 091eb4c8c7
fix(mouse): click after eol with conceal and virtual text (#27897)
Problem:  Wrong cursor position when clicking after end of line with
          'virtualedit', conceal and virtual text.
Solution: Always fill linebuf_vcol[] for the columns to clear.
2024-03-17 17:54:18 +08:00
zeertzjq 54db75e995
refactor(drawline): integrate terminal hl with eol loop (#27893)
There is no test for using 'cursorline' in Normal mode in a terminal
buffer, so add a test and fix 'cursorcolumn' remaining when entering
Terminal mode.

Also move synIDattr() tests to ui/highlight_spec.lua.
2024-03-17 17:24:03 +08:00
zeertzjq c52dfb6e84
fix(normal): don't check conceal when pressing 'r' (#27892)
Problem:  Cursor line is unconcealed when pressing 'r' in Normal mode
          when 'concealcursor' contains 'n' but not 'i'.
Solution: Don't check conceal when pressing 'r' in Normal mode.

Vim doesn't have this problem because it doesn't call redrawWinline() in
conceal_check_cursor_line() and instead sets a global variable.
2024-03-17 09:44:10 +08:00
zeertzjq d114dbe9f7
vim-patch:9.1.0184: Cursor pos wrong when clicking with conceal and wrap (#27890)
Problem:  Cursor position wrong when clicking with conceal and wrap.
Solution: Use the virtual column of the last char for ScreenCols[] in
          boguscols.  Remove use of MAXCOL in ScreenCols[].  Rename
          third argument of wlv_screen_line() to "clear_end" as that's
          clearer what it does (zeertzjq).

related: 14192
closes: vim/vim#14200

d0c1b7723f

Rename win_put_linebuf() to wlv_put_linebuf().
2024-03-17 07:26:39 +08:00
zeertzjq 34b57508a7
fix(drawline): check filler_todo in place of removed draw_state (#27889)
The only place it matters is the conceal wcol check, but it can avoid
unnecessary computations at other places.
2024-03-17 05:43:14 +08:00
Caleb Marshall 542c910a1d fix(lsp): add missing LSP semantic token highlight links
Added the following LSP semantic token types to be linked to highlight
groups by default:

* @lsp.type.event
* @lsp.type.keyword
* @lsp.type.modifier
* @lsp.type.number
* @lsp.type.operator
* @lsp.type.regexp
* @lsp.type.string
2024-03-16 20:37:56 +08:00
zeertzjq ee89ba1d75
vim-patch:9.1.0182: Can define function with invalid name inside 'formatexpr' (#27883)
Problem:  Can define function with invalid name inside 'formatexpr'.
Solution: Use goto instead of checking for did_emsg later.
          (zeertzjq)

closes: vim/vim#14209

6a04bf5ee5
2024-03-16 17:26:14 +08:00
zeertzjq c0daea3afd
vim-patch:9.1.0183: Wrong display or screenpos() result when toggling diff mode (#27882)
Problem:  Wrong display or screenpos() result when toggling diff mode.
Solution: Reset w_skipcol when disabling 'wrap'.  Reset w_leftcol when
          enabling 'wrap' (zeertzjq).

fixes: vim/vim#14210
closes: vim/vim#14211

9e7f1fc2f1
2024-03-16 17:10:20 +08:00
zeertzjq ead3a1bd7a
vim-patch:8.2.3782: Vim9: no error if a function shadows a script variable (#27881)
Problem:    Vim9: no error if a function shadows a script variable.
Solution:   Check the function doesn't shadow a variable. (closes vim/vim#9310)

052ff291d7

Omit EVAL_VAR_NO_FUNC: Vim9 script only.

Co-authored-by: Bram Moolenaar <Bram@vim.org>
2024-03-16 17:05:59 +08:00
bfredl 9c2fdfe6e7
Merge pull request #27877 from bfredl/pseudorandom
fix(intro): redrawing intro exposing pseudo-randomness
2024-03-16 09:32:52 +01:00
bfredl d1a30221fc fix(intro): redrawing intro exposing pseudo-randomness
problem:  redrawing intro exposes pseudo-randomness
solution: remove pseudo-randomness
2024-03-16 08:40:45 +01:00
bfredl c0549b9c47
Merge pull request #27871 from bfredl/ui_flush_fix
fix(ui): edge case around flushing in grid_line
2024-03-16 08:36:37 +01:00
ite-usagi 4447cefa48
fix(l10n): update Japanese translations (#27856) 2024-03-16 14:50:52 +08:00
bfredl b7779c5146
Merge pull request #27867 from bfredl/intro_multigrid
fix(ui): startup intro message should be visible with ext_multigrid
2024-03-15 13:27:58 +01:00
bfredl e0707d3529 fix(ui): fix edge case around flushing
ui_flush_buf() doesn't know about `lenpos` so `remote_ui_raw_line`
needs to always handle it before flushing
2024-03-15 12:07:04 +01:00
bfredl f1c9228bba
Merge pull request #27858 from luukvbaal/nvim_set_cursor
fix(ui): issues controlling cursor position with ext_cmdline
2024-03-15 10:02:26 +01:00
bfredl a8522f02e9 fix(ui): startup intro message should be visible with ext_multigrid
As this message is literally drawn on top of the EOB area of the first
window, the simple solution is to just draw the message on top of the
grid of the first window.

We still want #24764 (msg_intro event) but now only for ext_messages.
2024-03-15 09:48:31 +01:00
Luuk van Baal d41b8d4758 fix(ui): ext_cmdline should not move cursor to curwin
Problem:  The ext_cmdline cursor position on the screen seems to rely on
          an implicit assumption that the event listener implements a
          cmdline window that is made the current window which is
          problematic (e.g. breaks 'incsearch' in the actual current
          window).
Solution: Remove this assumption and allow nvim_win_set_cursor() to move
          the cursor on the screen to a non-current window (previous
          commit).
2024-03-15 09:15:56 +01:00
Luuk van Baal c971f538ab fix(api): update grid cursor in nvim_win_set_cursor()
Problem:  Cursor position set by nvim_win_set_cursor() is not reflected
          on the screen when followed by a blocking call like getchar().
Solution: Immediately update the cursor position on the grid.
2024-03-15 09:15:50 +01:00
zeertzjq 062c0245e3
refactor: remove unused "coloff" argument of win_put_linebuf() (#27866)
It isn't really used, and is always passed 0.
Also rename "start_col" to "startcol" for consistency with "endcol".
2024-03-15 14:45:58 +08:00
zeertzjq d326e04860
vim-patch:9.1.0181: no overflow check for string formatting (#27863)
Problem:  no overflow check for string formatting
Solution: Check message formatting function for overflow.
          (Chris van Willegen)

closes: vim/vim#13799

c35fc03dbd

Co-authored-by: Christ van Willegen <cvwillegen@gmail.com>
2024-03-15 08:05:59 +08:00
zeertzjq 60491466f9
vim-patch:9.1.0180: Cursor pos wrong when double-width chars are concealed (#27862)
Problem:  Cursor pos wrong when double-width chars are concealed.
Solution: Advance one more virtual column for a double-width char.
          Run some tests with both 'wrap' and 'nowrap' (zeertzjq).

closes: vim/vim#14197

010e1539d6
2024-03-15 06:56:45 +08:00
zeertzjq ca7dd33fa7
fix(highlight): don't show CursorColumn on current line (#27848)
Problem:
CursorColumn highlight behavior is inconsistent with 'virtualedit' set:
- If cursor is on the text, CursorColumn is not shown.
- If cursor is after end of line, CursorColumn is shown.

Solution:
Don't shown CursorColumn on current line if cursor is after end of line.

Vim doesn't have this problem because in most cases it uses the code
path for drawing buffer text when CursorColumn highlight is needed.
2024-03-15 05:54:22 +08:00
bfredl 4de4f13eb3
Merge pull request #27852 from bfredl/persistent_intro
fix(intro): make intro explicitly stateful
2024-03-14 20:00:07 +01:00
bfredl 0570a19c8a fix(intro): make intro explicitly stateful
Instead of randomly disappearing because some random event might have
caused mid_start or bot_scroll_start to randomly take a low value, treat
intro message as a _first class stateful_ thing.

This means that intro message will kept being _redrawn_ as long as we
are in the state it should be shown. This also includes screen resizes.
you will not lose the intro message because there was a delay in
detecting terminal features.
2024-03-14 14:39:08 +01:00
zeertzjq a6b6d036b1
refactor(drawline): rename vcol_off to vcol_off_co (#27857)
It is clearing that it's for conceal and matches the change from Vim
patch 9.0.1325.
Also correct some comments related to fix_for_boguscols().
2024-03-14 19:33:14 +08:00
bfredl cdd0788c70
Merge pull request #27854 from bfredl/boogalo_lines
fix(api): fix set_lines viewport adjustment, but this time good
2024-03-14 12:24:33 +01:00
Christian Clason 120c4ec855 fix(terminal): disable reflow again
reverts c855eee919

This setting introduces constant CI failures on macos
(see https://github.com/neovim/neovim/issues/23762).
2024-03-14 19:22:16 +08:00
bfredl fc2a56fe61 fix(api): fix set_lines viewport adjustment, but this time good
fixes #27720
2024-03-14 10:56:24 +01:00
zeertzjq 61b48e91b9 vim-patch:9.1.0177: Coverity reports dead code
Problem:  Coverity reports dead code.
Solution: Remove the dead code. Also fix a mistake in ml_get_pos_len()
          and update some comments (zeertzjq).

closes: vim/vim#14189

8c55d60658
2024-03-14 13:09:57 +08:00
zeertzjq 090d1fd0b8 vim-patch:9.1.0172: More code can use ml_get_buf_len() instead of STRLEN()
Problem:  More code can use ml_get_buf_len() instead of STRLEN().
Solution: Change more STRLEN() calls to ml_get_buf_len().  Also do not
          set ml_line_textlen in ml_replace_len() if "has_props" is set,
          because "len_arg" also includes the size of text properties in
          that case. (zeertzjq)

closes: vim/vim#14183

94b7c3233e
2024-03-14 13:09:54 +08:00
zeertzjq 3502aa63f0
vim-patch:8.2.4950: text properties position wrong after shifting text (#27849)
Problem:    Text properties position wrong after shifting text.
Solution:   Adjust the text properties when shifting a block of text.
            (closes vim/vim#10418)

4b93674159

Most of the patch is already merged. Add an assertion in place of "added".

Co-authored-by: LemonBoy <thatlemon@gmail.com>
2024-03-14 12:40:17 +08:00
zeertzjq 2af1dc0116 vim-patch:9.1.0176: Cursor column wrong with 'virtualedit' and conceal
Problem:  Cursor column wrong with 'virtualedit' and conceal.
Solution: Correct cursor column at end of line if never reached.
          (zeertzjq)

closes: vim/vim#14190

253ff4dece
2024-03-14 06:55:10 +08:00
zeertzjq 9599e5d28d vim-patch:9.1.0174: 'cursorline' and 'wincolor' hl missing with conceal and wrap
Problem:  'cursorline' and 'wincolor' highlight missing with concealed and
          wrapped lines.
Solution: Apply 'cursorline' and 'wincolor' highlight to boguscols.
          (zeertzjq)

Since 'cursorline' and 'wincolor' highlight apply after the end of the
line, it is more consistent to have them also apply to boguscols.

Assigning MAXCOL to values in ScreenCols[] make mouse click behave the
same with 'cursorline' and 'nocursorline', but such behavior may be
incorrect, as it puts the cursor on the next screen line.  That may be
fixed in a future PR.

closes: vim/vim#14192

21b0a3df8c
2024-03-14 06:55:08 +08:00
zeertzjq b17be231a6
vim-patch:9.1.0178: E1513 might be confusing (#27846)
Problem:  E1513 might be confusing
          (Christoph Thoma)
Solution: reword error message, fix test to not
          depend on the actual message

fixes: vim/vim#14189

0a32b8854b

Co-authored-by: Christian Brabandt <cb@256bit.org>
2024-03-14 06:44:50 +08:00
Sean Dewar bbb68e2a03
vim-patch:9.1.0175: wrong window positions with 'winfix{width,height}' (#27845)
Problem:  winframe functions incorrectly recompute window positions if
          the altframe wasn't adjacent to the closed frame, which is
          possible if adjacent windows had 'winfix{width,height}' set.

Solution: recompute for windows within the parent of the altframe and
          closed frame. Skip this (as before) if the altframe was
          top/left, but only if adjacent to the closed frame, as
          positions won't change in that case. Also correct the return
          value documentation for win_screenpos. (Sean Dewar)

The issue revealed itself after removing the win_comp_pos call below
winframe_restore in win_splitmove. Similarly, wrong positions could result from
windows closed in other tabpages, as win_free_mem uses winframe_remove (at least
until it is entered later, where enter_tabpage calls win_comp_pos).

NOTE: As win_comp_pos handles only curtab, it's possible via other means for
positions in non-current tabpages to be wrong (e.g: after changing 'laststatus',
'showtabline', etc.). Given enter_tabpage recomputes it, maybe it's intentional
as an optimization? Should probably be documented in win_screenpos then, but I
won't address that here.

closes: vim/vim#14191

Nvim: don't reuse "wp" for "topleft" in winframe_remove, so the change
integrates better with the call to winframe_find_altwin before it.

5866bc3a0f
2024-03-13 22:06:39 +00:00
bfredl 08fc1ebbaa fix(api/buffer): fix handling of viewport of non-current buffer
A lot of functions in move.c only worked for curwin, alternatively
took a `wp` arg but still only work if that happens to be curwin.

Refactor those that are needed for update_topline(wp) to work
for any window.

fixes #27723
fixes #27720
2024-03-13 07:19:59 +01:00
zeertzjq d5488633f6
fix(drawline): initialize linebuf_attr to 0 instead of -1 (#27840)
This also obviates the end-of-line loop when there is virtual text.
2024-03-13 11:36:41 +08:00
zeertzjq 93c93a0e36
refactor: remove "once" argument of loop_uv_run() (#27841)
It is always set to true when used, and makes the code a bit confusing.
2024-03-13 11:27:04 +08:00
Sean Dewar c048beef6c
vim-patch:9a660d2883f9
runtime(doc): add reference to matchbufline() at :h search()

related: vim/vim#14173

9a660d2883

Co-authored-by: Christian Brabandt <cb@256bit.org>
2024-03-12 21:42:47 +00:00
Sean Dewar 6bbb02d9ba
vim-patch:9.1.0171: Small split-move related improvements
Problem:  small improvements can be made to split-move related
          functions.
Solution: apply them (Sean Dewar):

Some of these changes were already applied to Nvim.
Here are the ones which were missing:

- Improve some doc comments (frame_flatten should still work for non-current
  tabpages, despite the topframe check, which looks benign, though I'm unsure if
  it's still needed; see vim/vim#2467).

- f_win_splitmove should check_split_disallowed on wp, not targetwin, as that's
  what win_splitmove checks (though it's probably unnecessary to check
  b_locked_split at all; see vim/vim#14109, which I hope to get around to
  finishing at some point).

- Apply the winframe_restore comment changes, and remove win_comp_pos from after
  winframe_restore in win_splitmove, as it shouldn't be necessary (no need to
  remove it from nvim_win_set_config too, as it was already omitted).
  Move win_append after winframe_restore in win_splitmove to match Vim.

closes: vim/vim#14185

5cac1a9bee
2024-03-12 21:38:39 +00:00
Sean Dewar ca7b603d02
vim-patch:9.1.0170: Re-allow curwin == prevwin, but document it instead
Problem:  more places exist where curwin == prevwin, and it may even be
          expected in some cases.
Solution: revert v9.1.0001, but document that it's possible instead.
          (Sean Dewar)

I've had a change of heart for the following reasons:

- A quick 'n dirty [GitHub code search](https://github.com/search?q=%2F%28winnr%5C%28%5C%29%5Cs*%3D%3D%5Cs*winnr%5C%28%5B%27%22%5D%23%5B%27%22%5D%5C%29%7Cwinnr%5C%28%5B%27%22%5D%23%5B%27%22%5D%5C%29%5Cs*%3D%3D%5Cs*winnr%5C%28%5C%29%29%2F&type=code)
  reveals some cases where it's expected in the wild.

  Particularly, it made me aware `winnr() == winnr('#')` is possible when curwin
  is changed temporarily during the evaluation of a &statusline expression item
  (`%{...}`), and is used to show something different on the statusline
  belonging to the previous window; that behaviour wasn't changed in v9.1.0001,
  but it means curwin == prevwin makes sense in some cases.

- The definition and call sites of back_to_prevwin imply some expectation that
  prevwin == wp (== curwin) is possible, as it's used to skip entering the
  prevwin in that case.

- Prior to v9.1.0001, `:wincmd p` would not beep in the case that was patched in
  v9.1.0001, but now does. That resulted in vim/vim#14047 being opened, as it affected
  the CtrlP plugin.

  I find it odd that `:wincmd p` had cases where it wouldn't beep despite doing
  nothing, but it may be preferable to keep things that way (or instead also
  beep if curwin == prevwin, if that's preferred).

- After more digging, I found cases in win_free_mem, enter_tabpage,
  aucmd_restbuf and qf_open_new_cwindow where curwin == prevwin is possible
  (many of them from autocommands). Others probably exist too, especially in
  places where curwin is changed temporarily.

fixes: vim/vim#14047
closes: vim/vim#14186

d64801e913
2024-03-12 21:14:40 +00:00
Sean Dewar 29d0ed577c
vim-patch:9.1.0169: current window number returned by tabpagewinnr may be outdated
Problem:  current window number returned by tabpagewinnr may be outdated
          when called from win_execute for the original tabpage.
Solution: update the original tabpage's tp_curwin in switch_win; use
          {un}use_tabpage instead. Don't do it in restore_win to ensure
          tp_curwin of the temporarily visited tabpage is unchanged from
          switch_win visiting it, as before. (Sean Dewar)

Maybe restore_win should only restore tp_curwin if
`curtab == switchwin->sw_curtab`, in case the user changed tabpages from within
win_execute, but not doing that is consistent with the old behaviour.

related: vim/vim#14186

e101028a5c
2024-03-12 21:05:54 +00:00
James 119390e7ce
refactor: avoid copying before vim_strup() if possible (#27830)
Current uses of vim_strup() calls memcpy()/strcpy() before calling vim_strup().
This results in 2 * strlen(string) operations.

We can trivially convert to lowercase while copying the string instead.
2024-03-13 04:34:59 +08:00
James McCoy dd0fc73bbe
Merge pull request #27808 from jamessan/gen_cflags-cleanup
Cleanup construction of command-lines for header generation
2024-03-12 14:00:29 -04:00
James 3bd84317fb
refactor: avoid quadratic behavior in backslash_halve() (#27827)
The original implementation has a worst-case of O(n^2). Every time
rem_backslash() is true, it calculates the length of the rest of the
string, and shift the rest of it to the left; backslash_halve_save()
copies the original string before doing backslash_halve().

The new implementation is O(n). It will find the first character where
rem_backslash() is true (it will do nothing if it's always false), and
shift the characters in-place; backslash_halve_save() avoids copying the
original string before doing backslash_halve().
2024-03-12 14:35:53 +08:00
dundargoc a74e869ffa
docs: small fixes (#27364)
Co-authored-by: C.D. MacEachern <craig.daniel.maceachern@gmail.com>
Co-authored-by: Ynda Jas <yndajas@gmail.com>
Co-authored-by: Owen Hines <TheOdd@users.noreply.github.com>
Co-authored-by: Wanten <41904684+WantenMN@users.noreply.github.com>
Co-authored-by: lukasvrenner <118417051+lukasvrenner@users.noreply.github.com>
Co-authored-by: cuinix <915115094@qq.com>
2024-03-12 13:51:53 +08:00
zeertzjq ac8cd5368d
refactor: use ml_get_buf_len() in API code (#27825) 2024-03-12 10:44:53 +08:00
zeertzjq b02a4d8ac3
vim-patch:9.1.0168: too many STRLEN() calls (#27823)
Problem:  too many STRLEN() calls
Solution: Make use of ml_get_len() calls instead
          (John Marriott)

closes: vim/vim#14123

bfcc895482

Co-authored-by: John Marriott <basilisk@internode.on.net>
2024-03-12 07:20:22 +08:00
zeertzjq 6481da3015
vim-patch:9.1.0166: Internal error with blockwise getregion() in another buffer (#27819)
Problem:  Internal error with blockwise getregion() in another buffer
Solution: Also change curwin->w_buffer when changing curbuf (zeertzjq)

closes: vim/vim#14179

5406eb8722
2024-03-12 07:19:30 +08:00
zeertzjq cf156377e8
vim-patch:8.2.4944: text properties are wrong after "cc" (#27821)
Problem:    Text properties are wrong after "cc". (Axel Forsman)
Solution:   Pass the deleted byte count to inserted_bytes(). (closes vim/vim#10412,
            closes vim/vim#7737, closes vim/vim#5763)

d0b1a09f44

Co-authored-by: LemonBoy <thatlemon@gmail.com>
2024-03-12 06:56:06 +08:00
zeertzjq 9cc755ad6a
vim-patch:0049a495c8d4 (#27817)
runtime(doc): improve 'winfixbuf' docs (vim/vim#14180)

- Make it not sound like a buffer option.
- "!" is called a modifier, not an option.

0049a495c8
2024-03-12 05:39:21 +08:00
Luuk van Baal b72931e704 feat(ui): allow non-zero 'cmdheight' with ext_messages
Problem:  Arbitrary restriction on 'cmdheight' with ext_messages.
          The 'cmdheight'-area may be desirable for the replacing
          cmdline.
Solution: Allow non-zero 'cmdheight' with ext_messages.
2024-03-11 07:13:48 +01:00
zeertzjq 3b3511c4d9 vim-patch:9.1.0156: Make 'wfb' failing to split still report E1513
Problem:  may not be clear why failing to split causes an ":Xdo" command
          to abort if 'wfb' is set.
Solution: do not return immediately if win_split fails, so E1513 is
          still given. Expect both errors in the test. Also fix tests to
          pass CI.
          (Sean Dewar)

closes: vim/vim#14152

769eb2d0c3

Co-authored-by: Sean Dewar <6256228+seandewar@users.noreply.github.com>
2024-03-11 11:42:03 +08:00
zeertzjq d71791a11a vim-patch:9.1.0152: Coverity complains about ignoring return value
Problem:  Coverity complains about ignoring return value of win_split()
          (after v9.1.150)
Solution: Check if win_split() failed, add winfixbuf.res to Makefile

af7ae81600

Co-authored-by: Christian Brabandt <cb@256bit.org>
2024-03-11 11:38:15 +08:00
Colin Kennedy 5931f2bc4a vim-patch:9.1.0150: Several minor 'winfixbuf' issues
Problem:  several minor 'winfixbuf' issues exist, mostly relating to the
          quickfix list
Solution: address them and adjust tests. Retab and reflow a few things too.
          (Sean Dewar)

Things touched include:

- Replace the semsgs with gettext'd emsgs.

- Handle window switching in ex_listdo properly, so curbuf and curwin
  are kept in-sync and trigger autocommands; handle those properly.

- Don't change the list entry index in qf_jump_edit_buffer if we fail
  due to 'wfb' (achieved by returning FAIL; QF_ABORT should only be used
  if the list was changed).

- Make qf_jump_edit_buffer actually switch to prevwin when using `:cXX`
  commands **outside** of the list window if 'wfb' is set in curwin.
  Handle autocommands properly in case they mess with the list.

  NOTE: previously, it seemed to split if 'wfb' was set, but do nothing
  and fail if prevwin is *valid*. This behaviour seemed strange, and maybe
  unintentional? Now it aligns more with what's described for the `:cXX`
  commands in the original PR description when used outside a list window,
  I think.

- In both functions, only consider prevwin if 'wfb' isn't set for it;
  fallback to splitting otherwise.

- Use win_split to split. Not sure if there was a specific reason for
  using ex_splitview. win_split is simpler and respects modifiers like
  :vertical that may have been used. Plus, its return value can be checked
  for setting opened_window in qf code (technically win_split_ins autocmds
  could immediately close it or change windows, in which the qf code might
  close some other window on failure; it's already the case elsewhere,
  though).

closes: vim/vim#14142

4bb505e28c

Co-authored-by: Sean Dewar <6256228+seandewar@users.noreply.github.com>
2024-03-11 11:38:15 +08:00
Colin Kennedy e8bc23db62 vim-patch:9.1.0149: null pointer member access when accessing 'winfixbuf' property
Problem:  qf_goto_win_with_qfl_file may check if prevwin has 'winfixbuf'
          set without checking if it's valid first.
Solution: Reverse the condition. Add a test, a modeline, and a missing
          CheckFeature. (Searn Dewar)

closes: vim/vim#14140

5131f224da

Co-authored-by: Sean Dewar <6256228+seandewar@users.noreply.github.com>
2024-03-11 11:38:15 +08:00
Colin Kennedy 141182d6c6 vim-patch:9.1.0147: Cannot keep a buffer focused in a window
Problem:  Cannot keep a buffer focused in a window
          (Amit Levy)
Solution: Add the 'winfixbuf' window-local option
          (Colin Kennedy)

fixes:  vim/vim#6445
closes: vim/vim#13903

2157035637

N/A patch:
vim-patch:58f1e5c0893a
2024-03-11 11:38:13 +08:00
James McCoy 118fd8367c
fix: deduplicate gen_cflags
Since many of the targets have common include paths, `gen_cflags`
accumulates a lot of duplicate flags.
2024-03-10 20:02:32 -04:00
James McCoy 74b2f6c3d9
fix: ignore non-existent properties during header generation
`get_target_property(<var> ...)` sets `<var>` to `<var>-NOTFOUND` if the
property doesn't exist for the given target.  Detect this situation to
avoid adding various `-Dprop-NOTFOUND` and `-Iprop-NOTFOUND` to the
command-line when generating the headers.
2024-03-10 19:58:35 -04:00
zeertzjq 92d4dbbd8c
vim-patch:9.1.0164: Internal error when passing invalid position to getregion() (#27805)
Problem:  Internal error or crash when passing invalid position to
          getregion().
Solution: Give an error for invalid position (zeertzjq).

closes: vim/vim#14172

26dd09ad5e
2024-03-11 06:21:32 +08:00
zeertzjq b465ede2c7
vim-patch:9.1.0138: too many STRLEN calls when getting a memline (#27799)
Problem:  too many STRLEN calls when getting a memline
Solution: Optimize calls to STRLEN(), add a few functions in memline.c
          that return the byte length instead of relying on STRLEN()
          (John Marriott)

closes: vim/vim#14052

02d7a6c6cf

Cherry-pick line break changes from patch 8.1.0226.
Cherry-pick ml_line_len from patch 8.1.0579.
Cherry-pick test_comments.vim change from patch 9.1.0153.

Co-authored-by: John Marriott <basilisk@internode.on.net>
2024-03-10 17:08:00 +08:00
zeertzjq a441bdc936
vim-patch:9.1.0162: problem with writing extended attributes on failure (#27800)
Problem:  problem with writing extended attributes on failure
Solution: Change return type to ssize_t and check listxattr's return
          value correctly on failure (Paul Tagliamonte)

The existing logic will return when the listxattr call returns with the
errno set to ENOTSUP (or a size of 0 bytes), without checking to see if
listxattr actually failed. listxattr can fail with at least E2BIG,
ENOTSUP, ERANGE, or anything that `stat(2)` can fail with (in my case;
ENOENT from stat).

The returned size is stored to a size_t, but the return type is a
ssize_t. On failure, listxattr returns -1, which will get translated to
size_t's MAX. If the listxattr call failed with anything other than
ENOTSUP, this triggers a request for size_t MAX bytes.

This means that, if the listxattr call fails with anything other than
ENOTSUP on save, vim will error with

`E342: Out of memory!  (allocating 18446744073709551615 bytes)`

(keen observers will note 18446744073709551615 is 0xffffffffffffffff)

In reality, this is likely masking a different (usually filesystem?)
error -- but at least it's an error being pushed to the user now, and we
don't try to allocate size_t MAX bytes.

I've opted to change the type that we store listxattr to from size_t to
ssize_t, to match listxattr(2)'s signature, and to check for the -1
return value. Additionally, I've removed the errno check -- if we get a
listxattr failure for any reason, we may as well bail without trying;
it's not like we can even recover.

closes: vim/vim#14169

14759ded57

Co-authored-by: Paul R. Tagliamonte <paultag@gmail.com>
2024-03-10 16:58:01 +08:00
zeertzjq 6052b346f1
revert: "fix(window): :close crash with autocmd, floats and tabpage" (#27796)
This reverts PR #27793.

On second thought, this solution may still crash, because it can leave a
window with a NULL buffer if there are autocommand windows or if closing
a floating window fails. It also makes close_last_window_tabpage() more
complicated, so revert it.
2024-03-10 10:33:10 +08:00
zeertzjq 9bd4a28079
fix(window): :close crash if WinClosed from float closes window (#27794)
Problem:  :close crash if WinClosed from float closes window.
Solution: Check if window has already been closed.
2024-03-10 08:37:16 +08:00
zeertzjq 731e7f51ee
fix(window): :close crash with autocmd, floats and tabpage (#27793)
Problem:  :close crash with autocmd, floats and tabpage.
Solution: Close floating windows in one more case.
2024-03-10 07:55:04 +08:00
zeertzjq 448cf10c47
vim-patch:9.1.0159: Crash in WinClosed after BufUnload closes other windows (#27792)
Problem:  Crash in WinClosed after BufUnload closes other windows
Solution: Don't trigger WinClosed if the buffer is NULL (zeertzjq)

Now win_close_othertab() doesn't trigger any autocommands if the buffer
is NULL, so remove the autocmd blocking above (which was added not long
ago in patch v9.0.0550) for consistency.

Also remove an unreachable close_last_window_tabpage() above:
- It is only reached if only_one_window() returns TRUE and last_window()
  returns FALSE.
- If only_one_window() returns TRUE, there is only one tabpage.
- If there is only one tabpage and last_window() returns FALSE, the
  one_window() in last_window() must return FALSE, and the ONE_WINDOW
  in close_last_window_tabpage() must also be FALSE.
- So close_last_window_tabpage() doesn't do anything and returns FALSE.

Then the curtab != prev_curtab check also doesn't make much sense, and
the only_one_window() can be replaced with a check for popup and a call
to last_window() since this is a stricter check than only_one_window().

closes: vim/vim#14166

b2ec0da080
2024-03-10 07:03:36 +08:00
zeertzjq 241c161299
vim-patch:9.1.0161: expand() removes slash after env variable that ends with colon (#27791)
Problem:  expand() removes a slash after an environment variable that
          ends with a colon on Windows.
Solution: Check the correct char for a colon (zeertzjq)

closes: vim/vim#14161

Note: Vim still removes the path-separator at the end, if another path separator
follows directly after it, e.g. on:

```
    echo $FOO='/usr/'
    echo expand('$FOO/bar') == '/usr/bar'
```

see:

,----[ misc1.c:1630 ]
|   // if var[] ends in a path separator and tail[] starts
|   // with it, skip a character
|   if (after_pathsep(dst, dst + c)
| #if defined(BACKSLASH_IN_FILENAME) || defined(AMIGA)
| 	  && (dst == save_dst || dst[-1] != ':')
| #endif
| 	  && vim_ispathsep(*tail))
|       ++tail;
`----

13a014452a

Cherry-pick test_expand.vim change from patch 9.0.1257.
2024-03-10 06:47:09 +08:00
Sean Dewar b596732831
Merge pull request #27330 from seandewar/win_set_config-fixes
fix(api): various window-related function fixes

This is a big one!
2024-03-09 22:32:20 +00:00
Sean Dewar c3d22d32ee
vim-patch:8.2.3862: crash on exit with EXITFREE and using win_execute()
Problem:    Crash on exit with EXITFREE and using win_execute().
Solution:   Also save and restore tp_topframe. (issue vim/vim#9374)

dab17a0689

Couldn't repro the crash in the test, but I only care about this patch so
switch_win sets topframe properly for win_split_ins in nvim_open_win and
nvim_win_set_config.
Add a test using nvim_win_call and :wincmd, as I couldn't repro the issue via
nvim_open_win or nvim_win_set_config (though it's clear they're affected by this
patch).

That said, at that point, could just use {un}use_tabpage inside switch_win
instead, which also updates tp_curwin (though maybe continue to not set it in
restore_win). That would also fix possible inconsistent behaviour such as:

:call win_execute(w, "let curwin_nr1 = tabpagewinnr(1)")
:let curwin_nr2 = tabpagewinnr(1)

Where it's possible for curwin_nr1 != curwin_nr2 if these commands are run from
the 1st tabpage, but window "w" is in the 2nd (as the 1st tabpage's tp_curwin
may still be invalid). I'll probably PR a fix for that later in Vim.

Co-authored-by: Bram Moolenaar <Bram@vim.org>
2024-03-09 21:58:30 +00:00
Sean Dewar b52d15853e
fix(api): win_set_config set tp_curwin of win moved from other tabpage
Problem: nvim_win_set_config does not update the tp_curwin of win's original
tabpage when moving it to another.

Solution: update it if win was the tp_curwin. Add a test.
2024-03-09 18:00:30 +00:00
Lewis Russell ade1b12f49 docs: support inline markdown
- Tags are now created with `[tag]()`
- References are now created with `[tag]`
- Code spans are no longer wrapped
2024-03-09 11:21:55 +00:00
Raphael 0e28493914
vim-patch:8.2.3915: illegal memory access when completing with invalid bytes (#27491)
Problem:    illegal memory access when completing with invalid bytes.
Solution:   Avoid going over the end of the completion text.

vim/vim@4b28ba3

Co-authored-by: Bram Moolenaar <Bram@vim.org>
2024-03-09 19:21:31 +08:00
glepnir b21d960119 fix(startup): set full_screen when in ex_mode
Problem Description: In ex_mode, the default_grid.chars are not allocated, and subsequently,
the w_grid.target in curwin is not allocated to default_grid in update_screen. This leads to
a null pointer crash when the completion function is executed in ex_mode.

Solution: Set full_screen when in ex_mode to ensure that default_grid is allocated.
2024-03-09 18:20:59 +08:00
zeertzjq 33dfb5a383 fix(window): :close may cause Nvim to quit with autocmd and float
Problem:  :close may cause Nvim to quit if an autocommand triggered when
          closing the buffer closes all other non-floating windows and
          there are floating windows.
Solution: Correct the check for the only non-floating window.
2024-03-09 13:38:32 +08:00
Sean Dewar 54022a2946
fix(api): win_set_config update statuslines after removing splits
Problem: nvim_win_set_config does not update statuslines after removing a split.

Solution: call last_status.

Didn't realize this was missing in the original nvim_win_set_config for splits
PR.

As it can only be done for the current tabpage, do it if win_tp == curtab;
enter_tabpage will eventually call last_status anyway when the user enters
another tabpage.
2024-03-09 01:00:33 +00:00
Sean Dewar e7c262f555
fix(api): patch some cmdwin/textlock holes
Problem: there are new ways to escape textlock or break the cmdwin in
nvim_win_set_config and nvim_tabpage_set_win.

Solution: fix them. Use win_goto to check it in nvim_tabpage_set_win and use the
try_start/end pattern like with similar functions such as nvim_set_current_win
(which uses the existing msg_list, if set).

Careful not to use `wp->handle` when printing the window ID in the error message
for nvim_tabpage_set_win, as win_goto autocommands may have freed the window.

On a related note, I have a feeling some API functions ought to be checking
curbuf_locked...
2024-03-08 23:24:06 +00:00
Sean Dewar d942c2b943
fix(api): handle win_split_ins failure properly
Problem: nvim_win_set_config does not handle failure in win_split_ins properly
yet, which can cause all sorts of issues. Also nvim_open_win and
nvim_win_set_config do not set the error message to the one from win_split_ins.

Solution: handle failure by undoing winframe_remove, like in win_splitmove.
Make sure autocommands from switching to the altwin fire within a valid window,
and ensure they don't screw things up. Set the error message to that of
win_split_ins, if any.

Also change a few other small things, including:

- adjust win_append to take a tabpage_T * argument, which is more consistent
  with win_remove (and also allows us to undo a call to win_remove).

- allow winframe_restore to restore window positions. Useful if `wp` was in a
  different tabpage, as a call to win_comp_pos (which only works for the current
  tabpage) after winframe_restore should no longer be needed.

  Though enter_tabpage calls win_comp_pos anyway, this has the advantage of
  ensuring w_winrow/col remains accurate even before entering the tabpage
  (useful for stuff like win_screenpos, if used on a window in another tabpage).

  (This change should probably also be PR'd to Vim later, even though it doesn't
  use winframe_restore for a `wp` in a different tabpage yet).
2024-03-08 23:24:05 +00:00
Sean Dewar 832bc5c169
vim-patch:9.1.0130: [security]: UAF if win_split_ins autocommands delete "wp"
Problem:  heap-use-after-free in win_splitmove if Enter/Leave
          autocommands from win_split_ins immediately closes "wp".
Solution: check that "wp" is valid after win_split_ins.
          (Sean Dewar)

abf7030a5c
2024-03-08 23:24:05 +00:00
Sean Dewar e3d4dfb6c3
vim-patch:9.1.0128: win_gotoid() may abort even when not switching a window
Problem:  win_gotoid() checks for textlock and other things when switching
          to a window that is already current (after v9.1.0119)
Solution: return early with success when attempting to switch to curwin
          (Sean Dewar)

2a65e73944
2024-03-08 23:24:05 +00:00
Sean Dewar b2245307f2
vim-patch:9.1.0121: Infinite loop or signed overflow with 'smoothscroll'
Problem:  infinite loop in win_update with 'smoothscroll' set when
          window width is equal to textoff, or signed integer overflow
          if smaller.
Solution: don't revalidate wp->w_skipcol in that case, as no buffer text
          is being shown. (Sean Dewar)

02fcae02a9

Test_window_split_no_room changes were already cherry-picked earlier.
2024-03-08 23:24:05 +00:00
Sean Dewar 01b27410a3
vim-patch:9.1.0119: can move away from cmdwin using win_splitmove()
Problem:  can switch windows while textlocked via f_win_gotoid and
          f_win_splitmove (which also allows switching in the cmdwin).
Solution: Check text_or_buf_locked in f_win_splitmove()
          (Sean Dewar)

While at it, call text_or_buf_locked() in f_win_gotoid() instead of testing for
cmdwin_type() (which text_buf_locked() does and in addition will also verify
that the buffer is not locked).

f865895c87
2024-03-08 23:24:05 +00:00
Sean Dewar 1c6b693ec1
vim-patch:9.1.0118: Use different restoration strategy in win_splitmove
Problem:  saving and restoring all frames to split-move is overkill now
          that WinNewPre is not fired when split-moving.
Solution: defer the flattening of frames until win_split_ins begins
          reorganising them, and attempt to restore the layout by
          undoing our changes. (Sean Dewar)

704966c254

Adjust winframe_restore to account for Nvim's horizontal separators when the
global statusline is in use. Add a test.
2024-03-08 23:24:04 +00:00
Sean Dewar 24dfa47e4f
vim-patch:partial:9.1.0117: Stop split-moving from firing WinNew and WinNewPre autocommands
Problem:  win_splitmove fires WinNewPre and possibly WinNew when moving
          windows, even though no new windows are created.
Solution: don't fire WinNew and WinNewPre when inserting an existing
          window, even if it isn't the current window. Improve the
          accuracy of related documentation. (Sean Dewar)

96cc4aef3d

Partial as WinNewPre has not been ported yet (it currently has problems anyway).
2024-03-08 23:24:04 +00:00
Sean Dewar 66f331fef7
vim-patch:9.1.0116: win_split_ins may not check available room
Problem:  win_split_ins has no check for E36 when moving an existing
          window
Solution: check for room and fix the issues in f_win_splitmove()
          (Sean Dewar)

0fd44a5ad8

Omit WSP_FORCE_ROOM, as it's not needed for Nvim's autocmd window, which is
floating. Shouldn't be difficult to port later if it's used for anything else.

Make win_splitmove continue working for turning floating windows into splits.
Move the logic for "unfloating" a float to win_split_ins; unlike splits, no
changes to the window layout are needed before calling it, as floats take no
room in the window layout and cannot affect the e_noroom check.

Add missing tp_curwin-fixing logic for turning external windows into splits, and
add a test.
NOTE: there are other issues with the way "tabpage independence" is implemented
for external windows; namely, some things assume that tp_curwin is indeed a
window within that tabpage, and as such, functions like tabpage_winnr and
nvim_tabpage_get_win currently don't always work for external windows (with the
latter aborting!)

Use last_status over frame_add_statusline, as Nvim's last_status already does
this for all windows in the current tabpage. Adjust restore_full_snapshot_rec to
handle this.
This "restore everything" approach is changed in a future commit anyway, so only
ensure it's robust enough to just pass tests.

Keep check_split_disallowed's current doc comment, as it's actually a bit more
accurate here. (I should probably PR Vim to use this one)

Allow f_win_splitmove to move a floating "wp" into a split; Nvim supports this.
Continue to disallow it from moving the autocommand window into a split (funnily
enough, the check wasn't reachable before, as moving a float was disallowed),
but now return -1 in that case (win_splitmove also returns FAIL for this, but
handling it in f_win_splitmove avoids us needing to switch windows first).

Cherry-pick Test_window_split_no_room fix from v9.1.0121.

Update nvim_win_set_config to handle win_split_ins failure in later commits.
2024-03-08 23:24:04 +00:00
Sean Dewar a70eae57bd
fix(api): make open_win block only enter/leave events if !enter && !noautocmd
Problem: nvim_open_win blocking all win_set_buf autocommands when !enter &&
!noautocmd is too aggressive.

Solution: temporarily block WinEnter/Leave and BufEnter/Leave events when
setting the buffer. Delegate the firing of BufWinEnter back to win_set_buf,
which also has the advantage of keeping the timing consistent (e.g: before the
epilogue in enter_buffer, which also handles restoring the cursor position if
autocommands didn't change it, among other things). Reword the documentation for
noautocmd a bit.

I pondered modifying do_buffer and callees to allow for BufEnter/Leave being
conditionally disabled, but it seems too invasive (and potentially error-prone,
especially if new code paths to BufEnter/Leave are added in the future).

Unfortunately, doing this has the drawback of blocking ALL such events for the
duration, which also means blocking unrelated such events; like if window
switching occurs in a ++nested autocmd fired by win_set_buf. If this turns out
to be a problem in practice, a different solution specialized for nvim_open_win
could be considered. :-)
2024-03-08 23:24:04 +00:00
Sean Dewar b1577d371a
fix(api): make win_set_config with "win" for splits need "split/vertical"
Problem: currently, for splits, nvim_win_set_config accepts win without any of
split or vertical set, which has little effect and seems error-prone.

Solution: require at least one of split or vertical to also be set for splits.

Also, update nvim_win_set_config docs, as it's no longer limited to just
floating and external windows.
2024-03-08 23:24:04 +00:00
Sean Dewar 5d58136ccc
fix(api): make open_win/win_set_config check if splitting allowed
Problem: splitting is disallowed in some cases to prevent the window layout
changes while a window is closing, but it's not checked for.

Solution: check for this, and set the API error message directly.

(Also sneak in a change to tui.c that got lost from #27352; it's a char* buf,
and the memset is assuming one byte each anyway)
2024-03-08 23:24:03 +00:00
Sean Dewar b1e24f240b
fix(api): avoid open_win UAF if target buf deleted by autocmds
Problem: WinNew and win_enter autocommands can delete the target buffer to
switch to, causing a heap-use-after-free.

Solution: store a bufref to the buffer, check it before attempting to switch.
2024-03-08 23:24:03 +00:00
Sean Dewar e55a502ed4
fix(api): open_win fire Buf* events when !enter && !noautocmd if entered early
Problem: if switch_win{_noblock} fails to restore the old curwin after WinNew
(e.g: it was closed), wp will become the new curwin, but win_set_buf enter
events would still be blocked if !enter && !noautocmd.

Solution: fire them, as we've actually entered the new window.

Note: there's a problem of switch_win{_noblock} failing to restore the old
curwin, leaving us in wp without triggering WinEnter/WinLeave, but this affects
all callers of switch_win{_noblock} anyways. (It's also not clear how WinLeave
can be called if the old curwin was closed already).
2024-03-08 23:24:00 +00:00
Sean Dewar a873f33993
fix(api): open_win fire BufWinEnter for other buffer when !enter && !noautocmd
Problem: BufWinEnter is not fired when not entering a new window, even when a
different buffer is specified and buffer-related autocommands are unblocked
(!noautocmd).

Solution: fire it in the context of the new window and buffer. Do not do it if
the buffer is unchanged, like :{s}buffer.

Be wary of autocommands! For example, it's possible for nvim_win_set_config to
be used in an autocommand to move a window to a different tabpage (in contrast,
things like wincmd T actually create a *new* window, so it may not have been
possible before, meaning other parts of Nvim could assume windows can't do
this... I'd be especially cautious of logic that restores curwin and curtab
without checking if curwin is still valid in curtab, if any such logic exists).

Also, bail early from win_set_buf if setting the temp curwin fails; this
shouldn't be possible, as the callers check that wp is valid, but in case that's
not true, win_set_buf will no longer continue setting a buffer for the wrong
window.

Note that pum_create_float_preview also uses win_set_buf, but from a glance,
doesn't look like it properly checks for autocmds screwing things up (win_enter,
nvim_create_buf...). I haven't addressed that here.

Also adds some test coverage for nvim_open_win autocommands.

Closes #27121.
2024-03-08 23:23:55 +00:00
Sean Dewar 233649bc75
fix(api): win_set_config fires unnecessary autocmds
Problem: win_set_config should have the observable effect of moving an existing
window to another place, but instead fires autocommands as if a new window was
created and entered (and does not fire autocommands reflecting a "return" to the
original window).

Solution: do not fire win_enter-related autocommands when splitting the window,
but continue to fire them when entering the window that fills the new space when
moving a window to a different tabpage, as the new curwin changes.

Also, remove "++once" from the WinEnter autocmd in the other test, as omitting
it also crashed Nvim before this fix.
2024-03-08 22:37:32 +00:00
Sean Dewar bcb70eeac4
fix(api): win_set_config autocmds crash when moving win to other tabpage
Problem: win_enter autocommands can close new_curwin, crashing if it was the
last window in its tabpage after removing win, or can close parent, crashing
when attempting to split it later.

Solution: remove win first, check that parent is valid after win_enter.

NOTE: This isn't actually quite right, as this means win is not in the window
list or even has a frame when triggering enter autocommands (so it's not
considered valid in the tabpage). This is addressed in later commits.
2024-03-08 22:37:31 +00:00
Colin Watson a69c720639
fix(fileio): fix off-by-one in rename_with_tmp (#27780)
`_FORTIFY_SOURCE` on Ubuntu caught this, resulting in:

    [OLDTEST] Running test_rename
    Failed: test_rename :: Nvim exited with non-zero code
    Job exited with code 134
    Screen (23 lines)
    ================================================================================
    "test_rename.vim" "test_rename.vim" 120L, 3623B
    Executing Test_rename_copy()
    Executing Test_rename_dir_to_dir()
    Executing Test_rename_fails()
    Error detected while processing command line..script /<<BUILDDIR>>/neovim-0.9.5/test/old/testdir/runtest.vim[437]..function RunTheTest[44]..Test_rename_fails:
    line   17:
    E730: using List as a String
    line   18:
    E976: using Blob as a String
    Executing Test_rename_file_ignore_case()*** buffer overflow detected ***: terminated

`snprintf`'s second parameter should be no greater than the number of
remaining bytes in the allocated object.  We can see that this was off
by one, because in the simple case where `tail == tempname` (for a file
in the current directory), `rename_with_tmp` was passing `MAXPATHL + 2`
for an object allocated with a size of only `MAXPATHL + 1`.

Introduced in 5f1a153831.
2024-03-09 05:49:06 +08:00
bfredl e534ec47db refactor(ui): remove outdated UI vs UIData distinction
Just some basic spring cleaning.

In the distant past, not all UI:s where remote UI:s. They still aren't,
but both of the "UI" and "UIData" structs are now only for remote UI:s.
Thus join them as "RemoteUI".
2024-03-08 09:23:28 +01:00
bfredl 55c9e2c96e
Merge pull request #27655 from bfredl/mpack_obj
refactor(msgpack): allow flushing buffer while packing msgpack
2024-03-08 08:57:09 +01:00
zeertzjq 6a580b997b
vim-patch:8.2.5077: various warnings from clang on MS-Windows (#27773)
Problem:    Various warnings from clang on MS-Windows.
Solution:   Avoid the warnings. (Yegappan Lakshmanan, closes vim/vim#10553)

a34b4460c2

Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
2024-03-08 13:56:27 +08:00
zeertzjq d0b3c87219
fix(process): avoid potential data race on exit (#27769)
On exit, pty_process_close() may be called after pty_process_finish1()
but before start_wait_eof_timer(), in which case the timer shouldn't be
started because pty_process_close() has already closed it.
2024-03-08 09:18:03 +08:00
zeertzjq c38764182a vim-patch:9.1.0158: 'shortmess' "F" flag doesn't work properly with 'autoread'
Problem:  'shortmess' "F" flag doesn't work properly with 'autoread'
          (after 9.1.0154)
Solution: Hide the file info message instead of the warning dialog
          (zeertzjq)

closes: vim/vim#14159
closes: vim/vim#14158

8a01744c56
2024-03-08 07:04:39 +08:00
zeertzjq d741e5d162 vim-patch:9.1.0154: shm=F not respected when reloading buffer with 'autoread'
Problem:  shm=F not respected when reloading buffer with 'autoread'
Solution: Check SHM_FILEINFO in buf_check_timestamp()
          (Shougo Matsushita)

closes: vim/vim#14144

9db39b0ec9

Co-authored-by: Shougo Matsushita <Shougo.Matsu@gmail.com>
2024-03-08 06:53:37 +08:00
zeertzjq 5f3579e6ea
vim-patch:9.1.0157: Duplicate assignment in f_getregion() (#27766)
Problem:  Duplicate assignment in f_getregion().
Solution: Remove the duplicate assignment.  Also improve getregion()
          docs wording and fix an unrelated typo (zeertzjq)

closes: vim/vim#14154

0df8f93bda
2024-03-08 06:44:57 +08:00
zeertzjq 3e569d440b
fix(process): close handles and timer in pty_process_close() (#27760)
This should prevent use-after-free on exit on Windows.
2024-03-07 18:05:55 +08:00
bfredl dc37c1550b refactor(msgpack): allow flushing buffer while packing msgpack
Before, we needed to always pack an entire msgpack_rpc Object to
a continous memory buffer before sending it out to a channel.
But this is generally wasteful. it is better to just flush
whatever is in the buffer and then continue packing to a new buffer.

This is also done for the UI event packer where there are some extra logic
to "finish" of an existing batch of nevents/ncalls. This doesn't really
stop us from flushing the buffer, just that we need to update the state
machine accordingly so the next call to prepare_call() always will
start with a new event (even though the buffer might contain overflow
data from a large event).
2024-03-07 09:39:46 +01:00
zeertzjq 6525832a8c
vim-patch:9.1.0155: can only get getregion() from current buffer (#27757)
Problem:  can only call getregion() for current buffer
Solution: Allow to retrieve selections from different buffers
          (Shougo Matsushita)

closes: vim/vim#14131

84bf6e658d

Co-authored-by: Shougo Matsushita <Shougo.Matsu@gmail.com>
2024-03-07 06:43:08 +08:00
zeertzjq 5b312cd5f6
fix(eval): make has('pythonx') work properly (#27739)
Problem:  has('pythonx') always returns 1.
Solution: Make it the same as has('python3').
2024-03-05 15:54:41 +08:00
Sean Dewar 633bf61d3b
fix(ui_client): check return value of channel_job_start (#27729)
Problem: null pointer member access in ui_client_start_server if
channel_job_start returns NULL.

Solution: check for it, return 0 in that case (which is already used to indicate
failure and is handled by main).

Happened on Linux when trying to run Nvim in an old gdbserver instance after having
rebuilt Nvim since. This gave E903 (the nvim binary was deleted, so " (deleted)" appears
as a suffix in the `v:progpath`, making it invalid), then ASAN complains due to the NPD;
instead it now then prints "Failed to start Nvim server!", as expected.
2024-03-04 13:15:04 +00:00
Sean Dewar bf0c69e504
fix(eval): correct failure return value for readfile/blob (#27722)
Currently returns 0 on failure, but should return an empty list (or blob).

Regressed in the big blob port of '21 (#15211).
2024-03-03 22:33:28 +00:00
luukvbaal dbf6be296d
fix(column): full redraw with 'stc, 'rnu' and inserted lines (#27712)
Problem:  Text is not redrawn with 'relativenumber' when only the 'statuscolumn' is redrawn after inserted lines.
Solution: Force a full redraw if statuscolumn width changed.
2024-03-03 08:40:46 +08:00
bfredl 0d553c8347
Merge pull request #27687 from luukvbaal/floatpos
fix(float): allow floating window in cmdline area
2024-03-02 11:22:40 +01:00
zeertzjq 62d04f21d9
vim-patch:9.1.0146: v:echospace wrong with invalid value of 'showcmdloc' (#27697)
Problem:  v:echospace wrong after setting invalid value to 'showcmdloc'.
Solution: Only call comp_col() if value is valid.
          (zeertzjq)

closes: vim/vim#14119

c27fcf4857
2024-03-02 06:48:11 +08:00
zeertzjq 1fe65b3457
vim-patch:87410ab3f556 (#27696)
runtime(doc): some improvements to getregion() docs (vim/vim#14122)

- Mention the default selection behavior
- Remove useless sentence
- Correct description about space padding

87410ab3f5
2024-03-02 06:42:39 +08:00
Luuk van Baal 884470124d fix(float): allow floating window in cmdline area
Problem:  Floats are arbitrarily positioned at 1 row above screen size.
Solution: Position at 1 row above 'cmdheight', only if window is hidden behind the message area.
2024-03-01 16:00:16 +01:00
zeertzjq 5d4e1693cb
vim-patch:9.1.0145: v:echospace not correct when 'showcmdloc' != last (#27682)
Problem:  the amount of available space (v:echospace) on the command
          line is not correct when showcmdloc is drawn into the
          statusline or tabline.
Solution: only add SHOWCMD_COLS to the shown command column when
          'showcmdloc' is set to last (Sam-programs)

closes: vim/vim#14108

062141b1a7

Co-authored-by: Sam-programs <130783534+Sam-programs@users.noreply.github.com>
2024-03-01 06:13:38 +08:00
glepnir 6ab0876f51 docs(eval): getline and indent function support string type
Problem: getline and indent function missing string type in param.

Solution: add string type in eval gen.
2024-02-29 13:30:25 +00:00
zeertzjq 0eaae1bc05
vim-patch:9.1.0143: [security]: autocmd causes use-after-free in set_curbuf() (#27664)
Problem:  [security]: autocmd cause use-after-free in set_curbuf()
          (kawarimidoll)
Solution: check side-effect of BufLeave autocommand, when the number
          of windows changed, close windows containing buffers that will
          be wiped, if curbuf changed unexpectedly make sure b_nwindows
          is decremented otherwise it cannot be wiped

set_curbuf() already makes some efforts to ensure the BufLeave
autocommands do not cause issues.  However there are still 2 issues
that are not taken care of:

1) If a BufLeave autocommand opens a new window containing the same
buffer as that is going got be closed in close_buffer() a bit later,
we suddenly have another window open, containing a free'd buffer.  So we
must check if the number of windows changed and if it does (and the
current buffer is going to be wiped (according to the 'bufhidden'
setting), let's immediately close all windows containing the current
buffer using close_windows()

2) If a BufLeave autocommand changes our current buffer (displays it in
the current window), buf->b_nwindow will be incremented. As part of
set_curbuf() we will however enter another buffer soon, which means, the
newly created curbuf will have b_nwindows still have set, even so the
buffer is no longer displayed in a window. This causes later problems,
because it will no longer be possible to wipe such a buffer. So just
before entering the final buffer, check if the curbuf changed when
calling the BufLeave autocommand and if it does (and curbuf is still
valid), decrement curbuf->b_nwindows.

Both issues can be verified using the provided test (however the second
issue only because such an impacted buffer won't be wiped, causing
futher issues in later tests).

fixes: vim/vim#13839
closes: vim/vim#14104

55f8bba73b

Co-authored-by: Christian Brabandt <cb@256bit.org>
2024-02-29 08:33:02 +08:00
zeertzjq ce7c51a1a3
vim-patch:9.1.0142: getregion() can be improved (#27662)
Problem:  getregion() can be improved (after v9.1.120)
Solution: change getregion() implementation to use pos as lists and
          one optional {opt} dictionary (Shougo Matsushita)

Note: The following is a breaking change!

Currently, the getregion() function (included as of patch v9.1.120) takes
3 arguments: the first 2 arguments are strings, describing a position,
arg3 is the type string.

However, that is slightly inflexible, there is no way to specify
additional arguments. So let's instead change the function signature to:

getregion(pos1, pos2 [, {Dict}]) where both pos1 and pos2 are lists.
This is slightly cleaner, and gives us the flexibility to specify
additional arguments as key/value pairs to the optional Dict arg.

Now it supports the "type" key to specify the selection type
(characterwise, blockwise or linewise) and now in addition one can also
define the selection type, independently of what the 'selection' option
actually is.

Technically, this is a breaking change, but since the getregion()
Vimscript function is still quite new, this should be fine.

closes: vim/vim#14090

19b718828d

Co-authored-by: Shougo Matsushita <Shougo.Matsu@gmail.com>
2024-02-29 07:19:26 +08:00
zeertzjq e592657df8
vim-patch:9.1.0141: Put in Visual mode wrong if it replaces fold marker (#27661)
Problem:  Put in Visual mode wrong if it replaces fold marker.
Solution: Temporarily disable folding during put in Visual mode.
          (zeertzjq)

fixes: vim/vim#14097
closes: vim/vim#14100

4e141c66b9
2024-02-29 06:48:29 +08:00
bfredl de5cf09cf9 refactor(metadata): generate all metadata in lua
Then we can just load metadata in C as a single msgpack blob. Which also
can be used directly as binarly data, instead of first unpacking all the
functions and ui_events metadata to immediately pack it again, which was
a bit of a silly walk (and one extra usecase of `msgpack_rpc_from_object`
which will get yak shaved in the next PR)
2024-02-28 11:00:38 +01:00
zeertzjq 7e46ff791c
vim-patch:9.1.0140: cursor on wrong row after 1 char 'below' virtual text when EOL is shown (#27651)
Problem:  The cursor screen row was incorrectly being calculated when the
          cursor follows a 1 character text_align 'below' virtual text line,
          resulting in the cursor being shown on the wrong line.
          This was caused by a cell size of 2 instead of 1 being used for the EOL
          character, which propagated to the calculation of space for putting the
          'below' virtual text on its own line. (rickhowe)
Solution: Fix the size used for the EOL character in calculating the
          cursor's screen position (Dylan Thacker-Smith)

fixes: vim/vim#11959
related: vim/vim#12028
closes: vim/vim#14096

da0c9137d1

Co-authored-by: Dylan Thacker-Smith <dylan.ah.smith@gmail.com>
2024-02-28 07:28:48 +08:00
Lewis Russell 9beb40a4db feat(docs): replace lua2dox.lua
Problem:

The documentation flow (`gen_vimdoc.py`) has several issues:
- it's not very versatile
- depends on doxygen
- doesn't work well with Lua code as it requires an awkward filter script to convert it into pseudo-C.
- The intermediate XML files and filters makes it too much like a rube goldberg machine.

Solution:

Re-implement the flow using Lua, LPEG and treesitter.

- `gen_vimdoc.py` is now replaced with `gen_vimdoc.lua` and replicates a portion of the logic.
- `lua2dox.lua` is gone!
- No more XML files.
- Doxygen is now longer used and instead we now use:
  - LPEG for comment parsing (see `scripts/luacats_grammar.lua` and `scripts/cdoc_grammar.lua`).
  - LPEG for C parsing (see `scripts/cdoc_parser.lua`)
  - Lua patterns for Lua parsing (see `scripts/luacats_parser.lua`).
  - Treesitter for Markdown parsing (see `scripts/text_utils.lua`).
- The generated `runtime/doc/*.mpack` files have been removed.
   - `scripts/gen_eval_files.lua` now instead uses `scripts/cdoc_parser.lua` directly.
- Text wrapping is implemented in `scripts/text_utils.lua` and appears to produce more consistent results (the main contributer to the diff of this change).
2024-02-27 14:41:17 +00:00
Maria José Solano 7ad2e3c645
docs: fix type of setreg() argument {options} (#27631) 2024-02-27 19:53:49 +08:00
zeertzjq 0d75324e3b
vim-patch:9.1.0137: <Del> in cmdline mode doesn't delete composing chars (#27636)
Problem:  <Del> in cmdline mode doesn't delete composing chars
Solution: Use mb_head_off() and mb_ptr2len() (zeertzjq)

closes: vim/vim#14095

ff2b79d239
2024-02-27 06:09:06 +08:00
bfredl cdcdc10411 refactor(msgpack): remove dead unpacker code in helpers
Unpacker code now lives in unpacker.c
This was part of the old unpacker which I forgor to remove.
2024-02-26 14:47:47 +01:00
bfredl 7038fdeee2
Merge pull request #27599 from bfredl/nofilealloc
refactor(fileio): remove API shell layer encouraging unnecessary allocations
2024-02-26 14:43:42 +01:00
VanaIgr ad5a155b1f
fix(mbyte): fix bugs in utf_cp_*_off() functions
Problems:
- Illegal bytes after valid UTF-8 char cause utf_cp_*_off() to fail.
- When stream isn't NUL-terminated, utf_cp_*_off() may go over the end.
Solution: Don't go over end of the char of end of the string.
2024-02-26 18:12:55 +08:00
zeertzjq 268066e014
fix(process): start pty process eof timer on main thread (#27625) 2024-02-26 09:47:49 +08:00
bfredl 7447b035ca refactor(shada): devirtualize writer
writer is only ever used with FileDescriptor. We already have separate
code paths for serializing shada data into memory, see
shada_encode_regs() and friends
2024-02-25 11:20:06 +01:00
bfredl 77e928fd3e refactor(fileio): remove API shell layer encouraging unnecessary allocations
Functions like file_open_new() and file_open_fd_new() which just is a
wrapper around the real functions but with an extra xmalloc/xfree around
is an anti-pattern. If the caller really needs to allocate a
FileDescriptor as a heap object, it can do that directly.

FileDescriptor by itself is pretty much a pointer, or rather two:
the OS fd index and a pointer to a buffer. So most of the time an extra
pointer layer is just wasteful.

In the case of scriptin[curscript] in getchar.c, curscript used
to mean in practice:

N+1 open scripts           when curscript>0
zero or one open scripts   when curscript==0

Which means scriptin[0] had to be compared to NULL to disambiguate the
curscript=0 case.

Instead, use curscript==-1 to mean that are no script,
then all pointer comparisons dissappear and we can just use an array of
structs without extra pointers.
2024-02-25 11:20:06 +01:00
Evgeni Chasnovski c2ddef30e7
docs: fix several misleading and superfluous wordings (#27609) 2024-02-25 08:45:34 +08:00
zeertzjq 04f723f1a5
vim-patch:9.1.0131: buffer-completion may not always find all matches (#27610)
Problem:  buffer-completion code too complicated and does not always
          find all matches (irisjae)
Solution: do not try to anchor pattern to beginning of line or
          directory-separator, always return all matches

Note: we are considering the non-fuzzy buffer-matching here.

Currently, the buffer-completion code makes 2 attempts to match a
pattern against the list of available patterns. First try is to match
the pattern and anchor it to either the beginning of the file name or
at a directory-separator (// or \\).

When a match is found, Vim returns the matching buffers and does not try
to find a match anywhere within a buffer name. So if you have opened two
buffers like /tmp/Foobar.c and /tmp/MyFoobar.c using `:b Foo` will only
complete to the first filename, but not the second (the same happens
with `getcompletion('Foo', 'buffer')`).

It may make sense, that completion priorities buffer names at directory
boundaries, but it inconsistent, may cause confusion why a certain
buffer name is not completed when typing `:b Foo<C-D>` which returns
only a single file name and then pressing Enter (to switch to that
buffer), Vim will error with 'E93: More than one match for Foo').
Similar things may happen when wiping the /tmp/Foobar.c pattern and
afterwards the completion starts completing other buffers.

So let's simplify the code and always match the pattern anywhere in the
buffer name, do not try to favor matches at directory boundaries. This
is also simplifies the code a bit, we do not need to run over the list
of buffers several times, but only twice.

fixes vim/vim#13894
closes: vim/vim#14082

0dc0bff000

Cherry-pick test_cmdline.vim from patch 9.1.0019 as it already passes.

Co-authored-by: Christian Brabandt <cb@256bit.org>
2024-02-24 22:59:28 +08:00
zeertzjq febf481002
vim-patch:9.1.0132: "C" doesn't include composing chars with 'virtualedit' (#27605)
Problem:  using "C" and 've=all' set, doesn't include composing chars
          when changing a line, keeps the composing chars for whatever
          is typed afterwards.
Solution: Use mb_head_off() and mb_ptr2len() instead of mb_tail_off().
          (zeertzjq)

closes: vim/vim#14083

048761bcd4
2024-02-24 22:04:52 +08:00
zeertzjq 9ea8a77b04
vim-patch:9.1.0129: Fix truncation of text_wrap 'wrap' virt text after EOL list char (#27600)
Problem:  Virtual text with text_wrap 'wrap' was effectively being
          truncated by a break conditional on the EOL list character
          being added to the screen line. (BigPeet)
Solution: Remove the condition that was leading to the early break and
          instead fix a similar but incorrectly written outer condition
          that checks if there is more to add at the end of the screen
          line. (Dylan Thacker-Smith)

Also, related:
- update comment in win_line()
- remove no longer necessary at_end_str variable in win_line()

fixes: vim/vim#12725
closes: vim/vim#14079

f548ae7b63

Co-authored-by: Dylan Thacker-Smith <dylan.ah.smith@gmail.com>
2024-02-24 20:16:39 +08:00
zeertzjq 9418381ccc
vim-patch:a35235e824bb (#27598)
runtime(doc) Update help text for matchbufline() and matchstrlist()

closes: vim/vim#14080

a35235e824

Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
2024-02-24 17:55:32 +08:00
bfredl c5990f2cdc perf(os/env): os_getenv() allocation when there is no env var set
os_getenv("FOO") caches the result when $FOO is set to something
non-empty. However, when $FOO was not set, every new call to
os_getenv("FOO") would allocate a temporary scratch buffer to
immediately throw away.

This has an huge impact e.g. on logging which depends on potentially
non-set env vars.
2024-02-24 09:30:21 +01:00
zeertzjq 99288ecc77
fix(terminal): block input when there is pending TermRequest (#27589) 2024-02-24 05:12:30 +08:00
bfredl cb5ae22eab
Merge pull request #27590 from bfredl/signcolfix
fix(marktree): do not count certain marks twice when checking for overlap
2024-02-23 13:37:11 +01:00
bfredl b97d5038f1 fix(marktree): some marks counted twice when checking for overlap
fixes #27046
2024-02-23 11:41:09 +01:00
zeertzjq 1f75184b5c vim-patch:9.1.0127: Naming a non-pointer variable "oap" is strange
Problem:  Naming a non-pointer variable "oap" is strange.
Solution: Rename it to "oa". Also prevent using freed memory in case of
          memory allocation failure. (zeertzjq)

closes: vim/vim#14075

5e3674b42d
2024-02-23 06:39:34 +08:00
zeertzjq 06df895e71 vim-patch:9.1.0126: Internal error when using upper-case mark in getregion()
Problem:  Internal error when passing mark in another buffer to
          getregion().
Solution: Don't allow marks in another buffer (zeertzjq)

closes: vim/vim#14076

Internal error when passing mark in another buffer to getregion()

421b597470
2024-02-23 06:39:05 +08:00
zeertzjq 20e4001eee vim-patch:9.1.0120: hard to get visual region using Vim script
Problem:  hard to get visual region using Vim script
Solution: Add getregion() Vim script function
          (Shougo Matsushita, Jakub Łuczyński)

closes: vim/vim#13998
closes: vim/vim#11579

3f905ab3c4

Cherry-pick changes from patch 9.1.0122, with :echom instead of :echow.

Co-authored-by: Shougo Matsushita <Shougo.Matsu@gmail.com>
Co-authored-by: Jakub Łuczyński <doubleloop@o2.pl>
2024-02-23 06:39:03 +08:00
zeertzjq 4ec5c58846
refactor(terminal): rename confusing variable name "rv" (#27573)
Now that terminal_open() no longer returns a value, the variable name
"rv" is confusing, and "term" makes more sense anyway.
2024-02-22 13:18:52 +08:00
zeertzjq 711a2f5ff6
fix(api): don't leak memory with nvim_win_get_ns (#27570) 2024-02-22 09:13:07 +08:00
zeertzjq 2137edbd4f
fix(extmarks): redraw properly with scoped inline virt_text (#27569) 2024-02-22 09:05:52 +08:00
altermo 1c032ad703 feat(extmark): window scoped extmark
Co-authored-by: zeertzjq <zeertzjq@outlook.com>
2024-02-21 16:11:50 +01:00
rktjmp 6d8bbfe19d
docs: remove mention of foreground/background/special keys in nvim_set_hl (#27558)
To align the output of `nvim_get_hl` with its documentation -- which
points to `nvim_set_hl`, remove mentions of the keys `foreground`,
`background` and `special`.

The long keys are are still supported (via fallback checks inside
`dict2hlattrs`), but the `fg`, `bg` and `sp` keys are preferenced.
2024-02-21 21:25:08 +08:00
dundargoc 4fb1739e6f build: fix uncrustify 2024-02-21 11:58:28 +01:00
bfredl 3cc54586be refactor(api): make freeing of return-value opt-in instead of opt out
As only a few API functions make use of explicit freeing of the return
value, make it opt-in instead. The arena is always present under the
hood, so `Arena *arena` arg now doesn't mean anything other than getting
access to this arena. Also it is in principle possible to return an
allocated value while still using the arena as scratch space for other
stuff (unlikely, but there no reason to not allow it).
2024-02-21 11:58:28 +01:00
bfredl eb1e8c12e2
Merge pull request #27541 from bfredl/exprarena
refactor(api): use an arena for nvim_parse_expression
2024-02-20 13:11:18 +01:00
zeertzjq a0790558c3
fix(extmarks): priority order of inline and non-inline virt_text (#27532) 2024-02-20 19:53:49 +08:00
bfredl acd9b54f08 refactor(api): use an arena for nvim_parse_expression 2024-02-20 12:31:11 +01:00
bfredl f2c73e9ee2 refactor(api): reduce temporary allocations when replacing lines
The way ml_replace_buf is implemented makes it unfriendly for
being used in a loop: every call allocates a scratch buffer for putting
the line into the "dirty" state. This then immediately needs to be freed
as the next ml_replace_buf and/or ml_append_buf call will flush that buffer.

It's better to later pay the price of allocating the scratch buffer only if
the line is being immediately edited (likely when using the API to only
change one line) with an extra memcpy, than allocating that buffer
multiple times every time the API is called.

Of course, a separate xmalloc/xfree cycle for each time the dirty line
changes is unwanted to begin with. But fixing that is a later refactor.
2024-02-20 11:24:15 +01:00
bfredl 8952a89db5
Merge pull request #27534 from bfredl/userarena
refactor(api): next PR to make use of the arena
2024-02-19 21:21:05 +01:00
dundargoc 8fdc84d0aa build: disable conversion warnings for GCC
GCC seems chronically incapable of producing correct and relevant
conversion warnings, and will therefore need to be silenced.
2024-02-19 20:41:44 +01:00
bfredl 404707c760 refactor(api): use arena for nvim_put and nvim_paste 2024-02-19 13:48:39 +01:00
bfredl d14eefaee9 refactor(api): use arena when listing objects 2024-02-19 13:48:39 +01:00
bfredl abb8dcd889 refactor(api): use arena for runtime and client info 2024-02-19 13:48:39 +01:00