I like to use org-refile to refile notes during the capture process. But, since org-refile does not saves the file after the refiling is done, the file ends up being locked up and I need to visit the file and manually save the buffer in order to access it from another emacs process or another application. Emacs also ask me if I want to save the file upon exit.

Is there anyway to make org-refile save the file automatically after the capture process is done?

I also note that after refiling there is no buffer opened associated with the file, still, if I visit the file the buffer appears as modified and the changes are not saved.

  • there's no "after-refile hook" (I think), but you can just add an advice :after to org-refile to save the current buffer if it's associated with a file. See Advising Emacs Lisp Functions. – rasmus Jan 6 '16 at 1:04
  • Which version of emacs are you using, and which version of org-mode? You can find your org-mode version with M-x org-version. For me, using org-refile from the org-capture buffer works fine, and the first thing I see in the echo area is Wrote /path/to/my/org/file indicating that the file was indeed saved after capture. My suspicion is that whatever file you are refiling to is open in another emacs frame/instance. Could this be the case? – elethan Jan 6 '16 at 2:09
  • @ramus org-after-refile-insert-hook runs after the entry is put in the new location, but before it is removed from the old. – erikstokes Jan 6 '16 at 2:38
  • @elethan, I'm using org 8.3.2, I get the same message in the echo area but the file is still not saved. – GPeraza Jan 7 '16 at 3:02
  • I have added an advice to org-refile to save all org buffers following @rasmus comment. This fixes the problem, how do I mark this as the correct answer? – GPeraza Jan 7 '16 at 3:03

There is no hook for org-refile that could usefully save the buffer (there's org-after-refile-insert-hook but it won't help). Since you're capturing you can use org-capture-after-finalize-hook to save. Since you're refiling you don't know which file needs to be save, so just save them all:

(add-hook 'org-capture-after-finalize-hook #'org-save-all-org-buffers)
  • Adding this hook does not work, I think the refiled buffer closes before capture finalizes. But adding an advice to org-refile to save all buffers after refiling seems to work. See rasmus comment to the main post. – GPeraza Jan 7 '16 at 3:05
  • org-capture-prepare-finalize-hook claims the capture buffer is still current when it runs. Perhaps that would work? – erikstokes Jan 7 '16 at 3:09

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.