/orgsync

A trivial org-mode file sync on start and save [rsync and git push/pull support]

Primary LanguagePython

How to configure

We need 2 hooks

  • starting: after-change-major-mode-hook
  • saving: after-save-hook

Installation

  • Clone this repo / download to `~/orgsync` path. Of course, custom location are fine.
  • In your `.emacs` or `.spacemacs` file, at the very end place this block to load our custom script
    ;; Load custom startup functions
    (load "~/orgsync/emacs/startup")
    ;; if you used a different directory then change it here.
        
  • Thats it!

Default behavior

  • We load the script on emacs/spacemacs launch. This adds hook for org-mode file open & file save.
  • On file open/save we trigger pull (to retrieve) / push (to store) the org file.
  • There are 2 strategy to do so. `Rsync` to a path or Use git. Default is to use `git`.
  • If you open a org file on a directory under git source control; it will commit and push to master. This can be changed by changing parameter in push.py
  • Either you use rsync or git, there is a delay to load/store file. Allow few seconds in this process.

Concept Aside

onLoad hook

;; onLoad org mode hook
;; find if there is a corresponding file in the remote
;; if there is then rsync it and reload
;; if there is not then keep going
(defun sync-from-cloud-if-possible()
  (interactive)
  (when (eq major-mode 'org-mode)
    ;; you can either use `rsync` or `git` as strategy
    (shell-command-to-string (format "python ~/orgsync/pull.py git %s" buffer-file-name))
    (message "Done pulling!")
    )
  )

(add-hook 'after-change-major-mode-hook #'sync-from-cloud-if-possible)

onSaveHook

;; Add hooks afterSave
;; while the mode is org-mode
;; call python syncer. 
(defun sync-to-cloud ()
  "Sync org file to github repo"
  (interactive)
  (when (eq major-mode 'org-mode)
    ;; you can use `rsync` or `git` as strategy
    (shell-command-to-string (format "python ~/orgsync/push.py %s" buffer-file-name))
    (message "Done rsyncing")
    ))

(add-hook 'after-save-hook #'sync-to-cloud)     

Restart emacs. You should be good to go!

Troubleshooting

  • If rsync takes too long and you feel emacs is freezing ==> it is freezing for real. Dont worry. You will get control in few seconds depending on your connection.
  • If rsync doesnot work, try rsyncing to your server in the terminal so that the system can authenticate you for the first time. (I havent done extensive work on this part yet.)