You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Phenethylamine edited this page Mar 6, 2019
·
1 revision
Default behavior for indentation in Emacs for js-mode and js2-mode is abysmal with having the arguments to a curried function span multiple lines, so here's a quick fix for that you can add into your config.
(If you're better than Elisp than I am, feel free to improve on this code here, because I know it's not perfect!)
Basically, if 'js--chained-expression-p returns nil (it's the function that checks for dot-chaining, so I found it to be most similar and a good starting point), it'll call my lambda there, which goes:
If the first character of the line is a (, check if the last non-whitespace character of the previous line is a ). If so, tell the indention method to indent to the beginning of that () block.
This has some slightly incorrect behavior that's not too hard to see if you think about how it works, but it's miles better than the existing behavior and doesn't actually override any other behavior since it's using the advice feature.