Bastien <b...@gnu.org> writes:

> Hi Eric,
>
> Eric Abrahamsen <e...@ericabrahamsen.net> writes:
>
>> By passing the FORCE argument to `org-get-property-block', the broken
>> block ends up getting silently repaired, and everything works as normal.
>
> Can you show this as a patch?
>
>> I'm not sure, however, that silently repairing things without the user's
>> knowledge is the right thing to do...
>
> We can warn the user with a temporary message, or ask him for
> confirmation.  Or provide a helper command to repair drawers and
> advertize it instead of throwing an error.
>
> I'll look into this after you send me the patch.

The more I thought about it, the more it seemed the silent repair is a
bad idea: it's not really repair, it's just sticking a new :END: in, and
will very likely result in cruft in the buffer. This patch wraps the
scan in catch/throw and asks users if they want to repair broken
drawers. Since the y-or-no-p stops at the broken drawer, it should be
useful for manual fixing.

E

>From 3995f4816ba400f5c7645f84b5dcf7e84698d604 Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <e...@ericabrahamsen.net>
Date: Fri, 23 May 2014 16:52:58 +0800
Subject: [PATCH] Warn users of malformed property drawers

org.el (org-buffer-property-keys): When scanning the buffer for valid
property keys, give users a chance to repair any malformed property
drawers.
---
 lisp/org.el | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index b16515e..a3f0cba 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -15712,12 +15712,17 @@ formats in the current buffer."
 	(widen)
 	(goto-char (point-min))
 	(while (re-search-forward org-property-start-re nil t)
-	  (setq range (org-get-property-block))
-	  (goto-char (car range))
-	  (while (re-search-forward org-property-re
-		  (cdr range) t)
-	    (add-to-list 'rtn (org-match-string-no-properties 2)))
-	  (outline-next-heading))))
+	  (catch 'cont
+	    (setq range (or (org-get-property-block)
+			    (if (y-or-n-p
+				 (format "Malformed drawer at %d, repair?" (point)))
+				(org-get-property-block nil nil t)
+				(throw 'cont nil))))
+	    (goto-char (car range))
+	    (while (re-search-forward org-property-re
+				      (cdr range) t)
+	      (add-to-list 'rtn (org-match-string-no-properties 2)))
+	    (outline-next-heading)))))
 
     (when include-specials
       (setq rtn (append org-special-properties rtn)))
-- 
1.9.3

Reply via email to