summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--paredit.el39
-rw-r--r--test.el122
2 files changed, 151 insertions, 10 deletions
diff --git a/paredit.el b/paredit.el
index fcf50b7..e2d3f78 100644
--- a/paredit.el
+++ b/paredit.el
@@ -1755,22 +1755,41 @@ With a prefix argument, skip the balance check."
If there are no more S-expressions in this one before the closing
delimiter, move past that closing delimiter; otherwise, move forward
past the S-expression following the point."
- (paredit-handle-sexp-errors
- (forward-sexp)
- ;; Use `up-list' if outside a string in case there is whitespace
- ;; between the point and the end of the list.
- (if (paredit-in-string-p) (forward-char) (up-list))))
+ (cond ((paredit-in-string-p)
+ (let ((end (paredit-enclosing-string-end)))
+ ;; `forward-sexp' and `up-list' may move into the next string
+ ;; in the buffer. Don't do that; move out of the current one.
+ (if (paredit-handle-sexp-errors
+ (progn (paredit-handle-sexp-errors (forward-sexp)
+ (up-list))
+ (<= end (point)))
+ t)
+ (goto-char end))))
+ ((paredit-in-char-p)
+ (forward-char))
+ (t
+ (paredit-handle-sexp-errors (forward-sexp)
+ (up-list)))))
(defun-saving-mark paredit-backward ()
"Move backward an S-expression, or up an S-expression backward.
If there are no more S-expressions in this one before the opening
delimiter, move past that opening delimiter backward; otherwise, move
move backward past the S-expression preceding the point."
- (paredit-handle-sexp-errors
- (backward-sexp)
- ;; Use `backward-up-list' if outside a string in case there is
- ;; whitespace between the point and the beginning of the list.
- (if (paredit-in-string-p) (backward-char) (backward-up-list))))
+ (cond ((paredit-in-string-p)
+ (let ((start (paredit-enclosing-string-start)))
+ (if (paredit-handle-sexp-errors
+ (progn (paredit-handle-sexp-errors (backward-sexp)
+ (backward-up-list))
+ (<= (point) start))
+ t)
+ (goto-char start))))
+ ((paredit-in-char-p)
+ ;++ Corner case: a buffer of `\|x'. What to do?
+ (backward-char 2))
+ (t
+ (paredit-handle-sexp-errors (backward-sexp)
+ (backward-up-list)))))
;;; Why is this not in lisp.el?
diff --git a/test.el b/test.el
index ba71788..bf9d9bf 100644
--- a/test.el
+++ b/test.el
@@ -741,6 +741,128 @@ Four arguments: the paredit command, the text of the buffer
("\"x|y\"" error)
("\"xy|\"" error)))
+(paredit-test 'paredit-forward
+ '(("|" "|")
+
+ ("|()" "()|" "()|")
+ ("(|)" "()|" "()|")
+ ("()|" "()|")
+
+ ("|( )" "( )|" "( )|")
+ ("(| )" "( )|" "( )|")
+ ("( |)" "( )|" "( )|")
+ ("( )|" "( )|")
+
+ ("|\"\"" "\"\"|" "\"\"|")
+ ("\"|\"" "\"\"|" "\"\"|")
+ ("\"\"|" "\"\"|")
+
+ ("|\")\"" "\")\"|" "\")\"|")
+ ("\"|)\"" "\")|\"" "\")\"|" "\")\"|")
+ ("\")|\"" "\")\"|" "\")\"|")
+ ("\")\"|" "\")\"|")
+
+ ("|\"()\"" "\"()\"|" "\"()\"|")
+ ("\"|()\"" "\"()|\"" "\"()\"|" "\"()\"|")
+ ("\"(|)\"" "\"()|\"" "\"()\"|" "\"()\"|")
+ ("\"()\"|" "\"()\"|")
+
+ ("|(\"x\" \"y\")" "(\"x\" \"y\")|" "(\"x\" \"y\")|")
+ ("(|\"x\" \"y\")" "(\"x\"| \"y\")" "(\"x\" \"y\"|)"
+ "(\"x\" \"y\")|" "(\"x\" \"y\")|")
+ ("(\"|x\" \"y\")" "(\"x|\" \"y\")" "(\"x\"| \"y\")" "(\"x\" \"y\"|)"
+ "(\"x\" \"y\")|" "(\"x\" \"y\")|")
+ ("(\"x|\" \"y\")" "(\"x\"| \"y\")" "(\"x\" \"y\"|)"
+ "(\"x\" \"y\")|" "(\"x\" \"y\")|")
+ ("(\"x\"| \"y\")" "(\"x\" \"y\"|)" "(\"x\" \"y\")|" "(\"x\" \"y\")|")
+ ("(\"x\" |\"y\")" "(\"x\" \"y\"|)" "(\"x\" \"y\")|" "(\"x\" \"y\")|")
+ ("(\"x\" \"|y\")" "(\"x\" \"y|\")" "(\"x\" \"y\"|)"
+ "(\"x\" \"y\")|" "(\"x\" \"y\")|")
+ ("(\"x\" \"y|\")" "(\"x\" \"y\"|)" "(\"x\" \"y\")|" "(\"x\" \"y\")|")
+ ("(\"x\" \"y\"|)" "(\"x\" \"y\")|" "(\"x\" \"y\")|")
+ ("(\"x\" \"y\")|" "(\"x\" \"y\")|")
+
+ ("|#\\(" "#\\(|" "#\\(|")
+ ("#|\\(" "#\\(|" "#\\(|")
+ ("#\\|(" "#\\(|" "#\\(|")
+ ("#\\(|" "#\\(|")
+
+ ("|#\\)" "#\\)|" "#\\)|")
+ ("#|\\)" "#\\)|" "#\\)|")
+ ("#\\|)" "#\\)|" "#\\)|")
+ ("#\\)|" "#\\)|")
+
+ ("|#\\\\" "#\\\\|" "#\\\\|")
+ ("#|\\\\" "#\\\\|" "#\\\\|")
+ ("#\\|\\" "#\\\\|" "#\\\\|")
+ ("#\\\\|" "#\\\\|")
+
+ ("|#\\;" "#\\;|" "#\\;|")
+ ("#|\\;" "#\\;|" "#\\;|")
+ ("#\\|;" "#\\;|" "#\\;|")
+ ("#\\;|" "#\\;|")))
+
+(paredit-test 'paredit-backward
+ '(("|" "|")
+
+ ("|()" "|()")
+ ("(|)" "|()" "|()")
+ ("()|" "|()" "|()")
+
+ ("|( )" "|( )")
+ ("(| )" "|( )" "|( )")
+ ("( |)" "|( )" "|( )")
+ ("( )|" "|( )" "|( )")
+
+ ("|\"\"" "|\"\"")
+ ("\"|\"" "|\"\"" "|\"\"")
+ ("\"\"|" "|\"\"" "|\"\"")
+
+ ("|\")\"" "|\")\"")
+ ("\"|)\"" "|\")\"" "|\")\"")
+ ("\")|\"" "|\")\"" "|\")\"")
+ ("\")\"|" "|\")\"" "|\")\"")
+
+ ("|\"()\"" "|\"()\"")
+ ("\"|()\"" "|\"()\"" "|\"()\"")
+ ("\"(|)\"" "\"|()\"" "|\"()\"" "|\"()\"")
+ ("\"()\"|" "|\"()\"" "|\"()\"")
+
+ ("|(\"x\" \"y\")" "|(\"x\" \"y\")")
+ ("(|\"x\" \"y\")" "|(\"x\" \"y\")" "|(\"x\" \"y\")")
+ ("(\"|x\" \"y\")" "(|\"x\" \"y\")" "|(\"x\" \"y\")" "|(\"x\" \"y\")")
+ ("(\"x|\" \"y\")" "(\"|x\" \"y\")" "(|\"x\" \"y\")"
+ "|(\"x\" \"y\")" "|(\"x\" \"y\")")
+ ("(\"x\"| \"y\")" "(|\"x\" \"y\")" "|(\"x\" \"y\")" "|(\"x\" \"y\")")
+ ("(\"x\" |\"y\")" "(|\"x\" \"y\")" "|(\"x\" \"y\")" "|(\"x\" \"y\")")
+ ("(\"x\" \"|y\")" "(\"x\" |\"y\")" "(|\"x\" \"y\")"
+ "|(\"x\" \"y\")" "|(\"x\" \"y\")")
+ ("(\"x\" \"y|\")" "(\"x\" \"|y\")" "(\"x\" |\"y\")" "(|\"x\" \"y\")"
+ "|(\"x\" \"y\")" "|(\"x\" \"y\")")
+ ("(\"x\" \"y\"|)" "(\"x\" |\"y\")" "(|\"x\" \"y\")"
+ "|(\"x\" \"y\")" "|(\"x\" \"y\")")
+ ("(\"x\" \"y\")|" "|(\"x\" \"y\")" "|(\"x\" \"y\")")
+
+ ("|#\\(" "|#\\(")
+ ("#|\\(" "|#\\(" "|#\\(")
+ ("#\\|(" "|#\\(" "|#\\(")
+ ("#\\(|" "|#\\(" "|#\\(")
+
+ ("|#\\)" "|#\\)")
+ ("#|\\)" "|#\\)" "|#\\)")
+ ("#\\|)" "|#\\)" "|#\\)")
+ ("#\\)|" "|#\\)" "|#\\)")
+
+ ("|#\\\\" "|#\\\\")
+ ("#|\\\\" "|#\\\\" "|#\\\\")
+ ("#\\|\\" "|#\\\\" "|#\\\\")
+ ("#\\\\|" "|#\\\\" "|#\\\\")
+
+ ("|#\\;" "|#\\;")
+ ("#|\\;" "|#\\;" "|#\\;")
+ ("#\\|;" "|#\\;" "|#\\;")
+ ("#\\;|" "|#\\;" "|#\\;")))
+
(defun paredit-canary-indent-method (state indent-point normal-indent)
(check-parens)
nil)