emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/org 3b1693c461 043/101: org-back-to-heading: Use org-el


From: ELPA Syncer
Subject: [elpa] externals/org 3b1693c461 043/101: org-back-to-heading: Use org-element API
Date: Sat, 1 Jul 2023 09:59:04 -0400 (EDT)

branch: externals/org
commit 3b1693c461edc4b7bd9a637d118736f35709ceb2
Author: Ihor Radchenko <yantar92@posteo.net>
Commit: Ihor Radchenko <yantar92@posteo.net>

    org-back-to-heading: Use org-element API
---
 lisp/org.el | 54 ++++++++++++------------------------------------------
 1 file changed, 12 insertions(+), 42 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 34c4559b14..027862a11f 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -20511,53 +20511,23 @@ interactive command with similar behavior."
                     (<= (org-outline-level) level))))))))
 
 (defun org-back-to-heading (&optional invisible-ok)
-  "Go back to beginning of heading."
+  "Go back to beginning of heading or inlinetask."
   (beginning-of-line)
   (or (and (org-at-heading-p (not invisible-ok))
            (not (and (featurep 'org-inlinetask)
                    (fboundp 'org-inlinetask-end-p)
                    (org-inlinetask-end-p))))
-      (if (org-element--cache-active-p)
-          (let ((heading (org-element-lineage (org-element-at-point)
-                                           '(headline inlinetask)
-                                           'include-self)))
-            (when heading
-              (goto-char (org-element-begin heading)))
-            (while (and (not invisible-ok)
-                        heading
-                        (org-fold-folded-p))
-              (goto-char (org-fold-core-previous-visibility-change))
-              (setq heading (org-element-lineage (org-element-at-point)
-                                              '(headline inlinetask)
-                                              'include-self))
-              (when heading
-                (goto-char (org-element-begin heading))))
-            (unless heading
-              (user-error "Before first headline at position %d in buffer %s"
-                         (point) (current-buffer)))
-            (point))
-        (let (found)
-         (save-excursion
-            ;; At inlinetask end.  Move to bol, so that the following
-            ;; search goes to the beginning of the inlinetask.
-            (when (and (featurep 'org-inlinetask)
-                       (fboundp 'org-inlinetask-end-p)
-                       (org-inlinetask-end-p))
-              (goto-char (line-beginning-position)))
-           (while (not found)
-             (or (re-search-backward (concat "^\\(?:" outline-regexp "\\)")
-                                     nil t)
-                  (user-error "Before first headline at position %d in buffer 
%s"
-                             (point) (current-buffer)))
-              ;; Skip inlinetask end.
-              (if (and (featurep 'org-inlinetask)
-                       (fboundp 'org-inlinetask-end-p)
-                       (org-inlinetask-end-p))
-                  (org-inlinetask-goto-beginning)
-               (setq found (and (or invisible-ok (not (org-fold-folded-p)))
-                                (point))))))
-         (goto-char found)
-         found))))
+      (unless
+          (org-element-lineage-map
+              (org-element-at-point)
+              (lambda (el)
+                (goto-char (org-element-begin el))
+                (or invisible-ok (not (org-fold-folded-p))))
+            '(headline inlinetask)
+            'with-self 'first-match)
+        (user-error "Before first headline at position %d in buffer %s"
+                   (point) (current-buffer))))
+  (point))
 
 (defun org-back-to-heading-or-point-min (&optional invisible-ok)
   "Go back to heading or first point in buffer.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]