emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH 1/2] Fix error with %e agenda prefix format when there is no effort set
@ 2011-07-21 17:56 Max Mikhanosha
  2011-07-22 13:36 ` Bastien
  0 siblings, 1 reply; 6+ messages in thread
From: Max Mikhanosha @ 2011-07-21 17:56 UTC (permalink / raw)
  To: Org Mode List

`org-agenda-prefix-format' has un undocumented format %e for Effort, which
is broken. it throws error on entries without effort property.

Following patch fixes that problem. TODO: make agenda redraw current line
when `org-agenda-set-effort' sets a new effort

From c06b376737142eff5cdec71e8fc8129552aba673 Mon Sep 17 00:00:00 2001
From: Max Mikhanosha <max@openchat.com>
Date: Wed, 6 Jul 2011 20:05:06 -0400
Subject: [PATCH 1/2] Fix error with %e agenda prefix format when there is no effort set

---
 lisp/org-agenda.el |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index cd09a74..f34ffae 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -5511,7 +5511,9 @@ Any match of REMOVE-RE will be removed from TXT."
 		(error nil)))
 	(when effort
 	  (setq neffort (org-duration-string-to-minutes effort)
-		effort (setq effort (concat "[" effort "]" )))))
+		effort (setq effort (concat "[" effort "]")))))
+      ;; prevent erroring out with %e format when there is no effort
+      (or effort (setq effort ""))
 
       (when remove-re
 	(while (string-match remove-re txt)
@@ -5549,6 +5551,7 @@ Any match of REMOVE-RE will be removed from TXT."
 		 (>= (length category) org-prefix-category-max-length))
 	    (setq category (substring category 0 (1- org-prefix-category-max-length)))))
       ;; Evaluate the compiled format
+      (assert effort)
       (setq rtn (concat (eval org-prefix-format-compiled) txt))
 
       ;; And finally add the text properties
-- 
1.7.3.4

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

* Re: [PATCH 1/2] Fix error with %e agenda prefix format when there is no effort set
  2011-07-21 17:56 [PATCH 1/2] Fix error with %e agenda prefix format when there is no effort set Max Mikhanosha
@ 2011-07-22 13:36 ` Bastien
  2011-07-22 15:57   ` Max Mikhanosha
  2011-07-22 18:01   ` [PATCH] Fix %e agenda format and refresh of agenda items in general Max Mikhanosha
  0 siblings, 2 replies; 6+ messages in thread
From: Bastien @ 2011-07-22 13:36 UTC (permalink / raw)
  To: Max Mikhanosha; +Cc: Org Mode List

Hi Max,

thanks for the patch.

Max Mikhanosha <max@openchat.com> writes:

> `org-agenda-prefix-format' has un undocumented format %e for Effort, which
> is broken. it throws error on entries without effort property.

Yep, right.

> Following patch fixes that problem. TODO: make agenda redraw current line
> when `org-agenda-set-effort' sets a new effort
>
> From c06b376737142eff5cdec71e8fc8129552aba673 Mon Sep 17 00:00:00 2001
> From: Max Mikhanosha <max@openchat.com>
> Date: Wed, 6 Jul 2011 20:05:06 -0400
> Subject: [PATCH 1/2] Fix error with %e agenda prefix format when there is no effort set
>
> ---
>  lisp/org-agenda.el |    5 ++++-
>  1 files changed, 4 insertions(+), 1 deletions(-)
>
> diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
> index cd09a74..f34ffae 100644
> --- a/lisp/org-agenda.el
> +++ b/lisp/org-agenda.el
> @@ -5511,7 +5511,9 @@ Any match of REMOVE-RE will be removed from TXT."
>  		(error nil)))
>  	(when effort
>  	  (setq neffort (org-duration-string-to-minutes effort)
> -		effort (setq effort (concat "[" effort "]" )))))
> +		effort (setq effort (concat "[" effort "]")))))
> +      ;; prevent erroring out with %e format when there is no effort
> +      (or effort (setq effort ""))
>  
>        (when remove-re
>  	(while (string-match remove-re txt)
> @@ -5549,6 +5551,7 @@ Any match of REMOVE-RE will be removed from TXT."
>  		 (>= (length category) org-prefix-category-max-length))
>  	    (setq category (substring category 0 (1- org-prefix-category-max-length)))))
>        ;; Evaluate the compiled format
> +      (assert effort)

Why is this needed?  

>        (setq rtn (concat (eval org-prefix-format-compiled) txt))
>  
>        ;; And finally add the text properties

Thanks,

-- 
 Bastien

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

* Re: [PATCH 1/2] Fix error with %e agenda prefix format when there is no effort set
  2011-07-22 13:36 ` Bastien
@ 2011-07-22 15:57   ` Max Mikhanosha
  2011-07-27 13:00     ` Bastien
  2011-07-22 18:01   ` [PATCH] Fix %e agenda format and refresh of agenda items in general Max Mikhanosha
  1 sibling, 1 reply; 6+ messages in thread
From: Max Mikhanosha @ 2011-07-22 15:57 UTC (permalink / raw)
  Cc: Org Mode List


> >  	    (setq category (substring category 0 (1- org-prefix-category-max-length)))))
> >        ;; Evaluate the compiled format
> > +      (assert effort)
> 
> Why is this needed?  

Oops left that in accidentally. If you hold on for a few days, I'll
send a more complete patch implementing:

1. Refresh the %e effort displayed on agenda line after it changed by (org-agenda-set-effort)

2. Two new commands, org-agenda-effort-up, org-agenda-effort-down,
that would shift the effort up/down to the next value, with suggested
bindings of M-Left and M-Right, which will allow effortless editing of
efforts in Agenda

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

* Re: [PATCH] Fix %e agenda format and refresh of agenda items in general
  2011-07-22 13:36 ` Bastien
  2011-07-22 15:57   ` Max Mikhanosha
@ 2011-07-22 18:01   ` Max Mikhanosha
  2011-07-27 13:01     ` Bastien
  1 sibling, 1 reply; 6+ messages in thread
From: Max Mikhanosha @ 2011-07-22 18:01 UTC (permalink / raw)
  To: Bastien; +Cc: Org Mode List

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

Here is an updated patch, its split into 3 very small part, belowe is
an explanaton of each:

1. First patch is my original patch to fix error with %e agenda format.

2. Second patch fixes what I beleive to be a logic bug. Most agenda
related commands have the following format:

  (defun org-agenda-do-STUFF ()

   (org-with-remote-undo buffer
      (with-current-buffer buffer

        ;; change the item
        (call-interactively 'org-do-STUFF)
        (setq newhead (org-get-heading)))

     ;; refresh agenda lines that have same marker
     (org-agenda-change-all-lines newhead hdmarker))) 

The problem is with (org-agenda-change-all-lines). It calls
(org-format-agenda-item) on each item, but with the current buffer
being the agenda buffer and not the original item's buffer.

Also (org-format-agenda-item) expects the agenda item format to be in
the variable org-prefix-format-compiled. But when called by
(org-agenda-change-all-lines), that variable is not restored, and
instead has stale value from the last block of the agenda.

This causes the items to be randomly reformatted with last block's
agenda format, when they are changed.

My second patch fixes above problem, by making
(org-agenda-change-all-lines) call (org-format-agenda-item) in the
same way as when item was originally generated including changing
to the item's buffer, and restoring the correct compiled format variable.

3. Third patch changes (org-agenda-set-effort) to refresh the item. It requires
the 2nd patch to work.


    

[-- Attachment #2: 0003-Fix-error-with-e-agenda-prefix-format-when-there-is-.patch --]
[-- Type: application/octet-stream, Size: 1329 bytes --]

From c06b376737142eff5cdec71e8fc8129552aba673 Mon Sep 17 00:00:00 2001
From: Max Mikhanosha <max@openchat.com>
Date: Wed, 6 Jul 2011 20:05:06 -0400
Subject: [PATCH 3/8] Fix error with %e agenda prefix format when there is no effort set

---
 lisp/org-agenda.el |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index cd09a74..f34ffae 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -5511,7 +5511,9 @@ Any match of REMOVE-RE will be removed from TXT."
 		(error nil)))
 	(when effort
 	  (setq neffort (org-duration-string-to-minutes effort)
-		effort (setq effort (concat "[" effort "]" )))))
+		effort (setq effort (concat "[" effort "]")))))
+      ;; prevent erroring out with %e format when there is no effort
+      (or effort (setq effort ""))
 
       (when remove-re
 	(while (string-match remove-re txt)
@@ -5549,6 +5551,7 @@ Any match of REMOVE-RE will be removed from TXT."
 		 (>= (length category) org-prefix-category-max-length))
 	    (setq category (substring category 0 (1- org-prefix-category-max-length)))))
       ;; Evaluate the compiled format
+      (assert effort)
       (setq rtn (concat (eval org-prefix-format-compiled) txt))
 
       ;; And finally add the text properties
-- 
1.7.3.4


[-- Attachment #3: 0007-org-agenda-change-all-lines-Change-to-item-s-buffer-.patch --]
[-- Type: application/octet-stream, Size: 1969 bytes --]

From 6d8411910f83aa46b5b7782060bb25549e7d663b Mon Sep 17 00:00:00 2001
From: Max Mikhanosha <max@openchat.com>
Date: Fri, 22 Jul 2011 13:31:05 -0400
Subject: [PATCH 7/8] (org-agenda-change-all-lines): Change to item's buffer and use
 original column format that item was generated with

---
 lisp/org-agenda.el |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index c230201..ff1d55c 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -5566,7 +5566,6 @@ Any match of REMOVE-RE will be removed from TXT."
 		 (>= (length category) org-prefix-category-max-length))
 	    (setq category (substring category 0 (1- org-prefix-category-max-length)))))
       ;; Evaluate the compiled format
-      (assert effort)
       (setq rtn (concat (eval org-prefix-format-compiled) txt))
 
       ;; And finally add the text properties
@@ -5583,6 +5582,7 @@ Any match of REMOVE-RE will be removed from TXT."
 	'txt txt
 	'time time
 	'extra extra
+	'format org-prefix-format-compiled
 	'dotime dotime))))
 
 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
@@ -7257,8 +7257,16 @@ If FORCE-TAGS is non nil, the car of it returns the new tags."
 		dotime (org-get-at-bol 'dotime)
 		cat (org-get-at-bol 'org-category)
 		tags thetags
-		new (org-format-agenda-item (org-get-at-bol 'extra)
-					    newhead cat tags dotime)
+		new
+		(let ((org-prefix-format-compiled
+		       (or (get-text-property (point) 'format)
+			   org-prefix-format-compiled)))
+		  (with-current-buffer (marker-buffer hdmarker)
+		    (save-excursion
+		      (save-restriction
+			(widen)
+			(org-format-agenda-item (org-get-at-bol 'extra)
+						newhead cat tags dotime)))))
 		pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
 		undone-face (org-get-at-bol 'undone-face)
 		done-face (org-get-at-bol 'done-face))
-- 
1.7.3.4


[-- Attachment #4: 0008-org-agenda-set-effort-Refresh-changed-lines.patch --]
[-- Type: application/octet-stream, Size: 1069 bytes --]

From 72ccd0d747ee5d332115098c40137b9b2eaf0f5b Mon Sep 17 00:00:00 2001
From: Max Mikhanosha <max@openchat.com>
Date: Fri, 22 Jul 2011 13:35:51 -0400
Subject: [PATCH 8/8] (org-agenda-set-effort): Refresh changed lines

---
 lisp/org-agenda.el |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index ff1d55c..9c60919 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -7428,10 +7428,12 @@ the same tree node, and the headline of the tree node in the Org-mode file."
 	  (org-show-context 'agenda))
 	(save-excursion
 	  (and (outline-next-heading)
-	       (org-flag-heading nil)))   ; show the next heading
+	       (org-flag-heading nil)))	; show the next heading
 	(goto-char pos)
 	(call-interactively 'org-set-effort)
-	(end-of-line 1)))))
+	(end-of-line 1)
+	(setq newhead (org-get-heading)))
+      (org-agenda-change-all-lines newhead hdmarker))))
 
 (defun org-agenda-toggle-archive-tag ()
   "Toggle the archive tag for the current entry."
-- 
1.7.3.4


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

* Re: [PATCH 1/2] Fix error with %e agenda prefix format when there is no effort set
  2011-07-22 15:57   ` Max Mikhanosha
@ 2011-07-27 13:00     ` Bastien
  0 siblings, 0 replies; 6+ messages in thread
From: Bastien @ 2011-07-27 13:00 UTC (permalink / raw)
  To: Max Mikhanosha; +Cc: Org Mode List

Hi Max,

Max Mikhanosha <max@openchat.com> writes:

> 2. Two new commands, org-agenda-effort-up, org-agenda-effort-down,
> that would shift the effort up/down to the next value, with suggested
> bindings of M-Left and M-Right, which will allow effortless editing of
> efforts in Agenda

That'd be nice -- thanks for your time!

-- 
 Bastien

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

* Re: [PATCH] Fix %e agenda format and refresh of agenda items in general
  2011-07-22 18:01   ` [PATCH] Fix %e agenda format and refresh of agenda items in general Max Mikhanosha
@ 2011-07-27 13:01     ` Bastien
  0 siblings, 0 replies; 6+ messages in thread
From: Bastien @ 2011-07-27 13:01 UTC (permalink / raw)
  To: Max Mikhanosha; +Cc: Org Mode List

Hi Max,

Max Mikhanosha <max@openchat.com> writes:

> Here is an updated patch, its split into 3 very small part, belowe is
> an explanaton of each:

I applied all three, thanks a bunch for this.

> 1. First patch is my original patch to fix error with %e agenda
> format.

Okay.

> 2. Second patch fixes what I beleive to be a logic bug. Most agenda
> related commands have the following format:

I understand and I agree, thanks for the clear explanations and the fix.

> 3. Third patch changes (org-agenda-set-effort) to refresh the item. It requires
> the 2nd patch to work.

Applied too.

Thanks a lot!

-- 
 Bastien

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

end of thread, other threads:[~2011-07-27 14:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-21 17:56 [PATCH 1/2] Fix error with %e agenda prefix format when there is no effort set Max Mikhanosha
2011-07-22 13:36 ` Bastien
2011-07-22 15:57   ` Max Mikhanosha
2011-07-27 13:00     ` Bastien
2011-07-22 18:01   ` [PATCH] Fix %e agenda format and refresh of agenda items in general Max Mikhanosha
2011-07-27 13:01     ` Bastien

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).