From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Yuri D'Elia Newsgroups: gmane.emacs.bugs Subject: bug#21086: 24.5; python.el: python-shell-buffer-substring fails under certain circumstances Date: Sat, 18 Jul 2015 18:13:33 +0200 Message-ID: <55AA7B2D.9060208@thregr.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------010104030308080106090107" X-Trace: ger.gmane.org 1437236069 30637 80.91.229.3 (18 Jul 2015 16:14:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 18 Jul 2015 16:14:29 +0000 (UTC) To: 21086@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Jul 18 18:14:16 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZGUkd-0003OV-Ap for geb-bug-gnu-emacs@m.gmane.org; Sat, 18 Jul 2015 18:14:11 +0200 Original-Received: from localhost ([::1]:48806 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZGUkc-0007Js-D8 for geb-bug-gnu-emacs@m.gmane.org; Sat, 18 Jul 2015 12:14:10 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33466) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZGUkY-0007Il-So for bug-gnu-emacs@gnu.org; Sat, 18 Jul 2015 12:14:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZGUkU-00089K-ON for bug-gnu-emacs@gnu.org; Sat, 18 Jul 2015 12:14:06 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:51767) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZGUkU-00089B-Kw for bug-gnu-emacs@gnu.org; Sat, 18 Jul 2015 12:14:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1ZGUkU-0007OK-Ao for bug-gnu-emacs@gnu.org; Sat, 18 Jul 2015 12:14:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Yuri D'Elia Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 18 Jul 2015 16:14:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 21086 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.143723603728391 (code B ref -1); Sat, 18 Jul 2015 16:14:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 18 Jul 2015 16:13:57 +0000 Original-Received: from localhost ([127.0.0.1]:53213 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZGUkO-0007Nq-DV for submit@debbugs.gnu.org; Sat, 18 Jul 2015 12:13:56 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:48142) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZGUkM-0007Ne-7K for submit@debbugs.gnu.org; Sat, 18 Jul 2015 12:13:54 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZGUkF-00086u-Sc for submit@debbugs.gnu.org; Sat, 18 Jul 2015 12:13:48 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:49280) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZGUkF-00086p-Ph for submit@debbugs.gnu.org; Sat, 18 Jul 2015 12:13:47 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33416) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZGUkE-0007IS-Kn for bug-gnu-emacs@gnu.org; Sat, 18 Jul 2015 12:13:47 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZGUkA-00086G-JY for bug-gnu-emacs@gnu.org; Sat, 18 Jul 2015 12:13:46 -0400 Original-Received: from e.thregr.org ([80.68.88.20]:35180) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZGUkA-00086C-DO for bug-gnu-emacs@gnu.org; Sat, 18 Jul 2015 12:13:42 -0400 Original-Received: from [151.46.221.109] (helo=[192.168.43.14]) by e.thregr.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_RC4) (envelope-from ) id 1ZGUk8-0006Pt-Ml for bug-gnu-emacs@gnu.org; Sat, 18 Jul 2015 18:13:40 +0200 X-Enigmail-Draft-Status: N1110 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:105024 Archived-At: This is a multi-part message in MIME format. --------------010104030308080106090107 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Assuming some python buffer like: #.... if 1: print 1 where the selected region is "print \"1\"" (mark before "p"), `python-shell-send-region' would fail with: File "test.py", line 3 print 1 ^ IndentationError: expected an indented block The reason lies within `python-shell-buffer-substring', which assumes that a region always starts with the correct indentation. The attached patch fixes the above behavior: when the region doesn't start with indentation, but the current block does (looking at (current-indentation)), we prefix the fillstr with the correct amount of indent. --------------010104030308080106090107 Content-Type: text/x-diff; name="python-buffer-substring.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="python-buffer-substring.patch" --- python.el.Orig 2015-07-18 18:00:49.367517569 +0200 +++ python.el 2015-07-18 18:03:01.203659502 +0200 @@ -2548,18 +2548,22 @@ (make-string ;; Subtract 2 because of the coding cookie. (- (line-number-at-pos start) 2) ?\n)))) - (toplevel-block-p (save-excursion - (goto-char start) - (or (zerop (line-number-at-pos start)) - (progn - (python-util-forward-comment 1) - (zerop (current-indentation))))))) + (block-param (save-excursion + (goto-char start) + (progn + (python-util-forward-comment 1) + (list (current-indentation) + (/= (point) start))))) + (block-indentation (car block-param)) + (starts-with-indentation-p (cadr block-param))) (with-temp-buffer (python-mode) (if fillstr (insert fillstr)) + (when (and (> block-indentation 0) (not starts-with-indentation-p)) + (insert (make-string block-indentation ?\s))) (insert substring) (goto-char (point-min)) - (when (not toplevel-block-p) + (when (> block-indentation 0) (insert "if True:") (delete-region (point) (line-end-position))) (when nomain --------------010104030308080106090107--