orgmode icon indicating copy to clipboard operation
orgmode copied to clipboard

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

Open GitMurf opened this issue 1 year ago • 5 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!

GitMurf avatar Feb 16 '24 05:02 GitMurf

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

kristijanhusak avatar Feb 16 '24 06:02 kristijanhusak

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

GitMurf avatar Feb 16 '24 11:02 GitMurf

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

GitMurf avatar Feb 16 '24 11:02 GitMurf

@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.

GitMurf avatar Feb 16 '24 12:02 GitMurf

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.

GitMurf avatar Feb 16 '24 12:02 GitMurf

This was added in https://github.com/nvim-orgmode/orgmode/commit/70ca80be8e503ea928657e0028ed114bf9fb1c00.

You can define it like this:

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

kristijanhusak avatar Feb 26 '24 18:02 kristijanhusak

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

GitMurf avatar Feb 26 '24 22:02 GitMurf