From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id 8MZbBhRG52ODXwEAbAwnHQ (envelope-from ) for ; Sat, 11 Feb 2023 08:39:00 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id YHhyBRRG52O3QQAAG6o9tA (envelope-from ) for ; Sat, 11 Feb 2023 08:39:00 +0100 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 9099B6531 for ; Sat, 11 Feb 2023 08:38:59 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQkSP-0001PF-2D; Sat, 11 Feb 2023 02:38:01 -0500 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 1pQ5A5-00015c-0o for emacs-orgmode@gnu.org; Thu, 09 Feb 2023 06:32:25 -0500 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pQ5A3-0002xu-6x for emacs-orgmode@gnu.org; Thu, 09 Feb 2023 06:32:20 -0500 Received: by mail-ej1-x635.google.com with SMTP id c26so623561ejz.10 for ; Thu, 09 Feb 2023 03:32:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:user-agent:from:to:cc:subject:date:message-id:reply-to; bh=G65G/eHVVb1CMRsHzuNXdsJrue3LASNzphywO+rjbsU=; b=PDOsSSPr4TD3qapxfwHGy9i73+kc2W4fh0umSmkFWN1layPK7UglGi+DsknlSVEcIa XicUmaEpIQPtdk3wvyFX4qYIlAI6j8ZwkSUzyeBbQcTSw7TMM4lsHVIiZx3hBEwEg+G9 8mWnbL6uht2xRJDPh9NhoZuwZc5qFCaCGRjJFl2gDjvh+YRHJesmMBK8ISku9z9zRNy0 8CRD6SXRshk+eN6tK2u3UtMSVijJ6D7xI5X7eoVkgzu2lPKxxll7xvtb6lXtXXrBnUxz i183NPu/4wdxxztDI9cAylyctjMNdtB2LqsVG2lXpYQH6WF/ZQh/yElbiuGZcJGwUgrd ipnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:user-agent:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=G65G/eHVVb1CMRsHzuNXdsJrue3LASNzphywO+rjbsU=; b=eKHDUGfEZTdoKX8kk0Cf4h2W0M0RHbKRtv7zvu3tWjPAgJhaRkwlqMC7zr+BJsjoAS Qqg4r8ljOtTTQQWCg3UaxFvm0cMlEVLS6R+BOYxdFNQxrKfkOFaMiZ/DOtmRJvP1pPR+ ql7lH/bUsA4EzXJi6G6BabbWHEzAJTTXQxOi2lI5dy6fG4iIrjj6UMwnIXB0BGPKgztp SLpipm0OCccpaVXDY7Omoq0FN772XvefSfSH5tN/n/LJG7OGXFqJINb1QFc/6nsjln9Z CM1ipiIJnihvxjA2wPSy1b1aufcYYnfpcq4RfAu+XOLoQSpXd2hDpY7r+EjPPcm7OZqd md7g== X-Gm-Message-State: AO0yUKV13ukkGqBfIa7KzWOTRa6azk9LrRl5w1aS6gqsYmDECP7+Gcbk 5w4lPxplFqEPIbVZD+vRFnvFDuDB3zo= X-Google-Smtp-Source: AK7set95RWLukOWLbIaGTClV6g8V6/qhtTwjPefyO7ojPB11QGq33QStRsWFoLJxIIWouj11r62/KA== X-Received: by 2002:a17:907:98cf:b0:88e:2ff5:85d2 with SMTP id kd15-20020a17090798cf00b0088e2ff585d2mr14227016ejc.25.1675942337079; Thu, 09 Feb 2023 03:32:17 -0800 (PST) Received: from gazelle.gmail.com (ip1f10e370.dynamic.kabel-deutschland.de. [31.16.227.112]) by smtp.gmail.com with ESMTPSA id br2-20020a170906d14200b008818d9e0bfesm759479ejb.117.2023.02.09.03.32.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Feb 2023 03:32:16 -0800 (PST) User-agent: mu4e 1.8.13; emacs 28.2 From: =?utf-8?Q?Th=C3=A9o?= Maxime Tyburn To: emacs-orgmode@gnu.org Subject: Multiple noweb-ref Date: Thu, 09 Feb 2023 11:01:57 +0100 Message-ID: <87pmajxef5.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=2a00:1450:4864:20::635; envelope-from=theo.tyburn@gmail.com; helo=mail-ej1-x635.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sat, 11 Feb 2023 02:37:56 -0500 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-Country: US X-Migadu-Flow: FLOW_IN ARC-Seal: i=1; s=key1; d=yhetil.org; t=1676101139; a=rsa-sha256; cv=none; b=ntooHSUUwQcFl11dcBCm21uqPH+HFm43MR9aO4cRzD/uQV693srUNIethUhGeL5f7a0DNt y+RKSFjlmD9COfCZr5K5NNZpSrKOP9pzNwWOI0xm8pWv/9F0lqQu0t0iaSE/p5Ku0XFcCj MDsfYS445gr7rhEhhfhFdlK2kweyiD7ivjSbFRRWuqx9YfZ2+np2YCje15Ceb4Wk5+IpwC LsHLl/aAvz7BoSlC3fIosa85awbOqq1HG0jH94jp2nZZKxJ+dNq/G+GBxF+cAkNMGFOSjw /ljeynmRvC+FZ9rVMS5C8l6z9z2h/ZJ1+WTukzGWWNm5euR26MVi2FGuzDIT9A== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=PDOsSSPr; 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=1676101139; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=G65G/eHVVb1CMRsHzuNXdsJrue3LASNzphywO+rjbsU=; b=uVXdwu/YWF1aPQL+ImKvFH5CS8MeFZoPJygcaNW2iSvmbVQOASVvFXoQp9pXLT8aK4n5jY 0KoR2yhWtx7GrkELP9qAG5ccR+ejrYMaRHuWiHaZ2xubRH2A8MXODc/G9/c0xaOWpX5NfS 1WAklCHDEq1dKgij67PkIu4P8ZCXaIvKeo+Kl+rHFWW1OQ3zzjjoHE8VEcyLMUP/iFwkzS gkwwO9mfeXpgHuzmo9/CqI4DtkNFqqvUeFq+33436ikSC3VJ5zRtlwFaOsKL+iik9yWnRi xICIq1T+wsn7LI3nVD5ieAX/6Ac0Lr52jF8kmrU4JD9bBpnBTQBqwJQkn7luBw== Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=PDOsSSPr; 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: -5.30 X-Spam-Score: -5.30 X-Migadu-Queue-Id: 9099B6531 X-Migadu-Scanner: scn1.migadu.com X-TUID: ewbBYCLl50ZS Hi, I have several code blocks that I label using `:noweb-ref label`. I set them for all blocks under a subtree by setting the org property `header-args+` of the root of the subtree to `:noweb-ref label`. Now with this approach, I can't accumulate `noweb-ref` like I could do for tags. I would like all blocks under a subtree A to have the reference "foo" and all the blocks under a subtree B of subtree A to have the reference "bar", while also having the reference "foo". What I would like to have, when I expand `<>` is to get all the blocks under A, and when I expand `<>` I get all the blocks under B. For now when I expand `<>` I only get the blocks under A that are not unde= r B. Is there a way to do this with the current features of org-babel? Anyway I tried to hack my way trough it. It seems there are two things to do : 1) Enable noweb-ref to contain multiple references. 2) Accumulate references when using header-args+ or use tags to set the value of noweb-ref I came up with a quick patch for 1): modified lisp/ob-core.el @@ -2910,8 +2910,11 @@ block but are passed literally to the \"example-bloc= k\"." (if (org-in-commented-heading-p) (org-forward-heading-same-level nil t) (let* ((info (org-babel-get-src-block-info t)) - (ref (cdr (assq :noweb-ref (nth 2 info))))) - (push info (gethash ref cache)))))) + (refs (cdr (assq :noweb-ref (nth 2 info))))) + (if refs + (dolist (ref (s-split "+" refs)) + (push info (gethash ref cache))) + (push info (gethash refs cache))))))) (funcall expand-references id cache))))) ;; Interpose PREFIX between every line. (mapconcat #'identity With this I already get interesting results. A noweb-ref "foo+bar" gets expanded by <> by and <>. For example if I define references like this #+BEGIN_SRC emacs-lisp :noweb-ref one aaa #+END_SRC #+BEGIN_SRC emacs-lisp :noweb-ref two bbb #+END_SRC #+BEGIN_SRC emacs-lisp :noweb-ref one+two ababab #+END_SRC and tangle them like this #+BEGIN_SRC emacs-lisp :tangle one.el :noweb yes <> #+END_SRC #+BEGIN_SRC emacs-lisp :tangle two.el :noweb yes <> #+END_SRC I get two files one.el: aaa ababab and two.el: bbb ababab This is already nice! Feedback on the code is of course very welcome. Not sure if using a plus sign as a delimiter is clever. Also not sure if using `s-split` is a good idea, what would be the builtin alternative? For 2) I didn't check in detail how one could achieve this. I have the impression it would be easier to use tags. One could define a new variable `org-babel-set-noweb-refs-from-tags` that would be used in `org-babel-get-src-block-info` to generate the value of noweb-ref we would like to have depending on the tags of the headline of the block. I'll try this soonish. Best, Th=C3=A9o