emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-timestamp-up/down broken in tip
@ 2011-07-22  0:20 Max Mikhanosha
  2011-07-22  6:55 ` Sebastien Vauban
  2011-07-22  7:27 ` Bastien
  0 siblings, 2 replies; 10+ messages in thread
From: Max Mikhanosha @ 2011-07-22  0:20 UTC (permalink / raw)
  To: Org Mode List

With latest git I can only press S-up or S-down on the time part of
the timestamp once, after changing the time it moves point to the
closing bracket, and doing another S-up or S-down changes the date
part instead of time.

Example: with point on the "05" at the timestamp [2011-07-21 Thu
19:05] doing Shift-Up results in time correctly changed to 19:10, but
point moves to the closing bracket. Next time you press S-Up it
changes date, not time.

Reverting following commit fixes the problem for me:

commit fd0f8e10d1d3a339da9460d6c71283e85897c455
Author: Nicolas Goaziou <n.goaziou@gmail.com>
Date:   Thu Jul 21 11:48:35 2011 +0200

    Fix bug with TODO states changes modifying scheduling of next headline
    
    * lisp/org.el (org-timestamp-change): some locales don't use the same
      length for date abbreviations. Set a marker at origin in case length
      of new timestamp is different.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: org-timestamp-up/down broken in tip
  2011-07-22  0:20 org-timestamp-up/down broken in tip Max Mikhanosha
@ 2011-07-22  6:55 ` Sebastien Vauban
  2011-07-22  7:17   ` Bastien
  2011-07-22  7:27 ` Bastien
  1 sibling, 1 reply; 10+ messages in thread
From: Sebastien Vauban @ 2011-07-22  6:55 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi Max,

Max Mikhanosha wrote:
> With latest git I can only press S-up or S-down on the time part of
> the timestamp once, after changing the time it moves point to the
> closing bracket, and doing another S-up or S-down changes the date
> part instead of time.
>
> Example: with point on the "05" at the timestamp [2011-07-21 Thu
> 19:05] doing Shift-Up results in time correctly changed to 19:10, but
> point moves to the closing bracket. Next time you press S-Up it
> changes date, not time.
>
> Reverting following commit fixes the problem for me:
>
> commit fd0f8e10d1d3a339da9460d6c71283e85897c455
> Author: Nicolas Goaziou <n.goaziou-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> Date:   Thu Jul 21 11:48:35 2011 +0200
>
>     Fix bug with TODO states changes modifying scheduling of next headline
>     
>     * lisp/org.el (org-timestamp-change): some locales don't use the same
>       length for date abbreviations. Set a marker at origin in case length
>       of new timestamp is different.

I don't know which commit broke it, but I confirm the symptom you've spotted.

Best regards,
  Seb

-- 
Sebastien Vauban

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: org-timestamp-up/down broken in tip
  2011-07-22  6:55 ` Sebastien Vauban
@ 2011-07-22  7:17   ` Bastien
  0 siblings, 0 replies; 10+ messages in thread
From: Bastien @ 2011-07-22  7:17 UTC (permalink / raw)
  To: Sebastien Vauban; +Cc: emacs-orgmode

"Sebastien Vauban" <wxhgmqzgwmuf@spammotel.com> writes:

> I don't know which commit broke it, but I confirm the symptom you've
> spotted.

I do as well -- I'm on it. :)

-- 
 Bastien

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: org-timestamp-up/down broken in tip
  2011-07-22  0:20 org-timestamp-up/down broken in tip Max Mikhanosha
  2011-07-22  6:55 ` Sebastien Vauban
@ 2011-07-22  7:27 ` Bastien
  2011-07-22  7:53   ` Bastien
  1 sibling, 1 reply; 10+ messages in thread
From: Bastien @ 2011-07-22  7:27 UTC (permalink / raw)
  To: Max Mikhanosha; +Cc: Org Mode List

Hi Max,

thanks a lot for reporting this annoying problem and for finding 
the bad commit.

Max Mikhanosha <max@openchat.com> writes:

> Reverting following commit fixes the problem for me:
>
> commit fd0f8e10d1d3a339da9460d6c71283e85897c455
> Author: Nicolas Goaziou <n.goaziou@gmail.com>
> Date:   Thu Jul 21 11:48:35 2011 +0200
>
>     Fix bug with TODO states changes modifying scheduling of next
>     headline

I reverted this commit.

We need a better solution for the problem this commit was trying to
solve.  

Thanks,

-- 
 Bastien

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: org-timestamp-up/down broken in tip
  2011-07-22  7:27 ` Bastien
@ 2011-07-22  7:53   ` Bastien
  2011-07-22  8:47     ` Nicolas Goaziou
  0 siblings, 1 reply; 10+ messages in thread
From: Bastien @ 2011-07-22  7:53 UTC (permalink / raw)
  To: Max Mikhanosha; +Cc: Org Mode List

Bastien <bzg@altern.org> writes:

> I reverted this commit.
>
> We need a better solution for the problem this commit was trying to
> solve.  

I should add that I tested Nicolas' patch and it worked okay for me,
but I should have tested it better.  So, my bad on this one.

-- 
 Bastien

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: org-timestamp-up/down broken in tip
  2011-07-22  7:53   ` Bastien
@ 2011-07-22  8:47     ` Nicolas Goaziou
  2011-07-22 20:11       ` Nicolas Goaziou
  0 siblings, 1 reply; 10+ messages in thread
From: Nicolas Goaziou @ 2011-07-22  8:47 UTC (permalink / raw)
  To: Bastien; +Cc: Org Mode List

Hello,

Bastien <bzg@altern.org> writes:

> Bastien <bzg@altern.org> writes:
>
>> I reverted this commit.
>>
>> We need a better solution for the problem this commit was trying to
>> solve.  
>
> I should add that I tested Nicolas' patch and it worked okay for me,
> but I should have tested it better.  So, my bad on this one.

In fact, the problem is that when a time-stamp is changed, the old one
is completely deleted (which is logical). A marker is useless when text
is removed under it.

So, saving point, saving marker, or even saving a line-column
combination can't help here.

Now, the good news are that we can tell exactly in which part of the
time-stamp the point was before. A general solution would be to keep
point before the new time-stamp, look at it, and move to the right part.

A refinement could be to try to keep the same position within the
part. If point was at year, month, day (number), the column will be the
same because they all have fixed size. But if it was past there, we have
to check how far it was from the beginning of the part, and put it
there, unless this happens to be after the end of that part, in which
case, it will simply be put at the last position in it.

I can't work on it before a dozen of hours, though. I will do it then
unless someone wants to take care of it before.

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: org-timestamp-up/down broken in tip
  2011-07-22  8:47     ` Nicolas Goaziou
@ 2011-07-22 20:11       ` Nicolas Goaziou
  2011-07-24 19:10         ` Bastien
  0 siblings, 1 reply; 10+ messages in thread
From: Nicolas Goaziou @ 2011-07-22 20:11 UTC (permalink / raw)
  To: Bastien; +Cc: Org Mode List

[-- Attachment #1: Type: text/plain, Size: 105 bytes --]

Here is the second attempt to fix both that problem and the original
one.

Regards,

-- 
Nicolas Goaziou

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Keep-point-in-the-same-category-when-updating-a-time.patch --]
[-- Type: text/x-patch, Size: 3304 bytes --]

From f3af2f87996312a0975a5395bdbbc8feaab59641 Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <n.goaziou@gmail.com>
Date: Fri, 22 Jul 2011 22:05:44 +0200
Subject: [PATCH] Keep point in the same category when updating a time-stamp

* lisp/org.el (org-timestamp-change): keep point in the same category
  when updating a time-stamp. This requires to be careful, as,
  depending on the locale, name of day might change of length during
  the process.
---
 lisp/org.el |   33 ++++++++++++++++++++++++++++-----
 1 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 54f931a..815f016 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -15582,7 +15582,7 @@ With prefix ARG, change that many days."
 The date will be changed by N times WHAT.  WHAT can be `day', `month',
 `year', `minute', `second'.  If WHAT is not given, the cursor position
 in the timestamp determines what will be changed."
-  (let ((pos (point))
+  (let ((origin (point)) origin-cat
 	with-hm inactive
 	(dm (max (nth 1 org-time-stamp-rounding-minutes) 1))
 	org-ts-what
@@ -15592,6 +15592,10 @@ in the timestamp determines what will be changed."
 	(error "Not at a timestamp"))
     (if (and (not what) (eq org-ts-what 'bracket))
 	(org-toggle-timestamp-type)
+      ;; Point isn't on brackets.  Remember the part of the time-stamp
+      ;; the point was in.  Indeed, size of time-stamps may change,
+      ;; but point must be kept in the same category nonetheless.
+      (setq origin-cat org-ts-what)
       (if (and (not what) (not (eq org-ts-what 'day))
 	       org-display-custom-times
 	       (get-text-property (point) 'display)
@@ -15642,11 +15646,30 @@ in the timestamp determines what will be changed."
 	    (setcar (nthcdr 1 time0) (or (nth 1 time0) 0))
 	    (setcar (nthcdr 2 time0) (or (nth 2 time0) 0))
 	    (setq time (apply 'encode-time time0))))
-      (setq org-last-changed-timestamp
-	    (org-insert-time-stamp time with-hm inactive nil nil extra))
+      ;; Insert the new time-stamp, and ensure point stays in the same
+      ;; category as before (i.e. not after the last position in that
+      ;; category).
+      (let ((pos (point)))
+	;; Stay before inserted string. `save-excursion' is of no use.
+	(setq org-last-changed-timestamp
+	      (org-insert-time-stamp time with-hm inactive nil nil extra))
+	(goto-char pos))
+      (save-match-data
+	(looking-at org-ts-regexp3)
+	(goto-char (cond
+		    ;; `day' category ends before `hour' if any, or at
+		    ;; the end of the day name.
+		    ((eq origin-cat 'day)
+		     (min (or (match-beginning 7) (1- (match-end 5))) origin))
+		    ((eq origin-cat 'hour) (min (1- (match-end 7)) origin))
+		    ((eq origin-cat 'minute) (min (1- (match-end 8)) origin))
+		    ((integerp origin-cat) (min (1- (match-end 0)) origin))
+		    ;; `year' and `month' have both fixed size: point
+		    ;; couldn't have moved into another part.
+		    (t origin))))
+      ;; Update clock if on a CLOCK line.
       (org-clock-update-time-maybe)
-      (goto-char pos)
-      ;; Try to recenter the calendar window, if any
+      ;; Try to recenter the calendar window, if any.
       (if (and org-calendar-follow-timestamp-change
 	       (get-buffer-window "*Calendar*" t)
 	       (memq org-ts-what '(day month year)))
-- 
1.7.6


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: org-timestamp-up/down broken in tip
  2011-07-22 20:11       ` Nicolas Goaziou
@ 2011-07-24 19:10         ` Bastien
  2011-07-25 10:01           ` Nicolas Goaziou
  0 siblings, 1 reply; 10+ messages in thread
From: Bastien @ 2011-07-24 19:10 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Org Mode List

Nicolas Goaziou <n.goaziou@gmail.com> writes:

> Here is the second attempt to fix both that problem and the original
> one.

Thanks Nicolas -- I tested the patch more carefully and yes, it does
solve the problem at hand.  

One small weirdness:

      CLOCK: [2011-07-03 dim. 21:02]--[2011-07-13 mer. 21:03] => 240:01
                                ^
When point is at this position  |

S-<left> will move one character backward.

Can you see where does this come from?

Also, the solution looks really hackish...  a big hammer for such a 
small nail :/  Anyway.  Feel free to commit this when you want!

Thanks again,

-- 
 Bastien

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: org-timestamp-up/down broken in tip
  2011-07-24 19:10         ` Bastien
@ 2011-07-25 10:01           ` Nicolas Goaziou
  2011-07-25 13:57             ` Bastien
  0 siblings, 1 reply; 10+ messages in thread
From: Nicolas Goaziou @ 2011-07-25 10:01 UTC (permalink / raw)
  To: Bastien; +Cc: Org Mode List

Hello,

Bastien <bzg@altern.org> writes:

> One small weirdness:
>
>       CLOCK: [2011-07-03 dim. 21:02]--[2011-07-13 mer. 21:03] => 240:01
>                                 ^
> When point is at this position  |
>
> S-<left> will move one character backward.
>
> Can you see where does this come from?

Yes, I corrected this.

> Also, the solution looks really hackish...  a big hammer for such a 
> small nail :/

"For every problem, there is a solution which is simple, clean and wrong."

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: org-timestamp-up/down broken in tip
  2011-07-25 10:01           ` Nicolas Goaziou
@ 2011-07-25 13:57             ` Bastien
  0 siblings, 0 replies; 10+ messages in thread
From: Bastien @ 2011-07-25 13:57 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Org Mode List

Nicolas Goaziou <n.goaziou@gmail.com> writes:

>> S-<left> will move one character backward.
>>
>> Can you see where does this come from?
>
> Yes, I corrected this.

Thanks for the fix and for having applied the patch!

-- 
 Bastien

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2011-07-25 13:57 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-22  0:20 org-timestamp-up/down broken in tip Max Mikhanosha
2011-07-22  6:55 ` Sebastien Vauban
2011-07-22  7:17   ` Bastien
2011-07-22  7:27 ` Bastien
2011-07-22  7:53   ` Bastien
2011-07-22  8:47     ` Nicolas Goaziou
2011-07-22 20:11       ` Nicolas Goaziou
2011-07-24 19:10         ` Bastien
2011-07-25 10:01           ` Nicolas Goaziou
2011-07-25 13:57             ` Bastien

Code repositories for project(s) associated with this 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).