aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorNoam Postavsky2017-08-19 11:45:07 -0400
committerNoam Postavsky2017-08-27 13:46:41 -0400
commit5440b238b1ec4175dd32bc14b4098f6570b2ca85 (patch)
treefe45d9ac0d9dd8a508810eea07ad1bc59d141ed0 /lisp/progmodes/python.el
parent79cc9445e182ad5d80380ccf677b947d76854ce8 (diff)
downloademacs-5440b238b1ec4175dd32bc14b4098f6570b2ca85.tar.gz
emacs-5440b238b1ec4175dd32bc14b4098f6570b2ca85.zip
Disable completion while entering python multiline statements
The "legacy" completion mechanism sends newlines to the running python process to get the list of completions, which confuses things if the user is in the middle of entering a multiline statement (Bug#28051). It's better to disable completion in this case. * lisp/progmodes/python.el (python-shell--block-prompt): New variable. (python-shell-prompt-set-calculated-regexps): Set it. (python-shell-completion-at-point): Return 'ignore' as the completion function when the current prompt is a block prompt.
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el16
1 files changed, 15 insertions, 1 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index e73b2a8488c..444167f536e 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -2212,6 +2212,11 @@ machine then modifies `tramp-remote-process-environment' and
2212Do not set this variable directly, instead use 2212Do not set this variable directly, instead use
2213`python-shell-prompt-set-calculated-regexps'.") 2213`python-shell-prompt-set-calculated-regexps'.")
2214 2214
2215(defvar python-shell--block-prompt nil
2216 "Input block prompt for inferior python shell.
2217Do not set this variable directly, instead use
2218`python-shell-prompt-set-calculated-regexps'.")
2219
2215(defvar python-shell--prompt-calculated-output-regexp nil 2220(defvar python-shell--prompt-calculated-output-regexp nil
2216 "Calculated output prompt regexp for inferior python shell. 2221 "Calculated output prompt regexp for inferior python shell.
2217Do not set this variable directly, instead use 2222Do not set this variable directly, instead use
@@ -2366,6 +2371,7 @@ and `python-shell-output-prompt-regexp' using the values from
2366 (dolist (prompt (butlast detected-prompts)) 2371 (dolist (prompt (butlast detected-prompts))
2367 (setq prompt (regexp-quote prompt)) 2372 (setq prompt (regexp-quote prompt))
2368 (cl-pushnew prompt input-prompts :test #'string=)) 2373 (cl-pushnew prompt input-prompts :test #'string=))
2374 (setq python-shell--block-prompt (nth 1 detected-prompts))
2369 (cl-pushnew (regexp-quote 2375 (cl-pushnew (regexp-quote
2370 (car (last detected-prompts))) 2376 (car (last detected-prompts)))
2371 output-prompts :test #'string=)) 2377 output-prompts :test #'string=))
@@ -2726,6 +2732,7 @@ variable.
2726 (set (make-local-variable 'python-shell-interpreter-args) 2732 (set (make-local-variable 'python-shell-interpreter-args)
2727 (or python-shell--interpreter-args python-shell-interpreter-args)) 2733 (or python-shell--interpreter-args python-shell-interpreter-args))
2728 (set (make-local-variable 'python-shell--prompt-calculated-input-regexp) nil) 2734 (set (make-local-variable 'python-shell--prompt-calculated-input-regexp) nil)
2735 (set (make-local-variable 'python-shell--block-prompt) nil)
2729 (set (make-local-variable 'python-shell--prompt-calculated-output-regexp) nil) 2736 (set (make-local-variable 'python-shell--prompt-calculated-output-regexp) nil)
2730 (python-shell-prompt-set-calculated-regexps) 2737 (python-shell-prompt-set-calculated-regexps)
2731 (setq comint-prompt-regexp python-shell--prompt-calculated-input-regexp) 2738 (setq comint-prompt-regexp python-shell--prompt-calculated-input-regexp)
@@ -3632,7 +3639,14 @@ using that one instead of current buffer's process."
3632 ;; Also, since pdb interaction is single-line 3639 ;; Also, since pdb interaction is single-line
3633 ;; based, this is enough. 3640 ;; based, this is enough.
3634 (string-match-p python-shell-prompt-pdb-regexp prompt)) 3641 (string-match-p python-shell-prompt-pdb-regexp prompt))
3635 #'python-shell-completion-get-completions) 3642 (if (or (equal python-shell--block-prompt prompt)
3643 (string-match-p
3644 python-shell-prompt-block-regexp prompt))
3645 ;; The non-native completion mechanism sends
3646 ;; newlines to the interpreter, so we can't use
3647 ;; it during a multiline statement (Bug#28051).
3648 #'ignore
3649 #'python-shell-completion-get-completions))
3636 (t #'python-shell-completion-native-get-completions))))) 3650 (t #'python-shell-completion-native-get-completions)))))
3637 (list start end 3651 (list start end
3638 (completion-table-dynamic 3652 (completion-table-dynamic