As far as I'm aware there isn't any way of optionally ignoring the additional word characters specified in Preferences when trying to select words.
I'm often wanting to copy, change or set search selection, part of a variable name which doesn't include a dash, underscore, etc., though most of the time I do want it to include those elements as part of a single word.
One solution would be to use a modifier key: So, in my world, Cmd-Opt- Shift + Right or Left arrow would ignore the additional word characters and Cmd-Opt double-click and Cmd-Ctrl W would also work the same way (there may be better modifiers!)
The alternative would be to toggle the additional word characters option in the Edit menu, which would have the downside of not allowing you to dynamically change your specification in mid- selection, but may be simpler to implement.
I've wanted this for a long time and am surprised it hasn't been suggested before (as far as I can remember) which probably means a) that the functionality is there and I just haven't figured out how to open my eyes yet, or b) it's a really crap idea.
Any thoughts? James
On 7/4/2006, at 16:28, James Andrews wrote:
[...] I'm often wanting to copy, change or set search selection, part of a variable name which doesn't include a dash, underscore, etc., though most of the time I do want it to include those elements as part of a single word.
This is very hard to follow. Could you give an example? And is this run-time toggling of the word characters based on basically your mood or could it be boiled down to having different word characters for different scopes (planned) or have the unit you want to work on be something which is already defined by the syntax highlighting (as there are also some plans of making that reachable from commands/ snippets)?
[...] I'm often wanting to copy, change or set search selection, part of a variable name which doesn't include a dash, underscore, etc., though most of the time I do want it to include those elements as part of a single word.
This is very hard to follow. Could you give an example? And is this run-time toggling of the word characters based on basically your mood or could it be boiled down to having different word characters for different scopes (planned) or have the unit you want to work on be something which is already defined by the syntax highlighting (as there are also some plans of making that reachable from commands/snippets)?
Alan, firstly apologies for the lack of clarity, and the delay in replying. The idea isn't for it to be based on my mood (:-P) and neither is it based on scopes or syntax highlighting, unless I misunderstand your meaning.
In quite a number of development situations (Rails, CSS, PHP, XSLT, etc.), commands, variables and other elements are often written in the form xxx-yyy or xxx_yyy_zzz. I often find myself dealing with related entities of the form xxxxxxxxx-aaaaaa and xxxxxxxxx-bbb where I just want to select the xxxxxxxxx or aaaaaa portion quickly and easily to either replace it, copy it or enter it into the search buffer.
Other uses relate to elements such as variables (with @ or $ at the start) or css colour codes (such as #f33456) where you want to select everything except the special character in order to copy or replace it. For example Photoshop doesn't include the # if you copy a colour, so replacing an existing colour in a CSS file is slightly more fiddly than I'd like it to be, and I find that when I'm working on a design I have to do this often.
Using this facility with Cmd-e to 'search in project' allows you to rapidly find related symbols that have something in common without making the scope totally specific to a single entity. i.e. quickly finding a family of variables or commands that share a common element in their name.
So, in other words, it's about ad-hoc selections of text where a lot of the time I want the whole thing but at other times I want a part of it. Usually the difference between the whole of the item and a part is related to these extra word characters (although camel-case is another mechanism for creating a logical element within a contiguous set of characters.)
Ideally, I'd like to be able to do this operation with either keyboard or mouse selection methods, depending on the circumstance.
Having different word characters for different scopes is great is but I'm not sure if that this would answer my request (though it might add to its relevance) which is to be able to (optionally) select word elements.
I hope this explains my meaning. I would be interested to know if it would be considered generally useful. Personally I would use it all the time, but my usage pattern may be different to the majority of people. If you want me to be more specific, I can give some real world examples, but thought my post was already long enough!
On another (related) topic, I really love the new Ctrl-Opt-B. James
On Apr 11, 2006, at 7:24 AM, James Andrews wrote:
In quite a number of development situations (Rails, CSS, PHP, XSLT, etc.), commands, variables and other elements are often written in the form xxx-yyy or xxx_yyy_zzz. I often find myself dealing with related entities of the form xxxxxxxxx-aaaaaa and xxxxxxxxx-bbb where I just want to select the xxxxxxxxx or aaaaaa portion quickly and easily to either replace it, copy it or enter it into the search buffer.
Other uses relate to elements such as variables (with @ or $ at the start) or css colour codes (such as #f33456) where you want to select everything except the special character in order to copy or replace it. For example Photoshop doesn't include the # if you copy a colour, so replacing an existing colour in a CSS file is slightly more fiddly than I'd like it to be, and I find that when I'm working on a design I have to do this often.
This sounds like it could be easily accomplished by a macro recording an appropriate regexp search. If you have the standard word selection include the underscores etc, you could create a macro, bound to your favorite keypress, which does a backward regexp search for a "(sequence of letters, preceded by a nonletter and followed by a nonletter) or (a sequence of numbers, preceded by a nonnumber and followed by a nonnumber)". So maybe something like: ((?<![a-zA-Z])[a-zA-Z]+(?![a-zA-Z]))|((?<![0-9])[0-9]+(?![0-9]))
Of course you can adjust it to your liking. Once Allan also plans to allow mouse gestures as triggers for bundle items, you will be able to even trigger this by some mouse gesture. Unless I've misunderstood what you are trying to do.
Haris
On 11 Apr 2006, at 13:46, Charilaos Skiadas wrote:
On Apr 11, 2006, at 7:24 AM, James Andrews wrote:
In quite a number of development situations (Rails, CSS, PHP, XSLT, etc.), commands, variables and other elements are often written in the form xxx-yyy or xxx_yyy_zzz. I often find myself dealing with related entities of the form xxxxxxxxx-aaaaaa and xxxxxxxxx-bbb where I just want to select the xxxxxxxxx or aaaaaa portion quickly and easily to either replace it, copy it or enter it into the search buffer.
Other uses relate to elements such as variables (with @ or $ at the start) or css colour codes (such as #f33456) where you want to select everything except the special character in order to copy or replace it. For example Photoshop doesn't include the # if you copy a colour, so replacing an existing colour in a CSS file is slightly more fiddly than I'd like it to be, and I find that when I'm working on a design I have to do this often.
This sounds like it could be easily accomplished by a macro recording an appropriate regexp search. If you have the standard word selection include the underscores etc, you could create a macro, bound to your favorite keypress, which does a backward regexp search for a "(sequence of letters, preceded by a nonletter and followed by a nonletter) or (a sequence of numbers, preceded by a nonnumber and followed by a nonnumber)". So maybe something like: ((?<![a-zA-Z])[a-zA-Z]+(?![a-zA-Z]))|((?<![0-9])[0-9]+(?![0-9]))
Hi Haris,
This wasn't quite what I had in mind (more an extension of existing keyboard or mouse text selection techniques using an added modifier key) but it would be an alternative (and quick to implement) if it could be made to work.
What commands would you combine with the regex to result in selecting text at the cursor with the specified scope? I've done some thinking and digging around in case I'd missed something, but can't see how it could be done.
Thanks, James
On Apr 11, 2006, at 9:21 AM, James Andrews wrote:
Hi Haris,
This wasn't quite what I had in mind (more an extension of existing keyboard or mouse text selection techniques using an added modifier key) but it would be an alternative (and quick to implement) if it could be made to work.
What commands would you combine with the regex to result in selecting text at the cursor with the specified scope? I've done some thinking and digging around in case I'd missed something, but can't see how it could be done.
Wait, I don't see where scope comes in in what you discussed above, I don't thing that would help you select the foo in foo_bar. That is another, very interesting question, which does not have a trivial answer atm, though I guess Allan could possibly provide such a command, that selects the entire current scope. He has however given us the tools to create it ourselves, using the new inputFormat plist key (see the release notes):
Basically it is now possible to get as input to a command an "xml" version of the text, where the tags are exactly the scopes. Scanning this file would, theoretically, allow you to select the current scope. The problem would probably be to locate the text right where the cursor is. Possible with a bit of programming. You'd basically need (I think) to locate all text nodes and count newlines until you match TM_LINE_NUMBER. Then scan characters until TM_LINE_INDEX. Then select the text node containing this character. At the end of the day you would have a command that outputs the whole text of the current scope. Then you could also have the command use pbcopy to place this into the pasteboard and discard its output. Then you could use this in a macro together with a literal backward search to actually select the corresponding text. The only drawback of this, apart from its slowness in large documents, is the fact that it alters the pasteboard. Another alternative, if TextMate's applescripting possibilities allow this (which I think they don't at the moment, though I'd like to put it as a request if they don't), is to tell TextMate through osascript to do a backward search for the appropriate text, all from within the command. That would leave the pasteboard intact.
Sorry for the technical answer.
Thanks, James
Haris
On 11/4/2006, at 16:21, James Andrews wrote:
This wasn't quite what I had in mind (more an extension of existing keyboard or mouse text selection techniques using an added modifier key) but it would be an alternative (and quick to implement) if it could be made to work.
What commands would you combine with the regex to result in selecting text at the cursor with the specified scope? [...]
Try this:
1) Automation -> Start Macro Recording 2) Edit -> Find -> Find… 3) Enter this as search string: (?<![a-z])[a-z]+(?![a-z]) 4) Check the regular expression and ignore case checkboxes 5) Click Previous and close the Find dialog 6) Automation -> Stop Macro Recording
Now you have a macro which _selects_ the current word defined as only consisting of a-z.
You can save this macro on any key you like, e.g. put it on option-W to signal “modified word selection”.
You can give this (saved) macro a scope selector. For example if this is how you want word selections in CSS properties, give it a scope selector of meta.property-list.css or just source.css -- then you can record macros (with changed character sets) for other scopes and use the same key (and TM will pick the proper macro), or you can use different keys for different variants.
On 11 Apr 2006, at 16:02, Allan Odgaard wrote:
Try this:
- Automation -> Start Macro Recording
- Edit -> Find -> Find…
- Enter this as search string: (?<![a-z])[a-z]+(?![a-z])
- Check the regular expression and ignore case checkboxes
- Click Previous and close the Find dialog
- Automation -> Stop Macro Recording
Now you have a macro which _selects_ the current word defined as only consisting of a-z.
Thanks Allan, this works a treat - I modified the regex to include numbers: (?<![a-z0-9])[a-z0-9]+(?![a-z0-9])
You can save this macro on any key you like, e.g. put it on option- W to signal “modified word selection”.
Option-w creates this: ∑ so I settled on ctrl-opt-w. Since repeated presses causes the selection to move backwards through words/word elements, I've actually recorded another version on linked keys to move forwards (shift-ctrl-opt-w).
You can give this (saved) macro a scope selector. For example if this is how you want word selections in CSS properties, give it a scope selector of meta.property-list.css or just source.css -- then you can record macros (with changed character sets) for other scopes and use the same key (and TM will pick the proper macro), or you can use different keys for different variants.
It's great that scopes can alter the behaviour of this depending on the type of content you're working on - I'll wait to see if I actually need to use this.
Perhaps there isn't the demand for this from elsewhere, but I would like to see my original suggestion implemented within TM at some point, as the macro approach does have some drawbacks in terms of expected or desired behaviour (Issues 1 & 2 are linked and probably fixable by modifying the macro):
1/ unlike ctrl-w, the current selection changes with repeated presses (though I've tried to make a virtue of this fact.) 2/ if at the start of the word/'word element' it selects the previous word or word element rather than the current one. 3/ cannot extend the selection to include the whole of the next 'word element' as you can do with words (using shift-opt-left or right.) 4/ cannot jump the cursor to the next 'word element' boundary - equivalent of cmd-left or cmd-right. 5/ cannot utilise mouse equivalents of selecting the whole word (double-click.) 6/ requires a change of mental context to switch to a command based keystroke rather than using current selection keys or mousing techniques with an additional modifier.
This probably 'ain't a priority', but I just wanted to suggest the idea so it was 'out'. After all, I already have a solution that does most of what I need (once again proving the power and flexibility of TM) and the full answer may lie in adding even more functionality to macros to obviate the issues I raised.
Thanks for the help and responses and thanks for listening. James
James Andrews Director
r e - c o g http://re-cog.com http://re-cogmedia.com