diff options
76 files changed, 2072 insertions, 1220 deletions
diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 50ef4e6897..90ba2a6d7a 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1 +1,2 @@ -custom: https://salt.bountysource.com/teams/neovim +github: neovim +open_collective: neovim diff --git a/runtime/autoload/spellfile.vim b/runtime/autoload/spellfile.vim index d098902305..e36e2f936b 100644 --- a/runtime/autoload/spellfile.vim +++ b/runtime/autoload/spellfile.vim @@ -1,13 +1,9 @@ " Vim script to download a missing spell file if !exists('g:spellfile_URL') - " Prefer using http:// when netrw should be able to use it, since - " more firewalls let this through. - if executable("curl") || executable("wget") || executable("fetch") - let g:spellfile_URL = 'http://ftp.vim.org/pub/vim/runtime/spell' - else - let g:spellfile_URL = 'ftp://ftp.vim.org/pub/vim/runtime/spell' - endif + " Always use https:// because it's secure. The certificate is for nluug.nl, + " thus we can't use the alias ftp.vim.org here. + let g:spellfile_URL = 'https://ftp.nluug.nl/pub/vim/runtime/spell' endif let s:spellfile_URL = '' " Start with nothing so that s:donedict is reset. diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt index 0300ba55b3..44b611c2cf 100644 --- a/runtime/doc/lsp.txt +++ b/runtime/doc/lsp.txt @@ -23,14 +23,14 @@ QUICKSTART *lsp-quickstart* Nvim provides a LSP client, but the servers are provided by third parties. Follow these steps to get LSP features: - 1. Install the nvim-lsp plugin. It provides common configuration for + 1. Install the nvim-lspconfig plugin. It provides common configuration for various servers so you can get started quickly. - https://github.com/neovim/nvim-lsp + https://github.com/neovim/nvim-lspconfig 2. Install a language server. Try ":LspInstall <tab>" or use your system package manager to install the relevant language server: https://microsoft.github.io/language-server-protocol/implementors/servers/ 3. Add `nvim_lsp.xx.setup{…}` to your vimrc, where "xx" is the name of the - relevant config. See the nvim-lsp README for details. + relevant config. See the nvim-lspconfig README for details. To check LSP clients attached to the current buffer: > @@ -39,9 +39,10 @@ To check LSP clients attached to the current buffer: > *lsp-config* Inline diagnostics are enabled automatically, e.g. syntax errors will be annotated in the buffer. But you probably want to use other features like -go-to-definition, hover, etc. Example config: > +go-to-definition, hover, etc. Full list of features in |vim.lsp.buf|. + +Example config: > - nnoremap <silent> gd <cmd>lua vim.lsp.buf.declaration()<CR> nnoremap <silent> <c-]> <cmd>lua vim.lsp.buf.definition()<CR> nnoremap <silent> K <cmd>lua vim.lsp.buf.hover()<CR> nnoremap <silent> gD <cmd>lua vim.lsp.buf.implementation()<CR> @@ -50,6 +51,9 @@ go-to-definition, hover, etc. Example config: > nnoremap <silent> gr <cmd>lua vim.lsp.buf.references()<CR> nnoremap <silent> g0 <cmd>lua vim.lsp.buf.document_symbol()<CR> nnoremap <silent> gW <cmd>lua vim.lsp.buf.workspace_symbol()<CR> + nnoremap <silent> gd <cmd>lua vim.lsp.buf.declaration()<CR> + +Note: Language servers may have limited support for these features. Nvim provides the |vim.lsp.omnifunc| 'omnifunc' handler which allows |i_CTRL-X_CTRL-O| to consume LSP completion. Example config (note the use of diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt index 509ed7bf2c..2b638a8539 100644 --- a/runtime/doc/lua.txt +++ b/runtime/doc/lua.txt @@ -551,290 +551,6 @@ Example: TCP echo-server *tcp-server* print('TCP echo-server listening on port: '..server:getsockname().port) ------------------------------------------------------------------------------ -VIM.TREESITTER *lua-treesitter* - -Nvim integrates the tree-sitter library for incremental parsing of buffers. - -Currently Nvim does not provide the tree-sitter parsers, instead these must -be built separately, for instance using the tree-sitter utility. The only -exception is a C parser being included in official builds for testing -purposes. Parsers are searched for as `parser/{lang}.*` in any 'runtimepath' -directory. A parser can also be loaded manually using a full path: > - - vim.treesitter.require_language("python", "/path/to/python.so") - -<Create a parser for a buffer and a given language (if another plugin uses the -same buffer/language combination, it will be safely reused). Use > - - parser = vim.treesitter.get_parser(bufnr, lang) - -<`bufnr=0` can be used for current buffer. `lang` will default to 'filetype' (this -doesn't work yet for some filetypes like "cpp") Currently, the parser will be -retained for the lifetime of a buffer but this is subject to change. A plugin -should keep a reference to the parser object as long as it wants incremental -updates. - -Parser files *treesitter-parsers* - -Parsers are the heart of tree-sitter. They are libraries that tree-sitter will -search for in the `parsers` runtime directory. - -For a parser to be available for a given language, there must be a file named -`{lang}.so` within the parser directory. - -Parser methods *lua-treesitter-parser* - -tsparser:parse() *tsparser:parse()* -Whenever you need to access the current syntax tree, parse the buffer: > - - tstree = parser:parse() - -<This will return an immutable tree that represents the current state of the -buffer. When the plugin wants to access the state after a (possible) edit -it should call `parse()` again. If the buffer wasn't edited, the same tree will -be returned again without extra work. If the buffer was parsed before, -incremental parsing will be done of the changed parts. - -NB: to use the parser directly inside a |nvim_buf_attach| Lua callback, you must -call `get_parser()` before you register your callback. But preferably parsing -shouldn't be done directly in the change callback anyway as they will be very -frequent. Rather a plugin that does any kind of analysis on a tree should use -a timer to throttle too frequent updates. - -tsparser:set_included_ranges({ranges}) *tsparser:set_included_ranges()* - Changes the ranges the parser should consider. This is used for - language injection. {ranges} should be of the form (all zero-based): > - { - {start_node, end_node}, - ... - } -< - NOTE: `start_node` and `end_node` are both inclusive. - -Tree methods *lua-treesitter-tree* - -tstree:root() *tstree:root()* - Return the root node of this tree. - - -Node methods *lua-treesitter-node* - -tsnode:parent() *tsnode:parent()* - Get the node's immediate parent. - -tsnode:iter_children() *tsnode:iter_children()* - Iterates over all the direct children of {tsnode}, regardless of - wether they are named or not. - Returns the child node plus the eventual field name corresponding to - this child node. - -tsnode:field({name}) *tsnode:field()* - Returns a table of the nodes corresponding to the {name} field. - -tsnode:child_count() *tsnode:child_count()* - Get the node's number of children. - -tsnode:child({index}) *tsnode:child()* - Get the node's child at the given {index}, where zero represents the - first child. - -tsnode:named_child_count() *tsnode:named_child_count()* - Get the node's number of named children. - -tsnode:named_child({index}) *tsnode:named_child()* - Get the node's named child at the given {index}, where zero represents - the first named child. - -tsnode:start() *tsnode:start()* - Get the node's start position. Return three values: the row, column - and total byte count (all zero-based). - -tsnode:end_() *tsnode:end_()* - Get the node's end position. Return three values: the row, column - and total byte count (all zero-based). - -tsnode:range() *tsnode:range()* - Get the range of the node. Return four values: the row, column - of the start position, then the row, column of the end position. - -tsnode:type() *tsnode:type()* - Get the node's type as a string. - -tsnode:symbol() *tsnode:symbol()* - Get the node's type as a numerical id. - -tsnode:named() *tsnode:named()* - Check if the node is named. Named nodes correspond to named rules in - the grammar, whereas anonymous nodes correspond to string literals - in the grammar. - -tsnode:missing() *tsnode:missing()* - Check if the node is missing. Missing nodes are inserted by the - parser in order to recover from certain kinds of syntax errors. - -tsnode:has_error() *tsnode:has_error()* - Check if the node is a syntax error or contains any syntax errors. - -tsnode:sexpr() *tsnode:sexpr()* - Get an S-expression representing the node as a string. - -tsnode:descendant_for_range({start_row}, {start_col}, {end_row}, {end_col}) - *tsnode:descendant_for_range()* - Get the smallest node within this node that spans the given range of - (row, column) positions - -tsnode:named_descendant_for_range({start_row}, {start_col}, {end_row}, {end_col}) - *tsnode:named_descendant_for_range()* - Get the smallest named node within this node that spans the given - range of (row, column) positions - -Query methods *lua-treesitter-query* - -Tree-sitter queries are supported, with some limitations. Currently, the only -supported match predicate is `eq?` (both comparing a capture against a string -and two captures against each other). - -vim.treesitter.parse_query({lang}, {query}) - *vim.treesitter.parse_query()* - Parse {query} as a string. (If the query is in a file, the caller - should read the contents into a string before calling). - -query:iter_captures({node}, {bufnr}, {start_row}, {end_row}) - *query:iter_captures()* - Iterate over all captures from all matches inside {node}. - {bufnr} is needed if the query contains predicates, then the caller - must ensure to use a freshly parsed tree consistent with the current - text of the buffer. {start_row} and {end_row} can be used to limit - matches inside a row range (this is typically used with root node - as the node, i e to get syntax highlight matches in the current - viewport) - - The iterator returns two values, a numeric id identifying the capture - and the captured node. The following example shows how to get captures - by name: -> - for id, node in query:iter_captures(tree:root(), bufnr, first, last) do - local name = query.captures[id] -- name of the capture in the query - -- typically useful info about the node: - local type = node:type() -- type of the captured node - local row1, col1, row2, col2 = node:range() -- range of the capture - ... use the info here ... - end -< -query:iter_matches({node}, {bufnr}, {start_row}, {end_row}) - *query:iter_matches()* - Iterate over all matches within a node. The arguments are the same as - for |query:iter_captures()| but the iterated values are different: - an (1-based) index of the pattern in the query, and a table mapping - capture indices to nodes. If the query has more than one pattern - the capture table might be sparse, and e.g. `pairs` should be used and not - `ipairs`. Here an example iterating over all captures in - every match: -> - for pattern, match in cquery:iter_matches(tree:root(), bufnr, first, last) do - for id,node in pairs(match) do - local name = query.captures[id] - -- `node` was captured by the `name` capture in the match - ... use the info here ... - end - end - -Treesitter Query Predicates *lua-treesitter-predicates* - -When writing queries for treesitter, one might use `predicates`, that is, -special scheme nodes that are evaluted to verify things on a captured node for -example, the |eq?| predicate : > - ((identifier) @foo (#eq? @foo "foo")) - -This will only match identifier corresponding to the `"foo"` text. -Here is a list of built-in predicates : - - `eq?` *ts-predicate-eq?* - This predicate will check text correspondance between nodes or - strings : > - ((identifier) @foo (#eq? @foo "foo")) - ((node1) @left (node2) @right (#eq? @left @right)) -< - `match?` *ts-predicate-match?* - `vim-match?` *ts-predicate-vim-match?* - This will match if the provived vim regex matches the text - corresponding to a node : > - ((idenfitier) @constant (#match? @constant "^[A-Z_]+$")) -< Note: the `^` and `$` anchors will respectively match the - start and end of the node's text. - - `lua-match?` *ts-predicate-lua-match?* - This will match the same way than |match?| but using lua - regexes. - - `contains?` *ts-predicate-contains?* - Will check if any of the following arguments appears in the - text corresponding to the node : > - ((identifier) @foo (#contains? @foo "foo")) - ((identifier) @foo-bar (#contains @foo-bar "foo" "bar")) -< - *lua-treesitter-not-predicate* -Each predicate has a `not-` prefixed predicate that is just the negation of -the predicate. - - *vim.treesitter.query.add_predicate()* -vim.treesitter.query.add_predicate({name}, {handler}) - -This adds a predicate with the name {name} to be used in queries. -{handler} should be a function whose signature will be : > - handler(match, pattern, bufnr, predicate) -< - *vim.treesitter.query.list_predicates()* -vim.treesitter.query.list_predicates() - -This lists the currently available predicates to use in queries. - -Treesitter syntax highlighting (WIP) *lua-treesitter-highlight* - -NOTE: This is a partially implemented feature, and not usable as a default -solution yet. What is documented here is a temporary interface indented -for those who want to experiment with this feature and contribute to -its development. - -Highlights are defined in the same query format as in the tree-sitter highlight -crate, which some limitations and additions. Set a highlight query for a -buffer with this code: > - - local query = [[ - "for" @keyword - "if" @keyword - "return" @keyword - - (string_literal) @string - (number_literal) @number - (comment) @comment - - (preproc_function_def name: (identifier) @function) - - ; ... more definitions - ]] - - highlighter = vim.treesitter.TSHighlighter.new(query, bufnr, lang) - -- alternatively, to use the current buffer and its filetype: - -- highlighter = vim.treesitter.TSHighlighter.new(query) - - -- Don't recreate the highlighter for the same buffer, instead - -- modify the query like this: - local query2 = [[ ... ]] - highlighter:set_query(query2) - -As mentioned above the supported predicate is currently only `eq?`. `match?` -predicates behave like matching always fails. As an addition a capture which -begin with an upper-case letter like `@WarningMsg` will map directly to this -highlight group, if defined. Also if the predicate begins with upper-case and -contains a dot only the part before the first will be interpreted as the -highlight group. As an example, this warns of a binary expression with two -identical identifiers, highlighting both as |hl-WarningMsg|: > - - ((binary_expression left: (identifier) @WarningMsg.left right: (identifier) @WarningMsg.right) - (eq? @WarningMsg.left @WarningMsg.right)) - ------------------------------------------------------------------------------- VIM.HIGHLIGHT *lua-highlight* Nvim includes a function for highlighting a selection on yank (see for example @@ -1567,4 +1283,46 @@ validate({opt}) *vim.validate()* • msg: (optional) error string if validation fails + +============================================================================== +Lua module: uri *lua-uri* + +uri_from_bufnr({bufnr}) *vim.uri_from_bufnr()* + Get a URI from a bufnr + + Parameters: ~ + {bufnr} (number): Buffer number + + Return: ~ + URI + +uri_from_fname({path}) *vim.uri_from_fname()* + Get a URI from a file path. + + Parameters: ~ + {path} (string): Path to file + + Return: ~ + URI + +uri_to_bufnr({uri}) *vim.uri_to_bufnr()* + Return or create a buffer for a uri. + + Parameters: ~ + {uri} (string): The URI + + Return: ~ + bufnr. + Note: + Creates buffer but does not load it + +uri_to_fname({uri}) *vim.uri_to_fname()* + Get a filename from a URI + + Parameters: ~ + {uri} (string): The URI + + Return: ~ + Filename + vim:tw=78:ts=8:ft=help:norl: diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 190d6f9229..bd61d113fb 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -2738,21 +2738,26 @@ A jump table for the options with a short description can be found at |Q_op|. hor{N} horizontal bar, {N} percent of the character height ver{N} vertical bar, {N} percent of the character width block block cursor, fills the whole character - [only one of the above three should be present] + - Only one of the above three should be present. + - Default is "block" for each mode. blinkwait{N} *cursor-blinking* blinkon{N} blinkoff{N} blink times for cursor: blinkwait is the delay before the cursor starts blinking, blinkon is the time that the cursor is shown and blinkoff is the time that the - cursor is not shown. The times are in msec. When one - of the numbers is zero, there is no blinking. E.g.: > + cursor is not shown. Times are in msec. When one of + the numbers is zero, there is no blinking. E.g.: > :set guicursor=n:blinkon0 -< {group-name} - Highlight group name that sets the color and font for - the cursor. |inverse|/reverse and no group-name are - interpreted as "the host terminal default cursor - colors" which usually invert bg and fg colors. +< - Default is "blinkon0" for each mode. + {group-name} + Highlight group that decides the color and font of the + cursor. + In the |TUI|: + - |inverse|/reverse and no group-name are interpreted + as "host-terminal default cursor colors" which + typically means "inverted bg and fg colors". + - |ctermfg| and |guifg| are ignored. {group-name}/{group-name} Two highlight group names, the first is used when no language mappings are used, the other when they @@ -5667,6 +5672,14 @@ A jump table for the options with a short description can be found at |Q_op|. up to the first character that is not an ASCII letter or number and not a dash. Also see |set-spc-auto|. + *'spelloptions'* *'spo'* +'spelloptions' 'spo' string (default "") + local to buffer + A comma separated list of options for spell checking: + camel When a word is CamelCased, assume "Cased" is a + separate word: every upper-case character in a word + that comes after a lower case character indicates the + start of a new word. *'spellsuggest'* *'sps'* 'spellsuggest' 'sps' string (default "best") diff --git a/runtime/doc/quickfix.txt b/runtime/doc/quickfix.txt index 61e090cc78..188cfc91b6 100644 --- a/runtime/doc/quickfix.txt +++ b/runtime/doc/quickfix.txt @@ -501,6 +501,29 @@ EXECUTE A COMMAND IN ALL THE BUFFERS IN QUICKFIX OR LOCATION LIST: < Otherwise it works the same as `:ldo`. {not in Vi} +FILTERING A QUICKFIX OR LOCATION LIST: + *cfilter-plugin* *:Cfilter* *:Lfilter* +If you have too many entries in a quickfix list, you can use the cfilter +plugin to reduce the number of entries. Load the plugin with: > + + packadd cfilter + +Then you can use the following commands to filter a quickfix/location list: > + + :Cfilter[!] /{pat}/ + :Lfilter[!] /{pat}/ + +The |:Cfilter| command creates a new quickfix list from the entries matching +{pat} in the current quickfix list. {pat} is a Vim |regular-expression| +pattern. Both the file name and the text of the entries are matched against +{pat}. If the optional ! is supplied, then the entries not matching {pat} are +used. The pattern can be optionally enclosed using one of the following +characters: ', ", /. If the pattern is empty, then the last used search +pattern is used. + +The |:Lfilter| command does the same as |:Cfilter| but operates on the current +location list. + ============================================================================= 2. The error window *quickfix-window* @@ -1563,22 +1586,6 @@ The backslashes before the pipe character are required to avoid it to be recognized as a command separator. The backslash before each space is required for the set command. - *cfilter-plugin* *:Cfilter* *:Lfilter* -If you have too many matching messages, you can use the cfilter plugin to -reduce the number of entries. Load the plugin with: > - packadd cfilter - -Then you can use these command: > - :Cfilter[!] /{pat}/ - :Lfilter[!] /{pat}/ - -:Cfilter creates a new quickfix list from entries matching {pat} in the -current quickfix list. Both the file name and the text of the entries are -matched against {pat}. If ! is supplied, then entries not matching {pat} are -used. - -:Lfilter does the same as :Cfilter but operates on the current location list. - ============================================================================= 8. The directory stack *quickfix-directory-stack* diff --git a/runtime/doc/spell.txt b/runtime/doc/spell.txt index b88e26cdff..0eef976819 100644 --- a/runtime/doc/spell.txt +++ b/runtime/doc/spell.txt @@ -187,6 +187,9 @@ When there is a line break right after a sentence the highlighting of the next line may be postponed. Use |CTRL-L| when needed. Also see |set-spc-auto| for how it can be set automatically when 'spelllang' is set. +The 'spelloptions' option has a few more flags that influence the way spell +checking works. + Vim counts the number of times a good word is encountered. This is used to sort the suggestions: words that have been seen before get a small bonus, words that have been seen often get a bigger bonus. The COMMON item in the @@ -617,11 +620,12 @@ ask you where to write the file (there must be a writable directory in 'runtimepath' for this). The plugin has a default place where to look for spell files, on the Vim ftp -server. If you want to use another location or another protocol, set the -g:spellfile_URL variable to the directory that holds the spell files. The -|netrw| plugin is used for getting the file, look there for the specific -syntax of the URL. Example: > - let g:spellfile_URL = 'http://ftp.vim.org/vim/runtime/spell' +server. The protocol used is SSL (https://) for security. If you want to use +another location or another protocol, set the g:spellfile_URL variable to the +directory that holds the spell files. You can use http:// or ftp://, but you +are taking a security risk then. The |netrw| plugin is used for getting the +file, look there for the specific syntax of the URL. Example: > + let g:spellfile_URL = 'https://ftp.nluug.nl/vim/runtime/spell' You may need to escape special characters. The plugin will only ask about downloading a language once. If you want to diff --git a/runtime/doc/treesitter.txt b/runtime/doc/treesitter.txt new file mode 100644 index 0000000000..7f644486f7 --- /dev/null +++ b/runtime/doc/treesitter.txt @@ -0,0 +1,295 @@ +*treesitter.txt* Nvim + + + NVIM REFERENCE MANUAL + + +Tree-sitter integration *treesitter* + + Type |gO| to see the table of contents. + +------------------------------------------------------------------------------ +VIM.TREESITTER *lua-treesitter* + +Nvim integrates the tree-sitter library for incremental parsing of buffers. + +Currently Nvim does not provide the tree-sitter parsers, instead these must +be built separately, for instance using the tree-sitter utility. The only +exception is a C parser being included in official builds for testing +purposes. Parsers are searched for as `parser/{lang}.*` in any 'runtimepath' +directory. A parser can also be loaded manually using a full path: > + + vim.treesitter.require_language("python", "/path/to/python.so") + +<Create a parser for a buffer and a given language (if another plugin uses the +same buffer/language combination, it will be safely reused). Use > + + parser = vim.treesitter.get_parser(bufnr, lang) + +<`bufnr=0` can be used for current buffer. `lang` will default to 'filetype' (this +doesn't work yet for some filetypes like "cpp") Currently, the parser will be +retained for the lifetime of a buffer but this is subject to change. A plugin +should keep a reference to the parser object as long as it wants incremental +updates. + +Parser files *treesitter-parsers* + +Parsers are the heart of tree-sitter. They are libraries that tree-sitter will +search for in the `parser` runtime directory. + +For a parser to be available for a given language, there must be a file named +`{lang}.so` within the parser directory. + +Parser methods *lua-treesitter-parser* + +tsparser:parse() *tsparser:parse()* +Whenever you need to access the current syntax tree, parse the buffer: > + + tstree = parser:parse() + +<This will return an immutable tree that represents the current state of the +buffer. When the plugin wants to access the state after a (possible) edit +it should call `parse()` again. If the buffer wasn't edited, the same tree will +be returned again without extra work. If the buffer was parsed before, +incremental parsing will be done of the changed parts. + +NB: to use the parser directly inside a |nvim_buf_attach| Lua callback, you must +call `get_parser()` before you register your callback. But preferably parsing +shouldn't be done directly in the change callback anyway as they will be very +frequent. Rather a plugin that does any kind of analysis on a tree should use +a timer to throttle too frequent updates. + +tsparser:set_included_ranges({ranges}) *tsparser:set_included_ranges()* + Changes the ranges the parser should consider. This is used for + language injection. {ranges} should be of the form (all zero-based): > + { + {start_node, end_node}, + ... + } +< + NOTE: `start_node` and `end_node` are both inclusive. + +Tree methods *lua-treesitter-tree* + +tstree:root() *tstree:root()* + Return the root node of this tree. + + +Node methods *lua-treesitter-node* + +tsnode:parent() *tsnode:parent()* + Get the node's immediate parent. + +tsnode:iter_children() *tsnode:iter_children()* + Iterates over all the direct children of {tsnode}, regardless of + wether they are named or not. + Returns the child node plus the eventual field name corresponding to + this child node. + +tsnode:field({name}) *tsnode:field()* + Returns a table of the nodes corresponding to the {name} field. + +tsnode:child_count() *tsnode:child_count()* + Get the node's number of children. + +tsnode:child({index}) *tsnode:child()* + Get the node's child at the given {index}, where zero represents the + first child. + +tsnode:named_child_count() *tsnode:named_child_count()* + Get the node's number of named children. + +tsnode:named_child({index}) *tsnode:named_child()* + Get the node's named child at the given {index}, where zero represents + the first named child. + +tsnode:start() *tsnode:start()* + Get the node's start position. Return three values: the row, column + and total byte count (all zero-based). + +tsnode:end_() *tsnode:end_()* + Get the node's end position. Return three values: the row, column + and total byte count (all zero-based). + +tsnode:range() *tsnode:range()* + Get the range of the node. Return four values: the row, column + of the start position, then the row, column of the end position. + +tsnode:type() *tsnode:type()* + Get the node's type as a string. + +tsnode:symbol() *tsnode:symbol()* + Get the node's type as a numerical id. + +tsnode:named() *tsnode:named()* + Check if the node is named. Named nodes correspond to named rules in + the grammar, whereas anonymous nodes correspond to string literals + in the grammar. + +tsnode:missing() *tsnode:missing()* + Check if the node is missing. Missing nodes are inserted by the + parser in order to recover from certain kinds of syntax errors. + +tsnode:has_error() *tsnode:has_error()* + Check if the node is a syntax error or contains any syntax errors. + +tsnode:sexpr() *tsnode:sexpr()* + Get an S-expression representing the node as a string. + +tsnode:descendant_for_range({start_row}, {start_col}, {end_row}, {end_col}) + *tsnode:descendant_for_range()* + Get the smallest node within this node that spans the given range of + (row, column) positions + +tsnode:named_descendant_for_range({start_row}, {start_col}, {end_row}, {end_col}) + *tsnode:named_descendant_for_range()* + Get the smallest named node within this node that spans the given + range of (row, column) positions + +Query methods *lua-treesitter-query* + +Tree-sitter queries are supported, with some limitations. Currently, the only +supported match predicate is `eq?` (both comparing a capture against a string +and two captures against each other). + +vim.treesitter.parse_query({lang}, {query}) + *vim.treesitter.parse_query()* + Parse {query} as a string. (If the query is in a file, the caller + should read the contents into a string before calling). + +query:iter_captures({node}, {bufnr}, {start_row}, {end_row}) + *query:iter_captures()* + Iterate over all captures from all matches inside {node}. + {bufnr} is needed if the query contains predicates, then the caller + must ensure to use a freshly parsed tree consistent with the current + text of the buffer. {start_row} and {end_row} can be used to limit + matches inside a row range (this is typically used with root node + as the node, i e to get syntax highlight matches in the current + viewport) + + The iterator returns two values, a numeric id identifying the capture + and the captured node. The following example shows how to get captures + by name: +> + for id, node in query:iter_captures(tree:root(), bufnr, first, last) do + local name = query.captures[id] -- name of the capture in the query + -- typically useful info about the node: + local type = node:type() -- type of the captured node + local row1, col1, row2, col2 = node:range() -- range of the capture + ... use the info here ... + end +< +query:iter_matches({node}, {bufnr}, {start_row}, {end_row}) + *query:iter_matches()* + Iterate over all matches within a node. The arguments are the same as + for |query:iter_captures()| but the iterated values are different: + an (1-based) index of the pattern in the query, and a table mapping + capture indices to nodes. If the query has more than one pattern + the capture table might be sparse, and e.g. `pairs` should be used and not + `ipairs`. Here an example iterating over all captures in + every match: +> + for pattern, match in cquery:iter_matches(tree:root(), bufnr, first, last) do + for id,node in pairs(match) do + local name = query.captures[id] + -- `node` was captured by the `name` capture in the match + ... use the info here ... + end + end + +Treesitter Query Predicates *lua-treesitter-predicates* + +When writing queries for treesitter, one might use `predicates`, that is, +special scheme nodes that are evaluted to verify things on a captured node for +example, the |eq?| predicate : > + ((identifier) @foo (#eq? @foo "foo")) + +This will only match identifier corresponding to the `"foo"` text. +Here is a list of built-in predicates : + + `eq?` *ts-predicate-eq?* + This predicate will check text correspondance between nodes or + strings : > + ((identifier) @foo (#eq? @foo "foo")) + ((node1) @left (node2) @right (#eq? @left @right)) +< + `match?` *ts-predicate-match?* + `vim-match?` *ts-predicate-vim-match?* + This will match if the provived vim regex matches the text + corresponding to a node : > + ((idenfitier) @constant (#match? @constant "^[A-Z_]+$")) +< Note: the `^` and `$` anchors will respectively match the + start and end of the node's text. + + `lua-match?` *ts-predicate-lua-match?* + This will match the same way than |match?| but using lua + regexes. + + `contains?` *ts-predicate-contains?* + Will check if any of the following arguments appears in the + text corresponding to the node : > + ((identifier) @foo (#contains? @foo "foo")) + ((identifier) @foo-bar (#contains @foo-bar "foo" "bar")) +< + *lua-treesitter-not-predicate* +Each predicate has a `not-` prefixed predicate that is just the negation of +the predicate. + + *vim.treesitter.query.add_predicate()* +vim.treesitter.query.add_predicate({name}, {handler}) + +This adds a predicate with the name {name} to be used in queries. +{handler} should be a function whose signature will be : > + handler(match, pattern, bufnr, predicate) +< + *vim.treesitter.query.list_predicates()* +vim.treesitter.query.list_predicates() + +This lists the currently available predicates to use in queries. + +Treesitter syntax highlighting (WIP) *lua-treesitter-highlight* + +NOTE: This is a partially implemented feature, and not usable as a default +solution yet. What is documented here is a temporary interface indented +for those who want to experiment with this feature and contribute to +its development. + +Highlights are defined in the same query format as in the tree-sitter highlight +crate, which some limitations and additions. Set a highlight query for a +buffer with this code: > + + local query = [[ + "for" @keyword + "if" @keyword + "return" @keyword + + (string_literal) @string + (number_literal) @number + (comment) @comment + + (preproc_function_def name: (identifier) @function) + + ; ... more definitions + ]] + + highlighter = vim.treesitter.TSHighlighter.new(query, bufnr, lang) + -- alternatively, to use the current buffer and its filetype: + -- highlighter = vim.treesitter.TSHighlighter.new(query) + + -- Don't recreate the highlighter for the same buffer, instead + -- modify the query like this: + local query2 = [[ ... ]] + highlighter:set_query(query2) + +As mentioned above the supported predicate is currently only `eq?`. `match?` +predicates behave like matching always fails. As an addition a capture which +begin with an upper-case letter like `@WarningMsg` will map directly to this +highlight group, if defined. Also if the predicate begins with upper-case and +contains a dot only the part before the first will be interpreted as the +highlight group. As an example, this warns of a binary expression with two +identical identifiers, highlighting both as |hl-WarningMsg|: > + + ((binary_expression left: (identifier) @WarningMsg.left right: (identifier) @WarningMsg.right) + (eq? @WarningMsg.left @WarningMsg.right)) + + vim:tw=78:ts=8:ft=help:norl: diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index 4bcea3e3fe..3090be82f2 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -508,7 +508,6 @@ Test functions: test_alloc_fail() test_autochdir() test_disable_char_avail() - test_garbagecollect_now() test_null_channel() test_null_dict() test_null_job() diff --git a/runtime/filetype.vim b/runtime/filetype.vim index 32bd6daba0..c464e8cebd 100644 --- a/runtime/filetype.vim +++ b/runtime/filetype.vim @@ -1158,10 +1158,10 @@ au BufNewFile,BufRead *.papp,*.pxml,*.pxsl setf papp au BufNewFile,BufRead */etc/passwd,*/etc/passwd-,*/etc/passwd.edit,*/etc/shadow,*/etc/shadow-,*/etc/shadow.edit,*/var/backups/passwd.bak,*/var/backups/shadow.bak setf passwd " Pascal (also *.p) -au BufNewFile,BufRead *.pas setf pascal +au BufNewFile,BufRead *.pas,*.pp setf pascal -" Delphi project file -au BufNewFile,BufRead *.dpr setf pascal +" Delphi or Lazarus program file +au BufNewFile,BufRead *.dpr,*.lpr setf pascal " PDF au BufNewFile,BufRead *.pdf setf pdf @@ -1732,7 +1732,7 @@ au BufNewFile,BufRead *.texinfo,*.texi,*.txi setf texinfo au BufNewFile,BufRead texmf.cnf setf texmf " Tidy config -au BufNewFile,BufRead .tidyrc,tidyrc setf tidy +au BufNewFile,BufRead .tidyrc,tidyrc,tidy.conf setf tidy " TF mud client au BufNewFile,BufRead *.tf,.tfrc,tfrc setf tf diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua index 208082f241..c015884f5b 100644 --- a/runtime/lua/vim/lsp/buf.lua +++ b/runtime/lua/vim/lsp/buf.lua @@ -1,9 +1,7 @@ local vim = vim local validate = vim.validate -local api = vim.api local vfn = vim.fn local util = require 'vim.lsp.util' -local list_extend = vim.list_extend local M = {} @@ -142,6 +140,7 @@ function M.formatting_sync(options, timeout_ms) local result = vim.lsp.buf_request_sync(0, "textDocument/formatting", params, timeout_ms) if not result then return end result = result[1].result + if not result then return end vim.lsp.util.apply_text_edits(result) end @@ -153,36 +152,14 @@ end --@param start_pos ({number, number}, optional) mark-indexed position. ---Defaults to the end of the last visual selection. function M.range_formatting(options, start_pos, end_pos) - validate { - options = {options, 't', true}; - start_pos = {start_pos, 't', true}; - end_pos = {end_pos, 't', true}; - } + validate { options = {options, 't', true} } local sts = vim.bo.softtabstop; options = vim.tbl_extend('keep', options or {}, { tabSize = (sts > 0 and sts) or (sts < 0 and vim.bo.shiftwidth) or vim.bo.tabstop; insertSpaces = vim.bo.expandtab; }) - local A = list_extend({}, start_pos or api.nvim_buf_get_mark(0, '<')) - local B = list_extend({}, end_pos or api.nvim_buf_get_mark(0, '>')) - -- convert to 0-index - A[1] = A[1] - 1 - B[1] = B[1] - 1 - -- account for encoding. - if A[2] > 0 then - A = {A[1], util.character_offset(0, A[1], A[2])} - end - if B[2] > 0 then - B = {B[1], util.character_offset(0, B[1], B[2])} - end - local params = { - textDocument = { uri = vim.uri_from_bufnr(0) }; - range = { - start = { line = A[1]; character = A[2]; }; - ["end"] = { line = B[1]; character = B[2]; }; - }; - options = options; - } + local params = util.make_given_range_params(start_pos, end_pos) + params.options = options return request('textDocument/rangeFormatting', params) end @@ -307,6 +284,21 @@ function M.code_action(context) request('textDocument/codeAction', params) end +--- Performs |vim.lsp.buf.code_action()| for a given range. +--- +--@param context: (table, optional) Valid `CodeActionContext` object +--@param start_pos ({number, number}, optional) mark-indexed position. +---Defaults to the start of the last visual selection. +--@param end_pos ({number, number}, optional) mark-indexed position. +---Defaults to the end of the last visual selection. +function M.range_code_action(context, start_pos, end_pos) + validate { context = { context, 't', true } } + context = context or { diagnostics = util.get_line_diagnostics() } + local params = util.make_given_range_params(start_pos, end_pos) + params.context = context + request('textDocument/codeAction', params) +end + --- Executes an LSP server command. --- --@param command A valid `ExecuteCommandParams` object diff --git a/runtime/lua/vim/lsp/callbacks.lua b/runtime/lua/vim/lsp/callbacks.lua index 0ee03e6a2f..4e7a8333a0 100644 --- a/runtime/lua/vim/lsp/callbacks.lua +++ b/runtime/lua/vim/lsp/callbacks.lua @@ -229,16 +229,19 @@ M['textDocument/implementation'] = location_callback --@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_signatureHelp M['textDocument/signatureHelp'] = function(_, method, result) + -- When use `autocmd CompleteDone <silent><buffer> lua vim.lsp.buf.signature_help()` to call signatureHelp callback + -- If the completion item doesn't have signatures It will make noise. Change to use `print` that can use `<silent>` to ignore + if not (result and result.signatures and result.signatures[1]) then + print('No signature help available') + return + end + local lines = util.convert_signature_help_to_markdown_lines(result) + lines = util.trim_empty_lines(lines) + if vim.tbl_isempty(lines) then + print('No signature help available') + return + end util.focusable_preview(method, function() - if not (result and result.signatures and result.signatures[1]) then - return { 'No signature available' } - end - -- TODO show popup when signatures is empty? - local lines = util.convert_signature_help_to_markdown_lines(result) - lines = util.trim_empty_lines(lines) - if vim.tbl_isempty(lines) then - return { 'No signature available' } - end return lines, util.try_trim_markdown_code_blocks(lines) end) end diff --git a/runtime/lua/vim/lsp/rpc.lua b/runtime/lua/vim/lsp/rpc.lua index 64080cf4f2..749a51fecc 100644 --- a/runtime/lua/vim/lsp/rpc.lua +++ b/runtime/lua/vim/lsp/rpc.lua @@ -494,10 +494,13 @@ local function start(cmd, cmd_args, handlers, extra_spawn_params) decoded.error = convert_NIL(decoded.error) decoded.result = convert_NIL(decoded.result) - -- Do not surface RequestCancelled to users, it is RPC-internal. - if decoded.error - and decoded.error.code == protocol.ErrorCodes.RequestCancelled then - local _ = log.debug() and log.debug("Received cancellation ack", decoded) + -- Do not surface RequestCancelled or ContentModified to users, it is RPC-internal. + if decoded.error then + if decoded.error.code == protocol.ErrorCodes.RequestCancelled then + local _ = log.debug() and log.debug("Received cancellation ack", decoded) + elseif decoded.error.code == protocol.ErrorCodes.ContentModified then + local _ = log.debug() and log.debug("Received content modified ack", decoded) + end local result_id = tonumber(decoded.id) -- Clear any callback since this is cancelled now. -- This is safe to do assuming that these conditions hold: diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index 24cb454e5b..d94a8bb774 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -505,13 +505,13 @@ function M.convert_signature_help_to_markdown_lines(signature_help) if signature.documentation then M.convert_input_to_markdown_lines(signature.documentation, contents) end - if signature_help.parameters then + if signature.parameters and #signature.parameters > 0 then local active_parameter = signature_help.activeParameter or 0 -- If the activeParameter is not inside the valid range, then clip it. - if active_parameter >= #signature_help.parameters then + if active_parameter >= #signature.parameters then active_parameter = 0 end - local parameter = signature.parameters and signature.parameters[active_parameter] + local parameter = signature.parameters[active_parameter + 1] if parameter then --[=[ --Represents a parameter of a callable-signature. A parameter can @@ -532,8 +532,8 @@ function M.convert_signature_help_to_markdown_lines(signature_help) } --]=] -- TODO highlight parameter - if parameter.documentation then - M.convert_input_help_to_markdown_lines(parameter.documentation, contents) + if parameter.documentation and parameter.documentation ~= vim.NIL then + M.convert_input_to_markdown_lines(parameter.documentation, contents) end end end @@ -668,7 +668,7 @@ function M.focusable_float(unique_name, fn) local bufnr = api.nvim_get_current_buf() do local win = find_window_by_var(unique_name, bufnr) - if win then + if win and api.nvim_win_is_valid(win) and not vim.fn.pumvisible() then api.nvim_set_current_win(win) api.nvim_command("stopinsert") return @@ -1465,11 +1465,46 @@ end function M.make_range_params() local position = make_position_param() return { - textDocument = { uri = vim.uri_from_bufnr(0) }, + textDocument = M.make_text_document_params(), range = { start = position; ["end"] = position; } } end +--- Using the given range in the current buffer, creates an object that +--- is similar to |vim.lsp.util.make_range_params()|. +--- +--@param start_pos ({number, number}, optional) mark-indexed position. +---Defaults to the start of the last visual selection. +--@param end_pos ({number, number}, optional) mark-indexed position. +---Defaults to the end of the last visual selection. +--@returns { textDocument = { uri = `current_file_uri` }, range = { start = +---`start_position`, end = `end_position` } } +function M.make_given_range_params(start_pos, end_pos) + validate { + start_pos = {start_pos, 't', true}; + end_pos = {end_pos, 't', true}; + } + local A = list_extend({}, start_pos or api.nvim_buf_get_mark(0, '<')) + local B = list_extend({}, end_pos or api.nvim_buf_get_mark(0, '>')) + -- convert to 0-index + A[1] = A[1] - 1 + B[1] = B[1] - 1 + -- account for encoding. + if A[2] > 0 then + A = {A[1], M.character_offset(0, A[1], A[2])} + end + if B[2] > 0 then + B = {B[1], M.character_offset(0, B[1], B[2])} + end + return { + textDocument = M.make_text_document_params(), + range = { + start = {line = A[1], character = A[2]}, + ['end'] = {line = B[1], character = B[2]} + } + } +end + --- Creates a `TextDocumentIdentifier` object for the current buffer. --- --@returns `TextDocumentIdentifier` diff --git a/runtime/lua/vim/treesitter/highlighter.lua b/runtime/lua/vim/treesitter/highlighter.lua index 718088e0ad..5b964a6020 100644 --- a/runtime/lua/vim/treesitter/highlighter.lua +++ b/runtime/lua/vim/treesitter/highlighter.lua @@ -3,7 +3,8 @@ local a = vim.api -- support reload for quick experimentation local TSHighlighter = rawget(vim.treesitter, 'TSHighlighter') or {} TSHighlighter.__index = TSHighlighter -local ts_hs_ns = a.nvim_create_namespace("treesitter_hl") + +TSHighlighter.active = TSHighlighter.active or {} -- These are conventions defined by tree-sitter, though it -- needs to be user extensible also. @@ -54,13 +55,16 @@ TSHighlighter.hl_map = { } function TSHighlighter.new(query, bufnr, ft) + if bufnr == nil or bufnr == 0 then + bufnr = a.nvim_get_current_buf() + end + local self = setmetatable({}, TSHighlighter) self.parser = vim.treesitter.get_parser( bufnr, ft, { on_changedtree = function(...) self:on_changedtree(...) end, - on_bytes = function() self.parser:parse() end } ) @@ -69,8 +73,12 @@ function TSHighlighter.new(query, bufnr, ft) self.edit_count = 0 self.redraw_count = 0 self.line_count = {} + self.root = self.parser:parse():root() a.nvim_buf_set_option(self.buf, "syntax", "") + -- TODO(bfredl): can has multiple highlighters per buffer???? + TSHighlighter.active[bufnr] = self + -- Tricky: if syntax hasn't been enabled, we need to reload color scheme -- but use synload.vim rather than syntax.vim to not enable -- syntax FileType autocmds. Later on we should integrate with the @@ -100,6 +108,12 @@ function TSHighlighter:get_hl_from_capture(capture) end end +function TSHighlighter:on_changedtree(changes) + for _, ch in ipairs(changes or {}) do + a.nvim__buf_redraw_range(self.buf, ch[1], ch[3]+1) + end +end + function TSHighlighter:set_query(query) if type(query) == "string" then query = vim.treesitter.parse_query(self.parser.lang, query) @@ -123,28 +137,60 @@ function TSHighlighter:set_query(query) end }) - self:on_changedtree({{self.parser:parse():root():range()}}) + a.nvim__buf_redraw_range(self.buf, 0, a.nvim_buf_line_count(self.buf)) end -function TSHighlighter:on_changedtree(changes) - -- Get a fresh root - local root = self.parser:parse():root() +function TSHighlighter._on_line(_, _win, buf, line) + -- on_line is only called when this is non-nil + local self = TSHighlighter.active[buf] + if self.root == nil then + return -- parser bought the farm already + end - for _, ch in ipairs(changes or {}) do - a.nvim_buf_clear_namespace(self.buf, ts_hs_ns, ch[1], ch[3]+1) - - for capture, node in self.query:iter_captures(root, self.buf, ch[1], ch[3] + 1) do - local start_row, start_col, end_row, end_col = node:range() - local hl = self.hl_cache[capture] - if hl then - a.nvim_buf_set_extmark(self.buf, ts_hs_ns, start_row, start_col, { - end_col = end_col, - end_line = end_row, - hl_group = hl - }) - end + if self.iter == nil then + self.iter = self.query:iter_captures(self.root,buf,line,self.botline) + end + while line >= self.nextrow do + local capture, node = self.iter() + if capture == nil then + break + end + local start_row, start_col, end_row, end_col = node:range() + local hl = self.hl_cache[capture] + if hl and end_row >= line then + a.nvim__put_attr(start_row, start_col, { end_line = end_row, end_col = end_col, hl_group = hl }) + end + if start_row > line then + self.nextrow = start_row end end end +function TSHighlighter._on_start(_, buf, _tick) + local self = TSHighlighter.active[buf] + if self then + local tree = self.parser:parse() + self.root = (tree and tree:root()) or nil + end +end + +function TSHighlighter._on_win(_, _win, buf, _topline, botline) + local self = TSHighlighter.active[buf] + if not self then + return false + end + + self.iter = nil + self.nextrow = 0 + self.botline = botline + self.redraw_count = self.redraw_count + 1 + return true +end + +a.nvim__set_luahl { + on_start = TSHighlighter._on_start; + on_win = TSHighlighter._on_win; + on_line = TSHighlighter._on_line; +} + return TSHighlighter diff --git a/runtime/lua/vim/uri.lua b/runtime/lua/vim/uri.lua index 9c3535c676..f1a12c72ec 100644 --- a/runtime/lua/vim/uri.lua +++ b/runtime/lua/vim/uri.lua @@ -7,6 +7,9 @@ local uri_decode do local schar = string.char + + --- Convert hex to char + --@private local function hex_to_char(hex) return schar(tonumber(hex, 16)) end @@ -34,6 +37,8 @@ do else tohex = function(b) return string.format("%02x", b) end end + + --@private local function percent_encode_char(char) return "%"..tohex(sbyte(char), 2) end @@ -45,10 +50,14 @@ do end +--@private local function is_windows_file_uri(uri) return uri:match('^file:///[a-zA-Z]:') ~= nil end +--- Get a URI from a file path. +--@param path (string): Path to file +--@return URI local function uri_from_fname(path) local volume_path, fname = path:match("^([a-zA-Z]:)(.*)") local is_windows = volume_path ~= nil @@ -67,6 +76,9 @@ end local URI_SCHEME_PATTERN = '^([a-zA-Z]+[a-zA-Z0-9+-.]*)://.*' +--- Get a URI from a bufnr +--@param bufnr (number): Buffer number +--@return URI local function uri_from_bufnr(bufnr) local fname = vim.api.nvim_buf_get_name(bufnr) local scheme = fname:match(URI_SCHEME_PATTERN) @@ -77,6 +89,9 @@ local function uri_from_bufnr(bufnr) end end +--- Get a filename from a URI +--@param uri (string): The URI +--@return Filename local function uri_to_fname(uri) local scheme = assert(uri:match(URI_SCHEME_PATTERN), 'URI must contain a scheme: ' .. uri) if scheme ~= 'file' then @@ -93,7 +108,10 @@ local function uri_to_fname(uri) return uri end --- Return or create a buffer for a uri. +--- Return or create a buffer for a uri. +--@param uri (string): The URI +--@return bufnr. +--@note Creates buffer but does not load it local function uri_to_bufnr(uri) local scheme = assert(uri:match(URI_SCHEME_PATTERN), 'URI must contain a scheme: ' .. uri) if scheme == 'file' then diff --git a/runtime/pack/dist/opt/cfilter/plugin/cfilter.vim b/runtime/pack/dist/opt/cfilter/plugin/cfilter.vim index 7a6464fc98..fe4455fe2e 100644 --- a/runtime/pack/dist/opt/cfilter/plugin/cfilter.vim +++ b/runtime/pack/dist/opt/cfilter/plugin/cfilter.vim @@ -1,15 +1,17 @@ " cfilter.vim: Plugin to filter entries from a quickfix/location list -" Last Change: May 12, 2018 -" Maintainer: Yegappan Lakshmanan (yegappan AT yahoo DOT com) -" Version: 1.0 +" Last Change: Aug 23, 2018 +" Maintainer: Yegappan Lakshmanan (yegappan AT yahoo DOT com) +" Version: 1.1 " " Commands to filter the quickfix list: -" :Cfilter[!] {pat} +" :Cfilter[!] /{pat}/ " Create a new quickfix list from entries matching {pat} in the current " quickfix list. Both the file name and the text of the entries are " matched against {pat}. If ! is supplied, then entries not matching -" {pat} are used. -" :Lfilter[!] {pat} +" {pat} are used. The pattern can be optionally enclosed using one of +" the following characters: ', ", /. If the pattern is empty, then the +" last used search pattern is used. +" :Lfilter[!] /{pat}/ " Same as :Cfilter but operates on the current location list. " if exists("loaded_cfilter") @@ -17,7 +19,7 @@ if exists("loaded_cfilter") endif let loaded_cfilter = 1 -func s:Qf_filter(qf, pat, bang) +func s:Qf_filter(qf, searchpat, bang) if a:qf let Xgetlist = function('getqflist') let Xsetlist = function('setqflist') @@ -28,14 +30,31 @@ func s:Qf_filter(qf, pat, bang) let cmd = ':Lfilter' . a:bang endif + let firstchar = a:searchpat[0] + let lastchar = a:searchpat[-1:] + if firstchar == lastchar && + \ (firstchar == '/' || firstchar == '"' || firstchar == "'") + let pat = a:searchpat[1:-2] + if pat == '' + " Use the last search pattern + let pat = @/ + endif + else + let pat = a:searchpat + endif + + if pat == '' + return + endif + if a:bang == '!' - let cond = 'v:val.text !~# a:pat && bufname(v:val.bufnr) !~# a:pat' + let cond = 'v:val.text !~# pat && bufname(v:val.bufnr) !~# pat' else - let cond = 'v:val.text =~# a:pat || bufname(v:val.bufnr) =~# a:pat' + let cond = 'v:val.text =~# pat || bufname(v:val.bufnr) =~# pat' endif let items = filter(Xgetlist(), cond) - let title = cmd . ' ' . a:pat + let title = cmd . ' /' . pat . '/' call Xsetlist([], ' ', {'title' : title, 'items' : items}) endfunc diff --git a/scripts/gen_vimdoc.py b/scripts/gen_vimdoc.py index f754452c02..c42b568220 100755 --- a/scripts/gen_vimdoc.py +++ b/scripts/gen_vimdoc.py @@ -113,10 +113,12 @@ CONFIG = { 'section_order': [ 'vim.lua', 'shared.lua', + 'uri.lua', ], 'files': ' '.join([ os.path.join(base_dir, 'src/nvim/lua/vim.lua'), os.path.join(base_dir, 'runtime/lua/vim/shared.lua'), + os.path.join(base_dir, 'runtime/lua/vim/uri.lua'), ]), 'file_patterns': '*.lua', 'fn_name_prefix': '', @@ -129,6 +131,7 @@ CONFIG = { 'module_override': { # `shared` functions are exposed on the `vim` module. 'shared': 'vim', + 'uri': 'vim', }, 'append_only': [ 'shared.lua', diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 15065760b3..e77870dcf3 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -244,78 +244,6 @@ Boolean nvim_buf_detach(uint64_t channel_id, return true; } -static void buf_clear_luahl(buf_T *buf, bool force) -{ - if (buf->b_luahl || force) { - api_free_luaref(buf->b_luahl_start); - api_free_luaref(buf->b_luahl_window); - api_free_luaref(buf->b_luahl_line); - api_free_luaref(buf->b_luahl_end); - } - buf->b_luahl_start = LUA_NOREF; - buf->b_luahl_window = LUA_NOREF; - buf->b_luahl_line = LUA_NOREF; - buf->b_luahl_end = LUA_NOREF; -} - -/// Unstabilized interface for defining syntax hl in lua. -/// -/// This is not yet safe for general use, lua callbacks will need to -/// be restricted, like textlock and probably other stuff. -/// -/// The API on_line/nvim__put_attr is quite raw and not intended to be the -/// final shape. Ideally this should operate on chunks larger than a single -/// line to reduce interpreter overhead, and generate annotation objects -/// (bufhl/virttext) on the fly but using the same representation. -void nvim__buf_set_luahl(uint64_t channel_id, Buffer buffer, - DictionaryOf(LuaRef) opts, Error *err) - FUNC_API_LUA_ONLY -{ - buf_T *buf = find_buffer_by_handle(buffer, err); - - if (!buf) { - return; - } - - redraw_buf_later(buf, NOT_VALID); - buf_clear_luahl(buf, false); - - for (size_t i = 0; i < opts.size; i++) { - String k = opts.items[i].key; - Object *v = &opts.items[i].value; - if (strequal("on_start", k.data)) { - if (v->type != kObjectTypeLuaRef) { - api_set_error(err, kErrorTypeValidation, "callback is not a function"); - goto error; - } - buf->b_luahl_start = v->data.luaref; - v->data.luaref = LUA_NOREF; - } else if (strequal("on_window", k.data)) { - if (v->type != kObjectTypeLuaRef) { - api_set_error(err, kErrorTypeValidation, "callback is not a function"); - goto error; - } - buf->b_luahl_window = v->data.luaref; - v->data.luaref = LUA_NOREF; - } else if (strequal("on_line", k.data)) { - if (v->type != kObjectTypeLuaRef) { - api_set_error(err, kErrorTypeValidation, "callback is not a function"); - goto error; - } - buf->b_luahl_line = v->data.luaref; - v->data.luaref = LUA_NOREF; - } else { - api_set_error(err, kErrorTypeValidation, "unexpected key: %s", k.data); - goto error; - } - } - buf->b_luahl = true; - return; -error: - buf_clear_luahl(buf, true); - buf->b_luahl = false; -} - void nvim__buf_redraw_range(Buffer buffer, Integer first, Integer last, Error *err) FUNC_API_LUA_ONLY @@ -1465,15 +1393,17 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, } if (col2 >= 0) { - if (line2 >= 0) { - len = STRLEN(ml_get_buf(buf, (linenr_T)line2+1, false)); + if (line2 >= 0 && line2 < buf->b_ml.ml_line_count) { + len = STRLEN(ml_get_buf(buf, (linenr_T)line2 + 1, false)); + } else if (line2 == buf->b_ml.ml_line_count) { + // We are trying to add an extmark past final newline + len = 0; } else { // reuse len from before line2 = (int)line; } if (col2 > (Integer)len) { - api_set_error(err, kErrorTypeValidation, - "end_col value outside range"); + api_set_error(err, kErrorTypeValidation, "end_col value outside range"); goto error; } } else if (line2 >= 0) { @@ -1664,43 +1594,6 @@ void nvim_buf_clear_highlight(Buffer buffer, nvim_buf_clear_namespace(buffer, ns_id, line_start, line_end, err); } -static VirtText parse_virt_text(Array chunks, Error *err) -{ - VirtText virt_text = KV_INITIAL_VALUE; - for (size_t i = 0; i < chunks.size; i++) { - if (chunks.items[i].type != kObjectTypeArray) { - api_set_error(err, kErrorTypeValidation, "Chunk is not an array"); - goto free_exit; - } - Array chunk = chunks.items[i].data.array; - if (chunk.size == 0 || chunk.size > 2 - || chunk.items[0].type != kObjectTypeString - || (chunk.size == 2 && chunk.items[1].type != kObjectTypeString)) { - api_set_error(err, kErrorTypeValidation, - "Chunk is not an array with one or two strings"); - goto free_exit; - } - - String str = chunk.items[0].data.string; - char *text = transstr(str.size > 0 ? str.data : ""); // allocates - - int hl_id = 0; - if (chunk.size == 2) { - String hl = chunk.items[1].data.string; - if (hl.size > 0) { - hl_id = syn_check_group((char_u *)hl.data, (int)hl.size); - } - } - kv_push(virt_text, ((VirtTextChunk){ .text = text, .hl_id = hl_id })); - } - - return virt_text; - -free_exit: - clear_virttext(&virt_text); - return virt_text; -} - /// Set the virtual text (annotation) for a buffer line. /// @@ -1775,6 +1668,44 @@ Integer nvim_buf_set_virtual_text(Buffer buffer, return src_id; } +/// call a function with buffer as temporary current buffer +/// +/// This temporarily switches current buffer to "buffer". +/// If the current window already shows "buffer", the window is not switched +/// If a window inside the current tabpage (including a float) already shows the +/// buffer One of these windows will be set as current window temporarily. +/// Otherwise a temporary scratch window (calleed the "autocmd window" for +/// historical reasons) will be used. +/// +/// This is useful e.g. to call vimL functions that only work with the current +/// buffer/window currently, like |termopen()|. +/// +/// @param buffer Buffer handle, or 0 for current buffer +/// @param fun Function to call inside the buffer (currently lua callable +/// only) +/// @param[out] err Error details, if any +/// @return Return value of function. NB: will deepcopy lua values +/// currently, use upvalues to send lua references in and out. +Object nvim_buf_call(Buffer buffer, LuaRef fun, Error *err) + FUNC_API_SINCE(7) + FUNC_API_LUA_ONLY +{ + buf_T *buf = find_buffer_by_handle(buffer, err); + if (!buf) { + return NIL; + } + try_start(); + aco_save_T aco; + aucmd_prepbuf(&aco, (buf_T *)buf); + + Array args = ARRAY_DICT_INIT; + Object res = nlua_call_ref(fun, NULL, args, true, err); + + aucmd_restbuf(&aco); + try_end(err); + return res; +} + Dictionary nvim__buf_stats(Buffer buffer, Error *err) { Dictionary rv = ARRAY_DICT_INIT; diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 13f77d2d85..e0d5862e02 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -15,6 +15,8 @@ #include "nvim/lua/executor.h" #include "nvim/ascii.h" #include "nvim/assert.h" +#include "nvim/charset.h" +#include "nvim/syntax.h" #include "nvim/vim.h" #include "nvim/buffer.h" #include "nvim/window.h" @@ -1579,3 +1581,52 @@ bool extmark_get_index_from_obj(buf_T *buf, Integer ns_id, Object obj, int return false; } } + +VirtText parse_virt_text(Array chunks, Error *err) +{ + VirtText virt_text = KV_INITIAL_VALUE; + for (size_t i = 0; i < chunks.size; i++) { + if (chunks.items[i].type != kObjectTypeArray) { + api_set_error(err, kErrorTypeValidation, "Chunk is not an array"); + goto free_exit; + } + Array chunk = chunks.items[i].data.array; + if (chunk.size == 0 || chunk.size > 2 + || chunk.items[0].type != kObjectTypeString + || (chunk.size == 2 && chunk.items[1].type != kObjectTypeString)) { + api_set_error(err, kErrorTypeValidation, + "Chunk is not an array with one or two strings"); + goto free_exit; + } + + String str = chunk.items[0].data.string; + char *text = transstr(str.size > 0 ? str.data : ""); // allocates + + int hl_id = 0; + if (chunk.size == 2) { + String hl = chunk.items[1].data.string; + if (hl.size > 0) { + hl_id = syn_check_group((char_u *)hl.data, (int)hl.size); + } + } + kv_push(virt_text, ((VirtTextChunk){ .text = text, .hl_id = hl_id })); + } + + return virt_text; + +free_exit: + clear_virttext(&virt_text); + return virt_text; +} + +bool api_is_truthy(Object obj, const char *what, Error *err) +{ + if (obj.type == kObjectTypeBoolean) { + return obj.data.boolean; + } else if (obj.type == kObjectTypeInteger) { + return obj.data.integer; // C semantics: non-zery int is true + } else { + api_set_error(err, kErrorTypeValidation, "%s is not an boolean", what); + return false; + } +} diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 9155ffcfb8..1de1472fc2 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2610,22 +2610,91 @@ Array nvim__inspect_cell(Integer grid, Integer row, Integer col, Error *err) /// interface should probably be derived from a reformed /// bufhl/virttext interface with full support for multi-line /// ranges etc -void nvim__put_attr(Integer id, Integer start_row, Integer start_col, - Integer end_row, Integer end_col) +void nvim__put_attr(Integer line, Integer col, Dictionary opts, Error *err) FUNC_API_LUA_ONLY { if (!lua_attr_active) { return; } - if (id == 0 || syn_get_final_id((int)id) == 0) { - return; + int line2 = -1, hl_id = 0; + colnr_T col2 = 0; + VirtText virt_text = KV_INITIAL_VALUE; + for (size_t i = 0; i < opts.size; i++) { + String k = opts.items[i].key; + Object *v = &opts.items[i].value; + if (strequal("end_line", k.data)) { + if (v->type != kObjectTypeInteger) { + api_set_error(err, kErrorTypeValidation, + "end_line is not an integer"); + goto error; + } + if (v->data.integer < 0) { + api_set_error(err, kErrorTypeValidation, + "end_line value outside range"); + goto error; + } + + line2 = (int)v->data.integer; + } else if (strequal("end_col", k.data)) { + if (v->type != kObjectTypeInteger) { + api_set_error(err, kErrorTypeValidation, + "end_col is not an integer"); + goto error; + } + if (v->data.integer < 0 || v->data.integer > MAXCOL) { + api_set_error(err, kErrorTypeValidation, + "end_col value outside range"); + goto error; + } + + col2 = (colnr_T)v->data.integer; + } else if (strequal("hl_group", k.data)) { + String hl_group; + switch (v->type) { + case kObjectTypeString: + hl_group = v->data.string; + hl_id = syn_check_group( + (char_u *)(hl_group.data), + (int)hl_group.size); + break; + case kObjectTypeInteger: + hl_id = (int)v->data.integer; + break; + default: + api_set_error(err, kErrorTypeValidation, + "hl_group is not valid."); + goto error; + } + } else if (strequal("virt_text", k.data)) { + if (v->type != kObjectTypeArray) { + api_set_error(err, kErrorTypeValidation, + "virt_text is not an Array"); + goto error; + } + virt_text = parse_virt_text(v->data.array, err); + if (ERROR_SET(err)) { + goto error; + } + } else { + api_set_error(err, kErrorTypeValidation, "unexpected key: %s", k.data); + goto error; + } + } + if (col2 && line2 < 0) { + line2 = (int)line; } - int attr = syn_id2attr((int)id); - if (attr == 0) { + + int attr = hl_id ? syn_id2attr((int)hl_id) : 0; + if (attr == 0 && !kv_size(virt_text)) { return; } - decorations_add_luahl_attr(attr, (int)start_row, (colnr_T)start_col, - (int)end_row, (colnr_T)end_col); + + VirtText *v = xmalloc(sizeof(*v)); + *v = virt_text; // LeakSanitizer be sad + decorations_add_luahl_attr(attr, (int)line, (colnr_T)col, + (int)line2, (colnr_T)col2, v); +error: + return; } void nvim__screenshot(String path) @@ -2633,3 +2702,68 @@ void nvim__screenshot(String path) { ui_call_screenshot(path); } + +static void clear_luahl(bool force) +{ + if (luahl_active || force) { + api_free_luaref(luahl_start); + api_free_luaref(luahl_win); + api_free_luaref(luahl_line); + api_free_luaref(luahl_end); + } + luahl_start = LUA_NOREF; + luahl_win = LUA_NOREF; + luahl_line = LUA_NOREF; + luahl_end = LUA_NOREF; + luahl_active = false; +} + +/// Unstabilized interface for defining syntax hl in lua. +/// +/// This is not yet safe for general use, lua callbacks will need to +/// be restricted, like textlock and probably other stuff. +/// +/// The API on_line/nvim__put_attr is quite raw and not intended to be the +/// final shape. Ideally this should operate on chunks larger than a single +/// line to reduce interpreter overhead, and generate annotation objects +/// (bufhl/virttext) on the fly but using the same representation. +void nvim__set_luahl(DictionaryOf(LuaRef) opts, Error *err) + FUNC_API_LUA_ONLY +{ + redraw_later(NOT_VALID); + clear_luahl(false); + + for (size_t i = 0; i < opts.size; i++) { + String k = opts.items[i].key; + Object *v = &opts.items[i].value; + if (strequal("on_start", k.data)) { + if (v->type != kObjectTypeLuaRef) { + api_set_error(err, kErrorTypeValidation, "callback is not a function"); + goto error; + } + luahl_start = v->data.luaref; + v->data.luaref = LUA_NOREF; + } else if (strequal("on_win", k.data)) { + if (v->type != kObjectTypeLuaRef) { + api_set_error(err, kErrorTypeValidation, "callback is not a function"); + goto error; + } + luahl_win = v->data.luaref; + v->data.luaref = LUA_NOREF; + } else if (strequal("on_line", k.data)) { + if (v->type != kObjectTypeLuaRef) { + api_set_error(err, kErrorTypeValidation, "callback is not a function"); + goto error; + } + luahl_line = v->data.luaref; + v->data.luaref = LUA_NOREF; + } else { + api_set_error(err, kErrorTypeValidation, "unexpected key: %s", k.data); + goto error; + } + } + luahl_active = true; + return; +error: + clear_luahl(true); +} diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 4648631ebe..ec633dcc26 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -837,7 +837,7 @@ static void clear_wininfo(buf_T *buf) buf->b_wininfo = wip->wi_next; if (wip->wi_optset) { clear_winopt(&wip->wi_opt); - deleteFoldRecurse(&wip->wi_folds); + deleteFoldRecurse(buf, &wip->wi_folds); } xfree(wip); } @@ -1941,6 +1941,7 @@ void free_buf_options(buf_T *buf, int free_p_ff) vim_regfree(buf->b_s.b_cap_prog); buf->b_s.b_cap_prog = NULL; clear_string_option(&buf->b_s.b_p_spl); + clear_string_option(&buf->b_s.b_p_spo); clear_string_option(&buf->b_p_sua); clear_string_option(&buf->b_p_ft); clear_string_option(&buf->b_p_cink); @@ -2502,7 +2503,7 @@ void buflist_setfpos(buf_T *const buf, win_T *const win, } if (copy_options && wip->wi_optset) { clear_winopt(&wip->wi_opt); - deleteFoldRecurse(&wip->wi_folds); + deleteFoldRecurse(buf, &wip->wi_folds); } } if (lnum != 0) { diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index b3c95f9362..ea968d9592 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -451,6 +451,7 @@ typedef struct { regprog_T *b_cap_prog; // program for 'spellcapcheck' char_u *b_p_spf; // 'spellfile' char_u *b_p_spl; // 'spelllang' + char_u *b_p_spo; // 'spelloptions' int b_cjk; // all CJK letters as OK char_u b_syn_chartab[32]; // syntax iskeyword option char_u *b_syn_isk; // iskeyword option @@ -842,12 +843,6 @@ struct file_buffer { // The number for times the current line has been flushed in the memline. int flush_count; - bool b_luahl; - LuaRef b_luahl_start; - LuaRef b_luahl_window; - LuaRef b_luahl_line; - LuaRef b_luahl_end; - int b_diff_failed; // internal diff failed for this buffer }; diff --git a/src/nvim/change.c b/src/nvim/change.c index b8bc08b747..71614363d2 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -362,8 +362,7 @@ void changed_bytes(linenr_T lnum, colnr_T col) /// insert/delete bytes at column /// /// Like changed_bytes() but also adjust extmark for "new" bytes. -/// When "new" is negative text was deleted. -static void inserted_bytes(linenr_T lnum, colnr_T col, int old, int new) +void inserted_bytes(linenr_T lnum, colnr_T col, int old, int new) { if (curbuf_splice_pending == 0) { extmark_splice_cols(curbuf, (int)lnum-1, col, old, new, kExtmarkUndo); @@ -1677,9 +1676,16 @@ int open_line( truncate_spaces(saved_line); } ml_replace(curwin->w_cursor.lnum, saved_line, false); - extmark_splice_cols( - curbuf, (int)curwin->w_cursor.lnum, - 0, curwin->w_cursor.col, (int)STRLEN(saved_line), kExtmarkUndo); + + int new_len = (int)STRLEN(saved_line); + + // TODO(vigoux): maybe there is issues there with expandtabs ? + if (new_len < curwin->w_cursor.col) { + extmark_splice_cols( + curbuf, (int)curwin->w_cursor.lnum, + new_len, curwin->w_cursor.col - new_len, 0, kExtmarkUndo); + } + saved_line = NULL; if (did_append) { changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col, diff --git a/src/nvim/cursor_shape.c b/src/nvim/cursor_shape.c index 3f06340611..0d21080aa5 100644 --- a/src/nvim/cursor_shape.c +++ b/src/nvim/cursor_shape.c @@ -13,6 +13,10 @@ #include "nvim/api/private/helpers.h" #include "nvim/ui.h" +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "cursor_shape.c.generated.h" +#endif + /// Handling of cursor and mouse pointer shapes in various modes. cursorentry_T shape_table[SHAPE_IDX_COUNT] = { @@ -77,7 +81,9 @@ Array mode_style_array(void) return all; } -/// Parse the 'guicursor' option +/// Parses the 'guicursor' option. +/// +/// Clears `shape_table` if 'guicursor' is empty. /// /// @param what SHAPE_CURSOR or SHAPE_MOUSE ('mouseshape') /// @@ -99,11 +105,17 @@ char_u *parse_shape_opt(int what) // First round: check for errors; second round: do it for real. for (round = 1; round <= 2; round++) { + if (round == 2 || *p_guicursor == NUL) { + // Set all entries to default (block, blinkon0, default color). + // This is the default for anything that is not set. + clear_shape_table(); + if (*p_guicursor == NUL) { + ui_mode_info_set(); + return NULL; + } + } // Repeat for all comma separated parts. modep = p_guicursor; - if (*p_guicursor == NUL) { - modep = (char_u *)"a:block-blinkon0"; - } while (modep != NULL && *modep != NUL) { colonp = vim_strchr(modep, ':'); commap = vim_strchr(modep, ','); @@ -144,14 +156,6 @@ char_u *parse_shape_opt(int what) if (all_idx >= 0) { idx = all_idx--; - } else if (round == 2) { - { - // Set the defaults, for the missing parts - shape_table[idx].shape = SHAPE_BLOCK; - shape_table[idx].blinkwait = 0L; - shape_table[idx].blinkon = 0L; - shape_table[idx].blinkoff = 0L; - } } /* Parse the part after the colon */ @@ -330,3 +334,16 @@ int cursor_get_mode_idx(void) return SHAPE_IDX_N; } } + +/// Clears all entries in shape_table to block, blinkon0, and default color. +static void clear_shape_table(void) +{ + for (int idx = 0; idx < SHAPE_IDX_COUNT; idx++) { + shape_table[idx].shape = SHAPE_BLOCK; + shape_table[idx].blinkwait = 0L; + shape_table[idx].blinkon = 0L; + shape_table[idx].blinkoff = 0L; + shape_table[idx].id = 0; + shape_table[idx].id_lm = 0; + } +} diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 32830c5d7f..00542e3766 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -4518,7 +4518,6 @@ int get_option_tv(const char **const arg, typval_T *const rettv, static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate) { char_u *p; - char_u *name; unsigned int extra = 0; /* @@ -4526,11 +4525,14 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate) */ for (p = *arg + 1; *p != NUL && *p != '"'; MB_PTR_ADV(p)) { if (*p == '\\' && p[1] != NUL) { - ++p; - /* A "\<x>" form occupies at least 4 characters, and produces up - * to 6 characters: reserve space for 2 extra */ - if (*p == '<') - extra += 2; + p++; + // A "\<x>" form occupies at least 4 characters, and produces up + // to 21 characters (3 * 6 for the char and 3 for a modifier): + // reserve space for 18 extra. + // Each byte in the char could be encoded as K_SPECIAL K_EXTRA x. + if (*p == '<') { + extra += 18; + } } } @@ -4549,7 +4551,8 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate) * Copy the string into allocated memory, handling backslashed * characters. */ - name = xmalloc(p - *arg + extra); + const int len = (int)(p - *arg + extra); + char_u *name = xmalloc(len); rettv->v_type = VAR_STRING; rettv->vval.v_string = name; @@ -4616,6 +4619,9 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate) extra = trans_special((const char_u **)&p, STRLEN(p), name, true, true); if (extra != 0) { name += extra; + if (name >= rettv->vval.v_string + len) { + iemsg("get_string_tv() used more space than allocated"); + } break; } FALLTHROUGH; @@ -6962,9 +6968,10 @@ void set_buffer_lines(buf_T *buf, linenr_T lnum_arg, bool append, if (!append && lnum <= curbuf->b_ml.ml_line_count) { // Existing line, replace it. + int old_len = (int)STRLEN(ml_get(lnum)); if (u_savesub(lnum) == OK && ml_replace(lnum, (char_u *)line, true) == OK) { - changed_bytes(lnum, 0); + inserted_bytes(lnum, 0, old_len, STRLEN(line)); if (is_curbuf && lnum == curwin->w_cursor.lnum) { check_cursor_col(); } diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 3a4b4f2a50..bd77a3b7e2 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -2584,8 +2584,6 @@ static void f_foldtextresult(typval_T *argvars, typval_T *rettv, FunPtr fptr) { char_u *text; char_u buf[FOLD_TEXT_LEN]; - foldinfo_T foldinfo; - int fold_count; static bool entered = false; rettv->v_type = VAR_STRING; @@ -2599,9 +2597,10 @@ static void f_foldtextresult(typval_T *argvars, typval_T *rettv, FunPtr fptr) if (lnum < 0) { lnum = 0; } - fold_count = foldedCount(curwin, lnum, &foldinfo); - if (fold_count > 0) { - text = get_foldtext(curwin, lnum, lnum + fold_count - 1, &foldinfo, buf); + + foldinfo_T info = fold_info(curwin, lnum); + if (info.fi_lines > 0) { + text = get_foldtext(curwin, lnum, lnum + info.fi_lines - 1, info, buf); if (text == buf) { text = vim_strsave(text); } diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index dfebd13868..7bb4bd32a3 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -2228,17 +2228,19 @@ int parse_command_modifiers(exarg_T *eap, char_u **errormsg, bool skip_only) continue; case 't': if (checkforcmd(&p, "tab", 3)) { - long tabnr = get_address( - eap, &eap->cmd, ADDR_TABS, eap->skip, skip_only, false, 1); + if (!skip_only) { + long tabnr = get_address( + eap, &eap->cmd, ADDR_TABS, eap->skip, skip_only, false, 1); - if (tabnr == MAXLNUM) { - cmdmod.tab = tabpage_index(curtab) + 1; - } else { - if (tabnr < 0 || tabnr > LAST_TAB_NR) { - *errormsg = (char_u *)_(e_invrange); - return false; + if (tabnr == MAXLNUM) { + cmdmod.tab = tabpage_index(curtab) + 1; + } else { + if (tabnr < 0 || tabnr > LAST_TAB_NR) { + *errormsg = (char_u *)_(e_invrange); + return false; + } + cmdmod.tab = tabnr + 1; } - cmdmod.tab = tabnr + 1; } eap->cmd = p; continue; @@ -9295,14 +9297,17 @@ static void ex_match(exarg_T *eap) static void ex_fold(exarg_T *eap) { if (foldManualAllowed(true)) { - foldCreate(curwin, eap->line1, eap->line2); + pos_T start = { eap->line1, 1, 0 }; + pos_T end = { eap->line2, 1, 0 }; + foldCreate(curwin, start, end); } } static void ex_foldopen(exarg_T *eap) { - opFoldRange(eap->line1, eap->line2, eap->cmdidx == CMD_foldopen, - eap->forceit, FALSE); + pos_T start = { eap->line1, 1, 0 }; + pos_T end = { eap->line2, 1, 0 }; + opFoldRange(start, end, eap->cmdidx == CMD_foldopen, eap->forceit, false); } static void ex_folddo(exarg_T *eap) diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index c966c780a0..f9ca7bfa42 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -276,6 +276,7 @@ static void init_incsearch_state(incsearch_state_T *s) // Sets search_first_line and search_last_line to the address range. static bool do_incsearch_highlighting(int firstc, incsearch_state_T *s, int *skiplen, int *patlen) + FUNC_ATTR_NONNULL_ALL { char_u *cmd; cmdmod_T save_cmdmod = cmdmod; @@ -287,6 +288,7 @@ static bool do_incsearch_highlighting(int firstc, incsearch_state_T *s, exarg_T ea; pos_T save_cursor; bool use_last_pat; + bool retval = false; *skiplen = 0; *patlen = ccline.cmdlen; @@ -306,6 +308,7 @@ static bool do_incsearch_highlighting(int firstc, incsearch_state_T *s, return false; } + emsg_off++; memset(&ea, 0, sizeof(ea)); ea.line1 = 1; ea.line2 = 1; @@ -317,13 +320,13 @@ static bool do_incsearch_highlighting(int firstc, incsearch_state_T *s, cmd = skip_range(ea.cmd, NULL); if (vim_strchr((char_u *)"sgvl", *cmd) == NULL) { - return false; + goto theend; } // Skip over "substitute" to find the pattern separator. for (p = cmd; ASCII_ISALPHA(*p); p++) {} if (*skipwhite(p) == NUL) { - return false; + goto theend; } if (STRNCMP(cmd, "substitute", p - cmd) == 0 @@ -336,12 +339,15 @@ static bool do_incsearch_highlighting(int firstc, incsearch_state_T *s, p_magic = false; } } else if (STRNCMP(cmd, "sort", MAX(p - cmd, 3)) == 0) { - // skip over flags. + // skip over ! and flags + if (*p == '!') { + p = skipwhite(p + 1); + } while (ASCII_ISALPHA(*(p = skipwhite(p)))) { p++; } if (*p == NUL) { - return false; + goto theend; } } else if (STRNCMP(cmd, "vimgrep", MAX(p - cmd, 3)) == 0 || STRNCMP(cmd, "vimgrepadd", MAX(p - cmd, 8)) == 0 @@ -352,14 +358,14 @@ static bool do_incsearch_highlighting(int firstc, incsearch_state_T *s, if (*p == '!') { p++; if (*skipwhite(p) == NUL) { - return false; + goto theend; } } if (*cmd != 'g') { delim_optional = true; } } else { - return false; + goto theend; } p = skipwhite(p); @@ -368,7 +374,7 @@ static bool do_incsearch_highlighting(int firstc, incsearch_state_T *s, use_last_pat = end == p && *end == delim; if (end == p && !use_last_pat) { - return false; + goto theend; } // Don't do 'hlsearch' highlighting if the pattern matches everything. @@ -380,7 +386,7 @@ static bool do_incsearch_highlighting(int firstc, incsearch_state_T *s, empty = empty_pattern(p); *end = c; if (empty) { - return false; + goto theend; } } @@ -408,7 +414,10 @@ static bool do_incsearch_highlighting(int firstc, incsearch_state_T *s, } curwin->w_cursor = save_cursor; - return true; + retval = true; +theend: + emsg_off--; + return retval; } // May do 'incsearch' highlighting if desired. @@ -443,6 +452,10 @@ static void may_do_incsearch_highlighting(int firstc, long count, if (search_first_line == 0) { // start at the original cursor position curwin->w_cursor = s->search_start; + } else if (search_first_line > curbuf->b_ml.ml_line_count) { + // start after the last line + curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; + curwin->w_cursor.col = MAXCOL; } else { // start at the first line in the range curwin->w_cursor.lnum = search_first_line; @@ -544,6 +557,7 @@ static void may_do_incsearch_highlighting(int firstc, long count, } update_screen(SOME_VALID); + highlight_match = false; restore_last_search_pattern(); // Leave it at the end to make CTRL-R CTRL-W work. But not when beyond the @@ -563,6 +577,7 @@ static void may_do_incsearch_highlighting(int firstc, long count, // May set "*c" to the added character. // Return OK when calling command_line_not_changed. static int may_add_char_to_search(int firstc, int *c, incsearch_state_T *s) + FUNC_ATTR_NONNULL_ALL { int skiplen, patlen; @@ -579,8 +594,8 @@ static int may_add_char_to_search(int firstc, int *c, incsearch_state_T *s) if (s->did_incsearch) { curwin->w_cursor = s->match_end; - if (!equalpos(curwin->w_cursor, s->search_start)) { - *c = gchar_cursor(); + *c = gchar_cursor(); + if (*c != NUL) { // If 'ignorecase' and 'smartcase' are set and the // command line has no uppercase characters, convert // the character to lowercase @@ -588,16 +603,14 @@ static int may_add_char_to_search(int firstc, int *c, incsearch_state_T *s) && !pat_has_uppercase(ccline.cmdbuff + skiplen)) { *c = mb_tolower(*c); } - if (*c != NUL) { - if (*c == firstc - || vim_strchr((char_u *)(p_magic ? "\\~^$.*[" : "\\^$"), *c) - != NULL) { - // put a backslash before special characters - stuffcharReadbuff(*c); - *c = '\\'; - } - return FAIL; + if (*c == firstc + || vim_strchr((char_u *)(p_magic ? "\\~^$.*[" : "\\^$"), *c) + != NULL) { + // put a backslash before special characters + stuffcharReadbuff(*c); + *c = '\\'; } + return FAIL; } } return OK; @@ -1444,6 +1457,7 @@ static int command_line_execute(VimState *state, int key) static int may_do_command_line_next_incsearch(int firstc, long count, incsearch_state_T *s, bool next_match) + FUNC_ATTR_NONNULL_ALL { int skiplen, patlen; @@ -1536,7 +1550,9 @@ static int may_do_command_line_next_incsearch(int firstc, long count, highlight_match = true; save_viewstate(&s->old_viewstate); update_screen(NOT_VALID); + highlight_match = false; redrawcmdline(); + curwin->w_cursor = s->match_end; } else { vim_beep(BO_ERROR); } @@ -6457,12 +6473,15 @@ static int open_cmdwin(void) // Save the command line info, can be used recursively. save_cmdline(&save_ccline); - /* No Ex mode here! */ + // No Ex mode here! exmode_active = 0; State = NORMAL; setmouse(); + // Reset here so it can be set by a CmdWinEnter autocommand. + cmdwin_result = 0; + // Trigger CmdwinEnter autocommands. typestr[0] = (char_u)cmdwin_type; typestr[1] = NUL; @@ -6478,7 +6497,6 @@ static int open_cmdwin(void) /* * Call the main loop until <CR> or CTRL-C is typed. */ - cmdwin_result = 0; normal_enter(true, false); RedrawingDisabled = i; diff --git a/src/nvim/extmark.c b/src/nvim/extmark.c index 3a04908ccb..17141f12fd 100644 --- a/src/nvim/extmark.c +++ b/src/nvim/extmark.c @@ -568,8 +568,18 @@ void extmark_splice(buf_T *buf, int new_row, colnr_T new_col, bcount_t new_byte, ExtmarkOp undo) { - long offset = ml_find_line_or_offset(buf, start_row+1, NULL, true); - extmark_splice_impl(buf, start_row, start_col, offset+start_col, + long offset = ml_find_line_or_offset(buf, start_row + 1, NULL, true); + + // On empty buffers, when editing the first line, the line is buffered, + // causing offset to be < 0. While the buffer is not actually empty, the + // buffered line has not been flushed (and should not be) yet, so the call is + // valid but an edge case. + // + // TODO(vigoux): maybe the is a better way of testing that ? + if (offset < 0 && buf->b_ml.ml_chunksize == NULL) { + offset = 0; + } + extmark_splice_impl(buf, start_row, start_col, offset + start_col, old_row, old_col, old_byte, new_row, new_col, new_byte, undo); } @@ -844,8 +854,15 @@ VirtText *extmark_find_virttext(buf_T *buf, int row, uint64_t ns_id) bool decorations_redraw_reset(buf_T *buf, DecorationRedrawState *state) { state->row = -1; + for (size_t i = 0; i < kv_size(state->active); i++) { + HlRange item = kv_A(state->active, i); + if (item.virt_text_owned) { + clear_virttext(item.virt_text); + xfree(item.virt_text); + } + } kv_size(state->active) = 0; - return buf->b_extmark_index || buf->b_luahl; + return buf->b_extmark_index; } @@ -889,10 +906,10 @@ bool decorations_redraw_start(buf_T *buf, int top_row, HlRange range; if (mark.id&MARKTREE_END_FLAG) { range = (HlRange){ altpos.row, altpos.col, mark.row, mark.col, - attr_id, vt }; + attr_id, vt, false }; } else { range = (HlRange){ mark.row, mark.col, altpos.row, - altpos.col, attr_id, vt }; + altpos.col, attr_id, vt, false }; } kv_push(state->active, range); @@ -957,7 +974,7 @@ int decorations_redraw_col(buf_T *buf, int col, DecorationRedrawState *state) VirtText *vt = kv_size(decor->virt_text) ? &decor->virt_text : NULL; kv_push(state->active, ((HlRange){ mark.row, mark.col, endpos.row, endpos.col, - attr_id, vt })); + attr_id, vt, false })); next_mark: marktree_itr_next(buf->b_marktree, state->itr); @@ -991,6 +1008,9 @@ next_mark: } if (keep) { kv_A(state->active, j++) = kv_A(state->active, i); + } else if (item.virt_text_owned) { + clear_virttext(item.virt_text); + xfree(item.virt_text); } } kv_size(state->active) = j; diff --git a/src/nvim/extmark.h b/src/nvim/extmark.h index 534e97a7f4..d394d4d806 100644 --- a/src/nvim/extmark.h +++ b/src/nvim/extmark.h @@ -85,6 +85,7 @@ typedef struct { int end_col; int attr_id; VirtText *virt_text; + bool virt_text_owned; } HlRange; typedef struct { diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 286f2b4fca..ed8b72e2be 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -210,7 +210,8 @@ void filemess(buf_T *buf, char_u *name, char_u *s, int attr) if (msg_silent != 0) { return; } - add_quoted_fname((char *)IObuff, IOSIZE - 80, buf, (const char *)name); + add_quoted_fname((char *)IObuff, IOSIZE - 100, buf, (const char *)name); + // Avoid an over-long translation to cause trouble. xstrlcat((char *)IObuff, (const char *)s, IOSIZE); // For the first message may have to start a new line. // For further ones overwrite the previous one, reset msg_scroll before diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 9994ad3ea8..197aedabec 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -153,14 +153,22 @@ bool hasFolding(linenr_T lnum, linenr_T *firstp, linenr_T *lastp) return hasFoldingWin(curwin, lnum, firstp, lastp, true, NULL); } -/* hasFoldingWin() {{{2 */ +// hasFoldingWin() {{{2 +/// Search folds starting at lnum +/// @param lnum first line to search +/// @param[out] first first line of fold containing lnum +/// @param[out] lastp last line with a fold +/// @param cache when true: use cached values of window +/// @param[out] infop where to store fold info +/// +/// @return true if range contains folds bool hasFoldingWin( win_T *const win, const linenr_T lnum, linenr_T *const firstp, linenr_T *const lastp, - const bool cache, // when true: use cached values of window - foldinfo_T *const infop // where to store fold info + const bool cache, + foldinfo_T *const infop ) { bool had_folded = false; @@ -280,26 +288,31 @@ int foldLevel(linenr_T lnum) // Return false if line is not folded. bool lineFolded(win_T *const win, const linenr_T lnum) { - return foldedCount(win, lnum, NULL) != 0; + return fold_info(win, lnum).fi_lines != 0; } -/* foldedCount() {{{2 */ -/* - * Count the number of lines that are folded at line number "lnum". - * Normally "lnum" is the first line of a possible fold, and the returned - * number is the number of lines in the fold. - * Doesn't use caching from the displayed window. - * Returns number of folded lines from "lnum", or 0 if line is not folded. - * When "infop" is not NULL, fills *infop with the fold level info. - */ -long foldedCount(win_T *win, linenr_T lnum, foldinfo_T *infop) +/// fold_info() {{{2 +/// +/// Count the number of lines that are folded at line number "lnum". +/// Normally "lnum" is the first line of a possible fold, and the returned +/// number is the number of lines in the fold. +/// Doesn't use caching from the displayed window. +/// +/// @return with the fold level info. +/// fi_lines = number of folded lines from "lnum", +/// or 0 if line is not folded. +foldinfo_T fold_info(win_T *win, linenr_T lnum) { + foldinfo_T info; linenr_T last; - if (hasFoldingWin(win, lnum, NULL, &last, false, infop)) { - return (long)(last - lnum + 1); + if (hasFoldingWin(win, lnum, NULL, &last, false, &info)) { + info.fi_lines = (long)(last - lnum + 1); + } else { + info.fi_lines = 0; } - return 0; + + return info; } /* foldmethodIsManual() {{{2 */ @@ -356,23 +369,21 @@ int foldmethodIsDiff(win_T *wp) return wp->w_p_fdm[0] == 'd'; } -/* closeFold() {{{2 */ -/* - * Close fold for current window at line "lnum". - * Repeat "count" times. - */ -void closeFold(linenr_T lnum, long count) +// closeFold() {{{2 +/// Close fold for current window at line "lnum". +/// Repeat "count" times. +void closeFold(pos_T pos, long count) { - setFoldRepeat(lnum, count, FALSE); + setFoldRepeat(pos, count, false); } /* closeFoldRecurse() {{{2 */ /* * Close fold for current window at line "lnum" recursively. */ -void closeFoldRecurse(linenr_T lnum) +void closeFoldRecurse(pos_T pos) { - (void)setManualFold(lnum, FALSE, TRUE, NULL); + (void)setManualFold(pos, false, true, NULL); } /* opFoldRange() {{{2 */ @@ -382,28 +393,32 @@ void closeFoldRecurse(linenr_T lnum) */ void opFoldRange( - linenr_T first, - linenr_T last, + pos_T firstpos, + pos_T lastpos, int opening, // TRUE to open, FALSE to close int recurse, // TRUE to do it recursively int had_visual // TRUE when Visual selection used ) { - int done = DONE_NOTHING; /* avoid error messages */ + int done = DONE_NOTHING; // avoid error messages + linenr_T first = firstpos.lnum; + linenr_T last = lastpos.lnum; linenr_T lnum; linenr_T lnum_next; for (lnum = first; lnum <= last; lnum = lnum_next + 1) { + pos_T temp = { lnum, 0, 0 }; lnum_next = lnum; /* Opening one level only: next fold to open is after the one going to * be opened. */ if (opening && !recurse) (void)hasFolding(lnum, NULL, &lnum_next); - (void)setManualFold(lnum, opening, recurse, &done); - /* Closing one level only: next line to close a fold is after just - * closed fold. */ - if (!opening && !recurse) + (void)setManualFold(temp, opening, recurse, &done); + // Closing one level only: next line to close a fold is after just + // closed fold. + if (!opening && !recurse) { (void)hasFolding(lnum, NULL, &lnum_next); + } } if (done == DONE_NOTHING) EMSG(_(e_nofold)); @@ -417,18 +432,18 @@ opFoldRange( * Open fold for current window at line "lnum". * Repeat "count" times. */ -void openFold(linenr_T lnum, long count) +void openFold(pos_T pos, long count) { - setFoldRepeat(lnum, count, TRUE); + setFoldRepeat(pos, count, true); } /* openFoldRecurse() {{{2 */ /* * Open fold for current window at line "lnum" recursively. */ -void openFoldRecurse(linenr_T lnum) +void openFoldRecurse(pos_T pos) { - (void)setManualFold(lnum, TRUE, TRUE, NULL); + (void)setManualFold(pos, true, true, NULL); } /* foldOpenCursor() {{{2 */ @@ -443,9 +458,10 @@ void foldOpenCursor(void) if (hasAnyFolding(curwin)) for (;; ) { done = DONE_NOTHING; - (void)setManualFold(curwin->w_cursor.lnum, TRUE, FALSE, &done); - if (!(done & DONE_ACTION)) + (void)setManualFold(curwin->w_cursor, true, false, &done); + if (!(done & DONE_ACTION)) { break; + } } } @@ -542,21 +558,21 @@ int foldManualAllowed(int create) // foldCreate() {{{2 /// Create a fold from line "start" to line "end" (inclusive) in the current /// window. -void foldCreate(win_T *wp, linenr_T start, linenr_T end) +void foldCreate(win_T *wp, pos_T start, pos_T end) { fold_T *fp; garray_T *gap; garray_T fold_ga; - int i, j; + int i; int cont; int use_level = FALSE; int closed = FALSE; int level = 0; - linenr_T start_rel = start; - linenr_T end_rel = end; + pos_T start_rel = start; + pos_T end_rel = end; - if (start > end) { - /* reverse the range */ + if (start.lnum > end.lnum) { + // reverse the range end = start_rel; start = end_rel; start_rel = start; @@ -577,14 +593,14 @@ void foldCreate(win_T *wp, linenr_T start, linenr_T end) i = 0; } else { for (;;) { - if (!foldFind(gap, start_rel, &fp)) { + if (!foldFind(gap, start_rel.lnum, &fp)) { break; } - if (fp->fd_top + fp->fd_len > end_rel) { + if (fp->fd_top + fp->fd_len > end_rel.lnum) { // New fold is completely inside this fold: Go one level deeper. gap = &fp->fd_nested; - start_rel -= fp->fd_top; - end_rel -= fp->fd_top; + start_rel.lnum -= fp->fd_top; + end_rel.lnum -= fp->fd_top; if (use_level || fp->fd_flags == FD_LEVEL) { use_level = true; if (level >= wp->w_p_fdl) { @@ -608,30 +624,35 @@ void foldCreate(win_T *wp, linenr_T start, linenr_T end) fp = (fold_T *)gap->ga_data + i; ga_init(&fold_ga, (int)sizeof(fold_T), 10); - /* Count number of folds that will be contained in the new fold. */ - for (cont = 0; i + cont < gap->ga_len; ++cont) - if (fp[cont].fd_top > end_rel) + // Count number of folds that will be contained in the new fold. + for (cont = 0; i + cont < gap->ga_len; cont++) { + if (fp[cont].fd_top > end_rel.lnum) { break; + } + } if (cont > 0) { ga_grow(&fold_ga, cont); /* If the first fold starts before the new fold, let the new fold * start there. Otherwise the existing fold would change. */ - if (start_rel > fp->fd_top) - start_rel = fp->fd_top; - - /* When last contained fold isn't completely contained, adjust end - * of new fold. */ - if (end_rel < fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1) - end_rel = fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1; - /* Move contained folds to inside new fold. */ + if (start_rel.lnum > fp->fd_top) { + start_rel.lnum = fp->fd_top; + } + + // When last contained fold isn't completely contained, adjust end + // of new fold. + if (end_rel.lnum < fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1) { + end_rel.lnum = fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1; + } + // Move contained folds to inside new fold memmove(fold_ga.ga_data, fp, sizeof(fold_T) * (size_t)cont); fold_ga.ga_len += cont; i += cont; /* Adjust line numbers in contained folds to be relative to the * new fold. */ - for (j = 0; j < cont; ++j) - ((fold_T *)fold_ga.ga_data)[j].fd_top -= start_rel; + for (int j = 0; j < cont; j++) { + ((fold_T *)fold_ga.ga_data)[j].fd_top -= start_rel.lnum; + } } /* Move remaining entries to after the new fold. */ if (i < gap->ga_len) @@ -641,8 +662,8 @@ void foldCreate(win_T *wp, linenr_T start, linenr_T end) /* insert new fold */ fp->fd_nested = fold_ga; - fp->fd_top = start_rel; - fp->fd_len = end_rel - start_rel + 1; + fp->fd_top = start_rel.lnum; + fp->fd_len = end_rel.lnum - start_rel.lnum + 1; /* We want the new fold to be closed. If it would remain open because * of using 'foldlevel', need to adjust fd_flags of containing folds. @@ -771,7 +792,7 @@ void deleteFold( */ void clearFolding(win_T *win) { - deleteFoldRecurse(&win->w_folds); + deleteFoldRecurse(win->w_buffer, &win->w_folds); win->w_foldinvalid = false; } @@ -1143,14 +1164,14 @@ static void checkupdate(win_T *wp) * Open or close fold for current window at line "lnum". * Repeat "count" times. */ -static void setFoldRepeat(linenr_T lnum, long count, int do_open) +static void setFoldRepeat(pos_T pos, long count, int do_open) { int done; long n; for (n = 0; n < count; ++n) { done = DONE_NOTHING; - (void)setManualFold(lnum, do_open, FALSE, &done); + (void)setManualFold(pos, do_open, false, &done); if (!(done & DONE_ACTION)) { /* Only give an error message when no fold could be opened. */ if (n == 0 && !(done & DONE_FOLD)) @@ -1167,12 +1188,13 @@ static void setFoldRepeat(linenr_T lnum, long count, int do_open) */ static linenr_T setManualFold( - linenr_T lnum, + pos_T pos, int opening, // TRUE when opening, FALSE when closing int recurse, // TRUE when closing/opening recursive int *donep ) { + linenr_T lnum = pos.lnum; if (foldmethodIsDiff(curwin) && curwin->w_p_scb) { linenr_T dlnum; @@ -1326,7 +1348,7 @@ static void deleteFoldEntry(win_T *const wp, garray_T *const gap, const int idx, fold_T *fp = (fold_T *)gap->ga_data + idx; if (recursive || GA_EMPTY(&fp->fd_nested)) { // recursively delete the contained folds - deleteFoldRecurse(&fp->fd_nested); + deleteFoldRecurse(wp->w_buffer, &fp->fd_nested); gap->ga_len--; if (idx < gap->ga_len) { memmove(fp, fp + 1, sizeof(*fp) * (size_t)(gap->ga_len - idx)); @@ -1368,9 +1390,9 @@ static void deleteFoldEntry(win_T *const wp, garray_T *const gap, const int idx, /* * Delete nested folds in a fold. */ -void deleteFoldRecurse(garray_T *gap) +void deleteFoldRecurse(buf_T *bp, garray_T *gap) { -# define DELETE_FOLD_NESTED(fd) deleteFoldRecurse(&((fd)->fd_nested)) +# define DELETE_FOLD_NESTED(fd) deleteFoldRecurse(bp, &((fd)->fd_nested)) GA_DEEP_CLEAR(gap, fold_T, DELETE_FOLD_NESTED); } @@ -1610,7 +1632,7 @@ static void setSmallMaybe(garray_T *gap) * Create a fold from line "start" to line "end" (inclusive) in the current * window by adding markers. */ -static void foldCreateMarkers(win_T *wp, linenr_T start, linenr_T end) +static void foldCreateMarkers(win_T *wp, pos_T start, pos_T end) { buf_T *buf = wp->w_buffer; if (!MODIFIABLE(buf)) { @@ -1625,13 +1647,13 @@ static void foldCreateMarkers(win_T *wp, linenr_T start, linenr_T end) /* Update both changes here, to avoid all folds after the start are * changed when the start marker is inserted and the end isn't. */ // TODO(teto): pass the buffer - changed_lines(start, (colnr_T)0, end, 0L, false); + changed_lines(start.lnum, (colnr_T)0, end.lnum, 0L, false); // Note: foldAddMarker() may not actually change start and/or end if // u_save() is unable to save the buffer line, but we send the // nvim_buf_lines_event anyway since it won't do any harm. - int64_t num_changed = 1 + end - start; - buf_updates_send_changes(buf, start, num_changed, num_changed, true); + int64_t num_changed = 1 + end.lnum - start.lnum; + buf_updates_send_changes(buf, start.lnum, num_changed, num_changed, true); } /* foldAddMarker() {{{2 */ @@ -1639,13 +1661,14 @@ static void foldCreateMarkers(win_T *wp, linenr_T start, linenr_T end) * Add "marker[markerlen]" in 'commentstring' to line "lnum". */ static void foldAddMarker( - buf_T *buf, linenr_T lnum, const char_u *marker, size_t markerlen) + buf_T *buf, pos_T pos, const char_u *marker, size_t markerlen) { char_u *cms = buf->b_p_cms; char_u *line; char_u *newline; char_u *p = (char_u *)strstr((char *)buf->b_p_cms, "%s"); bool line_is_comment = false; + linenr_T lnum = pos.lnum; // Allocate a new line: old-line + 'cms'-start + marker + 'cms'-end line = ml_get_buf(buf, lnum, false); @@ -1751,11 +1774,16 @@ static void foldDelMarker( } // get_foldtext() {{{2 -/// Return the text for a closed fold at line "lnum", with last line "lnume". -/// When 'foldtext' isn't set puts the result in "buf[FOLD_TEXT_LEN]". +/// Generates text to display +/// +/// @param buf allocated memory of length FOLD_TEXT_LEN. Used when 'foldtext' +/// isn't set puts the result in "buf[FOLD_TEXT_LEN]". +/// @param at line "lnum", with last line "lnume". +/// @return the text for a closed fold +/// /// Otherwise the result is in allocated memory. char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, - foldinfo_T *foldinfo, char_u *buf) + foldinfo_T foldinfo, char_u *buf) FUNC_ATTR_NONNULL_ARG(1) { char_u *text = NULL; @@ -1783,11 +1811,12 @@ char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, set_vim_var_nr(VV_FOLDSTART, (varnumber_T) lnum); set_vim_var_nr(VV_FOLDEND, (varnumber_T) lnume); - /* Set "v:folddashes" to a string of "level" dashes. */ - /* Set "v:foldlevel" to "level". */ - level = foldinfo->fi_level; - if (level > (int)sizeof(dashes) - 1) + // Set "v:folddashes" to a string of "level" dashes. + // Set "v:foldlevel" to "level". + level = foldinfo.fi_level; + if (level > (int)sizeof(dashes) - 1) { level = (int)sizeof(dashes) - 1; + } memset(dashes, '-', (size_t)level); dashes[level] = NUL; set_vim_var_string(VV_FOLDDASHES, dashes, -1); diff --git a/src/nvim/fold.h b/src/nvim/fold.h index f35b328fb1..95c4b0c1dc 100644 --- a/src/nvim/fold.h +++ b/src/nvim/fold.h @@ -18,6 +18,7 @@ typedef struct foldinfo { other fields are invalid */ int fi_low_level; /* lowest fold level that starts in the same line */ + long fi_lines; } foldinfo_T; diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 205be4b811..ddb69fc567 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -405,6 +405,12 @@ EXTERN int sys_menu INIT(= false); // ('lines' and 'rows') must not be changed. EXTERN int updating_screen INIT(= 0); +EXTERN bool luahl_active INIT(= false); +EXTERN LuaRef luahl_start INIT(= LUA_NOREF); +EXTERN LuaRef luahl_win INIT(= LUA_NOREF); +EXTERN LuaRef luahl_line INIT(= LUA_NOREF); +EXTERN LuaRef luahl_end INIT(= LUA_NOREF); + // All windows are linked in a list. firstwin points to the first entry, // lastwin to the last entry (can be the same as firstwin) and curwin to the // currently active window. diff --git a/src/nvim/log.h b/src/nvim/log.h index 17ff095473..d92b4629ed 100644 --- a/src/nvim/log.h +++ b/src/nvim/log.h @@ -5,6 +5,7 @@ #include <stdbool.h> #include "auto/config.h" +#include "nvim/macros.h" #define DEBUG_LOG_LEVEL 0 #define INFO_LOG_LEVEL 1 @@ -68,6 +69,10 @@ # define LOG_CALLSTACK_TO_FILE(fp) log_callstack_to_file(fp, __func__, __LINE__) #endif +#if NVIM_HAS_INCLUDE("sanitizer/asan_interface.h") +# include "sanitizer/asan_interface.h" +#endif + #ifdef INCLUDE_GENERATED_DECLARATIONS # include "log.h.generated.h" #endif diff --git a/src/nvim/macros.h b/src/nvim/macros.h index 0bbaa87aba..07dcb4a8e8 100644 --- a/src/nvim/macros.h +++ b/src/nvim/macros.h @@ -152,6 +152,12 @@ #define STR_(x) #x #define STR(x) STR_(x) +#ifndef __has_include +# define NVIM_HAS_INCLUDE(x) 0 +#else +# define NVIM_HAS_INCLUDE __has_include +#endif + #ifndef __has_attribute # define NVIM_HAS_ATTRIBUTE(x) 0 #elif defined(__clang__) && __clang__ == 1 \ diff --git a/src/nvim/main.c b/src/nvim/main.c index 1374c5eb5d..a22df9cc69 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -7,6 +7,8 @@ #include <string.h> #include <stdbool.h> +#include <lua.h> +#include <lauxlib.h> #include <msgpack.h> #include "nvim/ascii.h" diff --git a/src/nvim/memline.c b/src/nvim/memline.c index f9390bcb88..2a75f13cc2 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -1818,6 +1818,7 @@ ml_get_buf ( linenr_T lnum, bool will_change // line will be changed ) + FUNC_ATTR_NONNULL_ALL { bhdr_T *hp; DATA_BL *dp; diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 968cfde388..760536d48a 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -1977,20 +1977,20 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) case OP_FOLD: VIsual_reselect = false; // don't reselect now - foldCreate(curwin, oap->start.lnum, oap->end.lnum); + foldCreate(curwin, oap->start, oap->end); break; case OP_FOLDOPEN: case OP_FOLDOPENREC: case OP_FOLDCLOSE: case OP_FOLDCLOSEREC: - VIsual_reselect = false; /* don't reselect now */ - opFoldRange(oap->start.lnum, oap->end.lnum, - oap->op_type == OP_FOLDOPEN - || oap->op_type == OP_FOLDOPENREC, - oap->op_type == OP_FOLDOPENREC - || oap->op_type == OP_FOLDCLOSEREC, - oap->is_VIsual); + VIsual_reselect = false; // don't reselect now + opFoldRange(oap->start, oap->end, + oap->op_type == OP_FOLDOPEN + || oap->op_type == OP_FOLDOPENREC, + oap->op_type == OP_FOLDOPENREC + || oap->op_type == OP_FOLDCLOSEREC, + oap->is_VIsual); break; case OP_FOLDDEL: @@ -2590,14 +2590,16 @@ do_mouse ( && !is_drag && (jump_flags & (MOUSE_FOLD_CLOSE | MOUSE_FOLD_OPEN)) && which_button == MOUSE_LEFT) { - /* open or close a fold at this line */ - if (jump_flags & MOUSE_FOLD_OPEN) - openFold(curwin->w_cursor.lnum, 1L); - else - closeFold(curwin->w_cursor.lnum, 1L); - /* don't move the cursor if still in the same window */ - if (curwin == old_curwin) + // open or close a fold at this line + if (jump_flags & MOUSE_FOLD_OPEN) { + openFold(curwin->w_cursor, 1L); + } else { + closeFold(curwin->w_cursor, 1L); + } + // don't move the cursor if still in the same window + if (curwin == old_curwin) { curwin->w_cursor = save_cursor; + } } @@ -4393,51 +4395,55 @@ dozet: case 'i': curwin->w_p_fen = !curwin->w_p_fen; break; - /* "za": open closed fold or close open fold at cursor */ - case 'a': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) - openFold(curwin->w_cursor.lnum, cap->count1); - else { - closeFold(curwin->w_cursor.lnum, cap->count1); + // "za": open closed fold or close open fold at cursor + case 'a': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) { + openFold(curwin->w_cursor, cap->count1); + } else { + closeFold(curwin->w_cursor, cap->count1); curwin->w_p_fen = true; } break; - /* "zA": open fold at cursor recursively */ - case 'A': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) - openFoldRecurse(curwin->w_cursor.lnum); - else { - closeFoldRecurse(curwin->w_cursor.lnum); + // "zA": open fold at cursor recursively + case 'A': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) { + openFoldRecurse(curwin->w_cursor); + } else { + closeFoldRecurse(curwin->w_cursor); curwin->w_p_fen = true; } break; - /* "zo": open fold at cursor or Visual area */ - case 'o': if (VIsual_active) + // "zo": open fold at cursor or Visual area + case 'o': if (VIsual_active) { nv_operator(cap); - else - openFold(curwin->w_cursor.lnum, cap->count1); + } else { + openFold(curwin->w_cursor, cap->count1); + } break; - /* "zO": open fold recursively */ - case 'O': if (VIsual_active) + // "zO": open fold recursively + case 'O': if (VIsual_active) { nv_operator(cap); - else - openFoldRecurse(curwin->w_cursor.lnum); + } else { + openFoldRecurse(curwin->w_cursor); + } break; - /* "zc": close fold at cursor or Visual area */ - case 'c': if (VIsual_active) + // "zc": close fold at cursor or Visual area + case 'c': if (VIsual_active) { nv_operator(cap); - else - closeFold(curwin->w_cursor.lnum, cap->count1); + } else { + closeFold(curwin->w_cursor, cap->count1); + } curwin->w_p_fen = true; break; - /* "zC": close fold recursively */ - case 'C': if (VIsual_active) + // "zC": close fold recursively + case 'C': if (VIsual_active) { nv_operator(cap); - else - closeFoldRecurse(curwin->w_cursor.lnum); + } else { + closeFoldRecurse(curwin->w_cursor); + } curwin->w_p_fen = true; break; diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 1f55d2c315..d1f2e9e4f1 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -119,7 +119,7 @@ static char opchars[][3] = { 'r', NUL, OPF_CHANGE }, // OP_REPLACE { 'I', NUL, OPF_CHANGE }, // OP_INSERT { 'A', NUL, OPF_CHANGE }, // OP_APPEND - { 'z', 'f', OPF_LINES }, // OP_FOLD + { 'z', 'f', 0 }, // OP_FOLD { 'z', 'o', OPF_LINES }, // OP_FOLDOPEN { 'z', 'O', OPF_LINES }, // OP_FOLDOPENREC { 'z', 'c', OPF_LINES }, // OP_FOLDCLOSE @@ -1544,10 +1544,10 @@ int op_delete(oparg_T *oap) oap->line_count = 0; // no lines deleted } else if (oap->motion_type == kMTLineWise) { if (oap->op_type == OP_CHANGE) { - /* Delete the lines except the first one. Temporarily move the - * cursor to the next line. Save the current line number, if the - * last line is deleted it may be changed. - */ + // Delete the lines except the first one. Temporarily move the + // cursor to the next line. Save the current line number, if the + // last line is deleted it may be changed. + if (oap->line_count > 1) { lnum = curwin->w_cursor.lnum; ++curwin->w_cursor.lnum; @@ -1560,12 +1560,21 @@ int op_delete(oparg_T *oap) beginline(BL_WHITE); // cursor on first non-white did_ai = true; // delete the indent when ESC hit ai_col = curwin->w_cursor.col; - } else - beginline(0); /* cursor in column 0 */ - truncate_line(FALSE); /* delete the rest of the line */ - /* leave cursor past last char in line */ - if (oap->line_count > 1) - u_clearline(); /* "U" command not possible after "2cc" */ + } else { + beginline(0); // cursor in column 0 + } + + int old_len = (int)STRLEN(ml_get(curwin->w_cursor.lnum)); + truncate_line(false); // delete the rest of the line + + extmark_splice_cols(curbuf, + (int)curwin->w_cursor.lnum-1, curwin->w_cursor.col, + old_len - curwin->w_cursor.col, 0, kExtmarkUndo); + + // leave cursor past last char in line + if (oap->line_count > 1) { + u_clearline(); // "U" command not possible after "2cc" + } } else { del_lines(oap->line_count, TRUE); beginline(BL_WHITE | BL_FIX); diff --git a/src/nvim/option.c b/src/nvim/option.c index 8d74cead8d..6ae9378236 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -174,6 +174,7 @@ static char_u *p_syn; static char_u *p_spc; static char_u *p_spf; static char_u *p_spl; +static char_u *p_spo; static long p_ts; static long p_tw; static int p_udf; @@ -2285,6 +2286,7 @@ void check_buf_options(buf_T *buf) check_string_option(&buf->b_s.b_p_spc); check_string_option(&buf->b_s.b_p_spf); check_string_option(&buf->b_s.b_p_spl); + check_string_option(&buf->b_s.b_p_spo); check_string_option(&buf->b_p_sua); check_string_option(&buf->b_p_cink); check_string_option(&buf->b_p_cino); @@ -3090,6 +3092,10 @@ ambw_end: } else if (varp == &(curwin->w_s->b_p_spc)) { // When 'spellcapcheck' is set compile the regexp program. errmsg = compile_cap_prog(curwin->w_s); + } else if (varp == &(curwin->w_s->b_p_spo)) { // 'spelloptions' + if (**varp != NUL && STRCMP("camel", *varp) != 0) { + errmsg = e_invarg; + } } else if (varp == &p_sps) { // 'spellsuggest' if (spell_check_sps() != OK) { errmsg = e_invarg; @@ -5896,6 +5902,7 @@ static char_u *get_varp(vimoption_T *p) case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc); case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf); case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl); + case PV_SPO: return (char_u *)&(curwin->w_s->b_p_spo); case PV_SW: return (char_u *)&(curbuf->b_p_sw); case PV_TFU: return (char_u *)&(curbuf->b_p_tfu); case PV_TS: return (char_u *)&(curbuf->b_p_ts); @@ -6175,6 +6182,7 @@ void buf_copy_options(buf_T *buf, int flags) (void)compile_cap_prog(&buf->b_s); buf->b_s.b_p_spf = vim_strsave(p_spf); buf->b_s.b_p_spl = vim_strsave(p_spl); + buf->b_s.b_p_spo = vim_strsave(p_spo); buf->b_p_inde = vim_strsave(p_inde); buf->b_p_indk = vim_strsave(p_indk); buf->b_p_fp = empty_option; diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h index 02fa7ac216..a09811c8fb 100644 --- a/src/nvim/option_defs.h +++ b/src/nvim/option_defs.h @@ -787,6 +787,7 @@ enum { , BV_SPC , BV_SPF , BV_SPL + , BV_SPO , BV_STS , BV_SUA , BV_SW diff --git a/src/nvim/options.lua b/src/nvim/options.lua index f1221a52a2..02df0ab276 100644 --- a/src/nvim/options.lua +++ b/src/nvim/options.lua @@ -2320,6 +2320,16 @@ return { defaults={if_true={vi="best"}} }, { + full_name='spelloptions', abbreviation='spo', + type='string', list='onecomma', scope={'buffer'}, + deny_duplicates=true, + secure=true, + vi_def=true, + expand=true, + varname='p_spo', + defaults={if_true={vi="", vim=""}} + }, + { full_name='splitbelow', abbreviation='sb', type='bool', scope={'global'}, vi_def=true, diff --git a/src/nvim/os/lang.c b/src/nvim/os/lang.c index fe2d7986bf..603191a0ff 100644 --- a/src/nvim/os/lang.c +++ b/src/nvim/os/lang.c @@ -43,14 +43,20 @@ void lang_init(void) } } + char buf[50] = { 0 }; + bool set_lang; if (lang_region) { - os_setenv("LANG", lang_region, true); + set_lang = true; + xstrlcpy(buf, lang_region, sizeof(buf)); } else { - char buf[20] = { 0 }; - if (CFStringGetCString(cf_lang_region, buf, 20, - kCFStringEncodingUTF8)) { - os_setenv("LANG", buf, true); + set_lang = CFStringGetCString(cf_lang_region, buf, 40, + kCFStringEncodingUTF8); + } + if (set_lang) { + if (strcasestr(buf, "utf-8") == NULL) { + xstrlcat(buf, ".UTF-8", sizeof(buf)); } + os_setenv("LANG", buf, true); } CFRelease(cf_lang_region); # ifdef HAVE_LOCALE_H diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index ddce1e922d..5754950745 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -901,6 +901,7 @@ static bool qf_list_has_valid_entries(qf_list_T *qfl) /// Return a pointer to a list in the specified quickfix stack static qf_list_T * qf_get_list(qf_info_T *qi, int idx) + FUNC_ATTR_NONNULL_ALL { return &qi->qf_lists[idx]; } @@ -1230,6 +1231,7 @@ static char_u * qf_cmdtitle(char_u *cmd) /// Return a pointer to the current list in the specified quickfix stack static qf_list_T * qf_get_curlist(qf_info_T *qi) + FUNC_ATTR_NONNULL_ALL { return qf_get_list(qi, qi->qf_curlist); } @@ -4825,12 +4827,13 @@ static bool vgr_qflist_valid(win_T *wp, qf_info_T *qi, unsigned qfid, /// Search for a pattern in all the lines in a buffer and add the matching lines /// to a quickfix list. static bool vgr_match_buflines(qf_info_T *qi, char_u *fname, buf_T *buf, - regmmatch_T *regmatch, long tomatch, + regmmatch_T *regmatch, long *tomatch, int duplicate_name, int flags) + FUNC_ATTR_NONNULL_ARG(1, 3, 4, 5) { bool found_match = false; - for (long lnum = 1; lnum <= buf->b_ml.ml_line_count && tomatch > 0; lnum++) { + for (long lnum = 1; lnum <= buf->b_ml.ml_line_count && *tomatch > 0; lnum++) { colnr_T col = 0; while (vim_regexec_multi(regmatch, curwin, buf, lnum, col, NULL, NULL) > 0) { @@ -4856,7 +4859,7 @@ static bool vgr_match_buflines(qf_info_T *qi, char_u *fname, buf_T *buf, break; } found_match = true; - if (--tomatch == 0) { + if (--*tomatch == 0) { break; } if ((flags & VGR_GLOBAL) == 0 || regmatch->endpos[0].lnum > 0) { @@ -5030,7 +5033,7 @@ void ex_vimgrep(exarg_T *eap) } else { // Try for a match in all lines of the buffer. // For ":1vimgrep" look for first match only. - found_match = vgr_match_buflines(qi, fname, buf, ®match, tomatch, + found_match = vgr_match_buflines(qi, fname, buf, ®match, &tomatch, duplicate_name, flags); if (using_dummy) { diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index bcf02af4ef..a570328499 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -7387,6 +7387,7 @@ long vim_regexec_multi( proftime_T *tm, // timeout limit or NULL int *timed_out // flag is set when timeout limit reached ) + FUNC_ATTR_NONNULL_ARG(1) { regexec_T rex_save; bool rex_in_use_save = rex_in_use; diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 3c2e1ccaf5..f3fdafcc70 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -133,8 +133,6 @@ static sattr_T *linebuf_attr = NULL; static match_T search_hl; /* used for 'hlsearch' highlight matching */ -static foldinfo_T win_foldinfo; /* info for 'foldcolumn' */ - StlClickDefinition *tab_page_click_defs = NULL; long tab_page_click_defs_size = 0; @@ -158,6 +156,8 @@ static bool msg_grid_invalid = false; static bool resizing = false; +static bool do_luahl_line = false; + #ifdef INCLUDE_GENERATED_DECLARATIONS # include "screen.c.generated.h" #endif @@ -508,12 +508,12 @@ int update_screen(int type) } buf_T *buf = wp->w_buffer; - if (buf->b_luahl && buf->b_luahl_window != LUA_NOREF) { + if (luahl_active && luahl_start != LUA_NOREF) { Error err = ERROR_INIT; FIXED_TEMP_ARRAY(args, 2); args.items[0] = BUFFER_OBJ(buf->handle); args.items[1] = INTEGER_OBJ(display_tick); - nlua_call_ref(buf->b_luahl_start, "start", args, false, &err); + nlua_call_ref(luahl_start, "start", args, false, &err); if (ERROR_SET(&err)) { ELOG("error in luahl start: %s", err.msg); api_clear_error(&err); @@ -639,10 +639,11 @@ bool decorations_active = false; void decorations_add_luahl_attr(int attr_id, int start_row, int start_col, - int end_row, int end_col) + int end_row, int end_col, VirtText *virt_text) { kv_push(decorations.active, - ((HlRange){ start_row, start_col, end_row, end_col, attr_id, NULL })); + ((HlRange){ start_row, start_col, + end_row, end_col, attr_id, virt_text, true })); } /* @@ -699,7 +700,6 @@ static void win_update(win_T *wp) long j; static int recursive = FALSE; /* being called recursively */ int old_botline = wp->w_botline; - long fold_count; // Remember what happened to the previous line. #define DID_NONE 1 // didn't update a line #define DID_LINE 2 // updated a normal line @@ -710,6 +710,7 @@ static void win_update(win_T *wp) linenr_T mod_bot = 0; int save_got_int; + // If we can compute a change in the automatic sizing of the sign column // under 'signcolumn=auto:X' and signs currently placed in the buffer, better // figuring it out here so we can redraw the entire screen for it. @@ -1226,7 +1227,6 @@ static void win_update(win_T *wp) // Set the time limit to 'redrawtime'. proftime_T syntax_tm = profile_setlimit(p_rdt); syn_set_timeout(&syntax_tm); - win_foldinfo.fi_level = 0; /* * Update all the window rows. @@ -1238,7 +1238,9 @@ static void win_update(win_T *wp) decorations_active = decorations_redraw_reset(buf, &decorations); - if (buf->b_luahl && buf->b_luahl_window != LUA_NOREF) { + do_luahl_line = false; + + if (luahl_win != LUA_NOREF) { Error err = ERROR_INIT; FIXED_TEMP_ARRAY(args, 4); linenr_T knownmax = ((wp->w_valid & VALID_BOTLINE) @@ -1251,7 +1253,13 @@ static void win_update(win_T *wp) args.items[3] = INTEGER_OBJ(knownmax); // TODO(bfredl): we could allow this callback to change mod_top, mod_bot. // For now the "start" callback is expected to use nvim__buf_redraw_range. - nlua_call_ref(buf->b_luahl_window, "window", args, false, &err); + Object ret = nlua_call_ref(luahl_win, "win", args, true, &err); + + if (!ERROR_SET(&err) && api_is_truthy(ret, "luahl_window retval", &err)) { + do_luahl_line = true; + decorations_active = true; + } + if (ERROR_SET(&err)) { ELOG("error in luahl window: %s", err.msg); api_clear_error(&err); @@ -1448,24 +1456,19 @@ static void win_update(win_T *wp) * Otherwise, display normally (can be several display lines when * 'wrap' is on). */ - fold_count = foldedCount(wp, lnum, &win_foldinfo); - if (fold_count != 0) { - fold_line(wp, fold_count, &win_foldinfo, lnum, row); - ++row; - --fold_count; - wp->w_lines[idx].wl_folded = TRUE; - wp->w_lines[idx].wl_lastlnum = lnum + fold_count; - did_update = DID_FOLD; - } else if (idx < wp->w_lines_valid - && wp->w_lines[idx].wl_valid - && wp->w_lines[idx].wl_lnum == lnum - && lnum > wp->w_topline - && !(dy_flags & (DY_LASTLINE | DY_TRUNCATE)) - && srow + wp->w_lines[idx].wl_size > wp->w_grid.Rows - && diff_check_fill(wp, lnum) == 0 - ) { - /* This line is not going to fit. Don't draw anything here, - * will draw "@ " lines below. */ + foldinfo_T foldinfo = fold_info(wp, lnum); + + if (foldinfo.fi_lines == 0 + && idx < wp->w_lines_valid + && wp->w_lines[idx].wl_valid + && wp->w_lines[idx].wl_lnum == lnum + && lnum > wp->w_topline + && !(dy_flags & (DY_LASTLINE | DY_TRUNCATE)) + && srow + wp->w_lines[idx].wl_size > wp->w_grid.Rows + && diff_check_fill(wp, lnum) == 0 + ) { + // This line is not going to fit. Don't draw anything here, + // will draw "@ " lines below. row = wp->w_grid.Rows + 1; } else { prepare_search_hl(wp, lnum); @@ -1474,14 +1477,21 @@ static void win_update(win_T *wp) && syntax_present(wp)) syntax_end_parsing(syntax_last_parsed + 1); - /* - * Display one line. - */ - row = win_line(wp, lnum, srow, wp->w_grid.Rows, mod_top == 0, false); + // Display one line + row = win_line(wp, lnum, srow, + foldinfo.fi_lines ? srow : wp->w_grid.Rows, + mod_top == 0, false, foldinfo); - wp->w_lines[idx].wl_folded = FALSE; + wp->w_lines[idx].wl_folded = foldinfo.fi_lines != 0; wp->w_lines[idx].wl_lastlnum = lnum; did_update = DID_LINE; + + if (foldinfo.fi_lines > 0) { + did_update = DID_FOLD; + foldinfo.fi_lines--; + wp->w_lines[idx].wl_lastlnum = lnum + foldinfo.fi_lines; + } + syntax_last_parsed = lnum; } @@ -1496,20 +1506,17 @@ static void win_update(win_T *wp) idx++; break; } - if (dollar_vcol == -1) + if (dollar_vcol == -1) { wp->w_lines[idx].wl_size = row - srow; - ++idx; - lnum += fold_count + 1; + } + idx++; + lnum += foldinfo.fi_lines + 1; } else { if (wp->w_p_rnu) { // 'relativenumber' set: The text doesn't need to be drawn, but // the number column nearly always does. - fold_count = foldedCount(wp, lnum, &win_foldinfo); - if (fold_count != 0) { - fold_line(wp, fold_count, &win_foldinfo, lnum, row); - } else { - (void)win_line(wp, lnum, srow, wp->w_grid.Rows, true, true); - } + foldinfo_T info = fold_info(wp, lnum); + (void)win_line(wp, lnum, srow, wp->w_grid.Rows, true, true, info); } // This line does not need to be drawn, advance to the next one. @@ -1741,31 +1748,6 @@ static int advance_color_col(int vcol, int **color_cols) return **color_cols >= 0; } -// Returns the next grid column. -static int text_to_screenline(win_T *wp, char_u *text, int col, int off) - FUNC_ATTR_NONNULL_ALL -{ - int idx = wp->w_p_rl ? off : off + col; - LineState s = LINE_STATE(text); - - while (*s.p != NUL) { - // TODO(bfredl): cargo-culted from the old Vim code: - // if(col + cells > wp->w_width - (wp->w_p_rl ? col : 0)) { break; } - // This is obvious wrong. If Vim ever fixes this, solve for "cells" again - // in the correct condition. - const int maxcells = wp->w_grid.Columns - col - (wp->w_p_rl ? col : 0); - const int cells = line_putchar(&s, &linebuf_char[idx], maxcells, - wp->w_p_rl); - if (cells == -1) { - break; - } - col += cells; - idx += cells; - } - - return col; -} - // Compute the width of the foldcolumn. Based on 'foldcolumn' and how much // space is available for window "wp", minus "col". static int compute_foldcolumn(win_T *wp, int col) @@ -1830,271 +1812,6 @@ static int line_putchar(LineState *s, schar_T *dest, int maxcells, bool rl) return cells; } -/* - * Display one folded line. - */ -static void fold_line(win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T lnum, int row) -{ - char_u buf[FOLD_TEXT_LEN]; - pos_T *top, *bot; - linenr_T lnume = lnum + fold_count - 1; - int len; - char_u *text; - int fdc; - int col; - int txtcol; - int off; - - /* Build the fold line: - * 1. Add the cmdwin_type for the command-line window - * 2. Add the 'foldcolumn' - * 3. Add the 'number' or 'relativenumber' column - * 4. Compose the text - * 5. Add the text - * 6. set highlighting for the Visual area an other text - */ - col = 0; - off = 0; - - /* - * 1. Add the cmdwin_type for the command-line window - * Ignores 'rightleft', this window is never right-left. - */ - if (cmdwin_type != 0 && wp == curwin) { - schar_from_ascii(linebuf_char[off], cmdwin_type); - linebuf_attr[off] = win_hl_attr(wp, HLF_AT); - col++; - } - -# define RL_MEMSET(p, v, l) \ - do { \ - if (wp->w_p_rl) { \ - for (int ri = 0; ri < l; ri++) { \ - linebuf_attr[off + (wp->w_grid.Columns - (p) - (l)) + ri] = v; \ - } \ - } else { \ - for (int ri = 0; ri < l; ri++) { \ - linebuf_attr[off + (p) + ri] = v; \ - } \ - } \ - } while (0) - - // 2. Add the 'foldcolumn' - // Reduce the width when there is not enough space. - fdc = compute_foldcolumn(wp, col); - if (fdc > 0) { - fill_foldcolumn(buf, wp, true, lnum); - const char_u *it = &buf[0]; - for (int i = 0; i < fdc; i++) { - int mb_c = mb_ptr2char_adv(&it); - if (wp->w_p_rl) { - schar_from_char(linebuf_char[off + wp->w_grid.Columns - i - 1 - col], - mb_c); - } else { - schar_from_char(linebuf_char[off + col + i], mb_c); - } - } - RL_MEMSET(col, win_hl_attr(wp, HLF_FC), fdc); - col += fdc; - } - - /* Set all attributes of the 'number' or 'relativenumber' column and the - * text */ - RL_MEMSET(col, win_hl_attr(wp, HLF_FL), wp->w_grid.Columns - col); - - // If signs are being displayed, add spaces. - if (win_signcol_count(wp) > 0) { - len = wp->w_grid.Columns - col; - if (len > 0) { - int len_max = win_signcol_width(wp) * win_signcol_count(wp); - if (len > len_max) { - len = len_max; - } - char_u space_buf[18] = " "; - assert((size_t)len_max <= sizeof(space_buf)); - copy_text_attr(off + col, space_buf, len, - win_hl_attr(wp, HLF_FL)); - col += len; - } - } - - /* - * 3. Add the 'number' or 'relativenumber' column - */ - if (wp->w_p_nu || wp->w_p_rnu) { - len = wp->w_grid.Columns - col; - if (len > 0) { - int w = number_width(wp); - long num; - char *fmt = "%*ld "; - - if (len > w + 1) - len = w + 1; - - if (wp->w_p_nu && !wp->w_p_rnu) - /* 'number' + 'norelativenumber' */ - num = (long)lnum; - else { - /* 'relativenumber', don't use negative numbers */ - num = labs((long)get_cursor_rel_lnum(wp, lnum)); - if (num == 0 && wp->w_p_nu && wp->w_p_rnu) { - /* 'number' + 'relativenumber': cursor line shows absolute - * line number */ - num = lnum; - fmt = "%-*ld "; - } - } - - snprintf((char *)buf, FOLD_TEXT_LEN, fmt, w, num); - if (wp->w_p_rl) { - // the line number isn't reversed - copy_text_attr(off + wp->w_grid.Columns - len - col, buf, len, - win_hl_attr(wp, HLF_FL)); - } else { - copy_text_attr(off + col, buf, len, win_hl_attr(wp, HLF_FL)); - } - col += len; - } - } - - /* - * 4. Compose the folded-line string with 'foldtext', if set. - */ - text = get_foldtext(wp, lnum, lnume, foldinfo, buf); - - txtcol = col; /* remember where text starts */ - - // 5. move the text to linebuf_char[off]. Fill up with "fold". - // Right-left text is put in columns 0 - number-col, normal text is put - // in columns number-col - window-width. - col = text_to_screenline(wp, text, col, off); - - /* Fill the rest of the line with the fold filler */ - if (wp->w_p_rl) - col -= txtcol; - - schar_T sc; - schar_from_char(sc, wp->w_p_fcs_chars.fold); - while (col < wp->w_grid.Columns - - (wp->w_p_rl ? txtcol : 0) - ) { - schar_copy(linebuf_char[off+col++], sc); - } - - if (text != buf) - xfree(text); - - /* - * 6. set highlighting for the Visual area an other text. - * If all folded lines are in the Visual area, highlight the line. - */ - if (VIsual_active && wp->w_buffer == curwin->w_buffer) { - if (ltoreq(curwin->w_cursor, VIsual)) { - /* Visual is after curwin->w_cursor */ - top = &curwin->w_cursor; - bot = &VIsual; - } else { - /* Visual is before curwin->w_cursor */ - top = &VIsual; - bot = &curwin->w_cursor; - } - if (lnum >= top->lnum - && lnume <= bot->lnum - && (VIsual_mode != 'v' - || ((lnum > top->lnum - || (lnum == top->lnum - && top->col == 0)) - && (lnume < bot->lnum - || (lnume == bot->lnum - && (bot->col - (*p_sel == 'e')) - >= (colnr_T)STRLEN(ml_get_buf(wp->w_buffer, lnume, - FALSE))))))) { - if (VIsual_mode == Ctrl_V) { - // Visual block mode: highlight the chars part of the block - if (wp->w_old_cursor_fcol + txtcol < (colnr_T)wp->w_grid.Columns) { - if (wp->w_old_cursor_lcol != MAXCOL - && wp->w_old_cursor_lcol + txtcol - < (colnr_T)wp->w_grid.Columns) { - len = wp->w_old_cursor_lcol; - } else { - len = wp->w_grid.Columns - txtcol; - } - RL_MEMSET(wp->w_old_cursor_fcol + txtcol, win_hl_attr(wp, HLF_V), - len - (int)wp->w_old_cursor_fcol); - } - } else { - // Set all attributes of the text - RL_MEMSET(txtcol, win_hl_attr(wp, HLF_V), wp->w_grid.Columns - txtcol); - } - } - } - - // Show colorcolumn in the fold line, but let cursorcolumn override it. - if (wp->w_p_cc_cols) { - int i = 0; - int j = wp->w_p_cc_cols[i]; - int old_txtcol = txtcol; - - while (j > -1) { - txtcol += j; - if (wp->w_p_wrap) { - txtcol -= wp->w_skipcol; - } else { - txtcol -= wp->w_leftcol; - } - if (txtcol >= 0 && txtcol < wp->w_grid.Columns) { - linebuf_attr[off + txtcol] = - hl_combine_attr(linebuf_attr[off + txtcol], win_hl_attr(wp, HLF_MC)); - } - txtcol = old_txtcol; - j = wp->w_p_cc_cols[++i]; - } - } - - /* Show 'cursorcolumn' in the fold line. */ - if (wp->w_p_cuc) { - txtcol += wp->w_virtcol; - if (wp->w_p_wrap) - txtcol -= wp->w_skipcol; - else - txtcol -= wp->w_leftcol; - if (txtcol >= 0 && txtcol < wp->w_grid.Columns) { - linebuf_attr[off + txtcol] = hl_combine_attr( - linebuf_attr[off + txtcol], win_hl_attr(wp, HLF_CUC)); - } - } - - grid_put_linebuf(&wp->w_grid, row, 0, wp->w_grid.Columns, wp->w_grid.Columns, - false, wp, wp->w_hl_attr_normal, false); - - /* - * Update w_cline_height and w_cline_folded if the cursor line was - * updated (saves a call to plines() later). - */ - if (wp == curwin - && lnum <= curwin->w_cursor.lnum - && lnume >= curwin->w_cursor.lnum) { - curwin->w_cline_row = row; - curwin->w_cline_height = 1; - curwin->w_cline_folded = true; - curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); - conceal_cursor_used = conceal_cursor_line(curwin); - } -} - - -/// Copy "buf[len]" to linebuf_char["off"] and set attributes to "attr". -/// -/// Only works for ASCII text! -static void copy_text_attr(int off, char_u *buf, int len, int attr) -{ - int i; - - for (i = 0; i < len; i++) { - schar_from_ascii(linebuf_char[off + i], buf[i]); - linebuf_attr[off + i] = attr; - } -} /// Fills the foldcolumn at "p" for window "wp". /// Only to be called when 'foldcolumn' > 0. @@ -2109,7 +1826,7 @@ static size_t fill_foldcolumn( char_u *p, win_T *wp, - int closed, + foldinfo_T foldinfo, linenr_T lnum ) { @@ -2120,10 +1837,11 @@ fill_foldcolumn( size_t char_counter = 0; int symbol = 0; int len = 0; + bool closed = foldinfo.fi_lines > 0; // Init to all spaces. memset(p, ' ', MAX_MCO * fdc + 1); - level = win_foldinfo.fi_level; + level = foldinfo.fi_level; // If the column is too narrow, we start at the lowest level that // fits and use numbers to indicated the depth. @@ -2133,8 +1851,8 @@ fill_foldcolumn( } for (i = 0; i < MIN(fdc, level); i++) { - if (win_foldinfo.fi_lnum == lnum - && first_level + i >= win_foldinfo.fi_low_level) { + if (foldinfo.fi_lnum == lnum + && first_level + i >= foldinfo.fi_low_level) { symbol = wp->w_p_fcs_chars.foldopen; } else if (first_level == 1) { symbol = wp->w_p_fcs_chars.foldsep; @@ -2165,21 +1883,27 @@ fill_foldcolumn( return MAX(char_counter + (fdc-i), (size_t)fdc); } -/* - * Display line "lnum" of window 'wp' on the screen. - * Start at row "startrow", stop when "endrow" is reached. - * wp->w_virtcol needs to be valid. - * - * Return the number of last row the line occupies. - */ + +/// Display line "lnum" of window 'wp' on the screen. +/// Start at row "startrow", stop when "endrow" is reached. +/// wp->w_virtcol needs to be valid. +/// +/// @param lnum line to display +/// @param endrow stop drawing once reaching this row +/// @param nochange not updating for changed text +/// @param number_only only update the number column +/// @param foldinfo fold info for this line +/// +/// @return the number of last row the line occupies. static int win_line ( win_T *wp, linenr_T lnum, int startrow, int endrow, - bool nochange, // not updating for changed text - bool number_only // only update the number column + bool nochange, + bool number_only, + foldinfo_T foldinfo ) { int c = 0; // init for GCC @@ -2284,6 +2008,8 @@ win_line ( bool has_decorations = false; // this buffer has decorations bool do_virttext = false; // draw virtual text for this line + char_u buf_fold[FOLD_TEXT_LEN + 1]; // Hold value returned by get_foldtext + /* draw_state: items that are drawn in sequence: */ #define WL_START 0 /* nothing done yet */ # define WL_CMDLINE WL_START + 1 /* cmdline window column */ @@ -2348,7 +2074,7 @@ win_line ( } if (decorations_active) { - if (buf->b_luahl && buf->b_luahl_line != LUA_NOREF) { + if (do_luahl_line && luahl_line != LUA_NOREF) { Error err = ERROR_INIT; FIXED_TEMP_ARRAY(args, 3); args.items[0] = WINDOW_OBJ(wp->handle); @@ -2356,14 +2082,10 @@ win_line ( args.items[2] = INTEGER_OBJ(lnum-1); lua_attr_active = true; extra_check = true; - Object o = nlua_call_ref(buf->b_luahl_line, "line", args, true, &err); + nlua_call_ref(luahl_line, "line", args, false, &err); lua_attr_active = false; - if (o.type == kObjectTypeString) { - // TODO(bfredl): this is a bit of a hack. A final API should use an - // "unified" interface where luahl can add both bufhl and virttext - luatext = o.data.string.data; - do_virttext = true; - } else if (ERROR_SET(&err)) { + + if (ERROR_SET(&err)) { ELOG("error in luahl line: %s", err.msg); luatext = err.msg; do_virttext = true; @@ -2839,7 +2561,7 @@ win_line ( // already be in use. xfree(p_extra_free); p_extra_free = xmalloc(MAX_MCO * fdc + 1); - n_extra = fill_foldcolumn(p_extra_free, wp, false, lnum); + n_extra = fill_foldcolumn(p_extra_free, wp, foldinfo, lnum); p_extra_free[n_extra] = NUL; p_extra = p_extra_free; c_extra = NUL; @@ -3065,6 +2787,41 @@ win_line ( break; } + if (draw_state == WL_LINE + && foldinfo.fi_level != 0 + && foldinfo.fi_lines > 0 + && vcol == 0 + && n_extra == 0 + && row == startrow) { + char_attr = win_hl_attr(wp, HLF_FL); + + linenr_T lnume = lnum + foldinfo.fi_lines - 1; + memset(buf_fold, ' ', FOLD_TEXT_LEN); + p_extra = get_foldtext(wp, lnum, lnume, foldinfo, buf_fold); + n_extra = STRLEN(p_extra); + + if (p_extra != buf_fold) { + xfree(p_extra_free); + p_extra_free = p_extra; + } + c_extra = NUL; + c_final = NUL; + p_extra[n_extra] = NUL; + } + + if (draw_state == WL_LINE + && foldinfo.fi_level != 0 + && foldinfo.fi_lines > 0 + && col < grid->Columns + && n_extra == 0 + && row == startrow) { + // fill rest of line with 'fold' + c_extra = wp->w_p_fcs_chars.fold; + c_final = NUL; + + n_extra = wp->w_p_rl ? (col + 1) : (grid->Columns - col); + } + if (draw_state == WL_LINE && (area_highlighting || has_spell)) { // handle Visual or match highlighting in this line if (vcol == fromcol @@ -3293,6 +3050,10 @@ win_line ( p_extra++; } n_extra--; + } else if (foldinfo.fi_lines > 0) { + // skip writing the buffer line itself + c = NUL; + XFREE_CLEAR(p_extra_free); } else { int c0; @@ -3861,7 +3622,7 @@ win_line ( // not showing the '>', put pointer back to avoid getting stuck ptr++; } - } + } // end of printing from buffer content /* In the cursor line and we may be concealing characters: correct * the cursor column when we reach its position. */ @@ -4171,11 +3932,10 @@ win_line ( if (wp == curwin && lnum == curwin->w_cursor.lnum) { curwin->w_cline_row = startrow; curwin->w_cline_height = row - startrow; - curwin->w_cline_folded = false; + curwin->w_cline_folded = foldinfo.fi_lines > 0; curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); conceal_cursor_used = conceal_cursor_line(curwin); } - break; } @@ -4364,6 +4124,7 @@ win_line ( * so far. If there is no more to display it is caught above. */ if ((wp->w_p_rl ? (col < 0) : (col >= grid->Columns)) + && foldinfo.fi_lines == 0 && (*ptr != NUL || filler_todo > 0 || (wp->w_p_list && wp->w_p_lcs_chars.eol != NUL diff --git a/src/nvim/search.c b/src/nvim/search.c index 23d84038d6..b053459c7f 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -96,12 +96,8 @@ static int lastc_bytelen = 1; // >1 for multi-byte char // copy of spats[], for keeping the search patterns while executing autocmds static struct spat saved_spats[2]; -// copy of spats[RE_SEARCH], for keeping the search patterns while incremental -// searching -static struct spat saved_last_search_spat; -static int did_save_last_search_spat = 0; -static int saved_last_idx = 0; -static bool saved_no_hlsearch = false; +static int saved_spats_last_idx = 0; +static bool saved_spats_no_hlsearch = false; static char_u *mr_pattern = NULL; // pattern used by search_regcomp() static int mr_pattern_alloced = false; // mr_pattern was allocated @@ -268,8 +264,8 @@ void save_search_patterns(void) saved_spats[1] = spats[1]; if (spats[1].pat != NULL) saved_spats[1].pat = vim_strsave(spats[1].pat); - saved_last_idx = last_idx; - saved_no_hlsearch = no_hlsearch; + saved_spats_last_idx = last_idx; + saved_spats_no_hlsearch = no_hlsearch; } } @@ -281,8 +277,8 @@ void restore_search_patterns(void) set_vv_searchforward(); free_spat(&spats[1]); spats[1] = saved_spats[1]; - last_idx = saved_last_idx; - set_no_hlsearch(saved_no_hlsearch); + last_idx = saved_spats_last_idx; + set_no_hlsearch(saved_spats_no_hlsearch); } } @@ -309,6 +305,13 @@ void free_search_patterns(void) #endif +// copy of spats[RE_SEARCH], for keeping the search patterns while incremental +// searching +static struct spat saved_last_search_spat; +static int did_save_last_search_spat = 0; +static int saved_last_idx = 0; +static bool saved_no_hlsearch = false; + /// Save and restore the search pattern for incremental highlight search /// feature. /// @@ -317,10 +320,9 @@ void free_search_patterns(void) /// cancelling incremental searching even if it's called inside user functions. void save_last_search_pattern(void) { - if (did_save_last_search_spat != 0) { - IEMSG("did_save_last_search_spat is not zero"); - } else { - did_save_last_search_spat++; + if (++did_save_last_search_spat != 1) { + // nested call, nothing to do + return; } saved_last_search_spat = spats[RE_SEARCH]; @@ -333,11 +335,15 @@ void save_last_search_pattern(void) void restore_last_search_pattern(void) { - if (did_save_last_search_spat != 1) { - IEMSG("did_save_last_search_spat is not one"); + if (--did_save_last_search_spat > 0) { + // nested call, nothing to do + return; + } + if (did_save_last_search_spat != 0) { + iemsg("restore_last_search_pattern() called more often than" + " save_last_search_pattern()"); return; } - did_save_last_search_spat--; xfree(spats[RE_SEARCH].pat); spats[RE_SEARCH] = saved_last_search_spat; @@ -488,7 +494,7 @@ void set_last_search_pat(const char_u *s, int idx, int magic, int setlast) saved_spats[idx].pat = NULL; else saved_spats[idx].pat = vim_strsave(spats[idx].pat); - saved_last_idx = last_idx; + saved_spats_last_idx = last_idx; } /* If 'hlsearch' set and search pat changed: need redraw. */ if (p_hls && idx == last_idx && !no_hlsearch) @@ -1149,8 +1155,8 @@ int do_search( pat = p; /* put pat after search command */ } - if ((options & SEARCH_ECHO) && messaging() - && !cmd_silent && msg_silent == 0) { + if ((options & SEARCH_ECHO) && messaging() && !msg_silent + && (!cmd_silent || !shortmess(SHM_SEARCHCOUNT))) { char_u *trunc; char_u off_buf[40]; size_t off_len = 0; @@ -1159,7 +1165,8 @@ int do_search( msg_start(); // Get the offset, so we know how long it is. - if (spats[0].off.line || spats[0].off.end || spats[0].off.off) { + if (!cmd_silent + && (spats[0].off.line || spats[0].off.end || spats[0].off.off)) { p = off_buf; // -V507 *p++ = dirc; if (spats[0].off.end) { @@ -1179,19 +1186,19 @@ int do_search( } if (*searchstr == NUL) { - p = spats[last_idx].pat; + p = spats[0].pat; } else { p = searchstr; } - if (!shortmess(SHM_SEARCHCOUNT)) { + if (!shortmess(SHM_SEARCHCOUNT) || cmd_silent) { // Reserve enough space for the search pattern + offset + // search stat. Use all the space available, so that the // search state is right aligned. If there is not enough space // msg_strtrunc() will shorten in the middle. if (ui_has(kUIMessages)) { len = 0; // adjusted below - } else if (msg_scrolled != 0) { + } else if (msg_scrolled != 0 && !cmd_silent) { // Use all the columns. len = (Rows - msg_row) * Columns - 1; } else { @@ -1208,11 +1215,13 @@ int do_search( xfree(msgbuf); msgbuf = xmalloc(len); - { - memset(msgbuf, ' ', len); - msgbuf[0] = dirc; - msgbuf[len - 1] = NUL; + memset(msgbuf, ' ', len); + msgbuf[len - 1] = NUL; + // do not fill the msgbuf buffer, if cmd_silent is set, leave it + // empty for the search_stat feature. + if (!cmd_silent) { + msgbuf[0] = dirc; if (utf_iscomposing(utf_ptr2char(p))) { // Use a space to draw the composing char on. msgbuf[1] = ' '; @@ -1356,12 +1365,15 @@ int do_search( // Show [1/15] if 'S' is not in 'shortmess'. if ((options & SEARCH_ECHO) && messaging() - && !(cmd_silent + msg_silent) + && !msg_silent && c != FAIL && !shortmess(SHM_SEARCHCOUNT) && msgbuf != NULL) { search_stat(dirc, &pos, show_top_bot_msg, msgbuf, - (count != 1 || has_offset)); + (count != 1 + || has_offset + || (!(fdo_flags & FDO_SEARCH) + && hasFolding(curwin->w_cursor.lnum, NULL, NULL)))); } // The search command can be followed by a ';' to do another search. @@ -4350,7 +4362,9 @@ static void search_stat(int dirc, pos_T *pos, len = STRLEN(t); if (show_top_bot_msg && len + 2 < SEARCH_STAT_BUF_LEN) { - STRCPY(t + len, " W"); + memmove(t + 2, t, len); + t[0] = 'W'; + t[1] = ' '; len += 2; } diff --git a/src/nvim/spell.c b/src/nvim/spell.c index dc1bfe25b4..f036d7fe04 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -362,6 +362,8 @@ size_t spell_check( size_t wrongcaplen = 0; int lpi; bool count_word = docount; + bool use_camel_case = *wp->w_s->b_p_spo != NUL; + bool camel_case = false; // A word never starts at a space or a control character. Return quickly // then, skipping over the character. @@ -394,9 +396,24 @@ size_t spell_check( mi.mi_word = ptr; mi.mi_fend = ptr; if (spell_iswordp(mi.mi_fend, wp)) { + int prev_upper; + int this_upper; + + if (use_camel_case) { + c = PTR2CHAR(mi.mi_fend); + this_upper = SPELL_ISUPPER(c); + } + do { MB_PTR_ADV(mi.mi_fend); - } while (*mi.mi_fend != NUL && spell_iswordp(mi.mi_fend, wp)); + if (use_camel_case) { + prev_upper = this_upper; + c = PTR2CHAR(mi.mi_fend); + this_upper = SPELL_ISUPPER(c); + camel_case = !prev_upper && this_upper; + } + } while (*mi.mi_fend != NUL && spell_iswordp(mi.mi_fend, wp) + && !camel_case); if (capcol != NULL && *capcol == 0 && wp->w_s->b_cap_prog != NULL) { // Check word starting with capital letter. @@ -428,6 +445,11 @@ size_t spell_check( (void)spell_casefold(ptr, (int)(mi.mi_fend - ptr), mi.mi_fword, MAXWLEN + 1); mi.mi_fwordlen = (int)STRLEN(mi.mi_fword); + if (camel_case) { + // introduce a fake word end space into the folded word. + mi.mi_fword[mi.mi_fwordlen - 1] = ' '; + } + // The word is bad unless we recognize it. mi.mi_result = SP_BAD; mi.mi_result2 = SP_BAD; diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 4aa7c21ce4..9a9cc45c6b 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -5588,9 +5588,11 @@ void ex_ownsyntax(exarg_T *eap) hash_init(&curwin->w_s->b_keywtab_ic); // TODO: Keep the spell checking as it was. NOLINT(readability/todo) curwin->w_p_spell = false; // No spell checking + // make sure option values are "empty_option" instead of NULL clear_string_option(&curwin->w_s->b_p_spc); clear_string_option(&curwin->w_s->b_p_spf); clear_string_option(&curwin->w_s->b_p_spl); + clear_string_option(&curwin->w_s->b_p_spo); clear_string_option(&curwin->w_s->b_syn_isk); } diff --git a/src/nvim/testdir/check.vim b/src/nvim/testdir/check.vim index 073873bcb0..e0ebe8fd49 100644 --- a/src/nvim/testdir/check.vim +++ b/src/nvim/testdir/check.vim @@ -65,3 +65,11 @@ func CheckCanRunGui() throw 'Skipped: cannot start the GUI' endif endfunc + +" Command to check that not currently using the GUI +command CheckNotGui call CheckNotGui() +func CheckNotGui() + if has('gui_running') + throw 'Skipped: only works in the terminal' + endif +endfunc diff --git a/src/nvim/testdir/shared.vim b/src/nvim/testdir/shared.vim index 6180d542ff..0d32f4d875 100644 --- a/src/nvim/testdir/shared.vim +++ b/src/nvim/testdir/shared.vim @@ -329,3 +329,17 @@ func RunVimPiped(before, after, arguments, pipecmd) endif return 1 endfunc + +" Get all messages but drop the maintainer entry. +func GetMessages() + redir => result + redraw | messages + redir END + let msg_list = split(result, "\n") + " if msg_list->len() > 0 && msg_list[0] =~ 'Messages maintainer:' + " return msg_list[1:] + " endif + return msg_list +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 3dd68873d4..094bb3ebd1 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -1,6 +1,8 @@ " Tests for autocommands source shared.vim +source check.vim +source term_util.vim func! s:cleanup_buffers() abort for bnr in range(1, bufnr('$')) @@ -1735,6 +1737,35 @@ func Test_throw_in_BufWritePre() au! throwing endfunc +func Test_autocmd_CmdWinEnter() + CheckRunVimInTerminal + " There is not cmdwin switch, so + " test for cmdline_hist + " (both are available with small builds) + CheckFeature cmdline_hist + let lines =<< trim END + let b:dummy_var = 'This is a dummy' + autocmd CmdWinEnter * quit + let winnr = winnr('$') + END + let filename='XCmdWinEnter' + call writefile(lines, filename) + let buf = RunVimInTerminal('-S '.filename, #{rows: 6}) + + call term_sendkeys(buf, "q:") + call term_wait(buf) + call term_sendkeys(buf, ":echo b:dummy_var\<cr>") + call WaitForAssert({-> assert_match('^This is a dummy', term_getline(buf, 6))}, 1000) + call term_sendkeys(buf, ":echo &buftype\<cr>") + call WaitForAssert({-> assert_notmatch('^nofile', term_getline(buf, 6))}, 1000) + call term_sendkeys(buf, ":echo winnr\<cr>") + call WaitForAssert({-> assert_match('^1', term_getline(buf, 6))}, 1000) + + " clean up + call StopVimInTerminal(buf) + call delete(filename) +endfunc + func Test_FileChangedShell_reload() if !has('unix') return diff --git a/src/nvim/testdir/test_edit.vim b/src/nvim/testdir/test_edit.vim index 12d5d9790e..7f456ffbce 100644 --- a/src/nvim/testdir/test_edit.vim +++ b/src/nvim/testdir/test_edit.vim @@ -1,9 +1,11 @@ " Test for edit functions -" + if exists("+t_kD") let &t_kD="[3;*~" endif +source check.vim + " Needed for testing basic rightleft: Test_edit_rightleft source view_util.vim @@ -733,17 +735,16 @@ func! Test_edit_CTRL_O() endfunc func! Test_edit_CTRL_R() - throw 'skipped: Nvim does not support test_override()' " Insert Register new - call test_override("ALL", 1) + " call test_override("ALL", 1) set showcmd call feedkeys("AFOOBAR eins zwei\<esc>", 'tnix') call feedkeys("O\<c-r>.", 'tnix') call feedkeys("O\<c-r>=10*500\<cr>\<esc>", 'tnix') call feedkeys("O\<c-r>=getreg('=', 1)\<cr>\<esc>", 'tnix') call assert_equal(["getreg('=', 1)", '5000', "FOOBAR eins zwei", "FOOBAR eins zwei"], getline(1, '$')) - call test_override("ALL", 0) + " call test_override("ALL", 0) set noshowcmd bw! endfunc @@ -955,7 +956,6 @@ func! Test_edit_DROP() endfunc func! Test_edit_CTRL_V() - throw 'skipped: Nvim does not support test_override()' if has("ebcdic") return endif @@ -965,7 +965,7 @@ func! Test_edit_CTRL_V() " force some redraws set showmode showcmd "call test_override_char_avail(1) - call test_override('ALL', 1) + " call test_override('ALL', 1) call feedkeys("A\<c-v>\<c-n>\<c-v>\<c-l>\<c-v>\<c-b>\<esc>", 'tnix') call assert_equal(["abc\x0e\x0c\x02"], getline(1, '$')) @@ -978,7 +978,7 @@ func! Test_edit_CTRL_V() set norl endif - call test_override('ALL', 0) + " call test_override('ALL', 0) set noshowmode showcmd bw! endfunc @@ -1514,3 +1514,23 @@ func Test_edit_startinsert() set backspace& bwipe! endfunc + +func Test_edit_noesckeys() + CheckNotGui + new + + " <Left> moves cursor when 'esckeys' is set + exe "set t_kl=\<Esc>OD" + " set esckeys + call feedkeys("axyz\<Esc>ODX", "xt") + " call assert_equal("xyXz", getline(1)) + + " <Left> exits Insert mode when 'esckeys' is off + " set noesckeys + call setline(1, '') + call feedkeys("axyz\<Esc>ODX", "xt") + call assert_equal(["DX", "xyz"], getline(1, 2)) + + bwipe! + " set esckeys +endfunc diff --git a/src/nvim/testdir/test_environ.vim b/src/nvim/testdir/test_environ.vim index 21bb09a690..a25d83753c 100644 --- a/src/nvim/testdir/test_environ.vim +++ b/src/nvim/testdir/test_environ.vim @@ -1,5 +1,9 @@ +" Test for environment variables. + scriptencoding utf-8 +source check.vim + func Test_environ() unlet! $TESTENV call assert_equal(0, has_key(environ(), 'TESTENV')) @@ -42,3 +46,24 @@ func Test_external_env() endif call assert_equal('', result) endfunc + +func Test_mac_locale() + CheckFeature osxdarwin + + " If $LANG is not set then the system locale will be used. + " Run Vim after unsetting all the locale environmental vars, and capture the + " output of :lang. + let lang_results = system("unset LANG; unset LC_MESSAGES; " .. + \ shellescape(v:progpath) .. + \ " --clean -esX -c 'redir @a' -c 'lang' -c 'put a' -c 'print' -c 'qa!' ") + + " Check that: + " 1. The locale is the form of <locale>.UTF-8. + " 2. Check that fourth item (LC_NUMERIC) is properly set to "C". + " Example match: "en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8" + call assert_match('"\([a-zA-Z_]\+\.UTF-8/\)\{3}C\(/[a-zA-Z_]\+\.UTF-8\)\{2}"', + \ lang_results, + \ "Default locale should have UTF-8 encoding set, and LC_NUMERIC set to 'C'") +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index 617e3dfe41..9f8939f2f6 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -326,7 +326,7 @@ let s:filename_checks = { \ 'pamconf': ['/etc/pam.conf'], \ 'pamenv': ['/etc/security/pam_env.conf', '/home/user/.pam_environment'], \ 'papp': ['file.papp', 'file.pxml', 'file.pxsl'], - \ 'pascal': ['file.pas', 'file.dpr'], + \ 'pascal': ['file.pas', 'file.pp', 'file.dpr', 'file.lpr'], \ 'passwd': ['any/etc/passwd', 'any/etc/passwd-', 'any/etc/passwd.edit', 'any/etc/shadow', 'any/etc/shadow-', 'any/etc/shadow.edit', 'any/var/backups/passwd.bak', 'any/var/backups/shadow.bak'], \ 'pccts': ['file.g'], \ 'pdf': ['file.pdf'], @@ -455,7 +455,7 @@ let s:filename_checks = { \ 'texmf': ['texmf.cnf'], \ 'text': ['file.text', 'README'], \ 'tf': ['file.tf', '.tfrc', 'tfrc'], - \ 'tidy': ['.tidyrc', 'tidyrc'], + \ 'tidy': ['.tidyrc', 'tidyrc', 'tidy.conf'], \ 'tilde': ['file.t.html'], \ 'tli': ['file.tli'], \ 'tmux': ['tmuxfile.conf', '.tmuxfile.conf'], diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 6b45ac61d1..8fa70a5313 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -1221,6 +1221,24 @@ func Test_reg_executing_and_recording() unlet s:reg_stat endfunc +func Test_getchar() + call feedkeys('a', '') + call assert_equal(char2nr('a'), getchar()) + + " call test_setmouse(1, 3) + " let v:mouse_win = 9 + " let v:mouse_winid = 9 + " let v:mouse_lnum = 9 + " let v:mouse_col = 9 + " call feedkeys("\<S-LeftMouse>", '') + call nvim_input_mouse('left', 'press', 'S', 0, 0, 2) + call assert_equal("\<S-LeftMouse>", getchar()) + call assert_equal(1, v:mouse_win) + call assert_equal(win_getid(1), v:mouse_winid) + call assert_equal(1, v:mouse_lnum) + call assert_equal(3, v:mouse_col) +endfunc + func Test_libcall_libcallnr() if !has('libcall') return @@ -1341,3 +1359,22 @@ func Test_readdir() call delete('Xdir', 'rf') endfunc + +" Test for the eval() function +func Test_eval() + call assert_fails("call eval('5 a')", 'E488:') +endfunc + +" Test for the nr2char() function +func Test_nr2char() + " set encoding=latin1 + call assert_equal('@', nr2char(64)) + set encoding=utf8 + call assert_equal('a', nr2char(97, 1)) + call assert_equal('a', nr2char(97, 0)) + + call assert_equal("\x80\xfc\b\xf4\x80\xfeX\x80\xfeX\x80\xfeX", eval('"\<M-' .. nr2char(0x100000) .. '>"')) + call assert_equal("\x80\xfc\b\xfd\x80\xfeX\x80\xfeX\x80\xfeX\x80\xfeX\x80\xfeX", eval('"\<M-' .. nr2char(0x40000000) .. '>"')) +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_gf.vim b/src/nvim/testdir/test_gf.vim index 4a4ffcefa1..ee548037ba 100644 --- a/src/nvim/testdir/test_gf.vim +++ b/src/nvim/testdir/test_gf.vim @@ -1,3 +1,4 @@ +" Test for the gf and gF (goto file) commands " This is a test if a URL is recognized by "gf", with the cursor before and " after the "://". Also test ":\\". @@ -109,7 +110,7 @@ func Test_gf() endfunc func Test_gf_visual() - call writefile([], "Xtest_gf_visual") + call writefile(['one', 'two', 'three', 'four'], "Xtest_gf_visual") new call setline(1, 'XXXtest_gf_visualXXX') set hidden @@ -118,6 +119,30 @@ func Test_gf_visual() norm! ttvtXgf call assert_equal('Xtest_gf_visual', bufname('%')) + " if multiple lines are selected, then gf should fail + call setline(1, ["one", "two"]) + normal VGgf + call assert_equal('Xtest_gf_visual', @%) + + " following line number is used for gF + bwipe! + new + call setline(1, 'XXXtest_gf_visual:3XXX') + norm! 0ttvt:gF + call assert_equal('Xtest_gf_visual', bufname('%')) + call assert_equal(3, getcurpos()[1]) + + " line number in visual area is used for file name + if has('unix') + bwipe! + call writefile([], "Xtest_gf_visual:3") + new + call setline(1, 'XXXtest_gf_visual:3XXX') + norm! 0ttvtXgF + call assert_equal('Xtest_gf_visual:3', bufname('%')) + call delete('Xtest_gf_visual:3') + endif + bwipe! call delete('Xtest_gf_visual') set hidden& diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index 926103b69f..eeec5bd2c3 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -2450,6 +2450,22 @@ func Test_vimgrep() call XvimgrepTests('l') endfunc +" Test for incsearch highlighting of the :vimgrep pattern +" This test used to cause "E315: ml_get: invalid lnum" errors. +func Test_vimgrep_incsearch() + throw 'skipped: Nvim does not support test_override()' + enew + set incsearch + call test_override("char_avail", 1) + + call feedkeys(":2vimgrep assert test_quickfix.vim test_cdo.vim\<CR>", "ntx") + let l = getqflist() + call assert_equal(2, len(l)) + + call test_override("ALL", 0) + set noincsearch +endfunc + func XfreeTests(cchar) call s:setup_commands(a:cchar) diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim index 767cf99be3..211fc73562 100644 --- a/src/nvim/testdir/test_search.vim +++ b/src/nvim/testdir/test_search.vim @@ -244,6 +244,10 @@ func Test_search_cmdline2() " go to previous match (on line 2) call feedkeys("/the\<C-G>\<C-G>\<C-G>\<C-T>\<C-T>\<C-T>\<cr>", 'tx') call assert_equal(' 2 these', getline('.')) + 1 + " go to previous match (on line 2) + call feedkeys("/the\<C-G>\<C-R>\<C-W>\<cr>", 'tx') + call assert_equal('theother', @/) " Test 2: keep the view, " after deleting a character from the search cmd @@ -255,7 +259,7 @@ func Test_search_cmdline2() call assert_equal({'lnum': 10, 'leftcol': 0, 'col': 4, 'topfill': 0, 'topline': 6, 'coladd': 0, 'skipcol': 0, 'curswant': 4}, winsaveview()) " remove all history entries - for i in range(10) + for i in range(11) call histdel('/') endfor @@ -489,14 +493,14 @@ func Test_search_cmdline5() " Do not call test_override("char_avail", 1) so that <C-g> and <C-t> work " regardless char_avail. new - call setline(1, [' 1 the first', ' 2 the second', ' 3 the third']) + call setline(1, [' 1 the first', ' 2 the second', ' 3 the third', '']) set incsearch 1 call feedkeys("/the\<c-g>\<c-g>\<cr>", 'tx') call assert_equal(' 3 the third', getline('.')) $ call feedkeys("?the\<c-t>\<c-t>\<c-t>\<cr>", 'tx') - call assert_equal(' 2 the second', getline('.')) + call assert_equal(' 1 the first', getline('.')) " clean up set noincsearch bw! @@ -704,6 +708,19 @@ func Test_incsearch_substitute_dump() call VerifyScreenDump(buf, 'Test_incsearch_substitute_12', {}) call term_sendkeys(buf, "\<Esc>") call VerifyScreenDump(buf, 'Test_incsearch_substitute_13', {}) + call term_sendkeys(buf, ":%bwipe!\<CR>") + call term_sendkeys(buf, ":only!\<CR>") + + " get :'<,'>s command in history + call term_sendkeys(buf, ":set cmdheight=2\<CR>") + call term_sendkeys(buf, "aasdfasdf\<Esc>") + call term_sendkeys(buf, "V:s/a/b/g\<CR>") + " Using '<,'> does not give E20 + call term_sendkeys(buf, ":new\<CR>") + call term_sendkeys(buf, "aasdfasdf\<Esc>") + call term_sendkeys(buf, ":\<Up>\<Up>") + call VerifyScreenDump(buf, 'Test_incsearch_substitute_14', {}) + call term_sendkeys(buf, "<Esc>") call StopVimInTerminal(buf) call delete('Xis_subst_script') @@ -726,11 +743,14 @@ func Test_incsearch_sort_dump() " the 'ambiwidth' check. sleep 100m - " Need to send one key at a time to force a redraw. call term_sendkeys(buf, ':sort ni u /on') call VerifyScreenDump(buf, 'Test_incsearch_sort_01', {}) call term_sendkeys(buf, "\<Esc>") + call term_sendkeys(buf, ':sort! /on') + call VerifyScreenDump(buf, 'Test_incsearch_sort_02', {}) + call term_sendkeys(buf, "\<Esc>") + call StopVimInTerminal(buf) call delete('Xis_sort_script') endfunc @@ -861,6 +881,21 @@ func Test_incsearch_with_change() call delete('Xis_change_script') endfunc +func Test_incsearch_cmdline_modifier() + throw 'skipped: Nvim does not support test_override()' + if !exists('+incsearch') + return + endif + call test_override("char_avail", 1) + new + call setline(1, ['foo']) + set incsearch + " Test that error E14 does not occur in parsing command modifier. + call feedkeys("V:tab", 'tx') + + call Incsearch_cleanup() +endfunc + func Test_incsearch_scrolling() if !CanRunVimInTerminal() return @@ -982,6 +1017,40 @@ func Test_search_sentence() / endfunc +" Test that there is no crash when there is a last search pattern but no last +" substitute pattern. +func Test_no_last_substitute_pat() + " Use viminfo to set the last search pattern to a string and make the last + " substitute pattern the most recent used and make it empty (NULL). + call writefile(['~MSle0/bar', '~MSle0~&'], 'Xviminfo') + rviminfo! Xviminfo + call assert_fails('normal n', 'E35:') + + call delete('Xviminfo') +endfunc + +func Test_search_Ctrl_L_combining() + " Make sure, that Ctrl-L works correctly with combining characters. + " It uses an artificial example of an 'a' with 4 combining chars: + " 'a' U+0061 Dec:97 LATIN SMALL LETTER A a /\%u61\Z "\u0061" + " ' ̀' U+0300 Dec:768 COMBINING GRAVE ACCENT ̀ /\%u300\Z "\u0300" + " ' ́' U+0301 Dec:769 COMBINING ACUTE ACCENT ́ /\%u301\Z "\u0301" + " ' ̇' U+0307 Dec:775 COMBINING DOT ABOVE ̇ /\%u307\Z "\u0307" + " ' ̣' U+0323 Dec:803 COMBINING DOT BELOW ̣ /\%u323 "\u0323" + " Those should also appear on the commandline + if !has('multi_byte') || !exists('+incsearch') + return + endif + call Cmdline3_prep() + 1 + let bufcontent = ['', 'Miạ̀́̇m'] + call append('$', bufcontent) + call feedkeys("/Mi\<c-l>\<c-l>\<cr>", 'tx') + call assert_equal(5, line('.')) + call assert_equal(bufcontent[1], @/) + call Incsearch_cleanup() +endfunc + func Test_large_hex_chars1() " This used to cause a crash, the character becomes an NFA state. try @@ -1019,6 +1088,24 @@ func Test_one_error_msg() call assert_fails('call search(" \\((\\v[[=P=]]){185}+ ")', 'E871:') endfunc +func Test_incsearch_add_char_under_cursor() + throw 'skipped: Nvim does not support test_override()' + if !exists('+incsearch') + return + endif + set incsearch + new + call setline(1, ['find match', 'anything']) + 1 + call test_override('char_avail', 1) + call feedkeys("fc/m\<C-L>\<C-L>\<C-L>\<C-L>\<C-L>\<CR>", 'tx') + call assert_equal('match', @/) + call test_override('char_avail', 0) + + set incsearch& + bwipe! +endfunc + " Test for the search() function with match at the cursor position func Test_search_match_at_curpos() new diff --git a/src/nvim/testdir/test_search_stat.vim b/src/nvim/testdir/test_search_stat.vim index cf36f3214a..11c6489ca2 100644 --- a/src/nvim/testdir/test_search_stat.vim +++ b/src/nvim/testdir/test_search_stat.vim @@ -1,11 +1,9 @@ " Tests for search_stats, when "S" is not in 'shortmess' -" -" This test is fragile, it might not work interactively, but it works when run -" as test! -source shared.vim +source screendump.vim +source check.vim -func! Test_search_stat() +func Test_search_stat() new set shortmess-=S " Append 50 lines with text to search for, "foobar" appears 20 times @@ -45,7 +43,7 @@ func! Test_search_stat() call assert_match(pat .. stat, g:a) call cursor(line('$'), 1) let g:a = execute(':unsilent :norm! n') - let stat = '\[1/>99\] W' + let stat = 'W \[1/>99\]' call assert_match(pat .. stat, g:a) " Many matches @@ -55,7 +53,7 @@ func! Test_search_stat() call assert_match(pat .. stat, g:a) call cursor(1, 1) let g:a = execute(':unsilent :norm! N') - let stat = '\[>99/>99\] W' + let stat = 'W \[>99/>99\]' call assert_match(pat .. stat, g:a) " right-left @@ -87,7 +85,7 @@ func! Test_search_stat() call cursor('$',1) let pat = 'raboof/\s\+' let g:a = execute(':unsilent :norm! n') - let stat = '\[20/1\]' + let stat = 'W \[20/1\]' call assert_match(pat .. stat, g:a) call assert_match('search hit BOTTOM, continuing at TOP', g:a) set norl @@ -98,10 +96,10 @@ func! Test_search_stat() let @/ = 'foobar' let pat = '?foobar\s\+' let g:a = execute(':unsilent :norm! N') - let stat = '\[20/20\]' + let stat = 'W \[20/20\]' call assert_match(pat .. stat, g:a) call assert_match('search hit TOP, continuing at BOTTOM', g:a) - call assert_match('\[20/20\] W', Screenline(&lines)) + call assert_match('W \[20/20\]', Screenline(&lines)) " normal, no match call cursor(1,1) @@ -160,7 +158,115 @@ func! Test_search_stat() let stat = '\[1/2\]' call assert_notmatch(pat .. stat, g:a) - " close the window + " normal, n comes from a silent mapping + " First test a normal mapping, then a silent mapping + call cursor(1,1) + nnoremap n n + let @/ = 'find this' + let pat = '/find this\s\+' + let g:a = execute(':unsilent :norm n') + let g:b = split(g:a, "\n")[-1] + let stat = '\[1/2\]' + call assert_match(pat .. stat, g:b) + nnoremap <silent> n n + call cursor(1,1) + let g:a = execute(':unsilent :norm n') + let g:b = split(g:a, "\n")[-1] + let stat = '\[1/2\]' + call assert_notmatch(pat .. stat, g:b) + call assert_match(stat, g:b) + " Test that the message is not truncated + " it would insert '...' into the output. + call assert_match('^\s\+' .. stat, g:b) + unmap n + + " Clean up set shortmess+=S + " close the window bwipe! endfunc + +func Test_search_stat_foldopen() + CheckScreendump + + let lines =<< trim END + set shortmess-=S + setl foldenable foldmethod=indent foldopen-=search + call append(0, ['if', "\tfoo", "\tfoo", 'endif']) + let @/ = 'foo' + call cursor(1,1) + norm n + END + call writefile(lines, 'Xsearchstat1') + + let buf = RunVimInTerminal('-S Xsearchstat1', #{rows: 10}) + call TermWait(buf) + call VerifyScreenDump(buf, 'Test_searchstat_3', {}) + + call term_sendkeys(buf, "n") + call TermWait(buf) + call VerifyScreenDump(buf, 'Test_searchstat_3', {}) + + call term_sendkeys(buf, "n") + call TermWait(buf) + call VerifyScreenDump(buf, 'Test_searchstat_3', {}) + + call StopVimInTerminal(buf) + call delete('Xsearchstat1') +endfunc + +func! Test_search_stat_screendump() + CheckScreendump + + let lines =<< trim END + set shortmess-=S + " Append 50 lines with text to search for, "foobar" appears 20 times + call append(0, repeat(['foobar', 'foo', 'fooooobar', 'foba', 'foobar'], 20)) + call setline(2, 'find this') + call setline(70, 'find this') + nnoremap n n + let @/ = 'find this' + call cursor(1,1) + norm n + END + call writefile(lines, 'Xsearchstat') + let buf = RunVimInTerminal('-S Xsearchstat', #{rows: 10}) + call term_wait(buf) + call VerifyScreenDump(buf, 'Test_searchstat_1', {}) + + call term_sendkeys(buf, ":nnoremap <silent> n n\<cr>") + call term_sendkeys(buf, "gg0n") + call term_wait(buf) + call VerifyScreenDump(buf, 'Test_searchstat_2', {}) + + call StopVimInTerminal(buf) + call delete('Xsearchstat') +endfunc + +func Test_searchcount_in_statusline() + CheckScreendump + + let lines =<< trim END + set shortmess-=S + call append(0, 'this is something') + function TestSearchCount() abort + let search_count = searchcount() + if !empty(search_count) + return '[' . search_count.current . '/' . search_count.total . ']' + else + return '' + endif + endfunction + set hlsearch + set laststatus=2 statusline+=%{TestSearchCount()} + END + call writefile(lines, 'Xsearchstatusline') + let buf = RunVimInTerminal('-S Xsearchstatusline', #{rows: 10}) + call TermWait(buf) + call term_sendkeys(buf, "/something") + call VerifyScreenDump(buf, 'Test_searchstat_4', {}) + + call term_sendkeys(buf, "\<Esc>") + call StopVimInTerminal(buf) + call delete('Xsearchstatusline') +endfunc diff --git a/src/nvim/testdir/test_spell.vim b/src/nvim/testdir/test_spell.vim index 414c7278eb..ab8a998bb8 100644 --- a/src/nvim/testdir/test_spell.vim +++ b/src/nvim/testdir/test_spell.vim @@ -79,6 +79,11 @@ func Test_spellbadword() call assert_equal(['bycycle', 'bad'], spellbadword('My bycycle.')) call assert_equal(['another', 'caps'], spellbadword('A sentence. another sentence')) + call assert_equal(['TheCamelWord', 'bad'], spellbadword('TheCamelWord asdf')) + set spelloptions=camel + call assert_equal(['asdf', 'bad'], spellbadword('TheCamelWord asdf')) + set spelloptions= + set spelllang=en call assert_equal(['', ''], spellbadword('centre')) call assert_equal(['', ''], spellbadword('center')) @@ -113,6 +118,43 @@ foobar/? set spell& endfunc +func Test_spelllang_inv_region() + set spell spelllang=en_xx + let messages = GetMessages() + call assert_equal('Warning: region xx not supported', messages[-1]) + set spell& spelllang& +endfunc + +func Test_compl_with_CTRL_X_CTRL_K_using_spell() + " When spell checking is enabled and 'dictionary' is empty, + " CTRL-X CTRL-K in insert mode completes using the spelling dictionary. + new + set spell spelllang=en dictionary= + + set ignorecase + call feedkeys("Senglis\<c-x>\<c-k>\<esc>", 'tnx') + call assert_equal(['English'], getline(1, '$')) + call feedkeys("SEnglis\<c-x>\<c-k>\<esc>", 'tnx') + call assert_equal(['English'], getline(1, '$')) + + set noignorecase + call feedkeys("Senglis\<c-x>\<c-k>\<esc>", 'tnx') + call assert_equal(['englis'], getline(1, '$')) + call feedkeys("SEnglis\<c-x>\<c-k>\<esc>", 'tnx') + call assert_equal(['English'], getline(1, '$')) + + set spelllang=en_us + call feedkeys("Stheat\<c-x>\<c-k>\<esc>", 'tnx') + call assert_equal(['theater'], getline(1, '$')) + set spelllang=en_gb + call feedkeys("Stheat\<c-x>\<c-k>\<esc>", 'tnx') + " FIXME: commented out, expected theatre bug got theater. See issue #7025. + " call assert_equal(['theatre'], getline(1, '$')) + + bwipe! + set spell& spelllang& dictionary& ignorecase& +endfunc + func Test_spellreall() new set spell diff --git a/src/nvim/testdir/test_startup.vim b/src/nvim/testdir/test_startup.vim index 9abaca5957..12bec745a8 100644 --- a/src/nvim/testdir/test_startup.vim +++ b/src/nvim/testdir/test_startup.vim @@ -369,12 +369,11 @@ func Test_invalid_args() endfor if has('clientserver') - " FIXME: need to add --servername to this list - " but it causes vim-8.1.1282 to crash! for opt in ['--remote', '--remote-send', '--remote-silent', '--remote-expr', \ '--remote-tab', '--remote-tab-wait', \ '--remote-tab-wait-silent', '--remote-tab-silent', \ '--remote-wait', '--remote-wait-silent', + \ '--servername', \ ] let out = split(system(GetVimCommand() .. ' ' .. opt), "\n") call assert_equal(1, v:shell_error) @@ -384,14 +383,21 @@ func Test_invalid_args() endfor endif - " FIXME: commented out as this causes vim-8.1.1282 to crash! - "if has('clipboard') - " let out = split(system(GetVimCommand() .. ' --display'), "\n") - " call assert_equal(1, v:shell_error) - " call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) - " call assert_equal('Argument missing after: "--display"', out[1]) - " call assert_equal('More info with: "vim -h"', out[2]) - "endif + if has('gui_gtk') + let out = split(system(GetVimCommand() .. ' --display'), "\n") + call assert_equal(1, v:shell_error) + call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) + call assert_equal('Argument missing after: "--display"', out[1]) + call assert_equal('More info with: "vim -h"', out[2]) + endif + + if has('xterm_clipboard') + let out = split(system(GetVimCommand() .. ' -display'), "\n") + call assert_equal(1, v:shell_error) + call assert_match('^VIM - Vi IMproved .* (.*)$', out[0]) + call assert_equal('Argument missing after: "-display"', out[1]) + call assert_equal('More info with: "vim -h"', out[2]) + endif let out = split(system(GetVimCommand() .. ' -ix'), "\n") call assert_equal(1, v:shell_error) diff --git a/src/nvim/testdir/test_syntax.vim b/src/nvim/testdir/test_syntax.vim index 85ee42420e..2404f113d9 100644 --- a/src/nvim/testdir/test_syntax.vim +++ b/src/nvim/testdir/test_syntax.vim @@ -369,7 +369,11 @@ func Test_ownsyntax() call setline(1, '#define FOO') syntax on set filetype=c + ownsyntax perl + " this should not crash + set + call assert_equal('perlComment', synIDattr(synID(line('.'), col('.'), 1), 'name')) call assert_equal('c', b:current_syntax) call assert_equal('perl', w:current_syntax) diff --git a/src/nvim/testdir/test_timers.vim b/src/nvim/testdir/test_timers.vim index cffd80ff4f..d5ea54b764 100644 --- a/src/nvim/testdir/test_timers.vim +++ b/src/nvim/testdir/test_timers.vim @@ -233,16 +233,17 @@ func Test_timer_catch_error() endfunc func FeedAndPeek(timer) - call test_feedinput('a') + " call test_feedinput('a') + call nvim_input('a') call getchar(1) endfunc func Interrupt(timer) - call test_feedinput("\<C-C>") + " call test_feedinput("\<C-C>") + call nvim_input("\<C-C>") endfunc func Test_peek_and_get_char() - throw 'skipped: Nvim does not support test_feedinput()' if !has('unix') && !has('gui_running') return endif diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index dde17726fd..2ef9bf5a2e 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -1083,6 +1083,7 @@ static void tui_set_mode(UI *ui, ModeShape mode) } } else if (c.id == 0) { // No cursor color for this mode; reset to default. + data->want_invisible = false; unibi_out_ext(ui, data->unibi_ext.reset_cursor_color); } diff --git a/src/nvim/window.c b/src/nvim/window.c index cec0dfd67f..6608deb231 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -6019,6 +6019,12 @@ char_u *grab_file_name(long count, linenr_T *file_lnum) char_u *ptr; if (get_visual_text(NULL, &ptr, &len) == FAIL) return NULL; + // Only recognize ":123" here + if (file_lnum != NULL && ptr[len] == ':' && isdigit(ptr[len + 1])) { + char_u *p = ptr + len + 1; + + *file_lnum = getdigits_long(&p, false, 0); + } return find_file_name_in_path(ptr, len, options, count, curbuf->b_ffname); } return file_name_at_cursor(options | FNAME_HYP, count, file_lnum); diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index a2a188d036..ab913ba4a4 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -100,6 +100,15 @@ describe('API/extmarks', function() ns2 = request('nvim_create_namespace', "my-fancy-plugin2") end) + it("can end extranges past final newline using end_col = 0", function() + set_extmark(ns, marks[1], 0, 0, { + end_col = 0, + end_line = 1 + }) + eq("end_col value outside range", + pcall_err(set_extmark, ns, marks[2], 0, 0, { end_col = 1, end_line = 1 })) + end) + it('adds, updates and deletes marks', function() local rv = set_extmark(ns, marks[1], positions[1][1], positions[1][2]) eq(marks[1], rv) diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua index 57e6f4fd63..1155f12ffc 100644 --- a/test/functional/core/job_spec.lua +++ b/test/functional/core/job_spec.lua @@ -93,6 +93,7 @@ describe('jobs', function() {'notification', 'stdout', {0, {'hello world %VAR%', ''}}} }) else + nvim('command', "set shell=/bin/sh") nvim('command', [[call jobstart('echo $TOTO $VAR', g:job_opts)]]) expect_msg_seq({ {'notification', 'stdout', {0, {'hello world', ''}}} diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua index 5be47070a7..439cc12192 100644 --- a/test/functional/lua/buffer_updates_spec.lua +++ b/test/functional/lua/buffer_updates_spec.lua @@ -5,6 +5,7 @@ local inspect = require'vim.inspect' local command = helpers.command local meths = helpers.meths +local funcs = helpers.funcs local clear = helpers.clear local eq = helpers.eq local fail = helpers.fail @@ -256,9 +257,9 @@ describe('lua: nvim_buf_attach on_bytes', function() -- assert the wrong thing), but masks errors with unflushed lines (as -- nvim_buf_get_offset forces a flush of the memline). To be safe run the -- test both ways. - local function setup_eventcheck(verify) - meths.buf_set_lines(0, 0, -1, true, origlines) - local shadow = deepcopy(origlines) + local function setup_eventcheck(verify, start_txt) + meths.buf_set_lines(0, 0, -1, true, start_txt) + local shadow = deepcopy(start_txt) local shadowbytes = table.concat(shadow, '\n') .. '\n' -- TODO: while we are brewing the real strong coffe, -- verify should check buf_get_offset after every check_events @@ -273,7 +274,7 @@ describe('lua: nvim_buf_attach on_bytes', function() local events = exec_lua("return get_events(...)" ) if not pcall(eq, expected, events) then - local msg = 'unexpected byte updates received.\n\nBABBLA MER \n\n' + local msg = 'unexpected byte updates received.\n\n' msg = msg .. 'received events:\n' for _, e in ipairs(events) do @@ -286,26 +287,36 @@ describe('lua: nvim_buf_attach on_bytes', function() fail(msg) end - if verify then - for _, event in ipairs(events) do - if event[1] == verify_name and event[2] == "bytes" then - local _, _, _, _, _, _, start_byte, _, _, old_byte, _, _, new_byte = unpack(event) - local before = string.sub(shadowbytes, 1, start_byte) - -- no text in the tests will contain 0xff bytes (invalid UTF-8) - -- so we can use it as marker for unknown bytes - local unknown = string.rep('\255', new_byte) - local after = string.sub(shadowbytes, start_byte + old_byte + 1) - shadowbytes = before .. unknown .. after + if not verify then + return + end + + for _, event in ipairs(events) do + for _, elem in ipairs(event) do + if type(elem) == "number" and elem < 0 then + fail(string.format("Received event has negative values")) end end - local text = meths.buf_get_lines(0, 0, -1, true) - local bytes = table.concat(text, '\n') .. '\n' - eq(string.len(bytes), string.len(shadowbytes), shadowbytes) - for i = 1, string.len(shadowbytes) do - local shadowbyte = string.sub(shadowbytes, i, i) - if shadowbyte ~= '\255' then - eq(string.sub(bytes, i, i), shadowbyte, i) - end + + if event[1] == verify_name and event[2] == "bytes" then + local _, _, _, _, _, _, start_byte, _, _, old_byte, _, _, new_byte = unpack(event) + local before = string.sub(shadowbytes, 1, start_byte) + -- no text in the tests will contain 0xff bytes (invalid UTF-8) + -- so we can use it as marker for unknown bytes + local unknown = string.rep('\255', new_byte) + local after = string.sub(shadowbytes, start_byte + old_byte + 1) + shadowbytes = before .. unknown .. after + end + end + + local text = meths.buf_get_lines(0, 0, -1, true) + local bytes = table.concat(text, '\n') .. '\n' + + eq(string.len(bytes), string.len(shadowbytes), '\non_bytes: total bytecount of buffer is wrong') + for i = 1, string.len(shadowbytes) do + local shadowbyte = string.sub(shadowbytes, i, i) + if shadowbyte ~= '\255' then + eq(string.sub(bytes, i, i), shadowbyte, i) end end end @@ -316,7 +327,7 @@ describe('lua: nvim_buf_attach on_bytes', function() -- Yes, we can do both local function do_both(verify) it('single and multiple join', function() - local check_events = setup_eventcheck(verify) + local check_events = setup_eventcheck(verify, origlines) feed 'ggJ' check_events { {'test1', 'bytes', 1, 3, 0, 15, 15, 1, 0, 1, 0, 1, 1}; @@ -330,7 +341,7 @@ describe('lua: nvim_buf_attach on_bytes', function() end) it('opening lines', function() - local check_events = setup_eventcheck(verify) + local check_events = setup_eventcheck(verify, origlines) -- meths.buf_set_option(0, 'autoindent', true) feed 'Go' check_events { @@ -343,7 +354,7 @@ describe('lua: nvim_buf_attach on_bytes', function() end) it('opening lines with autoindent', function() - local check_events = setup_eventcheck(verify) + local check_events = setup_eventcheck(verify, origlines) meths.buf_set_option(0, 'autoindent', true) feed 'Go' check_events { @@ -355,6 +366,92 @@ describe('lua: nvim_buf_attach on_bytes', function() { "test1", "bytes", 1, 5, 7, 4, 118, 0, 0, 0, 1, 4, 5 }; } end) + + it('setline(num, line)', function() + local check_events = setup_eventcheck(verify, origlines) + funcs.setline(2, "babla") + check_events { + { "test1", "bytes", 1, 3, 1, 0, 16, 0, 15, 15, 0, 5, 5 }; + } + + funcs.setline(2, {"foo", "bar"}) + check_events { + { "test1", "bytes", 1, 4, 1, 0, 16, 0, 5, 5, 0, 3, 3 }; + { "test1", "bytes", 1, 5, 2, 0, 20, 0, 15, 15, 0, 3, 3 }; + } + + local buf_len = meths.buf_line_count(0) + funcs.setline(buf_len + 1, "baz") + check_events { + { "test1", "bytes", 1, 6, 7, 0, 90, 0, 0, 0, 1, 0, 4 }; + } + end) + + it('continuing comments with fo=or', function() + local check_events = setup_eventcheck(verify, {'// Comment'}) + meths.buf_set_option(0, 'formatoptions', 'ro') + meths.buf_set_option(0, 'filetype', 'c') + feed 'A<CR>' + check_events { + { "test1", "bytes", 1, 4, 0, 10, 10, 0, 0, 0, 1, 3, 4 }; + } + + feed '<ESC>' + check_events { + { "test1", "bytes", 1, 4, 1, 2, 13, 0, 1, 1, 0, 0, 0 }; + } + + feed 'ggo' -- goto first line to continue testing + check_events { + { "test1", "bytes", 1, 6, 1, 0, 11, 0, 0, 0, 1, 0, 4 }; + } + + feed '<CR>' + check_events { + { "test1", "bytes", 1, 6, 2, 2, 16, 0, 1, 1, 0, 0, 0 }; + { "test1", "bytes", 1, 7, 1, 3, 14, 0, 0, 0, 1, 3, 4 }; + } + end) + + it('editing empty buffers', function() + local check_events = setup_eventcheck(verify, {}) + + feed 'ia' + check_events { + { "test1", "bytes", 1, 3, 0, 0, 0, 0, 0, 0, 0, 1, 1 }; + } + end) + + it("changing lines", function() + local check_events = setup_eventcheck(verify, origlines) + + feed "cc" + check_events { + { "test1", "bytes", 1, 4, 0, 0, 0, 0, 15, 15, 0, 0, 0 }; + } + + feed "<ESC>" + check_events {} + + feed "c3j" + check_events { + { "test1", "bytes", 1, 4, 1, 0, 1, 3, 0, 48, 0, 0, 0 }; + } + end) + + it("visual charwise paste", function() + local check_events = setup_eventcheck(verify, {'1234567890'}) + funcs.setreg('a', '___') + + feed '1G1|vll' + check_events {} + + feed '"ap' + check_events { + { "test1", "bytes", 1, 3, 0, 0, 0, 0, 3, 3, 0, 0, 0 }; + { "test1", "bytes", 1, 5, 0, 0, 0, 0, 0, 0, 0, 3, 3 }; + } + end) end describe('(with verify) handles', function() diff --git a/test/functional/lua/treesitter_spec.lua b/test/functional/lua/treesitter_spec.lua index 2c9107a65a..128545b472 100644 --- a/test/functional/lua/treesitter_spec.lua +++ b/test/functional/lua/treesitter_spec.lua @@ -446,10 +446,7 @@ static int nlua_schedule(lua_State *const lstate) ]]} feed("5Goc<esc>dd") - if true == true then - pending('reenable this check in luahl PR') - return - end + screen:expect{grid=[[ {2:/// Schedule Lua callback on main loop's event queue} | {3:static} {3:int} {11:nlua_schedule}({3:lua_State} *{3:const} lstate) | @@ -480,7 +477,7 @@ static int nlua_schedule(lua_State *const lstate) || {6:lstate} != {6:lstate}) { | {11:lua_pushliteral}(lstate, {5:"vim.schedule: expected function"}); | {4:return} {11:lua_error}(lstate); | - *^/ | + {8:*^/} | } | | {7:LuaRef} cb = {11:nlua_ref}(lstate, {5:1}); | diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index a9e8ca9686..61447f1152 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -1330,4 +1330,29 @@ describe('lua stdlib', function() eq(false, pcall_result) end) end) + + describe('vim.api.nvim_buf_call', function() + it('can access buf options', function() + local buf1 = meths.get_current_buf() + local buf2 = exec_lua [[ + buf2 = vim.api.nvim_create_buf(false, true) + return buf2 + ]] + + eq(false, meths.buf_get_option(buf1, 'autoindent')) + eq(false, meths.buf_get_option(buf2, 'autoindent')) + + local val = exec_lua [[ + return vim.api.nvim_buf_call(buf2, function() + vim.cmd "set autoindent" + return vim.api.nvim_get_current_buf() + end) + ]] + + eq(false, meths.buf_get_option(buf1, 'autoindent')) + eq(true, meths.buf_get_option(buf2, 'autoindent')) + eq(buf1, meths.get_current_buf()) + eq(buf2, val) + end) + end) end) diff --git a/test/functional/ui/cursor_spec.lua b/test/functional/ui/cursor_spec.lua index 6c913124ac..e1a72ced05 100644 --- a/test/functional/ui/cursor_spec.lua +++ b/test/functional/ui/cursor_spec.lua @@ -286,6 +286,21 @@ describe('ui/cursor', function() eq(173, named.normal.blinkon) eq(42, named.showmatch.cell_percentage) end) + + -- If there is no setting for guicursor, it becomes the default setting. + meths.set_option('guicursor', 'n:ver35-blinkwait171-blinkoff172-blinkon173-Cursor/lCursor') + screen:expect(function() + for _,m in ipairs(screen._mode_info) do + if m.name ~= 'normal' then + eq('block', m.cursor_shape or 'block') + eq(0, m.blinkon or 0) + eq(0, m.blinkoff or 0) + eq(0, m.blinkwait or 0) + eq(0, m.hl_id or 0) + eq(0, m.id_lm or 0) + end + end + end) end) it("empty 'guicursor' sets cursor_shape=block in all modes", function() @@ -297,6 +312,8 @@ describe('ui/cursor', function() if m['cursor_shape'] ~= nil then eq('block', m.cursor_shape) eq(0, m.blinkon) + eq(0, m.hl_id) + eq(0, m.id_lm) end end end) diff --git a/test/functional/ui/fold_spec.lua b/test/functional/ui/fold_spec.lua index 6ec45064da..fe67b9f6b0 100644 --- a/test/functional/ui/fold_spec.lua +++ b/test/functional/ui/fold_spec.lua @@ -21,6 +21,8 @@ describe("folded lines", function() [5] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.LightGrey}, [6] = {background = Screen.colors.Yellow}, [7] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.WebGray}, + [8] = {foreground = Screen.colors.Brown }, + [9] = {bold = true, foreground = Screen.colors.Brown} }) end) @@ -29,7 +31,7 @@ describe("folded lines", function() feed("i<cr><esc>") feed("vkzf") screen:expect([[ - {5: ^+-- 2 lines: ·············}| + {7: }{5:^+-- 2 lines: ·············}| {1:~ }| {1:~ }| {1:~ }| @@ -49,8 +51,8 @@ describe("folded lines", function() funcs.setline(4, 'line 2') feed("j") screen:expect([[ - {7:+ }{5: 1 +-- 2 lines: ·························}| - {7:+ }{5: 0 ^+-- 2 lines: ·························}| + {7:+ }{8: 1 }{5:+-- 2 lines: ·························}| + {7:+ }{9: 0 }{5:^+-- 2 lines: ·························}| {1:~ }| {1:~ }| {1:~ }| @@ -130,8 +132,8 @@ describe("folded lines", function() ]]) feed('vkzf') - screen:expect([[ - {5:^+-- 2 lines: å 语 x̎͂̀̂͛͛ ﺎﻠﻋَﺮَﺒِﻳَّﺓ·················}| + screen:expect{grid=[[ + {5:^+-- 2 lines: å 语 x̎͂̀̂͛͛ العَرَبِيَّة·················}| {1:~ }| {1:~ }| {1:~ }| @@ -139,7 +141,7 @@ describe("folded lines", function() {1:~ }| {1:~ }| | - ]]) + ]]} feed_command("set noarabicshape") screen:expect([[ @@ -155,7 +157,7 @@ describe("folded lines", function() feed_command("set number foldcolumn=2") screen:expect([[ - {7:+ }{5: 1 ^+-- 2 lines: å 语 x̎͂̀̂͛͛ العَرَبِيَّة···········}| + {7:+ }{8: 1 }{5:^+-- 2 lines: å 语 x̎͂̀̂͛͛ العَرَبِيَّة···········}| {1:~ }| {1:~ }| {1:~ }| @@ -168,7 +170,7 @@ describe("folded lines", function() -- Note: too much of the folded line gets cut off.This is a vim bug. feed_command("set rightleft") screen:expect([[ - {5:+-- 2 lines: å ······················^· 1 }{7: +}| + {5:···········ةيَّبِرَعَلا x̎͂̀̂͛͛ 语 å :senil 2 --^+}{8: 1 }{7: +}| {1: ~}| {1: ~}| {1: ~}| @@ -180,7 +182,7 @@ describe("folded lines", function() feed_command("set nonumber foldcolumn=0") screen:expect([[ - {5:+-- 2 lines: å 语 x̎͂̀̂͛͛ ال·····················^·}| + {5:·················ةيَّبِرَعَلا x̎͂̀̂͛͛ 语 å :senil 2 --^+}| {1: ~}| {1: ~}| {1: ~}| @@ -192,7 +194,7 @@ describe("folded lines", function() feed_command("set arabicshape") screen:expect([[ - {5:+-- 2 lines: å 语 x̎͂̀̂͛͛ ﺍﻟ·····················^·}| + {5:·················ةيَّبِرَعَلا x̎͂̀̂͛͛ 语 å :senil 2 --^+}| {1: ~}| {1: ~}| {1: ~}| diff --git a/test/functional/ui/messages_spec.lua b/test/functional/ui/messages_spec.lua index efc02db159..5df4a1d533 100644 --- a/test/functional/ui/messages_spec.lua +++ b/test/functional/ui/messages_spec.lua @@ -323,7 +323,7 @@ describe('ui/ext_messages', function() {1:~ }| {1:~ }| ]], messages={ - {content = {{"/line [1/2] W"}}, kind = "search_count"} + {content = {{"/line W [1/2]"}}, kind = "search_count"} }} feed('n') |