diff options
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 90 |
1 files changed, 57 insertions, 33 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 67388c0339b..172193266ca 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; python.el --- Python's flying circus support for Emacs | 1 | ;;; python.el --- Python's flying circus support for Emacs |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 2003-2012 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 2003-2013 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Author: Fabián E. Gallina <fabian@anue.biz> | 5 | ;; Author: Fabián E. Gallina <fabian@anue.biz> |
| 6 | ;; URL: https://github.com/fgallina/python.el | 6 | ;; URL: https://github.com/fgallina/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) |
| @@ -221,7 +220,7 @@ | |||
| 221 | (defgroup python nil | 220 | (defgroup python nil |
| 222 | "Python Language's flying circus support for Emacs." | 221 | "Python Language's flying circus support for Emacs." |
| 223 | :group 'languages | 222 | :group 'languages |
| 224 | :version "23.2" | 223 | :version "24.3" |
| 225 | :link '(emacs-commentary-link "python")) | 224 | :link '(emacs-commentary-link "python")) |
| 226 | 225 | ||
| 227 | 226 | ||
| @@ -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 | |||
| 906 | indicated by the variable `python-indent-levels' to set the | 911 | indicated by the variable `python-indent-levels' to set the |
| 907 | current indentation. | 912 | current indentation. |
| 908 | 913 | ||
| 909 | When the variable `last-command' is equal to | 914 | When the variable `last-command' is equal to one of the symbols |
| 910 | `indent-for-tab-command' or FORCE-TOGGLE is non-nil it cycles | 915 | inside `python-indent-trigger-commands' or FORCE-TOGGLE is |
| 911 | levels indicated in the variable `python-indent-levels' by | 916 | non-nil it cycles levels indicated in the variable |
| 912 | setting the current level in the variable | 917 | `python-indent-levels' by setting the current level in the |
| 913 | `python-indent-current-level'. | 918 | variable `python-indent-current-level'. |
| 914 | 919 | ||
| 915 | When the variable `last-command' is not equal to | 920 | When the variable `last-command' is not equal to one of the |
| 916 | `indent-for-tab-command' and FORCE-TOGGLE is nil it calculates | 921 | symbols inside `python-indent-trigger-commands' and FORCE-TOGGLE |
| 917 | possible indentation levels and saves it in the variable | 922 | is nil it calculates possible indentation levels and saves it in |
| 918 | `python-indent-levels'. Afterwards it sets the variable | 923 | the variable `python-indent-levels'. Afterwards it sets the |
| 919 | `python-indent-current-level' correctly so offset is equal | 924 | variable `python-indent-current-level' correctly so offset is |
| 920 | to (`nth' `python-indent-current-level' `python-indent-levels')" | 925 | equal 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))) |
| @@ -1181,16 +1187,27 @@ Returns nil if point is not in a def or class." | |||
| 1181 | (forward-line -1)))) | 1187 | (forward-line -1)))) |
| 1182 | (point-marker)) | 1188 | (point-marker)) |
| 1183 | 1189 | ||
| 1184 | (defun python-nav-end-of-statement () | 1190 | (defun python-nav-end-of-statement (&optional noend) |
| 1185 | "Move to end of current statement." | 1191 | "Move to end of current statement. |
| 1192 | Optional argument NOEND is internal and makes the logic to not | ||
| 1193 | jump to the end of line when moving forward searching for the end | ||
| 1194 | of the statement." | ||
| 1186 | (interactive "^") | 1195 | (interactive "^") |
| 1187 | (while (and (goto-char (line-end-position)) | 1196 | (let (string-start bs-pos) |
| 1188 | (not (eobp)) | 1197 | (while (and (or noend (goto-char (line-end-position))) |
| 1189 | (when (or | 1198 | (not (eobp)) |
| 1190 | (python-info-line-ends-backslash-p) | 1199 | (cond ((setq string-start (python-syntax-context 'string)) |
| 1191 | (python-syntax-context 'string) | 1200 | (goto-char string-start) |
| 1192 | (python-syntax-context 'paren)) | 1201 | (python-nav-end-of-statement t)) |
| 1193 | (forward-line 1)))) | 1202 | ((python-syntax-context 'paren) |
| 1203 | ;; The statement won't end before we've escaped | ||
| 1204 | ;; at least one level of parenthesis. | ||
| 1205 | (condition-case err | ||
| 1206 | (goto-char (scan-lists (point) 1 -1)) | ||
| 1207 | (scan-error (goto-char (nth 3 err))))) | ||
| 1208 | ((setq bs-pos (python-info-line-ends-backslash-p)) | ||
| 1209 | (goto-char bs-pos) | ||
| 1210 | (forward-line 1)))))) | ||
| 1194 | (point-marker)) | 1211 | (point-marker)) |
| 1195 | 1212 | ||
| 1196 | (defun python-nav-backward-statement (&optional arg) | 1213 | (defun python-nav-backward-statement (&optional arg) |
| @@ -2009,7 +2026,14 @@ Returns the output. See `python-shell-send-string-no-output'." | |||
| 2009 | (defun python-shell-send-region (start end) | 2026 | (defun python-shell-send-region (start end) |
| 2010 | "Send the region delimited by START and END to inferior Python process." | 2027 | "Send the region delimited by START and END to inferior Python process." |
| 2011 | (interactive "r") | 2028 | (interactive "r") |
| 2012 | (python-shell-send-string (buffer-substring start end) nil t)) | 2029 | (python-shell-send-string |
| 2030 | (concat | ||
| 2031 | (let ((line-num (line-number-at-pos start))) | ||
| 2032 | ;; When sending a region, add blank lines for non sent code so | ||
| 2033 | ;; backtraces remain correct. | ||
| 2034 | (make-string (1- line-num) ?\n)) | ||
| 2035 | (buffer-substring start end)) | ||
| 2036 | nil t)) | ||
| 2013 | 2037 | ||
| 2014 | (defun python-shell-send-buffer (&optional arg) | 2038 | (defun python-shell-send-buffer (&optional arg) |
| 2015 | "Send the entire buffer to inferior Python process. | 2039 | "Send the entire buffer to inferior Python process. |
| @@ -2487,12 +2511,12 @@ JUSTIFY should be used (if applicable) as in `fill-paragraph'." | |||
| 2487 | JUSTIFY should be used (if applicable) as in `fill-paragraph'." | 2511 | JUSTIFY should be used (if applicable) as in `fill-paragraph'." |
| 2488 | (let* ((marker (point-marker)) | 2512 | (let* ((marker (point-marker)) |
| 2489 | (str-start-pos | 2513 | (str-start-pos |
| 2490 | (let ((m (make-marker))) | 2514 | (set-marker |
| 2491 | (setf (marker-position m) | 2515 | (make-marker) |
| 2492 | (or (python-syntax-context 'string) | 2516 | (or (python-syntax-context 'string) |
| 2493 | (and (equal (string-to-syntax "|") | 2517 | (and (equal (string-to-syntax "|") |
| 2494 | (syntax-after (point))) | 2518 | (syntax-after (point))) |
| 2495 | (point)))) m)) | 2519 | (point))))) |
| 2496 | (num-quotes (python-syntax-count-quotes | 2520 | (num-quotes (python-syntax-count-quotes |
| 2497 | (char-after str-start-pos) str-start-pos)) | 2521 | (char-after str-start-pos) str-start-pos)) |
| 2498 | (str-end-pos | 2522 | (str-end-pos |