From mboxrd@z Thu Jan 1 00:00:00 1970 From: Benjamin Andresen Subject: RFC: sort subtree by most recently clocked in and most time spend on Date: Mon, 23 Nov 2009 13:38:16 +0100 Message-ID: <87k4xhh0w7.fsf@in-ulm.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NCYBg-0007i1-AG for emacs-orgmode@gnu.org; Mon, 23 Nov 2009 07:38:36 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NCYBa-0007hT-EJ for emacs-orgmode@gnu.org; Mon, 23 Nov 2009 07:38:34 -0500 Received: from [199.232.76.173] (port=49471 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NCYBa-0007hO-4k for emacs-orgmode@gnu.org; Mon, 23 Nov 2009 07:38:30 -0500 Received: from mail.in-ulm.de ([217.10.8.10]:36687) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1NCYBZ-0000A1-3R for emacs-orgmode@gnu.org; Mon, 23 Nov 2009 07:38:29 -0500 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org 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