annotate runtime/indent/hamster.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 3b34837f4538
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1125
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
1 " Vim indent file
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
2 " Language: Hamster Script
25973
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
3 " Version: 2.0.6.1
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
4 " Last Change: 2021 Oct 11
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
5 " Maintainer: David Fishburn <dfishburn dot vim at gmail dot com>
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
6 " Download: https://www.vim.org/scripts/script.php?script_id=1099
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
7 "
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
8 " 2.0.6.1 (Oct 2021)
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
9 " Added b:undo_indent
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
10 " Added cpo check
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
11 "
1125
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
12
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
13 " Only load this indent file when no other was loaded.
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
14 if exists("b:did_indent")
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
15 finish
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
16 endif
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
17 let b:did_indent = 1
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
18
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
19 setlocal indentkeys+==~if,=~else,=~endif,=~endfor,=~endwhile
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
20 setlocal indentkeys+==~do,=~until,=~while,=~repeat,=~for,=~loop
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
21 setlocal indentkeys+==~sub,=~endsub
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
22
25973
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
23 let b:undo_indent = "setl indentkeys<"
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
24
1125
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
25 " Define the appropriate indent function but only once
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
26 setlocal indentexpr=HamGetFreeIndent()
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
27 if exists("*HamGetFreeIndent")
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
28 finish
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
29 endif
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
30
25973
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
31 let s:keepcpo = &cpo
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
32 set cpo&vim
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
33
1125
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
34 function HamGetIndent(lnum)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
35 let ind = indent(a:lnum)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
36 let prevline=getline(a:lnum)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
37
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
38 " Add a shiftwidth to statements following if, else, elseif,
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
39 " case, select, default, do, until, while, for, start
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
40 if prevline =~? '^\s*\<\(if\|else\%(if\)\?\|for\|repeat\|do\|while\|sub\)\>'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 1125
diff changeset
41 let ind = ind + shiftwidth()
1125
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
42 endif
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
43
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
44 " Subtract a shiftwidth from else, elseif, end(if|while|for), until
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
45 let line = getline(v:lnum)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
46 if line =~? '^\s*\(else\|elseif\|loop\|until\|end\%(if\|while\|for\|sub\)\)\>'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 1125
diff changeset
47 let ind = ind - shiftwidth()
1125
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
48 endif
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
49
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
50 return ind
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
51 endfunction
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
52
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
53 function HamGetFreeIndent()
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
54 " Find the previous non-blank line
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
55 let lnum = prevnonblank(v:lnum - 1)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
56
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
57 " Use zero indent at the top of the file
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
58 if lnum == 0
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
59 return 0
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
60 endif
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
61
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
62 let ind=HamGetIndent(lnum)
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
63 return ind
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
64 endfunction
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
65
25973
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
66 " Restore:
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
67 let &cpo = s:keepcpo
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
68 unlet s:keepcpo
3b34837f4538 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
69
1125
96cd8222a819 updated for version 7.1a
vimboss
parents:
diff changeset
70 " vim:sw=2 tw=80