From mboxrd@z Thu Jan 1 00:00:00 1970 From: Max Mikhanosha Subject: Re: [PATCH] Fix %e agenda format and refresh of agenda items in general Date: Fri, 22 Jul 2011 14:01:07 -0400 Message-ID: <87k4bary8s.wl%max@openchat.com> References: <87ipqv5xga.wl%max@openchat.com> <87r55i1lp4.fsf@gnu.org> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: multipart/mixed; boundary="Multipart_Fri_Jul_22_14:01:07_2011-1" Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([140.186.70.92]:48736) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QkK2A-0008SP-Mv for emacs-orgmode@gnu.org; Fri, 22 Jul 2011 14:01:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QkK29-0002gO-Ix for emacs-orgmode@gnu.org; Fri, 22 Jul 2011 14:01:10 -0400 Received: from p84-72.acedsl.com ([66.114.84.72]:50982 helo=momoland.openchat.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QkK29-0002gF-8b for emacs-orgmode@gnu.org; Fri, 22 Jul 2011 14:01:09 -0400 In-Reply-To: <87r55i1lp4.fsf@gnu.org> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Bastien Cc: Org Mode List --Multipart_Fri_Jul_22_14:01:07_2011-1 Content-Type: text/plain; charset=US-ASCII 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. --Multipart_Fri_Jul_22_14:01:07_2011-1 Content-Type: application/octet-stream; type=patch Content-Disposition: attachment; filename="0003-Fix-error-with-e-agenda-prefix-format-when-there-is-.patch" Content-Transfer-Encoding: quoted-printable >From c06b376737142eff5cdec71e8fc8129552aba673 Mon Sep 17 00:00:00 2001 From: Max Mikhanosha 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 "")) =20 (when remove-re (while (string-match remove-re txt) @@ -5549,6 +5551,7 @@ Any match of REMOVE-RE will be removed from TXT." (>=3D (length category) org-prefix-category-max-length)) (setq category (substring category 0 (1- org-prefix-category-max-le= ngth))))) ;; Evaluate the compiled format + (assert effort) (setq rtn (concat (eval org-prefix-format-compiled) txt)) =20 ;; And finally add the text properties --=20 1.7.3.4 --Multipart_Fri_Jul_22_14:01:07_2011-1 Content-Type: application/octet-stream; type=patch Content-Disposition: attachment; filename="0007-org-agenda-change-all-lines-Change-to-item-s-buffer-.patch" Content-Transfer-Encoding: quoted-printable >From 6d8411910f83aa46b5b7782060bb25549e7d663b Mon Sep 17 00:00:00 2001 From: Max Mikhanosha Date: Fri, 22 Jul 2011 13:31:05 -0400 Subject: [PATCH 7/8] (org-agenda-change-all-lines): Change to item's buff= er 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." (>=3D (length category) org-prefix-category-max-length)) (setq category (substring category 0 (1- org-prefix-category-max-le= ngth))))) ;; Evaluate the compiled format - (assert effort) (setq rtn (concat (eval org-prefix-format-compiled) txt)) =20 ;; 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)))) =20 (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 th= e 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)) --=20 1.7.3.4 --Multipart_Fri_Jul_22_14:01:07_2011-1 Content-Type: application/octet-stream; type=patch Content-Disposition: attachment; filename="0008-org-agenda-set-effort-Refresh-changed-lines.patch" Content-Transfer-Encoding: quoted-printable >From 72ccd0d747ee5d332115098c40137b9b2eaf0f5b Mon Sep 17 00:00:00 2001 From: Max Mikhanosha 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)))) =20 (defun org-agenda-toggle-archive-tag () "Toggle the archive tag for the current entry." --=20 1.7.3.4 --Multipart_Fri_Jul_22_14:01:07_2011-1--