Merge: wip/helm-query-rewriting
It's finally time to merge this branch, which adds non-sexp queries,
updates the readme, and a few other things.
Squashed commit of the following:
commit ee54e31dfa2c3335e4ef5498fc9714ddc093968b
Author: Adam Porter <adam@alphapapa.net>
Date: Sun Oct 6 00:10:19 2019 -0500
WIP: Depend-on/Require dash-functional
commit 42f6a47d86dfb7f8e96f3b1822e17a3eed825897
Author: Adam Porter <adam@alphapapa.net>
Date: Sat Oct 5 23:45:06 2019 -0500
WIP: Update docs
commit eb56e46ed8cd9ad6874dc955375be5efadb4fcf2
Author: Adam Porter <adam@alphapapa.net>
Date: Sat Oct 5 22:04:24 2019 -0500
WIP: Add demo script
commit cdd394f4865cd49791b2fbebb1913d9210aeaf35
Author: Adam Porter <adam@alphapapa.net>
Date: Sat Oct 5 20:24:44 2019 -0500
WIP: Update demo GIF
commit 7f470a7c3c7612b7718dc26044069dc2a6afdff3
Author: Adam Porter <adam@alphapapa.net>
Date: Sat Oct 5 13:02:09 2019 -0500
WIP: (property) Convert keyword properties to strings
I'm a little uncomfortable with how query parsing and processing is
getting spread out among 2 or 3 functions, but handling this in the
plain-query parsing function would require uglier special-case
workarounds, so this seems like the best solution for now.
commit 4e494a03f29a1d0068daa9cddf095dba15252133
Author: Adam Porter <adam@alphapapa.net>
Date: Fri Oct 4 16:25:00 2019 -0500
WIP: Handle query errors, move code, add tags-all, tags& aliases
This prevents query compilation errors from displaying a warning
buffer, especially in the Helm command.
Close to done, but now need to figure out the "property:" predicate,
because its value argument looks like an alternative property rather
than a value, e.g. "property:agenda-group,plans" in which "plans" is
the value for the property "agenda-group".
commit 9d8222d8fa9a584b1ee648c5aa38999200e7c54f
Author: Adam Porter <adam@alphapapa.net>
Date: Thu Oct 3 22:18:29 2019 -0500
WIP: Rewrite (priority) predicate to accept multiple priorities
This commit also fixes a latent bug in the preamble for (priority), which
wasn't being hit because the query (priority) was being rewritten by
pre-process to (priority '>= C).
commit 4900470ba52b0fcf4786ab857e316403dec00481
Author: Adam Porter <adam@alphapapa.net>
Date: Thu Oct 3 20:41:54 2019 -0500
WIP: More documentation
commit 5041a901f6c1071a4233e5671a0926e65e29a5c0
Author: Adam Porter <adam@alphapapa.net>
Date: Thu Oct 3 12:30:50 2019 -0500
WIP: Mention query types for commands
commit bb2d18532cb972a54b5b9056b76b0582eb4cad03
Author: Adam Porter <adam@alphapapa.net>
Date: Thu Oct 3 11:01:56 2019 -0500
WIP: Remove old code
commit 8de048e531bfa9ba7058e7d540aae2d332f9be68
Author: Adam Porter <adam@alphapapa.net>
Date: Thu Oct 3 11:01:03 2019 -0500
WIP: TODO done
commit 6a38fc845aeb05fe3f03174c04a7011830873705
Author: Adam Porter <adam@alphapapa.net>
Date: Thu Oct 3 10:59:45 2019 -0500
WIP: Tidy docstrings
commit 04d0c254fc8694b1363c91a1691f3303fcf7755a
Author: Adam Porter <adam@alphapapa.net>
Date: Thu Oct 3 10:58:21 2019 -0500
WIP: Document plain queries
commit 23dcc9bad4a8e6660e48632a20a04adb2654e20d
Author: Adam Porter <adam@alphapapa.net>
Date: Thu Oct 3 10:27:41 2019 -0500
WIP: Move ts aliases into defpreds, improve docstrings and comments
commit 6ef710f25bbd430b56ce205b8f314b17cd9ac7c3
Author: Adam Porter <adam@alphapapa.net>
Date: Thu Oct 3 10:11:17 2019 -0500
Tidy: Whitespace
commit 1022c4b36fb03a6724d97ba4dd1b5bb68025ed7b
Author: Adam Porter <adam@alphapapa.net>
Date: Thu Oct 3 10:01:53 2019 -0500
WIP: (org-ql-search) Accept plain queries
This way, helm-org-ql and org-ql-search accept queries in the same
format.
commit 1903e8f5684269c272a2ff3984d4d262f41323c5
Author: Adam Porter <adam@alphapapa.net>
Date: Thu Oct 3 09:22:35 2019 -0500
WIP: Add more plain-query tests
commit 9d58e3395e871f3536296ccfbb3901f98416bd9a
Author: Adam Porter <adam@alphapapa.net>
Date: Thu Oct 3 09:17:07 2019 -0500
WIP: Return boolean from --plain-query, and only when needed
commit 3770e18e68eaf776aef6fbb94e6ac5648c869c12
Author: Adam Porter <adam@alphapapa.net>
Date: Thu Oct 3 08:59:55 2019 -0500
WIP: Parse numbers in key/value args
e.g. "ts-a:on=-1" for yesterday, or "ts:on=0" or "ts:on=today" for
today.
commit 0f2b71bb869980f413c7366d1b15fa35f3f6a1c5
Author: Adam Porter <adam@alphapapa.net>
Date: Thu Oct 3 08:59:43 2019 -0500
WIP: Rename plain-query function
commit be410a36f4a1c043de24a2d0d2fbbe22135c3385
Author: Adam Porter <adam@alphapapa.net>
Date: Wed Oct 2 19:21:07 2019 -0500
WIP: Reverse query properly
PEG returns queries backwards for some reason, so reverse them back to
the order they were input in.
commit c184091ac2e96a76696055509ca6245e9a020b03
Author: Adam Porter <adam@alphapapa.net>
Date: Wed Oct 2 19:17:20 2019 -0500
WIP: Fix previous commit
Something weird happens when defining the function that's defined by
the macro in the eval-when block: It seems that I have to eval it
twice before it takes effect. So when I made the previous commit, the
function defined at the time was working properly, but the function
defined at the time was apparently not what was written in the file,
but some intermediate state that had been written before, so I don't
even know what the code was that was working properly.
After some more fiddling, this seems to work properly.
commit 4e7288d494c6cfe69f82f3aea4b88feced7232f7
Author: Adam Porter <adam@alphapapa.net>
Date: Wed Oct 2 18:42:59 2019 -0500
WIP: Handle keyword/value queries
commit f603d199f47c1115cf11f8661c19c73f056b414d
Author: Adam Porter <adam@alphapapa.net>
Date: Tue Oct 1 16:45:33 2019 -0500
WIP: Define pred aliases and input-query function with macros
commit 217ef7dff13e8464baaa50539c82843e48bc3fe8
Author: Adam Porter <adam@alphapapa.net>
Date: Tue Oct 1 16:16:04 2019 -0500
WIP: Tidy: Don't quote the lambda
I don't even know why I did that.
commit 3130f6519d7c21e47a026404e3929f118b003092
Author: Adam Porter <adam@alphapapa.net>
Date: Fri Sep 27 23:20:50 2019 -0500
WIP: Parsing with peg
Seems to be working pretty well.
commit 0762825c7ba8026768aec74b4fffd32b8530c42c
Author: Adam Porter <adam@alphapapa.net>
Date: Tue Sep 10 16:17:50 2019 -0500
WIP: Rewriting Helm queries
Some people are unaccustomed to parentheses, so we'll try to
accommodate them.
This commit is contained in:
parent
cea8028922
commit
f4918b19dc
9 changed files with 1046 additions and 520 deletions
188
notes.org
188
notes.org
|
|
@ -6,6 +6,194 @@
|
|||
|
||||
Note that the built-in sorting only works on Org elements, which is the default ~:action~. So if a different action is used, sorting will not work. In that case, the action should be mapped across the Org element results from outside the ~org-ql~ form.
|
||||
|
||||
** TODO [#C] Test caching
|
||||
|
||||
See notes on 1dce9467f25428b5289d3665cd840820969ed65a. It would be good to test the caching explicitly, at least for some queries, because if I were to completely break it again, in such a way that results were stored but retrieval always failed, the tests wouldn't catch it.
|
||||
|
||||
** TODO [#A] Helm command
|
||||
|
||||
In branch =wip/helm-org-ql=. Works really well, should add it and demonstrate it.
|
||||
|
||||
*** TODO Add
|
||||
|
||||
*** TODO Demonstrate
|
||||
|
||||
*** UNDERWAY Parsing non-Lisp queries
|
||||
|
||||
[2019-09-12 Thu 12:56] Lisp is so much easier to deal with, but some people don't like parentheses. So I'm trying to add a non-Lisp-style query syntax. It gets complicated. The =peg= library helps, but its documentation is sparse and incomplete. This seems to work fairly well for single-token queries, but I'm not sure if I can or should cram it all into one parser, or use separate ones for certain keywords.
|
||||
|
||||
#+BEGIN_SRC elisp
|
||||
(-let* ((input "todo:check|someday")
|
||||
(input "tags:universe+space")
|
||||
(input "heading:\"spaced phrase\"")
|
||||
(input "")
|
||||
(input "heading:\"spaced phrase\"+another")
|
||||
combinator
|
||||
(parsed (peg-parse-string ((predicate (substring keyword) ":" (opt args))
|
||||
(keyword (or "heading" "tags" "todo" "property"))
|
||||
(args (+ (and (or quoted-arg unquoted-arg) (opt separator))))
|
||||
(quoted-arg "\"" unquoted-arg "\"")
|
||||
(unquoted-arg (substring (+ (not (or separator "\"")) (any))))
|
||||
(separator (or (and "|" (action (setf combinator 'or)))
|
||||
(and "+" (action (setf combinator 'and)))
|
||||
(and ":" (action (setf combinator 'arg))))))
|
||||
input 'noerror))
|
||||
((predicate . args) (nreverse parsed)))
|
||||
(when predicate
|
||||
(list :predicate predicate :args args :combinator combinator)))
|
||||
;;=> (:predicate "heading" :args ("spaced phrase" "another" t) :combinator and)
|
||||
#+END_SRC
|
||||
|
||||
I don't know where the =t= is coming from.
|
||||
|
||||
The next step is to make it work with multi-token queries. It needs to handle all of the tokens in one parser so it can handle quoted phrases (if we split on spaces, it would split quoted phrases). But that makes getting the arguments out of it more difficult. Probably need to do something like this:
|
||||
|
||||
#+BEGIN_SRC elisp
|
||||
(-let* ((input "todo:check|someday")
|
||||
(input "tags:universe+space")
|
||||
(input "heading:\"spaced phrase\"")
|
||||
(input "")
|
||||
(input "heading:\"spaced phrase\"+another")
|
||||
combinator
|
||||
(parsed (peg-parse-string ((query (+ (or (and predicate `(pred args -- (list :predicate pred :args args)))
|
||||
(and plain-string `(s -- (list :predicate 'regexp :args s))))
|
||||
(opt (syntax-class whitespace))))
|
||||
(plain-string (substring (+ (not (syntax-class whitespace)) (any))))
|
||||
(predicate (substring keyword) ":" (opt args))
|
||||
(keyword (or "heading" "tags" "todo" "property"))
|
||||
(args (+ (and (or quoted-arg unquoted-arg) (opt separator))))
|
||||
(quoted-arg "\"" unquoted-arg "\"")
|
||||
(unquoted-arg (substring (+ (not (or separator "\"")) (any))))
|
||||
(separator (or (and "|" (action (setf combinator 'or)))
|
||||
(and "+" (action (setf combinator 'and)))
|
||||
(and ":" (action (setf combinator 'arg))))))
|
||||
input 'noerror)))
|
||||
parsed)
|
||||
#+END_SRC
|
||||
|
||||
In which lists are pushed onto the stack and returned, rather than strings. But I don't understand yet exactly how to use the =var= forms to consume input from the "value stack"; I need to study the examples more. I'm also not sure if that will even work with a variable number of arguments.
|
||||
|
||||
This seems to work, but we'll have to parse the args again in a separate step:
|
||||
|
||||
#+BEGIN_SRC elisp
|
||||
(-let* ((input "todo:check|someday")
|
||||
(input "tags:universe+space")
|
||||
(input "heading:\"spaced phrase\"")
|
||||
(input "")
|
||||
(input "heading:\"spaced phrase\"+another")
|
||||
(input "heading:\"spaced phrase\"+another todo:check")
|
||||
combinator
|
||||
(parsed (peg-parse-string ((query (+ (or (and predicate `(pred args -- (list :predicate pred :args args)))
|
||||
(and plain-string `(s -- (list :predicate 'regexp :args s))))
|
||||
(opt (+ (syntax-class whitespace) (any)))))
|
||||
(plain-string (substring (+ (not (syntax-class whitespace)) (any))))
|
||||
(predicate (substring keyword) ":" (opt args))
|
||||
(keyword (or "heading" "tags" "todo" "property"))
|
||||
(args (substring (+ (and (or quoted-arg unquoted-arg) (opt separator)))))
|
||||
(quoted-arg "\"" (+ (not (or separator "\"")) (any)) "\"")
|
||||
(unquoted-arg (+ (not (or separator "\"" (syntax-class whitespace))) (any)))
|
||||
(separator (or (and "|" (action (setf combinator 'or)))
|
||||
(and "+" (action (setf combinator 'and)))
|
||||
(and ":" (action (setf combinator 'arg))))))
|
||||
input 'noerror)))
|
||||
parsed)
|
||||
;;=> (t (:predicate "todo" :args "check") (:predicate "heading" :args "\"spaced phrase\"+another"))
|
||||
#+END_SRC
|
||||
|
||||
Well, a bit of fiddling (lots of trial-and-error required) produced this:
|
||||
|
||||
#+BEGIN_SRC elisp
|
||||
(-let* ((input "todo:check|someday")
|
||||
(input "tags:universe+space")
|
||||
(input "heading:\"spaced phrase\"")
|
||||
(input "")
|
||||
(input "heading:\"spaced phrase\"+another")
|
||||
(input "heading:\"spaced phrase\"+another todo:check")
|
||||
combinator
|
||||
(parsed (peg-parse-string ((query (+ (or (and predicate `(pred args -- (list :predicate pred :args args)))
|
||||
(and plain-string `(s -- (list :predicate 'regexp :args s))))
|
||||
(opt (+ (syntax-class whitespace) (any)))))
|
||||
(plain-string (substring (+ (not (syntax-class whitespace)) (any))))
|
||||
(predicate (substring keyword) ":" (opt args))
|
||||
(keyword (or "heading" "tags" "todo" "property"))
|
||||
(args (list (+ (and (substring (or quoted-arg unquoted-arg)) (opt separator)))))
|
||||
(quoted-arg "\"" (+ (not (or separator "\"")) (any)) "\"")
|
||||
(unquoted-arg (+ (not (or separator "\"" (syntax-class whitespace))) (any)))
|
||||
(separator (or (and "|" (action (setf combinator 'or)))
|
||||
(and "+" (action (setf combinator 'and)))
|
||||
(and ":" (action (setf combinator 'arg))))))
|
||||
input 'noerror)))
|
||||
parsed)
|
||||
;;=> (t (:predicate "todo" :args ("check")) (:predicate "heading" :args ("\"spaced phrase\"" "another")))
|
||||
#+END_SRC
|
||||
|
||||
That seems pretty usable!
|
||||
|
||||
** TODO [#B] Timeline view
|
||||
|
||||
e.g. as mentioned by Samuel Wales at https://lists.gnu.org/archive/html/emacs-orgmode/2019-08/msg00330.html. Prototype code:
|
||||
|
||||
#+BEGIN_SRC elisp
|
||||
(cl-defun org-ql-timeline (buffers-files query)
|
||||
(let ((results
|
||||
(org-ql-select buffers-files
|
||||
query :action
|
||||
(lambda ()
|
||||
(let* ((heading-string
|
||||
(->> (org-element-headline-parser
|
||||
(line-end-position))
|
||||
org-ql--add-markers
|
||||
org-ql-agenda--format-element))
|
||||
(timestamps
|
||||
(cl-loop with limit = (org-entry-end-position)
|
||||
while (re-search-forward org-ts-regexp-both
|
||||
limit t)
|
||||
collect (ts-parse-org (match-string 0))))
|
||||
(timestamp-strings
|
||||
(->> timestamps
|
||||
(-sort #'ts<)
|
||||
(--map (concat " " (ts-format it))))))
|
||||
(s-join "\n" (cons heading-string timestamp-strings))))
|
||||
:sort '(date))))
|
||||
(org-ql-agenda--agenda nil nil :strings results)))
|
||||
|
||||
(org-ql-timeline (org-agenda-files)
|
||||
'(and "Emacs" (ts)))
|
||||
|
||||
;; More timeline-like version, organized by date rather than task.
|
||||
|
||||
(cl-defun org-ql-timeline* (buffers-files query &key filter-ts)
|
||||
(let* ((ts-ht (ht))
|
||||
(results (org-ql-select buffers-files
|
||||
query
|
||||
:action (lambda ()
|
||||
(let* ((heading-string
|
||||
(->> (org-element-headline-parser
|
||||
(line-end-position))
|
||||
org-ql--add-markers
|
||||
org-ql-agenda--format-element))
|
||||
(date-timestamps
|
||||
;; Each one set to 00:00:00.
|
||||
(cl-loop with limit = (org-entry-end-position)
|
||||
while (re-search-forward org-ts-regexp-both
|
||||
limit t)
|
||||
collect (->> (match-string 0)
|
||||
ts-parse-org
|
||||
(ts-apply :hour 0 :minute 0 :second 0)))))
|
||||
(setf date-timestamps (delete-dups date-timestamps))
|
||||
(when filter-ts
|
||||
(setf date-timestamps (cl-remove-if-not filter-ts date-timestamps)))
|
||||
(--each date-timestamps
|
||||
(push heading-string (gethash it ts-ht)))))))
|
||||
(tss-sorted (-sort #'ts< (ht-keys ts-ht)))
|
||||
(strings (cl-loop for ts in tss-sorted
|
||||
collect (concat "\n"
|
||||
(propertize (ts-format "%Y-%m-%d" ts)
|
||||
'face 'org-agenda-structure))
|
||||
append (ht-get ts-ht ts))))
|
||||
(org-ql-agenda--agenda nil nil :strings strings)))
|
||||
#+END_SRC
|
||||
|
||||
** TODO [#A] Outline path in buffers-files arg
|
||||
|
||||
e.g.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue