Community
Participate
Working Groups
In Emacs, when you do a search and replace, the replacement text matches the case of the text being replaced. Supporting this in Eclipse would be immensely useful. Right now, I often drop down to Emacs when I need to do something like this.
Are you talking about the 'Find/Replace' dialog (Ctrl+F) or the 'Search' dialog (Ctrl+H)? Please attach screenshots describing your problem.
Please provide details of the behavior that you would like to see. It should still be possible to do replacement that does not preserve case, shouldn't it? There is currently \C control character for preserving case. If you would like to see a different mechanism, please describe it in detail.
Move to JDT/Text
(In reply to comment #2) > Please provide details of the behavior that you would like to see. It should > still be possible to do replacement that does not preserve case, shouldn't it? > There is currently \C control character for preserving case. If you would like > to see a different mechanism, please describe it in detail. Yes, I see that the \C control character appears to do whatever Emacs does. I did not know it existed. Even when someone brought it to my attention, I did not know how to turn it on until I asked. I would argue that the default behavior for: Find: foobarbaz Replace: abcdefxyz should be: Replace: \Cabcdefxyz For example, Emacs does the following: Original text: foobarbaz fooBarbaz FooBarBaz FOObarBAZ FoOBArbAz FOOBARBAZ Replace with: abcDefXYZ New text: abcDefXYZ abcDefXYZ AbcDefXYZ AbcDefXYZ AbcDefXYZ ABCDEFXYZ Hope this helps, arun
I should add that I am not sure that \C<replacetext> will do what I showed in my example. (In reply to comment #4) > (In reply to comment #2) > > Please provide details of the behavior that you would like to see. It should > > still be possible to do replacement that does not preserve case, shouldn't it? > > There is currently \C control character for preserving case. If you would like > > to see a different mechanism, please describe it in detail. > > Yes, I see that the \C control character appears to do whatever Emacs does. I > did not know it existed. Even when someone brought it to my attention, I did > not know how to turn it on until I asked. > > I would argue that the default behavior for: > > Find: foobarbaz > Replace: abcdefxyz > > should be: > > Replace: \Cabcdefxyz > > For example, Emacs does the following: > > Original text: > > foobarbaz > fooBarbaz > FooBarBaz > FOObarBAZ > FoOBArbAz > FOOBARBAZ > > Replace with: abcDefXYZ > > New text: > > abcDefXYZ > abcDefXYZ > AbcDefXYZ > AbcDefXYZ > AbcDefXYZ > ABCDEFXYZ > > Hope this helps, > arun
(In reply to comment #4) What should happen when the input and output strings have different length? It should be possible to replace FOOBARBAZ get abcDefXYZ and get abcDefXYZ as the result. Does emacs support that? How do you propose this behavior should be controlled?
(In reply to comment #6) > (In reply to comment #4) > > What should happen when the input and output strings have different length? > > It should be possible to replace FOOBARBAZ get abcDefXYZ and get abcDefXYZ as > the result. Does emacs support that? How do you propose this behavior should be > controlled? But that's the whole point. The case of the replacement text influences the final replacement if it deviates from lower case. As I mentioned before, it would help if we made the default behavior be \C<replace-text>
(In reply to comment #7) The question > What should happen when the input and output strings have different length? was not answered in comment #7.
(In reply to comment #8) > (In reply to comment #7) > The question > > > What should happen when the input and output strings have different length? > > was not answered in comment #7. I missed that parts. Here are some examples where the original text is: foobarbaz fooBarbaz FooBarBaz FOObarBAZ FoOBArbAz FOOBARBAZ Replacement is longer: foobarba -> abcDefXYZ Result is: abcDefXYZz abcDefXYZz AbcDefXYZz AbcDefXYZZ AbcDefXYZz ABCDEFXYZZ Replacement is shorter: foobarbaz -> abcDefXY Result is: abcDefXY abcDefXY AbcDefXY AbcDefXY AbcDefXY ABCDEFXY Replacement is longer:
(In reply to comment #9) Do I understand it correctly that using this algorithm it not possible to replace mySomething to yourSomething and MySomething to YourSomething in a single operation?
(In reply to comment #10) > (In reply to comment #9) > > Do I understand it correctly that using this algorithm it not possible to > replace mySomething to yourSomething and MySomething to YourSomething in a > single operation? Everything is possible in Emacs. :-) What I was showing so far is what was possible using the 'M-x query-replace' command (for those who know Emacs). There is another command 'M-x query-replace-regexp' that will do any thing that you can think of and express using regular expressions. I have used Emacs for more years than I would like to share and have never felt the need to use regular expressions for search and replace. Hence, I have never needed to use 'M-x query-replace-regexp'. A simple change to the current default semantics in Eclipse Find and Replace would make it much more useful (of course, IMHO). That is all I am looking for. I am not asking for support for the much more powerful 'query-replace-regexp' command.
(In reply to comment #11) > > Do I understand it correctly that using this algorithm it not possible to > > replace mySomething to yourSomething and MySomething to YourSomething in a > > single operation? I don't think you answered the question above. You are proposing a feature to be implemented in Eclipse. I'm trying to understand the area of applicability of the proposed feature.
(In reply to comment #12) > (In reply to comment #11) > > > Do I understand it correctly that using this algorithm it not possible to > > > replace mySomething to yourSomething and MySomething to YourSomething in a > > > single operation? > > I don't think you answered the question above. You are proposing a feature to > be implemented in Eclipse. I'm trying to understand the area of applicability > of the proposed feature. Yes, it is possible that I don't understand your question. You mentioned an algorithm and I naturally assumed that you were referring to the default semantics that I am suggesting for Eclipse Find and Replace since that has been the discussion so far. If you are referring to some other algorithm, please clarify. If you are asking for the area of applicability, it is text Find and Replace as I understand Eclipse. Again, if you are asking for something else, please clarify. If it is too difficult to implement or would cause too much disruption, please let me know and I'll understand. Thanks for listening, arun
(In reply to comment #13) > Yes, it is possible that I don't understand your question. Let me rephrase it. Is it true that with the Replace algorithm proposed in this feature request it would not be possible to replace mySomething with yourSomething and MySomething with YourSomething in a single Replace operation without using regular expressions?
(In reply to comment #14) > (In reply to comment #13) > > Yes, it is possible that I don't understand your question. > > Let me rephrase it. > > Is it true that with the Replace algorithm proposed in this feature request it > would not be possible to replace mySomething with yourSomething and MySomething > with YourSomething in a single Replace operation without using regular > expressions? In a single operation with our regular expressions, no. The proposed default semantics do not obviate the need for regular expressions as I said in my previous note. In current Eclipse Find and Replace semantics, one would still need to use regular expressions by setting Find -> mySomething Replace -> \Cyour\CSomething Is that what you are looking for?
(In reply to comment #15) Could you please provide real-life use cases where the proposed functionality would useful.
(In reply to comment #16) > (In reply to comment #15) > > Could you please provide real-life use cases where the proposed functionality > would useful. I have many times needed to do the following: replace 'my' with 'your' respecting the case of the replaced text in mySomething MySomething MYSOMETHING In Emacs that is easy in the query-replace command. I cannot do that in Eclipse without the following: Find: my Replace: \Cyour\C with Regular Expression selected. That is exactly the default behavior I am asking for. Hope this helps. arun
The subject says: "Make search and replace work more like other editors". Most editors I know behave like Eclipse. Can you list the editors that support your feature by default (besides Emacs)? We won't change the default as this would be too disruptive for long-time Eclipse users and RCPs. The only way to address this would be to add another check box but that would make the dialog bigger, which is something we tried to avoid in the past.
(In reply to comment #18) > The subject says: "Make search and replace work more like other editors". Most > editors I know behave like Eclipse. Can you list the editors that support your > feature by default (besides Emacs)? > > We won't change the default as this would be too disruptive for long-time > Eclipse users and RCPs. The only way to address this would be to add another > check box but that would make the dialog bigger, which is something we tried to > avoid in the past. No problem, I understand your point about being disruptive. There is a workaround which is to check the Regular Expression box and to surround the replacement text with \C. Also, someone at work has created a plugin that allows us to switch easily between the Eclipse buffer for a file and an Emacs buffer thereby getting the best of both worlds. Thanks for listening, arun