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.

1 Answer 1


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. Commented Sep 24, 2018 at 15:22
  • This works fine. However, it doesn't work if <language> is missing in the block header. eg #+BEGIN_SRC :hidden
    – dips
    Commented Jun 16, 2019 at 17:06
  • @dips You are picking the bones in the egg. "(error "No such language mode: :hidden-mode")". Try #+BEGIN_EXAMPLE blocks, but that is not the answer to this question.
    – SunDawning
    Commented Sep 27, 2019 at 2:45
  • 1
    @SunDawning, would you consider contributing this upstream so that it is a standard feature of org-mode?
    – MattHusz
    Commented Sep 17, 2020 at 18:08
  • 1
    @SunDawning sorry to nag. Is this something you'd be willing to contribute upstream? If not, would you be ok with me contributing it to org-mode? This is a nice feature and something I think many people could benefit from. Thanks.
    – MattHusz
    Commented Dec 4, 2021 at 17:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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