nim-lang / nim-mode

An emacs major mode for the Nim programming language
139 stars 46 forks source link

Newline not indenting #153

Closed mrcnski closed 7 years ago

mrcnski commented 7 years ago

There seem to be at least two problems with nim-mode's configuration of electric-indent-mode. One of them is already described in issue #151. The other one, which I'm surprised hasn't been mentioned yet, is that newlines seem to ignore electric-indent-mode. The correct behavior should be that pressing <RET> automatically indents to the current indentation level. Instead, I have to either press <RET> + <TAB> or C-M-j every time. You can compare the behavior to python-mode where newlines are automatically indented.

I've observed this issue in both Emacs 24 and the newest snapshot (Emacs 26) and confirmed it's not caused by any of my personal configuration.

yuutayamada commented 7 years ago

It's on purpose regarding electric-indent-mode.

Here is electric-indent-inhibits description:

"If non-nil, reindentation is not appropriate for this buffer. This should be set by major modes such as `python-mode' since Python does not lend itself to fully automatic indentation."

I don't think current nim-mode's auto indent can handle nim's all situations.

mrcnski commented 7 years ago

Thanks for closing my issue for me. Would have been nice if we discussed this first, though.

What is the relevance of electric-indent-inhibit here? It is set to t in both nim-mode and python-mode, yet one can easily observe different newline indentation behavior between the two major modes.

If nim-mode's auto indent is insufficient as you claim, then why not fix it instead of hand-waving the issue away? It seems like you admitted that it is insufficient and that there is work to be done here. Not to mention that the grammar of Nim is pretty well-defined already so the fix should fall into place on its own.

Maybe it's just easier to close this issue and pretend it doesn't exist?

Is it really "on purpose" that we should be hitting RET + TAB every single time when I've never encountered this in any other major mode?

Let me know if you still need clarification. And don't close issues prematurely, please.

yuutayamada commented 7 years ago

Sorry, I misinterpreted that your "C-M-j" to "C-j".

Let's me clarify; it's on purpose to just insert a newline by hitting return key and C-j to "insert a newline and indent", which was Emacs' default way before electric-indent was introduced.

Are you sure that you need to hit "C-M-j"?

krux02 commented 7 years ago

well what works for me is this:

(global-set-key (kbd "RET") 'newline-and-indent)

I have no idea how ideomatic that solution is though. From the description of that function, it seems to be pretty much what you want in all major modes, that's why I put it to global.

mrcnski commented 7 years ago

@yuutayamada I understand that Emacs worked a bit differently once not too long ago, but nowadays every major mode I've used will auto-indent when hitting RET. I'm trying C-j but it does not work for me - it seems identical to RET in the modes I've tried (nim, python, haskell, and c++).

Yes, C-M-j seems to auto-indent despite being intended for comments (based on its name, indent-new-comment-line). But I already remapped RET to get the functionality I want for the time being (see below).

@krux02, you can also use this if you only want to affect nim-mode:

(define-key nim-mode-map (kbd "RET") #'newline-and-indent)

[Sorry, just saw your edit. Maybe the above will be useful for somebody though.]

yuutayamada commented 7 years ago

@m-cat seems like python.el has own electric-indent function, which calls python-indent-post-self-insert-function after every your input (and conceal default's electric-indent by using electric-indent-inhibit seemingly). I'm not sure I can apply that to nim-mode and I guess it may take awhile. (maybe you can make feature request in issue board, so I can consider it separately)

So, please for now, use your way. I think it's no harm if you just want to swap RET and C-j.