]> gitweb.factorcode.org Git - factor.git/commitdiff
FUEL: Indentation for [let and [| forms.
authorJose A. Ortega Ruiz <jao@gnu.org>
Fri, 19 Dec 2008 13:54:18 +0000 (14:54 +0100)
committerJose A. Ortega Ruiz <jao@gnu.org>
Fri, 19 Dec 2008 13:54:18 +0000 (14:54 +0100)
misc/fuel/factor-mode.el
misc/fuel/fuel-syntax.el

index 2f6eef4f6584bfba416e893b50acddb4ec452283..7f129cd866d69b59ec56a3271523c59e961389f5 100644 (file)
@@ -94,16 +94,19 @@ code in the buffer."
   (save-excursion
     (beginning-of-line)
     (when (> (fuel-syntax--brackets-depth) 0)
-      (let* ((op (fuel-syntax--brackets-start))
-             (cl (fuel-syntax--brackets-end))
-             (ln (line-number-at-pos))
-             (iop (fuel-syntax--indentation-at op)))
-        (when (> ln (line-number-at-pos op))
-          (if (and (> cl 0)
-                   (= (- cl (point)) (current-indentation))
-                   (= ln (line-number-at-pos cl)))
-              iop
-            (fuel-syntax--increased-indentation iop)))))))
+      (let* ((bs (fuel-syntax--brackets-start))
+             (be (fuel-syntax--brackets-end))
+             (ln (line-number-at-pos)))
+        (when (> ln (line-number-at-pos bs))
+          (cond ((and (> be 0)
+                      (= (- be (point)) (current-indentation))
+                      (= ln (line-number-at-pos be)))
+                 (fuel-syntax--indentation-at bs))
+                ((or (fuel-syntax--is-eol bs)
+                     (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 ()
   (save-excursion
index e810772bd011bcc3d9e3a961beaeb2339d21870d..e4f9fe028800107526c673d67e6a96d00e9012a3 100644 (file)
     (" \\(!\\)" (1 "<"))
     ("^\\(!\\)" (1 "<"))
     ("\\(!(\\) .* \\()\\)" (1 "<") (2 ">"))
+    ("\\(\\[\\)\\(let\\|wlet\\|let\\*\\)\\( \\|$\\)" (1 "(]"))
+    ("\\(\\[\\)\\(|\\) +[^|]* \\(|\\)" (1 "(]") (2 "(|") (3 ")|"))
+    (" \\(|\\) " (1 "(|"))
+    (" \\(|\\)$" (1 ")"))
     ("\\([[({]\\)\\([^ \"\n]\\)" (1 "_") (2 "_"))
     ("\\([^ \"\n]\\)\\([])}]\\)" (1 "_") (2 "_"))))
 
   (looking-at fuel-syntax--end-of-def-regex))
 
 (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 ()
   (save-excursion
     (beginning-of-line)
-    (if (not (fuel-syntax--looking-at-emptiness))
-        (re-search-forward fuel-syntax--setter-regex (line-end-position) t)
-      (forward-line -1)
-      (or (fuel-syntax--at-constructor-line)
-          (fuel-syntax--at-setter-line)))))
+    (when (re-search-forward fuel-syntax--setter-regex
+                             (line-end-position)
+                             t)
+      (let* ((to (match-beginning 0))
+             (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 ()
   (save-excursion