@@ -242,6 +242,15 @@ automatically from the query."
242
242
" Insert content for org-ql dynamic block at point according to PARAMS.
243
243
Valid parameters include:
244
244
245
+ :scope The scope to consider for the Org QL query. This can
246
+ be one of the following:
247
+
248
+ `buffer' the current buffer
249
+ `org-agenda-files' all agenda files
250
+ `org-directory' all org files
251
+ `(list-of-files ...)' a list of org files
252
+ `all' all agenda files, and org-mode buffers
253
+
245
254
:query An Org QL query expression in either sexp or string
246
255
form.
247
256
@@ -271,23 +280,30 @@ Valid parameters include:
271
280
For example, an org-ql dynamic block header could look like:
272
281
273
282
#+BEGIN: org-ql :query (todo \" UNDERWAY\" ) :columns (priority todo heading) :sort (priority date) :ts-format \" %Y-%m-%d %H:%M\" "
274
- (-let* (((&plist :query :columns :sort :ts-format :take ) params)
283
+ (-let* (((&plist :scope : query :columns :sort :ts-format :take ) params)
275
284
(query (cl-etypecase query
276
- (string (org-ql--query-string-to-sexp query))
285
+ (string (org-ql--plain-query query))
277
286
(list ; ; SAFETY: Query is in sexp form: ask for confirmation, because it could contain arbitrary code.
278
287
(org-ql--ask-unsafe-query query)
279
288
query)))
280
289
(columns (or columns '(heading todo (priority " P" ))))
290
+ (scope (cond ((listp scope) scope)
291
+ ((string-equal scope " org-agenda-files" ) (org-agenda-files ))
292
+ ((or (not scope) (string-equal scope " buffer" )) (current-buffer ))
293
+ ((string-equal scope " org-directory" ) (org-ql-search-directories-files))
294
+ (t (user-error " Unknown scope '%s'" scope))))
281
295
; ; MAYBE: Custom column functions.
282
296
(format-fns
283
297
; ; NOTE: Backquoting this alist prevents the lambdas from seeing
284
298
; ; the variable `ts-format' , so we use `list' and `cons' .
285
299
(list (cons 'todo (lambda (element )
286
300
(org-element-property :todo-keyword element)))
287
301
(cons 'heading (lambda (element )
288
- (org-make-link-string (org-element-property :raw-value element)
289
- (org-link-display-format
290
- (org-element-property :raw-value element)))))
302
+ (let ((m (plist-get (cadr element) :org-hd-marker )))
303
+ (with-current-buffer (marker-buffer m)
304
+ (save-excursion
305
+ (goto-char m)
306
+ (org-store-link nil nil ))))))
291
307
(cons 'priority (lambda (element )
292
308
(--when-let (org-element-property :priority element)
293
309
(char-to-string it))))
@@ -299,9 +315,9 @@ For example, an org-ql dynamic block header could look like:
299
315
(ts-format ts-format (ts-parse-org-element it)))))
300
316
(cons 'property (lambda (element property )
301
317
(org-element-property (intern (concat " :" (upcase property))) element)))))
302
- (elements (org-ql-query :from ( current-buffer )
318
+ (elements (org-ql-query :from scope
303
319
:where query
304
- :select '(org- element-headline-parser ( line-end-position ))
320
+ :select 'element-with-markers
305
321
:order-by sort)))
306
322
(when take
307
323
(setf elements (cl-etypecase take
0 commit comments