Fix zr, zm, zR & zM vimmish folding in org-mode

Fixes the following keybinds for evil users:

z r        open next level of headings buffer-wide
z m        close next level of headings buffer-wide
z R        open all folded headings
z M        close all folded headings
[N] z R    open all headings at level N and above
[N] z M    close all headings at level N and below
This commit is contained in:
Henrik Lissner 2020-05-13 19:29:10 -04:00
parent 7bbb52f17c
commit a10c157d87
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 22 additions and 9 deletions

View file

@ -306,6 +306,20 @@ the prefix ARG changes this command's behavior."
;;;###autoload
(defalias #'+org/close-fold #'outline-hide-subtree)
;;;###autoload
(defun +org/close-all-folds (&optional level)
"Close all folds in the buffer (or below LEVEL)."
(interactive "p")
(outline-hide-sublevels (or level 1)))
;;;###autoload
(defun +org/open-all-folds (&optional level)
"Open all folds in the buffer (or up to LEVEL)."
(interactive "P")
(if (integerp level)
(outline-hide-sublevels level)
(outline-show-all)))
(defun +org--get-foldlevel ()
(let ((max 1))
(save-restriction
@ -321,22 +335,20 @@ the prefix ARG changes this command's behavior."
max)))
;;;###autoload
(defun +org/show-next-fold-level ()
(defun +org/show-next-fold-level (&optional count)
"Decrease the fold-level of the visible area of the buffer. This unfolds
another level of headings on each invocation."
(interactive)
(let* ((current-level (+org--get-foldlevel))
(new-level (1+ current-level)))
(interactive "p")
(let ((new-level (+ (+org--get-foldlevel) (or count 1))))
(outline-hide-sublevels new-level)
(message "Folded to level %s" new-level)))
;;;###autoload
(defun +org/hide-next-fold-level ()
(defun +org/hide-next-fold-level (&optional count)
"Increase the global fold-level of the visible area of the buffer. This folds
another level of headings on each invocation."
(interactive)
(let* ((current-level (+org--get-foldlevel))
(new-level (max 1 (1- current-level))))
(interactive "p")
(let ((new-level (max 1 (- (+org--get-foldlevel) (or count 1)))))
(outline-hide-sublevels new-level)
(message "Folded to level %s" new-level)))

View file

@ -907,11 +907,12 @@ compelling reason, so..."
:n "zc" #'+org/close-fold
:n "zC" #'outline-hide-subtree
:n "zm" #'+org/hide-next-fold-level
:n "zM" #'+org/close-all-folds
:n "zn" #'org-tree-to-indirect-buffer
:n "zo" #'+org/open-fold
:n "zO" #'outline-show-subtree
:n "zr" #'+org/show-next-fold-level
:n "zR" #'outline-show-all
:n "zR" #'+org/open-all-folds
:n "zi" #'org-toggle-inline-images
:map org-read-date-minibuffer-local-map