Add: src predicate
This commit is contained in:
parent
a60c238417
commit
37ba30c969
4 changed files with 80 additions and 16 deletions
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 ":"))) ":"
|
||||
;; (1+ space) (minimal-match (1+ not-newline)) eol)))
|
||||
;; element)
|
||||
|
||||
;; Src blocks.
|
||||
(`(src ,lang . ,_)
|
||||
(setq org-ql-preamble (org-ql--format-src-block-regexp lang))
|
||||
;; Always check contents with predicate.
|
||||
element)
|
||||
|
||||
(`(scheduled . ,_)
|
||||
(setq org-ql-preamble org-scheduled-time-regexp)
|
||||
;; Return element, because the predicate still needs testing.
|
||||
|
|
@ -781,6 +788,29 @@ replace the clause with a preamble."
|
|||
(query (-flatten-n 1 query))))
|
||||
(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 " | ||||