branch: elpa/haskell-tng-mode commit ceaec13032ef634ea713745e5a1ac05bd36368fe Author: Tseen She <ts33n....@gmail.com> Commit: Tseen She <ts33n....@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)