On Mon, 18 Dec 2023, at 12:27 PM, Ihor Radchenko wrote:
> I played around with the patch a bit and found a couple of rough edges:
> 1. When I try to open a link to non-existing search target, like
>    <id:some-id::non-existing-target>, I get a query to create a new
>    heading. If I reply "yes", a new heading is created. However, the
>    heading is created at the end of the file and is always level 1,
>    regardless of the "some-id" parent context.
>    It would make more sense to create a new heading at the end of the
>    id:some-id subtree.

Thanks for the comments. On this point, I'd like to modify `org-insert-heading' 
to allow for choosing the level of the newly inserted heading, but first wanted 
to check if you have a preference for how to change it.

I think it would be simplest to change the current:

(defun org-insert-heading (&optional arg invisible-ok top)
  "...When optional argument TOP is non-nil, insert a level 1 heading, 


(defun org-insert-heading (&optional arg invisible-ok level)
  "...When optional argument LEVEL is a number, insert a heading at that level. 
 For backwards compatibility, when LEVEL is non-nil but not a number, insert a 
level-1 heading."

but that is not totally backwards compatible -- is that ok?

If it should be completely backwards compatible, alternatively could add an 
additional optional argument:

(defun org-insert-heading (&optional arg invisible-ok top top-level)
  "...When optional argument TOP is non-nil, insert a top-level heading, 
unconditionally.  When TOP-LEVEL is non-nil, use that level, otherwise level 1."

Alternatively I could preserve the intention of TOP but add a special value to 
change what "top-level" means, so the docstring would become something like 

"When optional argument TOP is non-nil, insert a top-level
heading, unconditionally.  Specifically, when TOP is `relative',
\"top-level\" means one level deeper than the outline level at
minimum point position (respecting any narrowing of the buffer).
Otherwise, \"top-level\" means level 1."

(the motivation for this is that when the buffer is narrowed to the subtree 
with the matching ID, the new heading will be created at the appropriate level).


Reply via email to