From 9026bfb5716de7a6d8ea5df60da942204c32feff Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Wed, 18 Sep 2024 20:20:19 +0300 Subject: [PATCH] More fixes for kill-region-dwim (bug#69097) * lisp/simple.el (kill-region-dwim): Move the default nil to the top of choices. (kill-region): Set the FORCE argument of 'mark' to non-nil if kill-region-dwim is non-nil. That allows everyone to use non-nil kill-region-dwim even if mark-even-if-inactive is nil. Don't check 'last-command' if kill-region-dwim is non-nil. That allows everyone to type C-w twice in a row to delete two previous words. --- etc/NEWS | 2 +- lisp/simple.el | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 8bd5c7c9515..b52ad001a2e 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -142,7 +142,7 @@ you to bind keys to operate more similarly to the terminal. --- ** New user option 'kill-region-dwim'. This option, if non-nil, modifies the fall-back behavior of -'kill-region' if no region is active, and will kill the last word +'kill-region' ('C-w') if no region is active, and will kill the last word instead of raising an error. Note that if you have disabled Transient Mark mode you might prefer to use 'unix-word-rubout', as this feature relies on there being an active region. diff --git a/lisp/simple.el b/lisp/simple.el index 9fbd9bfb577..fcdf644d9d9 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -5825,9 +5825,9 @@ 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 "Kill region even when inactive" nil)) + :type '(choice (const :tag "Kill region even when inactive" nil) + (const :tag "Kill a word like `backward-kill-word'" emacs-word) + (const :tag "Kill a word like Bash would" unix-word)) :group 'killing :version "31.1") @@ -5865,7 +5865,7 @@ Supply two arguments, character positions BEG and END indicating the ;; Pass mark first, then point, because the order matters when ;; calling `kill-append'. (interactive (progn - (let ((beg (mark)) + (let ((beg (mark kill-region-dwim)) (end (point))) (cond ((and kill-region-dwim (not (use-region-p))) @@ -5888,10 +5888,12 @@ Supply two arguments, character positions BEG and END indicating the ((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) + (if (and (not (memq region '(unix-word emacs-word))) + (eq last-command 'kill-region)) (kill-append string (< end beg)) (kill-new string))) - (when (or string (eq last-command 'kill-region)) + (when (and (not (memq region '(unix-word emacs-word))) + (or string (eq last-command 'kill-region))) (setq this-command 'kill-region)) (setq deactivate-mark t) nil)