You can achieve what you want by adding the org-hide-block-all
command to org-mode-hook
:
(add-hook 'org-mode-hook 'org-hide-block-all)
For my personal configuration, I've extended this solution a bit:
(defvar org-blocks-hidden nil)
(defun org-toggle-blocks ()
(interactive)
(if org-blocks-hidden
(org-show-block-all)
(org-hide-block-all))
(setq-local org-blocks-hidden (not org-blocks-hidden)))
(add-hook 'org-mode-hook 'org-toggle-blocks)
(define-key org-mode-map (kbd "C-c t") 'org-toggle-blocks)
With this in place, org-mode
collapses SRC
blocks by default and lets me toggle visibility of all SRC
blocks by hitting C-c t. (If you decide to use this code you can of course adapt the key binding to your liking.)
org-hide-block-startup
: stackoverflow.com/a/21563210/2112489. And, the following link has something to do with cycling visibility ofsrc
blocks that I wrote up a while back in time, but it doesn't set them to be hidden by default. I won't have time to work on this today or tomorrow, but here is the link in case you or anyone else wants to play a bit with the code: stackoverflow.com/a/25496350/2112489