smartparens icon indicating copy to clipboard operation
smartparens copied to clipboard

disable auto-balancing in strict-mode per character?

Open kanubacode opened this issue 8 years ago • 3 comments

Is there a way to turn off auto balancing for certain characters? When writing Common Lisp, or well most Lisps, it is pretty common to want to insert a single single-quote character, but I am also really enjoying the auto-balancing of strict-mode for double-quotes and parentheses.

Edit: This actually seems to only occur in my Common Lisp REPL's major-mode...source buffers behave as expected.

Thanks!

kanubacode avatar Jul 26 '17 21:07 kanubacode

Most lisp buffers are configured with this snippet

(sp-with-modes (-difference sp-lisp-modes sp-clojure-modes)
  ;; also only use the pseudo-quote inside strings where it serve as
  ;; hyperlink.
  (sp-local-pair "`" "'"
                 :when '(sp-in-string-p
                         sp-in-comment-p)
                 :unless '(sp-lisp-invalid-hyperlink-p)
                 :skip-match (lambda (ms mb me)
                               (cond
                                ((equal ms "'")
                                 (or (sp-lisp-invalid-hyperlink-p "`" 'navigate '_)
                                     (not (sp-point-in-string-or-comment))))
                                (t (not (sp-point-in-string-or-comment)))))))

It should work if you add the repl mode to sp-lisp-modes variable before smartparens-config.el is loaded (so require smartparens, then add to the list, then require config).

If that works I'll gladly accept a pull request with the fix.

Fuco1 avatar Jul 26 '17 22:07 Fuco1

Oh, and the problem you had is actually this snippet here

(sp-with-modes sp-lisp-modes
  ;; disable ', it's the quote character!
  (sp-local-pair "'" nil :actions nil))

So in the worst case you can just use the same declaration but pass your major mode into sp-local-pair (check the docstring for how it works if unsure).

Fuco1 avatar Jul 26 '17 22:07 Fuco1

This works great, thanks

kanubacode avatar Jul 26 '17 22:07 kanubacode