all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#52265: Wishlist: Behavior of rectangles when last line is short
@ 2021-12-03 23:06 Tor Kringeland
  2021-12-04 19:50 ` Lars Ingebrigtsen
  2021-12-04 21:18 ` Alan Third
  0 siblings, 2 replies; 8+ messages in thread
From: Tor Kringeland @ 2021-12-03 23:06 UTC (permalink / raw)
  To: 52265

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





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#52265: Wishlist: Behavior of rectangles when last line is short
  2021-12-03 23:06 bug#52265: Wishlist: Behavior of rectangles when last line is short Tor Kringeland
@ 2021-12-04 19:50 ` Lars Ingebrigtsen
  2021-12-04 20:33   ` Tor Kringeland
  2021-12-04 21:18 ` Alan Third
  1 sibling, 1 reply; 8+ messages in thread
From: Lars Ingebrigtsen @ 2021-12-04 19:50 UTC (permalink / raw)
  To: Tor Kringeland; +Cc: 52265

Tor Kringeland <tor.a.s.kringeland@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





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#52265: Wishlist: Behavior of rectangles when last line is short
  2021-12-04 19:50 ` Lars Ingebrigtsen
@ 2021-12-04 20:33   ` Tor Kringeland
  2021-12-04 22:12     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 8+ messages in thread
From: Tor Kringeland @ 2021-12-04 20:33 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 52265

Lars Ingebrigtsen <larsi@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.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#52265: Wishlist: Behavior of rectangles when last line is short
  2021-12-03 23:06 bug#52265: Wishlist: Behavior of rectangles when last line is short Tor Kringeland
  2021-12-04 19:50 ` Lars Ingebrigtsen
@ 2021-12-04 21:18 ` Alan Third
  2021-12-06  0:12   ` Tor Kringeland
  1 sibling, 1 reply; 8+ messages in thread
From: Alan Third @ 2021-12-04 21:18 UTC (permalink / raw)
  To: Tor Kringeland; +Cc: 52265

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





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#52265: Wishlist: Behavior of rectangles when last line is short
  2021-12-04 20:33   ` Tor Kringeland
@ 2021-12-04 22:12     ` Lars Ingebrigtsen
  2021-12-06  0:25       ` Tor Kringeland
  0 siblings, 1 reply; 8+ messages in thread
From: Lars Ingebrigtsen @ 2021-12-04 22:12 UTC (permalink / raw)
  To: Tor Kringeland; +Cc: 52265

Tor Kringeland <tor.a.s.kringeland@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





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#52265: Wishlist: Behavior of rectangles when last line is short
  2021-12-04 21:18 ` Alan Third
@ 2021-12-06  0:12   ` Tor Kringeland
  0 siblings, 0 replies; 8+ messages in thread
From: Tor Kringeland @ 2021-12-06  0:12 UTC (permalink / raw)
  To: Alan Third; +Cc: 52265

Alan Third <alan@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.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#52265: Wishlist: Behavior of rectangles when last line is short
  2021-12-04 22:12     ` Lars Ingebrigtsen
@ 2021-12-06  0:25       ` Tor Kringeland
  2021-12-06  1:30         ` Lars Ingebrigtsen
  0 siblings, 1 reply; 8+ messages in thread
From: Tor Kringeland @ 2021-12-06  0:25 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 52265

Lars Ingebrigtsen <larsi@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.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#52265: Wishlist: Behavior of rectangles when last line is short
  2021-12-06  0:25       ` Tor Kringeland
@ 2021-12-06  1:30         ` Lars Ingebrigtsen
  0 siblings, 0 replies; 8+ messages in thread
From: Lars Ingebrigtsen @ 2021-12-06  1:30 UTC (permalink / raw)
  To: Tor Kringeland; +Cc: 52265

Tor Kringeland <tor.a.s.kringeland@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





^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-12-06  1:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-03 23:06 bug#52265: Wishlist: Behavior of rectangles when last line is short Tor Kringeland
2021-12-04 19:50 ` Lars Ingebrigtsen
2021-12-04 20:33   ` Tor Kringeland
2021-12-04 22:12     ` Lars Ingebrigtsen
2021-12-06  0:25       ` Tor Kringeland
2021-12-06  1:30         ` Lars Ingebrigtsen
2021-12-04 21:18 ` Alan Third
2021-12-06  0:12   ` Tor Kringeland

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.