Copy/paste line numbers with code

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

Max W. 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

Hu Yoi wrote:

Max W. 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! :slight_smile:

On 9/12/07, Max W. [email protected] 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.

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

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

TextMate can:

http://macromates.com/

James Edward G. II

James G. wrote:

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

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

TextMate can:

http://macromates.com/

James Edward G. II

i know :frowning:

On Sep 12, 2007, at 9:01 AM, Max W. wrote:

Does anyone know of a ruby editor for windows that will allow this?

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.

On Sep 12, 2007, at 10:55 AM, John J. 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… :wink:

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

James Edward G. II

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.jedit.org/) is a programmable editor (programmable
    in
    BeanShell-Java and Python), and there are many extensions available. For
    example
    http://taat.pl/en/jedit/#macros 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
    Notepad++

  • 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

James G. wrote:

On Sep 12, 2007, at 10:55 AM, John J. 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… :wink:

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

James Edward G. 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.

Ronald F. 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
    Notepad++

  • 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!

Thanks Ronald, i’ll look at Notepad++.

Good idea. It’s really a good editor and it does syntax-colour
Ruby (just mention this so this thread won’t go completely OT :wink:

BTW, I gave you by mistake the URL of the German Notepad++ site.
The English one is, as you maybe already found out by yourself,
http://notepad-plus.sourceforge.net/uk/site.htm

thanks for the advice everyone. i’m still surprised that
this isn’t a
standard feature of editors though!

Probably it is not used so often :wink:

BTW, I’m not proficient in Word, but since it is also has kind
of a programming language built into (some sort of BASIC), maybe
someone already wrote a Macroprogramm for this - did you check
that already?

Ronald