Fuco1 / smartparens

Minor mode for Emacs that deals with parens pairs and tries to be smart about it.
GNU General Public License v3.0
1.82k stars 194 forks source link

completely disable auto-pairing functionality? #614

Open blaenk opened 8 years ago

blaenk commented 8 years ago

I realize this may sound crazy, but I love smartparens for its extensive sexp manipulation API. I've used it to create many custom transformation functions. I also like the default bindings that are created. However, as crazy as it may sound, I prefer to use electric-pair-mode rather than smartparen's pairing functionality.

I'm wondering what I must do, if it's even possible, to only use smartparens mode for its binds and API. That is, I want to enable smartparens mode, but I can't figure out how to stop it from doing any auto-pairing behavior which inevitably always has conflicts with electric-pair-mode.

So is it possible to enable smartparens mode without pairing behavior? If not, would you be open to and would you be kind enough to introduce this? At first I was expecting to disable some sort of smartparens-auto-pair-mode or something, then I thought perhaps I could set certain sp- variables to nil, but I can't nail it down.

I would really appreciate some input!

Fuco1 commented 8 years ago

Yea, there's an option for that, sp-autoinsert-pair.

What would you expect such a setting be called? We should add an alias to make it easier to discover (the naming in SP is chaotic and a blend of initial broken design and the hell of backward compatibility).

blaenk commented 8 years ago

Oh my apologies for not elaborating further. I did discover those settings via C-h v while I was investigating this, but I was noticing conflicts with electric-pair-mode (i.e. when I didn't have smartparens-global-mode on, things worked how I expected them to). I should have noted down the exact behavior that replicated the issues but I can't remember now. I'll be sure to be on the lookout for them while I try this and report back.

The thing is that I then also noticed sp-autodelete-pair because I was experiencing problems with regard to deleting parentheses, so I also set that to nil, but it didn't seem to work consistently and I noticed even more options like sp-autoskip-opening-pair and sp-autoskip-closing-pair and sp-autodelete-opening-pair and sp-autodelete-closing-pair.

So overall I was left with the impression that I was plugging little leaks in a sinking ship, so I was wondering if perhaps there was one single way which disables everything. If not, which variables I specifically should look at.

My goal is to not have any behavior with regard to pairing. I don't want to have the sneaking feeling that smartparens is doing any work that would incur a performance cost which would ultimately be discarded anyways, such as highlighting pairs (I'm content with show-paren-mode), skipping past pairs, deleting adjacent pairs, all of that. I don't need any of it as I'm content with electric-pair and I also would rather they not conflict (which I've already observed them to do before). I would simply love to have smartparens mode so that I can use the keymap and the default bindings. I guess I could recreate the bindings myself manually but I still would be without the keymap as long as I don't have smartparens mode, AFAIK.

I'll try setting each of these to nil (and any others I may have missed if you happen to notice) and use it for a while. If I encounter the conflicts again I'll be sure to create an issue about it.

Thanks for creating smartparens BTW, I love it.

blaenk commented 8 years ago

Maybe it'd also be useful to empty out sp-pairs? So that it won't do work trying to detect them or whatever.

Fuco1 commented 8 years ago

Without that the navigation wouldn't work. You can however disable the actions on each pair and only leave navigation on, see sp-pair function.

The performance hit is quite negligible, although recently with emacs 25 they changed something and it got a lot slower. I still haven't looked into it.

smartparens was not designed to co-exist with electric-pair-mode but to replace it, so I guess there will be some issues around that :p, most of the options you see were added simply because someone asked for... so there's not much design behind it. Try disabling what you find and if you come to some working state we can create a pre-set settings where you would just toggle one thing to disable it all (for example implemented as a minor mode to disable some stuff)

blaenk commented 8 years ago

Ah yeah I just noticed that about sp-pairs haha, that was dumb.

Yeah I'll leave sp-pairs on its default for now then. I just really care about regular delimiters like parens, brackets, angle brackets, quotes etc. I'll try this setup out for a while and report back. I currently have this:

  (setq sp-show-pair-from-inside nil

        sp-highlight-pair-overlay nil
        sp-highlight-wrap-overlay nil
        sp-highlight-wrap-tag-overlay nil

        sp-autoinsert-pair nil
        sp-autodelete-pair nil
        sp-autodelete-closing-pair nil
        sp-autodelete-opening-pair nil
        sp-autoskip-closing-pair nil
        sp-autoskip-opening-pair nil
        sp-cancel-autoskip-on-backward-movement nil
        sp-autodelete-wrap nil
        sp-autowrap-region nil
        sp-autoinsert-quote-if-followed-by-closing-pair nil
        )

I admit I just set many things to nil, anything that seemed relevant; I'm sure there are settings there which didn't need to be unset.

blaenk commented 8 years ago

And yeah I know it was meant to be a superset of or replace electric-pair mode.

The way I see smartparens is as a sexp manipulation API, more of a superset of paredit, an extensible paredit, though I've never used paredit so maybe I'm way off. So in that vein, I don't care for its pairing behavior. I'm honestly surprised that this view of smartparens isn't more widespread, i.e. sexp manipulation API and pairing behavior on the side. This is why I wanted to have just access to that API + bindings.

Fuco1 commented 8 years ago

I think it would be a good idea to setup something like spacemacs's "layers", where each of them would basically group some functionality into a single on/off switch. I would probably go on with minor modes as you mentioned in the first post.

A bit tricky part would be to handle the interdependence of the "layers", that is, I'm not sure we can go with totally disjunct setups. But it's worth to think about.

blaenk commented 8 years ago

Yeah that would be great! So at the lowest level someone could just use the smartparens api and no active functionality like pairing or highlighting or anything. Then one above it would be perhaps to enable a smartparens mode with smartparens keymap with the default bindings, and so users could attach their own custom bindings for smartparens (i.e. if smartparens is enabled). Then another one above would be the auto-pairing behavior and everything associated with it (skipping over parentheses, deleting adjacent parentheses, etc). Then perhaps another would be highlighting overlays or whatever is done in that regard.

I'm not all too familiar with smartparens' internals so I don't mean to imply it'll be easily done, but it would be very cool for users like me who are primarily interested in the API and the out-of-the-box bindings. Of course you could also provide a kind of sp-turn-everything-on type thing in case they want it all.

Fuco1 commented 8 years ago

Note that the api is available even with smartparens-mode off (which should turn off every other functionality). As for the functions, you would need to add your own global binding or some minor mode to just do the bindings.

blaenk commented 8 years ago

Oh I'm aware thanks, that's what I was saying in the first few posts, and that's how I was using it early on. Indeed that's what I'd be interested in, to be able to have a map associated with smartparens for when it's on.

Fuco1 commented 8 years ago

Right, must've missed it :blush: