[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bug: ob-python mangles multiline :var values [9.3.6 (release_9.3.6-3
From: |
Kyle Meyer |
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 |
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.