Skip to content

feat(apis): add new useful methods to OrgApiFile and OrgApiHeadline#1127

Open
ar-at-localhost wants to merge 17 commits into
nvim-orgmode:masterfrom
ar-at-localhost:feat/apis
Open

feat(apis): add new useful methods to OrgApiFile and OrgApiHeadline#1127
ar-at-localhost wants to merge 17 commits into
nvim-orgmode:masterfrom
ar-at-localhost:feat/apis

Conversation

@ar-at-localhost
Copy link
Copy Markdown

@ar-at-localhost ar-at-localhost commented Apr 14, 2026

Summary

This PR adds new API methods to OrgAPIHeadline for programmatic uses.

Changes

Non-Breaking

  • Headline:clock_in and Headline:clock_out now accepts optional opts to enable silent behavior (useful for programmatic uses).

Checklist

I confirm that I have:

  • Followed the
    Conventional Commits
    specification
    (e.g., feat: add new feature, fix: correct bug,
    docs: update documentation).
  • My PR title also follows the conventional commits specification.
  • Updated relevant documentation, if necessary.
  • Thoroughly tested my changes (I've been using methods already in my personal project.)
  • Added tests (if applicable) and verified existing tests pass with
    make test.
  • Checked for breaking changes and documented them, if any.

- Add OrgHeadline:clock_in(opts) - clock in headline with optional silent event
- Add OrgHeadline:clock_out(opts) - clock out headline with optional silent event
- Add OrgHeadline:toggle_clock(opts) - toggle clock state (in if out, out if in)
- Add OrgHeadline:is_clocked_in() - check if headline is clocked in
- Add OrgHeadline:cancel_active_clock() - cancel active clock without event
- Add OrgHeadline:set_todo(keyword) - set todo keyword on headline
Comment thread doc/orgmode_api.txt Outdated
@return string


OrgFile:insert_headline() *OrgFile:insert_headline*
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kristijanhusak I'm not familiar with lemmy-help, so I generated these blindly. Please have a careful look. Thanks

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are auto generated from annotations, no need to add anything.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted to upstream.

Comment thread lua/orgmode/api/headline.lua Outdated
Comment thread tests/plenary/api/api_spec.lua Outdated
assert.is.Nil(closest_headline)
end)

describe('insert_headline', function()
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kristijanhusak AI generated. Have a careful look. Thanks

@ar-at-localhost ar-at-localhost changed the title feat(apis): add new useful methods to OrgApiFile and `OrgApiHeadline feat(apis): add new useful methods to OrgApiFile and OrgApiHeadline Apr 14, 2026
Comment thread doc/orgmode_api.txt Outdated
@return string


OrgFile:insert_headline() *OrgFile:insert_headline*
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are auto generated from annotations, no need to add anything.

Comment thread lua/orgmode/api/file.lua Outdated
--- Insert a headline to the file
--- @param headline OrgApiHeadline | OrgHeadline | { level: integer, keyword?: string, text: string } Headline to be inserted
--- @param after? OrgApiHeadline | OrgHeadline Optional headline to put after
function OrgFile:insert_headline(headline, after)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this in the API. You can use capture flow to insert headlines. If you need this level of programmatic insertion you can create your own function.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

Comment thread nix/nixvim.nix Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove all these new files that does not relate to the plugin.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something I’d prefer to keep. These files are intentionally committed so Nix users can contribute easily without needing to set up the environment manually.

That said, I’ve cleaned up and simplified the setup by switching to a more standard approach (Flakes instead of Devenv), which reduces the number of files and improves familiarity for existing Nix users.

The added files are effectively no-ops for non-Nix users, while still being valuable for contributors using Nix. In practice, if a future Nix user wanted to contribute, they would most likely end up adding a similar flake setup before making any actual changes anyway.

That said, I’ll still respect the decision if you’d prefer to remove it regardless.

Comment thread .envrc.example
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this file.

Comment thread .gitignore

# Lock file
.org-ts-lock.json

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are mostly nix specific stuff that you can ignore in your global gitignore. Please remove them.

Comment thread flake.nix
@@ -0,0 +1,63 @@
{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need nix specific stuff in repo.

end
logbook:add_clock_in()
EventManager.dispatch(events.ClockedIn:new(self))
if not opts or not opts.silent then
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the use case for the silent version?


---Get closest internal OrgHeadline for the headline
---@return OrgPromise<OrgHeadline>
function OrgHeadline:get_closest_headline()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method should not live on the OrgHeadline. It should be either in the api/init.lua or api/file.lua

Comment thread lua/orgmode/api/headline.lua
Co-authored-by: Kristijan Husak <husakkristijan@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants