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

Indent region breaks logic #195

Open
3 of 6 tasks
pacien opened this issue May 22, 2018 · 9 comments
Open
3 of 6 tasks

Indent region breaks logic #195

pacien opened this issue May 22, 2018 · 9 comments

Comments

@pacien
Copy link

pacien commented May 22, 2018

Conforming Bugs

Please tell us below:

  • basic information
    • OS name: DebianStretch
    • Versions: Emacs 24 with spacemacs, Nim compiler and nimsuggest 0.18.0
  • Are you using latest version of nim-mode? 0.4.2
  • Are there message related to nim-mode in *Messages* buffer? no
  • Did you read README.md? yes
  • Is your problem related to nimsuggest-mode? (company-mode, flycheck, or el-doc) no
    • Did you try nim-mode without nimsugggest-mode? What happened?
      (Comment out nimsuggest-mode's config please)

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
Copy link
Contributor

krux02 commented May 23, 2018

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
Copy link
Contributor

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

@krux02
Copy link
Contributor

krux02 commented Oct 10, 2018

@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
Copy link
Contributor

krux02 commented Oct 10, 2018

@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
Copy link
Contributor

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

@krux02
Copy link
Contributor

krux02 commented Oct 10, 2018

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

@yuutayamada
Copy link
Contributor

@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
Copy link
Contributor

krux02 commented Oct 10, 2018

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
Copy link
Contributor

maybe but it's off topic in this issue board

@krux02 krux02 added the critical label May 3, 2019
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