From 4673f61fa48f9cb1bf6d52343621fff0a939315a Mon Sep 17 00:00:00 2001 From: Gracjan Polak Date: Wed, 8 Jul 2015 22:31:46 +0200 Subject: [PATCH] Add haskell-forward-sexp --- haskell-mode.el | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/haskell-mode.el b/haskell-mode.el index 0bc555a4a..b9a5e0892 100644 --- a/haskell-mode.el +++ b/haskell-mode.el @@ -136,6 +136,7 @@ (require 'haskell-complete-module) (require 'haskell-compat) (require 'haskell-align-imports) +(require 'haskell-lexeme) (require 'haskell-sort-imports) (require 'haskell-string) @@ -652,6 +653,7 @@ Minor modes that work well with `haskell-mode': (set (make-local-variable 'comment-start-skip) "[-{]-[ \t]*") (set (make-local-variable 'comment-end) "") (set (make-local-variable 'comment-end-skip) "[ \t]*\\(-}\\|\\s>\\)") + (set (make-local-variable 'forward-sexp-function) #'haskell-forward-sexp) (set (make-local-variable 'parse-sexp-ignore-comments) nil) (set (make-local-variable 'indent-line-function) 'haskell-mode-suggest-indent-choice) ;; Set things up for eldoc-mode. @@ -747,6 +749,31 @@ Minor modes that work well with `haskell-mode': ;; (skip-syntax-forward "^w") ;; (make-string (- (point) line-start) ?\s)))))) +;;;###autoload +(defun haskell-forward-sexp (&optional arg) + "Haskell specific version of `forward-sexp'. + +Move forward across one balanced expression (sexp). With ARG, do +it that many times. Negative arg -N means move backward across N +balanced expressions. This command assumes point is not in a +string or comment. + +Note that negative arguments do not work so well." + (interactive "^p") + (or arg (setq arg 1)) + (if (< arg 0) + ;; Fall back to native Emacs method for negative arguments. + ;; Haskell has maximum munch rule that does not work well + ;; backwards. + (progn + (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))))))) + ;;;###autoload