Compare commits

..

610 commits

Author SHA1 Message Date
Jiri Jakes
ed23480e4b Apply #459
Some checks failed
CI / build (27.1) (push) Has been cancelled
CI / build (27.2) (push) Has been cancelled
CI / build (28.1) (push) Has been cancelled
CI / build (28.2) (push) Has been cancelled
CI / build (29.1) (push) Has been cancelled
CI / build (29.2) (push) Has been cancelled
CI / build (29.3) (push) Has been cancelled
CI / build (29.4) (push) Has been cancelled
CI / build (snapshot) (push) Has been cancelled
2026-08-17 19:55:50 +08:00
Adam Porter
4b8330a683
Merge pull request #491 from alhassy/master
Docs: Remove grammatical typo from “org-ql-search-block”
2025-04-20 20:33:00 -05:00
Musa Al-hassy
9946299bec Docs: Remove grammatical typo from “org-ql-search-block” 2025-04-20 07:50:43 -04:00
Adam Porter
98c62ab0a6 Docs: Fix some predicate arguments
Reported-by: Trevoke <https://github.com/Trevoke>
2024-11-25 17:49:54 -06:00
Adam Porter
a5650e2be8 Merge: v0.8.10 2024-11-06 21:45:09 -06:00
Adam Porter
9c53c1bddf Release: v0.8.10 2024-11-06 21:43:13 -06:00
Adam Porter
c95bb8a3ef Fix: (org-ql-refile) Use base buffer
See #466.
2024-11-06 21:42:40 -06:00
Adam Porter
0e68cc9fac Fix: (link) Don't match against null groups
e.g. in a source block containing Bash shell code like:

  [[ -z $data ]]

The matched groups could be null, since it's not actually an Org link,
so calling STRING-MATCH-P on them would signal an error.

Reported-by: John Wiegley <jwiegley@gmail.com>
2024-11-06 21:42:27 -06:00
Adam Porter
3cfc77d2ff Meta: v0.8.10-pre 2024-11-06 21:42:10 -06:00
Adam Porter
b6f8a315e9 Fix: (org-ql-view--format-element) Font-lock Org syntax
Not sure why I overlooked this for so long (links already worked,
which is probably why).
2024-09-16 18:25:02 -05:00
Adam Porter
fff110acde Fix: (org-ql-refile) Use base buffer
Should probably release this in a v0.8.10.

See #466.
2024-09-16 13:42:17 -05:00
Adam Porter
d574b60551 Add: (defface org-ql-view-query) 2024-09-11 01:50:16 -05:00
Adam Porter
82f762e31c Add: (org-ql-view-relative-deadline-prefix) 2024-09-11 01:01:30 -05:00
Adam Porter
a3c0205a68 Fix: (defface org-ql-view-due-date) Customization group 2024-09-10 22:38:19 -05:00
Adam Porter
1c8c89f264 Add: (defface org-ql-view-title) Use in -view--header-line-format
Note that we also add a safety check in ORG-QL-VIEW--LINK-FOLLOW,
because the addition of a call to PROPERTIZE in
ORG-QL-VIEW--HEADER-LINE-FORMAT effectively removes what was
functioning as a safety check there (as CONCAT had been signaling an
error for the unsafe argument, whereas PROPERTIZE, which is called to
apply the new face, does not).  We also change the expected error in
the tests accordingly.
2024-09-10 22:37:19 -05:00
Adam Porter
c3519fb4a0 Merge: v0.8.9 2024-09-05 18:58:13 -05:00
Adam Porter
81281350d4 Release: v0.8.9 2024-09-05 18:56:47 -05:00
Adam Porter
e241354fd6 Fix: (org-ql--define-query-preamble-fn) Pcase pattern for Emacs 30
Now all tests and lints pass on Emacs versions 27.1-29.4, and the
current 30.0.50-ish snapshot build.

Note: This change was originally applied on master, but it seems
reasonable to apply it to this stable bugfix release now.

Fixes #433.

Reported-by: Akira Komamura <akira.komamura@gmail.com>
Co-developed-by: Stefan Monnier <monnier@iro.umontreal.ca>
2024-09-05 18:45:58 -05:00
Adam Porter
5ea97d2272 Fix: (level) Check number argument for preamble
This allows a query like this:

  (level <= (string-to-number (property PROPERTY)))

to proceed without signaling an error from ORG-QL--QUERY-PREAMBLE.

See #460.

Reported-by: Stewmath <https://github.com/Stewmath>
2024-09-05 18:35:19 -05:00
Adam Porter
3e7f48ad7e Meta: (test.yml) Also test on Emacs 29.1-29.4 2024-09-05 04:26:59 -05:00
Adam Porter
c77bade432 Tests: Fix filenames for CI (better)
This is much simpler.
2024-09-05 04:25:59 -05:00
Adam Porter
86d338729f Fix: (property) Calling like (property PROPERTY :inherit t)
Supporting this form isn't really required, since it violates the
CL-style argument parsing of CL-DEFUN, but it's convenient, and
probably saves some hair-pulling for users who are less familiar with
Elisp.

Fixes #460.

Reported-by: Stewmath <https://github.com/Stewmath>
2024-09-05 04:24:24 -05:00
Adam Porter
a373e812d0 Fix: (org-ql-view--link-follow) Reading link parameters
This is needed due to changes in Emacs 30, but this code was always
mistaken, and it just happened to work.

See <https://github.com/jorgenschaefer/emacs-buttercup/issues/247>.

Fixes #441.

Suggested-by: Ola Nilsson <ola.nilsson@gmail.com>
2024-09-04 23:48:34 -05:00
Adam Porter
bcb77b75cc Meta: v0.8.9-pre 2024-09-04 21:55:10 -05:00
Adam Porter
831a1d4736 Tests: Fix filenames for CI (better)
This is much simpler.
2024-09-04 21:47:53 -05:00
Adam Porter
f72feb8018 Revert "Tests: Fix filename tests for CI"
This reverts commit 611198155d.
2024-09-04 21:40:36 -05:00
Adam Porter
fcb4e3ee62 Merge: v0.8.8 2024-08-29 16:38:58 -05:00
Adam Porter
20c0e5a9a7 Release: v0.8.8 2024-08-29 16:37:08 -05:00
Adam Porter
fd82c83d49 Fix: (org-ql-defpred) Docstring quote escapes 2024-08-29 16:35:57 -05:00
Adam Porter
847c066d54 Comment: TODO 2024-08-29 16:31:42 -05:00
Adam Porter
04b3bd2664 Fix: Use of org-ql-completing-read--snippet-regexp
* org-ql-completing-read.el (org-ql-completing-read-snippet): Call
snippet function with argument
(org-ql-completing-read): Call snippet function passed in rather than
hard-coded function.
(org-ql-completing-read--snippet-simple): Accept optional, ignored argument.
(org-ql-completing-read--snippet-regexp): Make argument optional;
rename for clarity.

Fixes #419.

Reported-by: tpeacock19 <https://github.com/tpeacock19>
2024-08-29 16:31:07 -05:00
Adam Porter
3c1dd36990 Fix: (org-ql-completing-read) Binding of completion-styles-alist
Fixes #337.

Thanks to Nicholas Vollmer (@progfolio), viz (@9viz), and Karthik
Chikmagalur (@karthink) for reporting and suggesting fixes.
2024-08-29 14:39:55 -05:00
Adam Porter
357d533b75 Fix: (-view--format-element) Remove text properties from keywords
Modes like org-indent-mode and org-modern can add text properties to
to-do keywords in Org buffers, and those properties can "bleed over"
when org-element copies those regions into strings.  When those
strings are then displayed in an org-ql-view buffer, they can affect
how the keywords appear, e.g. having extra spaces prefixing them,
which breaks alignment.  We apply faces to the keywords ourselves, so
we don't need any properties from the source buffer.

Fixes #455.
2024-08-29 14:27:09 -05:00
Adam Porter
b6704c2814 Meta: v0.8.8-pre 2024-08-29 14:19:10 -05:00
Adam Porter
b0cb7618e9 Merge: Respect narrowing in org-ql-find 2024-08-26 07:19:18 -05:00
Adam Porter
cfe5300987 Docs: Update changelog 2024-08-26 07:19:09 -05:00
Adam Porter
ba49d0e3c7 Change: Respect narrowing in org-ql-find
This allows searching within a narrowed buffer with org-ql-find.
Using "C-u" searches the widened buffer, while "C-u C-u" prompts to
select the buffers to search (which previously worked with just
"C-u").
2024-08-26 07:14:31 -05:00
Adam Porter
b7d4856f92 Fix: (org-ql--define-query-preamble-fn) Pcase pattern for Emacs 30
Now all tests and lints pass on Emacs versions 27.1-29.4.  But on the
current Emacs snapshot build used in CI, Buttercup is hanging
indefinitely, which may be the same problem that led Guix to disable
the tests in
<https://git.savannah.gnu.org/cgit/guix.git/commit/gnu/packages/emacs-xyz.scm?id=3add97c7761e6c58a1d7405f417a49dda5f0a742>.
But I've no way of knowing whether that's a problem in org-ql (seems
unlikely), Emacs snapshot, or Buttercup.  It would be nice to solve
this before Emacs 30.1 is released, but I don't know how to peer
inside Buttercup to find out what it's hanging on.

Fixes #433.

Reported-by: Akira Komamura <akira.komamura@gmail.com>
Co-developed-by: Stefan Monnier <monnier@iro.umontreal.ca>
2024-06-27 09:32:34 -05:00
Adam Porter
611198155d Tests: Fix filename tests for CI
As the comment says, in CI the filenames are being abbreviated, which
I can't explain (it has not always been this way).  So we compare them
in abbreviated form.
2024-06-27 08:03:04 -05:00
Adam Porter
a8608f408b Fix/Meta: (makem.sh) Update to v0.7.1
This omits the obsolete Org ELPA repository, which apparently was
causing a very old version of Org to be installed, which appeared to
be causing Buttercup to inexplicably hang (sometimes, on some systems,
in some circumstances...?).

I don't know if this is related to Guix commit
<https://git.savannah.gnu.org/cgit/guix.git/commit/gnu/packages/emacs-xyz.scm?id=3add97c7761e6c58a1d7405f417a49dda5f0a742>,
which disables the tests due to Buttercup hanging, because Guix is not
running the tests through makem.sh.
2024-06-27 07:44:10 -05:00
Adam Porter
bfb0fbeec1 Tests: Declare requirement on xr
This was overlooked because makem.sh gets run with --install-linters,
which installs relint, which depends on xr.
2024-06-27 07:41:16 -05:00
Adam Porter
ccbd5b4594 Meta: (test.yml) Also test on Emacs 29.1-29.4 2024-06-27 07:02:09 -05:00
Adam Porter
d4faa21640 Fix: (data-ts.org) French day-of-week abbreviation
The test data in v0.8.7 was accidentally changed to the English
abbreviation (the perils of working on systems with differing
locales), but the feature works as intended.

See <ffc3477013 (r143566834)>.
2024-06-26 12:01:32 -05:00
Adam Porter
f24d93f038 Merge: v0.8.7 2024-06-26 11:32:45 -05:00
Adam Porter
c2b4404808 Release: v0.8.7 2024-06-26 11:31:17 -05:00
Adam Porter
b362dd68b0 Fix: (org-dblock-write:org-ql) Resolve element properties
Fixes <https://github.com/alphapapa/org-ql/issues/431>.

Reported-by: Jez Cope <https://github.com/jezcope>
2024-06-26 11:30:26 -05:00
Adam Porter
ffc3477013 Fix: (org-ql-regexp-part-ts-date) Allow punctuation in day-of-week
Fixes <https://github.com/alphapapa/org-ql/issues/432>.  Closes
<https://github.com/alphapapa/org-ql/pull/435>.

Reported-by: Florian D. <https://github.com/neurolit>
2024-06-26 11:20:28 -05:00
Adam Porter
914e64746f Fix: (org-ql-search) Interactive narrowing
Fixes #430.  Closes #436.

Reported-by: Akira Komamura <akira.komamura@gmail.com>
2024-06-26 10:41:58 -05:00
Adam Porter
4af08e37f9 Merge: Match timestamps with inner time ranges
Note that this is a form of basic, initial support.  More
comprehensive support will require refactoring of how timestamp values
are handled, which is deferred until a future version.

See <https://github.com/alphapapa/org-ql/pull/237> and
<https://github.com/alphapapa/org-ql/issues/371>.

Reported-by: Ihor Radchenko <yantar92@gmail.com>
2024-06-26 10:29:28 -05:00
Adam Porter
e3b956e54d Docs: Update changelog 2024-06-26 10:25:41 -05:00
Adam Porter
02b4213826 Tests: Timestamps with inner time ranges 2024-06-26 10:20:35 -05:00
Ihor Radchenko
0d9c46247d org-ql-regexp-part-ts-time: Fix for time intervals 2024-06-26 10:01:20 -05:00
Adam Porter
b8284c8f5c Meta: v0.8.7-pre 2024-06-26 09:58:11 -05:00
Adam Porter
5ef4364d0a Tidy: Compiler warnings 2024-06-22 05:00:03 -05:00
Adam Porter
d5269bb5e2 Comment: Add FIXME 2024-06-12 23:45:43 -05:00
Adam Porter
e9d08ca344 Tidy: (org-ql-defpred) Docstring
This does not solve the compilation warning, because that's caused by
the Pcase patterns at the end of the docstring, which the linter
falsely identifies as incorrect.
2024-06-12 23:33:36 -05:00
Adam Porter
f7c3a61e32 Fix: (helm-org-ql [v0.6.2]) Compilation warnings 2024-06-12 22:55:29 -05:00
Adam Porter
0f01f0a9d8 Tidy: Compilation warnings 2024-06-12 22:47:33 -05:00
Adam Porter
c9370982bf Merge: v0.8.6 2024-04-03 15:27:29 -05:00
Adam Porter
1f264bf464 Release: v0.8.6 2024-04-03 15:26:33 -05:00
Adam Porter
8bd73b4b46 Fix: (org-ql-view-bookmark-make-record) buffers-files as symbol 2024-04-03 15:25:58 -05:00
Adam Porter
d3f6dde344 Meta: v0.8.6-pre 2024-04-03 15:25:06 -05:00
Adam Porter
e41fe9018a Docs: Add development section 2024-02-21 20:00:39 -06:00
Adam Porter
f5cda3d127 Merge: v0.8.5 2024-02-21 05:47:17 -06:00
Adam Porter
bfff0b5517 Release: v0.8.5 2024-02-21 05:46:04 -06:00
Adam Porter
c90bae0eab Fix: (ancestors, parent) Normalize sub-queries
I'm not sure why calling the REC labeled function didn't correctly
normalize these sub-queries; it seemed to only normalize for one
round, leaving some queries incorrectly normalized.  But this fixes
it.

Fixes #365.

Reported-by: Gabriele Mongiano <https://github.com/kofm>
2024-02-21 05:45:46 -06:00
Adam Porter
b6efba9aeb Fix: (heading) Don't match strings as regexps
Reported-by: Alex Popescu <https://github.com/al3xandru>
2024-02-21 05:45:36 -06:00
Adam Porter
770e60766a Meta: v0.8.5-pre 2024-02-21 05:45:25 -06:00
Adam Porter
8d3c93b883 Tidy: Compiler warning
I've no explanation for why this isn't caught by makem.sh's linting
compilation and declarations, but somehow it shows up at installation
time.
2024-01-13 00:47:47 -06:00
Adam Porter
9c63a45821 Meta: Update makem.sh 2024-01-13 00:47:35 -06:00
Adam Porter
a305862d7e Merge: v0.8.4 2024-01-13 00:04:27 -06:00
Adam Porter
9606aaf812 Release: v0.8.4 2024-01-13 00:03:28 -06:00
Adam Porter
34f8b75b35 Fix: (org-ql-find) Go to base buffer if possible
Use the base buffer if it has one, because if we run the search from
an indirect buffer, it's likely already narrowed to a different entry,
and making an indirect buffer from that one would end up with a
restriction that would likely hide the selected entry.
2024-01-13 00:03:03 -06:00
Adam Porter
0168171a14 Meta: v0.8.4-pre 2024-01-12 23:58:41 -06:00
Adam Porter
6679bdea00 Merge: v0.8.3 2024-01-10 01:56:57 -06:00
Adam Porter
7d8bd8b884 Release: v0.8.3 2024-01-10 01:56:00 -06:00
Adam Porter
0b1e4b43ec Fix: (org-ql-find) Moving point and widening buffer as needed
See #380.

Reported-by: Omar Antolín Camarena <omar.antolin@gmail.com>
2024-01-10 01:55:16 -06:00
Adam Porter
694739b31d Meta: v0.8.3-pre 2024-01-10 01:38:15 -06:00
Adam Porter
5b0026260a Merge: v0.8.2 2024-01-09 02:28:19 -06:00
Adam Porter
3448e49d86 Release: v0.8.2 2024-01-09 02:27:11 -06:00
Adam Porter
7ff6cc2ef7 Fix: (org-ql-find) Don't use org-with-point-at
See <https://github.com/alphapapa/org-ql/issues/380#issuecomment-1881913025>.

Reported-by: Bram Schoenmakers <me@bramschoenmakers.nl>
2024-01-09 02:25:46 -06:00
Adam Porter
8595139f5b Meta: v0.8.2-pre 2024-01-09 02:22:38 -06:00
Adam Porter
39394c831a Merge: v0.8.1 2024-01-03 18:49:09 -06:00
Adam Porter
51869fd7f9 Release: v0.8.1 2024-01-03 18:47:44 -06:00
Adam Porter
02a2e256dc Docs: Fix v0.7 changelog
Fixes #335.

Reported-by: Nicholas Vollmer <https://github.com/progfolio>
2024-01-03 18:46:21 -06:00
Ivan Perez
393f88e7f3 Remove mentions of removed functions from v0.7 subheading in Changelog.
These commands were removed in 5768c685ad,
but they were still mentioned in the release that was going to
incorporate those two functions, v0.7.

This commit removes the mention of those two functions from the v0.7
subheading in the changelog. Note that `org-ql-find-path` was
re-introduced in v0.8, so it remains under that subheading as a separate
addition.
2024-01-03 18:44:56 -06:00
Adam Porter
529e05851b Fix: (org-ql-view--format-element) Avoid unlinkifying links
I don't fully understand why this is the correct fix, because I don't
know where the raw heading text is being linkified (it seems like the
:raw-value property should be the unlinkified text), but this seems to
work correctly now.  If it turns out to break something else, we'll
find out and fix it.

Fixes #282.

Reported-by: Jacob Boxerman <https://github.com/jakebox>
2024-01-03 18:35:11 -06:00
Adam Porter
8e9a8fe090 Fix: (org-ql-find) Widen buffer
This fixes the case in which a user calls org-ql-find from a narrowed
buffer and chooses a result outside the restriction.  This is already
done in, e.g. org-ql-open-link; it's just an oversight here.
2024-01-03 18:28:06 -06:00
Adam Porter
24b799ab0b Meta: v0.8.1-pre 2024-01-03 18:25:18 -06:00
Adam Porter
a4bf5b0a92 Tidy: (org-ql-view--display) Take STRINGS instead of STRING
No need to allocate one large string just to insert it into the
buffer.
2023-12-24 01:10:27 -06:00
Adam Porter
0e39372146 Meta: v0.9-pre 2023-12-24 01:09:49 -06:00
Adam Porter
087e99703e Release: v0.8 2023-12-21 17:14:30 -06:00
Adam Porter
09e7b60505 Tidy: Compatibility aliases for Org 9.6 2023-12-21 17:11:01 -06:00
Adam Porter
b015b3b910 Tidy: Indentation, variable 2023-12-21 17:10:53 -06:00
Adam Porter
eaf58b463e Meta: Update copyright years
Fixes #336.
2023-12-21 16:54:17 -06:00
Adam Porter
08497a1648 Merge: org-ql-completing-read-export 2023-12-21 16:49:13 -06:00
Adam Porter
f98dee54c8 Docs: Update changelog and usage 2023-12-21 16:49:06 -06:00
Adam Porter
f4b006ffb9 Remap embark-collect to embark-export 2023-12-21 16:40:09 -06:00
Adam Porter
2644f53fe2 Tidy, rename 2023-12-21 16:40:09 -06:00
Omar Antolín
0552aa8b93 Use a keymap for the org-ql-view export functionality 2023-12-21 16:40:09 -06:00
Omar Antolín Camarena
121af5c5d5 Add C-c C-e key binding to save an org-ql-find session 2023-12-21 16:40:09 -06:00
Adam Porter
4ef9d9efed Meta: (bug_report.yml) Add Org version, remove labels and assignee 2023-12-19 03:27:01 -06:00
Adam Porter
77b4c2bce2 Meta: Add bug report template 2023-12-16 07:55:16 -06:00
Adam Porter
3dc2409539 Meta: Require Emacs 27.1 or later
Emacs 26.3 is quite old now, and I can't practically run tests for it
anymore because some other dependencies have dropped support for it.
2023-12-16 07:10:52 -06:00
Adam Porter
9a5680c6f3 Merge: (property) Use 'selective argument to org-entry-get
Closes #346.  See also #356.

Reported-by: Bram Schoenmakers <https://github.com/bram85>
Co-developed-by: Bram Schoenmakers <https://github.com/bram85>
2023-12-16 05:39:33 -06:00
Adam Porter
c78f785378 Docs: Update changelog 2023-12-16 05:39:08 -06:00
Bram Schoenmakers
f6d7514159 Handle the case when org-use-property-inheritance is a list of strings
When org-use-property-inheritance is a list, then the query

(property "FOO" "BAR")

would bail out with:

org-ql--byte-compile-warning: Invalid Org QL query: "Invalid Org QL
query: \"‘\\\"BLAH\\\"’ is a malformed function\", :warning", :error

(property "FOO") would still work though.

So, if org-use-property-inheritance is a list, cast it to
the (default) boolean value for this variable: nil.

Use 'selective' inheritance when org-use-property-inheritance is a list

This symbol is mentioned in the org-entry-get documentation.
2023-12-16 05:39:05 -06:00
Adam Porter
1496185141 Fix: (property) Handle org-use-property-inheritance when unspecified
Fixes #356.

Reported-by: beast-pro <https://github.com/beast-pro>
Reported-by: pcompassion <https://github.com/pcompassion>
2023-12-16 05:37:48 -06:00
Adam Porter
004ed1ee0f Tidy: Indentation
For Emacs 29.1's and with-simulated-input's changes.
2023-12-16 05:37:48 -06:00
Adam Porter
c62ff77cd3 Tidy: Use compat and newer symbol names 2023-12-16 05:37:48 -06:00
Adam Porter
0ab236f95b Tidy: Docstring
The compiler still complains that it has wrong usage of an unescaped
single quote, but nothing seems to fix it.
2023-12-16 05:37:48 -06:00
Adam Porter
a31baebc4f Add: (org-ql-view--format-element) org-category property
Hopefully this does not cause a noticeable performance impact.  Maybe
the new org-element caching features in Org will help with that.

Fixes #363.

Reported-by: Gabriele Mongiano <https://github.com/kofm>
2023-12-16 04:47:06 -06:00
Adam Porter
ace5e361af Merge: v0.7.4 2023-12-16 04:13:38 -06:00
Adam Porter
38e16b4a5f Release: v0.7.4 2023-12-16 04:11:01 -06:00
Adam Porter
7a6b622cd0 Fix: Ignore empty quoted strings when parsing string queries
Fixes #383.

Reported-by: Adam Porter <adam@alphapapa.net>
2023-12-16 04:10:34 -06:00
Adam Porter
5775848b8a Meta: v0.7.4-pre 2023-12-16 03:56:58 -06:00
Adam Porter
4f62ba3bd6 Fix: (org-ql-find) Pop to buffer then go to position
Seems that selecting the window after going to the position can
sometimes break (probably because of the window point).
2023-11-06 16:30:20 -06:00
Adam Porter
72b9934d1f Change: (org-ql-find.el) Factor out interactive form
And use in org-ql-find-path.
2023-11-06 15:55:39 -06:00
Adam Porter
e885001a2a Comment: Add TODO 2023-11-01 14:37:59 -05:00
Adam Porter
bd2dd12a41 Merge: (org-ql-open-link) And associated changes 2023-10-25 03:30:41 -05:00
Adam Porter
2319fc9d8b Docs: Update changelog, Usage 2023-10-25 03:29:03 -05:00
Adam Porter
58d29d0fff Comment: Add FIXME 2023-10-25 03:21:03 -05:00
Adam Porter
a802579f86 Tidy 2023-10-25 03:19:29 -05:00
Adam Porter
40b25ac319 Fix: (org-ql-completing-read-snippet) while-no-input 2023-10-23 18:57:58 -05:00
Adam Porter
7ecb4a8b10 Tidy 2023-10-23 18:57:58 -05:00
Adam Porter
9aba73a28b WIP 2023-10-23 18:57:58 -05:00
Adam Porter
3f08d45ace Fix: (org-ql-completing-read-action) Format link 2023-10-23 18:57:58 -05:00
Adam Porter
6c18f133e9 Tidy: Function, docstrings, commented code 2023-10-23 18:57:58 -05:00
Adam Porter
e030627aeb WIP: Add display-sort-function 2023-10-23 18:57:58 -05:00
Adam Porter
28f5aa3100 WIP: Many improvements
Now need to do some kind of sorting...
2023-10-23 18:57:56 -05:00
Adam Porter
deada67e1d WIP: org-ql-open-link
Need to tidy up and generalize org-ql-completing-read a bit more, but
this is basically working, and should be very useful.
2023-10-23 18:56:45 -05:00
Adam Porter
ee01bcb6e8 Merge: v0.7.3 2023-10-23 18:55:00 -05:00
Adam Porter
28c4215704 Release: v0.7.3 2023-10-23 18:52:04 -05:00
Adam Porter
631cd80ce8 Fix: (org-ql-find) Go to selected entry
Fixes #380.

Reported-by: Omar Antolín Camarena <omar@matem.unam.mx>
2023-10-23 01:26:39 -05:00
Adam Porter
de80f9a764 Comment: Add TODO 2023-10-23 01:23:48 -05:00
Adam Porter
09c3591504 Fix: Saving of org-ql-view views
It didn't seem that calling custom-save-all was necessary in the past,
but it appears that it is now.

Closes #378.

Reported-by: Pentaquark1 <https://github.com/Pentaquark1>
2023-10-19 21:50:30 -05:00
Adam Porter
4476759dc9 Fix: (org-ql--outline-path) Disable case-fold-search 2023-10-19 21:47:34 -05:00
Adam Porter
daad25e079 Meta: v0.7.3-pre 2023-10-19 21:45:22 -05:00
Adam Porter
ac2d43588a Add: (org-ql-find-path) 2023-10-19 21:44:26 -05:00
Adam Porter
6d5b614fc5 Fix: (org-ql-find) Interactive form
Fixes silly mistake in ab720689e9.
2023-10-02 22:52:25 -05:00
Adam Porter
ab720689e9 Change: (org-ql-find) Interactively, search relevant buffers 2023-09-30 20:09:12 -05:00
Adam Porter
ca23b1c7bd Merge: Embark support 2023-09-27 15:03:30 -05:00
Adam Porter
a41dfe25ea Docs: Update changelog, usage 2023-09-27 15:02:40 -05:00
Omar Antolín Camarena
641ec0ac50 Add category metadatum to org-ql-completing-read
This is all that is needed to gain support for Embark actions on
org-ql-find candidates.
2023-09-27 14:53:44 -05:00
Adam Porter
8250349e35 Merge: Update for Org 9.7 org-element API changes
See #364.
2023-09-27 13:40:53 -05:00
Adam Porter
5c9d4cdb48 Docs: Update changelog 2023-09-27 13:40:30 -05:00
Adam Porter
9e72bf6947 Fix: (org-ql-view--format-element) Check habit in source buffer
See #364.
2023-09-27 13:36:47 -05:00
Adam Porter
0e702ecb48 Change: Resolve Org element properties on 9.7+
See #364.
2023-09-27 13:36:47 -05:00
Adam Porter
0a0291288e Meta: v0.8-pre 2023-09-27 13:36:18 -05:00
Adam Porter
f9d4f62415 Release: v0.7.2 2023-09-27 00:21:21 -05:00
Adam Porter
56e203110b Fix: (org-ql-completing-read) Warn about empty headings 2023-09-26 20:48:59 -05:00
Adam Porter
be20dc3d5b Fix: (org-ql-find) Use org-with-point-at
I keep pointing out to other people that they should use
org-with-point-at, but I still have places in my own code where I need
to use it, too!
2023-09-26 13:42:00 -05:00
Adam Porter
8412d1a23d Tidy: Indentation
For Emacs 29.1.
2023-09-22 22:08:57 -05:00
Adam Porter
95abce2340 Fix: (org-ql-completing-read) :query-prefix prevented selection
COMPLETING-READ, when used with its REQUIRE-MATCH argument, would not
allow a result to be selected when ORG-QL-FIND was called with its
QUERY-PREFIX argument.

This change moves where the query is modified to include the prefix,
putting it into the RUN-QUERY function instead of the COLLECTION
function.  It seems to solve the problem, and the function seems to
still work when used without QUERY-PREFIX.  However, due to the
complexity of all this (we really need a SELECTING-READ API), it
wouldn't surprise me if something is later found to have been broken
by it...

Fixes #351.

Reported-by: Daniel Fleischer <https://github.com/danielfleischer>
2023-09-14 08:10:49 -05:00
Adam Porter
131407814e Fix: (org-ql--def-query-string-to-sexp-fn) Ignore leading blanks 2023-09-08 02:22:40 -05:00
Adam Porter
f65b1d91a4 Fix: (org-ql--normalize-from-to-on) Tolerate "-" input
Avoids errors while typing a query (e.g. a negative number) into
org-ql-find, which interrupts completion altogether.
2023-09-06 20:51:41 -05:00
Adam Porter
3622b92403 Meta: v0.7.2-pre 2023-09-06 20:49:12 -05:00
Adam Porter
d776e205d5 Release: v0.7.1 2023-09-06 18:57:36 -05:00
Adam Porter
ed81b7d7c8 Tests: Require xr
This is only a development dependency.
2023-09-06 18:56:32 -05:00
Adam Porter
3c24958738 Fix: (org-ql-completing-read) Variable name 2023-09-06 18:55:39 -05:00
Adam Porter
f9b60d8ef8 Fix: (org-ql-completing-read) Propertize strings with markers
Fixes #350.  Closes #357.
2023-09-06 16:09:18 -05:00
Adam Porter
2d29d69133 Docs: Update changelog 2023-09-06 16:08:54 -05:00
Ankit Pandey
a7af6d78b2 Fix: (org-ql-completing-read) Store markers as text property
Fixes #350
2023-09-06 11:11:17 -05:00
Adam Porter
898addeee9 Docs: Tidy
The circumstances which precipitated this expression of support for
fellow developers thankfully passed some time ago.
2023-09-04 22:40:52 -05:00
Adam Porter
eb5377320f Comment: Add FIXME 2023-05-25 10:48:47 -05:00
Adam Porter
2c098540ca Fix: (org-ql-completing-read) Format links before display
Also use org-entry-get to get the heading, which should avoid issues
with different Org versions having different optional arguments to
org-get-heading.
2023-05-05 17:25:21 -05:00
Adam Porter
1d98c7d07c Tests: Disable Org link bracket tests on old Org versions 2023-03-14 12:13:07 -05:00
Adam Porter
4c1a4b169f Fix: (org-ql-completing-read)
This seems to work better now with default Emacs completion (i.e. not
using Vertico or Helm).  It's still not perfect, but it seems to work
reasonably well and be more correct.

Fixes #338.  Thanks to @arozbiz for reporting.
2023-03-12 09:33:28 -05:00
Adam Porter
e08de2a76c Fix: (org-ql-completing-read) Bind org-outline-path-cache nil 2023-03-12 05:59:22 -05:00
Adam Porter
ce66f67c96 Meta: v0.7.1-pre 2023-03-12 05:59:13 -05:00
Adam Porter
aadddc4d84 Release: v0.7 2023-03-10 06:25:45 -06:00
Adam Porter
107fc66d08 Change: (org-ql-view--format-element) Use display-warning 2023-03-10 06:24:03 -06:00
Adam Porter
44679a6c93 Comment: Remove old FIXMEs 2023-03-10 06:23:53 -06:00
Adam Porter
962a3dc414 Comment: Remove old FIXME
See 3c73888b98.
2023-03-10 06:19:01 -06:00
Adam Porter
9e14f9eefa Fix: (link) Allow brackets in description
Org 9.3 stopped replacing brackets in link descriptions with braces
and started escaping them instead.

Fixes #283.  Thanks to Daniel Borchmann (@exot) for reporting.
2023-03-10 05:56:01 -06:00
Adam Porter
3c73888b98 Merge: (org-ql-sparse-tree) Accept string queries
Thanks to Akira Komamura (@akirak).
2023-03-10 04:46:45 -06:00
Adam Porter
d92afcda06 Docs: Update changelog 2023-03-10 04:46:32 -06:00
Adam Porter
99e580b530 Tidy: (org-ql-sparse-tree) Docstring; use pcase 2023-03-10 04:44:39 -06:00
Akira Komamura
1ae2f0cd60 Update the docstring 2023-03-10 04:44:39 -06:00
Akira Komamura
2b7d4e0e79 Fix: Accept plain queries in interactive org-ql-sparse-tree 2023-03-10 04:44:39 -06:00
Adam Porter
7f68db962e Merge: (blocked) predicate
Thanks to Akira Komamura (@akirak).
2023-03-10 03:42:37 -06:00
Adam Porter
902dad04c1 Docs/Tidy: Update readme, reorder forms 2023-03-10 03:36:21 -06:00
Akira Komamura
6afe3be572 Add: (blocked) predicate 2023-03-10 03:33:08 -06:00
Adam Porter
e5e9daab07 Fix: Aliases
One of them seems to break on Emacs 26.3 only...
2023-03-09 05:00:14 -06:00
Adam Porter
d21da3682b Tidy: Compilation warnings 2023-03-09 03:23:42 -06:00
Adam Porter
d86a402ba5 Tidy: Docstrings 2023-03-09 03:04:15 -06:00
Adam Porter
5c5a15a09b Fix: (org-ql--sanity-check-form) Use pcase 2023-03-09 02:47:23 -06:00
Adam Porter
2bc327d85f Fix: (org-ql-view--link-store) Error message for test suite
Use format string to prevent `substitute-quotes' from changing the
error string, breaking the test suite when run on CI.

Fixes #317.
2023-03-09 02:45:48 -06:00
Adam Porter
8bb1739661 Tests: (src) Normalization with no args
Closes #293.  Thanks to Akira Komamura (@akirak) for reporting.
2023-03-09 02:45:48 -06:00
Adam Porter
0d9940c5df Docs: Update README 2023-03-09 02:45:48 -06:00
Adam Porter
d784f8f71c Tests: (src) Implement 2023-03-09 02:45:48 -06:00
Adam Porter
68ac6ddd28 Tests: Use before-each for org-ql-test-data-buffer
This seems like the best way.
2023-03-09 02:45:48 -06:00
Adam Porter
2ae60f8dc5 Tests: (src) More normal forms 2023-03-09 02:45:48 -06:00
Adam Porter
1fdad05fef Tests: Tidy 2023-03-09 01:46:46 -06:00
Adam Porter
1996969920 Fix: (src) Rewrite body
Fixes #304.  Thanks to @johanwk for reporting.
2023-03-09 01:46:34 -06:00
Adam Porter
0304a2c9dc Tests: (org-ql-it) Expand using Buttercup's it
As the implementation of `it' changes, this will change with
it (correctly).
2023-03-09 00:52:47 -06:00
Adam Porter
6c9c0b957a Tests: Rename data2.org to data-file-tags.org
It appears likely that we'll need a few test-specific data files, so
we should use descriptive names.
2023-03-09 00:05:14 -06:00
Adam Porter
a5fbb5d976 Tidy: Indentation of dash forms
See, e.g. <https://github.com/magnars/dash.el/pull/375>.

Ultimately I'd prefer to indent with one distinguished argument, but
the noise it causes downstream is likely not worth it.  (And,
unfortunately, the indentation of the built-in thread-first and
thread-last forms has changed to be like this as well, which is even
worse, causing 10-11 characters of extra indentation in those forms'
bodies!)
2023-03-09 00:01:32 -06:00
Adam Porter
29533525c3 Tidy: (org-ql--plist-get*) Docstring 2022-12-25 17:51:00 -06:00
Adam Porter
36ff9854ce Fix: (category) Add normalizer for alias 2022-12-25 12:09:50 -06:00
Adam Porter
8dae879841 Change: (org-ql-defpred) Ensure aliased predicates have normalizers
Would have prevented me from releasing the "c" alias for "category"
without a normalizer.
2022-12-25 12:05:52 -06:00
Adam Porter
d253b123cf Docs: Add credits for v0.7-pre 2022-12-09 20:33:01 -06:00
Adam Porter
3d3d958d20 Meta: Test on CI with Emacs 28.1 and 28.2 2022-12-09 20:21:23 -06:00
Adam Porter
91908186fc Change/Fix: Preambles for predicates that expect arguments
Closes #285.  Thanks to Caleb Chase (@chasecaleb) for reporting.
2022-12-09 20:19:55 -06:00
Adam Porter
ecde3a0420 Change/Fix: (src) Normalization, case-insensitivity 2022-12-09 20:19:55 -06:00
Adam Porter
6e3a5eebe7 Fix: (src) Coalesce function 2022-12-08 21:22:40 -06:00
Adam Porter
9dd1bbb10b Merge: 0.6.3 2022-12-08 20:50:01 -06:00
Adam Porter
80b334c269 Release: v0.6.3 2022-12-08 20:45:14 -06:00
Adam Porter
2ddfb7c231 Fix: Require org-duration
This appears to be necessary on newer Org versions, but I don't know
exactly when.
2022-12-08 20:45:14 -06:00
Adam Porter
9f00fa3890 Fix: (org-ql--def-query-string-to-sexp-fn) Updated for peg v1.0.1
Fixes #314, fixes #316.  Thanks to Akira Komamura (@akirak) and Joon
Ro (@joonro) for reporting.

Instead of `[blank]` in this PEX, it used to be `(syntax-class
whitespace)`, which worked fine with peg v1.0.  Then
<https://debbugs.gnu.org/cgi/bugreport.cgi?bug=59345> was filed and
resulted in the release of peg v1.0.1, after which that no longer
worked.  As best I can tell from reading the discussion, `[blank]` and
`(syntax-class whitespace)` should behave the same way, yet here they
do not: with peg v1.0.1, only `[blank]` works.  Why, I do not know; I
only tried it because I could find no explanation for the broken
behavior, and luckily, it works.  Maybe it's due to the use of
`(syntax-class whitespace)` later in the `pexs`; but since it finally
works again, let's take the victory as-is.
2022-12-08 20:44:24 -06:00
Adam Porter
85aee42fae Meta: Update makem.sh to v0.6-pre
Needed for testing on Emacs 28+.
2022-12-08 20:38:47 -06:00
Adam Porter
f22fdd457b Meta: v0.6.3-pre 2022-12-08 19:48:40 -06:00
Adam Porter
5f70636556 Add: (org-ql-find-display-buffer-action) 2022-10-07 18:34:55 -05:00
Adam Porter
e54ba0102c Add: (property) :inherit argument 2022-10-07 18:33:35 -05:00
Adam Porter
e41cdb4591 Change: (org-ql-find-goto-hook) Add org-reveal
Showing the context is much better for the user.
2022-08-25 16:55:58 -05:00
Adam Porter
d7ada532c7 Add: Alias "c" to (category) 2022-08-19 03:38:43 -05:00
Adam Porter
7f4faff27b Add: (org-ql-refile) 2022-08-19 03:26:15 -05:00
Adam Porter
cfa3b307ec Add/Change: org-ql-completing-read, etc. 2022-08-19 03:26:15 -05:00
Adam Porter
18869c47ff Tidy: Headers 2022-08-19 03:14:46 -05:00
Adam Porter
6257ae8304 Fix: (org-ql-find--snippet-*) Use save-excursion 2022-08-15 16:16:55 -05:00
Adam Porter
06f1e1be6f Revert "Change: (org-ql-find) Add workaround for Ivy support"
This reverts commit a02ed48ac8.

See <https://github.com/alphapapa/org-ql/issues/284#issuecomment-1187705847>.
2022-07-18 13:44:25 -05:00
Adam Porter
a02ed48ac8 Change: (org-ql-find) Add workaround for Ivy support
See <https://github.com/alphapapa/org-ql/issues/284>.
2022-07-18 10:57:50 -05:00
Adam Porter
98b6049ecc Fix: (org-ql-find) Check major mode
See https://github.com/alphapapa/org-ql/issues/284#issuecomment-1185367899.
2022-07-15 13:50:10 -05:00
Adam Porter
a986e360c3 Fix: (org-ql-find) Select buffer
Thanks again to Thomas Bergheim (@bergheim).
2022-07-14 13:05:42 -05:00
Adam Porter
d46e69b0fc Fix: (org-ql-find) Always include query-prefix
Thanks to Thomas Bergheim (@bergheim) for his help!
2022-07-14 12:52:44 -05:00
Adam Porter
c2b8af3181 Fix: (org-ql-find) Always map across a list 2022-06-26 22:55:20 -05:00
Adam Porter
77916a1c4f Tidy: Indentation 2022-06-25 10:58:33 -05:00
Adam Porter
5f058b9eee Add: (org-ql-find-in-agenda, org-ql-find-in-org-directory) 2022-06-25 10:58:17 -05:00
Adam Porter
dc02c59cad Add: (org-ql--ensure-buffer)
And use in org-ql-find.  This seems to solve a problem I've been
noticing in helm-org-ql for a long time: that it can apparently
interrupt Org's initialization code, which can leave buffers
unprepared for Org, even stuck in fundamental-mode.  This should also
be used in helm-org-ql...
2022-06-25 10:56:18 -05:00
Adam Porter
bbd164c6ae Change/Fix: (org-ql-select) Warn instead of erroring on bad files
This helps prevent unexpected errors from making it impossible to
search, and displaying the messages in the warnings buffer makes them
more noticeable and readable for the user.
2022-06-25 10:54:38 -05:00
Adam Porter
5768c685ad Remove: org-ql-find-heading, org-ql-find-path
These are virtually obsolete with the introduction of the "rifle"
predicate as the default one.  Having them now is just confusing.
2022-06-25 10:53:29 -05:00
Adam Porter
bacdacb1b2 Change: Use buffer-chars-modified-tick
Closes #203.  Thanks to Ihor Radchenko (@yantar92).
2022-06-13 19:08:36 -05:00
Adam Porter
e22890ad04 Docs: Update changelog 2022-06-13 19:07:44 -05:00
Ihor Radchenko
675d333b91 Use buffer-chars-modified-tick instead of buffer-modified-tick 2022-06-13 19:05:34 -05:00
Adam Porter
6e7371ce61 Add: (org-ql-find) Snippet functions
The default is even more like org-rifle now.
2022-06-11 11:01:52 -05:00
Adam Porter
ede1a6b10b Change: Don't use (setf (plist-get ...))
That expansion is new in Emacs 28, which we don't yet target as the
minimum version.
2022-06-11 09:19:35 -05:00
Adam Porter
1ddc505977 Change: Rename coalesce-multiple-calls to coalesce 2022-06-11 08:16:15 -05:00
Adam Porter
6602f32165 Tests: Update (add, reorganize)
They all pass now (with a temporary, uncommitted workaround in
makem.sh for a Buttercup bug:
<https://github.com/jorgenschaefer/emacs-buttercup/issues/218>).
2022-06-11 08:15:24 -05:00
Adam Porter
73ef71ced7 Comment: Add FIXME 2022-06-11 08:15:24 -05:00
Adam Porter
4f29bcfd67 Add: (rifle/smart) Predicate 2022-06-11 08:15:24 -05:00
Adam Porter
968a249ae3 Add: Query coalescing for AND clauses
A later commit will update and add tests.
2022-06-11 08:15:24 -05:00
Adam Porter
0057972069 Add: (org-ql-default-predicate) 2022-06-10 01:32:48 -05:00
Adam Porter
c8c89be7bc Meta: Update makem.sh, Makefile 2022-06-09 22:34:07 -05:00
Adam Porter
d4f2eb760e Fix: (src) Normalization
Some argument combinations weren't normalized correctly and could
cause an infinite loop.

This commit doesn't update any corresponding tests, because they are
being rearranged in the WIP branch where this commit originates, and
teasing them out wouldn't be worth it.
2022-06-09 22:34:07 -05:00
Adam Porter
c7fab9dfce Tests: Wrap bare (expect) forms in (it) forms 2022-06-09 22:34:07 -05:00
Adam Porter
36e97d51cf Tests: Fix non-file-backed-buffer test
Somehow a Unicode "RIGHT SINGLE QUOTATION MARK" replaced the ASCII
apostrophe in this string, which broke the test.  Weird!
2022-06-09 22:16:59 -05:00
Adam Porter
64a9234733 Add: (org-ql-find) :query-filter
Also, tidy docstring.
2022-06-02 11:51:57 -05:00
Adam Porter
67506a56f8 Change: (org-ql--byte-compile-warning) More useful error message
e.g. if a predicate only accepts one argument, but the query gives
two, now the error will say, "PREDICATE called with 2 arguments, but
accepts only 1" (so maybe the predicate definition just needs
"&rest").
2022-05-31 12:01:42 -05:00
Adam Porter
d0acc8cbba Add: (org-ql-find) 2022-05-30 11:27:12 -05:00
Adam Porter
8933f8853c Merge: 0.6.2 2022-05-27 02:05:56 -05:00
Adam Porter
115500c8a0 Fix: (link) Save excursion around regexp search
Fixes #279.  Thanks to Marc Fargas (@telenieko) for reporting.

Released as 0.6.2.
2022-05-27 02:03:20 -05:00
Adam Porter
46f523d94a Meta: 0.7-pre 2022-03-18 10:34:54 -05:00
Adam Porter
f666fe150f Release: 0.6.1 2022-03-18 10:29:50 -05:00
Adam Porter
4f11878b7d Update: Transient macro names
Closes #269.  See https://github.com/magit/transient/issues/192.
Thanks to Jonas Bernoulli (@tarsius).
2022-03-18 10:29:07 -05:00
Adam Porter
1e7700e64e Fix: Links to headings with stats cookies in dynamic blocks
Fixes #248.  Closes #249.

Thanks to Maikol Solis (@maikol-solis) for reporting, and to him and
Ihor Radchenko (@yantar92) for helping plan the fix.
2022-03-18 10:28:17 -05:00
Adam Porter
49b973ab11 Meta: 0.6.1-pre 2022-03-18 10:06:58 -05:00
Adam Porter
31aeb0a250 Release: 0.6 2021-09-22 01:15:26 -05:00
Adam Porter
d2c3fb32d9 Tidy: Indentation 2021-09-22 01:11:38 -05:00
Adam Porter
140aa891f4 Remove: Obsolete macro org-ql 2021-09-22 01:08:54 -05:00
Adam Porter
e49cafe022 Merge: Abbreviate filenames in bookmarks 2021-09-22 01:00:58 -05:00
Adam Porter
c006bc3804 Docs: Update changelog 2021-09-22 01:00:22 -05:00
Akira Komamura
da2bab2552 Fix: Abbreviate file paths in created org-ql bookmarks 2021-09-22 00:59:18 -05:00
Adam Porter
9dfa534e60 Merge: branch 'dynamic-block-closed' 2021-09-22 00:57:00 -05:00
Adam Porter
1c9b99ace9 Docs: Update changelog 2021-09-22 00:56:45 -05:00
Jianye Ye
4646d6d307 Add: (closed) column for dynamic block 2021-09-22 00:52:08 -05:00
Jianye Ye
80970856d6 Add: Sort by (closed) for org-ql-select 2021-09-22 00:52:08 -05:00
Adam Porter
8f307a8820 Merge: Fix shadowed pcase pattern
Fixes #214.  Thanks to Cyrille Froehlich (@cfroehli), Ihor
Radchenko (@yantar92), Kai von Fintel (@fintelkai), and @aur3l14no.
2021-09-22 00:37:17 -05:00
Cyrille Froehlich
bbeee64f41 Simplify tags-all/tags-local too + Fix formatting 2021-07-28 08:39:22 +09:00
Cyrille Froehlich
99a2285317 Simplify tags-inherited normalizer 2021-07-28 08:35:13 +09:00
Cyrille Froehlich
363f7623c1 Fix: pcase pattern shadowed 2021-07-28 08:35:13 +09:00
Adam Porter
94f9e6f303 Add/Change: reverse sorter, and reverse sorting order
This is a breaking change of sorts in that searches using multiple
sorting methods will have to have the order of the sorters reversed to
get the same result.  Unfortunate, but I think it's worth it in the
end, and this is pre-1.0, anyway.

Fixes #143.
2021-07-12 21:33:24 -05:00
Ihor Radchenko
8342656b2d Fix: (org-ql-regexp-part-ts-repeaters) Habit repeaters with min/max
Closes #226.
2021-06-24 08:14:39 -05:00
Adam Porter
822bb774cd Tests: Use min/max-style habit repeater in a timestamp
See #226.
2021-06-24 08:14:16 -05:00
Adam Porter
e2a1d16cc4 Tests: Normalization of tags-inherited predicate
See #216.
2021-06-23 01:47:05 -05:00
Ihor Radchenko
1198284c7e Fix: (org-ql-regexp-part-ts-repeaters) Repeaters with a "."
Fixes #225.
2021-06-23 01:26:10 -05:00
Adam Porter
32f7e48e12 Tests: Add "." to a timestamp repeater
See #225.
2021-06-23 01:21:59 -05:00
Adam Porter
e03fb24f9b Fix: (outline-path) Normalizer infinite loop
Hopefully there aren't more of these lurking, but with the recent
--normalize-query change, there might be...
2021-06-21 07:55:58 -05:00
Adam Porter
482a5c939b Fix: Cache invalidation of relative-date ts-related predicates
Fixes #223.  Thanks to Ihor Radchenko (@yantar92) for reporting.
2021-06-21 06:18:03 -05:00
Adam Porter
87b3d0bd97 Add: :with-time argument for timestamp predicates
Squashed commit of the following:

commit 5d43309c55
Author: Adam Porter <adam@alphapapa.net>
Date:   Sat Jun 19 02:24:08 2021 -0500

    WIP: Allow "with-time=" in string queries

commit 9e683e17c1
Author: Adam Porter <adam@alphapapa.net>
Date:   Sat Jun 19 02:09:42 2021 -0500

    WIP: Update docstrings, comments, and readme

commit 8e93f4cbb3
Author: Adam Porter <adam@alphapapa.net>
Date:   Sat Jun 19 00:18:21 2021 -0500

    WIP: Tidy

commit 26c58c6c77
Author: Adam Porter <adam@alphapapa.net>
Date:   Fri Jun 18 23:55:42 2021 -0500

    WIP

commit a24b41d7e5
Author: Adam Porter <adam@alphapapa.net>
Date:   Fri Jun 18 22:27:43 2021 -0500

    WIP

commit 71857f9b43
Author: Adam Porter <adam@alphapapa.net>
Date:   Fri Jun 18 00:05:53 2021 -0500

    WIP: (ts :with-time) and supporting changes

commit 745e53b313
Author: Adam Porter <adam@alphapapa.net>
Date:   Thu Jun 17 22:54:51 2021 -0500

    Add: New timestamp regexps

commit f87be23954
Author: Adam Porter <adam@alphapapa.net>
Date:   Thu Jun 17 20:03:02 2021 -0500

    WIP

commit e893e65207
Author: Adam Porter <adam@alphapapa.net>
Date:   Sat Dec 19 03:54:11 2020 -0600

    WIP: Add with-time arg to timestamp predicates
2021-06-19 03:28:14 -05:00
Adam Porter
88151b7f00 Fix: (org-ql-view--complete-sort) Add random method
Such a minor omission, not worth a release or changelog entry.
2021-06-17 18:58:48 -05:00
Adam Porter
84e48d9d2f Docs: Mention non-sexp syntax as applies to (effort) and (level) 2021-06-16 21:05:40 -05:00
Adam Porter
d8bfa2317a Add: (effort) predicate
Closes #80.
2021-06-16 20:44:00 -05:00
Adam Porter
0dc073ffac Comment: Add TODO 2021-06-16 20:01:24 -05:00
Akira Komamura
bd6487e814 Meta: Add Emacs 27.2 to CI 2021-06-16 19:12:08 -05:00
Adam Porter
55f5708cc0 Tests: Fix link-to-self-buffer-search test
Also, ensure that views that search non-file-backed buffers can’t be
linked to.

This fixes the test failures on Emacs 27.2 and Emacs 28
pre-release.  (I can't explain why this test didn't fail on earlier
versions, but it's not worth figuring out.)
2021-06-16 19:09:20 -05:00
Akira Komamura
1421dda20c Fix: (link) :regexp-p argument 2021-06-16 17:57:43 -05:00
Akira Komamura
410888e449 Fix: (link) :target argument 2021-06-16 17:57:41 -05:00
Adam Porter
831a21b63e Merge: 0.5.2
NOTE: Due to changes between 0.5 and 0.6, the fixes don't merge
cleanly, so they will be applied in subsequent commits.  See #220.
2021-06-16 17:54:33 -05:00
Adam Porter
d3b0ef2f51 Release: 0.5.2 2021-06-16 17:45:20 -05:00
Adam Porter
eead60be8c Docs: Update changelog 2021-06-16 17:42:40 -05:00
Adam Porter
0cc4c5b549 Fix: (link) :regexp-p argument
See #220.  Thanks to Akira Komamura (@akirak).
2021-06-16 17:42:40 -05:00
Akira Komamura
e05de210c7 Fix: (link) :target argument
See #220.
2021-06-16 17:42:35 -05:00
Adam Porter
c57f0975f6 Tests: Add more LINK tests
Closes https://github.com/alphapapa/org-ql/pull/222.  See also
https://github.com/alphapapa/org-ql/pull/220.

Thanks to Akira Komamura (@akirak).
2021-06-16 17:28:00 -05:00
Adam Porter
5bba08403d Meta: 0.5.2-pre 2021-06-16 17:26:44 -05:00
Adam Porter
3c7a93d71f Merge: 0.5.1 2021-06-08 11:17:29 -05:00
Adam Porter
3a04b10738 Release: 0.5.1 2021-06-08 11:12:44 -05:00
Adam Porter
832adfee20 Merge: Fix custom sorting functions 2021-06-08 11:09:22 -05:00
Adam Porter
628fce8f13 Docs: Update changelog 2021-06-08 11:06:54 -05:00
savnkk_manjaro
dc32dcdaaa Fix: (org-ql-select) Use -sort instead of sort
Fixes #186.
2021-06-08 11:03:48 -05:00
Adam Porter
7a8e3b2e8e Tidy: Indentation
Due to changes in dash.
2021-06-08 10:56:05 -05:00
Adam Porter
105715309e Merge: Update dash dependencies 2021-06-08 10:49:37 -05:00
Adam Porter
7b701cc379 Docs: Update changelog 2021-06-08 10:48:37 -05:00
Adam Porter
5b248f3304 Meta: 0.5.1-pre 2021-06-08 10:39:09 -05:00
Mark Hudnall
21b3bd2d6a Change: Bump dash.el to fix helm-org-ql
See https://github.com/alphapapa/org-ql/issues/179.  dash.el 2.18.1
fixed an issue with `-flatten-n` that was causing `helm-org-ql`
functions to fail silently.
2021-06-08 10:21:45 -05:00
Basil L. Contovounesios
c9fe19969e Change: Don't depend on deprecated dash-functional
Dash 2.18.0 now subsumes dash-functional.

See https://github.com/magnars/dash.el/blob/master/NEWS.md#from-217-to-218
2021-02-28 15:01:03 -08:00
Adam Porter
208e103ecc Tidy: Function declarations
Using the FILEONLY argument of declare-function doesn't seem to be
enough to silence the check-declare warning, so maybe also using
"ext:" will do it.
2020-12-13 07:58:54 -06:00
Adam Porter
ec2e624dc2 Change: Bind predicates per-query instead of per-buffer 2020-12-12 06:09:49 -06:00
Adam Porter
2dfd378d5f Add/Change: (heading-regexp), (heading) predicates
Closes #64.  Closes #68.

Thanks to Feng Shu (@tumashu) for suggestions.
2020-12-09 21:28:55 -06:00
Adam Porter
31efd5a26d Comment: Add TODO 2020-12-09 21:18:10 -06:00
Adam Porter
1389ccb46b Revert: "Change: (olp, olps) Optimize multiple args with heading query"
This reverts commit 2d07cb0822.

See issue #160.  Thanks to @yantar92 for reporting.
2020-12-03 22:14:31 -06:00
Adam Porter
b62896a583 Fix: (org-ql-view.el) Declare org-ql-search function
Even though check-declare doesn't seem to find cl-defun forms, even
though its code appears to look for them...
2020-12-03 12:34:41 -06:00
Adam Porter
2d07cb0822 Change: (olp, olps) Optimize multiple args with heading query 2020-12-03 12:27:32 -06:00
Adam Porter
73209cf48e Meta: (pre-push) Only test before pushing master 2020-11-24 17:02:12 -06:00
Adam Porter
6fb8b42e3b Meta: Apply makem.sh customizations 2020-11-24 13:03:44 -06:00
Adam Porter
6ced616836 Tidy: Docstring, add comment 2020-11-24 12:45:16 -06:00
Adam Porter
5fab48e2cd Meta: Update makem.sh, etc. 2020-11-24 12:17:39 -06:00
Adam Porter
8fb6efecc1 Fix: Compile warnings 2020-11-24 11:47:42 -06:00
Adam Porter
014d49f416 Change/Fix: Require peg 1.0, fix variable binding depth errors
Had to (and needed to, anyway) use peg-1.0.  And while this does less
macro magic, and less magic with cl-eval-when, I couldn't get around
using eval.  I wish peg had a function that takes a list of rules and
returns a predicate that matches a string or at point.  (I tried to
work around the lack of that by using parts of peg macros, but it's
very complicated, and everything I tried had one problem or another.)
2020-11-24 11:20:59 -06:00
Adam Porter
890c24786a Docs: (defpred.org) Fix macro example
Thanks to Pete Kazmier (@pkazmier) for reporting (see issue #152).
2020-11-24 03:59:26 -06:00
Adam Porter
6e6f62dfaa Meta: (test.yml) Test all branches 2020-11-23 05:09:33 -06:00
Adam Porter
d4ea5df160 Docs: Update readme 2020-11-23 05:08:29 -06:00
Adam Porter
2598d558ed Tidy: (helm-org-ql) 2020-11-23 05:02:52 -06:00
Adam Porter
170276bdeb Tidy: (helm-source-org-ql-views) Rename to helm-org-ql-views-source
package-lint complains about the symbol prefix.  I guess following the
helm-source-* convention isn't a big deal.
2020-11-23 04:58:12 -06:00
Adam Porter
92d0e27340 Change: (helm-org-ql.el) Headers, requirements
Preparing for it to be a separate package.
2020-11-23 04:57:49 -06:00
Adam Porter
c3e23c3072 Docs: Mention deprecated macro 2020-11-23 04:52:01 -06:00
Adam Porter
37c6f23297 Docs: (Caching) Fix and clarify 2020-11-23 04:49:30 -06:00
Adam Porter
27609264a5 Tidy: (org-ql--defpred)
Somehow this old macro snuck back in...maybe in a merge gone bad?
2020-11-23 04:21:10 -06:00
Adam Porter
92d099caf6 Docs: (defpred.org) Add HTML export
It looks nice, even if it isn't practically viewable on GitHub.
2020-11-23 03:32:24 -06:00
Adam Porter
b01106bd0f Docs: (defpred.org) Formless, conclusion 2020-11-23 03:12:39 -06:00
Adam Porter
a06ea62521 Docs: (defpred.org) Tidy 2020-11-23 03:02:31 -06:00
Adam Porter
7c8cd41052 Docs: (defpred.org) Fix typos
Thanks to Alain M. Lafon (@munen).
2020-11-23 02:53:31 -06:00
Zen Monk Alain M. Lafon
58bf5dc0a3
Proofread defpred tutorial 2020-11-23 09:33:44 +01:00
Adam Porter
a24de862ec Fix: (org-ql-defpred) Use alist-get
Until map-2.1 can automatically be installed with makem.sh...
2020-11-23 02:03:58 -06:00
Adam Porter
485bbdfda8 Meta: Upgrade makem.sh, Makefile, test.yml 2020-11-23 02:03:48 -06:00
Adam Porter
a2acf93a2c Docs: (defpred.org) Fix example 2020-11-23 01:33:14 -06:00
Adam Porter
57b3eeba49 Merge: org-ql-defpred
Squashed commit of the following:

commit a0ace307b0de3f5e811f042fd9f0b821a0bbc95c
Author: Adam Porter <adam@alphapapa.net>
Date:   Mon Nov 23 01:11:07 2020 -0600

    Docs: Fix TOC

commit bef9f3c9b5b762070445c76ac3c833e51dd893ba
Author: Adam Porter <adam@alphapapa.net>
Date:   Mon Nov 23 01:09:33 2020 -0600

    Docs: (README.org) Add org-ql-defpred

commit ff0257696fe87764e3289e12ddc336377a9a5d01
Author: Adam Porter <adam@alphapapa.net>
Date:   Mon Nov 23 00:52:06 2020 -0600

    Docs: Improve defpred.org

    Thanks to piyo in #emacsconf@freenode.

commit 18d6d73a99c336cd637c99309ee5d150106b73b7
Author: Adam Porter <adam@alphapapa.net>
Date:   Mon Nov 23 00:35:24 2020 -0600

    Docs: Improve custom predicate tutorial

    Closes #155.  Thanks to Merlin Göttlinger (@mgttlinger) for suggesting
    improvements.

commit b8cbe36fb3
Author: Adam Porter <adam@alphapapa.net>
Date:   Mon Nov 23 00:05:52 2020 -0600

    Docs: Add custom predicate tutorial

commit b1008d0c52
Author: Adam Porter <adam@alphapapa.net>
Date:   Sun Nov 22 19:34:16 2020 -0600

    Docs: Update readme

commit 73d4f95cd4
Merge: 9a2719f 148a193
Author: Adam Porter <adam@alphapapa.net>
Date:   Sun Nov 22 19:29:15 2020 -0600

    Merge branch 'wip/0.6-pre' into wip/define-predicate

...
2020-11-23 01:13:03 -06:00
Adam Porter
148a193ca0 Meta: 0.6-pre 2020-11-22 19:06:16 -06:00
Adam Porter
3924b023e0 Release: 0.5 2020-11-22 18:19:02 -06:00
Adam Porter
90f712aba9 Change: (org-ql) Declare macro obsolete 2020-11-22 18:15:39 -06:00
Adam Porter
56a08208e5 Change: (defgroup org-ql) Add Info manual link 2020-11-22 17:31:15 -06:00
Adam Porter
7f8328a87c Change: (-view--link-follow) Ignore second argument
Hopefully this allows compatibility with Org 9.4, since Org's news
file doesn't say what the second argument is.
2020-11-22 17:25:59 -06:00
Adam Porter
c41cd4be82 Change: (-view--link-open, -view--link-follow) Rename function
For consistency with Org's naming scheme.
2020-11-22 17:25:04 -06:00
Adam Porter
46ad26f1a0 Change: Require org-super-agenda 1.2
Which includes the safety checks we use for links.
2020-11-22 17:20:12 -06:00
Adam Porter
2aa8e84fc9 Fix: peg-related compiler warnings 2020-11-22 17:09:36 -06:00
Adam Porter
6bb2db9392 Docs: Improve query explanation
See #92.
2020-11-20 08:22:41 -06:00
Adam Porter
e4fb1cce2e Docs: Explain how caching works
Fixes #132.  Thanks to Mikhail Skorzhinskii (@mskorzhinskiy) for
suggesting.
2020-11-20 08:13:15 -06:00
Adam Porter
f8a531f2be Merge: 0.4.9 2020-11-20 08:01:24 -06:00
Adam Porter
cd819c1e84 Release: 0.4.9 2020-11-20 07:55:55 -06:00
Adam Porter
038c5ae3bf Update changelog, version headers
Released as 0.4.9.
2020-11-20 07:54:44 -06:00
Ihor Radchenko
0f5cf5eff3 Honor restriction when it is set from inside agenda dispatcher 2020-11-20 07:43:03 -06:00
Adam Porter
1a77cb0e18 Tests: Add more sexp link tests 2020-11-18 08:15:47 -06:00
Adam Porter
e2dbeb4620 Notes: Move to meta/notes branch 2020-11-18 04:31:15 -06:00
Adam Porter
6b96c3684d Notes: Update 2020-11-18 04:16:07 -06:00
Adam Porter
dbf5dd3b0b Merge: 0.4.8 2020-11-18 04:14:01 -06:00
Adam Porter
a9c7345066 Notes: Add idea 2020-11-18 03:04:34 -06:00
Adam Porter
29090c4448 Fix: (org-ql--sort-by) Use reverse instead of nreverse
Released as 0.4.8.
2020-11-18 00:18:20 -06:00
Adam Porter
6618318622 Update readme, version header 2020-11-18 00:03:41 -06:00
Imran Khan
d500d28af5 Change nreverse to non-destructive version 2020-11-17 23:58:20 -06:00
Adam Porter
619fd8c403 Notes: Update 2020-11-17 00:37:21 -06:00
Adam Porter
814f3f0eda Notes: Update 2020-11-17 00:25:34 -06:00
Adam Porter
a02514c0dc Tests: Test dynamic block sexp query warning 2020-11-17 00:24:26 -06:00
Adam Porter
71703def04 Change: Query safety checks
- Variable org-ql-ask-unsafe-queries replaces
  org-ql-view-ask-unsafe-links.
- New function: org-ql--ask-unsafe-query.
- Tests: Improve
2020-11-16 23:52:15 -06:00
Adam Porter
0ca6b4b119 Tidy: Docstring 2020-11-16 23:51:24 -06:00
Adam Porter
d73d28f4c3 Notes: Add idea 2020-11-16 22:13:23 -06:00
Adam Porter
50ba441415 Fix: (org-ql-view-bookmark-handler) Bookmark destructuring
See #147.  Thanks to @tpeacock19 for reporting.
2020-11-16 21:16:09 -06:00
Adam Porter
2a010f29c1 Fix: (org-dblock-write:org-ql) Use org-link-display-format
Fixes #153.  Thanks to @jbriquet for reporting.
2020-11-16 20:08:44 -06:00
Adam Porter
2c14903c76 Notes: Update 2020-11-16 05:53:06 -06:00
Adam Porter
ec0f8c7231 Meta: Update makem.sh, Makefile, test.yml 2020-11-16 05:23:33 -06:00
Adam Porter
244c8290d5 Notes: Update 2020-11-16 05:13:05 -06:00
Adam Porter
badf214db7 Tests: Adjust error message for Org 9.3 and/or Emacs 27.1
I don't know if this is due to the Org 9.3 link change or if something
print/read-related changed in Emacs 27.1, but this should fix the
test, hopefully on both versions.
2020-11-16 05:06:55 -06:00
Adam Porter
673edaca11 Fix: (org-ql-view--link-open) Handle Org 9.3 links
Or try to, anyway...
2020-11-16 04:52:45 -06:00
Adam Porter
9396385fed Tests: Add a couple of asserts
Not absolutely needed now, but they might help in the future if
something changes again.
2020-11-16 04:49:28 -06:00
Adam Porter
12b3b426b5 Tests: Call org-store-link interactively 2020-11-16 04:49:20 -06:00
Adam Porter
5814cff188 Tests: (test.yml) Let lint fail
Some of these lint warnings aren't going to be fixed anytime soon, and
it's more useful to let the tests indicate success in that case.
2020-11-16 03:52:26 -06:00
Adam Porter
c07971cd57 Tidy: Use -let* instead of pcase-let* for plists
This actually only fixes a problem with running the tests, because I
don't have a way to force map-2.1 to be installed into the sandbox, so
the tests on CI always fail.  So for now we just use -let* for this.
2020-11-16 03:49:46 -06:00
Adam Porter
faaa6f7ee9 Test: Tidy
This prevents extra output about buffers without headings.
2020-11-16 03:49:15 -06:00
Adam Porter
c3aa701e57 Tidy: Silence, Checkdoc!
Some of these warnings are too much.
2020-11-16 03:29:10 -06:00
Adam Porter
e9815f39a0 Tests: Fix link-opening test 2020-11-16 03:16:40 -06:00
Adam Porter
7770285002 Fix: (org-ql-view--contract-buffers-files) Non-existent org-directory
Fixes #138.  Fixes #139.  Thanks to Matt Huszagh (@matthuszagh) for
reporting.

This *actually* fixes those issues.  The 0.4.7 release is related to
those issues, but those issues actually arose in code added to
0.5-pre.
2020-11-16 02:41:32 -06:00
Adam Porter
7b1919c2d5 Merge: 0.4.7 2020-11-16 02:29:13 -06:00
Adam Porter
0d12cdb3f5 Fix: (org-ql-search-directories-files) Error unless org-directory
Fixes #139.  Thanks to Matt Huszagh (@matthuszagh) for reporting.

Released as 0.4.7.
2020-11-16 02:25:45 -06:00
Adam Porter
e39fb1be5a Tests: Tidy 2020-11-16 02:11:38 -06:00
Adam Porter
9d86ee9e10 Change/Fix: Bookmark, link storing/loading/safety
This makes several changes and fixes and adds test cases for all the
combinations I'm aware of.

See #147.  Thanks to @tpeacock19 for patiently reporting these issues.

Squashed commit of the following:

commit d1b396c5654ae3fa8ad03d0d4b2cbde20000fa1a
Author: Adam Porter <adam@alphapapa.net>
Date:   Mon Nov 16 02:01:23 2020 -0600

    WIP: Fixes

commit 23215a723c4bf6e249c330863e01029166db56c3
Author: Adam Porter <adam@alphapapa.net>
Date:   Mon Nov 16 01:34:34 2020 -0600

    WIP: Fixes

commit 97b13d09d4d52bb168bfc19fb6f8daf2964f4b6c
Author: Adam Porter <adam@alphapapa.net>
Date:   Mon Nov 16 00:46:49 2020 -0600

    WIP: Test links too

    Everything passes now.

commit 1866a71dbbb6416f7e365c90cadd269765d52b70
Author: Adam Porter <adam@alphapapa.net>
Date:   Sun Nov 15 22:22:22 2020 -0600

    WIP: Test loading/saving bookmarks
2020-11-16 02:02:22 -06:00
Adam Porter
b04d0263a4 Notes: Update 2020-11-15 21:07:51 -06:00
Adam Porter
8a1fd14590 Fix: (org-ql-view--link-store) Indirect buffers
Probably the best thing to do, even if it's not "correct" in a sense.
2020-11-14 22:29:53 -06:00
Adam Porter
dabb812a3c Notes: Update 2020-11-14 22:25:11 -06:00
Adam Porter
5c8260b272 Notes: Add checklist 2020-11-14 20:58:32 -06:00
Adam Porter
511edbfff8 Notes: Make ToC after sorting 2020-11-14 20:58:19 -06:00
Adam Porter
60d0c2a455 Notes: Update 2020-11-14 20:53:30 -06:00
Adam Porter
5b401cd8b7 Tidy: (org-ql-view-bookmark-make-record) 2020-11-14 20:36:28 -06:00
Adam Porter
0a2b751464 Fix: (org-ql-view-bookmark-make-record) List of filenames
Fixes #148.  Thanks to @tpeacock19 for reporting.
2020-11-14 20:35:52 -06:00
Adam Porter
1b12d4e9b0 Fix: (org-ql-view--link-store) Don't re-format formatted queries
org-ql-view--format-query already returns a string.
2020-11-14 05:43:50 -06:00
Adam Porter
4a8deb541e Comment: Add FIXME 2020-11-14 05:43:12 -06:00
Adam Porter
0365b785cc Fix: (org-ql--defpred) Add to predicates variable when compiling
This seems to fix an occasional weird bug encountered when
byte-compiling and loading this file.  I can't explain why it only
happens sometimes, but this seems to fix it, and it stands to reason
why it does, so it seems like the right thing to do.
2020-11-14 05:41:37 -06:00
Adam Porter
89ff02a150 Fix: (org-ql--query-sexp-to-string) Ancestors, etc. queries 2020-11-14 05:40:24 -06:00
Adam Porter
dd30f07942 Notes: Update 2020-11-14 05:22:59 -06:00
Adam Porter
be4e941fc9 Notes: Update 2020-11-13 03:13:48 -06:00
Adam Porter
51f987c6b8 Fix: (org-dblock-write:org-ql) Rename unused variables 2020-11-13 02:45:45 -06:00
Adam Porter
f8b41ea027 Fix: (org-dblock-write:org-ql) Remove unused argument 2020-11-13 02:44:46 -06:00
Adam Porter
b90e6e25d0 Tests: Use test buffer for link safety tests 2020-11-13 02:42:52 -06:00
Adam Porter
56647d4b11 Notes: Update 2020-11-12 05:23:59 -06:00
Adam Porter
cd95d10f05 Add: Dynamic block (property) column 2020-11-12 05:01:20 -06:00
Adam Porter
2b21871a02 Notes: Update 2020-11-12 04:13:47 -06:00
Adam Porter
337bfa6695 Add: (tags-regexp, tags*) Predicate 2020-11-12 04:09:57 -06:00
Adam Porter
cbd4ea89f4 Notes: Update 2020-11-12 03:25:47 -06:00
Adam Porter
f63012dd5a Fix: (org-ql-view--link-store) Rejection of unlinkable buffers
Also, remove the Org <=9.1.4 compatibility code.  It's not worth it.
I'm probably the only person who needs it, anyway, and I can live with
the double-call until I upgrade my Org version.

Fixes #148.  Thanks to @tpeacock19 for reporting.
2020-11-12 02:44:16 -06:00
Adam Porter
284eda87e5 Fix: (org-ql-view--link-store) Test Org version
See #147.  Thanks to @tpeacock19 for reporting.
2020-11-12 02:10:57 -06:00
Adam Porter
a069cf5b2c Notes: Update 2020-11-12 00:28:32 -06:00
Adam Porter
5e790c48ac Tests: Add tests for link safety 2020-11-12 00:22:45 -06:00
Adam Porter
a5d4886880 Fix: (org-ql-view--link-open) Safety check the sort parameter 2020-11-12 00:22:23 -06:00
Adam Porter
689cfd68e7 Fix: (-view--link-open) Set org-super-agenda-allow-unsafe-groups 2020-11-11 22:52:54 -06:00
Adam Porter
6ab74454d0 Fix: (org-ql-view--expand-buffers-files) Remove eval support
This prevents arbitrary code execution when opening "org-ql-search:"
links.  (The links feature was just pushed to master in the last day
or so, and no stable release with the feature has been tagged.)  This
fix also means that arbitrary expressions are no longer accepted when
interactively completing the buffers-files argument to
org-ql-search (a worthy trade, I think; users who need to do that can
call the function from Lisp).
2020-11-11 20:51:24 -06:00
Adam Porter
c2c7efed00 Docs: Update readme
Links can search more than just the current document now.
2020-11-11 20:38:05 -06:00
Adam Porter
2bed84aa1e Fix: (org-ql-view--contract-buffers-files) Don't check file exists
If the buffer has no filename, this will signal an error.
2020-11-11 19:54:13 -06:00
Adam Porter
f8d671a7b8 Docs: Thanks to @tpeacock19 2020-11-11 19:52:46 -06:00
Adam Porter
b0b8c6334d Fix: (helm-org-ql.el) Compiler warnings 2020-11-11 19:52:46 -06:00
Adam Porter
4b557857d3 Tidy: Indentation 2020-11-11 19:52:46 -06:00
Adam Porter
b0e8fa2734 Tidy: Indentation 2020-11-11 19:52:46 -06:00
Adam Porter
04c94bc141 Change: (org-ql-view.el) Rename bookmark functions
They shouldn't be private functions, especially since one is autoloaded.
2020-11-11 19:52:24 -06:00
Adam Porter
0101bbebde Comment: Remove useless package header
Not the main library file.
2020-11-11 19:52:24 -06:00
Adam Porter
6970a952ba Fix: (org-ql-search.el) Require map
Need to explicitly load it so that map 2.1 will be loaded when the
file is byte-compiled, otherwise the pcase map expansions will fail.
2020-11-11 19:52:24 -06:00
Adam Porter
33df77420e Notes: Update 2020-11-11 19:52:24 -06:00
Adam Porter
87b952c7bf Fix: (org-ql-view--link-store) Don't store link to buffers 2020-11-11 19:52:24 -06:00
Adam Porter
01660aac22 Notes: Update 2020-11-11 19:52:24 -06:00
Adam Porter
ef40a25b05 Change: (org-ql-view--link-store) Convert queries to strings
See #147.
2020-11-11 19:52:24 -06:00
Adam Porter
e15cc3eb76 Add: (--query-sexp-to-string) 2020-11-11 19:52:24 -06:00
Adam Porter
07d21e57c0 Tidy 2020-11-11 19:52:24 -06:00
Adam Porter
bfd4d462a0 Add/Change/Fix: Storing links to containing buffer or files
This feels too complicated, but I don't see a way around it, short of
redesigning all of the argument expansion/contraction, which might end
up in the same place, anyway.

See #147.
2020-11-11 19:52:24 -06:00
Adam Porter
8102d7a8ee Fix: (org-ql-view--format-element)
Actually, really fix it this time.

Fixes #150.  Thanks to @tpeacock19 for reporting.
2020-11-11 18:11:24 -06:00
Adam Porter
168041f0df Comment: Add FIXME 2020-11-11 04:24:34 -06:00
Adam Porter
bd9162381f Notes: Update 2020-11-11 01:45:55 -06:00
Adam Porter
73da48d9da Comment: Add FIXMEs 2020-11-11 00:23:32 -06:00
Adam Porter
78fd672cc7 Fix: (org-ql-view--format-element) Get tags from marker buffer
Fixes bug introduced in 359a280d11.

Fixes #150.  Thanks to @tpeacock19 for reporting.
2020-11-11 00:23:17 -06:00
Adam Porter
23e73addcf Fix: (-view--link-store, -view--link-open) Types, current-buffer
This is regrettably complicated.  Maybe someday Elsa will help...

Fixes #147 (again).  Thanks to @tpeacock19 for reporting.
2020-11-10 20:35:32 -06:00
Adam Porter
60b457eea4 Fix: (org-ql-view.el) Compiler warnings 2020-11-10 19:43:48 -06:00
Adam Porter
93f60ad478 Fix: (org-ql-view--link-store) Handle single filenames
Fixes #147.  Thanks to @tpeacock19 for reporting.
2020-11-10 19:42:12 -06:00
Adam Porter
364dfabca4 Add: (org-ql-view-ask-unsafe-links) 2020-11-10 19:42:12 -06:00
Adam Porter
e3c7aaf98d Docs: (org-ql-search) Add Info links to docstring 2020-11-10 18:37:04 -06:00
Adam Porter
5d563809e2 Change: (-view--link-open, -view--link-store) Links to views of files
Fixes #147.  Thanks to @tpeacock19 for reporting.
2020-11-10 18:27:33 -06:00
Adam Porter
1b43a88d32 Fix: (org-ql-view--link-store) Check buffers-files only when needed
See #147.  Thanks to @tpeacock19 for reporting.
2020-11-10 17:45:27 -06:00
Adam Porter
5a0ed259bc Notes: Add TODO 2020-11-10 05:21:56 -06:00
Adam Porter
0b65eb221e Notes: Add TODO 2020-11-10 04:32:21 -06:00
Adam Porter
0cfe44084b Tidy: (org-dblock-write:org-ql) 2020-11-10 04:24:38 -06:00
Adam Porter
2e469fa547 Tidy: (org-ql--peg-parse-string) Silence, Checkdoc! 2020-11-10 04:14:44 -06:00
Adam Porter
6d5ce97dc7 Fix: Byte-compile warnings 2020-11-10 04:14:01 -06:00
Adam Porter
9bdfcc1d3d Add: (org-dblock-write:org-ql) Custom column headers 2020-11-10 02:28:44 -06:00
Adam Porter
992f3c2675 Add: Link support 2020-11-10 02:02:55 -06:00
Adam Porter
c0a10ba96a Fix: (org-dblock-write:org-ql) cl-minusp 2020-11-10 00:27:35 -06:00
Adam Porter
8e6aae95a0 Notes: Update 2020-11-10 00:06:37 -06:00
Adam Porter
c0ded3ded3 Add: Dynamic block 2020-11-09 23:58:17 -06:00
Adam Porter
2c466ebdcd Notes: Dynamic blocks update 2020-11-09 22:42:59 -06:00
Adam Porter
90b7a9a48b Notes: Update 2020-11-09 01:55:47 -06:00
Adam Porter
73e17844a3 Meta: Update .gitignore 2020-11-09 01:41:05 -06:00
Adam Porter
17fd923fc9 Meta: Delete Cask file 2020-11-09 01:32:04 -06:00
Adam Porter
9f98b87a8e Comment: Add FIXME 2020-11-09 00:20:33 -06:00
Adam Porter
a91bb208a3 Notes: Update 2020-11-08 23:29:41 -06:00
Adam Porter
b10522de6f Notes: Add idea 2020-11-08 22:15:54 -06:00
Adam Porter
4194456b40 Notes: Update, add ToC, sort, etc. 2020-11-08 20:07:15 -06:00
Adam Porter
359a280d11 Change/Fix: (org-ql-view--format-element) Use org-ql--tags-at
Use org-ql--tags-at instead of org-get-tags/org-get-tags-at.  This
uses our cache, which should improve performance, and it obviates the
function alias for Org versions before 9.3 (which occasionally
misbehaves, e.g. if Org is reloaded).
2020-11-08 18:05:27 -06:00
Adam Porter
958cd50794 Meta: Update makem.sh 2020-11-08 18:02:53 -06:00
Adam Porter
5e61d1b326 Fix: (org-ql--peg-parse-string) Unused lexical variable warning
peg.el doesn't use lexical binding, and org-ql.el does, so this caused
a byte-compile warning.  It doesn't seem to change the behavior of the
expanded code, so it should be a safe change...
2020-11-05 11:28:22 -06:00
Adam Porter
94be07244c Fix: (org-ql-view-refresh) Rename buffer uniquely
This is sort of a workaround or preventative measure as much as it is
a fix.  It seemed to be necessary when I was testing bookmark
loading in org-sidebar.
2020-11-05 11:21:33 -06:00
Adam Porter
f88fb549a3 Docs: Add Tips section 2020-11-05 11:21:06 -06:00
Adam Porter
028c25c106 Fix: (-view--bookmark-make-record) Replace buffers with filenames 2020-11-02 21:35:42 -06:00
Adam Porter
e5b4cd1065 Add: Bookmark support 2020-11-02 20:18:34 -06:00
Adam Porter
57708e6cc1 Change: (-view--plist, -view-save) Factor out plist code
In preparation for bookmark support.
2020-11-02 20:12:31 -06:00
Adam Porter
65cc3fc24e Notes: Add task 2020-10-19 00:24:24 -05:00
Adam Porter
6633dbb276 Release: 0.4.6
-----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1
 
 iEYEABECAAYFAl8L0BwACgkQ5+GdyTDsrJsFVQCdGz0i4KXwrnqcQC7Ov5/b+YSH
 lUEAoIJBRRJ462lJbe4nzkOkrB3VMIGF
 =JOpa
 -----END PGP SIGNATURE-----

Merge: 0.4.6
2020-07-12 22:09:03 -05:00
Adam Porter
0080055690 Fix: Copy macro peg-parse-string from peg-tests.el
Unfortunately, the macro was moved from peg.el to peg-tests.el in
later versions of peg, so we copy it for our use here.

Fixes #75.  Thanks to Karl Voit (@novoid) and @karlicoss for
reporting.

Released as 0.4.6.
2020-07-12 22:08:01 -05:00
Adam Porter
c847afe0b5 Merge: 0.4.5 2020-05-01 06:31:45 -05:00
Adam Porter
5a031bf5c1 Fix: (org-ql--select) Bind case-fold-search only around preamble
Fixes #114.  Thanks to @bitclick for reporting.

Released as 0.4.5.
2020-05-01 06:27:30 -05:00
Adam Porter
f4d7399e67 Fix: (org-ql-view--contract-buffers-files) Only compare to function
If the org-agenda-files variable points to a file pointing to a list
of agenda files, it shouldn't be compared to.  We should only compare
to the value returned by the org-agenda-files function.

Fixes #104.  Thanks to @gdindi for reporting.
2020-04-07 12:06:57 -05:00
Adam Porter
81673fc7b5 Fix: (org-ql-predicates) Use eval-and-compile
This is technically correct, even though package.el might obscure the
problem by causing the file to be loaded before it is compiled.
2020-04-07 12:05:24 -05:00
Adam Porter
ab5e9aa911 Notes: Add idea 2020-03-26 04:41:46 -05:00
Adam Porter
b3ee9a9c08 Notes: Add tasks, sort 2020-03-20 15:59:28 -05:00
Adam Porter
d55c01d2ae Merge: 0.4.4 2020-03-15 15:04:29 -05:00
Adam Porter
4fef5b089f Fix/Revert: Don't derive a new mode; check a variable in refresh
Using a different major mode in org-ql-view buffers causes some Org Agenda
remote commands to not work, because they test whether the major mode
is org-agenda-mode.  Even though these remote commands are not
guaranteed to work, it was not intended to break them now, so this
restores compatibility with them.

Fixes #102.  Thanks to Alois Janíček (@aloisjanicek) for reporting.

This reverts commit ba7d4a2e82.

Released as 0.4.4.
2020-03-15 15:02:52 -05:00
Adam Porter
5bc4a4a825 Merge: 0.4.3 2020-03-14 14:08:53 -05:00
Adam Porter
ba7d4a2e82 Add/Fix: org-ql-view-mode, and check when refreshing
Use a derived major mode for org-ql-view buffers, and ensure that mode
is active when calling org-ql-view-refresh, to avoid interfering with
buffers in other modes if the user calls the command by accident.

See
<b87156f2bb>.
Thanks to Alois Janíček (@AloisJanicek) for discovering the bug.

Released as 0.4.3.
2020-03-14 14:06:42 -05:00
Adam Porter
ca03ad0d4a Meta: Update makem.sh 2020-03-14 14:01:35 -05:00
Adam Porter
881d298cd0 Comment: Add TODOs 2020-03-13 19:08:26 -05:00
Adam Porter
1688774ddd Change: (org-ql-view--header-line-format) Use keyword args 2020-03-09 17:40:41 -05:00
Adam Porter
f7d8b8c78c Fix: (org-ql-view-map) Bind q to bury-buffer
Because org-agenda-quit isn't useful in org-ql-view buffers.
2020-03-09 13:31:56 -05:00
Adam Porter
996d648560 Fix: (org-ql-view--contract-buffers-files) Handle org-agenda-files 2020-03-08 11:14:13 -05:00
Adam Porter
3349c1d07a Change: (org-ql-view-map) Also bind "g" to refresh
I keep hitting "g" and nothing seems to happen, because it runs the
org-agenda refresh command, which doesn't do anything in org-ql-view
buffers.  This must be happening to other people too.  So let's fix
that.
2020-03-08 11:05:38 -05:00
Adam Porter
8aac3b6100 Fix: (org-ql-view-map) Use set-keymap-parent 2020-03-08 11:05:20 -05:00
Adam Porter
0648196076 Change/Fix: (helm-org-ql.el) Wrap in eval-and-compile
This avoids errors when Helm is not installed, and it seems to work
correctly when Helm is installed.  This should be an improvement until
this file is put in its own package.
2020-03-02 00:58:10 -06:00
Adam Porter
11a0466f92 Fix: (helm-org-ql-map) Use make-composed-keymap
Fixes #99.  Thanks to Akira Komamura (@akirak).
2020-03-02 00:45:27 -06:00
Adam Porter
20f3ce747c Fix: (org-ql-view--contract-buffers-files) Single file/buffer
This fixes the bug for now, but it needs to be tested more carefully.
And now the view dispatcher has a minor bug when changing the list of
buffers-files sometimes that requires pressing it more than once to
get the prompt; not sure if related to this.
2020-03-02 00:23:35 -06:00
Adam Porter
132173b36e Fix: (org-ql-view) Require crm
Fixes #98.  Thanks to @bepolymathe for reporting.
2020-03-02 00:22:41 -06:00
Adam Porter
e811ac5680 Docs: Add mascot 2020-03-01 09:41:35 -06:00
Adam Porter
fc91bdd483 Add/Change: (org-ql-view--contract-buffers-files), etc.
When offering completion of org-ql-view-buffers-files, and when
formatting it in the header line, use the "contracted" form when
possible (i.e. show "org-agenda-files" instead of a list of all the
expanded agenda file filenames).

Fixes #95.  Thanks to Kilian Sprotte (@kisp) for suggesting.
2020-02-27 20:03:25 -06:00
Adam Porter
a459204e78 Change: (view--complete-sort) Separate with spaces, not comma 2020-02-26 19:57:16 -06:00
Adam Porter
60d1bd1f97 Merge: 0.4.2 2020-02-26 19:15:52 -06:00
Adam Porter
4b1e253ee9 Fix: (org-ql-view--add-todo-face) Always return to-do keyword
Even when org-done-keywords-for-agenda is nil.  I'm not sure when this
was broken, but the logic was wrong in this function, and this is the
intended behavior, so this is a bug fix.

Released as 0.4.2.
2020-02-26 19:11:40 -06:00
Adam Porter
9b2ff276a0 Tests: Tidy 2020-02-24 01:48:09 -06:00
Adam Porter
9a56141f6c Add: (link) predicate 2020-02-24 01:47:02 -06:00
Adam Porter
5d720b9fc3 Merge: 0.4.1 2020-02-23 23:27:06 -06:00
Adam Porter
32c68d7f24 Fix: (--pre-process-query) level predicate with args in plain query
Fixes #96.  Thanks to Akira Komamura (@akirak) for reporting.

Released as 0.4.1.
2020-02-23 23:22:11 -06:00
Adam Porter
69692a4b9b Meta: (.gitignore) Ignore scratch.org 2020-02-23 23:00:41 -06:00
Adam Porter
be696ff075 Meta: Update makem.sh, etc. 2020-02-23 22:59:49 -06:00
Adam Porter
048de35b07 Notes: Add idea on partial property value searches 2020-02-13 00:45:01 -06:00
Adam Porter
87b483e4e4 Fix: Require transient in org-ql.el
I guess package-build only finds dependencies in the file named after
the package.
2020-02-11 06:54:19 -06:00
Adam Porter
d8dec50f5c Meta: (.gitignore) Add .sandbox 2020-02-10 09:13:30 -06:00
Adam Porter
9580c0ef67 Change: (org-ql-search) Use new completion functions 2020-02-10 09:12:49 -06:00
Adam Porter
b601a1e777 Update: (org-ql-view-save) Require map 2.0 and use map-elt
I upgrade to map.el 2.0 (from ELPA) locally, which deprecates this
TESTFN argument.
2020-02-10 09:12:46 -06:00
Adam Porter
6e3c0d3c68 Add: Transient view dispatcher 2020-02-10 09:11:59 -06:00
Adam Porter
68a1cf29b6 Docs: Update readme for new org-make-toc 2020-02-10 08:56:39 -06:00
Adam Porter
70f03b200f Docs: Move a screenshot to examples 2020-02-10 08:56:39 -06:00
Adam Porter
ef0c5220c2 Meta: 0.5-pre 2020-02-10 08:56:39 -06:00
Adam Porter
8baeeea49e Notes: Add idea 2020-02-09 15:25:44 -06:00
Adam Porter
e23a026fe5 Meta: Update makem.sh, Makefile, and pre-push
Use local .sandbox sandbox.  (Assumes it is initialized.)
2020-02-09 15:25:44 -06:00
Adam Porter
035c20fc28 Docs: Update comparison 2020-02-04 02:48:29 -06:00
Adam Porter
538373bb48 Release: 0.4 2020-01-22 23:39:25 -06:00
Adam Porter
6e55723e27 Docs: Clarify change notice 2020-01-22 23:38:34 -06:00
Adam Porter
d1a84a7c28 Merge: parent-ancestors-predicates
Closes #77.  Thanks to Josh Moller-Mara (@mm--).
2020-01-22 23:35:02 -06:00
Adam Porter
843564ad8c Add: (org-ql-views) Dangling tasks view 2020-01-22 23:34:34 -06:00
Adam Porter
66f58b97f2 Docs: Add examples, update ToC 2020-01-22 23:34:34 -06:00
Adam Porter
8f2baa10a3 Docs: Fix ToC, info file 2020-01-22 23:34:34 -06:00
Adam Porter
22cacbd8fe Docs: Add credit 2020-01-22 23:34:34 -06:00
Adam Porter
18c6787244 Tidy: (org-ql--pre-process-query) Calling of --query-predicate 2020-01-22 23:34:34 -06:00
Adam Porter
0e1196fd6f Tidy/Docs/Comment: Ancestor/descendant predicates 2020-01-22 23:34:25 -06:00
Adam Porter
adc5447c72 Tidy/Comment: Ancestor/descendant predicates 2020-01-22 23:33:44 -06:00
Adam Porter
3003eb8ad4 Comment: Add tasks 2020-01-22 23:33:29 -06:00
Adam Porter
e48cdf7143 Tests: Add ancestor/parent tests 2020-01-22 23:33:16 -06:00
Josh Moller-Mara
65fb37c30d Add: parent and ancestors predicates
These predicates are analogs to the existing "children" and
"descendents" predicates.

They may be useful for testing parents for specific todo states, or if
they have non-inherited tags (i.e. tags from
"org-tags-exclude-from-inheritance").
2020-01-22 23:32:24 -06:00
Adam Porter
b8a4a53983 Change: (org-ql-views/Stuck projects) Use descendants, not children 2020-01-22 23:24:54 -06:00
Adam Porter
090debabc7 Meta: Fix test.yml
It's easy to overwrite these local changes, but easy to revert them as
well.
2020-01-22 21:14:08 -06:00
Adam Porter
dc26e938fa Fix: (org-ql-block) Autoloads
Fixes #53.  Thanks to reports from Gus Cantieni (@gcantieni), Karl
Voit (@novoid), rieje (@rieje), and Jake | Junxuan (@jakejx).
2020-01-22 18:07:43 -06:00
Adam Porter
b00949d945 Docs: (priority) Update docstring
Fixes #81.  Thanks to Ihor Radchenko (@yantar92).
2020-01-22 17:37:28 -06:00
Adam Porter
2e0d38daae Tidy: (org-ql-select) Sorting pcase 2020-01-22 17:28:11 -06:00
Adam Porter
79d9bd59cf Docs: Add note about 0.5 changes 2020-01-22 17:23:00 -06:00
Jeff Filipovits
154d3bc949 Fix: (org-ql-select) Sorting with single atom sorter
Closes #90.  Thanks to Jeff Filipovits (@legalnonsense).
2020-01-22 17:15:13 -06:00
Adam Porter
9bd1235e00 Meta: Update makem.sh files 2020-01-22 17:05:16 -06:00
Adam Porter
6beada4912 Change: (org-ql-views) Mouseover text, view names 2020-01-22 17:02:44 -06:00
Adam Porter
610b1179c6 Add: (org-ql-view-sidebar-sort-views) 2020-01-22 17:01:03 -06:00
Adam Porter
b7a33170a1 Fix: (org-ql-view--buffer) Set buffer-read-only
Fixes #72.  Thanks to @xeijin.
2020-01-19 00:04:14 -06:00
Adam Porter
b3601cf0ae Add: (org-ql-block) Respect Org Agenda restrictions
Fixes #84.  Thanks to Ihor Radchenko (@yantar92) for reporting.
2020-01-18 23:32:35 -06:00
Adam Porter
0a7e4f349f Add: (org-ql-view-refresh) Message on refresh
Closes #71.  Thanks to @xeijin.

Squashed commit of the following:

commit edac9c6960
Author: Adam Porter <adam@alphapapa.net>
Date:   Sat Jan 18 20:24:28 2020 -0600

    Adjust message, indentation, add changelog entry

commit 6a263e34ff
Author: xeijin <xeijin@users.noreply.github.com>
Date:   Fri Jan 3 19:08:10 2020 +0000

    removing view title

commit fc37e3f146
Author: xeijin <xeijin@users.noreply.github.com>
Date:   Mon Dec 9 22:47:00 2019 +0000

    confirmation message for org-ql-view-refresh

    In keeping with the message displayed by `g` when refreshing an
    org-agenda buffer - if nothing has changed in an `org-ql` buffer
    it can sometimes be difficult to determine if the refresh took
    place at all.
2020-01-18 20:34:13 -06:00
Adam Porter
f42bc4019d Notes: Add note about direx 2020-01-16 09:58:36 -06:00
Adam Porter
22c0b37bbe Notes: Add idea 2020-01-16 06:21:49 -06:00
Adam Porter
fc536cafd6 Tests: (org-ql-test-show-result) Fix symbol 2020-01-13 20:24:14 -06:00
Adam Porter
c4f9a58fd6 Docs: Improve ToCs 2020-01-10 10:36:35 -06:00
Adam Porter
1f79632372 Meta: Update makem.sh, test.yml 2020-01-10 09:29:09 -06:00
Adam Porter
16cb6cef52 Tests: Declare variable 2020-01-08 13:05:50 -06:00
Adam Porter
9d15f503ba Tidy: Use alternatives to map-put
Emacs 27 marks map-put as obsolete and renames it to map-put!, which
causes byte-compilation warnings (sigh...isn't that the definition of
useless churn?).  Of course, map-put! doesn't exist in Emacs 26, so we
can't just use that.  I'm beginning to think that it will never be
possible to make the linting clean.
2020-01-08 12:58:52 -06:00
Adam Porter
3ce29bee46 Meta: (test.yml) Don't count lint failure as job failure
It's more valuable to see at a glance that the tests passed than to
have every run indicate failure because of lint failures, especially
when some of the lint failures come from package-lint issues that may
be patched in the future.
2020-01-08 12:45:53 -06:00
Adam Porter
5b48d62e87 Meta: Update Makefile, makem.sh 2020-01-08 11:01:18 -06:00
Adam Porter
9f5bbeb3f2 Fix: Inherit org-file-tags
Fixes #55.  Closes #57.

Thanks to Mikhail Skorzhinskiy (@mskorzhinskiy).
2020-01-08 10:58:55 -06:00
Adam Porter
dadbbe4a87 Tests: Allow using other data file 2020-01-08 09:26:55 -06:00
Adam Porter
2a7440b639 Tests: Move non-test-data to notes.org 2020-01-08 09:00:24 -06:00
Adam Porter
d2f7b06f3d Tests: Rename symbols, fix loading test data interactively 2020-01-08 06:48:11 -06:00
Adam Porter
21c7dc1587 Notes: Add idea 2020-01-07 08:51:19 -06:00
Adam Porter
fa1e3354b6 Notes: Add org-sql 2020-01-04 09:03:32 -06:00
Adam Porter
2af9515934 Notes: Add about org-element cache 2020-01-04 08:32:41 -06:00
Adam Porter
fb830f8577 Meta: (test.yml) Use checkout@v2 2020-01-04 01:50:11 -06:00
Adam Porter
997765f9ea Tidy: Comment out unused form
Removes a linter warning for now.
2020-01-03 07:02:06 -06:00
Adam Porter
19833cbbec Tidy: Docstrings 2020-01-03 06:57:54 -06:00
Adam Porter
fbff8720b0 Tidy: Habit preamble
No need for rx-to-string, because it's static.
2020-01-03 05:47:00 -06:00
Adam Porter
84b458d6fe Tidy: Move binding 2020-01-03 05:43:19 -06:00
Adam Porter
d28d54c588 Comment: Add/remove TODOs 2020-01-03 05:40:06 -06:00
Adam Porter
e9d5bca842 Comment: Add headings 2020-01-03 04:12:59 -06:00
Adam Porter
689a197066 Meta: Update .gitignore 2020-01-03 04:11:52 -06:00
Adam Porter
3cc7ebe5b4 Meta: Add CI using GitHub Actions
Using test.yml from makem.sh repo.
2020-01-03 04:01:48 -06:00
Adam Porter
b1d9fcf274 Meta: Update Makefile, makem.sh 2020-01-03 03:51:50 -06:00
Yiming Chen
6004ab98da Fix: (view--add-todo-face) Bind org-done-keywords
org-get-todo-face uses org-done-keywords, which is a buffer-local
variable, so it may be nil in the context that
org-ql-view--add-todo-face is called.  See,
e.g. org-agenda-highlight-todo, which does the same thing.

Thanks to Yiming Chen (@dsdshcym).
2020-01-03 03:45:20 -06:00
Enis OEZGEN
317b2ec1b7 Docs: Fix outdated example 2020-01-02 07:48:36 -06:00
Adam Porter
e1c55b5568 Meta: Update makem.sh 2020-01-01 02:59:40 -06:00
Adam Porter
b7e146862d Meta: Add pre-push hook to repo
This doesn't cause it to be run, of course, but it can be symlinked
into place by the user.  Better to commit it than to lose it by
accident sometime.
2020-01-01 02:21:21 -06:00
Adam Porter
6a97f1d95a Meta: Update makem,sh, Makefile 2019-12-31 21:14:51 -06:00
Adam Porter
a513f25b4a Tests: Declare buttercup dependency
Used in makem.sh to parse test dependencies.
2019-12-31 21:13:50 -06:00
Adam Porter
501ab1543b Notes: Add overlay-based cache idea 2019-12-30 22:45:31 -06:00
Adam Porter
c238ebcc97 Add: org-ql-view--format-query
Used to e.g. make timestamp objects in query human readable for
display in view headers.
2019-12-29 17:37:15 -06:00
Adam Porter
091a732a88 Fix: (--value-at) On cache miss, return nil when function does
Previously, on a cache miss, if FN returned nil, the sentinel would be
returned instead of nil.

Closes #78.  Thanks to Josh Moller-Mara (@mm--) for reporting.
2019-12-21 16:28:51 -06:00
Feng Shu
b9dfd7d93b Add: (regexp) Alias "r"
Thanks to Feng Shu (@tumashu).
2019-12-19 13:12:23 -06:00
Adam Porter
70a1acde93 Docs: Tidy changelog for 0.4.0-pre 2019-12-06 22:08:52 -06:00
Adam Porter
cb84615d89 Tidy: helm-org-ql 2019-12-02 20:21:34 -06:00
Adam Porter
d7fe019d6a Fix: (helm-source-org-ql-views) Call helm-make-source directly
Avoids macro expansion issues if Helm is not yet loaded.

Fixes #60.  Thanks to @matthuszagh for reporting.
2019-11-29 21:08:22 -06:00
Adam Porter
d3a73732ac Notes: Tidy 2019-11-28 15:09:43 -06:00
Adam Porter
a1851ed0eb Fix: (--value-at) Clear value cache when buffer changes
Fixes #59.  Thanks to Daniel Hubmann (@hubisan) for reporting.
2019-11-24 05:43:21 -06:00
Adam Porter
02159a831a Notes: Add/update 2019-11-24 05:25:38 -06:00
Adam Porter
d3272cdd8b Add: (view--display) Insert newline at end of buffer
Prevents end-of-buffer from scrolling the window horizontally.

Fixes #50.  Thanks to @xeijin for suggesting.
2019-11-05 15:41:15 -06:00
Adam Porter
cb6509ca6a Notes: Add mailing list post by John Kitchin 2019-10-28 08:29:06 -05:00
Adam Porter
0d6523f85b Add: (heading) Alias "h" 2019-10-19 02:10:04 -05:00
Adam Porter
7d321630a0 Test: Add test for negated, plain quoted phrase
0.3.2 doesn't have negation, and this should be tested with negation.
2019-10-19 02:04:04 -05:00
Adam Porter
d5c26b7f60 Merge: 0.3.2 2019-10-19 02:01:13 -05:00
Adam Porter
2274efce07 Release: 0.3.2 2019-10-19 01:55:35 -05:00
Adam Porter
7a4a41e402 Fix: Quoted phrase plain-string queries 2019-10-19 01:55:33 -05:00
Adam Porter
43b94dd4a8 Fix: (org-ql-views) Beginning/end-of-week timestamp times 2019-10-19 01:08:44 -05:00
Adam Porter
f2910261e2 Fix: (org-ql-search) Accept symbol as arg to :super-groups 2019-10-19 01:08:42 -05:00
Adam Porter
be7ac9921d Meta: 0.3.2-pre 2019-10-19 01:00:45 -05:00
Adam Porter
949a06c3ab Add: Negation in plain queries 2019-10-09 19:05:11 -05:00
Adam Porter
6b2004e678 Change/Fix: (src) predicate
Use keyword args, fix non-sexp syntax and searching.
2019-10-09 17:21:47 -05:00
Adam Porter
af0ef304e1 Merge: 0.3.1 2019-10-09 15:17:54 -05:00
Adam Porter
8e6f221063 Fix: Require map
Thanks to Brian Leung (@leungbk).  See #49.
2019-10-09 14:45:24 -05:00
Adam Porter
37ba30c969 Add: src predicate 2019-10-09 14:23:29 -05:00
Adam Porter
a60c238417 Fix: (org-ql-search) Bind print-length in interactive form
The list of buffers/files must always be printed completely.
2019-10-08 21:02:18 -05:00
Adam Porter
e9e756331c Fix: (--outline-path) Always return a string
org-heading-components returns nil for a heading without heading text,
which causes string-match to signal an error.  So we'll match the
regexp ourselves and return an empty string in that case.  Should be
slightly faster, anyway.
2019-10-08 20:55:51 -05:00
Adam Porter
da9be83326 Add: helm-org-ql-views, helm-source-org-ql-views 2019-10-08 16:45:41 -05:00
Adam Porter
13723f8163 Change: (helm-org-ql) Disable highlighting
Doesn't work properly because input contains predicates and keywords
that shouldn't be highlighted.  Might try to fix it someday to only
use args to (regexp) and (heading).
2019-10-07 22:45:39 -05:00
Adam Porter
553c22c3ac Add: Adjust search parameters in view buffers 2019-10-07 22:44:56 -05:00
Adam Porter
7fa0d83a54 Add: helm-org-ql-source, org-ql-search-directories-files, etc. 2019-10-07 20:08:01 -05:00
Adam Porter
34cdbd5c87 Docs: Add info manual
Updating readme accordingly, based on org-super-agenda's, which is
based on Magit's and Org's.
2019-10-07 19:53:11 -05:00
Adam Porter
ad20029721 Notes: Update 2019-10-07 19:53:11 -05:00
Adam Porter
c06e5518eb Add: Predicates outline-path, outline-path-segment 2019-10-07 19:53:10 -05:00
Adam Porter
8d680a8e79 Add: node-value-cache, --value-at
Not used for anything in this comment, but will be in the outline-path
predicates.  Also should probably use it for the tags cache.
2019-10-07 19:52:02 -05:00
Adam Porter
7e11145bad Fix: (--defpred) Debug declaration
To work with preds with aliases.
2019-10-07 12:38:02 -05:00
Adam Porter
acf8e0e0fb Notes: Add idea 2019-10-07 11:16:08 -05:00
Adam Porter
51ab6401b2 Docs: (--def-plain-query-fn) Fix docstring 2019-10-07 10:12:20 -05:00
Adam Porter
2a5ec2e4fd Meta: 0.4-pre 2019-10-07 10:12:13 -05:00
57 changed files with 12797 additions and 4889 deletions

78
.github/ISSUE_TEMPLATE/bug_report.yml vendored Normal file
View file

@ -0,0 +1,78 @@
name: Bug Report
description: File a bug report
# labels: ["bug"]
# assignees:
# - alphapapa
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this bug report!
- type: input
id: os-platform
attributes:
label: OS/platform
description: What operating system or platform are you running Emacs on?
validations:
required: true
- type: textarea
id: emacs-provenance
attributes:
label: Emacs version and provenance
description: What version of Emacs are you using, where did you acquire it, and how did you install it?
validations:
required: true
- type: input
id: emacs-command
attributes:
label: Emacs command
description: By what method did you run Emacs? (i.e. what command did you run?)
validations:
required: true
- type: textarea
id: org-provenance
attributes:
label: Org version and provenance
description: What version of Org are you using, where did you acquire it, and how did you install it?
validations:
required: true
- type: input
id: package-provenance
attributes:
label: org-ql package version and provenance
description: What version of org-ql are you using, where did you acquire it, and how did you install it?
validations:
required: true
- type: textarea
id: actions
attributes:
label: Actions taken
description: What actions did you take, step-by-step, in order, before the problem was noticed?
validations:
required: true
- type: textarea
id: results
attributes:
label: Observed results
description: What behavior did you observe that seemed wrong?
validations:
required: true
- type: textarea
id: expected
attributes:
label: Expected results
description: What behavior did you expect to observe?
validations:
required: true
- type: textarea
id: backtrace
attributes:
label: Backtrace
description: If an error was signaled, please use `M-x toggle-debug-on-error RET` and cause the error to happen again, then paste the contents of the `*Backtrace*` buffer here.
render: elisp
- type: textarea
id: etc
attributes:
label: Etc.
description: Any other information that seems relevant

5
.github/ISSUE_TEMPLATE/config.yml vendored Normal file
View file

@ -0,0 +1,5 @@
blank_issues_enabled: true
contact_links:
- name: Support questions
url: https://github.com/alphapapa/org-ql/discussions
about: Please ask and answer support questions here.

View file

@ -0,0 +1,45 @@
name: Feature Request
description: File a feature request
labels: ["enhancement"]
body:
- type: input
id: os-platform
attributes:
label: OS/platform
description: What operating system or platform are you running Emacs on?
validations:
required: true
- type: textarea
id: emacs-provenance
attributes:
label: Emacs version and provenance
description: What version of Emacs are you using, where did you acquire it, and how did you install it?
validations:
required: true
- type: textarea
id: org-provenance
attributes:
label: Org version and provenance
description: What version of Org are you using, where did you acquire it, and how did you install it?
validations:
required: true
- type: input
id: package-provenance
attributes:
label: org-ql package version and provenance
description: What version of org-ql are you using, where did you acquire it, and how did you install it?
validations:
required: true
- type: textarea
id: description
attributes:
label: Description
description: Describe your request.
validations:
required: true
- type: textarea
id: etc
attributes:
label: Etc.
description: Any other information that seems relevant

81
.github/workflows/test.yml vendored Normal file
View file

@ -0,0 +1,81 @@
# * test.yml --- Test Emacs packages using makem.sh on GitHub Actions
# URL: https://github.com/alphapapa/makem.sh
# Version: 0.3
# * Commentary:
# Based on Steve Purcell's examples at
# <https://github.com/purcell/setup-emacs/blob/master/.github/workflows/test.yml>,
# <https://github.com/purcell/package-lint/blob/master/.github/workflows/test.yml>.
# * License:
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# * Code:
name: "CI"
on:
pull_request:
push:
# Comment out this section to enable testing of all branches.
# branches:
# - master
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
emacs_version:
- 27.1
- 27.2
- 28.1
- 28.2
- 29.1
- 29.2
- 29.3
- 29.4
- snapshot
steps:
- uses: purcell/setup-emacs@master
with:
version: ${{ matrix.emacs_version }}
- uses: actions/checkout@v2
- name: Initialize sandbox
run: |
SANDBOX_DIR=$(mktemp -d) || exit 1
echo "SANDBOX_DIR=$SANDBOX_DIR" >> $GITHUB_ENV
./makem.sh -vv --sandbox=$SANDBOX_DIR --install-deps --install-linters
# The "all" rule is not used, because it treats compilation warnings
# as failures, so linting and testing are run as separate steps.
- name: Lint
# NOTE: Uncomment this line to treat lint failures as passing
# so the job doesn't show failure.
continue-on-error: true
run: ./makem.sh -vv --sandbox=$SANDBOX_DIR lint
- name: Test
if: always() # Run test even if linting fails.
run: ./makem.sh -vv --sandbox=$SANDBOX_DIR test
# Local Variables:
# eval: (outline-minor-mode)
# End:

7
.gitignore vendored
View file

@ -2,3 +2,10 @@
.#* .#*
/scratch.el /scratch.el
.cask .cask
/sandbox/
/.sandbox/
/scratch.org
/scratch/
/worktrees/
/worktree/
/NOTES.org

10
Cask
View file

@ -1,10 +0,0 @@
(package-file "org-ql.el")
(files "org-ql.el" "org-ql-agenda.el")
(source gnu)
(source melpa)
(development
(depends-on "buttercup")
(depends-on "xr"))

View file

@ -1,11 +1,46 @@
# * Verbosity # * makem.sh/Makefile --- Script to aid building and testing Emacs Lisp packages
# URL: https://github.com/alphapapa/makem.sh
# Version: 0.5
# * Arguments
# For consistency, we use only var=val options, not hyphen-prefixed options.
# NOTE: I don't like duplicating the arguments here and in makem.sh,
# but I haven't been able to find a way to pass arguments which
# conflict with Make's own arguments through Make to the script.
# Using -- doesn't seem to do it.
ifdef install-deps
INSTALL_DEPS = "--install-deps"
endif
ifdef install-linters
INSTALL_LINTERS = "--install-linters"
endif
ifdef sandbox
ifeq ($(sandbox), t)
SANDBOX = --sandbox
else
SANDBOX = --sandbox=$(sandbox)
endif
endif
ifdef debug
DEBUG = "--debug"
endif
# ** Verbosity
# Since the "-v" in "make -v" gets intercepted by Make itself, we have # Since the "-v" in "make -v" gets intercepted by Make itself, we have
# to use a variable. # to use a variable.
verbose = $(v) verbose = $(v)
ifneq (,$(findstring vv,$(verbose))) ifneq (,$(findstring vvv,$(verbose)))
VERBOSE = "-vvv"
else ifneq (,$(findstring vv,$(verbose)))
VERBOSE = "-vv" VERBOSE = "-vv"
else ifneq (,$(findstring v,$(verbose))) else ifneq (,$(findstring v,$(verbose)))
VERBOSE = "-v" VERBOSE = "-v"
@ -13,5 +48,12 @@ endif
# * Rules # * Rules
# TODO: Handle cases in which "test" or "tests" are called and a
# directory by that name exists, which can confuse Make.
%: %:
@./makem.sh $(VERBOSE) $(@) @./makem.sh $(DEBUG) $(VERBOSE) $(SANDBOX) $(INSTALL_DEPS) $(INSTALL_LINTERS) $(@)
.DEFAULT: init
init:
@./makem.sh $(DEBUG) $(VERBOSE) $(SANDBOX) $(INSTALL_DEPS) $(INSTALL_LINTERS)

1
NOTES Normal file
View file

@ -0,0 +1 @@
Note: Notes are kept in the file "NOTES.org" in the "meta/notes" branch.

View file

@ -1,33 +1,33 @@
#+TITLE: org-ql #+TITLE: org-ql
#+BEGIN_HTML # NOTE: Using =BEGIN_HTML= for this causes TeX/info export to fail, but this HTML block works.
<a href=https://alphapapa.github.io/dont-tread-on-emacs/><img src="images/dont-tread-on-emacs-150.png" align="right"></a> #+HTML: <img src="images/dog.png" align="right">
#+END_HTML
[[https://melpa.org/#/org-ql][file:https://melpa.org/packages/org-ql-badge.svg]] [[https://stable.melpa.org/#/org-ql][file:https://stable.melpa.org/packages/org-ql-badge.svg]] # NOTE: To avoid having this in the info manual, we use HTML rather than Org syntax; it still appears with the GitHub renderer.
#+HTML: <a href="https://melpa.org/#/org-ql"><img src="https://melpa.org/packages/org-ql-badge.svg"></a> <a href="https://stable.melpa.org/#/org-ql"><img src="https://stable.melpa.org/packages/org-ql-badge.svg"></a>
This package provides a query language for Org files. It offers two syntax styles: Lisp-like sexps and search engine-like keywords. 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= provide interactive search commands and saved views. 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.
* Contents * Contents
:PROPERTIES: :PROPERTIES:
:TOC: this :TOC: :include siblings :depth 0 :ignore this :force depth
:END: :END:
- [[#screenshots][Screenshots]] :CONTENTS:
- [[#installation][Installation]] - [[#screenshots][Screenshots]]
- [[#usage][Usage]] - [[#installation][Installation]]
- [[#commands][Commands]] - [[#usage][Usage]]
- [[#queries][Queries]] - [[#changelog][Changelog]]
- [[#functions--macros][Functions / Macros]] - [[#development][Development]]
- [[#changelog][Changelog]] :END:
- [[#notes][Notes]]
* Screenshots * Screenshots
[[images/org-ql-search.gif]] [[images/org-ql-search.gif]]
[[images/org-ql-search-snippet.png]] [[images/org-ql-view-dispatch.gif]]
[[images/helm-org-ql.gif]] [[images/helm-org-ql.gif]]
@ -38,11 +38,9 @@ It includes three libraries: The =org-ql= library is flexible and may be used as
:TOC: ignore-children :TOC: ignore-children
:END: :END:
The package may be installed directly from [[https://melpa.org/#/org-ql][MELPA]] or with other tools like [[https://framagit.org/steckerhalter/quelpa][Quelpa]]. The package =org-ql= may be installed directly from [[https://melpa.org/#/org-ql][MELPA]] or with other tools like [[https://framagit.org/steckerhalter/quelpa][Quelpa]].
After installation, you can use the commands without additional configuration. /Note: The command =helm-org-ql= only works if the package =helm-org= is installed; Helm is not a dependency of this package, so it's not automatically installed./ 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=.
To use the functions and macros in your own Elisp code, use libraries =org-ql= and =org-ql-view=.
** Quelpa ** Quelpa
@ -53,29 +51,42 @@ Installing with [[https://framagit.org/steckerhalter/quelpa][Quelpa]] is easy:
#+BEGIN_SRC elisp #+BEGIN_SRC elisp
(use-package org-ql (use-package org-ql
:quelpa (org-ql :fetcher github :repo "alphapapa/org-ql")) :quelpa (org-ql :fetcher github :repo "alphapapa/org-ql"
:files (:defaults (:exclude "helm-org-ql.el"))))
#+END_SRC
** 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:
#+BEGIN_SRC elisp
(use-package helm-org-ql
:quelpa (helm-org-ql :fetcher github :repo "alphapapa/org-ql"
:files ("helm-org-ql.el")))
#+END_SRC #+END_SRC
* Usage * Usage
:PROPERTIES:
:TOC: :include descendants :depth 1
:END:
:CONTENTS:
- [[#commands][Commands]]
- [[#queries][Queries]]
- [[#non-sexp-query-syntax][Non-sexp query syntax]]
- [[#general-predicates][General predicates]]
- [[#ancestordescendant-predicates][Ancestor/descendant predicates]]
- [[#datetime-predicates][Date/time predicates]]
- [[#functions--macros][Functions / Macros]]
- [[#dynamic-block][Dynamic block]]
- [[#links][Links]]
- [[#tips][Tips]]
:END:
These commands and functions are included: # These links work on GitHub's Org renderer but not in Org.
+ *Showing an agenda-like view:*
- ~org-ql-search~ (command)
- ~org-ql-view~ (command)
- =org-ql-view-sidebar= (command)
- ~org-ql-block~ (agenda block function)
+ *Showing a tree in a buffer:*
- =org-ql-sparse-tree= (command)
+ *Showing results with Helm*:
- =helm-org-ql= (command)
+ *Returning a list of matches or acting on them:*
- ~org-ql~ (macro)
- ~org-ql-select~ (function)
- ~org-ql-query~ (function)
Feedback on these APIs is welcome. Eventually, after being tested and polished, they will be considered stable. Feedback on these APIs is welcome. Eventually, after being tested and polished, they will be considered stable.
# TODO: Find a way to get these examples included in the info manual.
Lisp code examples are in [[examples.org]]. Lisp code examples are in [[examples.org]].
** Commands ** Commands
@ -83,6 +94,42 @@ Lisp code examples are in [[examples.org]].
:TOC: ignore-children :TOC: ignore-children
:END: :END:
+ *Jumping to an entry:*
- [[#org-ql-find][org-ql-find]] and related commands
- [[#helm-org-ql][helm-org-ql]]
+ *Showing an agenda-like view:*
- [[#org-ql-search][org-ql-search]]
- [[#org-ql-view][org-ql-view]]
- [[#org-ql-view-sidebar][org-ql-view-sidebar]]
- [[#org-ql-view-recent-items][org-ql-view-recent-items]]
+ *Showing a tree in a buffer:*
- [[#org-ql-sparse-tree][org-ql-sparse-tree]]
*** org-ql-find
/Note: These commands use [[#non-sexp-query-syntax][non-sexp queries]]./
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 [[https://github.com/oantolin/embark][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.
[[images/org-ql-find.png]]
*** 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.
*** 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.
*** org-ql-search *** org-ql-search
/Note: This command supports both sexp queries and [[#non-sexp-query-syntax][non-sexp queries]]./ /Note: This command supports both sexp queries and [[#non-sexp-query-syntax][non-sexp queries]]./
@ -94,7 +141,6 @@ Read ~QUERY~ and search with ~org-ql~. Interactively, prompt for these variable
+ ~buffer~: search the current buffer + ~buffer~: search the current buffer
+ ~all~: search all Org buffers + ~all~: search all Org buffers
+ ~agenda~: search buffers returned by the function ~org-agenda-files~ + ~agenda~: search buffers returned by the function ~org-agenda-files~
+ An expression which evaluates to a list of files/buffers
+ A space-separated list of file or buffer names + A space-separated list of file or buffer names
~GROUPS~: An ~org-super-agenda~ group set. See variable ~org-super-agenda-groups~. ~GROUPS~: An ~org-super-agenda~ group set. See variable ~org-super-agenda-groups~.
@ -104,16 +150,19 @@ Read ~QUERY~ and search with ~org-ql~. Interactively, prompt for these variable
~SORT~: One or a list of ~org-ql~ sorting functions, like ~date~ or ~priority~. ~SORT~: One or a list of ~org-ql~ sorting functions, like ~date~ or ~priority~.
*Bindings:* Keys bound in results buffer. *Bindings:* Keys bound in results buffer.
+ =g=: Refresh results. + =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~). + =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:* 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 [[https://github.com/oantolin/embark][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.
*** helm-org-ql *** helm-org-ql
/Note: This command uses [[#non-sexp-query-syntax][non-sexp queries]]./ /Note: This command uses [[#non-sexp-query-syntax][non-sexp queries]]. It is available separately in the package =helm-org-ql=./
This command displays matches with Helm. *Note:* Helm is not a package dependency, so this command only works if the package =helm-org= is installed. 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. + Press =C-x C-s= in the Helm session to save the results to an =org-ql-search= buffer.
@ -121,6 +170,11 @@ This command displays matches with Helm. *Note:* Helm is not a package dependen
Choose and display a view stored in ~org-ql-views~. 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~).
*** org-ql-view-sidebar *** 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. 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.
@ -129,100 +183,142 @@ Show a sidebar window listing views stored in =org-ql-views= for easy access. I
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=. 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=.
*** org-ql-sparse-tree =(query &key keep-previous (buffer (current-buffer)))= *** 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. 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. ~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.
** Queries ** Queries
:PROPERTIES:
:TOC: :include descendants :depth 1
:END:
:CONTENTS:
- [[#non-sexp-query-syntax][Non-sexp query syntax]]
- [[#general-predicates][General predicates]]
- [[#ancestordescendant-predicates][Ancestor/descendant predicates]]
- [[#datetime-predicates][Date/time predicates]]
:END:
An =org-ql= query is a lisp form which may contain arbitrary lisp forms, as well as 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. 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:* *Notes:*
+ Bare strings like ~"string"~ are automatically converted to ~(regexp "string")~ predicates. + 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. + 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.
*** Non-sexp query syntax *** Non-sexp query syntax
:PROPERTIES:
:TOC: ignore
:END:
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=. 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 | | Sexp syntax | Non-sexp syntax |
|-------------------------------------------------+-----------------------------------------| |-------------------------------------------------+----------------------------------------------|
| ~(todo)~ | ~todo:~ | | ~(todo)~ | ~todo:~ |
| ~(todo "SOMEDAY")~ | ~todo:SOMEDAY~ | | ~(todo "SOMEDAY")~ | ~todo:SOMEDAY~ |
| ~(todo "SOMEDAY" "WAITING")~ | ~todo:SOMEDAY,WAITING~ | | ~(todo "SOMEDAY" "WAITING")~ | ~todo:SOMEDAY,WAITING~ |
| ~(ts :on today)~ | ~ts:on=today~ | | ~(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~ | | ~(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~ | | ~(clocked :on -1)~ | ~clocked:on=-1~ |
| ~(heading "quoted phrase" "word")~ | ~heading:"quoted phrase",word~ | | ~(heading "quoted phrase" "word")~ | ~heading:"quoted phrase",word~ |
| ~(and (tags "book" "books") (priority "A"))~ | ~tags:book,books priority:A~ | | ~(and (tags "book" "books") (priority "A"))~ | ~tags:book,books priority:A~ |
| ~(priority >= B)~ | ~priority:A,B~ | | ~(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 =priority= predicate does not support comparators in the non-sexp syntax, so multiple priorities should be passed instead, as seen in the last example. 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.
*** Predicates *** General predicates
:PROPERTIES:
:TOC: ignore
:END:
Arguments are listed next to predicate names, where applicable. Arguments are listed next to predicate names, where applicable.
+ ~category (&optional categories)~ :: Return non-nil if current heading is in one or more of ~CATEGORIES~ (a list of strings). + =blocked= :: Return non-nil if current heading is blocked. Calls ~org-entry-blocked-p~, which see.
+ ~children (&optional query)~ :: Return non-nil if current heading has direct child headings. If ~QUERY~, test it against child headings. This selector may be nested, e.g. to match grandchild headings. + =category (&rest categories)= :: Return non-nil if current heading is in one or more of ~CATEGORIES~ (a list of strings).
+ ~descendants (&optional query)~ :: Return non-nil if current heading has descendant headings. If ~QUERY~, test it against descendant headings. This selector may be nested (if you can grok the nesting!). + =done= :: Return non-nil if entry's ~TODO~ keyword is in ~org-done-keywords~.
+ ~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. + =habit= :: Return non-nil if entry is a habit.
+ ~heading (&rest regexps)~ :: Return non-nil if current entry's heading matches all ~REGEXPS~ (regexp strings). + =heading (&rest strings)= :: Return non-nil if current entry's heading matches all ~STRINGS~. Matching is done case-insensitively.
+ ~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 ~>=~. - Aliases: =h=.
+ =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. + ~heading-regexp (&rest regexps)~ :: Return non-nil if current entry's heading matches all ~REGEXPS~ (regexp strings). Matching is done case-insensitively.
+ ~priority (&optional comparator-or-priority priority)~ :: Return non-nil if current heading has a certain priority. ~COMPARATOR-OR-PRIORITY~ should be either a comparator function, like ~<=~, or a priority string, like "A" (in which case (~=~ will be the comparator). If ~COMPARATOR-OR-PRIORITY~ is a comparator, ~PRIORITY~ should be a priority string. If both arguments are nil, return non-nil if heading has any defined priority. - Aliases: ~h*~.
+ ~property (property &optional value)~ :: Return non-nil if current entry has ~PROPERTY~ (a string), and optionally ~VALUE~ (a string). Note that property inheritance is currently /not/ enabled for this predicate. If you need to test with inheritance, you could use a custom predicate form, like ~(org-entry-get (point) "PROPERTY" 'inherit)~. + =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 ~>=~.
+ ~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. + =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.
+ ~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. + =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")~.
+ =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: ~olp~.
- Aliases: =inherited-tags=, =tags-i=, =itags=. + =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")~.
+ =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: ~olps~.
- Aliases: =local-tags=, =tags-l=, =ltags=. + =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.
+ =tags-all (tags)= :: Return non-nil if current heading includes all of =TAGS=. Tests both inherited and local tags. + =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~).
- Aliases: =tags&=. + =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.
+ ~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~). + =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 (&rest 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 (&rest 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 (&rest 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 (&rest 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 (&rest 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~).
*** 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.
*** Date/time predicates *** Date/time predicates
:PROPERTIES:
:TOC: ignore
:END:
All of these predicates take optional keyword arguments ~:from~, ~:to:~, and ~:on~: These predicates take optional keyword arguments:
+ If ~:from~, return non-nil if entry has a timestamp on or after ~:from~. + ~:from~: Match entries whose timestamp is on or after timestamp ~:from~.
+ If ~:to~, return non-nil if entry has a timestamp on or before ~:to~. + ~:to~: Match entries whose timestamp is on or before timestamp ~:to~.
+ If ~:on~, return non-nil if entry has a timestamp on date ~:on~. + ~: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.
Argument values should be either a number of days (positive to look forward, or negative to look backward), a ~ts~ struct, or a string parseable by ~parse-time-string~ (the string may omit the time value). 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:* + *Predicates*
+ ~ts~ :: Return non-nil if current entry has a timestamp in given period. If no arguments are specified, return non-nil if entry has any timestamp. - =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-active=, =ts-a= :: Like =ts=, but only matches active timestamps.
+ ~ts-inactive~, ~ts-i~ :: Like ~ts~, but only matches inactive 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. 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.
*Backward-looking:* 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:
+ ~clocked~ :: Return non-nil if current entry was clocked in given period. If no arguments are specified, return non-nil if entry was clocked at any time. 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. If no arguments are specified, return non-nil if entry was closed at any time.
*Forward-looking:* + *Backward-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=. If no arguments are specified, return non-nil if entry has any deadline. - =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.
+ ~planning~ :: Return non-nil if current entry has planning timestamp in given period (i.e. its deadline, scheduled, or closed timestamp). If no arguments are specified, return non-nil if entry is scheduled at any time. - =closed= :: Return non-nil if current entry was closed in given period. Without arguments, return non-nil if entry is closed.
+ ~scheduled~ :: Return non-nil if current entry is scheduled in given period. If no arguments are specified, return non-nil if entry is scheduled at any time.
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.
** Functions / Macros ** Functions / Macros
:PROPERTIES: :PROPERTIES:
:TOC: ignore-children :TOC: :include descendants
:END:
:CONTENTS:
- [[#agenda-like-views][Agenda-like views]]
- [[#function-org-ql-block][Function: org-ql-block]]
- [[#listing--acting-on-results][Listing / acting-on results]]
- [[#caching][Caching]]
- [[#function-org-ql-select][Function: org-ql-select]]
- [[#function-org-ql-query][Function: org-ql-query]]
- [[#macro-org-ql-deprecated][Macro: org-ql (deprecated)]]
- [[#custom-predicates][Custom predicates]]
- [[#macro-org-ql-defpred][Macro: org-ql-defpred]]
:END: :END:
*** Agenda-like views *** Agenda-like views
@ -256,6 +352,12 @@ The variable =org-ql-block-header= may be bound to a string to use as the block
*** Listing / acting-on results *** Listing / acting-on results
**** 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./
**** Function: ~org-ql-select~ **** Function: ~org-ql-select~
/Arguments:/ ~(buffers-or-files query &key action narrow sort)~ /Arguments:/ ~(buffers-or-files query &key action narrow sort)~
@ -278,7 +380,7 @@ Return items matching ~QUERY~ in ~BUFFERS-OR-FILES~.
If ~NARROW~ is non-nil, buffers are not widened (the default is to widen and search the entire buffer). 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~, ~todo~, ~priority~, or ~random~); or a user-defined comparator function that accepts two items as arguments and returns nil or non-nil. ~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: Examples:
@ -350,12 +452,101 @@ Examples:
;; => ((headline (:raw-value "Visit the moon" ...) ...) ...) ;; => ((headline (:raw-value "Visit the moon" ...) ...) ...)
#+END_SRC #+END_SRC
**** Macro: ~org-ql~ **** Macro: ~org-ql~ (deprecated)
/Arguments:/ ~(buffers-or-files query &key sort narrow markers action)~ /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. 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./
*** Custom predicates
+ See: [[file:examples/defpred.org][Custom predicate tutorial]]
**** 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)))~
** 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:
# NOTE: These results are edited manually because the Org links don't display well in the Info manual.
#+BEGIN_SRC org
,#+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 |
| TODO | A | | | Skype with president of Antarctica |
| TODO | B | | | Take over Mars |
,#+END:
#+END_SRC
** Links
Org QL View searches may be accessed by opening ~org-ql-search:~ links in an Org file.
In an Org QL View buffer, the command ~org-store-link~ (i.e. ~C-c l~) stores a link to the current search, and it may be inserted into an Org buffer with the command ~org-insert-link~ (~C-c C-l~). The stored link records all of the view settings, like title, sorting, and grouping.
Simple links may also be written manually in either sexp or non-sexp form, like:
#+BEGIN_SRC org
[[org-ql-search:todo:NEXT priority:A]]
[[org-ql-search:(and (todo "NEXT") (priority "A"))]]
#+END_SRC
** Tips
+ Org QL View buffers can be bookmarked with Emacs bookmark commands, e.g. =C-x r m=. This also integrates with [[https://github.com/alphapapa/org-sidebar][org-sidebar]] and [[https://github.com/alphapapa/burly.el][Burly]].
* Changelog * Changelog
:PROPERTIES: :PROPERTIES:
:TOC: ignore-children :TOC: ignore-children
@ -363,6 +554,348 @@ Expands into a call to ~org-ql-select~ with the same arguments. For convenience
/Note:/ Breaking changes may be made before version 1.0, but in the event of major changes, attempts at backward compatibility will be made with obsolescence declarations, translation of arguments, etc. Users who need stability guarantees before 1.0 may choose to use tagged stable releases. /Note:/ Breaking changes may be made before version 1.0, but in the event of major changes, attempts at backward compatibility will be made with obsolescence declarations, translation of arguments, etc. Users who need stability guarantees before 1.0 may choose to use tagged stable releases.
** 0.9-pre
*Additions*
+ Face ~org-ql-view-query~, applied to view queries in header line.
+ Face ~org-ql-view-title~, applied to view titles in header line.
+ Option ~org-ql-view-relative-deadline-prefix~.
*Changes*
+ Command ~org-ql-find~ respects narrowing of the current buffer by default, allowing searching within the narrowed region. (Using one ~C-u~ argument widens the current buffer, and using two ~C-u~ arguments prompts for the buffers to search.)
+ Function ~org-ql-completing-read~ accepts a new ~NARROWP~ argument, which is passed to ~org-ql-select~.
*Fixes*
+ Customization group for face ~org-ql-view-due-date~.
+ Apply Org syntax font-locking to items in ~org-ql-view~ buffers.
*** helm-org-ql
Tagged v0.6.2, fixing a compilation warning.
** 0.8.10
*Fixes*
+ Command ~org-ql-refile~ uses the base buffer when refiling to an indirect buffer. ([[https://github.com/alphapapa/org-ql/issues/466][#466]].)
+ Predicate ~link~ could signal an error when searching text that is mistakenly recognized as an Org link (e.g. Bash double-bracket constructs in a source block). (Thanks to [[https://github.com/jwiegley][John Wiegley]] for reporting.)
** 0.8.9
*Fixes*
+ Predicate ~property~ when called with argument form ~(property "PROPERTY-NAME" :inherit t)~. ([[https://github.com/alphapapa/org-ql/issues/460][#460]]. Thanks to [[https://github.com/Stewmath][Stewmath]] for reporting.)
+ Predicate ~level~'s preamble optimizer allows expressions in place of the numeric argument. (See [[https://github.com/alphapapa/org-ql/issues/460][#460]]. Thanks to [[https://github.com/Stewmath][Stewmath]] for reporting.)
+ Reading of view settings from Org links in upcoming Emacs version. ([[https://github.com/alphapapa/org-ql/issues/461][#461]]. Thanks to [[https://github.com/snogge][Ola Nilsson]] for help debugging, and for maintaining [[https://github.com/jorgenschaefer/emacs-buttercup][Buttercup]].)
*Compatibility*
+ Fix compilation error on Emacs 30. ([[https://github.com/alphapapa/org-ql/issues/433][#433]]. Thanks to [[https://github.com/akirak][Akira Komamura]] and [[https://github.com/monnier][Stefan Monnier]].)
** 0.8.8
*Fixes*
+ Remove text properties from to-do keywords before displaying them in an ~org-ql-view~ buffer. (Such text properties could cause them to, e.g. display with extra leading spaces, depending on which other modes might be enabled in the source Org buffer.)
+ Binding of ~completion-styles-alist~ in ~org-ql-completing-read~. (This fixes compatibility with Helm's ~helm~ completion style, as well as default Emacs completion in recursive minibuffers. [[https://github.com/alphapapa/org-ql/issues/337][#337]]. Thanks to [[https://github.com/progfolio][Nicholas Vollmer]], [[https://github.com/9viz][viz]], and [[https://github.com/karthink][Karthik Chikmagalur]] for reporting and suggesting fixes.)
+ Use of the context snippet function for ~org-ql-completing-read~. ([[https://github.com/alphapapa/org-ql/issues/419][#419]]. Thanks to [[https://github.com/tpeacock19][tpeacock19]] for reporting.)
** 0.8.7
*Fixes*
+ Timestamps with internal time ranges (e.g. ~<2024-06-26 10:00-11:00>~) are matched for simple queries. (This support is not yet comprehensive, e.g. a query that depends on the specific inner time range may not behave as expected. Previously such timestamps were not matched at all. See [[https://github.com/alphapapa/org-ql/pull/237][#237]] and [[https://github.com/alphapapa/org-ql/issues/371][#371]]. Thanks to [[https://github.com/yantar92][Ihor Radchenko]].)
+ Timestamps with day-of-the-week abbreviations are matched more flexibly (allowing, e.g. a period in French locales). (See [[https://github.com/alphapapa/org-ql/discussions/429][#429]], [[https://github.com/alphapapa/org-ql/issues/432][#432]]. Thanks to [[https://github.com/neurolit][Florian D.]] for reporting.)
+ Command ~org-ql-search~ did not narrow properly when called interactively.
*Compatibility*
+ Dynamic blocks work with Org 9.7. ([[https://github.com/alphapapa/org-ql/issues/431][#431]]. Thanks to [[https://github.com/jezcope][Jez Cope]] for reporting.)
** 0.8.6
*Fixes*
+ Bookmarking ~org-ql-view~ buffers when the ~buffers-files~ argument is a symbol (like ~org-agenda-files~).
** 0.8.5
*Fixes*
+ Predicate ~heading~ incorrectly matched strings as regular expressions, sometimes returning incorrect results. (See [[https://github.com/alphapapa/org-ql/discussions/410][discussion]]. Thanks to [[https://github.com/al3xandru][Alex Popescu]] for reporting.)
+ Predicates ~ancestor~ and ~parent~ did not normalize their sub-queries, sometimes returning incorrect results. ([[https://github.com/alphapapa/org-ql/issues/365][#365]]. Thanks to [[https://github.com/kofm][Gabriele Mongiano]] for reporting.)
** 0.8.4
*Fixes*
+ Command ~org-ql-find~ goes to the selected entry in the base buffer (rather than potentially an indirect buffer, whose narrowing could leave the selected entry hidden. The nuances around going to entries in buffers that may be indirect and/or narrowed are surprisingly complicated. Hopefully this is the last fix).
** 0.8.3
*Fixes*
+ Command ~org-ql-find~ incorrectly moved point. (See [[https://github.com/alphapapa/org-ql/issues/380#issuecomment-1881913025][#380]]. Thanks to [[https://github.com/oantolin][Omar Antolín Camarena]] for reporting.)
** 0.8.2
*Fixes*
+ Command ~org-ql-find~ incorrectly restored the buffer after jumping when not using indirect buffers. (See [[https://github.com/alphapapa/org-ql/issues/380#issuecomment-1881913025][#380]]. Thanks to [[https://github.com/bram85][Bram Schoenmakers]] for reporting.)
** 0.8.1
*Fixes*
+ Command ~org-ql-find~ widens the buffer before going to the selected entry.
+ In ~org-ql-view~ buffers, links in headings remain clickable links. (Fixes [[https://github.com/alphapapa/org-ql/issues/282][#282]]. Thanks to [[https://github.com/jakebox][Jacob Boxerman]] for reporting.)
** 0.8
*Additions*
+ Function ~org-ql-completing-read~, used by command ~org-ql-find~, now specifies the completion category as ~org-heading~, providing compatibility with [[https://github.com/oantolin/embark][Embark]]. (This is a powerful feature, as it means any ~org-ql-find~ result can be acted on from inside the search results with Embark, which provides common actions from Org Agenda and Org speed keys bindings.) ([[https://github.com/alphapapa/org-ql/issues/299][#299]]. Thanks to [[https://github.com/oantolin][Omar Antolín Camarena]], [[https://github.com/minad][Daniel Mendler]], and [[https://github.com/akirak][Akira Komamura]].)
- Command ~org-ql-completing-read-export~, bound to ~C-c C-e~ or ~embark-export~ while in an ~org-ql-completing-read~ session, exits and shows an ~org-ql-view~ buffer for the current search.
+ Command ~org-ql-find~ may be called in an ~org-agenda~ or ~org-ql-view~ buffer to search the buffers which contributed to the agenda/view buffer.
+ Command ~org-ql-find-path~, which searches outline paths in the current buffer.
+ Command ~org-ql-open-link~, which finds links in entries matching the given query, and opens the selected one with ~org-open-at-point~. (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.)
+ Items in ~org-ql-view~ buffers now include the ~org-category~ text property, like Org Agenda buffers, which allows grouping with ~org-super-agenda~'s category-related selectors. ([[https://github.com/alphapapa/org-ql/issues/363][#363]]. Thanks to [[https://github.com/kofm][Gabriele Mongiano]] for reporting.)
*Fixes*
+ Predicate ~property~ correctly uses the value of ~org-use-property-inheritance~ when not specified. ([[https://github.com/alphapapa/org-ql/pull/346][#346]], [[https://github.com/alphapapa/org-ql/issues/356][#356]]. Thanks to [[https://github.com/bram85][Bram Schoenmakers]].)
*Compatibility*
+ Emacs 27.1 or later is now required.
+ Org v9.7's ~org-element~ API changes required some adjustments. ([[https://github.com/alphapapa/org-ql/issues/364][#364]]. Thanks to several users for reporting, and to [[https://github.com/yantar92][Ihor Radchenko]] for his feedback.)
** 0.7.4
*Fixes*
+ Ignore empty quoted strings in plain-string queries ([[https://github.com/alphapapa/org-ql/issues/383][#383]]).
** 0.7.3
*Fixes*
+ Disable ~case-fold-search~ when collecting headings in outline paths. (Headings that started with a word that is also a to-do keyword but with different capitalization would be matched incorrectly.)
+ Saving of ~org-ql-view~ views. ([[https://github.com/alphapapa/org-ql/issues/378][#378]]. Thanks to [[https://github.com/Pentaquark1][Pentaquark1]] for reporting.)
+ Command ~org-ql-find~ didn't move point to the selected entry. ([[https://github.com/alphapapa/org-ql/issues/380][#380]]. Thanks to [[https://github.com/oantolin][Omar Antolín Camarena]] for reporting.)
** 0.7.2
*Fixes*
+ Timestamp predicates are more tolerant of partial input (e.g. preventing errors while the user is typing a query into ~org-ql-find~).
+ Query parser ignores leading whitespace (e.g. preventing errors while the user is typing a query into ~org-ql-find~).
+ Use of ~org-ql-find~ with ~:query-prefix~ argument prevented selection of results. ([[https://github.com/alphapapa/org-ql/issues/351][#351]]. Thanks to [[https://github.com/danielfleischer][Daniel Fleischer]] for reporting.)
+ Handle narrowed buffers correctly in ~org-ql-find~.
+ Warn about empty headings in ~org-ql-completing-read~ (the Org format allows a heading line to have no text, but it's useless for this purpose, and usually indicates unnoticed corruption).
** 0.7.1
*Fixes*
+ Function ~org-ql-completing-read~ is more compatible with default Emacs completion. (See [[https://github.com/alphapapa/org-ql/issues/338][#338]]. Thanks to [[https://github.com/arozbiz][arozbiz]] for reporting.)
+ Function ~org-ql-completing-read~ would sometimes stop updating with changes in input. (See [[https://github.com/alphapapa/org-ql/issues/350][#350]]. Thanks to [[https://github.com/anpandey][Ankit Raj Pandey]] for reporting and fixing, and to [[https://github.com/minad][Daniel Mendler]] for advising.)
+ In ~org-ql-completing-read~, format links for display, and use ~org-entry-get~ internally rather than ~org-get-heading~.
** 0.7
*Added*
+ Command ~org-ql-find~, which jumps to entries selected using Emacs's built-in completion facilities and Org QL queries (like ~helm-org-ql~, but doesn't require Helm.).
+ Command ~org-ql-refile~, which refiles the entry at point to one selected using Org QL completion.
+ Predicate ~rifle~, which matches an entry if each of the given arguments is found in either the entry's contents or its outline path. This provides very intuitive results, mimicing the behavior of [[https://github.com/alphapapa/org-rifle][=org-rifle=]]. In fact, the results are so useful that it's now the default predicate for plain-string query tokens. (It is also aliased to ~smart~, since it's so "smart," and not all users have used =org-rifle=.)
+ Option ~org-ql-default-predicate~, applied to plain-string query tokens (before, the ~regexp~ predicate was always used, but now it may be customized).
+ Alias ~c~ for predicate ~category~.
+ Predicate ~property~ now accepts the argument ~:inherit~ to match entries with property inheritance, and when unspecified, the option ~org-use-property-inheritance~ controls whether inheritance is used.
+ Predicate ~blocked~. (Thanks to [[https://github.com/akirak][Akira Komamura]].)
*Changed*
+ Give more useful error message for invalid queries.
+ Predicate ~src~ now matches case-insensitively.
+ Command ~org-ql-sparse-tree~ accepts both string and sexp queries. (Thanks to [[https://github.com/akirak][Akira Komamura]].)
*Fixed*
+ Predicate ~link~ matches links whose descriptions contain escaped brackets (changed in Org 9.3). (Thanks to [[https://github.com/exot][Daniel Borchmann]] for reporting.)
+ Predicate ~src~'s matching of begin/end block lines, normalization of arguments, and handling in non-sexp queries. (Thanks to [[https://github.com/akirak][Akira Komamura]] for reporting.)
+ Predicate ~src~'s behavior with various arguments.
+ Various compilation warnings.
*Internal*
+ Certain query predicates, when called multiple times in an ~and~ sub-expression, are optimized to a single call.
+ Use ~buffer-chars-modified-tick~ instead of ~buffer-modified-tick~. (Thanks to [[https://github.com/yantar92][Ihor Radchenko]].)
+ Implemented tests for ~src~ predicate.
*Credits*
+ Thanks to [[https://github.com/chasecaleb][Caleb Chase]] for help with [[https://github.com/alphapapa/org-ql/pull/285][#285]], fixed in [[https://github.com/alphapapa/org-ql/commit/91908186fcca4b5fd2e9d26da5bc0375c2b41acf][9190818]].
** 0.6.3
*Fixed*
+ Non-sexp query parsing with updated version 1.0.1 of the ~peg~ package. (Fixes [[https://github.com/alphapapa/org-ql/issues/314][#314]], [[https://github.com/alphapapa/org-ql/issues/316][#316]]. Thanks to [[https://github.com/akirak][Akira Komamura]] and [[https://github.com/joonro][Joon Ro]] for reporting.)
+ Require library ~org-duration~ (apparently necessary in newer Org versions).
** 0.6.2
*Fixed*
+ ~link~ predicate when used in an ~or~'ed query. ([[https://github.com/alphapapa/org-ql/issues/279][#279]]. Thanks to [[https://github.com/telenieko][Marc Fargas]] for reporting.)
** 0.6.1
*Fixed*
+ In dynamic blocks, links to headings with statistics cookies were broken. (Fixes [[https://github.com/alphapapa/org-ql/issues/248][#248]]. Thanks to [[https://github.com/maikol-solis][Maikol Solis]] and [[https://github.com/yantar92][Ihor Radchenko]].)
*Updated*
+ Compatibility with new macro names in Transient. ([[https://github.com/alphapapa/org-ql/pull/269][#269]]. Thanks to [[https://github.com/tarsius][Jonas Bernoulli]].)
** 0.6
*Added*
+ Macro =org-ql-defpred=, used to define search predicates. (See [[file:examples/defpred.org][tutorial]].)
+ Predicate ~effort~.
+ Predicate ~heading-regexp~, which matches regular expressions against heading text (alias: ~h*~).
+ Timestamp-related predicates now accept an optional ~:with-time~ argument, which allows matching timestamps with or without times (i.e. HH:MM).
+ Sorting methods:
- ~reverse~
- ~closed~ (Thanks to [[https://github.com/yejianye][Ryan Ye]].)
+ Dynamic block column ~closed~. (Thanks to [[https://github.com/yejianye][Ryan Ye]].)
+ Abbreviate filenames in bookmarks. (Thanks to [[https://github.com/akirak][Akira Komamura]].)
*Changed*
+ The order in which sorting functions is applied has been reversed. For example, ~:sort '(todo priority date)~ now does what ~:sort '(date priority todo)~ did in earlier versions. (This change is made to enable the new ~reverse~ sorting method.) Users who have customized =org-ql-views= will need to update the stored views' sorting methods to preserve the desired sort order.
+ Helm support (including the command =helm-org-ql=) has been moved to a separate package, =helm-org-ql=.
+ Predicate ~heading~ now matches plain strings instead of regular expressions.
+ Update =dash= dependency, and remove dependency on obsolete =dash-functional=. (Fixes [[https://github.com/alphapapa/org-ql/issues/179][#179]], [[https://github.com/alphapapa/org-ql/issues/209][#209]]. Thanks to [[https://github.com/landakram][Mark Hudnall]], [[https://github.com/akirak][Akira Komamura]], [[https://github.com/natask][Nathanael kinfe]], [[https://github.com/benthamite][Pablo Stafforini]], [[https://github.com/jmay][Jason May]], and [[https://github.com/basil-conto][Basil L. Contovounesios]].)
*Removed*
+ Obsolete macro ~org-ql~ (obsolete since 0.5, replaced by functions ~org-ql-select~ and ~org-ql-query~).
*Fixed*
+ Timestamp-related predicates called with relative-date arguments did not properly invalidate the query cache. (Fixes [[https://github.com/alphapapa/org-ql/issues/223][#223]]. Thanks to [[https://github.com/yantar92][Ihor Radchenko]] for reporting.)
*Internal*
+ Predicates are now defined more cleanly with a macro (=org-ql-defpred=) that consolidates functionality related to each predicate. This will also allow users to more easily define custom predicates.
+ Version 1.0 of library ~peg~ is now required.
+ Improvements to how arguments to timestamp-related predicates are processed.
+ Predicate normalizers are now applied repeatedly until a query is fully normalized. (Normalizers should be written with this in mind to avoid infinite loops.)
** 0.5.2
*Fixed*
+ Predicate ~link~'s ~:target~ and ~:regexp-p~ arguments. ([[https://github.com/alphapapa/org-ql/pull/220][#220]]. Thanks to [[https://github.com/akirak][Akira Komamura]].)
** 0.5.1
*Fixed*
+ Custom sorting functions could corrupt the cache, causing items to disappear after refreshing an =org-ql-search= buffer. ([[https://github.com/alphapapa/org-ql/issues/186][#186]], [[https://github.com/alphapapa/org-ql/issues/187][#187]]. Thanks to [[https://github.com/natask][Nathanael kinfe]].)
** 0.5
*Added*
+ View dispatcher using =transient.el= (like Magit), bound to =v= in search/view buffers.
+ Predicate =link=, which matches descriptions and targets in Org links.
+ Predicate ~tags-regexp~ (alias: ~tags*~), which matches regexps against entry tags (e.g, helpful when a tag might end in "s").
+ Emacs bookmark support: Org QL View buffers can be bookmarked with, e.g. =C-x r m= and shown with, e.g. =C-x r b=. (This also enables view restoration with [[https://github.com/alphapapa/burly.el][Burly]].)
+ Dynamic block support.
+ Org link support (storing and opening links to Org QL View searches).
+ Mascot.
*Changed*
+ Binding to refresh search/view buffers changed to =r=.
*Internal*
+ When formatting entries for Org QL View buffers, use internal function for retrieving heading tags. This improves speed by using our cache, and it removes the need for a compatibility alias for Org versions before 9.3.
*Deprecated*
+ Macro =org-ql= is marked obsolete. It will be removed in v0.7. Functions =org-ql-select= and =org-ql-query= should be used instead. (The macro serves only to confuse with regard to quoting arguments.)
*Acknowledgments*
+ [[https://github.com/tpeacock19][tpeacock19]] for extensive help testing new features in this version.
** 0.4.9
*Fixed*
+ Agenda restriction in =org-ql-block=. (Fixes [[https://github.com/alphapapa/org-ql/issues/84][#84]]. Thanks to [[https://github.com/yantar92][Ihor Radchenko]].)
** 0.4.8
*Fixed*
+ Multiple sorters not preserved when refreshing views. (Fixes [[https://github.com/alphapapa/org-ql/issues/136][#136]], [[https://github.com/alphapapa/org-ql/pull/137][#137]]. Thanks to [[https://github.com/natrys][Imran Khan]].)
** 0.4.7
*Fixed*
+ Give a useful error if =org-ql-search-directories-files= is called without a directories argument and =org-directory= doesn't exist. (Fixes [[https://github.com/alphapapa/org-ql/issues/139][#139]]. Thanks to [[https://github.com/matthuszagh][Matt Huszagh]] for reporting.)
** 0.4.6
*Fixed*
+ Compatibility with newer versions of the =peg= library, which removed a macro used by this package. (Fixes [[https://github.com/alphapapa/org-ql/issues/75][#75]]. Thanks to [[https://github.com/novoid][Karl Voit]] and [[https://github.com/karlicoss][@karlicoss]] for reporting.)
** 0.4.5
*Fixed*
+ Non-case-folding predicates like ~(todo)~ unnecessarily disabled case-folding for other predicates. ([[https://github.com/alphapapa/org-ql/issues/114][Issue #114]]. Thanks to [[https://github.com/bitclick][@bitclick]] for reporting.)
** 0.4.4
*Fixed*
+ Compatibility with Org Agenda remote editing commands (some of which were broken by 0.4.3). (Fixes [[https://github.com/alphapapa/org-ql/issues/102][#102]]. Thanks to [[https://github.com/AloisJanicek][Alois Janíček]] for reporting.)
** 0.4.3
*Fixed*
+ When =org-ql-view-refresh= is called, ensure the buffer is an Org QL View buffer.
** 0.4.2
*Fixed*
+ Items' to-do keywords were not shown in views.
** 0.4.1
*Fixed*
+ =level= predicate used with arguments in plain queries. (Thanks to [[https://github.com/akirak][Akira Komamura]] for reporting.)
** 0.4
/Note:/ The next release, 0.5, may include changes which will require minor updates to written queries (e.g. a few predicates may be renamed). Users who wish to avoid those changes happening unexpectedly in their configs should avoid upgrading =org-ql= beyond 0.4 automatically, as they will be pushed to the =master= branch when ready.
*Added*
+ *Commands*
- ~helm-org-ql-views~, which shows one of ~org-ql-views~ selected with Helm.
- ~org-ql-search~ can search files in ~org-directory~; customization options are available in the ~org-ql-search~ group.
- ~org-ql-view-refresh~ can be called with a prefix argument to adjust search parameters.
+ *Queries*
- Negation of terms in plain queries using ~!~. For example, ~tags:space !moon~ to exclude entries which contain ~moon~.
- Predicates =outline-path= (alias =olp=) and =outline-path-segment= (alias =olps=).
- Predicate ~src~, which matches Org Babel source blocks.
- Predicates =parent= and =ancestors=. (Thanks to [[https://github.com/mm--][Josh Moller-Mara]].)
- Alias =h= for =heading= predicate.
- Alias =r= for =regexp= predicate. (Thanks to [[https://github.com/tumashu][Feng Shu]].)
+ Info manual.
+ Function ~helm-org-ql-source~, which returns a Helm source that searches given buffers/files with ~helm-org-ql~. It can be used for custom Helm commands that search certain files.
+ Display a message when views are refreshed. (Thanks to [[https://github.com/xeijin][xeijin]].)
+ Respect Org Agenda restriction in =org-ql-block=. (Thanks to [[https://github.com/yantar92][Ihor Radchenko]] for reporting.)
+ Option =org-ql-view-sidebar-sort-views=.
+ Mouseover =help-echo= text for =org-ql-views= default view names.
+ "Dangling tasks" default view in =org-ql-views=. (Users who have modified =org-ql-views= from the default will not see the new view unless they copy it into their config.)
*Changed*
+ Some default =org-ql-view= views (users who have modified =org-ql-views= from the default will not see the new views unless they copy them into their config):
- Rename some views.
- "Stuck projects" view (now uses =descendants= instead of =children=, which is more useful.
*Fixed*
+ Inherit file tags when =org-tag-inheritance= is enabled. (Fixes [[https://github.com/alphapapa/org-ql/issues/55][#55]]. Thanks to [[https://github.com/mskorzhinskiy][Mikhail Skorzhinskiy]].)
+ Call =helm-make-source= directly instead of using =helm-build-sync-source= macro. (Fixes [[https://github.com/alphapapa/org-ql/issues/60][#60]]. Thanks to [[https://github.com/matthuszagh][Matt Huszagh]] for reporting.)
+ Search/view buffers now always end with a newline, which prevents side-scrolling of the window when calling =end-of-buffer=.
+ Face for done to-do keywords in =org-ql-view= buffers. (Thanks to [[https://github.com/dsdshcym][Yiming Chen]].)
+ Make view buffers read-only. (Fixes [[https://github.com/alphapapa/org-ql/issues/72][#72]]. Thanks to [[https://github.com/xeijin][xeijin]].)
+ Sorting with single sorter specified as an atom. (Thanks to [[https://github.com/legalnonsense][Jeff Filipovits]].)
+ Autoload for =org-ql-block= agenda block. (Fixes [[https://github.com/alphapapa/org-ql/issues/53][#53]]. Thanks to reports from [[https://github.com/gcantieni][Gus Cantieni]], [[https://github.com/novoid][Karl Voit]], [[https://github.com/rieje][rieje]], and [[https://github.com/jakejx][Jake | Junxuan]].)
*Internal*
+ Added generic node data cache to speed up recursive, tree-based queries.
** 0.3.2
*Fixed*
+ In =org-ql-search=, accept symbol as ~:super-groups~ argument.
+ In the =This week= and =Next week= default =org-ql-views= views, set timestamps for beginning-of-week to 00:00:00 and end-of-week to 23:59:59.
+ Plain quoted-phrases in non-sexp queries.
** 0.3.1 ** 0.3.1
*Fixed* *Fixed*
@ -470,9 +1003,17 @@ Expands into a call to ~org-ql-select~ with the same arguments. For convenience
First tagged release. First tagged release.
* Development
Bug reports, feature requests, and suggestions are welcome. For patches, see below.
** Copyright assignment
While Org QL is currently distributed in MELPA, it's [[https://github.com/alphapapa/org-ql/issues/409][intended]] to merge Org QL into Org mode. When that happens, it will become a part of Emacs and Org, and therefore cumulative contributions of more than 15 lines of code will require that the author assign copyright of such contributions to the FSF. Authors who are interested in doing so may contact [[mailto:assign@gnu.org][assign@gnu.org]] to request the appropriate form.
* Notes * Notes
:PROPERTIES: :PROPERTIES:
:TOC: ignore-children :TOC: :ignore this
:END: :END:
** Comparison with Org Agenda searches ** Comparison with Org Agenda searches
@ -483,13 +1024,7 @@ Of course, queries like these can already be written with Org Agenda searches, b
+lisp +{^\*+\s-+TO-READ\s-} +lisp +{^\*+\s-+TO-READ\s-}
#+END_EXAMPLE #+END_EXAMPLE
But with ~org-ql-agenda~, you would write: But with =org-ql-search=, you would write a query like =lisp todo:TO-READ=, or in Lisp syntax, ~(and "lisp" (todo "TO-READ"))~.
#+BEGIN_SRC elisp
(org-ql-agenda
(and (regexp "lisp")
(todo "TO-READ")))
#+END_SRC
** org-sidebar ** org-sidebar
@ -497,14 +1032,14 @@ This package is used by [[https://github.com/alphapapa/org-sidebar][org-sidebar]
* License * License
:PROPERTIES: :PROPERTIES:
:TOC: ignore :TOC: :ignore this
:END: :END:
GPLv3 GPLv3
* COMMENT Code :noexport: * COMMENT Code :noexport:
:PROPERTIES: :PROPERTIES:
:TOC: ignore :TOC: :ignore this
:END: :END:
# The COMMENT keyword prevents GitHub's renderer from showing this entry. # The COMMENT keyword prevents GitHub's renderer from showing this entry.
@ -564,9 +1099,32 @@ Generates the predicate subtree.
If ~org-ql~ is loaded byte-compiled, the argument lists are not named properly (not sure why, as ~help-function-arglist~ is supposed to handle that). We could run the function in another Emacs process with ~async~ to avoid this. If ~org-ql~ is loaded byte-compiled, the argument lists are not named properly (not sure why, as ~help-function-arglist~ is supposed to handle that). We could run the function in another Emacs process with ~async~ to avoid this.
* COMMENT Export setup :noexport:
:PROPERTIES:
:TOC: :ignore this
:END:
# Copied from org-super-agenda's readme, in which much was borrowed from Org's =org-manual.org=.
#+OPTIONS: broken-links:t *:t
** Info export options
#+TEXINFO_DIR_CATEGORY: Emacs
#+TEXINFO_DIR_TITLE: Org QL: (org-ql)
#+TEXINFO_DIR_DESC: Query language, search commands, and saved views for Org files
# NOTE: We could use these, but that causes a pointless error, "org-compile-file: File "..README.info" wasn't produced...", so we just rename the files in the after-save-hook instead.
# #+TEXINFO_FILENAME: org-ql.info
# #+EXPORT_FILE_NAME: org-ql.texi
** File-local variables ** File-local variables
# NOTE: Setting org-comment-string buffer-locally is a nasty hack to work around GitHub's org-ruby's HTML rendering, which does not respect noexport tags. The only way to hide this tree from its output is to use the COMMENT keyword, but that prevents Org from processing the export options declared in it. So since these file-local variables don't affect org-ruby, wet set org-comment-string to an unused keyword, which prevents Org from deleting this tree from the export buffer, which allows it to find the export options in it. And since org-export does respect the noexport tag, the tree is excluded from the info page.
# Local Variables: # Local Variables:
# eval: (require 'org-make-toc)
# before-save-hook: org-make-toc # before-save-hook: org-make-toc
# after-save-hook: (lambda nil (when (and (require 'ox-texinfo nil t) (org-texinfo-export-to-info)) (delete-file "README.texi") (rename-file "README.info" "org-ql.info" t)))
# org-export-initial-scope: buffer
# org-comment-string: "NOTCOMMENT"
# End: # End:

View file

@ -2,17 +2,26 @@
* Contents * Contents
:PROPERTIES: :PROPERTIES:
:TOC: this :TOC: :include siblings :ignore this
:END: :END:
- [[#agenda-like-view][Agenda-like view]] :CONTENTS:
- [[#entries-from-the-past-week][Entries from the past week]] - [[#custom-predicates][Custom predicates]]
- [[#find-entries-matching-a-certain-custom_id][Find entries matching a certain CUSTOM_ID]] - [[#agenda-like-view][Agenda-like view]]
- [[#listing-bills-coming-due][Listing bills coming due]] - [[#entries-from-the-past-week][Entries from the past week]]
- [[#music-database][Music database]] - [[#find-entries-matching-a-certain-custom_id][Find entries matching a certain CUSTOM_ID]]
- [[#return-org-elements][Return Org elements]] - [[#listing-bills-coming-due][Listing bills coming due]]
- [[#set-tags-on-certain-entries][Set tags on certain entries]] - [[#music-database][Music database]]
- [[#show-entries-with-recent-timestamps][Show entries with recent timestamps]] - [[#return-org-elements][Return Org elements]]
- [[#stuck-projects-block-agenda][Stuck projects block agenda]] - [[#set-tags-on-certain-entries][Set tags on certain entries]]
- [[#show-entries-with-recent-timestamps][Show entries with recent timestamps]]
- [[#stuck-projects-block-agenda][Stuck projects block agenda]]
- [[#subproject-and-subtask-queries][Subproject and subtask queries]]
- [[#task-list-for-files-in-subdirectories][Task list for files in subdirectories]]
:END:
* Custom predicates
+ [[file:examples/defpred.org][Custom predicate tutorial]]
* Agenda-like view * Agenda-like view
@ -26,7 +35,7 @@ Show an agenda-like view, similar to a "traditional" Org Agenda with Log Mode tu
(scheduled :to today) (scheduled :to today)
(ts-active :on today))) (ts-active :on today)))
(closed :on today)) (closed :on today))
:sort '(date priority todo)) :sort '(todo priority date))
#+END_SRC #+END_SRC
Another example, showing grouping with [[https://github.com/alphapapa/org-super-agenda][org-super-agenda]]: Another example, showing grouping with [[https://github.com/alphapapa/org-super-agenda][org-super-agenda]]:
@ -67,8 +76,8 @@ Show entries that have any timestamp within the past week. Group by date using
(org-ql-search (org-agenda-files) (org-ql-search (org-agenda-files)
'(ts :from -7 :to today) '(ts :from -7 :to today)
:title "Recent Items" :title "Recent Items"
:sort '(date priority todo) :sort '(todo priority date)
:groups '((:auto-ts t))) :super-groups '((:auto-ts t)))
#+END_SRC #+END_SRC
* Find entries matching a certain =CUSTOM_ID= * Find entries matching a certain =CUSTOM_ID=
@ -173,9 +182,71 @@ With this =org-ql-block= agenda view, like:
((org-ql-block-header "Stuck Projects"))))))) ((org-ql-block-header "Stuck Projects")))))))
#+END_SRC #+END_SRC
* Subproject and subtask queries
#+BEGIN_SRC elisp
;; Search for subprojects.
(org-ql-search (org-agenda-files)
'(and (todo "PROJECT")
(ancestors (todo "PROJECT"))))
;; Search for all subtasks of projects, grouped by parent heading.
(org-ql-search (org-agenda-files)
'(and (todo)
(ancestors (todo "PROJECT")))
:super-groups '((:auto-parent t)))
;; Search for direct top-level tasks of projects.
(org-ql-search (org-agenda-files)
'(and (todo)
(parent (todo "PROJECT")))
:super-groups '((:auto-parent t)))
#+END_SRC
Of course, all of those presume using a =PROJECT= keyword to define projects. If one defines a project as any task which has an ancestor task, one could use queries like:
#+BEGIN_SRC elisp
;; Search for all subtasks of top-level projects, grouped by parent heading.
(org-ql-search (org-agenda-files)
'(and (todo)
(ancestors
(and (todo)
(not (parent)))))
:super-groups '((:auto-parent t)))
;; Search for all subtasks of all projects, including subprojects, grouped by project.
(org-ql-search (org-agenda-files)
'(and (todo)
(ancestors (todo)))
:super-groups '((:auto-parent t)))
#+END_SRC
Other interesting queries:
#+BEGIN_SRC elisp
;; Subtasks of upcoming deadline items.
(org-ql-search (org-agenda-files)
'(and (todo)
(ancestors
(and (not (done))
(deadline auto))))
:super-groups '((:auto-parent t)))
;; TODO items whose ancestor is already DONE, and should therefore be
;; either marked DONE or CANCELLED.
(org-ql-search (org-agenda-files)
'(and (todo)
(ancestors (done)))
:super-groups '((:auto-parent t)))
#+END_SRC
* Task list for files in subdirectories
[[images/org-ql-search-snippet.png]]
* COMMENT Code :noexport: * COMMENT Code :noexport:
:PROPERTIES: :PROPERTIES:
:TOC: ignore :TOC: :ignore (this descendants)
:END: :END:
** File-local variables ** File-local variables

766
examples/defpred.html Normal file
View file

@ -0,0 +1,766 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<!-- 2020-11-23 Mon 03:31 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Org QL Custom Predicates Tutorial</title>
<meta name="generator" content="Org mode" />
<style type="text/css">
<!--/*--><![CDATA[/*><!--*/
.title { text-align: center;
margin-bottom: .2em; }
.subtitle { text-align: center;
font-size: medium;
font-weight: bold;
margin-top:0; }
.todo { font-family: monospace; color: red; }
.done { font-family: monospace; color: green; }
.priority { font-family: monospace; color: orange; }
.tag { background-color: #eee; font-family: monospace;
padding: 2px; font-size: 80%; font-weight: normal; }
.timestamp { color: #bebebe; }
.timestamp-kwd { color: #5f9ea0; }
.org-right { margin-left: auto; margin-right: 0px; text-align: right; }
.org-left { margin-left: 0px; margin-right: auto; text-align: left; }
.org-center { margin-left: auto; margin-right: auto; text-align: center; }
.underline { text-decoration: underline; }
#postamble p, #preamble p { font-size: 90%; margin: .2em; }
p.verse { margin-left: 3%; }
pre {
border: 1px solid #ccc;
box-shadow: 3px 3px 3px #eee;
padding: 8pt;
font-family: monospace;
overflow: auto;
margin: 1.2em;
}
pre.src {
position: relative;
overflow: visible;
padding-top: 1.2em;
}
pre.src:before {
display: none;
position: absolute;
background-color: white;
top: -10px;
right: 10px;
padding: 3px;
border: 1px solid black;
}
pre.src:hover:before { display: inline;}
/* Languages per Org manual */
pre.src-asymptote:before { content: 'Asymptote'; }
pre.src-awk:before { content: 'Awk'; }
pre.src-C:before { content: 'C'; }
/* pre.src-C++ doesn't work in CSS */
pre.src-clojure:before { content: 'Clojure'; }
pre.src-css:before { content: 'CSS'; }
pre.src-D:before { content: 'D'; }
pre.src-ditaa:before { content: 'ditaa'; }
pre.src-dot:before { content: 'Graphviz'; }
pre.src-calc:before { content: 'Emacs Calc'; }
pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
pre.src-fortran:before { content: 'Fortran'; }
pre.src-gnuplot:before { content: 'gnuplot'; }
pre.src-haskell:before { content: 'Haskell'; }
pre.src-java:before { content: 'Java'; }
pre.src-js:before { content: 'Javascript'; }
pre.src-latex:before { content: 'LaTeX'; }
pre.src-ledger:before { content: 'Ledger'; }
pre.src-lisp:before { content: 'Lisp'; }
pre.src-lilypond:before { content: 'Lilypond'; }
pre.src-lua:before { content: 'Lua'; }
pre.src-matlab:before { content: 'MATLAB'; }
pre.src-mscgen:before { content: 'Mscgen'; }
pre.src-ocaml:before { content: 'Objective Caml'; }
pre.src-octave:before { content: 'Octave'; }
pre.src-org:before { content: 'Org mode'; }
pre.src-oz:before { content: 'OZ'; }
pre.src-plantuml:before { content: 'Plantuml'; }
pre.src-processing:before { content: 'Processing.js'; }
pre.src-python:before { content: 'Python'; }
pre.src-R:before { content: 'R'; }
pre.src-ruby:before { content: 'Ruby'; }
pre.src-sass:before { content: 'Sass'; }
pre.src-scheme:before { content: 'Scheme'; }
pre.src-screen:before { content: 'Gnu Screen'; }
pre.src-sed:before { content: 'Sed'; }
pre.src-sh:before { content: 'shell'; }
pre.src-sql:before { content: 'SQL'; }
pre.src-sqlite:before { content: 'SQLite'; }
/* additional languages in org.el's org-babel-load-languages alist */
pre.src-forth:before { content: 'Forth'; }
pre.src-io:before { content: 'IO'; }
pre.src-J:before { content: 'J'; }
pre.src-makefile:before { content: 'Makefile'; }
pre.src-maxima:before { content: 'Maxima'; }
pre.src-perl:before { content: 'Perl'; }
pre.src-picolisp:before { content: 'Pico Lisp'; }
pre.src-scala:before { content: 'Scala'; }
pre.src-shell:before { content: 'Shell Script'; }
pre.src-ebnf2ps:before { content: 'ebfn2ps'; }
/* additional language identifiers per "defun org-babel-execute"
in ob-*.el */
pre.src-cpp:before { content: 'C++'; }
pre.src-abc:before { content: 'ABC'; }
pre.src-coq:before { content: 'Coq'; }
pre.src-groovy:before { content: 'Groovy'; }
/* additional language identifiers from org-babel-shell-names in
ob-shell.el: ob-shell is the only babel language using a lambda to put
the execution function name together. */
pre.src-bash:before { content: 'bash'; }
pre.src-csh:before { content: 'csh'; }
pre.src-ash:before { content: 'ash'; }
pre.src-dash:before { content: 'dash'; }
pre.src-ksh:before { content: 'ksh'; }
pre.src-mksh:before { content: 'mksh'; }
pre.src-posh:before { content: 'posh'; }
/* Additional Emacs modes also supported by the LaTeX listings package */
pre.src-ada:before { content: 'Ada'; }
pre.src-asm:before { content: 'Assembler'; }
pre.src-caml:before { content: 'Caml'; }
pre.src-delphi:before { content: 'Delphi'; }
pre.src-html:before { content: 'HTML'; }
pre.src-idl:before { content: 'IDL'; }
pre.src-mercury:before { content: 'Mercury'; }
pre.src-metapost:before { content: 'MetaPost'; }
pre.src-modula-2:before { content: 'Modula-2'; }
pre.src-pascal:before { content: 'Pascal'; }
pre.src-ps:before { content: 'PostScript'; }
pre.src-prolog:before { content: 'Prolog'; }
pre.src-simula:before { content: 'Simula'; }
pre.src-tcl:before { content: 'tcl'; }
pre.src-tex:before { content: 'TeX'; }
pre.src-plain-tex:before { content: 'Plain TeX'; }
pre.src-verilog:before { content: 'Verilog'; }
pre.src-vhdl:before { content: 'VHDL'; }
pre.src-xml:before { content: 'XML'; }
pre.src-nxml:before { content: 'XML'; }
/* add a generic configuration mode; LaTeX export needs an additional
(add-to-list 'org-latex-listings-langs '(conf " ")) in .emacs */
pre.src-conf:before { content: 'Configuration File'; }
table { border-collapse:collapse; }
caption.t-above { caption-side: top; }
caption.t-bottom { caption-side: bottom; }
td, th { vertical-align:top; }
th.org-right { text-align: center; }
th.org-left { text-align: center; }
th.org-center { text-align: center; }
td.org-right { text-align: right; }
td.org-left { text-align: left; }
td.org-center { text-align: center; }
dt { font-weight: bold; }
.footpara { display: inline; }
.footdef { margin-bottom: 1em; }
.figure { padding: 1em; }
.figure p { text-align: center; }
.inlinetask {
padding: 10px;
border: 2px solid gray;
margin: 10px;
background: #ffffcc;
}
#org-div-home-and-up
{ text-align: right; font-size: 70%; white-space: nowrap; }
textarea { overflow-x: auto; }
.linenr { font-size: smaller }
.code-highlighted { background-color: #ffff00; }
.org-info-js_info-navigation { border-style: none; }
#org-info-js_console-label
{ font-size: 10px; font-weight: bold; white-space: nowrap; }
.org-info-js_search-highlight
{ background-color: #ffff00; color: #000000; font-weight: bold; }
.org-svg { width: 90%; }
/*]]>*/-->
</style>
<link rel="stylesheet" type="text/css" href="export/styles/darksun/css/darksun.css"/>
<script type="text/javascript" src="export/styles/darksun/js/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="export/styles/darksun/js/jquery-ui-1.10.2.min.js"></script>
<script type="text/javascript" src="export/styles/darksun/js/jquery.localscroll-min.js"></script>
<script type="text/javascript" src="export/styles/darksun/js/jquery.scrollTo-1.4.3.1-min.js"></script>
<script type="text/javascript" src="export/styles/darksun/js/jquery.zclip.min.js"></script>
<script type="text/javascript" src="export/styles/darksun/js/darksun.js"></script>
<script type="text/javascript" src="export/styles/lib/js/jquery.stickytableheaders.min.js"></script>
<script type="text/javascript">
/*
@licstart The following is the entire license notice for the
JavaScript code in this tag.
Copyright (C) 2012-2013 Free Software Foundation, Inc.
The JavaScript code in this tag is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version. The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
As additional permission under GNU GPL version 3 section 7, you
may distribute non-source (e.g., minimized or compacted) forms of
that code without the copy of the GNU GPL normally required by
section 4, provided you include this license notice and a URL
through which recipients can access the Corresponding Source.
@licend The above is the entire license notice
for the JavaScript code in this tag.
*/
<!--/*--><![CDATA[/*><!--*/
function CodeHighlightOn(elem, id)
{
var target = document.getElementById(id);
if(null != target) {
elem.cacheClassElem = elem.className;
elem.cacheClassTarget = target.className;
target.className = "code-highlighted";
elem.className = "code-highlighted";
}
}
function CodeHighlightOff(elem, id)
{
var target = document.getElementById(id);
if(elem.cacheClassElem)
elem.className = elem.cacheClassElem;
if(elem.cacheClassTarget)
target.className = elem.cacheClassTarget;
}
/*]]>*///-->
</script>
</head>
<body>
<div id="content">
<h1 class="title">Org QL Custom Predicates Tutorial</h1>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#Using%20built-in%20predicates">Using built-in predicates</a></li>
<li><a href="#A%20custom%20~%28person%29~%20predicate">A custom <code>(person)</code> predicate</a></li>
<li><a href="#Searching%20for%20multiple%20people%20at%20once">Searching for multiple people at once</a></li>
<li><a href="#Normalizing%20queries%20to%20rewrite%20arguments">Normalizing queries to rewrite arguments</a></li>
<li><a href="#Non-sexp%20query%20syntax">Non-sexp query syntax</a></li>
<li><a href="#Using%20multiple%20predicates">Using multiple predicates</a></li>
<li><a href="#Predicate%20aliases">Predicate aliases</a></li>
<li><a href="#Be%20formless">Be formless</a></li>
<li><a href="#Conclusion">Conclusion</a></li>
<li><a href="#Appendix%3A%20Anaphoric%20macros">Appendix: Anaphoric macros</a></li>
<li><a href="#Example%20data">Example data</a>
<ul>
<li><a href="#Loud%20pet%20parakeet">Loud pet parakeet&#xa0;&#xa0;&#xa0;<span class="tag"><span class="personAlice">personAlice</span></span></a></li>
<li><a href="#Missing%20sticky%20notes">Missing sticky notes&#xa0;&#xa0;&#xa0;<span class="tag"><span class="personAlice">personAlice</span></span></a></li>
<li><a href="#Dirty%20dishes%20in%20sink">Dirty dishes in sink&#xa0;&#xa0;&#xa0;<span class="tag"><span class="personAlice">personAlice</span></span></a></li>
<li><a href="#Stinky%20coffee%20breath">Stinky coffee breath</a></li>
</ul>
</li>
</ul>
</div>
</div>
<p>
<span class="timestamp-wrapper"><span class="timestamp">[2020-11-22 Sun 22:35] </span></span> Imagine you have weekly meetings with other people, and during the week you take notes about items to discuss at each meeting. When the time for a meeting comes, you want to quickly and easily search for all of the items to discuss at the meeting.
</p>
<p>
You've been experimenting with different ways to track such data in Org. You've tried using tags, but some of the names in question conflict with other tags in your data (e.g. someone's named Charles, but you also work with a firm named Charles, Inc., and you'd prefer to continue using the tag <code>Charles</code> for entries about that firm), so you've been using tags like <code>:personNAME:</code>, which seems awkward. You've tried using a <code>:person: NAME</code> property on entries, which has the advantage of not cluttering the tags list, but also the disadvantage of not being readily visible in an outline.
</p>
<p>
So you haven't decided on a long-term solution, but the meetings aren't going to wait&#x2013;you need to search that data now, and you have a mix of both tags and properties in your entries. What you need is to be able to search for all of the entries about Alice (which you've tagged <code>:personAlice:</code>) when you're meeting with her, and all of the entries about Bob (which have the property <code>:person: Bob</code>) when you're meeting with him. What do you do?
</p>
<div id="outline-container-Using%20built-in%20predicates" class="outline-2">
<h2 id="Using%20built-in%20predicates">Using built-in predicates</h2>
<div class="outline-text-2" id="text-Using%20built-in%20predicates">
<p>
You could start by using built-in Org QL predicates to search your data. For example:
</p>
<div class="org-src-container">
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; text-decoration: underline;">org-ql-query</span><span style="color: #3d85b7;"> </span><span style="color: #3d85b7; font-weight: bold;">:select</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">org-get-heading </span><span style="color: #78880e; font-weight: bold;">:no-tags</span><span style="color: #3d85b7;">)</span>
<span style="color: #3d85b7; font-weight: bold;">:from</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; text-decoration: underline;">current-buffer</span><span style="color: #3d85b7;">)</span>
<span style="color: #3d85b7; font-weight: bold;">:where</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e; font-weight: bold;">or</span><span style="color: #78880e;"> (</span><span style="color: #3d8b85; text-decoration: underline;">tags</span><span style="color: #3d8b85;"> </span><span style="color: #65bc957591ca;">"personAlice"</span><span style="color: #78880e;">)</span>
<span style="color: #78880e;">(</span><span style="color: #3d8b85; text-decoration: underline;">property</span><span style="color: #3d8b85;"> </span><span style="color: #65bc957591ca;">"person"</span> <span style="color: #65bc957591ca;">"Bob"</span><span style="color: #78880e;">)</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
</pre>
</div>
<ul class="org-ul">
<li>[#A] Loud pet parakeet</li>
<li>[#C] Missing sticky notes</li>
<li>[#C] Dirty dishes in sink</li>
<li>[#A] Stinky coffee breath</li>
</ul>
<p>
That was easy enough, but it's not very&#x2026;semantic. You have to think about the implementation details: Alice uses tags, Bob uses properties, and what if Charlie uses both? It starts to feel complicated, and it's a lot to type out every time. Is there an easier way?
</p>
</div>
</div>
<div id="outline-container-A%20custom%20~%28person%29~%20predicate" class="outline-2">
<h2 id="A%20custom%20~%28person%29~%20predicate">A custom <code>(person)</code> predicate</h2>
<div class="outline-text-2" id="text-A%20custom%20~%28person%29~%20predicate">
<p>
Enter <code>org-ql</code> custom search predicates. Let's start simple, by defining a predicate to search for just the <code>:person:</code> property, one person at a time. The predicate will take one argument, a person's name, and search for that property. It would look like this:
</p>
<div class="org-src-container">
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; font-weight: bold;">org-ql-defpred</span><span style="color: #3d85b7;"> person (</span><span style="color: #78880e;">name</span><span style="color: #3d85b7;">)</span>
<span style="color: #73139976b41e;">"Search for entries with the \"person\" property being NAME."</span>
<span style="color: #3d85b7; font-weight: bold;">:body</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; text-decoration: underline;">property</span><span style="color: #78880e;"> </span><span style="color: #921da24c26e6;">"person"</span> <span style="color: #78880e;">name</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
</pre>
</div>
<p>
Now, let's see what results we get for searching this file for entries about Bob:
</p>
<div class="org-src-container">
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; text-decoration: underline;">org-ql-query</span><span style="color: #3d85b7;"> </span><span style="color: #3d85b7; font-weight: bold;">:select</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">org-get-heading </span><span style="color: #78880e; font-weight: bold;">:no-tags</span><span style="color: #3d85b7;">)</span>
<span style="color: #3d85b7; font-weight: bold;">:from</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; text-decoration: underline;">current-buffer</span><span style="color: #3d85b7;">)</span>
<span style="color: #3d85b7; font-weight: bold;">:where</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">person </span><span style="color: #921da24c26e6;">"Bob"</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
</pre>
</div>
<ul class="org-ul">
<li>[#C] Missing sticky notes</li>
<li>[#C] Dirty dishes in sink</li>
<li>[#A] Stinky coffee breath</li>
</ul>
<p>
Hmm, looks like we need to remind Bob to wash his mug and take some mints after lunch. Now what do we need to discuss with Alice?
</p>
<div class="org-src-container">
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; text-decoration: underline;">org-ql-query</span><span style="color: #3d85b7;"> </span><span style="color: #3d85b7; font-weight: bold;">:select</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">org-get-heading </span><span style="color: #78880e; font-weight: bold;">:no-tags</span><span style="color: #3d85b7;">)</span>
<span style="color: #3d85b7; font-weight: bold;">:from</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; text-decoration: underline;">current-buffer</span><span style="color: #3d85b7;">)</span>
<span style="color: #3d85b7; font-weight: bold;">:where</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">person </span><span style="color: #921da24c26e6;">"Alice"</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
</pre>
</div>
<pre class="example">
</pre>
<p>
Nothing? Oh, right, Alice's entries use the <code>:personAlice:</code> tag, so we'll also need to search those kind of entries. Let's make the predicate do that, too:
</p>
<div class="org-src-container">
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; font-weight: bold;">org-ql-defpred</span><span style="color: #3d85b7;"> person (</span><span style="color: #78880e;">name</span><span style="color: #3d85b7;">)</span>
<span style="color: #73139976b41e;">"Search for entries with the \"person\" property being NAME or having the tag \"personNAME\"."</span>
<span style="color: #3d85b7; font-weight: bold;">:body</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; font-weight: bold;">or</span><span style="color: #78880e;"> (</span><span style="color: #3d8b85; text-decoration: underline;">property</span><span style="color: #3d8b85;"> </span><span style="color: #65bc957591ca;">"person"</span> <span style="color: #3d8b85;">name</span><span style="color: #78880e;">)</span>
<span style="color: #78880e;">(</span><span style="color: #3d8b85; text-decoration: underline;">tags</span><span style="color: #3d8b85;"> (</span><span style="color: #a17e11; text-decoration: underline;">concat</span><span style="color: #a17e11;"> </span><span style="color: #b86396762cce;">"person"</span> <span style="color: #a17e11;">name</span><span style="color: #3d8b85;">)</span><span style="color: #78880e;">)</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
</pre>
</div>
<p>
How about now?
</p>
<div class="org-src-container">
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; text-decoration: underline;">org-ql-query</span><span style="color: #3d85b7;"> </span><span style="color: #3d85b7; font-weight: bold;">:select</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">org-get-heading </span><span style="color: #78880e; font-weight: bold;">:no-tags</span><span style="color: #3d85b7;">)</span>
<span style="color: #3d85b7; font-weight: bold;">:from</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; text-decoration: underline;">current-buffer</span><span style="color: #3d85b7;">)</span>
<span style="color: #3d85b7; font-weight: bold;">:where</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">person </span><span style="color: #921da24c26e6;">"Alice"</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
</pre>
</div>
<ul class="org-ul">
<li>[#A] Loud pet parakeet</li>
<li>[#C] Missing sticky notes</li>
<li>[#C] Dirty dishes in sink</li>
</ul>
<p>
Hmm, I thought we already told her to leave Polly at home.
</p>
</div>
</div>
<div id="outline-container-Searching%20for%20multiple%20people%20at%20once" class="outline-2">
<h2 id="Searching%20for%20multiple%20people%20at%20once">Searching for multiple people at once</h2>
<div class="outline-text-2" id="text-Searching%20for%20multiple%20people%20at%20once">
<p>
Oh, wait, this week is shortened due to holidays, so we're having a combined meeting. How do we search for entries about either of them? Well, this is the obvious solution:
</p>
<div class="org-src-container">
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; text-decoration: underline;">org-ql-query</span><span style="color: #3d85b7;"> </span><span style="color: #3d85b7; font-weight: bold;">:select</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">org-get-heading </span><span style="color: #78880e; font-weight: bold;">:no-tags</span><span style="color: #3d85b7;">)</span>
<span style="color: #3d85b7; font-weight: bold;">:from</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; text-decoration: underline;">current-buffer</span><span style="color: #3d85b7;">)</span>
<span style="color: #3d85b7; font-weight: bold;">:where</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e; font-weight: bold;">or</span><span style="color: #78880e;"> (</span><span style="color: #3d8b85;">person </span><span style="color: #65bc957591ca;">"Alice"</span><span style="color: #78880e;">)</span>
<span style="color: #78880e;">(</span><span style="color: #3d8b85;">person </span><span style="color: #65bc957591ca;">"Bob"</span><span style="color: #78880e;">)</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
</pre>
</div>
<ul class="org-ul">
<li>[#A] Loud pet parakeet</li>
<li>[#C] Missing sticky notes</li>
<li>[#C] Dirty dishes in sink</li>
<li>[#A] Stinky coffee breath</li>
</ul>
<p>
And that works fine. But it seems like a lot to type. Could we make the <code>person</code> predicate accept multiple names instead?
</p>
<div class="org-src-container">
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; font-weight: bold;">org-ql-defpred</span><span style="color: #3d85b7;"> person (</span><span style="color: #78880e;">&amp;rest</span><span style="color: #78880e;"> names</span><span style="color: #3d85b7;">)</span>
<span style="color: #73139976b41e;">"Search for entries about any of NAMES."</span>
<span style="color: #3d85b7; font-weight: bold;">:body</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; font-weight: bold;">cl-loop</span><span style="color: #78880e;"> for name in names</span>
<span style="color: #78880e;"> thereis (</span><span style="color: #3d8b85; font-weight: bold;">or</span><span style="color: #3d8b85;"> (</span><span style="color: #a17e11; text-decoration: underline;">property</span><span style="color: #a17e11;"> </span><span style="color: #b86396762cce;">"person"</span> <span style="color: #a17e11;">name</span><span style="color: #3d8b85;">)</span>
<span style="color: #3d8b85;">(</span><span style="color: #a17e11; text-decoration: underline;">tags</span><span style="color: #a17e11;"> (</span><span style="color: #3d85b7; text-decoration: underline;">concat</span><span style="color: #3d85b7;"> </span><span style="color: #73139976b41e;">"person"</span> <span style="color: #3d85b7;">name</span><span style="color: #a17e11;">)</span><span style="color: #3d8b85;">)</span><span style="color: #78880e;">)</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
</pre>
</div>
<p>
Now let's search again:
</p>
<div class="org-src-container">
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; text-decoration: underline;">org-ql-query</span><span style="color: #3d85b7;"> </span><span style="color: #3d85b7; font-weight: bold;">:select</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">org-get-heading </span><span style="color: #78880e; font-weight: bold;">:no-tags</span><span style="color: #3d85b7;">)</span>
<span style="color: #3d85b7; font-weight: bold;">:from</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; text-decoration: underline;">current-buffer</span><span style="color: #3d85b7;">)</span>
<span style="color: #3d85b7; font-weight: bold;">:where</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">person </span><span style="color: #921da24c26e6;">"Alice"</span> <span style="color: #921da24c26e6;">"Bob"</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
</pre>
</div>
<ul class="org-ul">
<li>[#A] Loud pet parakeet</li>
<li>[#C] Missing sticky notes</li>
<li>[#C] Dirty dishes in sink</li>
<li>[#A] Stinky coffee breath</li>
</ul>
<p>
That was easy!
</p>
</div>
</div>
<div id="outline-container-Normalizing%20queries%20to%20rewrite%20arguments" class="outline-2">
<h2 id="Normalizing%20queries%20to%20rewrite%20arguments">Normalizing queries to rewrite arguments</h2>
<div class="outline-text-2" id="text-Normalizing%20queries%20to%20rewrite%20arguments">
<p>
Now, all this is well and good if you don't have hundreds of thousands of Org entries in your files. But what if you do? All that <code>concat</code>'ing happening on every entry could add up, and the query might take a few seconds. What if we could do that stringing-along just once, before running the query? We want to turn our <code>(person "Alice" "Bob")</code> query into this, with the <code>:personNAME:</code> strings already made and the per-person <code>(property ...)</code> predicates also included:
</p>
<div class="org-src-container">
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; font-weight: bold;">or</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; text-decoration: underline;">tags</span><span style="color: #78880e;"> </span><span style="color: #921da24c26e6;">"personAlice"</span> <span style="color: #921da24c26e6;">"personBob"</span><span style="color: #3d85b7;">)</span>
<span style="color: #3d85b7;">(</span><span style="color: #78880e; text-decoration: underline;">property</span><span style="color: #78880e;"> </span><span style="color: #921da24c26e6;">"person"</span> <span style="color: #921da24c26e6;">"Alice"</span><span style="color: #3d85b7;">)</span>
<span style="color: #3d85b7;">(</span><span style="color: #78880e; text-decoration: underline;">property</span><span style="color: #78880e;"> </span><span style="color: #921da24c26e6;">"person"</span> <span style="color: #921da24c26e6;">"Bob"</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
</pre>
</div>
<p>
Can we do that? In fact, we can, by using a query normalizer. Normalizers are <code>pcase</code> forms (I <i>know</i>) that normalize query expressions before execution. We can use one to rewrite the query ahead of time, like this:
</p>
<div class="org-src-container">
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; font-weight: bold;">org-ql-defpred</span><span style="color: #3d85b7;"> person (</span><span style="color: #78880e;">&amp;rest</span><span style="color: #78880e;"> names</span><span style="color: #3d85b7;">)</span>
<span style="color: #73139976b41e;">"Search for entries about any of NAMES."</span>
<span style="color: #3d85b7; font-weight: bold;">:normalizers</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e;">(</span><span style="color: #3d8b85;">`(</span><span style="color: #a17e11;">person . ,names</span><span style="color: #3d8b85;">)</span>
<span style="color: #3d8b85;">`(</span><span style="color: #a17e11; font-weight: bold;">or</span><span style="color: #a17e11;"> (</span><span style="color: #3d85b7; text-decoration: underline;">tags</span><span style="color: #3d85b7;"> ,@(</span><span style="color: #78880e; font-weight: bold;">cl-loop</span><span style="color: #78880e;"> for name in names</span>
<span style="color: #78880e;"> collect (</span><span style="color: #3d8b85; text-decoration: underline;">concat</span><span style="color: #3d8b85;"> </span><span style="color: #65bc957591ca;">"person"</span> <span style="color: #3d8b85;">name</span><span style="color: #78880e;">)</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
<span style="color: #a17e11;">,@(</span><span style="color: #3d85b7; font-weight: bold;">cl-loop</span><span style="color: #3d85b7;"> for name in names</span>
<span style="color: #3d85b7;"> collect `(</span><span style="color: #78880e;">property </span><span style="color: #921da24c26e6;">"person"</span> <span style="color: #78880e;">,name</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span><span style="color: #3d8b85;">)</span><span style="color: #78880e;">)</span><span style="color: #3d85b7;">)</span>
<span style="color: #3d85b7; font-weight: bold;">:body</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; font-weight: bold;">cl-loop</span><span style="color: #78880e;"> for name in names</span>
<span style="color: #78880e;"> thereis (</span><span style="color: #3d8b85; font-weight: bold;">or</span><span style="color: #3d8b85;"> (</span><span style="color: #a17e11; text-decoration: underline;">property</span><span style="color: #a17e11;"> </span><span style="color: #b86396762cce;">"person"</span> <span style="color: #a17e11;">name</span><span style="color: #3d8b85;">)</span>
<span style="color: #3d8b85;">(</span><span style="color: #a17e11; text-decoration: underline;">tags</span><span style="color: #a17e11;"> name</span><span style="color: #3d8b85;">)</span><span style="color: #78880e;">)</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
</pre>
</div>
<p>
Now, don't faint from all the backquoting and unquoting&#x2013;it's just Lisp, nothing to be afraid of! Let's slow down a moment and see what the normalized query looks like to be sure we're doing it correctly:
</p>
<div class="org-src-container">
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; text-decoration: underline;">org-ql--normalize-query</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">person </span><span style="color: #921da24c26e6;">"Alice"</span> <span style="color: #921da24c26e6;">"Bob"</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
</pre>
</div>
<div class="org-src-container">
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; font-weight: bold;">or</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; text-decoration: underline;">tags</span><span style="color: #78880e;"> </span><span style="color: #921da24c26e6;">"personAlice"</span> <span style="color: #921da24c26e6;">"personBob"</span><span style="color: #3d85b7;">)</span>
<span style="color: #3d85b7;">(</span><span style="color: #78880e; text-decoration: underline;">property</span><span style="color: #78880e;"> </span><span style="color: #921da24c26e6;">"person"</span> <span style="color: #921da24c26e6;">"Alice"</span><span style="color: #3d85b7;">)</span>
<span style="color: #3d85b7;">(</span><span style="color: #78880e; text-decoration: underline;">property</span><span style="color: #78880e;"> </span><span style="color: #921da24c26e6;">"person"</span> <span style="color: #921da24c26e6;">"Bob"</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
</pre>
</div>
<p>
And, as they say, Bob's your uncle! Or even if he isn't, let's see if it works:
</p>
<div class="org-src-container">
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; text-decoration: underline;">org-ql-query</span><span style="color: #3d85b7;"> </span><span style="color: #3d85b7; font-weight: bold;">:select</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">org-get-heading </span><span style="color: #78880e; font-weight: bold;">:no-tags</span><span style="color: #3d85b7;">)</span>
<span style="color: #3d85b7; font-weight: bold;">:from</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; text-decoration: underline;">current-buffer</span><span style="color: #3d85b7;">)</span>
<span style="color: #3d85b7; font-weight: bold;">:where</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">person </span><span style="color: #921da24c26e6;">"Alice"</span> <span style="color: #921da24c26e6;">"Bob"</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
</pre>
</div>
<ul class="org-ul">
<li>[#A] Loud pet parakeet</li>
<li>[#C] Missing sticky notes</li>
<li>[#C] Dirty dishes in sink</li>
<li>[#A] Stinky coffee breath</li>
</ul>
<p>
Yep, same result as the non-normalized query. And look at how much simpler it is to write <code>(person "Alice" "Bob")</code> than to write <code>(or (tags "personAlice" "personBob") (property "person" "Alice") (property "person" "Bob"))</code>.
</p>
</div>
</div>
<div id="outline-container-Non-sexp%20query%20syntax" class="outline-2">
<h2 id="Non-sexp%20query%20syntax">Non-sexp query syntax</h2>
<div class="outline-text-2" id="text-Non-sexp%20query%20syntax">
<p>
But wait, that's not all! If you order now, we'll throw in non-sexp query syntax for free! That's right, your search could be as simple as typing <code>person:Alice,Bob</code>!
</p>
<div class="org-src-container">
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; text-decoration: underline;">org-ql-search</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; text-decoration: underline;">current-buffer</span><span style="color: #3d85b7;">)</span> <span style="color: #73139976b41e;">"person:Alice,Bob"</span><span style="color: #a17e11;">)</span>
</pre>
</div>
<p>
Don't believe me? Well, you see, queries in this syntax are converted to the sexp syntax, like:
</p>
<div class="org-src-container">
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; text-decoration: underline;">org-ql--query-string-to-sexp</span><span style="color: #3d85b7;"> </span><span style="color: #73139976b41e;">"person:Alice,Bob"</span><span style="color: #a17e11;">)</span>
</pre>
</div>
<div class="org-src-container">
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7;">person </span><span style="color: #73139976b41e;">"Alice"</span> <span style="color: #73139976b41e;">"Bob"</span><span style="color: #a17e11;">)</span>
</pre>
</div>
<p>
And that happens automatically when you use a search command like <code>org-ql-search</code>. If you have <code>org-ql</code> installed already, you could even click this link: <a href="person:Alice,Bob">Alice or Bob</a>. Which, in Org syntax, looks like:
</p>
<div class="org-src-container">
<pre class="src src-org"><span style="color: #b58900; text-decoration: underline;"><a href="org-ql-search:person:Alice,Bob">org-ql-search:person:Alice,Bob</a></span>
</pre>
</div>
<p>
And that would open an Agenda Mode buffer that looks like this:
</p>
<pre class="example">
Query: (person "Alice" "Bob") In:meetings.org
[#A] Loud pet parakeet :personAlice:
[#C] Missing sticky notes :personAlice:
[#C] Dirty dishes in sink :personAlice:
[#A] Stinky coffee breath
</pre>
</div>
</div>
<div id="outline-container-Using%20multiple%20predicates" class="outline-2">
<h2 id="Using%20multiple%20predicates">Using multiple predicates</h2>
<div class="outline-text-2" id="text-Using%20multiple%20predicates">
<p>
Oops, you forgot that there's a birthday party in 20 minutes, so you only have time to talk about the highest priority items at this joint meeting today.
</p>
<p>
No problem, let's just select high-priority items:
</p>
<div class="org-src-container">
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; text-decoration: underline;">org-ql-search</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; text-decoration: underline;">current-buffer</span><span style="color: #3d85b7;">)</span> <span style="color: #73139976b41e;">"person:Alice,Bob priority:A"</span><span style="color: #a17e11;">)</span>
</pre>
</div>
<p>
Which shows:
</p>
<pre class="example">
Query: (and (person "Alice" "Bob") (priority "A")) In:meetings.org
[#A] Loud pet parakeet :personAlice:
[#A] Stinky coffee breath
</pre>
</div>
</div>
<div id="outline-container-Predicate%20aliases" class="outline-2">
<h2 id="Predicate%20aliases">Predicate aliases</h2>
<div class="outline-text-2" id="text-Predicate%20aliases">
<p>
And, you know what, if you're just so busy that you don't even have time to type the word <code>person</code>, you can add an abbreviated alias, <code>p</code>, like this:
</p>
<div class="org-src-container">
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; font-weight: bold;">org-ql-defpred</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e;">person p</span><span style="color: #3d85b7;">)</span> <span style="color: #3d85b7;">(</span><span style="color: #78880e;">&amp;rest</span><span style="color: #78880e;"> names</span><span style="color: #3d85b7;">)</span>
<span style="color: #73139976b41e;">"Search for entries about any of NAMES."</span>
<span style="color: #3d85b7; font-weight: bold;">:normalizers</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e;">(</span><span style="color: #3d8b85;">`(</span><span style="color: #a17e11;">,predicate-names . ,names</span><span style="color: #3d8b85;">)</span>
<span style="color: #3d8b85;">`(</span><span style="color: #a17e11; font-weight: bold;">or</span><span style="color: #a17e11;"> (</span><span style="color: #3d85b7; text-decoration: underline;">tags</span><span style="color: #3d85b7;"> ,@(</span><span style="color: #78880e; font-weight: bold;">cl-loop</span><span style="color: #78880e;"> for name in names</span>
<span style="color: #78880e;"> collect (</span><span style="color: #3d8b85; text-decoration: underline;">concat</span><span style="color: #3d8b85;"> </span><span style="color: #65bc957591ca;">"person"</span> <span style="color: #3d8b85;">name</span><span style="color: #78880e;">)</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
<span style="color: #a17e11;">,@(</span><span style="color: #3d85b7; font-weight: bold;">cl-loop</span><span style="color: #3d85b7;"> for name in names</span>
<span style="color: #3d85b7;"> collect `(</span><span style="color: #78880e;">property </span><span style="color: #921da24c26e6;">"person"</span> <span style="color: #78880e;">,name</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span><span style="color: #3d8b85;">)</span><span style="color: #78880e;">)</span><span style="color: #3d85b7;">)</span>
<span style="color: #3d85b7; font-weight: bold;">:body</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; font-weight: bold;">cl-loop</span><span style="color: #78880e;"> for name in names</span>
<span style="color: #78880e;"> thereis (</span><span style="color: #3d8b85; font-weight: bold;">or</span><span style="color: #3d8b85;"> (</span><span style="color: #a17e11; text-decoration: underline;">property</span><span style="color: #a17e11;"> </span><span style="color: #b86396762cce;">"person"</span> <span style="color: #a17e11;">name</span><span style="color: #3d8b85;">)</span>
<span style="color: #3d8b85;">(</span><span style="color: #a17e11; text-decoration: underline;">tags</span><span style="color: #a17e11;"> (</span><span style="color: #3d85b7; text-decoration: underline;">concat</span><span style="color: #3d85b7;"> </span><span style="color: #73139976b41e;">"person"</span> <span style="color: #3d85b7;">name</span><span style="color: #a17e11;">)</span><span style="color: #3d8b85;">)</span><span style="color: #78880e;">)</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
</pre>
</div>
<p>
Let's try it:
</p>
<div class="org-src-container">
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; text-decoration: underline;">org-ql-search</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; text-decoration: underline;">current-buffer</span><span style="color: #3d85b7;">)</span> <span style="color: #73139976b41e;">"p:Alice,Bob priority:A"</span><span style="color: #a17e11;">)</span>
</pre>
</div>
<p>
And that shows:
</p>
<pre class="example">
Query: (and (person "Alice" "Bob") (priority "A")) In:meetings.org
[#A] Loud pet parakeet :personAlice:
[#A] Stinky coffee breath
</pre>
<p>
(It's up to you to remember whether <code>p</code> means <code>person</code> or <code>priority</code>, but code can't solve everything.)
</p>
</div>
</div>
<div id="outline-container-Be%20formless" class="outline-2">
<h2 id="Be%20formless">Be formless</h2>
<div class="outline-text-2" id="text-Be%20formless">
<p>
We can even go a step further: since the normalizer rewrites the query to call the <code>property</code> and <code>tags</code> predicates instead, this <code>person</code> predicate doesn't even need a body form!
</p>
<div class="org-src-container">
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; font-weight: bold;">org-ql-defpred</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e;">person p</span><span style="color: #3d85b7;">)</span> <span style="color: #3d85b7;">(</span><span style="color: #78880e;">&amp;rest</span><span style="color: #78880e;"> names</span><span style="color: #3d85b7;">)</span>
<span style="color: #73139976b41e;">"Search for entries about any of NAMES."</span>
<span style="color: #3d85b7; font-weight: bold;">:normalizers</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e;">(</span><span style="color: #3d8b85;">`(</span><span style="color: #a17e11;">,predicate-names . ,names</span><span style="color: #3d8b85;">)</span>
<span style="color: #3d8b85;">`(</span><span style="color: #a17e11; font-weight: bold;">or</span><span style="color: #a17e11;"> (</span><span style="color: #3d85b7; text-decoration: underline;">tags</span><span style="color: #3d85b7;"> ,@(</span><span style="color: #78880e; font-weight: bold;">cl-loop</span><span style="color: #78880e;"> for name in names</span>
<span style="color: #78880e;"> collect (</span><span style="color: #3d8b85; text-decoration: underline;">concat</span><span style="color: #3d8b85;"> </span><span style="color: #65bc957591ca;">"person"</span> <span style="color: #3d8b85;">name</span><span style="color: #78880e;">)</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
<span style="color: #a17e11;">,@(</span><span style="color: #3d85b7; font-weight: bold;">cl-loop</span><span style="color: #3d85b7;"> for name in names</span>
<span style="color: #3d85b7;"> collect `(</span><span style="color: #78880e;">property </span><span style="color: #921da24c26e6;">"person"</span> <span style="color: #78880e;">,name</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span><span style="color: #3d8b85;">)</span><span style="color: #78880e;">)</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
</pre>
</div>
<p>
Will it still work?
</p>
<div class="org-src-container">
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; text-decoration: underline;">org-ql-query</span><span style="color: #3d85b7;"> </span><span style="color: #3d85b7; font-weight: bold;">:select</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">org-get-heading </span><span style="color: #78880e; font-weight: bold;">:no-tags</span><span style="color: #3d85b7;">)</span>
<span style="color: #3d85b7; font-weight: bold;">:from</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; text-decoration: underline;">current-buffer</span><span style="color: #3d85b7;">)</span>
<span style="color: #3d85b7; font-weight: bold;">:where</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">person </span><span style="color: #921da24c26e6;">"Alice"</span> <span style="color: #921da24c26e6;">"Bob"</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
</pre>
</div>
<ul class="org-ul">
<li>[#A] Loud pet parakeet</li>
<li>[#C] Missing sticky notes</li>
<li>[#C] Dirty dishes in sink</li>
<li>[#A] Stinky coffee breath</li>
</ul>
<p>
It does!
</p>
</div>
</div>
<div id="outline-container-Conclusion" class="outline-2">
<h2 id="Conclusion">Conclusion</h2>
<div class="outline-text-2" id="text-Conclusion">
<p>
In this tutorial, we've gone from having to write lengthy, complex query expressions for accommodating idiosyncratic requirements, to being able to write simple query expressions that abstract away ugly details, to rewriting those query expressions into a more optimal form before a search is even run. The end result is an Org Query Language that is customized to meet your specific needs.
</p>
<p>
What new custom predicates will you write next?
</p>
</div>
</div>
<div id="outline-container-Appendix%3A%20Anaphoric%20macros" class="outline-2">
<h2 id="Appendix%3A%20Anaphoric%20macros">Appendix: Anaphoric macros</h2>
<div class="outline-text-2" id="text-Appendix%3A%20Anaphoric%20macros">
<p>
Finally, if you're a Lisper who appreciates anaphora, you might prefer a more syntactically concise definition of the predicate using Dash macros:
</p>
<div class="org-src-container">
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; font-weight: bold;">org-ql-defpred</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e;">person p</span><span style="color: #3d85b7;">)</span> <span style="color: #3d85b7;">(</span><span style="color: #78880e;">&amp;rest</span><span style="color: #78880e;"> names</span><span style="color: #3d85b7;">)</span>
<span style="color: #73139976b41e;">"Search for entries about any of NAMES."</span>
<span style="color: #3d85b7; font-weight: bold;">:normalizers</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e;">(</span><span style="color: #3d8b85;">`(</span><span style="color: #a17e11;">,predicate-names . ,names</span><span style="color: #3d8b85;">)</span>
<span style="color: #3d8b85;">`(</span><span style="color: #a17e11; font-weight: bold;">or</span><span style="color: #a17e11;"> (</span><span style="color: #3d85b7; text-decoration: underline;">tags</span><span style="color: #3d85b7;"> ,@(</span><span style="color: #78880e; font-weight: bold;">--map</span><span style="color: #78880e;"> `(</span><span style="color: #3d8b85;">concat </span><span style="color: #65bc957591ca;">"person"</span> <span style="color: #3d8b85;">,</span><span style="color: #3d8b85;">it</span><span style="color: #78880e;">)</span> <span style="color: #78880e;">names</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
<span style="color: #a17e11;">,@(</span><span style="color: #3d85b7; font-weight: bold;">--map</span><span style="color: #3d85b7;"> `(</span><span style="color: #78880e;">property </span><span style="color: #921da24c26e6;">"person"</span> <span style="color: #78880e;">,</span><span style="color: #78880e;">it</span><span style="color: #3d85b7;">)</span> <span style="color: #3d85b7;">names</span><span style="color: #a17e11;">)</span><span style="color: #3d8b85;">)</span><span style="color: #78880e;">)</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
</pre>
</div>
<p>
Let's make sure it works:
</p>
<div class="org-src-container">
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; text-decoration: underline;">org-ql-query</span><span style="color: #3d85b7;"> </span><span style="color: #3d85b7; font-weight: bold;">:select</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">org-get-heading </span><span style="color: #78880e; font-weight: bold;">:no-tags</span><span style="color: #3d85b7;">)</span>
<span style="color: #3d85b7; font-weight: bold;">:from</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; text-decoration: underline;">current-buffer</span><span style="color: #3d85b7;">)</span>
<span style="color: #3d85b7; font-weight: bold;">:where</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">person </span><span style="color: #921da24c26e6;">"Alice"</span> <span style="color: #921da24c26e6;">"Bob"</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
</pre>
</div>
<ul class="org-ul">
<li>[#A] Loud pet parakeet</li>
<li>[#C] Missing sticky notes</li>
<li>[#C] Dirty dishes in sink</li>
<li>[#A] Stinky coffee breath</li>
</ul>
<p>
Lisp is fun!
</p>
</div>
</div>
<div id="outline-container-Example%20data" class="outline-2">
<h2 id="Example%20data">Example data</h2>
<div class="outline-text-2" id="text-Example%20data">
</div>
<div id="outline-container-Loud%20pet%20parakeet" class="outline-3">
<h3 id="Loud%20pet%20parakeet">Loud pet parakeet&#xa0;&#xa0;&#xa0;<span class="tag"><span class="personAlice">personAlice</span></span></h3>
</div>
<div id="outline-container-Missing%20sticky%20notes" class="outline-3">
<h3 id="Missing%20sticky%20notes">Missing sticky notes&#xa0;&#xa0;&#xa0;<span class="tag"><span class="personAlice">personAlice</span></span></h3>
<div class="outline-text-3" id="text-Missing%20sticky%20notes">
</div>
</div>
<div id="outline-container-Dirty%20dishes%20in%20sink" class="outline-3">
<h3 id="Dirty%20dishes%20in%20sink">Dirty dishes in sink&#xa0;&#xa0;&#xa0;<span class="tag"><span class="personAlice">personAlice</span></span></h3>
<div class="outline-text-3" id="text-Dirty%20dishes%20in%20sink">
</div>
</div>
<div id="outline-container-Stinky%20coffee%20breath" class="outline-3">
<h3 id="Stinky%20coffee%20breath">Stinky coffee breath</h3>
<div class="outline-text-3" id="text-Stinky%20coffee%20breath">
</div>
</div>
</div>
</div>
<div id="postamble" class="status">
<p class="date">Created: 2020-11-23 Mon 03:31</p>
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
</div>
</body>
</html>

390
examples/defpred.org Normal file
View file

@ -0,0 +1,390 @@
#+TITLE: Org QL Custom Predicates Tutorial
#+OPTIONS: author:nil creator:nil created:nil date:nil num:nil title:t broken-links:t
#+SETUPFILE: export/setup/theme-darksun-local.setup
[2020-11-22 Sun 22:35] Imagine you have weekly meetings with other people, and during the week you take notes about items to discuss at each meeting. When the time for a meeting comes, you want to quickly and easily search for all of the items to discuss at the meeting.
You've been experimenting with different ways to track such data in Org. You've tried using tags, but some of the names in question conflict with other tags in your data (e.g. someone's named Charles, but you also work with a firm named Charles, Inc., and you'd prefer to continue using the tag =Charles= for entries about that firm), so you've been using tags like ~:personNAME:~, which seems awkward. You've tried using a ~:person: NAME~ property on entries, which has the advantage of not cluttering the tags list, but also the disadvantage of not being readily visible in an outline.
So you haven't decided on a long-term solution, but the meetings aren't going to wait--you need to search that data now, and you have a mix of both tags and properties in your entries. What you need is to be able to search for all of the entries about Alice (which you've tagged ~:personAlice:~) when you're meeting with her, and all of the entries about Bob (which have the property ~:person: Bob~) when you're meeting with him. What do you do?
* Contents :noexport:
:PROPERTIES:
:TOC: :include siblings :ignore this
:END:
:CONTENTS:
- [[#using-built-in-predicates][Using built-in predicates]]
- [[#a-custom-person-predicate][A custom (person) predicate]]
- [[#searching-for-multiple-people-at-once][Searching for multiple people at once]]
- [[#normalizing-queries-to-rewrite-arguments][Normalizing queries to rewrite arguments]]
- [[#non-sexp-query-syntax][Non-sexp query syntax]]
- [[#using-multiple-predicates][Using multiple predicates]]
- [[#predicate-aliases][Predicate aliases]]
- [[#be-formless][Be formless]]
- [[#conclusion][Conclusion]]
- [[#appendix-anaphoric-macros][Appendix: Anaphoric macros]]
:END:
* Using built-in predicates
You could start by using built-in Org QL predicates to search your data. For example:
#+BEGIN_SRC elisp :results list :exports both :cache yes
(org-ql-query :select '(org-get-heading :no-tags)
:from (current-buffer)
:where '(or (tags "personAlice")
(property "person" "Bob")))
#+END_SRC
#+RESULTS[91a413cda23cb65d6bb99212e111f283e5a5c910]:
- [#A] Loud pet parakeet
- [#C] Missing sticky notes
- [#C] Dirty dishes in sink
- [#A] Stinky coffee breath
That was easy enough, but it's not very...semantic. You have to think about the implementation details: Alice uses tags, Bob uses properties, and what if Charlie uses both? It starts to feel complicated, and it's a lot to type out every time. Is there an easier way?
* A custom ~(person)~ predicate
Enter =org-ql= custom search predicates. Let's start simple, by defining a predicate to search for just the ~:person:~ property, one person at a time. The predicate will take one argument, a person's name, and search for that property. It would look like this:
#+BEGIN_SRC elisp :results silent :exports code
(org-ql-defpred person (name)
"Search for entries with the \"person\" property being NAME."
:body (property "person" name))
#+END_SRC
Now, let's see what results we get for searching this file for entries about Bob:
#+BEGIN_SRC elisp :results list :exports both :cache yes
(org-ql-query :select '(org-get-heading :no-tags)
:from (current-buffer)
:where '(person "Bob"))
#+END_SRC
#+RESULTS[c11a4ce2c4f179d7487c9b46eff9f72766bc2bc4]:
- [#C] Missing sticky notes
- [#C] Dirty dishes in sink
- [#A] Stinky coffee breath
Hmm, looks like we need to remind Bob to wash his mug and take some mints after lunch. Now what do we need to discuss with Alice?
#+BEGIN_SRC elisp :results list :exports both :cache yes
(org-ql-query :select '(org-get-heading :no-tags)
:from (current-buffer)
:where '(person "Alice"))
#+END_SRC
#+RESULTS[1f12f437042bbc077a4696d707805c1367f2ca3d]:
#+BEGIN_EXAMPLE
#+END_EXAMPLE
Nothing? Oh, right, Alice's entries use the ~:personAlice:~ tag, so we'll also need to search those kind of entries. Let's make the predicate do that, too:
#+BEGIN_SRC elisp :results silent :exports code
(org-ql-defpred person (name)
"Search for entries with the \"person\" property being NAME or having the tag \"personNAME\"."
:body (or (property "person" name)
(tags (concat "person" name))))
#+END_SRC
How about now?
#+BEGIN_SRC elisp :results list :exports both :cache yes
(org-ql-query :select '(org-get-heading :no-tags)
:from (current-buffer)
:where '(person "Alice"))
#+END_SRC
#+RESULTS[1f12f437042bbc077a4696d707805c1367f2ca3d]:
- [#A] Loud pet parakeet
- [#C] Missing sticky notes
- [#C] Dirty dishes in sink
Hmm, I thought we already told her to leave Polly at home.
* Searching for multiple people at once
Oh, wait, this week is shortened due to holidays, so we're having a combined meeting. How do we search for entries about either of them? Well, this is the obvious solution:
#+BEGIN_SRC elisp :results list :exports both :cache yes
(org-ql-query :select '(org-get-heading :no-tags)
:from (current-buffer)
:where '(or (person "Alice")
(person "Bob")))
#+END_SRC
#+RESULTS[4e4c75bde4fbceaadb076a53410c1625d1283e06]:
- [#A] Loud pet parakeet
- [#C] Missing sticky notes
- [#C] Dirty dishes in sink
- [#A] Stinky coffee breath
And that works fine. But it seems like a lot to type. Could we make the =person= predicate accept multiple names instead?
#+BEGIN_SRC elisp :results silent :exports code
(org-ql-defpred person (&rest names)
"Search for entries about any of NAMES."
:body (cl-loop for name in names
thereis (or (property "person" name)
(tags (concat "person" name)))))
#+END_SRC
Now let's search again:
#+BEGIN_SRC elisp :results list :exports both :cache yes
(org-ql-query :select '(org-get-heading :no-tags)
:from (current-buffer)
:where '(person "Alice" "Bob"))
#+END_SRC
#+RESULTS[4f5971c56616f01d8d3c28a66ef380495ee3e158]:
- [#A] Loud pet parakeet
- [#C] Missing sticky notes
- [#C] Dirty dishes in sink
- [#A] Stinky coffee breath
That was easy!
* Normalizing queries to rewrite arguments
Now, all this is well and good if you don't have hundreds of thousands of Org entries in your files. But what if you do? All that =concat='ing happening on every entry could add up, and the query might take a few seconds. What if we could do that stringing-along just once, before running the query? We want to turn our ~(person "Alice" "Bob")~ query into this, with the =:personNAME:= strings already made and the per-person ~(property ...)~ predicates also included:
#+BEGIN_SRC elisp
(or (tags "personAlice" "personBob")
(property "person" "Alice")
(property "person" "Bob"))
#+END_SRC
Can we do that? In fact, we can, by using a query normalizer. Normalizers are =pcase= forms (I /know/) that normalize query expressions before execution. We can use one to rewrite the query ahead of time, like this:
#+BEGIN_SRC elisp :results silent :exports code
(org-ql-defpred person (&rest names)
"Search for entries about any of NAMES."
:normalizers ((`(person . ,names)
`(or (tags ,@(cl-loop for name in names
collect (concat "person" name)))
,@(cl-loop for name in names
collect `(property "person" ,name)))))
:body (cl-loop for name in names
thereis (or (property "person" name)
(tags name))))
#+END_SRC
/NOTE: Normalizers are applied to a query repeatedly until the query is fully normalized, so normalizers should be carefully written to avoid infinite loops. In this example, there is no risk of an infinite loop, because the normalized query no longer contains the ~person~ predicate, so the normalizer only applies to the query once./
Now, don't faint from all the backquoting and unquoting--it's just Lisp, nothing to be afraid of! Let's slow down a moment and see what the normalized query looks like to be sure we're doing it correctly:
#+BEGIN_SRC elisp :results code :exports both :cache yes
(org-ql--normalize-query '(person "Alice" "Bob"))
#+END_SRC
#+RESULTS[ebc46fff31b72359353dda539a26c95b7d650df2]:
#+BEGIN_SRC elisp
(or (tags "personAlice" "personBob")
(property "person" "Alice")
(property "person" "Bob"))
#+END_SRC
And, as they say, Bob's your uncle! Or even if he isn't, let's see if it works:
#+BEGIN_SRC elisp :results list :exports both :cache yes
(org-ql-query :select '(org-get-heading :no-tags)
:from (current-buffer)
:where '(person "Alice" "Bob"))
#+END_SRC
#+RESULTS[4f5971c56616f01d8d3c28a66ef380495ee3e158]:
- [#A] Loud pet parakeet
- [#C] Missing sticky notes
- [#C] Dirty dishes in sink
- [#A] Stinky coffee breath
Yep, same result as the non-normalized query. And look at how much simpler it is to write ~(person "Alice" "Bob")~ than to write ~(or (tags "personAlice" "personBob") (property "person" "Alice") (property "person" "Bob"))~.
* Non-sexp query syntax
But wait, that's not all! If you order now, we'll throw in non-sexp query syntax for free! That's right, your search could be as simple as typing ~person:Alice,Bob~!
#+BEGIN_SRC elisp :results none :exports code
(org-ql-search (current-buffer) "person:Alice,Bob")
#+END_SRC
Don't believe me? Well, you see, queries in this syntax are converted to the sexp syntax, like:
#+BEGIN_SRC elisp :results code :exports both :cache yes
(org-ql--query-string-to-sexp "person:Alice,Bob")
#+END_SRC
#+RESULTS[a60655544956644605c23c152570185c329faa87]:
#+BEGIN_SRC elisp
(person "Alice" "Bob")
#+END_SRC
And that happens automatically when you use a search command like =org-ql-search=. If you have =org-ql= installed already, you could even click this link: [[org-ql-search:person:Alice,Bob][Alice or Bob]]. Which, in Org syntax, looks like:
#+BEGIN_SRC org
[[org-ql-search:person:Alice,Bob]]
#+END_SRC
And that would open an Agenda Mode buffer that looks like this:
#+BEGIN_EXAMPLE
Query: (person "Alice" "Bob") In:meetings.org
[#A] Loud pet parakeet :personAlice:
[#C] Missing sticky notes :personAlice:
[#C] Dirty dishes in sink :personAlice:
[#A] Stinky coffee breath
#+END_EXAMPLE
* Using multiple predicates
Oops, you forgot that there's a birthday party in 20 minutes, so you only have time to talk about the highest priority items at this joint meeting today.
No problem, let's just select high-priority items:
#+BEGIN_SRC elisp :results silent :exports code
(org-ql-search (current-buffer) "person:Alice,Bob priority:A")
#+END_SRC
Which shows:
#+BEGIN_EXAMPLE
Query: (and (person "Alice" "Bob") (priority "A")) In:meetings.org
[#A] Loud pet parakeet :personAlice:
[#A] Stinky coffee breath
#+END_EXAMPLE
* Predicate aliases
And, you know what, if you're just so busy that you don't even have time to type the word =person=, you can add an abbreviated alias, =p=, like this:
#+BEGIN_SRC elisp :results silent :exports code
(org-ql-defpred (person p) (&rest names)
"Search for entries about any of NAMES."
:normalizers ((`(,predicate-names . ,names)
`(or (tags ,@(cl-loop for name in names
collect (concat "person" name)))
,@(cl-loop for name in names
collect `(property "person" ,name)))))
:body (cl-loop for name in names
thereis (or (property "person" name)
(tags (concat "person" name)))))
#+END_SRC
Let's try it:
#+BEGIN_SRC elisp :results silent :exports code
(org-ql-search (current-buffer) "p:Alice,Bob priority:A")
#+END_SRC
And that shows:
#+BEGIN_EXAMPLE
Query: (and (person "Alice" "Bob") (priority "A")) In:meetings.org
[#A] Loud pet parakeet :personAlice:
[#A] Stinky coffee breath
#+END_EXAMPLE
(It's up to you to remember whether =p= means =person= or =priority=, but code can't solve everything.)
* Be formless
We can even go a step further: since the normalizer rewrites the query to call the =property= and =tags= predicates instead, this =person= predicate doesn't even need a body form!
#+BEGIN_SRC elisp :results silent :exports code
(org-ql-defpred (person p) (&rest names)
"Search for entries about any of NAMES."
:normalizers ((`(,predicate-names . ,names)
`(or (tags ,@(cl-loop for name in names
collect (concat "person" name)))
,@(cl-loop for name in names
collect `(property "person" ,name))))))
#+END_SRC
Will it still work?
#+BEGIN_SRC elisp :results list :exports both :cache yes
(org-ql-query :select '(org-get-heading :no-tags)
:from (current-buffer)
:where '(person "Alice" "Bob"))
#+END_SRC
#+RESULTS[4f5971c56616f01d8d3c28a66ef380495ee3e158]:
- [#A] Loud pet parakeet
- [#C] Missing sticky notes
- [#C] Dirty dishes in sink
- [#A] Stinky coffee breath
It does!
* Conclusion
In this tutorial, we've gone from having to write lengthy, complex query expressions for accommodating idiosyncratic requirements, to being able to write simple query expressions that abstract away ugly details, to rewriting those query expressions into a more optimal form before a search is even run. The end result is an Org Query Language that is customized to meet your specific needs.
What new custom predicates will you write next?
* Appendix: Anaphoric macros
Finally, if you're a Lisper who appreciates anaphora, you might prefer a more syntactically concise definition of the predicate using Dash macros:
#+BEGIN_SRC elisp :results silent :exports code
(org-ql-defpred (person p) (&rest names)
"Search for entries about any of NAMES."
:normalizers ((`(,predicate-names . ,names)
`(or (tags ,@(--map (concat "person" it) names))
,@(--map `(property "person" ,it) names)))))
#+END_SRC
Let's make sure it normalizes correctly:
#+BEGIN_SRC elisp :results code :exports both :cache yes
(org-ql--normalize-query '(person "Alice" "Bob"))
#+END_SRC
#+RESULTS[ebc46fff31b72359353dda539a26c95b7d650df2]:
#+BEGIN_SRC elisp
(or (tags "personAlice" "personBob")
(property "person" "Alice")
(property "person" "Bob"))
#+END_SRC
It does, so the query also produces the correct results:
#+BEGIN_SRC elisp :results list :exports both :cache yes
(org-ql-query :select '(org-get-heading :no-tags)
:from (current-buffer)
:where '(person "Alice" "Bob"))
#+END_SRC
#+RESULTS[4f5971c56616f01d8d3c28a66ef380495ee3e158]:
- [#A] Loud pet parakeet
- [#C] Missing sticky notes
- [#C] Dirty dishes in sink
- [#A] Stinky coffee breath
Lisp is fun!
* Example data
:PROPERTIES:
:TOC: :ignore (this descendants)
:END:
** [#A] Loud pet parakeet :personAlice:
** [#C] Missing sticky notes :personAlice:
:PROPERTIES:
:person: Bob
:END:
** [#C] Dirty dishes in sink :personAlice:
:PROPERTIES:
:person: Bob
:END:
** [#A] Stinky coffee breath
:PROPERTIES:
:person: Bob
:END:

View file

@ -0,0 +1,17 @@
# -*- mode: org; -*-
# The files that hide sections and display a navbar and ToC are commented out.
# #+HTML_HEAD: <link rel="stylesheet" type="text/css" href="export/styles/darksun/css/htmlize.css"/>
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="export/styles/darksun/css/darksun.css"/>
# #+HTML_HEAD: <link rel="stylesheet" type="text/css" href="export/styles/darksun/css/hideshow.css"/>
#+HTML_HEAD: <script type="text/javascript" src="export/styles/darksun/js/jquery-1.11.0.min.js"></script>
#+HTML_HEAD: <script type="text/javascript" src="export/styles/darksun/js/jquery-ui-1.10.2.min.js"></script>
#+HTML_HEAD: <script type="text/javascript" src="export/styles/darksun/js/jquery.localscroll-min.js"></script>
#+HTML_HEAD: <script type="text/javascript" src="export/styles/darksun/js/jquery.scrollTo-1.4.3.1-min.js"></script>
#+HTML_HEAD: <script type="text/javascript" src="export/styles/darksun/js/jquery.zclip.min.js"></script>
#+HTML_HEAD: <script type="text/javascript" src="export/styles/darksun/js/darksun.js"></script>
# #+HTML_HEAD: <script type="text/javascript" src="export/styles/darksun/js/hideshow.js"></script>
#+HTML_HEAD: <script type="text/javascript" src="export/styles/lib/js/jquery.stickytableheaders.min.js"></script>

View file

@ -0,0 +1,15 @@
# -*- mode: org; -*-
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="http://www.pirilampo.org/styles/darksun/css/htmlize.css"/>
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="http://www.pirilampo.org/styles/darksun/css/darksun.css"/>
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="http://www.pirilampo.org/styles/darksun/css/hideshow.css"/>
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/darksun/js/jquery-1.11.0.min.js"></script>
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/darksun/js/jquery-ui-1.10.2.min.js"></script>
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/darksun/js/jquery.localscroll-min.js"></script>
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/darksun/js/jquery.scrollTo-1.4.3.1-min.js"></script>
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/darksun/js/jquery.zclip.min.js"></script>
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/darksun/js/darksun.js"></script>
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/darksun/js/hideshow.js"></script>
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/lib/js/jquery.stickytableheaders.min.js"></script>

View file

@ -0,0 +1,264 @@
* {
border-color: #657b83;
}
a {
color: #268bd2 !important;
}
a:visited {
color: #6c71c4 !important;
}
body {
background-color: #002b36 !important;
color: #839496 !important;
font-family: Libre Baskerville, serif;
}
html {
background-color: #002b36 !important;
}
input,
textarea {
background-color: #073642 !important;
color: #839496 !important;
}
blockquote,
code,
pre {
background-color: #073642 !important;
border: 1px solid #094352 !important;
border-radius: 2px;
box-shadow: none;
color: #839496 !important;
}
code {
font-size: 1.2em;
}
img {
margin: 0.5em;
}
.buttons {
background-color: #073642 !important;
color: #93a1a1 !important;
font-family: sans-serif;
font-size: 1.5rem;
}
.hsReviewPanel {
display: none;
}
.title {
border: 0;
}
#postamble {
display: none;
}
#banner {
text-align: center;
}
#tabs {
background-color: #073642 !important;
float: left;
margin: 0px 0px 20px 0px;
padding: 0;
width: 100%;
font-family: sans-serif;
}
#tabs ul {
margin: 0;
padding: 0;
}
#tabs li {
float: left;
list-style-type: none;
margin: 0px 2px 0px 0px;
padding: 0px 0px 0px 0px;
white-space: nowrap;
}
#tabs li a {
display: block;
font-size: 120%;
font-weight: bold;
margin: 0;
padding: 4px 10px 4px 10px;
text-decoration: none;
}
#tabs li a:hover {
color: #90c5eb !important;
}
#tabs li.ui-tabs-active a {
background-color: #094352 !important;
color: #59a9e1 !important;
}
#content {
clear: both;
width: 80%;
}
#content > p {
margin: 1em;
}
#content > div > h2 {
margin: 0.25rem;
}
#postamble {
text-align: right;
}
blockquote {
background-color: #073642 !important;
padding-left: 0.75em;
padding-right: 0.75em;
padding-top: 0.01em;
padding-bottom: 0.01em;
overflow: hidden;
margin-left: 0;
}
.outline-text-2,
.outline-text-3,
.outline-text-4,
.outline-text-5,
.outline-text-6 {
padding-left: 4%;
}
.outline-3 {
padding-left: 4%;
}
.outline-4 {
padding-left: 4%;
}
.outline-5 {
padding-left: 4%;
}
.outline-6 {
padding-left: 4%;
}
h1,
h2,
h3,
h4,
h5,
h6 {
font-family: sans-serif;
border-bottom: 2px solid;
border-color: #094352 !important;
}
a:hover {
text-decoration: underline;
}
#search {
display: block;
float: right;
}
.tag {
background-color: #002b36 !important;
color: #93a1a1 !important;
border: 0px;
}
.tag span {
background-color: #094352 !important;
margin: 0.25em;
padding: 0.25em;
}
#table-of-contents {
display: table;
float: right;
}
#table-of-contents h2 {
display: none;
}
#table-of-contents li {
list-style-type: none;
}
#table-of-contents a:hover {
text-decoration: underline;
}
#minitoc {
background-color: #073642 !important;
position: fixed;
top: 0px;
right: -5px;
padding: 0.5em;
z-index: 200;
width: 18%;
word-wrap: normal;
overflow: hidden;
}
#minitoc ul {
margin: 0.5em;
padding-left: 1em;
}
#minitoc h2 {
margin-top: 0;
margin-bottom: 0;
font-size: 110%;
}
#minitoc a {
display: block;
font-family: sans-serif;
text-decoration: none;
}
#minitoc a:hover {
text-decoration: underline;
}
/* #minitoc a { */
/* display: none; */
/* } */
#minitoc:hover a {
display: block;
}
#toTop {
top: -100px;
position: fixed;
text-align: center;
z-index: 999;
display: none;
}
#toTop:hover {
text-decoration: underline;
}
#left-panel-wrapper {
display: none;
position: fixed;
z-index: 200;
}
#left-panel-contents {
display: none;
position: fixed;
text-align: left;
top: 0;
z-index: 200;
}
#left-panel-button {
transform: rotate(90deg);
left: -23px;
position: fixed;
top: 50%;
z-index: 200;
}
#right-panel-wrapper {
position: fixed;
z-index: 200;
}
#right-panel-contents {
display: none;
z-index: 200;
position: fixed;
text-align: left;
top: 0;
}
.snippet-copy-to-clipboard {
display: none;
position: absolute;
left: 50px;
top: 50px;
}
.org-ol > li,
.org-dl > dt {
margin-top: 0.5em;
}
.org-ul {
margin-top: 1em;
margin-bottom: 1em;
}
.org-ul li {
margin-top: 0.5em;
}
.org-ul > li > a {
font-family: sans-serif;
}

View file

@ -0,0 +1,110 @@
/* hideshow.css --- HideShow CSS file */
/* Copyright (C) 2014 All Right Reserved, Fabrice Niessen */
/* This file is free software: you can redistribute it and/or */
/* modify it under the terms of the GNU General Public License as */
/* published by the Free Software Foundation, either version 3 of */
/* the License, or (at your option) any later version. */
/* This file is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* Author: Fabrice Niessen <(concat "fniessen" at-sign "pirilampo.org")> */
/* URL: https://github.com/fniessen/hide-show/ */
/* Version: 20140912.1722 */
.hsExpanded.hsAnchor {background: #EE7700;}
.buttons {
padding: 0px 7px 13px 0px;
background: #0A3F69;
}
.hsButton {
color: white;
float: right;
font-size: 70%;
margin-left: 10px;
}
.hsButton:hover {
text-decoration: underline;
cursor: pointer;
}
.ellipsis {
color: #999999;
/* background-color: #FFF8C0; */
/* float: right; */
margin-left: 0.6em;
}
.hsReview {
border: 1px solid #A4A4A4;
background-color: white;
z-index: 500; /* must be greater then z-index of hsOverlay */
position: relative; /* required for z-index to work */
}
#hsOverlay {
width: 100%;
height: 100%;
position: fixed;
left: 0px;
top: 0px;
background-color: #000;
opacity: .70;
z-index: 250; /* must be greater than any other z-index (except the one for .hsReview */
}
.hsReviewPanel {
background-color: #757176;
color: white;
line-height: 1.1em;
margin: 10px 0px;
padding: 10px;
position: fixed;
width: auto;
bottom: 0px;
right: 0px;
z-index: 501;
text-align: center;
}
.hsReviewPanel.hsReviewing {
display: none;
}
.hsReviewPanel:hover {
cursor: pointer;
}
.hsReviewingPanel {
background-color: white;
color: #757176;
line-height: 1.1em;
margin: 10px 0px;
padding: 10px;
position: fixed;
width: auto;
bottom: 0px;
right: 0px;
z-index: 501;
text-align: center;
}
.hsReviewButton:hover {
cursor: pointer;
}
.hsUnselectable {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}

View file

@ -0,0 +1,145 @@
.org-bold { /* bold */ font-weight: bold; }
.org-bold-italic { /* bold-italic */ font-weight: bold; font-style: italic; }
.org-buffer-menu-buffer { /* buffer-menu-buffer */ font-weight: bold; }
.org-builtin { /* font-lock-builtin-face */ color: #7a378b; }
.org-button { /* button */ text-decoration: underline; }
.org-calendar-today { /* calendar-today */ text-decoration: underline; }
.org-change-log-acknowledgement { /* change-log-acknowledgement */ color: #b22222; }
.org-change-log-conditionals { /* change-log-conditionals */ color: #a0522d; }
.org-change-log-date { /* change-log-date */ color: #8b2252; }
.org-change-log-email { /* change-log-email */ color: #a0522d; }
.org-change-log-file { /* change-log-file */ color: #0000ff; }
.org-change-log-function { /* change-log-function */ color: #a0522d; }
.org-change-log-list { /* change-log-list */ color: #a020f0; }
.org-change-log-name { /* change-log-name */ color: #008b8b; }
.org-comint-highlight-input { /* comint-highlight-input */ font-weight: bold; }
.org-comint-highlight-prompt { /* comint-highlight-prompt */ color: #00008b; }
.org-comment { /* font-lock-comment-face */ color: #b22222; }
.org-comment-delimiter { /* font-lock-comment-delimiter-face */ color: #b22222; }
.org-completions-annotations { /* completions-annotations */ font-style: italic; }
.org-completions-common-part { /* completions-common-part */ color: #000000; background-color: #ffffff; }
.org-completions-first-difference { /* completions-first-difference */ font-weight: bold; }
.org-constant { /* font-lock-constant-face */ color: #008b8b; }
.org-diary { /* diary */ color: #ff0000; }
.org-diff-context { /* diff-context */ color: #7f7f7f; }
.org-diff-file-header { /* diff-file-header */ background-color: #b3b3b3; font-weight: bold; }
.org-diff-function { /* diff-function */ background-color: #cccccc; }
.org-diff-header { /* diff-header */ background-color: #cccccc; }
.org-diff-hunk-header { /* diff-hunk-header */ background-color: #cccccc; }
.org-diff-index { /* diff-index */ background-color: #b3b3b3; font-weight: bold; }
.org-diff-nonexistent { /* diff-nonexistent */ background-color: #b3b3b3; font-weight: bold; }
.org-diff-refine-change { /* diff-refine-change */ background-color: #d9d9d9; }
.org-dired-directory { /* dired-directory */ color: #0000ff; }
.org-dired-flagged { /* dired-flagged */ color: #ff0000; font-weight: bold; }
.org-dired-header { /* dired-header */ color: #228b22; }
.org-dired-ignored { /* dired-ignored */ color: #7f7f7f; }
.org-dired-mark { /* dired-mark */ color: #008b8b; }
.org-dired-marked { /* dired-marked */ color: #ff0000; font-weight: bold; }
.org-dired-perm-write { /* dired-perm-write */ color: #b22222; }
.org-dired-symlink { /* dired-symlink */ color: #a020f0; }
.org-dired-warning { /* dired-warning */ color: #ff0000; font-weight: bold; }
.org-doc { /* font-lock-doc-face */ color: #8b2252; }
.org-escape-glyph { /* escape-glyph */ color: #a52a2a; }
.org-file-name-shadow { /* file-name-shadow */ color: #7f7f7f; }
.org-flyspell-duplicate { /* flyspell-duplicate */ color: #cdad00; font-weight: bold; text-decoration: underline; }
.org-flyspell-incorrect { /* flyspell-incorrect */ color: #ff4500; font-weight: bold; text-decoration: underline; }
.org-fringe { /* fringe */ background-color: #f2f2f2; }
.org-function-name { /* font-lock-function-name-face */ color: #0000ff; }
.org-header-line { /* header-line */ color: #333333; background-color: #e5e5e5; }
.org-help-argument-name { /* help-argument-name */ font-style: italic; }
.org-highlight { /* highlight */ background-color: #b4eeb4; }
.org-holiday { /* holiday */ background-color: #ffc0cb; }
.org-isearch { /* isearch */ color: #b0e2ff; background-color: #cd00cd; }
.org-isearch-fail { /* isearch-fail */ background-color: #ffc1c1; }
.org-italic { /* italic */ font-style: italic; }
.org-keyword { /* font-lock-keyword-face */ color: #a020f0; }
.org-lazy-highlight { /* lazy-highlight */ background-color: #afeeee; }
.org-link { /* link */ color: #0000ff; text-decoration: underline; }
.org-link-visited { /* link-visited */ color: #8b008b; text-decoration: underline; }
.org-log-edit-header { /* log-edit-header */ color: #a020f0; }
.org-log-edit-summary { /* log-edit-summary */ color: #0000ff; }
.org-log-edit-unknown-header { /* log-edit-unknown-header */ color: #b22222; }
.org-match { /* match */ background-color: #ffff00; }
.org-next-error { /* next-error */ background-color: #eedc82; }
.org-nobreak-space { /* nobreak-space */ color: #a52a2a; text-decoration: underline; }
.org-org-archived { /* org-archived */ color: #7f7f7f; }
.org-org-block { /* org-block */ color: #7f7f7f; }
.org-org-block-begin-line { /* org-block-begin-line */ color: #b22222; }
.org-org-block-end-line { /* org-block-end-line */ color: #b22222; }
.org-org-checkbox { /* org-checkbox */ font-weight: bold; }
.org-org-checkbox-statistics-done { /* org-checkbox-statistics-done */ color: #228b22; font-weight: bold; }
.org-org-checkbox-statistics-todo { /* org-checkbox-statistics-todo */ color: #ff0000; font-weight: bold; }
.org-org-clock-overlay { /* org-clock-overlay */ background-color: #ffff00; }
.org-org-code { /* org-code */ color: #7f7f7f; }
.org-org-column { /* org-column */ background-color: #e5e5e5; }
.org-org-column-title { /* org-column-title */ background-color: #e5e5e5; font-weight: bold; text-decoration: underline; }
.org-org-date { /* org-date */ color: #a020f0; text-decoration: underline; }
.org-org-document-info { /* org-document-info */ color: #191970; }
.org-org-document-info-keyword { /* org-document-info-keyword */ color: #7f7f7f; }
.org-org-document-title { /* org-document-title */ color: #191970; font-size: 144%; font-weight: bold; }
.org-org-done { /* org-done */ color: #228b22; font-weight: bold; }
.org-org-drawer { /* org-drawer */ color: #0000ff; }
.org-org-ellipsis { /* org-ellipsis */ color: #b8860b; text-decoration: underline; }
.org-org-footnote { /* org-footnote */ color: #a020f0; text-decoration: underline; }
.org-org-formula { /* org-formula */ color: #b22222; }
.org-org-headline-done { /* org-headline-done */ color: #bc8f8f; }
.org-org-hide { /* org-hide */ color: #ffffff; }
.org-org-latex-and-export-specials { /* org-latex-and-export-specials */ color: #8b4513; }
.org-org-level-1 { /* org-level-1 */ color: #0000ff; }
.org-org-level-2 { /* org-level-2 */ color: #a0522d; }
.org-org-level-3 { /* org-level-3 */ color: #a020f0; }
.org-org-level-4 { /* org-level-4 */ color: #b22222; }
.org-org-level-5 { /* org-level-5 */ color: #228b22; }
.org-org-level-6 { /* org-level-6 */ color: #008b8b; }
.org-org-level-7 { /* org-level-7 */ color: #7a378b; }
.org-org-level-8 { /* org-level-8 */ color: #8b2252; }
.org-org-link { /* org-link */ color: #0000ff; text-decoration: underline; }
.org-org-meta-line { /* org-meta-line */ color: #b22222; }
.org-org-mode-line-clock { /* org-mode-line-clock */ color: #000000; background-color: #bfbfbf; }
.org-org-mode-line-clock-overrun { /* org-mode-line-clock-overrun */ color: #000000; background-color: #ff0000; }
.org-org-quote { /* org-quote */ color: #7f7f7f; }
.org-org-scheduled { /* org-scheduled */ color: #006400; }
.org-org-scheduled-previously { /* org-scheduled-previously */ color: #b22222; }
.org-org-scheduled-today { /* org-scheduled-today */ color: #006400; }
.org-org-sexp-date { /* org-sexp-date */ color: #a020f0; }
.org-org-special-keyword { /* org-special-keyword */ color: #a020f0; }
.org-org-table { /* org-table */ color: #0000ff; }
.org-org-tag { /* org-tag */ font-weight: bold; }
.org-org-target { /* org-target */ text-decoration: underline; }
.org-org-time-grid { /* org-time-grid */ color: #b8860b; }
.org-org-todo { /* org-todo */ color: #ff0000; font-weight: bold; }
.org-org-upcoming-deadline { /* org-upcoming-deadline */ color: #b22222; }
.org-org-verbatim { /* org-verbatim */ color: #7f7f7f; }
.org-org-verse { /* org-verse */ color: #7f7f7f; }
.org-org-warning { /* org-warning */ color: #ff0000; font-weight: bold; }
.org-outline-1 { /* outline-1 */ color: #0000ff; }
.org-outline-2 { /* outline-2 */ color: #a0522d; }
.org-outline-3 { /* outline-3 */ color: #a020f0; }
.org-outline-4 { /* outline-4 */ color: #b22222; }
.org-outline-5 { /* outline-5 */ color: #228b22; }
.org-outline-6 { /* outline-6 */ color: #008b8b; }
.org-outline-7 { /* outline-7 */ color: #7a378b; }
.org-outline-8 { /* outline-8 */ color: #8b2252; }
.org-preprocessor { /* font-lock-preprocessor-face */ color: #7a378b; }
.org-query-replace { /* query-replace */ color: #b0e2ff; background-color: #cd00cd; }
.org-regexp-grouping-backslash { /* font-lock-regexp-grouping-backslash */ font-weight: bold; }
.org-regexp-grouping-construct { /* font-lock-regexp-grouping-construct */ font-weight: bold; }
.org-region { /* region */ background-color: #eedc82; }
.org-secondary-selection { /* secondary-selection */ background-color: #ffff00; }
.org-shadow { /* shadow */ color: #7f7f7f; }
.org-show-paren-match { /* show-paren-match */ background-color: #40e0d0; }
.org-show-paren-mismatch { /* show-paren-mismatch */ color: #ffffff; background-color: #a020f0; }
.org-string { /* font-lock-string-face */ color: #8b2252; }
.org-tool-bar { /* tool-bar */ color: #000000; background-color: #bfbfbf; }
.org-tooltip { /* tooltip */ color: #000000; background-color: #ffffe0; }
.org-trailing-whitespace { /* trailing-whitespace */ background-color: #ff0000; }
.org-type { /* font-lock-type-face */ color: #228b22; }
.org-underline { /* underline */ text-decoration: underline; }
.org-variable-name { /* font-lock-variable-name-face */ color: #a0522d; }
.org-warning { /* font-lock-warning-face */ color: #ff0000; font-weight: bold; }
.org-widget-button { /* widget-button */ font-weight: bold; }
.org-widget-button-pressed { /* widget-button-pressed */ color: #ff0000; }
.org-widget-documentation { /* widget-documentation */ color: #006400; }
.org-widget-field { /* widget-field */ background-color: #d9d9d9; }
.org-widget-inactive { /* widget-inactive */ color: #7f7f7f; }
.org-widget-single-line-field { /* widget-single-line-field */ background-color: #d9d9d9; }

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 625 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View file

@ -0,0 +1,524 @@
// darksun.js --- darksun JS file
//
// Copyright (C) 2011-2016 All Right Reserved, Fabrice Niessen
//
// This file is free software: you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// This file is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// Author: Fabrice Niessen <(concat "fniessen" at-sign "pirilampo.org")>
// URL: https://github.com/fniessen/org-html-themes/
// Version: 20140515.1841
$(function() {
$('p').
html(function(index, old) {
return old.replace('FIXME',
'<span class="fixme">FIXME</span>');
});
$('p').
html(function(index, old) {
return old.replace('XXX',
'<span class="fixme">XXX</span>');
});
});
// Remove leading section number
$(function() {
$('.section-number-2').text("");
for (var i = 3; i <= 5; i++) {
$('.section-number-' + i).each(function() {
$(this).text($(this).text().replace(/^[0-9]+\./g, ""));
});
}
});
$(function() {
$('<div id="minitoc" class="dontprint"></div>').prependTo('body');
});
// generate contents of minitoc
function generateMiniToc(divId) {
$('#minitoc-content').empty().append('<h2>In this section</h2><ul></ul>');
$('#' + divId).find('h3').each(function(i) {
// [2018-09-03 Mon 03:48] Get text up to non-breaking space,
// to omit the tags. If there are no tags, there will be no
// &nbsp;, so get all the text. (This fixes a bug in the
// original code.)
let text = null;
let pos = $(this).text().search(/ | ►/);
if (pos > 0) {
text = $(this).text().substring(0, pos);
}
else {
text = $(this).text();
}
$("#minitoc-content>ul").append("<li><a href='#" + $(this).attr("id") + "'>"
+ text + "</a></li>");
});
// Ensure that the target is expanded (hideShow)
$('#minitoc-content a[href^="#"]').click(function() {
var href = $(this).attr('href');
hsExpandAnchor(href);
});
}
// display tabs
function tabifySections() {
// hide TOC (if present)
$('#table-of-contents').hide();
// grab the list of `h2' from the page
var allSections = [];
$('h2')
.each(function() {
// Remove TODO keywords and tags (contained in spans)
var tabText = $(this).clone().find('span').remove().end()
.text().trim();
var tabId = $(this).parent().attr('id');
if (tabText) {
// - remove heading number (all leading digits)
// - remove progress logging (between square brackets)
// - remove leading and trailing spaces
tabText = tabText.replace(/^\d+\s+/, '').replace(/\[[\d/%]+\]/, '').trim();
allSections.push({
text: tabText,
id: tabId
});
}
});
// create the tab links
var tabs = $('<ul id="tabs"></ul>');
for (i = 0; i < allSections.length; i++) {
var item = allSections[i];
html = $('<li><a href="#' + item.id + '">' + item.text + '</a></li>');
tabs.append(html);
}
// insert tabs menu after title (`h1'), or at the beginning of the content
if($('.title').length !== 0) {
$('.title').after(tabs);
}
else {
$('#content').prepend(tabs);
}
}
function selectTabAndScroll(href) {
// At this point we assume that href is local (starts with #)
// alert(href);
// Find the tab to activate
var targetTab = $(href).closest('.ui-tabs-panel');
var targetTabId = targetTab.attr('id');
var targetTabAriaLabel = targetTab.attr('aria-labelledby');
var targetTabIndex = $("#content ul li")
.index($('[aria-labelledby="' + targetTabAriaLabel + '"]'));
// Activate target tab
$('#content').tabs('option', 'active', targetTabIndex);
// Rebuild minitoc
generateMiniToc(targetTabId);
// Set the location hash
// document.location.hash = href;
// Scroll to top if href was a tab
if (href == '#' + targetTabId) {
// alert(targetTabId);
$.scrollTo(0);
}
// Scroll to href if href was not a tab
else {
$.scrollTo(href);
}
}
$(document).ready(function() {
$('#preamble').remove();
$('#table-of-contents').remove();
// Initialize hideShow
hsInit();
// Prepare for tabs
tabifySections();
// Build the tabs from the #content div
$('#content').tabs();
// Set default animation
$('#content').tabs('option', 'show', true);
// Rebuild minitoc when a tab is activated
$('#content').tabs({
activate: function(event, ui) {
var divId = ui.newTab.attr('aria-controls');
generateMiniToc(divId);
}
});
// Required to get the link of the tab in URL
$('#content ul').localScroll({
target: '#content',
duration: 0,
hash: true
});
// Handle hash in URL
if ($('#content') && document.location.hash) {
hsExpandAnchor(document.location.hash);
selectTabAndScroll(document.location.hash);
}
// If no hash, build the minitoc anyway for selected tab
else {
var divId = $('#content div[aria-expanded=true]').attr('id');
generateMiniToc(divId);
}
// Handle click on internal links
$('.ui-tabs-panel a[href^="#"]').click(function(e) {
var href = $(this).attr('href');
hsExpandAnchor(href);
selectTabAndScroll(href);
e.preventDefault();
});
// add sticky headers to tables
$('table').stickyTableHeaders();
});
function copyToClipboard(text)
{
if (window.clipboardData && window.clipboardData.setData) { // Internet Explorer
window.clipboardData.setData("Text", text);
}
else { // Fallback solution
window.prompt("Copy to clipboard: Ctrl+C, Enter", text);
}
}
$(document).ready(function() {
// Assuming that the ZeroClipboard swf file is in the same folder than darksun,
// get the path to it (it will be relative to the current page location).
var bbScriptPath = $('script[src$="darksun.js"]').attr('src'); // the js file path
var bbPathToZeroClipboardSwf = bbScriptPath.replace('darksun.js', 'ZeroClipboard.swf');
// Add copy to clipboard snippets
$('.org-src-container').prepend('<div class="snippet-copy-to-clipboard"><span class="copy-to-clipboard-button">[copy]</span></div>');
// Display/hide snippets on source block mouseenter/mouseleave
$(document).on('mouseenter', '.org-src-container', function () {
$(this).find('.snippet-copy-to-clipboard').show();
// Need to call zclip here, once the button is visible.
// Beacause when the button is not visible, zclip does nothing.
if ((window.location.protocol != 'file:') && ($(this).find('.zclip').length == 0)) {
$(this).find('.copy-to-clipboard-button').zclip({
//path: 'http://www.steamdev.com/zclip/js/ZeroClipboard.swf',
//path: 'styles/darksun/js/ZeroClipboard.swf',
path: bbPathToZeroClipboardSwf,
copy: function() {
return $(this).parent().parent().find('.src').text();
}
});
}
}).on('mouseleave', '.org-src-container', function () {
$(this).find('.snippet-copy-to-clipboard').hide();
});
// Handle copy to clipboard (here, for a local file only 'file://...'
if (window.location.protocol == 'file:') { // if local file use browser-specific code
$('.copy-to-clipboard-button').click(function() {
// Get the text to be copied
var text = $(this).parent().parent().find('.src').text();
text = text.replace(/\n/g, "\r\n");
// alert(text);
copyToClipboard(text);
});
}
});
$(function() {
$('li > code :contains("[X]")')
.parent()
.addClass('checked')
.end()
.remove();
$('li > code :contains("[-]")')
.parent()
.addClass('halfchecked')
.end()
.remove();
$('li > code :contains("[ ]")')
.parent()
.addClass('unchecked')
.end()
.remove();
});
$(function() {
$('i :contains("[#A]")')
.replaceWith('<i><span style="color: #F67777;">[#A]</span></i>');
$('i :contains("[#B]")')
.replaceWith('<i><span style="color: #B6E864;">[#B]</span></i>');
$('i :contains("[#C]")')
.replaceWith('<i><span style="color: #C3DCFF;">[#C]</span></i>');
});
function togglePanel(e) {
e.preventDefault();
$("#left-panel-contents").toggleClass('active').toggle(200);
$("#right-panel-contents").toggleClass('active').toggle(200);
var slidePos =
$("#left-panel-button").css("left") == "-23px"? '182px': '-23px';
$("#left-panel-button").
animate({"left": slidePos, "opacity": 0.9}, {duration: "200" });
// if ($("#left-panel-contents").hasClass('active')) {
// hsHideTodoKeyword('done');
// } else {
// hsShowTodoKeyword('done');
// }
// return false;
}
$(function() {
$('<div id="left-panel-wrapper" class="dontprint"><div id="left-panel-contents" style="opacity: 0.9"></div><div id="left-panel-button" class="dontprint"><a href="#">Dashboard</a></div></div>')
.appendTo('body');
$('<div id="right-panel-wrapper" class="dontprint"><div id="right-panel-contents" style="opacity: 0.9"></div></div>')
.appendTo('body');
$('#left-panel-button').click(togglePanel);
});
$(function() {
var ul = $('<ul id="listOfTodo"></ul>').appendTo('#left-panel-contents');
var countOfTodo = {}, listOfTodo = [], totalOfTodo = 0;
// assign the counts (avoid double-counting elements from the ToC)
$('span.todo').not($('#table-of-contents span.todo')).each(function() {
var $thisTodo = $(this).text().trim();
if ($.inArray($thisTodo, listOfTodo) == -1) {
countOfTodo[$thisTodo] = 1;
listOfTodo.push($thisTodo);
}
else
countOfTodo[$thisTodo] += 1;
totalOfTodo += 1;
});
function scoreTodo(t) {
switch (t) {
case 'NEW': return 1;
case 'TODO': return 2;
case 'STRT': return 3;
case 'WAIT': return 4;
case 'DLGT': return 5;
case 'SDAY': return 6;
case 'DFRD': return 7;
case 'DONE': return 8;
case 'CANX': return 9;
default: return 0;
}
}
function compareTodo(a, b) {
if (scoreTodo(a) < scoreTodo(b)) return -1;
if (scoreTodo(a) > scoreTodo(b)) return 1;
return 0;
}
listOfTodo.sort(compareTodo);
// display
for (i = 0; i < listOfTodo.length; i++) {
var $thisTodo = listOfTodo[i];
$(ul).append('<li><span class="todo ' + $thisTodo + '">'+ $thisTodo + '</span>'
+ ' <small>(' + countOfTodo[$thisTodo] + ')</small></li>');
}
$('#listOfTodo')
.before('<b>Next Actions</b> <small>(' + totalOfTodo + ')</small>:<br>');
});
$(function() {
var ul = $('<ul id="listOfDone"></ul>').appendTo('#left-panel-contents');
var countOfDone = {}, listOfDone = [], totalOfDone = 0;
// assign the counts (avoid double-counting elements from the ToC)
$('span.done').not($('#table-of-contents span.done')).each(function() {
var $thisDone = $(this).text().trim();
if ($.inArray($thisDone, listOfDone) == -1) {
countOfDone[$thisDone] = 1;
listOfDone.push($thisDone);
}
else
countOfDone[$thisDone] += 1;
totalOfDone += 1;
});
// display
for (i = 0; i < listOfDone.length; i++) {
var $thisDone = listOfDone[i];
$(ul).append('<li><span class="done ' + $thisDone + '">'+ $thisDone + '</span>'
+ ' <small>(' + countOfDone[$thisDone] + ')</small></li>');
}
$('#listOfDone')
.before('<b>Done Actions</b> <small>(' + totalOfDone + '):</small><br>');
});
$(function() {
var ul = $('<ul id="listOfTags"></ul>').appendTo('#right-panel-contents');
var countOfTags = {}, listOfTags = [], totalOfTags = 0;
// assign the counts (avoid double-counting elements from the ToC)
$('span.tag').not($('#table-of-contents span.tag')).each(function() {
var $thisTagGroup = $(this).text().trim().split(/\s/);
// \s matches spaces, tabs, new lines, etc.
for (tag in $thisTagGroup) {
if ($.inArray($thisTagGroup[tag], listOfTags) == -1) {
countOfTags[$thisTagGroup[tag]] = 1;
listOfTags.push($thisTagGroup[tag]);
}
else
countOfTags[$thisTagGroup[tag]] += 1;
totalOfTags += 1;
}
});
listOfTags.sort();
// display
for (i = 0; i < listOfTags.length; i++) {
var $thisTag = listOfTags[i];
// $(ul).append('<li><span class="tag ' + $thisTag + '">'+
// $thisTag + '</span> <small>(' + countOfTags[$thisTag] + ')</small></li>');
$(ul).append('<li><span class="tag"><span class="' + $thisTag + '">' + $thisTag
+ '</span></span>'
+ ' <small>(' + countOfTags[$thisTag] + ')</small></li>');
}
$('#listOfTags')
.before('<b>Contexts</b> <small>(' + totalOfTags + '):</small><br>');
});
$(function() {
$('.done').parent(':header').parent().find(':header').addClass('DONEheader');
$('.done').parent(':header').parent().css({color: '#999999'});
});
$(function() {
$('span.todo').click(function(e) {
var orgKeyword = $(this).text().trim();
$('.' + orgKeyword).toggleClass('selected');
$('#content .' + orgKeyword).parent().parent()
.toggleClass('match' + orgKeyword);
$('#left-panel-wrapper .' + orgKeyword).parent()
.toggleClass('match' + orgKeyword);
e.preventDefault();
})
});
$(function() {
$('.tag span').click(function(e) {
var orgTag = $(this).text().trim();
$('.' + orgTag).toggleClass('selected');
$('#content .' + orgTag).parent().parent().parent()
.toggleClass('matchtag');
$('#right-panel-wrapper .' + orgTag).parent().parent()
.toggleClass('matchtag');
e.preventDefault();
})
});
function clickPreviousTab() {
var active = $('#content').tabs('option', 'active');
// Avoid going back to last tab
if (active == 0) return;
$('#content').tabs('option', 'active', active - 1);
// Set the location href
var href = $('#content div[aria-expanded=true]').attr('id');
document.location.hash = href;
$.scrollTo(0);
}
function clickNextTab() {
var active = $('#content').tabs('option', 'active');
$('#content').tabs('option', 'active', active + 1);
// Set the location href
var href = $('#content div[aria-expanded=true]').attr('id');
document.location.hash = href;
$.scrollTo(0);
}
function orgDefkey(e) {
if (!e)
var e = window.event;
var keycode = (e.keyCode) ? e.keyCode : e.which;
var actualkey = String.fromCharCode(keycode);
switch (actualkey) {
case "?": // help (dashboard)
case "h":
togglePanel(e);
break;
case "n": // next
clickNextTab();
break;
case "p": // previous
clickPreviousTab();
break;
// case "b": // scroll down - should be mapped to Shift-SPC
// $(window).scrollTop($(window).scrollTop()-$(window).height());
// break;
case "<": // scroll to top
$(window).scrollTop(0);
break;
case ">": // scroll to bottom
$(window).scrollTop($(document).height());
break;
case "-": // collapse all
hsCollapseAll();
break;
case "+": // expand all
hsExpandAll();
break;
case "r": // go to next task
hsReviewTaskNext();
break;
case "R": // go to previous task
hsReviewTaskPrev();
break;
case "q": // quit reviewing
hsReviewTaskQuit();
break;
case "g": // refresh the page (from the server, rather than the cache)
location.reload(true);
break;
}
}
document.onkeypress = orgDefkey;

View file

@ -0,0 +1,335 @@
// hideshow.js --- HideShow JS file
//
// Copyright (C) 2014 All Right Reserved, Fabrice Niessen
//
// This file is free software: you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// This file is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// Author: Fabrice Niessen <(concat "fniessen" at-sign "pirilampo.org")>
// URL: https://github.com/fniessen/hide-show/
// Version: 20140912.1722
// var HS_COLLAPSIBLE_HEADERS = $('h3, h4, h5'); // collapsible headers
if (typeof HS_STARTUP_FOLDED === 'undefined') {
var HS_STARTUP_FOLDED = false; // Show just the overview, or show all.
}
if (typeof HS_SHOW_ALL_TEXT === 'undefined') {
var HS_SHOW_ALL_TEXT = 'Expand';
}
if (typeof HS_HIDE_ALL_TEXT === 'undefined') {
var HS_HIDE_ALL_TEXT = 'Collapse';
}
if (typeof HS_ALWAYS_DISPLAY_ICON === 'undefined') {
var HS_ALWAYS_DISPLAY_ICON = false; // Display an icon for all states, or
// just when closed.
}
if (typeof HS_ICON_CLOSED === 'undefined') {
var HS_ICON_CLOSED = '&#x25BA;'; // black right-pointing pointer
}
if (typeof HS_ICON_OPEN === 'undefined') {
var HS_ICON_OPEN = '&#x25BC;'; // black down-pointing triangle
}
if (typeof HS_ICON_EMPTY === 'undefined') {
var HS_ICON_EMPTY = '&#x25A0;'; // black square
}
if (typeof HS_SHOW_ALL_OPEN_DONE_TREES === 'undefined') {
var HS_SHOW_ALL_OPEN_DONE_TREES = false; // Expand all will open DONE trees.
}
if (typeof HS_CLASS === 'undefined') {
var HS_CLASS = 'hsCollapsible';
}
// Expand a header
function hsExpand(header) {
hsExpand2(header, true);
}
// Expand a header
function hsExpand2(header, expandDoneHeader) {
// Ignore non collapsible entries
if (!header.parent().hasClass(HS_CLASS)) return;
// Do not expand DONE node if not required
if (hsIsDoneHeader(header) && !expandDoneHeader) return;
header.children('span[class="ellipsis"]').remove();
if (HS_ALWAYS_DISPLAY_ICON == true) {
header.append('<span class="ellipsis"> ' + HS_ICON_OPEN + '</span>');
}
header.parent().removeClass('hsCollapsed').addClass('hsExpanded');
header.nextAll().show();
}
// Expand a header and all its parents
function hsExpandParents(header) {
hsExpand(header);
header.parents('.hsCollapsed').each(function() {
hsExpand($(this).children(':header'));
});
}
// Collapse a header and all its parents
function hsCollapseParents(header) {
hsCollapse(header);
header.parents('.hsExpanded').each(function() {
hsCollapse($(this).children(':header'));
});
}
// Collapse a header
function hsCollapse(header) {
// Ignore non collapsible entries
if (!header.parent().hasClass(HS_CLASS)) return;
header.children('span[class="ellipsis"]').remove();
header.append('<span class="ellipsis"> ' + HS_ICON_CLOSED + '</span>');
header.parent().removeClass('hsExpanded').addClass('hsCollapsed');
// header.nextAll().hide('fast');
header.nextAll().hide();
}
// Toggle a header
function hsToggleCollapsing(header) {
if (header.parent().hasClass('hsCollapsed'))
hsExpand(header);
else if (header.parent().hasClass('hsExpanded'))
hsCollapse(header);
}
// Expand all headers
function hsExpandAll() {
$('#content .hsCollapsed').each(function() {
hsExpand2($(this).children(':header'), HS_SHOW_ALL_OPEN_DONE_TREES);
});
}
// Collapse all headers
function hsCollapseAll() {
$('#content .hsExpanded').each(function() {
hsCollapse($(this).children(':header'));
});
}
// Collapse all visible headers
function hsCollapseAllVisible() {
$('#content .hsExpanded:visible').each(function() {
hsCollapse($(this).children(':header'));
});
}
// Add click events to H3/H4/H5 headers which have contents.
function hsInit() {
for (var i = 3; i <= 5; i++) {
$('#content .outline-' + i).each(function() {
var header = $(this).children(':header');
if (header.siblings().length > 0) {
$(this).addClass(HS_CLASS);
header.css({cursor: 'pointer'});
header.click(function() {
hsToggleCollapsing($(this)); });
// Allow to override global Collapse/Expand default on an entry
// basis (see property `:HTML_CONTAINER_CLASS:')
if (header.parent().hasClass('hsCollapsed')) {
hsCollapse(header);
} else if (header.parent().hasClass('hsExpanded')) {
hsExpand(header);
} else {
hsSetDefaultVisibility(header);
}
}
else {
if (HS_ALWAYS_DISPLAY_ICON == true) {
header.append('<span class="ellipsis"> ' + HS_ICON_EMPTY
+ '</span>');
}
$(this).addClass('hsEmpty');
}
});
}
// Add div to hold minitoc content (so it can be cleared without deleting the buttons)
$('#minitoc').append($('<div id="minitoc-content"></div>'));
// Add buttons
$('#minitoc').append($('<div class="buttons dontprint"></div>'));
$('.buttons').append($('<span>' + HS_SHOW_ALL_TEXT + '</span>')
.addClass('hsButton')
.click(hsExpandAll));
$('.buttons').append($('<span>' + HS_HIDE_ALL_TEXT + '</span>')
.addClass('hsButton')
.click(hsCollapseAll));
}
// Returns true if a header is a DONE header
function hsIsDoneHeader(header) {
return $('span.done', header).length;
}
// Sets the default visibility state to a header
function hsSetDefaultVisibility(header) {
if (HS_STARTUP_FOLDED) {
hsCollapse(header);
}
else {
if (!hsIsDoneHeader(header) | HS_SHOW_ALL_OPEN_DONE_TREES) {
hsExpand(header);
}
else {
hsCollapse(header);
}
}
}
// Expands an anchor, i.e. expand all parent headers
function hsExpandAnchor(id) {
// alert(id);
if (id) {
// alert($(id + '.hsNode').length);
$(id).parents('.hsCollapsed').each(function() {
hsExpand2($(this).children(':header'), true);
});
}
}
// Search for next task to review, starting from beginning of current tab.
// If BACKWARD is true, search in the reverse direction.
function hsReviewTaskNext(backward) {
// If no tasks to review at all, do nothing.
if ($('.outline-2 span.todo').length == 0) return;
if ($('.hsReviewing').length == 0) { // reviewing is starting
$('body').addClass('hsReviewing');
$('.hsReviewPanel').addClass('hsReviewing');
$('body').prepend('<div id="hsOverlay"></div>');
hsAddReviewingPanels();
hsCollapseAll();
// Get first task to review on each tab and expand it
$('.outline-2').each(function(){
var firstTodo = $(this).find('span.todo:first').parent().parent();
firstTodo.addClass('hsReview');
hsExpandParents($(firstTodo).children(':header'));
});
}
else {
// Get all todos
var todosElements = $('.outline-2:visible span.todo').parent().parent();
// alert(todosElements.length);
var todos = jQuery.makeArray(todosElements);
if (backward) {
todos = todos.reverse();
}
// Find current review item and review the next one
var foundReview = false;
var index;
for (index = 0; index < todos.length; ++index) {
var todo = todos[index];
if (foundReview) {
$(todo).addClass('hsReview');
hsExpandParents($(todo).children(':header'));
break;
}
if ($(todo).hasClass('hsReview')) {
foundReview = true;
if (index < todos.length - 1) {
$(todo).removeClass('hsReview');
hsCollapseParents($(todo).children(':header'));
}
}
}
// Update reviewing panel
if (index < todos.length) {
var reviewItem = index + 1;
if (backward) {
reviewItem = todos.length - index;
}
$('.outline-2:visible .hsReviewingPanel .hsReviewItem').text(reviewItem);
}
}
// Scroll to the current review item
$('html, body').animate({
scrollTop: $(".hsReview:visible").offset().top
}, 200);
}
// go to previous task to review
function hsReviewTaskPrev() {
hsReviewTaskNext(true);
}
// stop reviewing tasks
function hsReviewTaskQuit() {
$('body').removeClass('hsReviewing');
$('.hsReviewPanel').removeClass('hsReviewing');
$('.hsReview').removeClass('hsReview');
$('#hsOverlay').remove();
$('.hsReviewingPanel').remove();
}
function hsHideTodoKeyword(kw) {
$('span.' + kw).addClass('hsHidden').parent().parent().hide();
}
function hsShowTodoKeyword(kw) {
$('span.' + kw).removeClass('hsHidden').parent().parent().show();
// XXX Show if parent is not collapsed!
}
function hsAddReviewPanels() {
$('.outline-2').each(function(e) {
var nbItems = $(this).find('span.todo').length;
if (nbItems > 0) {
$(this).prepend('<div class="hsReviewPanel hsUnselectable" onclick="hsReviewTaskNext()">'
+ 'Press r or click here<br>'
+ 'to review ' + nbItems + ' tasks<br>'
+ '(out of ' + nbReviewTotalTasks + ' tasks)</div>');
}
});
}
function hsAddReviewingPanels() {
$('.outline-2').each(function(e) {
var nbItems = $(this).find('span.todo').length;
if (nbItems > 0) {
$(this).prepend('<div class="hsReviewingPanel hsUnselectable">Reviewing task <span class="hsReviewItem">1</span> / ' + nbItems + '<br>'
+ '(out of ' + nbReviewTotalTasks + ' tasks)<br>'
+ 'Shortcuts: '
+ '<span class="hsReviewButton" onclick="hsReviewTaskNext()">r (next)</span> - '
+ '<span class="hsReviewButton" onclick="hsReviewTaskPrev()">R (previous)</span>'
+ '</div>');
}
else {
$(this).prepend('<div class="hsReviewingPanel hsUnselectable">No task to review<br>'
+ '(out of ' + nbReviewTotalTasks + ' tasks)<br>'
+ 'Shortcuts: '
+ '<span class="hsReviewButton" onclick="hsReviewTaskNext()">r (next)</span> - '
+ '<span class="hsReviewButton" onclick="hsReviewTaskPrev()">R (previous)</span>'
+ '</div>');
}
});
}
var nbReviewTotalTasks;
$(document).ready(function() {
nbReviewTotalTasks = $('.outline-2 span.todo').length;
hsAddReviewPanels();
});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,9 @@
/**
* jQuery.LocalScroll - Animated scrolling navigation, using anchors.
* Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
* Dual licensed under MIT and GPL.
* Date: 3/11/2009
* @author Ariel Flesler
* @version 1.2.7
**/
;(function($){var l=location.href.replace(/#.*/,'');var g=$.localScroll=function(a){$('body').localScroll(a)};g.defaults={duration:1e3,axis:'y',event:'click',stop:true,target:window,reset:true};g.hash=function(a){if(location.hash){a=$.extend({},g.defaults,a);a.hash=false;if(a.reset){var e=a.duration;delete a.duration;$(a.target).scrollTo(0,a);a.duration=e}i(0,location,a)}};$.fn.localScroll=function(b){b=$.extend({},g.defaults,b);return b.lazy?this.bind(b.event,function(a){var e=$([a.target,a.target.parentNode]).filter(d)[0];if(e)i(a,e,b)}):this.find('a,area').filter(d).bind(b.event,function(a){i(a,this,b)}).end().end();function d(){return!!this.href&&!!this.hash&&this.href.replace(this.hash,'')==l&&(!b.filter||$(this).is(b.filter))}};function i(a,e,b){var d=e.hash.slice(1),f=document.getElementById(d)||document.getElementsByName(d)[0];if(!f)return;if(a)a.preventDefault();var h=$(b.target);if(b.lock&&h.is(':animated')||b.onBefore&&b.onBefore.call(b,a,f,h)===false)return;if(b.stop)h.stop(true);if(b.hash){var j=f.id==d?'id':'name',k=$('<a> </a>').attr(j,d).css({position:'absolute',top:$(window).scrollTop(),left:$(window).scrollLeft()});f[j]='';$('body').prepend(k);location=e.hash;k.remove();f[j]=d}h.scrollTo(f,b).trigger('notify.serialScroll',[f])}})(jQuery);

View file

@ -0,0 +1,7 @@
/**
* Copyright (c) 2007-2012 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
* Dual licensed under MIT and GPL.
* @author Ariel Flesler
* @version 1.4.3.1
*/
;(function($){var h=$.scrollTo=function(a,b,c){$(window).scrollTo(a,b,c)};h.defaults={axis:'xy',duration:parseFloat($.fn.jquery)>=1.3?0:1,limit:true};h.window=function(a){return $(window)._scrollable()};$.fn._scrollable=function(){return this.map(function(){var a=this,isWin=!a.nodeName||$.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!isWin)return a;var b=(a.contentWindow||a).document||a.ownerDocument||a;return/webkit/i.test(navigator.userAgent)||b.compatMode=='BackCompat'?b.body:b.documentElement})};$.fn.scrollTo=function(e,f,g){if(typeof f=='object'){g=f;f=0}if(typeof g=='function')g={onAfter:g};if(e=='max')e=9e9;g=$.extend({},h.defaults,g);f=f||g.duration;g.queue=g.queue&&g.axis.length>1;if(g.queue)f/=2;g.offset=both(g.offset);g.over=both(g.over);return this._scrollable().each(function(){if(e==null)return;var d=this,$elem=$(d),targ=e,toff,attr={},win=$elem.is('html,body');switch(typeof targ){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(targ)){targ=both(targ);break}targ=$(targ,this);if(!targ.length)return;case'object':if(targ.is||targ.style)toff=(targ=$(targ)).offset()}$.each(g.axis.split(''),function(i,a){var b=a=='x'?'Left':'Top',pos=b.toLowerCase(),key='scroll'+b,old=d[key],max=h.max(d,a);if(toff){attr[key]=toff[pos]+(win?0:old-$elem.offset()[pos]);if(g.margin){attr[key]-=parseInt(targ.css('margin'+b))||0;attr[key]-=parseInt(targ.css('border'+b+'Width'))||0}attr[key]+=g.offset[pos]||0;if(g.over[pos])attr[key]+=targ[a=='x'?'width':'height']()*g.over[pos]}else{var c=targ[pos];attr[key]=c.slice&&c.slice(-1)=='%'?parseFloat(c)/100*max:c}if(g.limit&&/^\d+$/.test(attr[key]))attr[key]=attr[key]<=0?0:Math.min(attr[key],max);if(!i&&g.queue){if(old!=attr[key])animate(g.onAfterFirst);delete attr[key]}});animate(g.onAfter);function animate(a){$elem.animate(attr,f,g.easing,a&&function(){a.call(this,e,g)})}}).end()};h.max=function(a,b){var c=b=='x'?'Width':'Height',scroll='scroll'+c;if(!$(a).is('html,body'))return a[scroll]-$(a)[c.toLowerCase()]();var d='client'+c,html=a.ownerDocument.documentElement,body=a.ownerDocument.body;return Math.max(html[scroll],body[scroll])-Math.min(html[d],body[d])};function both(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1 @@
!function(a,b){"use strict";function c(c,g){var h=this;h.$el=a(c),h.el=c,h.id=e++,h.$window=a(b),h.$document=a(document),h.$el.bind("destroyed",a.proxy(h.teardown,h)),h.$clonedHeader=null,h.$originalHeader=null,h.isSticky=!1,h.hasBeenSticky=!1,h.leftOffset=null,h.topOffset=null,h.init=function(){h.$el.each(function(){var b=a(this);b.css("padding",0),h.$originalHeader=a("thead:first",this),h.$clonedHeader=h.$originalHeader.clone(),b.trigger("clonedHeader."+d,[h.$clonedHeader]),h.$clonedHeader.addClass("tableFloatingHeader"),h.$clonedHeader.css("display","none"),h.$originalHeader.addClass("tableFloatingHeaderOriginal"),h.$originalHeader.after(h.$clonedHeader),h.$printStyle=a('<style type="text/css" media="print">.tableFloatingHeader{display:none !important;}.tableFloatingHeaderOriginal{position:static !important;}</style>'),a("head").append(h.$printStyle)}),h.setOptions(g),h.updateWidth(),h.toggleHeaders(),h.bind()},h.destroy=function(){h.$el.unbind("destroyed",h.teardown),h.teardown()},h.teardown=function(){h.isSticky&&h.$originalHeader.css("position","static"),a.removeData(h.el,"plugin_"+d),h.unbind(),h.$clonedHeader.remove(),h.$originalHeader.removeClass("tableFloatingHeaderOriginal"),h.$originalHeader.css("visibility","visible"),h.$printStyle.remove(),h.el=null,h.$el=null},h.bind=function(){h.$scrollableArea.on("scroll."+d,h.toggleHeaders),h.isWindowScrolling||(h.$window.on("scroll."+d+h.id,h.setPositionValues),h.$window.on("resize."+d+h.id,h.toggleHeaders)),h.$scrollableArea.on("resize."+d,h.toggleHeaders),h.$scrollableArea.on("resize."+d,h.updateWidth)},h.unbind=function(){h.$scrollableArea.off("."+d,h.toggleHeaders),h.isWindowScrolling||(h.$window.off("."+d+h.id,h.setPositionValues),h.$window.off("."+d+h.id,h.toggleHeaders)),h.$scrollableArea.off("."+d,h.updateWidth)},h.toggleHeaders=function(){h.$el&&h.$el.each(function(){var b,c=a(this),d=h.isWindowScrolling?isNaN(h.options.fixedOffset)?h.options.fixedOffset.outerHeight():h.options.fixedOffset:h.$scrollableArea.offset().top+(isNaN(h.options.fixedOffset)?0:h.options.fixedOffset),e=c.offset(),f=h.$scrollableArea.scrollTop()+d,g=h.$scrollableArea.scrollLeft(),i=h.isWindowScrolling?f>e.top:d>e.top,j=(h.isWindowScrolling?f:0)<e.top+c.height()-h.$clonedHeader.height()-(h.isWindowScrolling?0:d);i&&j?(b=e.left-g+h.options.leftOffset,h.$originalHeader.css({position:"fixed","margin-top":h.options.marginTop,left:b,"z-index":3}),h.leftOffset=b,h.topOffset=d,h.$clonedHeader.css("display",""),h.isSticky||(h.isSticky=!0,h.updateWidth()),h.setPositionValues()):h.isSticky&&(h.$originalHeader.css("position","static"),h.$clonedHeader.css("display","none"),h.isSticky=!1,h.resetWidth(a("td,th",h.$clonedHeader),a("td,th",h.$originalHeader)))})},h.setPositionValues=function(){var a=h.$window.scrollTop(),b=h.$window.scrollLeft();!h.isSticky||0>a||a+h.$window.height()>h.$document.height()||0>b||b+h.$window.width()>h.$document.width()||h.$originalHeader.css({top:h.topOffset-(h.isWindowScrolling?0:a),left:h.leftOffset-(h.isWindowScrolling?0:b)})},h.updateWidth=function(){if(h.isSticky){h.$originalHeaderCells||(h.$originalHeaderCells=a("th,td",h.$originalHeader)),h.$clonedHeaderCells||(h.$clonedHeaderCells=a("th,td",h.$clonedHeader));var b=h.getWidth(h.$clonedHeaderCells);h.setWidth(b,h.$clonedHeaderCells,h.$originalHeaderCells),h.$originalHeader.css("width",h.$clonedHeader.width())}},h.getWidth=function(c){var d=[];return c.each(function(c){var e,f=a(this);if("border-box"===f.css("box-sizing"))e=f[0].getBoundingClientRect().width;else{var g=a("th",h.$originalHeader);if("collapse"===g.css("border-collapse"))if(b.getComputedStyle)e=parseFloat(b.getComputedStyle(this,null).width);else{var i=parseFloat(f.css("padding-left")),j=parseFloat(f.css("padding-right")),k=parseFloat(f.css("border-width"));e=f.outerWidth()-i-j-k}else e=f.width()}d[c]=e}),d},h.setWidth=function(a,b,c){b.each(function(b){var d=a[b];c.eq(b).css({"min-width":d,"max-width":d})})},h.resetWidth=function(b,c){b.each(function(b){var d=a(this);c.eq(b).css({"min-width":d.css("min-width"),"max-width":d.css("max-width")})})},h.setOptions=function(c){h.options=a.extend({},f,c),h.$scrollableArea=a(h.options.scrollableArea),h.isWindowScrolling=h.$scrollableArea[0]===b},h.updateOptions=function(a){h.setOptions(a),h.unbind(),h.bind(),h.updateWidth(),h.toggleHeaders()},h.init()}var d="stickyTableHeaders",e=0,f={fixedOffset:0,leftOffset:0,marginTop:0,scrollableArea:b};a.fn[d]=function(b){return this.each(function(){var e=a.data(this,"plugin_"+d);e?"string"==typeof b?e[b].apply(e):e.updateOptions(b):"destroy"!==b&&a.data(this,"plugin_"+d,new c(this,b))})}}(jQuery,window);

View file

@ -0,0 +1,20 @@
Copyright (c) 2011 Jonas Mosbech
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -24,7 +24,6 @@
;; From MELPA ;; From MELPA
(require 'dash) (require 'dash)
(require 'dash-functional)
(require 's) (require 's)
;; org-ql ;; org-ql

View file

@ -1,7 +1,9 @@
;;; helm-org-ql.el --- Helm commands for org-ql -*- lexical-binding: t; -*- ;;; helm-org-ql.el --- Helm support for org-ql -*- lexical-binding: t; -*-
;; Author: Adam Porter <adam@alphapapa.net> ;; Author: Adam Porter <adam@alphapapa.net>
;; URL: https://github.com/alphapapa/org-ql ;; URL: https://github.com/alphapapa/org-ql
;; Version: 0.6.2
;; Package-Requires: ((emacs "26.1") (compat "29.1.4.5") (dash "2.18.1") (s "1.12.0") (helm-org "1.0") (org-ql "0.6-pre"))
;;; Commentary: ;;; Commentary:
@ -30,41 +32,48 @@
;;;; Requirements ;;;; Requirements
(require 'cl-lib)
(require 'org) (require 'org)
(require 'org-ql) (require 'compat)
(require 'dash)
(require 's)
;; (require 'helm) (require 'helm)
;; (require 'helm-org) (require 'helm-org)
(require 'org-ql)
(require 'org-ql-search)
(declare-function org-ql--normalize-query "org-ql" t t)
;;;; Compatibility ;;;; Compatibility
;; Declare Helm functions since Helm may not be installed. (defalias 'helm-org-ql--show-entry
(declare-function helm "ext:helm") (if (version< org-version "9.6")
(declare-function helm-run-after-exit "ext:helm") 'org-show-entry
(declare-function helm-window "ext:helm-lib") 'org-fold-show-entry))
(declare-function helm-buffer-get "ext:helm-lib")
(declare-function helm-make-source "ext:helm-source")
(declare-function helm-org-goto-marker "ext:helm-org")
;; Silence byte-compiler about variables.
(defvar helm-map)
(defvar helm-pattern)
(defvar helm-input-idle-delay)
;;;; Variables ;;;; Variables
(defvar helm-org-ql-map (defvar helm-org-ql-map
(let ((map (copy-keymap helm-map)) (let ((map (make-sparse-keymap))
(mappings '( (mappings '("C-x C-s" helm-org-ql-save)))
"C-x C-s" helm-org-ql-save
)))
(cl-loop for (key fn) on mappings by #'cddr (cl-loop for (key fn) on mappings by #'cddr
do (define-key map (kbd key) fn)) do (define-key map (kbd key) fn))
map) (make-composed-keymap map helm-map))
"Keymap for `helm-org-ql' sessions. "Keymap for `helm-org-ql' sessions.
Based on `helm-map'.") Based on `helm-map'.")
(defvar helm-org-ql-views-source
(helm-make-source "Org QL Views" 'helm-source-sync
:candidates (lambda ()
(->> org-ql-views
(-map #'car)
(-sort #'string<)))
:action (list (cons "Show view" #'org-ql-view)))
"Helm source for `org-ql-views'.")
(defvar-local helm-org-ql-buffers-files nil (defvar-local helm-org-ql-buffers-files nil
"Used for `helm-org-ql-save'.") "Used for `helm-org-ql-save'.")
@ -72,7 +81,8 @@ Based on `helm-map'.")
(defgroup helm-org-ql nil (defgroup helm-org-ql nil
"Options for `helm-org-ql'." "Options for `helm-org-ql'."
:group 'org-ql) :group 'org-ql
:group 'helm)
(defcustom helm-org-ql-reverse-paths t (defcustom helm-org-ql-reverse-paths t
"Whether to reverse Org outline paths in `helm-org-ql' results." "Whether to reverse Org outline paths in `helm-org-ql' results."
@ -98,9 +108,11 @@ Based on `helm-map'.")
Interactively, search the current buffer. Note that this command Interactively, search the current buffer. Note that this command
only accepts non-sexp, \"plain\" queries. only accepts non-sexp, \"plain\" queries.
NAME is passed to `helm-org-ql-source', which see.
NOTE: Atoms in the query are turned into strings where NOTE: Atoms in the query are turned into strings where
appropriate, which makes it unnecessary to type quotation marks appropriate, which makes it unnecessary to type quotation marks
around words that are intended to be searched for as indepenent around words that are intended to be searched for as independent
strings. strings.
All query tokens are wrapped in the operator BOOLEAN (default All query tokens are wrapped in the operator BOOLEAN (default
@ -125,51 +137,20 @@ Is transformed into this query:
(let ((boolean (if current-prefix-arg 'or boolean)) (let ((boolean (if current-prefix-arg 'or boolean))
(helm-input-idle-delay helm-org-ql-input-idle-delay)) (helm-input-idle-delay helm-org-ql-input-idle-delay))
(helm :prompt (format "Query (boolean %s): " (-> boolean symbol-name upcase)) (helm :prompt (format "Query (boolean %s): " (-> boolean symbol-name upcase))
:sources :sources (helm-org-ql-source buffers-files :name name))))
;; Expansion of `helm-build-sync-source' macro.
(helm-make-source name 'helm-source-sync
:candidates (lambda nil
(let* ((query (org-ql--plain-query helm-pattern boolean))
(window-width (window-width (helm-window))))
(when query
(with-current-buffer (helm-buffer-get)
(setq helm-org-ql-buffers-files buffers-files))
(ignore-errors
;; Ignore errors that might be caused by partially typed queries.
;; FIXME: This doesn't prevent warnings that are errors occurring during
;; byte-compilation due to partially typed values which can't be correctly
;; pre-processed, e.g. "ts:to=2019-01-0", which can't be parsed into a
;; timestamp. A "*Compile-Log*" buffer is displayed with "Error: Wrong type
;; argument: integerp, nil". With my Helm settings, it's hidden as soon as
;; the query is typed correctly, so it's tolerable, but I'd prefer to fix it.
;; I haven't found a way to ignore the error/warning; `with-no-warnings' has
;; no effect, and we're already using `ignore-errors'. The only solution I
;; can think of would be to ignore the errors/warnings higher up the chain
;; where byte-compilation is actually done, but it might not be a good idea
;; to always ignore such errors/warnings.
(org-ql-select buffers-files query
:action (list 'helm-org-ql--heading window-width))))))
:match #'identity
:fuzzy-match nil
:multimatch nil
:volatile t
:keymap helm-org-ql-map
:action helm-org-ql-actions))))
;;;###autoload ;;;###autoload
(defun helm-org-ql-agenda-files () (defun helm-org-ql-agenda-files ()
"Search agenda files with `helm-org-ql', which see." "Search agenda files with `helm-org-ql', which see."
(interactive) (interactive)
(helm-org-ql (org-agenda-files) :name "helm-org-ql-agenda-files")) (helm-org-ql (org-agenda-files) :name "Org Agenda Files"))
;;;###autoload ;;;###autoload
(defun helm-org-ql-org-directory () (defun helm-org-ql-org-directory ()
"Search Org files in `org-directory' with `helm-org-ql'." "Search Org files in `org-directory' with `helm-org-ql'."
(interactive) (interactive)
(helm-org-ql (directory-files org-directory 'full (helm-org-ql (org-ql-search-directories-files)
(rx ".org" eos)) :name "Org Directory Files"))
:name "helm-org-ql-org-directory"))
(defun helm-org-ql-show-marker (marker) (defun helm-org-ql-show-marker (marker)
"Show heading at MARKER." "Show heading at MARKER."
@ -180,7 +161,7 @@ Is transformed into this query:
;; it to go to the previous heading. I don't know why it does that. ;; it to go to the previous heading. I don't know why it does that.
(switch-to-buffer (marker-buffer marker)) (switch-to-buffer (marker-buffer marker))
(goto-char marker) (goto-char marker)
(org-show-entry)) (helm-org-ql--show-entry))
(defun helm-org-ql-show-marker-indirect (marker) (defun helm-org-ql-show-marker-indirect (marker)
"Show heading at MARKER with `org-tree-to-indirect-buffer'." "Show heading at MARKER with `org-tree-to-indirect-buffer'."
@ -193,15 +174,44 @@ Is transformed into this query:
(interactive) (interactive)
(let ((buffers-files (with-current-buffer (helm-buffer-get) (let ((buffers-files (with-current-buffer (helm-buffer-get)
helm-org-ql-buffers-files)) helm-org-ql-buffers-files))
(query (org-ql--plain-query helm-pattern))) (query (org-ql--query-string-to-sexp helm-pattern)))
(helm-run-after-exit #'org-ql-search buffers-files query))) (helm-run-after-exit #'org-ql-search buffers-files query)))
;;;###autoload
(defun helm-org-ql-views ()
"Show an `org-ql' view selected with Helm."
(interactive)
(helm :sources helm-org-ql-views-source))
;;;; Functions ;;;; Functions
;;;###autoload
(cl-defun helm-org-ql-source (buffers-files &key (name "helm-org-ql"))
"Return Helm source named NAME to search BUFFERS-FILES with `helm-org-ql'."
;; Expansion of `helm-build-sync-source' macro.
(helm-make-source name 'helm-source-sync
:candidates (lambda ()
(let* ((query (org-ql--query-string-to-sexp helm-pattern))
(window-width (window-width (helm-window))))
(when query
(with-current-buffer (helm-buffer-get)
(setq helm-org-ql-buffers-files buffers-files))
(ignore-errors
;; Ignore errors that might be caused by partially typed queries.
(org-ql-select buffers-files query
:action `(helm-org-ql--heading ,window-width))))))
:match #'identity
:fuzzy-match nil
:multimatch nil
:nohighlight t
:volatile t
:keymap helm-org-ql-map
:action helm-org-ql-actions))
(defun helm-org-ql--heading (window-width) (defun helm-org-ql--heading (window-width)
"Return string for Helm for heading at point. "Return string for Helm for heading at point.
WINDOW-WIDTH should be the width of the Helm window." WINDOW-WIDTH should be the width of the Helm window."
(font-lock-ensure (point-at-bol) (point-at-eol)) (font-lock-ensure (pos-bol) (pos-eol))
;; TODO: It would be better to avoid calculating the prefix and width ;; TODO: It would be better to avoid calculating the prefix and width
;; at each heading, but there's no easy way to do that once in each ;; at each heading, but there's no easy way to do that once in each
;; buffer, unless we manually called `org-ql' in each buffer, which ;; buffer, unless we manually called `org-ql' in each buffer, which
@ -209,10 +219,10 @@ WINDOW-WIDTH should be the width of the Helm window."
;; call a setup function in a buffer before running queries. ;; call a setup function in a buffer before running queries.
(let* ((prefix (concat (buffer-name) ":")) (let* ((prefix (concat (buffer-name) ":"))
(width (- window-width (length prefix))) (width (- window-width (length prefix)))
(path (org-split-string (org-format-outline-path (org-get-outline-path)
width nil "")
""))
(heading (org-get-heading t)) (heading (org-get-heading t))
(path (-> (org-get-outline-path)
(org-format-outline-path width nil "")
(org-split-string "")))
(path (if helm-org-ql-reverse-paths (path (if helm-org-ql-reverse-paths
(concat heading "\\" (s-join "\\" (nreverse path))) (concat heading "\\" (s-join "\\" (nreverse path)))
(concat (s-join "/" path) "/" heading)))) (concat (s-join "/" path) "/" heading))))

22
hooks/pre-push Executable file
View file

@ -0,0 +1,22 @@
#!/bin/bash
# * Commit parameters
# Unused now, but good for future reference. See man 5 githooks.
remote="$1"
url="$2"
read local_ref local_sha remote_ref remote_sha
# * Run tests
# Not using sandbox and auto-install, because "git push" shouldn't
# cause remote code to be downloaded and executed (i.e. what would
# happen by installing packages). It can be done manually when needed.
# Only run when pushing master.
if [[ $local_ref = refs/heads/master ]]
then
make sandbox=.sandbox test
fi

View file

@ -0,0 +1,166 @@
#!/bin/bash
# NOTE: Run "setxkbmap us" before running. See https://github.com/jordansissel/xdotool/issues/49
# NOTE: <f1> should be bound to this function in the Emacs window, like this:
# (global-set-key [f1]
# (defun gif-screencast-start-or-stop ()
# (interactive)
# (if gif-screencast-mode
# (progn
# (gif-screencast-stop)
# (setq gc-cons-threshold gc-cons-threshold-original))
# (setq gc-cons-threshold-original gc-cons-threshold)
# (setq gc-cons-threshold (* 1024 1024 500))
# (gif-screencast))))
# * Functions
function ensure_window_name {
if ! [[ $(xdotool getwindowfocus getwindowname) = $1 ]]
then
echo "Wrong window!" >&2
exit 1
fi
}
function key {
xdotool key "$@"
}
function input {
raw_input "$@"
# Correct for Helm's input idle delay by sending extra commands to
# make the screenshots be taken. Not sure why two are necessary,
# but they seem to be.
key ctrl+p
sleep 0.26
key ctrl+p
}
function raw_input {
xdotool type --delay 200 "$@"
}
function view-dispatch {
key v
sleep 2
}
function view-refresh {
key r
sleep 2
}
function clear-input {
key ctrl+a ctrl+k
sleep 0.5
}
function set-field {
key $1
shift
sleep 1
clear-input
raw_input "$@"
sleep 1
key Return
sleep 1
}
function set-field-with-unique-completion {
# "$@" should be a unique completion.
key $1
shift
sleep 0.5
clear-input
key Tab
sleep 0.5
raw_input "$@"
key Tab
sleep 0.75
key Return
sleep 1
}
function complete-in-steps {
# Assumes input is clear.
key Tab
sleep 0.75
key Tab
sleep 0.75
for s in "$@"
do
raw_input "$s"
key Tab
sleep 0.75
done
sleep 1
}
# * Script
# No matter what I try, xdotool is not working properly to focus/raise/select
# a window. And for some bizarre reason, the "xdotool selectwindow" command
# outputs a completely different window ID than "xdotool search" outputs. In
# fact, the window ID it outputs does not even appear in the output of
# "xprop" for that window. I have no idea where it's getting that ID.
# So rather than cleanly selecting the proper window in the script, we have to
# do a hacky workaround by sleeping and checking the name of the active
# window.
sleep 3
ensure_window_name "data.org"
# Start gif-screencast
key F1
sleep 2
# M-x org-ql-view RET, TAB, Ov TAB, Ag TAB, RET
key alt+x
sleep 0.2
raw_input "org-ql-view"
sleep 1
key Return
sleep 1
complete-in-steps Ov Ag
key Return
sleep 2
# Edit view.
view-dispatch
set-field t "Space-related"
set-field q "tags:space,spaceship"
set-field-with-unique-completion g pri
view-refresh
# Save query
view-dispatch
key ctrl+s
sleep 1
key Return
sleep 2
# New query: Ambition
view-dispatch
set-field t Ambition
set-field q "category:ambition"
set-field s "priority"
set-field g "parent"
view-refresh
view-dispatch
set-field t "Upcoming: ambition"
set-field g ts
view-refresh
# Save view.
view-dispatch
key ctrl+s
sleep 0.75
key Return
key F1

BIN
images/dog.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.5 KiB

BIN
images/org-ql-find.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 MiB

1071
makem.sh

File diff suppressed because it is too large Load diff

2642
notes.org

File diff suppressed because it is too large Load diff

402
org-ql-completing-read.el Normal file
View file

@ -0,0 +1,402 @@
;;; org-ql-completing-read.el --- Completing read of Org entries using org-ql -*- lexical-binding: t; -*-
;; Copyright (C) 2022-2023 Adam Porter
;; Author: Adam Porter <adam@alphapapa.net>
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; This library provides completing-read of Org entries using `org-ql'
;; search.
;;; Code:
(require 'org-ql)
(declare-function org-ql-search "org-ql-search")
(declare-function org-ql--normalize-query "org-ql" t t)
;;;; Variables
(defvar-keymap org-ql-completing-read-map
:doc "Active during `org-ql-completing-read' sessions."
"C-c C-e" #'org-ql-completing-read-export)
;; `embark-collect' doesn't work for `org-ql-completing-read', so remap
;; it to `embark-export' (which `keymap-set', et al doesn't allow).
(define-key org-ql-completing-read-map [remap embark-collect] 'embark-export)
;;;; Customization
(defgroup org-ql-completing-read nil
"Completing-read of Org entries using `org-ql' search."
:group 'org-ql)
(defcustom org-ql-completing-read-reverse-paths t
"Whether to reverse Org outline paths in `org-ql-completing-read' results."
:type 'boolean)
(defcustom org-ql-completing-read-snippet-function #'org-ql-completing-read--snippet-simple
;; TODO(v0.9): Performance of completion annotations seems to be
;; much improved now (whether due to changes in Emacs, Vertico, or
;; both, I don't know). It may be reasonable to make the context
;; snippet the default now.
"Function used to annotate results in `org-ql-completing-read'.
Function is called at entry beginning. (When set to
`org-ql-completing-read--snippet-regexp', it is called with a
regexp matching plain query tokens.)"
:type '(choice (function-item :tag "Show context around search terms" org-ql-completing-read--snippet-regexp)
(function-item :tag "Show first N characters" org-ql-completing-read--snippet-simple)
(function :tag "Custom function")))
(defcustom org-ql-completing-read-snippet-length 51
"Size of snippets of entry content to include in completion annotations.
Only used when `org-ql-completing-read-snippet-function' is set
to `org-ql-completing-read--snippet-regexp'."
:type 'integer)
(defcustom org-ql-completing-read-snippet-minimum-token-length 3
"Query tokens shorter than this many characters are ignored.
That is, they are not included when gathering entry snippets.
This avoids too-small tokens causing performance problems."
:type 'integer)
(defcustom org-ql-completing-read-snippet-prefix nil
"String prepended to snippets.
For an experience like `org-rifle', use a newline."
:type '(choice (const :tag "None (shown on same line)" nil)
(const :tag "New line (shown under heading)" "\n")
string))
(defface org-ql-completing-read-snippet '((t (:inherit font-lock-comment-face)))
"Snippets.")
(defvar org-ql-completing-read-input-regexp nil
"Current regexp for `org-ql-completing-read' input.
To be used in, e.g. annotation functions.")
;;;; Functions
(defun org-ql-completing-read-action ()
"Default action for `org-ql-completing-read'.
Returns (STRING . MARKER) cons for entry at point."
(font-lock-ensure (pos-bol) (pos-eol))
(cons (org-link-display-format (org-entry-get nil "ITEM")) (point-marker)))
(defun org-ql-completing-read-snippet (marker)
"Return snippet for entry at MARKER.
Returns value returned by function
`org-ql-completing-read-snippet-function' or
`org-ql-completing-read--snippet-simple', whichever returns a
value, or nil."
(pcase (while-no-input
;; Using `while-no-input' here doesn't make it as
;; responsive as, e.g. Helm while typing, but it seems to
;; help a little when using the org-rifle-style snippets.
(org-with-point-at marker
(or (funcall org-ql-completing-read-snippet-function
org-ql-completing-read-input-regexp)
(org-ql-completing-read--snippet-simple))))
(`t ;; Interrupted: return nil (which can be concatted).
nil)
(else (propertize (concat " " else)
'face 'org-ql-completing-read-snippet))))
(defun org-ql-completing-read-path (marker)
"Return formatted outline path for entry at MARKER."
(org-with-point-at marker
(let ((path (thread-first (org-get-outline-path nil t)
(org-format-outline-path (window-width) nil "")
(org-split-string ""))))
(if org-ql-completing-read-reverse-paths
(concat "\\" (string-join (reverse path) "\\"))
(concat "/" (string-join path "/"))))))
;;;;; Completing read
(defun org-ql-completing-read-export ()
"Show `org-ql-view' buffer for current `org-ql-completing-read'-based search."
(interactive)
(user-error "Not in an `org-ql-completing-read' session"))
;;;###autoload
(cl-defun org-ql-completing-read
(buffers-files &key query-prefix query-filter narrowp
(action #'org-ql-completing-read-action)
;; FIXME: Unused argument.
;; (annotate #'org-ql-completing-read-snippet)
(snippet #'org-ql-completing-read-snippet)
(path #'org-ql-completing-read-path)
(action-filter #'list)
(prompt "Find entry: "))
"Return marker at entry in BUFFERS-FILES selected with `org-ql'.
PROMPT is shown to the user.
NARROWP is passed to `org-ql-select', which see.
QUERY-PREFIX may be a string to prepend to the query entered by
the user (e.g. use \"heading:\" to only search headings, easily
creating a custom command that saves the user from having to type
it).
QUERY-FILTER may be a function through which the query the user
types is filtered before execution (e.g. it could replace spaces
with commas to turn multiple tokens, which would normally be
treated as multiple predicates, into multiple arguments to a
single predicate)."
(declare (indent defun))
;; Emacs's completion API is not always easy to understand, especially when using "programmed
;; completion." This code was made possible by the example Clemens Radermacher shared at
;; <https://github.com/radian-software/selectrum/issues/114#issuecomment-744041532>.
;; NOTE: I don't usually leave commented-out debugging code, but due to the incredibly tedious
;; complexity of the "Programmed Completion" API and the time spent trying to get this reasonably
;; close to "correct," I'm leaving it in, because I will undoubtedly have to go through this
;; process again.
;; (message "ORG-QL-COMPLETING-READ: Starts.")
(let ((table (make-hash-table :test #'equal))
(disambiguations (make-hash-table :test #'equal))
(window-width (window-width))
last-input org-outline-path-cache query-tokens)
(cl-labels (;; (debug-message
;; (f &rest args) (apply #'message (concat "ORG-QL-COMPLETING-READ: " f) args))
(action ()
(font-lock-ensure (pos-bol) (pos-eol))
;; This function needs to handle multiple candidates per
;; call, so we loop over a list of values by default.
(pcase-dolist (`(,string . ,marker) (funcall action-filter (funcall action)))
(when string
(if (string-empty-p string)
;; A heading's string can be empty, but we can't use one because it
;; wouldn't be useful to the user; and if one is found, it's very
;; likely to indicate an unnoticed mistake or corruption in the
;; file: so display a warning and don't record it as a candidate.
(display-warning 'org-ql-completing-read (format-message "Empty heading at %S" marker))
(when (gethash string table)
;; Disambiguate string (even adding the path isn't enough, because that could
;; also be duplicated).
(if-let ((suffix (gethash string disambiguations)))
(setf string (format "%s <%s>" string (cl-incf suffix)))
(setf string (format "%s <%s>" string (puthash string 2 disambiguations)))))
(puthash (propertize string 'org-marker marker) marker table)))))
(path (marker)
(org-with-point-at marker
(let* ((path (thread-first (org-get-outline-path nil t)
(org-format-outline-path window-width nil "")
(org-split-string "")))
(formatted-path (if org-ql-completing-read-reverse-paths
(concat "\\" (string-join (reverse path) "\\"))
(concat "/" (string-join path "/")))))
formatted-path)))
(todo (marker)
(if-let (it (org-entry-get marker "TODO"))
(concat (propertize it 'face (org-get-todo-face it)) " ")
""))
(affix (completions)
;; (debug-message "AFFIX:%S" completions)
(cl-loop for completion in completions
for marker = (get-text-property 0 'org-marker completion)
for prefix = (todo marker)
for suffix = (concat (funcall path marker) " " (funcall snippet marker))
collect (list completion prefix suffix)))
(annotate (candidate)
;; (debug-message "ANNOTATE:%S" candidate)
(while-no-input
;; Using `while-no-input' here doesn't make it as responsive as,
;; e.g. Helm while typing, but it seems to help a little when using the
;; org-rifle-style snippets.
(or (funcall snippet (get-text-property 0 'org-marker candidate)) "")))
(group (candidate transform)
(pcase transform
(`nil (buffer-name (marker-buffer (get-text-property 0 'org-marker candidate))))
(_ candidate)))
(try (string _collection _pred point &optional _metadata)
;; (debug-message "TRY: STRING:%S" string)
(cons string point))
(all (string table pred _point)
;; (debug-message "all: STRING:%S" string)
;; (debug-message "all-completions RETURNS: %S" (all-completions string table pred))
(all-completions string table pred))
(collection (input _pred flag)
(pcase flag
('metadata (list 'metadata
(cons 'category 'org-heading)
(cons 'group-function #'group)
(cons 'affixation-function #'affix)
(cons 'annotation-function #'annotate)
(cons 'display-sort-function
(lambda (strings)
(let ((quoted-tokens (mapcar #'regexp-quote query-tokens)))
(sort strings
(lambda (a b)
(cl-labels ((matches
(s) (cl-loop for token in quoted-tokens
count (string-match-p token s))))
(> (matches a) (matches b))))))))))
(`t
;; (debug-message "COLLECTION:t INPUT:%S KEYS:%S"
;; input (hash-table-keys table))
;; It's not ideal to call `run-query' unconditionally here, but due to
;; the complexity of the "Programmed Completion" API, it's basically
;; necessary, and org-ql's caching should make it nearly free.
(run-query input)
(hash-table-keys table))
('lambda
;; (debug-message "COLLECTION:lambda INPUT:%S KEYS:%S"
;; input (hash-table-keys table))
(if (not (hash-table-empty-p table))
(when (gethash input table)
t)
(run-query input)
(when (gethash input table)
;; (debug-message "COLLECTION:lambda INPUT:%S FOUND" input)
t)))
(`nil
;; (debug-message "COLLECTION:nil INPUT:%S" input)
(if (not (hash-table-empty-p table))
(when (gethash input table)
t)
(run-query input)
;; (debug-message "COLLECTION:nil INPUT:%S KEYS:%S"
;; input (hash-table-keys table))
(cond ((hash-table-empty-p table)
nil)
((gethash input table)
t)
(t
;; FIXME: "it should return the longest common prefix
;; substring of all matches otherwise"...but there's no
;; function to compute that? At least returning an empty
;; string doesn't seem to break anything.
input))))
(`(boundaries . ,suffix)
;; (debug-message "COLLECTION:boundaries INPUT:%S SUFFIX:%S KEYS:%S"
;; input suffix (hash-table-keys table))
;; FIXME: This is unlikely to be correct, but I'm not even sure if it
;; can be correct in this case since the input (e.g. "todo: foo")
;; usually won't match a completion candidate directly.
`(boundaries 0 . ,(length suffix)))))
(run-query (input)
;; (debug-message "RUN-QUERY:%S" input)
(when query-prefix
(setf input (concat query-prefix input)))
(unless (or (string-empty-p input)
(equal last-input input))
;; (debug-message "RUN-QUERY:%S RUNNING" input)
(setf last-input input)
;; Clear hash table each time the user changes the input.
(clrhash table)
(clrhash disambiguations)
(when query-filter
(setf input (funcall query-filter input)))
(setf query-tokens
;; Remove any tokens that specify predicates or are too short.
(--select (not (or (string-match-p (rx bos (1+ (not (any ":"))) ":") it)
(< (length it) org-ql-completing-read-snippet-minimum-token-length)))
(split-string input nil t (rx blank)))
org-ql-completing-read-input-regexp
(when query-tokens
;; Limiting each context word to 15 characters prevents
;; excessively long, non-word strings from ending up in
;; snippets, which can adversely affect performance.
(rx-to-string `(seq (optional (repeat 1 3 (repeat 1 15 (not space)) (0+ space)))
bow (or ,@query-tokens) (0+ (not space))
(optional (repeat 1 3 (0+ space) (repeat 1 15 (not space))))))))
(org-ql-select buffers-files (org-ql--query-string-to-sexp input)
:narrow narrowp
:action #'action))))
(unless (listp buffers-files)
;; Since we map across this argument, we ensure it's a list.
(setf buffers-files (list buffers-files)))
;; NOTE: It seems that the `completing-read' machinery can call, abort, and re-call the
;; collection function while the user is typing, which can interrupt the machinery Org uses to
;; prepare an Org buffer when an Org file is loaded. This results in, e.g. the buffer being
;; left in fundamental-mode, unprepared to be used as an Org buffer, which breaks many things
;; and is very confusing for the user. Ideally, of course, we would solve this in
;; `org-ql-select', and we already attempt to, but that function is called by the
;; `completing-read' machinery, which interrupts it, so we must work around this problem by
;; ensuring all of the BUFFERS-FILES are loaded and initialized before calling
;; `completing-read'.
(mapc #'org-ql--ensure-buffer buffers-files)
(let* ((completion-styles '(org-ql-completing-read))
(completion-styles-alist (cons (list 'org-ql-completing-read #'try #'all "Org QL Find")
completion-styles-alist))
(selected
(minibuffer-with-setup-hook
(lambda ()
(use-local-map (make-composed-keymap org-ql-completing-read-map (current-local-map))))
(cl-letf* (((symbol-function 'org-ql-completing-read-export)
(lambda ()
(interactive)
(run-at-time 0 nil
#'org-ql-search
buffers-files
(minibuffer-contents-no-properties))
(if (fboundp 'minibuffer-quit-recursive-edit)
(minibuffer-quit-recursive-edit)
(abort-recursive-edit))))
((symbol-function 'embark-export)
(symbol-function 'org-ql-completing-read-export)))
(completing-read prompt #'collection nil t)))))
;; (debug-message "SELECTED:%S KEYS:%S" selected (hash-table-keys table))
(or (gethash selected table)
;; If there are completions in the table, but none of them exactly match the user input
;; (e.g. a heading "foo" that matches a query "todo:"), `completing-read' will not
;; select it automatically, so we return it ourselves. But note that this is not
;; necessarily correct. For example, if the user types "todo:" and gets a list of
;; completions ("foo" "bar"), and then changes the input to "ba" and presses RET
;; immediately (without getting a new list of completions), the table will include "foo"
;; and "bar", and we will return "foo"'s value rather than the first match for the query
;; "ba", because `completing-read' will not cause the COLLECTION function to run a new
;; query for the new input.
(car (hash-table-values table))
(user-error "No results for input"))))))
(defun org-ql-completing-read--snippet-simple (&optional _input-regexp)
"Return a snippet of the current entry.
Returns up to `org-ql-completing-read-snippet-length' characters."
(save-excursion
(org-end-of-meta-data t)
(unless (org-at-heading-p)
(let ((end (min (+ (point) org-ql-completing-read-snippet-length)
(org-entry-end-position))))
(concat org-ql-completing-read-snippet-prefix
(truncate-string-to-width
(replace-regexp-in-string "\n" " " (buffer-substring (point) end)
t t)
50 nil nil t))))))
(defun org-ql-completing-read--snippet-regexp (&optional input-regexp)
"Return a snippet of the current entry's matches for INPUT-REGEXP."
;; REGEXP may be nil if there are no qualifying tokens in the query.
(when input-regexp
(save-excursion
(org-end-of-meta-data t)
(unless (org-at-heading-p)
(let* ((end (org-entry-end-position))
(snippets (cl-loop while (re-search-forward input-regexp end t)
concat (match-string 0) concat ""
do (goto-char (match-end 0)))))
(unless (string-empty-p snippets)
(concat org-ql-completing-read-snippet-prefix
(replace-regexp-in-string (rx (1+ "\n")) " " snippets t t))))))))
;;;; Footer
(provide 'org-ql-completing-read)
;;; org-ql-completing-read.el ends here

233
org-ql-find.el Normal file
View file

@ -0,0 +1,233 @@
;;; org-ql-find.el --- Find headings with completion using org-ql -*- lexical-binding: t; -*-
;; Copyright (C) 2022-2023 Adam Porter
;; Author: Adam Porter <adam@alphapapa.net>
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; This library provides a way to quickly find and go to Org entries
;; selected with Emacs's built-in completions API (so it works with
;; packages that extend it, like Vertico, Marginalia, etc). It works
;; like `helm-org-ql' but does not require Helm.
;;; Code:
(require 'cl-lib)
(require 'org)
(require 'org-ql)
(require 'org-ql-search)
(require 'org-ql-completing-read)
(declare-function org-ql--normalize-query "org-ql" t t)
;;;; Customization
(defgroup org-ql-find nil
"Options for `org-ql-find'."
:group 'org-ql)
(defcustom org-ql-find-goto-hook '(org-show-entry org-reveal)
"Functions called when selecting an entry."
;; TODO: Add common choices, including `org-tree-to-indirect-buffer'.
:type 'hook)
(defcustom org-ql-find-display-buffer-action '(display-buffer-same-window)
"Display buffer action list for `org-ql-find'.
See function `display-buffer'."
:type 'sexp)
;;;; Commands
;;;###autoload
(cl-defun org-ql-find (buffers-files &key query-prefix query-filter widen
(prompt "Find entry: "))
"Go to an Org entry in BUFFERS-FILES selected by searching entries with `org-ql'.
Interactively, search the buffers and files relevant to the
current buffer (i.e. in `org-agenda-mode', the value of
`org-ql-view-buffers-files' or `org-agenda-contributing-files';
in `org-mode', that buffer).
With one or more universal prefix arguments, WIDEN buffers before
searching (otherwise, respect any narrowing). With two universal
prefix arguments, select multiple buffers to search with
completion and PROMPT.
QUERY-PREFIX may be a string to prepend to the query (e.g. use
\"heading:\" to only search headings, easily creating a custom
command that saves the user from having to type it).
QUERY-FILTER may be a function through which the query the user
types is filtered before execution (e.g. it could replace spaces
with commas to turn multiple tokens, which would normally be
treated as multiple predicates, into multiple arguments to a
single predicate)."
(interactive (list (org-ql-find--buffers
:read-buffer-p (equal '(16) current-prefix-arg))
:widen current-prefix-arg))
(let ((marker (save-restriction
(when (and widen (equal (current-buffer) buffers-files))
(widen))
(org-ql-completing-read buffers-files
:narrowp (not widen)
:query-prefix query-prefix
:query-filter query-filter
:prompt prompt))))
(set-buffer (or (buffer-base-buffer (marker-buffer marker))
(marker-buffer marker)))
(pop-to-buffer (current-buffer) org-ql-find-display-buffer-action)
(without-restriction
(goto-char marker)
(run-hook-with-args 'org-ql-find-goto-hook))
(when (equal (current-buffer) (marker-buffer marker))
;; Ensure point is still within visible portion of buffer. (If
;; `org-tree-to-indirect-buffer' is used in `org-ql-find-goto-hook',
;; the buffer will have been changed and it won't matter; otherwise,
;; the buffer could have been narrowed to a region excluding the
;; selected entry.)
(let ((end-of-subtree (org-with-point-at marker
(org-end-of-subtree 'invisible-ok))))
(unless (and (<= (point-min) marker)
(>= (point-max) end-of-subtree))
(widen)
(goto-char marker))))))
;;;###autoload
(defun org-ql-refile (marker)
"Refile current entry to MARKER (interactively, one selected with `org-ql').
Interactive completion uses files listed in `org-refile-targets',
which see (but only the files are used)."
(interactive (let ((buffers-files (delete-dups
;; Always include the current buffer.
(cons (current-buffer)
(cl-loop for (files-spec . _candidate-spec) in org-refile-targets
append (cl-typecase files-spec
(null (list (current-buffer)))
(symbol (pcase (funcall files-spec)
((and (pred stringp) file) (list file))
((and (pred listp) files) files)))
(list files-spec)))))))
(list (org-ql-completing-read buffers-files :prompt "Refile to: "))))
(let ((buffer (or (buffer-base-buffer (marker-buffer marker))
(marker-buffer marker))))
(org-refile nil nil
;; The RFLOC argument:
(list
;; Name
(org-with-point-at marker
(nth 4 (org-heading-components)))
;; File
(buffer-file-name buffer)
;; nil
nil
;; Position
marker))))
;;;###autoload
(defun org-ql-find-in-agenda ()
"Call `org-ql-find' on `org-agenda-files'."
(interactive)
(org-ql-find (org-agenda-files)))
;;;###autoload
(defun org-ql-find-in-org-directory ()
"Call `org-ql-find' on files in `org-directory'."
(interactive)
(org-ql-find (org-ql-search-directories-files)))
;;;###autoload
(defun org-ql-find-path (buffers-files)
"Call `org-ql-find' to search outline paths in BUFFERS-FILES.
Interactively, search the buffers and files relevant to the
current buffer (i.e. in `org-agenda-mode', the value of
`org-ql-view-buffers-files' or `org-agenda-contributing-files';
in `org-mode', that buffer). With universal prefix, select
multiple buffers to search with completion and PROMPT."
(interactive (list (org-ql-find--buffers)))
(let ((org-ql-default-predicate 'outline-path))
(org-ql-find buffers-files)))
;;;###autoload
(cl-defun org-ql-open-link (buffers-files &key query-prefix query-filter
(prompt "Open link: "))
"Open a link selected with `org-ql-completing-read'.
Links found in entries matching the input query are offered as
candidates, and the selected one is opened with
`org-open-at-point'. Arguments BUFFERS-FILES, QUERY-FILTER,
QUERY-PREFIX, and PROMPT are passed to `org-ql-completing-read',
which see.
Interactively, search the buffers and files relevant to the
current buffer (i.e. in `org-agenda-mode', the value of
`org-ql-view-buffers-files' or `org-agenda-contributing-files';
in `org-mode', that buffer). With universal prefix, select
multiple buffers to search with completion and PROMPT."
(interactive (list (org-ql-find--buffers)))
(let* ((marker (org-ql-completing-read buffers-files
:query-prefix query-prefix
:query-filter query-filter
:prompt prompt
:action-filter #'identity
:action (lambda ()
(save-excursion
(cl-loop with limit = (org-entry-end-position)
while (re-search-forward org-link-any-re limit t)
for link = (string-trim (match-string 0))
do (progn
(set-text-properties 0 (length link) '(face org-link) link)
(setf link (org-link-display-format link)))
collect (cons link (copy-marker (match-beginning 0))))))
:snippet (lambda (&rest _)
"")
:path (lambda (marker)
(org-with-point-at marker
(let* ((path (thread-first (org-get-outline-path t t)
(org-format-outline-path (window-width) nil "")
(org-split-string "")))
(formatted-path (if org-ql-completing-read-reverse-paths
(concat "\\" (string-join (reverse path) "\\"))
(concat "/" (string-join path "/")))))
formatted-path))))))
(org-with-point-at marker
(org-open-at-point))))
;;;; Functions
(cl-defun org-ql-find--buffers (&key read-buffer-p)
"Return buffer or list of buffers to search in.
In a mode derived from `org-agenda-mode', return the value of
`org-ql-view-buffers-files' or `org-agenda-contributing-files'.
In a mode derived from `org-mode', return the current buffer. If
READ-BUFFER-P, read a list of buffers in `org-mode' with
completion. To be used in `org-ql-find' commands' interactive
forms."
(if read-buffer-p
(mapcar #'get-buffer
(completing-read-multiple
"Buffers: "
(cl-loop for buffer in (buffer-list)
when (eq 'org-mode (buffer-local-value 'major-mode buffer))
collect (buffer-name buffer))
nil t))
(cond ((derived-mode-p 'org-agenda-mode) (or org-ql-view-buffers-files
org-agenda-contributing-files))
((derived-mode-p 'org-mode) (current-buffer))
(t (user-error "This is not an Org-related buffer: %S" (current-buffer))))))
(provide 'org-ql-find)
;;; org-ql-find.el ends here

View file

@ -1,5 +1,7 @@
;;; org-ql-search.el --- Search commands for org-ql -*- lexical-binding: t; -*- ;;; org-ql-search.el --- Search commands for org-ql -*- lexical-binding: t; -*-
;; Copyright (C) 2019-2023 Adam Porter
;; Author: Adam Porter <adam@alphapapa.net> ;; Author: Adam Porter <adam@alphapapa.net>
;; Url: https://github.com/alphapapa/org-ql ;; Url: https://github.com/alphapapa/org-ql
@ -30,16 +32,72 @@
(require 'cl-lib) (require 'cl-lib)
(require 'dash) (require 'dash)
(require 'f)
(require 'map)
(require 'org-super-agenda) (require 'org-super-agenda)
(require 's) (require 's)
(require 'org-ql) (require 'org-ql)
(require 'org-ql-view) (require 'org-ql-view)
(declare-function org-ql--normalize-query "org-ql" t t)
;;;; Compatibility
(defalias 'org-ql-search--link-heading-search-string
(cond ((fboundp 'org-link--normalize-string) #'org-link--normalize-string)
((fboundp 'org-link-heading-search-string) #'org-link-heading-search-string)
((fboundp 'org-make-org-heading-search-string) #'org-make-org-heading-search-string)
(t (error "org-ql: Unable to define alias `org-ql-search--link-heading-search-string'. This may affect links in dynamic blocks. Please report this as a bug"))))
(defalias 'org-ql-search--org-make-link-string
(cond ((fboundp 'org-link-make-string) #'org-link-make-string)
((fboundp 'org-make-link-string) #'org-make-link-string)
(t (error "org-ql: Unable to define alias `org-ql-search--org-make-link-string'. Please report this as a bug"))))
(defalias 'org-ql-search--org-link-store-props
(cond ((fboundp 'org-link-store-props) #'org-link-store-props)
((fboundp 'org-store-link-props) #'org-store-link-props)
(t (error "org-ql: Unable to define alias `org-ql-search--org-link-store-props'. Please report this as a bug"))))
(defalias 'org-ql--org-hide-archived-subtrees
(if (version<= "9.6" org-version)
'org-fold-hide-archived-subtrees
'org-hide-archived-subtrees))
(defalias 'org-ql--org-show-context
(if (version<= "9.6" org-version)
'org-fold-show-context
'org-show-context))
;;;; Variables ;;;; Variables
(defvar org-ql-block-header nil (defvar org-ql-block-header nil
"An optional string to override the default header in `org-ql-block' agenda blocks.") "Optional string overriding default header in `org-ql-block' agenda blocks.")
;;;; Customization
(defgroup org-ql-search nil
"Options for `org-ql-search' commands."
:group 'org-ql)
(defcustom org-ql-search-directories-files-regexp "\.org$"
"Regular expression to match Org filenames in `org-directory'.
Files matching this regexp will be searched. By default,
\".org\" files are matched, but you may also select to include
\".org_archive\" files, or use a custom regexp."
:type '(radio (const :tag "Normal \".org\" files" :value "\.org$")
(const :tag "Also include \".org_archive\" files" "\.org\\(_archive\\)?$")
(string :tag "Custom regular expression")))
(defcustom org-ql-search-directories-files-recursive nil
"Recurse into subdirectories by default in `org-ql-search-directories-files'.
This should probably be disabled by default, because
e.g. `org-directory' may include deeply nested directories of
non-Org files, such as a \".git\" directory, Org attachments
directories, etc, which would make it slow to list the
`org-directory' files recursively."
:type 'boolean)
;;;; Commands ;;;; Commands
@ -49,8 +107,8 @@
The tree will show the lines where the query matches, and any The tree will show the lines where the query matches, and any
other context defined in `org-show-context-detail', which see. other context defined in `org-show-context-detail', which see.
QUERY is an `org-ql' query sexp (quoted, since this is a QUERY is an `org-ql' query in either sexp or string form (see
function). BUFFER defaults to the current buffer. Info node `(org-ql)Queries').
When KEEP-PREVIOUS is non-nil (interactively, with prefix), the When KEEP-PREVIOUS is non-nil (interactively, with prefix), the
outline is not reset to the overview state before finding outline is not reset to the overview state before finding
@ -58,7 +116,7 @@ matches, which allows stacking calls to this command.
Runs `org-occur-hook' after making the sparse tree." Runs `org-occur-hook' after making the sparse tree."
;; Code based on `org-occur'. ;; Code based on `org-occur'.
(interactive (list (read-minibuffer "Query: ") (interactive (list (read-string "Query: ")
:keep-previous current-prefix-arg)) :keep-previous current-prefix-arg))
(with-current-buffer buffer (with-current-buffer buffer
(unless keep-previous (unless keep-previous
@ -66,13 +124,24 @@ Runs `org-occur-hook' after making the sparse tree."
;; we remove existing `org-occur' highlights, just in case. ;; we remove existing `org-occur' highlights, just in case.
(org-remove-occur-highlights nil nil t) (org-remove-occur-highlights nil nil t)
(org-overview)) (org-overview))
(let ((num-results 0)) (let ((num-results 0)
(query (pcase-exhaustive query
((and (pred stringp)
(rx bos (0+ blank) (or "(" "\"")))
;; Read sexp query from string.
(read query))
((pred stringp)
;; Parse string query into sexp query.
(org-ql--query-string-to-sexp query))
((pred listp)
;; Sexp query.
query))))
(org-ql-select buffer query (org-ql-select buffer query
:action (lambda () :action (lambda ()
(org-show-context 'occur-tree) (org-ql--org-show-context 'occur-tree)
(cl-incf num-results))) (cl-incf num-results)))
(unless org-sparse-tree-open-archived-trees (unless org-sparse-tree-open-archived-trees
(org-hide-archived-subtrees (point-min) (point-max))) (org-ql--org-hide-archived-subtrees (point-min) (point-max)))
(run-hooks 'org-occur-hook) (run-hooks 'org-occur-hook)
(unless (get-buffer-window buffer) (unless (get-buffer-window buffer)
(pop-to-buffer buffer)) (pop-to-buffer buffer))
@ -91,20 +160,21 @@ Interactively, may also be:
- `buffer': search the current buffer - `buffer': search the current buffer
- `all': search all Org buffers - `all': search all Org buffers
- `agenda': search buffers returned by the function `org-agenda-files' - `agenda': search buffers returned by the function `org-agenda-files'
- An expression which evaluates to a list of files/buffers - `directory': search Org files in `org-directory'
- A space-separated list of file or buffer names - A space-separated list of file or buffer names
QUERY: An `org-ql' query in either sexp or \"plain string\" QUERY: An `org-ql' query in either sexp or non-sexp form (see
form (see documentation). Info node `(org-ql)Queries').
SUPER-GROUPS: An `org-super-agenda' group set. See variable SUPER-GROUPS: An `org-super-agenda' group set. See variable
`org-super-agenda-groups'. `org-super-agenda-groups' and Info node `(org-super-agenda)Group
selectors'.
NARROW: When non-nil, don't widen buffers before NARROW: When non-nil, don't widen buffers before
searching. Interactively, with prefix, leave narrowed. searching. Interactively, with prefix, leave narrowed.
SORT: One or a list of `org-ql' sorting functions, like `date' or SORT: One or a list of `org-ql' sorting functions, like `date' or
`priority'. `priority' (see Info node `(org-ql)Listing / acting-on results').
TITLE: An optional string displayed in the header. TITLE: An optional string displayed in the header.
@ -113,98 +183,242 @@ display the results. By default, the value of
`org-ql-view-buffer' is used, and a new buffer is created if `org-ql-view-buffer' is used, and a new buffer is created if
necessary." necessary."
(declare (indent defun)) (declare (indent defun))
(interactive (list (pcase-exhaustive (completing-read "Buffers/Files: " (interactive (list (org-ql-view--complete-buffers-files)
(list 'buffer 'agenda 'all) (read-string "Query: " (when org-ql-view-query
nil t) (format "%S" org-ql-view-query)))
("agenda" (org-agenda-files)) :narrow (or org-ql-view-narrow (equal current-prefix-arg '(4)))
("all" (--select (equal (buffer-local-value 'major-mode it) 'org-mode) :super-groups (org-ql-view--complete-super-groups)
(buffer-list))) :sort (org-ql-view--complete-sort)))
((or "" "buffer") (current-buffer)) ;; NOTE: Using `with-temp-buffer' is a hack to work around the fact that `make-local-variable'
((and form (guard (rx bos "("))) (-flatten (eval (read form)))) ;; does not work reliably from inside a `let' form when the target buffer is current on entry
(else (s-split (rx (1+ space)) else))) ;; to or exit from the `let', even though `make-local-variable' is actually done in
(read-string "Query: ") ;; `org-ql-view--display'. So we do all this within a temp buffer, which works around it.
:narrow (eq current-prefix-arg '(4)) (with-temp-buffer
:super-groups (when (bound-and-true-p org-super-agenda-auto-selector-keywords) (let* ((query (cl-etypecase query
(pcase (completing-read "Group by: " (string (if (or (string-prefix-p "(" query)
(append (list "Don't group" (string-prefix-p "\"" query))
"Global super-groups") ;; Read sexp query.
(cl-loop for type in org-super-agenda-auto-selector-keywords (read query)
collect (substring (symbol-name type) 6)))
nil t)
("Global super-groups" org-super-agenda-groups)
((or "" "Don't group") nil)
(property (list (list (intern (concat ":auto-" property)))))))
:sort (pcase (completing-read "Sort by: "
(list "Don't sort"
"date"
"deadline"
"priority"
"scheduled"
"todo")
nil t)
((or "" "Don't sort") nil)
(sort (intern sort)))))
(let* ((query (cl-etypecase query
(string (if (string-match-p (rx bos (1+ alpha) ":") query)
;; Parse non-sexp query into sexp query. ;; Parse non-sexp query into sexp query.
(org-ql--plain-query query) (org-ql--query-string-to-sexp query)))
;; Read sexp query. (list query)))
(read query))) (results (org-ql-select buffers-files query
(list query))) :action 'element-with-markers
(results (org-ql-select buffers-files query :narrow narrow
:action 'element-with-markers :sort sort))
:narrow narrow (strings (-map #'org-ql-view--format-element results))
:sort sort)) (buffer (or buffer (format "%s %s*" org-ql-view-buffer-name-prefix (or title query))))
(strings (-map #'org-ql-view--format-element results)) (header (org-ql-view--header-line-format
(buffer (or buffer (format "%s %s*" org-ql-view-buffer-name-prefix (or title query)))) :buffers-files buffers-files :query query :title title))
(header (org-ql-view--header-line-format buffers-files query title)) ;; Bind variables for `org-ql-view--display' to set.
;; Bind variables for `org-ql-view--display' to set. (org-ql-view-buffers-files buffers-files)
(org-ql-view-buffers-files buffers-files) (org-ql-view-query query)
(org-ql-view-query query) (org-ql-view-sort sort)
(org-ql-view-sort sort) (org-ql-view-narrow narrow)
(org-ql-view-narrow narrow) (org-ql-view-super-groups super-groups)
(org-ql-view-super-groups super-groups) (org-ql-view-title title))
(org-ql-view-title title)) (when super-groups
(when super-groups (let ((org-super-agenda-groups (cl-etypecase super-groups
(let ((org-super-agenda-groups super-groups)) (symbol (symbol-value super-groups))
(setf strings (org-super-agenda--group-items strings)))) (list super-groups))))
(org-ql-view--display :buffer buffer :header header (setf strings (org-super-agenda--group-items strings))))
:string (s-join "\n" strings)))) (org-ql-view--display :buffer buffer :header header :strings strings))))
(defun org-ql-search-block (query) ;;;###autoload
"Insert items for QUERY into current buffer. (defun org-ql-search-block (args)
QUERY should be an `org-ql' query form. Intended to be used as a "Insert items for ARGS into current buffer.
user-defined function in `org-agenda-custom-commands'. QUERY Intended to be used as a user-defined function in
corresponds to the `match' item in the custom command form. `org-agenda-custom-commands'. ARGS corresponds to the `match'
item in the custom command form. It should be a list of
arguments which may be applied to `org-ql-select', which see, but
not including its BUFFERS-FILES argument (which is supplied
through the Agenda). An additional `:header' keyword argument
may be supplied as a string, like that supplied to
`org-ql-view--display'.
Like other agenda block commands, it searches files returned by Like other agenda block commands, it searches files returned by
function `org-agenda-files'. Inserts a newline after the block. function `org-agenda-files'. Inserts a newline after the block.
If `org-ql-block-header' is non-nil, it is used as the header If `org-ql-block-header' is non-nil, it is used as the header
string for the block, otherwise a the header is formed string for the block, otherwise the header is formed
automatically from the query." automatically from the query."
(when-let* ((from (org-agenda-files nil 'ifmode)) (pcase-let ((`(,query . ,(map :header :sort)) args)
(items (org-ql-select from query (narrow-p) (old-beg) (old-end))
:action 'element-with-markers))) (when-let* ((from (pcase org-agenda-restrict
;; Not sure if calling the prepare function is necessary, but let's follow the pattern. ('nil (org-agenda-files nil 'ifmode))
(org-agenda-prepare) (_ (prog1 org-agenda-restrict
;; FIXME: `org-agenda--insert-overriding-header' is from an Org version newer than (with-current-buffer org-agenda-restrict
;; I'm using. Should probably declare it as a minimum Org version after upgrading. ;; Narrow the buffer; remember to widen it later.
;; (org-agenda--insert-overriding-header (or org-ql-block-header (org-ql-agenda--header-line-format from query))) (setf old-beg (point-min) old-end (point-max)
(insert (org-add-props (or org-ql-block-header (org-ql-view--header-line-format from query)) narrow-p t)
nil 'face 'org-agenda-structure) "\n") (narrow-to-region org-agenda-restrict-begin org-agenda-restrict-end))))))
;; Calling `org-agenda-finalize' should be unnecessary, because in a "series" agenda, (items (org-ql-select from query
;; `org-agenda-multi' is bound non-nil, in which case `org-agenda-finalize' does nothing. :action 'element-with-markers
;; But we do call `org-agenda-finalize-entries', which allows `org-super-agenda' to work. :narrow narrow-p :sort sort)))
(->> items (when narrow-p
(-map #'org-ql-view--format-element) ;; Restore buffer's previous restrictions.
org-agenda-finalize-entries (with-current-buffer from
insert) (narrow-to-region old-beg old-end)))
(insert "\n"))) ;; Not sure if calling the prepare function is necessary, but let's follow the pattern.
(org-agenda-prepare)
;; FIXME: `org-agenda--insert-overriding-header' is from an Org version newer than
;; I'm using. Should probably declare it as a minimum Org version after upgrading.
;; (org-agenda--insert-overriding-header (or org-ql-block-header (org-ql-agenda--header-line-format from query)))
;; FIXME: Should we really use `org-ql-block-header' AND `header', or just one of them?
(insert (org-add-props (or org-ql-block-header header
(org-ql-view--header-line-format
:buffers-files from :query query))
nil 'face 'org-agenda-structure) "\n")
;; Calling `org-agenda-finalize' should be unnecessary, because in a "series" agenda,
;; `org-agenda-multi' is bound non-nil, in which case `org-agenda-finalize' does nothing.
;; But we do call `org-agenda-finalize-entries', which allows `org-super-agenda' to work.
;; However, `org-agenda-finalize-entries' sorts entries with `org-entries-lessp', which
;; overrides the sorting `org-ql' has already done, so we rebind `org-entries-lessp' to
;; prevent it from affecting sort order. (Ideally we would let `org-entries-lessp'
;; handle sorting, but that's not possible, because we can't add the `type' text property
;; it uses to sort entries, because the design of org-ql and org-agenda is fundamentally
;; different. So we have to do the sorting ourselves.)
(cl-letf (((symbol-function 'org-entries-lessp) #'ignore))
(->> items
(-map #'org-ql-view--format-element)
org-agenda-finalize-entries
insert))
(insert "\n"))))
;;;###autoload ;;;###autoload
(defalias 'org-ql-block 'org-ql-search-block) (defalias 'org-ql-block 'org-ql-search-block)
;;;; Dynamic blocks
;; This section implements support for Org dynamic blocks. See Info node `(org)Dynamic blocks'.
(require 'org-table)
(cl-defun org-dblock-write:org-ql (params)
"Insert content for org-ql dynamic block at point according to PARAMS.
Valid parameters include:
: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
this (must be a single line in the Org buffer):
#+BEGIN: org-ql :query (todo \"UNDERWAY\")
:columns (priority todo heading) :sort (priority date)
:ts-format \"%Y-%m-%d %H:%M\""
(-let* (((&plist :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"))))
;; 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)
(let ((normalized-heading
(org-ql-search--link-heading-search-string (org-element-property :raw-value element))))
(org-ql-search--org-make-link-string normalized-heading (org-link-display-format normalized-heading)))))
(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 (current-buffer)
:where query
:select '(org-ql-view--resolve-element-properties
(org-element-headline-parser (line-end-position)))
: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))))
;;;; Functions
(defvar org-ql-search-directories-files-error
;; Workaround to silence byte-compiler which thinks having this string in an
;; argument's default value form is a too-long docstring.
"No DIRECTORIES given, and `org-directory' doesn't exist")
(cl-defun org-ql-search-directories-files
(&key (directories
(if (file-exists-p org-directory)
(list org-directory)
(user-error org-ql-search-directories-files-error)))
(recurse org-ql-search-directories-files-recursive)
(regexp org-ql-search-directories-files-regexp))
"Return list of matching files in DIRECTORIES.
When RECURSE is non-nil, recurse into subdirectories. When
REGEXP is non-nil, only return files that match REGEXP."
(let ((files (->> directories
(--map (f-files it nil recurse))
-flatten)))
(if regexp
(--select (string-match regexp it)
files)
files)))
;;;; Footer ;;;; Footer
(provide 'org-ql-search) (provide 'org-ql-search)

File diff suppressed because it is too large Load diff

2792
org-ql.el

File diff suppressed because it is too large Load diff

2230
org-ql.info Normal file

File diff suppressed because it is too large Load diff

16
tests/data-file-tags.org Normal file
View file

@ -0,0 +1,16 @@
# This file is currently used to test org-file-tags.
#+FILETAGS: :food:
* Fruit :fruit:
** Blueberry
** Strawberry
* Vegetable :vegetable:
** Broccoli
** Potato

10
tests/data-links.org Normal file
View file

@ -0,0 +1,10 @@
* Alpha
Let us link to: [[id:74d357ac-fb9c-40d1-a63f-eca8a227321d][Bravo [a phrase in brackets]]].
* Bravo [a phrase in brackets]
:PROPERTIES:
:ID: 74d357ac-fb9c-40d1-a63f-eca8a227321d
:END:
* Charlie

29
tests/data-src.org Normal file
View file

@ -0,0 +1,29 @@
#+title: org-ql test data for ~src~ predicate
* Alpha
#+begin_src elisp
(message "foo")
#+end_src
#+begin_src python
print("foo")
#+end_src
#+begin_src js
console.log("foo")
#+end_src
* Bravo
#+begin_src elisp
(message "bar")
#+end_src
#+begin_src python
print("bar")
#+end_src
* Charlie
This entry has no source block.

29
tests/data-ts.org Normal file
View file

@ -0,0 +1,29 @@
#+title: Timestamp-specific tests
/Timestamps in this file are active ones./
* Single-timestamp ranges
** Single-timestamp, without repeater
<2024-06-25 Tue 08:00-09:00>
** Single-timestamp, with repeater (deadline)
DEADLINE: <2024-06-25 Tue 08:00-09:00 ++7d>
* Multi-timestamp ranges
/Not sure that it would make sense to use repeaters for this kind of range./
** Multi-timestamp, without repeater
<2024-06-25 Tue 08:00>--<2024-06-26 Wed 08:00>
* Day-of-week abbreviations
** French
<2024-07-12 ven.>
* Canary
/This entry should never be matched./

View file

@ -1,38 +1,34 @@
#+TODO: TODO TODAY NEXT STARTED IN-PROGRESS UNDERWAY WAITING SOMEDAY MAYBE CHECK | DONE CANCELED #+TODO: TODO TODAY NEXT STARTED IN-PROGRESS UNDERWAY WAITING SOMEDAY MAYBE CHECK | DONE CANCELED
* Test data # Will try to open the agenda view as if it was [2017-07-05 Wed]
Rather than using my personal agenda every time I want to take a screenshot, how about this. * TODO [#A] Take over the universe :universe:ambition:
Will try to open the agenda view as if it was [2017-07-05 Wed]
** TODO [#A] Take over the universe :universe:ambition:
DEADLINE: <2017-07-15 Sat -1m> DEADLINE: <2017-07-15 Sat -1m>
:PROPERTIES: :PROPERTIES:
:agenda-group: plans :agenda-group: plans
:CATEGORY: ambition :CATEGORY: ambition
:END: :END:
*** TODO [#A] Take over the world :world: ** TODO [#A] Take over the world :world:
DEADLINE: <2017-07-07 Fri> DEADLINE: <2017-07-07 Fri>
I'd like to be finished with this before the weekend... I'd like to be finished with this before the weekend...
**** TODO [#A] Skype with president of Antarctica :world:meetings: *** TODO [#A] Skype with president of Antarctica :world:meetings:
SCHEDULED: <2017-07-04 Tue 21:00> SCHEDULED: <2017-07-04 Tue 21:00>
Not sure what his timezone is... Not sure what his timezone is...
*** TODO [#B] Take over Mars ** TODO [#B] Take over Mars
**** TODO Visit Mars :space:travel:planet: *** TODO Visit Mars :space:travel:planet:
DEADLINE: <2017-09-20 Wed -3m> DEADLINE: <2017-09-20 Wed -3m>
Ah, the red planet... Ah, the red planet...
*** TODO [#C] Take over the moon ** TODO [#C] Take over the moon
**** WAITING Visit the moon :space:travel: *** WAITING Visit the moon :space:travel:
DEADLINE: <2017-08-27 Sun -2m> DEADLINE: <2017-08-27 Sun -2m>
:LOGBOOK: :LOGBOOK:
- State "WAITING" from [2017-07-24 Mon 19:01] - State "WAITING" from [2017-07-24 Mon 19:01]
@ -40,16 +36,16 @@ DEADLINE: <2017-08-27 Sun -2m>
Just waiting on that callback from NASA... Just waiting on that callback from NASA...
*** TODO Practice leaping tall buildings in a single bound :personal: ** TODO Practice leaping tall buildings in a single bound :personal:
SCHEDULED: <2017-07-05 Wed +2d> SCHEDULED: <2017-07-05 Wed .+2d/3d>
:PROPERTIES: :PROPERTIES:
:STYLE: habit :STYLE: habit
:END: :END:
*** TODO [#B] Renew membership in supervillain club ** TODO [#B] Renew membership in supervillain club
DEADLINE: <2017-07-10 Mon -1w> DEADLINE: <2017-07-10 Mon 23:59 -1w>
*** DONE [#B] Learn universal sign language ** DONE [#B] Learn universal sign language
CLOSED: [2017-07-05 Wed 03:02] CLOSED: [2017-07-05 Wed 03:02]
:PROPERTIES: :PROPERTIES:
:ID: 729de245-75fa-43b4-845a-57af61109485 :ID: 729de245-75fa-43b4-845a-57af61109485
@ -60,58 +56,60 @@ CLOSED: [2017-07-05 Wed 03:02]
CLOCK: [2017-07-05 Wed 02:00]--[2017-07-05 Wed 03:02] => 1:02 CLOCK: [2017-07-05 Wed 02:00]--[2017-07-05 Wed 03:02] => 1:02
:END: :END:
** TODO Order a pizza :food:dinner: * TODO Order a pizza :food:dinner:
SCHEDULED: <2017-07-05 Wed 18:00> SCHEDULED: <2017-07-05 Wed 18:00>
:PROPERTIES: :PROPERTIES:
:Effort: 5 :Effort: 5
:END: :END:
** TODO [#C] Get haircut :personal:@town: * TODO [#C] Get haircut :personal:@town:
SCHEDULED: <2017-07-05 Wed> SCHEDULED: <2017-07-05 Wed>
Should probably do this before I take over the world. Want to look my best. (Not that it will matter once I'm in charge.) Should probably do this before I take over the world. Want to look my best. (Not that it will matter once I'm in charge.)
** TODO [#B] Internet :bills: * TODO [#B] Internet :bills:
DEADLINE: <2017-07-21 Fri -1m> DEADLINE: <2017-07-21 Fri -1m>
** TODO [#A] Spaceship lease :bills:spaceship: * TODO [#A] Spaceship lease :bills:spaceship:
DEADLINE: <2017-08-01 Tue -1m> DEADLINE: <2017-08-01 Tue -1m>
:PROPERTIES: :PROPERTIES:
:agenda-group: bills :agenda-group: bills
:END: :END:
** TODO [#B] Fix flux capacitor :spaceship:shopping:@computer: * TODO [#B] Fix flux capacitor :spaceship:shopping:@computer:
SCHEDULED: <2017-07-05 Wed> SCHEDULED: <2017-07-05 Wed>
If I don't, the frobnicator will probably fall off halfway to Mars... If I don't, the frobnicator will probably fall off halfway to Mars...
Gotta buy one first, though. Gotta buy one first, though. [[https://example.com/][This one]] looks suitable.
** Recurring * Recurring
:PROPERTIES: :PROPERTIES:
:agenda-group: recurring :agenda-group: recurring
:END: :END:
*** CHECK /r/emacs :website:Emacs: ** CHECK /r/emacs :website:Emacs:
DEADLINE: <2017-07-05 Wed +1w> DEADLINE: <2017-07-05 Wed .+1w>
*** TODO Shop for groceries :food:shopping:@town: + [[http://reddit.com/r/emacs][Link to /r/emacs]]
** TODO Shop for groceries :food:shopping:@town:
SCHEDULED: <2017-07-05 Wed +1w> SCHEDULED: <2017-07-05 Wed +1w>
:PROPERTIES: :PROPERTIES:
:Effort: 30 :Effort: 30
:END: :END:
*** Sunrise/sunset ** Sunrise/sunset
%%(org-super-agenda--test-diary-sunrise) %%(org-super-agenda--test-diary-sunrise)
%%(org-super-agenda--test-diary-sunset) %%(org-super-agenda--test-diary-sunset)
** Ideas * Ideas
:PROPERTIES: :PROPERTIES:
:CATEGORY: ideas :CATEGORY: ideas
:END: :END:
*** SOMEDAY Rewrite Emacs in Common Lisp :Emacs:elisp:computers:software:programming: ** SOMEDAY Rewrite Emacs in Common Lisp :Emacs:elisp:computers:software:programming:
SCHEDULED: <2017-07-05 Wed> SCHEDULED: <2017-07-05 Wed>
:LOGBOOK: :LOGBOOK:
- State "SOMEDAY" from "MAYBE" [2017-07-24 Mon 18:59] - State "SOMEDAY" from "MAYBE" [2017-07-24 Mon 18:59]
@ -120,447 +118,9 @@ SCHEDULED: <2017-07-05 Wed>
I mean, since no one has ever tried doing it before... I mean, since no one has ever tried doing it before...
*** SOMEDAY Write a symphony :music: ** SOMEDAY Write a symphony :music:
:PROPERTIES: :PROPERTIES:
:agenda-group: plans :agenda-group: plans
:END: :END:
I don't know when I'll get to this, so it's undated. I don't know when I'll get to this, so it's undated.
* Code
#+BEGIN_SRC elisp
(cl-defun ap/org-tweak-timestamps (&key (offset 0) epoch-ts)
"Advance all timestamps in the current buffer as if the earliest one was on today.
OFFSET changes which timestamp (in chronological order) is set to
today. Or, if EPOCH-TS is non-nil, use it as the new zero-point
for today."
(let* ((tss (->> (org-with-wide-buffer
(goto-char (point-min))
(cl-loop while (re-search-forward org-ts-regexp-both nil t)
collect (ts-parse-org (match-string 0))))
(-sort #'ts<)))
(epoch-ts (if epoch-ts
(ts-parse-org epoch-ts)
(nth offset tss)))
(difference-secs (ts-diff (ts-now) epoch-ts))
(days (floor (/ difference-secs 86400))))
(org-with-wide-buffer
(goto-char (point-min))
(while (re-search-forward org-ts-regexp-both nil t)
(let* ((ts (ts-parse-org (match-string 0)))
(timed-p (string-match-p (rx (repeat 2 digit) ":" (repeat 2 digit) (or ">" "]")) (match-string 0)))
(type (cond ((string-prefix-p "<" (match-string 0)) 'active)
((string-prefix-p "[" (match-string 0)) 'inactive)
(t (error "Unknown ts type"))))
(brackets (cl-ecase type
('active (cons "<" ">"))
('inactive (cons "[" "]"))))
(format-string (concat (car brackets)
(if timed-p
"%Y-%m-%d %a %H:%M"
"%Y-%m-%d %a")
(cdr brackets)))
(new-ts (ts-adjust 'day days ts))
(new-ts-string (ts-format format-string new-ts)))
(replace-match new-ts-string t t nil 0))))
(message "Tweaked from epoch: %s" (ts-format epoch-ts))))
#+END_SRC
#+BEGIN_SRC elisp
(org-time-string-to-absolute (org-entry-get (point) "SCHEDULED"))
#+END_SRC
#+BEGIN_SRC elisp :results none
;; Setup code
(require 'org-super-agenda)
(org-super-agenda-mode 1)
(require 'org-habit)
(setq org-todo-keywords
'((sequence "TODO(t!)" "TODAY(a!)" "NEXT(n!)" "STARTED(s!)" "IN-PROGRESS(p!)" "UNDERWAY(u!)" "WAITING(w@)" "SOMEDAY(o!)" "MAYBE(m!)" "|" "DONE(d@)" "CANCELED(c@)")
(sequence "CHECK(k!)" "|" "DONE(d@)")
(sequence "TO-READ(r!)" "READING(R!)" "|" "HAVE-READ(d@)")
(sequence "TO-WATCH(!)" "WATCHING(!)" "SEEN(!)")))
(with-current-buffer "test.org" (revert-buffer))
(defmacro with-org-today-date (date &rest body)
"Run BODY with the `org-today' function set to return simply DATE.
DATE should be a date-time string (both date and time must be included)."
(declare (indent defun))
`(let ((day (date-to-day ,date))
(orig (symbol-function 'org-today)))
(unwind-protect
(progn
(fset 'org-today (lambda () day))
,@body)
(fset 'org-today orig))))
#+END_SRC
#+BEGIN_SRC elisp :results none
(defun diary-sunrise ()
(let ((dss (diary-sunrise-sunset)))
(with-temp-buffer
(insert dss)
(goto-char (point-min))
(search-forward ",")
(buffer-substring (point-min) (match-beginning 0)))))
(defun diary-sunset ()
(let ((dss (diary-sunrise-sunset))
start end)
(with-temp-buffer
(insert dss)
(goto-char (point-min))
(search-forward ", ")
(setq start (match-end 0))
(search-forward " at")
(setq end (match-beginning 0))
(goto-char start)
(capitalize-word 1)
(buffer-substring start end))))
#+END_SRC
*Note:* Removing tests from here as they're added to =test.el=.
#+BEGIN_SRC elisp
(org-super-agenda--test-with-org-today-date "2017-07-05 00:00"
(let ((org-agenda-files (list "~/src/emacs/org-super-agenda/test/test.org"))
(org-agenda-span 'day)
(org-super-agenda-groups
'((:name "Time grid items in all-uppercase with RosyBrown1 foreground"
:time-grid t
:transformer (--> it
(upcase it)
(propertize it 'face '(:foreground "RosyBrown1"))))
(:name "Priority >= C items underlined, on black background"
:face (:background "black" :underline t)
:not (:priority>= "C")
:order 100))))
(org-agenda nil "a")))
(org-super-agenda--test-with-org-today-date "2017-07-05 00:00"
(let ((org-agenda-files (list "~/src/emacs/org-super-agenda/test/test.org"))
(org-agenda-span 'day)
(org-super-agenda-groups
'((:name none
:time-grid t)
(:name "Should be all-uppercase RosyBrown1 on black"
:face (:background "black" :foreground "RosyBrown1")
:transformer #'upcase
:not (:priority>= "C")
:order 100))))
(org-agenda nil "a")))
(with-org-today-date "2017-07-05 00:00"
(let ((org-agenda-files (list "~/src/org-super-agenda/test/test.org"))
(org-agenda-span 'day)
(org-super-agenda-groups
'((:name none
:time-grid t)
(:name none
:not (:priority>= "C")
:order 100))))
(org-agenda nil "a")))
(with-org-today-date "2017-07-05 00:00"
(let ((org-agenda-files (list "~/src/org-super-agenda/test/test.org"))
(org-agenda-span 'day)
(org-super-agenda-groups
'((:name "Items with child TODOs"
:children todo))))
(org-agenda nil "a")))
(with-org-today-date "2017-07-05 00:00"
(let ((org-agenda-files (list "~/src/org-super-agenda/test/test.org"))
(org-agenda-span 'day)
(org-super-agenda-groups
'((:name "Items with child TODOs"
:children "CHECK"))))
(org-agenda nil "a")))
(with-org-today-date "2017-07-05 00:00"
(let ((org-agenda-files (list "~/src/org-super-agenda/test/test.org"))
(org-agenda-span 'day)
(org-agenda-custom-commands
'(("u" "Super view"
((agenda "" ((org-super-agenda-groups
'((:name "Today"
:time-grid t
:scheduled today
:deadline today)))))
(todo "" ((org-super-agenda-groups
'((:name "Projects"
:children t)
(:discard (:anything t)))))))))))
(org-agenda nil "u")))
(with-org-today-date "2017-07-05 00:00"
(let ((org-agenda-files (list "~/src/org-super-agenda/test/test.org"))
(org-agenda-span 'day)
(org-agenda-custom-commands
'(("u" "Super view"
((agenda "" ((org-super-agenda-groups
'((:name "Today"
:time-grid today)))))
(todo "" ((org-super-agenda-groups
'((:name "Projects"
:children t)
(:discard (:anything t)))))))))))
(org-agenda nil "u")))
(with-org-today-date "2017-07-05 00:00"
(let ((org-agenda-files (list "~/src/org-super-agenda/test/test.org"))
(org-agenda-span 'day)
(org-agenda-custom-commands
'(("u" "Super view"
((agenda "" ((org-super-agenda-groups
'((:name "Schedule"
:time-grid t
:date today)
(:name "Due today"
:deadline today)
(:name "Due soon"
:deadline t)))))
(todo "" ((org-agenda-overriding-header "")
(org-super-agenda-groups
'((:name "Projects"
:children t)
(:discard (:anything t)))))))))))
(org-agenda nil "u")))
(with-org-today-date "2017-07-05 00:00"
(let ((org-agenda-files (list "~/src/org-super-agenda/test/test.org"))
(org-agenda-span 'day)
(org-super-agenda-groups
'((:scheduled (before "2017-07-06")))))
(org-agenda nil "a")))
#+END_SRC
#+BEGIN_SRC elisp
(with-org-today-date "2017-07-05 00:00"
(let ((org-super-agenda-groups
'((:todo "WAITING")))
(org-agenda-files (list "~/src/org-super-agenda/test/test.org")))
(org-todo-list)))
(with-org-today-date "2017-07-05 00:00"
(let ((org-super-agenda-groups
'((:todo "SOMEDAY")))
(org-agenda-files (list "~/src/org-super-agenda/test/test.org")))
(org-tags-view nil "Emacs")))
(with-org-today-date "2017-07-05 00:00"
(let ((org-super-agenda-groups
'((:todo "CHECK")))
(org-agenda-files (list "~/src/org-super-agenda/test/test.org")))
;; org-search-view doesn't seem to set the todo-state property, so the matcher doesn't work
(org-search-view nil "Emacs")))
(with-org-today-date "2017-07-05 00:00"
(let ((org-super-agenda-groups
'((:regexp ("moon" "mars"))))
(org-agenda-files (list "~/src/org-super-agenda/test/test.org")))
(org-search-view nil "space")))
(with-org-today-date "2017-07-05 00:00"
(let ((org-super-agenda-groups
'((:todo "SOMEDAY")))
(org-agenda-files (list "~/src/org-super-agenda/test/test.org")))
(org-agenda-list nil nil 'day)))
#+END_SRC
** Agenda examining
This helps a lot.
#+BEGIN_SRC elisp
(defun data-debug-show-string-with-properties (s)
(with-current-buffer (get-buffer-create "argh")
(erase-buffer)
(print s (current-buffer))
;; Convert string reader representations to plain lists that can be set
(cl-loop for (match replace) in '(("#(" "'(")
("#<" "'(")
(">" ")"))
do (progn
(goto-char (point-min))
(while (search-forward match nil 'noerror)
(replace-match replace 'fixedcase 'literal))))
;; Surround content in a list which `argh' is set to, then eval
;; the buffer to do it
(goto-char (point-min))
(insert "(setq argh (list '")
(delete-forward-char 2)
(goto-char (point-max))
(insert "))")
;; Okay, sure, eval'ing the buffer is dangerous and bad and wrong.
;; But this is the only way I can find to make this work. (Maybe
;; `text-properties-at' could be used to get actual lists...)
(eval-buffer)
(data-debug-show-stuff argh "argh")
;; (switch-to-buffer (current-buffer))
))
(defun data-debug-show-current-line-with-properties ()
(interactive)
(data-debug-show-string-with-properties (buffer-substring (line-beginning-position) (line-end-position))))
(with-current-buffer "*Org Agenda*"
(data-debug-show-string-with-properties (seq-subseq (split-string (buffer-string) "\n")
0 5)))
#+END_SRC
** Agenda censoring
For sharing screenshots of the agenda without revealing private data.
#+BEGIN_SRC elisp
(defun org-agenda-sharpie ()
"Censor the text of items in the agenda."
(interactive)
(let (regexp old-heading new-heading properties)
;; Save face properties of line in agenda to reapply to changed text
(setq properties (text-properties-at (point)))
;; Go to source buffer
(org-with-point-at (org-find-text-property-in-string 'org-marker
(buffer-substring (line-beginning-position)
(line-end-position)))
;; Save old heading text and ask for new text
(line-beginning-position)
(unless (org-at-heading-p)
;; Not sure if necessary
(org-back-to-heading))
(setq old-heading (when (looking-at org-complex-heading-regexp)
(match-string 4))))
(setq new-heading (read-from-minibuffer "Overwrite visible heading with: "))
(add-text-properties 0 (length new-heading) properties new-heading)
;; Back to agenda buffer
(save-excursion
(when (and old-heading new-heading)
;; Replace agenda text
(let ((inhibit-read-only t))
(goto-char (line-beginning-position))
(when (search-forward old-heading (line-end-position))
(replace-match new-heading 'fixedcase 'literal)))))))
#+END_SRC
** Auto grouping
#+BEGIN_SRC elisp
(with-org-today-date "2017-07-05 00:00"
(let ((org-super-agenda-groups
'((:auto-group t)))
(org-agenda-files (list "~/src/org-super-agenda/test/test.org")))
(org-agenda-list nil nil 'day)))
#+END_SRC
** Auto categories
#+BEGIN_SRC elisp
(let ((org-super-agenda-groups
'((:auto-category t))))
(org-agenda-list nil nil 'day))
#+END_SRC
** Date
#+BEGIN_SRC elisp
(with-org-today-date "2017-07-05 00:00"
(-let* ((org-agenda-files (list "~/src/org-super-agenda/test/test.org"))
(org-agenda-span 'day)
((sec minute hour day month year dow dst utcoff) (list 0 0 0 5 7 2017 3 t nil))
(last-day-of-month
;; A hack that seems to work fine
(1+ (calendar-last-day-of-month month year)))
(target-date (format "%d-%02d-%02d" year month last-day-of-month))
(org-super-agenda-groups
`((:deadline (before ,target-date))
(:discard (:anything t)))))
(org-todo-list)))
(with-org-today-date "2017-07-05 00:00"
(-let* ((org-agenda-files (list "~/src/org-super-agenda/test/test.org"))
(org-agenda-span 'day)
((sec minute hour day month year dow dst utcoff) (list 0 0 0 5 7 2017 3 t nil))
(last-day-of-month (calendar-last-day-of-month month year))
(target-date (format "%d-%02d-%02d" year month last-day-of-month))
(org-super-agenda-groups
`((:deadline (before ,target-date))
(:discard (:anything t)))))
(org-todo-list)))
#+END_SRC
** Effort
#+BEGIN_SRC elisp
(with-org-today-date "2017-07-05 00:00"
(let ((org-agenda-files (list "~/src/org-super-agenda/test/test.org"))
(org-super-agenda-groups
'((:effort< "0:06"))))
(org-agenda-list nil nil 'day)))
#+END_SRC
** Misc
*** let-plist
I don't need this right now, but it might come in handy here or elsewhere.
#+BEGIN_SRC elisp
(defmacro osa/let-plist (keys plist &rest body)
"`cl-destructuring-bind' without the boilerplate for plists."
;; See https://emacs.stackexchange.com/q/22542/3871
;; I really don't understand why Emacs doesn't have this already.
;; So many things come close to it: pcase, pcase-let, map-let,
;; cl-destructuring-bind, -let...but none of them let you simply
;; bind all the values of a plist to variables with the same name as
;; their keys. You always have to type the name of the key twice.
;; For example, compare these two forms:
;; (-let (((&keys :from from :to to :date date :subject subject) email))
;; (list from to date subject))
;; (osa/let-plist (:from :to :date :subject) email
;; (list from to date subject))
;; Now, sure, sometimes you need to bind values to differently named
;; variables. But when you don't, I know which one I prefer.
(declare (indent defun))
(setq keys (cl-loop for key in keys
collect (intern (replace-regexp-in-string (rx bol ":") ""
(symbol-name key)))))
`(cl-destructuring-bind
(&key ,@keys &allow-other-keys)
,plist
,@body))
#+END_SRC
** Profiling
#+BEGIN_SRC elisp :results none
(defmacro profile-it (times &rest body)
`(let (output)
(dolist (p '("org-super-agenda-" "map" "org-" "string-" "s-" "buffer-" "append" "delq" "map" "list" "car" "save-" "outline-" "delete-dups" "sort" "line-" "nth" "concat" "char-to-string" "rx-" "goto-" "when" "search-" "re-"))
(elp-instrument-package p))
(dotimes (x ,times)
,@body)
(elp-results)
(elp-restore-all)
(point-min)
(forward-line 20)
(delete-region (point) (point-max))
(setq output (buffer-substring-no-properties (point-min) (point-max)))
(kill-buffer)
(delete-window)
output))
#+END_SRC

File diff suppressed because it is too large Load diff