[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: overlay (combine) lines

From: Kevin Rodgers
Subject: Re: overlay (combine) lines
Date: Sat, 20 Oct 2007 00:20:24 -0600
User-agent: Thunderbird (Macintosh/20070809)

address@hidden wrote:
I am trying to figure out how to overlay lines of code.

For example, if I have the following two lines, how can i combine the
non blanks into one line.

-----before overlay--------------
  one           three
          two             four

-------after overlay--------------
  one   two  three   four

In the past on a mainframe I was able to do this using a primative
line editor by typing an M and O on the line numbers as follows:

00M001  one           three
00O002          two             four

resulting in only one line:
0000001 one   two   three  four

Here is some pure hackery:

(defun combine-next-line ()
  "Combine the next line with the current line.
The printable characters in the next line are used to replace the
whitespace characters in the same column of the current line."
  (let* ((this-line-beg (line-beginning-position))
         (next-line-end (line-end-position 2))
         (this-line (buffer-substring this-line-beg
         (next-line (buffer-substring (line-beginning-position 2)
         (column 0)
         (line-length (min (length this-line) (length next-line))))
    (while (< column line-length)
      (when (and (equal (char-syntax (aref this-line column)) ?\s)
                 (not (equal (char-syntax (aref next-line column)) ?\s)))
        (aset this-line column (aref next-line column)))
      (setq column (1+ column)))
    (delete-region this-line-beg next-line-end)
    (goto-char this-line-beg)
    (insert this-line)
    (when (< column (length next-line))
      (insert (substring next-line column)))))

Kevin Rodgers
Denver, Colorado, USA

reply via email to

[Prev in Thread] Current Thread [Next in Thread]