-
Notifications
You must be signed in to change notification settings - Fork 48
Hanging attributes #55
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 9 commits
4467c80
f17f6ba
a954d79
97fa57f
87c3197
e513ffb
d03754a
f2c0542
a6d16d4
34356ba
79bf5f4
85df17c
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 | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -79,16 +79,58 @@ function! GetHandlebarsIndent(...) | |||||||||||||||||||
| " all indent rules only apply if the block opening/closing | ||||||||||||||||||||
| " tag is on a separate line | ||||||||||||||||||||
|
|
||||||||||||||||||||
| " indent after block {{#block | ||||||||||||||||||||
| if prevLine =~# '\v\s*\{\{[#^].*\s*' | ||||||||||||||||||||
| " " check for a hanging attribute | ||||||||||||||||||||
| let lastLnumCol = col([lnum, '$']) - 1 | ||||||||||||||||||||
| if synIDattr(synID(lnum, lastLnumCol, 1), "name") =~ '^mustache' | ||||||||||||||||||||
| \ && prevLine !~# '}}\s*$' | ||||||||||||||||||||
| let hangingAttributePattern = '{{[#^]\=\%(\k\|[/-]\)\+\s\+\zs\k\+=' | ||||||||||||||||||||
| let standaloneComponentPattern = '^\s*{{\%(\k\|[/-]\)\+\s*$' | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if prevLine =~ hangingAttributePattern | ||||||||||||||||||||
| " {{component attribute=value | ||||||||||||||||||||
| " other=value}} | ||||||||||||||||||||
| let [line, col] = searchpos(hangingAttributePattern, 'Wbn', lnum) | ||||||||||||||||||||
| if line == lnum | ||||||||||||||||||||
| return col - 1 | ||||||||||||||||||||
| endif | ||||||||||||||||||||
| elseif prevLine =~ standaloneComponentPattern | ||||||||||||||||||||
| " {{component | ||||||||||||||||||||
| " attribute=value}} | ||||||||||||||||||||
| return indent(lnum) + sw | ||||||||||||||||||||
| endif | ||||||||||||||||||||
| endif | ||||||||||||||||||||
|
|
||||||||||||||||||||
| let componentClosingPattern = '\v^\s*\{\{\/\S*\}\}\s*' | ||||||||||||||||||||
|
jsit marked this conversation as resolved.
Outdated
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| " check for a closing }}, indent according to the opening one | ||||||||||||||||||||
|
Contributor
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. Is this part of hanging indent, too? Or is this a separate improvement? I just want to keep this PR as clean as possible.
Contributor
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. I see now that this is necessary for the hanging indent. However, it looks like it duplicates some other functionality. I notice that on this line: It's returning " indent after block: {{#block, {{^block
if prevLine =~# '\v\s*\{\{[#^].*\s*'
let ind = ind + sw
endifWould it be possible to restrict this section to just the "hanging indent"-related conditionals?
Contributor
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. This isn't the same case, though. The case that was already there applies on Basically, the one that maches {{#foo}}
[Cursor]
{{/foo}}While the new code works on this case: {{#foo one=two
three=four}}
[Cursor]
{{/foo}}The previous line in this case is not the block opener, it's the For a different explanation, consider the comments -- the existing code is The only way I can see to unify them is to extend the new code to handle the old code's case, because "find the opening part" is the more generic logic. But trying it out, I seem to be breaking the To be honest, I don't think it's worth the risk to try to combine the two cases, especially since it would make the one merged case more complicated and possibly trickier to change in the future. Let me know what you think and whether I've explained the difference between the cases well enough. |
||||||||||||||||||||
| let saved_pos = getpos('.') | ||||||||||||||||||||
| if prevLine =~# '}}$' && prevLine !~# '^\s*{{' && | ||||||||||||||||||||
| \ currentLine !~# componentClosingPattern && | ||||||||||||||||||||
| \ search('}}$', 'Wb') | ||||||||||||||||||||
| let [line, col] = searchpairpos('{{', '', '}}', 'Wb') | ||||||||||||||||||||
| if line > 0 | ||||||||||||||||||||
| if strpart(getline(line), col - 1, 3) =~ '{{[#^]' | ||||||||||||||||||||
| " then it's a block component, indent a shiftwidth more | ||||||||||||||||||||
| return indent(line) + sw | ||||||||||||||||||||
| else | ||||||||||||||||||||
| return indent(line) | ||||||||||||||||||||
| endif | ||||||||||||||||||||
|
Comment on lines
+112
to
+117
Contributor
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.
Suggested change
We could almost do this, see what I mean? the |
||||||||||||||||||||
| else | ||||||||||||||||||||
| call setpos('.', saved_pos) | ||||||||||||||||||||
| endif | ||||||||||||||||||||
| endif | ||||||||||||||||||||
|
|
||||||||||||||||||||
| " indent after block: {{#block, {{^block | ||||||||||||||||||||
| if prevLine =~# '\v\s*\{\{[#^].*\s*' && | ||||||||||||||||||||
| \ prevLine !~# '{{[#^]\(.\{}\)\s.\{}}}.*{{\/\1}}' | ||||||||||||||||||||
|
AndrewRadev marked this conversation as resolved.
Outdated
|
||||||||||||||||||||
| let ind = ind + sw | ||||||||||||||||||||
| endif | ||||||||||||||||||||
| " but not if the block ends on the same line | ||||||||||||||||||||
| if prevLine =~# '\v\s*\{\{\#(.+)(\s+|\}\}).*\{\{\/\1' | ||||||||||||||||||||
| if prevLine =~# '\v\s*\{\{[#^](.+)(\s+|\}\}).*\{\{\/\1' | ||||||||||||||||||||
| let ind = ind - sw | ||||||||||||||||||||
| endif | ||||||||||||||||||||
| " unindent after block close {{/block}} | ||||||||||||||||||||
| if currentLine =~# '\v^\s*\{\{\/\S*\}\}\s*' | ||||||||||||||||||||
| if currentLine =~# componentClosingPattern | ||||||||||||||||||||
| let ind = ind - sw | ||||||||||||||||||||
| endif | ||||||||||||||||||||
| " indent after component block {{a-component | ||||||||||||||||||||
|
|
@@ -105,7 +147,7 @@ function! GetHandlebarsIndent(...) | |||||||||||||||||||
| let closingLnum = search('}}\s*$', 'Wbc', lnum) | ||||||||||||||||||||
| let [openingLnum, col] = searchpairpos('{{', '', '}}', 'Wb') | ||||||||||||||||||||
| if openingLnum > 0 && closingLnum > 0 | ||||||||||||||||||||
| if strpart(getline(openingLnum), col - 1, 3) !~ '{{[#^]' | ||||||||||||||||||||
| if strpart(getline(openingLnum), col - 1, 3) !~# '{{[#^]' | ||||||||||||||||||||
| let ind = ind - sw | ||||||||||||||||||||
| endif | ||||||||||||||||||||
| else | ||||||||||||||||||||
|
|
||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.