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

Smart mode prevents deleting whitespace if parentheses would change #27

Open
andreyorst opened this issue Sep 4, 2020 · 4 comments
Open
Labels
enhancement New feature or request

Comments

@andreyorst
Copy link
Contributor

This is a minor inconvenience. Here's an example.

Imagine you've written the let block, and you've just finished writing the expression:

(let ((first-binfing (some-expression with args)|)))

(| represents the point)

Now you want to add second binding. You press enter, and Emacs sets the indentation for you:

image

Oops. You've forgot to escape the binding list, and Emacs thinks that you want to add another form to first binding list. So naturally you simply delete the whitespace with backspace:

image

Uh oh. Parinfer smart mode prevents me from escaping the block. Deleting with backspace doesn't work anymore.

Now I have to press left arrow or C-b:

image

And now you finally can type (:

image

Other parinfer implementations allow deleting and escaping current block. Im not sure if this is a Parinfer rust thing or in your Elisp code.

Again this is not a serious issue, but rather a minor inconvenience.

@justinbarclay
Copy link
Owner

Sorry for the delay, gmail decided to put my github notifications into spam 🤷‍♀️.

This is mostly linked to parinfer-rust because it can reposition the cursor. I also verified that this behavior is part of the parinfer spec. With this demo set to smart mode it exhibits the same behavior as you've described.

However, I have checked out atom-parinfer and it does follow the behavior you've described.

I think this could be a worthy enhancement

@justinbarclay justinbarclay added the enhancement New feature or request label Sep 13, 2020
@andreyorst
Copy link
Contributor Author

andreyorst commented Dec 6, 2020

I guess this function, when bound to "<backspace>" solves this just fine:

(defun backspace-or-delete-indentation ()
  (interactive)
  (let ((old (point))
        (new (save-excursion
               (back-to-indentation)
               (point))))
    (if (eq old new)
        (delete-indentation)
      (delete-backward-char 1))))

Do you think if your plugin should bind it by default?

EDIT: Ugh, after thinking a bit more, it will not allow to move blocks to top level, so

@justinbarclay
Copy link
Owner

Hmm from looking at other packages like parinfer for vscode, it seems they set an argument, force-balance, to true when calling into parinfer-rust. One that I never implemented when I was working on the interface for the rust plugin. This is something I plan to work on over my Christmas holiday.

Thanks for continuing to think about this problem and I am sorry I haven't been able to put more time into fixing it.

@andreyorst
Copy link
Contributor Author

Thanks for continuing to think about this problem and I am sorry I haven't been able to put more time into fixing it.

No worries! I'm currently not using Parinfer as of this moment, mostly because of eraserhd/parinfer-rust#92 -- at work it generates a lot of noise in merge requests or requires me to do a lot of cleanup before pushing, but I'm planning to come back when behavior would be more transparent or when I'll make sure that every project I work on is correctly formatted all the time :)

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

No branches or pull requests

2 participants