Change/Fix: (org-ql--add-agenda-markers) Rename and use copy-marker

org-agenda-new-marker sometimes raises "selecting deleted buffer"
errors, and other times returns markers that don't point into a
buffer (I don't even know how that's possible).  copy-marker always
works, so we'll use it, even though it might leave markers hanging
around which theoretically could affect performance over time (but
isn't Emacs still supposed to GC them?  I'm not sure).

Also, rename it to org-ql--add-markers, since we're not adding
"agenda" markers anymore.
This commit is contained in:
Adam Porter 2018-08-22 14:15:28 -05:00
parent a9a4ac33d8
commit 90aa62a5af

View file

@ -52,7 +52,7 @@ buffer. In this case, ACTION should return an Org element."
;; headline element, which --add-markers works with. On the other hand, ;; headline element, which --add-markers works with. On the other hand,
;; maybe this should be on the agenda-ng side. ;; maybe this should be on the agenda-ng side.
(->> ,action (->> ,action
org-ql--add-agenda-markers))))) org-ql--add-markers)))))
`(org-ql--query ,buffers-or-files `(org-ql--query ,buffers-or-files
',pred-body ',pred-body
:action ,action :action ,action
@ -78,7 +78,7 @@ point at the beginning of its heading. For example,
`org-element-headline-parser' may be used to parse an entry into `org-element-headline-parser' may be used to parse an entry into
an Org element (note that it must be called with a limit an Org element (note that it must be called with a limit
argument, so a lambda must be used to do so). Also see argument, so a lambda must be used to do so). Also see
`org-ql--add-agenda-markers', which may be used to add markers `org-ql--add-markers', which may be used to add markers
compatible with Org Agenda code. compatible with Org Agenda code.
If NARROW is non-nil, buffers are not widened. If NARROW is non-nil, buffers are not widened.
@ -187,13 +187,16 @@ If NARROW is non-nil, buffer will not be widened."
;;;;; Helpers ;;;;; Helpers
(defun org-ql--add-agenda-markers (element) (defun org-ql--add-markers (element)
"Return ELEMENT with Org Agenda marker text properties added. "Return ELEMENT with Org marker text properties added.
ELEMENT should be an Org element like that returned by ELEMENT should be an Org element like that returned by
`org-element-headline-parser'. This function should be called `org-element-headline-parser'. This function should be called
from within ELEMENT's buffer. It calls `org-agenda-new-marker', from within ELEMENT's buffer."
which see." ;; FIXME: `org-agenda-new-marker' works, until it doesn't, because...I don't know. It sometimes
(let* ((marker (org-agenda-new-marker (org-element-property :begin element))) ;; raises errors or returns markers that don't point into a buffer. `copy-marker' always works,
;; of course, but maybe it will leave "dangling" markers, which could affect performance over
;; time? I don't know, but for now, it seems that we have to use `copy-marker'.
(let* ((marker (copy-marker (org-element-property :begin element)))
(properties (--> (cadr element) (properties (--> (cadr element)
(plist-put it :org-marker marker) (plist-put it :org-marker marker)
(plist-put it :org-hd-marker marker)))) (plist-put it :org-hd-marker marker))))