[TxMt] Re: Select and Replace: magic needed....
Scott Haneda
talklists at newgeo.com
Mon Jun 15 19:28:19 UTC 2009
On Jun 15, 2009, at 11:11 AM, Nicholas Cole wrote:
> Dear All,
>
> Many years ago, in a state of innocence, I hard-coded my LaTeX
> quotation marks.
>
>> Thus I have text that `looks like this'.
>
> I now find that it would have been MUCH better (if not essential) to
> have done:
>
>> Thus I have text that \enquote{looks like this}
>
> I can't do a search and replace, because there is no algorithm that
> will get the quotes right, but I would like to be able to do the
> following:
>
> 1. Select the text that needs changing with the mouse
>
> 2. Hit a key and have the text changed to the \enquote version.
>
> I feel like this ought to be the sort of thing that TextMate excels
> at. How should I do it?
Just playing around, not sure if I understand your case. Starting
with this sample text as in put, in a TM file:
`looks like this' dsa 'dsadad'
`looks like this' dsadsad `looks like this'
Search on patterh: `(.+?)'
Replace with pattern \enquote{$1}
Result:
\enquote{looks like this} dsa 'dsadad'
\enquote{looks like this} dsadsad \enquote{looks like this}
I made a Macro that works only on the selection, as you asked, but you
can change it to work on the entire document if desired:
{
action = replaceAll;
findInProjectIgnoreCase = 1;
findString = "`(.+?)'";
ignoreCase = 1;
regularExpression = 1;
replaceAllScope = selection;
replaceString = "\\enquote{$1}";
wrapAround = 1;
}
What wold be more ideal, I think, is to take the cursor position, and
grow a selection to the left and right until the selection hits a
known list of characters on the left and right. I am not sure how to
alter the "select word", or "Select Enclosing Brackets", which I
believe would be a good place to start in getting this to work as you
want it.
Hope this helps.
--
Scott * If you contact me off list replace talklists@ with scott@ *
More information about the textmate
mailing list