[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/haskell-tng-mode 06b357c 054/385: hacky closing braces
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/haskell-tng-mode 06b357c 054/385: hacky closing braces |
Date: |
Tue, 5 Oct 2021 23:59:00 -0400 (EDT) |
branch: elpa/haskell-tng-mode
commit 06b357c3a359dedcea2cf67768753264610424a5
Author: Tseen She <ts33n.sh3@gmail.com>
Commit: Tseen She <ts33n.sh3@gmail.com>
hacky closing braces
---
haskell-tng-smie.el | 11 +++++++++--
haskell-tng-util.el | 15 +++++++++++++++
test/faces/medley.hs.lexer | 6 ++++++
3 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/haskell-tng-smie.el b/haskell-tng-smie.el
index 71ecac6..037f6c1 100644
--- a/haskell-tng-smie.el
+++ b/haskell-tng-smie.el
@@ -74,9 +74,16 @@
;; A hacky solution is to calculate and cache the closing brace when
;; discovering an open brace, but that just introduces more problems.
((and wldo (not (looking-at "{")))
- (message "WLDO was at %s" start)
- ;; TODO find the closing brace and add to the state
+ (let ((close (haskell-tng:layout-close)))
+ (message "WLDO opened at %s setting level to %s, closing at %s"
+ start (current-column) close)
+ (push close haskell-tng-smie:wldos))
"{")
+ ((when-let (close (car haskell-tng-smie:wldos))
+ (>= (point) close))
+ (message "WLDO closed at %s" (point))
+ (pop haskell-tng-smie:wldos)
+ "}")
;; TODO should only trigger inside a WLDO block
;; layout of wldo blocks: semicolons
diff --git a/haskell-tng-util.el b/haskell-tng-util.el
index e4737e8..9f90b00 100644
--- a/haskell-tng-util.el
+++ b/haskell-tng-util.el
@@ -20,6 +20,7 @@
(when (looking-at ")")
(point)))))
+;; FIXME comment aware
(defun haskell-tng:indent-close (&optional pos)
"The beginning of the line with indentation that closes `POS'."
(save-excursion
@@ -31,6 +32,20 @@
(throw 'closed (point))))
nil))))
+;; FIXME comment aware
+;; TODO share with haskell-tng:indent-close?
+(defun haskell-tng:layout-close (&optional pos)
+ "The point with indentation that closes `POS'."
+ (save-excursion
+ (goto-char (or pos (point)))
+ (let ((level (current-column)))
+ (catch 'closed
+ (while (and (forward-line) (not (eobp)))
+ (when (< (current-indentation) level)
+ (forward-char (current-indentation))
+ (throw 'closed (point))))
+ nil))))
+
(defun haskell-tng:indent-close-previous ()
"Indentation closing the previous symbol."
(save-excursion
diff --git a/test/faces/medley.hs.lexer b/test/faces/medley.hs.lexer
index 10a0a2f..a1aeae1 100644
--- a/test/faces/medley.hs.lexer
+++ b/test/faces/medley.hs.lexer
@@ -212,6 +212,7 @@ Set
s
->
a
+}
instance
Get
a
@@ -230,6 +231,7 @@ _
SYNTAX_)
=
a
+}
instance
Get
a
@@ -253,6 +255,7 @@ SYNTAX_)
=
get
xs
+}
data
Options
=
@@ -325,6 +328,7 @@ a
a
->
a
+}
instance
SYNTAX_(
Eq
@@ -371,6 +375,7 @@ _
_
=
False
+}
data
ReportType
=
@@ -403,6 +408,7 @@ G
a
=
Char
+}
data
Flobble
=
- [nongnu] elpa/haskell-tng-mode 73e2b11 063/385: the new lexer works!, (continued)
- [nongnu] elpa/haskell-tng-mode 73e2b11 063/385: the new lexer works!, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 8e1a225 068/385: sexp tests, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 269be91 072/385: revert broken grammar rules, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 3194e62 074/385: stefan to the rescue, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode b690037 081/385: comment-* support, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 502cc26 085/385: document a failure mode, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 08f924c 088/385: simplify the grammar rules, better s-exps, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 71cf945 048/385: lexer test based on Haskell2010, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 4d6bbfc 050/385: feedback from Stefan, improving lexing, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 96609e4 052/385: thoughts on layout inference, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 06b357c 054/385: hacky closing braces,
ELPA Syncer <=
- [nongnu] elpa/haskell-tng-mode 64ad4a8 057/385: refactored to centralise state, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 0ac5a2f 059/385: copyright years and move the test assertions, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode a6bb27e 061/385: [ci skip] layout algorithm implemented and tested, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 7d2863e 065/385: tests for SMIE state invalidation, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 41a29dd 066/385: backward lexer, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode c48e7a5 069/385: starting to transcribe the expression table, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 1f1110a 073/385: transcribe the grammar rules, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 01789b1 075/385: y u no haskell-mode?, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode b8f3e3f 079/385: back out incomplete grammar rules, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 9e19b2b 080/385: double down on simpler grammar, ELPA Syncer, 2021/10/06