I want to add notes to a heading but instead of using org-add-note, it should be possible to choose any date I want to have as time stamp. I use notes partly as Diary so I want to be able to create an entry without having to manipulate it afterwards for the desired date.

I wrote this function to accomplish this:

  (defun tietan/org-add-note-ts ()
    (let ((date (org-read-date))(res)(inp))
      (setq res (concat "- Note taken on <"
                        "> \\\\\n"
                        (tietan/simplified-read-mb-lines "Insert text (C-j to submit): ") ))
      (setq res (replace-regexp-in-string (regexp-quote "\n") "\n  " res nil 'literal))
      (kill-new res)

Now the questions:

  1. Is there a better way to achieve date selection for org-add-note? I still have to manually insert the output of this function into the org-heading. org-capture would always need a specific configuration for that, which doesn't suit my wish to have it as a possible solution for multiple use cases.

  2. Which function could I use to get the same buffer input window you normally get with org-add-note?


I copied the multiline block prompt from here https://stackoverflow.com/a/17004260 and changed the name to better fit in my personal naming conventions

(defun tietan/simplified-read-mb-lines (prompt)
    (let ((keymap (copy-keymap minibuffer-local-map)))
      (define-key keymap (kbd "RET") 'newline)
      (read-from-minibuffer prompt nil keymap)))

How about:

(defun my-org-add-note ()
  (move-marker org-log-note-marker (point))
  (setq org-log-note-purpose 'note
        org-log-note-effective-time (org-read-date nil t))
  (add-hook 'post-command-hook 'org-add-log-note 'append))

This sets org-log-note-effective-time to org-read-date. Everything else should be the same.

  • Thank you this is exactly what I needed. I'm curios of how to find those steps that need to be done. Could you give me a hint of where I can find the procedures a function like org-add-note uses, so that in the future I could come up with this (way better) solution myself.
    – Tietan
    Jan 12 at 6:44
  • Do C-h f org-add-note to see the documentation of the function. Among other things, it also gives a link to the definition of the function (look for the file name at the end of the first line which says: org-add-note is a Lisp closure in ‘org.el’. - that org.el is a clickable link that will take you to the definition of the function). Once there, you'll see that it calls org-add-log-setup with an argument of note (a symbol). Repeating the process, you'll get to the definition of that function: compare it with the function in the answer.
    – NickD
    Jan 12 at 8:44

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.