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.

Wilfred Hughes
  • 6,890
  • 2
  • 29
  • 59
NVaughan
  • 1,481
  • 12
  • 27

2 Answers2

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))
NVaughan
  • 1,481
  • 12
  • 27
2

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

John Kitchin
  • 11,555
  • 1
  • 19
  • 41
  • 1
    He wants the behaviour to be automatic. You may as well open a pair and press delete if using this solution. – JCC Sep 08 '16 at 00:27