How to configure org-archive-location in org-mode correctly

BACKGROUND: In org mode, the variable org-archive-location defaults to "% s_archive ::", so the file "toto.org" is archived in the file "toto.org_archive". I would like to archive instead in "toto.ref". I am using org-mode version 7.4 (outside the git server).

I would think that it is as simple as

(setq org-archive-location '(replace-regexp-in-string ".org" ".ref" %s) ) 

But I was told that this is not correct in LISP (plus, this does not work). My final solution is this: you should be able to adapt to the smartest org-archive-location configurations:

 (setq org-archive-location "%s::* ARCHIVES") (defadvice org-extract-archive-file (after org-to-ref activate) (setq ad-return-value (replace-regexp-in-string "\\.org" ".ref" ad-return-value) ) ) 

Note:

1) I didn’t voluntarily add $ at the end of ".org" so that it correctly changes "test.org.gpg" to "test.ref.gpg".

2) It seems that the regular expression "\ .org" (and not, say, ".org") should be used (a more detailed explanation in the answers below).

+4
source share
4 answers

You cannot define a variable in Emacs so that its value is obtained by running the code; variables have simple static values.

You can get the described effect by reporting the function org-extract-archive-file , which creates the archive location from org-archive-location :

 (defadvice org-extract-archive-file (after org-to-ref activate) (setq ad-return-value (replace-regexp-in-string "\\.org" ".ref" ad-return-value))) 

Now this works for me, but, of course, the internals of org-mode can be changed, and this solution may not work forever.

+3
source

You do not have to quote expression you want to evaluate. Also note that in regex . matches any character.

+2
source

Here is an example of how to set the file, location (for example, the main header) in the file and whether or not to include additional information about the archive:

 (let* ( (org-archive-location "~/todo.org::* TASKS") (org-archive-save-context-info nil)) ...) 
0
source

You can try: #+ARCHIVE: %s.ref:: at the beginning of your org file. Read more about it here .

In addition, another interesting option is to install the following inside your headtree, for example:

 * Main Header of tree :PROPERTIES: :ARCHIVE: toto.ref:: * Main Header of tree in archive file :END: ** sub tree of main header and so on 

The last one I took from this video .

0
source

Source: https://habr.com/ru/post/1340383/


All Articles