Skip to content
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

Idempotently sync changes between ikhal and orgmode #3

Open
lyz-code opened this issue Mar 3, 2024 · 4 comments
Open

Idempotently sync changes between ikhal and orgmode #3

lyz-code opened this issue Mar 3, 2024 · 4 comments

Comments

@lyz-code
Copy link

lyz-code commented Mar 3, 2024

Hi @BartSte, first of all thanks for the awesome program, I haven't got the chance to use it yet but it looks beautiful.

There is a feature that I have not found in the docs nor skimming through the code and I wanted to know if it's implemented. If not, how do you see the problem and if you'd accept PRs.

In an ideal scenario I'd love to be able to sync changes between the external calendars and the orgmode files transparently without user interaction with khalorg.

For sync to work we would need both directions:

  • From external sources to orgmode: This could be done running khalorg list in the same cron job that is running vdirsyncer.
  • From orgmode changes to external sources: I see two paths here:
    • Run a daemon that is able to detect changes in the agenda files either through a cron or inotify and once they are detected it runs khalorg + vdirsyncer. This could be part of khalorg or an external program.
    • Integrate that functionality in the saving mechanism of the editor (in my case nvim so it would be part of the nvim-plugin (I guess))

How do you see it?

@BartSte
Copy link
Owner

BartSte commented Mar 4, 2024

Hey @lyz-code, thanks for your interest. I accept PRs.

You are correct that currently there is no "automatic sync mechanism" that handles both pulling en pushing agenda items. The solution you describe sounds logical to me.

My current workflow is that I have 1 org file holding my Outlook agenda. When I want to pull the items I run khalorg list outlook > outlook.org. When I want to push new/edited items, I use the commands from the plugin. If I forget to do this, and run the khalorg list again, I will loose information. I guess this is also the issue you are encountering.

The ideal solution, I guess, would be if:

  • khal pulls the latest calendar data from the server.
  • khalorg could accept 1 org file (holding all agenda items of a calendar) and negotiate with khal whether:
    • an item was changed in the org file
    • an item was changed on khal (which we updated earlier)
  • based on the info above, the khal and the org file are updated.

The process above can be executed using systemd or cron using a simple timer.

I'll think about it some more this week. Let me know what you think the best approach would be.

Cheers

@lyz-code
Copy link
Author

lyz-code commented Mar 4, 2024

The algorithm you proposed looks perfect for me. At the implementation level I feel that having a khalorg sync <calendar_name> that the user can use either on cron or systemd (with whatever it feels more comfortable with) could be an elegant solution.

I'm a little busy right now so I can't guarantee a PR in a near horizon, but it's surely something that is nagging me inside my head, so if you don't have the energy to work on it, eventually I'll do it :)

@BartSte
Copy link
Owner

BartSte commented Mar 6, 2024

I was just thinking. Would it not be possible to let khalorg push all its changes to khal, without checking for any sync errors, and let vdirsyncer handle the synchronization?

For example:
You have:

  • remote calendar called: remote
  • local calendar in khal called: local_khal
  • the same local calendar as local_khal but now in org format: local_org

Lets say changes are made in remote: an existing event A is edited. At the same time, we also edit event A in org.

Now we can do the following:

  • Push all changes made in local_org to local_khal using khalorg (we need to make a new command for this).
  • Next we run vdirsyncer sync which will pull the changes from remote into local_khal. Here, we let vdirsyncer resolve the merge conflict in event A.
  • Next, we use khalorg list to update our local_org calendar.

The process above can still be executed using timer (cron/systemd). I might be missing something here but it is a start.

@lyz-code
Copy link
Author

lyz-code commented Mar 8, 2024

Makes a lot of sense to reuse vdirsyncer already in place conflict resolution. I hadn't thought of that possibility.

The workflow might be confusing for a new user though, so if we go through this path I'd definitely either:

  • make the documentation cristal clear
  • Create a khalorg new that asks the user the information needed to create a new calendar, and that creates the required calendars in vdirsync behind the scenes
  • Create the kharlorg sync that follows the process you described (push, run vdirsyncer, list)

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

No branches or pull requests

2 participants