Fix: (src) Normalization

Some argument combinations weren't normalized correctly and could
cause an infinite loop.

This commit doesn't update any corresponding tests, because they are
being rearranged in the WIP branch where this commit originates, and
teasing them out wouldn't be worth it.
This commit is contained in:
Adam Porter 2022-06-09 22:10:27 -05:00
parent c7fab9dfce
commit d4f2eb760e

View file

@ -1668,22 +1668,24 @@ If keyword argument LANG is non-nil, the block must be in that
language." language."
:normalizers ((`(,predicate-names . ,args) :normalizers ((`(,predicate-names . ,args)
;; Rewrite to use keyword args. ;; Rewrite to use keyword args.
(-let (regexps lang keyword-index) (cond ((cl-every #'stringp args)
(cond ((plist-get args :lang) ;; No keywords, only regexps.
;; Lang given first, or only lang given. `(src :regexps ,args))
(setf lang (plist-get args :lang) ((and (stringp (car args)) (cl-some #'keywordp args))
regexps (seq-difference args (list :lang lang)))) ;; Regexp as first arg with keyword later.
((setf keyword-index (-find-index #'keywordp args)) (let* ((keyword-pos (cl-position :lang args))
;; Regexps and lang given. (regexps (cl-subseq args 0 keyword-pos))
(setf lang (plist-get (cl-subseq args keyword-index) :lang) ;; We assume that if :lang is given, the string argument follows.
regexps (cl-subseq args 0 keyword-index))) (lang (nth (1+ (cl-position :lang args)) args)))
(t ;; Only regexps given. `(src :lang ,lang
(setf regexps args))) :regexps ,regexps)))
(when regexps ((keywordp (car args))
;; This feels awkward and wrong, but we have to quote lists ;; All plist args.
;; and avoid quoting nil. There must be a better way. `(src ,@(delq nil
(setf regexps `(',regexps))) (append (when (plist-get args :lang)
`(src :lang ,lang :regexps ,@regexps)))) (list :lang (plist-get args :lang)))
(when (plist-get args :regexps)
(list :regexps (plist-get args :regexps))))))))))
:preambles ((`(,predicate-names . ,args) :preambles ((`(,predicate-names . ,args)
(list :regexp (org-ql--format-src-block-regexp (plist-get args :lang)) (list :regexp (org-ql--format-src-block-regexp (plist-get args :lang))
;; Always check contents with predicate. ;; Always check contents with predicate.