The macro described here has a few oddities. http://comox.textdrive.com/pipermail/textmate/2005-October/006444.html
<quote> 1) move to beginning of line (ctrl A) 2) regexp search for: (?=\S|$) </quote>
Lets say '#' indicates where the cursor is.
When I press Home on the following line.. @implementation App#Controller Then the cursor is placed between '@' and 'i'.
When I press Home on the following line.. x -(IBAction)te#st:(id)sender { Then the cursor is placed just before '-'.
Pressing home on an empty line then the cursor is placed on the following line.
Is there a better smart-home macro? preferable a smart-home macro that can toggle between line-begin and text-begin.
-- Simon Strandgaard http://opcoders.com/
On 12/8/06, Simon Strandgaard neoneye@gmail.com wrote:
The macro described here has a few oddities. http://comox.textdrive.com/pipermail/textmate/2005-October/006444.html
<quote> 1) move to beginning of line (ctrl A) 2) regexp search for: (?=\S|$) </quote>
Lets say '#' indicates where the cursor is.
When I press Home on the following line.. @implementation App#Controller Then the cursor is placed between '@' and 'i'.
When I press Home on the following line.. x -(IBAction)te#st:(id)sender { Then the cursor is placed just before '-'.
Pressing home on an empty line then the cursor is placed on the following line.
Is there a better smart-home macro? preferable a smart-home macro that can toggle between line-begin and text-begin.
I never got an answer on this issue.
If any of you are using smart home, what way did you define it?
Simon Strandgaard wrote:
On 12/8/06, Simon Strandgaard
Is there a better smart-home macro? preferable a smart-home macro that can toggle between line-begin and text-begin.
I never got an answer on this issue.
If any of you are using smart home, what way did you define it?
I don't use such a macro, but I imagine you can get it to work basically however you want. How is that, exactly?
-Jacob
Jacob Rus wrote:
Simon Strandgaard wrote:
On 12/8/06, Simon Strandgaard
Is there a better smart-home macro? preferable a smart-home macro that can toggle between line-begin and text-begin.
I never got an answer on this issue.
If any of you are using smart home, what way did you define it?
I don't use such a macro, but I imagine you can get it to work basically however you want. How is that, exactly?
what if you do:
* move to beginning of line * search ahead (w/ regexp) for `[^ \t]` * move left
that should do what you want, as far as I cant tell.
-Jacob
On 4/7/07, Jacob Rus jrus@hcs.harvard.edu wrote:
Jacob Rus wrote:
Simon Strandgaard wrote:
On 12/8/06, Simon Strandgaard
[snip]
If any of you are using smart home, what way did you define it?
[snip]
what if you do:
- move to beginning of line
- search ahead (w/ regexp) for `[^ \t]`
- move left
that should do what you want, as far as I cant tell.
Thanks Jacob, this works much better than what I had before :-)
Still, any ideas how to jump between beginning of line and beginning of text ? (aka. smart-home in the pc world)
On Apr 7, 2007, at 5:11 PM, Simon Strandgaard wrote:
Thanks Jacob, this works much better than what I had before :-)
Still, any ideas how to jump between beginning of line and beginning of text ? (aka. smart-home in the pc world)
This is an interesting problem... does anyone know how to set up a macro to make a decision based on a condition?
Or maybe how to achieve this as a command rather than a macro?
So far what I've thought up: Do the macro as before, and then cmd- shift-left. From there pressing left will home to the beginning of the line, pressing right will home to the beginning of the text. Also on the first step instead of moving to the beginning of the line, again cmd-shift-left, and copy to clipboard. This will give you something to compare to for the last step, if they're the same, then press right. If they're different, press left... I don't see how this can happen in a macro though.
For a command is it possible to find the current column location of the cursor? also is it possible to move the cursor around without affecting any of the text? (or at least perceivably not affecting any of the text)...
Just had another idea for a macro... Not 100% sure this can work, but... can you have a 'search for text in clipboard' or something equivalent? then we can search for [^ \t]|^*pasted text* where *pasted text* is the current word (or cmd-opt-shift-left)... That way it will jump to the first non-space character (beginning of text), unless the only thing to the left of the cursor are non-space characters, in which case it will jump to the beginning of the line (based on the greedy nature of regexps)?
On Sat, 7 Apr 2007, Simon Strandgaard wrote:
Still, any ideas how to jump between beginning of line and beginning of text ? (aka. smart-home in the pc world)
Here's a command that will do the trick. If the cursor is at the beginning of the line it gets moved to the first non-whitespace character. Otherwise it gets moved to the beginning of the line.
Input: Selected Text or Line Output: Insert as Snippet
----- Cut Here ----- #! /usr/bin/perl
$line = $ENV{'TM_CURRENT_LINE'}; $column = $ENV{'TM_COLUMN_NUMBER'}; $whitespace = '';
if ($column == 1) { # Chop leading whitespace from the line and # place it into its own variable. $line =~ s/^([ \t]*)//; $whitespace = $1; }
# Escape anything in the line that might be mistaken # as a snippet token. $line =~ s/([$\`])/\\1/g;
# Print the line as a snippet. The cursor will be # placed at the ${1} token. printf '%s${1}%s', $whitespace, $line;
----- Cut Here -----
On 4/9/07, Steve King steve@narbat.com wrote:
On Sat, 7 Apr 2007, Simon Strandgaard wrote:
Still, any ideas how to jump between beginning of line and beginning of text ? (aka. smart-home in the pc world)
Here's a command that will do the trick. If the cursor is at the beginning of the line it gets moved to the first non-whitespace character. Otherwise it gets moved to the beginning of the line.
[snip]
Ah, nice.
I have modified it slightly so that it first jump's to the the text-beginning and afterwards to the line-beginning.
#! /usr/bin/ruby line = ENV['TM_CURRENT_LINE'] index = ENV['TM_LINE_INDEX'].to_i
# extract leading whitespace remain = line.sub(/(^[ \t]*)/, '') whitespace = $1
if index == whitespace.size whitespace = '' else line = remain end
# place cursor print "#{whitespace}${1}#{line}"
On Apr 9, 2007, at 10:35 PM, Simon Strandgaard wrote:
[snip]
Ah, nice.
I have modified it slightly so that it first jump's to the the text-beginning and afterwards to the line-beginning.
#! /usr/bin/ruby line = ENV['TM_CURRENT_LINE'] index = ENV['TM_LINE_INDEX'].to_i
# extract leading whitespace remain = line.sub(/(^[ \t]*)/, '') whitespace = $1
if index == whitespace.size whitespace = '' else line = remain end
# place cursor print "#{whitespace}${1}#{line}"
Excellent... one issue though, it seems that it trims some of the line with it on certain cases. I use smarty templates in some of my work, and some lines have text like:
{$var|modifier}
after using the command, $var disappears (everything before the pipe, not including the left curly brace)
On 4/10/07, Constantinos Neophytou ♎ jaguarcy@gmail.com wrote:
Excellent... one issue though, it seems that it trims some of the line with it on certain cases. I use smarty templates in some of my work, and some lines have text like:
{$var|modifier}
after using the command, $var disappears (everything before the pipe, not including the left curly brace)
When Simon translated Steve's Perl code into Ruby, he missed out a crucial line:
# Escape anything in the line that might be mistaken # as a snippet token. $line =~ s/([$\`])/\\1/g;
In Ruby, I think that would be:
line.gsub!(/([$\`])/){"\#$1"};
Robin
On 4/10/07, Robin Houston robin.houston@gmail.com wrote:
On 4/10/07, Constantinos Neophytou ♎ jaguarcy@gmail.com wrote:
Excellent... one issue though, it seems that it trims some of the line with it on certain cases. I use smarty templates in some of my work, and some lines have text like:
{$var|modifier}
after using the command, $var disappears (everything before the pipe, not including the left curly brace)
When Simon translated Steve's Perl code into Ruby, he missed out a crucial line:
# Escape anything in the line that might be mistaken # as a snippet token. $line =~ s/([$\`])/\\1/g; In Ruby, I think that would be:
line.gsub!(/([$\`])/){"\#$1"};
Yes indeed. Thanks
problem: when text is selected and invoking this smart-home-command, then the selected text is erased.
Any ideas how to avoid this?
On 4/10/07, Simon Strandgaard neoneye@gmail.com wrote:
problem: when text is selected and invoking this smart-home-command, then the selected text is erased.
Any ideas how to avoid this?
You could record a macro that selects the current line (apple-L) then invokes the command.
Robin
On 4/10/07, Robin Houston robin.houston@gmail.com wrote:
You could record a macro that selects the current line (apple-L) then invokes the command.
Apple-SHIFT-L, sorry!
Also, the line of Ruby code I posted needs to be changed to
line = line.gsub(/([$\`])/){"\#$1"}
otherwise it gives an error when a) the cursor is already at the end of the initial whitespace on the line, and b) the line contains a special character ($, , or `).
Robin
On Tue, 10 Apr 2007, Robin Houston wrote:
You could record a macro that selects the current line (apple-L) then invokes the command.
I think you mean shift-apple-L; just apple-L brings up a "Go To Line" prompt. (Unless I've completely fubar'd my key map, which might be the case. :-)
But that doesn't do it. If you already have a selection which spans multiple lines, the "Select Line" action expands the selection to include the entirety of all those lines. It doesn't just select the current line. Net result: several lines are deleted and replaced with a single line. Whoops!
On Tue, 10 Apr 2007, Simon Strandgaard wrote:
problem: when text is selected and invoking this smart-home-command, then the selected text is erased.
Any ideas how to avoid this?
Use a macro to deselect the text then execute the command. I have a "Select Nothing" macro that is:
moveRightAndModifySelection: moveLeft:
(Record it by typing "shift-Right" then "Left".) This places the cursor at the beginning of the selection then clears the selection. Just record a macro with those strokes and the "Smart Home" command, save the macro, and bind it to the Home key.
(As an aside... I'm surprised I can't find a "clearSelection:" action. Anyone know of one that's better than this hack?)
It would, of course, be better to just move the cursor without modifying the selection. Unfortunately, the way commands are implemented there's no way to simply move the cursor without inserting text as a snippet. Any selection is going to be replaced by that insertion.
Which brings us to another problem with this command. Since it's actually doing an insert operation the buffer gets marked as modified, even if no other changes have been made. I'd love to have a way to simply move the cursor without the insert operation. Here's to a richer API in 2.0!