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