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.20241216.63538.tar (.sig), 2024-Dec-16, 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 treesitter.

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 to open REPL C-c C-c to send code to repl C-M-q Indent the function

4. Features

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

an overview of the features are:

  • Syntax highliting
  • Indentation
  • Imenu support
  • REPL (C-c r in the mode to run)
  • Prettify symbols mode support

5. Comparasion with haskell-mode

The more interesting features are:

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

6. 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 haskells syntax to implement indentation, so I thought why not use tree sitter?

7. Installation

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

8. 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)

8.1. how to disable haskell-ts-mode indentation

(setq haskell-ts-use-indent nil)

8.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)

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

8.4. Language server

haskell-ts-mode now works with lsp-mode, however lsp-haskell still requires on haskell-mode.

To add eglot support, add the following code to you 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. TODO

  • Imenu support for functions with multiple definitions
  • Proper indenting of multiline signatures: the treesitter grammer does not flatten the signautes, rather leaves them to the standard infix interpretatoin. 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.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.20240924.102005.tar.lz2024-Sep-246.29 KiB
haskell-ts-mode-1.0.20240922.24808.tar.lz2024-Sep-226.29 KiB
haskell-ts-mode-1.0.20240920.70721.tar.lz2024-Sep-216.29 KiB
haskell-ts-mode-1.0.20240918.43015.tar.lz2024-Sep-186.29 KiB
haskell-ts-mode-1.0.20240917.55922.tar.lz2024-Sep-176.28 KiB
haskell-ts-mode-1.0.20240914.30703.tar.lz2024-Sep-146.13 KiB
haskell-ts-mode-1.0.20240906.11701.tar.lz2024-Sep-085.89 KiB
haskell-ts-mode-1.0.20240904.65301.tar.lz2024-Sep-045.67 KiB