aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1994-04-24 05:44:23 +0000
committerRichard M. Stallman1994-04-24 05:44:23 +0000
commite6291fe1d67168297f0d2ee32df19dba3d69e42d (patch)
treea4bba413b065612150ead8b6322f2d836506a3b0
parentc5a15222301072c1cefcda253436e4000e473794 (diff)
downloademacs-e6291fe1d67168297f0d2ee32df19dba3d69e42d.tar.gz
emacs-e6291fe1d67168297f0d2ee32df19dba3d69e42d.zip
(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.
-rw-r--r--lisp/simple.el21
1 files changed, 15 insertions, 6 deletions
diff --git a/lisp/simple.el b/lisp/simple.el
index f8f676e59b0..40dc51f08c9 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -914,9 +914,12 @@ If `kill-whole-line' is non-nil, then kill the whole line
914when given no argument at the beginning of a line." 914when given no argument at the beginning of a line."
915 (interactive "P") 915 (interactive "P")
916 (kill-region (point) 916 (kill-region (point)
917 ;; Don't shift point before doing the delete; that way, 917 ;; It is better to move point to the other end of the kill
918 ;; undo will record the right position of point. 918 ;; before killing. That way, in a read-only buffer, point
919 (save-excursion 919 ;; moves across the text that is copied to the kill ring.
920 ;; The choice has no effect on undo now that undo records
921 ;; the value of point from before the command was run.
922 (progn
920 (if arg 923 (if arg
921 (forward-line (prefix-numeric-value arg)) 924 (forward-line (prefix-numeric-value arg))
922 (if (eobp) 925 (if (eobp)
@@ -1037,6 +1040,9 @@ yanking point; just return the Nth kill forward."
1037 1040
1038;;;; Commands for manipulating the kill ring. 1041;;;; Commands for manipulating the kill ring.
1039 1042
1043(defvar kill-read-only-ok nil
1044 "*Non-nil means don't signal an error for killing read-only text.")
1045
1040(defun kill-region (beg end) 1046(defun kill-region (beg end)
1041 "Kill between point and mark. 1047 "Kill between point and mark.
1042The text is deleted but saved in the kill ring. 1048The text is deleted but saved in the kill ring.
@@ -1059,10 +1065,13 @@ to make one entry in the kill ring."
1059 ;; If the buffer is read-only, we should beep, in case the person 1065 ;; If the buffer is read-only, we should beep, in case the person
1060 ;; just isn't aware of this. However, there's no harm in putting 1066 ;; just isn't aware of this. However, there's no harm in putting
1061 ;; the region's text in the kill ring, anyway. 1067 ;; the region's text in the kill ring, anyway.
1062 ((and buffer-read-only (not inhibit-read-only)) 1068 ((or (and buffer-read-only (not inhibit-read-only))
1069 (text-property-not-all beg end 'read-only nil))
1063 (copy-region-as-kill beg end) 1070 (copy-region-as-kill beg end)
1064 ;; This should always barf, and give us the correct error. 1071 ;; This should always barf, and give us the correct error.
1065 (barf-if-buffer-read-only)) 1072 (if kill-read-only-ok
1073 (message "Read only text copied to kill ring")
1074 (barf-if-buffer-read-only)))
1066 1075
1067 ;; In certain cases, we can arrange for the undo list and the kill 1076 ;; In certain cases, we can arrange for the undo list and the kill
1068 ;; ring to share the same string object. This code does that. 1077 ;; ring to share the same string object. This code does that.
@@ -1998,7 +2007,7 @@ In programs, it is faster to call `forward-word' with negative arg."
1998 "Kill characters forward until encountering the end of a word. 2007 "Kill characters forward until encountering the end of a word.
1999With argument, do this that many times." 2008With argument, do this that many times."
2000 (interactive "p") 2009 (interactive "p")
2001 (kill-region (point) (save-excursion (forward-word arg) (point)))) 2010 (kill-region (point) (progn (forward-word arg) (point))))
2002 2011
2003(defun backward-kill-word (arg) 2012(defun backward-kill-word (arg)
2004 "Kill characters backward until encountering the end of a word. 2013 "Kill characters backward until encountering the end of a word.