From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id KL9WF/Zws154GwAA0tVLHw (envelope-from ) for ; Thu, 07 May 2020 02:22:46 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id 6PhcFwJxs17FEgAAbx9fmQ (envelope-from ) for ; Thu, 07 May 2020 02:22:58 +0000 Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:470:142::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 3C0AC940292 for ; Thu, 7 May 2020 02:22:56 +0000 (UTC) Received: from localhost ([::1]:51926 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jWWBc-0000Kt-HW for larch@yhetil.org; Wed, 06 May 2020 22:22:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56452) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jWWBI-0000Kl-CF for emacs-orgmode@gnu.org; Wed, 06 May 2020 22:22:36 -0400 Received: from relay12.mail.gandi.net ([217.70.178.232]:37297) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jWWBG-0006Iv-Qj for emacs-orgmode@gnu.org; Wed, 06 May 2020 22:22:36 -0400 Received: from localhost (unknown [159.146.10.161]) (Authenticated sender: self@gkayaalp.com) by relay12.mail.gandi.net (Postfix) with ESMTPSA id F1113200003 for ; Thu, 7 May 2020 02:22:29 +0000 (UTC) From: =?utf-8?Q?G=C3=B6ktu=C4=9F_Kayaalp?= To: emacs-orgmode@gnu.org Subject: =?utf-8?Q?=E2=80=98org-test-with-temp-text=E2=80=99?= fails weirdly Date: Thu, 07 May 2020 05:22:24 +0300 Message-ID: <87h7wsjxgf.fsf@gkayaalp.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: none client-ip=217.70.178.232; envelope-from=self@gkayaalp.com; helo=relay12.mail.gandi.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/06 22:22:30 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_BL=0.001, RCVD_IN_MSPIKE_L3=0.001, URIBL_BLOCKED=0.001, URIBL_SBL=1.623, URIBL_SBL_A=0.1 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: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 X-Spam-Score: 2.29 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 2001:470:142::17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Scan-Result: default: False [2.29 / 13.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; GENERIC_REPUTATION(0.00)[-0.49748344428655]; DWL_DNSWL_FAIL(0.00)[2001:470:142::17:server fail]; R_SPF_ALLOW(0.00)[+ip6:2001:470:142::/48:c]; IP_REPUTATION_HAM(0.00)[asn: 22989(0.11), country: US(-0.00), ip: 2001:470:142::17(-0.50)]; TO_DN_NONE(0.00)[]; MX_GOOD(-0.50)[cached: eggs.gnu.org]; MAILLIST(-0.20)[mailman]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; RCVD_IN_DNSWL_FAIL(0.00)[2001:470:142::17:server fail]; RCVD_TLS_LAST(0.00)[]; R_DKIM_NA(0.00)[]; ASN(0.00)[asn:22989, ipnet:2001:470:142::/48, country:US]; MID_RHS_MATCH_FROM(0.00)[]; TAGGED_FROM(0.00)[larch=yhetil.org]; ARC_NA(0.00)[]; RECEIVED_SPAMHAUS_XBL(3.00)[159.146.10.161:received]; RCVD_COUNT_FIVE(0.00)[5]; FROM_NEQ_ENVFROM(0.00)[self@gkayaalp.com,emacs-orgmode-bounces@gnu.org]; FROM_HAS_DN(0.00)[]; URIBL_BLOCKED(0.00)[gkayaalp.com:email]; MIME_GOOD(-0.10)[multipart/mixed,text/plain,text/x-diff]; PREVIOUSLY_DELIVERED(0.00)[emacs-orgmode@gnu.org]; DMARC_NA(0.00)[gkayaalp.com]; HAS_LIST_UNSUB(-0.01)[]; RCPT_COUNT_ONE(0.00)[1]; BAD_REP_POLICIES(0.10)[]; RECEIVED_SPAMHAUS_PBL(0.00)[159.146.10.161:received]; MIME_TRACE(0.00)[0:+,1:+,2:+]; FORGED_SENDER_MAILLIST(0.00)[] X-TUID: Y+EGkri7zHv0 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello, I was trying to have spurious indentation removed from Python source blocks before execution so that such blocks can be indented in Org mode buffers. I managed to do so successfully, but some tests keep failing and I believe it=E2=80=99s the test runner that=E2=80=99s the culprit. With= the attached patch applied, I=E2=80=99ve observed successful execution when manually try= ing test cases similar to those in test-ob-python.el, indented or not. But the following tests fail with =E2=80=98(args-out-of-range "return x" 42 43)= =E2=80=99 errors: FAILED test-ob-python/colnames-nil-header-argument FAILED test-ob-python/colnames-no-header-argument FAILED test-ob-python/colnames-yes-header-argument (9 tests fail without this patch, the other 6 is irrelevant and do fail when I test w/o the patch too, on commit b171ff02f.) I think the cause is the modifications to the code blocks body (deletion of spurious indentation from an indented src block), but I=E2=80=99m not su= re how exactly. This is weird because the in-buffer text doesn=E2=80=99t change. In any case I=E2=80=99m also proposing the attached patch as a new feature. Could start a new thread for it if necessary. P.S.: please keep me in the CC in your replies, I=E2=80=99m not subscribed = to the mailing list. --=20 =C4=B0. G=C3=B6ktu=C4=9F Kayaalp / @cadadr / pgp: 024C 30DD 597D 142B 49AC 40EB 465C D949 B101 2427 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-lisp-ob-python.el-remove-spurious-indentation-before.patch >From 88ad28dce8e0111c10ca18db5f58d35924112441 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0=2E=20G=C3=B6ktu=C4=9F=20Kayaalp?= Date: Thu, 7 May 2020 03:11:50 +0300 Subject: [PATCH] lisp/ob-python.el: remove spurious indentation before evaluation --- lisp/ob-python.el | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lisp/ob-python.el b/lisp/ob-python.el index dbcfac08d..42bb47f73 100644 --- a/lisp/ob-python.el +++ b/lisp/ob-python.el @@ -69,6 +69,24 @@ This will typically be either `python' or `python-mode'." :package-version '(Org . "8.0") :type 'symbol) +(defun org-babel-python--clean-spurious-indentation (body) + (let* ((extra-indentation + (save-match-data + (string-match "\\`\\([ \t]+\\)" body) + (match-string 1 body))) + (xlen (length extra-indentation))) + (if (zerop xlen) + body + (mapconcat + (lambda (line) (if (<= (length line) xlen) + line + (if (string= extra-indentation + (substring line 0 xlen)) + (substring line xlen) + line))) + (split-string body "\n") + "\n")))) + (defun org-babel-execute:python (body params) "Execute a block of Python code with Babel. This function is called by `org-babel-execute-src-block'." @@ -84,7 +102,8 @@ This function is called by `org-babel-execute-src-block'." (preamble (cdr (assq :preamble params))) (full-body (org-babel-expand-body:generic - (concat body (if return-val (format "\nreturn %s" return-val) "")) + (concat (org-babel-python--clean-spurious-indentation body) + (if return-val (format "\nreturn %s" return-val) "")) params (org-babel-variable-assignments:python params))) (result (org-babel-python-evaluate session full-body result-type result-params preamble))) -- 2.17.1 --=-=-=--