-
Notifications
You must be signed in to change notification settings - Fork 27
accept md and rmd files; refactor align, shrink, and calc_column_stats to work on address/visual range #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
6a58ed8
074b1fa
76963cc
c5c52c5
0b618d1
6fcc0c7
51cf551
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,8 @@ let s:magic_chars = '^*$.~/[]\' | |
|
|
||
| let s:named_syntax_map = {'csv': [',', 'quoted', ''], 'csv_semicolon': [';', 'quoted', ''], 'tsv': ["\t", 'simple', ''], 'csv_pipe': ['|', 'simple', ''], 'csv_whitespace': [" ", 'whitespace', ''], 'rfc_csv': [',', 'quoted_rfc', ''], 'rfc_semicolon': [';', 'quoted_rfc', '']} | ||
|
|
||
| let s:ft_exceptions_map = {'markdown':['|','simple',''], 'rmd':['|','simple','']} | ||
|
|
||
| let s:autodetection_delims = exists('g:rcsv_delimiters') ? g:rcsv_delimiters : ["\t", ",", ";", "|"] | ||
|
|
||
| let s:number_regex = '^[0-9]\+\(\.[0-9]\+\)\?$' | ||
|
|
@@ -762,12 +764,12 @@ func! rainbow_csv#adjust_column_stats(column_stats) | |
| endfunc | ||
|
|
||
|
|
||
| func! s:calc_column_stats(delim, policy, comment_prefix, progress_bucket_size) | ||
| func! s:calc_column_stats(delim, policy, comment_prefix, progress_bucket_size, first_line, last_line) | ||
| " Result `column_stats` is a list of (max_total_len, max_int_part_len, max_fractional_part_len) tuples. | ||
| let column_stats = [] | ||
| let lastLineNo = line("$") | ||
| let lastLineNo = a:last_line | ||
| let is_first_line = 1 | ||
| for linenum in range(1, lastLineNo) | ||
| for linenum in range(a:first_line, lastLineNo) | ||
| if (a:progress_bucket_size && linenum % a:progress_bucket_size == 0) | ||
| let s:align_progress_bar_position = s:align_progress_bar_position + 1 | ||
| call s:display_progress_bar(s:align_progress_bar_position) | ||
|
|
@@ -821,12 +823,25 @@ func! rainbow_csv#align_field(field, is_first_line, max_field_components_lens, i | |
| endfunc | ||
|
|
||
|
|
||
| func! rainbow_csv#csv_align() | ||
| func! rainbow_csv#csv_align(range_info) range | ||
| let first_line = a:firstline | ||
| let last_line = a:lastline | ||
| " The first (statistic) pass of the function takes about 40% of runtime, the second (actual align) pass around 60% of runtime. | ||
| " Numeric-aware logic by itself adds about 50% runtime compared to the basic string-based field width alignment | ||
| " If there are lot of numeric columns this can additionally increase runtime by another 50% or more. | ||
| let show_progress_bar = wordcount()['bytes'] > 200000 | ||
| let [delim, policy, comment_prefix] = rainbow_csv#get_current_dialect() | ||
| if ((policy == 'monocolumn') && (has_key(s:ft_exceptions_map, &ft))) | ||
| if (a:range_info == 0) | ||
| echoerr "RainbowAlign requires an address range in markdown and rmd files" | ||
| return | ||
| endif | ||
| let policy = 'simple' | ||
| let delim = '|' | ||
| let comment_prefix = '' | ||
| " no progress bar for markdown and rmd filetypes | ||
| let show_progress_bar = 0 | ||
| endif | ||
| if policy == 'monocolumn' | ||
| echoerr "RainbowAlign is available only for highlighted CSV files" | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of immediately returning you can adjust delim and policy to '|' and simple for markdown files - this would be the special case at Align level only. same for the shrink. You can also check here that range is provided instead of checking it below.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| return | ||
|
|
@@ -835,13 +850,13 @@ func! rainbow_csv#csv_align() | |
| echoerr 'RainbowAlign not available for "rfc_csv" filetypes, consider using "csv" instead' | ||
| return | ||
| endif | ||
| let lastLineNo = line("$") | ||
| let lastLineNo = last_line | ||
| let progress_bucket_size = (lastLineNo * 2) / s:progress_bar_size " multiply by 2 because we have two passes. | ||
| if !show_progress_bar || progress_bucket_size < 10 | ||
| let progress_bucket_size = 0 | ||
| endif | ||
| let s:align_progress_bar_position = 0 | ||
| let [column_stats, first_failed_line] = s:calc_column_stats(delim, policy, comment_prefix, progress_bucket_size) | ||
| let [column_stats, first_failed_line] = s:calc_column_stats(delim, policy, comment_prefix, progress_bucket_size,first_line,last_line) | ||
| if first_failed_line != 0 | ||
| echoerr 'Unable to allign: Inconsistent double quotes at line ' . first_failed_line | ||
| return | ||
|
|
@@ -853,7 +868,7 @@ func! rainbow_csv#csv_align() | |
| endif | ||
| let has_edit = 0 | ||
| let is_first_line = 1 | ||
| for linenum in range(1, lastLineNo) | ||
| for linenum in range(first_line, lastLineNo) | ||
| if (progress_bucket_size && linenum % progress_bucket_size == 0) | ||
| let s:align_progress_bar_position = s:align_progress_bar_position + 1 | ||
| call s:display_progress_bar(s:align_progress_bar_position) | ||
|
|
@@ -888,8 +903,20 @@ func! rainbow_csv#csv_align() | |
| endfunc | ||
|
|
||
|
|
||
| func! rainbow_csv#csv_shrink() | ||
| func! rainbow_csv#csv_shrink(range_info) range | ||
| let first_line = a:firstline | ||
| let last_line = a:lastline | ||
| let show_progress_bar = wordcount()['bytes'] > 200000 | ||
| let [delim, policy, comment_prefix] = rainbow_csv#get_current_dialect() | ||
| if ((policy == 'monocolumn') && (has_key(s:ft_exceptions_map, &ft))) | ||
| if (a:range_info == 0) | ||
| echoerr "RainbowShrink requires an address range in markdown and rmd files" | ||
| return | ||
| endif | ||
| let policy = 'simple' | ||
| let delim = '|' | ||
| let comment_prefix = '' | ||
| endif | ||
| if policy == 'monocolumn' | ||
| echoerr "RainbowShrink is available only for highlighted CSV files" | ||
| return | ||
|
|
@@ -898,15 +925,14 @@ func! rainbow_csv#csv_shrink() | |
| echoerr 'RainbowShrink not available for "rfc_csv" filetypes, consider using "csv" instead' | ||
| return | ||
| endif | ||
| let lastLineNo = line("$") | ||
| let lastLineNo = last_line | ||
| let has_edit = 0 | ||
| let show_progress_bar = wordcount()['bytes'] > 200000 | ||
| let progress_bucket_size = lastLineNo / s:progress_bar_size | ||
| if !show_progress_bar || progress_bucket_size < 10 | ||
| let progress_bucket_size = 0 | ||
| endif | ||
| let s:align_progress_bar_position = 0 | ||
| for linenum in range(1, lastLineNo) | ||
| for linenum in range(first_line, lastLineNo) | ||
| if (progress_bucket_size && linenum % progress_bucket_size == 0) | ||
| let s:align_progress_bar_position = s:align_progress_bar_position + 1 | ||
| call s:display_progress_bar(s:align_progress_bar_position) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert all whitespace-related changes, they are meaningful in markdown - removing them breaks the doc formatting when it is rendered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
everything else good to go. hunting down where, in my vim settings, I have trailing whitespaces getting trimmed automatically.
As I've never seen it before, what's the effect of trailing whitespaces on markdown documents ? or, what kind of rendering is being done that relies on the trailing whitespaces ?
As soon as I've addressed that, I will resubmit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two whitespaces at the end create a linebreak in GFM (Github-Flavored Markdown). There are multiple competing markdown dialects actually: https://en.wikipedia.org/wiki/Markdown but since this repo is hosted on github we should obviously follow the github spec.