diff options
author | Bastien Guerry <bzg@altern.org> | 2011-07-09 15:20:31 +0200 |
---|---|---|
committer | Bastien Guerry <bzg@altern.org> | 2011-07-09 15:20:31 +0200 |
commit | 65b64bea53e73ea73a4b791a1057b074db144b23 (patch) | |
tree | 272ace2df4f08135aa94d56afc5514b2d080839a | |
parent | 516b2fbb8763788585ac6a9f60ad7d51c4b0aab3 (diff) | |
download | org-mode-65b64bea53e73ea73a4b791a1057b074db144b23.tar.gz |
org-clock.el: new hook to remove empty clock drawer.
* org-clock.el (org-clock-remove-empty-clock-drawer): New
function to remove empty clock drawer.
(org-clock-out-hook): Add the new function as a hook.
-rw-r--r-- | lisp/org-clock.el | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lisp/org-clock.el b/lisp/org-clock.el index 8679c89..f1eb673 100644 --- a/lisp/org-clock.el +++ b/lisp/org-clock.el @@ -1389,6 +1389,22 @@ If there is no running clock, throw an error, unless FAIL-QUIETLY is set." (run-hooks 'org-clock-out-hook) (org-clock-delete-current)))))) +(add-hook 'org-clock-out-hook 'org-clock-remove-empty-clock-drawer) + +(defun org-clock-remove-empty-clock-drawer nil + "Remove empty clock drawer in the current subtree." + (let* ((olid (or (org-entry-get (point) "LOG_INTO_DRAWER") + org-log-into-drawer)) + (clock-drawer (if (eq t olid) "LOGBOOK" olid)) + (end (save-excursion (org-end-of-subtree t t)))) + (when clock-drawer + (save-excursion + (org-back-to-heading t) + (while (search-forward clock-drawer end t) + (goto-char (match-beginning 0)) + (org-remove-empty-drawer-at clock-drawer (point)) + (forward-line 1)))))) + (defun org-clock-cancel () "Cancel the running clock by removing the start timestamp." (interactive) |