bug-bash
[Top][All Lists]
Advanced

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

Old idea for vi-yank-pop


From: ian
Subject: Old idea for vi-yank-pop
Date: Wed, 06 Nov 2013 14:14:27 -0800

A few years ago, I had an idea for bash, which I recently remembered. I
never cared about it enough to propose it, but I figured I should share
in case it is helpful to someone else.

In vim, you can get access to multiple yanks/cuts/kills, but you can't
in bash's vi-mode. It would be a good feature to give vi-mode access to
the the stack of yanks from the default emacs mode. I figured it could
be called vi_yank_pop. This is a patch I wrote a long time ago. I don't
know if it works, and it probably mostly copies the emacs code.

Cheers,
Ian Kelling


--- ../bash-4.0/lib/readline/kill.c     2008-08-12 14:59:31.000000000
-0700
+++ kill.c      2009-03-12 20:58:07.000000000 -0700
@@ -550,6 +550,39 @@
     }
 }
 
+int
+rl_vi_yank_pop (count, key)
+     int count, key;
+{
+  int l, n;
+
+  if (((rl_last_func != rl_vi_yank_pop) && (rl_last_func != rl_vi_put))
||
+      !rl_kill_ring)
+    {
+      _rl_abort_internal ();
+      return -1;
+    }
+
+  l = strlen (rl_kill_ring[rl_kill_index]);
+  n = rl_point - l;
+  if (n >= 0 && STREQN (rl_line_buffer + n + 1,
rl_kill_ring[rl_kill_index], l))
+    {
+      rl_delete_text (n, rl_point);
+      rl_point = n;
+      rl_kill_index--;
+      if (rl_kill_index < 0)
+       rl_kill_index = rl_kill_ring_length - 1;
+      rl_vi_put (1, 'p');
+      return 0;
+    }
+  else
+    {
+      _rl_abort_internal ();
+      return -1;
+    }
+}
+
+
 /* Yank the COUNTh argument from the previous history line, skipping
    HISTORY_SKIP lines before looking for the `previous line'. */
 static int
--- ../bash-4.0/lib/readline/funmap.c   2009-01-04 11:32:33.000000000
-0800
+++ funmap.c    2009-03-12 18:37:18.000000000 -0700
@@ -139,6 +139,7 @@
   { "yank-last-arg", rl_yank_last_arg },
   { "yank-nth-arg", rl_yank_nth_arg },
   { "yank-pop", rl_yank_pop },
+  { "vi-yank-pop", rl_vi_yank_pop },
 
 #if defined (VI_MODE)
   { "vi-append-eol", rl_vi_append_eol },
--- ../bash-4.0/lib/readline/readline.h 2009-01-04 11:32:33.000000000
-0800
+++ readline.h  2009-03-12 18:37:18.000000000 -0700
@@ -167,6 +167,7 @@
 extern int rl_copy_backward_word PARAMS((int, int));
 extern int rl_yank PARAMS((int, int));
 extern int rl_yank_pop PARAMS((int, int));
+extern int rl_vi_yank_pop PARAMS((int, int));
 extern int rl_yank_nth_arg PARAMS((int, int));
 extern int rl_yank_last_arg PARAMS((int, int));
 /* Not available unless __CYGWIN__ is defined. */



reply via email to

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