Dummyparens is a simple utility providing parentheses auto-pairing and wrapping.
When you press an opening parenthesis key it inserts the closing one for you. If a region is selected when you press the key, the region will be wrapped. If you wrap with { it will also indent the wrapped region (convenient for C and the like).
This is similar to electric-pair minor mode, but with wrapping.
It’s intended to be minimalistic and non-invasive as you would expect such simple functionality to be.
For more sophisticated features, like HTML tags or LaTeX environments handling, consider smartparens.
This is the simplest method if you have the package.el module
(built-in since Emacs 24.1) you can simply use M-x package-install
and then put the following snippet in your ~/.emacs file
(eval-after-load "dummyparens-autoloads"
'(progn
(if (require 'dummyparens nil t)
(global-dummyparens-mode)
(warn "dummyparens not found"))))
- Create folder ~/.emacs.d if you don’t have it
- Go to it and clone dummyparens there
git clone https://github.com/snosov1/dummyparens.git
- Put this in your ~/.emacs file
(add-to-list 'load-path "~/.emacs.d") (when (require 'dummyparens nil t) (global-dummyparens-mode))
You can use M-x customize-group
and choose dummyparens
there.
- You can customize dp-pairs variable to add or remove symbols that
have to be paired. E.g.
(setq dp-pairs '( ("(" ")" nil) ("[" "]" nil) ("{" "}" dp-brace-post-handler) ("\"" "\"" nil) ))
The last argument is an action to perform after the pair was inserted.
- If you want to disable dummyparens in certain modes, you can use the
dp-ignore-modes-list
variable.(setq dp-ignore-modes-list '( minibuffer-inactive-mode ))
Although, this mode haven’t yet been spotted to conflict with other ones (this would kill the whole point of this mode!)