electric-indent-mode is turnedd on by default since Emacs 24.4, according to C-u C-h n 24.4.
Fundamental mode is not an ordinary major mode, it's the default major mode for temporary buffers and Emacs creates lots of temporary buffers all the time, such as when you use minibuffer/echo area and make network requests. For example, right now I have 20 buffers ...
This is a partial answer to your question, as I could not yet figure out, how to run a hook on fundamental-mode only, but please read on.
With the following command, you can activate the Enter behaviour you like. Just run this command with M-x from the current buffer. (It enables this keybinding in all buffers with the same major-mode)
I see the need for this every day. The current behavior is really annoying, to the point of distracting me from the flow of writing code productively.
I have entered the previous code:
Entering a newline lines up the next line with the beginning of the print statement. To start a new definition, I ...
AFAICT what you're seeing is perfectly normal behavior. After
if x = 0
sml-mode doesn't know you're about to write then (because it doesn't pay attention to types or even distinguishes between variables and numbers), so it presumes you might be about to write an argument that you might pass to the function 0 [we know 0 can't be a function, but sml-mode ...
This is happening because the function electric-indent-post-self-insert-function calls (delete-horizontal-space t) at the end of the line. The only way around this that I see is to copy the code of that function to your dotfile, remove that line, and add/remove the hook post-self-insert-hook. This would be a lot of work, and will probably leave all your ...
If your major mode derives from python-mode, than you likely need to make it
(setq-local electric-indent-inhibit nil)
As for why it's non-nil: python-mode sets this vars to a non-nil value because electric-indent is usually undesirable when indentation is syntactically significant (as in Python).
I actually don't need/want most of the electricity. A solution which involves turning off electric-indent-mode but somehow activating the "add whitespace for new lines" feature would be fine with me.
This approach might be of interest:
In programming modes I invariably want RET to invoke indent-new-comment-line or its mode-specific analogue, which always ...