From: John Mastro <john.b.mastro@gmail.com>
To: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Subject: Re: interleaving text lines of two regions
Date: Fri, 27 Jan 2017 12:01:29 -0800 [thread overview]
Message-ID: <CAOj2CQR4anjafuYWwFWj2=D3P3kptmn9-qJp9+BkTAOBSgRvhg@mail.gmail.com> (raw)
In-Reply-To: <CAOj2CQQfbFVb4rg2sy=9k09ubgFzTEvw6Gd92wHEKu-dTvEd5g@mail.gmail.com>
John Mastro <john.b.mastro@gmail.com> wrote:
>
> 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).
Just for one, here's a version that interleaves the last N kills
(default 2):
(defun yank-interleaved (n)
(interactive
(list (if current-prefix-arg (prefix-numeric-value current-prefix-arg) 2)))
(let ((yanks (mapcar (lambda (i)
(split-string (current-kill i t) "\n" t "\\s-"))
(number-sequence 0 (1- n)))))
(while (seq-some #'consp yanks)
(dotimes (i n)
(when (nth i yanks)
(insert (pop (nth i yanks)) "\n"))))))
prev parent reply other threads:[~2017-01-27 20:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-27 19:00 interleaving text lines of two regions B. T. Raven
2017-01-27 19:51 ` John Mastro
2017-01-27 20:01 ` John Mastro [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAOj2CQR4anjafuYWwFWj2=D3P3kptmn9-qJp9+BkTAOBSgRvhg@mail.gmail.com' \
--to=john.b.mastro@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.