Skip to content

Commit

Permalink
Cleanup and mark as stable release
Browse files Browse the repository at this point in the history
  • Loading branch information
nivekuil committed May 25, 2015
1 parent 3169199 commit bcd1d90
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 38 deletions.
22 changes: 10 additions & 12 deletions README.org
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
[[http://melpa.org/#/corral][file:http://melpa.org/packages/corral-badge.svg]]
* Corral
** What it is
A lightweight set of commands that enable you to quickly wrap parentheses, brackets, quotes, and other delimiters around text.
Corral is a lightweight set of commands that enable you to quickly wrap parentheses, brackets, quotes, and other delimiters around text.

** What it isn't
A replacement to a fully-featured structural editing mode for lisp, such as paredit. Corral prioritizes speed and simplicity, and should work for any language.
It is not meant to be a replacement to lisp structural editing modes such as paredit. Corral emphasizes speed and simplicity, and should work for any language.

** Examples
[[./corral-example-c.gif]] \\
Expand All @@ -18,14 +16,7 @@ Corral can be found on melpa, and should be installed from there. To install it
#+END_SRC

** Usage
Call a command once to wrap the 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.

The wrapping algorithm tries to operate on these principles:
- If the point is over a word, it will always wrap around that word.
- Otherwise, =backward= and =forward= commands should have different effects.
- Symbols will not be directly corraled.

If there are any discrepancies, feel free to report it on the issue tracker.
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
Expand All @@ -37,6 +28,13 @@ To use these commands, just bind them to keys of your choosing. Here are some e
(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.
Expand Down
50 changes: 24 additions & 26 deletions corral.el
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
;; Author: Kevin Liu <[email protected]>
;; Created: 16 May 2015
;; Homepage: http://github.com/nivekuil/corral
;; Version: 0.1.8

;; This file is not part of GNU Emacs.
;; Version: 0.2

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
Expand All @@ -23,11 +21,11 @@

;;; Commentary:

;; This package contains functions that incrementally wrap (or "corral")
;; s-expressions with delimiters, such as parentheses and brackets.
;; After calling one of the interactive commands, repeated calls will shift
;; the corral instead of inserting new delimiters, expanding the amount of
;; text contained within the delimiters.
;; This package adds commands that allow the user to quickly and intuitively
;; wrap a desired amount of text within delimiters, including parentheses and
;; quotes. After calling one of the interactive commands, repeated calls will
;; shift the corral instead of inserting new delimiters, expanding the amount
;; of text contained within the delimiters.

;;; Code:

Expand Down Expand Up @@ -109,8 +107,8 @@ You can also use 'add-to-list', like this:
(corral-shift-backward open close))
(corral-wrap-backward open close)))
(setq corral--virtual-point (point))))
(unless corral-preserve-point
(goto-char corral--virtual-point)))
(unless corral-preserve-point
(goto-char corral--virtual-point)))

(defun corral-command-forward (open close backward forward)
"Handle command with OPEN and CLOSE from commands BACKWARD and FORWARD."
Expand All @@ -128,17 +126,17 @@ You can also use 'add-to-list', like this:
(corral-shift-forward open close))
(corral-wrap-forward open close)))
(setq corral--virtual-point (point))))
(unless corral-preserve-point
(goto-char corral--virtual-point)))
(unless corral-preserve-point
(goto-char corral--virtual-point)))


;;;###autoload
(defun corral-parentheses-backward ()
"Wrap parentheses around sexp, moving point to the closing parentheses."
(interactive)
(corral-command-backward ?( ?)
'corral-parentheses-backward
'corral-parentheses-forward))
'corral-parentheses-backward
'corral-parentheses-forward))

;;;###autoload
(defun corral-parentheses-forward ()
Expand All @@ -153,8 +151,8 @@ You can also use 'add-to-list', like this:
"Wrap brackets around sexp, moving point to the opening bracket."
(interactive)
(corral-command-backward ?[ ?]
'corral-brackets-backward
'corral-brackets-forward))
'corral-brackets-backward
'corral-brackets-forward))

;;;###autoload
(defun corral-brackets-forward ()
Expand All @@ -177,16 +175,8 @@ You can also use 'add-to-list', like this:
"Wrap brackets around sexp, moving point to the closing bracket."
(interactive)
(corral-command-forward ?{ ?}
'corral-braces-backward
'corral-braces-forward))

;;;###autoload
(defun corral-double-quotes-forward ()
"Wrap double quotes around sexp, moving point to the closing double quote."
(interactive)
(corral-command-forward ?\" ?\"
'corral-double-quotes-backward
'corral-double-quotes-forward))
'corral-braces-backward
'corral-braces-forward))

;;;###autoload
(defun corral-double-quotes-backward ()
Expand All @@ -196,6 +186,14 @@ You can also use 'add-to-list', like this:
'corral-double-quotes-backward
'corral-double-quotes-forward))

;;;###autoload
(defun corral-double-quotes-forward ()
"Wrap double quotes around sexp, moving point to the closing double quote."
(interactive)
(corral-command-forward ?\" ?\"
'corral-double-quotes-backward
'corral-double-quotes-forward))

(provide 'corral)

;;; corral.el ends here

0 comments on commit bcd1d90

Please sign in to comment.