Restore vim zr, zR, zm, & zM folding in org-mode
For evil users.
This commit is contained in:
parent
8762129e8d
commit
f7a6089956
2 changed files with 61 additions and 16 deletions
|
@ -256,6 +256,52 @@ wrong places)."
|
||||||
(interactive)
|
(interactive)
|
||||||
(org-toggle-checkbox '(4)))
|
(org-toggle-checkbox '(4)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defalias #'+org/toggle-fold #'+org|toggle-only-current-fold)
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun +org/open-fold ()
|
||||||
|
"Open the current fold (not but its children)."
|
||||||
|
(interactive)
|
||||||
|
(+org/toggle-fold t))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defalias #'+org/close-fold #'outline-hide-subtree)
|
||||||
|
|
||||||
|
(defun +org--get-foldlevel ()
|
||||||
|
(let ((max 1))
|
||||||
|
(save-restriction
|
||||||
|
(narrow-to-region (window-start) (window-end))
|
||||||
|
(save-excursion
|
||||||
|
(goto-char (point-min))
|
||||||
|
(while (not (eobp))
|
||||||
|
(org-next-visible-heading 1)
|
||||||
|
(when (outline-invisible-p (line-end-position))
|
||||||
|
(let ((level (org-outline-level)))
|
||||||
|
(when (> level max)
|
||||||
|
(setq max level))))))
|
||||||
|
max)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun +org/show-next-fold-level ()
|
||||||
|
"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)))
|
||||||
|
(outline-hide-sublevels new-level)
|
||||||
|
(message "Folded to level %s" new-level)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun +org/hide-next-fold-level ()
|
||||||
|
"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))))
|
||||||
|
(outline-hide-sublevels new-level)
|
||||||
|
(message "Folded to level %s" new-level)))
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;; Hooks
|
;; Hooks
|
||||||
|
@ -331,21 +377,20 @@ wrong places)."
|
||||||
t))
|
t))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +org|toggle-only-current-fold ()
|
(defun +org|toggle-only-current-fold (&optional arg)
|
||||||
"Toggle the local fold at the point (as opposed to cycling through all levels
|
"Toggle the local fold at the point (as opposed to cycling through all levels
|
||||||
with `org-cycle')."
|
with `org-cycle')."
|
||||||
(interactive)
|
(interactive "P")
|
||||||
(unless (eq this-command 'org-shifttab)
|
(unless (eq this-command 'org-shifttab)
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(org-beginning-of-line)
|
(org-beginning-of-line)
|
||||||
(when (org-at-heading-p)
|
(when (org-at-heading-p)
|
||||||
(outline-toggle-children)
|
(when (or (not arg)
|
||||||
(unless (outline-invisible-p (line-end-position))
|
(outline-invisible-p (line-end-position)))
|
||||||
(org-cycle-hide-drawers 'subtree))
|
(outline-toggle-children)
|
||||||
t))))
|
(unless (outline-invisible-p (line-end-position))
|
||||||
|
(org-cycle-hide-drawers 'subtree))
|
||||||
;;;###autoload
|
t)))))
|
||||||
(defalias #'+org/toggle-fold #'+org|toggle-only-current-fold)
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +org|remove-occur-highlights ()
|
(defun +org|remove-occur-highlights ()
|
||||||
|
|
|
@ -317,13 +317,13 @@ between the two."
|
||||||
(evil-define-key* 'normal evil-org-mode-map
|
(evil-define-key* 'normal evil-org-mode-map
|
||||||
"za" #'+org/toggle-fold
|
"za" #'+org/toggle-fold
|
||||||
"zA" #'org-shifttab
|
"zA" #'org-shifttab
|
||||||
"zc" #'outline-hide-subtree
|
"zc" #'+org/close-fold
|
||||||
"zC" (λ! (outline-hide-sublevels 1))
|
"zC" #'outline-hide-subtree
|
||||||
"zd" (lambda (&optional arg) (interactive "p") (outline-hide-sublevels (or arg 3)))
|
"zm" #'+org/hide-next-fold-level
|
||||||
"zm" (λ! (outline-hide-sublevels 1))
|
"zo" #'+org/open-fold
|
||||||
"zo" #'outline-show-subtree
|
"zO" #'outline-show-subtree
|
||||||
"zO" #'outline-show-all
|
"zr" #'+org/show-next-fold-level
|
||||||
"zr" #'outline-show-all)
|
"zR" #'outline-show-all)
|
||||||
;; <localleader>
|
;; <localleader>
|
||||||
(map! :map evil-org-mode-map
|
(map! :map evil-org-mode-map
|
||||||
:localleader
|
:localleader
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue