Whenever I hit enter to get to the next line when writing a function for example emacs indents an addition tabs worth of space. I'll try to sketch out the problem:

fun pow(x : int, y : int) =  
----if y = 0  *hits RET*  
--------then 1  *hits RET*  
------------else x * pow(x,y-1)

In this scenario the dashes represent the indentation that is happening and I'm using enter to go to the new line. I'm totally new to emacs so I'm not sure if the issue has to do with a bug or user error? Could someone who is more experienced using emacs please point me the right direction, this behavior is driving me nuts!

Just to clarify a few things, I'm having this same issue on both my PC and Mac. When I say "hits RET" what I really mean is that I'm hitting the ENTER key. I'm assuming that I'm in SML mode because on the bottom line (I forget the technical name for it) it says (SML). I've also changed from FUNDAMENTAL mode to SML-Mode by typing M-x sml-mode. I'm using Emacs v26.1 and SML-Mode v6.9.

I wanted to also mention that I turned off electric-indent-mode and now here is the new behavior. I'll type if ..., hit RET, type then, hit RET, it goes to the right place. If on the other hand I just type if, hit RET, hit TAB, type then - the indentation goes haywire like it was previously. I'm wondering if I'm not hitting the right buttons in the right order or some other really silly beginner's mistake?


1 Answer 1


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 doesn't], so it indents to the place where this hypothetical argument would be written. If you ask it to (re)indent after typing the then the result should be correct, tho (with electric-indent-mode this happpens when you hit the next RET, but you can also force it at any time with TAB).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.