unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Noam Postavsky <npostavs@gmail.com>
To: Dima Kogan <dima@secretsauce.net>
Cc: 36056@debbugs.gnu.org
Subject: bug#36056: Regression? (Python Documentation String Indent In Auto Fill Mode)
Date: Sun, 08 Sep 2019 10:46:40 -0400	[thread overview]
Message-ID: <87zhjealrj.fsf_-_@gmail.com> (raw)
In-Reply-To: <878sqzztlc.fsf@secretsauce.net> (Dima Kogan's message of "Sat, 07 Sep 2019 14:26:07 -0700")

[-- Attachment #1: Type: text/plain, Size: 852 bytes --]

Dima Kogan <dima@secretsauce.net> writes:

> This is what I'd expect. After the fix (i.e. if
> fill-indent-according-to-mode is t) I get this:
>
>
> 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
>
> '''
>
>
> For some reason it now wants to add one space at the beginning of every
> line in a paragraph except the first. Is there some interpretation where
> this the "correct" behavior?

Thanks for reporting this.  The problem seems to be that fill-newline
puts the space on the new line when breaking the line, and
python-indent-line (which is called when fill-indent-according-to-mode
is t) leaves indentation inside strings as-is.

Maybe the solution is to bind fill-indent-according-to-mode only during
auto-filling?  The patch below seems to work for both this bug's OP, and
your case.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 2495 bytes --]

From 46a01b97025ed2f826af4237044bad5262e06c6a Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
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)))
+
 \f
 ;;; 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)))))
 
 \f
-;;; 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))))
+
 \f
 ;;; Mark
 
-- 
2.11.0


  reply	other threads:[~2019-09-08 14:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-02  9:01 bug#36056: 26.2; Python Documentation String Indent In Auto Fill Mode ricercar
2019-06-03  0:57 ` Basil L. Contovounesios
2019-06-22 23:31   ` Noam Postavsky
2019-09-07 21:26 ` bug#36056: Regression? Dima Kogan
2019-09-08 14:46   ` Noam Postavsky [this message]
2019-09-09 22:02     ` bug#36056: Regression? (Python Documentation String Indent In Auto Fill Mode) Dima Kogan
2019-09-13  1:49       ` Noam Postavsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zhjealrj.fsf_-_@gmail.com \
    --to=npostavs@gmail.com \
    --cc=36056@debbugs.gnu.org \
    --cc=dima@secretsauce.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).