GNU bug report logs - #21766
25.0.50; delete-trailing-whitespace sometimes deletes non-whitespace

Previous Next

Package: emacs;

Reported by: Markus Triska <triska <at> metalevel.at>

Date: Mon, 26 Oct 2015 23:10:01 UTC

Severity: normal

Merged with 21769

Found in version 25.0.50

Done: Juanma Barranquero <lekktu <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Andreas Röhler <andreas.roehler <at> easy-emacs.de>
To: 21766 <at> debbugs.gnu.org
Subject: bug#21766: 25.0.50; delete-trailing-whitespace sometimes deletes non-whitespace
Date: Tue, 27 Oct 2015 08:07:38 +0100
[Message part 1 (text/plain, inline)]
 On 27.10.2015 01:15, Juanma Barranquero wrote:
> On Tue, Oct 27, 2015 at 12:07 AM, Markus Triska <triska <at> metalevel.at 
> <mailto:triska <at> metalevel.at>> wrote:
> >
> >
> > Steps to reproduce:
> >
> > 1) wget http://www.metalevel.at/ei/fault1.html
> >
> > 2) emacs -Q fault1.html
> >
> > 3) M-x delete-trailing-whitespace RET
> >
> > This removes several non-white-space characters, including the whole
> > line containing "and use it like" (line 83 in the original file),
>
> Apparently, the call to skip-syntax-backward is altering the match 
> data. If you try this
>
> --- a/lisp/simple.el
> +++ b/lisp/simple.el
> @@ -609,7 +609,7 @@ delete-trailing-whitespace
>              (start (or start (point-min))))
>          (goto-char start)
>          (while (re-search-forward "\\s-$" end-marker t)
> -          (skip-syntax-backward "-" (line-beginning-position))
> +          (save-match-data (skip-syntax-backward "-" 
> (line-beginning-position)))
>            ;; Don't delete formfeeds, even if they are considered 
> whitespace.
>            (if (looking-at-p ".*\f")
>                (goto-char (match-end 0)))
>
>
> or, alternatively,
>
> @@ -609,11 +609,12 @@ delete-trailing-whitespace
>              (start (or start (point-min))))
>          (goto-char start)
>          (while (re-search-forward "\\s-$" end-marker t)
> -          (skip-syntax-backward "-" (line-beginning-position))
> -          ;; Don't delete formfeeds, even if they are considered 
> whitespace.
> -          (if (looking-at-p ".*\f")
> -              (goto-char (match-end 0)))
> -          (delete-region (point) (match-end 0)))
> +          (let ((end (match-end 0)))
> +            (skip-syntax-backward "-" (line-beginning-position))
> +            ;; Don't delete formfeeds, even if they are considered 
> whitespace.
> +            (if (looking-at-p ".*\f")
> +                (goto-char end))
> +            (delete-region (point) end)))
>          ;; Delete trailing empty lines.
>          (goto-char end-marker)
>          (when (and (not end)
>
> it works.

First fix looks cleaner.

> Now, the question is, should skip-syntax-backward preserve the match 
> data, or must delete-trailing-whitespace be coded defensively? The 
> usual policy has been that code that needs the match data preserved 
> should make sure itself that it is so.

Such a basic routine should preserve matches by its own virtue.

A couple of regression tests should pay here.

Thanks
[Message part 2 (text/html, inline)]

This bug report was last modified 9 years and 210 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.