corral
corral copied to clipboard
Quickly surround text with delimiters in emacs
[[http://melpa.org/#/corral][file:http://melpa.org/packages/corral-badge.svg]] [[http://stable.melpa.org/#/corral][file: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: #+BEGIN_SRC emacs-lisp (add-to-list 'load-path "/path/to/corral/directory/") (require 'corral) #+END_SRC
** 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: #+BEGIN_SRC emacs-lisp (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) #+END_SRC
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 [[https://github.com/nivekuil/corral#configure-how-corral-handles-punctuationsymbols][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. #+BEGIN_SRC emacs-lisp (setq corral-preserve-point t) #+END_SRC *** 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: #+BEGIN_SRC emacs-lisp (setq corral-syntax-entries '((?# "_") (? "_"))) #+END_SRC