-
Notifications
You must be signed in to change notification settings - Fork 22
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
accept md and rmd files; refactor align, shrink, and calc_column_stats to work on address/visual range #52
base: master
Are you sure you want to change the base?
Conversation
…csv_align to use either address or visual range
…tance as well as requirements for ranges when using align and shrink functions in those filetypes
addresses #51 |
Awesome! Thank you! Looking at it |
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.
Thank you for sending this PR!
There are some adjustments that have to be made before I can merge it.
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.
README.md
Outdated
|csv_pipe || (pipe) | | | | ||
|rfc_csv |, (comma) | |Same as "csv" but allows multiline fields | | ||
|rfc_semicolon |; (semicolon) | |Same as "csv_semicolon" but allows multiline fields | | ||
|markdown || (pipe) |.md |align and shrink functions only operate on ranges | |
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.
I don't think we should add markdown filetypes to this list since they are being handled in a special way only for the purpose of the Align/Shrink procedures. Instead, you can write more about this special case in the docs for Align and Shrink commands. This is because the main feature of the extension is highlighting and users could wrongly assume that Rainbow CSV somehow adjusts markdown highlighting too.
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.
removed
README.md
Outdated
Align CSV columns with whitespaces. | ||
Don't run this command if you treat leading and trailing whitespaces in fields as part of the data. | ||
You can edit aligned CSV file in Vim column-edit mode (Ctrl+v). | ||
In markdown and r-markdown files, this function requires a range of addresses or a visual range selection. |
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.
I would extend this comment by adding that in markdown files the RainbowAlign command uses pipe separator by default and only works on ranges and/or visual range selection or something like this.
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.
updated
autoload/rainbow_csv.vim
Outdated
@@ -17,7 +17,7 @@ let s:system_python_interpreter = '' | |||
|
|||
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: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', ''], 'markdown':['|', 'simple', ''], 'rmd':['|', 'simple', '']} |
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 don't change this list since it can be used by other logic.
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
autoload/rainbow_csv.vim
Outdated
" 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 show_progress_bar = (l:lastline - l:firstline) > 200000 |
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, you replaced byte count with line count
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
" 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 show_progress_bar = (l:lastline - l:firstline) > 200000 | ||
let [delim, policy, comment_prefix] = rainbow_csv#get_current_dialect() | ||
if policy == 'monocolumn' | ||
echoerr "RainbowAlign is available only for highlighted CSV files" |
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.
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.
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
autoload/rainbow_csv.vim
Outdated
@@ -835,25 +834,35 @@ func! rainbow_csv#csv_align() | |||
echoerr 'RainbowAlign not available for "rfc_csv" filetypes, consider using "csv" instead' | |||
return | |||
endif | |||
let lastLineNo = line("$") | |||
|
|||
if (l:firstline == 1 && l:lastline == line("$") && (&ft == 'markdown' || &ft == 'rmd')) |
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 move this check higher, see my other comment.
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
autoload/rainbow_csv.vim
Outdated
|
||
func! rainbow_csv#csv_align() | ||
func! rainbow_csv#csv_align() range | ||
let l:firstline = a:firstline |
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 don't use l:
prefix for consistency with other code.
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.
updated
autoload/rainbow_csv.vim
Outdated
@@ -883,12 +892,13 @@ func! rainbow_csv#csv_align() | |||
let is_first_line = 0 | |||
endfor | |||
if !has_edit | |||
echoerr "File is already aligned" | |||
echoerr "Range is already aligned" |
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 keep the original comment since it is a more common use case, and seeing the range might be confusing.
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
autoload/rainbow_csv.vim
Outdated
endif | ||
endfunc | ||
|
||
|
||
func! rainbow_csv#csv_shrink() | ||
func! rainbow_csv#csv_shrink() range |
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.
All my comments regarding the align function also apply to Shrink function.
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.
moved the show_progress_bar setting to location similar to that found in _align, so that the exception processing block for md/rmd files could remain in a single location, as in _align.
…ce to README.md
…ce to autoload/.vim and doc/.txt
I believe that will handle the current set of comments. Let me know if there's more we can do. |
autoload/rainbow_csv.vim
Outdated
let is_first_line = 1 | ||
for linenum in range(1, lastLineNo) | ||
let lastLineNo = a:last_line | ||
let is_first_line = a:first_line |
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.
This is a boolean var that affects how numeric-only columns with a non-numeric header are aligned.
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.
sorry about that . complete miss on my part while converting to ranges
autoload/rainbow_csv.vim
Outdated
" 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 (&ft == 'markdown' || &ft == 'rmd') |
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.
This condition should only override "monocolumn" policy, otherwise get_current_dialect()
policy should have priority
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.
Actually, this might not be a big deal, I can fix it myself, later, so you can leave it as is if you want. "monocolumn" is just a fall back which means that no better dialect was found.
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.
after reading through the rest of the file, wondering if &ft is correct choice over &syntax. Input?
autoload/rainbow_csv.vim
Outdated
@@ -852,8 +865,8 @@ func! rainbow_csv#csv_align() | |||
return | |||
endif | |||
let has_edit = 0 | |||
let is_first_line = 1 | |||
for linenum in range(1, lastLineNo) | |||
let is_first_line = first_line |
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 fix, this is a boolean variable.
autoload/rainbow_csv.vim
Outdated
" 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 (&ft == 'markdown' || &ft == 'rmd') | ||
if (first_line == 1 && last_line == line("$")) |
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.
I think this check might be unreliable, please use this idiom instead: https://vi.stackexchange.com/questions/24793/how-to-check-whether-a-command-is-run-with-range-or-not
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.
Actually, it is fine to keep your implementation if you prefer, since this is just a warning which won't be able to produce a serious bug.
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.
+ is_last_line returned to treatment as bool + range-provided checks converted to use <range> + predicates exception for markdown/rmd files on current dialect = monocolumn for both shrink and align functions + adds maps of exception filetypes; used in both shink and align functions; other variations of markdown may be supported in future
Thank you for your adjustments! I will take it from here, would still need to test it and maybe make some additional changes. I currently have some other competing priorities but when I have some free time on my hands I will finalize the integration. Stay tuned! |
-range=%