In my .emacs there is the following mode hooks:
(defun my-html-mode-hook ()
(interactive)
(setq tab-width 4
;; this will make sure TABs are used instead of spaces
indent-tabs-mode t)
)
(defun my-javascript-mode-hook ()
(interactive)
(setq tab-width 4
;; this will make sure TABs are used instead of spaces
indent-tabs-mode t)
)
(add-hook 'javascript-mode-hook 'my-javascript-mode-hook)
(add-hook 'html-mode-hook 'my-html-mode-hook)
Now when I am opening a .html, it works as expected, same for opening .js.
However, when opening .html and then switching to JavaScript by M-x javascript-mode by hand, my-javascript-mode-hook is not run (at least tab width switches to 8). How to make that hook run when I switch the mode manually?
There appears to be a dreaded ambiguity in naming, namely both
javascript-mode-hookandjs-mode-hookare recognized and run on startup when a JavaScript file is opened.However, when switching to JavaScript by hand, only
js-mode-hookis run. Bothjs-modeandjavascript-modemode triggerJavaScriptmode (at least they are displayed as(JavaScript)in the status line), so someone got tired of typing the "avacript" letters and kicked them out of "javascript" but forgot to clean up some mess...