org-ql
org-ql copied to clipboard
org-ql-agenda: Custom formatter support
Is there a way to force org-ql-agenda
to show the name of the buffer from which each task is derived? I tried adding :auto-category t
to :super-groups
but it didn't work (i.e., it probably groups by category but still doesn't show the name of the category).
You could modify the formatter to do so.
By this do you mean modifying this function to show the buffer source?
Yes. You can see a comment at the bottom that mentions adding the proper prefix, which refers to imitating org-agenda-prefix-format
. Adding support for that would let you set the prefix according to your preferences.
Alternatively, you could use simple :after
function advice to alter the string returned by the function.
I probably won't work on this soon, but it's a good idea.
https://github.com/alphapapa/org-ql/pull/44
Isn't this already supported with the use of "select" in org-ql-query? There one can provide a custom sexp to format the output. Same with the action argument to org-ql-select, no?
Is there a reason for not using the same functionality in the org-ql views?
@Whil- If you want to override the formatting function used in org-ql-view
, you could use function advice. As I've said in other issues, I'm not very interested in adding little things that would be intended to be deprecated in the future.
Got it, thanks. Though providing the select functionality also for the view function should hardly be considered minor. Thinking of org mode documents as a database of entities is very powerful and org-ql is very helpful with this. And allowing the output from the query on the database to be customized by for example adding attributes from the nodes etc. makes a lot of sense.
This ofc already is possible using org-ql-select and org-ql-query. So I'll just finish with a thumbs up for that! π
Though providing the select functionality also for the view function should hardly be considered minor.
What I mean is, since I plan to implement a new view library, I don't want to spend much effort on implementing formatting changes that would be obsoleted by the future plans.
In the meantime, you can use advice-add
or cl-letf
to override the formatting function in your code.
However, since this has taken a while, it might be worth adding an argument and/or a variable to let users more easily change the formatting function.
As I have pointed out here on reddit, the URL from OP provided in link is not working anymore. So I don't know which format function he is referencing.
Also does that mean - asked from an Elisp newbie - I need to go into the source code and modify the format function? Or the returned string?
Let's pick one place or the other to have this conversation. I'll reply on Reddit again.
For completeness I'll repost the solution via adding an advice here as well, if you don't mind?
(defun ugt/org-ql-view--format-element (orig-fun &rest args)
"This function will intercept the original function and
add the filename to the result.
ARGS is `element' in `org-ql-view--format-element'"
(if (not args)
""
(let* ((element args)
(properties (cadar element))
(result (apply orig-fun element))
(filename (buffer-name
(marker-buffer
(plist-get properties :org-marker)))))
(concat filename " " result))))
(advice-add 'org-ql-view--format-element :around #'ugt/org-ql-view--format-element)
Minor tweak to @pragmat1c1 code. In case someone wants to add category instead of filename. updated properties as mentioned @ reddit comment
(defun ugt/org-ql-view--format-element (orig-fun &rest args)
"This function will intercept the original function and
add the category to the result.
ARGS is `element' in `org-ql-view--format-element'"
(if (not args)
""
(let* ((element args)
(properties (cadar element))
(result (apply orig-fun element))
(category (get-text-property
0
'org-category
(plist-get properties :todo-keyword))))
(org-add-props (concat category ":" result) (text-properties-at 0 result)))))
(advice-add 'org-ql-view--format-element :around #'ugt/org-ql-view--format-element)
Since it's been so long since the last 0.x release, I'm going to defer this to 0.7 in an effort to reduce the scope of 0.6 and release it sooner.
I'm using this version of org-ql:
Status: Installed in βorg-ql-20220301.841/β (unsigned).
Version: 20220301.841
Commit: af18eac2b80b2f56c135f37fcbdcce19fbc34b65
and the function from the comment above returns an empty category.
Here's the fixed version:
(defun zdo/org-ql-view--format-element (orig-fun &rest args)
"This function will intercept the original function and
add the category to the result.
ARGS is `element' in `org-ql-view--format-element'"
(if (not args)
""
(let* ((element args)
(properties (cadar element))
(result (apply orig-fun element))
(category (org-entry-get (plist-get properties :org-marker) "CATEGORY")))
(org-add-props
(format " %-8s %s" (concat category ":") result)
(text-properties-at 0 result)))))
(advice-add 'org-ql-view--format-element :around #'zdo/org-ql-view--format-element)
with nice indentation π

For future reference, this issue will generally be addressed by the branch mentioned here: https://github.com/alphapapa/org-ql/issues/331
Thanks @dmitri-zganiaiko. I added some modifications to make sure the indentation will work too if the file or buffer name are too long.
(defun salih/org-ql-view--format-element (orig-fun &rest args)
"This function will intercept the original function and
add the category to the result.
ARGS is `element' in `org-ql-view--format-element'"
(if (not args)
""
(let* ((element args)
(properties (cadar element))
(result (apply orig-fun element))
(smt "")
(category (org-entry-get (plist-get properties :org-marker) "CATEGORY")))
(if (> (length category) 11)
(setq category (substring category 0 10)))
(if (< (length category) 11)
(setq smt (make-string (- 11 (length category)) ?\s)))
(org-add-props
(format " %-8s %s" (concat category ":" smt) result)
(text-properties-at 0 result)))))
Hi, I'm looking for a way to format a org-ql-block
and this issue is related, but I think it's meant to be applied in a bigger scope than org-ql-block
How do I supply a formatting option to an individual org-ql-block? For instance, How can I turn the following code into org-ql-block?
(tags-todo "inbox"
((org-agenda-prefix-format " %?-12t% s")
(org-agenda-overriding-header "\nInbox\n")))
Thank you for the support
@pcompassion For the header, please see the documentation: https://github.com/alphapapa/org-ql#function-org-ql-block The formatter is not yet customizeable, other than editing the function, which you're welcome to do in your configuration, but you'll be on your own for that.