Implement simple custom columns for dynamic blocks
Allows passing a function in an org-ql dynamic block's columns list to act on a matched heading's Org element.
This commit is contained in:
parent
4b8330a683
commit
f9e4ac360f
1 changed files with 35 additions and 10 deletions
|
|
@ -287,18 +287,37 @@ Valid parameters include:
|
|||
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', `priority', `deadline', `scheduled',
|
||||
`closed', `custom'. 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\").
|
||||
|
||||
For a `custom' column, the first argument is a
|
||||
function, followed by any arguments to that
|
||||
function. A header string is required:
|
||||
|
||||
((custom my-func \"arg\") \"MyHeading\").
|
||||
|
||||
The custom function must return a string.
|
||||
|
||||
Note that the first argument passed to the custom
|
||||
function will be the Org element of the matched
|
||||
heading. So the function above will run as:
|
||||
|
||||
(my-func element \"arg\")
|
||||
|
||||
The alist of column lambdas in this function are
|
||||
useful starting points for writing your own custom
|
||||
column functions.
|
||||
|
||||
:sort One or a list of Org QL sorting methods
|
||||
(see `org-ql-select').
|
||||
|
||||
|
|
@ -345,7 +364,13 @@ this (must be a single line in the Org buffer):
|
|||
(--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)))))
|
||||
(org-element-property (intern (concat ":" (upcase property))) element)))
|
||||
(cons 'custom (lambda (element func &rest args)
|
||||
(let ((result (apply func element args)))
|
||||
(if (stringp result)
|
||||
result
|
||||
(error "org-dblock-write:org-ql: Custom column %s must return a string"
|
||||
(if (symbolp func) func "lambda"))))))))
|
||||
(elements (org-ql-query :from (current-buffer)
|
||||
:where query
|
||||
:select '(org-ql-view--resolve-element-properties
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue