diff options
| author | Deniz Dogan | 2011-02-11 19:25:06 +0100 |
|---|---|---|
| committer | Deniz Dogan | 2011-02-11 19:25:06 +0100 |
| commit | 25833f5e5919a434a033963b2236a4e6e88a5a37 (patch) | |
| tree | b5f9734ba624014898da99e3bc6bf4d77baef448 | |
| parent | 75d1d833f5273724839fdf46543d6b0920695700 (diff) | |
| download | emacs-25833f5e5919a434a033963b2236a4e6e88a5a37.tar.gz emacs-25833f5e5919a434a033963b2236a4e6e88a5a37.zip | |
* lisp/simple.el (delete-trailing-whitespace): New optional buffer
bound parameters.
| -rw-r--r-- | lisp/ChangeLog | 5 | ||||
| -rw-r--r-- | lisp/simple.el | 30 |
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 @@ | |||
| 1 | 2011-02-11 Deniz Dogan <deniz.a.m.dogan@gmail.com> | ||
| 2 | |||
| 3 | * simple.el (delete-trailing-whitespace): New optional buffer | ||
| 4 | bound parameters. | ||
| 5 | |||
| 1 | 2011-02-11 Bastien Guerry <bzg@altern.org> | 6 | 2011-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. |
| 619 | All whitespace after the last non-whitespace character in a line is deleted. | 619 | All whitespace after the last non-whitespace character in a line is deleted. |
| 620 | This respects narrowing, created by \\[narrow-to-region] and friends. | 620 | This respects narrowing, created by \\[narrow-to-region] and friends. |
| 621 | A formfeed is not considered whitespace by this function." | 621 | A formfeed is not considered whitespace by this function. |
| 622 | (interactive "*") | 622 | If 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. |