11
votes

How can I edit Google Drive text documents using Emacs and mirror my changes back to the Google Doc?

I found a Google command line program, as well as something called gclient, which is part of Emacsspeak, but they seem to require Linux or Windows, and I'm on OSX using Aquamacs. Or maybe I just don't understand how to install them.

Is this doable?

3
I didn't try it, but the first link that you mention - the code is written in Python, so there is a good chance it will work on OSX as is. And if not, then you're probably on your own figuring out what didn't work. You will not know how much effort it will require to get it to work, unless you try. Though, frankly, I'd go with editing whatever I need in Org, then exporting it to Open Office format and uploading to Google... unless there's really a lot of paperwork to do. - user797257

3 Answers

5
votes

googlecl can be installed from macports. You can then open files with local emacs using emacs server.

Once it is installed, you can follow these commands:

$ google docs list          # gets a list of the files
$ google docs get <FILE> /tmp/edit$$.txt   # gets the <FILE> to /tmp/edit$$.tmp
$ emacsclient /tmp/edit$$.tmp
$ google docs upload /tmp/edit$$.tmp <FILE>

However, I've found that google docs get doesn't work as well as it should.

1
votes

There is no need to Fetch, Edit(emacs), and Push the file back.

First install "Google Drive" on your mac. Then you can edit the file directly. Look under ~/Google\ Drive.

0
votes

Another option using gdrive (requires helm for completion)

(defvar gdocs-folder-id "<gdrive folder for exported docs>"
 "location for storing org to gdocs exported files, use 'gdrive list  -t <foldername>' to find the id")

(defun gdoc-export-buffer ()
  "Export current buffer as google doc to folder irentified by gdocs-folder-id"
  (interactive)
  (shell-command
  (format "gdrive upload --convert --mimetype text/plain --parent %s --file %s"
      gdocs-folder-id buffer-file-name)))

(defun gdoc-import-buffer (doc)
   "Import a file in gdocs-folder-id into current buffer"
   (interactive 
   (list
      (completing-read "Choose one: "
                 (split-string
                  (shell-command-to-string
                   (format "gdrive list -q \"'%s' in parents\"" gdocs-folder-id)) "\n"))))
  (insert (replace-regexp-in-string (string ?\C-m) (string ?\C-j) (shell-command-to-string
  (format "gdrive download -s --format txt --id %s" (car (split-string doc " ")))))))