A few days ago I decided to finally fix one of the issues I had with JavaScript indentation in Emacs (in the default js-mode
– I use js2-mode, which delegates indentation to js-mode
). When using const
to declare variables, and the declaration not fitting in one line, the indentation of the next line was broken like this:
const hello = 'world';
This is presumably fine when you have several declarations in a row and you want to line them up, but I never want that – what I want is
const hello = 'world';
that is, just one tab of indentation in the second line. It turns out there is no user option enabling this (and that’s why I didn’t bother to look for a solution for some time). Knowing that indentation-related code in Emacs can be rather hairy, I didn’t have the courage to look into the sources to find a solution – until last week. Finally, I decided to take a look. After about half an hour edebugging and looking around in js.el
, I found the js--declaration-keyword-re
variable, containing a regex matching one of the words var
, let
and const
. I kicked out the const
(IOW, I’ve put (setq js--declaration-keyword-re "\\<\\(let\\|var\\)\\>")
in my init.el
), and voilà – problem solved! (It may be the case that my change breaks something, and the two dashes mean that the user is not supposed to touch this variable, but frankly I don’t care about either. I will start to care when I encounter a problem with my solution, which is probably never going to happen. In any case I submitted a suggestion of making this variable a user option.)
CategoryEnglish, CategoryBlog, CategoryEmacs, CategoryJavaScript