emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Org mode repeated dates to do spaced learning


From: Andrea Giugliano
Subject: Re: [O] Org mode repeated dates to do spaced learning
Date: Sun, 6 Jan 2019 17:17:23 +0000

Hi there,

That was a very helpful suggestion. At the bottom of the mail I attached
my first (working) stab at it.

The idea is to have an headline with the :spaced: tag and another tag
maintaining the number of repetition performed so far. At the beginning
I was thinking to use scheduled times instead of a "counter" tag, but it
was not worth the complexity of the code.

If anybody else finds this feature useful, what would be the best way
to share this?

#+begin_src elisp
(defun my/space-repeat-if-tag-spaced (e)
  "Resets the header on the TODO states and increases the scheduled date
according to a suggested spaced repetition interval."
  (let* ((spaced-rep-map '((0 . "++1d")
                          (1 . "++2d")
                          (2 . "++10d")
                          (3 . "++30d")
                          (4 . "++60d")
                          (5 . "++4m")))
         (spaced-key "spaced")
         (tags (org-get-tags nil t))
         (spaced-todo-p (member spaced-key tags))
         (repetition-n (first (cdr spaced-todo-p)))
         (n+1 (if repetition-n (+ 1 (string-to-number (substring repetition-n 
(- (length repetition-n) 1) (length repetition-n)))) 0))
         (spaced-repetition-p (alist-get n+1 spaced-rep-map))
         (new-repetition-tag (concat "repetition" (number-to-string n+1)))
         (new-tags (reverse (if repetition-n
                                (seq-reduce
                                 (lambda (a x) (if (string-equal x 
repetition-n) (cons new-repetition-tag a) (cons x a)))
                                 tags
                                 '())
                              (seq-reduce
                               (lambda (a x) (if (string-equal x spaced-key) 
(cons new-repetition-tag (cons x a)) (cons x a)))
                               tags
                               '())))))
    (if (and spaced-todo-p spaced-repetition-p)
      (progn
          ;; avoid infinitive looping
          (remove-hook 'org-trigger-hook 'my/space-repeat-if-tag-spaced)
          ;; reset to previous state
          (org-call-with-arg 'org-todo 'left)
          ;; schedule to next spaced repetition
          (org-schedule nil (alist-get n+1 spaced-rep-map))
          ;; rewrite local tags
          (org-set-tags new-tags)
          (add-hook 'org-trigger-hook 'my/space-repeat-if-tag-spaced))
        )))

(add-hook 'org-trigger-hook 'my/space-repeat-if-tag-spaced)
#+end_src


Thanks,

Andrea




On Wed 02 Jan 2019 at 05:59, Marcin Borkowski <address@hidden> wrote:

> On 2019-01-01, at 17:34, Andrea Giugliano <address@hidden> wrote:
>
>> Hi,
>>
>> Thanks for your reply. You are right org-drill does spaced repetition. I
>> just was unclear: I would like to see that in the agenda as a normal
>> item (that gets space-repeated every time I mark it DONE though).
>> I could not get from the docs if org-drill does that.
>
> That is an interesting idea.  I am pretty sure you could make it happen
> with `org-trigger-hook' or `org-after-todo-state-change-hook' (I am not
> entirely sure why both exist, btw).
>
>> Thanks,
>>
>> Andrea
>
> Hth,



reply via email to

[Prev in Thread] Current Thread [Next in Thread]