Re: Move a Text Line to the Start

2009-05-22 Thread Dennis

On May 22, 2009, at 9:52 AM, James wrote:

> I always wanted to be able to move the selected line or lines up by
> one line, or down by one line. (TextMate has this function.)

Marc Liyanage has a script that does exactly what you're looking for:

http://www.entropy.ch/blog/Developer/2008/04/13/AppleScripts-for-Some-Missing-BBEdit-Text-Operations.html

-Dennis

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "BBEdit Talk" group.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a specific feature request or would like to report a suspected (or 
confirmed) problem with the software, please email to "supp...@barebones.com" 
rather than posting to the group.
-~--~~~~--~~--~--~---



Re: Move a Text Line to the Start

2009-05-22 Thread James

I always wanted to be able to move the selected line or lines up by
one line, or down by one line. (TextMate has this function.)

Could this code be modified to do that?

Or should I think of another solution?

Thanks
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "BBEdit Talk" group.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a specific feature request or would like to report a suspected (or 
confirmed) problem with the software, please email to "supp...@barebones.com" 
rather than posting to the group.
-~--~~~~--~~--~--~---



Re: Move a Text Line to the Start

2009-05-19 Thread Ronald J Kimball

On Tue, May 19, 2009 at 08:53:18AM -0700, davecortesi wrote:
> 
> To keep flogging this dead regex, I *think* the only problem with
> Peter's failed solution,
> 
> > I woiuld have expected to be able to do:
> > ((?s:.*?)\r)(.*.*\r)
> 
> (aside from a colon I think is a typo) is that the target line, group
> \2, is not a good place for unconstrained ".*".

The colon is not a typo.  (?:) turns the flag on only for
that subpattern.  Similarly, (?-:) turns the flag off
only for that subpattern.  That's why the unconstrained .* in the
subpattern is appropriate.

The problem Peter reported was that the (?s) was affecting the whole
pattern, rather than just the subpattern.

In Perl (with \r changed to \n), this regex works just fine.

Ronald

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "BBEdit Talk" group.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a specific feature request or would like to report a suspected (or 
confirmed) problem with the software, please email to "supp...@barebones.com" 
rather than posting to the group.
-~--~~~~--~~--~--~---



Re: Move a Text Line to the Start

2009-05-19 Thread davecortesi

To keep flogging this dead regex, I *think* the only problem with
Peter's failed solution,

> I woiuld have expected to be able to do:
> ((?s:.*?)\r)(.*.*\r)

(aside from a colon I think is a typo) is that the target line, group
\2, is not a good place for unconstrained ".*". This seems to work,

(?s)(.*?\r)(.*?.*?\r)

but since the original problem specifically said the target was a
line, how about

(?s)(.*?\r)([^\r]*[^\r]*\r)

(?s) sets the option and doesn't count as a replacement group
(.*?\r) the minimum number of complete lines preceding...
([^\r]*[^\r]*\r) exactly one line including the pattern
somewhere

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "BBEdit Talk" group.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a specific feature request or would like to report a suspected (or 
confirmed) problem with the software, please email to "supp...@barebones.com" 
rather than posting to the group.
-~--~~~~--~~--~--~---



Re: Move a Text Line to the Start

2009-05-19 Thread Ronald J Kimball

On Tue, May 19, 2009 at 10:22:23AM +0800, Peter N Lewis wrote:
> 
> So either set $LIST_SEPARATOR to undef or "", or alternatively use  
> join("",@array).

Or, best of all, just print the array directly:

print @array;

Ronald

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "BBEdit Talk" group.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a specific feature request or would like to report a suspected (or 
confirmed) problem with the software, please email to "supp...@barebones.com" 
rather than posting to the group.
-~--~~~~--~~--~--~---



Re: Move a Text Line to the Start

2009-05-19 Thread Roland Küffner


Am 18.05.2009 um 03:59 schrieb Peter N Lewis:
>> If, for example, the target line is:
>>  .*
>> how do I make it the middle part of the found text?

A quick test of this pattern worked for me:
(?s)(\A.*?\r)(\s*.*?\r)(.*\Z)

replace with \2\1\3

This would even move the  tag to the top if it spanned over  
more than one line.

Roland

>
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "BBEdit Talk" group.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a specific feature request or would like to report a suspected (or 
confirmed) problem with the software, please email to "supp...@barebones.com" 
rather than posting to the group.
-~--~~~~--~~--~--~---



Re: Move a Text Line to the Start

2009-05-18 Thread Peter N Lewis

On 18/05/2009, at 17:56 , John Delacour wrote:
> It's probably better to push the other lines on to an array, but that
> gave me leading spaces (Tell me why someone), so I took the
> concatenation route.

man perlvar:
$OUTPUT_FIELD_SEPARATOR == $OFS == $,
The output field separator for the print operator. If defined, this  
value is printed between each of print's arguments. Default is  
"undef". (Mnemonic: what is printed when there is a "," in your print  
statement.)

$LIST_SEPARATOR == $"
This is like $, except that it applies to array and slice val- ues  
interpolated into a double-quoted string (or similar inter- preted  
string). Default is a space.  (Mnemonic: obvious, I think.)

So either set $LIST_SEPARATOR to undef or "", or alternatively use  
join("",@array).

That said, your solution is fine as it is, there is no real advantage  
of pushing them on to an array, certainly not unless the file is huge  
in which case other techniques might be needed anyway.

Enjoy,
Peter.

-- 
  Run macros from your iPhone with Keyboard Maestro Control!
  or take a break with Derzle for your iPhone

Keyboard Maestro  Macros for your Mac
Aragom Space War  Don't get  
killed!
Derzle  Enjoy a relaxing puzzle.
   





--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "BBEdit Talk" group.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a specific feature request or would like to report a suspected (or 
confirmed) problem with the software, please email to "supp...@barebones.com" 
rather than posting to the group.
-~--~~~~--~~--~--~---



Re: Move a Text Line to the Start

2009-05-18 Thread John Delacour

At 12:28 -0700 17/5/09, Warren Michelsen wrote:

>Given a text document containing a number of lines separated by line 
>breaks, I need to find a particular line and move it to the start of 
>the document.
>
>Seems like a strategy would be to find the entire document in three parts:
>the lines before the target line
>the target line
>the lines following the target line.
>
>Then just replace with \2\1\3
>
>If, for example, the target line is:
>   .*
>how do I make it the middle part of the found text?


Rather than taxing my shrinking brain with complicated RegEx patterns 
I tend to use Unix filters for this sort of thing.  For example:


#!/usr/bin/perl
my $pattern = ".*";
my ($line1, $otherlines);
while (<>) {
   m~$pattern~ and $line1 .= $_
   or $otherlines .= $_
}
print "$line1$otherlines";



It's probably better to push the other lines on to an array, but that 
gave me leading spaces (Tell me why someone), so I took the 
concatenation route.

JD

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "BBEdit Talk" group.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a specific feature request or would like to report a suspected (or 
confirmed) problem with the software, please email to "supp...@barebones.com" 
rather than posting to the group.
-~--~~~~--~~--~--~---



Re: Move a Text Line to the Start

2009-05-17 Thread Peter N Lewis

On 18/05/2009, at 3:28 , Warren Michelsen wrote:
> Given a text document containing a number of lines separated by line  
> breaks, I need to find a particular line and move it to the start of  
> the document.
>
> Seems like a strategy would be to find the entire document in three  
> parts:
> the lines before the target line
> the target line
> the lines following the target line.
>
> Then just replace with \2\1\3
>
> If, for example, the target line is:
>   .*
> how do I make it the middle part of the found text?

Search for: (?s)(.*?\r)(?-s)(.*.*\r)
Replace with: \2\1

Breaking the search pattern down:

(?s) - turn on flag so . matches \r
(.*?\r) - any sequence of characters (including \r) terminated by \r
(?-s) - turn off flag so . no longer matches \r
(.*.*\r) - single line containing  ending in \r

I woiuld have expected to be able to do:

((?s:.*?)\r)(.*.*\r)

But that does not work, the ?s flag appears to affect the entire  
statement, which is not what the documentation says.

"The scope of options set in this manner is limited to the subpattern  
contained therein."

But in my testing the latter search string found the whole document,  
so either I'm confused or there is a bug in there somewhere.

Enjoy,
Peter.


-- 
  Run macros from your iPhone with Keyboard Maestro Control!
  or take a break with Derzle for your iPhone

Keyboard Maestro  Macros for your Mac
Aragom Space War  Don't get  
killed!
Derzle  Enjoy a relaxing puzzle.
   





--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "BBEdit Talk" group.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a specific feature request or would like to report a suspected (or 
confirmed) problem with the software, please email to "supp...@barebones.com" 
rather than posting to the group.
-~--~~~~--~~--~--~---



Move a Text Line to the Start

2009-05-17 Thread Warren Michelsen

Given a text document containing a number of lines separated by line breaks, I 
need to find a particular line and move it to the start of the document.

Seems like a strategy would be to find the entire document in three parts: 
the lines before the target line
the target line
the lines following the target line. 

Then just replace with \2\1\3

If, for example, the target line is: 
.*
how do I make it the middle part of the found text?




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "BBEdit Talk" group.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a specific feature request or would like to report a suspected (or 
confirmed) problem with the software, please email to "supp...@barebones.com" 
rather than posting to the group.
-~--~~~~--~~--~--~---