Explorar o código

More in progress hacking of the server script

Alex Bennee %!s(int64=16) %!d(string=hai) anos
pai
achega
42a3ccad7c
Modificáronse 1 ficheiros con 26 adicións e 15 borrados
  1. 26 15
      edit_server.el

+ 26 - 15
edit_server.el

@@ -2,8 +2,11 @@
 ;; Emacs edit-server
 ;;
 ;; 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)
 ;; Licensed under GPLv3
@@ -12,7 +15,9 @@
 
 ; still debugging
 (setq debug-on-error 't)
+(setq edebug-all-defs 't)
 
+;; Vars
 (defvar edit-server-port 9292
   "Port the edit server listens too")
 
@@ -23,8 +28,6 @@
   "Network process associated with the current edit, made local when
   the edit buffer is create")
 
-
-
 (defun edit-server-start nil
   "Start the edit server"
   (interactive)
@@ -61,16 +64,19 @@
 
     ;;Get the content from the headers, we don't actually much care
     ;;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)
   "Create an edit buffer, place content in it and setup the call
 backs"
   (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))
 
 ;
@@ -82,18 +88,23 @@ backs"
 ; 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()
   "Once someone is done with editing their text edit-server-done is
   called and the response is sent back to the browser"
   (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)
   (delq proc edit-server-clients)
   (message (format "client %s has quit" proc)))