reddit / emacs

org-ql-search - Show properties in search results?

pragmat1c1 · 2022-05-05 12:03
I am using u/github-alphapapa 's excellent **org-ql** package for all sorts of things. Below is a function that generates a list of journal entries I have created using **org-journal.** In that example below I'd love to add a property ("CREATED") to the search results, so that I can see when the item was written. Is there a way to add properties in query results in "org-ql-search"? ``` (defun ugt-org-ql--datestamped-list-of-org-journal-entries (&optional arg) "Datestamp list of entries in Org files" (interactive "P") ;; set global name for ;; using in advice-add! (setq org-ql-view-buffer "*List of org journal entries*") (let ((num-days-back (if arg (- arg) -100))) (eval `(org-ql-search org-journal-files '(and ;;(heading "mindfulness") (ts-i :from ,num-days-back :to today)) :title ,org-ql-view-buffer ;;:columns '(property "CREATED") ;; <-- does not work :sort '(date) :super-groups '((:auto-ts-closed t) ;;(:property "CREATED") ))))) ```
akirakom · 2022-05-05 17:42
I don't think it's possible without some hack. One obvious way would be to temporarily advice `org-ql-view--format-element`.
pragmat1c1 · 2022-05-05 20:06
Thank you for the hint. I have dug out my own solution from two years ago from here: https://www.reddit.com/r/emacs/comments/jiaseq/comment/ga7h0pi/?utm_source=share&utm_medium=web2x&context=3 And came up with this: ``` (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)))) (created-date (plist-get properties :CREATED))) ;;(concat filename " " result) (concat created-date " " result) ))) (advice-add 'org-ql-view--format-element :around #'ugt/org-ql-view--format-element) ```