Mercurial > vim
annotate runtime/indent/css.vim @ 28333:04310f81143d v8.2.4692
patch 8.2.4692: no test for what 8.2.4691 fixes
Commit: https://github.com/vim/vim/commit/0f68e6c07aaf62c034a242f183b93c1bb44e7f93
Author: zeertzjq <zeertzjq@outlook.com>
Date: Tue Apr 5 13:17:01 2022 +0100
patch 8.2.4692: no test for what 8.2.4691 fixes
Problem: No test for what 8.2.4691 fixes.
Solution: Add a test. Use a more generic sotlution. (closes https://github.com/vim/vim/issues/10090)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 05 Apr 2022 14:30:03 +0200 |
parents | 9c221ad9634a |
children |
rev | line source |
---|---|
7 | 1 " Vim indent file |
25880 | 2 " Language: CSS |
3 " Maintainer: Doug Kearns <dougkearns@gmail.com> | |
4 " Previous Maintainer: Nikolai Weibull <now@bitwi.se> | |
5 " Last Change: 24 Sep 2021 | |
6 | |
7 " Use of shiftwidth() added by Oleg Zubchenko. | |
7 | 8 |
9 if exists("b:did_indent") | |
10 finish | |
11 endif | |
12 let b:did_indent = 1 | |
13 | |
14 setlocal indentexpr=GetCSSIndent() | |
375 | 15 setlocal indentkeys=0{,0},!^F,o,O |
1189 | 16 setlocal nosmartindent |
7 | 17 |
25880 | 18 let b:undo_indent = "setl inde< indk< si<" |
3557 | 19 |
7 | 20 if exists("*GetCSSIndent") |
21 finish | |
22 endif | |
3526
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2698
diff
changeset
|
23 let s:keepcpo= &cpo |
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2698
diff
changeset
|
24 set cpo&vim |
7 | 25 |
389 | 26 function s:prevnonblanknoncomment(lnum) |
27 let lnum = a:lnum | |
28 while lnum > 1 | |
29 let lnum = prevnonblank(lnum) | |
375 | 30 let line = getline(lnum) |
31 if line =~ '\*/' | |
389 | 32 while lnum > 1 && line !~ '/\*' |
1189 | 33 let lnum -= 1 |
375 | 34 endwhile |
389 | 35 if line =~ '^\s*/\*' |
1189 | 36 let lnum -= 1 |
389 | 37 else |
1189 | 38 break |
389 | 39 endif |
40 else | |
41 break | |
375 | 42 endif |
43 endwhile | |
44 return lnum | |
45 endfunction | |
46 | |
389 | 47 function s:count_braces(lnum, count_open) |
48 let n_open = 0 | |
49 let n_close = 0 | |
50 let line = getline(a:lnum) | |
51 let pattern = '[{}]' | |
52 let i = match(line, pattern) | |
53 while i != -1 | |
54 if synIDattr(synID(a:lnum, i + 1, 0), 'name') !~ 'css\%(Comment\|StringQ\{1,2}\)' | |
55 if line[i] == '{' | |
1189 | 56 let n_open += 1 |
389 | 57 elseif line[i] == '}' |
1189 | 58 if n_open > 0 |
59 let n_open -= 1 | |
60 else | |
61 let n_close += 1 | |
62 endif | |
389 | 63 endif |
64 endif | |
65 let i = match(line, pattern, i + 1) | |
66 endwhile | |
67 return a:count_open ? n_open : n_close | |
68 endfunction | |
69 | |
375 | 70 function GetCSSIndent() |
389 | 71 let line = getline(v:lnum) |
72 if line =~ '^\s*\*' | |
73 return cindent(v:lnum) | |
74 endif | |
75 | |
76 let pnum = s:prevnonblanknoncomment(v:lnum - 1) | |
77 if pnum == 0 | |
7 | 78 return 0 |
79 endif | |
80 | |
11062 | 81 return indent(pnum) + s:count_braces(pnum, 1) * shiftwidth() |
82 \ - s:count_braces(v:lnum, 0) * shiftwidth() | |
7 | 83 endfunction |
3526
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2698
diff
changeset
|
84 |
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2698
diff
changeset
|
85 let &cpo = s:keepcpo |
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2698
diff
changeset
|
86 unlet s:keepcpo |