From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.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 SJegB53Bc2cg3QAAqHPOHw:P1 (envelope-from ) for ; Tue, 31 Dec 2024 10:04:13 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id SJegB53Bc2cg3QAAqHPOHw (envelope-from ) for ; Tue, 31 Dec 2024 11:04:13 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=thibaut.dev header.s=purelymail3 header.b=foAogXnS; dkim=fail ("headers rsa verify failed") header.d=purelymail.com header.s=purelymail3 header.b=DcBDacPZ; 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=none) header.from=gnu.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1735639452; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=ayEypcf34ImiOtDUPzw1Axvyr3q+xBaM3l3tbiBHeu4=; b=OHwblcBYvaEToaxAmzXjfTJ8YlsPPJytvZDvUWnPY+joF50SvxEVGoTrp9/S2kPDT9Xjn1 OtpgW7JYixriz9Cw0a/eeSFKk7hQQLzVHMIGJlPfrnPntc/TW9ochyHnZUI/+YnhhwYXZ+ v98LbZlGz7rFWupt+dwerb1yRKqF6ovQ9iLzki8iVDE0zWlGI8ZcLf25cpz9od6qyjFe16 bDIl/nUNfIQzpHl75iao2DBmJ1rJhFjotH5Wd8AZkcJAZBPXDGvA4WGOfmdwf9de7BIb3A 4NOsSfHgDjnZ4a6699k9fT5/EqZBytcaU8gAAajTazMIYmUn5Ve/pTuWXgplkQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=thibaut.dev header.s=purelymail3 header.b=foAogXnS; dkim=fail ("headers rsa verify failed") header.d=purelymail.com header.s=purelymail3 header.b=DcBDacPZ; 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=none) header.from=gnu.org ARC-Seal: i=1; s=key1; d=yhetil.org; t=1735639452; a=rsa-sha256; cv=none; b=ffbPydPJUYYIHGo0axhg59ppA9mrq1oUeq5CZDsgo5yNAIFYkH2nKrXPwH3MpqA0amqK4l /KT4fUKMoXlvnRA6zBquoibEgqXfuF4Z3s8GZaEGcg0Cow0zuMuepRZm+AMm/T1l8x9sWy bgVXPpmOKRIPB0znXpfGAJDvq8ymOwcUxK0xgQ/G/3pipWwL430Tad/omXOtvnxX71IT8D RczDgljfNpsshuy6hQiOzkkRGkF9o4ZBA9hKYXPwdMab3jqRR1tzpGjXDgWxkUmNCGbxn3 naefpBAJn6smVBTZ9WzE8lLulwS3+9EVVcPRzg3VxLwjF85rgaWi5d/NGfNjaw== 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 B09B819C59 for ; Tue, 31 Dec 2024 11:04:12 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tSYfV-0008Bp-Ty; Tue, 31 Dec 2024 04:36:06 -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 1tSYfU-0008Ar-Er for emacs-orgmode@gnu.org; Tue, 31 Dec 2024 04:36:04 -0500 Received: from sendmail.purelymail.com ([34.202.193.197]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tSYfR-0000nn-C6 for emacs-orgmode@gnu.org; Tue, 31 Dec 2024 04:36:04 -0500 DKIM-Signature: a=rsa-sha256; b=foAogXnSIUups1XQ2V+RFrzNyZec3KTxg+YSaln6GHY1E4FXa85rmx03P7/oiakzZw1I7bAkg9uHHyHV53LOfEVoMCd2DVS7TRLWzuk/geUoP4Fp8YAnkUdSSoyZkdXjtwzFAyARZ041j+IiMPXF460bERWiMJXrDQiBIQk9C8bX6wrJh4dQRFkPswq3tOrVwiVtLW1w4E9SxCQbiDD3yYXUo3jgzR/8zpbS4YiitaEDKFAbBDdQg3GNJfevAcWZen2nJVpv20M0Db0lky1vVyGom7VzD+IyUkK5sudjQNCjpsBlU6KKK7rhYRzlgTtJpqoes7q31An4KsySf6psig==; s=purelymail3; d=thibaut.dev; v=1; bh=e/lmYDuMScw180UPkHoHRkygKxwPfJSKT1w775ZyWT8=; h=Received:From:To:Subject:Date; DKIM-Signature: a=rsa-sha256; b=DcBDacPZH9WF0UFC7Ci/mZZhBf004JPDaSWXyvoV7Y8/i5ejbrn2wH80/oF5lYgbabHihKSaTqLVGW1ZhsIfZWi0ugVqh97bdFxQ3BABFzRAOSkNyVkHaR4vn0afKjvyVYYnRGu9wQB8WEpj85NzXRy04o5hteXjHOmUei3xvH0v/v4knIpt46TIj3VmsGk7jci6TSqgoXzE+yEq0TjzfCe3OntGp0My9EFcTrsJTodAofB3B1tBuh+gky62xy0zLaBa1PO341+fnly9uQ7sfB2pDgQ0H5KzHY5D8TVMt9syaJr5CEhZCDRIyWOVhQ08RcLJmIygVlFGwn8BQs3HRw==; s=purelymail3; d=purelymail.com; v=1; bh=e/lmYDuMScw180UPkHoHRkygKxwPfJSKT1w775ZyWT8=; h=Feedback-ID:Received:From:To:Subject:Date; Feedback-ID: 12196:2647:null:purelymail X-Pm-Original-To: emacs-orgmode@gnu.org Received: by smtp.purelymail.com (Purelymail SMTP) with ESMTPSA id 1931050875; (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Tue, 31 Dec 2024 09:35:55 +0000 (UTC) To: yantar92@posteo.net Cc: emacs-orgmode@gnu.org Subject: [PATCH] ob-tangle: source blocks without language can be tangled (was: [BUG] Inconsistent org-babel tangle behaviour) Date: Tue, 31 Dec 2024 10:31:59 +0100 Message-ID: <20241231093553.13814-1-thibaut@thibaut.dev> X-Mailer: git-send-email 2.47.1 In-Reply-To: <87jzbix4le.fsf@localhost> References: <87jzbix4le.fsf@localhost> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by Purelymail Content-Type: text/plain; charset=UTF-8 Received-SPF: pass client-ip=34.202.193.197; envelope-from=thibaut@thibaut.dev; helo=sendmail.purelymail.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, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, 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: , Reply-to: Thibaut Meyer From: Thibaut Meyer via "General discussions about Org-mode." 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-Spam-Score: -5.20 X-Spam-Score: -5.20 X-Migadu-Queue-Id: B09B819C59 X-Migadu-Scanner: mx10.migadu.com X-TUID: thtADBY3OMFm * lisp/ob-tangle.el: (org-babel-tangle-collect-blocks): source blocks without a language are not not ignored anymore, if they inherit a src-tfile other than "yes" or "no". * lisp/ob-core.el: adapts the org-babel-src-block-regexp regular expression to make the language part of a source block optional. * testing/lisp/test-ob-tangle.el: (ob-tangle/collect-blocks): Augment the test with source blocks without language specifiers. * etc/ORG-NEWS: (=3Dob-tangle=3D now tangles source blocks that do not specify a =3Dlanguage=3D if an inherited property sets a tangle filename): Document the new behaviour. * doc/org-manual.org: (Structure of Code Blocks) Clarify what happens when the language identifier is omitted. --- Here is my attempt. Modifying the regex in ob-core.el felt scary, but it seems fine since this didn't break any tests and manually testing the new regex seemed to work fine. I've added the small change to the documentation as you suggested as I think it clarifies things regarding how the source block structure is interpreted. Cheers. doc/org-manual.org | 3 ++- etc/ORG-NEWS | 8 ++++++++ lisp/ob-core.el | 4 ++-- lisp/ob-tangle.el | 8 ++++++-- testing/lisp/test-ob-tangle.el | 16 ++++++++++++---- 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/doc/org-manual.org b/doc/org-manual.org index 2d5fd57b3..f0c53265a 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -18028,7 +18028,8 @@ or block. See [[*Languages]], for identifiers of supported languages. =20 When =3D=3D identifier is omitted, the block also cannot - have =3D=3D and =3D
=3D. + have =3D=3D and =3D
=3D. Otherwise, the firs= t + switch/argument will be treated as =3D=3D. =20 Language identifier is also used to fontify code blocks in Org buffers, when ~org-src-fontify-natively~ is set to non-~nil~. See diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 2d4616fab..4aa628c7e 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -437,6 +437,14 @@ For example, given =3DH:3=3D and =3Dtoc:2=3D in =3D#+O= PTIONS:=3D, all headings at the 1st and 2nd level appear in the table of contents and those at the 3rd level do not. =20 +*** =3Dob-tangle=3D now tangles source blocks that do not specify a =3Dlan= guage=3D if an inherited property sets a tangle filename + +Previously, all source blocks that did not specify a =3Dlanguage=3D where +ignored by ~org-babel-tangle-collect-blocks~. Now, if it inherits a +:tangle header argument with a value other than =3Dno=3D or =3Dyes=3D (tha= t is, a +filename), a source block without =3Dlanguage=3D will get tangled to that +file. + * Version 9.7 =20 ** Important announcements and breaking changes diff --git a/lisp/ob-core.el b/lisp/ob-core.el index ff021cbd3..cf56367f8 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -216,8 +216,8 @@ When matching, reference is stored in match group 1." =20 (defvar org-babel-src-block-regexp (concat - ;; (1) indentation (2) lang - "^\\([ \t]*\\)#\\+begin_src[ \t]+\\([^ \f\t\n\r\v]+\\)[ \t]*" + ;; (1) indentation (2) lang + "^\\([ \t]*\\)#\\+begin_src\\(?:[ \t]+\\([^ \f\t\n\r\v]*\\)\\)?[ \t]*" ;; (3) switches "\\([^\":\n]*\"[^\"\n*]*\"[^\":\n]*\\|[^\":\n]*\\)" ;; (4) header arguments diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el index 044212da2..d37d3c67f 100644 --- a/lisp/ob-tangle.el +++ b/lisp/ob-tangle.el @@ -508,9 +508,13 @@ code blocks by target file." =09 (src-lang (nth 0 info)) =09 (src-tfile (cdr (assq :tangle (nth 2 info))))) =09 (unless (or (string=3D src-tfile "no") - (not src-lang) ;; src block without lang + ;; src block without lang + (and (not src-lang) (string=3D src-tfile "yes")) =09=09 (and tangle-file (not (equal tangle-file src-tfile))) -=09=09 (and lang-re (not (string-match-p lang-re src-lang)))) + ;; lang-re but either no lang or lang doesn't match +=09=09 (and lang-re + (or (not src-lang) + (not (string-match-p lang-re src-lang))))) =09 ;; Add the spec for this block to blocks under its tangled =09 ;; file name. =09 (let* ((block (org-babel-tangle-single-block counter)) diff --git a/testing/lisp/test-ob-tangle.el b/testing/lisp/test-ob-tangle.e= l index e13bca0cb..6e95c4c91 100644 --- a/testing/lisp/test-ob-tangle.el +++ b/testing/lisp/test-ob-tangle.el @@ -628,6 +628,10 @@ another block \"H1: :tangle ~/../../tmp/absolute.el\" #+end_src =20 +#+begin_src +\"H1: no language and inherited :tangle relative.el in properties\" +#+end_src + * H2 without :tangle in properties =20 #+begin_src emacs-lisp @@ -660,6 +664,10 @@ another block =20 #+begin_src emacs-lisp :tangle ~/../../tmp/absolute.el \"H2: :tangle ~/../../tmp/absolute.el\" +#+end_src + +#+begin_src +\"H2: without language and thus without :tangle\" #+end_src" `((?a . ,el-file-abs) (?r . ,el-file-rel)))) @@ -684,7 +692,7 @@ another block collected-blocks))))) (should (equal (funcall normalize-expected-targets-alist `(("/tmp/absolute.el" . 4) - ("relative.el" . 5) + ("relative.el" . 6) ;; file name differs between tests (,el-file-abs . 4))) (funcall count-blocks-in-target-files @@ -699,11 +707,11 @@ another block (should (equal (funcall normalize-expected-targets-alist `(("/tmp/absolute.el" . 4) - ("relative.el" . 5) + ("relative.el" . 6) ;; Default :tangle header now also ;; points to the file name derived from the = name of - ;; the Org file, so 5 blocks should go there= . - (,el-file-abs . 5))) + ;; the Org file, so 6 blocks should go there= . + (,el-file-abs . 6))) (funcall count-blocks-in-target-files (org-babel-tangle-collect-blocks))))))))) =20 --=20 2.47.1