aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorAndrea Corallo2020-12-12 15:31:33 +0100
committerAndrea Corallo2020-12-12 15:31:33 +0100
commit0474fda62d79cb7eb250f34f19773c87f283c665 (patch)
treedf7418a6b22fbbfda725c56825ec0290f8e6be39 /lisp/progmodes/python.el
parentbe907b0ba82c2a65e0468d50653cae8a7cf5f16b (diff)
parent4afef614cd6c93b4d4a57aa5bb211563649abc56 (diff)
downloademacs-0474fda62d79cb7eb250f34f19773c87f283c665.tar.gz
emacs-0474fda62d79cb7eb250f34f19773c87f283c665.zip
Merge remote-tracking branch 'savannah/master' into HEAD
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el152
1 files changed, 72 insertions, 80 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index e9c3b3986aa..d75944a702f 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -4,8 +4,8 @@
4 4
5;; Author: Fabián E. Gallina <fgallina@gnu.org> 5;; Author: Fabián E. Gallina <fgallina@gnu.org>
6;; URL: https://github.com/fgallina/python.el 6;; URL: https://github.com/fgallina/python.el
7;; Version: 0.27 7;; Version: 0.27.1
8;; Package-Requires: ((emacs "24.1") (cl-lib "1.0")) 8;; Package-Requires: ((emacs "24.2") (cl-lib "1.0"))
9;; Maintainer: emacs-devel@gnu.org 9;; Maintainer: emacs-devel@gnu.org
10;; Created: Jul 2010 10;; Created: Jul 2010
11;; Keywords: languages 11;; Keywords: languages
@@ -875,7 +875,7 @@ work on `python-indent-calculate-indentation' instead."
875 (python-util-forward-comment) 875 (python-util-forward-comment)
876 (current-indentation)))) 876 (current-indentation))))
877 (if (and indentation (not (zerop indentation))) 877 (if (and indentation (not (zerop indentation)))
878 (set (make-local-variable 'python-indent-offset) indentation) 878 (setq-local python-indent-offset indentation)
879 (when python-indent-guess-indent-offset-verbose 879 (when python-indent-guess-indent-offset-verbose
880 (message "Can't guess python-indent-offset, using defaults: %s" 880 (message "Can't guess python-indent-offset, using defaults: %s"
881 python-indent-offset)))))))) 881 python-indent-offset))))))))
@@ -2623,7 +2623,7 @@ also `with-current-buffer'."
2623 (set-buffer python-shell--font-lock-buffer) 2623 (set-buffer python-shell--font-lock-buffer)
2624 (when (not font-lock-mode) 2624 (when (not font-lock-mode)
2625 (font-lock-mode 1)) 2625 (font-lock-mode 1))
2626 (set (make-local-variable 'delay-mode-hooks) t) 2626 (setq-local delay-mode-hooks t)
2627 (let ((python-indent-guess-indent-offset nil)) 2627 (let ((python-indent-guess-indent-offset nil))
2628 (when (not (derived-mode-p 'python-mode)) 2628 (when (not (derived-mode-p 'python-mode))
2629 (python-mode)) 2629 (python-mode))
@@ -2702,7 +2702,7 @@ With argument MSG show activation message."
2702 (interactive "p") 2702 (interactive "p")
2703 (python-shell-with-shell-buffer 2703 (python-shell-with-shell-buffer
2704 (python-shell-font-lock-kill-buffer) 2704 (python-shell-font-lock-kill-buffer)
2705 (set (make-local-variable 'python-shell--font-lock-buffer) nil) 2705 (setq-local python-shell--font-lock-buffer nil)
2706 (add-hook 'post-command-hook 2706 (add-hook 'post-command-hook
2707 #'python-shell-font-lock-post-command-hook nil 'local) 2707 #'python-shell-font-lock-post-command-hook nil 'local)
2708 (add-hook 'kill-buffer-hook 2708 (add-hook 'kill-buffer-hook
@@ -2725,7 +2725,7 @@ With argument MSG show deactivation message."
2725 (cdr (python-util-comint-last-prompt)) 2725 (cdr (python-util-comint-last-prompt))
2726 (line-end-position) 2726 (line-end-position)
2727 '(face nil font-lock-face nil))) 2727 '(face nil font-lock-face nil)))
2728 (set (make-local-variable 'python-shell--font-lock-buffer) nil) 2728 (setq-local python-shell--font-lock-buffer nil)
2729 (remove-hook 'post-command-hook 2729 (remove-hook 'post-command-hook
2730 #'python-shell-font-lock-post-command-hook 'local) 2730 #'python-shell-font-lock-post-command-hook 'local)
2731 (remove-hook 'kill-buffer-hook 2731 (remove-hook 'kill-buffer-hook
@@ -2741,8 +2741,8 @@ With argument MSG show deactivation message."
2741With argument MSG show activation/deactivation message." 2741With argument MSG show activation/deactivation message."
2742 (interactive "p") 2742 (interactive "p")
2743 (python-shell-with-shell-buffer 2743 (python-shell-with-shell-buffer
2744 (set (make-local-variable 'python-shell-font-lock-enable) 2744 (setq-local python-shell-font-lock-enable
2745 (not python-shell-font-lock-enable)) 2745 (not python-shell-font-lock-enable))
2746 (if python-shell-font-lock-enable 2746 (if python-shell-font-lock-enable
2747 (python-shell-font-lock-turn-on msg) 2747 (python-shell-font-lock-turn-on msg)
2748 (python-shell-font-lock-turn-off msg)) 2748 (python-shell-font-lock-turn-off msg))
@@ -2765,9 +2765,9 @@ eventually provide a shell."
2765(defun python-shell-comint-watch-for-first-prompt-output-filter (output) 2765(defun python-shell-comint-watch-for-first-prompt-output-filter (output)
2766 "Run `python-shell-first-prompt-hook' when first prompt is found in OUTPUT." 2766 "Run `python-shell-first-prompt-hook' when first prompt is found in OUTPUT."
2767 (when (not python-shell--first-prompt-received) 2767 (when (not python-shell--first-prompt-received)
2768 (set (make-local-variable 'python-shell--first-prompt-received-output-buffer) 2768 (setq-local python-shell--first-prompt-received-output-buffer
2769 (concat python-shell--first-prompt-received-output-buffer 2769 (concat python-shell--first-prompt-received-output-buffer
2770 (ansi-color-filter-apply output))) 2770 (ansi-color-filter-apply output)))
2771 (when (python-shell-comint-end-of-output-p 2771 (when (python-shell-comint-end-of-output-p
2772 python-shell--first-prompt-received-output-buffer) 2772 python-shell--first-prompt-received-output-buffer)
2773 (if (string-match-p 2773 (if (string-match-p
@@ -2775,7 +2775,7 @@ eventually provide a shell."
2775 (or python-shell--first-prompt-received-output-buffer "")) 2775 (or python-shell--first-prompt-received-output-buffer ""))
2776 ;; Skip pdb prompts and reset the buffer. 2776 ;; Skip pdb prompts and reset the buffer.
2777 (setq python-shell--first-prompt-received-output-buffer nil) 2777 (setq python-shell--first-prompt-received-output-buffer nil)
2778 (set (make-local-variable 'python-shell--first-prompt-received) t) 2778 (setq-local python-shell--first-prompt-received t)
2779 (setq python-shell--first-prompt-received-output-buffer nil) 2779 (setq python-shell--first-prompt-received-output-buffer nil)
2780 (with-current-buffer (current-buffer) 2780 (with-current-buffer (current-buffer)
2781 (let ((inhibit-quit nil)) 2781 (let ((inhibit-quit nil))
@@ -2815,30 +2815,30 @@ variable.
2815\(Type \\[describe-mode] in the process buffer for a list of commands.)" 2815\(Type \\[describe-mode] in the process buffer for a list of commands.)"
2816 (when python-shell--parent-buffer 2816 (when python-shell--parent-buffer
2817 (python-util-clone-local-variables python-shell--parent-buffer)) 2817 (python-util-clone-local-variables python-shell--parent-buffer))
2818 (set (make-local-variable 'indent-tabs-mode) nil) 2818 (setq-local indent-tabs-mode nil)
2819 ;; Users can interactively override default values for 2819 ;; Users can interactively override default values for
2820 ;; `python-shell-interpreter' and `python-shell-interpreter-args' 2820 ;; `python-shell-interpreter' and `python-shell-interpreter-args'
2821 ;; when calling `run-python'. This ensures values let-bound in 2821 ;; when calling `run-python'. This ensures values let-bound in
2822 ;; `python-shell-make-comint' are locally set if needed. 2822 ;; `python-shell-make-comint' are locally set if needed.
2823 (set (make-local-variable 'python-shell-interpreter) 2823 (setq-local python-shell-interpreter
2824 (or python-shell--interpreter python-shell-interpreter)) 2824 (or python-shell--interpreter python-shell-interpreter))
2825 (set (make-local-variable 'python-shell-interpreter-args) 2825 (setq-local python-shell-interpreter-args
2826 (or python-shell--interpreter-args python-shell-interpreter-args)) 2826 (or python-shell--interpreter-args python-shell-interpreter-args))
2827 (set (make-local-variable 'python-shell--prompt-calculated-input-regexp) nil) 2827 (setq-local python-shell--prompt-calculated-input-regexp nil)
2828 (set (make-local-variable 'python-shell--block-prompt) nil) 2828 (setq-local python-shell--block-prompt nil)
2829 (set (make-local-variable 'python-shell--prompt-calculated-output-regexp) nil) 2829 (setq-local python-shell--prompt-calculated-output-regexp nil)
2830 (python-shell-prompt-set-calculated-regexps) 2830 (python-shell-prompt-set-calculated-regexps)
2831 (setq comint-prompt-regexp python-shell--prompt-calculated-input-regexp) 2831 (setq comint-prompt-regexp python-shell--prompt-calculated-input-regexp)
2832 (set (make-local-variable 'comint-prompt-read-only) t) 2832 (setq-local comint-prompt-read-only t)
2833 (setq mode-line-process '(":%s")) 2833 (setq mode-line-process '(":%s"))
2834 (set (make-local-variable 'comint-output-filter-functions) 2834 (setq-local comint-output-filter-functions
2835 '(ansi-color-process-output 2835 '(ansi-color-process-output
2836 python-shell-comint-watch-for-first-prompt-output-filter 2836 python-shell-comint-watch-for-first-prompt-output-filter
2837 python-comint-postoutput-scroll-to-bottom 2837 python-comint-postoutput-scroll-to-bottom
2838 comint-watch-for-password-prompt)) 2838 comint-watch-for-password-prompt))
2839 (setq-local comint-highlight-input nil) 2839 (setq-local comint-highlight-input nil)
2840 (set (make-local-variable 'compilation-error-regexp-alist) 2840 (setq-local compilation-error-regexp-alist
2841 python-shell-compilation-regexp-alist) 2841 python-shell-compilation-regexp-alist)
2842 (add-hook 'completion-at-point-functions 2842 (add-hook 'completion-at-point-functions
2843 #'python-shell-completion-at-point nil 'local) 2843 #'python-shell-completion-at-point nil 'local)
2844 (define-key inferior-python-mode-map "\t" 2844 (define-key inferior-python-mode-map "\t"
@@ -3605,7 +3605,7 @@ __PYTHON_EL_native_completion_setup()" process)
3605With argument MSG show deactivation message." 3605With argument MSG show deactivation message."
3606 (interactive "p") 3606 (interactive "p")
3607 (python-shell-with-shell-buffer 3607 (python-shell-with-shell-buffer
3608 (set (make-local-variable 'python-shell-completion-native-enable) nil) 3608 (setq-local python-shell-completion-native-enable nil)
3609 (when msg 3609 (when msg
3610 (message "Shell native completion is disabled, using fallback")))) 3610 (message "Shell native completion is disabled, using fallback"))))
3611 3611
@@ -3614,7 +3614,7 @@ With argument MSG show deactivation message."
3614With argument MSG show deactivation message." 3614With argument MSG show deactivation message."
3615 (interactive "p") 3615 (interactive "p")
3616 (python-shell-with-shell-buffer 3616 (python-shell-with-shell-buffer
3617 (set (make-local-variable 'python-shell-completion-native-enable) t) 3617 (setq-local python-shell-completion-native-enable t)
3618 (python-shell-completion-native-turn-on-maybe msg))) 3618 (python-shell-completion-native-turn-on-maybe msg)))
3619 3619
3620(defun python-shell-completion-native-turn-on-maybe (&optional msg) 3620(defun python-shell-completion-native-turn-on-maybe (&optional msg)
@@ -3994,7 +3994,7 @@ Argument OUTPUT is a string with the output from the comint process."
3994 (tracked-buffer-window (get-buffer-window tracked-buffer)) 3994 (tracked-buffer-window (get-buffer-window tracked-buffer))
3995 (tracked-buffer-line-pos)) 3995 (tracked-buffer-line-pos))
3996 (with-current-buffer tracked-buffer 3996 (with-current-buffer tracked-buffer
3997 (set (make-local-variable 'overlay-arrow-position) (make-marker)) 3997 (setq-local overlay-arrow-position (make-marker))
3998 (setq tracked-buffer-line-pos (progn 3998 (setq tracked-buffer-line-pos (progn
3999 (goto-char (point-min)) 3999 (goto-char (point-min))
4000 (forward-line (1- line-number)) 4000 (forward-line (1- line-number))
@@ -5535,48 +5535,43 @@ REPORT-FN is Flymake's callback function."
5535 "Major mode for editing Python files. 5535 "Major mode for editing Python files.
5536 5536
5537\\{python-mode-map}" 5537\\{python-mode-map}"
5538 (set (make-local-variable 'tab-width) 8) 5538 (setq-local tab-width 8)
5539 (set (make-local-variable 'indent-tabs-mode) nil) 5539 (setq-local indent-tabs-mode nil)
5540 5540
5541 (set (make-local-variable 'comment-start) "# ") 5541 (setq-local comment-start "# ")
5542 (set (make-local-variable 'comment-start-skip) "#+\\s-*") 5542 (setq-local comment-start-skip "#+\\s-*")
5543 5543
5544 (set (make-local-variable 'parse-sexp-lookup-properties) t) 5544 (setq-local parse-sexp-lookup-properties t)
5545 (set (make-local-variable 'parse-sexp-ignore-comments) t) 5545 (setq-local parse-sexp-ignore-comments t)
5546 5546
5547 (set (make-local-variable 'forward-sexp-function) 5547 (setq-local forward-sexp-function #'python-nav-forward-sexp)
5548 'python-nav-forward-sexp)
5549 5548
5550 (set (make-local-variable 'font-lock-defaults) 5549 (setq-local font-lock-defaults
5551 `(,python-font-lock-keywords 5550 `(,python-font-lock-keywords
5552 nil nil nil nil 5551 nil nil nil nil
5553 (font-lock-syntactic-face-function 5552 (font-lock-syntactic-face-function
5554 . python-font-lock-syntactic-face-function))) 5553 . python-font-lock-syntactic-face-function)))
5555 5554
5556 (set (make-local-variable 'syntax-propertize-function) 5555 (setq-local syntax-propertize-function
5557 python-syntax-propertize-function) 5556 python-syntax-propertize-function)
5558 5557
5559 (set (make-local-variable 'indent-line-function) 5558 (setq-local indent-line-function #'python-indent-line-function)
5560 #'python-indent-line-function) 5559 (setq-local indent-region-function #'python-indent-region)
5561 (set (make-local-variable 'indent-region-function) #'python-indent-region)
5562 ;; Because indentation is not redundant, we cannot safely reindent code. 5560 ;; Because indentation is not redundant, we cannot safely reindent code.
5563 (set (make-local-variable 'electric-indent-inhibit) t) 5561 (setq-local electric-indent-inhibit t)
5564 (set (make-local-variable 'electric-indent-chars) 5562 (setq-local electric-indent-chars
5565 (cons ?: electric-indent-chars)) 5563 (cons ?: electric-indent-chars))
5566 5564
5567 ;; Add """ ... """ pairing to electric-pair-mode. 5565 ;; Add """ ... """ pairing to electric-pair-mode.
5568 (add-hook 'post-self-insert-hook 5566 (add-hook 'post-self-insert-hook
5569 #'python-electric-pair-string-delimiter 'append t) 5567 #'python-electric-pair-string-delimiter 'append t)
5570 5568
5571 (set (make-local-variable 'paragraph-start) "\\s-*$") 5569 (setq-local paragraph-start "\\s-*$")
5572 (set (make-local-variable 'fill-paragraph-function) 5570 (setq-local fill-paragraph-function #'python-fill-paragraph)
5573 #'python-fill-paragraph) 5571 (setq-local normal-auto-fill-function #'python-do-auto-fill)
5574 (set (make-local-variable 'normal-auto-fill-function) #'python-do-auto-fill)
5575 5572
5576 (set (make-local-variable 'beginning-of-defun-function) 5573 (setq-local beginning-of-defun-function #'python-nav-beginning-of-defun)
5577 #'python-nav-beginning-of-defun) 5574 (setq-local end-of-defun-function #'python-nav-end-of-defun)
5578 (set (make-local-variable 'end-of-defun-function)
5579 #'python-nav-end-of-defun)
5580 5575
5581 (add-hook 'completion-at-point-functions 5576 (add-hook 'completion-at-point-functions
5582 #'python-completion-at-point nil 'local) 5577 #'python-completion-at-point nil 'local)
@@ -5584,26 +5579,25 @@ REPORT-FN is Flymake's callback function."
5584 (add-hook 'post-self-insert-hook 5579 (add-hook 'post-self-insert-hook
5585 #'python-indent-post-self-insert-function 'append 'local) 5580 #'python-indent-post-self-insert-function 'append 'local)
5586 5581
5587 (set (make-local-variable 'imenu-create-index-function) 5582 (setq-local imenu-create-index-function
5588 #'python-imenu-create-index) 5583 #'python-imenu-create-index)
5589 5584
5590 (set (make-local-variable 'add-log-current-defun-function) 5585 (setq-local add-log-current-defun-function
5591 #'python-info-current-defun) 5586 #'python-info-current-defun)
5592 5587
5593 (add-hook 'which-func-functions #'python-info-current-defun nil t) 5588 (add-hook 'which-func-functions #'python-info-current-defun nil t)
5594 5589
5595 (set (make-local-variable 'skeleton-further-elements) 5590 (setq-local skeleton-further-elements
5596 '((abbrev-mode nil) 5591 '((abbrev-mode nil)
5597 (< '(backward-delete-char-untabify (min python-indent-offset 5592 (< '(backward-delete-char-untabify (min python-indent-offset
5598 (current-column)))) 5593 (current-column))))
5599 (^ '(- (1+ (current-indentation)))))) 5594 (^ '(- (1+ (current-indentation))))))
5600 5595
5601 (with-no-warnings 5596 (with-no-warnings
5602 ;; suppress warnings about eldoc-documentation-function being obsolete 5597 ;; suppress warnings about eldoc-documentation-function being obsolete
5603 (if (null eldoc-documentation-function) 5598 (if (null eldoc-documentation-function)
5604 ;; Emacs<25 5599 ;; Emacs<25
5605 (set (make-local-variable 'eldoc-documentation-function) 5600 (setq-local eldoc-documentation-function #'python-eldoc-function)
5606 #'python-eldoc-function)
5607 (if (boundp 'eldoc-documentation-functions) 5601 (if (boundp 'eldoc-documentation-functions)
5608 (add-hook 'eldoc-documentation-functions #'python-eldoc-function nil t) 5602 (add-hook 'eldoc-documentation-functions #'python-eldoc-function nil t)
5609 (add-function :before-until (local 'eldoc-documentation-function) 5603 (add-function :before-until (local 'eldoc-documentation-function)
@@ -5620,16 +5614,14 @@ REPORT-FN is Flymake's callback function."
5620 python-hideshow-forward-sexp-function 5614 python-hideshow-forward-sexp-function
5621 nil)) 5615 nil))
5622 5616
5623 (set (make-local-variable 'outline-regexp) 5617 (setq-local outline-regexp (python-rx (* space) block-start))
5624 (python-rx (* space) block-start)) 5618 (setq-local outline-heading-end-regexp ":[^\n]*\n")
5625 (set (make-local-variable 'outline-heading-end-regexp) ":[^\n]*\n") 5619 (setq-local outline-level
5626 (set (make-local-variable 'outline-level) 5620 (lambda ()
5627 #'(lambda () 5621 "`outline-level' function for Python mode."
5628 "`outline-level' function for Python mode." 5622 (1+ (/ (current-indentation) python-indent-offset))))
5629 (1+ (/ (current-indentation) python-indent-offset))))
5630 5623
5631 (set (make-local-variable 'prettify-symbols-alist) 5624 (setq-local prettify-symbols-alist python-prettify-symbols-alist)
5632 python-prettify-symbols-alist)
5633 5625
5634 (python-skeleton-add-menu-items) 5626 (python-skeleton-add-menu-items)
5635 5627