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





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.