GNU bug report logs - #21766
25.0.50; delete-trailing-whitespace sometimes deletes non-whitespace

Previous Next

Package: emacs;

Reported by: Markus Triska <triska <at> metalevel.at>

Date: Mon, 26 Oct 2015 23:10:01 UTC

Severity: normal

Merged with 21769

Found in version 25.0.50

Done: Juanma Barranquero <lekktu <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: martin rudalics <rudalics <at> gmx.at>
To: Juanma Barranquero <lekktu <at> gmail.com>, Markus Triska <triska <at> metalevel.at>
Cc: 21766 <at> debbugs.gnu.org
Subject: bug#21766: 25.0.50; delete-trailing-whitespace sometimes deletes non-whitespace
Date: Tue, 27 Oct 2015 09:05:52 +0100
> Now, the question is, should skip-syntax-backward preserve the
> match data, or must delete-trailing-whitespace be coded defensively?

The latter.

> The
> usual policy has been that code that needs the match data preserved should
> make sure itself that it is so.

Shouldn't we remove that "\\s-$" rigmarole?  Something like the largely
untested

      (let ((end-marker (copy-marker (or end (point-max))))
	    old-bol new-eol new-bol)
        (goto-char (or start (point-min)))
        (while (re-search-forward "\\\n" end-marker t)
	  (setq new-bol (point))
	  (goto-char (setq new-eol (match-beginning 0)))
          (if (or (zerop (skip-syntax-backward
			  "-" (or old-bol (line-beginning-position))))
		  (looking-at-p ".*\f"))
	      (goto-char new-bol)
	    (delete-region (point) new-eol)
	    (forward-char))
	  (setq old-bol (point)))

It's still not very clean (should line-beginning-position be allowed to
go before START?) so if someone wants to polish it up ....

martin




This bug report was last modified 9 years and 259 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.