Skip to content

Running indent-according-to-mode moves the cursor way to the right #488

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

Closed
EDmitry opened this issue Mar 2, 2015 · 16 comments
Closed

Running indent-according-to-mode moves the cursor way to the right #488

EDmitry opened this issue Mar 2, 2015 · 16 comments

Comments

@EDmitry
Copy link

EDmitry commented Mar 2, 2015

When using turn-on-haskell-indentation if I create two new lines after some haskell block of code and run indent-according-to-mode this will result in the indentation about 12 spaces to the right. This breaks a bunch of modes (like evil-mode) that move the cursor around and then call indent-according-to-mode to get the right indentation for that line. I suspect this is because of the functionality of tab to cycle through various indentation so executing the command results in cycling to the second tab position because when the cursor is in the beginning of the line that is the first tab position. Is there any workaround?

@gracjan
Copy link
Contributor

gracjan commented Mar 2, 2015

@EDmitry: there is a pending pull request that upgrades haskell-indentation #483. Can you check if the branch there fixes your problem?

@purcell
Copy link
Member

purcell commented Mar 2, 2015

@EDmitry This is exactly due to the cycling behaviour, and because the beginning of the line is simply the first of multiple possible indent levels. My guess is that it is impossible in this context to call indent-according-to-mode unconditionally and not get the behaviour you're seeing.

For my own part, I have disabled auto-indenting on newline: you can use C-j to newline-and-indent anyway.

Not sure what the evil way to do that would be.

@EDmitry
Copy link
Author

EDmitry commented Mar 2, 2015

Hmm, I can definitely change some evil bindings, but is there some haskell-mode API to be able to just say "please indent this to the first position you have without cycling over"? I could just make evil call that instead of indent-according-to-mode.

@purcell
Copy link
Member

purcell commented Mar 2, 2015

Not really. You'd presumably have the same issue in python-mode, which also has variable level indenting.

@EDmitry
Copy link
Author

EDmitry commented Mar 2, 2015

Does that mean that there is no way to indent to the first valid position when making a newline with RET ? It looks like it would only work if the first position is not the beginning of the line, so when cursor is in the beginning of the line it would naturally indent to the first position when indent method is called.

@purcell
Copy link
Member

purcell commented Mar 3, 2015

Does that mean that there is no way to indent to the first valid position when making a newline with RET ?

That's already what it's doing, but beginning-of-line is the first valid indent position most of the time. :-) So what you're asking is for something to know whether you want to move to the first or second syntactically-valid indentation point, and that can't be determined automatically.

It looks like it would only work if the first position is not the beginning of the line, so when cursor is in the beginning of the line it would naturally indent to the first position when indent method is called.

Right.

@gracjan
Copy link
Contributor

gracjan commented Mar 3, 2015

Still, this behavior makes only sense if the internal workings of emacs indentation are known. @EDmitry, you are not alone surprised by this. For example haskell-indentation defines haskell-newline-and-indent that is supposed to act more in line what you are trying to achieve by skipping usual indent-according-to-mode.

@EDmitry
Copy link
Author

EDmitry commented Mar 4, 2015

It actually looks like haskell-newline-and-indent is what I am looking for. I just wished it did this without moving the cursor. For example I have a shortcut for opening a new line above and I would want it to have the same behavior.

@gracjan
Copy link
Contributor

gracjan commented Mar 4, 2015

If completely disabling "indent after newline" is your goal then disable electric-indent or electric-local-indent.

Unless I misunderstand something opening line above without moving sounds like a basic emacs command that does not require anything haskell-mode related. Am I wrong?

@EDmitry
Copy link
Author

EDmitry commented Mar 4, 2015

I am talking about cases when there are several valid indentation positions for a given place in the code including the beginning of the line I want to ask haskell-mode to move the cursor (indent) to the most probable indentation level. Because if I just move the cursor to the beginning of the line and call indent-according-to-mode and the beginning of the line was the most probable position I will end up with a second valid indentation pisition, but not the one I would likely want. I want the cursor to stay in the beginning of the line if that is indeed the indentation level haskell-mode thinks most likely will be needed.

I am making an assumption that haskell-mode ranks indentation levels and chooses the best one and not just indents to the first valid one, but I might be wrong.

@gracjan
Copy link
Contributor

gracjan commented Mar 4, 2015

Neither haskell-simple-indent nor haskell-indent do anything like this.

@EDmitry
Copy link
Author

EDmitry commented Mar 9, 2015

Hm, then why doesn't it always move the cursor to the beginning of the line whenever it is a possible indentation level?

Say I have:

somefunc x = xs
             ^ here would be the cursor after the newline

The cursor will be right under x, although the beginning of the line is valid too. Indeed I can use <tab> to cycle to the beginning of the line as well. From this I made a conclusion that haskell-indentation ranked that stop under s higher than the beginning of the line. If that's not true, how does it work then?

@gracjan
Copy link
Contributor

gracjan commented Mar 9, 2015

With eletric-indent a TAB translates roughly to (progn (insert "\n") (indent-according-to-mode)) and in case of haskell-indentation it selects next indentation point. It is already on first good indentation point so will select the next good one.

Note also that haskell-indentation is quite buggy, I encourage you to check out branch wip/hi2. Actually we could use some help testing it out before we merge into master (it will replace haskell-indentation).

@EDmitry
Copy link
Author

EDmitry commented Mar 9, 2015

Checking out the new branch, thanks!

@gracjan
Copy link
Contributor

gracjan commented Mar 28, 2015

@EDmitry: branch wip/hi2 got merged in place of haskell-indentation. Is it working for you?

@gracjan
Copy link
Contributor

gracjan commented Oct 16, 2015

Reopen if you have additional information about this issue.

@gracjan gracjan closed this as completed Oct 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants