diff --git a/application.py b/application.py index 43bf940..04b7c25 100755 --- a/application.py +++ b/application.py @@ -526,8 +526,11 @@ class Application(object): def run_external(self, *args): curses.reset_shell_mode() - pipe = Popen(args) - pipe.wait() + try: + pipe = Popen(args) + pipe.wait() + except OSError, e: + self.set_error("%s: %s" % (args[0], e)) curses.reset_prog_mode() self.win.redrawwin() self.draw() diff --git a/mode/html.py b/mode/html.py index c35a62a..3ed52be 100644 --- a/mode/html.py +++ b/mode/html.py @@ -1,3 +1,4 @@ +import os import color, method, mode from lex import Grammar, PatternRule, RegionRule from mode.xml import TagGrammar @@ -21,12 +22,16 @@ class HTML(mode.Fundamental): extensions = ['.html', '.htm', '.shtml', '.shtm', '.xhtml'] grammar = HTMLGrammar colors = {} + config = { + 'html.viewcmd': 'jfirefox', + } def __init__(self, w): mode.Fundamental.__init__(self, w) self.add_bindings('close-paren', (')',)) self.add_bindings('close-brace', ('}',)) self.add_bindings('close-bracket', (']',)) + self.add_action(HtmlViewPage()) self.add_action(HtmlCheckSpelling()) _colorbase = { @@ -44,6 +49,24 @@ for _name in _colorbase: HTML.colors['style.%s' % _name] = _colorbase[_name] HTML.colors['tag.%s' % _name] = _colorbase[_name] + +class HtmlViewPage(method.Method): + '''Insert a pair of LaTeX-style single-quotes into the buffer''' + def _execute(self, w, **vargs): + viewcmd = w.application.config.get('html.viewcmd') + viewbg = viewcmd.endswith('&') + if viewbg: + viewcmd = viewcmd[:-1] + argv = (viewcmd, w.buffer.path) + if viewbg: + if os.fork() == 0: + try: + os.execvp(viewcmd, argv) + except OSError: + os._exit(1) + else: + w.application.run_external(*argv) + class HtmlCheckSpelling(method.Method): """Check the spelling of the document via ispell -t""" def _execute(self, w, **vargs): diff --git a/mode/latex.py b/mode/latex.py index 1bfe4b7..2f64f2b 100644 --- a/mode/latex.py +++ b/mode/latex.py @@ -28,6 +28,12 @@ class Latex(mode.Fundamental): 'latex_string.end': ('green', 'default', 'bold'), 'latex_escaped': ('magenta', 'default', 'bold'), } + config = { + 'latex.buildcmd': 'latex', + 'latex.pdfbuildcmd': 'pdflatex', + 'latex.pdfviewcmd': 'evince', + } + def __init__(self, w): mode.Fundamental.__init__(self, w) self.add_bindings('wrap-paragraph', ('M-q',)) @@ -44,12 +50,14 @@ class Latex(mode.Fundamental): class LatexBuild(method.Method): '''Insert a pair of LaTeX-style single-quotes into the buffer''' - buildcmd = 'latex' + def _getcmd(self, w): + return w.application.config.get('latex.buildcmd') def _build(self, w): if w.buffer.changed(): return (True, 'Build Cancelled: unsaved buffer') app = w.application - cmd = "%s '\\batchmode\\input %s' >/dev/null 2>&1" % (self.buildcmd, + buildcmd = self._getcmd(w) + cmd = "%s '\\batchmode\\input %s' >/dev/null 2>&1" % (buildcmd, w.buffer.path) status = os.system(cmd) if status == 0: @@ -75,17 +83,18 @@ class LatexBuild(method.Method): class LatexBuildPdf(LatexBuild): '''Insert a pair of LaTeX-style single-quotes into the buffer''' - buildcmd = 'pdflatex' + def _getcmd(self, w): + return w.application.config.get('latex.pdfbuildcmd') class LatexViewPdf(LatexBuildPdf): '''Insert a pair of LaTeX-style single-quotes into the buffer''' - viewcmd = 'evince' def _execute(self, w, **vargs): ok = LatexBuildPdf._execute(self, w, **vargs) if ok: + viewcmd = w.application.config.get('latex.pdfviewcmd') pid = os.fork() if pid == 0: pdfpath = self._modpath(w, '.pdf') - os.execvp(self.viewcmd, (self.viewcmd, pdfpath)) + os.execvp(viewcmd, (viewcmd, pdfpath)) class LatexCommentRegion(method.CommentRegion): commentc = '%'