Skip to content

Commit

Permalink
Fix: (src) Rewrite body
Browse files Browse the repository at this point in the history
Fixes alphapapa#304.  Thanks to @johanwk for reporting.
  • Loading branch information
alphapapa committed Mar 9, 2023
1 parent 0304a2c commit 1996969
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
1 change: 1 addition & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ Simple links may also be written manually in either sexp or non-sexp form, like:

*Fixed*
+ Predicate ~src~'s matching of begin/end block lines, normalization of arguments, and handling in non-sexp queries.
+ Predicate ~src~'s behavior with various arguments.

*Internal*
+ Certain query predicates, when called multiple times in an ~and~ sub-expression, are optimized to a single call.
Expand Down
36 changes: 16 additions & 20 deletions org-ql.el
Original file line number Diff line number Diff line change
Expand Up @@ -1925,26 +1925,22 @@ language. Matching is done case-insensitively."
;; Always check contents with predicate.
:query query)))
:body
(catch 'return
(save-excursion
(save-match-data
(when (re-search-forward org-babel-src-block-regexp (org-entry-end-position) t)
(when lang
(unless (string= lang (match-string 2))
(throw 'return nil)))
(if regexps
(let ((contents-beg (progn
(goto-char (match-beginning 0))
(forward-line 1)
(point)))
(contents-end (progn
(goto-char (match-end 0))
(point-at-bol))))
(cl-loop for re in regexps
do (goto-char contents-beg)
always (re-search-forward re contents-end t)))
;; No regexps to check: return non-nil.
t))))))
(save-excursion
(save-match-data
(cl-loop while (re-search-forward org-babel-src-block-regexp (org-entry-end-position) t)
thereis (when (or (not lang) (equal lang (match-string 2)))
(or (not regexps)
(save-excursion
(let ((contents-beg (progn
(goto-char (match-beginning 0))
(forward-line 1)
(point)))
(contents-end (progn
(goto-char (match-end 0))
(point-at-bol))))
(cl-loop for re in regexps
do (goto-char contents-beg)
always (re-search-forward re contents-end t))))))))))

(org-ql-defpred (tags) (&rest tags)
"Return non-nil if current heading has one or more of TAGS (a list of strings).
Expand Down

0 comments on commit 1996969

Please sign in to comment.