summaryrefslogtreecommitdiffstatshomepage
path: root/src/nvim/diff.c
AgeCommit message (Collapse)AuthorFiles
2026-03-17feat(diff): merge adjacent blocks using inline:word (#37085)Harsh Kapse1
vim-patch:9.2.0174: diff: inline word-diffs can be fragmented Problem: When using 'diffopt=inline:word', lines were excessively fragmented with punctuation creating separate highlight blocks, making it harder to read the diffs. Solution: Added 'diff_refine_inline_word_highlight()' to merge adjacent diff blocks that are separated by small gaps of non-word characters (up to 5 bytes by default) (HarshK97). When using inline:word diff mode, adjacent changed words separated by punctuation or whitespace are now merged into a single highlight block if the gap between them contains fewer than 5 non-word characters. This creates more readable diffs and closely matches GitHub's own diff display. closes: vim/vim#19098 https://github.com/vim/vim/commit/42c6686c78d39843f71dba989a8ea59bc6975132
2026-01-30vim-patch:9.1.2118: 'cursorline' missing after :diffput to empty buf (#37628)zeertzjq1
Problem: 'cursorline' and part of 'statusline' are missing after :diffput to an empty buffer. Solution: Make sure the cursor doesn't go beyond the last line after :diffput (zeertzjq) related: neovim/neovim#37621 closes: vim/vim#19281 https://github.com/vim/vim/commit/ce1e562fdafa998e577d65a8b0a1b8bc1cbfcf4c
2026-01-14vim-patch:9.1.2085: Use-after-free in winframe_remove()zeertzjq1
Problem: Use-after-free in winframe_remove() (henices) Solution: Set window_layout_locked() inside winframe_remove() and check that writing diff files is disallowed when the window layout is locked. It can happen with a custom diff expression when removing a window: 1. Buffer was removed, so win_frame_remove() is called to remove the window. 2. win_frame_remove() → frame_new_height() → scroll_to_fraction() → diff_check_fill() (checks for filler lines) 3. diff_check_fill() ends up causing a diff_try_update, and because we are not using internal diff, it has to first write the file to a buffer using buf_write() 4. buf_write() is called for a buffer that is not contained within a window, so it first calls aucmd_prepbuf() to create a new temporary window before writing the buffer and then later calls aucmd_restbuf(), which restores the previous window layout, calling winframe_remove() again, which will free the window/frame structure, eventually freeing stuff that will still be accessed at step 2. closes: vim/vim#19064 https://github.com/vim/vim/commit/ead1dda74a485ef0470e7252d07c1a36b8cde517 Nvim doesn't have this bug as Nvim uses a floating window as autocommand window, and removing it doesn't need winframe_remove(). Co-authored-by: Christian Brabandt <cb@256bit.org>
2026-01-12vim-patch:9.1.2078: A few more typos in various files (#37368)zeertzjq1
Problem: A few more typos in various files Solution: Fix those (zeertzjq, antonkesy) related: neovim/neovim#37348 closes: vim/vim#19153 https://github.com/vim/vim/commit/6a2b5b2246833f7922e38eabab7090e29e89c3a1 Co-authored-by: Anton Kesy <anton@kesy.de>
2026-01-05vim-patch:8.1.0753: printf format not checked for semsg() (#37248)zeertzjq1
Problem: printf format not checked for semsg(). Solution: Add GNUC attribute and fix reported problems. (Dominique Pelle, closes vim/vim#3805) https://github.com/vim/vim/commit/b5443cc46dd1485d6c785dd8c65a2c07bd5a17f3 Cherry-pick a change from patch 8.2.3830. Co-authored-by: Bram Moolenaar <Bram@vim.org>
2026-01-01vim-patch:8.2.2198: ml_get error when resizing window and using text propertyJan Edmund Lazo1
Problem: ml_get error when resizing window and using text property. Solution: Validate botline of the right window. (closes vim/vim#7528) https://github.com/vim/vim/commit/23999d799cfe844b604f193183f8f84052c8e746 Migrate to Vim's (in)validate_botline_win() API. Nvim wants to pass "curwin" instead of hiding them behind alias/macro/inline-function. https://github.com/neovim/neovim/pull/37164#discussion_r2655006908 Co-authored-by: Bram Moolenaar <Bram@vim.org>
2025-12-09vim-patch:9.1.1963: diff: missing diff size limit for xdiff (#36877)zeertzjq1
Problem: diff: missing diff size limit for xdiff Solution: Impose file size limit for internal diff (xdiff) (Yee Cheng Chin). Git imposes a hard cap on file size for content that it passes to xdiff (added to Git in dcd1742e56e, defined in xdiff-interface.h), due to integer overflow concerns in xdiff. Vim doesn't specify such a limit right now, which means it's possible for a user to diff a large file (1GB+) and trigger these overflow issues. Add the same size limit (1GB minus 1MB) to Vim and simply throws an error when Vim encounters files larger than said limit. For now, reuse the same error message regarding internal diff failures. There is no need to add the same limit for external diff as it's up to each tool to error check their input to decide what is appropriate or not. closes: vim/vim#18891 https://github.com/vim/vim/commit/4af6d9755cba0dd07e881172f2a6e0efe9986ddc Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
2025-10-05vim-patch:8.1.1957: more code can be moved to evalvars.cJan Edmund Lazo1
Problem: More code can be moved to evalvars.c. Solution: Move code to where it fits better. (Yegappan Lakshmanan, closes vim/vim#4883) https://github.com/vim/vim/commit/da6c03342117fb7f4a8110bd9e8627b612a05a64 Co-authored-by: Bram Moolenaar <Bram@vim.org>
2025-10-04vim-patch:9.1.1823: diff: w_topline may be invalidated (#36018)zeertzjq1
Problem: diff: w_topline may be invalidated Solution: Update lnum in diff_set_topline() (Yee Cheng Chin). This can happen in ex_diffupdate() for certain edge cases which cause the logic to now be wrong. This was also the root cause for vim/vim#18437 where Vim would crash due to a null pointer dereferencing (said pointer would not be null under normal circumstances). related: vim/vim#18437 closes: vim/vim#18484 https://github.com/vim/vim/commit/dd9ed46a39df8a8b08ef4b491fdf53bcbfdc0c2d Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
2025-10-02vim-patch:9.1.1818: possible crash when calculating topline in diff.czeertzjq1
Problem: possible crash when calculating topline in diff.c (youngmith) Solution: Check for pointer being Null before accessing it fixes: vim/vim#18437 https://github.com/vim/vim/commit/d32b3bb7ebe29f856a054cfd552c68afabd065c3 The POC is likely not applicable to Nvim due to #32160. Co-authored-by: Christian Brabandt <cb@256bit.org>
2025-09-15vim-patch:9.1.1758: Diff mode crashes when adding text property in ↵zeertzjq1
autocommand (#35760) Problem: Diff mode crashes when adding text property in autocommand (after 9.1.1557). Solution: Only restore ML_EMPTY memline flag, ignore the others (zeertzjq). fixes: vim/vim#18288 closes: vim/vim#18291 https://github.com/vim/vim/commit/46e22fd2f73b03795a5922ba07621472713eddb3
2025-09-12vim-patch:9.1.1753: defaults: 'diffopt' option value can be improved (#35727)zeertzjq1
Problem: defaults: 'diffopt' option value can be improved Solution: Update diffopt defaults to include "indent-heuristic" and "inline:char" (Yee Cheng Chin) The default diff options have not been updated much despite new functionality having been added to Vim. - indent-heurstic: This has been enabled by default in Git since 33de716387 in 2017. Given that Vim uses xdiff from Git, it makes sense to track the default configuration from Git. - inline:char: This turns on character-wise inline highlighting which is generally much better than the default inline:simple. It has been implemented since vim/vim#16881 and we have not seen reports of any issues with it, and it has received good feedbacks. closes: vim/vim#18255 https://github.com/vim/vim/commit/976b365305c2e9025813ff3c7fe52f8d927fafc3 Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
2025-08-24fix(diff): set default diff flags properly (#35450)zeertzjq1
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-08-07vim-patch:9.1.1600: using diff anchors with hidden buffers fails silently ↵zeertzjq1
(#35218) Problem: diff: using diff anchors with hidden buffers fails silently Solution: Give specific error message for diff anchors when using hidden buffers (Yee Cheng Chin). Diff anchors currently will fail to parse if a buffer used for diff'ing is hidden. Previously it would just fail as the code assumes it would not happen normally, but this is actually possible to do if `closeoff` and `hideoff` are not set in diffopt. Git's default diff tool "vimdiff3" also takes advantage of this. This fix this properly would require the `{address}` parser to be smarter about whether a particular address relies on window position or not (e.g. the `'.` address requires an active window, but `'a` or `1234` do not). Since hidden diff buffers seem relatively niche, just provide a better error message / documentation for now. This could be improved later if there's a demand for it. related: vim/vim#17615 closes: vim/vim#17904 https://github.com/vim/vim/commit/cad3b2421de7b703e0ee619850a8a3bc55454281 Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
2025-07-20vim-patch:9.1.1567: crash when using inline diff mode (#35005)zeertzjq1
Problem: Crash when using inline diff mode (Ilya Grigoriev) Solution: Set tp_diffbuf to NULL when skipping a diff block (Yee Cheng Chin). Fix an array out of bounds crash when using diffopt+=inline:char when 4 or more buffers are being diff'ed. This happens when one of the blocks is empty. The inline highlight logic skips using that buffer's block, but when another buffer is used later and calls diff_read() to merge the diff blocks together, it could erroneously consider the empty block's diff info which has not been initialized, leaving to diff numbers that are invalid. Later on the diff num is used without bounds checking which leads to the crash. Fix this by making sure to unset tp_diffbuf to NULL when we skip a block, so diff_read() will not consider this buffer to be used within inline diff. Also, add more bounds checking just to be safe. closes: vim/vim#17805 https://github.com/vim/vim/commit/c8b99e2d139cf72c567892e44939f2719f703fa8 Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
2025-07-18vim-patch:9.1.1557: not possible to anchor specific lines in diff mode (#34967)zeertzjq1
Problem: not possible to anchor specific lines in diff mode Solution: Add support for the anchoring lines in diff mode using the 'diffanchor' option (Yee Cheng Chin). Adds support for anchoring specific lines to each other while viewing a diff. While lines are anchored, they are guaranteed to be aligned to each other in a diff view, allowing the user to control and inform the diff algorithm what the desired alignment is. Internally, this is done by splitting up the buffer at each anchor and run the diff algorithm on each split section separately, and then merge the results back for a logically consistent diff result. To do this, add a new "diffanchors" option that takes a list of `{address}`, and a new "diffopt" option value "anchor". Each address specified will be an anchor, and the user can choose to use any type of address, including marks, line numbers, or pattern search. Anchors are sorted by line number in each file, and it's possible to have multiple anchors on the same line (this is useful when doing multi-buffer diff). Update documentation to provide examples. This is similar to Git diff's `--anchored` flag. Other diff tools like Meld/Araxis Merge also have similar features (called "synchronization points" or "synchronization links"). We are not using Git/Xdiff's `--anchored` implementation here because it has a very limited API (it requires usage of the Patience algorithm, and can only anchor unique lines that are the same across both files). Because the user could anchor anywhere, diff anchors could result in adjacent diff blocks (one block is directly touching another without a gap), if there is a change right above the anchor point. We don't want to merge these diff blocks because we want to line up the change at the anchor. Adjacent diff blocks were first allowed when linematch was added, but the existing code had a lot of branched paths where line-matched diff blocks were handled differently. As a part of this change, refactor them to have a more unified code path that is generalized enough to handle adjacent diff blocks correctly and without needing to carve in exceptions all over the place. closes: vim/vim#17615 https://github.com/vim/vim/commit/0d9160e11ce4b921adff1e5621dd989ce96fb0f3 Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
2025-06-22vim-patch:9.1.1473: inconsistent range arg for :diffget/diffput (#34588)zeertzjq1
Problem: inconsistent range arg for :diffget/diffput Solution: fix the range specification, place the cursor for :diffput and :diffget consistently on the last line (Yee Cheng Chin) Previously, `:<range>diffget` only allowed using 1 or above in the range value, making it impossible to use the command for a diff block at the beginning of the file. Fix the range specification so the user can now use 0 to specify the space before the first line. This allows `:0,$+1diffget` to work to retrieve all the changes from the other file instead of missing the first diff block. Also do this for `:diffput`. Also, make `:diffput` work more similar to `:diffget`. Make it so that if the cursor is on the last line and a new line is inserted in the other file, doing `:diffput` will select that diff block below the line, just like `:diffget` would. Also clean up the logic a little bit for edge cases and for handling line matched diff blocks better. closes: vim/vim#17579 https://github.com/vim/vim/commit/d75ab0cbf5cfaefab3edb0aa553954de70b236f8 Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
2025-06-09vim-patch:9.1.1439: Last diff folds not merged (#34380)zeertzjq1
Problem: Last diff folds not merged (after v8.1.1922) Solution: loop over all windows in the current tabpage and update all folds (Gary Johnson) This commit fixes a bug where the last two folds of a diff are not merged when the last difference between the two diff'd buffers is resolved. Normally, when two buffers are diff'd, folding is used to show only the text that differs and to hide the text that is the same between the two buffers. When a difference is resolved by making a block of text the same in both buffers, the folds are updated to merge that block with the folds above and below it into one closed fold. That updating of the folds did not occur when the block of text was the last diff block in the buffers. The bug was introduced by this patch on August 24, 2019: patch 8.1.1922: in diff mode global operations can be very slow Problem: In diff mode global operations can be very slow. Solution: Do not call diff_redraw() many times, call it once when redrawing. And also don't update folds multiple times. Unfortunately, folds were then not updated often enough. The problem was fixed by adding a short loop to the ex_diffgetput() function in diff.c to update all the folds in the current tab when the last difference is removed. A test for this was added to test_diffmode.vim. Two of the reference screen dumps for another test in that file, Test_diffget_diffput_linematch(), had to be changed to have all the folds closed rather than to have the last diff block remain open. closes: vim/vim#17457 https://github.com/vim/vim/commit/3fa0d3514b928e0b21ef24594785f9104a3ffafd Co-authored-by: Gary Johnson <garyjohn@spocom.com>
2025-06-06fix(diff): fix incorrect item size of dout_ga (#34338)zeertzjq1
Related https://github.com/neovim/neovim/commit/267494151bcc6e4fff7b9b8c80b7a5f42e2aa002
2025-04-19vim-patch:9.1.1319: Various typos in the code, issue with ↵zeertzjq1
test_inst_complete.vim (#33527) Problem: Various typos in the code, redundant and strange use of :execute in test_ins_complete.vim (after 9.1.1315). Solution: Fix typos in the code and in the documentation, use the executed command directly (zeertzjq). closes: vim/vim#17143 https://github.com/vim/vim/commit/98800979dc109e03f390a0472b14ed89189e02fe Co-authored-by: Christ van Willegen <cvwillegen@gmail.com>
2025-04-16fix(env.c): drop envmap, free os_getenv() result #32683Judit Novak1
Problem: vim.uv.os_setenv gets "stuck" per-key. #32550 Caused by the internal `envmap` cache. #7920 :echo $FOO <-- prints nothing :lua vim.uv.os_setenv("FOO", "bar") :echo $FOO <-- prints bar (as expected) :lua vim.uv.os_setenv("FOO", "fizz") :echo $FOO <-- prints bar, still (not expected. Should be "fizz") :lua vim.uv.os_unsetenv("FOO") :echo $FOO <-- prints bar, still (not expected. Should be nothing) :lua vim.uv.os_setenv("FOO", "buzz") :echo $FOO <-- prints bar, still (not expected. Should be "buzz") Solution: - Remove the `envmap` cache. - Callers to `os_getenv` must free the result. - Update all call-sites. - Introduce `os_getenv_noalloc`. - Extend `os_env_exists()` the `nonempty` parameter.
2025-04-05vim-patch:9.1.1276: inline word diff treats multibyte chars as word char ↵zeertzjq1
(#33323) Problem: inline word diff treats multibyte chars as word char (after 9.1.1243) Solution: treat all non-alphanumeric characters as non-word characters (Yee Cheng Chin) Previously inline word diff simply used Vim's definition of keyword to determine what is a word, which leads to multi-byte character classes such as emojis and CJK (Chinese/Japanese/Korean) characters all classifying as word characters, leading to entire sentences being grouped as a single word which does not provide meaningful information in a diff highlight. Fix this by treating all non-alphanumeric characters (with class number above 2) as non-word characters, as there is usually no benefit in using word diff on them. These include CJK characters, emojis, and also subscript/superscript numbers. Meanwhile, multi-byte characters like Cyrillic and Greek letters will still continue to considered as words. Note that this is slightly inconsistent with how words are defined elsewhere, as Vim usually considers any character with class >=2 to be a "word". related: vim/vim#16881 (diff inline highlight) closes: vim/vim#17050 https://github.com/vim/vim/commit/9aa120f7ada592ed03b37f4de8ee413c5385f123 Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
2025-03-29refactor(diff): remove unreachable code (#33149)zeertzjq1
2025-03-28vim-patch:9.1.1246: coverity complains about some changes in v9.1.1243zeertzjq1
Problem: coverity complains about some changes in v9.1.1243 Solution: remove duplicate code in diff_find_changed() (Yee Cheng Chin) closes: vim/vim#16988 https://github.com/vim/vim/commit/4f9b1243e3ef60b9efb64a4e789c55be3cdc7a25 Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
2025-03-28vim-patch:9.1.1243: diff mode is lacking for changes within lineszeertzjq1
Problem: Diff mode's inline highlighting is lackluster. It only performs a line-by-line comparison, and calculates a single shortest range within a line that could encompass all the changes. In lines with multiple changes, or those that span multiple lines, this approach tends to end up highlighting much more than necessary. Solution: Implement new inline highlighting modes by doing per-character or per-word diff within the diff block, and highlight only the relevant parts, add "inline:simple" to the defaults (which is the old behaviour) This change introduces a new diffopt option "inline:<type>". Setting to "none" will disable all inline highlighting, "simple" (the default) will use the old behavior, "char" / "word" will perform a character/word-wise diff of the texts within each diff block and only highlight the differences. The new char/word inline diff only use the internal xdiff, and will respect diff options such as algorithm choice, icase, and misc iwhite options. indent-heuristics is always on to perform better sliding. For character highlight, a post-process of the diff results is first applied before we show the highlight. This is because a naive diff will create a result with a lot of small diff chunks and gaps, due to the repetitive nature of individual characters. The post-process is a heuristic-based refinement that attempts to merge adjacent diff blocks if they are separated by a short gap (1-3 characters), and can be further tuned in the future for better results. This process results in more characters than necessary being highlighted but overall less visual noise. For word highlight, always use first buffer's iskeyword definition. Otherwise if each buffer has different iskeyword settings we would not be able to group words properly. The char/word diffing is always per-diff block, not per line, meaning that changes that span multiple lines will show up correctly. Added/removed newlines are not shown by default, but if the user has 'list' set (with "eol" listchar defined), the eol character will be be highlighted correctly for the specific newline characters. Also, add a new "DiffTextAdd" highlight group linked to "DiffText" by default. It allows color schemes to use different colors for texts that have been added within a line versus modified. This doesn't interact with linematch perfectly currently. The linematch feature splits up diff blocks into multiple smaller blocks for better visual matching, which makes inline highlight less useful especially for multi-line change (e.g. a line is broken into two lines). This could be addressed in the future. As a side change, this also removes the bounds checking introduced to diff_read() as they were added to mask existing logic bugs that were properly fixed in vim/vim#16768. closes: vim/vim#16881 https://github.com/vim/vim/commit/9943d4790e42721a6777da9e12637aa595ba4965 Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
2025-03-27refactor(eval): move diff functions to diff.c (#33085)zeertzjq1
They were moved in Vim in patch 8.1.1989. This change is required to port patch 9.1.1243.
2025-03-03vim-patch:9.1.1165: diff: regression with multi-file diff blocks (#32702)zeertzjq1
Problem: Vim's diff block merging algorithm when doing a multi-file diff is buggy when two different diff hunks overlap a single existing diff block (after v9.1.0743) Solution: fix a couple bugs in this logic: 1. Fix regression from v9.1.0743 where it's not correctly expanding the 2nd overlap correctly, where it always expands without taking into account that this was always taken care of when the first overlap happened. Instead, we should only grow the 2nd overlap if it overhangs outside the existing diff block, and if we encounter a new overlapping diff block (due to overlap chaining). 2. When we expand a diff block to match the hunk size on the orig side (when handling the first overlap), we expand the same amount of lines in the new side. This is not sound if there exists a second overlap hunk that we haven't processed yet, and that hunk has different number of lines in orig/new. Fix this by doing the corresponding counter adjustment when handling 2nd/3rd/etc overlap by calculating the difference in lines between orig and new side. (Yee Cheng Chin) closes: vim/vim#16768 https://github.com/vim/vim/commit/bc08ceb75572dcac57ef5019f3d0df6e8290c0f9 Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
2025-02-25feat(marks): add conceal_lines to nvim_buf_set_extmark()Luuk van Baal1
Implement an extmark property that conceals lines vertically.
2025-02-04vim-patch:9.1.1027: no sanitize check when running linematchzeertzjq1
Problem: no sanitize check when running linematch Solution: add sanitize check before applying the linematch algorithm, similar to diff_find_change() (Jonathon) closes: vim/vim#16446 https://github.com/vim/vim/commit/ca307efe486670b76563a4a287bc94dace57fb74 Co-authored-by: Jonathon <jonathonwhite@protonmail.com>
2025-02-04vim-patch:9.1.1023: Coverity complains about dereferencing NULL pointerzeertzjq1
Problem: Coverity complains about dereferencing NULL pointer Solution: Verify curdiff is not null before dereferencing it closes: vim/vim#16437 https://github.com/vim/vim/commit/a9f77be9223f8b886d89f7fac778d363586beb85 Co-authored-by: Christian Brabandt <cb@256bit.org>
2025-02-04vim-patch:9.1.1009: diff feature can be improvedzeertzjq1
Problem: diff feature can be improved Solution: include the linematch diff alignment algorithm (Jonathon) closes: vim/vim#9661 https://github.com/vim/vim/commit/7c7a4e6d1ad50d5b25b42aa2d5a33a8d04a4cc8a Co-authored-by: Jonathon <jonathonwhite@protonmail.com>
2025-01-16vim-patch:9.1.1018: v9.1.0743 causes regression with diff mode (#32047)zeertzjq1
Problem: v9.1.0743 causes regression with diff mode Solution: Fix the regression with overlapping regions closes: vim/vim#16454 https://github.com/vim/vim/commit/01f6509fb2de1627cc4ec2c109cd0aa2e3346d50 Co-authored-by: Yukihiro Nakadaira <yukihiro.nakadaira@gmail.com>
2025-01-09Revert "refactor(options): set option value for non-current context ↵zeertzjq1
directly" (#31924) Reverts #31112
2024-12-26refactor(options): set option value for non-current context directlyFamiu Haque1
Problem: Currently, we use `switch_option_context` to temporarily switch the current option context before setting an option for a different buffer / window. This is not ideal because we already support getting and setting option values for non-current contexts in the underlying implementation. Solution: Set option value for non-current context by passing the context directly to the lower level functions. Also introduce a new `OptCtx` struct to store option context information, this will scale much better if we add more option scopes and other context information in the future.
2024-12-23refactor: iwyu #31637Justin M. Keyes1
Result of `make iwyu` (after some "fixups").
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-16refactor(options): remove `.indir`, redesign option scopes #31066Famiu Haque1
Problem: The way option scopes currently work is inflexible and does not allow for nested option scopes or easily finding the value of an option at any arbitrary scope without having to do long handwritten switch-case statements like in `get_varp()`. `.indir` is also confusing and redundant since option indices for each scope can be autogenerated. Solution: Expand option scopes in such a way that an option can support any amount of scopes using a set of scope flags, similarly to how it's already done for option types. Also make options contain information about its index at each scope it supports. This allows for massively simplifying `get_varp()` and `get_varp_scope()` in the future by just using a struct for options at each scope. This would be done by creating a table that stores the offset of an option's variable at a scope by using the option's index at that scope as a key. This PR also autogenerates enums for option indices at each scope to remove the need for `.indir` entirely, and also to allow easily iterating over options all options that support any scope. Ref: #29314
2024-11-05refactor(options): remove fileformat macrosFamiu Haque1
2024-09-30fix(diff): use mmfile_t in linematchLewis Russell1
Problem: Linematch used to use strchr to navigate a string, however strchr does not supoprt embedded NULs. Solution: Use `mmfile_t` instead of `char *` in linematch and introduce `strnchr()`. Also remove heap allocations from `matching_char_iwhite()` Fixes: #30505
2024-09-27vim-patch:9.1.0743: diff mode does not handle overlapping diffs correctly ↵zeertzjq1
(#30532) Problem: diff mode does not handle overlapping diffs correctly Solution: correct the logic to handle overlapping blocks (Yukihiro Nakadaira) Vim merges overlapped diff blocks and it doesn't work expectedly in some situation. closes: vim/vim#15735 https://github.com/vim/vim/commit/06fe70c183a53ea97cd42ace490d4fb9fd14f042 Co-authored-by: Yukihiro Nakadaira <yukihiro.nakadaira@gmail.com>
2024-09-23vim-patch:9.1.0740: incorrect internal diff with empty file (#30471)zeertzjq1
Problem: incorrect internal diff with an empty file Solution: Set pointer to NULL, instead of using an empty line file (Yukihiro Nakadaira) When using internal diff, empty file is read as one empty line file. So result differs from external diff. closes: vim/vim#15719 https://github.com/vim/vim/commit/f1694b439bb175d956b49da620f1253462ec507b Co-authored-by: Yukihiro Nakadaira <yukihiro.nakadaira@gmail.com>
2024-08-15feat(diff): do not try external when out of memoryLewis Russell1
- Also merge diff_buf_idx_tp into diff_buf_idx.
2024-07-31fix(scrollbind): properly take filler/virtual lines into accountLewis Russell1
Problem: `'scrollbind'` does not work properly if the window being scrolled automatically contains any filler/virtual lines (except for diff filler lines). This is because when the scrollbind check is done, the logic only considers changes to topline which are represented as line numbers. Solution: Write the logic for determine the scroll amount to take into account filler/virtual lines. Fixes #29751
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-07-15docs: misc (#29622)dundargoc1
Co-authored-by: Christian Clason <c.clason@uni-graz.at> Co-authored-by: zeertzjq <zeertzjq@outlook.com>
2024-06-14revert: "refactor: use S_LEN macro" (#29319)Lewis Russell1
revert: "refactor: use S_LEN(s) instead of s, n (#29219)" This reverts commit c37695a5d5f2e8914fff86f3581bed70b4c85d3c.
2024-06-11Merge pull request #29278 from bfredl/strcatbfredl1
refactor(memory): use builtin strcat() instead of STRCAT()
2024-06-11refactor: use S_LEN(s) instead of s, n (#29219)James1