From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id 8He4EZjEW2TIfQAASxT56A (envelope-from ) for ; Wed, 10 May 2023 18:21:44 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id MCehEZjEW2TVXAEA9RJhRA (envelope-from ) for ; Wed, 10 May 2023 18:21:44 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id B7E9CD3B9 for ; Wed, 10 May 2023 18:21:43 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pwmYq-0007IX-Of; Wed, 10 May 2023 12:21:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pwmYp-0007IF-6G for emacs-orgmode@gnu.org; Wed, 10 May 2023 12:21:03 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pwmYn-0002Zw-30 for emacs-orgmode@gnu.org; Wed, 10 May 2023 12:21:02 -0400 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-30789a4c537so3280439f8f.0 for ; Wed, 10 May 2023 09:21:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683735659; x=1686327659; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=S9lXAjHu+Y8GS4RrC8CD2Ks/IYabYlJc7/YVzmsn0nc=; b=IzkSITyYoQH0poCb/y+Ju9N+gyhck9wZHsDTM4U4YVyHhsm33N5nKZgmtOrAARo64H Rlx3YzCVqDURuRttzG5slzCZQJL242hDnL0FoC86R7gsDOpKgGcMUVGzliCf9GJQPzBA EzeTtKI4vtvnJhjvynI1yaKb043ivJUsVo15P8DYE5P6Pt0Rt1B4k745ldAS7NVhakTF M/Z1xbBk6lDZ/CZbWgRBA7UW8qqGKOMdawkeFeI9ond1/bUwv+JT9dyy+bu41hr6e/+T ui67/zZQCrquJWmxIY969xd3mJ/m4IROc5sjsvHdyGlDAt4mfVlJCDfwH1x3aPdYekeN qImQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683735659; x=1686327659; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=S9lXAjHu+Y8GS4RrC8CD2Ks/IYabYlJc7/YVzmsn0nc=; b=aXgy3sULrTW8/PDbkHB+kbFghtZS0oFIB+MKLY1XmGcy6mn5KCh7nVN4QGVcTZIyAL OCNviufbh3dkZUJ/a75UPzyzGdWnrPgBJaqeOnRHoykdpCtlAtK8I2+ifKX/OrK1k9iV ohX5DlL4TfSVvZy3vQUq2GTfcTnOipmXinTMpnYcRLuybyHglvvi7CyLMPr06Gk5KIv5 H3IjN5Jk2ltZDMMV/Fpx/Eh2gi09XTTLMehAOIhhNwD3gnsy7TiRLHwwudrF8jNVGzNQ 4GRp/DcKVw8rtXJIUz3gr6IiLUJI9AfbqGqlOAgirjEIl2nRTN80Y/klhj2caq/HuRqE aB5Q== X-Gm-Message-State: AC+VfDx0Dx18x5lJ9eNI2YXQPpIpgQL1TgBBbnKw7Bh/thtTX8aBhIDb sJXs9byjZP1cnQlj3wpRKwO6i0NCsEc= X-Google-Smtp-Source: ACHHUZ7k5PVzbtLHKMPzZxn7h+PPjDQXiMKD8nYmk6n+vmsRokyVmBTcMcQURPVi0a6jYkfvK6sa6w== X-Received: by 2002:a5d:63c3:0:b0:307:809b:614a with SMTP id c3-20020a5d63c3000000b00307809b614amr13199222wrw.29.1683735658841; Wed, 10 May 2023 09:20:58 -0700 (PDT) Received: from hayvan (pharma2-70.w2k.pharmakol.uni-freiburg.de. [132.230.165.170]) by smtp.gmail.com with ESMTPSA id p6-20020adfe606000000b002e5f6f8fc4fsm17885370wrm.100.2023.05.10.09.20.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 May 2023 09:20:58 -0700 (PDT) From: Mehmet Tekman To: Ihor Radchenko Cc: emacs-orgmode@gnu.org Subject: Re: [ANN] lisp/ob-tangle-sync.el In-Reply-To: <87sfc4a0ce.fsf@localhost> (Ihor Radchenko's message of "Wed, 10 May 2023 11:32:17 +0000") References: <87r0rxabd4.fsf@localhost> <87sfcd78vw.fsf@gmail.com> <87r0rxv3t5.fsf@localhost> <87lei577g4.fsf@gmail.com> <87lei5v1fg.fsf@localhost> <87fs8duyae.fsf@localhost> <8735451u20.fsf@gmail.com> <874jokbjsk.fsf@localhost> <87zg6ch2dm.fsf@gmail.com> <87sfc4a0ce.fsf@localhost> Date: Wed, 10 May 2023 18:20:55 +0200 Message-ID: <87r0ro9mzc.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=mtekman89@gmail.com; helo=mail-wr1-x42c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Seal: i=1; s=key1; d=yhetil.org; t=1683735703; a=rsa-sha256; cv=none; b=HLYVxXfGfHuP4tBNY6XWq/3xLrPRbSI9/+ONza8W6U1A3/MkuVUv21czjC5diVwEuuB1jV 4lofUikM2bw+nfg8iYRdRNVVGBLMVyrrpZuQggRrLHPItnCdPai67ZQdQpbbhJL45tDk7/ spzX89tqXDPS2MkBSuu1oYOc1hDccERyqqmLv2dYIy1eILHytbRnGZ19fqt3TUZQqF1lTu CKEqYtFdEPtpIuauCN+6jo5imRyVoq56HQ0hBmOkvMMiYjOGToIJR4ZAhQ8SrGCRYsqVm5 dkXc/vgDqqWduNoRsPtIx5I7xSTZmi7dQe4OMyHZ5C7Y0yVUKXBZtRV5KwujXg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=IzkSITyY; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1683735703; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=S9lXAjHu+Y8GS4RrC8CD2Ks/IYabYlJc7/YVzmsn0nc=; b=mUrDwePHBwtgU36hc2MH9CX9B70FxRfmT/KU+iC2n7nIoRUAmCXK4JiiJR2CrP1oXmc2Ff IvYjVWWgeDbqx190OgAfKRJE/Tsns9BVajEl0GNHILDr197VFl866rqa69evnkFK3BICKC Dfpze3c0MPgxrJ7vn/zVhbAM0rseRFtkwo8MhCblnPjA8TXPv/P1MxqYc4kC1X6VN3IskR 9aHwT2b0SkUMJUGXlXCiPC5WTjOTCbVewdONPQE+QPdgfY39X7rF2HtqQzLx3I3uoOuF5E QYhnN0Du0oSkoKVfmpKw0z302xgyKBMkhoTzBvKT3A+kcU3TE+0apDUI79EKWQ== X-Migadu-Scanner: scn1.migadu.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=IzkSITyY; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -6.37 X-Spam-Score: -6.37 X-Migadu-Queue-Id: B7E9CD3B9 X-TUID: siXYxaL9Otav --=-=-= Content-Type: text/plain Ihor Radchenko writes: > It will be great if you could do it. > I have other things to work on. Of course! I'm just a little unfamiliar on how one coordinates active collaboration via mailing list :-) Anyways - I did it, and it took less time than I thought > We should modify it. For example like the following: > > 1. We will assume that :any can only occur one time in the exclusive > groups. (Otherwise, there is no single definite way to parse header > arguments) > 2. Merge function will treat :any specially - when parameter does not > match any of the argument values from all the groups combined, it is > considered as :any and replace the previous corresponding values in > its exclusive group, if any; > In other words, we will need a special match for :any - "anything not > equal to other values in all the groups combined". I've modified the `merge' function within `org-babel-merge-params' so that the main logic now accumulates a list of potential candidates that could be the :any keyword, and selects the last added candidate as the match. The first two patches are very minor, simply adding tangle-exclusive-groups using the existing code templates. The last patch is the merge function rewrite. It all seems to be passing tests, though I would like to add my toy.org file to the org testing framework at some point. Best, Mehmet --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-lisp-ob-core.el-org-babel-common-header-args-w-value.patch Content-Description: Added new tangle exclusion group for tangle sync action >From eeb3f165498fcc420b862f67fb616b474a14b684 Mon Sep 17 00:00:00 2001 From: MT Date: Wed, 10 May 2023 17:38:22 +0200 Subject: [PATCH 1/3] * lisp/ob-core.el (org-babel-common-header-args-w-values): Added mutually exclusive tangle groups relating to desired tangle sync actions (e.g. :tangle (yes|no|) [(import|export|sync)]) --- lisp/ob-core.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 65fa47ab5..013a37ce5 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -431,7 +431,8 @@ then run `org-babel-switch-to-session'." (sep . :any) (session . :any) (shebang . :any) - (tangle . ((tangle yes no :any))) + (tangle . ((tangle yes no :any) + (import export skip sync))) (tangle-mode . ((#o755 #o555 #o444 :any))) (var . :any) (wrap . :any))) -- 2.40.1 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-lisp-ob-core.el-org-babel-merge-params-Tangle-header.patch Content-Description: Implemented initial tangle header merge framework from existing code template >From 366a120a394d7783bf1640037ade31f826ef0277 Mon Sep 17 00:00:00 2001 From: MT Date: Wed, 10 May 2023 17:41:37 +0200 Subject: [PATCH 2/3] * lisp/ob-core.el (org-babel-merge-params): Tangle header with exclusive parameters can now be parsed, following the template of :exports and :results --- lisp/ob-core.el | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 013a37ce5..ed31a9de1 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -2803,6 +2803,9 @@ parameters when merging lists." (exports-exclusive-groups (mapcar (lambda (group) (mapcar #'symbol-name group)) (cdr (assq 'exports org-babel-common-header-args-w-values)))) + (tangle-exclusive-groups + (mapcar (lambda (group) (mapcar #'symbol-name group)) + (cdr (assq 'tangle org-babel-common-header-args-w-values)))) (merge (lambda (exclusive-groups &rest result-params) ;; Maintain exclusivity of mutually exclusive parameters, @@ -2822,7 +2825,7 @@ parameters when merging lists." params ;Final parameters list. ;; Some keywords accept multiple values. We need to treat ;; them specially. - vars results exports) + vars results exports tangle) (dolist (plist plists) (dolist (pair plist) (pcase pair @@ -2873,6 +2876,12 @@ parameters when merging lists." (cond ((and value (functionp value)) (funcall value)) (value value) (t "")))))) + (`(:tangle . ,value) + (setq tangle (funcall merge + tangle-exclusive-groups + tangle + (split-string + (or value ""))))) ((or '(:dir . attach) '(:dir . "'attach")) (unless (org-attach-dir nil t) (error "No attachment directory for element (add :ID: or :DIR: property)")) @@ -2898,7 +2907,8 @@ parameters when merging lists." params))))) ;; Handle other special keywords, which accept multiple values. (setq params (nconc (list (cons :results (mapconcat #'identity results " ")) - (cons :exports (mapconcat #'identity exports " "))) + (cons :exports (mapconcat #'identity exports " ")) + (cons :tangle (mapconcat #'identity tangle " "))) params)) ;; Return merged params. (org-babel-eval-headers params))) -- 2.40.1 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0003-lisp-ob-core.el-org-babel-merge-params-Major-rewrite.patch Content-Description: Major rewrite of the merge function to handle :any keywords >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 --=-=-=--