From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Abrahamsen Subject: Re: [RFC] Display most recent log item in Agenda Date: Fri, 19 Dec 2014 16:50:59 +0800 Message-ID: <871tnwnhu4.fsf@ericabrahamsen.net> References: <87388imto5.fsf@ericabrahamsen.net> <878uia6kdh.fsf@nicolasgoaziou.fr> <87ppbllmqj.fsf@ericabrahamsen.net> <87vbld5biw.fsf@nicolasgoaziou.fr> <87wq5sqqin.fsf@ericabrahamsen.net> <87k31s559y.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:39077) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y1wM7-00027A-8q for emacs-orgmode@gnu.org; Fri, 19 Dec 2014 07:08:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y1wM1-0005wK-RG for emacs-orgmode@gnu.org; Fri, 19 Dec 2014 07:08:27 -0500 Received: from plane.gmane.org ([80.91.229.3]:60458) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y1wM1-0005ve-FV for emacs-orgmode@gnu.org; Fri, 19 Dec 2014 07:08:21 -0500 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1Y1wLz-00031n-Pq for emacs-orgmode@gnu.org; Fri, 19 Dec 2014 13:08:19 +0100 Received: from 219.237.3.86 ([219.237.3.86]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 19 Dec 2014 13:08:19 +0100 Received: from eric by 219.237.3.86 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 19 Dec 2014 13:08:19 +0100 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: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Nicolas Goaziou writes: > Eric Abrahamsen writes: > >> I thought that's what `org-log-beginning' was for: finding where the >> log-note list would be (drawer or no), if it exists. > > Not exactly. It finds where the next note is to be inserted. This may > not be in front of the log-note list even if it exists (e.g., if > `org-log-states-order-reversed' is nil you may end up in front of the > following paragraph). I keep hammering on this but... There's still a bug in `org-log-beginning', I think maybe the same one as before. Say it's called on an empty entry, or one that only contains a property drawer and/or a planning line, and there's another entry immediately after it, no blank line. Then we reach this line: (if (org-at-heading-p) (point) The test returns true because we're already on the next headline. (point) is returned as the place to put the new note, without checking if a drawer should be inserted, too. That means the first note won't go in a drawer, but all subsequent ones do. I came up with something that works, but I look forward to seeing a more elegant solution! Eric --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Fix-for-org-log-beginning-on-empty-entries.patch >From 04cea438e69a6b3d8fba060c02d80d2977ff9786 Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen Date: Fri, 19 Dec 2014 16:48:22 +0800 Subject: [PATCH] Fix for `org-log-beginning' on empty entries * lisp/org.el (org-log-beginning): Check for the need to insert a drawer in all cases. --- lisp/org.el | 59 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 1383d76..b3d4381 100755 --- a/lisp/org.el +++ b/lisp/org.el @@ -13613,35 +13613,36 @@ narrowing." (when (looking-at org-property-drawer-re) (goto-char (match-end 0)) (forward-line)) - (if (org-at-heading-p) (point) - (let ((end (save-excursion (outline-next-heading) (point))) - (drawer (org-log-into-drawer))) - (cond - (drawer - (let ((regexp (concat "^[ \t]*:" (regexp-quote drawer) ":[ \t]*$")) - (case-fold-search t)) - (catch 'exit - ;; Try to find existing drawer. - (while (re-search-forward regexp end t) - (let ((element (org-element-at-point))) - (when (eq (org-element-type element) 'drawer) - (let ((cend (org-element-property :contents-end element))) - (when (and (not org-log-states-order-reversed) cend) - (goto-char cend))) - (throw 'exit nil)))) - ;; No drawer found. Create one, if permitted. - (when create - (unless (bolp) (insert "\n")) - (let ((beg (point))) - (insert ":" drawer ":\n:END:\n") - (org-indent-region beg (point))) - (end-of-line -1))))) - (org-log-state-notes-insert-after-drawers - (while (and (looking-at org-drawer-regexp) - (progn (goto-char (match-end 0)) - (re-search-forward org-property-end-re end t))) - (forward-line))))) - (if (bolp) (point) (line-beginning-position 2))))) + (let ((end (save-excursion (when (org-at-heading-p) + (forward-line -1)) + (outline-next-heading) (point))) + (drawer (org-log-into-drawer))) + (cond + (drawer + (let ((regexp (concat "^[ \t]*:" (regexp-quote drawer) ":[ \t]*$")) + (case-fold-search t)) + (catch 'exit + ;; Try to find existing drawer. + (while (re-search-forward regexp end t) + (let ((element (org-element-at-point))) + (when (eq (org-element-type element) 'drawer) + (let ((cend (org-element-property :contents-end element))) + (when (and (not org-log-states-order-reversed) cend) + (goto-char cend))) + (throw 'exit nil)))) + ;; No drawer found. Create one, if permitted. + (when create + (unless (bolp) (insert "\n")) + (let ((beg (point))) + (insert ":" drawer ":\n:END:\n") + (org-indent-region beg (point))) + (end-of-line -1))))) + (org-log-state-notes-insert-after-drawers + (while (and (looking-at org-drawer-regexp) + (progn (goto-char (match-end 0)) + (re-search-forward org-property-end-re end t))) + (forward-line))))) + (if (bolp) (point) (line-beginning-position 2)))) (defun org-add-log-setup (&optional purpose state prev-state findpos how extra) "Set up the post command hook to take a note. -- 2.2.0 --=-=-=--