From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: "B. T. Raven" Newsgroups: gmane.emacs.help Subject: interleaving text lines of two regions Date: Fri, 27 Jan 2017 13:00:13 -0600 Organization: NewsGuy - Unlimited Usenet $23.95 Message-ID: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1485543947 16643 195.159.176.226 (27 Jan 2017 19:05:47 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 27 Jan 2017 19:05:47 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jan 27 20:05:38 2017 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cXBq1-0002x4-Lk for geh-help-gnu-emacs@m.gmane.org; Fri, 27 Jan 2017 20:05:33 +0100 Original-Received: from localhost ([::1]:47443 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cXBq3-0002GP-Ks for geh-help-gnu-emacs@m.gmane.org; Fri, 27 Jan 2017 14:05:35 -0500 Original-Path: usenet.stanford.edu!news.glorb.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!spln!extra.newsguy.com!newsp.newsguy.com!news4 Original-Newsgroups: gnu.emacs.help Original-Lines: 83 Original-NNTP-Posting-Host: pdbbf15bdfaa285df91a90672db2327c33fc7005e410ea79d.newsdawg.com X-Mozilla-News-Host: news://news.newsguy.net:8080 X-Received-Bytes: 3957 X-Received-Body-CRC: 3554983066 Original-Xref: usenet.stanford.edu gnu.emacs.help:219059 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:112176 Archived-At: Hello emacsworld: I use the 'paste' filter to interleave lines of two text files (as for example an original with a translation) but for shorter stretches of text it seems like Emacs could do the same thing with an interactive interleave-regions function. This would look something like ediff where the user would select region-1 and region-2 and then have elisp take the first line from one region and then insert the first line from the second region, and so on, to produce a new buffer with interleaved text. On the emacs wiki I found a 'yank-interleave function which probably has most of the code needed for the proposed 'interleave-regions but I don't quite understand it. In the *scratch* buffer I tested a mod of that function with the final three gibberish lines below and got back a faulty interleave as shown in the first lines: ;; This buffer is for notes you don't want to save, and for Lisp evaluation.asneuthoaseutheoaunteohuouesntuho aoeoasenthesnheosnthjoantheujoj santoehoaesuntoahonteheesnthu ;; If you want to create a file, visit that file with C-x C-f, ;; then enter the text in that file's own buffer. asneuthoaseutheoaunteohuouesntuho aoeoasenthesnheosnthjoantheujoj santoehoaesuntoahonteheesnthu I modified the function by removing the "separator" argument like this: (defun yank-interleaved () ;; original function called with argument 'separator' "Yank the previous kill, interleaving each line of the yanked text with a line in current buffer. Interleaving begins on the line containing point, and moves downward. If point is at the beginning of the line, the yanked lines are inserted before the buffer lines. If it is at the end of the line, the yanked lines are inserted after. If the argument SEPARATOR is given, insert this between each buffer line and yanked line." ;; TODO: Make it work with active region ;; (interactive "MSeparator: ") (interactive) (let ((yank (current-kill 1 t)) dir line) (if (null (string-match-p "\n" yank)) (yank) (setq dir (cond ((bolp) 'front) ((eolp) 'back) (t (user-error "Call with point at beginning or end of line")))) (setq yank (split-string yank "\n" t "\\s-")) (while (setq line (pop yank)) (if (eq dir 'front) (progn (beginning-of-line) (insert line) ;; (insert separator) ) (end-of-line) ;; (insert separator) (insert line)) (forward-line))))) Of course what I wanted to see was: ;; This buffer is for notes you don't want to save, and for Lisp evaluation. asneuthoaseutheoaunteohuouesntuho ;; If you want to create a file, visit that file with C-x C-f, aoeoasenthesnheosnthjoantheujoj ;; then enter the text in that file's own buffer. santoehoaesuntoahonteheesnthu Can any of you help me to understand what's going on and whether my proposed interleave-regions function would be worth pursuing for other applications? Thanks, Ed