I've been trying to get smartparens to recognize Mathematica's comments, which have delimiters (* and *), while keeping the default behavior for ordinary parens ( and ). The following configuration isn't working.

(sp-with-modes '(wolfram-mode)
  (sp-local-pair "(*" "*)"
             :unless '(sp-in-string-p)
             :actions '(insert wrap)))

As soon as I type an open paren, smartparens enters a close paren, as it should. I would like to have the active pair turn into Mathematica comments when I type *, as follows,

(|) -> (* | *)

where | is point. Unfortunately, I found this in the smartparens wiki,

Pairs have to be prefix-free, that means no opening pair should be a prefix of some other pair. This is reasonable and in fact necessary for correct function. For example, with auto insertion of pair "(" ")" and pair "(/" "/)" (which has as a prefix the one paren version), the program wouldn't know you might want to insert the longer version and simply inserts (|). This can technically be fixed with "look-ahead" and then backward alteration of input text, but it will be confusing and probably not very useful anyway. If such functionality will ever get implemented, it will be disabled by default.

I'd like to have this functionality, as it's the same behavior that the Mathematica parser itself exhibits. Can anyone tell me how to do this?

  • The documentation is out of date, but this feature works in the trunk and has been for at least 8 months. I will update the docs.
    – Fuco
    Commented Feb 10, 2016 at 14:36
  • @Fuco: please consider elaborating, providing the correct doc here, pointing to the "trunk", or whatever, to help more.
    – Drew
    Commented Feb 10, 2016 at 14:53

1 Answer 1


With code newer than the documentation you found, you can set up (* to automatically insert the pair *).

(sp-pair "(*" "*)")

But we can actually do better, and tell smartparens to, upon insertion, add spaces, and put point between them:

(sp-pair "(*" "*)" :post-handlers '(:add " | "))

There's some documentation on this, but I find it somewhat confusing. At least for this use case, it's not too complicated.

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.