Quickly surround text with delimiters in emacs
Emacs Lisp
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

README.org

http://melpa.org/packages/corral-badge.svg http://stable.melpa.org/packages/corral-badge.svg

Corral

Corral is a lightweight package that lets you quickly wrap parentheses and other delimiters around text, intuitively surrounding what you want it to using just two commands.

Examples

./corral-example-c.gif ./corral-example-js.gif ./corral-example-el.gif

These examples are shown with the built-in electric-pair-mode enabled.

Installation

Corral can be found on melpa, and should be installed from there. To install it manually instead, save corral.el to your computer and add this to your init file:

(add-to-list 'load-path "/path/to/corral/directory/")
(require 'corral)

Usage

Call a command once to wrap delimiters around the sexp at point. Repeated calls of the same command, backward or forward, will shift the delimiters in the respective direction, corralling more text.

To use these commands, just bind them to keys of your choosing. Here are some example keybindings:

(global-set-key (kbd "M-9") 'corral-parentheses-backward)
(global-set-key (kbd "M-0") 'corral-parentheses-forward)
(global-set-key (kbd "M-[") 'corral-brackets-backward)
(global-set-key (kbd "M-]") 'corral-brackets-forward)
(global-set-key (kbd "M-{") 'corral-braces-backward)
(global-set-key (kbd "M-}") 'corral-braces-forward)
(global-set-key (kbd "M-\"") 'corral-double-quotes-backward)

The wrapping algorithm tries to follow these rules:

  • If the point is over a word, it will always wrap around that word.
  • Otherwise, backward and forward commands should have different effects.

You can tweak how the wrapping works by modifying the syntax table through corral-syntax-entries (see Settings).

Settings

Keep point position instead of following delimiters

This is controlled by the variable corral-preserve-point, which can be set manually or through customize.

(setq corral-preserve-point t)

Configure how corral handles punctuation/symbols

Corral can be configured to use special syntax rules, which are set through the variable corral-syntax-entries. This variable is a list of syntax entries and follows the same syntax as modify-syntax-entry.

For example, if you want to have # and * be treated as symbols so that they are wrapped as part of the word:

(setq corral-syntax-entries '((?# "_")
                              (?* "_")))