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