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
Sorry.
kai
--
Be indiscrete. Do it continuously.
> 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
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 ?
> 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? :-)