2011/2/11 Stefan Monnier : >>> +      (while (re-search-forward "\\s-$" end t) >>> +        (skip-syntax-backward "-" (save-excursion (forward-line 0) (point))) >>> +        ;; Don't delete formfeeds, even if they are considered whitespace. >>> +        (save-match-data >>> +          (if (looking-at ".*\f") >>> +              (goto-char (match-end 0)))) >>> +        (delete-region (point) (match-end 0)))))) > >> You can't use the value of `end' to limit the search like that, since >> the deletion changes the size of the region. (Use narrowing or a >> marker.) > > Good point, thanks.  ...or do it from the end. > This patch is teaching me a lot... Attached is a last attempt, if it's not good then I give up and hope that someone else will take care of it. Thanks, Deniz Dogan