aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/buffer.c
Commit message (Collapse)AuthorAge
* vim-patch:9.1.0997: too many strlen() calls in drawscreen.c (#31927)zeertzjq2025-01-09
| | | | | | | | | | Problem: too many strlen() calls in drawscreen.c Solution: refactor drawscreen.c and remove calls to strlen(), make get_keymap_str() (in screen.c) return string length instead of TRUE/FALSE (John Marriott). https://github.com/vim/vim/commit/a21240b97debea2e087aee6ad1488b5f075d1259 Co-authored-by: John Marriott <basilisk@internode.on.net>
* refactor(wininfo): change wininfo from a linked list to an arraybfredl2024-12-16
| | | | | | | | | | "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.
* refactor(options): autogenerate valid values and flag enums for options (#31089)Famiu Haque2024-11-23
| | | | | | | | | | | | | | Problem: Option metadata like list of valid values for an option and option flags are not listed in the `options.lua` file and are instead manually defined in C, which means option metadata is split between several places. Solution: Put metadata such as list of valid values for an option and option flags in `options.lua`, and autogenerate the corresponding C variables and enums. Supersedes #28659 Co-authored-by: glepnir <glephunter@gmail.com>
* refactor(options): impl default 'titlestring' by format flags #30843zshuzh2024-11-20
| | | | | | | Problem: Unnecessary C impl of default 'titlestring'. Solutin: Define it using format flags.
* fix(messages): more ext_messages kinds #31279luukvbaal2024-11-20
| | | | Add kinds for various commands that output a list, the 'wildmode' list, and for number prompts.
* refactor(message): propagate highlight id instead of attrsLuuk van Baal2024-11-08
| | | | | | | Problem: Highlight group id is not propagated to the end of the message call stack, where ext_messages are emitted. Solution: Refactor message functions to pass along highlight group id instead of attr id.
* vim-patch:9.1.0831: 'findexpr' can't be used as lambad or Funcref (#31058)zeertzjq2024-11-03
| | | | | | | | | | | | | Problem: 'findexpr' can't be used for lambads (Justin Keyes) Solution: Replace the findexpr option with the findfunc option (Yegappan Lakshmanan) related: vim/vim#15905 closes: vim/vim#15976 https://github.com/vim/vim/commit/a13f3a4f5de9c150f70298850e34747838904995 Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
* vim-patch:9.1.0810: cannot easily adjust the |:find| commandzeertzjq2024-10-29
| | | | | | | | | | | | Problem: cannot easily adjust the |:find| command Solution: Add support for the 'findexpr' option (Yegappan Lakshmanan) closes: vim/vim#15901 closes: vim/vim#15905 https://github.com/vim/vim/commit/aeb1c97db5b9de4f4903e7f288f2aa5ad6c49440 Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
* vim-patch:9.1.0804: tests: no error check when setting global 'cc'zeertzjq2024-10-24
| | | | | | | | | | | Problem: tests: no error check when setting global 'cc' Solution: also parse and check global 'cc' value (Milly) closes: vim/vim#15914 https://github.com/vim/vim/commit/a441a3eaabbfc14b4772e07ecbecaaff3bd06a58 Co-authored-by: Milly <milly.ca@gmail.com>
* fix(build): remove USE_FNAME_CASE, redundant with CASE_INSENSITIVE_FILENAMEbfredl2024-10-11
| | | | | It stands to reason, you need to "fix" case-insensitive filenames if-and-only-if you have case-insensitive filenames.
* vim-patch:9.1.0764: [security]: use-after-free when closing a buffer (#30705)zeertzjq2024-10-07
| | | | | | | | | | | | | Problem: [security]: use-after-free when closing a buffer Solution: When splitting the window and editing a new buffer, check whether the newly to be edited buffer has been marked for deletion and abort in this case Github Advisory: https://github.com/vim/vim/security/advisories/GHSA-rj48-v4mq-j4vg https://github.com/vim/vim/commit/51b62387be93c65fa56bbabe1c3c1ea5df187641 Co-authored-by: Christian Brabandt <cb@256bit.org>
* refactor!: rename 'jumpoptions' flag "unload" to "clean" (#30418)zeertzjq2024-09-19
| | | Follow-up to #29347
* fix: replace NVIM with Nvim in default titlestring (#30348)Gregory Anders2024-09-11
|
* vim-patch:9.1.0678: [security]: use-after-free in alist_add()zeertzjq2024-08-17
| | | | | | | | | | | | | Problem: [security]: use-after-free in alist_add() (SuyueGuo) Solution: Lock the current window, so that the reference to the argument list remains valid. This fixes CVE-2024-43374 https://github.com/vim/vim/commit/0a6e57b09bc8c76691b367a5babfb79b31b770e8 Co-authored-by: Christian Brabandt <cb@256bit.org>
* vim-patch:8.2.3476: renaming a buffer on startup may cause using freed memoryzeertzjq2024-08-08
| | | | | | | | | | | Problem: Renaming a buffer on startup may cause using freed memory. Solution: Check if the buffer is used in a window. (closes vim/vim#8955) https://github.com/vim/vim/commit/d3710cf01ef6ab1b2f233866ff01dab76686f642 Cherry-pick Test_echo_true_in_cmd() from Vim. Co-authored-by: Bram Moolenaar <Bram@vim.org>
* refactor(shada): rework msgpack decoding without msgpack-cbfredl2024-08-05
| | | | | | | This also makes shada reading slightly faster due to avoiding some copying and allocation. Use keysets to drive decoding of msgpack maps for shada entries.
* refactor: collapse statements in single assignmentsLewis Russell2024-07-30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Problem: Variables are often assigned multiple places in common patterns. Solution: Replace these common patterns with different patterns that reduce the number of assignments. Use `MAX` and `MIN`: ```c if (x < y) { x = y; } // --> x = MAX(x, y); ``` ```c if (x > y) { x = y; } // --> x = MIN(x, y); ``` Use ternary: ```c int a; if (cond) { a = b; } els { a = c; } // --> int a = cond ? b : c; ```
* vim-patch:9.1.0557: moving in the buffer list doesn't work as documented ↵zeertzjq2024-07-11
| | | | | | | | | | | | | | | | | | | (#29653) Problem: moving in the buffer list doesn't work as documented (SenileFelineS) Solution: Skip non-help buffers, when run from normal buffers, else only move from help buffers to the next help buffer (LemonBoy) As explained in the help section for :bnext and :bprev the commands should jump from help buffers to help buffers (and from regular ones to regular ones). fixes: vim/vim#4478 closes: vim/vim#15198 https://github.com/vim/vim/commit/893eeeb44583ca33276e263165b2a6e50fd297d0 Co-authored-by: LemonBoy <thatlemon@gmail.com>
* vim-patch:9.1.0556: :bwipe doesn't remove file from jumplist of other ↵zeertzjq2024-07-11
| | | | | | | | | | | | | tabpages (#29651) Problem: :bwipe doesn't remove file from jumplist and tagstack of other tabpages. Time complexity of mark_forget_file() is O(n^2) when removing all entries (after v9.1.0554) Solution: Use FOR_ALL_TAB_WINDOWS(). Start the loops over the arrays from the end instead of the start (zeertzjq) closes: vim/vim#15199 https://github.com/vim/vim/commit/2e7d89b39883b0cfd3e615b02bd55186e00fb7ce
* vim-patch:9.1.0554: :bw leaves jumplist and tagstack data around (#29639)zeertzjq2024-07-10
| | | | | | | | | | | | | | | | | Problem: :bw leaves jumplist and tagstack data around (Paul "Joey" Clark) Solution: Wipe jumplist and tagstack references to the wiped buffer (LemonBoy) As documented the :bwipeout command brutally deletes all the references to the buffer, so let's make it delete all the entries in the jump list and tag stack referring to the wiped-out buffer. fixes: vim/vim#8201 closes: vim/vim#15185 https://github.com/vim/vim/commit/4ff3a9b1e3ba45f9dbd0ea8c721f27d9315c4d93 Co-authored-by: LemonBoy <thatlemon@gmail.com>
* feat(jumplist): allow opting out of removing unloaded buffers (#29347)zeertzjq2024-06-30
| | | | Problem: Cannot opt out of removing unloaded buffers from the jumplist. Solution: Only enable that with "unload" flag in 'jumpoptions'.
* revert: "refactor: use S_LEN macro" (#29319)Lewis Russell2024-06-14
| | | | | revert: "refactor: use S_LEN(s) instead of s, n (#29219)" This reverts commit c37695a5d5f2e8914fff86f3581bed70b4c85d3c.
* refactor: use S_LEN(s) instead of s, n (#29219)James2024-06-11
|
* vim-patch:9.1.0469: Cannot have buffer-local value for 'completeopt'zeertzjq2024-06-06
| | | | | | | | | | | | | | Problem: Cannot have buffer-local value for 'completeopt' (Nick Jensen). Solution: Make 'completeopt' global-local (zeertzjq). Also for some reason test Test_ColonEight_MultiByte seems to be failing sporadically now. Let's mark it as flaky. fixes: vim/vim#5487 closes: vim/vim#14922 https://github.com/vim/vim/commit/529b9ad62a0e843ee56ef609aef7e51b7dc8a4c8
* refactor: replace '\0' with NULJames Tirta Halim2024-06-04
|
* refactor: move shared messages to errors.h #26214Justin M. Keyes2024-06-01
|
* vim-patch:9.1.0231: Filetype may be undetected when SwapExists sets ft in ↵zeertzjq2024-04-01
| | | | | | | | | | | | other buf (#28136) Problem: Filetype may be undetected when a SwapExists autocommand sets filetype in another buffer. Solution: Make filetype detection state buffer-specific. Also fix a similar problem for 'modified' (zeertzjq). closes: vim/vim#14344 https://github.com/vim/vim/commit/5bf6c2117fcef85fcf046c098dd3eb72a0147859
* fix(api/buffer): fix handling of viewport of non-current bufferbfredl2024-03-13
| | | | | | | | | | | 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
* vim-patch:9.1.0147: Cannot keep a buffer focused in a windowColin Kennedy2024-03-11
| | | | | | | | | | | | | | | 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 https://github.com/vim/vim/commit/215703563757a4464907ead6fb9edaeb7f430bea N/A patch: vim-patch:58f1e5c0893a
* fix(window): :close may cause Nvim to quit with autocmd and floatzeertzjq2024-03-09
| | | | | | | 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.
* vim-patch:9.1.0116: win_split_ins may not check available roomSean Dewar2024-03-08
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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) https://github.com/vim/vim/commit/0fd44a5ad81ade342cb54d8984965bdedd2272c8 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.
* vim-patch:9.1.0143: [security]: autocmd causes use-after-free in ↵zeertzjq2024-02-29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 https://github.com/vim/vim/commit/55f8bba73be5f9c3a5a4d0d6c5f56e65f2c7d3fc Co-authored-by: Christian Brabandt <cb@256bit.org>
* fix(mbyte): fix bugs in utf_cp_*_off() functionsVanaIgr2024-02-26
| | | | | | 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.
* vim-patch:9.1.0131: buffer-completion may not always find all matches (#27610)zeertzjq2024-02-24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 https://github.com/vim/vim/commit/0dc0bff000fd804c6b0778ccc4554a4e4c82c8c9 Cherry-pick test_cmdline.vim from patch 9.1.0019 as it already passes. Co-authored-by: Christian Brabandt <cb@256bit.org>
* vim-patch:9.1.0113: duplicate code when cleaning undo stackzeertzjq2024-02-16
| | | | | | | | | | | Problem: duplicate code when cleaning undo stack Solution: refactor undo cleanup into a single public function related: vim/vim#13928 https://github.com/vim/vim/commit/9071ed8107244e0c56a16b77d1c28e975cb21dd2 Co-authored-by: Christian Brabandt <cb@256bit.org>
* refactor: rename w_float_config to w_config #27419Will Hopkins2024-02-10
| | | Follows up on rename of `FloatConfig` to `WinConfig` in #27397.
* refactor(api): refactor more api functions to use arena returnbfredl2024-02-08
| | | | | | | | | | | | | | | Currently having two separate memory strategies for API return values is a bit unnecessary, and mostly a consequence of converting the hot spot cases which needed it first. But there is really no downside to using arena everywhere (which implies also directly using strings which are allocated earlier or even statically, without copy). There only restriction is we need to know the size of arrays in advance, but this info can often be passed on from some earlier stage if it is missing. This collects some "small" cases. The more complex stuff will get a PR each.
* fix(jumplist): Ctrl+o, Ctrl+i weird behavior when deleting buffers #25461vE5li2024-01-28
| | | | | | | | | | | | | | Problem: - Navigation is not always symmetric: pressing Ctrl+o n times followed by Ctrl+i n times does not always gets me back to where I started. - Invalid buffers are not skipped by Ctrl+i/o, I have to press Ctrl+i/o multiple times to get to the next/previous buffer. Solution: - Remove all entries of a buffer from the jump list when deleting it. - Don't add a new entry to the jump list if the next buffer to be displayed is already in the jump list. Closes #25365
* vim-patch:9.1.0049: Make "[Command Line]" a special buffer nameSean Dewar2024-01-28
| | | | | | | | | | | | | | | | | 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
* fix(column): keep track of number of lines with number of signsLuuk van Baal2024-01-15
| | | | | | | | | | | | | | | | | | | Problem: Some edge cases to the old (pre-#26406) and current "b_signcols" structure result in an incorrectly sized "auto" 'signcolumn'. Solution: * Implement a simpler 'signcolumn' validation strategy by immediately counting the number of signs in a range upon sign insertion and deletion. Decrease in performance here but there is a clear path forward to decreasing this performance hit by moving signs to a dedicated marktree, or by adding meta-data to the existing marktree which may be queried more efficiently? * Also replace "max_count" and keep track of the number of lines with a certain number of signs. This makes it so that it is no longer necessary to scan the entire buffer when the maximum number of signs decreases. This likely makes the commit a net increase in performance. * To ensure correctness we also have re-initialize the count for an edited region that spans multiple lines. Such an edit may move the signs within it. Thus we count and decrement before splicing the marktree and count and increment after.
* refactor(IWYU): fix headersdundargoc2024-01-11
| | | | | | 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.
* refactor: remove redundant NOLINT commentsdundargoc2024-01-01
|
* refactor: follow style guidedundargoc2023-12-30
|
* refactor: run IWYU on entire repodundargoc2023-12-21
| | | | Reference: https://github.com/neovim/neovim/issues/6371.
* refactor(IWYU): move decor provider types to decoration_defs.h (#26692)zeertzjq2023-12-21
|
* fix(buffer): do not filter help bufferChristian Clason2023-12-20
| | | | | | | | | | | | Problem: If a help buffer is opened without legacy syntax set (because treesitter is enabled), Vim strips (some) markup. This means the syntax engine fails to parse (some) syntax if treesitter highlighting is disabled again. Solution: Do not strip the help buffer of markup since (legacy or treesitter) highlighting is always enabled in Nvim. Similarly, remove redundant setting of filetype and give the function a more descriptive name.
* refactor: use `bool` to represent boolean valuesdundargoc2023-12-19
|
* refactor: move non-symbols to defs.h headersdundargoc2023-12-17
|
* refactor(options): reduce `findoption()` usageFamiu Haque2023-12-09
| | | | | | Problem: Many places in the code use `findoption()` to access an option using its name, even if the option index is available. This is very slow because it requires looping through the options array over and over. Solution: Use option index instead of name wherever possible. Also introduce an `OptIndex` enum which contains the index for every option as enum constants, this eliminates the need to pass static option names as strings.
* perf(column): keep track of number of lines that hold up the 'signcolumn'Luuk van Baal2023-12-07
| | | | | | | | | | | | | | | | | | | | Problem: The entire marktree needs to be traversed each time a sign is removed from the sentinel line. Solution: Remove sentinel line and instead keep track of the number of lines that hold up the 'signcolumn' in "max_count". Adjust this number for added/removed signs, and set it to 0 when the maximum number of signs on a line changes. Only when "max_count" is decremented to 0 due to sign removal do we need to check the entire buffer. Also replace "invalid_top" and "invalid_bot" with a map of invalid ranges, further reducing the number of lines to be checked. Also improve tree traversal when counting the number of signs. Instead of looping over the to be checked range and counting the overlap for each row, keep track of the overlap in an array and add this to the count.