Как автоматически сделать org-mobile-push org-mobile pull в emacs
Поскольку я использую org-mode для отслеживания списка todo в emacs, мне нравится приложение iPhone: MobileOrg, с ним я могу получить доступ к моему списку дел в течение всего дня.
Но вот проблема:
Мне нужно вручную орг-мобилью направить мои изменения из локального файла на мобильный телефон с помощью Dropbox, а org-mobile - поменять сделанные по телефону изменения.
Как сделать это автоматически? Как добавить некоторые рецепты в файл dotemacs.
Ответы
Ответ 1
Добавьте эти две строки в файл emacs dot:
(add-hook 'after-init-hook 'org-mobile-pull)
(add-hook 'kill-emacs-hook 'org-mobile-push)
С их помощью он автоматически вытягивает изменения при запуске emacs и выдает изменения до выхода emacs.
- Обновить
Если вы никогда не выходите из Emacs, это решение может не сработать для вас. Итак, другое решение, использующее таймер бездействия
;; moble sync
(defvar org-mobile-sync-timer nil)
(defvar org-mobile-sync-idle-secs (* 60 10))
(defun org-mobile-sync ()
(interactive)
(org-mobile-pull)
(org-mobile-push))
(defun org-mobile-sync-enable ()
"enable mobile org idle sync"
(interactive)
(setq org-mobile-sync-timer
(run-with-idle-timer org-mobile-sync-idle-secs t
'org-mobile-sync)));
(defun org-mobile-sync-disable ()
"disable mobile org idle sync"
(interactive)
(cancel-timer org-mobile-sync-timer))
(org-mobile-sync-enable)
Я только что узнал, что это так же, как и ниже, поэтому, если вы предпочитаете решение таймера бездействия, пожалуйста, воздержитесь ответ tkf.
Ответ 2
У меня есть что-то подобное в настройке Emacs, чтобы делать push и pull, когда я ухожу от компьютера.
(defvar my-org-mobile-sync-timer nil)
(defvar my-org-mobile-sync-secs (* 60 20))
(defun my-org-mobile-sync-pull-and-push ()
(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)
Альтернатива заключается в следующем:
(Я нашел это здесь https://github.com/matburt/mobileorg-android/wiki/Scripting/):
emacs --batch --load ~/.emacs --eval "(org-mobile-pull)" --eval "(org-mobile-push)"
Ответ 3
В качестве побочного решения, похожего на Sandeep C's
;; for Emacs 24.3.1 insert next line
(require 'cl)
;; automatically org-mobile-push on save of a file
(add-hook
'after-save-hook
(lambda ()
(let (
(org-filenames (mapcar 'file-name-nondirectory (directory-files org-directory))) ; list of org file names (not paths)
(filename (file-name-nondirectory buffer-file-name)) ; list of the buffers filename (not path)
)
(if (find filename org-filenames :test #'string=)
(org-mobile-push)
)
)
)
)
Ответ 4
Этот код взят из http://kenmankoff.com/2012/08/17/emacs-org-mode-and-mobileorg-auto-sync/, с изменением нескольких деталей. Вам нужно настроить переменные в начале. Этот код будет
Код для файла .emacs:
(require 'org-mobile)
;; Configure these two variables
(setq org-mobile-inbox-for-pull "~/Dropbox/org/mobile.org"
org-mobile-directory "~/Dropbox/MobileOrg")
(require 'gnus-async)
;; Define a timer variable
(defvar org-mobile-push-timer nil
"Timer that `org-mobile-push-timer' used to reschedule itself, or nil.")
;; Push to mobile when the idle timer runs out
(defun org-mobile-push-with-delay (secs)
(when org-mobile-push-timer
(cancel-timer org-mobile-push-timer))
(setq org-mobile-push-timer
(run-with-idle-timer
(* 1 secs) nil 'org-mobile-push)))
;; After saving files, start an idle timer after which we are going to push
(add-hook 'after-save-hook
(lambda ()
(if (or (eq major-mode 'org-mode) (eq major-mode 'org-agenda-mode))
(dolist (file (org-mobile-files-alist))
(if (string= (expand-file-name (car file)) (buffer-file-name))
(org-mobile-push-with-delay 10))))))
;; watch mobileorg.org for changes, and then call org-mobile-pull
(defun org-mobile-install-monitor (file secs)
(run-with-timer
0 secs
(lambda (f p)
(unless (< p (second (time-since (elt (file-attributes f) 5))))
(org-mobile-pull)
(org-mobile-push)))
file secs))
(defvar monitor-timer (org-mobile-install-monitor (concat org-mobile-directory "/mobileorg.org") 30)
"Check if file changed every 30 s.")
Ответ 5
вы также можете нажать сразу после сохранения заметки, например:
(add-hook
'after-save-hook
(lambda ()
(if (string= buffer-file-name "<path to my notes.org>")
(org-mobile-push)
)
))
Ответ 6
Я использую этот код elisp из gist на моем init.el, и он работает очень хорошо, за исключением того, что у него нет org-mobile- вытащить.
Ответ 7
Я решил просто нажать при сохранении, поэтому я добавил это в свой файл init emacs:
(defun org-mobile-push-on-save ()
"Used in `after-save-hook'."
(when (memq this-command '(save-buffer save-some-buffers))
(org-mobile-push)))
(add-hook 'org-mode-hook
(lambda ()
(add-hook 'after-save-hook 'org-mobile-push-on-save nil 'make-local)))
В двух словах, он добавляет буферы после сохранения в org-mode.
Дополнительная информация о коде:
Для автоматического натяжения таймер, как и в других ответах, вероятно, является хорошим способом.