11

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?

incandescentman
  • 6,168
  • 3
  • 46
  • 86
  • 1
    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. –  Aug 23 '13 at 07:38

4 Answers4

5

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.

vy32
  • 28,461
  • 37
  • 122
  • 246
  • OK I installed googlecl. How do I use emacs server to edit Google Docs? @vy32 – incandescentman Oct 06 '13 at 06:56
  • By fetching the file to a local file, editing with emacsserver, and then pushing them back. – vy32 Oct 07 '13 at 01:22
  • 1
    It is slightly simpler to use the "google docs edit" command. Just set the `EDITOR` environmental variable to your emacsclient and use `google docs edit `. It will automatically download to a temp file and upload when you kill the emacs client buffer. Be warned that doing this erases any formatting in the google document. – manylegged Dec 03 '13 at 00:38
  • 1
    ```googlecl``` no longer works - returns an OAUTH1.0 error (seems it needs migrating to v2. – ayman Dec 25 '15 at 22:45
0

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.

vanni
  • 25
  • 2
  • 2
    When I try to edit my Google Drive files in Emacs, the files are empty and look like ![this](http://i.imgur.com/SJTwEEg.png). http://i.imgur.com/SJTwEEg.png – incandescentman Oct 11 '14 at 22:11
  • And when I try to create a text file in Emacs (foo.txt), the Google Drive web interface seems to be unable to read it. – incandescentman Oct 11 '14 at 22:15
  • This works for files stored on google drive that are NOT gdocs. As such it is useful, but the original question is about editing google docs. – Iain Nov 28 '19 at 11:36
0

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 " ")))))))
jagguli
  • 631
  • 1
  • 7
  • 21
0

It all seems to work if you open from a terminal, e.g.:

open -a emacs "Google Drive/My Drive/path/to/file.txt"

Saving the file works, but you can't open a new file once you're in emacs, and Google Drive seems to get confused if you try to create a new file from within emacs.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253