Background / Problem: I have 2 machines sharing a file directory using Google drive. I edit the shared files using Emacs on both machines alternatively everyday. I would like to make sure that at most one active Emacs session is running at a time to avoid sync conflict due to multiple active sessions with unsaved files.

Idea: I would like to make Emacs to save the time-stamp and hostname to some shared log file whenever I close it, so that I can check the log entry when I open Emacs on another machine next time. That makes sure my previous Emacs sessions was closed and all files were saved and synced/up-to-date.

Implementation: I would like to add a function to kill-emacs-hook to append or replace time-stamp and hostname in a log file. The log file can be a org-mode file with a heading "Last session close time", so that I can replace the old content (i.e., old time-stamp and hostname) under that heading in the function. How can I do that?

Or: Is there any package provide the "last session time" logging for us?

Another question (please let me know if I should create a new question on stackexchange): We can open an org-mode file automatically when starting Emacs. Can we make sure a specific heading (in my case "Last session close time") is shown on startup?

2 Answers 2


Not exactly the answer you are expecting, but:

If you are running on GNU/Linux in a GNOME environment, you could try the upcoming Emacs 26.1. Tramp offers a new method there, gdrive, which allows you to edit the file remotely on the Google drive. Something like

C-x C-f /gdrive:[email protected]:/dir/to/file

Replace the account name with yours.

If you use an older Emacs, you could download the recent Tramp 2.3.2, which comes already with Google drive support.


I added the following hook to append the timestamp to my startup file:

(setq my-startup-filename "~/Google Drive/startup.txt")
 (lambda ()
   (append-to-file (concat "\n" system-name " " (format-time-string "%a, %Y/%m/%d, %l:%M %p")) nil my-startup-filename)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.