|
From: | Nathan Neff |
Subject: | Re: [O] Insert subheading at top respect content |
Date: | Thu, 22 Aug 2019 14:13:51 -0500 |
Hi Nate,What do you mean by passing "the right argument". Which argument do you want to pass?
At first, I thought the direct way to fix your function would be(defun njn-subheading-respect-content ()
(interactive "")
(org-next-visible-heading 1)
(org-insert-heading nil)
)because in your original example, the heading did already have a child.However, that is not guaranteed, and in the above implementation, thenew heading is created with the level of the next headline, and thatnext headline might be a sibling, a child or a parent. So we need toexplicitly set the level:
(defun njn-subheading-respect-content ()
(interactive "")
(let ((level (car (org-heading-components))))
(org-next-visible-heading 1)
(org-insert-heading nil)
(while (<= (car (org-heading-components)) level)
(org-demote))))I am using (possibly repeated) calls to `org-demote', because this willdo everything correct, also with stuff like org-odd-levels only etc.
Hope this helps.- CarstenOn Wed, Aug 21, 2019 at 12:43 AM Nathan Neff <address@hidden> wrote:On Fri, Aug 16, 2019 at 4:03 AM Carsten Dominik <address@hidden> wrote:On Fri, Aug 16, 2019 at 10:21 AM Nathan Neff <address@hidden> wrote:Hello all,Something that's eluded me all this time has been an"Insert subheading, after the content, but before other subheadings"For example:If my cursor is anywhere between lines 1 and 4, I would like the subheadingto be inserted at line 5.1* Heading:PROPERTIES:...2 Some content3 More content45** Subheading 16** Subheading 27I know there's org-insert-subheading and C-u which respects content, butrespect-content will insert a subheading at line 7 in the example above. I wouldlike to have a new subheading at line 4.What about C-c C-n M-RETThanks Carsten - I created a function:(defun njn-subheading-respect-content ()(interactive "")(org-next-visible-heading 1)(org-insert-subheading 't))But I'm trying to find out where to get the "correct" argto org-next-visible-heading - I have hard-coded a 1 in theabove example, but this produces the following subheading:* Heading <-exec when cursor on this headingSome content about Heading*** New heading is inserted here (and is the wrong level - should be 2 instead of 3)** Sub1** Sub2I will mess with this function a bit and post if I find a solution.Thanks,--NateCarstenThanks,--Nate
[Prev in Thread] | Current Thread | [Next in Thread] |