I recently upgraded from emacs 23 to emacs 24. Working with JavaScript using the default js-mode, I've noticed a minor but annoying difference between js-mode in emacs23 vs. emacs24. To make sure it wasn't one of my settings I started emacs23 and emacs24 with the --no-init-file
option and I see the same problem, namely:
In emacs23 in js-mode, when you type a closing curly brace, }
, it temporarily jumps the cursor back to the match opening curly brace and then indents the closing brace to the appropriate level of indentation.
When I do it in emacs24, the temp cursor jump to the matching opening curly brace occurs as expected, but it does not indent the closing brace, making me hit the tab key to finish the job.
Is anyone else seeing this discrepancy? If so, any ideas on how to fix it? Is there is nice "indent-on-closing-curly" type of variable to set somewhere in my init.el?
I am using emacs on Xubuntu Linux (and I installed from source). I haven't compared 23 vs. 24 on other platforms yet.
Note: someone might want to suggest using Yegge's js2-mode instead, but I generally don't like using it and would like to get js-mode working right.
Since I've found a satisfactory answer and haven't heard from anyone else, I'll post my answer and accept it in case it helps anybody else.
I didn't find the exact reason why js-mode behaves differently in emacs 23 vs. emacs 24, but setting electric-indent-mode
in your .emacs or init.el gives the behavior I want. With this, it actually indents before you type the closing brace, but that works for me. This is a new setting in emacs 24. Your .emacs entry would be:
(electric-indent-mode t)
One problem I encountered is that org-mode doesn't like electric-indent-mode, so you can either specifically set electric-indent-mode for javascript/java/c/etc. modes or specifically unset it for org-mode. I chose the latter with this:
(defun my-org-mode-hooks ()
(electric-indent-mode -1))
(add-hook 'org-mode-hook 'my-org-mode-hooks)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With