 (defun factor--indent-in-brackets ()
   (save-excursion
     (beginning-of-line)
-    (when (or (and (re-search-forward factor--regex-closing-paren
-                                      (line-end-position) t)
-                   (not (backward-char)))
-              (> (factor--ppss-brackets-depth) 0))
-      (let ((op (factor--ppss-brackets-start)))
-        (when (> (line-number-at-pos) (line-number-at-pos op))
-          (if (factor--at-closing-paren-p)
+    (when (> (factor--ppss-brackets-depth) 0)
+      (let ((op (factor--ppss-brackets-start))
+            (cl (factor--ppss-brackets-end))
+            (ln (line-number-at-pos)))
+        (when (> ln (line-number-at-pos op))
+          (if (= ln (line-number-at-pos cl))
               (factor--indentation-at op)
             (factor--increased-indentation (factor--indentation-at op))))))))
 


  (set-syntax-table factor-mode-syntax-table)
  ;; Defun navigation
  (setq defun-prompt-regexp "[^ :]+")
  (set (make-local-variable 'open-paren-in-column-0-is-defun-start) t)
  ;; Indentation
  (set (make-local-variable 'indent-line-function) 'factor--indent-line)
  (setq factor-indent-width (factor--guess-indent-width))


;;; Factor mode syntax:

(defconst factor--regex-definition-starters
  (regexp-opt '("TUPLE" "MACRO" "MACRO:" "M" ":" "")))

(defconst factor--regex-definition-start
  (format "^\\(%s:\\) " factor--regex-definition-starters))

(defconst factor--regex-definition-end
  (format "\\(;\\( +%s\\)?\\)" factor--regex-declaration-words))

(defconst factor--font-lock-syntactic-keywords
  `(("\\(#!\\)" (1 "<"))
    (" \\(!\\)" (1 "<"))
    ("^\\(!\\)" (1 "<"))
    ("\\(!(\\) .* \\()\\)" (1 "<") (2 ">"))))
