From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christoph LANGE Subject: Re: Function that splits a CLOCK interval Date: Tue, 07 Apr 2015 18:07:37 +0200 Message-ID: <552400C9.608@gmail.com> References: <551AD28B.2060405@gmail.com> <2A9C3F90-716A-4B98-AD54-B935BB562685@agfa.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]:54427) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YfW2W-0005qn-E5 for emacs-orgmode@gnu.org; Tue, 07 Apr 2015 12:07:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YfW2R-00054S-82 for emacs-orgmode@gnu.org; Tue, 07 Apr 2015 12:07:48 -0400 Received: from mail-wi0-x233.google.com ([2a00:1450:400c:c05::233]:38521) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YfW2Q-00054H-Ud for emacs-orgmode@gnu.org; Tue, 07 Apr 2015 12:07:43 -0400 Received: by wiun10 with SMTP id n10so24800396wiu.1 for ; Tue, 07 Apr 2015 09:07:41 -0700 (PDT) In-Reply-To: <2A9C3F90-716A-4B98-AD54-B935BB562685@agfa.com> 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: Peter Frings Cc: "emacs-orgmode@gnu.org" Hi Peter, Peter Frings on 2015-04-01 12:37: >> The following function now automates the task of splitting: >> … > > Fantastic, just what I needed! thanks for your feedback! I have now made a few improvements but not yet found time to get started with contributing the code to Worg, so one more email with the improvements. > One little thing, though. When I interrupt the function with C-g at the prompt, the current line is already duplicated. It would by nice that C-g left the buffer unchanged. Done, see code below. Plus, the function now accepts a prefix argument and works with active time stamps. When a prefix argument is given, the interactive editing of the timestamp uses C as a default before changing A--C into A--B B--C. Cheers, Christoph --- %< --- %< --- %< --- %< --- %< --- %< --- %< --- %< --- %< --- %< --- (defun org-clock-split-current-interval (end-as-default) "If this is a CLOCK line, split its clock time interval into two. Let the current time interval be A--C. By default, this function interactively prompts for a time B (suggesting A as a default), and then replaces A--C by B--C and A--B. When called with a prefix argument, the function uses C as a default for B. The point is left on the later interval, so that this line can, e.g., be moved to another entry." (interactive "P") (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 nil) (skip-chars-forward " \t") (when (looking-at org-clock-string) (beginning-of-line nil) (let ((re (concat "\\([ \t]*" org-clock-string " *\\)" "\\([[<][^]>]+[]>]\\)\\(-+\\)\\([[<][^]>]+[]>]\\)" "\\(?:[ \t]*=>.*\\)?"))) (when (looking-at re) (let ((indentation (match-string 1)) (start (match-string 2)) (to (match-string 3)) (end (match-string 4)) (use-start-as-default (equal end-as-default nil))) ;; interactively change A--C to B--C, ;; or (given prefix argument) to A--B, … (re-search-forward (concat org-clock-string " \\([[<]\\)")) (when (not use-start-as-default) (re-search-forward "\\([[<]\\)")) ;; … respecting whether A or C is an active or an inactive timestamp (call-interactively (if (equal (match-string 1) "<") 'org-time-stamp '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 B (re-search-backward org-ts-regexp-both) (let ((middle (match-string 0))) ;; insert A--B below, or (given prefix argument) insert B--C above (end-of-line (if use-start-as-default 1 0)) (insert "\n" indentation (if use-start-as-default start middle) to (if use-start-as-default middle end)) (org-clock-update-time-maybe)))))))) -- 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)