-
-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: captures #613
refactor: captures #613
Conversation
I also added subtemplates to reduce duplication. Now the user can specify the subtemplates as follows: {
e = {
description = 'Event',
subtemplates = {
r = {
description = 'recurring',
template = '** %?\n %T',
target = '~/org/calendar.org',
headline = 'recurring'
},
o = {
description = 'one-time',
template = '** %?\n %T',
target = '~/org/calendar.org',
headline = 'one-time'
},
},
},
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR.
Generally looks ok, but I don't think we need empty_lines
option since it can be achieved with \n
, unless I'm missing something.
DOCS.md
Outdated
* `template` (`string|string[]`) — body of the template that will be used when creating capture | ||
* `target` (`string?`) — name of the file to which the capture content will be added. If the target is not specified, the content will be added to the [`org_default_notes_file`](#orgdefaultnotesfile) file | ||
* `headline` (`string?`) — title of the headline after which the capture content will be added. If no headline is specified, the content will be appended to the end of the file | ||
* `empty_lines` (`table?`): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be achieved with \n
in the template, there's no need to define it. For example:
j = {
description = 'Journal',
-- Add 3 empty lines before and 3 lines after
template = '\n\n\n* TODO %?\n\n\n',
target = '~/sync/org/journal.org'
},
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment why it doesn't work.
This doesn't work if you add text to the headline. Sample template: {
description = "Test",
template = "\n\n** text with newlines",
target = "~/org/tmp.org",
headline = "Test",
} Result after double use of the template:
With empty lines it works: {
description = "Test",
template = "** text with newlines",
target = "~/org/tmp.org",
headline = "Test",
empty_lines = {
before = 2,
},
} Result:
|
This is happening because of this line https://github.com/nvim-orgmode/orgmode/blob/master/lua/orgmode/capture/init.lua#L154 This trims the empty lines before. We need to have this headline in order to be able to properly promote/demote depending on destination. We can handle this in 2 ways:
I'd prefer the first since it's a smaller change, but you can also try the 2nd option if you want. |
Okay, I'll see what I can do. Another advantage of
Emacs orgmode also has the option |
Ah, ok, wasn't aware of this. I thought this is not part of Emacs. We generally try to follow as much as possible. |
Done |
I have made the following changes:
|
There are a lot of duplicate commits. Can you please squash them? |
5891e62
to
b13b592
Compare
Done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are almost there. Let's just tweak the empty lines thing as I explained in the comment and I think it's good to go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything looks great now, thanks!
@danilshvalov just please rebase from master since there are some conflicts. |
Sorry for the long delay. Done |
Thanks! |
* refactor: captures * refactor: make headline detached from template * feat: subtemplates * refactor: move `empty_lines` to `properties` * feat: remove buffer empty lines * fix: properly place capture without headline * tests: add tests for org captures * fix: template validation * chore: remove old tests
This pull request was aimed at improving the extensibility of orgmode captures. At first, I just wanted to add an option to append and prepend empty lines after refiling. It turned out to be a bit more complicated than I thought, so I decided to do a little refactoring. I am ready to change anything else that needed to be changed in orgmode captures, if necessary.
P.S. empty lines were also added.