Mercurial > hg > RemoteEditor > emacs
changeset 7:6b82a318980c
*** empty log message ***
author | gongo |
---|---|
date | Tue, 12 Dec 2006 16:23:59 +0900 |
parents | 5796f9efc332 |
children | 2b2c8c2cb9d6 |
files | redit-client-sm.el redit-client-sm.elc redit_client.pl |
diffstat | 3 files changed, 133 insertions(+), 151 deletions(-) [+] |
line wrap: on
line diff
--- a/redit-client-sm.el Tue Dec 12 11:02:31 2006 +0900 +++ b/redit-client-sm.el Tue Dec 12 16:23:59 2006 +0900 @@ -1,5 +1,5 @@ ;; $Id$ -(defcustom redit-client-program "/Users/gongo/src/member/gongo/redit-emacs/redit_client.pl" +(defcustom redit-client-program "/Users/gongo/src/REP_project/emacs/redit_client.pl" "The program to use as the remote-edit client." :group 'redit :type 'string) @@ -30,7 +30,7 @@ ;; editor local sequence number (defvar redit-client-seqno 0 - "Remote-edit client's editor-id.") + "Remote-edit client's editor-id.") (defvar redit-client-line-max-in-server nil "Value of point-max in server's buffer.") @@ -95,7 +95,7 @@ (set-process-sentinel redit-client-process nil) (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 が与えられる @@ -110,9 +110,6 @@ (set-process-coding-system redit-client-process 'raw-text 'raw-text) ;; 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 @@ -123,8 +120,8 @@ (message "Remote edit client started.")) (error "redit-client connection refused."))) - ;; (redit-join-command ()) - (defun redit-join-command (host) +;; (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 @@ -141,19 +138,17 @@ (set-process-coding-system redit-client-process 'raw-text 'raw-text) - ;; 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"))) + + ;; 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) @@ -262,14 +257,14 @@ ;; 編集情報を保存するだけにとどめる (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 + (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) @@ -321,17 +316,18 @@ (defun redit-client-process-filter (proc string) ;; バッファローカルなフックリスト before-change-functions から ;; redit-client-before-change-function を取り除く. after も同じ + ;; proc からの出力に hook しないように (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 + (let ((command (rep-get-command-from-pkt string))) ;; command がどの命令かを判断し、対応した処理をする。case みたい (cond ;; FIXME ((if (= command (string-to-number redit-open-ack)) - (if (/= redit-client-editor-id) + (if (/= redit-client-editor-id (rep-get-editor-id-from-pkt string)) (redit-client-exec-open-ack string)))) ((if (= command (string-to-number redit-read-ack)) @@ -355,27 +351,19 @@ (redit-client-exec-write-line string)))) ;; from Session Manager - ;; 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 を保存する ((if (= command (string-to-number redit-put-ack-command)) (redit-client-exec-put string))) ;; select ack ;; TODO : start editing ((if (= command (string-to-number redit-select-ack-command)) - (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)))) - ))) + (redit-client-exec-select))) + ;; get ((if (= command (string-to-number redit-get-command)) (if (= redit-client-editor-id (rep-get-editor-id-from-pkt string)) @@ -393,14 +381,15 @@ ((if (= command (string-to-number redit-delete-line-command)) (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 "")))) + ;;((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) + (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) @@ -460,7 +449,7 @@ (endl (real-count-lines end)) ;; end の行番号 (currline)) ;; currline = nil ;; 前回の編集した行と今回の編集した行が違っていたら前回の編集をサーバへ送る - ;; (message (concat "before = " (number-to-string beginl) " : " (number-to-string endl))) + (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) @@ -488,145 +477,137 @@ (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 を挿入する (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) ;; テキストデータを挿入 - ;;(add-hook 'before-change-functions - ;;'redit-client-before-change-function t t) - ;;(add-hook 'after-change-functions - ;;'redit-client-after-change-function t t))) -)) + (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) ;; テキストデータを挿入 + )) ;; 引き数 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))) -;;(add-hook 'before-change-functions -;;'redit-client-before-change-function t t) -;;(add-hook 'after-change-functions -;;'redit-client-after-change-function t t) -) + (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))) + ) ;; 引き数 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) + (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) - ;; not necessary since Emacs 21.1 - ;; (make-local-hook 'window-scroll-functions) + ;; not necessary since Emacs 21.1 + ;; (make-local-hook 'window-scroll-functions) - ;; window がスクロールする度に呼ばれる関数群 - (add-hook 'window-scroll-functions - 'redit-client-update-function t t)))) + ;; 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 に行番号を入れてる(だけ) (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))) + (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 から Session IDを取得する (defun redit-client-exec-put (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"))) + (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)))) + (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))) (defun rep-get-sequence-id-from-pkt (pkt) @@ -643,21 +624,21 @@ ;; 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)) + (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 (defun dequeue (queue) (if (Queue-front queue) - (prog1 - (pop (Queue-front queue)) - (unless (Queue-front queue) - ;; キューは空になった - (setf (Queue-rear queue) nil))))) + (prog1 + (pop (Queue-front queue)) + (unless (Queue-front queue) + ;; キューは空になった + (setf (Queue-rear queue) nil))))) ;; ;; USER @@ -786,7 +767,13 @@ (defun redit-client-print-command-queue () "Print command queue." (interactive) - (print redit-client-command-queue)) + ;;(message redit-client-command-queue)) + (let ((queue redit-client-command-queue)) + (while (Queue-front queue) + (message (Queue-front queue)) + (setq queue (cdr (Queue-rear queue))) + ) +)) (defun redit-client-print-recive-queue () "Print command queue."
--- a/redit_client.pl Tue Dec 12 11:02:31 2006 +0900 +++ b/redit_client.pl Tue Dec 12 16:23:59 2006 +0900 @@ -75,19 +75,14 @@ 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");