emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Kyle Meyer <kyle@kyleam.com>
To: Jack Kamm <jackkamm@gmail.com>
Cc: emacs-orgmode@gnu.org, "Matthew Lundin" <mdl@imapmail.org>,
	"Štěpán Němec" <stepnem@gmail.com>
Subject: Re: Bug: ob-python mangles multiline :var values [9.3.6 (release_9.3.6-397-ga089600)]
Date: Mon, 08 Jun 2020 04:29:27 +0000	[thread overview]
Message-ID: <87a71ew57c.fsf@kyleam.com> (raw)
In-Reply-To: <87r1usxdba.fsf@gmail.com>

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.


  reply	other threads:[~2020-06-08  4:30 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-13 13:16 Bug: ob-python mangles multiline :var values [9.3.6 (release_9.3.6-397-ga089600)] Štěpán Němec
2020-05-24 14:51 ` Jack Kamm
2020-05-27 18:26   ` Matthew Lundin
2020-05-27 21:46     ` Jack Kamm
2020-05-28 14:39       ` Jack Kamm
2020-06-06 18:24         ` Jack Kamm
2020-06-08  4:29           ` Kyle Meyer [this message]
2020-06-10  4:05             ` Jack Kamm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a71ew57c.fsf@kyleam.com \
    --to=kyle@kyleam.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=jackkamm@gmail.com \
    --cc=mdl@imapmail.org \
    --cc=stepnem@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).