]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix invalid search bound error in python-shell-completion-at-point
authorkobarity <kobarity@gmail.com>
Sun, 16 Oct 2022 09:26:29 +0000 (11:26 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Sun, 16 Oct 2022 09:26:29 +0000 (11:26 +0200)
* lisp/progmodes/python.el (python-shell-completion-at-point): Add
check if point is before line-start.
* test/lisp/progmodes/python-tests.el (python-shell-completion-shell-buffer-1)
(python-shell-completion-shell-buffer-native-1): New tests
(bug#58548).

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

index 50f1e6752e4503024b93392d462f8fe7012cb810..11195894234bdaa55abb600b1b25411de9b6ea08 100644 (file)
@@ -4080,15 +4080,18 @@ using that one instead of current buffer's process."
                  (buffer-substring-no-properties line-start (point)))
             (buffer-substring-no-properties line-start (point))))
          (start
-          (save-excursion
-            (if (not (re-search-backward
-                      (python-rx
-                       (or whitespace open-paren close-paren string-delimiter simple-operator))
-                      line-start
-                      t 1))
-                line-start
-              (forward-char (length (match-string-no-properties 0)))
-              (point))))
+          (if (< (point) line-start)
+              (point)
+            (save-excursion
+              (if (not (re-search-backward
+                        (python-rx
+                         (or whitespace open-paren close-paren
+                             string-delimiter simple-operator))
+                        line-start
+                        t 1))
+                  line-start
+                (forward-char (length (match-string-no-properties 0)))
+                (point)))))
          (end (point))
          (prompt-boundaries
           (with-current-buffer (process-buffer process)
index 97dc17ce2931f42f9a5c2342e487799820d42180..71bd0e0d682f7df7a4217091f120342c7bb89ac1 100644 (file)
@@ -4509,6 +4509,33 @@ import abc
      (python-eldoc-function)
      (should (completion-at-point)))))
 
+(ert-deftest python-shell-completion-shell-buffer-1 ()
+  (skip-unless (executable-find python-tests-shell-interpreter))
+  (python-tests-with-temp-buffer-with-shell
+   ""
+   (python-shell-with-shell-buffer
+     (insert "import abc")
+     (comint-send-input)
+     (python-tests-shell-wait-for-prompt)
+     (insert "abc.")
+     (should (nth 2 (python-shell-completion-at-point)))
+     (end-of-line 0)
+     (should-not (nth 2 (python-shell-completion-at-point))))))
+
+(ert-deftest python-shell-completion-shell-buffer-native-1 ()
+  (skip-unless (executable-find python-tests-shell-interpreter))
+  (python-tests-with-temp-buffer-with-shell
+   ""
+   (python-shell-completion-native-turn-on)
+   (python-shell-with-shell-buffer
+     (insert "import abc")
+     (comint-send-input)
+     (python-tests-shell-wait-for-prompt)
+     (insert "abc.")
+     (should (nth 2 (python-shell-completion-at-point)))
+     (end-of-line 0)
+     (should-not (nth 2 (python-shell-completion-at-point))))))
+
 
 \f
 ;;; PDB Track integration