branch: elpa/haskell-tng-mode commit 9bc086ac37f580dc0fd19ded676dfd0f28771c16 Author: Tseen She <ts33n....@gmail.com> Commit: Tseen She <ts33n....@gmail.com>
easier install --- README.md | 17 +++++++++++++++-- haskell-tng-contrib.el | 2 ++ haskell-tng-mode.el | 25 +++++++++++++++++++++---- haskell-tng-smie.el | 31 ++++++++++++++++++++++++------- 4 files changed, 62 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 594dfb7..5a5219f 100644 --- a/README.md +++ b/README.md @@ -34,14 +34,27 @@ Instead, and following the [anarchical spirit of Haskell](https://www.microsoft. ## Install -Check out the source code repository, type `cask build`, and add to your load path: +Check out the source code repository and add to your load path: ```lisp (add-to-list 'load-path (expand-file-name "~/Projects/haskell-tng.el/")) (require 'haskell-tng-mode) +(require 'haskell-tng-contrib) ;; optional ``` -There are no plans to distribute any other way: this encourages contributor engagement. +## Commands + +### Core + +- `C-c c` compile, prompt on first use + - `C-u C-c c` always prompt + - `C-- C-c c` clean project + - `C-c e` jump to error + +### Contrib + +- `C-c C-C` invoke [`stack2cabal`](https://hackage.haskell.org/package/stack2cabal) +- `C-c C-r f` invoke [`stylish-haskell`](https://hackage.haskell.org/package/stylish-haskell) ## Plan diff --git a/haskell-tng-contrib.el b/haskell-tng-contrib.el index 36a7bf3..b90fbe5 100644 --- a/haskell-tng-contrib.el +++ b/haskell-tng-contrib.el @@ -15,6 +15,7 @@ ;; TODO a generic wrapper around commands that can be downloaded and built using ;; cabal v2-install. +;;;###autoload (defun haskell-tng-contrib:stylish-haskell () "Apply `stylish-haskell' rules." (interactive) @@ -22,6 +23,7 @@ (call-process "stylish-haskell" nil nil nil "-i" buffer-file-name) (revert-buffer t t t)) +;;;###autoload (defun haskell-tng-contrib:stack2cabal () "Prepare a stack project for use with cabal." (interactive) diff --git a/haskell-tng-mode.el b/haskell-tng-mode.el index 3acda8a..cc49625 100644 --- a/haskell-tng-mode.el +++ b/haskell-tng-mode.el @@ -6,14 +6,15 @@ ;; Homepage: https://gitlab.com/tseenshe/haskell-tng-mode ;; Keywords: languages ;; Package-Version: 0.0.1 -;; Package-Requires: ((dash "2.14.1")) +;; Package-Requires: ((bind-key "2.4") (dash "2.16.0")) ;;; Commentary: ;; -;; A modern rewrite of `haskell-mode'. +;; An experimental rewrite of `haskell-mode'. ;; ;;; Code: +(require 'bind-key) (require 'dabbrev) (require 'haskell-tng-syntax) @@ -84,9 +85,25 @@ Load `prettify-symbols-mode' in `haskell-tng-mode-hook'." (setq-local projectile-tags-command "fast-tags -Re --exclude=dist-newstyle .") (setq-local smie-blink-matching-inners nil) ;; c.f. `smie-closer-alist' - (haskell-tng-smie:setup)) + (haskell-tng-smie:setup) -;; TODO: autoload this when I'm ready to use tng instead of regular + (bind-key "<return>" 'haskell-tng-newline haskell-tng-mode-map) + + ;; core compilation loop, supports C-u and C-- prefixes + (bind-key "C-c c" 'haskell-tng-compile haskell-tng-mode-map) + (bind-key "C-c e" 'next-error haskell-tng-mode-map) + + ;; convenient for commands to work from the compile buffer too + (bind-key "C-c c" 'haskell-tng-compile haskell-tng-compilation-mode-map) + (bind-key "C-c e" 'next-error haskell-tng-compilation-mode-map) + + ;; external tools + (bind-key "C-c C" 'haskell-tng-contrib:stack2cabal haskell-tng-mode-map) + (bind-key "C-c C-r f" 'haskell-tng-contrib:stylish-haskell haskell-tng-mode-map) + + ) + +;;;###autoload (progn (add-to-list 'auto-mode-alist '("\\.hs\\'" . haskell-tng-mode)) (modify-coding-system-alist 'file "\\.hs\\'" 'utf-8)) diff --git a/haskell-tng-smie.el b/haskell-tng-smie.el index f6a2b70..f83d975 100644 --- a/haskell-tng-smie.el +++ b/haskell-tng-smie.el @@ -30,7 +30,27 @@ (require 'haskell-tng-font-lock) (require 'haskell-tng-lexer) -;; TODO maybe autodetect? Then delete this user variable +(defun haskell-tng-newline () + "A `newline-and-indent' with a better user experience for `haskell-tng-mode'." + (interactive) + ;; TODO a dynamically bound variable might improve the quality of + ;; 'empty-line-token predictions. + (let ((rem (when (/= (point) (line-end-position)) + (buffer-substring-no-properties (point) (line-end-position))))) + ;; TODO https://debbugs.gnu.org/cgi/bugreport.cgi?bug=36432 + (when rem + (delete-region (point) (line-end-position))) + ;; TODO don't continue line comments if there is code before them + ;; + ;; TODO in-comment indent should observe | haddock markers + (call-interactively #'comment-indent-new-line) + (when rem + (save-excursion + (insert rem))))) + +;; TODO autodetection of indent options + +;; TODO implement haskell-tng-indent-aligntypes (defcustom haskell-tng-indent-aligntypes nil "Whether to align arrows to their parent :: declaration. @@ -44,7 +64,7 @@ foobar :: Monad m :type 'booleanp :group 'haskell-tng) -;; TODO maybe autodetect? Then delete this user variable +;; TODO implement haskell-tng-indent-typelead (defcustom haskell-tng-indent-typelead 3 "Leading spaces in a trailing type signature, relative to type arrows. For example 3 and 1 are respectively: @@ -315,16 +335,13 @@ information, to aid in the creation of new rules." )) (defconst haskell-tng-smie:return - '(comment-indent-new-line + '(haskell-tng-newline + comment-indent-new-line newline-and-indent newline haskell-tng-smie:debug-newline) "Users with custom newlines should add their command.") -;; TODO newline and indent at the beginning of a line should be the same as -;; newline and indent at the end of the previous line. Newline in the middle of -;; a line is trickier. - (defvar-local haskell-tng-smie:indentations nil) (defun haskell-tng-smie:indent-cycle () "When invoked more than once, returns an alternative indentation level."