Hi
I've just started using TextMate and I'm hugely impressed by it. My text editor requirements are not very sophisticated, I use it mostly for HTML/CSS and for processing text from time to time from databases, or transcripts of online meetings with chat clients, that kind of thing. I'm sure that I will be using TextMate for my simple AppleScript writing as well now in preference to Apple's rather basic Script Editor.
I have been using BBEdit for ages and I feel it is a very fine text editor indeed, however TextMate is a bit of genius.
Before I used BBEdit I used the Nisus Writer word processor for text editing in the classic Mac OS. Although a word processor Nisus Writer was a superb text editor and, like TextMate offered many truly unique abilities. Nisus also made a text editor called QUED/M which predated their word processor and had similar unique abilities of their word processor.
One of the truly great things about Nisus Writer and QUED/M was the non-contiguous text selection and the way in which Nisus had exploited this.
I think Nisus were the first with non-contiguous text selection but today it is quite common-place. An obvious example is Apple's TextEdit which will do non-contiguous text selection. If you are not familiar with it then you can open an TextEdit document and put it in 'rich text' mode if it is not already. Then put some text into it. Now you can select non-contiguous words in that text using command-click. Now that you have selected those words you can press command-B on your keyboard and those words will turn bold.
I'm now going to describe how Nisus exploited non-contiguous text selection and why it was so very useful.
If you imagine that you have some text which is intended for a web- site. Within the text are various book titles and you wish to surround these with the <em> tag. There is nothing at all about the words of the book titles which is similar. Well with Nisus Writer you would select the book titles non-contiguously, using command-click, then you would get out the Find dialogue and put in the Find field:
.+
In the Replace field:
<em>&<em>
(The & matching all of the Find field)
Then you invoke 'Replace in Selection' and each piece of non- contiguously selected text is now surrounded by <em> tags.
In Nisus Writer you would turn that operation into a macro and now you can apply the <em> tags to any non-contiguously selected text with great ease.
Now it gets cleverer :)
In the example above the replaced text, the book titles surrounded by <em> is still selected after the Find/Replace has been performed. This means that further GREP Find/Replace can by performed using 'Replace in Selection.
With a programme like BBEdit a search for multiple items in a file will produce a browser identifying the search results. However with Nisus Writer a search for multiple items in a file will leave them selected non-contiguously in the file. This enables you to perform a further search on those non-contiguous selections with 'Replace in Selection' again.
To give an example.
I think it is nice to have smart quotes in the displayed text in a web- site. To do this I have to use HTML entities. The actual text I have contains 'stupid' quotes, however I can create a Find/Replace that will look for the 'stupid' quotes and replace them with 'smart quote' HTML entities depending on whether they come before or after words.
The problem is that there are many 'stupid' quotes in the HTML tags for things like class="main".
What I need to do is to find the text between the HTML tags and then replace the 'stupid' quotes in that with the smart quote HTML entities.
To do this in BBEdit I created an AppleScript which has a loop. It finds the first instance of 'text between HTML tags' and then replaces 'stupid' quotes with smart quote HTML tags. Then it finds the next instance of 'text between HTML tags' and so on...
To do that required me to create quite a clunking AppleScript.
However in Nisus Writer I could do it with two simple Find/Replace operations. Because Nisus Writer had non-contiguous selection of course. I could find all the instances of 'text between HTML tags' and know that this was selected. Then I could use 'Replace in Selection' to replace all the 'stupid' quotes with smart quote HTML entities. For Nisus Writer this was an absolutely trivial matter.
So, the moral of my story is that in a text editor with GREP Find/ Replace having non-contiguous text selection brings a massive amount of additional text editing power.
Patrick
On 24 Jun 2008, at 15:26, Patrick James wrote:
[...] So, the moral of my story is that in a text editor with GREP Find/ Replace having non-contiguous text selection brings a massive amount of additional text editing power.
My last comments on this: http://lists.macromates.com/textmate/2007-August/021949.html
As for your smart-quotes example, have a look at http://daringfireball.net/projects/smartypants/ -- this will also skip text inside <pre> etc. It is included with TextMate, so you can e.g. use ⌥⌘R and type ‘SmartyPants.pl’. We don’t have a dedicated command for it, but the Markdown conversion commands (in the Markdown bundle) uses it.
I know your quotes thing was just an example, but I think in most examples where discontinous selection can be used, there is often an existing solution which does the job fine. As mentioned in the linked- too letter, the discountinous selection will introduce _a lot_ of complexity for all commands that work with a selection, and I don’t feel that is worth it (and in TextMate, as opposed to e.g. Nisus Writer, commands for the most part are user-extensions, and the simple contract we presently have for these is IMHO a major contributing factor to the amount of useful bundle commands we have today).
Also, I have another feature coming in 2.0 which will allow you to effectively do the further replacements on the results of a ‘find all’ (so even w/o SmartyPants.pl, there will be a simple way to do the same).
I do however feel TM needs a way to highlight discontinuous text segments, and technically this can be made using dynamic scopes, which in practice can be used by a command to “parse out” the selection…
Hello Allan
Thank you very much for your considered reply.
I have no knowledge of the functioning of TextMate, this ignorance brings a great freedom for me in that I could say that I would like to see this or that without worrying about context or consequences :)
I'm very new to TextMate and to a large extent I am still comprehending it. There is a tendency when people come to a new program to simply want that which they are used to but not see that which is new and perhaps make that which they are used to redundant. I might be guilty of this :)
I do have SmartyPants for BBEdit, which I got after I wrote that script I described in my example. However I'm very glad to see that SmartyPants can also be used with TextMate and I will check this out.
I am very used to having non-contiguous selection and, if you like, the 'Nisus implementation' because I used Nisus Writer and QUED/M for years. So it is something that seems as natural to me as, say, drag and drop.
Below you mention that you are preparing a feature which will allow further replacements in the results of 'find all' and that is a significant part of my request . If it works out it will be very much appreciated.
I am hugely enjoying finding out the tremendous and unique capabilities of TextMate and I wish you all the best with it .
Patrick
On 24 Jun 2008, at 23:24, Allan Odgaard wrote amongst other very good things:
Also, I have another feature coming in 2.0 which will allow you to effectively do the further replacements on the results of a ‘find all’ (so even w/o SmartyPants.pl, there will be a simple way to do the same).