Skip to content

Implement haskell-forward-sexp #758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions haskell-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down