GNU bug report logs -
#79371
[PATCH] Make yank-in-context also can indent the yanked text.
Previous Next
To reply to this bug, email your comments to 79371 AT debbugs.gnu.org.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#79371
; Package
emacs
.
(Tue, 02 Sep 2025 15:57:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Elijah Gabe Pérez <eg642616 <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Tue, 02 Sep 2025 15:57:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Tags: patch
This patch makes `yank-in-context` can optionally indent the yanked
text.
The indentation is done calling `indent-region`, but the function to use
can be changed.
Additionally, i added support for `delete-selection-mode` in
`yank-in-context`.
[0001-Make-yank-in-context-can-also-indent-the-yanked-text.patch (text/x-patch, attachment)]
[Message part 3 (text/plain, inline)]
--
- E.G via Gnus and Org.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#79371
; Package
emacs
.
(Tue, 02 Sep 2025 16:24:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 79371 <at> debbugs.gnu.org (full text, mbox):
> From: Elijah Gabe Pérez <eg642616 <at> gmail.com>
> Date: Tue, 02 Sep 2025 09:55:55 -0600
>
> This patch makes `yank-in-context` can optionally indent the yanked
> text.
>
> The indentation is done calling `indent-region`, but the function to use
> can be changed.
Thanks, but I wonder whether this indeed justifies yet another user
option, given that indenting the yanked text, if that is desired, can
be obtained by typing C-M-\ immediately after yanking.
What do others think about this?
> Additionally, i added support for `delete-selection-mode` in
> `yank-in-context`.
This should be a separate change, because I believe it is correct to
do that by default regardless of anything else.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#79371
; Package
emacs
.
(Tue, 02 Sep 2025 16:56:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 79371 <at> debbugs.gnu.org (full text, mbox):
> This patch makes `yank-in-context` can optionally indent the yanked text.
[...]
> @@ -6432,8 +6452,12 @@ yank-in-context
> variable to determine how strings should be escaped."
> (interactive "*P")
> (let ((yank-transform-functions (cons #'yank-in-context--transform
> - yank-transform-functions)))
> - (yank arg)))
> + yank-transform-functions))
> + (beg (point)) end)
> + (yank arg)
> + (setq end (point))
> + (if yank-in-context-indent
> + (funcall yank-in-context-indent-function beg end))))
Hmm... what's the intended use case?
`yank-in-context` differs from `yank` only inside strings and comments,
but in most major modes `indent-region` doesn't know how to indent
inside strings and comments because we don't know if it holds plain text
or code or whatnot.
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#79371
; Package
emacs
.
(Tue, 02 Sep 2025 17:01:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 79371 <at> debbugs.gnu.org (full text, mbox):
Hello,
On Tue 02 Sep 2025 at 07:22pm +03, Eli Zaretskii wrote:
>> From: Elijah Gabe Pérez <eg642616 <at> gmail.com>
>> Date: Tue, 02 Sep 2025 09:55:55 -0600
>>
>> This patch makes `yank-in-context` can optionally indent the yanked
>> text.
>>
>> The indentation is done calling `indent-region`, but the function to use
>> can be changed.
>
> Thanks, but I wonder whether this indeed justifies yet another user
> option, given that indenting the yanked text, if that is desired, can
> be obtained by typing C-M-\ immediately after yanking.
>
> What do others think about this?
Sometimes you want indentation and sometimes you don't, so requiring the
user to type C-M-\ seems preferable to me, too.
--
Sean Whitton
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#79371
; Package
emacs
.
(Tue, 02 Sep 2025 18:15:01 GMT)
Full text and
rfc822 format available.
Message #17 received at submit <at> debbugs.gnu.org (full text, mbox):
Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <bug-gnu-emacs <at> gnu.org> writes:
>> This patch makes `yank-in-context` can optionally indent the yanked text.
> [...]
>> @@ -6432,8 +6452,12 @@ yank-in-context
>> variable to determine how strings should be escaped."
>> (interactive "*P")
>> (let ((yank-transform-functions (cons #'yank-in-context--transform
>> - yank-transform-functions)))
>> - (yank arg)))
>> + yank-transform-functions))
>> + (beg (point)) end)
>> + (yank arg)
>> + (setq end (point))
>> + (if yank-in-context-indent
>> + (funcall yank-in-context-indent-function beg end))))
>
> Hmm... what's the intended use case?
>
> `yank-in-context` differs from `yank` only inside strings and comments,
> but in most major modes `indent-region` doesn't know how to indent
> inside strings and comments because we don't know if it holds plain text
> or code or whatnot.
This can be fixed not indenting the yanked text if it's in a comment or string.
In my opinion, this feature can be useful since some users often prefer
commands to be automated rather than having to pressing multiple keys.
This can be inconvenient in some cases, but I think it can be useful for
people who know what they're doing.
Another alternative is to create a hook for yank or that electric-indent
can also handle this.
--
- E.G via Gnus and Org.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#79371
; Package
emacs
.
(Tue, 02 Sep 2025 18:15:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#79371
; Package
emacs
.
(Tue, 02 Sep 2025 18:41:02 GMT)
Full text and
rfc822 format available.
Message #23 received at 79371 <at> debbugs.gnu.org (full text, mbox):
>>> This patch makes `yank-in-context` can optionally indent the yanked text.
>> [...]
>>> @@ -6432,8 +6452,12 @@ yank-in-context
>>> variable to determine how strings should be escaped."
>>> (interactive "*P")
>>> (let ((yank-transform-functions (cons #'yank-in-context--transform
>>> - yank-transform-functions)))
>>> - (yank arg)))
>>> + yank-transform-functions))
>>> + (beg (point)) end)
>>> + (yank arg)
>>> + (setq end (point))
>>> + (if yank-in-context-indent
>>> + (funcall yank-in-context-indent-function beg end))))
>>
>> Hmm... what's the intended use case?
>>
>> `yank-in-context` differs from `yank` only inside strings and comments,
>> but in most major modes `indent-region` doesn't know how to indent
>> inside strings and comments because we don't know if it holds plain text
>> or code or whatnot.
>
> This can be fixed not indenting the yanked text if it's in a comment or string.
Ah... so your intended use case is using `yank-in-context` to yank inside code?
I see...
Then why limit it to `yank-in-context`?
[ I see that limiting it to `yank-in-context` means that it's limited to
a command that already cares about the difference between
code/comments/strings. So there's some logic to it. ]
> Another alternative is to create a hook for yank or that electric-indent
> can also handle this.
It also occurred to me that it could make sense to link it to
electric-indent.
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#79371
; Package
emacs
.
(Tue, 02 Sep 2025 19:15:02 GMT)
Full text and
rfc822 format available.
Message #26 received at submit <at> debbugs.gnu.org (full text, mbox):
Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <bug-gnu-emacs <at> gnu.org> writes:
>>>> This patch makes `yank-in-context` can optionally indent the yanked text.
>>> [...]
>>>> @@ -6432,8 +6452,12 @@ yank-in-context
>>>> variable to determine how strings should be escaped."
>>>> (interactive "*P")
>>>> (let ((yank-transform-functions (cons #'yank-in-context--transform
>>>> - yank-transform-functions)))
>>>> - (yank arg)))
>>>> + yank-transform-functions))
>>>> + (beg (point)) end)
>>>> + (yank arg)
>>>> + (setq end (point))
>>>> + (if yank-in-context-indent
>>>> + (funcall yank-in-context-indent-function beg end))))
>>>
>>> Hmm... what's the intended use case?
>>>
>>> `yank-in-context` differs from `yank` only inside strings and comments,
>>> but in most major modes `indent-region` doesn't know how to indent
>>> inside strings and comments because we don't know if it holds plain text
>>> or code or whatnot.
>>
>> This can be fixed not indenting the yanked text if it's in a comment or string.
>
> Ah... so your intended use case is using `yank-in-context` to yank inside code?
> I see...
>
> Then why limit it to `yank-in-context`?
>
> [ I see that limiting it to `yank-in-context` means that it's limited to
> a command that already cares about the difference between
> code/comments/strings. So there's some logic to it. ]
Originally, my idea was to implement this in yank (and its other
commands), but the yank code base is (for some reason) separated into
subr.el, so it was going to be difficult and inconvenient for me, i
decided to add it to `yank-in-context`, since this command is intended
for yanking code[1].
> It also occurred to me that it could make sense to link it to
> electric-indent.
Fine, I'll see how to implement it in electric-indent.
1. Although yank-in-context can also be used outside of prog modes for
non-code text (e.g message-mode), it is buggy for some reason.
--
- E.G via Gnus and Org.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#79371
; Package
emacs
.
(Tue, 02 Sep 2025 19:15:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#79371
; Package
emacs
.
(Tue, 02 Sep 2025 23:12:01 GMT)
Full text and
rfc822 format available.
Message #32 received at submit <at> debbugs.gnu.org (full text, mbox):
>> [ I see that limiting it to `yank-in-context` means that it's limited to
>> a command that already cares about the difference between
>> code/comments/strings. So there's some logic to it. ]
>
> Originally, my idea was to implement this in yank (and its other
> commands), but the yank code base is (for some reason) separated into
> subr.el, so it was going to be difficult and inconvenient for me, i
> decided to add it to `yank-in-context`, since this command is intended
> for yanking code[1].
Yeah, I think it makes sense.
>> It also occurred to me that it could make sense to link it to
>> electric-indent.
> Fine, I'll see how to implement it in electric-indent.
I'm not sure that's such a good idea.
At some point I did consider implementing `electric-indent` in
a different way, which would automatically cover things like `yank`, but
in the end electric-indent is fairly "conservative" in terms of when it
reindents. But conceptually the two are somewhat related, tho your
functionality might be closer to modes like `aggressive-indent-mode`.
If you're careful to place an undo boundary before doing the
`indent-region`, it ends up being a choice between:
- Don't reindent by default, let user hit `C-M-\` if they want to reindent.
- Reindent by default, let user hit `C-/` if they didn't want to reindent.
IOW, I'm rather favorable to your proposition. It seems worth a try.
Tho, maybe you want to pay attention to
(or (memq indent-line-function
electric-indent-functions-without-reindent)
electric-indent-inhibit)
so as not to call `indent-region` when that function is unlikely to do
a good job.
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#79371
; Package
emacs
.
(Tue, 02 Sep 2025 23:12:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#79371
; Package
emacs
.
(Fri, 05 Sep 2025 01:46:02 GMT)
Full text and
rfc822 format available.
Message #38 received at 79371 <at> debbugs.gnu.org (full text, mbox):
Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <bug-gnu-emacs <at> gnu.org> writes:
>> Fine, I'll see how to implement it in electric-indent.
> I'm not sure that's such a good idea.
>
> At some point I did consider implementing `electric-indent` in
> a different way, which would automatically cover things like `yank`, but
> in the end electric-indent is fairly "conservative" in terms of when it
> reindents.
Probably this should be an additional and optional feature for
electric-indent e.g. only indent a region when some command has been
called.
This could extend it to other things, e.g. indent the buffer on save.
> If you're careful to place an undo boundary before doing the
> `indent-region`, it ends up being a choice between:
>
> - Don't reindent by default, let user hit `C-M-\` if they want to reindent.
> - Reindent by default, let user hit `C-/` if they didn't want to reindent.
>
> IOW, I'm rather favorable to your proposition. It seems worth a try.
> Tho, maybe you want to pay attention to
>
> (or (memq indent-line-function
> electric-indent-functions-without-reindent)
> electric-indent-inhibit)
>
> so as not to call `indent-region` when that function is unlikely to do
> a good job.
Thanks, I'll keep that in mind.
--
- E.G via Gnus and Org.
This bug report was last modified 8 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.