Christian Brabandt wrote:

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

I'm confused.  How does this patch to add i/ and a/ related to the :s
command mentioned above?  I'm missing the end goal.


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

RE_BOTH is used for save, RE_LAST for using.


-- 
hundred-and-one symptoms of being an internet addict:
148. You find it easier to dial-up the National Weather Service
     Weather/your_town/now.html than to simply look out the window.

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
You received this message from the "vim_use" 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

Reply via email to