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 3fvmGdC+3V4uUAAA0tVLHw (envelope-from ) for ; Mon, 08 Jun 2020 04:30:08 +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 uAxnFdC+3V5hEgAAbx9fmQ (envelope-from ) for ; Mon, 08 Jun 2020 04:30:08 +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 744EA9400B1 for ; Mon, 8 Jun 2020 04:30:07 +0000 (UTC) Received: from localhost ([::1]:43622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ji9QC-0004g8-Uo for larch@yhetil.org; Mon, 08 Jun 2020 00:30:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49906) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ji9Pm-0004g0-Nh for emacs-orgmode@gnu.org; Mon, 08 Jun 2020 00:29:38 -0400 Received: from pb-smtp21.pobox.com ([173.228.157.53]:61491) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ji9Pk-0003wj-5c for emacs-orgmode@gnu.org; Mon, 08 Jun 2020 00:29:37 -0400 Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id C6765E63DB; Mon, 8 Jun 2020 00:29:32 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:in-reply-to:references:date:message-id:mime-version :content-type; s=sasl; bh=SYIg1EzcegMKIT5SDGr6LKFoB4M=; b=M+wIuI GRY+ojlwGoJsPZ0wfl+ia18BaCej4CdOt4PwYtzxDNz6uXmpEW4Gm118OKdn0kgw i3v1w6PWB3x5rn3XwRfn5xYHfTg6nJh0b/C8lL5zCQO/fUQaFA/r39gj2kNw3smF 954agXZxs6PIP3/9TteO0+YTVHIIHEwrreCAo= Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 9ED61E63DA; Mon, 8 Jun 2020 00:29:32 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=kyleam.com; h=from:to:cc:subject:in-reply-to:references:date:message-id:mime-version:content-type; s=mesmtp; bh=JcOw4K83X2qzSvNK3fLsFjPNspngP6Zcnba8GfEQcR8=; b=ya034gpAPxGdquCwIVHe2LbeYuvB+LmigimCq6wOKeTlu1hPfG32PdyAp+z81J8rJfrZZTzTJNmCZybWp98bZRDjFf/gUqfVQ0C9jWKjqDtOF+GPQ4UZ9aGgOQgDrnkRDtTVZSoboktZNTYorkkvgjbdZJWEUyuV2TVbIOac8kA= Received: from localhost (unknown [45.33.91.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp21.pobox.com (Postfix) with ESMTPSA id DF002E63D7; Mon, 8 Jun 2020 00:29:29 -0400 (EDT) (envelope-from kyle@kyleam.com) From: Kyle Meyer To: Jack Kamm Subject: Re: Bug: ob-python mangles multiline :var values [9.3.6 (release_9.3.6-397-ga089600)] In-Reply-To: <87r1usxdba.fsf@gmail.com> References: <87sgico0ne.fsf@gmail.com> <87a71xtmh0.fsf@gmail.com> <87h7w18ca1.fsf@fastmail.fm> <87zh9t9hkw.fsf@gmail.com> <87tv009l9a.fsf@gmail.com> <87r1usxdba.fsf@gmail.com> Date: Mon, 08 Jun 2020 04:29:27 +0000 Message-ID: <87a71ew57c.fsf@kyleam.com> MIME-Version: 1.0 Content-Type: text/plain X-Pobox-Relay-ID: A4FD82F0-A940-11EA-B912-8D86F504CC47-24757444!pb-smtp21.pobox.com Received-SPF: pass client-ip=173.228.157.53; envelope-from=kyle@kyleam.com; helo=pb-smtp21.pobox.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/08 00:29:33 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_DNSWL_LOW=-0.7, 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, Matthew Lundin , =?utf-8?B?xaB0xJtww6FuIE7Em21lYw==?= Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=fail (rsa verify failed) header.d=pobox.com header.s=sasl header.b=M+wIuI G; dkim=fail (rsa verify failed) header.d=kyleam.com header.s=mesmtp header.b=ya034gpA; 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.01 X-TUID: HQupDW4cLpWy Jack Kamm writes: > My fix this time was to use functions from python.el to indent, and to > detect whether we are in a string and shouldn't be indented. > > I also added a couple more unit tests, one for multiline strings, and > one for the variable scope/assignment issue that Matt reported. Thanks for working on this. > diff --git a/lisp/ob-python.el b/lisp/ob-python.el > index dbcfac08d..622f69ce3 100644 > --- a/lisp/ob-python.el > +++ b/lisp/ob-python.el > @@ -296,11 +296,15 @@ (defun org-babel-python-evaluate-external-process > (if (member "pp" result-params) > org-babel-python-pp-wrapper-method > org-babel-python-wrapper-method) > - (mapconcat > - (lambda (line) (format "\t%s" line)) > - (split-string (org-remove-indentation (org-trim body)) > - "[\r\n]") > - "\n") > + (with-temp-buffer > + (insert body) > + (goto-char (point-min)) > + (while (< (point) (point-max)) nit-pick: In this code base, (not (eobp)) is the more common way to spell this. % git grep "(< (point) (point-max))" master | wc -l 1 % git grep "(not (eobp))" master | wc -l 44 > + (unless (python-syntax-context 'string) > + (python-indent-shift-right (line-beginning-position) > + (line-end-position))) These lead to byte-compiler warnings: Compiling /home/kyle/src/emacs/org-mode-devel/lisp/ob-python.el... In end of data: ob-python.el:391:1:Warning: the following functions are not known to be defined: python-syntax-context, python-indent-shift-right At the moment, python.el is only loaded for sessions (in org-babel-python-initiate-session-by-key), assuming org-babel-python-mode is set to `python'. With the above change, you're now using python.el functions in a non-session code path, so you'll need a (require 'python) somewhere. Also, just a note: I wondered whether python-syntax-context and python-indent-shift-right are available in Emacs 24.3, the minimum Emacs version we support. They are.