Sebastien Vauban <sva-news-D0wtAvR13HarG/idocf...@public.gmane.org>
writes:

> I still consider the default behavior as dangerous -- because the novice
> is not aware (except if obvious) that some clock times may be dropped in
> the computation, and I find that scary --, but thanks anyway for the
> workaround.

Would you mind testing the following patch, then? `untilnow' is just
a suggestion.

Regards,

>From eec96edbc27a56159642f939a9ccd0e56e348a58 Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <m...@nicolasgoaziou.fr>
Date: Fri, 20 Feb 2015 11:35:16 +0100
Subject: [PATCH] org-clock: Add `untilnow' time block
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* lisp/org-clock.el (org-clock-special-range): Handle `untilnow'
  range.
(org-clock-display-default-range): Add `untilnow' as valid range.

* doc/org.texi (The clock table): Document `untilnow'

Suggested-by: Sébastien Vauban
---
 doc/org.texi      |  1 +
 lisp/org-clock.el | 33 +++++++++++++++++++++------------
 2 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/doc/org.texi b/doc/org.texi
index bec46a9..ba553e2 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -6572,6 +6572,7 @@ be selected:
              thisweek, lastweek, thisweek-@var{N}     @r{a relative week}
              thismonth, lastmonth, thismonth-@var{N}  @r{a relative month}
              thisyear, lastyear, thisyear-@var{N}     @r{a relative year}
+             untilnow
              @r{Use @kbd{S-@key{left}/@key{right}} keys to shift the time interval.}
 :tstart      @r{A time string specifying when to start considering times.}
              @r{Relative times like @code{"<-2w>"} can also be used.  See}
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 07f02b0..f6cc766 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -440,6 +440,7 @@ This applies when using `org-clock-goto'."
 		 (const lastmonth)
 		 (const thisyear)
 		 (const lastyear)
+		 (const untilnow)
 		 (const :tag "Select range interactively" interactive)))
 
 (defvar org-clock-in-prepare-hook nil
@@ -2087,18 +2088,24 @@ buffer and update it."
 
 (defun org-clock-special-range (key &optional time as-strings wstart mstart)
   "Return two times bordering a special time range.
-Key is a symbol specifying the range and can be one of `today', `yesterday',
-`thisweek', `lastweek', `thismonth', `lastmonth', `thisyear', `lastyear'.
-By default, a week starts Monday 0:00 and ends Sunday 24:00.
-The range is determined relative to TIME, which defaults to current time.
-The return value is a cons cell with two internal times like the ones
-returned by `current time' or `encode-time'.
-If AS-STRINGS is non-nil, the returned times will be formatted strings.
-If WSTART is non-nil, use this number to specify the starting day of a
-week (monday is 1).
-If MSTART is non-nil, use this number to specify the starting day of a
-month (1 is the first day of the month).
-If you can combine both, the month starting day will have priority."
+
+KEY is a symbol specifying the range and can be one of `today',
+`yesterday', `thisweek', `lastweek', `thismonth', `lastmonth',
+`thisyear', `lastyear' or `untilnow'.
+
+By default, a week starts Monday 0:00 and ends Sunday 24:00.  The
+range is determined relative to TIME, which defaults to current
+time.
+
+The return value is a cons cell with two internal times like the
+ones returned by `current time' or `encode-time'.  If AS-STRINGS
+is non-nil, the returned times will be formatted strings.
+
+If WSTART is non-nil, use this number to specify the starting day
+of a week (monday is 1).  If MSTART is non-nil, use this number
+to specify the starting day of a month (1 is the first day of the
+month).  If you can combine both, the month starting day will
+have priority."
   (if (integerp key) (setq key (intern (number-to-string key))))
   (let* ((tm (decode-time (or time (current-time))))
 	 (s 0) (m (nth 1 tm)) (h (nth 2 tm))
@@ -2190,6 +2197,7 @@ If you can combine both, the month starting day will have priority."
 	      month1 (+ 4 (* 3 (- (+ q shift) 1))) h1 0 m1 0))))
      ((memq key '(year thisyear))
       (setq m 0 h 0 d 1 month 1 y (+ y shift) y1 (1+ y)))
+     ((eq key 'untilnow) (setq y1 y month1 m d1 d m 0 h 0 d 1 month 1 y 1))
      ((eq key 'interactive) nil)
      (t (user-error "No such time block %s" key)))
     (setq ts (encode-time s m h d month y)
@@ -2205,6 +2213,7 @@ If you can combine both, the month starting day will have priority."
       (setq txt (format-time-string "%B %Y" ts)))
      ((memq key '(year thisyear))
       (setq txt (format-time-string "the year %Y" ts)))
+     ((eq key 'untilnow) (setq txt "now"))
      ((memq key '(quarter thisq))
       (setq txt (concat (org-count-quarter shiftedq)
 			" quarter of " (number-to-string shiftedy)))))
-- 
2.3.0

Reply via email to