]> code.delx.au - gnu-emacs-elpa/commitdiff
* sml-defs.el (sml-close-paren): added a second field that specifies when
authormonnier <>
Thu, 17 Jun 1999 15:14:01 +0000 (15:14 +0000)
committermonnier <>
Thu, 17 Jun 1999 15:14:01 +0000 (15:14 +0000)
  not to delegate.  Used for zero-indent single-line `if..else'.

ChangeLog
TODO
sml-defs.el
sml-mode.el
sml-move.el

index e740a5878abaca8508e21ffae40ec1cb05ffa729..51161fc506062b1419a9cab07e6da0282d9518eb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+1999-06-17  Stefan Monnier  <monnier@cs.yale.edu>
+
+       * sml-defs.el (sml-close-paren): added a second field that specifies when
+         not to delegate.  Only used for `else'.
+
 1999-06-16  Stefan Monnier  <monnier@cs.yale.edu>
 
        * sml-move.el (sml-(for|back)ward-sym): distinguishes between
diff --git a/TODO b/TODO
index 21791c1a6b5c8d9c3faa86c5367c66eec8a2d9d8..9b04bad2721fee451f0a9717401b86f363e0145e 100644 (file)
--- a/TODO
+++ b/TODO
@@ -7,8 +7,6 @@
 
 * improve the run-sml to allow running on another machine and to take args
 
-* allow zero-indent after single-line `if a then b else'.
-
 * allow right-aligning "and" with its correspondant.
 
 * sample problematic indentations:
index 8d5e89062544dff3e845e323e07c2a2844a18075..2e73b97af4f02fc1a33c79a009fa6b1f2be601bd 100644 (file)
 (defconst sml-indent-rule
   (sml-preproc-alist
    `(("struct" . 0)
-     (,sml-module-head-syms . ("d=" 0))
-     ("local" . ("in" 0))
+     (,sml-module-head-syms "d=" 0)
+     ("local" "in" 0)
      ;;("of" . (3 nil))
      ;;("else" . (sml-indent-level 0))
      ;;(("in" "fun" "and" "of") . (sml-indent-level nil))
-     (,sml-=-starter-syms . (nil))
+     ("if" "else" 0)
+     (,sml-=-starter-syms nil)
      (("abstype" "case" "datatype" "if" "then" "else" "sharing" "infix" "infixr"
        "let" "local" "nonfix" "open" "raise" "sig" "struct" "type" "val" "while"
        "do" "with" "withtype"))))
   "Symbols that should behave somewhat like opening parens.")
 
 (defconst sml-close-paren
-  `(("in" "\\<l\\(ocal\\|et\\)\\>")
-    ("with" "\\<abstype\\>")
-    ("withtype" "\\<\\(abs\\|data\\)type\\>")
-    ("end" ,sml-begin-symbols-re)
-    ("then" "\\<if\\>")
-    ("else" . "\\<if\\>")
-    ("of" "\\<case\\>")
-    ("d=" nil))
+  `(("in" "\\<l\\(ocal\\|et\\)\\>")
+    ("with" "\\<abstype\\>")
+    ("withtype" "\\<\\(abs\\|data\\)type\\>")
+    ("end" ,sml-begin-symbols-re)
+    ("then" "\\<if\\>")
+    ("else" "\\<if\\>" (sml-bolp))
+    ("of" "\\<case\\>")
+    ("d=" nil))
   "Symbols that should behave somewhat like close parens.")
 
 (defconst sml-agglomerate-re "\\<else[ \t]+if\\>"
index 459f42955d265d7d3b772cccdd90620808dbcc6b..206a1cfb38b4c8eb6f64ca184005db1bcd6810df 100644 (file)
@@ -520,7 +520,7 @@ If anyone has a good algorithm for this..."
 (defun sml-indent-relative (sym data)
   (save-excursion
     (sml-forward-sym) (sml-backward-sexp nil)
-    (unless (cdr data) (sml-backward-spaces) (sml-backward-sym))
+    (unless (second data) (sml-backward-spaces) (sml-backward-sym))
     (+ (or (cdr (assoc sym sml-symbol-indent)) 0)
        (sml-delegated-indent))))
 
@@ -591,11 +591,11 @@ the parent at the end of this function."
   (save-excursion
     (let ((delegate (assoc sym sml-close-paren))
          (head-sym sym))
-      (when delegate
+      (when (and delegate (not (eval (third delegate))))
        ;;(sml-find-match-backward sym delegate)
        (sml-forward-sym) (sml-backward-sexp nil)
        (setq head-sym
-             (if (cdr delegate)
+             (if (second delegate)
                  (save-excursion (sml-forward-sym))
                (sml-backward-spaces) (sml-backward-sym))))
 
@@ -619,41 +619,30 @@ the parent at the end of this function."
 
 (defun sml-indent-default (&optional noindent)
   (let* ((sym-after (save-excursion (sml-forward-sym)))
-        (prec-after (sml-op-prec sym-after 'back))
-        (indent-after (or (cdr (assoc sym-after sml-symbol-indent)) 0))
         (_ (sml-backward-spaces))
         (sym-before (sml-backward-sym))
-        (prec (or (sml-op-prec sym-before 'back) prec-after 100))
         (sym-indent (and sym-before (sml-get-sym-indent sym-before))))
     (if sym-indent
-       (if noindent (current-column) (+ sym-indent indent-after))
-      ;;(sml-forward-sym)
-      (while (and (not (sml-bolp))
-                 (sml-move-if (sml-backward-sexp (1- prec)))
-                 (not (sml-bolp)))
-       (while (sml-move-if (sml-backward-sexp prec))))
-;;       (or (and (not (sml-bolp))
-;;            ;; If we backed over an equal char which was not the
-;;            ;; polymorphic equality, then we did what amounts to
-;;            ;; delegate indent from `=' to the corresponding head, so we
-;;            ;; need to look at the preceding symbol and follow its
-;;            ;; intentation instructions.
-;;            (string-equal "d=" sym-before)
-;;            (let ((point (point)))
-;;              (sml-backward-spaces)
-;;              (let* ((sym (sml-backward-sym))
-;;                     (sym-indent (cdr (assoc-default sym sml-indent-rule))))
-;;                (when sym-indent
-;;                  (if noindent (current-column)
-;;                    (let ((sym-indent (sml-get-sym-indent sym 1)))
-;;                      (if sym-indent (+ indent-after sym-indent)
-;;                        (goto-char point)
-;;                        (+ indent-after (current-column)))))))))
-      
-      (when noindent
-       (sml-move-if (sml-backward-spaces)
-                    (string-match sml-starters-re (or (sml-backward-sym) ""))))
-      (current-column))))
+       ;; the previous sym is an indentation introducer: follow the rule
+       (let ((indent-after (or (cdr (assoc sym-after sml-symbol-indent)) 0)))
+         (if noindent (current-column) (+ sym-indent indent-after)))
+      ;; default-default
+      (let* ((prec-after (sml-op-prec sym-after 'back))
+            (prec (or (sml-op-prec sym-before 'back) prec-after 100)))
+       ;; go back until you hit a symbol that has a lower prec than the
+       ;; "current one", or until you backed over a sym that has the same prec
+       ;; but is at the beginning of a line.
+       (while (and (not (sml-bolp))
+                   (sml-move-if (sml-backward-sexp (1- prec)))
+                   (not (sml-bolp)))
+         (while (sml-move-if (sml-backward-sexp prec))))
+       ;; the `noindent' case does back over an introductory symbol
+       ;; such as `fun', ...
+       (when noindent
+         (sml-move-if
+          (sml-backward-spaces)
+          (string-match sml-starters-re (or (sml-backward-sym) ""))))
+       (current-column)))))
 
 
 (defun sml-bolp ()
index 7b1bea179165823ede6449de7cb64a4c844832ab..8a65eab6c9c1997313c4fa36ad61e19f9ceaab11 100644 (file)
@@ -227,7 +227,7 @@ Returns T if the move indeed moved through one sexp and NIL if not."
        ((and prec op-prec (>= prec op-prec)) nil)
        ;; special rules for nested constructs like if..then..else
        ((and (or (not prec) (and prec op-prec))
-            (setq match (cdr (assoc op sml-close-paren))))
+            (setq match (second (assoc op sml-close-paren))))
        (sml-find-match-backward (concat "\\<" op "\\>") match))
        ;; don't back over open-parens
        ((assoc op sml-open-paren) nil)