If the buffer is read-only, Emacs will beep and refrain from deleting
the rectangle, but put it in `killed-rectangle' anyway. This means that
-you can use this command to copy text from a read-only buffer.
-\(If the variable `kill-read-only-ok' is non-nil, then this won't
-even beep.)"
+you can use this command to copy text from a read-only buffer."
(interactive "r\nP")
- (condition-case nil
- (let (indent-tabs-mode)
- (setq killed-rectangle (delete-extract-rectangle start end fill)))
- ((buffer-read-only text-read-only)
- (setq deactivate-mark t)
- (setq killed-rectangle (extract-rectangle start end))
- (if kill-read-only-ok
- (progn (message "Read only text copied to `killed-rectangle'") nil)
- (barf-if-buffer-read-only)
- (signal 'text-read-only (list (current-buffer)))))))
+ (let (indent-tabs-mode)
+ (setq killed-rectangle (delete-extract-rectangle start end fill))))
;;;###autoload
(defun copy-rectangle-as-kill (start end)
(let (rectangle-mark-mode) (region-beginning))
(let (rectangle-mark-mode) (region-end))))
(str (mapconcat #'identity strs "\n")))
- (when (eq last-command 'kill-region)
- ;; Try to prevent kill-region from appending this to some
- ;; earlier element.
- (setq last-command 'kill-region-dont-append))
(when strs
(put-text-property 0 (length str) 'yank-handler
`(rectangle--insert-for-yank ,strs t)
(= n 1))
;; If a region is active, kill or delete it.
(if (eq delete-active-region 'kill)
- (kill-region (region-beginning) (region-end) 'region)
+ (kill-region (region-beginning) (region-end))
(funcall region-extract-function 'delete-only)))
;; In Overwrite mode, maybe untabify while deleting
((null (or (null overwrite-mode)
(= n 1))
;; If a region is active, kill or delete it.
(if (eq delete-active-region 'kill)
- (kill-region (region-beginning) (region-end) 'region)
+ (kill-region (region-beginning) (region-end))
(funcall region-extract-function 'delete-only)))
;; For forward deletion, treat composed characters as a single
;;;; Commands for manipulating the kill ring.
-(defcustom kill-read-only-ok nil
- "Non-nil means don't signal an error for killing read-only text."
- :type 'boolean
- :group 'killing)
+(defvar kill-read-only-ok nil "Unused obsolete variable.")
+(make-obsolete-variable 'kill-read-only-ok nil "31.1")
-(defcustom kill-region-dwim nil
- "Behavior when `kill-region' is invoked without an active region.
+(defcustom kill-region-dwim t
+ "Whether `kill-region' kills last word when region is not active.
If set to nil (default), kill the region even if it is inactive,
-signalling an error if there is no region.
-If set to `emacs-word', kill the last word as defined by the
-current major mode.
-If set to `unix-word', kill the last word in the style of a shell like
-Bash. This ignores the major mode like `unix-word-rubout' (which see)."
- :type '(choice (const :tag "Kill a word like `backward-kill-word'" emacs-word)
- (const :tag "Kill a word like Bash would" unix-word)
- (const :tag "Do not kill anything" nil))
+signalling an error if there is no region. Otherwise, kill the last
+word instead."
+ :type 'boolean
:group 'killing
:version "31.1")
-(defun kill-region (beg end &optional region)
+(defun kill-region (beg end &optional _ignored)
"Kill (\"cut\") text between point and mark.
This deletes the text from the buffer and saves it in the kill ring.
The command \\[yank] can retrieve it from there.
the text, but put the text in the kill ring anyway. This means that
you can use the killing commands to copy text from a read-only buffer.
-Lisp programs should use this function for killing text.
- (To delete text, use `delete-region'.)
-Supply two arguments, character positions BEG and END indicating the
- stretch of text to be killed. If the optional argument REGION is
- `region', the function ignores BEG and END, and kills the current
- region instead. Interactively, REGION is always non-nil, and so
- this command always kills the current region. It is possible to
- override this behavior by customising the user option
- `kill-region-dwim'."
+Lisp programs should use this function for killing text. (To delete
+text, use `delete-region'.) Supply two arguments, character positions
+BEG and END indicating the stretch of text to be killed."
;; Pass mark first, then point, because the order matters when
;; calling `kill-append'.
- (interactive (progn
- (let ((beg (mark))
- (end (point)))
- (cond
- ((and kill-region-dwim (not (use-region-p)))
- (list beg end kill-region-dwim))
- ((not (or beg end))
- (user-error "The mark is not set now, so there is no region"))
- ((list beg end 'region))))))
-
- (condition-case nil
- (let ((string (cond
- ((memq region '(unix-word emacs-word))
- (let ((end (point)))
- (save-excursion
- (if (eq region 'emacs-word)
- (forward-word -1)
- (forward-unix-word -1))
- (filter-buffer-substring (point) end 'delete))))
- (region
- (funcall region-extract-function 'delete))
- ((filter-buffer-substring beg end 'delete)))))
- (when string ;STRING is nil if BEG = END
- ;; Add that string to the kill ring, one way or another.
- (if (eq last-command 'kill-region)
- (kill-append string (< end beg))
- (kill-new string)))
- (when (or string (eq last-command 'kill-region))
- (setq this-command 'kill-region))
- (setq deactivate-mark t)
- nil)
- ((buffer-read-only text-read-only)
- ;; The code above failed because the buffer, or some of the characters
- ;; in the region, are read-only.
- ;; We should beep, in case the user just isn't aware of this.
- ;; However, there's no harm in putting
- ;; the region's text in the kill ring, anyway.
- (copy-region-as-kill beg end region)
- ;; Set this-command now, so it will be set even if we get an error.
- (setq this-command 'kill-region)
- ;; This should barf, if appropriate, and give us the correct error.
- (if kill-read-only-ok
- (progn (message "Read only text copied to kill ring") nil)
- ;; Signal an error if the buffer is read-only.
- (barf-if-buffer-read-only)
- ;; If the buffer isn't read-only, the text is.
- (signal 'text-read-only (list (current-buffer)))))))
+ (interactive
+ (cond
+ ((use-region-p)
+ (list (use-region-beginning) (use-region-end)))
+ (kill-region-dwim
+ (list (save-excursion (backward-word) (point)) (point)))
+ (t (list (or (mark t)
+ (user-error "The mark is not set now, so there is no region"))
+ (point)))))
+ (when-let ((string (filter-buffer-substring beg end 'delete)))
+ (kill-new string)
+ (setq deactivate-mark t)))
;; copy-region-as-kill no longer sets this-command, because it's confusing
;; to get two copies of the text when the user accidentally types M-w and
If the buffer is read-only, Emacs will beep and refrain from deleting
the line, but put the line in the kill ring anyway. This means that
-you can use this command to copy text from a read-only buffer.
-\(If the variable `kill-read-only-ok' is non-nil, then this won't
-even beep.)"
+you can use this command to copy text from a read-only buffer."
(interactive "P")
(kill-region (point)
;; It is better to move point to the other end of the kill
;; - Make the first kill-region emit a non-local exit only if the
;; second kill-region below would not operate on a non-empty
;; region.
- (let ((kill-read-only-ok (or kill-read-only-ok
- (/= regions-begin (point)))))
- (kill-region (marker-position regions-begin)
- (marker-position region1-end)))
+ (kill-region (marker-position regions-begin)
+ (marker-position region1-end))
(kill-region (marker-position regions-begin)
(point))
(set-marker regions-begin nil)
If the buffer is read-only, Emacs will beep and refrain from deleting
the line, but put the line in the kill ring anyway. This means that
-you can use this command to copy text from a read-only buffer.
-\(If the variable `kill-read-only-ok' is non-nil, then this won't
-even beep.)"
+you can use this command to copy text from a read-only buffer."
(interactive "P")
;; Like in `kill-line', it's better to move point to the other end
;; of the kill before killing.