I'm using Emacs to create text to copy to another program, but I need to copy line by line. I'm using a variation of
kill-ring-save I provide below.
(defun my-kill-ring-save ()
(if (equal mark-active nil) (kill-ring-save (point) (line-end-position)) (kill-ring-save (point) (mark))))
(global-set-key "\M-w" 'my-kill-ring-save)
So I would do this:
M-wto copy the line
- Alt-Tab to go to the other program
- Ctrl-v to paste the line
- Alt-Tab to go back to Emacs
C-ktwo times (delete the current line, and again so the next line moves up)
- Repeat the process
The problem is that when I hit Ctrl-v in the other program sometimes it yanks not only the line I want, but other previously deleted lines. I read that the paste command should only paste the last line in the kill ring, thats what I would like it to do. This problem only happens (as far as I know) If I
C-k two times fast and right after copying the line with M-w. If I kill lines with
C-k, wait for 3 seconds, I'm able to
M-w the current line and paste just this line. Sorry if it seems like a exageration of a small problem, but I'm actually doing this process a lot of times so any solution would be great for me. I couldn't find any related problem about this specficic issue.
EDIT: the solution below unfortunately didn't work or I couldn't use it correctly, appreciate any update on this, thanks!