+(defun until-closed-helper (level)
+ (if
+ (re-search-backward "\\_<\\(with\\|where\\|begin\\|end\\)\\_>"
+ nil t)
+ (cond
+ ((string= (match-string 0) "end")
+ (until-closed-helper (+ level 1)))
+ ((= level 0)
+ (current-indentation))
+ (t
+ (until-closed-helper (- level 1))))
+
+ 0))
+
+(defun until-closed (is-with)
+ (save-excursion
+ (if is-with
+ (until-closed-helper 1)
+ (until-closed-helper 0))))
+