[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 4ab7c30: delete-trailing-whitespace: handle read-on
From: |
Sam Steingold |
Subject: |
[Emacs-diffs] master 4ab7c30: delete-trailing-whitespace: handle read-only text in buffer |
Date: |
Wed, 7 Dec 2016 20:06:28 +0000 (UTC) |
branch: master
commit 4ab7c308e073aa26973c5cdd17ec44bf5b325b57
Author: Sam Steingold <address@hidden>
Commit: Sam Steingold <address@hidden>
delete-trailing-whitespace: handle read-only text in buffer
* lisp/simple.el (region-modifiable-p): New function.
(delete-trailing-whitespace): Us it to avoid trying to delete read-only
text.
---
lisp/simple.el | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/lisp/simple.el b/lisp/simple.el
index 91dee30..7eead1c 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -602,6 +602,11 @@ is called on the entire buffer (rather than an active
region)."
:group 'editing
:version "24.3")
+(defun region-modifiable-p (start end)
+ "Return non-nil if the region contain no non-read-only text."
+ (and (not (get-text-property start 'read-only))
+ (eq end (next-single-property-change start 'read-only nil end))))
+
(defun delete-trailing-whitespace (&optional start end)
"Delete trailing whitespace between START and END.
If called interactively, START and END are the start/end of the
@@ -631,7 +636,9 @@ buffer if the variable `delete-trailing-lines' is non-nil."
;; Treating \n as non-whitespace makes things easier.
(modify-syntax-entry ?\n "_")
(while (re-search-forward "\\s-+$" end-marker t)
- (delete-region (match-beginning 0) (match-end 0))))
+ (let ((b (match-beginning 0)) (e (match-end 0)))
+ (when (region-modifiable-p b e)
+ (delete-region b e)))))
(if end
(set-marker end-marker nil)
;; Delete trailing empty lines.
@@ -639,6 +646,7 @@ buffer if the variable `delete-trailing-lines' is non-nil."
;; Really the end of buffer.
(= (goto-char (point-max)) (1+ (buffer-size)))
(<= (skip-chars-backward "\n") -2)
+ (region-modifiable-p (1+ (point)) (point-max))
(delete-region (1+ (point)) (point-max)))))))
;; Return nil for the benefit of `write-file-functions'.
nil)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master 4ab7c30: delete-trailing-whitespace: handle read-only text in buffer,
Sam Steingold <=