transpose.el -- transpose line to row

[Last up date: 07/06/30]
[目次] >> [LISPのささやき] >> [transpose.el]

(defun transpose-line-to-row (start end )
  (interactive "r")
  ;; count each row and row-max
  (setq lines  (count-lines start end)
	row-max 0
	)
  (goto-char start)
  (setq i 0)
  (while (< i lines)
    (end-of-line)
    (setq line-end (point))
    (beginning-of-line)
    (setq row-max 
	  (max row-max (- line-end (point))))
    (forward-line)
    (setq i (1+ i)))
  ;; 
  (setq matrix (make-vector row-max ""))
  (goto-char start)
  (setq i 0)
  (while (< i lines)
    (end-of-line)
    (setq line-end (point))
    (beginning-of-line)
    (setq j 0)
    (while (< j row-max)
      (if (< (point) line-end)
	  (progn 
	    (aset matrix j (concat (aref matrix j) 
				   (char-to-string (following-char))))
	    (forward-char)
	    )
	(aset matrix j (concat (aref matrix j) " ")))
      (setq j (1+ j)))
    (forward-line)
    (setq i (1+ i))
    )
  ;; output
  (goto-char end)
  (setq i 0)
  (while (< i row-max)
    (newline)
    (beginning-of-line)
    (insert (aref matrix i))
    (setq i (1+ i)))
  )

Counter image
[WACKIE SPACE]