[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/haskell-tng-mode 25b15eb 102/385: indentation alternatives
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/haskell-tng-mode 25b15eb 102/385: indentation alternatives wiring |
Date: |
Tue, 5 Oct 2021 23:59:10 -0400 (EDT) |
branch: elpa/haskell-tng-mode
commit 25b15ebd36d84fa751ca76d2f23e221d6df4ac02
Author: Tseen She <ts33n.sh3@gmail.com>
Commit: Tseen She <ts33n.sh3@gmail.com>
indentation alternatives wiring
---
haskell-tng-smie.el | 60 ++++++++++++++++++++++++-----------------------------
1 file changed, 27 insertions(+), 33 deletions(-)
diff --git a/haskell-tng-smie.el b/haskell-tng-smie.el
index df284b0..6139fbc 100644
--- a/haskell-tng-smie.el
+++ b/haskell-tng-smie.el
@@ -101,41 +101,35 @@
(and (not (smie-rule-bolp)) (smie-rule-prev-p "else")
(smie-rule-parent)))))
-(defvar-local haskell-tng-smie:indenting nil
- )
+(defconst haskell-tng-smie:dont-cycle '(newline-and-indent)
+ "Users with custom newlines should add their command.")
+(defvar-local haskell-tng-smie:indentations nil)
(defun haskell-tng-smie:indent-cycle ()
- "Returns the next alternative indentation level from a ring."
- (when (and
- (eq this-command last-command)
- ;; TODO allow users to define the blacklist, incase they have a custom
- ;; newline+tab command.
- (not (eq this-command #'newline-and-indent)))
- ;; TODO invalidation of any caches
- ;; TODO record the smie indent level (recursing like in stefan's code)
- ;; TODO implement
- ;; (message "CALLING INDENT CYCLE FROM %s" this-command)
- 2))
-
-;; (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)))))
+ "When invoked more than once, returns an alternative indentation level."
+ ;; There is a design choice here: either we compute all the indentation
levels
+ ;; (including a recursive call to `smie-indent-calculate') and put them into
a
+ ;; ring that we cycle, or we push/pop with recalculation. We choose the
+ ;; latter, because cache invalidation is unclear for the former
+ (if (or (not (eq this-command last-command))
+ (member this-command haskell-tng-smie:dont-cycle))
+ (setq haskell-tng-smie:indentations nil)
+
+ (when (null haskell-tng-smie:indentations)
+ ;; avoid recalculating the prime indentation level
+ (let ((prime (current-column)))
+ (setq haskell-tng-smie:indentations
+ (append (-remove-item prime (haskell-tng-smie:indent-alts))
+ (list prime)))))
+
+ (pop haskell-tng-smie:indentations)))
+
+(defun haskell-tng-smie:indent-alts ()
+ "Returns a list of alternative indentation levels for the
+ current line."
+ ;; FIXME implement
+ '(2)
+ )
(defun haskell-tng-smie:setup ()
(setq-local smie-indent-basic 2)
- [nongnu] elpa/haskell-tng-mode cfbdae1 084/385: simplify the lexer assertion language, (continued)
- [nongnu] elpa/haskell-tng-mode cfbdae1 084/385: simplify the lexer assertion language, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 0c5acb7 087/385: lexer and grammar supports symid, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 6c520bc 093/385: fixes for type level lists, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode f085f16 097/385: indentation regression tests, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 01ea0b8 103/385: heuristic alternative indentation levels, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode c20ea4f 096/385: infix varid as symid, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode bfe859a 095/385: notes about lexers, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 0506391 109/385: module ... where indents to 0, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode d9bbcdd 111/385: next steps, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 6cf67bf 105/385: indentation can't handle mismatched parens, don't test for it, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 25b15eb 102/385: indentation alternatives wiring,
ELPA Syncer <=
- [nongnu] elpa/haskell-tng-mode e023657 107/385: SMIE wishlist, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 497214b 119/385: syntax tests and bugfixes, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode df5d2c5 122/385: better whitespace gap detection, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 3b7cd02 123/385: some todos, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode fc4d3e3 127/385: compilation mode supports multiline error spans, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 88bad65 128/385: visually distinguish compile errors and warnings, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 9dc0abc 129/385: alt indentation levels should be ordered, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 879fc34 130/385: thots, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 1009082 140/385: append indentation test, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 88b17d4 137/385: started indentation rules, ELPA Syncer, 2021/10/06