Mercurial > vim
annotate runtime/indent/css.vim @ 33791:370543108ba1 v9.0.2114
patch 9.0.2114: overflow detection not accurate when adding digits
Commit: https://github.com/vim/vim/commit/22cbc8a4e17ce61aa460c451a26e1bff2c3d2af9
Author: Christian Brabandt <cb@256bit.org>
Date: Sun Nov 19 10:47:21 2023 +0100
patch 9.0.2114: overflow detection not accurate when adding digits
Problem: overflow detection not accurate when adding digits
Solution: Use a helper function
Use a helper function to better detect overflows before adding integer
digits to a long or an integer variable respectively. Signal the
overflow to the caller function.
closes: #13539
Signed-off-by: Christian Brabandt <cb@256bit.org>
Signed-off-by: Michael Henry <vim@drmikehenry.com>
Signed-off-by: Ernie Rael <errael@raelity.com>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 19 Nov 2023 11:00:07 +0100 |
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 |