Mercurial > hg > RemoteEditor > emacs
changeset 6:5796f9efc332
*** empty log message ***
author | gongo |
---|---|
date | Tue, 12 Dec 2006 11:02:31 +0900 |
parents | ee15fce75335 |
children | 6b82a318980c |
files | ChangeLog line-merge.el redit-client-sm.el redit-client-sm.elc redit_client.pl |
diffstat | 5 files changed, 502 insertions(+), 417 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ChangeLog Tue Dec 12 11:02:31 2006 +0900 @@ -0,0 +1,23 @@ +2006-12-12 Wataru MIYAGUNI <gongo@cr.ie.u-ryukyu.ac.jp> + + * redit-client-sm.el + obsolete function を変更 + + since Emacs 22.1 + >> old: (process-kill-without-query redit-client-process) + >> new: (set-process-query-on-exit-flag redit-client-process nil) + 第2引数が non-nil だと、emacs終了時に + 「`Active processes exist; kill them and exit anyway?' 」 + って聞いてきます。process は redit_client.pl のことです。 + 多分いらないので nil を入れました。 + + since Emacs 21.1 + >> old: (make-local-hook 'before-change-functions) ;; afterも + >> new: not necessary + なんか要らないらしいです。21.1以前だと必須みたいですが。 + + + * redit-client-sm.el + defstruct を使うときは + (eval-when-compile (require 'cl)) を加えた後に + byte-compile-file してからやると使える。
--- a/line-merge.el Sun Oct 22 17:29:02 2006 +0900 +++ b/line-merge.el Tue Dec 12 11:02:31 2006 +0900 @@ -1,13 +1,13 @@ -; -; USER -; | i | r | d -; ---|-------------------- -;T i | 0\+1 | 0\+1 | 0\+1 -;O ---|-------------------- -;K r | +1\0 | 0\X | i\X -;E ---|-------------------- -;N d | +1\0 | X\i | X\X -; +;; +;; USER +;; | i | r | d +;; ---|-------------------- +;;T i | 0\+1 | 0\+1 | 0\+1 +;;O ---|-------------------- +;;K r | +1\0 | 0\X | i\X +;;E ---|-------------------- +;;N d | +1\0 | X\i | X\X +;; (defun dequeue-all (queue) "clean queue" (while (Queue-front queue) @@ -24,7 +24,7 @@ (setq cc (car cque)) (while rque (setq rc (car rque)) -;-------- translation ------------ +;;-------- translation ------------ (if (< (+ (redit-get-line cc) xcc) (+ (redit-get-line rc) xrc)) (if (= (redit-get-command cc) (string-to-number redit-write-command)) (setq xrc (- xrc 1))) @@ -46,25 +46,25 @@ (if (= (redit-get-command cc) (string-to-number redit-replace-command)) (setq cignore 1)) (if (= (redit-get-command cc) (string-to-number redit-delete-line-command)) (setq cignore 1) (setq rignore 1))) -;-------- translation ------------ +;;-------- translation ------------ - (setq rque (cdr rque))) ; while rque + (setq rque (cdr rque))) ;; while rque - ;ignore + ;;ignore (if (= cignore 1) - ;xxx + ;;xxx (setq cignore 0)) (if (= rignore 1) - ;xxx + ;;xxx (setq cignore 0)) -;-------- add after que ------------ +;;-------- add after que ------------ (enqueue after-CQ (concat (format "%2d%2d%9d" (redit-get-command cc) (redit-get-uid cc) (+ (redit-get-line cc) xcc)) (redit-get-text cc))) -;-------- add after que ------------ +;;-------- add after que ------------ - (setq cque (cdr cque))) ; while cque - ) ; let -) ;defun + (setq cque (cdr cque))) ;; while cque + ) ;; let +) ;;defun (defun redit-line-translate-in (cque rque) "redit line translate for input" @@ -79,7 +79,7 @@ (setq rignore 0) (while cque (setq cc (car cque)) -;-------- translation ------------ +;;-------- translation ------------ (if (and (= cignore 1) (= rignore 1)) (if (< (+ (redit-get-line rc) xrc) (+ (redit-get-line cc) xcc)) @@ -101,22 +101,22 @@ (if (= (redit-get-command rc) (string-to-number redit-replace-command)) (setq crc redit-write-command) (setq cignore 1)) (if (= (redit-get-command rc) (string-to-number redit-delete-line-command)) (setq cignore 1) (setq rignore 1)))) -;-------- translation ------------ +;;-------- translation ------------ - (setq cque (cdr cque))) ; while rque + (setq cque (cdr cque))) ;; while rque - ;ignore + ;;ignore (if (= cignore 1) - ;xxx + ;;xxx (setq cignore 0)) (if (= rignore 1) - ;xxx + ;;xxx (setq rignore 0)) -;-------- add after que ------------ +;;-------- add after que ------------ (enqueue after-RQ (concat (format "%2d%2d%9d" (redit-get-command rc) (redit-get-uid rc) (+ (redit-get-line rc) xrc)) (redit-get-text rc))) -;-------- add after que ------------ +;;-------- add after que ------------ - (setq rque (cdr rque))) ; while cque - ) ; let -) ;defun + (setq rque (cdr rque))) ;; while cque + ) ;; let +) ;;defun
--- a/redit-client-sm.el Sun Oct 22 17:29:02 2006 +0900 +++ b/redit-client-sm.el Tue Dec 12 11:02:31 2006 +0900 @@ -1,16 +1,14 @@ -; $Id$ -; (defcustom redit-client-program "/usr/home/masasi/work/redit/reditclient" -;(defcustom redit-client-program "/usr/home/shinobu/redit/demo/reditclient" -; (defcustom redit-client-program "/Users/dot/work/REP_project/emacs/redit_client.pl" -(defcustom redit-client-program "/home/dot/work/REP_project/emacs/redit_client.pl" +;; $Id$ +(defcustom redit-client-program "/Users/gongo/src/member/gongo/redit-emacs/redit_client.pl" "The program to use as the remote-edit client." :group 'redit :type 'string) -; 送受信されるコマンドは -; 2 + 2 + 9 + data -; command_number + buffer_number + line_number + data +;; 送受信されるコマンドは +;; 2 + 2 + 9 + data +;; command_number + buffer_number + line_number + data +(eval-when-compile (require 'cl)) (defvar redit-client-process nil "Remote-edit client process.") @@ -30,7 +28,7 @@ (defvar redit-client-session-id 0 "Remote-edit client's session-id.") -; editor local sequence number +;; editor local sequence number (defvar redit-client-seqno 0 "Remote-edit client's editor-id.") @@ -54,7 +52,7 @@ (defvar redit-read-command "3") (defvar redit-read-ack "4") (defvar redit-read-finish-ack "5") -(defvar redit-write-command "6") ; insert +(defvar redit-write-command "6") ;; insert (defvar redit-write-still-ack "7") (defvar redit-write-finish-ack "8") (defvar redit-delete-line-command "9") @@ -79,13 +77,13 @@ (defvar redit-quit-command "53") (defvar redit-quit-ack-command "54") -; Queue struct -(defstruct Queue (front nil) (rear nil)) +;; Queue struct +(defstruct Queue (front nil) (rear nil)) (setq redit-client-command-queue (make-Queue)) (setq redit-client-receive-queue (make-Queue)) (setq redit-client-send-queue (make-Queue)) -;line translated que +;; line translated queue (setq after-CQ (make-Queue)) (setq after-RQ (make-Queue)) @@ -95,39 +93,44 @@ (if redit-client-process (progn (set-process-sentinel redit-client-process nil) - (condition-case () ; エラーが起こるとプロセスを消す + (condition-case () ;; エラーが起こるとプロセスを消す (delete-process redit-client-process) (error nil)))) - (if (setq host (read-string "Hostname: ")); minibufferでホスト名を入力させる + (if (setq host (read-string "Hostname: "));; minibufferでホスト名を入力させる (let ((process-connection-type nil)) - ; クライアントプロセス(redit-client)内のプログラムをスタートさせる。 - ; 引き数として host が与えられる + ;; クライアントプロセス(redit-client)内のプログラムをスタートさせる。 + ;; 引き数として host が与えられる (setq redit-client-process (start-process "reditclient" nil redit-client-program host)) - ; redit-client-process の状態が変化すると redit-client-sentinel を呼ぶ + ;; redit-client-process の状態が変化すると redit-client-sentinel を呼ぶ (set-process-sentinel redit-client-process 'redit-client-sentinel) - ; redit-client-process からのデータ入力は redit-client-process-filter - ; を介する + ;; redit-client-process からのデータ入力は redit-client-process-filter + ;; を介する (set-process-filter redit-client-process 'redit-client-process-filter) - ; redit-client-process からの入出力を 8-bit codes で取扱う。 + ;; redit-client-process からの入出力を 8-bit codes で取扱う。 (set-process-coding-system redit-client-process 'raw-text 'raw-text) - ; emacs が終了すると redit-client-process も終了する - (process-kill-without-query redit-client-process) - ; フック変数 before-change-functions, after-change-functions - ;をバッファローカルにする - (make-local-hook 'before-change-functions) - (make-local-hook 'after-change-functions) + ;; emacs が終了すると redit-client-process も終了する + ;; process-kill-without-query is an obsolete function + ;; (process-kill-without-query redit-client-process) + ;;(process-query-on-exit-flag redit-client-process) + (set-process-query-on-exit-flag redit-client-process nil) + + ;; フック変数 before-change-functions, after-change-functions + ;; をバッファローカルにする + ;; not necessary since Emacs 21.1 + ;; (make-local-hook 'before-change-functions) + ;; (make-local-hook 'after-change-functions) (message "Remote edit client started.")) (error "redit-client connection refused."))) - ; (redit-join-command ()) + ;; (redit-join-command ()) (defun redit-join-command (host) "Allow this Emacs process to be a remote-edit session manager for client processes." (interactive "P") (if redit-client-process (progn (set-process-sentinel redit-client-process nil) - (condition-case () ; + (condition-case () ;; (delete-process redit-client-process) (error nil)))) (if (setq host (read-string "Hostname: ")) (let ((process-connection-type nil)) @@ -137,72 +140,78 @@ (set-process-filter redit-client-process 'redit-client-process-filter) (set-process-coding-system redit-client-process 'raw-text 'raw-text) - (process-kill-without-query redit-client-process) - ; (make-local-hook 'before-change-functions) - ; (make-local-hook 'after-change-functions) - ; FIXME - ; concat my hostname this command? + + ;; process-kill-without-query is an obsolete function + ;; (process-kill-without-query redit-client-process) + ;; (process-query-on-exit-flag redit-client-process) + (set-process-query-on-exit-flag redit-client-process nil) + + ;; not necessary since Emacs 21.1 + ;; (make-local-hook 'before-change-functions) + ;; (make-local-hook 'after-change-functions) + ;; FIXME + ;; concat my hostname this command? (process-send-string redit-client-process (concat (format "%10d%10d%10d%10d%10d%10d" (string-to-number redit-join-command) 0 0 (gen-seqno) 0 0) "\n"))) (error "redit-client connection refused."))) - ; (redit-get-command) - (defun redit-get-command () +;; (redit-get-command) +(defun redit-get-command () "get. alias redit-join-command and redit-select-command." - (interactive) - (redit-join-command ()) - (redit-select-command ())) + (interactive) + (redit-join-command ()) + (redit-select-command ())) - ; select : select session - ; ユーザの入力を受け取って、selectコマンドを構成し、通信プロセスに渡す - ; (redit-select-command () - (defun redit-select-command (session-name) +;; 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")) - ) + (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-put-command () - ; "put" - ; (interactive) - ; ) - (defun redit-put-command (session-name) +;; (defun redit-put-command () +;; "put" +;; (interactive) +;; ) +(defun redit-put-command (session-name) "put session" (interactive "P") (if (setq session-name (read-string "put session name:")) - (process-send-string - redit-client-process - (concat (format "%10d%10d%10d%10d%10d%10d" (string-to-number redit-put-command) redit-client-session-id redit-client-editor-id (gen-seqno) 0 0) session-name "\n")) + (process-send-string + redit-client-process + (concat (format "%10d%10d%10d%10d%10d%10d" (string-to-number redit-put-command) redit-client-session-id redit-client-editor-id (gen-seqno) 0 0) session-name "\n")) (error "invalid session name.") ) ) - (defun redit-register-command (session-name) +(defun redit-register-command (session-name) "register" (interactive "P") (if (setq session-name (read-string "session name:")) - (process-send-string - redit-client-process - (concat (format "%10d%10d%10d%10d%10d%10d" (string-to-number redit-register-command) redit-client-session-id redit-client-editor-id (gen-seqno) 0 0) session-name "\n")) + (process-send-string + redit-client-process + (concat (format "%10d%10d%10d%10d%10d%10d" (string-to-number redit-register-command) redit-client-session-id redit-client-editor-id (gen-seqno) 0 0) session-name "\n")) (error "invalid session name.") ) ) - (defun redit-deregister-command () +(defun redit-deregister-command () "deregister" (interactive) ) - (defun redit-quit-command () +(defun redit-quit-command () "quit" (interactive) ) @@ -212,88 +221,82 @@ (if redit-client-process (if (setq file (read-string "Filename: ")) (progn - ; redit-client-process の input に文字列を送信する + ;; redit-client-process の input に文字列を送信する (process-send-string redit-client-process - ; redit-open-command (01) と file を連結させる + ;; redit-open-command (01) と file を連結させる (concat redit-open-command file)) - ; redit-client-process から出力を得るまでループ + ;; redit-client-process から出力を得るまでループ (while (eq nil (accept-process-output redit-client-process))))) (error "redit-client is not running."))) -; redit-client-process にreadコマンドとバッファ番号、行番号を送り、 -; サーバからの出力を得る +;; redit-client-process にreadコマンドとバッファ番号、行番号を送り、 +;; サーバからの出力を得る (defun redit-client-read-line (linenum) (if redit-client-process (save-excursion (progn (process-send-string redit-client-process - (format "%10d%10d%10d%10d%10d%10d\n" (string-to-number redit-read-command) redit-client-session-id redit-client-editor-id (gen-seqno) linenum 0)) + (format "%10d%10d%10d%10d%10d%10d\n" (string-to-number redit-read-command) redit-client-session-id redit-client-editor-id (gen-seqno) linenum 0)) (while (eq nil (accept-process-output redit-client-process))))) (error "redit-client is not running."))) -; linenumで指定された行の編集をサーバへ送る -; redit-client-process にwriteコマンドとバッファ番号、行番号、行の内容を送り、 -; Ack を受け取る +;; linenumで指定された行の編集をサーバへ送る +;; redit-client-process にwriteコマンドとバッファ番号、行番号、行の内容を送り、 +;; Ack を受け取る (defun redit-client-write-line (linenum isnewline) (if redit-client-process (save-excursion - (let ((beginp) (endp) (length)) - ; write lines on server buffer - (setq beginp - (progn (goto-line linenum) (point))) - (setq endp - (progn (goto-line linenum) (end-of-line) (point))) - (setq length (- endp beginp)) + (let ((beginp) (endp) (length)) + ;; write lines on server buffer + (setq beginp + (progn (goto-line linenum) (point))) + (setq endp + (progn (goto-line linenum) (end-of-line) (point))) + (setq length (- endp beginp)) - ; トークンが回ってくるのを待つ場合は、すぐに process-send-string せずに編集情報を保存するだけにとどめる - - ; redit-client-command-queueに編集情報を保存する - (enqueue redit-client-command-queue + ;; トークンが回ってくるのを待つ場合は、 + ;; すぐに process-send-string せずに + ;; 編集情報を保存するだけにとどめる + (enqueue redit-client-command-queue (concat (format "%10d%10d%10d%10d%10d%10d" (string-to-number redit-write-command) redit-client-session-id redit-client-editor-id (gen-seqno) linenum length) - (buffer-substring beginp endp) - (if (eq isnewline t) - "\n") "\n")) + (buffer-substring beginp endp) + (if (eq isnewline t) "\n") + "\n")) - ; redit-client-process へ command_num + buffer_num + line_num + string - ;の文字列を送る - (process-send-string - redit-client-process - (concat (format "%10d%10d%10d%10d%10d%10d" (string-to-number redit-write-command) redit-client-session-id redit-client-editor-id (gen-seqno) linenum length) - (buffer-substring beginp endp) - (if (eq isnewline t) - "\n") "\n")) - ;(while (eq nil - ; (accept-process-output redit-client-process 1))))) - )) + ;; redit-client-process へ + ;; command_num + buffer_num + line_num + string + ;; の文字列を送る + (process-send-string + redit-client-process + (concat (format "%10d%10d%10d%10d%10d%10d" (string-to-number redit-write-command) redit-client-session-id redit-client-editor-id (gen-seqno) linenum length) + (buffer-substring beginp endp) + (if (eq isnewline t) "\n") + "\n")) + )) (error "redit-client is not running."))) -; linenum で指定した行の削除命令を redit-client-process に送信する +;; linenum で指定した行の削除命令を redit-client-process に送信する (defun redit-client-delete-line (linenum) (if redit-client-process (save-restriction - ; トークンが回ってくるのを待つ場合は、すぐに process-send-string せずに編集情報を保存するだけにとどめる + ;; トークンが回ってくるのを待つ場合は、 + ;; すぐに process-send-string せずに + ;; 編集情報を保存するだけにとどめる + (enqueue redit-client-command-queue + (concat (format "%10d%10d%10d%10d%10d%10d" (string-to-number redit-delete-line-command) redit-client-session-id redit-client-editor-id (gen-seqno) linenum 0) "\n")) - ; redit-client-command-queueに編集情報を保存する - (enqueue redit-client-command-queue - (concat (format "%10d%10d%10d%10d%10d%10d" (string-to-number redit-write-command) redit-client-session-id redit-client-editor-id (gen-seqno) linenum length) - (buffer-substring beginp endp) - (if (eq isnewline t) - "\n") "\n")) - - ; write lines on server buffer + ;; write lines on server buffer (process-send-string redit-client-process (concat (format "%10d%10d%10d%10d%10d%10d" (string-to-number redit-delete-line-command) redit-client-session-id redit-client-editor-id (gen-seqno) linenum 0) "\n")) - ;(while (eq nil - ; (accept-process-output redit-client-process 1)))) - ) + ) (error "redit-client is not running."))) -; redit-client-process へcloseコマンドを送る +;; redit-client-process へcloseコマンドを送る (defun redit-client-close () "Save File and exit Remote-edit client." (interactive) @@ -303,7 +306,7 @@ redit-client-process (concat (format "%10d%10d%10d%10d%10d%10d" (string-to-number redit-close-command) redit-client-session-id redit-client-editor-id (gen-seqno) linenum 0) "\n")))) -; redit-client-process を終了させる +;; redit-client-process を終了させる (defun redit-client-kill () "Stop Remote-Edit client process." (interactive) @@ -313,91 +316,93 @@ (kill-buffer redit-client-buffer)) (kill-all-local-variables)) -; proc == redit-client-process -; string == redit-client-process からの output +;; proc == redit-client-process +;; string == redit-client-process からの output (defun redit-client-process-filter (proc string) - ;バッファローカルなフックリスト before-change-functions から - ;redit-client-before-change-function を取り除く. after も同じ + ;; バッファローカルなフックリスト before-change-functions から + ;; redit-client-before-change-function を取り除く. after も同じ (remove-hook 'before-change-functions 'redit-client-before-change-function t) (remove-hook 'after-change-functions 'redit-client-after-change-function t) - ; (message string) ;; add + ;; (message string) ;; add (let ((command (rep-get-command-from-pkt string))) - ;command がどの命令かを判断し、対応した処理をする。case みたい + ;; command がどの命令かを判断し、対応した処理をする。case みたい (cond - ; FIXME + ;; FIXME ((if (= command (string-to-number redit-open-ack)) - (if (/= redit-client-editor-id) - (redit-client-exec-open-ack string)))) + (if (/= redit-client-editor-id) + (redit-client-exec-open-ack string)))) - ((if (= command (string-to-number redit-read-ack)) - (if (= redit-client-editor-id (rep-get-editor-id-from-pkt string)) - (redit-client-exec-read-ack string)))) + ((if (= command (string-to-number redit-read-ack)) + (if (= redit-client-editor-id (rep-get-editor-id-from-pkt string)) + (redit-client-exec-read-ack string)))) ((if (= command (string-to-number redit-write-still-ack)) - (if (= redit-client-editor-id (rep-get-editor-id-from-pkt string)) - (redit-client-exec-write-still-ack string)))) + (if (= redit-client-editor-id (rep-get-editor-id-from-pkt string)) + (redit-client-exec-write-still-ack string)))) ((if (= command (string-to-number redit-delete-line-ack)) - (if (= redit-client-editor-id (rep-get-editor-id-from-pkt string)) - (redit-client-exec-delete-line-ack string)))) + (if (= redit-client-editor-id (rep-get-editor-id-from-pkt string)) + (redit-client-exec-delete-line-ack string)))) ((if (= command (string-to-number redit-close-ack)) - (if (= redit-client-editor-id (rep-get-editor-id-from-pkt string)) - (redit-client-exec-close-ack string)))) + (if (= redit-client-editor-id (rep-get-editor-id-from-pkt string)) + (redit-client-exec-close-ack string)))) ((if (= command (string-to-number redit-write-command)) - (if (/= redit-client-editor-id (rep-get-editor-id-from-pkt string)) - (redit-client-exec-write-line string)))) + (if (/= redit-client-editor-id (rep-get-editor-id-from-pkt string)) + (redit-client-exec-write-line string)))) - ; from Session Manager + ;; from Session Manager - ; join ack (editor id) - ; editor id を保存する + ;; join ack (editor id) + ;; editor id を保存する ((if (= command (string-to-number redit-join-ack-command)) (redit-client-exec-join string))) - ; put ack (editor id) - ; session id を保存する + ;; put ack (editor id) + ;; session id を保存する ((if (= command (string-to-number redit-put-ack-command)) (redit-client-exec-put string))) - ; select ack - ; TODO : start editing + ;; select ack + ;; TODO : start editing ((if (= command (string-to-number redit-select-ack-command)) - (progn - (add-hook 'before-change-functions - 'redit-client-before-change-function t t) - (add-hook 'after-change-functions - 'redit-client-after-change-function t t)))) - - ; get + (progn + (redit-client-exec-select) + ;;(add-hook 'before-change-functions + ;;'redit-client-before-change-function t t) + ;;(add-hook 'after-change-functions + ;;'redit-client-after-change-function t t)))) + ))) + ;; get ((if (= command (string-to-number redit-get-command)) - (if (= redit-client-editor-id (rep-get-editor-id-from-pkt string)) - (redit-client-exec-get string)))) - ; register + (if (= redit-client-editor-id (rep-get-editor-id-from-pkt string)) + (redit-client-exec-get string)))) + ;; register ((if (= command (string-to-number redit-register-command)) - (if (= redit-client-editor-id (rep-get-editor-id-from-pkt string)) - (redit-client-exec-register string)))) - ; deregister + (if (= redit-client-editor-id (rep-get-editor-id-from-pkt string)) + (redit-client-exec-register string)))) + ;; deregister ((if (= command (string-to-number redit-deregister-command)) - (if (= redit-client-editor-id (rep-get-editor-id-from-pkt string)) - (redit-client-exec-deregister string)))) + (if (= redit-client-editor-id (rep-get-editor-id-from-pkt string)) + (redit-client-exec-deregister string)))) - ; delete line + ;; delete line ((if (= command (string-to-number redit-delete-line-command)) - (if (/= redit-client-editor-id (rep-get-editor-id-from-pkt string)) - (redit-server-exec-delete-line string)))) + (if (/= redit-client-editor-id (rep-get-editor-id-from-pkt string)) + (redit-client-exec-delete-line string)))) + ;; (redit-server-exec-delete-line string)))) ((string-equal string "")))) - ;(add-hook 'before-change-functions - ; 'redit-client-before-change-function t t) - ;(add-hook 'after-change-functions - ; 'redit-client-after-change-function t t) - ) -; window-scroll-functions に hook される。 -; window がスクロールする度に呼ばれる + (add-hook 'before-change-functions + 'redit-client-before-change-function t t) + (add-hook 'after-change-functions + 'redit-client-after-change-function t t) + ) +;; window-scroll-functions に hook される。 +;; window がスクロールする度に呼ばれる (defun redit-client-update-function (window window-start) (if (equal (window-buffer) redit-client-buffer) (save-excursion @@ -405,12 +410,12 @@ 'redit-client-before-change-function t) (remove-hook 'after-change-functions 'redit-client-after-change-function t) - ; read part. + ;; read part. (while (and (= (point-max) (window-end nil t)) (> redit-client-line-max-in-server (real-count-lines (window-end nil t)))) -; (count-lines (window-end nil t)))) + ;; (count-lines (window-end nil t)))) (redit-client-read-line (real-count-lines (window-end nil t)))) (if (not (= (count-lines (point-min) (window-end nil t)) @@ -431,7 +436,7 @@ (add-hook 'after-change-functions 'redit-client-after-change-function t t)))) -; currentp の位置の行数を返す +;; currentp の位置の行数を返す (defun real-count-lines (currentp) (+ (count-lines (point-min) currentp) (if (= (save-excursion (goto-char currentp) (current-column)) @@ -445,191 +450,225 @@ (setq exprs (cdr exprs))) (goto-char saved-point))) -; before-change-functions に hook される -; バッファに変更があるたびに呼ばれる。バッファが変更される前に呼ばれる。 -; begin と end には変更前の変更部分の始まりと終わりの point が入る +;; before-change-functions に hook される +;; バッファに変更があるたびに呼ばれる。バッファが変更される前に呼ばれる。 +;; begin と end には変更前の変更部分の始まりと終わりの point が入る (defun redit-client-before-change-function (begin end) - ; check delete - ; (message "call redit-client-before-change-function") - (let ((beginl (real-count-lines begin)) ; begin の行番号 - (endl (real-count-lines end)) ; end の行番号 - (currline)) ; currline = nil - ;前回の編集した行と今回の編集した行が違っていたら前回の編集をサーバへ送る + ;; check delete + ;; (message "call redit-client-before-change-function") + (let ((beginl (real-count-lines begin)) ;; begin の行番号 + (endl (real-count-lines end)) ;; end の行番号 + (currline)) ;; currline = nil + ;; 前回の編集した行と今回の編集した行が違っていたら前回の編集をサーバへ送る + ;; (message (concat "before = " (number-to-string beginl) " : " (number-to-string endl))) (if (not (= beginl redit-client-previous-edited-line)) (redit-client-write-line redit-client-previous-edited-line nil)) (if (< beginl endl) (progn (setq currline endl) - ; endlからbeginlまで行の削除命令を出す + ;; endlからbeginlまで行の削除命令を出す (while (> currline beginl) (redit-client-delete-line endl) (setq currline (- currline 1))))))) - -; after-change-functions に hook される -; バッファに変更があるたびに呼ばれる。バッファが変更された後に呼ばれる -; begin と end には変更後の変更部分の始まりと終わりの point が入る +;; after-change-functions に hook される +;; バッファに変更があるたびに呼ばれる。バッファが変更された後に呼ばれる +;; begin と end には変更後の変更部分の始まりと終わりの point が入る (defun redit-client-after-change-function (begin end length) - ; check insert - ; (message "call redit-client-after-change-function") + ;; check insert + ;; (message "call redit-client-after-change-function") (let ((beginl (real-count-lines begin)) (endl (real-count-lines end)) (currline)) + (message (concat "after = " (number-to-string beginl) " : " (number-to-string endl))) (if (< beginl endl) (progn (setq currline beginl) - ; beginlからendlまで挿入命令を出す - (while (< currline endl) - (progn (redit-client-write-line beginl nil);t) + ;; beginlからendlまで挿入命令を出す + (while (<= currline endl) + (progn (redit-client-write-line beginl nil) ;; t) (setq currline (+ currline 1)))))) (setq redit-client-previous-edited-line endl))) - -; 引き数で与えられた string (line_num + text_data) から -; 指定された行を削除し、そこに text_data を挿入する +;; 引き数で与えられた string (line_num + text_data) から +;; 指定された行を削除し、そこに text_data を挿入する (defun redit-client-exec-write-line (string) - (let ((linenum (rep-get-line-number-from-pkt string)) ; 行番号 - (text (rep-get-text-from-pkt string))) ; テキストデータ - (if (< (real-count-lines (point-max)) linenum) - (progn - (end-of-buffer) - (newline))) - (goto-line linenum) - (delete-region (progn (beginning-of-line) (point)); 行の頭から - (progn (end-of-line) (point))) ; 行の末尾まで削除 - (insert text))) ; テキストデータを挿入 +(let ((linenum (rep-get-line-number-from-pkt string)) ;; 行番号 + (text (rep-get-text-from-pkt string))) ;; テキストデータ + (if (< (real-count-lines (point-max)) linenum) + (progn + (end-of-buffer) + (newline))) + (goto-line linenum) + (delete-region (progn (beginning-of-line) (point)) ;; 行の頭から + (progn (end-of-line) (point))) ;; 行の末尾まで削除 + (insert text) ;; テキストデータを挿入 + ;;(add-hook 'before-change-functions + ;;'redit-client-before-change-function t t) + ;;(add-hook 'after-change-functions + ;;'redit-client-after-change-function t t))) +)) -; 引き数 string (line_num + text_data) で指定された行を削除する +;; 引き数 string (line_num + text_data) で指定された行を削除する (defun redit-client-exec-delete-line (string) - (let ((linenum (rep-get-line-number-from-pkt string))) - (goto-line linenum) - ; 行頭から末尾までのテキストを削除 - (delete-region (progn (beginning-of-line) (point)) - (progn (end-of-line) (point))) - ; 指定された行自体を削除 - ; 指定された行番号は別の行の番号を表すことになる - (if (= (point) (point-max)) - (delete-backward-char 1) - (delete-char 1)))) +(let ((linenum (rep-get-line-number-from-pkt string))) + (goto-line linenum) + ;; 行頭から末尾までのテキストを削除 + (delete-region (progn (beginning-of-line) (point)) + (progn (end-of-line) (point))) + ;; 指定された行自体を削除 + ;; 指定された行番号は別の行の番号を表すことになる + (if (= (point) (point-max)) + (delete-backward-char 1) + (delete-char 1))) +;;(add-hook 'before-change-functions +;;'redit-client-before-change-function t t) +;;(add-hook 'after-change-functions +;;'redit-client-after-change-function t t) +) -; 引き数 string (buf_num + line_num + text_data) +;; 引き数 string (buf_num + line_num + text_data) (defun redit-client-exec-open-ack (string) - (save-excursion - (let ((bufnum (rep-get-editor-id-from-pkt string)) - (linenum (rep-get-line-number-from-pkt string))) - (make-variable-buffer-local 'redit-client-buffer-name) - (make-variable-buffer-local 'redit-client-editor-id) - (setq redit-client-buffer-name - (rep-get-text-from-pk string)) - (setq redit-client-buffer (get-buffer-create redit-client-buffer-name)) - ; プロセスとバッファを関連づける - (set-process-buffer redit-client-process redit-client-buffer) - (switch-to-buffer redit-client-buffer) ; windowのバッファを変更する - (make-variable-buffer-local 'redit-client-previous-edited-line) - (make-variable-buffer-local 'redit-client-after-edited-line) - (make-variable-buffer-local 'redit-client-line-max-in-server) - (make-variable-buffer-local 'redit-client-previous-line) - (setq redit-client-line-max-in-server linenum) - (setq redit-client-editor-id bufnum) - (setq redit-client-previous-edited-line 1) - (setq redit-client-after-edited-line 1) - (setq redit-client-previous-line 1) - (add-hook 'before-change-functions - 'redit-client-before-change-function t t) - (add-hook 'after-change-functions - 'redit-client-after-change-function t t) - (make-local-hook 'window-scroll-functions) - ; window がスクロールする度に呼ばれる関数群 - (add-hook 'window-scroll-functions - 'redit-client-update-function t t)))) +(save-excursion + (let ((bufnum (rep-get-editor-id-from-pkt string)) + (linenum (rep-get-line-number-from-pkt string))) + (make-variable-buffer-local 'redit-client-buffer-name) + (make-variable-buffer-local 'redit-client-editor-id) + (setq redit-client-buffer-name + (rep-get-text-from-pk string)) + (setq redit-client-buffer (get-buffer-create redit-client-buffer-name)) + ;; プロセスとバッファを関連づける + (set-process-buffer redit-client-process redit-client-buffer) + (switch-to-buffer redit-client-buffer) ;; windowのバッファを変更する + (make-variable-buffer-local 'redit-client-previous-edited-line) + (make-variable-buffer-local 'redit-client-after-edited-line) + (make-variable-buffer-local 'redit-client-line-max-in-server) + (make-variable-buffer-local 'redit-client-previous-line) + (setq redit-client-line-max-in-server linenum) + (setq redit-client-editor-id bufnum) + (setq redit-client-previous-edited-line 1) + (setq redit-client-after-edited-line 1) + (setq redit-client-previous-line 1) + ;;(add-hook 'before-change-functions + ;;'redit-client-before-change-function t t) + ;;(add-hook 'after-change-functions + ;;'redit-client-after-change-function t t) -; string (line_num + text_data) で指定された行に -; text_data を挿入する + ;; not necessary since Emacs 21.1 + ;; (make-local-hook 'window-scroll-functions) + + ;; window がスクロールする度に呼ばれる関数群 + (add-hook 'window-scroll-functions + 'redit-client-update-function t t)))) + +;; string (line_num + text_data) で指定された行に +;; text_data を挿入する (defun redit-client-exec-read-ack (string) - (save-excursion - (let ((lines (rep-get-line-number-from-pkt string))) - ; redit-client-buffer をカレントバッファにする - (set-buffer redit-client-buffer) - (goto-line lines) - (beginning-of-line) ; 行の始めへ移動 -; (delete-region (progn (beginning-of-line) (point)) -; (progn (end-of-line) (point))) - (insert (rep-get-text-from-pkt string))))) ; テキストデータを挿入 +(save-excursion + (let ((lines (rep-get-line-number-from-pkt string))) + ;; redit-client-buffer をカレントバッファにする + (set-buffer redit-client-buffer) + (goto-line lines) + (beginning-of-line) ;; 行の始めへ移動 + ;; (delete-region (progn (beginning-of-line) (point)) + ;; (progn (end-of-line) (point))) + (insert (rep-get-text-from-pkt string))))) ;; テキストデータを挿入 -; redit-client-line-max-in-server に行番号を入れてる(だけ) +;; redit-client-line-max-in-server に行番号を入れてる(だけ) (defun redit-client-exec-write-still-ack (string) - (save-excursion - (set-buffer redit-client-buffer) - (let ((linenum (rep-get-line-number-from-pkt string ))) - (setq redit-client-line-max-in-server linenum)))) +(save-excursion + (set-buffer redit-client-buffer) + (let ((linenum (rep-get-line-number-from-pkt string ))) + (setq redit-client-line-max-in-server linenum)))) (defun redit-client-exec-delete-line-ack (string) - (save-excursion - (set-buffer redit-client-buffer) - (let ((linenum (rep-get-line-number-from-pkt string))) - (setq redit-client-line-max-in-server linenum)))) +(save-excursion + (set-buffer redit-client-buffer) + (let ((linenum (rep-get-line-number-from-pkt string))) + (setq redit-client-line-max-in-server linenum)))) -; プロセスとバッファ、ローカル変数を削除する +;; プロセスとバッファ、ローカル変数を削除する (defun redit-client-exec-close-ack (string) - (if redit-client-process - (kill-process redit-client-process)) - (if redit-client-buffer - (kill-buffer redit-client-buffer)) - (kill-all-local-variables)) +(if redit-client-process + (kill-process redit-client-process)) +(if redit-client-buffer + (kill-buffer redit-client-buffer)) +(kill-all-local-variables)) + +;; 引き数で与えられた string から Editor IDを取得する +(defun redit-client-exec-join (string) +(setq redit-client-editor-id (rep-get-editor-id-from-pkt string)) +(insert (concat "eid = " (number-to-string redit-client-editor-id) "\n")) +(insert (rep-get-text-from-pkt string))) -; 引き数で与えられた string から Editor IDを取得する -(defun redit-client-exec-join (string) - (setq redit-client-editor-id (rep-get-editor-id-from-pkt string)) - (insert (rep-get-text-from-pkt string))) - -; 引き数で与えられた string から Session IDを取得する +;; 引き数で与えられた string から Session IDを取得する (defun redit-client-exec-put (string) - (setq redit-client-session-id (rep-get-session-id-from-pkt string))) +(setq redit-client-session-id (rep-get-session-id-from-pkt string)) +(insert (concat "put session id = " (number-to-string redit-client-session-id) "\n"))) -; プロセスの状態を見て、対応したメッセージを表示 +;; SessionIDを名前とした、新しいバッファを開く +;; FIXME +;; SessionIDではなく、Session Nameが望ましい? +;; バッファを開いた後、Sessionで開いてるファイルの中身を表示するべき +(defun redit-client-exec-select () +(switch-to-buffer (get-buffer-create + (number-to-string redit-client-session-id)))) + +;; プロセスの状態を見て、対応したメッセージを表示 (defun redit-client-sentinel (proc msg) - (cond ((eq (process-status proc) 'exit) - (message "Client subprocess exited")) - ((eq (process-status proc) 'signal) - (message "Client subprocess killed")))) +(cond ((eq (process-status proc) 'exit) + (message "Client subprocess exited")) + ((eq (process-status proc) 'signal) + (message "Client subprocess killed")))) (defun gen-seqno () - "generate editor local sequence number." - (setq redit-client-seqno (+ redit-client-seqno 1))) +"generate editor local sequence number." +(setq redit-client-seqno (+ redit-client-seqno 1))) (defun rep-get-command-from-pkt (pkt) - (string-to-number (substring pkt 0 10))) +(string-to-number (substring pkt 0 10))) (defun rep-get-session-id-from-pkt (pkt) - (string-to-number (substring pkt 10 20))) +(string-to-number (substring pkt 10 20))) (defun rep-get-editor-id-from-pkt (pkt) - (string-to-number (substring pkt 20 30))) + (string-to-number (substring pkt 20 30))) (defun rep-get-sequence-id-from-pkt (pkt) - (string-to-number (substring pkt 30 40))) + (string-to-number (substring pkt 30 40))) (defun rep-get-line-number-from-pkt (pkt) - (string-to-number (substring pkt 40 50))) + (string-to-number (substring pkt 40 50))) (defun rep-get-text-size-from-pkt (pkt) - (string-to-number (substring pkt 50 60))) + (string-to-number (substring pkt 50 60))) (defun rep-get-text-from-pkt (pkt) - (substring pkt 60)) + (let ((size (rep-get-text-size-from-pkt pkt))) + (substring (decode-coding-string pkt 'euc-jp) 60 (+ 60 size)))) -; enqueue item in queue + +;; enqueue item in queue (defun enqueue (queue item) (let ((new-cell (list item))) (if (Queue-front queue) - ; 最終セルを書き換える + ;; 最終セルを書き換える (setf (cdr (Queue-rear queue)) new-cell) - ; キューは空の状態 + ;; キューは空の状態 (setf (Queue-front queue) new-cell)) (setf (Queue-rear queue) new-cell))) -; deque last queue +;; deque last queue (defun dequeue (queue) (if (Queue-front queue) (prog1 (pop (Queue-front queue)) (unless (Queue-front queue) - ; キューは空になった + ;; キューは空になった (setf (Queue-rear queue) nil))))) - +;; +;; USER +;; | i | r | d +;; ---|-------------------- +;; T i | 0\+1 | 0\+1 | 0\+1 +;; O ---|-------------------- +;; K r | +1\0 | 0\X | i\X +;; E ---|-------------------- +;; N d | +1\0 | X\i | X\X +;; (defun dequeue-all (queue) "clean queue" (while (Queue-front queue) @@ -638,112 +677,112 @@ (defun redit-line-translate-out (cque rque) "redit line translate for output" (let ((cc) (rc) (xcc) (xrc) (ccc) (crc) (cignore 0) (rignore 0)) - (setq xcc 0) - (setq xrc 0) - (setq cignore 0) - (setq rignore 0) - (while cque - (setq cc (car cque)) - (while rque - (setq rc (car rque)) -;-------- translation ------------ + (setq xcc 0) + (setq xrc 0) + (setq cignore 0) + (setq rignore 0) + (while cque + (setq cc (car cque)) + (while rque + (setq rc (car rque)) + ;; -------- translation ------------ - (if (< (+ (redit-get-line cc) xcc) (+ (redit-get-line rc) xrc)) - (if (= (redit-get-command cc) (string-to-number redit-write-command)) (setq xrc (- xrc 1))) + (if (< (+ (redit-get-line cc) xcc) (+ (redit-get-line rc) xrc)) + (if (= (redit-get-command cc) (string-to-number redit-write-command)) (setq xrc (- xrc 1))) (if (= (redit-get-command cc) (string-to-number redit-delete-line-command)) (setq xrc (- xrc 1)))) - (if (> (+ (redit-get-line cc) xcc) (+ (redit-get-line rc) xrc)) - (if (= (redit-get-command rc) (string-to-number redit-write-command)) (setq xcc (+ xcc 1))) + (if (> (+ (redit-get-line cc) xcc) (+ (redit-get-line rc) xrc)) + (if (= (redit-get-command rc) (string-to-number redit-write-command)) (setq xcc (+ xcc 1))) (if (= (redit-get-command rc) (string-to-number redit-delete-line-command)) (setq xcc (- xcc 1)))) - (if (= (+ (redit-get-line cc) xcc) (+ (redit-get-line rc) xrc)) - (if (= (redit-get-command rc) (string-to-number redit-write-command)) (setq xcc (+ xcc 1))) + (if (= (+ (redit-get-line cc) xcc) (+ (redit-get-line rc) xrc)) + (if (= (redit-get-command rc) (string-to-number redit-write-command)) (setq xcc (+ xcc 1))) (if (= (redit-get-command rc) (string-to-number redit-replace-command)) - (if (= (redit-get-command cc) (string-to-number redit-write-command)) (setq xrc (+ xrc 1))) + (if (= (redit-get-command cc) (string-to-number redit-write-command)) (setq xrc (+ xrc 1))) (if (= (redit-get-command cc) (string-to-number redit-replace-command)) (setq cignore 1)) (if (= (redit-get-command cc) (string-to-number redit-delete-line-command)) (setq crc redit-write-command) (setq cignore 1)))) - (if (= (redit-get-command rc) (string-to-number redit-delete-line-command)) + (if (= (redit-get-command rc) (string-to-number redit-delete-line-command)) (if (= (redit-get-command cc) (string-to-number redit-write-command)) (setq xrc (+ (redit-get-line rc) 1))) - (if (= (redit-get-command cc) (string-to-number redit-replace-command)) (setq cignore 1)) - (if (= (redit-get-command cc) (string-to-number redit-delete-line-command)) (setq cignore 1) (setq rignore 1))) + (if (= (redit-get-command cc) (string-to-number redit-replace-command)) (setq cignore 1)) + (if (= (redit-get-command cc) (string-to-number redit-delete-line-command)) (setq cignore 1) (setq rignore 1))) -;-------- translation ------------ + ;; -------- translation ------------ - (setq rque (cdr rque))) ; while rque + (setq rque (cdr rque))) ;; while rque - ;ignore - (if (= cignore 1) - ;xxx - (setq cignore 0)) - (if (= rignore 1) - ;xxx - (setq cignore 0)) + ;; ignore + (if (= cignore 1) + ;; xxx + (setq cignore 0)) + (if (= rignore 1) + ;; xxx + (setq cignore 0)) -;-------- add after que ------------ - (enqueue after-CQ (concat (format "%2d%2d%9d" (redit-get-command cc) (redit-get-uid cc) (+ (redit-get-line cc) xcc)) (redit-get-text cc))) -;-------- add after que ------------ + ;; -------- add after que ------------ + (enqueue after-CQ (concat (format "%2d%2d%9d" (redit-get-command cc) (redit-get-uid cc) (+ (redit-get-line cc) xcc)) (redit-get-text cc))) + ;; -------- add after que ------------ - (setq cque (cdr cque))) ; while cque - ) ; let -) ;defun + (setq cque (cdr cque))) ;; while cque + ) ;; let + ) ;; defun (defun redit-line-translate-in (cque rque) "redit line translate for input" (let ((cc) (rc) (xcc) (xrc) (ccc) (crc) (cignore 0) (rignore 0)) - (setq xcc 0) - (setq xrc 0) - (setq cignore 0) - (setq rignore 0) - (while rque - (setq rc (car rque)) + (setq xcc 0) + (setq xrc 0) (setq cignore 0) (setq rignore 0) - (while cque - (setq cc (car cque)) -;-------- translation ------------ + (while rque + (setq rc (car rque)) + (setq cignore 0) + (setq rignore 0) + (while cque + (setq cc (car cque)) + ;; -------- translation ------------ - (if (and (= cignore 1) (= rignore 1)) - (if (< (+ (redit-get-line rc) xrc) (+ (redit-get-line cc) xcc)) - (if (= (redit-get-command rc) (string-to-number redit-write-command)) (setq xcc (+ xcc 1))) - (if (= (redit-get-command rc) (string-to-number redit-delete-line-command)) (setq xcc (- xcc 1)))) + (if (and (= cignore 1) (= rignore 1)) + (if (< (+ (redit-get-line rc) xrc) (+ (redit-get-line cc) xcc)) + (if (= (redit-get-command rc) (string-to-number redit-write-command)) (setq xcc (+ xcc 1))) + (if (= (redit-get-command rc) (string-to-number redit-delete-line-command)) (setq xcc (- xcc 1)))) - (if (> (+ (redit-get-line rc) xrc) (+ (redit-get-line cc) xcc)) - (if (= (redit-get-command cc) (string-to-number redit-write-command)) (setq xrc (- xrc 1))) - (if (= (redit-get-command cc) (string-to-number redit-delete-line-command)) (setq xrc (+ xrc 1)))) + (if (> (+ (redit-get-line rc) xrc) (+ (redit-get-line cc) xcc)) + (if (= (redit-get-command cc) (string-to-number redit-write-command)) (setq xrc (- xrc 1))) + (if (= (redit-get-command cc) (string-to-number redit-delete-line-command)) (setq xrc (+ xrc 1)))) - (if (= (+ (redit-get-line rc) xrc) (+ (redit-get-line cc) xcc)) - (if (= (redit-get-command cc) (string-to-number redit-write-command)) (setq xcc (+ xcc 1))) - (if (= (redit-get-command cc) (string-to-number redit-replace-command)) - (if (= (redit-get-command rc) (string-to-number redit-write-command)) (setq xcc (+ xcc 1))) - (if (= (redit-get-command rc) (string-to-number redit-replace-command)) (setq cignore 1)) - (if (= (redit-get-command rc) (string-to-number redit-delete-line-command)) (setq crc redit-write-command) (setq cignore 1)))) + (if (= (+ (redit-get-line rc) xrc) (+ (redit-get-line cc) xcc)) + (if (= (redit-get-command cc) (string-to-number redit-write-command)) (setq xcc (+ xcc 1))) + (if (= (redit-get-command cc) (string-to-number redit-replace-command)) + (if (= (redit-get-command rc) (string-to-number redit-write-command)) (setq xcc (+ xcc 1))) + (if (= (redit-get-command rc) (string-to-number redit-replace-command)) (setq cignore 1)) + (if (= (redit-get-command rc) (string-to-number redit-delete-line-command)) (setq crc redit-write-command) (setq cignore 1)))) (if (= (redit-get-command cc) (string-to-number redit-delete-line-command)) - (if (= (redit-get-command rc) (string-to-number redit-write-command)) (setq xcc (+ (redit-get-line cc) 1))) + (if (= (redit-get-command rc) (string-to-number redit-write-command)) (setq xcc (+ (redit-get-line cc) 1))) (if (= (redit-get-command rc) (string-to-number redit-replace-command)) (setq crc redit-write-command) (setq cignore 1)) (if (= (redit-get-command rc) (string-to-number redit-delete-line-command)) (setq cignore 1) (setq rignore 1)))) -;-------- translation ------------ + ;; -------- translation ------------ - (setq cque (cdr cque))) ; while rque + (setq cque (cdr cque))) ;; while rque - ;ignore - (if (= cignore 1) - ;xxx - (setq cignore 0)) - (if (= rignore 1) - ;xxx - (setq rignore 0)) + ;; ignore + (if (= cignore 1) + ;; xxx + (setq cignore 0)) + (if (= rignore 1) + ;; xxx + (setq rignore 0)) -;-------- add after que ------------ - (enqueue after-RQ (concat (format "%2d%2d%9d" (redit-get-command rc) (redit-get-uid rc) (+ (redit-get-line rc) xrc)) (redit-get-text rc))) -;-------- add after que ------------ + ;; -------- add after que ------------ + (enqueue after-RQ (concat (format "%2d%2d%9d" (redit-get-command rc) (redit-get-uid rc) (+ (redit-get-line rc) xrc)) (redit-get-text rc))) + ;; -------- add after que ------------ - (setq rque (cdr rque))) ; while cque - ) ; let -) ;defun + (setq rque (cdr rque))) ;; while cque + ) ;; let + ) ;; defun -; for debug +;; for debug (defun redit-client-print-command-queue () "Print command queue." (interactive) @@ -757,4 +796,4 @@ (defun redit-client-print-send-queue () "Print command queue." (interactive) - (print redit-client-send-queue)) + (print redit-client-send-queue)) \ No newline at end of file
--- a/redit_client.pl Sun Oct 22 17:29:02 2006 +0900 +++ b/redit_client.pl Tue Dec 12 11:02:31 2006 +0900 @@ -1,10 +1,12 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl -w #use strict; use IO::Select; use IO::Socket; +use Encode; use Rep; +use NKF; if($ARGV[0] eq "") { print "Usage: $0 SERVER_NAME\n"; @@ -22,7 +24,7 @@ sub HEADER_TEXTSIZ_POS {5}; my $peer_addr = $ARGV[0]; -my $peer_port = "8080"; +my $peer_port = "8765"; my $TIMEOUT = 0; # connect to the session manager @@ -30,8 +32,8 @@ PeerPort => $peer_port, Proto => 'tcp') or die("Cannot open socket : $!\n"); -my $myeid; -my $mysid; +my $myeid = ""; +my $mysid = ""; my $ack; my $packet; @@ -43,7 +45,7 @@ if ($stdin_selector->can_read($TIMEOUT)) { my $buffer = <STDIN>; # TODO : - my $packet = &make_packet_from_emacs($buffer); + my $packet = &make_packet_from_emacs($buffer); $sock->write($packet,length($packet)); &debug_msg("send message is : ||" . $buffer . "||\n"); } @@ -54,7 +56,7 @@ if($sm_message->{'cmd'} == SMCMD_JOIN_ACK){ $myeid = $sm_message->{'eid'}; - &debug_msg("mysid is : " . $mysid . "\n"); + &debug_msg("myeid is : " . $myeid . "\n"); } if($sm_message->{'cmd'} == SMCMD_PUT_ACK){ @@ -62,17 +64,33 @@ &debug_msg("mysid is : " . $mysid . "\n"); } - if($sm_message->{'eid'} != $myeid or $sm_message->{'cmd'} == SMCMD_JOIN_ACK or $sm_message->{'cmd'} == SMCMD_PUT_ACK or $sm_message->{'cmd'} == SMCMD_SELECT_ACK){ - my $output = sprintf("%10d%10d%10d%10d%10d%10d" . $sm_message->{'text'}, - $sm_message->{'cmd'}, - $sm_message->{'sid'}, - $sm_message->{'eid'}, - $sm_message->{'seqno'}, - $sm_message->{'lineno'}, - $sm_message->{'textsiz'} - ); - syswrite(STDOUT,$output,length($output)); - &debug_msg("recv message is : ||" . $output . "||\n"); + if ($sm_message->{'eid'} != $myeid + or $sm_message->{'cmd'} == SMCMD_JOIN_ACK + or $sm_message->{'cmd'} == SMCMD_PUT_ACK + or $sm_message->{'cmd'} == SMCMD_SELECT_ACK) { + + my $text = nkf("-eW", $sm_message->{'text'}); + $text =~ s/\n//g; + # バイト数ではなく文字数で + my $textsiz = length(decode('euc-jp', $text)); + + my $output = sprintf("%10d%10d%10d%10d%10d%10d" . + #nkf("-eW", $sm_message->{'text'}), + #$sm_message->{'text'}, + $text, + $sm_message->{'cmd'}, + $sm_message->{'sid'}, + $sm_message->{'eid'}, + $sm_message->{'seqno'}, + $sm_message->{'lineno'}, + #$sm_message->{'textsiz'} + $textsiz + ); + # {'text'}によけいな改行がある時があるので + # これはsession manager側でどうにかしてもらう + syswrite(STDOUT,$output,length($output)); + &debug_msg("recv messageleng: ||" . length($output) . "||\n"); + &debug_msg("recv message is : ||" . $output . "||\n"); } else { &debug_msg("chop cmd : " . $sm_message->{'cmd'} . "\n"); &debug_msg("chop eid : " . $sm_message->{'eid'} . "\n"); @@ -84,14 +102,19 @@ sub make_packet_from_emacs { # FIXME my $buffer = shift; + my $text = substr($buffer,&EMACS_HEADER_SIZ); + $text =~ s/\x92//g; + $text = nkf("-w", $text); + &debug_msg("text = " .$text. "\n"); return &make_packet( &get_header_token($buffer, HEADER_CMD_POS), &get_header_token($buffer, HEADER_SID_POS), &get_header_token($buffer, HEADER_EID_POS), &get_header_token($buffer, HEADER_SEQNO_POS), &get_header_token($buffer, HEADER_LINENO_POS), - substr($buffer,&EMACS_HEADER_SIZ) - ); + #$substr($buffer,&EMACS_HEADER_SIZ) + $text + ); } sub get_header_token {