summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTaylor R Campbell <campbell@mumble.net>2010-09-17 20:28:03 +0000
committerTaylor R Campbell <campbell@mumble.net>2010-09-17 20:28:03 +0000
commitc0a916070586689a4b29fe0537b2af59a581e2b4 (patch)
tree99e61a901966c00f484b21d4fc6bfc8a9651ab78
parent70d40b5891cbd8eb4ff495a375bf330c97ce6ab5 (diff)
Make `paredit-newline' keep invalid structure inside comments.
Ignore-this: 914cf744a9baefd2fe545a4dcedcb6e6 darcs-hash:20100917202803-00fcc-ccf81a80dc2bcb44576e674bea314d5c6cfcf3de
-rw-r--r--paredit.el39
1 files changed, 27 insertions, 12 deletions
diff --git a/paredit.el b/paredit.el
index ce8ea88..848312d 100644
--- a/paredit.el
+++ b/paredit.el
@@ -962,25 +962,40 @@ If not in a string, act as `paredit-doublequote'; if no prefix argument
(insert char) ; (Is there a better way to
nil)) ; express the rubout char?
; ?\^? works, but ugh...)
-
-;;; The placement of these functions in this file is totally random.
-
+
(defun paredit-newline ()
"Insert a newline and indent it.
This is like `newline-and-indent', but it not only indents the line
that the point is on but also the S-expression following the point,
if there is one.
Move forward one character first if on an escaped character.
-If in a string, just insert a literal newline."
+If in a string, just insert a literal newline.
+If in a comment and if followed by invalid structure, call
+ `indent-new-comment-line' to keep the invalid structure in a
+ comment."
(interactive)
- (if (paredit-in-string-p)
- (newline)
- (if (and (not (paredit-in-comment-p)) (paredit-in-char-p))
- (forward-char))
- (newline-and-indent)
- ;; 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))))
+ (cond ((paredit-in-string-p)
+ (newline))
+ ((paredit-in-comment-p)
+ (if (paredit-handle-sexp-errors
+ ;; Check for anything that would break structure in
+ ;; the comment.
+ (save-restriction
+ (narrow-to-region (point) (point-at-eol))
+ (save-excursion
+ (while (< (point) (point-max))
+ (forward-sexp)))
+ t)
+ nil)
+ (progn (newline-and-indent) (indent-sexp))
+ (indent-new-comment-line)))
+ (t
+ (if (paredit-in-char-p)
+ (forward-char))
+ (newline-and-indent)
+ ;; 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-reindent-defun (&optional argument)
"Reindent the definition that the point is on.