Subject: Re: bug#79371: [PATCH] Make yank-in-context also can indent the yanked text.

From: Elijah Gabe Pérez <[email-masked]>
Date: Tue, 02 Sep 2025 12:14:07 -0600

Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <[email-masked]> 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.