From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juanma Barranquero Newsgroups: gmane.emacs.bugs Subject: bug#21766: 25.0.50; delete-trailing-whitespace sometimes deletes non-whitespace Date: Tue, 27 Oct 2015 01:15:18 +0100 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a11c3ba826c9e4f05230afb1e X-Trace: ger.gmane.org 1445905044 12123 80.91.229.3 (27 Oct 2015 00:17:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 27 Oct 2015 00:17:24 +0000 (UTC) Cc: 21766@debbugs.gnu.org To: Markus Triska Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Oct 27 01:17:14 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 1Zqrwu-0006mO-7Q for geb-bug-gnu-emacs@m.gmane.org; Tue, 27 Oct 2015 01:17:12 +0100 Original-Received: from localhost ([::1]:56017 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zqrwt-00089L-O4 for geb-bug-gnu-emacs@m.gmane.org; Mon, 26 Oct 2015 20:17:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33791) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zqrwp-000893-H9 for bug-gnu-emacs@gnu.org; Mon, 26 Oct 2015 20:17:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zqrwl-0007yf-AE for bug-gnu-emacs@gnu.org; Mon, 26 Oct 2015 20:17:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:48809) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zqrwl-0007yZ-60 for bug-gnu-emacs@gnu.org; Mon, 26 Oct 2015 20:17:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Zqrwk-000579-Ib for bug-gnu-emacs@gnu.org; Mon, 26 Oct 2015 20:17:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juanma Barranquero Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 27 Oct 2015 00:17:02 +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: Original-Received: via spool by 21766-submit@debbugs.gnu.org id=B21766.144590496219586 (code B ref 21766); Tue, 27 Oct 2015 00:17:02 +0000 Original-Received: (at 21766) by debbugs.gnu.org; 27 Oct 2015 00:16:02 +0000 Original-Received: from localhost ([127.0.0.1]:39517 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Zqrvl-00055c-Ix for submit@debbugs.gnu.org; Mon, 26 Oct 2015 20:16:02 -0400 Original-Received: from mail-lb0-f171.google.com ([209.85.217.171]:35652) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Zqrvj-00055K-8f for 21766@debbugs.gnu.org; Mon, 26 Oct 2015 20:16:00 -0400 Original-Received: by lbbes7 with SMTP id es7so52145316lbb.2 for <21766@debbugs.gnu.org>; Mon, 26 Oct 2015 17:15:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=/s8wE5+WLQpIywfMBsm1dtGAkFAhmrWudo97noJhsUg=; b=yWUaA4W3LCX7/bPmoDAvjIdmIG+pglYlyC/OSaBrzvlzh5PYpi1hKJA4XE7jzUs8l8 QJchQUN1wxctbWHQwtTtmZpPH8ge4rQr9uz07zzvuFe7ITXtip2bDq68+ndHV0V9hTcy S1FnEl1+EonEpaGcW2iy7p1pb29/bW2mzCHjGHrzVxhhE2XqEqoq4tNa0tPH2AO3TiDg z+XkkahiMPHa93sZ49MlAW+kAU+OLwpq4FoocfyUPYrZyz68QPheP/d3HKtPwdttVO2L VJ0ijrwGZOJFWJJXBOIK121gNTc/S07Q1+kwer/rKY7pw/TyGF90mPGSoRQ3cFaA5pAM DMAw== X-Received: by 10.112.77.10 with SMTP id o10mr18571208lbw.28.1445904958394; Mon, 26 Oct 2015 17:15:58 -0700 (PDT) Original-Received: by 10.25.217.135 with HTTP; Mon, 26 Oct 2015 17:15:18 -0700 (PDT) In-Reply-To: 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:108053 Archived-At: --001a11c3ba826c9e4f05230afb1e Content-Type: text/plain; charset=UTF-8 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. 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. --001a11c3ba826c9e4f05230afb1e Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
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-spac= e 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
<= div>
--- a/lisp/simple.el
+++ b/lisp/simpl= e.el
@@ -609,7 +609,7 @@ delete-trailing-whitespace
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(start (or start (point-min)))= )
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(goto-char start)
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(while (re-search-forward "\\s-$&quo= t; end-marker t)
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(skip-syntax= -backward "-" (line-beginning-position))
+ =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0(save-match-data (skip-syntax-backward "-"= ; (line-beginning-position)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0;; Don't delete formfeeds, even if they are considered whitespace= .
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(if (looking-at-p &quo= t;.*\f")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0(goto-char (match-end 0)))


<= div>or, alternatively,

@@ -609,11 +609,12 @@ = delete-trailing-whitespace
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0(start (or start (point-min))))
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0(goto-char start)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= (while (re-search-forward "\\s-$" end-marker t)
- =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(skip-syntax-backward "-" (line-be= ginning-position))
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; Don'= ;t delete formfeeds, even if they are considered whitespace.
- = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(if (looking-at-p ".*\f")
=
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(goto-char (match-en= d 0)))
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(delete-region (point)= (match-end 0)))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(let ((end (= match-end 0)))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(skip-s= yntax-backward "-" (line-beginning-position))
+ =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; Don't delete formfeeds, even if th= ey are considered whitespace.
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0(if (looking-at-p ".*\f")
+ =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(goto-char end))
+ =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(delete-region (point) end)))
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; Delete trailing empty lines.
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(goto-char end-marker)
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0(when (and (not end)

<= div>it works. Now, the question is, should skip-syntax-backward preserve th= e 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.
--001a11c3ba826c9e4f05230afb1e--