Commit def2072bd2c2

Vincent Demeester <vincent@sbr.pm>
2017-05-13 15:45:36
Add a org-mode auto archiving feature
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent ec763f3
Changed files (2)
.emacs.d/emacs.el
@@ -524,7 +524,7 @@
   (defun custom-persp/magit-docker ()
     (interactive)
     (custom-persp "magit-docker"
-              (magit-status (substitute-env-in-file-name "$HOME/go/src/github.com/docker/docker"))))
+   	   (magit-status (substitute-env-in-file-name "$HOME/go/src/github.com/docker/docker"))))
   (defun custom-persp/magit-docker-pipeline ()
     (interactive)
     (custom-persp "magit-pipeline"
@@ -1091,6 +1091,25 @@ With prefix argument, also display headlines without a TODO keyword."
 (require 'org-archive)
 (setq org-archive-location (concat org-archive-directory org-archive-file-pattern))
 
+(defvar org-my-archive-expiry-days 9
+  "The number of days after which a completed task should be auto-archived.
+This can be 0 for immediate, or a floating point value.")
+
+(defun org-archive-done-tasks ()
+  (interactive)
+  (save-excursion
+    (goto-char (point-min))
+    (while (re-search-forward "\* \\(DONE\\|CANCELED\\) " nil t)
+   (if (save-restriction
+            (save-excursion
+   	   (org-narrow-to-subtree)
+   	   (search-forward ":LOGBOOK:" nil t)))
+          (forward-line)
+        (org-archive-subtree)
+        (goto-char (line-beginning-position))))))
+
+(defalias 'archive-done-tasks 'org-archive-done-tasks)
+
 (setq org-tags-column -90)
 
 ;; Wish I could use taggroup but it doesn't seem to work..
.emacs.d/emacs.org
@@ -2016,6 +2016,30 @@
      (setq org-archive-location (concat org-archive-directory org-archive-file-pattern))
    #+END_SRC
 
+   Let's also have some /auto-archive/ stuff, taken inspiration from [[http://article.gmane.org/gmane.emacs.orgmode/2963][john wiegley]].
+
+   #+BEGIN_SRC emacs-lisp
+     (defvar org-my-archive-expiry-days 9
+       "The number of days after which a completed task should be auto-archived.
+     This can be 0 for immediate, or a floating point value.")
+
+     (defun org-archive-done-tasks ()
+       (interactive)
+       (save-excursion
+         (goto-char (point-min))
+         (while (re-search-forward "\* \\(DONE\\|CANCELED\\) " nil t)
+        (if (save-restriction
+                 (save-excursion
+      	     (org-narrow-to-subtree)
+      	     (search-forward ":LOGBOOK:" nil t)))
+               (forward-line)
+             (org-archive-subtree)
+             (goto-char (line-beginning-position))))))
+
+     (defalias 'archive-done-tasks 'org-archive-done-tasks)
+   #+END_SRC
+   
+
 ** Tags
 
    Tags should be displayed from the 90 column.