summaryrefslogtreecommitdiffstatshomepage
path: root/src/nvim/eval/buffer.c
AgeCommit message (Collapse)AuthorFiles
2026-04-18fix(eval): crash on some NULL ptr deref #39182phanium1
Crash on ``` let busy=$FOO call prompt_setcallback(bufnr('%'), $FOO) call chanclose(1, $FOO) ``` Co-authored-by: zeertzjq <zeertzjq@outlook.com>
2026-03-27feat(prompt): prompt_appendbuf() appends to prompt buffer #37763Shadman1
Problem: Currently, we recommend always inserting text above prompt-line in prompt-buffer. This can be done using the `:` mark. However, although we recommend it this way it can sometimes get confusing how to do it best. Solution: Provide an api to append text to prompt buffer. This is a common use-case for things using prompt-buffer.
2026-02-27vim-patch:partial:9.2.0068: Inefficient use of list_append_string() (#38083)zeertzjq1
Problem: Inefficient use of list_append_string() Solution: Pass string length to list_append_string() where it is known (John Marriott). closes: vim/vim#19491 https://github.com/vim/vim/commit/455d62e38a75572bccc43e42d20b5db3c4b22ec3 N/A patches: vim-patch:9.2.0063: memory leak in type_name_list_or_dict() vim-patch:9.2.0065: memory leak in invoke_sync_listeners() vim-patch:9.2.0066: memory leak in build_drop_cmd() vim-patch:9.2.0067: memory leak in dict_extend_func() Co-authored-by: John Marriott <basilisk@internode.on.net>
2026-02-17fix(prompt): clear undo when changing/appending promptSean Dewar1
Problem: undoing after the prompt is changed breaks it (and causes init_prompt to abort it and append a new one), as the undo history contains the old prompt. Solution: like submitting, clear the undo buffer. Don't do it in init_prompt if the line was empty; that may not result in a new prompt, and causes commands like "S" to lose the history. As u_save, etc. wasn't being called by prompt_setprompt, undoing after it fixes the prompt usually gave undesirable results anyway. Remove the added undo_spec.lua test, as its approach no longer works as a repro, and finding a new one seems fiddly.
2026-02-17fix(prompt): prompt_setprompt cursor col adjustmentSean Dewar1
Problem: prompt_setprompt adjusted cursor col may be negative (<=0 when 1-based), and doesn't check the col of ': Solution: avoid negative col and adjust correctly if ': col differs from old prompt's length.
2026-02-17fix(prompt): prompt_setprompt with unloaded buffer, ': with lnum 0Sean Dewar1
Problem: prompt_setprompt memory leak/other issues when fixing prompt line for unloaded buffer, or when ': line number is zero. Solution: don't fix prompt line for unloaded buffer. Clamp ': lnum above zero.
2026-02-15fix(prompt): prompt_setprompt does not adjust extmarks, no on_bytesSean Dewar1
Problem: prompt_setprompt does not adjust extmarks or trigger on_bytes buffer-updates when fixing the prompt line. Solution: adjust them, trigger on_bytes. Notably, hides extmarks when replacing the entire line (and clearing user input). Otherwise, when just replacing the prompt text, hides extmarks there, but moves those after (in the user input area) to the correct spot.
2026-02-15fix(prompt): wrong cursor col after prompt_setprompt, no on_linesSean Dewar1
Problem: prompt_setprompt calls coladvance with a byte column, but it expects a screen column. on_lines buffer-updates aren't fired when fixing the prompt line. Solution: don't use coladvance. Call changed_lines, which also simplifies the redraw logic. (and calls changed_cline_bef_curs if needed; added test checks this) Unlike https://github.com/neovim/neovim/pull/37743/changes#r2775398744, this means &modified is set by prompt_setprompt if it fixes the prompt line. Not setting &modified is inconsistent anyway -- even init_prompt sets it if it fixes the prompt line.
2026-02-15fix(prompt): prompt_setprompt sets cursor col unnecessarilySean Dewar1
Problem: prompt_setprompt adjusts the cursor's column number even when it's not on the prompt's line. Solution: only adjust when on the prompt's line.
2026-02-15fix(prompt): heap-buffer-overflows with invalid ': colSean Dewar1
Problem: heap-buffer-overflow in init_prompt and prompt_setprompt if ': mark has an invalid column number. Solution: consider an out-of-bounds column number as a missing prompt. Remove the check for NULL for old_line, as ml_get_buf can't return NULL.
2026-02-15fix(prompt): heap-buffer-overflow in prompt_setpromptSean Dewar1
Problem: prompt_setprompt may check the wrong buffer, which can lead to a heap-buffer-overflow. Solution: don't use curbuf. Also replace all kCallbackNone initializers with CALLBACK_INIT.
2026-02-14feat(prompt): plugins can update prompt during user input #37743Shadman1
Problem: Currently, if prompt gets changed during user-input with prompt_setprompt() it only gets reflected in next prompt. And that behavior is not also consistent. If user re-enters insert mode then the user input gets discarded and a new prompt gets created with the new prompt. Solution: Handle prompt_setprompt eagerly. Update the prompt display, preserve user input.
2025-08-26fix(eval): winnrs of unfocusable/hidden windows #35474Sean Dewar1
Problem: various functions may return incorrect window numbers for unfocusable or hidden windows. Solution: fix the checks. Make sure current windows in non-current tabpages have a window number. Fixes #35453
2025-08-20vim-patch:8.2.0853: ml_delete() often called with FALSE argumentJan Edmund Lazo1
Problem: ml_delete() often called with FALSE argument. Solution: Use ml_delete_flags(x, ML_DEL_MESSAGE) when argument is TRUE. https://github.com/vim/vim/commit/ca70c07b72c24aae3d141e67d08f50361f051af5 Co-authored-by: Bram Moolenaar <Bram@vim.org>
2025-08-14refactor(build): remove INCLUDE_GENERATED_DECLARATIONS guardsbfredl1
These are not needed after #35129 but making uncrustify still play nice with them was a bit tricky. Unfortunately `uncrustify --update-config-with-doc` breaks strings with backslashes. This issue has been reported upstream, and in the meanwhile auto-update on every single run has been disabled.
2025-07-20refactor: fixup! vim-patch:8.1.0877: new bufferJan Edmund Lazo1
https://github.com/neovim/neovim/pull/9674 removed switch_to_win_for_buf(). This vim-patch removed the last relevant usage of find_win_for_buf() Vim uses switch_to_win_for_buf() only for if_py_both.
2025-06-01fix(eval): winnr('$') counts non-current hidden/unfocusable windows #34207luukvbaal1
Problem: Non-visible/focusable windows are assigned a window number, whereas commands that use this window number skip over them. Solution: Skip over non-visible/focusable windows when computing the window number, unless it is made the current window through the API in which case an identifiable window number is still useful. This also ensures it matches the window number of the window entered by `<winnr>wincmd w` since 403fcacf.
2024-12-23refactor: iwyu #31637Justin M. Keyes1
Result of `make iwyu` (after some "fixups").
2024-12-16refactor(wininfo): change wininfo from a linked list to an arraybfredl1
"wininfo" is going to be my next victim. The main problem with wininfo is that it is "all or nothing", i e either all state about a buffer in a window is considered valid or none of it is. This needs to be fixed to address some long running grievances. For now this is just a warmup: refactor it from a linked list to a vector.
2024-03-13fix(api/buffer): fix handling of viewport of non-current bufferbfredl1
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-01-28vim-patch:9.1.0049: Make "[Command Line]" a special buffer nameSean Dewar1
Problem: E95 is possible if a buffer called "[Command Line]" already exists when opening the cmdwin. This can also happen if the cmdwin's buffer could not be deleted when closing. Solution: Un-name the cmdwin buffer, and give it a special name instead, similar to what's done for quickfix buffers and for unnamed prompt and scratch buffers. As a result, BufFilePre/Post are no longer fired when opening the cmdwin. Add a "command" key to the dictionary returned by getbufinfo() to differentiate the cmdwin buffer instead. (Sean Dewar) Cherry-pick test_normal changes from v9.0.0954. https://github.com/vim/vim/commit/1fb41032060df09ca2640dc49541f11062f6dfaa
2024-01-22perf(extmarks): add metadata for efficient filtering of special decorationsbfredl1
This expands on the global "don't pay for what you don't use" rules for these special extmark decorations: - inline virtual text, which needs to be processed in plines.c when we calculate the size of text on screen - virtual lines, which are needed when calculating "filler" lines - signs, with text and/or highlights, both of which needs to be processed for the entire line already at the beginning of a line. This adds a count to each node of the marktree, for how many special marks of each kind can be found in the subtree for this node. This makes it possible to quickly skip over these extra checks, when working in regions of the buffer not containing these kind of marks, instead of before where this could just be skipped if the entire _buffer_ didn't contain such marks.
2024-01-11refactor(IWYU): fix headersdundargoc1
Remove `export` pramgas from defs headers as it causes IWYU to believe that the definitions from the defs headers comes from main header, which is not what we really want.
2023-12-30refactor: follow style guidedundargoc1
2023-11-30build: don't define FUNC_ATTR_* as empty in headers (#26317)zeertzjq1
FUNC_ATTR_* should only be used in .c files with generated headers. Defining FUNC_ATTR_* as empty in headers causes misuses of them to be silently ignored. Instead don't define them by default, and only define them as empty after a .c file has included its generated header.
2023-11-28refactor: fix headers with IWYUdundargoc1
2023-11-27refactor: rename types.h to types_defs.hdundargoc1
2023-11-27build(IWYU): fix includes for undo_defs.hdundargoc1
2023-11-27build(IWYU): fix includes for func_attr.hdundargoc1
2023-11-25vim-patch:8.2.4685: when a swap file is found for a popup there is no dialog ↵zeertzjq1
(#26207) Problem: When a swap file is found for a popup there is no dialog and the buffer is loaded anyway. Solution: Silently load the buffer read-only. (closes vim/vim#10073) https://github.com/vim/vim/commit/188639d75c363dffaf813e8e2209f7350ad1e871 Co-authored-by: Bram Moolenaar <Bram@vim.org>
2023-11-17refactor(sign): move legacy signs to extmarksLuuk van Baal1
Problem: The legacy signlist data structures and associated functions are redundant since the introduction of extmark signs. Solution: Store signs defined through the legacy commands in a hashmap, placed signs in the extmark tree. Replace signlist associated functions. Usage of the legacy sign commands should yield no change in behavior with the exception of: - "orphaned signs" are now always removed when the line it is placed on is deleted. This used to depend on the value of 'signcolumn'. - It is no longer possible to place multiple signs with the same identifier in a single group on multiple lines. This will now move the sign instead. Moreover, both signs placed through the legacy sign commands and through |nvim_buf_set_extmark()|: - Will show up in both |sign-place| and |nvim_buf_get_extmarks()|. - Are displayed by increasing sign identifier, left to right. Extmark signs used to be ordered decreasingly as opposed to legacy signs.
2023-11-12build: remove PVSdundargoc1
We already have an extensive suite of static analysis tools we use, which causes a fair bit of redundancy as we get duplicate warnings. PVS is also prone to give false warnings which creates a lot of work to identify and disable.
2023-08-26refactor(change): do API changes to buffer without curbuf switchbfredl1
Most of the messy things when changing a non-current buffer is not about the buffer, it is about windows. In particular, it is about `curwin`. When editing a non-current buffer which is displayed in some other window in the current tabpage, one such window will be "borrowed" as the curwin. But this means if two or more non-current windows displayed the buffers, one of them will be treated differenty. this is not desirable. In particular, with nvim_buf_set_text, cursor _column_ position was only corrected for one single window. Two new tests are added: the test with just one non-current window passes, but the one with two didn't. Two corresponding such tests were also added for nvim_buf_set_lines. This already worked correctly on master, but make sure this is well-tested for future refactors. Also, nvim_create_buf no longer invokes autocmds just because you happened to use `scratch=true`. No option value was changed, therefore OptionSet must not be fired.
2023-08-24refactor(memline): distinguish mutating uses of ml_get_buf()bfredl1
ml_get_buf() takes a third parameters to indicate whether the caller wants to mutate the memline data in place. However the vast majority of the call sites is using this function just to specify a buffer but without any mutation. This makes it harder to grep for the places which actually perform mutation. Solution: Remove the bool param from ml_get_buf(). it now works like ml_get() except for a non-current buffer. Add a new ml_get_buf_mut() function for the mutating use-case, which can be grepped along with the other ml_replace() etc functions which can modify the memline.
2023-08-22vim-patch:9.0.0837: append() reports failure when not appending anythingzeertzjq1
Problem: append() reports failure when not appending anything. Solution: Only report failure when appending something. (closes vim/vim#11498) https://github.com/vim/vim/commit/cd9c8d400c1eb9cbb4ff6a33be02f91a30ab13b2 Co-authored-by: Bram Moolenaar <Bram@vim.org>
2023-07-03refactor: remove longdundargoc1
long is 32-bits even on 64-bit windows which makes the type suboptimal for a codebase meant to be cross-platform.
2023-04-26refactor: uncrustifydundargoc1
Notable changes: replace all infinite loops to `while(true)` and remove `int` from `unsigned int`.
2023-04-07refactor: remove redundant const char * castsii141
2023-01-18refactor: replace char_u with char 24 (#21823)dundargoc1
refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459
2023-01-15refactor: fix IWYU mapping file and use IWYU (#21802)dundargoc1
Also add the EXITFREE definition to main_lib rather than the nvim target, as the header generation needs the EXITFREE flag to work properly.
2022-12-02feat(aucmd_win): allow crazy things with hidden buffers (#21250)zeertzjq1
Problem: Crash when doing crazy things with hidden buffers. Solution: Dynamically allocate the list of autocommand windows.
2022-11-29vim-patch:9.0.0965: using one window for executing autocommands is insufficientzeertzjq1
Problem: Using one window for executing autocommands is insufficient. Solution: Use up to five windows for executing autocommands. https://github.com/vim/vim/commit/e76062c078debed0df818f70e4db14ad7a7cb53a N/A patches for version.c: vim-patch:9.0.0966: some compilers don't allow a declaration after a label Problem: Some compilers don't allow a declaration after a label. Solution: Move the declaration to the start of the block. (John Marriott) https://github.com/vim/vim/commit/f86490ed4fdab213a28f667abd055c023a73d645 Co-authored-by: Bram Moolenaar <Bram@vim.org>
2022-11-29refactor: buffer_ensure_loaded()zeertzjq1
Cherry-picked from Vim patch 8.1.1612.
2022-11-29vim-patch:9.0.0914: deletebufline() may move marks in the wrong windowzeertzjq1
Problem: deletebufline() may move marks in the wrong window. Solution: Find a window for the buffer being changed. (closes vim/vim#11583) https://github.com/vim/vim/commit/228e422855d43965f2c3319ff0cdc26ea422c10f Cherry-pick code change from patch 9.0.0961. Co-authored-by: Bram Moolenaar <Bram@vim.org>
2022-11-29vim-patch:9.0.0910: setting lines in another buffer may not work wellzeertzjq1
Problem: Setting lines in another buffer may not work well. Solution: Make sure the buffer being changed has a window. (issue vim/vim#11558) https://github.com/vim/vim/commit/c934bfa1b765505e5fc491f2ee7cc106894cafc8 Co-authored-by: Bram Moolenaar <Bram@vim.org>
2022-11-29vim-patch:8.1.2001: some source files are too big (#21231)zeertzjq1
Problem: Some source files are too big. Solution: Move buffer and window related functions to evalbuffer.c and evalwindow.c. (Yegappan Lakshmanan, closes vim/vim#4898) https://github.com/vim/vim/commit/261f346f8154c0ec7094a4a211c653c74e9f7c2e