Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Newline not indenting #153

Closed
mrcnski opened this issue Mar 3, 2017 · 6 comments
Closed

Newline not indenting #153

mrcnski opened this issue Mar 3, 2017 · 6 comments
Labels

Comments

@mrcnski
Copy link

mrcnski commented Mar 3, 2017

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
Copy link
Contributor

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
Copy link
Author

mrcnski commented Mar 5, 2017

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
Copy link
Contributor

yuutayamada commented Mar 5, 2017

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"?

@yuutayamada yuutayamada reopened this Mar 5, 2017
@krux02
Copy link
Contributor

krux02 commented Mar 5, 2017

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
Copy link
Author

mrcnski commented Mar 5, 2017

@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
Copy link
Contributor

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants