                  (point-max)))
           (pt (point)))
       (when skip (forward-line direction))
-      (cl-loop while (and (/= (point) bnd) (funcall predicate))
+      (cl-loop while (and (/= (point) bnd) (funcall predicate base-indent))
                do (progn
                     (when before (setq pt (point-at-bol)))
                     (forward-line direction)

  (save-excursion
    (when point
      (goto-char point))
    (let ((base (current-indentation))
          (begin (point))
          (end (point)))
      (setq begin (+fold--hideshow-seek begin -1 t nil #'+fold--hideshow-geq-or-empty-p)
            begin (+fold--hideshow-seek begin 1 nil nil #'+fold--hideshow-g-or-empty-p)
            end   (+fold--hideshow-seek end 1 t nil #'+fold--hideshow-geq-or-empty-p)
            end   (+fold--hideshow-seek end -1 nil nil #'+fold--hideshow-empty-line-p))
      (list begin end base))))

;;
;; Indentation detection

(defun +fold--hideshow-empty-line-p (_)
  (string= "" (string-trim (thing-at-point 'line))))

(defun +fold--hideshow-geq-or-empty-p (base-indent)
  (or (+fold--hideshow-empty-line-p)
      (>= (current-indentation) base-indent)))

(defun +fold--hideshow-g-or-empty-p (base-indent)
  (or (+fold--hideshow-empty-line-p)
      (> (current-indentation) base-indent)))

(defun +fold--hideshow-seek (start direction before skip predicate base-indent)
  "Seeks forward (if direction is 1) or backward (if direction is -1) from start, until predicate
fails. If before is nil, it will return the first line where predicate fails, otherwise it returns
the last line where predicate holds."
