Mercurial > emacs
comparison lisp/simple.el @ 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 | a517c80bbe8d |
children | 3497b7f6f0e7 |
comparison
equal
deleted
inserted
replaced
7062:6356b8d3144e | 7063:9a0d189fd877 |
---|---|
912 | 912 |
913 If `kill-whole-line' is non-nil, then kill the whole line | 913 If `kill-whole-line' is non-nil, then kill the whole line |
914 when given no argument at the beginning of a line." | 914 when 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) |
923 (signal 'end-of-buffer nil)) | 926 (signal 'end-of-buffer nil)) |
924 (if (or (looking-at "[ \t]*$") (and kill-whole-line (bolp))) | 927 (if (or (looking-at "[ \t]*$") (and kill-whole-line (bolp))) |
1035 | 1038 |
1036 | 1039 |
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. |
1042 The text is deleted but saved in the kill ring. | 1048 The text is deleted but saved in the kill ring. |
1043 The command \\[yank] can retrieve it from there. | 1049 The command \\[yank] can retrieve it from there. |
1044 \(If you want to kill and then yank immediately, use \\[copy-region-as-kill].) | 1050 \(If you want to kill and then yank immediately, use \\[copy-region-as-kill].) |
1057 (cond | 1063 (cond |
1058 | 1064 |
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. |
1069 ((not (or (eq buffer-undo-list t) | 1078 ((not (or (eq buffer-undo-list t) |
1070 (eq last-command 'kill-region) | 1079 (eq last-command 'kill-region) |
1996 | 2005 |
1997 (defun kill-word (arg) | 2006 (defun kill-word (arg) |
1998 "Kill characters forward until encountering the end of a word. | 2007 "Kill characters forward until encountering the end of a word. |
1999 With argument, do this that many times." | 2008 With 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. |
2005 With argument, do this that many times." | 2014 With argument, do this that many times." |
2006 (interactive "p") | 2015 (interactive "p") |