[gnu.emacs] block manipulation

scotth@corp.sgi.com (Scott Henry) (02/02/90)

rsw> Is there any support in GNU EMACS for manipulating blocks of texts
rsw> (not regions) spanning multiple lines? Or how about a real simple one,
rsw> how do you get rid of a column without having to write a lisp
rsw> functions to go down line by line deleting a particular character
rsw> position?

rsw> 						Ron

Do an apropos on "rectangle". I get the following functions:

clear-rectangle		      
copy-rectangle-to-register
delete-rectangle	      
kill-rectangle		      
open-rectangle		      
yank-rectangle		      

These functions are designed to manipulate rectangular areas of text --
eg: columns 15-23 of lines 21-104.  There are a couple of "quirks" when
using them at the end of lines, but they are invaluable when they are
usefull.

--
  Scott Henry <scotth@sgi.com>	| These are my	| Tardis Express -- when it
  Information Services,		| Opinions only!| absolutely, positively
  Silicon Graphics, Inc		| Whose else?	| has to be there -- yesterday.

ron@woan.austin.ibm.com (Ronald S. Woan/2113674) (02/02/90)

Is there any support in GNU EMACS for manipulating blocks of texts
(not regions) spanning multiple lines? Or how about a real simple one,
how do you get rid of a column without having to write a lisp
functions to go down line by line deleting a particular character
position?

						Ron

+-----All Views Expressed Are My Own And Are Not Necessarily Shared By------+
+------------------------------My Employer----------------------------------+
+ Ronald S. Woan  (IBM VNET)WOAN AT AUSTIN, (AUSTIN)ron@woan.austin.ibm.com +
+ outside of IBM       @cs.utexas.edu:ibmaus!auschs!woan.austin.ibm.com!ron +
+ last resort                                        woan@peyote.cactus.org +

mdb@ESD.3Com.COM (Mark D. Baushke) (02/02/90)

On 1 Feb 90 17:28:23 GMT, ron@woan.austin.ibm.com (Ronald S. Woan) said:

ron> Is there any support in GNU EMACS for manipulating blocks of texts
ron> (not regions) spanning multiple lines? Or how about a real simple one,
ron> how do you get rid of a column without having to write a lisp
ron> functions to go down line by line deleting a particular character
ron> position?

Do the rectangle manipulation functions handle what you want 
(see $EMACS/lisp/rect.el for more information)?

	clear-rectangle
	delete-rectangle
	kill-rectangle
	open-rectangle
	yank-rectangle

Given the above rectangle functions and add the functions insert-box
insert-suffix (lisp given below) and you have a fairly full set of
functionality for manipulating rectangular regions (columns) of text.

(defun insert-box (start end text)
  "Insert a text prefix at a column in all the lines in the region.
   Called from a program, takes three arguments, START, END, and TEXT.
   The column is taken from that of START.
   The rough inverse of this function is kill-rectangle."
  (interactive "r\nsText To Insert: ")
  (save-excursion
    (let (cc)
      ;; the point-marker stuff is needed to keep the edits from changing
      ;; where end is
      (goto-char end)
      (setq end (point-marker))
      (goto-char start)
      (setq cc  (current-column))
      (while (< (point) end) ;; modified 2/2/88
	;; I should here check for tab chars
	(insert text)
	(forward-line 1)
	(move-to-column cc))
      (move-marker end nil))))

(defun insert-suffix (start end text)
  "Insert a text prefix at the end in all the lines in the region.
   Called from a program, takes three arguments, START, END, and TEXT.
   The column is taken from that of START."
  (interactive "r\nsText To Insert: ")
  (save-excursion
    (let (cc)
      ;; the point-marker stuff is needed to keep the edits from changing
      ;; where end is
      (goto-char end)
      (setq end (point-marker))
      (goto-char start)
      (end-of-line)	
      (while (< (point) end);; modified 2/2/88
	;; I should here check for tab chars
	(insert text)
	(forward-line 1)
	(end-of-line)	
	)
      (move-marker end nil))))


Enjoy!
-- 
Mark D. Baushke
mdb@ESD.3Com.COM

jr@bbn.com (John Robinson) (02/03/90)

In article <1418@awdprime.UUCP>, ron@woan (Ronald S. Woan/2113674) writes:
>Is there any support in GNU EMACS for manipulating blocks of texts
>(not regions) spanning multiple lines? Or how about a real simple one,
>how do you get rid of a column without having to write a lisp
>functions to go down line by line deleting a particular character
>position?

You want the rectangle package (I had to read a while before I
understood what you menat by "blocks"; in emacs they are called
rectangles).  For starters,

  (apropos "rectangle")

  clear-rectangle		      
    Function: Blank out rectangle with corners at point and mark.
  copy-rectangle-to-register    C-x R
    Function: Copy rectangular region into register REG.
  delete-extract-rectangle      
    Function: Return and delete contents of rectangle with corners at START and END.
  delete-rectangle	      
    Function: Delete (don't save) text in rectangle with point and mark as corners.
  extract-rectangle	      
    Function: Return contents of rectangle with corners at START and END.
  insert-rectangle	      
    Function: Insert text of RECTANGLE with upper left corner at point.
  kill-rectangle		      
    Function: Delete rectangle with corners at point and mark; save as last killed one.
  open-rectangle		      
    Function: Blank out rectangle with corners at point and mark, shifting text right.
  yank-rectangle		      
    Function: Yank the last killed rectangle with upper left corner at point.

(note: C-x r is the default binding for copy-rectangle-to-register,
but I rebind it to make room for mh-rmail.  Beats me why only that one
function of the whole list gets a default binding...)

Basically, a rectangle is the characters within the box formed by
point and mark.  Empty positions are filled up with spaces as
necessary.
--
/jr, nee John Robinson     Life did not take over the globe by combat,
jr@bbn.com or bbn!jr          but by networking -- Lynn Margulis

lupton@uhccux.uhcc.hawaii.edu (Robert Lupton) (02/03/90)

The other question, `how do I delete a column', might be more easily
dealt with with a keyboard macro:
^X(^D^N^B^X)
run many times:
^[100^Xe

			Robert