Hello,

I added TextDelete and TextYank events.

This necessity appeared because of the small delete register getting
in our way in order to implement a proper killring. There exists a
plugin that tries to address it (YankRing.vim) but then other things
break down, like macros with counts, not to mention the plugin is
heavy.

This issue was raised on irc by the-isz and myself after we realised
we couldn't have a nice flow about editing some file like this:

delete a word (dw), remove some trailing spaces (xxx), go to end of
line ($), paste word (arg, dw didn't put word in registers 1-9, need
to undo, put word in explicit register, etc)

With this patch, we can now make a very simple "YankRing" plugin which
only stores Yanked/Deleted texts by listening on those events, without
interfering with all the vim commands like the original YankRing
plugin does.

You can test it with:

autocmd TextDeleted * echom 'Deleted: ' . @"
autocmd TextYanked * echom 'Yanked: ' . @"

Tell me what you think.

Philippe


>From f82fa9037bf6bd2013742e9502ffcdea903e8401 Mon Sep 17 00:00:00 2001
From: Philippe Vaucher <[email protected]>
Date: Mon, 23 May 2011 17:08:51 +0200
Subject: [PATCH] Added TextDeleted and TextYanked events

---
 runtime/doc/autocmd.txt |   13 +++++++++++++
 src/fileio.c            |    2 ++
 src/ops.c               |    2 ++
 src/vim.h               |    2 ++
 4 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt
index 145ecf6..057db21 100644
--- a/runtime/doc/autocmd.txt
+++ b/runtime/doc/autocmd.txt
@@ -302,6 +302,9 @@ Name                        triggered by ~
 |InsertCharPre|                when a character was typed in Insert mode, 
before
                        inserting it

+|TextDeleted|          when some text is deleted (dw, dd, D)
+|TextYanked|           when some text is yanked (yw, yd, Y)
+
 |ColorScheme|          after loading a color scheme

 |RemoteReply|          a reply from a server Vim was received
@@ -670,6 +673,16 @@ InsertCharPre                      When a character is 
typed in
Insert mode,
                                It is not allowed to change the text |textlock|.
                                The event is not triggered when 'paste' is
                                set.
+                                                       *TextDeleted*
+TextDeleted                    Just after a delete (|d|) command is issued.
+                                You can inspect the @" variable to
know
+                                about the deleted text.
+
+                                                       *TextYanked*
+TextYanked                     Just after a |yank| (|y|) command is issued.
+                                You can inspect the @" variable to
know
+                                about the deleted text.
+
                                                        *InsertEnter*
 InsertEnter                    Just before starting Insert mode.  Also for
                                Replace mode and Virtual Replace mode.  The
diff --git a/src/fileio.c b/src/fileio.c
index 6355c79..81b09e2 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -7688,6 +7688,8 @@ static struct event_name
     {"WinEnter",       EVENT_WINENTER},
     {"WinLeave",       EVENT_WINLEAVE},
     {"VimResized",     EVENT_VIMRESIZED},
+    {"TextDeleted",    EVENT_TEXTDELETED},
+    {"TextYanked",     EVENT_TEXTYANKED},
     {NULL,             (event_T)0}
 };

diff --git a/src/ops.c b/src/ops.c
index c41f844..375e629 100644
--- a/src/ops.c
+++ b/src/ops.c
@@ -3160,6 +3160,8 @@ op_yank(oap, deleting, mess)
 # endif
 #endif

+    apply_autocmds(deleting ? EVENT_TEXTDELETED : EVENT_TEXTYANKED,
NULL, NULL, FALSE, curbuf);
+
     return OK;

 fail:          /* free the allocated lines */
diff --git a/src/vim.h b/src/vim.h
index 1f4f17b..5473a21 100644
--- a/src/vim.h
+++ b/src/vim.h
@@ -1290,6 +1290,8 @@ enum auto_event
     EVENT_TABENTER,            /* after entering a tab page */
     EVENT_SHELLCMDPOST,                /* after ":!cmd" */
     EVENT_SHELLFILTERPOST,     /* after ":1,2!cmd", ":w !cmd", ":r !cmd".
*/
+    EVENT_TEXTDELETED,         /* after a delete command was done (dd, dw,
D) */
+    EVENT_TEXTYANKED,          /* after a yank command was done (yy, yw, Y)
*/
     NUM_EVENTS                 /* MUST be the last one */
 };

--
1.7.4.msysgit.0

-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Raspunde prin e-mail lui