I've tried following some of the other answered questions here regarding this topic but can't seem to get my head around this particular part of the problem.

I have the following function, which returns the value of a key :PROPERTIES: pair when a cursor is under an org header:

  (defun capture-noter-link ()
    "insert PROPERTY value of pdftools link"
    ;; (interactive)
    (let ((linkStr
               (switch-to-buffer (plist-get org-capture-plist :original-buffer))
               (org-entry-get nil "NOTER_PAGE"))
      (insert linkStr)))

Calling this function interactively while in the source org file gives me the desired result. I then tried to implement this in org-capture by using the following template:

("ai" "Anki IR"
 (file+headline org-my-anki-file "Incremental Reading Cards")
          "* %<%H:%M>   %^g\n:PROPERTIES:\n:ANKI_NOTE_TYPE: Cloze\n:ANKI_DECK: MegaDeck\n:END:\n** Text\n%x\n** Extra\n %(capture-noter-link)\n")

However the desired link isn't inserted into the capture buffer. What could I be doing wrong?

(defun insert-property(&optional p)
      "insert PROPERTY value of pdftools link"
      (unless p (setq p "TEST"))
      (message "property passed is: %s" p)
      (let ((pvalue
                 (message "%s" (org-capture-get :original-buffer))
                 (switch-to-buffer (org-capture-get :original-buffer))
                 (message "retrieved property is: %s" (org-entry-get (point) p))
                 (org-entry-get (point) p)

I don't think you need any (insert x) call for a start: the function itself should not insert the string - it should just return it.

I had a fiddle and came up with the above function, just to satisfy my own curiosity. I hope it helps. I used org-capture-get and also (point) but maybe that's an alternative way.

Just add %(insert-property "TEST")% in my capture template.

Test data:-

*** scratchpad                                              :tangle no:noexport:

My template:-

("t" "Todo" entry
  (file+headline "refile.org" "Tasks To Refile")
  "* TODO %? %(insert-property "TEST")%
:DateCreated: %T
  • "... in my capture template": can you add your capture template to your answer? That will make it self-contained and much more useful. – NickD Feb 3 '20 at 15:02
  • So you meant to write "... in your capture template"? If so, please say so. – NickD Feb 3 '20 at 15:29
  • I meant to say no such thing. I gave my code and said what needs to be inserted, I had that in MY template to test it. I'm quite happy to delete my solution if you insist on picking at minutiae. He gave his template and I gave MY code that he can try in HIS template. FWIW I did add my template to my working code. – RichieHH Feb 3 '20 at 15:57
  • Thank you for including the template. FWIW, I'm not trying to pick at minutiae: I'm trying to make the answer as useful as possible to the OP and anybody else who might have the same (or similar) question. I thought the basics of the answer were correct, so it was worth to improve it as much as possible. – NickD Feb 3 '20 at 16:52
  • Using the above example I get the desired PROPERTY echoed in the minibuffer when testing it interactively. I then remove (interactive) and test with your minimal scratchpad and template example, but the capture buffer returns this: ** TODO %(insert-property , with the last paren cut off like that. – ダニエル Feb 4 '20 at 1:34

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.