haskell-ts-mode

emacs major mode

A haskell mode that uses treesitter

Screenshot

The above screenshot is indented and coloured using haskell-ts-mode, with prettify-symbols-mode enabled.

Usage

Features

Say it with me: indentation does not change the syntax-tree. This means that the indentation is a lot more predictable, but sometimes you must manually press M-i to indent.

An overview of the features are:

Comparison with haskell-mode

The more interesting features are:

Motivation

haskell-mode contains nearly 30k lines of code and is about 30 years old. Therefore, a lot of stuff Emacs has gained the ability to do in those years, haskell-mode already has implemented them.

In 2018, a mode called haskell-tng-mode was made to solve some of these problems. However, because of Haskell's syntax, it too became very complex and required a web of dependencies.

Both these modes ended up practically parsing Haskell's syntax to implement indentation, so I thought why not use Tree-sitter?

Installation

The package is available on ELPA. You can install it using:

M-x package-install RET haskell-ts-mode RET

(add-to-list 'load-path "path/to/haskell-ts-mode")(require 'haskell-ts-mode)

Customization

If colour is too much or too less for you, adjust treesit-font-lock-level accordingly.

If you want to highlight signature declarations (disabled by default), add the following to your init file:

(setq haskell-ts-highlight-signature t)

How to disable haskell-ts-mode indentation

(setq haskell-ts-use-indent nil)

Pretify symbols mode

prettify-symbols-mode can be used to replace common symbols with Unicode alternatives.

(add-hook 'haskell-ts-mode 'prettify-symbols-mode)

Adjusting font lock level

Set haskell-ts-font-lock-level accordingly. Default value is 4, so if you suffer from contagious dehydration, you can lower it.

Language server

haskell-ts-mode now works with lsp-mode, but lsp-haskell still relies on haskell-mode.

To add eglot support, add the following code to your init.el:

(with-eval-after-load 'eglot  (defvar eglot-server-programs)  (add-to-list 'eglot-server-programs'(haskell-ts-mode . ("haskell-language-server-wrapper" "--lsp"))))

TODO

Author: Pranshu