From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andreas =?UTF-8?Q?R=C3=B6hler?= Newsgroups: gmane.emacs.bugs Subject: bug#21766: 25.0.50; delete-trailing-whitespace sometimes deletes non-whitespace Date: Tue, 27 Oct 2015 08:07:38 +0100 Message-ID: <562F22BA.3050103@easy-emacs.de> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="------------030608040407060300090508" X-Trace: ger.gmane.org 1445929704 8784 80.91.229.3 (27 Oct 2015 07:08:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 27 Oct 2015 07:08:24 +0000 (UTC) To: 21766@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Oct 27 08:08:12 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZqyMd-0006fA-5M for geb-bug-gnu-emacs@m.gmane.org; Tue, 27 Oct 2015 08:08:11 +0100 Original-Received: from localhost ([::1]:57842 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZqyMc-00070J-Ju for geb-bug-gnu-emacs@m.gmane.org; Tue, 27 Oct 2015 03:08:10 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41499) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZqyMX-00070E-UB for bug-gnu-emacs@gnu.org; Tue, 27 Oct 2015 03:08:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZqyMU-0005By-Jx for bug-gnu-emacs@gnu.org; Tue, 27 Oct 2015 03:08:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:49203) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZqyMU-0005Bu-Gd for bug-gnu-emacs@gnu.org; Tue, 27 Oct 2015 03:08:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1ZqyMU-00082N-1s for bug-gnu-emacs@gnu.org; Tue, 27 Oct 2015 03:08:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Andreas =?UTF-8?Q?R=C3=B6hler?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 27 Oct 2015 07:08:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 21766 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.144592964930854 (code B ref -1); Tue, 27 Oct 2015 07:08:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 27 Oct 2015 07:07:29 +0000 Original-Received: from localhost ([127.0.0.1]:39911 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZqyLw-00081Z-Hg for submit@debbugs.gnu.org; Tue, 27 Oct 2015 03:07:29 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:59585) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZqyLu-00081Q-Ls for submit@debbugs.gnu.org; Tue, 27 Oct 2015 03:07:27 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZqyLt-00057J-2u for submit@debbugs.gnu.org; Tue, 27 Oct 2015 03:07:26 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:44105) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZqyLs-00057F-Vf for submit@debbugs.gnu.org; Tue, 27 Oct 2015 03:07:24 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41353) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZqyLr-0006zR-Ox for bug-gnu-emacs@gnu.org; Tue, 27 Oct 2015 03:07:24 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZqyLo-00056t-FH for bug-gnu-emacs@gnu.org; Tue, 27 Oct 2015 03:07:23 -0400 Original-Received: from mout.kundenserver.de ([212.227.126.131]:61633) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZqyLo-00056o-5E for bug-gnu-emacs@gnu.org; Tue, 27 Oct 2015 03:07:20 -0400 Original-Received: from [192.168.178.31] ([77.6.197.144]) by mrelayeu.kundenserver.de (mreue002) with ESMTPSA (Nemesis) id 0LnGP8-1aQsw40SwY-00hblK for ; Tue, 27 Oct 2015 08:07:18 +0100 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.9) Gecko/20100915 Thunderbird/3.1.4 In-Reply-To: X-Provags-ID: V03:K0:OdjrnciVoZy7Au53RKZjb/qS6OqsqHY2IH30/bD8yC4ql+WKbj+ 3Nkkl4aDAgX0Cuc/0QV/LD2lzJnaXZteGdQDafybUZYJGh1uHe/AXM7JAaw7cCQ5OVaOgv6 KYuOevvD77i29VuUw31S/sWF8gkIyKeGvIjmsBBj5G2Z40XLZrHNv5OaiA1l+mjIrGDddJM iRW1mM5FMLP6Yh8rN7XIQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:J6TVg7OaZhs=:q5PooRh1FMklgDXS1ouM1z KCJNu0wQAsRFF3ehRr0UwtQJmLWQWi7JED25BH9B3UQVOJJ7usfG+3TeI1eHYRHySI/g8K2YF OvX6jWuCQqxNmw8KaOYV9zoXMWzKm37L0CW2FT/c41cd3Qtc1hx2ZKpG/0bk/0FtnBqSrxeUf McarGAVsJJzvpPepatG/LZlu/CbKq3RCvs0X3fZwn5r1yWV3hBM3mVPSiLWN3Mh8ldini0g6N WABIPCYWJAzcTgssJZX+OfhkobYZFUB6YrFCPSyY5ZMCN5Bl7E525upytZulsyefs2KeMdoZv pz43uPE7vIkODUMZV8UPiz2TVMadSRPJ17hRGigdyJaXIVxvc2ktyH1SWVJvhtscckMDKPP7l q9LCP7aLp/qA79PMSnUo9vVX9shqn/lNgl2ApFRkGqt5JJi7fc922vChEsFHBGy3vRIlVd6ye jn6UyQnVaRovL+xKtGjb3zZM8ANPE7UA5thFmAjC9xA0NmJtCo4B5wmYXPqc9omLftZxVag21 jzdglhQpvveyXMWSohTTaAF3etXRL7joeD+5JPgiYify4ADfDvJraFUPSwbGm1lQhGVRiCBWE LcirIDjysTth3ToKK+NaCU9i732bgY9y3EbhgQxjDjjFpz041KUqNuU9Qum+DIQbFGRg4/R/+ aBLnBXf8Uf2o3kuZtQbX4fR695W3jbvr86TrbOJmfA/tBse/deXA3zqlCyLleV4mNdB8TIm7e 3fvki1G5LL6effwX X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x 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-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:108057 Archived-At: This is a multi-part message in MIME format. --------------030608040407060300090508 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 27.10.2015 01:15, Juanma Barranquero wrote: > On Tue, Oct 27, 2015 at 12:07 AM, Markus Triska > 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 --------------030608040407060300090508 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit On 27.10.2015 01:15, Juanma Barranquero wrote:
On Tue, Oct 27, 2015 at 12:07 AM, Markus Triska <triska@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
--------------030608040407060300090508--