Students who are trying to learn Nim complain that Emacs modes for Nim do not work flawlessly, and are huge. These students tried nimrod-mode and nim-mode. Here are a small sample of the problems that they encountered:
1 -- nimrod-mode does not highlight multiline comments.
2 -- nim-mode often fails in performing indentation. For instance, in the listing below, if I place the cursor in front of the for loop colon and press <Enter>, the part of the text that is after the colon goes to the beginning of the line:
proc fib(n: int): int =
var (r1, r2) = (1, 1)
for i in 2..n: (r1,r2) = (r1+r2, r1)
result= r1
The result of pressing <Enter> after the for-loop colon is shown below:
proc fib(n: int): int =
var (r1, r2) = (1, 1)
for i in 2..n:
(r1,r2) = (r1+r2, r1)
result= r1
Interesting enough, indentation works in the absence of parenthesis. In the following list, if I press <Enter> after the colon, nim-mode indents correctly.
proc fb(n: int): int =
if n<2: result=1
elif n<3:
result=n
else:
result= fb(n-3)+fb(n-2)+fb(n-2)
Here is the result:
proc fb(n: int): int =
if n<2:
result=1
elif n<3:
result=n
else:
result= fb(n-3)+fb(n-2)+fb(n-2)
By the way, python-mode performs the indentation without a flinch:
def fib(n):
(r1, r2) = (1, 1)
for i in range(1,n+1):(r1,r2) = (r1+r2, r1)
return r1
Here is the result of pressing <Enter> :
def fib(n):
(r1, r2) = (1, 1)
for i in range(1,n+1):
(r1,r2) = (r1+r2, r1)
return r1
Since the nim-mode program is huge, the students were not able to fix the bugs that they find now and then. Therefore, they switched to lem. If somebody publishes a small program that performs highlighting and indentation correctly in Emacs, it will be easy to make the transition from lem back to Emacs, since the two editors are very similar.
You're right that there's a couple of examples where the indentation of nim-mode is all over the place and this is one of them. I've been meaning to take a look at this too, but lack of time and not being that experienced with elisp means I haven't done so.
Something like this is another:
proc someProc(binWidth = 0.0,
breaks: seq[float] = @[],
binPosition = "none" # <- tab in this line will put it
# binPosition = "none", # <- here
): ReturnVal =
The reason in your specific case of course is the tuple unpacking. It seems the opening parens is confusing nim-mode. In my case it's the default @[] for the breaks. Remove that and it works.
As far as I'm aware @krux02 did most of the recent development on nim-mode. Also @kaushalmodi comes to mind as someone who could probably fix this easily.
Be that as it may, the fact remains that nim-mode is written in elisp. ;)
I don't even think these changes are hard at all, but I don't know my way around how to find the code responsible for those indentations without studying all of nim-mode first.