diff --git a/haskell-mode.el b/haskell-mode.el index 4abd2a286..b91c728f0 100644 --- a/haskell-mode.el +++ b/haskell-mode.el @@ -860,10 +860,16 @@ Note that negative arguments do not work so well." (goto-char (or (scan-sexps (point) arg) (buffer-end arg))) (backward-prefix-chars)) (save-match-data - (if (haskell-lexeme-looking-at-token) - (if (member (match-string 0) (list "(" "[" "{")) - (goto-char (or (scan-sexps (point) arg) (buffer-end arg))) - (goto-char (match-end 0))))))) + (while (> arg 0) + (when (haskell-lexeme-looking-at-token) + (cond ((member (match-string 0) (list "(" "[" "{")) + (goto-char (or (scan-sexps (point) 1) (buffer-end 1)))) + ((member (match-string 0) (list ")" "]" "}")) + (signal 'scan-error (list "Containing expression ends prematurely." + (match-beginning 0) + (match-end 0)))) + (t (goto-char (match-end 0))))) + (setf arg (1- arg)))))) diff --git a/tests/haskell-mode-tests.el b/tests/haskell-mode-tests.el index 301ed977d..e3b6d7ef8 100644 --- a/tests/haskell-mode-tests.el +++ b/tests/haskell-mode-tests.el @@ -410,4 +410,58 @@ Also should respect 10 column fill." (string= "hello world" (buffer-substring 1 (point-max)))))) +(ert-deftest forward-sexp-function-1 () + "Check if `forward-sexp-function' behaves properly on end of +sexp." + (should (with-temp-buffer + (haskell-mode) + (insert "(foo) bar") + (goto-char 5) + (condition-case err + (progn (forward-sexp) + nil) + (scan-error (equal (cddr err) (list 5 6))))))) + +(ert-deftest forward-sexp-function-2 () + "Check if `forward-sexp-function' behaves properly on beginning +of sexp." + (should (with-temp-buffer + (haskell-mode) + (insert "(foo) bar") + (goto-char 1) + (forward-sexp) + (eq (point) 6)))) + +(ert-deftest haskell-forward-sexp-1 () + "Check if `haskell-forward-sexp' properly moves over sexps." + (should (with-temp-buffer + (insert "foo = bar . baz") + (goto-char 1) + (haskell-forward-sexp 4) + (eq (point) 12)))) + +(ert-deftest haskell-forward-sexp-2 () + "Check if `haskell-forward-sexp' properly moves over sexps." + (should (with-temp-buffer + (insert "foo = bar . baz") + (goto-char 1) + (haskell-forward-sexp 1) + (eq (point) 4)))) + +(ert-deftest haskell-forward-sexp-3 () + "Check if `haskell-forward-sexp' properly moves over sexps." + (should (with-temp-buffer + (insert "(a b) c = d . e") + (goto-char 1) + (haskell-forward-sexp 5) + (eq (point) 14)))) + +(ert-deftest haskell-forward-sexp-4 () + "Check if `haskell-forward-sexp' properly moves over sexps." + (should (with-temp-buffer + (insert "(a b) c = d . e") + (goto-char 1) + (haskell-forward-sexp 1) + (eq (point) 6)))) + (provide 'haskell-mode-tests)