diff options
51 files changed, 1477 insertions, 654 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 8cde2f8fb0..ed8c78ef2f 100644 --- a/runtime/doc/builtin.txt +++ b/runtime/doc/builtin.txt @@ -2126,8 +2126,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()* @@ -8726,6 +8725,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/sign.txt b/runtime/doc/sign.txt index 53ef03eb63..162bdaed7b 100644 --- a/runtime/doc/sign.txt +++ b/runtime/doc/sign.txt @@ -595,23 +595,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/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/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/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/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/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..698172442e 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, lp->ll_n1, 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; } diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index d97f7b6d35..d3bac14754 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -3745,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) { @@ -3788,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); diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 0a30cdb62e..d56efe30da 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -2710,6 +2710,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, long n1, long 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 = (int)n1, ir = 0; il <= (int)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) { 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 af26fe8a1c..a3e0e650fa 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2456,7 +2456,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 @@ -2693,7 +2693,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..b1859f9dfe 100644 --- a/src/nvim/testdir/test_blob.vim +++ b/src/nvim/testdir/test_blob.vim @@ -1,5 +1,7 @@ " Tests for the Blob types +source vim9.vim + func TearDown() " Run garbage collection after every test call test_garbagecollect_now() @@ -9,186 +11,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 +347,101 @@ 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) + call delete('Xblob') + END + call CheckLegacyAndVim9Success(lines) " This was crashing when calling readfile() with a directory. call assert_fails("call readfile('.', 'B')", 'E17: "." is a directory') @@ -275,85 +449,190 @@ 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 " The following used to cause an out-of-bounds memory access 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_tabpage.vim b/src/nvim/testdir/test_tabpage.vim index b97aa409d8..c20c798c49 100644 --- a/src/nvim/testdir/test_tabpage.vim +++ b/src/nvim/testdir/test_tabpage.vim @@ -846,4 +846,19 @@ func Test_lastused_tabpage() tabonly! 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/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/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/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 76ea6256a1..069fbad803 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -1529,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) |