]> git.eshelyaron.com Git - emacs.git/commitdiff
Simplify 'kill-region'
authorEshel Yaron <me@eshelyaron.com>
Sun, 15 Sep 2024 08:26:10 +0000 (10:26 +0200)
committerEshel Yaron <me@eshelyaron.com>
Sun, 15 Sep 2024 08:26:10 +0000 (10:26 +0200)
14 files changed:
lisp/avy.el
lisp/bindings.el
lisp/delsel.el
lisp/dired.el
lisp/emulation/cua-base.el
lisp/emulation/cua-rect.el
lisp/emulation/viper-cmd.el
lisp/ibuf-ext.el
lisp/menu-bar.el
lisp/mouse.el
lisp/org/org-archive.el
lisp/rect.el
lisp/replace.el
lisp/simple.el

index cba9348d44b7130a5f333dfcf6b74ecae911dda1..02937a1ec8d2905d955b02b8967a873c4c2d9af8 100644 (file)
@@ -2058,8 +2058,7 @@ newline."
         (if (not (numberp start))
             (user-error "Fail to select the line to kill")
           (save-excursion
-            (let ((kill-read-only-ok t)
-                  (buffer-read-only t))
+            (let ((buffer-read-only t))
               (goto-char start)
               (kill-whole-line arg))))))
     (select-window initial-window)))
index fabaa93eeaca6e32281a654c9dba313c75037705..a41f113f303ac75fbeb560f9f0b24e8f3130bbb7 100644 (file)
@@ -1411,16 +1411,6 @@ if `inhibit-field-text-motion' is non-nil."
 ;; can use S-tab instead to access that binding.
 (define-key function-key-map [S-tab] [backtab])
 
-(defun ignore-preserving-kill-region (&rest _)
-  "Like `ignore', but don't overwrite `last-event' if it's `kill-region'."
-  (declare (completion ignore))
-  (interactive)
-  (when (eq last-command 'kill-region)
-    (setq this-command 'kill-region))
-  nil)
-
-(define-key global-map [mouse-movement] #'ignore-preserving-kill-region)
-
 (define-key global-map "\C-t" 'transpose-chars)
 (define-key esc-map "t" 'transpose-words)
 (define-key esc-map "\C-t" 'transpose-sexps)
index 3c0206bda92532513c2491d6caae88449fd27bae..8a7002eb965bf660884a4ac5508e6c72c919e77f 100644 (file)
@@ -105,9 +105,7 @@ the active region is killed instead of deleted."
   (interactive "P")
   (cond
    (killp
-    ;; Don't allow `kill-region' to change the value of `this-command'.
-    (let (this-command)
-      (kill-region (point) (mark) t)))
+    (kill-region (point) (mark)))
    (delete-selection-save-to-register
     (set-register delete-selection-save-to-register
                   (funcall region-extract-function t))
index b33d043790b51b0d7f517ef946dfed0bafc576d7..72ce20449b4f5e1aa2fdc73abe450aba51065741 100644 (file)
@@ -3454,9 +3454,7 @@ You can then feed the file name(s) to other commands with \\[yank]."
                        files
                        " "))))
     (unless (string= string "")
-      (if (eq last-command 'kill-region)
-          (kill-append string nil)
-        (kill-new string))
+      (kill-new string)
       (message "%s" string))))
 
 \f
index c674a6b7a4ddf0d496ef3e0523239d4830fdeecb..532d2c34d3fa6a63d930b227db78fee87f162741 100644 (file)
@@ -824,9 +824,9 @@ With numeric prefix arg, copy to register 0-9 instead."
        (cua--register
        (copy-to-register cua--register start end t 'region))
        ((eq this-original-command 'clipboard-kill-region)
-       (clipboard-kill-region start end 'region))
+       (clipboard-kill-region start end))
        (t
-       (kill-region start end 'region))))
+       (kill-region start end))))
     (cua--deactivate)))
 
 ;;; Generic commands for regions, rectangles, and global marks
index e50924dbd1fd4fe44c0e25744597aa03a9570d5f..bdb87f99e69b3d416702a69bfff4cccf2a6ca370 100644 (file)
@@ -1467,10 +1467,6 @@ With prefix arg, indent to that column."
       (setq killed-rectangle strs)
       (setq cua--last-killed-rectangle
             (cons (and kill-ring (car kill-ring)) killed-rectangle))
-      (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)
index 192eb99a570a15caa8d76e686d2e6ec1a4bd5af0..bfe1cca9f8702ecababcff7212041f9bcff8c245 100644 (file)
@@ -1264,8 +1264,6 @@ as a Meta key and any number of multiple escapes are allowed."
                (t (setq viper-use-register nil)
                 (error viper-InvalidRegister viper-use-register)))
          (setq viper-use-register nil)))
-    (setq last-command
-         (if (eq last-command 'd-command) 'kill-region nil))
     (setq chars-deleted (abs (- (point) viper-com-point)))
     (if (> chars-deleted viper-change-notification-threshold)
        (unless (viper-is-in-minibuffer)
@@ -1291,8 +1289,6 @@ as a Meta key and any number of multiple escapes are allowed."
                  (t (setq viper-use-register nil)
                     (error viper-InvalidRegister viper-use-register)))
            (setq viper-use-register nil)))
-      (setq last-command
-           (if (eq last-command 'D-command) 'kill-region nil))
       (setq lines-deleted (count-lines (point) viper-com-point))
       (if (> lines-deleted viper-change-notification-threshold)
          (unless (viper-is-in-minibuffer)
index 9cff15c76bea17b2ddcac6051cdf94dda4ab2cd1..b8fc23ec763e22d17be511816b3772dcdb6ab8db 100644 (file)
@@ -1758,9 +1758,7 @@ You can then feed the file name(s) to other commands with \\[yank]."
          (string
           (mapconcat #'identity (delete "" file-names) " ")))
     (unless (string= string "")
-      (if (eq last-command 'kill-region)
-          (kill-append string nil)
-        (kill-new string))
+      (kill-new string)
       (message "%s" string))))
 
 ;;;###autoload
@@ -1776,9 +1774,7 @@ You can then feed the file name(s) to other commands with \\[yank]."
                              (list (ibuffer-current-buffer))))))
          (string (mapconcat #'buffer-name buffers " ")))
     (unless (string= string "")
-      (if (eq last-command 'kill-region)
-          (kill-append string nil)
-        (kill-new string))
+      (kill-new string)
       (message "%s" string))))
 
 (defun ibuffer-mark-on-buffer (func &optional ibuffer-mark-on-buffer-mark group)
index 6c27bd6d921a37f24e7ba13375abea3a6cdc9121..7069cbf08c591a3308cf0187139bda7bb4838ae1 100644 (file)
@@ -640,13 +640,11 @@ BEG and END, and saves the current region instead."
   (let ((select-enable-clipboard t))
     (kill-ring-save beg end region)))
 
-(defun clipboard-kill-region (beg end &optional region)
-  "Kill the region, and save it in the GUI's clipboard.
-If the optional argument REGION is non-nil, the function ignores
-BEG and END, and kills the current region instead."
+(defun clipboard-kill-region (beg end &optional _ignored)
+  "Kill the region from BEG to END, and save it in the GUI's clipboard."
   (interactive "r\np")
   (let ((select-enable-clipboard t))
-    (kill-region beg end region)))
+    (kill-region beg end)))
 
 (defun menu-bar-enable-clipboard ()
   "Make CUT, PASTE and COPY (keys and menu bar items) use the clipboard.
index 65d77762a5e808d42c516fc643d6493894ff6ecf..a6a956f9edf3f1ff3e5b7950a1d25f6ba1b1d765 100644 (file)
@@ -1635,7 +1635,6 @@ is dragged over to."
       (mouse-drag-and-drop-region start-event)
     ;; Give temporary modes such as isearch a chance to turn off.
     (run-hooks 'mouse-leave-buffer-hook)
-    (ignore-preserving-kill-region)
     (mouse-drag-track start-event)))
 
 ;; Inhibit the region-confinement when undoing mouse-drag-region
@@ -1846,8 +1845,7 @@ The region will be defined with mark and point."
                                             nil start-point))
                         ((>= mouse-row bottom)
                          (mouse-scroll-subr start-window (1+ (- mouse-row bottom))
-                                            nil start-point))))))
-                 (ignore-preserving-kill-region)))
+                                            nil start-point))))))))
              map)
            t (lambda ()
                (funcall cleanup)
@@ -2191,7 +2189,7 @@ if `mouse-drag-copy-region' is non-nil)."
           ;; Region already saved in the previous click;
           ;; don't make a duplicate entry, just delete.
           (funcall region-extract-function 'delete-only)
-        (kill-region (mark t) (point) 'region))
+        (kill-region (mark t) (point)))
       (setq mouse-selection-click-count 0)
       (setq mouse-save-then-kill-posn nil))
 
index 53c825ed6f6f09f0c1fe161f15cf82f3b416dd92..c5b69105fc1af491a2addd54ffe1218607a8c3e9 100644 (file)
@@ -304,7 +304,7 @@ direct children of this heading."
            ;; We first only copy, in case something goes wrong
            ;; we need to protect `this-command', to avoid kill-region sets it,
            ;; which would lead to duplication of subtrees
-           (let (this-command) (org-copy-subtree 1 nil t))
+           (org-copy-subtree 1 nil t)
            (set-buffer buffer)
            ;; Enforce Org mode for the archive buffer
            (if (not (derived-mode-p 'org-mode))
index 9300782467913bdbca37d4cb0d9c53af20fa89ac..00def3b527e38d40b1735de8d6ba6218e4d7620b 100644 (file)
@@ -333,20 +333,10 @@ deleted.
 
 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)
@@ -813,10 +803,6 @@ Ignores `line-move-visual'."
                           (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)
index 160dd5db2b1f6aae31c146bbe68213f3c504a30c..76656625f3765dc012fccb8246e96c8652d1d48d 100644 (file)
@@ -1138,8 +1138,6 @@ the kill ring, the \\[delete-matching-lines] command is faster."
     (save-excursion
       (while (and (< (point) rend)
                  (re-search-forward regexp rend t))
-        (unless (zerop count)
-          (setq last-command 'kill-region))
        (kill-region (save-excursion (goto-char (match-beginning 0))
                                      (forward-line 0)
                                      (point))
@@ -1198,8 +1196,6 @@ interactively, also print the number."
     (save-excursion
       (while (and (< (point) rend)
                  (re-search-forward regexp rend t))
-       (unless (zerop count)
-          (setq last-command 'kill-region))
        (copy-region-as-kill (save-excursion (goto-char (match-beginning 0))
                                              (forward-line 0)
                                              (point))
index f80c531cf7a77db7fff77504e1194075ef52dc9a..9361c69879aad363817caca6af678903001d5b86 100644 (file)
@@ -1474,7 +1474,7 @@ the end of the line."
              (= 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)
@@ -1517,7 +1517,7 @@ the actual saved text might be different from what was killed."
              (= 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
@@ -5691,26 +5691,19 @@ move the yanking point; just return the Nth kill forward."
 
 ;;;; 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.
@@ -5732,64 +5725,23 @@ If the buffer is read-only, Emacs will beep and refrain from deleting
 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
@@ -6554,9 +6506,7 @@ use \\[append-next-kill] before \\[kill-line].
 
 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
@@ -6637,10 +6587,8 @@ If ARG is zero, kill current line but exclude the trailing newline."
     ;; - 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)
@@ -8385,9 +8333,7 @@ use \\[append-next-kill] before \\[kill-line].
 
 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.