aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorJan D2015-04-03 12:32:13 +0200
committerJan D2015-04-03 12:32:13 +0200
commit75c8741afba2321add3ad52c5143b4fdb1d63e18 (patch)
tree3a125791aba92eb58bee81163a93c3246f275a54 /lisp/progmodes/python.el
parent734900695acbe17bc7c52c85133918b8949fd2d3 (diff)
parent0b914bada39e4577cd9e9209a15c44cc1f83294d (diff)
downloademacs-75c8741afba2321add3ad52c5143b4fdb1d63e18.tar.gz
emacs-75c8741afba2321add3ad52c5143b4fdb1d63e18.zip
Merge branch 'master' into cairo
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el76
1 files changed, 37 insertions, 39 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index be747d008dd..67b44aa1bbe 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -4,7 +4,7 @@
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
7;; Version: 0.24.4 7;; Version: 0.24.5
8;; Maintainer: emacs-devel@gnu.org 8;; Maintainer: emacs-devel@gnu.org
9;; Created: Jul 2010 9;; Created: Jul 2010
10;; Keywords: languages 10;; Keywords: languages
@@ -696,6 +696,12 @@ It makes underscores and dots word constituent chars.")
696 :group 'python 696 :group 'python
697 :safe 'booleanp) 697 :safe 'booleanp)
698 698
699(defcustom python-indent-guess-indent-offset-verbose t
700 "Non-nil means to emit a warning when indentation guessing fails."
701 :type 'boolean
702 :group 'python
703 :safe' booleanp)
704
699(defcustom python-indent-trigger-commands 705(defcustom python-indent-trigger-commands
700 '(indent-for-tab-command yas-expand yas/expand) 706 '(indent-for-tab-command yas-expand yas/expand)
701 "Commands that might trigger a `python-indent-line' call." 707 "Commands that might trigger a `python-indent-line' call."
@@ -766,8 +772,9 @@ work on `python-indent-calculate-indentation' instead."
766 (current-indentation)))) 772 (current-indentation))))
767 (if (and indentation (not (zerop indentation))) 773 (if (and indentation (not (zerop indentation)))
768 (set (make-local-variable 'python-indent-offset) indentation) 774 (set (make-local-variable 'python-indent-offset) indentation)
769 (message "Can't guess python-indent-offset, using defaults: %s" 775 (when python-indent-guess-indent-offset-verbose
770 python-indent-offset))))))) 776 (message "Can't guess python-indent-offset, using defaults: %s"
777 python-indent-offset))))))))
771 778
772(defun python-indent-context () 779(defun python-indent-context ()
773 "Get information about the current indentation context. 780 "Get information about the current indentation context.
@@ -843,15 +850,6 @@ keyword
843 ;; Beginning of buffer. 850 ;; Beginning of buffer.
844 ((= (line-number-at-pos) 1) 851 ((= (line-number-at-pos) 1)
845 (cons :no-indent 0)) 852 (cons :no-indent 0))
846 ;; Comment continuation (maybe).
847 ((save-excursion
848 (when (and
849 (or
850 (python-info-current-line-comment-p)
851 (python-info-current-line-empty-p))
852 (forward-comment -1)
853 (python-info-current-line-comment-p))
854 (cons :after-comment (point)))))
855 ;; Inside a string. 853 ;; Inside a string.
856 ((let ((start (python-syntax-context 'string ppss))) 854 ((let ((start (python-syntax-context 'string ppss)))
857 (when start 855 (when start
@@ -963,28 +961,29 @@ keyword
963 ((let ((start (python-info-dedenter-statement-p))) 961 ((let ((start (python-info-dedenter-statement-p)))
964 (when start 962 (when start
965 (cons :at-dedenter-block-start start)))) 963 (cons :at-dedenter-block-start start))))
966 ;; After normal line. 964 ;; After normal line, comment or ender (default case).
967 ((let ((start (save-excursion 965 ((save-excursion
968 (back-to-indentation) 966 (back-to-indentation)
969 (skip-chars-backward " \t\n") 967 (skip-chars-backward " \t\n")
970 (python-nav-beginning-of-statement) 968 (python-nav-beginning-of-statement)
971 (point)))) 969 (cons
972 (when start 970 (cond ((python-info-current-line-comment-p)
973 (if (save-excursion 971 :after-comment)
974 (python-util-forward-comment -1) 972 ((save-excursion
975 (python-nav-beginning-of-statement) 973 (goto-char (line-end-position))
976 (looking-at (python-rx block-ender))) 974 (python-util-forward-comment -1)
977 (cons :after-block-end start) 975 (python-nav-beginning-of-statement)
978 (cons :after-line start))))) 976 (looking-at (python-rx block-ender)))
979 ;; Default case: do not indent. 977 :after-block-end)
980 (t (cons :no-indent 0)))))) 978 (t :after-line))
979 (point))))))))
981 980
982(defun python-indent--calculate-indentation () 981(defun python-indent--calculate-indentation ()
983 "Internal implementation of `python-indent-calculate-indentation'. 982 "Internal implementation of `python-indent-calculate-indentation'.
984May return an integer for the maximum possible indentation at 983May return an integer for the maximum possible indentation at
985current context or a list of integers. The latter case is only 984current context or a list of integers. The latter case is only
986happening for :at-dedenter-block-start context since the 985happening for :at-dedenter-block-start context since the
987possibilities can be narrowed to especific indentation points." 986possibilities can be narrowed to specific indentation points."
988 (save-restriction 987 (save-restriction
989 (widen) 988 (widen)
990 (save-excursion 989 (save-excursion
@@ -1075,7 +1074,7 @@ minimum."
1075(defun python-indent-line (&optional previous) 1074(defun python-indent-line (&optional previous)
1076 "Internal implementation of `python-indent-line-function'. 1075 "Internal implementation of `python-indent-line-function'.
1077Use the PREVIOUS level when argument is non-nil, otherwise indent 1076Use the PREVIOUS level when argument is non-nil, otherwise indent
1078to the maxium available level. When indentation is the minimum 1077to the maximum available level. When indentation is the minimum
1079possible and PREVIOUS is non-nil, cycle back to the maximum 1078possible and PREVIOUS is non-nil, cycle back to the maximum
1080level." 1079level."
1081 (let ((follow-indentation-p 1080 (let ((follow-indentation-p
@@ -1110,9 +1109,7 @@ indentation levels from right to left."
1110 (interactive "*") 1109 (interactive "*")
1111 (when (and (not (bolp)) 1110 (when (and (not (bolp))
1112 (not (python-syntax-comment-or-string-p)) 1111 (not (python-syntax-comment-or-string-p))
1113 (= (+ (line-beginning-position) 1112 (= (current-indentation) (current-column)))
1114 (current-indentation))
1115 (point)))
1116 (python-indent-line t) 1113 (python-indent-line t)
1117 t)) 1114 t))
1118 1115
@@ -2301,12 +2298,11 @@ Signals an error if no shell buffer is available for current buffer."
2301 2298
2302(defun python-shell-font-lock-kill-buffer () 2299(defun python-shell-font-lock-kill-buffer ()
2303 "Kill the font-lock buffer safely." 2300 "Kill the font-lock buffer safely."
2304 (python-shell-with-shell-buffer 2301 (when (and python-shell--font-lock-buffer
2305 (when (and python-shell--font-lock-buffer 2302 (buffer-live-p python-shell--font-lock-buffer))
2306 (buffer-live-p python-shell--font-lock-buffer)) 2303 (kill-buffer python-shell--font-lock-buffer)
2307 (kill-buffer python-shell--font-lock-buffer) 2304 (when (derived-mode-p 'inferior-python-mode)
2308 (when (derived-mode-p 'inferior-python-mode) 2305 (setq python-shell--font-lock-buffer nil))))
2309 (setq python-shell--font-lock-buffer nil)))))
2310 2306
2311(defmacro python-shell-font-lock-with-font-lock-buffer (&rest body) 2307(defmacro python-shell-font-lock-with-font-lock-buffer (&rest body)
2312 "Execute the forms in BODY in the font-lock buffer. 2308 "Execute the forms in BODY in the font-lock buffer.
@@ -2357,9 +2353,11 @@ goes wrong and syntax highlighting in the shell gets messed up."
2357(defun python-shell-font-lock-post-command-hook () 2353(defun python-shell-font-lock-post-command-hook ()
2358 "Fontifies current line in shell buffer." 2354 "Fontifies current line in shell buffer."
2359 (let ((prompt-end (cdr (python-util-comint-last-prompt)))) 2355 (let ((prompt-end (cdr (python-util-comint-last-prompt))))
2360 (when (and prompt-end (> (point) prompt-end)) 2356 (when (and prompt-end (> (point) prompt-end)
2357 (process-live-p (get-buffer-process (current-buffer))))
2361 (let* ((input (buffer-substring-no-properties 2358 (let* ((input (buffer-substring-no-properties
2362 prompt-end (point-max))) 2359 prompt-end (point-max)))
2360 (deactivate-mark nil)
2363 (start-pos prompt-end) 2361 (start-pos prompt-end)
2364 (buffer-undo-list t) 2362 (buffer-undo-list t)
2365 (font-lock-buffer-pos nil) 2363 (font-lock-buffer-pos nil)