summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTaylor R Campbell <campbell@mumble.net>2013-04-07 16:46:58 +0000
committerTaylor R Campbell <campbell@mumble.net>2013-04-07 16:46:58 +0000
commit6cb5747b0973c36e0e21da4851f35a66c106a327 (patch)
tree07031d5d5939b6efb7b9ff5b073b91c46e73bbbe
parent5840f55909187d671616ef35135f802da5ee609c (diff)
Change `paredit-meta-doublequote' to avoid breaking the line.
This way, default M-" behaves more like default M-). New command `paredit-meta-doublequote-and-newline' (no default key) behaves like the old `paredit-meta-doublequote'.
-rw-r--r--paredit.el32
-rw-r--r--test.el34
2 files changed, 53 insertions, 13 deletions
diff --git a/paredit.el b/paredit.el
index 5389e8e..3e7cc5f 100644
--- a/paredit.el
+++ b/paredit.el
@@ -293,7 +293,7 @@ Paredit behaves badly if parentheses are unbalanced, so exercise
"(frob grovel) ; full \"|lexical"))
("M-\"" paredit-meta-doublequote
("(foo \"bar |baz\" quux)"
- "(foo \"bar baz\"\n |quux)")
+ "(foo \"bar baz\"| quux)")
("(foo |(bar #\\x \"baz \\\\ quux\") zot)"
,(concat "(foo \"|(bar #\\\\x \\\"baz \\\\"
"\\\\ quux\\\")\" zot)")))
@@ -901,21 +901,27 @@ If in a character literal, do nothing. This prevents accidentally
(paredit-insert-pair n ?\" ?\" 'paredit-forward-for-quote))))
(defun paredit-meta-doublequote (&optional n)
+ "Move to the end of the string.
+If not in a string, act as `paredit-doublequote'; if not prefix argument
+ is specified and the region is not active or `transient-mark-mode' is
+ disabled, the default is to wrap one S-expression, however, not zero."
+ (interactive "P")
+ (if (not (paredit-in-string-p))
+ (paredit-doublequote (or n (and (not (paredit-region-active-p)) 1)))
+ (goto-char (paredit-enclosing-string-end))))
+
+(defun paredit-meta-doublequote-and-newline (&optional n)
"Move to the end of the string, insert a newline, and indent.
-If not in a string, act as `paredit-doublequote'; if no prefix argument
- is specified and the region is not active or `transient-mark-mode' is
- disabled, the default is to wrap one S-expression, however, not
- zero."
+If not in a string, act as `paredit-doublequote'; if not prefix argument
+ is specified and the region is not active or `transient-mark-mode' is
+ disabled, the default is to wrap one S-expression, however, not zero."
(interactive "P")
(if (not (paredit-in-string-p))
- (paredit-doublequote (or n
- (and (not (paredit-region-active-p))
- 1)))
- (let ((start+end (paredit-string-start+end-points)))
- (goto-char (1+ (cdr start+end)))
- (newline)
- (lisp-indent-line)
- (paredit-ignore-sexp-errors (indent-sexp)))))
+ (paredit-doublequote (or n (and (not (paredit-region-active-p)) 1)))
+ (progn (goto-char (paredit-enclosing-string-end))
+ (newline)
+ (lisp-indent-line)
+ (paredit-ignore-sexp-errors (indent-sexp)))))
(defun paredit-forward-for-quote (end)
(let ((state (paredit-current-parse-state)))
diff --git a/test.el b/test.el
index a63f70e..d46aa13 100644
--- a/test.el
+++ b/test.el
@@ -1001,6 +1001,40 @@ Four arguments: the paredit command, the text of the buffer
("((x) ;c\n (y)|)" error)
("((x) ;c\n (y))|" error)))
+(paredit-test 'paredit-meta-doublequote
+ '(("|(fo \"ba\\\" bz\" qx)" "\"|(fo \\\"ba\\\\\\\" bz\\\" qx)\"")
+ ("(|fo \"ba\\\" bz\" qx)" "(\"|fo\" \"ba\\\" bz\" qx)")
+ ("(f|o \"ba\\\" bz\" qx)" "(f \"|o\" \"ba\\\" bz\" qx)")
+ ;++ Should the space be left there after the `"'?
+ ("(fo| \"ba\\\" bz\" qx)" "(fo \"| \\\"ba\\\\\\\" bz\\\"\" qx)")
+ ("(fo |\"ba\\\" bz\" qx)" "(fo \"|\\\"ba\\\\\\\" bz\\\"\" qx)")
+ ("(fo \"|ba\\\" bz\" qx)" "(fo \"ba\\\" bz\"| qx)")
+ ("(fo \"b|a\\\" bz\" qx)" "(fo \"ba\\\" bz\"| qx)")
+ ("(fo \"ba|\\\" bz\" qx)" "(fo \"ba\\\" bz\"| qx)")
+ ("(fo \"ba\\|\" bz\" qx)" "(fo \"ba\\\" bz\"| qx)")
+ ("(fo \"ba\\\"| bz\" qx)" "(fo \"ba\\\" bz\"| qx)")
+ ("(fo \"ba\\\" |bz\" qx)" "(fo \"ba\\\" bz\"| qx)")
+ ("(fo \"ba\\\" b|z\" qx)" "(fo \"ba\\\" bz\"| qx)")
+ ("(fo \"ba\\\" bz|\" qx)" "(fo \"ba\\\" bz\"| qx)")
+ ;++ Should the space be left there after the `"'?
+ ("(fo \"ba\\\" bz\"| qx)" "(fo \"ba\\\" bz\" \"| qx\")")
+ ("(fo \"ba\\\" bz\" |qx)" "(fo \"ba\\\" bz\" \"|qx\")")
+ ("(fo \"ba\\\" bz\" q|x)" "(fo \"ba\\\" bz\" q \"|x\")")
+ ("(fo \"ba\\\" bz\" qx|)" "(fo \"ba\\\" bz\" qx \"|\")")
+ ("(fo \"ba\\\" bz\" qx)|" "(fo \"ba\\\" bz\" qx) \"|\"")
+
+ ;++ Full tests...
+ ("(foo |(bar #\\x \"baz \\\\ quux\") zot)"
+ "(foo \"|(bar #\\\\x \\\"baz \\\\\\\\ quux\\\")\" zot)")))
+
+;++ Copy tests from `paredit-meta-doublequote'...
+
+(paredit-test 'paredit-meta-doublequote-and-newline
+ '(("(foo \"bar |baz\" quux)"
+ "(foo \"bar baz\"\n |quux)")
+ ("(foo |(bar #\\x \"baz \\\\ quux\") zot)"
+ "(foo \"|(bar #\\\\x \\\"baz \\\\\\\\ quux\\\")\" zot)")))
+
(defun paredit-canary-indent-method (state indent-point normal-indent)
(check-parens)
nil)