README.org
author Pranshu Sharma <pranshu@bauherren.ovh>
Thu, 12 Dec 2024 23:29:55 +1000
changeset 2 9272314a1c65
parent 0 4d355b59e2a3
permissions -rw-r--r--
Fixed up readme and some typos, and added .elpaignore .elpaignore: Added the file README.org: Formatting changes haskell-ts-mode.el: Remvoed eglot support by default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
     3
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
     4
* haskell-ts-mode
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
     5
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
     6
A haskell mode that uses treesitter.
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
     7
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
     8
* Screenshot
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
     9
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    10
[[./ss.png]]
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    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
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    14
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    15
* Usage
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    16
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    17
=C-c C-r= to open REPL
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    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
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    20
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    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
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    27
an overview of the features are:
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    28
- Syntax highliting
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    29
- Indentation
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    30
- Imenu support
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    31
- REPL (C-c r in the mode to run)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    32
- Prettify symbols mode support
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    33
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    34
* Comparasion with haskell-mode
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    35
The more interesting features are:
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    36
- Logical syntax highlighting:
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    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
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    39
    variable that is captured that can be used in body of function
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    40
  - The return type of a function is highlighted
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    41
  - All new variabels are(or should be) highlighted, this includes
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    42
    generators, lambda args.
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    43
  - highlighting the '=' operaotr in guarded matches correctly, this
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    44
    would be stupidly hard in regexp based syntax
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    45
- More perfomant, this is especially seen in longer files
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    46
- Much much less code, haskell mode has accumlated 30,000 lines of
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    47
  features to do with all things haskell related, this mode just keeps
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    48
  the scope to basic major mode stuff, and leaves other stuff for
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    49
  external packages.
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    50
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    51
* Motivation
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    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
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    54
about 30 years old.  Therefore, a lot of stuff emacs has gained the
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    55
ability to do in those years, haskell-mode already has implemented
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    56
them.
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    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
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    59
these problems. However because of haskell's syntax, it too became
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    60
very complex and required a web of dependencies.
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    61
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    62
Both these modes ended up practically parsing haskells syntax to
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    63
implement indentation, so I thought why not use tree sitter?
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    64
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    65
* Installation
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    66
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    67
The package is avaiable on elpa, you can install it using:
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    68
M-x package-install RET haskell-ts-mode RET
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    69
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    70
#+begin_src elisp
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    71
(add-to-list 'load-path "path/to/haskell-ts-mode")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    72
(require 'haskell-ts-mode)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    73
#+end_src
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    74
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    75
* Customization
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    76
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    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
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    79
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    80
If you want to highlight signature declarations (disabled by default),
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    81
add the following to your init file:
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    82
#+begin_src emacs-lisp
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    83
(setq haskell-ts-highlight-signature t)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    84
#+end_src
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    85
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    86
** how to disable haskell-ts-mode indentation
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    87
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    88
#+begin_src emacs-lisp
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    89
(setq haskell-ts-use-indent nil)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    90
#+end_src
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    91
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    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
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    94
unicode alternatives.
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    95
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    96
#+begin_src emacs-lisp
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    97
(add-hook 'haskell-ts-mode 'prettify-symbols-mode)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    98
#+end_src
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    99
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   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
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   103
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   104
** Language server
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   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
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   109
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   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
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   115
#+end_src
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   116
2
9272314a1c65 Fixed up readme and some typos, and added .elpaignore
Pranshu Sharma <pranshu@bauherren.ovh>
parents: 0
diff changeset
   117
* TODO
0
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   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.