GNU bug report logs - #73782
[PATCH] Add `delete-selection-local-mode'.

Previous Next

Package: emacs;

Reported by: Okamsn <okamsn <at> protonmail.com>

Date: Sun, 13 Oct 2024 02:05:02 UTC

Severity: wishlist

Tags: patch

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 73782 in the body.
You can then email your comments to 73782 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#73782; Package emacs. (Sun, 13 Oct 2024 02:05:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Okamsn <okamsn <at> protonmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 13 Oct 2024 02:05:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Okamsn <okamsn <at> protonmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] Add `delete-selection-local-mode'.
Date: Sun, 13 Oct 2024 01:25:28 +0000
[Message part 1 (text/plain, inline)]
Hello,

This patch adds a local version of `delete-selection-mode`. I use a 
modal editing package for which I would like to have 
`delete-selection-mode` enabled depending on the modal state that is 
active in the buffer. This doesn't currently work because 
`delete-selection-mode` applies to all buffers.

For compatibility, I made the local mode set the value of the variable 
`delete-selection-mode` buffer locally. I see that some features, such 
as the built-in `table.el`, check that variable to adjust their 
behavior. Do you think that is a good way to maintain compatibility?

Thank you.
[0001-Add-delete-selection-local-mode.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#73782; Package emacs. (Sun, 13 Oct 2024 05:40:02 GMT) Full text and rfc822 format available.

Message #8 received at 73782 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Okamsn <okamsn <at> protonmail.com>, Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 73782 <at> debbugs.gnu.org
Subject: Re: bug#73782: [PATCH] Add `delete-selection-local-mode'.
Date: Sun, 13 Oct 2024 08:38:38 +0300
> Date: Sun, 13 Oct 2024 01:25:28 +0000
> From:  Okamsn via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
> 
> This patch adds a local version of `delete-selection-mode`. I use a 
> modal editing package for which I would like to have 
> `delete-selection-mode` enabled depending on the modal state that is 
> active in the buffer. This doesn't currently work because 
> `delete-selection-mode` applies to all buffers.

Thanks.  This feature needs a NEWS entry, and maybe also a suitable
change to the user manual.

> For compatibility, I made the local mode set the value of the variable 
> `delete-selection-mode` buffer locally. I see that some features, such 
> as the built-in `table.el`, check that variable to adjust their 
> behavior. Do you think that is a good way to maintain compatibility?

SGTM, but I'd like to hear from Stefan (CC'ed) as well.




Severity set to 'wishlist' from 'normal' Request was from Stefan Kangas <stefankangas <at> gmail.com> to control <at> debbugs.gnu.org. (Sun, 13 Oct 2024 09:15:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#73782; Package emacs. (Thu, 17 Oct 2024 17:08:02 GMT) Full text and rfc822 format available.

Message #13 received at 73782 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Okamsn <okamsn <at> protonmail.com>
Cc: 73782 <at> debbugs.gnu.org
Subject: Re: bug#73782: [PATCH] Add `delete-selection-local-mode'.
Date: Thu, 17 Oct 2024 13:07:27 -0400
> +(define-minor-mode delete-selection-local-mode
> +  "Toggle Delete Selection mode in the current buffer.
> +
> +See the command `delete-selection-mode'.
> +
> +For compatibility with features and packages that are aware of
> +`delete-selection-mode', this mode also sets the
> +variable `delete-selection-mode' in the current buffer."
> +  :global nil :group 'editing-basics

Have you tried to use the `:variable (buffer-local-value
'delete-selection-mode)` instead of introducing a parallel
`delete-selection-local-mode` variable?


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#73782; Package emacs. (Thu, 24 Oct 2024 03:25:02 GMT) Full text and rfc822 format available.

Message #16 received at 73782 <at> debbugs.gnu.org (full text, mbox):

From: Okamsn <okamsn <at> protonmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 73782 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>
Subject: Re: bug#73782: [PATCH] Add `delete-selection-local-mode'.
Date: Thu, 24 Oct 2024 03:24:14 +0000
[Message part 1 (text/plain, inline)]
Stefan Monnier wrote:
>> +(define-minor-mode delete-selection-local-mode
>> +  "Toggle Delete Selection mode in the current buffer.
>> +
>> +See the command `delete-selection-mode'.
>> +
>> +For compatibility with features and packages that are aware of
>> +`delete-selection-mode', this mode also sets the
>> +variable `delete-selection-mode' in the current buffer."
>> +  :global nil :group 'editing-basics
> 
> Have you tried to use the `:variable (buffer-local-value
> 'delete-selection-mode)` instead of introducing a parallel
> `delete-selection-local-mode` variable?
> 
> 
>          Stefan
> 

I had not thought to try that. Attached is a patch which uses 
`buffer-local-value` as a `setf`-able place. I had to include the third 
argument `(current-buffer)`.

Do you think that disabling the local mode should remove the 
buffer-local version of `delete-selection-mode` via 
`kill-local-variable`? It seems that once the variable is made buffer 
local, the global mode can't take effect in the buffer, even when the 
local mode is disabled.

If you do think that the local version of the variable should be 
removed, do you think that it should be removed selectively or always?

Thank you.
[v3-0001-Add-delete-selection-local-mode.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#73782; Package emacs. (Thu, 24 Oct 2024 14:03:02 GMT) Full text and rfc822 format available.

Message #19 received at 73782 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Okamsn <okamsn <at> protonmail.com>
Cc: 73782 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>
Subject: Re: bug#73782: [PATCH] Add `delete-selection-local-mode'.
Date: Thu, 24 Oct 2024 10:01:36 -0400
> Do you think that disabling the local mode should remove the
> buffer-local version of `delete-selection-mode` via
> `kill-local-variable`? It seems that once the variable is made buffer
> local, the global mode can't take effect in the buffer, even when the
> local mode is disabled.

In `electric-indent-local-mode` I faced the same question and wasn't
completely sure but I opted somewhat arbitrarily to do the
`kill-local-variable` whenever applicable.
I still don't know if it's the better choice, but FWIW, nobody's
complained about it:

      (cond
       ((eq electric-indent-mode (default-value 'electric-indent-mode))
        (kill-local-variable 'electric-indent-mode))

> * lisp/delsel.el (delete-selection-pre-hook): Check whether local mode
> is active.

AFAICT you don't change `delete-selection-pre-hook` any more.

> * doc/emacs/mark.texi (Using Region): Describe
> delete-selection-local-mode.
> +;;;###autoload
> +(define-minor-mode delete-selection-local-mode
> +  "Toggle Delete Selection mode in the current buffer.
> +
> +See the command `delete-selection-mode'.

FWIW, for `electric-indent-local-mode` I went for something shorter:

   "Toggle `electric-indent-mode' only in this buffer."


- Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#73782; Package emacs. (Sat, 26 Oct 2024 18:16:02 GMT) Full text and rfc822 format available.

Message #22 received at 73782 <at> debbugs.gnu.org (full text, mbox):

From: Okamsn <okamsn <at> protonmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 73782 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>
Subject: Re: bug#73782: [PATCH] Add `delete-selection-local-mode'.
Date: Sat, 26 Oct 2024 18:14:57 +0000
[Message part 1 (text/plain, inline)]
Stefan Monnier wrote:
>> Do you think that disabling the local mode should remove the
>> buffer-local version of `delete-selection-mode` via
>> `kill-local-variable`? It seems that once the variable is made buffer
>> local, the global mode can't take effect in the buffer, even when the
>> local mode is disabled.
> 
> In `electric-indent-local-mode` I faced the same question and wasn't
> completely sure but I opted somewhat arbitrarily to do the
> `kill-local-variable` whenever applicable.
> I still don't know if it's the better choice, but FWIW, nobody's
> complained about it:
> 
>        (cond
>         ((eq electric-indent-mode (default-value 'electric-indent-mode))
>          (kill-local-variable 'electric-indent-mode))
> 
>> * lisp/delsel.el (delete-selection-pre-hook): Check whether local mode
>> is active.
> 
> AFAICT you don't change `delete-selection-pre-hook` any more.
> 
>> * doc/emacs/mark.texi (Using Region): Describe
>> delete-selection-local-mode.
>> +;;;###autoload
>> +(define-minor-mode delete-selection-local-mode
>> +  "Toggle Delete Selection mode in the current buffer.
>> +
>> +See the command `delete-selection-mode'.
> 
> FWIW, for `electric-indent-local-mode` I went for something shorter:
> 
>     "Toggle `electric-indent-mode' only in this buffer."
> 
> 
> - Stefan
> 

Hello,

Please see the attached patch with the changes you suggested.

Thank you.
[v4-0001-Add-delete-selection-local-mode.patch (text/x-patch, attachment)]

Reply sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
You have taken responsibility. (Sat, 26 Oct 2024 18:55:02 GMT) Full text and rfc822 format available.

Notification sent to Okamsn <okamsn <at> protonmail.com>:
bug acknowledged by developer. (Sat, 26 Oct 2024 18:55:02 GMT) Full text and rfc822 format available.

Message #27 received at 73782-done <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Okamsn <okamsn <at> protonmail.com>
Cc: 73782-done <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>
Subject: Re: bug#73782: [PATCH] Add `delete-selection-local-mode'.
Date: Sat, 26 Oct 2024 14:53:21 -0400
> Please see the attached patch with the changes you suggested.

Thanks, pushed, closing,


        Stefan





bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 24 Nov 2024 12:24:16 GMT) Full text and rfc822 format available.

This bug report was last modified 263 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.