summaryrefslogtreecommitdiff
path: root/paredit.el
diff options
context:
space:
mode:
Diffstat (limited to 'paredit.el')
-rw-r--r--paredit.el41
1 files changed, 40 insertions, 1 deletions
diff --git a/paredit.el b/paredit.el
index b67b1bd..be45288 100644
--- a/paredit.el
+++ b/paredit.el
@@ -337,11 +337,13 @@ Paredit behaves badly if parentheses are unbalanced, so exercise
("|(defun hello-world ...)"
";;; |\n(defun hello-world ...)"))
- ("C-j" paredit-newline
+ (() paredit-newline
("(let ((n (frobbotz))) |(display (+ n 1)\nport))"
,(concat "(let ((n (frobbotz)))"
"\n |(display (+ n 1)"
"\n port))")))
+ ("RET" paredit-RET)
+ ("C-j" paredit-C-j)
"Deleting & Killing"
(("C-d" ,@paredit-forward-delete-keys)
@@ -1007,6 +1009,43 @@ If in a comment and if followed by invalid structure, call
;; Indent the following S-expression, but don't signal an
;; error if there's only a closing delimiter after the point.
(paredit-ignore-sexp-errors (indent-sexp)))))
+
+(defun paredit-electric-indent-mode-p ()
+ "True if Electric Indent Mode is on, false if not.
+Electric Indent Mode is generally not compatible with paredit and
+ users are advised to disable it, since paredit does essentially
+ everything it tries to do better.
+However, to mitigate the negative user experience of combining
+ Electric Indent Mode with paredit, the default key bindings for
+ RET and C-j in paredit are exchanged depending on whether
+ Electric Indent Mode is enabled."
+ (and (boundp 'electric-indent-mode)
+ electric-indent-mode))
+
+(defun paredit-RET ()
+ "Default key binding for RET in Paredit Mode.
+Normally, inserts a newline, like traditional Emacs RET.
+With Electric Indent Mode enabled, inserts a newline and indents
+ the new line, as well as any subexpressions of it on subsequent
+ lines."
+ (interactive)
+ (if (paredit-electric-indent-mode-p)
+ (let ((electric-indent-mode nil))
+ (paredit-newline))
+ (newline)))
+
+(defun paredit-C-j ()
+ "Default key binding for C-j in Paredit Mode.
+Normally, inserts a newline and indents
+ the new line, as well as any subexpressions of it on subsequent
+ lines.
+With Electric Indent Mode enabled, inserts a newline, like
+ traditional Emacs RET."
+ (interactive)
+ (if (paredit-electric-indent-mode-p)
+ (let ((electric-indent-mode nil))
+ (newline))
+ (paredit-newline)))
(defun paredit-reindent-defun (&optional argument)
"Reindent the definition that the point is on.