Skip to content

Commit

Permalink
All of Vintageous loads with a few tweaks. Exciting times.
Browse files Browse the repository at this point in the history
It'll require more work though as nothing is hooked up and I'm sure
there will be plenty of issues once I try to actually execute
its commands.
  • Loading branch information
quarnster committed Apr 5, 2013
1 parent 82550f6 commit 7c70c92
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@
[submodule "3rdparty/bundles/GoSublime"]
path = 3rdparty/bundles/GoSublime
url = git://github.com/DisposaBoy/GoSublime.git
[submodule "3rdparty/bundles/Vintageous"]
path = 3rdparty/bundles/Vintageous
url = git://github.com/quarnster/Vintageous.git
1 change: 1 addition & 0 deletions 3rdparty/bundles/Vintageous
Submodule Vintageous added at ebcf82
2 changes: 2 additions & 0 deletions backend/packages/Default/history_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def get_jump_history():
return Note
46 changes: 46 additions & 0 deletions backend/sublime/sublime.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,47 @@
package sublime

import (
"code.google.com/p/log4go"
"lime/3rdparty/libs/gopy/lib"
"log"
"os"
"strings"
)

func scanpath(path string, m *py.Module) {
// This should probably be done by the Editor as it needs to scan through for themes, keybinding, settings etc
if f, err := os.Open(path); err != nil {
log4go.Warn(err)
} else {
defer f.Close()
if dirs, err := f.Readdirnames(-1); err != nil {
log4go.Warn(err)
} else {
for _, dir := range dirs {
if dir != "Vintageous" && dir != "Default" {
// TODO obviously
continue
}
dir2 := path + dir
if f2, err := os.Open(dir2); err != nil {
log4go.Warn(err)
} else {
defer f2.Close()
if fi, err := f2.Readdir(-1); err != nil {
log4go.Warn(err)
} else {
for _, f := range fi {
if fn := f.Name(); strings.HasSuffix(fn, ".py") {
m.Base().CallMethod("reload_plugin", "s", dir+"."+fn[:len(fn)-3])
}
}
}
}
}
}
}
}

func init() {
py.Initialize()
m, err := py.InitModule("sublime", sublime_methods)
Expand Down Expand Up @@ -33,4 +70,13 @@ func init() {
log.Fatal(err)
}
}
py.AddToPath("../packages/")
py.AddToPath("../../3rdparty/bundles/")
py.AddToPath(".")
if m, err := py.Import("sublime_plugin"); err != nil {
log.Fatal(err)
} else {
scanpath("../packages/", m)
scanpath("../../3rdparty/bundles/", m)
}
}
55 changes: 43 additions & 12 deletions backend/sublime/sublime_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
import os.path
import inspect
import traceback
import imp
import sublime
import sys
import importlib

class __Event:
def __init__(self):
Expand Down Expand Up @@ -46,15 +49,45 @@ class TextCommand(Command):
class EventListener(object):
pass

def reload_plugin(filename):
print "Loading plugin %s" % filename
oldpath = os.getcwd()
path = os.path.dirname(os.path.abspath(filename))

def fn(fullname):
paths = fullname.split(".")
paths = "/".join(paths)
for p in sys.path:
f = os.path.join(p, paths)
if os.path.exists(f):
return f
f += ".py"
if os.path.exists(f):
return f
return None

class __myfinder:
class myloader(object):
def load_module(self, fullname):
if fullname in sys.modules:
return sys.modules[fullname]
f = fn(fullname)
if not f.endswith(".py"):
m = imp.new_module(fullname)
m.__path__ = f
sys.modules[fullname] = m
return m
return imp.load_source(fullname, f)

def find_module(self, fullname, path=None):
f = fn(fullname)
if f != None:
return self.myloader()



sys.meta_path = [__myfinder()]

def reload_plugin(module):
print "Loading plugin %s" % module
try:
os.chdir(path)
filename = os.path.relpath(filename, path)
module = os.path.splitext(filename)[0]
module = __import__(module)
module = importlib.import_module(module)
for item in inspect.getmembers(module):
if type(EventListener) != type(item[1]):
continue
Expand All @@ -77,7 +110,5 @@ def add(inst, listname):
application_commands[item[0]] = item[1]
except:
traceback.print_exc()
finally:
os.chdir(oldpath)


except:
traceback.print_exc()

0 comments on commit 7c70c92

Please sign in to comment.