aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/progmodes')
-rw-r--r--lisp/progmodes/python.el57
1 files changed, 35 insertions, 22 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 67388c0339b..54a657a2593 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -204,7 +204,6 @@
204 204
205(require 'ansi-color) 205(require 'ansi-color)
206(require 'comint) 206(require 'comint)
207(eval-when-compile (require 'cl-lib))
208 207
209;; Avoid compiler warnings 208;; Avoid compiler warnings
210(defvar view-return-to-alist) 209(defvar view-return-to-alist)
@@ -529,7 +528,7 @@ is used to limit the scan."
529 (while (and (< i 3) 528 (while (and (< i 3)
530 (or (not limit) (< (+ point i) limit)) 529 (or (not limit) (< (+ point i) limit))
531 (eq (char-after (+ point i)) quote-char)) 530 (eq (char-after (+ point i)) quote-char))
532 (cl-incf i)) 531 (setq i (1+ i)))
533 i)) 532 i))
534 533
535(defun python-syntax-stringify () 534(defun python-syntax-stringify ()
@@ -608,6 +607,12 @@ It makes underscores and dots word constituent chars.")
608 :group 'python 607 :group 'python
609 :safe 'booleanp) 608 :safe 'booleanp)
610 609
610(defcustom python-indent-trigger-commands
611 '(indent-for-tab-command yas-expand yas/expand)
612 "Commands that might trigger a `python-indent-line' call."
613 :type '(repeat symbol)
614 :group 'python)
615
611(define-obsolete-variable-alias 616(define-obsolete-variable-alias
612 'python-indent 'python-indent-offset "24.3") 617 'python-indent 'python-indent-offset "24.3")
613 618
@@ -906,20 +911,21 @@ Uses the offset calculated in
906indicated by the variable `python-indent-levels' to set the 911indicated by the variable `python-indent-levels' to set the
907current indentation. 912current indentation.
908 913
909When the variable `last-command' is equal to 914When the variable `last-command' is equal to one of the symbols
910`indent-for-tab-command' or FORCE-TOGGLE is non-nil it cycles 915inside `python-indent-trigger-commands' or FORCE-TOGGLE is
911levels indicated in the variable `python-indent-levels' by 916non-nil it cycles levels indicated in the variable
912setting the current level in the variable 917`python-indent-levels' by setting the current level in the
913`python-indent-current-level'. 918variable `python-indent-current-level'.
914 919
915When the variable `last-command' is not equal to 920When the variable `last-command' is not equal to one of the
916`indent-for-tab-command' and FORCE-TOGGLE is nil it calculates 921symbols inside `python-indent-trigger-commands' and FORCE-TOGGLE
917possible indentation levels and saves it in the variable 922is nil it calculates possible indentation levels and saves it in
918`python-indent-levels'. Afterwards it sets the variable 923the variable `python-indent-levels'. Afterwards it sets the
919`python-indent-current-level' correctly so offset is equal 924variable `python-indent-current-level' correctly so offset is
920to (`nth' `python-indent-current-level' `python-indent-levels')" 925equal to (`nth' `python-indent-current-level'
926`python-indent-levels')"
921 (or 927 (or
922 (and (or (and (eq this-command 'indent-for-tab-command) 928 (and (or (and (memq this-command python-indent-trigger-commands)
923 (eq last-command this-command)) 929 (eq last-command this-command))
924 force-toggle) 930 force-toggle)
925 (not (equal python-indent-levels '(0))) 931 (not (equal python-indent-levels '(0)))
@@ -2009,7 +2015,14 @@ Returns the output. See `python-shell-send-string-no-output'."
2009(defun python-shell-send-region (start end) 2015(defun python-shell-send-region (start end)
2010 "Send the region delimited by START and END to inferior Python process." 2016 "Send the region delimited by START and END to inferior Python process."
2011 (interactive "r") 2017 (interactive "r")
2012 (python-shell-send-string (buffer-substring start end) nil t)) 2018 (python-shell-send-string
2019 (concat
2020 (let ((line-num (line-number-at-pos start)))
2021 ;; When sending a region, add blank lines for non sent code so
2022 ;; backtraces remain correct.
2023 (make-string (1- line-num) ?\n))
2024 (buffer-substring start end))
2025 nil t))
2013 2026
2014(defun python-shell-send-buffer (&optional arg) 2027(defun python-shell-send-buffer (&optional arg)
2015 "Send the entire buffer to inferior Python process. 2028 "Send the entire buffer to inferior Python process.
@@ -2487,12 +2500,12 @@ JUSTIFY should be used (if applicable) as in `fill-paragraph'."
2487JUSTIFY should be used (if applicable) as in `fill-paragraph'." 2500JUSTIFY should be used (if applicable) as in `fill-paragraph'."
2488 (let* ((marker (point-marker)) 2501 (let* ((marker (point-marker))
2489 (str-start-pos 2502 (str-start-pos
2490 (let ((m (make-marker))) 2503 (set-marker
2491 (setf (marker-position m) 2504 (make-marker)
2492 (or (python-syntax-context 'string) 2505 (or (python-syntax-context 'string)
2493 (and (equal (string-to-syntax "|") 2506 (and (equal (string-to-syntax "|")
2494 (syntax-after (point))) 2507 (syntax-after (point)))
2495 (point)))) m)) 2508 (point)))))
2496 (num-quotes (python-syntax-count-quotes 2509 (num-quotes (python-syntax-count-quotes
2497 (char-after str-start-pos) str-start-pos)) 2510 (char-after str-start-pos) str-start-pos))
2498 (str-end-pos 2511 (str-end-pos