copy/paste line numbers with code

M

Max Williams

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
 
H

Hu Yoi

Max said:
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
 
M

Max Williams

Hu said:
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! :)
 
B

Bob Showalter

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.
 
J

John Joyce

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.
 
J

James Edward Gray II

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
 
M

Max Williams

James said:
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.
 
R

Ronald Fischer

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? =20

Not directly, but here are a few ideas:

- jEdit (http://www.jedit.org/) is a programmable editor (programmable
in=20
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=20
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=20
the line numbers with Control-Z afterwards. You can download it from
http://notepad-plus.sourceforge.net/de/site.htm

- 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
--=20
Ronald Fischer <[email protected]>
Phone: +49-89-452133-162
 
M

Max Williams

Ronald said:
- 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/de/site.htm

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

Ronald Fischer

Thanks Ronald, i'll look at Notepad++.=20

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 ;-)

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=20
this isn't a=20
standard feature of editors though!

Probably it is not used so often ;-)

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=20
that already?

Ronald
--=20
Ronald Fischer <[email protected]>
Phone: +49-89-452133-162
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top