nim-lang / nim-mode

An emacs major mode for the Nim programming language
138 stars 46 forks source link

Indent region breaks logic #195

Open pacien opened 6 years ago

pacien commented 6 years ago

Conforming Bugs

Please tell us below:

And describe your problem:


Original file: correctly indented manually

import unittest, json

suite "indent test":
  test "example":
    check (%* {
      "test": "test"
    }) != nil

    check (%* {
      "test": "test"
    }) != nil

    check (%* {
      "test": "test"
    }) != nil

After mark-whole-buffer and indent-region: indent is broken

import unittest, json

suite "indent test":
  test "example":
    check (%* {
      "test": "test"
    }) != nil

  check (%* {
    "test": "test"
  }) != nil

check (%* {
  "test": "test"
}) != nil
krux02 commented 6 years ago

Yes I can confirm this. It is even worse that this. Sometimes nim-indent-post-self-insert-function breaks the code after typing a ":". So I recommend to disable electric-indent-mode for Nim if you don't want nim-mode to break your code automatically during typing.

yuutayamada commented 5 years ago

you can set nim-smie-indent-dedenters to nil for your case

krux02 commented 5 years ago

@yuutayamada I think you miss the point. Electric indent should never ever break the logic in the code. When electric indentation isn't 100% sure of what it is doing it is better if it isn't doing anything at all.

krux02 commented 5 years ago

@pacien I have an open PR that rewrites the readme, this is how I would write it: https://github.com/nim-lang/nim-mode/blob/ea6fad3be9b16773f3769581992b1208d3b4342e/README.md

Maybe you get some valuable information from it.

yuutayamada commented 5 years ago

@krux02 I think he is mentioning indent-region. electric-indent is for manual indentation line by line.

krux02 commented 5 years ago

isn't electric indentation and indent-region besad on the exact same rules?

yuutayamada commented 5 years ago

@krux02 in pacien's example, it's clearly the problem comes from the variable I mentioned (I tested), not from electric indentation

If you are talking about nim-indent-post-self-insert-function for electric-indent-mode, it has condition below and I think it will be blocked due to (eq (char-before) last-command-event) because you gonna need to mark the region.

  (when (and electric-indent-mode
             (eq (char-before) last-command-event))
krux02 commented 5 years ago

It's a nightmare to learn all the pitfall of automatic code breaking indentation changes in electric-indent-mode. You save every Nim developer who wants to use emacs a lot of trouble and time if you just delete without substitution nim-indent-post-self-insert-function.

yuutayamada commented 5 years ago

maybe but it's off topic in this issue board