7

I maintain an org file with a lot of draft posts (here's a link to the file). My workflow is to work on a draft post, and once it's ready to get published, I copy it to a new org file, which I then push to my pelican based blog.

What I would have liked to do, is use the refile command to help me with moving the subtree, which represent a post, to the new post file.

My research led me to few answers here at stack-overflow. I implemented this function:

(require 'org-element) (defun me/org-file-from-subtree (&optional name) "Cut the subtree currently being edited and create a new file from it. If called with the universal argument, prompt for new filename, otherwise use the subtree title." (interactive "P") (org-back-to-heading) (let ((filename (cond (current-prefix-arg (expand-file-name (read-file-name "New file name: "))) (t (concat (expand-file-name (org-element-property :title (org-element-at-point)) default-directory) ".org"))))) (org-cut-subtree) (find-file-noselect filename) (with-temp-file filename (org-mode) (yank)))) 

Source: Jonathan Leech-Pepin's answer here.

This function works, but it doesn't carry the footnotes defined in the subtree I'm trying to refile. Any idea how I can cut the footnotes together with the subtree?

UPDATE: Adding an example for what I'm trying to achieve. Given this org file:

* Drafts ** First Post Lorem ipsum dolor sit amet, fermentum vulputate laoreet eligendi,[fn:1] magna wisi elit scelerisque ** Second Post Ultrices natoque sollicitudin duis curabitur, quam pellentesque ante aliquam nulla aenean, dui egestas ipsum adipiscing, sem nulla sit nisl, parturient[fn:2] habitasse ac amet at eget suspendisse. * Footnotes [fn:1] This is a footnote for the first post [fn:2] This is a footnote for the second post 

Now, what I want to be able to do is move the first post, together with it's footnote (fn:1) to a new file.

Thanks. Yaniv

(I should say that I'm new to emacs, and still don't really comprehend the lisp code I put in my init... so I might be missing something very basic)

4
  • See the following detailed example of how to programmatically use org-archive-subtree / org-archive-location / org-archive-save-context-info to move subtrees anywhere you want: stackoverflow.com/a/22232709/2112489 I do not use footnotes, so you would need to see if org-archive-subtree handles them in a way that meets your needs. If it is just an issue of expanding the region being selected, then consider modifying your post to provide a detailed example of what it is that you are trying to cut/move so people can use your test data to create a working solution. Commented Nov 24, 2015 at 4:15
  • Thanks @lawlist, the example you provided is very insightful. Unfortunately, the org-archive-subtree doesn't pick the footnotes with the subtree. Commented Nov 24, 2015 at 17:33
  • I recommend advising org-archive-subtree to run a function at the tail end that pastes the footnote information in the target file at the desired location (let (footnote) (save-excursion (org-back-to-heading t) (org-narrow-to-subtree) (while (re-search-forward "\\[fn:[0-9]+\\]" nil t) (push (cons (buffer-substring-no-properties (match-beginning 0) (match-end 0)) nil) footnote)) (widen) (org-end-of-subtree t t) (setq footnote (mapcar (lambda (x) (and (search-forward (car x) nil t nil) (cons (car x) (buffer-substring-no-properties (match-beginning 0) (point-at-eol))))) footnote))) footnote) Commented Nov 25, 2015 at 17:52
  • Thanks @lawlist. I'm not sure I know how to mend the org-archive-subtree. Any chance you can advise how your snippet can be added to the function I use to refile to a new file (see in my original question - me/org-file-from-subtree)? Commented Nov 25, 2015 at 19:00

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.