unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Reuben Thomas <rrt@sc3d.org>
To: Noam Postavsky <npostavs@users.sourceforge.net>
Cc: Mark Karpov <markkarpov@openmailbox.org>, 25157@debbugs.gnu.org
Subject: bug#25157: 26.0.50; whitespace-cleanup does not remove single trailing empty line anymore
Date: Tue, 20 Dec 2016 18:37:29 +0000	[thread overview]
Message-ID: <CAOnWdoj=icjFZPDSYN494E1U59iKq_AD4O2J5pe5is9mZ7=UuA@mail.gmail.com> (raw)
In-Reply-To: <87eg13b4jk.fsf@users.sourceforge.net>

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

On 20 December 2016 at 04:36, <npostavs@users.sourceforge.net> wrote:

> tags 25157 confirmed
> quit
>
> Mark Karpov <markkarpov@openmailbox.org> writes:
>
> > The ‘whitespace-cleanup’ command does not remove single trailing empty
> > line anymore.
>

​​I can reproduce this; sorry!


> -(defcustom whitespace-empty-at-eob-regexp "^\\([ \t\n]+\\)"
> +(defcustom whitespace-empty-at-eob-regexp "^\\([ \t\n]*\\(\n\\{2,\\}\\|[
> \t]+\\)\\)\\'"
>
> I don't quite understand why this more complicated expression is
> necessary.  Reuben, can you explain?
>

​With the previous regexp, whitespace-cleanup would remove a single newline
at the end of a buffer.

I think I tried to be a bit too clever.

Thinking again, what we require is:

Match at the end of the buffer, either:

a. A mix of spaces and tabs, or

b. Optional whitespace followed by a newline followed by whitespace.

These two categories are not mutually exclusive (which is fine, and avoids
being too clever).

The point is that if there are any newlines, there must be at least two.

Also note that the regexp does not need to be anchored at the start of a
line (I'm not sure why I thought it did).

So, I think a correct regexp, directly translating the above, is: \\([
\t]+\\|\\([ \t\n]*\n[ \t\n]+\\)\\)\\'

However, there's still a problem: while this regexp will not match a single
newline at the end of a buffer, when it does match any number of newlines
(with or without extra space), it will remove all of them, whereas it
should leave a single newline.

I can't see a way around this purely in the regexp, because if for example
the end of the buffer is:

\t\n\t

then the regexp should match (and this one does), but whitespace-cleanup
should leave a newline.

So I think a further change to the code is needed to whitespace-cleanup:
when whitespace-empty-at-eob-regexp is matched, it should check
match-string, and if it contains a newline, it should insert a newline in
the buffer after deleting the matched string.

Given my previous error of reasoning, I'm submitting the above for your
consideration before I prepare a patch!

-- 
http://rrt.sc3d.org

[-- Attachment #2: Type: text/html, Size: 4862 bytes --]

  reply	other threads:[~2016-12-20 18:37 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-10 14:41 bug#25157: 26.0.50; whitespace-cleanup does not remove single trailing empty line anymore Mark Karpov
2016-12-20  4:36 ` npostavs
2016-12-20 18:37   ` Reuben Thomas [this message]
2016-12-21  0:51     ` Reuben Thomas
2016-12-21  4:07     ` npostavs
2016-12-21 11:07       ` Reuben Thomas
2016-12-22  2:18         ` npostavs
2016-12-22 12:53           ` Reuben Thomas
2016-12-23  0:03             ` npostavs
2016-12-23 10:44               ` Reuben Thomas
2016-12-24 15:34                 ` npostavs
2016-12-26 22:37                   ` Reuben Thomas

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='CAOnWdoj=icjFZPDSYN494E1U59iKq_AD4O2J5pe5is9mZ7=UuA@mail.gmail.com' \
    --to=rrt@sc3d.org \
    --cc=25157@debbugs.gnu.org \
    --cc=markkarpov@openmailbox.org \
    --cc=npostavs@users.sourceforge.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).