summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeneb Meketa <deneb@pixar.com>2021-05-27 01:21:59 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2021-05-27 01:21:59 +0200
commit7f11dea66298c2c9aeccab2b542ee8e73346f09f (patch)
treee21f734f54f16669b2339da6b08db55252f94c11
parent0dfe193ec42160bfaa30933c5ebfa7ae91cde88b (diff)
downloademacs-7f11dea66298c2c9aeccab2b542ee8e73346f09f.tar.gz
Fix filling of overlong first lines in Python doc strings
* lisp/progmodes/python.el (python-fill-string): Fill overlong first lines correctly (bug#20860). Copyright-paperwork-exempt: yes
-rw-r--r--lisp/progmodes/python.el7
-rw-r--r--test/lisp/progmodes/python-tests.el24
2 files changed, 30 insertions, 1 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 20ec339fffb..f7267bdef29 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -4239,6 +4239,11 @@ JUSTIFY should be used (if applicable) as in `fill-paragraph'."
(point)))))
(num-quotes (python-syntax-count-quotes
(char-after str-start-pos) str-start-pos))
+ (str-line-start-pos
+ (save-excursion
+ (goto-char str-start-pos)
+ (beginning-of-line)
+ (point-marker)))
(str-end-pos
(save-excursion
(goto-char (+ str-start-pos num-quotes))
@@ -4262,7 +4267,7 @@ JUSTIFY should be used (if applicable) as in `fill-paragraph'."
('symmetric (and multi-line-p (cons 1 1)))))
(fill-paragraph-function))
(save-restriction
- (narrow-to-region str-start-pos str-end-pos)
+ (narrow-to-region str-line-start-pos str-end-pos)
(fill-paragraph justify))
(save-excursion
(when (and (python-info-docstring-p) python-fill-docstring-style)
diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el
index 3e653cb568a..1af579bb7a4 100644
--- a/test/lisp/progmodes/python-tests.el
+++ b/test/lisp/progmodes/python-tests.el
@@ -5432,6 +5432,30 @@ buffer with overlapping strings."
(run-python nil nil 'show)
(should (eq buffer (current-buffer)))))
+(ert-deftest python-tests--fill-long-first-line ()
+ (should
+ (equal
+ (with-temp-buffer
+ (insert "def asdf():
+ \"\"\"123 123 123 123 123 123 123 123 123 123 123 123 123 SHOULDBEWRAPPED 123 123 123 123
+
+ \"\"\"
+ a = 1
+")
+ (python-mode)
+ (goto-char (point-min))
+ (forward-line 1)
+ (end-of-line)
+ (fill-paragraph)
+ (buffer-substring-no-properties (point-min) (point-max)))
+ "def asdf():
+ \"\"\"123 123 123 123 123 123 123 123 123 123 123 123 123
+ SHOULDBEWRAPPED 123 123 123 123
+
+ \"\"\"
+ a = 1
+")))
+
(provide 'python-tests)
;; Local Variables: