help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: interleaving text lines of two regions


From: John Mastro
Subject: Re: interleaving text lines of two regions
Date: Fri, 27 Jan 2017 12:01:29 -0800

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"))))))



reply via email to

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