summary refs log tree commit diff
path: root/emacs
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2021-02-12 09:27:43 -0800
committerFranck Cuny <franck@fcuny.net>2021-02-12 09:27:43 -0800
commit13db79415ce2e9f7215f47bade0ee64361c8a154 (patch)
tree12fe4dce66717b74a4eb878b3f7a6da38a655096 /emacs
parentemacs: no snippets (diff)
downloademacs.d-13db79415ce2e9f7215f47bade0ee64361c8a154.tar.gz
org: custom functions
Add a few custom functions for org-mode.
Diffstat (limited to 'emacs')
-rw-r--r--emacs/lisp/fcuny-org-custom.el33
1 files changed, 33 insertions, 0 deletions
diff --git a/emacs/lisp/fcuny-org-custom.el b/emacs/lisp/fcuny-org-custom.el
new file mode 100644
index 0000000..d1b30cd
--- /dev/null
+++ b/emacs/lisp/fcuny-org-custom.el
@@ -0,0 +1,33 @@
+(defun fcuny/org-new-datetree-at-point ()
+  (interactive)
+  (org-up-heading-safe)
+  (org-datetree-find-date-create
+   (calendar-gregorian-from-absolute (org-today))
+   'subtree-at-point))
+
+(defun org-refile-to-datetree (&optional file)
+  "Refile a subtree to a datetree 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. A datetree within a subheading
+is possible if the heading has a property of DATE_TREE."
+  (interactive "f")
+  (let* ((datetree-date (or (org-entry-get nil "TIMESTAMP" t)
+                            (org-read-date t nil "now")))
+         (date (org-date-to-gregorian datetree-date))
+         )
+    (save-excursion
+      (with-current-buffer (current-buffer)
+        (org-cut-subtree)
+        (if file (find-file file))
+	(widen)
+        (org-datetree-find-date-create date)
+        (org-narrow-to-subtree)
+        (show-subtree)
+        (org-end-of-subtree t)
+        (newline)
+        (goto-char (point-max))
+        (org-paste-subtree (+ org-datetree-base-level 3))
+        (widen)
+        ))))
+
+(provide 'fcuny-org-custom)