0

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?

4
  • 2
    Some suggestions: (1) provide some sample text that forum participants can cut and paste into an org-mode buffer to work with; (2) reduce the issue to just the problem with returning search results on invisible text; i.e., if rescheduling is not needed to resolve this issue, then eliminate rescheduling. If the goal is just to return a result such as a category of hidden property drawers, then a minimal working example with sample text seems like the most probable way to entice answers from forum participants .... That being said, some forum participants enjoy a challenge ... :)
    – lawlist
    Dec 18, 2019 at 8:25
  • Good points, thanks. I updated the question. Dec 18, 2019 at 15:50
  • 1
    Is 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.
    – NickD
    Dec 18, 2019 at 19:28
  • @NickD That was my function, which I had left in by mistake and have now removed. I fixed the prefixes in the question. I also started prefixing my functions for clarity. Thanks for the coding style suggestion. Dec 19, 2019 at 13:58

1 Answer 1

2

You should check out the Using the Property API section of the manual. In particular, doing (org-entry-get (point) "SCHEDULED") with point at the beginning of the headline returns the scheduled date of the entry, whether the headline is folded or not -- or even hidden: try hiding everything and execute

  (org-entry-get 12 "SCHEDULED")

on the tree you show above when everything is folded. I get the scheduled date of the headline "task 1": [2019-12-26 Thu].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.