Permalink
Browse files

Minor improvements

  • Loading branch information...
sergeche committed Feb 27, 2013
1 parent 74ce8c5 commit e63cda2267cf568180d50f0e2bb09c8cf8966595
View
@@ -11,12 +11,15 @@
PACKAGES_PATH = sublime.packages_path() or os.path.dirname(BASE_PATH)
# EMMET_GRAMMAR = os.path.join(BASE_PATH, 'Emmet.tmLanguage')
EMMET_GRAMMAR = 'Packages/%s/Emmet.tmLanguage' % os.path.basename(BASE_PATH)
-sys.path += [BASE_PATH] + [os.path.join(BASE_PATH, f) for f in ['completions', 'emmet']]
+sys.path += [BASE_PATH] + [os.path.join(BASE_PATH, f) for f in ['emmet_completions', 'emmet']]
-import completions as cmpl
+
+# import completions as cmpl
import emmet.pyv8loader as pyv8loader
-from completions.meta import HTML_ELEMENTS_ATTRIBUTES, HTML_ATTRIBUTES_VALUES
+import emmet_completions as cmpl
+from emmet_completions.meta import HTML_ELEMENTS_ATTRIBUTES, HTML_ATTRIBUTES_VALUES
from emmet.context import Context
+from emmet.context import js_file_reader as _js_file_reader
from emmet.pyv8loader import LoaderDelegate
__version__ = '1.1'
@@ -37,6 +40,13 @@
def is_st3():
return sublime.version()[0] == '3'
+def js_file_reader(file_path, use_unicode=True):
+ if hasattr(sublime, 'load_resource'):
+ rel_path = os.path.relpath(file_path, os.path.dirname(sublime.packages_path()))
+ return sublime.load_resource(rel_path)
+
+ return _js_file_reader(file_path, use_unicode)
+
def init():
"Init Emmet plugin"
# load settings
@@ -70,7 +80,8 @@ def init():
files=['../editor.js'],
ext_path=settings.get('extensions_path', None),
contrib=contrib,
- logger=delegate.log
+ logger=delegate.log,
+ reader=js_file_reader
)
update_settings()
View
@@ -37,6 +37,17 @@ def make_path(filename):
def js_log(message):
print(message)
+def js_file_reader(file_path, use_unicode=True):
+ if use_unicode:
+ f = codecs.open(file_path, 'r', 'utf-8')
+ else:
+ f = open(file_path, 'r')
+
+ content = f.read()
+ f.close()
+
+ return content
+
def import_pyv8():
# Importing non-existing modules is a bit tricky in Python:
# if we simply call `import PyV8` and module doesn't exists,
@@ -81,8 +92,9 @@ class Context():
@param contrib: Python objects to contribute to JS execution context
@param pyv8_path: Location of PyV8 binaries
"""
- def __init__(self, files=[], ext_path=None, contrib=None, logger=None):
+ def __init__(self, files=[], ext_path=None, contrib=None, logger=None, reader=js_file_reader):
self.logger = logger
+ self.reader = reader
try:
import_pyv8()
@@ -132,7 +144,8 @@ def load_extensions(self, path=None):
self.log('Loading Emmet extensions from %s' % self._ext_path)
for dirname, dirnames, filenames in os.walk(self._ext_path):
for filename in filenames:
- ext_files.append(os.path.join(dirname, filename))
+ if filename[0] != '.':
+ ext_files.append(os.path.join(dirname, filename))
self.js().locals.pyLoadExtensions(ext_files)
@@ -190,21 +203,16 @@ def reset(self):
if self._ctx:
self._ctx.leave()
self._ctx = None
- PyV8.JSEngine.collect()
- gc.collect()
+ try:
+ PyV8.JSEngine.collect()
+ gc.collect()
+ except:
+ pass
self._should_load_extension = True
def read_js_file(self, file_path):
- if self._use_unicode:
- f = codecs.open(file_path, 'r', 'utf-8')
- else:
- f = open(file_path, 'r')
-
- content = f.read()
- f.close()
-
- return content
+ return self.reader(file_path, self._use_unicode)
def eval(self, source):
self.js().eval(source)
View
@@ -49,15 +49,16 @@ def read(self, path, size, callback=None):
try:
content = self._read(path, size)
- except Exception as e:
- return callback(repr(e), None)
- # return as array of character codes since PyV8 may corrupt
- # binary data when python string is translated into JS string
- if is_python3:
- content = [ch for ch in content]
- else:
- content = [ord(ch) for ch in content]
+ # return as array of character codes since PyV8 may corrupt
+ # binary data when python string is translated into JS string
+ if is_python3:
+ content = [ch for ch in content]
+ else:
+ content = [ord(ch) for ch in content]
+
+ except Exception as e:
+ return callback(str(e), None)
callback(None, content)
@@ -71,11 +72,10 @@ def read_text(self, path, size, callback=None):
try:
content = self._read(path, size, 'r')
+ if not is_python3:
+ content = content.decode('utf-8')
except Exception as e:
- return callback(repr(e), None)
-
- if not is_python3:
- content = content.decode('utf-8')
+ return callback(str(e), None)
callback(None, content)
File renamed without changes.
Oops, something went wrong.

0 comments on commit e63cda2

Please sign in to comment.