org.el/org-goto-first-child: Support cache and passing element arg

This commit is contained in:
Ihor Radchenko 2021-10-16 23:38:46 +08:00
parent 5d162b7bcf
commit d43781707b
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 23 additions and 8 deletions

View File

@ -20777,17 +20777,32 @@ move point."
(while (org-goto-sibling 'previous)
(org-flag-heading nil))))
(defun org-goto-first-child ()
(defun org-goto-first-child (&optional element)
"Goto the first child, even if it is invisible.
Return t when a child was found. Otherwise don't move point and
return nil."
(let (level (pos (point)) (re org-outline-regexp-bol))
(when (org-back-to-heading-or-point-min t)
(setq level (org-outline-level))
(forward-char 1)
(if (and (re-search-forward re nil t) (> (org-outline-level) level))
(progn (goto-char (match-beginning 0)) t)
(goto-char pos) nil))))
(if (org-element--cache-active-p)
(when-let ((heading (org-element-lineage
(or element (org-element-at-point))
'(headline inlinetask org-data)
t)))
(unless (or (eq 'inlinetask (org-element-type heading))
(not (org-element-property :contents-begin heading)))
(let ((pos (point)))
(goto-char (org-element-property :contents-begin heading))
(if (re-search-forward
org-outline-regexp-bol
(org-element-property :end heading)
t)
(progn (goto-char (match-beginning 0)) t)
(goto-char pos) nil))))
(let (level (pos (point)) (re org-outline-regexp-bol))
(when (org-back-to-heading-or-point-min t)
(setq level (org-outline-level))
(forward-char 1)
(if (and (re-search-forward re nil t) (> (org-outline-level) level))
(progn (goto-char (match-beginning 0)) t)
(goto-char pos) nil)))))
(defun org-show-hidden-entry ()
"Show an entry where even the heading is hidden."