diff options
author | Taylor R Campbell <campbell@mumble.net> | 2013-04-07 16:35:27 +0000 |
---|---|---|
committer | Taylor R Campbell <campbell@mumble.net> | 2013-04-07 16:35:27 +0000 |
commit | db829365197d1400c229b5bedfd1a06c7754a30a (patch) | |
tree | c690bfc53f591885ecb280e7d95f864ff05ee7c8 | |
parent | 460254d20624057f8ededfeb822891492c908c66 (diff) |
Make `paredit-forward' and `paredit-backward' move out of strings.
-rw-r--r-- | paredit.el | 39 | ||||
-rw-r--r-- | test.el | 122 |
2 files changed, 151 insertions, 10 deletions
@@ -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? @@ -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) |