Last active
October 27, 2018 17:44
-
-
Save wakatara/5d719e3dfba424fdf328b33b85d2a008 to your computer and use it in GitHub Desktop.
Archive all the org-mode journal files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun archive-done-org-journal-files () | |
"Cycles all org files through checking function." | |
(interactive) | |
(save-excursion | |
(mapc 'check-org-file-finito (directory-files "~/Desktop/test_archives/" t ".org$")) | |
)) | |
(defun check-org-file-finito (f) | |
"Checks TODO keyword items are DONE then archives." | |
(interactive) | |
(find-file f) | |
;; Shows open Todo items whether agenda or todo | |
(let ( | |
(kwd-re | |
(cond (org-not-done-regexp) | |
( | |
(let ((kwd | |
(completing-read "Keyword (or KWD1|KWD2|...): " | |
(mapcar #'list org-todo-keywords-1)))) | |
(concat "\\(" | |
(mapconcat 'identity (org-split-string kwd "|") "\\|") | |
"\\)\\>"))) | |
((<= (prefix-numeric-value) (length org-todo-keywords-1)) | |
(regexp-quote (nth (1- (prefix-numeric-value)) | |
org-todo-keywords-1))) | |
(t (user-error "Invalid prefix argument: %s"))))) | |
(if (= (org-occur (concat "^" org-outline-regexp " *" kwd-re )) 0) | |
(rename-file-buffer-to-org-archive) | |
(kill-buffer (current-buffer)) | |
))) | |
(defun rename-file-buffer-to-org-archive () | |
"Renames current buffer and file it's visiting." | |
(interactive) | |
(let ((name (buffer-name)) | |
(filename (buffer-file-name)) | |
) | |
(if (not (and filename (file-exists-p filename))) | |
(error "Buffer '%s' is not visiting a file!" name) | |
(let ((new-name (concat (file-name-sans-extension filename) ".org_archive"))) | |
(if (get-buffer new-name) | |
(error "A buffer named '%s' already exists!" new-name) | |
(rename-file filename new-name 1) | |
(rename-buffer new-name) | |
(set-visited-file-name new-name) | |
(set-buffer-modified-p nil) | |
(kill-buffer (current-buffer)) | |
(message "File '%s' successfully archived as '%s'." | |
name (file-name-nondirectory new-name))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment