Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable syntax highlighting in enscript based on the language of the a… #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions SublimePrint.py
Original file line number Diff line number Diff line change
@@ -83,6 +83,24 @@ def get_printer(self):

return used_printer


def get_lang(self):
'''
Return the syntax (language) of the active window.
'''
syntaxPackage = sublime.active_window().active_view().settings().get('syntax')
#print(syntaxPackage)
if syntaxPackage.count('/') == 3 and syntaxPackage.count('/Support/') == 1:
(pkg, lang, support, tmLang) = syntaxPackage.split('/')
else:
(pkg, lang, tmLang) = syntaxPackage.split('/')

#print(lang)
lang = lang.lower()

return lang


def printer_command(self, title=None, print_line_numbers=True):
'''
Return the array of command line options to pass to the subprocess.
@@ -97,6 +115,13 @@ def printer_command(self, title=None, print_line_numbers=True):
if not (print_line_numbers and settings.get("print_line_numbers")):
options.pop("line-numbers")

if options["highlight"] == True:
lang = self.get_lang()
options["highlight"] = lang
if lang == 'text':
options.pop("highlight")
# print(options)

options_list = ["--{0}={1}".format(k, v) for k, v in options.items() if v != ""]
options_list += ["--{0}".format(k) for k, v in options.items() if v == ""]