[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/haskell-tng-mode ceaec13 098/385: groundwork for tab cycli
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/haskell-tng-mode ceaec13 098/385: groundwork for tab cycling |
Date: |
Tue, 5 Oct 2021 23:59:09 -0400 (EDT) |
branch: elpa/haskell-tng-mode
commit ceaec13032ef634ea713745e5a1ac05bd36368fe
Author: Tseen She <ts33n.sh3@gmail.com>
Commit: Tseen She <ts33n.sh3@gmail.com>
groundwork for tab cycling
---
haskell-tng-smie.el | 47 ++++++++++++++++-------------------------
test/haskell-tng-indent-test.el | 32 +++++++++++++++++++---------
2 files changed, 40 insertions(+), 39 deletions(-)
diff --git a/haskell-tng-smie.el b/haskell-tng-smie.el
index 5472934..74d11f8 100644
--- a/haskell-tng-smie.el
+++ b/haskell-tng-smie.el
@@ -101,35 +101,20 @@
(and (not (smie-rule-bolp)) (smie-rule-prev-p "else")
(smie-rule-parent)))))
-;; FIXME tests for indentation, including the cycled choices
-
-;; TODO decide either to set indent-line-function or to wrap around
-;; smie-indent-calculate with
-
-;; (add-hook 'smie-indent-functions
-;; #'haskell-tng:smie-indent nil 'local)
-
-(defvar haskell-tng:smie-indent-nested-call nil)
-
-(defun haskell-tng:smie-indent ()
- (cond
- ;; When we're not in the top-level call to smie-indent-calculate, so just do
- ;; nothing and let the other rules do their job.
- (haskell-tng:smie-indent-nested-call nil)
- ;; When cycling, return the next indentation.
- ((eq this-command last-command)
- (haskell-tng:return-next-stashed-indentation-column))
- ;; When we're in the top-level call to smie-indent-calculate, take control
- ;; and return a non-nil value to prevent the other rules from being used.
- (t
- (let ((haskell-tng:smie-indent-nested-call t)
- (n (haskell-tng:get-number-of-closing-braces-at-bol))
- (indentations ()))
- (dotimes (i n)
- (haskell-tng:tell-lexer-there-are-N-closing-braces-at-bol i)
- (push (smie-indent-calculate) indentations))
- (haskell-tng:stash-indentation-columns indentations)
- (haskell-tng:return-next-stashed-indentation-column)))))
+(defun haskell-tng:indent-cycle ()
+ "Returns the next alternative indentation level from a ring."
+ (when (and
+ (eq major-mode 'haskell-tng-mode) ;; smie-indent-functions is global
+ (eq this-command last-command)
+ (or
+ ;; FIXME detecting double TAB is really hard...
+ ;;(and (message "THIS=%s LAST=%s" this-command last-command) nil)
+ (eq this-command #'indent-for-tab-command)
+ ;; maybe other typical TAB bindings here
+ ))
+ ;; TODO implement
+ (message "CALLING INDENT CYCLE FROM %s" this-command)
+ 2))
(defun haskell-tng-smie:setup ()
(setq-local smie-indent-basic 2)
@@ -142,6 +127,10 @@
'after-change-functions
#'haskell-tng-lexer:state-invalidation)
+ (add-to-list
+ 'smie-indent-functions
+ #'haskell-tng:indent-cycle)
+
(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 52eb640..f0aacd2 100644
--- a/test/haskell-tng-indent-test.el
+++ b/test/haskell-tng-indent-test.el
@@ -34,22 +34,33 @@
(buffer-substring-no-properties
(line-beginning-position)
(- (line-beginning-position 2) 1)))
-(defun next-line-string ()
- (buffer-substring-no-properties
- (line-beginning-position 2)
- (- (line-beginning-position 3) 1)))
(defun haskell-tng-indent-test:newline-indent-insert ()
(let (indents)
(while (not (eobp))
(end-of-line)
(let ((indent (list (current-line-string)))
- (next (next-line-string)))
- (newline-and-indent)
+ alts tmp-this tmp-last)
+ (funcall-interactively #'newline-and-indent)
(push (current-column) indent)
- ;; FIXME alts go here
- (push (reverse indent) indents)
- (kill-whole-line)))
+
+ ;; TODO a better way to get the alts
+ (while (< (length alts) 10)
+ (funcall-interactively #'indent-for-tab-command)
+ (push (current-column) alts))
+
+ (setq indent
+ (delete-dups
+ (append (reverse indent) (reverse alts))))
+
+ (push indent indents)
+ (setq
+ tmp-this this-command
+ tmp-last last-command)
+ (kill-whole-line)
+ (setq
+ this-command tmp-this
+ last-command tmp-last)))
(reverse indents)))
(defun haskell-tng-indent-test:indents-to-string (indents)
@@ -65,7 +76,8 @@ of integer alternative indentations."
(defun haskell-tng-indent-test:indent-to-string (indent)
(let ((line (car indent))
(indent (cadr indent))
- (alts (cddr indent)))
+ (_alts (cddr indent)))
+ ;; FIXME show alts
(list line (concat (s-repeat indent " ") "v"))))
(defun have-expected-newline-indent-insert (file)
- [nongnu] elpa/haskell-tng-mode 6d2d764 094/385: skeleton for indentation tests, (continued)
- [nongnu] elpa/haskell-tng-mode 6d2d764 094/385: skeleton for indentation tests, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 0d04664 115/385: implement batch compilation, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode adb3c50 143/385: better insert indentation suggestions, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode e79577e 132/385: match ghc source paths when compiling, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 8ec4807 145/385: somehow dropped font-lock-extend-region-multiline, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode d3a6a22 147/385: no todos in the test/src dir, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 85f20b1 154/385: indent coproducts, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 3dbb883 013/385: more progress on multiline type expansion, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode c6382e1 036/385: almost got it with imports, then I lost it..., ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode f3e3838 070/385: starting to transcribe the expression table, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode ceaec13 098/385: groundwork for tab cycling,
ELPA Syncer <=
- [nongnu] elpa/haskell-tng-mode 8b6d545 178/385: split all the tests, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 4e1f51c 170/385: indent is deriving aware, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 3ddafce 181/385: disambiguate -> during lexing, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 6b4dca0 189/385: note other build tools, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode cc657a8 197/385: support type alignment options, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode a7098e8 194/385: stylish haskell outputs failures, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 21fe2a0 221/385: fix broken test assertions, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 907255e 026/385: some namespacing, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode e7eaa38 077/385: some ideas for cabal, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode ddd0706 108/385: suggest next line indentation, ELPA Syncer, 2021/10/06