aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/private/helpers.c
Commit message (Collapse)AuthorAge
* refactor: remove some unused includes (#19747)zeertzjq2022-08-13
| | | | | - Remove autocmd.h from fileio.h - Remove normal.h from main.h - Move bufinfo_T from undo_defs.h to undo.c
* refactor: move non-symbols in ex_eval.h to ex_eval_defs.h (#19739)zeertzjq2022-08-12
| | | | This avoids including ex_eval.h in any other header, thus preventing future circular includes.
* feat(marks): restore viewport on jump #15831Javier Lopez2022-06-30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ** Refactor Previously most functions used to "get" a mark returned a position, changed the line number and sometimes changed even the current buffer. Now functions return a {x}fmark_T making calling context aware whether the mark is in another buffer without arcane casting. A new function is provided for switching to the mark buffer and returning a flag style Enum to convey what happen in the movement. If the cursor changed, line, columns, if it changed buffer, etc. The function to get named mark was split into multiple functions. - mark_get() -> fmark_T - mark_get_global() -> xfmark_T - mark_get_local() -> fmark_T - mark_get_motion() -> fmark_T - mark_get_visual() -> fmark_T Functions that manage the changelist and jumplist were also modified to return mark types. - get_jumplist -> fmark_T - get_changelist -> fmark_T The refactor is also seen mainly on normal.c, where all the mark movement has been siphoned through one function nv_gomark, while the other functions handle getting the mark and setting their movement flags. To handle whether context marks should be left, etc. ** Mark View While doing the refactor the concept of a mark view was also implemented: The view of a mark currently implemented as the number of lines between the mark position on creation and the window topline. This allows for moving not only back to the position of a mark but having the window look similar to when the mark was defined. This is done by carrying and extra element in the fmark_T struct, which can be extended later to also restore horizontal shift. *** User space features 1. There's a new option, jumpoptions+=view enables the mark view restoring automatically when using the jumplist, changelist, alternate-file and mark motions. <C-O> <C-I> g; g, <C-^> '[mark] `[mark] ** Limitations - The view information is not saved in shada. - Calls to get_mark should copy the value in the pointer since we are using pos_to_mark() to wrap and provide a homogeneous interfaces. This was also a limitation in the previous state of things.
* refactor: move some mapping-related code to a separate file (#19061)zeertzjq2022-06-23
| | | | | | | | | | | | | | | | | | | This marks the following Vim patches as ported: vim-patch:8.1.1785: map functionality mixed with character input Problem: Map functionality mixed with character input. Solution: Move the map functionality to a separate file. (Yegappan Lakshmanan, closes vim/vim#4740) Graduate the +localmap feature. https://github.com/vim/vim/commit/b66bab381c8ba71fd6e92327d1d34c6f8a65f2a7 vim-patch:8.2.3643: header for source file is outdated Problem: Header for source file is outdated. Solution: Make the header more accurate. (closes vim/vim#9186) https://github.com/vim/vim/commit/a3f83feb63eae5464a620ae793c002eb45f7a838 Also cherry-pick a change for <unique> mappings from patch 8.2.0807. Rename map_clear_mode() to do_mapclear().
* perf(highlight): allocate permanent names in an arena for fun and cache localitybfredl2022-06-21
|
* perf(ui): reduce allocation overhead when encoding "redraw" eventsbfredl2022-06-20
| | | | | | | | | | | | | | | | | Note for external UIs: Nvim can now emit multiple "redraw" event batches before a final "flush" event is received. To retain existing behavior, clients should make sure to update visible state at an explicit "flush" event, not just the end of a "redraw" batch of event. * Get rid of copy_object() blizzard in the auto-generated ui_event layer * Special case "grid_line" by encoding screen state directly to msgpack events with no intermediate API events. * Get rid of the arcane notion of referring to the screen as the "shell" * Array and Dictionary are kvec_t:s, so define them as such. * Allow kvec_t:s, such as Arrays and Dictionaries, to be allocated with a predetermined size within an arena. * Eliminate redundant capacity checking when filling such kvec_t:s with values.
* refactor(api): move command related API to separate filebfredl2022-06-12
|
* refactor(api): move extmark specific functions to api/extmark.cbfredl2022-06-12
|
* refactor(api): move option code to own filebfredl2022-06-12
|
* fix(messages): add color when showing nvim_echo in :messages historybfredl2022-06-11
|
* refactor: change type of linenr_T from long to int32_tDundar Goc2022-06-10
| | | | | | | | | | | | | The size of long varies depending on architecture, in contrast to the MAXLNUM constant which sets the maximum allowable number of lines to 2^32-1. This discrepancy may lead to hard to detect bugs, for example https://github.com/neovim/neovim/issues/18454. Setting linenr_T to a fix maximum size of 2^32-1 will prevent this type of errors in the future. Also change the variables `amount` and `amount_after` to be linenr_T since they're referring to "the line number difference" between two texts.
* refactor: correct comments and assertions about mapping rhs <Nop> (#18821)zeertzjq2022-06-01
| | | | | | | | Also avoid referring to mappings as "keymaps" in commands and docs. *map_empty_rhs* *map-empty-rhs* You can create an empty {rhs} by typing nothing after a single CTRL-V (you have to type CTRL-V two times). Unfortunately, you cannot do this in a vimrc file.
* feat: add preview functionality to user commandsFamiu Haque2022-05-31
| | | | Adds a Lua-only `preview` flag to user commands which allows the command to be incrementally previewed like `:substitute` when 'inccommand' is set.
* refactor(uncrustify): set maximum number of consecutive newlines to 2 (#18695)dundargoc2022-05-25
|
* Merge pull request #18528 from lewis6991/setwinoptbfredl2022-05-25
|\ | | | | feat(api): add `win` and `buf` to `nvim_set_option_value`
| * feat(api): add win and buf to nvim_set_option_valueLewis Russell2022-05-17
| | | | | | | | Co-authored-by: Gregory Anders <8965202+gpanders@users.noreply.github.com>
* | fix(cid/352839): USE_AFTER_FREE in create_user_command #18669James McCoy2022-05-22
| |
* | fix(cid/351940): free compl_arg in create_user_commands()'s error path exitJames McCoy2022-05-20
| |
* | feat(ui): add `'winbar'`Famiu Haque2022-05-18
|/ | | | | | | Adds support for a bar at the top of each window, enabled through the `'winbar'` option. Co-authored-by: Björn Linse <bjorn.linse@gmail.com>
* refactor(api/nvim_cmd): use `kvec_t` for constructing cmdline stringFamiu Haque2022-05-14
| | | | Co-authored-by: Björn Linse <bjorn.linse@gmail.com>
* fix(api): make `nvim_cmd` work correctly with empty arguments list (#18527)Famiu Haque2022-05-11
| | | Closes #18526.
* Merge pull request #18366 from famiu/feat/api/nvim_cmdbfredl2022-05-11
|\ | | | | feat(api): add `nvim_cmd`
| * feat(api): add `nvim_cmd`Famiu Haque2022-05-11
| | | | | | | | Adds the API function `nvim_cmd` which allows executing an Ex-command through a Dictionary which can have the same values as the return value of `nvim_parse_cmd()`. This makes it much easier to do things like passing arguments with a space to commands that otherwise may not allow it, or to make commands interpret certain characters literally when they otherwise would not.
* | vim-patch:8.2.4911: the mode #defines are not clearly named (#18499)zeertzjq2022-05-10
|/ | | | | | | | Problem: The mode #defines are not clearly named. Solution: Prepend MODE_. Renumber them to put the mapped modes first. https://github.com/vim/vim/commit/249591057b4840785c50e41dd850efb8a8faf435 A hunk from the patch depends on patch 8.2.4861, which hasn't been ported yet, but that should be easy to notice.
* refactor: replace char_u variables and functions with charDundar Goc2022-05-07
| | | | Work on https://github.com/neovim/neovim/issues/459
* refactor: replace char_u variables and functions with charDundar Goc2022-05-05
| | | | Work on https://github.com/neovim/neovim/issues/459
* fix(coverity): use xstrndup() instead of vim_strsave() (#18363)zeertzjq2022-05-03
|
* refactor: replace char_u variables and functions with char (#18288)dundargoc2022-04-30
| | | Work on https://github.com/neovim/neovim/issues/459
* refactor(uncrustify): change rules to better align with the style guideDundar Goc2022-04-29
| | | | | | | | | | | | | Add space around arithmetic operators '+' and '-'. Remove space between back-to-back parentheses, i.e. ')(' vs. ') ('. Remove space between '((' or '))' of control statements. Add space between ')' and '{' of control statements. Remove space between function name and '(' on function declaration. Collapse empty blocks between '{' and '}'. Remove newline at the end of the file. Remove newline between 'enum' and '{'. Remove newline between '}' and ')' in a function invocation. Remove newline between '}' and 'while' of 'do' statement.
* vim-patch:8.1.2145: cannot map <C-H> when modifyOtherKeys is enabledzeertzjq2022-04-29
| | | | | | | | | | | | | Problem: Cannot map <C-H> when modifyOtherKeys is enabled. Solution: Add the <C-H> mapping twice, both with modifier and as 0x08. Use only the first one when modifyOtherKeys has been detected. https://github.com/vim/vim/commit/459fd785e4a8d044147a3f83a5fca8748528aa84 Add REPTERM_NO_SPECIAL instead of REPTERM_SPECIAL because the meaning of "special" is different between Vim and Nvim. Omit seenModifyOtherKeys as Nvim supports attaching multiple UIs. Omit tests as they send terminal codes. Keep the behavior of API functions.
* refactor!: rename nvim_add_user_command to nvim_create_user_commandGregory Anders2022-04-10
|
* vim-patch:8.1.1693: syntax coloring and highlighting is in one big file (#17721)Lewis Russell2022-03-18
| | | | | | | | | | | Problem: Syntax coloring and highlighting is in one big file. Solution: Move the highlighting to a separate file. (Yegappan Lakshmanan, closes vim/vim#4674) https://github.com/vim/vim/commit/f9cc9f209ede9f15959e4c2351e970477c139614 Name the new file highlight_group.c instead. Co-authored-by: zeertzjq <zeertzjq@outlook.com>
* refactor: fix clint warnings (#17682)dundargoc2022-03-13
|
* feat(decorations): support signsLewis Russell2022-03-05
| | | | | | | | | | | | Add the following options to extmarks: - sign_text - sign_hl_group - number_hl_group - line_hl_group - cursorline_hl_group Note: ranges are unsupported and decorations are only applied to start_row
* Merge pull request #15079 from shadmansaleh/feat/verbose_luabfredl2022-03-01
|\ | | | | feat(lua): add :verbose support for lua config
| * feat(lua): show proper verbose output for lua configurationshadmansaleh2022-02-28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `:verbose` didn't work properly with lua configs (For example: options or keymaps are set from lua, just say that they were set from lua, doesn't say where they were set at. This fixes that issue. Now `:verbose` will provide filename and line no when option/keymap is set from lua. Changes: - compiles lua/vim/keymap.lua as vim/keymap.lua - When souring a lua file current_sctx.sc_sid is set to SID_LUA - Moved finding scripts SID out of `do_source()` to `get_current_script_id()`. So it can be reused for lua files. - Added new function `nlua_get_sctx` that extracts current lua scripts name and line no with debug library. And creates a sctx for it. NOTE: This function ignores C functions and blacklist which currently contains only vim/_meta.lua so vim.o/opt wrappers aren't targeted. - Added function `nlua_set_sctx` that changes provided sctx to current lua scripts sctx if a lua file is being executed. - Added tests in tests/functional/lua/verbose_spec.lua - add primary support for additional types (:autocmd, :function, :syntax) to lua verbose Note: These can't yet be directly set from lua but once that's possible :verbose should work for them hopefully :D - add :verbose support for nvim_exec & nvim_command within lua Currently auto commands/commands/functions ... can only be defined by nvim_exec/nvim_command this adds support for them. Means if those Are defined within lua with vim.cmd/nvim_exec :verbose will show their location . Though note it'll show the line no on which nvim_exec call was made.
* | feat(lua): add missing changes to autocmds lost in the rebaseTJ DeVries2022-02-28
|/ | | | Note: some of these changes are breaking, like change of API signatures
* feat(lua): add api and lua autocmdsTJ DeVries2022-02-27
|
* feat(api): implement nvim_buf_get_text (#15181)Gregory Anders2022-02-22
| | | | | | | | | | nvim_buf_get_text is the mirror of nvim_buf_set_text. It differs from nvim_buf_get_lines in that it allows retrieving only portions of lines. While this can typically be done easily enough by API clients, implementing this function provides symmetry between the get/set text/lines APIs, and also provides a nice convenience that saves API clients the work of having to slice the result of nvim_buf_get_lines themselves.
* fix(api): validate command names in nvim_add_user_command (#17406)Gregory Anders2022-02-15
| | | | This uses the same validation used when defining commands with `:command`.
* vim-patch:8.2.4018: ml_get error when win_execute redraws with Visual selectionSean Dewar2022-02-03
| | | | | | | | | | | Problem: ml_get error when win_execute redraws with Visual selection. Solution: Disable Visual area temporarily. (closes vim/vim#9479) https://github.com/vim/vim/commit/18f4740f043b353abe47b7a00131317052457686 {switch_to/restore}_win_for_buf is N/A (marked as such in v8.0.0860; currently only used in Vim's if_py). Add a modeline to test_execute_func.vim.
* vim-patch:8.2.4241: some type casts are redundantDundar Göc2022-01-30
| | | | | | | | Problem: Some type casts are redundant. Solution: Remove the type casts. (closes vim/vim#9643) https://github.com/vim/vim/commit/420fabcd4ffeaf79082a6e43db91e1d363f88f27 This is not a literal port but an equivalent one.
* vim-patch:8.2.3584: "verbose set efm" reports location of the :compiler commandzeertzjq2022-01-21
| | | | | | | | Problem: "verbose set efm" reports the location of the :compiler command. (Gary Johnson) Solution: Add the "-keepscript" argument to :command and use it when defining CompilerSet. https://github.com/vim/vim/commit/58ef8a31d7087d495ab1582be5b7a22796ac2451
* refactor(extmarks): use a more efficient representationBjörn Linse2022-01-15
| | | | | | | | | | | | | | | | | | | | | | | | | | | marktree.c was originally constructed as a "generic" datatype, to make the prototyping of its internal logic as simple as possible and also as the usecases for various kinds of extmarks/decorations was not yet decided. As a consequence of this, various extra indirections and allocations was needed to use marktree to implement extmarks (ns/id pairs) and decorations of different kinds (some which is just a single highlight id, other an allocated list of virtual text/lines) This change removes a lot of indirection, by making Marktree specialized for the usecase. In particular, the namespace id and mark id is stored directly, instead of the 64-bit global id particular to the Marktree struct. This removes the two maps needed to convert between global and per-ns ids. Also, "small" decorations are stored inline, i.e. those who doesn't refer to external heap memory anyway. That is highlights (with priority+flags) are stored inline, while virtual text, which anyway occurs a lot of heap allocations, do not. (previously a hack was used to elide heap allocations for highlights with standard prio+flags) TODO(bfredl): the functionaltest-lua CI version of gcc is having severe issues with uint16_t bitfields, so splitting up compound assignments and redundant casts are needed. Clean this up once we switch to a working compiler version.
* fix(api): validate user_command name (#17004)Lewis Russell2022-01-09
| | | | The name argument of nvim_add_user_command must begin with an uppercase character. Check that is does.
* fix(api): force redefinition of user commands by default (#16918)Gregory Anders2022-01-04
|
* perf(api): elide luaref copy when setting 'callback' in nvim_set_keymapBjörn Linse2022-01-01
|
* feat(api): add support for lua function & description in keymapshadmansaleh2022-01-01
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Behavioral changes: 1. Added support for lua function in keymaps in -------------------------------------------- - nvim_set_keymap Can set lua function as keymap rhs like following: ```lua vim.api.nvim_{buf_}set_keymap('n', '<leader>lr', '', {callback = vim.lsp.buf.references}) ``` Note: lua function can only be set from lua . If api function being called from viml or over rpc this option isn't available. - nvim_{buf_}get_keymap When called from lua, lua function is returned is `callback` key . But in other cases callback contains number of the function ref. - :umap, nvim_del_keymap & nvim_buf_del_keymap clears lua keymaps correctly. - :map commands for displaing rhs . For lua keymaps rhs is displayed as <Lua function ref_no> Note: lua keymap cannot be set through viml command / functions. - mapargs() When dict is false it returns string in `<Lua function ref_no>` format (same format as :map commands). When dict is true it returns ref_no number in `callback` key. - mapcheck() returns string in `<Lua function ref_no>` format (same format as :map commands). 2. Added support for keymap description --------------------------------------- - nvim_{buf_}set_keymap: added `desc` option in opts table . ```lua vim.api.nvim_set_keymap('n', '<leader>w', '<cmd>w<cr>', {desc='Save current file'}) ``` - nvim_{buf_}get_keymap: contains `desc` in returned list. - commands like `:nmap <leader>w` will show description in a new line below rhs. - `maparg()` return dict contains `desc`.
* feat(api): implement nvim_{add,del}_user_commandGregory Anders2021-12-28
| | | | | Add support for adding and removing custom user commands with the Nvim API.
* fix: add STRNLEN compatability macroClaes Nästén2021-12-06
| | | | | Older SunOS systems come without strnlen, add STRNLEN macro in line with the other str* compat macros.