I know I can go to a block header and fold/unfold by hitting the TAB key. However suppose I'm inside a block that has hundreds of lines, and I just want to fold the current block, without having to go to the block header -- is there a keyboard short-cut that can do that? Or is there an elisp function that does that, so that I can bind some shortcut to that function?
Create a keybinding that performs the following function:
(defun zin/org-cycle-current-headline ()
(interactive)
(outline-previous-heading)
(org-cycle))
This will jump back to the previous headline and then cycle. Since the headline is already open, it will close it. It also places the point at the start of the headline.
If you wrap the two commands in (save-excursion )
it will retain the point, however that could lead to entering information inside the ellipsis without realizing it. Alternately you can change the command to call a non-interactive form:
(defun zin/org-cycle-current-headline ()
(interactive)
(org-cycle-internal-local))
This is equivalent to the above with (save-excursion )
.
C-c C-p
will get you to the heading, TAB
will fold. You can create a keyboard macro for this, or the equivalent ELISP:
(defun up-n-fold ()
(interactive)
(progn
(outline-previous-visible-heading 1)
(org-cycle)))
Edit: corrected C-c p for C-c C-p as noted by many below. Thanks!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With