nobiot / org-transclusion

Emacs package to enable transclusion with Org Mode
https://nobiot.github.io/org-transclusion/
GNU General Public License v3.0
917 stars 44 forks source link

[Feature request] Support removing todo-keywords from the transcluded text #149

Open lhernanz opened 2 years ago

lhernanz commented 2 years ago

Very often I transclude fragments that include TODO elements in them. The core use case is that I have a template for a daily review that is a TODO item itself and I want the template to be used as part of my journal file when I am doing the review. I still want my original header to be a TODO item so that it still shows up in the agenda until I mark it as complete.

As both the original file and the destination are part of org-agenda-files, though, org-agenda gets confused by the duplicate (I am not entirely sure why) and it breaks.

Therefore, I would love to have a similar flag as only-contents that would remove all the todo-keywords from the transcluded text.

The filtering function would be similar to this. The headline and the content is preserved, just the TODO keyword is removed from the output

(defun org-transclusion-content-filter-org-remove-todo (data)
  "Exclude todo-keywords from the headlines from DATA"
  (if (eq (org-element-type data) 'headline)
        (progn
          (if (org-element-property :todo-keyword data)
              (org-element-put-property data :todo-keyword nil)
            )
          (org-element-set-contents (org-element-copy data) nil)
          )
      data))

Thanks!

nobiot commented 2 years ago

If I added a hook or some way to let users to add their own filter in a new branch, would you be able to customize your own filter -- looks like you can by the sample code added above.

I have been meaning to add this for some time -- I cannot add filter for every single request. I may not be able to do this quickly -- I have a major life event in October, so I've been postponing major updates to Nov/Dec this year. But I might be able to try a new branch and do some experiment there...

lhernanz commented 2 years ago

Thanks for the fast response!

Yes, having a generic filtering mechanism where you can define new filters would be amazing. You could even move the only-contents implementation to the new system to have a first use case. As adding new keywords in your model seems to be expensive (there are referenced in several places), maybe adding a :filters keyword that works similar to the :exclude-elements one would be an interesting venue to explore. In that way, you could so something similar to the following:

#+transclude: [[id:%{template-id}][Review Template]] :level 3 :exclude-elements "clock drawer keyword planning src-block" :filters "only-contents remove-todo"

Any timing is good for me. For the moment, I have just redefined the only-contents function to remove the todos as I do not have a need for the only-contents functionality. Thanks!

lhernanz commented 2 years ago

I updated my naive implementation above after being affected by the same problem as #125 with the duplicate headings. Let's see if the new one works properly.