Mercurial > vim
annotate runtime/indent/cdl.vim @ 34215:8b0648002604 v9.1.0056
patch 9.1.0056: wrong number of trailing spaces inserted after blockwise put
Commit: https://github.com/vim/vim/commit/6638ec8afa9875ff565020536954c424d5f6f27d
Author: VanaIgr <vanaigranov@gmail.com>
Date: Thu Jan 25 21:50:41 2024 +0100
patch 9.1.0056: wrong number of trailing spaces inserted after blockwise put
Problem: Incorrect number of trailing spaces inserted for multibyte
characters when pasting a blockwise register in blockwise visual
mode (VanaIgr)
Solution: Skip over trailing UTF-8 bytes when computing the number of trailing
spaces (VanaIgr)
When pasting in blockwise visual mode, and the register type is <CTRL-V>, Vim
aligns the text after the replaced area by inserting spaces after pasted
lines that are shorter than the longest line. When a shorter line contains
multibyte characters, each trailing UTF-8 byte's width is counted in addition
to the width of the character itself. Each trailing byte counts as being 4
cells wide (since it would be displayed as <xx>).
closes: #13909
Signed-off-by: VanaIgr <vanaigranov@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 25 Jan 2024 22:15:02 +0100 |
parents | d6dde6229b36 |
children |
rev | line source |
---|---|
7 | 1 " Description: Comshare Dimension Definition Language (CDL) |
25880 | 2 " Maintainer: Raul Segura Acevedo <raulseguraaceved@netscape.net> (Invalid email address) |
3 " Doug Kearns <dougkearns@gmail.com> | |
28379 | 4 " Last Change: 2022 Apr 06 |
7 | 5 |
6 if exists("b:did_indent") | |
7 "finish | |
8 endif | |
9 let b:did_indent = 1 | |
10 | |
11 setlocal indentexpr=CdlGetIndent(v:lnum) | |
12 setlocal indentkeys& | |
13 setlocal indentkeys+==~else,=~endif,=~then,;,),= | |
14 | |
28379 | 15 let b:undo_indent = "setl inde< indk<" |
16 | |
7 | 17 " Only define the function once. |
18 if exists("*CdlGetIndent") | |
19 "finish | |
20 endif | |
21 | |
25773 | 22 " find out if an "...=..." expression is an assignment (or a conditional) |
23 " it scans 'line' first, and then the previous lines | |
33577
d6dde6229b36
runtime: Fix more typos (#13354)
Christian Brabandt <cb@256bit.org>
parents:
28379
diff
changeset
|
24 fun! CdlAssignment(lnum, line) |
7 | 25 let f = -1 |
26 let lnum = a:lnum | |
27 let line = a:line | |
28 while lnum > 0 && f == -1 | |
29 " line without members [a] of [b]:[c]... | |
30 let inicio = 0 | |
31 while 1 | |
32 " keywords that help to decide | |
33 let inicio = matchend(line, '\c\<\(expr\|\a*if\|and\|or\|not\|else\|then\|memberis\|\k\+of\)\>\|[<>;]', inicio) | |
34 if inicio < 0 | |
35 break | |
36 endif | |
37 " it's formula if there's a ';', 'elsE', 'theN', 'enDif' or 'expr' | |
38 " conditional if there's a '<', '>', 'elseif', 'if', 'and', 'or', 'not', | |
25773 | 39 " 'memberis', 'childrenof' and other \k\+of functions |
7 | 40 let f = line[inicio-1] =~? '[en;]' || strpart(line, inicio-4, 4) =~? 'ndif\|expr' |
41 endw | |
42 let lnum = prevnonblank(lnum-1) | |
43 let line = substitute(getline(lnum), '\c\(\[[^]]*]\(\s*of\s*\|:\)*\)\+', ' ', 'g') | |
44 endw | |
45 " if we hit the start of the file then f = -1, return 1 (formula) | |
46 return f != 0 | |
47 endf | |
48 | |
49 fun! CdlGetIndent(lnum) | |
50 let thisline = getline(a:lnum) | |
51 if match(thisline, '^\s*\(\k\+\|\[[^]]*]\)\s*\(,\|;\s*$\)') >= 0 | |
52 " it's an attributes line | |
11518 | 53 return shiftwidth() |
7 | 54 elseif match(thisline, '^\c\s*\([{}]\|\/[*/]\|dimension\|schedule\|group\|hierarchy\|class\)') >= 0 |
55 " it's a header or '{' or '}' or a comment | |
56 return 0 | |
57 end | |
58 | |
59 let lnum = prevnonblank(a:lnum-1) | |
60 " Hit the start of the file, use zero indent. | |
61 if lnum == 0 | |
62 return 0 | |
63 endif | |
64 | |
65 " PREVIOUS LINE | |
66 let ind = indent(lnum) | |
67 let line = getline(lnum) | |
24278 | 68 |
69 " Whether a '=' is a conditional or an assignment. -1 means we don't know | |
70 " yet. | |
71 " One 'closing' element at the beginning of the line has already reduced the | |
72 " indent, but 'else', 'elseif' & 'then' increment it for the next line. | |
73 " '=' at the beginning already has the right indent (increased for | |
74 " asignments). | |
75 let f = -1 | |
7 | 76 let inicio = matchend(line, '^\c\s*\(else\a*\|then\|endif\|/[*/]\|[);={]\)') |
77 if inicio > 0 | |
78 let c = line[inicio-1] | |
79 " ')' and '=' don't change indent and are useless to set 'f' | |
80 if c == '{' | |
11518 | 81 return shiftwidth() |
7 | 82 elseif c != ')' && c != '=' |
83 let f = 1 " all but 'elseif' are followed by a formula | |
84 if c ==? 'n' || c ==? 'e' " 'then', 'else' | |
11518 | 85 let ind = ind + shiftwidth() |
7 | 86 elseif strpart(line, inicio-6, 6) ==? 'elseif' " elseif, set f to conditional |
11518 | 87 let ind = ind + shiftwidth() |
7 | 88 let f = 0 |
89 end | |
90 end | |
91 end | |
92 | |
33577
d6dde6229b36
runtime: Fix more typos (#13354)
Christian Brabandt <cb@256bit.org>
parents:
28379
diff
changeset
|
93 " remove members [a] of [b]:[c]... (inicio remains valid) |
7 | 94 let line = substitute(line, '\c\(\[[^]]*]\(\s*of\s*\|:\)*\)\+', ' ', 'g') |
95 while 1 | |
96 " search for the next interesting element | |
97 let inicio=matchend(line, '\c\<if\|endif\|[()=;]', inicio) | |
98 if inicio < 0 | |
99 break | |
100 end | |
101 | |
102 let c = line[inicio-1] | |
103 " 'expr(...)' containing the formula | |
104 if strpart(line, inicio-5, 5) ==? 'expr(' | |
105 let ind = 0 | |
106 let f = 1 | |
107 elseif c == ')' || c== ';' || strpart(line, inicio-5, 5) ==? 'endif' | |
11518 | 108 let ind = ind - shiftwidth() |
7 | 109 elseif c == '(' || c ==? 'f' " '(' or 'if' |
11518 | 110 let ind = ind + shiftwidth() |
7 | 111 else " c == '=' |
25773 | 112 " if it is an assignment increase indent |
7 | 113 if f == -1 " we don't know yet, find out |
33577
d6dde6229b36
runtime: Fix more typos (#13354)
Christian Brabandt <cb@256bit.org>
parents:
28379
diff
changeset
|
114 let f = CdlAssignment(lnum, strpart(line, 0, inicio)) |
7 | 115 end |
116 if f == 1 " formula increase it | |
11518 | 117 let ind = ind + shiftwidth() |
7 | 118 end |
119 end | |
120 endw | |
121 | |
122 " CURRENT LINE, if it starts with a closing element, decrease indent | |
25773 | 123 " or if it starts with '=' (assignment), increase indent |
7 | 124 if match(thisline, '^\c\s*\(else\|then\|endif\|[);]\)') >= 0 |
11518 | 125 let ind = ind - shiftwidth() |
7 | 126 elseif match(thisline, '^\s*=') >= 0 |
25773 | 127 if f == -1 " we don't know yet if is an assignment, find out |
33577
d6dde6229b36
runtime: Fix more typos (#13354)
Christian Brabandt <cb@256bit.org>
parents:
28379
diff
changeset
|
128 let f = CdlAssignment(lnum, "") |
7 | 129 end |
130 if f == 1 " formula increase it | |
11518 | 131 let ind = ind + shiftwidth() |
7 | 132 end |
133 end | |
134 | |
135 return ind | |
136 endfun |