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