emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* How to mark task as done at specified (past) time?
@ 2019-11-28 10:57 Tim Landscheidt
  2019-12-12  3:26 ` Kyle Meyer
  0 siblings, 1 reply; 4+ messages in thread
From: Tim Landscheidt @ 2019-11-28 10:57 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

with Emacs 26.2/org-mode 9.1.9, I have a repeating task that
I close with a helper function:

| (defun tl-entry-done ()
|   (interactive)
|   (find-file "/path/to/file.org")
|   (goto-char (org-find-entry-with-id "ENTRY-ID"))
|   (org-todo 'done))

Every time I do this task, I get an acknowledging mail, so
instead of manually closing this task (and forgetting to do
that, or delaying it for some time) I want Gnus to mark the
task as done /at the time when the mail was sent/, i. e. in:

|    - State "DONE"       from "TODO"       [2019-11-27 Mi 16:44]

I want "2019-11-27 Mi 16:44" not to be the current time, but
some other (past) time.

How can I mark a task as done at a specified time?  Looking
at org-add-planning-info, there seems to be a mechanism to
pass a timestamp, but it does not seem to be exposed at
higher levels (?).

Do I have to cl-flet org-current-time or something similar?

Tim

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

* Re: How to mark task as done at specified (past) time?
  2019-11-28 10:57 How to mark task as done at specified (past) time? Tim Landscheidt
@ 2019-12-12  3:26 ` Kyle Meyer
  2020-07-08 20:50   ` Tim Landscheidt
  0 siblings, 1 reply; 4+ messages in thread
From: Kyle Meyer @ 2019-12-12  3:26 UTC (permalink / raw)
  To: Tim Landscheidt, emacs-orgmode

Tim Landscheidt <tim@tim-landscheidt.de> writes:
[...]
> I want Gnus to mark the task as done /at the time when the mail was
> sent/, i. e. in:
> |    - State "DONE"       from "TODO"       [2019-11-27 Mi 16:44]
>
> I want "2019-11-27 Mi 16:44" not to be the current time, but
> some other (past) time.
>
> How can I mark a task as done at a specified time?  Looking
> at org-add-planning-info, there seems to be a mechanism to
> pass a timestamp, but it does not seem to be exposed at
> higher levels (?).

Yes, as far as I can see, org-todo uses the TIME argument of
org-add-planning-info for the org-extend-today-until feature, but
there's not a way for the caller to directly specify the timestamp.

> Do I have to cl-flet org-current-time or something similar?

Something along those lines would probably be the most straightforward.
Light testing with the command below suggests overriding current-time is
sufficient:

    (defun my-org-todo-time-machine ()
      (interactive)
      (cl-letf (((symbol-function 'current-time)
                 (lambda ()
                   (apply #'encode-time (org-parse-time-string
                                         "2019-11-27 Mi 16:44")))))
        (call-interactively #'org-todo)))

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

* Re: How to mark task as done at specified (past) time?
  2019-12-12  3:26 ` Kyle Meyer
@ 2020-07-08 20:50   ` Tim Landscheidt
  2020-07-09  2:56     ` Kyle Meyer
  0 siblings, 1 reply; 4+ messages in thread
From: Tim Landscheidt @ 2020-07-08 20:50 UTC (permalink / raw)
  To: Kyle Meyer; +Cc: emacs-orgmode

Kyle Meyer <kyle@kyleam.com> wrote a long time ago:

> […]

>> Do I have to cl-flet org-current-time or something similar?

> Something along those lines would probably be the most straightforward.
> Light testing with the command below suggests overriding current-time is
> sufficient:

>     (defun my-org-todo-time-machine ()
>       (interactive)
>       (cl-letf (((symbol-function 'current-time)
>                  (lambda ()
>                    (apply #'encode-time (org-parse-time-string
>                                          "2019-11-27 Mi 16:44")))))
>         (call-interactively #'org-todo)))

I finally got around to this and ended up with an entry in
gnus-select-article-hook à la:

| (lambda nil
|   (if
|       (and
|        (string= gnus-newsgroup-name "mail.only.this.group")
|        (string-match "^Regular expression that matches subject$"
|                      (gnus-summary-article-subject)))
|       (let
|           ((article-time
|             (gnus-date-get-time
|              (mail-header-date
|               (gnus-summary-article-header)))))
|         (cl-letf
|             (((symbol-function 'current-time)
|               (lambda nil article-time)))
|           (find-file "/path/to/file.org")
|           (goto-char
|            (org-find-entry-with-id "TASK-ID"))
|           (org-todo 'done)))))

I have an icky feeling about cl-letfing current-time because
Murphy might cause a timer to fire in just that time frame
and I have no idea what current-time is for that timer; so
if future org-mode releases would provide a cleaner API I
would very much appreciate that :-).

Thanks,
Tim


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

* Re: How to mark task as done at specified (past) time?
  2020-07-08 20:50   ` Tim Landscheidt
@ 2020-07-09  2:56     ` Kyle Meyer
  0 siblings, 0 replies; 4+ messages in thread
From: Kyle Meyer @ 2020-07-09  2:56 UTC (permalink / raw)
  To: Tim Landscheidt; +Cc: emacs-orgmode

Tim Landscheidt writes:

> I have an icky feeling about cl-letfing current-time because
> Murphy might cause a timer to fire in just that time frame
> and I have no idea what current-time is for that timer; so
> if future org-mode releases would provide a cleaner API I
> would very much appreciate that :-).

Murphy would need to do something pretty invasive to get the timer to
execute in that scope, I think.  (Not relevant for this context, but
threads don't play nicely with cl-letf; if you cl-letf bind a function
definition in one thread and then yield execution to another, the second
thread can see the cl-letf binding.)

Anyway, I'd be glad to see API proposals (backward-compatibility
concerns aside).


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

end of thread, other threads:[~2020-07-09  2:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-11-28 10:57 How to mark task as done at specified (past) time? Tim Landscheidt
2019-12-12  3:26 ` Kyle Meyer
2020-07-08 20:50   ` Tim Landscheidt
2020-07-09  2:56     ` Kyle Meyer

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).