all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Noam Postavsky <npostavs@users.sourceforge.net>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Emacs developers <emacs-devel@gnu.org>
Subject: Re: [Emacs-diffs] master c66aaa6: Recomplexify ‘delete-trailing-whitespace’ by treating \n as whitespace again
Date: Wed, 15 Mar 2017 23:04:38 -0400	[thread overview]
Message-ID: <CAM-tV--oe=9PL2cq2PrSZk5U20roLNcYcZCT=q=-ksFTdD03OA@mail.gmail.com> (raw)
In-Reply-To: <jwvvaraszp4.fsf-monnier+gmane.emacs.devel@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 603 bytes --]

On Wed, Mar 15, 2017 at 10:52 PM, Stefan Monnier
<monnier@iro.umontreal.ca> wrote:
> Yes, it's normal: the "search" attempts a "match" from every whitespace.
> So if you have N consecutive whitespace chars in the middle of line,
> that gives you N attempts to "match" and every attempt takes O(N) steps
> to find that the end of the whitespace is not an LF.
>
> I don't understand how "\\s-+$" can be significantly faster than
> "[\s\t]+$" in this respect.

What?  I though I said "\\s-+" is *slower* (though only by a factor of 2).

Anyway, how about the attached which removes the syntax table stuff.

[-- Attachment #2: 0001-Simplify-delete-trailing-whitespace-by-dropping-synt.patch --]
[-- Type: text/x-patch, Size: 1669 bytes --]

From 2275487232b96ca782ca671d60be002e3948a764 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Wed, 15 Mar 2017 23:01:13 -0400
Subject: [PATCH] Simplify delete-trailing-whitespace by dropping syntax tables

* lisp/simple.el (delete-trailing-whitespace): Just match [[:blank:]]
independently of current syntax table.
---
 lisp/simple.el | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/lisp/simple.el b/lisp/simple.el
index 369fbf7192..2cf8c13225 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -630,14 +630,13 @@ delete-trailing-whitespace
     (save-excursion
       (let ((end-marker (and end (copy-marker end))))
         (goto-char (or start (point-min)))
-        (with-syntax-table (make-syntax-table (syntax-table))
-          ;; Don't delete formfeeds, even if they are considered whitespace.
-          (modify-syntax-entry ?\f "_")
-          (while (re-search-forward "\\s-$" end-marker t)
-            (skip-syntax-backward "-" (line-beginning-position))
-            (let ((b (point)) (e (match-end 0)))
-              (when (region-modifiable-p b e)
-                (delete-region b e)))))
+        ;; Note that trying to match all the trailing whitespace with
+        ;; just the regexp can be very slow (Bug#26079).
+        (while (re-search-forward "[[:blank:]]$" end-marker t)
+          (skip-syntax-backward "-" (line-beginning-position))
+          (let ((b (point)) (e (match-end 0)))
+            (when (region-modifiable-p b e)
+              (delete-region b e))))
         (if end
             (set-marker end-marker nil)
           ;; Delete trailing empty lines.
-- 
2.11.1


  reply	other threads:[~2017-03-16  3:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20170315023157.29463.36647@vcs0.savannah.gnu.org>
     [not found] ` <20170315023159.30AA520CAB@vcs0.savannah.gnu.org>
2017-03-15 11:28   ` [Emacs-diffs] master c66aaa6: Recomplexify ‘delete-trailing-whitespace’ by treating \n as whitespace again Stefan Monnier
2017-03-15 12:09     ` Noam Postavsky
2017-03-15 14:50       ` Stefan Monnier
2017-03-15 17:05         ` Noam Postavsky
2017-03-15 20:26           ` Stefan Monnier
2017-03-16  0:18             ` Noam Postavsky
2017-03-16  2:52               ` Stefan Monnier
2017-03-16  3:04                 ` Noam Postavsky [this message]
2017-03-16  3:08                   ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAM-tV--oe=9PL2cq2PrSZk5U20roLNcYcZCT=q=-ksFTdD03OA@mail.gmail.com' \
    --to=npostavs@users.sourceforge.net \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.