How do I immediately save the .org buffer created by org-archive-location?

Context and what I've tried so far

Current .emacs settings:

FILE: .emacs
(setq org-archive-location (concat "~/Documents/Reference/org/archive/" (format-time-string "%Y-%m") ".org::"))


FILE: main2.org
* Done item

Calling org-archive-location with C-c $ results in the following buffers

FILE: *Messages*
Subtree archived in file: ~/Documents/Reference/org/archive/2019-06.org


FILE: 2019-06.org
Archived entries from file /Users/janmeppe/Documents/Reference/org/main2.org

* Done item 
:ARCHIVE_TIME: 2019-06-18 Tue 11:26
:ARCHIVE_FILE: ~/Documents/Reference/org/main2.org

Now the problem is this, I have to manually save the buffer for it to appear in the finder, how do I automatically save this buffer after calling org-archive-location?

I tried adding the following but it this help

(advice-add 'org-archive-location :after #'org-save-all-org-buffers)

org-archive-location is not a function that can be modified with advice. It is a variable. Perhaps the O.P. meant to say org-archive-subtree? Type C-h k (aka M-x describe-key) and then the keyboard shortcut to see what function is triggered ....

(advice-add 'org-archive-subtree :after #'org-save-all-org-buffers)

I would prefer to save only the buffer containing the archived subtree and the buffer from which it was archived/removed, but that would take some additional digging into the code and doing some testing ... Perhaps another forum participant would like to write up an alternate answer that uses a scalpel instead of the org-save-all-org-buffers (which is a sledgehammer).

| improve this answer | |
  • No time to dig either, but org-archive-hook runs after successfully archiving a subtree, with point in the original file. There is also the variable org-archive-location which indicates where subtrees should be archived for the current file. Unfortunately, org-archive-location uses some bizarro syntax which isn't a file path. If someone can figure out how to expand the org-archive-location into a normal file system path, then org-archive-hook could be made to 1. save the current org file and 2. the corresponding archive file. – Lorem Ipsum Sep 20 '19 at 12:55

I found a workaround with the same functionality but it works on calling save-buffer which I call often with :w in evil. I'm not marking this as the correct answer because it does not answer the question (i.e. how to save immediately after org-archive-location) but I'd like to share it because it results in the same functionality.

(advice-add 'save-buffer :after #'org-save-all-org-buffers)
| improve this answer | |

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.