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.
This commit is contained in:
Juri Linkov 2024-09-18 20:20:19 +03:00
parent 3924730200
commit 9026bfb571
2 changed files with 9 additions and 7 deletions

View file

@ -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.

View file

@ -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)