With this setup (setq org-log-refile 'time) I have the following notes added to my TODO entry that I refiled (already twice and it is ended up in long someday-maybe):

* TASK Note on where the entry was refiled from
- Refiled on [2016-04-04 Mon 00:57]
- Refiled on [2015-05-15 Fri 13:53]
- State "TASK"       from ""           [2015-05-15 Fri 13:53]

What I would also like to have is the note about the place where it was refiled from. Like so:

* TASK Note on where the entry was refiled from
- Refiled on [2016-04-04 Mon 00:57] from ~/emacs-tasks.org::*Tasks%20workflow
- Refiled on [2015-05-15 Fri 13:53] from ~/stuff.org
- State "TASK"       from ""           [2015-05-15 Fri 13:53]

The problem is that the templates for adding notes org-log-note-headings do not support a proper placeholder (something like %F used in org-capture-templates). Moreover, it is explicitly not recommended to change these templates. Any suggestions how to achieve desired result?


For now I came up with the following work around:

;; do not use default refile logging
(setq org-log-refile nil)

;; add custom logging instead
(add-hook 'org-after-refile-insert-hook #'clavis-org-refile-add-refiled-from-note)

(advice-add 'org-refile

(defvar clavis-org-refile-refiled-from-id nil)
(defvar clavis-org-refile-refiled-from-header nil)

(defun clavis-org-save-source-id-and-header ()
  "Saves refile's source entry's id and header name to `clavis-org-refile-refiled-from-id' and `clavis-org-refile-refiled-from-header'. If refiling entry is first level entry then it stores file path and buffer name respectively."
    (if (org-up-heading-safe)
          (setq clavis-org-refile-refiled-from-id (org-id-get nil t))
          (setq clavis-org-refile-refiled-from-header
                (org-get-heading 'no-tags 'no-todo 'no-priority 'no-comment)))
      (setq clavis-org-refile-refiled-from-id (buffer-file-name))
      (setq clavis-org-refile-refiled-from-header (buffer-name)))))

(defun clavis-org-refile-add-refiled-from-note ()
  "Adds a note to entry at point on where the entry was refiled from using the org ID from `clavis-org-refile-refiled-from-id' and `clavis-org-refile-refiled-from-header' variables."
  (when (and clavis-org-refile-refiled-from-id
      (let* ((note-format "- Refiled on [%s] from [[id:%s][%s]]\n")
             (time-format (substring (cdr org-time-stamp-formats) 1 -1))
             (time-stamp (format-time-string time-format (current-time))))
        (goto-char (org-log-beginning t))
        (insert (format note-format
    (setq clavis-org-refile-refiled-from-id nil)
    (setq clavis-org-refile-refiled-from-header nil)))

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.