[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 01/01: * sml-mode.el (sml--rightalign-and-p): New function.
From: |
Stefan Monnier |
Subject: |
[elpa] 01/01: * sml-mode.el (sml--rightalign-and-p): New function. |
Date: |
Wed, 04 Jun 2014 14:58:45 +0000 |
monnier pushed a commit to branch master
in repository elpa.
commit 2acab4eeb3a5bf32b013b7365a10f361e40db5ab
Author: Stefan Monnier <address@hidden>
Date: Wed Jun 4 10:58:39 2014 -0400
* sml-mode.el (sml--rightalign-and-p): New function.
---
packages/sml-mode/sml-mode.el | 26 +++++++++++++++++++++++++-
packages/sml-mode/testcases.sml | 1 +
2 files changed, 26 insertions(+), 1 deletions(-)
diff --git a/packages/sml-mode/sml-mode.el b/packages/sml-mode/sml-mode.el
index e9c2477..a46d9ff 100644
--- a/packages/sml-mode/sml-mode.el
+++ b/packages/sml-mode/sml-mode.el
@@ -487,6 +487,30 @@ Regexp match data 0 points to the chars."
(defvar sml-indent-separator-outdent 2)
+(defun sml--rightalign-and-p ()
+ (when sml-rightalign-and
+ ;; Only right-align the "and" if the intervening code is more deeply
+ ;; indented, to avoid things like:
+ ;; datatype foo
+ ;; = Foo of int
+ ;; and bar = Bar of string
+ (save-excursion
+ (let ((max (line-end-position 0))
+ (data (smie-backward-sexp "and"))
+ (startcol (save-excursion
+ (forward-comment (- (point)))
+ (current-column)))
+ (mincol (current-column)))
+ (save-excursion
+ (search-forward "=" max t)
+ (forward-line 1)
+ (if (< (point) max) (setq max (point))))
+ (while (and (<= (point) max) (not (eobp)))
+ (skip-chars-forward " \t")
+ (setq mincol (current-column))
+ (forward-line 1))
+ (>= mincol startcol)))))
+
(defun sml-smie-rules (kind token)
;; I much preferred the pcase version of the code, especially while
;; edebugging the code. But that will have to wait until we get rid of
@@ -528,7 +552,7 @@ Regexp match data 0 points to the chars."
((equal token "and")
;; FIXME: maybe "and" (c|sh)ould be handled as an smie-separator.
(cond
- ((smie-rule-parent-p "datatype") (if sml-rightalign-and 5 0))
+ ((smie-rule-parent-p "datatype") (if (sml--rightalign-and-p) 5 0))
((smie-rule-parent-p "fun" "val") 0)))
((equal token "d=")
(cond
diff --git a/packages/sml-mode/testcases.sml b/packages/sml-mode/testcases.sml
index 0e98ed6..14b73d3 100644
--- a/packages/sml-mode/testcases.sml
+++ b/packages/sml-mode/testcases.sml
@@ -142,6 +142,7 @@ val x =
datatype foobar
= FooB of int
| FooA of bool * int
+and baz = QUX of foo
datatype foo = FOO | BAR of baz
and baz = BAZ | QUUX of foo