electric-indent-mode
is a global mode, so if your function ever gets invoked, it will disable it everywhere.
You then also have the problem that if the global mode is enabled, new buffers which are never given a new major mode at all will have that behaviour, because the hook you're using never runs.
electric-indent-local-mode
is the equivalent buffer-local minor mode, so I think you should disable the global mode, and instead enable the local mode everywhere you want it, which you can do using much the same technique you've shown in your question.
(electric-indent-mode 0)
(add-hook 'after-change-major-mode-hook #'my-electric-indent-local-mode-maybe)
(defun my-electric-indent-local-mode-maybe ()
"Enable `electric-indent-local-mode' if appropriate."
(unless (eq major-mode 'fundamental-mode)
(electric-indent-local-mode 1)))
I'll add that the local mode turns out to be a hack of the global mode, such that as far as describe-mode
is concerned it's the global mode which is active or inactive on a per-buffer basis. This is pretty confusing when testing :)
You could alternatively do this:
(defun my-electric-indent-rules (_char)
"Used with `electric-indent-functions'."
(when (eq major-mode 'fundamental-mode)
(setq electric-indent-inhibit t) ;; Prevent future attempts.
'no-indent)) ;; Deny the current attempt.
(add-hook 'electric-indent-functions #'my-electric-indent-rules)
I don't recommend it for your case though, because it's having to process things every time it might need to indent something, as opposed to configuring the behaviour once per buffer.
(Thanks to Andrew Swann for pointing out that we could make this latter approach more efficient in the fundamental-mode
case by also setting electric-indent-inhibit
.)