From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juanma Barranquero Newsgroups: gmane.emacs.devel Subject: Re: 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 1446023362 1470 80.91.229.3 (28 Oct 2015 09:09:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 28 Oct 2015 09:09:22 +0000 (UTC) Cc: Andreas Schwab , Emacs developers , Markus Triska , 21766@debbugs.gnu.org To: Stephen Leake Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Oct 28 10:09:06 2015 Return-path: Envelope-to: ged-emacs-devel@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 1ZrMj7-00037W-Tf for ged-emacs-devel@m.gmane.org; Wed, 28 Oct 2015 10:09:02 +0100 Original-Received: from localhost ([::1]:36279 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrMj7-0004Zu-CN for ged-emacs-devel@m.gmane.org; Wed, 28 Oct 2015 05:09:01 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60742) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrMj2-0004Zn-SS for emacs-devel@gnu.org; Wed, 28 Oct 2015 05:08:58 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZrMj1-0006GK-E0 for emacs-devel@gnu.org; Wed, 28 Oct 2015 05:08:56 -0400 Original-Received: from mail-lb0-x22d.google.com ([2a00:1450:4010:c04::22d]:33504) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrMj1-0006GG-2j for emacs-devel@gnu.org; Wed, 28 Oct 2015 05:08:55 -0400 Original-Received: by lbbec13 with SMTP id ec13so889068lbb.0 for ; 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-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c04::22d X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:192778 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--