aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl Heuer1997-11-19 21:36:56 +0000
committerKarl Heuer1997-11-19 21:36:56 +0000
commitccd19b9f49b88df9eb4c994e6db33e97f1c612c0 (patch)
treef47bf0bc574f057d3b6a74859f578cd82df1448b
parent887bbf181d84912e57d1ad0f208a7e3fcde6ba49 (diff)
downloademacs-ccd19b9f49b88df9eb4c994e6db33e97f1c612c0.tar.gz
emacs-ccd19b9f49b88df9eb4c994e6db33e97f1c612c0.zip
(kill-region): Detect read-only text
by getting an error trying to delete it. Handle the cases where we can, and can't, get the killed text from the undo list with much the same code.
-rw-r--r--lisp/simple.el82
1 files changed, 40 insertions, 42 deletions
diff --git a/lisp/simple.el b/lisp/simple.el
index c8c3c9fc52f..5e0687ca364 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -1423,48 +1423,46 @@ If the previous command was also a kill command,
1423the text killed this time appends to the text killed last time 1423the text killed this time appends to the text killed last time
1424to make one entry in the kill ring." 1424to make one entry in the kill ring."
1425 (interactive "r") 1425 (interactive "r")
1426 (cond 1426 (condition-case nil
1427 1427 ;; Don't let the undo list be truncated before we can even access it.
1428 ;; If the buffer is read-only, we should beep, in case the person 1428 (let ((undo-strong-limit (+ (- (max beg end) (min beg end)) 100))
1429 ;; just isn't aware of this. However, there's no harm in putting 1429 (old-list buffer-undo-list)
1430 ;; the region's text in the kill ring, anyway. 1430 tail
1431 ((and (not inhibit-read-only) 1431 ;; If we can't rely on finding the killed text
1432 (or buffer-read-only 1432 ;; in the undo list, save it now as a string.
1433 (text-property-not-all beg end 'read-only nil))) 1433 (string (if (or (eq buffer-undo-list t)
1434 (copy-region-as-kill beg end) 1434 (= beg end))
1435 ;; This should always barf, and give us the correct error. 1435 (buffer-substring beg end))))
1436 (if kill-read-only-ok 1436 (delete-region beg end)
1437 (message "Read only text copied to kill ring") 1437 ;; Search back in buffer-undo-list for this string,
1438 (setq this-command 'kill-region) 1438 ;; in case a change hook made property changes.
1439 ;; Signal an error if the buffer is read-only. 1439 (setq tail buffer-undo-list)
1440 (barf-if-buffer-read-only) 1440 (unless string
1441 ;; If the buffer isn't read-only, the text is. 1441 (while (not (stringp (car (car tail))))
1442 (signal 'text-read-only (list (current-buffer))))) 1442 (setq tail (cdr tail)))
1443 1443 ;; If we did not already make the string to use,
1444 ;; In certain cases, we can arrange for the undo list and the kill 1444 ;; use the same one that undo made for us.
1445 ;; ring to share the same string object. This code does that. 1445 (setq string (car (car tail))))
1446 ((not (or (eq buffer-undo-list t) 1446 ;; Add that string to the kill ring, one way or another.
1447 (eq last-command 'kill-region) 1447 (if (eq last-command 'kill-region)
1448 ;; Use = since positions may be numbers or markers. 1448 (kill-append string (< end beg))
1449 (= beg end))) 1449 (kill-new string))
1450 ;; Don't let the undo list be truncated before we can even access it. 1450 (setq this-command 'kill-region))
1451 (let ((undo-strong-limit (+ (- (max beg end) (min beg end)) 100)) 1451 ((buffer-read-only text-read-only)
1452 (old-list buffer-undo-list) 1452 ;; The code above failed because the buffer, or some of the characters
1453 tail) 1453 ;; in the region, are read-only.
1454 (delete-region beg end) 1454 ;; We should beep, in case the user just isn't aware of this.
1455 ;; Search back in buffer-undo-list for this string, 1455 ;; However, there's no harm in putting
1456 ;; in case a change hook made property changes. 1456 ;; the region's text in the kill ring, anyway.
1457 (setq tail buffer-undo-list) 1457 (copy-region-as-kill beg end)
1458 (while (not (stringp (car (car tail)))) 1458 ;; This should always barf, and give us the correct error.
1459 (setq tail (cdr tail))) 1459 (if kill-read-only-ok
1460 ;; Take the same string recorded for undo 1460 (message "Read only text copied to kill ring")
1461 ;; and put it in the kill-ring. 1461 (setq this-command 'kill-region)
1462 (kill-new (car (car tail))))) 1462 ;; Signal an error if the buffer is read-only.
1463 1463 (barf-if-buffer-read-only)
1464 (t 1464 ;; If the buffer isn't read-only, the text is.
1465 (copy-region-as-kill beg end) 1465 (signal 'text-read-only (list (current-buffer)))))))
1466 (delete-region beg end)))
1467 (setq this-command 'kill-region))
1468 1466
1469;; copy-region-as-kill no longer sets this-command, because it's confusing 1467;; copy-region-as-kill no longer sets this-command, because it's confusing
1470;; to get two copies of the text when the user accidentally types M-w and 1468;; to get two copies of the text when the user accidentally types M-w and