Skip to content

Instantly share code, notes, and snippets.

@cabo
Created March 14, 2012 14:57
Show Gist options
  • Save cabo/2037035 to your computer and use it in GitHub Desktop.
Save cabo/2037035 to your computer and use it in GitHub Desktop.
hs-hide-all-comments: get rid of all this verbose nonsense that nobody cares about :-)
(defun hs-hide-all-comments ()
"Hide all top level blocks, if they are comments, displaying only first line.
Move point to the beginning of the line, and run the normal hook
`hs-hide-hook'. See documentation for `run-hooks'."
(interactive)
(hs-life-goes-on
(save-excursion
(unless hs-allow-nesting
(hs-discard-overlays (point-min) (point-max)))
(goto-char (point-min))
(let ((spew (make-progress-reporter "Hiding all comment blocks..."
(point-min) (point-max)))
(re (concat "\\(" hs-c-start-regexp "\\)")))
(while (re-search-forward re (point-max) t)
(if (match-beginning 1)
;; found a comment, probably
(let ((c-reg (hs-inside-comment-p)))
(when (and c-reg (car c-reg))
(if (> (count-lines (car c-reg) (nth 1 c-reg)) 1)
(hs-hide-block-at-point t c-reg)
(goto-char (nth 1 c-reg))))))
(progress-reporter-update spew (point)))
(progress-reporter-done spew)))
(beginning-of-line)
(run-hooks 'hs-hide-hook)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment