4

How can I make smartparens not to insert a parenthesis pair when the point is at the beginning of a word? I only want it to insert the opening parenthesis.

This is my setup:

(use-package smartparens-config
  :ensure smartparens
  :diminish smartparens-mode
  :config
  (progn
    (smartparens-global-mode 1)
    (show-smartparens-global-mode 1)
    (setq
       smartparens-strict-mode nil
       sp-autoinsert-if-followed-by-word nil
       sp-autoskip-closing-pair 'always
       sp-base-key-bindings 'paredit
       sp-hybrid-kill-entire-symbol nil)
    ))

As you see, I have set sp-autoinsert-if-followed-by-word to nil, as the documentation recommends, but to no avail.

See the animated gif here:

animated gif of problem

How can I fix this? Thanks.

1
  • 1
    electric-pair-mode behaves the way you want -- if you don't have to use smartparens for other reasons. Sep 7, 2016 at 20:13

2 Answers 2

6

According to the author of smartparens, sp-autoinsert-if-followed-by-word has been deprecated. Instead, one should use the :when and :unless filters to accomplish what I wanted. (See the documentation.)

Thus, the way I managed smartparens to work as I wanted was this:

(sp-pair "(" nil :unless '(sp-point-before-word-p))
(sp-pair "[" nil :unless '(sp-point-before-word-p))
(sp-pair "{" nil :unless '(sp-point-before-word-p))
(sp-local-pair 'latex-mode "$" nil :unless '(sp-point-before-word-p))
2

Type C-q ( to only insert a single opening paren.

1
  • 1
    He wants the behaviour to be automatic. You may as well open a pair and press delete if using this solution.
    – JCC
    Sep 8, 2016 at 0:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.