From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id QGc/MiFpyl4hfQAA0tVLHw (envelope-from ) for ; Sun, 24 May 2020 12:31:29 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id wKgYLiFpyl71OgAAB5/wlQ (envelope-from ) for ; Sun, 24 May 2020 12:31:29 +0000 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 500C3940BD0 for ; Sun, 24 May 2020 12:31:29 +0000 (UTC) Received: from localhost ([::1]:60368 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcpmq-0004zg-Au for larch@yhetil.org; Sun, 24 May 2020 08:31:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35656) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcplt-0004zS-Th for emacs-orgmode@gnu.org; Sun, 24 May 2020 08:30:29 -0400 Received: from mout-p-101.mailbox.org ([2001:67c:2050::465:101]:55352) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256) (Exim 4.90_1) (envelope-from ) id 1jcplo-00058P-RW; Sun, 24 May 2020 08:30:29 -0400 Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 49VKLd6dCzzKmWQ; Sun, 24 May 2020 14:30:17 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter02.heinlein-hosting.de (spamfilter02.heinlein-hosting.de [80.241.56.116]) (amavisd-new, port 10030) with ESMTP id DqzEyM4G-x5z; Sun, 24 May 2020 14:30:15 +0200 (CEST) From: Kevin Foley To: Bastien Subject: Re: [PATCH] Fix `org-babel-detangle' handling of false positives In-Reply-To: <87y2pk7zhn.fsf@gnu.org> References: <8736buek6n.fsf@gnu.org> <87h7zzdkqo.fsf@gnu.org> <87y2pk7zhn.fsf@gnu.org> Date: Sun, 24 May 2020 08:30:11 -0400 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Rspamd-Queue-Id: E361617F1 X-Rspamd-Score: -6.57 / 15.00 / 15.00 Received-SPF: pass client-ip=2001:67c:2050::465:101; envelope-from=kevin@kevinjfoley.me; helo=mout-p-101.mailbox.org X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: emacs-orgmode@gnu.org Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Spam-Score: 0.49 X-TUID: pjYpWyYvAWde --=-=-= Content-Type: text/plain Hi Bastien, Bastien writes: > I tried to apply your patch but I was not able to apply it, perhaps > just a problem with extracting it from your email. > > Can you send an (perhaps updated) version as an attachment? What issue did you have? I was able to download and apply the original patch to the latest commit on master (701c7bed) without any issues/conflicts using =git am -- =. I'm new to patch based development so I may be missing something. I've tried recreating the patch and attaching to this message, hopefully that resolves it. I've also attached it as "text/x-patch" instead of "text/plain" which I used last time, I'm not sure if that causes issues or if one is preferred. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Fix-org-babel-detangle-handling-of-false-positives.patch >From eae83992e0c671d0162ba60f567629138ecc0074 Mon Sep 17 00:00:00 2001 From: "Kevin J. Foley" Date: Tue, 28 Jan 2020 17:51:29 -0500 Subject: [PATCH] Fix `org-babel-detangle' handling of false positives * lisp/ob-tangle.el (org-babel-detangle): Handle false positive matches of `org-link-bracket-re' * testing/examples/babel.el: New file for babel detangle false positive test * testing/examples/babel.org (detangle): Add detangle/false positive example * testing/lisp/test-ob-tangle.el (ob-tangle/detangle-false-positive): Add test for detangle false positive --- lisp/ob-tangle.el | 18 ++++++++++-------- testing/examples/babel.el | 5 +++++ testing/examples/babel.org | 13 +++++++++++++ testing/lisp/test-ob-tangle.el | 11 +++++++++++ 4 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 testing/examples/babel.el diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el index 8fd407478..4fe444532 100644 --- a/lisp/ob-tangle.el +++ b/lisp/ob-tangle.el @@ -516,14 +516,16 @@ (defun org-babel-detangle (&optional source-code-file) (goto-char (point-min)) (let ((counter 0) new-body end) (while (re-search-forward org-link-bracket-re nil t) - (when (re-search-forward - (concat " " (regexp-quote (match-string 2)) " ends here")) - (setq end (match-end 0)) - (forward-line -1) - (save-excursion - (when (setq new-body (org-babel-tangle-jump-to-org)) - (org-babel-update-block-body new-body))) - (setq counter (+ 1 counter))) + (if (and (match-string 2) + (re-search-forward + (concat " " (regexp-quote (match-string 2)) " ends here") nil t)) + (progn (setq end (match-end 0)) + (forward-line -1) + (save-excursion + (when (setq new-body (org-babel-tangle-jump-to-org)) + (org-babel-update-block-body new-body))) + (setq counter (+ 1 counter))) + (setq end (point))) (goto-char end)) (prog1 counter (message "Detangled %d code blocks" counter))))) diff --git a/testing/examples/babel.el b/testing/examples/babel.el new file mode 100644 index 000000000..a7bb0ccf5 --- /dev/null +++ b/testing/examples/babel.el @@ -0,0 +1,5 @@ +(string-match-p "^#[[:digit:]]+$" "#123") + +;; [[id:73115FB0-6565-442B-BB95-50195A499EF4][detangle:1]] +;; detangle changes +;; linked content to detangle:1 ends here diff --git a/testing/examples/babel.org b/testing/examples/babel.org index c889d5d92..b0942800a 100644 --- a/testing/examples/babel.org +++ b/testing/examples/babel.org @@ -488,3 +488,16 @@ nil #+BEGIN_SRC emacs-lisp :output-dir xxx :file foo.bar nil #+END_SRC +* detangle +** false positive +The =[[= causes a false positive which ~org-babel-detangle~ should handle properly +#+begin_src emacs-lisp :tangle yes +(string-match-p "^#[[:digit:]]+$" "#123") +#+end_src +** linked content to detangle +:PROPERTIES: +:ID: 73115FB0-6565-442B-BB95-50195A499EF4 +:END: +#+begin_src emacs-lisp :tangle yes :comments link + ;; detangle +#+end_src diff --git a/testing/lisp/test-ob-tangle.el b/testing/lisp/test-ob-tangle.el index 301f7aff7..ed75e6ca4 100644 --- a/testing/lisp/test-ob-tangle.el +++ b/testing/lisp/test-ob-tangle.el @@ -25,6 +25,8 @@ ;;; Code: +(require 'subr-x) + ;; TODO ;; (ert-deftest ob-tangle/noweb-on-tangle () ;; "Noweb header arguments tangle correctly. @@ -380,6 +382,15 @@ (ert-deftest ob-tangle/commented-src-blocks () (org-split-string (buffer-string)))) (delete-file file)))))) +(ert-deftest ob-tangle/detangle-false-positive () + "Test handling of false positive link during detangle." + (org-test-in-example-file (expand-file-name "babel.el" org-test-example-dir) + (org-babel-detangle) + (org-test-at-id "73115FB0-6565-442B-BB95-50195A499EF4" + (org-babel-next-src-block) + (should (equal (string-trim (org-element-property :value (org-element-at-point))) + ";; detangle changes"))))) + (provide 'test-ob-tangle) ;;; test-ob-tangle.el ends here -- 2.19.0 --=-=-= Content-Type: text/plain Thanks, Kevin --=-=-=--