From: Juanma Barranquero <lekktu@gmail.com>
To: Markus Triska <triska@metalevel.at>
Cc: 21766@debbugs.gnu.org
Subject: bug#21766: 25.0.50; delete-trailing-whitespace sometimes deletes non-whitespace
Date: Tue, 27 Oct 2015 01:15:18 +0100 [thread overview]
Message-ID: <CAAeL0SQ2X62q1YWEdTjj4Tkh6=mTRo6EmJmY-4F0fE0bgm8JyA@mail.gmail.com> (raw)
In-Reply-To: <m2si4xfcv5.fsf@metalevel.at>
[-- Attachment #1: Type: text/plain, Size: 2105 bytes --]
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-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.
[-- Attachment #2: Type: text/html, Size: 2981 bytes --]
next prev parent reply other threads:[~2015-10-27 0:15 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-26 23:07 bug#21766: 25.0.50; delete-trailing-whitespace sometimes deletes non-whitespace Markus Triska
2015-10-27 0:15 ` Juanma Barranquero [this message]
2015-10-27 7:07 ` Andreas Röhler
2015-10-27 7:53 ` Juanma Barranquero
2015-10-27 8:05 ` martin rudalics
2015-10-27 8:12 ` Juanma Barranquero
2015-10-27 8:25 ` martin rudalics
2015-10-27 8:32 ` Juanma Barranquero
2015-10-27 9:01 ` Andreas Schwab
2015-10-27 9:16 ` Juanma Barranquero
2015-10-27 9:24 ` martin rudalics
2015-10-27 9:46 ` Andreas Schwab
2015-10-27 10:21 ` Juanma Barranquero
2015-10-27 16:03 ` Juanma Barranquero
[not found] ` <CAAeL0SQ76tmxLV112FkGrAKmZxBcdxP_D783reO3r_WdsYy9zA@mail.gmail.com>
2015-10-28 1:51 ` Stephen Leake
[not found] ` <86wpu77ob5.fsf@stephe-leake.org>
2015-10-28 9:08 ` Juanma Barranquero
[not found] ` <CAAeL0SRhG7DqQ1U5w-sSzjgcci6AYD_EaApxuDW=SgQzO0iauQ@mail.gmail.com>
2015-10-28 17:38 ` Juanma Barranquero
2015-10-28 19:19 ` Stefan Monnier
2015-10-29 6:30 ` Andreas Röhler
2015-10-29 9:41 ` Juanma Barranquero
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAAeL0SQ2X62q1YWEdTjj4Tkh6=mTRo6EmJmY-4F0fE0bgm8JyA@mail.gmail.com' \
--to=lekktu@gmail.com \
--cc=21766@debbugs.gnu.org \
--cc=triska@metalevel.at \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).