README.org
author Pranshu Sharma <pranshu@bauherren.ovh>
Thu, 12 Dec 2024 22:06:43 +1000
changeset 0 4d355b59e2a3
child 2 9272314a1c65
permissions -rw-r--r--
Inital commit
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
     1
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
     2
* haskell-ts-mode
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
     3
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
     4
A haskell mode that uses treesitter.
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
     5
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
     6
* Screenshot
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
     7
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
     8
[[./ss.png]]
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
     9
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    10
The above screenshot is indented coloured using haskell-ts-mode, with
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    11
prettify-symbols-mode enabled.
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    12
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    13
* Usage
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    14
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    15
=C-c C-r= to open REPL
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    16
=C-c C-c= to send code to repl
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    17
=C-M-q=   Indent paragraph
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    18
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    19
* Features
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    20
an overview of the features are:
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    21
- Syntax highliting
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    22
- Indentation
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    23
- Imenu support
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    24
- REPL (C-c r in the mode to run)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    25
- Prettify symbols mode support
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    26
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    27
* Comparasion with haskell-mode
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    28
The more interesting features are:
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    29
- Logical syntax highlighting:
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    30
  - Only arguments that can be used in functions are highlighted, eg
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    31
    in `f (_:(a:[])) only 'a' is highlighted, as it is the only
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    32
    variable that is captured that can be used in body of function
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    33
  - The return type of a function is highlighted
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    34
  - All new variabels are(or should be) highlighted, this includes
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    35
    generators, lambda args.
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    36
  - highlighting the '=' operaotr in guarded matches correctly, this
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    37
    would be stupidly hard in regexp based syntax
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    38
- Unlike haskell-mode, quasi quotes are understood and do not confuse
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    39
  the mode, thanks to treesitter
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    40
- Predictable (but less powerful) indentation: haskell-mode's
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    41
  indentation works in a cyclical way, it cycles through where you
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    42
  might want indentation.  haskell-ts-mode, meanwhile relies on you to
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    43
  set the concrete syntax tree changing whitespace.
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    44
- More perfomant, this is especially seen in longer files
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    45
- Much much less code, haskell mode has accumlated 30,000 lines of
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    46
  features to do with all things haskell related, this mode just keeps
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    47
  the scope to basic major mode stuff, and leaves other stuff for
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    48
  external packages.
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    49
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    50
* Motivation
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    51
  
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    52
haskell-mode contains nearly 30k lines of code, and is
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    53
about 30 years old.  Therefore, a lot of stuff emacs has gained the
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    54
ability to do in those years, haskell-mode already has implemented
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    55
them.
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    56
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    57
In 2018, a mode called haskell-tng-mode was made to solve some of
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    58
these problems. However because of haskell's syntax, it too became
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    59
very complex and required a web of dependencies.
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    60
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    61
Both these modes ended up practically parsing haskells syntax to
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    62
implement indentation, so I thought why not use tree sitter?
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    63
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    64
* Installation
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    65
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    66
The package is avaiable on elpa, you can install it using:
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    67
M-x package-install RET haskell-ts-mode RET
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    68
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    69
#+begin_src elisp
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    70
(add-to-list 'load-path "path/to/haskell-ts-mode")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    71
(require 'haskell-ts-mode)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    72
#+end_src
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    73
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    74
* Customization
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    75
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    76
If colour is too much or too less for you, adjust
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    77
treesit-font-lock-level accordingly.
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    78
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    79
If you want to highlight signature declarations (disabled by default),
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    80
add the following to your init file:
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    81
#+begin_src emacs-lisp
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    82
(setq haskell-ts-highlight-signature t)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    83
#+end_src
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    84
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    85
** how to disable haskell-ts-mode indentation
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    86
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    87
#+begin_src emacs-lisp
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    88
(setq haskell-ts-use-indent nil)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    89
#+end_src
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    90
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    91
** Pretify symbols mode
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    92
prettify symbols mode can be used to replace common symbols with
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    93
unicode alternatives.
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    94
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    95
#+begin_src emacs-lisp
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    96
(add-hook 'haskell-ts-mode 'prettify-symbols-mode)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    97
#+end_src
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    98
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    99
** Adjusting font lock level
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   100
set haskell-ts-font-lock-level accordingly.
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   101
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   102
** Language server
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   103
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   104
haskell-ts-mode is compatiable with lsp-haskell.
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   105
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   106
To enable eglot support, use the following code in your init.el:
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   107
#+begin_src emacs-lisp
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   108
(with-eval-after-load 'eglot (haskell-ts-setup-eglot))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   109
#+end_src
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   110
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   111
* TODO and limitations
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   112
- Imenu support for functions with multiple definitions
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   113
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   114
Limitations: _Proper indenting of multiline signatures_: the
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   115
treesitter grammer does not flatten the signautes, rather leaves them
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   116
to the standard infix interpretatoin. This makes indentation hard, as
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   117
it will mean the only way to check if the the signature node is an
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   118
ancestor of node at point is to perfom a recursive ascent, which is
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   119
horrible for perfomance.