Edit with Emacs is an extension for editing text areas in [[Google Chrome]] and [[FireFox]].

* Chrome Extension: https://chrome.google.com/extensions/detail/ljobjlafonikaiipfkggjbhkghgicgoh
* FireFox Add-On: https://addons.mozilla.org/en-US/firefox/addon/edit-with-emacs1/
* Development: http://github.com/stsquad/emacs_chrome

The extension requires an "edit server" to handle edit requests from Chrome(ium)/FireFox. This is due to the security model of Chrome preventing the execution of external applications. Fortunately the extension comes with a native elisp edit server which can run in your Emacs daemon session.

== Tips and Tricks ==

* If you use proxy, you may need to add "--proxy-bypass-list=127.0.0.1:9292" parameter to chrome command line.

=== Customisation ===

The extension has a number of variables that allow various behaviours to be customised. Currently they are:

* edit-server-new-frame - If not nil, edit each buffer in a new frame (and raise it)
* edit-server-new-frame-alist - Frame parameters for new frames.  See `default-frame-alist' for examples. If nil, the new frame will use the existing `default-frame-alist' values.

There are currently two hooks

* edit-server-start-hook - called with current buffer ready to edit
* edit-server-done-hook - called when the user has finished editing and exited the edit buffer.  For example, use the following to preserve textarea contents in the case of navigating away from the textarea page:

    (lambda () (kill-ring-save (point-min) (point-max)))

=== Controlling invocation ===

If you're already running an instance of Emacs in <code>--daemon</code> mode then you can wrap the code in something like:
<pre>
 (when (and (daemonp) (require 'edit-server nil :noerror))
   (edit-server-start))
</pre>

The edit
To open pages for editing in a new buffer instead of a new frame on
your running Emacs instance do:
<pre>
(when (require 'edit-server nil :noerror)
  (setq edit-server-new-frame nil)
  (edit-server-start))
</pre>

=== Integration with Google Mail ===

[http://gmailblog.blogspot.co.uk/2013/03/gmails-new-compose-now-default.html Gmail has switched to a new compose window]
which unfortunately breaks interaction with ##edit-server##.  However fortunately someone has hacked together a solution
for this: https://github.com/frobtech/edit-server-htmlize

To use, simply ensure that ##edit-server-htmlize.el## is on your ##load-path## and then do:

<pre>
(autoload 'edit-server-maybe-dehtmlize-buffer "edit-server-htmlize" "edit-server-htmlize" t)
(autoload 'edit-server-maybe-htmlize-buffer   "edit-server-htmlize" "edit-server-htmlize" t)
(add-hook 'edit-server-start-hook 'edit-server-maybe-dehtmlize-buffer)
(add-hook 'edit-server-done-hook  'edit-server-maybe-htmlize-buffer)
</pre>

=== Changing Default Mode ===

To have edit-server work in some other mode (other than text-mode), edit edit-server.el and
change this line:

<pre>
   (define-derived-mode edit-server-text-mode text-mode "Edit Server Text Mode"
</pre>
to something like:
<pre>
   (define-derived-mode edit-server-text-mode markdown-mode "Edit Server Text Mode"
</pre>

Or instead of editing edit-server.el add this:
<pre>
  (add-hook 'edit-server-start-hook 'markdown-mode)
</pre>

=== Integrating with other modes ===

TODO: Look at integrating as-external...


On OS X, running Aquamacs 2.1, how would I force Aquamacs to bring the new message frame above Chrome? Currently, a new frame is opened on top of Aquamacs, but below
Chrome.  Also, i think the ALT+E button doesn't function on Chrome 10.0.612.1 dev - no Aquamacs window is raised.

On OS X running Aquamacs (version 3.x development) : force Aquamacs to become the front application (bringing *all* frames forward, not just new "edit" frame) using:
(add-hook 'edit-server-start-hook
         (lambda ()
           (do-applescript "tell application \"Aquamacs\" to activate")))

I've described [https://aaron.baugher.biz/post/saving-blog-comments-in-org-part-2/ how to integrate edit-server with org-mode] to save edits to an org-mode task and clock the time spent on them.

----
CategoryHypermedia
