annotate runtime/indent/sdl.vim @ 16024:7fd3a9eaeedb v8.1.1017

patch 8.1.1017: off-by-one error in filetype detection commit https://github.com/vim/vim/commit/493fbe4abee660d30b4f2aef87b754b0a720213c Author: Bram Moolenaar <Bram@vim.org> Date: Sun Mar 17 17:16:12 2019 +0100 patch 8.1.1017: off-by-one error in filetype detection Problem: Off-by-one error in filetype detection. Solution: Also check the last line of the file.
author Bram Moolenaar <Bram@vim.org>
date Sun, 17 Mar 2019 17:30:14 +0100
parents 63b0b7b79b25
children 9c221ad9634a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 " Vim indent file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 " Language: SDL
3237
91e53bcb7946 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 7
diff changeset
3 " Maintainer: Michael Piefel <entwurf@piefel.de>
91e53bcb7946 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 7
diff changeset
4 " Last Change: 10 December 2011
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 " Shamelessly stolen from the Vim-Script indent file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 " Only load this indent file when no other was loaded.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 if exists("b:did_indent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 setlocal indentexpr=GetSDLIndent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 setlocal indentkeys+==~end,=~state,*<Return>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 " Only define the function once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 if exists("*GetSDLIndent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 " finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21
3237
91e53bcb7946 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 7
diff changeset
22 let s:cpo_save = &cpo
91e53bcb7946 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 7
diff changeset
23 set cpo&vim
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 function! GetSDLIndent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 " Find a non-blank line above the current line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 let lnum = prevnonblank(v:lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 " At the start of the file use zero indent.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 if lnum == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 let ind = indent(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 let virtuality = '^\s*\(\(virtual\|redefined\|finalized\)\s\+\)\=\s*'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 " Add a single space to comments which use asterisks
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 if getline(lnum) =~ '^\s*\*'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 let ind = ind - 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 if getline(v:lnum) =~ '^\s*\*'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 let ind = ind + 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 " Add a 'shiftwidth' after states, different blocks, decision (and alternatives), inputs
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 if (getline(lnum) =~? '^\s*\(start\|state\|system\|package\|connection\|channel\|alternative\|macro\|operator\|newtype\|select\|substructure\|decision\|generator\|refinement\|service\|method\|exceptionhandler\|asntype\|syntype\|value\|(.*):\|\(priority\s\+\)\=input\|provided\)'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 \ || getline(lnum) =~? virtuality . '\(process\|procedure\|block\|object\)')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 \ && getline(lnum) !~? 'end[[:alpha:]]\+;$'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 4186
diff changeset
49 let ind = ind + shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 " Subtract a 'shiftwidth' after states
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 if getline(lnum) =~? '^\s*\(stop\|return\>\|nextstate\)'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 4186
diff changeset
54 let ind = ind - shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 " Subtract a 'shiftwidth' on on end (uncompleted line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 if getline(v:lnum) =~? '^\s*end\>'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 4186
diff changeset
59 let ind = ind - shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 " Put each alternatives where the corresponding decision was
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 if getline(v:lnum) =~? '^\s*\((.*)\|else\):'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 normal k
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 let ind = indent(searchpair('^\s*decision', '', '^\s*enddecision', 'bW',
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "sdlString"'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 " Put each state where the preceding state was
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 if getline(v:lnum) =~? '^\s*state\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 let ind = indent(search('^\s*start', 'bW'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 " Systems and packages are always in column 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 if getline(v:lnum) =~? '^\s*\(\(end\)\=system\|\(end\)\=package\)'
4186
7ffc704cb7c1 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
76 return 0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 " Put each end* where the corresponding begin was
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 if getline(v:lnum) =~? '^\s*end[[:alpha:]]'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 normal k
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 let partner=matchstr(getline(v:lnum), '\(' . virtuality . 'end\)\@<=[[:alpha:]]\+')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 let ind = indent(searchpair(virtuality . partner, '', '^\s*end' . partner, 'bW',
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "sdlString"'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 return ind
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89
3237
91e53bcb7946 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 7
diff changeset
90 let &cpo = s:cpo_save
91e53bcb7946 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 7
diff changeset
91 unlet s:cpo_save
91e53bcb7946 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 7
diff changeset
92
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 " vim:sw=2