diff options
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 27 |
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. |