Ihor Radchenko <[email protected]> writes:
lou <[email protected]> writes:
Yeah. Looks like prefix is computed _before_ category is
produced for
agenda. So, org-agenda-get-category is too early to be useful.
So you may need `org-agenda-with-point-at-orig-entry' as I
said
in the
updated docstring.
wrapping prefix-fn in `org-agenda-with-point-at-orig-entry'
produces an error (stacktrace is below).
But it also does not make sense. If %(..) is evaluated in the
agenda buffer why does `buffer-file-name` point to the buffer
of
the entry?
Hmm. Right. What I think happens is that *some* lines in agenda
are
computed inside Org buffer, but *some* are computed inside
agenda
buffer. Specifically, Org heading lines are computed inside Org
buffers,
while time indicators are inside agenda buffers (also, diary
entries -
inside diary buffers).
So, it is more complex (as usual in agenda code).
Yeah that seems right. I think the doc string to
`org-agenda-prefix-format` should probably be explicit about not
being able to rely on it being evaluated either in the agender or
the org buffer.
Also calling `org-get-category` *gets* the category, it just
produces also a warning, while `org-agenda-get-category`
returns
nil. To me this looks off.
org-agenda-get-category looks inside agenda buffer, at the text
properties set for agenda lines. If the text properties are
empty (as
they are before prefix is computed), it returns nil.
org-get-category returns "???" when no category is found.
Note that the initial problem (the warning) only occurs with
timestamped entries on the current date. For any other kind of
Agenda entry calling `org-get-category` works completely
without
issue.
Likely because of time grid lines that are computed inside
agenda
buffer and also trigger prefix calculation. Without time grid, I
expect
most things to run inside Org buffer.
I can confirm that setting `org-agenda-use-time-grid` also gets
rid of the warning.
While looking at `org-agenda-format-item` and trying to figure out
where exactly the prefix is composed I realised that there are a
bunch of dynamically scoped variables in that function. Including
`category`. So this works, without any erros or warnings:
* This is a header with a timestamp
:PROPERTIES:
:CATEGORY: test
:END:
<2025-12-16 Di 12:00-14:00>
#+begin_src emacs-lisp
(setq org-agenda-files (list (buffer-file-name (current-buffer))))
(setq org-agenda-prefix-format '((agenda . "%(symbol-value 'category)")))
(org-agenda)
#+end_src
#+RESULTS:
But obv. depends on the internals of that function.
~lou