Folding

For folding parts of code you can use

hide-show.el

and hs-outline-level (based on py-outline-level created by Gb)

;; this gets called by outline to determine the level. Just use the length of the whitespace
(defun hsk-outline-level ()
(let (buffer-invisibility-spec)
(save-excursion
(skip-chars-forward "\t ")
(current-column))))