annotate runtime/indent/cucumber.vim @ 34042:9ece16460769

runtime(cucumber): Updates to indent and syntax Commit: https://github.com/vim/vim/commit/715a8058895f5908f44ee243fdafa431b6483e47 Author: Tim Pope <code@tpope.net> Date: Thu Dec 28 13:03:39 2023 -0500 runtime(cucumber): Updates to indent and syntax
author Christian Brabandt <cb@256bit.org>
date Thu, 28 Dec 2023 23:30:08 +0100
parents 63b0b7b79b25
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2098
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
1 " Vim indent file
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
2 " Language: Cucumber
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
3 " Maintainer: Tim Pope <vimNOSPAM@tpope.org>
34042
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
4 " Last Change: 2023 Dec 28
2098
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
5
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
6 if exists("b:did_indent")
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
7 finish
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
8 endif
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
9 let b:did_indent = 1
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
10
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
11 setlocal autoindent
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
12 setlocal indentexpr=GetCucumberIndent()
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
13 setlocal indentkeys=o,O,*<Return>,<:>,0<Bar>,0#,=,!^F
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
14
4681
2eb30f341e8d Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents: 2202
diff changeset
15 let b:undo_indent = 'setl ai< inde< indk<'
2eb30f341e8d Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents: 2202
diff changeset
16
2098
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
17 " Only define the function once.
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
18 if exists("*GetCucumberIndent")
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
19 finish
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
20 endif
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
21
34042
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
22 let s:headings = {
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
23 \ 'Feature': 'feature',
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
24 \ 'Rule': 'rule',
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
25 \ 'Background': 'bg_or_scenario',
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
26 \ 'Scenario': 'bg_or_scenario',
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
27 \ 'ScenarioOutline': 'bg_or_scenario',
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
28 \ 'Examples': 'examples',
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
29 \ 'Scenarios': 'examples'}
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
30
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
31 function! s:Line(lnum) abort
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
32 if getline(a:lnum) =~# ':'
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
33 let group = matchstr(synIDattr(synID(a:lnum,1+indent(a:lnum), 1), 'name'), '^cucumber\zs.*')
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
34 if !has_key(s:headings, group)
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
35 let group = substitute(matchstr(getline(a:lnum), '^\s*\zs\%([^:]\+\)\ze:\S\@!'), '\s\+', '', 'g')
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
36 endif
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
37 else
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
38 let group = ''
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
39 endif
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
40 let char = matchstr(getline(a:lnum), '^\s*\zs[[:punct:]]')
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
41 return {
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
42 \ 'lnum': a:lnum,
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
43 \ 'indent': indent(a:lnum),
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
44 \ 'heading': get(s:headings, group, ''),
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
45 \ 'tag': char ==# '@',
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
46 \ 'table': char ==# '|',
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
47 \ 'comment': char ==# '#',
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
48 \ }
2098
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
49 endfunction
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
50
34042
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
51 function! GetCucumberIndent(...) abort
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
52 let lnum = a:0 ? a:1 : v:lnum
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
53 let sw = shiftwidth()
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
54 let prev = s:Line(prevnonblank(lnum-1))
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
55 let curr = s:Line(lnum)
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
56 let next = s:Line(nextnonblank(lnum+1))
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
57 if curr.heading ==# 'feature'
4681
2eb30f341e8d Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents: 2202
diff changeset
58 " feature heading
2098
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
59 return 0
34042
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
60 elseif curr.heading ==# 'examples'
4681
2eb30f341e8d Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents: 2202
diff changeset
61 " examples heading
10048
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4681
diff changeset
62 return 2 * sw
34042
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
63 elseif curr.heading ==# 'bg_or_scenario'
4681
2eb30f341e8d Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents: 2202
diff changeset
64 " background, scenario or outline heading
10048
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4681
diff changeset
65 return sw
34042
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
66 elseif prev.heading ==# 'feature'
4681
2eb30f341e8d Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents: 2202
diff changeset
67 " line after feature heading
10048
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4681
diff changeset
68 return sw
34042
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
69 elseif prev.heading ==# 'examples'
4681
2eb30f341e8d Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents: 2202
diff changeset
70 " line after examples heading
10048
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4681
diff changeset
71 return 3 * sw
34042
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
72 elseif prev.heading ==# 'bg_or_scenario'
4681
2eb30f341e8d Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents: 2202
diff changeset
73 " line after background, scenario or outline heading
10048
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4681
diff changeset
74 return 2 * sw
34042
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
75 elseif (curr.tag || curr.comment) && (next.heading ==# 'feature' || prev.indent <= 0)
4681
2eb30f341e8d Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents: 2202
diff changeset
76 " tag or comment before a feature heading
2098
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
77 return 0
34042
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
78 elseif curr.tag
4681
2eb30f341e8d Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents: 2202
diff changeset
79 " other tags
10048
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4681
diff changeset
80 return sw
34042
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
81 elseif (curr.table || curr.comment) && prev.table
4681
2eb30f341e8d Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents: 2202
diff changeset
82 " mid-table
2eb30f341e8d Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents: 2202
diff changeset
83 " preserve indent
34042
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
84 return prev.indent
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
85 elseif curr.table && !prev.table
4681
2eb30f341e8d Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents: 2202
diff changeset
86 " first line of a table, relative indent
34042
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
87 return prev.indent + sw
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
88 elseif !curr.table && prev.table
4681
2eb30f341e8d Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents: 2202
diff changeset
89 " line after a table, relative unindent
34042
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
90 return prev.indent - sw
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
91 elseif curr.comment && getline(v:lnum-1) =~# '^\s*$' && next.heading ==# 'bg_or_scenario'
4681
2eb30f341e8d Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents: 2202
diff changeset
92 " comments on scenarios
10048
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4681
diff changeset
93 return sw
2098
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
94 endif
34042
9ece16460769 runtime(cucumber): Updates to indent and syntax
Christian Brabandt <cb@256bit.org>
parents: 11518
diff changeset
95 return prev.indent < 0 ? 0 : prev.indent
2098
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
96 endfunction
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
97
3259c3923c1e Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
diff changeset
98 " vim:set sts=2 sw=2: