From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christoph LANGE Subject: Function that splits a CLOCK interval Date: Tue, 31 Mar 2015 18:59:55 +0200 Message-ID: <551AD28B.2060405@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:60694) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YczWE-0007yR-JZ for emacs-orgmode@gnu.org; Tue, 31 Mar 2015 13:00:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YczWB-0005TY-D3 for emacs-orgmode@gnu.org; Tue, 31 Mar 2015 13:00:02 -0400 Received: from mail-wi0-x232.google.com ([2a00:1450:400c:c05::232]:38676) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YczWB-0005TS-2u for emacs-orgmode@gnu.org; Tue, 31 Mar 2015 12:59:59 -0400 Received: by wibgn9 with SMTP id gn9so34179896wib.1 for ; Tue, 31 Mar 2015 09:59:58 -0700 (PDT) Received: from [10.144.103.67] (hades-dfn.bi.fraunhofer.de. [192.76.241.15]) by mx.google.com with ESMTPSA id pa4sm21146760wjb.11.2015.03.31.09.59.57 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 31 Mar 2015 09:59:57 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: "emacs-orgmode@gnu.org" Dear org-mode community, I use org's clocking facility to clock all my working time. I frequently find myself clocking time for a task T1, but later realise that I actually spent part of this time on some other task T2. In such a situation I go to the corresponding CLOCK: line for T1, split the interval clocked, e.g. from CLOCK: [2015-03-30 Mon 16:27]--[2015-03-30 Mon 16:30] => 0:03 to CLOCK: [2015-03-30 Mon 16:28]--[2015-03-30 Mon 16:30] => 0:02 CLOCK: [2015-03-30 Mon 16:27]--[2015-03-30 Mon 16:28] => 0:01 and move one of the two lines to the LOGBOOK of task T2. The following function now automates the task of splitting: --- %< --- %< --- %< --- %< --- %< --- %< --- %< --- %< --- %< --- %< --- (defun org-clock-split-current-interval () "If this is a CLOCK line, split its clock time interval into two. t the current time interval be A--C; then this function interactively prompts for a time B (suggesting A as a default), and then replaces A--C by B--C and A--B. The point is left on the line B--C, so that this line can, e.g., be moved to another entry." (interactive) (save-excursion ;; Part of the following code is copied from org-clock-update-time-maybe. ;; If this function becomes part of org-clock.el, some refactoring would be in order. (beginning-of-line 1) (skip-chars-forward " \t") (when (looking-at org-clock-string) (let ((re (concat "[ \t]*" org-clock-string " *[[<][^]>]+[]>]-+[[<][^]>]+[]>]" "\\(?:[ \t]*=>.*\\)?"))) (when (looking-at re) ;; duplicate current line (resulting in A--C newline A--C) (let ((current-line (thing-at-point 'line t))) (when (or (= 1 (forward-line 1)) (eq (point) (point-max))) (insert "\n")) (insert current-line)) ;; interactively change start time of the later interval ;; (resulting in B--C newline A--C) ;; TODO when universal-argument is provided, we might alternatively offer changing the end time of the earlier interval, resulting in A--C newline A--B. (forward-line -2) ;; we currently assume that all timestamps in clock intervals are inactive (search-forward (concat org-clock-string " [")) ;; TODO call org-time-stamp with arguments that are conditional on whether an active or an inactive timestamp was found above (call-interactively 'org-time-stamp-inactive) ;; If there were a function that implemented the actual body of org-clock-update-time-maybe, we could call that function, as in this context we _know_ that we are on a CLOCK line. (org-clock-update-time-maybe) ;; copy changed time and also make it the end time of the earlier interval ;; (resulting in B--C newline A--B) (re-search-backward org-ts-regexp-both) (let ((ts (match-string 0))) (move-end-of-line 2) (when (re-search-backward org-ts-regexp-both nil t) (replace-match ts)) (org-clock-update-time-maybe))))))) (define-key org-mode-map (kbd "\C-cs") 'org-clock-split-current-interval) --- %< --- %< --- %< --- %< --- %< --- %< --- %< --- %< --- %< --- %< --- As I said in my previous email: I would even be happy to contribute it to the codebase of org-mode (core or contrib); however in this case someone would have to point me to a fool-proof guide for how to do this. I know that for contributing code I will have to sign some FSF copyright forms, and I know how to use git, but I don't know the exact org-mode specific steps of doing so. Cheers, Christoph -- Dr. Christoph Lange, Enterprise Information Systems Department Applied Computer Science @ University of Bonn; Fraunhofer IAIS http://langec.wordpress.com/about, Skype duke4701 → Semantic Publishing Challenge: Assessing the Quality of Scientific Output ESWC, 31 May–4 June 2014, Portorož, Slovenia. https://tinyurl.com/SPChallenge15 Submission deadline 27 March (abstracts: 20 March)