aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabián Ezequiel Gallina2012-05-17 00:02:54 -0300
committerFabián Ezequiel Gallina2012-05-17 00:02:54 -0300
commitbbac1eb8aba7459dc90e1f8bb21e603d16779077 (patch)
tree5f4cda5495a8d4a74c8b66abc78d207d60a47b0b
parent183f9296f1cf873b5aef9253f0def74e5d6d513e (diff)
downloademacs-bbac1eb8aba7459dc90e1f8bb21e603d16779077.tar.gz
emacs-bbac1eb8aba7459dc90e1f8bb21e603d16779077.zip
python-indent-guess-indent-offset improvements
-rw-r--r--lisp/progmodes/python.el43
1 files changed, 25 insertions, 18 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 26b13afe2ed..e4019373362 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -402,24 +402,31 @@ These make `python-indent-calculate-indentation' subtract the value of
402 402
403(defun python-indent-guess-indent-offset () 403(defun python-indent-guess-indent-offset ()
404 "Guess and set `python-indent-offset' for the current buffer." 404 "Guess and set `python-indent-offset' for the current buffer."
405 (save-excursion 405 (save-excursion
406 (let ((found-block)) 406 (save-restriction
407 (while (and (not found-block) 407 (widen)
408 (re-search-forward 408 (goto-char (point-min))
409 (python-rx line-start block-start) nil t)) 409 (let ((found-block))
410 (when (not (syntax-ppss-context (syntax-ppss))) 410 (while (and (not found-block)
411 (setq found-block t))) 411 (re-search-forward
412 (if (not found-block) 412 (python-rx line-start block-start) nil t))
413 (message "Can't guess python-indent-offset, using defaults: %s" 413 (when (and (not (syntax-ppss-context (syntax-ppss)))
414 python-indent-offset) 414 (progn
415 (while (and (progn 415 (goto-char (line-end-position))
416 (goto-char (line-end-position)) 416 (forward-comment -1)
417 (python-info-continuation-line-p)) 417 (eq ?: (char-before))))
418 (not (eobp))) 418 (setq found-block t)))
419 (forward-line 1)) 419 (if (not found-block)
420 (forward-line 1) 420 (message "Can't guess python-indent-offset, using defaults: %s"
421 (forward-comment 1) 421 python-indent-offset)
422 (setq python-indent-offset (current-indentation)))))) 422 (while (and (progn
423 (goto-char (line-end-position))
424 (python-info-continuation-line-p))
425 (not (eobp)))
426 (forward-line 1))
427 (forward-line 1)
428 (forward-comment 1)
429 (setq python-indent-offset (current-indentation)))))))
423 430
424(defun python-indent-context (&optional stop) 431(defun python-indent-context (&optional stop)
425 "Return information on indentation context. 432 "Return information on indentation context.