changeset 4:e73bf047eb19

add REP translate routine for emacs lisp
author shinobu
date Sun, 22 Oct 2006 13:51:18 +0900
parents 52cb18a3c1e2
children ee15fce75335
files line-merge.el
diffstat 1 files changed, 122 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/line-merge.el	Sun Oct 22 13:51:18 2006 +0900
@@ -0,0 +1,122 @@
+;
+;      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)
+    (dequeue queue)))
+
+(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 ------------
+
+      (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-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-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-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 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)))
+
+;-------- translation ------------
+
+      (setq rque (cdr rque)))                    ; while rque
+
+	  ;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 ------------
+
+    (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 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 (> (+ (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-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-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 ------------
+
+      (setq cque (cdr cque)))                    ; while rque
+
+	  ;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 ------------
+
+    (setq rque (cdr rque)))                     ; while cque
+  ) ; let
+) ;defun