Christian Brabandt
unread,Jul 16, 2012, 3:27:46 PM7/16/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to vim...@googlegroups.com, vim-dev Mailingliste
Bram,
On Sa, 07 Jul 2012, Tim Chase wrote:
> On 07/07/12 06:35, Christian Brabandt wrote:
> >> I'd favor a solution with
> >> :%s/{pattern}/\=CollectMatch(submatch(0))/gn
> >>
> >> but '\=' and the "n" flag don't work together.
> >> What about a todo item? Add another flag?
>
> I must say I'm surprised that the \= and "n" flags don't play well
> together. Though it would toggle 'modified', you could have
> CollectMatch just return its argument for a noop replacement...
Attached s_eval_expr_n-flag.diff allows to execute functions inside the
substitution part of an :s-command. The function is executed inside the
sandbox, which should be good enough. Here is why I'd like such a
function:
I have a plugin Colorizer.vim, that highlights color codes and names by
their values. I found, that the fastest way to do this, is to
issue an :s/.../\=Highlight(submatch)/ Unfortunately, this creates a new
undo-branch, although my plugin does not change the buffer.
The alternative is to manually loop over each line, match against a
pattern and for each pattern found, call the function. This works, but is
way to slow. For my use-case, using the sandbox is good enough.
> > Would a textobject like i/ work?
>
> Two parts of me conflict on this: one thinks "wow, that's a cool
> idea", the other thinks "what twisted sicko thought up that one?!"
> :-) I suspect there are a bunch of odd edge-cases such as
> search-offset modifiers, zero-width assertions of what can
> precede/follow a given pattern, use of the \zs and \ze modifiers, etc.
Attached patch search_textobj.diff implements a match text-object. This
was just a fun way to, to see if this is possible. I don't know, if this
is really useful, so I like the idea. I tried to mimic the behaviour of
existing textobjects as good as possible and so far, it seems to do what
it should.
The inner object jump to the next search-object and in visual-mode on
further jumps stop in front of the next match. The 'a' object jump from
match to match, including trailing whitespace if possible (or leading
whitespace, if no trailing whitespace is possible).
Use i/ for inner-forward search i? for inner-backward object, a/ and a?
for the "a" forward/backwards motions.
BTW: This here looks suspicious:
#define RE_SEARCH 0 /* save/use pat in/from search_pattern */
#define RE_SUBST 1 /* save/use pat in/from subst_pattern */
#define RE_BOTH 2 /* save pat in both patterns */
#define RE_LAST 2 /* use last used pattern if "pat" is NULL */
regards,
Christian
--