> > > No because every delete/yank use the " register even if a register was
> > > explicitely specified. As a matter of completeness maybe it'd be nice
> > > to know which register was intended yes but it's the first time I
> > > fiddle with vim's source (with some pain) so I'm not too sure how much
> > > work is involved in creating one of those v:somevar.
>
> > OK, we can add it later when really needed.
>
> Do we get it for free? :help v:register says it contains "the name of
> the register in effect for the current normal mode command". It
> certainly seems like it *could* contain the register used, though I'm
> not sure whether the contents are lost before the autocmd fires.

Actually we do! Didn't know v:register existed, thanks!

Here's what I test it with:

autocmd! TextDeletePost * echom 'DeletePost: Register(' . v:register .
') Value(' . eval('@' . v:register) . ')'
autocmd! TextYankPost   * echom 'YankPost: Register(' . v:register .
') Value(' . eval('@' . v:register) . ')'

Here's the (hopefully final) patch:

>From 15a2f33bd2dd3d10d0f167e249546fcff8f7e9a0 Mon Sep 17 00:00:00 2001
From: Philippe Vaucher <[email protected]>
Date: Tue, 24 May 2011 20:32:48 +0200
Subject: [PATCH] Add TextDeletePost and TextYankPost events

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

diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt
index 145ecf6..93fdefc 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

+|TextDeletePost|       when some text is deleted (dw, dd, D)
+|TextYankPost|         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,24 @@ 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.
+                                                       *TextDeletePost*
+TextDeletePost                 Just after a delete (|d|) command is issued.
+                                Not issued if the black hole register
+                                (|quote_|) is used. The affected text
can be
+                                accessed by several ways, through @"
+                                (|quotequote| or |v:register|: >
+                                  :echo @"
+                                  :echo eval('@' . v:register)
+<
+                                                       *TextYankPost*
+TextYankPost                   Just after a |yank| (|y|) command is issued.
+                                Not issued if the black hole register
+                                (|quote_|) is used. The affected text
can be
+                                accessed by several ways, through @"
+                                (|quotequote| or |v:register|: >
+                                  :echo @"
+                                  :echo eval('@' . v:register)
+<
                                                        *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..a794a04 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},
+    {"TextDeletePost", EVENT_TEXTDELETEPOST},
+    {"TextYankPost",   EVENT_TEXTYANKPOST},
     {NULL,             (event_T)0}
 };

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

+    ++textlock;
+    apply_autocmds(deleting ? EVENT_TEXTDELETEPOST :
EVENT_TEXTYANKPOST, NULL, NULL, FALSE, curbuf);
+    --textlock;
+
     return OK;

 fail:          /* free the allocated lines */
diff --git a/src/vim.h b/src/vim.h
index 1f4f17b..dc147cf 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_TEXTDELETEPOST,      /* after a delete command was done (dd, dw,
D) */
+    EVENT_TEXTYANKPOST,                /* after a yank command was done (yy, 
yw, Y)
*/
     NUM_EVENTS                 /* MUST be the last one */
 };

--
1.7.1

-- 
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