qemacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemacs-devel] Patch to make killing and yanking more emacs-like


From: Max Thoursie
Subject: [Qemacs-devel] Patch to make killing and yanking more emacs-like
Date: Thu, 30 Oct 2003 21:53:38 +0100
User-agent: Mutt/1.4i

I found that in some aspects killing and yanking is different from
emacs.

Successive kills appends to the kill buffer, so that one can kill for
example three lines (including the newline separator) by striking C-k
six times, and then paste all three lines elsewhere with a C-y stroke.

This patch adds this behavior to qemacs. In detail:

- kill appends to killbuffer if last command was a kill
- yank moves mark to beginning of yanked region
- yank-pop uses delete instead of undo
- yank-pop checks that previous was a yank
- yank-pop only cycles though used kill-buffers

/Max Thoursie

diff -u qemacs-0.3.1/qe.c qemacs-0.3.1-kill/qe.c
--- qemacs-0.3.1/qe.c     Tue Apr 22 00:01:42 2003
+++ qemacs-0.3.1-kill/qe.c    Thu Oct 30 21:10:52 2003
@@ -1259,8 +1259,14 @@
     QEmacsState *qs = &qe_state;
     EditBuffer *b;
 
-    if (++qs->yank_current == NB_YANK_BUFFERS)
-        qs->yank_current = 0;
+    if(qs->yank_used == NB_YANK_BUFFERS) {
+        if (++qs->yank_current == NB_YANK_BUFFERS)
+            qs->yank_current = 0;
+    } else {
+        qs->yank_current = qs->yank_used;
+        qs->yank_used++;
+    }
+            
     b = qs->yank_buffers[qs->yank_current];
     if (b)
         eb_free(b);
@@ -1300,8 +1306,13 @@
         p2 = tmp;
     }
     len = p2 - p1;
-    b = new_yank_buffer();
-    eb_insert_buffer(b, 0, s->b, p1, len);
+
+    /* if last cmd was kill, append to yankbuffer */
+    if (!(qs->last_cmd_func == do_kill_region
+          && (b = qs->yank_buffers[qs->yank_current])))
+            b = new_yank_buffer();
+    eb_insert_buffer(b, b->total_size, s->b, p1, len);
+
     if (kill) {
         eb_delete(s->b, p1, len);
         s->offset = p1;
@@ -1326,6 +1337,7 @@
         return;
     size = b->total_size;
     if (size > 0) {
+        s->b->mark = s->offset;
         eb_insert_buffer(s->b, s->offset, b, 0, size);
         s->offset += size;
     }
@@ -1333,13 +1345,27 @@
 
 void do_yank_pop(EditState *s)
 {
+    int off, len;
     QEmacsState *qs = s->qe_state;
 
-    /* XXX: should verify if last command was a yank */
-    do_undo(s);
-    /* XXX: not strictly correct if the ring is not full */
+    if (qs->last_cmd_func != do_yank &&
+        qs->last_cmd_func != do_yank_pop) {
+            put_status(s, "Previous command was not a yank");
+            return;
+    }
+
+    off = s->b->mark;
+    len = s->offset - off;
+    /* if previous command was a yank, this should never be the case
-    */
+    /* however, emacs's yank has an option to exchange point and mark
-    */
+    if (len < 0) {
+        off += len;
+        len = -len;
+    }
+    eb_delete(s->b, off, len);
+    
     if (--qs->yank_current < 0)
-        qs->yank_current = NB_YANK_BUFFERS - 1;
+        qs->yank_current = qs->yank_used - 1;
     do_yank(s);
 }
 
@@ -6260,7 +6286,10 @@
     }
     qe_state.macro_key_index = -1; /* no macro executing */
     qe_state.ungot_key = -1; /* no unget key */
-    
+
+    /* XXX: move this? */
+    qe_state.yank_used = 0; /* no unsed yank buffers */
+                    
     eb_init();
     charset_init();
     init_input_methods();
diff -u qemacs-0.3.1/qe.h qemacs-0.3.1-kill/qe.h
--- qemacs-0.3.1/qe.h     Tue Apr 22 00:01:42 2003
+++ qemacs-0.3.1-kill/qe.h    Thu Oct 30 21:09:23 2003
@@ -835,6 +835,7 @@
     /* yank buffers */
     EditBuffer *yank_buffers[NB_YANK_BUFFERS];
     int yank_current;
+    int yank_used;
     char res_path[1024];
     char status_shadow[MAX_SCREEN_WIDTH];
     char system_fonts[NB_FONT_FAMILIES][256];




reply via email to

[Prev in Thread] Current Thread [Next in Thread]