From 46a01b97025ed2f826af4237044bad5262e06c6a Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sun, 8 Sep 2019 10:42:19 -0400 Subject: [PATCH] Fix fill-paragraph in python docstrings (Bug#36056) * lisp/progmodes/python.el (python-do-auto-fill): New function. (python-mode): Set it as normal-auto-fill-function, and don't set fill-indent-according-to-mode. Having the latter set during fill-paragraph gives wrongs result, because python-indent-line doesn't remove indentation added by filling. * test/lisp/progmodes/python-tests.el (python-fill-docstring): New test. --- lisp/progmodes/python.el | 8 +++++++- test/lisp/progmodes/python-tests.el | 13 ++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 14b65669c4..ec5d8c5551 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -4084,6 +4084,12 @@ python-fill-paren (goto-char (line-end-position)))) t) +(defun python-do-auto-fill () + "Like `do-auto-fill', but bind `fill-indent-according-to-mode'." + ;; See Bug#36056. + (let ((fill-indent-according-to-mode t)) + (do-auto-fill))) + ;;; Skeletons @@ -5379,7 +5385,7 @@ python-mode (set (make-local-variable 'paragraph-start) "\\s-*$") (set (make-local-variable 'fill-paragraph-function) #'python-fill-paragraph) - (set (make-local-variable 'fill-indent-according-to-mode) t) ; Bug#36056. + (set (make-local-variable 'normal-auto-fill-function) #'python-do-auto-fill) (set (make-local-variable 'beginning-of-defun-function) #'python-nav-beginning-of-defun) diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index b1cf7e8806..c5ad1dfb86 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el @@ -1351,7 +1351,7 @@ python-indent-region-5 expected))))) -;;; Autofill +;;; Filling (ert-deftest python-auto-fill-docstring () (python-tests-with-temp-buffer @@ -1368,6 +1368,17 @@ python-auto-fill-docstring (forward-line 1) (should (= docindent (current-indentation)))))) +(ert-deftest python-fill-docstring () + (python-tests-with-temp-buffer + "\ +r'''aaa + +this is a test this is a test this is a test this is a test this is a test this is a test. +'''" + (search-forward "test.") + (fill-paragraph) + (should (= (current-indentation) 0)))) + ;;; Mark -- 2.11.0