From: monnier <> Date: Thu, 17 Jun 1999 15:14:01 +0000 (+0000) Subject: * sml-defs.el (sml-close-paren): added a second field that specifies when X-Git-Url: https://code.delx.au/gnu-emacs-elpa/commitdiff_plain/f5e091cde63e71ac3c1d5a01d680aab36a2b271a * sml-defs.el (sml-close-paren): added a second field that specifies when not to delegate. Used for zero-indent single-line `if..else'. --- diff --git a/ChangeLog b/ChangeLog index e740a5878..51161fc50 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +1999-06-17 Stefan Monnier + + * 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 * sml-move.el (sml-(for|back)ward-sym): distinguishes between diff --git a/TODO b/TODO index 21791c1a6..9b04bad27 100644 --- 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: diff --git a/sml-defs.el b/sml-defs.el index 8d5e89062..2e73b97af 100644 --- a/sml-defs.el +++ b/sml-defs.el @@ -169,12 +169,13 @@ (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")))) @@ -203,14 +204,14 @@ "Symbols that should behave somewhat like opening parens.") (defconst sml-close-paren - `(("in" . "\\") - ("with" . "\\") - ("withtype" . "\\<\\(abs\\|data\\)type\\>") - ("end" . ,sml-begin-symbols-re) - ("then" . "\\") - ("else" . "\\") - ("of" . "\\") - ("d=" . nil)) + `(("in" "\\") + ("with" "\\") + ("withtype" "\\<\\(abs\\|data\\)type\\>") + ("end" ,sml-begin-symbols-re) + ("then" "\\") + ("else" "\\" (sml-bolp)) + ("of" "\\") + ("d=" nil)) "Symbols that should behave somewhat like close parens.") (defconst sml-agglomerate-re "\\" diff --git a/sml-mode.el b/sml-mode.el index 459f42955..206a1cfb3 100644 --- a/sml-mode.el +++ b/sml-mode.el @@ -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 () diff --git a/sml-move.el b/sml-move.el index 7b1bea179..8a65eab6c 100644 --- a/sml-move.el +++ b/sml-move.el @@ -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)