NonGNU-devel ELPA - haskell-ts-mode

haskell-ts-mode Atom Feed

Description
A treesit based major mode for haskell
Latest
haskell-ts-mode-1.0.20250202.61612.tar (.sig), 2025-Feb-02, 30.0 KiB
Maintainer
Pranshu Sharma <pranshusharma366atgmail>
Website
https://codeberg.org/pranshu/haskell-ts-mode
Browse ELPA's repository
CGit or Gitweb
Badge

To install this package from Emacs, use package-install or list-packages.

Full description

1. haskell-ts-mode

A Haskell mode that uses Tree-sitter.

2. Screenshot

ss.png

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

3. Usage

  • C-c C-r Open REPL
  • C-c C-c Send code to REPL
  • M-q Indent the function

4. 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.

Overview of features:

  • Syntax highlighting
  • Structural navigation
  • Indentation
  • Imenu support
  • REPL (C-c C-r in the mode to run)
  • Prettify Symbols mode support

5. Comparison with haskell-mode

The more interesting features are:

  • Logical syntax highlighting:
    • Only arguments that can be used in functions are highlighted, e.g., in f (_:(a:[])) only a is highlighted, as it is the only variable that is captured, and that can be used in the body of the function.
    • The return type of a function is highlighted.
    • All new variabels are (or should be) highlighted, this includes generators, lambda arguments.
    • Highlighting the = operator in guarded matches correctly, this would be stupidly hard in regexp based syntax.
  • More performant, this is especially seen in longer files.
  • Much, much less code, haskell-mode has accumlated 30,000 lines of code and features to do with all things Haskell related. haskell-ts-mode just keeps the scope to basic major mode stuff, and leaves other stuff to external packages.

6. Motivation

haskell-mode contains nearly 30k lines of code, and is about 30 years old. A lot of features implemented by haskell-mode are now also available in standard Emacs, and have thus become obsolete.

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?

7. Structural navigation

This mode provides strucural navigation, for Emacs 30+.

combs (x:xs) = map (x:) c ++ c
  where c = combs xs

In the above code, if the pointer is right in front of the function definition combs, and you press C-M-f (forward-sexp), it will take you to the end of the second line.

8. Installation

The package is avaiable on NonGnu 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)

9. Customization

9.1. How to disable haskell-ts-mode indentation

(setq haskell-ts-use-indent nil)

9.2. Pretify Symbols mode

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

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

9.3. 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.

9.4. Language server

haskell-ts-mode works with lsp-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"))))

9.5. Prettify sybmols mode

Turning on prettify-symbols-mode does stuff like turn -> to . If you want to prettify words, set haskell-ts-prettify-words to non-nil. This will do stuff like prettify forall into and elem to .

10. TODO

  • Imenu support for functions with multiple definitions.
  • Proper indenting of multiline signatures: the Tree-sitter grammar does not flatten the signatures, but rather leaves them to the standard infix interpretation. This makes indentation hard, as it will mean the only way to check if the the signature node is an ancestor of node at point is to perfom a recursive ascent.

Old versions

haskell-ts-mode-1.0.20250131.124137.tar.lz2025-Jan-317.10 KiB
haskell-ts-mode-1.0.20250126.114656.tar.lz2025-Jan-267.04 KiB
haskell-ts-mode-1.0.20250120.151713.tar.lz2025-Jan-206.79 KiB
haskell-ts-mode-1.0.20250119.81018.tar.lz2025-Jan-196.51 KiB
haskell-ts-mode-1.0.20250113.153114.tar.lz2025-Jan-136.51 KiB
haskell-ts-mode-1.0.20250107.161140.tar.lz2025-Jan-076.49 KiB
haskell-ts-mode-1.0.20241231.74452.tar.lz2024-Dec-316.19 KiB
haskell-ts-mode-1.0.20241108.150811.tar.lz2024-Nov-086.17 KiB
haskell-ts-mode-1.0.20240925.24042.tar.lz2024-Sep-256.31 KiB
haskell-ts-mode-1.0.20240918.43015.tar.lz2024-Sep-186.29 KiB