aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorFabián Ezequiel Gallina2012-05-17 00:02:53 -0300
committerFabián Ezequiel Gallina2012-05-17 00:02:53 -0300
commit954aa7bdb84f2b84d3ad3c248712c09a710582fa (patch)
treea350ecf6b8bd9533bf15f3f30ff5c74a6d2490d5 /lisp
parent79dafa51ba09e8a5fc8f48b23b440388dd3596e8 (diff)
downloademacs-954aa7bdb84f2b84d3ad3c248712c09a710582fa.tar.gz
emacs-954aa7bdb84f2b84d3ad3c248712c09a710582fa.zip
Enhanced python-indent-guess-indent-offset logic.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/progmodes/python.el27
1 files changed, 19 insertions, 8 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 37a4d029c0f..abe92dd43dd 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -401,14 +401,25 @@ These make `python-indent-calculate-indentation' subtract the value of
401`python-indent-offset'.") 401`python-indent-offset'.")
402 402
403(defun python-indent-guess-indent-offset () 403(defun python-indent-guess-indent-offset ()
404 "Guess and set the value for `python-indent-offset' given the current buffer." 404 "Guess and set `python-indent-offset' for the current buffer."
405 (let ((guessed-indentation (save-excursion 405 (save-excursion
406 (goto-char (point-min)) 406 (let ((found-block))
407 (re-search-forward ":\\s-*\n" nil t) 407 (while (and (not found-block)
408 (while (and (not (eobp)) (forward-comment 1))) 408 (re-search-forward
409 (current-indentation)))) 409 (python-rx line-start block-start) nil t))
410 (when (not (equal guessed-indentation 0)) 410 (when (not (syntax-ppss-context (syntax-ppss)))
411 (setq python-indent-offset guessed-indentation)))) 411 (setq found-block t)))
412 (if (not found-block)
413 (message "Can't guess python-indent-offset, using defaults: %s"
414 python-indent-offset)
415 (while (and (progn
416 (goto-char (line-end-position))
417 (python-info-continuation-line-p))
418 (not (eobp)))
419 (forward-line 1))
420 (forward-line 1)
421 (forward-comment 1)
422 (setq python-indent-offset (current-indentation))))))
412 423
413(defun python-indent-context (&optional stop) 424(defun python-indent-context (&optional stop)
414 "Return information on indentation context. 425 "Return information on indentation context.