unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Fixing rectangle operations
@ 2005-12-15  4:41 Herbert Euler
  2005-12-15  5:02 ` Herbert Euler
  2005-12-15  7:21 ` Miles Bader
  0 siblings, 2 replies; 12+ messages in thread
From: Herbert Euler @ 2005-12-15  4:41 UTC (permalink / 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/

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

end of thread, other threads:[~2005-12-19 10:09 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-15  4:41 Fixing rectangle operations Herbert Euler
2005-12-15  5:02 ` 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

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).