I wrote some code to reschedule all headings under a subtree, but it was failing to get the scheduled date of heading in invisible lines, even though it could access other properties such as the name of the heading.
I debugged it with edebug
and noticed that the value of (point)
was always the same, even though different heading names were appearing in the *Messages*
buffer.
I used a quick fix of showing the full buffer with (org-shifttab 3)
and wrapping the last function inside a (org-save-outline-visibility t ...)
, but this seems inelegant and over the top.
I wonder if search-forward
that I am using in org-get-scheduled-timestring-at-point
does not move point to invisible lines, even though it forces lines with a match to become visible when used interactively.
Here is a minimal example with an Org-buffer:
* heading ** TODO task 1 SCHEDULED: [2019-12-26 Thu] *** DONE task 0 SCHEDULED: [2019-12-09 Mon] *** TODO sub task SCHEDULED: [2019-12-01 Thu] ** TODO task 2 SCHEDULED: [2020-01-01 Wed]
and the code:
(defun my-org-get-end-of-subtree ()
"Gets the index at the end of the subtree."
(save-excursion
(ignore-errors
(outline-end-of-subtree)
(point))))
(defun my-org-get-property ()
"Returns whether the scheduled date of the heading at point is in the past."
(interactive)
(save-excursion
(org-back-to-heading)
(message "Point is at %d" (point))
(search-forward (concat org-scheduled-string " ")) ; move point to the scheduled entry
(buffer-substring (point) (line-end-position))))
(defun my-org-test-fails ()
(interactive)
(let ((end (my-org-get-end-of-subtree)))
(when end
(save-excursion
(org-back-to-heading)
(while (and (outline-next-heading)
(< (point) end))
(message (my-org-get-property)))))))
(defun my-org-test-works ()
(interactive)
(let ((end (my-org-get-end-of-subtree)))
(when end
(org-save-outline-visibility t
(save-excursion
(org-shifttab 3)
(org-back-to-heading)
(while (and (outline-next-heading)
(< (point) end))
(message (my-org-get-property))))))))
The result in the *Messages*
buffer of running org-test-fails
and then org-test-works
is:
task 1 Point is at 68 [2019-12-26 Thu] done task Point is at 68 [2019-12-26 Thu] sub task Point is at 68 [2019-12-26 Thu] task 2 Point is at 68 [2019-12-26 Thu] ... task 1 Point is at 79 [2019-12-26 Thu] done task Point is at 123 [2019-12-09 Mon] sub task Point is at 171 [2019-12-01 Thu] task 2 Point is at 218 [2020-01-01 Wed]
How can I move point to a line that matches text and is invisible? Or how can I get the text of the SCHEDULED
property of an invisible heading just like I am able to get its heading text?
org-is-scheduled-date-today-or-in-past
your function or does org provide it? You should name your functions with a different prefix, so that we know what you are (supposed to be) providing and what Org mode is supposed to provide.