jcollard / elm-mode

Elm mode for emacs
GNU General Public License v3.0
375 stars 67 forks source link

Disable indenting current line on enter #20

Closed crodjer closed 9 years ago

crodjer commented 9 years ago

Say I am in this situation:

Action = Connect String
       | Send String
       | Receive String
       | Disconnect

update : Action -> Model -> Model -- cursor here

When I press enter, it indents the type definition according to the previous block:

Action = Connect String
       | Send String
       | Receive String
       | Disconnect

         update : Action -> Model -> Model
                            -- cursor here now.

I have noticed that the post line indentation is almost always wrong, so is there a way to disable it?

jcollard commented 9 years ago

I am unable to reproduce this. Which version of emacs are you using?

On my setup, if I press return in the example the cursor appears all the way at the left and the line with the update declaration remains unindented.

$ emacs --version
GNU Emacs 24.3.1
Copyright (C) 2013 Free Software Foundation, Inc.
GNU Emacs comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.
crodjer commented 9 years ago

Oh, strange. I use it for multiple other languages and indentations work okay in those. Anyway, I'll try and look into the elisp, maybe then I could come up with a better feedback. I have another question, there are two indentation modules, elm-indent-mode and elm-indentation-mode. I am using elm-indent-mode (the default one?), but there are issues with elm-indentation-mode as well. How's the behaviour of these to modes supposed to differ?

Here are my emacs version details:

GNU Emacs 24.5.1
Copyright (C) 2015 Free Software Foundation, Inc.
GNU Emacs comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.
crodjer commented 9 years ago

Okay, so I noticed that elm mode indentation is almost all exactly the same as haskell mode indentation. If I run s/Haskell/Elm/g and s/haskell/elm/g on haskell-indent.el, I get almost exactly the same result as elm-indent.el. Still, when I use haskell-indent-mode instead of elm-indent-mode, things are fine. This tells us that the issue comes in from somewhere outside. My best guess is elm-mode.el vs haskell-mode.el. Looking into this further.

jcollard commented 9 years ago

That is correct. Rather than writing an entire indent mode from scratch I did my best to copy haskell-mode indentation. It certainly isn't perfect and I'm not much of an elisp hacker. I appreciate the effort you're expending here.

crodjer commented 9 years ago

Makes sense, no need to re-invent the wheel. I am a big fan of Haskell mode (and ghc-mod), and after reading its code, even more so.

As far as the effort is concerned, always game for reading code better than I could myself write. That is the best way to learn. Moreover, having a well behaved editor adds an extra nudge at doing things in a particular programming language. So putting a couple of hours for this helps towards not having to scratch an itch every few minutes in future.

Anyway, I just figured out what was the reason behind this. Its emacs's electric indent mode. It is turned on by default in Emacs 24.4+, and mine being 24.5 has that. This user would have affected more people as they updated their editors.

In haskell-mode, electric indentation is disabled. Doing something similar in elm-mode, fixes the issues I was having. Will send across a PR for this in a few minutes.

Edit: Github markdown seem to break with emailed comments.

m4b commented 9 years ago

Wow. So I've been suffering in OCaml mode lately, with emacs 24.5, because every time I newline after a function it indents and does crazy things. Similarly for comments, and other silliness.

So I was reading this for some random reason, maybe cause I was hoping @jcollard would say something funny, and I realized that @crodjer 's problem sounded just what was happening to me; so I disabled electric-mode and all's right in the (OCaml emacs) world again.

Here is a :joy_cat: to express my appreciation.

crodjer commented 9 years ago

That's great! I wonder why should electric-mode be globally (and secretly) enabled though. Infact, this causes a tiny annoyance with Python as well (one instance in which python-mode can't correctly decide indentation). I used to just ignore that.

On Thu, May 28, 2015 at 8:43 PM, m4b notifications@github.com wrote:

Wow. So I've been suffering in OCaml mode lately, with emacs 24.5, because every time I newline after a function it indents and does crazy things. Similarly for comments, and other silliness.

So I was reading this for some random reason, maybe cause I was hoping @jcollard https://github.com/jcollard would say something funny, and I realized that @crodjer https://github.com/crodjer 's problem sounded just what was happening to me; so I disabled electric-mode and all's right in the (OCaml emacs) world again.

Here is a [image: :joy_cat:] to express my appreciation.

— Reply to this email directly or view it on GitHub https://github.com/jcollard/elm-mode/issues/20#issuecomment-106394467.

Thanks Rohan Jain

jcollard commented 9 years ago

Thanks for the fix @crodjer.