From 9fbdbb814f4ad67a14979aba4a6a49800c2f1a99 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Tue, 27 Sep 2022 17:30:34 +0100 Subject: Update runtime files --- .github/CODEOWNERS | 12 +- runtime/autoload/context.vim | 9 +- runtime/autoload/dist/vimindent.vim | 1200 +++++++++++++++++++++++++++++++++++ runtime/compiler/hare.vim | 31 + runtime/doc/cmdline.txt | 4 +- runtime/doc/develop.txt | 2 +- runtime/doc/ft_context.txt | 32 +- runtime/doc/indent.txt | 30 +- runtime/doc/map.txt | 16 +- runtime/doc/motion.txt | 4 +- runtime/doc/options.txt | 7 +- runtime/doc/pattern.txt | 7 +- runtime/doc/quickfix.txt | 8 +- runtime/doc/repeat.txt | 13 +- runtime/doc/syntax.txt | 4 +- runtime/doc/tags | 5 + runtime/doc/textprop.txt | 39 +- runtime/doc/todo.txt | 43 +- runtime/doc/various.txt | 4 +- runtime/doc/vim9.txt | 4 +- runtime/filetype.vim | 2 +- runtime/ftplugin/chatito.vim | 15 + runtime/ftplugin/elixir.vim | 6 +- runtime/ftplugin/gyp.vim | 14 + runtime/ftplugin/hare.vim | 27 + runtime/ftplugin/heex.vim | 16 + runtime/ftplugin/vim.vim | 18 +- runtime/indent/chatito.vim | 32 + runtime/indent/gyp.vim | 7 + runtime/indent/hare.vim | 138 ++++ runtime/indent/solidity.vim | 442 +++++++++++++ runtime/indent/testdir/vim.in | 778 ++++++++++++++++++++++- runtime/indent/testdir/vim.ok | 778 ++++++++++++++++++++++- runtime/indent/vim.vim | 224 +------ runtime/indent/vue.vim | 12 + runtime/syntax/chatito.vim | 62 ++ runtime/syntax/desktop.vim | 6 +- runtime/syntax/gyp.vim | 49 ++ runtime/syntax/hare.vim | 133 ++++ runtime/syntax/help.vim | 3 +- runtime/syntax/hlsplaylist.vim | 120 ++++ runtime/syntax/plsql.vim | 68 +- runtime/syntax/solidity.vim | 173 +++++ runtime/syntax/vim.vim | 2 +- src/INSTALLpc.txt | 1 - 45 files changed, 4222 insertions(+), 378 deletions(-) create mode 100644 runtime/autoload/dist/vimindent.vim create mode 100644 runtime/compiler/hare.vim create mode 100644 runtime/ftplugin/chatito.vim create mode 100644 runtime/ftplugin/gyp.vim create mode 100644 runtime/ftplugin/hare.vim create mode 100644 runtime/ftplugin/heex.vim create mode 100644 runtime/indent/chatito.vim create mode 100644 runtime/indent/gyp.vim create mode 100644 runtime/indent/hare.vim create mode 100644 runtime/indent/solidity.vim create mode 100644 runtime/indent/vue.vim create mode 100644 runtime/syntax/chatito.vim create mode 100644 runtime/syntax/gyp.vim create mode 100644 runtime/syntax/hare.vim create mode 100644 runtime/syntax/hlsplaylist.vim create mode 100644 runtime/syntax/solidity.vim diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 2baadcbf6f..b33c37bff5 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -57,6 +57,7 @@ runtime/compiler/gawk.vim @dkearns runtime/compiler/gjs.vim @dkearns runtime/compiler/go.vim @dbarnett runtime/compiler/haml.vim @tpope +runtime/compiler/hare.vim @rsaihe runtime/compiler/icon.vim @dkearns runtime/compiler/javac.vim @dkearns runtime/compiler/jest.vim @dkearns @@ -107,6 +108,7 @@ runtime/ftplugin/awk.vim @dkearns runtime/ftplugin/basic.vim @dkearns runtime/ftplugin/bst.vim @tpope runtime/ftplugin/cfg.vim @chrisbra +runtime/ftplugin/chatito.vim @ObserverOfTime runtime/ftplugin/clojure.vim @axvr runtime/ftplugin/cs.vim @nickspoons runtime/ftplugin/csh.vim @dkearns @@ -116,9 +118,9 @@ runtime/ftplugin/desktop.vim @e-kwsm runtime/ftplugin/dosbatch.vim @mrdubya runtime/ftplugin/eiffel.vim @dkearns runtime/ftplugin/elixir.vim @mhanberg -runtime/ftplugin/expect.vim @dkearns runtime/ftplugin/erlang.vim @hcs42 runtime/ftplugin/eruby.vim @tpope @dkearns +runtime/ftplugin/expect.vim @dkearns runtime/ftplugin/fennel.vim @gpanders runtime/ftplugin/fetchmail.vim @dkearns runtime/ftplugin/fpcmake.vim @dkearns @@ -134,9 +136,11 @@ runtime/ftplugin/gitconfig.vim @tpope runtime/ftplugin/gitignore.vim @ObserverOfTime runtime/ftplugin/gitrebase.vim @tpope runtime/ftplugin/gitsendemail.vim @tpope +runtime/ftplugin/gyp.vim @ObserverOfTime runtime/ftplugin/go.vim @dbarnett runtime/ftplugin/gprof.vim @dpelle runtime/ftplugin/haml.vim @tpope +runtime/ftplugin/hare.vim @rsaihe runtime/ftplugin/hgcommit.vim @k-takata runtime/ftplugin/html.vim @dkearns runtime/ftplugin/i3config.vim @hiqua @@ -208,6 +212,7 @@ runtime/ftplugin/zsh.vim @chrisbra runtime/indent/basic.vim @dkearns runtime/indent/bst.vim @tpope runtime/indent/cdl.vim @dkearns +runtime/indent/chatito.vim @ObserverOfTime runtime/indent/clojure.vim @axvr runtime/indent/config.vim @dkearns runtime/indent/cs.vim @nickspoons @@ -229,7 +234,9 @@ runtime/indent/gdscript.vim @habamax runtime/indent/gitconfig.vim @tpope runtime/indent/gitolite.vim @sitaramc runtime/indent/go.vim @dbarnett +runtime/indent/gyp.vim @ObserverOfTime runtime/indent/haml.vim @tpope +runtime/indent/hare.vim @rsaihe runtime/indent/idlang.vim @dkearns runtime/indent/j.vim @glts runtime/indent/java.vim @xuhdev @@ -303,6 +310,7 @@ runtime/syntax/cabal.vim @coot runtime/syntax/cabalconfig.vim @coot runtime/syntax/cabalproject.vim @coot runtime/syntax/cf.vim @ernstvanderlinden +runtime/syntax/chatito.vim @ObserverOfTime runtime/syntax/clojure.vim @axvr runtime/syntax/cs.vim @nickspoons runtime/syntax/csh.vim @cecamp @@ -345,7 +353,9 @@ runtime/syntax/go.vim @bhcleek runtime/syntax/godoc.vim @dbarnett runtime/syntax/gprof.vim @dpelle runtime/syntax/groff.vim @jmarshall +runtime/syntax/gyp.vim @ObserverOfTime runtime/syntax/haml.vim @tpope +runtime/syntax/hare.vim @rsaihe runtime/syntax/haskell.vim @coot runtime/syntax/hgcommit.vim @k-takata runtime/syntax/html.vim @dkearns diff --git a/runtime/autoload/context.vim b/runtime/autoload/context.vim index e42b99e2e9..fc59309768 100644 --- a/runtime/autoload/context.vim +++ b/runtime/autoload/context.vim @@ -3,13 +3,18 @@ vim9script # Language: ConTeXt typesetting engine # Maintainer: Nicola Vitacolonna # Former Maintainers: Nikolai Weibull -# Latest Revision: 2022 Aug 12 +# Latest Revision: 2022 Sep 19 # Typesetting {{{ import autoload './typeset.vim' export def ConTeXtCmd(path: string): list - return ['mtxrun', '--script', 'context', '--nonstopmode', '--autogenerate', path] + var cmd = ['mtxrun', '--script', 'context', '--nonstopmode', '--autogenerate'] + if !empty(get(g:, 'context_extra_options', '')) + cmd += g:context_extra_options + endif + cmd->add(path) + return cmd enddef export def Typeset(bufname: string, env = {}, Cmd = ConTeXtCmd): bool diff --git a/runtime/autoload/dist/vimindent.vim b/runtime/autoload/dist/vimindent.vim new file mode 100644 index 0000000000..572fc7c6cb --- /dev/null +++ b/runtime/autoload/dist/vimindent.vim @@ -0,0 +1,1200 @@ +vim9script + +# Language: Vim script +# Maintainer: github user lacygoill +# Last Change: 2022 Sep 24 + +# Config {{{1 + +const TIMEOUT: number = get(g:, 'vim_indent', {}) + ->get('searchpair_timeout', 100) + +def IndentMoreInBracketBlock(): number # {{{2 + if get(g:, 'vim_indent', {}) + ->get('more_in_bracket_block', false) + return shiftwidth() + else + return 0 + endif +enddef + +def IndentMoreLineContinuation(): number # {{{2 + var n: any = get(g:, 'vim_indent', {}) + # We inspect `g:vim_indent_cont` to stay backward compatible. + ->get('line_continuation', get(g:, 'vim_indent_cont', shiftwidth() * 3)) + + if n->typename() == 'string' + return n->eval() + else + return n + endif +enddef +# }}}2 + +# Init {{{1 +var patterns: list +# Tokens {{{2 +# BAR_SEPARATION {{{3 + +const BAR_SEPARATION: string = '[^|\\]\@1<=|' + +# OPENING_BRACKET {{{3 + +const OPENING_BRACKET: string = '[[{(]' + +# CLOSING_BRACKET {{{3 + +const CLOSING_BRACKET: string = '[]})]' + +# NON_BRACKET {{{3 + +const NON_BRACKET: string = '[^[\]{}()]' + +# LIST_OR_DICT_CLOSING_BRACKET {{{3 + +const LIST_OR_DICT_CLOSING_BRACKET: string = '[]}]' + +# LIST_OR_DICT_OPENING_BRACKET {{{3 + +const LIST_OR_DICT_OPENING_BRACKET: string = '[[{]' + +# CHARACTER_UNDER_CURSOR {{{3 + +const CHARACTER_UNDER_CURSOR: string = '\%.c.' + +# INLINE_COMMENT {{{3 + +# TODO: It is not required for an inline comment to be surrounded by whitespace. +# But it might help against false positives. +# To be more reliable, we should inspect the syntax, and only require whitespace +# before the `#` comment leader. But that might be too costly (because of +# `synstack()`). +const INLINE_COMMENT: string = '\s[#"]\%(\s\|[{}]\{3}\)' + +# INLINE_VIM9_COMMENT {{{3 + +const INLINE_VIM9_COMMENT: string = '\s#' + +# COMMENT {{{3 + +# TODO: Technically, `"\s` is wrong. +# +# First, whitespace is not required. +# Second, in Vim9, a string might appear at the start of the line. +# To be sure, we should also inspect the syntax. +# We can't use `INLINE_COMMENT` here. {{{ +# +# const COMMENT: string = $'^\s*{INLINE_COMMENT}' +# ^------------^ +# ✘ +# +# Because `INLINE_COMMENT` asserts the presence of a whitespace before the +# comment leader. This assertion is not satisfied for a comment starting at the +# start of the line. +#}}} +const COMMENT: string = '^\s*\%(#\|"\\\=\s\).*$' + +# DICT_KEY {{{3 + +const DICT_KEY: string = '^\s*\%(' + .. '\%(\w\|-\)\+' + .. '\|' + .. '"[^"]*"' + .. '\|' + .. "'[^']*'" + .. '\|' + .. '\[[^]]\+\]' + .. '\)' + .. ':\%(\s\|$\)' + +# END_OF_COMMAND {{{3 + +const END_OF_COMMAND: string = $'\s*\%($\|||\@!\|{INLINE_COMMENT}\)' + +# END_OF_LINE {{{3 + +const END_OF_LINE: string = $'\s*\%($\|{INLINE_COMMENT}\)' + +# END_OF_VIM9_LINE {{{3 + +const END_OF_VIM9_LINE: string = $'\s*\%($\|{INLINE_VIM9_COMMENT}\)' + +# OPERATOR {{{3 + +const OPERATOR: string = '\%(^\|\s\)\%([-+*/%]\|\.\.\|||\|&&\|??\|?\|<<\|>>\|\%([=!]=\|[<>]=\=\|[=!]\~\|is\|isnot\)[?#]\=\)\%(\s\|$\)\@=\%(\s*[|<]\)\@!' + # assignment operators + .. '\|' .. '\s\%([-+*/%]\|\.\.\)\==\%(\s\|$\)\@=' + # support `:` when used inside conditional operator `?:` + .. '\|' .. '\%(\s\|^\):\%(\s\|$\)' + +# HEREDOC_OPERATOR {{{3 + +const HEREDOC_OPERATOR: string = '\s=<<\s\@=\%(\s\+\%(trim\|eval\)\)\{,2}' + +# PATTERN_DELIMITER {{{3 + +# A better regex would be: +# +# [^-+*/%.:# \t[:alnum:]\"|]\@=.\|->\@!\%(=\s\)\@!\|[+*/%]\%(=\s\)\@! +# +# But sometimes, it can be too costly and cause `E363` to be given. +const PATTERN_DELIMITER: string = '[-+*/%]\%(=\s\)\@!' + +# QUOTE {{{3 + +const QUOTE: string = '["'']' +# }}}2 +# Syntaxes {{{2 +# ASSIGNS_HEREDOC {{{3 + +const ASSIGNS_HEREDOC: string = $'^\%({COMMENT}\)\@!.*\%({HEREDOC_OPERATOR}\)\s\+\zs[A-Z]\+{END_OF_LINE}' + +# CD_COMMAND {{{3 + +const CD_COMMAND: string = $'[lt]\=cd!\=\s\+-{END_OF_COMMAND}' + +# HIGHER_ORDER_COMMAND {{{3 + +patterns =<< trim eval END + argdo\>!\= + bufdo\>!\= + cdo\>!\= + folddoc\%[losed]\> + foldd\%[oopen]\> + ldo\=\>!\= + tabdo\=\> + windo\> + au\%[tocmd]\>.* + com\%[mand]\>.* + g\%[lobal]!\={PATTERN_DELIMITER}.* + v\%[global]!\={PATTERN_DELIMITER}.* +END +const HIGHER_ORDER_COMMAND: string = $'\%(^\|{BAR_SEPARATION}\)\s*\<\%(' .. patterns->join('\|') .. '\):\@!' + +# MAPPING_COMMAND {{{3 + +const MAPPING_COMMAND: string = '\%(\join('\|') .. $'\){END_OF_COMMAND}' + .. $'\|^\s*cat\%[ch]\%(\s\+\({PATTERN_DELIMITER}\).*\1\)\={END_OF_COMMAND}' + .. $'\|^\s*elseif\=\s\+\%({OPERATOR}\)\@!' + +# STARTS_CURLY_BLOCK {{{3 + +# TODO: `{` alone on a line is not necessarily the start of a block. +# It could be a dictionary if the previous line ends with a binary/ternary +# operator. This can cause an issue whenever we use `STARTS_CURLY_BLOCK` or +# `LINE_CONTINUATION_AT_EOL`. +const STARTS_CURLY_BLOCK: string = '\%(' + .. '^\s*{' + .. '\|' .. '^.*\zs\s=>\s\+{' + .. '\|' .. $'^\%(\s*\|.*{BAR_SEPARATION}\s*\)\%(com\%[mand]\|au\%[tocmd]\).*\zs\s{{' + .. '\)' .. END_OF_COMMAND + +# STARTS_NAMED_BLOCK {{{3 + +# All of these will be used at the start of a line (or after a bar). +# NOTE: Don't replace `\%x28` with `(`.{{{ +# +# Otherwise, the paren would be unbalanced which might cause syntax highlighting +# issues much later in the code of the current script (sometimes, the syntax +# highlighting plugin fails to correctly recognize a heredoc which is far away +# and/or not displayed because inside a fold). +# }}} +patterns =<< trim END + if + el\%[se] + elseif\= + for + wh\%[ile] + try + cat\%[ch] + fina\|finally\= + fu\%[nction]\%x28\@! + \%(export\s\+\)\=def + aug\%[roup]\%(\s\+[eE][nN][dD]\)\@!\s\+\S\+ +END +const STARTS_NAMED_BLOCK: string = '^\s*\%(sil\%[ent]\s\+\)\=\%(' .. patterns->join('\|') .. '\)\>:\@!' + +# STARTS_FUNCTION {{{3 + +const STARTS_FUNCTION: string = '^\s*\%(export\s\+\)\=def\>:\@!' + +# ENDS_FUNCTION {{{3 + +const ENDS_FUNCTION: string = $'^\s*enddef\>:\@!{END_OF_COMMAND}' + +# START_MIDDLE_END {{{3 + +const START_MIDDLE_END: dict> = { + if: ['if', 'el\%[se]\|elseif\=', 'en\%[dif]'], + else: ['if', 'el\%[se]\|elseif\=', 'en\%[dif]'], + elseif: ['if', 'el\%[se]\|elseif\=', 'en\%[dif]'], + endif: ['if', 'el\%[se]\|elseif\=', 'en\%[dif]'], + for: ['for', '', 'endfor\='], + endfor: ['for', '', 'endfor\='], + while: ['wh\%[ile]', '', 'endw\%[hile]'], + endwhile: ['wh\%[ile]', '', 'endw\%[hile]'], + try: ['try', 'cat\%[ch]\|fina\|finally\=', 'endt\%[ry]'], + catch: ['try', 'cat\%[ch]\|fina\|finally\=', 'endt\%[ry]'], + finally: ['try', 'cat\%[ch]\|fina\|finally\=', 'endt\%[ry]'], + endtry: ['try', 'cat\%[ch]\|fina\|finally\=', 'endt\%[ry]'], + def: ['\%(export\s\+\)\=def', '', 'enddef'], + enddef: ['\%(export\s\+\)\=def', '', 'enddef'], + function: ['fu\%[nction]', '', 'endf\%[unction]'], + endfunction: ['fu\%[nction]', '', 'endf\%[unction]'], + augroup: ['aug\%[roup]\%(\s\+[eE][nN][dD]\)\@!\s\+\S\+', '', 'aug\%[roup]\s\+[eE][nN][dD]'], +}->map((_, kwds: list) => + kwds->map((_, kwd: string) => kwd == '' + ? '' + : $'\%(^\|{BAR_SEPARATION}\|\:\@!\%%(\s*%s\)\@!', kwd, OPERATOR)}\)')) +# }}}2 +# EOL {{{2 +# OPENING_BRACKET_AT_EOL {{{3 + +const OPENING_BRACKET_AT_EOL: string = $'{OPENING_BRACKET}{END_OF_VIM9_LINE}' + +# COMMA_AT_EOL {{{3 + +const COMMA_AT_EOL: string = $',{END_OF_VIM9_LINE}' + +# COMMA_OR_DICT_KEY_AT_EOL {{{3 + +const COMMA_OR_DICT_KEY_AT_EOL: string = $'\%(,\|{DICT_KEY}\){END_OF_VIM9_LINE}' + +# LAMBDA_ARROW_AT_EOL {{{3 + +const LAMBDA_ARROW_AT_EOL: string = $'\s=>{END_OF_VIM9_LINE}' + +# LINE_CONTINUATION_AT_EOL {{{3 + +const LINE_CONTINUATION_AT_EOL: string = '\%(' + .. ',' + .. '\|' .. OPERATOR + .. '\|' .. '\s=>' + .. '\|' .. '[^=]\zs[[(]' + .. '\|' .. DICT_KEY + # `{` is ambiguous. + # It can be the start of a dictionary or a block. + # We only want to match the former. + .. '\|' .. $'^\%({STARTS_CURLY_BLOCK}\)\@!.*\zs{{' + .. '\)\s*\%(\s#.*\)\=$' +# }}}2 +# SOL {{{2 +# BACKSLASH_AT_SOL {{{3 + +const BACKSLASH_AT_SOL: string = '^\s*\%(\\\|[#"]\\ \)' + +# CLOSING_BRACKET_AT_SOL {{{3 + +const CLOSING_BRACKET_AT_SOL: string = $'^\s*{CLOSING_BRACKET}' + +# LINE_CONTINUATION_AT_SOL {{{3 + +const LINE_CONTINUATION_AT_SOL: string = '^\s*\%(' + .. '\\' + .. '\|' .. '[#"]\\ ' + .. '\|' .. OPERATOR + .. '\|' .. '->\s*\h' + .. '\|' .. '\.\h' # dict member + .. '\|' .. '|' + # TODO: `}` at the start of a line is not necessarily a line continuation. + # Could be the end of a block. + .. '\|' .. CLOSING_BRACKET + .. '\)' + +# RANGE_AT_SOL {{{3 + +const RANGE_AT_SOL: string = '^\s*:\S' +# }}}1 +# Interface {{{1 +export def Expr(lnum: number): number # {{{2 + # line which is indented + var line_A: dict = {text: getline(lnum), lnum: lnum} + # line above, on which we'll base the indent of line A + var line_B: dict + + if line_A->AtStartOf('HereDoc') + line_A->CacheHeredoc() + elseif line_A.lnum->IsInside('HereDoc') + return line_A.text->HereDocIndent() + elseif line_A.lnum->IsRightBelow('HereDoc') + var ind: number = b:vimindent.startindent + unlet! b:vimindent + return ind + endif + + # Don't move this block after the function header one. + # Otherwise, we might clear the cache too early if the line following the + # header is a comment. + if line_A.text =~ COMMENT + return CommentIndent() + endif + + line_B = PrevCodeLine(line_A.lnum) + if line_A.text =~ BACKSLASH_AT_SOL + if line_B.text =~ BACKSLASH_AT_SOL + return Indent(line_B.lnum) + else + return Indent(line_B.lnum) + IndentMoreLineContinuation() + endif + endif + + if line_A->AtStartOf('FuncHeader') + line_A.lnum->CacheFuncHeader() + elseif line_A.lnum->IsInside('FuncHeader') + return b:vimindent.startindent + 2 * shiftwidth() + elseif line_A.lnum->IsRightBelow('FuncHeader') + var startindent: number = b:vimindent.startindent + unlet! b:vimindent + if line_A.text =~ ENDS_FUNCTION + return startindent + else + return startindent + shiftwidth() + endif + endif + + var past_bracket_block: dict + if exists('b:vimindent') + && b:vimindent->has_key('is_BracketBlock') + past_bracket_block = RemovePastBracketBlock(line_A) + endif + if line_A->AtStartOf('BracketBlock') + line_A->CacheBracketBlock() + endif + if line_A.lnum->IsInside('BracketBlock') + && !b:vimindent.block_stack[0].is_curly_block + for block: dict in b:vimindent.block_stack + # Can't call `BracketBlockIndent()` before we're indenting a line *after* the start of the block.{{{ + # + # That's because it might need the correct indentation of the start + # of the block. But if we're still *on* the start, we haven't yet + # computed that indentation. + #}}} + if line_A.lnum > block.startlnum + && !block.is_curly_block + return BracketBlockIndent(line_A, block) + endif + endfor + endif + if line_A.text->ContinuesBelowBracketBlock(line_B, past_bracket_block) + && line_A.text !~ CLOSING_BRACKET_AT_SOL + return past_bracket_block.startindent + endif + + # Problem: If we press `==` on the line right below the start of a multiline + # lambda (split after its arrow `=>`), the indent is not correct. + # Solution: Indent relative to the line above. + if line_B->EndsWithLambdaArrow() + return Indent(line_B.lnum) + shiftwidth() + IndentMoreInBracketBlock() + endif + + # Don't move this block before the heredoc one.{{{ + # + # A heredoc might be assigned on the very first line. + # And if it is, we need to cache some info. + #}}} + # Don't move it before the function header and bracket block ones either.{{{ + # + # You could, because these blocks of code deal with construct which can only + # appear in a Vim9 script. And in a Vim9 script, the first line is + # `vim9script`. Or maybe some legacy code/comment (see `:help vim9-mix`). + # But you can't find a Vim9 function header or Vim9 bracket block on the + # first line. + # + # Anyway, even if you could, don't. First, it would be inconsistent. + # Second, it could give unexpected results while we're trying to fix some + # failing test. + #}}} + if line_A.lnum == 1 + return 0 + endif + + # Don't do that: + # if line_A.text !~ '\S' + # return -1 + # endif + # It would prevent a line from being automatically indented when using the + # normal command `o`. + # TODO: Can we write a test for this? + + if line_B.text =~ STARTS_CURLY_BLOCK + return Indent(line_B.lnum) + shiftwidth() + IndentMoreInBracketBlock() + + elseif line_A.text =~ CLOSING_BRACKET_AT_SOL + var start: number = MatchingOpenBracket(line_A) + if start <= 0 + return -1 + endif + return Indent(start) + IndentMoreInBracketBlock() + + elseif line_A.text =~ ENDS_BLOCK_OR_CLAUSE + && !line_B->EndsWithLineContinuation() + var kwd: string = BlockStartKeyword(line_A.text) + if !START_MIDDLE_END->has_key(kwd) + return -1 + endif + + # If the cursor is after the match for the end pattern, we won't find + # the start of the block. Let's make sure that doesn't happen. + cursor(line_A.lnum, 1) + + var [start: string, middle: string, end: string] = START_MIDDLE_END[kwd] + var block_start = SearchPairStart(start, middle, end) + if block_start > 0 + return Indent(block_start) + else + return -1 + endif + endif + + var base_ind: number + if line_A->IsFirstLineOfCommand(line_B) + line_A.isfirst = true + line_B = line_B->FirstLinePreviousCommand() + base_ind = Indent(line_B.lnum) + + if line_B->EndsWithCurlyBlock() + && !line_A->IsInThisBlock(line_B.lnum) + return base_ind + endif + + else + line_A.isfirst = false + base_ind = Indent(line_B.lnum) + + var line_C: dict = PrevCodeLine(line_B.lnum) + if !line_B->IsFirstLineOfCommand(line_C) || line_C.lnum <= 0 + return base_ind + endif + endif + + var ind: number = base_ind + Offset(line_A, line_B) + return [ind, 0]->max() +enddef + +def g:GetVimIndent(): number # {{{2 + # for backward compatibility + return Expr(v:lnum) +enddef +# }}}1 +# Core {{{1 +def Offset( # {{{2 + # we indent this line ... + line_A: dict, + # ... relatively to this line + line_B: dict, + ): number + + # increase indentation inside a block + if line_B.text =~ STARTS_NAMED_BLOCK || line_B->EndsWithCurlyBlock() + # But don't indent if the line starting the block also closes it. + if line_B->AlsoClosesBlock() + return 0 + # Indent twice for a line continuation in the block header itself, so that + # we can easily distinguish the end of the block header from the start of + # the block body. + elseif line_B->EndsWithLineContinuation() + && !line_A.isfirst + || line_A.text =~ LINE_CONTINUATION_AT_SOL + && line_A.text !~ PLUS_MINUS_COMMAND + || line_A.text->Is_IN_KeywordForLoop(line_B.text) + return 2 * shiftwidth() + else + return shiftwidth() + endif + + # increase indentation of a line if it's the continuation of a command which + # started on a previous line + elseif !line_A.isfirst + && (line_B->EndsWithLineContinuation() + || line_A.text =~ LINE_CONTINUATION_AT_SOL) + return shiftwidth() + endif + + return 0 +enddef + +def HereDocIndent(line_A: string): number # {{{2 + # at the end of a heredoc + if line_A =~ $'^\s*{b:vimindent.endmarker}$' + # `END` must be at the very start of the line if the heredoc is not trimmed + if !b:vimindent.is_trimmed + # We can't invalidate the cache just yet. + # The indent of `END` is meaningless; it's always 0. The next line + # will need to be indented relative to the start of the heredoc. It + # must know where it starts; it needs the cache. + return 0 + else + var ind: number = b:vimindent.startindent + # invalidate the cache so that it's not used for the next heredoc + unlet! b:vimindent + return ind + endif + endif + + # In a non-trimmed heredoc, all of leading whitespace is semantic. + # Leave it alone. + if !b:vimindent.is_trimmed + # But do save the indent of the assignment line. + if !b:vimindent->has_key('startindent') + b:vimindent.startindent = b:vimindent.startlnum->Indent() + endif + return -1 + endif + + # In a trimmed heredoc, *some* of the leading whitespace is semantic. + # We want to preserve it, so we can't just indent relative to the assignment + # line. That's because we're dealing with data, not with code. + # Instead, we need to compute by how much the indent of the assignment line + # was increased or decreased. Then, we need to apply that same change to + # every line inside the body. + var offset: number + if !b:vimindent->has_key('offset') + var old_startindent: number = b:vimindent.startindent + var new_startindent: number = b:vimindent.startlnum->Indent() + offset = new_startindent - old_startindent + + # If all the non-empty lines in the body have a higher indentation relative + # to the assignment, there is no need to indent them more. + # But if at least one of them does have the same indentation level (or a + # lower one), then we want to indent it further (and the whole block with it). + # This way, we can clearly distinguish the heredoc block from the rest of + # the code. + var end: number = search($'^\s*{b:vimindent.endmarker}$', 'nW') + var should_indent_more: bool = range(v:lnum, end - 1) + ->indexof((_, lnum: number): bool => Indent(lnum) <= old_startindent && getline(lnum) != '') >= 0 + if should_indent_more + offset += shiftwidth() + endif + + b:vimindent.offset = offset + b:vimindent.startindent = new_startindent + endif + + return [0, Indent(v:lnum) + b:vimindent.offset]->max() +enddef + +def CommentIndent(): number # {{{2 + var line_B: dict + line_B.lnum = prevnonblank(v:lnum - 1) + line_B.text = getline(line_B.lnum) + if line_B.text =~ COMMENT + return Indent(line_B.lnum) + endif + + var next: number = NextCodeLine() + if next == 0 + return 0 + endif + var vimindent_save: dict = get(b:, 'vimindent', {})->deepcopy() + var ind: number = next->Expr() + # The previous `Expr()` might have set or deleted `b:vimindent`. + # This could cause issues (e.g. when indenting 2 commented lines above a + # heredoc). Let's make sure the state of the variable is not altered. + if vimindent_save->empty() + unlet! b:vimindent + else + b:vimindent = vimindent_save + endif + if getline(next) =~ ENDS_BLOCK + return ind + shiftwidth() + else + return ind + endif +enddef + +def BracketBlockIndent(line_A: dict, block: dict): number # {{{2 + if !block->has_key('startindent') + block.startindent = block.startlnum->Indent() + endif + + var ind: number = block.startindent + + if line_A.text =~ CLOSING_BRACKET_AT_SOL + if b:vimindent.is_on_named_block_line + ind += 2 * shiftwidth() + endif + return ind + IndentMoreInBracketBlock() + endif + + var startline: dict = { + text: block.startline, + lnum: block.startlnum + } + if startline->EndsWithComma() + || startline->EndsWithLambdaArrow() + || (startline->EndsWithOpeningBracket() + # TODO: Is that reliable? + && block.startline !~ + $'^\s*{NON_BRACKET}\+{LIST_OR_DICT_CLOSING_BRACKET},\s\+{LIST_OR_DICT_OPENING_BRACKET}') + ind += shiftwidth() + IndentMoreInBracketBlock() + endif + + if b:vimindent.is_on_named_block_line + ind += shiftwidth() + endif + + if block.is_dict + && line_A.text !~ DICT_KEY + ind += shiftwidth() + endif + + return ind +enddef + +def CacheHeredoc(line_A: dict) # {{{2 + var endmarker: string = line_A.text->matchstr(ASSIGNS_HEREDOC) + var endlnum: number = search($'^\s*{endmarker}$', 'nW') + var is_trimmed: bool = line_A.text =~ $'.*\s\%(trim\%(\s\+eval\)\=\)\s\+[A-Z]\+{END_OF_LINE}' + b:vimindent = { + is_HereDoc: true, + startlnum: line_A.lnum, + endlnum: endlnum, + endmarker: endmarker, + is_trimmed: is_trimmed, + } + if is_trimmed + b:vimindent.startindent = Indent(line_A.lnum) + endif + RegisterCacheInvalidation() +enddef + +def CacheFuncHeader(startlnum: number) # {{{2 + var pos: list = getcurpos() + cursor(startlnum, 1) + if search('(', 'W', startlnum) <= 0 + return + endif + var endlnum: number = SearchPair('(', '', ')', 'nW') + setpos('.', pos) + if endlnum == startlnum + return + endif + + b:vimindent = { + is_FuncHeader: true, + startindent: startlnum->Indent(), + endlnum: endlnum, + } + RegisterCacheInvalidation() +enddef + +def CacheBracketBlock(line_A: dict) # {{{2 + var pos: list = getcurpos() + var opening: string = line_A.text->matchstr(CHARACTER_UNDER_CURSOR) + var closing: string = {'[': ']', '{': '}', '(': ')'}[opening] + var endlnum: number = SearchPair(opening, '', closing, 'nW') + setpos('.', pos) + if endlnum <= line_A.lnum + return + endif + + if !exists('b:vimindent') + b:vimindent = { + is_BracketBlock: true, + is_on_named_block_line: line_A.text =~ STARTS_NAMED_BLOCK, + block_stack: [], + } + endif + + var is_dict: bool + var is_curly_block: bool + if opening == '{' + if line_A.text =~ STARTS_CURLY_BLOCK + [is_dict, is_curly_block] = [false, true] + else + [is_dict, is_curly_block] = [true, false] + endif + endif + b:vimindent.block_stack->insert({ + is_dict: is_dict, + is_curly_block: is_curly_block, + startline: line_A.text, + startlnum: line_A.lnum, + endlnum: endlnum, + }) + + RegisterCacheInvalidation() +enddef + +def RegisterCacheInvalidation() # {{{2 + # invalidate the cache so that it's not used for the next `=` normal command + autocmd_add([{ + cmd: 'unlet! b:vimindent', + event: 'ModeChanged', + group: '__VimIndent__', + once: true, + pattern: '*:n', + replace: true, + }]) +enddef + +def RemovePastBracketBlock(line_A: dict): dict # {{{2 + var stack: list> = b:vimindent.block_stack + + var removed: dict + if line_A.lnum > stack[0].endlnum + removed = stack[0] + endif + + stack->filter((_, block: dict): bool => line_A.lnum <= block.endlnum) + if stack->empty() + unlet! b:vimindent + endif + return removed +enddef +# }}}1 +# Util {{{1 +# Get {{{2 +def Indent(lnum: number): number # {{{3 + if lnum <= 0 + # Don't return `-1`. It could cause `Expr()` to return a non-multiple of `'shiftwidth'`.{{{ + # + # It would be OK if we were always returning `Indent()` directly. But + # we don't. Most of the time, we include it in some computation + # like `Indent(...) + shiftwidth()`. If `'shiftwidth'` is `4`, and + # `Indent()` returns `-1`, `Expr()` will end up returning `3`. + #}}} + return 0 + endif + return indent(lnum) +enddef + +def BlockStartKeyword(line: string): string # {{{3 + var kwd: string = line->matchstr('\l\+') + return fullcommand(kwd, false) +enddef + +def MatchingOpenBracket(line: dict): number # {{{3 + var end: string = line.text->matchstr(CLOSING_BRACKET) + var start: string = {']': '[', '}': '{', ')': '('}[end] + cursor(line.lnum, 1) + return SearchPairStart(start, '', end) +enddef + +def FirstLinePreviousCommand(line: dict): dict # {{{3 + var line_B: dict = line + + while line_B.lnum > 1 + var code_line_above: dict = PrevCodeLine(line_B.lnum) + + if line_B.text =~ CLOSING_BRACKET_AT_SOL + var n: number = MatchingOpenBracket(line_B) + + if n <= 0 + break + endif + + line_B.lnum = n + line_B.text = getline(line_B.lnum) + continue + + elseif line_B->IsFirstLineOfCommand(code_line_above) + break + endif + + line_B = code_line_above + endwhile + + return line_B +enddef + +def PrevCodeLine(lnum: number): dict # {{{3 + var line: string = getline(lnum) + if line =~ '^\s*[A-Z]\+$' + var endmarker: string = line->matchstr('[A-Z]\+') + var pos: list = getcurpos() + cursor(lnum, 1) + var n: number = search(ASSIGNS_HEREDOC, 'bnW') + setpos('.', pos) + if n > 0 + line = getline(n) + if line =~ $'{HEREDOC_OPERATOR}\s\+{endmarker}' + return {lnum: n, text: line} + endif + endif + endif + + var n: number = prevnonblank(lnum - 1) + line = getline(n) + while line =~ COMMENT && n > 1 + n = prevnonblank(n - 1) + line = getline(n) + endwhile + # If we get back to the first line, we return 1 no matter what; even if it's a + # commented line. That should not cause an issue though. We just want to + # avoid a commented line above which there is a line of code which is more + # relevant. There is nothing above the first line. + return {lnum: n, text: line} +enddef + +def NextCodeLine(): number # {{{3 + var last: number = line('$') + if v:lnum == last + return 0 + endif + + var lnum: number = v:lnum + 1 + while lnum <= last + var line: string = getline(lnum) + if line != '' && line !~ COMMENT + return lnum + endif + ++lnum + endwhile + return 0 +enddef + +def SearchPair( # {{{3 + start: string, + middle: string, + end: string, + flags: string, + stopline = 0, + ): number + + var s: string = start + var e: string = end + if start == '[' || start == ']' + s = s->escape('[]') + endif + if end == '[' || end == ']' + e = e->escape('[]') + endif + return searchpair(s, middle, e, flags, (): bool => InCommentOrString(), stopline, TIMEOUT) +enddef + +def SearchPairStart( # {{{3 + start: string, + middle: string, + end: string, + ): number + return SearchPair(start, middle, end, 'bnW') +enddef + +def SearchPairEnd( # {{{3 + start: string, + middle: string, + end: string, + stopline = 0, + ): number + return SearchPair(start, middle, end, 'nW', stopline) +enddef +# }}}2 +# Test {{{2 +def AtStartOf(line_A: dict, syntax: string): bool # {{{3 + if syntax == 'BracketBlock' + return AtStartOfBracketBlock(line_A) + endif + + var pat: string = { + HereDoc: ASSIGNS_HEREDOC, + FuncHeader: STARTS_FUNCTION + }[syntax] + return line_A.text =~ pat + && (!exists('b:vimindent') || !b:vimindent->has_key('is_HereDoc')) +enddef + +def AtStartOfBracketBlock(line_A: dict): bool # {{{3 + # We ignore bracket blocks while we're indenting a function header + # because it makes the logic simpler. It might mean that we don't + # indent correctly a multiline bracket block inside a function header, + # but that's a corner case for which it doesn't seem worth making the + # code more complex. + if exists('b:vimindent') + && !b:vimindent->has_key('is_BracketBlock') + return false + endif + + var pos: list = getcurpos() + cursor(line_A.lnum, [line_A.lnum, '$']->col()) + + if SearchPair(OPENING_BRACKET, '', CLOSING_BRACKET, 'bcW', line_A.lnum) <= 0 + setpos('.', pos) + return false + endif + # Don't restore the cursor position. + # It needs to be on a bracket for `CacheBracketBlock()` to work as intended. + + return line_A->EndsWithOpeningBracket() + || line_A->EndsWithCommaOrDictKey() + || line_A->EndsWithLambdaArrow() +enddef + +def ContinuesBelowBracketBlock( # {{{3 + line_A: string, + line_B: dict, + block: dict + ): bool + + return !block->empty() + && (line_A =~ LINE_CONTINUATION_AT_SOL + || line_B->EndsWithLineContinuation()) +enddef + +def IsInside(lnum: number, syntax: string): bool # {{{3 + if !exists('b:vimindent') + || !b:vimindent->has_key($'is_{syntax}') + return false + endif + + if syntax == 'BracketBlock' + if !b:vimindent->has_key('block_stack') + || b:vimindent.block_stack->empty() + return false + endif + return lnum <= b:vimindent.block_stack[0].endlnum + endif + + return lnum <= b:vimindent.endlnum +enddef + +def IsRightBelow(lnum: number, syntax: string): bool # {{{3 + return exists('b:vimindent') + && b:vimindent->has_key($'is_{syntax}') + && lnum > b:vimindent.endlnum +enddef + +def IsInThisBlock(line_A: dict, lnum: number): bool # {{{3 + var pos: list = getcurpos() + cursor(lnum, [lnum, '$']->col()) + var end: number = SearchPairEnd('{', '', '}') + setpos('.', pos) + + return line_A.lnum <= end +enddef + +def IsFirstLineOfCommand(line_1: dict, line_2: dict): bool # {{{3 + if line_1.text->Is_IN_KeywordForLoop(line_2.text) + return false + endif + + if line_1.text =~ RANGE_AT_SOL + || line_1.text =~ PLUS_MINUS_COMMAND + return true + endif + + if line_2.text =~ DICT_KEY + && !line_1->IsInThisBlock(line_2.lnum) + return true + endif + + var line_1_is_good: bool = line_1.text !~ COMMENT + && line_1.text !~ DICT_KEY + && line_1.text !~ LINE_CONTINUATION_AT_SOL + + var line_2_is_good: bool = !line_2->EndsWithLineContinuation() + + return line_1_is_good && line_2_is_good +enddef + +def Is_IN_KeywordForLoop(line_1: string, line_2: string): bool # {{{3 + return line_2 =~ '^\s*for\s' + && line_1 =~ '^\s*in\s' +enddef + +def InCommentOrString(): bool # {{{3 + for synID: number in synstack('.', col('.')) + if synIDattr(synID, 'name') =~ '\ccomment\|string\|heredoc' + return true + endif + endfor + + return false +enddef + +def AlsoClosesBlock(line_B: dict): bool # {{{3 + # We know that `line_B` opens a block. + # Let's see if it also closes that block. + var kwd: string = BlockStartKeyword(line_B.text) + if !START_MIDDLE_END->has_key(kwd) + return false + endif + + var [start: string, middle: string, end: string] = START_MIDDLE_END[kwd] + var pos: list = getcurpos() + cursor(line_B.lnum, 1) + var block_end: number = SearchPairEnd(start, middle, end, line_B.lnum) + setpos('.', pos) + + return block_end > 0 +enddef + +def EndsWithComma(line: dict): bool # {{{3 + return NonCommentedMatch(line, COMMA_AT_EOL) +enddef + +def EndsWithCommaOrDictKey(line_A: dict): bool # {{{3 + return NonCommentedMatch(line_A, COMMA_OR_DICT_KEY_AT_EOL) +enddef + +def EndsWithCurlyBlock(line_B: dict): bool # {{{3 + return NonCommentedMatch(line_B, STARTS_CURLY_BLOCK) +enddef + +def EndsWithLambdaArrow(line_A: dict): bool # {{{3 + return NonCommentedMatch(line_A, LAMBDA_ARROW_AT_EOL) +enddef + +def EndsWithLineContinuation(line_B: dict): bool # {{{3 + return NonCommentedMatch(line_B, LINE_CONTINUATION_AT_EOL) +enddef + +def EndsWithOpeningBracket(line: dict): bool # {{{3 + return NonCommentedMatch(line, OPENING_BRACKET_AT_EOL) +enddef + +def NonCommentedMatch(line: dict, pat: string): bool # {{{3 + # Could happen if there is no code above us, and we're not on the 1st line. + # In that case, `PrevCodeLine()` returns `{lnum: 0, line: ''}`. + if line.lnum == 0 + return false + endif + + if line.text =~ PLUS_MINUS_COMMAND + return false + endif + + # In `argdelete *`, `*` is not a multiplication operator. + # TODO: Other commands can accept `*` as an argument. Handle them too. + if line.text =~ '\matchstr($'\s\+\zs{PATTERN_DELIMITER}\ze{END_OF_COMMAND}') + if !delim->empty() + delim = $'\V{delim}\m' + if line.text =~ $'\%(\S*{delim}\S\+\|\S\+{delim}\S*\)\s\+{delim}{END_OF_COMMAND}' + return false + endif + endif + # TODO: We might still miss some corner cases:{{{ + # + # conflated with arithmetic division + # v + # substitute/pat / rep / + # echo + # ^--^ + # ✘ + # + # A better way to handle all these corner cases, would be to inspect the top + # of the syntax stack: + # + # :echo synID('.', col('.'), v:false)->synIDattr('name') + # + # Unfortunately, the legacy syntax plugin is not accurate enough. + # For example, it doesn't highlight a slash as an operator. + # }}} + + # `%` at the end of a line is tricky. + # It might be the modulo operator or the current file (e.g. `edit %`). + # Let's assume it's the latter. + if line.text =~ $'%{END_OF_COMMAND}' + return false + endif + + # `:help cd-` + if line.text =~ CD_COMMAND + return false + endif + + # At the end of a mapping, any character might appear; e.g. a paren: + # + # nunmap ( + # + # Don't conflate this with a line continuation symbol. + if line.text =~ MAPPING_COMMAND + return false + endif + + # not a comparison operator + # vv + # normal! == + if line.text =~ NORMAL_COMMAND + return false + endif + + var pos: list = getcurpos() + cursor(line.lnum, 1) + var match_lnum: number = search(pat, 'cnW', line.lnum, TIMEOUT, (): bool => InCommentOrString()) + setpos('.', pos) + return match_lnum > 0 +enddef +# }}}1 +# vim:sw=4 diff --git a/runtime/compiler/hare.vim b/runtime/compiler/hare.vim new file mode 100644 index 0000000000..c0fa68cc00 --- /dev/null +++ b/runtime/compiler/hare.vim @@ -0,0 +1,31 @@ +" Vim compiler file +" Compiler: Hare Compiler +" Maintainer: Amelia Clarke +" Last Change: 2022-09-21 + +if exists("g:current_compiler") + finish +endif +let g:current_compiler = "hare" + +let s:cpo_save = &cpo +set cpo&vim + +if exists(':CompilerSet') != 2 + command -nargs=* CompilerSet setlocal +endif + +if filereadable("Makefile") || filereadable("makefile") + CompilerSet makeprg=make +else + CompilerSet makeprg=hare\ build +endif + +CompilerSet errorformat= + \Error\ %f:%l:%c:\ %m, + \Syntax\ error:\ %.%#\ at\ %f:%l:%c\\,\ %m, + \%-G%.%# + +let &cpo = s:cpo_save +unlet s:cpo_save +" vim: tabstop=2 shiftwidth=2 expandtab diff --git a/runtime/doc/cmdline.txt b/runtime/doc/cmdline.txt index e29369cb66..a9d3b36422 100644 --- a/runtime/doc/cmdline.txt +++ b/runtime/doc/cmdline.txt @@ -1,4 +1,4 @@ -*cmdline.txt* For Vim version 9.0. Last change: 2022 Jun 16 +*cmdline.txt* For Vim version 9.0. Last change: 2022 Sep 26 VIM REFERENCE MANUAL by Bram Moolenaar @@ -806,7 +806,7 @@ Count and Range *N:* When giving a count before entering ":", this is translated into: :.,.+(count - 1) -In words: The 'count' lines at and after the cursor. Example: To delete +In words: The "count" lines at and after the cursor. Example: To delete three lines: > 3:d is translated into: .,.+2d < diff --git a/runtime/doc/develop.txt b/runtime/doc/develop.txt index f76a9456e2..9325694755 100644 --- a/runtime/doc/develop.txt +++ b/runtime/doc/develop.txt @@ -1,4 +1,4 @@ -*develop.txt* For Vim version 9.0. Last change: 2020 Aug 15 +*develop.txt* For Vim version 9.0. Last change: 2022 Sep 20 VIM REFERENCE MANUAL by Bram Moolenaar diff --git a/runtime/doc/ft_context.txt b/runtime/doc/ft_context.txt index ba6bd0d819..e608c5b849 100644 --- a/runtime/doc/ft_context.txt +++ b/runtime/doc/ft_context.txt @@ -1,4 +1,4 @@ -*ft_context.txt* For Vim version 9.0. Last change: 2022 Aug 12 +*ft_context.txt* For Vim version 9.0. Last change: 2022 Sep 27 This is the documentation for the ConTeXt filetype plugin. @@ -23,13 +23,12 @@ ConTeXt, similarly to LaTeX, is a macro-based typesetting system built on TeX: < The ConTeXt plugin provides syntax highlighting, completion and support for typesetting ConTeXt documents. The recommended way to typeset a document is to -use |:ConTeXt|. This will invoke the `mtxrun` script that is found in $PATH. +use |:ConTeXt|. This will invoke the `mtxrun` script that is found in `$PATH`. -For more fine grained control over the command and its environment, you may -invoke `context.Typeset()` directly (or `context#Typeset()` from legacy Vim -script). For instance, if you have installed a version of ConTeXt in -`~/context`, you may define a function to use it (you may put the following -code in `~/.vim/after/ftplugin/context.vim`) similar to the following: +For more fine grained control over the command and its environment, +`context.Typeset()` can be used directly (or `context#Typeset()` from legacy +Vim script). For instance, if a version of ConTeXt is installed in +`~/context`, you may define a function to use it similar to the following: > import autoload 'context.vim' @@ -38,14 +37,15 @@ code in `~/.vim/after/ftplugin/context.vim`) similar to the following: printf("%s/context/tex/texmf--/bin:%s", $HOME, $PATH)} context.Typeset("%", env) enddef -< -and perhaps use it with a mapping: + +This code may go in `~/.vim/after/ftplugin/context.vim`. A mapping can then be +defined to invoke the custom command: > nnoremap t MyConTeXt() < `context.Typeset()` accepts a third optional argument to specify a custom -typesetting command. Such argument must be a function that takes a path and -returns the command as a List. For example: +typesetting command. That must be a function that takes a path and returns the +command as a List. For example: > def ConTeXtCustomCommand(path: string): list return ['mtxrun', '--script', 'context', '--nonstopmode, path] @@ -103,14 +103,20 @@ Stop all the ConTeXt jobs currently running in the background. Settings ~ *'b:context_ignore_makefile'* *'g:context_ignore_makefile'* -`make` can be used to (synchronously) typeset a document. If a Makefile exists +`:make` can be used to (synchronously) typeset a document. If a Makefile exists and this option is not set, standard `make` is used. If this option is set, `mtxrun` is invoked instead, even if a Makefile exists. > g:context_ignore_makefile = 0 < -NOTE: before using `make`, set the working directory of the buffer to the +NOTE: before using `:make`, set the working directory of the buffer to the directory of the file to be typeset. + + *'g:context_extra_options'* +A list of additional options to pass to `mtxrun`. +> + g:context_extra_options = [] +< *'b:context_include'* *'g:context_include'* Dictionary of filetype/GROUP pairs for which syntax highlighting should be diff --git a/runtime/doc/indent.txt b/runtime/doc/indent.txt index 2ebbadbf8a..38c173bce2 100644 --- a/runtime/doc/indent.txt +++ b/runtime/doc/indent.txt @@ -1227,13 +1227,31 @@ comments will be indented according to the correctly indented code. VIM *ft-vim-indent* - *g:vim_indent_cont* -For indenting Vim scripts there is one variable that specifies the amount of -indent for a continuation line, a line that starts with a backslash: > - - :let g:vim_indent_cont = shiftwidth() * 3 + *g:vim_indent* +Vim scripts indentation can be configured with the `g:vim_indent` dictionary +variable. It supports 3 keys, `line_continuation`, `more_in_bracket_block`, +and `searchpair_timeout`. +`line_continuation` expects a number which will be added to the indent level of +a continuation line starting with a backslash, and defaults to +`shiftwidth() * 3`. It also accepts a string, which is evaluated at runtime. +`more_in_bracket_block` expects a boolean value; when on, an extra +`shiftwidth()` is added inside blocks surrounded with brackets. It defaults to +`v:false`. +`searchpair_timeout` expects a number which will be passed to `searchpair()` as +a timeout. Increasing the value might give more accurate results, but also +causes the indentation to take more time. It defaults to 100 (milliseconds). + +Example of configuration: + + let g:vim_indent = #{ + \ line_continuation: shiftwidth() * 3, + \ more_in_bracket_block: v:false, + \ searchpair_timeout: 100, + \ } -Three times shiftwidth is the default value. + *g:vim_indent_cont* +This variable is equivalent to `g:vim_indent.line_continuation`. +It's supported for backward compatibility. vim:tw=78:ts=8:noet:ft=help:norl: diff --git a/runtime/doc/map.txt b/runtime/doc/map.txt index f1bfd75de6..bd1381a37d 100644 --- a/runtime/doc/map.txt +++ b/runtime/doc/map.txt @@ -1,4 +1,4 @@ -*map.txt* For Vim version 9.0. Last change: 2022 Sep 12 +*map.txt* For Vim version 9.0. Last change: 2022 Sep 26 VIM REFERENCE MANUAL by Bram Moolenaar @@ -1761,7 +1761,8 @@ The valid escape sequences are If the first two characters of an escape sequence are "q-" (for example, ) then the value is quoted in such a way as to make it a valid value for use in an expression. This uses the argument as one single value. -When there is no argument is an empty string. +When there is no argument is an empty string. See the +|q-args-example| below. ** To allow commands to pass their arguments on to a user-defined function, there is a special form ("function args"). This splits the command @@ -1771,7 +1772,7 @@ See the Mycmd example below. If no arguments are given is removed. To embed whitespace into an argument of , prepend a backslash. replaces every pair of backslashes (\\) with one backslash. A backslash followed by a character other than white space or a backslash -remains unmodified. Overview: +remains unmodified. Also see |f-args-example| below. Overview: command ~ XX ab 'ab' @@ -1785,7 +1786,8 @@ remains unmodified. Overview: XX a\\\\b 'a\\b' XX a\\\\ b 'a\\', 'b' -Examples > + +Examples for user commands: > " Delete everything after here to the end :com Ddel +,$d @@ -1801,7 +1803,8 @@ Examples > " Count the number of lines in the range :com! -range -nargs=0 Lines echo - + 1 "lines" - " Call a user function (example of ) +< *f-args-example* +Call a user function (example of ) > :com -nargs=* Mycmd call Myfunc() When executed as: > @@ -1809,7 +1812,8 @@ When executed as: > This will invoke: > :call Myfunc("arg1","arg2") - :" A more substantial example +< *q-args-example* +A more substantial example: > :function Allargs(command) : let i = 0 : while i < argc() diff --git a/runtime/doc/motion.txt b/runtime/doc/motion.txt index 4253684d1a..263c4f3ac3 100644 --- a/runtime/doc/motion.txt +++ b/runtime/doc/motion.txt @@ -1,4 +1,4 @@ -*motion.txt* For Vim version 9.0. Last change: 2022 Apr 18 +*motion.txt* For Vim version 9.0. Last change: 2022 Sep 26 VIM REFERENCE MANUAL by Bram Moolenaar @@ -1145,7 +1145,7 @@ g; Go to [count] older position in change list. (not a motion command) *g,* *E663* -g, Go to [count] newer cursor position in change list. +g, Go to [count] newer position in change list. Just like |g;| but in the opposite direction. (not a motion command) diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 336d4497d5..4ea75ba2db 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -1,4 +1,4 @@ -*options.txt* For Vim version 9.0. Last change: 2022 Sep 09 +*options.txt* For Vim version 9.0. Last change: 2022 Sep 27 VIM REFERENCE MANUAL by Bram Moolenaar @@ -1702,7 +1702,8 @@ A jump table for the options with a short description can be found at |Q_op|. after that. Therefore do not append an item with += but use ^= to prepend, e.g.: > set clipboard^=unnamed -< These names are recognized: +< When using the GUI see |'go-A'|. + These names are recognized: *clipboard-unnamed* unnamed When included, Vim will use the clipboard register '*' @@ -3978,6 +3979,8 @@ A jump table for the options with a short description can be found at |Q_op|. "A" - yes "aA" yes yes + When using a terminal see the 'clipboard' option. + *'go-c'* 'c' Use console dialogs instead of popup dialogs for simple choices. diff --git a/runtime/doc/pattern.txt b/runtime/doc/pattern.txt index 7700d26e10..a9452c5c3f 100644 --- a/runtime/doc/pattern.txt +++ b/runtime/doc/pattern.txt @@ -1,4 +1,4 @@ -*pattern.txt* For Vim version 9.0. Last change: 2022 Mar 04 +*pattern.txt* For Vim version 9.0. Last change: 2022 Sep 24 VIM REFERENCE MANUAL by Bram Moolenaar @@ -134,6 +134,11 @@ gD Goto global Declaration. When the cursor is on a CTRL-C Interrupt current (search) command. Use CTRL-Break on MS-Windows |dos-CTRL-Break|. In Normal mode, any pending command is aborted. + When Vim was started with output redirected and there + are no changed buffers CTRL-C exits Vim. That is to + help users who use "vim file | grep word" and don't + know how to get out (blindly typing :qa would + work). *:noh* *:nohlsearch* :noh[lsearch] Stop the highlighting for the 'hlsearch' option. It diff --git a/runtime/doc/quickfix.txt b/runtime/doc/quickfix.txt index 67947854df..032e9a7960 100644 --- a/runtime/doc/quickfix.txt +++ b/runtime/doc/quickfix.txt @@ -1,4 +1,4 @@ -*quickfix.txt* For Vim version 9.0. Last change: 2022 Feb 22 +*quickfix.txt* For Vim version 9.0. Last change: 2022 Sep 26 VIM REFERENCE MANUAL by Bram Moolenaar @@ -478,7 +478,7 @@ You can parse a list of lines using 'errorformat' without creating or modifying a quickfix list using the |getqflist()| function. Examples: > echo getqflist({'lines' : ["F1:10:Line10", "F2:20:Line20"]}) echo getqflist({'lines' : systemlist('grep -Hn quickfix *')}) -This returns a dictionary where the 'items' key contains the list of quickfix +This returns a dictionary where the "items" key contains the list of quickfix entries parsed from lines. The following shows how to use a custom 'errorformat' to parse the lines without modifying the 'errorformat' option: > echo getqflist({'efm' : '%f#%l#%m', 'lines' : ['F1#10#Line']}) @@ -597,7 +597,7 @@ can go back to the unfiltered list using the |:colder|/|:lolder| command. quickfix command or function, the |b:changedtick| variable is incremented. You can get the number of this buffer using the getqflist() and getloclist() - functions by passing the 'qfbufnr' item. For a + functions by passing the "qfbufnr" item. For a location list, this buffer is wiped out when the location list is removed. @@ -2011,7 +2011,7 @@ The function should return a single line of text to display in the quickfix window for each entry from start_idx to end_idx. The function can obtain information about the entries using the |getqflist()| function and specifying the quickfix list identifier "id". For a location list, getloclist() function -can be used with the 'winid' argument. If an empty list is returned, then the +can be used with the "winid" argument. If an empty list is returned, then the default format is used to display all the entries. If an item in the returned list is an empty string, then the default format is used to display the corresponding entry. diff --git a/runtime/doc/repeat.txt b/runtime/doc/repeat.txt index f8602ba8c9..059c6393d2 100644 --- a/runtime/doc/repeat.txt +++ b/runtime/doc/repeat.txt @@ -1,4 +1,4 @@ -*repeat.txt* For Vim version 9.0. Last change: 2022 Jun 18 +*repeat.txt* For Vim version 9.0. Last change: 2022 Sep 22 VIM REFERENCE MANUAL by Bram Moolenaar @@ -92,7 +92,8 @@ pattern and do not match another pattern: > This first finds all lines containing "found", but only executes {cmd} when there is no match for "notfound". -To execute a non-Ex command, you can use the `:normal` command: > +Any Ex command can be used, see |ex-cmd-index|. To execute a Normal mode +command, you can use the `:normal` command: > :g/pat/normal {commands} Make sure that {commands} ends with a whole command, otherwise Vim will wait for you to type the rest of the command for each match. The screen will not @@ -200,7 +201,8 @@ For writing a Vim script, see chapter 41 of the user manual |usr_41.txt|. *:source-range* :[range]so[urce] [++clear] Read Ex commands from the [range] of lines in the - current buffer. + current buffer. When [range] is omitted read all + lines. When sourcing commands from the current buffer, the same script-ID || is used even if the buffer is @@ -904,6 +906,11 @@ executed like a normal Ex command, "step" will stop once in the compiled context, where local variables can be inspected, and once just before executing the command. +In a :def function variables that haven't been declared yet cannot be +inspected. Variables that have been declared can be inspected, also when the +block they were declared in has finished. In commands this would not be +possible, thus is slightly misleading (but can be useful). + The backtrace shows the hierarchy of function calls, e.g.: >bt ~ 3 function One[3] ~ diff --git a/runtime/doc/syntax.txt b/runtime/doc/syntax.txt index adc1d56955..1587df5e7c 100644 --- a/runtime/doc/syntax.txt +++ b/runtime/doc/syntax.txt @@ -1,4 +1,4 @@ -*syntax.txt* For Vim version 9.0. Last change: 2022 Jun 10 +*syntax.txt* For Vim version 9.0. Last change: 2022 Sep 26 VIM REFERENCE MANUAL by Bram Moolenaar @@ -3153,7 +3153,7 @@ The default is to use the twice sh_minlines. Set it to a smaller number to speed up displaying. The disadvantage is that highlight errors may appear. syntax/sh.vim tries to flag certain problems as errors; usually things like -extra ']'s, 'done's, 'fi's, etc. If you find the error handling problematic +unmatched "]", "done", "fi", etc. If you find the error handling problematic for your purposes, you may suppress such error highlighting by putting the following line in your .vimrc: > diff --git a/runtime/doc/tags b/runtime/doc/tags index 1fdc74fc9b..2c4a550dee 100644 --- a/runtime/doc/tags +++ b/runtime/doc/tags @@ -302,6 +302,7 @@ $quote eval.txt /*$quote* 'fs' options.txt /*'fs'* 'fsync' options.txt /*'fsync'* 'ft' options.txt /*'ft'* +'g:context_extra_options' ft_context.txt /*'g:context_extra_options'* 'g:context_ignore_makefile' ft_context.txt /*'g:context_ignore_makefile'* 'g:context_include' ft_context.txt /*'g:context_include'* 'g:mf_other_macros' ft_mp.txt /*'g:mf_other_macros'* @@ -4343,6 +4344,7 @@ E1302 eval.txt /*E1302* E1303 map.txt /*E1303* E1304 vim9.txt /*E1304* E1305 textprop.txt /*E1305* +E1306 vim9.txt /*E1306* E131 userfunc.txt /*E131* E132 userfunc.txt /*E132* E133 userfunc.txt /*E133* @@ -6802,6 +6804,7 @@ extendnew() builtin.txt /*extendnew()* extension-removal cmdline.txt /*extension-removal* extensions-improvements todo.txt /*extensions-improvements* f motion.txt /*f* +f-args-example map.txt /*f-args-example* false vim9.txt /*false* false-variable eval.txt /*false-variable* falsy eval.txt /*falsy* @@ -7399,6 +7402,7 @@ g:tex_subscripts syntax.txt /*g:tex_subscripts* g:tex_superscripts syntax.txt /*g:tex_superscripts* g:tex_verbspell syntax.txt /*g:tex_verbspell* g:var eval.txt /*g:var* +g:vim_indent indent.txt /*g:vim_indent* g:vim_indent_cont indent.txt /*g:vim_indent_cont* g:vimball_home pi_vimball.txt /*g:vimball_home* g:vimball_mkdir pi_vimball.txt /*g:vimball_mkdir* @@ -9173,6 +9177,7 @@ pythonx if_pyth.txt /*pythonx* pythonx-directory if_pyth.txt /*pythonx-directory* pyxeval() builtin.txt /*pyxeval()* q repeat.txt /*q* +q-args-example map.txt /*q-args-example* q/ cmdline.txt /*q\/* q: cmdline.txt /*q:* q? cmdline.txt /*q?* diff --git a/runtime/doc/textprop.txt b/runtime/doc/textprop.txt index 5fb53aff12..5a849fed69 100644 --- a/runtime/doc/textprop.txt +++ b/runtime/doc/textprop.txt @@ -1,4 +1,4 @@ -*textprop.txt* For Vim version 9.0. Last change: 2022 Sep 17 +*textprop.txt* For Vim version 9.0. Last change: 2022 Sep 21 VIM REFERENCE MANUAL by Bram Moolenaar @@ -143,10 +143,11 @@ prop_add({lnum}, {col}, {props}) automatically to a negative number; otherwise zero is used *E1305* - text text to be displayed before {col}, or after the - line if {col} is zero; prepend and/or append - spaces for padding with highlighting; cannot - be used with "length", "end_lnum" and "end_col" + text text to be displayed before {col}, or + above/below the line if {col} is zero; prepend + and/or append spaces for padding with + highlighting; cannot be used with "length", + "end_lnum" and "end_col" |virtual-text| *E1294* text_align when "text" is present and {col} is zero; specifies where to display the text: @@ -191,12 +192,23 @@ prop_add({lnum}, {col}, {props}) If not found an error is given. *virtual-text* When "text" is used and the column is non-zero then this text - will be displayed at the start location of the text property - after the text. The text of the buffer line will be shifted - to make room. This is called "virtua