-
Notifications
You must be signed in to change notification settings - Fork 109
/
org-ql.info
2230 lines (1815 loc) · 81.5 KB
/
org-ql.info
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
This is README.info, produced by makeinfo version 6.7 from README.texi.
INFO-DIR-SECTION Emacs
START-INFO-DIR-ENTRY
* Org QL: (org-ql). Query language, search commands, and saved views for Org files.
END-INFO-DIR-ENTRY
File: README.info, Node: Top, Next: Contents, Up: (dir)
org-ql
******
This package provides a query language for Org files. It offers two
syntax styles: Lisp-like sexps and search engine-like keywords.
It includes three libraries: The ‘org-ql’ library is flexible and may
be used as a backend for other tools. The libraries ‘org-ql-search’ and
‘helm-org-ql’ (a separate package) provide interactive search commands
and saved views.
* Menu:
* Contents::
* Screenshots::
* Installation::
* Usage::
* Changelog::
* Development::
* Notes::
* License::
— The Detailed Node Listing —
Installation
* Quelpa::
* Helm support::
Usage
* Commands::
* Queries::
* Functions / Macros::
* Dynamic block::
* Links::
* Tips::
Commands
* org-ql-find::
* org-ql-open-link::
* org-ql-refile::
* org-ql-search::
* helm-org-ql::
* org-ql-view::
* org-ql-view-sidebar::
* org-ql-view-recent-items::
* org-ql-sparse-tree::
Queries
* Non-sexp query syntax::
* General predicates::
* Ancestor/descendant predicates::
* Date/time predicates::
Functions / Macros
* Agenda-like views::
* Listing / acting-on results::
* Custom predicates::
Changelog
* 0.9-pre: 09-pre.
* 0.8.10: 0810.
* 0.8.9: 089.
* 0.8.8: 088.
* 0.8.7: 087.
* 0.8.6: 086.
* 0.8.5: 085.
* 0.8.4: 084.
* 0.8.3: 083.
* 0.8.2: 082.
* 0.8.1: 081.
* 0.8: 08.
* 0.7.4: 074.
* 0.7.3: 073.
* 0.7.2: 072.
* 0.7.1: 071.
* 0.7: 07.
* 0.6.3: 063.
* 0.6.2: 062.
* 0.6.1: 061.
* 0.6: 06.
* 0.5.2: 052.
* 0.5.1: 051.
* 0.5: 05.
* 0.4.9: 049.
* 0.4.8: 048.
* 0.4.7: 047.
* 0.4.6: 046.
* 0.4.5: 045.
* 0.4.4: 044.
* 0.4.3: 043.
* 0.4.2: 042.
* 0.4.1: 041.
* 0.4: 04.
* 0.3.2: 032.
* 0.3.1: 031.
* 0.3: 03.
* 0.2.3: 023.
* 0.2.2: 022.
* 0.2.1: 021.
* 0.2: 02.
* 0.1: 01.
0.9-pre
* helm-org-ql: helm-org-ql (1).
Development
* Copyright assignment::
Notes
* Comparison with Org Agenda searches::
* org-sidebar::
File: README.info, Node: Contents, Next: Screenshots, Prev: Top, Up: Top
1 Contents
**********
• • • • •
File: README.info, Node: Screenshots, Next: Installation, Prev: Contents, Up: Top
2 Screenshots
*************
File: README.info, Node: Installation, Next: Usage, Prev: Screenshots, Up: Top
3 Installation
**************
The package ‘org-ql’ may be installed directly from MELPA
(https://melpa.org/#/org-ql) or with other tools like Quelpa
(https://framagit.org/steckerhalter/quelpa).
After installation, you can use the commands without additional
configuration. To use the functions and macros in your own Elisp code,
use libraries ‘org-ql’ and ‘org-ql-view’.
* Menu:
* Quelpa::
* Helm support::
File: README.info, Node: Quelpa, Next: Helm support, Up: Installation
3.1 Quelpa
==========
Installing with Quelpa (https://framagit.org/steckerhalter/quelpa) is
easy:
1. Install quelpa-use-package
(https://framagit.org/steckerhalter/quelpa-use-package#installation)
(which can be installed directly from MELPA).
2. Add this form to your init file:
(use-package org-ql
:quelpa (org-ql :fetcher github :repo "alphapapa/org-ql"
:files (:defaults (:exclude "helm-org-ql.el"))))
File: README.info, Node: Helm support, Prev: Quelpa, Up: Installation
3.2 Helm support
================
The command ‘helm-org-ql’ is available in the package ‘helm-org-ql’. It
may be installed from MELPA, or with Quelpa, like so:
(use-package helm-org-ql
:quelpa (helm-org-ql :fetcher github :repo "alphapapa/org-ql"
:files ("helm-org-ql.el")))
File: README.info, Node: Usage, Next: Changelog, Prev: Installation, Up: Top
4 Usage
*******
• •
• • • • • • • •
Feedback on these APIs is welcome. Eventually, after being tested
and polished, they will be considered stable.
Lisp code examples are in .
* Menu:
* Commands::
* Queries::
* Functions / Macros::
* Dynamic block::
* Links::
* Tips::
File: README.info, Node: Commands, Next: Queries, Up: Usage
4.1 Commands
============
• *Jumping to an entry:*
• and related commands
• • *Showing an agenda-like view:*
• • • • • *Showing a tree in a buffer:*
•
* Menu:
* org-ql-find::
* org-ql-open-link::
* org-ql-refile::
* org-ql-search::
* helm-org-ql::
* org-ql-view::
* org-ql-view-sidebar::
* org-ql-view-recent-items::
* org-ql-sparse-tree::
File: README.info, Node: org-ql-find, Next: org-ql-open-link, Up: Commands
4.1.1 org-ql-find
-----------------
_Note: These commands use ._
These commands jump to a heading selected using Emacs’s built-in
completion facilities with an Org QL query:
• ‘org-ql-find’ searches in the current buffer.
• ‘org-ql-find-path’ searches outline paths in the current buffer.
• ‘org-ql-find-in-agenda’ searches in ‘(org-agenda-files)’.
• ‘org-ql-find-in-org-directory’ searches in ‘org-directory’.
Note that these commands are compatible with Embark
(https://github.com/oantolin/embark): the ‘embark-act’ command can be
called on a completion candidate (i.e. a search result) to act on it
immediately, without having to visit the entry in its source Org buffer,
and ‘embark-export’ may be called to show the results in an
‘org-ql-view’ buffer.
File: README.info, Node: org-ql-open-link, Next: org-ql-refile, Prev: org-ql-find, Up: Commands
4.1.2 org-ql-open-link
----------------------
This command finds links in entries matching the input query and offers
them for selection; the selected link is then opened with
‘org-open-at-point’.
The input is matched using the default predicate, which means it
searches both entry content and outline paths. This is helpful when a
collection of links are kept in Org files: rather than having to first
visit the entry containing the desired link, then locate it within the
entry, and then open it, the user can simply select the link and open it
directly. For example, if an entry with the heading ‘Emacs’ contained a
link named ‘mailing list’, one could search for ‘Emacs list’ and open
the link to the mailing list directly.
File: README.info, Node: org-ql-refile, Next: org-ql-search, Prev: org-ql-open-link, Up: Commands
4.1.3 org-ql-refile
-------------------
This command refiles the current Org entry to one selected by searching
with Org QL completion. It searches files listed in
‘org-refile-targets’ as well as the current buffer.
File: README.info, Node: org-ql-search, Next: helm-org-ql, Prev: org-ql-refile, Up: Commands
4.1.4 org-ql-search
-------------------
_Note: This command supports both sexp queries and ._
Read ‘QUERY’ and search with ‘org-ql’. Interactively, prompt for
these variables:
‘BUFFERS-FILES’: ‘A’ list of buffers and/or files to search.
Interactively, may also be:
• ‘buffer’: search the current buffer
• ‘all’: search all Org buffers
• ‘agenda’: search buffers returned by the function
‘org-agenda-files’
• A space-separated list of file or buffer names
‘GROUPS’: An ‘org-super-agenda’ group set. See variable
‘org-super-agenda-groups’.
‘NARROW’: When non-nil, don’t widen buffers before searching.
Interactively, with prefix, leave narrowed.
‘SORT’: One or a list of ‘org-ql’ sorting functions, like ‘date’ or
‘priority’.
*Bindings:* Keys bound in results buffer.
• ‘r’: Refresh results. With prefix, prompt to adjust search
parameters.
• ‘v’: Show ‘transient’ view dispatcher (like Magit’s popups).
• ‘C-x C-s’: Save query to variable ‘org-ql-views’ (accessible with
command ‘org-ql-view’).
*Note:* The view buffer is currently put in ‘org-agenda-mode’, which
means that _some_ Org Agenda commands work, such as jumping to entries
and changing item priorities (without necessarily updating the view).
This feature is experimental and not guaranteed to work correctly with
all commands. (It works to the extent it does because the appropriate
text properties are placed on each item, imitating an Agenda buffer.)
*Note:* Also, this buffer is compatible with Embark
(https://github.com/oantolin/embark): the ‘embark-act’ command can be
called on an entry to act on it immediately, without having to visit the
entry in its source Org buffer.
File: README.info, Node: helm-org-ql, Next: org-ql-view, Prev: org-ql-search, Up: Commands
4.1.5 helm-org-ql
-----------------
_Note: This command uses . It is available separately in the package
‘helm-org-ql’._
This command displays matches with Helm.
• Press ‘C-x C-s’ in the Helm session to save the results to an
‘org-ql-search’ buffer.
File: README.info, Node: org-ql-view, Next: org-ql-view-sidebar, Prev: helm-org-ql, Up: Commands
4.1.6 org-ql-view
-----------------
Choose and display a view stored in ‘org-ql-views’.
*Bindings:* Keys bound in view buffer.
• ‘g’, ‘r’: Refresh results. With prefix, prompt to adjust search
parameters.
• ‘v’: Show ‘transient’ view dispatcher (like Magit’s popups).
• ‘C-x C-s’: Save query to variable ‘org-ql-views’ (accessible with
command ‘org-ql-view’).
File: README.info, Node: org-ql-view-sidebar, Next: org-ql-view-recent-items, Prev: org-ql-view, Up: Commands
4.1.7 org-ql-view-sidebar
-------------------------
Show a sidebar window listing views stored in ‘org-ql-views’ for easy
access. In the sidebar, press ‘RET’ or ‘mouse-1’ to show the view at
point, and press ‘c’ to customize the view at point.
File: README.info, Node: org-ql-view-recent-items, Next: org-ql-sparse-tree, Prev: org-ql-view-sidebar, Up: Commands
4.1.8 org-ql-view-recent-items
------------------------------
Show items in ‘FILES’ from last ‘DAYS’ days with timestamps of ‘TYPE’.
‘TYPE’ may be ‘ts’, ‘ts-active’, ‘ts-inactive’, ‘clocked’, ‘closed’,
‘deadline’, ‘planning’, or ‘scheduled’. ‘FILES’ defaults to those
returned by the function ‘org-agenda-files’.
File: README.info, Node: org-ql-sparse-tree, Prev: org-ql-view-recent-items, Up: Commands
4.1.9 org-ql-sparse-tree
------------------------
Arguments: ‘(query &key keep-previous (buffer (current-buffer)))’
Show a sparse tree for ‘QUERY’ in ‘BUFFER’ and return number of
results. The tree will show the lines where the query matches, and any
other context defined in ‘org-show-context-detail’, which see.
‘QUERY’ is an ‘org-ql’ query sexp (quoted, since this is a function).
‘BUFFER’ defaults to the current buffer. When ‘KEEP-PREVIOUS’ is
non-nil (interactively, with prefix), the outline is not reset to the
overview state before finding matches, which allows stacking calls to
this command. Runs ‘org-occur-hook’ after making the sparse tree.
File: README.info, Node: Queries, Next: Functions / Macros, Prev: Commands, Up: Usage
4.2 Queries
===========
• • • •
An ‘org-ql’ query is a Lisp expression which may contain arbitrary
expressions, as well as calling certain built-in predicates. It is
byte-compiled into a predicate function which is tested with point on
each heading in an Org buffer; when it returns non-nil, the heading
matches the query. When possible, certain built-in predicates are
optimized away to whole-buffer regular expression searches, which are
much faster to search for than testing the predicate on each heading.
*Notes:*
• Bare strings like ‘"string"’ are automatically converted to
‘(regexp "string")’ predicates.
• Standard numeric comparator function symbols (‘<’, ‘<=’, ‘>’, ‘>=’,
‘=’ ) need not be quoted when passed as an argument to predicates
which accept them. The resemblance to infix notation is
coincidental.
* Menu:
* Non-sexp query syntax::
* General predicates::
* Ancestor/descendant predicates::
* Date/time predicates::
File: README.info, Node: Non-sexp query syntax, Next: General predicates, Up: Queries
4.2.1 Non-sexp query syntax
---------------------------
The command ‘org-ql-search’ also accepts, and the command ‘helm-org-ql’
only accepts, an alternative, non-sexp query syntax. The syntax is
simple, and a few examples of queries in both syntaxes should suffice.
By default, when multiple predicates are used, they are combined with
boolean ‘and’.
Sexp syntax Non-sexp syntax
-------------------------------------------------------------------------------------------------------
‘(todo)’ ‘todo:’
‘(todo "SOMEDAY")’ ‘todo:SOMEDAY’
‘(todo "SOMEDAY" "WAITING")’ ‘todo:SOMEDAY,WAITING’
‘(ts :on today)’ ‘ts:on=today’
‘(ts-active :from "2017-01-01" :to "2018-01-01")’ ‘ts-active:from=2017-01-01,to=2018-01-01’
‘(clocked :on -1)’ ‘clocked:on=-1’
‘(heading "quoted phrase" "word")’ ‘heading:"quoted phrase",word’
‘(and (tags "book" "books") (priority "A"))’ ‘tags:book,books priority:A’
‘(src :lang "elisp" :regexps ("defun"))’ ‘src:defun,lang=elisp’ or ‘src:lang=elisp,defun’
‘(and (tags "space") (not (regexp "moon")))’ ‘tags:space !moon’
‘(priority >= B)’ ‘priority:A,B’
Note that the ‘effort’, ‘level’, and ‘priority’ predicates do not
support comparators in the non-sexp syntax, so multiple arguments should
be passed instead, as seen in the last example.
File: README.info, Node: General predicates, Next: Ancestor/descendant predicates, Prev: Non-sexp query syntax, Up: Queries
4.2.2 General predicates
------------------------
Arguments are listed next to predicate names, where applicable.
‘blocked’
Return non-nil if current heading is blocked. Calls
‘org-entry-blocked-p’, which see.
‘category (&optional categories)’
Return non-nil if current heading is in one or more of ‘CATEGORIES’
(a list of strings).
‘done’
Return non-nil if entry’s ‘TODO’ keyword is in ‘org-done-keywords’.
‘effort (&optional effort-or-comparator effort)’
Return non-nil if current heading’s effort property matches
arguments. The following forms are accepted: ‘(effort DURATION)’:
Matches if effort is ‘DURATION’. ‘(effort DURATION DURATION)’:
Matches if effort is between DURATIONs, inclusive. ‘(effort
COMPARATOR DURATION)’: Matches if effort compares to ‘DURATION’
with ‘COMPARATOR’. ‘COMPARATOR’ may be ‘<’, ‘<=’, ‘>’, or ‘>=’.
‘DURATION’ should be an Org effort string, like ‘5’ or ‘0:05’.
‘habit’
Return non-nil if entry is a habit.
‘heading (&rest strings)’
Return non-nil if current entry’s heading matches all ‘STRINGS’.
Matching is done case-insensitively.
• Aliases: ‘h’.
‘heading-regexp (&rest regexps)’
Return non-nil if current entry’s heading matches all ‘REGEXPS’
(regexp strings). Matching is done case-insensitively.
• Aliases: ‘h*’.
‘level (level-or-comparator &optional level)’
Return non-nil if current heading’s outline level matches
arguments. The following forms are accepted: ‘(level NUMBER)’:
Matches if heading level is ‘NUMBER’. ‘(level NUMBER NUMBER)’:
Matches if heading level is equal to or between NUMBERs. ‘(level
COMPARATOR NUMBER)’: Matches if heading level compares to ‘NUMBER’
with ‘COMPARATOR’. ‘COMPARATOR’ may be ‘<’, ‘<=’, ‘>’, or ‘>=’.
‘link (&optional description-or-target &key description target regexp-p)’
Return non-nil if current heading contains a link matching
arguments. ‘DESCRIPTION-OR-TARGET’ is matched against the link’s
description and target. Alternatively, one or both of
‘DESCRIPTION’ and ‘TARGET’ may be matched separately. Without
arguments, return non-nil if any link is found.
‘outline-path (&rest strings)’
Return non-nil if current node’s outline path matches all of
‘STRINGS’. Each string may appear as a substring in any part of
the node’s outline path. For example, the path
‘Food/Fruits/Grapes’ would match ‘(olp "Fruit" "Grape")’.
• Aliases: ‘olp’.
‘outline-path-segment (&rest strings)’
Return non-nil if current node’s outline path matches ‘STRINGS’.
Matches ‘STRINGS’ as a contiguous segment of the outline path.
Each string is compared as a substring. For example the path
‘Food/Fruits/Grapes’ would match ‘(olps "Fruit" "Grape")’ but not
‘(olps "Food" "Grape")’.
• Aliases: ‘olps’.
‘path (&rest regexps)’
Return non-nil if current heading’s buffer’s filename path matches
any of ‘REGEXPS’ (regexp strings). Without arguments, return
non-nil if buffer is file-backed.
‘priority (&rest args)’
Return non-nil if current heading has a certain priority. ‘ARGS’
may be either a list of one or more priority letters as strings, or
a comparator function symbol followed by a priority letter string.
For example: ‘(priority "A") (priority "A" "B") (priority '>= "B")’
Note that items without a priority cookie never match this
predicate (while Org itself considers items without a cookie to
have the default priority, which, by default, is equal to priority
‘B’).
‘property (property &optional value &key inherit)’
Return non-nil if current entry has ‘PROPERTY’ (a string), and
optionally ‘VALUE’ (a string). If ‘INHERIT’ is nil, only match
entries with ‘PROPERTY’ set on the entry; if t, also match entries
with inheritance. If ‘INHERIT’ is not specified, use the value of
‘org-use-property-inheritance’, which see.
‘regexp (&rest regexps)’
Return non-nil if current entry matches all of ‘REGEXPS’ (regexp
strings). Matches against entire entry, from beginning of its
heading to the next heading.
• Aliases: ‘r’.
‘rifle (&rest strings)’
Return non-nil if each string is found in either the entry or its
outline path. Works like ‘org-rifle’. This is probably the most
useful, intuitive, general-purpose predicate.
• Aliases: ‘smart’.
• *Note:* By default, this is the default predicate used for
plain-string query tokens (i.e. given without a specified
predicate). This can be customized with the option
‘org-ql-default-predicate’.
‘src (&key lang regexps)’
Return non-nil if current entry contains an Org Babel source block.
If ‘LANG’ is non-nil, match blocks of that language. If ‘REGEXPS’
is non-nil, require that block’s contents match all regexps.
Matching is done case-insensitively.
‘tags (&optional tags)’
Return non-nil if current heading has one or more of ‘TAGS’ (a list
of strings). Tests both inherited and local tags.
‘tags-inherited (&optional tags)’
Return non-nil if current heading’s inherited tags include one or
more of ‘TAGS’ (a list of strings). If ‘TAGS’ is nil, return
non-nil if heading has any inherited tags.
• Aliases: ‘inherited-tags’, ‘tags-i’, ‘itags’.
‘tags-local (&optional tags)’
Return non-nil if current heading’s local tags include one or more
of ‘TAGS’ (a list of strings). If ‘TAGS’ is nil, return non-nil if
heading has any local tags.
• Aliases: ‘local-tags’, ‘tags-l’, ‘ltags’.
‘tags-all (tags)’
Return non-nil if current heading includes all of ‘TAGS’. Tests
both inherited and local tags.
• Aliases: ‘tags&’.
‘tags-regexp (&rest regexps)’
Return non-nil if current heading has tags matching one or more of
‘REGEXPS’. Tests both inherited and local tags.
• Aliases: ‘tags*’.
‘todo (&optional keywords)’
Return non-nil if current heading is a ‘TODO’ item. With
‘KEYWORDS’, return non-nil if its keyword is one of ‘KEYWORDS’ (a
list of strings). When called without arguments, only matches
non-done tasks (i.e. does not match keywords in
‘org-done-keywords’).
File: README.info, Node: Ancestor/descendant predicates, Next: Date/time predicates, Prev: General predicates, Up: Queries
4.2.3 Ancestor/descendant predicates
------------------------------------
‘ancestors (&optional query)’
Return non-nil if current heading has ancestor headings. If
‘QUERY’, return non-nil if an ancestor heading matches it. This
selector may be nested.
‘children (&optional query)’
Return non-nil if current heading has direct child headings. If
‘QUERY’, return non-nil if a child heading matches it. This
selector may be nested, e.g. to match grandchild headings.
‘descendants (&optional query)’
Return non-nil if current heading has descendant headings. If
‘QUERY’, return non-nil if a descendant heading matches it. This
selector may be nested (if you can grok the nesting!).
‘parent (&optional query)’
Return non-nil if current heading has a direct parent heading. If
‘QUERY’, return non-nil if the parent heading matches it. This
selector may be nested, e.g. to match grandparent headings.
File: README.info, Node: Date/time predicates, Prev: Ancestor/descendant predicates, Up: Queries
4.2.4 Date/time predicates
--------------------------
These predicates take optional keyword arguments:
• ‘:from’: Match entries whose timestamp is on or after timestamp
‘:from’.
• ‘:to’: Match entries whose timestamp is on or before timestamp
‘:to’.
• ‘:on’: Match entries whose timestamp is on date ‘:on’.
• ‘:with-time’: If unspecified, match timestamps with or without
times (i.e. HH:MM). If nil, match timestamps without times. If t,
match timestamps with times.
Timestamp/date arguments should be either a number of days (positive
to look forward, or negative to look backward), a string parseable by
‘parse-time-string’ (the string may omit the time value), the symbol
‘today’, or a ‘ts’ struct.
• *Predicates*
‘ts’
Return non-nil if current entry has a timestamp in given
period. Without arguments, return non-nil if entry has a
timestamp.
‘ts-active’, ‘ts-a’
Like ‘ts’, but only matches active timestamps.
‘ts-inactive’, ‘ts-i’
Like ‘ts’, but only matches inactive timestamps.
The following predicates, in addition to the keyword arguments, can
also take a single argument, a number, which looks backward or forward a
number of days. The number can be negative to invert the direction.
These two predicates interpret a single number argument as if it were
passed to the ‘:from’ keyword argument, which eases the common case of
searching for items clocked or closed in the past few days:
• *Backward-looking*
‘clocked’
Return non-nil if current entry was clocked in given period.
Without arguments, return non-nil if entry was ever clocked.
Note: Clock entries are expected to be clocked out. Currently
clocked entries (i.e. with unclosed timestamp ranges) are
ignored.
‘closed’
Return non-nil if current entry was closed in given period.
Without arguments, return non-nil if entry is closed.
These predicates interpret a single number argument as if it were
passed to the ‘:to’ keyword argument, which eases the common case of
searching for items planned in the next few days:
• *Forward-looking*
‘deadline’
Return non-nil if current entry has deadline in given period.
If argument is ‘auto’, return non-nil if entry has deadline
within ‘org-deadline-warning-days’. Without arguments, return
non-nil if entry has any deadline.
‘planning’
Return non-nil if current entry has planning timestamp (i.e.
its deadline, scheduled, or closed timestamp) in given period.
Without arguments, return non-nil if entry has any planning
timestamp.
‘scheduled’
Return non-nil if current entry is scheduled in given period.
Without arguments, return non-nil if entry is scheduled.
File: README.info, Node: Functions / Macros, Next: Dynamic block, Prev: Queries, Up: Usage
4.3 Functions / Macros
======================
•
• •
• • • • •
•
* Menu:
* Agenda-like views::
* Listing / acting-on results::
* Custom predicates::
File: README.info, Node: Agenda-like views, Next: Listing / acting-on results, Up: Functions / Macros
4.3.1 Agenda-like views
-----------------------
1. Function: ‘org-ql-block’
For use as a custom agenda block type in
‘org-agenda-custom-commands’. For example, you could define a
custom series command like this, which would list all priority A
items tagged ‘Emacs’ with to-do keyword ‘SOMEDAY’, followed by the
standard agenda view, in a single buffer:
(setq org-agenda-custom-commands
'(("ces" "Custom: Agenda and Emacs SOMEDAY [#A] items"
((org-ql-block '(and (todo "SOMEDAY")
(tags "Emacs")
(priority "A"))
((org-ql-block-header "SOMEDAY :Emacs: High-priority")))
(agenda)))))
Which would be equivalent to a ‘tags-todo’ search like this:
(setq org-agenda-custom-commands
'(("ces" "Custom: Agenda and Emacs SOMEDAY [#A] items"
((tags-todo "PRIORITY=\"A\"+Emacs/!SOMEDAY")
(agenda)))))
However, the ‘org-ql-block’ version runs in about 1/5th the time.
The variable ‘org-ql-block-header’ may be bound to a string to use
as the block header, otherwise the header is formed automatically.
File: README.info, Node: Listing / acting-on results, Next: Custom predicates, Prev: Agenda-like views, Up: Functions / Macros
4.3.2 Listing / acting-on results
---------------------------------
1. Caching
Org QL uses a per-buffer cache to speed up subsequent searches.
It’s keyed on query expressions and match actions, which means
that, for the same query and same match action in the same buffer,
if the buffer has not been modified since the last time the query
was run, the cached match-action result will be returned, and the
query will not be evaluated in that buffer again.
Therefore, since neither query expressions nor match actions are
guaranteed to be evaluated when the following functions are called,
they should be free of side effects. Or, if a side effect is
required, the cache should be invalidated (e.g. by incrementing
the buffer’s modified tick, or by using a query expression or match
action that has yet to be cached). _Note: Future improvements will
allow the cache to be more easily disabled or cleared._
2. Function: ‘org-ql-select’
_Arguments:_ ‘(buffers-or-files query &key action narrow sort)’
Return items matching ‘QUERY’ in ‘BUFFERS-OR-FILES’.
‘BUFFERS-OR-FILES’ is a one or a list of files and/or buffers.
‘QUERY’ is an ‘org-ql’ query sexp (quoted, since this is a
function).
‘ACTION’ is a function which is called on each matching entry with
point at the beginning of its heading. It may be:
• ‘element’ or nil: Equivalent to ‘org-element-headline-parser’.
• ‘element-with-markers’: Equivalent to calling
‘org-element-headline-parser’, with markers added using
‘org-ql--add-markers’. Suitable for formatting with
‘org-ql-agenda--format-element’, allowing insertion into an
Org Agenda-like buffer.
• A sexp, which will be byte-compiled into a lambda function.
• A function symbol.
If ‘NARROW’ is non-nil, buffers are not widened (the default is to
widen and search the entire buffer).
‘SORT’ is either nil, in which case items are not sorted; or one or
a list of defined ‘org-ql’ sorting methods (‘date’, ‘deadline’,
‘scheduled’, ‘closed’, ‘todo’, ‘priority’, or ‘random’); or a
user-defined comparator function that accepts two items as
arguments and returns nil or non-nil.
Examples:
;; Return list of to-do headings in inbox file with tags and to-do keywords:
(org-ql-select "~/org/inbox.org"
'(todo)
:action #'org-get-heading)
;; => ("TODO Practice leaping tall buildings in a single bound :personal:" ...)
;; Without tags and to-do keywords:
(org-ql-select "~/org/inbox.org"
'(todo)
:action '(org-get-heading t t))
;; => ("Practice leaping tall buildings in a single bound" ...)
;; Return WAITING heading elements in agenda files:
(org-ql-select (org-agenda-files)
'(todo "WAITING")
:action 'element)
;; => ((headline (:raw-value "Visit the moon" ...) ...) ...)
;; Since `element' is the default for ACTION, it may be omitted:
(org-ql-select (org-agenda-files)
'(todo "WAITING"))
;; => ((headline (:raw-value "Visit the moon" ...) ...) ...)
3. Function: ‘org-ql-query’
_Arguments:_ ‘(&key (select 'element-with-markers) from where
order-by narrow)’
Like ‘org-ql-select’, but arguments are named more like a ‘SQL’
query.
• ‘SELECT’ corresponds to the ‘org-ql-select’ argument ‘ACTION’.
• ‘FROM’ corresponds to the ‘org-ql-select’ argument
‘BUFFERS-OR-FILES’.
• ‘WHERE’ corresponds to the ‘org-ql-select’ argument ‘QUERY’.
• ‘ORDER-BY’ corresponds to the ‘org-ql-select’ argument ‘SORT’,
which see.
• ‘NARROW’ corresponds to the ‘org-ql-select’ argument ‘NARROW’.
Examples:
;; Return list of to-do headings in inbox file with tags and to-do keywords:
(org-ql-query
:select #'org-get-heading
:from "~/org/inbox.org"
:where '(todo))
;; => ("TODO Practice leaping tall buildings in a single bound :personal:" ...)
;; Without tags and to-do keywords:
(org-ql-query
:select '(org-get-heading t t)
:from "~/org/inbox.org"
:where '(todo))
;; => ("Practice leaping tall buildings in a single bound" ...)
;; Return WAITING heading elements in agenda files:
(org-ql-query
:select 'element
:from (org-agenda-files)
:where '(todo "WAITING"))
;; => ((headline (:raw-value "Visit the moon" ...) ...) ...)
;; Since `element' is the default for SELECT, it may be omitted:
(org-ql-query
:from (org-agenda-files)
:where '(todo "WAITING"))
;; => ((headline (:raw-value "Visit the moon" ...) ...) ...)
4. Macro: ‘org-ql’ (deprecated)
_Arguments:_ ‘(buffers-or-files query &key sort narrow markers
action)’
Expands into a call to ‘org-ql-select’ with the same arguments.
For convenience, arguments should be unquoted.
_Note: This macro is deprecated and will be removed in v0.7._
File: README.info, Node: Custom predicates, Prev: Listing / acting-on results, Up: Functions / Macros
4.3.3 Custom predicates
-----------------------
• See: Custom predicate tutorial (examples/defpred.org)
1. Macro: ‘org-ql-defpred’
_Arguments:_ ‘(name args docstring &key body preambles
normalizers)’
Define an ‘org-ql’ selector predicate named
‘org-ql--predicate-NAME’. ‘NAME’ may be a symbol or a list of
symbols: if a list, the first is used as ‘NAME’ and the rest are
aliases. ‘A’ function is only created for ‘NAME’, not for aliases,
so a normalizer should be used to replace aliases with ‘NAME’ in
queries (keep reading).
‘ARGS’ is a ‘cl-defun’-style argument list. ‘DOCSTRING’ is the
function’s docstring.
‘BODY’ is the body of the predicate. It will be evaluated with
point on the beginning of an Org heading and should return non-nil
if the heading’s entry is a match.
‘PREAMBLES’ and ‘NORMALIZERS’ are lists of ‘pcase’ forms matched
against Org ‘QL’ query sexps. They are spliced into ‘pcase’ forms
in the definitions of the functions ‘org-ql--query-preamble’ and
‘org-ql--normalize-query’, which see. Those functions are
redefined when this macro is expanded, unless variable
‘org-ql-defpred-defer’ is non-nil, in which case those functions
should be redefined manually after defining predicates by calling
‘org-ql--define-query-preamble-fn’ and
‘org-ql--define-normalize-query-fn’.
‘NORMALIZERS’ are used to normalize query expressions to standard
forms. For example, when the predicate has aliases, the aliases
should be replaced with predicate names using a normalizer. Also,
predicate arguments may be put into a more optimal form so that the
predicate has less work to do at query time. NOTE: Normalizers are
applied to a query repeatedly until the query is fully normalized,
so normalizers should be carefully written to avoid infinite loops.
‘PREAMBLES’ refer to regular expressions which may be used to
search through a buffer directly to a potential match rather than
testing the predicate body on each heading. (Naming things is
hard.) In each ‘pcase’ form in ‘PREAMBLES’, the ‘pcase’ expression
(not the pattern) should be a plist with the following keys, each
value of which should be an expression which may refer to variables
bound in the pattern:
‘:regexp’ Regular expression which searches directly to a potential
match.
‘:case-fold’ Bound to ‘case-fold-search’ around the regexp search.
‘:query’ Expression which should replace the query expression, or
‘query’ if it should not be changed (e.g. if the regexp is
insufficient to determine whether a heading matches, in which case
the predicate’s body needs to be tested on the heading). If the
regexp guarantees a match, this may be simply ‘t’, leaving the
query expression with no work to do, which improves performance.
For convenience, within the ‘pcase’ patterns, the symbol
‘predicate-names’ is a special form which is replaced with a
pattern matching any of the predicate’s name and aliases. For
example, if ‘NAME’ were:
‘(heading h)’
Then if ‘NORMALIZERS’ were:
‘((`(,predicate-names . ,args) `(heading ,@args)))’
It would be expanded to:
‘((`(,(or 'heading 'h) . ,args) `(heading ,@args)))’
File: README.info, Node: Dynamic block, Next: Links, Prev: Functions / Macros, Up: Usage
4.4 Dynamic block
=================
Org QL provides a dynamic block that lists entries in the current
document matching a query. In the header, these parameters are
supported:
• ‘:query’: An Org QL query expression in either sexp or non-sexp
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.
The heading column is formatted as a link to the heading (not shown
in the following example).
For example, this dynamic block shows the first seven headings that
are to-do items with priority A or B, sorted by deadline then priority,
with certain columns (including the value of the ‘agenda-group’ property
with a custom header) and timestamp format:
#+BEGIN: org-ql :query "todo: priority:A,B" :columns (todo (priority "P") ((property "agenda-group") "Group") deadline heading) :sort (deadline priority) :take 7 :ts-format "%Y-%m-%d %H:%M"
| Todo | P | Group | Deadline | Heading |
|------+---+-------+------------------+---------------------------------------|
| TODO | A | | 2017-07-07 00:00 | Take over the world |
| TODO | B | | 2017-07-10 00:00 | Renew membership in supervillain club |
| TODO | A | plans | 2017-07-15 00:00 | Take over the universe |
| TODO | B | | 2017-07-21 00:00 | Internet |
| TODO | A | bills | 2017-08-01 00:00 | Spaceship lease |