diff options
author | Taylor R Campbell <campbell+paredit@mumble.net> | 2022-11-24 19:05:29 +0000 |
---|---|---|
committer | Taylor R Campbell <campbell+paredit@mumble.net> | 2022-11-24 19:05:46 +0000 |
commit | 5615023023aea50683f5725284fb9bc6cbbd64ec (patch) | |
tree | 704c9b2a0dddf1580210b0657398f89e8f903722 /paredit.el | |
parent | 153b5d80f75b1d66d1080bc590885a9c4f0782e1 (diff) |
Work around Electric Indent Mode brokenness in newline keys.
Diffstat (limited to 'paredit.el')
-rw-r--r-- | paredit.el | 41 |
1 files changed, 40 insertions, 1 deletions
@@ -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. |