emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Mikhail Skorzhinskiy <mskorzhinskiy@eml.cc>
To: Michael Welle <mwe012008@gmx.net>
Cc: emacs-orgmode@gnu.org
Subject: Re: Temporary cancelling recurring tasks
Date: Thu, 26 Jan 2017 18:13:32 +0300	[thread overview]
Message-ID: <87fuk597mr.fsf@eml.cc> (raw)
In-Reply-To: <87o9yu5cll.fsf@luisa.c0t0d0s0.de>

Take a look to http://karl-voit.at/2017/01/15/org-clone-subtree-with-time-shift/

On 2017-01-26T13:39:50+0300, Michael Welle wrote:

> Hello,
> 
> I want to temporary cancel recurring tasks. Let's say I have tasks, that
> only make sense when I'm in my office. Now I'm away for a few months.
> The tasks would clutter my agenda. I could comment them, archive them or
> use org-cancel-repeater and set the task's state to DONE. But all that
> makes it hard to restore the previous state when I'm back in my office.
> 
> I think, the clean solution is to set the state of the task to CANCELLED
> or STOPPED or something like that, to deactivate the recurring task.
> When I activate the task again, the scheduled date and the repeater
> should be restored. To achieve that, I tried the following:
> 
> 
> ;;
> ;; Deactivate/Activate recurring tasks
> ;;
> 
> 
> ;; Prior to Org commit 7d52a8c3cc86c8ce03eda006752af1ab4bed4316
> ;; there seems to be no way to set the repeater of a, let's say,
> ;; SCHEDULED property programmatically. So we use this function.
> (defun hmw/org-schedule-set-value (val)
>   "Sets the value of the SCHEDULED property. This allows for
> setting the repeater as well."
>   (interactive)
>   (save-excursion
>     (org-back-to-heading t)
>     (let ((bound1 (point))
> 	  (bound0 (save-excursion (outline-next-heading) (point))))
>       (when (re-search-forward
> 	     (concat "\\(" org-scheduled-time-regexp "\\)")
> 	     bound0 t)
> 	(replace-match val t nil nil 2)))))
> 
> (defvar hmw/org-scheduled-property-backup "DISABLED-SCHEDULED"
>   "Back up the original value of the SCHEDULED property into this
> property when deactivating a recurring task. The value is rescued from
> this property to initialise the SCHEDULED property when activating the
> task again.")
> 
> (defvar hmw/org-activated-recurring-task-state "TODO"
>   "Switch a recurring task to this state after activating.")
> 
> (defvar hmw/org-deactivated-recurring-task-state "CANCELLED"
>   "Switch a recurring task to this state after deactivating.")
> 
> (defun hmw/org-deactivate-recurring-task ()
>   "Deactivate a recurring task. The value of the SCHEDULED property is
> stored in the property referenced by `hmw/org-scheduled-property-backup',
> so it can be restored later. The task's state is set to the value of
> `hmw/org-deactivated-recurring-task-state'." 
>   (interactive)
>   (when (org-entry-is-todo-p)
>     (save-excursion
>       (org-back-to-heading t)
>       (let* ((pom (point-at-bol))
>              (val (org-entry-get pom "SCHEDULED")))
>         (when val
> 	  ;; Remove the time stamp meaning. We don't want active
> 	  ;; timestamp to trigger any actions for the deactivated
> 	  ;; task.
> 	  (setq val (replace-regexp-in-string "^<\\(.*\\)>$" "\\1" val))
> 	  (org-entry-put pom hmw/org-scheduled-property-backup val)
> 	  (org-entry-put pom "SCHEDULED" nil)
> 	  (org-todo hmw/org-deactivated-recurring-task-state))))))
> 
> (defun hmw/org-activate-recurring-task ()
>   "Activate a previously deactivated recurring task. The value of the
> SCHEDULED property is retrieved from the property referenced by
> `hmw/org-scheduled-property-backup', which is then deleted. The task's 
> state is set to the value of `hmw/org-activated-recurring-task-state'."
>   (interactive)
>   (when (org-entry-is-done-p)
>     (save-excursion
>       (org-back-to-heading t)
>       (let* ((pom (point-at-bol))
>              (val (org-entry-get pom hmw/org-scheduled-property-backup)))
>         (when val
> 	  ;; For Org commit 7d52a8c3cc86c8ce03eda006752af1ab4bed4316 or
> 	  ;; later use this
> 	  ;;(setq val (replace-regexp-in-string "^\\(.*\\)$" "<\\1>" val))
> 	  ;;(org-entry-put pom "SCHEDULED" val)
> 	  
> 	  ;; For older Org use this
> 	  (org-entry-put pom "SCHEDULED" val)
> 	  (hmw/org-schedule-set-value val)
>           
> 	  (org-entry-delete pom hmw/org-scheduled-property-backup)
> 	  (org-todo hmw/org-activated-recurring-task-state))))))
>  
> 
> The idea is to store the value of the SCHEDULED property somewhere when
> the task gets deactivated. Later, on activation, the property value is
> restored.
> 
> There are two variants. The one above, which should work for Org prior
> to commit 7d52a8c3cc86c8ce03eda006752af1ab4bed4316 and also for later
> revisions. And one for that commit and later. If you use the newer Org
> revision, you optionally can get rid of the function
> hw/org-schedule-set-value and follow the comments in
> hmw/org-activate-recurring-task.
> 
> Regards
> hmw
> 


-- 
Skorzhinskiy Mikhail

  parent reply	other threads:[~2017-01-26 15:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-26 10:39 Temporary cancelling recurring tasks Michael Welle
2017-01-26 14:41 ` Nick Dokos
2017-01-26 15:14   ` Michael Welle
2017-01-26 15:13 ` Mikhail Skorzhinskiy [this message]
2017-01-26 15:24   ` Michael Welle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fuk597mr.fsf@eml.cc \
    --to=mskorzhinskiy@eml.cc \
    --cc=emacs-orgmode@gnu.org \
    --cc=mwe012008@gmx.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).