From: Christoph LANGE <math.semantic.web@gmail.com>
To: Peter Frings <peter.frings@agfa.com>
Cc: "emacs-orgmode@gnu.org" <emacs-orgmode@gnu.org>
Subject: Re: Function that splits a CLOCK interval
Date: Tue, 07 Apr 2015 18:07:37 +0200 [thread overview]
Message-ID: <552400C9.608@gmail.com> (raw)
In-Reply-To: <2A9C3F90-716A-4B98-AD54-B935BB562685@agfa.com>
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)
next prev parent reply other threads:[~2015-04-07 16:07 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-31 16:59 Function that splits a CLOCK interval Christoph LANGE
2015-04-01 10:37 ` Peter Frings
2015-04-07 16:07 ` Christoph LANGE [this message]
2015-04-08 3:50 ` Xavier Maillard
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=552400C9.608@gmail.com \
--to=math.semantic.web@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=peter.frings@agfa.com \
/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).