chrisbra / csv.vim

A Filetype plugin for csv files
http://www.vim.org/scripts/script.php?script_id=2830
Vim License
1.27k stars 62 forks source link

Auto-detect comments #159

Closed bestouff closed 3 years ago

bestouff commented 4 years ago

Hi,

I have a CSV file like this:

# comment 1
# comment 2
col1;col2;col3
data1;data2;data3
data1;data2;data3

Would it be possible to have the comment somehow auto-detected ? Or at least a command to inform the plugin that # is a start-of-comment ?

chrisbra commented 4 years ago

How should the plugin detect comments automatically? It uses the &commentstring option currently to do so. I am not sure, what better ways it could use.

bestouff commented 4 years ago

I thought maybe if all lines that don't contain the column separator start with the same character, this is the start-of-comment ?

Anyway I tried :set commentstring="#%s" but that didn't seem to change anything - at least the syntax highlighting didn't change. So I wasn't sure if comments are handled by csv.vim.

chrisbra commented 4 years ago

Anyway I tried :set commentstring="#%s" but that didn't seem to change anything - at least the syntax highlighting didn't change. So I wasn't sure if comments are handled by csv.vim.

You need to re-init the plugin. Run CSVInit after changing the comment character.

bestouff commented 4 years ago

Well, this results in:

Error detected while processing function <SNR>249_CheckSaneSearchPattern:
line   37:
E684: list index out of range: 0

and then when pressing a cursor key:

Error detected while processing function csv#MoveCol[6]..csv#MaxColumns:
line   12:
E684: list index out of range: 0
E116: Invalid arguments for function escape(b:csv_cmt[0], '\\')
line   13:
E121: Undefined variable: pat
Error detected while processing function csv#MoveCol[9]..CSVWidth[21]..csv#CalculateColumnWidth[11]..csv#MaxColumns:
line   12:
E684: list index out of range: 0
E116: Invalid arguments for function escape(b:csv_cmt[0], '\\')
Error detected while processing function csv#MoveCol[9]..CSVWidth:
line   21:
E171: Missing :endif
Error detected while processing function csv#MoveCol:
line    9:
E171: Missing :endif
chrisbra commented 4 years ago

Hmm missing space I believe in the commentstring option. Will fix it tomorrow.

Am 09.03.2020 um 21:55 schrieb Xavier Bestel notifications@github.com:

 Well, this results in:

Error detected while processing function 249_CheckSaneSearchPattern: line 37: E684: list index out of range: 0 and then when pressing a cursor key:

Error detected while processing function csv#MoveCol[6]..csv#MaxColumns: line 12: E684: list index out of range: 0 E116: Invalid arguments for function escape(b:csv_cmt[0], '\') line 13: E121: Undefined variable: pat Error detected while processing function csv#MoveCol[9]..CSVWidth[21]..csv#CalculateColumnWidth[11]..csv#MaxColumns: line 12: E684: list index out of range: 0 E116: Invalid arguments for function escape(b:csv_cmt[0], '\') Error detected while processing function csv#MoveCol[9]..CSVWidth: line 21: E171: Missing :endif Error detected while processing function csv#MoveCol: line 9: E171: Missing :endif — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

chrisbra commented 4 years ago

:set commentstring="#%s"

That obviously needs to be :set commentstring=#%s, note the missing ", which Vim sees as comments and hence the errors in the csv#MaxColumns functions.

Error detected while processing function 249_CheckSaneSearchPattern: line 37: E684: list index out of range: 0

That looks wrong. Please show the output of the following commands:

 :redir => a |sil filetype | redir end
 :echo a

Also, what Vim version is this?

bestouff commented 4 years ago

filetype detection:ON plugin:ON indent:ON

I'm using spacevim with

VIM - Vi IMproved 8.1 (2018 May 18, compilé Mar 03 2020 16:41:00)
Rustines incluses : 1-2269
Modifié par team+vim@tracker.debian.org
Compilé par team+vim@tracker.debian.org
Énorme version sans interface graphique.
  Fonctionnalités incluses (+) ou non (-) :
+acl               -farsi             -mouse_sysmouse    -tag_any_white
+arabic            +file_in_path      +mouse_urxvt       -tcl
+autocmd           +find_in_path      +mouse_xterm       +termguicolors
+autochdir         +float             +multi_byte        +terminal
-autoservername    +folding           +multi_lang        +terminfo
-balloon_eval      -footer            -mzscheme          +termresponse
+balloon_eval_term +fork()            +netbeans_intg     +textobjects
-browse            +gettext           +num64             +textprop
++builtin_terms    -hangul_input      +packages          +timers
+byte_offset       +iconv             +path_extra        +title
+channel           +insert_expand     -perl              -toolbar
+cindent           +job               +persistent_undo   +user_commands
-clientserver      +jumplist          +postscript        +vartabs
-clipboard         +keymap            +printer           +vertsplit
+cmdline_compl     +lambda            +profile           +virtualedit
+cmdline_hist      +langmap           -python            +visual
+cmdline_info      +libcall           -python3           +visualextra
+comments          +linebreak         +quickfix          +viminfo
+conceal           +lispindent        +reltime           +vreplace
+cryptv            +listcmds          +rightleft         +wildignore
+cscope            +localmap          -ruby              +wildmenu
+cursorbind        -lua               +scrollbind        +windows
+cursorshape       +menu              +signs             +writebackup
+dialog_con        +mksession         +smartindent       -X11
+diff              +modify_fname      +sound             -xfontset
+digraphs          +mouse             +spell             -xim
-dnd               -mouseshape        +startuptime       -xpm
-ebcdic            +mouse_dec         +statusline        -xsmp
+emacs_tags        +mouse_gpm         -sun_workshop      -xterm_clipboard
+eval              -mouse_jsbterm     +syntax            -xterm_save
+ex_extra          +mouse_netterm     +tag_binary        
+extra_search      +mouse_sgr         -tag_old_static    
         fichier vimrc système : "$VIM/vimrc"
     fichier vimrc utilisateur : "$HOME/.vimrc"
 2me fichier vimrc utilisateur : "~/.vim/vimrc"
      fichier exrc utilisateur : "$HOME/.exrc"
 fichier de valeurs par défaut : "$VIMRUNTIME/defaults.vim"
               $VIM par défaut : "/usr/share/vim"
Compilation : gcc -c -I. -Iproto -DHAVE_CONFIG_H   -Wdate-time  -g -O2 -fdebug-prefix-map=/build/vim-LZqrFQ/vim-8.1.2269=. -fstack-protector-strong -Wformat -Werror=format-security -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1       
Édition de liens : gcc   -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -o vim        -lm -ltinfo -lnsl  -lselinux -lcanberra -lacl -lattr -lgpm -ldl