]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix fill-paragraph in python docstrings (Bug#36056)
authorNoam Postavsky <npostavs@gmail.com>
Sun, 8 Sep 2019 14:42:19 +0000 (10:42 -0400)
committerNoam Postavsky <npostavs@gmail.com>
Fri, 13 Sep 2019 00:25:30 +0000 (20:25 -0400)
* 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
test/lisp/progmodes/python-tests.el

index 14b65669c4ba1614155391d50544db512c9e944d..ec5d8c555128209791b3b75cab3048c2168ee794 100644 (file)
@@ -4084,6 +4084,12 @@ JUSTIFY should be used (if applicable) as in `fill-paragraph'."
       (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)))
+
 \f
 ;;; Skeletons
 
@@ -5379,7 +5385,7 @@ REPORT-FN is Flymake's callback function."
   (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)
index b1cf7e8806a522e26e41b5c97dfd2f392099cfdc..c5ad1dfb86236acdccffe6b1de07903b8b8c4c62 100644 (file)
@@ -1351,7 +1351,7 @@ this is an arbitrarily
                       expected)))))
 
 \f
-;;; Autofill
+;;; Filling
 
 (ert-deftest python-auto-fill-docstring ()
   (python-tests-with-temp-buffer
@@ -1368,6 +1368,17 @@ def some_function(arg1,
      (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))))
+
 \f
 ;;; Mark