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

Insane SMIE indentation #179

Open
drvink opened this issue Apr 22, 2018 · 10 comments
Open

Insane SMIE indentation #179

drvink opened this issue Apr 22, 2018 · 10 comments

Comments

@drvink
Copy link
Contributor

drvink commented Apr 22, 2018

This has been driving me berserk ever since the change to the SMIE-based parser (I was using the old one because it didn't have this issue, but after it was removed, I didn't feel like maintaining yet another personal fork of some mode):

wtf-tuareg

Why does tuareg insist on typing on the wrong side of the road? sml-mode is similarly broken (in fact I can't think of a mode that hasn't gotten worse after adopting SMIE). I'm using Emacs 25.3 and tuareg-mode 20180325.47.

@Chris00
Copy link
Member

Chris00 commented Apr 22, 2018

This is just because it “thinks” you will continue the previous expression. For example, in your second case:

let x = 1
        + 1

@drvink
Copy link
Contributor Author

drvink commented Apr 22, 2018

That is a technically accurate interpretation, but I don't know a single indentation-aware Emacs major mode--any editor, actually--that behaves this way. The default "smart" indentation behavior that is typical is:

(* when the user hits return/enter... *)
match cursor_state with
| Block_starting -> indent ()
| Incomplete_expr -> maybe_indent () (* or just use previous indent *)
| Block_ending -> unindent ()
| _ -> ()

Post-SMIE Tuareg is actually even worse than this:

tuareg-busted

Here's what I'd expect, using F# and C as examples:

emacs-fsharp
emacs-c

@Chris00 Chris00 self-assigned this Apr 22, 2018
@rgrinberg
Copy link
Member

Here's another example where the indentation is quite strange:

let plus x y = x + y<CR>
             | <-- this is where the cursor ends up

I kind of understand that it's possible the continue the expression in this case, but really it would be quite unlikely.

One option to fix this would be to have tab toggle between the candidates.

Also, I would expect a subsequent newline would definitely reset the indentation level to the last line.

@Chris00
Copy link
Member

Chris00 commented Dec 6, 2019

It would indeed probably be better that, after a newline, the cursor be positioned at the level of the parent expression (until one type something so that SMIE can decide). @monnier Is a modification of SMIE required or can it be fixed in this repo at reasonable cost?

@monnier
Copy link
Contributor

monnier commented Dec 6, 2019 via email

@Chris00
Copy link
Member

Chris00 commented Dec 6, 2019

@monnier Thanks for the explanations. Modifying ((eq token 'empty-line-token) ";"))) works except at the end of file (where the token 'basic is given to the rules function). Not sure to understand the reason for the difference. Should I add a new function to 'smie-indent-functions to handle this case or is there an alternative?

@monnier
Copy link
Contributor

monnier commented Dec 6, 2019 via email

@Chris00
Copy link
Member

Chris00 commented Dec 8, 2019

Thanks—spot on. The only remaining problem is comments at the end of a buffer (or before end in module ... end). The rule function is also triggered with :elem, 'basic resulting in the same incorrect indentation.

@monnier
Copy link
Contributor

monnier commented Dec 8, 2019 via email

@Chris00
Copy link
Member

Chris00 commented Dec 8, 2019 via email

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

4 participants