]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/progmodes/python.el (python-shell-buffer-substring): Handle
authorFabián Ezequiel Gallina <fgallina@gnu.org>
Sat, 27 Dec 2014 20:22:29 +0000 (17:22 -0300)
committerFabián Ezequiel Gallina <fgallina@gnu.org>
Sat, 27 Dec 2014 20:22:29 +0000 (17:22 -0300)
cornercase when region sent starts at point-min.

lisp/ChangeLog
lisp/progmodes/python.el
test/ChangeLog
test/automated/python-tests.el

index cf866fa9d525b737bc0b4b2d0ce28b4e4925efac..4b8f8f61c438c04e30b9395d1c6f08723017ca4a 100644 (file)
@@ -1,3 +1,8 @@
+2014-12-27  Fabián Ezequiel Gallina  <fgallina@gnu.org>
+
+       * progmodes/python.el (python-shell-buffer-substring): Handle
+       cornercase when region sent starts at point-min.
+
 2014-12-27  Eli Zaretskii  <eliz@gnu.org>
 
        * language/misc-lang.el (composition-function-table): Add Syriac
index 4a4e320cd657276f29ce2df3c3c95d4fff97fd55..0d80110f7b711313520fefafcf906c509c4ffdd0 100644 (file)
@@ -2523,17 +2523,16 @@ the python shell:
   4. Wraps indented regions under an \"if True:\" block so the
      interpreter evaluates them correctly."
   (let* ((substring (buffer-substring-no-properties start end))
-         (buffer-substring-p (save-restriction
-                               (widen)
-                               (not (equal (list (point-min) (point-max))
-                                           (list start end)))))
+         (starts-at-point-min-p (save-restriction
+                                  (widen)
+                                  (= (point-min) start)))
          (encoding (python-info-encoding))
-         (fillstr (concat
-                   (when buffer-substring-p
-                     (format "# -*- coding: %s -*-\n" encoding))
-                   (make-string
-                    (- (line-number-at-pos start)
-                       (if buffer-substring-p 2 1)) ?\n)))
+         (fillstr (when (not starts-at-point-min-p)
+                    (concat
+                     (format "# -*- coding: %s -*-\n" encoding)
+                     (make-string
+                      ;; Substract 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))
index 101e9d9caa72707f15cfbcdbd42a413fda93c2f6..74d46775431db974d425c489bab02030ea32ecee 100644 (file)
@@ -1,3 +1,7 @@
+2014-12-27  Fabián Ezequiel Gallina  <fgallina@gnu.org>
+
+       (python-shell-buffer-substring-9): New test.
+
 2014-12-27  Fabián Ezequiel Gallina  <fgallina@gnu.org>
 
        * automated/python-tests.el (python-shell-buffer-substring-1)
index 8fcda58e1e04e08b67705cc038e4dfc50ebc192c..a49485712427939fbf718d4ce0cb7169562320bf 100644 (file)
@@ -2651,6 +2651,27 @@ class Foo(models.Model):
     pass
 "))))
 
+(ert-deftest python-shell-buffer-substring-9 ()
+  "Check substring starting from `point-min'."
+  (python-tests-with-temp-buffer
+   "# coding: utf-8
+
+class Foo(models.Model):
+    pass
+
+class Bar(models.Model):
+    pass
+"
+   (should (string= (python-shell-buffer-substring
+                     (point-min)
+                     (python-tests-look-at "class Bar(models.Model):"))
+                    "# coding: utf-8
+
+class Foo(models.Model):
+    pass
+
+"))))
+
 \f
 ;;; Shell completion