| (defadvice org-archive-subtree (around fix-hierarchy activate) | |
| (let* ((fix-archive-p (and (not current-prefix-arg) | |
| (not (use-region-p)))) | |
| (afile (org-extract-archive-file (org-get-local-archive-location))) | |
| (buffer (or (find-buffer-visiting afile) (find-file-noselect afile)))) | |
| ad-do-it | |
| (when fix-archive-p | |
| (with-current-buffer buffer | |
| (goto-char (point-max)) | |
| (while (org-up-heading-safe)) | |
| (let* ((olpath (org-entry-get (point) "ARCHIVE_OLPATH")) | |
| (path (and olpath (split-string olpath "/"))) | |
| (level 1) | |
| tree-text) | |
| (when olpath | |
| (org-mark-subtree) | |
| (setq tree-text (buffer-substring (region-beginning) (region-end))) | |
| (let (this-command) (org-cut-subtree)) | |
| (goto-char (point-min)) | |
| (save-restriction | |
| (widen) | |
| (-each path | |
| (lambda (heading) | |
| (if (re-search-forward | |
| (rx-to-string | |
| `(: bol (repeat ,level "*") (1+ " ") ,heading)) nil t) | |
| (org-narrow-to-subtree) | |
| (goto-char (point-max)) | |
| (unless (looking-at "^") | |
| (insert "\n")) | |
| (insert (make-string level ?*) | |
| " " | |
| heading | |
| "\n")) | |
| (cl-incf level))) | |
| (widen) | |
| (org-end-of-subtree t t) | |
| (org-paste-subtree level tree-text)))))))) |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
nerrons
commented
Mar 7, 2017
•
|
It seems that only the level 1 titles will be also recorded in the _archive file, but not level 2, level 3, etc. For example, when I have Is there any ways to fix it? Org mode version 9.0.5 |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Fuco1
Apr 20, 2017
@tsktsktsk64 It works for me as expected on Emacs 24.5.1 with Org mode 9.0.5.
I think some function might have changed in new Emacs to make this stop working.
You could try to edebug the form and then step through it to see where it fails. I will fix it one day when I migrate to Emacs 25 for sure :)
|
@tsktsktsk64 It works for me as expected on Emacs 24.5.1 with Org mode 9.0.5. I think some function might have changed in new Emacs to make this stop working. You could try to edebug the form and then step through it to see where it fails. I will fix it one day when I migrate to Emacs 25 for sure :) |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Fuco1
Apr 30, 2017
This has been turned into a blog post here: https://fuco1.github.io/2017-04-20-Archive-subtrees-under-the-same-hierarchy-as-original-in-the-archive-files.html
|
This has been turned into a blog post here: https://fuco1.github.io/2017-04-20-Archive-subtrees-under-the-same-hierarchy-as-original-in-the-archive-files.html |
It seems that only the level 1 titles will be also recorded in the _archive file, but not level 2, level 3, etc.
For example, when I have
* L1** L2*** L3and I
org-archive-subtreewhen my cursor is on** L3, this is what I get in the _archive file:* L1** L3Is there any ways to fix it?
Thank you so much for your work.
Org mode version 9.0.5
GNU Emacs 25.1.1 (x86_64-apple-darwin16.1.0, NS appkit-1504.60 Version 10.12.1 (Build 16B2555)) of 2016-11-27