From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: emacs-orgmode@gnu.org
Subject: Re: [RFC] Display most recent log item in Agenda
Date: Fri, 19 Dec 2014 16:50:59 +0800 [thread overview]
Message-ID: <871tnwnhu4.fsf@ericabrahamsen.net> (raw)
In-Reply-To: 87k31s559y.fsf@nicolasgoaziou.fr
[-- Attachment #1: Type: text/plain, Size: 1157 bytes --]
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> Eric Abrahamsen <eric@ericabrahamsen.net> 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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-for-org-log-beginning-on-empty-entries.patch --]
[-- Type: text/x-diff, Size: 3175 bytes --]
From 04cea438e69a6b3d8fba060c02d80d2977ff9786 Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@ericabrahamsen.net>
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
next prev parent reply other threads:[~2014-12-19 12:08 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-14 10:07 [RFC] Display most recent log item in Agenda Eric Abrahamsen
2014-12-14 15:12 ` Eric Abrahamsen
2014-12-14 20:34 ` Nicolas Goaziou
2014-12-15 1:34 ` Eric Abrahamsen
2014-12-15 12:43 ` Nicolas Goaziou
2014-12-16 2:26 ` Eric Abrahamsen
2014-12-16 9:10 ` Nicolas Goaziou
2014-12-17 7:16 ` Eric Abrahamsen
2014-12-20 21:13 ` Nicolas Goaziou
2014-12-19 8:50 ` Eric Abrahamsen [this message]
2014-12-20 21:02 ` Nicolas Goaziou
2014-12-21 4:08 ` Eric Abrahamsen
2014-12-15 4:29 ` Eric Abrahamsen
2014-12-15 12:33 ` Nicolas Goaziou
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=871tnwnhu4.fsf@ericabrahamsen.net \
--to=eric@ericabrahamsen.net \
--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).