|
13 | 13 | (setq result (cons (current-column) result)))
|
14 | 14 | (reverse result))))
|
15 | 15 |
|
| 16 | + |
| 17 | +(defun find-indent-and-backtab-positions (lines-above-content &optional prepare-buffer) |
| 18 | + (with-temp-buffer |
| 19 | + (if prepare-buffer |
| 20 | + (funcall prepare-buffer)) |
| 21 | + (dolist (line lines-above-content) |
| 22 | + (insert line) |
| 23 | + (insert "\n")) |
| 24 | + ;; cursor is at the beginning of the second line now |
| 25 | + (let ((result-forward '(0)) |
| 26 | + (result-backward '())) |
| 27 | + (dotimes (i 9) |
| 28 | + (haskell-simple-indent) |
| 29 | + (setq result-forward (cons (current-column) result-forward))) |
| 30 | + (dotimes (i 9) |
| 31 | + (setq result-backward (cons (current-column) result-backward)) |
| 32 | + (haskell-simple-indent-backtab)) |
| 33 | + (setq result-backward (cons (current-column) result-backward)) |
| 34 | + (list (reverse result-forward) result-backward)))) |
| 35 | + |
16 | 36 | (ert-deftest find-indent-positions-1 ()
|
17 | 37 | (should (equal '(5 7 10 19 26 32 40 48 56 64)
|
18 | 38 | (find-indent-positions '("main = do putStrLn \"Hello World!\"")))))
|
|
33 | 53 | (should (equal '(2 4 5 8 16 24 32 40 48 56)
|
34 | 54 | (find-indent-positions '("a b c d e f g h"
|
35 | 55 | " long_streak")))))
|
| 56 | + |
| 57 | +(ert-deftest find-indent-positions-5 () |
| 58 | + (should (equal '(2 4 6 13 15 17 19 24 32 40) |
| 59 | + (find-indent-positions '(" f g e e iirelevant" |
| 60 | + "a b c d" |
| 61 | + " h idden" |
| 62 | + " hidden" |
| 63 | + "" |
| 64 | + " e f g h" |
| 65 | + ""))))) |
| 66 | + |
| 67 | +(ert-deftest find-indent-and-backtab-positions-1 () |
| 68 | + (should (equal '((0 2 4 5 8 16 24 32 40 48) |
| 69 | + (0 2 4 5 8 16 24 32 40 48)) |
| 70 | + ;; Note: haskell-simple-indent-backtab is broken when |
| 71 | + ;; it encounters TABs in source file. |
| 72 | + (find-indent-and-backtab-positions '("a b c d e f g h" |
| 73 | + " long_streak") |
| 74 | + (lambda () |
| 75 | + (setq indent-tabs-mode nil)))))) |
| 76 | + |
| 77 | +(ert-deftest find-indent-and-backtab-positions-1a () |
| 78 | + (should (equal '((0 2 4 5 8 16 24 32 40 48) |
| 79 | + (0 2 4 5 8 16 24 32 40 48)) |
| 80 | + (find-indent-and-backtab-positions '("a b c d e f g h" |
| 81 | + " long_streak"))))) |
| 82 | + |
| 83 | +(ert-deftest find-indent-and-backtab-positions-2 () |
| 84 | + (should (equal '((0 8 10 13 20 24 27 32 35 37) |
| 85 | + (0 8 10 13 20 24 27 32 35 37)) |
| 86 | + (find-indent-and-backtab-positions '("\tx <- return 123 {- This is a comment -}") |
| 87 | + (lambda () |
| 88 | + (setq-local indent-tabs-mode nil)))))) |
| 89 | + |
| 90 | +(ert-deftest find-indent-and-backtab-positions-2a () |
| 91 | + (should (equal '((0 8 10 13 20 24 27 32 35 37) |
| 92 | + (0 8 10 13 20 24 27 32 35 37)) |
| 93 | + (find-indent-and-backtab-positions '("\tx <- return 123 {- This is a comment -}"))))) |
| 94 | + |
| 95 | +(ert-deftest find-indent-and-backtab-positions-3 () |
| 96 | + (should (equal '((0 2 4 6 13 15 17 19 24 32) |
| 97 | + (0 2 4 6 13 15 17 19 24 32)) |
| 98 | + (find-indent-and-backtab-positions '(" f g e e iirelevant" |
| 99 | + "a b c d" |
| 100 | + " h idden x" |
| 101 | + " hidden 4 5" |
| 102 | + "" |
| 103 | + " e f g h" |
| 104 | + "") |
| 105 | + (lambda () |
| 106 | + (setq-local indent-tabs-mode nil)))))) |
| 107 | + |
| 108 | +(ert-deftest find-indent-and-backtab-positions-3a () |
| 109 | + (should (equal '((0 2 4 6 13 15 17 19 24 32) |
| 110 | + (0 2 4 6 13 15 17 19 24 32)) |
| 111 | + (find-indent-and-backtab-positions '(" f g e e iirelevant" |
| 112 | + "a b c d" |
| 113 | + " h idden x" |
| 114 | + " hidden 4 5" |
| 115 | + "" |
| 116 | + " e f g h" |
| 117 | + ""))))) |
0 commit comments