[CCing vim_dev; apologies for my continued disorganised postings!]
OK, folks,
After reading feedback, etc., here is a revised patch. It's just the
documentation
that is different from the previous patch.
In the end, given that a number of things can be done without v:operator, as
Andy
demonstrated, and that Yankring is a pretty specific example, I thought perhaps
the best thing would be to put a brief example analogous to the v:prevcount
example which is right nextdoor in the docs.
If you still think a lengthier example is better, though, Bram, I'm happy to
revise the patch again. I thought this, or a scaled-down count-ignorant version
might be a more useful lengthy example (compared to the function name thing I
suggested before):
:" Defines a motion/text-object <C> which allows you to operate on
:" the {count}th column of a tab-delimited table, or the column
:" the cursor is currently in if no count is given.
:onoremap C <Esc>:call OperateColumn()<CR>
:function! OperateColumn()
: let c = v:prevcount
: if c == 0
: call search('^\|\t\zs','bc',line("."))
: else
: call cursor(line("."),1)
: while search('\v(\zs[^\t]*(\t|$)){'.c.'}','c',line(".")) == 0
: call setline(line("."),getline(line("."))."\t")
: endwhile
: endif
: call feedkeys('"'.v:register.v:operator)
: if strpart(getline(line('.')),col('.')-1,1) == "\t"
: call feedkeys(":\<CR>")
: else
: call feedkeys(search('\t','n',line(".")) == 0 ? "$" : "t\t")
: endif
:endfun
Ben.
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---
Index: runtime/doc/eval.txt
===================================================================
--- runtime/doc/eval.txt (revision 621)
+++ runtime/doc/eval.txt (working copy)
@@ -1401,10 +1401,20 @@
This is the screen column number, like with |virtcol()|. The
value is zero when there was no mouse button click.
+ *v:operator* *operator-variable*
+v:operator The last operator given in Normal mode. This is a single
+ character except for commands starting with <g> or <z>,
+ in which case it is two characters. Best used alongside
+ |v:prevcount| and |v:register|. Useful if you want to cancel
+ Operator-pending mode and then use the operator. >
+ :omap O <Esc>:call MyMotion(v:operator)<CR>
+< Read-only.
+
*v:prevcount* *prevcount-variable*
v:prevcount The count given for the last but one Normal mode command.
This is the v:count value of the previous command. Useful if
- you want to cancel Visual mode and then use the count. >
+ you want to cancel Visual or Operator-pending mode and then
+ use the count. >
:vmap % <Esc>:call MyFilter(v:prevcount)<CR>
< Read-only.
Index: src/vim.h
===================================================================
--- src/vim.h (revision 607)
+++ src/vim.h (working copy)
@@ -1688,7 +1688,8 @@
#define VV_MOUSE_WIN 49
#define VV_MOUSE_LNUM 50
#define VV_MOUSE_COL 51
-#define VV_LEN 52 /* number of v: vars */
+#define VV_OP 52
+#define VV_LEN 53 /* number of v: vars */
#ifdef FEAT_CLIPBOARD
Index: src/eval.c
===================================================================
--- src/eval.c (revision 607)
+++ src/eval.c (working copy)
@@ -345,6 +345,7 @@
{VV_NAME("mouse_win", VAR_NUMBER), 0},
{VV_NAME("mouse_lnum", VAR_NUMBER), 0},
{VV_NAME("mouse_col", VAR_NUMBER), 0},
+ {VV_NAME("operator", VAR_STRING), VV_RO},
};
/* shorthand */
@@ -17260,6 +17261,35 @@
}
/*
+ * Set v:operator if needed.
+ */
+ void
+set_op_var(optype)
+ int optype;
+{
+ /* This will either be two operator characters, or one and a NUL. */
+ char_u opchars[2];
+
+ if (optype == OP_NOP)
+ {
+ set_vim_var_string(VV_OP, NULL, 0);
+ return;
+ }
+
+ opchars[0] = get_op_char(optype);
+ if (opchars[0] == 'g' || opchars[0] == 'z')
+ opchars[1] = get_extra_op_char(optype);
+ else
+ opchars[1] = 0;
+
+ /* Avoid free/alloc when the value is already right. */
+ if (vimvars[VV_OP].vv_str == NULL ||
+ vimvars[VV_OP].vv_str[0] != opchars[0] ||
+ vimvars[VV_OP].vv_str[1] != opchars[1])
+ set_vim_var_string(VV_OP, opchars, opchars[1]==0?1:2);
+}
+
+/*
* Get or set v:exception. If "oldval" == NULL, return the current value.
* Otherwise, restore the value to "oldval" and return NULL.
* Must always be called in pairs to save and restore v:exception! Does not
Index: src/normal.c
===================================================================
--- src/normal.c (revision 607)
+++ src/normal.c (working copy)
@@ -7173,6 +7173,7 @@
{
cap->oap->start = curwin->w_cursor;
cap->oap->op_type = OP_DELETE;
+ set_op_var(OP_DELETE);
cap->count1 = 1;
nv_dollar(cap);
finish_op = TRUE;
@@ -8212,6 +8213,7 @@
{
cap->oap->start = curwin->w_cursor;
cap->oap->op_type = op_type;
+ set_op_var(op_type);
}
}