updates to scala documentation viewer

--HG--
branch : pmacs2
This commit is contained in:
erik@cage.vpscustomer.com 2010-09-27 01:05:13 -04:00
parent 8f82922870
commit 30c093411d
2 changed files with 30 additions and 10 deletions

View File

@ -755,8 +755,11 @@ class Application(object):
# running external programs
def run_pipe(self, args, b, name='*Output*', switch=True, modename=None):
pipe = Popen(args=args, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
#pipe = Popen(args=args, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
data = b.make_string().encode('utf-8')
return self.run_pipe2(args, data, name, switch, modename)
def run_pipe2(self, args, data, name='*Output*', switch=True, modename=None):
pipe = Popen(args=args, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
try:
pipe.stdin.write(data)
pipe.stdin.close()
@ -770,7 +773,8 @@ class Application(object):
switch_to = switch(status)
else:
switch_to = bool(switch)
self.data_buffer(name, output, switch_to=switch_to, modename=modename)
self.data_buffer(name, output.decode('utf-8'), switch_to=switch_to,
modename=modename)
return status
def run_external(self, *args):
curses.reset_shell_mode()

View File

@ -107,24 +107,39 @@ class ScalaDocBrowse(Method):
class ScalaDocLookup(Method):
args = [arg('name', t='string', p='Name: ', dv=default.current_word,
ld=True, h='The Scala name to get help on')]
def _get_path(self, w, name):
return w.application.getpath('cache', 'scala', name)
def _get_url(self, w, name, url):
path = self._get_path(w, name)
w.application.mkdirs('cache', 'scala')
if not os.path.exists(path):
open(path, 'w').write(urllib2.urlopen(url).read())
html = open(path, 'r').read()
return html
def _execute(self, w, **vargs):
try:
import BeautifulSoup
from BeautifulSoup import BeautifulSoup
except ImportError:
w.set_error('BeautifulSoup is not installed...')
return
a = w.application
name = vargs.get('name')
path = a.getpath('cache', 'scala', 'api.html')
url = a.config['scala.api']
html = self._get_url(w, 'api.html', a.config['scala.api'])
soup = BeautifulSoup(html)
a.mkdirs('cache', 'scala')
tags = soup.findAll('li')
for li in tags:
if li['title'].endswith(name):
frag = li.contents[0]['href']
url2 = a.config['scala.api-base'] + '/' + frag
a.run_external('links', url2)
return
if not os.path.exists(path):
open(path, 'w').write(urllib2.urlopen(url).read())
w.set_error('looking up %s...' % name)
w.set_error('error looking up %s...' % name)
# white is for delimiters, operators, numbers
default = ('default', 'default')
@ -171,6 +186,7 @@ class Scala(Fundamental):
closetags = {')': '(', ']': '[', '}': '{'}
config = {
'scala.api': 'http://www.scala-lang.org/api/current/allclasses.html',
'scala.api-base': 'http://www.scala-lang.org/api/current',
}
colors = {