diff options
| author | kobarity | 2022-10-22 21:36:15 +0900 |
|---|---|---|
| committer | Eli Zaretskii | 2022-10-27 19:04:14 +0300 |
| commit | 7ac3d91eb2a7e9454087f17e1fadba350a86a208 (patch) | |
| tree | 96df09ecf27e5da25fa943058afa46357cb60033 | |
| parent | d820c39bd18e493ba716ad3ceb8101c1dee3a02b (diff) | |
| download | emacs-7ac3d91eb2a7e9454087f17e1fadba350a86a208.tar.gz emacs-7ac3d91eb2a7e9454087f17e1fadba350a86a208.zip | |
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)
| -rw-r--r-- | lisp/progmodes/python.el | 17 | ||||
| -rw-r--r-- | test/lisp/progmodes/python-tests.el | 71 |
2 files changed, 82 insertions, 6 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 11195894234..cec0d54a447 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -4375,7 +4375,9 @@ For this to work as best as possible you should call | |||
| 4375 | `python-shell-send-buffer' from time to time so context in | 4375 | `python-shell-send-buffer' from time to time so context in |
| 4376 | inferior Python process is updated properly." | 4376 | inferior Python process is updated properly." |
| 4377 | (let ((process (python-shell-get-process))) | 4377 | (let ((process (python-shell-get-process))) |
| 4378 | (when process | 4378 | (when (and process |
| 4379 | (python-shell-with-shell-buffer | ||
| 4380 | (python-util-comint-end-of-output-p))) | ||
| 4379 | (python-shell-completion-at-point process)))) | 4381 | (python-shell-completion-at-point process)))) |
| 4380 | 4382 | ||
| 4381 | (define-obsolete-function-alias | 4383 | (define-obsolete-function-alias |
| @@ -4800,6 +4802,8 @@ def __FFAP_get_module_path(objstr): | |||
| 4800 | (defun python-ffap-module-path (module) | 4802 | (defun python-ffap-module-path (module) |
| 4801 | "Function for `ffap-alist' to return path for MODULE." | 4803 | "Function for `ffap-alist' to return path for MODULE." |
| 4802 | (when-let ((process (python-shell-get-process)) | 4804 | (when-let ((process (python-shell-get-process)) |
| 4805 | (ready (python-shell-with-shell-buffer | ||
| 4806 | (python-util-comint-end-of-output-p))) | ||
| 4803 | (module-file | 4807 | (module-file |
| 4804 | (python-shell-send-string-no-output | 4808 | (python-shell-send-string-no-output |
| 4805 | (format "%s\nprint(__FFAP_get_module_path(%s))" | 4809 | (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' | |||
| 4918 | returns will be used. If not FORCE-PROCESS is passed what | 4922 | returns will be used. If not FORCE-PROCESS is passed what |
| 4919 | `python-shell-get-process' returns is used." | 4923 | `python-shell-get-process' returns is used." |
| 4920 | (let ((process (or force-process (python-shell-get-process)))) | 4924 | (let ((process (or force-process (python-shell-get-process)))) |
| 4921 | (when process | 4925 | (when (and process |
| 4926 | (python-shell-with-shell-buffer | ||
| 4927 | (python-util-comint-end-of-output-p))) | ||
| 4922 | (let* ((input (or force-input | 4928 | (let* ((input (or force-input |
| 4923 | (python-eldoc--get-symbol-at-point))) | 4929 | (python-eldoc--get-symbol-at-point))) |
| 4924 | (docstring | 4930 | (docstring |
| @@ -5664,6 +5670,13 @@ This is for compatibility with Emacs < 24.4." | |||
| 5664 | comint-last-prompt) | 5670 | comint-last-prompt) |
| 5665 | (t nil))) | 5671 | (t nil))) |
| 5666 | 5672 | ||
| 5673 | (defun python-util-comint-end-of-output-p () | ||
| 5674 | "Return non-nil if the last prompt matches input prompt." | ||
| 5675 | (when-let ((prompt (python-util-comint-last-prompt))) | ||
| 5676 | (python-shell-comint-end-of-output-p | ||
| 5677 | (buffer-substring-no-properties | ||
| 5678 | (car prompt) (cdr prompt))))) | ||
| 5679 | |||
| 5667 | (defun python-util-forward-comment (&optional direction) | 5680 | (defun python-util-forward-comment (&optional direction) |
| 5668 | "Python mode specific version of `forward-comment'. | 5681 | "Python mode specific version of `forward-comment'. |
| 5669 | Optional argument DIRECTION defines the direction to move to." | 5682 | Optional argument DIRECTION defines the direction to move to." |
diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index 81c9217c62c..8330525394c 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el | |||
| @@ -46,10 +46,7 @@ always located at the beginning of buffer." | |||
| 46 | (defun python-tests-shell-wait-for-prompt () | 46 | (defun python-tests-shell-wait-for-prompt () |
| 47 | "Wait for the prompt in the shell buffer." | 47 | "Wait for the prompt in the shell buffer." |
| 48 | (python-shell-with-shell-buffer | 48 | (python-shell-with-shell-buffer |
| 49 | (while (not (if-let ((prompt (python-util-comint-last-prompt))) | 49 | (while (not (python-util-comint-end-of-output-p)) |
| 50 | (python-shell-comint-end-of-output-p | ||
| 51 | (buffer-substring-no-properties | ||
| 52 | (car prompt) (cdr prompt))))) | ||
| 53 | (sit-for 0.1)))) | 50 | (sit-for 0.1)))) |
| 54 | 51 | ||
| 55 | (defmacro python-tests-with-temp-buffer-with-shell (contents &rest body) | 52 | (defmacro python-tests-with-temp-buffer-with-shell (contents &rest body) |
| @@ -4478,6 +4475,21 @@ print('Hello') | |||
| 4478 | (insert "u") | 4475 | (insert "u") |
| 4479 | (should-not (nth 2 (python-completion-at-point)))))) | 4476 | (should-not (nth 2 (python-completion-at-point)))))) |
| 4480 | 4477 | ||
| 4478 | (ert-deftest python-completion-at-point-while-running-1 () | ||
| 4479 | "Should not try to complete when a program is running in the Shell buffer." | ||
| 4480 | (skip-unless (executable-find python-tests-shell-interpreter)) | ||
| 4481 | (python-tests-with-temp-buffer-with-shell | ||
| 4482 | " | ||
| 4483 | import time | ||
| 4484 | |||
| 4485 | time.sleep(3) | ||
| 4486 | " | ||
| 4487 | (let ((inhibit-message t)) | ||
| 4488 | (python-shell-send-buffer) | ||
| 4489 | (goto-char (point-max)) | ||
| 4490 | (insert "time.") | ||
| 4491 | (should-not (with-timeout (1 t) (completion-at-point)))))) | ||
| 4492 | |||
| 4481 | (ert-deftest python-completion-at-point-native-1 () | 4493 | (ert-deftest python-completion-at-point-native-1 () |
| 4482 | (skip-unless (executable-find python-tests-shell-interpreter)) | 4494 | (skip-unless (executable-find python-tests-shell-interpreter)) |
| 4483 | (python-tests-with-temp-buffer-with-shell | 4495 | (python-tests-with-temp-buffer-with-shell |
| @@ -4552,6 +4564,31 @@ import abc | |||
| 4552 | 4564 | ||
| 4553 | ;;; FFAP | 4565 | ;;; FFAP |
| 4554 | 4566 | ||
| 4567 | (ert-deftest python-ffap-module-path-1 () | ||
| 4568 | (skip-unless (executable-find python-tests-shell-interpreter)) | ||
| 4569 | (python-tests-with-temp-buffer-with-shell | ||
| 4570 | " | ||
| 4571 | import abc | ||
| 4572 | " | ||
| 4573 | (let ((inhibit-message t)) | ||
| 4574 | (python-shell-send-buffer) | ||
| 4575 | (python-tests-shell-wait-for-prompt) | ||
| 4576 | (should (file-exists-p (python-ffap-module-path "abc")))))) | ||
| 4577 | |||
| 4578 | (ert-deftest python-ffap-module-path-while-running-1 () | ||
| 4579 | "Should not get module path when a program is running in the Shell buffer." | ||
| 4580 | (skip-unless (executable-find python-tests-shell-interpreter)) | ||
| 4581 | (python-tests-with-temp-buffer-with-shell | ||
| 4582 | " | ||
| 4583 | import abc | ||
| 4584 | import time | ||
| 4585 | |||
| 4586 | time.sleep(3) | ||
| 4587 | " | ||
| 4588 | (let ((inhibit-message t)) | ||
| 4589 | (python-shell-send-buffer) | ||
| 4590 | (should-not (with-timeout (1 t) (python-ffap-module-path "abc")))))) | ||
| 4591 | |||
| 4555 | 4592 | ||
| 4556 | ;;; Code check | 4593 | ;;; Code check |
| 4557 | 4594 | ||
| @@ -4615,6 +4652,32 @@ some_symbol some_other_symbol | |||
| 4615 | (should (string= (python-eldoc--get-symbol-at-point) | 4652 | (should (string= (python-eldoc--get-symbol-at-point) |
| 4616 | "some_symbol")))) | 4653 | "some_symbol")))) |
| 4617 | 4654 | ||
| 4655 | (ert-deftest python-eldoc--get-doc-at-point-1 () | ||
| 4656 | (skip-unless (executable-find python-tests-shell-interpreter)) | ||
| 4657 | (python-tests-with-temp-buffer-with-shell | ||
| 4658 | " | ||
| 4659 | import time | ||
| 4660 | " | ||
| 4661 | (let ((inhibit-message t)) | ||
| 4662 | (python-shell-send-buffer) | ||
| 4663 | (python-tests-shell-wait-for-prompt) | ||
| 4664 | (python-tests-look-at "time") | ||
| 4665 | (should (python-eldoc--get-doc-at-point))))) | ||
| 4666 | |||
| 4667 | (ert-deftest python-eldoc--get-doc-at-point-while-running-1 () | ||
| 4668 | "Should not get documentation when a program is running in the Shell buffer." | ||
| 4669 | (skip-unless (executable-find python-tests-shell-interpreter)) | ||
| 4670 | (python-tests-with-temp-buffer-with-shell | ||
| 4671 | " | ||
| 4672 | import time | ||
| 4673 | |||
| 4674 | time.sleep(3) | ||
| 4675 | " | ||
| 4676 | (let ((inhibit-message t)) | ||
| 4677 | (python-shell-send-buffer) | ||
| 4678 | (python-tests-look-at "time") | ||
| 4679 | (should-not (with-timeout (1 t) (python-eldoc--get-doc-at-point)))))) | ||
| 4680 | |||
| 4618 | 4681 | ||
| 4619 | ;;; Imenu | 4682 | ;;; Imenu |
| 4620 | 4683 | ||