aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/build.yml23
-rw-r--r--.github/workflows/test.yml28
-rw-r--r--runtime/autoload/python.vim9
-rw-r--r--runtime/doc/builtin.txt103
-rw-r--r--runtime/doc/change.txt6
-rw-r--r--runtime/doc/lsp.txt7
-rw-r--r--runtime/doc/map.txt6
-rw-r--r--runtime/doc/news.txt5
-rw-r--r--runtime/doc/sign.txt13
-rw-r--r--runtime/doc/syntax.txt20
-rw-r--r--runtime/doc/ui.txt5
-rw-r--r--runtime/doc/usr_05.txt80
-rw-r--r--runtime/doc/usr_41.txt6
-rw-r--r--runtime/ftplugin/quarto.vim1
-rw-r--r--runtime/ftplugin/r.vim4
-rw-r--r--runtime/ftplugin/rhelp.vim4
-rw-r--r--runtime/ftplugin/rmd.vim21
-rw-r--r--runtime/ftplugin/rnoweb.vim21
-rw-r--r--runtime/ftplugin/rrst.vim4
-rw-r--r--runtime/indent/quarto.vim1
-rw-r--r--runtime/indent/r.vim14
-rw-r--r--runtime/indent/rhelp.vim4
-rw-r--r--runtime/indent/rmd.vim6
-rw-r--r--runtime/indent/rnoweb.vim4
-rw-r--r--runtime/indent/rrst.vim4
-rw-r--r--runtime/lua/vim/_inspector.lua2
-rw-r--r--runtime/lua/vim/filetype.lua1
-rw-r--r--runtime/lua/vim/lsp.lua6
-rw-r--r--runtime/lua/vim/lsp/semantic_tokens.lua3
-rw-r--r--runtime/lua/vim/treesitter/health.lua22
-rw-r--r--runtime/lua/vim/treesitter/language.lua2
-rw-r--r--runtime/lua/vim/treesitter/languagetree.lua2
-rw-r--r--runtime/lua/vim/treesitter/playground.lua46
-rw-r--r--runtime/plugin/matchparen.vim5
-rw-r--r--runtime/syntax/python.vim20
-rw-r--r--runtime/syntax/python2.vim345
-rw-r--r--runtime/syntax/quarto.vim17
-rw-r--r--runtime/syntax/r.vim48
-rw-r--r--runtime/syntax/rmd.vim209
-rw-r--r--runtime/syntax/sh.vim11
-rw-r--r--src/nvim/api/buffer.c3
-rw-r--r--src/nvim/api/ui.c15
-rw-r--r--src/nvim/diff.c5
-rw-r--r--src/nvim/drawline.c2
-rw-r--r--src/nvim/eval.c160
-rw-r--r--src/nvim/eval.lua4
-rw-r--r--src/nvim/eval/funcs.c72
-rw-r--r--src/nvim/eval/typval.c130
-rw-r--r--src/nvim/eval/typval.h6
-rw-r--r--src/nvim/ex_getln.c4
-rw-r--r--src/nvim/getchar.c97
-rw-r--r--src/nvim/globals.h4
-rw-r--r--src/nvim/input.c16
-rw-r--r--src/nvim/mapping.c10
-rw-r--r--src/nvim/spellsuggest.c2
-rw-r--r--src/nvim/testdir/test_blob.vim907
-rw-r--r--src/nvim/testdir/test_buffer.vim71
-rw-r--r--src/nvim/testdir/test_filetype.vim1
-rw-r--r--src/nvim/testdir/test_listdict.vim6
-rw-r--r--src/nvim/testdir/test_swap.vim1
-rw-r--r--src/nvim/testdir/test_tabpage.vim39
-rw-r--r--src/nvim/testdir/test_window_cmd.vim46
-rw-r--r--src/nvim/testdir/vim9.vim8
-rw-r--r--src/nvim/tui/tui.c2
-rw-r--r--src/nvim/ui.c21
-rw-r--r--src/nvim/ui.h7
-rw-r--r--src/nvim/ui_client.c2
-rw-r--r--src/nvim/window.c6
-rw-r--r--test/functional/api/vim_spec.lua18
-rw-r--r--test/functional/plugin/lsp/semantic_tokens_spec.lua160
-rw-r--r--test/functional/terminal/tui_spec.lua75
-rw-r--r--test/functional/ui/statuscolumn_spec.lua20
-rw-r--r--test/functional/vimscript/has_spec.lua21
-rw-r--r--test/helpers.lua2
74 files changed, 2301 insertions, 780 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index ef0a17ce1d..10e3e2bdeb 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -114,26 +114,3 @@ jobs:
run: |
cmake -B build -G Ninja
cmake --build build
-
- multi-config:
- runs-on: ubuntu-22.04
- timeout-minutes: 10
- steps:
- - uses: actions/checkout@v3
-
- - name: Install dependencies
- run: ./.github/scripts/install_deps.sh
-
- - name: Build third-party deps
- run: |
- cmake -S cmake.deps -B .deps -G "Ninja Multi-Config"
- cmake --build .deps
-
- - name: Configure
- run: cmake -B build -G "Ninja Multi-Config" -D CMAKE_C_COMPILER=gcc
-
- - name: Release
- run: cmake --build build --config Release
-
- - name: MinSizeRel
- run: cmake --build build --config MinSizeRel
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 3bd982477a..c6b8291458 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -294,6 +294,34 @@ jobs:
echo 'Core dumps found'
exit 1
+ build-types:
+ runs-on: ubuntu-22.04
+ timeout-minutes: 10
+ steps:
+ - uses: actions/checkout@v3
+
+ - name: Install dependencies
+ run: ./.github/scripts/install_deps.sh
+
+ - uses: ./.github/actions/cache
+
+ - name: Build third-party deps
+ run: |
+ cmake -S cmake.deps -B $DEPS_BUILD_DIR -G "Ninja Multi-Config"
+ cmake --build $DEPS_BUILD_DIR
+
+ - name: Configure
+ run: cmake -B build -G "Ninja Multi-Config" -D CMAKE_C_COMPILER=gcc
+
+ - name: Release
+ run: cmake --build build --config Release
+
+ - name: RelWithDebInfo
+ run: cmake --build build --config RelWithDebInfo
+
+ - name: MinSizeRel
+ run: cmake --build build --config MinSizeRel
+
windows:
runs-on: windows-2019
timeout-minutes: 45
diff --git a/runtime/autoload/python.vim b/runtime/autoload/python.vim
index 1eaad09ef5..d5f4862363 100644
--- a/runtime/autoload/python.vim
+++ b/runtime/autoload/python.vim
@@ -22,8 +22,7 @@ let s:maxoff = 50 " maximum number of lines to look backwards for ()
function s:SearchBracket(fromlnum, flags)
return searchpairpos('[[({]', '', '[])}]', a:flags,
\ {-> synstack('.', col('.'))
- \ ->map({_, id -> id->synIDattr('name')})
- \ ->match('\%(Comment\|Todo\|String\)$') >= 0},
+ \ ->indexof({_, id -> synIDattr(id, 'name') =~ '\%(Comment\|Todo\|String\)$'}) >= 0},
\ [0, a:fromlnum - s:maxoff]->max(), g:python_indent.searchpair_timeout)
endfunction
@@ -157,15 +156,13 @@ function python#GetIndent(lnum, ...)
" the start of the comment. synID() is slow, a linear search would take
" too long on a long line.
if synstack(plnum, pline_len)
- \ ->map({_, id -> id->synIDattr('name')})
- \ ->match('\%(Comment\|Todo\)$') >= 0
+ \ ->indexof({_, id -> synIDattr(id, 'name') =~ '\%(Comment\|Todo\)$'}) >= 0
let min = 1
let max = pline_len
while min < max
let col = (min + max) / 2
if synstack(plnum, col)
- \ ->map({_, id -> id->synIDattr('name')})
- \ ->match('\%(Comment\|Todo\)$') >= 0
+ \ ->indexof({_, id -> synIDattr(id, 'name') =~ '\%(Comment\|Todo\)$'}) >= 0
let max = col
else
let min = col + 1
diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt
index 3ff4e47a45..7fab2ac6ff 100644
--- a/runtime/doc/builtin.txt
+++ b/runtime/doc/builtin.txt
@@ -55,6 +55,7 @@ assert_report({msg}) Number report a test failure
assert_true({actual} [, {msg}]) Number assert {actual} is true
atan({expr}) Float arc tangent of {expr}
atan2({expr1}, {expr2}) Float arc tangent of {expr1} / {expr2}
+blob2list({blob}) List convert {blob} into a list of numbers
browse({save}, {title}, {initdir}, {default})
String put up a file requester
browsedir({title}, {initdir}) String put up a directory requester
@@ -296,7 +297,8 @@ libcallnr({lib}, {func}, {arg}) Number idem, but return a Number
line({expr} [, {winid}]) Number line nr of cursor, last line or mark
line2byte({lnum}) Number byte count of line {lnum}
lispindent({lnum}) Number Lisp indent for line {lnum}
-list2str({list} [, {utf8}]) String turn numbers in {list} into a String
+list2blob({list}) Blob turn {list} of numbers into a Blob
+list2str({list} [, {utf8}]) String turn {list} of numbers into a String
localtime() Number current time
log({expr}) Float natural logarithm (base e) of {expr}
log10({expr}) Float logarithm of Float {expr} to base 10
@@ -359,7 +361,8 @@ pyxeval({expr}) any evaluate |python_x| expression
rand([{expr}]) Number get pseudo-random number
range({expr} [, {max} [, {stride}]])
List items from {expr} to {max}
-readblob({fname}) Blob read a |Blob| from {fname}
+readblob({fname} [, {offset} [, {size}]])
+ Blob read a |Blob| from {fname}
readdir({dir} [, {expr}]) List file names in {dir} selected by {expr}
readfile({fname} [, {type} [, {max}]])
List get list of lines from file {fname}
@@ -377,7 +380,8 @@ remove({blob}, {idx} [, {end}]) Number/Blob
remove bytes {idx}-{end} from {blob}
remove({dict}, {key}) any remove entry {key} from {dict}
rename({from}, {to}) Number rename (move) file from {from} to {to}
-repeat({expr}, {count}) String repeat {expr} {count} times
+repeat({expr}, {count}) List/Blob/String
+ repeat {expr} {count} times
resolve({filename}) String get filename a shortcut points to
reverse({list}) List reverse {list} in-place
round({expr}) Float round off {expr}
@@ -776,6 +780,17 @@ atan2({expr1}, {expr2}) *atan2()*
Can also be used as a |method|: >
Compute()->atan2(1)
+blob2list({blob}) *blob2list()*
+ Return a List containing the number value of each byte in Blob
+ {blob}. Examples: >
+ blob2list(0z0102.0304) returns [1, 2, 3, 4]
+ blob2list(0z) returns []
+< Returns an empty List on error. |list2blob()| does the
+ opposite.
+
+ Can also be used as a |method|: >
+ GetBlob()->blob2list()
+<
*browse()*
browse({save}, {title}, {initdir}, {default})
Put up a file requester. This only works when "has("browse")"
@@ -2126,8 +2141,7 @@ extend({expr1}, {expr2} [, {expr3}]) *extend()*
extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
Like |extend()| but instead of adding items to {expr1} a new
List or Dictionary is created and returned. {expr1} remains
- unchanged. Items can still be changed by {expr2}, if you
- don't want that use |deepcopy()| first.
+ unchanged.
feedkeys({string} [, {mode}]) *feedkeys()*
@@ -3868,6 +3882,7 @@ has({feature}) Returns 1 if {feature} is supported, 0 otherwise. The
clipboard |clipboard| provider is available.
fname_case Case in file names matters (for Darwin and MS-Windows
this is not present).
+ gui_running Nvim has a GUI.
iconv Can use |iconv()| for conversion.
linux Linux system.
mac MacOS system.
@@ -4767,6 +4782,19 @@ lispindent({lnum}) *lispindent()*
Can also be used as a |method|: >
GetLnum()->lispindent()
+list2blob({list}) *list2blob()*
+ Return a Blob concatenating all the number values in {list}.
+ Examples: >
+ list2blob([1, 2, 3, 4]) returns 0z01020304
+ list2blob([]) returns 0z
+< Returns an empty Blob on error. If one of the numbers is
+ negative or more than 255 error *E1239* is given.
+
+ |blob2list()| does the opposite.
+
+ Can also be used as a |method|: >
+ GetList()->list2blob()
+
list2str({list} [, {utf8}]) *list2str()*
Convert each number in {list} to a character string can
concatenate them all. Examples: >
@@ -6110,6 +6138,25 @@ pyxeval({expr}) *pyxeval()*
Can also be used as a |method|: >
GetExpr()->pyxeval()
<
+rand([{expr}]) *rand()*
+ Return a pseudo-random Number generated with an xoshiro128**
+ algorithm using seed {expr}. The returned number is 32 bits,
+ also on 64 bits systems, for consistency.
+ {expr} can be initialized by |srand()| and will be updated by
+ rand(). If {expr} is omitted, an internal seed value is used
+ and updated.
+ Returns -1 if {expr} is invalid.
+
+ Examples: >
+ :echo rand()
+ :let seed = srand()
+ :echo rand(seed)
+ :echo rand(seed) % 16 " random number 0 - 15
+<
+ Can also be used as a |method|: >
+ seed->rand()
+<
+
*E726* *E727*
range({expr} [, {max} [, {stride}]]) *range()*
Returns a |List| with Numbers:
@@ -6132,29 +6179,29 @@ range({expr} [, {max} [, {stride}]]) *range()*
Can also be used as a |method|: >
GetExpr()->range()
<
-rand([{expr}]) *rand()*
- Return a pseudo-random Number generated with an xoshiro128**
- algorithm using seed {expr}. The returned number is 32 bits,
- also on 64 bits systems, for consistency.
- {expr} can be initialized by |srand()| and will be updated by
- rand(). If {expr} is omitted, an internal seed value is used
- and updated.
- Returns -1 if {expr} is invalid.
- Examples: >
- :echo rand()
- :let seed = srand()
- :echo rand(seed)
- :echo rand(seed) % 16 " random number 0 - 15
-<
- Can also be used as a |method|: >
- seed->rand()
-<
-
-readblob({fname}) *readblob()*
+readblob({fname} [, {offset} [, {size}]]) *readblob()*
Read file {fname} in binary mode and return a |Blob|.
- When the file can't be opened an error message is given and
+ If {offset} is specified, read the file from the specified
+ offset. If it is a negative value, it is used as an offset
+ from the end of the file. E.g., to read the last 12 bytes: >
+ readblob('file.bin', -12)
+< If {size} is specified, only the specified size will be read.
+ E.g. to read the first 100 bytes of a file: >
+ readblob('file.bin', 0, 100)
+< If {size} is -1 or omitted, the whole data starting from
+ {offset} will be read.
+ This can be also used to read the data from a character device
+ on Unix when {size} is explicitly set. Only if the device
+ supports seeking {offset} can be used. Otherwise it should be
+ zero. E.g. to read 10 bytes from a serial console: >
+ readblob('/dev/ttyS0', 0, 10)
+< When the file can't be opened an error message is given and
the result is an empty |Blob|.
+ When the offset is beyond the end of the file the result is an
+ empty blob.
+ When trying to read more bytes than are available the result
+ is truncated.
Also see |readfile()| and |writefile()|.
@@ -6374,8 +6421,8 @@ repeat({expr}, {count}) *repeat()*
result. Example: >
:let separator = repeat('-', 80)
< When {count} is zero or negative the result is empty.
- When {expr} is a |List| the result is {expr} concatenated
- {count} times. Example: >
+ When {expr} is a |List| or a |Blob| the result is {expr}
+ concatenated {count} times. Example: >
:let longlist = repeat(['a', 'b'], 3)
< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
@@ -8725,6 +8772,8 @@ timer_start({time}, {callback} [, {options}])
{time} is the waiting time in milliseconds. This is the
minimum time before invoking the callback. When the system is
busy or Vim is not waiting for input the time will be longer.
+ Zero can be used to execute the callback when Vim is back in
+ the main loop.
{callback} is the function to call. It can be the name of a
function or a |Funcref|. It is called with one argument, which
diff --git a/runtime/doc/change.txt b/runtime/doc/change.txt
index 990ba3d8fd..2cebd8abdd 100644
--- a/runtime/doc/change.txt
+++ b/runtime/doc/change.txt
@@ -276,7 +276,9 @@ gr{char} Replace the virtual characters under the cursor with
{char}. This replaces in screen space, not file
space. See |gR| and |Virtual-Replace-mode| for more
details. As with |r| a count may be given.
- {char} can be entered like with |r|.
+ {char} can be entered like with |r|, but characters
+ that have a special meaning in Insert mode, such as
+ most CTRL-keys, cannot be used.
*digraph-arg*
The argument for Normal mode commands like |r| and |t| is a single character.
@@ -976,7 +978,7 @@ inside of strings can change! Also see 'softtabstop' option. >
< to display registers '1' and 'a'. Spaces are allowed
in {arg}.
- *:di* *:display*
+ *:di* *:dis* *:display*
:di[splay] [arg] Same as :registers.
*y* *yank*
diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt
index 3b5a434eff..7e46698614 100644
--- a/runtime/doc/lsp.txt
+++ b/runtime/doc/lsp.txt
@@ -851,11 +851,10 @@ start_client({config}) *vim.lsp.start_client()*
• cmd_cwd: (string, default=|getcwd()|) Directory to launch
the `cmd` process. Not related to `root_dir`.
• cmd_env: (table) Environment flags to pass to the LSP on
- spawn. Can be specified using keys like a map or as a list
- with `k=v` pairs or both. Non-string values are coerced to string.
- Example: >
+ spawn. Must be specified using a map-like table.
+ Non-string values are coerced to string. Example: >
- { "PRODUCTION=true"; "TEST=123"; PORT = 8080; HOST = "0.0.0.0"; }
+ { PORT = 8080; HOST = "0.0.0.0"; }
<
• detached: (boolean, default true) Daemonize the server
process so that it runs in a separate process group from
diff --git a/runtime/doc/map.txt b/runtime/doc/map.txt
index ad0570e9f7..3a5223fa3a 100644
--- a/runtime/doc/map.txt
+++ b/runtime/doc/map.txt
@@ -1205,12 +1205,14 @@ functions used in one script use the same name as in other scripts. To avoid
this, they can be made local to the script.
*<SID>* *<SNR>* *E81*
-The string "<SID>" can be used in a mapping or menu.
+The string "<SID>" can be used in a mapping or menu. This is useful if you
+have a script-local function that you want to call from a mapping in the same
+script.
When executing the map command, Vim will replace "<SID>" with the special
key code <SNR>, followed by a number that's unique for the script, and an
underscore. Example: >
:map <SID>Add
-could define a mapping "<SNR>23_Add".
+would define a mapping "<SNR>23_Add".
When defining a function in a script, "s:" can be prepended to the name to
make it local to the script. But when a mapping is executed from outside of
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt
index 86a81e0c95..919f8ceaee 100644
--- a/runtime/doc/news.txt
+++ b/runtime/doc/news.txt
@@ -179,6 +179,11 @@ The following new APIs or features were added.
Additionally |TSNode:range()| now takes an optional {include_bytes} argument.
+• |nvim_list_uis()| reports all |ui-option| fields.
+
+• Vim's `has('gui_running')` is now supported as a way for plugins to check if
+ a GUI (not the |TUI|) is attached to Nvim. |has()|
+
==============================================================================
CHANGED FEATURES *news-changes*
diff --git a/runtime/doc/sign.txt b/runtime/doc/sign.txt
index 53ef03eb63..9f469767a2 100644
--- a/runtime/doc/sign.txt
+++ b/runtime/doc/sign.txt
@@ -525,6 +525,7 @@ sign_jump({id}, {group}, {buf})
{buf} and position the cursor at sign {id} in group {group}.
This is similar to the |:sign-jump| command.
+ If {group} is an empty string, then the global group is used.
For the use of {buf}, see |bufname()|.
Returns the line number of the sign. Returns -1 if the
@@ -595,23 +596,23 @@ sign_placelist({list})
|sign_place()| function. The {list} argument specifies the
List of signs to place. Each list item is a dict with the
following sign attributes:
- buffer buffer name or number. For the accepted
+ buffer Buffer name or number. For the accepted
values, see |bufname()|.
- group sign group. {group} functions as a namespace
+ group Sign group. {group} functions as a namespace
for {id}, thus two groups can use the same
IDs. If not specified or set to an empty
string, then the global group is used. See
|sign-group| for more information.
- id sign identifier. If not specified or zero,
+ id Sign identifier. If not specified or zero,
then a new unique identifier is allocated.
Otherwise the specified number is used. See
|sign-identifier| for more information.
- lnum line number in the buffer where the sign is to
+ lnum Line number in the buffer where the sign is to
be placed. For the accepted values, see
|line()|.
- name name of the sign to place. See |sign_define()|
+ name Name of the sign to place. See |sign_define()|
for more information.
- priority priority of the sign. When multiple signs are
+ priority Priority of the sign. When multiple signs are
placed on a line, the sign with the highest
priority is used. If not specified, the
default value of 10 is used. See
diff --git a/runtime/doc/syntax.txt b/runtime/doc/syntax.txt
index 7102e93f0a..68d059be82 100644
--- a/runtime/doc/syntax.txt
+++ b/runtime/doc/syntax.txt
@@ -2756,17 +2756,25 @@ For highlighted doctests and code inside: >
:let python_no_doctest_highlight = 1
or >
:let python_no_doctest_code_highlight = 1
-(first option implies second one).
+The first option implies the second one.
For highlighted trailing whitespace and mix of spaces and tabs: >
:let python_space_error_highlight = 1
-If you want all possible Python highlighting (the same as setting the
-preceding last option and unsetting all other ones): >
+If you want all possible Python highlighting: >
:let python_highlight_all = 1
+This has the same effect as setting python_space_error_highlight and
+unsetting all the other ones.
+
+If you use Python 2 or straddling code (Python 2 and 3 compatible),
+you can enforce the use of an older syntax file with support for
+Python 2 and up to Python 3.5. >
+ : let python_use_python2_syntax = 1
+This option will exclude all modern Python 3.6 or higher features.
+
+Note: Only existence of these options matters, not their value.
+ You can replace 1 above with anything.
-Note: Only existence of these options matter, not their value. You can replace
- 1 above with anything.
QUAKE *quake.vim* *ft-quake-syntax*
@@ -5179,7 +5187,7 @@ Conceal Placeholder characters substituted for concealed
*hl-CurSearch*
CurSearch Used for highlighting a search pattern under the cursor
(see 'hlsearch').
- *hl-Cursor*
+ *hl-Cursor* *hl-lCursor*
Cursor Character under the cursor.
lCursor Character under the cursor when |language-mapping|
is used (see 'guicursor').
diff --git a/runtime/doc/ui.txt b/runtime/doc/ui.txt
index bb567e021e..e706e36374 100644
--- a/runtime/doc/ui.txt
+++ b/runtime/doc/ui.txt
@@ -53,9 +53,8 @@ with these (optional) keys:
- `term_name` Sets the name of the terminal 'term'.
- `term_colors` Sets the number of supported colors 't_Co'.
- `term_background` Sets the default value of 'background'.
-- `stdin_fd` Read buffer from `fd` as if it was a stdin pipe.
- This option can only used by |--embed| ui on startup.
- See |ui-startup-stdin|.
+- `stdin_fd` Read buffer 1 from this fd as if it were stdin |--|.
+ Only from |--embed| UI on startup. |ui-startup-stdin|
- `stdin_tty` Tells if `stdin` is a `tty` or not.
- `stdout_tty` Tells if `stdout` is a `tty` or not.
diff --git a/runtime/doc/usr_05.txt b/runtime/doc/usr_05.txt
index d8fb2acedb..00b4f9eed4 100644
--- a/runtime/doc/usr_05.txt
+++ b/runtime/doc/usr_05.txt
@@ -10,7 +10,7 @@ make Vim start with options set to different values. Add plugins to extend
Vim's capabilities. Or define your own macros.
|05.1| The vimrc file
-|05.2| The example vimrc file explained
+|05.2| Example vimrc contents
|05.3| Simple mappings
|05.4| Adding a package
|05.5| Adding a plugin
@@ -27,10 +27,10 @@ Table of contents: |usr_toc.txt|
You probably got tired of typing commands that you use very often. To start
Vim with all your favorite option settings and mappings, you write them in
-what is called the init.vim file. Vim executes the commands in this file when
+what is called the init.vim file. Vim executes the commands in this file when
it starts up.
-If you already have a init.vim file (e.g., when your sysadmin has one setup
+If you already have a init.vim file (e.g., when your sysadmin has one setup
for you), you can edit it this way: >
:edit $MYVIMRC
@@ -56,80 +56,32 @@ This chapter only explains the most basic items. For more information on how
to write a Vim script file: |usr_41.txt|.
==============================================================================
-*05.2* The example vimrc file explained *vimrc_example.vim*
+*05.2* Example vimrc contents *vimrc_example.vim*
In the first chapter was explained how to create a vimrc file. >
:exe 'edit' stdpath('config').'/init.vim'
-In this section we will explain the various commands used in this file. This
-will give you hints about how to set up your own preferences. Not everything
-will be explained though. Use the ":help" command to find out more.
-
->
- set backspace=indent,eol,start
-
-This specifies where in Insert mode the <BS> is allowed to delete the
-character in front of the cursor. The three items, separated by commas, tell
-Vim to delete the white space at the start of the line, a line break and the
-character before where Insert mode started.
->
-
- set autoindent
-
-This makes Vim use the indent of the previous line for a newly created line.
-Thus there is the same amount of white space before the new line. For example
-when pressing <Enter> in Insert mode, and when using the "o" command to open a
-new line.
+In this section we will explain the various commands that can be specified in
+this file. This will give you hints about how to set up your own preferences.
+Not everything will be explained though. Use the ":help" command to find out
+more.
>
-
set backup
This tells Vim to keep a backup copy of a file when overwriting it. The backup
file will have the same name as the original file with "~" added. See |07.4|
>
-
set history=50
-
+<
Keep 50 commands and 50 search patterns in the history. Use another number if
you want to remember fewer or more lines.
>
-
- set ruler
-
-Always display the current cursor position in the lower right corner of the
-Vim window.
-
->
- set showcmd
-
-Display an incomplete command in the lower right corner of the Vim window,
-left of the ruler. For example, when you type "2f", Vim is waiting for you to
-type the character to find and "2f" is displayed. When you press "w" next,
-the "2fw" command is executed and the displayed "2f" is removed.
->
- +-------------------------------------------------+
- |text in the Vim window |
- |~ |
- |~ |
- |-- VISUAL -- 2f 43,8 17% |
- +-------------------------------------------------+
- ^^^^^^^^^^^ ^^^^^^^^ ^^^^^^^^^^
- 'showmode' 'showcmd' 'ruler'
-
->
- set incsearch
-<
-Display matches for a search pattern while you type.
-
->
map Q gq
This defines a key mapping. More about that in the next section. This
-defines the "Q" command to do formatting with the "gq" operator. This is how
-it worked before Vim 5.0. Otherwise the "Q" command repeats the last recorded
-register.
-
+defines the "Q" command to do formatting with the "gq" operator. Otherwise the
+"Q" command repeats the last recorded register.
>
vnoremap _g y:exe "grep /" .. escape(@", '\\/') .. "/ *.c *.h"<CR>
@@ -138,14 +90,8 @@ This is a complicated mapping. You can see that mappings can be used to do
quite complicated things. Still, it is just a sequence of commands that are
executed like you typed them.
+ *vimrc-filetype*
>
- set hlsearch
-
-This option tells Vim to highlight matches with the last used search pattern.
-The "if" command is very useful to set options only when some condition is
-met. More about that in |usr_41.txt|.
-
- *vimrc-filetype* >
filetype plugin indent on
This switches on three very clever mechanisms:
@@ -342,7 +288,7 @@ That's all! Now you can use the commands defined in this plugin.
Instead of putting plugins directly into the plugin/ directory, you may
better organize them by putting them into subdirectories under plugin/.
-As an example, consider using "~/.local/share/nvim/site/plugin/perl/*.vim" for
+As an example, consider using "~/.local/share/nvim/site/plugin/perl/*.vim" for
all your Perl plugins.
diff --git a/runtime/doc/usr_41.txt b/runtime/doc/usr_41.txt
index 0f2cfdd2ac..ed16f837cf 100644
--- a/runtime/doc/usr_41.txt
+++ b/runtime/doc/usr_41.txt
@@ -721,6 +721,10 @@ Floating point computation: *float-functions*
isinf() check for infinity
isnan() check for not a number
+Blob manipulation: *blob-functions*
+ blob2list() get a list of numbers from a blob
+ list2blob() get a blob from a list of numbers
+
Other computation: *bitwise-function*
and() bitwise AND
invert() bitwise invert
@@ -1321,6 +1325,8 @@ is a List with arguments.
Function references are most useful in combination with a Dictionary, as is
explained in the next section.
+More information about defining your own functions here: |user-functions|.
+
==============================================================================
*41.8* Lists and Dictionaries
diff --git a/runtime/ftplugin/quarto.vim b/runtime/ftplugin/quarto.vim
new file mode 100644
index 0000000000..a76bcc2c7e
--- /dev/null
+++ b/runtime/ftplugin/quarto.vim
@@ -0,0 +1 @@
+runtime ftplugin/rmd.vim
diff --git a/runtime/ftplugin/r.vim b/runtime/ftplugin/r.vim
index a78afa2e7e..28966368cb 100644
--- a/runtime/ftplugin/r.vim
+++ b/runtime/ftplugin/r.vim
@@ -2,7 +2,7 @@
" Language: R
" Maintainer: Jakson Alves de Aquino <jalvesaq@gmail.com>
" Homepage: https://github.com/jalvesaq/R-Vim-runtime
-" Last Change: Sat Aug 15, 2020 11:37AM
+" Last Change: Sun Apr 24, 2022 09:14AM
" Only do this when not yet done for this buffer
if exists("b:did_ftplugin")
@@ -22,7 +22,7 @@ setlocal comments=:#',:###,:##,:#
if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
let b:browsefilter = "R Source Files (*.R)\t*.R\n" .
- \ "Files that include R (*.Rnw *.Rd *.Rmd *.Rrst)\t*.Rnw;*.Rd;*.Rmd;*.Rrst\n" .
+ \ "Files that include R (*.Rnw *.Rd *.Rmd *.Rrst *.qmd)\t*.Rnw;*.Rd;*.Rmd;*.Rrst;*.qmd\n" .
\ "All Files (*.*)\t*.*\n"
endif
diff --git a/runtime/ftplugin/rhelp.vim b/runtime/ftplugin/rhelp.vim
index d0b546d62d..2fde4875c6 100644
--- a/runtime/ftplugin/rhelp.vim
+++ b/runtime/ftplugin/rhelp.vim
@@ -2,7 +2,7 @@
" Language: R help file
" Maintainer: Jakson Alves de Aquino <jalvesaq@gmail.com>
" Homepage: https://github.com/jalvesaq/R-Vim-runtime
-" Last Change: Sat Aug 15, 2020 12:01PM
+" Last Change: Sun Apr 24, 2022 09:12AM
" Only do this when not yet done for this buffer
if exists("b:did_ftplugin")
@@ -18,7 +18,7 @@ set cpo&vim
setlocal iskeyword=@,48-57,_,.
if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
- let b:browsefilter = "R Source Files (*.R *.Rnw *.Rd *.Rmd *.Rrst)\t*.R;*.Rnw;*.Rd;*.Rmd;*.Rrst\n" .
+ let b:browsefilter = "R Source Files (*.R *.Rnw *.Rd *.Rmd *.Rrst *.qmd)\t*.R;*.Rnw;*.Rd;*.Rmd;*.Rrst;*.qmd\n" .
\ "All Files (*.*)\t*.*\n"
endif
diff --git a/runtime/ftplugin/rmd.vim b/runtime/ftplugin/rmd.vim
index 2ee72ffc6c..355b88f04a 100644
--- a/runtime/ftplugin/rmd.vim
+++ b/runtime/ftplugin/rmd.vim
@@ -2,7 +2,7 @@
" Language: R Markdown file
" Maintainer: Jakson Alves de Aquino <jalvesaq@gmail.com>
" Homepage: https://github.com/jalvesaq/R-Vim-runtime
-" Last Change: Sat Aug 15, 2020 12:03PM
+" Last Change: Sun Apr 24, 2022 09:12AM
" Original work by Alex Zvoleff (adjusted from R help for rmd by Michel Kuhlmann)
" Only do this when not yet done for this buffer
@@ -32,13 +32,24 @@ function! FormatRmd()
return 1
endfunction
-" If you do not want 'comments' dynamically defined, put in your vimrc:
-" let g:rmd_dynamic_comments = 0
+function! SetRmdCommentStr()
+ if (search("^[ \t]*```[ ]*{r", "bncW") > search("^[ \t]*```$", "bncW")) || ((search('^---$', 'Wn') || search('^\.\.\.$', 'Wn')) && search('^---$', 'bnW'))
+ set commentstring=#\ %s
+ else
+ set commentstring=<!--\ %s\ -->
+ endif
+endfunction
+
+" If you do not want both 'comments' and 'commentstring' dynamically defined,
+" put in your vimrc: let g:rmd_dynamic_comments = 0
if !exists("g:rmd_dynamic_comments") || (exists("g:rmd_dynamic_comments") && g:rmd_dynamic_comments == 1)
setlocal formatexpr=FormatRmd()
+ augroup RmdCStr
+ autocmd!
+ autocmd CursorMoved <buffer> call SetRmdCommentStr()
+ augroup END
endif
-
" Enables pandoc if it is installed
unlet! b:did_ftplugin
runtime ftplugin/pandoc.vim
@@ -47,7 +58,7 @@ runtime ftplugin/pandoc.vim
let b:did_ftplugin = 1
if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
- let b:browsefilter = "R Source Files (*.R *.Rnw *.Rd *.Rmd *.Rrst)\t*.R;*.Rnw;*.Rd;*.Rmd;*.Rrst\n" .
+ let b:browsefilter = "R Source Files (*.R *.Rnw *.Rd *.Rmd *.Rrst *.qmd)\t*.R;*.Rnw;*.Rd;*.Rmd;*.Rrst;*.qmd\n" .
\ "All Files (*.*)\t*.*\n"
endif
diff --git a/runtime/ftplugin/rnoweb.vim b/runtime/ftplugin/rnoweb.vim
index dc5f1b5e06..cf1c0922c0 100644
--- a/runtime/ftplugin/rnoweb.vim
+++ b/runtime/ftplugin/rnoweb.vim
@@ -2,7 +2,7 @@
" Language: Rnoweb
" Maintainer: Jakson Alves de Aquino <jalvesaq@gmail.com>
" Homepage: https://github.com/jalvesaq/R-Vim-runtime
-" Last Change: Sat Aug 15, 2020 12:02PM
+" Last Change: Sun Apr 24, 2022 09:13AM
" Only do this when not yet done for this buffer
if exists("b:did_ftplugin")
@@ -25,10 +25,27 @@ setlocal suffixesadd=.bib,.tex
setlocal comments=b:%,b:#,b:##,b:###,b:#'
if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
- let b:browsefilter = "R Source Files (*.R *.Rnw *.Rd *.Rmd *.Rrst)\t*.R;*.Rnw;*.Rd;*.Rmd;*.Rrst\n" .
+ let b:browsefilter = "R Source Files (*.R *.Rnw *.Rd *.Rmd *.Rrst *.qmd)\t*.R;*.Rnw;*.Rd;*.Rmd;*.Rrst;*.qmd\n" .
\ "All Files (*.*)\t*.*\n"
endif
+function! SetRnwCommentStr()
+ if (search("^\s*<<.*>>=", "bncW") > search("^@", "bncW"))
+ set commentstring=#\ %s
+ else
+ set commentstring=%\ %s
+ endif
+endfunction
+
+" If you do not want both 'comments' and 'commentstring' dynamically defined,
+" put in your vimrc: let g:rnw_dynamic_comments = 0
+if !exists("g:rnw_dynamic_comments") || (exists("g:rnw_dynamic_comments") && g:rnw_dynamic_comments == 1)
+ augroup RnwCStr
+ autocmd!
+ autocmd CursorMoved <buffer> call SetRnwCommentStr()
+ augroup END
+endif
+
if exists('b:undo_ftplugin')
let b:undo_ftplugin .= " | setl isk< sua< com< | unlet! b:browsefilter"
else
diff --git a/runtime/ftplugin/rrst.vim b/runtime/ftplugin/rrst.vim
index a56fd6478e..19c67c4cc2 100644
--- a/runtime/ftplugin/rrst.vim
+++ b/runtime/ftplugin/rrst.vim
@@ -2,7 +2,7 @@
" Language: reStructuredText documentation format with R code
" Maintainer: Jakson Alves de Aquino <jalvesaq@gmail.com>
" Homepage: https://github.com/jalvesaq/R-Vim-runtime
-" Last Change: Sat Aug 15, 2020 12:02PM
+" Last Change: Sun Apr 24, 2022 09:13AM
" Original work by Alex Zvoleff
" Only do this when not yet done for this buffer
@@ -38,7 +38,7 @@ if !exists("g:rrst_dynamic_comments") || (exists("g:rrst_dynamic_comments") && g
endif
if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
- let b:browsefilter = "R Source Files (*.R *.Rnw *.Rd *.Rmd *.Rrst)\t*.R;*.Rnw;*.Rd;*.Rmd;*.Rrst\n" .
+ let b:browsefilter = "R Source Files (*.R *.Rnw *.Rd *.Rmd *.Rrst *.qmd)\t*.R;*.Rnw;*.Rd;*.Rmd;*.Rrst;*.qmd\n" .
\ "All Files (*.*)\t*.*\n"
endif
diff --git a/runtime/indent/quarto.vim b/runtime/indent/quarto.vim
new file mode 100644
index 0000000000..586d232d2b
--- /dev/null
+++ b/runtime/indent/quarto.vim
@@ -0,0 +1 @@
+runtime indent/rmd.vim
diff --git a/runtime/indent/r.vim b/runtime/indent/r.vim
index ca85a2e62d..293dd98175 100644
--- a/runtime/indent/r.vim
+++ b/runtime/indent/r.vim
@@ -2,7 +2,7 @@
" Language: R
" Author: Jakson Alves de Aquino <jalvesaq@gmail.com>
" Homepage: https://github.com/jalvesaq/R-Vim-runtime
-" Last Change: Sun Aug 19, 2018 09:13PM
+" Last Change: Wed Oct 26, 2022 12:04PM
" Only load this indent file when no other was loaded.
@@ -14,6 +14,8 @@ let b:did_indent = 1
setlocal indentkeys=0{,0},:,!^F,o,O,e
setlocal indentexpr=GetRIndent()
+let b:undo_indent = "setl inde< indk<"
+
" Only define the function once.
if exists("*GetRIndent")
finish
@@ -28,7 +30,7 @@ let g:r_indent_ess_comments = get(g:, 'r_indent_ess_comments', 0)
let g:r_indent_comment_column = get(g:, 'r_indent_comment_column', 40)
let g:r_indent_ess_compatible = get(g:, 'r_indent_ess_compatible', 0)
let g:r_indent_op_pattern = get(g:, 'r_indent_op_pattern',
- \ '\(&\||\|+\|-\|\*\|/\|=\|\~\|%\|->\)\s*$')
+ \ '\(&\||\|+\|-\|\*\|/\|=\|\~\|%\|->\||>\)\s*$')
function s:RDelete_quotes(line)
let i = 0
@@ -359,17 +361,19 @@ function GetRIndent()
let olnum = s:Get_prev_line(lnum)
let oline = getline(olnum)
if olnum > 0
- if line =~ g:r_indent_op_pattern && s:Get_paren_balance(line, "(", ")") == 0
- if oline =~ g:r_indent_op_pattern && s:Get_paren_balance(line, "(", ")") == 0
+ if substitute(line, '#.*', '', '') =~ g:r_indent_op_pattern && s:Get_paren_balance(line, "(", ")") == 0
+ if substitute(oline, '#.*', '', '') =~ g:r_indent_op_pattern && s:Get_paren_balance(line, "(", ")") == 0
return indent(lnum)
else
return indent(lnum) + shiftwidth()
endif
else
- if oline =~ g:r_indent_op_pattern && s:Get_paren_balance(line, "(", ")") == 0
+ if substitute(oline, '#.*', '', '') =~ g:r_indent_op_pattern && s:Get_paren_balance(line, "(", ")") == 0
return indent(lnum) - shiftwidth()
endif
endif
+ elseif substitute(line, '#.*', '', '') =~ g:r_indent_op_pattern && s:Get_paren_balance(line, "(", ")") == 0
+ return indent(lnum) + shiftwidth()
endif
let post_fun = 0
diff --git a/runtime/indent/rhelp.vim b/runtime/indent/rhelp.vim
index cf69ae3392..2b9d49b915 100644
--- a/runtime/indent/rhelp.vim
+++ b/runtime/indent/rhelp.vim
@@ -2,7 +2,7 @@
" Language: R Documentation (Help), *.Rd
" Author: Jakson Alves de Aquino <jalvesaq@gmail.com>
" Homepage: https://github.com/jalvesaq/R-Vim-runtime
-" Last Change: Tue Apr 07, 2015 04:38PM
+" Last Change: Feb 25, 2023
" Only load this indent file when no other was loaded.
@@ -20,6 +20,8 @@ setlocal nolisp
setlocal indentkeys=0{,0},:,!^F,o,O,e
setlocal indentexpr=GetCorrectRHelpIndent()
+let b:undo_indent = "setl ai< cin< inde< indk< lisp< si<"
+
" Only define the functions once.
if exists("*GetRHelpIndent")
finish
diff --git a/runtime/indent/rmd.vim b/runtime/indent/rmd.vim
index 8fd57257fa..a043b0c994 100644
--- a/runtime/indent/rmd.vim
+++ b/runtime/indent/rmd.vim
@@ -2,7 +2,7 @@
" Language: Rmd
" Author: Jakson Alves de Aquino <jalvesaq@gmail.com>
" Homepage: https://github.com/jalvesaq/R-Vim-runtime
-" Last Change: Sun Mar 28, 2021 08:05PM
+" Last Change: Wed Nov 09, 2022 09:44PM
" Only load this indent file when no other was loaded.
@@ -16,6 +16,8 @@ let b:did_indent = 1
setlocal indentkeys=0{,0},<:>,!^F,o,O,e
setlocal indentexpr=GetRmdIndent()
+let b:undo_indent = "setl inde< indk<"
+
if exists("*GetRmdIndent")
finish
endif
@@ -47,6 +49,8 @@ function s:GetMdIndent()
return indent(v:lnum - 1) + 2
elseif pline =~ '^\s*\d\+\.\s\+'
return indent(v:lnum - 1) + 3
+ elseif pline =~ '^\[\^\S\+\]: '
+ return indent(v:lnum - 1) + shiftwidth()
endif
return indent(prevnonblank(v:lnum - 1))
endfunction
diff --git a/runtime/indent/rnoweb.vim b/runtime/indent/rnoweb.vim
index 73966868b8..33bc103d18 100644
--- a/runtime/indent/rnoweb.vim
+++ b/runtime/indent/rnoweb.vim
@@ -2,7 +2,7 @@
" Language: Rnoweb
" Author: Jakson Alves de Aquino <jalvesaq@gmail.com>
" Homepage: https://github.com/jalvesaq/R-Vim-runtime
-" Last Change: Fri Apr 15, 2016 10:58PM
+" Last Change: Feb 25, 2023
" Only load this indent file when no other was loaded.
@@ -29,6 +29,8 @@ let b:did_indent = 1
setlocal indentkeys=0{,0},!^F,o,O,e,},=\bibitem,=\item
setlocal indentexpr=GetRnowebIndent()
+let b:undo_indent = "setl inde< indk<"
+
if exists("*GetRnowebIndent")
finish
endif
diff --git a/runtime/indent/rrst.vim b/runtime/indent/rrst.vim
index f3ee53e7fb..585c5e6654 100644
--- a/runtime/indent/rrst.vim
+++ b/runtime/indent/rrst.vim
@@ -2,7 +2,7 @@
" Language: Rrst
" Author: Jakson Alves de Aquino <jalvesaq@gmail.com>
" Homepage: https://github.com/jalvesaq/R-Vim-runtime
-" Last Change: Tue Apr 07, 2015 04:38PM
+" Last Change: Feb 25, 2023
" Only load this indent file when no other was loaded.
@@ -16,6 +16,8 @@ let b:did_indent = 1
setlocal indentkeys=0{,0},:,!^F,o,O,e
setlocal indentexpr=GetRrstIndent()
+let b:undo_indent = "setl inde< indk<"
+
if exists("*GetRrstIndent")
finish
endif
diff --git a/runtime/lua/vim/_inspector.lua b/runtime/lua/vim/_inspector.lua
index f46a525910..bb6608421b 100644
--- a/runtime/lua/vim/_inspector.lua
+++ b/runtime/lua/vim/_inspector.lua
@@ -69,7 +69,7 @@ function vim.inspect_pos(bufnr, row, col, filter)
-- treesitter
if filter.treesitter then
for _, capture in pairs(vim.treesitter.get_captures_at_pos(bufnr, row, col)) do
- capture.hl_group = '@' .. capture.capture
+ capture.hl_group = '@' .. capture.capture .. '.' .. capture.lang
table.insert(results.treesitter, resolve_hl(capture))
end
end
diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua
index a4e078fd04..256c053801 100644
--- a/runtime/lua/vim/filetype.lua
+++ b/runtime/lua/vim/filetype.lua
@@ -276,6 +276,7 @@ local extension = {
feature = 'cucumber',
cuh = 'cuda',
cu = 'cuda',
+ cue = 'cue',
pld = 'cupl',
si = 'cuplsim',
cyn = 'cynpp',
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua
index d215b4c47e..61a06ff7a7 100644
--- a/runtime/lua/vim/lsp.lua
+++ b/runtime/lua/vim/lsp.lua
@@ -908,11 +908,11 @@ end
--- the `cmd` process. Not related to `root_dir`.
---
--- - cmd_env: (table) Environment flags to pass to the LSP on
---- spawn. Can be specified using keys like a map or as a list with `k=v`
---- pairs or both. Non-string values are coerced to string.
+--- spawn. Must be specified using a map-like table.
+--- Non-string values are coerced to string.
--- Example:
--- <pre>
---- { "PRODUCTION=true"; "TEST=123"; PORT = 8080; HOST = "0.0.0.0"; }
+--- { PORT = 8080; HOST = "0.0.0.0"; }
--- </pre>
---
--- - detached: (boolean, default true) Daemonize the server process so that it runs in a
diff --git a/runtime/lua/vim/lsp/semantic_tokens.lua b/runtime/lua/vim/lsp/semantic_tokens.lua
index 00b4757ea9..24b5c6c24e 100644
--- a/runtime/lua/vim/lsp/semantic_tokens.lua
+++ b/runtime/lua/vim/lsp/semantic_tokens.lua
@@ -334,7 +334,8 @@ function STHighlighter:process_response(response, client, version)
current_result.highlights = tokens_to_ranges(tokens, self.bufnr, client)
current_result.namespace_cleared = false
- api.nvim_command('redraw!')
+ -- redraw all windows displaying buffer
+ api.nvim__buf_redraw_range(self.bufnr, 0, -1)
end
--- on_win handler for the decoration provider (see |nvim_set_decoration_provider|)
diff --git a/runtime/lua/vim/treesitter/health.lua b/runtime/lua/vim/treesitter/health.lua
index 1abcdd0b31..fd1188fde4 100644
--- a/runtime/lua/vim/treesitter/health.lua
+++ b/runtime/lua/vim/treesitter/health.lua
@@ -2,28 +2,26 @@ local M = {}
local ts = vim.treesitter
local health = require('vim.health')
---- Lists the parsers currently installed
----
----@return string[] list of parser files
-function M.list_parsers()
- return vim.api.nvim_get_runtime_file('parser/*', true)
-end
-
--- Performs a healthcheck for treesitter integration
function M.check()
- local parsers = M.list_parsers()
+ local parsers = vim.api.nvim_get_runtime_file('parser/*', true)
health.report_info(string.format('Nvim runtime ABI version: %d', ts.language_version))
for _, parser in pairs(parsers) do
local parsername = vim.fn.fnamemodify(parser, ':t:r')
- local is_loadable, ret = pcall(ts.language.add, parsername)
+ local is_loadable, err_or_nil = pcall(ts.language.add, parsername)
- if not is_loadable or not ret then
+ if not is_loadable then
health.report_error(
- string.format('Parser "%s" failed to load (path: %s): %s', parsername, parser, ret or '?')
+ string.format(
+ 'Parser "%s" failed to load (path: %s): %s',
+ parsername,
+ parser,
+ err_or_nil or '?'
+ )
)
- elseif ret then
+ else
local lang = ts.language.inspect_language(parsername)
health.report_ok(
string.format('Parser: %-10s ABI: %d, path: %s', parsername, lang._abi_version, parser)
diff --git a/runtime/lua/vim/treesitter/language.lua b/runtime/lua/vim/treesitter/language.lua
index 0796383bf5..5bcc786e88 100644
--- a/runtime/lua/vim/treesitter/language.lua
+++ b/runtime/lua/vim/treesitter/language.lua
@@ -63,7 +63,7 @@ function M.add(lang, opts)
M.register(lang, filetype or lang)
if vim._ts_has_language(lang) then
- return true
+ return
end
if path == nil then
diff --git a/runtime/lua/vim/treesitter/languagetree.lua b/runtime/lua/vim/treesitter/languagetree.lua
index 7ec7bbfa12..43fb866896 100644
--- a/runtime/lua/vim/treesitter/languagetree.lua
+++ b/runtime/lua/vim/treesitter/languagetree.lua
@@ -467,7 +467,7 @@ function LanguageTree:_get_injections()
-- Generate a map by lang of node lists.
-- Each list is a set of ranges that should be parsed together.
- for _, lang_map in ipairs(injections) do
+ for _, lang_map in pairs(injections) do
for lang, patterns in pairs(lang_map) do
if not result[lang] then
result[lang] = {}
diff --git a/runtime/lua/vim/treesitter/playground.lua b/runtime/lua/vim/treesitter/playground.lua
index 001bc2d5bf..fd5b687195 100644
--- a/runtime/lua/vim/treesitter/playground.lua
+++ b/runtime/lua/vim/treesitter/playground.lua
@@ -138,6 +138,19 @@ end
local decor_ns = api.nvim_create_namespace('ts.playground')
+---@private
+---@param lnum integer
+---@param col integer
+---@param end_lnum integer
+---@param end_col integer
+---@return string
+local function get_range_str(lnum, col, end_col, end_lnum)
+ if lnum == end_lnum then
+ return string.format('[%d:%d-%d]', lnum + 1, col + 1, end_col)
+ end
+ return string.format('[%d:%d-%d:%d]', lnum + 1, col + 1, end_lnum + 1, end_col)
+end
+
--- Write the contents of this Playground into {bufnr}.
---
---@param bufnr number Buffer number to write into.
@@ -145,26 +158,31 @@ local decor_ns = api.nvim_create_namespace('ts.playground')
function TSPlayground:draw(bufnr)
vim.bo[bufnr].modifiable = true
local lines = {} ---@type string[]
+ local lang_hl_marks = {} ---@type table[]
+
for _, item in self:iter() do
- lines[#lines + 1] = string.rep(' ', item.depth) .. item.text
+ local range_str = get_range_str(item.lnum, item.col, item.end_lnum, item.end_col)
+ local lang_str = self.opts.lang and string.format(' %s', item.lang) or ''
+ local line = string.rep(' ', item.depth) .. item.text .. '; ' .. range_str .. lang_str
+
+ if self.opts.lang then
+ lang_hl_marks[#lang_hl_marks + 1] = {
+ col = #line - #lang_str,
+ end_col = #line,
+ }
+ end
+
+ lines[#lines + 1] = line
end
+
api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
api.nvim_buf_clear_namespace(bufnr, decor_ns, 0, -1)
- for i, item in self:iter() do
- local range_str
- if item.lnum == item.end_lnum then
- range_str = string.format('[%d:%d-%d]', item.lnum + 1, item.col + 1, item.end_col)
- else
- range_str =
- string.format('[%d:%d-%d:%d]', item.lnum + 1, item.col + 1, item.end_lnum + 1, item.end_col)
- end
-
- local lang_str = self.opts.lang and string.format(' %s', item.lang) or ''
-
- api.nvim_buf_set_extmark(bufnr, decor_ns, i - 1, 0, {
- virt_text = { { range_str, 'Comment' }, { lang_str, 'Title' } },
+ for i, m in ipairs(lang_hl_marks) do
+ api.nvim_buf_set_extmark(bufnr, decor_ns, i - 1, m.col, {
+ hl_group = 'Title',
+ end_col = m.end_col,
})
end
diff --git a/runtime/plugin/matchparen.vim b/runtime/plugin/matchparen.vim
index 3982489b92..e19b283228 100644
--- a/runtime/plugin/matchparen.vim
+++ b/runtime/plugin/matchparen.vim
@@ -108,8 +108,9 @@ func s:Highlight_Matching_Pair()
" searchpairpos()'s skip argument.
" We match "escape" for special items, such as lispEscapeSpecial, and
" match "symbol" for lispBarSymbol.
- let s_skip = '!empty(filter(map(synstack(line("."), col(".")), ''synIDattr(v:val, "name")''), ' .
- \ '''v:val =~? "string\\|character\\|singlequote\\|escape\\|symbol\\|comment"''))'
+ let s_skip = 'synstack(".", col("."))'
+ \ . '->indexof({_, id -> synIDattr(id, "name") =~? '
+ \ . '"string\\|character\\|singlequote\\|escape\\|symbol\\|comment"}) >= 0'
" If executing the expression determines that the cursor is currently in
" one of the syntax types, then we want searchpairpos() to find the pair
" within those syntax types (i.e., not skip). Otherwise, the cursor is
diff --git a/runtime/syntax/python.vim b/runtime/syntax/python.vim
index ef4da1b448..831fb92f4c 100644
--- a/runtime/syntax/python.vim
+++ b/runtime/syntax/python.vim
@@ -1,7 +1,7 @@
" Vim syntax file
" Language: Python
" Maintainer: Zvezdan Petkovic <zpetkovic@acm.org>
-" Last Change: 2022 Jun 28
+" Last Change: 2023 Feb 26
" Credits: Neil Schemenauer <nas@python.ca>
" Dmitry Vasiliev
"
@@ -35,12 +35,26 @@
"
" let python_highlight_all = 1
"
+" The use of Python 2 compatible syntax highlighting can be enforced.
+" The straddling code (Python 2 and 3 compatible), up to Python 3.5,
+" will be also supported.
+"
+" let python_use_python2_syntax = 1
+"
+" This option will exclude all modern Python 3.6 or higher features.
+"
" quit when a syntax file was already loaded.
if exists("b:current_syntax")
finish
endif
+" Use of Python 2 and 3.5 or lower requested.
+if exists("python_use_python2_syntax")
+ runtime! syntax/python2.vim
+ finish
+endif
+
" We need nocompatible mode in order to continue lines with backslashes.
" Original setting will be restored.
let s:cpo_save = &cpo
@@ -91,8 +105,8 @@ syn keyword pythonInclude from import
syn keyword pythonAsync async await
" Soft keywords
-" These keywords do not mean anything unless used in the right context
-" See https://docs.python.org/3/reference/lexical_analysis.html#soft-keywords
+" These keywords do not mean anything unless used in the right context.
+" See https://docs.python.org/3/reference/lexical_analysis.html#soft-keywords
" for more on this.
syn match pythonConditional "^\s*\zscase\%(\s\+.*:.*$\)\@="
syn match pythonConditional "^\s*\zsmatch\%(\s\+.*:\s*\%(#.*\)\=$\)\@="
diff --git a/runtime/syntax/python2.vim b/runtime/syntax/python2.vim
new file mode 100644
index 0000000000..3b30eabbae
--- /dev/null
+++ b/runtime/syntax/python2.vim
@@ -0,0 +1,345 @@
+" Vim syntax file
+" Language: Python 2
+" Maintainer: Zvezdan Petkovic <zpetkovic@acm.org>
+" Last Change: 2016 Oct 29
+" Credits: Neil Schemenauer <nas@python.ca>
+" Dmitry Vasiliev
+"
+" This version is a major rewrite by Zvezdan Petkovic.
+"
+" - introduced highlighting of doctests
+" - updated keywords, built-ins, and exceptions
+" - corrected regular expressions for
+"
+" * functions
+" * decorators
+" * strings
+" * escapes
+" * numbers
+" * space error
+"
+" - corrected synchronization
+" - more highlighting is ON by default, except
+" - space error highlighting is OFF by default
+"
+" Optional highlighting can be controlled using these variables.
+"
+" let python_no_builtin_highlight = 1
+" let python_no_doctest_code_highlight = 1
+" let python_no_doctest_highlight = 1
+" let python_no_exception_highlight = 1
+" let python_no_number_highlight = 1
+" let python_space_error_highlight = 1
+"
+" All the options above can be switched on together.
+"
+" let python_highlight_all = 1
+"
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+" NOTE: This file is a copy of the last commit of runtime/syntax/python.vim
+" that still supported Python 2. There is support for Python 3, up to 3.5,
+" and it was kept in the file as is, because it supports the straddling code
+" (Python 2 and 3 compatible) better.
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+
+" quit when a syntax file was already loaded.
+if exists("b:current_syntax")
+ finish
+endif
+
+" We need nocompatible mode in order to continue lines with backslashes.
+" Original setting will be restored.
+let s:cpo_save = &cpo
+set cpo&vim
+
+if exists("python_no_doctest_highlight")
+ let python_no_doctest_code_highlight = 1
+endif
+
+if exists("python_highlight_all")
+ if exists("python_no_builtin_highlight")
+ unlet python_no_builtin_highlight
+ endif
+ if exists("python_no_doctest_code_highlight")
+ unlet python_no_doctest_code_highlight
+ endif
+ if exists("python_no_doctest_highlight")
+ unlet python_no_doctest_highlight
+ endif
+ if exists("python_no_exception_highlight")
+ unlet python_no_exception_highlight
+ endif
+ if exists("python_no_number_highlight")
+ unlet python_no_number_highlight
+ endif
+ let python_space_error_highlight = 1
+endif
+
+" Keep Python keywords in alphabetical order inside groups for easy
+" comparison with the table in the 'Python Language Reference'
+" https://docs.python.org/2/reference/lexical_analysis.html#keywords,
+" https://docs.python.org/3/reference/lexical_analysis.html#keywords.
+" Groups are in the order presented in NAMING CONVENTIONS in syntax.txt.
+" Exceptions come last at the end of each group (class and def below).
+"
+" Keywords 'with' and 'as' are new in Python 2.6
+" (use 'from __future__ import with_statement' in Python 2.5).
+"
+" Some compromises had to be made to support both Python 3 and 2.
+" We include Python 3 features, but when a definition is duplicated,
+" the last definition takes precedence.
+"
+" - 'False', 'None', and 'True' are keywords in Python 3 but they are
+" built-ins in 2 and will be highlighted as built-ins below.
+" - 'exec' is a built-in in Python 3 and will be highlighted as
+" built-in below.
+" - 'nonlocal' is a keyword in Python 3 and will be highlighted.
+" - 'print' is a built-in in Python 3 and will be highlighted as
+" built-in below (use 'from __future__ import print_function' in 2)
+" - async and await were added in Python 3.5 and are soft keywords.
+"
+syn keyword pythonStatement False None True
+syn keyword pythonStatement as assert break continue del exec global
+syn keyword pythonStatement lambda nonlocal pass print return with yield
+syn keyword pythonStatement class def nextgroup=pythonFunction skipwhite
+syn keyword pythonConditional elif else if
+syn keyword pythonRepeat for while
+syn keyword pythonOperator and in is not or
+syn keyword pythonException except finally raise try
+syn keyword pythonInclude from import
+syn keyword pythonAsync async await
+
+" Decorators (new in Python 2.4)
+" A dot must be allowed because of @MyClass.myfunc decorators.
+syn match pythonDecorator "@" display contained
+syn match pythonDecoratorName "@\s*\h\%(\w\|\.\)*" display contains=pythonDecorator
+
+" Python 3.5 introduced the use of the same symbol for matrix multiplication:
+" https://www.python.org/dev/peps/pep-0465/. We now have to exclude the
+" symbol from highlighting when used in that context.
+" Single line multiplication.
+syn match pythonMatrixMultiply
+ \ "\%(\w\|[])]\)\s*@"
+ \ contains=ALLBUT,pythonDecoratorName,pythonDecorator,pythonFunction,pythonDoctestValue
+ \ transparent
+" Multiplication continued on the next line after backslash.
+syn match pythonMatrixMultiply
+ \ "[^\\]\\\s*\n\%(\s*\.\.\.\s\)\=\s\+@"
+ \ contains=ALLBUT,pythonDecoratorName,pythonDecorator,pythonFunction,pythonDoctestValue
+ \ transparent
+" Multiplication in a parenthesized expression over multiple lines with @ at
+" the start of each continued line; very similar to decorators and complex.
+syn match pythonMatrixMultiply
+ \ "^\s*\%(\%(>>>\|\.\.\.\)\s\+\)\=\zs\%(\h\|\%(\h\|[[(]\).\{-}\%(\w\|[])]\)\)\s*\n\%(\s*\.\.\.\s\)\=\s\+@\%(.\{-}\n\%(\s*\.\.\.\s\)\=\s\+@\)*"
+ \ contains=ALLBUT,pythonDecoratorName,pythonDecorator,pythonFunction,pythonDoctestValue
+ \ transparent
+
+syn match pythonFunction "\h\w*" display contained
+
+syn match pythonComment "#.*$" contains=pythonTodo,@Spell
+syn keyword pythonTodo FIXME NOTE NOTES TODO XXX contained
+
+" Triple-quoted strings can contain doctests.
+syn region pythonString matchgroup=pythonQuotes
+ \ start=+[uU]\=\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
+ \ contains=pythonEscape,@Spell
+syn region pythonString matchgroup=pythonTripleQuotes
+ \ start=+[uU]\=\z('''\|"""\)+ end="\z1" keepend
+ \ contains=pythonEscape,pythonSpaceError,pythonDoctest,@Spell
+syn region pythonRawString matchgroup=pythonQuotes
+ \ start=+[uU]\=[rR]\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
+ \ contains=@Spell
+syn region pythonRawString matchgroup=pythonTripleQuotes
+ \ start=+[uU]\=[rR]\z('''\|"""\)+ end="\z1" keepend
+ \ contains=pythonSpaceError,pythonDoctest,@Spell
+
+syn match pythonEscape +\\[abfnrtv'"\\]+ contained
+syn match pythonEscape "\\\o\{1,3}" contained
+syn match pythonEscape "\\x\x\{2}" contained
+syn match pythonEscape "\%(\\u\x\{4}\|\\U\x\{8}\)" contained
+" Python allows case-insensitive Unicode IDs: http://www.unicode.org/charts/
+syn match pythonEscape "\\N{\a\+\%(\s\a\+\)*}" contained
+syn match pythonEscape "\\$"
+
+" It is very important to understand all details before changing the
+" regular expressions below or their order.
+" The word boundaries are *not* the floating-point number boundaries
+" because of a possible leading or trailing decimal point.
+" The expressions below ensure that all valid number literals are
+" highlighted, and invalid number literals are not. For example,
+"
+" - a decimal point in '4.' at the end of a line is highlighted,
+" - a second dot in 1.0.0 is not highlighted,
+" - 08 is not highlighted,
+" - 08e0 or 08j are highlighted,
+"
+" and so on, as specified in the 'Python Language Reference'.
+" https://docs.python.org/2/reference/lexical_analysis.html#numeric-literals
+" https://docs.python.org/3/reference/lexical_analysis.html#numeric-literals
+if !exists("python_no_number_highlight")
+ " numbers (including longs and complex)
+ syn match pythonNumber "\<0[oO]\=\o\+[Ll]\=\>"
+ syn match pythonNumber "\<0[xX]\x\+[Ll]\=\>"
+ syn match pythonNumber "\<0[bB][01]\+[Ll]\=\>"
+ syn match pythonNumber "\<\%([1-9]\d*\|0\)[Ll]\=\>"
+ syn match pythonNumber "\<\d\+[jJ]\>"
+ syn match pythonNumber "\<\d\+[eE][+-]\=\d\+[jJ]\=\>"
+ syn match pythonNumber
+ \ "\<\d\+\.\%([eE][+-]\=\d\+\)\=[jJ]\=\%(\W\|$\)\@="
+ syn match pythonNumber
+ \ "\%(^\|\W\)\zs\d*\.\d\+\%([eE][+-]\=\d\+\)\=[jJ]\=\>"
+endif
+
+" Group the built-ins in the order in the 'Python Library Reference' for
+" easier comparison.
+" https://docs.python.org/2/library/constants.html
+" https://docs.python.org/3/library/constants.html
+" http://docs.python.org/2/library/functions.html
+" http://docs.python.org/3/library/functions.html
+" http://docs.python.org/2/library/functions.html#non-essential-built-in-functions
+" http://docs.python.org/3/library/functions.html#non-essential-built-in-functions
+" Python built-in functions are in alphabetical order.
+if !exists("python_no_builtin_highlight")
+ " built-in constants
+ " 'False', 'True', and 'None' are also reserved words in Python 3
+ syn keyword pythonBuiltin False True None
+ syn keyword pythonBuiltin NotImplemented Ellipsis __debug__
+ " built-in functions
+ syn keyword pythonBuiltin abs all any bin bool bytearray callable chr
+ syn keyword pythonBuiltin classmethod compile complex delattr dict dir
+ syn keyword pythonBuiltin divmod enumerate eval filter float format
+ syn keyword pythonBuiltin frozenset getattr globals hasattr hash
+ syn keyword pythonBuiltin help hex id input int isinstance
+ syn keyword pythonBuiltin issubclass iter len list locals map max
+ syn keyword pythonBuiltin memoryview min next object oct open ord pow
+ syn keyword pythonBuiltin print property range repr reversed round set
+ syn keyword pythonBuiltin setattr slice sorted staticmethod str
+ syn keyword pythonBuiltin sum super tuple type vars zip __import__
+ " Python 2 only
+ syn keyword pythonBuiltin basestring cmp execfile file
+ syn keyword pythonBuiltin long raw_input reduce reload unichr
+ syn keyword pythonBuiltin unicode xrange
+ " Python 3 only
+ syn keyword pythonBuiltin ascii bytes exec
+ " non-essential built-in functions; Python 2 only
+ syn keyword pythonBuiltin apply buffer coerce intern
+ " avoid highlighting attributes as builtins
+ syn match pythonAttribute /\.\h\w*/hs=s+1
+ \ contains=ALLBUT,pythonBuiltin,pythonFunction,pythonAsync
+ \ transparent
+endif
+
+" From the 'Python Library Reference' class hierarchy at the bottom.
+" http://docs.python.org/2/library/exceptions.html
+" http://docs.python.org/3/library/exceptions.html
+if !exists("python_no_exception_highlight")
+ " builtin base exceptions (used mostly as base classes for other exceptions)
+ syn keyword pythonExceptions BaseException Exception
+ syn keyword pythonExceptions ArithmeticError BufferError
+ syn keyword pythonExceptions LookupError
+ " builtin base exceptions removed in Python 3
+ syn keyword pythonExceptions EnvironmentError StandardError
+ " builtin exceptions (actually raised)
+ syn keyword pythonExceptions AssertionError AttributeError
+ syn keyword pythonExceptions EOFError FloatingPointError GeneratorExit
+ syn keyword pythonExceptions ImportError IndentationError
+ syn keyword pythonExceptions IndexError KeyError KeyboardInterrupt
+ syn keyword pythonExceptions MemoryError NameError NotImplementedError
+ syn keyword pythonExceptions OSError OverflowError ReferenceError
+ syn keyword pythonExceptions RuntimeError StopIteration SyntaxError
+ syn keyword pythonExceptions SystemError SystemExit TabError TypeError
+ syn keyword pythonExceptions UnboundLocalError UnicodeError
+ syn keyword pythonExceptions UnicodeDecodeError UnicodeEncodeError
+ syn keyword pythonExceptions UnicodeTranslateError ValueError
+ syn keyword pythonExceptions ZeroDivisionError
+ " builtin OS exceptions in Python 3
+ syn keyword pythonExceptions BlockingIOError BrokenPipeError
+ syn keyword pythonExceptions ChildProcessError ConnectionAbortedError
+ syn keyword pythonExceptions ConnectionError ConnectionRefusedError
+ syn keyword pythonExceptions ConnectionResetError FileExistsError
+ syn keyword pythonExceptions FileNotFoundError InterruptedError
+ syn keyword pythonExceptions IsADirectoryError NotADirectoryError
+ syn keyword pythonExceptions PermissionError ProcessLookupError
+ syn keyword pythonExceptions RecursionError StopAsyncIteration
+ syn keyword pythonExceptions TimeoutError
+ " builtin exceptions deprecated/removed in Python 3
+ syn keyword pythonExceptions IOError VMSError WindowsError
+ " builtin warnings
+ syn keyword pythonExceptions BytesWarning DeprecationWarning FutureWarning
+ syn keyword pythonExceptions ImportWarning PendingDeprecationWarning
+ syn keyword pythonExceptions RuntimeWarning SyntaxWarning UnicodeWarning
+ syn keyword pythonExceptions UserWarning Warning
+ " builtin warnings in Python 3
+ syn keyword pythonExceptions ResourceWarning
+endif
+
+if exists("python_space_error_highlight")
+ " trailing whitespace
+ syn match pythonSpaceError display excludenl "\s\+$"
+ " mixed tabs and spaces
+ syn match pythonSpaceError display " \+\t"
+ syn match pythonSpaceError display "\t\+ "
+endif
+
+" Do not spell doctests inside strings.
+" Notice that the end of a string, either ''', or """, will end the contained
+" doctest too. Thus, we do *not* need to have it as an end pattern.
+if !exists("python_no_doctest_highlight")
+ if !exists("python_no_doctest_code_highlight")
+ syn region pythonDoctest
+ \ start="^\s*>>>\s" end="^\s*$"
+ \ contained contains=ALLBUT,pythonDoctest,pythonFunction,@Spell
+ syn region pythonDoctestValue
+ \ start=+^\s*\%(>>>\s\|\.\.\.\s\|"""\|'''\)\@!\S\++ end="$"
+ \ contained
+ else
+ syn region pythonDoctest
+ \ start="^\s*>>>" end="^\s*$"
+ \ contained contains=@NoSpell
+ endif
+endif
+
+" Sync at the beginning of class, function, or method definition.
+syn sync match pythonSync grouphere NONE "^\%(def\|class\)\s\+\h\w*\s*[(:]"
+
+" The default highlight links. Can be overridden later.
+hi def link pythonStatement Statement
+hi def link pythonConditional Conditional
+hi def link pythonRepeat Repeat
+hi def link pythonOperator Operator
+hi def link pythonException Exception
+hi def link pythonInclude Include
+hi def link pythonAsync Statement
+hi def link pythonDecorator Define
+hi def link pythonDecoratorName Function
+hi def link pythonFunction Function
+hi def link pythonComment Comment
+hi def link pythonTodo Todo
+hi def link pythonString String
+hi def link pythonRawString String
+hi def link pythonQuotes String
+hi def link pythonTripleQuotes pythonQuotes
+hi def link pythonEscape Special
+if !exists("python_no_number_highlight")
+ hi def link pythonNumber Number
+endif
+if !exists("python_no_builtin_highlight")
+ hi def link pythonBuiltin Function
+endif
+if !exists("python_no_exception_highlight")
+ hi def link pythonExceptions Structure
+endif
+if exists("python_space_error_highlight")
+ hi def link pythonSpaceError Error
+endif
+if !exists("python_no_doctest_highlight")
+ hi def link pythonDoctest Special
+ hi def link pythonDoctestValue Define
+endif
+
+let b:current_syntax = "python"
+
+let &cpo = s:cpo_save
+unlet s:cpo_save
+
+" vim:set sw=2 sts=2 ts=8 noet:
diff --git a/runtime/syntax/quarto.vim b/runtime/syntax/quarto.vim
new file mode 100644
index 0000000000..d5d4ee257d
--- /dev/null
+++ b/runtime/syntax/quarto.vim
@@ -0,0 +1,17 @@
+" Language: Quarto (Markdown with chunks of R, Python and other languages)
+" Provisory Maintainer: Jakson Aquino <jalvesaq@gmail.com>
+" Homepage: https://github.com/jalvesaq/R-Vim-runtime
+" Last Change: Fri Feb 24, 2023 08:26AM
+"
+" The developers of tools for Quarto maintain Vim runtime files in their
+" Github repository and, if required, I will hand over the maintenance of
+" this script for them.
+
+runtime syntax/rmd.vim
+
+syn match quartoShortarg /\S\+/ contained
+syn keyword quartoShortkey var meta env pagebreak video include contained
+syn region quartoShortcode matchgroup=PreProc start='{{< ' end=' >}}' contains=quartoShortkey,quartoShortarg transparent keepend
+
+hi def link quartoShortkey Include
+hi def link quartoShortarg String
diff --git a/runtime/syntax/r.vim b/runtime/syntax/r.vim
index a8100cfded..9b3754ae23 100644
--- a/runtime/syntax/r.vim
+++ b/runtime/syntax/r.vim
@@ -5,7 +5,7 @@
" Tom Payne <tom@tompayne.org>
" Contributor: Johannes Ranke <jranke@uni-bremen.de>
" Homepage: https://github.com/jalvesaq/R-Vim-runtime
-" Last Change: Sun Mar 28, 2021 01:47PM
+" Last Change: Thu Nov 17, 2022 10:13PM
" Filenames: *.R *.r *.Rhistory *.Rt
"
" NOTE: The highlighting of R functions might be defined in
@@ -65,41 +65,35 @@ if g:r_syntax_hl_roxygen
" roxygen line containing only a roxygen comment marker, optionally followed
" by whitespace is called an empty roxygen line.
+ syn match rOCommentKey "^\s*#\{1,2}'" contained
+ syn region rOExamples start="^\s*#\{1,2}' @examples.*"rs=e+1,hs=e+1 end="^\(#\{1,2}' @.*\)\@=" end="^\(#\{1,2}'\)\@!" contained contains=rOTag fold
+
+ " R6 classes may contain roxygen lines independent of roxygen blocks
+ syn region rOR6Class start=/R6Class(/ end=/)/ transparent contains=ALLBUT,rError,rBraceError,rCurlyError fold
+ syn match rOR6Block "#\{1,2}'.*" contains=rOTag,rOExamples,@Spell containedin=rOR6Class contained
+ syn match rOR6Block "^\s*#\{1,2}'.*" contains=rOTag,rOExamples,@Spell containedin=rOR6Class contained
+
" First we match all roxygen blocks as containing only a title. In case an
" empty roxygen line ending the title or a tag is found, this will be
" overridden later by the definitions of rOBlock.
- syn match rOTitleBlock "\%^\(\s*#\{1,2}' .*\n\)\{1,}" contains=rOCommentKey,rOTitleTag
- syn match rOTitleBlock "^\s*\n\(\s*#\{1,2}' .*\n\)\{1,}" contains=rOCommentKey,rOTitleTag
+ syn match rOTitleBlock "\(\%^\|^\s*\n\)\@<=\(\s*#\{1,2}' .*\n\)\{1,}" contains=rOCommentKey,rOTitleTag
" A title as part of a block is always at the beginning of the block, i.e.
" either at the start of a file or after a completely empty line.
- syn match rOTitle "\%^\(\s*#\{1,2}' .*\n\)\{-1,}\s*#\{1,2}'\s*$" contained contains=rOCommentKey,rOTitleTag
- syn match rOTitle "^\s*\n\(\s*#\{1,2}' .*\n\)\{-1,}\s*#\{1,2}'\s*$" contained contains=rOCommentKey,rOTitleTag
+ syn match rOTitle "\(\%^\|^\s*\n\)\@<=\(\s*#\{1,2}' .*\n\)\{-1,}\s*#\{1,2}'\s*$" contained contains=rOCommentKey,rOTitleTag
syn match rOTitleTag contained "@title"
" When a roxygen block has a title and additional content, the title
" consists of one or more roxygen lines (as little as possible are matched),
" followed either by an empty roxygen line
- syn region rOBlock start="\%^\(\s*#\{1,2}' .*\n\)\{-1,}\s*#\{1,2}'\s*$" end="^\s*\(#\{1,2}'\)\@!" contains=rOTitle,rOTag,rOExamples,@Spell keepend fold
- syn region rOBlock start="^\s*\n\(\s*#\{1,2}' .*\n\)\{-1,}\s*#\{1,2}'\s*$" end="^\s*\(#\{1,2}'\)\@!" contains=rOTitle,rOTag,rOExamples,@Spell keepend fold
+ syn region rOBlock start="\(\%^\|^\s*\n\)\@<=\(\s*#\{1,2}' .*\n\)\{-1,}\s*#\{1,2}'\s*$" end="^\s*\(#\{1,2}'\)\@!" contains=rOTitle,rOTag,rOExamples,@Spell keepend fold
" or by a roxygen tag (we match everything starting with @ but not @@ which is used as escape sequence for a literal @).
- syn region rOBlock start="\%^\(\s*#\{1,2}' .*\n\)\{-}\s*#\{1,2}' @\(@\)\@!" end="^\s*\(#\{1,2}'\)\@!" contains=rOTitle,rOTag,rOExamples,@Spell keepend fold
- syn region rOBlock start="^\s*\n\(\s*#\{1,2}' .*\n\)\{-}\s*#\{1,2}' @\(@\)\@!" end="^\s*\(#\{1,2}'\)\@!" contains=rOTitle,rOTag,rOExamples,@Spell keepend fold
+ syn region rOBlock start="\(\%^\|^\s*\n\)\@<=\(\s*#\{1,2}' .*\n\)\{-}\s*#\{1,2}' @\(@\)\@!" end="^\s*\(#\{1,2}'\)\@!" contains=rOTitle,rOTag,rOExamples,@Spell keepend fold
" If a block contains an @rdname, @describeIn tag, it may have paragraph breaks, but does not have a title
- syn region rOBlockNoTitle start="\%^\(\s*#\{1,2}' .*\n\)\{-1,}\s*#\{1,2}'\s*\n\(\s*#\{1,2}'.*\n\)\{-}\s*#\{1,2}' @rdname" end="^\s*\(#\{1,2}'\)\@!" contains=rOTag,rOExamples,@Spell keepend fold
- syn region rOBlockNoTitle start="^\s*\n\(\s*#\{1,2}' .*\n\)\{-1,}\s*#\{1,2}'\s*\n\(\s*#\{1,2}'.*\n\)\{-}\s*#\{1,2}' @rdname" end="^\s*\(#\{1,2}'\)\@!" contains=rOTag,rOExamples,@Spell keepend fold
- syn region rOBlockNoTitle start="\%^\(\s*#\{1,2}' .*\n\)\{-1,}\s*#\{1,2}'\s*\n\(\s*#\{1,2}'.*\n\)\{-}\s*#\{1,2}' @describeIn" end="^\s*\(#\{1,2}'\)\@!" contains=rOTag,rOExamples,@Spell keepend fold
- syn region rOBlockNoTitle start="^\s*\n\(\s*#\{1,2}' .*\n\)\{-1,}\s*#\{1,2}'\s*\n\(\s*#\{1,2}'.*\n\)\{-}\s*#\{1,2}' @describeIn" end="^\s*\(#\{1,2}'\)\@!" contains=rOTag,rOExamples,@Spell keepend fold
-
- syn match rOCommentKey "^\s*#\{1,2}'" contained
- syn region rOExamples start="^\s*#\{1,2}' @examples.*"rs=e+1,hs=e+1 end="^\(#\{1,2}' @.*\)\@=" end="^\(#\{1,2}'\)\@!" contained contains=rOTag fold
-
- " R6 classes may contain roxygen lines independent of roxygen blocks
- syn region rOR6Class start=/R6Class(/ end=/)/ transparent contains=ALLBUT,rError,rBraceError,rCurlyError fold
- syn match rOR6Block "#\{1,2}'.*" contains=rOTag,rOExamples,@Spell containedin=rOR6Class contained
- syn match rOR6Block "^\s*#\{1,2}'.*" contains=rOTag,rOExamples,@Spell containedin=rOR6Class contained
+ syn region rOBlockNoTitle start="\(\%^\|^\s*\n\)\@<=\(\s*#\{1,2}' .*\n\)\{-1,}\s*#\{1,2}'\s*\n\(\s*#\{1,2}'.*\n\)\{-}\s*#\{1,2}' @rdname" end="^\s*\(#\{1,2}'\)\@!" contains=rOTag,rOExamples,@Spell keepend fold
+ syn region rOBlockNoTitle start="\(\%^\|^\s*\n\)\@<=\(\s*#\{1,2}' .*\n\)\{-1,}\s*#\{1,2}'\s*\n\(\s*#\{1,2}'.*\n\)\{-}\s*#\{1,2}' @describeIn" end="^\s*\(#\{1,2}'\)\@!" contains=rOTag,rOExamples,@Spell keepend fold
" rOTag list originally generated from the lists that were available in
" https://github.com/klutometis/roxygen/R/rd.R and
@@ -245,14 +239,15 @@ syn match rOperator "&"
syn match rOperator '-'
syn match rOperator '\*'
syn match rOperator '+'
-if &filetype != "rmd" && &filetype != "rrst"
- syn match rOperator "[|!<>^~/:]"
-else
+if &filetype == "quarto" || &filetype == "rmd" || &filetype == "rrst"
syn match rOperator "[|!<>^~`/:]"
+else
+ syn match rOperator "[|!<>^~/:]"
endif
syn match rOperator "%\{2}\|%\S\{-}%"
syn match rOperator '\([!><]\)\@<=='
syn match rOperator '=='
+syn match rOperator '|>'
syn match rOpError '\*\{3}'
syn match rOpError '//'
syn match rOpError '&&&'
@@ -318,10 +313,13 @@ if &filetype == "rhelp"
endif
" Type
+syn match rType "\\"
syn keyword rType array category character complex double function integer list logical matrix numeric vector data.frame
" Name of object with spaces
-if &filetype != "rmd" && &filetype != "rrst"
+if &filetype == "rmd" || &filetype == "rrst" || &filetype == "quarto"
+ syn region rNameWSpace start="`" end="`" contains=rSpaceFun containedin=rmdrChunk
+else
syn region rNameWSpace start="`" end="`" contains=rSpaceFun
endif
diff --git a/runtime/syntax/rmd.vim b/runtime/syntax/rmd.vim
index cccd4110f5..f849af97d2 100644
--- a/runtime/syntax/rmd.vim
+++ b/runtime/syntax/rmd.vim
@@ -1,7 +1,7 @@
-" markdown Text with R statements
-" Language: markdown with R code chunks
+" Language: Markdown with chunks of R, Python and other languages
+" Maintainer: Jakson Aquino <jalvesaq@gmail.com>
" Homepage: https://github.com/jalvesaq/R-Vim-runtime
-" Last Change: Wed Apr 21, 2021 09:55AM
+" Last Change: Fri Feb 24, 2023 08:28AM
"
" For highlighting pandoc extensions to markdown like citations and TeX and
" many other advanced features like folding of markdown sections, it is
@@ -13,63 +13,120 @@ if exists("b:current_syntax")
finish
endif
+let s:cpo_save = &cpo
+set cpo&vim
+
" Highlight the header of the chunks as R code
let g:rmd_syn_hl_chunk = get(g:, 'rmd_syn_hl_chunk', 0)
" Pandoc-syntax has more features, but it is slower.
" https://github.com/vim-pandoc/vim-pandoc-syntax
-let g:pandoc#syntax#codeblocks#embeds#langs = get(g:, 'pandoc#syntax#codeblocks#embeds#langs', ['r'])
+
+" Don't waste time loading syntax that will be discarded:
+let s:save_pandoc_lngs = get(g:, 'pandoc#syntax#codeblocks#embeds#langs', [])
+let g:pandoc#syntax#codeblocks#embeds#langs = []
+
+" Step_1: Source pandoc.vim if it is installed:
runtime syntax/pandoc.vim
if exists("b:current_syntax")
+ if hlexists('pandocDelimitedCodeBlock')
+ syn clear pandocDelimitedCodeBlock
+ endif
+
+ if len(s:save_pandoc_lngs) > 0 && !exists('g:rmd_fenced_languages')
+ let g:rmd_fenced_languages = deepcopy(s:save_pandoc_lngs)
+ endif
+
" Recognize inline R code
- syn region rmdrInline matchgroup=rmdInlineDelim start="`r " end="`" contains=@R containedin=pandocLaTeXRegion,yamlFlowString keepend
- hi def link rmdInlineDelim Delimiter
-
- " Fix recognition of language chunks (code adapted from pandoc, 2021-03-28)
- " Knitr requires braces in the block's header
- for s:lng in g:pandoc#syntax#codeblocks#embeds#langs
- let s:nm = matchstr(s:lng, '^[^=]*')
- exe 'syn clear pandocDelimitedCodeBlock_'.s:nm
- exe 'syn clear pandocDelimitedCodeBlockinBlockQuote_'.s:nm
- if g:rmd_syn_hl_chunk
- exe 'syn region rmd'.s:nm.'ChunkDelim matchgroup=rmdCodeDelim start="^\s*```\s*{\s*'.s:nm.'\>" matchgroup=rmdCodeDelim end="}$" keepend containedin=rmd'.s:nm.'Chunk contains=@R'
- exe 'syn region rmd'.s:nm.'Chunk start="^\s*```\s*{\s*'.s:nm.'\>.*$" matchgroup=rmdCodeDelim end="^\s*```\ze\s*$" keepend contains=rmd'.s:nm.'ChunkDelim,@'.toupper(s:nm)
+ syn region rmdrInline matchgroup=rmdInlineDelim start="`r " end="`" contains=@Rmdr containedin=pandocLaTeXRegion,yamlFlowString keepend
+else
+ " Step_2: Source markdown.vim if pandoc.vim is not installed
+
+ " Configuration if not using pandoc syntax:
+ " Add syntax highlighting of YAML header
+ let g:rmd_syn_hl_yaml = get(g:, 'rmd_syn_hl_yaml', 1)
+ " Add syntax highlighting of citation keys
+ let g:rmd_syn_hl_citations = get(g:, 'rmd_syn_hl_citations', 1)
+
+ " R chunks will not be highlighted by syntax/markdown because their headers
+ " follow a non standard pattern: "```{lang" instead of "^```lang".
+ " Make a copy of g:markdown_fenced_languages to highlight the chunks later:
+ if exists('g:markdown_fenced_languages') && !exists('g:rmd_fenced_languages')
+ let g:rmd_fenced_languages = deepcopy(g:markdown_fenced_languages)
+ endif
+
+ if exists('g:markdown_fenced_languages') && len(g:markdown_fenced_languages) > 0
+ let s:save_mfl = deepcopy(g:markdown_fenced_languages)
+ endif
+ " Don't waste time loading syntax that will be discarded:
+ let g:markdown_fenced_languages = []
+ runtime syntax/markdown.vim
+ if exists('s:save_mfl') > 0
+ let g:markdown_fenced_languages = deepcopy(s:save_mfl)
+ unlet s:save_mfl
+ endif
+ syn region rmdrInline matchgroup=rmdInlineDelim start="`r " end="`" contains=@Rmdr keepend
+
+ " Step_2a: Add highlighting for both YAML and citations which are pandoc
+ " specific, but also used in Rmd files
+
+ " You don't need this if either your markdown/syntax.vim already highlights
+ " the YAML header or you are writing standard markdown
+ if g:rmd_syn_hl_yaml
+ " Basic highlighting of YAML header
+ syn match rmdYamlFieldTtl /^\s*\zs\w\%(-\|\w\)*\ze:/ contained
+ syn match rmdYamlFieldTtl /^\s*-\s*\zs\w\%(-\|\w\)*\ze:/ contained
+ syn region yamlFlowString matchgroup=yamlFlowStringDelimiter start='"' skip='\\"' end='"' contains=yamlEscape,rmdrInline contained
+ syn region yamlFlowString matchgroup=yamlFlowStringDelimiter start="'" skip="''" end="'" contains=yamlSingleEscape,rmdrInline contained
+ syn match yamlEscape contained '\\\%([\\"abefnrtv\^0_ NLP\n]\|x\x\x\|u\x\{4}\|U\x\{8}\)'
+ syn match yamlSingleEscape contained "''"
+ syn match yamlComment /#.*/ contained
+ " A second colon is a syntax error, unles within a string or following !expr
+ syn match yamlColonError /:\s*[^'^"^!]*:/ contained
+ if &filetype == 'quarto'
+ syn region pandocYAMLHeader matchgroup=rmdYamlBlockDelim start=/\%(\%^\|\_^\s*\n\)\@<=\_^-\{3}\ze\n.\+/ end=/^---$/ keepend contains=rmdYamlFieldTtl,yamlFlowString,yamlComment,yamlColonError
else
- exe 'syn region rmd'.s:nm.'Chunk matchgroup=rmdCodeDelim start="^\s*```\s*{\s*'.s:nm.'\>.*$" matchgroup=rmdCodeDelim end="^\s*```\ze\s*$" keepend contains=@'.toupper(s:nm)
+ syn region pandocYAMLHeader matchgroup=rmdYamlBlockDelim start=/\%(\%^\|\_^\s*\n\)\@<=\_^-\{3}\ze\n.\+/ end=/^\([-.]\)\1\{2}$/ keepend contains=rmdYamlFieldTtl,yamlFlowString,yamlComment,yamlColonError
endif
- endfor
- unlet s:lng
- unlet s:nm
- hi def link rmdInlineDelim Delimiter
- hi def link rmdCodeDelim Delimiter
- let b:current_syntax = "rmd"
- finish
-endif
-
-" Configuration if not using pandoc syntax:
-" Add syntax highlighting of YAML header
-let g:rmd_syn_hl_yaml = get(g:, 'rmd_syn_hl_yaml', 1)
-" Add syntax highlighting of citation keys
-let g:rmd_syn_hl_citations = get(g:, 'rmd_syn_hl_citations', 1)
-
-let s:cpo_save = &cpo
-set cpo&vim
+ hi def link rmdYamlBlockDelim Delimiter
+ hi def link rmdYamlFieldTtl Identifier
+ hi def link yamlFlowString String
+ hi def link yamlComment Comment
+ hi def link yamlColonError Error
+ endif
-" R chunks will not be highlighted by syntax/markdown because their headers
-" follow a non standard pattern: "```{lang" instead of "^```lang".
-" Make a copy of g:markdown_fenced_languages to highlight the chunks later:
-if exists('g:markdown_fenced_languages')
- if !exists('g:rmd_fenced_languages')
- let g:rmd_fenced_languages = deepcopy(g:markdown_fenced_languages)
- let g:markdown_fenced_languages = []
+ " You don't need this if either your markdown/syntax.vim already highlights
+ " citations or you are writing standard markdown
+ if g:rmd_syn_hl_citations
+ " From vim-pandoc-syntax
+ " parenthetical citations
+ syn match pandocPCite /\^\@<!\[[^\[\]]\{-}-\{0,1}@[[:alnum:]_][[:alnum:]à-öø-ÿÀ-ÖØ-ß_:.#$%&\-+?<>~\/]*.\{-}\]/ contains=pandocEmphasis,pandocStrong,pandocLatex,pandocCiteKey,@Spell,pandocAmpersandEscape display
+ " in-text citations with location
+ syn match pandocICite /@[[:alnum:]_][[:alnum:]à-öø-ÿÀ-ÖØ-ß_:.#$%&\-+?<>~\/]*\s\[.\{-1,}\]/ contains=pandocCiteKey,@Spell display
+ " cite keys
+ syn match pandocCiteKey /\(-\=@[[:alnum:]_][[:alnum:]à-öø-ÿÀ-ÖØ-ß_:.#$%&\-+?<>~\/]*\)/ containedin=pandocPCite,pandocICite contains=@NoSpell display
+ syn match pandocCiteAnchor /[-@]/ contained containedin=pandocCiteKey display
+ syn match pandocCiteLocator /[\[\]]/ contained containedin=pandocPCite,pandocICite
+ hi def link pandocPCite Operator
+ hi def link pandocICite Operator
+ hi def link pandocCiteKey Label
+ hi def link pandocCiteAnchor Operator
+ hi def link pandocCiteLocator Operator
endif
-else
- let g:rmd_fenced_languages = ['r']
endif
-runtime syntax/markdown.vim
+" Step_3: Highlight code blocks.
+
+syn region rmdCodeBlock matchgroup=rmdCodeDelim start="^\s*```\s*{.*}$" matchgroup=rmdCodeDelim end="^\s*```\ze\s*$" keepend
+syn region rmdCodeBlock matchgroup=rmdCodeDelim start="^\s*```.+$" matchgroup=rmdCodeDelim end="^```$" keepend
+hi link rmdCodeBlock Special
" Now highlight chunks:
+syn region knitrBodyOptions start='^#| ' end='$' contained containedin=rComment,pythonComment contains=knitrBodyVar,knitrBodyValue transparent
+syn match knitrBodyValue ': \zs.*\ze$' keepend contained containedin=knitrBodyOptions
+syn match knitrBodyVar '| \zs\S\{-}\ze:' contained containedin=knitrBodyOptions
+
+let g:rmd_fenced_languages = get(g:, 'rmd_fenced_languages', ['r'])
for s:type in g:rmd_fenced_languages
if s:type =~ '='
let s:ft = substitute(s:type, '.*=', '', '')
@@ -81,58 +138,40 @@ for s:type in g:rmd_fenced_languages
unlet! b:current_syntax
exe 'syn include @Rmd'.s:nm.' syntax/'.s:ft.'.vim'
if g:rmd_syn_hl_chunk
- exe 'syn region rmd'.s:nm.'ChunkDelim matchgroup=rmdCodeDelim start="^\s*```\s*{\s*'.s:nm.'\>" matchgroup=rmdCodeDelim end="}$" keepend containedin=rmd'.s:nm.'Chunk contains=@Rmdr'
- exe 'syn region rmd'.s:nm.'Chunk start="^\s*```\s*{\s*'.s:nm.'\>.*$" matchgroup=rmdCodeDelim end="^\s*```\ze\s*$" keepend contains=rmd'.s:nm.'ChunkDelim,@Rmd'.s:nm
+ exe 'syn match knitrChunkDelim /```\s*{\s*'.s:nm.'/ contained containedin=knitrChunkBrace contains=knitrChunkLabel'
+ exe 'syn match knitrChunkLabelDelim /```\s*{\s*'.s:nm.',\=\s*[-[:alnum:]]\{-1,}[,}]/ contained containedin=knitrChunkBrace'
+ syn match knitrChunkDelim /}\s*$/ contained containedin=knitrChunkBrace
+ exe 'syn match knitrChunkBrace /```\s*{\s*'.s:nm.'.*$/ contained containedin=rmd'.s:nm.'Chunk contains=knitrChunkDelim,knitrChunkLabelDelim,@Rmd'.s:nm
+ exe 'syn region rmd'.s:nm.'Chunk start="^\s*```\s*{\s*=\?'.s:nm.'\>.*$" matchgroup=rmdCodeDelim end="^\s*```\ze\s*$" keepend contains=knitrChunkBrace,@Rmd'.s:nm
+
+ hi link knitrChunkLabel Identifier
+ hi link knitrChunkDelim rmdCodeDelim
+ hi link knitrChunkLabelDelim rmdCodeDelim
else
- exe 'syn region rmd'.s:nm.'Chunk matchgroup=rmdCodeDelim start="^\s*```\s*{\s*'.s:nm.'\>.*$" matchgroup=rmdCodeDelim end="^\s*```\ze\s*$" keepend contains=@Rmd'.s:nm
+ exe 'syn region rmd'.s:nm.'Chunk matchgroup=rmdCodeDelim start="^\s*```\s*{\s*=\?'.s:nm.'\>.*$" matchgroup=rmdCodeDelim end="^\s*```\ze\s*$" keepend contains=@Rmd'.s:nm
endif
endfor
unlet! s:type
-" Recognize inline R code
-syn region rmdrInline matchgroup=rmdInlineDelim start="`r " end="`" contains=@Rmdr keepend
+" Step_4: Highlight code recognized by pandoc but not defined in pandoc.vim yet:
+syn match pandocDivBegin '^:::\+ {.\{-}}' contains=pandocHeaderAttr
+syn match pandocDivEnd '^:::\+$'
+hi def link knitrBodyVar PreProc
+hi def link knitrBodyValue Constant
+hi def link knitrBodyOptions rComment
+hi def link pandocDivBegin Delimiter
+hi def link pandocDivEnd Delimiter
hi def link rmdInlineDelim Delimiter
hi def link rmdCodeDelim Delimiter
-" You don't need this if either your markdown/syntax.vim already highlights
-" the YAML header or you are writing standard markdown
-if g:rmd_syn_hl_yaml
- " Minimum highlighting of yaml header
- syn match rmdYamlFieldTtl /^\s*\zs\w*\ze:/ contained
- syn match rmdYamlFieldTtl /^\s*-\s*\zs\w*\ze:/ contained
- syn region yamlFlowString matchgroup=yamlFlowStringDelimiter start='"' skip='\\"' end='"' contains=yamlEscape,rmdrInline contained
- syn region yamlFlowString matchgroup=yamlFlowStringDelimiter start="'" skip="''" end="'" contains=yamlSingleEscape,rmdrInline contained
- syn match yamlEscape contained '\\\%([\\"abefnrtv\^0_ NLP\n]\|x\x\x\|u\x\{4}\|U\x\{8}\)'
- syn match yamlSingleEscape contained "''"
- syn region pandocYAMLHeader matchgroup=rmdYamlBlockDelim start=/\%(\%^\|\_^\s*\n\)\@<=\_^-\{3}\ze\n.\+/ end=/^\([-.]\)\1\{2}$/ keepend contains=rmdYamlFieldTtl,yamlFlowString
- hi def link rmdYamlBlockDelim Delimiter
- hi def link rmdYamlFieldTtl Identifier
- hi def link yamlFlowString String
-endif
-
-" You don't need this if either your markdown/syntax.vim already highlights
-" citations or you are writing standard markdown
-if g:rmd_syn_hl_citations
- " From vim-pandoc-syntax
- " parenthetical citations
- syn match pandocPCite /\^\@<!\[[^\[\]]\{-}-\{0,1}@[[:alnum:]_][[:alnum:]à-öø-ÿÀ-ÖØ-ß_:.#$%&\-+?<>~\/]*.\{-}\]/ contains=pandocEmphasis,pandocStrong,pandocLatex,pandocCiteKey,@Spell,pandocAmpersandEscape display
- " in-text citations with location
- syn match pandocICite /@[[:alnum:]_][[:alnum:]à-öø-ÿÀ-ÖØ-ß_:.#$%&\-+?<>~\/]*\s\[.\{-1,}\]/ contains=pandocCiteKey,@Spell display
- " cite keys
- syn match pandocCiteKey /\(-\=@[[:alnum:]_][[:alnum:]à-öø-ÿÀ-ÖØ-ß_:.#$%&\-+?<>~\/]*\)/ containedin=pandocPCite,pandocICite contains=@NoSpell display
- syn match pandocCiteAnchor /[-@]/ contained containedin=pandocCiteKey display
- syn match pandocCiteLocator /[\[\]]/ contained containedin=pandocPCite,pandocICite
- hi def link pandocPCite Operator
- hi def link pandocICite Operator
- hi def link pandocCiteKey Label
- hi def link pandocCiteAnchor Operator
- hi def link pandocCiteLocator Operator
+if len(s:save_pandoc_lngs)
+ let g:pandoc#syntax#codeblocks#embeds#langs = s:save_pandoc_lngs
endif
-
-let b:current_syntax = "rmd"
-
+unlet s:save_pandoc_lngs
let &cpo = s:cpo_save
unlet s:cpo_save
+let b:current_syntax = "rmd"
+
" vim: ts=8 sw=2
diff --git a/runtime/syntax/sh.vim b/runtime/syntax/sh.vim
index 13d74dbc17..f455f19c93 100644
--- a/runtime/syntax/sh.vim
+++ b/runtime/syntax/sh.vim
@@ -2,8 +2,8 @@
" Language: shell (sh) Korn shell (ksh) bash (sh)
" Maintainer: Charles E. Campbell <NcampObell@SdrPchip.AorgM-NOSPAM>
" Previous Maintainer: Lennart Schultz <Lennart.Schultz@ecmwf.int>
-" Last Change: Dec 20, 2022
-" Version: 205
+" Last Change: Feb 11, 2023
+" Version: 207
" URL: http://www.drchip.org/astronaut/vim/index.html#SYNTAX_SH
" For options and settings, please use: :help ft-sh-syntax
" This file includes many ideas from Eric Brunet (eric.brunet@ens.fr) and heredoc fixes from Felipe Contreras
@@ -166,7 +166,7 @@ if exists("b:is_kornshell") || exists("b:is_bash")
syn cluster shLoopoList add=shForPP
endif
syn cluster shPPSLeftList contains=shAlias,shArithmetic,shCmdParenRegion,shCommandSub,shCtrlSeq,shDeref,shDerefSimple,shDoubleQuote,shEcho,shEscape,shExDoubleQuote,shExpr,shExSingleQuote,shHereDoc,shNumber,shOperator,shOption,shPosnParm,shHereString,shRedir,shSingleQuote,shSpecial,shStatement,shSubSh,shTest,shVariable
-syn cluster shPPSRightList contains=shComment,shDeref,shDerefSimple,shEscape,shPosnParm
+syn cluster shPPSRightList contains=shDeref,shDerefSimple,shEscape,shPosnParm
syn cluster shSubShList contains=@shCommandSubList,shCommandSubBQ,shCaseEsac,shColon,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shIf,shHereString,shRedir,shSetList,shSource,shStatement,shVariable,shCtrlSeq,shOperator
syn cluster shTestList contains=shArithmetic,shCharClass,shCommandSub,shCommandSubBQ,shCtrlSeq,shDeref,shDerefSimple,shDoubleQuote,shSpecialDQ,shExDoubleQuote,shExpr,shExSingleQuote,shNumber,shOperator,shSingleQuote,shTest,shTestOpr
syn cluster shNoZSList contains=shSpecialNoZS
@@ -335,7 +335,7 @@ syn match shEscape contained '\%(^\)\@!\%(\\\\\)*\\.' nextgroup=shComment
" systems too, however, so the following syntax will flag $(..) as
" an Error under /bin/sh. By consensus of vimdev'ers!
if exists("b:is_kornshell") || exists("b:is_bash") || exists("b:is_posix")
- syn region shCommandSub matchgroup=shCmdSubRegion start="\$(\ze[^(]\|$" skip='\\\\\|\\.' end=")" contains=@shCommandSubList
+ syn region shCommandSub matchgroup=shCmdSubRegion start="\$(\ze[^(]" skip='\\\\\|\\.' end=")" contains=@shCommandSubList
syn region shArithmetic matchgroup=shArithRegion start="\$((" skip='\\\\\|\\.' end="))" contains=@shArithList
syn region shArithmetic matchgroup=shArithRegion start="\$\[" skip='\\\\\|\\.' end="\]" contains=@shArithList
syn match shSkipInitWS contained "^\s\+"
@@ -503,7 +503,6 @@ endif
" ksh: ${.sh.*} variables: {{{1
" ========================================
if exists("b:is_kornshell")
-" syn match shDerefVar contained "[.]*" nextgroup=@shDerefVarList
syn match shDerefVar contained "\.\+" nextgroup=@shDerefVarList
endif
@@ -548,6 +547,7 @@ syn region shDerefVarArray contained matchgroup=shDeref start="\[" end="]" co
" bash : ${parameter,pattern} Case modification
" bash : ${parameter,,pattern} Case modification
" bash : ${@:start:qty} display command line arguments from start to start+qty-1 (inferred)
+" bash : ${parameter@operator} transforms parameter (operator∈[uULqEPARa])
syn cluster shDerefPatternList contains=shDerefPattern,shDerefString
if !exists("g:sh_no_error")
syn match shDerefOpError contained ":[[:punct:]]"
@@ -563,6 +563,7 @@ if exists("b:is_bash") || exists("b:is_kornshell") || exists("b:is_posix")
endif
if exists("b:is_bash")
syn match shDerefOp contained "[,^]\{1,2}" nextgroup=@shDerefPatternList
+ syn match shDerefOp contained "@[uULQEPAKa]"
endif
syn region shDerefString contained matchgroup=shDerefDelim start=+\%(\\\)\@<!'+ end=+'+ contains=shStringSpecial
syn region shDerefString contained matchgroup=shDerefDelim start=+\%(\\\)\@<!"+ skip=+\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index bbdb66988b..ca3cf76388 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -248,6 +248,9 @@ void nvim__buf_redraw_range(Buffer buffer, Integer first, Integer last, Error *e
if (!buf) {
return;
}
+ if (last < 0) {
+ last = buf->b_ml.ml_line_count;
+ }
redraw_buf_range_later(buf, (linenr_T)first + 1, (linenr_T)last);
}
diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c
index f6dee066dc..a8f5d2e070 100644
--- a/src/nvim/api/ui.c
+++ b/src/nvim/api/ui.c
@@ -113,6 +113,10 @@ void remote_ui_disconnect(uint64_t channel_id)
kv_destroy(data->call_buf);
pmap_del(uint64_t)(&connected_uis, channel_id);
ui_detach_impl(ui, channel_id);
+
+ // Destroy `ui`.
+ XFREE_CLEAR(ui->term_name);
+ XFREE_CLEAR(ui->term_background);
xfree(ui);
}
@@ -163,15 +167,9 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height, Dictiona
UI *ui = xcalloc(1, sizeof(UI));
ui->width = (int)width;
ui->height = (int)height;
- ui->pum_nlines = 0;
- ui->pum_pos = false;
- ui->pum_width = 0.0;
- ui->pum_height = 0.0;
ui->pum_row = -1.0;
ui->pum_col = -1.0;
ui->rgb = true;
- ui->override = false;
-
CLEAR_FIELD(ui->ui_ext);
for (size_t i = 0; i < options.size; i++) {
@@ -320,6 +318,7 @@ static void ui_set_option(UI *ui, bool init, String name, Object value, Error *e
return;
});
set_tty_option("term", string_to_cstr(value.data.string));
+ ui->term_name = string_to_cstr(value.data.string);
return;
}
@@ -328,6 +327,7 @@ static void ui_set_option(UI *ui, bool init, String name, Object value, Error *e
return;
});
t_colors = (int)value.data.integer;
+ ui->term_colors = (int)value.data.integer;
return;
}
@@ -336,6 +336,7 @@ static void ui_set_option(UI *ui, bool init, String name, Object value, Error *e
return;
});
set_tty_background(value.data.string.data);
+ ui->term_background = string_to_cstr(value.data.string);
return;
}
@@ -359,6 +360,7 @@ static void ui_set_option(UI *ui, bool init, String name, Object value, Error *e
return;
});
stdin_isatty = value.data.boolean;
+ ui->stdin_tty = value.data.boolean;
return;
}
@@ -367,6 +369,7 @@ static void ui_set_option(UI *ui, bool init, String name, Object value, Error *e
return;
});
stdout_isatty = value.data.boolean;
+ ui->stdout_tty = value.data.boolean;
return;
}
diff --git a/src/nvim/diff.c b/src/nvim/diff.c
index c5b28822d0..289939b2ca 100644
--- a/src/nvim/diff.c
+++ b/src/nvim/diff.c
@@ -31,6 +31,7 @@
#include "nvim/ex_cmds.h"
#include "nvim/ex_cmds_defs.h"
#include "nvim/ex_docmd.h"
+#include "nvim/extmark.h"
#include "nvim/extmark_defs.h"
#include "nvim/fileio.h"
#include "nvim/fold.h"
@@ -3102,6 +3103,9 @@ static void diffgetput(const int addr_count, const int idx_cur, const int idx_fr
if (buf_empty && (curbuf->b_ml.ml_line_count == 2)) {
// Added the first line into an empty buffer, need to
// delete the dummy empty line.
+ // This has a side effect of incrementing curbuf->deleted_bytes,
+ // which results in inaccurate reporting of the byte count of
+ // previous contents in buffer-update events.
buf_empty = false;
ml_delete((linenr_T)2, false);
}
@@ -3143,6 +3147,7 @@ static void diffgetput(const int addr_count, const int idx_cur, const int idx_fr
}
}
}
+ extmark_adjust(curbuf, lnum, lnum + count - 1, (long)MAXLNUM, added, kExtmarkUndo);
changed_lines(lnum, 0, lnum + count, added, true);
if (did_free) {
diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c
index cd815da458..bf8649afe0 100644
--- a/src/nvim/drawline.c
+++ b/src/nvim/drawline.c
@@ -1199,7 +1199,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
statuscol.draw = true;
statuscol.sattrs = sattrs;
statuscol.foldinfo = foldinfo;
- statuscol.width = win_col_off(wp);
+ statuscol.width = win_col_off(wp) - (cmdwin_type != 0 && wp == curwin);
statuscol.use_cul = use_cursor_line_sign(wp, lnum);
statuscol.sign_cul_attr = statuscol.use_cul ? sign_cul_attr : 0;
statuscol.num_attr = sign_num_attr ? sign_num_attr
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 841588d4c3..0fbf31a8cd 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -1498,21 +1498,14 @@ char *get_lval(char *const name, typval_T *const rettv, lval_T *const lp, const
tv_clear(&var1);
const int bloblen = tv_blob_len(lp->ll_tv->vval.v_blob);
- if (lp->ll_n1 < 0 || lp->ll_n1 > bloblen
- || (lp->ll_range && lp->ll_n1 == bloblen)) {
- if (!quiet) {
- semsg(_(e_blobidx), (int64_t)lp->ll_n1);
- }
+ if (tv_blob_check_index(bloblen, lp->ll_n1, quiet) == FAIL) {
tv_clear(&var2);
return NULL;
}
if (lp->ll_range && !lp->ll_empty2) {
lp->ll_n2 = (long)tv_get_number(&var2);
tv_clear(&var2);
- if (lp->ll_n2 < 0 || lp->ll_n2 >= bloblen || lp->ll_n2 < lp->ll_n1) {
- if (!quiet) {
- semsg(_(e_blobidx), (int64_t)lp->ll_n2);
- }
+ if (tv_blob_check_range(bloblen, lp->ll_n1, lp->ll_n2, quiet) == FAIL) {
return NULL;
}
}
@@ -1620,33 +1613,14 @@ void set_var_lval(lval_T *lp, char *endp, typval_T *rettv, int copy, const bool
lp->ll_n2 = tv_blob_len(lp->ll_blob) - 1;
}
- if (lp->ll_n2 - lp->ll_n1 + 1 != tv_blob_len(rettv->vval.v_blob)) {
- emsg(_("E972: Blob value does not have the right number of bytes"));
+ if (tv_blob_set_range(lp->ll_blob, (int)lp->ll_n1, (int)lp->ll_n2, rettv) == FAIL) {
return;
}
- if (lp->ll_empty2) {
- lp->ll_n2 = tv_blob_len(lp->ll_blob);
- }
-
- for (int il = (int)lp->ll_n1, ir = 0; il <= (int)lp->ll_n2; il++) {
- tv_blob_set(lp->ll_blob, il, tv_blob_get(rettv->vval.v_blob, ir++));
- }
} else {
bool error = false;
const char val = (char)tv_get_number_chk(rettv, &error);
if (!error) {
- garray_T *const gap = &lp->ll_blob->bv_ga;
-
- // Allow for appending a byte. Setting a byte beyond
- // the end is an error otherwise.
- if (lp->ll_n1 < gap->ga_len || lp->ll_n1 == gap->ga_len) {
- ga_grow(&lp->ll_blob->bv_ga, 1);
- tv_blob_set(lp->ll_blob, (int)lp->ll_n1, (uint8_t)val);
- if (lp->ll_n1 == gap->ga_len) {
- gap->ga_len++;
- }
- }
- // error for invalid range was already given in get_lval()
+ tv_blob_set_append(lp->ll_blob, (int)lp->ll_n1, (uint8_t)val);
}
}
} else if (op != NULL && *op != '=') {
@@ -2571,6 +2545,39 @@ static int eval4(char **arg, typval_T *rettv, int evaluate)
return OK;
}
+/// Make a copy of blob "tv1" and append blob "tv2".
+static void eval_addblob(typval_T *tv1, typval_T *tv2)
+{
+ const blob_T *const b1 = tv1->vval.v_blob;
+ const blob_T *const b2 = tv2->vval.v_blob;
+ blob_T *const b = tv_blob_alloc();
+
+ for (int i = 0; i < tv_blob_len(b1); i++) {
+ ga_append(&b->bv_ga, tv_blob_get(b1, i));
+ }
+ for (int i = 0; i < tv_blob_len(b2); i++) {
+ ga_append(&b->bv_ga, tv_blob_get(b2, i));
+ }
+
+ tv_clear(tv1);
+ tv_blob_set_ret(tv1, b);
+}
+
+/// Make a copy of list "tv1" and append list "tv2".
+static int eval_addlist(typval_T *tv1, typval_T *tv2)
+{
+ typval_T var3;
+ // Concatenate Lists.
+ if (tv_list_concat(tv1->vval.v_list, tv2->vval.v_list, &var3) == FAIL) {
+ tv_clear(tv1);
+ tv_clear(tv2);
+ return FAIL;
+ }
+ tv_clear(tv1);
+ *tv1 = var3;
+ return OK;
+}
+
/// Handle fourth level expression:
/// + number addition, concatenation of list or blob
/// - number subtraction
@@ -2584,7 +2591,6 @@ static int eval4(char **arg, typval_T *rettv, int evaluate)
static int eval5(char **arg, typval_T *rettv, int evaluate)
{
typval_T var2;
- typval_T var3;
varnumber_T n1, n2;
float_T f1 = 0, f2 = 0;
char *p;
@@ -2602,7 +2608,7 @@ static int eval5(char **arg, typval_T *rettv, int evaluate)
}
if ((op != '+' || (rettv->v_type != VAR_LIST && rettv->v_type != VAR_BLOB))
- && (op == '.' || rettv->v_type != VAR_FLOAT)) {
+ && (op == '.' || rettv->v_type != VAR_FLOAT) && evaluate) {
// For "list + ...", an illegal use of the first operand as
// a number cannot be determined before evaluating the 2nd
// operand: if this is also a list, all is ok.
@@ -2610,7 +2616,7 @@ static int eval5(char **arg, typval_T *rettv, int evaluate)
// we know that the first operand needs to be a string or number
// without evaluating the 2nd operand. So check before to avoid
// side effects after an error.
- if (evaluate && !tv_check_str(rettv)) {
+ if ((op == '.' && !tv_check_str(rettv)) || (op != '.' && !tv_check_num(rettv))) {
tv_clear(rettv);
return FAIL;
}
@@ -2643,32 +2649,12 @@ static int eval5(char **arg, typval_T *rettv, int evaluate)
tv_clear(rettv);
rettv->v_type = VAR_STRING;
rettv->vval.v_string = p;
- } else if (op == '+' && rettv->v_type == VAR_BLOB
- && var2.v_type == VAR_BLOB) {
- const blob_T *const b1 = rettv->vval.v_blob;
- const blob_T *const b2 = var2.vval.v_blob;
- blob_T *const b = tv_blob_alloc();
-
- for (int i = 0; i < tv_blob_len(b1); i++) {
- ga_append(&b->bv_ga, tv_blob_get(b1, i));
- }
- for (int i = 0; i < tv_blob_len(b2); i++) {
- ga_append(&b->bv_ga, tv_blob_get(b2, i));
- }
-
- tv_clear(rettv);
- tv_blob_set_ret(rettv, b);
- } else if (op == '+' && rettv->v_type == VAR_LIST
- && var2.v_type == VAR_LIST) {
- // Concatenate Lists.
- if (tv_list_concat(rettv->vval.v_list, var2.vval.v_list, &var3)
- == FAIL) {
- tv_clear(rettv);
- tv_clear(&var2);
+ } else if (op == '+' && rettv->v_type == VAR_BLOB && var2.v_type == VAR_BLOB) {
+ eval_addblob(rettv, &var2);
+ } else if (op == '+' && rettv->v_type == VAR_LIST && var2.v_type == VAR_LIST) {
+ if (eval_addlist(rettv, &var2) == FAIL) {
return FAIL;
}
- tv_clear(rettv);
- *rettv = var3;
} else {
bool error = false;
@@ -4864,7 +4850,7 @@ void filter_map(typval_T *argvars, typval_T *rettv, int map)
if (filter_map_one(&tv, expr, map, &rem) == FAIL || did_emsg) {
break;
}
- if (tv.v_type != VAR_NUMBER) {
+ if (tv.v_type != VAR_NUMBER && tv.v_type != VAR_BOOL) {
emsg(_(e_invalblob));
return;
}
@@ -4952,6 +4938,8 @@ theend:
return retval;
}
+/// "function()" function
+/// "funcref()" function
void common_function(typval_T *argvars, typval_T *rettv, bool is_funcref)
{
char *s;
@@ -5873,27 +5861,63 @@ write_blob_error:
return false;
}
-/// Read a blob from a file `fd`.
+/// Read blob from file "fd".
+/// Caller has allocated a blob in "rettv".
///
/// @param[in] fd File to read from.
-/// @param[in,out] blob Blob to write to.
+/// @param[in,out] rettv Blob to write to.
+/// @param[in] offset Read the file from the specified offset.
+/// @param[in] size Read the specified size, or -1 if no limit.
///
-/// @return true on success, or false on failure.
-bool read_blob(FILE *const fd, blob_T *const blob)
+/// @return OK on success, or FAIL on failure.
+int read_blob(FILE *const fd, typval_T *rettv, off_T offset, off_T size_arg)
FUNC_ATTR_NONNULL_ALL
{
+ blob_T *const blob = rettv->vval.v_blob;
FileInfo file_info;
if (!os_fileinfo_fd(fileno(fd), &file_info)) {
- return false;
+ return FAIL; // can't read the file, error
+ }
+
+ int whence;
+ off_T size = size_arg;
+ const off_T file_size = (off_T)os_fileinfo_size(&file_info);
+ if (offset >= 0) {
+ // The size defaults to the whole file. If a size is given it is
+ // limited to not go past the end of the file.
+ if (size == -1 || (size > file_size - offset && !S_ISCHR(file_info.stat.st_mode))) {
+ // size may become negative, checked below
+ size = (off_T)os_fileinfo_size(&file_info) - offset;
+ }
+ whence = SEEK_SET;
+ } else {
+ // limit the offset to not go before the start of the file
+ if (-offset > file_size && !S_ISCHR(file_info.stat.st_mode)) {
+ offset = -file_size;
+ }
+ // Size defaults to reading until the end of the file.
+ if (size == -1 || size > -offset) {
+ size = -offset;
+ }
+ whence = SEEK_END;
+ }
+ if (size <= 0) {
+ return OK;
+ }
+ if (offset != 0 && vim_fseek(fd, offset, whence) != 0) {
+ return OK;
}
- const int size = (int)os_fileinfo_size(&file_info);
- ga_grow(&blob->bv_ga, size);
- blob->bv_ga.ga_len = size;
+
+ ga_grow(&blob->bv_ga, (int)size);
+ blob->bv_ga.ga_len = (int)size;
if (fread(blob->bv_ga.ga_data, 1, (size_t)blob->bv_ga.ga_len, fd)
< (size_t)blob->bv_ga.ga_len) {
- return false;
+ // An empty blob is returned on error.
+ tv_blob_free(rettv->vval.v_blob);
+ rettv->vval.v_blob = NULL;
+ return FAIL;
}
- return true;
+ return OK;
}
/// Saves a typval_T as a string.
diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua
index a476e20339..ae10a7e035 100644
--- a/src/nvim/eval.lua
+++ b/src/nvim/eval.lua
@@ -49,6 +49,7 @@ return {
assert_true={args={1, 2}, base=1},
atan={args=1, base=1, float_func="atan"},
atan2={args=2, base=1},
+ blob2list={args=1, base=1},
browse={args=4},
browsedir={args=2},
bufadd={args=1, base=1},
@@ -249,6 +250,7 @@ return {
line={args={1, 2}, base=1},
line2byte={args=1, base=1},
lispindent={args=1, base=1},
+ list2blob={args=1, base=1},
list2str={args={1, 2}, base=1},
localtime={},
log={args=1, base=1, float_func="log"},
@@ -296,7 +298,7 @@ return {
perleval={args=1, base=1},
rand={args={0, 1}, base=1},
range={args={1, 3}, base=1},
- readblob={args=1, base=1},
+ readblob={args={1, 3}, base=1},
readdir={args={1, 2}, base=1},
readfile={args={1, 3}, base=1},
reduce={args={2, 3}, base=1},
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
index 1baf96e281..4208c5ca46 100644
--- a/src/nvim/eval/funcs.c
+++ b/src/nvim/eval/funcs.c
@@ -3228,7 +3228,9 @@ static void f_has(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
}
if (!n) {
- if (STRNICMP(name, "patch", 5) == 0) {
+ if (STRNICMP(name, "gui_running", 11) == 0) {
+ n = ui_gui_attached();
+ } else if (STRNICMP(name, "patch", 5) == 0) {
if (name[5] == '-'
&& strlen(name) >= 11
&& ascii_isdigit(name[6])
@@ -3743,7 +3745,6 @@ static void f_inputsecret(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
/// "insert()" function
static void f_insert(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
{
- list_T *l;
bool error = false;
if (argvars[0].v_type == VAR_BLOB) {
@@ -3786,8 +3787,12 @@ static void f_insert(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
tv_copy(&argvars[0], rettv);
} else if (argvars[0].v_type != VAR_LIST) {
semsg(_(e_listblobarg), "insert()");
- } else if (!value_check_lock(tv_list_locked((l = argvars[0].vval.v_list)),
- N_("insert() argument"), TV_TRANSLATE)) {
+ } else {
+ list_T *l = argvars[0].vval.v_list;
+ if (value_check_lock(tv_list_locked(l), N_("insert() argument"), TV_TRANSLATE)) {
+ return;
+ }
+
int64_t before = 0;
if (argvars[2].v_type != VAR_UNKNOWN) {
before = tv_get_number_chk(&argvars[2], &error);
@@ -5587,15 +5592,24 @@ static void read_file_or_blob(typval_T *argvars, typval_T *rettv, bool always_bl
ptrdiff_t prevlen = 0; // length of data in prev
ptrdiff_t prevsize = 0; // size of prev buffer
int64_t maxline = MAXLNUM;
+ off_T offset = 0;
+ off_T size = -1;
if (argvars[1].v_type != VAR_UNKNOWN) {
- if (strcmp(tv_get_string(&argvars[1]), "b") == 0) {
- binary = true;
- } else if (strcmp(tv_get_string(&argvars[1]), "B") == 0) {
- blob = true;
- }
- if (argvars[2].v_type != VAR_UNKNOWN) {
- maxline = tv_get_number(&argvars[2]);
+ if (always_blob) {
+ offset = (off_T)tv_get_number(&argvars[1]);
+ if (argvars[2].v_type != VAR_UNKNOWN) {
+ size = (off_T)tv_get_number(&argvars[2]);
+ }
+ } else {
+ if (strcmp(tv_get_string(&argvars[1]), "b") == 0) {
+ binary = true;
+ } else if (strcmp(tv_get_string(&argvars[1]), "B") == 0) {
+ blob = true;
+ }
+ if (argvars[2].v_type != VAR_UNKNOWN) {
+ maxline = tv_get_number(&argvars[2]);
+ }
}
}
@@ -5614,11 +5628,8 @@ static void read_file_or_blob(typval_T *argvars, typval_T *rettv, bool always_bl
if (blob) {
tv_blob_alloc_ret(rettv);
- if (!read_blob(fd, rettv->vval.v_blob)) {
+ if (read_blob(fd, rettv, offset, size) == FAIL) {
semsg(_(e_notread), fname);
- // An empty blob is returned on error.
- tv_blob_free(rettv->vval.v_blob);
- rettv->vval.v_blob = NULL;
}
fclose(fd);
return;
@@ -5965,6 +5976,37 @@ static void f_repeat(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
while (n-- > 0) {
tv_list_extend(rettv->vval.v_list, argvars[0].vval.v_list, NULL);
}
+ } else if (argvars[0].v_type == VAR_BLOB) {
+ tv_blob_alloc_ret(rettv);
+ if (argvars[0].vval.v_blob == NULL || n <= 0) {
+ return;
+ }
+
+ const int slen = argvars[0].vval.v_blob->bv_ga.ga_len;
+ const int len = (int)(slen * n);
+ if (len <= 0) {
+ return;
+ }
+
+ ga_grow(&rettv->vval.v_blob->bv_ga, len);
+
+ rettv->vval.v_blob->bv_ga.ga_len = len;
+
+ int i;
+ for (i = 0; i < slen; i++) {
+ if (tv_blob_get(argvars[0].vval.v_blob, i) != 0) {
+ break;
+ }
+ }
+
+ if (i == slen) {
+ // No need to copy since all bytes are already zero
+ return;
+ }
+
+ for (i = 0; i < n; i++) {
+ tv_blob_set_range(rettv->vval.v_blob, i * slen, (i + 1) * slen - 1, argvars);
+ }
} else {
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c
index 0a30cdb62e..7d49049b0c 100644
--- a/src/nvim/eval/typval.c
+++ b/src/nvim/eval/typval.c
@@ -48,10 +48,16 @@ static char e_dict_required_for_argument_nr[]
= N_("E1206: Dictionary required for argument %d");
static char e_number_required_for_argument_nr[]
= N_("E1210: Number required for argument %d");
+static char e_list_required_for_argument_nr[]
+ = N_("E1211: List required for argument %d");
static char e_string_or_list_required_for_argument_nr[]
= N_("E1222: String or List required for argument %d");
static char e_list_or_blob_required_for_argument_nr[]
= N_("E1226: List or Blob required for argument %d");
+static char e_blob_required_for_argument_nr[]
+ = N_("E1238: Blob required for argument %d");
+static char e_invalid_value_for_blob_nr[]
+ = N_("E1239: Invalid value for blob: %d");
static char e_string_or_function_required_for_argument_nr[]
= N_("E1256: String or function required for argument %d");
@@ -2710,6 +2716,63 @@ bool tv_blob_equal(const blob_T *const b1, const blob_T *const b2)
return true;
}
+/// Check if "n1" is a valid index for a blob with length "bloblen".
+int tv_blob_check_index(int bloblen, varnumber_T n1, bool quiet)
+{
+ if (n1 < 0 || n1 > bloblen) {
+ if (!quiet) {
+ semsg(_(e_blobidx), n1);
+ }
+ return FAIL;
+ }
+ return OK;
+}
+
+/// Check if "n1"-"n2" is a valid range for a blob with length "bloblen".
+int tv_blob_check_range(int bloblen, varnumber_T n1, varnumber_T n2, bool quiet)
+{
+ if (n2 < 0 || n2 >= bloblen || n2 < n1) {
+ if (!quiet) {
+ semsg(_(e_blobidx), n2);
+ }
+ return FAIL;
+ }
+ return OK;
+}
+
+/// Set bytes "n1" to "n2" (inclusive) in "dest" to the value of "src".
+/// Caller must make sure "src" is a blob.
+/// Returns FAIL if the number of bytes does not match.
+int tv_blob_set_range(blob_T *dest, int n1, int n2, typval_T *src)
+{
+ if (n2 - n1 + 1 != tv_blob_len(src->vval.v_blob)) {
+ emsg(_("E972: Blob value does not have the right number of bytes"));
+ return FAIL;
+ }
+
+ for (int il = n1, ir = 0; il <= n2; il++) {
+ tv_blob_set(dest, il, tv_blob_get(src->vval.v_blob, ir++));
+ }
+ return OK;
+}
+
+/// Store one byte "byte" in blob "blob" at "idx".
+/// Append one byte if needed.
+void tv_blob_set_append(blob_T *blob, int idx, uint8_t byte)
+{
+ garray_T *gap = &blob->bv_ga;
+
+ // Allow for appending a byte. Setting a byte beyond
+ // the end is an error otherwise.
+ if (idx <= gap->ga_len) {
+ if (idx == gap->ga_len) {
+ ga_grow(gap, 1);
+ gap->ga_len++;
+ }
+ tv_blob_set(blob, idx, byte);
+ }
+}
+
/// "remove({blob})" function
void tv_blob_remove(typval_T *argvars, typval_T *rettv, const char *arg_errmsg)
{
@@ -2769,6 +2832,51 @@ void tv_blob_remove(typval_T *argvars, typval_T *rettv, const char *arg_errmsg)
}
}
+/// blob2list() function
+void f_blob2list(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
+{
+ tv_list_alloc_ret(rettv, kListLenMayKnow);
+
+ if (tv_check_for_blob_arg(argvars, 0) == FAIL) {
+ return;
+ }
+
+ blob_T *const blob = argvars->vval.v_blob;
+ list_T *const l = rettv->vval.v_list;
+ for (int i = 0; i < tv_blob_len(blob); i++) {
+ tv_list_append_number(l, tv_blob_get(blob, i));
+ }
+}
+
+/// list2blob() function
+void f_list2blob(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
+{
+ tv_blob_alloc_ret(rettv);
+ blob_T *const blob = rettv->vval.v_blob;
+
+ if (tv_check_for_list_arg(argvars, 0) == FAIL) {
+ return;
+ }
+
+ list_T *const l = argvars->vval.v_list;
+ if (l == NULL) {
+ return;
+ }
+
+ TV_LIST_ITER_CONST(l, li, {
+ bool error = false;
+ varnumber_T n = tv_get_number_chk(TV_LIST_ITEM_TV(li), &error);
+ if (error || n < 0 || n > 255) {
+ if (!error) {
+ semsg(_(e_invalid_value_for_blob_nr), n);
+ }
+ ga_clear(&blob->bv_ga);
+ return;
+ }
+ ga_append(&blob->bv_ga, (uint8_t)n);
+ });
+}
+
//{{{1 Generic typval operations
//{{{2 Init/alloc/clear
//{{{3 Alloc
@@ -3911,6 +4019,28 @@ int tv_check_for_opt_number_arg(const typval_T *const args, const int idx)
|| tv_check_for_number_arg(args, idx) != FAIL) ? OK : FAIL;
}
+/// Give an error and return FAIL unless "args[idx]" is a blob.
+int tv_check_for_blob_arg(const typval_T *const args, const int idx)
+ FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE
+{
+ if (args[idx].v_type != VAR_BLOB) {
+ semsg(_(e_blob_required_for_argument_nr), idx + 1);
+ return FAIL;
+ }
+ return OK;
+}
+
+/// Give an error and return FAIL unless "args[idx]" is a list.
+int tv_check_for_list_arg(const typval_T *const args, const int idx)
+ FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE
+{
+ if (args[idx].v_type != VAR_LIST) {
+ semsg(_(e_list_required_for_argument_nr), idx + 1);
+ return FAIL;
+ }
+ return OK;
+}
+
/// Give an error and return FAIL unless "args[idx]" is a dict.
int tv_check_for_dict_arg(const typval_T *const args, const int idx)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE
diff --git a/src/nvim/eval/typval.h b/src/nvim/eval/typval.h
index 3f59cd3547..4a2654f03e 100644
--- a/src/nvim/eval/typval.h
+++ b/src/nvim/eval/typval.h
@@ -372,7 +372,7 @@ static inline uint8_t tv_blob_get(const blob_T *const b, int idx)
return ((uint8_t *)b->bv_ga.ga_data)[idx];
}
-static inline void tv_blob_set(blob_T *b, int idx, uint8_t c)
+static inline void tv_blob_set(blob_T *blob, int idx, uint8_t c)
REAL_FATTR_ALWAYS_INLINE REAL_FATTR_NONNULL_ALL;
/// Store the byte `c` at index `idx` in the blob.
@@ -380,9 +380,9 @@ static inline void tv_blob_set(blob_T *b, int idx, uint8_t c)
/// @param[in] b Blob to index. Cannot be NULL.
/// @param[in] idx Index in a blob. Must be valid.
/// @param[in] c Value to store.
-static inline void tv_blob_set(blob_T *const b, int idx, uint8_t c)
+static inline void tv_blob_set(blob_T *const blob, int idx, uint8_t c)
{
- ((uint8_t *)b->bv_ga.ga_data)[idx] = c;
+ ((uint8_t *)blob->bv_ga.ga_data)[idx] = c;
}
/// Initialize VimL object
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index 376352a13b..4b56dfdd3f 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -2445,7 +2445,7 @@ static bool cmdpreview_may_show(CommandLineState *s)
CpInfo cpinfo;
bool icm_split = *p_icm == 's'; // inccommand=split
buf_T *cmdpreview_buf;
- win_T *cmdpreview_win;
+ win_T *cmdpreview_win = NULL;
emsg_silent++; // Block error reporting as the command may be incomplete,
// but still update v:errmsg
@@ -2682,7 +2682,7 @@ char *getcmdline_prompt(const int firstc, const char *const prompt, const int at
/// Read the 'wildmode' option, fill wim_flags[].
int check_opt_wim(void)
{
- char_u new_wim_flags[4];
+ uint8_t new_wim_flags[4];
int i;
int idx = 0;
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c
index 37840f8875..183fd5e19f 100644
--- a/src/nvim/getchar.c
+++ b/src/nvim/getchar.c
@@ -125,8 +125,8 @@ static int KeyNoremap = 0; // remapping flags
// middle for typeahead and room for new characters (which needs to be 3 *
// MAXMAPLEN for the Amiga).
#define TYPELEN_INIT (5 * (MAXMAPLEN + 3))
-static char_u typebuf_init[TYPELEN_INIT]; // initial typebuf.tb_buf
-static char_u noremapbuf_init[TYPELEN_INIT]; // initial typebuf.tb_noremap
+static uint8_t typebuf_init[TYPELEN_INIT]; // initial typebuf.tb_buf
+static uint8_t noremapbuf_init[TYPELEN_INIT]; // initial typebuf.tb_noremap
static size_t last_recorded_len = 0; // number of last recorded chars
@@ -337,14 +337,12 @@ static int read_readbuffers(int advance)
static int read_readbuf(buffheader_T *buf, int advance)
{
- char_u c;
-
if (buf->bh_first.b_next == NULL) { // buffer is empty
return NUL;
}
buffblock_T *const curr = buf->bh_first.b_next;
- c = (char_u)curr->b_str[buf->bh_index];
+ uint8_t c = (uint8_t)curr->b_str[buf->bh_index];
if (advance) {
if (curr->b_str[++buf->bh_index] == NUL) {
@@ -657,17 +655,17 @@ void stuffescaped(const char *arg, bool literally)
static int read_redo(bool init, bool old_redo)
{
static buffblock_T *bp;
- static char_u *p;
+ static uint8_t *p;
int c;
int n;
- char_u buf[MB_MAXBYTES + 1];
+ uint8_t buf[MB_MAXBYTES + 1];
if (init) {
bp = old_redo ? old_redobuff.bh_first.b_next : redobuff.bh_first.b_next;
if (bp == NULL) {
return FAIL;
}
- p = (char_u *)bp->b_str;
+ p = (uint8_t *)bp->b_str;
return OK;
}
if ((c = *p) == NUL) {
@@ -688,9 +686,9 @@ static int read_redo(bool init, bool old_redo)
}
if (*++p == NUL && bp->b_next != NULL) {
bp = bp->b_next;
- p = (char_u *)bp->b_str;
+ p = (uint8_t *)bp->b_str;
}
- buf[i] = (char_u)c;
+ buf[i] = (uint8_t)c;
if (i == n - 1) { // last byte of a character
if (n != 1) {
c = utf_ptr2char((char *)buf);
@@ -854,7 +852,7 @@ bool noremap_keys(void)
// return FAIL for failure, OK otherwise
int ins_typebuf(char *str, int noremap, int offset, bool nottyped, bool silent)
{
- char_u *s1, *s2;
+ uint8_t *s1, *s2;
int addlen;
int val;
int nrm;
@@ -975,11 +973,11 @@ int ins_typebuf(char *str, int noremap, int offset, bool nottyped, bool silent)
/// @return the length of what was inserted
int ins_char_typebuf(int c, int modifiers)
{
- char_u buf[MB_MAXBYTES * 3 + 4];
- unsigned int len = special_to_buf(c, modifiers, true, (char *)buf);
+ char buf[MB_MAXBYTES * 3 + 4];
+ unsigned int len = special_to_buf(c, modifiers, true, buf);
assert(len < sizeof(buf));
buf[len] = NUL;
- (void)ins_typebuf((char *)buf, KeyNoremap, 0, !KeyTyped, cmd_silent);
+ (void)ins_typebuf(buf, KeyNoremap, 0, !KeyTyped, cmd_silent);
return (int)len;
}
@@ -1081,11 +1079,11 @@ void del_typebuf(int len, int offset)
// Write typed characters to script file.
// If recording is on put the character in the recordbuffer.
-static void gotchars(const char_u *chars, size_t len)
+static void gotchars(const uint8_t *chars, size_t len)
FUNC_ATTR_NONNULL_ALL
{
- const char_u *s = chars;
- static char_u buf[4] = { 0 };
+ const uint8_t *s = chars;
+ static uint8_t buf[4] = { 0 };
static size_t buflen = 0;
size_t todo = len;
@@ -1404,7 +1402,7 @@ int merge_modifiers(int c_arg, int *modifiers)
int vgetc(void)
{
int c;
- char_u buf[MB_MAXBYTES + 1];
+ uint8_t buf[MB_MAXBYTES + 1];
// Do garbage collection when garbagecollect() was called previously and
// we are now at the toplevel.
@@ -1548,9 +1546,9 @@ int vgetc(void)
// Note: This will loop until enough bytes are received!
if ((n = MB_BYTE2LEN_CHECK(c)) > 1) {
no_mapping++;
- buf[0] = (char_u)c;
+ buf[0] = (uint8_t)c;
for (int i = 1; i < n; i++) {
- buf[i] = (char_u)vgetorpeek(true);
+ buf[i] = (uint8_t)vgetorpeek(true);
if (buf[i] == K_SPECIAL) {
// Must be a K_SPECIAL - KS_SPECIAL - KE_FILLER sequence,
// which represents a K_SPECIAL (0x80).
@@ -1815,7 +1813,7 @@ typedef enum {
/// Put "string[new_slen]" in typebuf.
/// Remove "slen" bytes.
/// @return FAIL for error, OK otherwise.
-static int put_string_in_typebuf(int offset, int slen, char_u *string, int new_slen)
+static int put_string_in_typebuf(int offset, int slen, uint8_t *string, int new_slen)
{
int extra = new_slen - slen;
string[new_slen] = NUL;
@@ -1838,7 +1836,7 @@ static int put_string_in_typebuf(int offset, int slen, char_u *string, int new_s
/// in Insert mode completion. This includes the form with a CTRL modifier.
static bool at_ins_compl_key(void)
{
- char_u *p = typebuf.tb_buf + typebuf.tb_off;
+ uint8_t *p = typebuf.tb_buf + typebuf.tb_off;
int c = *p;
if (typebuf.tb_len > 3 && c == K_SPECIAL && p[1] == KS_MODIFIER && (p[2] & MOD_MASK_CTRL)) {
@@ -1858,7 +1856,7 @@ static int check_simplify_modifier(int max_offset)
if (offset + 3 >= typebuf.tb_len) {
break;
}
- char_u *tp = typebuf.tb_buf + typebuf.tb_off + offset;
+ uint8_t *tp = typebuf.tb_buf + typebuf.tb_off + offset;
if (tp[0] == K_SPECIAL && tp[1] == KS_MODIFIER) {
// A modifier was not used for a mapping, apply it to ASCII
// keys. Shift would already have been applied.
@@ -1874,12 +1872,12 @@ static int check_simplify_modifier(int max_offset)
vgetc_char = c;
vgetc_mod_mask = tp[2];
}
- char_u new_string[MB_MAXBYTES];
+ uint8_t new_string[MB_MAXBYTES];
int len;
if (IS_SPECIAL(new_c)) {
new_string[0] = K_SPECIAL;
- new_string[1] = (char_u)K_SECOND(new_c);
- new_string[2] = (char_u)K_THIRD(new_c);
+ new_string[1] = (uint8_t)K_SECOND(new_c);
+ new_string[2] = (uint8_t)K_THIRD(new_c);
len = 3;
} else {
len = utf_char2bytes(new_c, (char *)new_string);
@@ -1889,7 +1887,7 @@ static int check_simplify_modifier(int max_offset)
return -1;
}
} else {
- tp[2] = (char_u)modifier;
+ tp[2] = (uint8_t)modifier;
if (put_string_in_typebuf(offset + 3, 1, new_string, len) == FAIL) {
return -1;
}
@@ -2010,10 +2008,10 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth)
// Don't allow mapping the first byte(s) of a multi-byte char.
// Happens when mapping <M-a> and then changing 'encoding'.
// Beware that 0x80 is escaped.
- char_u *p1 = (char_u *)mp->m_keys;
- char_u *p2 = (char_u *)mb_unescape((const char **)&p1);
+ char *p1 = mp->m_keys;
+ char *p2 = (char *)mb_unescape((const char **)&p1);
- if (p2 != NULL && MB_BYTE2LEN(tb_c1) > utfc_ptr2len((char *)p2)) {
+ if (p2 != NULL && MB_BYTE2LEN(tb_c1) > utfc_ptr2len(p2)) {
mlen = 0;
}
@@ -2077,7 +2075,7 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth)
// Check for match with 'pastetoggle'
if (*p_pt != NUL && mp == NULL && (State & (MODE_INSERT | MODE_NORMAL))) {
- bool match = typebuf_match_len((char_u *)p_pt, &mlen);
+ bool match = typebuf_match_len((uint8_t *)p_pt, &mlen);
if (match) {
// write chars to script file(s)
if (mlen > typebuf.tb_maplen) {
@@ -2267,7 +2265,7 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth)
// If this is a LANGMAP mapping, then we didn't record the keys
// at the start of the function and have to record them now.
if (keylen > typebuf.tb_maplen && (mp->m_mode & MODE_LANGMAP) != 0) {
- gotchars((char_u *)map_str, strlen(map_str));
+ gotchars((uint8_t *)map_str, strlen(map_str));
}
if (save_m_noremap != REMAP_YES) {
@@ -2442,7 +2440,7 @@ static int vgetorpeek(bool advance)
if (advance) {
// Also record this character, it might be needed to
// get out of Insert mode.
- *typebuf.tb_buf = (char_u)c;
+ *typebuf.tb_buf = (uint8_t)c;
gotchars(typebuf.tb_buf, 1);
}
cmd_silent = false;
@@ -2515,7 +2513,7 @@ static int vgetorpeek(bool advance)
// move cursor left, if possible
if (curwin->w_cursor.col != 0) {
colnr_T col = 0;
- char_u *ptr;
+ char *ptr;
if (curwin->w_wcol > 0) {
// After auto-indenting and no text is following,
// we are expecting to truncate the trailing
@@ -2524,11 +2522,10 @@ static int vgetorpeek(bool advance)
if (did_ai
&& *skipwhite(get_cursor_line_ptr() + curwin->w_cursor.col) == NUL) {
curwin->w_wcol = 0;
- ptr = (char_u *)get_cursor_line_ptr();
+ ptr = get_cursor_line_ptr();
chartabsize_T cts;
- init_chartabsize_arg(&cts, curwin,
- curwin->w_cursor.lnum, 0, (char *)ptr, (char *)ptr);
- while ((char_u *)cts.cts_ptr < ptr + curwin->w_cursor.col) {
+ init_chartabsize_arg(&cts, curwin, curwin->w_cursor.lnum, 0, ptr, ptr);
+ while (cts.cts_ptr < ptr + curwin->w_cursor.col) {
if (!ascii_iswhite(*cts.cts_ptr)) {
curwin->w_wcol = cts.cts_vcol;
}
@@ -2554,9 +2551,9 @@ static int vgetorpeek(bool advance)
if (col > 0 && curwin->w_wcol > 0) {
// Correct when the cursor is on the right halve
// of a double-wide character.
- ptr = (char_u *)get_cursor_line_ptr();
- col -= utf_head_off((char *)ptr, (char *)ptr + col);
- if (utf_ptr2cells((char *)ptr + col) > 1) {
+ ptr = get_cursor_line_ptr();
+ col -= utf_head_off(ptr, ptr + col);
+ if (utf_ptr2cells(ptr + col) > 1) {
curwin->w_wcol--;
}
}
@@ -2760,7 +2757,7 @@ static int vgetorpeek(bool advance)
}
if (timedout && c == ESC) {
- char_u nop_buf[3];
+ uint8_t nop_buf[3];
// When recording there will be no timeout. Add a <Nop> after the ESC
// to avoid that it forms a key code with following characters.
@@ -2798,7 +2795,7 @@ static int vgetorpeek(bool advance)
/// Return -1 when end of input script reached.
///
/// @param wait_time milliseconds
-int inchar(char_u *buf, int maxlen, long wait_time)
+int inchar(uint8_t *buf, int maxlen, long wait_time)
{
int len = 0; // Init for GCC.
int retesc = false; // Return ESC with gotint.
@@ -2837,7 +2834,7 @@ int inchar(char_u *buf, int maxlen, long wait_time)
return -1;
}
} else {
- buf[0] = (char_u)script_char;
+ buf[0] = (uint8_t)script_char;
len = 1;
}
}
@@ -2851,7 +2848,7 @@ int inchar(char_u *buf, int maxlen, long wait_time)
// and buf may be pointing inside typebuf.tb_buf[].
if (got_int) {
#define DUM_LEN (MAXMAPLEN * 3 + 3)
- char_u dum[DUM_LEN + 1];
+ uint8_t dum[DUM_LEN + 1];
for (;;) {
len = os_inchar(dum, DUM_LEN, 0L, 0, NULL);
@@ -2884,13 +2881,13 @@ int inchar(char_u *buf, int maxlen, long wait_time)
typebuf.tb_change_cnt = 1;
}
- return fix_input_buffer((char *)buf, len);
+ return fix_input_buffer(buf, len);
}
// Fix typed characters for use by vgetc() and check_termcode().
// "buf[]" must have room to triple the number of bytes!
// Returns the new length.
-int fix_input_buffer(char *buf, int len)
+int fix_input_buffer(uint8_t *buf, int len)
FUNC_ATTR_NONNULL_ALL
{
if (!using_script()) {
@@ -2901,7 +2898,7 @@ int fix_input_buffer(char *buf, int len)
}
// Reading from script, need to process special bytes
- char_u *p = (char_u *)buf;
+ uint8_t *p = buf;
// Two characters are special: NUL and K_SPECIAL.
// Replace NUL by K_SPECIAL KS_ZERO KE_FILLER
@@ -2911,8 +2908,8 @@ int fix_input_buffer(char *buf, int len)
|| (p[0] == K_SPECIAL
&& (i < 2 || p[1] != KS_EXTRA))) {
memmove(p + 3, p + 1, (size_t)i);
- p[2] = (char_u)K_THIRD(p[0]);
- p[1] = (char_u)K_SECOND(p[0]);
+ p[2] = (uint8_t)K_THIRD(p[0]);
+ p[1] = (uint8_t)K_SECOND(p[0]);
p[0] = K_SPECIAL;
p += 2;
len += 2;
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index 94448eb7d7..f3bfbdabf6 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -789,7 +789,7 @@ EXTERN int redir_reg INIT(= 0); // message redirection register
EXTERN int redir_vname INIT(= 0); // message redirection variable
EXTERN garray_T *capture_ga INIT(= NULL); // captured output for execute()
-EXTERN char_u langmap_mapchar[256]; // mapping for language keys
+EXTERN uint8_t langmap_mapchar[256]; // mapping for language keys
EXTERN int save_p_ls INIT(= -1); // Save 'laststatus' setting
EXTERN int save_p_wmh INIT(= -1); // Save 'winminheight' setting
@@ -832,7 +832,7 @@ EXTERN long sub_nsubs; // total number of substitutions
EXTERN linenr_T sub_nlines; // total number of lines changed
// table to store parsed 'wildmode'
-EXTERN char_u wim_flags[4];
+EXTERN uint8_t wim_flags[4];
// whether titlestring and iconstring contains statusline syntax
#define STL_IN_ICON 1
diff --git a/src/nvim/input.c b/src/nvim/input.c
index 5b9b866778..fa55c02a24 100644
--- a/src/nvim/input.c
+++ b/src/nvim/input.c
@@ -86,7 +86,7 @@ int ask_yesno(const char *const str, const bool direct)
/// Translates the interrupt character for unix to ESC.
int get_keystroke(MultiQueue *events)
{
- char *buf = NULL;
+ uint8_t *buf = NULL;
int buflen = 150;
int len = 0;
int n;
@@ -112,7 +112,7 @@ int get_keystroke(MultiQueue *events)
// First time: blocking wait. Second time: wait up to 100ms for a
// terminal code to complete.
- n = os_inchar((uint8_t *)buf + len, maxlen, len == 0 ? -1L : 100L, 0, events);
+ n = os_inchar(buf + len, maxlen, len == 0 ? -1L : 100L, 0, events);
if (n > 0) {
// Replace zero and K_SPECIAL by a special key code.
n = fix_input_buffer(buf + len, n);
@@ -127,14 +127,14 @@ int get_keystroke(MultiQueue *events)
}
// Handle modifier and/or special key code.
- n = (uint8_t)buf[0];
+ n = buf[0];
if (n == K_SPECIAL) {
- n = TO_SPECIAL((uint8_t)buf[1], (uint8_t)buf[2]);
- if ((uint8_t)buf[1] == KS_MODIFIER
+ n = TO_SPECIAL(buf[1], buf[2]);
+ if (buf[1] == KS_MODIFIER
|| n == K_IGNORE
|| (is_mouse_key(n) && n != K_LEFTMOUSE)) {
- if ((uint8_t)buf[1] == KS_MODIFIER) {
- mod_mask = (uint8_t)buf[2];
+ if (buf[1] == KS_MODIFIER) {
+ mod_mask = buf[2];
}
len -= 3;
if (len > 0) {
@@ -149,7 +149,7 @@ int get_keystroke(MultiQueue *events)
continue;
}
buf[len >= buflen ? buflen - 1 : len] = NUL;
- n = utf_ptr2char(buf);
+ n = utf_ptr2char((char *)buf);
break;
}
xfree(buf);
diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c
index 3840a00981..60524b9fb7 100644
--- a/src/nvim/mapping.c
+++ b/src/nvim/mapping.c
@@ -323,7 +323,7 @@ static void set_maparg_rhs(const char *const orig_rhs, const size_t orig_rhs_len
mapargs->orig_rhs_len = 0;
// stores <lua>ref_no<cr> in map_str
mapargs->rhs_len = (size_t)vim_snprintf(S_LEN(tmp_buf), "%c%c%c%d\r", K_SPECIAL,
- (char_u)KS_EXTRA, KE_LUA, rhs_lua);
+ KS_EXTRA, KE_LUA, rhs_lua);
mapargs->rhs = xstrdup(tmp_buf);
}
}
@@ -1879,7 +1879,7 @@ int makemap(FILE *fd, buf_T *buf)
// return FAIL for failure, OK otherwise
int put_escstr(FILE *fd, char *strstart, int what)
{
- char_u *str = (char_u *)strstart;
+ uint8_t *str = (uint8_t *)strstart;
int c;
// :map xx <Nop>
@@ -1956,7 +1956,7 @@ int put_escstr(FILE *fd, char *strstart, int what)
}
} else if (c < ' ' || c > '~' || c == '|'
|| (what == 0 && c == ' ')
- || (what == 1 && str == (char_u *)strstart && c == ' ')
+ || (what == 1 && str == (uint8_t *)strstart && c == ' ')
|| (what != 2 && c == '<')) {
if (putc(Ctrl_V, fd) < 0) {
return FAIL;
@@ -2383,7 +2383,7 @@ int langmap_adjust_mb(int c)
void langmap_init(void)
{
for (int i = 0; i < 256; i++) {
- langmap_mapchar[i] = (char_u)i; // we init with a one-to-one map
+ langmap_mapchar[i] = (uint8_t)i; // we init with a one-to-one map
}
ga_init(&langmap_mapga, sizeof(langmap_entry_T), 8);
}
@@ -2447,7 +2447,7 @@ void langmap_set(void)
langmap_set_entry(from, to);
} else {
assert(to <= UCHAR_MAX);
- langmap_mapchar[from & 255] = (char_u)to;
+ langmap_mapchar[from & 255] = (uint8_t)to;
}
// Advance to next pair
diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c
index d176a65228..ea2d5e6ff7 100644
--- a/src/nvim/spellsuggest.c
+++ b/src/nvim/spellsuggest.c
@@ -1209,7 +1209,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun
// The loop may take an indefinite amount of time. Break out after some
// time.
- proftime_T time_limit;
+ proftime_T time_limit = 0;
if (spell_suggest_timeout > 0) {
time_limit = profile_setlimit(spell_suggest_timeout);
}
diff --git a/src/nvim/testdir/test_blob.vim b/src/nvim/testdir/test_blob.vim
index cf03d2011c..2c145f2019 100644
--- a/src/nvim/testdir/test_blob.vim
+++ b/src/nvim/testdir/test_blob.vim
@@ -1,5 +1,8 @@
" Tests for the Blob types
+source check.vim
+source vim9.vim
+
func TearDown()
" Run garbage collection after every test
call test_garbagecollect_now()
@@ -9,186 +12,308 @@ endfunc
" Blob creation from constant
func Test_blob_create()
- let b = 0zDEADBEEF
- call assert_equal(v:t_blob, type(b))
- call assert_equal(4, len(b))
- call assert_equal(0xDE, b[0])
- call assert_equal(0xAD, b[1])
- call assert_equal(0xBE, b[2])
- call assert_equal(0xEF, b[3])
- call assert_fails('let x = b[4]')
-
- call assert_equal(0xDE, get(b, 0))
- call assert_equal(0xEF, get(b, 3))
-
- call assert_fails('let b = 0z1', 'E973:')
- call assert_fails('let b = 0z1x', 'E973:')
- call assert_fails('let b = 0z12345', 'E973:')
-
- call assert_equal(0z, v:_null_blob)
-
- let b = 0z001122.33445566.778899.aabbcc.dd
- call assert_equal(0z00112233445566778899aabbccdd, b)
- call assert_fails('let b = 0z1.1')
- call assert_fails('let b = 0z.')
- call assert_fails('let b = 0z001122.')
- call assert_fails('call get("", 1)', 'E896:')
- call assert_equal(0, len(v:_null_blob))
+ let lines =<< trim END
+ VAR b = 0zDEADBEEF
+ call assert_equal(v:t_blob, type(b))
+ call assert_equal(4, len(b))
+ call assert_equal(0xDE, b[0])
+ call assert_equal(0xAD, b[1])
+ call assert_equal(0xBE, b[2])
+ call assert_equal(0xEF, b[3])
+ call assert_fails('VAR x = b[4]')
+
+ call assert_equal(0xDE, get(b, 0))
+ call assert_equal(0xEF, get(b, 3))
+
+ call assert_fails('VAR b = 0z1', 'E973:')
+ call assert_fails('VAR b = 0z1x', 'E973:')
+ call assert_fails('VAR b = 0z12345', 'E973:')
+
+ call assert_equal(0z, v:_null_blob)
+
+ LET b = 0z001122.33445566.778899.aabbcc.dd
+ call assert_equal(0z00112233445566778899aabbccdd, b)
+ call assert_fails('VAR b = 0z1.1')
+ call assert_fails('VAR b = 0z.')
+ call assert_fails('VAR b = 0z001122.')
+ call assert_fails('call get("", 1)', 'E896:')
+ call assert_equal(0, len(v:_null_blob))
+ END
+ call CheckLegacyAndVim9Success(lines)
endfunc
" assignment to a blob
func Test_blob_assign()
- let b = 0zDEADBEEF
- let b2 = b[1:2]
- call assert_equal(0zADBE, b2)
-
- let bcopy = b[:]
- call assert_equal(b, bcopy)
- call assert_false(b is bcopy)
-
- let b = 0zDEADBEEF
- let b2 = b
- call assert_true(b is b2)
- let b[:] = 0z11223344
- call assert_equal(0z11223344, b)
- call assert_equal(0z11223344, b2)
- call assert_true(b is b2)
-
- let b = 0zDEADBEEF
- let b[3:] = 0z66
- call assert_equal(0zDEADBE66, b)
- let b[:1] = 0z8899
- call assert_equal(0z8899BE66, b)
-
- call assert_fails('let b[2:3] = 0z112233', 'E972:')
- call assert_fails('let b[2:3] = 0z11', 'E972:')
- call assert_fails('let b[3:2] = 0z', 'E979:')
-
- let b = 0zDEADBEEF
- let b += 0z99
- call assert_equal(0zDEADBEEF99, b)
-
- call assert_fails('let b .= 0z33', 'E734:')
- call assert_fails('let b .= "xx"', 'E734:')
- call assert_fails('let b += "xx"', 'E734:')
- call assert_fails('let b[1:1] .= 0z55', 'E734:')
-
- let l = [0z12]
- let m = deepcopy(l)
- let m[0] = 0z34 " E742 or E741 should not occur.
+ let lines =<< trim END
+ VAR b = 0zDEADBEEF
+ VAR b2 = b[1 : 2]
+ call assert_equal(0zADBE, b2)
+
+ VAR bcopy = b[:]
+ call assert_equal(b, bcopy)
+ call assert_false(b is bcopy)
+
+ LET b = 0zDEADBEEF
+ LET b2 = b
+ call assert_true(b is b2)
+ LET b[:] = 0z11223344
+ call assert_equal(0z11223344, b)
+ call assert_equal(0z11223344, b2)
+ call assert_true(b is b2)
+
+ LET b = 0zDEADBEEF
+ LET b[3 :] = 0z66
+ call assert_equal(0zDEADBE66, b)
+ LET b[: 1] = 0z8899
+ call assert_equal(0z8899BE66, b)
+
+ LET b = 0zDEADBEEF
+ LET b += 0z99
+ call assert_equal(0zDEADBEEF99, b)
+
+ VAR l = [0z12]
+ VAR m = deepcopy(l)
+ LET m[0] = 0z34 #" E742 or E741 should not occur.
+ END
+ call CheckLegacyAndVim9Success(lines)
+
+ let lines =<< trim END
+ VAR b = 0zDEADBEEF
+ LET b[2 : 3] = 0z112233
+ END
+ call CheckLegacyAndVim9Failure(lines, 'E972:')
+
+ let lines =<< trim END
+ VAR b = 0zDEADBEEF
+ LET b[2 : 3] = 0z11
+ END
+ call CheckLegacyAndVim9Failure(lines, 'E972:')
+
+ let lines =<< trim END
+ VAR b = 0zDEADBEEF
+ LET b[3 : 2] = 0z
+ END
+ call CheckLegacyAndVim9Failure(lines, 'E979:')
+
+ let lines =<< trim END
+ VAR b = 0zDEADBEEF
+ LET b ..= 0z33
+ END
+ call CheckLegacyAndVim9Failure(lines, ['E734:', 'E1019:', 'E734:'])
+
+ let lines =<< trim END
+ VAR b = 0zDEADBEEF
+ LET b ..= "xx"
+ END
+ call CheckLegacyAndVim9Failure(lines, ['E734:', 'E1019:', 'E734:'])
+
+ let lines =<< trim END
+ VAR b = 0zDEADBEEF
+ LET b += "xx"
+ END
+ call CheckLegacyAndVim9Failure(lines, ['E734:', 'E1012:', 'E734:'])
+
+ let lines =<< trim END
+ VAR b = 0zDEADBEEF
+ LET b[1 : 1] ..= 0z55
+ END
+ call CheckLegacyAndVim9Failure(lines, ['E734:', 'E1183:', 'E734:'])
endfunc
func Test_blob_get_range()
+ let lines =<< trim END
+ VAR b = 0z0011223344
+ call assert_equal(0z2233, b[2 : 3])
+ call assert_equal(0z223344, b[2 : -1])
+ call assert_equal(0z00, b[0 : -5])
+ call assert_equal(0z, b[0 : -11])
+ call assert_equal(0z44, b[-1 :])
+ call assert_equal(0z0011223344, b[:])
+ call assert_equal(0z0011223344, b[: -1])
+ call assert_equal(0z, b[5 : 6])
+ call assert_equal(0z0011, b[-10 : 1])
+ END
+ call CheckLegacyAndVim9Success(lines)
+
+ " legacy script white space
let b = 0z0011223344
call assert_equal(0z2233, b[2:3])
- call assert_equal(0z223344, b[2:-1])
- call assert_equal(0z00, b[0:-5])
- call assert_equal(0z, b[0:-11])
- call assert_equal(0z44, b[-1:])
- call assert_equal(0z0011223344, b[:])
- call assert_equal(0z0011223344, b[:-1])
- call assert_equal(0z, b[5:6])
- call assert_equal(0z0011, b[-10:1])
endfunc
func Test_blob_get()
- let b = 0z0011223344
- call assert_equal(0x00, get(b, 0))
- call assert_equal(0x22, get(b, 2, 999))
- call assert_equal(0x44, get(b, 4))
- call assert_equal(0x44, get(b, -1))
- call assert_equal(-1, get(b, 5))
- call assert_equal(999, get(b, 5, 999))
- call assert_equal(-1, get(b, -8))
- call assert_equal(999, get(b, -8, 999))
- call assert_equal(10, get(v:_null_blob, 2, 10))
-
- call assert_equal(0x00, b[0])
- call assert_equal(0x22, b[2])
- call assert_equal(0x44, b[4])
- call assert_equal(0x44, b[-1])
- call assert_fails('echo b[5]', 'E979:')
- call assert_fails('echo b[-8]', 'E979:')
+ let lines =<< trim END
+ VAR b = 0z0011223344
+ call assert_equal(0x00, get(b, 0))
+ call assert_equal(0x22, get(b, 2, 999))
+ call assert_equal(0x44, get(b, 4))
+ call assert_equal(0x44, get(b, -1))
+ call assert_equal(-1, get(b, 5))
+ call assert_equal(999, get(b, 5, 999))
+ call assert_equal(-1, get(b, -8))
+ call assert_equal(999, get(b, -8, 999))
+ call assert_equal(10, get(v:_null_blob, 2, 10))
+
+ call assert_equal(0x00, b[0])
+ call assert_equal(0x22, b[2])
+ call assert_equal(0x44, b[4])
+ call assert_equal(0x44, b[-1])
+ END
+ call CheckLegacyAndVim9Success(lines)
+
+ let lines =<< trim END
+ VAR b = 0z0011223344
+ echo b[5]
+ END
+ call CheckLegacyAndVim9Failure(lines, 'E979:')
+
+ let lines =<< trim END
+ VAR b = 0z0011223344
+ echo b[-8]
+ END
+ call CheckLegacyAndVim9Failure(lines, 'E979:')
endfunc
func Test_blob_to_string()
- let b = 0z00112233445566778899aabbccdd
- call assert_equal('0z00112233.44556677.8899AABB.CCDD', string(b))
- call assert_equal(b, eval(string(b)))
- call remove(b, 4, -1)
- call assert_equal('0z00112233', string(b))
- call remove(b, 0, 3)
- call assert_equal('0z', string(b))
+ let lines =<< trim END
+ VAR b = 0z00112233445566778899aabbccdd
+ call assert_equal('0z00112233.44556677.8899AABB.CCDD', string(b))
+ call assert_equal(b, eval(string(b)))
+ call remove(b, 4, -1)
+ call assert_equal('0z00112233', string(b))
+ call remove(b, 0, 3)
+ call assert_equal('0z', string(b))
+ call assert_equal('0z', string(v:_null_blob))
+ END
+ call CheckLegacyAndVim9Success(lines)
endfunc
func Test_blob_compare()
- let b1 = 0z0011
- let b2 = 0z1100
- let b3 = 0z001122
- call assert_true(b1 == b1)
- call assert_false(b1 == b2)
- call assert_false(b1 == b3)
- call assert_true(b1 != b2)
- call assert_true(b1 != b3)
- call assert_true(b1 == 0z0011)
- call assert_fails('echo b1 == 9', 'E977:')
- call assert_fails('echo b1 != 9', 'E977:')
-
- call assert_false(b1 is b2)
- let b2 = b1
- call assert_true(b1 == b2)
- call assert_true(b1 is b2)
- let b2 = copy(b1)
- call assert_true(b1 == b2)
- call assert_false(b1 is b2)
- let b2 = b1[:]
- call assert_true(b1 == b2)
- call assert_false(b1 is b2)
-
- call assert_fails('let x = b1 > b2')
- call assert_fails('let x = b1 < b2')
- call assert_fails('let x = b1 - b2')
- call assert_fails('let x = b1 / b2')
- call assert_fails('let x = b1 * b2')
+ let lines =<< trim END
+ VAR b1 = 0z0011
+ VAR b2 = 0z1100
+ VAR b3 = 0z001122
+ call assert_true(b1 == b1)
+ call assert_false(b1 == b2)
+ call assert_false(b1 == b3)
+ call assert_true(b1 != b2)
+ call assert_true(b1 != b3)
+ call assert_true(b1 == 0z0011)
+
+ call assert_false(b1 is b2)
+ LET b2 = b1
+ call assert_true(b1 == b2)
+ call assert_true(b1 is b2)
+ LET b2 = copy(b1)
+ call assert_true(b1 == b2)
+ call assert_false(b1 is b2)
+ LET b2 = b1[:]
+ call assert_true(b1 == b2)
+ call assert_false(b1 is b2)
+ call assert_true(b1 isnot b2)
+ END
+ call CheckLegacyAndVim9Success(lines)
+
+ let lines =<< trim END
+ VAR b1 = 0z0011
+ echo b1 == 9
+ END
+ call CheckLegacyAndVim9Failure(lines, ['E977:', 'E1072', 'E1072'])
+
+ let lines =<< trim END
+ VAR b1 = 0z0011
+ echo b1 != 9
+ END
+ call CheckLegacyAndVim9Failure(lines, ['E977:', 'E1072', 'E1072'])
+
+ let lines =<< trim END
+ VAR b1 = 0z0011
+ VAR b2 = 0z1100
+ VAR x = b1 > b2
+ END
+ call CheckLegacyAndVim9Failure(lines, ['E978:', 'E1072:', 'E1072:'])
+
+ let lines =<< trim END
+ VAR b1 = 0z0011
+ VAR b2 = 0z1100
+ VAR x = b1 < b2
+ END
+ call CheckLegacyAndVim9Failure(lines, ['E978:', 'E1072:', 'E1072:'])
+
+ let lines =<< trim END
+ VAR b1 = 0z0011
+ VAR b2 = 0z1100
+ VAR x = b1 - b2
+ END
+ call CheckLegacyAndVim9Failure(lines, ['E974:', 'E1036:', 'E974:'])
+
+ let lines =<< trim END
+ VAR b1 = 0z0011
+ VAR b2 = 0z1100
+ VAR x = b1 / b2
+ END
+ call CheckLegacyAndVim9Failure(lines, ['E974:', 'E1036:', 'E974:'])
+
+ let lines =<< trim END
+ VAR b1 = 0z0011
+ VAR b2 = 0z1100
+ VAR x = b1 * b2
+ END
+ call CheckLegacyAndVim9Failure(lines, ['E974:', 'E1036:', 'E974:'])
endfunc
-" test for range assign
-func Test_blob_range_assign()
- let b = 0z00
- let b[1] = 0x11
- let b[2] = 0x22
- call assert_equal(0z001122, b)
- call assert_fails('let b[4] = 0x33', 'E979:')
+func Test_blob_index_assign()
+ let lines =<< trim END
+ VAR b = 0z00
+ LET b[1] = 0x11
+ LET b[2] = 0x22
+ call assert_equal(0z001122, b)
+ END
+ call CheckLegacyAndVim9Success(lines)
+
+ let lines =<< trim END
+ VAR b = 0z00
+ LET b[2] = 0x33
+ END
+ call CheckLegacyAndVim9Failure(lines, 'E979:')
+
+ let lines =<< trim END
+ VAR b = 0z00
+ LET b[-2] = 0x33
+ END
+ call CheckLegacyAndVim9Failure(lines, 'E979:')
endfunc
func Test_blob_for_loop()
- let blob = 0z00010203
- let i = 0
- for byte in blob
- call assert_equal(i, byte)
- let i += 1
- endfor
- call assert_equal(4, i)
-
- let blob = 0z00
- call remove(blob, 0)
- call assert_equal(0, len(blob))
- for byte in blob
- call assert_error('loop over empty blob')
- endfor
-
- let blob = 0z0001020304
- let i = 0
- for byte in blob
- call assert_equal(i, byte)
- if i == 1
+ let lines =<< trim END
+ VAR blob = 0z00010203
+ VAR i = 0
+ for byte in blob
+ call assert_equal(i, byte)
+ LET i += 1
+ endfor
+ call assert_equal(4, i)
+
+ LET blob = 0z00
call remove(blob, 0)
- elseif i == 3
- call remove(blob, 3)
- endif
- let i += 1
- endfor
- call assert_equal(5, i)
+ call assert_equal(0, len(blob))
+ for byte in blob
+ call assert_report('loop over empty blob')
+ endfor
+
+ LET blob = 0z0001020304
+ LET i = 0
+ for byte in blob
+ call assert_equal(i, byte)
+ if i == 1
+ call remove(blob, 0)
+ elseif i == 3
+ call remove(blob, 3)
+ endif
+ LET i += 1
+ endfor
+ call assert_equal(5, i)
+ END
+ call CheckLegacyAndVim9Success(lines)
endfunc
func Test_blob_concatenate()
@@ -223,51 +348,132 @@ endfunc
" Test removing items in blob
func Test_blob_func_remove()
- " Test removing 1 element
- let b = 0zDEADBEEF
- call assert_equal(0xDE, remove(b, 0))
- call assert_equal(0zADBEEF, b)
-
- let b = 0zDEADBEEF
- call assert_equal(0xEF, remove(b, -1))
- call assert_equal(0zDEADBE, b)
-
- let b = 0zDEADBEEF
- call assert_equal(0xAD, remove(b, 1))
- call assert_equal(0zDEBEEF, b)
-
- " Test removing range of element(s)
- let b = 0zDEADBEEF
- call assert_equal(0zBE, remove(b, 2, 2))
- call assert_equal(0zDEADEF, b)
-
- let b = 0zDEADBEEF
- call assert_equal(0zADBE, remove(b, 1, 2))
- call assert_equal(0zDEEF, b)
+ let lines =<< trim END
+ #" Test removing 1 element
+ VAR b = 0zDEADBEEF
+ call assert_equal(0xDE, remove(b, 0))
+ call assert_equal(0zADBEEF, b)
+
+ LET b = 0zDEADBEEF
+ call assert_equal(0xEF, remove(b, -1))
+ call assert_equal(0zDEADBE, b)
+
+ LET b = 0zDEADBEEF
+ call assert_equal(0xAD, remove(b, 1))
+ call assert_equal(0zDEBEEF, b)
+
+ #" Test removing range of element(s)
+ LET b = 0zDEADBEEF
+ call assert_equal(0zBE, remove(b, 2, 2))
+ call assert_equal(0zDEADEF, b)
+
+ LET b = 0zDEADBEEF
+ call assert_equal(0zADBE, remove(b, 1, 2))
+ call assert_equal(0zDEEF, b)
+ END
+ call CheckLegacyAndVim9Success(lines)
" Test invalid cases
- let b = 0zDEADBEEF
- call assert_fails("call remove(b, 5)", 'E979:')
- call assert_fails("call remove(b, 1, 5)", 'E979:')
- call assert_fails("call remove(b, 3, 2)", 'E979:')
- call assert_fails("call remove(1, 0)", 'E896:')
- call assert_fails("call remove(b, b)", 'E974:')
- call assert_fails("call remove(b, 1, [])", 'E745:')
- call assert_fails("call remove(v:_null_blob, 1, 2)", 'E979:')
-
- " Translated from v8.2.3284
- let b = 0zDEADBEEF
- lockvar b
- call assert_fails('call remove(b, 0)', 'E741:')
- unlockvar b
+ let lines =<< trim END
+ VAR b = 0zDEADBEEF
+ call remove(b, 5)
+ END
+ call CheckLegacyAndVim9Failure(lines, 'E979:')
+
+ let lines =<< trim END
+ VAR b = 0zDEADBEEF
+ call remove(b, 1, 5)
+ END
+ call CheckLegacyAndVim9Failure(lines, 'E979:')
+
+ let lines =<< trim END
+ VAR b = 0zDEADBEEF
+ call remove(b, 3, 2)
+ END
+ call CheckLegacyAndVim9Failure(lines, 'E979:')
+
+ let lines =<< trim END
+ VAR b = 0zDEADBEEF
+ call remove(1, 0)
+ END
+ call CheckLegacyAndVim9Failure(lines, 'E896:')
+
+ let lines =<< trim END
+ VAR b = 0zDEADBEEF
+ call remove(b, b)
+ END
+ call CheckLegacyAndVim9Failure(lines, 'E974:')
+
+ let lines =<< trim END
+ VAR b = 0zDEADBEEF
+ call remove(b, 1, [])
+ END
+ call CheckLegacyAndVim9Failure(lines, 'E745:')
+
+ let lines =<< trim END
+ VAR b = 0zDEADBEEF
+ call remove(v:_null_blob, 1, 2)
+ END
+ call CheckLegacyAndVim9Failure(lines, 'E979:')
+
+ let lines =<< trim END
+ let b = 0zDEADBEEF
+ lockvar b
+ call remove(b, 0)
+ unlockvar b
+ END
+ call CheckScriptFailure(lines, 'E741:')
+
+ " can only check at script level, not in a :def function
+ let lines =<< trim END
+ vim9script
+ var b = 0zDEADBEEF
+ lockvar b
+ remove(b, 0)
+ END
+ call CheckScriptFailure(lines, 'E741:')
endfunc
func Test_blob_read_write()
- let b = 0zDEADBEEF
- call writefile(b, 'Xblob')
- let br = readfile('Xblob', 'B')
- call assert_equal(b, br)
- call delete('Xblob')
+ let lines =<< trim END
+ VAR b = 0zDEADBEEF
+ call writefile(b, 'Xblob')
+ VAR br = readfile('Xblob', 'B')
+ call assert_equal(b, br)
+ VAR br2 = readblob('Xblob')
+ call assert_equal(b, br2)
+ VAR br3 = readblob('Xblob', 1)
+ call assert_equal(b[1 :], br3)
+ VAR br4 = readblob('Xblob', 1, 2)
+ call assert_equal(b[1 : 2], br4)
+ VAR br5 = readblob('Xblob', -3)
+ call assert_equal(b[-3 :], br5)
+ VAR br6 = readblob('Xblob', -3, 2)
+ call assert_equal(b[-3 : -2], br6)
+
+ #" reading past end of file, empty result
+ VAR br1e = readblob('Xblob', 10000)
+ call assert_equal(0z, br1e)
+
+ #" reading too much, result is truncated
+ VAR blong = readblob('Xblob', -1000)
+ call assert_equal(b, blong)
+ LET blong = readblob('Xblob', -10, 8)
+ call assert_equal(b, blong)
+ LET blong = readblob('Xblob', 0, 10)
+ call assert_equal(b, blong)
+
+ call delete('Xblob')
+ END
+ call CheckLegacyAndVim9Success(lines)
+
+ if filereadable('/dev/random')
+ let b = readblob('/dev/random', 0, 10)
+ call assert_equal(10, len(b))
+ endif
+
+ call assert_fails("call readblob('notexist')", 'E484:')
+ " TODO: How do we test for the E485 error?
" This was crashing when calling readfile() with a directory.
call assert_fails("call readfile('.', 'B')", 'E17: "." is a directory')
@@ -275,85 +481,230 @@ endfunc
" filter() item in blob
func Test_blob_filter()
- call assert_equal(v:_null_blob, filter(v:_null_blob, '0'))
- call assert_equal(0z, filter(0zDEADBEEF, '0'))
- call assert_equal(0zADBEEF, filter(0zDEADBEEF, 'v:val != 0xDE'))
- call assert_equal(0zDEADEF, filter(0zDEADBEEF, 'v:val != 0xBE'))
- call assert_equal(0zDEADBE, filter(0zDEADBEEF, 'v:val != 0xEF'))
- call assert_equal(0zDEADBEEF, filter(0zDEADBEEF, '1'))
- call assert_equal(0z01030103, filter(0z010203010203, 'v:val != 0x02'))
- call assert_equal(0zADEF, filter(0zDEADBEEF, 'v:key % 2'))
+ let lines =<< trim END
+ call assert_equal(v:_null_blob, filter(v:_null_blob, '0'))
+ call assert_equal(0z, filter(0zDEADBEEF, '0'))
+ call assert_equal(0zADBEEF, filter(0zDEADBEEF, 'v:val != 0xDE'))
+ call assert_equal(0zDEADEF, filter(0zDEADBEEF, 'v:val != 0xBE'))
+ call assert_equal(0zDEADBE, filter(0zDEADBEEF, 'v:val != 0xEF'))
+ call assert_equal(0zDEADBEEF, filter(0zDEADBEEF, '1'))
+ call assert_equal(0z01030103, filter(0z010203010203, 'v:val != 0x02'))
+ call assert_equal(0zADEF, filter(0zDEADBEEF, 'v:key % 2'))
+ END
+ call CheckLegacyAndVim9Success(lines)
endfunc
" map() item in blob
func Test_blob_map()
- call assert_equal(0zDFAEBFF0, map(0zDEADBEEF, 'v:val + 1'))
- call assert_equal(0z00010203, map(0zDEADBEEF, 'v:key'))
- call assert_equal(0zDEAEC0F2, map(0zDEADBEEF, 'v:key + v:val'))
-
- call assert_fails("call map(0z00, '[9]')", 'E978:')
+ let lines =<< trim END
+ call assert_equal(0zDFAEBFF0, map(0zDEADBEEF, 'v:val + 1'))
+ call assert_equal(0z00010203, map(0zDEADBEEF, 'v:key'))
+ call assert_equal(0zDEAEC0F2, map(0zDEADBEEF, 'v:key + v:val'))
+ END
+ call CheckLegacyAndVim9Success(lines)
+
+ let lines =<< trim END
+ call map(0z00, '[9]')
+ END
+ call CheckLegacyAndVim9Failure(lines, 'E978:')
endfunc
func Test_blob_index()
- call assert_equal(2, index(0zDEADBEEF, 0xBE))
- call assert_equal(-1, index(0zDEADBEEF, 0))
- call assert_equal(2, index(0z11111111, 0x11, 2))
- call assert_equal(3, 0z11110111->index(0x11, 2))
- call assert_equal(2, index(0z11111111, 0x11, -2))
- call assert_equal(3, index(0z11110111, 0x11, -2))
- call assert_equal(0, index(0z11110111, 0x11, -10))
- call assert_fails("echo index(0z11110111, 0x11, [])", 'E745:')
- call assert_equal(-1, index(v:_null_blob, 1))
-
- call assert_fails('call index("asdf", 0)', 'E897:')
+ let lines =<< trim END
+ call assert_equal(2, index(0zDEADBEEF, 0xBE))
+ call assert_equal(-1, index(0zDEADBEEF, 0))
+ call assert_equal(2, index(0z11111111, 0x11, 2))
+ call assert_equal(3, 0z11110111->index(0x11, 2))
+ call assert_equal(2, index(0z11111111, 0x11, -2))
+ call assert_equal(3, index(0z11110111, 0x11, -2))
+ call assert_equal(0, index(0z11110111, 0x11, -10))
+ call assert_equal(-1, index(v:_null_blob, 1))
+ END
+ call CheckLegacyAndVim9Success(lines)
+
+ let lines =<< trim END
+ echo index(0z11110111, 0x11, [])
+ END
+ call CheckLegacyAndVim9Failure(lines, 'E745:')
+
+ let lines =<< trim END
+ call index("asdf", 0)
+ END
+ call CheckLegacyAndVim9Failure(lines, 'E897:')
endfunc
func Test_blob_insert()
- let b = 0zDEADBEEF
- call insert(b, 0x33)
- call assert_equal(0z33DEADBEEF, b)
-
- let b = 0zDEADBEEF
- call insert(b, 0x33, 2)
- call assert_equal(0zDEAD33BEEF, b)
-
- call assert_fails('call insert(b, -1)', 'E475:')
- call assert_fails('call insert(b, 257)', 'E475:')
- call assert_fails('call insert(b, 0, [9])', 'E745:')
- call assert_fails('call insert(b, 0, -20)', 'E475:')
- call assert_fails('call insert(b, 0, 20)', 'E475:')
- call assert_fails('call insert(b, [])', 'E745:')
+ let lines =<< trim END
+ VAR b = 0zDEADBEEF
+ call insert(b, 0x33)
+ call assert_equal(0z33DEADBEEF, b)
+
+ LET b = 0zDEADBEEF
+ call insert(b, 0x33, 2)
+ call assert_equal(0zDEAD33BEEF, b)
+ END
+ call CheckLegacyAndVim9Success(lines)
+
+ " only works in legacy script
call assert_equal(0, insert(v:_null_blob, 0x33))
- " Translated from v8.2.3284
- let b = 0zDEADBEEF
- lockvar b
- call assert_fails('call insert(b, 3)', 'E741:')
- unlockvar b
+ let lines =<< trim END
+ VAR b = 0zDEADBEEF
+ call insert(b, -1)
+ END
+ call CheckLegacyAndVim9Failure(lines, 'E475:')
+
+ let lines =<< trim END
+ VAR b = 0zDEADBEEF
+ call insert(b, 257)
+ END
+ call CheckLegacyAndVim9Failure(lines, 'E475:')
+
+ let lines =<< trim END
+ VAR b = 0zDEADBEEF
+ call insert(b, 0, [9])
+ END
+ call CheckLegacyAndVim9Failure(lines, ['E745:', 'E1013:', 'E745:'])
+
+ let lines =<< trim END
+ VAR b = 0zDEADBEEF
+ call insert(b, 0, -20)
+ END
+ call CheckLegacyAndVim9Failure(lines, 'E475:')
+
+ let lines =<< trim END
+ VAR b = 0zDEADBEEF
+ call insert(b, 0, 20)
+ END
+ call CheckLegacyAndVim9Failure(lines, 'E475:')
+
+ let lines =<< trim END
+ VAR b = 0zDEADBEEF
+ call insert(b, [])
+ END
+ call CheckLegacyAndVim9Failure(lines, ['E745:', 'E1013:', 'E745:'])
+
+ let lines =<< trim END
+ insert(v:_null_blob, 0x33)
+ END
+ call CheckDefExecAndScriptFailure(lines, 'E1131:')
+
+ let lines =<< trim END
+ let b = 0zDEADBEEF
+ lockvar b
+ call insert(b, 3)
+ unlockvar b
+ END
+ call CheckScriptFailure(lines, 'E741:')
+
+ let lines =<< trim END
+ vim9script
+ var b = 0zDEADBEEF
+ lockvar b
+ insert(b, 3)
+ END
+ call CheckScriptFailure(lines, 'E741:')
endfunc
func Test_blob_reverse()
- call assert_equal(0zEFBEADDE, reverse(0zDEADBEEF))
- call assert_equal(0zBEADDE, reverse(0zDEADBE))
- call assert_equal(0zADDE, reverse(0zDEAD))
- call assert_equal(0zDE, reverse(0zDE))
- call assert_equal(0z, reverse(v:_null_blob))
+ let lines =<< trim END
+ call assert_equal(0zEFBEADDE, reverse(0zDEADBEEF))
+ call assert_equal(0zBEADDE, reverse(0zDEADBE))
+ call assert_equal(0zADDE, reverse(0zDEAD))
+ call assert_equal(0zDE, reverse(0zDE))
+ call assert_equal(0z, reverse(v:_null_blob))
+ END
+ call CheckLegacyAndVim9Success(lines)
+endfunc
+
+func Test_blob_json_encode()
+ let lines =<< trim END
+ #" call assert_equal('[222,173,190,239]', json_encode(0zDEADBEEF))
+ call assert_equal('[222, 173, 190, 239]', json_encode(0zDEADBEEF))
+ call assert_equal('[]', json_encode(0z))
+ END
+ call CheckLegacyAndVim9Success(lines)
endfunc
func Test_blob_lock()
- let b = 0z112233
- lockvar b
- call assert_fails('let b = 0z44', 'E741:')
- unlockvar b
- let b = 0z44
+ let lines =<< trim END
+ let b = 0z112233
+ lockvar b
+ unlockvar b
+ let b = 0z44
+ END
+ call CheckScriptSuccess(lines)
+
+ let lines =<< trim END
+ vim9script
+ var b = 0z112233
+ lockvar b
+ unlockvar b
+ b = 0z44
+ END
+ call CheckScriptSuccess(lines)
+
+ let lines =<< trim END
+ let b = 0z112233
+ lockvar b
+ let b = 0z44
+ END
+ call CheckScriptFailure(lines, 'E741:')
+
+ let lines =<< trim END
+ vim9script
+ var b = 0z112233
+ lockvar b
+ b = 0z44
+ END
+ call CheckScriptFailure(lines, 'E741:')
endfunc
func Test_blob_sort()
if has('float')
- call assert_fails('call sort([1.0, 0z11], "f")', 'E975:')
- else
- call assert_fails('call sort(["abc", 0z11], "f")', 'E702:')
+ call CheckLegacyAndVim9Failure(['call sort([1.0, 0z11], "f")'], 'E975:')
endif
+ call CheckLegacyAndVim9Failure(['call sort([11, 0z11], "N")'], 'E974:')
+endfunc
+
+" Tests for the blob2list() function
+func Test_blob2list()
+ call assert_fails('let v = blob2list(10)', 'E1238: Blob required for argument 1')
+ eval 0zFFFF->blob2list()->assert_equal([255, 255])
+ let tests = [[0z0102, [1, 2]],
+ \ [0z00, [0]],
+ \ [0z, []],
+ \ [0z00000000, [0, 0, 0, 0]],
+ \ [0zAABB.CCDD, [170, 187, 204, 221]]]
+ for t in tests
+ call assert_equal(t[0]->blob2list(), t[1])
+ endfor
+ exe 'let v = 0z' .. repeat('000102030405060708090A0B0C0D0E0F', 64)
+ call assert_equal(1024, blob2list(v)->len())
+ call assert_equal([4, 8, 15], [v[100], v[1000], v[1023]])
+ call assert_equal([], blob2list(v:_null_blob))
+endfunc
+
+" Tests for the list2blob() function
+func Test_list2blob()
+ call assert_fails('let b = list2blob(0z10)', 'E1211: List required for argument 1')
+ let tests = [[[1, 2], 0z0102],
+ \ [[0], 0z00],
+ \ [[], 0z],
+ \ [[0, 0, 0, 0], 0z00000000],
+ \ [[255, 255], 0zFFFF],
+ \ [[170, 187, 204, 221], 0zAABB.CCDD],
+ \ ]
+ for t in tests
+ call assert_equal(t[1], t[0]->list2blob())
+ endfor
+ call assert_fails('let b = list2blob([1, []])', 'E745:')
+ call assert_fails('let b = list2blob([-1])', 'E1239:')
+ call assert_fails('let b = list2blob([256])', 'E1239:')
+ let b = range(16)->repeat(64)->list2blob()
+ call assert_equal(1024, b->len())
+ call assert_equal([4, 8, 15], [b[100], b[1000], b[1023]])
+ call assert_equal(0z, list2blob(v:_null_list))
endfunc
" The following used to cause an out-of-bounds memory access
@@ -364,6 +715,58 @@ func Test_blob2string()
call assert_equal(v, string(b))
endfunc
+func Test_blob_repeat()
+ call assert_equal(0z, repeat(0z00, 0))
+ call assert_equal(0z00, repeat(0z00, 1))
+ call assert_equal(0z0000, repeat(0z00, 2))
+ call assert_equal(0z00000000, repeat(0z0000, 2))
+
+ call assert_equal(0z, repeat(0z12, 0))
+ call assert_equal(0z, repeat(0z1234, 0))
+ call assert_equal(0z1234, repeat(0z1234, 1))
+ call assert_equal(0z12341234, repeat(0z1234, 2))
+endfunc
+
+" Test for blob allocation failure
+func Test_blob_alloc_failure()
+ CheckFunction test_alloc_fail
+ " blob variable
+ call test_alloc_fail(GetAllocId('blob_alloc'), 0, 0)
+ call assert_fails('let v = 0z10', 'E342:')
+
+ " blob slice
+ let v = 0z1020
+ call test_alloc_fail(GetAllocId('blob_alloc'), 0, 0)
+ call assert_fails('let x = v[0:0]', 'E342:')
+ call assert_equal(0z1020, x)
+
+ " blob remove()
+ let v = 0z10203040
+ call test_alloc_fail(GetAllocId('blob_alloc'), 0, 0)
+ call assert_fails('let x = remove(v, 1, 2)', 'E342:')
+ call assert_equal(0, x)
+
+ " list2blob()
+ call test_alloc_fail(GetAllocId('blob_alloc'), 0, 0)
+ call assert_fails('let a = list2blob([1, 2, 4])', 'E342:')
+ call assert_equal(0, a)
+
+ " mapnew()
+ call test_alloc_fail(GetAllocId('blob_alloc'), 0, 0)
+ call assert_fails('let x = mapnew(0z1234, {_, v -> 1})', 'E342:')
+ call assert_equal(0, x)
+
+ " copy()
+ call test_alloc_fail(GetAllocId('blob_alloc'), 0, 0)
+ call assert_fails('let x = copy(v)', 'E342:')
+ call assert_equal(0z, x)
+
+ " readblob()
+ call test_alloc_fail(GetAllocId('blob_alloc'), 0, 0)
+ call assert_fails('let x = readblob("test_blob.vim")', 'E342:')
+ call assert_equal(0, x)
+endfunc
+
" Test for the indexof() function
func Test_indexof()
let b = 0zdeadbeef
diff --git a/src/nvim/testdir/test_buffer.vim b/src/nvim/testdir/test_buffer.vim
index 9220cc17b9..98eba83f73 100644
--- a/src/nvim/testdir/test_buffer.vim
+++ b/src/nvim/testdir/test_buffer.vim
@@ -451,4 +451,75 @@ func Test_buffer_maxmem()
" set maxmem& maxmemtot&
endfunc
+" Test for buffer allocation failure
+func Test_buflist_alloc_failure()
+ CheckFunction test_alloc_fail
+ %bw!
+
+ edit Xfile1
+ call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
+ call assert_fails('edit Xfile2', 'E342:')
+
+ " test for bufadd()
+ call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
+ call assert_fails('call bufadd("Xbuffer")', 'E342:')
+
+ " test for setting the arglist
+ edit Xfile2
+ call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
+ call assert_fails('next Xfile3', 'E342:')
+
+ " test for setting the alternate buffer name when writing a file
+ call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
+ call assert_fails('write Xother', 'E342:')
+ call delete('Xother')
+
+ " test for creating a buffer using bufnr()
+ call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
+ call assert_fails("call bufnr('Xnewbuf', v:true)", 'E342:')
+
+ " test for renaming buffer using :file
+ call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
+ call assert_fails('file Xnewfile', 'E342:')
+
+ " test for creating a buffer for a popup window
+ call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
+ call assert_fails('call popup_create("mypop", {})', 'E342:')
+
+ if has('terminal')
+ " test for creating a buffer for a terminal window
+ call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
+ call assert_fails('call term_start(&shell)', 'E342:')
+ %bw!
+ endif
+
+ " test for loading a new buffer after wiping out all the buffers
+ edit Xfile4
+ call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
+ call assert_fails('%bw!', 'E342:')
+
+ " test for :checktime loading the buffer
+ call writefile(['one'], 'Xfile5')
+ if has('unix')
+ edit Xfile5
+ " sleep for some time to make sure the timestamp is different
+ sleep 200m
+ call writefile(['two'], 'Xfile5')
+ set autoread
+ call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
+ call assert_fails('checktime', 'E342:')
+ set autoread&
+ bw!
+ endif
+
+ " test for :vimgrep loading a dummy buffer
+ call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
+ call assert_fails('vimgrep two Xfile5', 'E342:')
+ call delete('Xfile5')
+
+ " test for quickfix command loading a buffer
+ call test_alloc_fail(GetAllocId('newbuf_bvars'), 0, 0)
+ call assert_fails('cexpr "Xfile6:10:Line10"', 'E342:')
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim
index 96ab5620ec..148f8b6d42 100644
--- a/src/nvim/testdir/test_filetype.vim
+++ b/src/nvim/testdir/test_filetype.vim
@@ -140,6 +140,7 @@ let s:filename_checks = {
\ 'csv': ['file.csv'],
\ 'cucumber': ['file.feature'],
\ 'cuda': ['file.cu', 'file.cuh'],
+ \ 'cue': ['file.cue'],
\ 'cupl': ['file.pld'],
\ 'cuplsim': ['file.si'],
\ 'cvs': ['cvs123'],
diff --git a/src/nvim/testdir/test_listdict.vim b/src/nvim/testdir/test_listdict.vim
index fa22bad0cb..a6a1c736c4 100644
--- a/src/nvim/testdir/test_listdict.vim
+++ b/src/nvim/testdir/test_listdict.vim
@@ -886,11 +886,15 @@ func Test_listdict_extendnew()
let l = [1, 2, 3]
call assert_equal([1, 2, 3, 4, 5], extendnew(l, [4, 5]))
call assert_equal([1, 2, 3], l)
+ lockvar l
+ call assert_equal([1, 2, 3, 4, 5], extendnew(l, [4, 5]))
- " Test extend() with dictionaries.
+ " Test extendnew() with dictionaries.
let d = {'a': {'b': 'B'}}
call assert_equal({'a': {'b': 'B'}, 'c': 'cc'}, extendnew(d, {'c': 'cc'}))
call assert_equal({'a': {'b': 'B'}}, d)
+ lockvar d
+ call assert_equal({'a': {'b': 'B'}, 'c': 'cc'}, extendnew(d, {'c': 'cc'}))
endfunc
func s:check_scope_dict(x, fixed)
diff --git a/src/nvim/testdir/test_swap.vim b/src/nvim/testdir/test_swap.vim
index cf46b4c5bd..ceadc1d85a 100644
--- a/src/nvim/testdir/test_swap.vim
+++ b/src/nvim/testdir/test_swap.vim
@@ -235,7 +235,6 @@ func Test_swap_recover()
autocmd SwapExists * let v:swapchoice = 'r'
augroup END
-
call mkdir('Xswap')
let $Xswap = 'foo' " Check for issue #4369.
set dir=Xswap//
diff --git a/src/nvim/testdir/test_tabpage.vim b/src/nvim/testdir/test_tabpage.vim
index b97aa409d8..db23a36dd4 100644
--- a/src/nvim/testdir/test_tabpage.vim
+++ b/src/nvim/testdir/test_tabpage.vim
@@ -846,4 +846,43 @@ func Test_lastused_tabpage()
tabonly!
endfunc
+" Test for tabpage allocation failure
+func Test_tabpage_alloc_failure()
+ CheckFunction test_alloc_fail
+ call test_alloc_fail(GetAllocId('newtabpage_tvars'), 0, 0)
+ call assert_fails('tabnew', 'E342:')
+
+ call test_alloc_fail(GetAllocId('newtabpage_tvars'), 0, 0)
+ edit Xfile1
+ call assert_fails('tabedit Xfile2', 'E342:')
+ call assert_equal(1, winnr('$'))
+ call assert_equal(1, tabpagenr('$'))
+ call assert_equal('Xfile1', @%)
+
+ new
+ call test_alloc_fail(GetAllocId('newtabpage_tvars'), 0, 0)
+ call assert_fails('wincmd T', 'E342:')
+ bw!
+
+ call test_alloc_fail(GetAllocId('newtabpage_tvars'), 0, 0)
+ call assert_fails('tab split', 'E342:')
+ call assert_equal(2, winnr('$'))
+ call assert_equal(1, tabpagenr('$'))
+endfunc
+
+" this was giving ml_get errors
+func Test_tabpage_last_line()
+ enew
+ call setline(1, repeat(['a'], &lines + 5))
+ $
+ tabnew
+ call setline(1, repeat(['b'], &lines + 20))
+ $
+ tabNext
+ call assert_equal('a', getline('.'))
+
+ bwipe!
+ bwipe!
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/nvim/testdir/test_window_cmd.vim b/src/nvim/testdir/test_window_cmd.vim
index 8b9457ae1d..34614832a9 100644
--- a/src/nvim/testdir/test_window_cmd.vim
+++ b/src/nvim/testdir/test_window_cmd.vim
@@ -1525,6 +1525,52 @@ func Test_win_move_statusline()
%bwipe!
endfunc
+" Test for window allocation failure
+func Test_window_alloc_failure()
+ CheckFunction test_alloc_fail
+ %bw!
+
+ " test for creating a new window above current window
+ call test_alloc_fail(GetAllocId('newwin_wvars'), 0, 0)
+ call assert_fails('above new', 'E342:')
+ call assert_equal(1, winnr('$'))
+
+ " test for creating a new window below current window
+ call test_alloc_fail(GetAllocId('newwin_wvars'), 0, 0)
+ call assert_fails('below new', 'E342:')
+ call assert_equal(1, winnr('$'))
+
+ " test for popup window creation failure
+ call test_alloc_fail(GetAllocId('newwin_wvars'), 0, 0)
+ call assert_fails('call popup_create("Hello", {})', 'E342:')
+ call assert_equal([], popup_list())
+
+ call test_alloc_fail(GetAllocId('newwin_wvars'), 0, 0)
+ call assert_fails('split', 'E342:')
+ call assert_equal(1, winnr('$'))
+
+ edit Xfile1
+ edit Xfile2
+ call test_alloc_fail(GetAllocId('newwin_wvars'), 0, 0)
+ call assert_fails('sb Xfile1', 'E342:')
+ call assert_equal(1, winnr('$'))
+ call assert_equal('Xfile2', @%)
+ %bw!
+
+ " FIXME: The following test crashes Vim
+ " test for new tabpage creation failure
+ " call test_alloc_fail(GetAllocId('newwin_wvars'), 0, 0)
+ " call assert_fails('tabnew', 'E342:')
+ " call assert_equal(1, tabpagenr('$'))
+ " call assert_equal(1, winnr('$'))
+
+ " This test messes up the internal Vim window/frame information. So the
+ " Test_window_cmd_cmdwin_with_vsp() test fails after running this test.
+ " Open a new tab and close everything else to fix this issue.
+ tabnew
+ tabonly
+endfunc
+
func Test_win_equal_last_status()
let save_lines = &lines
set lines=20
diff --git a/src/nvim/testdir/vim9.vim b/src/nvim/testdir/vim9.vim
index 3c0ff2b2dd..2cc3d88aa8 100644
--- a/src/nvim/testdir/vim9.vim
+++ b/src/nvim/testdir/vim9.vim
@@ -34,6 +34,10 @@ func CheckScriptSuccess(lines)
endtry
endfunc
+func CheckDefExecAndScriptFailure(lines, error, lnum = -3)
+ return
+endfunc
+
" Check that "lines" inside a legacy function has no error.
func CheckLegacySuccess(lines)
let cwd = getcwd()
@@ -98,9 +102,9 @@ endfunc
" Use ' #"' for a comment
func CheckLegacyAndVim9Failure(lines, error)
if type(a:error) == type('string')
- let legacyError = error
+ let legacyError = a:error
else
- let legacyError = error[0]
+ let legacyError = a:error[0]
endif
let legacylines = a:lines->deepcopy()->map({_, v ->
diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c
index fee1d21672..48dc860ebd 100644
--- a/src/nvim/tui/tui.c
+++ b/src/nvim/tui/tui.c
@@ -1109,8 +1109,8 @@ void tui_set_mode(TUIData *tui, ModeShape mode)
// Hopefully the user's default cursor color is inverse.
unibi_out_ext(tui, tui->unibi_ext.reset_cursor_color);
} else {
+ char hexbuf[8];
if (tui->set_cursor_color_as_str) {
- char hexbuf[8];
snprintf(hexbuf, 7 + 1, "#%06x", aep.rgb_bg_color);
UNIBI_SET_STR_VAR(tui->params[0], hexbuf);
} else {
diff --git a/src/nvim/ui.c b/src/nvim/ui.c
index 73545441d3..ce1a57350a 100644
--- a/src/nvim/ui.c
+++ b/src/nvim/ui.c
@@ -134,6 +134,7 @@ void ui_free_all_mem(void)
}
#endif
+/// Returns true if any `rgb=true` UI is attached.
bool ui_rgb_attached(void)
{
if (!headless_mode && p_tgc) {
@@ -147,6 +148,18 @@ bool ui_rgb_attached(void)
return false;
}
+/// Returns true if a GUI is attached.
+bool ui_gui_attached(void)
+{
+ for (size_t i = 0; i < ui_count; i++) {
+ bool tui = uis[i]->stdin_tty || uis[i]->stdout_tty;
+ if (!tui) {
+ return true;
+ }
+ }
+ return false;
+}
+
/// Returns true if any UI requested `override=true`.
bool ui_override(void)
{
@@ -598,6 +611,14 @@ Array ui_array(void)
PUT(info, "height", INTEGER_OBJ(ui->height));
PUT(info, "rgb", BOOLEAN_OBJ(ui->rgb));
PUT(info, "override", BOOLEAN_OBJ(ui->override));
+
+ // TUI fields. (`stdin_fd` is intentionally omitted.)
+ PUT(info, "term_name", STRING_OBJ(cstr_to_string(ui->term_name)));
+ PUT(info, "term_background", STRING_OBJ(cstr_to_string(ui->term_background)));
+ PUT(info, "term_colors", INTEGER_OBJ(ui->term_colors));
+ PUT(info, "stdin_tty", BOOLEAN_OBJ(ui->stdin_tty));
+ PUT(info, "stdout_tty", BOOLEAN_OBJ(ui->stdout_tty));
+
for (UIExtension j = 0; j < kUIExtCount; j++) {
if (ui_ext_names[j][0] != '_' || ui->ui_ext[j]) {
PUT(info, ui_ext_names[j], BOOLEAN_OBJ(ui->ui_ext[j]));
diff --git a/src/nvim/ui.h b/src/nvim/ui.h
index e83f93eb07..dc0ccc73ea 100644
--- a/src/nvim/ui.h
+++ b/src/nvim/ui.h
@@ -103,6 +103,13 @@ struct ui_t {
double pum_height;
double pum_width;
+ // TUI fields.
+ char *term_name;
+ char *term_background;
+ int term_colors;
+ bool stdin_tty;
+ bool stdout_tty;
+
// TODO(bfredl): integrate into struct!
UIData data[1];
};
diff --git a/src/nvim/ui_client.c b/src/nvim/ui_client.c
index 8262293ec5..25ff63ea2d 100644
--- a/src/nvim/ui_client.c
+++ b/src/nvim/ui_client.c
@@ -1,6 +1,8 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
+/// Nvim's own UI client, which attaches to a child or remote Nvim server.
+
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
diff --git a/src/nvim/window.c b/src/nvim/window.c
index 0a4d36acb2..38b7326363 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -1899,8 +1899,8 @@ static void win_rotate(bool upwards, int count)
}
}
- win_T *wp1;
- win_T *wp2;
+ win_T *wp1 = NULL;
+ win_T *wp2 = NULL;
while (count--) {
if (upwards) { // first window becomes last window
@@ -4813,7 +4813,7 @@ static void win_enter_ext(win_T *const wp, const int flags)
// Might need to scroll the old window before switching, e.g., when the
// cursor was moved.
- if (*p_spk == 'c') {
+ if (*p_spk == 'c' && !curwin_invalid) {
update_topline(curwin);
}
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index 3e40967dd5..08abf82f47 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -2549,20 +2549,26 @@ describe('API', function()
{
chan = 1,
ext_cmdline = false,
- ext_popupmenu = false,
- ext_tabline = false,
- ext_wildmenu = false,
+ ext_hlstate = false,
ext_linegrid = screen._options.ext_linegrid or false,
+ ext_messages = false,
ext_multigrid = false,
- ext_hlstate = false,
+ ext_popupmenu = false,
+ ext_tabline = false,
ext_termcolors = false,
- ext_messages = false,
+ ext_wildmenu = false,
height = 4,
- rgb = true,
override = true,
+ rgb = true,
+ stdin_tty = false,
+ stdout_tty = false,
+ term_background = '',
+ term_colors = 0,
+ term_name = '',
width = 20,
}
}
+
eq(expected, nvim("list_uis"))
screen:detach()
diff --git a/test/functional/plugin/lsp/semantic_tokens_spec.lua b/test/functional/plugin/lsp/semantic_tokens_spec.lua
index 9c1ba86fe1..004fce4983 100644
--- a/test/functional/plugin/lsp/semantic_tokens_spec.lua
+++ b/test/functional/plugin/lsp/semantic_tokens_spec.lua
@@ -24,6 +24,25 @@ end)
describe('semantic token highlighting', function()
+ local screen
+ before_each(function()
+ screen = Screen.new(40, 16)
+ screen:attach()
+ screen:set_default_attr_ids {
+ [1] = { bold = true, foreground = Screen.colors.Blue1 };
+ [2] = { foreground = Screen.colors.DarkCyan };
+ [3] = { foreground = Screen.colors.SlateBlue };
+ [4] = { bold = true, foreground = Screen.colors.SeaGreen };
+ [5] = { foreground = tonumber('0x6a0dad') };
+ [6] = { foreground = Screen.colors.Blue1 };
+ [7] = { bold = true, foreground = Screen.colors.DarkCyan };
+ [8] = { bold = true, foreground = Screen.colors.SlateBlue };
+ }
+ command([[ hi link @namespace Type ]])
+ command([[ hi link @function Special ]])
+ command([[ hi @declaration gui=bold ]])
+ end)
+
describe('general', function()
local text = dedent([[
#include <iostream>
@@ -58,24 +77,7 @@ describe('semantic token highlighting', function()
"resultId":"2"
}]]
- local screen
before_each(function()
- screen = Screen.new(40, 16)
- screen:attach()
- screen:set_default_attr_ids {
- [1] = { bold = true, foreground = Screen.colors.Blue1 };
- [2] = { foreground = Screen.colors.DarkCyan };
- [3] = { foreground = Screen.colors.SlateBlue };
- [4] = { bold = true, foreground = Screen.colors.SeaGreen };
- [5] = { foreground = tonumber('0x6a0dad') };
- [6] = { foreground = Screen.colors.Blue1 };
- [7] = { bold = true, foreground = Screen.colors.DarkCyan };
- [8] = { bold = true, foreground = Screen.colors.SlateBlue };
- }
- command([[ hi link @namespace Type ]])
- command([[ hi link @function Special ]])
- command([[ hi @declaration gui=bold ]])
-
exec_lua(create_server_definition)
exec_lua([[
local legend, response, edit_response = ...
@@ -928,6 +930,46 @@ b = "as"]],
extmark_added = true,
}
},
+ expected_screen1 = function()
+ screen:expect{grid=[[
+ char* {7:foo} = "\n"^; |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ end,
+ expected_screen2 = function()
+ screen:expect{grid=[[
+ ^ |
+ char* {7:foo} = "\n"; |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ end,
},
{
it = 'response with multiple delta edits',
@@ -1127,6 +1169,46 @@ int main()
extmark_added = true,
}
},
+ expected_screen1 = function()
+ screen:expect{grid=[[
+ #include <iostream> |
+ |
+ int {8:main}() |
+ { |
+ int {7:x}; |
+ #ifdef {5:__cplusplus} |
+ {4:std}::{2:cout} << {2:x} << "\n"; |
+ {6:#else} |
+ {6: printf("%d\n", x);} |
+ {6:#endif} |
+ ^} |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ end,
+ expected_screen2 = function()
+ screen:expect{grid=[[
+ #include <iostream> |
+ |
+ int {8:main}() |
+ { |
+ int {8:x}(); |
+ double {7:y}; |
+ #ifdef {5:__cplusplus} |
+ {4:std}::{2:cout} << {3:x} << "\n"; |
+ {6:#else} |
+ {6: printf("%d\n", x);} |
+ {6:^#endif} |
+ } |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ end,
},
{
it = 'optional token_edit.data on deletion',
@@ -1156,6 +1238,46 @@ int main()
},
expected2 = {
},
+ expected_screen1 = function()
+ screen:expect{grid=[[
+ {7:string} = "test^" |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ end,
+ expected_screen2 = function()
+ screen:expect{grid=[[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ end,
},
}) do
it(test.it, function()
@@ -1192,6 +1314,8 @@ int main()
insert(test.text1)
+ test.expected_screen1()
+
local highlights = exec_lua([[
return semantic_tokens.__STHighlighter.active[bufnr].client_state[client_id].current_result.highlights
]])
@@ -1208,6 +1332,8 @@ int main()
]], test.text2)
end
+ test.expected_screen2()
+
highlights = exec_lua([[
return semantic_tokens.__STHighlighter.active[bufnr].client_state[client_id].current_result.highlights
]])
diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua
index 792ad63e76..069fbad803 100644
--- a/test/functional/terminal/tui_spec.lua
+++ b/test/functional/terminal/tui_spec.lua
@@ -1398,17 +1398,34 @@ describe('TUI', function()
]]}
end)
- it('is included in nvim_list_uis()', function()
- feed_data(':echo map(nvim_list_uis(), {k,v -> sort(items(filter(v, {k,v -> k[:3] !=# "ext_" })))})\r')
- screen:expect([=[
- |
- {4:~ }|
- {5: }|
- [[['chan', 1], ['height', 6], ['override', v:false|
- ], ['rgb', v:false], ['width', 50]]] |
- {10:Press ENTER or type command to continue}{1: } |
- {3:-- TERMINAL --} |
- ]=])
+ it('in nvim_list_uis()', function()
+ -- $TERM in :terminal.
+ local exp_term = is_os('bsd') and 'builtin_xterm' or 'xterm-256color'
+ local expected = {
+ {
+ chan = 1,
+ ext_cmdline = false,
+ ext_hlstate = false,
+ ext_linegrid = true,
+ ext_messages = false,
+ ext_multigrid = false,
+ ext_popupmenu = false,
+ ext_tabline = false,
+ ext_termcolors = true,
+ ext_wildmenu = false,
+ height = 6,
+ override = false,
+ rgb = false,
+ stdin_tty = true,
+ stdout_tty = true,
+ term_background = '',
+ term_colors = 256,
+ term_name = exp_term,
+ width = 50
+ },
+ }
+ local _, rv = child_session:request('nvim_list_uis')
+ eq(expected, rv)
end)
it('allows grid to assume wider ambiguous-width characters than host terminal #19686', function()
@@ -1512,6 +1529,42 @@ describe('TUI', function()
exec_lua([[vim.loop.kill(vim.fn.jobpid(vim.bo.channel), 'sigterm')]])
screen:expect({any = '%[Process exited 1%]'})
end)
+
+ it('no stack-use-after-scope with cursor color #22432', function()
+ screen:set_option('rgb', true)
+ command('set termguicolors')
+ child_session:request('nvim_exec', [[
+ set tgc
+ hi Cursor guifg=Red guibg=Green
+ set guicursor=n:block-Cursor/lCursor
+ ]], false)
+ screen:set_default_attr_ids({
+ [1] = {reverse = true},
+ [2] = {bold = true, foreground = Screen.colors.Blue},
+ [3] = {foreground = Screen.colors.Blue},
+ [4] = {reverse = true, bold = true},
+ [5] = {bold = true},
+ })
+ screen:expect([[
+ {1: } |
+ {2:~}{3: }|
+ {2:~}{3: }|
+ {2:~}{3: }|
+ {4:[No Name] }|
+ |
+ {5:-- TERMINAL --} |
+ ]])
+ feed('i')
+ screen:expect([[
+ {1: } |
+ {2:~}{3: }|
+ {2:~}{3: }|
+ {2:~}{3: }|
+ {4:[No Name] }|
+ {5:-- INSERT --} |
+ {5:-- TERMINAL --} |
+ ]])
+ end)
end)
describe('TUI', function()
diff --git a/test/functional/ui/statuscolumn_spec.lua b/test/functional/ui/statuscolumn_spec.lua
index 287686cf37..f997546c7c 100644
--- a/test/functional/ui/statuscolumn_spec.lua
+++ b/test/functional/ui/statuscolumn_spec.lua
@@ -478,4 +478,24 @@ describe('statuscolumn', function()
|
]])
end)
+
+ it('works with cmdwin', function()
+ feed(':set stc=%l<CR>q:k$')
+ screen:expect([[
+ 7 aaaaa |
+ 8 aaaaa |
+ 9 aaaaa |
+ 10aaaaa |
+ [No Name] [+] |
+ :1set stc=%^l |
+ :2 |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ [Command Line] |
+ : |
+ ]])
+ end)
end)
diff --git a/test/functional/vimscript/has_spec.lua b/test/functional/vimscript/has_spec.lua
index 2e26d603b3..78a761d370 100644
--- a/test/functional/vimscript/has_spec.lua
+++ b/test/functional/vimscript/has_spec.lua
@@ -1,8 +1,11 @@
local helpers = require('test.functional.helpers')(after_each)
-local eq = helpers.eq
+local Screen = require('test.functional.ui.screen')
local clear = helpers.clear
+local connect = helpers.connect
+local eq = helpers.eq
local funcs = helpers.funcs
local is_os = helpers.is_os
+local nvim_prog = helpers.nvim_prog
describe('has()', function()
before_each(clear)
@@ -69,8 +72,22 @@ describe('has()', function()
end
end)
+ it('"gui_running"', function()
+ eq(0, funcs.has('gui_running'))
+ local tui = Screen.new(50,15)
+ local gui_session = connect(funcs.serverstart())
+ local gui = Screen.new(50,15)
+ eq(0, funcs.has('gui_running'))
+ tui:attach({ext_linegrid=true, rgb=true, stdin_tty=true, stdout_tty=true})
+ gui:attach({ext_multigrid=true, rgb=true}, gui_session)
+ eq(1, funcs.has('gui_running'))
+ tui:detach()
+ eq(1, funcs.has('gui_running'))
+ gui:detach()
+ eq(0, funcs.has('gui_running'))
+ end)
+
it('does not change v:shell_error', function()
- local nvim_prog = helpers.nvim_prog
funcs.system({nvim_prog, '-es', '+73cquit'})
funcs.has('python3') -- use a call whose implementation shells out
eq(73, funcs.eval('v:shell_error'))
diff --git a/test/helpers.lua b/test/helpers.lua
index d45536b42b..117b6b4aaa 100644
--- a/test/helpers.lua
+++ b/test/helpers.lua
@@ -312,7 +312,7 @@ function module.is_os(s)
or s == 'bsd') then
error('unknown platform: '..tostring(s))
end
- return ((s == 'win' and module.sysname():find('windows'))
+ return not not ((s == 'win' and module.sysname():find('windows'))
or (s == 'mac' and module.sysname() == 'darwin')
or (s == 'freebsd' and module.sysname() == 'freebsd')
or (s == 'openbsd' and module.sysname() == 'openbsd')