如何在 emacs 中自动执行 org-mobile-push org-mobile pull

发布于 2024-12-20 11:06:30 字数 231 浏览 3 评论 0原文

由于我在 emacs 中使用 org-mode 来跟踪我的待办事项列表,因此我喜欢 iPhone 应用程序:MobileOrg,有了它,我可以全天访问我的待办事项列表。

但问题是:

我必须通过 dropbox 手动 org-mobile-push 从本地文件到手机的更改,然后 org-mobile-pull 手机上所做的更改。

如何自动做到这一点?就像在 dotemacs 文件中添加一些食谱一样。

Since I am using org-mode to track my todo list in emacs, I like the iPhone app: MobileOrg, with it, I can access my todo list all day.

But here's the problem:

I have to manually org-mobile-push my changes from local file to mobile phone through dropbox, and org-mobile-pull the changes made by phone back.

How to make that automatically? Like adding some recipes in dotemacs file.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

骷髅 2024-12-27 11:06:30

将这两行添加到 dot emacs 文件中:

(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 的回答

Add these two lines to dot emacs file:

(add-hook 'after-init-hook 'org-mobile-pull)
(add-hook 'kill-emacs-hook 'org-mobile-push) 

With them, it automatically pulls the changes on emacs startup, and pushes the changes before emacs exits.

-- Update

If you never exit your Emacs, this solution might not work for you. So, another solution using idle timer

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

I just found out it is same as below answer, so, if you prefer the idle timer solution, please upvote tkf's answer.

逆夏时光 2024-12-27 11:06:30

当我离开计算机时,我的 Emacs 设置中有类似的东西可以进行推拉操作。

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

另一种方法是将以下内容放入 cron 作业中
(我在这里找到了这个 https://github.com/matburt/mobileorg-android/wiki /脚本/):

emacs --batch --load ~/.emacs --eval "(org-mobile-pull)" --eval "(org-mobile-push)"

I have something like this in my Emacs setting to do push and pull when I am away from computer.

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

Alternative is to put the following in cron job
(I found this here https://github.com/matburt/mobileorg-android/wiki/Scripting/):

emacs --batch --load ~/.emacs --eval "(org-mobile-pull)" --eval "(org-mobile-push)"
毁梦 2024-12-27 11:06:30

此代码取自 http://kenmankoff .com/2012/08/17/emacs-org-mode-and-mobileorg-auto-sync/,更改了一些细节。您需要在一开始就配置变量。此代码将

  • 每 30 秒检查一次 MobileOrg 是否已同步,如果已同步

    • 从 MobileOrg 拉取。
    • 推送到 MobileOrg。

      这对于更新 MobileOrg 中的议程视图是必要的。
      通过此行为,您可以离开计算机,在 MobileOrg 中更新一些内容,同步,等待 30 秒,再次同步,您的移动议程视图将会更新。

  • 每当保存 org 文件时
    • 检查保存的组织文件是否应该与 MobileOrg 同步,如果是的话
      • 等待用户空闲
      • 推送至 MobileOrg

代码:

(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.")

This code is taken from http://kenmankoff.com/2012/08/17/emacs-org-mode-and-mobileorg-auto-sync/, with a couple of details changed. You need to configure the variables in the beginning. This code will

  • Check every 30s whether MobileOrg has synced, and if so

    • Pull from MobileOrg.
    • Push to MobileOrg.

      This is necessary to update the agenda views in MobileOrg.
      With this behavior, you can be away from your computer, update some things in MobileOrg, sync, wait 30 seconds, sync again, and your mobile agenda view will be updated.

  • Whenever an org file is saved
    • Check whether the saved org file is supposed to be synced with MobileOrg, and if so
      • Wait for the user to become idle
      • Push to MobileOrg

Code for your .emacs file:

(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.")
半世蒼涼 2024-12-27 11:06:30

您也可以在保存注释后立即按下,如下所示:

(add-hook 
  'after-save-hook 
  (lambda () 
     (if (string= buffer-file-name "<path to my notes.org>") 
        (org-mobile-push)
     )
  ))

you can also push right after saving a note, like this:

(add-hook 
  'after-save-hook 
  (lambda () 
     (if (string= buffer-file-name "<path to my notes.org>") 
        (org-mobile-push)
     )
  ))
·深蓝 2024-12-27 11:06:30

我在 init.el 上使用 来自 gist 的 elisp 代码,它工作得很好,除了它不没有内置 org-mobile-pull。

I use this elisp code from gist on my init.el and it works pretty well, except it doesn't have org-mobile-pull built in.

荒岛晴空 2024-12-27 11:06:30

作为一个辅助解决方案,类似于 Sandeep C 的

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

As a side solution, similar to 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)        
       )
     )
   )
)
跨年 2024-12-27 11:06:30

我选择在保存时简单地推送,因此我将其添加到我的 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)))

简而言之,它向组织模式缓冲区添加了一个保存后钩子。

有关代码的更多信息:

对于自动拉取,像其他答案中那样的计时器可能是一个不错的选择方式。

I opted to simply push when saving, so I added this to my emacs init file:

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

In a nutshell, it adds an after-save-hook to org-mode buffers.

More info on the code:

For auto-pull, a timer as in other answers is probably a good way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文