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.8k stars 193 forks source link
emacs emacs-lisp lisp pairs parentheses smartparens

Smartparens

Join the chat at https://gitter.im/smartparens/Lobby MELPA Documentation Status MELPA Stable Documentation Status Build Status Coverage Status Paypal logo Patreon

Table of Contents

Smartparens is a minor mode for dealing with pairs in Emacs.

It can automatically insert pairs:

smartparens insert

wrap, unwrap and rewrap pairs:

smartparens wrapping

expand and contract pairs:

smartparens slurping

navigate pairs:

smartparens navigating

and much more!

Getting Started

We generally target GNU Emacs version 25 and newer, however, everything should work mostly fine on anything newer than version 24.

You can install smartparens from MELPA. Once installed, enable the default configuration:

(require 'smartparens-config)

You can now use smartparens with M-x smartparens-mode. To automatically enable smartparens in a programming mode:

;; Always start smartparens mode in js-mode.
(add-hook 'js-mode-hook #'smartparens-mode)

You may want to try smartparens-strict-mode. This enforces that pairs are always balanced, so commands like kill-line keep your code well-formed.

You can also use use-package to install and setup smartparens. An example config is:

(use-package smartparens
  :ensure smartparens  ;; install the package
  :hook (prog-mode text-mode markdown-mode) ;; add `smartparens-mode` to these hooks
  :config
  ;; load default config
  (require 'smartparens-config))

Usage

Inside Emacs, M-x sp-cheat-sheet will show you all the commands available, with examples.

There's also a great article demonstrating movement and editing in smartparens and extensive documentation in the wiki.

Contributing

We love pull requests. Please include tests. Smartparens uses ert-runner for testing. To run all the tests, run:

$ cask exec ert-runner

Alternatively, you can open the individual files in Emacs, then M-x eval-buffer M-x ert.

You can learn more about how we test on the testing wiki page.

Language Support

Smartparens has a default configuration that works well for most languages. For language-specific behaviour, smartparens has a separate smartparens-FOO.el file for every language and smartparens-config.el loads these automatically.

Supporting Smartparens

If you want to support this project, you can:

Related Projects

Other Emacs projects that deal with pairs include:

Smartparens aims to provide a superset of these features, in all programming languages.