Mercurial > vim
view runtime/ftplugin/zimbu.vim @ 33399:95db67c7b754 v9.0.1958
patch 9.0.1958: cannot complete option values
Commit: https://github.com/vim/vim/commit/900894b09a95398dfc75599e9f0aa2ea25723384
Author: Yee Cheng Chin <ychin.git@gmail.com>
Date: Fri Sep 29 20:42:32 2023 +0200
patch 9.0.1958: cannot complete option values
Problem: cannot complete option values
Solution: Add completion functions for several options
Add cmdline tab-completion for setting string options
Add tab-completion for setting string options on the cmdline using
`:set=` (along with `:set+=` and `:set-=`).
The existing tab completion for setting options currently only works
when nothing is typed yet, and it only fills in with the existing value,
e.g. when the user does `:set diffopt=<Tab>` it will be completed to
`set diffopt=internal,filler,closeoff` and nothing else. This isn't too
useful as a user usually wants auto-complete to suggest all the possible
values, such as 'iblank', or 'algorithm:patience'.
For set= and set+=, this adds a new optional callback function for each
option that can be invoked when doing completion. This allows for each
option to have control over how completion works. For example, in
'diffopt', it will suggest the default enumeration, but if `algorithm:`
is selected, it will further suggest different algorithm types like
'meyers' and 'patience'. When using set=, the existing option value will
be filled in as the first choice to preserve the existing behavior. When
using set+= this won't happen as it doesn't make sense.
For flag list options (e.g. 'mouse' and 'guioptions'), completion will
take into account existing typed values (and in the case of set+=, the
existing option value) to make sure it doesn't suggest duplicates.
For set-=, there is a new `ExpandSettingSubtract` function which will
handle flag list and comma-separated options smartly, by only suggesting
values that currently exist in the option.
Note that Vim has some existing code that adds special handling for
'filetype', 'syntax', and misc dir options like 'backupdir'. This change
preserves them as they already work, instead of converting to the new
callback API for each option.
closes: #13182
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Fri, 29 Sep 2023 20:45:04 +0200 |
parents | 4027cefc2aab |
children |
line wrap: on
line source
" Vim filetype plugin file " Language: Zimbu " Maintainer: The Vim Project <https://github.com/vim/vim> " Last Change: 2023 Aug 10 " Former Maintainer: Bram Moolenaar <Bram@vim.org> " Only do this when not done yet for this buffer if exists("b:did_ftplugin") finish endif " Don't load another plugin for this buffer let b:did_ftplugin = 1 " Using line continuation here. let s:cpo_save = &cpo set cpo-=C let b:undo_ftplugin = "setl fo< com< ofu< efm< tw< et< sts< sw< | if has('vms') | setl isk< | endif" " Set 'formatoptions' to break comment lines but not other lines, " and insert the comment leader when hitting <CR> or using "o". setlocal fo-=t fo+=croql " Set completion with CTRL-X CTRL-O to autoloaded function. if exists('&ofu') setlocal ofu=ccomplete#Complete endif " Set 'comments' to format dashed lists in comments. " And to keep Zudocu comment characters. setlocal comments=sO:#\ -,mO:#\ \ ,exO:#/,s:/*,m:\ ,ex:*/,:#=,:#-,:#%,:# setlocal errorformat^=%f\ line\ %l\ col\ %c:\ %m,ERROR:\ %m " When the matchit plugin is loaded, this makes the % command skip parens and " braces in comments. if exists("loaded_matchit") && !exists("b:match_words") let b:match_words = '\(^\s*\)\@<=\(MODULE\|CLASS\|INTERFACE\|BITS\|ENUM\|SHARED\|FUNC\|REPLACE\|DEFINE\|PROC\|EQUAL\|MAIN\|IF\|GENERATE_IF\|WHILE\|REPEAT\|WITH\|DO\|FOR\|SWITCH\|TRY\)\>\|{\s*$:\(^\s*\)\@<=\(ELSE\|ELSEIF\|GENERATE_ELSE\|GENERATE_ELSEIF\|CATCH\|FINALLY\)\>:\(^\s*\)\@<=\(}\|\<UNTIL\>\)' let b:match_skip = 's:comment\|string\|zimbuchar' let b:undo_ftplugin ..= " | unlet! b:match_words b:match_skip" endif setlocal tw=78 setlocal et sts=2 sw=2 " Does replace when a dot, space or closing brace is typed. func! GCUpperDot(what) if v:char != ' ' && v:char != "\r" && v:char != "\x1b" && v:char != '.' && v:char != ')' && v:char != '}' && v:char != ',' " no space or dot after the typed text let g:got_char = v:char return a:what endif return GCUpperCommon(a:what) endfunc " Does not replace when a dot is typed. func! GCUpper(what) if v:char != ' ' && v:char != "\r" && v:char != "\x1b" && v:char != ')' && v:char != ',' " no space or other "terminating" character after the typed text let g:got_char = v:char return a:what endif return GCUpperCommon(a:what) endfunc " Only replaces when a space is typed. func! GCUpperSpace(what) if v:char != ' ' " no space after the typed text let g:got_char = v:char return a:what endif return GCUpperCommon(a:what) endfunc func! GCUpperCommon(what) let col = col(".") - strlen(a:what) if col > 1 && getline('.')[col - 2] != ' ' " no space before the typed text let g:got_char = 999 return a:what endif let synName = synIDattr(synID(line("."), col(".") - 2, 1), "name") if synName =~ 'Comment\|String\|zimbuCregion\|\<c' " inside a comment or C code let g:got_char = 777 return a:what endif let g:got_char = 1111 return toupper(a:what) endfunc iabbr <buffer> <expr> alias GCUpperSpace("alias") iabbr <buffer> <expr> arg GCUpperDot("arg") iabbr <buffer> <expr> break GCUpper("break") iabbr <buffer> <expr> case GCUpperSpace("case") iabbr <buffer> <expr> catch GCUpperSpace("catch") iabbr <buffer> <expr> check GCUpperDot("check") iabbr <buffer> <expr> class GCUpperSpace("class") iabbr <buffer> <expr> interface GCUpperSpace("interface") iabbr <buffer> <expr> implements GCUpperSpace("implements") iabbr <buffer> <expr> shared GCUpperSpace("shared") iabbr <buffer> <expr> continue GCUpper("continue") iabbr <buffer> <expr> default GCUpper("default") iabbr <buffer> <expr> extends GCUpper("extends") iabbr <buffer> <expr> do GCUpper("do") iabbr <buffer> <expr> else GCUpper("else") iabbr <buffer> <expr> elseif GCUpperSpace("elseif") iabbr <buffer> <expr> enum GCUpperSpace("enum") iabbr <buffer> <expr> exit GCUpper("exit") iabbr <buffer> <expr> false GCUpper("false") iabbr <buffer> <expr> fail GCUpper("fail") iabbr <buffer> <expr> finally GCUpper("finally") iabbr <buffer> <expr> for GCUpperSpace("for") iabbr <buffer> <expr> func GCUpperSpace("func") iabbr <buffer> <expr> if GCUpperSpace("if") iabbr <buffer> <expr> import GCUpperSpace("import") iabbr <buffer> <expr> in GCUpperSpace("in") iabbr <buffer> <expr> io GCUpperDot("io") iabbr <buffer> <expr> main GCUpper("main") iabbr <buffer> <expr> module GCUpperSpace("module") iabbr <buffer> <expr> new GCUpper("new") iabbr <buffer> <expr> nil GCUpper("nil") iabbr <buffer> <expr> ok GCUpper("ok") iabbr <buffer> <expr> proc GCUpperSpace("proc") iabbr <buffer> <expr> proceed GCUpper("proceed") iabbr <buffer> <expr> return GCUpper("return") iabbr <buffer> <expr> step GCUpperSpace("step") iabbr <buffer> <expr> switch GCUpperSpace("switch") iabbr <buffer> <expr> sys GCUpperDot("sys") iabbr <buffer> <expr> this GCUpperDot("this") iabbr <buffer> <expr> throw GCUpperSpace("throw") iabbr <buffer> <expr> try GCUpper("try") iabbr <buffer> <expr> to GCUpperSpace("to") iabbr <buffer> <expr> true GCUpper("true") iabbr <buffer> <expr> until GCUpperSpace("until") iabbr <buffer> <expr> while GCUpperSpace("while") iabbr <buffer> <expr> repeat GCUpper("repeat") let b:undo_ftplugin ..= \ " | iunabbr <buffer> alias" .. \ " | iunabbr <buffer> arg" .. \ " | iunabbr <buffer> break" .. \ " | iunabbr <buffer> case" .. \ " | iunabbr <buffer> catch" .. \ " | iunabbr <buffer> check" .. \ " | iunabbr <buffer> class" .. \ " | iunabbr <buffer> interface" .. \ " | iunabbr <buffer> implements" .. \ " | iunabbr <buffer> shared" .. \ " | iunabbr <buffer> continue" .. \ " | iunabbr <buffer> default" .. \ " | iunabbr <buffer> extends" .. \ " | iunabbr <buffer> do" .. \ " | iunabbr <buffer> else" .. \ " | iunabbr <buffer> elseif" .. \ " | iunabbr <buffer> enum" .. \ " | iunabbr <buffer> exit" .. \ " | iunabbr <buffer> false" .. \ " | iunabbr <buffer> fail" .. \ " | iunabbr <buffer> finally" .. \ " | iunabbr <buffer> for" .. \ " | iunabbr <buffer> func" .. \ " | iunabbr <buffer> if" .. \ " | iunabbr <buffer> import" .. \ " | iunabbr <buffer> in" .. \ " | iunabbr <buffer> io" .. \ " | iunabbr <buffer> main" .. \ " | iunabbr <buffer> module" .. \ " | iunabbr <buffer> new" .. \ " | iunabbr <buffer> nil" .. \ " | iunabbr <buffer> ok" .. \ " | iunabbr <buffer> proc" .. \ " | iunabbr <buffer> proceed" .. \ " | iunabbr <buffer> return" .. \ " | iunabbr <buffer> step" .. \ " | iunabbr <buffer> switch" .. \ " | iunabbr <buffer> sys" .. \ " | iunabbr <buffer> this" .. \ " | iunabbr <buffer> throw" .. \ " | iunabbr <buffer> try" .. \ " | iunabbr <buffer> to" .. \ " | iunabbr <buffer> true" .. \ " | iunabbr <buffer> until" .. \ " | iunabbr <buffer> while" .. \ " | iunabbr <buffer> repeat" if !exists("no_plugin_maps") && !exists("no_zimbu_maps") nnoremap <silent> <buffer> [[ m`:call ZimbuGoStartBlock()<CR> nnoremap <silent> <buffer> ]] m`:call ZimbuGoEndBlock()<CR> let b:undo_ftplugin ..= \ " | silent! exe 'nunmap <buffer> [['" .. \ " | silent! exe 'nunmap <buffer> ]]'" endif " Using a function makes sure the search pattern is restored func! ZimbuGoStartBlock() ?^\s*\(FUNC\|PROC\|MAIN\|ENUM\|CLASS\|INTERFACE\)\> endfunc func! ZimbuGoEndBlock() /^\s*\(FUNC\|PROC\|MAIN\|ENUM\|CLASS\|INTERFACE\)\> endfunc let &cpo = s:cpo_save unlet s:cpo_save