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)