"Rick Lupton" writes: >> It looks like we cannot simply rely on narrowing to determine the >> created heading level. > > I think you're right. I have extended `org-link-search' to accept an optional argument describing the org element where newly created headings should go as subheadings. > > My thought was that this was not significantly more complicated than just passing the numeric level for new headings, but actually more flexible (e.g. you could if you wanted (with additional future elisp) create missing headings as part of a "To be filed" subtree within the file, rather than always at the end). > > Does that look ok? Yes. > [is it useful to keep attaching the unchanged first patch so they are available as a set?] Yes, it is useful. Makes it easier for my to batch-apply the patchset using https://git.kyleam.com/piem/about/ I have some thoughts about rewording your changes to the manual and ORG-NEWS. See the attached patch on top of yours. > Subject: [PATCH 1/2] lisp/org.el (org-insert-heading): allow specifying > heading level *Allow > * lisp/org.el (org-insert-heading): Change optional argument TOP to > LEVEL, accepting a number to force a specific heading level. > * testing/lisp/test-org.el (test-org/insert-heading): Add tests > * etc/ORG-NEWS: Document changes Please end sentences with period. > From d5759dd95bec88be38ddbde07fa4437c0528469a Mon Sep 17 00:00:00 2001 > From: Rick Lupton > Date: Sun, 19 Nov 2023 14:52:05 +0000 > Subject: [PATCH 2/2] org-id.el: Add search strings, inherit parent IDs > > ... > (org-link-try-link-store-functions): Extract logic to call external > link store functions. Pass them a new `interactive?' argument. > ... > (org-id-store-link): Consider IDs of parent headings as link targets > when current heading has no ID and `org-id-link-consider-parent-id' is > set. Add a search string to the link when enabled. Please, use two spaces between sentences. > * lisp/org-lint.el: add checker for "::" in ID properties. ... and start sentences from capital letter: *Add > -(defun org-link-search (s &optional avoid-pos stealth) > +(defun org-link-search (s &optional avoid-pos stealth new-heading-container) The new optional argument to a public function should be announced in ORG-NEWS. > + (new-heading-level (if new-heading-container > + (+ 1 (org-element-property :level new-heading-container)) What if new-heading-container is not a heading? > + 1))) > + (goto-char new-heading-position) This is err when container ends after narrowed region boundary. > +(defun org-link-precise-link-target () > ... > + (cond > + (name > + (list name > + name > + (org-element-begin element))) It would make sense to use #+caption as default description when available.