electric-indent-mode does not provide an exclusion list where you could add
electric-indent-local-mode in major mode hooks instead of the global
The first "normal" approach is to switch the minor-mode actively on in all major-modes you want it to have: Call
electric-indent-local-mode in the hooks of the major modes where you want to switch it on:
(add-hook 'c-mode-hook #'electric-indent-local-mode)
c-mode-hook you can also use
prog-mode-hook to switch
electric-indent-mode on in almost all modes for programming languages.
The second version is to call
after-change-major-mode-hook if the major-mode is not in some exclusion list.
(defcustom my-electric-indent-exclusion-list '(txt-mode fundamental-mode)
"Major modes where `electric-indent-local-mode' is not switched on."
:type '(repeat symbol))
(defun my-switch-on-electric-indent ()
"Maybe switch on `electric-indent-local-mode'.
Do not activate electric indent if the major mode is
(unless (apply #'derived-mode-p my-electric-indent-exclusion-list)
(add-hook 'after-change-major-mode-hook #'my-switch-on-electric-indent)
As Drew indicated in his comment, if it was not for fundamental mode, there would be another simple method to disable
electric-indent-mode for specific major modes.
For most minor modes that have a global and a local version and where there is not an explicite exclusion list, it is possible to switch on the global version and switch it off with the local minor mode version in the major-modes hook.
This cannot be used for
fundamental-mode since there is no
I demonstrate it here for