-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow :file parameter in org-ql dynamic blocks #239
base: master
Are you sure you want to change the base?
Conversation
this Implements has a problem: it generate wrong headline link |
this Implements has a problem: it generate wrong headline link
Can you elaborate?
|
fb9591e
to
0045168
Compare
I see what you meant now. Should be fixed, though links may still be wrong for Org buffers without file. Not sure what can be done in the last scenario when the user also does not use org-id. |
Hi, |
I work on these projects in my spare time, which I don't have as much of as
I used to. If you would like to sponsor work on a particular feature, let
me know.
…On Tue, May 17, 2022, 05:54 Marc Fargas ***@***.***> wrote:
Hi,
May I ask what is preventing this PR to be merged? ended here searching
precisely about using the dynamic block across org-agenda-files
—
Reply to this email directly, view it on GitHub
<#239 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAES2FJAOEOASRT52XOIB3LVKN3HPANCNFSM5BYIVKCA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
I understand. I was mostly asking about feedback on the last comment in this PR to see if I could continue @yantar92 's work (or if my, currently very limited, Elisp is not yet enough for it). |
4f5fbc4
to
d0acc8c
Compare
What's the status for this? Any easy way to help? |
For anyone wanting this feature: (require 'org-ql-search)
(cl-defun org-dblock-write:my-org-ql (params)
"Insert content for org-ql dynamic block at point according to PARAMS.
Valid parameters include:
:scope The scope to consider for the Org QL query. This can
be one of the following:
`buffer' the current buffer
`org-agenda-files' all agenda files
`org-directory' all org files
`(\"path\" ...)' list of buffer names or file paths
`all' all agenda files, and org-mode buffers
:query An Org QL query expression in either sexp or string
form.
:columns A list of columns, including `heading', `todo',
`property',`priority',`deadline',`scheduled',`closed'.
Each column may also be specified as a list with the
second element being a header string. For example,
to abbreviate the priority column: (priority \"P\").
For certain columns, like `property', arguments may
be passed by specifying the column type itself as a
list. For example, to display a column showing the
values of a property named \"milestone\", with the
header being abbreviated to \"M\":
((property \"milestone\") \"M\").
:sort One or a list of Org QL sorting methods
(see `org-ql-select').
:take Optionally take a number of results from the front (a
positive number) or the end (a negative number) of
the results.
:ts-format Optional format string used to format
timestamp-based columns.
For example, an org-ql dynamic block header could look like:
#+BEGIN: org-ql :query (todo \"UNDERWAY\") :columns (priority todo heading) :sort (priority date) :ts-format \"%Y-%m-%d %H:%M\""
(-let* (((&plist :scope :query :columns :sort :ts-format :take) params)
(query (cl-etypecase query
(string (org-ql--query-string-to-sexp query))
(list ;; SAFETY: Query is in sexp form: ask for confirmation, because it could contain arbitrary code.
(org-ql--ask-unsafe-query query)
query)))
(columns (or columns '(heading todo (priority "P"))))
(scope (cond ((and (listp scope) (seq-every-p #'stringp scope)) scope)
((string-equal scope "org-agenda-files") (org-agenda-files))
((or (not scope) (string-equal scope "buffer")) (current-buffer))
((string-equal scope "org-directory") (org-ql-search-directories-files))
(t (user-error "Unknown scope '%s'" scope))))
;; MAYBE: Custom column functions.
(format-fns
;; NOTE: Backquoting this alist prevents the lambdas from seeing
;; the variable `ts-format', so we use `list' and `cons'.
(list (cons 'todo (lambda (element)
(org-element-property :todo-keyword element)))
(cons 'heading (lambda (element)
(cond
((and org-id-link-to-org-use-id
(org-element-property :ID element))
(org-make-link-string (format "id:%s" (org-element-property :ID element))
(org-element-property :raw-value element)))
((org-element-property :file element)
(org-make-link-string (format "file:%s::*%s"
(org-element-property :file element)
(org-element-property :raw-value element))
(org-element-property :raw-value element)))
(t (org-make-link-string (org-element-property :raw-value element)
(org-link-display-format
(org-element-property :raw-value element)))))
))
(cons 'priority (lambda (element)
(--when-let (org-element-property :priority element)
(char-to-string it))))
(cons 'deadline (lambda (element)
(--when-let (org-element-property :deadline element)
(ts-format ts-format (ts-parse-org-element it)))))
(cons 'scheduled (lambda (element)
(--when-let (org-element-property :scheduled element)
(ts-format ts-format (ts-parse-org-element it)))))
(cons 'closed (lambda (element)
(--when-let (org-element-property :closed element)
(ts-format ts-format (ts-parse-org-element it)))))
(cons 'property (lambda (element property)
(org-element-property (intern (concat ":" (upcase property))) element)))))
(elements (org-ql-query :from scope
:where query
:select '(org-element-put-property (org-element-headline-parser (line-end-position)) :file (buffer-file-name))
:order-by sort)))
(when take
(setf elements (cl-etypecase take
((and integer (satisfies cl-minusp)) (-take-last (abs take) elements))
(integer (-take take elements)))))
(cl-labels ((format-element
(element) (string-join (cl-loop for column in columns
collect (or (pcase-exhaustive column
((pred symbolp)
(funcall (alist-get column format-fns) element))
(`((,column . ,args) ,_header)
(apply (alist-get column format-fns) element args))
(`(,column ,_header)
(funcall (alist-get column format-fns) element)))
""))
" | ")))
;; Table header
(insert "| " (string-join (--map (pcase it
((pred symbolp) (capitalize (symbol-name it)))
(`(,_ ,name) name))
columns)
" | ")
" |" "\n")
(insert "|- \n") ; Separator hline
(dolist (element elements)
(insert "| " (format-element element) " |" "\n"))
(delete-char -1)
(org-table-align))))
seems to work for me (which is basically diff of this pr pasted into current code). use with For my personal version I also patched it to have |
It would be nice if the parameter accepted a function that returns a list of files. See |
I don't know. I'll have to review it when I have time.
…On Wed, May 18, 2022, 05:17 Marc Fargas ***@***.***> wrote:
I work on these projects in my spare time
I understand. I was mostly asking about feedback on the last comment
<#239 (comment)> in
this PR to see if I could continue @yantar92 <https://github.com/yantar92>
's work (or if my, currently very limited, Elisp is not yet enough for it).
—
Reply to this email directly, view it on GitHub
<#239 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAES2FKXBE64UYNXKQIKAFTVKS7UZANCNFSM5BYIVKCA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
*patiently waiting for this feature* 👍 🏅 🙈 [I added |
059b10c
to
77b4c2b
Compare
Thanks @hrehfeld that elisp in #239 (comment) works for me. I made a small change so that it accepts a function name like clocktables.
Anyway, I am stoked about finding this. |
Implements #151