Skip to main content
deleted 266 characters in body
Source Link
NickD
  • 33.6k
  • 3
  • 30
  • 47

[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.

[Original answer starts here: it uses org-fold.el so it requires a fairly recent version of Org mode: 9.5.4 and above]

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.

[Original answer starts here: it uses org-fold.el so it requires a fairly recent version of Org mode: 9.5.4 and 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 org-fold function so that it will work in version 9.5.4 or later of Org mode:

 #+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

As you can see the only difference is the function name.

EDIT: It may be that you are using an old version of Org mode that does not have org-fold.el. 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.

added 641 characters in body
Source Link
NickD
  • 33.6k
  • 3
  • 30
  • 47

Here's a version of the function to unfold the source block at point that should work for Org mode versions before 9.5.4 (including 9.1.9):

#+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-hide-block-toggle 'off nil e))))
#+end_src

It should behave identically to the function below (which only works for version 9.5.4 and above).


Original answer

[Original answer starts here: it uses org-fold.el so it requires a fairly recent version of Org mode: 9.5.4 and above]

Here's a little function to unfold the current element-at-point, given that it is a src-block:

Here's a little function to unfold the current element-at-point, given that it is a src-block:

Here's a version of the function to unfold the source block at point that should work for Org mode versions before 9.5.4 (including 9.1.9):

#+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-hide-block-toggle 'off nil e))))
#+end_src

It should behave identically to the function below (which only works for version 9.5.4 and above).


Original answer

[Original answer starts here: it uses org-fold.el so it requires a fairly recent version of Org mode: 9.5.4 and above]

Here's a little function to unfold the current element-at-point, given that it is a src-block:

added 8 characters in body
Source Link
NickD
  • 33.6k
  • 3
  • 30
  • 47

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. Itorg-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.

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. It 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.

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.

added 195 characters in body
Source Link
NickD
  • 33.6k
  • 3
  • 30
  • 47
Loading
added 716 characters in body
Source Link
NickD
  • 33.6k
  • 3
  • 30
  • 47
Loading
Source Link
NickD
  • 33.6k
  • 3
  • 30
  • 47
Loading