Difference between revisions of "Paredit-mode"
Jump to navigation
Jump to search
(Suggest enable-paredit-mode rather than (lambda () (paredit-mode +1)). Fix indentation. Call the quick reference what it is; don't dignify it by calling it `documentation'.) |
(link to lisp_editing page) |
||
(7 intermediate revisions by 3 users not shown) | |||
Line 24: | Line 24: | ||
== Helpful keybindings == | == Helpful keybindings == | ||
+ | |||
+ | === Navigating === | ||
; {{Keys|C-M-f}} | ; {{Keys|C-M-f}} | ||
Line 30: | Line 32: | ||
; {{Keys|C-M-b}} | ; {{Keys|C-M-b}} | ||
: Backward sexp | : Backward sexp | ||
+ | |||
+ | ; {{Keys|C-M-u}} | ||
+ | : Go up sexp | ||
+ | |||
+ | ; ''')''' | ||
+ | : Go to the end of the node or the end of the parent node when repeated. | ||
+ | |||
+ | === Killing === | ||
+ | |||
+ | ; {{Keys|C-k}} | ||
+ | : Kill everything from here to the end of the line, including any following lines that are included in the scope of the nodes being killed. It will also kill inside strings but stop at the end of the string. | ||
+ | |||
+ | === Raising === | ||
+ | |||
+ | ; {{Keys|M-r}} | ||
+ | : Replace the parent node by the current node. | ||
+ | |||
+ | (|foo) -> foo | ||
+ | (foo |bar mu) -> bar | ||
+ | (foo (bar |mu zot) bob) -> (foo mu bob) | ||
+ | |||
+ | === Wrapping === | ||
+ | |||
+ | ; {{Keys|C-M-(}} | ||
+ | : to wrap the following node in parens. Alternatively, {{Keys|C-M-SPC}} to select the whole node, or just use your normal region selection and run '''(''' or '''[''' or '''{''' to wrap that selection. | ||
+ | |||
+ | === Splitting === | ||
+ | |||
+ | ; {{Keys|M-S}} | ||
+ | : split the current node. This works on parenthesized expressions or strings. | ||
+ | |||
+ | ; {{Keys|M-J}} | ||
+ | : join two nodes. Works same as above in reverse. | ||
== Common Customization == | == Common Customization == | ||
Line 53: | Line 88: | ||
== See Also == | == See Also == | ||
+ | See a full list on the [[Lisp_editing]] page. | ||
+ | |||
+ | * [http://wikemacs.org/wiki/Lisp_editing#Parinfer_-_keep_parens_and_indentation_balanced Parinfer] helps to keep both the indentation and parens balanced. Easy and yet advanced features like Paredit. | ||
* [[autopair-mode]] | * [[autopair-mode]] | ||
− | * [[rainbow delimiters]] | + | * [[rainbow delimiters]], to highlight each level of parentheses in a different color |
* [[electric-pair-mode]] | * [[electric-pair-mode]] | ||
+ | * [https://github.com/abo-abo/lispy lispy], vi-like paredit (i.e., an alternative to paredit with short keybindings) | ||
+ | * [https://github.com/promethial/paxedit paxedit], context driven lisp editing and refactoring, inspired by paredit. | ||
== Project Pages == | == Project Pages == | ||
Line 64: | Line 104: | ||
== Tutorial Pages == | == Tutorial Pages == | ||
+ | |||
+ | * [http://danmidwood.com/content/2014/11/21/animated-paredit.html a tutorial by danmidwood] with many gifs. | ||
== External Links == | == External Links == |
Latest revision as of 08:42, 26 April 2017
Description | structural editing of S-expression data |
---|---|
Author | Taylor Campbell |
Maintainer | Taylor Campbell |
Source | http://mumble.net/~campbell/emacs/paredit.el |
Paredit is a minor mode for performing structured editing of S-expression data. The typical example of this would be Lisp or Scheme source code.
Paredit helps keep parentheses balanced and adds many keys for moving S-expressions and moving around in S-expressions.
Basic setup
(autoload 'enable-paredit-mode "paredit"
"Turn on pseudo-structural editing of Lisp code."
t)
(add-hook 'emacs-lisp-mode-hook 'enable-paredit-mode)
(add-hook 'lisp-mode-hook 'enable-paredit-mode)
(add-hook 'lisp-interaction-mode-hook 'enable-paredit-mode)
(add-hook 'scheme-mode-hook 'enable-paredit-mode)
Helpful keybindings
- [C-M-f]
- Forward sexp
- [C-M-b]
- Backward sexp
- [C-M-u]
- Go up sexp
- )
- Go to the end of the node or the end of the parent node when repeated.
Killing
- [C-k]
- Kill everything from here to the end of the line, including any following lines that are included in the scope of the nodes being killed. It will also kill inside strings but stop at the end of the string.
Raising
- [M-r]
- Replace the parent node by the current node.
(|foo) -> foo (foo |bar mu) -> bar (foo (bar |mu zot) bob) -> (foo mu bob)
Wrapping
- [C-M-(]
- to wrap the following node in parens. Alternatively, [C-M-SPC] to select the whole node, or just use your normal region selection and run ( or [ or { to wrap that selection.
Splitting
- [M-S]
- split the current node. This works on parenthesized expressions or strings.
- [M-J]
- join two nodes. Works same as above in reverse.
Common Customization
SLIME REPL
(add-hook 'slime-repl-mode-hook 'enable-paredit-mode)
SLIME’s REPL has the very annoying habit of grabbing DEL which interferes with paredit’s normal operation. To alleviate this problem use the following code:
;; Stop SLIME's REPL from grabbing DEL,
;; which is annoying when backspacing over a '('
(defun override-slime-repl-bindings-with-paredit ()
(define-key slime-repl-mode-map
(read-kbd-macro paredit-backward-delete-key)
nil))
(add-hook 'slime-repl-mode-hook 'override-slime-repl-bindings-with-paredit)
See Also
See a full list on the Lisp_editing page.
- Parinfer helps to keep both the indentation and parens balanced. Easy and yet advanced features like Paredit.
- autopair-mode
- rainbow delimiters, to highlight each level of parentheses in a different color
- electric-pair-mode
- lispy, vi-like paredit (i.e., an alternative to paredit with short keybindings)
- paxedit, context driven lisp editing and refactoring, inspired by paredit.
Project Pages
Tutorial Pages
- a tutorial by danmidwood with many gifs.