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 cKQnAEKjdWfTEQEA62LTzQ:P1 (envelope-from ) for ; Wed, 01 Jan 2025 20:19:14 +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 cKQnAEKjdWfTEQEA62LTzQ (envelope-from ) for ; Wed, 01 Jan 2025 21:19:14 +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=Y21wni3S; dkim=fail ("headers rsa verify failed") header.d=purelymail.com header.s=purelymail3 header.b=lDo6B61f; 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=1735762753; 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=urkKTs4pSD3APbRQD9twfGY4L+eJyBQjCdWqB+qRrr0=; b=Z2kGNRpapn/T0Fg6kZshVgtFHffdI4Dl+Fa9D4gIIQcgolSPgbdu7YPQxYVE9NugTkHmdc /YVoDF+fAtxIdRFMoLIc9dtx/Elj7HrIUTCBd8y7qQ7/SBw7gwDrhKjOZali41vPdlU9dE N5a9zXW2EVKWT1I0NC4aOkRbMvOwYLBf8TIjlux0M1NTpaaAoiWC8LU18Z5haolfIwKXgt 2pqeN3PdVobKRKHiJBolLjEnaY01gIGRoxrdO2GQpqvmqmBFHE9lkEQGfODDlH9MLpbZRO HiU5W/VaKM/cZtN4aj8L1Jr+N22k8eKwkIDaXAOV5tDr+t+RBi6zsLSJUAYfXA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=thibaut.dev header.s=purelymail3 header.b=Y21wni3S; dkim=fail ("headers rsa verify failed") header.d=purelymail.com header.s=purelymail3 header.b=lDo6B61f; 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=1735762753; a=rsa-sha256; cv=none; b=WL7phsFzPCYl+iIuMLFCA2Gzkdsi2qXVhR4NY0i4FtfNpTkSBSnsejC2qovSPj+YQX80ag R2xUiJtPs2Ck3RXs6EiHkCqspS4ktS7sBQgeTD+ifowmewBKppF4un62JCU0N1wFGblMrW MZcRuXg5Dyf7FJ8rOVTTErnuo6rq63fFIJ+GGUBy4a4g1kn6S6FZcnRVx8/yy7pzJB9vK8 FLCRyfmyfEpgzDwRAL5HTv3H1sR3GVZUaHl/PAphsw5Xh6C38sc2ShXwlAT4gHTrGHWCO3 Jtd1EWng2zSpjR9EF7a2rFgFpTDt6dkgCEc2ME0wCQaXeJ5GSUWqbgd1vI1hcg== 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 8E8D69DF15 for ; Wed, 01 Jan 2025 21:19:13 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tT5Ae-00075e-7m; Wed, 01 Jan 2025 15:18:24 -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 1tT5AX-00075K-HC for emacs-orgmode@gnu.org; Wed, 01 Jan 2025 15:18:18 -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 1tT5AU-0003Av-N3 for emacs-orgmode@gnu.org; Wed, 01 Jan 2025 15:18:16 -0500 DKIM-Signature: a=rsa-sha256; b=Y21wni3S3jCldJgT0D3JlDqQWXapRXsTyePYPoYLj5vcaeBsShk1T2tNvXztwTxt0yMZdTlxcbMV9O8fjxQ9ODXOAsuVTwFt8wiLkK/FR+g8VEuX8YEqEeHtdKfA/Plqbdd63JHcQ1slC4PbQuale7qd8XgEk5WOtW8aXvgIeWLC6WjQGXPHhA0Y/fNZitVdFyjTz8I6vqVN8tKvM5fv08HIE1axJN+q4HkxiRwfJ+yp3rXW/4GfTkMo5t/EeoH+KWJfTX3Unha7EohJWpoyB6H0nRRvGEDqz4EyLZMqd9dR9i/wiFW2RnIS80qiPS6x6YSKDv5hlnXqGxkGEp79sw==; s=purelymail3; d=thibaut.dev; v=1; bh=g5xo3SzyVgsp63HajcVVSGmshfwmdtcAEntT3n0bj5Q=; h=Received:From:To:Subject:Date; DKIM-Signature: a=rsa-sha256; b=lDo6B61fUXizfL4Fgs0loqnd2qt1c7Ai4HMBK1Bb3NEMSMIzjmYrpFP8ubQ1R+lx9ZYqDyPzJBzYXOCKWnVdOuGNfJTZjIWh1xVgQP76DPOZ8O8o4ts1zx2OiV4y8bTcTT8vJngJJMxWlxy4JiVvsV5Vx37f8/+b/G5Xznur8woig1K1T8Ew3B3hYGMbtOqUC10JvwQw7Vw9JO97iDwrcJW5P9zV4SrNKymXh3JOcGmpmVwsKlLpMQDYmHxxmZ9E8UJ6mXkTsQWjTGnEDQCvaRgsU1J8JKy1yMB1xX4Mbht9edm2SeU0ke30mnxQewKxfDXQdPI47mF52O37vl7vxw==; s=purelymail3; d=purelymail.com; v=1; bh=g5xo3SzyVgsp63HajcVVSGmshfwmdtcAEntT3n0bj5Q=; 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 310711864; (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Wed, 01 Jan 2025 20:18:07 +0000 (UTC) To: yantar92@posteo.net Cc: emacs-orgmode@gnu.org Subject: [PATCH] ob-tangle: source blocks without language can be tangled Date: Wed, 1 Jan 2025 21:16:51 +0100 Message-ID: <20250101201805.32825-1-thibaut@thibaut.dev> X-Mailer: git-send-email 2.47.1 In-Reply-To: <87frm2fxr1.fsf@localhost> References: <87frm2fxr1.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_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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: -6.50 X-Spam-Score: -6.50 X-Migadu-Queue-Id: 8E8D69DF15 X-Migadu-Scanner: mx10.migadu.com X-TUID: mVRnXqWrSgnS * lisp/ob-tangle.el: (org-babel-tangle-collect-blocks): source blocks without a language are 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. TINYCHANGE --- Here the same patch with the TINYCHANGE cookie. I'll get the fsf papers anyway as I intend to commit more. Thanks Ihor. 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