* Insert subheading at top respect content
@ 2019-08-16 8:12 Nathan Neff
2019-08-16 9:03 ` Carsten Dominik
0 siblings, 1 reply; 7+ messages in thread
From: Nathan Neff @ 2019-08-16 8:12 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 558 bytes --]
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 subheading
to be inserted at line 5.
1* Heading
:PROPERTIES:...
2 Some content
3 More content
4
5** Subheading 1
6** Subheading 2
7
I know there's org-insert-subheading and C-u which respects content, but
respect-content will insert a subheading at line 7 in the example above. I
would
like to have a new subheading at line 4.
Thanks,
--Nate
[-- Attachment #2: Type: text/html, Size: 870 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Insert subheading at top respect content
2019-08-16 8:12 Insert subheading at top respect content Nathan Neff
@ 2019-08-16 9:03 ` Carsten Dominik
2019-08-20 22:42 ` Nathan Neff
0 siblings, 1 reply; 7+ messages in thread
From: Carsten Dominik @ 2019-08-16 9:03 UTC (permalink / raw)
To: Nathan Neff; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 719 bytes --]
On Fri, Aug 16, 2019 at 10:21 AM Nathan Neff <nathan.neff@gmail.com> 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 subheading
> to be inserted at line 5.
>
> 1* Heading
> :PROPERTIES:...
> 2 Some content
> 3 More content
> 4
> 5** Subheading 1
> 6** Subheading 2
> 7
> I know there's org-insert-subheading and C-u which respects content, but
> respect-content will insert a subheading at line 7 in the example above.
> I would
> like to have a new subheading at line 4.
>
What about C-c C-n M-RET
Carsten
>
> Thanks,
> --Nate
>
[-- Attachment #2: Type: text/html, Size: 1517 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Insert subheading at top respect content
2019-08-16 9:03 ` Carsten Dominik
@ 2019-08-20 22:42 ` Nathan Neff
2019-08-21 1:43 ` Nathan Neff
2019-08-21 5:28 ` Carsten Dominik
0 siblings, 2 replies; 7+ messages in thread
From: Nathan Neff @ 2019-08-20 22:42 UTC (permalink / raw)
To: Carsten Dominik; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1442 bytes --]
On Fri, Aug 16, 2019 at 4:03 AM Carsten Dominik <dominik@uva.nl> wrote:
>
>
> On Fri, Aug 16, 2019 at 10:21 AM Nathan Neff <nathan.neff@gmail.com>
> 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
>> subheading
>> to be inserted at line 5.
>>
>> 1* Heading
>> :PROPERTIES:...
>> 2 Some content
>> 3 More content
>> 4
>> 5** Subheading 1
>> 6** Subheading 2
>> 7
>> I know there's org-insert-subheading and C-u which respects content, but
>> respect-content will insert a subheading at line 7 in the example above.
>> I would
>> like to have a new subheading at line 4.
>>
>
> What about C-c C-n M-RET
>
Thanks 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" arg
to org-next-visible-heading - I have hard-coded a 1 in the
above example, but this produces the following subheading:
* Heading <-exec when cursor on this heading
Some content about Heading
*** New heading is inserted here (and is the wrong level - should be 2
instead of 3)
** Sub1
** Sub2
I will mess with this function a bit and post if I find a solution.
Thanks,
--Nate
>
> Carsten
>
>
>>
>> Thanks,
>> --Nate
>>
>
[-- Attachment #2: Type: text/html, Size: 3154 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Insert subheading at top respect content
2019-08-20 22:42 ` Nathan Neff
@ 2019-08-21 1:43 ` Nathan Neff
2019-08-21 5:28 ` Carsten Dominik
1 sibling, 0 replies; 7+ messages in thread
From: Nathan Neff @ 2019-08-21 1:43 UTC (permalink / raw)
To: Carsten Dominik; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1608 bytes --]
On Tue, Aug 20, 2019 at 5:42 PM Nathan Neff <nathan.neff@gmail.com> wrote:
>
>
> On Fri, Aug 16, 2019 at 4:03 AM Carsten Dominik <dominik@uva.nl> wrote:
>
>>
>>
>> On Fri, Aug 16, 2019 at 10:21 AM Nathan Neff <nathan.neff@gmail.com>
>> 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
>>> subheading
>>> to be inserted at line 5.
>>>
>>> 1* Heading
>>> :PROPERTIES:...
>>> 2 Some content
>>> 3 More content
>>> 4
>>> 5** Subheading 1
>>> 6** Subheading 2
>>> 7
>>> I know there's org-insert-subheading and C-u which respects content, but
>>> respect-content will insert a subheading at line 7 in the example
>>> above. I would
>>> like to have a new subheading at line 4.
>>>
>>
>> What about C-c C-n M-RET
>>
>
> Thanks 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" arg
> to org-next-visible-heading - I have hard-coded a 1 in the
> above example, but this produces the following subheading:
>
> * Heading <-exec when cursor on this heading
> Some content about Heading
> *** New heading is inserted here (and is the wrong level - should be 2
> instead of 3)
> ** Sub1
> ** Sub2
>
> I will mess with this function a bit and post if I find a solution.
>
> Thanks,
> --Nate
>
>>
>> Carsten
>>
>>
>>>
>>> Thanks,
>>> --Nate
>>>
>>
[-- Attachment #2: Type: text/html, Size: 3596 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Insert subheading at top respect content
2019-08-20 22:42 ` Nathan Neff
2019-08-21 1:43 ` Nathan Neff
@ 2019-08-21 5:28 ` Carsten Dominik
2019-08-22 19:13 ` Nathan Neff
1 sibling, 1 reply; 7+ messages in thread
From: Carsten Dominik @ 2019-08-21 5:28 UTC (permalink / raw)
To: Nathan Neff; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 2624 bytes --]
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, the
new heading is created with the level of the next headline, and that
next headline might be a sibling, a child or a parent. So we need to
explicitly 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 will
do everything correct, also with stuff like org-odd-levels only etc.
Hope this helps.
- Carsten
On Wed, Aug 21, 2019 at 12:43 AM Nathan Neff <nathan.neff@gmail.com> wrote:
>
>
> On Fri, Aug 16, 2019 at 4:03 AM Carsten Dominik <dominik@uva.nl> wrote:
>
>>
>>
>> On Fri, Aug 16, 2019 at 10:21 AM Nathan Neff <nathan.neff@gmail.com>
>> 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
>>> subheading
>>> to be inserted at line 5.
>>>
>>> 1* Heading
>>> :PROPERTIES:...
>>> 2 Some content
>>> 3 More content
>>> 4
>>> 5** Subheading 1
>>> 6** Subheading 2
>>> 7
>>> I know there's org-insert-subheading and C-u which respects content, but
>>> respect-content will insert a subheading at line 7 in the example
>>> above. I would
>>> like to have a new subheading at line 4.
>>>
>>
>> What about C-c C-n M-RET
>>
>
> Thanks 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" arg
> to org-next-visible-heading - I have hard-coded a 1 in the
> above example, but this produces the following subheading:
>
> * Heading <-exec when cursor on this heading
> Some content about Heading
> *** New heading is inserted here (and is the wrong level - should be 2
> instead of 3)
> ** Sub1
> ** Sub2
>
> I will mess with this function a bit and post if I find a solution.
>
> Thanks,
> --Nate
>
>>
>> Carsten
>>
>>
>>>
>>> Thanks,
>>> --Nate
>>>
>>
[-- Attachment #2: Type: text/html, Size: 4754 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Insert subheading at top respect content
2019-08-21 5:28 ` Carsten Dominik
@ 2019-08-22 19:13 ` Nathan Neff
2019-08-22 21:07 ` Carsten Dominik
0 siblings, 1 reply; 7+ messages in thread
From: Nathan Neff @ 2019-08-22 19:13 UTC (permalink / raw)
To: Carsten Dominik; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 3412 bytes --]
On Wed, Aug 21, 2019 at 12:28 AM Carsten Dominik <dominik@uva.nl> wrote:
> Hi Nate,
>
> What do you mean by passing "the right argument". Which argument do you
> want to pass?
>
I mean the hard-coded 1 on org-next-visible-heading.
>
> 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, the
> new heading is created with the level of the next headline, and that
> next headline might be a sibling, a child or a parent. So we need to
> explicitly 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 will
> do everything correct, also with stuff like org-odd-levels only etc.
>
>
Cool! I tried the above solution and made some modifications:
(defun njn-subheading-respect-content ()
(interactive "")
(org-show-children)
(let
((level (car (org-heading-components)))
)
(outline-next-heading)
(org-insert-heading)
(while (<= (car (org-heading-components)) level)
(org-demote))
))
I added (org-show-children) to work when cursor is on a folded heading.
I removed the 1 argument to org-next-visible-heading
This appears to do what I want - thanks for the help!
> Hope this helps.
>
> - Carsten
>
>
>
>
>
> On Wed, Aug 21, 2019 at 12:43 AM Nathan Neff <nathan.neff@gmail.com>
> wrote:
>
>>
>>
>> On Fri, Aug 16, 2019 at 4:03 AM Carsten Dominik <dominik@uva.nl> wrote:
>>
>>>
>>>
>>> On Fri, Aug 16, 2019 at 10:21 AM Nathan Neff <nathan.neff@gmail.com>
>>> 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
>>>> subheading
>>>> to be inserted at line 5.
>>>>
>>>> 1* Heading
>>>> :PROPERTIES:...
>>>> 2 Some content
>>>> 3 More content
>>>> 4
>>>> 5** Subheading 1
>>>> 6** Subheading 2
>>>> 7
>>>> I know there's org-insert-subheading and C-u which respects content, but
>>>> respect-content will insert a subheading at line 7 in the example
>>>> above. I would
>>>> like to have a new subheading at line 4.
>>>>
>>>
>>> What about C-c C-n M-RET
>>>
>>
>> Thanks 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" arg
>> to org-next-visible-heading - I have hard-coded a 1 in the
>> above example, but this produces the following subheading:
>>
>> * Heading <-exec when cursor on this heading
>> Some content about Heading
>> *** New heading is inserted here (and is the wrong level - should be 2
>> instead of 3)
>> ** Sub1
>> ** Sub2
>>
>> I will mess with this function a bit and post if I find a solution.
>>
>> Thanks,
>> --Nate
>>
>>>
>>> Carsten
>>>
>>>
>>>>
>>>> Thanks,
>>>> --Nate
>>>>
>>>
[-- Attachment #2: Type: text/html, Size: 6816 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Insert subheading at top respect content
2019-08-22 19:13 ` Nathan Neff
@ 2019-08-22 21:07 ` Carsten Dominik
0 siblings, 0 replies; 7+ messages in thread
From: Carsten Dominik @ 2019-08-22 21:07 UTC (permalink / raw)
To: Nathan Neff; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 3733 bytes --]
You are welcome. Good to hear that you have a good solution now.
Carsten
On Thu, Aug 22, 2019 at 9:14 PM Nathan Neff <nathan.neff@gmail.com> wrote:
>
>
> On Wed, Aug 21, 2019 at 12:28 AM Carsten Dominik <dominik@uva.nl> wrote:
>
>> Hi Nate,
>>
>> What do you mean by passing "the right argument". Which argument do you
>> want to pass?
>>
>
> I mean the hard-coded 1 on org-next-visible-heading.
>
>
>>
>> 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, the
>> new heading is created with the level of the next headline, and that
>> next headline might be a sibling, a child or a parent. So we need to
>> explicitly 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 will
>> do everything correct, also with stuff like org-odd-levels only etc.
>>
>>
> Cool! I tried the above solution and made some modifications:
>
> (defun njn-subheading-respect-content ()
> (interactive "")
> (org-show-children)
> (let
> ((level (car (org-heading-components)))
> )
> (outline-next-heading)
> (org-insert-heading)
> (while (<= (car (org-heading-components)) level)
> (org-demote))
> ))
>
>
> I added (org-show-children) to work when cursor is on a folded heading.
>
> I removed the 1 argument to org-next-visible-heading
>
> This appears to do what I want - thanks for the help!
>
>
>
>
>> Hope this helps.
>>
>> - Carsten
>>
>>
>>
>>
>>
>> On Wed, Aug 21, 2019 at 12:43 AM Nathan Neff <nathan.neff@gmail.com>
>> wrote:
>>
>>>
>>>
>>> On Fri, Aug 16, 2019 at 4:03 AM Carsten Dominik <dominik@uva.nl> wrote:
>>>
>>>>
>>>>
>>>> On Fri, Aug 16, 2019 at 10:21 AM Nathan Neff <nathan.neff@gmail.com>
>>>> 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
>>>>> subheading
>>>>> to be inserted at line 5.
>>>>>
>>>>> 1* Heading
>>>>> :PROPERTIES:...
>>>>> 2 Some content
>>>>> 3 More content
>>>>> 4
>>>>> 5** Subheading 1
>>>>> 6** Subheading 2
>>>>> 7
>>>>> I know there's org-insert-subheading and C-u which respects content,
>>>>> but
>>>>> respect-content will insert a subheading at line 7 in the example
>>>>> above. I would
>>>>> like to have a new subheading at line 4.
>>>>>
>>>>
>>>> What about C-c C-n M-RET
>>>>
>>>
>>> Thanks 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" arg
>>> to org-next-visible-heading - I have hard-coded a 1 in the
>>> above example, but this produces the following subheading:
>>>
>>> * Heading <-exec when cursor on this heading
>>> Some content about Heading
>>> *** New heading is inserted here (and is the wrong level - should be 2
>>> instead of 3)
>>> ** Sub1
>>> ** Sub2
>>>
>>> I will mess with this function a bit and post if I find a solution.
>>>
>>> Thanks,
>>> --Nate
>>>
>>>>
>>>> Carsten
>>>>
>>>>
>>>>>
>>>>> Thanks,
>>>>> --Nate
>>>>>
>>>>
[-- Attachment #2: Type: text/html, Size: 6986 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-08-22 21:07 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-08-16 8:12 Insert subheading at top respect content Nathan Neff
2019-08-16 9:03 ` Carsten Dominik
2019-08-20 22:42 ` Nathan Neff
2019-08-21 1:43 ` Nathan Neff
2019-08-21 5:28 ` Carsten Dominik
2019-08-22 19:13 ` Nathan Neff
2019-08-22 21:07 ` Carsten Dominik
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).