Difference between revisions of "Paredit-mode"

From WikEmacs
Jump to: navigation, search
(Changed command for Join to M-J from M-j. Latter is comment-indent-new-line.)
 
(2 intermediate revisions by 2 users not shown)
Line 14: Line 14:
  
 
<source lang="lisp">
 
<source lang="lisp">
(autoload 'paredit-mode "paredit"
+
(autoload 'enable-paredit-mode "paredit"
      "Minor mode for pseudo-structurally editing Lisp code." t)
+
  "Turn on pseudo-structural editing of Lisp code."
(add-hook 'emacs-lisp-mode-hook      (lambda () (paredit-mode +1)))
+
  t)
(add-hook 'lisp-mode-hook            (lambda () (paredit-mode +1)))
+
(add-hook 'emacs-lisp-mode-hook      'enable-paredit-mode)
(add-hook 'lisp-interaction-mode-hook (lambda () (paredit-mode +1)))
+
(add-hook 'lisp-mode-hook            'enable-paredit-mode)
(add-hook 'scheme-mode-hook          (lambda () (paredit-mode +1)))
+
(add-hook 'lisp-interaction-mode-hook 'enable-paredit-mode)
 +
(add-hook 'scheme-mode-hook          'enable-paredit-mode)
 
</source>
 
</source>
  
 
== Helpful keybindings ==
 
== Helpful keybindings ==
 +
 +
=== Navigating ===
  
 
; {{Keys|C-M-f}}
 
; {{Keys|C-M-f}}
Line 29: 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 35: Line 71:
  
 
<source lang="lisp">
 
<source lang="lisp">
(add-hook 'slime-repl-mode-hook (lambda () (paredit-mode +1)))
+
(add-hook 'slime-repl-mode-hook 'enable-paredit-mode)
 
</source>
 
</source>
  
Line 41: Line 77:
  
 
<source lang="lisp">
 
<source lang="lisp">
;; Stop SLIME's REPL from grabbing DEL,
+
;; Stop SLIME's REPL from grabbing DEL,
;; which is annoying when backspacing over a '('
+
;; which is annoying when backspacing over a '('
(defun override-slime-repl-bindings-with-paredit ()
+
(defun override-slime-repl-bindings-with-paredit ()
  (define-key slime-repl-mode-map
+
  (define-key slime-repl-mode-map
      (read-kbd-macro paredit-backward-delete-key) nil))
+
    (read-kbd-macro paredit-backward-delete-key)
      (add-hook 'slime-repl-mode-hook 'override-slime-repl-bindings-with-paredit)
+
    nil))
 +
(add-hook 'slime-repl-mode-hook 'override-slime-repl-bindings-with-paredit)
 
</source>
 
</source>
  
Line 59: Line 96:
 
* [http://mumble.net/~campbell/emacs/paredit.el Stable Version]
 
* [http://mumble.net/~campbell/emacs/paredit.el Stable Version]
 
* [http://mumble.net/~campbell/emacs/paredit-beta.el Beta Version]
 
* [http://mumble.net/~campbell/emacs/paredit-beta.el Beta Version]
* [http://mumble.net/~campbell/emacs/paredit.html Official documentation]
+
* [http://mumble.net/~campbell/emacs/paredit.html Quick reference]
  
 
== Tutorial Pages ==
 
== Tutorial Pages ==

Latest revision as of 17:47, 17 September 2014

Paredit
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[edit]

(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[edit]

Navigating[edit]

[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[edit]

[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[edit]

[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[edit]

[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[edit]

[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[edit]

SLIME REPL[edit]

(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[edit]

Project Pages[edit]

Tutorial Pages[edit]

External Links[edit]