From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: John Mastro Newsgroups: gmane.emacs.help Subject: Re: interleaving text lines of two regions Date: Fri, 27 Jan 2017 11:51:13 -0800 Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: blaine.gmane.org 1485546727 15166 195.159.176.226 (27 Jan 2017 19:52:07 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 27 Jan 2017 19:52:07 +0000 (UTC) Cc: "B. T. Raven" 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:52:03 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 1cXCYv-0003C0-Vu for geh-help-gnu-emacs@m.gmane.org; Fri, 27 Jan 2017 20:51:58 +0100 Original-Received: from localhost ([::1]:47591 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cXCZ1-0006hH-7u for geh-help-gnu-emacs@m.gmane.org; Fri, 27 Jan 2017 14:52:03 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59061) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cXCYZ-0006h9-Mp for help-gnu-emacs@gnu.org; Fri, 27 Jan 2017 14:51:36 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cXCYY-00026m-PR for help-gnu-emacs@gnu.org; Fri, 27 Jan 2017 14:51:35 -0500 Original-Received: from mail-qt0-x236.google.com ([2607:f8b0:400d:c0d::236]:35683) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cXCYY-00026f-KD for help-gnu-emacs@gnu.org; Fri, 27 Jan 2017 14:51:34 -0500 Original-Received: by mail-qt0-x236.google.com with SMTP id x49so151622856qtc.2 for ; Fri, 27 Jan 2017 11:51:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=9feERiYkyba1q8v03VbhcWiyCD87gAO36n1GytiWWXU=; b=hyhuWGqNfUL4G7TK0dHrGxMq9QllQfMRzdsj+TTWMQmc4bBatgKe7PrnEqUPxSHC7/ uX5fuHcDdciTYxIjugfAozOASlX3hqq0nvcq1OcIG9AhzCCMHu+bFnYeD9vbWbII2G7/ bqpNXUOyEa8j7bvepuROY7Pypi0TCRo65/uwfOdo4nq9tU9YhsCq1i92116I9mzAP8Xg lCV5eZJajDAILsfeDg9ID4lKf+Y2eb8MrJBnSzMCJ18jQhD7Ml+39DD17XvLBtt9dJkM SEh8LTG68XKR1sNsBWJ1awFOvj6ooIIhz6UBoIR0rzgDNlGmo9MiammM59Z8ujwdniEY F8lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=9feERiYkyba1q8v03VbhcWiyCD87gAO36n1GytiWWXU=; b=UxuHkV7bmxYrMTRatmcFZFJ5hoT7lTKWjMOQskanzYgjaDMCQGyFfRKo5Ifxn3WZvR cQ+g2NiRZflHbr0q/E4QnoTjYCSkboAIQD0ZZwgA1tY5QzDHXSBeWOIxcOVP1HPLAdwj LElSt9YrU22dr8t+1uVDeb1ETjEcy4ZcXzUvWCJ7eGUUxpQS1HYHPPq11BN/Udl9CaAT 57A1DNI5N5wGO02UumP3Hr737dwXi3CNIUF4Fdynwy/CwAYow8wfZo/T6XmRLfblNmOE GHZSbvEhuOeA2sAExVGYczUFws19+ITSn7J+P5WY5A2EKpS/PGinkwE2wzuceWXdnPJy JBnA== X-Gm-Message-State: AIkVDXKsKhSvOSSehaMzBtj1HeMocOIG/h1GZD+O1P2XfplCTzwGRN3xtIkqJKcnngVzUdaLhdWvHoAUS1dRTg== X-Received: by 10.233.232.194 with SMTP id a185mr9378848qkg.24.1485546693629; Fri, 27 Jan 2017 11:51:33 -0800 (PST) Original-Received: by 10.237.41.2 with HTTP; Fri, 27 Jan 2017 11:51:13 -0800 (PST) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400d:c0d::236 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:112177 Archived-At: B. T. Raven wrote: > 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: If I understand correctly, I think something simpler like this could work: (defun yank-interleaved () (interactive) (let ((lines-0 (split-string (current-kill 0 t) "\n" t "\\s-")) (lines-1 (split-string (current-kill 1 t) "\n" t "\\s-"))) (while (or lines-0 lines-1) (when lines-0 (insert (pop lines-0) "\n")) (when lines-1 (insert (pop lines-1) "\n"))))) It interleaves the last two kills (and could easily be generalized to interleave the last N kills). If I use `M-h M-w' on each of these two paragraphs: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccccccccccc xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz And then invoke `M-x yank-interleaved', I get this: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz cccccccccccccccccccccccccccccccccccccccc Which I think is correct, or on the right track anyway? John