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

Exclude sub-headline #146

Closed randomwangran closed 2 years ago

randomwangran commented 2 years ago

Hi Nobiot:

Currently, if the users would like to transclude a node, all children of the heading will be also transcluded. This is very useful.

In another use case, for example, the user would like to exclude the children. There is no feature for doing this at this moment. Correct me if I am wrong. For example, a Ph.D. student wrote how he used Org-transclusion in this post. If he wants to transclude a figure but does not want to include his thoughts, it would be very difficult to do it.

An ideal workflow would be to check the tag of the headline. If a the heading contains :noexport:, then this heading should be excluded.

I was wondering if this is an interesting feature for you?

I happen to find the following elisp code to copy the information within the heading but not the child headings. Not sure how to incorporate it in Org-transclusion's excluding mechanism.

(defun my-org-copy-subtree-contents ()
  "Get the content text of the subtree at point and add it to the `kill-ring'.
Excludes the heading and any child subtrees.
see <https://hungyi.net/posts/org-mode-subtree-contents>"
  (interactive)
  (if (org-before-first-heading-p)
      (message "Not in or on an org heading")
    (save-excursion
      ;; If inside heading contents, move the point back to the heading
      ;; otherwise `org-agenda-get-some-entry-text' won't work.
      (unless (org-on-heading-p) (org-previous-visible-heading 1))
      (let ((contents (substring-no-properties
                       (org-agenda-get-some-entry-text
                        (point-marker)
                        most-positive-fixnum))))
        (message "Copied: %s" contents)
        (kill-new contents)))))
nobiot commented 2 years ago

In another use case, for example, the user would like to exclude the children. There is no feature for doing this at this moment.

There is a feature to exclude children (sub-headlines). Could you try :exclude-elements "headline" and see if it does what you are aiming to do? Perhaps I need to improve documentation -- it was part of one of the recent videos.

randomwangran commented 2 years ago

My bad.

Thanks for pointing out this one.

The manual is very clear about this indeed. Sorry about that.

4.4.1 Notes on excluding the headline element

If you add ‘headline’ as a list of elements to exclude, you exclude
sub-headlines within your subtrees and you will still transclude the
content of the top-most headline of the subtrees.