syl20bnr / spacemacs

A community-driven Emacs distribution - The best editor is neither Emacs nor Vim, it's Emacs *and* Vim!
http://spacemacs.org
GNU General Public License v3.0
23.57k stars 4.9k forks source link

Active parinfer indent mode should turn off smartparens #9491

Open gilch opened 6 years ago

gilch commented 6 years ago

I've tried using the new parinfer feature #5574 in combination with the existing SPC k lisp state features. I think it's nice to have both, but they don't cooperate very well sometimes.

Some of paredit's basic features naturally emerge from parinfer https://shaunlebron.github.io/parinfer/#paredit-emerges

But this doesn't work if smartparens is automatically inserting balanced pairs. You have to be able to insert a bracket individually so parinfer can infer the other one. It's really annoying to have to remember to turn smartparens back off all the time.

Perhaps exiting from lisp state could turn smartparens back off if it was off when lisp state was started. Or activating lisp state could switch parinfer to paren mode. Either way, activating parinfer's indent mode should always switch off smartparens.

Activating parinfer's indent mode must also turn off aggressive indent mode, or it's useless.

Likewise, activating aggressive indent mode must switch to parinfer's paren mode.

next-mad-hatter commented 5 years ago

Perhaps exiting from lisp state could turn smartparens back off if it was off when lisp state was started.

My attempt at this: https://github.com/syl20bnr/evil-lisp-state/pull/43 -- this way, activating parinfer and deactivating smartparens in user config should yield a workable lisp editing setup with both plugins available.

evil-lisp-state seemed the right place to fix it, altough it looks like it is not actively maintained. Feel free to test and/or review -- I have very little experience with emacs.

gilch commented 4 years ago

I didn't think this got fixed yet.

gilch commented 3 years ago

I still don't think this got fixed. There was a pull request for it, but it's still open.

lebensterben commented 3 years ago

I agree. I turn off smartparen manually when parinfer is in used.

gilch commented 2 years ago

Still not fixed, last I checked. I did come up with a workaround using a watcher though.

gilch commented 1 year ago

I've done the workaround on multiple configs now. It has been some variation of

(defun user/evil-state-watcher (symbol newval operation where)
  (when (and (not (eq newval 'lisp))
             (eq evil-state 'lisp))
    (smartparens-mode 0)))

and

  ;; In dotspacemacs/user-config
  (add-variable-watcher 'evil-state #'user/evil-state-watcher)
gilch commented 1 year ago

I noticed the "Reported upstream" label. Which upstream has this been reported to?

Spacemacs uses parinfer-rust-mode now, not DogLooksGood/parinfer-mode/. And I'm not sure that would be the right upstream either. The issue seems to be the SPC k lisp state altering the user's preferred minor mode set, and then not putting it back how it was upon state exit, which at least interferes with Parinfer, and could potentially affect others.

On the other hand, if "lisp state" is a pure Spacemacs thing, then the issue is here, not anywhere upstream. If lisp state does have an upstream, maybe it should be reported there, instead of to whatever parinfer package we happen to be using now.

lebensterben commented 1 year ago

it was reported 5 years ago to the now-deprecated parinfer-mode

https://github.com/DogLooksGood/parinfer-mode/issues/55

lebensterben commented 1 year ago

Closing this since the issue is no longer reproducible.

gilch commented 1 year ago

Closing which? I'm confused. This issue hasn't been closed. Also, I reproduced it just now after a package update (on the latest Spacemacs develop branch).

lebensterben commented 1 year ago

@gilch

Can you explain the steps to reproduce the issue?

gilch commented 1 year ago

Install latest develop Spacemacs and packages. Add and install parinfer layer.

Open a new elisp buffer (e.g. SPC f f foo.el). Enter the following code.

(print + 1 2 3)

Make sure smartparens is off (: (smartparens 0) will do it). The SP minor mode indicator should not be there and SPC h d m shouldn't list it either. Insert a ( character before the +. Parinfer should infer the trailing one:

(print (+ 1 2 3))

Delete the ( you just inserted. Parinfer should remove the trailing one as well:

(print + 1 2 3)

Now activate lisp state SPC k .. Exit lisp state Esc. Now try inserting it again.

(print ()+ 1 2 3)

Wrong answer. It should have worked like it did the first time.

Why? Smartparens automatically completed the pair before parinfer could infer the trailing one, so it ended up in the wrong spot. Smartparens is incompatible with parinfer-rust-mode's smart mode. They shouldn't be on at the same time. Even though we had it turned off, lisp state needs it, so lisp state turned it back on. That's maybe fine. The problem is that it left it on instead of putting it back how it was when we exited lisp state. So now we have to manually turn Smartparens back off in order to use parinfer, and I don't think it even has a keybinding anymore.

gilch commented 1 year ago

The other incompatible minor mode I noted in the OP is aggressive-indent mode SPC t I. This one is not quite as annoying, but it is also incompatible with parinfer's smart mode.

In a new elisp buffer, enter the following code:

(defun foo (a)
 b)

Insert spaces before the b until it passes column 11. Parinfer moves the trailing ).

(defun foo (a
            b))

Delete a few of the spaces you just inserted. Activate aggressive-indent mode SPC t I. You might have to make an edit before it kicks in. Try adding a newline below the form. The b snaps to its standard indentation.

(defun foo (a)
  b)

Now try inserting spaces before the b again, like we did before. Aggressive-indent mode doesn't allow it. We can no longer use Parinfer. We'd have to turn aggressive-indent mode off first.

But Parinfer has two modes. The default smart mode mostly infers trails from indents (but will add indents in certain cases to preserve parens). If you switch to the other one SPC t P, then it reverses the inference and infers indents from parentheses, the same thing aggressive-indent mode does, but Parinfer is a bit less strict about it. Instead of snapping to the exact standard indent, it will accept any indent the parens don't contradict. Activating aggressive-indent mode should have switched parinfer to paren mode. Switching Parinfer back to smart mode should turn off aggressive-indent mode.

I can see this one possibly making sense upstream.

lebensterben commented 1 year ago

please report it to the upstream here

https://github.com/justinbarclay/parinfer-rust-mode

github-actions[bot] commented 2 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!