Add: src predicate
This commit is contained in:
parent
a60c238417
commit
37ba30c969
4 changed files with 80 additions and 16 deletions
|
|
@ -189,6 +189,7 @@ Arguments are listed next to predicate names, where applicable.
|
||||||
+ =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.
|
+ =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.
|
||||||
+ =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)~.
|
+ =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)~.
|
||||||
+ =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.
|
+ =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.
|
||||||
|
+ ~src (&optional 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.
|
||||||
+ =tags (&optional tags)= :: Return non-nil if current heading has one or more of ~TAGS~ (a list of strings). Tests both inherited and local tags.
|
+ =tags (&optional tags)= :: Return non-nil if current heading has one or more of ~TAGS~ (a list of strings). Tests both inherited and local tags.
|
||||||
+ =tags-inherited (&optional tags)= :: Return non-nil if current heading's inherited tags include one or more of ~TAGS~ (a list of strings). If ~TAGS~ is nil, return non-nil if heading has any inherited tags.
|
+ =tags-inherited (&optional tags)= :: Return non-nil if current heading's inherited tags include one or more of ~TAGS~ (a list of strings). If ~TAGS~ is nil, return non-nil if heading has any inherited tags.
|
||||||
- Aliases: ~inherited-tags~, ~tags-i~, ~itags~.
|
- Aliases: ~inherited-tags~, ~tags-i~, ~itags~.
|
||||||
|
|
@ -379,6 +380,7 @@ Expands into a call to ~org-ql-select~ with the same arguments. For convenience
|
||||||
+ Command ~org-ql-view-refresh~ can be called with a prefix argument to adjust search parameters.
|
+ Command ~org-ql-view-refresh~ can be called with a prefix argument to adjust search parameters.
|
||||||
+ 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.
|
+ 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.
|
||||||
+ Command ~helm-org-ql-views~, which shows one of ~org-ql-views~ selected with Helm.
|
+ Command ~helm-org-ql-views~, which shows one of ~org-ql-views~ selected with Helm.
|
||||||
|
+ Predicate ~src~, which matches Org Babel source blocks.
|
||||||
|
|
||||||
*Internal*
|
*Internal*
|
||||||
+ Added generic node data cache to speed up recursive, tree-based queries.
|
+ Added generic node data cache to speed up recursive, tree-based queries.
|
||||||
|
|
|
||||||
54
org-ql.el
54
org-ql.el
|
|
@ -747,6 +747,13 @@ replace the clause with a preamble."
|
||||||
;; (setq org-ql-preamble (rx-to-string `(seq bol (0+ space) ":" (1+ (not (or space ":"))) ":"
|
;; (setq org-ql-preamble (rx-to-string `(seq bol (0+ space) ":" (1+ (not (or space ":"))) ":"
|
||||||
;; (1+ space) (minimal-match (1+ not-newline)) eol)))
|
;; (1+ space) (minimal-match (1+ not-newline)) eol)))
|
||||||
;; element)
|
;; element)
|
||||||
|
|
||||||
|
;; Src blocks.
|
||||||
|
(`(src ,lang . ,_)
|
||||||
|
(setq org-ql-preamble (org-ql--format-src-block-regexp lang))
|
||||||
|
;; Always check contents with predicate.
|
||||||
|
element)
|
||||||
|
|
||||||
(`(scheduled . ,_)
|
(`(scheduled . ,_)
|
||||||
(setq org-ql-preamble org-scheduled-time-regexp)
|
(setq org-ql-preamble org-scheduled-time-regexp)
|
||||||
;; Return element, because the predicate still needs testing.
|
;; Return element, because the predicate still needs testing.
|
||||||
|
|
@ -781,6 +788,29 @@ replace the clause with a preamble."
|
||||||
(query (-flatten-n 1 query))))
|
(query (-flatten-n 1 query))))
|
||||||
(list :query query :preamble org-ql-preamble :preamble-case-fold preamble-case-fold))))))
|
(list :query query :preamble org-ql-preamble :preamble-case-fold preamble-case-fold))))))
|
||||||
|
|
||||||
|
(defun org-ql--format-src-block-regexp (&optional lang)
|
||||||
|
"Return regexp equivalent to `org-babel-src-block-regexp' with LANG filled in."
|
||||||
|
;; I couldn't find a way to match block contents without the regexp
|
||||||
|
;; also matching past the end of the block and into later blocks. Even
|
||||||
|
;; using `minimal-match' in several different combinations didn't work.
|
||||||
|
;; So matching contents will have to be done with the predicate.
|
||||||
|
(rx-to-string `(seq bol (group (zero-or-more (any " ")))
|
||||||
|
"#+begin_src"
|
||||||
|
(one-or-more (any " "))
|
||||||
|
,lang
|
||||||
|
(zero-or-more (any " "))
|
||||||
|
(group (or (seq (zero-or-more (not (any "\n\":")))
|
||||||
|
"\""
|
||||||
|
(zero-or-more (not (any "\n\"*")))
|
||||||
|
"\""
|
||||||
|
(zero-or-more (not (any "\n\":"))))
|
||||||
|
(zero-or-more (not (any "\n\":")))))
|
||||||
|
(group (zero-or-more (not (any "\n")))) "\n"
|
||||||
|
(63 (group (*\? (not (any " | ||||||