summaryrefslogtreecommitdiffstatshomepage
path: root/src/nvim/undo.c
AgeCommit message (Collapse)AuthorFiles
2026-04-20vim-patch:9.2.0365: using int as bool (#39232)zeertzjq1
Problem: using int as bool Solution: refactor: use bool type for internal flags in buf_T (Hirohito Higashi) Change the type of 23 internal state flag fields in buf_T from int to bool for improved type clarity and code readability. These fields are pure boolean flags that are never accessed via the option system's varp (which uses *(int *)varp = value), never compared with int fields holding non-0/1 values, and never use tristate values. Converted fields: - State flags: b_dev_valid, b_saving, b_mod_set, b_new_change, b_marks_read, b_modified_was_set, b_did_filetype, b_keep_filetype, b_au_did_filetype, b_u_synced, b_scanned, b_p_initialized - Characteristic flags: b_has_textprop, b_may_swap, b_did_warn, b_help, b_spell, b_shortname, b_has_sign_column, b_netbeans_file, b_was_netbeans_file, b_write_to_channel, b_diff_failed All TRUE/FALSE assignments to these fields have been updated to true/false accordingly. The type of temporary save variables (e.g. help_save in tag.c) has also been adjusted to bool. Option value fields (b_p_XXX) are kept as int because they are accessed via the option system and some use tristate (-1) semantics. Fields compared with int option values (b_start_eof, b_start_eol, b_start_bomb) are also kept as int to preserve comparison integrity. closes: vim/vim#20020 https://github.com/vim/vim/commit/1966a1c8963f59c00a9f25d129bec90366205e1b Co-authored-by: Hirohito Higashi <h.east.727@gmail.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-14build: update clang v21, fix warningsdundargoc1
- `src/nvim/ex_cmds_defs.h`: use "U" instead of "u" per `readability-uppercase-literal-suffix`
2026-04-07fix(undo): undefined behavior with empty entry in 'undodir' (#38849)zeertzjq1
Problem: Undefined behavior when 'undodir' contains empty entry. Solution: Don't try to remove trailing slashes from empty path. Also don't remove a colon on Windows while at it.
2026-04-07fix: don't make path empty when truncating trailing slashes (#38844)zeertzjq1
Fixes the following Coverity warning: *** CID 549779: Integer handling issues (INTEGER_OVERFLOW) /src/nvim/undo.c: 717 in u_get_undo_file_name() 711 dir_name[dir_len] = NUL; 712 713 // Remove trailing pathseps from directory name 714 char *p = &dir_name[dir_len - 1]; 715 while (vim_ispathsep(*p)) { 716 *p-- = NUL; >>> CID 549779: Integer handling issues (INTEGER_OVERFLOW) >>> Expression "dir_len--", where "dir_len" is known to be equal to 0, underflows the type of "dir_len--", which is type "size_t". 717 dir_len--; 718 } 719 720 bool has_directory = os_isdir(dir_name); 721 if (!has_directory && *dirp == NUL && !reading) { 722 // Last directory in the list does not exist, create it.
2026-04-06vim-patch:9.2.0291: too many strlen() callszeertzjq1
Problem: too many strlen() calls Solution: refactor concat_fname() and remove calls to strlen() (John Marriott) Function `concat_fnames()` can make up to 5 calls to `STRLEN()` (either directly or indirectly via `STRCAT()`). In many cases the lengths of arguments `fname1` and/or `fname2` are either known or can simply be calculated. This Commit refactors this function to accept the lengths of arguments `fname1` and `fname2` as arguments. It also adds new argument `ret` to return the resulting string as a `string_T`. Additionally: - function `add_pack_dir_to_rtp()` in `scriptfile.c`: Use a `string_T` to store local variables `new_rtp` and `afterdir`. Replace calls to `STRCAT()` with calls to `STRCPY()`. Change type of variable `keep` to `size_t` for consistency with other lengths. - function `qf_get_fnum()` in `quickfix.c`: Use a `string_T` to store local variables `ptr` and `bufname` - function `qf_push_dir()` in `quickfix.c`: Use a `string_T` to store local variable `dirname`. Replace call to `vim_strsave()` with `vim_strnsave()`. - function `qf_guess_filepath()` in `quickfix.c`: Use a `string_T` to store local variable `fullname`. - function `make_percent_swname()` in `memline.c`: Rename some variables to better reflect their use. Use a `string_T` to store local variables `d` and `fixed_name`. Slightly refactor to remove need to create an extra string. - function `get_file_in_dir()` in `memline.c`: Use a `string_T` to store local variables `tail` and `retval`. Move some variables closer to where they are used. - function `cs_resolve_file()` in `if_cscope.c`: Use a `string_T` to store local variable `csdir`. Remove one call to `STRLEN()`. - function `add_pathsep()` in `filepath.c`: Refactor and remove 1 call to `STRLEN()` - function `set_init_xdg_rtp()` in `option.c`: Use a `string_T` to store local variable `vimrc_xdg`. closes: vim/vim#19854 https://github.com/vim/vim/commit/cb51add7ae400a47407fb7fb7b7a54e238d4fdf4 Co-authored-by: John Marriott <basilisk@internode.on.net> Co-authored-by: Christian Brabandt <cb@256bit.org>
2026-03-11fix(prompt): don't implicitly set 'modified' #38118Willaaaaaaa1
Problem: In aec3d7915c55fc0b7dc73f6186cf0ae45d416d33 Vim changed prompt-buffers to respect 'modified' so the termdebug plugin can "control closing the window". But for most use-cases (REPL, shell, AI "chat", …), prompt-buffers are in practice always "modified", and no way to "save" them, so *implicitly* setting 'modified' is noisy and annoying. Solution: Don't implicitly set 'modified' when a prompt-buffer is updated. Plugins/users can still explicitly set 'modified', which will then trigger the "E37: No write since last change" warning.
2026-02-17fix(undo): u_savecommon uses wrong bufferSean Dewar1
Problem: u_savecommon with reload = true wrongly uses curbuf. Solution: use buf. Fix comments.
2026-02-08fix(messages): unwanted newlines with ext_messages #37733luukvbaal1
Problem: Newlines intended to write messages below the cmdline or to mark the start of a new message on message grid are emitted through ext_messages. This results in unnecessary newlines for a UI that has decoupled its message area from the cmdline. msg_col is set directly in some places which is not transmitted to msg_show events. Various missing message kind for list commands. Trailing newlines on various list commands. Solution: Only emit such newlines without ext_messages enabled. Use msg_advance() instead of setting msg_col directly. Assign them the "list_cmd" kind. Ensure no trailing newline is printed.
2026-01-02vim-patch:9.1.2037: undo: cursor position not correctly restored (#37195)zeertzjq1
Problem: undo: cursor position not correctly restored Solution: Do not override the saved cursor position (altermo) closes: vim/vim#19052 https://github.com/vim/vim/commit/a722da29c128576d581f451f3f6282de27680d9f Co-authored-by: altermo <107814000+altermo@users.noreply.github.com>
2025-12-28vim-patch:9.1.2024: 'fsync' option cannot be set per buffer (#37129)zeertzjq1
Problem: 'fsync' option cannot be set per buffer Solution: Make 'fsync' option global-local (glepnir) closes: vim/vim#19019 https://github.com/vim/vim/commit/4d5b30372663e8ea356b25fe94334558c6ae283f Co-authored-by: glepnir <glephunter@gmail.com>
2025-12-15fix(messages): exclude "search hit BOTTOM" msg from history #36961Ayaan1
Problem: :messages history include the "search hit BOTTOM, continuing at TOP" message, which is noise. Solution: Set msg_hist_off before giving the warning and reset it after warning.
2025-08-20vim-patch:8.2.0844: text properties crossing lines not handled correctlyJan Edmund Lazo1
Problem: Text properties crossing lines not handled correctly. Solution: When saving for undo include an extra line when needed and do not adjust properties when undoing. (Axel Forsman, closes vim/vim#5875) ML_DEL_UNDO, ML_APPEND_UNDO are no-opt because textprop feature is N/A. https://github.com/vim/vim/commit/a9d4b84d97fb74061eeb42c1433e111fb58825dc Co-authored-by: Bram Moolenaar <Bram@vim.org>
2025-08-20vim-patch:8.2.4379: an empty change is reported to a listenerJan Edmund Lazo1
Problem: An empty change is reported to a listener. Solution: Do not report an empty change. (closes vim/vim#9768) Remove unused return value. https://github.com/vim/vim/commit/55737c2a31ed450dd7bf2a9c587adfbb32b755bb Co-authored-by: Bram Moolenaar <Bram@vim.org>
2025-08-20vim-patch:8.2.3795: too many #ifdefsJan Edmund Lazo1
Problem: Too many #ifdefs. Solution: Graduate the jumplist feature. https://github.com/vim/vim/commit/739f13a55b4982efb37ebc9282e7f79975fff982 Co-authored-by: Bram Moolenaar <Bram@vim.org>
2025-08-20vim-patch:8.1.2008: error for invalid range when using listener and undoJan Edmund Lazo1
Problem: Error for invalid range when using listener and undo. (Paul Jolly) Solution: Do not change the cursor before the lines are restored. (closes vim/vim#4908) https://github.com/vim/vim/commit/4544bd2f247425c9dd743c76618dd70f53c72538 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-20vim-patch:8.1.1891: functions used in one file are globalJan Edmund Lazo1
Problem: Functions used in one file are global. Solution: Add "static". (Yegappan Lakshmanan, closes vim/vim#4840) https://github.com/vim/vim/commit/5843f5f37b0632e2d706abc9014bfd7d98f7b02e Co-authored-by: Bram Moolenaar <Bram@vim.org>
2024-12-23refactor: iwyu #31637Justin M. Keyes1
Result of `make iwyu` (after some "fixups").
2024-12-22fix(messages): typo and unwanted truncation in msg_outtrans_long #31669luukvbaal1
- Typo/bug in msg_outtrans_long passing string length as "hist" argument. - Avoid truncating message in msg_outtrans_long with ext_messages (followup to 1097d239c307a10a87fa995c4cfbe5987939e177). - Remove `_hl` from `msg_keep`, `smsg_keep` as there is no non-`_hl` variant. - `msg_printf_hl` is removed (identical to `smsg` except it sets `msg_scroll = true`, seemingly as a caveat to force a more prompt in cmdline mode). Move this logic to the only the only place this was used in ex_getln.c.
2024-12-16fix(messages): no message kind for :undo messages #31590Tomasz N1
Problem: cannot handle `:undo` and `:redo` messages in a special way, e.g. replace one by another. Solution: add `undo` kind.
2024-11-23refactor(options): autogenerate valid values and flag enums for options (#31089)Famiu Haque1
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>
2024-11-13refactor(highlight): make enum of builtin highlights start with 1bfredl1
This makes it possible to use HLF_ values directly as highlight id:s and avoids +1 adjustments especially around messages.
2024-11-08refactor(message): propagate highlight id instead of attrsLuuk van Baal1
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.
2024-08-05refactor(shada): rework msgpack decoding without msgpack-cbfredl1
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.
2024-07-30refactor: collapse statements in single assignmentsLewis Russell1
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; ```
2024-06-01refactor: move shared messages to errors.h #26214Justin M. Keyes1
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-02-16vim-patch:9.1.0113: duplicate code when cleaning undo stackzeertzjq1
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>
2024-02-12fix(extmarks): redraw pre-undo position (#27437)zeertzjq1
Problem: Virtual text not redrawn properly after undo moves its extmark. Solution: Redraw the moved extmark's pre-undo position.
2024-01-27fix(column): clear "b_signcols" before moving saved marksLuuk van Baal1
Problem: Marks moved by undo may be lost to "b_signcols.count". Solution: Count signs for each undo object separately instead of once for the entire undo.
2024-01-25refactor: IWYU (#27186)zeertzjq1
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-17fix(column): remove sign from line it was previously on with undoLuuk van Baal1
2024-01-15fix(column): keep track of number of lines with number of signsLuuk van Baal1
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.
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-12-21refactor: run IWYU on entire repodundargoc1
Reference: https://github.com/neovim/neovim/issues/6371.
2023-12-18docs: add style rule regarding initializationdundargoc1
Specifically, specify that each initialization should be done on a separate line.
2023-12-12fix(extmarks): `U` changed_bytes after extmark_splice (#26501)Jaehwang Jung1
See also: https://github.com/neovim/neovim/pull/26364
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-29refactor: move some constants out of vim_defs.h (#26298)zeertzjq1
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-27build: enable IWYU on macdundargoc1
2023-11-27build(IWYU): replace most private mappings with pragmas (#26247)zeertzjq1
2023-11-20refactor: enable formatting for ternariesdundargoc1
This requires removing the "Inner expression should be aligned" rule from clint as it prevents essentially any formatting regarding ternary operators.
2023-11-19refactor: follow style guidedundargoc1
- reduce variable scope - prefer initialization over declaration and assignment
2023-11-13fix(textformat): remove unnecessary changed_bytes() (#26027)zeertzjq1
This was removed from Vim in patch 8.1.0681.