Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to do M-x narrow-to-rectangle ?

210 views
Skip to first unread message

Stephen Eglen

unread,
Mar 10, 2001, 10:41:20 AM3/10/01
to
Hi,

A few times recently i've been wondering how to do search+replace
within a given rectangle (e.g. when editing columns of numbers). One
general solution might be to have a variant of narrow-to-region called
narrow-to-rectangle. However narrow-to-region is an inbuilt function,
and I don't imagine it is easy to make narrow-to-rectangle. Anyone
have any ideas of a good workaround?

Thanks, Stephen

Kai Großjohann

unread,
Mar 10, 2001, 11:56:22 AM3/10/01
to
I'm afraid you'll have to cut the rectangle, paste it into a temp
buffer, then do the edits, then move the rectangle from the temp
buffer into the result buffer.

Sorry.
kai
--
Be indiscrete. Do it continuously.

Samuel Padgett

unread,
Mar 10, 2001, 1:49:26 PM3/10/01
to
Kai.Gro...@CS.Uni-Dortmund.DE (Kai Großjohann) writes:

> I'm afraid you'll have to cut the rectangle, paste it into a temp
> buffer, then do the edits, then move the rectangle from the temp
> buffer into the result buffer.

The rectangle functions always seemed backwards to me: You mark an
ordinary region, then you have a few special commands that say, "Okay,
only operate on the _rectangle_ between point and mark, not the whole
region." It is non-intuitive, particularly when Transient Mark mode
is enabled. Wouldn't it make more to sense to be able to set a
special kind of mark that is used to define a rectangular region and
have all the commands that typically operate on regions (C-w, M-w, C-x
n n, M-%, etc.) operate on the rectangle, instead?

I guess this is non-trivial to implement?

Incidentally, this is one of the few things I know that Vim can do
that Emacs can't...

Sam
--
Room service? Send up a larger room.
-- Groucho Marx

Stefan Monnier <foo@acm.com>

unread,
Mar 10, 2001, 3:27:31 PM3/10/01
to
>>>>> "Samuel" == Samuel Padgett <samuel....@gte.net> writes:
> The rectangle functions always seemed backwards to me: You mark an
> ordinary region, then you have a few special commands that say, "Okay,
> only operate on the _rectangle_ between point and mark, not the whole
> region." It is non-intuitive, particularly when Transient Mark mode
> is enabled. Wouldn't it make more to sense to be able to set a
> special kind of mark that is used to define a rectangular region and
> have all the commands that typically operate on regions (C-w, M-w, C-x
> n n, M-%, etc.) operate on the rectangle, instead?
> I guess this is non-trivial to implement?

Some of the above is provided by rect-mark.el.
But it's just a little part. Support for such a thing in general
would require extensive changes all over the place.


Stefan

PS: What should the behavior of a narrowed rectangle be ?
should editing be prevented from making the rectangle non-rectangular ?

Samuel Padgett

unread,
Mar 10, 2001, 6:24:43 PM3/10/01
to
"Stefan Monnier <f...@acm.com>" <monnier+gnu.emacs.help/news/@flint.cs.yale.edu> writes:

> PS: What should the behavior of a narrowed rectangle be ?
> should editing be prevented from making the rectangle non-rectangular ?

Hm, good question. I would probably say no, the rectangle should just
define the initial region to narrow to. You can add and delete lines
from a narrowed region today, so why not add and delete columns from
lines in a narrowed rectangle? The narrowed portion of the buffer
should not have to stay the same size. When done, the original
rectangle might not be a rectangle any longer, but would that really
cause any harm?

I'm sure other sticky issues like this would crop up implementing
rectangular regions -- and I'm sure I would be a lot of work -- but
wouldn't it be cool? :-)

0 new messages