summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Dominik <carsten.dominik@gmail.com>2010-08-16 19:20:01 +0200
committerCarsten Dominik <carsten.dominik@gmail.com>2010-08-16 19:20:01 +0200
commit56cf6ad42de9f00fe90cfb5230468872e679c163 (patch)
treecff4e68341bd3eb56e72612f5e128c09104c8823
parent3aa4ba493e8a859c0f06cf257146425adaad62e0 (diff)
downloadorg-mode-56cf6ad42de9f00fe90cfb5230468872e679c163.tar.gz
Verify that refile cached position is correct
* lisp/org.el (org-refile-check-position): New function. (org-goto): (org-refile-get-location): Call `org-refile-check-position'. Samuel Wales has reported that the cache is loosing it, occasionally.
-rw-r--r--lisp/org.el25
1 files changed, 24 insertions, 1 deletions
diff --git a/lisp/org.el b/lisp/org.el
index 49b04f4..003ab84 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -6440,7 +6440,9 @@ the headline hierarchy above."
(selected-point
(if (eq interface 'outline)
(car (org-get-location (current-buffer) org-goto-help))
- (nth 3 (org-refile-get-location "Goto: ")))))
+ (let ((pa (org-refile-get-location "Goto: ")))
+ (org-refile-check-position pa)
+ (nth 3 pa)))))
(if selected-point
(progn
(org-mark-ring-push org-goto-start-pos)
@@ -10246,6 +10248,7 @@ This can be done with a 0 prefix: `C-0 C-c C-w'"
(setq answ (funcall cfunc prompt tbl nil (not new-nodes)
nil 'org-refile-history))
(setq pa (or (assoc answ tbl) (assoc (concat answ "/") tbl)))
+ (org-refile-check-position pa)
(if pa
(progn
(when (or (not org-refile-history)
@@ -10272,6 +10275,26 @@ This can be done with a 0 prefix: `C-0 C-c C-w'"
(org-refile-new-child parent-target child)))
(error "Invalid target location")))))
+(defun org-refile-check-position (refile-pointer)
+ "Check if the refile pointer matches the readline to which it points."
+ (let* ((file (nth 1 refile-pointer))
+ (re (nth 2 refile-pointer))
+ (pos (nth 3 refile-pointer))
+ buffer)
+ (when (org-string-nw-p re)
+ (setq buffer (if (markerp pos)
+ (marker-buffer pos)
+ (or (find-buffer-visiting file)
+ (find-file-noselect file))))
+ (with-current-buffer buffer
+ (save-excursion
+ (save-restriction
+ (widen)
+ (goto-char pos)
+ (beginning-of-line 1)
+ (unless (org-looking-at-p re)
+ (error "Invalid refile position, please rebuild the cache"))))))))
+
(defun org-refile-new-child (parent-target child)
"Use refile target PARENT-TARGET to add new CHILD below it."
(unless parent-target