aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/fold.c
Commit message (Collapse)AuthorAge
* vim-patch:9.1.1015: Coverity complains about dereferencing NULL value (#32020)zeertzjq2025-01-15
| | | | | | | | | | Problem: Coverity complains about dereferencing NULL value Solution: Check that cms2 is not null closes: vim/vim#16438 https://github.com/vim/vim/commit/1ac53b84ada3a992f320566737e66fa00d48611f Co-authored-by: Christian Brabandt <cb@256bit.org>
* refactor(options): remove `.indir`, redesign option scopes #31066Famiu Haque2024-11-16
| | | | | | | | | | | | | | | | | | | | | | 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
* vim-patch:9.1.0672: marker folds may get corrupted on undo (#30026)zeertzjq2024-08-11
| | | | | | | | | | | | | Problem: marker folds may get corrupted on undo (Yousef Mohammed) Solution: when adjusting folds, make sure that line1 is the lower limit and line2 is the upper line limit. In particular, line2 should not be able to get smaller than line1. fixes: vim/vim#15455 closes: vim/vim#15466 https://github.com/vim/vim/commit/8d02e5cf961b06da5bc490ac5972bcbc252c4793 Co-authored-by: Christian Brabandt <cb@256bit.org>
* 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; ```
* refactor(memory): use builtin strcat() instead of STRCAT()bfredl2024-06-11
| | | | | | | | The latter was mostly relevant with the past char_u madness. NOTE: STRCAT also functioned as a counterfeit "NOLINT" for clint apparently. But NOLINT-ing every usecase is just the same as disabling the check entirely.
* refactor: move shared messages to errors.h #26214Justin M. Keyes2024-06-01
|
* refactor: add xmemcpyz() and use it in place of some xstrlcpy() (#28422)zeertzjq2024-04-20
| | | | | | Problem: Using xstrlcpy() when the exact length of the string to be copied is known is not ideal because it requires adding 1 to the length and an unnecessary strlen(). Solution: Add xmemcpyz() and use it in place of such xstrlcpy() calls.
* vim-patch:9.1.0177: Coverity reports dead codezeertzjq2024-03-14
| | | | | | | | | | 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 https://github.com/vim/vim/commit/8c55d60658b7ee3458dca57fc5eec90ca9bb9bf3
* vim-patch:9.1.0172: More code can use ml_get_buf_len() instead of STRLEN()zeertzjq2024-03-14
| | | | | | | | | | | | 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 https://github.com/vim/vim/commit/94b7c3233ef534acc669b3083ed1fe59cf3a090b
* 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
* refactor(api): reduce temporary allocations when replacing linesbfredl2024-02-20
| | | | | | | | | | | | | | | 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.
* 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.
* vim-patch:9.1.0002: a closing fold expr, may start a new fold (#26876)zeertzjq2024-01-04
| | | | | | | | | | | | | | | Problem: a closing fold expression may unexpectedly start a new fold when it should end a fold (reported by Shota Nozaki) Solution: if a fold hasn't started yet, do not immediately start a new fold with level 1 (Shota Nozaki) fixes: vim/vim#12768 closes: vim/vim#13748 https://github.com/vim/vim/commit/0689b870595c687a23e102913ce5037f65d03748 Co-authored-by: Shota Nozaki <emonkak@gmail.com>
* refactor: follow style guidedundargoc2023-12-30
|
* refactor(options): generate BV_ and WV_ constants (#26705)zeertzjq2023-12-22
|
* refactor: run IWYU on entire repodundargoc2023-12-21
| | | | Reference: https://github.com/neovim/neovim/issues/6371.
* refactor: use `bool` to represent boolean valuesdundargoc2023-12-19
|
* docs: add style rule regarding initializationdundargoc2023-12-18
| | | | | Specifically, specify that each initialization should be done on a separate line.
* build: don't define FUNC_ATTR_* as empty in headers (#26317)zeertzjq2023-11-30
| | | | | | 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.
* refactor: move some constants out of vim_defs.h (#26298)zeertzjq2023-11-29
|
* refactor: fix headers with IWYUdundargoc2023-11-28
|
* refactor: rename types.h to types_defs.hdundargoc2023-11-27
|
* build(IWYU): fix includes for undo_defs.hdundargoc2023-11-27
|
* build(IWYU): fix includes for func_attr.hdundargoc2023-11-27
|
* refactor: move garray_T to garray_defs.h (#26227)zeertzjq2023-11-26
|
* build: rework IWYU mapping filesdundargoc2023-11-25
| | | | | Create mapping to most of the C spec and some POSIX specific functions. This is more robust than relying files shipped with IWYU.
* build: remove PVSdundargoc2023-11-12
| | | | | | | 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.
* refactor: remove redundant castsdundargoc2023-11-11
|
* refactor: the long goodbyedundargoc2023-11-05
| | | | | | long is 32 bits on windows, while it is 64 bits on other architectures. This makes the type suboptimal for a codebase meant to be cross-platform. Replace it with more appropriate integer types.
* build(lint): remove unnecessary clint.py rulesdundargoc2023-10-23
| | | | | Uncrustify is the source of truth where possible. Remove any redundant checks from clint.py.
* refactor: the long goodbyedundargoc2023-10-09
| | | | | | long is 32 bits on windows, while it is 64 bits on other architectures. This makes the type suboptimal for a codebase meant to be cross-platform. Replace it with more appropriate integer types.
* refactor: reorganize option header files (#25437)zeertzjq2023-09-30
| | | | | | - Move vimoption_T to option.h - option_defs.h is for option-related types - option_vars.h corresponds to Vim's option.h - option_defs.h and option_vars.h don't include each other
* build(iwyu): add a few more _defs.h mappings (#25435)zeertzjq2023-09-30
|
* fix(ui): handle virtual text with multiple hl in more cases (#25304)zeertzjq2023-09-22
|
* feat(folds): support virtual text format for 'foldtext' (#25209)zeertzjq2023-09-17
| | | Co-authored-by: Lewis Russell <lewis6991@gmail.com>
* refactor(change): do API changes to buffer without curbuf switchbfredl2023-08-26
| | | | | | | | | | | | | | | | | | | | | | | 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.
* refactor(memline): distinguish mutating uses of ml_get_buf()bfredl2023-08-24
| | | | | | | | | | | | | | 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.
* fix(folds): update folds in Insert mode with fdm=indent (#24402)Brandon Simmons2023-07-21
| | | | | | | | | | | Previously, when using foldmethod=indent, inserting an unindented line would inadvertently open closed folds below it. As a performance improvement, folds were only updated once, across all lines, after Insert mode was exited. Now, the performance improvement is no longer being used when foldmethod=indent, so folds are updated multiple times during Insert mode, but only across the lines that are changing, which preserves the folds (and their open/close states) instead of recreating them.
* refactor: uncrustifydundargoc2023-04-26
| | | | Notable changes: replace all infinite loops to `while(true)` and remove `int` from `unsigned int`.
* vim-patch:8.2.4179: 'foldtext' is evaluated in the current script contextzeertzjq2023-04-17
| | | | | | | | | | | Problem: 'foldtext' is evaluated in the current script context. Solution: Use the script context where the option was set. https://github.com/vim/vim/commit/9530b580a7b71960dbbdb2b12a3aafeb540bd135 Script version is N/A. Co-authored-by: Bram Moolenaar <Bram@vim.org>
* vim-patch:8.2.1049: Vim9: leaking memory when using continuation linezeertzjq2023-04-14
| | | | | | | | | | | | | | | | | | | Problem: Vim9: leaking memory when using continuation line. Solution: Keep a pointer to the continuation line in evalarg_T. Centralize checking for a next command. https://github.com/vim/vim/commit/b171fb179053fa631fec74911b5fb9374cb6a8a1 Omit eval_next_line(): Vim9 script only. vim-patch:8.2.1050: missing change in struct Problem: Missing change in struct. Solution: Add missing change. https://github.com/vim/vim/commit/65a8ed37f7bc61fbe5c612a7b0eb0dfc16ad3e11 Co-authored-by: Bram Moolenaar <Bram@vim.org>
* refactor: remove redundant const char * castsii142023-04-07
|
* refactor: make error message definitions constii142023-04-05
| | | | message.c functions now take const char * as a format. Error message definitions can be made const.
* refactor: replace char_u with char 22 (#21786)dundargoc2023-01-17
| | | Work on https://github.com/neovim/neovim/issues/459
* vim-patch:partial:9.0.1166: code is indented more than necessary (#21716)zeertzjq2023-01-10
| | | | | | | | | | | | | | | | | | | | | | Problem: Code is indented more than necessary. Solution: Use an early return where it makes sense. (Yegappan Lakshmanan, closes vim/vim#11792) https://github.com/vim/vim/commit/1cfb14aa972ccf3235ac67f07b7db1175b7c5384 Partial port as some highlight.c changes depend on previous patches. Cherry-pick fname_match() change from patch 8.2.4959. Omit internal_func_check_arg_types(): only used for Vim9 script. N/A patches for version.c: vim-patch:9.0.1167: EditorConfig files do not have their own filetype Problem: EditorConfig files do not have their own filetype. Solution: Add the "editorconfig" filetype. (Gregory Anders, closes vim/vim#11779) https://github.com/vim/vim/commit/d41262ed06564cef98a3800e2928e6e0db91abbf Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
* refactor: replace char_u with char 17 - remove STRLCPY (#21235)dundargoc2023-01-09
| | | | | refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459
* vim-patch:9.0.1158: code is indented more than necessary (#21697)zeertzjq2023-01-09
| | | | | | | | | | | Problem: Code is indented more than necessary. Solution: Use an early return where it makes sense. (Yegappan Lakshmanan, closes vim/vim#11787) https://github.com/vim/vim/commit/7f8b2559a30e2e2a443c35b28e94c6b45ba7ae04 Omit reset_last_used_map(): only used in Vim9 script. Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
* vim-patch:9.0.1132: code is indented more than needed (#21626)zeertzjq2023-01-03
| | | | | | | | | | | Problem: Code is indented more than needed. Solution: Use an early return to reduce indentation. (Yegappan Lakshmanan, closes vim/vim#11769) https://github.com/vim/vim/commit/dc4daa3a3915fba11ac87d27977240d9a5e0d47d Omit expand_autoload_callback(): only applies to Vim9 script. Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
* fix(folds): use long for number of folded lines (#21447)zeertzjq2022-12-17
| | | Also remove some duplicate unsigned long casts.
* vim-patch:8.2.4393: possible number overflow with nested folds (#21305)zeertzjq2022-12-06
| | | | | | | | Problem: Possible number overflow with nested folds. Solution: Avoid a negative line number. https://github.com/vim/vim/commit/6b43471da4516e8f6c17e5dc2eccbb9d0ba2e0a4 Co-authored-by: Bram Moolenaar <Bram@vim.org>