|
@@ -2,8 +2,11 @@
|
|
|
;; Emacs edit-server
|
|
;; Emacs edit-server
|
|
|
;;
|
|
;;
|
|
|
;; This provides an edit server to respond to requests from the Chrome
|
|
;; This provides an edit server to respond to requests from the Chrome
|
|
|
-;; Emacs Chrome plugin. Based on
|
|
|
|
|
-;; http://www.emacswiki.org/emacs/EmacsEchoServer to start with.
|
|
|
|
|
|
|
+;; Emacs Chrome plugin. This is my first attempt at doing something
|
|
|
|
|
+;; with sockets in Emacs. I based it on the following examples:
|
|
|
|
|
+;;
|
|
|
|
|
+;; http://www.emacswiki.org/emacs/EmacsEchoServer
|
|
|
|
|
+;; http://nullprogram.com/blog/2009/05/17/
|
|
|
;;
|
|
;;
|
|
|
;; (C) 2009 Alex Bennee (alex@bennee.com)
|
|
;; (C) 2009 Alex Bennee (alex@bennee.com)
|
|
|
;; Licensed under GPLv3
|
|
;; Licensed under GPLv3
|
|
@@ -12,7 +15,9 @@
|
|
|
|
|
|
|
|
; still debugging
|
|
; still debugging
|
|
|
(setq debug-on-error 't)
|
|
(setq debug-on-error 't)
|
|
|
|
|
+(setq edebug-all-defs 't)
|
|
|
|
|
|
|
|
|
|
+;; Vars
|
|
|
(defvar edit-server-port 9292
|
|
(defvar edit-server-port 9292
|
|
|
"Port the edit server listens too")
|
|
"Port the edit server listens too")
|
|
|
|
|
|
|
@@ -23,8 +28,6 @@
|
|
|
"Network process associated with the current edit, made local when
|
|
"Network process associated with the current edit, made local when
|
|
|
the edit buffer is create")
|
|
the edit buffer is create")
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
(defun edit-server-start nil
|
|
(defun edit-server-start nil
|
|
|
"Start the edit server"
|
|
"Start the edit server"
|
|
|
(interactive)
|
|
(interactive)
|
|
@@ -61,16 +64,19 @@
|
|
|
|
|
|
|
|
;;Get the content from the headers, we don't actually much care
|
|
;;Get the content from the headers, we don't actually much care
|
|
|
;;about the headers for now. I suspect this would break on Windows
|
|
;;about the headers for now. I suspect this would break on Windows
|
|
|
- (let ((content (cdr (split-string string "
\n
\n"))))
|
|
|
|
|
- (edit-server-create-edit-buffer proc content))))
|
|
|
|
|
|
|
+; (let ((content (cdr (split-string string "
\n
\n"))))
|
|
|
|
|
+; (edit-server-create-edit-buffer proc content))))
|
|
|
|
|
+ (edit-server-send-response proc "You got a response")))
|
|
|
|
|
|
|
|
(defun edit-server-create-edit-buffer(proc string)
|
|
(defun edit-server-create-edit-buffer(proc string)
|
|
|
"Create an edit buffer, place content in it and setup the call
|
|
"Create an edit buffer, place content in it and setup the call
|
|
|
backs"
|
|
backs"
|
|
|
(switch-to-buffer "edit-text-buffer")
|
|
(switch-to-buffer "edit-text-buffer")
|
|
|
- (set (make-local-variable 'edit-server-current-proc) 'proc)
|
|
|
|
|
- (local-set-key (kbd "C-x k") 'edit-server-done)
|
|
|
|
|
- (local-set-key (kbd "C-x C-s") 'edit-server-done)
|
|
|
|
|
|
|
+ (set (make-local-variable 'edit-server-current-proc) proc)
|
|
|
|
|
+; Can't do this, affects all buffers of same major mode, will need to
|
|
|
|
|
+; create a special mode to do this.
|
|
|
|
|
+; (local-set-key (kbd "C-x k") 'edit-server-done)
|
|
|
|
|
+; (local-set-key (kbd "C-x C-s") 'edit-server-done)
|
|
|
(insert string))
|
|
(insert string))
|
|
|
|
|
|
|
|
;
|
|
;
|
|
@@ -82,18 +88,23 @@ backs"
|
|
|
; For the text
|
|
; For the text
|
|
|
;
|
|
;
|
|
|
|
|
|
|
|
|
|
+(defun edit-server-send-response (proc string)
|
|
|
|
|
+ "Send a response back to the calling process with a string"
|
|
|
|
|
+ (interactive)
|
|
|
|
|
+ (message "edit-server-send-response")
|
|
|
|
|
+ (process-send-string proc "HTTP/1.0 200 OK
\n")
|
|
|
|
|
+ (process-send-string proc "Server: Emacs
\n")
|
|
|
|
|
+ (process-send-string proc "
\n")
|
|
|
|
|
+ (process-send-string proc string))
|
|
|
|
|
+
|
|
|
(defun edit-server-done()
|
|
(defun edit-server-done()
|
|
|
"Once someone is done with editing their text edit-server-done is
|
|
"Once someone is done with editing their text edit-server-done is
|
|
|
called and the response is sent back to the browser"
|
|
called and the response is sent back to the browser"
|
|
|
(interactive)
|
|
(interactive)
|
|
|
- (message "edit-server-done")
|
|
|
|
|
- (let (proc edit-server-current-proc)
|
|
|
|
|
- (process-send-string proc "HTTP/1.0 200 OK
\n")
|
|
|
|
|
- (process-send-string proc "Server: Emacs
\n")
|
|
|
|
|
- (process-send-string proc "
\n")
|
|
|
|
|
- (process-send-string proc (buffer-string))))
|
|
|
|
|
|
|
+ (edit-server-send-response edit-server-current-proc (buffer-string)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+; What do I need this for?
|
|
|
(defun edit-server-sentinel (proc msg)
|
|
(defun edit-server-sentinel (proc msg)
|
|
|
(delq proc edit-server-clients)
|
|
(delq proc edit-server-clients)
|
|
|
(message (format "client %s has quit" proc)))
|
|
(message (format "client %s has quit" proc)))
|