Preface this by saying I program but I'm not a programmer, and I especially don't know lisp.

I use org capture during code reviews, and we use line numbers as a way or organizing changes that need to be made. Is there a way to have org-capture include the line number that point was at when org capture was called?

  • This issue was raised before. Looks like the template language did not implement the (line-number-at-pos) function.
    – Emacs User
    Commented Nov 19, 2015 at 20:23
  • I saw that thread too, but that is a different issue. They were modifying org-store-link so that links included the line number, and the OP was disappointed that the link didn't jump to the line number. I don't want it in a link, I just want the number.
    – PaulB
    Commented Nov 19, 2015 at 21:37
  • If all you need is the line number, then use \n%(number-to-string (line-number-at-pos))\n in the template.
    – Emacs User
    Commented Nov 19, 2015 at 22:47
  • That's close! but it actually the gives me the line number of the caputre buffer, which is always 3 in my template. Any idea how to get it to use the line number from the buffer in which org-capture is called?
    – PaulB
    Commented Nov 20, 2015 at 22:22
  • You're probably doing it in the capture template and not in the link template or link types. Org website has examples of creating new link types. Make one with line number and use that in your capture template. That was the issue I gave you the link for earlier.
    – Emacs User
    Commented Nov 20, 2015 at 22:38

2 Answers 2


The org-capture function puts some properties into the org-capture-plist, i. a. :original-buffer, :original-file and :original-file-nondirectory, which all point to the buffer/file where the capture has been initiated from. The following addition to your capture template will insert the line-number at point in the original buffer:

%(with-current-buffer (org-capture-get :original-buffer) (number-to-string (line-number-at-pos)))

Well this might not be the best answer, but what I did was wrap org-capture in a function that sets a global variable to the line number right before calling org-capture.

Here's the function I used to set the plus-line-capture:

(defun org-plus-line-capture ()
  (setq plus-line-capture (number-to-string (line-number-at-pos)))

Then in the capture template you can do this:

[[file://%F::%(concat plus-line-capture)][%^{Link Text}]]
  • %(with-current-buffer (org-capture-get :original-file-nondirectory) (number-to-string (line-number-at-pos))) in your capture template will do the same without any variable assignment.
    – mutbuerger
    Commented Jul 22, 2016 at 12:00
  • Well if this works, then this seems like the actual answer to the question; yes-no?
    – lucidquiet
    Commented Jul 25, 2016 at 18:35
  • You're right, I'll add an answer.
    – mutbuerger
    Commented Jul 25, 2016 at 18:52

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.