comparison redit-client-sm.el @ 63:0f7d2aab0e04 v20080828-2

*** empty log message ***
author gongo
date Thu, 28 Aug 2008 19:44:23 +0900
parents 5e44d3723fa9
children 312ea950243c
comparison
equal deleted inserted replaced
62:5e44d3723fa9 63:0f7d2aab0e04
355 (defun redit-quit-command () 355 (defun redit-quit-command ()
356 "quit" 356 "quit"
357 (interactive) 357 (interactive)
358 ;; process kill とかしよう 358 ;; process kill とかしよう
359 ) 359 )
360
361
362 ;; obsolete
363 ;;(defun redit-client-open (file)
364 ;; (interactive "P")
365 ;; (if redit-client-process
366 ;; (if (setq file (read-string "Filename: "))
367 ;; (progn
368 ;; ;; redit-client-process の input に文字列を送信する
369 ;; (process-send-string
370 ;; redit-client-process
371 ;; ;; redit-open-command (01) と file を連結させる
372 ;; (concat redit-open-command file))
373 ;; ;; redit-client-process から出力を得るまでループ
374 ;; (while (eq nil (accept-process-output redit-client-process)))))
375 ;; (error "redit-client is not running.")))
376
377 ;; redit-client-process にreadコマンドとバッファ番号、行番号を送り、
378 ;; サーバからの出力を得る
379 ;;(defun redit-client-read-line (linenum)
380 ;; (if redit-client-process
381 ;; (save-excursion
382 ;; (progn
383 ;; (process-send-string
384 ;; redit-client-process
385 ;; (format "%10d%10d%10d%10d%10d%10d\n" redit-read-command redit-client-session-id redit-client-editor-id (gen-seqno) linenum 0))
386 ;; (while (eq nil
387 ;; (accept-process-output redit-client-process)))))
388 ;; (error "redit-client is not running.")))
389
390 360
391 ;; linenumで指定された行の編集をサーバへ送る 361 ;; linenumで指定された行の編集をサーバへ送る
392 ;; redit-client-process に insert コマンドと 362 ;; redit-client-process に insert コマンドと
393 ;; バッファ(sid)番号、行番号、行の内容を送り、 Ack を受け取る 363 ;; バッファ(sid)番号、行番号、行の内容を送り、 Ack を受け取る
394 ;; _text が指定されている場合、バッファのlinenumの文字列ではなく 364 ;; _text が指定されている場合、バッファのlinenumの文字列ではなく
453 linenum 5 "55555")) 423 linenum 5 "55555"))
454 )) 424 ))
455 )) 425 ))
456 (error "redit-client is not running."))) 426 (error "redit-client is not running.")))
457 427
458 ;; redit-client-process へcloseコマンドを送る
459 ;;(defun redit-client-close ()
460 ;; "Save File and exit Remote-edit client."
461 ;; (interactive)
462 ;; (let ((line redit-client-previous-line))
463 ;; (redit-client-insert-line line nil)
464 ;; (process-send-string
465 ;; redit-client-process
466 ;; (concat
467 ;; ;; obsolete send string
468 ;; ;; (format "%10d%10d%10d%10d%10d%10d" (string-to-number redit-close-command) redit-client-session-id redit-client-editor-id (gen-seqno) 0 0)
469 ;; (redit-pack
470 ;; redit-close-command
471 ;; redit-client-session-id
472 ;; redit-client-editor-id
473 ;; (gen-seqno) 0 0) "\n"))))
474
475 ;; redit-client-process を終了させる
476 ;;(defun redit-client-kill ()
477 ;; "Stop Remote-Edit client process."
478 ;; (interactive)
479 ;; (if redit-client-process
480 ;; (kill-process redit-client-process))
481 ;; (if redit-client-buffer
482 ;; (kill-buffer redit-client-buffer))
483 ;; (kill-all-local-variables))
484
485 ;; proc == redit-client-process 428 ;; proc == redit-client-process
486 ;; string == redit-client-process からの output 429 ;; string == redit-client-process からの output
487 (defun redit-client-process-filter (proc string) 430 (defun redit-client-process-filter (proc string)
488 ;; バッファローカルなフックリスト before-change-functions から 431 ;; バッファローカルなフックリスト before-change-functions から
489 ;; redit-client-before-change-function を取り除く. after も同じ 432 ;; redit-client-before-change-function を取り除く. after も同じ
570 'redit-client-before-change-function t) 513 'redit-client-before-change-function t)
571 (add-hook 'after-change-functions 514 (add-hook 'after-change-functions
572 'redit-client-after-change-function t) 515 'redit-client-after-change-function t)
573 ) 516 )
574 517
575 ;; window-scroll-functions に hook される。
576 ;; window がスクロールする度に呼ばれる
577 ;;(defun redit-client-update-function (window window-start)
578 ;; (if (equal (window-buffer) redit-client-buffer)
579 ;; (save-excursion
580 ;; (remove-hook 'before-change-functions
581 ;; 'redit-client-before-change-function t)
582 ;; (remove-hook 'after-change-functions
583 ;; 'redit-client-after-change-function t)
584 ;; ;; read part.
585 ;; (while (and (= (point-max)
586 ;; (window-end nil t))
587 ;; (> redit-client-line-max-in-server
588 ;; (real-count-lines (window-end nil t))))
589 ;; ;; (count-lines (window-end nil t))))
590 ;; (redit-client-read-line (real-count-lines (window-end nil t))))
591 ;;
592 ;; (if (not (= (count-lines (point-min) (window-end nil t))
593 ;; (real-count-lines (window-end nil t))))
594 ;; (redit-client-read-line
595 ;; (progn (goto-line redit-client-line-max-in-server)
596 ;; (real-count-lines (point)))))
597 ;;
598 ;; (if (< redit-client-line-max-in-server
599 ;; (real-count-lines (window-end nil t)))
600 ;; (progn (goto-line (window-end nil t))
601 ;; (delete-region
602 ;; (progn (beginning-of-line) (backward-char) (point))
603 ;; (progn (forward-char) (end-of-line) (point)))))
604 ;;
605 ;; (add-hook 'before-change-functions
606 ;; 'redit-client-before-change-function t t)
607 ;; (add-hook 'after-change-functions
608 ;; 'redit-client-after-change-function t t))))
609
610 ;; currentp の位置の行数を返す 518 ;; currentp の位置の行数を返す
611 (defun real-count-lines (currentp) 519 (defun real-count-lines (currentp)
612 (+ (count-lines (point-min) currentp) 520 (+ (count-lines (point-min) currentp)
613 (if (= (save-excursion (goto-char currentp) (current-column)) 521 (if (= (save-excursion (goto-char currentp) (current-column))
614 0) 522 0)
615 1 0))) 523 1 0)))
616
617 ;;(defun limited-save-excursion (&rest exprs)
618 ;; (let ((saved-point (point)))
619 ;; (while exprs
620 ;; (eval (car exprs))
621 ;; (setq exprs (cdr exprs)))
622 ;; (goto-char saved-point)))
623 524
624 ;; before-change-functions に hook される 525 ;; before-change-functions に hook される
625 ;; バッファが変更される直前に呼ばれる。 526 ;; バッファが変更される直前に呼ばれる。
626 ;; begin と end には変更前の変更部分の始まりと終わりの point が入る 527 ;; begin と end には変更前の変更部分の始まりと終わりの point が入る
627 (defun redit-client-before-change-function (begin end) 528 (defun redit-client-before-change-function (begin end)
756 (delete-backward-char 1) 657 (delete-backward-char 1)
757 (delete-char 1))) 658 (delete-char 1)))
758 ) 659 )
759 ))) 660 )))
760 661
761 ;; 何用?相手が開いてるファイルを取得するのかな?
762 ;; read みたいなもん?
763 ;; 引き数 string (buf_num + line_num + text_data)
764 ;;(defun redit-client-exec-open-ack (string)
765 ;; (save-excursion
766 ;; (let ((bufnum (redit-get-editor-id-from-pkt string))
767 ;; (linenum (redit-get-line-number-from-pkt string)))
768 ;; (make-variable-buffer-local 'redit-client-buffer-name)
769 ;; (make-variable-buffer-local 'redit-client-editor-id)
770 ;; (setq redit-client-buffer-name
771 ;; (redit-get-text-from-pkt string))
772 ;; (setq redit-client-buffer (get-buffer-create redit-client-buffer-name))
773 ;; ;; プロセスとバッファを関連づける
774 ;; (set-process-buffer redit-client-process redit-client-buffer)
775 ;; (switch-to-buffer redit-client-buffer) ;; windowのバッファを変更する
776 ;; (make-variable-buffer-local 'redit-client-previous-edited-line)
777 ;; (make-variable-buffer-local 'redit-client-after-edited-line)
778 ;; (make-variable-buffer-local 'redit-client-line-max-in-server)
779 ;; (make-variable-buffer-local 'redit-client-previous-line)
780 ;; (setq redit-client-line-max-in-server linenum)
781 ;; (setq redit-client-editor-id bufnum)
782 ;; (setq redit-client-previous-edited-line 1)
783 ;; (setq redit-client-after-edited-line 1)
784 ;; (setq redit-client-previous-line 1)
785 ;;
786 ;; ;;(add-hook 'before-change-functions
787 ;; ;;'redit-client-before-change-function t t)
788 ;; ;;(add-hook 'after-change-functions
789 ;; ;;'redit-client-after-change-function t t)
790 ;;
791 ;; ;; not necessary since Emacs 21.1
792 ;; ;; (make-local-hook 'window-scroll-functions)
793 ;;
794 ;; ;; window がスクロールする度に呼ばれる関数群
795 ;; (add-hook 'window-scroll-functions
796 ;; 'redit-client-update-function t t))))
797
798
799 ;; string (line_num + text_data) で指定された行に
800 ;; text_data を挿入する
801 ;;(defun redit-client-exec-read-ack (string)
802 ;; (save-excursion
803 ;; (let ((lines (redit-get-line-number-from-pkt string)))
804 ;; ;; redit-client-buffer をカレントバッファにする
805 ;; (set-buffer redit-client-buffer)
806 ;; (goto-line lines)
807 ;; (beginning-of-line) ;; 行の始めへ移動
808 ;; ;; (delete-region (progn (beginning-of-line) (point))
809 ;; ;; (progn (end-of-line) (point)))
810 ;; (insert (redit-get-text-from-pkt string))))) ;; テキストデータを挿入
811
812 ;; redit-client-line-max-in-server に行番号を入れてる(だけ)
813 ;;(defun redit-client-exec-insert-ack (string)
814 ;; (save-excursion
815 ;; (set-buffer redit-client-buffer)
816 ;; (let ((linenum (redit-get-line-number-from-pkt string )))
817 ;; (setq redit-client-line-max-in-server linenum))))
818 ;;
819 ;;(defun redit-client-exec-delete-line-ack (string)
820 ;; (save-excursion
821 ;; (set-buffer redit-client-buffer)
822 ;; (let ((linenum (redit-get-line-number-from-pkt string)))
823 ;; (setq redit-client-line-max-in-server linenum))))
824
825 ;; プロセスとバッファ、ローカル変数を削除する
826 ;;(defun redit-client-exec-close-ack (string)
827 ;; (if redit-client-process
828 ;; (kill-process redit-client-process))
829 ;; (if redit-client-buffer
830 ;; (kill-buffer redit-client-buffer))
831 ;; (kill-all-local-variables))
832
833 ;; 引き数で与えられた string から Editor IDを取得する 662 ;; 引き数で与えられた string から Editor IDを取得する
834 (defun redit-client-exec-join (filename sid eid) 663 (defun redit-client-exec-join (filename sid eid)
835 (let ((bufname) (sinfo)) 664 (let ((bufname) (sinfo))
836 ;; SessionInfo の生成 665 ;; SessionInfo の生成
837 (setq sinfo (redit-create-session-info sid eid)) 666 (setq sinfo (redit-create-session-info sid eid))
891 (defun gen-seqno () 720 (defun gen-seqno ()
892 "generate editor local sequence number." 721 "generate editor local sequence number."
893 (setq redit-client-seqno (+ redit-client-seqno 1))) 722 (setq redit-client-seqno (+ redit-client-seqno 1)))
894 723
895 724
896 ;;(defun redit-line-translate-out (cque rque)
897 ;; "redit line translate for output"
898 ;; (let ((cc) (rc) (xcc) (xrc) (ccc) (crc) (cignore 0) (rignore 0))
899 ;; (setq xcc 0)
900 ;; (setq xrc 0)
901 ;; (setq cignore 0)
902 ;; (setq rignore 0)
903 ;; (while cque
904 ;; (setq cc (car cque))
905 ;; (while rque
906 ;; (setq rc (car rque))
907 ;; ;; -------- translation ------------
908 ;;
909 ;; (if (< (+ (redit-get-line-from-queue cc) xcc) (+ (redit-get-line-from-queue rc) xrc))
910 ;; (if (= (redit-get-command-from-queue cc) redit-insert-command) (setq xrc (- xrc 1)))
911 ;; (if (= (redit-get-command-from-queue cc) redit-delete-line-command) (setq xrc (- xrc 1))))
912 ;;
913 ;; (if (> (+ (redit-get-line-from-queue cc) xcc) (+ (redit-get-line-from-queue rc) xrc))
914 ;; (if (= (redit-get-command-from-queue rc) redit-insert-command) (setq xcc (+ xcc 1)))
915 ;; (if (= (redit-get-command-from-queue rc) redit-delete-line-command) (setq xcc (- xcc 1))))
916 ;;
917 ;; (if (= (+ (redit-get-line-from-queue cc) xcc) (+ (redit-get-line-from-queue rc) xrc))
918 ;; (if (= (redit-get-command-from-queue rc) redit-insert-command) (setq xcc (+ xcc 1)))
919 ;; (if (= (redit-get-command-from-queue rc) redit-replace-command)
920 ;; (if (= (redit-get-command-from-queue cc) redit-insert-command) (setq xrc (+ xrc 1)))
921 ;; (if (= (redit-get-command-from-queue cc) redit-replace-command) (setq cignore 1))
922 ;; (if (= (redit-get-command-from-queue cc) redit-delete-line-command) (setq crc redit-insert-command) (setq cignore 1))))
923 ;;
924 ;; (if (= (redit-get-command-from-queue rc) redit-delete-line-command)
925 ;; (if (= (redit-get-command-from-queue cc) redit-insert-command) (setq xrc (+ (redit-get-line-from-queue rc) 1)))
926 ;; (if (= (redit-get-command-from-queue cc) redit-replace-command) (setq cignore 1))
927 ;; (if (= (redit-get-command-from-queue cc) redit-delete-line-command) (setq cignore 1) (setq rignore 1)))
928 ;;
929 ;; ;; -------- translation ------------
930 ;;
931 ;; (setq rque (cdr rque))) ;; while rque
932 ;;
933 ;; ;; ignore
934 ;; (if (= cignore 1)
935 ;; ;; xxx
936 ;; (setq cignore 0))
937 ;; (if (= rignore 1)
938 ;; ;; xxx
939 ;; (setq cignore 0))
940 ;;
941 ;; ;; -------- add after que ------------
942 ;; (enqueue after-CQ (concat (format "%2d%2d%9d" (redit-get-command-from-queue cc) (redit-get-uid-from-queue cc) (+ (redit-get-line-from-queue cc) xcc)) (redit-get-text-from-queue cc)))
943 ;; ;; -------- add after que ------------
944 ;;
945 ;; (setq cque (cdr cque))) ;; while cque
946 ;; ) ;; let
947 ;; ) ;; defun
948 ;;
949 ;;(defun redit-line-translate-in (cque rque)
950 ;; "redit line translate for input"
951 ;; (let ((cc) (rc) (xcc) (xrc) (ccc) (crc) (cignore 0) (rignore 0))
952 ;; (setq xcc 0)
953 ;; (setq xrc 0)
954 ;; (setq cignore 0)
955 ;; (setq rignore 0)
956 ;; (while rque
957 ;; (setq rc (car rque))
958 ;; (setq cignore 0)
959 ;; (setq rignore 0)
960 ;; (while cque
961 ;; (setq cc (car cque))
962 ;; ;; -------- translation ------------
963 ;;
964 ;; (if (and (= cignore 1) (= rignore 1))
965 ;; (if (< (+ (redit-get-line-from-queue rc) xrc) (+ (redit-get-line-from-queue cc) xcc))
966 ;; (if (= (redit-get-command-from-queue rc) redit-insert-command) (setq xcc (+ xcc 1)))
967 ;; (if (= (redit-get-command-from-queue rc) redit-delete-line-command) (setq xcc (- xcc 1))))
968 ;;
969 ;; (if (> (+ (redit-get-line-from-queue rc) xrc) (+ (redit-get-line-from-queue cc) xcc))
970 ;; (if (= (redit-get-command-from-queue cc) redit-insert-command) (setq xrc (- xrc 1)))
971 ;; (if (= (redit-get-command-from-queue cc) redit-delete-line-command) (setq xrc (+ xrc 1))))
972 ;;
973 ;; (if (= (+ (redit-get-line-from-queue rc) xrc) (+ (redit-get-line-from-queue cc) xcc))
974 ;; (if (= (redit-get-command-from-queue cc) redit-insert-command) (setq xcc (+ xcc 1)))
975 ;; (if (= (redit-get-command-from-queue cc) redit-replace-command)
976 ;; (if (= (redit-get-command-from-queue rc) redit-insert-command) (setq xcc (+ xcc 1)))
977 ;; (if (= (redit-get-command-from-queue rc) redit-replace-command) (setq cignore 1))
978 ;; (if (= (redit-get-command-from-queue rc) redit-delete-line-command) (setq crc redit-insert-command) (setq cignore 1))))
979 ;; (if (= (redit-get-command-from-queue cc) redit-delete-line-command)
980 ;; (if (= (redit-get-command-from-queue rc) redit-insert-command) (setq xcc (+ (redit-get-line-from-queue cc) 1)))
981 ;; (if (= (redit-get-command-from-queue rc) redit-replace-command) (setq crc redit-insert-command) (setq cignore 1))
982 ;; (if (= (redit-get-command-from-queue rc) redit-delete-line-command) (setq cignore 1) (setq rignore 1))))
983 ;;
984 ;; ;; -------- translation ------------
985 ;;
986 ;; (setq cque (cdr cque))) ;; while rque
987 ;;
988 ;; ;; ignore
989 ;; (if (= cignore 1)
990 ;; ;; xxx
991 ;; (setq cignore 0))
992 ;; (if (= rignore 1)
993 ;; ;; xxx
994 ;; (setq rignore 0))
995 ;;
996 ;; ;; -------- add after que ------------
997 ;; (enqueue after-RQ (concat (format "%2d%2d%9d" (redit-get-command-from-queue rc) (redit-get-uid-from-queue rc) (+ (redit-get-line-from-queue rc) xrc)) (redit-get-text-from-queue rc)))
998 ;; ;; -------- add after que ------------
999 ;;
1000 ;; (setq rque (cdr rque))) ;; while cque
1001 ;; ) ;; let
1002 ;; ) ;; defun
1003
1004 ;; for debug
1005 ;;(defun redit-client-print-command-queue ()
1006 ;; "Print command queue."
1007 ;; (interactive)
1008 ;; ;;(message redit-client-command-queue))
1009 ;; (let (queue)
1010 ;; (setq queue redit-client-command-queue)
1011 ;; (while (Queue-front queue)
1012 ;; (message (Queue-front queue))
1013 ;; (setq queue (cdr (Queue-rear queue)))
1014 ;; )))
1015 ;;
1016 ;;(defun redit-client-print-recive-queue ()
1017 ;; "Print command queue."
1018 ;; (interactive)
1019 ;; (print redit-client-receive-queue))
1020 ;;
1021 ;;(defun redit-client-print-send-queue ()
1022 ;; "Print command queue."
1023 ;; (interactive)
1024 ;; (print redit-client-send-queue))
1025 ;;
1026
1027 (defun is-value-in-range (min value max) 725 (defun is-value-in-range (min value max)
1028 (if (and (<= min value) (<= value max)) 726 (if (and (<= min value) (<= value max))
1029 t nil)) 727 t nil))