         (then-else-count 0)
         ;; The same with "let", "loop", and "in".
         (let-in-count 0)
+        (just-had-let nil)
         ;; Only look in the current paren-delimited code.
         (topp (save-excursion (or (ignore-errors
                                     (backward-up-list 1)

              (ignore-errors
                (backward-up-list 1)
                (current-column))))

       ;; Align "in" to nearest "loop" if there is sign of not being in
       ;; the body of a let.
       (save-excursion
         (and (futhark-looking-at-word "in")
              (futhark-first-keyword-backward)
              (futhark-looking-at-word "in")
              (futhark-find-keyword-backward "loop")
              (current-column)))

       ;; Align "in" to nearest "let" or "loop".
       (save-excursion

            ((futhark-looking-at-word "else")
             (incf if-else-count)
             (incf then-else-count))
            ((and (or (futhark-looking-at-word "let")
                      (futhark-looking-at-word "loop"))
                  (not just-had-let))
             (setq just-had-let t)
             (setq let-in-count (max 0 (1- let-in-count))))
            ((futhark-looking-at-word "in")
             (setq just-had-let nil)
             (incf let-in-count))
            ((futhark-looking-at-word "do")
             (setq just-had-let nil))
            )

      (when (and (futhark-looking-at-word word)
