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

* RE: Fixing rectangle operations
  2005-12-15  4:41 Fixing rectangle operations Herbert Euler
@ 2005-12-15  5:02 ` Herbert Euler
  2005-12-15  7:21 ` Miles Bader
  1 sibling, 0 replies; 12+ messages in thread
From: Herbert Euler @ 2005-12-15  5:02 UTC (permalink / raw)


Oh, it should be

    (if (>= (current-column) startcol))

I'm sorry.

Regards,
Guanpeng Xu

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

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

* Re: Fixing rectangle operations
  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-19  2:24   ` Giorgos Keramidas
  1 sibling, 2 replies; 12+ messages in thread
From: Miles Bader @ 2005-12-15  7:21 UTC (permalink / raw)
  Cc: emacs-devel

"Herbert Euler" <herberteuler@hotmail.com> writes:
> 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 dunno, vim's behavior seems kind of bizarre to me.

Treating all lines as implicitly "blank extended" in rectangle
operations seems much more natural (and _not_ doing so likely to cause a
lot of user confusion).

-miles
-- 
自らを空にして、心を開く時、道は開かれる

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

* Re: Fixing rectangle operations
  2005-12-15  7:21 ` Miles Bader
@ 2005-12-15  9:28   ` Mathias Dahl
  2005-12-15 16:51     ` Stefan Monnier
  2005-12-19  2:24   ` Giorgos Keramidas
  1 sibling, 1 reply; 12+ messages in thread
From: Mathias Dahl @ 2005-12-15  9:28 UTC (permalink / raw)


Miles Bader <miles.bader@necel.com> writes:

> "Herbert Euler" <herberteuler@hotmail.com> writes:
>> 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 dunno, vim's behavior seems kind of bizarre to me.
>
> Treating all lines as implicitly "blank extended" in rectangle
> operations seems much more natural (and _not_ doing so likely to cause a
> lot of user confusion).

I agree.  I can see the problem with Emacs doing what it does, but
that feels more natural.  At least in the situations I use C-x r t I
have never seen this as a problem.

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

* Re: Fixing rectangle operations
  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
  0 siblings, 2 replies; 12+ messages in thread
From: Stefan Monnier @ 2005-12-15 16:51 UTC (permalink / raw)
  Cc: emacs-devel

>>> 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 dunno, vim's behavior seems kind of bizarre to me.
>> 
>> Treating all lines as implicitly "blank extended" in rectangle
>> operations seems much more natural (and _not_ doing so likely to cause a
>> lot of user confusion).

> I agree.  I can see the problem with Emacs doing what it does, but
> that feels more natural.  At least in the situations I use C-x r t I
> have never seen this as a problem.

Clearly both behaviors make sense.
If that really matters, we could provide the Vim behavior via C-u prefix or
via another command.


        Stefan

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

* Re: Fixing rectangle operations
  2005-12-15 16:51     ` Stefan Monnier
@ 2005-12-15 20:23       ` Lennart Borgman
  2005-12-15 23:19       ` Johan Bockgård
  1 sibling, 0 replies; 12+ messages in thread
From: Lennart Borgman @ 2005-12-15 20:23 UTC (permalink / raw)
  Cc: emacs-devel, Mathias Dahl

Stefan Monnier wrote:

>Clearly both behaviors make sense.
>If that really matters, we could provide the Vim behavior via C-u prefix or
>via another command.
>  
>
If it matters then please do not hide it. ;-)

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

* Re: Fixing rectangle operations
  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
  1 sibling, 1 reply; 12+ messages in thread
From: Johan Bockgård @ 2005-12-15 23:19 UTC (permalink / raw)


Stefan Monnier <monnier@iro.umontreal.ca> writes:

> Clearly both behaviors make sense. If that really matters, we could
> provide the Vim behavior via C-u prefix or via another command.

And most rectangle commands other than `C-x r t' already use a prefix
to distinguish two different kinds of behavior (there "don't fill
empty areas" is the default behavior though).

-- 
Johan Bockgård

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

* Re: Fixing rectangle operations
  2005-12-15 23:19       ` Johan Bockgård
@ 2005-12-16  2:08         ` Herbert Euler
  2005-12-16 13:14           ` Mathias Dahl
  0 siblings, 1 reply; 12+ messages in thread
From: Herbert Euler @ 2005-12-16  2:08 UTC (permalink / raw)


>From: bojohan+news@dd.chalmers.se (Johan Bockgård)
>To: emacs-devel@gnu.org
>Subject: Re: Fixing rectangle operations
>Date: Fri, 16 Dec 2005 00:19:00 +0100
>
>And most rectangle commands other than `C-x r t' already use a prefix
>to distinguish two different kinds of behavior (there "don't fill
>empty areas" is the default behavior though).

But I don't see it in 'string-insert-rectangle':

string-insert-rectangle is an interactive autoloaded Lisp function in 
`rect'.
(string-insert-rectangle start end string)

Insert string on each line of region-rectangle, shifting text right.

When called from a program, the rectangle's corners are start and end.
The left edge of the rectangle specifies the column for insertion.
This command does not delete or overwrite any existing text.

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

* Re: Fixing rectangle operations
  2005-12-16  2:08         ` Herbert Euler
@ 2005-12-16 13:14           ` Mathias Dahl
  2005-12-16 18:20             ` Herbert Euler
  0 siblings, 1 reply; 12+ messages in thread
From: Mathias Dahl @ 2005-12-16 13:14 UTC (permalink / raw)


"Herbert Euler" <herberteuler@hotmail.com> writes:

> When called from a program, the rectangle's corners are start and end.
> The left edge of the rectangle specifies the column for insertion.
> This command does not delete or overwrite any existing text.

Hmm, it does indeed overwrite existing text. I just tested, calling it
interactively. Did the above only pertain to a program calling it
maybe?

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

* Re: Fixing rectangle operations
  2005-12-16 13:14           ` Mathias Dahl
@ 2005-12-16 18:20             ` Herbert Euler
  2005-12-19 10:09               ` Mathias Dahl
  0 siblings, 1 reply; 12+ messages in thread
From: Herbert Euler @ 2005-12-16 18:20 UTC (permalink / raw)


>From: Mathias Dahl <brakjoller@gmail.com>
>To: emacs-devel@gnu.org
>Subject: Re: Fixing rectangle operations
>Date: Fri, 16 Dec 2005 14:14:08 +0100
>
>Hmm, it does indeed overwrite existing text. I just tested, calling it
>interactively. Did the above only pertain to a program calling it
>maybe?

I'm sorry I don't quite understand what you said. What's the program
calling 'string-insert-rectangle'?

Regards,
Guanpeng Xu

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

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

* Re: Fixing rectangle operations
  2005-12-15  7:21 ` Miles Bader
  2005-12-15  9:28   ` Mathias Dahl
@ 2005-12-19  2:24   ` Giorgos Keramidas
  1 sibling, 0 replies; 12+ messages in thread
From: Giorgos Keramidas @ 2005-12-19  2:24 UTC (permalink / raw)
  Cc: Herbert Euler, emacs-devel

On 2005-12-15 16:21, Miles Bader <miles.bader@necel.com> wrote:
> "Herbert Euler" <herberteuler@hotmail.com> writes:
> > 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 dunno, vim's behavior seems kind of bizarre to me.
>
> Treating all lines as implicitly "blank extended" in rectangle
> operations seems much more natural (and _not_ doing so likely
> to cause a lot of user confusion).

Agreed,

I regularly use rectangle-mode to 'draw' boxes like:

    +--------+
    |        |
    |        |
    +--------+

With the current behavior of Emacs, I can start with:

    +


    +

and fill 'empty' areas with C-u ARG '-' and C-x r t.

Vim's behavior, on the other hand, is extremely annoying for this
sort of work, because I have to manually 'prefill' empty areas
with whitespace and then hit ^V to operate on the current rectangle.

FWIW, if there is a possibility of keeping the current Emacs
behavior and using C-u to switch to Vim's default, then I'd
really prefer that very much.

- Giorgos

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

* Re: Fixing rectangle operations
  2005-12-16 18:20             ` Herbert Euler
@ 2005-12-19 10:09               ` Mathias Dahl
  0 siblings, 0 replies; 12+ messages in thread
From: Mathias Dahl @ 2005-12-19 10:09 UTC (permalink / raw)


"Herbert Euler" <herberteuler@hotmail.com> writes:


>>Hmm, it does indeed overwrite existing text. I just tested, calling it
>>interactively. Did the above only pertain to a program calling it
>>maybe?
>
> I'm sorry I don't quite understand what you said. What's the program
> calling 'string-insert-rectangle'?

Sorry for that, I read too sloppily and used `string-rectangle'. I did
not even know about `string-insert-rectangle'.

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