all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Deneb Meketa <deneb@pixar.com>
To: 20860@debbugs.gnu.org
Subject: bug#20860: python.el's fill-paragraph incorrectly handles doc-strings with long first lines
Date: Mon, 19 Apr 2021 17:12:24 -0700	[thread overview]
Message-ID: <CABLivvTOt8T7ODr3s6exbi9BRKB8PO1Zo9iA7zLPMMsuyZMXOw@mail.gmail.com> (raw)
In-Reply-To: <CAE3SAJWNur4W-OvjbgiLEock=YX1LoezNUBhoJufcHfC_WpEKg@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 816 bytes --]

Attached please find a patch for consideration.

I also ran into this issue, and found this fix.  When we narrow to perform
the main fill, we need to preserve the entire first line.  Otherwise the
fill operation won't see the beginning of the first line; it will think
that line begins at the opening quote, and thus will allow the first line
to be longer than it should.

I have tested this in 26.1 with docstrings and ordinary strings, single and
triple quotes, auto-fill and fill-paragraph, docstring styles pep-257 and
django.  As far as I can tell, this function has not changed since 26.1.

Proposed commit message:

Python: fix overlong first line in string fill.

When we narrow to perform filling, make sure to include the entire first
line in
the narrowed view.  Otherwise the fill doesn't work correctly.

[-- Attachment #1.2: Type: text/html, Size: 1003 bytes --]

[-- Attachment #2: emacs-bug20860.patch --]
[-- Type: text/x-patch, Size: 1956 bytes --]

--- python.OLD.el	2021-04-19 16:18:39.840528000 -0700
+++ python.NEW.el	2021-04-19 16:22:37.874439000 -0700
@@ -3945,16 +3945,21 @@ (defun python-fill-string (&optional jus
           (set-marker
            (make-marker)
            (or (python-syntax-context 'string)
                (and (equal (string-to-syntax "|")
                            (syntax-after (point)))
                     (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))
             (or (re-search-forward (rx (syntax string-delimiter)) nil t)
                 (goto-char (point-max)))
             (point-marker)))
          (multi-line-p
           ;; Docstring styles may vary for oneliners and multi-liners.
@@ -3968,17 +3973,17 @@ (defun python-fill-string (&optional jus
             ;; graphic idea of each style.
             (`django (cons 1 1))
             (`onetwo (and multi-line-p (cons 1 2)))
             (`pep-257 (and multi-line-p (cons nil 2)))
             (`pep-257-nn (and multi-line-p (cons nil 1)))
             (`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)
         ;; Add the number of newlines indicated by the selected style
         ;; at the start of the docstring.
         (goto-char (+ str-start-pos num-quotes))
         (delete-region (point) (progn
                                  (skip-syntax-forward "> ")

  parent reply	other threads:[~2021-04-20  0:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-20 16:51 bug#20860: 24.4; python.el's fill-paragraph incorrectly handles doc-strings with long first lines Topher Brown
2015-09-08 10:37 ` Tobias Getzner
2021-04-20  0:12 ` Deneb Meketa [this message]
2021-05-26 23:22   ` Lars Ingebrigtsen

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

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

  git send-email \
    --in-reply-to=CABLivvTOt8T7ODr3s6exbi9BRKB8PO1Zo9iA7zLPMMsuyZMXOw@mail.gmail.com \
    --to=deneb@pixar.com \
    --cc=20860@debbugs.gnu.org \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.