I want to get the first line of the buffer I'm actually in. More generally, I'm looking for a utility that returns Nth line from a supplied buffer. Is there some built-in for that?

  • FWIW, this operation is not provided by any built-in, because it's not something you'd normally ever need. So I suspect that there's another way to do what you want which does not require such an operation.
    – Stefan
    Commented Jul 11, 2016 at 14:14
  • @Stefan I want to do something with data in file, and for that I need some information that is stored in the first line. Commented Jul 11, 2016 at 14:27
  • That much I could guess.
    – Stefan
    Commented Jul 11, 2016 at 17:38

1 Answer 1


This could be done with the next function (with or without narrowing):

(defun get-nth-line (number)
  "Get line with NUMBER"
      (goto-line number)
      (buffer-substring-no-properties (line-beginning-position)

To get the first line execute

(get-nth-line 1)

If you want to get text properties, then use buffer-substring instead of buffer-substring-no-properties.


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.