7

Both autopair and smartparens provide functionality for inserting matching pairs of delimiters automatically.

How do they differ from each other in practice (if at all)? What are some use cases that are covered by one of these packages but not by the other?

itsjeyd
  • 14,586
  • 3
  • 58
  • 87
  • 2
    If smartparens is anything like paredit (and from what I understand, it is), then it's about _a lot more_ than just inserting matching pairs. In fact, if all you want is matching pairs, smartparens might be overkill. – Malabarba Oct 10 '14 at 11:44

2 Answers2

6

smartparens has a superset of the functionality provided by autopair. Apart from providing pair insertion (which is what autopair does) , it supports manipulating what it calls "hybrid sexps" or sexps in non-lisp modes. It provides commands for navigating, marking, joining, splitting, absorbing and more for sexps among other things.

I personally use smartparens and found that it provides some overlapping functionality with

  • yasnippet - ability to trigger pair insertion using a string
  • change-inner - select expression within matched pair
  • and paredit of course
Vamsi
  • 3,916
  • 22
  • 35
  • Interesting! How large is the overlap with `change-inner`? Based on your own experience, would you say that `smartparens` could be used as a replacement for `change-inner`? – itsjeyd Oct 10 '14 at 18:26
  • 1
    I`sp-kill-sexp` is somewhat of a dwim version of `change-outer` with a slight difference in where point has to be placed. `C-u C-u M-x sp-kill-hybrid-sexp` is a dwim version of `change-inner`. I use both packages for Auctex which is my primary emacs usage. – Vamsi Oct 10 '14 at 23:21
  • 1
    If you are willing to write some custom elisp using `smartparens` I would say `change-inner` can be replaced. But `change-inner`is way more convenient and does not strain the working memory (only 2 functions/keybinds to remember) as much as `smartparens` equivalents would. – Vamsi Oct 10 '14 at 23:24
  • Thanks! I played around a bit with the commands you mentioned and from what I can tell `C-u C-u M-x sp-kill-sexp` looks like a decent replacement for `change-outer`. – itsjeyd Oct 11 '14 at 08:08
  • @Vamsi In what way is `sp-kill-hybrid-sexp` better than `change inner`? I'm wondering if I should switch. – incandescentman Nov 06 '15 at 06:58
2

One basic difference is that smartparens can match escaped pairs and non-punctuation mark, like if and fi; you can also customize your pairs. smartparens is really great when working regex where there are lots of escaped pairs like \(...\), since it has its own highlighting for such pairs, making working with sed, awk... much more pleasant.

Malabarba
  • 22,878
  • 6
  • 78
  • 163
Tu Do
  • 6,772
  • 20
  • 39