From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carsten Dominik Subject: Re: Insert subheading at top respect content Date: Thu, 22 Aug 2019 23:07:33 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000000193870590bb1563" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:35792) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0uJE-00051p-Oz for emacs-orgmode@gnu.org; Thu, 22 Aug 2019 17:07:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i0uJD-000123-9y for emacs-orgmode@gnu.org; Thu, 22 Aug 2019 17:07:52 -0400 Received: from mail-ed1-f44.google.com ([209.85.208.44]:44530) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i0uJD-00010s-0v for emacs-orgmode@gnu.org; Thu, 22 Aug 2019 17:07:51 -0400 Received: by mail-ed1-f44.google.com with SMTP id a21so9932801edt.11 for ; Thu, 22 Aug 2019 14:07:50 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Nathan Neff Cc: emacs-orgmode --0000000000000193870590bb1563 Content-Type: text/plain; charset="UTF-8" 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 wrote: > > > On Wed, Aug 21, 2019 at 12:28 AM Carsten Dominik 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 >> wrote: >> >>> >>> >>> On Fri, Aug 16, 2019 at 4:03 AM Carsten Dominik wrote: >>> >>>> >>>> >>>> On Fri, Aug 16, 2019 at 10:21 AM Nathan Neff >>>> 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 >>>>> >>>> --0000000000000193870590bb1563 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
You are welcome. Good to hear that you have a good solutio= n now.

Carsten



On= Thu, Aug 22, 2019 at 9:14 PM Nathan Neff <nathan.neff@gmail.com> wrote:


<= div class=3D"gmail_quote">
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".=C2=A0 Which = argument do you want to pass?

I= mean the hard-coded 1 on org-next-visible-heading.
=C2=A0
<= blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l= eft:1px solid rgb(204,204,204);padding-left:1ex">

=
At first, I thought the direct way to fix your function would be=

(defun njn-subheading-respect-content ()
=C2= =A0 (interactive "")
=C2=A0 (org-next-visible-heading 1)
= =C2=A0 (org-insert-heading nil)
=C2=A0)

bec= ause in your original example, the heading did already have a child.
<= div>However, that is not guaranteed, and in the above implementation, the
new heading is created with the level of the next headline, and th= at
next headline might be a sibling, a child or a parent.=C2=A0 S= o we need to
explicitly set the level:

(defun njn-s= ubheading-respect-content ()
=C2=A0 (interactive "")
=C2=A0= (let ((level (car (org-heading-components))))
=C2=A0 =C2=A0 (org-next-v= isible-heading 1)
=C2=A0 =C2=A0 (org-insert-heading nil)
=C2=A0 =C2= =A0 (while (<=3D (car (org-heading-components)) level)
=C2=A0 =C2=A0 = =C2=A0 (org-demote))))

I am using (possibly re= peated) calls to `org-demote', because this will
do everythin= g correct, also with stuff like org-odd-levels only etc.


Cool!=C2=A0 I tried the above solu= tion and made some modifications:

(defun njn-= subheading-respect-content ()
=C2=A0 (interactive ""= ;)
=C2=A0 (org-show-children)
=C2=A0 (let=C2=A0
=C2=A0 =C2=A0 ((level (car (org-heading-components)))
=C2=A0 )=
=C2=A0 =C2=A0 (outline-next-heading)
=C2=A0 =C2=A0 (or= g-insert-heading)
=C2=A0 =C2=A0 (while (<=3D (car (org-heading= -components)) level)
=C2=A0 =C2=A0 =C2=A0 (org-demote))
=C2=A0 ))=C2=A0
=C2=A0

I added (o= rg-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!
<= div>

=C2=A0
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 bee= n an
"Insert subheading, after the content, but before other= subheadings"

For example:
If my cu= rsor is anywhere between lines 1 and 4, I would like the subheading
to be inserted at line 5.

1* Heading
<= div>:PROPERTIES:...
2 Some content
3 More content
4
5** Subheading 1
6** Subheading 2
<= div>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.=C2=A0 I would
like to have a new su= bheading at line 4.

What ab= out C-c C-n M-RET

Thanks = Carsten - I created a function:
(defun njn-subheading-respect-con= tent ()
=C2=A0 (interactive "")
=C2=A0 (org-n= ext-visible-heading 1)
=C2=A0 (org-insert-subheading 't)
=C2=A0)

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 th= e following subheading:

* Heading <-exec when c= ursor on this heading
Some content about Heading
*** Ne= w heading is inserted here (and is the wrong level - should be 2 instead of= 3)
** Sub1
** Sub2
=C2=A0
I will m= ess with this function a bit and post if I find a solution.

<= /div>
Thanks,
--Nate

<= div>Carsten
=C2=A0

Thanks,
--Nate
--0000000000000193870590bb1563--