all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* overlay (combine) lines
@ 2007-10-02 18:53 ry2ngh
  2007-10-20  6:20 ` Kevin Rodgers
  0 siblings, 1 reply; 2+ messages in thread
From: ry2ngh @ 2007-10-02 18:53 UTC (permalink / raw)
  To: help-gnu-emacs

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


Thanks in advance,

-Ryan

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: overlay (combine) lines
  2007-10-02 18:53 overlay (combine) lines ry2ngh
@ 2007-10-20  6:20 ` Kevin Rodgers
  0 siblings, 0 replies; 2+ messages in thread
From: Kevin Rodgers @ 2007-10-20  6:20 UTC (permalink / raw)
  To: help-gnu-emacs

ry2ngh@gmail.com 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
				      (line-end-position)))
	 (next-line (buffer-substring (line-beginning-position 2)
				      next-line-end))
	 (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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-10-20  6:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-02 18:53 overlay (combine) lines ry2ngh
2007-10-20  6:20 ` Kevin Rodgers

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.