emacs-elpa-diffs
[Top][All Lists]
Advanced

[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
 =



reply via email to

[Prev in Thread] Current Thread [Next in Thread]