From 6ce5313b7d3f0ab718072942f082bc259dccbae6 Mon Sep 17 00:00:00 2001 From: MT Date: Wed, 10 May 2023 17:44:42 +0200 Subject: [PATCH 3/3] * lisp/ob-core.el (org-babel-merge-params): Major rewrite of the `merge' function, which adds the capability to process the :any keyword when merging parameters with exclusive groups. --- lisp/ob-core.el | 60 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/lisp/ob-core.el b/lisp/ob-core.el index ed31a9de1..3d9000efc 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -2811,15 +2811,61 @@ parameters when merging lists." ;; Maintain exclusivity of mutually exclusive parameters, ;; as defined in EXCLUSIVE-GROUPS while merging lists in ;; RESULT-PARAMS. - (let (output) + (let (output group-any) (dolist (new-params result-params (delete-dups output)) (dolist (new-param new-params) - (dolist (exclusive-group exclusive-groups) - (when (member new-param exclusive-group) - (setq output (cl-remove-if - (lambda (o) (member o exclusive-group)) - output)))) - (push new-param output)))))) + (let (matched-param potential-any-param) + ;; new-param may be an :any value, so we check + ;; across all exclusive-groups. + ;; - If new-param matches one of groups, we + (dolist (exclusive-group exclusive-groups) + (if (member new-param exclusive-group) + (setq output (cl-remove-if + (lambda (o) (member o exclusive-group)) + output) + ;; Cancel any potential matches if it's caught + matched-param t + potential-any-param nil) + ;; If not a direct match, flag it as a potential + ;; :any match This can happen multiple times for + ;; each new-param, but only once for each + ;; exclusive-group. + (if (and (not matched-param) + (member ":any" exclusive-group)) + ;; At this point, the new-param has not yet matched + ;; anything in the N exclusive groups + ;; - We also assume that only 1 of these N groups + ;; has the :any keyword. + ;; - This point in the code can therefore be only + ;; reached once under this assumption. + ;; - We therefore setq instead of push + (setq potential-any-param (cons new-param + exclusive-group))))) + + ;; At this point we know whether new-param and 1 + ;; of the exclusive groups have an :any keyword - + ;; - Due to multiple new-params potentially being + ;; matches in the same group, we push these to a + ;; super group of "any" keywords, and process them + ;; later. + (if potential-any-param + (setq group-any potential-any-param) + ;; If the param isn't :any, add it to the output + ;; as a regular keyword + (push new-param output))))) + + (when group-any + ;; Whatever is leftover at this point are :any candidates. + ;; - We assume that last added is the most relevant and + ;; that everything else should be ignored + ;; - We add the first, and reject everything else in that + ;; exclusion group. + (push (car group-any) output) + (setq output (cl-remove-if + (lambda (o) (member o (cdr group-any))) + output))) + output))) + (variable-index 0) ;Handle positional arguments. clearnames params ;Final parameters list. -- 2.40.1