Skip to content

Commit 61e0401

Browse files
committed
Merge pull request #6 from Kapiainen/dev
Reorganizing and new features
2 parents 6e4ec4e + d5eaff9 commit 61e0401

File tree

2,650 files changed

+204
-39
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,650 files changed

+204
-39
lines changed

.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
*.stackdump
2-
Compile.bat
1+
*.stackdump
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Core/Main.sublime-menu

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[
2+
{
3+
"id": "preferences",
4+
"children":
5+
[
6+
{
7+
"caption": "Package Settings",
8+
"mnemonic": "P",
9+
"id": "package-settings",
10+
"children":
11+
[
12+
{
13+
"caption": "SublimePapyrus",
14+
"children":
15+
[
16+
{
17+
"caption": "Settings – Default",
18+
"command": "open_file", "args":
19+
{
20+
"file": "${packages}/SublimePapyrus/SublimePapyrus.sublime-settings"
21+
}
22+
},
23+
{
24+
"caption": "Settings – User",
25+
"command": "open_file", "args":
26+
{
27+
"file": "${packages}/User/SublimePapyrus.sublime-settings"
28+
}
29+
}
30+
]
31+
}
32+
]
33+
}
34+
]
35+
}
36+
]
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"target": "compile_papyrus",
33
"cmd": "$file",
4-
"file_regex": "(^.*\\.psc)\\(([0-9]*),([0-9]*)\\)",
4+
"file_regex": "^(.*\\.psc)\\(([0-9]*),([0-9]*)\\):\\s*(.*)$",
55
"selector": "source.papyrus"
66
}
File renamed without changes.

Papyrus/Papyrus.tmLanguage renamed to Core/Papyrus.tmLanguage

+1-1
Large diffs are not rendered by default.
File renamed without changes.

Papyrus/README.txt renamed to Core/README.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ This package can handle compiling source files (.psc), disassembling bytecode
88

99
If you're using an unorthodox installation (i.e. your Skyrim files are moved
1010
out of the Steam directory), you'll want to set up an INI file so Sublime can
11-
know where your compiler is, where the compiled files should go, etc.
11+
know where your compiler is, where the compiled files should go, etc.
1212

13-
To create the default version of this file, select "Papyrus INI: Create
14-
default INI file" from the command palette (brought up with Ctrl-Shift-P).
13+
To create the default version of this file, select "SublimePapyrus INI: Create
14+
default INI file" from the command palette (brought up with Ctrl-Shift-P).
1515

1616
(Note that to disassemble .pex files or convert .pas files, they must be in
1717
the same directory as the PapyrusAssembler.exe.)
File renamed without changes.

Papyrus/SublimePapyrus.py renamed to Core/SublimePapyrus.py

+81-11
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import sublime, sublime_plugin
2+
import re
23
import os
34
import sys
45
PYTHON_VERSION = sys.version_info
5-
SUBLIME_TEXT_VERSION = 2
6-
if (PYTHON_VERSION[0] == 3) and (PYTHON_VERSION[1] == 3):
7-
# 3.3
8-
SUBLIME_TEXT_VERSION = 3
9-
if SUBLIME_TEXT_VERSION == 2:
6+
if PYTHON_VERSION[0] == 2:
107
import ConfigParser
118
from StringIO import StringIO
12-
elif SUBLIME_TEXT_VERSION == 3:
9+
elif PYTHON_VERSION[0] == 3:
1310
import configparser
1411
from io import StringIO
12+
import importlib
13+
BUILD_SYSTEM = importlib.import_module("Default.exec")
1514

1615
# This may only work on Windows 7 and up -- fine for our purposes
1716
INI_LOCATION = os.path.expanduser("~/Documents/SublimePapyrus.ini")
@@ -58,6 +57,13 @@
5857
#
5958
""" % (END_USER_SCRIPTS, END_USER_COMPILER, END_USER_OUTPUT, END_USER_FLAGS)
6059

60+
ERROR_HIGHLIGHT_KEY = "papyrus_error"
61+
ERROR_HIGHLIGHT_SCOPE = "invalid"
62+
63+
def plugin_loaded():
64+
global USER_SETTINGS
65+
USER_SETTINGS = sublime.load_settings('SublimePapyrus.sublime-settings')
66+
6167
def getPrefs(filePath):
6268
fileDir, fileName = os.path.split(filePath)
6369
ret = {}
@@ -66,9 +72,9 @@ def getPrefs(filePath):
6672
ret["flags"] = END_USER_FLAGS
6773
ret["import"] = END_USER_SCRIPTS
6874
if (os.path.exists(INI_LOCATION)):
69-
if SUBLIME_TEXT_VERSION == 2:
75+
if PYTHON_VERSION[0] == 2:
7076
parser = ConfigParser.ConfigParser()
71-
elif SUBLIME_TEXT_VERSION == 3:
77+
elif PYTHON_VERSION[0] == 3:
7278
parser = configparser.ConfigParser()
7379
parser.read([INI_LOCATION])
7480

@@ -95,9 +101,9 @@ def getPrefs(filePath):
95101

96102
if (parser.get("Skyrim", "scripts") not in ret["import"]):
97103
ret["import"].append(parser.get("Skyrim", "scripts"))
98-
if SUBLIME_TEXT_VERSION == 2:
104+
if PYTHON_VERSION[0] == 2:
99105
ret["import"] = ";".join(filter(None, ret["import"]))
100-
elif SUBLIME_TEXT_VERSION == 3:
106+
elif PYTHON_VERSION[0] == 3:
101107
ret["import"] = ";".join([_f for _f in ret["import"] if _f])
102108

103109
ret["filename"] = fileName
@@ -119,7 +125,8 @@ def run(self, **args):
119125
class CreateDefaultSettingsFileCommand(sublime_plugin.WindowCommand):
120126
def run(self, **args):
121127
if os.path.exists(INI_LOCATION):
122-
sublime.status_message("ERROR: INI file already exists at %s" % (INI_LOCATION))
128+
if sublime.ok_cancel_dialog("INI file already exists at %s.\n Do you want to open the file?" % INI_LOCATION):
129+
self.window.open_file(INI_LOCATION)
123130
else:
124131
outHandle = open(INI_LOCATION, "w")
125132
outHandle.write(DEFAULT_INI_TEXT)
@@ -160,3 +167,66 @@ def run(self, **args):
160167
args["working_dir"] = scriptDir
161168

162169
self.window.run_command("exec", args)
170+
171+
if PYTHON_VERSION[0] == 3:
172+
class ExecCommand(BUILD_SYSTEM.ExecCommand):
173+
def finish(self, proc):
174+
super(ExecCommand, self).finish(proc)
175+
source = sublime.active_window().active_view()
176+
if source != None:
177+
if HasExtension(source.file_name(), "psc"):
178+
source.erase_regions(ERROR_HIGHLIGHT_KEY)
179+
if USER_SETTINGS.get('highlight_compiler_errors', False):
180+
output = GetOutput(self.output_view)
181+
if output != None:
182+
pattern = GetPattern(self.output_view)
183+
if pattern != None:
184+
errors = GetErrors(output, pattern)
185+
if errors != None:
186+
regions = GetRegions(source, errors)
187+
if regions != None:
188+
source.add_regions(ERROR_HIGHLIGHT_KEY, regions, ERROR_HIGHLIGHT_SCOPE)
189+
elif USER_SETTINGS.get('hide_successful_build_results', False):
190+
self.window.run_command("hide_panel", {"panel": "output.exec"})
191+
192+
def GetOutput(view):
193+
if view != None:
194+
return view.substr(sublime.Region(0, view.size()))
195+
else:
196+
return None
197+
198+
def GetPattern(view):
199+
if view != None:
200+
return view.settings().get("result_file_regex")
201+
else:
202+
return None
203+
204+
def GetErrors(output, pattern):
205+
lines = output.rstrip().split('\n')
206+
matches = []
207+
for line in lines:
208+
match = re.findall(pattern, line)
209+
if len(match) > 0:
210+
matches.append(match)
211+
if len(matches) > 0:
212+
return matches
213+
else:
214+
return None
215+
216+
def HasExtension(filename, extension):
217+
match = re.match("^.*\." + extension + "$", filename, re.IGNORECASE)
218+
if match != None:
219+
return True
220+
else:
221+
return False
222+
223+
def GetRegions(view, errors):
224+
regions = []
225+
for error in errors:
226+
region = view.line(sublime.Region(view.text_point(int(error[0][1]) - 1, 0)))
227+
regions.append(region)
228+
del region
229+
if len(regions) > 0:
230+
return regions
231+
else:
232+
return None

Core/SublimePapyrus.sublime-settings

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"highlight_compiler_errors": false,
3+
"hide_successful_build_results": false
4+
}
File renamed without changes.

0 commit comments

Comments
 (0)