Skip to content

Commit 7fa6145

Browse files
author
Caspar Gruijthuijsen
committed
absolute paths replaced by sublime resources
1 parent ecfd5ff commit 7fa6145

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

ahk/run_in_matlab.ahk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
1+
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
22
; #Warn ; Enable warnings to assist with detecting common errors.
33
; SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
44
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.

auto_matlab_commands.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import re
22
import subprocess
33
import collections
4-
from os.path import join, isfile
4+
import errno
5+
from os import makedirs
6+
from os.path import join, isfile, split
57
import xml.etree.ElementTree as ET
68

79
import sublime
@@ -282,14 +284,34 @@ def run(self, command):
282284
return
283285

284286
# find ahk script
285-
ahk_script = abspath(sublime.find_resources(
286-
config.AUTO_HOTKEY_SCRIPT)[-1],
287-
join(sublime.packages_path(), '..'))
287+
ahk_script_resource = sublime.find_resources(
288+
config.AUTO_HOTKEY_SCRIPT)[-1]
289+
ahk_script_path = abspath(ahk_script_resource,
290+
join(sublime.packages_path(), '..'))
291+
292+
if not isfile(ahk_script_path):
293+
# create ahk dir
294+
try:
295+
makedirs(split(ahk_script_path)[0])
296+
except OSError as e:
297+
if e.errno != errno.EEXIST:
298+
self.window.status_message(str(e))
299+
raise e
300+
return
301+
except Exception as e:
302+
self.window.status_message(str(e))
303+
raise e
304+
return
305+
# create ahk script
306+
with open(ahk_script_path, 'w') as fh:
307+
fh.write(sublime.load_resource(ahk_script_resource).replace(
308+
'\r\n', '\n'))
288309

289310
# run command
290-
subprocess.Popen([ahk_path, ahk_script, command,
311+
subprocess.Popen([ahk_path, ahk_script_path, command,
291312
'1' if ahk_return_focus else '0'])
292313

314+
293315
class ToggleAutoHotkeyFocusCommand(sublime_plugin.WindowCommand):
294316

295317
"""Toggle whether AutoHotkey will return the focus to Sublime

auto_matlab_documentation.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,15 @@ def run(self, edit):
7272
snip_path = project_settings.get('documentation_snippet')
7373
if not snip_path:
7474
snip_path = settings.get('documentation_snippet', '')
75-
if isfile(abspath(snip_path,
76-
vars=self.view.window().extract_variables())):
77-
snip_path = abspath(snip_path,
78-
vars=self.view.window().extract_variables())
79-
elif sublime.find_resources(snip_path):
80-
snip_path = abspath(sublime.find_resources(snip_path)[-1],
81-
join(sublime.packages_path(), ".."))
82-
else:
75+
snip_resources = sublime.find_resources(snip_path)
76+
if not snip_resources:
8377
msg = '[ERROR] AutoMatlab - Documentation snippet could not ' \
8478
'be found.'
8579
self.view.window().status_message(msg)
8680
raise Exception(msg)
8781
return
88-
89-
with open(snip_path) as fh:
90-
snip_all = fh.read()
82+
snip_all = sublime.load_resource(snip_resources[-1]).replace(
83+
'\r\n', '\n')
9184

9285
# extract documentation snippet content
9386
pattern = r'<!\[CDATA\[([\s\S]*)\]]>'

0 commit comments

Comments
 (0)