smartparens icon indicating copy to clipboard operation
smartparens copied to clipboard

Ensure turn-off-smartparens-mode also disables strict mode.

Open Wilfred opened this issue 10 years ago • 8 comments

I've started using smartparens-strict-mode, and it works really well. However, I noticed my calls to turn-off-smartparens-mode didn't disable strict mode. This fixes that.

I think this is a reasonable behaviour, let me know what you think.

Wilfred avatar Nov 03 '15 21:11 Wilfred

If we disable it like this then turning sp back on would not re-enable strict mode, which is what I would expect.

That is, if I enable strict mode for a buffer I would want smartparens-mode to disable it when I disable sp and enable it back when I enable it. I'm not sure how to solve this reliably.

Fuco1 avatar Nov 07 '15 16:11 Fuco1

You're right, that'd be a little confusing. How about we add a turn-off-smartparens-strict-mode function? If users want both switched off, they can call both functions (it'd suit me at least).

I've modified my branch to add this command.

Wilfred avatar Nov 09 '15 22:11 Wilfred

Is there, then, any reason not to call (smartparens-strict-mode -1). Or do you want it for hooks? Notice that calling this won't turn off smartparens-mode so you would need to call both "turn off" functions.

Fuco1 avatar Nov 09 '15 23:11 Fuco1

Yep, exactly, I'd like it for hooks. I suppose I could call (smartparens-strict-mode -1) but we could say the same thing about turn-off-smartparens-mode. I like how explicit turn-off-smartparens-strict-mode is.

Wilfred avatar Nov 12 '15 22:11 Wilfred

Maybe SP could have its own extra local variable which would track if the strict mode was on when sp was being disabled and re-enable it according to that.

So the situations will be:

  1. User turns both on. If a setting "track strict mode" is on, toggling SP also toggles strict mode (first time turning on strict mode means it is "on" for the buffer)
  2. User turns both on, but has "track strict mode" disabled. To disable both, they have to turn both off manually/on hook (like you propose)
  3. User doesn't use strict mode at all. Nothing special happens.
  4. User toggles strict mode on and then off, the "tracking variable" will set itself to off. Toggling SP on or off will leave strict mode off.

Since we have 2 modes with 2 states 4 situations should be all, unless I'm missing some sequence

Fuco1 avatar Nov 13 '15 17:11 Fuco1

Hm, is it that complicated? Are there any situations where I'd want smartparens-strict-mode but not smartparens-mode?

I thought strict mode was just SP with a few extensions. I can't see any situation where I wouldn't want to switch one off without also wanting to switch the other off.

Wilfred avatar Nov 16 '15 22:11 Wilfred

Right, the issue is more that if you had strict mode before and you toggle both off with just call to turn-off-smartparens-mode, calling turn-on-smartparens-mode (or just (smartparens-mode 1) should also re-enable strict mode.

You are right that it makes little sense having just strict mode on without SP. The reason it's a minor mode is to have the keymap with the remapping toggle-able.

Fuco1 avatar Nov 16 '15 22:11 Fuco1

I'm going to change the behaviour in the following way:

  1. If you turn on strict mode, it will automatically enable smartparens-mode if it wasn't already on (this already seems to exist)
  2. If you turn off smartparens-mode, it will automatically disable strict mode which remaps a lot of regular commands to smartparens variants.

The other cases will do nothing special. If you first enable smartparens, then strict mode and then disable strict mode, it will only disable strict mode.

This way it behaves in a way that smartparens-mode is a "dependency" of strict mode, and disabling it will turn off both. Enabling just strict mode will enable the "dependency".

I will also deprecate the turn-off-smartparens-mode, I don't know why it exists to be hones... if someone needs it for a hook, they can just add a lambda or something. It seems pointless.

Fuco1 avatar Apr 03 '24 16:04 Fuco1

The points from the above comment are now implemented.

Fuco1 avatar Jun 29 '24 20:06 Fuco1