emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-map-entries doesn't understand deletions
@ 2009-04-04 23:06 Samuel Wales
  2009-04-05 11:48 ` Carsten Dominik
  0 siblings, 1 reply; 4+ messages in thread
From: Samuel Wales @ 2009-04-04 23:06 UTC (permalink / raw)
  To: emacs-orgmode

A while back, I wanted to archive all tasks that were closed
more than n days ago (or, better, archive tasks merked with
a done todo keyword, since some tasks have vestigial closed
timestamps without having a done todo keyword).

I tried using mapping.  However, it took me months to get
this far, was extremely difficult for me, and it is still
not working.  I cannot proceed further, but I also now think
that the remaining issue is probably not user error.

The problem seems to be that archiving deletes entries,
which places point after the deleted entry, which causes
mapping to skip an entry.  See the comments for more details, including
why this is apparently not fixable by the user.

If it is not user error, then there might be a fundamental
problem with how org-map-entries places point.  I have a suggestion
for a possible solution in the comments.

Thanks.


;;i don't want to change the todo kw
(setf org-archive-mark-done nil)

(defvar alpha-org-archive-expired-ndays 31
  "when done (or closed -- see code) entries are expired, expire
only older todo entries.")
(defun alpha-org-days-since-closed ()
  "age in days since closed"
  (interactive)
  (let ((ts (org-entry-get nil "CLOSED")))
    (when ts (org-days-to-time ts))))
(defun alpha-org-expired-p ()
  (let ((n (alpha-org-days-since-closed)))
    (and n (< n (- alpha-org-archive-expired-ndays)))))
(defun alpha-org-archive-heading ()
  (interactive)
  ;;archiving moves point to the next entry, which is congruent to
  ;;/forward/ killing.  however, mapping moves point /after/
  ;;running this.  save-excursion would do nothing useful here.
  ;;
  ;;i think it's undocumented whether mapping operates 1.
  ;;according to point after execution, 2.  goes to a prior
  ;;concept of point (e.g. going to a marker placed at the next
  ;;entry), or 3.  does some kind of save-excursion thing that
  ;;assumes no deletion.  this question is important.
  ;;
  ;;it seems to be 3.  try running this on 2 sequential entries
  ;;that need archiving.  it will skip over the second even if you
  ;;manually move to the previous entry.  thus, perhaps, any
  ;;kludging around it in this function is reversed.  the code is
  ;;incomprehensible to me.
  ;;
  ;;i think that 3. is probably incorrect behavior because
  ;;sometimes, as here, people want to delete
  ;;entries.  1. would at least leave everything up to user
  ;;control and I would recommend it, despite its drawbacks.  if
save-excursion, or whatever, was placed there to fix some other
problem, then doing so might require care in implementing.  perhaps
even with a parameter.
  (when (alpha-org-expired-p)
;;;        ;;(insert (prin1-to-string (alpha-org-days-since-closed)))
    (org-archive-subtree)
    ;;the above moves point to the next entry, and exiting this
    ;;form moves it again.  therefore we have to move back.  dunno
    ;;if visibility matters, so playing it safe by saying visible
    ;;here and show-all in the caller.  this will instantiate a
    ;;loop if archiving does not do as expected.  that would be a
    ;;bug.
    (outline-previous-visible-heading 1)))
(defun alpha-org-archive-expired-closed ()
  (interactive)
  ;;forestall issues with folding and visibility
  (show-all)
  (org-map-entries 'alpha-org-archive-heading
                   ;;this expression is hardcoded instead of
                   ;;specifying doneness.  otoh, there are
                   ;;sometimes mistakenly closed items that are
                   ;;not done in the kw, and we don't want to
                   ;;archive those.
                   ;;
                   ;;"/+DONE|+MOOT"
                   ;;TODO={^DONE$\\|^MOOT$}
                   ;;"+CLOSED<\"<-1m>\""
                   t
                   'file))

-- 
Myalgic encephalomyelitis denialism is causing death (decades early;
Jason et al. 2006) and severe suffering (worse than nearly all other
diseases studied; e.g. Schweitzer et al. 1995) and grossly corrupting
science.  http://www.meactionuk.org.uk/What_Is_ME_What_Is_CFS.htm

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: org-map-entries doesn't understand deletions
  2009-04-04 23:06 org-map-entries doesn't understand deletions Samuel Wales
@ 2009-04-05 11:48 ` Carsten Dominik
  2009-04-06  4:24   ` Samuel Wales
  0 siblings, 1 reply; 4+ messages in thread
From: Carsten Dominik @ 2009-04-05 11:48 UTC (permalink / raw)
  To: Samuel Wales; +Cc: emacs-orgmode

Hi Samuel,

you are quite right.

The mapping function does wrap the call to your action
function into a save-excursion form that assumes to return
to the beginning of the headline.  It then jumps to the end
of that line and continues search from there.

This is by design, because it allows "quick and dirty" uses
of the mapper without having to take care where the cursor is
after the function call.  And is does the right thing in all
cases where meta data of the entry at point i changed.

But you are also right, that for your application this does
not work out right.

To remidy this situation, get the latest git version.

Your action function may now set the variable
`org-map-continue-from-here' to the buffer position
from where you wish to continue the search.  In your case
you would now remove you attempt to fix this

    (outline-previous-visible-heading 1)))

and replace it with

    (setq org-map-continue-from (point))))


This should fix the problems.


On Apr 5, 2009, at 1:06 AM, Samuel Wales wrote:

> A while back, I wanted to archive all tasks that were closed
> more than n days ago (or, better, archive tasks merked with
> a done todo keyword, since some tasks have vestigial closed
> timestamps without having a done todo keyword).
>
> I tried using mapping.  However, it took me months to get
> this far, was extremely difficult for me, and it is still
> not working.  I cannot proceed further, but I also now think
> that the remaining issue is probably not user error.
>
> The problem seems to be that archiving deletes entries,
> which places point after the deleted entry, which causes
> mapping to skip an entry.  See the comments for more details,  
> including
> why this is apparently not fixable by the user.
>
> If it is not user error, then there might be a fundamental
> problem with how org-map-entries places point.  I have a suggestion
> for a possible solution in the comments.
>
> Thanks.
>
>
> ;;i don't want to change the todo kw
> (setf org-archive-mark-done nil)
>
> (defvar alpha-org-archive-expired-ndays 31
>  "when done (or closed -- see code) entries are expired, expire
> only older todo entries.")
> (defun alpha-org-days-since-closed ()
>  "age in days since closed"
>  (interactive)
>  (let ((ts (org-entry-get nil "CLOSED")))
>    (when ts (org-days-to-time ts))))
> (defun alpha-org-expired-p ()
>  (let ((n (alpha-org-days-since-closed)))
>    (and n (< n (- alpha-org-archive-expired-ndays)))))
> (defun alpha-org-archive-heading ()
>  (interactive)
>  ;;archiving moves point to the next entry, which is congruent to
>  ;;/forward/ killing.  however, mapping moves point /after/
>  ;;running this.  save-excursion would do nothing useful here.
>  ;;
>  ;;i think it's undocumented whether mapping operates 1.
>  ;;according to point after execution, 2.  goes to a prior
>  ;;concept of point (e.g. going to a marker placed at the next
>  ;;entry), or 3.  does some kind of save-excursion thing that
>  ;;assumes no deletion.  this question is important.
>  ;;
>  ;;it seems to be 3.  try running this on 2 sequential entries
>  ;;that need archiving.  it will skip over the second even if you
>  ;;manually move to the previous entry.  thus, perhaps, any
>  ;;kludging around it in this function is reversed.  the code is
>  ;;incomprehensible to me.
>  ;;
>  ;;i think that 3. is probably incorrect behavior because
>  ;;sometimes, as here, people want to delete
>  ;;entries.  1. would at least leave everything up to user
>  ;;control and I would recommend it, despite its drawbacks.  if
> save-excursion, or whatever, was placed there to fix some other
> problem, then doing so might require care in implementing.  perhaps
> even with a parameter.
>  (when (alpha-org-expired-p)
> ;;;        ;;(insert (prin1-to-string (alpha-org-days-since-closed)))
>    (org-archive-subtree)
>    ;;the above moves point to the next entry, and exiting this
>    ;;form moves it again.  therefore we have to move back.  dunno
>    ;;if visibility matters, so playing it safe by saying visible
>    ;;here and show-all in the caller.  this will instantiate a
>    ;;loop if archiving does not do as expected.  that would be a
>    ;;bug.
>    (outline-previous-visible-heading 1)))
> (defun alpha-org-archive-expired-closed ()
>  (interactive)
>  ;;forestall issues with folding and visibility
>  (show-all)
>  (org-map-entries 'alpha-org-archive-heading
>                   ;;this expression is hardcoded instead of
>                   ;;specifying doneness.  otoh, there are
>                   ;;sometimes mistakenly closed items that are
>                   ;;not done in the kw, and we don't want to
>                   ;;archive those.
>                   ;;
>                   ;;"/+DONE|+MOOT"
>                   ;;TODO={^DONE$\\|^MOOT$}
>                   ;;"+CLOSED<\"<-1m>\""
>                   t
>                   'file))
>
> -- 
> Myalgic encephalomyelitis denialism is causing death (decades early;
> Jason et al. 2006) and severe suffering (worse than nearly all other
> diseases studied; e.g. Schweitzer et al. 1995) and grossly corrupting
> science.  http://www.meactionuk.org.uk/What_Is_ME_What_Is_CFS.htm
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Remember: use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: org-map-entries doesn't understand deletions
  2009-04-05 11:48 ` Carsten Dominik
@ 2009-04-06  4:24   ` Samuel Wales
  2009-04-06  6:02     ` Carsten Dominik
  0 siblings, 1 reply; 4+ messages in thread
From: Samuel Wales @ 2009-04-06  4:24 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: emacs-orgmode

On Sun, Apr 5, 2009 at 04:48, Carsten Dominik <carsten.dominik@gmail.com> wrote:
> Your action function may now set the variable
> `org-map-continue-from-here' to the buffer position
> from where you wish to continue the search.  In your case
> you would now remove you attempt to fix this

Thank you very much.  I will try it.

I figured it was probably intended to relieve the user of
responsibility for point.  However, using mapping for editing
operations seems like the right thing to do also.

Your solution and the new paragraph in the manual should take care of it.

So I set it to where point is after a deletion?  i.e. on the following item?

-- 
Myalgic encephalomyelitis denialism is causing death and severe
suffering, worse than multiple sclerosis.  It is corrupting science in
the most foul way possible.  Anybody can get the disease at any time
-- permanently.  How much do science and justice matter to you?
http://www.meactionuk.org.uk/What_Is_ME_What_Is_CFS.htm

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: org-map-entries doesn't understand deletions
  2009-04-06  4:24   ` Samuel Wales
@ 2009-04-06  6:02     ` Carsten Dominik
  0 siblings, 0 replies; 4+ messages in thread
From: Carsten Dominik @ 2009-04-06  6:02 UTC (permalink / raw)
  To: Samuel Wales; +Cc: emacs-orgmode


On Apr 6, 2009, at 6:24 AM, Samuel Wales wrote:

> On Sun, Apr 5, 2009 at 04:48, Carsten Dominik <carsten.dominik@gmail.com 
> > wrote:
>> Your action function may now set the variable
>> `org-map-continue-from-here' to the buffer position
>> from where you wish to continue the search.  In your case
>> you would now remove you attempt to fix this
>
> Thank you very much.  I will try it.
>
> I figured it was probably intended to relieve the user of
> responsibility for point.  However, using mapping for editing
> operations seems like the right thing to do also.
>
> Your solution and the new paragraph in the manual should take care  
> of it.
>
> So I set it to where point is after a deletion?  i.e. on the  
> following item?

On the following item, yes.

- Carsten

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-04-06  6:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-04 23:06 org-map-entries doesn't understand deletions Samuel Wales
2009-04-05 11:48 ` Carsten Dominik
2009-04-06  4:24   ` Samuel Wales
2009-04-06  6:02     ` Carsten Dominik

Code repositories for project(s) associated with this 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).