annotate runtime/indent/pov.vim @ 32238:b2cce50602ca v9.0.1450

patch 9.0.1450: MacOS: building fails if clock_gettime() is not available Commit: https://github.com/vim/vim/commit/08210f8def4886b0cd04dd4bbebed719f0512315 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Apr 13 19:15:54 2023 +0100 patch 9.0.1450: MacOS: building fails if clock_gettime() is not available Problem: MacOS: building fails if clock_gettime() is not available. Solution: Add a configure check for clock_gettime(). (closes https://github.com/vim/vim/issues/12242)
author Bram Moolenaar <Bram@vim.org>
date Thu, 13 Apr 2023 20:30:03 +0200
parents 4d76b3e07c07
children
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: PoV-Ray Scene Description Language
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 " Maintainer: David Necas (Yeti) <yeti@physics.muni.cz>
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 7
diff changeset
4 " Last Change: 2017 Jun 13
28620
4d76b3e07c07 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
5 " 2022 April: b:undo_indent added by Doug Kearns
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 " URI: http://trific.ath.cx/Ftp/vim/indent/pov.vim
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 " Some preliminary settings.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 setlocal nolisp " Make sure lisp indenting doesn't supersede us.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 setlocal indentexpr=GetPoVRayIndent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 setlocal indentkeys+==else,=end,0]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19
28620
4d76b3e07c07 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
20 let b:undo_indent = "setl inde< indk< lisp<"
4d76b3e07c07 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
21
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 " Only define the function once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 if exists("*GetPoVRayIndent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 " Counts matches of a regexp <rexp> in line number <line>.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 " Doesn't count matches inside strings and comments (as defined by current
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 " syntax).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 function! s:MatchCount(line, rexp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 let str = getline(a:line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 let i = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 let n = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 while i >= 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 let i = matchend(str, a:rexp, i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 if i >= 0 && synIDattr(synID(a:line, i, 0), "name") !~? "string\|comment"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 let n = n + 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 return n
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 " The main function. Returns indent amount.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 function GetPoVRayIndent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 " If we are inside a comment (may be nested in obscure ways), give up
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 if synIDattr(synID(v:lnum, indent(v:lnum)+1, 0), "name") =~? "string\|comment"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 return -1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49
25773
11b656e74444 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
50 " Search backwards for the first non-empty, non-comment line.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 let plnum = prevnonblank(v:lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 let plind = indent(plnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 while plnum > 0 && synIDattr(synID(plnum, plind+1, 0), "name") =~? "comment"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 let plnum = prevnonblank(plnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 let plind = indent(plnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 " Start indenting from zero
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 if plnum == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 " Analyse previous nonempty line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 let chg = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 let chg = chg + s:MatchCount(plnum, '[[{(]')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 let chg = chg + s:MatchCount(plnum, '#\s*\%(if\|ifdef\|ifndef\|switch\|while\|macro\|else\)\>')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 let chg = chg - s:MatchCount(plnum, '#\s*end\>')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 let chg = chg - s:MatchCount(plnum, '[]})]')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 " Dirty hack for people writing #if and #else on the same line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 let chg = chg - s:MatchCount(plnum, '#\s*\%(if\|ifdef\|ifndef\|switch\)\>.*#\s*else\>')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 " When chg > 0, then we opened groups and we should indent more, but when
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 " chg < 0, we closed groups and this already affected the previous line,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 " so we should not dedent. And when everything else fails, scream.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 let chg = chg > 0 ? chg : 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 " Analyse current line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 " FIXME: If we have to dedent, we should try to find the indentation of the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 " opening line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 let cur = s:MatchCount(v:lnum, '^\s*\%(#\s*\%(end\|else\)\>\|[]})]\)')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 if cur > 0
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 7
diff changeset
81 let final = plind + (chg - cur) * shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 else
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 7
diff changeset
83 let final = plind + chg * shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 return final < 0 ? 0 : final
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 endfunction