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: Wed, 28 Oct 2015 10:08:14 +0100 Message-ID: References: <86wpu77ob5.fsf@stephe-leake.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a11c3c46e2c2c9e0523268bb8 X-Trace: ger.gmane.org 1446023436 2539 80.91.229.3 (28 Oct 2015 09:10:36 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 28 Oct 2015 09:10:36 +0000 (UTC) Cc: Andreas Schwab , 21766@debbugs.gnu.org, Markus Triska , Emacs developers To: Stephen Leake Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Oct 28 10:10:24 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 1ZrMkL-00046F-7j for geb-bug-gnu-emacs@m.gmane.org; Wed, 28 Oct 2015 10:10:17 +0100 Original-Received: from localhost ([::1]:36288 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrMkK-00059m-GN for geb-bug-gnu-emacs@m.gmane.org; Wed, 28 Oct 2015 05:10:16 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:32952) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrMkB-00056j-OX for bug-gnu-emacs@gnu.org; Wed, 28 Oct 2015 05:10:13 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZrMk7-0006wV-F1 for bug-gnu-emacs@gnu.org; Wed, 28 Oct 2015 05:10:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:50467) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrMk7-0006wR-Bk for bug-gnu-emacs@gnu.org; Wed, 28 Oct 2015 05:10:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1ZrMk6-0005dZ-Il for bug-gnu-emacs@gnu.org; Wed, 28 Oct 2015 05:10: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: Wed, 28 Oct 2015 09:10: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.144602335721577 (code B ref 21766); Wed, 28 Oct 2015 09:10:02 +0000 Original-Received: (at 21766) by debbugs.gnu.org; 28 Oct 2015 09:09:17 +0000 Original-Received: from localhost ([127.0.0.1]:41175 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZrMjM-0005bt-CW for submit@debbugs.gnu.org; Wed, 28 Oct 2015 05:09:17 -0400 Original-Received: from mail-lb0-f174.google.com ([209.85.217.174]:36546) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZrMj1-0005ao-17 for 21766@debbugs.gnu.org; Wed, 28 Oct 2015 05:09:13 -0400 Original-Received: by lbjm5 with SMTP id m5so784908lbj.3 for <21766@debbugs.gnu.org>; Wed, 28 Oct 2015 02:08:54 -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=wKz60Wo81gsCOboHau1FviIQm0yHVUnADmQjf5eCD0E=; b=tdQqgDCq396dCUEQ+da/f6YlVJ1SdQCVpWCUgsnGe9tbhRVIkg/BZ5E8v3VzzRc6OZ v5qZfeMnksuBYj0XQxBD/2Y2oKQr96dBbjwekfE5+2tG8MCdMKLV/I/b+tqEce5DjYIQ BXMy9oJGMatm8c1SHnWOAFoF8vMGU6qGnal3aP08lgt879/lpWrStEH6ocNZBFL/7lub aEj1+1ML1QvqE9TnzmX9K3MjYImBkgcA321u9yDSMuVkDJa8wZvGXLIi0ndGBta9Yzfh o4QbmfSRGl35WzlipcAiYROxVsPgfetT6Nw0AXmpzUlTiifMummZ5Q+t9+mcTuAZ+ldY yMsA== X-Received: by 10.112.62.194 with SMTP id a2mr22864137lbs.80.1446023334208; Wed, 28 Oct 2015 02:08:54 -0700 (PDT) Original-Received: by 10.25.217.135 with HTTP; Wed, 28 Oct 2015 02:08:14 -0700 (PDT) In-Reply-To: <86wpu77ob5.fsf@stephe-leake.org> 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:108093 Archived-At: --001a11c3c46e2c2c9e0523268bb8 Content-Type: text/plain; charset=UTF-8 On Wed, Oct 28, 2015 at 2:51 AM, Stephen Leake < stephen_leake@stephe-leake.org> wrote: > I suggest instead to save the file without extra whitespace, and add code > to the test to insert the extra whitespace. The file is quite short, so in this case is better to get rid of it and just insert its contents into the buffer. Thanks, Juanma Fix bug#21766 and add test. * lisp/simple.el (delete-trailing-whitespace): Save match data when calling `skip-syntax-backward'. * test/automated/simple-test.el (simple-delete-trailing-whitespace): New test. diff --git a/lisp/simple.el b/lisp/simple.el index 338a060..f6c580f 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -609,7 +609,8 @@ 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))) diff --git a/test/automated/simple-test.el b/test/automated/simple-test.el index 8da575d..5bfb746 100644 --- a/test/automated/simple-test.el +++ b/test/automated/simple-test.el @@ -180,5 +180,27 @@ simple-test--dummy-buffer (should (= x 2))) (remove-hook 'post-self-insert-hook inc)))) + +;;; `delete-trailing-whitespace' +(ert-deftest simple-delete-trailing-whitespace () + "Test bug#21766: delete-whitespace sometimes deletes non-whitespace." + (defvar python-indent-guess-indent-offset) ; to avoid a warning + (let ((python (featurep 'python)) + (python-indent-guess-indent-offset nil) + (delete-trailing-lines t)) + (unwind-protect + (with-temp-buffer + (python-mode) + (insert (concat "query = \"\"\"WITH filtered AS \n" + "WHERE \n" + "\"\"\".format(fv_)\n" + "\n" + "\n")) + (delete-trailing-whitespace) + (should (equal (count-lines (point-min) (point-max)) 3))) + ;; Let's clean up if running interactive + (unless (or noninteractive python) + (unload-feature 'python))))) + (provide 'simple-test) ;;; simple-test.el ends here -- 2.6.2.windows.1 --001a11c3c46e2c2c9e0523268bb8 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On Wed, Oct 28, 2015 at 2:51 AM, Stephen Leake <stephen_leake@= stephe-leake.org> wrote:

> I=C2=A0suggest instead to = save the file without extra whitespace, and add code
> to the test to= insert the extra whitespace.

The file is quite sh= ort, so in this case is better to get rid of it and just insert its content= s into the buffer.

Thanks,

=C2=A0 =C2=A0 =C2=A0Juanma



=C2=A0 =C2=A0 =C2=A0 =C2=A0 Fix bug#21766 and add test.

=C2=A0 =C2=A0 =C2=A0 =C2=A0 * lisp/simple.el (delet= e-trailing-whitespace): Save match data when
=C2=A0 =C2=A0 =C2=A0= =C2=A0 calling `skip-syntax-backward'.
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 * test/automated/simple-test.el (simple-delete-trailing-whitespace):=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 New test.

<= br>
diff --git a/lisp/simple.el b/lisp/simple.el
index = 338a060..f6c580f 100644
--- a/lisp/simple.el
+++ b/lisp= /simple.el
@@ -609,7 +609,8 @@ 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-s= yntax-backward "-" (line-beginning-position))
+ =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0(save-match-data
+ =C2=A0 =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 =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 ".*\f")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(goto-char = (match-end 0)))
diff --git a/test/automated/simple-test.el b/test= /automated/simple-test.el
index 8da575d..5bfb746 100644
--- a/test/automated/simple-test.el
+++ b/test/automated/simple-= test.el
@@ -180,5 +180,27 @@ simple-test--dummy-buffer
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(should (=3D x 2)))
=C2= =A0 =C2=A0 =C2=A0 =C2=A0(remove-hook 'post-self-insert-hook inc))))
=C2=A0
+=0C
+;;; `delete-trailing-whitespace'= ;
+(ert-deftest simple-delete-trailing-whitespace ()
+ = =C2=A0"Test bug#21766: delete-whitespace sometimes deletes non-whitesp= ace."
+ =C2=A0(defvar python-indent-guess-indent-offset) =C2= =A0; to avoid a warning
+ =C2=A0(let ((python (featurep 'pyth= on))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0(python-indent-guess-indent-off= set nil)
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0(delete-trailing-lines t))<= /div>
+ =C2=A0 =C2=A0(unwind-protect
+ =C2=A0 =C2=A0 =C2=A0 = =C2=A0(with-temp-buffer
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(pyth= on-mode)
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(insert (concat &quo= t;query =3D \"\"\"WITH filtered AS \n"
+ =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0"WHERE =C2=A0 =C2=A0 =C2=A0\n"
+ =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0"\"\"\".format(fv_)\n"
+ =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0"\n"
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"\n"))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(delete-trailing-whitespace)
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(should (equal (count-lines (poi= nt-min) (point-max)) 3)))
+ =C2=A0 =C2=A0 =C2=A0;; Let's clea= n up if running interactive
+ =C2=A0 =C2=A0 =C2=A0(unless (or non= interactive python)
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0(unload-feature = 'python)))))
+
=C2=A0(provide 'simple-test)
=C2=A0;;; simple-test.el ends here
--=C2=A0
2.6.= 2.windows.1

--001a11c3c46e2c2c9e0523268bb8--