From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id qAM3MYPXkGbKJgAA62LTzQ:P1 (envelope-from ) for ; Fri, 12 Jul 2024 07:13:07 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id qAM3MYPXkGbKJgAA62LTzQ (envelope-from ) for ; Fri, 12 Jul 2024 09:13:07 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=7d.nz header.s=20240212 header.b=T+JaxnJW; 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"; dmarc=pass (policy=reject) header.from=7d.nz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1720768387; 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=ZsO837sRwKxW50SGho56iRAJVtLDf2fi5am3WGUZpXc=; b=Es+Nfh6S/I3Aa5rb9YtZfGhC1VJ6pNtHKxBbCIDTrRHOOnQseaVcQQsB4Z+yAsmHkJ9e7w phTEOKIW2yaDLGAvHh100XwuNd1gbtfoZPgYUnlJoRv0mOPAiAZsWn+4sMQXgP63Vtuf8h uc9eZATiNT4bkPWWzmQUeiIqyArF3JnP4AGz/jtCCy3WenG/wNCsBtUWFs3lgNWOnUjQY7 gs435ZeWgQj8AYk2U+Tz6qrFWC9qJe6u+bkBDkvY2p9uH8F14HFNZq6H2gLemanfRUQvn0 yAysaYjyLasVsxfdIJkunO3Yvlz6r/kW0oxQ0dbrwULb6EjR7xrktqap9J+jLQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=7d.nz header.s=20240212 header.b=T+JaxnJW; 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"; dmarc=pass (policy=reject) header.from=7d.nz ARC-Seal: i=1; s=key1; d=yhetil.org; t=1720768387; a=rsa-sha256; cv=none; b=hwEwZwGQR0qtM5JNig8IAXRTb+sjJnYgiEbTizTd0UHDrjnjdgx/nS6JmwjfIiVEEKWjXl VHOYRdShRoIt1hRarGwJS5eKpRCawGt54TcmDpmAYnnTmC+GPLT/JO7NZgISuK37Sz4sh+ h4mt948U4iWXzwuKaeNBWXzA+JZHvZj/gok4jpKtcn+rv8H+ws7Cl+ggVTAuvmuDpdStoz HhP1UMZBIvOgjpBp5kd61jlb2TPlTwXHAHdiBl5R1aW166MjDE24ZPq1voJHUCdndSj0wC x1SH9I2juF3G7YzASd3l6KFztidJSqP93Bvg4qR6uf+4E65TQOxa8RhKUZw6Iw== 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 4A44B757B2 for ; Fri, 12 Jul 2024 09:13:07 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSARh-0004EL-Pq; Fri, 12 Jul 2024 03:11:58 -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 1sSARX-0004Dv-Hn for emacs-orgmode@gnu.org; Fri, 12 Jul 2024 03:11:47 -0400 Received: from smtp-8fa9.mail.infomaniak.ch ([2001:1600:7:10::8fa9]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sSARS-0004q2-PS for emacs-orgmode@gnu.org; Fri, 12 Jul 2024 03:11:47 -0400 Received: from smtp-3-0001.mail.infomaniak.ch (smtp-3-0001.mail.infomaniak.ch [10.4.36.108]) by smtp-4-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4WL2ny2BJ9znyK for ; Fri, 12 Jul 2024 09:11:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=7d.nz; s=20240212; t=1720768294; bh=ZsO837sRwKxW50SGho56iRAJVtLDf2fi5am3WGUZpXc=; h=Date:From:Subject:To:From; b=T+JaxnJW62NgmIx4S09NcBWdLQh8/lXRLYIA8mu1Q5cPlodpB2UA3GS0RIuao040f K3HF1GevoJbWceytzhMAyJWr6ylHvpAhmpg31KSy3Sm4tPu83/cfLbtaAHlhxScZNe 6oVlYozw8CioGFe7wszU0g9BgLAkYKC7LVBnggwuomE4etMlmVWuV1v2s9Lrly5m8C 19M+gCFlf9mG78xP12vbotrsntz6dRxGrjpCHPCN1GzdRmh6hDr0MbFHjAh81XXm4W Q/EAkVteXQorsyTfWHdFZkxKBQFtyHyfNw2I3l74a97G0HdTL8ysZXyWckV7Z44U+J QIiOwmep+VyQw== Received: from unknown by smtp-3-0001.mail.infomaniak.ch (Postfix) with ESMTPA id 4WL2nx6YzhzmMR for ; Fri, 12 Jul 2024 09:11:33 +0200 (CEST) Message-ID: <6a7129e2-9d26-4292-b8d1-1a3e3db90f4b@7d.nz> Date: Fri, 12 Jul 2024 09:11:40 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Phil Subject: [FR] org-babel-n-tangle To: emacs-orgmode@gnu.org Content-Language: fr, en-ZA Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Infomaniak-Routing: alpha Received-SPF: pass client-ip=2001:1600:7:10::8fa9; envelope-from=pe@7d.nz; helo=smtp-8fa9.mail.infomaniak.ch 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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 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-Country: US X-Migadu-Flow: FLOW_IN X-Spam-Score: -9.93 X-Migadu-Queue-Id: 4A44B757B2 X-Migadu-Scanner: mx10.migadu.com X-Migadu-Spam-Score: -9.93 X-TUID: NosKKhVObl6A Hi, The ability to tangle to multiple destinations is a very convenient way to manage cluster configurations. No, it's more than that: it's an *awesome* way to deploy and keep clusters configs and repros well organized. The following *org-babel-n-tangle*, is just a small derivation of *org-babel-tangle*. It's displayed here as a diff not with the intent to be applied as a patch, but to show the very little differences required in order to get this working. #+begin_src diff diff -u ~/.emacs.d/repos/org/lisp/ob-tangle.el ~/tmp/ob-ntangle.el --- ~/.emacs.d/repos/org/lisp/ob-tangle.el +++ ~/tmp/ob-ntangle.el @@ -238,8 +238,12 @@ (org-babel-tangle-file filename))) ;;;###autoload -(defun org-babel-tangle (&optional arg target-file lang-re) - "Write code blocks to source-specific files. +(defun org-babel-n-tangle (&optional arg target-file lang-re) + "Write code blocks to source-specific files +located into the directories designated by the :n-tangle parameter +then onto subsequent directory and file of the :tangle parameter. +Performs like `org-babel-tangle' adding an extra iteration over +a list of directories, potentially different hosts and protocols Extract the bodies of all source code blocks from the current file into their own source-specific files. Return the list of files. With one universal prefix argument, only tangle the block at point. @@ -268,12 +272,19 @@ (tangle-file (when (equal arg '(16)) (or (cdr (assq :tangle (nth 2 (org-babel-get-src-block-info 'no-eval)))) - (user-error "Point is not in a source code block")))) + (user-error "Point is not in a source code block")))) + (targets (or (cadr (assoc (cdr + (assoc :n-tangle (nth 2 (org-babel-get-src-block-info)))) + org-babel-ntangle-destinations)) + '(nil))) ; iterate on one local target path-collector (source-file buffer-file-name)) + + (dolist (target targets) ;; iterate the n-tangle group + (progn (mapc ;; map over file-names (lambda (by-fn) - (let ((file-name (car by-fn))) + (let ((file-name (concat target (car by-fn)))) (when file-name (let ((lspecs (cdr by-fn)) (fnd (file-name-directory file-name)) @@ -354,6 +365,7 @@ (if (equal arg '(4)) (org-babel-tangle-single-block 1 t) (org-babel-tangle-collect-blocks lang-re tangle-file))) + )) (message "Tangled %d code block%s from %s" block-counter (if (= block-counter 1) "" "s") (file-name-nondirectory #+end_src In order to use this *:n-tangle* parameter, the destinations are declared in groups of host and/or root folders. #+begin_src elisp (setq org-babel-ntangle-destinations '(("test-1" ("/tmp/test/host-A" "/tmp/test/host-B" )) ("hosts-A&B/tmp" ("/-:hostA:/tmp/" "/-:hostB:/tmp/")))) #+end_src Calling *org-babel-n-tangle* with the universal argument runs the tangle processor, not on the entire file, but for the current block. The tangled output goes into the designated group. #+begin_example #+begin_src elisp :n-tangle "hosts-A&B/tmp" :tangle /x/y :mkdirp t (org-babel-n-tangle '(4)) #+end_src #+end_example In the above example the tangled outputs goes to *hostA:/tmp/x/y* and *hostB:/tmp/x/y* using a default protocol. In the absence of *:n-tangle* or when *org-babel-ntangle-destinations* is nil. *org-babel-n-tangle* behaves like *org-babel-tangle* What do you think ? Phil /"Oh what a tangled web we weave..."/