GNU bug report logs - #55828
Add command to edit a rectangle arbitrarily in a separate buffer

Previous Next

Package: emacs;

Reported by: Phil Sainty <psainty <at> orcon.net.nz>

Date: Tue, 7 Jun 2022 09:25:01 UTC

Severity: wishlist

To reply to this bug, email your comments to 55828 AT debbugs.gnu.org.

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#55828; Package emacs. (Tue, 07 Jun 2022 09:25:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Phil Sainty <psainty <at> orcon.net.nz>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 07 Jun 2022 09:25:01 GMT) Full text and rfc822 format available.

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

From: Phil Sainty <psainty <at> orcon.net.nz>
To: bug-gnu-emacs <at> gnu.org
Cc: Michael Heerdegen <michael_heerdegen <at> web.de>
Subject: Add command to edit a rectangle arbitrarily in a separate buffer
Date: Tue, 07 Jun 2022 21:24:30 +1200
[Message part 1 (text/plain, inline)]
At https://debbugs.gnu.org/cgi/bugreport.cgi?bug=55234#11 Michael 
Heerdegen wrote:
> I implemented a command that lets me edit a rectangular region
> in a separate buffer

I've had one of those for years as well, and always intended to
work on it some more and propose it as a standard feature.

I bind it to "C-x r e", with "C-c C-c" to write the rectangle back
to the original buffer after editing.

There are a lot of special-purpose "do X to a rectangle" commands,
but I think a command which lets you do *absolutely anything* to
a rectangle is extremely useful, and a buffer with only that text
gives you that ability pretty trivially.  I think Emacs should have
this in its standard rectangle toolkit; so here's a new feature
request for that.

For reference I've attached my version.  It's old code which knows
nothing of `rectangle-mark-mode' or other newer things, and it has
the notable flaw of introducing trailing whitespace if the rectangular
region had intersected any line endings (something I'd intended to
address before suggesting this); but it's always done the job when
I've needed it, so I'm attaching it as-is (aside from renaming it to
`rectangle-edit' which seems to be an available name-space for such
a feature).

It sounds to me as if Michael's code does more than mine -- at minimum
mine does not ask what to do with modified dimensions as described at
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=55234#17 (I just use the
original dimensions), so I'd be interested to see that.


-Phil
[rectangle-edit.el (text/x-lisp, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#55828; Package emacs. (Wed, 08 Jun 2022 07:03:01 GMT) Full text and rfc822 format available.

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

From: Juri Linkov <juri <at> linkov.net>
To: Phil Sainty <psainty <at> orcon.net.nz>
Cc: Michael Heerdegen <michael_heerdegen <at> web.de>, 55828 <at> debbugs.gnu.org
Subject: Re: bug#55828: Add command to edit a rectangle arbitrarily in a
 separate buffer
Date: Wed, 08 Jun 2022 09:58:55 +0300
> It sounds to me as if Michael's code does more than mine -- at minimum
> mine does not ask what to do with modified dimensions as described at
> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=55234#17 (I just use the
> original dimensions), so I'd be interested to see that.

As Michael pointed out, it could be based on string-edit,
so rectangle-edit could just call string-edit with the rectangle
as a string, and success-callback to replace the original rectangle
with the edited string.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#55828; Package emacs. (Wed, 08 Jun 2022 09:58:02 GMT) Full text and rfc822 format available.

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

From: Phil Sainty <psainty <at> orcon.net.nz>
To: Juri Linkov <juri <at> linkov.net>
Cc: Michael Heerdegen <michael_heerdegen <at> web.de>, 55828 <at> debbugs.gnu.org
Subject: Re: bug#55828: Add command to edit a rectangle arbitrarily in a
 separate buffer
Date: Wed, 08 Jun 2022 21:57:52 +1200
On 2022-06-08 18:58, Juri Linkov wrote:
> As Michael pointed out, it could be based on string-edit,

Perhaps.  I just compiled from master to have a look at this,
and I don't know whether that's an obvious way to go.  I'm not
seeing a particularly nice way to pass the information about the
source of the rectangle through to the success callback, unless
that function was a closure generated at call time, or the data
was passed as text properties, both of which seem a bit ugly to
me in this scenario (the latter more so than the former, but
neither feels ideal).

Perhaps `string-edit' is missing a `data' argument to be passed
along to the callback functions?

There's also no obvious facility for preparing the edit buffer.
In my command I'm setting the syntax-table to match the original
buffer, and setting fill-column to the rectangle width, both of
which seem like sensible things for the purpose at hand; but
there's no way of doing such things with `string-edit' other
than `string-edit-mode-hook' which I think is going to be
awkward to deal with for such a purpose.  I guess you can
let-bind the hook variable around the `string-edit' call to add
a set-up function, but it again feels like there should be a
nicer option.

It does provide some boilerplate, but I'm not sure it makes
sense to shoe-horn the rectangle command into that framework
in its current form.  Maybe with some enhancements it makes
sense, though.


-Phil





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#55828; Package emacs. (Wed, 08 Jun 2022 16:30:03 GMT) Full text and rfc822 format available.

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

From: Juri Linkov <juri <at> linkov.net>
To: Phil Sainty <psainty <at> orcon.net.nz>
Cc: Michael Heerdegen <michael_heerdegen <at> web.de>, 55828 <at> debbugs.gnu.org
Subject: Re: bug#55828: Add command to edit a rectangle arbitrarily in a
 separate buffer
Date: Wed, 08 Jun 2022 19:18:01 +0300
> It does provide some boilerplate, but I'm not sure it makes
> sense to shoe-horn the rectangle command into that framework
> in its current form.  Maybe with some enhancements it makes
> sense, though.

The initial version of string-edit is only 1 month old.
So you are welcome to propose any improvements that
will make it more useful for different use cases.




Severity set to 'wishlist' from 'normal' Request was from Stefan Kangas <stefan <at> marxist.se> to control <at> debbugs.gnu.org. (Sun, 19 Jun 2022 13:54:02 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 360 days ago.

Previous Next


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