It seems unhelpful to debate whether printing is a necessary feature, since the people who need it need it and the people who don't don't. But it does seem debatable whether the lack of a built-in printing capability is a good reason not to purchase Sublime Text. ExportHtml is described by many on this forum as an excellent plugin for exporting printable code to a browser while preserving syntax formatting. For those who primarily use Sublime Text for prose, I think the SublimePrint plugin is also very good.
It is worth remembering that plain text printing is an old problem with many solutions, at least in the unix world. Because Sublime Text is so easily extensible, it is not difficult to write a plugin that seamlessly transfers the job of printing, previewing and formatting to one of these tools. Examples of linux printing tools include enscript, gtklp, evince, okular, xpp.
Enscript - used in the SublimePrint plugin - transforms plain text to postscript with options for fonts, margins, headers, etc. Okular, evince, gtklp and xpp use a print dialog similar to that in a word processing program. You select a printer, choose duplex or single-sided, which pages to print, number of pages per sheet, etc. Evince and Okular also provide page preview before printing. Okular can convert your output to pdf and can then add annotations, color highlighting and underlining.
Here's an example of a simple experimental plugin - ExternalPrintPreview.py - that formats a text file with enscript and sends it to evince for previewing and printing. It may help those who need a print/preview capability in Sublime. (Let me know!) To run it, use a keybinding to trigger the "external_print_preview" command:
def run(self, view):
if not File_To_Print:
sublime.error_message("Oops!\n You need to save the file \n before you can print it.")
if not sublime.ok_cancel_dialog("Oops!\nUnsaved changes won't print. \nDo you want to cancel print?", "PrintAnyway"):
Tmp_File_Name = tempfile.NamedTemporaryFile(delete=False).name
p=subprocess.Popen(["enscript", File_To_Print, ("--output="+Tmp_File_Name),
"--header=$n|%W|$%", "--header-font=Times-Roman10", "--font=Times-Roman12",
"--margins=40:40:70:70", "--word-wrap"], shell=False)
sublime.error_message("Error running enscript")
# evince below could be replaced by okular, xpp, or gtklp
try: subprocess.Popen(["evince", Tmp_File_Name], shell=False)
except: sublime.error_message("Error launching print preview")
This plugin requires that enscript and evince are installed (in directories on your PATH) and it complains if you haven't saved your document. It stores a temporary file. In the example above, I've hard-coded my enscript preferences for margins, fonts, headers and word-wrap; you can substitute whatever values you prefer. ("man enscript" for options.) While the above example uses evince for print preview, you can easily substitute "okular" or one of the other programs. (Of course you need to install them first!)
If you want to start okular with a print dialog box - rather than in preview/viewer mode - the syntax is:
try: subprocess.Popen(["okular", "--print", Tmp_File_Name], shell=False)
If you don't want a print preview capability at all and just want a print dialog box, you can experiment with xpp or gtklp:
try: subprocess.Popen(["xpp", Tmp_File_Name], shell=False)
try: subprocess.Popen(["gtklp < "+ Tmp_File_Name], shell=True)
[See note below about shell=true]
Experiment with these options and you may find a choice that fits your needs and integrates seamlessly with Sublime.
Obviously these are linux-centric solutions. Enscript and evince are also available for Windows, but you should be aware that python's Popen() won't be able to launch these programs after you install them unless you explicitly specify their full paths. (So, instead of just using "evince" with Popen() as in the example above, you would need something like "c:\program files\a bunch of other stuff\users\etcetera\why is windows like this\evince.exe"). You can use the Windows "where" command to determine the full paths and names for these exe's after installing enscript and evince.
If printing and previewing plain text files is a more or less trivial problem - at least under linux!- it shouldn't be an obstacle to purchasing what is an otherwise excellent product.
[Note about shell=true: gtklp won't open a file specified on the command line unless the filename is piped to it, and that requires shell=true. This won't create a good feeling in those who care about security, but the shell is being used here only with a temporary filename supplied by tempfile, so it should be safe. It would not be safe however to use shell=true in the first use of Popen above, where enscript is sent the name of the user's text file. The problem is that you can create a file in Sublime with a name like "blah.txt |rm -f *". Dangerous filenames like these include injected commands the shell can be induced to execute.]