[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Possibly Bug in function org-scan-tags
From: |
Nick Dokos |
Subject: |
Re: [O] Possibly Bug in function org-scan-tags |
Date: |
Fri, 16 Dec 2011 01:41:41 -0500 |
bala mayam <address@hidden> wrote:
> The patch has error, it does not work for the following example file
> /tmp/example.org
> * DONE s1
> * DONE s2
> * DONE s3
>
> The below patch works for all the cases
>
> diff --git a/lisp/org.el b/lisp/org.el
> index 8a1fbd3..93d603f 100644
> --- a/lisp/org.el
> +++ b/lisp/org.el
> @@ -12858,7 +12858,8 @@ only lines with a TODO keyword are included in the
> outpu
> ;; Get the correct position from where to continue
> (if org-map-continue-from
> (goto-char org-map-continue-from)
> - (and (= (point) lspos) (end-of-line 1)))))
> + (and (= (point) lspos) (end-of-line 1)))
> + (setq org-map-continue-from nil)))
> (when (and (eq action 'sparse-tree)
> (not org-sparse-tree-open-archived-trees))
> (org-hide-archived-subtrees (point-min) (point-max)))
>
> - Balamayam
>
> On Thu, Dec 15, 2011 at 3:18 AM, bala subramaniyam <address@hidden> wrote:
>
> Hi,
> The variable "org-map-continue-from" is not reset to nil
> after the funcall to action
> in function "org-scan-tags".
>
> Heres the patch which works
>
> diff --git a/lisp/org.el b/lisp/org.el
> index 8a1fbd3..54ab5fb 100644
> --- a/lisp/org.el
> +++ b/lisp/org.el
> @@ -12848,7 +12848,8 @@ only lines with a TODO keyword are included in
> the output."
> (setq org-map-continue-from nil)
> (save-excursion
> (setq rtn1 (funcall action))
> - (push rtn1 rtn)))
> + (push rtn1 rtn))
> + (setq org-map-continue-from nil))
> (t (error "Invalid action")))
>
> ;; if we are to skip sublevels, jump to end of subtree
>
> To see the error in action assume that we want to archive all the "DONE"
> states in the file
> /tmp/test.org which contains the following lines.
> * s1
> ** DONE ss1
> ** NEXT ss2
>
> (defun my-org-archive-subtree ()
> (setq org-map-continue-from (point-at-bol))
> (org-archive-subtree))
>
> (org-map-entries 'my-org-archive-subtree "/DONE" (list "/tmp/test.org"))
>
> While the org-scan-tags funciton parses the first subheading(**DONE ss1)
> the match is
> successful and the function "my-org-archive-subtree" is called which sets
> the variable
> "org-map-continue-from" value to *beginning of line* and this variable is
> not set back to nil
> after the function call ends, which leads to infinite loop while parsing
> the subsequent headlines
> which does not match the "DONE" state(**NEXT ss2).
>
I think it's a bit much to expect org to avoid all possible infinite loops
that a user function can get it into - it's up to you to write the function
properly so that it does *not* lead to infinite loops.
In this case, I think you can write
--8<---------------cut here---------------start------------->8---
(defun my-org-archive-subtree ()
(let ((org-map-continue-from (point-at-bol)))
(org-archive-subtree)))
--8<---------------cut here---------------end--------------->8---
and be done with it - no changes to org needed. AFAICT, it deals with
both of your examples without going into an infinite loop.
What am I missing?
Nick