In org-mode, how could one specify the visibility state of individual SRC_BLOCKs when a file is opened?

org-mode provides the variable org-hide-block-startup to specify if all source blocks are shown or hidden when a file is opened. How could I specify, instead, the initial state of individual source blocks when a file is opened?

The visibility state of headings can be manually chosen using the VISIBILITY property. It is not obvious, however, if there is something similar for source blocks.


Indeed, some code blocks are too long and take up too much space.

By default, you want to display all the code blocks, only hidden when you set a block of code to hide.

Suppose there is a block of code in an org file that needs to be hidden, like:

#+BEGIN_SRC emacs-lisp :hidden
(defun individual-visibility-source-blocks ()
  "Fold some blocks in the current buffer."
   (lambda ()
     (let ((case-fold-search t))
       (when (and
                (beginning-of-line 1)
                (looking-at org-block-regexp))

 (function individual-visibility-source-blocks))

When the command "individual-visibility-source-blocks" is used, all code blocks are displayed except for the code block.

  • Your answer is nice and clever. You've made me aware of the function org-block-map which I'm sure will me put to use in many other places. – UndeadKernel Sep 24 '18 at 15:22
  • This works fine. However, it doesn't work if <language> is missing in the block header. eg #+BEGIN_SRC :hidden – dips 2 days ago

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.