+(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)))))
+