WIP: Update docstrings, comments, and readme
This commit is contained in:
parent
8e93f4cbb3
commit
9e683e17c1
3 changed files with 146 additions and 200 deletions
202
org-ql.el
202
org-ql.el
|
|
@ -1846,34 +1846,41 @@ With KEYWORDS, return non-nil if its keyword is one of KEYWORDS (a list of strin
|
|||
|
||||
;;;;;; Timestamps
|
||||
|
||||
;; TODO: Remove the _on vars from these arg lists. I think they're not
|
||||
;; NOTE: The underscores before some arguments in these definitions
|
||||
;; prevent "unused lexical variable" warnings, because we pre-process
|
||||
;; them before the functions are called.
|
||||
|
||||
;; TODO: Remove the _underscored vars from these arg lists. I think they're not
|
||||
;; necessary, or shouldn't be, since --pre-process-query should handle them.
|
||||
|
||||
;; NOTE: These docstrings apply to the functions defined by `org-ql--defpref',
|
||||
;; not necessarily to the way users are expected to call them in queries. The
|
||||
;; queries are pre-processed by `org-ql--normalize-query' to handle
|
||||
;; arguments which are constant during a query's execution.
|
||||
;; NOTE: Arguments to these predicates are pre-processed in
|
||||
;; `org-ql--normalize-query' and `org-ql--query-predicate'. Some
|
||||
;; arguments are not to be given by the user in a query,
|
||||
;; e.g. `regexp'. FROM and TO are actually expected to be `ts'
|
||||
;; structs. However, the docstrings are written for users, which
|
||||
;; makes documentation easier to update.
|
||||
|
||||
;; TODO: Update the macro to define a user-facing docstring so I don't
|
||||
;; have to manually update the documentation.
|
||||
|
||||
(org-ql-defpred clocked (&key from to _on)
|
||||
;; The underscore before `on' prevents "unused lexical variable"
|
||||
;; warnings, because we pre-process that argument in a macro before
|
||||
;; this function is called.
|
||||
"Return non-nil if current entry was clocked in given period.
|
||||
If no arguments are specified, return non-nil if entry has any
|
||||
timestamp.
|
||||
;; This string is common to these predicates and is used in
|
||||
;; documentation; keeping it here should make it easier to update:
|
||||
"If FROM, return non-nil if entry's timestamp is on or after FROM.
|
||||
|
||||
If FROM, return non-nil if entry has a timestamp on or after
|
||||
FROM.
|
||||
If TO, return non-nil if entry's timestamp is on or before TO.
|
||||
|
||||
If TO, return non-nil if entry has a timestamp on or before TO.
|
||||
|
||||
If ON, return non-nil if entry has a timestamp on date ON.
|
||||
If ON, return non-nil if entry's timestamp is on date ON.
|
||||
|
||||
FROM, TO, and ON should be either `ts' structs, or strings
|
||||
parseable by `parse-time-string' which may omit the time value."
|
||||
|
||||
(org-ql-defpred clocked (&key from to _on)
|
||||
"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."
|
||||
;; TODO: Verify that currently clocked entries are still ignored.
|
||||
:normalizers ((`(,predicate-names ,(and num-days (pred numberp)))
|
||||
;; (clocked) and (closed) implicitly look into the past.
|
||||
(let ((from (->> (ts-now)
|
||||
|
|
@ -1888,23 +1895,9 @@ parseable by `parse-time-string' which may omit the time value."
|
|||
(org-ql--predicate-ts :from from :to to :regexp org-ql-clock-regexp :match-group 1))
|
||||
|
||||
(org-ql-defpred closed (&key from to _on)
|
||||
;; TODO: Should this use the new org-ql-regexps?
|
||||
;; The underscore before `on' prevents "unused lexical variable"
|
||||
;; warnings, because we pre-process that argument in a macro before
|
||||
;; this function is called.
|
||||
;; MAYBE: Use the new org-ql-regexps?
|
||||
"Return non-nil if current entry was closed in given period.
|
||||
If no arguments are specified, return non-nil if entry has any
|
||||
timestamp.
|
||||
|
||||
If FROM, return non-nil if entry has a timestamp on or after
|
||||
FROM.
|
||||
|
||||
If TO, return non-nil if entry has a timestamp on or before TO.
|
||||
|
||||
If ON, return non-nil if entry has a timestamp on date ON.
|
||||
|
||||
FROM, TO, and ON should be either `ts' structs, or strings
|
||||
parseable by `parse-time-string' which may omit the time value."
|
||||
Without arguments, return non-nil if entry is closed."
|
||||
:normalizers ((`(,predicate-names ,(and num-days (pred numberp)))
|
||||
;; (clocked) and (closed) implicitly look into the past.
|
||||
(let ((from (->> (ts-now)
|
||||
|
|
@ -1919,22 +1912,10 @@ parseable by `parse-time-string' which may omit the time value."
|
|||
:limit (line-end-position 2)))
|
||||
|
||||
(org-ql-defpred deadline (&key from to _on regexp _with-time)
|
||||
;; The underscore before `on' prevents "unused lexical variable"
|
||||
;; warnings, because we pre-process that argument in a macro before
|
||||
;; this function is called.
|
||||
"Return non-nil if current entry has deadline in given period.
|
||||
If no arguments are specified, return non-nil if entry has any
|
||||
timestamp.
|
||||
|
||||
If FROM, return non-nil if entry has a timestamp on or after
|
||||
FROM.
|
||||
|
||||
If TO, return non-nil if entry has a timestamp on or before TO.
|
||||
|
||||
If ON, return non-nil if entry has a timestamp on date ON.
|
||||
|
||||
FROM, TO, and ON should be either `ts' structs, or strings
|
||||
parseable by `parse-time-string' which may omit the time value."
|
||||
If argument is `auto', return non-nil if entry has deadline
|
||||
within `org-deadline-warning-days'. Without arguments, return
|
||||
non-nil if entry has a deadline."
|
||||
:normalizers ((`(,predicate-names auto)
|
||||
;; Use `org-deadline-warning-days' as the :to arg.
|
||||
(let ((to (->> (ts-now)
|
||||
|
|
@ -1946,7 +1927,8 @@ parseable by `parse-time-string' which may omit the time value."
|
|||
(ts-adjust 'day num-days)
|
||||
(ts-apply :hour 23 :minute 59 :second 59))))
|
||||
`(deadline :to ,to))))
|
||||
;; NOTE: Does this normalizer cause the preamble to not be used? (Adding one to the deadline-warning definition to be sure.)
|
||||
;; NOTE: Does this normalizer cause the preamble to not be used?
|
||||
;; (Adding one to the deadline-warning definition to be sure.)
|
||||
:preambles ((`(,predicate-names . ,rest)
|
||||
(list :query query
|
||||
:regexp (pcase-exhaustive (org-ql--plist-get* rest :with-time)
|
||||
|
|
@ -1959,8 +1941,8 @@ parseable by `parse-time-string' which may omit the time value."
|
|||
|
||||
(org-ql-defpred deadline-warning (&key from to)
|
||||
;; TODO: Should this also accept a WITH-TIME argument?
|
||||
;; TODO: Should this use the new org-ql-regexps?
|
||||
"Internal selector used to handle `org-deadline-warning-days' and deadlines with warning periods."
|
||||
;; MAYBE: Use the new org-ql-regexps?
|
||||
"Internal predicate used to handle `org-deadline-warning-days' and deadlines with warning periods."
|
||||
:preambles ((`(,predicate-names . ,_)
|
||||
(list :regexp org-deadline-time-regexp :query query)))
|
||||
:body
|
||||
|
|
@ -1988,23 +1970,8 @@ parseable by `parse-time-string' which may omit the time value."
|
|||
('week (ts<= (->> ts (ts-adjust 'day (* -7 warning-value))) org-ql--today)))))))
|
||||
|
||||
(org-ql-defpred planning (&key from to _on regexp _with-time)
|
||||
;; The underscore before `on' prevents "unused lexical variable"
|
||||
;; warnings, because we pre-process that argument in a macro before
|
||||
;; this function is called.
|
||||
"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 has any
|
||||
timestamp.
|
||||
|
||||
If FROM, return non-nil if entry has a timestamp on or after
|
||||
FROM.
|
||||
|
||||
If TO, return non-nil if entry has a timestamp on or before TO.
|
||||
|
||||
If ON, return non-nil if entry has a timestamp on date ON.
|
||||
|
||||
FROM, TO, and ON should be either `ts' structs, or strings
|
||||
parseable by `parse-time-string' which may omit the time value."
|
||||
;; FIXME: Update docstring.
|
||||
"Return non-nil if current entry has planning timestamp in given period.
|
||||
Without arguments, return non-nil if entry has any planning timestamp."
|
||||
:normalizers ((`(,predicate-names ,(and num-days (pred numberp)))
|
||||
(let ((to (->> (ts-now)
|
||||
(ts-adjust 'day num-days)
|
||||
|
|
@ -2016,30 +1983,15 @@ parseable by `parse-time-string' which may omit the time value."
|
|||
('t org-ql-regexp-planning-with-time)
|
||||
('nil org-ql-regexp-planning-without-time)
|
||||
('not-found org-ql-regexp-planning)))))
|
||||
;; NOTE: The argument `regexp' is provided by pre-processing done by `org-ql--query-predicate'.
|
||||
;; MAYBE: Should the regexp be done in the normalizer instead? (If so, also in other ts-related predicates.)
|
||||
;; MAYBE: Should the regexp be done in the normalizer instead? (If
|
||||
;; so, also in other ts-related predicates.)
|
||||
:body
|
||||
(org-ql--predicate-ts :from from :to to :regexp regexp :match-group 1
|
||||
:limit (line-end-position 2)))
|
||||
|
||||
(org-ql-defpred scheduled (&key from to _on regexp _with-time)
|
||||
;; The underscore before `on' prevents "unused lexical variable"
|
||||
;; warnings, because we pre-process that argument in a macro before
|
||||
;; this function is called.
|
||||
"Return non-nil if current entry is scheduled in given period.
|
||||
If no arguments are specified, return non-nil if entry has any
|
||||
timestamp.
|
||||
|
||||
If FROM, return non-nil if entry has a timestamp on or after
|
||||
FROM.
|
||||
|
||||
If TO, return non-nil if entry has a timestamp on or before TO.
|
||||
|
||||
If ON, return non-nil if entry has a timestamp on date ON.
|
||||
|
||||
FROM, TO, and ON should be either `ts' structs, or strings
|
||||
parseable by `parse-time-string' which may omit the time value."
|
||||
;; FIXME: Update docstring.
|
||||
Without arguments, return non-nil if entry is scheduled."
|
||||
:normalizers ((`(,predicate-names ,(and num-days (pred numberp)))
|
||||
(let ((to (->> (ts-now)
|
||||
(ts-adjust 'day num-days)
|
||||
|
|
@ -2058,24 +2010,8 @@ parseable by `parse-time-string' which may omit the time value."
|
|||
(org-ql-defpred (ts ts-active ts-a ts-inactive ts-i)
|
||||
(&key from to _on regexp _with-time
|
||||
(match-group 0) (limit (org-entry-end-position)))
|
||||
;; NOTE: Arguments to this predicate are pre-processed in `org-ql--normalize-query'.
|
||||
;; The underscore before `on' prevents "unused lexical variable" warnings due to the
|
||||
;; pre-processing converting that argument to FROM and TO. The `regexp' argument is
|
||||
;; also provided by the pre-processing and is not to be given by the user. FROM and
|
||||
;; TO are actually expected to be `ts' structs. The docstring is written for users.
|
||||
"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.
|
||||
|
||||
If FROM, return non-nil if entry has a timestamp on or after
|
||||
FROM.
|
||||
|
||||
If TO, return non-nil if entry has a timestamp on or before TO.
|
||||
|
||||
If ON, return non-nil if entry has a timestamp on date ON.
|
||||
|
||||
FROM, TO, and ON should be either `ts' structs, or strings
|
||||
parseable by `parse-time-string' which may omit the time value.
|
||||
Without arguments, return non-nil if entry has a timestamp.
|
||||
|
||||
TYPE may be `active' to match active timestamps, `inactive' to
|
||||
match inactive ones, or `both' / nil to match both types.
|
||||
|
|
@ -2083,35 +2019,39 @@ match inactive ones, or `both' / nil to match both types.
|
|||
LIMIT bounds the search for the timestamp REGEXP. It defaults to
|
||||
the end of the entry, i.e. the position returned by
|
||||
`org-entry-end-position', but for certain searches it should be
|
||||
bound to a different positiion, e.g. for planning lines, the end
|
||||
of the line after the heading."
|
||||
;; FIXME: Update docstring (e.g. mention MATCH-GROUP).
|
||||
bound to a different positiion (e.g. for planning lines, the end
|
||||
of the line after the heading). MATCH-GROUP should be the number
|
||||
of REGEXP's group that matches the Org timestamp (i.e. excluding
|
||||
any planning prefix); it defaults to 0 (i.e. the whole regexp)."
|
||||
;; MAYBE: Define active/inactive ones separately?
|
||||
:normalizers ((`(,(or 'ts-active 'ts-a) . ,rest) `(ts :type active ,@rest))
|
||||
(`(,(or 'ts-inactive 'ts-i) . ,rest) `(ts :type inactive ,@rest)))
|
||||
:preambles ((`(,predicate-names . ,rest)
|
||||
(list :regexp (pcase (plist-get rest :type)
|
||||
((or 'nil 'both) (pcase-exhaustive (org-ql--plist-get* rest :with-time)
|
||||
('t org-ql-regexp-ts-both-with-time)
|
||||
('nil org-ql-regexp-ts-both-without-time)
|
||||
('not-found org-ql-regexp-ts-both)))
|
||||
('active (pcase-exhaustive (org-ql--plist-get* rest :with-time)
|
||||
('t org-ql-regexp-ts-active-with-time)
|
||||
('nil org-ql-regexp-ts-active-without-time)
|
||||
('not-found org-ql-regexp-ts-active)))
|
||||
('inactive (pcase-exhaustive (org-ql--plist-get* rest :with-time)
|
||||
('t org-ql-regexp-ts-inactive-with-time)
|
||||
('nil org-ql-regexp-ts-inactive-without-time)
|
||||
('not-found org-ql-regexp-ts-inactive))))
|
||||
;; Predicate needs testing only when args are present.
|
||||
:query (-let (((&keys :from :to :on) rest))
|
||||
;; FIXME: This used to be (when (or from to on) query), but that doesn't seem right, so I
|
||||
;; changed it to this if, and the tests pass either way. Might deserve a little scrutiny.
|
||||
(if (or from to on)
|
||||
query
|
||||
t)))))
|
||||
;; TODO: DRY this with the clocked predicate.
|
||||
;; NOTE: The argument `regexp' is provided by pre-processing done by `org-ql--query-predicate'.
|
||||
:normalizers
|
||||
((`(,(or 'ts-active 'ts-a) . ,rest) `(ts :type active ,@rest))
|
||||
(`(,(or 'ts-inactive 'ts-i) . ,rest) `(ts :type inactive ,@rest)))
|
||||
|
||||
:preambles
|
||||
((`(,predicate-names . ,rest)
|
||||
(list :regexp (pcase (plist-get rest :type)
|
||||
((or 'nil 'both) (pcase-exhaustive (org-ql--plist-get* rest :with-time)
|
||||
('t org-ql-regexp-ts-both-with-time)
|
||||
('nil org-ql-regexp-ts-both-without-time)
|
||||
('not-found org-ql-regexp-ts-both)))
|
||||
('active (pcase-exhaustive (org-ql--plist-get* rest :with-time)
|
||||
('t org-ql-regexp-ts-active-with-time)
|
||||
('nil org-ql-regexp-ts-active-without-time)
|
||||
('not-found org-ql-regexp-ts-active)))
|
||||
('inactive (pcase-exhaustive (org-ql--plist-get* rest :with-time)
|
||||
('t org-ql-regexp-ts-inactive-with-time)
|
||||
('nil org-ql-regexp-ts-inactive-without-time)
|
||||
('not-found org-ql-regexp-ts-inactive))))
|
||||
;; Predicate needs testing only when args are present.
|
||||
:query (-let (((&keys :from :to :on) rest))
|
||||
;; TODO: This used to be (when (or from to on) query), but
|
||||
;; that doesn't seem right, so I changed it to this if, and the
|
||||
;; tests pass either way. Might deserve a little scrutiny.
|
||||
(if (or from to on)
|
||||
query
|
||||
t)))))
|
||||
|
||||
:body
|
||||
(cl-macrolet ((next-timestamp ()
|
||||
`(when (re-search-forward regexp limit t)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue