FUEL: Indentation for [let and [| forms.

db4
Jose A. Ortega Ruiz 2008-12-19 14:54:18 +01:00
parent af27929ea4
commit f9042f1340
2 changed files with 51 additions and 16 deletions

View File

@ -94,16 +94,19 @@ code in the buffer."
(save-excursion (save-excursion
(beginning-of-line) (beginning-of-line)
(when (> (fuel-syntax--brackets-depth) 0) (when (> (fuel-syntax--brackets-depth) 0)
(let* ((op (fuel-syntax--brackets-start)) (let* ((bs (fuel-syntax--brackets-start))
(cl (fuel-syntax--brackets-end)) (be (fuel-syntax--brackets-end))
(ln (line-number-at-pos)) (ln (line-number-at-pos)))
(iop (fuel-syntax--indentation-at op))) (when (> ln (line-number-at-pos bs))
(when (> ln (line-number-at-pos op)) (cond ((and (> be 0)
(if (and (> cl 0) (= (- be (point)) (current-indentation))
(= (- cl (point)) (current-indentation)) (= ln (line-number-at-pos be)))
(= ln (line-number-at-pos cl))) (fuel-syntax--indentation-at bs))
iop ((or (fuel-syntax--is-eol bs)
(fuel-syntax--increased-indentation iop))))))) (not (eq ?\ (char-after (1+ bs)))))
(fuel-syntax--increased-indentation
(fuel-syntax--indentation-at bs)))
(t (+ 2 (fuel-syntax--line-offset bs)))))))))
(defun factor-mode--indent-definition () (defun factor-mode--indent-definition ()
(save-excursion (save-excursion

View File

@ -180,6 +180,10 @@
(" \\(!\\)" (1 "<")) (" \\(!\\)" (1 "<"))
("^\\(!\\)" (1 "<")) ("^\\(!\\)" (1 "<"))
("\\(!(\\) .* \\()\\)" (1 "<") (2 ">")) ("\\(!(\\) .* \\()\\)" (1 "<") (2 ">"))
("\\(\\[\\)\\(let\\|wlet\\|let\\*\\)\\( \\|$\\)" (1 "(]"))
("\\(\\[\\)\\(|\\) +[^|]* \\(|\\)" (1 "(]") (2 "(|") (3 ")|"))
(" \\(|\\) " (1 "(|"))
(" \\(|\\)$" (1 ")"))
("\\([[({]\\)\\([^ \"\n]\\)" (1 "_") (2 "_")) ("\\([[({]\\)\\([^ \"\n]\\)" (1 "_") (2 "_"))
("\\([^ \"\n]\\)\\([])}]\\)" (1 "_") (2 "_")))) ("\\([^ \"\n]\\)\\([])}]\\)" (1 "_") (2 "_"))))
@ -215,16 +219,44 @@
(looking-at fuel-syntax--end-of-def-regex)) (looking-at fuel-syntax--end-of-def-regex))
(defsubst fuel-syntax--looking-at-emptiness () (defsubst fuel-syntax--looking-at-emptiness ()
(looking-at "^[ \t]*$")) (looking-at "^[ ]*$\\|$"))
(defsubst fuel-syntax--is-eol (pos)
(save-excursion
(goto-char (1+ pos))
(fuel-syntax--looking-at-emptiness)))
(defsubst fuel-syntax--line-offset (pos)
(- pos (save-excursion
(goto-char pos)
(beginning-of-line)
(point))))
(defun fuel-syntax--previous-non-blank ()
(forward-line -1)
(while (and (not (bobp)) (fuel-syntax--looking-at-emptiness))
(forward-line -1)))
(defun fuel-syntax--beginning-of-block ()
(save-excursion
(or (and (> (fuel-syntax--brackets-depth) 0)
(fuel-syntax--brackets-start))
(and (fuel-syntax--beginning-of-defun) (point))
(point))))
(defun fuel-syntax--at-setter-line () (defun fuel-syntax--at-setter-line ()
(save-excursion (save-excursion
(beginning-of-line) (beginning-of-line)
(if (not (fuel-syntax--looking-at-emptiness)) (when (re-search-forward fuel-syntax--setter-regex
(re-search-forward fuel-syntax--setter-regex (line-end-position) t) (line-end-position)
(forward-line -1) t)
(or (fuel-syntax--at-constructor-line) (let* ((to (match-beginning 0))
(fuel-syntax--at-setter-line))))) (from (fuel-syntax--beginning-of-block)))
(goto-char from)
(let ((depth (fuel-syntax--brackets-depth)))
(and (or (re-search-forward fuel-syntax--constructor-regex to t)
(re-search-forward fuel-syntax--setter-regex to t))
(= depth (fuel-syntax--brackets-depth))))))))
(defun fuel-syntax--at-constructor-line () (defun fuel-syntax--at-constructor-line ()
(save-excursion (save-excursion