Mercurial > vim
annotate runtime/indent/css.vim @ 13761:ddd0ad66922b
Added tag v8.0.1752 for changeset aef8ba129a4fe3b09dc83a8b3297a1c7b959248a
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 24 Apr 2018 14:00:08 +0200 |
parents | 1218c5353e2b |
children | 9c221ad9634a |
rev | line source |
---|---|
7 | 1 " Vim indent file |
389 | 2 " Language: CSS |
839 | 3 " Maintainer: Nikolai Weibull <now@bitwi.se> |
3557 | 4 " Latest Revision: 2012-05-30 |
11062 | 5 " Use of shiftwidth() added by Oleg Zubchenko. |
7 | 6 |
7 if exists("b:did_indent") | |
8 finish | |
9 endif | |
10 let b:did_indent = 1 | |
11 | |
12 setlocal indentexpr=GetCSSIndent() | |
375 | 13 setlocal indentkeys=0{,0},!^F,o,O |
1189 | 14 setlocal nosmartindent |
7 | 15 |
3557 | 16 let b:undo_indent = "setl smartindent< indentkeys< indentexpr<" |
17 | |
7 | 18 if exists("*GetCSSIndent") |
19 finish | |
20 endif | |
3526
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2698
diff
changeset
|
21 let s:keepcpo= &cpo |
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2698
diff
changeset
|
22 set cpo&vim |
7 | 23 |
389 | 24 function s:prevnonblanknoncomment(lnum) |
25 let lnum = a:lnum | |
26 while lnum > 1 | |
27 let lnum = prevnonblank(lnum) | |
375 | 28 let line = getline(lnum) |
29 if line =~ '\*/' | |
389 | 30 while lnum > 1 && line !~ '/\*' |
1189 | 31 let lnum -= 1 |
375 | 32 endwhile |
389 | 33 if line =~ '^\s*/\*' |
1189 | 34 let lnum -= 1 |
389 | 35 else |
1189 | 36 break |
389 | 37 endif |
38 else | |
39 break | |
375 | 40 endif |
41 endwhile | |
42 return lnum | |
43 endfunction | |
44 | |
389 | 45 function s:count_braces(lnum, count_open) |
46 let n_open = 0 | |
47 let n_close = 0 | |
48 let line = getline(a:lnum) | |
49 let pattern = '[{}]' | |
50 let i = match(line, pattern) | |
51 while i != -1 | |
52 if synIDattr(synID(a:lnum, i + 1, 0), 'name') !~ 'css\%(Comment\|StringQ\{1,2}\)' | |
53 if line[i] == '{' | |
1189 | 54 let n_open += 1 |
389 | 55 elseif line[i] == '}' |
1189 | 56 if n_open > 0 |
57 let n_open -= 1 | |
58 else | |
59 let n_close += 1 | |
60 endif | |
389 | 61 endif |
62 endif | |
63 let i = match(line, pattern, i + 1) | |
64 endwhile | |
65 return a:count_open ? n_open : n_close | |
66 endfunction | |
67 | |
375 | 68 function GetCSSIndent() |
389 | 69 let line = getline(v:lnum) |
70 if line =~ '^\s*\*' | |
71 return cindent(v:lnum) | |
72 endif | |
73 | |
74 let pnum = s:prevnonblanknoncomment(v:lnum - 1) | |
75 if pnum == 0 | |
7 | 76 return 0 |
77 endif | |
78 | |
11062 | 79 return indent(pnum) + s:count_braces(pnum, 1) * shiftwidth() |
80 \ - s:count_braces(v:lnum, 0) * shiftwidth() | |
7 | 81 endfunction |
3526
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2698
diff
changeset
|
82 |
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2698
diff
changeset
|
83 let &cpo = s:keepcpo |
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2698
diff
changeset
|
84 unlet s:keepcpo |