Only sync if a save of an agenda file has occured.

This commit is contained in:
Ivan Malison 2015-01-30 19:41:28 -08:00
parent 1514b7c640
commit 224d0c15b5
2 changed files with 39 additions and 22 deletions

View File

@ -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)) (unbind-key "C-j" org-mode-map))
:init :init
(progn (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-directory "~/Dropbox/org")
(setq org-mobile-inbox-for-pull "~/Dropbox/org/flagged.org") (setq org-mobile-inbox-for-pull "~/Dropbox/org/flagged.org")
(setq org-mobile-directory "~/Dropbox/Apps/MobileOrg") (setq org-mobile-directory "~/Dropbox/Apps/MobileOrg")

View File

@ -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)