Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Old Question: How to Print From XCode With Line Numbers

When I searched this forum, I didn't see any postings for this after 2008 and I haven't found anything useful on Google, either.


I want to print from XCode and have it show line numbers for the code I print out. I know I can cut and paste my code into another text editor, but then it doesn't highlight the same as XCode and that confuses me (I'm very visual and also have a slight learning disability that shows up when reading sometimes).


I've seen this question asked a number of times and haven't seen an answer and didn't see it posted or showing up after about 2008. I'm using XCode 3.2.6 and would be glad to upgrade if I knew this one feature were included. I hope that the reason I don't see this question in any recent posts or pages is because Apple finally added this feature. (I know it's been requested a lot, I've seen comments about that on some boards.)


I know you can use Enscript, but from what I understand, that will print in black and white, so I won't have any highlighting, much less the XCode syntax highlighting.


Do newer versions have this fixed or is there some way to do it now?

iMac, Mac OS X (10.5.6)

Posted on May 26, 2011 9:49 PM

Reply
Question marked as Best reply

Posted on May 26, 2011 9:58 PM

Nothing new.


Screenshot as-is or open/paste into an editor that supports printing w/line numbers, such as TextWrangler, etc.

13 replies

May 26, 2011 10:54 PM in response to K T

I just tried -- I got an error page telling me to file a bug report!


I meant I had read comments by the developers of XCode from years ago with them making comments that made it clear they knew that it was a much desired feature.


I'll file a report. Right now I'm on XCode 3. I'll probably be upgrading soon. I'm coding in Perl without an extensive IDE and just switched over to XCode from some Linux programs I had been using with MacPorts.

May 27, 2011 7:27 AM in response to HalNineThousand

HalNineThousand wrote:


I know you can use Enscript, but from what I understand, that will print in black and white, so I won't have any highlighting, much less the XCode syntax highlighting.

Enscript can print in color. I use the following:

alias en='enscript --pretty-print --fancy-header --line-numbers --landscape --color --columns=2'

It works great for Perl too. Here is an example:

User uploaded file

You can adjust the colors in the enscript config files if you want.


Right now I'm on XCode 3. I'll probably be upgrading soon. I'm coding in Perl without an extensive IDE and just switched over to XCode from some Linux programs I had been using with MacPorts.


I suggest sticking with Xcode 3. Xcode4 is heavily optimized for iOS and MacOSX. You can do other kinds of Makefile-based projects in Xcode4, but not as well as Xcode3. Plus, you will probably lose your syntax highlighting in anything except C, C++, and Javascript.


What I did was install Xcode3 into /Xcode3 and keep the mainline Xcode in /Developer. That way, I will always have Xcode3 and I won't have to worry about some future update to Xcode4 blowing away Xcode3 because I forgot to specify the Xcode4 install directory.

May 27, 2011 9:19 AM in response to etresoft

I wish you had responded before I marked this ans answered, since that is a good answer about how to do it.


Is there a way, with Enscript, to specify the colors so they match what I use in XCode? Switching between one style and another confuses me.


Thanks for the heads up on versions 3 and 4. The project I'm working on now is almost all Perl (but will include Python later) for a Linux system. While I don't have to build anything, I'd hate to lose syntax highlighting. (Why on Earth would they REMOVE features like highlighting for other languages? Or is it just a matter of copying over the proper definition files?)


If XCode is moving in that direciton, I may have to find another editor to use. What amazes me is that after trying 10-12 editors over the past week, and just looking at what I would think are standard features (line numbering in the editor and for printing, syntax highlighting for the same, code folding, being able to control font or printout size, and how it handles finding or showing start and end braces/brackets/parenthesis), I'm amazed that even text editors that cost as much as $100 lack a number of these basic features.


I have a solution that works for now. I wrote a user script in Perl that reads through the file and adds line numbers with spaces at the start of each line. Then I can print it. After printing, I can either use UNDO to remove the line numbers or use the same script to remove them.


After I get comments and stuff in there, I'll post it on my blog site with my other projects and put a linke here, in a spearate topic about printing with line numbers.

May 27, 2011 10:13 AM in response to HalNineThousand

HalNineThousand wrote:


I wish you had responded before I marked this ans answered, since that is a good answer about how to do it.


Is there a way, with Enscript, to specify the colors so they match what I use in XCode? Switching between one style and another confuses me.

To change the colors, I think you need to use sudo to hack up the file "/usr/share/enscript/hl/style_emacs.st". I couldn't figure out a way to make enscript use a similar file in a user directory and quickly lost interest.


Thanks for the heads up on versions 3 and 4. The project I'm working on now is almost all Perl (but will include Python later) for a Linux system.


Have you tried MacFUSE with sshfs to mount a Linux path on the Mac? Xcode has lots of file system overhead, so it works best from a local drive, but sshfs can be very handy for other things. I use sshfs with nedit (locally) when I need a fast, decent editor outside of my Xcode projects.


While I don't have to build anything, I'd hate to lose syntax highlighting. (Why on Earth would they REMOVE features like highlighting for other languages?


Probably for the same good reason that they removed CVS support in Xcode4. If you find out what good reason that was, be sure to let us know.


However, I think I was wrong about the syntax highlighting. I have heard many complaints form people that FORTRAN syntax highlighting doesn't work. Then I opened a Perl script in Xcode 4 to check and it didn't have any highlighting. I normally use Xcode3 for this. Then when I went to poke around for syntaxt highlighting files, I actually opened my Xcode3 project in Xcode4. This time, my Perl code has the proper highlighting. So, if you wrap your Perl projects in an empty project or Makefile-based project, you will get syntax highlighting. If you just open the file outside of a project, no syntax highlighting.


Still, no line numbers nor any colors in printing though. Apple also removed the scripts menu in Xcode4 🙂If you stay with Xcode3, you can add script menu items to print via enscript. I haven't printed in ages, but that is what I did at one time.

May 27, 2011 9:03 PM in response to etresoft

If Apple is removing the user scripts from XCode 4 and is changing things so I either don't have syntax highlighting for Perl or have to have it in a project or something similar, than that tells me that OS X is going the same way IOS is going: Restrict everything and make everyone do it in our languages and our way.


As much as I love working on an iMac, that's getting too restrictive for an IDE. I use Eclipse for Java, but it feels klunky and really wanted to use something else for Perl (and later Python) and sometimes C++.


I don't need a lot for an IDE. I ran my business for almost a decade using just a text editor that had the editor on top, a file list on the side, and a console in the bottom part of the window. A text editor with the features I need is what's important.


If XCode is removing more and more features, including powerful features, then when I have a break between this section and the next on this project, I'm going to be evaluating IDEs and text editors for something that won't cut me off at the knees.


Sorry to sound harsh. I'm thankful for the help from people here, but I'm frustrated that Apple is acting like Big Brother and removing words in the language of developers, like BB did with Newspeak.

May 28, 2011 6:14 AM in response to HalNineThousand

That is a bit harsh. As I said above, syntax highlighting does work with Perl and many other languages in Xcode4. I don't know about FORTRAN, nor will I ever.


For developing iOS and MacOSX software, Xcode4 is far superior to Xcode3. For other types of projects, I find makefile-based projects in Xcode3 to be superior.


Apple doesn't try to be all things to all people. They do things their way and periodically they "trim the fat" so to speak. To be honest, I never really used the script menu and haven't printed any source code in at least 5 years.


I suggest avoiding the "Apple is restricting me" mantra. That's bogus. Apple does things their way, that's true. If you don't want to do it their way don't use their products. They are a big company. You won't hurt their feelings. But before you "vote with your feet" and "stand up for your principles", give yourself an honest evaluation of Apple's products compared to those of their competitors. Even with their "restrictions", Apple's products make their competitors look like amateurs. You can find "freer" products, but not better ones.

May 29, 2011 1:14 PM in response to etresoft

I'm self-taught and never even used anything that most would qualify as an IDE until I had been programming for a number of years and my business was well past the startup phase. Most of what I do is with scripting languages, althought I will, in the future, be using more C++, and I do sometimes use Java. I don't need a heavy duty IDE.


But on the part about restrictions, yes, Apple does things their way. That's okay. But their way is not my way and it's unlikely I'll ever be at a point where I'm developing for just OS X. After I finish my current project, I'll be working more on video editing and programming will be just a hobby for me when I have time or need a project for a particular purpose.


In the past I've looked over open source programs, commercial programs, programs that came with a particular OS and others along those lines.


In this case, I'm more concerned about a text editor that has the features I need than many of the other features IDEs provide. (And, in the past, when I had to deal with building something, I did my own scripts and found I worked just as well running al that from the command line as I did from within an IDE.)


So it's not a love or hate feeling, but, as you pointed out, Apple doesn't try to be all things to all people, and if they're trimming features and focusing more on their model of development, and it's diverging from my needs, then that's fine. They'll do well. I'm just looking for the best environment that fits my needs.

Feb 27, 2013 9:30 AM in response to HalNineThousand

In XCode 4.6, all I had to do was rename the "Printing" theme in the list of Fonts and Colors themes to something else ("Printing_OLD", in case you are wondering) and then take my normal theme, duplicate it, and rename the duplicate to "Printing". It works, I'm printing in color from XCode.


It's apparently more of an undocumented feature than a missing feature.


Update: Sorry, I was trying to print in color rather than print with line numbers, which you can't do from the process described above.

Old Question: How to Print From XCode With Line Numbers

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.