comparison lisp/simple.el @ 1834:9a1f696c1734

* simple.el (kill-region): If the buffer is read-only, do beep, but also put the region in the kill ring. Doc fix.
author Jim Blandy <jimb@redhat.com>
date Mon, 01 Feb 1993 22:31:17 +0000
parents 6ca05c5f8979
children 0b79cade13e3
comparison
equal deleted inserted replaced
1833:ce05243e2491 1834:9a1f696c1734
967 (defun kill-region (beg end) 967 (defun kill-region (beg end)
968 "Kill between point and mark. 968 "Kill between point and mark.
969 The text is deleted but saved in the kill ring. 969 The text is deleted but saved in the kill ring.
970 The command \\[yank] can retrieve it from there. 970 The command \\[yank] can retrieve it from there.
971 \(If you want to kill and then yank immediately, use \\[copy-region-as-kill].) 971 \(If you want to kill and then yank immediately, use \\[copy-region-as-kill].)
972 If the buffer is read-only, Emacs will beep and refrain from deleting
973 the text, but put the text in the kill ring anyway. This means that
974 you can use the killing commands to copy text from a read-only buffer.
972 975
973 This is the primitive for programs to kill text (as opposed to deleting it). 976 This is the primitive for programs to kill text (as opposed to deleting it).
974 Supply two arguments, character numbers indicating the stretch of text 977 Supply two arguments, character numbers indicating the stretch of text
975 to be killed. 978 to be killed.
976 Any command that calls this function is a \"kill command\". 979 Any command that calls this function is a \"kill command\".
977 If the previous command was also a kill command, 980 If the previous command was also a kill command,
978 the text killed this time appends to the text killed last time 981 the text killed this time appends to the text killed last time
979 to make one entry in the kill ring." 982 to make one entry in the kill ring."
980 (interactive "*r") 983 (interactive "r")
981 (cond 984 (cond
982 ;; If the buffer was read-only, we used to just do a 985
983 ;; copy-region-as-kill. This was never what I wanted - usually I 986 ;; If the buffer is read-only, we should beep, in case the person
984 ;; was making a mistake and trying to edit a file checked into RCS - 987 ;; just isn't aware of this. However, there's no harm in putting
985 ;; so I've taken the code out. 988 ;; the region's text in the kill ring, anyway.
989 (buffer-read-only
990 (copy-region-as-kill beg end)
991 (ding))
992
993 ;; In certain cases, we can arrange for the undo list and the kill
994 ;; ring to share the same string object. This code does that.
986 ((not (or (eq buffer-undo-list t) 995 ((not (or (eq buffer-undo-list t)
987 (eq last-command 'kill-region) 996 (eq last-command 'kill-region)
988 (eq beg end))) 997 (eq beg end)))
989 ;; Don't let the undo list be truncated before we can even access it. 998 ;; Don't let the undo list be truncated before we can even access it.
990 (let ((undo-strong-limit (+ (- (max beg end) (min beg end)) 100))) 999 (let ((undo-strong-limit (+ (- (max beg end) (min beg end)) 100)))
991 (delete-region beg end) 1000 (delete-region beg end)
992 ;; Take the same string recorded for undo 1001 ;; Take the same string recorded for undo
993 ;; and put it in the kill-ring. 1002 ;; and put it in the kill-ring.
994 (kill-new (car (car buffer-undo-list))) 1003 (kill-new (car (car buffer-undo-list)))
995 (setq this-command 'kill-region))) 1004 (setq this-command 'kill-region)))
1005
996 (t 1006 (t
997 (copy-region-as-kill beg end) 1007 (copy-region-as-kill beg end)
998 (delete-region beg end)))) 1008 (delete-region beg end))))
999 1009
1000 (defun copy-region-as-kill (beg end) 1010 (defun copy-region-as-kill (beg end)