I use MobileOrg to synchronize my emacs org-files with my mobile. For correct synchronization, mobile-org requires me to run org-mobile-push and org-mobile-pull from within emacs.

I can automatically run org-mobile-pull on startup by inserting


into my .emacs file, but how do I automatically run an emacs command when closing emacs?

asked 18 Apr '11, 08:30

Jazz's gravatar image

Jazz ♦
accept rate: 33%

edited 18 Apr '11, 10:40

Apparently, a way to solve this is to rebind C-c C-x (default close emacs keyboard shortcut) to another function. Upon further research, I found the .emacs of Elliot Glaysher, who bound a more intelligent function to C-c C-x:

(defun intelligent-close ()
  (org-mobile-push) ;; <== MOBILE ==
  (if (eq (car (visible-frame-list)) (selected-frame))
      (if (> (length (visible-frame-list)) 1)
          (delete-frame (selected-frame))
    (delete-frame (selected-frame)))
(global-set-key "C-xC-c" 'intelligent-close)

As you can see, I simply added org-mobile-push to the function. Works like a charm. :)

I'd be very interested in further solutions for this problem!


answered 18 Apr '11, 09:39

Jazz's gravatar image

Jazz ♦
accept rate: 33%

Well, I don't have any experience with that, however, and this may or may not work, but my idea would be to setup a cron job to run a bash script that would look and see if emacs is open, mark the time stamp and then compare it to when emacs closes, and if it's more than X time, do Y. If it's less than X time, do Z.

Now this idea is strictly conceptual, but something like that may (or may not) work. I wish I had a more concrete idea for you with code, but alas, I do not.


answered 18 Apr '11, 09:00

Ron's gravatar image

Ron ♦
accept rate: 13%

This is a good idea, but is dependend on the fact that the commands are executable from outside of emacs. I updated my question to clarify that org-mobile-push and org-mobile-pull must be run from within emacs.

(18 Apr '11, 09:25) Jazz ♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 18 Apr '11, 08:30

Seen: 8,086 times

Last updated: 18 Apr '11, 10:40

powered by OSQA