From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michal Nazarewicz Newsgroups: gmane.emacs.bugs Subject: bug#23843: [PATCH 1/3] Make =?UTF-8?Q?=E2=80=98delete-trailing-whitespace=E2=80=99?= delete spaces after form feed Date: Sat, 25 Jun 2016 00:14:43 +0200 Message-ID: <1466806485-15732-1-git-send-email-mina86@mina86.com> References: <1466806193-15280-1-git-send-email-mina86@mina86.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1466806547 29310 80.91.229.3 (24 Jun 2016 22:15:47 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 24 Jun 2016 22:15:47 +0000 (UTC) To: 23843@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Jun 25 00:15:39 2016 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 1bGZNx-0006xB-64 for geb-bug-gnu-emacs@m.gmane.org; Sat, 25 Jun 2016 00:15:37 +0200 Original-Received: from localhost ([::1]:47499 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGZNw-0004F4-4o for geb-bug-gnu-emacs@m.gmane.org; Fri, 24 Jun 2016 18:15:36 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39772) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGZNS-0003Qb-Mp for bug-gnu-emacs@gnu.org; Fri, 24 Jun 2016 18:15:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bGZNO-00010A-El for bug-gnu-emacs@gnu.org; Fri, 24 Jun 2016 18:15:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:42366) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGZNO-000103-Bf for bug-gnu-emacs@gnu.org; Fri, 24 Jun 2016 18:15:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bGZNO-0000ub-7A for bug-gnu-emacs@gnu.org; Fri, 24 Jun 2016 18:15:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <1466806193-15280-1-git-send-email-mina86@mina86.com> Resent-From: Michal Nazarewicz Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 24 Jun 2016 22:15:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 23843 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 23843-submit@debbugs.gnu.org id=B23843.14668064973463 (code B ref 23843); Fri, 24 Jun 2016 22:15:02 +0000 Original-Received: (at 23843) by debbugs.gnu.org; 24 Jun 2016 22:14:57 +0000 Original-Received: from localhost ([127.0.0.1]:54700 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bGZNJ-0000tn-Fn for submit@debbugs.gnu.org; Fri, 24 Jun 2016 18:14:57 -0400 Original-Received: from mail-wm0-f54.google.com ([74.125.82.54]:37948) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bGZNH-0000tI-6p for 23843@debbugs.gnu.org; Fri, 24 Jun 2016 18:14:55 -0400 Original-Received: by mail-wm0-f54.google.com with SMTP id r201so41796482wme.1 for <23843@debbugs.gnu.org>; Fri, 24 Jun 2016 15:14:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=vwkP0RlIGY6kNME/jKPYr0SCtUR36WUz1clUv7nCZDU=; b=MVF+ETHsoA2uwN2tjf0oDq2kJxLiXdau8Iw+K+k1T+rwspK4E8Rcu982LADIiUxVwr 0+hkQRgzQi4zn/eoPpn2VQ+Oe78KvLWlsgwDXw42pXF6Pi2J13V//NiTMd1EuyKBStPv vok8RRkxPUpJYUjGOw8mWxQwUUigXpGe14kOA2KzW8kAAji90DHygavBoGWvkOpVM0I4 osfFuukOGOdvbu9ANnjsIdfy7wucmnjHqH0MQY5wRF41oX3Y4yTwgIqmwBzhRNEMjka1 0OoaxgvmQPKctGjmJGMV/KnLEzsGjb8MzUKEs3wIdhLKzMNoGoJFjhlOJ5mGYz9LeE31 edPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:subject:date:message-id :mime-version:content-transfer-encoding; bh=vwkP0RlIGY6kNME/jKPYr0SCtUR36WUz1clUv7nCZDU=; b=gYqDg8GKQSaenFdqXVnJi5yofcVIPZAoT/Fwz4YqBd10lViAJAH/r9JQ5Gx78bVTyG ylK4mNFvxU/e0f/Jr8fwRfBHwh0vatAu1qNTuEPaUPmHMkWr/DOTIyiGLrX++TFC4/l/ JUeNkmM4kWUzkeKKwoOWfiCPK4vm4E6OI8GOpJYTmLoB3/cjQs/KUz79eCPnnykuqoXD P7xCZiVVva/+ccD0plBuOgGvawaL4vVO6dsxGyzKDb9krRmvYRogf7bakVhYRW2BRGlo XRZIG55W4u7hucKYqvC5Y0SVBIMCEPpd8CqwN3UZD51TauL7qtQThOWeHgfnp2xOxB4A 3Cxg== X-Gm-Message-State: ALyK8tLEepYhvP6oK6Ssz7ZwKs/eMybB9Yun9z/uiQzbHFHETi7S6EkihN5AkdoW4L1ererA X-Received: by 10.28.224.69 with SMTP id x66mr262029wmg.89.1466806489486; Fri, 24 Jun 2016 15:14:49 -0700 (PDT) Original-Received: from mpn.zrh.corp.google.com ([172.16.113.135]) by smtp.gmail.com with ESMTPSA id v70sm345056wmf.18.2016.06.24.15.14.47 for <23843@debbugs.gnu.org> (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Jun 2016 15:14:47 -0700 (PDT) Original-Received: by mpn.zrh.corp.google.com (Postfix, from userid 126942) id 2A71E1E35D2; Sat, 25 Jun 2016 00:14:47 +0200 (CEST) X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] 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" Xref: news.gmane.org gmane.emacs.bugs:120021 Archived-At: * lisp/simple.el (delete-trailing-whitespace): Treat form fead as a non-whitespace character (regradless of whether it’s character syntax is whitespace) and delete any whitespace following it instead of leaving lines with form feeds completely unchanged. I.e. a line like "\f " will now became "\f". --- etc/NEWS | 6 ++++++ lisp/simple.el | 15 +++++++-------- test/lisp/simple-tests.el | 17 +++++++++++++++-- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index b3a044d..e76628a 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -187,6 +187,12 @@ questions, with a handy way to display help texts. 'undo', undo the last replacement; bound to 'u'. 'undo-all', undo all replacements; bound to 'U'. +** 'delete-trailing-whitespace' deletes whitespace after form feed. +In modes where form feed was treated as a whitespace character, +'delete-trailing-whitespace' would keep lines containing it unchanged. +It now deletes whitespace after the last form feed thus behaving the +same as in modes where the character is not whitespace. + * Changes in Specialized Modes and Packages in Emacs 25.2 diff --git a/lisp/simple.el b/lisp/simple.el index bc3e7b8..ffedbfa 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -602,15 +602,14 @@ delete-trailing-whitespace (list nil nil)))) (save-match-data (save-excursion - (let ((end-marker (copy-marker (or end (point-max)))) - (start (or start (point-min)))) - (goto-char start) - (while (re-search-forward "\\s-$" end-marker t) - (skip-syntax-backward "-" (line-beginning-position)) + (let ((end-marker (copy-marker (or end (point-max))))) + (goto-char (or start (point-min))) + (with-syntax-table (make-syntax-table (syntax-table)) ;; 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))) + (modify-syntax-entry ?\f "_") + (while (re-search-forward "\\s-$" end-marker t) + (skip-syntax-backward "-" (line-beginning-position)) + (delete-region (point) (match-end 0)))) ;; Delete trailing empty lines. (goto-char end-marker) (when (and (not end) diff --git a/test/lisp/simple-tests.el b/test/lisp/simple-tests.el index 40cd1d2..2722544 100644 --- a/test/lisp/simple-tests.el +++ b/test/lisp/simple-tests.el @@ -204,7 +204,7 @@ simple-test--transpositions ;;; `delete-trailing-whitespace' -(ert-deftest simple-delete-trailing-whitespace () +(ert-deftest simple-delete-trailing-whitespace--bug-21766 () "Test bug#21766: delete-whitespace sometimes deletes non-whitespace." (defvar python-indent-guess-indent-offset) ; to avoid a warning (let ((python (featurep 'python)) @@ -219,11 +219,24 @@ simple-test--transpositions "\n" "\n")) (delete-trailing-whitespace) - (should (equal (count-lines (point-min) (point-max)) 3))) + (should (string-equal (buffer-string) + (concat "query = \"\"\"WITH filtered AS\n" + "WHERE\n" + "\"\"\".format(fv_)\n")))) ;; Let's clean up if running interactive (unless (or noninteractive python) (unload-feature 'python))))) +(ert-deftest simple-delete-trailing-whitespace--formfeeds () + "Test formfeeds are not deleted but whitespace past them is." + (with-temp-buffer + (with-syntax-table (make-syntax-table) + (modify-syntax-entry ?\f " ") ; Make sure \f is whitespace + (insert " \f \n \f \f \n\nlast\n") + (delete-trailing-whitespace) + (should (string-equal (buffer-string) " \f\n \f \f\n\nlast\n")) + (should (equal ?\s (char-syntax ?\f)))))) + ;;; auto-boundary tests (ert-deftest undo-auto-boundary-timer () -- 2.8.0.rc3.226.g39d4020