Skip to content

Commit c794f18

Browse files
committed
Update
1 parent 4f53883 commit c794f18

25 files changed

+344
-330
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ A collection of language packs for Vim.
77
> One to rule them all, one to find them, one to bring them all and in the darkness bind them.
88
99
- It **won't affect your startup time**, as scripts are loaded only on demand\*.
10-
- It **installs and updates 120+ times faster** than the <!--Package Count-->607<!--/Package Count--> packages it consists of.
10+
- It **installs and updates 120+ times faster** than the <!--Package Count-->606<!--/Package Count--> packages it consists of.
1111
- It is also more secure (scripts loaded for every filetype are generated by vim-polyglot)
1212
- Best syntax and indentation support (no other features). Hand-selected language packs.
1313
- Automatically detects indentation (includes performance-optimized version of [vim-sleuth](https://github.com/tpope/vim-sleuth), can be disabled)
@@ -96,7 +96,6 @@ On top of all language packs from [vim repository](https://github.com/vim/vim/tr
9696
- [haproxy](https://github.com/CH-DanReif/haproxy.vim) (HAProxy syntax highlighting)
9797
- [haskell](https://github.com/neovimhaskell/haskell-vim) (Haskell syntax highlighting for hs, hs-boot, hsc, bpk and hsig files)
9898
- [haxe](https://github.com/jdonaldson/vaxe) (Haxe and HXML syntax highlighting for hx, hxsl, hxml and hss files)
99-
- [hcl](https://github.com/b4b4r07/vim-hcl) (HCL syntax highlighting for hcl, nomad and workflow files)
10099
- [helm](https://github.com/towolf/vim-helm)
101100
- [help](https://github.com/neovim/neovim/tree/master/runtime)
102101
- [hive](https://github.com/zebradil/hive.vim) (HiveQL syntax highlighting for q, hql and ql files)
@@ -187,7 +186,7 @@ On top of all language packs from [vim repository](https://github.com/vim/vim/tr
187186
- [swift](https://github.com/keith/swift.vim) (Swift syntax highlighting for swift files)
188187
- [sxhkd](https://github.com/baskerville/vim-sxhkdrc) (Syntax highlighting for sxhkdrc files)
189188
- [systemd](https://github.com/wgwoods/vim-systemd-syntax) (Syntax highlighting for automount, dnssd, link, mount, netdev and 9 more files)
190-
- [terraform](https://github.com/hashivim/vim-terraform) (Syntax highlighting for tf and tfvars files)
189+
- [terraform](https://github.com/hashivim/vim-terraform) (HCL syntax highlighting for tf, tfvars, hcl, nomad and workflow files)
191190
- [textile](https://github.com/timcharper/textile.vim) (Textile syntax highlighting for textile files)
192191
- [thrift](https://github.com/solarnz/thrift.vim) (Thrift syntax highlighting for thrift files)
193192
- [tmux](https://github.com/ericpruitt/tmux.vim/tree/master/vim)

autoload/csv.vim

Lines changed: 75 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ endif
1414
" Some ideas are taken from the wiki http://vim.wikia.com/wiki/VimTip667
1515
" though, implementation differs.
1616

17-
let s:csv_numeric_sort = v:version > 704 || v:version == 704 && has("patch341")
17+
let s:csv_numeric_sort = v:version > 704 || v:version == 704 && has("patch951")
1818
if !s:csv_numeric_sort "{{{2
1919
fu! csv#CSVSortValues(i1, i2) "{{{3
2020
return (a:i1+0) == (a:i2+0) ? 0 : (a:i1+0) > (a:i2+0) ? 1 : -1
@@ -222,6 +222,15 @@ fu! csv#LocalSettings(type) "{{{3
222222
endif
223223
endfu
224224

225+
fu! csv#RemoveAutoHighlight() "{{{3
226+
exe "aug CSV_HI".bufnr('')
227+
exe "au! CursorMoved <buffer=".bufnr('').">"
228+
aug end
229+
exe "aug! CSV_HI".bufnr('')
230+
" Remove any existing highlighting
231+
HiColumn!
232+
endfu
233+
225234
fu! csv#DoAutoCommands() "{{{3
226235
" Highlight column, on which the cursor is
227236
if exists("g:csv_highlight_column") && g:csv_highlight_column =~? 'y'
@@ -233,12 +242,7 @@ fu! csv#DoAutoCommands() "{{{3
233242
" Set highlighting for column, on which the cursor is currently
234243
HiColumn
235244
else
236-
exe "aug CSV_HI".bufnr('')
237-
exe "au! CursorMoved <buffer=".bufnr('').">"
238-
aug end
239-
exe "aug! CSV_HI".bufnr('')
240-
" Remove any existing highlighting
241-
HiColumn!
245+
call csv#RemoveAutoHighlight()
242246
endif
243247
" undo autocommand:
244248
let b:undo_ftplugin .= '| exe "sil! au! CSV_HI'.bufnr('').' CursorMoved <buffer> "'
@@ -539,7 +543,7 @@ fu! csv#WColumn(...) "{{{3
539543
let temp=getpos('.')[2]
540544
let j=1
541545
let ret = 1
542-
for i in sort(b:csv_fixed_width_cols, s:csv_numeric_sort ? 'n' : 'csv#CSVSortValues')
546+
for i in sort(b:csv_fixed_width_cols, s:csv_numeric_sort ? 'N' : 'csv#CSVSortValues')
543547
if temp >= i
544548
let ret = j
545549
endif
@@ -549,6 +553,9 @@ fu! csv#WColumn(...) "{{{3
549553
call setpos('.',_cur)
550554
return ret
551555
endfu
556+
fu! csv#ValidComment() "{{{3
557+
return b:csv_cmt != ['', ''] && !empty(b:csv_cmt[0])
558+
endfu
552559
fu! csv#MaxColumns(...) "{{{3
553560
let this_col = exists("a:1")
554561
"return maximum number of columns in first 10 lines
@@ -561,8 +568,10 @@ fu! csv#MaxColumns(...) "{{{3
561568
endif
562569

563570
" Filter comments out
564-
let pat = '^\s*\V'. escape(b:csv_cmt[0], '\\')
565-
call filter(l, 'v:val !~ pat')
571+
if csv#ValidComment()
572+
let pat = '^\s*\V'. escape(b:csv_cmt[0], '\\')
573+
call filter(l, 'v:val !~ pat')
574+
endif
566575
if !empty(l) || this_col
567576
break
568577
else
@@ -606,8 +615,10 @@ fu! csv#ColWidth(colnr, row, silent) "{{{3
606615
endif
607616
endif
608617
let b:csv_list=getline(skipfirst+1,last)
609-
let pat = '^\s*\V'. escape(b:csv_cmt[0], '\\')
610-
call filter(b:csv_list, 'v:val !~ pat')
618+
if csv#ValidComment()
619+
let pat = '^\s*\V'. escape(b:csv_cmt[0], '\\')
620+
call filter(b:csv_list, 'v:val !~ pat')
621+
endif
611622
call filter(b:csv_list, '!empty(v:val)')
612623
call map(b:csv_list, 'split(v:val, b:col.''\zs'')')
613624
endif
@@ -898,7 +909,7 @@ fu! csv#Columnize(field) "{{{3
898909
return result
899910
else
900911
" right align
901-
return printf("%*S", width+1 , a:field)
912+
return printf("%*S", width , a:field)
902913
endif
903914
endfun
904915
fu! csv#GetColPat(colnr, zs_flag) "{{{3
@@ -912,15 +923,15 @@ fu! csv#GetColPat(colnr, zs_flag) "{{{3
912923
let pat='\%' . b:csv_fixed_width_cols[-1] . 'v.*'
913924
else
914925
let pat='\%' . b:csv_fixed_width_cols[(a:colnr - 1)] .
915-
\ 'c.\{-}\%' . b:csv_fixed_width_cols[a:colnr] . 'v'
926+
\ 'c.*\%<' . (b:csv_fixed_width_cols[a:colnr] + 1) . 'v'
916927
endif
917928
endif
918929
elseif !exists("b:csv_fixed_width_cols")
919930
let pat=b:col
920931
else
921-
let pat='\%' . b:csv_fixed_width_cols[0] . 'v.\{-}' .
932+
let pat='\%' . b:csv_fixed_width_cols[0] . 'v.*' .
922933
\ (len(b:csv_fixed_width_cols) > 1 ?
923-
\ '\%' . b:csv_fixed_width_cols[1] . 'v' :
934+
\ '\%<' . (b:csv_fixed_width_cols[1] + 1) . 'v' :
924935
\ '')
925936
endif
926937
return pat . (a:zs_flag ? '\zs' : '')
@@ -1115,7 +1126,12 @@ fu! csv#MoveCol(forward, line, ...) "{{{3
11151126
let pat=csv#GetColPat(1, 0)
11161127
else
11171128
" Move backwards
1118-
let pat=csv#GetColPat(maxcol, 0)
1129+
if cpos == 1 && (exists("a:1") && a:1)
1130+
" H move to previous line
1131+
let pat=csv#GetColPat(maxcol, 0)
1132+
else
1133+
let pat='\%1v'
1134+
endif
11191135
endif
11201136
endif
11211137
else
@@ -1149,9 +1165,13 @@ fu! csv#MoveCol(forward, line, ...) "{{{3
11491165
" of a field.
11501166
let epos = getpos('.')
11511167
if getline('.')[col('.')-1] == ' '
1152-
call search('\S', 'W', line('.'))
1153-
if getpos('.')[2] > spos
1154-
call setpos('.', epos)
1168+
if !exists("b:csv_fixed_width_cols")
1169+
call search('\S', 'W', line('.'))
1170+
if getpos('.')[2] > spos
1171+
call setpos('.', epos)
1172+
endif
1173+
elseif cpos > b:csv_fixed_width_cols[colnr]
1174+
call search('\%'. b:csv_fixed_width_cols[colnr]. 'v', 'W', line('.'))
11551175
endif
11561176
endif
11571177
endif
@@ -1246,8 +1266,10 @@ fu! csv#CopyCol(reg, col, cnt) "{{{3
12461266
endfor
12471267
endif
12481268
" Filter comments out
1249-
let pat = '^\s*\V'. escape(b:csv_cmt[0], '\\')
1250-
call filter(a, 'v:val !~ pat')
1269+
if csv#ValidComment()
1270+
let pat = '^\s*\V'. escape(b:csv_cmt[0], '\\')
1271+
call filter(a, 'v:val !~ pat')
1272+
endif
12511273

12521274
if !exists("b:csv_fixed_width_cols")
12531275
call map(a, 'split(v:val, ''^'' . b:col . ''\zs'')[col-1:cnt_cols]')
@@ -1288,10 +1310,9 @@ fu! csv#MoveColumn(start, stop, ...) range "{{{3
12881310
endif
12891311

12901312
" Swap line by line, instead of reading the whole range into memory
1291-
12921313
for i in range(a:start, a:stop)
12931314
let content = getline(i)
1294-
if content =~ '^\s*\V'. escape(b:csv_cmt[0], '\\')
1315+
if b:csv_cmt != ['',''] && content =~ '^\s*\V'. escape(b:csv_cmt[0], '\\')
12951316
" skip comments
12961317
continue
12971318
endif
@@ -1359,13 +1380,9 @@ fu! csv#DupColumn(start, stop, ...) range "{{{3
13591380
" skipping comment lines (we could do it with a single :s statement,
13601381
" but that would fail for the first and last column.
13611382

1362-
let commentpat = '\%(\%>'.(a:start-1).'l\V'.
1363-
\ escape(b:csv_cmt[0], '\\').'\m\)'. '\&\%(\%<'.
1364-
\ (a:stop+1). 'l\V'. escape(b:csv_cmt[0], '\\'). '\m\)'
1365-
13661383
for i in range(a:start, a:stop)
13671384
let content = getline(i)
1368-
if content =~ '^\s*\V'. escape(b:csv_cmt[0], '\\')
1385+
if csv#ValidComment() && content =~ '^\s*\V'. escape(b:csv_cmt[0], '\\')
13691386
" skip comments
13701387
continue
13711388
endif
@@ -1429,10 +1446,12 @@ fu! csv#AddColumn(start, stop, ...) range "{{{3
14291446
" skipping comment lines (we could do it with a single :s statement,
14301447
" but that would fail for the first and last column.
14311448

1432-
let commentpat = '\%(\%>'.(a:start-1).'l\V'.
1433-
\ escape(b:csv_cmt[0], '\\').'\m\)'. '\&\%(\%<'.
1434-
\ (a:stop+1). 'l\V'. escape(b:csv_cmt[0], '\\'). '\m\)'
1435-
if search(commentpat)
1449+
if b:csv_cmt != ['','']
1450+
let commentpat = '\%(\%>'.(a:start-1).'l\V'.
1451+
\ escape(b:csv_cmt[0], '\\').'\m\)'. '\&\%(\%<'.
1452+
\ (a:stop+1). 'l\V'. escape(b:csv_cmt[0], '\\'). '\m\)'
1453+
endif
1454+
if !empty(commentpat) && search(commentpat)
14361455
for i in range(a:start, a:stop)
14371456
let content = getline(i)
14381457
if content =~ '^\s*\V'. escape(b:csv_cmt[0], '\\')
@@ -1611,7 +1630,7 @@ fu! csv#MaxColumn(list) "{{{3
16111630
endtry
16121631
call add(result, str2float(nr))
16131632
endfor
1614-
let result = sort(result, s:csv_numeric_sort ? 'n' : 'csv#CSVSortValues')
1633+
let result = sort(result, s:csv_numeric_sort ? 'N' : 'csv#CSVSortValues')
16151634
let ind = len(result) > 9 ? 9 : len(result)
16161635
if has_key(get(s:, 'additional', {}), 'distinct') && s:additional['distinct']
16171636
if exists("*uniq")
@@ -1672,7 +1691,7 @@ fu! csv#DoForEachColumn(start, stop, bang) range "{{{3
16721691
endif
16731692
let t = g:csv_convert
16741693
let line = getline(item)
1675-
if line =~ '^\s*\V'. escape(b:csv_cmt[0], '\\')
1694+
if b:csv_cmt!=['',''] && line =~ '^\s*\V'. escape(b:csv_cmt[0], '\\')
16761695
" Filter comments out
16771696
call add(result, line)
16781697
continue
@@ -1736,7 +1755,7 @@ fu! csv#FoldValue(lnum, filter) "{{{3
17361755
for item in values(a:filter)
17371756
" always fold comments away
17381757
let content = getline(a:lnum)
1739-
if content =~ '^\s*\V'. escape(b:csv_cmt[0], '\\')
1758+
if b:csv_cmt != ['',''] && content =~ '^\s*\V'. escape(b:csv_cmt[0], '\\')
17401759
return 1
17411760
elseif eval('content' . (item.match ? '!~' : '=~') . 'item.pat')
17421761
let result += 1
@@ -1898,7 +1917,7 @@ fu! csv#GetColumn(line, col, strip) "{{{3
18981917
" Return Column content at a:line, a:col
18991918
let a=getline(a:line)
19001919
" Filter comments out
1901-
if a =~ '^\s*\V'. escape(b:csv_cmt[0], '\\')
1920+
if csv#ValidComment() && a =~ '^\s*\V'. escape(b:csv_cmt[0], '\\')
19021921
return ''
19031922
endif
19041923

@@ -1979,7 +1998,7 @@ fu! csv#AnalyzeColumn(...) "{{{3
19791998
let res[item]+=1
19801999
endfor
19812000

1982-
let max_items = reverse(sort(values(res), s:csv_numeric_sort ? 'n' : 'csv#CSVSortValues'))
2001+
let max_items = reverse(sort(values(res), s:csv_numeric_sort ? 'N' : 'csv#CSVSortValues'))
19832002
" What about the minimum 5 items?
19842003
let count_items = keys(res)
19852004
if len(max_items) > topn
@@ -2057,6 +2076,7 @@ fu! csv#InitCSVFixedWidth() "{{{3
20572076
endif
20582077
" Turn off syntax highlighting
20592078
syn clear
2079+
call csv#RemoveAutoHighlight()
20602080
let max_line = line('$') > 10 ? 10 : line('$')
20612081
let t = getline(1, max_line)
20622082
let max_len = max(map(t, 'len(split(v:val, ''\zs''))'))
@@ -2118,8 +2138,8 @@ fu! csv#InitCSVFixedWidth() "{{{3
21182138
endw
21192139
let b:csv_fixed_width_cols=[]
21202140
let tcc=0
2121-
let b:csv_fixed_width_cols = sort(keys(Dict), s:csv_numeric_sort ? 'n' : 'csv#CSVSortValues')
2122-
let b:csv_fixed_width = join(sort(keys(Dict), s:csv_numeric_sort ? 'n' : 'csv#CSVSortValues'), ',')
2141+
let b:csv_fixed_width_cols = sort(keys(Dict), s:csv_numeric_sort ? 'N' : 'csv#CSVSortValues')
2142+
let b:csv_fixed_width = join(sort(keys(Dict), s:csv_numeric_sort ? 'N' : 'csv#CSVSortValues'), ',')
21232143
call csv#Init(1, line('$'))
21242144

21252145
let &l:cc=_cc
@@ -2200,7 +2220,7 @@ fu! csv#CSVMappings() "{{{3
22002220
call csv#Map('nnoremap', '<C-Right>', ':<C-U>call csv#MoveCol(1, line("."))<CR>')
22012221
call csv#Map('nnoremap', 'L', ':<C-U>call csv#MoveCol(1, line("."))<CR>')
22022222
try
2203-
if g:csv_bind_B == 1
2223+
if get(g:, 'csv_bind_B', 0) == 1
22042224
call csv#Map('nnoremap', 'B', ':<C-U>call csv#MoveCol(-1, line("."))<CR>')
22052225
else
22062226
call csv#Map('nnoremap', 'E', ':<C-U>call csv#MoveCol(-1, line("."))<CR>')
@@ -2431,7 +2451,7 @@ fu! csv#NewDelimiter(newdelimiter, firstl, lastl) "{{{3
24312451
let line=a:firstl
24322452
while line <= a:lastl
24332453
" Don't change delimiter for comments
2434-
if getline(line) =~ '^\s*\V'. escape(b:csv_cmt[0], '\\')
2454+
if csv#ValidComment() && getline(line) =~ '^\s*\V'. escape(b:csv_cmt[0], '\\')
24352455
let line+=1
24362456
continue
24372457
endif
@@ -2476,7 +2496,7 @@ fu! csv#DuplicateRows(columnlist) "{{{3
24762496
let i = 1
24772497
let content = getline(line)
24782498
" Skip comments
2479-
if content =~ '^\s*\V'. escape(b:csv_cmt[0], '\\')
2499+
if csv#ValidComment() && content =~ '^\s*\V'. escape(b:csv_cmt[0], '\\')
24802500
continue
24812501
endif
24822502
let cols = split(content, b:col. '\zs')
@@ -2532,7 +2552,11 @@ fu! csv#Transpose(line1, line2) "{{{3
25322552
let TrailingDelim = getline(1) =~ b:delimiter.'$'
25332553
endif
25342554

2535-
let pat = '^\s*\V'. escape(b:csv_cmt[0], '\\')
2555+
if b:csv_cmt != ['','']
2556+
let pat = '^\s*\V'. escape(b:csv_cmt[0], '\\')
2557+
else
2558+
let pat = ''
2559+
endif
25362560

25372561
try
25382562
let columns = csv#MaxColumns(a:line1)
@@ -2544,7 +2568,7 @@ fu! csv#Transpose(line1, line2) "{{{3
25442568
let matrix = []
25452569
for line in range(a:line1, a:line2)
25462570
" Filter comments out
2547-
if getline(line) =~ pat
2571+
if !empty(pat) && getline(line) =~ pat
25482572
continue
25492573
endif
25502574
let r = []
@@ -3033,10 +3057,12 @@ fu! csv#SumCSVRow(line, nr) "{{{3
30333057
endif
30343058
let line=getline(ln)
30353059
" Filter comments out
3036-
let pat = '^\s*\V'. escape(b:csv_cmt[0], '\\')
3037-
if line =~ pat
3038-
call csv#Warn("Invalid count specified")
3039-
return
3060+
if csv#ValidComment()
3061+
let pat = '^\s*\V'. escape(b:csv_cmt[0], '\\')
3062+
if line =~ pat
3063+
call csv#Warn("Invalid count specified")
3064+
return
3065+
endif
30403066
endif
30413067
let func='csv#SumColumn'
30423068
let cells=split(line, b:col.'\zs')

0 commit comments

Comments
 (0)