Skip to content

Commit

Permalink
#17 - support customization of autodetection dialects
Browse files Browse the repository at this point in the history
  • Loading branch information
mechatroner committed Apr 15, 2019
1 parent 58d6b2f commit 15c40f8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ To adjust plugin configuration:
Enable content-based separator autodetection.
Files with ".csv" and ".tsv" extensions are always highlighted no matter what is the value of this option.

#### "rainbow_csv_autodetect_dialects"
List of CSV dialects to autodetect.
If "enable_rainbow_csv_autodetect" is set to false this setting is ignored

#### "rainbow_csv_max_file_size_bytes"
Disable Rainbow CSV for files bigger than the specified size. This can be helpful to prevent poor performance and crashes with very large files.
Manual separator selection will override this setting for the current file.
Expand Down
3 changes: 3 additions & 0 deletions RainbowCSV.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
// Files with ".csv" and ".tsv" extensions are always highlighted no matter what is the value of this option.
"enable_rainbow_csv_autodetect": true,

// List of CSV dialects to autodetect.
// If "enable_rainbow_csv_autodetect" is set to false this setting is ignored
"rainbow_csv_autodetect_dialects": [["\t", "simple"], [",", "quoted"], [";", "quoted"]],

// Auto adjust rainbow colors for Packages/User/RainbowCSV.sublime-color-scheme
// Rainbow CSV will auto-generate color theme with high-contrast colors to make CSV columns more distinguishable.
Expand Down
3 changes: 2 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,8 @@ def is_delimited_table(sampled_lines, delim, policy):

def autodetect_content_based(view):
sampled_lines = sample_lines(view)
autodetection_dialects = [('\t', 'simple'), (',', 'quoted'), (';', 'quoted')]
autodetection_dialects_default = [('\t', 'simple'), (',', 'quoted'), (';', 'quoted')]
autodetection_dialects = get_setting(view, 'rainbow_csv_autodetect_dialects', autodetection_dialects_default)
for delim, policy in autodetection_dialects:
if is_delimited_table(sampled_lines, delim, policy):
return (delim, policy)
Expand Down

0 comments on commit 15c40f8

Please sign in to comment.