🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #98490

yank-rectangle

#98490
From: macrakis
Date: Tue, 25 Jun 1991 20:42
53 lines
3041 bytes
GNU Emacs 18.55.121 on NeXT 2.0

Currently, kill-rectangle and yank-rectangle operate on rectangles
only AS rectangles, and never as ordinary text.

I sometimes find it useful to insert a killed rectangle not as a
rectangle, but as a sequence of lines.  There are several possible
interfaces to this functionality that I can think of:

1) Have kill-rectangle also put the rectangle into the kill-ring as
ordinary text.  Advantage: ordinary yank, yank-pop, etc., now work;
have ring functionality for free.  Disadvantages: may break code that
depends on current behavior; conses up an extra string; still don't
have yank-rectangle-pop functionality (not orthogonal).

2) Add a new function, yank-rectangle-as-text.  Advantage: no change
to existing code.  Disadvantages: yet another obscure function.

3) Make C-u yank-rectangle do yank-rectangle-as-text.  Advantage: no
new functions.  Disadvantage: yet another wart.

4) Generalize yank, kill-rectangle, and yank-rectangle so that they
work on the same kill-ring (like (1)), and both make sense.  The
semantics of yank-rectangle could be: yank killed thing as though it
were a rectangle of width equal to its widest line, and length equal
to the number of lines in it.  kill-rectangle would simply have to
arrange to have at least one line properly padded for this to work.
This seems to me the cleanest solution.  Advantage: clean and simple
interface, general orthogonal behavior (including yank-pop, etc., but
yank-pop-rectangle would either have to be a separate function or
would have to notice whether the current yank was actually a rectangle
yank).  Disadvantage: perhaps a little messier to program, but not
much.  Note that it only requires modifying the rectangle functions,
not the core yank and kill functions.


PS By the way, solution (4) suggests that a useful piece of Gnu Lisp
functionality would be an in-place subseq-to-subseq copy routine
(which might as well work for buffers as well as all sequences):

	(set-substring Target-STRING Target-from
		       Source-STRING Source-from
		       Len)	; or Source-to

This has many applications besides rectangles; for instance, a GC-free
implementation of compare-windows -- although perhaps that ought to have
more direct support, e.g.

	(compare-substring String1 From1 To1
			   String2 From2 To2)
	returns index of first difference or nil

where String could be any sequence or buffer.
Technical Details
Message-ID: <9106252042.AA12911@_next1.osf.org_>
Path: arc1-ca.pugleaf.net!gmdzi!unido!fauern!ira.uka.de!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!osf.ORG!macrakis

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb2f1,53cc14847c8e7ae5,start
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1991-06-25 13:42:03 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!fauern!ira.uka.de!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!osf.ORG!macrakis
From: macrakis@osf.ORG
Newsgroups: gnu.emacs.bug
Subject: yank-rectangle
Message-ID: <9106252042.AA12911@_next1.osf.org_>
Date: 25 Jun 91 20:42:03 GMT
Sender: gnulists@ai.mit.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 53
Approved: bug-gnu-emacs@prep.ai.mit.edu