EDIT
Actually, due to advices it quite easy to 'adapt' evil-delete
as follows:
(advice-add 'evil-delete :around #'org-evil-delete-adv)
(defun org-evil-delete-adv (fn beg end &rest args)
(let ((on-folded-headline (and (eq major-mode 'org-mode)
(org-at-heading-p)
(org-fold-folded-p (line-end-position)))))
(when on-folded-headline
(setq end (line-end-position))
(org-show-subtree))
(apply fn beg end args)
(when on-folded-headline
(org-fold-hide-subtree))))
After evaluating the code above code, you should get the behavior you ask for. However, I am not sure if that advice breaks some other evil functionality.
END EDIT
The behavior of killing the children in Emacs (state) is similar when using kill-line
. The cumbersome way to fix it, is to define a custom motion (or redefine the evil-end-of-line
motion) to not kill the 'folded part', e.g. by defining end of line on an org-headline via next-property-change
.
The easy and straightforward solution is to define a very simple keyboard macro for it, and use it for killing (to the end of) a headline. When recording the macro, simply start from the folded headline, unfold it first, kill (to the end of) the line, and fold again. You can find plenty of info about defining vim keyboard macro's on the web.
Subsequently, you could save the macro and bind it to your preferred key sequence. Info about saving a keyboard macro you can find in the Emacs manual here. It works the same for evil macro's that, despite being evil, prevent killing children.