all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Visuwesh <visuweshm@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 55692@debbugs.gnu.org
Subject: bug#55692: 29.0.50; delete-selection-mode: Replace region only if set using the mouse
Date: Sun, 29 May 2022 11:47:32 +0530	[thread overview]
Message-ID: <8735gs9819.fsf@gmail.com> (raw)
In-Reply-To: <83ilpplbhr.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 28 May 2022 22:10:08 +0300")

[-- Attachment #1: Type: text/plain, Size: 800 bytes --]

[சனி மே 28, 2022] Eli Zaretskii wrote:

>> From: Visuwesh <visuweshm@gmail.com>
>> Date: Sat, 28 May 2022 23:03:51 +0530
>> 
>> Motivation: I often find myself annoyed by `delete-selection-mode' when
>> using the keyboard since the region in Emacs does not translate to text
>> selections in other applications.  On the contrary, I find myself
>> wanting the behaviour of `delete-selection-mode' for regions set using
>> the mouse.  Attached patch adds an user option to do that.
>
> IMO, we shouldn't distinguish between the mouse and shift-selection
> methods of defining the region.  So this feature, if accepted, should
> also treat both methods of defining the region the same.

Considering shift-selection would be convenient as well.  Please check
attached patch.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-delete-selection-mode-Add-user-option-to-delete-temp.patch --]
[-- Type: text/x-patch, Size: 3412 bytes --]

From 49e09eadf09b1848ce3dbe109e557384c99ce94d Mon Sep 17 00:00:00 2001
From: Visuwesh <visuweshm@gmail.com>
Date: Sun, 29 May 2022 11:45:19 +0530
Subject: [PATCH] delete-selection-mode: Add user option to delete temporary
 regions only

* lisp/delsel.el (delete-selection-temporary-regions-only): Add new
user option.
(delete-selection-pre-hook): Respect it.
* doc/emacs/mark.texi (Using Region): Document the new user option.
* etc/NEWS: Announce the new user option. (bug#55692)
---
 doc/emacs/mark.texi |  7 +++++--
 etc/NEWS            |  5 +++++
 lisp/delsel.el      | 12 ++++++++++++
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/doc/emacs/mark.texi b/doc/emacs/mark.texi
index 91c44d527b..1b53c2c478 100644
--- a/doc/emacs/mark.texi
+++ b/doc/emacs/mark.texi
@@ -291,13 +291,16 @@ Using Region
 @cindex Delete Selection mode
 @cindex mode, Delete Selection
 @findex delete-selection-mode
+@vindex delete-selection-temporary-regions-only
   By default, text insertion occurs normally even if the mark is
 active---for example, typing @kbd{a} inserts the character @samp{a},
 then deactivates the mark.  Delete Selection mode, a minor mode,
 modifies this behavior: if you enable that mode, then inserting text
 while the mark is active causes the text in the region to be deleted
-first.  To toggle Delete Selection mode on or off, type @kbd{M-x
-delete-selection-mode}.
+first.  If you want to replace only temporary regions, set by
+mouse-dragging or shift-selection, then change the variable
+@code{delete-selection-temporary-regions-only} to @code{t}.  To toggle
+Delete Selection mode on or off, type @kbd{M-x delete-selection-mode}.

 @node Mark Ring
 @section The Mark Ring
diff --git a/etc/NEWS b/etc/NEWS
index 85a0ee44b9..3016c62db0 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -271,6 +271,11 @@ startup.  Previously, these functions ignored
 \f
 * Changes in Emacs 29.1

++++
+** New user option 'delete-selection-temporary-regions-only'.
+When non-nil, 'delete-selection-mode' will only delete the temporary
+regions (usually set by mouse-dragging or shift-selection).
+
 +++
 ** New user option 'switch-to-prev-buffer-skip-regexp'.
 This should be a regexp or a list of regexps; buffers whose names
diff --git a/lisp/delsel.el b/lisp/delsel.el
index f5fe7cf793..7ee41ff2a7 100644
--- a/lisp/delsel.el
+++ b/lisp/delsel.el
@@ -64,6 +64,14 @@ delete-selection-save-to-register
   "If non-nil, deleted region text is stored in this register.
 Value must be the register (key) to use.")

+(defcustom delete-selection-temporary-regions-only nil
+  "Whether to delete only temporary regions.
+When non-nil, typed text only replaces temporary regions (usually
+set by mouse-dragging or shift-selection)."
+  :version "29.1"
+  :group 'editing-basics
+  :type 'boolean)
+
 ;;;###autoload
 (defalias 'pending-delete-mode 'delete-selection-mode)

@@ -251,6 +259,10 @@ delete-selection-pre-hook
 have this property won't delete the selection.
 See `delete-selection-helper'."
   (when (and delete-selection-mode (use-region-p)
+             (if delete-selection-temporary-regions-only
+                 (and (consp transient-mark-mode)
+                      (eq (car transient-mark-mode) 'only))
+               t)
 	     (not buffer-read-only))
     (delete-selection-helper (and (symbolp this-command)
                                   (get this-command 'delete-selection)))))
--
2.33.1

  reply	other threads:[~2022-05-29  6:17 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-28 17:33 bug#55692: 29.0.50; delete-selection-mode: Replace region only if set using the mouse Visuwesh
2022-05-28 19:10 ` Eli Zaretskii
2022-05-29  6:17   ` Visuwesh [this message]
2022-05-29  6:52     ` Eli Zaretskii
2022-05-29  8:10       ` Visuwesh
2022-05-29  9:04         ` Eli Zaretskii
2022-05-29 14:53           ` Visuwesh
2022-05-29 17:10             ` Eli Zaretskii
2022-05-31 10:44               ` Visuwesh
2022-05-31 14:33                 ` Drew Adams
2022-06-01 16:04                 ` Eli Zaretskii
2022-06-01 17:03                   ` Visuwesh
2022-09-06 10:59                     ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8735gs9819.fsf@gmail.com \
    --to=visuweshm@gmail.com \
    --cc=55692@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.