haskell-ts-mode.el
author Pranshu Sharma <pranshu@bauherren.ovh>
Thu, 12 Dec 2024 22:06:43 +1000
changeset 0 4d355b59e2a3
child 1 27f2627e9f2f
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
;;; haskell-ts-mode.el --- A treesit based major mode for haskell -*- lexical-binding:t -*-
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
     2
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
     3
;; Copyright (C) 2024  Pranshu Sharma
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
     4
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
     5
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
     6
;; Author: Pranshu Sharma <pranshusharma366 at gmail>
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
     7
;; URL: https://codeberg.org/pranshu/haskell-ts-mode
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
     8
;; Package-Requires: ((emacs "29.3"))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
     9
;; Version: 1
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    10
;; Keywords: languages, haskell
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    11
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    12
;; This program is free software; you can redistribute it and/or modify
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    13
;; it under the terms of the GNU General Public License as published by
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    14
;; the Free Software Foundation, either version 3 of the License, or
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    15
;; (at your option) any later version.
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    16
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    17
;; This program is distributed in the hope that it will be useful,
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    18
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    19
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    20
;; GNU General Public License for more details.
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    21
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    22
;; You should have received a copy of the GNU General Public License
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    23
;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    24
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    25
;;; Commentary:
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    26
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    27
;; This is a major mode that uses treesitter to provide all the basic
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    28
;; major mode stuff, like indentation, font lock, etc...
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    29
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    30
;;; Code:
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    31
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    32
(require 'comint)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    33
(require 'treesit)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    34
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    35
(declare-function treesit-parser-create "treesit.c")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    36
(declare-function treesit-node-start "treesit.c")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    37
(declare-function treesit-node-parent "treesit.c")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    38
(declare-function treesit-node-prev-sibling "treesit.c")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    39
(declare-function treesit-node-next-sibling "treesit.c")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    40
(declare-function treesit-node-end "treesit.c")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    41
(declare-function treesit-node-child "treesit.c")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    42
(declare-function treesit-node-type "treesit.c")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    43
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    44
(defgroup haskell-ts-mode nil
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    45
  "Group that contains haskell-ts-mode variables"
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    46
  :group 'langs)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    47
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    48
(defvar haskell-ts-font-lock-feature-list
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    49
  `((comment str pragma parens)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    50
    (type definition function args)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    51
    (match keyword)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    52
    (otherwise signature type-sig)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    53
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    54
(defcustom haskell-ts-use-indent t
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    55
  "Set to non-nil to use the indentation provided by haskell-ts-mode"
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    56
  :group 'haskell-ts-mode
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    57
  :type 'boolean)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    58
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    59
(defcustom haskell-ts-font-lock-level 4
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    60
  "Level of font lock, 1 for minimum highlghting and 4 for maximum."
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    61
  :group 'haskell-ts-mode
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    62
  :type 'integer)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    63
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    64
(defvar haskell-ts-prettify-symbols-alist
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    65
  '(("\\" . "λ")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    66
    ("/=" . "≠")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    67
    ("->" . "→")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    68
    ("=>" . "⇒")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    69
    ("<-" . "←")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    70
    ("<=" . "≥")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    71
    (">=" . "≤")))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    72
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    73
(defvar haskell-ts-font-lock
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    74
  (treesit-font-lock-rules
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    75
   :language 'haskell
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    76
   :feature 'keyword
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    77
   `(["module" "import" "data" "let" "where" "case" "type"
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    78
      "if" "then" "else" "of" "do" "in" "instance" "class"]
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    79
     @font-lock-keyword-face)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    80
   :language 'haskell
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    81
   :feature 'otherwise
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    82
   :override t
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    83
   `(((match (guards guard: (boolean (variable) @font-lock-keyword-face)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    84
      (:match "otherwise" @font-lock-keyword-face)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    85
   :language 'haskell
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    86
   :feature 'type-sig
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    87
   "(signature (binding_list (variable) @font-lock-doc-markup-face))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    88
    (signature (variable) @font-lock-doc-markup-face)"
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    89
   :language 'haskell
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    90
   :feature 'args
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    91
   :override 'keep
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    92
   (concat
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    93
    "(function (infix left_operand: (_) @haskell-ts--fontify-arg))"
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    94
    "(function (infix right_operand: (_) @haskell-ts--fontify-arg))"
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    95
    "(generator . (_) @haskell-ts--fontify-arg)"
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    96
    "(bind (as (variable) . (_) @haskell-ts--fontify-arg))"
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    97
    "(patterns) @haskell-ts--fontify-arg")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    98
   :language 'haskell
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
    99
   :feature 'type
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   100
   `((type) @font-lock-type-face
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   101
     (constructor) @font-lock-type-face)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   102
   :language 'haskell
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   103
   :override t
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   104
   :feature 'signature
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   105
   `((signature (function) @haskell-ts--fontify-type)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   106
     (context (function) @haskell-ts--fontify-type))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   107
   :language 'haskell
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   108
   :feature 'match
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   109
   `((match ("|" @font-lock-doc-face) ("=" @font-lock-doc-face))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   110
     (list_comprehension ("|" @font-lock-doc-face
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   111
			  (qualifiers (generator "<-" @font-lock-doc-face))))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   112
     (match ("->" @font-lock-doc-face)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   113
   :language 'haskell
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   114
   :feature 'comment
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   115
   `(((comment) @font-lock-comment-face)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   116
     ((haddock) @font-lock-doc-face))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   117
   :language 'haskell
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   118
   :feature 'pragma
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   119
   `((pragma) @font-lock-preprocessor-face
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   120
     (cpp) @font-lock-preprocessor-face)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   121
   :language 'haskell
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   122
   :feature 'str
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   123
   :override t
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   124
   `((char) @font-lock-string-face
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   125
     (string) @font-lock-string-face
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   126
     (quasiquote (quoter) @font-lock-type-face)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   127
     (quasiquote (quasiquote_body) @font-lock-preprocessor-face))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   128
   :language 'haskell
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   129
   :feature 'parens
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   130
   :override t
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   131
   `(["(" ")" "[" "]"] @font-lock-operator-face
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   132
     (infix operator: (_) @font-lock-operator-face))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   133
   :language 'haskell
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   134
   :feature 'function
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   135
   :override t
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   136
   `((function name: (variable) @font-lock-function-name-face)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   137
     (function (infix (operator)  @font-lock-function-name-face))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   138
     (declarations (type_synomym (name) @font-lock-function-name-face))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   139
     (bind (variable) @font-lock-function-name-face)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   140
     (function (infix (infix_id (variable) @font-lock-function-name-face)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   141
     (bind (as (variable) @font-lock-function-name-face))))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   142
  "A function that returns the treesit font lock lock settings for haskell.")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   143
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   144
(defun haskell-ts--stand-alone-parent (_ parent bol)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   145
  (save-excursion
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   146
    (goto-char (treesit-node-start parent))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   147
    (let ((type (treesit-node-type parent)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   148
      (if (and (not bol)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   149
	       (or (looking-back "^[ \t]*" (line-beginning-position))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   150
		   (seq-some
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   151
		    (lambda (kw) 
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   152
		      (string= type kw))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   153
		    '("when" "where" "do" "let" "local_binds" "function"))))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   154
	  (treesit-node-start parent)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   155
	(haskell-ts--stand-alone-parent 1 (funcall
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   156
					   (if bol 'treesit-node-parent 'identity)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   157
					   (treesit-node-parent parent))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   158
					nil)))))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   159
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   160
(defvar haskell-ts--ignore-types
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   161
  (regexp-opt '("comment" "cpp" "haddock"))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   162
  "Node types that will be ignored by indentation.")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   163
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   164
(defvar haskell-ts-indent-rules
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   165
  (let* ((p-sib
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   166
	  (lambda (node arg)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   167
	    (let* ((func (if arg
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   168
			     'treesit-node-prev-sibling
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   169
			   'treesit-node-next-sibling))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   170
		   (n (funcall func	 node)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   171
	      (while (and n (string-match haskell-ts--ignore-types
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   172
					  (treesit-node-type n)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   173
		(setq n (funcall func n)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   174
	      n)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   175
	 (p-prev-sib
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   176
	  (lambda (node _ _) (treesit-node-start (funcall p-sib node t))))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   177
	 (p-n-prev (lambda (node) (funcall p-sib node t)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   178
	 (parent-first-child (lambda (_ parent _)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   179
			       (treesit-node-start (treesit-node-child parent 0)))))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   180
    `((haskell
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   181
       ((node-is "^cpp$") column-0 0)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   182
       ((parent-is "^comment$") column-0 0)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   183
       ((parent-is "^haddock$") column-0 0)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   184
       ((parent-is "^imports$") column-0 0)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   185
       ;; Infix
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   186
       ((n-p-gp nil "infix" "infix")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   187
	(lambda (_ node _)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   188
	  (let ((first-inf nil))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   189
	    (while (string= "infix"
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   190
			    (treesit-node-type
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   191
			     (setq node (treesit-node-parent node))))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   192
	      (setq first-inf node))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   193
	    (funcall ,parent-first-child nil first-inf nil)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   194
	0)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   195
       ((node-is "^infix$") ,parent-first-child 0)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   196
       
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   197
       ;; Lambda
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   198
       ((parent-is "^lambda\\(_case\\)?$") standalone-parent 2)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   199
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   200
       ((parent-is "^class_declarations$") prev-sibling 0)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   201
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   202
       ((node-is "^where$") parent 2)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   203
       
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   204
       ;; in
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   205
       ((node-is "^in$") parent 0)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   206
       
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   207
       ((parent-is "qualifiers") parent 0)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   208
       
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   209
       ;; list
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   210
       ((node-is "^]$") parent 0)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   211
       ((parent-is "^list$") standalone-parent 2)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   212
       
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   213
       ;; If then else
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   214
       ((node-is "^then$") parent 2)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   215
       ((node-is "^else$") parent 2)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   216
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   217
       ((parent-is "^apply$") haskell-ts--stand-alone-parent 1)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   218
       ((node-is "^quasiquote$") grand-parent 2)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   219
       ((parent-is "^quasiquote_body$") (lambda (_ _ c) c) 0)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   220
       ((lambda (node parent bol)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   221
	  (when-let ((n (treesit-node-prev-sibling node)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   222
	    (while (string= "comment" (treesit-node-type n))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   223
	      (setq n (treesit-node-prev-sibling n)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   224
	    (string= "do" (treesit-node-type n))))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   225
	haskell-ts--stand-alone-parent
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   226
	3)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   227
       ((parent-is "^do$") ,p-prev-sib 0)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   228
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   229
       ((parent-is "^alternatives$") ,p-prev-sib 0)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   230
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   231
       ;; prev-adaptive-prefix is broken sometimes
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   232
       (no-node
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   233
	(lambda (_ _ _)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   234
	  (save-excursion
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   235
	    (goto-char (line-beginning-position 0))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   236
	    (back-to-indentation)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   237
	    (point)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   238
	0)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   239
       
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   240
       ((parent-is "^data_constructors$") parent 0)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   241
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   242
       ;; where
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   243
       ((lambda (node _ _)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   244
	  (let ((n (treesit-node-prev-sibling node)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   245
	    (while (string= "comment" (treesit-node-type n))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   246
	      (setq n (treesit-node-prev-sibling n)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   247
	    (string= "where" (treesit-node-type n))))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   248
	
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   249
	(lambda (_ b _)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   250
	  (+ 1 (treesit-node-start (treesit-node-prev-sibling b))))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   251
	3)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   252
       ((parent-is "local_binds\\|instance_declarations") ,p-prev-sib 0)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   253
       
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   254
       ;; Match
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   255
       ((lambda (node _ _)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   256
	  (and (string= "match" (treesit-node-type node))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   257
	       (string-match (regexp-opt '("patterns" "variable"))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   258
			     (treesit-node-type (funcall ,p-n-prev node)))))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   259
	standalone-parent 2)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   260
       
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   261
       ((node-is "match") ,p-prev-sib 0)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   262
       ((parent-is "match") standalone-parent 2)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   263
       
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   264
       ((parent-is "^haskell$") column-0 0)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   265
       ((parent-is "^declarations$") column-0 0)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   266
       
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   267
       ((parent-is "^record$") standalone-parent 2)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   268
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   269
       ((parent-is "^exports$")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   270
	(lambda (_ b _) (treesit-node-start (treesit-node-prev-sibling b)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   271
	0)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   272
       ((n-p-gp nil "signature" "foreign_import") grand-parent 3)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   273
       ((parent-is "^case$") standalone-parent 4)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   274
       ((node-is "^alternatives$")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   275
	(lambda (_ b _)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   276
	  (treesit-node-start (treesit-node-child b 0)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   277
	2)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   278
       ((node-is "^comment$")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   279
	;; Indenting comments by priorites:
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   280
	;; 1. next relevent sibling if exists
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   281
	;; 2. previous relevent sibling if exists
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   282
	;; 3. parent
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   283
	;; (relevent means type not it haskell-ts--ignore-types)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   284
	(lambda (node parent _)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   285
	  (if-let ((next-sib (funcall ,p-sib node nil)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   286
	      (treesit-node-start next-sib)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   287
	    (if-let ((prev-sib (funcall ,p-prev-sib node nil nil)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   288
		prev-sib
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   289
	      (treesit-node-start parent))))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   290
	0)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   291
       ;; Backup
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   292
       (catch-all parent 2)))))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   293
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   294
;; Copied from haskell-tng-mode, changed a bit
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   295
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   296
(defvar haskell-ts-mode-syntax-table
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   297
      (let ((table (make-syntax-table)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   298
	;; The defaults are mostly fine
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   299
	(mapc
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   300
	 (lambda (ls)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   301
	   (mapc
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   302
	    (lambda (char)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   303
	      (modify-syntax-entry char (car ls) table))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   304
	    (cdr ls)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   305
	 '(("_" ?! ?_)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   306
	   ("w" ?')
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   307
	   ;; Haskell has some goofy comment enders like C-q C-l
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   308
	   (">" 13 10 12 11)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   309
	   ("_ 123" ?-)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   310
	   ("(}1nb" ?\{)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   311
	   ("){4nb" ?\})
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   312
	   ("<" ?#)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   313
	   (">" ?\n)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   314
	   ;; Special operaters
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   315
	   ("." ?\, ?\; ?@)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   316
	   ("\"" ?\")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   317
	   ("$`"  ?\`)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   318
	table))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   319
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   320
(defmacro haskell-ts-imenu-name-function (check-func)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   321
  `(lambda (node)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   322
     (let ((nn (treesit-node-child node 0 node)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   323
	 (if (funcall ,check-func node)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   324
	 (if (string= (treesit-node-type nn) "infix")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   325
	     (treesit-node-text (treesit-node-child nn 1))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   326
	     (haskell-ts-defun-name node))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   327
       nil))))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   328
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   329
(defun haskell-ts-indent-defun (pos)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   330
  "Indent the current function."
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   331
  (interactive "d")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   332
  (let ((node (treesit-node-at pos)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   333
    (while (not (string-match
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   334
		 "^declarations$\\|haskell"
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   335
		 (treesit-node-type (treesit-node-parent node))))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   336
      (setq node (treesit-node-parent node)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   337
    (indent-region (treesit-node-start node) (treesit-node-end node))))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   338
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   339
(defvar haskell-ts-mode-map
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   340
  (let ((km (make-sparse-keymap)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   341
    (define-key km (kbd "C-c C-c") 'haskell-ts-compile-region-and-go)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   342
    (define-key km (kbd "C-c C-r") 'haskell-ts-run-haskell)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   343
    (define-key km (kbd "C-M-q") 'haskell-ts-indent-defun) ; For those who don't have emacs 30
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   344
    km)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   345
  "Map for haskell-ts-mode.")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   346
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   347
;;;###autoload
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   348
(define-derived-mode haskell-ts-mode prog-mode "haskell ts mode"
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   349
  "Major mode for Haskell files using tree-sitter."
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   350
  (unless (treesit-ready-p 'haskell)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   351
    (error "Tree-sitter for Haskell is not available"))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   352
  (treesit-parser-create 'haskell)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   353
  (setq-local treesit-defun-type-regexp "\\(?:\\(?:function\\|struct\\)_definition\\)")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   354
  ;; Indent
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   355
  (when haskell-ts-use-indent
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   356
    (setq-local treesit-simple-indent-rules haskell-ts-indent-rules)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   357
    (setq-local indent-tabs-mode nil))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   358
  ;; Comment
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   359
  (setq-local comment-start "-- ")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   360
  (setq-local comment-use-syntax t)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   361
  (setq-local comment-start-skip "\\(?: \\|^\\)-+")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   362
  ;; Elecric
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   363
  (setq-local electric-pair-pairs
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   364
	      '((?` . ?`) (?\( . ?\)) (?{ . ?}) (?\" . ?\") (?\[ . ?\])))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   365
  ;; Nav
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   366
  (setq-local treesit-defun-name-function 'haskell-ts-defun-name)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   367
  (setq-local treesit-defun-type-regexp
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   368
	      ;; Since haskell is strict functional, any 2nd level
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   369
	      ;; entity is defintion
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   370
	      (cons ".+"
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   371
		    (lambda (node)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   372
		      (and (not (string-match haskell-ts--ignore-types (treesit-node-type node)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   373
			   (string= "declarations" (treesit-node-type (treesit-node-parent node)))))))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   374
  (setq-local prettify-symbols-alist haskell-ts-prettify-symbols-alist)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   375
  ;; Imenu
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   376
  (setq-local treesit-simple-imenu-settings
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   377
	      `((nil haskell-ts-imenu-func-node-p nil
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   378
		     ,(haskell-ts-imenu-name-function #'haskell-ts-imenu-func-node-p))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   379
		("Signatures.." haskell-ts-imenu-sig-node-p nil
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   380
		 ,(haskell-ts-imenu-name-function #'haskell-ts-imenu-sig-node-p))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   381
		("Data..." haskell-ts-imenu-data-type-p nil
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   382
		 (lambda (node)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   383
		   (treesit-node-text (treesit-node-child node 1))))))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   384
  ;; font-lock
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   385
  (setq-local treesit-font-lock-level haskell-ts-font-lock-level)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   386
  (setq-local treesit-font-lock-settings haskell-ts-font-lock)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   387
  (setq-local treesit-font-lock-feature-list
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   388
	      haskell-ts-font-lock-feature-list)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   389
  (treesit-major-mode-setup))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   390
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   391
(defun haskell-ts--fontify-arg (node &optional _ _ _)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   392
  (if (string= "variable" (treesit-node-type node))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   393
      (put-text-property
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   394
       (treesit-node-start node)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   395
       (treesit-node-end node)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   396
       'face font-lock-variable-name-face)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   397
    (mapc 'haskell-ts--fontify-arg (treesit-node-children node))))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   398
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   399
(defun haskell-ts--fontify-type (node &optional _ _ _)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   400
  (let ((last-child (treesit-node-child node -1)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   401
    (if (string= (treesit-node-type last-child) "function")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   402
	(haskell-ts--fontify-type last-child)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   403
      (put-text-property
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   404
       (treesit-node-start last-child)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   405
       (treesit-node-end last-child)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   406
       'face font-lock-variable-name-face))))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   407
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   408
(defun haskell-ts-imenu-node-p (regex node)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   409
  (and (string-match-p regex (treesit-node-type node))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   410
       (string= (treesit-node-type (treesit-node-parent node)) "declarations")))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   411
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   412
(defun haskell-ts-imenu-func-node-p (node)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   413
  (haskell-ts-imenu-node-p "function\\|bind" node))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   414
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   415
(defun haskell-ts-imenu-sig-node-p (node)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   416
  (haskell-ts-imenu-node-p "signature" node))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   417
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   418
(defun haskell-ts-imenu-data-type-p (node)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   419
  (haskell-ts-imenu-node-p "data_type" node))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   420
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   421
(defun haskell-ts-defun-name (node)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   422
  (treesit-node-text (treesit-node-child node 0)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   423
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   424
(defun haskell-ts-compile-region-and-go (start end)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   425
  "Compile the text from START to END in the haskell proc."
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   426
  (interactive "r")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   427
  (let ((hs (haskell-ts-haskell-session)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   428
    (comint-send-string hs ":{\n")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   429
    (comint-send-region hs start end)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   430
    (comint-send-string hs "\n:}\n")))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   431
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   432
(defun haskell-ts-run-haskell()
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   433
  (interactive)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   434
  (pop-to-buffer-same-window
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   435
   (if (comint-check-proc "*haskell*")
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   436
       "*haskell*"
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   437
     (make-comint "haskell" "ghci" nil buffer-file-name))))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   438
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   439
(defun haskell-ts-haskell-session ()
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   440
  (get-buffer-process "*haskell*"))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   441
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   442
(defvar eglot-server-programs)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   443
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   444
(defun haskell-ts-setup-eglot()
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   445
  (interactive)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   446
  (add-to-list 'eglot-server-programs
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   447
	       '(haskell-ts-mode . ("haskell-language-server-wrapper" "--lsp"))))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   448
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   449
(when (treesit-ready-p 'haskell)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   450
  (add-to-list 'auto-mode-alist '("\\.hs\\'" . haskell-ts-mode)))
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   451
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   452
(provide 'haskell-ts-mode)
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   453
4d355b59e2a3 Inital commit
Pranshu Sharma <pranshu@bauherren.ovh>
parents:
diff changeset
   454
;;; haskell-ts-mode.el ends here