emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Max Mikhanosha <max@openchat.com>
To: Bastien <bzg@altern.org>
Cc: Org Mode List <emacs-orgmode@gnu.org>
Subject: Re: [PATCH] Fix %e agenda format and refresh of agenda items in general
Date: Fri, 22 Jul 2011 14:01:07 -0400	[thread overview]
Message-ID: <87k4bary8s.wl%max@openchat.com> (raw)
In-Reply-To: <87r55i1lp4.fsf@gnu.org>

[-- 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


  parent reply	other threads:[~2011-07-22 18:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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   ` Max Mikhanosha [this message]
2011-07-27 13:01     ` [PATCH] Fix %e agenda format and refresh of agenda items in general Bastien

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=87k4bary8s.wl%max@openchat.com \
    --to=max@openchat.com \
    --cc=bzg@altern.org \
    --cc=emacs-orgmode@gnu.org \
    /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).