Hello, I'm trying to use a regexp with look-ahead. The search works, but clicking "replace" button does nothing. I'm stumped. Here's an example:
Find: public (?=int) Replace: private Regular expression: checked Ignore case: unchecked Wrap around: checked
Click "find" and "public " is selected, but then clicking "replace" does nothing. Also "replace and find" goes to the next occurrence, but does not perform the replacement.
Using Textmate 1.5.10
Thanks, ErikN
On Thu, Feb 16, 2012 at 06:41, Erik Neumann erikn@myphysicslab.com wrote:
Hello, I'm trying to use a regexp with look-ahead. The search works, but clicking "replace" button does nothing. I'm stumped. Here's an example:
Find: public (?=int) Replace: private Regular expression: checked Ignore case: unchecked Wrap around: checked
Click "find" and "public " is selected, but then clicking "replace" does nothing. Also "replace and find" goes to the next occurrence, but does not perform the replacement.
FWIW, "replace all" works for me in that scenario.
Martin
"replace all" works for me too. Which makes me feel confident this is a bug and not a mistake on my part. Is there a place other than this email list to report a bug in Textmate? --ErikN
On Wed, Feb 15, 2012 at 11:52 PM, Martin Kühl martin.kuehl@gmail.comwrote:
On Thu, Feb 16, 2012 at 06:41, Erik Neumann erikn@myphysicslab.com wrote:
Hello, I'm trying to use a regexp with look-ahead. The search works,
but
clicking "replace" button does nothing. I'm stumped. Here's an example:
Find: public (?=int) Replace: private Regular expression: checked Ignore case: unchecked Wrap around: checked
Click "find" and "public " is selected, but then clicking "replace" does nothing. Also "replace and find" goes to the next occurrence, but does
not
perform the replacement.
FWIW, "replace all" works for me in that scenario.
Martin
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
On Thu, Feb 16, 2012 at 22:12, Erik Neumann erikn@myphysicslab.com wrote:
"replace all" works for me too. Which makes me feel confident this is a bug and not a mistake on my part. Is there a place other than this email list to report a bug in Textmate?
http://wiki.macromates.com/Main/BugReporting
The mailing list is usually sufficient.
Cheers, Martin
On 17/02/2012, at 04.12, Erik Neumann wrote:
"replace all" works for me too. Which makes me feel confident this is a bug and not a mistake on my part.
This is basically the same as http://lists.macromates.com/textmate/2011-September/032978.html
Is there a place other than this email list to report a bug in Textmate?
Only via direct email (see contact page) but it is highly unlikely that 1.x will see any more updates (other than the one I have pending but yet to push).
Ah, interesting. I was unaware of the "replace all in selection" command on the Find menu. However, the "replace" button in the Find dialog seems to do something different from the "replace all in selection" command. The "replace" button seems to be "do the find once in the selection, and then replace the entire selection using the result of the first successful match". The explanation that the lookahead fails to match within the selection explains the behavior.
For example, here is a regexp without look-ahead: Find: public ([^ ]+) Replace: private $1 Regular expression: selected Text: public String toString() { } public void makeFoo() { } public void makeBar() { }
If I select this area of text and do "replace all in selection" from the Find menu it replaces the 3 instances of "public" with "private", and the selection range is preserved. But if I click the replace button of the Find dialog, then the entire selection is replaced by the result of the first match, which is "private String".
I can use the "replace all" or "replace all in selection" as a workaround. Maybe put a note in the help file that the replace button is really "replace selection with result of first match in selection"?
Regards, ErikN
On Fri, Feb 17, 2012 at 4:33 AM, Allan Odgaard mailinglist@textmate.orgwrote:
On 17/02/2012, at 04.12, Erik Neumann wrote:
"replace all" works for me too. Which makes me feel confident this is a
bug and not a mistake on my part.
This is basically the same as http://lists.macromates.com/textmate/2011-September/032978.html
On 5 Sep 2011, at 05:06, Brandon M Fryslie wrote:
- […] when I do Replace in Current Selection (shortcut or menu) nothing is replaced. […] My hunch says it has something to do with the negative lookbehind but I don't see any way in which I've used it incorrectly so I am stumped.*>* *>* Anyone have any suggestions or is this a bug?*
This is a bug / limitation: When you Replace in Selection and your regexp matches text _outside_ the selection (via look-around assertions) it will fail because it doesn’t have access to the text outside the selection.
The only workaround is to ensure the stuff matched in the look-around assertion is also part of the selection when using Replace in Selection (or alternatively use Replace All).
On 17/02/2012, at 23.38, Erik Neumann wrote:
[…] However, the "replace" button in the Find dialog seems to do something different from the "replace all in selection" command. The "replace" button seems to be "do the find once in the selection, and then replace the entire selection using the result of the first successful match".
Replace is effectively just “overwrite selection with the content of the replace field” but if the latter is a regexp, it tries needs to match the find string against the selection for potential captures for the format string expansion.
This is a lot simpler than having to store state about last find action and I think I tested a few other applications and found they did the same before I did it. I want to change it in 2.0 though still haven’t added the proper “remember last find” state.
[…] Maybe put a note in the help file that the replace button is really "replace selection with result of first match in selection"?
I think this is the second or third time it has come up in the 7 years TextMate has done this. Doubt that number would have been lower if it was explicitly spelled out in the help book ;)