aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDeniz Dogan2011-02-11 19:25:06 +0100
committerDeniz Dogan2011-02-11 19:25:06 +0100
commit25833f5e5919a434a033963b2236a4e6e88a5a37 (patch)
treeb5f9734ba624014898da99e3bc6bf4d77baef448
parent75d1d833f5273724839fdf46543d6b0920695700 (diff)
downloademacs-25833f5e5919a434a033963b2236a4e6e88a5a37.tar.gz
emacs-25833f5e5919a434a033963b2236a4e6e88a5a37.zip
* lisp/simple.el (delete-trailing-whitespace): New optional buffer
bound parameters.
-rw-r--r--lisp/ChangeLog5
-rw-r--r--lisp/simple.el30
2 files changed, 24 insertions, 11 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 043c8bebea6..68fdfbf4d2e 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
12011-02-11 Deniz Dogan <deniz.a.m.dogan@gmail.com>
2
3 * simple.el (delete-trailing-whitespace): New optional buffer
4 bound parameters.
5
12011-02-11 Bastien Guerry <bzg@altern.org> 62011-02-11 Bastien Guerry <bzg@altern.org>
2 7
3 * files.el (basic-save-buffer): save unmodified buffers when 8 * files.el (basic-save-buffer): save unmodified buffers when
diff --git a/lisp/simple.el b/lisp/simple.el
index 537c9a80838..f19525aba4c 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -614,22 +614,30 @@ On nonblank line, delete any immediately following blank lines."
614 (if (looking-at "^[ \t]*\n\\'") 614 (if (looking-at "^[ \t]*\n\\'")
615 (delete-region (point) (point-max))))) 615 (delete-region (point) (point-max)))))
616 616
617(defun delete-trailing-whitespace () 617(defun delete-trailing-whitespace (&optional start end)
618 "Delete all the trailing whitespace across the current buffer. 618 "Delete all the trailing whitespace across the current buffer.
619All whitespace after the last non-whitespace character in a line is deleted. 619All whitespace after the last non-whitespace character in a line is deleted.
620This respects narrowing, created by \\[narrow-to-region] and friends. 620This respects narrowing, created by \\[narrow-to-region] and friends.
621A formfeed is not considered whitespace by this function." 621A formfeed is not considered whitespace by this function.
622 (interactive "*") 622If the region is active, only delete whitespace within the region."
623 (interactive (progn
624 (barf-if-buffer-read-only)
625 (if (use-region-p)
626 (list (region-beginning) (region-end))
627 (list nil nil))))
623 (save-match-data 628 (save-match-data
624 (save-excursion 629 (save-excursion
625 (goto-char (point-min)) 630 (let ((end-marker (copy-marker (or end (point-max))))
626 (while (re-search-forward "\\s-$" nil t) 631 (start (or start (point-min))))
627 (skip-syntax-backward "-" (save-excursion (forward-line 0) (point))) 632 (goto-char start)
628 ;; Don't delete formfeeds, even if they are considered whitespace. 633 (while (re-search-forward "\\s-$" end-marker t)
629 (save-match-data 634 (skip-syntax-backward "-" (save-excursion (forward-line 0) (point)))
630 (if (looking-at ".*\f") 635 ;; Don't delete formfeeds, even if they are considered whitespace.
631 (goto-char (match-end 0)))) 636 (save-match-data
632 (delete-region (point) (match-end 0)))))) 637 (if (looking-at ".*\f")
638 (goto-char (match-end 0))))
639 (delete-region (point) (match-end 0)))
640 (set-marker end-marker nil)))))
633 641
634(defun newline-and-indent () 642(defun newline-and-indent ()
635 "Insert a newline, then indent according to major mode. 643 "Insert a newline, then indent according to major mode.