From cb975c6183ed1653cc8d7fe5283a9b294bf07bf4 Mon Sep 17 00:00:00 2001 From: kobarity Date: Sun, 16 Oct 2022 11:26:29 +0200 Subject: [PATCH] Fix invalid search bound error in python-shell-completion-at-point * 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 | 21 ++++++++++++--------- test/lisp/progmodes/python-tests.el | 27 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 50f1e6752e4..11195894234 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -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) diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index 97dc17ce293..71bd0e0d682 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el @@ -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)))))) + ;;; PDB Track integration -- 2.39.5