[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Fixing rectangle operations
From: |
Herbert Euler |
Subject: |
Fixing rectangle operations |
Date: |
Thu, 15 Dec 2005 12:41:53 +0800 |
Hello everyone,
Both Emacs and Vim support operate on a rectangle
region in buffer, but I think Vim handles it better. The
following example comes from Vim Main Help File.
Assume the content one want to insert 'very ' before
'long':
This is a -!-long line
short
Any other long line
The point is before 'long' in the first line. Vim documents
that if one want to insert 'very ' before these two 'long's,
it will ignore the short line. Hence the result is:
This is a very long line
short
Any other very long line
I tested this in Emacs. I set a mark at where the point
is in the orignal text, and move the point to the third
line, before 'long'. But M-x string-insert-rectangle yields:
This is a very long line
short very
Any other very long line
This is not good.
Still, I don't think this is what I mean in most conditions,
and prefer leaving short lines as what they were.
I modified 'rect.el' so that rectangle operations will
not operate on short lines. The only function needs to
be changed is 'apply-on-rectangle'. I just add the
verification of whether the rectangle covers short
lines:
;; The replacement for `operate-on-rectangle' -- dv
(defun apply-on-rectangle (function start end &rest args)
"Call FUNCTION for each line of rectangle with corners at START, END.
FUNCTION is called with two arguments: the start and end columns of the
rectangle, plus ARGS extra arguments. Point is at the beginning of line
when
the function is called."
(let (startcol startpt endcol endpt)
(save-excursion
(goto-char start)
(setq startcol (current-column))
(beginning-of-line)
(setq startpt (point))
(goto-char end)
(setq endcol (current-column))
(forward-line 1)
(setq endpt (point-marker))
;; ensure the start column is the left one.
(if (< endcol startcol)
(let ((col startcol))
(setq startcol endcol endcol col)))
;; start looping over lines
(goto-char startpt)
(while (< (point) endpt)
(end-of-line) ; first go to end of
each line
(if (>= (current-column) start) ; this simple test will avoid
operating on short lines
(apply function startcol endcol args))
(forward-line 1)))
))
I think this is better than what Emacs does now.
Regards,
Guanpeng Xu
_________________________________________________________________
Don't just search. Find. Check out the new MSN Search!
http://search.msn.click-url.com/go/onm00200636ave/direct/01/
- Fixing rectangle operations,
Herbert Euler <=
- RE: Fixing rectangle operations, Herbert Euler, 2005/12/15
- Re: Fixing rectangle operations, Miles Bader, 2005/12/15
- Re: Fixing rectangle operations, Mathias Dahl, 2005/12/15
- Re: Fixing rectangle operations, Stefan Monnier, 2005/12/15
- Re: Fixing rectangle operations, Lennart Borgman, 2005/12/15
- Re: Fixing rectangle operations, Johan Bockgård, 2005/12/15
- Re: Fixing rectangle operations, Herbert Euler, 2005/12/15
- Re: Fixing rectangle operations, Mathias Dahl, 2005/12/16
- Re: Fixing rectangle operations, Herbert Euler, 2005/12/16
- Re: Fixing rectangle operations, Mathias Dahl, 2005/12/19