runtime(csv): include a simple csv filetype and syntax plugin Commit: https://github.com/vim/vim/commit/1ce65e35ac6555054db1276e30d9d63421e6b346 Author: Maxim Kim <haba...@gmail.com> Date: Tue Jun 18 19:43:00 2024 +0200
runtime(csv): include a simple csv filetype and syntax plugin fixes: https://github.com/vim/vim/issues/15038 Signed-off-by: Maxim Kim <haba...@gmail.com> Signed-off-by: Christian Brabandt <c...@256bit.org> diff --git a/.github/MAINTAINERS b/.github/MAINTAINERS index ea8e560d0..5ebe93a58 100644 --- a/.github/MAINTAINERS +++ b/.github/MAINTAINERS @@ -119,6 +119,7 @@ runtime/ftplugin/clojure.vim @axvr runtime/ftplugin/cs.vim @nickspoons runtime/ftplugin/csh.vim @dkearns runtime/ftplugin/css.vim @dkearns +runtime/ftplugin/csv.vim @habamax runtime/ftplugin/cucumber.vim @tpope runtime/ftplugin/dart.vim @ribru17 runtime/ftplugin/deb822sources.vim @jamessan @@ -369,6 +370,7 @@ runtime/syntax/chatito.vim @ObserverOfTime runtime/syntax/chuck.vim @gacallea runtime/syntax/clojure.vim @axvr runtime/syntax/cs.vim @nickspoons +runtime/syntax/csv.vim @habamax runtime/syntax/cucumber.vim @tpope runtime/syntax/d.vim @JesseKPhillips runtime/syntax/dart.vim @pr3d4t0r diff --git a/runtime/ftplugin/csv.vim b/runtime/ftplugin/csv.vim new file mode 100644 index 000000000..f1021f83b --- /dev/null +++ b/runtime/ftplugin/csv.vim @@ -0,0 +1,23 @@ +vim9script + +# Maintainer: Maxim Kim <haba...@gmail.com> +# Last Update: 2024-06-18 + +if !exists("b:csv_delimiter") + # detect delimiter + var delimiters = ",; |" + + var max = 0 + for d in delimiters + var count = getline(1)->split(d)->len() + getline(2)->split(d)->len() + if count > max + max = count + b:csv_delimiter = d + endif + endfor +endif + +if exists("b:did_ftplugin") + finish +endif +b:did_ftplugin = 1 diff --git a/runtime/syntax/csv.vim b/runtime/syntax/csv.vim new file mode 100644 index 000000000..848029a48 --- /dev/null +++ b/runtime/syntax/csv.vim @@ -0,0 +1,39 @@ +vim9script + +# Maintainer: Maxim Kim <haba...@gmail.com> +# Last Update: 2024-06-18 + +if exists("b:current_syntax") + finish +endif + +var delimiter = get(b:, "csv_delimiter", ",") + +# generate bunch of following syntaxes: +# syntax match csvCol8 /.\{-}\(,\|$\)/ nextgroup=escCsvCol0,csvCol0 +# syntax region escCsvCol8 start=/ *"\([^"]*""\)*[^"]*/ end=/" *\(,\|$\)/ nextgroup=escCsvCol0,csvCol0 +for col in range(8, 0, -1) + var ncol = (col == 8 ? 0 : col + 1) + exe $'syntax match csvCol{col}' .. ' /.\{-}\(' .. delimiter .. '\|$\)/ nextgroup=escCsvCol' .. ncol .. ',csvCol' .. ncol + exe $'syntax region escCsvCol{col}' .. ' start=/ *"\([^"]*""\)*[^"]*/ end=/" *\(' .. delimiter .. '\|$\)/ nextgroup=escCsvCol' .. ncol .. ',csvCol' .. ncol +endfor + +hi def link csvCol1 Statement +hi def link csvCol2 Constant +hi def link csvCol3 Type +hi def link csvCol4 PreProc +hi def link csvCol5 Identifier +hi def link csvCol6 Special +hi def link csvCol7 String +hi def link csvCol8 Comment + +hi def link escCsvCol1 csvCol1 +hi def link escCsvCol2 csvCol2 +hi def link escCsvCol3 csvCol3 +hi def link escCsvCol4 csvCol4 +hi def link escCsvCol5 csvCol5 +hi def link escCsvCol6 csvCol6 +hi def link escCsvCol7 csvCol7 +hi def link escCsvCol8 csvCol8 + +b:current_syntax = "csv" -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_dev/E1sJd7k-003GpD-Ey%40256bit.org.