I have two files open, shown in two windows.

Some lines in one file belong in the other file.

I could cut the line here, move to the other window, paste there, and come back. That's a lot of work with so many lines to go through.

There does not seem to be any existing command that would do the work, so how do I write an elisp function (or macro?), and bind it to an available key/chord, to do that?

This is similar to the problem solved by diff-mode and the like, but the files here are not related, so a diff doesn't make sense.

[edit 1] very good point raised by @StarBug. I see several possibilities (a configuration variable?), listed from top to bottom: a. move at the top, b. move at point, c. move to 'same' line on screen, d. move to bottom.

[edit 2] fixed the confusion between frame and window.

  • I like the idea of a function that facilitates copy/paste between two frames in some clever way. However, I am sure exactly what you want. How would the function "know" where to paste the text in frame 2?
    – StarBug
    Sep 3, 2020 at 11:56
  • Just to be sure: You do mean frames, not Emacs windows, right?
    – Drew
    Sep 3, 2020 at 18:05

1 Answer 1


As mentioned by @StarBug, one UI problem will be how to specify the "other" buffer/frame.

But you could start with something like:

(defun my-command (beg end)
   (if (use-region-p)
       (list (region-beginning) (region-end))
     (list (line-beginning-position)
           (line-beginning-position 2))))
  (let ((line (delete-and-extract-region beg end)))
    (with-selected-frame (other-frame)
      (insert line))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.