branch: elpa/haskell-ts-mode commit e6ee63c7134970a943af99da1bf30804f172aa66 Merge: 1c017f310e 44d5bdb92f Author: Pranshu Sharma <pranshusharma...@gmail.com> Commit: Pranshu Sharma <pranshusharma...@gmail.com>
Merge branch 'indent' --- README.org | 5 +++-- haskell.el | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/README.org b/README.org index 4c2932d1fb..cd1d5a96e8 100644 --- a/README.org +++ b/README.org @@ -1,9 +1,10 @@ -A WIP haskell mode that requires treesitter and offers syntax highlighting and imenu, and a comint mode. +A WIP haskell mode that requires treesitter and offers basic +indentation, syntax highlighting and imenu, and a comint repl. * TODO -- Indentation - Autoloading - Syntax table - Fix treesit-font-lock-feature-list - Comment problem +- Better imenu supprt diff --git a/haskell.el b/haskell.el index 2881845395..dade0e157a 100644 --- a/haskell.el +++ b/haskell.el @@ -10,7 +10,8 @@ :feature 'keyword `(["module" "import" "data" "let" "where" "case" "if" "then" "else" "of" "do" "in" "instance"] - @font-lock-keyword-face) + @font-lock-keyword-face + ["(" ")" "[" "]"] @font-lock-operator-face) :language 'haskell :feature 'type `((type) @font-lock-type-face @@ -40,14 +41,60 @@ :feature 'str `((char) @font-lock-string-face (string) @font-lock-string-face))) + +;; TODO change to defvar +(setq haskell-ts-indent-rules + `((haskell + ((node-is "comment") column-0 0) + ((parent-is "haskell") column-0 0) + ((parent-is "declarations") column-0 0) + ((parent-is "imports") column-0 0) + ((parent-is "local_binds") prev-sibling 0) + ((parent-is "apply") parent 2) + ;; Match + ((match "match" nil nil 2 2) parent 2) + ((node-is "match") prev-sibling 0) + ;; Do Hg + ((parent-is "do") prev-sibling 0) + ((match nil "do" nil 1 1) great-grand-parent 2) + ((node-is "alternatives") grand-parent 0) + ((parent-is "alternatives") grand-parent 2) + + ;; Infix + ((node-is "infix") grand-parent 2) + ((parent-is "infix") parent 0) + ;; Where PS TODO 2nd + + ((lambda (node parent bol) + (string= "where" (treesit-node-type (treesit-node-prev-sibling node)))) + (lambda (a b c) + (+ 1 (treesit-node-start (treesit-node-prev-sibling b)))) + 3) + ((parent-is "local_binds") prev-sibling 2) + ((node-is "^where$") parent 2) + ;; If statement + ((node-is "then") parent 2) + ((node-is "else") parent 2) + + ;; lists + ((node-is "^in$") parent 2) + ((lambda (a b c) + (save-excursion + (goto-char c) + (re-search-forward "^[ \t]*$" (line-end-position) t))) + prev-adaptive-prefix 0)))) + + ;;;###autoload (define-derived-mode haskell-ts-mode prog-mode "haskell ts mode" - "Major mode for Haskell files using tree-sitter" + "Mjaor mode for Haskell files using tree-sitter" :group 'haskell (unless (treesit-ready-p 'haskell) (error "Tree-sitter for Haskell is not available")) (treesit-parser-create 'haskell) (setq-local treesit-defun-type-regexp "\\(?:\\(?:function\\|struct\\)_definition\\)") + ;; Indent + (setq-local treesit-simple-indent-rules haskell-ts-indent-rules) ;; Misc (setq-local comment-start "--") (setq-local indent-tabs-mode nil) @@ -107,4 +154,4 @@ (define-key haskell-ts-mode-map (kbd "C-c c") 'haskell-compile-region-and-go) (define-key haskell-ts-mode-map (kbd "C-c r") 'run-haskell) -(add-to-list ' auto-mode-alist '("\\.hs\\'" . haskell-ts-mode)) +;; (add-to-list 'auto-mode-alist '("\\.hs\\'" . haskell-ts-mode))