Commit Graph

291 Commits

Author SHA1 Message Date
Evgeni Chasnovski
fe9cbcb3a5
feat(api): nvim_exec2(), deprecate nvim_exec() #19032
Problem:
The signature of nvim_exec() is not extensible per ":help api-contract".

Solution:
Introduce nvim_exec2() and deprecate nvim_exec().
2023-03-25 09:58:48 -07:00
Lewis Russell
e5641df6d3 feat: add vim.filetype.get_option() 2023-03-20 10:06:32 +00:00
Justin M. Keyes
673d2b52fa refactor!: rename vim.pretty_print => vim.print
Problem:
The function name `vim.pretty_print`:
1. is verbose, which partially defeats its purpose as sugar
2. does not draw from existing precedent or any sort of convention
   (except external projects like penlight or python?), which reduces
   discoverability, and degrades signaling about best practices.

Solution:
- Rename to `vim.print`.
- Change the behavior so that
  1. strings are printed without quotes
  2. each arg is printed on its own line
  3. tables are indented with 2 instead of 4 spaces
- Example:
  :lua ='a', 'b', 42, {a=3}
  a
  b
  42
  {
    a = 3
  }

Comparison of alternatives:
- `vim.print`:
  - pro: consistent with Lua's `print()`
  - pro: aligns with potential `nvim_print` API function which will
    replace nvim_echo, nvim_notify, etc.
  - con: behaves differently than Lua's `print()`, slightly misleading?
- `vim.echo`:
  - pro: `:echo` has similar "pretty print" behavior.
  - con: inconsistent with Lua idioms.
- `vim.p`:
  - pro: very short, fits with `vim.o`, etc.
  - con: not as discoverable as "echo"
  - con: less opportunity for `local p = vim.p` because of potential shadowing.
2023-03-13 01:25:09 +01:00
zeertzjq
6d0c61d90d
fix(api): set script context when setting usercmd or option (#22624) 2023-03-11 21:09:11 +08:00
Justin M. Keyes
7f424e2b65 feat(api): more fields in nvim_list_uis
Problem:
nvim_list_uis does not report all ":help ui-option" fields.

Solution:
Store ":help ui-option" fields on the `UI` object and update ui_array.
2023-02-27 19:50:59 +01:00
Justin M. Keyes
09b3432eaf
fix(api): allow empty Lua table for nested dicts #22268
Problem:
The Lua-API bridge allows Dict params to be empty Lua (list) tables at
the function-signature level. But not for _nested_ Dicts, because they
are not modeled:
fae7540732/src/nvim/api/keysets.lua (L184)
Some API functions like nvim_cmd check for kObjectTypeDictionary and
don't handle the case of empty Lua tables (treated as "Array").

Solution:
Introduce VALIDATE_T_DICT and use it in places where
kObjectTypeDictionary was being checked directly.

fixes #21005
2023-02-16 07:07:18 -08:00
Justin M. Keyes
556f8646c0
refactor(api): consistent VALIDATE messages #22262
Problem:
Validation messages are not consistently formatted.
- Parameter names sometimes are NOT quoted.
- Descriptive names (non-parameters) sometimes ARE quoted.

Solution:
Always quote the `name` value passed to a VALIDATE macro _unless_ the
value has whitespace.
2023-02-14 11:19:28 -08:00
Justin M. Keyes
ff3d04b75b
refactor(api): VALIDATE macros #22256
- VALIDATE() takes a format string
- deduplicate check_string_array
- VALIDATE_RANGE
- validate UI args
2023-02-14 05:07:38 -08:00
Justin M. Keyes
46a87a5d2b
refactor(api): VALIDATE macros #22187
Problem:
- API validation involves too much boilerplate.
- API validation errors are not consistently worded.

Solution:
Introduce some macros. Currently these are clumsy, but they at least
help with consistency and avoid some nesting.
2023-02-14 02:19:04 -08:00
bfredl
f8f82901cd fix(tests): fixes for using vim.mpack and more ASAN 2023-02-10 20:19:04 +01:00
zeertzjq
3b75485043
revert: "shada/context: fully remove jumplist duplicates #10898" (#21874)
This reverts commit 8b8ecf44f2.
It is causing performance problems on exit.
Fix #21082.
2023-01-23 19:32:27 +08:00
luukvbaal
da3460562e
fix(api): avoid memory leak with click functions in nvim_eval_statusline() (#21845)
Problem:    Allocated click function memory is lost due to
            `nvim_eval_statusline()` not passing in a `StlClickRecord`.
Solution:   Do not allocate click function memory if `tabtab == NULL`.

Resolve #21764, supersede #21842.
2023-01-17 07:31:36 +08:00
zeertzjq
61d5bd561a refactor: remove E5500, adjust tests
Now with try_end() including more exception info, E5500 looks like
redundant information.
Adjust tests for more exception information.
2023-01-16 18:03:08 +08:00
zeertzjq
9b1112cf48
fix(statuscolumn): fix crashes and clang/PVS warnings (#21725) 2023-01-10 21:18:12 +08:00
zeertzjq
146c428a53
fix(statusline): make nvim_eval_statusline() work with %S (#21553) 2022-12-27 18:04:42 +08:00
zeertzjq
72a19b2ffe
fix(api): "emsg_silent" should imply "silent" in nvim_cmd (#21438) 2022-12-16 08:54:13 +08:00
dundargoc
615f124003
docs: fix typos (#21196)
Co-authored-by: zeertzjq <zeertzjq@outlook.com>
Co-authored-by: Raphael <glephunter@gmail.com>
Co-authored-by: Gregory Anders <greg@gpanders.com>
2022-11-29 09:45:48 +08:00
dundargoc
5eb5f49488
test: simplify platform detection (#21020)
Extend the capabilities of is_os to detect more platforms such as
freebsd and openbsd. Also remove `iswin()` helper function as it can be
replaced by `is_os("win")`.
2022-11-22 08:13:30 +08:00
Lewis Russell
e8cc489acc
feat(test): add Lua forms for API methods (#20152) 2022-11-14 10:01:35 +00:00
dundargoc
5c5187c6f8
test: remove skip for 32-bit MSVC (#21030)
We don't support 32-bit windows anymore so it's not needed.
2022-11-14 16:28:30 +08:00
dundargoc
736c36c02f
test: introduce skip() #21010
This is essentially a convenience wrapper around the `pending()`
function, similar to `skip_fragile()` but more general-purpose.

Also remove `pending_win32` function as it can be replaced by
`skip(iswin())`.
2022-11-13 05:52:19 -08:00
zeertzjq
850d7146fc
fix(paste): feed keys as typed in cmdline mode (#20959) 2022-11-06 12:43:05 +08:00
Justin M. Keyes
09dffb9db7
docs: various #12823
- increase python line-length limit from 88 => 100.
- gen_help_html: fix bug in "tag" case (tbl_count => tbl_contains)

ref #15632
fix #18215
fix #18479
fix #20527
fix #20532

Co-authored-by: Ben Weedon <ben@weedon.email>
2022-10-09 05:21:52 -07:00
zeertzjq
2a12faaec1
fix(api): dynamically allocate line buffer for nvim_out_write (#20537) 2022-10-08 20:10:00 +08:00
bfredl
b414e9fdbb
Merge pull request #20364 from zeertzjq/parse-cmd-omit
fix(api)!: nvim_parse_cmd omit "count" "range" "reg" if not supported
2022-09-30 09:59:45 +02:00
zeertzjq
cb62592bcb fix(api)!: nvim_parse_cmd omit "count" "range" "reg" if not supported 2022-09-30 11:24:23 +08:00
Famiu Haque
e46eef75ac feat(nvim_cmd): allow using first argument as count
Allows `nvim_cmd` to use the first argument as count for applicable
commands. Also adds support for non-String arguments to `nvim_cmd`.
2022-09-29 19:31:40 +06:00
zeertzjq
45707c1eae
fix(api): fix nvim_cmd crash with filename expansion (#20397) 2022-09-29 16:04:14 +08:00
ii14
4dc4cf3467
fix(options): mark winhighlight as list style (#19477)
Also add missing fcs, lcs and winhighlight to list of key-value options for `vim.opt`.

Co-authored-by: ii14 <ii14@users.noreply.github.com>
2022-09-07 17:59:27 +02:00
zeertzjq
1ef7720567 fix(api)!: correctly deal with number before :tab
Now nvim_parse_cmd and nvim_create_user_command use a "tab" value which
is the same as the number passed before :tab modifier instead of the
number plus 1, and "tab" value is -1 if :tab modifier is not used.
2022-09-02 22:28:57 +08:00
zeertzjq
689f5d604e feat(api): add support for :horizontal modifier 2022-09-01 20:53:43 +08:00
zeertzjq
15a768eeb0
fix(api): avoid side effects with nvim_parse_cmd (#19890)
Save and restore the cursor and last search pattern and do not change
search history.
2022-08-22 18:06:18 +08:00
zeertzjq
03fddfd928
fix(api): nvim_exec and nvim_cmd restore msg_col when capturing output (#19789)
This matches the code in execute_common(), preventing messages after the
API call from being printed at the wrong column.
2022-08-16 17:30:39 +08:00
Famiu Haque
78658ef383
fix(api): vim.cmd.make crashes when argument count isn't 1 (#19701)
Closes #19696
2022-08-10 18:37:59 +08:00
Lewis Russell
0fdf59ac9d
fix(api): nvim_cmd handle 0 range (#19655)
Fixes #19608
2022-08-06 13:53:37 +01:00
notomo
46e3e1c728
fix(api): make nvim_cmd mods.silent work correctly (#19489) 2022-07-25 09:43:39 +08:00
zeertzjq
9f837a5dcf
fix(api): fix nvim_parse_cmd interfere with printing line in Ex mode (#19400) 2022-07-17 09:59:32 +08:00
zeertzjq
73526abbbd
fix(api): do not switch win/buf if getting option in current win/buf (#19383) 2022-07-16 09:31:05 +08:00
zeertzjq
7a907c3314 feat(api): add unsilent to command APIs 2022-07-03 04:34:28 +08:00
zeertzjq
610cf9f950 vim-patch:8.0.1570: can't use :popup for a menu in the terminal
Problem:    Can't use :popup for a menu in the terminal. (Wei Zhang)
Solution:   Make :popup work in the terminal.  Also fix that entries were
            included that don't work in the current state.
29a2c08d79
2022-07-01 10:17:39 +08:00
Famiu Haque
606ec8b708 feat(api): make nvim_parse_cmd and nvim_cmd support :filter
Also fixes a memory leak in `parse_cmdline`.

Closes #18954.
2022-06-28 17:31:04 +06:00
zeertzjq
cf23695dd7
fix(api): nvim_parse_cmd check for ambiguous user command (#19116) 2022-06-27 14:10:13 +08:00
Gregory Anders
58d028f64b feat(api): add "buf" and "win" to nvim_get_option_value
These mirror their counterparts in nvim_set_option_value.
2022-06-20 09:16:21 -06:00
bfredl
e3281d992e fix(tests): check for EOF on exit of nvim properly 2022-06-13 10:15:44 +02:00
bfredl
24352cba01
Merge pull request #18528 from lewis6991/setwinopt
feat(api): add `win` and `buf` to `nvim_set_option_value`
2022-05-25 17:05:28 +02:00
Famiu Haque
fb8fa004d8 fix: make nvim_cmd not suppress errors inside key mapping
Closes #18632
2022-05-19 22:23:14 +06:00
Famiu Haque
e1bdb2a258 feat(ui): add 'winbar'
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>
2022-05-18 09:27:08 +06:00
Lewis Russell
6219331c4d feat(api): add win and buf to nvim_set_option_value
Co-authored-by: Gregory Anders <8965202+gpanders@users.noreply.github.com>
2022-05-17 14:48:10 +01:00
deforde
0a3d615b1c
fix(api): nvim_eval_statusline should validate input #18347
Fix #18112

Make an exception for strings starting with "%!".
2022-05-15 13:06:23 -07:00
Famiu Haque
cf68f0a512
fix(api): make nvim_cmd work correctly with empty arguments list (#18527)
Closes #18526.
2022-05-11 10:51:53 -06:00
Famiu Haque
dfcc584665 feat(api): add nvim_cmd
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.
2022-05-11 13:12:16 +06:00
Famiu Haque
14f3383c0d fix(api): make nvim_parse_cmd work correctly with both range and count
It seems range and count can be used together in commands. This PR fixes
the behavior of `nvim_parse_cmd` for those cases by removing the mutual
exclusivity of "range" and "count". It also removes range line number
validation for `nvim_parse_cmd` as it's not its job to validate the
command.
2022-05-07 12:26:49 +06:00
Famiu Haque
511f06a56e fix(api): make nvim_parse_cmd propagate errors
Makes `nvim_parse_cmd` propagate any errors that occur while parsing to
give the user a better idea of what's wrong with the command.
2022-05-05 23:11:57 +06:00
Famiu Haque
7aedcd8feb refactor(api): make range in nvim_parse_cmd an array
Changes the `range` value in `nvim_parse_cmd` into an array to describe
range information more concisely. Also makes `range` and `count` be
mutually exclusive by making count `-1` when command takes a range
instead of a count. Additionally corrects the behavior of `count` for
built-in commands by making the default count `0`.
2022-05-05 20:35:14 +06:00
Famiu Haque
3ec93ca92c
feat(nvim_parse_cmd): add range, count, reg #18383
Adds range, count and reg to the return values of nvim_parse_cmd. Also makes
line1 and line2 be -1 if the command does not take a range. Also moves
nvim_parse_cmd to vimscript.c because it fits better there.
2022-05-04 05:04:01 -07:00
Famiu Haque
8dbb11ebf6 feat(api): add nvim_parse_cmdline
Adds an API function to parse a command line string and get command information from it.
2022-04-30 21:04:51 +06:00
zeertzjq
519e4c4472 test: correct order of arguments to eq() and neq() 2022-04-26 11:38:58 +08:00
Eden Zhang
813ecdac79
fix(paste): ignore mappings in Cmdline mode (#18114) 2022-04-17 08:11:53 +08:00
zeertzjq
a9665bb12c
fix(event-loop): duplicate display updating logic in vgetorpeek() (#17913) 2022-03-30 05:25:00 +08:00
zeertzjq
77eb6f9dc7
fix(api, lua): return NIL on failure to find converted function (#17779) 2022-03-20 08:08:50 +08:00
zeertzjq
e263afc0e9 fix(paste): escape control characters in Cmdline mode 2022-03-15 18:15:18 +08:00
zeertzjq
3470a9c3de test(paste): add tests with virtualedit=onemore 2022-03-15 18:15:18 +08:00
zeertzjq
e4ec8d7d50 test(paste): reorganize tests and add tests for linewise Visual mode 2022-03-15 18:15:18 +08:00
zeertzjq
a6eafc77ce fix(paste): deal with trailing new line in chunk 2022-03-15 18:15:18 +08:00
zeertzjq
fcc6f66cf2 fix(paste): avoid edges cases caused by empty chunk 2022-03-15 18:15:18 +08:00
zeertzjq
bfb7754442 fix(paste): deal with eol and eof in Visual mode 2022-03-15 18:15:18 +08:00
zeertzjq
2601e0873f fix(paste): don't move cursor past the end of pasted text in Normal mode 2022-03-15 18:15:18 +08:00
zeertzjq
9b1e1fbc9f fix(paste): use getcmdtype() to determine whether in cmdline mode 2022-03-15 18:15:18 +08:00
zeertzjq
3011794c86 feat(api): relax statusline fillchar width check
Treat fillchar as single-width even if it isn't.
2022-03-10 07:40:52 +08:00
Lewis Russell
d512be55a2 fix(api): re-route nvim_get_runtime_file errors
This allows nvim_get_runtime_file to be properly used via pcall
2022-02-15 23:00:28 +00:00
shadmansaleh
f292dd2126 fix: autoload variables not loaded with vim.g & nvim_get_var 2022-02-13 01:23:23 +06:00
zeertzjq
23c3f7f572 fix(api): use changedir_func() in nvim_set_current_dir()
Co-Authored-By: smolck <46855713+smolck@users.noreply.github.com>
2022-02-10 09:45:20 +08:00
glacambre
5b34c2ab73 fix(--headless): do not block on press-enter prompts when no UI
This commit fixes #9358, where emitting multiple messages with 'echo' or
a single one with 'echom' or 'echoerr' would result in a press-enter
prompt that couldn't be dismissed by pressing enter.

This requires adapting a few tests to spawn a UI before testing whether
press-enter prompts are blocking.

It also fixes #11718, as when combined with #15910 it enables making
sure that neovim never blocks and emits messages on startup.
2022-02-05 13:02:33 +01:00
zeertzjq
f4300985d3
Merge pull request #17113 from zeertzjq/vim-8.2.2569
feat(statusline): support multibyte fillchar
2022-02-01 17:57:01 +08:00
zeertzjq
6e69a3c3e7 refactor: remove CSI unescaping and clean up related names and comments 2022-01-21 18:08:56 +08:00
zeertzjq
be15ac06ba feat(statusline): support multibyte fillchar
This includes a partial port of Vim patch 8.2.2569 and some changes to
nvim_eval_statusline() to allow a multibyte fillchar. Literally every
line of C code touched by that patch has been refactored in Nvim, and
that patch contains some irrelevant foldcolumn tests I'm not sure how to
port (as Nvim's foldcolumn behavior has diverged from Vim's).
2022-01-16 19:54:27 +08:00
zeertzjq
ab1ceaaaa9 fix: do not save K_EVENT as lastc in Insert mode
I'm also gonna move some other K_EVENT-related tests to vim_spec.lua
2021-12-26 16:14:35 +08:00
Gregory Anders
33cd1ba00a
fix(api): make nil value in nvim_set_option_value clear local value (#16710)
For special options such as 'undolevels' and 'scrolloff', this sets the
local value to the special "unset" value (e.g. -12345 for 'undolevels').
2021-12-21 14:20:34 -07:00
Gregory Anders
71ac00ccb5 feat(api): add nvim_get_option_value 2021-12-04 14:04:23 -07:00
Javier Lopez
961cd83b3b
refactor(api/marks)!: add opts param for feature extensibility (#16146)
In the future we might want to extend the concept of named marks and
adding opts reduces the need of changing the function signature in the
furute.
2021-11-01 07:46:26 -06:00
Sean Dewar
d918759dee
test(vim_spec): fix MSVC_32 skip for nvim_parse_expression test (#16161)
"works with &opt" is flaky; now it always fails after #15999 for some reason.

This test was skipped in #10773 due to previous flakiness, but after the switch away from appveyor
the check no longer works. Just skip for any CI running the MSVC_32 job.
2021-10-27 16:27:17 -06:00
Björn Linse
9e41e82481 feat(nvim_open_term): support input callback in lua 2021-10-20 13:07:43 +02:00
Famiu Haque
9086938f7b
feat(api): evaluate statusline string #16020
Adds API function `nvim_eval_statusline` to allow evaluating a
statusline string and obtaining information regarding it.

Closes https://github.com/neovim/neovim/issues/15849
2021-10-18 12:44:17 -07:00
Sean Dewar
da9b0abc67
feat(:source, nvim_exec): defer script item creation until s:var access
For anonymous scripts, defer the creation of script items until an attempt to access a script-local
variable is made. This dramatically reduces the number of script items created when using lots of
vim.cmd and nvim_exec especially.

This will mean <SID> usage fails until a script-local variable access is first made.
2021-10-14 12:50:04 +01:00
Sean Dewar
d4ed51eb44
feat(:source, nvim_exec): support script-local variables
Based on #13143 (and #11507) with changes:

 - Omit script_type_E. Use sn_name == NULL to determine anon items.
 - Keep SID_STR. Used by anon :source for .lua files (no item).
 - Show SID in get_scriptname output (:verbose set).
 - Factor item creation into new_script_item.
 - Leave sc_seq = 0 (anon scripts don't re-use the same item when re-sourced).
 - Add tests for anon :source.

Co-authored-by: Vikram Pal <vikrampal659@gmail.com>
Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
2021-10-14 01:27:10 +01:00
Javier Lopez
49fdc62114
feat(api): named marks set, get, delete #15346
Adds the following API functions.

- nvim_buf_set_mark(buf, name, line, col)
  * Set marks in a buffer.
- nvim_buf_del_mark(buf, name)
  * Delete a mark that belongs to buffer.
- nvim_del_mark(name)
  * Delete a global mark.
- nvim_get_mark(name)
  * Get a global mark.

Tests:

- Adds test to all the new api functions, and adds more for the existing
  nvim_buf_get_mark.
    * Tests include failure cases.

Documentation:

- Adds documentation for all the new functions, and improves the
  existing fucntion docs.
2021-10-05 08:49:20 -07:00
Björn Linse
3beea1fe1b
Merge pull request #15516 from bfredl/keyset
refactor(api): Represent option dicts as a structs in C and reduce conversion overhead from lua
2021-10-03 14:31:53 +02:00
Björn Linse
32565922ef refactor(api): handle option dicts properly
Do not copy a lot of lua strings (dict keys) to just strequal() them
Just compare them directly to a dedicated hash function.

feat(generators): HASHY McHASHFACE
2021-10-03 10:46:57 +02:00
Björn Linse
9df7e022b4 fix(runtime): add packages as "/pack/*/start/*" patterns to &rtp
This makes `globpath(&rtp, ...)` work again for start packages
2021-10-02 16:45:19 +02:00
Björn Linse
396280d303 refactor(runtime): always use DIP_START when searching for runtime files
Now remove the addition of "start/*" packages in 'packpath' as
explicit items in 'runtimepath'. This avoids 'runtimepath' from becoming
very long when using a lot of plugins as packages.

To get the effective search path as a list, use |nvim_list_runtime_paths()|
2021-09-18 13:53:50 +02:00
Oliver Marriott
d9f93e5642
fix(typo): overriden -> overridden (RE: PR #14159) (#15360) 2021-09-17 13:07:00 -04:00
Sean Dewar
6188926e00
fix(:source, nvim_exec): handle Vimscript line continuations #14809
Problem:
Anonymous :source (no args) and nvim_exec() don't support Vimscript line continuations.

Solution:
Factor out the concat logic into concat_continued_line() and a
CONCAT_CONTINUED_LINES macro for simple concatenations where lines are
fetched individually.

Closes #14807
2021-09-14 16:35:33 -07:00
Justin M. Keyes
6751d6254b
refactor(tests): use assert_alive() #15546 2021-09-01 09:42:53 -07:00
Justin M. Keyes
0603eba6e7
feat(api): nvim_get_chan_info: include "argv" for jobs #15537
ref #15440
2021-09-01 07:29:38 -07:00
TJ DeVries
6ecec87c09 fix(vim.opt): Fix #14668 Now correctly handles unescaped commas in isfname style 2021-06-29 08:42:07 -04:00
glacambre
0c8454f5bc Fix crash on :echo get_all_options_info()
Iterating over PARAM_COUNT is wrong as PARAM_COUNT also counts the last
element of the options array, which has a NULL fullname in order to
signal the end of the array.
2021-05-26 07:07:11 +02:00
Shadman
01493e7990
api: fix nvim_exec() silencing behaviour (#14413)
Previously nvim_exec would silent output no matter whether output
is true or false.
Now output is only silent and captured when output is true.
2021-04-21 10:41:37 +02:00
Björn Linse
ed08936987 api: allow open non-current buffer as terminal (+ xmas bonus)
vim.api.nvim_chan_send(vim.api.nvim_open_term(0), io.open("/path/to/smile.cat", "r"):read("*a"))
2021-03-12 14:44:47 +01:00
notomo
971e0ca903
fix(notify): Expected 3 arguments error (#13905) 2021-02-09 11:41:02 +01:00
Matthieu Coudron
a90a43796a test: test vim-notify 2021-02-02 15:40:08 +01:00