Commit bbac1eb8 authored by Fabián Ezequiel Gallina's avatar Fabián Ezequiel Gallina Committed by Fabián Ezequiel Gallina
Browse files

python-indent-guess-indent-offset improvements

parent 183f9296
...@@ -402,24 +402,31 @@ These make `python-indent-calculate-indentation' subtract the value of ...@@ -402,24 +402,31 @@ These make `python-indent-calculate-indentation' subtract the value of
(defun python-indent-guess-indent-offset () (defun python-indent-guess-indent-offset ()
"Guess and set `python-indent-offset' for the current buffer." "Guess and set `python-indent-offset' for the current buffer."
(save-excursion (save-excursion
(let ((found-block)) (save-restriction
(while (and (not found-block) (widen)
(re-search-forward (goto-char (point-min))
(python-rx line-start block-start) nil t)) (let ((found-block))
(when (not (syntax-ppss-context (syntax-ppss))) (while (and (not found-block)
(setq found-block t))) (re-search-forward
(if (not found-block) (python-rx line-start block-start) nil t))
(message "Can't guess python-indent-offset, using defaults: %s" (when (and (not (syntax-ppss-context (syntax-ppss)))
python-indent-offset) (progn
(while (and (progn (goto-char (line-end-position))
(goto-char (line-end-position)) (forward-comment -1)
(python-info-continuation-line-p)) (eq ?: (char-before))))
(not (eobp))) (setq found-block t)))
(forward-line 1)) (if (not found-block)
(forward-line 1) (message "Can't guess python-indent-offset, using defaults: %s"
(forward-comment 1) python-indent-offset)
(setq python-indent-offset (current-indentation)))))) (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) (defun python-indent-context (&optional stop)
"Return information on indentation context. "Return information on indentation context.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment