Closed choppsv1 closed 3 years ago
auto-inserts text into files
automatic-text-adding feature
Are you sure that https://github.com/Fuco1/smartparens is the package your referring to?
Minor mode for Emacs that deals with parens pairs and tries to be smart about it.
Or by text
do you mean parentheses, quotes, etc.?
Could you add some reproduction steps with observed and expected behaviors.
By auto-added-text I am referring to any characters that one did not type, but were added to ones file anyway. This violates the principle of least surprise.
Not unlike many (most) people using spacemacs I use vi modal interactions. So starting in command mode, If I type i f o o " ESC b i " ESC
I expect to see "foo" as that is what I entered, and what I would get in vi/vim. With this smartparens horror (:) instead I get ""foo"", which I did not enter. This is not a contrived example as I often find myself adding the closing half of a pair of punctuation prior to the opening half b/c I forgot or didn't realize I wanted to add the opening half to begin with (e.g., the "foo" example is a very typical example where I decide to put quotes around a word after I started typing the word).
Confirmed, I'm also getting ""foo""
in .spacemacs
which is in emacs-lisp-mode
.
This comment might be a reason why it isn't disabled by default:
Some packages relies on it as a dependency, we cannot do anything for this. Putting smartparents in dotspacemacs-excluded-packages will effectively remove all Spacemacs configuration regarding smartparents. Not much we can do about packages using it internally.
source: https://github.com/syl20bnr/spacemacs/issues/6144#issuecomment-222199155
It's from 3 years ago, so I don't know if it's still the case.
There's a package called https://github.com/emacs-evil/evil-surround which allows for wrapping text objects (evil) in pairs. It comes with Spacemacs.
In your example after typing foo
and exiting to normal state (Esc
)
You'll end up with "foo"
if you either:
vb
or viw
and press s"
ysiw"
I second this motion. I often add opening/closing delimiters to blocks in visual-block-mode (something like C-v } $ A "
), and smartparens causes a lot of buggy and unintended behavior.
I too second this motion. My reason is that smartparens brings emacs to its knees, e.g., in my shell buffer when it has lots of lines with mismatched parentheses, brackets, etc. For now I added the following code to disable it in some modes.
(remove-hook 'comint-mode-hook 'smartparens-mode)
(remove-hook 'prog-mode-hook 'smartparens-mode)
(remove-hook 'minibuffer-setup-hook 'spacemacs//conditionally-enable-smartparens-mode)
It would be far better if smartparens is off altogether.
Issue #10441 also reported emacs lock-up problem with smartparens. This is the kind of problem I run into almost daily if I did not disable smartparens. It is hard for me to come up with a test case, because I don't know which line among hundreds of lines in my shell buffer.
I discovered that adding the following line prior to loading any spacemacs file disables smartparens completely. This is of course rather drastic measure which will make it harder to enable smartparens later on.
(defadvice spacemacs-editing/init-smartparens (around disable-smartparens activate))
These seem to work as a workaround:
;; disable automatic closing pairs ;; https://www.reddit.com/r/emacs/comments/39gxye/stop_spacemacs_from_auto_inserting_parenthesis/ ;; https://github.com/Fuco1/smartparens/wiki/Pair-management#removing-pairs
(sp-pair "'" nil :actions :rem)
(sp-pair "\"" nil :actions :rem)
(sp-pair "(" nil :actions :rem)
(sp-pair "\{" nil :actions :rem)
(sp-pair "\[" nil :actions :rem)
Still hate smartparens. :)
For some reason this is now enabled in python mode, even though I have hacks all over the place to make sure it deosn't get enabled.
Actually the last comment/snippet from @duianto at least makes the auto-insert go away even in python mode. But wow what a PITA this all is just to have the editor not do surprisingly wrong things with my keystrokes (it's most basic job).
After having disabled smartparens-mode for a long time, I recently re-enabled it for me so that I can help track down problems that I may encounter with it.
Should difficult problems arise, I plan on adding the following before spacemacs is setup to completely disable smartparens-mode:
(defadvice smartparens-mode (around disable-smartparens activate)
"Disable smartparens-mode completely.")
To un-do above, I can simply do this
(ad-deactivate 'smartparens-mode)
Hopefully we can help improve smartparens-mode so that it does not bring down emacs to its knees. However it would be helpful if an easy way is provided to disable features like this.
Spacemacs is useful, but too many things are enabled by default which often hose emacs. For the first 30 years of use, emacs has been stable enough for me that I didn't even need to know that "pkill -USR2 emacs" would be handy to wake up hosed emacs. In the past few years I use it several times a week!
It has been a while but there was a time when I had to resort to things such as below out of frustration to help me figure out what feature was hosing emacs. Each one of the features mentioned below has caused problems for me at one time.
(defun my-disable-most-hooks ()
"Disable many things that can get in the way of general emacs usage."
(interactive)
(let ()
(when (bound-and-true-p global-company-mode) ; company
(global-company-mode 0))
(when (bound-and-true-p company-mode)
(company-mode 0))
(when (bound-and-true-p eldoc-mode) ; eldoc
(eldoc-mode 0))
(when (bound-and-true-p global-eldoc-mode)
(global-eldoc-mode 0))
(when (bound-and-true-p global-flycheck-mode) ; flycheck
(global-flycheck-mode 0))
(when (bound-and-true-p flyspell-mode) ; flyspell
(flyspell-mode-off))
(when (bound-and-true-p ggtags-mode) ; ggtags
(ggtags-mode 0))
(when (bound-and-true-p global-git-gutter+-mode) ; git-gutter+
(global-git-gutter+-mode 0))
(when (bound-and-true-p git-gutter+-mode)
(git-gutter+-mode 0))
(when (bound-and-true-p global-highlight-parentheses-mode)
(global-highlight-parentheses-mode 0))
(when (bound-and-true-p highlight-parentheses-mode)
(highlight-parentheses-mode 0))
(when (bound-and-true-p global-hl-line-mode) ; hl-line
(global-hl-line-mode 0))
(when (bound-and-true-p jit-lock-mode) ; jit-lock
(jit-lock-mode nil))
(when (bound-and-true-p smartparens-global-mode) ; smartparens
(smartparens-global-mode 0))
(when (bound-and-true-p smartparens-mode)
(smartparens-mode 0))
(when (member 'sp--post-self-insert-hook-handler post-self-insert-hook)
(remove-hook 'post-self-insert-hook 'sp--post-self-insert-hook-handler))
(when (member 'sp--pre-command-hook-handler pre-command-hook)
(remove-hook 'pre-command-hook 'sp--pre-command-hook-handler))
(when (member 'sp--pre-command-state pre-command-hook)
(remove-hook 'pre-command-hook 'sp--pre-command-state))
(when (bound-and-true-p yas-global-mode) ; yas
(yas-global-mode 0))
)
)
I think we should consider implementing this and/or the proposed idea from https://github.com/syl20bnr/spacemacs/issues/8162 to split smartparens
out into its own layer and make easy to exclude (if not disabled by default).
I also dislike this mode, as I find it creates a ton of lag and -- even worse -- the behavior itself is often buggy (see comment about jumping around and editing in vim visual block mode, for instance). It looks like there are quite a few struggles with it, too:
Struggling to turn smartparens off: https://github.com/syl20bnr/spacemacs/issues/10858 https://github.com/syl20bnr/spacemacs/issues/6144 https://github.com/syl20bnr/spacemacs/issues/9491
Performance / stability issues: https://github.com/syl20bnr/spacemacs/issues/10441 https://github.com/syl20bnr/spacemacs/issues/3828 https://github.com/syl20bnr/spacemacs/issues/2432 https://github.com/syl20bnr/spacemacs/issues/1425
I used to try and think it was a cute way of detecting a config failure, but I have failed -- It's just super annoying every time it gets re-enabled while I'm trying to get work done, which then derails my thought process and impedes me getting my work done.
Why is something so intrusive, so unexpected, and so annoying to many people, on by default, and impossible to turn off?
Please fix this, PLEASE.
I second this. I noticed severe slow-downs when using an inferior shell, guessing that smartparens
tries to match parentheses way back into the shell's history causing the lag. If it is of help to anyone, I use this workaround to exclude the smartparens
package globally (in the .spacemacs
dotfile):
dotspacemacs-excluded-packages '(smartparens)
I was not aware that smartparens is causing so much issues on the performance side, I will take some time and try to add a setting for disabling it completely in the dotfile, as was suggested in #14446.
About changing the defaults I need to discuss with the others, point is we have a lot of packages which are possibly outdated and now causing more issues than help. I did run into similar issues with clean-aindent-mode
and lsp powered go-mode
for now the strategy was to allow users to easily disable it but have it on per default as it seems to work fine for the majority.
Smartparens can now be disabled via the dotfile. If you find the time it would be great if you could have a test and close this ticket if it works for you @choppsv1.
I haven't tested this yet but on a first glance, I think it may be more intuitive to have the new setting before dotspacemacs-smartparens-strict-mode
and make clear that dotspacemacs-smartparens-strict-mode
is not relevant when the new setting is off.
Or even have a single setting with values t
/nil
/strict
.
I tested with dotspacemacs-activate-smartparens-mode nil
and it works for me. Thank you @smile13241324!
I've also removed all of my half-baked smartparens-disabling hacks, and confirmed your new settings works for me. Thank you @smile13241324, this is really great!
Solved :)
I'd like to make a case here for not defaulting to enabling smartparens mode.
First: smartparens is very disruptive to the editing experience. It auto-inserts text into files, and is very confusing to someone who doesn't know about it or expect it.
Compare this to something less disruptive like highlighting spelling or coding mistakes, colorizing text. Note that none of these less disruptive features are on by default.
Second consider:
Camp A: Happy with smartparens. Camp B: Hates smartparens.
First time spacemacs users (who defaults are important for) who would land in camp A, don't hate spacemacs if smartparens isn't on, but it may take a little while before they discover they can turn this functionality on.
First time spacemacs users who would land in camp B, have a very negative initial experience with spacemacs b/c it has this irritating automatic-text-adding feature enabled. And, it requires serious learning and work (for a first time user) to disable.
Finally, perhaps a corollary to this is, disabling or enabling smartparens should be made a lot easier than it is right now. Certainly, I think that disruptive and/or contentious features that are not simple to disable should not be enabled by default.
Thanks. :)