nvim-orgmode/orgmode

Add new capture items from template to top of file instead of bottom of file

GitMurf opened this issue · 7 comments

Does this feature exist in Emacs orgmode core?

N/A

Orgmode link

No response

Feature value

No response

Additional context

Maybe there are already ways to accomplish this but I would like a way to add a capture template item to a target file at the top of the file instead of the bottom. Essentially to prepend instead of append. In a perfect world I could just specify the line number for the target file and it could add to bottom if you set line number as -1, add to the very top if line number set as 0, and any other number (e.g., 5) would be inserted below that line number... so for 5, that means it would essentially become line 6.

Let me know if you have any questions and/or if there is already a mechanism to accomplish this. Thanks!

This option is used in Emacs orgmode for that https://emacs.stackexchange.com/a/58346 . I'll look into implementing it at some point.

Here is even clearer information on emacs prepend feature. I guess they actually have a property for it called prepend! This isn't exactly what I need, but close because this required you put under a headline and not just the top of the note. But actually both these options would be important and valuable :)

https://orgmode.org/manual/Template-elements.html

image

@kristijanhusak if you want to point me in the right direction, I would be happy to take a look at a PR.

@kristijanhusak another thought I had, is there a way as is today to use the title of a file to put a template capture under instead of a headline? if so, that would also accomplish what I am looking to do.

For completeness sake, another emacs feature that would satisfy my requirements is the feature to use regex to decide on the target location in a file to add the capture item.

see here: https://orgmode.org/manual/Template-elements.html#index-org_002ddefault_002dnotes_002dfile-1

‘(file+regexp "filename" "regexp to find location")’
Use a regular expression to position point.

This was added in 70ca80b.

You can define it like this:

{
  template = '* %?',
  regexp = 'regexp to find location' -- Same as Vim search from command line
}

@kristijanhusak amazing work! Thank you! This is perfect :)