Emacs bridge quick start

This page contains the generic quick start instruction for Emacs bridge. You also may want to check out the user manual for device specific setup options and other useful information.

For the basic configuration open this page in eww (M-x eww {{http/bindAddress}}:{{http/bindPort}}), scroll through the page, and evaluate (C-x e) all lisp snippets relevant to your setup. If you want to redo the initial setup you'll first need to clear the application data to enable access without auth token.

First the emacsbridge-auth-key variable needs to be configured. The following snippets try to autofill it by either a dynamically generated server key, or a statically set one:

(if (bound-and-true-p server-auth-key)
    (setq emacsbridge-auth-key server-auth-key)
  (progn
    (if (file-exists-p
         (concat server-auth-dir "/server"))
        (progn
          (with-temp-buffer
            (insert-file-contents
             (concat server-auth-dir "/server"))
            (setq emacsbridge-auth-key
                  (cadr (split-string
                         (buffer-string) "\n" t)))))
        (setq emacsbridge-auth-key nil))))

Next this key needs to be registered with Emacs bridge:

(let ((url-request-method "POST")
  (url-request-extra-headers
  '(("Content-Type" ."application/x-www-form-urlencoded")
  ("setting" . "server-key")))
  (url-request-data emacsbridge-auth-key))
  (switch-to-buffer
   (url-retrieve-synchronously
    "{{http/protocol}}://{{http/bindAddress}}:{{http/bindPort}}/settings")))

For a dynamic key this needs to be repeated on every start of Emacs. After the initial configuration the http auth key is required for that. Code to handle that (including re-trying if the application is not available on emacs startup) will be part of the support libraries.

If the above steps finished without error it should now be possible to trigger notifications via RPC:

(let ((url-request-method "POST")
      (url-request-extra-headers
       `(("Content-Type" ."application/json")
         ("auth-token" . ,emacsbridge-auth-token)
         ("method" . "notification")))
      (url-request-data
       "{\"title\": \"Title from Emacs\",
\"text\": \"Notification sent from Emacs via RPC\"}"))
  (switch-to-buffer
   (url-retrieve-synchronously
    "{{http/protocol}}://{{http/bindAddress}}:{{http/bindPort}}/rpc")))