From: Benjamin Andresen <benny@in-ulm.de>
To: emacs-orgmode@gnu.org
Subject: RFC: sort subtree by most recently clocked in and most time spend on
Date: Mon, 23 Nov 2009 13:38:16 +0100 [thread overview]
Message-ID: <87k4xhh0w7.fsf@in-ulm.de> (raw)
Hey there,
I wrote a bit of code to do the things in the subject.
I'm interested if someone has a better way to deal with the subtree
copying thing I'm doing. I'm not really happy with using the kill-ring
like that.
`org-narrow-subtree' won't work, because `save-excursion' doesn't revert
it to the previous state and the org-sort already uses it.
Thanks in advance for looking over it!
(defun ba/org-heading-clock-times ()
"Return alist of clocktimes from current heading."
(let* ((re (concat "^\\(\\*+\\)[ \t]\\|^[ \t]*"
org-clock-string
"[ \t]*\\(?:\\(\\[.*?\\]\\)-+\\(\\[.*?\\]\\)\\|=>[ \t]+\\([0-9]+\\):\\([0-9]+\\)\\)"))
t1 ts te tsf tef dt
results)
(save-excursion
;; shut up about copying
(flet ((message (&rest ignored) nil))
(org-copy-subtree))
(with-temp-buffer
(yank)
(while (re-search-backward re nil t)
(when (match-end 2)
;; Two time stamps
(setq ts (match-string-no-properties 2)
te (match-string-no-properties 3)
tsf (org-float-time (apply 'encode-time (org-parse-time-string ts)))
tef (org-float-time (apply 'encode-time (org-parse-time-string te)))
dt (- tef tsf)
t1 (floor (/ dt 60)))
(add-to-list 'results `(,ts . ,t1))))))
results))
(defun ba/org-sort-most-time-spend ()
(let ((org-ts-w/mins (ba/org-heading-clock-times)))
(- (apply '+ (mapcar '(lambda (a)
(cdr a))
org-ts-w/mins)))))
(defun ba/org-sort-most-recently-clocked ()
(let ((org-ts-w/mins (ba/org-heading-clock-times)))
(if (not org-ts-w/mins)
(org-float-time)
(- (org-float-time)
(org-float-time (apply 'encode-time
(org-parse-time-string (caar org-ts-w/mins))))))))
br,
benny
reply other threads:[~2009-11-23 12:38 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87k4xhh0w7.fsf@in-ulm.de \
--to=benny@in-ulm.de \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).