Skip to content

Instantly share code, notes, and snippets.

@lislon
Created October 28, 2015 22:21
Show Gist options
  • Select an option

  • Save lislon/debbd4d7542b669d8059 to your computer and use it in GitHub Desktop.

Select an option

Save lislon/debbd4d7542b669d8059 to your computer and use it in GitHub Desktop.
(defvar my/org-mobile-sync-timer nil)
(defvar my/org-mobile-sync-secs (* 60 20))
(defun my/org-mobile-sync-pull-and-push ()
(require 'org)
(org-mobile-pull)
(org-mobile-push)
(when (fboundp 'sauron-add-event)
(sauron-add-event 'my 3 "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))
(my/org-mobile-sync-start)
(defun my/org-mobile-fix-index-bug ()
"Fixes MobileOrg's index.org after push to workaround bug in Android.
That function deletes \"#+ALLPRIORITIES\" string from index.org file"
(interactive)
(let ((file (concat org-mobile-directory "/index.org")))
(save-excursion
(with-temp-buffer
(insert-file-contents file)
(beginning-of-buffer)
(when (search-forward "#+ALLPRIORITIES" nil t)
;; Avoid polluting kill-ring by not calling (kill-line)
(let ((beg (progn (forward-line 0)
(point))))
(forward-line 1)
(delete-region beg (point))))
(write-region nil nil file)
)
)))
(advice-add 'org-mobile-push :after 'my/org-mobile-fix-index-bug)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment