improvements to HTML mode... better external cmd handling, latex/html cmds use app.config now.
--HG-- branch : pmacs2
This commit is contained in:
parent
017f79e888
commit
015eb1fad1
|
@ -526,8 +526,11 @@ class Application(object):
|
|||
|
||||
def run_external(self, *args):
|
||||
curses.reset_shell_mode()
|
||||
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()
|
||||
|
|
23
mode/html.py
23
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):
|
||||
|
|
|
@ -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 = '%'
|
||||
|
|
Loading…
Reference in New Issue