From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:306:2d92::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id 6OH2OWPar2QaHwEASxT56A (envelope-from ) for ; Thu, 13 Jul 2023 13:05:08 +0200 Received: from aspmx1.migadu.com ([2001:41d0:306:2d92::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id eKD9OWPar2TuSAEA9RJhRA (envelope-from ) for ; Thu, 13 Jul 2023 13:05:07 +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 68E33448BD for ; Thu, 13 Jul 2023 13:05:07 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=lipklim.org header.s=key1 header.b=V59ivH66; dmarc=pass (policy=quarantine) header.from=lipklim.org; 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=1689246307; 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:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=u6ZAhMpwiQi02pS8wS14T7flPY6/aJg9yFX32rAAfRU=; b=E8jA2PU5Penpl/+HNQ8VA+u2yhq4hk84cq1lrOSJS79kDgatNwIk5V/HLOzomTZe3k+qFm igdpOKwdPfunXOcVm0aNaUOh37dwzFEfVe5Dpm4U3jjM6VjZMveq5376wDa8htujRtu18J 1kpwe9eSs2NJowgtm2NCVEhYqkzP0EWVErSaCkwVF19Nk/bsoFDx+uG+AtlO10egFgpuUB d/YYh5qzixu505vfoAxWgZAkHiSKblNRdvRxOK6OWe2SvVJ45EkOkvFecEhC4w2Vt2cIhF NgIq8aEC53Laub0xfPV7QLnyYSAUy7IQMCNtZ3RQgChs63PeCHe1eXRzij6ZoA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=lipklim.org header.s=key1 header.b=V59ivH66; dmarc=pass (policy=quarantine) header.from=lipklim.org; 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-Seal: i=1; s=key1; d=yhetil.org; t=1689246307; a=rsa-sha256; cv=none; b=Y6mRaSY2ro66sEy7S8QxDAAUeMPAGCqxIVv5Xqi4gJKmFrfsUt4jyehVUPlStTZToL55Tj ftS2bxXNw5u3yE0F3pJcuPYb3i2SYBPNp36pvJCBjNkUfDHQp1ZfUzobxzsbzBlK3HdPNc FCU7Hymk/iSklh/0u0c+5ViM6WL8Ypote5n/fWxBdN9sc/99tKTHABx+aIKwwPtI7bn61F t3E8LyUXOPpZ71Wjymurh75M3Lug1XITR8WZSU+sClI/4UrQUdbfODtf8pWtiN1xrLf/AW 7bJjn1jh1gw22opDogWmsPOCKB56KMCehuJeeYju8+Wa9iI/kyTe/U44CPcSPg== Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qJu7H-0001jQ-Ma; Thu, 13 Jul 2023 07:04:11 -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 1qJu7F-0001i4-47 for emacs-orgmode@gnu.org; Thu, 13 Jul 2023 07:04:09 -0400 Received: from out-31.mta1.migadu.com ([2001:41d0:203:375::1f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qJu7C-0005mh-Jl for emacs-orgmode@gnu.org; Thu, 13 Jul 2023 07:04:08 -0400 References: <87lefkd9tb.fsf@lipklim.org> <87h6q8d9lz.fsf@lipklim.org> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lipklim.org; s=key1; t=1689246240; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=u6ZAhMpwiQi02pS8wS14T7flPY6/aJg9yFX32rAAfRU=; b=V59ivH66ZOi+wJjnx/mvlAwZFjo0JdshNXS/O8hSSQbXPM3JA8k7LmtM9+aTP6YoONfSQ9 qApW6Uol0u8VOlYHflb2298qKGXMxxYP0sTFD/HLD1mnSXq/82wy9syU6LhKxJrkTCNQHQ sYkApSo/cA1N/zI1HGTMCnUzy+afhQY= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Evgenii Klimov To: emacs-orgmode@gnu.org Subject: [PATCH v2] ob-tangle.el: Blocks overwrite each other when grouping before tangling Date: Thu, 13 Jul 2023 11:52:36 +0100 In-reply-to: <87h6q8d9lz.fsf@lipklim.org> Message-ID: <87cz0wcbtt.fsf@lipklim.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2001:41d0:203:375::1f; envelope-from=eugene.dev@lipklim.org; helo=out-31.mta1.migadu.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, 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-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Queue-Id: 68E33448BD X-Migadu-Scanner: mx2.migadu.com X-Migadu-Spam-Score: -9.57 X-Spam-Score: -9.57 X-TUID: yiBRLAHn+rrf --=-=-= Content-Type: text/plain In this version I just updated the docstrings for the relevant functions, because prior to that it wasn't clear: does this "default export file for *all* source blocks" influence blocks with :tangle "yes"/FILENAME? --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=v2-0001-ob-tangle.el-Avoid-relative-file-names-when-group.patch >From 1a4f76960cf11fb192f2bee2cdc8778c7b897f1a Mon Sep 17 00:00:00 2001 From: Evgenii Klimov Date: Wed, 12 Jul 2023 19:24:48 +0100 Subject: [PATCH v2] ob-tangle.el: Avoid relative file names when grouping blocks to tangle * lisp/ob-tangle.el (org-babel-effective-tangled-filename): Avoid using relative file names that could cause one block to overwrite the others in `org-babel-tangle-collect-blocks' if they have the same target file but in different formats. (org-babel-tangle-file, org-babel-tangle): Clarify the meaning of the TARGET-FILE argument. --- lisp/ob-tangle.el | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el index 25129616f..1274d0db7 100644 --- a/lisp/ob-tangle.el +++ b/lisp/ob-tangle.el @@ -194,11 +194,12 @@ evaluating BODY." ;;;###autoload (defun org-babel-tangle-file (file &optional target-file lang-re) - "Extract the bodies of source code blocks in FILE. + "Extract the bodies of source code blocks from FILE. Source code blocks are extracted with `org-babel-tangle'. Optional argument TARGET-FILE can be used to specify a default -export file for all source blocks. +export file for all source blocks without :tangle header +argument. Optional argument LANG-RE can be used to limit the exported source code blocks by languages matching a regular expression. @@ -230,9 +231,10 @@ With one universal prefix argument, only tangle the block at point. When two universal prefix arguments, only tangle blocks for the tangle file of the block at point. Optional argument TARGET-FILE can be used to specify a default -export file for all source blocks. Optional argument LANG-RE can -be used to limit the exported source code blocks by languages -matching a regular expression." +export file for all source blocks without :tangle header +argument. Optional argument LANG-RE can be used to limit the +exported source code blocks by languages matching a regular +expression." (interactive "P") (run-hooks 'org-babel-pre-tangle-hook) ;; Possibly Restrict the buffer to the current code block @@ -427,17 +429,23 @@ that the appropriate major-mode is set. SPEC has the form: org-babel-tangle-comment-format-end link-data))))) (defun org-babel-effective-tangled-filename (buffer-fn src-lang src-tfile) - "Return effective tangled filename of a source-code block. + "Return effective tangled absolute filename of a source-code block. BUFFER-FN is the name of the buffer, SRC-LANG the language of the block and SRC-TFILE is the value of the :tangle header argument, as computed by `org-babel-tangle-single-block'." - (let ((base-name (cond - ((string= "yes" src-tfile) - ;; Use the buffer name - (file-name-sans-extension buffer-fn)) - ((string= "no" src-tfile) nil) - ((> (length src-tfile) 0) src-tfile))) - (ext (or (cdr (assoc src-lang org-babel-tangle-lang-exts)) src-lang))) + (let* ((fnd (file-name-directory (buffer-file-name + (get-buffer buffer-fn)))) + (base-name (cond + ((string= "yes" src-tfile) + ;; Use the buffer name + (file-name-concat fnd + (file-name-sans-extension buffer-fn))) + ((string= "no" src-tfile) nil) + ((> (length src-tfile) 0) + (if (file-name-directory src-tfile) + src-tfile + (file-name-concat fnd src-tfile))))) + (ext (or (cdr (assoc src-lang org-babel-tangle-lang-exts)) src-lang))) (when base-name ;; decide if we want to add ext to base-name (if (and ext (string= "yes" src-tfile)) -- 2.34.1 --=-=-=--