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

Overly aggressive indenting after recent Emacs update #377

Closed
giogadi opened this issue Nov 23, 2014 · 20 comments
Closed

Overly aggressive indenting after recent Emacs update #377

giogadi opened this issue Nov 23, 2014 · 20 comments

Comments

@giogadi
Copy link

giogadi commented Nov 23, 2014

Howdy,

I recently updated to the latest version of Emacs on Homebrew (using OSX Yosemite):

https://github.com/Homebrew/homebrew/blob/master/Library/Formula/emacs.rb

Suddenly, whenever I go to a new line using simple-indent-mode the editor always adds a 4-space indent, even in simple cases like:

foo :: Int
    foo = 1 -- auto-indent inserted here by haskell-mode

This behavior persisted even after completely nuking my emacs installation and starting over. Has anyone else experienced this issue?

@chrisdone
Copy link
Member

I imagine the abominable electric-indent-mode has something to do with this.

@chrisdone
Copy link
Member

Did you update to Emacs 24.4?

@giogadi
Copy link
Author

giogadi commented Nov 23, 2014

Yes, I'm in Emacs 24.4. Aaaaaaand you're right, disabling electric-indent-mode did the trick! Abominable is right.

@purcell
Copy link
Member

purcell commented Nov 23, 2014

In the latest haskell-mode code electric-indent-mode is suppressed, for exactly this reason. Which version do you have?

@giogadi
Copy link
Author

giogadi commented Nov 23, 2014

I got the version that's currently in marmalade. I guess I could switch to the melpa version, but easier thing is to just disable electric-indent, unless that's actually useful in other contexts?

@purcell
Copy link
Member

purcell commented Nov 23, 2014

That's extremely old (Jun 2013). You'd likely have to update your config for the newer versions to work.

electric-indent-mode is a global mode, so just (electric-indent-mode 0) at the top level to disable it completely. I personally find it helpful in major modes where the indentation is unambiguous.

If you want to disable it only in haskell-mode, then try this:

(add-hook 'haskell-mode-hook (lambda () (setq electric-indent-inhibit t)))

@giogadi
Copy link
Author

giogadi commented Nov 23, 2014

The melpa version of haskell-mode didn't appear to have the automatic suppression of electric-indent, so I followed the tip from @purcell. Quick thing, I had to change the hook you gave me to this for it to work:

(add-hook 'haskell-mode-hook (lambda () (electric-indent-local-mode -1)))

Thanks for the help!

@purcell
Copy link
Member

purcell commented Nov 23, 2014

It's possible that electric-indent-inhibit didn't make it into Emacs in time for the 24.4 freeze: looks like it was added on 7th Oct. I'll see if we can incorporate a more widely effective fix directly into haskell-mode.

purcell added a commit that referenced this issue Nov 23, 2014
@purcell
Copy link
Member

purcell commented Nov 23, 2014

I was mistaken: that var is in 24.4. And the MELPA version does correctly inhibit electric-indent-local-mode for me.

@gracjan
Copy link
Contributor

gracjan commented Jan 30, 2015

Note that electric-indent-inhibit works only on non-empty lines or when cursor in not in the first column. So electric-indent-inhibit does not really fix the 'newline-and-indent' aggresive behavior of haskell-simple-indent:

 (unless (and electric-indent-inhibit
        (not at-newline)
    (indent-according-to-mode))))))

@gracjan
Copy link
Contributor

gracjan commented Feb 27, 2015

@purcell: I still get 'newline-and-indent' despite your changes in 99658ce

@ivan-m
Copy link
Contributor

ivan-m commented Sep 13, 2015

I think we need to do something similar in haskell-cabal-mode as well, as electric-indent can do weird indentation there as well.

@sirlensalot
Copy link
Contributor

Given the bad support for electric-indent-inhibit noted in #377 (comment) I propose haskell-mode go for a full shutdown of electric indent a la #377 (comment)

@gracjan
Copy link
Contributor

gracjan commented Sep 13, 2015 via email

@sirlensalot
Copy link
Contributor

Honestly I'm a little surprised that the various indentations do not use electric, since that seems to work fine for c, java, perl etc. While on this topic, I wonder why haskell-mode doesn't leverage semantic to parse source files ... I worked pretty heavily on java emacs stuff in another life and semantic kinda rules. Whereas there's a lot of one-off parsing going on at least in haskell-indent.el ...

@gracjan
Copy link
Contributor

gracjan commented Sep 14, 2015

Electric seems to work best for languages with a unique, well defined indentation point derived from curly braces or parentheses. Haskell usually has multiple choices how a line should be indented with different semantics so a programmer needs to choose which semantics he wants.

What exactly does 'semantic' buy in this case? Honest question, I've never used it.

@purcell
Copy link
Member

purcell commented Sep 14, 2015

Semantic is pretty huge, and java-mode doesn't use it afaik -- I don't think it's really a building block for major modes. There are languages with more complicated syntax than haskell which Emacs managed to indent robustly. An example would be ruby-mode, which in its latest incarnation is built on the new smie indent engine thanks to the work of @dgutov. I'm not aware of an idiomatic way of building bounce-indent major modes, which I think is the key issue here.

@gracjan
Copy link
Contributor

gracjan commented Sep 14, 2015 via email

@sirlensalot
Copy link
Contributor

While java-mode doesn't use semantic, jdee does which is more like haskell-mode in that it offers completion, ant integration, maybe maven now too for all I know. Via semantic it's able to offer nice things like incremental parsing, completion in as-yet-uncompiled code, etc.

My experience back then (circa 2003) was semantic was very fast and has a great API for use within an IDE-like mode.

The problem is more that Haskell doesn't offer a BNF afaict. With a BNF you fire up Wisent and you're done! The comments in Lexer.x indicate it was produced from regexes, presumably in the Haskell report. Someone would probably have to handcode a Bison-style input for Wisent ...

... or follow the semantic docs in writing a regex-based tag generator, using the Haskell report. This could be OK too in that it would at least centralize parsing code in one place. Apparently this disables incremental parsing though.

references:
JDEE: https://github.com/jdee-emacs/jdee
Semantic docs: http://cedet.sourceforge.net/addlang.shtml
GHC Parser docs: https://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler/Parser
Haskell 2010 syntax: https://www.haskell.org/onlinereport/haskell2010/haskellch10.html
https://www.reddit.com/r/haskell/comments/2ig8ml/where_can_i_find_the_complete_bnf_syntax_of/
http://sourceforge.net/p/cedet/mailman/message/21667834/
http://stackoverflow.com/a/11511916/4015221

@gracjan
Copy link
Contributor

gracjan commented Oct 18, 2015

About agressive indenting.

One. electric-indent blacklist all haskell indentation modes:

(defvar electric-indent-functions-without-reindent
  '(indent-relative indent-to-left-margin indent-relative-maybe
    py-indent-line coffee-indent-line org-indent-line yaml-indent-line
    haskell-indentation-indent-line haskell-indent-cycle haskell-simple-indent
    yaml-indent-line))

Two. haskell-indentation-mode provides its own haskell-indentation-newline-and-indent function that is directly bound to RET and as if electric indent was always on.

Anyway this issue got offtopic, lets close it. If somebody experiences staricase problem again please report a new issue. Thanks.

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

No branches or pull requests

6 participants