mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-11-28 07:45:00 +00:00
Disable completion/ElDoc/FFAP when Python program is running
* lisp/progmodes/python.el (python-completion-at-point) (python-ffap-module-path, python-eldoc--get-doc-at-point): Add check using `python-util-comint-end-of-output-p'. (python-util-comint-end-of-output-p): New function. * test/lisp/progmodes/python-tests.el (python-tests-shell-wait-for-prompt): Use `python-util-comint-end-of-output-p'. (python-completion-at-point-while-running-1) (python-ffap-module-path-1) (python-ffap-module-path-while-running-1) (python-eldoc--get-doc-at-point-1) (python-eldoc--get-doc-at-point-while-running-1): New tests. (Bug#58713)
This commit is contained in:
parent
d820c39bd1
commit
7ac3d91eb2
@ -4375,7 +4375,9 @@ For this to work as best as possible you should call
|
||||
`python-shell-send-buffer' from time to time so context in
|
||||
inferior Python process is updated properly."
|
||||
(let ((process (python-shell-get-process)))
|
||||
(when process
|
||||
(when (and process
|
||||
(python-shell-with-shell-buffer
|
||||
(python-util-comint-end-of-output-p)))
|
||||
(python-shell-completion-at-point process))))
|
||||
|
||||
(define-obsolete-function-alias
|
||||
@ -4800,6 +4802,8 @@ def __FFAP_get_module_path(objstr):
|
||||
(defun python-ffap-module-path (module)
|
||||
"Function for `ffap-alist' to return path for MODULE."
|
||||
(when-let ((process (python-shell-get-process))
|
||||
(ready (python-shell-with-shell-buffer
|
||||
(python-util-comint-end-of-output-p)))
|
||||
(module-file
|
||||
(python-shell-send-string-no-output
|
||||
(format "%s\nprint(__FFAP_get_module_path(%s))"
|
||||
@ -4918,7 +4922,9 @@ If not FORCE-INPUT is passed then what `python-eldoc--get-symbol-at-point'
|
||||
returns will be used. If not FORCE-PROCESS is passed what
|
||||
`python-shell-get-process' returns is used."
|
||||
(let ((process (or force-process (python-shell-get-process))))
|
||||
(when process
|
||||
(when (and process
|
||||
(python-shell-with-shell-buffer
|
||||
(python-util-comint-end-of-output-p)))
|
||||
(let* ((input (or force-input
|
||||
(python-eldoc--get-symbol-at-point)))
|
||||
(docstring
|
||||
@ -5664,6 +5670,13 @@ This is for compatibility with Emacs < 24.4."
|
||||
comint-last-prompt)
|
||||
(t nil)))
|
||||
|
||||
(defun python-util-comint-end-of-output-p ()
|
||||
"Return non-nil if the last prompt matches input prompt."
|
||||
(when-let ((prompt (python-util-comint-last-prompt)))
|
||||
(python-shell-comint-end-of-output-p
|
||||
(buffer-substring-no-properties
|
||||
(car prompt) (cdr prompt)))))
|
||||
|
||||
(defun python-util-forward-comment (&optional direction)
|
||||
"Python mode specific version of `forward-comment'.
|
||||
Optional argument DIRECTION defines the direction to move to."
|
||||
|
@ -46,10 +46,7 @@ always located at the beginning of buffer."
|
||||
(defun python-tests-shell-wait-for-prompt ()
|
||||
"Wait for the prompt in the shell buffer."
|
||||
(python-shell-with-shell-buffer
|
||||
(while (not (if-let ((prompt (python-util-comint-last-prompt)))
|
||||
(python-shell-comint-end-of-output-p
|
||||
(buffer-substring-no-properties
|
||||
(car prompt) (cdr prompt)))))
|
||||
(while (not (python-util-comint-end-of-output-p))
|
||||
(sit-for 0.1))))
|
||||
|
||||
(defmacro python-tests-with-temp-buffer-with-shell (contents &rest body)
|
||||
@ -4478,6 +4475,21 @@ print('Hello')
|
||||
(insert "u")
|
||||
(should-not (nth 2 (python-completion-at-point))))))
|
||||
|
||||
(ert-deftest python-completion-at-point-while-running-1 ()
|
||||
"Should not try to complete when a program is running in the Shell buffer."
|
||||
(skip-unless (executable-find python-tests-shell-interpreter))
|
||||
(python-tests-with-temp-buffer-with-shell
|
||||
"
|
||||
import time
|
||||
|
||||
time.sleep(3)
|
||||
"
|
||||
(let ((inhibit-message t))
|
||||
(python-shell-send-buffer)
|
||||
(goto-char (point-max))
|
||||
(insert "time.")
|
||||
(should-not (with-timeout (1 t) (completion-at-point))))))
|
||||
|
||||
(ert-deftest python-completion-at-point-native-1 ()
|
||||
(skip-unless (executable-find python-tests-shell-interpreter))
|
||||
(python-tests-with-temp-buffer-with-shell
|
||||
@ -4552,6 +4564,31 @@ import abc
|
||||
|
||||
;;; FFAP
|
||||
|
||||
(ert-deftest python-ffap-module-path-1 ()
|
||||
(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)
|
||||
(should (file-exists-p (python-ffap-module-path "abc"))))))
|
||||
|
||||
(ert-deftest python-ffap-module-path-while-running-1 ()
|
||||
"Should not get module path when a program is running in the Shell buffer."
|
||||
(skip-unless (executable-find python-tests-shell-interpreter))
|
||||
(python-tests-with-temp-buffer-with-shell
|
||||
"
|
||||
import abc
|
||||
import time
|
||||
|
||||
time.sleep(3)
|
||||
"
|
||||
(let ((inhibit-message t))
|
||||
(python-shell-send-buffer)
|
||||
(should-not (with-timeout (1 t) (python-ffap-module-path "abc"))))))
|
||||
|
||||
|
||||
;;; Code check
|
||||
|
||||
@ -4615,6 +4652,32 @@ some_symbol some_other_symbol
|
||||
(should (string= (python-eldoc--get-symbol-at-point)
|
||||
"some_symbol"))))
|
||||
|
||||
(ert-deftest python-eldoc--get-doc-at-point-1 ()
|
||||
(skip-unless (executable-find python-tests-shell-interpreter))
|
||||
(python-tests-with-temp-buffer-with-shell
|
||||
"
|
||||
import time
|
||||
"
|
||||
(let ((inhibit-message t))
|
||||
(python-shell-send-buffer)
|
||||
(python-tests-shell-wait-for-prompt)
|
||||
(python-tests-look-at "time")
|
||||
(should (python-eldoc--get-doc-at-point)))))
|
||||
|
||||
(ert-deftest python-eldoc--get-doc-at-point-while-running-1 ()
|
||||
"Should not get documentation when a program is running in the Shell buffer."
|
||||
(skip-unless (executable-find python-tests-shell-interpreter))
|
||||
(python-tests-with-temp-buffer-with-shell
|
||||
"
|
||||
import time
|
||||
|
||||
time.sleep(3)
|
||||
"
|
||||
(let ((inhibit-message t))
|
||||
(python-shell-send-buffer)
|
||||
(python-tests-look-at "time")
|
||||
(should-not (with-timeout (1 t) (python-eldoc--get-doc-at-point))))))
|
||||
|
||||
|
||||
;;; Imenu
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user