edit Google Docs using Emacs?
Asked Answered
E

4

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?

Emmyemmye answered 22/8, 2013 at 20:43 Comment(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.Attend
I
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.

Isolationist answered 5/10, 2013 at 22:0 Comment(4)
OK I installed googlecl. How do I use emacs server to edit Google Docs? @IsolationistEmmyemmye
By fetching the file to a local file, editing with emacsserver, and then pushing them back.Isolationist
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 <FILE>. 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.Nucellus
googlecl no longer works - returns an OAUTH1.0 error (seems it needs migrating to v2.Khania
J
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.

Jay answered 10/10, 2014 at 20:22 Comment(3)
When I try to edit my Google Drive files in Emacs, the files are empty and look like !this. i.imgur.com/SJTwEEg.pngEmmyemmye
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.Emmyemmye
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.Worthen
G
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 " ")))))))
Glabrescent answered 25/10, 2015 at 4:0 Comment(0)
Z
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.

Zwinglian answered 18/1, 2023 at 19:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.