GNU bug report logs - #52265
Wishlist: Behavior of rectangles when last line is short

Previous Next

Package: emacs;

Reported by: Tor Kringeland <tor.a.s.kringeland <at> ntnu.no>

Date: Fri, 3 Dec 2021 23:08:01 UTC

Severity: wishlist

Tags: moreinfo

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 52265 in the body.
You can then email your comments to 52265 AT debbugs.gnu.org in the normal way.

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#52265; Package emacs. (Fri, 03 Dec 2021 23:08:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Tor Kringeland <tor.a.s.kringeland <at> ntnu.no>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 03 Dec 2021 23:08:01 GMT) Full text and rfc822 format available.

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

From: Tor Kringeland <tor.a.s.kringeland <at> ntnu.no>
To: bug-gnu-emacs <at> gnu.org
Subject: Wishlist: Behavior of rectangles when last line is short
Date: Sat, 04 Dec 2021 00:06:52 +0100
Suppose we have the following text

text123
more text
text
first
second
third  

and want to turn it into

text123,first
more text,second	
text,third

using rectangles.  This is problematic since the last line is shorter
than the two before.  A solution to this [1] is to add spaces at the end
of the last line until it becomes the longest, mark the last three lines
with POINT being at the end of the spaces and then kill the rectangle.
Since the first line is shorter than the two following, one has to add
spaces here as well to make it the longest.  After yanking the
rectangle, we're left with

text123   first	
more text second	
text	  third   

This is far along the way, but I can't think of a last step to make it
into CSV format except by doing it manually.

I have a few suggestions for making this better:

1. When moving POINT to the the empty line below the line containing
   "third" and killing the region starting on the line with "first",
   nothing happens.  How about having the whole region killed as a
   rectangle in this case?

2. Having a user option or prefix argument affecting `yank-rectangle'
   which when active would /e.g./ prompt the user for a string to
   insert, instead of filling the space between the lines and the yanked
   rectangle with tabs/spaces.  Optionally, just place the given string
   in front of the rectangle and put it at the end of the lines, without
   worrying about visual alignment (so you wouldn't have to worry about
   the first line being the longest).

With these two items, killing the first rectangle and yanking it (with
the prefix) at the end of the line would produce the desired text.

- [1] https://stackoverflow.com/a/8411061




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#52265; Package emacs. (Sat, 04 Dec 2021 19:51:01 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Tor Kringeland <tor.a.s.kringeland <at> ntnu.no>
Cc: 52265 <at> debbugs.gnu.org
Subject: Re: bug#52265: Wishlist: Behavior of rectangles when last line is
 short
Date: Sat, 04 Dec 2021 20:50:39 +0100
Tor Kringeland <tor.a.s.kringeland <at> ntnu.no> writes:

> Suppose we have the following text
>
> text123
> more text
> text
> first
> second
> third  
>
> and want to turn it into
>
> text123,first
> more text,second	
> text,third
>
> using rectangles.

I'm not sure I understand.  Does Emacs have a rectangle command that
does this?  And if so, what is it called?

> 1. When moving POINT to the the empty line below the line containing
>    "third" and killing the region starting on the line with "first",
>    nothing happens.  How about having the whole region killed as a
>    rectangle in this case?

Killing the region (i.e., using `C-w') works fine for me...

> 2. Having a user option or prefix argument affecting `yank-rectangle'
>    which when active would /e.g./ prompt the user for a string to
>    insert, instead of filling the space between the lines and the yanked
>    rectangle with tabs/spaces.  Optionally, just place the given string
>    in front of the rectangle and put it at the end of the lines, without
>    worrying about visual alignment (so you wouldn't have to worry about
>    the first line being the longest).

I think this is way outside the scope of rectangles.  Your use case
seems to be to turn a series of lines into CSV columns -- but that's
better expressed through a CSV command.  You might want to group them by
two or three or four lines into columns, for instance.

So I don't think using rectangles for something like this is totally the
wrong tool, and it can't possibly work very well.  Unless I'm
misunderstanding something, which I might well be doing.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Added tag(s) moreinfo. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sat, 04 Dec 2021 19:51:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#52265; Package emacs. (Sat, 04 Dec 2021 20:34:01 GMT) Full text and rfc822 format available.

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

From: Tor Kringeland <tor.a.s.kringeland <at> ntnu.no>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 52265 <at> debbugs.gnu.org
Subject: Re: bug#52265: Wishlist: Behavior of rectangles when last line is
 short
Date: Sat, 04 Dec 2021 21:33:25 +0100
Lars Ingebrigtsen <larsi <at> gnus.org> writes:

> Killing the region (i.e., using `C-w') works fine for me...

I should have been more clear.  I used `kill-rectangle' to kill the
region so that I can yank it as a column to the right of the three first
lines; this is done using `yank-rectangle' at the end of the first line,
after inserting a number of spaces.

> I think this is way outside the scope of rectangles.  Your use case
> seems to be to turn a series of lines into CSV columns -- but that's
> better expressed through a CSV command.  You might want to group them by
> two or three or four lines into columns, for instance.

I see your point, and my example is relevant for creating CSV records,
but I think what rectangles already bring are pretty close to the
desired end result.

The crux is turning a collection of lines into columns, which you can
already do by killing/yanking rectangles.  The behavior in the first
point would be nice in general, as having the killed rectangle extend to
the end of the lines instead of just being the length of the current
line, is a nice optional feature to have, I think, which extends beyond
my CSV example.

The behavior in the second point is more geared toward this specific
example, but it's also a general one.  Basically it's about allowing the
user to optionally specify what column separator to use.  The default
one is tabs and spaces for visual alignment.  In my CSV example a comma
would be used.  And you could /e.g./ use a vertical bar for `org-mode'
tables.

As a sidenote, `org-mode' already sidesteps this last issue by having
the command `org-table-create-or-convert-from-region' which can create a
table from the resulting columns after yanking the rectangle.  Maybe
something similar could be done in `csv-mode'?  It would solve the issue
wrt. my second point, though I still think there is some general use in
being able to specify the column separator.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#52265; Package emacs. (Sat, 04 Dec 2021 21:19:01 GMT) Full text and rfc822 format available.

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

From: Alan Third <alan <at> idiocy.org>
To: Tor Kringeland <tor.a.s.kringeland <at> ntnu.no>
Cc: 52265 <at> debbugs.gnu.org
Subject: Re: bug#52265: Wishlist: Behavior of rectangles when last line is
 short
Date: Sat, 4 Dec 2021 21:18:21 +0000
On Sat, Dec 04, 2021 at 12:06:52AM +0100, Tor Kringeland wrote:
> Suppose we have the following text
> 
> text123
> more text
> text
> first
> second
> third  
> 
> and want to turn it into
> 
> text123,first
> more text,second	
> text,third
> 
> using rectangles.  This is problematic since the last line is shorter
> than the two before.  A solution to this [1] is to add spaces at the end
> of the last line until it becomes the longest, mark the last three lines
> with POINT being at the end of the spaces and then kill the rectangle.
> Since the first line is shorter than the two following, one has to add
> spaces here as well to make it the longest.

Try C-x SPC, that should put you into a rectangle mode which lets you
specify a rectangle that extends past the end of the line.

-- 
Alan Third




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#52265; Package emacs. (Sat, 04 Dec 2021 22:13:02 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Tor Kringeland <tor.a.s.kringeland <at> ntnu.no>
Cc: 52265 <at> debbugs.gnu.org
Subject: Re: bug#52265: Wishlist: Behavior of rectangles when last line is
 short
Date: Sat, 04 Dec 2021 23:12:21 +0100
Tor Kringeland <tor.a.s.kringeland <at> ntnu.no> writes:

> I should have been more clear.  I used `kill-rectangle' to kill the
> region so that I can yank it as a column to the right of the three first
> lines; this is done using `yank-rectangle' at the end of the first line,
> after inserting a number of spaces.

Oh, I see.  😀  Well, that makes more sense, then.

> The behavior in the second point is more geared toward this specific
> example, but it's also a general one.  Basically it's about allowing the
> user to optionally specify what column separator to use.  The default
> one is tabs and spaces for visual alignment.  In my CSV example a comma
> would be used.  And you could /e.g./ use a vertical bar for `org-mode'
> tables.

I think there's a separate package for doing this...  er...  something
about tabular mode, but I forget what it's called.  It mogrifies text
into a table, and from that you can export into various formats.  Or was
it table.el?  It's been a long while since I used it last.

> As a sidenote, `org-mode' already sidesteps this last issue by having
> the command `org-table-create-or-convert-from-region' which can create a
> table from the resulting columns after yanking the rectangle.  Maybe
> something similar could be done in `csv-mode'?  It would solve the issue
> wrt. my second point, though I still think there is some general use in
> being able to specify the column separator.

I think selecting prefix characters etc just isn't general enough.  When
creating a CSV file, for instance, you want to get rid of the spaces,
too.  So creating a table and then exporting (via various rules) seems
more useful.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#52265; Package emacs. (Mon, 06 Dec 2021 00:13:01 GMT) Full text and rfc822 format available.

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

From: Tor Kringeland <tor.a.s.kringeland <at> ntnu.no>
To: Alan Third <alan <at> idiocy.org>
Cc: 52265 <at> debbugs.gnu.org
Subject: Re: bug#52265: Wishlist: Behavior of rectangles when last line is
 short
Date: Mon, 06 Dec 2021 01:12:46 +0100
Alan Third <alan <at> idiocy.org> writes:

> Try C-x SPC, that should put you into a rectangle mode which lets you
> specify a rectangle that extends past the end of the line.

Thank you!  This solves my first problem, since this does the same
thing, and more elegantly.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#52265; Package emacs. (Mon, 06 Dec 2021 00:26:01 GMT) Full text and rfc822 format available.

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

From: Tor Kringeland <tor.a.s.kringeland <at> ntnu.no>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 52265 <at> debbugs.gnu.org
Subject: Re: bug#52265: Wishlist: Behavior of rectangles when last line is
 short
Date: Mon, 06 Dec 2021 01:25:23 +0100
Lars Ingebrigtsen <larsi <at> gnus.org> writes:

> I think there's a separate package for doing this...  er...  something
> about tabular mode, but I forget what it's called.  It mogrifies text
> into a table, and from that you can export into various formats.  Or was
> it table.el?  It's been a long while since I used it last.

Thank you, I'll have a look around the ecosystem :)

> I think selecting prefix characters etc just isn't general enough.  When
> creating a CSV file, for instance, you want to get rid of the spaces,
> too.  So creating a table and then exporting (via various rules) seems
> more useful.

I see.  Alan Third mentioned `rectangle-mark-mode', which solves the
first point.  For the second point I can concoct something to format to
CSV (or find a package).  So you can close this request for my part.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#52265; Package emacs. (Mon, 06 Dec 2021 01:31:02 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Tor Kringeland <tor.a.s.kringeland <at> ntnu.no>
Cc: 52265 <at> debbugs.gnu.org
Subject: Re: bug#52265: Wishlist: Behavior of rectangles when last line is
 short
Date: Mon, 06 Dec 2021 02:30:21 +0100
Tor Kringeland <tor.a.s.kringeland <at> ntnu.no> writes:

> I see.  Alan Third mentioned `rectangle-mark-mode', which solves the
> first point.  For the second point I can concoct something to format to
> CSV (or find a package).  So you can close this request for my part.

OK; closing.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




bug closed, send any further explanations to 52265 <at> debbugs.gnu.org and Tor Kringeland <tor.a.s.kringeland <at> ntnu.no> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Mon, 06 Dec 2021 01:31:03 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 03 Jan 2022 12:24:08 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 168 days ago.

Previous Next


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