Ok we did some tests and now everything works as it should.
For a better view of the patch, see
https://github.com/Silex/vim/commit/de0dd46e90fd7c6587492d3d7f8878d9f57f42f2
We tested with `vim -u NONE -U NONE --noplugin test.vim`, followed
by :so % and
test.vim being:
let s:count = 0
function! s:del_or_yank_event(desc)
echom s:count . ' ' . a:desc . ': Register(' . v:register . ')
Value(' . eval('@' . v:register) . ')'
let s:count += 1
endfunction
autocmd! TextDeletePost * call
<SID>del_or_yank_event('TextDeletePost')
autocmd! TextYankPost * call
<SID>del_or_yank_event('TextYankPost')
Tell me if there's an issue I forgot to address.
Here's the patch:
>From de0dd46e90fd7c6587492d3d7f8878d9f57f42f2 Mon Sep 17 00:00:00 2001
From: Philippe Vaucher <[email protected]>
Date: Wed, 25 May 2011 13:02:28 +0200
Subject: [PATCH] Add TextDeletePost and TextYankPost events
---
runtime/doc/autocmd.txt | 21 +++++++++++++++++++++
src/fileio.c | 2 ++
src/ops.c | 11 +++++++++++
src/vim.h | 2 ++
4 files changed, 36 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..5709aa5 100644
--- a/src/ops.c
+++ b/src/ops.c
@@ -1957,6 +1957,10 @@ op_delete(oap)
msgmore(curbuf->b_ml.ml_line_count - old_lcount);
+ ++textlock;
+ apply_autocmds(EVENT_TEXTDELETEPOST, NULL, NULL, FALSE, curbuf);
+ --textlock;
+
#ifdef FEAT_VIRTUALEDIT
setmarks:
#endif
@@ -3160,6 +3164,13 @@ op_yank(oap, deleting, mess)
# endif
#endif
+ if(mess && !deleting)
+ {
+ ++textlock;
+ apply_autocmds(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.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