branch: elpa/haskell-tng-mode commit 91a1d0840265ef6104fb543bfb549e157c7d5cc5 Author: Tseen She <ts33n....@gmail.com> Commit: Tseen She <ts33n....@gmail.com>
creating small scenarios for indentation specs --- README.md | 1 + haskell-tng-smie.el | 26 +++++++++++++--------- test/haskell-tng-indent-test.el | 7 +++--- test/src/indentation.hs | 21 ++++++++++++++++++ test/src/indentation.hs.insert.indent | 42 +++++++++++++++++++++++++++++++++++ test/src/indentation.hs.reindent | 42 +++++++++++++++++++++++++++++++++++ 6 files changed, 125 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index b1c9c35..f0b6db3 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,7 @@ Some blue sky features are being considered but may be best as independent proje - identify trivial / helper functions and forward their `edit-definition` to another location. - Code gen - `instance` boilerplate + - record of functions boilerplate - Refactoring - be compatible with [`apply-refact`](https://github.com/mpickering/apply-refact) / [`hlint-refactor-mode`](https://github.com/mpickering/hlint-refactor-mode) - insert explicit list of exports diff --git a/haskell-tng-smie.el b/haskell-tng-smie.el index 06067fe..9c8baa6 100644 --- a/haskell-tng-smie.el +++ b/haskell-tng-smie.el @@ -5,14 +5,20 @@ ;;; Commentary: ;; -;; SMIE precedence table, providing s-expression navigation, and indentation -;; rules. +;; SMIE precedence table and indentation rules. ;; -;; Although SMIE provides the primary indentation suggest (when the user types -;; RETURN), we cycle through alternative candidates on TAB. The philosophy is -;; not to try and get indentation right 100% of the time, but to get it right -;; 90% of the time and make it so easy to fix it that it doesn't get in the -;; way. +;; Although SMIE provides the primary indentation suggestion, we cycle through +;; heuristic alternative candidates on subsequent presses of TAB. +;; +;; The philosophy is not to get indentation right 100% of the time, but to get +;; it right 90% of the time and make it so easy to fix it that it doesn't get +;; in the way. +;; +;; Interactive indentation is ambiguous in a whitespace sensitive language +;; because it is not known if the user wishes to continue the previous line, +;; create a new line at the same level, or close off the block. We try to err +;; on the side of "staying at the same level" (not escaping or closing a +;; previous line) when we can. ;; ;; Users may consult the SMIE manual to customise their indentation rules: ;; https://www.gnu.org/software/emacs/manual/html_mono/elisp.html#SMIE @@ -128,14 +134,14 @@ information, to aid in the creation of new rules." (:after (pcase arg ("where" + ;; TODO `module' doesn't trigger when writing a fresh file, it's coming + ;; up as before/after `{'. (if (smie-rule-parent-p "module") '(column . 0) smie-indent-basic)) ((or "::" "=" "let" "do" "of" "{") smie-indent-basic) )) - - ;; TODO :before rules )) (defconst haskell-tng-smie:return @@ -226,8 +232,6 @@ current line." #'haskell-tng-smie:indent-cycle nil 'local) - ;; TODO alternative to indent-for-tab-command that does alignment - (smie-setup haskell-tng-smie:grammar #'haskell-tng-smie:rules diff --git a/test/haskell-tng-indent-test.el b/test/haskell-tng-indent-test.el index 08da3b0..2734c83 100644 --- a/test/haskell-tng-indent-test.el +++ b/test/haskell-tng-indent-test.el @@ -26,6 +26,8 @@ ;; Test 1 involves a lot of buffer refreshing and will be very slow. (ert-deftest haskell-tng-newline-indent-file-tests () + (should (have-expected-newline-indent-insert (testdata "src/indentation.hs"))) + (should (have-expected-newline-indent-insert (testdata "src/layout.hs"))) (should (have-expected-newline-indent-insert (testdata "src/medley.hs"))) ;; TODO more tests @@ -33,11 +35,10 @@ ) (ert-deftest haskell-tng-reindent-file-tests () + (should (have-expected-reindent-insert (testdata "src/indentation.hs"))) + (should (have-expected-reindent-insert (testdata "src/layout.hs"))) (should (have-expected-reindent-insert (testdata "src/medley.hs"))) - - ;; FIXME a test file specifically for common indentation situations to - ;; define a spec. ) (defun current-line-string () diff --git a/test/src/indentation.hs b/test/src/indentation.hs new file mode 100644 index 0000000..e66d171 --- /dev/null +++ b/test/src/indentation.hs @@ -0,0 +1,21 @@ +-- | Idealised indentation scenarios. +-- +-- Bugs and unexpected behaviour in (re-)indentation may be documented here. +module Indentation where + +-- A basic `do` block using virtual indentation to suggest the whitespace +basic_do = do + -- TODO do should have virtual indentation of 0, so this is at 2 + foo = blah blah blah + -- TODO should suggest that bar is a binding + bar = blah blah + blah -- manual continuation, should be 1st alt TODO + blah -- continue what we were doing, should be the SMIE rule + +-- TODO `do` with manual layout +-- TODO nested `do` + + +-- TODO coproduct definitions, the | should align with = + +-- TODO lists diff --git a/test/src/indentation.hs.insert.indent b/test/src/indentation.hs.insert.indent new file mode 100644 index 0000000..cfb7ced --- /dev/null +++ b/test/src/indentation.hs.insert.indent @@ -0,0 +1,42 @@ +-- | Idealised indentation scenarios. +v 1 +-- +v 1 +-- Bugs and unexpected behaviour in (re-)indentation may be documented here. +v 1 +module Indentation where +v 1 2 + +v 1 +-- A basic `do` block using virtual indentation to suggest the whitespace +v 1 2 +basic_do = do +2 1 v + -- TODO do should have virtual indentation of 0, so this is at 2 +2 1 3 4v + foo = blah blah blah +2 1 3 4v + -- TODO should suggest that bar is a binding +2 1 3 4v + bar = blah blah +2 3 4 1 5v + blah -- manual continuation, should be 1st alt TODO +1 2 v 3 4 + blah -- continue what we were doing, should be the SMIE rule +1 2 v 3 4 + +1 2 v +-- TODO `do` with manual layout +1 2 v 3 +-- TODO nested `do` +1 2 v 3 + +1 2 v + +1 2 v +-- TODO coproduct definitions, the | should align with = +1 2 v + +1 2 v +-- TODO lists +1 2 v \ No newline at end of file diff --git a/test/src/indentation.hs.reindent b/test/src/indentation.hs.reindent new file mode 100644 index 0000000..21edc49 --- /dev/null +++ b/test/src/indentation.hs.reindent @@ -0,0 +1,42 @@ +v +-- | Idealised indentation scenarios. +v 1 +-- +v 1 +-- Bugs and unexpected behaviour in (re-)indentation may be documented here. +v 1 +module Indentation where +v 1 2 + +1 v +-- A basic `do` block using virtual indentation to suggest the whitespace +1 v 2 +basic_do = do +2 1 v 3 + -- TODO do should have virtual indentation of 0, so this is at 2 +2 1 v 3 + foo = blah blah blah +1 v 2 3 + -- TODO should suggest that bar is a binding +v 2 3 1 4 + bar = blah blah +2 3 4 1 5v + blah -- manual continuation, should be 1st alt TODO +1 2 v 3 4 + blah -- continue what we were doing, should be the SMIE rule +1 2 v 3 4 + +1 2 v +-- TODO `do` with manual layout +1 2 v 3 +-- TODO nested `do` +1 2 v 3 + +1 2 v + +1 2 v +-- TODO coproduct definitions, the | should align with = +1 2 v + +1 2 v +-- TODO lists \ No newline at end of file