From 93c50e3a7867a1a85fc78b337172585f7a10dcc6 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Fri, 15 May 2020 23:48:48 +0200 Subject: [PATCH] Speed-up `org-(next|previous)-visible-heading * lisp/org.el (org-next-visible-heading): Do not stop at every invisible heading. (org-previous-visible-heading): Use `org-next-visible-heading'. --- lisp/org.el | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 339418314..dcd446745 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -20458,24 +20458,37 @@ Stop at the first and last subheadings of a superior heading." (org-forward-heading-same-level (if arg (- arg) -1) invisible-ok)) (defun org-next-visible-heading (arg) - "Move to the next visible heading. - -This function wraps `outline-next-visible-heading' with -`org-with-limited-levels' in order to skip over inline tasks and -respect customization of `org-odd-levels-only'." + "Move to the next visible heading line. +With ARG, repeats or can move backward if negative." (interactive "p") - (org-with-limited-levels - (outline-next-visible-heading arg))) + (let ((regexp (concat "^" (org-get-limited-outline-regexp))) + (initial-arg arg)) + (if (< arg 0) + (beginning-of-line) + (end-of-line)) + (while (and (< arg 0) (re-search-backward regexp nil :move)) + (unless (bobp) + (pcase (get-char-property-and-overlay (point) 'invisible) + (`(outline . ,o) + (goto-char (overlay-start o)) + (beginning-of-line)) + (_ nil))) + (cl-incf arg)) + (while (and (> arg 0) (re-search-forward regexp nil :move)) + (pcase (get-char-property-and-overlay (point) 'invisible) + (`(outline . ,o) + (goto-char (overlay-end o)) + (end-of-line 2)) + (_ + (end-of-line))) + (cl-decf arg)) + (when (/= arg initial-arg) (beginning-of-line)))) (defun org-previous-visible-heading (arg) "Move to the previous visible heading. - -This function wraps `outline-previous-visible-heading' with -`org-with-limited-levels' in order to skip over inline tasks and -respect customization of `org-odd-levels-only'." +With ARG, repeats or can move forward if negative." (interactive "p") - (org-with-limited-levels - (outline-previous-visible-heading arg))) + (org-next-visible-heading (- arg))) (defun org-forward-paragraph () "Move forward to beginning of next paragraph or equivalent.