>>>> "Uwe" == Uwe Brauer <oub(a)mat.ucm.es>
writes:
Uwe> Hello
Uwe> I would like to transpose columns in matrix like construct like this
Uwe> 1 2 2 1
Uwe> 1 2 --> 2 1
Uwe> 1 2 2 1
Hi Uwe, you got me hooked.
Try these and report back.
Good Luck,
Adrian
(defun apa-transpose-rectangles (start1 end1 start2 end2)
"Transpose two rectangles of equal geometry in buffer.
It is an error for the rectangles to be of different geometry.
It is an error for the first rectangle not to be active when this
command is called interactively.
Press \\[exit-recursive-edit] after selecting the second rectangle of
equal geometry."
(interactive
(let
((mouse-track-rectangle-p t)
s1 e1 s2 e2 r1)
(unless (region-active-p)
(error "first rectangle is not active"))
(zmacs-deactivate-region)
(activate-region)
(setq s1 (region-beginning))
(setq e1 (region-end))
(setq r1 (extract-rectangle s1 e1))
(message "select another %dx%d rectangle, then press %s"
(length (car r1)) (length r1)
(substitute-command-keys "\\[exit-recursive-edit]"))
(recursive-edit)
(setq s2 (region-beginning))
(setq e2 (region-end))
(list s1 e1 s2 e2)))
(let
((rect1 (extract-rectangle start1 end1))
(rect2 (extract-rectangle start2 end2)))
(unless
(equal (mapcar (lambda (l) (length l)) rect1)
(mapcar (lambda (l) (length l)) rect2))
(error "rectangles are of different geometry: %dx%d vs %dx%d"
(length (car rect1)) (length rect1)
(length (car rect2)) (length rect2)))
(delete-rectangle start1 end1)
(goto-char start1)
(insert-rectangle rect2)
(delete-rectangle start2 end2)
(goto-char start2)
(insert-rectangle rect1)))
(defun apa-transpose-regions (start1 end1 start2 end2 &optional leave-markers)
"Transpose two regions in buffer.
It is an error for the first region not to be active when this
command is called interactively.
Press \\[exit-recursive-edit] after selecting the second region."
(interactive
(let
((cb (current-buffer))
(zmacs-region-stays nil)
s1 e1 s2 e2)
(setq s1 (region-beginning cb))
(setq e1 (region-end cb))
(message "select another region, then press %s"
(substitute-command-keys "\\[exit-recursive-edit]"))
(recursive-edit)
(setq s2 (region-beginning cb))
(setq e2 (region-end cb))
(list s1 e1 s2 e2 t)))
(transpose-regions start1 end1 start2 end2 leave-markers))
Uwe> I can do this by hand via kill and yank rectangle, but does anybody
Uwe> know about a package which does this. I searched in the web without
Uwe> success
Uwe> Thanks
Uwe> Uwe Brauer
--
Adrian Aichner
mailto:adrianï¼ xemacs.org
http://www.xemacs.org/