From 6c70495565cae032d111d2ffdd7bd9b8524af28b Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Thu, 4 Nov 2010 17:27:55 -0400 Subject: [PATCH] - --- sml-mode.el | 51 ++++++++++++++++++++++++++++++++++++--------------- testcases.sml | 55 +++++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 85 insertions(+), 21 deletions(-) diff --git a/sml-mode.el b/sml-mode.el index 4bae76eccdd..876b9c0b500 100644 --- a/sml-mode.el +++ b/sml-mode.el @@ -450,6 +450,8 @@ Regexp match data 0 points to the chars." (nonassoc " -dummy- "))) ;Bogus anchor at the end. )))) +(defvar sml-indent-separator-outdent 2) + (defun sml-smie-rules (kind token) (pcase (cons kind token) (`(:after . "struct") 0) @@ -463,11 +465,28 @@ Regexp match data 0 points to the chars." ;; Shift single-char separators 2 columns left if they appear ;; at the beginning of a line so the content is aligned ;; (assuming exactly one space after the separator is used). - (if (and (smie-bolp) (eq kind :before)) - (if (smie-parent-p "(" "{" "[" "=" "d=" "|" "d|") 0 - (if (smie-parent-p "of" "in" "fun") - ;; FIXME: Adjust to correct nb of spaces. - '(+ point -2))))) + (cond + ((smie-bolp) + ;; FIXME: Rather than consult the number of spaces, we could *set* the + ;; number of spaces so as to align the separator with the close-paren + ;; while aligning the content with the rest. + (let ((outdent (if (looking-at ".\\( *\\)[^\n ]") + (1+ (- (match-end 1) (match-beginning 1))) + sml-indent-separator-outdent))) + ;; FIXME: This test is really just checking (not + ;; (smie-sibling-p)). + (pcase kind + (`:before + (if (smie-parent-p "(" "{" "[" "=" "d=" "of" "in" "fun") + `(bound parent (+ point ,(- outdent)) point))) + (`:after outdent)))) + ;; ((eq kind :after) + ;; (forward-char 1) + ;; (ignore-errors + ;; (smie-backward-sexp 'halfsexp) + ;; 'point-virtual)) + )) + (`(:after . ,(or `"(" `"{" `"[")) (if (not (smie-hanging-p)) 2)) (`(:before . ,(or `"let" `"(" `"[" `"{")) (if (smie-hanging-p) 'parent)) (`(:before . "if") (if (smie-prev-p "else") 'parent)) ;'point @@ -526,11 +545,12 @@ Assumes point is right before the | symbol." (defun sml-smie-forward-token-1 () (forward-comment (point-max)) - (buffer-substring (point) - (progn - (or (/= 0 (skip-syntax-forward "'w_")) - (skip-syntax-forward ".'")) - (point)))) + (buffer-substring-no-properties + (point) + (progn + (or (/= 0 (skip-syntax-forward "'w_")) + (skip-syntax-forward ".'")) + (point)))) (defun sml-smie-forward-token () (let ((sym (sml-smie-forward-token-1))) @@ -543,11 +563,12 @@ Assumes point is right before the | symbol." (defun sml-smie-backward-token-1 () (forward-comment (- (point))) - (buffer-substring (point) - (progn - (or (/= 0 (skip-syntax-backward ".'")) - (skip-syntax-backward "'w_")) - (point)))) + (buffer-substring-no-properties + (point) + (progn + (or (/= 0 (skip-syntax-backward ".'")) + (skip-syntax-backward "'w_")) + (point)))) (defun sml-smie-backward-token () (let ((sym (sml-smie-backward-token-1))) diff --git a/testcases.sml b/testcases.sml index edf03c072c9..83afcd7e42d 100644 --- a/testcases.sml +++ b/testcases.sml @@ -14,7 +14,45 @@ val bar = fn a1 a2 a3 a5 a6 a4 => (1 + ;( + w + , + s + , + s + , s , a , + a + , s , a , + a + ) + ;( + w + ,s + ,a + ) + ;( + w + , s + , a + ) + ;( w + , s + , a + ) + ;( w + ,s + ,a + ) ;3 + + a + * 4 + + let val x = 3 + in toto + end + + if a then + b + else + c ;4) val ber = 1; @@ -156,18 +194,20 @@ val y = ( foo("(*") * 2; end; - + let in a ; b end; - + let in - a + a + + b + + c ; b end; - + let in if a then b @@ -203,6 +243,9 @@ structure Foo = struct val x = 1 end +structure Foo = struct val x = 1 + end + signature FSPLIT = sig type flint = FLINT.prog @@ -369,8 +412,8 @@ and sfdec env (leE,leI,fvI,leRet) (fk,f,args,body) = val fErets = (map F.VAR fvbIs) val bodyE = bodyE(F.RET fErets) (* val tmp = mklv() - val bodyE = bodyE(F.RECORD(F.RK_STRUCT, map F.VAR fvbIs, - tmp, F.RET[F.VAR tmp])) *) + val bodyE = bodyE(F.RECORD(F.RK_STRUCT, map F.VAR fvbIs, + tmp, F.RET[F.VAR tmp])) *) val fdecE = (fkE, fE, args, bodyE) val fElty = LT.ltc_fct(map #2 args, map getLty fErets) val _ = addLty(fE, fElty) -- 2.11.4.GIT