Fuco1 / smartparens

Minor mode for Emacs that deals with parens pairs and tries to be smart about it.
GNU General Public License v3.0
1.84k stars 193 forks source link

:wrap does not respect :when and :unless keywords #1129

Open Perangelot opened 2 years ago

Perangelot commented 2 years ago

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")))