Here's a little function to unfold the current element-at-point, given that it is a src-block
:
#+begin_src elisp
(defun my/org-show-block ()
(let* ((e (org-element-at-point))
(type (org-element-type e))
(beg (org-element-property :begin e))
(end (org-element-property :end e)))
(when (eq type 'src-block)
(org-fold-region beg end nil 'block))))
#+end_src
It's a no-op if the block is already unfolded.
EDIT: C-h f org-fold-region
says in my case:
org-fold-region is an alias for ‘org-fold-core-region’ in
‘org-fold.el’.
(org-fold-region FROM TO FLAG &optional SPEC-OR-ALIAS)
Hide or show lines from FROM to TO, according to FLAG.
SPEC-OR-ALIAS is the folding spec or foldable element, as a symbol.
If SPEC-OR-ALIAS is omitted and FLAG is nil, unfold everything in the region.
You can make sure that the file is loaded with (require 'org-fold)
to temporarily get you over the hump, but that should not be necessary: it is required
by org.el
so when that is loaded,
org-fold.el[c]
would have been loaded as well. You should check that you are initializing Org mode correctly.
EDIT 2: It may be that you are using an old version of Org mode that does not have org-fold.el
. Please add the version of Org mode that you are using (M-x org-version
) to your question.
org-fold
is available in Org mode 9.5.4 and later. Emacs 28.2 currently comes with Org mode 9.6 I think, so that should work.