diff options
| author | Fabián Ezequiel Gallina <fgallina@cuca> | 2012-05-17 00:02:54 -0300 |
|---|---|---|
| committer | Fabián Ezequiel Gallina <fgallina@gnu.org> | 2012-05-17 00:02:54 -0300 |
| commit | bbac1eb8aba7459dc90e1f8bb21e603d16779077 (patch) | |
| tree | 5f4cda5495a8d4a74c8b66abc78d207d60a47b0b /lisp/progmodes/python.el | |
| parent | 183f9296f1cf873b5aef9253f0def74e5d6d513e (diff) | |
python-indent-guess-indent-offset improvements
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 (defun python-indent-guess-indent-offset () "Guess and set `python-indent-offset' for the current buffer." - (save-excursion - (let ((found-block)) - (while (and (not found-block) - (re-search-forward - (python-rx line-start block-start) nil t)) - (when (not (syntax-ppss-context (syntax-ppss))) - (setq found-block t))) - (if (not found-block) - (message "Can't guess python-indent-offset, using defaults: %s" - python-indent-offset) - (while (and (progn - (goto-char (line-end-position)) - (python-info-continuation-line-p)) - (not (eobp))) - (forward-line 1)) - (forward-line 1) - (forward-comment 1) - (setq python-indent-offset (current-indentation)))))) + (save-excursion + (save-restriction + (widen) + (goto-char (point-min)) + (let ((found-block)) + (while (and (not found-block) + (re-search-forward + (python-rx line-start block-start) nil t)) + (when (and (not (syntax-ppss-context (syntax-ppss))) + (progn + (goto-char (line-end-position)) + (forward-comment -1) + (eq ?: (char-before)))) + (setq found-block t))) + (if (not found-block) + (message "Can't guess python-indent-offset, using defaults: %s" + python-indent-offset) + (while (and (progn + (goto-char (line-end-position)) + (python-info-continuation-line-p)) + (not (eobp))) + (forward-line 1)) + (forward-line 1) + (forward-comment 1) + (setq python-indent-offset (current-indentation))))))) (defun python-indent-context (&optional stop) "Return information on indentation context. |
