From: "Herbert Euler" <herberteuler@hotmail.com>
Subject: Fixing rectangle operations
Date: Thu, 15 Dec 2005 12:41:53 +0800 [thread overview]
Message-ID: <BAY112-F282D1415E777AEB75AA479DA3B0@phx.gbl> (raw)
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/
next reply other threads:[~2005-12-15 4:41 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-12-15 4:41 Herbert Euler [this message]
2005-12-15 5:02 ` Fixing rectangle operations Herbert Euler
2005-12-15 7:21 ` Miles Bader
2005-12-15 9:28 ` Mathias Dahl
2005-12-15 16:51 ` Stefan Monnier
2005-12-15 20:23 ` Lennart Borgman
2005-12-15 23:19 ` Johan Bockgård
2005-12-16 2:08 ` Herbert Euler
2005-12-16 13:14 ` Mathias Dahl
2005-12-16 18:20 ` Herbert Euler
2005-12-19 10:09 ` Mathias Dahl
2005-12-19 2:24 ` Giorgos Keramidas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=BAY112-F282D1415E777AEB75AA479DA3B0@phx.gbl \
--to=herberteuler@hotmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).