Browse files

run_existing_command check User/SublimeREPL first.

(add missing id's in Clojure+Python .sublime-menus
  • Loading branch information...
1 parent 930a019 commit 4413608dae4c4a0aaf4d86baea69c40ccac1bbd3 @wuub wuub committed May 28, 2012
Showing with 11 additions and 5 deletions.
  1. +1 −1 config/Clojure/Main.sublime-menu
  2. +1 −0 config/Python/Main.sublime-menu
  3. +9 −4 run_existing_command.py
View
2 config/Clojure/Main.sublime-menu
@@ -9,7 +9,7 @@
"children":
[
{"caption": "Clojure",
-
+ "id": "Clojure",
"children":[
{"command": "repl_open",
"caption": "Clojure",
View
1 config/Python/Main.sublime-menu
@@ -9,6 +9,7 @@
"children":
[
{"caption": "Python",
+ "id": "Python",
"children":[
{"command": "repl_open",
View
13 run_existing_command.py
@@ -5,12 +5,18 @@
import sublime_plugin
SUBLIMEREPL_DIR = os.getcwdu()
+SUBLIMEREPL_USER_DIR = os.path.join(sublime.packages_path(), "User", "SublimeREPL")
# yes, CommandCommmand :)
class RunExistingWindowCommandCommand(sublime_plugin.WindowCommand):
def run(self, id, file):
- path = os.path.join(SUBLIMEREPL_DIR, file)
- json_cmd = self._find_cmd(id, path)
+ """Find and run existing command with id in specified file.
+ SUBLIMEREPL_USER_DIR is consulted first, and then SUBLIMEREPL_DIR"""
+ for prefix in (SUBLIMEREPL_USER_DIR, SUBLIMEREPL_DIR):
+ path = os.path.join(prefix, file)
+ json_cmd = self._find_cmd(id, path)
+ if json_cmd:
+ break
if not json_cmd:
return
args = json_cmd["args"] if "args" in json_cmd else None
@@ -20,14 +26,13 @@ def _find_cmd(self, id, file):
return self._find_cmd_in_file(id, file)
def _find_cmd_in_file(self, id, file):
-
try:
with codecs.open(file, "r", "utf-8") as f:
lines = [line.split("//")[0] for line in f.readlines()]
data = json.loads("\n".join(lines))
return self._find_cmd_in_json(id, data)
except (IOError, ValueError), e:
- print sublime.error_message(str(e))
+ return None
def _find_cmd_in_json(self, id, json_object):
if isinstance(json_object, list):

0 comments on commit 4413608

Please sign in to comment.