Skip to content

Commit

Permalink
add additional swift and xcode commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Trevormichael committed Apr 10, 2022
1 parent 8a19273 commit 02782bf
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 3 deletions.
Binary file added .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.pythonPath": "/opt/homebrew/bin/python3"
}
29 changes: 29 additions & 0 deletions apps/xcode/xcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,32 @@ def filename():
return result

return ""

@mod.action_class
class ApplicationActions:
def follow():
"""Go to declaration"""
actions.key('ctrl-cmd-j')
def go_back():
"""Go back"""
actions.key('ctrl-cmd-left')
def go_forward():
"""Go forward"""
actions.key('ctrl-cmd-right')
def go_line_start(line: str):
"""Go to start of line number"""
actions.key('cmd-l')
actions.insert(line)
actions.key('enter')
actions.sleep('200ms')
actions.key('cmd-left')
def go_line_end(line: str):
"""Go to end of line number"""
actions.key('cmd-l')
actions.insert(line)
actions.key('enter')
def fix_formatting():
"""Format file contents"""
actions.key('cmd-a')
actions.key('ctrl-i')

7 changes: 7 additions & 0 deletions apps/xcode/xcode.talon
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@ app: xcode
-
tag(): user.find_and_replace
tag(): user.line_commands

follow: user.follow()
go back: user.go_back()
go forward: user.go_forward()
go <number> start: user.go_line_start(number)
go <number>: user.go_line_end(number)
fix formatting: user.fix_formatting()
13 changes: 12 additions & 1 deletion lang/swift/swift.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ def code_state_else_if():
actions.insert(" else if ()")
actions.key("left")

def code_operator_assignment():
actions.auto_insert(" = ")

def code_insert_function(text: str, selection: str):
if selection:
text = text + "({})".format(selection)
Expand Down Expand Up @@ -51,4 +54,12 @@ def code_default_function(text: str):
)
)

actions.user.code_insert_function(result, None)
actions.user.code_insert_function(result, None)

@mod.action_class
class LanguageActions:
def create_body():
"""Create and enter body"""
actions.insert(r" {}")
actions.key("left")
actions.key("enter")
5 changes: 3 additions & 2 deletions lang/swift/swift.talon
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ state let: "let "
state if let: "if let "
state guard let: "guard let "

^funk <user.text>$: user.code_default_function(text)
^private funk <user.text>$: user.code_private_function(text)
^(funk|function) <user.text>$: user.code_default_function(text)
^private (funk|function) <user.text>$: user.code_private_function(text)
^create body$: user.create_body()

0 comments on commit 02782bf

Please sign in to comment.