Look, I know it's wrong. I know I'm not supposed to do inline javascript. But I just want to put everything together! I want code to be easily accessible from the single place that it's relevant! That's important to me. Rest assured: Once my projects get large, I start pulling them apart. But in the mean time, the code I write (being generally game-related as it is) is extremely specific to the presentation, and I think it's actually inappropriate (not to mention inefficient, from my point of view) to separate them widely. There's just one problem:
Vim sucks at autoindenting.
Augh, this whole morning has been essentially wasted, because I spent it trying - trying my hardest - to find a vim indenting plugin that will indent javascript inline in HTML. It turns out that, as far as I can find, no such thing exists. There are a million wonderful javascript indenters, which work beautifully, but which only work on files that are javascript through-and-through. Unfortunately, my heart is set on keeping my javascript intertwined lovingly with my HTML, until such time as I feel like I should stop doing that.
So I had to fix it myself. The pain. It turns out vim scripting is, like the rest of this horrible death-train of an editor, obtuse, stuck in the past, and hard to work with. I guess I'll give thanks for the fact that I was able to edit it at all... But I feel like that's kind of a basic thing for an extensible editor. Anyway.
I got a copy of the HTML indent rules off of a Gary Bernhardt bitbucket link I found from my googling all morning, and delved into it. It turns out that the rules for indenting and dedenting on lines with bracket are only dependent on whether or not the lines in question contain open and close braces - and not how many of those there are. The practical effect of this: function () {};
is dedented the same way };
is. What?
It's not even hard to fix (and I have managed to) - all you need to do is count the braces and do some subtraction. For every brace closed on this line which isn't also opened on this line, dedent this line. For every brace opened on the previous line which isn't closed on the previous line, indent this line. That's it. As of this writing, my indent script has an unfortunate flaw - it'll treat } {
exactly the same as { }
. This is a pretty big problem, but I need to do some work today.