diff options
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r-- | lisp/progmodes/python.el | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index afb96974b17..20299c20d28 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -54,14 +54,7 @@ ;; `python-nav-backward-statement', ;; `python-nav-beginning-of-statement', `python-nav-end-of-statement', ;; `python-nav-beginning-of-block', `python-nav-end-of-block' and -;; `python-nav-if-name-main' are included but no bound to any key. At -;; last but not least the specialized `python-nav-forward-sexp' allows -;; easy navigation between code blocks. If you prefer `cc-mode'-like -;; `forward-sexp' movement, setting `forward-sexp-function' to nil is -;; enough, You can do that using the `python-mode-hook': - -;; (add-hook 'python-mode-hook -;; (lambda () (setq forward-sexp-function nil))) +;; `python-nav-if-name-main' are included but no bound to any key. ;; Shell interaction: is provided and allows opening Python shells ;; inside Emacs and executing any block of code of your current buffer @@ -241,14 +234,12 @@ ;; 2) Add the following hook in your .emacs: ;; (add-hook 'python-mode-hook -;; #'(lambda () -;; (define-key python-mode-map "\C-m" 'newline-and-indent))) +;; (lambda () +;; (define-key python-mode-map "\C-m" 'newline-and-indent))) ;; I'd recommend the first one since you'll get the same behavior for ;; all modes out-of-the-box. -;;; TODO: - ;;; Code: (require 'ansi-color) @@ -3094,7 +3085,8 @@ t when called interactively." (list (read-string "Python command: ") nil t)) (let ((process (or process (python-shell-get-process-or-error msg)))) (if (string-match ".\n+." string) ;Multiline. - (let* ((temp-file-name (python-shell--save-temp-file string)) + (let* ((temp-file-name (with-current-buffer (process-buffer process) + (python-shell--save-temp-file string))) (file-name (or (buffer-file-name) temp-file-name))) (python-shell-send-file file-name process temp-file-name t)) (comint-send-string process string) @@ -3385,7 +3377,8 @@ user-friendly message if there's no process running; defaults to t when called interactively." (interactive "p") (pop-to-buffer - (process-buffer (python-shell-get-process-or-error msg)) nil t)) + (process-buffer (python-shell-get-process-or-error msg)) + nil 'mark-for-redisplay)) (defun python-shell-send-setup-code () "Send all setup code for shell. @@ -3976,8 +3969,8 @@ Returns the tracked buffer." "Finish tracking." (python-pdbtrack-unset-tracked-buffer) (when python-pdbtrack-kill-buffers - (mapc #'(lambda (buffer) - (ignore-errors (kill-buffer buffer))) + (mapc (lambda (buffer) + (ignore-errors (kill-buffer buffer))) python-pdbtrack-buffers-to-kill)) (setq python-pdbtrack-buffers-to-kill nil)) @@ -4240,6 +4233,11 @@ JUSTIFY should be used (if applicable) as in `fill-paragraph'." (point))))) (num-quotes (python-syntax-count-quotes (char-after str-start-pos) str-start-pos)) + (str-line-start-pos + (save-excursion + (goto-char str-start-pos) + (beginning-of-line) + (point-marker))) (str-end-pos (save-excursion (goto-char (+ str-start-pos num-quotes)) @@ -4263,7 +4261,7 @@ JUSTIFY should be used (if applicable) as in `fill-paragraph'." ('symmetric (and multi-line-p (cons 1 1))))) (fill-paragraph-function)) (save-restriction - (narrow-to-region str-start-pos str-end-pos) + (narrow-to-region str-line-start-pos str-end-pos) (fill-paragraph justify)) (save-excursion (when (and (python-info-docstring-p) python-fill-docstring-style) @@ -5501,6 +5499,13 @@ By default messages are considered errors." :type '(alist :key-type (regexp) :value-type (symbol))) +(defcustom python-forward-sexp-function #'python-nav-forward-sexp + "Function to use when navigating between expressions." + :version "28.1" + :type '(choice (const :tag "Python blocks" python-nav-forward-sexp) + (const :tag "CC-mode like" nil) + function)) + (defvar-local python--flymake-proc nil) (defun python--flymake-parse-output (source proc report-fn) @@ -5598,7 +5603,7 @@ REPORT-FN is Flymake's callback function." (setq-local parse-sexp-lookup-properties t) (setq-local parse-sexp-ignore-comments t) - (setq-local forward-sexp-function #'python-nav-forward-sexp) + (setq-local forward-sexp-function python-forward-sexp-function) (setq-local font-lock-defaults `(,python-font-lock-keywords |