[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

copy/paste line numbers with code

Max Williams

9/12/2007 2:02:00 PM

I'm writing up my project report and want to include line numbers with
the code that i paste into my word doc writeup. Does anyone know of a
ruby editor for windows that will allow this? I use SciTE and Eclipse
already but can't see how to do it using those, so if someone knows a
way for those that would be ideal.

thanks
max
--
Posted via http://www.ruby-....

11 Answers

Hu Yoi

9/12/2007 2:52:00 PM

0

Max Williams wrote:
> I'm writing up my project report and want to include line numbers with
> the code that i paste into my word doc writeup. Does anyone know of a
> ruby editor for windows that will allow this? I use SciTE and Eclipse
> already but can't see how to do it using those, so if someone knows a
> way for those that would be ideal.
>
> thanks
> max

I have used a bit of Ruby code to do this:

code = File.open("Song.rb")
code.each {
|line| puts "#{code.lineno}. #{line}"
}
code.close

present your .rb file to replace "Song.rb" and copy code with line
number from your Console or SciTE
--
Posted via http://www.ruby-....

Max Williams

9/12/2007 2:55:00 PM

0

Hu Yoi wrote:
> Max Williams wrote:
>> I'm writing up my project report and want to include line numbers with
>> the code that i paste into my word doc writeup. Does anyone know of a
>> ruby editor for windows that will allow this? I use SciTE and Eclipse
>> already but can't see how to do it using those, so if someone knows a
>> way for those that would be ideal.
>>
>> thanks
>> max
>
> I have used a bit of Ruby code to do this:
>
> code = File.open("Song.rb")
> code.each {
> |line| puts "#{code.lineno}. #{line}"
> }
> code.close
>
> present your .rb file to replace "Song.rb" and copy code with line
> number from your Console or SciTE

thanks...i thought about doing something like this but it's a last
desperate option - if i make any changes i need to run this again on the
file for example. There must be a text editor out there that does this?
(and knows how to colour ruby) Anyone know?

don't meant to sound ungrateful though, thanks! :)
--
Posted via http://www.ruby-....

James Gray

9/12/2007 3:07:00 PM

0

On Sep 12, 2007, at 9:54 AM, Max Williams wrote:

> There must be a text editor out there that does this?
> (and knows how to colour ruby) Anyone know?

TextMate can:

http://macro...

James Edward Gray II

Bob Showalter

9/12/2007 3:08:00 PM

0

On 9/12/07, Max Williams <toastkid.williams@gmail.com> wrote:
> I'm writing up my project report and want to include line numbers with
> the code that i paste into my word doc writeup. Does anyone know of a
> ruby editor for windows that will allow this? I use SciTE and Eclipse
> already but can't see how to do it using those, so if someone knows a
> way for those that would be ideal.

I don't know SciTE or Eclipse, but with vim it would be trivial to
write a macro to pipe the data through cat -n or nl (you can get these
for Win32), copy the data to the clipboard, and then remove the line
numbers.

Max Williams

9/12/2007 3:12:00 PM

0

James Gray wrote:
> On Sep 12, 2007, at 9:54 AM, Max Williams wrote:
>
>> There must be a text editor out there that does this?
>> (and knows how to colour ruby) Anyone know?
>
> TextMate can:
>
> http://macro...
>
> James Edward Gray II

i know :(

On Sep 12, 2007, at 9:01 AM, Max Williams wrote:
>Does anyone know of a ruby editor for windows that will allow this?
--
Posted via http://www.ruby-....

John Joyce

9/12/2007 3:56:00 PM

0

James! He's using Scite, I doubt he has access to TextMate
(unfortunately)
You might try E-Texteditor, a rough clone of Textmate for Windows.
It's rough though, I can't believe they charge for it in its current
state. It uses TM Bundles but doesn't come close in terms of grace,
beauty or ease of use.
Your next option would be to use some form of Emacs. Steep learning
curve but can make you very productive.

James Gray

9/12/2007 4:07:00 PM

0

On Sep 12, 2007, at 10:55 AM, John Joyce wrote:

> James! He's using Scite, I doubt he has access to TextMate
> (unfortunately)

I know. But when he asked if anyone knew of an editor... ;)

To be semi-helpful, this should be easy enough to setup in vi or
emacs. Both are available on Windows.

James Edward Gray II

Max Williams

9/12/2007 4:46:00 PM

0

James Gray wrote:
> On Sep 12, 2007, at 10:55 AM, John Joyce wrote:
>
>> James! He's using Scite, I doubt he has access to TextMate
>> (unfortunately)
>
> I know. But when he asked if anyone knew of an editor... ;)
>
> To be semi-helpful, this should be easy enough to setup in vi or
> emacs. Both are available on Windows.
>
> James Edward Gray II

Feels like a sledgehammer to crack a nut to be honest...I tried
e-texteditor, it doesn't look like it does it either. Must say i'm
surprised that there don't seem to be *any* windows editors that will do
this. oh well, thanks for the help guys.
--
Posted via http://www.ruby-....

Ronald Fischer

9/13/2007 9:42:00 AM

0

> I'm writing up my project report and want to include line numbers with
> the code that i paste into my word doc writeup. Does anyone know of a
> ruby editor for windows that will allow this?

Not directly, but here are a few ideas:

- jEdit (http://www....) is a programmable editor (programmable
in
BeanShell-Java and Python), and there are many extensions available. For
example
http://taat.pl/en/jed... lists a macro Lines_to_numbered.bsh
which
is supposed (I haven't tried it) to write line numbers in front of each
line. You call the macro, copy the buffer, and undo the changes.
Actually, if you don't mind diving into BeanShell programming, you could
write your own macro doing this.

- Notepad++ is similar in this respect. Here you can use the plugin
"TextFX Tools", which has a command "number lines", which puts line
numbers in front of the selected text, though in just one standard
format (with leading zeroes), and I don't know how easy it is to change
this. Again, you can copy the numbered file to the clipboard and remove
the line numbers with Control-Z afterwards. You can download it from
http://notepad-plus.sourceforge.net/d...

- You could put the line numbering process outside of the editor, either
by writing a trivial Ruby program which creates a file with numbers out
of a text file, or using some of the utilities which are already
available
(I use, for example, Cygwin, which has the nl command for numbering the
lines). Many editors allow running an external program on the buffer -
examples are (again) jEdit, but also the vi family and, AFIK, Scite too.

HTH

Ronald
--
Ronald Fischer <ronald.fischer@venyon.com>
Phone: +49-89-452133-162

Max Williams

9/13/2007 9:48:00 AM

0

Ronald Fischer wrote:

> - Notepad++ is similar in this respect. Here you can use the plugin
> "TextFX Tools", which has a command "number lines", which puts line
> numbers in front of the selected text, though in just one standard
> format (with leading zeroes), and I don't know how easy it is to change
> this. Again, you can copy the numbered file to the clipboard and remove
> the line numbers with Control-Z afterwards. You can download it from
> http://notepad-plus.sourceforge.net/d...
>
> - You could put the line numbering process outside of the editor, either
> by writing a trivial Ruby program which creates a file with numbers out
> of a text file, or using some of the utilities which are already
> available
> (I use, for example, Cygwin, which has the nl command for numbering the
> lines). Many editors allow running an external program on the buffer -
> examples are (again) jEdit, but also the vi family and, AFIK, Scite too.
>
> HTH
>
> Ronald

Thanks Ronald, i'll look at Notepad++. Currently, i'm doing the
following, which actually works quite well -

Set up a column in excel with '001', '002', etc.
Paste text from eclipse into the next column in excel.
Copy both columns back into a dummy file in eclipse (the apostrophes in
the numbers are necessary for eclipse to colour code correctly here)
Then paste the required chunks of code out of eclipse into word -
colouring all nicely preserved.

thanks for the advice everyone. i'm still surprised that this isn't a
standard feature of editors though!
--
Posted via http://www.ruby-....