emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master aa559c1553: Fix Python completion when point in shell buffer is b


From: Lars Ingebrigtsen
Subject: master aa559c1553: Fix Python completion when point in shell buffer is before prompt
Date: Wed, 12 Oct 2022 07:15:07 -0400 (EDT)

branch: master
commit aa559c15537a59147bb01617b4a1f9eee20af3a1
Author: kobarity <kobarity@gmail.com>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Fix Python completion when point in shell buffer is before prompt
    
    * lisp/progmodes/python.el (python-shell-completion-at-point): Limit
    prompt boundaries check to shell buffer.
    * test/lisp/progmodes/python-tests.el (python-shell-completion-2):
    (python-shell-completion-native-2): New tests (bug#58441).
---
 lisp/progmodes/python.el            |  6 ++++--
 test/lisp/progmodes/python-tests.el | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 680b57fc3e..0de76b0bde 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -4069,7 +4069,8 @@ With argument MSG show activation/deactivation message."
 Optional argument PROCESS forces completions to be retrieved
 using that one instead of current buffer's process."
   (setq process (or process (get-buffer-process (current-buffer))))
-  (let* ((line-start (if (derived-mode-p 'inferior-python-mode)
+  (let* ((is-shell-buffer (derived-mode-p 'inferior-python-mode))
+         (line-start (if is-shell-buffer
                          ;; Working on a shell buffer: use prompt end.
                          (cdr (python-util-comint-last-prompt))
                        (line-beginning-position)))
@@ -4100,7 +4101,8 @@ using that one instead of current buffer's process."
          (completion-fn
           (with-current-buffer (process-buffer process)
             (cond ((or (null prompt)
-                       (< (point) (cdr prompt-boundaries)))
+                       (and is-shell-buffer
+                            (< (point) (cdr prompt-boundaries))))
                    #'ignore)
                   ((or (not python-shell-completion-native-enable)
                        ;; Even if native completion is enabled, for
diff --git a/test/lisp/progmodes/python-tests.el 
b/test/lisp/progmodes/python-tests.el
index 60ff9bb613..9ad2d16930 100644
--- a/test/lisp/progmodes/python-tests.el
+++ b/test/lisp/progmodes/python-tests.el
@@ -4411,6 +4411,22 @@ import abc
      (insert "A")
      (should (completion-at-point)))))
 
+(ert-deftest python-shell-completion-2 ()
+  "Should work regardless of the point in the Shell buffer."
+  (skip-unless (executable-find python-tests-shell-interpreter))
+  (python-tests-with-temp-buffer-with-shell
+   "
+import abc
+"
+   (let ((inhibit-message t))
+     (python-shell-send-buffer)
+     (python-tests-shell-wait-for-prompt)
+     (python-shell-with-shell-buffer
+       (goto-char (point-min)))
+     (goto-char (point-max))
+     (insert "abc.")
+     (should (completion-at-point)))))
+
 (ert-deftest python-shell-completion-native-1 ()
   (skip-unless (executable-find python-tests-shell-interpreter))
   (python-tests-with-temp-buffer-with-shell
@@ -4427,6 +4443,23 @@ import abc
      (insert "A")
      (should (completion-at-point)))))
 
+(ert-deftest python-shell-completion-native-2 ()
+  "Should work regardless of the point in the Shell buffer."
+  (skip-unless (executable-find python-tests-shell-interpreter))
+  (python-tests-with-temp-buffer-with-shell
+   "
+import abc
+"
+   (let ((inhibit-message t))
+     (python-shell-completion-native-turn-on)
+     (python-shell-send-buffer)
+     (python-tests-shell-wait-for-prompt)
+     (python-shell-with-shell-buffer
+       (goto-char (point-min)))
+     (goto-char (point-max))
+     (insert "abc.")
+     (should (completion-at-point)))))
+
 (ert-deftest python-shell-completion-native-with-ffap-1 ()
   (skip-unless (executable-find python-tests-shell-interpreter))
   (python-tests-with-temp-buffer-with-shell



reply via email to

[Prev in Thread] Current Thread [Next in Thread]