Skip to content

Commit 64bd44f

Browse files
committed
Merge pull request #758 from gracjan/pr-haskell-forward-sexp
Implement haskell-forward-sexp
2 parents 9ca6bb8 + 4673f61 commit 64bd44f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

haskell-mode.el

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
(require 'haskell-complete-module)
137137
(require 'haskell-compat)
138138
(require 'haskell-align-imports)
139+
(require 'haskell-lexeme)
139140
(require 'haskell-sort-imports)
140141
(require 'haskell-string)
141142

@@ -652,6 +653,7 @@ Minor modes that work well with `haskell-mode':
652653
(set (make-local-variable 'comment-start-skip) "[-{]-[ \t]*")
653654
(set (make-local-variable 'comment-end) "")
654655
(set (make-local-variable 'comment-end-skip) "[ \t]*\\(-}\\|\\s>\\)")
656+
(set (make-local-variable 'forward-sexp-function) #'haskell-forward-sexp)
655657
(set (make-local-variable 'parse-sexp-ignore-comments) nil)
656658
(set (make-local-variable 'indent-line-function) 'haskell-mode-suggest-indent-choice)
657659
;; Set things up for eldoc-mode.
@@ -747,6 +749,31 @@ Minor modes that work well with `haskell-mode':
747749
;; (skip-syntax-forward "^w")
748750
;; (make-string (- (point) line-start) ?\s))))))
749751

752+
;;;###autoload
753+
(defun haskell-forward-sexp (&optional arg)
754+
"Haskell specific version of `forward-sexp'.
755+
756+
Move forward across one balanced expression (sexp). With ARG, do
757+
it that many times. Negative arg -N means move backward across N
758+
balanced expressions. This command assumes point is not in a
759+
string or comment.
760+
761+
Note that negative arguments do not work so well."
762+
(interactive "^p")
763+
(or arg (setq arg 1))
764+
(if (< arg 0)
765+
;; Fall back to native Emacs method for negative arguments.
766+
;; Haskell has maximum munch rule that does not work well
767+
;; backwards.
768+
(progn
769+
(goto-char (or (scan-sexps (point) arg) (buffer-end arg)))
770+
(backward-prefix-chars))
771+
(save-match-data
772+
(if (haskell-lexeme-looking-at-token)
773+
(if (member (match-string 0) (list "(" "[" "{"))
774+
(goto-char (or (scan-sexps (point) arg) (buffer-end arg)))
775+
(goto-char (match-end 0)))))))
776+
750777

751778

752779
;;;###autoload

0 commit comments

Comments
 (0)