Skip to content

feat(api): Allow to insert links through API #731

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

Merged
merged 2 commits into from
May 22, 2024

Conversation

seflue
Copy link
Contributor

@seflue seflue commented May 21, 2024

To give plugins like Telescope-orgmode the ability to insert links, the API needs an extension.

The refactoring moves some methods from org.mappings into modules, where they should belong anyway, so they can be used from the new api method.

The new API method api.insert_link is mostly existing code moved from org.mappings.insert_link, which now just calls api.insert_link.

@seflue
Copy link
Contributor Author

seflue commented May 21, 2024

@kristijanhusak Please see my PR in Telescope-orgmode as an example, how this change can be used. I actually need this change for that feature.

Copy link
Member

@kristijanhusak kristijanhusak left a comment

Choose a reason for hiding this comment

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

Lets just abstract the logic in different place and use it on both places accordingly.

--- Insert a link to a given location at the current cursor position
--- @param link_location string
--- @return boolean
function OrgApi.insert_link(link_location)
Copy link
Member

Choose a reason for hiding this comment

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

Let's abstract all this logic in Hyperlinks and then require that one here. I'm trying not to depend on orgmode.api in the core, but vice versa.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have to admit, that I just looked at other functions, which had similar calling schemes, but I agree, that it would be cleaner to move them into Hyperlinks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved the code as you suggested.

Sebastian Flügge added 2 commits May 21, 2024 23:57
To give plugins like Telescope-orgmode the ability to insert links, the
API needs an extension.

The refactoring moves some methods from org.mappings into modules, where
they should belong anyway, so they can be used from the new api method.

The new API method api.insert_link is mostly existing code moved from
org.mappings.insert_link, which now just calls api.insert_link.
To have clean module dependencies, insert_link is now a method of
Hyperlinks and is exposed over the api but also called from mappings.
@seflue seflue force-pushed the api_insert_link branch from 3232e42 to 5732cf3 Compare May 21, 2024 21:57
@seflue seflue requested a review from kristijanhusak May 21, 2024 22:01
Copy link
Member

@kristijanhusak kristijanhusak left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@kristijanhusak kristijanhusak merged commit 36c76c2 into nvim-orgmode:master May 22, 2024
6 checks passed
@seflue seflue deleted the api_insert_link branch May 23, 2024 01:50
SlayerOfTheBad pushed a commit to SlayerOfTheBad/orgmode that referenced this pull request Aug 16, 2024
* feat(api): Allow to insert links through API

To give plugins like Telescope-orgmode the ability to insert links, the
API needs an extension.

The refactoring moves some methods from org.mappings into modules, where
they should belong anyway, so they can be used from the new api method.

The new API method api.insert_link is mostly existing code moved from
org.mappings.insert_link, which now just calls api.insert_link.

* refactor: move link insertion into Hyperlinks

To have clean module dependencies, insert_link is now a method of
Hyperlinks and is exposed over the api but also called from mappings.

---------

Co-authored-by: Sebastian Flügge <sebastian.fluegge@dnv.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