[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] /srv/bzr/emacs/trunk r103227: * lisp/simple.el (delete-tra
From: |
Deniz Dogan |
Subject: |
[Emacs-diffs] /srv/bzr/emacs/trunk r103227: * lisp/simple.el (delete-trailing-whitespace): New optional buffer |
Date: |
Fri, 11 Feb 2011 19:25:06 +0100 |
User-agent: |
Bazaar (2.0.3) |
------------------------------------------------------------
revno: 103227
committer: Deniz Dogan <address@hidden>
branch nick: emacs-trunk
timestamp: Fri 2011-02-11 19:25:06 +0100
message:
* lisp/simple.el (delete-trailing-whitespace): New optional buffer
bound parameters.
modified:
lisp/ChangeLog
lisp/simple.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog 2011-02-11 17:35:37 +0000
+++ b/lisp/ChangeLog 2011-02-11 18:25:06 +0000
@@ -1,3 +1,8 @@
+2011-02-11 Deniz Dogan <address@hidden>
+
+ * simple.el (delete-trailing-whitespace): New optional buffer
+ bound parameters.
+
2011-02-11 Bastien Guerry <address@hidden>
* files.el (basic-save-buffer): save unmodified buffers when
=== modified file 'lisp/simple.el'
--- a/lisp/simple.el 2011-02-01 21:22:21 +0000
+++ b/lisp/simple.el 2011-02-11 18:25:06 +0000
@@ -614,22 +614,30 @@
(if (looking-at "^[ \t]*\n\\'")
(delete-region (point) (point-max)))))
-(defun delete-trailing-whitespace ()
+(defun delete-trailing-whitespace (&optional start end)
"Delete all the trailing whitespace across the current buffer.
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."
- (interactive "*")
+A formfeed is not considered whitespace by this function.
+If the region is active, only delete whitespace within the region."
+ (interactive (progn
+ (barf-if-buffer-read-only)
+ (if (use-region-p)
+ (list (region-beginning) (region-end))
+ (list nil nil))))
(save-match-data
(save-excursion
- (goto-char (point-min))
- (while (re-search-forward "\\s-$" nil 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))))))
+ (let ((end-marker (copy-marker (or end (point-max))))
+ (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)))
+ ;; 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)))
+ (set-marker end-marker nil)))))
(defun newline-and-indent ()
"Insert a newline, then indent according to major mode.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] /srv/bzr/emacs/trunk r103227: * lisp/simple.el (delete-trailing-whitespace): New optional buffer,
Deniz Dogan <=