0

How can I make a function that copies text from line number N at point? I will be at some specific line and point position and want to copy the text from a different line N.

1 Answer 1

3
(defun foo (n)
  "Copy line N to the kill-ring.
N is the numeric prefix arg"
  (interactive "p")
  (save-excursion
    (goto-char (point-min))
    (forward-line (1- n))
    (kill-ring-save (line-beginning-position) (line-end-position))))
6
  • How would I use it?
    – Dilna
    Jan 28, 2023 at 3:18
  • I would like to have a variation where I can pass the line number N from the mode-line.
    – Dilna
    Jan 28, 2023 at 3:28
  • You say C-u N M-x foo RET C-y where N is the desired line number.
    – NickD
    Jan 28, 2023 at 3:34
  • "... from the modeline" - you mean from the minibuffer?
    – NickD
    Jan 28, 2023 at 3:35
  • From minibuffer that you say.
    – Dilna
    Jan 28, 2023 at 4:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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