started adding documentation facilities to scala mode
--HG-- branch : pmacs2
This commit is contained in:
parent
3d8b0036d1
commit
8468559e7f
|
@ -4,6 +4,9 @@ from lex import Grammar, PatternRule, RegionRule, PatternMatchRule
|
|||
from mode.xml import XMLGrammar
|
||||
from mode.pipe import Pipe
|
||||
from method.shell import Interact
|
||||
from method import Method, arg
|
||||
import default
|
||||
import urllib2
|
||||
|
||||
chr1 = '[a-zA-Z_]'
|
||||
chr2 = '[a-zA-Z_0-9]'
|
||||
|
@ -28,6 +31,7 @@ class ScalaGrammar(Grammar):
|
|||
|
||||
PatternRule('delimiter', r'(?:;|{|}|\[|\]|\(|\)|,|\.|<(?![a-zA-Z_])|>|:|/|\+|-|\*|=)'),
|
||||
|
||||
RegionRule('scala.inline', r'(?:^| )(?=<[a-zA-Z_])', XMLGrammar, '^[ \t]*$'),
|
||||
PatternRule('spaces', r'(?:\t| )+'),
|
||||
PatternRule('eol', r'\n'),
|
||||
|
||||
|
@ -52,8 +56,6 @@ class ScalaGrammar(Grammar):
|
|||
PatternRule('scala.annotation', '@[a-zA-Z_][a-zA-Z0-9_]*'),
|
||||
PatternRule('scala.bareword', '[a-zA-Z_][a-zA-Z0-9_]*'),
|
||||
PatternRule('scala.null', 'null'),
|
||||
|
||||
RegionRule('scala.inline', r'(?:^| )(?=<[a-zA-Z_])', XMLGrammar, '^[ \t]*$'),
|
||||
]
|
||||
|
||||
class ScalaTabber(StackTabber2):
|
||||
|
@ -89,6 +91,34 @@ class ScalaStart(Interact):
|
|||
def _execute(self, w, **vargs):
|
||||
Interact._execute(self, w, bname='*Scala*', cmd='scala')
|
||||
|
||||
class ScalaDocBrowse(Method):
|
||||
def _execute(self, w, **vargs):
|
||||
a = w.application
|
||||
url = a.config['scala.api']
|
||||
Interact().execute(w, bname='*Scala-Doc*', cmd='links "%s"' % url)
|
||||
|
||||
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 _execute(self, w, **vargs):
|
||||
try:
|
||||
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']
|
||||
|
||||
a.mkdirs('cache', 'scala')
|
||||
|
||||
if not os.path.exists(path):
|
||||
open(path, 'w').write(urllib2.urlopen(url).read())
|
||||
|
||||
w.set_error('looking up %s...' % name)
|
||||
|
||||
class Scala(Fundamental):
|
||||
name = 'Scala'
|
||||
extensions = ['.scala']
|
||||
|
@ -96,11 +126,14 @@ class Scala(Fundamental):
|
|||
tabbercls = ScalaTabber
|
||||
grammar = ScalaGrammar
|
||||
commentc = '//'
|
||||
actions = [ScalaStart]
|
||||
actions = [ScalaStart, ScalaDocBrowse, ScalaDocLookup]
|
||||
opentokens = ('delimiter',)
|
||||
opentags = {'(': ')', '[': ']', '{': '}'}
|
||||
closetokens = ('delimiter',)
|
||||
closetags = {')': '(', ']': '[', '}': '{'}
|
||||
config = {
|
||||
'scala.api': 'http://www.scala-lang.org/api/current/allclasses.html',
|
||||
}
|
||||
|
||||
colors = {
|
||||
'scala.annotation': ('magenta', 'default'),
|
||||
|
|
Loading…
Reference in New Issue