Browse Source

Allow date to be shifted into the future if time is earlier than now

PT writes:

> Currently, I'm using Google Calendar and it's quick add syntax is very
> convenient:
>
> http://www.google.com/support/calendar/bin/answer.py?hl=en&answer=36604#text
>
>
> Of course, Org has similar capabilites, but I found one thing which
> google calendar does better: if it's 4pm and I add an event for 8am
> then GCal schedules it for 8am tomorrow.
>
> Org, on the the other hand, schedules it for 8am today even if that
> time is already passed.
>
> I never add past events and I think it's quite atypical. Shouldn't be
> an option similar to org-read-date-prefer-future for times too, so
> that timestamps also prefer the future when no date given?

This is now possible, but it is not the default.  You need to set

(setq org-read-date-prefer-future 'time)
Carsten Dominik 15 years ago
parent
commit
0b8457c835
3 changed files with 51 additions and 13 deletions
  1. 4 1
      doc/org.texi
  2. 6 0
      lisp/ChangeLog
  3. 41 12
      lisp/org.el

+ 4 - 1
doc/org.texi

@@ -5019,7 +5019,10 @@ range, it is taken from the stamp in the buffer.  When filling in
 information, Org mode assumes that most of the time you will want to enter a
 information, Org mode assumes that most of the time you will want to enter a
 date in the future: if you omit the month/year and the given day/month is
 date in the future: if you omit the month/year and the given day/month is
 @i{before} today, it will assume that you mean a future date@footnote{See the
 @i{before} today, it will assume that you mean a future date@footnote{See the
-variable @code{org-read-date-prefer-future}.}.
+variable @code{org-read-date-prefer-future}.  You may set that variable to
+the symbol @code{time} to even make a time before now shift the date to
+tomorrow.}.  If the date has been automatically shifted into the future, the
+time prompt will show this with @samp{(=>F).}
 
 
 For example, let's assume that today is @b{June 13, 2006}.  Here is how
 For example, let's assume that today is @b{June 13, 2006}.  Here is how
 various inputs will be interpreted, the items filled in by Org mode are
 various inputs will be interpreted, the items filled in by Org mode are

+ 6 - 0
lisp/ChangeLog

@@ -1,3 +1,9 @@
+2009-10-01  Carsten Dominik  <carsten.dominik@gmail.com>
+
+	* org.el (org-read-date-prefer-future): New allowed value `time'.
+	(org-read-date-analyze): Shift day to tomorrow depending on time
+	entered and value of `org-read-date-prefer-future'.
+
 2009-09-30  Carsten Dominik  <carsten.dominik@gmail.com>
 2009-09-30  Carsten Dominik  <carsten.dominik@gmail.com>
 
 
 	* org.el (org-set-tags-to): New command.
 	* org.el (org-set-tags-to): New command.

+ 41 - 12
lisp/org.el

@@ -2188,20 +2188,29 @@ Custom commands can set this variable in the options section."
 (defcustom org-read-date-prefer-future t
 (defcustom org-read-date-prefer-future t
   "Non-nil means, assume future for incomplete date input from user.
   "Non-nil means, assume future for incomplete date input from user.
 This affects the following situations:
 This affects the following situations:
-1. The user gives a day, but no month.
+1. The user gives a month but not a year.
+   For example, if it is april and you enter \"feb 2\", this will be read
+   as feb 2, *next* year.  \"May 5\", however, will be this year.
+2. The user gives a day, but no month.
    For example, if today is the 15th, and you enter \"3\", Org-mode will
    For example, if today is the 15th, and you enter \"3\", Org-mode will
    read this as the third of *next* month.  However, if you enter \"17\",
    read this as the third of *next* month.  However, if you enter \"17\",
    it will be considered as *this* month.
    it will be considered as *this* month.
-2. The user gives a month but not a year.
-   For example, if it is april and you enter \"feb 2\", this will be read
-   as feb 2, *next* year.  \"May 5\", however, will be this year.
 
 
-Currently this does not work for ISO week specifications.
+If you set this variable to the symbol `time', then also the following
+will work:
+
+3. If the user gives a time, but no day.  If the time is before now,
+   to will be interpreted as tomorrow.
+
+Currently none of this works for ISO week specifications.
 
 
-When this option is nil, the current month and year will always be used
-as defaults."
+When this option is nil, the current day, month and year will always be
+used as defaults."
   :group 'org-time
   :group 'org-time
-  :type 'boolean)
+  :type '(choice
+	  (const :tag "Never" nil)
+	  (const :tag "Check month and day" t)
+	  (const :tag "Check month, day, and time" time)))
 
 
 (defcustom org-read-date-display-live t
 (defcustom org-read-date-display-live t
   "Non-nil means, display current interpretation of date prompt live.
   "Non-nil means, display current interpretation of date prompt live.
@@ -12702,6 +12711,7 @@ user."
 (defvar def)
 (defvar def)
 (defvar defdecode)
 (defvar defdecode)
 (defvar with-time)
 (defvar with-time)
+(defvar org-read-date-analyze-futurep nil)
 (defun org-read-date-display ()
 (defun org-read-date-display ()
   "Display the current date prompt interpretation in the minibuffer."
   "Display the current date prompt interpretation in the minibuffer."
   (when org-read-date-display-live
   (when org-read-date-display-live
@@ -12731,6 +12741,8 @@ user."
 	(setq txt (concat (substring txt 0 (match-end 0)) "-"
 	(setq txt (concat (substring txt 0 (match-end 0)) "-"
 			  org-end-time-was-given
 			  org-end-time-was-given
 			  (substring txt (match-end 0)))))
 			  (substring txt (match-end 0)))))
+      (when org-read-date-analyze-futurep
+	(setq txt (concat txt " (=>F)")))
       (setq org-read-date-overlay
       (setq org-read-date-overlay
 	    (org-make-overlay (1- (point-at-eol)) (point-at-eol)))
 	    (org-make-overlay (1- (point-at-eol)) (point-at-eol)))
       (org-overlay-display org-read-date-overlay txt 'secondary-selection))))
       (org-overlay-display org-read-date-overlay txt 'secondary-selection))))
@@ -12740,8 +12752,8 @@ user."
   ;; FIXME: cleanup and comment
   ;; FIXME: cleanup and comment
   (let (delta deltan deltaw deltadef year month day
   (let (delta deltan deltaw deltadef year month day
 	      hour minute second wday pm h2 m2 tl wday1
 	      hour minute second wday pm h2 m2 tl wday1
-	      iso-year iso-weekday iso-week iso-year iso-date)
-
+	      iso-year iso-weekday iso-week iso-year iso-date futurep)
+    (setq org-read-date-analyze-futurep nil)
     (when (string-match "\\`[ \t]*\\.[ \t]*\\'" ans)
     (when (string-match "\\`[ \t]*\\.[ \t]*\\'" ans)
       (setq ans "+0"))
       (setq ans "+0"))
 
 
@@ -12814,22 +12826,36 @@ user."
 	  month (or (nth 4 tl)
 	  month (or (nth 4 tl)
 		    (if (and org-read-date-prefer-future
 		    (if (and org-read-date-prefer-future
 			     (nth 3 tl) (< (nth 3 tl) (nth 3 defdecode)))
 			     (nth 3 tl) (< (nth 3 tl) (nth 3 defdecode)))
-			(1+ (nth 4 defdecode))
+			(prog (1+ (nth 4 defdecode)) (setq futurep t))
 		      (nth 4 defdecode)))
 		      (nth 4 defdecode)))
 	  year (or (nth 5 tl)
 	  year (or (nth 5 tl)
 		   (if (and org-read-date-prefer-future
 		   (if (and org-read-date-prefer-future
 			    (nth 4 tl) (< (nth 4 tl) (nth 4 defdecode)))
 			    (nth 4 tl) (< (nth 4 tl) (nth 4 defdecode)))
-		       (1+ (nth 5 defdecode))
+		       (prog1 (1+ (nth 5 defdecode)) (setq futurep t))
 		     (nth 5 defdecode)))
 		     (nth 5 defdecode)))
 	  hour (or (nth 2 tl) (nth 2 defdecode))
 	  hour (or (nth 2 tl) (nth 2 defdecode))
 	  minute (or (nth 1 tl) (nth 1 defdecode))
 	  minute (or (nth 1 tl) (nth 1 defdecode))
 	  second (or (nth 0 tl) 0)
 	  second (or (nth 0 tl) 0)
 	  wday (nth 6 tl))
 	  wday (nth 6 tl))
 
 
+    (when (and (eq org-read-date-prefer-future 'time)
+	       (not (nth 3 tl)) (not (nth 4 tl)) (not (nth 5 tl))
+	       (equal day (nth 3 defdecode))
+	       (equal month (nth 4 defdecode))
+	       (equal year (nth 5 defdecode))
+	       (nth 2 tl)
+	       (or (< (nth 2 tl) (nth 2 defdecode))
+		   (and (= (nth 2 tl) (nth 2 defdecode))
+			(nth 1 tl)
+			(< (nth 1 tl) (nth 1 defdecode)))))
+      (setq day (1+ day)
+	    futurep t))
+
     ;; Special date definitions below
     ;; Special date definitions below
     (cond
     (cond
      (iso-week
      (iso-week
       ;; There was an iso week
       ;; There was an iso week
+      (setq futurep nil)
       (setq year (or iso-year year)
       (setq year (or iso-year year)
 	    day (or iso-weekday wday 1)
 	    day (or iso-weekday wday 1)
 	    wday nil ; to make sure that the trigger below does not match
 	    wday nil ; to make sure that the trigger below does not match
@@ -12849,6 +12875,7 @@ user."
 	    year (nth 2 iso-date)
 	    year (nth 2 iso-date)
 	    day (nth 1 iso-date)))
 	    day (nth 1 iso-date)))
      (deltan
      (deltan
+      (setq futurep nil)
       (unless deltadef
       (unless deltadef
 	(let ((now (decode-time (current-time))))
 	(let ((now (decode-time (current-time))))
 	  (setq day (nth 3 now) month (nth 4 now) year (nth 5 now))))
 	  (setq day (nth 3 now) month (nth 4 now) year (nth 5 now))))
@@ -12857,6 +12884,7 @@ user."
 	    ((equal deltaw "m") (setq month (+ month deltan)))
 	    ((equal deltaw "m") (setq month (+ month deltan)))
 	    ((equal deltaw "y") (setq year (+ year deltan)))))
 	    ((equal deltaw "y") (setq year (+ year deltan)))))
      ((and wday (not (nth 3 tl)))
      ((and wday (not (nth 3 tl)))
+      (setq futurep nil)
       ;; Weekday was given, but no day, so pick that day in the week
       ;; Weekday was given, but no day, so pick that day in the week
       ;; on or after the derived date.
       ;; on or after the derived date.
       (setq wday1 (nth 6 (decode-time (encode-time 0 0 0 day month year))))
       (setq wday1 (nth 6 (decode-time (encode-time 0 0 0 day month year))))
@@ -12867,6 +12895,7 @@ user."
 	(setq org-time-was-given t))
 	(setq org-time-was-given t))
     (if (< year 100) (setq year (+ 2000 year)))
     (if (< year 100) (setq year (+ 2000 year)))
     (if (< year 1970) (setq year (nth 5 defdecode))) ; not representable
     (if (< year 1970) (setq year (nth 5 defdecode))) ; not representable
+    (setq org-read-date-analyze-futurep futurep)
     (list second minute hour day month year)))
     (list second minute hour day month year)))
 
 
 (defvar parse-time-weekdays)
 (defvar parse-time-weekdays)