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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/haskell-tng-mode cb0f3d2 082/385: starting indentation rul


From: ELPA Syncer
Subject: [nongnu] elpa/haskell-tng-mode cb0f3d2 082/385: starting indentation rules
Date: Tue, 5 Oct 2021 23:59:06 -0400 (EDT)

branch: elpa/haskell-tng-mode
commit cb0f3d239f027ea7a5e532837f87c7f28398fd90
Author: Tseen She <ts33n.sh3@gmail.com>
Commit: Tseen She <ts33n.sh3@gmail.com>

    starting indentation rules
---
 haskell-tng-smie.el | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/haskell-tng-smie.el b/haskell-tng-smie.el
index 55832f6..07254bc 100644
--- a/haskell-tng-smie.el
+++ b/haskell-tng-smie.el
@@ -40,6 +40,7 @@
 ;; with a more complete grammar has been shown to be less than satisfactory,
 ;; therefore there is no reason to do more than is needed.
 (defvar haskell-tng-smie:grammar
+  ;; see docs for `smie-prec2->grammar'
   (smie-prec2->grammar
    (smie-bnf->prec2
     '((id)
@@ -57,6 +58,8 @@
        (id "+" infixexp)
        (id))
 
+      ;; TODO lexer should identify / normalise ids, consid, etc.
+
       ;; WLDOs
       (wldo
        ("where" decls)
@@ -85,14 +88,26 @@
 
     )))
 
-;; FIXME indentation rules
 ;; 
https://www.gnu.org/software/emacs/manual/html_mono/elisp.html#SMIE-Indentation
 ;;
 ;; ideas for an indentation tester
 ;; 
https://github.com/elixir-editors/emacs-elixir/blob/master/test/test-helper.el#L52-L63
-(defvar haskell-tng-smie:rules nil)
+(defun haskell-tng-smie:rules (method arg)
+  ;; see docs for `smie-rules-function'
+  ;; FIXME implement and test indentation
+  (pcase (cons method arg)
+    (`(:elem . basic) smie-indent-basic)
+    (`(,_ . ",") (smie-rule-separator method))
+    (`(:after . "=") smie-indent-basic)
+    (`(:before . ,(or `"(" `"{"))
+     (if (smie-rule-hanging-p) (smie-rule-parent)))
+    (`(:before . "if")
+     (and (not (smie-rule-bolp)) (smie-rule-prev-p "else")
+          (smie-rule-parent)))))
 
 (defun haskell-tng-smie:setup ()
+  (setq-local smie-indent-basic 2)
+
   (add-to-list
    'after-change-functions
    #'haskell-tng-layout:cache-invalidation)
@@ -103,7 +118,7 @@
 
   (smie-setup
    haskell-tng-smie:grammar
-   haskell-tng-smie:rules
+   #'haskell-tng-smie:rules
    :forward-token #'haskell-tng-lexer:forward-token
    :backward-token #'haskell-tng-lexer:backward-token))
 



reply via email to

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