How can I fix javascript mode change in emacs 24?

I recently upgraded from emacs 23 to emacs 24. Using JavaScript using js-mode by default, I noticed a slight but annoying difference between js-mode in emacs23 and emacs24. To make sure this is not 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 entering a closing curly brace } it temporarily moves the cursor back into coincidence, opening curly braces, and then discards the closing figure to the appropriate level of indentation.

When I do this in emacs24, the temp cursor moves to the corresponding opening of the curly bracket, as expected, but does not indent the closing bracket, forcing me to press the tab key to finish the job.

Does anyone else see this discrepancy? If so, any ideas on how to fix this? Is there a nice variable like "indent-on-clos-curly" to set somewhere in my init.el?

I am using emacs on Xubuntu Linux (and I installed it from the source). I have not compared 23 to 24 on other platforms.

Note: someone might want to use Yegge js2-mode instead, but I usually don't like using it and would like js-mode to work correctly.

+6
source share
2 answers

Since I found a satisfactory answer and did not hear anything, I will send my answer and accept it if it helps someone else.

I have not found the exact reason js-mode behaves differently in emacs 23 versus emacs 24, but setting electric-indent-mode in your .emacs or init.el gives the behavior that I want. This is actually the indentation before entering the closing shape, but this works for me. This is a new setup in emacs 24. Your .emacs entry will be:

 (electric-indent-mode t) 

One of the problems I ran into is that org-mode does not like indented mode, so you can either set the electric-indent mode for javascript / java / c / etc. or specifically disable it for org-mode. I chose the last one:

 (defun my-org-mode-hooks () (electric-indent-mode -1)) (add-hook 'org-mode-hook 'my-org-mode-hooks) 
+10
source

Thank midpeter444 (electric-indent-mode t) works like a charm. I had googled and someone suggested setting js-auto-indent-flag to non-nil, it didn’t work on my Emacs 24.3, even there the js-auto-indent-flag variable can be set using "customize-group js', this has no effect. I found that java.el does not use it, although it is declared in the source.

0
source

Source: https://habr.com/ru/post/919714/


All Articles