Skip to content

Show smartparens mode

strangepr0gram edited this page Sep 23, 2022 · 4 revisions

show-smartparens-mode provides functionality similar to show-paren-mode, but works for all the user-defined pairs which are recognized by sp-get-sexp.

It is available as a globalized minor mode and is allowed in all modes where smartparens-mode is allowed, that is any mode which is not on the sp-ignore-modes-list.

You can turn it on with:

(show-smartparens-global-mode t)

If you want to only turn it on in specific modes, use after-load hooks for these modes and call (show-smartparens-mode t).

You can customize the delay after which smartparens will initiate the search by modifying the variable sp-show-pair-delay. Default value is 0.125 seconds.

Note that the pair-search is somewhat slower than show-paren-mode, which uses C libraries to do the parsing. If you have a very long buffer and a mis-matched pair, this can sometimes result in a noticeable lag (1 second or more) when you place cursor in front/behind this pair. For most of the normal editing business however, the difference is not noticeable.

Customizing the looks

Smartparens uses the same default faces as show-paren-mode, but has them renamed so you can differentiate the two modes if you wish. The face names are:

sp-show-pair-match-face
sp-show-pair-mismatch-face

You can customize them using M-x customize-group show-smartparens or M-x customize-face name-of-face.

In addition, smartparens has a third face which is used for the expression between matching pairs. This face is named:

sp-show-pair-match-content-face

By default, show-smartparens-mode does not highlight the contained expression at all. Setting sp-show-pair-match-content-face to the same thing as sp-show-pair-match-face emulates setting show-paren-style to expression when using show-paren-mode.

However, it may also be useful to use a different colour for the matching pairs and the contained expression. This is of course possible with show-smartparens-mode but not with regular show-paren-mode.