diff options
author | Kyle Meyer <kyle@kyleam.com> | 2015-06-22 22:30:13 -0400 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2015-06-22 22:30:13 -0400 |
commit | 463b249419c79a14d897cc962128ba6c805d7d07 (patch) | |
tree | 8ace859c4519dabe8c1d36bd3d94734b2c687e53 /lisp | |
parent | 0071e4d558625cbe0a4d581e9e017039e563236f (diff) | |
download | emacs.d-463b249419c79a14d897cc962128ba6c805d7d07.tar.gz |
Rewrite org-clone-and-shift-by-repeater
As of Org mode commit 329683861cc85aa,
org-clone-subtree-with-time-shift accepts a value of 0, which allows a
repeating subtree to be replaced with a non-repeating subtree and a
shifted, repeating subtree.
Rewrite org-clone-and-shift-by-repeater to use the new
org-clone-subtree-with-time-shift. As an added bonus, this means that
org-clone-and-shift-by-repeater now supports scheduled items and time
stamps, not just deadlines
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/init-org.el | 41 |
1 files changed, 9 insertions, 32 deletions
diff --git a/lisp/init-org.el b/lisp/init-org.el index 2eb4995..f60c68e 100644 --- a/lisp/init-org.el +++ b/lisp/init-org.el @@ -84,38 +84,15 @@ The repeater is removed from the original subtree." (interactive) (save-excursion (org-back-to-heading) - (let* ((heading (org-element-at-point)) - (tree-begin (org-element-property :begin heading)) - (tree-end (org-element-property :end heading)) - (tree (buffer-substring tree-begin tree-end)) - (deadline (org-element-property :deadline heading)) - (deadline-end (org-element-property :end deadline)) - (repeat-val (org-element-property :repeater-value deadline)) - (repeat-unit (org-element-property :repeater-unit deadline)) - new-tree) - (cond - ((not deadline) (user-error "Heading doesn't have deadline")) - ((not repeat-val) (user-error "Deadline isn't repeating")) - ((eq repeat-unit 'week) - ;; `org-timestamp-change' doesn't recognize weeks. - (setq repeat-val (* repeat-val 7) - repeat-unit 'day))) - ;; Make new tree with repeater shifted one cycle. - (with-temp-buffer - (insert tree) - (goto-char (point-min)) - (re-search-forward org-ts-regexp) - (org-timestamp-change repeat-val repeat-unit) - (setq new-tree (buffer-string))) - ;; Insert new tree with shifted repeater. - (goto-char tree-end) - (insert new-tree) - ;; Remove the repeater from the original tree. - (goto-char tree-begin) - (re-search-forward - ;; Regexp taken from `org-clone-subtree-with-time-shift'. - "<[^<>\n]+\\( +[.+]?\\+[0-9]+[hdwmy]\\)" deadline-end) - (delete-region (match-beginning 1) (match-end 1))))) + (let ((repeater + (and (re-search-forward + ;; Regexp taken from `org-clone-subtree-with-time-shift'. + "<[^<>\n]+ +\\([.+]?\\+[0-9]+[hdwmy]\\)" + (save-excursion (org-end-of-subtree)) t) + (match-string-no-properties 1)))) + (unless repeater + (user-error "Subtree does not have repeater")) + (org-clone-subtree-with-time-shift 0 repeater)))) (defun km/org-delete-checked-items () "Delete checked items. |