improvements to HTML mode... better external cmd handling, latex/html cmds use app.config now.

--HG--
branch : pmacs2
This commit is contained in:
moculus 2008-04-16 14:44:24 +00:00
parent 017f79e888
commit 015eb1fad1
3 changed files with 42 additions and 7 deletions

View File

@ -526,8 +526,11 @@ class Application(object):
def run_external(self, *args): def run_external(self, *args):
curses.reset_shell_mode() curses.reset_shell_mode()
pipe = Popen(args) try:
pipe.wait() pipe = Popen(args)
pipe.wait()
except OSError, e:
self.set_error("%s: %s" % (args[0], e))
curses.reset_prog_mode() curses.reset_prog_mode()
self.win.redrawwin() self.win.redrawwin()
self.draw() self.draw()

View File

@ -1,3 +1,4 @@
import os
import color, method, mode import color, method, mode
from lex import Grammar, PatternRule, RegionRule from lex import Grammar, PatternRule, RegionRule
from mode.xml import TagGrammar from mode.xml import TagGrammar
@ -21,12 +22,16 @@ class HTML(mode.Fundamental):
extensions = ['.html', '.htm', '.shtml', '.shtm', '.xhtml'] extensions = ['.html', '.htm', '.shtml', '.shtm', '.xhtml']
grammar = HTMLGrammar grammar = HTMLGrammar
colors = {} colors = {}
config = {
'html.viewcmd': 'jfirefox',
}
def __init__(self, w): def __init__(self, w):
mode.Fundamental.__init__(self, w) mode.Fundamental.__init__(self, w)
self.add_bindings('close-paren', (')',)) self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',)) self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',)) self.add_bindings('close-bracket', (']',))
self.add_action(HtmlViewPage())
self.add_action(HtmlCheckSpelling()) self.add_action(HtmlCheckSpelling())
_colorbase = { _colorbase = {
@ -44,6 +49,24 @@ for _name in _colorbase:
HTML.colors['style.%s' % _name] = _colorbase[_name] HTML.colors['style.%s' % _name] = _colorbase[_name]
HTML.colors['tag.%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): class HtmlCheckSpelling(method.Method):
"""Check the spelling of the document via ispell -t""" """Check the spelling of the document via ispell -t"""
def _execute(self, w, **vargs): def _execute(self, w, **vargs):

View File

@ -28,6 +28,12 @@ class Latex(mode.Fundamental):
'latex_string.end': ('green', 'default', 'bold'), 'latex_string.end': ('green', 'default', 'bold'),
'latex_escaped': ('magenta', 'default', 'bold'), 'latex_escaped': ('magenta', 'default', 'bold'),
} }
config = {
'latex.buildcmd': 'latex',
'latex.pdfbuildcmd': 'pdflatex',
'latex.pdfviewcmd': 'evince',
}
def __init__(self, w): def __init__(self, w):
mode.Fundamental.__init__(self, w) mode.Fundamental.__init__(self, w)
self.add_bindings('wrap-paragraph', ('M-q',)) self.add_bindings('wrap-paragraph', ('M-q',))
@ -44,12 +50,14 @@ class Latex(mode.Fundamental):
class LatexBuild(method.Method): class LatexBuild(method.Method):
'''Insert a pair of LaTeX-style single-quotes into the buffer''' '''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): def _build(self, w):
if w.buffer.changed(): if w.buffer.changed():
return (True, 'Build Cancelled: unsaved buffer') return (True, 'Build Cancelled: unsaved buffer')
app = w.application 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) w.buffer.path)
status = os.system(cmd) status = os.system(cmd)
if status == 0: if status == 0:
@ -75,17 +83,18 @@ class LatexBuild(method.Method):
class LatexBuildPdf(LatexBuild): class LatexBuildPdf(LatexBuild):
'''Insert a pair of LaTeX-style single-quotes into the buffer''' '''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): class LatexViewPdf(LatexBuildPdf):
'''Insert a pair of LaTeX-style single-quotes into the buffer''' '''Insert a pair of LaTeX-style single-quotes into the buffer'''
viewcmd = 'evince'
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
ok = LatexBuildPdf._execute(self, w, **vargs) ok = LatexBuildPdf._execute(self, w, **vargs)
if ok: if ok:
viewcmd = w.application.config.get('latex.pdfviewcmd')
pid = os.fork() pid = os.fork()
if pid == 0: if pid == 0:
pdfpath = self._modpath(w, '.pdf') pdfpath = self._modpath(w, '.pdf')
os.execvp(self.viewcmd, (self.viewcmd, pdfpath)) os.execvp(viewcmd, (viewcmd, pdfpath))
class LatexCommentRegion(method.CommentRegion): class LatexCommentRegion(method.CommentRegion):
commentc = '%' commentc = '%'