Hi Victor, > Le 09 Sep 2021, Marco Wahl <marcowahls...@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!