Closed gsnedders closed 9 years ago
(This is using 20151015.1244 on MELPA.)
Are you using Emacs 25 snapshot? Then you'll need to customize js-switch-indent-offset
, like mentioned (or at least hinted at) in NEWS.
This goes against the documentation ("Otherwise [when not nil], all lines inside switch statement body are indented one additional level")
Could you mention the exact steps you took to read that documentation?
It's GNU Emacs 24.5.1 (x86_64-apple-darwin13.4.0, NS apple-appkit-1265.21), as packaged by homebrew—so no. The documentation quoted comes from the "customize js2-mode" menu item.
That works for me in 24.5. Does js2-indent-switch-body
actually evaluate to t
in the target buffer?
Try M-x describe-variable
or M-:
.
Hmm. Yes, it does. Now I restarted emacs, and it still evaluates to t
, yet now it works. o_O
And yet in another buffer it doesn't work. This is pretty weird. I wonder if it's just a bug in the indentation caused by something in that buffer?
What's the value of that variable in the other buffer?
t
.
OK, so let's try this:
describe-variable
js2-indent-switch-body
, ensure value t
describe-variable
js2-basic-offset
, ensure value 4
Trying to create a more minimal TC seems to be weirdly difficult. Cutting stuff down in the buffer while indent doesn't do it, killing the buffer, then reopening the file now cut down results in indent then working.
idlharness.js
puts the opening brace on a separate line, which we apparently didn't handle.
Should be fixed now, thanks
Just in case you're like me, and you were trying to figure out why js2-mode on Emacs 25 and up lines up case
with switch
, and how to change it: js2-indent-switch-body
is NOT the answer. :)
On Emacs 25, js2-mode uses the js-mode indentation. To have case
indented within switch
, and also the case contents further indented, add something like (setq js-switch-indent-offset 4)
to your js2-mode-hook
.
Testing with:
Set
js2-indent-switch-body
tot
. Go tocase 'true':
and press tab. Watch as it stays at column 0. This goes against the documentation ("Otherwise [when not nil], all lines inside switch statement body are indented one additional level"), as I would expect it to get indented byjs2-basic-offset
.