summary refs log tree commit diff
diff options
context:
space:
mode:
authorFranck Cuny <fcuny@twitter.com>2019-12-09 10:41:45 -0800
committerFranck Cuny <fcuny@twitter.com>2019-12-09 10:41:45 -0800
commit3acb681bc552d8c0f049595a261b9ded272d0c52 (patch)
treeaf6876497f7415d7c98bfcaa60f9b989a39a69dd
parent[emacs] don't hide directories info. (diff)
downloademacs.d-3acb681bc552d8c0f049595a261b9ded272d0c52.tar.gz
[org] Add functions to refile to datetree
I want to be able to refile some notes to a datetree. These new
functions do just that, and one of them is specific to the work
journal.
Diffstat (limited to '')
-rw-r--r--emacs.d/custom/fcuny-org.el46
1 files changed, 32 insertions, 14 deletions
diff --git a/emacs.d/custom/fcuny-org.el b/emacs.d/custom/fcuny-org.el
index 9825ca9..a4bd7a8 100644
--- a/emacs.d/custom/fcuny-org.el
+++ b/emacs.d/custom/fcuny-org.el
@@ -3,6 +3,15 @@
 (use-package dash
   :ensure t)
 
+(defvar org-directory (expand-file-name "~/Documents/notebooks"))
+(defvar org-default-tasks-file (concat org-directory "/tasks.org"))
+(defvar org-default-journal-file (concat org-directory "/journal.org"))
+(defvar org-default-notes-file (concat org-directory "/notes.org"))
+(defvar org-default-work-tasks-file (concat org-directory "/work-tasks.org"))
+(defvar org-default-work-journal-file (concat org-directory "/work-journal.org"))
+(defvar org-default-work-notes-file (concat org-directory "/work-notes.org"))
+(defvar org-default-inbox-file (concat org-directory "/inbox.org"))
+
 (use-package org
   :after (dash)
   :ensure t
@@ -53,20 +62,6 @@ _g n_: go to notes
   (org-lowest-priority ?D)
   (org-default-priority ?D) ;; Ensures unset tasks have low priority.
 
-  ;; files
-  (org-directory (expand-file-name "~/Documents/notebooks"))
-  ;; (org-archive-location "~/Documents/notebooks/journal.org::datetree/* Finished Tasks")
-
-  (org-default-tasks-file (concat org-directory "/tasks.org"))
-  (org-default-journal-file (concat org-directory "/journal.org"))
-  (org-default-notes-file (concat org-directory "/notes.org"))
-
-  (org-default-work-tasks-file (concat org-directory "/work-tasks.org"))
-  (org-default-work-journal-file (concat org-directory "/work-journal.org"))
-  (org-default-work-notes-file (concat org-directory "/work-notes.org"))
-
-  (org-default-inbox-file (concat org-directory "/inbox.org"))
-
   ;; how to manage tasks
   (org-todo-keywords '((sequence "TODO(t)" "STARTED(s)" "DELEGATED(D)" "|" "DONE(d)")
                        (sequence "SOMEDAY" "|" "CANCELED(c)")))
@@ -262,4 +257,27 @@ _g n_: go to notes
      ((< days 358) (format "%.1fM" (/ days 30.0)))
      (t            (format "%.1fY" (/ days 365.0))))))
 
+(defun fcuny/org-refile-to-datetree (&optional file)
+"Refile current subtree to a datetree in FILE corresponding to it's timestamp.
+The current time is used if the entry has no timestamp. If FILE
+is nil, refile in the current file."
+  (interactive)
+  (require 'org-datetree)
+  (let* ((file (cond
+                (file (find-file-noselect file))
+                (t (current-buffer))))
+         (datetree-date (or (org-entry-get nil "CREATED" t)
+                            (org-entry-get nil "TIMESTAMP_IA" t)
+                            (org-read-date t nil "now")))
+         (date (org-date-to-gregorian datetree-date)))
+    (org-refile nil nil (list nil (buffer-file-name file) nil
+                              (with-current-buffer file
+                                (save-excursion
+                                  (org-datetree-find-date-create date)
+                                  (point)))))))
+
+(defun fcuny/org-refile-to-work-journal ()
+  (interactive)
+  (fcuny/org-refile-to-datetree org-default-work-journal-file))
+
 (provide 'fcuny-org)