jonsmithers / vim-html-template-literals

Syntax highlighting for html template literals in javascript (as in lit-html and polymer 3)
MIT License
71 stars 10 forks source link

html.vim indention #5

Closed dman777 closed 6 years ago

dman777 commented 6 years ago

Here is othree's html.vim indention. This improves the current indention in where after foobar the cursor will land underneath the f in foobar:

   <div>
     foobar
   </div>

As of right now(before this PR code), after foobar the cursor will land way more to the left upon hitting enter.

I wasn't able to autoload the indent file and have it work. The html.vim indention code needs to be nested inside ComputeLitHtmlIndent function.

I am sure there is a cleaner/better way to do this. Please feel free to improve it.

jonsmithers commented 6 years ago

I appreciate the effort in this, but I think the downside to using purely indent/html.vim is that normal javascript indentation stops working correctly.

The html indent file is actually already autoloaded on line 13 (exe 'runtime! indent/html.vim'), so you could just do return HtmlIndent(). It seems to me the indentation issue you describe could be fixed by doing this:

     return l:result
   endif

-  let l:isJsx  = (IsSynstackInsideJsx(l:currLineSynstack))
-  if (l:wasCss || l:isCss || l:wasHtml || l:isHtml) && !l:isJsx
-    call VHTL_debug('html indent ' . l:adjustForClosingBracket)
-    return HtmlIndent() + l:adjustForClosingBracket
-  endif
-
-  if len(b:litHtmlOriginalIndentExpression)
-    call VHTL_debug('js indent ' . b:litHtmlOriginalIndentExpression)
-    return eval(b:litHtmlOriginalIndentExpression)
-  else
-    call VHTL_debug('cindent should never happen')
-    return cindent(v:lnum)
-  endif
+  call VHTL_debug('defaulting to html indent')
+  return HtmlIndent()
 endfu

I'm thinking I'll modify your changes to the above diff?

(b:litHtmlOriginalIndentExpression ultimately represents vim-javascript's indent function. After asserting that we're inside a lit-html region, it makes a lot more sense to default to html indentation than javascript indentation.)

dman777 commented 6 years ago

Ah... ok. I didn't even think about that! Thanks for catching.

I tried what you suggested which worked great for the html. But then it made the JS indention a little funky.

I decided that for the trade off, I will just deal with the HTML indention a little less better and keep the JS indention good. It's so minor...not a blocker and does not give a bad experience.

I am going to close this PR. From initial use, I think the state of this plugin is in excellent condition and production ready! Thank you so much for your hard work and making it possible to use VIM with lit html and Polymer 3!!!

I will spread the word around on Polymer slack about this plugin. People need to know about it!