Skip to content

Sync punctuation to symbol char classes. #541

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

Closed
wants to merge 1 commit into from
Closed
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
34 changes: 26 additions & 8 deletions haskell-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -454,26 +454,44 @@ Run M-x describe-variable haskell-mode-hook for a list of such modes."))
;; Syntax table.
(defvar haskell-mode-syntax-table
(let ((table (make-syntax-table)))

;; Remove default punctuation class because because we try to use
;; punctuation for a purpose of matching Haskell symbol
;; characters. Previous punctuation should get an 'illegal' class,
;; but Emacs does not have one. Lets treat them as whitespace as
;; the next best categorization.
(with-syntax-table table
(dotimes (x 256)
(when (eq (char-syntax x) ?.)
(modify-syntax-entry x "-" table))))

;; Now add punctuation class to characters defined by Haskell
;; report as 'symbol'. Note that ':' is also here as it is also a
;; symbol although not listed among symbols. Ugh, just read
;; Haskell report extra carefuly and you will understand. Notably
;; '-' is not here as it is also a comment character so has to be
;; defined separately.
(mapc (lambda (x)
(modify-syntax-entry x "." table))
"!#$%&*+./:<=>?@^|~")
(modify-syntax-entry ?- ". 123" table)

(modify-syntax-entry ?\ " " table)
(modify-syntax-entry ?\t " " table)
(modify-syntax-entry ?\" "\"" table)
(modify-syntax-entry ?\' "_" table)
(modify-syntax-entry ?_ "_" table)
(modify-syntax-entry ?\( "()" table)
(modify-syntax-entry ?\) ")(" table)
(modify-syntax-entry ?\[ "(]" table)
(modify-syntax-entry ?\] ")[" table)
(modify-syntax-entry ?\[ "(]" table)
(modify-syntax-entry ?\] ")[" table)

(modify-syntax-entry ?\{ "(}1nb" table)
(modify-syntax-entry ?\} "){4nb" table)
(modify-syntax-entry ?- ". 123" table)
(modify-syntax-entry ?\{ "(}1nb" table)
(modify-syntax-entry ?\} "){4nb" table)
(modify-syntax-entry ?\n ">" table)

(modify-syntax-entry ?\` "$`" table)
(modify-syntax-entry ?\\ "\\" table)
(mapc (lambda (x)
(modify-syntax-entry x "." table))
"!#$%&*+./:<=>?@^|~")

;; Haskell symbol characters are treated as punctuation because
;; they are not able to form identifiers with word constituent 'w'
Expand Down