aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2012-07-28 18:38:55 +0800
committerChong Yidong2012-07-28 18:38:55 +0800
commit345a2258671ec587a32129daf37fb53b3eea903e (patch)
treed56dcdb70927a4cf7855ce14484a050846975279
parent049a0936caca462a2f12107813a24b70eeb97c3e (diff)
downloademacs-345a2258671ec587a32129daf37fb53b3eea903e.tar.gz
emacs-345a2258671ec587a32129daf37fb53b3eea903e.zip
* simple.el (delete-trailing-lines): New option.
(delete-trailing-whitespace): Obey it. Fixes: debbugs:11879
-rw-r--r--etc/NEWS4
-rw-r--r--lisp/ChangeLog5
-rw-r--r--lisp/simple.el28
3 files changed, 31 insertions, 6 deletions
diff --git a/etc/NEWS b/etc/NEWS
index ce44a530e26..0a4157a4557 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -147,6 +147,10 @@ for it.
147 147
148* Editing Changes in Emacs 24.2 148* Editing Changes in Emacs 24.2
149 149
150** New option `delete-trailing-lines' specifies whether the
151M-x delete-trailing-lines command should delete trailing lines at the
152end of the buffer. It defaults to t.
153
150** Search changes 154** Search changes
151 155
152*** Global `M-s _' starts a symbol (identifier) incremental search, 156*** Global `M-s _' starts a symbol (identifier) incremental search,
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index a158e4f347a..410a23592df 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
12012-07-28 Chong Yidong <cyd@gnu.org>
2
3 * simple.el (delete-trailing-lines): New option.
4 (delete-trailing-whitespace): Obey it (Bug#11879).
5
12012-07-28 David Engster <deng@randomsample.de> 62012-07-28 David Engster <deng@randomsample.de>
2 7
3 * xml.el (xml-node-name, xml-parse-file, xml-parse-region): 8 * xml.el (xml-node-name, xml-parse-file, xml-parse-region):
diff --git a/lisp/simple.el b/lisp/simple.el
index 3240ede0299..2011ff2b1bb 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -564,13 +564,28 @@ On nonblank line, delete any immediately following blank lines."
564 (if (looking-at "^[ \t]*\n\\'") 564 (if (looking-at "^[ \t]*\n\\'")
565 (delete-region (point) (point-max))))) 565 (delete-region (point) (point-max)))))
566 566
567(defcustom delete-trailing-lines t
568 "If non-nil, \\[delete-trailing-whitespace] deletes trailing lines.
569Trailing lines are deleted only if `delete-trailing-whitespace'
570is called on the entire buffer (rather than an active region)."
571 :type 'boolean
572 :group 'editing
573 :version "24.2")
574
567(defun delete-trailing-whitespace (&optional start end) 575(defun delete-trailing-whitespace (&optional start end)
568 "Delete all the trailing whitespace across the current buffer. 576 "Delete trailing whitespace between START and END.
569All whitespace after the last non-whitespace character in a line is deleted. 577If called interactively, START and END are the start/end of the
570This respects narrowing, created by \\[narrow-to-region] and friends. 578region if the mark is active, or of the buffer's accessible
571A formfeed is not considered whitespace by this function. 579portion if the mark is inactive.
572If END is nil, also delete all trailing lines at the end of the buffer. 580
573If the region is active, only delete whitespace within the region." 581This command deletes whitespace characters after the last
582non-whitespace character in each line between START and END. It
583does not consider formfeed characters to be whitespace.
584
585If this command acts on the entire buffer (i.e. if called
586interactively with the mark inactive, or called from Lisp with
587END nil), it also deletes all trailing lines at the end of the
588buffer if the variable `delete-trailing-lines' is non-nil."
574 (interactive (progn 589 (interactive (progn
575 (barf-if-buffer-read-only) 590 (barf-if-buffer-read-only)
576 (if (use-region-p) 591 (if (use-region-p)
@@ -590,6 +605,7 @@ If the region is active, only delete whitespace within the region."
590 ;; Delete trailing empty lines. 605 ;; Delete trailing empty lines.
591 (goto-char end-marker) 606 (goto-char end-marker)
592 (when (and (not end) 607 (when (and (not end)
608 delete-trailing-lines
593 ;; Really the end of buffer. 609 ;; Really the end of buffer.
594 (save-restriction (widen) (eobp)) 610 (save-restriction (widen) (eobp))
595 (<= (skip-chars-backward "\n") -2)) 611 (<= (skip-chars-backward "\n") -2))