From: Stefan Monnier <monnier@iro.umontreal.ca>
To: help-gnu-emacs@gnu.org
Cc: "Fabián Ezequiel Gallina" <fgallina@gnu.org>
Subject: Re: python-shell-send-region uses wrong encoding?
Date: Tue, 29 Oct 2013 13:28:38 -0400 [thread overview]
Message-ID: <jwv1u342dtd.fsf-monnier+gmane.emacs.help@gnu.org> (raw)
In-Reply-To: 20131029113044.GA28039@doriath.local
> This is the same output that I get when I run the script in a terminal.
> However, if I select the lines after 'from __future__ ...' until the end and
> do python-shell-send-region (C-c C-r) I get this output instead:
> u'W\xf6rterbuch'
> u'W\xc3\xb6rterbuch'
> The second line of output seems to indicate that the text was sent in a
> different encoding compared to python-shell-send-buffer.
No, it indicates that Python interpreted the bytes sent by Emacs in
a different way: the first line (where you explicitly asked for a utf-8
decoding) indicates that the bytes indeed use the right utf-8 encoding,
but the second indicates that Python does not decode the input as utf-8
but as something else (presumably latin-1).
E.g. the patch below (which causes python-shell-send-string to tell
Python that the file sent is using utf-8) should fix your problem (tho
it's not a proper fix, since we shouldn't hardcode utf-8 here, but copy
which ever -*- coding: -*- coding is in the file).
Fabián, could you write a cleaner fix?
Stefan
=== modified file 'lisp/progmodes/python.el'
--- lisp/progmodes/python.el 2013-10-07 18:51:26 +0000
+++ lisp/progmodes/python.el 2013-10-29 17:25:11 +0000
@@ -2047,6 +2047,7 @@
(temp-file-name (make-temp-file "py"))
(file-name (or (buffer-file-name) temp-file-name)))
(with-temp-file temp-file-name
+ (insert "# -*- coding: utf-8 -*-")
(insert string)
(delete-trailing-whitespace))
(python-shell-send-file file-name process temp-file-name))
next prev parent reply other threads:[~2013-10-29 17:28 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-29 11:30 python-shell-send-region uses wrong encoding? Ernest Adrogué
2013-10-29 14:24 ` Drew Adams
2013-10-29 14:37 ` Ernest Adrogué
2013-10-29 16:00 ` Drew Adams
2013-10-29 16:54 ` Ernest Adrogué
2013-10-29 17:11 ` Eli Zaretskii
2013-10-29 14:26 ` Andreas Röhler
2013-10-29 14:55 ` Ernest Adrogué
2013-10-29 15:29 ` Andreas Röhler
2013-10-29 15:34 ` Peter Dyballa
2013-10-29 16:34 ` Ernest Adrogué
2013-10-29 17:15 ` Eli Zaretskii
2013-10-29 17:53 ` Ernest Adrogué
2013-10-29 19:10 ` Eli Zaretskii
2013-10-29 20:48 ` Ernest Adrogué
2013-10-29 18:07 ` Peter Dyballa
2013-10-29 20:37 ` Ernest Adrogué
2013-10-29 17:28 ` Stefan Monnier [this message]
2013-10-30 3:20 ` Stefan Monnier
2013-10-30 6:45 ` Andreas Röhler
2013-10-30 11:37 ` Stefan Monnier
2013-10-30 12:08 ` Yuri Khan
2013-10-30 12:45 ` Andreas Röhler
2013-10-31 14:30 ` Ernest Adrogué
2013-10-31 14:31 ` Ernest Adrogué
2013-10-31 17:54 ` Ernest Adrogué
2013-10-31 20:35 ` Stefan Monnier
2013-11-04 19:15 ` Stefan Monnier
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.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwv1u342dtd.fsf-monnier+gmane.emacs.help@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=fgallina@gnu.org \
--cc=help-gnu-emacs@gnu.org \
/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.
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).