khalorg
khalorg copied to clipboard
Idempotently sync changes between ikhal and orgmode
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?
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
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 :)
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
tolocal_khal
usingkhalorg
(we need to make a new command for this). - Next we run
vdirsyncer sync
which will pull the changes from remote intolocal_khal
. Here, we letvdirsyncer
resolve the merge conflict in event A. - Next, we use
khalorg list
to update ourlocal_org
calendar.
The process above can still be executed using timer (cron/systemd). I might be missing something here but it is a start.
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
, runvdirsyncer
,list
)