GNU bug report logs - #79371
[PATCH] Make yank-in-context also can indent the yanked text.

Previous Next

Package: emacs;

Reported by: Elijah Gabe Pérez <eg642616 <at> gmail.com>

Date: Tue, 2 Sep 2025 15:57:02 UTC

Severity: normal

Tags: patch

Full log


View this message in rfc822 format

From: Elijah Gabe Pérez <eg642616 <at> gmail.com>
To: 79371 <at> debbugs.gnu.org
Cc: monnier <at> iro.umontreal.ca
Subject: bug#79371: [PATCH] Make yank-in-context also can indent the yanked text.
Date: Tue, 02 Sep 2025 13:14:34 -0600
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.




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.