Piotr Isajew <pisa...@yahoo.com> writes:

> Hi Bastien,
>
> Dnia 29.01.2014 Bastien <b...@gnu.org> napisaƂ/a:
>
>> Piotr Isajew <pisa...@yahoo.com> writes:
>>
>>> For example, when I open .org file I would like to have subtrees
>>> marked as DONE folded, but the others should be opened as with
>>> #+STARTUP: content setting. Can it be done?
>>
>> No.  But you can archive the DONE subtrees with C-c C-x C-a for
>> example.  See "Archiving" in Org's manual.
>
> I haven't thought about archiving so thanks for pointing me to
> this.  In general that could be the solution, but for this case it
> seems too drastic. It would mean excluding DONE subtrees from
> searches and clock reports which I don't want to happen before I
> finish entire project. What I want is just to initially get DONE
> subtrees out of my sight.
>
> I was able to achieve more or less what I wanted by setting
> VISIBILITY property with a hook:
>
> (defun set-visibility-to-folded-when-done()
>   "Change default subtree VISIBILITY to folded when state is changed to DONE"
>   ( when (string= org-state "DONE")
>     (org-set-property "VISIBILITY" "folded"))
> )
> (add-hook 'org-after-todo-state-change-hook
>           'set-visibility-to-folded-when-done)
>

You might want to augment your function slightly with a call to
org-set-startup-visibility:

--8<---------------cut here---------------start------------->8---
(defun set-visibility-to-folded-when-done()
  "Change default subtree VISIBILITY to folded when state is changed to DONE"
  (when (string= org-state "DONE")
    (org-set-property "VISIBILITY" "folded")
    (org-set-startup-visibility)))
--8<---------------cut here---------------end--------------->8---

That will fold the item immediately.

-- 
Nick


Reply via email to