diff options
| author | Tom Tromey <tromey@redhat.com> | 2013-01-05 19:36:45 -0700 |
|---|---|---|
| committer | Tom Tromey <tromey@redhat.com> | 2013-01-05 19:36:45 -0700 |
| commit | e078a23febca14bc919c5806670479c395e3253e (patch) | |
| tree | e9e4ed91feef744d525264c31974c3ed00146bcd /lisp/progmodes/python.el | |
| parent | 63d535c829a930207b64fe733228f15a554644b1 (diff) | |
| parent | 7a2657fa3bedbd977f4e11fe030cb4a210c04ab4 (diff) | |
| download | emacs-e078a23febca14bc919c5806670479c395e3253e.tar.gz | |
merge from trunk
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 @@ ;;; python.el --- Python's flying circus support for Emacs -;; Copyright (C) 2003-2012 Free Software Foundation, Inc. +;; Copyright (C) 2003-2013 Free Software Foundation, Inc. ;; Author: Fabián E. Gallina <fabian@anue.biz> ;; URL: https://github.com/fgallina/python.el @@ -204,7 +204,6 @@ (require 'ansi-color) (require 'comint) -(eval-when-compile (require 'cl-lib)) ;; Avoid compiler warnings (defvar view-return-to-alist) @@ -221,7 +220,7 @@ (defgroup python nil "Python Language's flying circus support for Emacs." :group 'languages - :version "23.2" + :version "24.3" :link '(emacs-commentary-link "python")) @@ -529,7 +528,7 @@ is used to limit the scan." (while (and (< i 3) (or (not limit) (< (+ point i) limit)) (eq (char-after (+ point i)) quote-char)) - (cl-incf i)) + (setq i (1+ i))) i)) (defun python-syntax-stringify () @@ -608,6 +607,12 @@ It makes underscores and dots word constituent chars.") :group 'python :safe 'booleanp) +(defcustom python-indent-trigger-commands + '(indent-for-tab-command yas-expand yas/expand) + "Commands that might trigger a `python-indent-line' call." + :type '(repeat symbol) + :group 'python) + (define-obsolete-variable-alias 'python-indent 'python-indent-offset "24.3") @@ -906,20 +911,21 @@ Uses the offset calculated in indicated by the variable `python-indent-levels' to set the current indentation. -When the variable `last-command' is equal to -`indent-for-tab-command' or FORCE-TOGGLE is non-nil it cycles -levels indicated in the variable `python-indent-levels' by -setting the current level in the variable -`python-indent-current-level'. - -When the variable `last-command' is not equal to -`indent-for-tab-command' and FORCE-TOGGLE is nil it calculates -possible indentation levels and saves it in the variable -`python-indent-levels'. Afterwards it sets the variable -`python-indent-current-level' correctly so offset is equal -to (`nth' `python-indent-current-level' `python-indent-levels')" +When the variable `last-command' is equal to one of the symbols +inside `python-indent-trigger-commands' or FORCE-TOGGLE is +non-nil it cycles levels indicated in the variable +`python-indent-levels' by setting the current level in the +variable `python-indent-current-level'. + +When the variable `last-command' is not equal to one of the +symbols inside `python-indent-trigger-commands' and FORCE-TOGGLE +is nil it calculates possible indentation levels and saves it in +the variable `python-indent-levels'. Afterwards it sets the +variable `python-indent-current-level' correctly so offset is +equal to (`nth' `python-indent-current-level' +`python-indent-levels')" (or - (and (or (and (eq this-command 'indent-for-tab-command) + (and (or (and (memq this-command python-indent-trigger-commands) (eq last-command this-command)) force-toggle) (not (equal python-indent-levels '(0))) @@ -1181,16 +1187,27 @@ Returns nil if point is not in a def or class." (forward-line -1)))) (point-marker)) -(defun python-nav-end-of-statement () - "Move to end of current statement." +(defun python-nav-end-of-statement (&optional noend) + "Move to end of current statement. +Optional argument NOEND is internal and makes the logic to not +jump to the end of line when moving forward searching for the end +of the statement." (interactive "^") - (while (and (goto-char (line-end-position)) - (not (eobp)) - (when (or - (python-info-line-ends-backslash-p) - (python-syntax-context 'string) - (python-syntax-context 'paren)) - (forward-line 1)))) + (let (string-start bs-pos) + (while (and (or noend (goto-char (line-end-position))) + (not (eobp)) + (cond ((setq string-start (python-syntax-context 'string)) + (goto-char string-start) + (python-nav-end-of-statement t)) + ((python-syntax-context 'paren) + ;; The statement won't end before we've escaped + ;; at least one level of parenthesis. + (condition-case err + (goto-char (scan-lists (point) 1 -1)) + (scan-error (goto-char (nth 3 err))))) + ((setq bs-pos (python-info-line-ends-backslash-p)) + (goto-char bs-pos) + (forward-line 1)))))) (point-marker)) (defun python-nav-backward-statement (&optional arg) @@ -2009,7 +2026,14 @@ Returns the output. See `python-shell-send-string-no-output'." (defun python-shell-send-region (start end) "Send the region delimited by START and END to inferior Python process." (interactive "r") - (python-shell-send-string (buffer-substring start end) nil t)) + (python-shell-send-string + (concat + (let ((line-num (line-number-at-pos start))) + ;; When sending a region, add blank lines for non sent code so + ;; backtraces remain correct. + (make-string (1- line-num) ?\n)) + (buffer-substring start end)) + nil t)) (defun python-shell-send-buffer (&optional arg) "Send the entire buffer to inferior Python process. @@ -2487,12 +2511,12 @@ JUSTIFY should be used (if applicable) as in `fill-paragraph'." JUSTIFY should be used (if applicable) as in `fill-paragraph'." (let* ((marker (point-marker)) (str-start-pos - (let ((m (make-marker))) - (setf (marker-position m) - (or (python-syntax-context 'string) - (and (equal (string-to-syntax "|") - (syntax-after (point))) - (point)))) m)) + (set-marker + (make-marker) + (or (python-syntax-context 'string) + (and (equal (string-to-syntax "|") + (syntax-after (point))) + (point))))) (num-quotes (python-syntax-count-quotes (char-after str-start-pos) str-start-pos)) (str-end-pos |
