emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* behavior of (org-insert-heading-respect-content)
@ 2021-09-09 14:55 Victor A. Stoichita
  2021-09-09 18:54 ` Marco Wahl
  0 siblings, 1 reply; 9+ messages in thread
From: Victor A. Stoichita @ 2021-09-09 14:55 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

I see the following behavior which seems erroneous to me :
- When I issue (org-insert-heading-respect-content) in a brand new org
  buffer, with point at point-min I get the error "Beginning of buffer"
  and no heading is inserted.
- If I write something on the 1st line, say "test", but no newline, and
  then issue (org-insert-heading-respect-content), the result is :
  "test  * " which is not a properly formatted heading
- Only if there is a newline before point does
  (org-insert-heading-respect-content) insert a proper heading. 

Am I getting something wrong or is this a bug ?

Regards,
Victor


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: behavior of (org-insert-heading-respect-content)
  2021-09-09 14:55 behavior of (org-insert-heading-respect-content) Victor A. Stoichita
@ 2021-09-09 18:54 ` Marco Wahl
  2021-09-09 19:29   ` Victor A. Stoichita
  0 siblings, 1 reply; 9+ messages in thread
From: Marco Wahl @ 2021-09-09 18:54 UTC (permalink / raw)
  To: Victor A. Stoichita; +Cc: emacs-orgmode

Hi!

"Victor A. Stoichita" <victor@svictor.net> writes:

> I see the following behavior which seems erroneous to me :
> - When I issue (org-insert-heading-respect-content) in a brand new org
>   buffer, with point at point-min I get the error "Beginning of buffer"
>   and no heading is inserted.
> - If I write something on the 1st line, say "test", but no newline, and
>   then issue (org-insert-heading-respect-content), the result is :
>   "test  * " which is not a properly formatted heading
> - Only if there is a newline before point does
>   (org-insert-heading-respect-content) insert a proper heading. 
>
> Am I getting something wrong or is this a bug ?

I think so.

My impression is that org-insert-heading-respect-content should be
called only with point in a subtree.

The fix would be to signal an error when point is not located in a
subtree.

Does this sound reasonable?









^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: behavior of (org-insert-heading-respect-content)
  2021-09-09 18:54 ` Marco Wahl
@ 2021-09-09 19:29   ` Victor A. Stoichita
  2021-09-13 19:21     ` Marco Wahl
  0 siblings, 1 reply; 9+ messages in thread
From: Victor A. Stoichita @ 2021-09-09 19:29 UTC (permalink / raw)
  To: Marco Wahl; +Cc: emacs-orgmode


Le 09 Sep 2021, Marco Wahl <marcowahlsoft@gmail.com> a écrit :

> My impression is that org-insert-heading-respect-content should be
> called only with point in a subtree.
>
> The fix would be to signal an error when point is not located in a
> subtree.
>
> Does this sound reasonable?

In a way, yes. I guess that the error would not appear too often.
But falling back gracefully to org-insert-heading could be even
better, especially when org-insert-heading-respect-content is called
from Lisp (rather than interactively).

For now, I use this and it seems to do the job:

#+begin_src elisp
  (if (equal 1 (line-number-at-pos nil t))
        (org-insert-heading)
      (org-insert-heading-respect-content))
#+end_src

If I’m not mistaken, org-insert-heading-respect-content works as expected even when point is not in a subtree. It seems to only fail if point is on the 1st line. 

Regards,
Victor


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: behavior of (org-insert-heading-respect-content)
  2021-09-09 19:29   ` Victor A. Stoichita
@ 2021-09-13 19:21     ` Marco Wahl
  2021-09-17 15:23       ` Victor A. Stoichita
  0 siblings, 1 reply; 9+ messages in thread
From: Marco Wahl @ 2021-09-13 19:21 UTC (permalink / raw)
  To: Victor A. Stoichita; +Cc: emacs-orgmode

Hi Victor,

> Le 09 Sep 2021, Marco Wahl <marcowahlsoft@gmail.com> a écrit :
>
>> My impression is that org-insert-heading-respect-content should be
>> called only with point in a subtree.
>>
>> The fix would be to signal an error when point is not located in a
>> subtree.
>>
>> Does this sound reasonable?
>
> In a way, yes. I guess that the error would not appear too often.
> But falling back gracefully to org-insert-heading could be even
> better, especially when org-insert-heading-respect-content is called
> from Lisp (rather than interactively).
>
> For now, I use this and it seems to do the job:
>
> #+begin_src elisp
>   (if (equal 1 (line-number-at-pos nil t))
>         (org-insert-heading)
>       (org-insert-heading-respect-content))
> #+end_src
>
> If I’m not mistaken, org-insert-heading-respect-content works as
> expected even when point is not in a subtree. It seems to only fail if
> point is on the 1st line.

As far is I see it, the intended behavior of
org-insert-heading-respect-content with point before the first heading
is to

- insert the new heading immediately before the first heading.  Respect
  the content!

- If there is no heading at all in the file the heading shall be
  inserted at the bottom of the file.

Do we agree on the desired behavior of
org-insert-heading-respect-content?

With your proposition the respect for the content gets lost, doesn't it?


Ciao!


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: behavior of (org-insert-heading-respect-content)
  2021-09-13 19:21     ` Marco Wahl
@ 2021-09-17 15:23       ` Victor A. Stoichita
  2021-09-18 13:08         ` Marco Wahl
  0 siblings, 1 reply; 9+ messages in thread
From: Victor A. Stoichita @ 2021-09-17 15:23 UTC (permalink / raw)
  To: Marco Wahl; +Cc: emacs-orgmode


Le 13 Sep 2021, Marco Wahl <marcowahlsoft@gmail.com> a écrit :

> As far is I see it, the intended behavior of
> org-insert-heading-respect-content with point before the first heading
> is to
>
> - insert the new heading immediately before the first heading.  Respect
>   the content!
Hi Marco !

I agree with you. But this does not work. Say I have a buffer with this content :

--8<---------------cut here---------------start------------->8---
put point HERE and C-<return>
Some more stuff 
* Heading
content
--8<---------------cut here---------------end--------------->8---

When point is at HERE and I C-<return>, org inserts a new asterisk on
the after "stuff", but  on the same line → not a proper heading.
>
> - If there is no heading at all in the file the heading shall be
>   inserted at the bottom of the file.

Yes. But I get the same behavior with 
--8<---------------cut here---------------start------------->8---
put point HERE and C-<return>
Some more stuff 
--8<---------------cut here---------------end--------------->8---

The asterisk is inserted right after "stuff", on the same line → not
a proper heading.

>
> Do we agree on the desired behavior of
> org-insert-heading-respect-content?

Yes, we do!
>
> With your proposition the respect for the content gets lost,
> doesn't it?

Yes, you’re right. It currently does not respect the content before
first heading. Therefore it’s not a fix for the behavior of
org-insert-heading-respect-content.
It’s just the quickest workaround I’ve come up with to make my own
function work (in my use-case, when I call that function, either point
is at point-min in a brand new buffer, or point is below the first
heading).

Regards,
Victor



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: behavior of (org-insert-heading-respect-content)
  2021-09-17 15:23       ` Victor A. Stoichita
@ 2021-09-18 13:08         ` Marco Wahl
  2021-09-26 11:13           ` Bastien
  0 siblings, 1 reply; 9+ messages in thread
From: Marco Wahl @ 2021-09-18 13:08 UTC (permalink / raw)
  To: Victor A. Stoichita; +Cc: emacs-orgmode

Victor!

> Le 13 Sep 2021, Marco Wahl <marcowahlsoft@gmail.com> a écrit :
>
>> As far is I see it, the intended behavior of
>> org-insert-heading-respect-content with point before the first heading
>> is to
>>
>> - insert the new heading immediately before the first heading.  Respect
>>   the content!
> Hi Marco !
>
> I agree with you. But this does not work. Say I have a buffer with this content :
>
> put point HERE and C-<return>
> Some more stuff 
> * Heading
> content
>
>
> When point is at HERE and I C-<return>, org inserts a new asterisk on
> the after "stuff", but  on the same line → not a proper heading.
>>
>> - If there is no heading at all in the file the heading shall be
>>   inserted at the bottom of the file.
>
> Yes. But I get the same behavior with 
>
> put point HERE and C-<return>
> Some more stuff 
>
> The asterisk is inserted right after "stuff", on the same line → not
> a proper heading.
>
>>
>> Do we agree on the desired behavior of
>> org-insert-heading-respect-content?
>
> Yes, we do!
>>
>> With your proposition the respect for the content gets lost,
>> doesn't it?
>
> Yes, you’re right. It currently does not respect the content before
> first heading. Therefore it’s not a fix for the behavior of
> org-insert-heading-respect-content.
> It’s just the quickest workaround I’ve come up with to make my own
> function work (in my use-case, when I call that function, either point
> is at point-min in a brand new buffer, or point is below the first
> heading).

Okay, thanks for clarifying.

Would be great if you could test the fix.


Thank you!


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: behavior of (org-insert-heading-respect-content)
  2021-09-18 13:08         ` Marco Wahl
@ 2021-09-26 11:13           ` Bastien
  2021-09-26 12:13             ` Marco Wahl
  0 siblings, 1 reply; 9+ messages in thread
From: Bastien @ 2021-09-26 11:13 UTC (permalink / raw)
  To: Marco Wahl; +Cc: Victor A. Stoichita, emacs-orgmode

Hi Marco,

Marco Wahl <marcowahlsoft@gmail.com> writes:

> Would be great if you could test the fix.

If you're confident with the fix, please go ahead and push the commit.

Thanks,

-- 
 Bastien


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: behavior of (org-insert-heading-respect-content)
  2021-09-26 11:13           ` Bastien
@ 2021-09-26 12:13             ` Marco Wahl
  2021-09-26 12:31               ` Bastien
  0 siblings, 1 reply; 9+ messages in thread
From: Marco Wahl @ 2021-09-26 12:13 UTC (permalink / raw)
  To: Bastien; +Cc: Victor A. Stoichita, emacs-orgmode

Bastien!

> Marco Wahl <marcowahlsoft@gmail.com> writes:
>
>> Would be great if you could test the fix.
>
> If you're confident with the fix, please go ahead and push the commit.

This has been committed some days ago.  See

    https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=069bcba529142bdb91647258924513f0fb0f3fa1





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: behavior of (org-insert-heading-respect-content)
  2021-09-26 12:13             ` Marco Wahl
@ 2021-09-26 12:31               ` Bastien
  0 siblings, 0 replies; 9+ messages in thread
From: Bastien @ 2021-09-26 12:31 UTC (permalink / raw)
  To: Marco Wahl; +Cc: Victor A. Stoichita, emacs-orgmode

Marco Wahl <marcowahlsoft@gmail.com> writes:

> Bastien!
>
>> Marco Wahl <marcowahlsoft@gmail.com> writes:
>>
>>> Would be great if you could test the fix.
>>
>> If you're confident with the fix, please go ahead and push the commit.
>
> This has been committed some days ago.  See
>
>     https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=069bcba529142bdb91647258924513f0fb0f3fa1

Okay, thanks for confirming!

-- 
 Bastien


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-09-26 12:32 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-09 14:55 behavior of (org-insert-heading-respect-content) Victor A. Stoichita
2021-09-09 18:54 ` Marco Wahl
2021-09-09 19:29   ` Victor A. Stoichita
2021-09-13 19:21     ` Marco Wahl
2021-09-17 15:23       ` Victor A. Stoichita
2021-09-18 13:08         ` Marco Wahl
2021-09-26 11:13           ` Bastien
2021-09-26 12:13             ` Marco Wahl
2021-09-26 12:31               ` Bastien

Code repositories for project(s) associated with this 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 NNTP newsgroup(s).