From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: npostavs@users.sourceforge.net Newsgroups: gmane.emacs.bugs Subject: bug#20774: auto-fill doesn't work properly when first-line prefix differs in adaptive-fill-mode Date: Mon, 28 Aug 2017 23:37:30 -0400 Message-ID: <87pobf82o5.fsf@users.sourceforge.net> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1503977773 21162 195.159.176.226 (29 Aug 2017 03:36:13 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 29 Aug 2017 03:36:13 +0000 (UTC) To: Samuel Freilich , 20774@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Aug 29 05:36:07 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dmXJt-00059q-E2 for geb-bug-gnu-emacs@m.gmane.org; Tue, 29 Aug 2017 05:36:05 +0200 Original-Received: from localhost ([::1]:42616 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dmXK0-00081M-17 for geb-bug-gnu-emacs@m.gmane.org; Mon, 28 Aug 2017 23:36:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39159) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dmXJt-000819-Tw for bug-gnu-emacs@gnu.org; Mon, 28 Aug 2017 23:36:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dmXJq-0006OZ-NL for bug-gnu-emacs@gnu.org; Mon, 28 Aug 2017 23:36:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:51206) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dmXJq-0006OQ-Fi for bug-gnu-emacs@gnu.org; Mon, 28 Aug 2017 23:36:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dmXJq-0006VJ-5t for bug-gnu-emacs@gnu.org; Mon, 28 Aug 2017 23:36:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: Resent-From: npostavs@users.sourceforge.net Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 29 Aug 2017 03:36:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 20774 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 20774-submit@debbugs.gnu.org id=B20774.150397775724990 (code B ref 20774); Tue, 29 Aug 2017 03:36:02 +0000 Original-Received: (at 20774) by debbugs.gnu.org; 29 Aug 2017 03:35:57 +0000 Original-Received: from localhost ([127.0.0.1]:59887 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dmXJl-0006V0-FD for submit@debbugs.gnu.org; Mon, 28 Aug 2017 23:35:57 -0400 Original-Received: from mail-io0-f178.google.com ([209.85.223.178]:35913) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dmXJk-0006Uo-D0 for 20774@debbugs.gnu.org; Mon, 28 Aug 2017 23:35:56 -0400 Original-Received: by mail-io0-f178.google.com with SMTP id g33so7793772ioj.3 for <20774@debbugs.gnu.org>; Mon, 28 Aug 2017 20:35:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:mime-version; bh=Ldz2X9JhSUFQrlPVjSZ7dAsRkwQD14kBJ2nsV2lPvVU=; b=JEqRzgV+MgwKQrPv/KkilthIfkI3Kx+Cib9bS1tel4eKrtPj14i0TreJSIjxvQnvwL pmqEiFIP3A0gv0tc6a1UFN60Li+UnyLL932Mig+rSs0vz0Svbi4bMrLC/m4WxPAiH5LS nX3U8gRxUFKXAkNgGAR4uHg+ZOdoYHy+InviCtnFDEmeCtmLtnZI7y9Evqc/sV+uXCWv muf7iJWLdPkiLXpMCE99WqMXVlShUHiQzMTdF/u81HAJc8/npcFZjzwVkbJYSSUoz63F vFua69g/Pg7iwBoQQvoqvHw4GesDjeBivxnjHhfL9v4/wcWZ0Ns1qeBv5Nd5y5o6pBut zX9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :mime-version; bh=Ldz2X9JhSUFQrlPVjSZ7dAsRkwQD14kBJ2nsV2lPvVU=; b=CxjXWGjTmstIwDXfxCnsDGhsSL1etSMYEO2K5gBVXxhZ3DkMUlzHUz9OaE9vVW8hUs cBYkN15mfKZ6g04oxXyldINyTQKTNL23RYxDwhrlCLLlZEN42TPUh/far3LVC6LzZgLb 5iyJnQDEBfHf0R4+jo4+Js03f3phezGRYPh5gWwxhIwOzth++AEeFJVlZBvuLtDp2iKq FqJMLBcyX1yoa1LYBaiY8mzAJ2bJIslIAL2FcQVAj08TRzuNZEUGHK84wtSHANX1QkLG 7i5WaqcxkjvOSjUvY+KrkUQFDwAu1G74J+ZgVYLgECxEypFrS2tVFDc1YtcnSB2iEbUV Qj3A== X-Gm-Message-State: AHYfb5iq9m5RBF+K0rl6rv+OW8rXjsGIYYfghlxjG+KTWN5JjX1APiJQ WEXqHZaXdvDsaihp X-Received: by 10.107.136.229 with SMTP id s98mr2497718ioi.323.1503977750652; Mon, 28 Aug 2017 20:35:50 -0700 (PDT) Original-Received: from zony ([45.2.119.49]) by smtp.googlemail.com with ESMTPSA id f25sm906065ioj.36.2017.08.28.20.35.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Aug 2017 20:35:49 -0700 (PDT) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:136312 Archived-At: --=-=-= Content-Type: text/plain [forwarding to bug list] --=-=-= Content-Type: message/rfc822 Content-Disposition: inline Received: by 10.58.43.76 with HTTP; Mon, 28 Aug 2017 19:06:23 -0700 (PDT) In-Reply-To: <87fucga09e.fsf@users.sourceforge.net> References: <878tibbwcv.fsf@users.sourceforge.net> <87wp5v9bsp.fsf@users.sourceforge.net> <87r2w1aew4.fsf@users.sourceforge.net> <87fucga09e.fsf@users.sourceforge.net> From: Samuel Freilich Date: Mon, 28 Aug 2017 22:06:23 -0400 Message-ID: Subject: Re: bug#20774: auto-fill doesn't work properly when first-line prefix differs in adaptive-fill-mode To: npostavs@users.sourceforge.net MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=====-=-=" --=====-=-= Content-Type: multipart/alternative; boundary="======-=-=" --======-=-= Content-Type: text/plain; charset=utf-8 Content-Disposition: inline wrote: > Actually, it's now occuring to me that adding a position to a > string-width isn't quite correct either Ah right, (point) is in characters, which doesn't correspond directly to columns at all. I think I can avoid the extra save-excursion and make it a little cleaner as a result. > there should be 2 spaces after the period Heresy! :-P But done. That does seem to be the most common style in the ChangeLog. Please take another look. Hopefully this patch can be merged. --======-=-= Content-Type: text/x-patch; name=0003-Do-not-split-line-before-width-of-fill-prefix.patch Content-Disposition: attachment; filename=0003-Do-not-split-line-before-width-of-fill-prefix.patch >From 118c8a43510a7d3020a552ce0e87e5a1b9ccec54 Mon Sep 17 00:00:00 2001 From: Samuel Freilich Date: Wed, 23 Aug 2017 13:40:45 -0400 Subject: [PATCH] Do not split line before width of fill-prefix When auto-filling a paragraph, don't split a line before the width of the fill-prefix, creating a subsequent line that is as long or longer (Bug#20774). * lisp/simple.el (do-auto-fill): Only consider break-points that are later in the line than the width of the fill-prefix. This is a more general solution than the previous logic, which only skipped over the exact fill-prefix. The fill-prefix doesn't necessarily match the prefix of the first line of a paragraph in adaptive-fill-mode. --- lisp/simple.el | 27 ++++++++++++--------------- test/lisp/simple-tests.el | 11 +++++++++++ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/lisp/simple.el b/lisp/simple.el index 13cfa3487d..27990bb661 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -7151,18 +7151,18 @@ do-auto-fill (setq fill-prefix prefix)))) (while (and (not give-up) (> (current-column) fc)) - ;; Determine where to split the line. - (let* (after-prefix - (fill-point - (save-excursion - (beginning-of-line) - (setq after-prefix (point)) - (and fill-prefix - (looking-at (regexp-quote fill-prefix)) - (setq after-prefix (match-end 0))) - (move-to-column (1+ fc)) - (fill-move-to-break-point after-prefix) - (point)))) + ;; Determine where to split the line. + (let ((fill-point + (save-excursion + (beginning-of-line) + ;; Don't split earlier in the line than the length of the + ;; fill prefix, since the resulting line would be longer. + (when fill-prefix + (move-to-column (string-width fill-prefix))) + (let ((after-prefix (point))) + (move-to-column (1+ fc)) + (fill-move-to-break-point after-prefix) + (point))))) ;; See whether the place we found is any good. (if (save-excursion @@ -7170,9 +7170,6 @@ do-auto-fill (or (bolp) ;; There is no use breaking at end of line. (save-excursion (skip-chars-forward " ") (eolp)) - ;; It is futile to split at the end of the prefix - ;; since we would just insert the prefix again. - (and after-prefix (<= (point) after-prefix)) ;; Don't split right after a comment starter ;; since we would just make another comment starter. (and comment-start-skip diff --git a/test/lisp/simple-tests.el b/test/lisp/simple-tests.el index ad7aee1db1..c7330e4034 100644 --- a/test/lisp/simple-tests.el +++ b/test/lisp/simple-tests.el @@ -497,5 +497,16 @@ simple-test-undo-with-switched-buffer (should (equal (line-number-at-pos 5) 3)) (should (equal (line-number-at-pos 7) 4))))) +(ert-deftest auto-fill-mode-no-break-before-length-of-fill-prefix () + (with-temp-buffer + (setq-local fill-prefix " ") + (set-fill-column 5) + ;; Shouldn't break after 'foo' (3 characters) when the next + ;; line is indented >= to that, that woudln't result in shorter + ;; lines. + (insert "foo bar") + (do-auto-fill) + (should (string-equal (buffer-string) "foo bar")))) + (provide 'simple-test) ;;; simple-test.el ends here -- 2.14.1.342.g6490525c54-goog --======-=-=-- --=====-=-=-- --=-=-=--