diff --git a/dotfiles/emacs.d/init.el b/dotfiles/emacs.d/init.el index cdb7561a..ab4f435a 100644 --- a/dotfiles/emacs.d/init.el +++ b/dotfiles/emacs.d/init.el @@ -834,28 +834,6 @@ the same tree node, and the headline of the tree node in the Org-mode file." (unbind-key "C-j" org-mode-map)) :init (progn - ;; Automatically sync with mobile - (defvar my-org-mobile-sync-timer nil) - (defvar my-org-mobile-sync-secs 120) - (defun my-org-mobile-sync-pull-and-push () - (org-mobile-pull) - (org-mobile-push) - (when (fboundp 'sauron-add-event) - (sauron-add-event 'me 1 "Called org-mobile-pull and org-mobile-push"))) - (defun my-org-mobile-sync-start () - "Start automated `org-mobile-push'" - (interactive) - (setq my-org-mobile-sync-timer - (run-with-idle-timer my-org-mobile-sync-secs t - 'my-org-mobile-sync-pull-and-push))) - - (defun my-org-mobile-sync-stop () - "Stop automated `org-mobile-push'" - (interactive) - (cancel-timer my-org-mobile-sync-timer)) - (if (and (boundp 'file-notify--library) file-notify--library) - (use-package org-mobile-sync :ensure t :config (org-mobile-sync-mode 1)) - (my-org-mobile-sync-start)) (setq org-directory "~/Dropbox/org") (setq org-mobile-inbox-for-pull "~/Dropbox/org/flagged.org") (setq org-mobile-directory "~/Dropbox/Apps/MobileOrg") diff --git a/dotfiles/emacs.d/load.d/org-mobile-sync.el b/dotfiles/emacs.d/load.d/org-mobile-sync.el new file mode 100644 index 00000000..864449dd --- /dev/null +++ b/dotfiles/emacs.d/load.d/org-mobile-sync.el @@ -0,0 +1,39 @@ +(defvar imalison-org-mobile-sync-timer nil) +(defvar imalison-org-mobile-sync-secs 60) +(defvar imalison-org-mobile-sync:unsaved-changes-count 0) +(defvar imalison-org-mobile-sync:unsaved-changes-min-sync 1) + +(defun imalison-org-mobile-sync-pull-and-push () + (org-mobile-pull) + (imalison-org-mobile-sync) + (when (fboundp 'sauron-add-event) + (sauron-add-event 'me 1 "Called org-mobile-pull and org-mobile-push"))) + +(defun imalison-org-mobile-sync-start () + "Start automated `org-mobile-push'" + (interactive) + (setq imalison-org-mobile-sync-timer + (run-with-idle-timer imalison-org-mobile-sync-secs t + 'imalison-org-mobile-sync-pull-and-push))) + +(defun imalison-org-mobile-sync-stop () + "Stop automated `org-mobile-push'" + (interactive) + (cancel-timer imalison-org-mobile-sync-timer)) +(if (and (boundp 'file-notify--library) file-notify--library) + (use-package org-mobile-sync :ensure t :config (org-mobile-sync-mode 1)) + (imalison-org-mobile-sync-start)) + +(defun imalison-org-mobile-sync (&optional force) + (interactive) + (when (or force (>= imalison-org-mobile-sync:unsaved-changes-count imalison-org-mobile-sync:unsaved-changes-min-sync)) + (org-mobile-push) + (setq imalison-org-mobile-sync:unsaved-changes-count 0))) + +(add-hook 'after-save-hook (lambda () + (when (member (file-truename (buffer-file-name)) + (mapcar 'file-truename org-agenda-files)) + (setq imalison-org-mobile-sync:unsaved-changes-count + (+ imalison-org-mobile-sync:unsaved-changes-count 1))))) +(imalison-org-mobile-sync-start) +(provide 'org-mobile-sync)