diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2011-09-23 11:06:14 -0400 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2011-09-23 11:06:14 -0400 |
commit | db4e950db70e655d72d8d45d91e90674b25b47e4 (patch) | |
tree | ea3714ab7b1f92b70d251595558433daeb601e88 /lisp | |
parent | c4682d186f8f9914d65f95b8a9470f166348b689 (diff) | |
download | emacs-db4e950db70e655d72d8d45d91e90674b25b47e4.tar.gz emacs-db4e950db70e655d72d8d45d91e90674b25b47e4.tar.bz2 emacs-db4e950db70e655d72d8d45d91e90674b25b47e4.zip |
* lisp/simple.el (delete-trailing-whitespace): Document last change; simplify.
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/ChangeLog | 5 | ||||
-rw-r--r-- | lisp/simple.el | 21 |
2 files changed, 16 insertions, 10 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index f17ba200815..fd5cb9bcac7 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2011-09-23 Stefan Monnier <monnier@iro.umontreal.ca> + + * simple.el (delete-trailing-whitespace): + Document last change; simplify. + 2011-09-23 Peter J. Weisberg <pj@irregularexpressions.net> * simple.el (delete-trailing-whitespace): Also delete diff --git a/lisp/simple.el b/lisp/simple.el index c828584c17f..142270930ca 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -568,6 +568,7 @@ On nonblank line, delete any immediately following blank lines." All whitespace after the last non-whitespace character in a line is deleted. This respects narrowing, created by \\[narrow-to-region] and friends. A formfeed is not considered whitespace by this function. +If END is nil, also delete all trailing lines at the end of the buffer. If the region is active, only delete whitespace within the region." (interactive (progn (barf-if-buffer-read-only) @@ -580,18 +581,18 @@ If the region is active, only delete whitespace within the region." (start (or start (point-min)))) (goto-char start) (while (re-search-forward "\\s-$" end-marker t) - (skip-syntax-backward "-" (save-excursion (forward-line 0) (point))) + (skip-syntax-backward "-" (line-beginning-position)) ;; Don't delete formfeeds, even if they are considered whitespace. - (save-match-data - (if (looking-at ".*\f") - (goto-char (match-end 0)))) + (if (looking-at-p ".*\f") + (goto-char (match-end 0))) (delete-region (point) (match-end 0))) - (save-restriction - (goto-char end-marker) - (widen) - (if (and (eobp) - (looking-back "\n\n+" nil t)) - (replace-match "\n"))) + ;; Delete trailing empty lines. + (goto-char end-marker) + (when (and (not end) + (<= (skip-chars-backward "\n") -2) + ;; Really the end of buffer. + (save-restriction (widen) (eobp))) + (delete-region (1+ (point)) end-marker)) (set-marker end-marker nil)))) ;; Return nil for the benefit of `write-file-functions'. nil) |