[Original answer starts here: it uses org-fold.el
so it requires a fairly recent version of Org mode: 9.5.4 and above]above.]
EDIT: here's another version of this function that is very similar to the one at the top of the answer. It uses an C-h f org-fold-region
saysfunction so that it will work in my caseversion 9.5.4 or later of Org mode:
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.
#+begin_src elisp
(defun my/org-show-block ()
(let* ((e (org-element-at-point))
(type (org-element-type e)))
(when (eq type 'src-block)
(org-fold-hide-block-toggle 'off nil e))))
#+end_src
YouAs you can make sure thatsee the fileonly difference 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 correctlyfunction name.
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, but earlier version probably will not.