changeset 31:ccd1ad69a852 rep_camp_20071111

*** empty log message ***
author gongo
date Fri, 21 Dec 2007 13:30:50 +0900
parents 9e43cec05dc5
children 62e709cbaaae
files redit-client-sm.el redit-client-sm.elc translate.el
diffstat 3 files changed, 119 insertions(+), 116 deletions(-) [+]
line wrap: on
line diff
--- a/redit-client-sm.el	Sun Nov 11 03:02:50 2007 +0900
+++ b/redit-client-sm.el	Fri Dec 21 13:30:50 2007 +0900
@@ -169,51 +169,60 @@
 (defun redit-join-command ()
   "Allow this Emacs process to be a remote-edit session manager for client processes."
   (interactive)
-  (if redit-client-process
-      (progn
-	(set-process-sentinel redit-client-process nil)
-	(condition-case () ;; 
-	    (delete-process redit-client-process) (error nil))))
-
-  (setq redit-client-process (open-network-stream
-			      "redit-client" nil "localhost" 8766))    
-
-  ;; called when the process changes state
-  (set-process-sentinel redit-client-process 'redit-client-sentinel)
-
-  ;; called when the process receive packet
-  (set-process-filter redit-client-process 'redit-client-process-filter)
-
-  ;; //Code of the process input/output buffer is rep-string-encoding
-  ;; //(set-process-coding-system redit-client-process rep-string-encoding rep-string-encoding)
-  ;; 送受信するデータは utf-8 じゃなくて バイナリで貰わないとずれる?可能性があるので
-  (set-process-coding-system redit-client-process 'binary 'binary)
+  (let (bufname)
+    (setq bufname (encode-coding-string
+		   (buffer-name)
+		   rep-string-encoding))
+    (if redit-client-process
+	(progn
+	  (set-process-sentinel redit-client-process nil)
+	  (condition-case () ;; 
+	      (delete-process redit-client-process) (error nil))))
+    
+    (setq redit-client-process (open-network-stream
+				"redit-client" nil "localhost" 8766))    
 
-  ;; プロセスが生きてるとき、 emacs を終了しようとすると
-  ;; 「processがうんたらで、本当に切ってもいいの y/n」
-  ;; って聞かれる。nil てやっておくと聞かれない。
-  ;; quit を入れるんなら t にして有効にすべきなんだろうか。
-  ;; 今は nil で
-  (set-process-query-on-exit-flag redit-client-process nil)
+    ;; called when the process changes state
+    (set-process-sentinel redit-client-process 'redit-client-sentinel)
+    
+    ;; called when the process receive packet
+    (set-process-filter redit-client-process 'redit-client-process-filter)
     
-  ;; not necessary since Emacs 21.1
-  ;; (make-local-hook 'before-change-functions)
-  ;; (make-local-hook 'after-change-functions)
+    ;; //Code of the process input/output buffer is rep-string-encoding
+    ;; //(set-process-coding-system redit-client-process rep-string-encoding rep-string-encoding)
+    ;; 送受信するデータはバイナリで貰わないといけない。
+    ;; utf-8 じゃなくてずれる可能性があるので
+    (set-process-coding-system redit-client-process 'binary 'binary)
+    
+    ;; プロセスが生きてるとき、 emacs を終了しようとすると
+    ;; 「processがうんたらで、本当に切ってもいいの y/n」
+    ;; って聞かれる。nil てやっておくと聞かれない。
+    ;; quit を入れるんなら t にして有効にすべきなんだろうか。
+    ;; 今は nil で
+    (set-process-query-on-exit-flag redit-client-process nil)
     
-  (if (string= "*scratch*" (buffer-name)) 
-    ;; JOIN if buffer-name is "*scratch*"
-    (process-send-string redit-client-process
-      (concat
-        (redit-pack
-	 redit-join-command
-	 0 0 0 0 0)))
-    ;; PUT if buffer-name is not "*scratch*"
-    (process-send-string redit-client-process
-      (concat
-        (redit-pack
+    ;; not necessary since Emacs 21.1
+    ;; (make-local-hook 'before-change-functions)
+    ;; (make-local-hook 'after-change-functions)
+    
+    (if (string= "*scratch*" bufname) 
+	;; JOIN if buffer-name is "*scratch*"
+	(process-send-string
+	 redit-client-process
+	 (concat
+	  (redit-pack
+	   redit-join-command
+	   0 0 0 0 0)))
+      ;; PUT if buffer-name is not "*scratch*"
+      (process-send-string
+       redit-client-process
+       (concat
+	(redit-pack
 	 redit-put-command
-	 0 0 0 0 (string-bytes (encode-coding-string (buffer-name) rep-string-encoding))) (buffer-name)))))
-
+	 0 0 0 0 (string-bytes bufname))
+	(buffer-name)))
+      )))
+  
 ;; 'get' is obsolete command
 ;; (defun redit-get-command ()
 ;;   "get. alias redit-join-command and redit-select-command."
@@ -224,19 +233,24 @@
 ;; select : select session
 ;; ユーザの入力を受け取って、selectコマンドを構成し、通信プロセスに渡す
 ;; (redit-select-command ()
-;;(defun redit-select-command (session-name)
-;;  "select session"
-;;  (interactive "P")
-;;  (if (setq session-name (read-string "session name:"))
-;;      (progn 
-;;	(setq redit-client-session-id (string-to-number session-name))
-;;	(process-send-string 
-;;	 redit-client-process
-;;	 (concat (format "%10d%10d%10d%10d%10d%10d" (string-to-number redit-select-command) redit-client-session-id redit-client-editor-id (gen-seqno) 0 0) session-name "\n"))
-;;	)
-;;    (error "invalid session name.")
-;;    )
-;;  )
+(defun redit-select-command (session-name)
+  "select session"
+  (interactive "P")
+  (if (setq session-name (read-string "session name:"))
+      (progn 
+	(setq redit-client-session-id (string-to-number session-name))
+	(process-send-string 
+	 redit-client-process
+	 (redit-pack
+	  redit-select-command redit-client-session-id redit-client-editor-id
+	  (gen-seqno) 0 0))
+	
+	;;(concat (format "%10d%10d%10d%10d%10d%10d" (string-to-number redit-select-command) redit-client-session-id redit-client-editor-id (gen-seqno) 0 0) session-name "\n"))
+	)
+    (error "invalid session name.")
+    )
+)
+
 
 ;; put-command は、join-command 内で
 ;; ファイルを開いてない *scratch* の時に呼び出されるので
@@ -554,7 +568,7 @@
 	(endl (real-count-lines end))	  ;; end の行番号
 	(currline))			  ;; currline = nil
 
-    (message "before-change-function")
+    ;; (message "before-change-function")
 
     ;; 前回の編集した行と今回の編集した行が
     ;; 違っていたら前回の編集をサーバへ送る
@@ -579,7 +593,7 @@
 	(endl (real-count-lines end))
 	(currline))
 
-    (message "after-change-function")
+    ;; (message "after-change-function")
 
     ;; 挿入処理で起こる。
     ;; (ex. 改行, C-y などのペースト, ...)
Binary file redit-client-sm.elc has changed
--- a/translate.el	Sun Nov 11 03:02:50 2007 +0900
+++ b/translate.el	Fri Dec 21 13:30:50 2007 +0900
@@ -1,5 +1,7 @@
 (eval-when-compile (require 'cl))
 
+(load-file "redit.el")
+
 (defstruct Queue (front nil) (rear nil))
 
 (defvar lc-queue nil
@@ -61,24 +63,11 @@
    (redit-pack-int cmd) (redit-pack-int sid) (redit-pack-int eid)
    (redit-pack-int seq) (redit-pack-int lno) (redit-pack-int siz)))
 
-
 (defun unpack-int (pkt byte)
   (let (num)
     (setq num (* byte 4))
     (string-to-char (substring pkt (- num 1) num))))
 
-(defun rep-get-command-from-pkt (pkt)
-  (unpack-int pkt 1))
-(defun rep-get-line-number-from-pkt (pkt)
-  (unpack-int pkt 5))
-
-(defvar redit-write-command          "6") ;; insert
-(defvar redit-delete-line-command    "9")
-(defvar redit-replace-command       "13")
-(defvar redit-nop-command           "15")
-
-
-
 ;; @param rcmd REPcommand queue of Remote Host
 ;; @param lcmd REPcommand queue of Local Host
 ;;  
@@ -110,53 +99,53 @@
        (llno (rep-get-line-number-from-pkt lcmd)))
 
     (if (= rlno llno)
-	(progn
-	  (cond ((= lc (string-to-number redit-write-command))
-		 ;; local REPcommand is insert
-		 (cond ((= rc (string-to-number redit-write-command))
-			;; remote REPcommand is insert
-			(message "local=i, remote=i lineno++ *")
-			)
-		       ((= rc (string-to-number redit-replace-command))
-			;; remote REPcommand is replace
-			(message "local=i, remote=r lineno++")
-			)
-		       ((= rc (string-to-number redit-delete-line-command))
-			;; remote REPcommand is delete
-			(message "local=i, remote=d lineno++")
-			))
-		 )
-		((= lc (string-to-number redit-replace-command))
-		 ;; local REPcommand is replace
-		 (cond ((= rc (string-to-number redit-write-command))
-			;; remote REPcommand is insert
-			(message "local=r, remote=i 0")
-			)
-		       ((= rc (string-to-number redit-replace-command))
-			;; remote REPcommand is replace
-			(message "local=r, remote=r cmd = NOP *")
-			)
-		       ((= rc (string-to-number redit-delete-line-command))
-			;; remote REPcommand is delete
-			(message "local=r, remote=d cmd = NOP")
-			))
-		 )
-		((= lc (string-to-number redit-delete-line-command))
-		 ;; local REPcommand is delete
-		 (cond ((= rc (string-to-number redit-write-command))
-			;; remote REPcommand is insert
-			(message "local=d, remote=i 0")
-			)
-		       ((= rc (string-to-number redit-replace-command))
-			;; remote REPcommand is replace
-			(message "local=d, remote=r cmd = insert")
-			)
-		       ((= rc (string-to-number redit-delete-line-command))
-			;; remote REPcommand is delete
-			(message "local=d, remote=d cmd = nop")
-			))
-		 ))
-	  ))
+	;;(progn
+	(cond ((= lc redit-insert-command)
+	       ;; local REPcommand is insert
+	       (cond ((= rc redit-insert-command)
+		      ;; remote REPcommand is insert
+		      (message "local=i, remote=i lineno++ *")
+		      )
+		     ((= rc redit-replace-command)
+		      ;; remote REPcommand is replace
+		      (message "local=i, remote=r lineno++")
+		      )
+		     ((= rc redit-delete-line-command)
+		      ;; remote REPcommand is delete
+		      (message "local=i, remote=d lineno++")
+		      ))
+	       )
+	      ((= lc redit-replace-command)
+	       ;; local REPcommand is replace
+	       (cond ((= rc redit-insert-command)
+		      ;; remote REPcommand is insert
+		      (message "local=r, remote=i 0")
+		      )
+		     ((= rc redit-replace-command)
+		      ;; remote REPcommand is replace
+		      (message "local=r, remote=r cmd = NOP *")
+		      )
+		     ((= rc redit-delete-line-command)
+		      ;; remote REPcommand is delete
+		      (message "local=r, remote=d cmd = NOP")
+		      ))
+	       )
+	      ((= lc redit-delete-line-command)
+	       ;; local REPcommand is delete
+	       (cond ((= rc redit-insert-command)
+		      ;; remote REPcommand is insert
+		      (message "local=d, remote=i 0")
+		      )
+		     ((= rc redit-replace-command)
+		      ;; remote REPcommand is replace
+		      (message "local=d, remote=r cmd = insert")
+		      )
+		     ((= rc redit-delete-line-command)
+		      ;; remote REPcommand is delete
+		      (message "local=d, remote=d cmd = nop")
+		      ))
+	       )
+	      ))
     ))
 
 ;; rcmd[0] <> lcmd[0]