changeset 7063:9a0d189fd877

(kill-line, kill-word): Don't use save-excursion. (kill-read-only-ok): New variable. (kill-region): Handle that variable. Handle read-only text property.
author Richard M. Stallman <rms@gnu.org>
date Sun, 24 Apr 1994 05:44:23 +0000
parents 6356b8d3144e
children 19a84bb30e9e
files lisp/simple.el
diffstat 1 files changed, 15 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/simple.el	Sun Apr 24 05:13:41 1994 +0000
+++ b/lisp/simple.el	Sun Apr 24 05:44:23 1994 +0000
@@ -914,9 +914,12 @@
 when given no argument at the beginning of a line."
   (interactive "P")
   (kill-region (point)
-	       ;; Don't shift point before doing the delete; that way,
-	       ;; undo will record the right position of point.
-	       (save-excursion
+	       ;; It is better to move point to the other end of the kill
+	       ;; before killing.  That way, in a read-only buffer, point
+	       ;; moves across the text that is copied to the kill ring.
+	       ;; The choice has no effect on undo now that undo records
+	       ;; the value of point from before the command was run.
+	       (progn
 		 (if arg
 		     (forward-line (prefix-numeric-value arg))
 		   (if (eobp)
@@ -1037,6 +1040,9 @@
 
 ;;;; Commands for manipulating the kill ring.
 
+(defvar kill-read-only-ok nil
+  "*Non-nil means don't signal an error for killing read-only text.")
+
 (defun kill-region (beg end)
   "Kill between point and mark.
 The text is deleted but saved in the kill ring.
@@ -1059,10 +1065,13 @@
    ;; If the buffer is read-only, we should beep, in case the person
    ;; just isn't aware of this.  However, there's no harm in putting
    ;; the region's text in the kill ring, anyway.
-   ((and buffer-read-only (not inhibit-read-only))
+   ((or (and buffer-read-only (not inhibit-read-only))
+	(text-property-not-all beg end 'read-only nil))
     (copy-region-as-kill beg end)
     ;; This should always barf, and give us the correct error.
-    (barf-if-buffer-read-only))
+    (if kill-read-only-ok
+	(message "Read only text copied to kill ring")
+      (barf-if-buffer-read-only)))
 
    ;; In certain cases, we can arrange for the undo list and the kill
    ;; ring to share the same string object.  This code does that.
@@ -1998,7 +2007,7 @@
   "Kill characters forward until encountering the end of a word.
 With argument, do this that many times."
   (interactive "p")
-  (kill-region (point) (save-excursion (forward-word arg) (point))))
+  (kill-region (point) (progn (forward-word arg) (point))))
 
 (defun backward-kill-word (arg)
   "Kill characters backward until encountering the end of a word.