smartparens icon indicating copy to clipboard operation
smartparens copied to clipboard

:wrap does not respect :when and :unless keywords

Open Perangelot opened this issue 2 years ago • 0 comments

Expected behavior

A region is wrapped in a pair using the keybindings specified in the definition iff all functions in :when keyword return non-nil, or if all functions in :unless keyword return nil.

Actual behavior

The :wrap keyword is ignorant of the :when and :unless keywords.

An example

With the below code, when pressing C-S-k in org-mode and having foo as active region,

  1. \mathit{foo} should result if sp-in-math-p returns non-nil.
  2. /foo/ should result if sp-in-math-p returns nil.
  (with-eval-after-load 'org
    (sp-with-modes 'org-mode

      (sp-local-pair "\\mathit\{" "\}"
                     :when '(sp-in-math-p)
                     :post-handlers '(sp-latex-skip-double-quote)
                     :wrap "C-S-k")

      (sp-local-pair "\/" "\/"
                     :unless '(sp-in-math-p)
                     :post-handlers '(sp-latex-skip-double-quote)
                     :wrap "C-S-k")))

Perangelot avatar Jul 19 '22 18:07 Perangelot